From fbc2ecf895ac4971ffecb560b2aaba354a3fa6fb Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Mon, 13 Nov 2023 14:02:21 +0300 Subject: [PATCH 01/21] W3C: Updated Python wrapper Signed-off-by: artem.ivanov --- wrappers/python/anoncreds/__init__.py | 4 + wrappers/python/anoncreds/bindings.py | 252 +++++++++++++++++++++++ wrappers/python/anoncreds/types.py | 278 +++++++++++++++++++++++++- wrappers/python/demo/w3c_test.py | 263 ++++++++++++++++++++++++ 4 files changed, 794 insertions(+), 3 deletions(-) create mode 100644 wrappers/python/demo/w3c_test.py diff --git a/wrappers/python/anoncreds/__init__.py b/wrappers/python/anoncreds/__init__.py index c86a2b85..f177cbef 100644 --- a/wrappers/python/anoncreds/__init__.py +++ b/wrappers/python/anoncreds/__init__.py @@ -21,6 +21,8 @@ RevocationStatusList, RevocationRegistryDefinition, RevocationRegistryDefinitionPrivate, + W3CCredential, + W3CPresentation, ) __all__ = ( @@ -48,4 +50,6 @@ "RevocationRegistryDefinition", "RevocationRegistryDefinitionPrivate", "Schema", + "W3CCredential", + "W3CPresentation" ) diff --git a/wrappers/python/anoncreds/bindings.py b/wrappers/python/anoncreds/bindings.py index 28122f8b..54314f56 100644 --- a/wrappers/python/anoncreds/bindings.py +++ b/wrappers/python/anoncreds/bindings.py @@ -964,3 +964,255 @@ def create_or_update_revocation_state( byref(updated_rev_state), ) return updated_rev_state + + +def create_w3c_credential_offer( + schema_id: str, cred_def_id: str, key_proof: ObjectHandle +) -> ObjectHandle: + cred_offer = ObjectHandle() + do_call( + "anoncreds_create_w3c_credential_offer", + encode_str(schema_id), + encode_str(cred_def_id), + key_proof, + byref(cred_offer), + ) + return cred_offer + + +def create_w3c_credential_request( + entropy: Optional[str], + prover_did: Optional[str], + cred_def: ObjectHandle, + link_secret: str, + link_secret_id: str, + cred_offer: ObjectHandle, +) -> Tuple[ObjectHandle, ObjectHandle]: + cred_req, cred_req_metadata = ObjectHandle(), ObjectHandle() + do_call( + "anoncreds_create_w3c_credential_request", + encode_str(entropy), + encode_str(prover_did), + cred_def, + encode_str(link_secret), + encode_str(link_secret_id), + cred_offer, + byref(cred_req), + byref(cred_req_metadata), + ) + return (cred_req, cred_req_metadata) + + +def create_w3c_credential( + cred_def: ObjectHandle, + cred_def_private: ObjectHandle, + cred_offer: ObjectHandle, + cred_request: ObjectHandle, + attr_raw_values: Mapping[str, str], + revocation_config: Optional[RevocationConfig], + encoding: Optional[str], +) -> ObjectHandle: + cred = ObjectHandle() + attr_keys = list(attr_raw_values.keys()) + names_list = FfiStrList.create(attr_keys) + raw_values_list = FfiStrList.create(str(attr_raw_values[k]) for k in attr_keys) + do_call( + "anoncreds_create_w3c_credential", + cred_def, + cred_def_private, + cred_offer, + cred_request, + names_list, + raw_values_list, + pointer(revocation_config) + if revocation_config + else POINTER(RevocationConfig)(), + encode_str(encoding), + byref(cred), + ) + return cred + + +def process_w3c_credential( + cred: ObjectHandle, + cred_req_metadata: ObjectHandle, + link_secret: str, + cred_def: ObjectHandle, + rev_reg_def: Optional[ObjectHandle], +) -> ObjectHandle: + result = ObjectHandle() + do_call( + "anoncreds_process_w3c_credential", + cred, + cred_req_metadata, + encode_str(link_secret), + cred_def, + rev_reg_def or ObjectHandle(), + byref(result), + ) + return result + + +def credential_to_w3c( + cred: ObjectHandle, +) -> ObjectHandle: + result = ObjectHandle() + do_call( + "anoncreds_credential_to_w3c", + cred, + byref(result), + ) + return result + + +def credential_from_w3c( + cred: ObjectHandle, +) -> ObjectHandle: + result = ObjectHandle() + do_call( + "anoncreds_credential_from_w3c", + cred, + byref(result), + ) + return result + + +def w3c_credential_add_non_anoncreds_integrity_proof( + cred: ObjectHandle, + proof: str, +) -> ObjectHandle: + result = ObjectHandle() + do_call( + "anoncreds_w3c_credential_add_non_anoncreds_integrity_proof", + cred, + encode_str(proof), + byref(result), + ) + return result + + +def w3c_credential_id( + cred: ObjectHandle, + id: str, +) -> ObjectHandle: + result = ObjectHandle() + do_call( + "anoncreds_w3c_credential_id", + cred, + encode_str(id), + byref(result), + ) + return result + + +def w3c_credential_subject_id( + cred: ObjectHandle, + id: str, +) -> ObjectHandle: + result = ObjectHandle() + do_call( + "anoncreds_w3c_credential_subject_id", + cred, + encode_str(id), + byref(result), + ) + return result + + +def w3c_credential_add_context( + cred: ObjectHandle, + context: str, +) -> ObjectHandle: + result = ObjectHandle() + do_call( + "anoncreds_w3c_credential_add_context", + cred, + encode_str(context), + byref(result), + ) + return result + + +def w3c_credential_add_type( + cred: ObjectHandle, + type_: str, +) -> ObjectHandle: + result = ObjectHandle() + do_call( + "anoncreds_w3c_credential_add_type", + cred, + encode_str(type_), + byref(result), + ) + return result + + +def create_w3c_presentation( + pres_req: ObjectHandle, + credentials: Sequence[CredentialEntry], + credentials_prove: Sequence[CredentialProve], + link_secret: str, + schemas: Sequence[ObjectHandle], + schema_ids: Sequence[str], + cred_defs: Sequence[ObjectHandle], + cred_def_ids: Sequence[str], +) -> ObjectHandle: + entry_list = CredentialEntryList() + entry_list.count = len(credentials) + entry_list.data = (CredentialEntry * entry_list.count)(*credentials) + prove_list = CredentialProveList() + prove_list.count = len(credentials_prove) + prove_list.data = (CredentialProve * prove_list.count)(*credentials_prove) + present = ObjectHandle() + + do_call( + "anoncreds_create_w3c_presentation", + pres_req, + entry_list, + prove_list, + encode_str(link_secret), + FfiObjectHandleList.create(schemas), + FfiStrList.create(schema_ids), + FfiObjectHandleList.create(cred_defs), + FfiStrList.create(cred_def_ids), + byref(present), + ) + return present + + +def verify_w3c_presentation( + presentation: ObjectHandle, + pres_req: ObjectHandle, + schema_ids: Sequence[str], + schemas: Sequence[ObjectHandle], + cred_def_ids: Sequence[str], + cred_defs: Sequence[ObjectHandle], + rev_reg_def_ids: Optional[Sequence[str]], + rev_reg_defs: Optional[Sequence[ObjectHandle]], + rev_status_lists: Optional[Sequence[ObjectHandle]], + nonrevoked_interval_overrides: Optional[Sequence[NonrevokedIntervalOverride]], +) -> bool: + verify = c_int8() + + nonrevoked_interval_overrides_list = NonrevokedIntervalOverrideList() + if nonrevoked_interval_overrides: + nonrevoked_interval_overrides_list.count = len(nonrevoked_interval_overrides) + nonrevoked_interval_overrides_list.data = ( + NonrevokedIntervalOverride * nonrevoked_interval_overrides.count + )(*nonrevoked_interval_overrides) + + do_call( + "anoncreds_verify_w3c_presentation", + presentation, + pres_req, + FfiObjectHandleList.create(schemas), + FfiStrList.create(schema_ids), + FfiObjectHandleList.create(cred_defs), + FfiStrList.create(cred_def_ids), + FfiObjectHandleList.create(rev_reg_defs), + FfiStrList.create(rev_reg_def_ids), + FfiObjectHandleList.create(rev_status_lists), + nonrevoked_interval_overrides_list, + byref(verify), + ) + return bool(verify) diff --git a/wrappers/python/anoncreds/types.py b/wrappers/python/anoncreds/types.py index 46ab4f14..d6fc5cfc 100644 --- a/wrappers/python/anoncreds/types.py +++ b/wrappers/python/anoncreds/types.py @@ -342,6 +342,134 @@ def rev_reg_index(self) -> Optional[int]: ) return int(str(sval)) if sval is not None else None + def to_w3c( + self + ) -> "W3CCredential": + return W3CCredential( + bindings.credential_to_w3c( + self.handle, + ) + ) + + @classmethod + def from_w3c(cls, cred: "W3CCredential") -> "Credential": + return Credential( + bindings.credential_from_w3c( + cred.handle + ) + ) + + +class W3CCredential(bindings.AnoncredsObject): + GET_ATTR = "anoncreds_w3c_credential_get_attribute" + + @classmethod + def create( + cls, + cred_def: Union[str, CredentialDefinition], + cred_def_private: Union[str, CredentialDefinitionPrivate], + cred_offer: Union[str, CredentialOffer], + cred_request: Union[str, CredentialRequest], + attr_raw_values: Mapping[str, str], + revocation_config: Optional["CredentialRevocationConfig"] = None, + encoding: Optional[str] = None, + ) -> "W3CCredential": + if not isinstance(cred_def, bindings.AnoncredsObject): + cred_def = CredentialDefinition.load(cred_def) + if not isinstance(cred_def_private, bindings.AnoncredsObject): + cred_def_private = CredentialDefinitionPrivate.load(cred_def_private) + if not isinstance(cred_offer, bindings.AnoncredsObject): + cred_offer = CredentialOffer.load(cred_offer) + if not isinstance(cred_request, bindings.AnoncredsObject): + cred_request = CredentialRequest.load(cred_request) + cred = bindings.create_w3c_credential( + cred_def.handle, + cred_def_private.handle, + cred_offer.handle, + cred_request.handle, + attr_raw_values, + revocation_config._native if revocation_config else None, + encoding, + ) + return W3CCredential(cred) + + def process( + self, + cred_req_metadata: Union[str, CredentialRequestMetadata], + link_secret: str, + cred_def: Union[str, CredentialDefinition], + rev_reg_def: Optional[Union[str, "RevocationRegistryDefinition"]] = None, + ) -> "W3CCredential": + if not isinstance(cred_req_metadata, bindings.AnoncredsObject): + cred_req_metadata = CredentialRequestMetadata.load(cred_req_metadata) + if not isinstance(cred_def, bindings.AnoncredsObject): + cred_def = CredentialDefinition.load(cred_def) + if rev_reg_def and not isinstance(rev_reg_def, bindings.AnoncredsObject): + rev_reg_def = RevocationRegistryDefinition.load(rev_reg_def) + return W3CCredential( + bindings.process_w3c_credential( + self.handle, + cred_req_metadata.handle, + link_secret, + cred_def.handle, + rev_reg_def.handle if rev_reg_def else None, + ) + ) + + @classmethod + def load(cls, value: Union[dict, str, bytes, memoryview]) -> "W3CCredential": + return Credential( + bindings._object_from_json("anoncreds_w3c_credential_from_json", value) + ) + + @property + def schema_id(self) -> str: + return str( + bindings._object_get_attribute( + self.GET_ATTR, + self.handle, + "schema_id", + ) + ) + + @property + def cred_def_id(self) -> str: + return str( + bindings._object_get_attribute( + self.GET_ATTR, + self.handle, + "cred_def_id", + ) + ) + + @property + def rev_reg_id(self) -> str: + return str( + bindings._object_get_attribute( + self.GET_ATTR, + self.handle, + "rev_reg_id", + ) + ) + + @property + def rev_reg_index(self) -> Optional[int]: + sval = bindings._object_get_attribute( + self.GET_ATTR, + self.handle, + "rev_reg_index", + ) + return int(str(sval)) if sval is not None else None + + def to_legacy( + self + ) -> "Credential": + return Credential.from_w3c(self) + + @classmethod + def from_legacy(cls, cred: "Credential") -> "W3CCredential": + return cred.to_w3c() + class PresentationRequest(bindings.AnoncredsObject): @classmethod @@ -364,7 +492,7 @@ def add_self_attested(self, attest: Mapping[str, str]): def _get_entry( self, - cred: Credential, + cred: Union[Credential, W3CCredential], timestamp: Optional[int] = None, rev_state: Union[None, str, "CredentialRevocationState"] = None, ): @@ -380,7 +508,7 @@ def _get_entry( def add_attributes( self, - cred: Credential, + cred: Union[Credential, W3CCredential], *referents: Sequence[str], reveal: bool = True, timestamp: Optional[int] = None, @@ -394,7 +522,7 @@ def add_attributes( def add_predicates( self, - cred: Credential, + cred: Union[Credential, W3CCredential], *referents: Sequence[str], timestamp: Optional[int] = None, rev_state: Union[None, str, "CredentialRevocationState"] = None, @@ -552,6 +680,150 @@ def verify( ) +class W3CPresentation(bindings.AnoncredsObject): + @classmethod + def create( + cls, + pres_req: Union[str, PresentationRequest], + present_creds: PresentCredentials, + link_secret: str, + schemas: Mapping[str, Union[str, Schema]], + cred_defs: Mapping[str, Union[str, CredentialDefinition]], + ) -> "W3CPresentation": + if not isinstance(pres_req, bindings.AnoncredsObject): + pres_req = PresentationRequest.load(pres_req) + schema_ids = list(schemas.keys()) + cred_def_ids = list(cred_defs.keys()) + schema_handles = [ + ( + Schema.load(s) if not isinstance(s, bindings.AnoncredsObject) else s + ).handle + for s in schemas.values() + ] + cred_def_handles = [ + ( + CredentialDefinition.load(c) + if not isinstance(c, bindings.AnoncredsObject) + else c + ).handle + for c in cred_defs.values() + ] + creds = [] + creds_prove = [] + for cred, cred_ts in present_creds.entries.items(): + for timestamp, (attrs, preds, rev_state) in cred_ts.items(): + entry_idx = len(creds) + creds.append( + bindings.CredentialEntry.create( + cred, timestamp, rev_state and rev_state + ) + ) + for reft, reveal in attrs: + creds_prove.append( + bindings.CredentialProve.attribute(entry_idx, reft, reveal) + ) + for reft in preds: + creds_prove.append( + bindings.CredentialProve.predicate(entry_idx, reft) + ) + return W3CPresentation( + bindings.create_w3c_presentation( + pres_req.handle, + creds, + creds_prove, + link_secret, + schema_handles, + schema_ids, + cred_def_handles, + cred_def_ids, + ) + ) + + @classmethod + def load(cls, value: Union[dict, str, bytes, memoryview]) -> "W3CPresentation": + return W3CPresentation( + bindings._object_from_json("anoncreds_w3c_presentation_from_json", value) + ) + + def verify( + self, + pres_req: Union[str, PresentationRequest], + schemas: Mapping[str, Union[str, Schema]], + cred_defs: Mapping[str, Union[str, CredentialDefinition]], + rev_reg_defs: Optional[ + Mapping[str, Union[str, "RevocationRegistryDefinition"]] + ] = None, + rev_status_lists: Optional[Sequence[Union[str, "RevocationStatusList"]]] = None, + nonrevoked_interval_overrides: Optional[ + Sequence["NonrevokedIntervalOverride"] + ] = None, + ) -> bool: + if not isinstance(pres_req, bindings.AnoncredsObject): + pres_req = PresentationRequest.load(pres_req) + + schema_ids = list(schemas.keys()) + schema_handles = [ + ( + Schema.load(s) if not isinstance(s, bindings.AnoncredsObject) else s + ).handle + for s in schemas.values() + ] + + cred_def_ids = list(cred_defs.keys()) + cred_def_handles = [ + ( + CredentialDefinition.load(c) + if not isinstance(c, bindings.AnoncredsObject) + else c + ).handle + for c in cred_defs.values() + ] + + if rev_reg_defs: + rev_reg_def_ids = list(rev_reg_defs.keys()) + rev_reg_def_handles = [ + ( + RevocationRegistryDefinition.load(r) + if not isinstance(r, bindings.AnoncredsObject) + else r + ).handle + for r in rev_reg_defs.values() + ] + else: + rev_reg_def_ids = None + rev_reg_def_handles = None + + if rev_status_lists: + rev_status_list_handles = [ + ( + RevocationStatusList.load(r) + if not isinstance(r, bindings.AnoncredsObject) + else r + ).handle + for r in rev_status_lists + ] + else: + rev_status_list_handles = None + + nonrevoked_interval_overrides_native = [] + if nonrevoked_interval_overrides: + for o in nonrevoked_interval_overrides: + nonrevoked_interval_overrides_native.append(o._native) + + return bindings.verify_w3c_presentation( + self.handle, + pres_req.handle, + schema_ids, + schema_handles, + cred_def_ids, + cred_def_handles, + rev_reg_def_ids, + rev_reg_def_handles, + rev_status_list_handles, + nonrevoked_interval_overrides_native, + ) + + class RevocationRegistryDefinitionPrivate(bindings.AnoncredsObject): @classmethod def load( diff --git a/wrappers/python/demo/w3c_test.py b/wrappers/python/demo/w3c_test.py new file mode 100644 index 00000000..993262a2 --- /dev/null +++ b/wrappers/python/demo/w3c_test.py @@ -0,0 +1,263 @@ +from anoncreds import ( + generate_nonce, + create_link_secret, + Credential, + W3CCredential, + CredentialDefinition, + CredentialOffer, + CredentialRequest, + CredentialRevocationConfig, + CredentialRevocationState, + PresentationRequest, + Presentation, + W3CPresentation, + PresentCredentials, + RevocationRegistryDefinition, + RevocationStatusList, + Schema +) + +issuer_id = "mock:uri" +schema_id = "mock:uri" +cred_def_id = "mock:uri" +rev_reg_id = "mock:uri:revregid" +entropy = "entropy" +rev_idx = 1 + +schema = Schema.create( + "schema name", "schema version", issuer_id, ["name", "age", "sex", "height"] +) + +cred_def_pub, cred_def_priv, cred_def_correctness = CredentialDefinition.create( + schema_id, schema, issuer_id, "tag", "CL", support_revocation=True +) + +(rev_reg_def_pub, rev_reg_def_private) = RevocationRegistryDefinition.create( + cred_def_id, cred_def_pub, issuer_id, "some_tag", "CL_ACCUM", 10 +) + +time_create_rev_status_list = 12 +revocation_status_list = RevocationStatusList.create( + cred_def_pub, + rev_reg_id, + rev_reg_def_pub, + rev_reg_def_private, + issuer_id, + True, + time_create_rev_status_list, +) + +link_secret = create_link_secret() +link_secret_id = "default" + +cred_offer = CredentialOffer.create(schema_id, cred_def_id, cred_def_correctness) + +cred_request, cred_request_metadata = CredentialRequest.create( + entropy, None, cred_def_pub, link_secret, link_secret_id, cred_offer +) + +issue_cred = W3CCredential.create( + cred_def_pub, + cred_def_priv, + cred_offer, + cred_request, + {"sex": "male", "name": "Alex", "height": "175", "age": "28"}, + CredentialRevocationConfig( + rev_reg_def_pub, + rev_reg_def_private, + revocation_status_list, + rev_idx, + ), + None, +) + +recv_cred = issue_cred.process( + cred_request_metadata, link_secret, cred_def_pub, rev_reg_def_pub +) + +print("W3C Credential") +print(recv_cred.to_json()) + +legacy_cred = recv_cred.to_legacy() +print("Legacy Credential") +print(legacy_cred.to_json()) + +w3c_cred = legacy_cred.to_w3c() +print("W3C converted Credential") +print(w3c_cred.to_json()) + +time_after_creating_cred = time_create_rev_status_list + 1 +issued_rev_status_list = revocation_status_list.update( + cred_def_pub, + rev_reg_def_pub, + rev_reg_def_private, + [rev_idx], + None, + time_after_creating_cred, +) + +nonce = generate_nonce() +pres_req = PresentationRequest.load( + { + "nonce": nonce, + "name": "pres_req_1", + "version": "0.1", + "requested_attributes": { + "attr1_referent": {"name": "name", "issuer_id": issuer_id}, + "attr2_referent": {"names": ["name", "height"]}, + }, + "requested_predicates": { + "predicate1_referent": {"name": "age", "p_type": ">=", "p_value": 18} + }, + "non_revoked": {"from": 10, "to": 200}, + } +) + +rev_state = CredentialRevocationState.create( + rev_reg_def_pub, + revocation_status_list, + rev_idx, + rev_reg_def_pub.tails_location, +) + +schemas = {schema_id: schema} +cred_defs = {cred_def_id: cred_def_pub} +rev_reg_defs = {rev_reg_id: rev_reg_def_pub} +rev_status_lists = [issued_rev_status_list] + +# Create Presentation using W3C credential +present = PresentCredentials() + +present.add_attributes( + recv_cred, + "attr1_referent", + reveal=True, + timestamp=time_after_creating_cred, + rev_state=rev_state, +) + +present.add_attributes( + recv_cred, + "attr2_referent", + reveal=True, + timestamp=time_after_creating_cred, + rev_state=rev_state, +) + +present.add_predicates( + recv_cred, + "predicate1_referent", + timestamp=time_after_creating_cred, + rev_state=rev_state, +) + +presentation = W3CPresentation.create( + pres_req, + present, + link_secret, + schemas, + cred_defs, +) + +verified = presentation.verify( + pres_req, schemas, cred_defs, rev_reg_defs, rev_status_lists +) +assert verified + +# Create Presentation using Legacy credential +present = PresentCredentials() + +present.add_attributes( + legacy_cred, + "attr1_referent", + reveal=True, + timestamp=time_after_creating_cred, + rev_state=rev_state, +) + +present.add_attributes( + legacy_cred, + "attr2_referent", + reveal=True, + timestamp=time_after_creating_cred, + rev_state=rev_state, +) + +present.add_predicates( + legacy_cred, + "predicate1_referent", + timestamp=time_after_creating_cred, + rev_state=rev_state, +) + +presentation = Presentation.create( + pres_req, + present, + {}, + link_secret, + schemas, + cred_defs, +) + +verified = presentation.verify( + pres_req, schemas, cred_defs, rev_reg_defs, rev_status_lists +) +assert verified + +# Issuer revokes credential + +time_revoke_cred = time_after_creating_cred + 1 +revoked_status_list = issued_rev_status_list.update( + cred_def_pub, + rev_reg_def_pub, + rev_reg_def_private, + None, + [rev_idx], + time_revoke_cred, +) + +rev_status_lists.append(revoked_status_list) + +rev_state.update( + rev_reg_def_pub, + revocation_status_list, + rev_idx, + rev_reg_def_pub.tails_location, + revoked_status_list, +) + +present = PresentCredentials() +present.add_attributes( + recv_cred, + "attr1_referent", + reveal=True, + timestamp=time_revoke_cred, + rev_state=rev_state, +) + +present.add_attributes( + recv_cred, + "attr2_referent", + reveal=True, + timestamp=time_revoke_cred, + rev_state=rev_state, +) + +present.add_predicates( + recv_cred, "predicate1_referent", timestamp=time_revoke_cred, rev_state=rev_state +) + +presentation = W3CPresentation.create( + pres_req, present, link_secret, schemas, cred_defs +) + +verified = presentation.verify( + pres_req, + schemas, + cred_defs, + rev_reg_defs, + rev_status_lists, +) +assert not verified + +print("ok") From dfbca250d211dd8bd793b902ba0029b7f15711f4 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Tue, 14 Nov 2023 12:05:18 +0300 Subject: [PATCH 02/21] Added JS wrapper Signed-off-by: artem.ivanov --- wrappers/javascript/package.json | 2 +- .../anoncreds-nodejs/src/NodeJSAnoncreds.ts | 386 ++++++++++++++++++ .../anoncreds-nodejs/src/library/bindings.ts | 81 +++- .../anoncreds-nodejs/tests/api.test.ts | 301 +++++++++++++- .../anoncreds-nodejs/tests/bindings.test.ts | 380 +++++++++++++++++ .../anoncreds-react-native/cpp/HostObject.cpp | 43 ++ .../anoncreds-react-native/cpp/anoncreds.cpp | 321 +++++++++++++++ .../anoncreds-react-native/cpp/anoncreds.h | 24 ++ .../src/NativeBindings.ts | 87 ++++ .../src/ReactNativeAnoncreds.ts | 188 +++++++++ .../anoncreds-shared/src/Anoncreds.ts | 79 ++++ .../anoncreds-shared/src/api/Credential.ts | 13 + .../anoncreds-shared/src/api/W3CCredential.ts | 201 +++++++++ .../src/api/W3CCredentialOffer.ts | 43 ++ .../src/api/W3CCredentialRequest.ts | 62 +++ .../src/api/W3CPresentation.ts | 160 ++++++++ .../anoncreds-shared/src/api/index.ts | 4 + wrappers/javascript/pnpm-lock.yaml | 13 +- wrappers/python/anoncreds/bindings.py | 8 +- wrappers/python/anoncreds/types.py | 55 +++ 20 files changed, 2437 insertions(+), 14 deletions(-) create mode 100644 wrappers/javascript/packages/anoncreds-shared/src/api/W3CCredential.ts create mode 100644 wrappers/javascript/packages/anoncreds-shared/src/api/W3CCredentialOffer.ts create mode 100644 wrappers/javascript/packages/anoncreds-shared/src/api/W3CCredentialRequest.ts create mode 100644 wrappers/javascript/packages/anoncreds-shared/src/api/W3CPresentation.ts diff --git a/wrappers/javascript/package.json b/wrappers/javascript/package.json index 1514a401..d5d8995d 100644 --- a/wrappers/javascript/package.json +++ b/wrappers/javascript/package.json @@ -39,7 +39,7 @@ "eslint-plugin-import": "^2.28.1", "eslint-plugin-prettier": "^5.0.0", "jest": "^29.7.0", - "lerna": "7.2.0", + "lerna": "^7.2.0", "prettier": "^3.0.3", "ts-jest": "^29.1.1", "ts-node": "^10.9.1", diff --git a/wrappers/javascript/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts b/wrappers/javascript/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts index f4dc05e7..6723ba0e 100644 --- a/wrappers/javascript/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts +++ b/wrappers/javascript/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts @@ -102,6 +102,16 @@ export class NodeJSAnoncreds implements Anoncreds { return handleReturnPointer(ret) } + public w3cCredentialGetAttribute(options: { objectHandle: ObjectHandle; name: string }) { + const { objectHandle, name } = serializeArguments(options) + + const ret = allocateStringBuffer() + this.nativeAnoncreds.anoncreds_w3c_credential_get_attribute(objectHandle, name, ret) + this.handleError() + + return handleReturnPointer(ret) + } + public createCredentialDefinition(options: { schemaId: string schema: ObjectHandle @@ -617,6 +627,366 @@ export class NodeJSAnoncreds implements Anoncreds { return new ObjectHandle(handleReturnPointer(ret)) } + public createW3CCredentialOffer(options: { + schemaId: string + credentialDefinitionId: string + keyCorrectnessProof: ObjectHandle + }): ObjectHandle { + const { schemaId, credentialDefinitionId, keyCorrectnessProof } = serializeArguments(options) + + const ret = allocatePointer() + this.nativeAnoncreds.anoncreds_create_w3c_credential_offer( + schemaId, + credentialDefinitionId, + keyCorrectnessProof, + ret + ) + this.handleError() + + return new ObjectHandle(handleReturnPointer(ret)) + } + + public createW3CCredentialRequest(options: { + entropy?: string + proverDid?: string + credentialDefinition: ObjectHandle + linkSecret: string + linkSecretId: string + credentialOffer: ObjectHandle + }): { credentialRequest: ObjectHandle; credentialRequestMetadata: ObjectHandle } { + const { entropy, proverDid, credentialDefinition, linkSecret, linkSecretId, credentialOffer } = + serializeArguments(options) + + const credentialRequestPtr = allocatePointer() + const credentialRequestMetadataPtr = allocatePointer() + + this.nativeAnoncreds.anoncreds_create_w3c_credential_request( + entropy, + proverDid, + credentialDefinition, + linkSecret, + linkSecretId, + credentialOffer, + credentialRequestPtr, + credentialRequestMetadataPtr + ) + this.handleError() + + return { + credentialRequest: new ObjectHandle(handleReturnPointer(credentialRequestPtr)), + credentialRequestMetadata: new ObjectHandle(handleReturnPointer(credentialRequestMetadataPtr)) + } + } + + public createW3CCredential(options: { + credentialDefinition: ObjectHandle + credentialDefinitionPrivate: ObjectHandle + credentialOffer: ObjectHandle + credentialRequest: ObjectHandle + attributeRawValues: Record + revocationConfiguration?: NativeCredentialRevocationConfig + encoding?: string + }): ObjectHandle { + const { credentialDefinition, credentialDefinitionPrivate, credentialOffer, credentialRequest } = + serializeArguments(options) + + const attributeNames = StringListStruct({ + count: Object.keys(options.attributeRawValues).length, + data: Object.keys(options.attributeRawValues) as unknown as TypedArray + }) + + const attributeRawValues = StringListStruct({ + count: Object.keys(options.attributeRawValues).length, + data: Object.values(options.attributeRawValues) as unknown as TypedArray + }) + + let revocationConfiguration + if (options.revocationConfiguration) { + const { revocationRegistryDefinition, revocationRegistryDefinitionPrivate, revocationStatusList, registryIndex } = + serializeArguments(options.revocationConfiguration) + + revocationConfiguration = CredRevInfoStruct({ + reg_def: revocationRegistryDefinition, + reg_def_private: revocationRegistryDefinitionPrivate, + status_list: revocationStatusList, + reg_idx: registryIndex + }) + } + + const credentialPtr = allocatePointer() + this.nativeAnoncreds.anoncreds_create_w3c_credential( + credentialDefinition, + credentialDefinitionPrivate, + credentialOffer, + credentialRequest, + attributeNames as unknown as Buffer, + attributeRawValues as unknown as Buffer, + revocationConfiguration?.ref().address() ?? 0, + options.encoding, + credentialPtr + ) + this.handleError() + + return new ObjectHandle(handleReturnPointer(credentialPtr)) + } + + public processW3CCredential(options: { + credential: ObjectHandle + credentialRequestMetadata: ObjectHandle + linkSecret: string + credentialDefinition: ObjectHandle + revocationRegistryDefinition?: ObjectHandle | undefined + }): ObjectHandle { + const { credential, credentialRequestMetadata, linkSecret, credentialDefinition } = serializeArguments(options) + + const ret = allocatePointer() + + this.nativeAnoncreds.anoncreds_process_w3c_credential( + credential, + credentialRequestMetadata, + linkSecret, + credentialDefinition, + options.revocationRegistryDefinition?.handle ?? 0, + ret + ) + this.handleError() + + return new ObjectHandle(handleReturnPointer(ret)) + } + + public createW3CPresentation(options: { + presentationRequest: ObjectHandle + credentials: NativeCredentialEntry[] + credentialsProve: NativeCredentialProve[] + linkSecret: string + schemas: Record + credentialDefinitions: Record + }): ObjectHandle { + const { presentationRequest, linkSecret } = serializeArguments(options) + + const credentialEntries = options.credentials.map((value) => + CredentialEntryStruct({ + credential: value.credential.handle, + timestamp: value.timestamp ?? -1, + rev_state: value.revocationState?.handle ?? 0 + }) + ) + + const credentialEntryList = CredentialEntryListStruct({ + count: credentialEntries.length, + data: credentialEntries as unknown as TypedArray< + StructObject<{ + credential: number + timestamp: number + rev_state: number + }> + > + }) + + const credentialProves = options.credentialsProve.map((value) => { + const { entryIndex: entry_idx, isPredicate: is_predicate, reveal, referent } = serializeArguments(value) + return CredentialProveStruct({ entry_idx, referent, is_predicate, reveal }) + }) + + const credentialProveList = CredentialProveListStruct({ + count: credentialProves.length, + data: credentialProves as unknown as TypedArray< + StructObject<{ + entry_idx: string | number + referent: string + is_predicate: number + reveal: number + }> + > + }) + + const schemaKeys = Object.keys(options.schemas) + const schemaIds = StringListStruct({ + count: schemaKeys.length, + data: schemaKeys as unknown as TypedArray + }) + + const schemaValues = Object.values(options.schemas) + const schemas = ObjectHandleListStruct({ + count: schemaValues.length, + data: ObjectHandleArray(schemaValues.map((o) => o.handle)) + }) + + const credentialDefinitionKeys = Object.keys(options.credentialDefinitions) + const credentialDefinitionIds = StringListStruct({ + count: credentialDefinitionKeys.length, + data: credentialDefinitionKeys as unknown as TypedArray + }) + + const credentialDefinitionValues = Object.values(options.credentialDefinitions) + const credentialDefinitions = ObjectHandleListStruct({ + count: credentialDefinitionValues.length, + data: ObjectHandleArray(credentialDefinitionValues.map((o) => o.handle)) + }) + + const ret = allocatePointer() + + this.nativeAnoncreds.anoncreds_create_w3c_presentation( + presentationRequest, + credentialEntryList as unknown as Buffer, + credentialProveList as unknown as Buffer, + linkSecret, + schemas as unknown as Buffer, + schemaIds as unknown as Buffer, + credentialDefinitions as unknown as Buffer, + credentialDefinitionIds as unknown as Buffer, + ret + ) + this.handleError() + + return new ObjectHandle(handleReturnPointer(ret)) + } + + public verifyW3CPresentation(options: { + presentation: ObjectHandle + presentationRequest: ObjectHandle + schemas: ObjectHandle[] + schemaIds: string[] + credentialDefinitions: ObjectHandle[] + credentialDefinitionIds: string[] + revocationRegistryDefinitions?: ObjectHandle[] + revocationRegistryDefinitionIds?: string[] + revocationStatusLists?: ObjectHandle[] + nonRevokedIntervalOverrides?: NativeNonRevokedIntervalOverride[] + }): boolean { + const { + presentation, + presentationRequest, + schemas, + credentialDefinitions, + revocationRegistryDefinitions, + revocationStatusLists, + revocationRegistryDefinitionIds, + schemaIds, + credentialDefinitionIds + } = serializeArguments(options) + + const nativeNonRevokedIntervalOverrides = options.nonRevokedIntervalOverrides?.map((value) => { + const { requestedFromTimestamp, revocationRegistryDefinitionId, overrideRevocationStatusListTimestamp } = + serializeArguments(value) + return NonRevokedIntervalOverrideStruct({ + rev_reg_def_id: revocationRegistryDefinitionId, + requested_from_ts: requestedFromTimestamp, + override_rev_status_list_ts: overrideRevocationStatusListTimestamp + }) + }) + + const nonRevokedIntervalOverrideList = NonRevokedIntervalOverrideListStruct({ + count: options.nonRevokedIntervalOverrides?.length ?? 0, + data: nativeNonRevokedIntervalOverrides as unknown as TypedArray< + StructObject<{ + rev_reg_def_id: string + requested_from_ts: number + override_rev_status_list_ts: number + }> + > + }) + + const ret = allocateInt8Buffer() + + this.nativeAnoncreds.anoncreds_verify_w3c_presentation( + presentation, + presentationRequest, + schemas, + schemaIds, + credentialDefinitions, + credentialDefinitionIds, + revocationRegistryDefinitions, + revocationRegistryDefinitionIds, + revocationStatusLists, + nonRevokedIntervalOverrideList as unknown as Buffer, + ret + ) + this.handleError() + + return Boolean(handleReturnPointer(ret)) + } + + public credentialToW3C(options: { objectHandle: ObjectHandle }): ObjectHandle { + const { objectHandle } = serializeArguments(options) + + const ret = allocatePointer() + + this.nativeAnoncreds.anoncreds_credential_to_w3c(objectHandle, ret) + this.handleError() + + return new ObjectHandle(handleReturnPointer(ret)) + } + + public credentialFromW3C(options: { objectHandle: ObjectHandle }): ObjectHandle { + const { objectHandle } = serializeArguments(options) + + const ret = allocatePointer() + + this.nativeAnoncreds.anoncreds_credential_from_w3c(objectHandle, ret) + this.handleError() + + return new ObjectHandle(handleReturnPointer(ret)) + } + + public w3cCredentialAddNonAnoncredsIntegrityProof(options: { + objectHandle: ObjectHandle + proof: string + }): ObjectHandle { + const { objectHandle, proof } = serializeArguments(options) + + const ret = allocatePointer() + + this.nativeAnoncreds.anoncreds_w3c_credential_add_non_anoncreds_integrity_proof(objectHandle, proof, ret) + this.handleError() + + return new ObjectHandle(handleReturnPointer(ret)) + } + + public w3cCredentialSetId(options: { objectHandle: ObjectHandle; id: string }): ObjectHandle { + const { objectHandle, id } = serializeArguments(options) + + const ret = allocatePointer() + + this.nativeAnoncreds.anoncreds_w3c_credential_set_id(objectHandle, id, ret) + this.handleError() + + return new ObjectHandle(handleReturnPointer(ret)) + } + + public w3cCredentialSetSubjectId(options: { objectHandle: ObjectHandle; id: string }): ObjectHandle { + const { objectHandle, id } = serializeArguments(options) + + const ret = allocatePointer() + + this.nativeAnoncreds.anoncreds_w3c_credential_set_subject_id(objectHandle, id, ret) + this.handleError() + + return new ObjectHandle(handleReturnPointer(ret)) + } + + public w3cCredentialAddContext(options: { objectHandle: ObjectHandle; context: string }): ObjectHandle { + const { objectHandle, context } = serializeArguments(options) + + const ret = allocatePointer() + + this.nativeAnoncreds.anoncreds_w3c_credential_add_context(objectHandle, context, ret) + this.handleError() + + return new ObjectHandle(handleReturnPointer(ret)) + } + + public w3cCredentialAddType(options: { objectHandle: ObjectHandle; type_: string }): ObjectHandle { + const { objectHandle, type_ } = serializeArguments(options) + + const ret = allocatePointer() + + this.nativeAnoncreds.anoncreds_w3c_credential_add_type(objectHandle, type_, ret) + this.handleError() + + return new ObjectHandle(handleReturnPointer(ret)) + } + public version(): string { return this.nativeAnoncreds.anoncreds_version() } @@ -706,6 +1076,22 @@ export class NodeJSAnoncreds implements Anoncreds { return this.objectFromJson(this.nativeAnoncreds.anoncreds_key_correctness_proof_from_json, options) } + public w3cCredentialOfferFromJson(options: { json: string }): ObjectHandle { + return this.objectFromJson(this.nativeAnoncreds.anoncreds_credential_offer_from_json, options) + } + + public w3cCredentialRequestFromJson(options: { json: string }): ObjectHandle { + return this.objectFromJson(this.nativeAnoncreds.anoncreds_credential_request_from_json, options) + } + + public w3cCredentialFromJson(options: { json: string }): ObjectHandle { + return this.objectFromJson(this.nativeAnoncreds.anoncreds_w3c_credential_from_json, options) + } + + public w3cPresentationFromJson(options: { json: string }): ObjectHandle { + return this.objectFromJson(this.nativeAnoncreds.anoncreds_w3c_presentation_from_json, options) + } + public getJson(options: { objectHandle: ObjectHandle }) { const ret = allocateByteBuffer() diff --git a/wrappers/javascript/packages/anoncreds-nodejs/src/library/bindings.ts b/wrappers/javascript/packages/anoncreds-nodejs/src/library/bindings.ts index a8ffc7ab..8a5a265e 100644 --- a/wrappers/javascript/packages/anoncreds-nodejs/src/library/bindings.ts +++ b/wrappers/javascript/packages/anoncreds-nodejs/src/library/bindings.ts @@ -147,7 +147,6 @@ export const nativeBindings = { FFI_INT8_PTR ] ], - anoncreds_create_revocation_status_list: [ FFI_ERRORCODE, [ @@ -192,5 +191,83 @@ export const nativeBindings = { anoncreds_credential_definition_private_from_json: [FFI_ERRORCODE, [ByteBufferStruct, FFI_STRING_PTR]], anoncreds_revocation_registry_definition_private_from_json: [FFI_ERRORCODE, [ByteBufferStruct, FFI_STRING_PTR]], anoncreds_key_correctness_proof_from_json: [FFI_ERRORCODE, [ByteBufferStruct, FFI_STRING_PTR]], - anoncreds_schema_from_json: [FFI_ERRORCODE, [ByteBufferStruct, FFI_STRING_PTR]] + anoncreds_schema_from_json: [FFI_ERRORCODE, [ByteBufferStruct, FFI_STRING_PTR]], + anoncreds_create_w3c_credential_offer: [ + FFI_ERRORCODE, + [FFI_STRING, FFI_STRING, FFI_OBJECT_HANDLE, FFI_OBJECT_HANDLE_PTR] + ], + anoncreds_create_w3c_credential_request: [ + FFI_ERRORCODE, + [ + FFI_STRING, + FFI_STRING, + FFI_OBJECT_HANDLE, + FFI_STRING, + FFI_STRING, + FFI_OBJECT_HANDLE, + FFI_OBJECT_HANDLE_PTR, + FFI_OBJECT_HANDLE_PTR + ] + ], + anoncreds_create_w3c_credential: [ + FFI_ERRORCODE, + [ + FFI_OBJECT_HANDLE, + FFI_OBJECT_HANDLE, + FFI_OBJECT_HANDLE, + FFI_OBJECT_HANDLE, + StringListStruct, + StringListStruct, + FFI_OBJECT_HANDLE, + FFI_STRING, + FFI_OBJECT_HANDLE_PTR + ] + ], + anoncreds_process_w3c_credential: [ + FFI_ERRORCODE, + [FFI_OBJECT_HANDLE, FFI_OBJECT_HANDLE, FFI_STRING, FFI_OBJECT_HANDLE, FFI_OBJECT_HANDLE, FFI_OBJECT_HANDLE_PTR] + ], + anoncreds_create_w3c_presentation: [ + FFI_ERRORCODE, + [ + FFI_OBJECT_HANDLE, + CredentialEntryListStruct, + CredentialProveListStruct, + FFI_STRING, + ObjectHandleListStruct, + StringListStruct, + ObjectHandleListStruct, + StringListStruct, + FFI_OBJECT_HANDLE_PTR + ] + ], + anoncreds_verify_w3c_presentation: [ + FFI_ERRORCODE, + [ + FFI_OBJECT_HANDLE, + FFI_OBJECT_HANDLE, + ObjectHandleListStruct, + StringListStruct, + ObjectHandleListStruct, + StringListStruct, + ObjectHandleListStruct, + StringListStruct, + ObjectHandleListStruct, + NonRevokedIntervalOverrideListStruct, + FFI_INT8_PTR + ] + ], + anoncreds_credential_to_w3c: [FFI_ERRORCODE, [FFI_OBJECT_HANDLE, FFI_OBJECT_HANDLE_PTR]], + anoncreds_credential_from_w3c: [FFI_ERRORCODE, [FFI_OBJECT_HANDLE, FFI_OBJECT_HANDLE_PTR]], + anoncreds_w3c_credential_add_non_anoncreds_integrity_proof: [ + FFI_ERRORCODE, + [FFI_OBJECT_HANDLE, FFI_STRING, FFI_OBJECT_HANDLE_PTR] + ], + anoncreds_w3c_credential_set_id: [FFI_ERRORCODE, [FFI_OBJECT_HANDLE, FFI_STRING, FFI_OBJECT_HANDLE_PTR]], + anoncreds_w3c_credential_set_subject_id: [FFI_ERRORCODE, [FFI_OBJECT_HANDLE, FFI_STRING, FFI_OBJECT_HANDLE_PTR]], + anoncreds_w3c_credential_add_context: [FFI_ERRORCODE, [FFI_OBJECT_HANDLE, FFI_STRING, FFI_OBJECT_HANDLE_PTR]], + anoncreds_w3c_credential_add_type: [FFI_ERRORCODE, [FFI_OBJECT_HANDLE, FFI_STRING, FFI_OBJECT_HANDLE_PTR]], + anoncreds_w3c_credential_get_attribute: [FFI_ERRORCODE, [FFI_OBJECT_HANDLE, FFI_STRING, FFI_STRING_PTR]], + anoncreds_w3c_presentation_from_json: [FFI_ERRORCODE, [ByteBufferStruct, FFI_STRING_PTR]], + anoncreds_w3c_credential_from_json: [FFI_ERRORCODE, [ByteBufferStruct, FFI_STRING_PTR]] } as const diff --git a/wrappers/javascript/packages/anoncreds-nodejs/tests/api.test.ts b/wrappers/javascript/packages/anoncreds-nodejs/tests/api.test.ts index 6968eedb..551b029f 100644 --- a/wrappers/javascript/packages/anoncreds-nodejs/tests/api.test.ts +++ b/wrappers/javascript/packages/anoncreds-nodejs/tests/api.test.ts @@ -11,7 +11,11 @@ import { PresentationRequest, RevocationRegistryDefinition, RevocationStatusList, - Schema + Schema, + W3CCredential, + W3CCredentialOffer, + W3CCredentialRequest, + W3CPresentation } from '@hyperledger/anoncreds-shared' import { setup } from './utils' @@ -540,3 +544,298 @@ test('create and verify presentation passing only JSON objects as parameters', ( expect(verify).toBeTruthy() }) + +describe('API W3C', () => { + beforeAll(() => setup()) + + test('create and verify w3c presentation', () => { + const nonce = anoncreds.generateNonce() + + const presentationRequest = PresentationRequest.fromJson({ + nonce, + name: 'pres_req_1', + version: '0.1', + requested_attributes: { + attr1_referent: { + name: 'name', + issuer: 'mock:uri' + }, + attr2_referent: { + names: ['name', 'height'] + } + }, + requested_predicates: { + predicate1_referent: { name: 'age', p_type: '>=', p_value: 18 } + }, + non_revoked: { from: 13, to: 200 } + }) + + const schema = Schema.create({ + name: 'schema-1', + issuerId: 'mock:uri', + version: '1', + attributeNames: ['name', 'age', 'sex', 'height'] + }) + + const { credentialDefinition, keyCorrectnessProof, credentialDefinitionPrivate } = CredentialDefinition.create({ + schemaId: 'mock:uri', + issuerId: 'mock:uri', + schema, + signatureType: 'CL', + supportRevocation: true, + tag: 'TAG' + }) + + const { revocationRegistryDefinition, revocationRegistryDefinitionPrivate } = RevocationRegistryDefinition.create({ + credentialDefinitionId: 'mock:uri', + credentialDefinition, + issuerId: 'mock:uri', + tag: 'some_tag', + revocationRegistryType: 'CL_ACCUM', + maximumCredentialNumber: 10 + }) + + const tailsPath = revocationRegistryDefinition.getTailsLocation() + + const timeCreateRevStatusList = 12 + const revocationStatusList = RevocationStatusList.create({ + credentialDefinition, + revocationRegistryDefinitionId: 'mock:uri', + revocationRegistryDefinition, + revocationRegistryDefinitionPrivate, + issuerId: 'mock:uri', + issuanceByDefault: true, + timestamp: timeCreateRevStatusList + }) + + const credentialOffer = W3CCredentialOffer.create({ + schemaId: 'mock:uri', + credentialDefinitionId: 'mock:uri', + keyCorrectnessProof + }) + + const linkSecret = LinkSecret.create() + const linkSecretId = 'link secret id' + + const { credentialRequestMetadata, credentialRequest } = W3CCredentialRequest.create({ + entropy: 'entropy', + credentialDefinition, + linkSecret, + linkSecretId, + credentialOffer + }) + + const credential = W3CCredential.create({ + credentialDefinition, + credentialDefinitionPrivate, + credentialOffer, + credentialRequest, + attributeRawValues: { name: 'Alex', height: '175', age: '28', sex: 'male' }, + revocationConfiguration: new CredentialRevocationConfig({ + registryDefinition: revocationRegistryDefinition, + registryDefinitionPrivate: revocationRegistryDefinitionPrivate, + statusList: revocationStatusList, + registryIndex: 9 + }) + }) + + const legacyCredential = credential.toLegacy() + expect('mock:uri').toEqual(legacyCredential.schemaId) + expect('mock:uri').toEqual(legacyCredential.credentialDefinitionId) + + const w3cCredential = W3CCredential.fromLegacy(legacyCredential) + expect('mock:uri').toEqual(w3cCredential.schemaId) + expect('mock:uri').toEqual(w3cCredential.credentialDefinitionId) + + const credentialReceived = credential.process({ + credentialDefinition, + credentialRequestMetadata, + linkSecret, + revocationRegistryDefinition + }) + + const revocationRegistryIndex = credentialReceived.revocationRegistryIndex ?? 0 + + const revocationState = CredentialRevocationState.create({ + revocationRegistryDefinition, + revocationStatusList, + revocationRegistryIndex, + tailsPath + }) + + const presentation = W3CPresentation.create({ + presentationRequest, + credentials: [ + { + credential: credentialReceived, + revocationState, + timestamp: timeCreateRevStatusList + } + ], + credentialDefinitions: { 'mock:uri': credentialDefinition }, + credentialsProve: [ + { + entryIndex: 0, + isPredicate: false, + referent: 'attr1_referent', + reveal: true + }, + { + entryIndex: 0, + isPredicate: false, + referent: 'attr2_referent', + reveal: true + }, + { + entryIndex: 0, + isPredicate: true, + referent: 'predicate1_referent', + reveal: true + } + ], + linkSecret, + schemas: { 'mock:uri': schema } + }) + + expect(presentation.handle.handle).toStrictEqual(expect.any(Number)) + + // Without revocation timestamp override, it shall fail + expect(() => { + presentation.verify({ + presentationRequest, + schemas: { 'mock:uri': schema }, + credentialDefinitions: { 'mock:uri': credentialDefinition }, + revocationRegistryDefinitions: { 'mock:uri': revocationRegistryDefinition }, + revocationStatusLists: [revocationStatusList] + }) + }).toThrowError('Invalid timestamp') + + const verify = presentation.verify({ + presentationRequest, + schemas: { 'mock:uri': schema }, + credentialDefinitions: { 'mock:uri': credentialDefinition }, + revocationRegistryDefinitions: { 'mock:uri': revocationRegistryDefinition }, + revocationStatusLists: [revocationStatusList], + nonRevokedIntervalOverrides: [ + { + overrideRevocationStatusListTimestamp: 12, + requestedFromTimestamp: 13, + revocationRegistryDefinitionId: 'mock:uri' + } + ] + }) + + expect(verify).toBeTruthy() + }) + + test('create and verify w3c presentation (no revocation use case)', () => { + const schema = Schema.create({ + name: 'schema-1', + issuerId: 'mock:uri', + version: '1', + attributeNames: ['name', 'age', 'sex', 'height'] + }) + + const { credentialDefinition, keyCorrectnessProof, credentialDefinitionPrivate } = CredentialDefinition.create({ + schemaId: 'mock:uri', + issuerId: 'mock:uri', + schema, + signatureType: 'CL', + supportRevocation: false, + tag: 'TAG' + }) + + const credentialOffer = W3CCredentialOffer.create({ + schemaId: 'mock:uri', + credentialDefinitionId: 'mock:uri', + keyCorrectnessProof + }) + + const linkSecret = LinkSecret.create() + const linkSecretId = 'link secret id' + + const { credentialRequestMetadata, credentialRequest } = W3CCredentialRequest.create({ + entropy: 'entropy', + credentialDefinition, + linkSecret, + linkSecretId, + credentialOffer + }) + + const credential = W3CCredential.create({ + credentialDefinition, + credentialDefinitionPrivate, + credentialOffer, + credentialRequest, + attributeRawValues: { name: 'Alex', height: '175', age: '28', sex: 'male' } + }) + + const credReceived = credential.process({ + credentialDefinition, + credentialRequestMetadata, + linkSecret + }) + + const nonce = anoncreds.generateNonce() + + const presentationRequest = PresentationRequest.fromJson({ + nonce, + name: 'pres_req_1', + version: '0.1', + requested_attributes: { + attr1_referent: { + name: 'name', + issuer: 'mock:uri' + }, + attr2_referent: { + names: ['name', 'height'] + } + }, + requested_predicates: { + predicate1_referent: { name: 'age', p_type: '>=', p_value: 18 } + } + }) + + const presentation = W3CPresentation.create({ + presentationRequest, + credentials: [ + { + credential: credReceived + } + ], + credentialDefinitions: { 'mock:uri': credentialDefinition }, + credentialsProve: [ + { + entryIndex: 0, + isPredicate: false, + referent: 'attr1_referent', + reveal: true + }, + { + entryIndex: 0, + isPredicate: false, + referent: 'attr2_referent', + reveal: true + }, + { + entryIndex: 0, + isPredicate: true, + referent: 'predicate1_referent', + reveal: true + } + ], + linkSecret, + schemas: { 'mock:uri': schema } + }) + + expect(presentation.handle.handle).toStrictEqual(expect.any(Number)) + + const verify = presentation.verify({ + presentationRequest, + schemas: { 'mock:uri': schema }, + credentialDefinitions: { 'mock:uri': credentialDefinition } + }) + + expect(verify).toBeTruthy() + }) +}) diff --git a/wrappers/javascript/packages/anoncreds-nodejs/tests/bindings.test.ts b/wrappers/javascript/packages/anoncreds-nodejs/tests/bindings.test.ts index 0d190790..741a448a 100644 --- a/wrappers/javascript/packages/anoncreds-nodejs/tests/bindings.test.ts +++ b/wrappers/javascript/packages/anoncreds-nodejs/tests/bindings.test.ts @@ -329,6 +329,94 @@ describe('bindings', () => { expect(JSON.parse(credReceivedJson)).toHaveProperty('witness') }) + test('create and receive w3c credential', () => { + const schemaObj = anoncreds.createSchema({ + name: 'schema-1', + issuerId: 'mock:uri', + version: '1', + attributeNames: ['attr-1'] + }) + + const { credentialDefinition, keyCorrectnessProof, credentialDefinitionPrivate } = + anoncreds.createCredentialDefinition({ + schemaId: 'mock:uri', + issuerId: 'mock:uri', + schema: schemaObj, + signatureType: 'CL', + supportRevocation: true, + tag: 'TAG' + }) + + const { revocationRegistryDefinition, revocationRegistryDefinitionPrivate } = + anoncreds.createRevocationRegistryDefinition({ + credentialDefinitionId: 'mock:uri', + credentialDefinition, + issuerId: 'mock:uri', + tag: 'some_tag', + revocationRegistryType: 'CL_ACCUM', + maximumCredentialNumber: 10 + }) + + const tailsPath = anoncreds.revocationRegistryDefinitionGetAttribute({ + objectHandle: revocationRegistryDefinition, + name: 'tails_location' + }) + expect(tailsPath).toBeTruthy() + + const timeCreateRevStatusList = 12 + const revocationStatusList = anoncreds.createRevocationStatusList({ + credentialDefinition, + revocationRegistryDefinitionId: 'mock:uri', + revocationRegistryDefinition, + revocationRegistryDefinitionPrivate, + issuerId: 'mock:uri', + issuanceByDefault: true, + timestamp: timeCreateRevStatusList + }) + + const credentialOffer = anoncreds.createW3CCredentialOffer({ + schemaId: 'mock:uri', + credentialDefinitionId: 'mock:uri', + keyCorrectnessProof + }) + + const linkSecret = anoncreds.createLinkSecret() + const linkSecretId = 'link secret id' + + const { credentialRequestMetadata, credentialRequest } = anoncreds.createW3CCredentialRequest({ + entropy: ENTROPY, + credentialDefinition, + linkSecret, + linkSecretId, + credentialOffer + }) + + const credential = anoncreds.createW3CCredential({ + credentialDefinition, + credentialDefinitionPrivate, + credentialOffer, + credentialRequest, + revocationConfiguration: { + revocationRegistryDefinition, + revocationRegistryDefinitionPrivate, + revocationStatusList, + registryIndex: 9 + }, + attributeRawValues: { 'attr-1': 'test' }, + encoding: undefined + }) + + const credReceived = anoncreds.processW3CCredential({ + credential, + credentialDefinition, + credentialRequestMetadata, + linkSecret, + revocationRegistryDefinition + }) + + anoncreds.getJson({ objectHandle: credReceived }) + }) + test('create and verify presentation', () => { const nonce = anoncreds.generateNonce() @@ -515,6 +603,180 @@ describe('bindings', () => { expect(verify).toBeTruthy() }) + test('create and verify w3c presentation', () => { + const nonce = anoncreds.generateNonce() + + const presentationRequest = anoncreds.presentationRequestFromJson({ + json: JSON.stringify({ + nonce, + name: 'pres_req_1', + version: '0.1', + requested_attributes: { + attr1_referent: { + name: 'name', + issuer: 'mock:uri' + }, + attr2_referent: { + names: ['name', 'height'] + } + }, + requested_predicates: { + predicate1_referent: { name: 'age', p_type: '>=', p_value: 18 } + }, + non_revoked: { from: 10, to: 200 } + }) + }) + + expect(anoncreds.getTypeName({ objectHandle: presentationRequest })).toEqual('PresentationRequest') + + const schemaObj = anoncreds.createSchema({ + name: 'schema-1', + issuerId: 'mock:uri', + version: '1', + attributeNames: ['name', 'age', 'sex', 'height'] + }) + + const { credentialDefinition, keyCorrectnessProof, credentialDefinitionPrivate } = + anoncreds.createCredentialDefinition({ + schemaId: 'mock:uri', + issuerId: 'mock:uri', + schema: schemaObj, + signatureType: 'CL', + supportRevocation: true, + tag: 'TAG' + }) + + const { revocationRegistryDefinition, revocationRegistryDefinitionPrivate } = + anoncreds.createRevocationRegistryDefinition({ + credentialDefinitionId: 'mock:uri', + credentialDefinition, + issuerId: 'mock:uri', + tag: 'some_tag', + revocationRegistryType: 'CL_ACCUM', + maximumCredentialNumber: 10 + }) + + const tailsPath = anoncreds.revocationRegistryDefinitionGetAttribute({ + objectHandle: revocationRegistryDefinition, + name: 'tails_location' + }) + + const timeCreateRevStatusList = 12 + const revocationStatusList = anoncreds.createRevocationStatusList({ + credentialDefinition, + revocationRegistryDefinitionId: 'mock:uri', + revocationRegistryDefinition, + revocationRegistryDefinitionPrivate, + issuerId: 'mock:uri', + issuanceByDefault: true, + timestamp: timeCreateRevStatusList + }) + + const credentialOffer = anoncreds.createW3CCredentialOffer({ + schemaId: 'mock:uri', + credentialDefinitionId: 'mock:uri', + keyCorrectnessProof + }) + + const linkSecret = anoncreds.createLinkSecret() + const linkSecretId = 'link secret id' + + const { credentialRequestMetadata, credentialRequest } = anoncreds.createW3CCredentialRequest({ + entropy: ENTROPY, + credentialDefinition, + linkSecret, + linkSecretId, + credentialOffer + }) + + const credential = anoncreds.createW3CCredential({ + credentialDefinition, + credentialDefinitionPrivate, + credentialOffer, + credentialRequest, + revocationConfiguration: { + revocationRegistryDefinition, + revocationRegistryDefinitionPrivate, + revocationStatusList, + registryIndex: 9 + }, + attributeRawValues: { name: 'Alex', height: '175', age: '28', sex: 'male' }, + encoding: undefined + }) + + const credentialReceived = anoncreds.processW3CCredential({ + credential, + credentialDefinition, + credentialRequestMetadata, + linkSecret, + revocationRegistryDefinition + }) + + const revRegIndex = anoncreds.w3cCredentialGetAttribute({ + objectHandle: credentialReceived, + name: 'rev_reg_index' + }) + + const revocationRegistryIndex = revRegIndex === null ? 0 : parseInt(revRegIndex) + + const revocationState = anoncreds.createOrUpdateRevocationState({ + revocationRegistryDefinition, + revocationStatusList, + revocationRegistryIndex, + tailsPath + }) + + const presentation = anoncreds.createW3CPresentation({ + presentationRequest, + credentials: [ + { + credential: credentialReceived, + revocationState, + timestamp: timeCreateRevStatusList + } + ], + credentialDefinitions: { 'mock:uri': credentialDefinition }, + credentialsProve: [ + { + entryIndex: 0, + isPredicate: false, + referent: 'attr1_referent', + reveal: true + }, + { + entryIndex: 0, + isPredicate: false, + referent: 'attr2_referent', + reveal: true + }, + { + entryIndex: 0, + isPredicate: true, + referent: 'predicate1_referent', + reveal: true + } + ], + linkSecret, + schemas: { 'mock:uri': schemaObj } + }) + + expect(presentation.handle).toStrictEqual(expect.any(Number)) + + const verify = anoncreds.verifyW3CPresentation({ + presentation, + presentationRequest, + schemas: [schemaObj], + schemaIds: ['mock:uri'], + credentialDefinitions: [credentialDefinition], + credentialDefinitionIds: ['mock:uri'], + revocationRegistryDefinitions: [revocationRegistryDefinition], + revocationRegistryDefinitionIds: ['mock:uri'], + revocationStatusLists: [revocationStatusList] + }) + + expect(verify).toBeTruthy() + }) + test('create and verify presentation (no revocation use case)', () => { const schemaObj = anoncreds.createSchema({ name: 'schema-1', @@ -663,4 +925,122 @@ describe('bindings', () => { expect(verify).toBeTruthy() }) + + test('create and verify w3c presentation (no revocation use case)', () => { + const schemaObj = anoncreds.createSchema({ + name: 'schema-1', + issuerId: 'mock:uri', + version: '1', + attributeNames: ['name', 'age', 'sex', 'height'] + }) + + const { credentialDefinition, keyCorrectnessProof, credentialDefinitionPrivate } = + anoncreds.createCredentialDefinition({ + schemaId: 'mock:uri', + issuerId: 'mock:uri', + schema: schemaObj, + signatureType: 'CL', + supportRevocation: false, + tag: 'TAG' + }) + + const credentialOffer = anoncreds.createW3CCredentialOffer({ + schemaId: 'mock:uri', + credentialDefinitionId: 'mock:uri', + keyCorrectnessProof + }) + + const linkSecret = anoncreds.createLinkSecret() + const linkSecretId = 'link secret id' + + const { credentialRequestMetadata, credentialRequest } = anoncreds.createW3CCredentialRequest({ + entropy: ENTROPY, + credentialDefinition, + linkSecret, + linkSecretId, + credentialOffer + }) + + const credential = anoncreds.createW3CCredential({ + credentialDefinition, + credentialDefinitionPrivate, + credentialOffer, + credentialRequest, + attributeRawValues: { name: 'Alex', height: '175', age: '28', sex: 'male' } + }) + + const credReceived = anoncreds.processW3CCredential({ + credential, + credentialDefinition, + credentialRequestMetadata, + linkSecret + }) + + const nonce = anoncreds.generateNonce() + + const presentationRequest = anoncreds.presentationRequestFromJson({ + json: JSON.stringify({ + nonce, + name: 'pres_req_1', + version: '0.1', + requested_attributes: { + attr1_referent: { + name: 'name', + issuer: 'mock:uri' + }, + attr2_referent: { + names: ['name', 'height'] + } + }, + requested_predicates: { + predicate1_referent: { name: 'age', p_type: '>=', p_value: 18 } + } + }) + }) + + const presentation = anoncreds.createW3CPresentation({ + presentationRequest, + credentials: [ + { + credential: credReceived + } + ], + credentialDefinitions: { 'mock:uri': credentialDefinition }, + credentialsProve: [ + { + entryIndex: 0, + isPredicate: false, + referent: 'attr1_referent', + reveal: true + }, + { + entryIndex: 0, + isPredicate: false, + referent: 'attr2_referent', + reveal: true + }, + { + entryIndex: 0, + isPredicate: true, + referent: 'predicate1_referent', + reveal: true + } + ], + linkSecret, + schemas: { 'mock:uri': schemaObj } + }) + + expect(presentation.handle).toStrictEqual(expect.any(Number)) + + const verify = anoncreds.verifyW3CPresentation({ + presentation, + presentationRequest, + schemas: [schemaObj], + schemaIds: ['mock:uri'], + credentialDefinitions: [credentialDefinition], + credentialDefinitionIds: ['mock:uri'] + }) + + expect(verify).toBeTruthy() + }) }) diff --git a/wrappers/javascript/packages/anoncreds-react-native/cpp/HostObject.cpp b/wrappers/javascript/packages/anoncreds-react-native/cpp/HostObject.cpp index e6980c22..b12ac831 100644 --- a/wrappers/javascript/packages/anoncreds-react-native/cpp/HostObject.cpp +++ b/wrappers/javascript/packages/anoncreds-react-native/cpp/HostObject.cpp @@ -15,23 +15,33 @@ FunctionMap AnoncredsTurboModuleHostObject::functionMapping(jsi::Runtime &rt) { fMap.insert(std::make_tuple("getCurrentError", &anoncreds::getCurrentError)); fMap.insert( std::make_tuple("createCredential", &anoncreds::createCredential)); + fMap.insert( + std::make_tuple("createW3CCredential", &anoncreds::createW3CCredential)); fMap.insert(std::make_tuple("createCredentialDefinition", &anoncreds::createCredentialDefinition)); fMap.insert(std::make_tuple("createCredentialOffer", &anoncreds::createCredentialOffer)); + fMap.insert(std::make_tuple("createW3CCredentialOffer", + &anoncreds::createW3CCredentialOffer)); fMap.insert(std::make_tuple("createCredentialRequest", &anoncreds::createCredentialRequest)); + fMap.insert(std::make_tuple("createW3CCredentialRequest", + &anoncreds::createW3CCredentialRequest)); fMap.insert( std::make_tuple("createLinkSecret", &anoncreds::createLinkSecret)); fMap.insert(std::make_tuple("createOrUpdateRevocationState", &anoncreds::createOrUpdateRevocationState)); fMap.insert( std::make_tuple("createPresentation", &anoncreds::createPresentation)); + fMap.insert( + std::make_tuple("createW3CPresentation", &anoncreds::createW3CPresentation)); fMap.insert(std::make_tuple("createRevocationRegistryDefinition", &anoncreds::createRevocationRegistryDefinition)); fMap.insert(std::make_tuple("createSchema", &anoncreds::createSchema)); fMap.insert(std::make_tuple("credentialGetAttribute", &anoncreds::credentialGetAttribute)); + fMap.insert(std::make_tuple("w3cCredentialGetAttribute", + &anoncreds::w3cCredentialGetAttribute)); fMap.insert(std::make_tuple("encodeCredentialAttributes", &anoncreds::encodeCredentialAttributes)); fMap.insert(std::make_tuple("generateNonce", &anoncreds::generateNonce)); @@ -39,6 +49,8 @@ FunctionMap AnoncredsTurboModuleHostObject::functionMapping(jsi::Runtime &rt) { fMap.insert(std::make_tuple("getTypeName", &anoncreds::getTypeName)); fMap.insert( std::make_tuple("processCredential", &anoncreds::processCredential)); + fMap.insert( + std::make_tuple("processW3CCredential", &anoncreds::processW3CCredential)); fMap.insert( std::make_tuple("revocationRegistryDefinitionGetAttribute", &anoncreds::revocationRegistryDefinitionGetAttribute)); @@ -46,6 +58,8 @@ FunctionMap AnoncredsTurboModuleHostObject::functionMapping(jsi::Runtime &rt) { std::make_tuple("setDefaultLogger", &anoncreds::setDefaultLogger)); fMap.insert( std::make_tuple("verifyPresentation", &anoncreds::verifyPresentation)); + fMap.insert( + std::make_tuple("verifyW3CPresentation", &anoncreds::verifyW3CPresentation)); fMap.insert(std::make_tuple("createRevocationStatusList", &anoncreds::createRevocationStatusList)); fMap.insert(std::make_tuple("updateRevocationStatusList", @@ -65,17 +79,25 @@ fMap.insert(std::make_tuple("createRevocationStatusList", &anoncreds::revocationStatusListFromJson)); fMap.insert(std::make_tuple("presentationFromJson", &anoncreds::presentationFromJson)); + fMap.insert(std::make_tuple("w3cPresentationFromJson", + &anoncreds::w3cPresentationFromJson)); fMap.insert(std::make_tuple("presentationRequestFromJson", &anoncreds::presentationRequestFromJson)); fMap.insert(std::make_tuple("credentialOfferFromJson", &anoncreds::credentialOfferFromJson)); + fMap.insert(std::make_tuple("w3cCredentialOfferFromJson", + &anoncreds::w3cCredentialOfferFromJson)); fMap.insert(std::make_tuple("schemaFromJson", &anoncreds::schemaFromJson)); fMap.insert(std::make_tuple("credentialRequestFromJson", &anoncreds::credentialRequestFromJson)); + fMap.insert(std::make_tuple("w3cCredentialRequestFromJson", + &anoncreds::w3cCredentialRequestFromJson)); fMap.insert(std::make_tuple("credentialRequestMetadataFromJson", &anoncreds::credentialRequestMetadataFromJson)); fMap.insert( std::make_tuple("credentialFromJson", &anoncreds::credentialFromJson)); + fMap.insert( + std::make_tuple("w3cCredentialFromJson", &anoncreds::w3cCredentialFromJson)); fMap.insert( std::make_tuple("revocationRegistryDefinitionPrivateFromJson", &anoncreds::revocationRegistryDefinitionPrivateFromJson)); @@ -87,6 +109,27 @@ fMap.insert(std::make_tuple("createRevocationStatusList", &anoncreds::credentialDefinitionPrivateFromJson)); fMap.insert(std::make_tuple("keyCorrectnessProofFromJson", &anoncreds::keyCorrectnessProofFromJson)); + fMap.insert( + std::make_tuple("w3cCredentialAddNonAnonCredsIntegrityProof", + &anoncreds::w3cCredentialAddNonAnonCredsIntegrityProof)); + fMap.insert( + std::make_tuple("w3cCredentialSetId", + &anoncreds::w3cCredentialSetId)); + fMap.insert( + std::make_tuple("w3cCredentialSetSubjectId", + &anoncreds::w3cCredentialSetSubjectId)); + fMap.insert( + std::make_tuple("w3cCredentialAddContext", + &anoncreds::w3cCredentialAddContext)); + fMap.insert( + std::make_tuple("w3cCredentialAddType", + &anoncreds::w3cCredentialAddType)); + fMap.insert( + std::make_tuple("credentialToW3C", + &anoncreds::credentialToW3C)); + fMap.insert( + std::make_tuple("credentialFromW3C", + &anoncreds::credentialFromW3C)); return fMap; } diff --git a/wrappers/javascript/packages/anoncreds-react-native/cpp/anoncreds.cpp b/wrappers/javascript/packages/anoncreds-react-native/cpp/anoncreds.cpp index fb5ac140..71dd40df 100644 --- a/wrappers/javascript/packages/anoncreds-react-native/cpp/anoncreds.cpp +++ b/wrappers/javascript/packages/anoncreds-react-native/cpp/anoncreds.cpp @@ -682,4 +682,325 @@ jsi::Value revocationRegistryDefinitionGetAttribute(jsi::Runtime &rt, return createReturnValue(rt, code, &out); }; +jsi::Value w3cPresentationFromJson(jsi::Runtime &rt, jsi::Object options) { + auto json = jsiToValue(rt, options, "json"); + + ObjectHandle out; + ByteBuffer b = stringToByteBuffer(json); + + ErrorCode code = anoncreds_w3c_presentation_from_json(b, &out); + auto returnValue = createReturnValue(rt, code, &out); + + // Free memory + delete[] b.data; + + return returnValue; +}; + +jsi::Value w3cCredentialOfferFromJson(jsi::Runtime &rt, jsi::Object options) { + auto json = jsiToValue(rt, options, "json"); + + ObjectHandle out; + ByteBuffer b = stringToByteBuffer(json); + + ErrorCode code = anoncreds_credential_offer_from_json(b, &out); + auto returnValue = createReturnValue(rt, code, &out); + + // Free memory + delete[] b.data; + + return returnValue; +}; + +jsi::Value w3cCredentialRequestFromJson(jsi::Runtime &rt, jsi::Object options) { + auto json = jsiToValue(rt, options, "json"); + + ObjectHandle out; + ByteBuffer b = stringToByteBuffer(json); + + ErrorCode code = anoncreds_credential_request_from_json(b, &out); + auto returnValue = createReturnValue(rt, code, &out); + + // Free memory + delete[] b.data; + + return returnValue; +}; + +jsi::Value w3cCredentialFromJson(jsi::Runtime &rt, jsi::Object options) { + auto json = jsiToValue(rt, options, "json"); + + ObjectHandle out; + ByteBuffer b = stringToByteBuffer(json); + + ErrorCode code = anoncreds_w3c_credential_from_json(b, &out); + auto returnValue = createReturnValue(rt, code, &out); + + // Free memory + delete[] b.data; + + return returnValue; +}; + +jsi::Value createW3CPresentation(jsi::Runtime &rt, jsi::Object options) { + auto presentationRequest = + jsiToValue(rt, options, "presentationRequest"); + auto credentials = + jsiToValue(rt, options, "credentials"); + auto credentialsProve = + jsiToValue(rt, options, "credentialsProve"); + auto linkSecret = jsiToValue(rt, options, "linkSecret"); + auto schemas = jsiToValue(rt, options, "schemas"); + auto schemaIds = jsiToValue(rt, options, "schemaIds"); + auto credentialDefinitions = + jsiToValue(rt, options, "credentialDefinitions"); + auto credentialDefinitionIds = + jsiToValue(rt, options, "credentialDefinitionIds"); + + ObjectHandle out; + + ErrorCode code = anoncreds_create_w3c_presentation( + presentationRequest, credentials, credentialsProve, linkSecret.c_str(), + schemas, schemaIds, credentialDefinitions, credentialDefinitionIds, &out); + + auto returnValue = createReturnValue(rt, code, &out); + + // Free memory + delete[] credentials.data; + for (int i = 0; i < credentialsProve.count; i++) { + delete[] credentialsProve.data[i].referent; + } + for (int i = 0; i < schemaIds.count; i++) { + delete[] schemaIds.data[i]; + } + delete[] schemas.data; + for (int i = 0; i < credentialDefinitionIds.count; i++) { + delete[] credentialDefinitionIds.data[i]; + } + delete[] credentialDefinitions.data; + + return returnValue; +}; + +jsi::Value verifyW3CPresentation(jsi::Runtime &rt, jsi::Object options) { + auto presentation = jsiToValue(rt, options, "presentation"); + auto presentationRequest = + jsiToValue(rt, options, "presentationRequest"); + auto schemas = jsiToValue(rt, options, "schemas"); + auto schemaIds = jsiToValue(rt, options, "schemaIds"); + auto credentialDefinitions = + jsiToValue(rt, options, "credentialDefinitions"); + auto credentialDefinitionIds = + jsiToValue(rt, options, "credentialDefinitionIds"); + auto revocationRegistryDefinitions = jsiToValue( + rt, options, "revocationRegistryDefinitions", true); + auto revocationRegistryDefinitionIds = jsiToValue( + rt, options, "revocationRegistryDefinitionIds", true); + auto revocationStatusLists = jsiToValue( + rt, options, "revocationStatusLists", true); + auto nonRevokedIntervalOverrides = + jsiToValue( + rt, options, "nonRevokedIntervalOverrides", true); + + int8_t out; + + ErrorCode code = anoncreds_verify_w3c_presentation( + presentation, presentationRequest, schemas, schemaIds, + credentialDefinitions, credentialDefinitionIds, + revocationRegistryDefinitions, revocationRegistryDefinitionIds, + revocationStatusLists, nonRevokedIntervalOverrides, &out); + + auto returnValue = createReturnValue(rt, code, &out); + + // Free memory + for (int i = 0; i < schemaIds.count; i++) { + delete[] schemaIds.data[i]; + } + delete[] schemas.data; + for (int i = 0; i < credentialDefinitionIds.count; i++) { + delete[] credentialDefinitionIds.data[i]; + } + delete[] credentialDefinitions.data; + + return returnValue; +}; + +jsi::Value createW3CCredential(jsi::Runtime &rt, jsi::Object options) { + auto credentialDefinition = + jsiToValue(rt, options, "credentialDefinition"); + auto credentialDefinitionPrivate = + jsiToValue(rt, options, "credentialDefinitionPrivate"); + auto credentialOffer = + jsiToValue(rt, options, "credentialOffer"); + auto credentialRequest = + jsiToValue(rt, options, "credentialRequest"); + auto attributeNames = jsiToValue(rt, options, "attributeNames"); + auto attributeRawValues = + jsiToValue(rt, options, "attributeRawValues"); + auto revocation = + jsiToValue(rt, options, "revocationConfiguration", true); + auto encoding = + jsiToValue(rt, options, "encoding", true); + + ObjectHandle out; + + ErrorCode code = anoncreds_create_w3c_credential( + credentialDefinition, credentialDefinitionPrivate, credentialOffer, + credentialRequest, attributeNames, attributeRawValues, + revocation.reg_def ? &revocation : 0, + encoding.length() ? encoding.c_str() : nullptr, &out); + + return createReturnValue(rt, code, &out); +}; + +jsi::Value createW3CCredentialOffer(jsi::Runtime &rt, jsi::Object options) { + auto schemaId = jsiToValue(rt, options, "schemaId"); + auto credentialDefinitionId = + jsiToValue(rt, options, "credentialDefinitionId"); + auto keyCorrectnessProof = + jsiToValue(rt, options, "keyCorrectnessProof"); + + ObjectHandle out; + + ErrorCode code = anoncreds_create_w3c_credential_offer( + schemaId.c_str(), credentialDefinitionId.c_str(), keyCorrectnessProof, + &out); + + return createReturnValue(rt, code, &out); +}; + +jsi::Value createW3CCredentialRequest(jsi::Runtime &rt, jsi::Object options) { + auto entropy = jsiToValue(rt, options, "entropy", true); + auto proverDid = jsiToValue(rt, options, "proverDid", true); + auto credentialDefinition = + jsiToValue(rt, options, "credentialDefinition"); + auto linkSecret = jsiToValue(rt, options, "linkSecret"); + auto linkSecretId = jsiToValue(rt, options, "linkSecretId"); + auto credentialOffer = + jsiToValue(rt, options, "credentialOffer"); + + CredentialRequestReturn out; + + ErrorCode code = anoncreds_create_w3c_credential_request( + entropy.length() ? entropy.c_str() : nullptr, + proverDid.length() ? proverDid.c_str() : nullptr, credentialDefinition, + linkSecret.c_str(), linkSecretId.c_str(), credentialOffer, + &out.credentialRequest, &out.credentialRequestMetadata); + + return createReturnValue(rt, code, &out); +}; + +jsi::Value w3cCredentialGetAttribute(jsi::Runtime &rt, jsi::Object options) { + auto handle = jsiToValue(rt, options, "objectHandle"); + auto name = jsiToValue(rt, options, "name"); + + const char *out; + + ErrorCode code = + anoncreds_w3c_credential_get_attribute(handle, name.c_str(), &out); + + return createReturnValue(rt, code, &out); +}; + +jsi::Value processW3CCredential(jsi::Runtime &rt, jsi::Object options) { + auto credential = jsiToValue(rt, options, "credential"); + auto credentialRequestMetadata = + jsiToValue(rt, options, "credentialRequestMetadata"); + auto linkSecret = jsiToValue(rt, options, "linkSecret"); + auto credentialDefinition = + jsiToValue(rt, options, "credentialDefinition"); + auto revocationRegistryDefinition = jsiToValue( + rt, options, "revocationRegistryDefinition", true); + + ObjectHandle out; + + ErrorCode code = anoncreds_process_w3c_credential( + credential, credentialRequestMetadata, linkSecret.c_str(), credentialDefinition, + revocationRegistryDefinition, &out); + + return createReturnValue(rt, code, &out); +}; + +jsi::Value w3cCredentialAddNonAnonCredsIntegrityProof(jsi::Runtime &rt, jsi::Object options) { + auto credential = jsiToValue(rt, options, "objectHandle"); + auto proof = jsiToValue(rt, options, "proof"); + + ObjectHandle out; + + ErrorCode code = anoncreds_w3c_credential_add_non_anoncreds_integrity_proof( + credential, proof.c_str(), &out); + + return createReturnValue(rt, code, &out); +}; + +jsi::Value w3cCredentialSetId(jsi::Runtime &rt, jsi::Object options) { + auto credential = jsiToValue(rt, options, "objectHandle"); + auto id = jsiToValue(rt, options, "id"); + + ObjectHandle out; + + ErrorCode code = anoncreds_w3c_credential_set_id( + credential, id.c_str(), &out); + + return createReturnValue(rt, code, &out); +}; + +jsi::Value w3cCredentialSetSubjectId(jsi::Runtime &rt, jsi::Object options) { + auto credential = jsiToValue(rt, options, "objectHandle"); + auto id = jsiToValue(rt, options, "id"); + + ObjectHandle out; + + ErrorCode code = anoncreds_w3c_credential_set_subject_id( + credential, id.c_str(), &out); + + return createReturnValue(rt, code, &out); +}; + +jsi::Value w3cCredentialAddContext(jsi::Runtime &rt, jsi::Object options) { + auto credential = jsiToValue(rt, options, "objectHandle"); + auto context = jsiToValue(rt, options, "context"); + + ObjectHandle out; + + ErrorCode code = anoncreds_w3c_credential_add_context( + credential, context.c_str(), &out); + + return createReturnValue(rt, code, &out); +}; + +jsi::Value w3cCredentialAddType(jsi::Runtime &rt, jsi::Object options) { + auto credential = jsiToValue(rt, options, "objectHandle"); + auto type_ = jsiToValue(rt, options, "type_"); + + ObjectHandle out; + + ErrorCode code = anoncreds_w3c_credential_add_type( + credential, type_.c_str(), &out); + + return createReturnValue(rt, code, &out); +}; + +jsi::Value credentialToW3C(jsi::Runtime &rt, jsi::Object options) { + auto credential = jsiToValue(rt, options, "objectHandle"); + + ObjectHandle out; + + ErrorCode code = anoncreds_credential_to_w3c( + credential, &out); + + return createReturnValue(rt, code, &out); +}; + +jsi::Value credentialFromW3C(jsi::Runtime &rt, jsi::Object options) { + auto credential = jsiToValue(rt, options, "objectHandle"); + + ObjectHandle out; + + ErrorCode code = anoncreds_credential_from_w3c( + credential, &out); + + return createReturnValue(rt, code, &out); +}; + } // namespace anoncreds diff --git a/wrappers/javascript/packages/anoncreds-react-native/cpp/anoncreds.h b/wrappers/javascript/packages/anoncreds-react-native/cpp/anoncreds.h index 4f03b4df..7e91203e 100644 --- a/wrappers/javascript/packages/anoncreds-react-native/cpp/anoncreds.h +++ b/wrappers/javascript/packages/anoncreds-react-native/cpp/anoncreds.h @@ -20,6 +20,11 @@ struct CredentialRequestReturn { ObjectHandle credentialRequestMetadata; }; +struct W3CCredentialRequestReturn { + ObjectHandle credentialRequest; + ObjectHandle credentialRequestMetadata; +}; + struct RevocationRegistryDefinitionReturn { ObjectHandle revocationRegistryDefinition; ObjectHandle revocationRegistryDefinitionPrivate; @@ -61,10 +66,16 @@ jsi::Value credentialDefinitionFromJson(jsi::Runtime &rt, jsi::Object options); jsi::Value credentialDefinitionPrivateFromJson(jsi::Runtime &rt, jsi::Object options); jsi::Value keyCorrectnessProofFromJson(jsi::Runtime &rt, jsi::Object options); +jsi::Value w3cCredentialOfferFromJson(jsi::Runtime &rt, jsi::Object options); +jsi::Value w3cCredentialRequestFromJson(jsi::Runtime &rt, jsi::Object options); +jsi::Value w3cCredentialFromJson(jsi::Runtime &rt, jsi::Object options); +jsi::Value w3cPresentationFromJson(jsi::Runtime &rt, jsi::Object options); // Proofs jsi::Value createPresentation(jsi::Runtime &rt, jsi::Object options); jsi::Value verifyPresentation(jsi::Runtime &rt, jsi::Object options); +jsi::Value createW3CPresentation(jsi::Runtime &rt, jsi::Object options); +jsi::Value verifyW3CPresentation(jsi::Runtime &rt, jsi::Object options); // Credentials jsi::Value createCredential(jsi::Runtime &rt, jsi::Object options); @@ -74,6 +85,19 @@ jsi::Value credentialGetAttribute(jsi::Runtime &rt, jsi::Object options); jsi::Value encodeCredentialAttributes(jsi::Runtime &rt, jsi::Object options); jsi::Value processCredential(jsi::Runtime &rt, jsi::Object options); +jsi::Value createW3CCredential(jsi::Runtime &rt, jsi::Object options); +jsi::Value createW3CCredentialOffer(jsi::Runtime &rt, jsi::Object options); +jsi::Value createW3CCredentialRequest(jsi::Runtime &rt, jsi::Object options); +jsi::Value w3cCredentialGetAttribute(jsi::Runtime &rt, jsi::Object options); +jsi::Value processW3CCredential(jsi::Runtime &rt, jsi::Object options); +jsi::Value w3cCredentialAddNonAnonCredsIntegrityProof(jsi::Runtime &rt, jsi::Object options); +jsi::Value w3cCredentialSetId(jsi::Runtime &rt, jsi::Object options); +jsi::Value w3cCredentialSetSubjectId(jsi::Runtime &rt, jsi::Object options); +jsi::Value w3cCredentialAddContext(jsi::Runtime &rt, jsi::Object options); +jsi::Value w3cCredentialAddType(jsi::Runtime &rt, jsi::Object options); +jsi::Value credentialToW3C(jsi::Runtime &rt, jsi::Object options); +jsi::Value credentialFromW3C(jsi::Runtime &rt, jsi::Object options); + // Revocation jsi::Value createOrUpdateRevocationState(jsi::Runtime &rt, jsi::Object options); jsi::Value createRevocationStatusList(jsi::Runtime &rt, jsi::Object options); diff --git a/wrappers/javascript/packages/anoncreds-react-native/src/NativeBindings.ts b/wrappers/javascript/packages/anoncreds-react-native/src/NativeBindings.ts index 12df01d3..3b3589a5 100644 --- a/wrappers/javascript/packages/anoncreds-react-native/src/NativeBindings.ts +++ b/wrappers/javascript/packages/anoncreds-react-native/src/NativeBindings.ts @@ -185,4 +185,91 @@ export type NativeBindings = { credentialDefinitionPrivateFromJson(options: { json: string }): ReturnObject keyCorrectnessProofFromJson(options: { json: string }): ReturnObject + + createW3CCredentialOffer(options: { + schemaId: string + credentialDefinitionId: string + keyCorrectnessProof: number + }): ReturnObject + + createW3CCredentialRequest(options: { + entropy?: string + proverDid?: string + credentialDefinition: number + linkSecret: string + linkSecretId: string + credentialOffer: number + }): ReturnObject<{ credentialRequest: Handle; credentialRequestMetadata: Handle }> + + createW3CCredential(options: { + credentialDefinition: number + credentialDefinitionPrivate: number + credentialOffer: number + credentialRequest: number + attributeNames: string[] + attributeRawValues: string[] + revocationConfiguration?: { + registryIndex: number + revocationRegistryDefinition: number + revocationRegistryDefinitionPrivate: number + revocationStatusList?: number + } + encoding?: string + }): ReturnObject + + processW3CCredential(options: { + credential: number + credentialRequestMetadata: number + linkSecret: string + credentialDefinition: number + revocationRegistryDefinition?: number + }): ReturnObject + + w3cCredentialGetAttribute(options: { objectHandle: number; name: string }): ReturnObject + + w3cCredentialAddNonAnonCredsIntegrityProof(options: { objectHandle: number; proof: string }): ReturnObject + + w3cCredentialSetId(options: { objectHandle: number; id: string }): ReturnObject + + w3cCredentialSetSubjectId(options: { objectHandle: number; id: string }): ReturnObject + + w3cCredentialAddContext(options: { objectHandle: number; context: string }): ReturnObject + + w3cCredentialAddType(options: { objectHandle: number; type_: string }): ReturnObject + + credentialToW3C(options: { objectHandle: number }): ReturnObject + + credentialFromW3C(options: { objectHandle: number }): ReturnObject + + createW3CPresentation(options: { + presentationRequest: number + credentials: { credential: number; timestamp?: number; revocationState?: number }[] + credentialsProve: NativeCredentialProve[] + linkSecret: string + schemaIds: string[] + schemas: number[] + credentialDefinitionIds: string[] + credentialDefinitions: number[] + }): ReturnObject + + verifyW3CPresentation(options: { + presentation: number + presentationRequest: number + schemas: number[] + schemaIds: string[] + credentialDefinitions: number[] + credentialDefinitionIds: string[] + revocationRegistryDefinitions?: number[] + revocationRegistryDefinitionIds?: string[] + revocationStatusLists?: number[] + nonRevokedIntervalOverrides?: NativeNonRevokedIntervalOverride[] + }): ReturnObject + + w3cCredentialOfferFromJson(options: { json: string }): ReturnObject + + w3cCredentialRequestFromJson(options: { json: string }): ReturnObject + + w3cCredentialFromJson(options: { json: string }): ReturnObject + + w3cPresentationFromJson(options: { json: string }): ReturnObject } diff --git a/wrappers/javascript/packages/anoncreds-react-native/src/ReactNativeAnoncreds.ts b/wrappers/javascript/packages/anoncreds-react-native/src/ReactNativeAnoncreds.ts index 9f855405..e6b899b5 100644 --- a/wrappers/javascript/packages/anoncreds-react-native/src/ReactNativeAnoncreds.ts +++ b/wrappers/javascript/packages/anoncreds-react-native/src/ReactNativeAnoncreds.ts @@ -392,4 +392,192 @@ export class ReactNativeAnoncreds implements Anoncreds { const handle = this.handleError(this.anoncreds.keyCorrectnessProofFromJson(serializeArguments(options))) return new ObjectHandle(handle) } + + public createW3CCredential(options: { + credentialDefinition: ObjectHandle + credentialDefinitionPrivate: ObjectHandle + credentialOffer: ObjectHandle + credentialRequest: ObjectHandle + attributeRawValues: Record + revocationConfiguration?: NativeCredentialRevocationConfig + encoding?: string + }): ObjectHandle { + const attributeNames = Object.keys(options.attributeRawValues) + const attributeRawValues = Object.values(options.attributeRawValues) + + const credential = this.handleError( + // eslint-disable-next-line @typescript-eslint/ban-ts-comment, @typescript-eslint/prefer-ts-expect-error + // @ts-ignore + this.anoncreds.createW3CCredential({ + // eslint-disable-next-line @typescript-eslint/ban-ts-comment, @typescript-eslint/prefer-ts-expect-error + // @ts-ignore + ...serializeArguments(options), + attributeRawValues, + attributeNames, + revocationConfiguration: options.revocationConfiguration + ? { + registryIndex: options.revocationConfiguration.registryIndex, + revocationRegistryDefinition: options.revocationConfiguration.revocationRegistryDefinition.handle, + revocationRegistryDefinitionPrivate: + options.revocationConfiguration.revocationRegistryDefinitionPrivate.handle, + revocationStatusList: options.revocationConfiguration.revocationStatusList.handle + } + : undefined, + encoding: options.encoding + }) + ) + + return new ObjectHandle(credential) + } + + public processW3CCredential(options: { + credential: ObjectHandle + credentialRequestMetadata: ObjectHandle + linkSecret: string + credentialDefinition: ObjectHandle + revocationRegistryDefinition?: ObjectHandle + }): ObjectHandle { + const handle = this.handleError(this.anoncreds.processW3CCredential(serializeArguments(options))) + return new ObjectHandle(handle) + } + + public createW3CCredentialOffer(options: { + schemaId: string + credentialDefinitionId: string + keyCorrectnessProof: ObjectHandle + }): ObjectHandle { + const handle = this.handleError(this.anoncreds.createW3CCredentialOffer(serializeArguments(options))) + return new ObjectHandle(handle) + } + + public createW3CCredentialRequest(options: { + entropy?: string + proverDid?: string + credentialDefinition: ObjectHandle + linkSecret: string + linkSecretId: string + credentialOffer: ObjectHandle + }): { credentialRequest: ObjectHandle; credentialRequestMetadata: ObjectHandle } { + const { credentialRequest, credentialRequestMetadata } = this.handleError( + this.anoncreds.createW3CCredentialRequest(serializeArguments(options)) + ) + + return { + credentialRequestMetadata: new ObjectHandle(credentialRequestMetadata), + credentialRequest: new ObjectHandle(credentialRequest) + } + } + + public createW3CPresentation(options: { + presentationRequest: ObjectHandle + credentials: NativeCredentialEntry[] + credentialsProve: NativeCredentialProve[] + linkSecret: string + schemas: Record + credentialDefinitions: Record + }): ObjectHandle { + const schemaKeys = Object.keys(options.schemas) + const schemaValues = Object.values(options.schemas).map((o) => o.handle) + const credentialDefinitionKeys = Object.keys(options.credentialDefinitions) + const credentialDefinitionValues = Object.values(options.credentialDefinitions).map((o) => o.handle) + + const credentialEntries = options.credentials.map((value) => ({ + credential: value.credential.handle, + timestamp: value.timestamp ?? -1, + revocationState: value.revocationState?.handle ?? 0 + })) + + const handle = this.handleError( + this.anoncreds.createW3CPresentation({ + presentationRequest: options.presentationRequest.handle, + linkSecret: options.linkSecret, + credentialsProve: options.credentialsProve, + credentials: credentialEntries, + schemas: schemaValues, + schemaIds: schemaKeys, + credentialDefinitions: credentialDefinitionValues, + credentialDefinitionIds: credentialDefinitionKeys + }) + ) + return new ObjectHandle(handle) + } + + public verifyW3CPresentation(options: { + presentation: ObjectHandle + presentationRequest: ObjectHandle + schemas: ObjectHandle[] + schemaIds: string[] + credentialDefinitions: ObjectHandle[] + credentialDefinitionIds: string[] + revocationRegistryDefinitions?: ObjectHandle[] + revocationRegistryDefinitionIds?: string[] + revocationStatusLists?: ObjectHandle[] + nonRevokedIntervalOverrides?: NativeNonRevokedIntervalOverride[] + }): boolean { + return Boolean(this.handleError(this.anoncreds.verifyW3CPresentation(serializeArguments(options)))) + } + + public w3cCredentialGetAttribute(options: { objectHandle: ObjectHandle; name: string }): string { + return this.handleError(this.anoncreds.w3cCredentialGetAttribute(serializeArguments(options))) + } + + public w3cPresentationFromJson(options: { json: string }): ObjectHandle { + const handle = this.handleError(this.anoncreds.w3cPresentationFromJson(serializeArguments(options))) + return new ObjectHandle(handle) + } + + public w3cCredentialOfferFromJson(options: { json: string }): ObjectHandle { + const handle = this.handleError(this.anoncreds.w3cCredentialOfferFromJson(serializeArguments(options))) + return new ObjectHandle(handle) + } + + public w3cCredentialRequestFromJson(options: { json: string }): ObjectHandle { + const handle = this.handleError(this.anoncreds.w3cCredentialRequestFromJson(serializeArguments(options))) + return new ObjectHandle(handle) + } + + public w3cCredentialFromJson(options: { json: string }): ObjectHandle { + const handle = this.handleError(this.anoncreds.w3cCredentialFromJson(serializeArguments(options))) + return new ObjectHandle(handle) + } + + public w3cCredentialAddNonAnonCredsIntegrityProof(options: { + objectHandle: ObjectHandle + proof: string + }): ObjectHandle { + const handle = this.handleError( + this.anoncreds.w3cCredentialAddNonAnonCredsIntegrityProof(serializeArguments(options)) + ) + return new ObjectHandle(handle) + } + + public w3cCredentialSetId(options: { objectHandle: ObjectHandle; id: string }): ObjectHandle { + const handle = this.handleError(this.anoncreds.w3cCredentialSetId(serializeArguments(options))) + return new ObjectHandle(handle) + } + + public w3cCredentialSetSubjectId(options: { objectHandle: ObjectHandle; id: string }): ObjectHandle { + const handle = this.handleError(this.anoncreds.w3cCredentialSetSubjectId(serializeArguments(options))) + return new ObjectHandle(handle) + } + + public w3cCredentialAddContext(options: { objectHandle: ObjectHandle; context: string }): ObjectHandle { + const handle = this.handleError(this.anoncreds.w3cCredentialAddContext(serializeArguments(options))) + return new ObjectHandle(handle) + } + + public w3cCredentialAddType(options: { objectHandle: ObjectHandle; type_: string }): ObjectHandle { + const handle = this.handleError(this.anoncreds.w3cCredentialAddType(serializeArguments(options))) + return new ObjectHandle(handle) + } + + public credentialToW3C(options: { objectHandle: ObjectHandle }): ObjectHandle { + const handle = this.handleError(this.anoncreds.credentialToW3C(serializeArguments(options))) + return new ObjectHandle(handle) + } + + public credentialFromW3C(options: { objectHandle: ObjectHandle }): ObjectHandle { + const handle = this.handleError(this.anoncreds.credentialFromW3C(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 911b74b4..af117aa1 100644 --- a/wrappers/javascript/packages/anoncreds-shared/src/Anoncreds.ts +++ b/wrappers/javascript/packages/anoncreds-shared/src/Anoncreds.ts @@ -204,4 +204,83 @@ export type Anoncreds = { getTypeName(options: { objectHandle: ObjectHandle }): string objectFree(options: { objectHandle: ObjectHandle }): void + + createW3CCredentialOffer(options: { + schemaId: string + credentialDefinitionId: string + keyCorrectnessProof: ObjectHandle + }): ObjectHandle + + createW3CCredentialRequest(options: { + entropy?: string + proverDid?: string + credentialDefinition: ObjectHandle + linkSecret: string + linkSecretId: string + credentialOffer: ObjectHandle + }): { credentialRequest: ObjectHandle; credentialRequestMetadata: ObjectHandle } + + createW3CCredential(options: { + credentialDefinition: ObjectHandle + credentialDefinitionPrivate: ObjectHandle + credentialOffer: ObjectHandle + credentialRequest: ObjectHandle + attributeRawValues: Record + revocationConfiguration?: NativeCredentialRevocationConfig + encoding?: string + }): ObjectHandle + + processW3CCredential(options: { + credential: ObjectHandle + credentialRequestMetadata: ObjectHandle + linkSecret: string + credentialDefinition: ObjectHandle + revocationRegistryDefinition?: ObjectHandle + }): ObjectHandle + + createW3CPresentation(options: { + presentationRequest: ObjectHandle + credentials: NativeCredentialEntry[] + credentialsProve: NativeCredentialProve[] + linkSecret: string + schemas: Record + credentialDefinitions: Record + }): ObjectHandle + + verifyW3CPresentation(options: { + presentation: ObjectHandle + presentationRequest: ObjectHandle + schemas: ObjectHandle[] + schemaIds: string[] + credentialDefinitions: ObjectHandle[] + credentialDefinitionIds: string[] + revocationRegistryDefinitions?: ObjectHandle[] + revocationRegistryDefinitionIds?: string[] + revocationStatusLists?: ObjectHandle[] + nonRevokedIntervalOverrides?: NativeNonRevokedIntervalOverride[] + }): boolean + + w3cPresentationFromJson(options: { json: string }): ObjectHandle + + w3cCredentialAddNonAnonCredsIntegrityProof(options: { objectHandle: ObjectHandle; proof: string }): ObjectHandle + + w3cCredentialSetId(options: { objectHandle: ObjectHandle; id: string }): ObjectHandle + + w3cCredentialSetSubjectId(options: { objectHandle: ObjectHandle; id: string }): ObjectHandle + + w3cCredentialAddContext(options: { objectHandle: ObjectHandle; context: string }): ObjectHandle + + w3cCredentialAddType(options: { objectHandle: ObjectHandle; type_: string }): ObjectHandle + + w3cCredentialGetAttribute(options: { objectHandle: ObjectHandle; name: string }): string + + w3cCredentialOfferFromJson(options: { json: string }): ObjectHandle + + w3cCredentialRequestFromJson(options: { json: string }): ObjectHandle + + w3cCredentialFromJson(options: { json: string }): ObjectHandle + + credentialToW3C(options: { objectHandle: ObjectHandle }): 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 e8857875..eb47a710 100644 --- a/wrappers/javascript/packages/anoncreds-shared/src/api/Credential.ts +++ b/wrappers/javascript/packages/anoncreds-shared/src/api/Credential.ts @@ -12,6 +12,7 @@ import { CredentialOffer } from './CredentialOffer' import { CredentialRequest } from './CredentialRequest' import { CredentialRequestMetadata } from './CredentialRequestMetadata' import { RevocationRegistryDefinition } from './RevocationRegistryDefinition' +import { W3CCredential } from './W3CCredential' import { pushToArray } from './utils' export type CreateCredentialOptions = { @@ -140,4 +141,16 @@ export class Credential extends AnoncredsObject { const index = anoncreds.credentialGetAttribute({ objectHandle: this.handle, name: 'rev_reg_index' }) return index ? Number(index) : undefined } + + public toW3c(): W3CCredential { + return new W3CCredential( + anoncreds.credentialToW3C({ + objectHandle: this.handle + }).handle + ) + } + + public static fromW3C(credential: W3CCredential) { + return new Credential(anoncreds.credentialFromW3C({ objectHandle: credential.handle }).handle) + } } diff --git a/wrappers/javascript/packages/anoncreds-shared/src/api/W3CCredential.ts b/wrappers/javascript/packages/anoncreds-shared/src/api/W3CCredential.ts new file mode 100644 index 00000000..b802a99e --- /dev/null +++ b/wrappers/javascript/packages/anoncreds-shared/src/api/W3CCredential.ts @@ -0,0 +1,201 @@ +import type { CredentialRevocationConfig } from './CredentialRevocationConfig' +import type { RevocationStatusList } from './RevocationStatusList' +import type { ObjectHandle } from '../ObjectHandle' +import type { JsonObject } from '../types' + +import { AnoncredsObject } from '../AnoncredsObject' +import { anoncreds } from '../register' + +import { Credential } from './Credential' +import { CredentialDefinition } from './CredentialDefinition' +import { CredentialDefinitionPrivate } from './CredentialDefinitionPrivate' +import { CredentialRequestMetadata } from './CredentialRequestMetadata' +import { RevocationRegistryDefinition } from './RevocationRegistryDefinition' +import { W3CCredentialOffer } from './W3CCredentialOffer' +import { W3CCredentialRequest } from './W3CCredentialRequest' +import { pushToArray } from './utils' + +export type CreateW3CCredentialOptions = { + credentialDefinition: CredentialDefinition | JsonObject + credentialDefinitionPrivate: CredentialDefinitionPrivate | JsonObject + credentialOffer: W3CCredentialOffer | JsonObject + credentialRequest: W3CCredentialRequest | JsonObject + attributeRawValues: Record + revocationRegistryId?: string + revocationConfiguration?: CredentialRevocationConfig + revocationStatusList?: RevocationStatusList | JsonObject + encoding?: string +} + +export type ProcessW3CCredentialOptions = { + credentialRequestMetadata: CredentialRequestMetadata | JsonObject + linkSecret: string + credentialDefinition: CredentialDefinition | JsonObject + revocationRegistryDefinition?: RevocationRegistryDefinition | JsonObject +} + +export class W3CCredential extends AnoncredsObject { + public static create(options: CreateW3CCredentialOptions) { + 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) + + const credentialDefinitionPrivate = + options.credentialDefinitionPrivate instanceof CredentialDefinitionPrivate + ? options.credentialDefinitionPrivate.handle + : pushToArray(CredentialDefinitionPrivate.fromJson(options.credentialDefinitionPrivate).handle, objectHandles) + + const credentialOffer = + options.credentialOffer instanceof W3CCredentialOffer + ? options.credentialOffer.handle + : pushToArray(W3CCredentialOffer.fromJson(options.credentialOffer).handle, objectHandles) + + const credentialRequest = + options.credentialRequest instanceof W3CCredentialRequest + ? options.credentialRequest.handle + : pushToArray(W3CCredentialRequest.fromJson(options.credentialRequest).handle, objectHandles) + + credential = anoncreds.createW3CCredential({ + credentialDefinition, + credentialDefinitionPrivate, + credentialOffer, + credentialRequest, + attributeRawValues: options.attributeRawValues, + revocationConfiguration: options.revocationConfiguration?.native, + encoding: options.encoding + }) + } finally { + objectHandles.forEach((handle) => { + handle.clear() + }) + } + return new W3CCredential(credential.handle) + } + + public static fromJson(json: JsonObject) { + return new W3CCredential(anoncreds.credentialFromJson({ json: JSON.stringify(json) }).handle) + } + + public process(options: ProcessW3CCredentialOptions) { + 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) + + const credentialRequestMetadata = + options.credentialRequestMetadata instanceof CredentialRequestMetadata + ? options.credentialRequestMetadata.handle + : pushToArray(CredentialRequestMetadata.fromJson(options.credentialRequestMetadata).handle, objectHandles) + + const revocationRegistryDefinition = + options.revocationRegistryDefinition instanceof RevocationRegistryDefinition + ? options.revocationRegistryDefinition.handle + : options.revocationRegistryDefinition !== undefined + ? pushToArray( + RevocationRegistryDefinition.fromJson(options.revocationRegistryDefinition).handle, + objectHandles + ) + : undefined + + credential = anoncreds.processW3CCredential({ + credential: this.handle, + credentialDefinition, + credentialRequestMetadata, + linkSecret: options.linkSecret, + revocationRegistryDefinition + }) + + // We can discard previous handle and store the new one + this.handle.clear() + this.handle = credential + } finally { + objectHandles.forEach((handle) => { + handle.clear() + }) + } + return this + } + + public get schemaId() { + return anoncreds.w3cCredentialGetAttribute({ objectHandle: this.handle, name: 'schema_id' }) + } + + public get credentialDefinitionId() { + return anoncreds.w3cCredentialGetAttribute({ objectHandle: this.handle, name: 'cred_def_id' }) + } + + public get revocationRegistryId() { + return anoncreds.w3cCredentialGetAttribute({ objectHandle: this.handle, name: 'rev_reg_id' }) + } + + public get revocationRegistryIndex() { + const index = anoncreds.w3cCredentialGetAttribute({ objectHandle: this.handle, name: 'rev_reg_index' }) + return index ? Number(index) : undefined + } + + public toLegacy(): Credential { + return new Credential( + anoncreds.credentialFromW3C({ + objectHandle: this.handle + }).handle + ) + } + + public static fromLegacy(credential: Credential): W3CCredential { + return new W3CCredential(anoncreds.credentialToW3C({ objectHandle: credential.handle }).handle) + } + + public addNonAnonCredsIntegrityProof(proof: string): W3CCredential { + return new W3CCredential( + anoncreds.w3cCredentialAddNonAnonCredsIntegrityProof({ + objectHandle: this.handle, + proof + }).handle + ) + } + + public setId(id: string): W3CCredential { + return new W3CCredential( + anoncreds.w3cCredentialSetId({ + objectHandle: this.handle, + id + }).handle + ) + } + + public setSubjectId(id: string): W3CCredential { + return new W3CCredential( + anoncreds.w3cCredentialSetSubjectId({ + objectHandle: this.handle, + id + }).handle + ) + } + + public addContext(context: string): W3CCredential { + return new W3CCredential( + anoncreds.w3cCredentialAddContext({ + objectHandle: this.handle, + context + }).handle + ) + } + + public addType(type_: string): W3CCredential { + return new W3CCredential( + anoncreds.w3cCredentialAddType({ + objectHandle: this.handle, + type_ + }).handle + ) + } +} diff --git a/wrappers/javascript/packages/anoncreds-shared/src/api/W3CCredentialOffer.ts b/wrappers/javascript/packages/anoncreds-shared/src/api/W3CCredentialOffer.ts new file mode 100644 index 00000000..7009eec0 --- /dev/null +++ b/wrappers/javascript/packages/anoncreds-shared/src/api/W3CCredentialOffer.ts @@ -0,0 +1,43 @@ +import type { ObjectHandle } from '../ObjectHandle' +import type { JsonObject } from '../types' + +import { AnoncredsObject } from '../AnoncredsObject' +import { anoncreds } from '../register' + +import { KeyCorrectnessProof } from './KeyCorrectnessProof' +import { pushToArray } from './utils' + +export type CreateW3CCredentialOfferOptions = { + schemaId: string + credentialDefinitionId: string + keyCorrectnessProof: KeyCorrectnessProof | JsonObject +} + +export class W3CCredentialOffer extends AnoncredsObject { + public static create(options: CreateW3CCredentialOfferOptions) { + let credentialOfferHandle + // Objects created within this method must be freed up + const objectHandles: ObjectHandle[] = [] + try { + const keyCorrectnessProof = + options.keyCorrectnessProof instanceof KeyCorrectnessProof + ? options.keyCorrectnessProof.handle + : pushToArray(KeyCorrectnessProof.fromJson(options.keyCorrectnessProof).handle, objectHandles) + + credentialOfferHandle = anoncreds.createW3CCredentialOffer({ + schemaId: options.schemaId, + credentialDefinitionId: options.credentialDefinitionId, + keyCorrectnessProof + }).handle + } finally { + objectHandles.forEach((handle) => { + handle.clear() + }) + } + return new W3CCredentialOffer(credentialOfferHandle) + } + + public static fromJson(json: JsonObject) { + return new W3CCredentialOffer(anoncreds.w3cCredentialOfferFromJson({ json: JSON.stringify(json) }).handle) + } +} diff --git a/wrappers/javascript/packages/anoncreds-shared/src/api/W3CCredentialRequest.ts b/wrappers/javascript/packages/anoncreds-shared/src/api/W3CCredentialRequest.ts new file mode 100644 index 00000000..e92f1c23 --- /dev/null +++ b/wrappers/javascript/packages/anoncreds-shared/src/api/W3CCredentialRequest.ts @@ -0,0 +1,62 @@ +import type { ObjectHandle } from '../ObjectHandle' +import type { JsonObject } from '../types' + +import { AnoncredsObject } from '../AnoncredsObject' +import { anoncreds } from '../register' + +import { CredentialDefinition } from './CredentialDefinition' +import { CredentialRequestMetadata } from './CredentialRequestMetadata' +import { W3CCredentialOffer } from './W3CCredentialOffer' +import { pushToArray } from './utils' + +export type CreateW3CCredentialRequestOptions = { + entropy?: string + proverDid?: string + credentialDefinition: CredentialDefinition | JsonObject + linkSecret: string + linkSecretId: string + credentialOffer: W3CCredentialOffer | JsonObject +} + +export class W3CCredentialRequest extends AnoncredsObject { + public static create(options: CreateW3CCredentialRequestOptions) { + let createReturnObj: { + credentialRequest: ObjectHandle + credentialRequestMetadata: ObjectHandle + } + // 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) + + const credentialOffer = + options.credentialOffer instanceof W3CCredentialOffer + ? options.credentialOffer.handle + : pushToArray(W3CCredentialOffer.fromJson(options.credentialOffer).handle, objectHandles) + + createReturnObj = anoncreds.createW3CCredentialRequest({ + entropy: options.entropy, + proverDid: options.proverDid, + credentialDefinition, + linkSecret: options.linkSecret, + linkSecretId: options.linkSecretId, + credentialOffer + }) + } finally { + objectHandles.forEach((handle) => { + handle.clear() + }) + } + return { + credentialRequest: new W3CCredentialRequest(createReturnObj.credentialRequest.handle), + credentialRequestMetadata: new CredentialRequestMetadata(createReturnObj.credentialRequestMetadata.handle) + } + } + + public static fromJson(json: JsonObject) { + return new W3CCredentialRequest(anoncreds.w3cCredentialRequestFromJson({ json: JSON.stringify(json) }).handle) + } +} diff --git a/wrappers/javascript/packages/anoncreds-shared/src/api/W3CPresentation.ts b/wrappers/javascript/packages/anoncreds-shared/src/api/W3CPresentation.ts new file mode 100644 index 00000000..1607906a --- /dev/null +++ b/wrappers/javascript/packages/anoncreds-shared/src/api/W3CPresentation.ts @@ -0,0 +1,160 @@ +import type { CredentialProve, NonRevokedIntervalOverride } from './Presentation' +import type { ObjectHandle } from '../ObjectHandle' +import type { JsonObject } from '../types' + +import { AnoncredsObject } from '../AnoncredsObject' +import { anoncreds } from '../register' + +import { CredentialDefinition } from './CredentialDefinition' +import { CredentialRevocationState } from './CredentialRevocationState' +import { PresentationRequest } from './PresentationRequest' +import { RevocationRegistryDefinition } from './RevocationRegistryDefinition' +import { RevocationStatusList } from './RevocationStatusList' +import { Schema } from './Schema' +import { W3CCredential } from './W3CCredential' +import { pushToArray } from './utils' + +// TODO: Simplify Presentation API (see PresentCredentials object in python wrapper)) + +export type W3CCredentialEntry = { + credential: W3CCredential | JsonObject + timestamp?: number + revocationState?: CredentialRevocationState | JsonObject +} + +export type CreateW3CPresentationOptions = { + presentationRequest: PresentationRequest | JsonObject + credentials: W3CCredentialEntry[] + credentialsProve: CredentialProve[] + linkSecret: string + schemas: Record + credentialDefinitions: Record +} + +export type VerifyW3CPresentationOptions = { + presentationRequest: PresentationRequest | JsonObject + schemas: Record + credentialDefinitions: Record + revocationRegistryDefinitions?: Record + revocationStatusLists?: (RevocationStatusList | JsonObject)[] + nonRevokedIntervalOverrides?: NonRevokedIntervalOverride[] +} + +export class W3CPresentation extends AnoncredsObject { + public static create(options: CreateW3CPresentationOptions) { + let presentationHandle + // Objects created within this method must be freed up + const objectHandles: ObjectHandle[] = [] + try { + const presentationRequest = + options.presentationRequest instanceof PresentationRequest + ? options.presentationRequest.handle + : pushToArray(PresentationRequest.fromJson(options.presentationRequest).handle, objectHandles) + + presentationHandle = anoncreds.createW3CPresentation({ + presentationRequest, + credentials: options.credentials.map((item) => ({ + credential: + item.credential instanceof W3CCredential + ? item.credential.handle + : pushToArray(W3CCredential.fromJson(item.credential).handle, objectHandles), + revocationState: + item.revocationState instanceof CredentialRevocationState + ? item.revocationState.handle + : item.revocationState !== undefined + ? pushToArray(CredentialRevocationState.fromJson(item.revocationState).handle, objectHandles) + : undefined, + + timestamp: item.timestamp + })), + credentialsProve: options.credentialsProve, + linkSecret: options.linkSecret, + schemas: Object.entries(options.schemas).reduce>((prev, [id, object]) => { + const objectHandle = + object instanceof Schema ? object.handle : pushToArray(Schema.fromJson(object).handle, objectHandles) + + prev[id] = objectHandle + return prev + }, {}), + credentialDefinitions: Object.entries(options.credentialDefinitions).reduce>( + (prev, [id, object]) => { + const objectHandle = + object instanceof CredentialDefinition + ? object.handle + : pushToArray(CredentialDefinition.fromJson(object).handle, objectHandles) + + prev[id] = objectHandle + return prev + }, + {} + ) + }).handle + } finally { + objectHandles.forEach((handle) => { + handle.clear() + }) + } + return new W3CPresentation(presentationHandle) + } + + public static fromJson(json: JsonObject) { + return new W3CPresentation(anoncreds.w3cPresentationFromJson({ json: JSON.stringify(json) }).handle) + } + + public verify(options: VerifyW3CPresentationOptions) { + const schemas = Object.values(options.schemas) + const schemaIds = Object.keys(options.schemas) + + const credentialDefinitions = Object.values(options.credentialDefinitions) + const credentialDefinitionIds = Object.keys(options.credentialDefinitions) + + const revocationRegistryDefinitions = options.revocationRegistryDefinitions + ? Object.values(options.revocationRegistryDefinitions) + : undefined + + const revocationRegistryDefinitionIds = options.revocationRegistryDefinitions + ? Object.keys(options.revocationRegistryDefinitions) + : undefined + + let verified + const objectHandles: ObjectHandle[] = [] + try { + const presentationRequest = + options.presentationRequest instanceof PresentationRequest + ? options.presentationRequest.handle + : pushToArray(PresentationRequest.fromJson(options.presentationRequest).handle, objectHandles) + + verified = anoncreds.verifyW3CPresentation({ + presentation: this.handle, + presentationRequest, + schemas: schemas.map((o) => + o instanceof Schema ? o.handle : pushToArray(Schema.fromJson(o).handle, objectHandles) + ), + schemaIds, + credentialDefinitions: credentialDefinitions.map((o) => + o instanceof CredentialDefinition + ? o.handle + : pushToArray(CredentialDefinition.fromJson(o).handle, objectHandles) + ), + credentialDefinitionIds, + revocationRegistryDefinitions: revocationRegistryDefinitions?.map((o) => + o instanceof RevocationRegistryDefinition + ? o.handle + : pushToArray(RevocationRegistryDefinition.fromJson(o).handle, objectHandles) + ), + revocationRegistryDefinitionIds, + revocationStatusLists: options.revocationStatusLists?.map((o) => + o instanceof RevocationStatusList + ? o.handle + : pushToArray(RevocationStatusList.fromJson(o).handle, objectHandles) + ), + nonRevokedIntervalOverrides: options.nonRevokedIntervalOverrides + }) + } finally { + objectHandles.forEach((handle) => { + handle.clear() + }) + } + return verified + } +} diff --git a/wrappers/javascript/packages/anoncreds-shared/src/api/index.ts b/wrappers/javascript/packages/anoncreds-shared/src/api/index.ts index 6f2750c8..b6aa73ed 100644 --- a/wrappers/javascript/packages/anoncreds-shared/src/api/index.ts +++ b/wrappers/javascript/packages/anoncreds-shared/src/api/index.ts @@ -15,3 +15,7 @@ export * from './RevocationRegistry' export * from './RevocationRegistryDefinition' export * from './RevocationRegistryDefinitionPrivate' export * from './RevocationStatusList' +export * from './W3CCredential' +export * from './W3CCredentialOffer' +export * from './W3CCredentialRequest' +export * from './W3CPresentation' diff --git a/wrappers/javascript/pnpm-lock.yaml b/wrappers/javascript/pnpm-lock.yaml index de8f4741..1f28abfd 100644 --- a/wrappers/javascript/pnpm-lock.yaml +++ b/wrappers/javascript/pnpm-lock.yaml @@ -44,7 +44,7 @@ importers: specifier: ^29.7.0 version: 29.7.0(@types/node@20.6.4)(ts-node@10.9.1) lerna: - specifier: 7.2.0 + specifier: ^7.2.0 version: 7.2.0 prettier: specifier: ^3.0.3 @@ -4602,7 +4602,7 @@ packages: glob: 7.2.3 infer-owner: 1.0.4 lru-cache: 6.0.0 - minipass: 3.1.6 + minipass: 3.3.6 minipass-collect: 1.0.2 minipass-flush: 1.0.5 minipass-pipeline: 1.2.4 @@ -9503,7 +9503,7 @@ packages: { integrity: sha512-6T6lH0H8OG9kITm/Jm6tdooIbogG9e0tLgpY6mphXSm/A9u8Nq1ryBG+Qspiub9LjWlBPsPS3tWQ/Botq4FdxA== } engines: { node: '>= 8' } dependencies: - minipass: 3.1.6 + minipass: 3.3.6 /minipass-fetch@3.0.4: resolution: @@ -9522,7 +9522,7 @@ packages: { integrity: sha512-JmQSYYpPUqX5Jyn1mXaRwOda1uQ8HP5KAT/oDSLCzt1BYRhQU0/hDtsB1ufZfEEzMZ9aAVmsBw8+FWsIXlClWw== } engines: { node: '>= 8' } dependencies: - minipass: 3.1.6 + minipass: 3.3.6 /minipass-json-stream@1.0.1: resolution: @@ -9537,7 +9537,7 @@ packages: { integrity: sha512-xuIq7cIOt09RPRJ19gdi4b+RiNvDFYe5JH+ggNvBqGqpQXcru3PcRmOZuHBKWK1Txf9+cQ+HMVN4d6z46LZP7A== } engines: { node: '>=8' } dependencies: - minipass: 3.1.6 + minipass: 3.3.6 /minipass-sized@1.0.3: resolution: @@ -9553,6 +9553,7 @@ packages: engines: { node: '>=8' } dependencies: yallist: 4.0.0 + dev: false /minipass@3.3.6: resolution: @@ -11704,7 +11705,7 @@ packages: { integrity: sha512-97qShzy1AiyxvPNIkLWoGua7xoQzzPjQ0HAH4B0rWKo7SZ6USuPcrUiAFrws0UH8RrbWmgq3LMTObhPIHbbBeQ== } engines: { node: '>= 8' } dependencies: - minipass: 3.1.6 + minipass: 3.3.6 dev: false /ssri@9.0.1: diff --git a/wrappers/python/anoncreds/bindings.py b/wrappers/python/anoncreds/bindings.py index 54314f56..366b6832 100644 --- a/wrappers/python/anoncreds/bindings.py +++ b/wrappers/python/anoncreds/bindings.py @@ -1091,13 +1091,13 @@ def w3c_credential_add_non_anoncreds_integrity_proof( return result -def w3c_credential_id( +def w3c_set_credential_id( cred: ObjectHandle, id: str, ) -> ObjectHandle: result = ObjectHandle() do_call( - "anoncreds_w3c_credential_id", + "anoncreds_w3c_set_credential_id", cred, encode_str(id), byref(result), @@ -1105,13 +1105,13 @@ def w3c_credential_id( return result -def w3c_credential_subject_id( +def w3c_credential_set_subject_id( cred: ObjectHandle, id: str, ) -> ObjectHandle: result = ObjectHandle() do_call( - "anoncreds_w3c_credential_subject_id", + "anoncreds_w3c_credential_set_subject_id", cred, encode_str(id), byref(result), diff --git a/wrappers/python/anoncreds/types.py b/wrappers/python/anoncreds/types.py index d6fc5cfc..fc16b4c5 100644 --- a/wrappers/python/anoncreds/types.py +++ b/wrappers/python/anoncreds/types.py @@ -359,6 +359,61 @@ def from_w3c(cls, cred: "W3CCredential") -> "Credential": ) ) + def add_non_anoncreds_integrity_proof( + self, + proof: str + ) -> "W3CCredential": + return W3CCredential( + bindings.w3c_credential_add_non_anoncreds_integrity_proof( + self.handle, + proof, + ) + ) + + def set_credential_id( + self, + id: str + ) -> "W3CCredential": + return W3CCredential( + bindings.w3c_credential_set_credential_id( + self.handle, + id, + ) + ) + + def set_subject_id( + self, + id: str + ) -> "W3CCredential": + return W3CCredential( + bindings.w3c_credential_set_subject_id( + self.handle, + id, + ) + ) + + def add_context( + self, + context: str + ) -> "W3CCredential": + return W3CCredential( + bindings.w3c_credential_add_context( + self.handle, + context, + ) + ) + + def add_type( + self, + type: str + ) -> "W3CCredential": + return W3CCredential( + bindings.w3c_credential_add_type( + self.handle, + type, + ) + ) + class W3CCredential(bindings.AnoncredsObject): GET_ATTR = "anoncreds_w3c_credential_get_attribute" From 6fb3c164cff3e9a089eb6ba4af04396564e7faf6 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Wed, 15 Nov 2023 12:51:18 +0300 Subject: [PATCH 03/21] Updated wrappers Signed-off-by: artem.ivanov --- .../anoncreds-nodejs/src/NodeJSAnoncreds.ts | 6 ++-- .../anoncreds-nodejs/src/library/bindings.ts | 2 +- .../anoncreds-nodejs/tests/api.test.ts | 6 +++- .../anoncreds-react-native/cpp/anoncreds.cpp | 4 ++- .../src/NativeBindings.ts | 2 +- .../src/ReactNativeAnoncreds.ts | 2 +- .../anoncreds-shared/src/Anoncreds.ts | 2 +- .../anoncreds-shared/src/api/Credential.ts | 32 +++++++++++++++---- .../anoncreds-shared/src/api/W3CCredential.ts | 29 +++++++++++++++-- wrappers/python/anoncreds/bindings.py | 2 ++ wrappers/python/anoncreds/types.py | 10 ++++-- wrappers/python/demo/w3c_test.py | 2 +- 12 files changed, 78 insertions(+), 21 deletions(-) diff --git a/wrappers/javascript/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts b/wrappers/javascript/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts index 6723ba0e..0bf4bd01 100644 --- a/wrappers/javascript/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts +++ b/wrappers/javascript/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts @@ -907,12 +907,12 @@ export class NodeJSAnoncreds implements Anoncreds { return Boolean(handleReturnPointer(ret)) } - public credentialToW3C(options: { objectHandle: ObjectHandle }): ObjectHandle { - const { objectHandle } = serializeArguments(options) + public credentialToW3C(options: { objectHandle: ObjectHandle, credentialDefinition: ObjectHandle }): ObjectHandle { + const { objectHandle, credentialDefinition } = serializeArguments(options) const ret = allocatePointer() - this.nativeAnoncreds.anoncreds_credential_to_w3c(objectHandle, ret) + this.nativeAnoncreds.anoncreds_credential_to_w3c(objectHandle, credentialDefinition, 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 8a5a265e..5533faca 100644 --- a/wrappers/javascript/packages/anoncreds-nodejs/src/library/bindings.ts +++ b/wrappers/javascript/packages/anoncreds-nodejs/src/library/bindings.ts @@ -257,7 +257,7 @@ export const nativeBindings = { FFI_INT8_PTR ] ], - anoncreds_credential_to_w3c: [FFI_ERRORCODE, [FFI_OBJECT_HANDLE, FFI_OBJECT_HANDLE_PTR]], + anoncreds_credential_to_w3c: [FFI_ERRORCODE, [FFI_OBJECT_HANDLE, FFI_OBJECT_HANDLE, FFI_OBJECT_HANDLE_PTR]], anoncreds_credential_from_w3c: [FFI_ERRORCODE, [FFI_OBJECT_HANDLE, FFI_OBJECT_HANDLE_PTR]], anoncreds_w3c_credential_add_non_anoncreds_integrity_proof: [ FFI_ERRORCODE, diff --git a/wrappers/javascript/packages/anoncreds-nodejs/tests/api.test.ts b/wrappers/javascript/packages/anoncreds-nodejs/tests/api.test.ts index 551b029f..227baf7a 100644 --- a/wrappers/javascript/packages/anoncreds-nodejs/tests/api.test.ts +++ b/wrappers/javascript/packages/anoncreds-nodejs/tests/api.test.ts @@ -643,10 +643,14 @@ describe('API W3C', () => { expect('mock:uri').toEqual(legacyCredential.schemaId) expect('mock:uri').toEqual(legacyCredential.credentialDefinitionId) - const w3cCredential = W3CCredential.fromLegacy(legacyCredential) + const w3cCredential = W3CCredential.fromLegacy({ credential: legacyCredential, credentialDefinition }) expect('mock:uri').toEqual(w3cCredential.schemaId) expect('mock:uri').toEqual(w3cCredential.credentialDefinitionId) + const convertedW3CCredential = legacyCredential.toW3C({ credentialDefinition }) + expect('mock:uri').toEqual(convertedW3CCredential.schemaId) + expect('mock:uri').toEqual(convertedW3CCredential.credentialDefinitionId) + const credentialReceived = credential.process({ credentialDefinition, credentialRequestMetadata, diff --git a/wrappers/javascript/packages/anoncreds-react-native/cpp/anoncreds.cpp b/wrappers/javascript/packages/anoncreds-react-native/cpp/anoncreds.cpp index 71dd40df..046b1462 100644 --- a/wrappers/javascript/packages/anoncreds-react-native/cpp/anoncreds.cpp +++ b/wrappers/javascript/packages/anoncreds-react-native/cpp/anoncreds.cpp @@ -983,11 +983,13 @@ jsi::Value w3cCredentialAddType(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"); ObjectHandle out; ErrorCode code = anoncreds_credential_to_w3c( - credential, &out); + credential, credentialDefinition, &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 3b3589a5..4bdd5692 100644 --- a/wrappers/javascript/packages/anoncreds-react-native/src/NativeBindings.ts +++ b/wrappers/javascript/packages/anoncreds-react-native/src/NativeBindings.ts @@ -237,7 +237,7 @@ export type NativeBindings = { w3cCredentialAddType(options: { objectHandle: number; type_: string }): ReturnObject - credentialToW3C(options: { objectHandle: number }): ReturnObject + credentialToW3C(options: { objectHandle: number, credentialDefinition: number }): 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 e6b899b5..03204b61 100644 --- a/wrappers/javascript/packages/anoncreds-react-native/src/ReactNativeAnoncreds.ts +++ b/wrappers/javascript/packages/anoncreds-react-native/src/ReactNativeAnoncreds.ts @@ -571,7 +571,7 @@ export class ReactNativeAnoncreds implements Anoncreds { return new ObjectHandle(handle) } - public credentialToW3C(options: { objectHandle: ObjectHandle }): ObjectHandle { + public credentialToW3C(options: { objectHandle: ObjectHandle, credentialDefinition: ObjectHandle }): 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 af117aa1..b83d2269 100644 --- a/wrappers/javascript/packages/anoncreds-shared/src/Anoncreds.ts +++ b/wrappers/javascript/packages/anoncreds-shared/src/Anoncreds.ts @@ -280,7 +280,7 @@ export type Anoncreds = { w3cCredentialFromJson(options: { json: string }): ObjectHandle - credentialToW3C(options: { objectHandle: ObjectHandle }): ObjectHandle + credentialToW3C(options: { objectHandle: ObjectHandle, credentialDefinition: ObjectHandle }): 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 eb47a710..dee4f390 100644 --- a/wrappers/javascript/packages/anoncreds-shared/src/api/Credential.ts +++ b/wrappers/javascript/packages/anoncreds-shared/src/api/Credential.ts @@ -34,6 +34,10 @@ export type ProcessCredentialOptions = { revocationRegistryDefinition?: RevocationRegistryDefinition | JsonObject } +export type CredentialToW3COptions = { + credentialDefinition: CredentialDefinition | JsonObject +} + export class Credential extends AnoncredsObject { public static create(options: CreateCredentialOptions) { let credential @@ -142,12 +146,28 @@ export class Credential extends AnoncredsObject { return index ? Number(index) : undefined } - public toW3c(): W3CCredential { - return new W3CCredential( - anoncreds.credentialToW3C({ - objectHandle: this.handle - }).handle - ) + 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, + }).handle + ) + } finally { + objectHandles.forEach((handle) => { + handle.clear() + }) + } + return credential } public static fromW3C(credential: W3CCredential) { diff --git a/wrappers/javascript/packages/anoncreds-shared/src/api/W3CCredential.ts b/wrappers/javascript/packages/anoncreds-shared/src/api/W3CCredential.ts index b802a99e..ab35df15 100644 --- a/wrappers/javascript/packages/anoncreds-shared/src/api/W3CCredential.ts +++ b/wrappers/javascript/packages/anoncreds-shared/src/api/W3CCredential.ts @@ -34,6 +34,11 @@ export type ProcessW3CCredentialOptions = { revocationRegistryDefinition?: RevocationRegistryDefinition | JsonObject } +export type W3CCredentialFromLegacyOptions = { + credential: Credential + credentialDefinition: CredentialDefinition | JsonObject +} + export class W3CCredential extends AnoncredsObject { public static create(options: CreateW3CCredentialOptions) { let credential @@ -150,8 +155,28 @@ export class W3CCredential extends AnoncredsObject { ) } - public static fromLegacy(credential: Credential): W3CCredential { - return new W3CCredential(anoncreds.credentialToW3C({ objectHandle: credential.handle }).handle) + 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, + }).handle + ) + } finally { + objectHandles.forEach((handle) => { + handle.clear() + }) + } + return credential } public addNonAnonCredsIntegrityProof(proof: string): W3CCredential { diff --git a/wrappers/python/anoncreds/bindings.py b/wrappers/python/anoncreds/bindings.py index 366b6832..6880b546 100644 --- a/wrappers/python/anoncreds/bindings.py +++ b/wrappers/python/anoncreds/bindings.py @@ -1055,11 +1055,13 @@ def process_w3c_credential( def credential_to_w3c( cred: ObjectHandle, + cred_def: ObjectHandle, ) -> ObjectHandle: result = ObjectHandle() do_call( "anoncreds_credential_to_w3c", cred, + cred_def, byref(result), ) return result diff --git a/wrappers/python/anoncreds/types.py b/wrappers/python/anoncreds/types.py index fc16b4c5..e89bf008 100644 --- a/wrappers/python/anoncreds/types.py +++ b/wrappers/python/anoncreds/types.py @@ -343,11 +343,15 @@ def rev_reg_index(self) -> Optional[int]: return int(str(sval)) if sval is not None else None def to_w3c( - self + self, + cred_def: Union[str, CredentialDefinition] ) -> "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, ) ) @@ -522,8 +526,8 @@ def to_legacy( return Credential.from_w3c(self) @classmethod - def from_legacy(cls, cred: "Credential") -> "W3CCredential": - return cred.to_w3c() + def from_legacy(cls, cred: "Credential", cred_def: Union[str, CredentialDefinition]) -> "W3CCredential": + return cred.to_w3c(cred_def) class PresentationRequest(bindings.AnoncredsObject): diff --git a/wrappers/python/demo/w3c_test.py b/wrappers/python/demo/w3c_test.py index 993262a2..0d5c6285 100644 --- a/wrappers/python/demo/w3c_test.py +++ b/wrappers/python/demo/w3c_test.py @@ -82,7 +82,7 @@ print("Legacy Credential") print(legacy_cred.to_json()) -w3c_cred = legacy_cred.to_w3c() +w3c_cred = legacy_cred.to_w3c(cred_def_pub) print("W3C converted Credential") print(w3c_cred.to_json()) From 1bed31e5b6985cafdd55031b261321a2217be9da Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Wed, 15 Nov 2023 15:19:37 +0300 Subject: [PATCH 04/21] Added missing method to NodeJS wrapper Signed-off-by: artem.ivanov --- .../anoncreds-nodejs/src/NodeJSAnoncreds.ts | 20 ++++++++++++++--- .../src/NativeBindings.ts | 2 +- .../src/ReactNativeAnoncreds.ts | 2 +- .../anoncreds-shared/src/Anoncreds.ts | 2 +- .../anoncreds-shared/src/api/Credential.ts | 22 +++++++++---------- .../anoncreds-shared/src/api/W3CCredential.ts | 22 +++++++++---------- 6 files changed, 42 insertions(+), 28 deletions(-) diff --git a/wrappers/javascript/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts b/wrappers/javascript/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts index 0bf4bd01..a2725c11 100644 --- a/wrappers/javascript/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts +++ b/wrappers/javascript/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts @@ -687,7 +687,7 @@ export class NodeJSAnoncreds implements Anoncreds { revocationConfiguration?: NativeCredentialRevocationConfig encoding?: string }): ObjectHandle { - const { credentialDefinition, credentialDefinitionPrivate, credentialOffer, credentialRequest } = + const { credentialDefinition, credentialDefinitionPrivate, credentialOffer, credentialRequest, encoding } = serializeArguments(options) const attributeNames = StringListStruct({ @@ -722,7 +722,7 @@ export class NodeJSAnoncreds implements Anoncreds { attributeNames as unknown as Buffer, attributeRawValues as unknown as Buffer, revocationConfiguration?.ref().address() ?? 0, - options.encoding, + encoding, credentialPtr ) this.handleError() @@ -907,7 +907,7 @@ export class NodeJSAnoncreds implements Anoncreds { return Boolean(handleReturnPointer(ret)) } - public credentialToW3C(options: { objectHandle: ObjectHandle, credentialDefinition: ObjectHandle }): ObjectHandle { + public credentialToW3C(options: { objectHandle: ObjectHandle; credentialDefinition: ObjectHandle }): ObjectHandle { const { objectHandle, credentialDefinition } = serializeArguments(options) const ret = allocatePointer() @@ -943,6 +943,20 @@ export class NodeJSAnoncreds implements Anoncreds { return new ObjectHandle(handleReturnPointer(ret)) } + public w3cCredentialAddNonAnonCredsIntegrityProof(options: { + objectHandle: ObjectHandle + proof: string + }): ObjectHandle { + const { objectHandle, proof } = serializeArguments(options) + + const ret = allocatePointer() + + this.nativeAnoncreds.anoncreds_w3c_credential_add_non_anoncreds_integrity_proof(objectHandle, proof, ret) + this.handleError() + + return new ObjectHandle(handleReturnPointer(ret)) + } + public w3cCredentialSetId(options: { objectHandle: ObjectHandle; id: string }): ObjectHandle { const { objectHandle, id } = serializeArguments(options) diff --git a/wrappers/javascript/packages/anoncreds-react-native/src/NativeBindings.ts b/wrappers/javascript/packages/anoncreds-react-native/src/NativeBindings.ts index 4bdd5692..60344f5c 100644 --- a/wrappers/javascript/packages/anoncreds-react-native/src/NativeBindings.ts +++ b/wrappers/javascript/packages/anoncreds-react-native/src/NativeBindings.ts @@ -237,7 +237,7 @@ export type NativeBindings = { w3cCredentialAddType(options: { objectHandle: number; type_: string }): ReturnObject - credentialToW3C(options: { objectHandle: number, credentialDefinition: number }): ReturnObject + credentialToW3C(options: { objectHandle: number; credentialDefinition: number }): 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 03204b61..8d55cf44 100644 --- a/wrappers/javascript/packages/anoncreds-react-native/src/ReactNativeAnoncreds.ts +++ b/wrappers/javascript/packages/anoncreds-react-native/src/ReactNativeAnoncreds.ts @@ -571,7 +571,7 @@ export class ReactNativeAnoncreds implements Anoncreds { return new ObjectHandle(handle) } - public credentialToW3C(options: { objectHandle: ObjectHandle, credentialDefinition: ObjectHandle }): ObjectHandle { + public credentialToW3C(options: { objectHandle: ObjectHandle; credentialDefinition: ObjectHandle }): 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 b83d2269..a8debf1b 100644 --- a/wrappers/javascript/packages/anoncreds-shared/src/Anoncreds.ts +++ b/wrappers/javascript/packages/anoncreds-shared/src/Anoncreds.ts @@ -280,7 +280,7 @@ export type Anoncreds = { w3cCredentialFromJson(options: { json: string }): ObjectHandle - credentialToW3C(options: { objectHandle: ObjectHandle, credentialDefinition: ObjectHandle }): ObjectHandle + credentialToW3C(options: { objectHandle: ObjectHandle; credentialDefinition: ObjectHandle }): 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 dee4f390..d118fc70 100644 --- a/wrappers/javascript/packages/anoncreds-shared/src/api/Credential.ts +++ b/wrappers/javascript/packages/anoncreds-shared/src/api/Credential.ts @@ -151,17 +151,17 @@ export class Credential extends AnoncredsObject { // 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, - }).handle - ) + 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 + }).handle + ) } finally { objectHandles.forEach((handle) => { handle.clear() diff --git a/wrappers/javascript/packages/anoncreds-shared/src/api/W3CCredential.ts b/wrappers/javascript/packages/anoncreds-shared/src/api/W3CCredential.ts index ab35df15..bd974bae 100644 --- a/wrappers/javascript/packages/anoncreds-shared/src/api/W3CCredential.ts +++ b/wrappers/javascript/packages/anoncreds-shared/src/api/W3CCredential.ts @@ -160,17 +160,17 @@ export class W3CCredential extends AnoncredsObject { // 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, - }).handle - ) + 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 + }).handle + ) } finally { objectHandles.forEach((handle) => { handle.clear() From 0e817d6483c46271f130e2e699c23222ff0005a3 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Thu, 16 Nov 2023 09:12:39 +0300 Subject: [PATCH 05/21] Fixes in Python and Node wrappers Signed-off-by: artem.ivanov --- .../anoncreds-nodejs/tests/api.test.ts | 24 ++++ .../anoncreds-shared/src/api/Credential.ts | 8 +- .../anoncreds-shared/src/api/W3CCredential.ts | 75 +++++++------ wrappers/python/anoncreds/bindings.py | 4 +- wrappers/python/anoncreds/types.py | 103 ++++++++---------- wrappers/python/demo/w3c_test.py | 28 ++++- 6 files changed, 146 insertions(+), 96 deletions(-) diff --git a/wrappers/javascript/packages/anoncreds-nodejs/tests/api.test.ts b/wrappers/javascript/packages/anoncreds-nodejs/tests/api.test.ts index 227baf7a..c9f5b642 100644 --- a/wrappers/javascript/packages/anoncreds-nodejs/tests/api.test.ts +++ b/wrappers/javascript/packages/anoncreds-nodejs/tests/api.test.ts @@ -643,6 +643,10 @@ describe('API W3C', () => { expect('mock:uri').toEqual(legacyCredential.schemaId) expect('mock:uri').toEqual(legacyCredential.credentialDefinitionId) + const legacyCredentialFrom = Credential.fromW3C({ credential }) + expect('mock:uri').toEqual(legacyCredentialFrom.schemaId) + expect('mock:uri').toEqual(legacyCredentialFrom.credentialDefinitionId) + const w3cCredential = W3CCredential.fromLegacy({ credential: legacyCredential, credentialDefinition }) expect('mock:uri').toEqual(w3cCredential.schemaId) expect('mock:uri').toEqual(w3cCredential.credentialDefinitionId) @@ -651,6 +655,26 @@ describe('API W3C', () => { expect('mock:uri').toEqual(convertedW3CCredential.schemaId) expect('mock:uri').toEqual(convertedW3CCredential.credentialDefinitionId) + convertedW3CCredential.addNonAnonCredsIntegrityProof({ + type: 'Ed25519Signature2020', + created: '2021-11-13T18:19:39Z', + verificationMethod: 'did:sov:3avoBCqDMFHFaKUHug9s8W#key-1', + proofPurpose: 'assertionMethod', + proofValue: 'z58DAdFfa9SkqZMVPxAQpic7ndSayn1PzZs6ZjWp1CktyGesjuTSwRdoWhAfGFCF5bppETSTojQCrfFPP2oumHKtz' + }) + + const id = 'http://example.com/credentials/3732' + const subjectId = 'did:example:ebfeb1f712ebc6f1c276e12ec21' + + convertedW3CCredential.setId(id) + convertedW3CCredential.setSubjectId(subjectId) + convertedW3CCredential.addContext('https://www.w3.org/2018/credentials/examples/v1') + convertedW3CCredential.addType('UniversityDegreeCredential') + const convertedW3CCredentialJson = convertedW3CCredential.toJson() + + expect(id).toEqual(convertedW3CCredentialJson.id) + expect(subjectId).toEqual(convertedW3CCredentialJson.credentialSubject.id) + const credentialReceived = credential.process({ credentialDefinition, credentialRequestMetadata, diff --git a/wrappers/javascript/packages/anoncreds-shared/src/api/Credential.ts b/wrappers/javascript/packages/anoncreds-shared/src/api/Credential.ts index d118fc70..b825e6f9 100644 --- a/wrappers/javascript/packages/anoncreds-shared/src/api/Credential.ts +++ b/wrappers/javascript/packages/anoncreds-shared/src/api/Credential.ts @@ -38,6 +38,10 @@ export type CredentialToW3COptions = { credentialDefinition: CredentialDefinition | JsonObject } +export type CredentialFromW3COptions = { + credential: W3CCredential +} + export class Credential extends AnoncredsObject { public static create(options: CreateCredentialOptions) { let credential @@ -170,7 +174,7 @@ export class Credential extends AnoncredsObject { return credential } - public static fromW3C(credential: W3CCredential) { - return new Credential(anoncreds.credentialFromW3C({ objectHandle: credential.handle }).handle) + public static fromW3C(options: CredentialFromW3COptions) { + return new Credential(anoncreds.credentialFromW3C({ objectHandle: options.credential.handle }).handle) } } diff --git a/wrappers/javascript/packages/anoncreds-shared/src/api/W3CCredential.ts b/wrappers/javascript/packages/anoncreds-shared/src/api/W3CCredential.ts index bd974bae..3246c70e 100644 --- a/wrappers/javascript/packages/anoncreds-shared/src/api/W3CCredential.ts +++ b/wrappers/javascript/packages/anoncreds-shared/src/api/W3CCredential.ts @@ -179,48 +179,53 @@ export class W3CCredential extends AnoncredsObject { return credential } - public addNonAnonCredsIntegrityProof(proof: string): W3CCredential { - return new W3CCredential( - anoncreds.w3cCredentialAddNonAnonCredsIntegrityProof({ - objectHandle: this.handle, - proof - }).handle - ) + public addNonAnonCredsIntegrityProof(proof: JsonObject) { + const credential = anoncreds.w3cCredentialAddNonAnonCredsIntegrityProof({ + objectHandle: this.handle, + proof: JSON.stringify(proof) + }) + + this.handle.clear() + this.handle = credential } - public setId(id: string): W3CCredential { - return new W3CCredential( - anoncreds.w3cCredentialSetId({ - objectHandle: this.handle, - id - }).handle - ) + public setId(id: string) { + const credential = anoncreds.w3cCredentialSetId({ + objectHandle: this.handle, + id + }) + + this.handle.clear() + this.handle = credential } - public setSubjectId(id: string): W3CCredential { - return new W3CCredential( - anoncreds.w3cCredentialSetSubjectId({ - objectHandle: this.handle, - id - }).handle - ) + public setSubjectId(id: string) { + const credential = anoncreds.w3cCredentialSetSubjectId({ + objectHandle: this.handle, + id + }) + + this.handle.clear() + this.handle = credential } - public addContext(context: string): W3CCredential { - return new W3CCredential( - anoncreds.w3cCredentialAddContext({ - objectHandle: this.handle, - context - }).handle - ) + public addContext(context: string) { + const credential = anoncreds.w3cCredentialAddContext({ + objectHandle: this.handle, + context + }) + + this.handle.clear() + this.handle = credential } - public addType(type_: string): W3CCredential { - return new W3CCredential( - anoncreds.w3cCredentialAddType({ - objectHandle: this.handle, - type_ - }).handle - ) + public addType(type_: string) { + const credential = anoncreds.w3cCredentialAddType({ + objectHandle: this.handle, + type_ + }) + + this.handle.clear() + this.handle = credential } } diff --git a/wrappers/python/anoncreds/bindings.py b/wrappers/python/anoncreds/bindings.py index 6880b546..9d7fbb73 100644 --- a/wrappers/python/anoncreds/bindings.py +++ b/wrappers/python/anoncreds/bindings.py @@ -1093,13 +1093,13 @@ def w3c_credential_add_non_anoncreds_integrity_proof( return result -def w3c_set_credential_id( +def w3c_credential_set_id( cred: ObjectHandle, id: str, ) -> ObjectHandle: result = ObjectHandle() do_call( - "anoncreds_w3c_set_credential_id", + "anoncreds_w3c_credential_set_id", cred, encode_str(id), byref(result), diff --git a/wrappers/python/anoncreds/types.py b/wrappers/python/anoncreds/types.py index e89bf008..afa93e63 100644 --- a/wrappers/python/anoncreds/types.py +++ b/wrappers/python/anoncreds/types.py @@ -1,3 +1,4 @@ +import json from typing import Mapping, Optional, Sequence, Tuple, Union from . import bindings @@ -363,61 +364,6 @@ def from_w3c(cls, cred: "W3CCredential") -> "Credential": ) ) - def add_non_anoncreds_integrity_proof( - self, - proof: str - ) -> "W3CCredential": - return W3CCredential( - bindings.w3c_credential_add_non_anoncreds_integrity_proof( - self.handle, - proof, - ) - ) - - def set_credential_id( - self, - id: str - ) -> "W3CCredential": - return W3CCredential( - bindings.w3c_credential_set_credential_id( - self.handle, - id, - ) - ) - - def set_subject_id( - self, - id: str - ) -> "W3CCredential": - return W3CCredential( - bindings.w3c_credential_set_subject_id( - self.handle, - id, - ) - ) - - def add_context( - self, - context: str - ) -> "W3CCredential": - return W3CCredential( - bindings.w3c_credential_add_context( - self.handle, - context, - ) - ) - - def add_type( - self, - type: str - ) -> "W3CCredential": - return W3CCredential( - bindings.w3c_credential_add_type( - self.handle, - type, - ) - ) - class W3CCredential(bindings.AnoncredsObject): GET_ATTR = "anoncreds_w3c_credential_get_attribute" @@ -529,6 +475,53 @@ def to_legacy( def from_legacy(cls, cred: "Credential", cred_def: Union[str, CredentialDefinition]) -> "W3CCredential": return cred.to_w3c(cred_def) + def add_non_anoncreds_integrity_proof( + self, + proof: Union[str, dict] + ) -> "W3CCredential": + if isinstance(proof, dict): + proof = json.dumps(proof) + self.handle = bindings.w3c_credential_add_non_anoncreds_integrity_proof( + self.handle, + proof, + ) + + def set_id( + self, + id: str + ) -> "W3CCredential": + self.handle = bindings.w3c_credential_set_id( + self.handle, + id, + ) + + def set_subject_id( + self, + id: str + ) -> "W3CCredential": + self.handle = bindings.w3c_credential_set_subject_id( + self.handle, + id, + ) + + def add_context( + self, + context: str + ) -> "W3CCredential": + self.handle = bindings.w3c_credential_add_context( + self.handle, + context, + ) + + def add_type( + self, + type: str + ) -> "W3CCredential": + self.handle = bindings.w3c_credential_add_type( + self.handle, + type, + ) + class PresentationRequest(bindings.AnoncredsObject): @classmethod diff --git a/wrappers/python/demo/w3c_test.py b/wrappers/python/demo/w3c_test.py index 0d5c6285..2e35806f 100644 --- a/wrappers/python/demo/w3c_test.py +++ b/wrappers/python/demo/w3c_test.py @@ -79,13 +79,37 @@ print(recv_cred.to_json()) legacy_cred = recv_cred.to_legacy() -print("Legacy Credential") +print("Legacy Credential `to_legacy`") +print(legacy_cred.to_json()) + +legacy_cred = Credential.from_w3c(recv_cred) +print("Legacy Credential `from_w3c`") print(legacy_cred.to_json()) w3c_cred = legacy_cred.to_w3c(cred_def_pub) -print("W3C converted Credential") +print("W3C converted Credential `to_w3c`") print(w3c_cred.to_json()) +w3c_cred_restored = W3CCredential.from_legacy(legacy_cred, cred_def_pub) +print("W3C restored Credential `from_legacy`") +print(w3c_cred_restored.to_json()) + + +w3c_cred_restored.add_non_anoncreds_integrity_proof({ + "type": "Ed25519Signature2020", + "created": "2021-11-13T18:19:39Z", + "verificationMethod": "did:sov:3avoBCqDMFHFaKUHug9s8W#key-1", + "proofPurpose": "assertionMethod", + "proofValue": "z58DAdFfa9SkqZMVPxAQpic7ndSayn1PzZs6ZjWp1CktyGesjuTSwRdoWhAfGFCF5bppETSTojQCrfFPP2oumHKtz" +}) +w3c_cred_restored.set_id("http://example.com/credentials/3732") +w3c_cred_restored.set_subject_id("did:example:ebfeb1f712ebc6f1c276e12ec21") +w3c_cred_restored.add_context("https://www.w3.org/2018/credentials/examples/v1") +w3c_cred_restored.add_type("UniversityDegreeCredential") + +print("W3C extended Credential") +print(w3c_cred_restored.to_json()) + time_after_creating_cred = time_create_rev_status_list + 1 issued_rev_status_list = revocation_status_list.update( cred_def_pub, From 2f97949ecf6115f48c7bdebb0be71f7657a52a22 Mon Sep 17 00:00:00 2001 From: Abdulbois Date: Tue, 21 Nov 2023 20:30:31 +0500 Subject: [PATCH 06/21] fix: Replace with w3c call, change order of enum variants Signed-off-by: Abdulbois Signed-off-by: artem.ivanov --- .../javascript/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts | 2 +- .../packages/anoncreds-nodejs/src/library/bindings.ts | 2 +- .../packages/anoncreds-shared/src/api/W3CCredential.ts | 2 +- wrappers/python/anoncreds/bindings.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/wrappers/javascript/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts b/wrappers/javascript/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts index a2725c11..5f25e62c 100644 --- a/wrappers/javascript/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts +++ b/wrappers/javascript/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts @@ -721,8 +721,8 @@ export class NodeJSAnoncreds implements Anoncreds { credentialRequest, attributeNames as unknown as Buffer, attributeRawValues as unknown as Buffer, - revocationConfiguration?.ref().address() ?? 0, encoding, + revocationConfiguration?.ref().address() ?? 0, credentialPtr ) this.handleError() diff --git a/wrappers/javascript/packages/anoncreds-nodejs/src/library/bindings.ts b/wrappers/javascript/packages/anoncreds-nodejs/src/library/bindings.ts index 5533faca..ce88c874 100644 --- a/wrappers/javascript/packages/anoncreds-nodejs/src/library/bindings.ts +++ b/wrappers/javascript/packages/anoncreds-nodejs/src/library/bindings.ts @@ -218,8 +218,8 @@ export const nativeBindings = { FFI_OBJECT_HANDLE, StringListStruct, StringListStruct, - FFI_OBJECT_HANDLE, FFI_STRING, + FFI_OBJECT_HANDLE, FFI_OBJECT_HANDLE_PTR ] ], diff --git a/wrappers/javascript/packages/anoncreds-shared/src/api/W3CCredential.ts b/wrappers/javascript/packages/anoncreds-shared/src/api/W3CCredential.ts index 3246c70e..7ae213fc 100644 --- a/wrappers/javascript/packages/anoncreds-shared/src/api/W3CCredential.ts +++ b/wrappers/javascript/packages/anoncreds-shared/src/api/W3CCredential.ts @@ -83,7 +83,7 @@ export class W3CCredential extends AnoncredsObject { } public static fromJson(json: JsonObject) { - return new W3CCredential(anoncreds.credentialFromJson({ json: JSON.stringify(json) }).handle) + return new W3CCredential(anoncreds.w3cCredentialFromJson({ json: JSON.stringify(json) }).handle) } public process(options: ProcessW3CCredentialOptions) { diff --git a/wrappers/python/anoncreds/bindings.py b/wrappers/python/anoncreds/bindings.py index 9d7fbb73..4e5de89a 100644 --- a/wrappers/python/anoncreds/bindings.py +++ b/wrappers/python/anoncreds/bindings.py @@ -1024,10 +1024,10 @@ def create_w3c_credential( cred_request, names_list, raw_values_list, + encode_str(encoding), pointer(revocation_config) if revocation_config else POINTER(RevocationConfig)(), - encode_str(encoding), byref(cred), ) return cred From 19ca2758eb43625876e879fcd0eb1cc9c258b142 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Mon, 4 Dec 2023 11:02:10 +0300 Subject: [PATCH 07/21] Python: Added classes for W3CCredentialOffer and W3CCredentialRequest Signed-off-by: artem.ivanov --- wrappers/python/anoncreds/__init__.py | 2 + wrappers/python/anoncreds/bindings.py | 37 ++++++++++++++++ wrappers/python/anoncreds/types.py | 64 +++++++++++++++++++++++++-- wrappers/python/demo/w3c_test.py | 8 ++-- 4 files changed, 103 insertions(+), 8 deletions(-) diff --git a/wrappers/python/anoncreds/__init__.py b/wrappers/python/anoncreds/__init__.py index f177cbef..4264e772 100644 --- a/wrappers/python/anoncreds/__init__.py +++ b/wrappers/python/anoncreds/__init__.py @@ -21,6 +21,8 @@ RevocationStatusList, RevocationRegistryDefinition, RevocationRegistryDefinitionPrivate, + W3CCredentialOffer, + W3CCredentialRequest, W3CCredential, W3CPresentation, ) diff --git a/wrappers/python/anoncreds/bindings.py b/wrappers/python/anoncreds/bindings.py index 4e5de89a..5ecc0a0d 100644 --- a/wrappers/python/anoncreds/bindings.py +++ b/wrappers/python/anoncreds/bindings.py @@ -709,6 +709,20 @@ def create_credential_offer( return cred_offer +def create_w3c_credential_offer( + schema_id: str, cred_def_id: str, key_proof: ObjectHandle +) -> ObjectHandle: + cred_offer = ObjectHandle() + do_call( + "anoncreds_create_w3c_credential_offer", + encode_str(schema_id), + encode_str(cred_def_id), + key_proof, + byref(cred_offer), + ) + return cred_offer + + def create_credential_request( entropy: Optional[str], prover_did: Optional[str], @@ -732,6 +746,29 @@ def create_credential_request( return (cred_req, cred_req_metadata) +def create_w3c_credential_request( + entropy: Optional[str], + prover_did: Optional[str], + cred_def: ObjectHandle, + link_secret: str, + link_secret_id: str, + cred_offer: ObjectHandle, +) -> Tuple[ObjectHandle, ObjectHandle]: + cred_req, cred_req_metadata = ObjectHandle(), ObjectHandle() + do_call( + "anoncreds_create_w3c_credential_request", + encode_str(entropy), + encode_str(prover_did), + cred_def, + encode_str(link_secret), + encode_str(link_secret_id), + cred_offer, + byref(cred_req), + byref(cred_req_metadata), + ) + return (cred_req, cred_req_metadata) + + def create_link_secret() -> str: result = StrBuffer() do_call( diff --git a/wrappers/python/anoncreds/types.py b/wrappers/python/anoncreds/types.py index afa93e63..016c5ee7 100644 --- a/wrappers/python/anoncreds/types.py +++ b/wrappers/python/anoncreds/types.py @@ -103,6 +103,27 @@ def load(cls, value: Union[dict, str, bytes, memoryview]) -> "CredentialOffer": ) +class W3CCredentialOffer(bindings.AnoncredsObject): + @classmethod + def create( + cls, + schema_id: str, + cred_def_id: str, + key_proof: Union[str, KeyCorrectnessProof], + ) -> "W3CCredentialOffer": + if not isinstance(key_proof, bindings.AnoncredsObject): + key_proof = KeyCorrectnessProof.load(key_proof) + return W3CCredentialOffer( + bindings.create_w3c_credential_offer(schema_id, cred_def_id, key_proof.handle) + ) + + @classmethod + def load(cls, value: Union[dict, str, bytes, memoryview]) -> "W3CCredentialOffer": + return W3CCredentialOffer( + bindings._object_from_json("anoncreds_credential_offer_from_json", value) + ) + + class CredentialRequest(bindings.AnoncredsObject): @classmethod def create( @@ -137,6 +158,41 @@ def load(cls, value: Union[dict, str, bytes, memoryview]) -> "CredentialRequest" ) + +class W3CCredentialRequest(bindings.AnoncredsObject): + @classmethod + def create( + cls, + entropy: Optional[str], + prover_did: Optional[str], + cred_def: Union[str, CredentialDefinition], + link_secret: str, + link_secret_id: str, + cred_offer: Union[str, W3CCredentialOffer], + ) -> Tuple["W3CCredentialRequest", "CredentialRequestMetadata"]: + if not isinstance(cred_def, bindings.AnoncredsObject): + cred_def = CredentialDefinition.load(cred_def) + if not isinstance(cred_offer, bindings.AnoncredsObject): + cred_offer = W3CCredentialOffer.load(cred_offer) + cred_def_handle, cred_def_metadata = bindings.create_w3c_credential_request( + entropy, + prover_did, + cred_def.handle, + link_secret, + link_secret_id, + cred_offer.handle, + ) + return W3CCredentialRequest(cred_def_handle), CredentialRequestMetadata( + cred_def_metadata + ) + + @classmethod + def load(cls, value: Union[dict, str, bytes, memoryview]) -> "W3CCredentialRequest": + return W3CCredentialRequest( + bindings._object_from_json("anoncreds_credential_request_from_json", value) + ) + + class CredentialRequestMetadata(bindings.AnoncredsObject): @classmethod def load( @@ -373,8 +429,8 @@ def create( cls, cred_def: Union[str, CredentialDefinition], cred_def_private: Union[str, CredentialDefinitionPrivate], - cred_offer: Union[str, CredentialOffer], - cred_request: Union[str, CredentialRequest], + cred_offer: Union[str, W3CCredentialOffer], + cred_request: Union[str, W3CCredentialRequest], attr_raw_values: Mapping[str, str], revocation_config: Optional["CredentialRevocationConfig"] = None, encoding: Optional[str] = None, @@ -384,9 +440,9 @@ def create( if not isinstance(cred_def_private, bindings.AnoncredsObject): cred_def_private = CredentialDefinitionPrivate.load(cred_def_private) if not isinstance(cred_offer, bindings.AnoncredsObject): - cred_offer = CredentialOffer.load(cred_offer) + cred_offer = W3CCredentialOffer.load(cred_offer) if not isinstance(cred_request, bindings.AnoncredsObject): - cred_request = CredentialRequest.load(cred_request) + cred_request = W3CCredentialRequest.load(cred_request) cred = bindings.create_w3c_credential( cred_def.handle, cred_def_private.handle, diff --git a/wrappers/python/demo/w3c_test.py b/wrappers/python/demo/w3c_test.py index 2e35806f..21ecc8f0 100644 --- a/wrappers/python/demo/w3c_test.py +++ b/wrappers/python/demo/w3c_test.py @@ -4,8 +4,8 @@ Credential, W3CCredential, CredentialDefinition, - CredentialOffer, - CredentialRequest, + W3CCredentialOffer, + W3CCredentialRequest, CredentialRevocationConfig, CredentialRevocationState, PresentationRequest, @@ -50,9 +50,9 @@ link_secret = create_link_secret() link_secret_id = "default" -cred_offer = CredentialOffer.create(schema_id, cred_def_id, cred_def_correctness) +cred_offer = W3CCredentialOffer.create(schema_id, cred_def_id, cred_def_correctness) -cred_request, cred_request_metadata = CredentialRequest.create( +cred_request, cred_request_metadata = W3CCredentialRequest.create( entropy, None, cred_def_pub, link_secret, link_secret_id, cred_offer ) From 00d3a1539d34be0a65e048edf46e920473786ef7 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Fri, 8 Dec 2023 09:19:50 +0300 Subject: [PATCH 08/21] Reverted lerna version change Signed-off-by: artem.ivanov --- wrappers/javascript/package.json | 2 +- wrappers/javascript/pnpm-lock.yaml | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/wrappers/javascript/package.json b/wrappers/javascript/package.json index d5d8995d..1514a401 100644 --- a/wrappers/javascript/package.json +++ b/wrappers/javascript/package.json @@ -39,7 +39,7 @@ "eslint-plugin-import": "^2.28.1", "eslint-plugin-prettier": "^5.0.0", "jest": "^29.7.0", - "lerna": "^7.2.0", + "lerna": "7.2.0", "prettier": "^3.0.3", "ts-jest": "^29.1.1", "ts-node": "^10.9.1", diff --git a/wrappers/javascript/pnpm-lock.yaml b/wrappers/javascript/pnpm-lock.yaml index 1f28abfd..8eb90b1a 100644 --- a/wrappers/javascript/pnpm-lock.yaml +++ b/wrappers/javascript/pnpm-lock.yaml @@ -44,7 +44,7 @@ importers: specifier: ^29.7.0 version: 29.7.0(@types/node@20.6.4)(ts-node@10.9.1) lerna: - specifier: ^7.2.0 + specifier: 7.2.0 version: 7.2.0 prettier: specifier: ^3.0.3 @@ -4602,7 +4602,7 @@ packages: glob: 7.2.3 infer-owner: 1.0.4 lru-cache: 6.0.0 - minipass: 3.3.6 + minipass: 3.1.6 minipass-collect: 1.0.2 minipass-flush: 1.0.5 minipass-pipeline: 1.2.4 @@ -9503,7 +9503,7 @@ packages: { integrity: sha512-6T6lH0H8OG9kITm/Jm6tdooIbogG9e0tLgpY6mphXSm/A9u8Nq1ryBG+Qspiub9LjWlBPsPS3tWQ/Botq4FdxA== } engines: { node: '>= 8' } dependencies: - minipass: 3.3.6 + minipass: 3.1.6 /minipass-fetch@3.0.4: resolution: @@ -9522,7 +9522,7 @@ packages: { integrity: sha512-JmQSYYpPUqX5Jyn1mXaRwOda1uQ8HP5KAT/oDSLCzt1BYRhQU0/hDtsB1ufZfEEzMZ9aAVmsBw8+FWsIXlClWw== } engines: { node: '>= 8' } dependencies: - minipass: 3.3.6 + minipass: 3.1.6 /minipass-json-stream@1.0.1: resolution: @@ -9537,7 +9537,7 @@ packages: { integrity: sha512-xuIq7cIOt09RPRJ19gdi4b+RiNvDFYe5JH+ggNvBqGqpQXcru3PcRmOZuHBKWK1Txf9+cQ+HMVN4d6z46LZP7A== } engines: { node: '>=8' } dependencies: - minipass: 3.3.6 + minipass: 3.1.6 /minipass-sized@1.0.3: resolution: @@ -9553,7 +9553,6 @@ packages: engines: { node: '>=8' } dependencies: yallist: 4.0.0 - dev: false /minipass@3.3.6: resolution: @@ -11705,7 +11704,7 @@ packages: { integrity: sha512-97qShzy1AiyxvPNIkLWoGua7xoQzzPjQ0HAH4B0rWKo7SZ6USuPcrUiAFrws0UH8RrbWmgq3LMTObhPIHbbBeQ== } engines: { node: '>= 8' } dependencies: - minipass: 3.3.6 + minipass: 3.1.6 dev: false /ssri@9.0.1: @@ -13076,4 +13075,4 @@ packages: /yocto-queue@0.1.0: resolution: { integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q== } - engines: { node: '>=10' } + engines: { node: '>=10' } \ No newline at end of file From 2b903fe88e96ec5047986a8c383679148099c8ec Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Fri, 8 Dec 2023 10:28:58 +0300 Subject: [PATCH 09/21] Run prettier Signed-off-by: artem.ivanov --- .../javascript/packages/anoncreds-shared/src/api/Credential.ts | 1 - wrappers/javascript/pnpm-lock.yaml | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/wrappers/javascript/packages/anoncreds-shared/src/api/Credential.ts b/wrappers/javascript/packages/anoncreds-shared/src/api/Credential.ts index b825e6f9..19b6a4d5 100644 --- a/wrappers/javascript/packages/anoncreds-shared/src/api/Credential.ts +++ b/wrappers/javascript/packages/anoncreds-shared/src/api/Credential.ts @@ -132,7 +132,6 @@ export class Credential extends AnoncredsObject { } return this } - public get schemaId() { return anoncreds.credentialGetAttribute({ objectHandle: this.handle, name: 'schema_id' }) } diff --git a/wrappers/javascript/pnpm-lock.yaml b/wrappers/javascript/pnpm-lock.yaml index 8eb90b1a..de8f4741 100644 --- a/wrappers/javascript/pnpm-lock.yaml +++ b/wrappers/javascript/pnpm-lock.yaml @@ -13075,4 +13075,4 @@ packages: /yocto-queue@0.1.0: resolution: { integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q== } - engines: { node: '>=10' } \ No newline at end of file + engines: { node: '>=10' } From c4369493aa7daed0535bdda3908b6145a484472e Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Mon, 11 Dec 2023 12:00:24 +0300 Subject: [PATCH 10/21] Use `W3c` instead of capitalized `W3C` Signed-off-by: artem.ivanov --- .../anoncreds-nodejs/src/NodeJSAnoncreds.ts | 22 ++++---- .../anoncreds-nodejs/tests/api.test.ts | 50 +++++++++---------- .../anoncreds-nodejs/tests/bindings.test.ts | 32 ++++++------ .../anoncreds-react-native/cpp/HostObject.cpp | 24 ++++----- .../anoncreds-react-native/cpp/anoncreds.cpp | 20 ++++---- .../anoncreds-react-native/cpp/anoncreds.h | 18 +++---- .../src/NativeBindings.ts | 18 +++---- .../src/ReactNativeAnoncreds.ts | 34 ++++++------- .../anoncreds-shared/src/Anoncreds.ts | 18 +++---- .../anoncreds-shared/src/api/Credential.ts | 18 +++---- .../{W3CCredential.ts => W3cCredential.ts} | 48 +++++++++--------- ...edentialOffer.ts => W3cCredentialOffer.ts} | 12 ++--- ...tialRequest.ts => W3cCredentialRequest.ts} | 20 ++++---- ...{W3CPresentation.ts => W3cPresentation.ts} | 30 +++++------ .../anoncreds-shared/src/api/index.ts | 8 +-- 15 files changed, 186 insertions(+), 186 deletions(-) rename wrappers/javascript/packages/anoncreds-shared/src/api/{W3CCredential.ts => W3cCredential.ts} (84%) rename wrappers/javascript/packages/anoncreds-shared/src/api/{W3CCredentialOffer.ts => W3cCredentialOffer.ts} (76%) rename wrappers/javascript/packages/anoncreds-shared/src/api/{W3CCredentialRequest.ts => W3cCredentialRequest.ts} (73%) rename wrappers/javascript/packages/anoncreds-shared/src/api/{W3CPresentation.ts => W3cPresentation.ts} (88%) diff --git a/wrappers/javascript/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts b/wrappers/javascript/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts index 5f25e62c..1f4e36d4 100644 --- a/wrappers/javascript/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts +++ b/wrappers/javascript/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts @@ -627,7 +627,7 @@ export class NodeJSAnoncreds implements Anoncreds { return new ObjectHandle(handleReturnPointer(ret)) } - public createW3CCredentialOffer(options: { + public createW3cCredentialOffer(options: { schemaId: string credentialDefinitionId: string keyCorrectnessProof: ObjectHandle @@ -646,7 +646,7 @@ export class NodeJSAnoncreds implements Anoncreds { return new ObjectHandle(handleReturnPointer(ret)) } - public createW3CCredentialRequest(options: { + public createW3cCredentialRequest(options: { entropy?: string proverDid?: string credentialDefinition: ObjectHandle @@ -678,7 +678,7 @@ export class NodeJSAnoncreds implements Anoncreds { } } - public createW3CCredential(options: { + public createW3cCredential(options: { credentialDefinition: ObjectHandle credentialDefinitionPrivate: ObjectHandle credentialOffer: ObjectHandle @@ -730,7 +730,7 @@ export class NodeJSAnoncreds implements Anoncreds { return new ObjectHandle(handleReturnPointer(credentialPtr)) } - public processW3CCredential(options: { + public processW3cCredential(options: { credential: ObjectHandle credentialRequestMetadata: ObjectHandle linkSecret: string @@ -754,7 +754,7 @@ export class NodeJSAnoncreds implements Anoncreds { return new ObjectHandle(handleReturnPointer(ret)) } - public createW3CPresentation(options: { + public createW3cPresentation(options: { presentationRequest: ObjectHandle credentials: NativeCredentialEntry[] credentialsProve: NativeCredentialProve[] @@ -842,7 +842,7 @@ export class NodeJSAnoncreds implements Anoncreds { return new ObjectHandle(handleReturnPointer(ret)) } - public verifyW3CPresentation(options: { + public verifyW3cPresentation(options: { presentation: ObjectHandle presentationRequest: ObjectHandle schemas: ObjectHandle[] @@ -907,7 +907,7 @@ export class NodeJSAnoncreds implements Anoncreds { return Boolean(handleReturnPointer(ret)) } - public credentialToW3C(options: { objectHandle: ObjectHandle; credentialDefinition: ObjectHandle }): ObjectHandle { + public credentialToW3c(options: { objectHandle: ObjectHandle; credentialDefinition: ObjectHandle }): ObjectHandle { const { objectHandle, credentialDefinition } = serializeArguments(options) const ret = allocatePointer() @@ -918,7 +918,7 @@ export class NodeJSAnoncreds implements Anoncreds { return new ObjectHandle(handleReturnPointer(ret)) } - public credentialFromW3C(options: { objectHandle: ObjectHandle }): ObjectHandle { + public credentialFromW3c(options: { objectHandle: ObjectHandle }): ObjectHandle { const { objectHandle } = serializeArguments(options) const ret = allocatePointer() @@ -990,12 +990,12 @@ export class NodeJSAnoncreds implements Anoncreds { return new ObjectHandle(handleReturnPointer(ret)) } - public w3cCredentialAddType(options: { objectHandle: ObjectHandle; type_: string }): ObjectHandle { - const { objectHandle, type_ } = serializeArguments(options) + public w3cCredentialAddType(options: { objectHandle: ObjectHandle; type: string }): ObjectHandle { + const { objectHandle, type } = serializeArguments(options) const ret = allocatePointer() - this.nativeAnoncreds.anoncreds_w3c_credential_add_type(objectHandle, type_, ret) + this.nativeAnoncreds.anoncreds_w3c_credential_add_type(objectHandle, type, ret) this.handleError() return new ObjectHandle(handleReturnPointer(ret)) diff --git a/wrappers/javascript/packages/anoncreds-nodejs/tests/api.test.ts b/wrappers/javascript/packages/anoncreds-nodejs/tests/api.test.ts index c9f5b642..2b44a40d 100644 --- a/wrappers/javascript/packages/anoncreds-nodejs/tests/api.test.ts +++ b/wrappers/javascript/packages/anoncreds-nodejs/tests/api.test.ts @@ -12,10 +12,10 @@ import { RevocationRegistryDefinition, RevocationStatusList, Schema, - W3CCredential, - W3CCredentialOffer, - W3CCredentialRequest, - W3CPresentation + W3cCredential, + W3cCredentialOffer, + W3cCredentialRequest, + W3cPresentation } from '@hyperledger/anoncreds-shared' import { setup } from './utils' @@ -608,7 +608,7 @@ describe('API W3C', () => { timestamp: timeCreateRevStatusList }) - const credentialOffer = W3CCredentialOffer.create({ + const credentialOffer = W3cCredentialOffer.create({ schemaId: 'mock:uri', credentialDefinitionId: 'mock:uri', keyCorrectnessProof @@ -617,7 +617,7 @@ describe('API W3C', () => { const linkSecret = LinkSecret.create() const linkSecretId = 'link secret id' - const { credentialRequestMetadata, credentialRequest } = W3CCredentialRequest.create({ + const { credentialRequestMetadata, credentialRequest } = W3cCredentialRequest.create({ entropy: 'entropy', credentialDefinition, linkSecret, @@ -625,7 +625,7 @@ describe('API W3C', () => { credentialOffer }) - const credential = W3CCredential.create({ + const credential = W3cCredential.create({ credentialDefinition, credentialDefinitionPrivate, credentialOffer, @@ -643,19 +643,19 @@ describe('API W3C', () => { expect('mock:uri').toEqual(legacyCredential.schemaId) expect('mock:uri').toEqual(legacyCredential.credentialDefinitionId) - const legacyCredentialFrom = Credential.fromW3C({ credential }) + const legacyCredentialFrom = Credential.fromW3c({ credential }) 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, credentialDefinition }) expect('mock:uri').toEqual(w3cCredential.schemaId) expect('mock:uri').toEqual(w3cCredential.credentialDefinitionId) - const convertedW3CCredential = legacyCredential.toW3C({ credentialDefinition }) - expect('mock:uri').toEqual(convertedW3CCredential.schemaId) - expect('mock:uri').toEqual(convertedW3CCredential.credentialDefinitionId) + const convertedW3cCredential = legacyCredential.toW3c({ credentialDefinition }) + expect('mock:uri').toEqual(convertedW3cCredential.schemaId) + expect('mock:uri').toEqual(convertedW3cCredential.credentialDefinitionId) - convertedW3CCredential.addNonAnonCredsIntegrityProof({ + convertedW3cCredential.addNonAnonCredsIntegrityProof({ type: 'Ed25519Signature2020', created: '2021-11-13T18:19:39Z', verificationMethod: 'did:sov:3avoBCqDMFHFaKUHug9s8W#key-1', @@ -666,14 +666,14 @@ describe('API W3C', () => { const id = 'http://example.com/credentials/3732' const subjectId = 'did:example:ebfeb1f712ebc6f1c276e12ec21' - convertedW3CCredential.setId(id) - convertedW3CCredential.setSubjectId(subjectId) - convertedW3CCredential.addContext('https://www.w3.org/2018/credentials/examples/v1') - convertedW3CCredential.addType('UniversityDegreeCredential') - const convertedW3CCredentialJson = convertedW3CCredential.toJson() + convertedW3cCredential.setId(id) + convertedW3cCredential.setSubjectId(subjectId) + convertedW3cCredential.addContext('https://www.w3.org/2018/credentials/examples/v1') + convertedW3cCredential.addType('UniversityDegreeCredential') + const convertedW3cCredentialJson = convertedW3cCredential.toJson() - expect(id).toEqual(convertedW3CCredentialJson.id) - expect(subjectId).toEqual(convertedW3CCredentialJson.credentialSubject.id) + expect(id).toEqual(convertedW3cCredentialJson.id) + expect(subjectId).toEqual(convertedW3cCredentialJson.credentialSubject.id) const credentialReceived = credential.process({ credentialDefinition, @@ -691,7 +691,7 @@ describe('API W3C', () => { tailsPath }) - const presentation = W3CPresentation.create({ + const presentation = W3cPresentation.create({ presentationRequest, credentials: [ { @@ -773,7 +773,7 @@ describe('API W3C', () => { tag: 'TAG' }) - const credentialOffer = W3CCredentialOffer.create({ + const credentialOffer = W3cCredentialOffer.create({ schemaId: 'mock:uri', credentialDefinitionId: 'mock:uri', keyCorrectnessProof @@ -782,7 +782,7 @@ describe('API W3C', () => { const linkSecret = LinkSecret.create() const linkSecretId = 'link secret id' - const { credentialRequestMetadata, credentialRequest } = W3CCredentialRequest.create({ + const { credentialRequestMetadata, credentialRequest } = W3cCredentialRequest.create({ entropy: 'entropy', credentialDefinition, linkSecret, @@ -790,7 +790,7 @@ describe('API W3C', () => { credentialOffer }) - const credential = W3CCredential.create({ + const credential = W3cCredential.create({ credentialDefinition, credentialDefinitionPrivate, credentialOffer, @@ -824,7 +824,7 @@ describe('API W3C', () => { } }) - const presentation = W3CPresentation.create({ + const presentation = W3cPresentation.create({ presentationRequest, credentials: [ { diff --git a/wrappers/javascript/packages/anoncreds-nodejs/tests/bindings.test.ts b/wrappers/javascript/packages/anoncreds-nodejs/tests/bindings.test.ts index 741a448a..8a1eb72f 100644 --- a/wrappers/javascript/packages/anoncreds-nodejs/tests/bindings.test.ts +++ b/wrappers/javascript/packages/anoncreds-nodejs/tests/bindings.test.ts @@ -374,7 +374,7 @@ describe('bindings', () => { timestamp: timeCreateRevStatusList }) - const credentialOffer = anoncreds.createW3CCredentialOffer({ + const credentialOffer = anoncreds.createW3cCredentialOffer({ schemaId: 'mock:uri', credentialDefinitionId: 'mock:uri', keyCorrectnessProof @@ -383,7 +383,7 @@ describe('bindings', () => { const linkSecret = anoncreds.createLinkSecret() const linkSecretId = 'link secret id' - const { credentialRequestMetadata, credentialRequest } = anoncreds.createW3CCredentialRequest({ + const { credentialRequestMetadata, credentialRequest } = anoncreds.createW3cCredentialRequest({ entropy: ENTROPY, credentialDefinition, linkSecret, @@ -391,7 +391,7 @@ describe('bindings', () => { credentialOffer }) - const credential = anoncreds.createW3CCredential({ + const credential = anoncreds.createW3cCredential({ credentialDefinition, credentialDefinitionPrivate, credentialOffer, @@ -406,7 +406,7 @@ describe('bindings', () => { encoding: undefined }) - const credReceived = anoncreds.processW3CCredential({ + const credReceived = anoncreds.processW3cCredential({ credential, credentialDefinition, credentialRequestMetadata, @@ -672,7 +672,7 @@ describe('bindings', () => { timestamp: timeCreateRevStatusList }) - const credentialOffer = anoncreds.createW3CCredentialOffer({ + const credentialOffer = anoncreds.createW3cCredentialOffer({ schemaId: 'mock:uri', credentialDefinitionId: 'mock:uri', keyCorrectnessProof @@ -681,7 +681,7 @@ describe('bindings', () => { const linkSecret = anoncreds.createLinkSecret() const linkSecretId = 'link secret id' - const { credentialRequestMetadata, credentialRequest } = anoncreds.createW3CCredentialRequest({ + const { credentialRequestMetadata, credentialRequest } = anoncreds.createW3cCredentialRequest({ entropy: ENTROPY, credentialDefinition, linkSecret, @@ -689,7 +689,7 @@ describe('bindings', () => { credentialOffer }) - const credential = anoncreds.createW3CCredential({ + const credential = anoncreds.createW3cCredential({ credentialDefinition, credentialDefinitionPrivate, credentialOffer, @@ -704,7 +704,7 @@ describe('bindings', () => { encoding: undefined }) - const credentialReceived = anoncreds.processW3CCredential({ + const credentialReceived = anoncreds.processW3cCredential({ credential, credentialDefinition, credentialRequestMetadata, @@ -726,7 +726,7 @@ describe('bindings', () => { tailsPath }) - const presentation = anoncreds.createW3CPresentation({ + const presentation = anoncreds.createW3cPresentation({ presentationRequest, credentials: [ { @@ -762,7 +762,7 @@ describe('bindings', () => { expect(presentation.handle).toStrictEqual(expect.any(Number)) - const verify = anoncreds.verifyW3CPresentation({ + const verify = anoncreds.verifyW3cPresentation({ presentation, presentationRequest, schemas: [schemaObj], @@ -944,7 +944,7 @@ describe('bindings', () => { tag: 'TAG' }) - const credentialOffer = anoncreds.createW3CCredentialOffer({ + const credentialOffer = anoncreds.createW3cCredentialOffer({ schemaId: 'mock:uri', credentialDefinitionId: 'mock:uri', keyCorrectnessProof @@ -953,7 +953,7 @@ describe('bindings', () => { const linkSecret = anoncreds.createLinkSecret() const linkSecretId = 'link secret id' - const { credentialRequestMetadata, credentialRequest } = anoncreds.createW3CCredentialRequest({ + const { credentialRequestMetadata, credentialRequest } = anoncreds.createW3cCredentialRequest({ entropy: ENTROPY, credentialDefinition, linkSecret, @@ -961,7 +961,7 @@ describe('bindings', () => { credentialOffer }) - const credential = anoncreds.createW3CCredential({ + const credential = anoncreds.createW3cCredential({ credentialDefinition, credentialDefinitionPrivate, credentialOffer, @@ -969,7 +969,7 @@ describe('bindings', () => { attributeRawValues: { name: 'Alex', height: '175', age: '28', sex: 'male' } }) - const credReceived = anoncreds.processW3CCredential({ + const credReceived = anoncreds.processW3cCredential({ credential, credentialDefinition, credentialRequestMetadata, @@ -998,7 +998,7 @@ describe('bindings', () => { }) }) - const presentation = anoncreds.createW3CPresentation({ + const presentation = anoncreds.createW3cPresentation({ presentationRequest, credentials: [ { @@ -1032,7 +1032,7 @@ describe('bindings', () => { expect(presentation.handle).toStrictEqual(expect.any(Number)) - const verify = anoncreds.verifyW3CPresentation({ + const verify = anoncreds.verifyW3cPresentation({ presentation, presentationRequest, schemas: [schemaObj], diff --git a/wrappers/javascript/packages/anoncreds-react-native/cpp/HostObject.cpp b/wrappers/javascript/packages/anoncreds-react-native/cpp/HostObject.cpp index b12ac831..f073ffd1 100644 --- a/wrappers/javascript/packages/anoncreds-react-native/cpp/HostObject.cpp +++ b/wrappers/javascript/packages/anoncreds-react-native/cpp/HostObject.cpp @@ -16,17 +16,17 @@ FunctionMap AnoncredsTurboModuleHostObject::functionMapping(jsi::Runtime &rt) { fMap.insert( std::make_tuple("createCredential", &anoncreds::createCredential)); fMap.insert( - std::make_tuple("createW3CCredential", &anoncreds::createW3CCredential)); + std::make_tuple("createW3cCredential", &anoncreds::createW3cCredential)); fMap.insert(std::make_tuple("createCredentialDefinition", &anoncreds::createCredentialDefinition)); fMap.insert(std::make_tuple("createCredentialOffer", &anoncreds::createCredentialOffer)); - fMap.insert(std::make_tuple("createW3CCredentialOffer", - &anoncreds::createW3CCredentialOffer)); + fMap.insert(std::make_tuple("createW3cCredentialOffer", + &anoncreds::createW3cCredentialOffer)); fMap.insert(std::make_tuple("createCredentialRequest", &anoncreds::createCredentialRequest)); - fMap.insert(std::make_tuple("createW3CCredentialRequest", - &anoncreds::createW3CCredentialRequest)); + fMap.insert(std::make_tuple("createW3cCredentialRequest", + &anoncreds::createW3cCredentialRequest)); fMap.insert( std::make_tuple("createLinkSecret", &anoncreds::createLinkSecret)); fMap.insert(std::make_tuple("createOrUpdateRevocationState", @@ -34,7 +34,7 @@ FunctionMap AnoncredsTurboModuleHostObject::functionMapping(jsi::Runtime &rt) { fMap.insert( std::make_tuple("createPresentation", &anoncreds::createPresentation)); fMap.insert( - std::make_tuple("createW3CPresentation", &anoncreds::createW3CPresentation)); + std::make_tuple("createW3cPresentation", &anoncreds::createW3cPresentation)); fMap.insert(std::make_tuple("createRevocationRegistryDefinition", &anoncreds::createRevocationRegistryDefinition)); fMap.insert(std::make_tuple("createSchema", &anoncreds::createSchema)); @@ -50,7 +50,7 @@ FunctionMap AnoncredsTurboModuleHostObject::functionMapping(jsi::Runtime &rt) { fMap.insert( std::make_tuple("processCredential", &anoncreds::processCredential)); fMap.insert( - std::make_tuple("processW3CCredential", &anoncreds::processW3CCredential)); + std::make_tuple("processW3cCredential", &anoncreds::processW3cCredential)); fMap.insert( std::make_tuple("revocationRegistryDefinitionGetAttribute", &anoncreds::revocationRegistryDefinitionGetAttribute)); @@ -59,7 +59,7 @@ FunctionMap AnoncredsTurboModuleHostObject::functionMapping(jsi::Runtime &rt) { fMap.insert( std::make_tuple("verifyPresentation", &anoncreds::verifyPresentation)); fMap.insert( - std::make_tuple("verifyW3CPresentation", &anoncreds::verifyW3CPresentation)); + std::make_tuple("verifyW3cPresentation", &anoncreds::verifyW3cPresentation)); fMap.insert(std::make_tuple("createRevocationStatusList", &anoncreds::createRevocationStatusList)); fMap.insert(std::make_tuple("updateRevocationStatusList", @@ -125,11 +125,11 @@ fMap.insert(std::make_tuple("createRevocationStatusList", std::make_tuple("w3cCredentialAddType", &anoncreds::w3cCredentialAddType)); fMap.insert( - std::make_tuple("credentialToW3C", - &anoncreds::credentialToW3C)); + std::make_tuple("credentialToW3c", + &anoncreds::credentialToW3c)); fMap.insert( - std::make_tuple("credentialFromW3C", - &anoncreds::credentialFromW3C)); + std::make_tuple("credentialFromW3c", + &anoncreds::credentialFromW3c)); return fMap; } diff --git a/wrappers/javascript/packages/anoncreds-react-native/cpp/anoncreds.cpp b/wrappers/javascript/packages/anoncreds-react-native/cpp/anoncreds.cpp index 046b1462..ac836e7c 100644 --- a/wrappers/javascript/packages/anoncreds-react-native/cpp/anoncreds.cpp +++ b/wrappers/javascript/packages/anoncreds-react-native/cpp/anoncreds.cpp @@ -742,7 +742,7 @@ jsi::Value w3cCredentialFromJson(jsi::Runtime &rt, jsi::Object options) { return returnValue; }; -jsi::Value createW3CPresentation(jsi::Runtime &rt, jsi::Object options) { +jsi::Value createW3cPresentation(jsi::Runtime &rt, jsi::Object options) { auto presentationRequest = jsiToValue(rt, options, "presentationRequest"); auto credentials = @@ -782,7 +782,7 @@ jsi::Value createW3CPresentation(jsi::Runtime &rt, jsi::Object options) { return returnValue; }; -jsi::Value verifyW3CPresentation(jsi::Runtime &rt, jsi::Object options) { +jsi::Value verifyW3cPresentation(jsi::Runtime &rt, jsi::Object options) { auto presentation = jsiToValue(rt, options, "presentation"); auto presentationRequest = jsiToValue(rt, options, "presentationRequest"); @@ -825,7 +825,7 @@ jsi::Value verifyW3CPresentation(jsi::Runtime &rt, jsi::Object options) { return returnValue; }; -jsi::Value createW3CCredential(jsi::Runtime &rt, jsi::Object options) { +jsi::Value createW3cCredential(jsi::Runtime &rt, jsi::Object options) { auto credentialDefinition = jsiToValue(rt, options, "credentialDefinition"); auto credentialDefinitionPrivate = @@ -853,7 +853,7 @@ jsi::Value createW3CCredential(jsi::Runtime &rt, jsi::Object options) { return createReturnValue(rt, code, &out); }; -jsi::Value createW3CCredentialOffer(jsi::Runtime &rt, jsi::Object options) { +jsi::Value createW3cCredentialOffer(jsi::Runtime &rt, jsi::Object options) { auto schemaId = jsiToValue(rt, options, "schemaId"); auto credentialDefinitionId = jsiToValue(rt, options, "credentialDefinitionId"); @@ -869,7 +869,7 @@ jsi::Value createW3CCredentialOffer(jsi::Runtime &rt, jsi::Object options) { return createReturnValue(rt, code, &out); }; -jsi::Value createW3CCredentialRequest(jsi::Runtime &rt, jsi::Object options) { +jsi::Value createW3cCredentialRequest(jsi::Runtime &rt, jsi::Object options) { auto entropy = jsiToValue(rt, options, "entropy", true); auto proverDid = jsiToValue(rt, options, "proverDid", true); auto credentialDefinition = @@ -902,7 +902,7 @@ jsi::Value w3cCredentialGetAttribute(jsi::Runtime &rt, jsi::Object options) { return createReturnValue(rt, code, &out); }; -jsi::Value processW3CCredential(jsi::Runtime &rt, jsi::Object options) { +jsi::Value processW3cCredential(jsi::Runtime &rt, jsi::Object options) { auto credential = jsiToValue(rt, options, "credential"); auto credentialRequestMetadata = jsiToValue(rt, options, "credentialRequestMetadata"); @@ -971,17 +971,17 @@ jsi::Value w3cCredentialAddContext(jsi::Runtime &rt, jsi::Object options) { jsi::Value w3cCredentialAddType(jsi::Runtime &rt, jsi::Object options) { auto credential = jsiToValue(rt, options, "objectHandle"); - auto type_ = jsiToValue(rt, options, "type_"); + auto type = jsiToValue(rt, options, "type"); ObjectHandle out; ErrorCode code = anoncreds_w3c_credential_add_type( - credential, type_.c_str(), &out); + credential, type.c_str(), &out); return createReturnValue(rt, code, &out); }; -jsi::Value credentialToW3C(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"); @@ -994,7 +994,7 @@ jsi::Value credentialToW3C(jsi::Runtime &rt, jsi::Object options) { return createReturnValue(rt, code, &out); }; -jsi::Value credentialFromW3C(jsi::Runtime &rt, jsi::Object options) { +jsi::Value credentialFromW3c(jsi::Runtime &rt, jsi::Object options) { auto credential = jsiToValue(rt, options, "objectHandle"); ObjectHandle out; diff --git a/wrappers/javascript/packages/anoncreds-react-native/cpp/anoncreds.h b/wrappers/javascript/packages/anoncreds-react-native/cpp/anoncreds.h index 7e91203e..919dce35 100644 --- a/wrappers/javascript/packages/anoncreds-react-native/cpp/anoncreds.h +++ b/wrappers/javascript/packages/anoncreds-react-native/cpp/anoncreds.h @@ -20,7 +20,7 @@ struct CredentialRequestReturn { ObjectHandle credentialRequestMetadata; }; -struct W3CCredentialRequestReturn { +struct W3cCredentialRequestReturn { ObjectHandle credentialRequest; ObjectHandle credentialRequestMetadata; }; @@ -74,8 +74,8 @@ jsi::Value w3cPresentationFromJson(jsi::Runtime &rt, jsi::Object options); // Proofs jsi::Value createPresentation(jsi::Runtime &rt, jsi::Object options); jsi::Value verifyPresentation(jsi::Runtime &rt, jsi::Object options); -jsi::Value createW3CPresentation(jsi::Runtime &rt, jsi::Object options); -jsi::Value verifyW3CPresentation(jsi::Runtime &rt, jsi::Object options); +jsi::Value createW3cPresentation(jsi::Runtime &rt, jsi::Object options); +jsi::Value verifyW3cPresentation(jsi::Runtime &rt, jsi::Object options); // Credentials jsi::Value createCredential(jsi::Runtime &rt, jsi::Object options); @@ -85,18 +85,18 @@ jsi::Value credentialGetAttribute(jsi::Runtime &rt, jsi::Object options); jsi::Value encodeCredentialAttributes(jsi::Runtime &rt, jsi::Object options); jsi::Value processCredential(jsi::Runtime &rt, jsi::Object options); -jsi::Value createW3CCredential(jsi::Runtime &rt, jsi::Object options); -jsi::Value createW3CCredentialOffer(jsi::Runtime &rt, jsi::Object options); -jsi::Value createW3CCredentialRequest(jsi::Runtime &rt, jsi::Object options); +jsi::Value createW3cCredential(jsi::Runtime &rt, jsi::Object options); +jsi::Value createW3cCredentialOffer(jsi::Runtime &rt, jsi::Object options); +jsi::Value createW3cCredentialRequest(jsi::Runtime &rt, jsi::Object options); jsi::Value w3cCredentialGetAttribute(jsi::Runtime &rt, jsi::Object options); -jsi::Value processW3CCredential(jsi::Runtime &rt, jsi::Object options); +jsi::Value processW3cCredential(jsi::Runtime &rt, jsi::Object options); jsi::Value w3cCredentialAddNonAnonCredsIntegrityProof(jsi::Runtime &rt, jsi::Object options); jsi::Value w3cCredentialSetId(jsi::Runtime &rt, jsi::Object options); jsi::Value w3cCredentialSetSubjectId(jsi::Runtime &rt, jsi::Object options); jsi::Value w3cCredentialAddContext(jsi::Runtime &rt, jsi::Object options); jsi::Value w3cCredentialAddType(jsi::Runtime &rt, jsi::Object options); -jsi::Value credentialToW3C(jsi::Runtime &rt, jsi::Object options); -jsi::Value credentialFromW3C(jsi::Runtime &rt, jsi::Object options); +jsi::Value credentialToW3c(jsi::Runtime &rt, jsi::Object options); +jsi::Value credentialFromW3c(jsi::Runtime &rt, jsi::Object options); // Revocation jsi::Value createOrUpdateRevocationState(jsi::Runtime &rt, jsi::Object options); diff --git a/wrappers/javascript/packages/anoncreds-react-native/src/NativeBindings.ts b/wrappers/javascript/packages/anoncreds-react-native/src/NativeBindings.ts index 60344f5c..e2663168 100644 --- a/wrappers/javascript/packages/anoncreds-react-native/src/NativeBindings.ts +++ b/wrappers/javascript/packages/anoncreds-react-native/src/NativeBindings.ts @@ -186,13 +186,13 @@ export type NativeBindings = { keyCorrectnessProofFromJson(options: { json: string }): ReturnObject - createW3CCredentialOffer(options: { + createW3cCredentialOffer(options: { schemaId: string credentialDefinitionId: string keyCorrectnessProof: number }): ReturnObject - createW3CCredentialRequest(options: { + createW3cCredentialRequest(options: { entropy?: string proverDid?: string credentialDefinition: number @@ -201,7 +201,7 @@ export type NativeBindings = { credentialOffer: number }): ReturnObject<{ credentialRequest: Handle; credentialRequestMetadata: Handle }> - createW3CCredential(options: { + createW3cCredential(options: { credentialDefinition: number credentialDefinitionPrivate: number credentialOffer: number @@ -217,7 +217,7 @@ export type NativeBindings = { encoding?: string }): ReturnObject - processW3CCredential(options: { + processW3cCredential(options: { credential: number credentialRequestMetadata: number linkSecret: string @@ -235,13 +235,13 @@ export type NativeBindings = { w3cCredentialAddContext(options: { objectHandle: number; context: string }): ReturnObject - w3cCredentialAddType(options: { objectHandle: number; type_: string }): ReturnObject + w3cCredentialAddType(options: { objectHandle: number; type: string }): ReturnObject - credentialToW3C(options: { objectHandle: number; credentialDefinition: number }): ReturnObject + credentialToW3c(options: { objectHandle: number; credentialDefinition: number }): ReturnObject - credentialFromW3C(options: { objectHandle: number }): ReturnObject + credentialFromW3c(options: { objectHandle: number }): ReturnObject - createW3CPresentation(options: { + createW3cPresentation(options: { presentationRequest: number credentials: { credential: number; timestamp?: number; revocationState?: number }[] credentialsProve: NativeCredentialProve[] @@ -252,7 +252,7 @@ export type NativeBindings = { credentialDefinitions: number[] }): ReturnObject - verifyW3CPresentation(options: { + verifyW3cPresentation(options: { presentation: number presentationRequest: number schemas: number[] diff --git a/wrappers/javascript/packages/anoncreds-react-native/src/ReactNativeAnoncreds.ts b/wrappers/javascript/packages/anoncreds-react-native/src/ReactNativeAnoncreds.ts index 8d55cf44..0c3855f6 100644 --- a/wrappers/javascript/packages/anoncreds-react-native/src/ReactNativeAnoncreds.ts +++ b/wrappers/javascript/packages/anoncreds-react-native/src/ReactNativeAnoncreds.ts @@ -393,7 +393,7 @@ export class ReactNativeAnoncreds implements Anoncreds { return new ObjectHandle(handle) } - public createW3CCredential(options: { + public createW3cCredential(options: { credentialDefinition: ObjectHandle credentialDefinitionPrivate: ObjectHandle credentialOffer: ObjectHandle @@ -408,7 +408,7 @@ export class ReactNativeAnoncreds implements Anoncreds { const credential = this.handleError( // eslint-disable-next-line @typescript-eslint/ban-ts-comment, @typescript-eslint/prefer-ts-expect-error // @ts-ignore - this.anoncreds.createW3CCredential({ + this.anoncreds.createW3cCredential({ // eslint-disable-next-line @typescript-eslint/ban-ts-comment, @typescript-eslint/prefer-ts-expect-error // @ts-ignore ...serializeArguments(options), @@ -430,27 +430,27 @@ export class ReactNativeAnoncreds implements Anoncreds { return new ObjectHandle(credential) } - public processW3CCredential(options: { + public processW3cCredential(options: { credential: ObjectHandle credentialRequestMetadata: ObjectHandle linkSecret: string credentialDefinition: ObjectHandle revocationRegistryDefinition?: ObjectHandle }): ObjectHandle { - const handle = this.handleError(this.anoncreds.processW3CCredential(serializeArguments(options))) + const handle = this.handleError(this.anoncreds.processW3cCredential(serializeArguments(options))) return new ObjectHandle(handle) } - public createW3CCredentialOffer(options: { + public createW3cCredentialOffer(options: { schemaId: string credentialDefinitionId: string keyCorrectnessProof: ObjectHandle }): ObjectHandle { - const handle = this.handleError(this.anoncreds.createW3CCredentialOffer(serializeArguments(options))) + const handle = this.handleError(this.anoncreds.createW3cCredentialOffer(serializeArguments(options))) return new ObjectHandle(handle) } - public createW3CCredentialRequest(options: { + public createW3cCredentialRequest(options: { entropy?: string proverDid?: string credentialDefinition: ObjectHandle @@ -459,7 +459,7 @@ export class ReactNativeAnoncreds implements Anoncreds { credentialOffer: ObjectHandle }): { credentialRequest: ObjectHandle; credentialRequestMetadata: ObjectHandle } { const { credentialRequest, credentialRequestMetadata } = this.handleError( - this.anoncreds.createW3CCredentialRequest(serializeArguments(options)) + this.anoncreds.createW3cCredentialRequest(serializeArguments(options)) ) return { @@ -468,7 +468,7 @@ export class ReactNativeAnoncreds implements Anoncreds { } } - public createW3CPresentation(options: { + public createW3cPresentation(options: { presentationRequest: ObjectHandle credentials: NativeCredentialEntry[] credentialsProve: NativeCredentialProve[] @@ -488,7 +488,7 @@ export class ReactNativeAnoncreds implements Anoncreds { })) const handle = this.handleError( - this.anoncreds.createW3CPresentation({ + this.anoncreds.createW3cPresentation({ presentationRequest: options.presentationRequest.handle, linkSecret: options.linkSecret, credentialsProve: options.credentialsProve, @@ -502,7 +502,7 @@ export class ReactNativeAnoncreds implements Anoncreds { return new ObjectHandle(handle) } - public verifyW3CPresentation(options: { + public verifyW3cPresentation(options: { presentation: ObjectHandle presentationRequest: ObjectHandle schemas: ObjectHandle[] @@ -514,7 +514,7 @@ export class ReactNativeAnoncreds implements Anoncreds { revocationStatusLists?: ObjectHandle[] nonRevokedIntervalOverrides?: NativeNonRevokedIntervalOverride[] }): boolean { - return Boolean(this.handleError(this.anoncreds.verifyW3CPresentation(serializeArguments(options)))) + return Boolean(this.handleError(this.anoncreds.verifyW3cPresentation(serializeArguments(options)))) } public w3cCredentialGetAttribute(options: { objectHandle: ObjectHandle; name: string }): string { @@ -566,18 +566,18 @@ export class ReactNativeAnoncreds implements Anoncreds { return new ObjectHandle(handle) } - public w3cCredentialAddType(options: { objectHandle: ObjectHandle; type_: string }): ObjectHandle { + public w3cCredentialAddType(options: { objectHandle: ObjectHandle; type: string }): ObjectHandle { const handle = this.handleError(this.anoncreds.w3cCredentialAddType(serializeArguments(options))) return new ObjectHandle(handle) } - public credentialToW3C(options: { objectHandle: ObjectHandle; credentialDefinition: ObjectHandle }): ObjectHandle { - const handle = this.handleError(this.anoncreds.credentialToW3C(serializeArguments(options))) + public credentialToW3c(options: { objectHandle: ObjectHandle; credentialDefinition: ObjectHandle }): ObjectHandle { + const handle = this.handleError(this.anoncreds.credentialToW3c(serializeArguments(options))) return new ObjectHandle(handle) } - public credentialFromW3C(options: { objectHandle: ObjectHandle }): ObjectHandle { - const handle = this.handleError(this.anoncreds.credentialFromW3C(serializeArguments(options))) + public credentialFromW3c(options: { objectHandle: ObjectHandle }): ObjectHandle { + const handle = this.handleError(this.anoncreds.credentialFromW3c(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 a8debf1b..6b922e43 100644 --- a/wrappers/javascript/packages/anoncreds-shared/src/Anoncreds.ts +++ b/wrappers/javascript/packages/anoncreds-shared/src/Anoncreds.ts @@ -205,13 +205,13 @@ export type Anoncreds = { objectFree(options: { objectHandle: ObjectHandle }): void - createW3CCredentialOffer(options: { + createW3cCredentialOffer(options: { schemaId: string credentialDefinitionId: string keyCorrectnessProof: ObjectHandle }): ObjectHandle - createW3CCredentialRequest(options: { + createW3cCredentialRequest(options: { entropy?: string proverDid?: string credentialDefinition: ObjectHandle @@ -220,7 +220,7 @@ export type Anoncreds = { credentialOffer: ObjectHandle }): { credentialRequest: ObjectHandle; credentialRequestMetadata: ObjectHandle } - createW3CCredential(options: { + createW3cCredential(options: { credentialDefinition: ObjectHandle credentialDefinitionPrivate: ObjectHandle credentialOffer: ObjectHandle @@ -230,7 +230,7 @@ export type Anoncreds = { encoding?: string }): ObjectHandle - processW3CCredential(options: { + processW3cCredential(options: { credential: ObjectHandle credentialRequestMetadata: ObjectHandle linkSecret: string @@ -238,7 +238,7 @@ export type Anoncreds = { revocationRegistryDefinition?: ObjectHandle }): ObjectHandle - createW3CPresentation(options: { + createW3cPresentation(options: { presentationRequest: ObjectHandle credentials: NativeCredentialEntry[] credentialsProve: NativeCredentialProve[] @@ -247,7 +247,7 @@ export type Anoncreds = { credentialDefinitions: Record }): ObjectHandle - verifyW3CPresentation(options: { + verifyW3cPresentation(options: { presentation: ObjectHandle presentationRequest: ObjectHandle schemas: ObjectHandle[] @@ -270,7 +270,7 @@ export type Anoncreds = { w3cCredentialAddContext(options: { objectHandle: ObjectHandle; context: string }): ObjectHandle - w3cCredentialAddType(options: { objectHandle: ObjectHandle; type_: string }): ObjectHandle + w3cCredentialAddType(options: { objectHandle: ObjectHandle; type: string }): ObjectHandle w3cCredentialGetAttribute(options: { objectHandle: ObjectHandle; name: string }): string @@ -280,7 +280,7 @@ export type Anoncreds = { w3cCredentialFromJson(options: { json: string }): ObjectHandle - credentialToW3C(options: { objectHandle: ObjectHandle; credentialDefinition: ObjectHandle }): ObjectHandle + credentialToW3c(options: { objectHandle: ObjectHandle; credentialDefinition: ObjectHandle }): ObjectHandle - credentialFromW3C(options: { objectHandle: ObjectHandle }): 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 19b6a4d5..5081a1b9 100644 --- a/wrappers/javascript/packages/anoncreds-shared/src/api/Credential.ts +++ b/wrappers/javascript/packages/anoncreds-shared/src/api/Credential.ts @@ -12,7 +12,7 @@ import { CredentialOffer } from './CredentialOffer' import { CredentialRequest } from './CredentialRequest' import { CredentialRequestMetadata } from './CredentialRequestMetadata' import { RevocationRegistryDefinition } from './RevocationRegistryDefinition' -import { W3CCredential } from './W3CCredential' +import { W3cCredential } from './W3cCredential' import { pushToArray } from './utils' export type CreateCredentialOptions = { @@ -34,12 +34,12 @@ export type ProcessCredentialOptions = { revocationRegistryDefinition?: RevocationRegistryDefinition | JsonObject } -export type CredentialToW3COptions = { +export type CredentialToW3cOptions = { credentialDefinition: CredentialDefinition | JsonObject } -export type CredentialFromW3COptions = { - credential: W3CCredential +export type CredentialFromW3cOptions = { + credential: W3cCredential } export class Credential extends AnoncredsObject { @@ -149,7 +149,7 @@ export class Credential extends AnoncredsObject { return index ? Number(index) : undefined } - public toW3C(options: CredentialToW3COptions): W3CCredential { + public toW3c(options: CredentialToW3cOptions): W3cCredential { let credential // Objects created within this method must be freed up const objectHandles: ObjectHandle[] = [] @@ -159,8 +159,8 @@ export class Credential extends AnoncredsObject { ? options.credentialDefinition.handle : pushToArray(CredentialDefinition.fromJson(options.credentialDefinition).handle, objectHandles) - credential = new W3CCredential( - anoncreds.credentialToW3C({ + credential = new W3cCredential( + anoncreds.credentialToW3c({ objectHandle: this.handle, credentialDefinition }).handle @@ -173,7 +173,7 @@ export class Credential extends AnoncredsObject { return credential } - public static fromW3C(options: CredentialFromW3COptions) { - return new Credential(anoncreds.credentialFromW3C({ objectHandle: options.credential.handle }).handle) + public static fromW3c(options: CredentialFromW3cOptions) { + return new Credential(anoncreds.credentialFromW3c({ objectHandle: options.credential.handle }).handle) } } diff --git a/wrappers/javascript/packages/anoncreds-shared/src/api/W3CCredential.ts b/wrappers/javascript/packages/anoncreds-shared/src/api/W3cCredential.ts similarity index 84% rename from wrappers/javascript/packages/anoncreds-shared/src/api/W3CCredential.ts rename to wrappers/javascript/packages/anoncreds-shared/src/api/W3cCredential.ts index 7ae213fc..e922432d 100644 --- a/wrappers/javascript/packages/anoncreds-shared/src/api/W3CCredential.ts +++ b/wrappers/javascript/packages/anoncreds-shared/src/api/W3cCredential.ts @@ -11,15 +11,15 @@ import { CredentialDefinition } from './CredentialDefinition' import { CredentialDefinitionPrivate } from './CredentialDefinitionPrivate' import { CredentialRequestMetadata } from './CredentialRequestMetadata' import { RevocationRegistryDefinition } from './RevocationRegistryDefinition' -import { W3CCredentialOffer } from './W3CCredentialOffer' -import { W3CCredentialRequest } from './W3CCredentialRequest' +import { W3cCredentialOffer } from './W3cCredentialOffer' +import { W3cCredentialRequest } from './W3cCredentialRequest' import { pushToArray } from './utils' -export type CreateW3CCredentialOptions = { +export type CreateW3cCredentialOptions = { credentialDefinition: CredentialDefinition | JsonObject credentialDefinitionPrivate: CredentialDefinitionPrivate | JsonObject - credentialOffer: W3CCredentialOffer | JsonObject - credentialRequest: W3CCredentialRequest | JsonObject + credentialOffer: W3cCredentialOffer | JsonObject + credentialRequest: W3cCredentialRequest | JsonObject attributeRawValues: Record revocationRegistryId?: string revocationConfiguration?: CredentialRevocationConfig @@ -27,20 +27,20 @@ export type CreateW3CCredentialOptions = { encoding?: string } -export type ProcessW3CCredentialOptions = { +export type ProcessW3cCredentialOptions = { credentialRequestMetadata: CredentialRequestMetadata | JsonObject linkSecret: string credentialDefinition: CredentialDefinition | JsonObject revocationRegistryDefinition?: RevocationRegistryDefinition | JsonObject } -export type W3CCredentialFromLegacyOptions = { +export type W3cCredentialFromLegacyOptions = { credential: Credential credentialDefinition: CredentialDefinition | JsonObject } -export class W3CCredential extends AnoncredsObject { - public static create(options: CreateW3CCredentialOptions) { +export class W3cCredential extends AnoncredsObject { + public static create(options: CreateW3cCredentialOptions) { let credential // Objects created within this method must be freed up const objectHandles: ObjectHandle[] = [] @@ -56,16 +56,16 @@ export class W3CCredential extends AnoncredsObject { : pushToArray(CredentialDefinitionPrivate.fromJson(options.credentialDefinitionPrivate).handle, objectHandles) const credentialOffer = - options.credentialOffer instanceof W3CCredentialOffer + options.credentialOffer instanceof W3cCredentialOffer ? options.credentialOffer.handle - : pushToArray(W3CCredentialOffer.fromJson(options.credentialOffer).handle, objectHandles) + : pushToArray(W3cCredentialOffer.fromJson(options.credentialOffer).handle, objectHandles) const credentialRequest = - options.credentialRequest instanceof W3CCredentialRequest + options.credentialRequest instanceof W3cCredentialRequest ? options.credentialRequest.handle - : pushToArray(W3CCredentialRequest.fromJson(options.credentialRequest).handle, objectHandles) + : pushToArray(W3cCredentialRequest.fromJson(options.credentialRequest).handle, objectHandles) - credential = anoncreds.createW3CCredential({ + credential = anoncreds.createW3cCredential({ credentialDefinition, credentialDefinitionPrivate, credentialOffer, @@ -79,14 +79,14 @@ export class W3CCredential extends AnoncredsObject { handle.clear() }) } - return new W3CCredential(credential.handle) + return new W3cCredential(credential.handle) } public static fromJson(json: JsonObject) { - return new W3CCredential(anoncreds.w3cCredentialFromJson({ json: JSON.stringify(json) }).handle) + return new W3cCredential(anoncreds.w3cCredentialFromJson({ json: JSON.stringify(json) }).handle) } - public process(options: ProcessW3CCredentialOptions) { + public process(options: ProcessW3cCredentialOptions) { let credential // Objects created within this method must be freed up const objectHandles: ObjectHandle[] = [] @@ -111,7 +111,7 @@ export class W3CCredential extends AnoncredsObject { ) : undefined - credential = anoncreds.processW3CCredential({ + credential = anoncreds.processW3cCredential({ credential: this.handle, credentialDefinition, credentialRequestMetadata, @@ -149,13 +149,13 @@ export class W3CCredential extends AnoncredsObject { public toLegacy(): Credential { return new Credential( - anoncreds.credentialFromW3C({ + anoncreds.credentialFromW3c({ objectHandle: this.handle }).handle ) } - public static fromLegacy(options: W3CCredentialFromLegacyOptions): W3CCredential { + public static fromLegacy(options: W3cCredentialFromLegacyOptions): W3cCredential { let credential // Objects created within this method must be freed up const objectHandles: ObjectHandle[] = [] @@ -165,8 +165,8 @@ export class W3CCredential extends AnoncredsObject { ? options.credentialDefinition.handle : pushToArray(CredentialDefinition.fromJson(options.credentialDefinition).handle, objectHandles) - credential = new W3CCredential( - anoncreds.credentialToW3C({ + credential = new W3cCredential( + anoncreds.credentialToW3c({ objectHandle: options.credential.handle, credentialDefinition }).handle @@ -219,10 +219,10 @@ export class W3CCredential extends AnoncredsObject { this.handle = credential } - public addType(type_: string) { + public addType(type: string) { const credential = anoncreds.w3cCredentialAddType({ objectHandle: this.handle, - type_ + type }) this.handle.clear() diff --git a/wrappers/javascript/packages/anoncreds-shared/src/api/W3CCredentialOffer.ts b/wrappers/javascript/packages/anoncreds-shared/src/api/W3cCredentialOffer.ts similarity index 76% rename from wrappers/javascript/packages/anoncreds-shared/src/api/W3CCredentialOffer.ts rename to wrappers/javascript/packages/anoncreds-shared/src/api/W3cCredentialOffer.ts index 7009eec0..7db405fb 100644 --- a/wrappers/javascript/packages/anoncreds-shared/src/api/W3CCredentialOffer.ts +++ b/wrappers/javascript/packages/anoncreds-shared/src/api/W3cCredentialOffer.ts @@ -7,14 +7,14 @@ import { anoncreds } from '../register' import { KeyCorrectnessProof } from './KeyCorrectnessProof' import { pushToArray } from './utils' -export type CreateW3CCredentialOfferOptions = { +export type CreateW3cCredentialOfferOptions = { schemaId: string credentialDefinitionId: string keyCorrectnessProof: KeyCorrectnessProof | JsonObject } -export class W3CCredentialOffer extends AnoncredsObject { - public static create(options: CreateW3CCredentialOfferOptions) { +export class W3cCredentialOffer extends AnoncredsObject { + public static create(options: CreateW3cCredentialOfferOptions) { let credentialOfferHandle // Objects created within this method must be freed up const objectHandles: ObjectHandle[] = [] @@ -24,7 +24,7 @@ export class W3CCredentialOffer extends AnoncredsObject { ? options.keyCorrectnessProof.handle : pushToArray(KeyCorrectnessProof.fromJson(options.keyCorrectnessProof).handle, objectHandles) - credentialOfferHandle = anoncreds.createW3CCredentialOffer({ + credentialOfferHandle = anoncreds.createW3cCredentialOffer({ schemaId: options.schemaId, credentialDefinitionId: options.credentialDefinitionId, keyCorrectnessProof @@ -34,10 +34,10 @@ export class W3CCredentialOffer extends AnoncredsObject { handle.clear() }) } - return new W3CCredentialOffer(credentialOfferHandle) + return new W3cCredentialOffer(credentialOfferHandle) } public static fromJson(json: JsonObject) { - return new W3CCredentialOffer(anoncreds.w3cCredentialOfferFromJson({ json: JSON.stringify(json) }).handle) + return new W3cCredentialOffer(anoncreds.w3cCredentialOfferFromJson({ json: JSON.stringify(json) }).handle) } } diff --git a/wrappers/javascript/packages/anoncreds-shared/src/api/W3CCredentialRequest.ts b/wrappers/javascript/packages/anoncreds-shared/src/api/W3cCredentialRequest.ts similarity index 73% rename from wrappers/javascript/packages/anoncreds-shared/src/api/W3CCredentialRequest.ts rename to wrappers/javascript/packages/anoncreds-shared/src/api/W3cCredentialRequest.ts index e92f1c23..b2d6fb8b 100644 --- a/wrappers/javascript/packages/anoncreds-shared/src/api/W3CCredentialRequest.ts +++ b/wrappers/javascript/packages/anoncreds-shared/src/api/W3cCredentialRequest.ts @@ -6,20 +6,20 @@ import { anoncreds } from '../register' import { CredentialDefinition } from './CredentialDefinition' import { CredentialRequestMetadata } from './CredentialRequestMetadata' -import { W3CCredentialOffer } from './W3CCredentialOffer' +import { W3cCredentialOffer } from './W3cCredentialOffer' import { pushToArray } from './utils' -export type CreateW3CCredentialRequestOptions = { +export type CreateW3cCredentialRequestOptions = { entropy?: string proverDid?: string credentialDefinition: CredentialDefinition | JsonObject linkSecret: string linkSecretId: string - credentialOffer: W3CCredentialOffer | JsonObject + credentialOffer: W3cCredentialOffer | JsonObject } -export class W3CCredentialRequest extends AnoncredsObject { - public static create(options: CreateW3CCredentialRequestOptions) { +export class W3cCredentialRequest extends AnoncredsObject { + public static create(options: CreateW3cCredentialRequestOptions) { let createReturnObj: { credentialRequest: ObjectHandle credentialRequestMetadata: ObjectHandle @@ -33,11 +33,11 @@ export class W3CCredentialRequest extends AnoncredsObject { : pushToArray(CredentialDefinition.fromJson(options.credentialDefinition).handle, objectHandles) const credentialOffer = - options.credentialOffer instanceof W3CCredentialOffer + options.credentialOffer instanceof W3cCredentialOffer ? options.credentialOffer.handle - : pushToArray(W3CCredentialOffer.fromJson(options.credentialOffer).handle, objectHandles) + : pushToArray(W3cCredentialOffer.fromJson(options.credentialOffer).handle, objectHandles) - createReturnObj = anoncreds.createW3CCredentialRequest({ + createReturnObj = anoncreds.createW3cCredentialRequest({ entropy: options.entropy, proverDid: options.proverDid, credentialDefinition, @@ -51,12 +51,12 @@ export class W3CCredentialRequest extends AnoncredsObject { }) } return { - credentialRequest: new W3CCredentialRequest(createReturnObj.credentialRequest.handle), + credentialRequest: new W3cCredentialRequest(createReturnObj.credentialRequest.handle), credentialRequestMetadata: new CredentialRequestMetadata(createReturnObj.credentialRequestMetadata.handle) } } public static fromJson(json: JsonObject) { - return new W3CCredentialRequest(anoncreds.w3cCredentialRequestFromJson({ json: JSON.stringify(json) }).handle) + return new W3cCredentialRequest(anoncreds.w3cCredentialRequestFromJson({ json: JSON.stringify(json) }).handle) } } diff --git a/wrappers/javascript/packages/anoncreds-shared/src/api/W3CPresentation.ts b/wrappers/javascript/packages/anoncreds-shared/src/api/W3cPresentation.ts similarity index 88% rename from wrappers/javascript/packages/anoncreds-shared/src/api/W3CPresentation.ts rename to wrappers/javascript/packages/anoncreds-shared/src/api/W3cPresentation.ts index 1607906a..f233bc8f 100644 --- a/wrappers/javascript/packages/anoncreds-shared/src/api/W3CPresentation.ts +++ b/wrappers/javascript/packages/anoncreds-shared/src/api/W3cPresentation.ts @@ -11,27 +11,27 @@ import { PresentationRequest } from './PresentationRequest' import { RevocationRegistryDefinition } from './RevocationRegistryDefinition' import { RevocationStatusList } from './RevocationStatusList' import { Schema } from './Schema' -import { W3CCredential } from './W3CCredential' +import { W3cCredential } from './W3cCredential' import { pushToArray } from './utils' // TODO: Simplify Presentation API (see PresentCredentials object in python wrapper)) -export type W3CCredentialEntry = { - credential: W3CCredential | JsonObject +export type W3cCredentialEntry = { + credential: W3cCredential | JsonObject timestamp?: number revocationState?: CredentialRevocationState | JsonObject } -export type CreateW3CPresentationOptions = { +export type CreateW3cPresentationOptions = { presentationRequest: PresentationRequest | JsonObject - credentials: W3CCredentialEntry[] + credentials: W3cCredentialEntry[] credentialsProve: CredentialProve[] linkSecret: string schemas: Record credentialDefinitions: Record } -export type VerifyW3CPresentationOptions = { +export type VerifyW3cPresentationOptions = { presentationRequest: PresentationRequest | JsonObject schemas: Record credentialDefinitions: Record @@ -40,8 +40,8 @@ export type VerifyW3CPresentationOptions = { nonRevokedIntervalOverrides?: NonRevokedIntervalOverride[] } -export class W3CPresentation extends AnoncredsObject { - public static create(options: CreateW3CPresentationOptions) { +export class W3cPresentation extends AnoncredsObject { + public static create(options: CreateW3cPresentationOptions) { let presentationHandle // Objects created within this method must be freed up const objectHandles: ObjectHandle[] = [] @@ -51,13 +51,13 @@ export class W3CPresentation extends AnoncredsObject { ? options.presentationRequest.handle : pushToArray(PresentationRequest.fromJson(options.presentationRequest).handle, objectHandles) - presentationHandle = anoncreds.createW3CPresentation({ + presentationHandle = anoncreds.createW3cPresentation({ presentationRequest, credentials: options.credentials.map((item) => ({ credential: - item.credential instanceof W3CCredential + item.credential instanceof W3cCredential ? item.credential.handle - : pushToArray(W3CCredential.fromJson(item.credential).handle, objectHandles), + : pushToArray(W3cCredential.fromJson(item.credential).handle, objectHandles), revocationState: item.revocationState instanceof CredentialRevocationState ? item.revocationState.handle @@ -94,14 +94,14 @@ export class W3CPresentation extends AnoncredsObject { handle.clear() }) } - return new W3CPresentation(presentationHandle) + return new W3cPresentation(presentationHandle) } public static fromJson(json: JsonObject) { - return new W3CPresentation(anoncreds.w3cPresentationFromJson({ json: JSON.stringify(json) }).handle) + return new W3cPresentation(anoncreds.w3cPresentationFromJson({ json: JSON.stringify(json) }).handle) } - public verify(options: VerifyW3CPresentationOptions) { + public verify(options: VerifyW3cPresentationOptions) { const schemas = Object.values(options.schemas) const schemaIds = Object.keys(options.schemas) @@ -124,7 +124,7 @@ export class W3CPresentation extends AnoncredsObject { ? options.presentationRequest.handle : pushToArray(PresentationRequest.fromJson(options.presentationRequest).handle, objectHandles) - verified = anoncreds.verifyW3CPresentation({ + verified = anoncreds.verifyW3cPresentation({ presentation: this.handle, presentationRequest, schemas: schemas.map((o) => diff --git a/wrappers/javascript/packages/anoncreds-shared/src/api/index.ts b/wrappers/javascript/packages/anoncreds-shared/src/api/index.ts index b6aa73ed..6ac21014 100644 --- a/wrappers/javascript/packages/anoncreds-shared/src/api/index.ts +++ b/wrappers/javascript/packages/anoncreds-shared/src/api/index.ts @@ -15,7 +15,7 @@ export * from './RevocationRegistry' export * from './RevocationRegistryDefinition' export * from './RevocationRegistryDefinitionPrivate' export * from './RevocationStatusList' -export * from './W3CCredential' -export * from './W3CCredentialOffer' -export * from './W3CCredentialRequest' -export * from './W3CPresentation' +export * from './W3cCredential' +export * from './W3cCredentialOffer' +export * from './W3cCredentialRequest' +export * from './W3cPresentation' From c276c2aaaa5ea7f8b4092c7e552f4d0900c72556 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Mon, 11 Dec 2023 12:53:10 +0300 Subject: [PATCH 11/21] Use `W3c` instead of capitalized `W3C` in python wrapper Signed-off-by: artem.ivanov --- wrappers/python/anoncreds/__init__.py | 14 ++--- wrappers/python/anoncreds/bindings.py | 37 ------------- wrappers/python/anoncreds/types.py | 78 +++++++++++++-------------- wrappers/python/demo/w3c_test.py | 24 ++++----- 4 files changed, 59 insertions(+), 94 deletions(-) diff --git a/wrappers/python/anoncreds/__init__.py b/wrappers/python/anoncreds/__init__.py index 4264e772..f6f905ea 100644 --- a/wrappers/python/anoncreds/__init__.py +++ b/wrappers/python/anoncreds/__init__.py @@ -21,10 +21,10 @@ RevocationStatusList, RevocationRegistryDefinition, RevocationRegistryDefinitionPrivate, - W3CCredentialOffer, - W3CCredentialRequest, - W3CCredential, - W3CPresentation, + W3cCredentialOffer, + W3cCredentialRequest, + W3cCredential, + W3cPresentation, ) __all__ = ( @@ -52,6 +52,8 @@ "RevocationRegistryDefinition", "RevocationRegistryDefinitionPrivate", "Schema", - "W3CCredential", - "W3CPresentation" + "W3cCredentialOffer", + "W3cCredentialRequest", + "W3cCredential", + "W3cPresentation" ) diff --git a/wrappers/python/anoncreds/bindings.py b/wrappers/python/anoncreds/bindings.py index 5ecc0a0d..4e5de89a 100644 --- a/wrappers/python/anoncreds/bindings.py +++ b/wrappers/python/anoncreds/bindings.py @@ -709,20 +709,6 @@ def create_credential_offer( return cred_offer -def create_w3c_credential_offer( - schema_id: str, cred_def_id: str, key_proof: ObjectHandle -) -> ObjectHandle: - cred_offer = ObjectHandle() - do_call( - "anoncreds_create_w3c_credential_offer", - encode_str(schema_id), - encode_str(cred_def_id), - key_proof, - byref(cred_offer), - ) - return cred_offer - - def create_credential_request( entropy: Optional[str], prover_did: Optional[str], @@ -746,29 +732,6 @@ def create_credential_request( return (cred_req, cred_req_metadata) -def create_w3c_credential_request( - entropy: Optional[str], - prover_did: Optional[str], - cred_def: ObjectHandle, - link_secret: str, - link_secret_id: str, - cred_offer: ObjectHandle, -) -> Tuple[ObjectHandle, ObjectHandle]: - cred_req, cred_req_metadata = ObjectHandle(), ObjectHandle() - do_call( - "anoncreds_create_w3c_credential_request", - encode_str(entropy), - encode_str(prover_did), - cred_def, - encode_str(link_secret), - encode_str(link_secret_id), - cred_offer, - byref(cred_req), - byref(cred_req_metadata), - ) - return (cred_req, cred_req_metadata) - - def create_link_secret() -> str: result = StrBuffer() do_call( diff --git a/wrappers/python/anoncreds/types.py b/wrappers/python/anoncreds/types.py index 016c5ee7..596748b9 100644 --- a/wrappers/python/anoncreds/types.py +++ b/wrappers/python/anoncreds/types.py @@ -103,23 +103,23 @@ def load(cls, value: Union[dict, str, bytes, memoryview]) -> "CredentialOffer": ) -class W3CCredentialOffer(bindings.AnoncredsObject): +class W3cCredentialOffer(bindings.AnoncredsObject): @classmethod def create( cls, schema_id: str, cred_def_id: str, key_proof: Union[str, KeyCorrectnessProof], - ) -> "W3CCredentialOffer": + ) -> "W3cCredentialOffer": if not isinstance(key_proof, bindings.AnoncredsObject): key_proof = KeyCorrectnessProof.load(key_proof) - return W3CCredentialOffer( + return W3cCredentialOffer( bindings.create_w3c_credential_offer(schema_id, cred_def_id, key_proof.handle) ) @classmethod - def load(cls, value: Union[dict, str, bytes, memoryview]) -> "W3CCredentialOffer": - return W3CCredentialOffer( + def load(cls, value: Union[dict, str, bytes, memoryview]) -> "W3cCredentialOffer": + return W3cCredentialOffer( bindings._object_from_json("anoncreds_credential_offer_from_json", value) ) @@ -159,7 +159,7 @@ def load(cls, value: Union[dict, str, bytes, memoryview]) -> "CredentialRequest" -class W3CCredentialRequest(bindings.AnoncredsObject): +class W3cCredentialRequest(bindings.AnoncredsObject): @classmethod def create( cls, @@ -168,12 +168,12 @@ def create( cred_def: Union[str, CredentialDefinition], link_secret: str, link_secret_id: str, - cred_offer: Union[str, W3CCredentialOffer], - ) -> Tuple["W3CCredentialRequest", "CredentialRequestMetadata"]: + cred_offer: Union[str, W3cCredentialOffer], + ) -> Tuple["W3cCredentialRequest", "CredentialRequestMetadata"]: if not isinstance(cred_def, bindings.AnoncredsObject): cred_def = CredentialDefinition.load(cred_def) if not isinstance(cred_offer, bindings.AnoncredsObject): - cred_offer = W3CCredentialOffer.load(cred_offer) + cred_offer = W3cCredentialOffer.load(cred_offer) cred_def_handle, cred_def_metadata = bindings.create_w3c_credential_request( entropy, prover_did, @@ -182,13 +182,13 @@ def create( link_secret_id, cred_offer.handle, ) - return W3CCredentialRequest(cred_def_handle), CredentialRequestMetadata( + return W3cCredentialRequest(cred_def_handle), CredentialRequestMetadata( cred_def_metadata ) @classmethod - def load(cls, value: Union[dict, str, bytes, memoryview]) -> "W3CCredentialRequest": - return W3CCredentialRequest( + def load(cls, value: Union[dict, str, bytes, memoryview]) -> "W3cCredentialRequest": + return W3cCredentialRequest( bindings._object_from_json("anoncreds_credential_request_from_json", value) ) @@ -402,10 +402,10 @@ def rev_reg_index(self) -> Optional[int]: def to_w3c( self, cred_def: Union[str, CredentialDefinition] - ) -> "W3CCredential": + ) -> "W3cCredential": if not isinstance(cred_def, bindings.AnoncredsObject): cred_def = CredentialDefinition.load(cred_def) - return W3CCredential( + return W3cCredential( bindings.credential_to_w3c( self.handle, cred_def.handle, @@ -413,7 +413,7 @@ def to_w3c( ) @classmethod - def from_w3c(cls, cred: "W3CCredential") -> "Credential": + def from_w3c(cls, cred: "W3cCredential") -> "Credential": return Credential( bindings.credential_from_w3c( cred.handle @@ -421,7 +421,7 @@ def from_w3c(cls, cred: "W3CCredential") -> "Credential": ) -class W3CCredential(bindings.AnoncredsObject): +class W3cCredential(bindings.AnoncredsObject): GET_ATTR = "anoncreds_w3c_credential_get_attribute" @classmethod @@ -429,20 +429,20 @@ def create( cls, cred_def: Union[str, CredentialDefinition], cred_def_private: Union[str, CredentialDefinitionPrivate], - cred_offer: Union[str, W3CCredentialOffer], - cred_request: Union[str, W3CCredentialRequest], + cred_offer: Union[str, W3cCredentialOffer], + cred_request: Union[str, W3cCredentialRequest], attr_raw_values: Mapping[str, str], revocation_config: Optional["CredentialRevocationConfig"] = None, encoding: Optional[str] = None, - ) -> "W3CCredential": + ) -> "W3cCredential": if not isinstance(cred_def, bindings.AnoncredsObject): cred_def = CredentialDefinition.load(cred_def) if not isinstance(cred_def_private, bindings.AnoncredsObject): cred_def_private = CredentialDefinitionPrivate.load(cred_def_private) if not isinstance(cred_offer, bindings.AnoncredsObject): - cred_offer = W3CCredentialOffer.load(cred_offer) + cred_offer = W3cCredentialOffer.load(cred_offer) if not isinstance(cred_request, bindings.AnoncredsObject): - cred_request = W3CCredentialRequest.load(cred_request) + cred_request = W3cCredentialRequest.load(cred_request) cred = bindings.create_w3c_credential( cred_def.handle, cred_def_private.handle, @@ -452,7 +452,7 @@ def create( revocation_config._native if revocation_config else None, encoding, ) - return W3CCredential(cred) + return W3cCredential(cred) def process( self, @@ -460,14 +460,14 @@ def process( link_secret: str, cred_def: Union[str, CredentialDefinition], rev_reg_def: Optional[Union[str, "RevocationRegistryDefinition"]] = None, - ) -> "W3CCredential": + ) -> "W3cCredential": if not isinstance(cred_req_metadata, bindings.AnoncredsObject): cred_req_metadata = CredentialRequestMetadata.load(cred_req_metadata) if not isinstance(cred_def, bindings.AnoncredsObject): cred_def = CredentialDefinition.load(cred_def) if rev_reg_def and not isinstance(rev_reg_def, bindings.AnoncredsObject): rev_reg_def = RevocationRegistryDefinition.load(rev_reg_def) - return W3CCredential( + return W3cCredential( bindings.process_w3c_credential( self.handle, cred_req_metadata.handle, @@ -478,7 +478,7 @@ def process( ) @classmethod - def load(cls, value: Union[dict, str, bytes, memoryview]) -> "W3CCredential": + def load(cls, value: Union[dict, str, bytes, memoryview]) -> "W3cCredential": return Credential( bindings._object_from_json("anoncreds_w3c_credential_from_json", value) ) @@ -528,13 +528,13 @@ def to_legacy( return Credential.from_w3c(self) @classmethod - def from_legacy(cls, cred: "Credential", cred_def: Union[str, CredentialDefinition]) -> "W3CCredential": + def from_legacy(cls, cred: "Credential", cred_def: Union[str, CredentialDefinition]) -> "W3cCredential": return cred.to_w3c(cred_def) def add_non_anoncreds_integrity_proof( self, proof: Union[str, dict] - ) -> "W3CCredential": + ) -> "W3cCredential": if isinstance(proof, dict): proof = json.dumps(proof) self.handle = bindings.w3c_credential_add_non_anoncreds_integrity_proof( @@ -545,7 +545,7 @@ def add_non_anoncreds_integrity_proof( def set_id( self, id: str - ) -> "W3CCredential": + ) -> "W3cCredential": self.handle = bindings.w3c_credential_set_id( self.handle, id, @@ -554,7 +554,7 @@ def set_id( def set_subject_id( self, id: str - ) -> "W3CCredential": + ) -> "W3cCredential": self.handle = bindings.w3c_credential_set_subject_id( self.handle, id, @@ -563,7 +563,7 @@ def set_subject_id( def add_context( self, context: str - ) -> "W3CCredential": + ) -> "W3cCredential": self.handle = bindings.w3c_credential_add_context( self.handle, context, @@ -572,7 +572,7 @@ def add_context( def add_type( self, type: str - ) -> "W3CCredential": + ) -> "W3cCredential": self.handle = bindings.w3c_credential_add_type( self.handle, type, @@ -600,7 +600,7 @@ def add_self_attested(self, attest: Mapping[str, str]): def _get_entry( self, - cred: Union[Credential, W3CCredential], + cred: Union[Credential, W3cCredential], timestamp: Optional[int] = None, rev_state: Union[None, str, "CredentialRevocationState"] = None, ): @@ -616,7 +616,7 @@ def _get_entry( def add_attributes( self, - cred: Union[Credential, W3CCredential], + cred: Union[Credential, W3cCredential], *referents: Sequence[str], reveal: bool = True, timestamp: Optional[int] = None, @@ -630,7 +630,7 @@ def add_attributes( def add_predicates( self, - cred: Union[Credential, W3CCredential], + cred: Union[Credential, W3cCredential], *referents: Sequence[str], timestamp: Optional[int] = None, rev_state: Union[None, str, "CredentialRevocationState"] = None, @@ -788,7 +788,7 @@ def verify( ) -class W3CPresentation(bindings.AnoncredsObject): +class W3cPresentation(bindings.AnoncredsObject): @classmethod def create( cls, @@ -797,7 +797,7 @@ def create( link_secret: str, schemas: Mapping[str, Union[str, Schema]], cred_defs: Mapping[str, Union[str, CredentialDefinition]], - ) -> "W3CPresentation": + ) -> "W3cPresentation": if not isinstance(pres_req, bindings.AnoncredsObject): pres_req = PresentationRequest.load(pres_req) schema_ids = list(schemas.keys()) @@ -834,7 +834,7 @@ def create( creds_prove.append( bindings.CredentialProve.predicate(entry_idx, reft) ) - return W3CPresentation( + return W3cPresentation( bindings.create_w3c_presentation( pres_req.handle, creds, @@ -848,8 +848,8 @@ def create( ) @classmethod - def load(cls, value: Union[dict, str, bytes, memoryview]) -> "W3CPresentation": - return W3CPresentation( + def load(cls, value: Union[dict, str, bytes, memoryview]) -> "W3cPresentation": + return W3cPresentation( bindings._object_from_json("anoncreds_w3c_presentation_from_json", value) ) diff --git a/wrappers/python/demo/w3c_test.py b/wrappers/python/demo/w3c_test.py index 21ecc8f0..977cc247 100644 --- a/wrappers/python/demo/w3c_test.py +++ b/wrappers/python/demo/w3c_test.py @@ -2,15 +2,15 @@ generate_nonce, create_link_secret, Credential, - W3CCredential, + W3cCredential, CredentialDefinition, - W3CCredentialOffer, - W3CCredentialRequest, + W3cCredentialOffer, + W3cCredentialRequest, CredentialRevocationConfig, CredentialRevocationState, PresentationRequest, Presentation, - W3CPresentation, + W3cPresentation, PresentCredentials, RevocationRegistryDefinition, RevocationStatusList, @@ -50,13 +50,13 @@ link_secret = create_link_secret() link_secret_id = "default" -cred_offer = W3CCredentialOffer.create(schema_id, cred_def_id, cred_def_correctness) +cred_offer = W3cCredentialOffer.create(schema_id, cred_def_id, cred_def_correctness) -cred_request, cred_request_metadata = W3CCredentialRequest.create( +cred_request, cred_request_metadata = W3cCredentialRequest.create( entropy, None, cred_def_pub, link_secret, link_secret_id, cred_offer ) -issue_cred = W3CCredential.create( +issue_cred = W3cCredential.create( cred_def_pub, cred_def_priv, cred_offer, @@ -75,7 +75,7 @@ cred_request_metadata, link_secret, cred_def_pub, rev_reg_def_pub ) -print("W3C Credential") +print("W3c Credential") print(recv_cred.to_json()) legacy_cred = recv_cred.to_legacy() @@ -87,10 +87,10 @@ print(legacy_cred.to_json()) w3c_cred = legacy_cred.to_w3c(cred_def_pub) -print("W3C converted Credential `to_w3c`") +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, cred_def_pub) print("W3C restored Credential `from_legacy`") print(w3c_cred_restored.to_json()) @@ -175,7 +175,7 @@ rev_state=rev_state, ) -presentation = W3CPresentation.create( +presentation = W3cPresentation.create( pres_req, present, link_secret, @@ -271,7 +271,7 @@ recv_cred, "predicate1_referent", timestamp=time_revoke_cred, rev_state=rev_state ) -presentation = W3CPresentation.create( +presentation = W3cPresentation.create( pres_req, present, link_secret, schemas, cred_defs ) From e9e722979e8ed410e9d47d93133d757ef0276bac Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Mon, 11 Dec 2023 13:02:28 +0300 Subject: [PATCH 12/21] Dropped redundant methods for non-anoncreds proof and offer/request creation Signed-off-by: artem.ivanov --- docs/design/w3c/w3c-representation.md | 152 ---------------- src/data_types/w3c/credential.rs | 20 +-- src/ffi/w3c/cred_offer.rs | 25 --- src/ffi/w3c/cred_req.rs | 43 ----- src/ffi/w3c/credential.rs | 163 ------------------ src/ffi/w3c/mod.rs | 2 - tests/anoncreds_demos.rs | 151 ---------------- .../anoncreds-nodejs/src/NodeJSAnoncreds.ts | 131 -------------- .../anoncreds-nodejs/src/library/bindings.ts | 25 --- .../anoncreds-nodejs/tests/api.test.ts | 32 +--- .../anoncreds-nodejs/tests/bindings.test.ts | 12 +- .../anoncreds-react-native/cpp/HostObject.cpp | 41 +---- .../anoncreds-react-native/cpp/anoncreds.cpp | 127 -------------- .../anoncreds-react-native/cpp/anoncreds.h | 14 -- .../cpp/include/libanoncreds.h | 44 +++++ .../src/NativeBindings.ts | 29 ---- .../src/ReactNativeAnoncreds.ts | 67 ------- .../anoncreds-shared/src/Anoncreds.ts | 29 ---- .../anoncreds-shared/src/api/W3cCredential.ts | 66 +------ .../src/api/W3cCredentialOffer.ts | 43 ----- .../src/api/W3cCredentialRequest.ts | 62 ------- .../anoncreds-shared/src/api/index.ts | 3 +- wrappers/python/anoncreds/__init__.py | 4 - wrappers/python/anoncreds/bindings.py | 107 ------------ wrappers/python/anoncreds/types.py | 111 +----------- wrappers/python/demo/w3c_test.py | 24 +-- 26 files changed, 83 insertions(+), 1444 deletions(-) delete mode 100644 src/ffi/w3c/cred_offer.rs delete mode 100644 src/ffi/w3c/cred_req.rs delete mode 100644 wrappers/javascript/packages/anoncreds-shared/src/api/W3cCredentialOffer.ts delete mode 100644 wrappers/javascript/packages/anoncreds-shared/src/api/W3cCredentialRequest.ts diff --git a/docs/design/w3c/w3c-representation.md b/docs/design/w3c/w3c-representation.md index 1d140b0b..672db0f4 100644 --- a/docs/design/w3c/w3c-representation.md +++ b/docs/design/w3c/w3c-representation.md @@ -75,90 +75,6 @@ pub extern "C" fn anoncreds_credential_from_w3c( ) -> ErrorCode {} ``` -#### Credential object helper methods - -```rust -/// Add Non-Anoncreds Data Integrity proof signature to W3C AnonCreds credential -/// -/// # Params -/// cred - object handle pointing to W3C AnonCreds credential -/// proof - data integrity proof as JSON string -/// cred_p: reference that will contain update credential -/// -/// # Returns -/// Error code -#[no_mangle] -pub extern "C" fn anoncreds_w3c_credential_add_non_anoncreds_integrity_proof( - cred: ObjectHandle, - proof: FfiStr, - cred_p: *mut ObjectHandle, -) -> ErrorCode {} - -/// Add context to W3C AnonCreds credential -/// -/// # Params -/// cred - object handle pointing to W3C AnonCreds credential -/// context - context to add into credential -/// cred_p: reference that will contain update credential -/// -/// # Returns -/// Error code -#[no_mangle] -pub extern "C" fn anoncreds_w3c_credential_add_context( - cred: ObjectHandle, - context: FfiStr, - cred_p: *mut ObjectHandle, -) -> ErrorCode {} - -/// Add type to W3C AnonCreds credential -/// -/// # Params -/// cred - object handle pointing to W3C AnonCreds credential -/// type - type to add into credential -/// cred_p: reference that will contain update credential -/// -/// # Returns -/// Error code -#[no_mangle] -pub extern "C" fn anoncreds_w3c_credential_add_type( - cred: ObjectHandle, - type_: FfiStr, - cred_p: *mut ObjectHandle, -) -> ErrorCode {} - -/// Set subject id to W3C AnonCreds credential -/// -/// # Params -/// cred - object handle pointing to W3C AnonCreds credential -/// id - subject id to add into credential -/// cred_p: reference that will contain update credential -/// -/// # Returns -/// Error code -#[no_mangle] -pub extern "C" fn anoncreds_w3c_credential_set_subject_id( - cred: ObjectHandle, - id: FfiStr, - cred_p: *mut ObjectHandle, -) -> ErrorCode {} - -/// Set id to W3C AnonCreds credential -/// -/// # Params -/// cred - object handle pointing to W3C AnonCreds credential -/// id - id to add into credential -/// cred_p: reference that will contain update credential -/// -/// # Returns -/// Error code -#[no_mangle] -pub extern "C" fn anoncreds_w3c_credential_set_id( - cred: ObjectHandle, - id: FfiStr, - cred_p: *mut ObjectHandle, -) -> ErrorCode {} -``` - #### Flow methods duplication The idea for this approach to duplicate all issuance/presentation related methods for w3c standard. @@ -186,52 +102,6 @@ The reasons for adding duplication methods: - only credential conversion method to do migration for previously issued credentials ```rust -/// Create Credential Offer according to the AnonCreds specification -/// Note that Credential Offer still will be legacy styled (the same as result of anoncreds_create_credential_offer) -/// -/// # Params -/// schema_id: id of schema future credential refers to -/// cred_def_id: id of credential definition future credential refers to -/// key_proof: object handle pointing to credential definition key correctness proof -/// cred_offer_p: reference that will contain created credential offer (in legacy form) instance pointer -/// -/// # Returns -/// Error code -#[no_mangle] -pub extern "C" fn anoncreds_create_w3c_credential_offer( - schema_id: FfiStr, - cred_def_id: FfiStr, - key_proof: ObjectHandle, - cred_offer_p: *mut ObjectHandle, -) -> ErrorCode {} - -/// Create Credential Request according to the AnonCreds specification -/// Note that Credential Request still will be legacy styled (the same as result of anoncreds_create_credential_request) -/// -/// # Params -/// entropy: entropy string to use for request creation -/// prover_did: DID of the credential holder -/// cred_def: object handle pointing to credential definition -/// link_secret: holder link secret -/// link_secret_id: id of holder's link secret -/// credential_offer: object handle pointing to credential offer -/// cred_req_p: Reference that will contain created credential request (in legacy form) instance pointer. -/// cred_req_meta_p: Reference that will contain created credential request metadata (in legacy form) instance pointer. -/// -/// # Returns -/// Error code -#[no_mangle] -pub extern "C" fn anoncreds_create_w3c_credential_request( - entropy: FfiStr, - prover_did: FfiStr, - cred_def: ObjectHandle, - link_secret: FfiStr, - link_secret_id: FfiStr, - cred_offer: ObjectHandle, - cred_req_p: *mut ObjectHandle, - cred_req_meta_p: *mut ObjectHandle, -) -> ErrorCode {} - /// Create Credential in W3C form according to the specification. /// /// # Params @@ -421,28 +291,6 @@ w3c_presentation = Holder.anoncreds_w3c_create_presentation(w3c_presentation_req Verifier.anoncreds_w3c_verify_presentation(w3c_presentation) ``` -#### Issue W3C Credential, set RSA Identity Proof signature, and present W3C Presentation using RSA Identity Proof - -``` -/// Issue W3C credential using new flow methods -w3c_credential_offer = Issuer.anoncreds_w3c_create_credential_offer(...) -w3c_credential_request = Holder.anoncreds_w3c_create_credential_request(w3c_credential_offer,...) -w3c_credential = Issuer.anoncreds_w3c_create_credential(w3c_credential_request,...) -w3c_credential = Holder.anoncreds_w3c_process_credential(w3c_credential,...) - -/// Add RSA Identity Proof signature to credential -integrity_proof = extartnal_library.create_rsa_integrity_proof(w3c_credential) -w3c_credential = anoncreds_w3c_credential_add_non_anoncreds_integrity_proof(w3c_credential, integrity_proof) - -/// 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 RSA Identity Proof signature -w3c_presentation_request = Verifier.w3c_create_presentation_request() -rsa_integrity_proof_presentation = extartnal_library.create_presentation_using_rsa_integrity_proof(w3c_presentation_request, w3c_credential) -extartnal_verifier.verify_rsa_integrity_proof_presentation(rsa_integrity_proof_presentation) -``` - ### Presentation validation **Request** diff --git a/src/data_types/w3c/credential.rs b/src/data_types/w3c/credential.rs index e04c9d75..98c417f7 100644 --- a/src/data_types/w3c/credential.rs +++ b/src/data_types/w3c/credential.rs @@ -7,9 +7,7 @@ use std::string::ToString; use zeroize::Zeroize; use crate::data_types::w3c::constants::{ANONCREDS_CONTEXTS, ANONCREDS_CREDENTIAL_TYPES}; -use crate::data_types::w3c::credential_proof::{ - CredentialProof, CredentialSignatureProof, NonAnonCredsDataIntegrityProof, -}; +use crate::data_types::w3c::credential_proof::{CredentialProof, CredentialSignatureProof}; use crate::data_types::w3c::presentation_proof::{CredentialPresentationProof, PredicateAttribute}; use crate::data_types::{ cred_def::CredentialDefinitionId, @@ -330,18 +328,6 @@ impl W3CCredential { self.credential_subject.attributes = attributes } - pub fn set_subject_id(&mut self, id: URI) { - self.credential_subject.id = Some(id) - } - - pub fn add_context(&mut self, context: URI) { - self.context.0.insert(context); - } - - pub fn add_type(&mut self, types: String) { - self.type_.0.insert(types); - } - pub fn add_proof(&mut self, proof: CredentialProof) { match self.proof { OneOrMany::One(ref existing_proof) => { @@ -355,10 +341,6 @@ impl W3CCredential { self.add_proof(CredentialProof::AnonCredsSignatureProof(proof)); } - pub fn add_non_anoncreds_integrity_proof(&mut self, proof: NonAnonCredsDataIntegrityProof) { - self.add_proof(CredentialProof::NonAnonCredsDataIntegrityProof(proof)); - } - pub fn set_anoncreds_presentation_proof(&mut self, proof: CredentialPresentationProof) { self.proof = OneOrMany::One(CredentialProof::AnonCredsCredentialPresentationProof(proof)); } diff --git a/src/ffi/w3c/cred_offer.rs b/src/ffi/w3c/cred_offer.rs deleted file mode 100644 index 568fbd3c..00000000 --- a/src/ffi/w3c/cred_offer.rs +++ /dev/null @@ -1,25 +0,0 @@ -use crate::ffi::cred_offer::anoncreds_create_credential_offer; -use crate::ffi::error::ErrorCode; -use crate::ffi::object::ObjectHandle; -use ffi_support::FfiStr; - -/// Create Credential Offer according to the AnonCreds specification -/// Note that Credential Offer still will be legacy styled (the same as result of anoncreds_create_credential_offer) -/// -/// # Params -/// schema_id: id of schema future credential refers to -/// cred_def_id: id of credential definition future credential refers to -/// key_proof: object handle pointing to credential definition key correctness proof -/// cred_offer_p: reference that will contain created credential offer (in legacy form) instance pointer -/// -/// # Returns -/// Error code -#[no_mangle] -pub extern "C" fn anoncreds_create_w3c_credential_offer( - schema_id: FfiStr, - cred_def_id: FfiStr, - key_proof: ObjectHandle, - cred_offer_p: *mut ObjectHandle, -) -> ErrorCode { - anoncreds_create_credential_offer(schema_id, cred_def_id, key_proof, cred_offer_p) -} diff --git a/src/ffi/w3c/cred_req.rs b/src/ffi/w3c/cred_req.rs deleted file mode 100644 index ba958e33..00000000 --- a/src/ffi/w3c/cred_req.rs +++ /dev/null @@ -1,43 +0,0 @@ -use ffi_support::FfiStr; - -use crate::ffi::cred_req::anoncreds_create_credential_request; -use crate::ffi::error::ErrorCode; -use crate::ffi::object::ObjectHandle; - -/// Create Credential Request according to the AnonCreds specification -/// Note that Credential Request still will be legacy styled (the same as result of anoncreds_create_credential_request) -/// -/// # Params -/// entropy: entropy string to use for request creation -/// prover_did: DID of the credential holder -/// cred_def: object handle pointing to credential definition -/// link_secret: holder link secret -/// link_secret_id: id of holder's link secret -/// credential_offer: object handle pointing to credential offer -/// cred_req_p: Reference that will contain created credential request (in legacy form) instance pointer. -/// cred_req_meta_p: Reference that will contain created credential request metadata (in legacy form) instance pointer. -/// -/// # Returns -/// Error code -#[no_mangle] -pub extern "C" fn anoncreds_create_w3c_credential_request( - entropy: FfiStr, - prover_did: FfiStr, - cred_def: ObjectHandle, - link_secret: FfiStr, - link_secret_id: FfiStr, - cred_offer: ObjectHandle, - cred_req_p: *mut ObjectHandle, - cred_req_meta_p: *mut ObjectHandle, -) -> ErrorCode { - anoncreds_create_credential_request( - entropy, - prover_did, - cred_def, - link_secret, - link_secret_id, - cred_offer, - cred_req_p, - cred_req_meta_p, - ) -} diff --git a/src/ffi/w3c/credential.rs b/src/ffi/w3c/credential.rs index b3af072d..16dfac2b 100644 --- a/src/ffi/w3c/credential.rs +++ b/src/ffi/w3c/credential.rs @@ -6,8 +6,6 @@ use ffi_support::{rust_string_to_c, FfiStr}; use crate::data_types::credential::CredentialValuesEncoding; use crate::data_types::w3c::credential::CredentialAttributes; use crate::data_types::w3c::credential::W3CCredential; -use crate::data_types::w3c::credential_proof::NonAnonCredsDataIntegrityProof; -use crate::data_types::w3c::uri::URI; use crate::error::Result; use crate::ffi::credential::{FfiCredRevInfo, _link_secret, _revocation_config}; use crate::ffi::error::{catch_error, ErrorCode}; @@ -176,167 +174,6 @@ pub extern "C" fn anoncreds_credential_from_w3c( }) } -/// Add Non-Anoncreds Data Integrity proof signature to W3C AnonCreds credential -/// -/// # Params -/// cred: object handle pointing to W3C AnonCreds credential -/// proof: data integrity proof as JSON string -/// cred_p: reference that will contain update credential -/// -/// # Returns -/// Error code -#[no_mangle] -pub extern "C" fn anoncreds_w3c_credential_add_non_anoncreds_integrity_proof( - cred: ObjectHandle, - proof: FfiStr, - cred_p: *mut ObjectHandle, -) -> ErrorCode { - catch_error(|| { - check_useful_c_ptr!(cred_p); - - let proof = proof - .as_opt_str() - .ok_or_else(|| err_msg!("Missing proof"))?; - let proof: NonAnonCredsDataIntegrityProof = - serde_json::from_str(proof).map_err(|_| err_msg!("Unable to parse proof"))?; - - let mut cred = cred.load()?.cast_ref::()?.clone(); - - cred.add_non_anoncreds_integrity_proof(proof); - - let cred = ObjectHandle::create(cred)?; - unsafe { *cred_p = cred }; - - Ok(()) - }) -} - -/// Set id to W3C AnonCreds credential -/// -/// # Params -/// cred: object handle pointing to W3C AnonCreds credential -/// id: id to add into credential -/// cred_p: reference that will contain update credential -/// -/// # Returns -/// Error code -#[no_mangle] -pub extern "C" fn anoncreds_w3c_credential_set_id( - cred: ObjectHandle, - id: FfiStr, - cred_p: *mut ObjectHandle, -) -> ErrorCode { - catch_error(|| { - check_useful_c_ptr!(cred_p); - - let id = id.as_opt_str().ok_or_else(|| err_msg!("Missing id"))?; - - let mut cred = cred.load()?.cast_ref::()?.clone(); - - cred.set_id(URI::from(id)); - - let cred = ObjectHandle::create(cred)?; - unsafe { *cred_p = cred }; - - Ok(()) - }) -} - -/// Set subject id to W3C AnonCreds credential -/// -/// # Params -/// cred: object handle pointing to W3C AnonCreds credential -/// id: subject id to add into credential -/// cred_p: reference that will contain update credential -/// -/// # Returns -/// Error code -#[no_mangle] -pub extern "C" fn anoncreds_w3c_credential_set_subject_id( - cred: ObjectHandle, - id: FfiStr, - cred_p: *mut ObjectHandle, -) -> ErrorCode { - catch_error(|| { - check_useful_c_ptr!(cred_p); - - let id = id.as_opt_str().ok_or_else(|| err_msg!("Missing id"))?; - - let mut cred = cred.load()?.cast_ref::()?.clone(); - - cred.set_subject_id(URI::from(id)); - - let cred = ObjectHandle::create(cred)?; - unsafe { *cred_p = cred }; - - Ok(()) - }) -} - -/// Add context to W3C AnonCreds credential -/// -/// # Params -/// cred: object handle pointing to W3C AnonCreds credential -/// context: context to add into credential -/// cred_p: reference that will contain update credential -/// -/// # Returns -/// Error code -#[no_mangle] -pub extern "C" fn anoncreds_w3c_credential_add_context( - cred: ObjectHandle, - context: FfiStr, - cred_p: *mut ObjectHandle, -) -> ErrorCode { - catch_error(|| { - check_useful_c_ptr!(cred_p); - - let context = context - .as_opt_str() - .ok_or_else(|| err_msg!("Missing context"))?; - - let mut cred = cred.load()?.cast_ref::()?.clone(); - - cred.add_context(URI::from(context)); - - let cred = ObjectHandle::create(cred)?; - unsafe { *cred_p = cred }; - - Ok(()) - }) -} - -/// Add type to W3C AnonCreds credential -/// -/// # Params -/// cred: object handle pointing to W3C AnonCreds credential -/// type: type to add into credential -/// cred_p: reference that will contain update credential -/// -/// # Returns -/// Error code -#[no_mangle] -pub extern "C" fn anoncreds_w3c_credential_add_type( - cred: ObjectHandle, - type_: FfiStr, - cred_p: *mut ObjectHandle, -) -> ErrorCode { - catch_error(|| { - check_useful_c_ptr!(cred_p); - - let type_ = type_.as_opt_str().ok_or_else(|| err_msg!("Missing type"))?; - - let mut cred = cred.load()?.cast_ref::()?.clone(); - - cred.add_type(type_.to_string()); - - let cred = ObjectHandle::create(cred)?; - unsafe { *cred_p = cred }; - - Ok(()) - }) -} - /// Get value of requested credential attribute as string /// /// # Params diff --git a/src/ffi/w3c/mod.rs b/src/ffi/w3c/mod.rs index 3587e146..dedbc204 100644 --- a/src/ffi/w3c/mod.rs +++ b/src/ffi/w3c/mod.rs @@ -1,4 +1,2 @@ -mod cred_offer; -mod cred_req; mod credential; mod presentation; diff --git a/tests/anoncreds_demos.rs b/tests/anoncreds_demos.rs index 3416fd68..106e8ab6 100644 --- a/tests/anoncreds_demos.rs +++ b/tests/anoncreds_demos.rs @@ -3298,157 +3298,6 @@ fn anoncreds_demo_works_for_issue_two_credentials_in_different_forms_and_present ); } -#[test] -fn anoncreds_demo_works_for_issue_w3c_credential_add_identity_proof_present_w3c_presentation() { - // Create pseudo ledger and wallets - let mut ledger = Ledger::default(); - let mut issuer_wallet = IssuerWallet::default(); - let mut prover_wallet = ProverWallet::default(); - let verifier_wallet = VerifierWallet::default(); - - // Create schema - let (gvt_schema, gvt_schema_id) = issuer_wallet.create_schema(&mut ledger, GVT_CRED); - - // Create credential definition - let (gvt_cred_def, gvt_cred_def_id) = - issuer_wallet.create_cred_def(&mut ledger, &gvt_schema, false); - - // Issuer creates a Credential Offer - let cred_offer = issuer_wallet.create_credential_offer(&gvt_schema_id, &gvt_cred_def_id); - - // Prover creates a Credential Request - let (cred_request, cred_request_metadata) = - prover_wallet.create_credential_request(&gvt_cred_def, &cred_offer); - - // Issuer creates a credential - let cred_values = fixtures::credential_values(GVT_CRED); - let issue_cred = issuer_wallet.create_credential( - &CredentialFormat::W3C, - &gvt_cred_def_id, - &cred_offer, - &cred_request, - cred_values.into(), - None, - None, - None, - ); - - // Add RSA identity proof - let mut issue_cred = issue_cred.w3c().clone(); - let rsa_signature = json!({ - "type": "RsaSignature2018", - "created": "2017-06-18T21:19:10Z", - "proofPurpose": "assertionMethod", - "verificationMethod": "https://example.edu/issuers/565049#key-1", - "jws": "eyJhbGciOiJSUzI1NiIsImI2NCI6ZmFsc2UsImNyaXQiOlsiYjY0Il19..TCYt5X - sITJX1CxPCT8yAV-TVkIEq_PbChOMqsLfRoPsnsgw5WEuts01mq-pQy7UJiN5mgRxD-WUc - X16dUEMGlv50aqzpqh4Qktb3rk-BuQy72IFLOqV0G_zS245-kronKb78cPN25DGlcTwLtj - PAYuNzVBAh4vGHSrQyHUdBBPM" - }); - issue_cred.add_non_anoncreds_integrity_proof(rsa_signature); - issue_cred.set_subject_id(URI::from("did:example:ebfeb1f712ebc6f1c276e12ec21")); - issue_cred.add_context(URI::from("https://www.w3.org/2018/credentials/examples/v1")); - issue_cred.add_type("AlumniCredential".to_string()); - - // Prover receives the credential and processes it - let mut recv_cred = Credentials::W3C(issue_cred); - prover_wallet.store_credential( - GVT_CRED, - &mut recv_cred, - &cred_request_metadata, - &gvt_cred_def, - None, - ); - - // Make W3C presentation using w3c credential - - // Verifier creates a presentation request - let nonce = verifier_wallet.generate_nonce(); - let pres_request = serde_json::from_value(json!({ - "nonce": nonce, - "name":"pres_req_1", - "version":"0.1", - "requested_attributes":{ - "attr1_referent":{ - "name":"name" - } - }, - "requested_predicates":{ - "predicate1_referent":{"name":"age","p_type":">=","p_value":18} - } - })) - .expect("Error creating proof request"); - - // Prover creates presentation - let present_credentials = vec![CredentialToPresent { - id: GVT_CRED.to_string(), - attributes: vec![ - PresentAttribute { - referent: "attr1_referent".to_string(), - form: PresentAttributeForm::RevealedAttribute, - }, - PresentAttribute { - referent: "predicate1_referent".to_string(), - form: PresentAttributeForm::Predicate, - }, - ], - }]; - - let schemas = ledger.resolve_schemas(vec![&gvt_schema_id]); - let cred_defs = ledger.resolve_cred_defs(vec![&gvt_cred_def_id]); - - // Prover creates presentation - let presentation = prover_wallet.create_presentation( - &PresentationFormat::W3C, - &schemas, - &cred_defs, - &pres_request, - &present_credentials, - None, - ); - - let valid = verifier_wallet - .verify_presentation( - &presentation, - &pres_request, - &schemas, - &cred_defs, - None, - None, - None, - ) - .expect("Error verifying presentation"); - - assert!(valid); - - // Verifier verifies presentation - let presentation = presentation.w3c(); - assert_eq!( - &CredentialAttributeValue::Attribute("Alex".to_string()), - presentation.verifiable_credential[0] - .credential_subject - .attributes - .0 - .get("name") - .unwrap() - ); - - assert_eq!( - CredentialAttributeValue::Predicate(vec![PredicateAttribute { - type_: PredicateAttributeType::AnonCredsPredicate, - predicate: PredicateTypes::GE, - value: 18, - }]), - presentation.verifiable_credential[0] - .credential_subject - .attributes - .0 - .get("age") - .cloned() - .unwrap() - ); -} - #[test] fn anoncreds_demo_works_for_single_issuer_single_prover_and_present_self_attested_attribute() { // Create pseudo ledger and wallets diff --git a/wrappers/javascript/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts b/wrappers/javascript/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts index 1f4e36d4..136f25a3 100644 --- a/wrappers/javascript/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts +++ b/wrappers/javascript/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts @@ -627,57 +627,6 @@ export class NodeJSAnoncreds implements Anoncreds { return new ObjectHandle(handleReturnPointer(ret)) } - public createW3cCredentialOffer(options: { - schemaId: string - credentialDefinitionId: string - keyCorrectnessProof: ObjectHandle - }): ObjectHandle { - const { schemaId, credentialDefinitionId, keyCorrectnessProof } = serializeArguments(options) - - const ret = allocatePointer() - this.nativeAnoncreds.anoncreds_create_w3c_credential_offer( - schemaId, - credentialDefinitionId, - keyCorrectnessProof, - ret - ) - this.handleError() - - return new ObjectHandle(handleReturnPointer(ret)) - } - - public createW3cCredentialRequest(options: { - entropy?: string - proverDid?: string - credentialDefinition: ObjectHandle - linkSecret: string - linkSecretId: string - credentialOffer: ObjectHandle - }): { credentialRequest: ObjectHandle; credentialRequestMetadata: ObjectHandle } { - const { entropy, proverDid, credentialDefinition, linkSecret, linkSecretId, credentialOffer } = - serializeArguments(options) - - const credentialRequestPtr = allocatePointer() - const credentialRequestMetadataPtr = allocatePointer() - - this.nativeAnoncreds.anoncreds_create_w3c_credential_request( - entropy, - proverDid, - credentialDefinition, - linkSecret, - linkSecretId, - credentialOffer, - credentialRequestPtr, - credentialRequestMetadataPtr - ) - this.handleError() - - return { - credentialRequest: new ObjectHandle(handleReturnPointer(credentialRequestPtr)), - credentialRequestMetadata: new ObjectHandle(handleReturnPointer(credentialRequestMetadataPtr)) - } - } - public createW3cCredential(options: { credentialDefinition: ObjectHandle credentialDefinitionPrivate: ObjectHandle @@ -929,78 +878,6 @@ export class NodeJSAnoncreds implements Anoncreds { return new ObjectHandle(handleReturnPointer(ret)) } - public w3cCredentialAddNonAnoncredsIntegrityProof(options: { - objectHandle: ObjectHandle - proof: string - }): ObjectHandle { - const { objectHandle, proof } = serializeArguments(options) - - const ret = allocatePointer() - - this.nativeAnoncreds.anoncreds_w3c_credential_add_non_anoncreds_integrity_proof(objectHandle, proof, ret) - this.handleError() - - return new ObjectHandle(handleReturnPointer(ret)) - } - - public w3cCredentialAddNonAnonCredsIntegrityProof(options: { - objectHandle: ObjectHandle - proof: string - }): ObjectHandle { - const { objectHandle, proof } = serializeArguments(options) - - const ret = allocatePointer() - - this.nativeAnoncreds.anoncreds_w3c_credential_add_non_anoncreds_integrity_proof(objectHandle, proof, ret) - this.handleError() - - return new ObjectHandle(handleReturnPointer(ret)) - } - - public w3cCredentialSetId(options: { objectHandle: ObjectHandle; id: string }): ObjectHandle { - const { objectHandle, id } = serializeArguments(options) - - const ret = allocatePointer() - - this.nativeAnoncreds.anoncreds_w3c_credential_set_id(objectHandle, id, ret) - this.handleError() - - return new ObjectHandle(handleReturnPointer(ret)) - } - - public w3cCredentialSetSubjectId(options: { objectHandle: ObjectHandle; id: string }): ObjectHandle { - const { objectHandle, id } = serializeArguments(options) - - const ret = allocatePointer() - - this.nativeAnoncreds.anoncreds_w3c_credential_set_subject_id(objectHandle, id, ret) - this.handleError() - - return new ObjectHandle(handleReturnPointer(ret)) - } - - public w3cCredentialAddContext(options: { objectHandle: ObjectHandle; context: string }): ObjectHandle { - const { objectHandle, context } = serializeArguments(options) - - const ret = allocatePointer() - - this.nativeAnoncreds.anoncreds_w3c_credential_add_context(objectHandle, context, ret) - this.handleError() - - return new ObjectHandle(handleReturnPointer(ret)) - } - - public w3cCredentialAddType(options: { objectHandle: ObjectHandle; type: string }): ObjectHandle { - const { objectHandle, type } = serializeArguments(options) - - const ret = allocatePointer() - - this.nativeAnoncreds.anoncreds_w3c_credential_add_type(objectHandle, type, ret) - this.handleError() - - return new ObjectHandle(handleReturnPointer(ret)) - } - public version(): string { return this.nativeAnoncreds.anoncreds_version() } @@ -1090,14 +967,6 @@ export class NodeJSAnoncreds implements Anoncreds { return this.objectFromJson(this.nativeAnoncreds.anoncreds_key_correctness_proof_from_json, options) } - public w3cCredentialOfferFromJson(options: { json: string }): ObjectHandle { - return this.objectFromJson(this.nativeAnoncreds.anoncreds_credential_offer_from_json, options) - } - - public w3cCredentialRequestFromJson(options: { json: string }): ObjectHandle { - return this.objectFromJson(this.nativeAnoncreds.anoncreds_credential_request_from_json, options) - } - public w3cCredentialFromJson(options: { json: string }): ObjectHandle { return this.objectFromJson(this.nativeAnoncreds.anoncreds_w3c_credential_from_json, options) } diff --git a/wrappers/javascript/packages/anoncreds-nodejs/src/library/bindings.ts b/wrappers/javascript/packages/anoncreds-nodejs/src/library/bindings.ts index ce88c874..4ccf3b71 100644 --- a/wrappers/javascript/packages/anoncreds-nodejs/src/library/bindings.ts +++ b/wrappers/javascript/packages/anoncreds-nodejs/src/library/bindings.ts @@ -192,23 +192,6 @@ export const nativeBindings = { anoncreds_revocation_registry_definition_private_from_json: [FFI_ERRORCODE, [ByteBufferStruct, FFI_STRING_PTR]], anoncreds_key_correctness_proof_from_json: [FFI_ERRORCODE, [ByteBufferStruct, FFI_STRING_PTR]], anoncreds_schema_from_json: [FFI_ERRORCODE, [ByteBufferStruct, FFI_STRING_PTR]], - anoncreds_create_w3c_credential_offer: [ - FFI_ERRORCODE, - [FFI_STRING, FFI_STRING, FFI_OBJECT_HANDLE, FFI_OBJECT_HANDLE_PTR] - ], - anoncreds_create_w3c_credential_request: [ - FFI_ERRORCODE, - [ - FFI_STRING, - FFI_STRING, - FFI_OBJECT_HANDLE, - FFI_STRING, - FFI_STRING, - FFI_OBJECT_HANDLE, - FFI_OBJECT_HANDLE_PTR, - FFI_OBJECT_HANDLE_PTR - ] - ], anoncreds_create_w3c_credential: [ FFI_ERRORCODE, [ @@ -259,14 +242,6 @@ export const nativeBindings = { ], anoncreds_credential_to_w3c: [FFI_ERRORCODE, [FFI_OBJECT_HANDLE, FFI_OBJECT_HANDLE, FFI_OBJECT_HANDLE_PTR]], anoncreds_credential_from_w3c: [FFI_ERRORCODE, [FFI_OBJECT_HANDLE, FFI_OBJECT_HANDLE_PTR]], - anoncreds_w3c_credential_add_non_anoncreds_integrity_proof: [ - FFI_ERRORCODE, - [FFI_OBJECT_HANDLE, FFI_STRING, FFI_OBJECT_HANDLE_PTR] - ], - anoncreds_w3c_credential_set_id: [FFI_ERRORCODE, [FFI_OBJECT_HANDLE, FFI_STRING, FFI_OBJECT_HANDLE_PTR]], - anoncreds_w3c_credential_set_subject_id: [FFI_ERRORCODE, [FFI_OBJECT_HANDLE, FFI_STRING, FFI_OBJECT_HANDLE_PTR]], - anoncreds_w3c_credential_add_context: [FFI_ERRORCODE, [FFI_OBJECT_HANDLE, FFI_STRING, FFI_OBJECT_HANDLE_PTR]], - anoncreds_w3c_credential_add_type: [FFI_ERRORCODE, [FFI_OBJECT_HANDLE, FFI_STRING, FFI_OBJECT_HANDLE_PTR]], anoncreds_w3c_credential_get_attribute: [FFI_ERRORCODE, [FFI_OBJECT_HANDLE, FFI_STRING, FFI_STRING_PTR]], anoncreds_w3c_presentation_from_json: [FFI_ERRORCODE, [ByteBufferStruct, FFI_STRING_PTR]], anoncreds_w3c_credential_from_json: [FFI_ERRORCODE, [ByteBufferStruct, FFI_STRING_PTR]] diff --git a/wrappers/javascript/packages/anoncreds-nodejs/tests/api.test.ts b/wrappers/javascript/packages/anoncreds-nodejs/tests/api.test.ts index 2b44a40d..58da5ca2 100644 --- a/wrappers/javascript/packages/anoncreds-nodejs/tests/api.test.ts +++ b/wrappers/javascript/packages/anoncreds-nodejs/tests/api.test.ts @@ -13,8 +13,8 @@ import { RevocationStatusList, Schema, W3cCredential, - W3cCredentialOffer, - W3cCredentialRequest, + CredentialOffer, + CredentialRequest, W3cPresentation } from '@hyperledger/anoncreds-shared' @@ -608,7 +608,7 @@ describe('API W3C', () => { timestamp: timeCreateRevStatusList }) - const credentialOffer = W3cCredentialOffer.create({ + const credentialOffer = CredentialOffer.create({ schemaId: 'mock:uri', credentialDefinitionId: 'mock:uri', keyCorrectnessProof @@ -617,7 +617,7 @@ describe('API W3C', () => { const linkSecret = LinkSecret.create() const linkSecretId = 'link secret id' - const { credentialRequestMetadata, credentialRequest } = W3cCredentialRequest.create({ + const { credentialRequestMetadata, credentialRequest } = CredentialRequest.create({ entropy: 'entropy', credentialDefinition, linkSecret, @@ -655,26 +655,6 @@ describe('API W3C', () => { expect('mock:uri').toEqual(convertedW3cCredential.schemaId) expect('mock:uri').toEqual(convertedW3cCredential.credentialDefinitionId) - convertedW3cCredential.addNonAnonCredsIntegrityProof({ - type: 'Ed25519Signature2020', - created: '2021-11-13T18:19:39Z', - verificationMethod: 'did:sov:3avoBCqDMFHFaKUHug9s8W#key-1', - proofPurpose: 'assertionMethod', - proofValue: 'z58DAdFfa9SkqZMVPxAQpic7ndSayn1PzZs6ZjWp1CktyGesjuTSwRdoWhAfGFCF5bppETSTojQCrfFPP2oumHKtz' - }) - - const id = 'http://example.com/credentials/3732' - const subjectId = 'did:example:ebfeb1f712ebc6f1c276e12ec21' - - convertedW3cCredential.setId(id) - convertedW3cCredential.setSubjectId(subjectId) - convertedW3cCredential.addContext('https://www.w3.org/2018/credentials/examples/v1') - convertedW3cCredential.addType('UniversityDegreeCredential') - const convertedW3cCredentialJson = convertedW3cCredential.toJson() - - expect(id).toEqual(convertedW3cCredentialJson.id) - expect(subjectId).toEqual(convertedW3cCredentialJson.credentialSubject.id) - const credentialReceived = credential.process({ credentialDefinition, credentialRequestMetadata, @@ -773,7 +753,7 @@ describe('API W3C', () => { tag: 'TAG' }) - const credentialOffer = W3cCredentialOffer.create({ + const credentialOffer = CredentialOffer.create({ schemaId: 'mock:uri', credentialDefinitionId: 'mock:uri', keyCorrectnessProof @@ -782,7 +762,7 @@ describe('API W3C', () => { const linkSecret = LinkSecret.create() const linkSecretId = 'link secret id' - const { credentialRequestMetadata, credentialRequest } = W3cCredentialRequest.create({ + const { credentialRequestMetadata, credentialRequest } = CredentialRequest.create({ entropy: 'entropy', credentialDefinition, linkSecret, diff --git a/wrappers/javascript/packages/anoncreds-nodejs/tests/bindings.test.ts b/wrappers/javascript/packages/anoncreds-nodejs/tests/bindings.test.ts index 8a1eb72f..f72761df 100644 --- a/wrappers/javascript/packages/anoncreds-nodejs/tests/bindings.test.ts +++ b/wrappers/javascript/packages/anoncreds-nodejs/tests/bindings.test.ts @@ -374,7 +374,7 @@ describe('bindings', () => { timestamp: timeCreateRevStatusList }) - const credentialOffer = anoncreds.createW3cCredentialOffer({ + const credentialOffer = anoncreds.createCredentialOffer({ schemaId: 'mock:uri', credentialDefinitionId: 'mock:uri', keyCorrectnessProof @@ -383,7 +383,7 @@ describe('bindings', () => { const linkSecret = anoncreds.createLinkSecret() const linkSecretId = 'link secret id' - const { credentialRequestMetadata, credentialRequest } = anoncreds.createW3cCredentialRequest({ + const { credentialRequestMetadata, credentialRequest } = anoncreds.createCredentialRequest({ entropy: ENTROPY, credentialDefinition, linkSecret, @@ -672,7 +672,7 @@ describe('bindings', () => { timestamp: timeCreateRevStatusList }) - const credentialOffer = anoncreds.createW3cCredentialOffer({ + const credentialOffer = anoncreds.createCredentialOffer({ schemaId: 'mock:uri', credentialDefinitionId: 'mock:uri', keyCorrectnessProof @@ -681,7 +681,7 @@ describe('bindings', () => { const linkSecret = anoncreds.createLinkSecret() const linkSecretId = 'link secret id' - const { credentialRequestMetadata, credentialRequest } = anoncreds.createW3cCredentialRequest({ + const { credentialRequestMetadata, credentialRequest } = anoncreds.createCredentialRequest({ entropy: ENTROPY, credentialDefinition, linkSecret, @@ -944,7 +944,7 @@ describe('bindings', () => { tag: 'TAG' }) - const credentialOffer = anoncreds.createW3cCredentialOffer({ + const credentialOffer = anoncreds.createCredentialOffer({ schemaId: 'mock:uri', credentialDefinitionId: 'mock:uri', keyCorrectnessProof @@ -953,7 +953,7 @@ describe('bindings', () => { const linkSecret = anoncreds.createLinkSecret() const linkSecretId = 'link secret id' - const { credentialRequestMetadata, credentialRequest } = anoncreds.createW3cCredentialRequest({ + const { credentialRequestMetadata, credentialRequest } = anoncreds.createCredentialRequest({ entropy: ENTROPY, credentialDefinition, linkSecret, diff --git a/wrappers/javascript/packages/anoncreds-react-native/cpp/HostObject.cpp b/wrappers/javascript/packages/anoncreds-react-native/cpp/HostObject.cpp index f073ffd1..599ce28f 100644 --- a/wrappers/javascript/packages/anoncreds-react-native/cpp/HostObject.cpp +++ b/wrappers/javascript/packages/anoncreds-react-native/cpp/HostObject.cpp @@ -15,33 +15,23 @@ FunctionMap AnoncredsTurboModuleHostObject::functionMapping(jsi::Runtime &rt) { fMap.insert(std::make_tuple("getCurrentError", &anoncreds::getCurrentError)); fMap.insert( std::make_tuple("createCredential", &anoncreds::createCredential)); - fMap.insert( - std::make_tuple("createW3cCredential", &anoncreds::createW3cCredential)); fMap.insert(std::make_tuple("createCredentialDefinition", &anoncreds::createCredentialDefinition)); fMap.insert(std::make_tuple("createCredentialOffer", &anoncreds::createCredentialOffer)); - fMap.insert(std::make_tuple("createW3cCredentialOffer", - &anoncreds::createW3cCredentialOffer)); fMap.insert(std::make_tuple("createCredentialRequest", &anoncreds::createCredentialRequest)); - fMap.insert(std::make_tuple("createW3cCredentialRequest", - &anoncreds::createW3cCredentialRequest)); fMap.insert( std::make_tuple("createLinkSecret", &anoncreds::createLinkSecret)); fMap.insert(std::make_tuple("createOrUpdateRevocationState", &anoncreds::createOrUpdateRevocationState)); fMap.insert( std::make_tuple("createPresentation", &anoncreds::createPresentation)); - fMap.insert( - std::make_tuple("createW3cPresentation", &anoncreds::createW3cPresentation)); fMap.insert(std::make_tuple("createRevocationRegistryDefinition", &anoncreds::createRevocationRegistryDefinition)); fMap.insert(std::make_tuple("createSchema", &anoncreds::createSchema)); fMap.insert(std::make_tuple("credentialGetAttribute", &anoncreds::credentialGetAttribute)); - fMap.insert(std::make_tuple("w3cCredentialGetAttribute", - &anoncreds::w3cCredentialGetAttribute)); fMap.insert(std::make_tuple("encodeCredentialAttributes", &anoncreds::encodeCredentialAttributes)); fMap.insert(std::make_tuple("generateNonce", &anoncreds::generateNonce)); @@ -49,8 +39,6 @@ FunctionMap AnoncredsTurboModuleHostObject::functionMapping(jsi::Runtime &rt) { fMap.insert(std::make_tuple("getTypeName", &anoncreds::getTypeName)); fMap.insert( std::make_tuple("processCredential", &anoncreds::processCredential)); - fMap.insert( - std::make_tuple("processW3cCredential", &anoncreds::processW3cCredential)); fMap.insert( std::make_tuple("revocationRegistryDefinitionGetAttribute", &anoncreds::revocationRegistryDefinitionGetAttribute)); @@ -58,8 +46,6 @@ FunctionMap AnoncredsTurboModuleHostObject::functionMapping(jsi::Runtime &rt) { std::make_tuple("setDefaultLogger", &anoncreds::setDefaultLogger)); fMap.insert( std::make_tuple("verifyPresentation", &anoncreds::verifyPresentation)); - fMap.insert( - std::make_tuple("verifyW3cPresentation", &anoncreds::verifyW3cPresentation)); fMap.insert(std::make_tuple("createRevocationStatusList", &anoncreds::createRevocationStatusList)); fMap.insert(std::make_tuple("updateRevocationStatusList", @@ -79,25 +65,17 @@ fMap.insert(std::make_tuple("createRevocationStatusList", &anoncreds::revocationStatusListFromJson)); fMap.insert(std::make_tuple("presentationFromJson", &anoncreds::presentationFromJson)); - fMap.insert(std::make_tuple("w3cPresentationFromJson", - &anoncreds::w3cPresentationFromJson)); fMap.insert(std::make_tuple("presentationRequestFromJson", &anoncreds::presentationRequestFromJson)); fMap.insert(std::make_tuple("credentialOfferFromJson", &anoncreds::credentialOfferFromJson)); - fMap.insert(std::make_tuple("w3cCredentialOfferFromJson", - &anoncreds::w3cCredentialOfferFromJson)); fMap.insert(std::make_tuple("schemaFromJson", &anoncreds::schemaFromJson)); fMap.insert(std::make_tuple("credentialRequestFromJson", &anoncreds::credentialRequestFromJson)); - fMap.insert(std::make_tuple("w3cCredentialRequestFromJson", - &anoncreds::w3cCredentialRequestFromJson)); fMap.insert(std::make_tuple("credentialRequestMetadataFromJson", &anoncreds::credentialRequestMetadataFromJson)); fMap.insert( std::make_tuple("credentialFromJson", &anoncreds::credentialFromJson)); - fMap.insert( - std::make_tuple("w3cCredentialFromJson", &anoncreds::w3cCredentialFromJson)); fMap.insert( std::make_tuple("revocationRegistryDefinitionPrivateFromJson", &anoncreds::revocationRegistryDefinitionPrivateFromJson)); @@ -110,20 +88,19 @@ fMap.insert(std::make_tuple("createRevocationStatusList", fMap.insert(std::make_tuple("keyCorrectnessProofFromJson", &anoncreds::keyCorrectnessProofFromJson)); fMap.insert( - std::make_tuple("w3cCredentialAddNonAnonCredsIntegrityProof", - &anoncreds::w3cCredentialAddNonAnonCredsIntegrityProof)); + std::make_tuple("createW3cCredential", &anoncreds::createW3cCredential)); fMap.insert( - std::make_tuple("w3cCredentialSetId", - &anoncreds::w3cCredentialSetId)); + std::make_tuple("createW3cPresentation", &anoncreds::createW3cPresentation)); + fMap.insert(std::make_tuple("w3cCredentialGetAttribute", + &anoncreds::w3cCredentialGetAttribute)); fMap.insert( - std::make_tuple("w3cCredentialSetSubjectId", - &anoncreds::w3cCredentialSetSubjectId)); + std::make_tuple("processW3cCredential", &anoncreds::processW3cCredential)); fMap.insert( - std::make_tuple("w3cCredentialAddContext", - &anoncreds::w3cCredentialAddContext)); + std::make_tuple("verifyW3cPresentation", &anoncreds::verifyW3cPresentation)); + fMap.insert(std::make_tuple("w3cPresentationFromJson", + &anoncreds::w3cPresentationFromJson)); fMap.insert( - std::make_tuple("w3cCredentialAddType", - &anoncreds::w3cCredentialAddType)); + std::make_tuple("w3cCredentialFromJson", &anoncreds::w3cCredentialFromJson)); fMap.insert( std::make_tuple("credentialToW3c", &anoncreds::credentialToW3c)); diff --git a/wrappers/javascript/packages/anoncreds-react-native/cpp/anoncreds.cpp b/wrappers/javascript/packages/anoncreds-react-native/cpp/anoncreds.cpp index ac836e7c..deba0aed 100644 --- a/wrappers/javascript/packages/anoncreds-react-native/cpp/anoncreds.cpp +++ b/wrappers/javascript/packages/anoncreds-react-native/cpp/anoncreds.cpp @@ -697,36 +697,6 @@ jsi::Value w3cPresentationFromJson(jsi::Runtime &rt, jsi::Object options) { return returnValue; }; -jsi::Value w3cCredentialOfferFromJson(jsi::Runtime &rt, jsi::Object options) { - auto json = jsiToValue(rt, options, "json"); - - ObjectHandle out; - ByteBuffer b = stringToByteBuffer(json); - - ErrorCode code = anoncreds_credential_offer_from_json(b, &out); - auto returnValue = createReturnValue(rt, code, &out); - - // Free memory - delete[] b.data; - - return returnValue; -}; - -jsi::Value w3cCredentialRequestFromJson(jsi::Runtime &rt, jsi::Object options) { - auto json = jsiToValue(rt, options, "json"); - - ObjectHandle out; - ByteBuffer b = stringToByteBuffer(json); - - ErrorCode code = anoncreds_credential_request_from_json(b, &out); - auto returnValue = createReturnValue(rt, code, &out); - - // Free memory - delete[] b.data; - - return returnValue; -}; - jsi::Value w3cCredentialFromJson(jsi::Runtime &rt, jsi::Object options) { auto json = jsiToValue(rt, options, "json"); @@ -853,43 +823,6 @@ jsi::Value createW3cCredential(jsi::Runtime &rt, jsi::Object options) { return createReturnValue(rt, code, &out); }; -jsi::Value createW3cCredentialOffer(jsi::Runtime &rt, jsi::Object options) { - auto schemaId = jsiToValue(rt, options, "schemaId"); - auto credentialDefinitionId = - jsiToValue(rt, options, "credentialDefinitionId"); - auto keyCorrectnessProof = - jsiToValue(rt, options, "keyCorrectnessProof"); - - ObjectHandle out; - - ErrorCode code = anoncreds_create_w3c_credential_offer( - schemaId.c_str(), credentialDefinitionId.c_str(), keyCorrectnessProof, - &out); - - return createReturnValue(rt, code, &out); -}; - -jsi::Value createW3cCredentialRequest(jsi::Runtime &rt, jsi::Object options) { - auto entropy = jsiToValue(rt, options, "entropy", true); - auto proverDid = jsiToValue(rt, options, "proverDid", true); - auto credentialDefinition = - jsiToValue(rt, options, "credentialDefinition"); - auto linkSecret = jsiToValue(rt, options, "linkSecret"); - auto linkSecretId = jsiToValue(rt, options, "linkSecretId"); - auto credentialOffer = - jsiToValue(rt, options, "credentialOffer"); - - CredentialRequestReturn out; - - ErrorCode code = anoncreds_create_w3c_credential_request( - entropy.length() ? entropy.c_str() : nullptr, - proverDid.length() ? proverDid.c_str() : nullptr, credentialDefinition, - linkSecret.c_str(), linkSecretId.c_str(), credentialOffer, - &out.credentialRequest, &out.credentialRequestMetadata); - - return createReturnValue(rt, code, &out); -}; - jsi::Value w3cCredentialGetAttribute(jsi::Runtime &rt, jsi::Object options) { auto handle = jsiToValue(rt, options, "objectHandle"); auto name = jsiToValue(rt, options, "name"); @@ -921,66 +854,6 @@ jsi::Value processW3cCredential(jsi::Runtime &rt, jsi::Object options) { return createReturnValue(rt, code, &out); }; -jsi::Value w3cCredentialAddNonAnonCredsIntegrityProof(jsi::Runtime &rt, jsi::Object options) { - auto credential = jsiToValue(rt, options, "objectHandle"); - auto proof = jsiToValue(rt, options, "proof"); - - ObjectHandle out; - - ErrorCode code = anoncreds_w3c_credential_add_non_anoncreds_integrity_proof( - credential, proof.c_str(), &out); - - return createReturnValue(rt, code, &out); -}; - -jsi::Value w3cCredentialSetId(jsi::Runtime &rt, jsi::Object options) { - auto credential = jsiToValue(rt, options, "objectHandle"); - auto id = jsiToValue(rt, options, "id"); - - ObjectHandle out; - - ErrorCode code = anoncreds_w3c_credential_set_id( - credential, id.c_str(), &out); - - return createReturnValue(rt, code, &out); -}; - -jsi::Value w3cCredentialSetSubjectId(jsi::Runtime &rt, jsi::Object options) { - auto credential = jsiToValue(rt, options, "objectHandle"); - auto id = jsiToValue(rt, options, "id"); - - ObjectHandle out; - - ErrorCode code = anoncreds_w3c_credential_set_subject_id( - credential, id.c_str(), &out); - - return createReturnValue(rt, code, &out); -}; - -jsi::Value w3cCredentialAddContext(jsi::Runtime &rt, jsi::Object options) { - auto credential = jsiToValue(rt, options, "objectHandle"); - auto context = jsiToValue(rt, options, "context"); - - ObjectHandle out; - - ErrorCode code = anoncreds_w3c_credential_add_context( - credential, context.c_str(), &out); - - return createReturnValue(rt, code, &out); -}; - -jsi::Value w3cCredentialAddType(jsi::Runtime &rt, jsi::Object options) { - auto credential = jsiToValue(rt, options, "objectHandle"); - auto type = jsiToValue(rt, options, "type"); - - ObjectHandle out; - - ErrorCode code = anoncreds_w3c_credential_add_type( - credential, type.c_str(), &out); - - return createReturnValue(rt, code, &out); -}; - jsi::Value credentialToW3c(jsi::Runtime &rt, jsi::Object options) { auto credential = jsiToValue(rt, options, "objectHandle"); auto credentialDefinition = diff --git a/wrappers/javascript/packages/anoncreds-react-native/cpp/anoncreds.h b/wrappers/javascript/packages/anoncreds-react-native/cpp/anoncreds.h index 919dce35..377fb9a7 100644 --- a/wrappers/javascript/packages/anoncreds-react-native/cpp/anoncreds.h +++ b/wrappers/javascript/packages/anoncreds-react-native/cpp/anoncreds.h @@ -20,11 +20,6 @@ struct CredentialRequestReturn { ObjectHandle credentialRequestMetadata; }; -struct W3cCredentialRequestReturn { - ObjectHandle credentialRequest; - ObjectHandle credentialRequestMetadata; -}; - struct RevocationRegistryDefinitionReturn { ObjectHandle revocationRegistryDefinition; ObjectHandle revocationRegistryDefinitionPrivate; @@ -66,8 +61,6 @@ jsi::Value credentialDefinitionFromJson(jsi::Runtime &rt, jsi::Object options); jsi::Value credentialDefinitionPrivateFromJson(jsi::Runtime &rt, jsi::Object options); jsi::Value keyCorrectnessProofFromJson(jsi::Runtime &rt, jsi::Object options); -jsi::Value w3cCredentialOfferFromJson(jsi::Runtime &rt, jsi::Object options); -jsi::Value w3cCredentialRequestFromJson(jsi::Runtime &rt, jsi::Object options); jsi::Value w3cCredentialFromJson(jsi::Runtime &rt, jsi::Object options); jsi::Value w3cPresentationFromJson(jsi::Runtime &rt, jsi::Object options); @@ -86,15 +79,8 @@ jsi::Value encodeCredentialAttributes(jsi::Runtime &rt, jsi::Object options); jsi::Value processCredential(jsi::Runtime &rt, jsi::Object options); jsi::Value createW3cCredential(jsi::Runtime &rt, jsi::Object options); -jsi::Value createW3cCredentialOffer(jsi::Runtime &rt, jsi::Object options); -jsi::Value createW3cCredentialRequest(jsi::Runtime &rt, jsi::Object options); jsi::Value w3cCredentialGetAttribute(jsi::Runtime &rt, jsi::Object options); jsi::Value processW3cCredential(jsi::Runtime &rt, jsi::Object options); -jsi::Value w3cCredentialAddNonAnonCredsIntegrityProof(jsi::Runtime &rt, jsi::Object options); -jsi::Value w3cCredentialSetId(jsi::Runtime &rt, jsi::Object options); -jsi::Value w3cCredentialSetSubjectId(jsi::Runtime &rt, jsi::Object options); -jsi::Value w3cCredentialAddContext(jsi::Runtime &rt, jsi::Object options); -jsi::Value w3cCredentialAddType(jsi::Runtime &rt, jsi::Object options); jsi::Value credentialToW3c(jsi::Runtime &rt, jsi::Object options); jsi::Value credentialFromW3c(jsi::Runtime &rt, jsi::Object options); diff --git a/wrappers/javascript/packages/anoncreds-react-native/cpp/include/libanoncreds.h b/wrappers/javascript/packages/anoncreds-react-native/cpp/include/libanoncreds.h index 26129996..ca6f71eb 100644 --- a/wrappers/javascript/packages/anoncreds-react-native/cpp/include/libanoncreds.h +++ b/wrappers/javascript/packages/anoncreds-react-native/cpp/include/libanoncreds.h @@ -440,6 +440,50 @@ ErrorCode anoncreds_verify_presentation(ObjectHandle presentation, struct FfiList_FfiNonrevokedIntervalOverride nonrevoked_interval_override, int8_t *result_p); +ErrorCode anoncreds_process_w3c_credential(ObjectHandle cred, + ObjectHandle cred_req_metadata, + FfiStr link_secret, + ObjectHandle cred_def, + ObjectHandle rev_reg_def, + ObjectHandle *cred_p); + +ErrorCode anoncreds_credential_to_w3c(ObjectHandle cred, + ObjectHandle cred_def, + ObjectHandle *cred_p); + +ErrorCode anoncreds_credential_from_w3c(ObjectHandle cred, + ObjectHandle *cred_p); + +ErrorCode anoncreds_create_w3c_presentation(ObjectHandle pres_req, + struct FfiList_FfiCredentialEntry credentials, + struct FfiList_FfiCredentialProve credentials_prove, + FfiStr link_secret, + struct FfiList_ObjectHandle schemas, + FfiStrList schema_ids, + struct FfiList_ObjectHandle cred_defs, + FfiStrList cred_def_ids, + ObjectHandle *presentation_p); + +ErrorCode anoncreds_verify_w3c_presentation(ObjectHandle presentation, + ObjectHandle pres_req, + struct FfiList_ObjectHandle schemas, + FfiStrList schema_ids, + struct FfiList_ObjectHandle cred_defs, + FfiStrList cred_def_ids, + struct FfiList_ObjectHandle rev_reg_defs, + FfiStrList rev_reg_def_ids, + struct FfiList_ObjectHandle rev_status_list, + struct FfiList_FfiNonrevokedIntervalOverride nonrevoked_interval_override, + int8_t *result_p); + +ErrorCode anoncreds_w3c_credential_from_json(struct ByteBuffer json, ObjectHandle *result_p); + +ErrorCode anoncreds_w3c_credential_get_attribute(ObjectHandle handle, + FfiStr name, + const char **result_p); + +ErrorCode anoncreds_w3c_presentation_from_json(struct ByteBuffer json, ObjectHandle *result_p); + char *anoncreds_version(void); #ifdef __cplusplus diff --git a/wrappers/javascript/packages/anoncreds-react-native/src/NativeBindings.ts b/wrappers/javascript/packages/anoncreds-react-native/src/NativeBindings.ts index e2663168..67f8b9ac 100644 --- a/wrappers/javascript/packages/anoncreds-react-native/src/NativeBindings.ts +++ b/wrappers/javascript/packages/anoncreds-react-native/src/NativeBindings.ts @@ -186,21 +186,6 @@ export type NativeBindings = { keyCorrectnessProofFromJson(options: { json: string }): ReturnObject - createW3cCredentialOffer(options: { - schemaId: string - credentialDefinitionId: string - keyCorrectnessProof: number - }): ReturnObject - - createW3cCredentialRequest(options: { - entropy?: string - proverDid?: string - credentialDefinition: number - linkSecret: string - linkSecretId: string - credentialOffer: number - }): ReturnObject<{ credentialRequest: Handle; credentialRequestMetadata: Handle }> - createW3cCredential(options: { credentialDefinition: number credentialDefinitionPrivate: number @@ -227,16 +212,6 @@ export type NativeBindings = { w3cCredentialGetAttribute(options: { objectHandle: number; name: string }): ReturnObject - w3cCredentialAddNonAnonCredsIntegrityProof(options: { objectHandle: number; proof: string }): ReturnObject - - w3cCredentialSetId(options: { objectHandle: number; id: string }): ReturnObject - - w3cCredentialSetSubjectId(options: { objectHandle: number; id: string }): ReturnObject - - w3cCredentialAddContext(options: { objectHandle: number; context: string }): ReturnObject - - w3cCredentialAddType(options: { objectHandle: number; type: string }): ReturnObject - credentialToW3c(options: { objectHandle: number; credentialDefinition: number }): ReturnObject credentialFromW3c(options: { objectHandle: number }): ReturnObject @@ -265,10 +240,6 @@ export type NativeBindings = { nonRevokedIntervalOverrides?: NativeNonRevokedIntervalOverride[] }): ReturnObject - w3cCredentialOfferFromJson(options: { json: string }): ReturnObject - - w3cCredentialRequestFromJson(options: { json: string }): ReturnObject - w3cCredentialFromJson(options: { json: string }): ReturnObject w3cPresentationFromJson(options: { json: string }): ReturnObject diff --git a/wrappers/javascript/packages/anoncreds-react-native/src/ReactNativeAnoncreds.ts b/wrappers/javascript/packages/anoncreds-react-native/src/ReactNativeAnoncreds.ts index 0c3855f6..92a928bf 100644 --- a/wrappers/javascript/packages/anoncreds-react-native/src/ReactNativeAnoncreds.ts +++ b/wrappers/javascript/packages/anoncreds-react-native/src/ReactNativeAnoncreds.ts @@ -441,33 +441,6 @@ export class ReactNativeAnoncreds implements Anoncreds { return new ObjectHandle(handle) } - public createW3cCredentialOffer(options: { - schemaId: string - credentialDefinitionId: string - keyCorrectnessProof: ObjectHandle - }): ObjectHandle { - const handle = this.handleError(this.anoncreds.createW3cCredentialOffer(serializeArguments(options))) - return new ObjectHandle(handle) - } - - public createW3cCredentialRequest(options: { - entropy?: string - proverDid?: string - credentialDefinition: ObjectHandle - linkSecret: string - linkSecretId: string - credentialOffer: ObjectHandle - }): { credentialRequest: ObjectHandle; credentialRequestMetadata: ObjectHandle } { - const { credentialRequest, credentialRequestMetadata } = this.handleError( - this.anoncreds.createW3cCredentialRequest(serializeArguments(options)) - ) - - return { - credentialRequestMetadata: new ObjectHandle(credentialRequestMetadata), - credentialRequest: new ObjectHandle(credentialRequest) - } - } - public createW3cPresentation(options: { presentationRequest: ObjectHandle credentials: NativeCredentialEntry[] @@ -526,51 +499,11 @@ export class ReactNativeAnoncreds implements Anoncreds { return new ObjectHandle(handle) } - public w3cCredentialOfferFromJson(options: { json: string }): ObjectHandle { - const handle = this.handleError(this.anoncreds.w3cCredentialOfferFromJson(serializeArguments(options))) - return new ObjectHandle(handle) - } - - public w3cCredentialRequestFromJson(options: { json: string }): ObjectHandle { - const handle = this.handleError(this.anoncreds.w3cCredentialRequestFromJson(serializeArguments(options))) - return new ObjectHandle(handle) - } - public w3cCredentialFromJson(options: { json: string }): ObjectHandle { const handle = this.handleError(this.anoncreds.w3cCredentialFromJson(serializeArguments(options))) return new ObjectHandle(handle) } - public w3cCredentialAddNonAnonCredsIntegrityProof(options: { - objectHandle: ObjectHandle - proof: string - }): ObjectHandle { - const handle = this.handleError( - this.anoncreds.w3cCredentialAddNonAnonCredsIntegrityProof(serializeArguments(options)) - ) - return new ObjectHandle(handle) - } - - public w3cCredentialSetId(options: { objectHandle: ObjectHandle; id: string }): ObjectHandle { - const handle = this.handleError(this.anoncreds.w3cCredentialSetId(serializeArguments(options))) - return new ObjectHandle(handle) - } - - public w3cCredentialSetSubjectId(options: { objectHandle: ObjectHandle; id: string }): ObjectHandle { - const handle = this.handleError(this.anoncreds.w3cCredentialSetSubjectId(serializeArguments(options))) - return new ObjectHandle(handle) - } - - public w3cCredentialAddContext(options: { objectHandle: ObjectHandle; context: string }): ObjectHandle { - const handle = this.handleError(this.anoncreds.w3cCredentialAddContext(serializeArguments(options))) - return new ObjectHandle(handle) - } - - public w3cCredentialAddType(options: { objectHandle: ObjectHandle; type: string }): ObjectHandle { - const handle = this.handleError(this.anoncreds.w3cCredentialAddType(serializeArguments(options))) - return new ObjectHandle(handle) - } - public credentialToW3c(options: { objectHandle: ObjectHandle; credentialDefinition: ObjectHandle }): 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 6b922e43..0853e839 100644 --- a/wrappers/javascript/packages/anoncreds-shared/src/Anoncreds.ts +++ b/wrappers/javascript/packages/anoncreds-shared/src/Anoncreds.ts @@ -205,21 +205,6 @@ export type Anoncreds = { objectFree(options: { objectHandle: ObjectHandle }): void - createW3cCredentialOffer(options: { - schemaId: string - credentialDefinitionId: string - keyCorrectnessProof: ObjectHandle - }): ObjectHandle - - createW3cCredentialRequest(options: { - entropy?: string - proverDid?: string - credentialDefinition: ObjectHandle - linkSecret: string - linkSecretId: string - credentialOffer: ObjectHandle - }): { credentialRequest: ObjectHandle; credentialRequestMetadata: ObjectHandle } - createW3cCredential(options: { credentialDefinition: ObjectHandle credentialDefinitionPrivate: ObjectHandle @@ -262,22 +247,8 @@ export type Anoncreds = { w3cPresentationFromJson(options: { json: string }): ObjectHandle - w3cCredentialAddNonAnonCredsIntegrityProof(options: { objectHandle: ObjectHandle; proof: string }): ObjectHandle - - w3cCredentialSetId(options: { objectHandle: ObjectHandle; id: string }): ObjectHandle - - w3cCredentialSetSubjectId(options: { objectHandle: ObjectHandle; id: string }): ObjectHandle - - w3cCredentialAddContext(options: { objectHandle: ObjectHandle; context: string }): ObjectHandle - - w3cCredentialAddType(options: { objectHandle: ObjectHandle; type: string }): ObjectHandle - w3cCredentialGetAttribute(options: { objectHandle: ObjectHandle; name: string }): string - w3cCredentialOfferFromJson(options: { json: string }): ObjectHandle - - w3cCredentialRequestFromJson(options: { json: string }): ObjectHandle - w3cCredentialFromJson(options: { json: string }): ObjectHandle credentialToW3c(options: { objectHandle: ObjectHandle; credentialDefinition: ObjectHandle }): ObjectHandle diff --git a/wrappers/javascript/packages/anoncreds-shared/src/api/W3cCredential.ts b/wrappers/javascript/packages/anoncreds-shared/src/api/W3cCredential.ts index e922432d..84c4f579 100644 --- a/wrappers/javascript/packages/anoncreds-shared/src/api/W3cCredential.ts +++ b/wrappers/javascript/packages/anoncreds-shared/src/api/W3cCredential.ts @@ -9,17 +9,17 @@ import { anoncreds } from '../register' import { Credential } from './Credential' import { CredentialDefinition } from './CredentialDefinition' import { CredentialDefinitionPrivate } from './CredentialDefinitionPrivate' +import { CredentialOffer } from './CredentialOffer' +import { CredentialRequest } from './CredentialRequest' import { CredentialRequestMetadata } from './CredentialRequestMetadata' import { RevocationRegistryDefinition } from './RevocationRegistryDefinition' -import { W3cCredentialOffer } from './W3cCredentialOffer' -import { W3cCredentialRequest } from './W3cCredentialRequest' import { pushToArray } from './utils' export type CreateW3cCredentialOptions = { credentialDefinition: CredentialDefinition | JsonObject credentialDefinitionPrivate: CredentialDefinitionPrivate | JsonObject - credentialOffer: W3cCredentialOffer | JsonObject - credentialRequest: W3cCredentialRequest | JsonObject + credentialOffer: CredentialOffer | JsonObject + credentialRequest: CredentialRequest | JsonObject attributeRawValues: Record revocationRegistryId?: string revocationConfiguration?: CredentialRevocationConfig @@ -56,14 +56,14 @@ export class W3cCredential extends AnoncredsObject { : pushToArray(CredentialDefinitionPrivate.fromJson(options.credentialDefinitionPrivate).handle, objectHandles) const credentialOffer = - options.credentialOffer instanceof W3cCredentialOffer + options.credentialOffer instanceof CredentialOffer ? options.credentialOffer.handle - : pushToArray(W3cCredentialOffer.fromJson(options.credentialOffer).handle, objectHandles) + : pushToArray(CredentialOffer.fromJson(options.credentialOffer).handle, objectHandles) const credentialRequest = - options.credentialRequest instanceof W3cCredentialRequest + options.credentialRequest instanceof CredentialRequest ? options.credentialRequest.handle - : pushToArray(W3cCredentialRequest.fromJson(options.credentialRequest).handle, objectHandles) + : pushToArray(CredentialRequest.fromJson(options.credentialRequest).handle, objectHandles) credential = anoncreds.createW3cCredential({ credentialDefinition, @@ -178,54 +178,4 @@ export class W3cCredential extends AnoncredsObject { } return credential } - - public addNonAnonCredsIntegrityProof(proof: JsonObject) { - const credential = anoncreds.w3cCredentialAddNonAnonCredsIntegrityProof({ - objectHandle: this.handle, - proof: JSON.stringify(proof) - }) - - this.handle.clear() - this.handle = credential - } - - public setId(id: string) { - const credential = anoncreds.w3cCredentialSetId({ - objectHandle: this.handle, - id - }) - - this.handle.clear() - this.handle = credential - } - - public setSubjectId(id: string) { - const credential = anoncreds.w3cCredentialSetSubjectId({ - objectHandle: this.handle, - id - }) - - this.handle.clear() - this.handle = credential - } - - public addContext(context: string) { - const credential = anoncreds.w3cCredentialAddContext({ - objectHandle: this.handle, - context - }) - - this.handle.clear() - this.handle = credential - } - - public addType(type: string) { - const credential = anoncreds.w3cCredentialAddType({ - objectHandle: this.handle, - type - }) - - this.handle.clear() - this.handle = credential - } } diff --git a/wrappers/javascript/packages/anoncreds-shared/src/api/W3cCredentialOffer.ts b/wrappers/javascript/packages/anoncreds-shared/src/api/W3cCredentialOffer.ts deleted file mode 100644 index 7db405fb..00000000 --- a/wrappers/javascript/packages/anoncreds-shared/src/api/W3cCredentialOffer.ts +++ /dev/null @@ -1,43 +0,0 @@ -import type { ObjectHandle } from '../ObjectHandle' -import type { JsonObject } from '../types' - -import { AnoncredsObject } from '../AnoncredsObject' -import { anoncreds } from '../register' - -import { KeyCorrectnessProof } from './KeyCorrectnessProof' -import { pushToArray } from './utils' - -export type CreateW3cCredentialOfferOptions = { - schemaId: string - credentialDefinitionId: string - keyCorrectnessProof: KeyCorrectnessProof | JsonObject -} - -export class W3cCredentialOffer extends AnoncredsObject { - public static create(options: CreateW3cCredentialOfferOptions) { - let credentialOfferHandle - // Objects created within this method must be freed up - const objectHandles: ObjectHandle[] = [] - try { - const keyCorrectnessProof = - options.keyCorrectnessProof instanceof KeyCorrectnessProof - ? options.keyCorrectnessProof.handle - : pushToArray(KeyCorrectnessProof.fromJson(options.keyCorrectnessProof).handle, objectHandles) - - credentialOfferHandle = anoncreds.createW3cCredentialOffer({ - schemaId: options.schemaId, - credentialDefinitionId: options.credentialDefinitionId, - keyCorrectnessProof - }).handle - } finally { - objectHandles.forEach((handle) => { - handle.clear() - }) - } - return new W3cCredentialOffer(credentialOfferHandle) - } - - public static fromJson(json: JsonObject) { - return new W3cCredentialOffer(anoncreds.w3cCredentialOfferFromJson({ json: JSON.stringify(json) }).handle) - } -} diff --git a/wrappers/javascript/packages/anoncreds-shared/src/api/W3cCredentialRequest.ts b/wrappers/javascript/packages/anoncreds-shared/src/api/W3cCredentialRequest.ts deleted file mode 100644 index b2d6fb8b..00000000 --- a/wrappers/javascript/packages/anoncreds-shared/src/api/W3cCredentialRequest.ts +++ /dev/null @@ -1,62 +0,0 @@ -import type { ObjectHandle } from '../ObjectHandle' -import type { JsonObject } from '../types' - -import { AnoncredsObject } from '../AnoncredsObject' -import { anoncreds } from '../register' - -import { CredentialDefinition } from './CredentialDefinition' -import { CredentialRequestMetadata } from './CredentialRequestMetadata' -import { W3cCredentialOffer } from './W3cCredentialOffer' -import { pushToArray } from './utils' - -export type CreateW3cCredentialRequestOptions = { - entropy?: string - proverDid?: string - credentialDefinition: CredentialDefinition | JsonObject - linkSecret: string - linkSecretId: string - credentialOffer: W3cCredentialOffer | JsonObject -} - -export class W3cCredentialRequest extends AnoncredsObject { - public static create(options: CreateW3cCredentialRequestOptions) { - let createReturnObj: { - credentialRequest: ObjectHandle - credentialRequestMetadata: ObjectHandle - } - // 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) - - const credentialOffer = - options.credentialOffer instanceof W3cCredentialOffer - ? options.credentialOffer.handle - : pushToArray(W3cCredentialOffer.fromJson(options.credentialOffer).handle, objectHandles) - - createReturnObj = anoncreds.createW3cCredentialRequest({ - entropy: options.entropy, - proverDid: options.proverDid, - credentialDefinition, - linkSecret: options.linkSecret, - linkSecretId: options.linkSecretId, - credentialOffer - }) - } finally { - objectHandles.forEach((handle) => { - handle.clear() - }) - } - return { - credentialRequest: new W3cCredentialRequest(createReturnObj.credentialRequest.handle), - credentialRequestMetadata: new CredentialRequestMetadata(createReturnObj.credentialRequestMetadata.handle) - } - } - - public static fromJson(json: JsonObject) { - return new W3cCredentialRequest(anoncreds.w3cCredentialRequestFromJson({ json: JSON.stringify(json) }).handle) - } -} diff --git a/wrappers/javascript/packages/anoncreds-shared/src/api/index.ts b/wrappers/javascript/packages/anoncreds-shared/src/api/index.ts index 6ac21014..f32c0bc4 100644 --- a/wrappers/javascript/packages/anoncreds-shared/src/api/index.ts +++ b/wrappers/javascript/packages/anoncreds-shared/src/api/index.ts @@ -16,6 +16,5 @@ export * from './RevocationRegistryDefinition' export * from './RevocationRegistryDefinitionPrivate' export * from './RevocationStatusList' export * from './W3cCredential' -export * from './W3cCredentialOffer' -export * from './W3cCredentialRequest' +export * from './CredentialOffer' export * from './W3cPresentation' diff --git a/wrappers/python/anoncreds/__init__.py b/wrappers/python/anoncreds/__init__.py index f6f905ea..846a8843 100644 --- a/wrappers/python/anoncreds/__init__.py +++ b/wrappers/python/anoncreds/__init__.py @@ -21,8 +21,6 @@ RevocationStatusList, RevocationRegistryDefinition, RevocationRegistryDefinitionPrivate, - W3cCredentialOffer, - W3cCredentialRequest, W3cCredential, W3cPresentation, ) @@ -52,8 +50,6 @@ "RevocationRegistryDefinition", "RevocationRegistryDefinitionPrivate", "Schema", - "W3cCredentialOffer", - "W3cCredentialRequest", "W3cCredential", "W3cPresentation" ) diff --git a/wrappers/python/anoncreds/bindings.py b/wrappers/python/anoncreds/bindings.py index 4e5de89a..69425639 100644 --- a/wrappers/python/anoncreds/bindings.py +++ b/wrappers/python/anoncreds/bindings.py @@ -966,43 +966,6 @@ def create_or_update_revocation_state( return updated_rev_state -def create_w3c_credential_offer( - schema_id: str, cred_def_id: str, key_proof: ObjectHandle -) -> ObjectHandle: - cred_offer = ObjectHandle() - do_call( - "anoncreds_create_w3c_credential_offer", - encode_str(schema_id), - encode_str(cred_def_id), - key_proof, - byref(cred_offer), - ) - return cred_offer - - -def create_w3c_credential_request( - entropy: Optional[str], - prover_did: Optional[str], - cred_def: ObjectHandle, - link_secret: str, - link_secret_id: str, - cred_offer: ObjectHandle, -) -> Tuple[ObjectHandle, ObjectHandle]: - cred_req, cred_req_metadata = ObjectHandle(), ObjectHandle() - do_call( - "anoncreds_create_w3c_credential_request", - encode_str(entropy), - encode_str(prover_did), - cred_def, - encode_str(link_secret), - encode_str(link_secret_id), - cred_offer, - byref(cred_req), - byref(cred_req_metadata), - ) - return (cred_req, cred_req_metadata) - - def create_w3c_credential( cred_def: ObjectHandle, cred_def_private: ObjectHandle, @@ -1079,76 +1042,6 @@ def credential_from_w3c( return result -def w3c_credential_add_non_anoncreds_integrity_proof( - cred: ObjectHandle, - proof: str, -) -> ObjectHandle: - result = ObjectHandle() - do_call( - "anoncreds_w3c_credential_add_non_anoncreds_integrity_proof", - cred, - encode_str(proof), - byref(result), - ) - return result - - -def w3c_credential_set_id( - cred: ObjectHandle, - id: str, -) -> ObjectHandle: - result = ObjectHandle() - do_call( - "anoncreds_w3c_credential_set_id", - cred, - encode_str(id), - byref(result), - ) - return result - - -def w3c_credential_set_subject_id( - cred: ObjectHandle, - id: str, -) -> ObjectHandle: - result = ObjectHandle() - do_call( - "anoncreds_w3c_credential_set_subject_id", - cred, - encode_str(id), - byref(result), - ) - return result - - -def w3c_credential_add_context( - cred: ObjectHandle, - context: str, -) -> ObjectHandle: - result = ObjectHandle() - do_call( - "anoncreds_w3c_credential_add_context", - cred, - encode_str(context), - byref(result), - ) - return result - - -def w3c_credential_add_type( - cred: ObjectHandle, - type_: str, -) -> ObjectHandle: - result = ObjectHandle() - do_call( - "anoncreds_w3c_credential_add_type", - cred, - encode_str(type_), - byref(result), - ) - return result - - def create_w3c_presentation( pres_req: ObjectHandle, credentials: Sequence[CredentialEntry], diff --git a/wrappers/python/anoncreds/types.py b/wrappers/python/anoncreds/types.py index 596748b9..48e830dd 100644 --- a/wrappers/python/anoncreds/types.py +++ b/wrappers/python/anoncreds/types.py @@ -103,27 +103,6 @@ def load(cls, value: Union[dict, str, bytes, memoryview]) -> "CredentialOffer": ) -class W3cCredentialOffer(bindings.AnoncredsObject): - @classmethod - def create( - cls, - schema_id: str, - cred_def_id: str, - key_proof: Union[str, KeyCorrectnessProof], - ) -> "W3cCredentialOffer": - if not isinstance(key_proof, bindings.AnoncredsObject): - key_proof = KeyCorrectnessProof.load(key_proof) - return W3cCredentialOffer( - bindings.create_w3c_credential_offer(schema_id, cred_def_id, key_proof.handle) - ) - - @classmethod - def load(cls, value: Union[dict, str, bytes, memoryview]) -> "W3cCredentialOffer": - return W3cCredentialOffer( - bindings._object_from_json("anoncreds_credential_offer_from_json", value) - ) - - class CredentialRequest(bindings.AnoncredsObject): @classmethod def create( @@ -158,41 +137,6 @@ def load(cls, value: Union[dict, str, bytes, memoryview]) -> "CredentialRequest" ) - -class W3cCredentialRequest(bindings.AnoncredsObject): - @classmethod - def create( - cls, - entropy: Optional[str], - prover_did: Optional[str], - cred_def: Union[str, CredentialDefinition], - link_secret: str, - link_secret_id: str, - cred_offer: Union[str, W3cCredentialOffer], - ) -> Tuple["W3cCredentialRequest", "CredentialRequestMetadata"]: - if not isinstance(cred_def, bindings.AnoncredsObject): - cred_def = CredentialDefinition.load(cred_def) - if not isinstance(cred_offer, bindings.AnoncredsObject): - cred_offer = W3cCredentialOffer.load(cred_offer) - cred_def_handle, cred_def_metadata = bindings.create_w3c_credential_request( - entropy, - prover_did, - cred_def.handle, - link_secret, - link_secret_id, - cred_offer.handle, - ) - return W3cCredentialRequest(cred_def_handle), CredentialRequestMetadata( - cred_def_metadata - ) - - @classmethod - def load(cls, value: Union[dict, str, bytes, memoryview]) -> "W3cCredentialRequest": - return W3cCredentialRequest( - bindings._object_from_json("anoncreds_credential_request_from_json", value) - ) - - class CredentialRequestMetadata(bindings.AnoncredsObject): @classmethod def load( @@ -429,8 +373,8 @@ def create( cls, cred_def: Union[str, CredentialDefinition], cred_def_private: Union[str, CredentialDefinitionPrivate], - cred_offer: Union[str, W3cCredentialOffer], - cred_request: Union[str, W3cCredentialRequest], + cred_offer: Union[str, CredentialOffer], + cred_request: Union[str, CredentialRequest], attr_raw_values: Mapping[str, str], revocation_config: Optional["CredentialRevocationConfig"] = None, encoding: Optional[str] = None, @@ -440,9 +384,9 @@ def create( if not isinstance(cred_def_private, bindings.AnoncredsObject): cred_def_private = CredentialDefinitionPrivate.load(cred_def_private) if not isinstance(cred_offer, bindings.AnoncredsObject): - cred_offer = W3cCredentialOffer.load(cred_offer) + cred_offer = CredentialOffer.load(cred_offer) if not isinstance(cred_request, bindings.AnoncredsObject): - cred_request = W3cCredentialRequest.load(cred_request) + cred_request = CredentialRequest.load(cred_request) cred = bindings.create_w3c_credential( cred_def.handle, cred_def_private.handle, @@ -531,53 +475,6 @@ def to_legacy( def from_legacy(cls, cred: "Credential", cred_def: Union[str, CredentialDefinition]) -> "W3cCredential": return cred.to_w3c(cred_def) - def add_non_anoncreds_integrity_proof( - self, - proof: Union[str, dict] - ) -> "W3cCredential": - if isinstance(proof, dict): - proof = json.dumps(proof) - self.handle = bindings.w3c_credential_add_non_anoncreds_integrity_proof( - self.handle, - proof, - ) - - def set_id( - self, - id: str - ) -> "W3cCredential": - self.handle = bindings.w3c_credential_set_id( - self.handle, - id, - ) - - def set_subject_id( - self, - id: str - ) -> "W3cCredential": - self.handle = bindings.w3c_credential_set_subject_id( - self.handle, - id, - ) - - def add_context( - self, - context: str - ) -> "W3cCredential": - self.handle = bindings.w3c_credential_add_context( - self.handle, - context, - ) - - def add_type( - self, - type: str - ) -> "W3cCredential": - self.handle = bindings.w3c_credential_add_type( - self.handle, - type, - ) - class PresentationRequest(bindings.AnoncredsObject): @classmethod diff --git a/wrappers/python/demo/w3c_test.py b/wrappers/python/demo/w3c_test.py index 977cc247..f3728a43 100644 --- a/wrappers/python/demo/w3c_test.py +++ b/wrappers/python/demo/w3c_test.py @@ -4,8 +4,8 @@ Credential, W3cCredential, CredentialDefinition, - W3cCredentialOffer, - W3cCredentialRequest, + CredentialOffer, + CredentialRequest, CredentialRevocationConfig, CredentialRevocationState, PresentationRequest, @@ -50,9 +50,9 @@ link_secret = create_link_secret() link_secret_id = "default" -cred_offer = W3cCredentialOffer.create(schema_id, cred_def_id, cred_def_correctness) +cred_offer = CredentialOffer.create(schema_id, cred_def_id, cred_def_correctness) -cred_request, cred_request_metadata = W3cCredentialRequest.create( +cred_request, cred_request_metadata = CredentialRequest.create( entropy, None, cred_def_pub, link_secret, link_secret_id, cred_offer ) @@ -94,22 +94,6 @@ print("W3C restored Credential `from_legacy`") print(w3c_cred_restored.to_json()) - -w3c_cred_restored.add_non_anoncreds_integrity_proof({ - "type": "Ed25519Signature2020", - "created": "2021-11-13T18:19:39Z", - "verificationMethod": "did:sov:3avoBCqDMFHFaKUHug9s8W#key-1", - "proofPurpose": "assertionMethod", - "proofValue": "z58DAdFfa9SkqZMVPxAQpic7ndSayn1PzZs6ZjWp1CktyGesjuTSwRdoWhAfGFCF5bppETSTojQCrfFPP2oumHKtz" -}) -w3c_cred_restored.set_id("http://example.com/credentials/3732") -w3c_cred_restored.set_subject_id("did:example:ebfeb1f712ebc6f1c276e12ec21") -w3c_cred_restored.add_context("https://www.w3.org/2018/credentials/examples/v1") -w3c_cred_restored.add_type("UniversityDegreeCredential") - -print("W3C extended Credential") -print(w3c_cred_restored.to_json()) - time_after_creating_cred = time_create_rev_status_list + 1 issued_rev_status_list = revocation_status_list.update( cred_def_pub, From 3e1f1848eaa46b4aed2bc680aa51bc7727f2b442 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Tue, 12 Dec 2023 09:39:45 +0300 Subject: [PATCH 13/21] Added convert helper in node package Signed-off-by: artem.ivanov --- .../anoncreds-nodejs/src/NodeJSAnoncreds.ts | 364 ++++++++---------- .../src/ReactNativeAnoncreds.ts | 4 - 2 files changed, 155 insertions(+), 213 deletions(-) diff --git a/wrappers/javascript/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts b/wrappers/javascript/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts index 136f25a3..c6735945 100644 --- a/wrappers/javascript/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts +++ b/wrappers/javascript/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts @@ -162,35 +162,10 @@ export class NodeJSAnoncreds implements Anoncreds { const { credentialDefinition, credentialDefinitionPrivate, credentialOffer, credentialRequest } = serializeArguments(options) - const attributeNames = StringListStruct({ - count: Object.keys(options.attributeRawValues).length, - data: Object.keys(options.attributeRawValues) as unknown as TypedArray - }) - - const attributeRawValues = StringListStruct({ - count: Object.keys(options.attributeRawValues).length, - data: Object.values(options.attributeRawValues) as unknown as TypedArray - }) - - const attributeEncodedValues = options.attributeEncodedValues - ? StringListStruct({ - count: Object.keys(options.attributeEncodedValues).length, - data: Object.values(options.attributeEncodedValues) as unknown as TypedArray - }) - : undefined - - let revocationConfiguration - if (options.revocationConfiguration) { - const { revocationRegistryDefinition, revocationRegistryDefinitionPrivate, revocationStatusList, registryIndex } = - serializeArguments(options.revocationConfiguration) - - revocationConfiguration = CredRevInfoStruct({ - reg_def: revocationRegistryDefinition, - reg_def_private: revocationRegistryDefinitionPrivate, - status_list: revocationStatusList, - reg_idx: registryIndex - }) - } + const attributeNames = this.convertAttributeNames(options.attributeRawValues) + const attributeRawValues = this.convertAttributeRawValues(options.attributeRawValues) + const attributeEncodedValues = this.convertAttributeEncodedValues(options.attributeEncodedValues) + const revocationConfiguration = this.convertRevocationConfiguration(options.revocationConfiguration) const credentialPtr = allocatePointer() this.nativeAnoncreds.anoncreds_create_credential( @@ -312,42 +287,6 @@ export class NodeJSAnoncreds implements Anoncreds { }): ObjectHandle { const { presentationRequest, linkSecret } = serializeArguments(options) - const credentialEntries = options.credentials.map((value) => - CredentialEntryStruct({ - credential: value.credential.handle, - timestamp: value.timestamp ?? -1, - rev_state: value.revocationState?.handle ?? 0 - }) - ) - - const credentialEntryList = CredentialEntryListStruct({ - count: credentialEntries.length, - data: credentialEntries as unknown as TypedArray< - StructObject<{ - credential: number - timestamp: number - rev_state: number - }> - > - }) - - const credentialProves = options.credentialsProve.map((value) => { - const { entryIndex: entry_idx, isPredicate: is_predicate, reveal, referent } = serializeArguments(value) - return CredentialProveStruct({ entry_idx, referent, is_predicate, reveal }) - }) - - const credentialProveList = CredentialProveListStruct({ - count: credentialProves.length, - data: credentialProves as unknown as TypedArray< - StructObject<{ - entry_idx: string | number - referent: string - is_predicate: number - reveal: number - }> - > - }) - const selfAttestNames = StringListStruct({ count: Object.keys(options.selfAttest).length, data: Object.keys(options.selfAttest) as unknown as TypedArray @@ -358,29 +297,10 @@ export class NodeJSAnoncreds implements Anoncreds { data: Object.values(options.selfAttest) as unknown as TypedArray }) - const schemaKeys = Object.keys(options.schemas) - const schemaIds = StringListStruct({ - count: schemaKeys.length, - data: schemaKeys as unknown as TypedArray - }) - - const schemaValues = Object.values(options.schemas) - const schemas = ObjectHandleListStruct({ - count: schemaValues.length, - data: ObjectHandleArray(schemaValues.map((o) => o.handle)) - }) - - const credentialDefinitionKeys = Object.keys(options.credentialDefinitions) - const credentialDefinitionIds = StringListStruct({ - count: credentialDefinitionKeys.length, - data: credentialDefinitionKeys as unknown as TypedArray - }) - - const credentialDefinitionValues = Object.values(options.credentialDefinitions) - const credentialDefinitions = ObjectHandleListStruct({ - count: credentialDefinitionValues.length, - data: ObjectHandleArray(credentialDefinitionValues.map((o) => o.handle)) - }) + const credentialEntryList = this.convertCredentialList(options.credentials) + const credentialProveList = this.convertCredentialProves(options.credentialsProve) + const { schemaIds, schemas } = this.convertSchemas(options.schemas) + const { credentialDefinitionIds, credentialDefinitions } = this.convertCredDefs(options.credentialDefinitions) const ret = allocatePointer() @@ -426,26 +346,7 @@ export class NodeJSAnoncreds implements Anoncreds { credentialDefinitionIds } = serializeArguments(options) - const nativeNonRevokedIntervalOverrides = options.nonRevokedIntervalOverrides?.map((value) => { - const { requestedFromTimestamp, revocationRegistryDefinitionId, overrideRevocationStatusListTimestamp } = - serializeArguments(value) - return NonRevokedIntervalOverrideStruct({ - rev_reg_def_id: revocationRegistryDefinitionId, - requested_from_ts: requestedFromTimestamp, - override_rev_status_list_ts: overrideRevocationStatusListTimestamp - }) - }) - - const nonRevokedIntervalOverrideList = NonRevokedIntervalOverrideListStruct({ - count: options.nonRevokedIntervalOverrides?.length ?? 0, - data: nativeNonRevokedIntervalOverrides as unknown as TypedArray< - StructObject<{ - rev_reg_def_id: string - requested_from_ts: number - override_rev_status_list_ts: number - }> - > - }) + const nonRevokedIntervalOverrideList = this.convertNonRevokedIntervalOverrides(options.nonRevokedIntervalOverrides) const ret = allocateInt8Buffer() @@ -639,28 +540,9 @@ export class NodeJSAnoncreds implements Anoncreds { const { credentialDefinition, credentialDefinitionPrivate, credentialOffer, credentialRequest, encoding } = serializeArguments(options) - const attributeNames = StringListStruct({ - count: Object.keys(options.attributeRawValues).length, - data: Object.keys(options.attributeRawValues) as unknown as TypedArray - }) - - const attributeRawValues = StringListStruct({ - count: Object.keys(options.attributeRawValues).length, - data: Object.values(options.attributeRawValues) as unknown as TypedArray - }) - - let revocationConfiguration - if (options.revocationConfiguration) { - const { revocationRegistryDefinition, revocationRegistryDefinitionPrivate, revocationStatusList, registryIndex } = - serializeArguments(options.revocationConfiguration) - - revocationConfiguration = CredRevInfoStruct({ - reg_def: revocationRegistryDefinition, - reg_def_private: revocationRegistryDefinitionPrivate, - status_list: revocationStatusList, - reg_idx: registryIndex - }) - } + const attributeNames = this.convertAttributeNames(options.attributeRawValues) + const attributeRawValues = this.convertAttributeRawValues(options.attributeRawValues) + const revocationConfiguration = this.convertRevocationConfiguration(options.revocationConfiguration) const credentialPtr = allocatePointer() this.nativeAnoncreds.anoncreds_create_w3c_credential( @@ -713,65 +595,10 @@ export class NodeJSAnoncreds implements Anoncreds { }): ObjectHandle { const { presentationRequest, linkSecret } = serializeArguments(options) - const credentialEntries = options.credentials.map((value) => - CredentialEntryStruct({ - credential: value.credential.handle, - timestamp: value.timestamp ?? -1, - rev_state: value.revocationState?.handle ?? 0 - }) - ) - - const credentialEntryList = CredentialEntryListStruct({ - count: credentialEntries.length, - data: credentialEntries as unknown as TypedArray< - StructObject<{ - credential: number - timestamp: number - rev_state: number - }> - > - }) - - const credentialProves = options.credentialsProve.map((value) => { - const { entryIndex: entry_idx, isPredicate: is_predicate, reveal, referent } = serializeArguments(value) - return CredentialProveStruct({ entry_idx, referent, is_predicate, reveal }) - }) - - const credentialProveList = CredentialProveListStruct({ - count: credentialProves.length, - data: credentialProves as unknown as TypedArray< - StructObject<{ - entry_idx: string | number - referent: string - is_predicate: number - reveal: number - }> - > - }) - - const schemaKeys = Object.keys(options.schemas) - const schemaIds = StringListStruct({ - count: schemaKeys.length, - data: schemaKeys as unknown as TypedArray - }) - - const schemaValues = Object.values(options.schemas) - const schemas = ObjectHandleListStruct({ - count: schemaValues.length, - data: ObjectHandleArray(schemaValues.map((o) => o.handle)) - }) - - const credentialDefinitionKeys = Object.keys(options.credentialDefinitions) - const credentialDefinitionIds = StringListStruct({ - count: credentialDefinitionKeys.length, - data: credentialDefinitionKeys as unknown as TypedArray - }) - - const credentialDefinitionValues = Object.values(options.credentialDefinitions) - const credentialDefinitions = ObjectHandleListStruct({ - count: credentialDefinitionValues.length, - data: ObjectHandleArray(credentialDefinitionValues.map((o) => o.handle)) - }) + const credentialEntryList = this.convertCredentialList(options.credentials) + const credentialProveList = this.convertCredentialProves(options.credentialsProve) + const { schemaIds, schemas } = this.convertSchemas(options.schemas) + const { credentialDefinitionIds, credentialDefinitions } = this.convertCredDefs(options.credentialDefinitions) const ret = allocatePointer() @@ -815,26 +642,7 @@ export class NodeJSAnoncreds implements Anoncreds { credentialDefinitionIds } = serializeArguments(options) - const nativeNonRevokedIntervalOverrides = options.nonRevokedIntervalOverrides?.map((value) => { - const { requestedFromTimestamp, revocationRegistryDefinitionId, overrideRevocationStatusListTimestamp } = - serializeArguments(value) - return NonRevokedIntervalOverrideStruct({ - rev_reg_def_id: revocationRegistryDefinitionId, - requested_from_ts: requestedFromTimestamp, - override_rev_status_list_ts: overrideRevocationStatusListTimestamp - }) - }) - - const nonRevokedIntervalOverrideList = NonRevokedIntervalOverrideListStruct({ - count: options.nonRevokedIntervalOverrides?.length ?? 0, - data: nativeNonRevokedIntervalOverrides as unknown as TypedArray< - StructObject<{ - rev_reg_def_id: string - requested_from_ts: number - override_rev_status_list_ts: number - }> - > - }) + const nonRevokedIntervalOverrideList = this.convertNonRevokedIntervalOverrides(options.nonRevokedIntervalOverrides) const ret = allocateInt8Buffer() @@ -1007,4 +815,142 @@ export class NodeJSAnoncreds implements Anoncreds { this.nativeAnoncreds.anoncreds_object_free(options.objectHandle.handle) this.handleError() } + + private convertCredentialList(credentials: NativeCredentialEntry[]) { + const credentialEntries = credentials.map((value) => + CredentialEntryStruct({ + credential: value.credential.handle, + timestamp: value.timestamp ?? -1, + rev_state: value.revocationState?.handle ?? 0 + }) + ) + + return CredentialEntryListStruct({ + count: credentialEntries.length, + data: credentialEntries as unknown as TypedArray< + StructObject<{ + credential: number + timestamp: number + rev_state: number + }> + > + }) + } + + private convertCredentialProves(credentialsProve: NativeCredentialProve[]) { + const credentialProves = credentialsProve.map((value) => { + const { entryIndex: entry_idx, isPredicate: is_predicate, reveal, referent } = serializeArguments(value) + return CredentialProveStruct({ entry_idx, referent, is_predicate, reveal }) + }) + + return CredentialProveListStruct({ + count: credentialProves.length, + data: credentialProves as unknown as TypedArray< + StructObject<{ + entry_idx: string | number + referent: string + is_predicate: number + reveal: number + }> + > + }) + } + + private convertSchemas(schemas: Record) { + const schemaKeys = Object.keys(schemas) + const schemaIds = StringListStruct({ + count: schemaKeys.length, + data: schemaKeys as unknown as TypedArray + }) + + const schemaValues = Object.values(schemas) + const schemasList = ObjectHandleListStruct({ + count: schemaValues.length, + data: ObjectHandleArray(schemaValues.map((o) => o.handle)) + }) + return { + schemaIds, + schemas: schemasList + } + } + + private convertCredDefs(credentialDefinitions: Record) { + const credentialDefinitionKeys = Object.keys(credentialDefinitions) + const credentialDefinitionIds = StringListStruct({ + count: credentialDefinitionKeys.length, + data: credentialDefinitionKeys as unknown as TypedArray + }) + + const credentialDefinitionValues = Object.values(credentialDefinitions) + const credentialDefinitionsList = ObjectHandleListStruct({ + count: credentialDefinitionValues.length, + data: ObjectHandleArray(credentialDefinitionValues.map((o) => o.handle)) + }) + return { + credentialDefinitionIds, + credentialDefinitions: credentialDefinitionsList + } + } + + private convertNonRevokedIntervalOverrides(nonRevokedIntervalOverrides?: NativeNonRevokedIntervalOverride[]) { + const nativeNonRevokedIntervalOverrides = nonRevokedIntervalOverrides?.map((value) => { + const { requestedFromTimestamp, revocationRegistryDefinitionId, overrideRevocationStatusListTimestamp } = + serializeArguments(value) + return NonRevokedIntervalOverrideStruct({ + rev_reg_def_id: revocationRegistryDefinitionId, + requested_from_ts: requestedFromTimestamp, + override_rev_status_list_ts: overrideRevocationStatusListTimestamp + }) + }) + + return NonRevokedIntervalOverrideListStruct({ + count: nonRevokedIntervalOverrides?.length ?? 0, + data: nativeNonRevokedIntervalOverrides as unknown as TypedArray< + StructObject<{ + rev_reg_def_id: string + requested_from_ts: number + override_rev_status_list_ts: number + }> + > + }) + } + + private convertAttributeNames(attributeRawValues: Record) { + return StringListStruct({ + count: Object.keys(attributeRawValues).length, + data: Object.keys(attributeRawValues) as unknown as TypedArray + }) + } + + private convertAttributeRawValues(attributeRawValues: Record) { + return StringListStruct({ + count: Object.keys(attributeRawValues).length, + data: Object.values(attributeRawValues) as unknown as TypedArray + }) + } + + private convertAttributeEncodedValues(attributeEncodedValues?: Record) { + return attributeEncodedValues + ? StringListStruct({ + count: Object.keys(attributeEncodedValues).length, + data: Object.values(attributeEncodedValues) as unknown as TypedArray + }) + : undefined + } + + private convertRevocationConfiguration(revocationConfiguration?: NativeCredentialRevocationConfig) { + let credRevInfo + if (revocationConfiguration) { + const { revocationRegistryDefinition, revocationRegistryDefinitionPrivate, revocationStatusList, registryIndex } = + serializeArguments(revocationConfiguration) + + credRevInfo = CredRevInfoStruct({ + reg_def: revocationRegistryDefinition, + reg_def_private: revocationRegistryDefinitionPrivate, + status_list: revocationStatusList, + reg_idx: registryIndex + }) + } + return credRevInfo + } } diff --git a/wrappers/javascript/packages/anoncreds-react-native/src/ReactNativeAnoncreds.ts b/wrappers/javascript/packages/anoncreds-react-native/src/ReactNativeAnoncreds.ts index 92a928bf..ef287195 100644 --- a/wrappers/javascript/packages/anoncreds-react-native/src/ReactNativeAnoncreds.ts +++ b/wrappers/javascript/packages/anoncreds-react-native/src/ReactNativeAnoncreds.ts @@ -406,11 +406,7 @@ export class ReactNativeAnoncreds implements Anoncreds { const attributeRawValues = Object.values(options.attributeRawValues) const credential = this.handleError( - // eslint-disable-next-line @typescript-eslint/ban-ts-comment, @typescript-eslint/prefer-ts-expect-error - // @ts-ignore this.anoncreds.createW3cCredential({ - // eslint-disable-next-line @typescript-eslint/ban-ts-comment, @typescript-eslint/prefer-ts-expect-error - // @ts-ignore ...serializeArguments(options), attributeRawValues, attributeNames, From a3ce38cd1733c30b32bab5c456a5830aacabd7e8 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Wed, 20 Dec 2023 09:51:07 +0300 Subject: [PATCH 14/21] Clean up Signed-off-by: artem.ivanov --- src/data_types/w3c/proof.rs | 13 +------------ src/services/w3c/verifier.rs | 10 ++++++++-- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/data_types/w3c/proof.rs b/src/data_types/w3c/proof.rs index 48e4fcba..ee22ba8c 100644 --- a/src/data_types/w3c/proof.rs +++ b/src/data_types/w3c/proof.rs @@ -37,17 +37,6 @@ pub enum CryptoSuite { AnonCredsPresVp2023, } -impl Default for DataIntegrityProof { - fn default() -> Self { - DataIntegrityProof { - type_: DataIntegrityProofType::DataIntegrityProof, - cryptosuite: CryptoSuite::AnonCredsVc2023, - proof_value: "".to_string(), - challenge: None, - } - } -} - impl DataIntegrityProof { pub fn new( cryptosuite: CryptoSuite, @@ -55,10 +44,10 @@ impl DataIntegrityProof { challenge: Option, ) -> Self { DataIntegrityProof { + type_: DataIntegrityProofType::DataIntegrityProof, cryptosuite, proof_value: value.encode(), challenge, - ..DataIntegrityProof::default() } } diff --git a/src/services/w3c/verifier.rs b/src/services/w3c/verifier.rs index f585f4e0..acda5899 100644 --- a/src/services/w3c/verifier.rs +++ b/src/services/w3c/verifier.rs @@ -370,7 +370,7 @@ mod tests { use crate::data_types::pres_request::{AttributeInfo, PredicateTypes}; use crate::data_types::w3c::credential_attributes::CredentialAttributes; use crate::data_types::w3c::presentation::PredicateAttribute; - use crate::data_types::w3c::proof::DataIntegrityProof; + use crate::data_types::w3c::proof::{CryptoSuite, DataIntegrityProof, DataIntegrityProofType}; use crate::w3c::credential_conversion::tests::{ cred_def_id, credential_definition, issuer_id, schema, schema_id, }; @@ -453,7 +453,13 @@ mod tests { } fn _w3_presentation() -> W3CPresentation { - W3CPresentation::new(vec![_credential()], DataIntegrityProof::default(), None) + let proof = DataIntegrityProof { + type_: DataIntegrityProofType::DataIntegrityProof, + cryptosuite: CryptoSuite::AnonCredsPresVp2023, + proof_value: "proof".to_string(), + challenge: Some("1".to_string()), + }; + W3CPresentation::new(vec![_credential()], proof, None) } fn _base_presentation_request() -> PresentationRequestPayload { From 87312b527b1cbf7a8b61aba123ad3ac35bf79952 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Wed, 20 Dec 2023 10:34:10 +0300 Subject: [PATCH 15/21] Updated python wrapper Signed-off-by: artem.ivanov --- docs/design/w3c/w3c-representation.md | 272 -------------------------- src/ffi/w3c/credential.rs | 34 +++- wrappers/python/anoncreds/__init__.py | 2 + wrappers/python/anoncreds/bindings.py | 20 +- wrappers/python/anoncreds/types.py | 112 +++++++---- wrappers/python/demo/w3c_test.py | 7 + 6 files changed, 130 insertions(+), 317 deletions(-) diff --git a/docs/design/w3c/w3c-representation.md b/docs/design/w3c/w3c-representation.md index 74dc1047..5c6e0d44 100644 --- a/docs/design/w3c/w3c-representation.md +++ b/docs/design/w3c/w3c-representation.md @@ -296,275 +296,3 @@ w3c_presentation_request = Verifier.w3c_create_presentation_request() w3c_presentation = Holder.anoncreds_w3c_create_presentation(w3c_presentation_request, w3c_credential) Verifier.anoncreds_w3c_verify_presentation(w3c_presentation) ``` - -### Presentation validation - -**Request** -``` -{ - "name":"pres_req_1", - "non_revoked":null, - "nonce":"358493544514389191968232", - "requested_attributes":{ - "attr1_referent":{ - "name":"first_name", - "non_revoked":null, - "restrictions":null - }, - "attr2_referent":{ - "name":"sex", - "non_revoked":null, - "restrictions":null - }, - "attr3_referent":{ - "names":[ - "last_name", - "height" - ], - "non_revoked":null, - "restrictions":null - } - }, - "requested_predicates":{ - "predicate1_referent":{ - "name":"age", - "non_revoked":null, - "p_type":">=", - "p_value":18, - "restrictions":null - } - }, - "ver":"1.0", - "version":"0.1" -} -``` - -**Presentation** -``` -{ - "@context": [ - "https://www.w3.org/2018/credentials/v1", - "https://raw.githubusercontent.com/DSRCorporation/anoncreds-rs/design/w3c-support/docs/design/w3c/context.json" - ], - "type": [ - "VerifiablePresentation", - "AnonCredsPresentation" - ], - "verifiableCredential": [ - { - "@context": [ - "https://www.w3.org/2018/credentials/v1", - "https://raw.githubusercontent.com/DSRCorporation/anoncreds-rs/design/w3c-support/docs/design/w3c/context.json" - ], - "type": [ - "VerifiableCredential", - "AnonCredsPresentation" - ], - "issuer": "did:sov:3avoBCqDMFHFaKUHug9s8W", - "issuanceDate": "2023-10-26T01:17:32Z", - "credentialSchema": { - "type": "AnonCredsDefinition", - "definition": "did:sov:3avoBCqDMFHFaKUHug9s8W:3:CL:13:default", - "schema": "did:sov:3avoBCqDMFHFaKUHug9s8W:2:basic_person:0.1.0" - }, - "credentialSubject": { - "first_name": "Alice" - "lastt_name": "Jons" - "height": "185" - }, - "proof": { - "type": "AnonCredsPresentationProof2023", - "mapping": { - "revealedAttributes": ["attr1_referent"], - "unrevealedAttributes": ["attr2_referent"], - "revealedAttributeGroups": ["attr3_referent"], - "requestedPredicates": ["predicate1_referent"] - }, - "proofValue": "AAEBAnr2Ql...0UhJ-bIIdWFKVWxjU3ePxv_7HoY5pUw" - } - } - ], - "proof": { - "type": "AnonCredsPresentationProof2023", - "challenge": "182453895158932070575246", - "proofValue": "AAAgtMR4....J19l-agSA" - } -} -``` - -**Verifier validation steps is we keep mapping**: -``` -// validate requested attributes -for (referent, requested) in presentation_request.requested_attributes { - credential = presentation.verifiableCredential.find((verifiableCredential) => - verifiableCredential.proof.mapping.revealedAttributes.includes(referent) || - verifiableCredential.proof.mapping.unrevealedAttributes.includes(referent) || - verifiableCredential.proof.mapping.revealedAttributeGroups.includes(referent)) - - credential.checkRestrictions(requested.restrictions) - - if !credential { - error - } - if requested.name { - assert(credential.credentialSubject[requested.name]) - } - if requested.names { - names.forEach((name) => assert(credential.credentialSubject[name])) - } -} - -// validate requested predicates -for (referent, requested) in presentation_request.requested_predicates { - credential = presentation.verifiableCredential.find((verifiableCredential) => - verifiableCredential.proof.mapping.requestedPredicates.includes(referent)) - credential.checkRestrictions(requested.restrictions) - assert(credential.credentialSubject[requested.name]) // if we include derived predicate into subject -} -``` - -**Verifier validation steps is we drop mapping**: -``` -// validate requested attributes -for (referent, requested) in presentation_request.requested_attributes { - if requested.name { - // or filter if requted same attribute multiple times? - credential = presentation.verifiableCredential.find((verifiableCredential) => - credentialSubject.contains(requested[name]) - ) - if credential { - credential.checkRestrictions(requested.restrictions) - assert(credential.credentialSubject[requested.name]) - } - if !credential { - // consider attribute as unrevealed - // If we need to support and validate unrevealed attributes - credential_with_attribute = presentation.verifiableCredential.find((verifiableCredential) => - schema = get_schema(verifiableCredential.schema_id) // all schemas already passed into verification function - schema.attributes.includes(requested.name) - verifiableCredential.matches(restrictions) - ) - if !credential_with_attribute { - error - } - } - } - if requested.names { - for (referent, requested) in requested.names { - // do same as for single attribute above - // make sure that all come from single credential - } - } -} - -// validate requested predicates - we put predicate derived string or object into credentialSubject -// { -// "age" ">= 18" -// } -for (referent, requested) in presentation_request.requested_predicates { - // or filter if requted same attribute multiple times? - credential = presentation.verifiableCredential.find((verifiableCredential) => - credentialSubject.contains(requested[name]) - ) - if !credential { - error - } - credential.checkRestrictions(requested.restrictions) - assert(credential.credentialSubject[requested.name]) -} -``` - -### Examples - -Example of an AnonCreds W3C credential: - -```json -{ - "@context": [ - "https://www.w3.org/2018/credentials/v1", - "https://raw.githubusercontent.com/hyperledger/anoncreds-spec/main/data/anoncreds-w3c-context.json" - ], - "type": [ - "VerifiableCredential", - "AnonCredsCredential" - ], - "issuer": "did:sov:3avoBCqDMFHFaKUHug9s8W", - "issuanceDate": "2023-11-15T10:00:00.036203Z", - "credentialSchema": { - "type": "AnonCredsDefinition", - "definition": "did:sov:3avoBCqDMFHFaKUHug9s8W:3:CL:13:default", - "schema": "did:sov:3avoBCqDMFHFaKUHug9s8W:2:basic_person:0.1.0" - }, - "credentialSubject": { - "firstName": "Alice", - "lastName": "Jones", - "age": "18" - }, - "proof": [ - { - "type": "AnonCredsProof2023", - "signature": "AAAgf9w5.....8Z_x3FqdwRHoWruiF0FlM" - }, - { - "type": "Ed25519Signature2020", - "created": "2021-11-13T18:19:39Z", - "verificationMethod": "did:sov:3avoBCqDMFHFaKUHug9s8W#key-1", - "proofPurpose": "assertionMethod", - "proofValue": "z58DAdFfa9SkqZMVPxAQpic7ndSayn1PzZs6ZjWp1CktyGesjuTSwRdoWhAfGFCF5bppETSTojQCrfFPP2oumHKtz" - } - ] -} -``` - -Example of an AnonCreds W3C presentation: - -```json -{ - "@context": [ - "https://www.w3.org/2018/credentials/v1", - "https://raw.githubusercontent.com/hyperledger/anoncreds-spec/main/data/anoncreds-w3c-context.json" - ], - "type": [ - "VerifiablePresentation", - "AnonCredsPresentation" - ], - "verifiableCredential": [ - { - "@context": [ - "https://www.w3.org/2018/credentials/v1", - "https://raw.githubusercontent.com/hyperledger/anoncreds-spec/main/data/anoncreds-w3c-context.json" - ], - "type": [ - "VerifiableCredential", - "AnonCredsCredential" - ], - "credentialSchema": { - "type": "AnonCredsDefinition", - "definition": "did:sov:3avoBCqDMFHFaKUHug9s8W:3:CL:13:default", - "schema": "did:sov:3avoBCqDMFHFaKUHug9s8W:2:basic_person:0.1.0" - }, - "credentialSubject": { - "firstName": "Alice", - "age": [ - { - "type": "AnonCredsPredicate", - "predicate": ">=", - "value": 18 - } - ] - }, - "issuanceDate": "2023-11-15T10:59:48.036203Z", - "issuer": "did:sov:3avoBCqDMFHFaKUHug9s8W", - "proof": { - "type": "AnonCredsPresentationProof2023", - "proofValue": "eyJzdWJfcHJvb2Yi...zMTc1NzU0NDAzNDQ0ODUifX1dfX19" - } - } - ], - "proof": { - "type": "AnonCredsPresentationProof2023", - "challenge": "413296376279822794586260", - "proofValue": "eyJhZ2dyZWdhdGVkIjp7ImNfaGFzaCI6IjEwMT...IsMzAsMTM1LDE4MywxMDcsMTYwXV19fQ==" - } -} -``` \ No newline at end of file diff --git a/src/ffi/w3c/credential.rs b/src/ffi/w3c/credential.rs index 7c5210ee..6a1cb117 100644 --- a/src/ffi/w3c/credential.rs +++ b/src/ffi/w3c/credential.rs @@ -1,5 +1,7 @@ +use std::ffi::c_char; +use std::ptr; use crate::data_types::w3c::VerifiableCredentialSpecVersion; -use ffi_support::FfiStr; +use ffi_support::{FfiStr, rust_string_to_c}; use crate::data_types::w3c::credential::W3CCredential; use crate::data_types::w3c::credential_attributes::CredentialAttributes; @@ -209,6 +211,36 @@ pub extern "C" fn anoncreds_w3c_credential_get_integrity_proof_details( }) } +#[no_mangle] +pub extern "C" fn anoncreds_w3c_credential_proof_get_attribute( + handle: ObjectHandle, + name: FfiStr, + result_p: *mut *const c_char, +) -> ErrorCode { + catch_error(|| { + check_useful_c_ptr!(result_p); + let cred = handle.load()?; + let cred = cred.cast_ref::()?; + let val = match name.as_opt_str().unwrap_or_default() { + "schema_id" => rust_string_to_c(cred.schema_id.clone()), + "cred_def_id" => rust_string_to_c(cred.cred_def_id.to_string()), + "rev_reg_id" => cred + .rev_reg_id + .as_ref() + .map_or(ptr::null_mut(), |s| rust_string_to_c(s.to_string())), + "rev_reg_index" => cred + .rev_reg_index + .map_or(ptr::null_mut(), |s| rust_string_to_c(s.to_string())), + "timestamp" => cred + .timestamp + .map_or(ptr::null_mut(), |s| rust_string_to_c(s.to_string())), + s => return Err(err_msg!("Unsupported attribute: {}", s)), + }; + unsafe { *result_p = val }; + Ok(()) + }) +} + impl_anoncreds_object!(CredentialProofDetails, "CredentialProofInfo"); pub(crate) fn _credential_attributes( diff --git a/wrappers/python/anoncreds/__init__.py b/wrappers/python/anoncreds/__init__.py index 846a8843..551f9f82 100644 --- a/wrappers/python/anoncreds/__init__.py +++ b/wrappers/python/anoncreds/__init__.py @@ -22,6 +22,7 @@ RevocationRegistryDefinition, RevocationRegistryDefinitionPrivate, W3cCredential, + W3cCredentialProofDetails, W3cPresentation, ) @@ -51,5 +52,6 @@ "RevocationRegistryDefinitionPrivate", "Schema", "W3cCredential", + "W3cCredentialProofDetails", "W3cPresentation" ) diff --git a/wrappers/python/anoncreds/bindings.py b/wrappers/python/anoncreds/bindings.py index 69425639..d0887478 100644 --- a/wrappers/python/anoncreds/bindings.py +++ b/wrappers/python/anoncreds/bindings.py @@ -973,7 +973,7 @@ def create_w3c_credential( cred_request: ObjectHandle, attr_raw_values: Mapping[str, str], revocation_config: Optional[RevocationConfig], - encoding: Optional[str], + version: Optional[str], ) -> ObjectHandle: cred = ObjectHandle() attr_keys = list(attr_raw_values.keys()) @@ -987,10 +987,10 @@ def create_w3c_credential( cred_request, names_list, raw_values_list, - encode_str(encoding), pointer(revocation_config) if revocation_config else POINTER(RevocationConfig)(), + encode_str(version), byref(cred), ) return cred @@ -1019,12 +1019,14 @@ def process_w3c_credential( def credential_to_w3c( cred: ObjectHandle, cred_def: ObjectHandle, + version: Optional[str], ) -> ObjectHandle: result = ObjectHandle() do_call( "anoncreds_credential_to_w3c", cred, cred_def, + encode_str(version), byref(result), ) return result @@ -1051,6 +1053,7 @@ def create_w3c_presentation( schema_ids: Sequence[str], cred_defs: Sequence[ObjectHandle], cred_def_ids: Sequence[str], + version: Optional[str], ) -> ObjectHandle: entry_list = CredentialEntryList() entry_list.count = len(credentials) @@ -1070,6 +1073,7 @@ def create_w3c_presentation( FfiStrList.create(schema_ids), FfiObjectHandleList.create(cred_defs), FfiStrList.create(cred_def_ids), + encode_str(version), byref(present), ) return present @@ -1111,3 +1115,15 @@ def verify_w3c_presentation( byref(verify), ) return bool(verify) + + +def w3c_credential_get_integrity_proof_details( + cred: ObjectHandle, +) -> ObjectHandle: + result = ObjectHandle() + do_call( + "anoncreds_w3c_credential_get_integrity_proof_details", + cred, + byref(result), + ) + return result diff --git a/wrappers/python/anoncreds/types.py b/wrappers/python/anoncreds/types.py index 48e830dd..9b27db46 100644 --- a/wrappers/python/anoncreds/types.py +++ b/wrappers/python/anoncreds/types.py @@ -345,7 +345,8 @@ def rev_reg_index(self) -> Optional[int]: def to_w3c( self, - cred_def: Union[str, CredentialDefinition] + cred_def: Union[str, CredentialDefinition], + version: Optional[str] = None, ) -> "W3cCredential": if not isinstance(cred_def, bindings.AnoncredsObject): cred_def = CredentialDefinition.load(cred_def) @@ -353,6 +354,7 @@ def to_w3c( bindings.credential_to_w3c( self.handle, cred_def.handle, + version ) ) @@ -365,6 +367,58 @@ def from_w3c(cls, cred: "W3cCredential") -> "Credential": ) +class W3cCredentialProofDetails(bindings.AnoncredsObject): + GET_ATTR = "anoncreds_w3c_credential_proof_get_attribute" + + @property + def schema_id(self) -> str: + return str( + bindings._object_get_attribute( + self.GET_ATTR, + self.handle, + "schema_id", + ) + ) + + @property + def cred_def_id(self) -> str: + return str( + bindings._object_get_attribute( + self.GET_ATTR, + self.handle, + "cred_def_id", + ) + ) + + @property + def rev_reg_id(self) -> str: + return str( + bindings._object_get_attribute( + self.GET_ATTR, + self.handle, + "rev_reg_id", + ) + ) + + @property + def rev_reg_index(self) -> Optional[int]: + sval = bindings._object_get_attribute( + self.GET_ATTR, + self.handle, + "rev_reg_index", + ) + return int(str(sval)) if sval is not None else None + + @property + def timestamp(self) -> Optional[int]: + sval = bindings._object_get_attribute( + self.GET_ATTR, + self.handle, + "timestamp", + ) + return int(str(sval)) if sval is not None else None + + class W3cCredential(bindings.AnoncredsObject): GET_ATTR = "anoncreds_w3c_credential_get_attribute" @@ -377,7 +431,7 @@ def create( cred_request: Union[str, CredentialRequest], attr_raw_values: Mapping[str, str], revocation_config: Optional["CredentialRevocationConfig"] = None, - encoding: Optional[str] = None, + version: Optional[str] = None, ) -> "W3cCredential": if not isinstance(cred_def, bindings.AnoncredsObject): cred_def = CredentialDefinition.load(cred_def) @@ -394,7 +448,7 @@ def create( cred_request.handle, attr_raw_values, revocation_config._native if revocation_config else None, - encoding, + version, ) return W3cCredential(cred) @@ -423,57 +477,29 @@ def process( @classmethod def load(cls, value: Union[dict, str, bytes, memoryview]) -> "W3cCredential": - return Credential( + return W3cCredential( bindings._object_from_json("anoncreds_w3c_credential_from_json", value) ) @property - def schema_id(self) -> str: - return str( - bindings._object_get_attribute( - self.GET_ATTR, - self.handle, - "schema_id", - ) - ) - - @property - def cred_def_id(self) -> str: - return str( - bindings._object_get_attribute( - self.GET_ATTR, - self.handle, - "cred_def_id", - ) + def proof_details(self) -> "W3cCredentialProofDetails": + return W3cCredentialProofDetails( + bindings.w3c_credential_get_integrity_proof_details(self.handle) ) - @property - def rev_reg_id(self) -> str: - return str( - bindings._object_get_attribute( - self.GET_ATTR, - self.handle, - "rev_reg_id", - ) - ) - - @property - def rev_reg_index(self) -> Optional[int]: - sval = bindings._object_get_attribute( - self.GET_ATTR, - self.handle, - "rev_reg_index", - ) - return int(str(sval)) if sval is not None else None - def to_legacy( self ) -> "Credential": return Credential.from_w3c(self) @classmethod - def from_legacy(cls, cred: "Credential", cred_def: Union[str, CredentialDefinition]) -> "W3cCredential": - return cred.to_w3c(cred_def) + def from_legacy( + cls, + cred: "Credential", + cred_def: Union[str, CredentialDefinition], + version: Optional[str] = None + ) -> "W3cCredential": + return cred.to_w3c(cred_def, version) class PresentationRequest(bindings.AnoncredsObject): @@ -694,6 +720,7 @@ def create( link_secret: str, schemas: Mapping[str, Union[str, Schema]], cred_defs: Mapping[str, Union[str, CredentialDefinition]], + version: Optional[str] = None, ) -> "W3cPresentation": if not isinstance(pres_req, bindings.AnoncredsObject): pres_req = PresentationRequest.load(pres_req) @@ -741,6 +768,7 @@ def create( schema_ids, cred_def_handles, cred_def_ids, + version, ) ) diff --git a/wrappers/python/demo/w3c_test.py b/wrappers/python/demo/w3c_test.py index f3728a43..3f0d4f57 100644 --- a/wrappers/python/demo/w3c_test.py +++ b/wrappers/python/demo/w3c_test.py @@ -3,6 +3,7 @@ create_link_secret, Credential, W3cCredential, + W3cCredentialProofDetails, CredentialDefinition, CredentialOffer, CredentialRequest, @@ -75,6 +76,12 @@ cred_request_metadata, link_secret, cred_def_pub, rev_reg_def_pub ) +proof_details = recv_cred.proof_details +assert schema_id == proof_details.schema_id +assert cred_def_id == proof_details.cred_def_id +assert rev_idx == proof_details.rev_reg_index +assert None == proof_details.timestamp + print("W3c Credential") print(recv_cred.to_json()) From d04299f9272624052b07787334c6ba3caeb2de07 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Wed, 20 Dec 2023 12:27:36 +0300 Subject: [PATCH 16/21] Updated JavaScript wrappers Signed-off-by: artem.ivanov --- .../anoncreds-nodejs/src/NodeJSAnoncreds.ts | 66 ++++++---- .../anoncreds-nodejs/src/library/bindings.ts | 11 +- .../anoncreds-nodejs/tests/api.test.ts | 2 +- .../anoncreds-nodejs/tests/bindings.test.ts | 6 +- .../anoncreds-react-native/cpp/HostObject.cpp | 6 +- .../anoncreds-react-native/cpp/anoncreds.cpp | 31 ++++- .../anoncreds-react-native/cpp/anoncreds.h | 3 +- .../cpp/include/libanoncreds.h | 23 +++- .../src/NativeBindings.ts | 13 +- .../src/ReactNativeAnoncreds.ts | 23 +++- .../anoncreds-shared/src/Anoncreds.ts | 15 ++- .../anoncreds-shared/src/api/Credential.ts | 4 +- .../anoncreds-shared/src/api/W3cCredential.ts | 35 ++++- wrappers/python/anoncreds/__init__.py | 2 - wrappers/python/anoncreds/types.py | 120 +++++++++--------- wrappers/python/demo/w3c_test.py | 10 +- 16 files changed, 238 insertions(+), 132 deletions(-) diff --git a/wrappers/javascript/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts b/wrappers/javascript/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts index c6735945..80c75d09 100644 --- a/wrappers/javascript/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts +++ b/wrappers/javascript/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts @@ -102,16 +102,6 @@ export class NodeJSAnoncreds implements Anoncreds { return handleReturnPointer(ret) } - public w3cCredentialGetAttribute(options: { objectHandle: ObjectHandle; name: string }) { - const { objectHandle, name } = serializeArguments(options) - - const ret = allocateStringBuffer() - this.nativeAnoncreds.anoncreds_w3c_credential_get_attribute(objectHandle, name, ret) - this.handleError() - - return handleReturnPointer(ret) - } - public createCredentialDefinition(options: { schemaId: string schema: ObjectHandle @@ -535,9 +525,9 @@ export class NodeJSAnoncreds implements Anoncreds { credentialRequest: ObjectHandle attributeRawValues: Record revocationConfiguration?: NativeCredentialRevocationConfig - encoding?: string + version?: string }): ObjectHandle { - const { credentialDefinition, credentialDefinitionPrivate, credentialOffer, credentialRequest, encoding } = + const { credentialDefinition, credentialDefinitionPrivate, credentialOffer, credentialRequest, version } = serializeArguments(options) const attributeNames = this.convertAttributeNames(options.attributeRawValues) @@ -552,8 +542,8 @@ export class NodeJSAnoncreds implements Anoncreds { credentialRequest, attributeNames as unknown as Buffer, attributeRawValues as unknown as Buffer, - encoding, revocationConfiguration?.ref().address() ?? 0, + version, credentialPtr ) this.handleError() @@ -592,8 +582,9 @@ export class NodeJSAnoncreds implements Anoncreds { linkSecret: string schemas: Record credentialDefinitions: Record + version?: string }): ObjectHandle { - const { presentationRequest, linkSecret } = serializeArguments(options) + const { presentationRequest, linkSecret, version } = serializeArguments(options) const credentialEntryList = this.convertCredentialList(options.credentials) const credentialProveList = this.convertCredentialProves(options.credentialsProve) @@ -611,6 +602,7 @@ export class NodeJSAnoncreds implements Anoncreds { schemaIds as unknown as Buffer, credentialDefinitions as unknown as Buffer, credentialDefinitionIds as unknown as Buffer, + version, ret ) this.handleError() @@ -664,12 +656,16 @@ export class NodeJSAnoncreds implements Anoncreds { return Boolean(handleReturnPointer(ret)) } - public credentialToW3c(options: { objectHandle: ObjectHandle; credentialDefinition: ObjectHandle }): ObjectHandle { - const { objectHandle, credentialDefinition } = serializeArguments(options) + public credentialToW3c(options: { + objectHandle: ObjectHandle + credentialDefinition: ObjectHandle + version?: string + }): ObjectHandle { + const { objectHandle, credentialDefinition, version } = serializeArguments(options) const ret = allocatePointer() - this.nativeAnoncreds.anoncreds_credential_to_w3c(objectHandle, credentialDefinition, ret) + this.nativeAnoncreds.anoncreds_credential_to_w3c(objectHandle, credentialDefinition, version, ret) this.handleError() return new ObjectHandle(handleReturnPointer(ret)) @@ -686,6 +682,34 @@ export class NodeJSAnoncreds implements Anoncreds { return new ObjectHandle(handleReturnPointer(ret)) } + public w3cCredentialGetIntegrityProofDetails(options: { objectHandle: ObjectHandle }) { + const { objectHandle } = serializeArguments(options) + + const ret = allocatePointer() + this.nativeAnoncreds.anoncreds_w3c_credential_get_integrity_proof_details(objectHandle, ret) + this.handleError() + + return new ObjectHandle(handleReturnPointer(ret)) + } + + public w3cCredentialProofGetAttribute(options: { objectHandle: ObjectHandle; name: string }) { + const { objectHandle, name } = serializeArguments(options) + + const ret = allocateStringBuffer() + this.nativeAnoncreds.anoncreds_w3c_credential_proof_get_attribute(objectHandle, name, ret) + this.handleError() + + return handleReturnPointer(ret) + } + + public w3cCredentialFromJson(options: { json: string }): ObjectHandle { + return this.objectFromJson(this.nativeAnoncreds.anoncreds_w3c_credential_from_json, options) + } + + public w3cPresentationFromJson(options: { json: string }): ObjectHandle { + return this.objectFromJson(this.nativeAnoncreds.anoncreds_w3c_presentation_from_json, options) + } + public version(): string { return this.nativeAnoncreds.anoncreds_version() } @@ -775,14 +799,6 @@ export class NodeJSAnoncreds implements Anoncreds { return this.objectFromJson(this.nativeAnoncreds.anoncreds_key_correctness_proof_from_json, options) } - public w3cCredentialFromJson(options: { json: string }): ObjectHandle { - return this.objectFromJson(this.nativeAnoncreds.anoncreds_w3c_credential_from_json, options) - } - - public w3cPresentationFromJson(options: { json: string }): ObjectHandle { - return this.objectFromJson(this.nativeAnoncreds.anoncreds_w3c_presentation_from_json, options) - } - public getJson(options: { objectHandle: ObjectHandle }) { const ret = allocateByteBuffer() diff --git a/wrappers/javascript/packages/anoncreds-nodejs/src/library/bindings.ts b/wrappers/javascript/packages/anoncreds-nodejs/src/library/bindings.ts index 4ccf3b71..9f99754d 100644 --- a/wrappers/javascript/packages/anoncreds-nodejs/src/library/bindings.ts +++ b/wrappers/javascript/packages/anoncreds-nodejs/src/library/bindings.ts @@ -201,8 +201,8 @@ export const nativeBindings = { FFI_OBJECT_HANDLE, StringListStruct, StringListStruct, - FFI_STRING, FFI_OBJECT_HANDLE, + FFI_STRING, FFI_OBJECT_HANDLE_PTR ] ], @@ -221,6 +221,7 @@ export const nativeBindings = { StringListStruct, ObjectHandleListStruct, StringListStruct, + FFI_STRING, FFI_OBJECT_HANDLE_PTR ] ], @@ -240,9 +241,13 @@ export const nativeBindings = { FFI_INT8_PTR ] ], - anoncreds_credential_to_w3c: [FFI_ERRORCODE, [FFI_OBJECT_HANDLE, FFI_OBJECT_HANDLE, FFI_OBJECT_HANDLE_PTR]], + anoncreds_credential_to_w3c: [ + FFI_ERRORCODE, + [FFI_OBJECT_HANDLE, FFI_OBJECT_HANDLE, FFI_STRING, FFI_OBJECT_HANDLE_PTR] + ], anoncreds_credential_from_w3c: [FFI_ERRORCODE, [FFI_OBJECT_HANDLE, FFI_OBJECT_HANDLE_PTR]], - anoncreds_w3c_credential_get_attribute: [FFI_ERRORCODE, [FFI_OBJECT_HANDLE, FFI_STRING, FFI_STRING_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]], anoncreds_w3c_presentation_from_json: [FFI_ERRORCODE, [ByteBufferStruct, FFI_STRING_PTR]], anoncreds_w3c_credential_from_json: [FFI_ERRORCODE, [ByteBufferStruct, FFI_STRING_PTR]] } as const diff --git a/wrappers/javascript/packages/anoncreds-nodejs/tests/api.test.ts b/wrappers/javascript/packages/anoncreds-nodejs/tests/api.test.ts index 58da5ca2..cdfb27fe 100644 --- a/wrappers/javascript/packages/anoncreds-nodejs/tests/api.test.ts +++ b/wrappers/javascript/packages/anoncreds-nodejs/tests/api.test.ts @@ -716,7 +716,7 @@ describe('API W3C', () => { revocationRegistryDefinitions: { 'mock:uri': revocationRegistryDefinition }, revocationStatusLists: [revocationStatusList] }) - }).toThrowError('Invalid timestamp') + }).toThrowError('Presentation does not contain attribute name') const verify = presentation.verify({ presentationRequest, diff --git a/wrappers/javascript/packages/anoncreds-nodejs/tests/bindings.test.ts b/wrappers/javascript/packages/anoncreds-nodejs/tests/bindings.test.ts index f72761df..c4d2b0a5 100644 --- a/wrappers/javascript/packages/anoncreds-nodejs/tests/bindings.test.ts +++ b/wrappers/javascript/packages/anoncreds-nodejs/tests/bindings.test.ts @@ -712,8 +712,12 @@ describe('bindings', () => { revocationRegistryDefinition }) - const revRegIndex = anoncreds.w3cCredentialGetAttribute({ + const credentialProofDetails = anoncreds.w3cCredentialGetIntegrityProofDetails({ objectHandle: credentialReceived, + }) + + const revRegIndex = anoncreds.w3cCredentialProofGetAttribute({ + objectHandle: credentialProofDetails, name: 'rev_reg_index' }) diff --git a/wrappers/javascript/packages/anoncreds-react-native/cpp/HostObject.cpp b/wrappers/javascript/packages/anoncreds-react-native/cpp/HostObject.cpp index 599ce28f..5e533b38 100644 --- a/wrappers/javascript/packages/anoncreds-react-native/cpp/HostObject.cpp +++ b/wrappers/javascript/packages/anoncreds-react-native/cpp/HostObject.cpp @@ -91,8 +91,10 @@ fMap.insert(std::make_tuple("createRevocationStatusList", std::make_tuple("createW3cCredential", &anoncreds::createW3cCredential)); fMap.insert( std::make_tuple("createW3cPresentation", &anoncreds::createW3cPresentation)); - fMap.insert(std::make_tuple("w3cCredentialGetAttribute", - &anoncreds::w3cCredentialGetAttribute)); + fMap.insert(std::make_tuple("w3cCredentialGetIntegrityProofDetails", + &anoncreds::w3cCredentialGetIntegrityProofDetails)); + fMap.insert(std::make_tuple("w3cCredentialProofGetAttribute", + &anoncreds::w3cCredentialProofGetAttribute)); fMap.insert( std::make_tuple("processW3cCredential", &anoncreds::processW3cCredential)); fMap.insert( diff --git a/wrappers/javascript/packages/anoncreds-react-native/cpp/anoncreds.cpp b/wrappers/javascript/packages/anoncreds-react-native/cpp/anoncreds.cpp index deba0aed..74801d4c 100644 --- a/wrappers/javascript/packages/anoncreds-react-native/cpp/anoncreds.cpp +++ b/wrappers/javascript/packages/anoncreds-react-native/cpp/anoncreds.cpp @@ -726,12 +726,15 @@ jsi::Value createW3cPresentation(jsi::Runtime &rt, jsi::Object options) { jsiToValue(rt, options, "credentialDefinitions"); auto credentialDefinitionIds = jsiToValue(rt, options, "credentialDefinitionIds"); + auto version = + jsiToValue(rt, options, "version", true); ObjectHandle out; ErrorCode code = anoncreds_create_w3c_presentation( presentationRequest, credentials, credentialsProve, linkSecret.c_str(), - schemas, schemaIds, credentialDefinitions, credentialDefinitionIds, &out); + schemas, schemaIds, credentialDefinitions, credentialDefinitionIds, + version.length() ? version.c_str() : nullptr, &out); auto returnValue = createReturnValue(rt, code, &out); @@ -809,8 +812,8 @@ jsi::Value createW3cCredential(jsi::Runtime &rt, jsi::Object options) { jsiToValue(rt, options, "attributeRawValues"); auto revocation = jsiToValue(rt, options, "revocationConfiguration", true); - auto encoding = - jsiToValue(rt, options, "encoding", true); + auto version = + jsiToValue(rt, options, "version", true); ObjectHandle out; @@ -818,19 +821,30 @@ jsi::Value createW3cCredential(jsi::Runtime &rt, jsi::Object options) { credentialDefinition, credentialDefinitionPrivate, credentialOffer, credentialRequest, attributeNames, attributeRawValues, revocation.reg_def ? &revocation : 0, - encoding.length() ? encoding.c_str() : nullptr, &out); + version.length() ? version.c_str() : nullptr, &out); return createReturnValue(rt, code, &out); }; -jsi::Value w3cCredentialGetAttribute(jsi::Runtime &rt, jsi::Object options) { +jsi::Value w3cCredentialGetIntegrityProofDetails(jsi::Runtime &rt, jsi::Object options) { + auto handle = jsiToValue(rt, options, "objectHandle"); + + ObjectHandle out; + + ErrorCode code = + anoncreds_w3c_credential_get_integrity_proof_details(handle, &out); + + return createReturnValue(rt, code, &out); +}; + +jsi::Value w3cCredentialProofGetAttribute(jsi::Runtime &rt, jsi::Object options) { auto handle = jsiToValue(rt, options, "objectHandle"); auto name = jsiToValue(rt, options, "name"); const char *out; ErrorCode code = - anoncreds_w3c_credential_get_attribute(handle, name.c_str(), &out); + anoncreds_w3c_credential_proof_get_attribute(handle, name.c_str(), &out); return createReturnValue(rt, code, &out); }; @@ -858,11 +872,14 @@ jsi::Value credentialToW3c(jsi::Runtime &rt, jsi::Object options) { auto credential = jsiToValue(rt, options, "objectHandle"); auto credentialDefinition = jsiToValue(rt, options, "credentialDefinition"); + auto version = + jsiToValue(rt, options, "version", true); ObjectHandle out; ErrorCode code = anoncreds_credential_to_w3c( - credential, credentialDefinition, &out); + credential, credentialDefinition, + version.length() ? version.c_str() : nullptr, &out); return createReturnValue(rt, code, &out); }; diff --git a/wrappers/javascript/packages/anoncreds-react-native/cpp/anoncreds.h b/wrappers/javascript/packages/anoncreds-react-native/cpp/anoncreds.h index 377fb9a7..be53686c 100644 --- a/wrappers/javascript/packages/anoncreds-react-native/cpp/anoncreds.h +++ b/wrappers/javascript/packages/anoncreds-react-native/cpp/anoncreds.h @@ -79,7 +79,8 @@ jsi::Value encodeCredentialAttributes(jsi::Runtime &rt, jsi::Object options); jsi::Value processCredential(jsi::Runtime &rt, jsi::Object options); jsi::Value createW3cCredential(jsi::Runtime &rt, jsi::Object options); -jsi::Value w3cCredentialGetAttribute(jsi::Runtime &rt, jsi::Object options); +jsi::Value w3cCredentialGetIntegrityProofDetails(jsi::Runtime &rt, jsi::Object options); +jsi::Value w3cCredentialProofGetAttribute(jsi::Runtime &rt, jsi::Object options); jsi::Value processW3cCredential(jsi::Runtime &rt, jsi::Object options); jsi::Value credentialToW3c(jsi::Runtime &rt, jsi::Object options); jsi::Value credentialFromW3c(jsi::Runtime &rt, jsi::Object options); diff --git a/wrappers/javascript/packages/anoncreds-react-native/cpp/include/libanoncreds.h b/wrappers/javascript/packages/anoncreds-react-native/cpp/include/libanoncreds.h index ca6f71eb..de3a39e9 100644 --- a/wrappers/javascript/packages/anoncreds-react-native/cpp/include/libanoncreds.h +++ b/wrappers/javascript/packages/anoncreds-react-native/cpp/include/libanoncreds.h @@ -440,6 +440,16 @@ ErrorCode anoncreds_verify_presentation(ObjectHandle presentation, struct FfiList_FfiNonrevokedIntervalOverride nonrevoked_interval_override, int8_t *result_p); +ErrorCode anoncreds_create_w3c_credential(ObjectHandle cred_def, + ObjectHandle cred_def_private, + ObjectHandle cred_offer, + ObjectHandle cred_request, + FfiStrList attr_names, + FfiStrList attr_raw_values, + const struct FfiCredRevInfo *revocation, + FfiStr version, + ObjectHandle *cred_p); + ErrorCode anoncreds_process_w3c_credential(ObjectHandle cred, ObjectHandle cred_req_metadata, FfiStr link_secret, @@ -449,6 +459,7 @@ ErrorCode anoncreds_process_w3c_credential(ObjectHandle cred, ErrorCode anoncreds_credential_to_w3c(ObjectHandle cred, ObjectHandle cred_def, + FfiStr version, ObjectHandle *cred_p); ErrorCode anoncreds_credential_from_w3c(ObjectHandle cred, @@ -462,6 +473,7 @@ ErrorCode anoncreds_create_w3c_presentation(ObjectHandle pres_req, FfiStrList schema_ids, struct FfiList_ObjectHandle cred_defs, FfiStrList cred_def_ids, + FfiStr version, ObjectHandle *presentation_p); ErrorCode anoncreds_verify_w3c_presentation(ObjectHandle presentation, @@ -476,11 +488,14 @@ ErrorCode anoncreds_verify_w3c_presentation(ObjectHandle presentation, struct FfiList_FfiNonrevokedIntervalOverride nonrevoked_interval_override, int8_t *result_p); -ErrorCode anoncreds_w3c_credential_from_json(struct ByteBuffer json, ObjectHandle *result_p); +ErrorCode anoncreds_w3c_credential_get_integrity_proof_details(ObjectHandle handle, + ObjectHandle *result_p); -ErrorCode anoncreds_w3c_credential_get_attribute(ObjectHandle handle, - FfiStr name, - const char **result_p); +ErrorCode anoncreds_w3c_credential_proof_get_attribute(ObjectHandle handle, + FfiStr name, + const char **result_p); + +ErrorCode anoncreds_w3c_credential_from_json(struct ByteBuffer json, ObjectHandle *result_p); ErrorCode anoncreds_w3c_presentation_from_json(struct ByteBuffer json, ObjectHandle *result_p); diff --git a/wrappers/javascript/packages/anoncreds-react-native/src/NativeBindings.ts b/wrappers/javascript/packages/anoncreds-react-native/src/NativeBindings.ts index 67f8b9ac..8a33956b 100644 --- a/wrappers/javascript/packages/anoncreds-react-native/src/NativeBindings.ts +++ b/wrappers/javascript/packages/anoncreds-react-native/src/NativeBindings.ts @@ -199,7 +199,7 @@ export type NativeBindings = { revocationRegistryDefinitionPrivate: number revocationStatusList?: number } - encoding?: string + version?: string }): ReturnObject processW3cCredential(options: { @@ -210,9 +210,15 @@ export type NativeBindings = { revocationRegistryDefinition?: number }): ReturnObject - w3cCredentialGetAttribute(options: { objectHandle: number; name: string }): ReturnObject + w3cCredentialGetIntegrityProofDetails(options: { objectHandle: number }): ReturnObject - credentialToW3c(options: { objectHandle: number; credentialDefinition: number }): ReturnObject + w3cCredentialProofGetAttribute(options: { objectHandle: number; name: string }): ReturnObject + + credentialToW3c(options: { + objectHandle: number + credentialDefinition: number + version?: string + }): ReturnObject credentialFromW3c(options: { objectHandle: number }): ReturnObject @@ -225,6 +231,7 @@ export type NativeBindings = { schemas: number[] credentialDefinitionIds: string[] credentialDefinitions: number[] + version?: string }): ReturnObject verifyW3cPresentation(options: { diff --git a/wrappers/javascript/packages/anoncreds-react-native/src/ReactNativeAnoncreds.ts b/wrappers/javascript/packages/anoncreds-react-native/src/ReactNativeAnoncreds.ts index ef287195..6c28e34b 100644 --- a/wrappers/javascript/packages/anoncreds-react-native/src/ReactNativeAnoncreds.ts +++ b/wrappers/javascript/packages/anoncreds-react-native/src/ReactNativeAnoncreds.ts @@ -400,7 +400,7 @@ export class ReactNativeAnoncreds implements Anoncreds { credentialRequest: ObjectHandle attributeRawValues: Record revocationConfiguration?: NativeCredentialRevocationConfig - encoding?: string + version?: string }): ObjectHandle { const attributeNames = Object.keys(options.attributeRawValues) const attributeRawValues = Object.values(options.attributeRawValues) @@ -419,7 +419,7 @@ export class ReactNativeAnoncreds implements Anoncreds { revocationStatusList: options.revocationConfiguration.revocationStatusList.handle } : undefined, - encoding: options.encoding + version: options.version }) ) @@ -444,6 +444,7 @@ export class ReactNativeAnoncreds implements Anoncreds { linkSecret: string schemas: Record credentialDefinitions: Record + version?: string }): ObjectHandle { const schemaKeys = Object.keys(options.schemas) const schemaValues = Object.values(options.schemas).map((o) => o.handle) @@ -465,7 +466,8 @@ export class ReactNativeAnoncreds implements Anoncreds { schemas: schemaValues, schemaIds: schemaKeys, credentialDefinitions: credentialDefinitionValues, - credentialDefinitionIds: credentialDefinitionKeys + credentialDefinitionIds: credentialDefinitionKeys, + version: options.version }) ) return new ObjectHandle(handle) @@ -486,8 +488,13 @@ export class ReactNativeAnoncreds implements Anoncreds { return Boolean(this.handleError(this.anoncreds.verifyW3cPresentation(serializeArguments(options)))) } - public w3cCredentialGetAttribute(options: { objectHandle: ObjectHandle; name: string }): string { - return this.handleError(this.anoncreds.w3cCredentialGetAttribute(serializeArguments(options))) + public w3cCredentialGetIntegrityProofDetails(options: { objectHandle: ObjectHandle }): ObjectHandle { + const handle = this.handleError(this.anoncreds.w3cCredentialGetIntegrityProofDetails(serializeArguments(options))) + return new ObjectHandle(handle) + } + + public w3cCredentialProofGetAttribute(options: { objectHandle: ObjectHandle; name: string }): string { + return this.handleError(this.anoncreds.w3cCredentialProofGetAttribute(serializeArguments(options))) } public w3cPresentationFromJson(options: { json: string }): ObjectHandle { @@ -500,7 +507,11 @@ export class ReactNativeAnoncreds implements Anoncreds { return new ObjectHandle(handle) } - public credentialToW3c(options: { objectHandle: ObjectHandle; credentialDefinition: ObjectHandle }): ObjectHandle { + public credentialToW3c(options: { + objectHandle: ObjectHandle + credentialDefinition: ObjectHandle + version?: 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 0853e839..73f92be3 100644 --- a/wrappers/javascript/packages/anoncreds-shared/src/Anoncreds.ts +++ b/wrappers/javascript/packages/anoncreds-shared/src/Anoncreds.ts @@ -212,7 +212,7 @@ export type Anoncreds = { credentialRequest: ObjectHandle attributeRawValues: Record revocationConfiguration?: NativeCredentialRevocationConfig - encoding?: string + version?: string }): ObjectHandle processW3cCredential(options: { @@ -230,6 +230,7 @@ export type Anoncreds = { linkSecret: string schemas: Record credentialDefinitions: Record + version?: string }): ObjectHandle verifyW3cPresentation(options: { @@ -247,11 +248,17 @@ export type Anoncreds = { w3cPresentationFromJson(options: { json: string }): ObjectHandle - w3cCredentialGetAttribute(options: { objectHandle: ObjectHandle; name: string }): string - w3cCredentialFromJson(options: { json: string }): ObjectHandle - credentialToW3c(options: { objectHandle: ObjectHandle; credentialDefinition: ObjectHandle }): ObjectHandle + credentialToW3c(options: { + objectHandle: ObjectHandle + credentialDefinition: ObjectHandle + version?: string + }): ObjectHandle credentialFromW3c(options: { objectHandle: ObjectHandle }): ObjectHandle + + w3cCredentialGetIntegrityProofDetails(options: { objectHandle: ObjectHandle }): ObjectHandle + + w3cCredentialProofGetAttribute(options: { objectHandle: ObjectHandle; name: string }): string } diff --git a/wrappers/javascript/packages/anoncreds-shared/src/api/Credential.ts b/wrappers/javascript/packages/anoncreds-shared/src/api/Credential.ts index 5081a1b9..56ff65f9 100644 --- a/wrappers/javascript/packages/anoncreds-shared/src/api/Credential.ts +++ b/wrappers/javascript/packages/anoncreds-shared/src/api/Credential.ts @@ -36,6 +36,7 @@ export type ProcessCredentialOptions = { export type CredentialToW3cOptions = { credentialDefinition: CredentialDefinition | JsonObject + version?: string } export type CredentialFromW3cOptions = { @@ -162,7 +163,8 @@ export class Credential extends AnoncredsObject { credential = new W3cCredential( anoncreds.credentialToW3c({ objectHandle: this.handle, - credentialDefinition + credentialDefinition, + version: options.version }).handle ) } finally { diff --git a/wrappers/javascript/packages/anoncreds-shared/src/api/W3cCredential.ts b/wrappers/javascript/packages/anoncreds-shared/src/api/W3cCredential.ts index 84c4f579..4eb479d1 100644 --- a/wrappers/javascript/packages/anoncreds-shared/src/api/W3cCredential.ts +++ b/wrappers/javascript/packages/anoncreds-shared/src/api/W3cCredential.ts @@ -24,7 +24,7 @@ export type CreateW3cCredentialOptions = { revocationRegistryId?: string revocationConfiguration?: CredentialRevocationConfig revocationStatusList?: RevocationStatusList | JsonObject - encoding?: string + version?: string } export type ProcessW3cCredentialOptions = { @@ -37,9 +37,12 @@ export type ProcessW3cCredentialOptions = { export type W3cCredentialFromLegacyOptions = { credential: Credential credentialDefinition: CredentialDefinition | JsonObject + version?: string } export class W3cCredential extends AnoncredsObject { + private proofDetails?: ObjectHandle + public static create(options: CreateW3cCredentialOptions) { let credential // Objects created within this method must be freed up @@ -72,7 +75,7 @@ export class W3cCredential extends AnoncredsObject { credentialRequest, attributeRawValues: options.attributeRawValues, revocationConfiguration: options.revocationConfiguration?.native, - encoding: options.encoding + version: options.version }) } finally { objectHandles.forEach((handle) => { @@ -130,20 +133,37 @@ export class W3cCredential extends AnoncredsObject { return this } + private getProofDetails(): ObjectHandle { + if (!this.proofDetails) { + this.proofDetails = anoncreds.w3cCredentialGetIntegrityProofDetails({ objectHandle: this.handle }) + } + return this.proofDetails + } + public get schemaId() { - return anoncreds.w3cCredentialGetAttribute({ objectHandle: this.handle, name: 'schema_id' }) + const proofDetails = this.getProofDetails() + return anoncreds.w3cCredentialProofGetAttribute({ objectHandle: proofDetails, name: 'schema_id' }) } public get credentialDefinitionId() { - return anoncreds.w3cCredentialGetAttribute({ objectHandle: this.handle, name: 'cred_def_id' }) + const proofDetails = this.getProofDetails() + return anoncreds.w3cCredentialProofGetAttribute({ objectHandle: proofDetails, name: 'cred_def_id' }) } public get revocationRegistryId() { - return anoncreds.w3cCredentialGetAttribute({ objectHandle: this.handle, name: 'rev_reg_id' }) + const proofDetails = this.getProofDetails() + return anoncreds.w3cCredentialProofGetAttribute({ objectHandle: proofDetails, name: 'rev_reg_id' }) } public get revocationRegistryIndex() { - const index = anoncreds.w3cCredentialGetAttribute({ objectHandle: this.handle, name: 'rev_reg_index' }) + const proofDetails = this.getProofDetails() + const index = anoncreds.w3cCredentialProofGetAttribute({ objectHandle: proofDetails, name: 'rev_reg_index' }) + return index ? Number(index) : undefined + } + + public get timestamp() { + const proofDetails = this.getProofDetails() + const index = anoncreds.w3cCredentialProofGetAttribute({ objectHandle: proofDetails, name: 'timestamp' }) return index ? Number(index) : undefined } @@ -168,7 +188,8 @@ export class W3cCredential extends AnoncredsObject { credential = new W3cCredential( anoncreds.credentialToW3c({ objectHandle: options.credential.handle, - credentialDefinition + credentialDefinition, + version: options.version }).handle ) } finally { diff --git a/wrappers/python/anoncreds/__init__.py b/wrappers/python/anoncreds/__init__.py index 551f9f82..846a8843 100644 --- a/wrappers/python/anoncreds/__init__.py +++ b/wrappers/python/anoncreds/__init__.py @@ -22,7 +22,6 @@ RevocationRegistryDefinition, RevocationRegistryDefinitionPrivate, W3cCredential, - W3cCredentialProofDetails, W3cPresentation, ) @@ -52,6 +51,5 @@ "RevocationRegistryDefinitionPrivate", "Schema", "W3cCredential", - "W3cCredentialProofDetails", "W3cPresentation" ) diff --git a/wrappers/python/anoncreds/types.py b/wrappers/python/anoncreds/types.py index 9b27db46..bf05e055 100644 --- a/wrappers/python/anoncreds/types.py +++ b/wrappers/python/anoncreds/types.py @@ -367,60 +367,9 @@ def from_w3c(cls, cred: "W3cCredential") -> "Credential": ) -class W3cCredentialProofDetails(bindings.AnoncredsObject): - GET_ATTR = "anoncreds_w3c_credential_proof_get_attribute" - - @property - def schema_id(self) -> str: - return str( - bindings._object_get_attribute( - self.GET_ATTR, - self.handle, - "schema_id", - ) - ) - - @property - def cred_def_id(self) -> str: - return str( - bindings._object_get_attribute( - self.GET_ATTR, - self.handle, - "cred_def_id", - ) - ) - - @property - def rev_reg_id(self) -> str: - return str( - bindings._object_get_attribute( - self.GET_ATTR, - self.handle, - "rev_reg_id", - ) - ) - - @property - def rev_reg_index(self) -> Optional[int]: - sval = bindings._object_get_attribute( - self.GET_ATTR, - self.handle, - "rev_reg_index", - ) - return int(str(sval)) if sval is not None else None - - @property - def timestamp(self) -> Optional[int]: - sval = bindings._object_get_attribute( - self.GET_ATTR, - self.handle, - "timestamp", - ) - return int(str(sval)) if sval is not None else None - - class W3cCredential(bindings.AnoncredsObject): - GET_ATTR = "anoncreds_w3c_credential_get_attribute" + GET_ATTR = "anoncreds_w3c_credential_proof_get_attribute" + _proof_details = None @classmethod def create( @@ -481,12 +430,6 @@ def load(cls, value: Union[dict, str, bytes, memoryview]) -> "W3cCredential": bindings._object_from_json("anoncreds_w3c_credential_from_json", value) ) - @property - def proof_details(self) -> "W3cCredentialProofDetails": - return W3cCredentialProofDetails( - bindings.w3c_credential_get_integrity_proof_details(self.handle) - ) - def to_legacy( self ) -> "Credential": @@ -501,6 +444,65 @@ def from_legacy( ) -> "W3cCredential": return cred.to_w3c(cred_def, version) + def _get_proof_details(self) -> bindings.ObjectHandle: + if self._proof_details == None: + self._proof_details = bindings.w3c_credential_get_integrity_proof_details(self.handle) + return self._proof_details + + + @property + def schema_id(self) -> str: + proof_details = self._get_proof_details() + return str( + bindings._object_get_attribute( + self.GET_ATTR, + proof_details, + "schema_id", + ) + ) + + @property + def cred_def_id(self) -> str: + proof_details = self._get_proof_details() + return str( + bindings._object_get_attribute( + self.GET_ATTR, + proof_details, + "cred_def_id", + ) + ) + + @property + def rev_reg_id(self) -> str: + proof_details = self._get_proof_details() + return str( + bindings._object_get_attribute( + self.GET_ATTR, + proof_details, + "rev_reg_id", + ) + ) + + @property + def rev_reg_index(self) -> Optional[int]: + proof_details = self._get_proof_details() + sval = bindings._object_get_attribute( + self.GET_ATTR, + proof_details, + "rev_reg_index", + ) + return int(str(sval)) if sval is not None else None + + @property + def timestamp(self) -> Optional[int]: + proof_details = self._get_proof_details() + sval = bindings._object_get_attribute( + self.GET_ATTR, + proof_details, + "timestamp", + ) + return int(str(sval)) if sval is not None else None + class PresentationRequest(bindings.AnoncredsObject): @classmethod diff --git a/wrappers/python/demo/w3c_test.py b/wrappers/python/demo/w3c_test.py index 3f0d4f57..916c8e10 100644 --- a/wrappers/python/demo/w3c_test.py +++ b/wrappers/python/demo/w3c_test.py @@ -3,7 +3,6 @@ create_link_secret, Credential, W3cCredential, - W3cCredentialProofDetails, CredentialDefinition, CredentialOffer, CredentialRequest, @@ -76,11 +75,10 @@ cred_request_metadata, link_secret, cred_def_pub, rev_reg_def_pub ) -proof_details = recv_cred.proof_details -assert schema_id == proof_details.schema_id -assert cred_def_id == proof_details.cred_def_id -assert rev_idx == proof_details.rev_reg_index -assert None == proof_details.timestamp +assert schema_id == recv_cred.schema_id +assert cred_def_id == recv_cred.cred_def_id +assert rev_idx == recv_cred.rev_reg_index +assert None == recv_cred.timestamp print("W3c Credential") print(recv_cred.to_json()) From 1c3c30b0e7850553935bfa432cc1458fcb73c402 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Wed, 20 Dec 2023 13:29:44 +0300 Subject: [PATCH 17/21] Corrected context definition Signed-off-by: artem.ivanov --- src/data_types/w3c/context.rs | 1 + src/data_types/w3c/proof.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/data_types/w3c/context.rs b/src/data_types/w3c/context.rs index 586f34b7..5fb5e99c 100644 --- a/src/data_types/w3c/context.rs +++ b/src/data_types/w3c/context.rs @@ -6,6 +6,7 @@ use crate::data_types::w3c::uri::URI; use crate::data_types::w3c::VerifiableCredentialSpecVersion; #[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] +#[serde(untagged)] pub enum Context { URI(URI), Object(serde_json::Value), diff --git a/src/data_types/w3c/proof.rs b/src/data_types/w3c/proof.rs index ee22ba8c..e30a0653 100644 --- a/src/data_types/w3c/proof.rs +++ b/src/data_types/w3c/proof.rs @@ -145,6 +145,7 @@ impl DataIntegrityProof { pub struct CredentialSignatureProof { pub schema_id: SchemaId, pub cred_def_id: CredentialDefinitionId, + #[serde(skip_serializing_if = "Option::is_none")] pub rev_reg_id: Option, pub signature: CLCredentialSignature, pub signature_correctness_proof: SignatureCorrectnessProof, From 67d456b342e8312141066bb08f8fdba1362d0b25 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Wed, 20 Dec 2023 13:56:19 +0300 Subject: [PATCH 18/21] Returned rust version to 1.65.0 Signed-off-by: artem.ivanov --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e9b2c678..1dd1030a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,7 +1,7 @@ name: "Anoncreds" env: - RUST_VERSION: "1.70.0" + RUST_VERSION: "1.65.0" CROSS_VERSION: "0.2.4" on: From 5094192558c00d963554b9f3e20d7cf26f25fdc9 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Wed, 20 Dec 2023 15:21:15 +0300 Subject: [PATCH 19/21] Fixed prettier error Signed-off-by: artem.ivanov --- .../javascript/packages/anoncreds-nodejs/tests/bindings.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wrappers/javascript/packages/anoncreds-nodejs/tests/bindings.test.ts b/wrappers/javascript/packages/anoncreds-nodejs/tests/bindings.test.ts index c4d2b0a5..7e3e8966 100644 --- a/wrappers/javascript/packages/anoncreds-nodejs/tests/bindings.test.ts +++ b/wrappers/javascript/packages/anoncreds-nodejs/tests/bindings.test.ts @@ -713,7 +713,7 @@ describe('bindings', () => { }) const credentialProofDetails = anoncreds.w3cCredentialGetIntegrityProofDetails({ - objectHandle: credentialReceived, + objectHandle: credentialReceived }) const revRegIndex = anoncreds.w3cCredentialProofGetAttribute({ From 65c7ca6892be6abbc3c37890257220e5483c00d2 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Thu, 21 Dec 2023 10:48:57 +0300 Subject: [PATCH 20/21] Renamed parameter from version to w3cVersion Signed-off-by: artem.ivanov --- .../anoncreds-nodejs/src/NodeJSAnoncreds.ts | 18 +++++++++--------- .../anoncreds-react-native/cpp/anoncreds.cpp | 18 +++++++++--------- .../cpp/include/libanoncreds.h | 6 +++--- .../src/NativeBindings.ts | 6 +++--- .../src/ReactNativeAnoncreds.ts | 10 +++++----- .../packages/anoncreds-shared/src/Anoncreds.ts | 6 +++--- .../anoncreds-shared/src/api/Credential.ts | 4 ++-- .../anoncreds-shared/src/api/W3cCredential.ts | 8 ++++---- wrappers/python/anoncreds/bindings.py | 12 ++++++------ wrappers/python/anoncreds/types.py | 16 ++++++++-------- 10 files changed, 52 insertions(+), 52 deletions(-) diff --git a/wrappers/javascript/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts b/wrappers/javascript/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts index 80c75d09..56e4a1e0 100644 --- a/wrappers/javascript/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts +++ b/wrappers/javascript/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts @@ -525,9 +525,9 @@ export class NodeJSAnoncreds implements Anoncreds { credentialRequest: ObjectHandle attributeRawValues: Record revocationConfiguration?: NativeCredentialRevocationConfig - version?: string + w3cVersion?: string }): ObjectHandle { - const { credentialDefinition, credentialDefinitionPrivate, credentialOffer, credentialRequest, version } = + const { credentialDefinition, credentialDefinitionPrivate, credentialOffer, credentialRequest, w3cVersion } = serializeArguments(options) const attributeNames = this.convertAttributeNames(options.attributeRawValues) @@ -543,7 +543,7 @@ export class NodeJSAnoncreds implements Anoncreds { attributeNames as unknown as Buffer, attributeRawValues as unknown as Buffer, revocationConfiguration?.ref().address() ?? 0, - version, + w3cVersion, credentialPtr ) this.handleError() @@ -582,9 +582,9 @@ export class NodeJSAnoncreds implements Anoncreds { linkSecret: string schemas: Record credentialDefinitions: Record - version?: string + w3cVersion?: string }): ObjectHandle { - const { presentationRequest, linkSecret, version } = serializeArguments(options) + const { presentationRequest, linkSecret, w3cVersion } = serializeArguments(options) const credentialEntryList = this.convertCredentialList(options.credentials) const credentialProveList = this.convertCredentialProves(options.credentialsProve) @@ -602,7 +602,7 @@ export class NodeJSAnoncreds implements Anoncreds { schemaIds as unknown as Buffer, credentialDefinitions as unknown as Buffer, credentialDefinitionIds as unknown as Buffer, - version, + w3cVersion, ret ) this.handleError() @@ -659,13 +659,13 @@ export class NodeJSAnoncreds implements Anoncreds { public credentialToW3c(options: { objectHandle: ObjectHandle credentialDefinition: ObjectHandle - version?: string + w3cVersion?: string }): ObjectHandle { - const { objectHandle, credentialDefinition, version } = serializeArguments(options) + const { objectHandle, credentialDefinition, w3cVersion } = serializeArguments(options) const ret = allocatePointer() - this.nativeAnoncreds.anoncreds_credential_to_w3c(objectHandle, credentialDefinition, version, ret) + this.nativeAnoncreds.anoncreds_credential_to_w3c(objectHandle, credentialDefinition, w3cVersion, ret) this.handleError() return new ObjectHandle(handleReturnPointer(ret)) diff --git a/wrappers/javascript/packages/anoncreds-react-native/cpp/anoncreds.cpp b/wrappers/javascript/packages/anoncreds-react-native/cpp/anoncreds.cpp index 74801d4c..59b2e142 100644 --- a/wrappers/javascript/packages/anoncreds-react-native/cpp/anoncreds.cpp +++ b/wrappers/javascript/packages/anoncreds-react-native/cpp/anoncreds.cpp @@ -726,15 +726,15 @@ jsi::Value createW3cPresentation(jsi::Runtime &rt, jsi::Object options) { jsiToValue(rt, options, "credentialDefinitions"); auto credentialDefinitionIds = jsiToValue(rt, options, "credentialDefinitionIds"); - auto version = - jsiToValue(rt, options, "version", true); + auto w3cVersion = + jsiToValue(rt, options, "w3cVersion", true); ObjectHandle out; ErrorCode code = anoncreds_create_w3c_presentation( presentationRequest, credentials, credentialsProve, linkSecret.c_str(), schemas, schemaIds, credentialDefinitions, credentialDefinitionIds, - version.length() ? version.c_str() : nullptr, &out); + w3cVersion.length() ? w3cVersion.c_str() : nullptr, &out); auto returnValue = createReturnValue(rt, code, &out); @@ -812,8 +812,8 @@ jsi::Value createW3cCredential(jsi::Runtime &rt, jsi::Object options) { jsiToValue(rt, options, "attributeRawValues"); auto revocation = jsiToValue(rt, options, "revocationConfiguration", true); - auto version = - jsiToValue(rt, options, "version", true); + auto w3cVersion = + jsiToValue(rt, options, "w3cVersion", true); ObjectHandle out; @@ -821,7 +821,7 @@ jsi::Value createW3cCredential(jsi::Runtime &rt, jsi::Object options) { credentialDefinition, credentialDefinitionPrivate, credentialOffer, credentialRequest, attributeNames, attributeRawValues, revocation.reg_def ? &revocation : 0, - version.length() ? version.c_str() : nullptr, &out); + w3cVersion.length() ? w3cVersion.c_str() : nullptr, &out); return createReturnValue(rt, code, &out); }; @@ -872,14 +872,14 @@ jsi::Value credentialToW3c(jsi::Runtime &rt, jsi::Object options) { auto credential = jsiToValue(rt, options, "objectHandle"); auto credentialDefinition = jsiToValue(rt, options, "credentialDefinition"); - auto version = - jsiToValue(rt, options, "version", true); + auto w3cVersion = + jsiToValue(rt, options, "w3cVersion", true); ObjectHandle out; ErrorCode code = anoncreds_credential_to_w3c( credential, credentialDefinition, - version.length() ? version.c_str() : nullptr, &out); + w3cVersion.length() ? w3cVersion.c_str() : nullptr, &out); return createReturnValue(rt, code, &out); }; diff --git a/wrappers/javascript/packages/anoncreds-react-native/cpp/include/libanoncreds.h b/wrappers/javascript/packages/anoncreds-react-native/cpp/include/libanoncreds.h index de3a39e9..b6310bdc 100644 --- a/wrappers/javascript/packages/anoncreds-react-native/cpp/include/libanoncreds.h +++ b/wrappers/javascript/packages/anoncreds-react-native/cpp/include/libanoncreds.h @@ -447,7 +447,7 @@ ErrorCode anoncreds_create_w3c_credential(ObjectHandle cred_def, FfiStrList attr_names, FfiStrList attr_raw_values, const struct FfiCredRevInfo *revocation, - FfiStr version, + FfiStr w3c_version, ObjectHandle *cred_p); ErrorCode anoncreds_process_w3c_credential(ObjectHandle cred, @@ -459,7 +459,7 @@ ErrorCode anoncreds_process_w3c_credential(ObjectHandle cred, ErrorCode anoncreds_credential_to_w3c(ObjectHandle cred, ObjectHandle cred_def, - FfiStr version, + FfiStr w3c_version, ObjectHandle *cred_p); ErrorCode anoncreds_credential_from_w3c(ObjectHandle cred, @@ -473,7 +473,7 @@ ErrorCode anoncreds_create_w3c_presentation(ObjectHandle pres_req, FfiStrList schema_ids, struct FfiList_ObjectHandle cred_defs, FfiStrList cred_def_ids, - FfiStr version, + FfiStr w3c_version, ObjectHandle *presentation_p); ErrorCode anoncreds_verify_w3c_presentation(ObjectHandle presentation, diff --git a/wrappers/javascript/packages/anoncreds-react-native/src/NativeBindings.ts b/wrappers/javascript/packages/anoncreds-react-native/src/NativeBindings.ts index 8a33956b..2a531475 100644 --- a/wrappers/javascript/packages/anoncreds-react-native/src/NativeBindings.ts +++ b/wrappers/javascript/packages/anoncreds-react-native/src/NativeBindings.ts @@ -199,7 +199,7 @@ export type NativeBindings = { revocationRegistryDefinitionPrivate: number revocationStatusList?: number } - version?: string + w3cVersion?: string }): ReturnObject processW3cCredential(options: { @@ -217,7 +217,7 @@ export type NativeBindings = { credentialToW3c(options: { objectHandle: number credentialDefinition: number - version?: string + w3cVersion?: string }): ReturnObject credentialFromW3c(options: { objectHandle: number }): ReturnObject @@ -231,7 +231,7 @@ export type NativeBindings = { schemas: number[] credentialDefinitionIds: string[] credentialDefinitions: number[] - version?: string + w3cVersion?: string }): ReturnObject verifyW3cPresentation(options: { diff --git a/wrappers/javascript/packages/anoncreds-react-native/src/ReactNativeAnoncreds.ts b/wrappers/javascript/packages/anoncreds-react-native/src/ReactNativeAnoncreds.ts index 6c28e34b..254dfead 100644 --- a/wrappers/javascript/packages/anoncreds-react-native/src/ReactNativeAnoncreds.ts +++ b/wrappers/javascript/packages/anoncreds-react-native/src/ReactNativeAnoncreds.ts @@ -400,7 +400,7 @@ export class ReactNativeAnoncreds implements Anoncreds { credentialRequest: ObjectHandle attributeRawValues: Record revocationConfiguration?: NativeCredentialRevocationConfig - version?: string + w3cVersion?: string }): ObjectHandle { const attributeNames = Object.keys(options.attributeRawValues) const attributeRawValues = Object.values(options.attributeRawValues) @@ -419,7 +419,7 @@ export class ReactNativeAnoncreds implements Anoncreds { revocationStatusList: options.revocationConfiguration.revocationStatusList.handle } : undefined, - version: options.version + w3cVersion: options.w3cVersion }) ) @@ -444,7 +444,7 @@ export class ReactNativeAnoncreds implements Anoncreds { linkSecret: string schemas: Record credentialDefinitions: Record - version?: string + w3cVersion?: string }): ObjectHandle { const schemaKeys = Object.keys(options.schemas) const schemaValues = Object.values(options.schemas).map((o) => o.handle) @@ -467,7 +467,7 @@ export class ReactNativeAnoncreds implements Anoncreds { schemaIds: schemaKeys, credentialDefinitions: credentialDefinitionValues, credentialDefinitionIds: credentialDefinitionKeys, - version: options.version + w3cVersion: options.w3cVersion }) ) return new ObjectHandle(handle) @@ -510,7 +510,7 @@ export class ReactNativeAnoncreds implements Anoncreds { public credentialToW3c(options: { objectHandle: ObjectHandle credentialDefinition: ObjectHandle - version?: 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 73f92be3..e011fe47 100644 --- a/wrappers/javascript/packages/anoncreds-shared/src/Anoncreds.ts +++ b/wrappers/javascript/packages/anoncreds-shared/src/Anoncreds.ts @@ -212,7 +212,7 @@ export type Anoncreds = { credentialRequest: ObjectHandle attributeRawValues: Record revocationConfiguration?: NativeCredentialRevocationConfig - version?: string + w3cVersion?: string }): ObjectHandle processW3cCredential(options: { @@ -230,7 +230,7 @@ export type Anoncreds = { linkSecret: string schemas: Record credentialDefinitions: Record - version?: string + w3cVersion?: string }): ObjectHandle verifyW3cPresentation(options: { @@ -253,7 +253,7 @@ export type Anoncreds = { credentialToW3c(options: { objectHandle: ObjectHandle credentialDefinition: ObjectHandle - version?: 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 56ff65f9..3982ded8 100644 --- a/wrappers/javascript/packages/anoncreds-shared/src/api/Credential.ts +++ b/wrappers/javascript/packages/anoncreds-shared/src/api/Credential.ts @@ -36,7 +36,7 @@ export type ProcessCredentialOptions = { export type CredentialToW3cOptions = { credentialDefinition: CredentialDefinition | JsonObject - version?: string + w3cVersion?: string } export type CredentialFromW3cOptions = { @@ -164,7 +164,7 @@ export class Credential extends AnoncredsObject { anoncreds.credentialToW3c({ objectHandle: this.handle, credentialDefinition, - version: options.version + w3cVersion: options.w3cVersion }).handle ) } finally { diff --git a/wrappers/javascript/packages/anoncreds-shared/src/api/W3cCredential.ts b/wrappers/javascript/packages/anoncreds-shared/src/api/W3cCredential.ts index 4eb479d1..9f3c69cf 100644 --- a/wrappers/javascript/packages/anoncreds-shared/src/api/W3cCredential.ts +++ b/wrappers/javascript/packages/anoncreds-shared/src/api/W3cCredential.ts @@ -24,7 +24,7 @@ export type CreateW3cCredentialOptions = { revocationRegistryId?: string revocationConfiguration?: CredentialRevocationConfig revocationStatusList?: RevocationStatusList | JsonObject - version?: string + w3cVersion?: string } export type ProcessW3cCredentialOptions = { @@ -37,7 +37,7 @@ export type ProcessW3cCredentialOptions = { export type W3cCredentialFromLegacyOptions = { credential: Credential credentialDefinition: CredentialDefinition | JsonObject - version?: string + w3cVersion?: string } export class W3cCredential extends AnoncredsObject { @@ -75,7 +75,7 @@ export class W3cCredential extends AnoncredsObject { credentialRequest, attributeRawValues: options.attributeRawValues, revocationConfiguration: options.revocationConfiguration?.native, - version: options.version + w3cVersion: options.w3cVersion }) } finally { objectHandles.forEach((handle) => { @@ -189,7 +189,7 @@ export class W3cCredential extends AnoncredsObject { anoncreds.credentialToW3c({ objectHandle: options.credential.handle, credentialDefinition, - version: options.version + w3cVersion: options.w3cVersion }).handle ) } finally { diff --git a/wrappers/python/anoncreds/bindings.py b/wrappers/python/anoncreds/bindings.py index d0887478..c4073379 100644 --- a/wrappers/python/anoncreds/bindings.py +++ b/wrappers/python/anoncreds/bindings.py @@ -973,7 +973,7 @@ def create_w3c_credential( cred_request: ObjectHandle, attr_raw_values: Mapping[str, str], revocation_config: Optional[RevocationConfig], - version: Optional[str], + w3c_version: Optional[str], ) -> ObjectHandle: cred = ObjectHandle() attr_keys = list(attr_raw_values.keys()) @@ -990,7 +990,7 @@ def create_w3c_credential( pointer(revocation_config) if revocation_config else POINTER(RevocationConfig)(), - encode_str(version), + encode_str(w3c_version), byref(cred), ) return cred @@ -1019,14 +1019,14 @@ def process_w3c_credential( def credential_to_w3c( cred: ObjectHandle, cred_def: ObjectHandle, - version: Optional[str], + w3c_version: Optional[str], ) -> ObjectHandle: result = ObjectHandle() do_call( "anoncreds_credential_to_w3c", cred, cred_def, - encode_str(version), + encode_str(w3c_version), byref(result), ) return result @@ -1053,7 +1053,7 @@ def create_w3c_presentation( schema_ids: Sequence[str], cred_defs: Sequence[ObjectHandle], cred_def_ids: Sequence[str], - version: Optional[str], + w3c_version: Optional[str], ) -> ObjectHandle: entry_list = CredentialEntryList() entry_list.count = len(credentials) @@ -1073,7 +1073,7 @@ def create_w3c_presentation( FfiStrList.create(schema_ids), FfiObjectHandleList.create(cred_defs), FfiStrList.create(cred_def_ids), - encode_str(version), + encode_str(w3c_version), byref(present), ) return present diff --git a/wrappers/python/anoncreds/types.py b/wrappers/python/anoncreds/types.py index bf05e055..3410396e 100644 --- a/wrappers/python/anoncreds/types.py +++ b/wrappers/python/anoncreds/types.py @@ -346,7 +346,7 @@ def rev_reg_index(self) -> Optional[int]: def to_w3c( self, cred_def: Union[str, CredentialDefinition], - version: Optional[str] = None, + w3c_version: Optional[str] = None, ) -> "W3cCredential": if not isinstance(cred_def, bindings.AnoncredsObject): cred_def = CredentialDefinition.load(cred_def) @@ -354,7 +354,7 @@ def to_w3c( bindings.credential_to_w3c( self.handle, cred_def.handle, - version + w3c_version ) ) @@ -380,7 +380,7 @@ def create( cred_request: Union[str, CredentialRequest], attr_raw_values: Mapping[str, str], revocation_config: Optional["CredentialRevocationConfig"] = None, - version: Optional[str] = None, + w3c_version: Optional[str] = None, ) -> "W3cCredential": if not isinstance(cred_def, bindings.AnoncredsObject): cred_def = CredentialDefinition.load(cred_def) @@ -397,7 +397,7 @@ def create( cred_request.handle, attr_raw_values, revocation_config._native if revocation_config else None, - version, + w3c_version, ) return W3cCredential(cred) @@ -440,9 +440,9 @@ def from_legacy( cls, cred: "Credential", cred_def: Union[str, CredentialDefinition], - version: Optional[str] = None + w3c_version: Optional[str] = None ) -> "W3cCredential": - return cred.to_w3c(cred_def, version) + return cred.to_w3c(cred_def, w3c_version) def _get_proof_details(self) -> bindings.ObjectHandle: if self._proof_details == None: @@ -722,7 +722,7 @@ def create( link_secret: str, schemas: Mapping[str, Union[str, Schema]], cred_defs: Mapping[str, Union[str, CredentialDefinition]], - version: Optional[str] = None, + w3c_version: Optional[str] = None, ) -> "W3cPresentation": if not isinstance(pres_req, bindings.AnoncredsObject): pres_req = PresentationRequest.load(pres_req) @@ -770,7 +770,7 @@ def create( schema_ids, cred_def_handles, cred_def_ids, - version, + w3c_version, ) ) From f0c2901092687eaf45d9f8c1fea78b079399a2e3 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Mon, 15 Jan 2024 15:27:08 +0300 Subject: [PATCH 21/21] Fixed couple comments Signed-off-by: artem.ivanov --- .../anoncreds-nodejs/src/NodeJSAnoncreds.ts | 54 +++++++++---------- .../anoncreds-shared/src/api/index.ts | 1 - wrappers/python/anoncreds/types.py | 2 +- 3 files changed, 28 insertions(+), 29 deletions(-) diff --git a/wrappers/javascript/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts b/wrappers/javascript/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts index 56e4a1e0..fe7c76a9 100644 --- a/wrappers/javascript/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts +++ b/wrappers/javascript/packages/anoncreds-nodejs/src/NodeJSAnoncreds.ts @@ -163,8 +163,8 @@ export class NodeJSAnoncreds implements Anoncreds { credentialDefinitionPrivate, credentialOffer, credentialRequest, - attributeNames as unknown as Buffer, - attributeRawValues as unknown as Buffer, + attributeNames, + attributeRawValues, attributeEncodedValues as unknown as Buffer, revocationConfiguration?.ref().address() ?? 0, credentialPtr @@ -296,15 +296,15 @@ export class NodeJSAnoncreds implements Anoncreds { this.nativeAnoncreds.anoncreds_create_presentation( presentationRequest, - credentialEntryList as unknown as Buffer, - credentialProveList as unknown as Buffer, + credentialEntryList, + credentialProveList, selfAttestNames as unknown as Buffer, selfAttestValues as unknown as Buffer, linkSecret, - schemas as unknown as Buffer, - schemaIds as unknown as Buffer, - credentialDefinitions as unknown as Buffer, - credentialDefinitionIds as unknown as Buffer, + schemas, + schemaIds, + credentialDefinitions, + credentialDefinitionIds, ret ) this.handleError() @@ -350,7 +350,7 @@ export class NodeJSAnoncreds implements Anoncreds { revocationRegistryDefinitions, revocationRegistryDefinitionIds, revocationStatusLists, - nonRevokedIntervalOverrideList as unknown as Buffer, + nonRevokedIntervalOverrideList, ret ) this.handleError() @@ -540,8 +540,8 @@ export class NodeJSAnoncreds implements Anoncreds { credentialDefinitionPrivate, credentialOffer, credentialRequest, - attributeNames as unknown as Buffer, - attributeRawValues as unknown as Buffer, + attributeNames, + attributeRawValues, revocationConfiguration?.ref().address() ?? 0, w3cVersion, credentialPtr @@ -595,13 +595,13 @@ export class NodeJSAnoncreds implements Anoncreds { this.nativeAnoncreds.anoncreds_create_w3c_presentation( presentationRequest, - credentialEntryList as unknown as Buffer, - credentialProveList as unknown as Buffer, + credentialEntryList, + credentialProveList, linkSecret, - schemas as unknown as Buffer, - schemaIds as unknown as Buffer, - credentialDefinitions as unknown as Buffer, - credentialDefinitionIds as unknown as Buffer, + schemas, + schemaIds, + credentialDefinitions, + credentialDefinitionIds, w3cVersion, ret ) @@ -648,7 +648,7 @@ export class NodeJSAnoncreds implements Anoncreds { revocationRegistryDefinitions, revocationRegistryDefinitionIds, revocationStatusLists, - nonRevokedIntervalOverrideList as unknown as Buffer, + nonRevokedIntervalOverrideList, ret ) this.handleError() @@ -850,7 +850,7 @@ export class NodeJSAnoncreds implements Anoncreds { rev_state: number }> > - }) + }) as unknown as Buffer } private convertCredentialProves(credentialsProve: NativeCredentialProve[]) { @@ -869,7 +869,7 @@ export class NodeJSAnoncreds implements Anoncreds { reveal: number }> > - }) + }) as unknown as Buffer } private convertSchemas(schemas: Record) { @@ -877,13 +877,13 @@ export class NodeJSAnoncreds implements Anoncreds { const schemaIds = StringListStruct({ count: schemaKeys.length, data: schemaKeys as unknown as TypedArray - }) + }) as unknown as Buffer const schemaValues = Object.values(schemas) const schemasList = ObjectHandleListStruct({ count: schemaValues.length, data: ObjectHandleArray(schemaValues.map((o) => o.handle)) - }) + }) as unknown as Buffer return { schemaIds, schemas: schemasList @@ -895,13 +895,13 @@ export class NodeJSAnoncreds implements Anoncreds { const credentialDefinitionIds = StringListStruct({ count: credentialDefinitionKeys.length, data: credentialDefinitionKeys as unknown as TypedArray - }) + }) as unknown as Buffer const credentialDefinitionValues = Object.values(credentialDefinitions) const credentialDefinitionsList = ObjectHandleListStruct({ count: credentialDefinitionValues.length, data: ObjectHandleArray(credentialDefinitionValues.map((o) => o.handle)) - }) + }) as unknown as Buffer return { credentialDefinitionIds, credentialDefinitions: credentialDefinitionsList @@ -928,21 +928,21 @@ export class NodeJSAnoncreds implements Anoncreds { override_rev_status_list_ts: number }> > - }) + }) as unknown as Buffer } private convertAttributeNames(attributeRawValues: Record) { return StringListStruct({ count: Object.keys(attributeRawValues).length, data: Object.keys(attributeRawValues) as unknown as TypedArray - }) + }) as unknown as Buffer } private convertAttributeRawValues(attributeRawValues: Record) { return StringListStruct({ count: Object.keys(attributeRawValues).length, data: Object.values(attributeRawValues) as unknown as TypedArray - }) + }) as unknown as Buffer } private convertAttributeEncodedValues(attributeEncodedValues?: Record) { diff --git a/wrappers/javascript/packages/anoncreds-shared/src/api/index.ts b/wrappers/javascript/packages/anoncreds-shared/src/api/index.ts index f32c0bc4..e5e3239c 100644 --- a/wrappers/javascript/packages/anoncreds-shared/src/api/index.ts +++ b/wrappers/javascript/packages/anoncreds-shared/src/api/index.ts @@ -16,5 +16,4 @@ export * from './RevocationRegistryDefinition' export * from './RevocationRegistryDefinitionPrivate' export * from './RevocationStatusList' export * from './W3cCredential' -export * from './CredentialOffer' export * from './W3cPresentation' diff --git a/wrappers/python/anoncreds/types.py b/wrappers/python/anoncreds/types.py index 3410396e..ab49bf93 100644 --- a/wrappers/python/anoncreds/types.py +++ b/wrappers/python/anoncreds/types.py @@ -445,7 +445,7 @@ def from_legacy( return cred.to_w3c(cred_def, w3c_version) def _get_proof_details(self) -> bindings.ObjectHandle: - if self._proof_details == None: + if self._proof_details is None: self._proof_details = bindings.w3c_credential_get_integrity_proof_details(self.handle) return self._proof_details