From 8eae78987a62b2abba24e5d18dea8057cb25cebd Mon Sep 17 00:00:00 2001 From: Timo Glastra Date: Mon, 5 Feb 2024 21:52:42 +0700 Subject: [PATCH 1/5] refactor: only issuer id for legacy->w3c Signed-off-by: Timo Glastra --- docs/design/w3c/w3c-representation.md | 73 ++++++++++--------- src/ffi/w3c/credential.rs | 9 ++- src/services/w3c/credential_conversion.rs | 28 ++++--- tests/utils/mock.rs | 2 +- .../anoncreds-nodejs/src/NodeJSAnoncreds.ts | 10 +-- .../anoncreds-nodejs/src/library/bindings.ts | 5 +- .../anoncreds-react-native/cpp/anoncreds.cpp | 6 +- .../src/NativeBindings.ts | 6 +- .../src/ReactNativeAnoncreds.ts | 6 +- .../anoncreds-shared/src/Anoncreds.ts | 6 +- .../anoncreds-shared/src/api/Credential.ts | 31 ++------ .../anoncreds-shared/src/api/W3cCredential.ts | 31 ++------ wrappers/python/anoncreds/bindings.py | 4 +- wrappers/python/anoncreds/types.py | 10 +-- wrappers/python/demo/w3c_test.py | 4 +- 15 files changed, 94 insertions(+), 137 deletions(-) diff --git a/docs/design/w3c/w3c-representation.md b/docs/design/w3c/w3c-representation.md index c6e97642..a0f20f8b 100644 --- a/docs/design/w3c/w3c-representation.md +++ b/docs/design/w3c/w3c-representation.md @@ -1,31 +1,31 @@ ## Design for W3C representation of AnonCreds credentials and presentation -This design document describes how W3C formatted Verifiable Credentials and Presentations are supported in `anoncreds-rs` library. +This design document describes how W3C formatted Verifiable Credentials and Presentations are supported in `anoncreds-rs` library. ### Goals and ideas -* Use legacy styled credentials to generate W3C AnonCreds credentials and presentations - * Credentials conversion: - * Convert legacy styled AnonCreds credentials into W3C form - * Convert W3C styled AnonCreds credentials into legacy form - * Presentation conversion (Optional): - * Convert legacy styled AnonCreds presentation into W3C form - * Convert W3C styled AnonCreds presentation into legacy form -* Issue AnonCreds credentials in W3C form -* Create W3C presentations using W3C AnonCreds credentials -* Verify W3C presentations containing AnonCreds proof -* Extend W3C credentials: - * Ability to set Data Integrity proof signatures for generated W3C credential objects: - * W3C credentials may contain multiple signatures - * AnonCreds-Rs only generates/handle AnonCreds signatures - * Ability to add additional credential metadata +- Use legacy styled credentials to generate W3C AnonCreds credentials and presentations + - Credentials conversion: + - Convert legacy styled AnonCreds credentials into W3C form + - Convert W3C styled AnonCreds credentials into legacy form + - Presentation conversion (Optional): + - Convert legacy styled AnonCreds presentation into W3C form + - Convert W3C styled AnonCreds presentation into legacy form +- Issue AnonCreds credentials in W3C form +- Create W3C presentations using W3C AnonCreds credentials +- Verify W3C presentations containing AnonCreds proof +- Extend W3C credentials: + - Ability to set Data Integrity proof signatures for generated W3C credential objects: + - W3C credentials may contain multiple signatures + - AnonCreds-Rs only generates/handle AnonCreds signatures + - Ability to add additional credential metadata #### Out of scope -* Credentials: Verify validity of non-AnonCreds Data Integrity proof signatures -* Presentations: Create presentations using non-AnonCreds Data Integrity proof signature -* Presentations: Verify validity of presentations including non-AnonCreds Data Integrity proof signatures -* Presentations: Support different formats (for example DIF) of Presentation Request +- Credentials: Verify validity of non-AnonCreds Data Integrity proof signatures +- Presentations: Create presentations using non-AnonCreds Data Integrity proof signature +- Presentations: Verify validity of presentations including non-AnonCreds Data Integrity proof signatures +- Presentations: Support different formats (for example DIF) of Presentation Request ### Public API @@ -40,15 +40,16 @@ is require application uses conversion methods to get required format. These methods allow to solve both cases: Methods purpose - have to forms of credentials (probably even duplicate in wallet) to cover both cases: legacy and W3C -* `anoncreds_credential_to_w3c` - create W3C Presentation using a credential previously issued in legacy form -* `anoncreds_credential_from_w3c` - create a legacy styled presentation (for legacy Verifier) using a credential issued in W3C form + +- `anoncreds_credential_to_w3c` - create W3C Presentation using a credential previously issued in legacy form +- `anoncreds_credential_from_w3c` - create a legacy styled presentation (for legacy Verifier) using a credential issued in W3C form ```rust /// Convert credential in legacy form into W3C AnonCreds credential form /// /// # Params /// cred: object handle pointing to credential in legacy form to convert -/// cred_def: object handle pointing to the credential definition +/// issuer_id: issuer_id of the credential. Can be extracted from the cred_def and will be used as the `issuer` field in the w3c credential /// w3c_version: version of w3c verifiable credential specification (1.1 or 2.0) to use /// cred_p: reference that will contain converted credential (in W3C form) instance pointer /// @@ -57,7 +58,7 @@ Methods purpose - have to forms of credentials (probably even duplicate in walle #[no_mangle] pub extern "C" fn anoncreds_credential_to_w3c( cred: ObjectHandle, - cred_def: ObjectHandle, + issuer_id: FfiStr, w3c_version: FfiStr, cred_p: *mut ObjectHandle, ) -> ErrorCode {} @@ -90,18 +91,18 @@ So the credentials and presentations themselves are generated using new flow met The reasons for adding duplication methods: - avoid breaking changes in the existing API - - for example if we want Credential Offer pointing to the form of a credential to be issued + - for example if we want Credential Offer pointing to the form of a credential to be issued - clear separation between flows - - if a flow targeting issuing of W3C Credential the specific set of function to be used + - if a flow targeting issuing of W3C Credential the specific set of function to be used - avoid the situation when function result value may be in different forms - - example: - - issuer creates offer in legacy form but with resulting credential format indication (legacy or w3c ) - - as the flow execution result, create credential function returns credential either in w3c or legacy form - depending on offer - - if application analyze credential somehow it cause difficulties + - example: + - issuer creates offer in legacy form but with resulting credential format indication (legacy or w3c ) + - as the flow execution result, create credential function returns credential either in w3c or legacy form + depending on offer + - if application analyze credential somehow it cause difficulties - easier deprecation of legacy styled credentials and APIs - presentation conversion methods are not needed anymore in this case - - only credential conversion method to do migration for previously issued credentials + - only credential conversion method to do migration for previously issued credentials ```rust /// Create Credential in W3C form according to the specification. @@ -172,7 +173,7 @@ pub extern "C" fn anoncreds_w3c_credential_get_integrity_proof_details( ) -> ErrorCode {} /// Create W3C Presentation according to the specification. -/// +/// /// # Params /// pres_req: object handle pointing to presentation request /// credentials: credentials (in W3C form) to use for presentation preparation @@ -248,7 +249,7 @@ legacy_credential = Holder.anoncreds_process_credential(legacy_credential,...) /// Convert legacy styled credential to W3C credential form w3c_credential = Holder.anoncreds_credential_to_w3c(legacy_credential) -/// Do wallets need to store both credential forms to handle legacy and DIF presentations requests? +/// Do wallets need to store both credential forms to handle legacy and DIF presentations requests? Wallet.store_legacy_credential(legacy_credential) Wallet.store_w3c_credential(w3c_credential) @@ -270,7 +271,7 @@ w3c_credential = Holder.anoncreds_w3c_process_credential(w3c_credential,...) /// Convert W3C credential to legacy form legacy_credential = Holder.anoncreds_credential_from_w3c(w3c_credential) -/// Do wallets need to store both credential forms to handle legacy and DIF presentations requests? +/// Do wallets need to store both credential forms to handle legacy and DIF presentations requests? Wallet.store_legacy_credential(legacy_credential) Wallet.store_w3c_credential(w3c_credential) @@ -289,7 +290,7 @@ w3c_credential_request = Holder.anoncreds_w3c_create_credential_request(w3c_cred w3c_credential = Issuer.anoncreds_w3c_create_credential(w3c_credential_request,...) w3c_credential = Holder.anoncreds_w3c_process_credential(w3c_credential,...) -/// Do wallets need to store both credential forms to handle legacy and DIF presentations requests? +/// Do wallets need to store both credential forms to handle legacy and DIF presentations requests? Wallet.store_w3c_credential(w3c_credential) /// Verifiy W3C presenttion using W3C crdential form diff --git a/src/ffi/w3c/credential.rs b/src/ffi/w3c/credential.rs index 3e7fc52b..9f0096ac 100644 --- a/src/ffi/w3c/credential.rs +++ b/src/ffi/w3c/credential.rs @@ -1,3 +1,4 @@ +use crate::data_types::issuer_id::IssuerId; use crate::data_types::w3c::VerifiableCredentialSpecVersion; use ffi_support::{rust_string_to_c, FfiStr}; use std::ffi::c_char; @@ -125,7 +126,7 @@ pub extern "C" fn anoncreds_process_w3c_credential( /// /// # Params /// cred: object handle pointing to credential in legacy form to convert -/// cred_def: object handle pointing to the credential definition +/// issuer_id: issuer_id of the credential. Can be extracted from the cred_def and will be used as the `issuer` field in the w3c credential /// w3c_version: version of w3c verifiable credential specification (1.1 or 2.0) to use /// cred_p: reference that will contain converted credential (in W3C form) instance pointer /// @@ -134,7 +135,7 @@ pub extern "C" fn anoncreds_process_w3c_credential( #[no_mangle] pub extern "C" fn anoncreds_credential_to_w3c( cred: ObjectHandle, - cred_def: ObjectHandle, + issuer_id: FfiStr, w3c_version: FfiStr, cred_p: *mut ObjectHandle, ) -> ErrorCode { @@ -148,8 +149,8 @@ pub extern "C" fn anoncreds_credential_to_w3c( None => None, }; - let w3c_credential = - credential_to_w3c(credential, cred_def.load()?.cast_ref()?, w3c_version)?; + let issuer_id = IssuerId::new(issuer_id).expect("Invalid issuer ID"); + let w3c_credential = credential_to_w3c(credential, issuer_id, w3c_version)?; let w3c_cred = ObjectHandle::create(w3c_credential)?; unsafe { *cred_p = w3c_cred }; diff --git a/src/services/w3c/credential_conversion.rs b/src/services/w3c/credential_conversion.rs index 75859742..3a60b20b 100644 --- a/src/services/w3c/credential_conversion.rs +++ b/src/services/w3c/credential_conversion.rs @@ -1,4 +1,4 @@ -use crate::data_types::cred_def::CredentialDefinition; +use crate::data_types::issuer_id::IssuerId; use crate::data_types::w3c::credential::W3CCredential; use crate::data_types::w3c::credential_attributes::CredentialSubject; use crate::data_types::w3c::proof::{CredentialSignatureProofValue, DataIntegrityProof}; @@ -87,19 +87,19 @@ use crate::Error; /// ``` pub fn credential_to_w3c( credential: &Credential, - cred_def: &CredentialDefinition, + issuer_id: IssuerId, version: Option, ) -> Result { trace!( - "credential_to_w3c >>> credential: {:?}, cred_def: {:?}", + "credential_to_w3c >>> credential: {:?}, issuer_id: {:?}", credential, - cred_def + issuer_id ); credential.validate()?; let credential = credential.try_clone()?; - let issuer = cred_def.issuer_id.clone(); + let issuer = issuer_id.clone(); let attributes = CredentialSubject::from(&credential.values); let signature = CredentialSignatureProofValue { schema_id: credential.schema_id, @@ -323,9 +323,12 @@ pub(crate) mod tests { #[test] fn test_convert_credential_to_and_from_w3c() { let original_legacy_credential = legacy_credential(); - let w3c_credential = - credential_to_w3c(&original_legacy_credential, &credential_definition(), None) - .expect("unable to convert credential to w3c form"); + let w3c_credential = credential_to_w3c( + &original_legacy_credential, + credential_definition().issuer_id, + None, + ) + .expect("unable to convert credential to w3c form"); let legacy_credential = credential_from_w3c(&w3c_credential) .expect("unable to convert credential to legacy form"); assert_eq!(json!(original_legacy_credential), json!(legacy_credential),) @@ -339,9 +342,12 @@ pub(crate) mod tests { #[case] expected_context: Contexts, ) { let legacy_credential = legacy_credential(); - let w3c_credential = - credential_to_w3c(&legacy_credential, &credential_definition(), Some(version)) - .expect("unable to convert credential to w3c form"); + let w3c_credential = credential_to_w3c( + &legacy_credential, + credential_definition().issuer_id, + Some(version), + ) + .expect("unable to convert credential to w3c form"); assert_eq!(w3c_credential.context, expected_context.clone()); assert_eq!(w3c_credential.type_, ANONCREDS_CREDENTIAL_TYPES.clone()); diff --git a/tests/utils/mock.rs b/tests/utils/mock.rs index 1372ea94..b5b467f0 100644 --- a/tests/utils/mock.rs +++ b/tests/utils/mock.rs @@ -964,7 +964,7 @@ impl<'a> ProverWallet<'a> { match credential { Credentials::Legacy(legacy_cred) => { // Convert legacy credential into W3C form - let w3c_cred = credential_to_w3c(&legacy_cred, cred_def, None) + let w3c_cred = credential_to_w3c(&legacy_cred, cred_def.issuer_id, None) .expect("Error converting legacy credential into W3C form"); // Store w3c credential in wallet diff --git a/wrappers/javascript/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts b/wrappers/javascript/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts index fe7c76a9..6965a38f 100644 --- a/wrappers/javascript/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts +++ b/wrappers/javascript/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts @@ -656,16 +656,12 @@ export class NodeJSAnoncreds implements Anoncreds { return Boolean(handleReturnPointer(ret)) } - public credentialToW3c(options: { - objectHandle: ObjectHandle - credentialDefinition: ObjectHandle - w3cVersion?: string - }): ObjectHandle { - const { objectHandle, credentialDefinition, w3cVersion } = serializeArguments(options) + public credentialToW3c(options: { objectHandle: ObjectHandle; issuerId: string; w3cVersion?: string }): ObjectHandle { + const { objectHandle, issuerId, w3cVersion } = serializeArguments(options) const ret = allocatePointer() - this.nativeAnoncreds.anoncreds_credential_to_w3c(objectHandle, credentialDefinition, w3cVersion, ret) + this.nativeAnoncreds.anoncreds_credential_to_w3c(objectHandle, issuerId, w3cVersion, ret) this.handleError() return new ObjectHandle(handleReturnPointer(ret)) diff --git a/wrappers/javascript/packages/anoncreds-nodejs/src/library/bindings.ts b/wrappers/javascript/packages/anoncreds-nodejs/src/library/bindings.ts index 9f99754d..b16bcdaf 100644 --- a/wrappers/javascript/packages/anoncreds-nodejs/src/library/bindings.ts +++ b/wrappers/javascript/packages/anoncreds-nodejs/src/library/bindings.ts @@ -241,10 +241,7 @@ export const nativeBindings = { FFI_INT8_PTR ] ], - anoncreds_credential_to_w3c: [ - FFI_ERRORCODE, - [FFI_OBJECT_HANDLE, FFI_OBJECT_HANDLE, FFI_STRING, FFI_OBJECT_HANDLE_PTR] - ], + anoncreds_credential_to_w3c: [FFI_ERRORCODE, [FFI_OBJECT_HANDLE, FFI_STRING, FFI_STRING, FFI_OBJECT_HANDLE_PTR]], anoncreds_credential_from_w3c: [FFI_ERRORCODE, [FFI_OBJECT_HANDLE, FFI_OBJECT_HANDLE_PTR]], anoncreds_w3c_credential_get_integrity_proof_details: [FFI_ERRORCODE, [FFI_OBJECT_HANDLE, FFI_OBJECT_HANDLE_PTR]], anoncreds_w3c_credential_proof_get_attribute: [FFI_ERRORCODE, [FFI_OBJECT_HANDLE, FFI_STRING, FFI_STRING_PTR]], diff --git a/wrappers/javascript/packages/anoncreds-react-native/cpp/anoncreds.cpp b/wrappers/javascript/packages/anoncreds-react-native/cpp/anoncreds.cpp index 59b2e142..3c672dd8 100644 --- a/wrappers/javascript/packages/anoncreds-react-native/cpp/anoncreds.cpp +++ b/wrappers/javascript/packages/anoncreds-react-native/cpp/anoncreds.cpp @@ -870,15 +870,15 @@ jsi::Value processW3cCredential(jsi::Runtime &rt, jsi::Object options) { jsi::Value credentialToW3c(jsi::Runtime &rt, jsi::Object options) { auto credential = jsiToValue(rt, options, "objectHandle"); - auto credentialDefinition = - jsiToValue(rt, options, "credentialDefinition"); + auto issuerId = + jsiToValue(rt, options, "issuerId"); auto w3cVersion = jsiToValue(rt, options, "w3cVersion", true); ObjectHandle out; ErrorCode code = anoncreds_credential_to_w3c( - credential, credentialDefinition, + credential, issuerId.c_str(), w3cVersion.length() ? w3cVersion.c_str() : nullptr, &out); return createReturnValue(rt, code, &out); diff --git a/wrappers/javascript/packages/anoncreds-react-native/src/NativeBindings.ts b/wrappers/javascript/packages/anoncreds-react-native/src/NativeBindings.ts index 2a531475..aa147fd6 100644 --- a/wrappers/javascript/packages/anoncreds-react-native/src/NativeBindings.ts +++ b/wrappers/javascript/packages/anoncreds-react-native/src/NativeBindings.ts @@ -214,11 +214,7 @@ export type NativeBindings = { w3cCredentialProofGetAttribute(options: { objectHandle: number; name: string }): ReturnObject - credentialToW3c(options: { - objectHandle: number - credentialDefinition: number - w3cVersion?: string - }): ReturnObject + credentialToW3c(options: { objectHandle: number; issuerId: string; w3cVersion?: string }): ReturnObject credentialFromW3c(options: { objectHandle: number }): ReturnObject diff --git a/wrappers/javascript/packages/anoncreds-react-native/src/ReactNativeAnoncreds.ts b/wrappers/javascript/packages/anoncreds-react-native/src/ReactNativeAnoncreds.ts index 254dfead..76ee6576 100644 --- a/wrappers/javascript/packages/anoncreds-react-native/src/ReactNativeAnoncreds.ts +++ b/wrappers/javascript/packages/anoncreds-react-native/src/ReactNativeAnoncreds.ts @@ -507,11 +507,7 @@ export class ReactNativeAnoncreds implements Anoncreds { return new ObjectHandle(handle) } - public credentialToW3c(options: { - objectHandle: ObjectHandle - credentialDefinition: ObjectHandle - w3cVersion?: string - }): ObjectHandle { + public credentialToW3c(options: { objectHandle: ObjectHandle; issuerId: string; w3cVersion?: string }): ObjectHandle { const handle = this.handleError(this.anoncreds.credentialToW3c(serializeArguments(options))) return new ObjectHandle(handle) } diff --git a/wrappers/javascript/packages/anoncreds-shared/src/Anoncreds.ts b/wrappers/javascript/packages/anoncreds-shared/src/Anoncreds.ts index e011fe47..49530436 100644 --- a/wrappers/javascript/packages/anoncreds-shared/src/Anoncreds.ts +++ b/wrappers/javascript/packages/anoncreds-shared/src/Anoncreds.ts @@ -250,11 +250,7 @@ export type Anoncreds = { w3cCredentialFromJson(options: { json: string }): ObjectHandle - credentialToW3c(options: { - objectHandle: ObjectHandle - credentialDefinition: ObjectHandle - w3cVersion?: string - }): ObjectHandle + credentialToW3c(options: { objectHandle: ObjectHandle; issuerId: string; w3cVersion?: string }): ObjectHandle credentialFromW3c(options: { objectHandle: ObjectHandle }): ObjectHandle diff --git a/wrappers/javascript/packages/anoncreds-shared/src/api/Credential.ts b/wrappers/javascript/packages/anoncreds-shared/src/api/Credential.ts index 3982ded8..0c23df74 100644 --- a/wrappers/javascript/packages/anoncreds-shared/src/api/Credential.ts +++ b/wrappers/javascript/packages/anoncreds-shared/src/api/Credential.ts @@ -35,7 +35,7 @@ export type ProcessCredentialOptions = { } export type CredentialToW3cOptions = { - credentialDefinition: CredentialDefinition | JsonObject + issuerId: string w3cVersion?: string } @@ -151,28 +151,13 @@ export class Credential extends AnoncredsObject { } public toW3c(options: CredentialToW3cOptions): W3cCredential { - let credential - // Objects created within this method must be freed up - const objectHandles: ObjectHandle[] = [] - try { - const credentialDefinition = - options.credentialDefinition instanceof CredentialDefinition - ? options.credentialDefinition.handle - : pushToArray(CredentialDefinition.fromJson(options.credentialDefinition).handle, objectHandles) - - credential = new W3cCredential( - anoncreds.credentialToW3c({ - objectHandle: this.handle, - credentialDefinition, - w3cVersion: options.w3cVersion - }).handle - ) - } finally { - objectHandles.forEach((handle) => { - handle.clear() - }) - } - return credential + return new W3cCredential( + anoncreds.credentialToW3c({ + objectHandle: this.handle, + issuerId: options.issuerId, + w3cVersion: options.w3cVersion + }).handle + ) } public static fromW3c(options: CredentialFromW3cOptions) { diff --git a/wrappers/javascript/packages/anoncreds-shared/src/api/W3cCredential.ts b/wrappers/javascript/packages/anoncreds-shared/src/api/W3cCredential.ts index 9f3c69cf..c10d872a 100644 --- a/wrappers/javascript/packages/anoncreds-shared/src/api/W3cCredential.ts +++ b/wrappers/javascript/packages/anoncreds-shared/src/api/W3cCredential.ts @@ -36,7 +36,7 @@ export type ProcessW3cCredentialOptions = { export type W3cCredentialFromLegacyOptions = { credential: Credential - credentialDefinition: CredentialDefinition | JsonObject + issuerId: string w3cVersion?: string } @@ -176,27 +176,12 @@ export class W3cCredential extends AnoncredsObject { } public static fromLegacy(options: W3cCredentialFromLegacyOptions): W3cCredential { - let credential - // Objects created within this method must be freed up - const objectHandles: ObjectHandle[] = [] - try { - const credentialDefinition = - options.credentialDefinition instanceof CredentialDefinition - ? options.credentialDefinition.handle - : pushToArray(CredentialDefinition.fromJson(options.credentialDefinition).handle, objectHandles) - - credential = new W3cCredential( - anoncreds.credentialToW3c({ - objectHandle: options.credential.handle, - credentialDefinition, - w3cVersion: options.w3cVersion - }).handle - ) - } finally { - objectHandles.forEach((handle) => { - handle.clear() - }) - } - return credential + return new W3cCredential( + anoncreds.credentialToW3c({ + objectHandle: options.credential.handle, + issuerId: options.issuerId, + w3cVersion: options.w3cVersion + }).handle + ) } } diff --git a/wrappers/python/anoncreds/bindings.py b/wrappers/python/anoncreds/bindings.py index 2b5dedd2..0007d39a 100644 --- a/wrappers/python/anoncreds/bindings.py +++ b/wrappers/python/anoncreds/bindings.py @@ -1018,14 +1018,14 @@ def process_w3c_credential( def credential_to_w3c( cred: ObjectHandle, - cred_def: ObjectHandle, + issuer_id: str, w3c_version: Optional[str], ) -> ObjectHandle: result = ObjectHandle() do_call( "anoncreds_credential_to_w3c", cred, - cred_def, + encode_str(issuer_id), encode_str(w3c_version), byref(result), ) diff --git a/wrappers/python/anoncreds/types.py b/wrappers/python/anoncreds/types.py index ab49bf93..f9a30693 100644 --- a/wrappers/python/anoncreds/types.py +++ b/wrappers/python/anoncreds/types.py @@ -345,15 +345,13 @@ def rev_reg_index(self) -> Optional[int]: def to_w3c( self, - cred_def: Union[str, CredentialDefinition], + issuer_id: str, w3c_version: Optional[str] = None, ) -> "W3cCredential": - if not isinstance(cred_def, bindings.AnoncredsObject): - cred_def = CredentialDefinition.load(cred_def) return W3cCredential( bindings.credential_to_w3c( self.handle, - cred_def.handle, + issuer_id, w3c_version ) ) @@ -439,10 +437,10 @@ def to_legacy( def from_legacy( cls, cred: "Credential", - cred_def: Union[str, CredentialDefinition], + issuer_id: str, w3c_version: Optional[str] = None ) -> "W3cCredential": - return cred.to_w3c(cred_def, w3c_version) + return cred.to_w3c(issuer_id, w3c_version) def _get_proof_details(self) -> bindings.ObjectHandle: if self._proof_details is None: diff --git a/wrappers/python/demo/w3c_test.py b/wrappers/python/demo/w3c_test.py index 916c8e10..1e00f495 100644 --- a/wrappers/python/demo/w3c_test.py +++ b/wrappers/python/demo/w3c_test.py @@ -91,11 +91,11 @@ print("Legacy Credential `from_w3c`") print(legacy_cred.to_json()) -w3c_cred = legacy_cred.to_w3c(cred_def_pub) +w3c_cred = legacy_cred.to_w3c(issuer_id) print("W3c converted Credential `to_w3c`") print(w3c_cred.to_json()) -w3c_cred_restored = W3cCredential.from_legacy(legacy_cred, cred_def_pub) +w3c_cred_restored = W3cCredential.from_legacy(legacy_cred, issuer_id) print("W3C restored Credential `from_legacy`") print(w3c_cred_restored.to_json()) From a7a660f9b104f434c5d1ccc438190168b0d9856c Mon Sep 17 00:00:00 2001 From: Timo Glastra Date: Mon, 5 Feb 2024 22:04:06 +0700 Subject: [PATCH 2/5] some fixes Signed-off-by: Timo Glastra --- src/ffi/w3c/credential.rs | 2 +- src/services/w3c/credential_conversion.rs | 10 +++++----- tests/utils/mock.rs | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/ffi/w3c/credential.rs b/src/ffi/w3c/credential.rs index 9f0096ac..95f2a8a3 100644 --- a/src/ffi/w3c/credential.rs +++ b/src/ffi/w3c/credential.rs @@ -150,7 +150,7 @@ pub extern "C" fn anoncreds_credential_to_w3c( }; let issuer_id = IssuerId::new(issuer_id).expect("Invalid issuer ID"); - let w3c_credential = credential_to_w3c(credential, issuer_id, w3c_version)?; + let w3c_credential = credential_to_w3c(credential, &issuer_id, w3c_version)?; let w3c_cred = ObjectHandle::create(w3c_credential)?; unsafe { *cred_p = w3c_cred }; diff --git a/src/services/w3c/credential_conversion.rs b/src/services/w3c/credential_conversion.rs index 3a60b20b..9bdbdf21 100644 --- a/src/services/w3c/credential_conversion.rs +++ b/src/services/w3c/credential_conversion.rs @@ -81,13 +81,13 @@ use crate::Error; /// None, /// ).expect("Unable to process the credential"); /// -/// let _w3c_credential = w3c::credential_conversion::credential_to_w3c(&credential, &cred_def, None) +/// let _w3c_credential = w3c::credential_conversion::credential_to_w3c(&credential, &cred_def.issuer_id, None) /// .expect("Unable to convert credential to w3c form"); /// /// ``` pub fn credential_to_w3c( credential: &Credential, - issuer_id: IssuerId, + issuer_id: &IssuerId, version: Option, ) -> Result { trace!( @@ -228,7 +228,7 @@ pub fn credential_from_w3c(w3c_credential: &W3CCredential) -> Result ProverWallet<'a> { match credential { Credentials::Legacy(legacy_cred) => { // Convert legacy credential into W3C form - let w3c_cred = credential_to_w3c(&legacy_cred, cred_def.issuer_id, None) + let w3c_cred = credential_to_w3c(&legacy_cred, &cred_def.issuer_id, None) .expect("Error converting legacy credential into W3C form"); // Store w3c credential in wallet From 7d181754b5bfadc4ac6649d7639ea0b5b2f0aa9e Mon Sep 17 00:00:00 2001 From: Timo Glastra Date: Mon, 5 Feb 2024 22:18:42 +0700 Subject: [PATCH 3/5] more fixes Signed-off-by: Timo Glastra --- .../javascript/packages/anoncreds-nodejs/tests/api.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wrappers/javascript/packages/anoncreds-nodejs/tests/api.test.ts b/wrappers/javascript/packages/anoncreds-nodejs/tests/api.test.ts index cdfb27fe..4422328a 100644 --- a/wrappers/javascript/packages/anoncreds-nodejs/tests/api.test.ts +++ b/wrappers/javascript/packages/anoncreds-nodejs/tests/api.test.ts @@ -647,11 +647,11 @@ describe('API W3C', () => { expect('mock:uri').toEqual(legacyCredentialFrom.schemaId) expect('mock:uri').toEqual(legacyCredentialFrom.credentialDefinitionId) - const w3cCredential = W3cCredential.fromLegacy({ credential: legacyCredential, credentialDefinition }) + const w3cCredential = W3cCredential.fromLegacy({ credential: legacyCredential, issuerId: 'mock:uri' }) expect('mock:uri').toEqual(w3cCredential.schemaId) expect('mock:uri').toEqual(w3cCredential.credentialDefinitionId) - const convertedW3cCredential = legacyCredential.toW3c({ credentialDefinition }) + const convertedW3cCredential = legacyCredential.toW3c({ issuerId: 'mock:uri' }) expect('mock:uri').toEqual(convertedW3cCredential.schemaId) expect('mock:uri').toEqual(convertedW3cCredential.credentialDefinitionId) From 1991805de1ae50f8ade4084ddd96cfec8578c8d9 Mon Sep 17 00:00:00 2001 From: Timo Glastra Date: Tue, 6 Feb 2024 12:06:46 +0700 Subject: [PATCH 4/5] chore: address feedback Signed-off-by: Timo Glastra --- src/ffi/w3c/credential.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ffi/w3c/credential.rs b/src/ffi/w3c/credential.rs index 95f2a8a3..27a71f47 100644 --- a/src/ffi/w3c/credential.rs +++ b/src/ffi/w3c/credential.rs @@ -1,4 +1,3 @@ -use crate::data_types::issuer_id::IssuerId; use crate::data_types::w3c::VerifiableCredentialSpecVersion; use ffi_support::{rust_string_to_c, FfiStr}; use std::ffi::c_char; @@ -149,7 +148,10 @@ pub extern "C" fn anoncreds_credential_to_w3c( None => None, }; - let issuer_id = IssuerId::new(issuer_id).expect("Invalid issuer ID"); + let issuer_id = issuer_id + .as_opt_str() + .ok_or_else(|| err_msg!("Missing issuer id"))? + .try_into()?; let w3c_credential = credential_to_w3c(credential, &issuer_id, w3c_version)?; let w3c_cred = ObjectHandle::create(w3c_credential)?; From 4e61f24a90861517495910f06c2a0bf00d5bba8b Mon Sep 17 00:00:00 2001 From: Timo Glastra Date: Tue, 6 Feb 2024 12:07:17 +0700 Subject: [PATCH 5/5] chore: update version to 0.2.0-dev.11 Signed-off-by: Timo Glastra --- Cargo.lock.android | 2 +- Cargo.toml | 2 +- wrappers/javascript/lerna.json | 2 +- wrappers/javascript/packages/anoncreds-nodejs/package.json | 4 ++-- .../javascript/packages/anoncreds-react-native/package.json | 4 ++-- wrappers/javascript/packages/anoncreds-shared/package.json | 2 +- wrappers/python/anoncreds/version.py | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Cargo.lock.android b/Cargo.lock.android index 4a5ba788..ba8dd6d9 100644 --- a/Cargo.lock.android +++ b/Cargo.lock.android @@ -34,7 +34,7 @@ dependencies = [ [[package]] name = "anoncreds" -version = "0.2.0-dev.10" +version = "0.2.0-dev.11" dependencies = [ "anoncreds-clsignatures", "base64", diff --git a/Cargo.toml b/Cargo.toml index 2dc17370..caae7df1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "anoncreds" -version = "0.2.0-dev.10" +version = "0.2.0-dev.11" authors = [ "Hyperledger AnonCreds Contributors ", ] diff --git a/wrappers/javascript/lerna.json b/wrappers/javascript/lerna.json index 10d7c103..4eb5816a 100644 --- a/wrappers/javascript/lerna.json +++ b/wrappers/javascript/lerna.json @@ -1,6 +1,6 @@ { "$schema": "node_modules/lerna/schemas/lerna-schema.json", - "version": "0.2.0-dev.10", + "version": "0.2.0-dev.11", "npmClient": "pnpm", "command": { "version": { diff --git a/wrappers/javascript/packages/anoncreds-nodejs/package.json b/wrappers/javascript/packages/anoncreds-nodejs/package.json index a406cb90..8c2a937f 100644 --- a/wrappers/javascript/packages/anoncreds-nodejs/package.json +++ b/wrappers/javascript/packages/anoncreds-nodejs/package.json @@ -1,6 +1,6 @@ { "name": "@hyperledger/anoncreds-nodejs", - "version": "0.2.0-dev.10", + "version": "0.2.0-dev.11", "license": "Apache-2.0", "description": "Nodejs wrapper for Anoncreds", "main": "build/index", @@ -43,7 +43,7 @@ "binary": { "module_name": "anoncreds", "module_path": "native", - "remote_path": "v0.2.0-dev.10", + "remote_path": "v0.2.0-dev.11", "host": "https://github.com/hyperledger/anoncreds-rs/releases/download/", "package_name": "library-{platform}-{arch}.tar.gz" } diff --git a/wrappers/javascript/packages/anoncreds-react-native/package.json b/wrappers/javascript/packages/anoncreds-react-native/package.json index 631e2d5f..17e14a5d 100644 --- a/wrappers/javascript/packages/anoncreds-react-native/package.json +++ b/wrappers/javascript/packages/anoncreds-react-native/package.json @@ -1,6 +1,6 @@ { "name": "@hyperledger/anoncreds-react-native", - "version": "0.2.0-dev.10", + "version": "0.2.0-dev.11", "license": "Apache-2.0", "description": "React Native wrapper for Anoncreds", "main": "build/index", @@ -51,7 +51,7 @@ "binary": { "module_name": "anoncreds", "module_path": "native", - "remote_path": "v0.2.0-dev.10", + "remote_path": "v0.2.0-dev.11", "host": "https://github.com/hyperledger/anoncreds-rs/releases/download/", "package_name": "library-ios-android.tar.gz" } diff --git a/wrappers/javascript/packages/anoncreds-shared/package.json b/wrappers/javascript/packages/anoncreds-shared/package.json index 52ad18bc..0d245e1d 100644 --- a/wrappers/javascript/packages/anoncreds-shared/package.json +++ b/wrappers/javascript/packages/anoncreds-shared/package.json @@ -1,6 +1,6 @@ { "name": "@hyperledger/anoncreds-shared", - "version": "0.2.0-dev.10", + "version": "0.2.0-dev.11", "license": "Apache-2.0", "description": "Anoncreds wrapper library with NodeJS and React Native", "main": "build/index", diff --git a/wrappers/python/anoncreds/version.py b/wrappers/python/anoncreds/version.py index 4c87d59c..ff77cf06 100644 --- a/wrappers/python/anoncreds/version.py +++ b/wrappers/python/anoncreds/version.py @@ -1,3 +1,3 @@ """anoncreds library wrapper version.""" -__version__ = "0.2.0-dev.10" +__version__ = "0.2.0-dev.11"