From 03c3732d829e44eac680ae9daeb2d9b268305ba6 Mon Sep 17 00:00:00 2001 From: Ariel Gentile Date: Thu, 26 Mar 2026 20:56:00 -0300 Subject: [PATCH 1/2] fix(nodejs): support null credential attributes Signed-off-by: Ariel Gentile --- packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts | 10 ++++++---- packages/anoncreds-nodejs/tests/api.test.ts | 8 ++++++++ .../anoncreds-react-native/src/ReactNativeAnoncreds.ts | 8 ++++---- packages/anoncreds-shared/src/Anoncreds.ts | 4 ++-- packages/anoncreds-shared/src/api/Credential.ts | 2 +- packages/anoncreds-shared/src/api/W3cCredential.ts | 2 +- 6 files changed, 22 insertions(+), 12 deletions(-) diff --git a/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts b/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts index 0d4419e..5857f18 100644 --- a/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts +++ b/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts @@ -109,14 +109,15 @@ export class NodeJSAnoncreds implements Anoncreds { return handleReturnPointer(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(ret) + const value = Array.isArray(ret) ? ret[0] : ret + return (value as string) ?? null } public createCredentialDefinition(options: { @@ -734,14 +735,15 @@ export class NodeJSAnoncreds implements Anoncreds { return new ObjectHandle(handleReturnPointer(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(ret) + const value = Array.isArray(ret) ? ret[0] : ret + return (value as string) ?? null } public w3cCredentialFromJson(options: { json: string }): ObjectHandle { diff --git a/packages/anoncreds-nodejs/tests/api.test.ts b/packages/anoncreds-nodejs/tests/api.test.ts index 19fbd34..13ce2f9 100644 --- a/packages/anoncreds-nodejs/tests/api.test.ts +++ b/packages/anoncreds-nodejs/tests/api.test.ts @@ -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({ @@ -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({ diff --git a/packages/anoncreds-react-native/src/ReactNativeAnoncreds.ts b/packages/anoncreds-react-native/src/ReactNativeAnoncreds.ts index 3a9a580..16e8b5e 100644 --- a/packages/anoncreds-react-native/src/ReactNativeAnoncreds.ts +++ b/packages/anoncreds-react-native/src/ReactNativeAnoncreds.ts @@ -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 { @@ -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 { diff --git a/packages/anoncreds-shared/src/Anoncreds.ts b/packages/anoncreds-shared/src/Anoncreds.ts index b62b2eb..6ab88ce 100644 --- a/packages/anoncreds-shared/src/Anoncreds.ts +++ b/packages/anoncreds-shared/src/Anoncreds.ts @@ -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 @@ -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 } diff --git a/packages/anoncreds-shared/src/api/Credential.ts b/packages/anoncreds-shared/src/api/Credential.ts index fa9b366..f68030f 100644 --- a/packages/anoncreds-shared/src/api/Credential.ts +++ b/packages/anoncreds-shared/src/api/Credential.ts @@ -142,7 +142,7 @@ 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() { diff --git a/packages/anoncreds-shared/src/api/W3cCredential.ts b/packages/anoncreds-shared/src/api/W3cCredential.ts index e621d73..9f46b47 100644 --- a/packages/anoncreds-shared/src/api/W3cCredential.ts +++ b/packages/anoncreds-shared/src/api/W3cCredential.ts @@ -150,7 +150,7 @@ 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() { From 71d92e8766665b11ad37e082ba46f27fde8dc78f Mon Sep 17 00:00:00 2001 From: Ariel Gentile Date: Thu, 26 Mar 2026 20:58:36 -0300 Subject: [PATCH 2/2] style: fix Signed-off-by: Ariel Gentile --- packages/anoncreds-shared/src/api/Credential.ts | 4 +++- packages/anoncreds-shared/src/api/W3cCredential.ts | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/anoncreds-shared/src/api/Credential.ts b/packages/anoncreds-shared/src/api/Credential.ts index f68030f..8606c7f 100644 --- a/packages/anoncreds-shared/src/api/Credential.ts +++ b/packages/anoncreds-shared/src/api/Credential.ts @@ -142,7 +142,9 @@ export class Credential extends AnoncredsObject { } public get revocationRegistryId() { - return NativeAnoncreds.instance.credentialGetAttribute({ objectHandle: this.handle, name: 'rev_reg_id' }) ?? undefined + return ( + NativeAnoncreds.instance.credentialGetAttribute({ objectHandle: this.handle, name: 'rev_reg_id' }) ?? undefined + ) } public get revocationRegistryIndex() { diff --git a/packages/anoncreds-shared/src/api/W3cCredential.ts b/packages/anoncreds-shared/src/api/W3cCredential.ts index 9f46b47..5042fb7 100644 --- a/packages/anoncreds-shared/src/api/W3cCredential.ts +++ b/packages/anoncreds-shared/src/api/W3cCredential.ts @@ -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' }) ?? undefined + return ( + NativeAnoncreds.instance.w3cCredentialProofGetAttribute({ objectHandle: proofDetails, name: 'rev_reg_id' }) ?? + undefined + ) } public get revocationRegistryIndex() {