Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,15 @@ export class NodeJSAnoncreds implements Anoncreds {
return handleReturnPointer<string>(ret)
}

public credentialGetAttribute(options: { objectHandle: ObjectHandle; name: string }) {
public credentialGetAttribute(options: { objectHandle: ObjectHandle; name: string }): string | null {
const { objectHandle, name } = serializeArguments(options)

const ret = allocateStringBuffer()
const errorCode = this.nativeAnoncreds.anoncreds_credential_get_attribute(objectHandle, name, ret)
this.handleError(errorCode)

return handleReturnPointer<string>(ret)
const value = Array.isArray(ret) ? ret[0] : ret
return (value as string) ?? null
}

public createCredentialDefinition(options: {
Expand Down Expand Up @@ -734,14 +735,15 @@ export class NodeJSAnoncreds implements Anoncreds {
return new ObjectHandle(handleReturnPointer<number>(ret))
}

public w3cCredentialProofGetAttribute(options: { objectHandle: ObjectHandle; name: string }) {
public w3cCredentialProofGetAttribute(options: { objectHandle: ObjectHandle; name: string }): string | null {
const { objectHandle, name } = serializeArguments(options)

const ret = allocateStringBuffer()
const errorCode = this.nativeAnoncreds.anoncreds_w3c_credential_proof_get_attribute(objectHandle, name, ret)
this.handleError(errorCode)

return handleReturnPointer<string>(ret)
const value = Array.isArray(ret) ? ret[0] : ret
return (value as string) ?? null
}

public w3cCredentialFromJson(options: { json: string }): ObjectHandle {
Expand Down
8 changes: 8 additions & 0 deletions packages/anoncreds-nodejs/tests/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ describe('API', () => {
expect(credReceivedJson.signature).toBeDefined()
expect(credReceivedJson.witness).toBeNull()

// Revocation-related getters must return undefined for non-revocable credentials
expect(credReceived.revocationRegistryId).toBeUndefined()
expect(credReceived.revocationRegistryIndex).toBeUndefined()

const nonce = Nonce.generate()

const presentationRequest = PresentationRequest.fromJson({
Expand Down Expand Up @@ -765,6 +769,10 @@ describe('API W3C', () => {
linkSecret,
})

// Revocation-related getters must return undefined for non-revocable credentials
expect(credReceived.revocationRegistryId).toBeUndefined()
expect(credReceived.revocationRegistryIndex).toBeUndefined()

const nonce = Nonce.generate()

const presentationRequest = PresentationRequest.fromJson({
Expand Down
8 changes: 4 additions & 4 deletions packages/anoncreds-react-native/src/ReactNativeAnoncreds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,8 @@ export class ReactNativeAnoncreds implements Anoncreds {
return this.handleError(this.anoncreds.revocationRegistryDefinitionGetAttribute(serializeArguments(options)))
}

public credentialGetAttribute(options: { objectHandle: ObjectHandle; name: string }): string {
return this.handleError(this.anoncreds.credentialGetAttribute(serializeArguments(options)))
public credentialGetAttribute(options: { objectHandle: ObjectHandle; name: string }): string | null {
return this.handleError(this.anoncreds.credentialGetAttribute(serializeArguments(options))) ?? null
}

public getJson(options: { objectHandle: ObjectHandle }): string {
Expand Down Expand Up @@ -492,8 +492,8 @@ export class ReactNativeAnoncreds implements Anoncreds {
return new ObjectHandle(handle)
}

public w3cCredentialProofGetAttribute(options: { objectHandle: ObjectHandle; name: string }): string {
return this.handleError(this.anoncreds.w3cCredentialProofGetAttribute(serializeArguments(options)))
public w3cCredentialProofGetAttribute(options: { objectHandle: ObjectHandle; name: string }): string | null {
return this.handleError(this.anoncreds.w3cCredentialProofGetAttribute(serializeArguments(options))) ?? null
}

public w3cPresentationFromJson(options: { json: string }): ObjectHandle {
Expand Down
4 changes: 2 additions & 2 deletions packages/anoncreds-shared/src/Anoncreds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export type Anoncreds = {
timestamp?: number
}): ObjectHandle

credentialGetAttribute(options: { objectHandle: ObjectHandle; name: string }): string
credentialGetAttribute(options: { objectHandle: ObjectHandle; name: string }): string | null

revocationRegistryDefinitionGetAttribute(options: { objectHandle: ObjectHandle; name: string }): string

Expand Down Expand Up @@ -257,5 +257,5 @@ export type Anoncreds = {

w3cCredentialGetIntegrityProofDetails(options: { objectHandle: ObjectHandle }): ObjectHandle

w3cCredentialProofGetAttribute(options: { objectHandle: ObjectHandle; name: string }): string
w3cCredentialProofGetAttribute(options: { objectHandle: ObjectHandle; name: string }): string | null
}
4 changes: 3 additions & 1 deletion packages/anoncreds-shared/src/api/Credential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ export class Credential extends AnoncredsObject {
}

public get revocationRegistryId() {
return NativeAnoncreds.instance.credentialGetAttribute({ objectHandle: this.handle, name: 'rev_reg_id' })
return (
NativeAnoncreds.instance.credentialGetAttribute({ objectHandle: this.handle, name: 'rev_reg_id' }) ?? undefined
)
}

public get revocationRegistryIndex() {
Expand Down
5 changes: 4 additions & 1 deletion packages/anoncreds-shared/src/api/W3cCredential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,10 @@ export class W3cCredential extends AnoncredsObject {

public get revocationRegistryId() {
const proofDetails = this.getProofDetails()
return NativeAnoncreds.instance.w3cCredentialProofGetAttribute({ objectHandle: proofDetails, name: 'rev_reg_id' })
return (
NativeAnoncreds.instance.w3cCredentialProofGetAttribute({ objectHandle: proofDetails, name: 'rev_reg_id' }) ??
undefined
)
}

public get revocationRegistryIndex() {
Expand Down
Loading