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..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' }) + 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..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' }) + return ( + NativeAnoncreds.instance.w3cCredentialProofGetAttribute({ objectHandle: proofDetails, name: 'rev_reg_id' }) ?? + undefined + ) } public get revocationRegistryIndex() {