@0xpolygonid/js-sdk 1.33.1 → 1.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/esm/index.js +1322 -781
- package/dist/browser/esm/index.js.map +1 -1
- package/dist/browser/umd/index.global.js +182 -59
- package/dist/browser/umd/index.global.js.map +1 -1
- package/dist/node/cjs/index.cjs +2059 -1495
- package/dist/node/cjs/index.cjs.map +1 -1
- package/dist/node/esm/index.js +1322 -781
- package/dist/node/esm/index.js.map +1 -1
- package/dist/types/circuits/auth-v3.d.ts +20 -0
- package/dist/types/circuits/auth-v3.d.ts.map +1 -0
- package/dist/types/circuits/index.d.ts +1 -0
- package/dist/types/circuits/index.d.ts.map +1 -1
- package/dist/types/circuits/models.d.ts +2 -0
- package/dist/types/circuits/models.d.ts.map +1 -1
- package/dist/types/iden3comm/constants.d.ts +2 -1
- package/dist/types/iden3comm/constants.d.ts.map +1 -1
- package/dist/types/iden3comm/handlers/auth.d.ts +4 -1
- package/dist/types/iden3comm/handlers/auth.d.ts.map +1 -1
- package/dist/types/iden3comm/handlers/contract-request.d.ts +1 -1
- package/dist/types/iden3comm/handlers/contract-request.d.ts.map +1 -1
- package/dist/types/iden3comm/handlers/credential-proposal.d.ts +2 -2
- package/dist/types/iden3comm/handlers/credential-proposal.d.ts.map +1 -1
- package/dist/types/iden3comm/handlers/fetch.d.ts +2 -2
- package/dist/types/iden3comm/handlers/fetch.d.ts.map +1 -1
- package/dist/types/iden3comm/handlers/message-handler.d.ts +12 -0
- package/dist/types/iden3comm/handlers/message-handler.d.ts.map +1 -1
- package/dist/types/iden3comm/handlers/payment.d.ts +18 -6
- package/dist/types/iden3comm/handlers/payment.d.ts.map +1 -1
- package/dist/types/iden3comm/handlers/refresh.d.ts +4 -1
- package/dist/types/iden3comm/handlers/refresh.d.ts.map +1 -1
- package/dist/types/iden3comm/handlers/revocation-status.d.ts +4 -4
- package/dist/types/iden3comm/handlers/revocation-status.d.ts.map +1 -1
- package/dist/types/iden3comm/packers/zkp.d.ts.map +1 -1
- package/dist/types/iden3comm/types/protocol/payment.d.ts +58 -9
- package/dist/types/iden3comm/types/protocol/payment.d.ts.map +1 -1
- package/dist/types/iden3comm/utils/accept-profile.d.ts +3 -0
- package/dist/types/iden3comm/utils/accept-profile.d.ts.map +1 -1
- package/dist/types/proof/proof-service.d.ts +13 -0
- package/dist/types/proof/proof-service.d.ts.map +1 -1
- package/dist/types/proof/provers/inputs-generator.d.ts.map +1 -1
- package/dist/types/utils/index.d.ts +2 -0
- package/dist/types/utils/index.d.ts.map +1 -1
- package/dist/types/utils/payments/evm.d.ts +19 -0
- package/dist/types/utils/payments/evm.d.ts.map +1 -0
- package/dist/types/utils/payments/solana.d.ts +88 -0
- package/dist/types/utils/payments/solana.d.ts.map +1 -0
- package/dist/types/verifiable/constants.d.ts +16 -3
- package/dist/types/verifiable/constants.d.ts.map +1 -1
- package/package.json +7 -3
- package/src/circuits/auth-v3.ts +19 -0
- package/src/circuits/index.ts +1 -0
- package/src/circuits/models.ts +5 -1
- package/src/iden3comm/constants.ts +2 -1
- package/src/iden3comm/handlers/auth.ts +54 -11
- package/src/iden3comm/handlers/contract-request.ts +1 -1
- package/src/iden3comm/handlers/credential-proposal.ts +12 -6
- package/src/iden3comm/handlers/fetch.ts +29 -6
- package/src/iden3comm/handlers/message-handler.ts +28 -2
- package/src/iden3comm/handlers/payment.ts +190 -144
- package/src/iden3comm/handlers/refresh.ts +9 -13
- package/src/iden3comm/handlers/revocation-status.ts +9 -7
- package/src/iden3comm/packers/zkp.ts +18 -8
- package/src/iden3comm/types/protocol/payment.ts +79 -10
- package/src/iden3comm/utils/accept-profile.ts +24 -0
- package/src/proof/proof-service.ts +93 -25
- package/src/proof/provers/inputs-generator.ts +2 -0
- package/src/proof/provers/prover.ts +1 -1
- package/src/utils/index.ts +2 -0
- package/src/utils/payments/evm.ts +152 -0
- package/src/utils/payments/solana.ts +360 -0
- package/src/verifiable/constants.ts +17 -3
|
@@ -91,8 +91,8 @@ var KMS = class {
|
|
|
91
91
|
};
|
|
92
92
|
|
|
93
93
|
// src/kms/key-providers/bjj-provider.ts
|
|
94
|
-
import { Hex as
|
|
95
|
-
import { BytesHelper, checkBigIntInField } from "@iden3/js-iden3-core";
|
|
94
|
+
import { Hex as Hex4, PrivateKey, PublicKey as PublicKey4, Signature as Signature2 } from "@iden3/js-crypto";
|
|
95
|
+
import { BytesHelper as BytesHelper2, checkBigIntInField } from "@iden3/js-iden3-core";
|
|
96
96
|
|
|
97
97
|
// src/kms/store/abstract-key-store.ts
|
|
98
98
|
var AbstractPrivateKeyStore = class {
|
|
@@ -486,616 +486,337 @@ var bigIntCompare = (a, b) => {
|
|
|
486
486
|
return 0;
|
|
487
487
|
};
|
|
488
488
|
|
|
489
|
-
// src/
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
489
|
+
// src/utils/payments/solana.ts
|
|
490
|
+
import { serialize } from "borsh";
|
|
491
|
+
import { ed25519 } from "@noble/curves/ed25519";
|
|
492
|
+
|
|
493
|
+
// src/verifiable/proof.ts
|
|
494
|
+
import { Hash as Hash2, Proof } from "@iden3/js-merkletree";
|
|
495
|
+
|
|
496
|
+
// src/verifiable/constants.ts
|
|
497
|
+
var VerifiableConstants = Object.freeze({
|
|
498
|
+
ERRORS: {
|
|
499
|
+
FiELD_IS_EMPTY: "fieldPath is empty",
|
|
500
|
+
CONTEXT_TYPE_IS_EMPTY: "ctxType is empty",
|
|
501
|
+
// ErrStateNotFound issuer state is genesis state.
|
|
502
|
+
IDENTITY_DOES_NOT_EXIST: "Identity does not exist",
|
|
503
|
+
IDENTITY_DOES_NOT_EXIST_CUSTOM_ERROR: "IdentityDoesNotExist",
|
|
504
|
+
NO_AUTH_CRED_FOUND: "no auth credentials found",
|
|
505
|
+
STATE_DOES_NOT_EXIST: "State does not exist",
|
|
506
|
+
STATE_DOES_NOT_EXIST_CUSTOM_ERROR: "StateDoesNotExist",
|
|
507
|
+
ROOT_DOES_NOT_EXIST: "Root does not exist",
|
|
508
|
+
ROOT_DOES_NOT_EXIST_CUSTOM_ERROR: "RootDoesNotExist",
|
|
509
|
+
// identity wallet
|
|
510
|
+
ID_WALLET_NO_CREDENTIAL_SATISFIED_QUERY: "no credential satisfied query",
|
|
511
|
+
ID_WALLET_SIGNER_IS_REQUIRED: "Ethereum signer is required to create Ethereum identities in order to transit state",
|
|
512
|
+
ID_WALLET_PROVER_IS_REQUIRED: "prover is required to generate proofs for non ethereum identities",
|
|
513
|
+
ID_WALLET_CORE_CLAIM_REQUIRED_IN_SIG_PROOF: "credential must have coreClaim representation in the signature proof",
|
|
514
|
+
ID_WALLET_CORE_CLAIM_REQUIRED_IN_ANY_PROOF: "credential must have coreClaim representation in proofs",
|
|
515
|
+
ID_WALLET_CORE_CLAIM_MISMATCH: "core claim representations is set in both proofs but they are not equal",
|
|
516
|
+
ID_WALLET_CORE_CLAIM_IS_NOT_SET: "core claim is not set in credential proofs",
|
|
517
|
+
ID_WALLET_PROFILE_OR_IDENTITY_NOT_FOUND: "profile or identity not found",
|
|
518
|
+
ID_WALLET_PROFILE_ALREADY_EXISTS: "profile with given nonce or verifier already exists",
|
|
519
|
+
ID_WALLET_PROFILE_ALREADY_EXISTS_VERIFIER_TAGS: "profile with given verifier and tags already exists",
|
|
520
|
+
ID_WALLET_ISSUER_AUTH_BJJ_CRED_MUST_HAVE_ANY_PROOF: "issuer auth credential must have proof",
|
|
521
|
+
ID_WALLET_ISSUER_AUTH_BJJ_CRED_MUST_HAVE_MTP_PROOF: "mtp is required for auth bjj key to issue new credentials",
|
|
522
|
+
// proof service
|
|
523
|
+
PROOF_SERVICE_NO_CREDENTIAL_FOR_IDENTITY_OR_PROFILE: "no credentials belong to did or its profiles",
|
|
524
|
+
PROOF_SERVICE_NO_CREDENTIAL_FOR_QUERY: "credential not found for query",
|
|
525
|
+
PROOF_SERVICE_PROFILE_GENESIS_DID_MISMATCH: "subject and auth profiles are not derived from the same did",
|
|
526
|
+
PROOF_SERVICE_NO_QUERIES_IN_ZKP_REQUEST: "no queries in zkp request",
|
|
527
|
+
// credential wallet
|
|
528
|
+
CREDENTIAL_WALLET_ALL_CREDENTIALS_ARE_REVOKED: "all claims are revoked"
|
|
529
|
+
},
|
|
530
|
+
CREDENTIAL_TYPE: {
|
|
531
|
+
// VerifiableCredential is a W3C verifiable credential type
|
|
532
|
+
W3C_VERIFIABLE_CREDENTIAL: "VerifiableCredential",
|
|
533
|
+
W3C_VERIFIABLE_PRESENTATION: "VerifiablePresentation"
|
|
534
|
+
},
|
|
535
|
+
CREDENTIAL_SUBJECT_PATH: "https://www.w3.org/2018/credentials#credentialSubject",
|
|
536
|
+
JSONLD_SCHEMA: {
|
|
537
|
+
// JSONLDSchemaIden3Credential is a schema for context with Iden3Credential type
|
|
538
|
+
IDEN3_CREDENTIAL: "https://schema.iden3.io/core/jsonld/iden3proofs.jsonld",
|
|
539
|
+
// JSONLDSchemaIden3DisplayMethod is a schema for context with Iden3BasicDisplayMethodV1 type
|
|
540
|
+
IDEN3_DISPLAY_METHOD: "https://schema.iden3.io/core/jsonld/displayMethod.jsonld",
|
|
541
|
+
// JSONLDSchemaW3CCredential2018 is a schema for context with VerifiableCredential type
|
|
542
|
+
W3C_CREDENTIAL_2018: "https://www.w3.org/2018/credentials/v1",
|
|
543
|
+
W3C_VC_DOCUMENT_2018: `{"@context":{"@version":1.1,"@protected":true,"id":"@id","type":"@type","VerifiableCredential":{"@id":"https://www.w3.org/2018/credentials#VerifiableCredential","@context":{"@version":1.1,"@protected":true,"id":"@id","type":"@type","cred":"https://www.w3.org/2018/credentials#","sec":"https://w3id.org/security#","xsd":"http://www.w3.org/2001/XMLSchema#","credentialSchema":{"@id":"cred:credentialSchema","@type":"@id","@context":{"@version":1.1,"@protected":true,"id":"@id","type":"@type","cred":"https://www.w3.org/2018/credentials#","JsonSchemaValidator2018":"cred:JsonSchemaValidator2018"}},"credentialStatus":{"@id":"cred:credentialStatus","@type":"@id"},"credentialSubject":{"@id":"cred:credentialSubject","@type":"@id"},"evidence":{"@id":"cred:evidence","@type":"@id"},"expirationDate":{"@id":"cred:expirationDate","@type":"xsd:dateTime"},"holder":{"@id":"cred:holder","@type":"@id"},"issued":{"@id":"cred:issued","@type":"xsd:dateTime"},"issuer":{"@id":"cred:issuer","@type":"@id"},"issuanceDate":{"@id":"cred:issuanceDate","@type":"xsd:dateTime"},"proof":{"@id":"sec:proof","@type":"@id","@container":"@graph"},"refreshService":{"@id":"cred:refreshService","@type":"@id","@context":{"@version":1.1,"@protected":true,"id":"@id","type":"@type","cred":"https://www.w3.org/2018/credentials#","ManualRefreshService2018":"cred:ManualRefreshService2018"}},"termsOfUse":{"@id":"cred:termsOfUse","@type":"@id"},"validFrom":{"@id":"cred:validFrom","@type":"xsd:dateTime"},"validUntil":{"@id":"cred:validUntil","@type":"xsd:dateTime"}}},"VerifiablePresentation":{"@id":"https://www.w3.org/2018/credentials#VerifiablePresentation","@context":{"@version":1.1,"@protected":true,"id":"@id","type":"@type","cred":"https://www.w3.org/2018/credentials#","sec":"https://w3id.org/security#","holder":{"@id":"cred:holder","@type":"@id"},"proof":{"@id":"sec:proof","@type":"@id","@container":"@graph"},"verifiableCredential":{"@id":"cred:verifiableCredential","@type":"@id","@container":"@graph"}}},"EcdsaSecp256k1Signature2019":{"@id":"https://w3id.org/security#EcdsaSecp256k1Signature2019","@context":{"@version":1.1,"@protected":true,"id":"@id","type":"@type","sec":"https://w3id.org/security#","xsd":"http://www.w3.org/2001/XMLSchema#","challenge":"sec:challenge","created":{"@id":"http://purl.org/dc/terms/created","@type":"xsd:dateTime"},"domain":"sec:domain","expires":{"@id":"sec:expiration","@type":"xsd:dateTime"},"jws":"sec:jws","nonce":"sec:nonce","proofPurpose":{"@id":"sec:proofPurpose","@type":"@vocab","@context":{"@version":1.1,"@protected":true,"id":"@id","type":"@type","sec":"https://w3id.org/security#","assertionMethod":{"@id":"sec:assertionMethod","@type":"@id","@container":"@set"},"authentication":{"@id":"sec:authenticationMethod","@type":"@id","@container":"@set"}}},"proofValue":"sec:proofValue","verificationMethod":{"@id":"sec:verificationMethod","@type":"@id"}}},"EcdsaSecp256r1Signature2019":{"@id":"https://w3id.org/security#EcdsaSecp256r1Signature2019","@context":{"@version":1.1,"@protected":true,"id":"@id","type":"@type","sec":"https://w3id.org/security#","xsd":"http://www.w3.org/2001/XMLSchema#","challenge":"sec:challenge","created":{"@id":"http://purl.org/dc/terms/created","@type":"xsd:dateTime"},"domain":"sec:domain","expires":{"@id":"sec:expiration","@type":"xsd:dateTime"},"jws":"sec:jws","nonce":"sec:nonce","proofPurpose":{"@id":"sec:proofPurpose","@type":"@vocab","@context":{"@version":1.1,"@protected":true,"id":"@id","type":"@type","sec":"https://w3id.org/security#","assertionMethod":{"@id":"sec:assertionMethod","@type":"@id","@container":"@set"},"authentication":{"@id":"sec:authenticationMethod","@type":"@id","@container":"@set"}}},"proofValue":"sec:proofValue","verificationMethod":{"@id":"sec:verificationMethod","@type":"@id"}}},"Ed25519Signature2018":{"@id":"https://w3id.org/security#Ed25519Signature2018","@context":{"@version":1.1,"@protected":true,"id":"@id","type":"@type","sec":"https://w3id.org/security#","xsd":"http://www.w3.org/2001/XMLSchema#","challenge":"sec:challenge","created":{"@id":"http://purl.org/dc/terms/created","@type":"xsd:dateTime"},"domain":"sec:domain","expires":{"@id":"sec:expiration","@type":"xsd:dateTime"},"jws":"sec:jws","nonce":"sec:nonce","proofPurpose":{"@id":"sec:proofPurpose","@type":"@vocab","@context":{"@version":1.1,"@protected":true,"id":"@id","type":"@type","sec":"https://w3id.org/security#","assertionMethod":{"@id":"sec:assertionMethod","@type":"@id","@container":"@set"},"authentication":{"@id":"sec:authenticationMethod","@type":"@id","@container":"@set"}}},"proofValue":"sec:proofValue","verificationMethod":{"@id":"sec:verificationMethod","@type":"@id"}}},"RsaSignature2018":{"@id":"https://w3id.org/security#RsaSignature2018","@context":{"@version":1.1,"@protected":true,"challenge":"sec:challenge","created":{"@id":"http://purl.org/dc/terms/created","@type":"xsd:dateTime"},"domain":"sec:domain","expires":{"@id":"sec:expiration","@type":"xsd:dateTime"},"jws":"sec:jws","nonce":"sec:nonce","proofPurpose":{"@id":"sec:proofPurpose","@type":"@vocab","@context":{"@version":1.1,"@protected":true,"id":"@id","type":"@type","sec":"https://w3id.org/security#","assertionMethod":{"@id":"sec:assertionMethod","@type":"@id","@container":"@set"},"authentication":{"@id":"sec:authenticationMethod","@type":"@id","@container":"@set"}}},"proofValue":"sec:proofValue","verificationMethod":{"@id":"sec:verificationMethod","@type":"@id"}}},"proof":{"@id":"https://w3id.org/security#proof","@type":"@id","@container":"@graph"}}}`,
|
|
544
|
+
IDEN3_PROOFS_DEFINITION_DOCUMENT: `{"@context":{"@version":1.1,"@protected":true,"id":"@id","type":"@type","Iden3SparseMerkleTreeProof":{"@id":"https://schema.iden3.io/core/jsonld/iden3proofs.jsonld#Iden3SparseMerkleTreeProof","@context":{"@version":1.1,"@protected":true,"@propagate":true,"id":"@id","type":"@type","sec":"https://w3id.org/security#","@vocab":"https://schema.iden3.io/core/vocab/Iden3SparseMerkleTreeProof.md#","xsd":"http://www.w3.org/2001/XMLSchema#","mtp":{"@id":"https://schema.iden3.io/core/jsonld/iden3proofs.jsonld#SparseMerkleTreeProof","@type":"SparseMerkleTreeProof"},"coreClaim":{"@id":"coreClaim","@type":"xsd:string"},"issuerData":{"@id":"issuerData","@context":{"@version":1.1,"state":{"@id":"state","@context":{"txId":{"@id":"txId","@type":"xsd:string"},"blockTimestamp":{"@id":"blockTimestamp","@type":"xsd:integer"},"blockNumber":{"@id":"blockNumber","@type":"xsd:integer"},"rootOfRoots":{"@id":"rootOfRoots","@type":"xsd:string"},"claimsTreeRoot":{"@id":"claimsTreeRoot","@type":"xsd:string"},"revocationTreeRoot":{"@id":"revocationTreeRoot","@type":"xsd:string"},"authCoreClaim":{"@id":"authCoreClaim","@type":"xsd:string"},"value":{"@id":"value","@type":"xsd:string"}}}}}}},"SparseMerkleTreeProof":{"@id":"https://schema.iden3.io/core/jsonld/iden3proofs.jsonld#SparseMerkleTreeProof","@context":{"@version":1.1,"@protected":true,"id":"@id","type":"@type","sec":"https://w3id.org/security#","smt-proof-vocab":"https://schema.iden3.io/core/vocab/SparseMerkleTreeProof.md#","xsd":"http://www.w3.org/2001/XMLSchema#","existence":{"@id":"smt-proof-vocab:existence","@type":"xsd:boolean"},"revocationNonce":{"@id":"smt-proof-vocab:revocationNonce","@type":"xsd:number"},"siblings":{"@id":"smt-proof-vocab:siblings","@container":"@list"},"nodeAux":"@nest","hIndex":{"@id":"smt-proof-vocab:hIndex","@nest":"nodeAux","@type":"xsd:string"},"hValue":{"@id":"smt-proof-vocab:hValue","@nest":"nodeAux","@type":"xsd:string"}}},"BJJSignature2021":{"@id":"https://schema.iden3.io/core/jsonld/iden3proofs.jsonld#BJJSignature2021","@context":{"@version":1.1,"@protected":true,"id":"@id","@vocab":"https://schema.iden3.io/core/vocab/BJJSignature2021.md#","@propagate":true,"type":"@type","xsd":"http://www.w3.org/2001/XMLSchema#","coreClaim":{"@id":"coreClaim","@type":"xsd:string"},"issuerData":{"@id":"issuerData","@context":{"@version":1.1,"authCoreClaim":{"@id":"authCoreClaim","@type":"xsd:string"},"mtp":{"@id":"https://schema.iden3.io/core/jsonld/iden3proofs.jsonld#SparseMerkleTreeProof","@type":"SparseMerkleTreeProof"},"revocationStatus":{"@id":"revocationStatus","@type":"@id"},"state":{"@id":"state","@context":{"@version":1.1,"rootOfRoots":{"@id":"rootOfRoots","@type":"xsd:string"},"claimsTreeRoot":{"@id":"claimsTreeRoot","@type":"xsd:string"},"revocationTreeRoot":{"@id":"revocationTreeRoot","@type":"xsd:string"},"value":{"@id":"value","@type":"xsd:string"}}}}},"signature":{"@id":"signature","@type":"https://w3id.org/security#multibase"},"domain":"https://w3id.org/security#domain","creator":{"@id":"creator","@type":"http://www.w3.org/2001/XMLSchema#string"},"challenge":"https://w3id.org/security#challenge","created":{"@id":"created","@type":"http://www.w3.org/2001/XMLSchema#dateTime"},"expires":{"@id":"https://w3id.org/security#expiration","@type":"http://www.w3.org/2001/XMLSchema#dateTime"},"nonce":"https://w3id.org/security#nonce","proofPurpose":{"@id":"https://w3id.org/security#proofPurpose","@type":"@vocab","@context":{"@protected":true,"id":"@id","type":"@type","assertionMethod":{"@id":"https://w3id.org/security#assertionMethod","@type":"@id","@container":"@set"},"authentication":{"@id":"https://w3id.org/security#authenticationMethod","@type":"@id","@container":"@set"},"capabilityInvocation":{"@id":"https://w3id.org/security#capabilityInvocationMethod","@type":"@id","@container":"@set"},"capabilityDelegation":{"@id":"https://w3id.org/security#capabilityDelegationMethod","@type":"@id","@container":"@set"},"keyAgreement":{"@id":"https://w3id.org/security#keyAgreementMethod","@type":"@id","@container":"@set"}}},"proofValue":{"@id":"https://w3id.org/security#proofValue","@type":"https://w3id.org/security#multibase"},"verificationMethod":{"@id":"https://w3id.org/security#verificationMethod","@type":"@id"}}},"Iden3ReverseSparseMerkleTreeProof":{"@id":"https://schema.iden3.io/core/jsonld/iden3proofs.jsonld#Iden3ReverseSparseMerkleTreeProof","@context":{"@version":1.1,"@protected":true,"id":"@id","type":"@type","iden3-reverse-sparse-merkle-tree-proof-vocab":"https://schema.iden3.io/core/vocab/Iden3ReverseSparseMerkleTreeProof.md#","xsd":"http://www.w3.org/2001/XMLSchema#","revocationNonce":{"@id":"iden3-reverse-sparse-merkle-tree-proof-vocab:revocationNonce","@type":"xsd:integer"},"statusIssuer":{"@context":{"@version":1.1,"@protected":true,"id":"@id","type":"@type"},"@id":"iden3-reverse-sparse-merkle-tree-proof-vocab:statusIssuer"}}},"Iden3commRevocationStatusV1.0":{"@id":"https://schema.iden3.io/core/jsonld/iden3proofs.jsonld#Iden3commRevocationStatusV1.0","@context":{"@version":1.1,"@protected":true,"id":"@id","type":"@type","iden3-comm-revocation-statusV1.0-vocab":"https://schema.iden3.io/core/vocab/Iden3commRevocationStatusV1.0.md#","xsd":"http://www.w3.org/2001/XMLSchema#","revocationNonce":{"@id":"iden3-comm-revocation-statusV1.0-vocab:revocationNonce","@type":"xsd:integer"},"statusIssuer":{"@context":{"@version":1.1,"@protected":true,"id":"@id","type":"@type"},"@id":"iden3-comm-revocation-statusV1.0-vocab:statusIssuer"}}},"Iden3OnchainSparseMerkleTreeProof2023":{"@id":"https://schema.iden3.io/core/jsonld/iden3proofs.jsonld#Iden3OnchainSparseMerkleTreeProof2023","@context":{"@version":1.1,"@protected":true,"id":"@id","type":"@type","iden3-onchain-sparse-merkle-tree-proof-2023-vocab":"https://schema.iden3.io/core/vocab/Iden3OnchainSparseMerkleTreeProof2023.md#","xsd":"http://www.w3.org/2001/XMLSchema#","revocationNonce":{"@id":"iden3-onchain-sparse-merkle-tree-proof-2023-vocab:revocationNonce","@type":"xsd:integer"},"statusIssuer":{"@context":{"@version":1.1,"@protected":true,"id":"@id","type":"@type"},"@id":"iden3-onchain-sparse-merkle-tree-proof-2023-vocab:statusIssuer"}}},"JsonSchema2023":"https://www.w3.org/ns/credentials#JsonSchema2023","Iden3RefreshService2023":"https://schema.iden3.io/core/jsonld/iden3proofs.jsonld#Iden3RefreshService2023"}}`,
|
|
545
|
+
IDEN3_DISPLAY_METHOD_DEFINITION_DOCUMENT: `{"@context":{"@version":1.1,"@protected":true,"id":"@id","type":"@type","displayMethod":{"@id":"https://schema.iden3.io/core/vocab/displayMethod.md#displayMethod","@type":"@id","@context":{"@version":1.1,"@protected":true,"id":"@id","type":"@type","Iden3BasicDisplayMethodV1":"https://schema.iden3.io/core/vocab/displayMethod.md#Iden3BasicDisplayMethodV1"}}}}`
|
|
546
|
+
},
|
|
547
|
+
// JsonSchema2023 JSON schema for verification of Iden3Credential
|
|
548
|
+
JSON_SCHEMA_VALIDATOR: "JsonSchema2023",
|
|
549
|
+
SERVICE_TYPE: {
|
|
550
|
+
// Iden3CommServiceType is service type for iden3comm protocol
|
|
551
|
+
IDEN3_COMM: "iden3-communication",
|
|
552
|
+
// PushNotificationServiceType is service type for delivering push notifications to identity
|
|
553
|
+
PUSH_NOTIFICATION: "push-notification"
|
|
554
|
+
},
|
|
555
|
+
AUTH: {
|
|
556
|
+
AUTH_BJJ_CREDENTIAL_HASH: "013fd3f623559d850fb5b02ff012d0e2",
|
|
557
|
+
AUTH_BJJ_CREDENTIAL_SCHEMA_JSON_URL: "https://schema.iden3.io/core/json/auth.json",
|
|
558
|
+
AUTH_BJJ_CREDENTIAL_SCHEMA_JSONLD_URL: "https://schema.iden3.io/core/jsonld/auth.jsonld",
|
|
559
|
+
AUTH_BJJ_CREDENTIAL_TYPE: "AuthBJJCredential",
|
|
560
|
+
AUTH_BJJ_CREDENTIAL_SCHEMA_JSON: `{"$schema":"http://json-schema.org/draft-07/schema#","$metadata":{"uris":{"jsonLdContext":"https://schema.iden3.io/core/jsonld/auth.jsonld","jsonSchema":"https://schema.iden3.io/core/json/auth.json"},"serialization":{"indexDataSlotA":"x","indexDataSlotB":"y"}},"type":"object","required":["@context","id","type","issuanceDate","credentialSubject","credentialSchema","credentialStatus","issuer"],"properties":{"@context":{"type":["string","array","object"]},"id":{"type":"string"},"type":{"type":["string","array"],"items":{"type":"string"}},"issuer":{"type":["string","object"],"format":"uri","required":["id"],"properties":{"id":{"type":"string","format":"uri"}}},"issuanceDate":{"type":"string","format":"date-time"},"expirationDate":{"type":"string","format":"date-time"},"credentialSchema":{"type":"object","required":["id","type"],"properties":{"id":{"type":"string","format":"uri"},"type":{"type":"string"}}},"credentialSubject":{"type":"object","required":["x","y"],"properties":{"id":{"title":"Credential Subject ID","type":"string","format":"uri"},"x":{"type":"string"},"y":{"type":"string"}}}}}`,
|
|
561
|
+
AUTH_BJJ_CREDENTIAL_SCHEMA_JSONLD: `{"@context":[{"@version":1.1,"@protected":true,"id":"@id","type":"@type","AuthBJJCredential":{"@id":"https://schema.iden3.io/core/jsonld/auth.jsonld#AuthBJJCredential","@context":{"@version":1.1,"@protected":true,"id":"@id","type":"@type","iden3_serialization":"iden3:v1:slotIndexA=x&slotIndexB=y","xsd":"http://www.w3.org/2001/XMLSchema#","auth-vocab":"https://schema.iden3.io/core/vocab/auth.md#","x":{"@id":"auth-vocab:x","@type":"xsd:positiveInteger"},"y":{"@id":"auth-vocab:y","@type":"xsd:positiveInteger"}}},"Iden3StateInfo2023":{"@id":"https://schema.iden3.io/core/jsonld/auth.jsonld#Iden3StateInfo2023","@context":{"@version":1.1,"@protected":true,"id":"@id","type":"@type","xsd":"http://www.w3.org/2001/XMLSchema#","@vocab":"https://schema.iden3.io/core/vocab/state-info.md#","@propagate":true,"stateContractAddress":{"@id":"stateContractAddress","@type":"xsd:string"},"published":{"@id":"published","@type":"xsd:boolean"},"info":{"@id":"info","@type":"@id","@context":{"@protected":true,"id":{"@id":"id","@type":"xsd:string"},"state":{"@id":"state","@type":"xsd:string"},"replacedByState":{"@id":"replacedByState","@type":"xsd:string"},"createdAtTimestamp":{"@id":"createdAtTimestamp","@type":"xsd:string"},"replacedAtTimestamp":{"@id":"replacedAtTimestamp","@type":"xsd:string"},"createdAtBlock":{"@id":"createdAtBlock","@type":"xsd:string"},"replacedAtBlock":{"@id":"replacedAtBlock","@type":"xsd:string"}}},"global":{"@id":"global","@type":"@id","@context":{"@protected":true,"sec":"https://w3id.org/security#","root":{"@id":"root","@type":"xsd:string"},"replacedByRoot":{"@id":"replacedByRoot","@type":"xsd:string"},"createdAtTimestamp":{"@id":"createdAtTimestamp","@type":"xsd:string"},"replacedAtTimestamp":{"@id":"replacedAtTimestamp","@type":"xsd:string"},"createdAtBlock":{"@id":"createdAtBlock","@type":"xsd:string"},"replacedAtBlock":{"@id":"replacedAtBlock","@type":"xsd:string"},"proof":{"@id":"sec:proof","@type":"@id","@container":"@graph"}}}}}}]}`
|
|
516
562
|
}
|
|
563
|
+
});
|
|
564
|
+
var ProofType = /* @__PURE__ */ ((ProofType2) => {
|
|
565
|
+
ProofType2["BJJSignature"] = "BJJSignature2021";
|
|
566
|
+
ProofType2["Iden3SparseMerkleTreeProof"] = "Iden3SparseMerkleTreeProof";
|
|
567
|
+
return ProofType2;
|
|
568
|
+
})(ProofType || {});
|
|
569
|
+
var CredentialStatusType = /* @__PURE__ */ ((CredentialStatusType2) => {
|
|
570
|
+
CredentialStatusType2["SparseMerkleTreeProof"] = "SparseMerkleTreeProof";
|
|
571
|
+
CredentialStatusType2["Iden3ReverseSparseMerkleTreeProof"] = "Iden3ReverseSparseMerkleTreeProof";
|
|
572
|
+
CredentialStatusType2["Iden3commRevocationStatusV1"] = "Iden3commRevocationStatusV1.0";
|
|
573
|
+
CredentialStatusType2["Iden3OnchainSparseMerkleTreeProof2023"] = "Iden3OnchainSparseMerkleTreeProof2023";
|
|
574
|
+
return CredentialStatusType2;
|
|
575
|
+
})(CredentialStatusType || {});
|
|
576
|
+
var ProofPurpose = /* @__PURE__ */ ((ProofPurpose2) => {
|
|
577
|
+
ProofPurpose2["Authentication"] = "Authentication";
|
|
578
|
+
return ProofPurpose2;
|
|
579
|
+
})(ProofPurpose || {});
|
|
580
|
+
var MerklizedRootPosition = /* @__PURE__ */ ((MerklizedRootPosition4) => {
|
|
581
|
+
MerklizedRootPosition4["Index"] = "index";
|
|
582
|
+
MerklizedRootPosition4["Value"] = "value";
|
|
583
|
+
MerklizedRootPosition4["None"] = "";
|
|
584
|
+
return MerklizedRootPosition4;
|
|
585
|
+
})(MerklizedRootPosition || {});
|
|
586
|
+
var SubjectPosition = /* @__PURE__ */ ((SubjectPosition2) => {
|
|
587
|
+
SubjectPosition2["None"] = "";
|
|
588
|
+
SubjectPosition2["Index"] = "index";
|
|
589
|
+
SubjectPosition2["Value"] = "value";
|
|
590
|
+
return SubjectPosition2;
|
|
591
|
+
})(SubjectPosition || {});
|
|
592
|
+
var RefreshServiceType = /* @__PURE__ */ ((RefreshServiceType2) => {
|
|
593
|
+
RefreshServiceType2["Iden3RefreshService2023"] = "Iden3RefreshService2023";
|
|
594
|
+
return RefreshServiceType2;
|
|
595
|
+
})(RefreshServiceType || {});
|
|
596
|
+
var PaymentRequestDataType = /* @__PURE__ */ ((PaymentRequestDataType2) => {
|
|
597
|
+
PaymentRequestDataType2["Iden3PaymentRequestCryptoV1"] = "Iden3PaymentRequestCryptoV1";
|
|
598
|
+
PaymentRequestDataType2["Iden3PaymentRailsRequestV1"] = "Iden3PaymentRailsRequestV1";
|
|
599
|
+
PaymentRequestDataType2["Iden3PaymentRailsERC20RequestV1"] = "Iden3PaymentRailsERC20RequestV1";
|
|
600
|
+
PaymentRequestDataType2["Iden3PaymentRailsSolanaRequestV1"] = "Iden3PaymentRailsSolanaRequestV1";
|
|
601
|
+
PaymentRequestDataType2["Iden3PaymentRailsSolanaSPLRequestV1"] = "Iden3PaymentRailsSolanaSPLRequestV1";
|
|
602
|
+
return PaymentRequestDataType2;
|
|
603
|
+
})(PaymentRequestDataType || {});
|
|
604
|
+
var PaymentType = /* @__PURE__ */ ((PaymentType2) => {
|
|
605
|
+
PaymentType2["Iden3PaymentCryptoV1"] = "Iden3PaymentCryptoV1";
|
|
606
|
+
PaymentType2["Iden3PaymentRailsV1"] = "Iden3PaymentRailsV1";
|
|
607
|
+
PaymentType2["Iden3PaymentRailsERC20V1"] = "Iden3PaymentRailsERC20V1";
|
|
608
|
+
PaymentType2["Iden3PaymentRailsSolanaV1"] = "Iden3PaymentRailsSolanaV1";
|
|
609
|
+
PaymentType2["Iden3PaymentRailsSolanaSPLV1"] = "Iden3PaymentRailsSolanaSPLV1";
|
|
610
|
+
return PaymentType2;
|
|
611
|
+
})(PaymentType || {});
|
|
612
|
+
var SupportedPaymentProofType = /* @__PURE__ */ ((SupportedPaymentProofType2) => {
|
|
613
|
+
SupportedPaymentProofType2["EthereumEip712Signature2021"] = "EthereumEip712Signature2021";
|
|
614
|
+
SupportedPaymentProofType2["SolanaEd25519Signature2025"] = "SolanaEd25519Signature2025";
|
|
615
|
+
return SupportedPaymentProofType2;
|
|
616
|
+
})(SupportedPaymentProofType || {});
|
|
617
|
+
var SupportedCurrencies = /* @__PURE__ */ ((SupportedCurrencies2) => {
|
|
618
|
+
SupportedCurrencies2["ETH"] = "ETH";
|
|
619
|
+
SupportedCurrencies2["ETH_WEI"] = "ETHWEI";
|
|
620
|
+
SupportedCurrencies2["ETH_GWEI"] = "ETHGWEI";
|
|
621
|
+
SupportedCurrencies2["MATIC"] = "MATIC";
|
|
622
|
+
SupportedCurrencies2["POL"] = "POL";
|
|
623
|
+
return SupportedCurrencies2;
|
|
624
|
+
})(SupportedCurrencies || {});
|
|
625
|
+
var PaymentFeatures = /* @__PURE__ */ ((PaymentFeatures2) => {
|
|
626
|
+
PaymentFeatures2["EIP_2612"] = "EIP-2612";
|
|
627
|
+
return PaymentFeatures2;
|
|
628
|
+
})(PaymentFeatures || {});
|
|
629
|
+
var DisplayMethodType = /* @__PURE__ */ ((DisplayMethodType2) => {
|
|
630
|
+
DisplayMethodType2["Iden3BasicDisplayMethodV1"] = "Iden3BasicDisplayMethodV1";
|
|
631
|
+
return DisplayMethodType2;
|
|
632
|
+
})(DisplayMethodType || {});
|
|
633
|
+
var DEFAULT_CACHE_MAX_SIZE = 1e4;
|
|
634
|
+
var SOLANA_CHAIN_REF = Object.freeze({
|
|
635
|
+
DEVNET: "EtWTRABZaYq6iMfeYKouRu166VU2xqa1",
|
|
636
|
+
TESTNET: "4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z",
|
|
637
|
+
MAINNET: "5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp"
|
|
638
|
+
});
|
|
639
|
+
|
|
640
|
+
// src/verifiable/proof.ts
|
|
641
|
+
import { Hex as Hex3, Signature } from "@iden3/js-crypto";
|
|
642
|
+
import { Claim, DID as DID2 } from "@iden3/js-iden3-core";
|
|
643
|
+
var Iden3SparseMerkleTreeProof = class _Iden3SparseMerkleTreeProof {
|
|
644
|
+
type;
|
|
645
|
+
issuerData;
|
|
646
|
+
mtp;
|
|
647
|
+
coreClaim;
|
|
517
648
|
/**
|
|
518
|
-
*
|
|
519
|
-
* @param {
|
|
520
|
-
* @returns kms key identifier
|
|
649
|
+
* Creates an instance of Iden3SparseMerkleTreeProof.
|
|
650
|
+
* @param {object} obj
|
|
521
651
|
*/
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
const publicKey = privateKey.public();
|
|
528
|
-
const kmsId = {
|
|
529
|
-
type: this.keyType,
|
|
530
|
-
id: keyPath(this.keyType, publicKey.hex())
|
|
531
|
-
};
|
|
532
|
-
await this.keyStore.importKey({ alias: kmsId.id, key: privateKey.hex() });
|
|
533
|
-
return kmsId;
|
|
652
|
+
constructor(obj) {
|
|
653
|
+
this.coreClaim = obj.coreClaim;
|
|
654
|
+
this.issuerData = obj.issuerData;
|
|
655
|
+
this.type = "Iden3SparseMerkleTreeProof" /* Iden3SparseMerkleTreeProof */;
|
|
656
|
+
this.mtp = obj.mtp;
|
|
534
657
|
}
|
|
535
658
|
/**
|
|
536
|
-
* Gets public key by kmsKeyId
|
|
537
659
|
*
|
|
538
|
-
* @param {KmsKeyId} keyId - key identifier
|
|
539
|
-
*/
|
|
540
|
-
async publicKey(keyId) {
|
|
541
|
-
const privateKey = await this.privateKey(keyId);
|
|
542
|
-
return privateKey.public().hex();
|
|
543
|
-
}
|
|
544
|
-
/**
|
|
545
|
-
* signs prepared payload of size,
|
|
546
|
-
* with a key id
|
|
547
660
|
*
|
|
548
|
-
* @
|
|
549
|
-
* @param {Uint8Array} data - data to sign (32 bytes)
|
|
550
|
-
* @returns Uint8Array signature
|
|
661
|
+
* @returns `json object in serialized presentation`
|
|
551
662
|
*/
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
const publicKey = await this.publicKey(keyId);
|
|
570
|
-
return PublicKey.newFromCompressed(hexToBytes(publicKey)).verifyPoseidon(
|
|
571
|
-
BytesHelper.bytesToInt(message),
|
|
572
|
-
Signature.newFromCompressed(hexToBytes(signatureHex))
|
|
573
|
-
);
|
|
663
|
+
toJSON() {
|
|
664
|
+
const issuerId = this.issuerData.id;
|
|
665
|
+
return {
|
|
666
|
+
issuerData: {
|
|
667
|
+
id: issuerId.string(),
|
|
668
|
+
state: {
|
|
669
|
+
...this.issuerData.state,
|
|
670
|
+
rootOfRoots: this.issuerData.state.rootOfRoots.hex(),
|
|
671
|
+
claimsTreeRoot: this.issuerData.state.claimsTreeRoot.hex(),
|
|
672
|
+
revocationTreeRoot: this.issuerData.state.revocationTreeRoot.hex(),
|
|
673
|
+
value: this.issuerData.state.value.hex()
|
|
674
|
+
}
|
|
675
|
+
},
|
|
676
|
+
type: this.type,
|
|
677
|
+
coreClaim: this.coreClaim.hex(),
|
|
678
|
+
mtp: this.mtp.toJSON()
|
|
679
|
+
};
|
|
574
680
|
}
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
return allKeysFromKeyStore.filter((key) => key.alias.startsWith(this.keyType));
|
|
596
|
-
}
|
|
597
|
-
/**
|
|
598
|
-
* generates a ed25519 key from a seed phrase
|
|
599
|
-
* @param {Uint8Array} seed - byte array seed
|
|
600
|
-
* @returns {Promise<KmsKeyId>} kms key identifier
|
|
601
|
-
*/
|
|
602
|
-
async newPrivateKeyFromSeed(seed) {
|
|
603
|
-
if (seed.length !== 32) {
|
|
604
|
-
throw new Error("Seed should be 32 bytes");
|
|
681
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
682
|
+
static fromJSON(obj) {
|
|
683
|
+
let mtp;
|
|
684
|
+
if (obj?.mtp?.notEmpties && obj?.mtp?.depth && obj?.mtp?.siblings) {
|
|
685
|
+
const ne = obj?.mtp?.notEmpties;
|
|
686
|
+
const notEmpties = ne instanceof Uint8Array ? ne : new Uint8Array(Object.values(ne));
|
|
687
|
+
const siblingsHashes = obj?.mtp?.siblings.map(
|
|
688
|
+
(h) => Hash2.fromString(JSON.stringify(h))
|
|
689
|
+
);
|
|
690
|
+
const allSiblings = Proof.buildAllSiblings(obj?.mtp?.depth, notEmpties, siblingsHashes);
|
|
691
|
+
let nodeAux = obj.mtp.nodeAux || obj.mtp.node_aux;
|
|
692
|
+
if (nodeAux) {
|
|
693
|
+
nodeAux = {
|
|
694
|
+
key: Hash2.fromString(JSON.stringify(nodeAux.key)),
|
|
695
|
+
value: Hash2.fromString(JSON.stringify(nodeAux.value))
|
|
696
|
+
};
|
|
697
|
+
}
|
|
698
|
+
mtp = new Proof({ existence: obj?.mtp.existence, nodeAux, siblings: allSiblings });
|
|
699
|
+
} else {
|
|
700
|
+
mtp = Proof.fromJSON(obj.mtp);
|
|
605
701
|
}
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
702
|
+
return new _Iden3SparseMerkleTreeProof({
|
|
703
|
+
coreClaim: new Claim().fromHex(obj.coreClaim),
|
|
704
|
+
mtp,
|
|
705
|
+
issuerData: {
|
|
706
|
+
id: DID2.parse(obj.issuerData.id),
|
|
707
|
+
state: {
|
|
708
|
+
...obj.issuerData.state,
|
|
709
|
+
rootOfRoots: Hash2.fromHex(obj.issuerData.state.rootOfRoots),
|
|
710
|
+
claimsTreeRoot: Hash2.fromHex(obj.issuerData.state.claimsTreeRoot),
|
|
711
|
+
revocationTreeRoot: Hash2.fromHex(obj.issuerData.state.revocationTreeRoot),
|
|
712
|
+
value: Hash2.fromHex(obj.issuerData.state.value)
|
|
713
|
+
}
|
|
714
|
+
}
|
|
614
715
|
});
|
|
615
|
-
return kmsId;
|
|
616
|
-
}
|
|
617
|
-
/**
|
|
618
|
-
* Gets public key by kmsKeyId
|
|
619
|
-
* @param {KmsKeyId} keyId - key identifier
|
|
620
|
-
* @returns {Promise<string>} Public key as a hex string
|
|
621
|
-
*/
|
|
622
|
-
async publicKey(keyId) {
|
|
623
|
-
const privateKeyHex = await this.privateKey(keyId);
|
|
624
|
-
const publicKey = ed25519.getPublicKey(privateKeyHex);
|
|
625
|
-
return bytesToHex(publicKey);
|
|
626
|
-
}
|
|
627
|
-
/**
|
|
628
|
-
* signs prepared payload of size,
|
|
629
|
-
* with a key id
|
|
630
|
-
* @param {KmsKeyId} keyId - key identifier
|
|
631
|
-
* @param {Uint8Array} digest - data to sign (32 bytes)
|
|
632
|
-
* @returns {Promise<Uint8Array>} signature
|
|
633
|
-
*/
|
|
634
|
-
async sign(keyId, digest) {
|
|
635
|
-
const privateKeyHex = await this.privateKey(keyId);
|
|
636
|
-
return ed25519.sign(digest, privateKeyHex);
|
|
637
|
-
}
|
|
638
|
-
/**
|
|
639
|
-
* Verifies a signature for the given message and key identifier.
|
|
640
|
-
* @param digest - The message to verify the signature against.
|
|
641
|
-
* @param signatureHex - The signature to verify, as a hexadecimal string.
|
|
642
|
-
* @param keyId - The key identifier to use for verification.
|
|
643
|
-
* @returns A Promise that resolves to a boolean indicating whether the signature is valid.
|
|
644
|
-
*/
|
|
645
|
-
async verify(digest, signatureHex, keyId) {
|
|
646
|
-
const publicKeyHex = await this.publicKey(keyId);
|
|
647
|
-
return ed25519.verify(signatureHex, digest, publicKeyHex);
|
|
648
|
-
}
|
|
649
|
-
/**
|
|
650
|
-
* Retrieves the private key for a given keyId from the key store.
|
|
651
|
-
* @param {KmsKeyId} keyId - The identifier of the key to retrieve.
|
|
652
|
-
* @returns {Promise<string>} The private key associated with the keyId.
|
|
653
|
-
*/
|
|
654
|
-
async privateKey(keyId) {
|
|
655
|
-
return this._keyStore.get({ alias: keyId.id });
|
|
656
716
|
}
|
|
657
717
|
};
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
keyType;
|
|
669
|
-
_keyStore;
|
|
670
|
-
/**
|
|
671
|
-
* Creates an instance of BjjProvider.
|
|
672
|
-
* @param {KmsKeyType} keyType - kms key type
|
|
673
|
-
* @param {AbstractPrivateKeyStore} keyStore - key store for kms
|
|
674
|
-
*/
|
|
675
|
-
constructor(keyType, keyStore) {
|
|
676
|
-
if (keyType !== "Secp256k1" /* Secp256k1 */) {
|
|
677
|
-
throw new Error("Key type must be Secp256k1");
|
|
678
|
-
}
|
|
679
|
-
this.keyType = keyType;
|
|
680
|
-
this._keyStore = keyStore;
|
|
681
|
-
}
|
|
682
|
-
/**
|
|
683
|
-
* get all keys
|
|
684
|
-
* @returns list of keys
|
|
685
|
-
*/
|
|
686
|
-
async list() {
|
|
687
|
-
const allKeysFromKeyStore = await this._keyStore.list();
|
|
688
|
-
return allKeysFromKeyStore.filter((key) => key.alias.startsWith(this.keyType));
|
|
689
|
-
}
|
|
690
|
-
/**
|
|
691
|
-
* generates a baby jub jub key from a seed phrase
|
|
692
|
-
* @param {Uint8Array} seed - byte array seed
|
|
693
|
-
* @returns kms key identifier
|
|
694
|
-
*/
|
|
695
|
-
async newPrivateKeyFromSeed(seed) {
|
|
696
|
-
if (seed.length !== 32) {
|
|
697
|
-
throw new Error("Seed should be 32 bytes");
|
|
698
|
-
}
|
|
699
|
-
const publicKey = secp256k1.getPublicKey(seed);
|
|
700
|
-
const kmsId = {
|
|
701
|
-
type: this.keyType,
|
|
702
|
-
id: keyPath(this.keyType, bytesToHex(publicKey))
|
|
703
|
-
};
|
|
704
|
-
await this._keyStore.importKey({
|
|
705
|
-
alias: kmsId.id,
|
|
706
|
-
key: bytesToHex(seed).padStart(64, "0")
|
|
707
|
-
});
|
|
708
|
-
return kmsId;
|
|
718
|
+
var BJJSignatureProof2021 = class _BJJSignatureProof2021 {
|
|
719
|
+
type;
|
|
720
|
+
issuerData;
|
|
721
|
+
signature;
|
|
722
|
+
coreClaim;
|
|
723
|
+
constructor(obj) {
|
|
724
|
+
this.type = "BJJSignature2021" /* BJJSignature */;
|
|
725
|
+
this.issuerData = obj.issuerData;
|
|
726
|
+
this.coreClaim = obj.coreClaim;
|
|
727
|
+
this.signature = obj.signature;
|
|
709
728
|
}
|
|
710
729
|
/**
|
|
711
|
-
*
|
|
730
|
+
* toJSON is a method to serialize BJJSignatureProof2021 to json
|
|
712
731
|
*
|
|
713
|
-
* @
|
|
714
|
-
*/
|
|
715
|
-
async publicKey(keyId) {
|
|
716
|
-
const privateKeyHex = await this.privateKey(keyId);
|
|
717
|
-
const publicKey = secp256k1.getPublicKey(privateKeyHex, false);
|
|
718
|
-
return bytesToHex(publicKey);
|
|
719
|
-
}
|
|
720
|
-
/**
|
|
721
|
-
* Signs the given data using the private key associated with the specified key identifier.
|
|
722
|
-
* @param keyId - The key identifier to use for signing.
|
|
723
|
-
* @param data - The data to sign.
|
|
724
|
-
* @param opts - Signing options, such as the algorithm to use.
|
|
725
|
-
* @returns A Promise that resolves to the signature as a Uint8Array.
|
|
732
|
+
* @returns `json object in serialized presentation`
|
|
726
733
|
*/
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
734
|
+
toJSON() {
|
|
735
|
+
return {
|
|
736
|
+
issuerData: {
|
|
737
|
+
id: this.issuerData.id.string(),
|
|
738
|
+
state: {
|
|
739
|
+
...this.issuerData.state,
|
|
740
|
+
rootOfRoots: this.issuerData.state.rootOfRoots.hex(),
|
|
741
|
+
claimsTreeRoot: this.issuerData.state.claimsTreeRoot.hex(),
|
|
742
|
+
revocationTreeRoot: this.issuerData.state.revocationTreeRoot.hex(),
|
|
743
|
+
value: this.issuerData.state.value.hex()
|
|
744
|
+
},
|
|
745
|
+
mtp: this.issuerData.mtp.toJSON(),
|
|
746
|
+
authCoreClaim: this.issuerData.authCoreClaim.hex(),
|
|
747
|
+
credentialStatus: this.issuerData.credentialStatus
|
|
748
|
+
},
|
|
749
|
+
type: this.type,
|
|
750
|
+
coreClaim: this.coreClaim.hex(),
|
|
751
|
+
signature: Hex3.encodeString(this.signature.compress())
|
|
752
|
+
};
|
|
737
753
|
}
|
|
738
754
|
/**
|
|
739
|
-
*
|
|
740
|
-
* @param
|
|
741
|
-
* @param signatureHex - The signature to verify, as a hexadecimal string.
|
|
742
|
-
* @param keyId - The key identifier to use for verification.
|
|
743
|
-
* @returns A Promise that resolves to a boolean indicating whether the signature is valid.
|
|
755
|
+
* fromJSON is a method to deserialize BJJSignatureProof2021 from json
|
|
756
|
+
* @param obj
|
|
744
757
|
*/
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
return
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
758
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
759
|
+
static fromJSON(obj) {
|
|
760
|
+
return new _BJJSignatureProof2021({
|
|
761
|
+
issuerData: {
|
|
762
|
+
id: DID2.parse(obj.issuerData.id),
|
|
763
|
+
mtp: Proof.fromJSON(obj.issuerData.mtp),
|
|
764
|
+
state: {
|
|
765
|
+
...obj.issuerData.state,
|
|
766
|
+
rootOfRoots: Hash2.fromHex(obj.issuerData.state.rootOfRoots),
|
|
767
|
+
claimsTreeRoot: Hash2.fromHex(obj.issuerData.state.claimsTreeRoot),
|
|
768
|
+
revocationTreeRoot: Hash2.fromHex(obj.issuerData.state.revocationTreeRoot),
|
|
769
|
+
value: Hash2.fromHex(obj.issuerData.state.value)
|
|
770
|
+
},
|
|
771
|
+
credentialStatus: obj.issuerData.credentialStatus,
|
|
772
|
+
authCoreClaim: new Claim().fromHex(obj.issuerData.authCoreClaim)
|
|
773
|
+
},
|
|
774
|
+
coreClaim: new Claim().fromHex(obj.coreClaim),
|
|
775
|
+
signature: Signature.newFromCompressed(
|
|
776
|
+
Uint8Array.from(Hex3.decodeString(obj.signature)).slice(0, 64)
|
|
777
|
+
)
|
|
778
|
+
});
|
|
751
779
|
}
|
|
752
780
|
};
|
|
753
781
|
|
|
754
|
-
// src/
|
|
782
|
+
// src/verifiable/credential.ts
|
|
755
783
|
import {
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
ClaimOptions
|
|
761
|
-
|
|
762
|
-
DidMethod,
|
|
763
|
-
getUnixTimestamp as getUnixTimestamp8,
|
|
764
|
-
Id as Id19,
|
|
765
|
-
NetworkId,
|
|
766
|
-
SchemaHash as SchemaHash7
|
|
784
|
+
Claim as Claim2,
|
|
785
|
+
DID as DID4,
|
|
786
|
+
MerklizedRootPosition as MerklizedRootPositionCore,
|
|
787
|
+
IdPosition,
|
|
788
|
+
ClaimOptions,
|
|
789
|
+
getChainId
|
|
767
790
|
} from "@iden3/js-iden3-core";
|
|
768
|
-
import {
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
sha256 as sha2562,
|
|
772
|
-
Signature as Signature3,
|
|
773
|
-
Hex as Hex6,
|
|
774
|
-
getRandomBytes as getRandomBytes2,
|
|
775
|
-
Poseidon
|
|
776
|
-
} from "@iden3/js-crypto";
|
|
777
|
-
import { hashElems as hashElems2, ZERO_HASH as ZERO_HASH6 } from "@iden3/js-merkletree";
|
|
778
|
-
|
|
779
|
-
// src/identity/common.ts
|
|
780
|
-
import { DID as DID5, Id as Id2, IdPosition as IdPosition2, MerklizedRootPosition as MerklizedRootPosition2 } from "@iden3/js-iden3-core";
|
|
781
|
-
|
|
782
|
-
// src/verifiable/proof.ts
|
|
783
|
-
import { Hash as Hash2, Proof } from "@iden3/js-merkletree";
|
|
784
|
-
|
|
785
|
-
// src/verifiable/constants.ts
|
|
786
|
-
var VerifiableConstants = Object.freeze({
|
|
787
|
-
ERRORS: {
|
|
788
|
-
FiELD_IS_EMPTY: "fieldPath is empty",
|
|
789
|
-
CONTEXT_TYPE_IS_EMPTY: "ctxType is empty",
|
|
790
|
-
// ErrStateNotFound issuer state is genesis state.
|
|
791
|
-
IDENTITY_DOES_NOT_EXIST: "Identity does not exist",
|
|
792
|
-
IDENTITY_DOES_NOT_EXIST_CUSTOM_ERROR: "IdentityDoesNotExist",
|
|
793
|
-
NO_AUTH_CRED_FOUND: "no auth credentials found",
|
|
794
|
-
STATE_DOES_NOT_EXIST: "State does not exist",
|
|
795
|
-
STATE_DOES_NOT_EXIST_CUSTOM_ERROR: "StateDoesNotExist",
|
|
796
|
-
ROOT_DOES_NOT_EXIST: "Root does not exist",
|
|
797
|
-
ROOT_DOES_NOT_EXIST_CUSTOM_ERROR: "RootDoesNotExist",
|
|
798
|
-
// identity wallet
|
|
799
|
-
ID_WALLET_NO_CREDENTIAL_SATISFIED_QUERY: "no credential satisfied query",
|
|
800
|
-
ID_WALLET_SIGNER_IS_REQUIRED: "Ethereum signer is required to create Ethereum identities in order to transit state",
|
|
801
|
-
ID_WALLET_PROVER_IS_REQUIRED: "prover is required to generate proofs for non ethereum identities",
|
|
802
|
-
ID_WALLET_CORE_CLAIM_REQUIRED_IN_SIG_PROOF: "credential must have coreClaim representation in the signature proof",
|
|
803
|
-
ID_WALLET_CORE_CLAIM_REQUIRED_IN_ANY_PROOF: "credential must have coreClaim representation in proofs",
|
|
804
|
-
ID_WALLET_CORE_CLAIM_MISMATCH: "core claim representations is set in both proofs but they are not equal",
|
|
805
|
-
ID_WALLET_CORE_CLAIM_IS_NOT_SET: "core claim is not set in credential proofs",
|
|
806
|
-
ID_WALLET_PROFILE_OR_IDENTITY_NOT_FOUND: "profile or identity not found",
|
|
807
|
-
ID_WALLET_PROFILE_ALREADY_EXISTS: "profile with given nonce or verifier already exists",
|
|
808
|
-
ID_WALLET_PROFILE_ALREADY_EXISTS_VERIFIER_TAGS: "profile with given verifier and tags already exists",
|
|
809
|
-
ID_WALLET_ISSUER_AUTH_BJJ_CRED_MUST_HAVE_ANY_PROOF: "issuer auth credential must have proof",
|
|
810
|
-
ID_WALLET_ISSUER_AUTH_BJJ_CRED_MUST_HAVE_MTP_PROOF: "mtp is required for auth bjj key to issue new credentials",
|
|
811
|
-
// proof service
|
|
812
|
-
PROOF_SERVICE_NO_CREDENTIAL_FOR_IDENTITY_OR_PROFILE: "no credentials belong to did or its profiles",
|
|
813
|
-
PROOF_SERVICE_NO_CREDENTIAL_FOR_QUERY: "credential not found for query",
|
|
814
|
-
PROOF_SERVICE_PROFILE_GENESIS_DID_MISMATCH: "subject and auth profiles are not derived from the same did",
|
|
815
|
-
PROOF_SERVICE_NO_QUERIES_IN_ZKP_REQUEST: "no queries in zkp request",
|
|
816
|
-
// credential wallet
|
|
817
|
-
CREDENTIAL_WALLET_ALL_CREDENTIALS_ARE_REVOKED: "all claims are revoked"
|
|
818
|
-
},
|
|
819
|
-
CREDENTIAL_TYPE: {
|
|
820
|
-
// VerifiableCredential is a W3C verifiable credential type
|
|
821
|
-
W3C_VERIFIABLE_CREDENTIAL: "VerifiableCredential",
|
|
822
|
-
W3C_VERIFIABLE_PRESENTATION: "VerifiablePresentation"
|
|
823
|
-
},
|
|
824
|
-
CREDENTIAL_SUBJECT_PATH: "https://www.w3.org/2018/credentials#credentialSubject",
|
|
825
|
-
JSONLD_SCHEMA: {
|
|
826
|
-
// JSONLDSchemaIden3Credential is a schema for context with Iden3Credential type
|
|
827
|
-
IDEN3_CREDENTIAL: "https://schema.iden3.io/core/jsonld/iden3proofs.jsonld",
|
|
828
|
-
// JSONLDSchemaIden3DisplayMethod is a schema for context with Iden3BasicDisplayMethodV1 type
|
|
829
|
-
IDEN3_DISPLAY_METHOD: "https://schema.iden3.io/core/jsonld/displayMethod.jsonld",
|
|
830
|
-
// JSONLDSchemaW3CCredential2018 is a schema for context with VerifiableCredential type
|
|
831
|
-
W3C_CREDENTIAL_2018: "https://www.w3.org/2018/credentials/v1",
|
|
832
|
-
W3C_VC_DOCUMENT_2018: `{"@context":{"@version":1.1,"@protected":true,"id":"@id","type":"@type","VerifiableCredential":{"@id":"https://www.w3.org/2018/credentials#VerifiableCredential","@context":{"@version":1.1,"@protected":true,"id":"@id","type":"@type","cred":"https://www.w3.org/2018/credentials#","sec":"https://w3id.org/security#","xsd":"http://www.w3.org/2001/XMLSchema#","credentialSchema":{"@id":"cred:credentialSchema","@type":"@id","@context":{"@version":1.1,"@protected":true,"id":"@id","type":"@type","cred":"https://www.w3.org/2018/credentials#","JsonSchemaValidator2018":"cred:JsonSchemaValidator2018"}},"credentialStatus":{"@id":"cred:credentialStatus","@type":"@id"},"credentialSubject":{"@id":"cred:credentialSubject","@type":"@id"},"evidence":{"@id":"cred:evidence","@type":"@id"},"expirationDate":{"@id":"cred:expirationDate","@type":"xsd:dateTime"},"holder":{"@id":"cred:holder","@type":"@id"},"issued":{"@id":"cred:issued","@type":"xsd:dateTime"},"issuer":{"@id":"cred:issuer","@type":"@id"},"issuanceDate":{"@id":"cred:issuanceDate","@type":"xsd:dateTime"},"proof":{"@id":"sec:proof","@type":"@id","@container":"@graph"},"refreshService":{"@id":"cred:refreshService","@type":"@id","@context":{"@version":1.1,"@protected":true,"id":"@id","type":"@type","cred":"https://www.w3.org/2018/credentials#","ManualRefreshService2018":"cred:ManualRefreshService2018"}},"termsOfUse":{"@id":"cred:termsOfUse","@type":"@id"},"validFrom":{"@id":"cred:validFrom","@type":"xsd:dateTime"},"validUntil":{"@id":"cred:validUntil","@type":"xsd:dateTime"}}},"VerifiablePresentation":{"@id":"https://www.w3.org/2018/credentials#VerifiablePresentation","@context":{"@version":1.1,"@protected":true,"id":"@id","type":"@type","cred":"https://www.w3.org/2018/credentials#","sec":"https://w3id.org/security#","holder":{"@id":"cred:holder","@type":"@id"},"proof":{"@id":"sec:proof","@type":"@id","@container":"@graph"},"verifiableCredential":{"@id":"cred:verifiableCredential","@type":"@id","@container":"@graph"}}},"EcdsaSecp256k1Signature2019":{"@id":"https://w3id.org/security#EcdsaSecp256k1Signature2019","@context":{"@version":1.1,"@protected":true,"id":"@id","type":"@type","sec":"https://w3id.org/security#","xsd":"http://www.w3.org/2001/XMLSchema#","challenge":"sec:challenge","created":{"@id":"http://purl.org/dc/terms/created","@type":"xsd:dateTime"},"domain":"sec:domain","expires":{"@id":"sec:expiration","@type":"xsd:dateTime"},"jws":"sec:jws","nonce":"sec:nonce","proofPurpose":{"@id":"sec:proofPurpose","@type":"@vocab","@context":{"@version":1.1,"@protected":true,"id":"@id","type":"@type","sec":"https://w3id.org/security#","assertionMethod":{"@id":"sec:assertionMethod","@type":"@id","@container":"@set"},"authentication":{"@id":"sec:authenticationMethod","@type":"@id","@container":"@set"}}},"proofValue":"sec:proofValue","verificationMethod":{"@id":"sec:verificationMethod","@type":"@id"}}},"EcdsaSecp256r1Signature2019":{"@id":"https://w3id.org/security#EcdsaSecp256r1Signature2019","@context":{"@version":1.1,"@protected":true,"id":"@id","type":"@type","sec":"https://w3id.org/security#","xsd":"http://www.w3.org/2001/XMLSchema#","challenge":"sec:challenge","created":{"@id":"http://purl.org/dc/terms/created","@type":"xsd:dateTime"},"domain":"sec:domain","expires":{"@id":"sec:expiration","@type":"xsd:dateTime"},"jws":"sec:jws","nonce":"sec:nonce","proofPurpose":{"@id":"sec:proofPurpose","@type":"@vocab","@context":{"@version":1.1,"@protected":true,"id":"@id","type":"@type","sec":"https://w3id.org/security#","assertionMethod":{"@id":"sec:assertionMethod","@type":"@id","@container":"@set"},"authentication":{"@id":"sec:authenticationMethod","@type":"@id","@container":"@set"}}},"proofValue":"sec:proofValue","verificationMethod":{"@id":"sec:verificationMethod","@type":"@id"}}},"Ed25519Signature2018":{"@id":"https://w3id.org/security#Ed25519Signature2018","@context":{"@version":1.1,"@protected":true,"id":"@id","type":"@type","sec":"https://w3id.org/security#","xsd":"http://www.w3.org/2001/XMLSchema#","challenge":"sec:challenge","created":{"@id":"http://purl.org/dc/terms/created","@type":"xsd:dateTime"},"domain":"sec:domain","expires":{"@id":"sec:expiration","@type":"xsd:dateTime"},"jws":"sec:jws","nonce":"sec:nonce","proofPurpose":{"@id":"sec:proofPurpose","@type":"@vocab","@context":{"@version":1.1,"@protected":true,"id":"@id","type":"@type","sec":"https://w3id.org/security#","assertionMethod":{"@id":"sec:assertionMethod","@type":"@id","@container":"@set"},"authentication":{"@id":"sec:authenticationMethod","@type":"@id","@container":"@set"}}},"proofValue":"sec:proofValue","verificationMethod":{"@id":"sec:verificationMethod","@type":"@id"}}},"RsaSignature2018":{"@id":"https://w3id.org/security#RsaSignature2018","@context":{"@version":1.1,"@protected":true,"challenge":"sec:challenge","created":{"@id":"http://purl.org/dc/terms/created","@type":"xsd:dateTime"},"domain":"sec:domain","expires":{"@id":"sec:expiration","@type":"xsd:dateTime"},"jws":"sec:jws","nonce":"sec:nonce","proofPurpose":{"@id":"sec:proofPurpose","@type":"@vocab","@context":{"@version":1.1,"@protected":true,"id":"@id","type":"@type","sec":"https://w3id.org/security#","assertionMethod":{"@id":"sec:assertionMethod","@type":"@id","@container":"@set"},"authentication":{"@id":"sec:authenticationMethod","@type":"@id","@container":"@set"}}},"proofValue":"sec:proofValue","verificationMethod":{"@id":"sec:verificationMethod","@type":"@id"}}},"proof":{"@id":"https://w3id.org/security#proof","@type":"@id","@container":"@graph"}}}`,
|
|
833
|
-
IDEN3_PROOFS_DEFINITION_DOCUMENT: `{"@context":{"@version":1.1,"@protected":true,"id":"@id","type":"@type","Iden3SparseMerkleTreeProof":{"@id":"https://schema.iden3.io/core/jsonld/iden3proofs.jsonld#Iden3SparseMerkleTreeProof","@context":{"@version":1.1,"@protected":true,"@propagate":true,"id":"@id","type":"@type","sec":"https://w3id.org/security#","@vocab":"https://schema.iden3.io/core/vocab/Iden3SparseMerkleTreeProof.md#","xsd":"http://www.w3.org/2001/XMLSchema#","mtp":{"@id":"https://schema.iden3.io/core/jsonld/iden3proofs.jsonld#SparseMerkleTreeProof","@type":"SparseMerkleTreeProof"},"coreClaim":{"@id":"coreClaim","@type":"xsd:string"},"issuerData":{"@id":"issuerData","@context":{"@version":1.1,"state":{"@id":"state","@context":{"txId":{"@id":"txId","@type":"xsd:string"},"blockTimestamp":{"@id":"blockTimestamp","@type":"xsd:integer"},"blockNumber":{"@id":"blockNumber","@type":"xsd:integer"},"rootOfRoots":{"@id":"rootOfRoots","@type":"xsd:string"},"claimsTreeRoot":{"@id":"claimsTreeRoot","@type":"xsd:string"},"revocationTreeRoot":{"@id":"revocationTreeRoot","@type":"xsd:string"},"authCoreClaim":{"@id":"authCoreClaim","@type":"xsd:string"},"value":{"@id":"value","@type":"xsd:string"}}}}}}},"SparseMerkleTreeProof":{"@id":"https://schema.iden3.io/core/jsonld/iden3proofs.jsonld#SparseMerkleTreeProof","@context":{"@version":1.1,"@protected":true,"id":"@id","type":"@type","sec":"https://w3id.org/security#","smt-proof-vocab":"https://schema.iden3.io/core/vocab/SparseMerkleTreeProof.md#","xsd":"http://www.w3.org/2001/XMLSchema#","existence":{"@id":"smt-proof-vocab:existence","@type":"xsd:boolean"},"revocationNonce":{"@id":"smt-proof-vocab:revocationNonce","@type":"xsd:number"},"siblings":{"@id":"smt-proof-vocab:siblings","@container":"@list"},"nodeAux":"@nest","hIndex":{"@id":"smt-proof-vocab:hIndex","@nest":"nodeAux","@type":"xsd:string"},"hValue":{"@id":"smt-proof-vocab:hValue","@nest":"nodeAux","@type":"xsd:string"}}},"BJJSignature2021":{"@id":"https://schema.iden3.io/core/jsonld/iden3proofs.jsonld#BJJSignature2021","@context":{"@version":1.1,"@protected":true,"id":"@id","@vocab":"https://schema.iden3.io/core/vocab/BJJSignature2021.md#","@propagate":true,"type":"@type","xsd":"http://www.w3.org/2001/XMLSchema#","coreClaim":{"@id":"coreClaim","@type":"xsd:string"},"issuerData":{"@id":"issuerData","@context":{"@version":1.1,"authCoreClaim":{"@id":"authCoreClaim","@type":"xsd:string"},"mtp":{"@id":"https://schema.iden3.io/core/jsonld/iden3proofs.jsonld#SparseMerkleTreeProof","@type":"SparseMerkleTreeProof"},"revocationStatus":{"@id":"revocationStatus","@type":"@id"},"state":{"@id":"state","@context":{"@version":1.1,"rootOfRoots":{"@id":"rootOfRoots","@type":"xsd:string"},"claimsTreeRoot":{"@id":"claimsTreeRoot","@type":"xsd:string"},"revocationTreeRoot":{"@id":"revocationTreeRoot","@type":"xsd:string"},"value":{"@id":"value","@type":"xsd:string"}}}}},"signature":{"@id":"signature","@type":"https://w3id.org/security#multibase"},"domain":"https://w3id.org/security#domain","creator":{"@id":"creator","@type":"http://www.w3.org/2001/XMLSchema#string"},"challenge":"https://w3id.org/security#challenge","created":{"@id":"created","@type":"http://www.w3.org/2001/XMLSchema#dateTime"},"expires":{"@id":"https://w3id.org/security#expiration","@type":"http://www.w3.org/2001/XMLSchema#dateTime"},"nonce":"https://w3id.org/security#nonce","proofPurpose":{"@id":"https://w3id.org/security#proofPurpose","@type":"@vocab","@context":{"@protected":true,"id":"@id","type":"@type","assertionMethod":{"@id":"https://w3id.org/security#assertionMethod","@type":"@id","@container":"@set"},"authentication":{"@id":"https://w3id.org/security#authenticationMethod","@type":"@id","@container":"@set"},"capabilityInvocation":{"@id":"https://w3id.org/security#capabilityInvocationMethod","@type":"@id","@container":"@set"},"capabilityDelegation":{"@id":"https://w3id.org/security#capabilityDelegationMethod","@type":"@id","@container":"@set"},"keyAgreement":{"@id":"https://w3id.org/security#keyAgreementMethod","@type":"@id","@container":"@set"}}},"proofValue":{"@id":"https://w3id.org/security#proofValue","@type":"https://w3id.org/security#multibase"},"verificationMethod":{"@id":"https://w3id.org/security#verificationMethod","@type":"@id"}}},"Iden3ReverseSparseMerkleTreeProof":{"@id":"https://schema.iden3.io/core/jsonld/iden3proofs.jsonld#Iden3ReverseSparseMerkleTreeProof","@context":{"@version":1.1,"@protected":true,"id":"@id","type":"@type","iden3-reverse-sparse-merkle-tree-proof-vocab":"https://schema.iden3.io/core/vocab/Iden3ReverseSparseMerkleTreeProof.md#","xsd":"http://www.w3.org/2001/XMLSchema#","revocationNonce":{"@id":"iden3-reverse-sparse-merkle-tree-proof-vocab:revocationNonce","@type":"xsd:integer"},"statusIssuer":{"@context":{"@version":1.1,"@protected":true,"id":"@id","type":"@type"},"@id":"iden3-reverse-sparse-merkle-tree-proof-vocab:statusIssuer"}}},"Iden3commRevocationStatusV1.0":{"@id":"https://schema.iden3.io/core/jsonld/iden3proofs.jsonld#Iden3commRevocationStatusV1.0","@context":{"@version":1.1,"@protected":true,"id":"@id","type":"@type","iden3-comm-revocation-statusV1.0-vocab":"https://schema.iden3.io/core/vocab/Iden3commRevocationStatusV1.0.md#","xsd":"http://www.w3.org/2001/XMLSchema#","revocationNonce":{"@id":"iden3-comm-revocation-statusV1.0-vocab:revocationNonce","@type":"xsd:integer"},"statusIssuer":{"@context":{"@version":1.1,"@protected":true,"id":"@id","type":"@type"},"@id":"iden3-comm-revocation-statusV1.0-vocab:statusIssuer"}}},"Iden3OnchainSparseMerkleTreeProof2023":{"@id":"https://schema.iden3.io/core/jsonld/iden3proofs.jsonld#Iden3OnchainSparseMerkleTreeProof2023","@context":{"@version":1.1,"@protected":true,"id":"@id","type":"@type","iden3-onchain-sparse-merkle-tree-proof-2023-vocab":"https://schema.iden3.io/core/vocab/Iden3OnchainSparseMerkleTreeProof2023.md#","xsd":"http://www.w3.org/2001/XMLSchema#","revocationNonce":{"@id":"iden3-onchain-sparse-merkle-tree-proof-2023-vocab:revocationNonce","@type":"xsd:integer"},"statusIssuer":{"@context":{"@version":1.1,"@protected":true,"id":"@id","type":"@type"},"@id":"iden3-onchain-sparse-merkle-tree-proof-2023-vocab:statusIssuer"}}},"JsonSchema2023":"https://www.w3.org/ns/credentials#JsonSchema2023","Iden3RefreshService2023":"https://schema.iden3.io/core/jsonld/iden3proofs.jsonld#Iden3RefreshService2023"}}`,
|
|
834
|
-
IDEN3_DISPLAY_METHOD_DEFINITION_DOCUMENT: `{"@context":{"@version":1.1,"@protected":true,"id":"@id","type":"@type","displayMethod":{"@id":"https://schema.iden3.io/core/vocab/displayMethod.md#displayMethod","@type":"@id","@context":{"@version":1.1,"@protected":true,"id":"@id","type":"@type","Iden3BasicDisplayMethodV1":"https://schema.iden3.io/core/vocab/displayMethod.md#Iden3BasicDisplayMethodV1"}}}}`
|
|
835
|
-
},
|
|
836
|
-
// JsonSchema2023 JSON schema for verification of Iden3Credential
|
|
837
|
-
JSON_SCHEMA_VALIDATOR: "JsonSchema2023",
|
|
838
|
-
SERVICE_TYPE: {
|
|
839
|
-
// Iden3CommServiceType is service type for iden3comm protocol
|
|
840
|
-
IDEN3_COMM: "iden3-communication",
|
|
841
|
-
// PushNotificationServiceType is service type for delivering push notifications to identity
|
|
842
|
-
PUSH_NOTIFICATION: "push-notification"
|
|
843
|
-
},
|
|
844
|
-
AUTH: {
|
|
845
|
-
AUTH_BJJ_CREDENTIAL_HASH: "013fd3f623559d850fb5b02ff012d0e2",
|
|
846
|
-
AUTH_BJJ_CREDENTIAL_SCHEMA_JSON_URL: "https://schema.iden3.io/core/json/auth.json",
|
|
847
|
-
AUTH_BJJ_CREDENTIAL_SCHEMA_JSONLD_URL: "https://schema.iden3.io/core/jsonld/auth.jsonld",
|
|
848
|
-
AUTH_BJJ_CREDENTIAL_TYPE: "AuthBJJCredential",
|
|
849
|
-
AUTH_BJJ_CREDENTIAL_SCHEMA_JSON: `{"$schema":"http://json-schema.org/draft-07/schema#","$metadata":{"uris":{"jsonLdContext":"https://schema.iden3.io/core/jsonld/auth.jsonld","jsonSchema":"https://schema.iden3.io/core/json/auth.json"},"serialization":{"indexDataSlotA":"x","indexDataSlotB":"y"}},"type":"object","required":["@context","id","type","issuanceDate","credentialSubject","credentialSchema","credentialStatus","issuer"],"properties":{"@context":{"type":["string","array","object"]},"id":{"type":"string"},"type":{"type":["string","array"],"items":{"type":"string"}},"issuer":{"type":["string","object"],"format":"uri","required":["id"],"properties":{"id":{"type":"string","format":"uri"}}},"issuanceDate":{"type":"string","format":"date-time"},"expirationDate":{"type":"string","format":"date-time"},"credentialSchema":{"type":"object","required":["id","type"],"properties":{"id":{"type":"string","format":"uri"},"type":{"type":"string"}}},"credentialSubject":{"type":"object","required":["x","y"],"properties":{"id":{"title":"Credential Subject ID","type":"string","format":"uri"},"x":{"type":"string"},"y":{"type":"string"}}}}}`,
|
|
850
|
-
AUTH_BJJ_CREDENTIAL_SCHEMA_JSONLD: `{"@context":[{"@version":1.1,"@protected":true,"id":"@id","type":"@type","AuthBJJCredential":{"@id":"https://schema.iden3.io/core/jsonld/auth.jsonld#AuthBJJCredential","@context":{"@version":1.1,"@protected":true,"id":"@id","type":"@type","iden3_serialization":"iden3:v1:slotIndexA=x&slotIndexB=y","xsd":"http://www.w3.org/2001/XMLSchema#","auth-vocab":"https://schema.iden3.io/core/vocab/auth.md#","x":{"@id":"auth-vocab:x","@type":"xsd:positiveInteger"},"y":{"@id":"auth-vocab:y","@type":"xsd:positiveInteger"}}},"Iden3StateInfo2023":{"@id":"https://schema.iden3.io/core/jsonld/auth.jsonld#Iden3StateInfo2023","@context":{"@version":1.1,"@protected":true,"id":"@id","type":"@type","xsd":"http://www.w3.org/2001/XMLSchema#","@vocab":"https://schema.iden3.io/core/vocab/state-info.md#","@propagate":true,"stateContractAddress":{"@id":"stateContractAddress","@type":"xsd:string"},"published":{"@id":"published","@type":"xsd:boolean"},"info":{"@id":"info","@type":"@id","@context":{"@protected":true,"id":{"@id":"id","@type":"xsd:string"},"state":{"@id":"state","@type":"xsd:string"},"replacedByState":{"@id":"replacedByState","@type":"xsd:string"},"createdAtTimestamp":{"@id":"createdAtTimestamp","@type":"xsd:string"},"replacedAtTimestamp":{"@id":"replacedAtTimestamp","@type":"xsd:string"},"createdAtBlock":{"@id":"createdAtBlock","@type":"xsd:string"},"replacedAtBlock":{"@id":"replacedAtBlock","@type":"xsd:string"}}},"global":{"@id":"global","@type":"@id","@context":{"@protected":true,"sec":"https://w3id.org/security#","root":{"@id":"root","@type":"xsd:string"},"replacedByRoot":{"@id":"replacedByRoot","@type":"xsd:string"},"createdAtTimestamp":{"@id":"createdAtTimestamp","@type":"xsd:string"},"replacedAtTimestamp":{"@id":"replacedAtTimestamp","@type":"xsd:string"},"createdAtBlock":{"@id":"createdAtBlock","@type":"xsd:string"},"replacedAtBlock":{"@id":"replacedAtBlock","@type":"xsd:string"},"proof":{"@id":"sec:proof","@type":"@id","@container":"@graph"}}}}}}]}`
|
|
851
|
-
}
|
|
852
|
-
});
|
|
853
|
-
var ProofType = /* @__PURE__ */ ((ProofType2) => {
|
|
854
|
-
ProofType2["BJJSignature"] = "BJJSignature2021";
|
|
855
|
-
ProofType2["Iden3SparseMerkleTreeProof"] = "Iden3SparseMerkleTreeProof";
|
|
856
|
-
return ProofType2;
|
|
857
|
-
})(ProofType || {});
|
|
858
|
-
var CredentialStatusType = /* @__PURE__ */ ((CredentialStatusType2) => {
|
|
859
|
-
CredentialStatusType2["SparseMerkleTreeProof"] = "SparseMerkleTreeProof";
|
|
860
|
-
CredentialStatusType2["Iden3ReverseSparseMerkleTreeProof"] = "Iden3ReverseSparseMerkleTreeProof";
|
|
861
|
-
CredentialStatusType2["Iden3commRevocationStatusV1"] = "Iden3commRevocationStatusV1.0";
|
|
862
|
-
CredentialStatusType2["Iden3OnchainSparseMerkleTreeProof2023"] = "Iden3OnchainSparseMerkleTreeProof2023";
|
|
863
|
-
return CredentialStatusType2;
|
|
864
|
-
})(CredentialStatusType || {});
|
|
865
|
-
var ProofPurpose = /* @__PURE__ */ ((ProofPurpose2) => {
|
|
866
|
-
ProofPurpose2["Authentication"] = "Authentication";
|
|
867
|
-
return ProofPurpose2;
|
|
868
|
-
})(ProofPurpose || {});
|
|
869
|
-
var MerklizedRootPosition = /* @__PURE__ */ ((MerklizedRootPosition4) => {
|
|
870
|
-
MerklizedRootPosition4["Index"] = "index";
|
|
871
|
-
MerklizedRootPosition4["Value"] = "value";
|
|
872
|
-
MerklizedRootPosition4["None"] = "";
|
|
873
|
-
return MerklizedRootPosition4;
|
|
874
|
-
})(MerklizedRootPosition || {});
|
|
875
|
-
var SubjectPosition = /* @__PURE__ */ ((SubjectPosition2) => {
|
|
876
|
-
SubjectPosition2["None"] = "";
|
|
877
|
-
SubjectPosition2["Index"] = "index";
|
|
878
|
-
SubjectPosition2["Value"] = "value";
|
|
879
|
-
return SubjectPosition2;
|
|
880
|
-
})(SubjectPosition || {});
|
|
881
|
-
var RefreshServiceType = /* @__PURE__ */ ((RefreshServiceType2) => {
|
|
882
|
-
RefreshServiceType2["Iden3RefreshService2023"] = "Iden3RefreshService2023";
|
|
883
|
-
return RefreshServiceType2;
|
|
884
|
-
})(RefreshServiceType || {});
|
|
885
|
-
var PaymentRequestDataType = /* @__PURE__ */ ((PaymentRequestDataType2) => {
|
|
886
|
-
PaymentRequestDataType2["Iden3PaymentRequestCryptoV1"] = "Iden3PaymentRequestCryptoV1";
|
|
887
|
-
PaymentRequestDataType2["Iden3PaymentRailsRequestV1"] = "Iden3PaymentRailsRequestV1";
|
|
888
|
-
PaymentRequestDataType2["Iden3PaymentRailsERC20RequestV1"] = "Iden3PaymentRailsERC20RequestV1";
|
|
889
|
-
return PaymentRequestDataType2;
|
|
890
|
-
})(PaymentRequestDataType || {});
|
|
891
|
-
var PaymentType = /* @__PURE__ */ ((PaymentType2) => {
|
|
892
|
-
PaymentType2["Iden3PaymentCryptoV1"] = "Iden3PaymentCryptoV1";
|
|
893
|
-
PaymentType2["Iden3PaymentRailsV1"] = "Iden3PaymentRailsV1";
|
|
894
|
-
PaymentType2["Iden3PaymentRailsERC20V1"] = "Iden3PaymentRailsERC20V1";
|
|
895
|
-
return PaymentType2;
|
|
896
|
-
})(PaymentType || {});
|
|
897
|
-
var SupportedPaymentProofType = /* @__PURE__ */ ((SupportedPaymentProofType2) => {
|
|
898
|
-
SupportedPaymentProofType2["EthereumEip712Signature2021"] = "EthereumEip712Signature2021";
|
|
899
|
-
return SupportedPaymentProofType2;
|
|
900
|
-
})(SupportedPaymentProofType || {});
|
|
901
|
-
var SupportedCurrencies = /* @__PURE__ */ ((SupportedCurrencies2) => {
|
|
902
|
-
SupportedCurrencies2["ETH"] = "ETH";
|
|
903
|
-
SupportedCurrencies2["ETH_WEI"] = "ETHWEI";
|
|
904
|
-
SupportedCurrencies2["ETH_GWEI"] = "ETHGWEI";
|
|
905
|
-
SupportedCurrencies2["MATIC"] = "MATIC";
|
|
906
|
-
SupportedCurrencies2["POL"] = "POL";
|
|
907
|
-
return SupportedCurrencies2;
|
|
908
|
-
})(SupportedCurrencies || {});
|
|
909
|
-
var PaymentFeatures = /* @__PURE__ */ ((PaymentFeatures2) => {
|
|
910
|
-
PaymentFeatures2["EIP_2612"] = "EIP-2612";
|
|
911
|
-
return PaymentFeatures2;
|
|
912
|
-
})(PaymentFeatures || {});
|
|
913
|
-
var DisplayMethodType = /* @__PURE__ */ ((DisplayMethodType2) => {
|
|
914
|
-
DisplayMethodType2["Iden3BasicDisplayMethodV1"] = "Iden3BasicDisplayMethodV1";
|
|
915
|
-
return DisplayMethodType2;
|
|
916
|
-
})(DisplayMethodType || {});
|
|
917
|
-
var DEFAULT_CACHE_MAX_SIZE = 1e4;
|
|
791
|
+
import { Hash as Hash3, rootFromProof, verifyProof } from "@iden3/js-merkletree";
|
|
792
|
+
import { Merklizer as Merklizer2 } from "@iden3/js-jsonld-merklization";
|
|
793
|
+
import { PublicKey as PublicKey2, poseidon } from "@iden3/js-crypto";
|
|
918
794
|
|
|
919
|
-
// src/
|
|
920
|
-
import {
|
|
921
|
-
import {
|
|
922
|
-
var
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
mtp;
|
|
926
|
-
coreClaim;
|
|
927
|
-
/**
|
|
928
|
-
* Creates an instance of Iden3SparseMerkleTreeProof.
|
|
929
|
-
* @param {object} obj
|
|
930
|
-
*/
|
|
931
|
-
constructor(obj) {
|
|
932
|
-
this.coreClaim = obj.coreClaim;
|
|
933
|
-
this.issuerData = obj.issuerData;
|
|
934
|
-
this.type = "Iden3SparseMerkleTreeProof" /* Iden3SparseMerkleTreeProof */;
|
|
935
|
-
this.mtp = obj.mtp;
|
|
936
|
-
}
|
|
937
|
-
/**
|
|
938
|
-
*
|
|
939
|
-
*
|
|
940
|
-
* @returns `json object in serialized presentation`
|
|
941
|
-
*/
|
|
942
|
-
toJSON() {
|
|
943
|
-
const issuerId = this.issuerData.id;
|
|
944
|
-
return {
|
|
945
|
-
issuerData: {
|
|
946
|
-
id: issuerId.string(),
|
|
947
|
-
state: {
|
|
948
|
-
...this.issuerData.state,
|
|
949
|
-
rootOfRoots: this.issuerData.state.rootOfRoots.hex(),
|
|
950
|
-
claimsTreeRoot: this.issuerData.state.claimsTreeRoot.hex(),
|
|
951
|
-
revocationTreeRoot: this.issuerData.state.revocationTreeRoot.hex(),
|
|
952
|
-
value: this.issuerData.state.value.hex()
|
|
953
|
-
}
|
|
954
|
-
},
|
|
955
|
-
type: this.type,
|
|
956
|
-
coreClaim: this.coreClaim.hex(),
|
|
957
|
-
mtp: this.mtp.toJSON()
|
|
958
|
-
};
|
|
795
|
+
// src/credentials/utils.ts
|
|
796
|
+
import { DID as DID3 } from "@iden3/js-iden3-core";
|
|
797
|
+
import { PublicKey } from "@iden3/js-crypto";
|
|
798
|
+
var getUserDIDFromCredential = (issuerDID, credential) => {
|
|
799
|
+
if (!credential.credentialSubject.id) {
|
|
800
|
+
return issuerDID;
|
|
959
801
|
}
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
let mtp;
|
|
963
|
-
if (obj?.mtp?.notEmpties && obj?.mtp?.depth && obj?.mtp?.siblings) {
|
|
964
|
-
const ne = obj?.mtp?.notEmpties;
|
|
965
|
-
const notEmpties = ne instanceof Uint8Array ? ne : new Uint8Array(Object.values(ne));
|
|
966
|
-
const siblingsHashes = obj?.mtp?.siblings.map(
|
|
967
|
-
(h) => Hash2.fromString(JSON.stringify(h))
|
|
968
|
-
);
|
|
969
|
-
const allSiblings = Proof.buildAllSiblings(obj?.mtp?.depth, notEmpties, siblingsHashes);
|
|
970
|
-
let nodeAux = obj.mtp.nodeAux || obj.mtp.node_aux;
|
|
971
|
-
if (nodeAux) {
|
|
972
|
-
nodeAux = {
|
|
973
|
-
key: Hash2.fromString(JSON.stringify(nodeAux.key)),
|
|
974
|
-
value: Hash2.fromString(JSON.stringify(nodeAux.value))
|
|
975
|
-
};
|
|
976
|
-
}
|
|
977
|
-
mtp = new Proof({ existence: obj?.mtp.existence, nodeAux, siblings: allSiblings });
|
|
978
|
-
} else {
|
|
979
|
-
mtp = Proof.fromJSON(obj.mtp);
|
|
980
|
-
}
|
|
981
|
-
return new _Iden3SparseMerkleTreeProof({
|
|
982
|
-
coreClaim: new Claim().fromHex(obj.coreClaim),
|
|
983
|
-
mtp,
|
|
984
|
-
issuerData: {
|
|
985
|
-
id: DID2.parse(obj.issuerData.id),
|
|
986
|
-
state: {
|
|
987
|
-
...obj.issuerData.state,
|
|
988
|
-
rootOfRoots: Hash2.fromHex(obj.issuerData.state.rootOfRoots),
|
|
989
|
-
claimsTreeRoot: Hash2.fromHex(obj.issuerData.state.claimsTreeRoot),
|
|
990
|
-
revocationTreeRoot: Hash2.fromHex(obj.issuerData.state.revocationTreeRoot),
|
|
991
|
-
value: Hash2.fromHex(obj.issuerData.state.value)
|
|
992
|
-
}
|
|
993
|
-
}
|
|
994
|
-
});
|
|
802
|
+
if (typeof credential.credentialSubject.id !== "string") {
|
|
803
|
+
throw new Error("credential subject `id` is not a string");
|
|
995
804
|
}
|
|
805
|
+
return DID3.parse(credential.credentialSubject.id);
|
|
996
806
|
};
|
|
997
|
-
var
|
|
998
|
-
type
|
|
999
|
-
|
|
1000
|
-
signature;
|
|
1001
|
-
coreClaim;
|
|
1002
|
-
constructor(obj) {
|
|
1003
|
-
this.type = "BJJSignature2021" /* BJJSignature */;
|
|
1004
|
-
this.issuerData = obj.issuerData;
|
|
1005
|
-
this.coreClaim = obj.coreClaim;
|
|
1006
|
-
this.signature = obj.signature;
|
|
1007
|
-
}
|
|
1008
|
-
/**
|
|
1009
|
-
* toJSON is a method to serialize BJJSignatureProof2021 to json
|
|
1010
|
-
*
|
|
1011
|
-
* @returns `json object in serialized presentation`
|
|
1012
|
-
*/
|
|
1013
|
-
toJSON() {
|
|
1014
|
-
return {
|
|
1015
|
-
issuerData: {
|
|
1016
|
-
id: this.issuerData.id.string(),
|
|
1017
|
-
state: {
|
|
1018
|
-
...this.issuerData.state,
|
|
1019
|
-
rootOfRoots: this.issuerData.state.rootOfRoots.hex(),
|
|
1020
|
-
claimsTreeRoot: this.issuerData.state.claimsTreeRoot.hex(),
|
|
1021
|
-
revocationTreeRoot: this.issuerData.state.revocationTreeRoot.hex(),
|
|
1022
|
-
value: this.issuerData.state.value.hex()
|
|
1023
|
-
},
|
|
1024
|
-
mtp: this.issuerData.mtp.toJSON(),
|
|
1025
|
-
authCoreClaim: this.issuerData.authCoreClaim.hex(),
|
|
1026
|
-
credentialStatus: this.issuerData.credentialStatus
|
|
1027
|
-
},
|
|
1028
|
-
type: this.type,
|
|
1029
|
-
coreClaim: this.coreClaim.hex(),
|
|
1030
|
-
signature: Hex4.encodeString(this.signature.compress())
|
|
1031
|
-
};
|
|
1032
|
-
}
|
|
1033
|
-
/**
|
|
1034
|
-
* fromJSON is a method to deserialize BJJSignatureProof2021 from json
|
|
1035
|
-
* @param obj
|
|
1036
|
-
*/
|
|
1037
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1038
|
-
static fromJSON(obj) {
|
|
1039
|
-
return new _BJJSignatureProof2021({
|
|
1040
|
-
issuerData: {
|
|
1041
|
-
id: DID2.parse(obj.issuerData.id),
|
|
1042
|
-
mtp: Proof.fromJSON(obj.issuerData.mtp),
|
|
1043
|
-
state: {
|
|
1044
|
-
...obj.issuerData.state,
|
|
1045
|
-
rootOfRoots: Hash2.fromHex(obj.issuerData.state.rootOfRoots),
|
|
1046
|
-
claimsTreeRoot: Hash2.fromHex(obj.issuerData.state.claimsTreeRoot),
|
|
1047
|
-
revocationTreeRoot: Hash2.fromHex(obj.issuerData.state.revocationTreeRoot),
|
|
1048
|
-
value: Hash2.fromHex(obj.issuerData.state.value)
|
|
1049
|
-
},
|
|
1050
|
-
credentialStatus: obj.issuerData.credentialStatus,
|
|
1051
|
-
authCoreClaim: new Claim().fromHex(obj.issuerData.authCoreClaim)
|
|
1052
|
-
},
|
|
1053
|
-
coreClaim: new Claim().fromHex(obj.coreClaim),
|
|
1054
|
-
signature: Signature2.newFromCompressed(
|
|
1055
|
-
Uint8Array.from(Hex4.decodeString(obj.signature)).slice(0, 64)
|
|
1056
|
-
)
|
|
1057
|
-
});
|
|
1058
|
-
}
|
|
1059
|
-
};
|
|
1060
|
-
|
|
1061
|
-
// src/verifiable/credential.ts
|
|
1062
|
-
import {
|
|
1063
|
-
Claim as Claim2,
|
|
1064
|
-
DID as DID4,
|
|
1065
|
-
MerklizedRootPosition as MerklizedRootPositionCore,
|
|
1066
|
-
IdPosition,
|
|
1067
|
-
ClaimOptions,
|
|
1068
|
-
getChainId
|
|
1069
|
-
} from "@iden3/js-iden3-core";
|
|
1070
|
-
import { Hash as Hash3, rootFromProof, verifyProof } from "@iden3/js-merkletree";
|
|
1071
|
-
import { Merklizer as Merklizer2 } from "@iden3/js-jsonld-merklization";
|
|
1072
|
-
import { PublicKey as PublicKey3, poseidon } from "@iden3/js-crypto";
|
|
1073
|
-
|
|
1074
|
-
// src/credentials/utils.ts
|
|
1075
|
-
import { DID as DID3 } from "@iden3/js-iden3-core";
|
|
1076
|
-
import { PublicKey as PublicKey2 } from "@iden3/js-crypto";
|
|
1077
|
-
var getUserDIDFromCredential = (issuerDID, credential) => {
|
|
1078
|
-
if (!credential.credentialSubject.id) {
|
|
1079
|
-
return issuerDID;
|
|
1080
|
-
}
|
|
1081
|
-
if (typeof credential.credentialSubject.id !== "string") {
|
|
1082
|
-
throw new Error("credential subject `id` is not a string");
|
|
1083
|
-
}
|
|
1084
|
-
return DID3.parse(credential.credentialSubject.id);
|
|
1085
|
-
};
|
|
1086
|
-
var getKMSIdByAuthCredential = (credential) => {
|
|
1087
|
-
if (!credential.type.includes("AuthBJJCredential")) {
|
|
1088
|
-
throw new Error("can't sign with not AuthBJJCredential credential");
|
|
807
|
+
var getKMSIdByAuthCredential = (credential) => {
|
|
808
|
+
if (!credential.type.includes("AuthBJJCredential")) {
|
|
809
|
+
throw new Error("can't sign with not AuthBJJCredential credential");
|
|
1089
810
|
}
|
|
1090
811
|
const x = credential.credentialSubject["x"];
|
|
1091
812
|
const y = credential.credentialSubject["y"];
|
|
1092
|
-
const pb = new
|
|
813
|
+
const pb = new PublicKey([BigInt(x), BigInt(y)]);
|
|
1093
814
|
const kp = keyPath("BJJ" /* BabyJubJub */, pb.hex());
|
|
1094
815
|
return { type: "BJJ" /* BabyJubJub */, id: kp };
|
|
1095
816
|
};
|
|
1096
817
|
|
|
1097
818
|
// src/verifiable/core-utils.ts
|
|
1098
|
-
import { BytesHelper
|
|
819
|
+
import { BytesHelper, SchemaHash } from "@iden3/js-iden3-core";
|
|
1099
820
|
import { Path } from "@iden3/js-jsonld-merklization";
|
|
1100
821
|
import jsonld from "jsonld";
|
|
1101
822
|
import { keccak256 as keccak2562 } from "ethers";
|
|
@@ -1147,7 +868,7 @@ var fillCoreClaimSlot = async (slotData, mz, path) => {
|
|
|
1147
868
|
const p = await mz.resolveDocPath(path, mz.options);
|
|
1148
869
|
const entry = await mz.entry(p);
|
|
1149
870
|
const intVal = await entry.getValueMtEntry();
|
|
1150
|
-
const bytesVal =
|
|
871
|
+
const bytesVal = BytesHelper.intToBytes(intVal);
|
|
1151
872
|
slotData.set(bytesVal, 0);
|
|
1152
873
|
} catch (err) {
|
|
1153
874
|
if (err.toString().includes("entry not found")) {
|
|
@@ -1628,7 +1349,7 @@ var W3CCredential = class _W3CCredential {
|
|
|
1628
1349
|
async verifyBJJSignatureProof(proof, coreClaim, resolverURL, userDID, credStatusResolverRegistry) {
|
|
1629
1350
|
const authClaim = proof.issuerData.authCoreClaim;
|
|
1630
1351
|
const rawSlotsInt = authClaim.rawSlotsAsInts();
|
|
1631
|
-
const pubKey = new
|
|
1352
|
+
const pubKey = new PublicKey2([rawSlotsInt[2], rawSlotsInt[3]]);
|
|
1632
1353
|
const { hi, hv } = coreClaim.hiHv();
|
|
1633
1354
|
const claimHash = poseidon.hash([hi, hv]);
|
|
1634
1355
|
const bjjValid = pubKey.verifyPoseidon(claimHash, proof.signature);
|
|
@@ -2037,13 +1758,681 @@ var DIDDocumentJSONSchema = `{
|
|
|
2037
1758
|
},
|
|
2038
1759
|
"deprecated": true
|
|
2039
1760
|
}
|
|
2040
|
-
},
|
|
2041
|
-
"required": [
|
|
2042
|
-
"id"
|
|
2043
|
-
]
|
|
2044
|
-
}`;
|
|
1761
|
+
},
|
|
1762
|
+
"required": [
|
|
1763
|
+
"id"
|
|
1764
|
+
]
|
|
1765
|
+
}`;
|
|
1766
|
+
|
|
1767
|
+
// src/utils/payments/solana.ts
|
|
1768
|
+
import { getUnixTimestamp } from "@iden3/js-iden3-core";
|
|
1769
|
+
import { PublicKey as PublicKey3 } from "@solana/web3.js";
|
|
1770
|
+
var SolanaNativePaymentRequest = class {
|
|
1771
|
+
version;
|
|
1772
|
+
chainId;
|
|
1773
|
+
verifyingContract;
|
|
1774
|
+
recipient;
|
|
1775
|
+
amount;
|
|
1776
|
+
expirationDate;
|
|
1777
|
+
nonce;
|
|
1778
|
+
metadata;
|
|
1779
|
+
constructor(fields) {
|
|
1780
|
+
this.version = fields.version;
|
|
1781
|
+
this.chainId = fields.chainId;
|
|
1782
|
+
this.verifyingContract = fields.verifyingContract;
|
|
1783
|
+
this.recipient = fields.recipient;
|
|
1784
|
+
this.amount = fields.amount;
|
|
1785
|
+
this.expirationDate = fields.expirationDate;
|
|
1786
|
+
this.nonce = fields.nonce;
|
|
1787
|
+
this.metadata = fields.metadata;
|
|
1788
|
+
}
|
|
1789
|
+
};
|
|
1790
|
+
var SolanaSplPaymentRequest = class {
|
|
1791
|
+
version;
|
|
1792
|
+
chainId;
|
|
1793
|
+
verifyingContract;
|
|
1794
|
+
tokenAddress;
|
|
1795
|
+
recipient;
|
|
1796
|
+
amount;
|
|
1797
|
+
expirationDate;
|
|
1798
|
+
nonce;
|
|
1799
|
+
metadata;
|
|
1800
|
+
constructor(fields) {
|
|
1801
|
+
this.version = fields.version;
|
|
1802
|
+
this.chainId = fields.chainId;
|
|
1803
|
+
this.verifyingContract = fields.verifyingContract;
|
|
1804
|
+
this.tokenAddress = fields.tokenAddress;
|
|
1805
|
+
this.recipient = fields.recipient;
|
|
1806
|
+
this.amount = fields.amount;
|
|
1807
|
+
this.expirationDate = fields.expirationDate;
|
|
1808
|
+
this.nonce = fields.nonce;
|
|
1809
|
+
this.metadata = fields.metadata;
|
|
1810
|
+
}
|
|
1811
|
+
};
|
|
1812
|
+
var SolanaNativePaymentSchema = /* @__PURE__ */ new Map([
|
|
1813
|
+
[
|
|
1814
|
+
SolanaNativePaymentRequest,
|
|
1815
|
+
{
|
|
1816
|
+
kind: "struct",
|
|
1817
|
+
fields: [
|
|
1818
|
+
["version", ["u8"]],
|
|
1819
|
+
["chainId", "u64"],
|
|
1820
|
+
["verifyingContract", ["u8", 32]],
|
|
1821
|
+
["recipient", ["u8", 32]],
|
|
1822
|
+
["amount", "u64"],
|
|
1823
|
+
["expirationDate", "u64"],
|
|
1824
|
+
["nonce", "u64"],
|
|
1825
|
+
["metadata", ["u8"]]
|
|
1826
|
+
]
|
|
1827
|
+
}
|
|
1828
|
+
]
|
|
1829
|
+
]);
|
|
1830
|
+
var SolanaSplPaymentSchema = /* @__PURE__ */ new Map([
|
|
1831
|
+
[
|
|
1832
|
+
SolanaSplPaymentRequest,
|
|
1833
|
+
{
|
|
1834
|
+
kind: "struct",
|
|
1835
|
+
fields: [
|
|
1836
|
+
["version", ["u8"]],
|
|
1837
|
+
["chainId", "u64"],
|
|
1838
|
+
["verifyingContract", ["u8", 32]],
|
|
1839
|
+
["tokenAddress", ["u8", 32]],
|
|
1840
|
+
["recipient", ["u8", 32]],
|
|
1841
|
+
["amount", "u64"],
|
|
1842
|
+
["expirationDate", "u64"],
|
|
1843
|
+
["nonce", "u64"],
|
|
1844
|
+
["metadata", ["u8"]]
|
|
1845
|
+
]
|
|
1846
|
+
}
|
|
1847
|
+
]
|
|
1848
|
+
]);
|
|
1849
|
+
var SolanaPaymentInstruction = class {
|
|
1850
|
+
recipient;
|
|
1851
|
+
amount;
|
|
1852
|
+
expiration_date;
|
|
1853
|
+
nonce;
|
|
1854
|
+
metadata;
|
|
1855
|
+
signature;
|
|
1856
|
+
constructor(fields) {
|
|
1857
|
+
this.recipient = fields.recipient;
|
|
1858
|
+
this.amount = fields.amount;
|
|
1859
|
+
this.expiration_date = fields.expiration_date;
|
|
1860
|
+
this.nonce = fields.nonce;
|
|
1861
|
+
this.metadata = fields.metadata;
|
|
1862
|
+
this.signature = fields.signature;
|
|
1863
|
+
}
|
|
1864
|
+
};
|
|
1865
|
+
var SolanaPaymentInstructionSchema = /* @__PURE__ */ new Map([
|
|
1866
|
+
[
|
|
1867
|
+
SolanaPaymentInstruction,
|
|
1868
|
+
{
|
|
1869
|
+
kind: "struct",
|
|
1870
|
+
fields: [
|
|
1871
|
+
["recipient", ["u8", 32]],
|
|
1872
|
+
["amount", "u64"],
|
|
1873
|
+
["expiration_date", "u64"],
|
|
1874
|
+
["nonce", "u64"],
|
|
1875
|
+
["metadata", ["u8"]],
|
|
1876
|
+
["signature", [64]]
|
|
1877
|
+
]
|
|
1878
|
+
}
|
|
1879
|
+
]
|
|
1880
|
+
]);
|
|
1881
|
+
var buildSolanaPayment = async (solSigner, option, chainId, paymentRails, recipient, amount, expirationDate, nonce) => {
|
|
1882
|
+
let serialized;
|
|
1883
|
+
const proofVersion = option.type === "Iden3PaymentRailsSolanaRequestV1" /* Iden3PaymentRailsSolanaRequestV1 */ ? "SolanaEd25519NativeV1" : "SolanaEd25519SPLV1";
|
|
1884
|
+
let chainRef = chainId;
|
|
1885
|
+
switch (chainId) {
|
|
1886
|
+
case "101":
|
|
1887
|
+
chainRef = SOLANA_CHAIN_REF.DEVNET;
|
|
1888
|
+
break;
|
|
1889
|
+
case "102":
|
|
1890
|
+
chainRef = SOLANA_CHAIN_REF.TESTNET;
|
|
1891
|
+
break;
|
|
1892
|
+
case "103":
|
|
1893
|
+
chainRef = SOLANA_CHAIN_REF.MAINNET;
|
|
1894
|
+
break;
|
|
1895
|
+
}
|
|
1896
|
+
if (option.type === "Iden3PaymentRailsSolanaRequestV1" /* Iden3PaymentRailsSolanaRequestV1 */) {
|
|
1897
|
+
const request = new SolanaNativePaymentRequest({
|
|
1898
|
+
version: byteEncoder.encode(proofVersion),
|
|
1899
|
+
chainId: BigInt(chainId),
|
|
1900
|
+
verifyingContract: new PublicKey3(paymentRails).toBytes(),
|
|
1901
|
+
recipient: new PublicKey3(recipient).toBytes(),
|
|
1902
|
+
amount: BigInt(amount),
|
|
1903
|
+
expirationDate: BigInt(getUnixTimestamp(expirationDate)),
|
|
1904
|
+
nonce,
|
|
1905
|
+
metadata: byteEncoder.encode("0x")
|
|
1906
|
+
});
|
|
1907
|
+
serialized = serialize(SolanaNativePaymentSchema, request);
|
|
1908
|
+
} else {
|
|
1909
|
+
if (!option.contractAddress) {
|
|
1910
|
+
throw new Error(`failed request. no contract address for ${option.type} payment type`);
|
|
1911
|
+
}
|
|
1912
|
+
const request = new SolanaSplPaymentRequest({
|
|
1913
|
+
version: byteEncoder.encode(proofVersion),
|
|
1914
|
+
chainId: BigInt(chainId),
|
|
1915
|
+
verifyingContract: new PublicKey3(paymentRails).toBytes(),
|
|
1916
|
+
tokenAddress: new PublicKey3(option.contractAddress).toBytes(),
|
|
1917
|
+
recipient: new PublicKey3(recipient).toBytes(),
|
|
1918
|
+
amount: BigInt(amount),
|
|
1919
|
+
expirationDate: BigInt(getUnixTimestamp(expirationDate)),
|
|
1920
|
+
nonce,
|
|
1921
|
+
metadata: byteEncoder.encode("0x")
|
|
1922
|
+
});
|
|
1923
|
+
serialized = serialize(SolanaSplPaymentSchema, request);
|
|
1924
|
+
}
|
|
1925
|
+
const privateKey = solSigner.secretKey.slice(0, 32);
|
|
1926
|
+
const signature = await ed25519.sign(serialized, privateKey);
|
|
1927
|
+
const proof = [
|
|
1928
|
+
{
|
|
1929
|
+
type: "SolanaEd25519Signature2025" /* SolanaEd25519Signature2025 */,
|
|
1930
|
+
proofPurpose: "assertionMethod",
|
|
1931
|
+
proofValue: bytesToHex(signature),
|
|
1932
|
+
created: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1933
|
+
verificationMethod: `did:pkh:solana:${chainRef}:${solSigner.publicKey.toBase58()}`,
|
|
1934
|
+
domain: {
|
|
1935
|
+
version: proofVersion,
|
|
1936
|
+
chainId,
|
|
1937
|
+
verifyingContract: paymentRails
|
|
1938
|
+
}
|
|
1939
|
+
}
|
|
1940
|
+
];
|
|
1941
|
+
const d = {
|
|
1942
|
+
type: "Iden3PaymentRailsSolanaRequestV1" /* Iden3PaymentRailsSolanaRequestV1 */,
|
|
1943
|
+
"@context": [
|
|
1944
|
+
`https://schema.iden3.io/core/jsonld/payment.jsonld#${option.type}`,
|
|
1945
|
+
"https://schema.iden3.io/core/jsonld/solanaEd25519.jsonld"
|
|
1946
|
+
],
|
|
1947
|
+
recipient,
|
|
1948
|
+
amount: amount.toString(),
|
|
1949
|
+
expirationDate: expirationDate.toISOString(),
|
|
1950
|
+
nonce: nonce.toString(),
|
|
1951
|
+
metadata: "0x",
|
|
1952
|
+
proof
|
|
1953
|
+
};
|
|
1954
|
+
if (option.type === "Iden3PaymentRailsSolanaRequestV1" /* Iden3PaymentRailsSolanaRequestV1 */) {
|
|
1955
|
+
return d;
|
|
1956
|
+
}
|
|
1957
|
+
return {
|
|
1958
|
+
...d,
|
|
1959
|
+
type: option.type,
|
|
1960
|
+
tokenAddress: option.contractAddress || "",
|
|
1961
|
+
features: option.features || []
|
|
1962
|
+
};
|
|
1963
|
+
};
|
|
1964
|
+
var serializeSolanaPaymentInstruction = (data) => {
|
|
1965
|
+
let serialized;
|
|
1966
|
+
const proof = Array.isArray(data.proof) ? data.proof[0] : data.proof;
|
|
1967
|
+
const proofVersion = data.type === "Iden3PaymentRailsSolanaRequestV1" /* Iden3PaymentRailsSolanaRequestV1 */ ? "SolanaEd25519NativeV1" : "SolanaEd25519SPLV1";
|
|
1968
|
+
if (data.type === "Iden3PaymentRailsSolanaRequestV1" /* Iden3PaymentRailsSolanaRequestV1 */) {
|
|
1969
|
+
const request = new SolanaNativePaymentRequest({
|
|
1970
|
+
version: byteEncoder.encode(proofVersion),
|
|
1971
|
+
chainId: BigInt(proof.domain.chainId),
|
|
1972
|
+
verifyingContract: new PublicKey3(proof.domain.verifyingContract).toBytes(),
|
|
1973
|
+
recipient: new PublicKey3(data.recipient).toBytes(),
|
|
1974
|
+
amount: BigInt(data.amount),
|
|
1975
|
+
expirationDate: BigInt(getUnixTimestamp(new Date(data.expirationDate))),
|
|
1976
|
+
nonce: BigInt(data.nonce),
|
|
1977
|
+
metadata: byteEncoder.encode("0x")
|
|
1978
|
+
});
|
|
1979
|
+
serialized = serialize(SolanaNativePaymentSchema, request);
|
|
1980
|
+
} else {
|
|
1981
|
+
const request = new SolanaSplPaymentRequest({
|
|
1982
|
+
version: byteEncoder.encode(proofVersion),
|
|
1983
|
+
chainId: BigInt(proof.domain.chainId),
|
|
1984
|
+
verifyingContract: new PublicKey3(proof.domain.verifyingContract).toBytes(),
|
|
1985
|
+
tokenAddress: new PublicKey3(data.tokenAddress).toBytes(),
|
|
1986
|
+
recipient: new PublicKey3(data.recipient).toBytes(),
|
|
1987
|
+
amount: BigInt(data.amount),
|
|
1988
|
+
expirationDate: BigInt(getUnixTimestamp(new Date(data.expirationDate))),
|
|
1989
|
+
nonce: BigInt(data.nonce),
|
|
1990
|
+
metadata: byteEncoder.encode("0x")
|
|
1991
|
+
});
|
|
1992
|
+
serialized = serialize(SolanaSplPaymentSchema, request);
|
|
1993
|
+
}
|
|
1994
|
+
return serialized;
|
|
1995
|
+
};
|
|
1996
|
+
var verifyIden3SolanaPaymentRequest = async (data, resolver) => {
|
|
1997
|
+
const proof = Array.isArray(data.proof) ? data.proof[0] : data.proof;
|
|
1998
|
+
let serialized;
|
|
1999
|
+
if (data.type === "Iden3PaymentRailsSolanaRequestV1" /* Iden3PaymentRailsSolanaRequestV1 */) {
|
|
2000
|
+
const request = new SolanaNativePaymentRequest({
|
|
2001
|
+
version: byteEncoder.encode(proof.domain.version),
|
|
2002
|
+
chainId: BigInt(proof.domain.chainId),
|
|
2003
|
+
verifyingContract: new PublicKey3(proof.domain.verifyingContract).toBytes(),
|
|
2004
|
+
recipient: new PublicKey3(data.recipient).toBytes(),
|
|
2005
|
+
amount: BigInt(data.amount),
|
|
2006
|
+
expirationDate: BigInt(getUnixTimestamp(new Date(data.expirationDate))),
|
|
2007
|
+
nonce: BigInt(data.nonce),
|
|
2008
|
+
metadata: byteEncoder.encode("0x")
|
|
2009
|
+
});
|
|
2010
|
+
serialized = serialize(SolanaNativePaymentSchema, request);
|
|
2011
|
+
} else {
|
|
2012
|
+
const request = new SolanaSplPaymentRequest({
|
|
2013
|
+
version: byteEncoder.encode(proof.domain.version),
|
|
2014
|
+
chainId: BigInt(proof.domain.chainId),
|
|
2015
|
+
verifyingContract: new PublicKey3(proof.domain.verifyingContract).toBytes(),
|
|
2016
|
+
tokenAddress: new PublicKey3(data.tokenAddress).toBytes(),
|
|
2017
|
+
recipient: new PublicKey3(data.recipient).toBytes(),
|
|
2018
|
+
amount: BigInt(data.amount),
|
|
2019
|
+
expirationDate: BigInt(getUnixTimestamp(new Date(data.expirationDate))),
|
|
2020
|
+
nonce: BigInt(data.nonce),
|
|
2021
|
+
metadata: byteEncoder.encode("0x")
|
|
2022
|
+
});
|
|
2023
|
+
serialized = serialize(SolanaSplPaymentSchema, request);
|
|
2024
|
+
}
|
|
2025
|
+
const { didDocument } = await resolver.resolve(proof.verificationMethod);
|
|
2026
|
+
let publicKeyMultibase;
|
|
2027
|
+
if (didDocument?.verificationMethod) {
|
|
2028
|
+
for (const verificationMethod of didDocument.verificationMethod) {
|
|
2029
|
+
if (verificationMethod.type === "Ed25519VerificationKey2020") {
|
|
2030
|
+
publicKeyMultibase = verificationMethod.publicKeyMultibase;
|
|
2031
|
+
}
|
|
2032
|
+
}
|
|
2033
|
+
}
|
|
2034
|
+
if (!publicKeyMultibase) {
|
|
2035
|
+
throw new Error("No Ed25519VerificationKey2020 found in DID document");
|
|
2036
|
+
}
|
|
2037
|
+
return ed25519.verify(proof.proofValue, serialized, new PublicKey3(publicKeyMultibase).toBytes());
|
|
2038
|
+
};
|
|
2039
|
+
|
|
2040
|
+
// src/utils/payments/evm.ts
|
|
2041
|
+
import { ethers } from "ethers";
|
|
2042
|
+
import { getUnixTimestamp as getUnixTimestamp2 } from "@iden3/js-iden3-core";
|
|
2043
|
+
var buildEvmPayment = async (signer, option, chainId, paymentRails, recipient, amount, expirationDateRequired, nonce) => {
|
|
2044
|
+
const typeUrl = `https://schema.iden3.io/core/json/${option.type}.json`;
|
|
2045
|
+
const typesFetchResult = await fetch(typeUrl);
|
|
2046
|
+
const types = await typesFetchResult.json();
|
|
2047
|
+
delete types.EIP712Domain;
|
|
2048
|
+
const paymentData = option.type === "Iden3PaymentRailsRequestV1" /* Iden3PaymentRailsRequestV1 */ ? {
|
|
2049
|
+
recipient,
|
|
2050
|
+
amount,
|
|
2051
|
+
expirationDate: getUnixTimestamp2(expirationDateRequired),
|
|
2052
|
+
nonce,
|
|
2053
|
+
metadata: "0x"
|
|
2054
|
+
} : {
|
|
2055
|
+
tokenAddress: option.contractAddress,
|
|
2056
|
+
recipient,
|
|
2057
|
+
amount,
|
|
2058
|
+
expirationDate: getUnixTimestamp2(expirationDateRequired),
|
|
2059
|
+
nonce,
|
|
2060
|
+
metadata: "0x"
|
|
2061
|
+
};
|
|
2062
|
+
const domain = {
|
|
2063
|
+
name: "MCPayment",
|
|
2064
|
+
version: "1.0.0",
|
|
2065
|
+
chainId,
|
|
2066
|
+
verifyingContract: paymentRails
|
|
2067
|
+
};
|
|
2068
|
+
const signature = await signer.signTypedData(domain, types, paymentData);
|
|
2069
|
+
const proof = [
|
|
2070
|
+
{
|
|
2071
|
+
type: "EthereumEip712Signature2021" /* EthereumEip712Signature2021 */,
|
|
2072
|
+
proofPurpose: "assertionMethod",
|
|
2073
|
+
proofValue: signature,
|
|
2074
|
+
verificationMethod: `did:pkh:eip155:${chainId}:${await signer.getAddress()}`,
|
|
2075
|
+
created: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2076
|
+
eip712: {
|
|
2077
|
+
types: typeUrl,
|
|
2078
|
+
primaryType: "Iden3PaymentRailsRequestV1",
|
|
2079
|
+
domain
|
|
2080
|
+
}
|
|
2081
|
+
}
|
|
2082
|
+
];
|
|
2083
|
+
const d = {
|
|
2084
|
+
type: "Iden3PaymentRailsRequestV1" /* Iden3PaymentRailsRequestV1 */,
|
|
2085
|
+
"@context": [
|
|
2086
|
+
`https://schema.iden3.io/core/jsonld/payment.jsonld#${option.type}`,
|
|
2087
|
+
"https://w3id.org/security/suites/eip712sig-2021/v1"
|
|
2088
|
+
],
|
|
2089
|
+
recipient,
|
|
2090
|
+
amount: amount.toString(),
|
|
2091
|
+
expirationDate: expirationDateRequired.toISOString(),
|
|
2092
|
+
nonce: nonce.toString(),
|
|
2093
|
+
metadata: "0x",
|
|
2094
|
+
proof
|
|
2095
|
+
};
|
|
2096
|
+
if (option.type === "Iden3PaymentRailsRequestV1" /* Iden3PaymentRailsRequestV1 */) {
|
|
2097
|
+
return d;
|
|
2098
|
+
}
|
|
2099
|
+
return {
|
|
2100
|
+
...d,
|
|
2101
|
+
type: option.type,
|
|
2102
|
+
tokenAddress: option.contractAddress || "",
|
|
2103
|
+
features: option.features || []
|
|
2104
|
+
};
|
|
2105
|
+
};
|
|
2106
|
+
async function verifyEIP712TypedData(data, resolver) {
|
|
2107
|
+
const paymentData = data.type === "Iden3PaymentRailsRequestV1" /* Iden3PaymentRailsRequestV1 */ ? {
|
|
2108
|
+
recipient: data.recipient,
|
|
2109
|
+
amount: data.amount,
|
|
2110
|
+
expirationDate: getUnixTimestamp2(new Date(data.expirationDate)),
|
|
2111
|
+
nonce: data.nonce,
|
|
2112
|
+
metadata: "0x"
|
|
2113
|
+
} : {
|
|
2114
|
+
tokenAddress: data.tokenAddress,
|
|
2115
|
+
recipient: data.recipient,
|
|
2116
|
+
amount: data.amount,
|
|
2117
|
+
expirationDate: getUnixTimestamp2(new Date(data.expirationDate)),
|
|
2118
|
+
nonce: data.nonce,
|
|
2119
|
+
metadata: "0x"
|
|
2120
|
+
};
|
|
2121
|
+
const proof = Array.isArray(data.proof) ? data.proof[0] : data.proof;
|
|
2122
|
+
const typesFetchResult = await fetch(proof.eip712.types);
|
|
2123
|
+
const types = await typesFetchResult.json();
|
|
2124
|
+
delete types.EIP712Domain;
|
|
2125
|
+
const recovered = ethers.verifyTypedData(
|
|
2126
|
+
proof.eip712.domain,
|
|
2127
|
+
types,
|
|
2128
|
+
paymentData,
|
|
2129
|
+
proof.proofValue
|
|
2130
|
+
);
|
|
2131
|
+
const { didDocument } = await resolver.resolve(proof.verificationMethod);
|
|
2132
|
+
if (didDocument?.verificationMethod) {
|
|
2133
|
+
for (const verificationMethod of didDocument.verificationMethod) {
|
|
2134
|
+
if (verificationMethod.blockchainAccountId?.split(":").slice(-1)[0].toLowerCase() === recovered.toLowerCase()) {
|
|
2135
|
+
return recovered;
|
|
2136
|
+
}
|
|
2137
|
+
}
|
|
2138
|
+
} else {
|
|
2139
|
+
throw new Error("failed request. issuer DIDDocument does not contain any verificationMethods");
|
|
2140
|
+
}
|
|
2141
|
+
throw new Error(`failed request. no matching verificationMethod`);
|
|
2142
|
+
}
|
|
2143
|
+
|
|
2144
|
+
// src/kms/key-providers/bjj-provider.ts
|
|
2145
|
+
var BjjProvider = class {
|
|
2146
|
+
/**
|
|
2147
|
+
* key type that is handled by BJJ Provider
|
|
2148
|
+
* @type {KmsKeyType}
|
|
2149
|
+
*/
|
|
2150
|
+
keyType;
|
|
2151
|
+
keyStore;
|
|
2152
|
+
/**
|
|
2153
|
+
* Creates an instance of BjjProvider.
|
|
2154
|
+
* @param {KmsKeyType} keyType - kms key type
|
|
2155
|
+
* @param {AbstractPrivateKeyStore} keyStore - key store for kms
|
|
2156
|
+
*/
|
|
2157
|
+
constructor(keyType, keyStore) {
|
|
2158
|
+
if (keyType !== "BJJ" /* BabyJubJub */) {
|
|
2159
|
+
throw new Error("Key type must be BabyJubJub");
|
|
2160
|
+
}
|
|
2161
|
+
this.keyType = keyType;
|
|
2162
|
+
this.keyStore = keyStore;
|
|
2163
|
+
}
|
|
2164
|
+
/**
|
|
2165
|
+
* get all keys
|
|
2166
|
+
* @returns list of keys
|
|
2167
|
+
*/
|
|
2168
|
+
async list() {
|
|
2169
|
+
const allKeysFromKeyStore = await this.keyStore.list();
|
|
2170
|
+
return allKeysFromKeyStore.filter((key) => key.alias.startsWith(this.keyType));
|
|
2171
|
+
}
|
|
2172
|
+
/**
|
|
2173
|
+
* generates a baby jub jub key from a seed phrase
|
|
2174
|
+
* @param {Uint8Array} seed - byte array seed
|
|
2175
|
+
* @returns kms key identifier
|
|
2176
|
+
*/
|
|
2177
|
+
async newPrivateKeyFromSeed(seed) {
|
|
2178
|
+
const newKey = new Uint8Array(32);
|
|
2179
|
+
newKey.set(Uint8Array.from(seed), 0);
|
|
2180
|
+
newKey.fill(seed.length, 32, 0);
|
|
2181
|
+
const privateKey = new PrivateKey(seed);
|
|
2182
|
+
const publicKey = privateKey.public();
|
|
2183
|
+
const kmsId = {
|
|
2184
|
+
type: this.keyType,
|
|
2185
|
+
id: keyPath(this.keyType, publicKey.hex())
|
|
2186
|
+
};
|
|
2187
|
+
await this.keyStore.importKey({ alias: kmsId.id, key: privateKey.hex() });
|
|
2188
|
+
return kmsId;
|
|
2189
|
+
}
|
|
2190
|
+
/**
|
|
2191
|
+
* Gets public key by kmsKeyId
|
|
2192
|
+
*
|
|
2193
|
+
* @param {KmsKeyId} keyId - key identifier
|
|
2194
|
+
*/
|
|
2195
|
+
async publicKey(keyId) {
|
|
2196
|
+
const privateKey = await this.privateKey(keyId);
|
|
2197
|
+
return privateKey.public().hex();
|
|
2198
|
+
}
|
|
2199
|
+
/**
|
|
2200
|
+
* signs prepared payload of size,
|
|
2201
|
+
* with a key id
|
|
2202
|
+
*
|
|
2203
|
+
* @param {KmsKeyId} keyId - key identifier
|
|
2204
|
+
* @param {Uint8Array} data - data to sign (32 bytes)
|
|
2205
|
+
* @returns Uint8Array signature
|
|
2206
|
+
*/
|
|
2207
|
+
async sign(keyId, data) {
|
|
2208
|
+
if (data.length != 32) {
|
|
2209
|
+
throw new Error("data to sign is too large");
|
|
2210
|
+
}
|
|
2211
|
+
const i = BytesHelper2.bytesToInt(data);
|
|
2212
|
+
if (!checkBigIntInField(i)) {
|
|
2213
|
+
throw new Error("data to sign is too large");
|
|
2214
|
+
}
|
|
2215
|
+
const privateKey = await this.privateKey(keyId);
|
|
2216
|
+
const signature = privateKey.signPoseidon(i);
|
|
2217
|
+
return signature.compress();
|
|
2218
|
+
}
|
|
2219
|
+
async privateKey(keyId) {
|
|
2220
|
+
const privateKeyHex = await this.keyStore.get({ alias: keyId.id });
|
|
2221
|
+
return new PrivateKey(Hex4.decodeString(privateKeyHex));
|
|
2222
|
+
}
|
|
2223
|
+
async verify(message, signatureHex, keyId) {
|
|
2224
|
+
const publicKey = await this.publicKey(keyId);
|
|
2225
|
+
return PublicKey4.newFromCompressed(hexToBytes(publicKey)).verifyPoseidon(
|
|
2226
|
+
BytesHelper2.bytesToInt(message),
|
|
2227
|
+
Signature2.newFromCompressed(hexToBytes(signatureHex))
|
|
2228
|
+
);
|
|
2229
|
+
}
|
|
2230
|
+
};
|
|
2231
|
+
|
|
2232
|
+
// src/kms/key-providers/ed25519-provider.ts
|
|
2233
|
+
import { ed25519 as ed255192 } from "@noble/curves/ed25519";
|
|
2234
|
+
var Ed25519Provider = class {
|
|
2235
|
+
/**
|
|
2236
|
+
* Creates an instance of Ed25519Provider.
|
|
2237
|
+
* @param {KmsKeyType} keyType - kms key type
|
|
2238
|
+
* @param {AbstractPrivateKeyStore} keyStore - key store for kms
|
|
2239
|
+
*/
|
|
2240
|
+
constructor(keyType, _keyStore) {
|
|
2241
|
+
this.keyType = keyType;
|
|
2242
|
+
this._keyStore = _keyStore;
|
|
2243
|
+
}
|
|
2244
|
+
/**
|
|
2245
|
+
* get all keys
|
|
2246
|
+
* @returns list of keys
|
|
2247
|
+
*/
|
|
2248
|
+
async list() {
|
|
2249
|
+
const allKeysFromKeyStore = await this._keyStore.list();
|
|
2250
|
+
return allKeysFromKeyStore.filter((key) => key.alias.startsWith(this.keyType));
|
|
2251
|
+
}
|
|
2252
|
+
/**
|
|
2253
|
+
* generates a ed25519 key from a seed phrase
|
|
2254
|
+
* @param {Uint8Array} seed - byte array seed
|
|
2255
|
+
* @returns {Promise<KmsKeyId>} kms key identifier
|
|
2256
|
+
*/
|
|
2257
|
+
async newPrivateKeyFromSeed(seed) {
|
|
2258
|
+
if (seed.length !== 32) {
|
|
2259
|
+
throw new Error("Seed should be 32 bytes");
|
|
2260
|
+
}
|
|
2261
|
+
const publicKey = ed255192.getPublicKey(seed);
|
|
2262
|
+
const kmsId = {
|
|
2263
|
+
type: this.keyType,
|
|
2264
|
+
id: keyPath(this.keyType, bytesToHex(publicKey))
|
|
2265
|
+
};
|
|
2266
|
+
await this._keyStore.importKey({
|
|
2267
|
+
alias: kmsId.id,
|
|
2268
|
+
key: bytesToHex(seed)
|
|
2269
|
+
});
|
|
2270
|
+
return kmsId;
|
|
2271
|
+
}
|
|
2272
|
+
/**
|
|
2273
|
+
* Gets public key by kmsKeyId
|
|
2274
|
+
* @param {KmsKeyId} keyId - key identifier
|
|
2275
|
+
* @returns {Promise<string>} Public key as a hex string
|
|
2276
|
+
*/
|
|
2277
|
+
async publicKey(keyId) {
|
|
2278
|
+
const privateKeyHex = await this.privateKey(keyId);
|
|
2279
|
+
const publicKey = ed255192.getPublicKey(privateKeyHex);
|
|
2280
|
+
return bytesToHex(publicKey);
|
|
2281
|
+
}
|
|
2282
|
+
/**
|
|
2283
|
+
* signs prepared payload of size,
|
|
2284
|
+
* with a key id
|
|
2285
|
+
* @param {KmsKeyId} keyId - key identifier
|
|
2286
|
+
* @param {Uint8Array} digest - data to sign (32 bytes)
|
|
2287
|
+
* @returns {Promise<Uint8Array>} signature
|
|
2288
|
+
*/
|
|
2289
|
+
async sign(keyId, digest) {
|
|
2290
|
+
const privateKeyHex = await this.privateKey(keyId);
|
|
2291
|
+
return ed255192.sign(digest, privateKeyHex);
|
|
2292
|
+
}
|
|
2293
|
+
/**
|
|
2294
|
+
* Verifies a signature for the given message and key identifier.
|
|
2295
|
+
* @param digest - The message to verify the signature against.
|
|
2296
|
+
* @param signatureHex - The signature to verify, as a hexadecimal string.
|
|
2297
|
+
* @param keyId - The key identifier to use for verification.
|
|
2298
|
+
* @returns A Promise that resolves to a boolean indicating whether the signature is valid.
|
|
2299
|
+
*/
|
|
2300
|
+
async verify(digest, signatureHex, keyId) {
|
|
2301
|
+
const publicKeyHex = await this.publicKey(keyId);
|
|
2302
|
+
return ed255192.verify(signatureHex, digest, publicKeyHex);
|
|
2303
|
+
}
|
|
2304
|
+
/**
|
|
2305
|
+
* Retrieves the private key for a given keyId from the key store.
|
|
2306
|
+
* @param {KmsKeyId} keyId - The identifier of the key to retrieve.
|
|
2307
|
+
* @returns {Promise<string>} The private key associated with the keyId.
|
|
2308
|
+
*/
|
|
2309
|
+
async privateKey(keyId) {
|
|
2310
|
+
return this._keyStore.get({ alias: keyId.id });
|
|
2311
|
+
}
|
|
2312
|
+
};
|
|
2313
|
+
|
|
2314
|
+
// src/kms/key-providers/secp256k1-provider.ts
|
|
2315
|
+
import { secp256k1 } from "@noble/curves/secp256k1";
|
|
2316
|
+
import { sha256 } from "@iden3/js-crypto";
|
|
2317
|
+
import { ES256KSigner, hexToBytes as hexToBytes2 } from "did-jwt";
|
|
2318
|
+
var Sec256k1Provider = class {
|
|
2319
|
+
/**
|
|
2320
|
+
* key type that is handled by BJJ Provider
|
|
2321
|
+
* @type {KmsKeyType}
|
|
2322
|
+
*/
|
|
2323
|
+
keyType;
|
|
2324
|
+
_keyStore;
|
|
2325
|
+
/**
|
|
2326
|
+
* Creates an instance of BjjProvider.
|
|
2327
|
+
* @param {KmsKeyType} keyType - kms key type
|
|
2328
|
+
* @param {AbstractPrivateKeyStore} keyStore - key store for kms
|
|
2329
|
+
*/
|
|
2330
|
+
constructor(keyType, keyStore) {
|
|
2331
|
+
if (keyType !== "Secp256k1" /* Secp256k1 */) {
|
|
2332
|
+
throw new Error("Key type must be Secp256k1");
|
|
2333
|
+
}
|
|
2334
|
+
this.keyType = keyType;
|
|
2335
|
+
this._keyStore = keyStore;
|
|
2336
|
+
}
|
|
2337
|
+
/**
|
|
2338
|
+
* get all keys
|
|
2339
|
+
* @returns list of keys
|
|
2340
|
+
*/
|
|
2341
|
+
async list() {
|
|
2342
|
+
const allKeysFromKeyStore = await this._keyStore.list();
|
|
2343
|
+
return allKeysFromKeyStore.filter((key) => key.alias.startsWith(this.keyType));
|
|
2344
|
+
}
|
|
2345
|
+
/**
|
|
2346
|
+
* generates a baby jub jub key from a seed phrase
|
|
2347
|
+
* @param {Uint8Array} seed - byte array seed
|
|
2348
|
+
* @returns kms key identifier
|
|
2349
|
+
*/
|
|
2350
|
+
async newPrivateKeyFromSeed(seed) {
|
|
2351
|
+
if (seed.length !== 32) {
|
|
2352
|
+
throw new Error("Seed should be 32 bytes");
|
|
2353
|
+
}
|
|
2354
|
+
const publicKey = secp256k1.getPublicKey(seed);
|
|
2355
|
+
const kmsId = {
|
|
2356
|
+
type: this.keyType,
|
|
2357
|
+
id: keyPath(this.keyType, bytesToHex(publicKey))
|
|
2358
|
+
};
|
|
2359
|
+
await this._keyStore.importKey({
|
|
2360
|
+
alias: kmsId.id,
|
|
2361
|
+
key: bytesToHex(seed).padStart(64, "0")
|
|
2362
|
+
});
|
|
2363
|
+
return kmsId;
|
|
2364
|
+
}
|
|
2365
|
+
/**
|
|
2366
|
+
* Gets public key by kmsKeyId
|
|
2367
|
+
*
|
|
2368
|
+
* @param {KmsKeyId} keyId - key identifier
|
|
2369
|
+
*/
|
|
2370
|
+
async publicKey(keyId) {
|
|
2371
|
+
const privateKeyHex = await this.privateKey(keyId);
|
|
2372
|
+
const publicKey = secp256k1.getPublicKey(privateKeyHex, false);
|
|
2373
|
+
return bytesToHex(publicKey);
|
|
2374
|
+
}
|
|
2375
|
+
/**
|
|
2376
|
+
* Signs the given data using the private key associated with the specified key identifier.
|
|
2377
|
+
* @param keyId - The key identifier to use for signing.
|
|
2378
|
+
* @param data - The data to sign.
|
|
2379
|
+
* @param opts - Signing options, such as the algorithm to use.
|
|
2380
|
+
* @returns A Promise that resolves to the signature as a Uint8Array.
|
|
2381
|
+
*/
|
|
2382
|
+
async sign(keyId, data, opts = { alg: "ES256K" }) {
|
|
2383
|
+
const privateKeyHex = await this.privateKey(keyId);
|
|
2384
|
+
const signatureBase64 = await ES256KSigner(
|
|
2385
|
+
hexToBytes2(privateKeyHex),
|
|
2386
|
+
opts.alg === "ES256K-R"
|
|
2387
|
+
)(data);
|
|
2388
|
+
if (typeof signatureBase64 !== "string") {
|
|
2389
|
+
throw new Error("signatureBase64 must be a string");
|
|
2390
|
+
}
|
|
2391
|
+
return base64UrlToBytes(signatureBase64);
|
|
2392
|
+
}
|
|
2393
|
+
/**
|
|
2394
|
+
* Verifies a signature for the given message and key identifier.
|
|
2395
|
+
* @param message - The message to verify the signature against.
|
|
2396
|
+
* @param signatureHex - The signature to verify, as a hexadecimal string.
|
|
2397
|
+
* @param keyId - The key identifier to use for verification.
|
|
2398
|
+
* @returns A Promise that resolves to a boolean indicating whether the signature is valid.
|
|
2399
|
+
*/
|
|
2400
|
+
async verify(message, signatureHex, keyId) {
|
|
2401
|
+
const publicKeyHex = await this.publicKey(keyId);
|
|
2402
|
+
return secp256k1.verify(signatureHex, sha256(message), publicKeyHex);
|
|
2403
|
+
}
|
|
2404
|
+
async privateKey(keyId) {
|
|
2405
|
+
return this._keyStore.get({ alias: keyId.id });
|
|
2406
|
+
}
|
|
2407
|
+
};
|
|
2408
|
+
|
|
2409
|
+
// src/identity/identity-wallet.ts
|
|
2410
|
+
import {
|
|
2411
|
+
Blockchain,
|
|
2412
|
+
buildDIDType as buildDIDType3,
|
|
2413
|
+
BytesHelper as BytesHelper9,
|
|
2414
|
+
Claim as Claim9,
|
|
2415
|
+
ClaimOptions as ClaimOptions2,
|
|
2416
|
+
DID as DID27,
|
|
2417
|
+
DidMethod,
|
|
2418
|
+
getUnixTimestamp as getUnixTimestamp10,
|
|
2419
|
+
Id as Id19,
|
|
2420
|
+
NetworkId,
|
|
2421
|
+
SchemaHash as SchemaHash7
|
|
2422
|
+
} from "@iden3/js-iden3-core";
|
|
2423
|
+
import {
|
|
2424
|
+
poseidon as poseidon4,
|
|
2425
|
+
PublicKey as PublicKey5,
|
|
2426
|
+
sha256 as sha2562,
|
|
2427
|
+
Signature as Signature3,
|
|
2428
|
+
Hex as Hex6,
|
|
2429
|
+
getRandomBytes as getRandomBytes2,
|
|
2430
|
+
Poseidon
|
|
2431
|
+
} from "@iden3/js-crypto";
|
|
2432
|
+
import { hashElems as hashElems2, ZERO_HASH as ZERO_HASH6 } from "@iden3/js-merkletree";
|
|
2045
2433
|
|
|
2046
2434
|
// src/identity/common.ts
|
|
2435
|
+
import { DID as DID5, Id as Id2, IdPosition as IdPosition2, MerklizedRootPosition as MerklizedRootPosition2 } from "@iden3/js-iden3-core";
|
|
2047
2436
|
var subjectPositionIndex = (idPosition) => {
|
|
2048
2437
|
switch (idPosition) {
|
|
2049
2438
|
case IdPosition2.Index:
|
|
@@ -2774,6 +3163,8 @@ var Query = class {
|
|
|
2774
3163
|
};
|
|
2775
3164
|
var CircuitId = /* @__PURE__ */ ((CircuitId2) => {
|
|
2776
3165
|
CircuitId2["AuthV2"] = "authV2";
|
|
3166
|
+
CircuitId2["AuthV3"] = "authV3";
|
|
3167
|
+
CircuitId2["AuthV3_8_32"] = "authV3-8-32";
|
|
2777
3168
|
CircuitId2["StateTransition"] = "stateTransition";
|
|
2778
3169
|
CircuitId2["AtomicQueryMTPV2"] = "credentialAtomicQueryMTPV2";
|
|
2779
3170
|
CircuitId2["AtomicQueryMTPV2OnChain"] = "credentialAtomicQueryMTPV2OnChain";
|
|
@@ -4486,6 +4877,12 @@ var LinkedMultiQueryPubSignals = class {
|
|
|
4486
4877
|
}
|
|
4487
4878
|
};
|
|
4488
4879
|
|
|
4880
|
+
// src/circuits/auth-v3.ts
|
|
4881
|
+
var AuthV3Inputs = class extends AuthV2Inputs {
|
|
4882
|
+
};
|
|
4883
|
+
var AuthV3PubSignals = class extends AuthV2PubSignals {
|
|
4884
|
+
};
|
|
4885
|
+
|
|
4489
4886
|
// src/storage/blockchain/abi/State.json
|
|
4490
4887
|
var State_default = [{ inputs: [], stateMutability: "nonpayable", type: "constructor" }, { anonymous: false, inputs: [{ indexed: false, internalType: "uint8", name: "version", type: "uint8" }], name: "Initialized", type: "event" }, { anonymous: false, inputs: [{ indexed: true, internalType: "address", name: "previousOwner", type: "address" }, { indexed: true, internalType: "address", name: "newOwner", type: "address" }], name: "OwnershipTransferStarted", type: "event" }, { anonymous: false, inputs: [{ indexed: true, internalType: "address", name: "previousOwner", type: "address" }, { indexed: true, internalType: "address", name: "newOwner", type: "address" }], name: "OwnershipTransferred", type: "event" }, { inputs: [], name: "VERSION", outputs: [{ internalType: "string", name: "", type: "string" }], stateMutability: "view", type: "function" }, { inputs: [], name: "acceptOwnership", outputs: [], stateMutability: "nonpayable", type: "function" }, { inputs: [], name: "getDefaultIdType", outputs: [{ internalType: "bytes2", name: "", type: "bytes2" }], stateMutability: "view", type: "function" }, { inputs: [{ internalType: "uint256", name: "id", type: "uint256" }], name: "getGISTProof", outputs: [{ components: [{ internalType: "uint256", name: "root", type: "uint256" }, { internalType: "bool", name: "existence", type: "bool" }, { internalType: "uint256[64]", name: "siblings", type: "uint256[64]" }, { internalType: "uint256", name: "index", type: "uint256" }, { internalType: "uint256", name: "value", type: "uint256" }, { internalType: "bool", name: "auxExistence", type: "bool" }, { internalType: "uint256", name: "auxIndex", type: "uint256" }, { internalType: "uint256", name: "auxValue", type: "uint256" }], internalType: "structIState.GistProof", name: "", type: "tuple" }], stateMutability: "view", type: "function" }, { inputs: [{ internalType: "uint256", name: "id", type: "uint256" }, { internalType: "uint256", name: "blockNumber", type: "uint256" }], name: "getGISTProofByBlock", outputs: [{ components: [{ internalType: "uint256", name: "root", type: "uint256" }, { internalType: "bool", name: "existence", type: "bool" }, { internalType: "uint256[64]", name: "siblings", type: "uint256[64]" }, { internalType: "uint256", name: "index", type: "uint256" }, { internalType: "uint256", name: "value", type: "uint256" }, { internalType: "bool", name: "auxExistence", type: "bool" }, { internalType: "uint256", name: "auxIndex", type: "uint256" }, { internalType: "uint256", name: "auxValue", type: "uint256" }], internalType: "structIState.GistProof", name: "", type: "tuple" }], stateMutability: "view", type: "function" }, { inputs: [{ internalType: "uint256", name: "id", type: "uint256" }, { internalType: "uint256", name: "root", type: "uint256" }], name: "getGISTProofByRoot", outputs: [{ components: [{ internalType: "uint256", name: "root", type: "uint256" }, { internalType: "bool", name: "existence", type: "bool" }, { internalType: "uint256[64]", name: "siblings", type: "uint256[64]" }, { internalType: "uint256", name: "index", type: "uint256" }, { internalType: "uint256", name: "value", type: "uint256" }, { internalType: "bool", name: "auxExistence", type: "bool" }, { internalType: "uint256", name: "auxIndex", type: "uint256" }, { internalType: "uint256", name: "auxValue", type: "uint256" }], internalType: "structIState.GistProof", name: "", type: "tuple" }], stateMutability: "view", type: "function" }, { inputs: [{ internalType: "uint256", name: "id", type: "uint256" }, { internalType: "uint256", name: "timestamp", type: "uint256" }], name: "getGISTProofByTime", outputs: [{ components: [{ internalType: "uint256", name: "root", type: "uint256" }, { internalType: "bool", name: "existence", type: "bool" }, { internalType: "uint256[64]", name: "siblings", type: "uint256[64]" }, { internalType: "uint256", name: "index", type: "uint256" }, { internalType: "uint256", name: "value", type: "uint256" }, { internalType: "bool", name: "auxExistence", type: "bool" }, { internalType: "uint256", name: "auxIndex", type: "uint256" }, { internalType: "uint256", name: "auxValue", type: "uint256" }], internalType: "structIState.GistProof", name: "", type: "tuple" }], stateMutability: "view", type: "function" }, { inputs: [], name: "getGISTRoot", outputs: [{ internalType: "uint256", name: "", type: "uint256" }], stateMutability: "view", type: "function" }, { inputs: [{ internalType: "uint256", name: "start", type: "uint256" }, { internalType: "uint256", name: "length", type: "uint256" }], name: "getGISTRootHistory", outputs: [{ components: [{ internalType: "uint256", name: "root", type: "uint256" }, { internalType: "uint256", name: "replacedByRoot", type: "uint256" }, { internalType: "uint256", name: "createdAtTimestamp", type: "uint256" }, { internalType: "uint256", name: "replacedAtTimestamp", type: "uint256" }, { internalType: "uint256", name: "createdAtBlock", type: "uint256" }, { internalType: "uint256", name: "replacedAtBlock", type: "uint256" }], internalType: "structIState.GistRootInfo[]", name: "", type: "tuple[]" }], stateMutability: "view", type: "function" }, { inputs: [], name: "getGISTRootHistoryLength", outputs: [{ internalType: "uint256", name: "", type: "uint256" }], stateMutability: "view", type: "function" }, { inputs: [{ internalType: "uint256", name: "root", type: "uint256" }], name: "getGISTRootInfo", outputs: [{ components: [{ internalType: "uint256", name: "root", type: "uint256" }, { internalType: "uint256", name: "replacedByRoot", type: "uint256" }, { internalType: "uint256", name: "createdAtTimestamp", type: "uint256" }, { internalType: "uint256", name: "replacedAtTimestamp", type: "uint256" }, { internalType: "uint256", name: "createdAtBlock", type: "uint256" }, { internalType: "uint256", name: "replacedAtBlock", type: "uint256" }], internalType: "structIState.GistRootInfo", name: "", type: "tuple" }], stateMutability: "view", type: "function" }, { inputs: [{ internalType: "uint256", name: "blockNumber", type: "uint256" }], name: "getGISTRootInfoByBlock", outputs: [{ components: [{ internalType: "uint256", name: "root", type: "uint256" }, { internalType: "uint256", name: "replacedByRoot", type: "uint256" }, { internalType: "uint256", name: "createdAtTimestamp", type: "uint256" }, { internalType: "uint256", name: "replacedAtTimestamp", type: "uint256" }, { internalType: "uint256", name: "createdAtBlock", type: "uint256" }, { internalType: "uint256", name: "replacedAtBlock", type: "uint256" }], internalType: "structIState.GistRootInfo", name: "", type: "tuple" }], stateMutability: "view", type: "function" }, { inputs: [{ internalType: "uint256", name: "timestamp", type: "uint256" }], name: "getGISTRootInfoByTime", outputs: [{ components: [{ internalType: "uint256", name: "root", type: "uint256" }, { internalType: "uint256", name: "replacedByRoot", type: "uint256" }, { internalType: "uint256", name: "createdAtTimestamp", type: "uint256" }, { internalType: "uint256", name: "replacedAtTimestamp", type: "uint256" }, { internalType: "uint256", name: "createdAtBlock", type: "uint256" }, { internalType: "uint256", name: "replacedAtBlock", type: "uint256" }], internalType: "structIState.GistRootInfo", name: "", type: "tuple" }], stateMutability: "view", type: "function" }, { inputs: [{ internalType: "uint256", name: "id", type: "uint256" }], name: "getStateInfoById", outputs: [{ components: [{ internalType: "uint256", name: "id", type: "uint256" }, { internalType: "uint256", name: "state", type: "uint256" }, { internalType: "uint256", name: "replacedByState", type: "uint256" }, { internalType: "uint256", name: "createdAtTimestamp", type: "uint256" }, { internalType: "uint256", name: "replacedAtTimestamp", type: "uint256" }, { internalType: "uint256", name: "createdAtBlock", type: "uint256" }, { internalType: "uint256", name: "replacedAtBlock", type: "uint256" }], internalType: "structIState.StateInfo", name: "", type: "tuple" }], stateMutability: "view", type: "function" }, { inputs: [{ internalType: "uint256", name: "id", type: "uint256" }, { internalType: "uint256", name: "state", type: "uint256" }], name: "getStateInfoByIdAndState", outputs: [{ components: [{ internalType: "uint256", name: "id", type: "uint256" }, { internalType: "uint256", name: "state", type: "uint256" }, { internalType: "uint256", name: "replacedByState", type: "uint256" }, { internalType: "uint256", name: "createdAtTimestamp", type: "uint256" }, { internalType: "uint256", name: "replacedAtTimestamp", type: "uint256" }, { internalType: "uint256", name: "createdAtBlock", type: "uint256" }, { internalType: "uint256", name: "replacedAtBlock", type: "uint256" }], internalType: "structIState.StateInfo", name: "", type: "tuple" }], stateMutability: "view", type: "function" }, { inputs: [{ internalType: "uint256", name: "id", type: "uint256" }, { internalType: "uint256", name: "startIndex", type: "uint256" }, { internalType: "uint256", name: "length", type: "uint256" }], name: "getStateInfoHistoryById", outputs: [{ components: [{ internalType: "uint256", name: "id", type: "uint256" }, { internalType: "uint256", name: "state", type: "uint256" }, { internalType: "uint256", name: "replacedByState", type: "uint256" }, { internalType: "uint256", name: "createdAtTimestamp", type: "uint256" }, { internalType: "uint256", name: "replacedAtTimestamp", type: "uint256" }, { internalType: "uint256", name: "createdAtBlock", type: "uint256" }, { internalType: "uint256", name: "replacedAtBlock", type: "uint256" }], internalType: "structIState.StateInfo[]", name: "", type: "tuple[]" }], stateMutability: "view", type: "function" }, { inputs: [{ internalType: "uint256", name: "id", type: "uint256" }], name: "getStateInfoHistoryLengthById", outputs: [{ internalType: "uint256", name: "", type: "uint256" }], stateMutability: "view", type: "function" }, { inputs: [], name: "getVerifier", outputs: [{ internalType: "address", name: "", type: "address" }], stateMutability: "view", type: "function" }, { inputs: [{ internalType: "uint256", name: "id", type: "uint256" }], name: "idExists", outputs: [{ internalType: "bool", name: "", type: "bool" }], stateMutability: "view", type: "function" }, { inputs: [{ internalType: "contractIStateTransitionVerifier", name: "verifierContractAddr", type: "address" }, { internalType: "bytes2", name: "defaultIdType", type: "bytes2" }], name: "initialize", outputs: [], stateMutability: "nonpayable", type: "function" }, { inputs: [], name: "owner", outputs: [{ internalType: "address", name: "", type: "address" }], stateMutability: "view", type: "function" }, { inputs: [], name: "pendingOwner", outputs: [{ internalType: "address", name: "", type: "address" }], stateMutability: "view", type: "function" }, { inputs: [], name: "renounceOwnership", outputs: [], stateMutability: "nonpayable", type: "function" }, { inputs: [{ internalType: "bytes2", name: "defaultIdType", type: "bytes2" }], name: "setDefaultIdType", outputs: [], stateMutability: "nonpayable", type: "function" }, { inputs: [{ internalType: "address", name: "newVerifierAddr", type: "address" }], name: "setVerifier", outputs: [], stateMutability: "nonpayable", type: "function" }, { inputs: [{ internalType: "uint256", name: "id", type: "uint256" }, { internalType: "uint256", name: "state", type: "uint256" }], name: "stateExists", outputs: [{ internalType: "bool", name: "", type: "bool" }], stateMutability: "view", type: "function" }, { inputs: [{ internalType: "address", name: "newOwner", type: "address" }], name: "transferOwnership", outputs: [], stateMutability: "nonpayable", type: "function" }, { inputs: [{ internalType: "uint256", name: "id", type: "uint256" }, { internalType: "uint256", name: "oldState", type: "uint256" }, { internalType: "uint256", name: "newState", type: "uint256" }, { internalType: "bool", name: "isOldStateGenesis", type: "bool" }, { internalType: "uint256[2]", name: "a", type: "uint256[2]" }, { internalType: "uint256[2][2]", name: "b", type: "uint256[2][2]" }, { internalType: "uint256[2]", name: "c", type: "uint256[2]" }], name: "transitState", outputs: [], stateMutability: "nonpayable", type: "function" }, { inputs: [{ internalType: "uint256", name: "id", type: "uint256" }, { internalType: "uint256", name: "oldState", type: "uint256" }, { internalType: "uint256", name: "newState", type: "uint256" }, { internalType: "bool", name: "isOldStateGenesis", type: "bool" }, { internalType: "uint256", name: "methodId", type: "uint256" }, { internalType: "bytes", name: "methodParams", type: "bytes" }], name: "transitStateGeneric", outputs: [], stateMutability: "nonpayable", type: "function" }];
|
|
4491
4888
|
|
|
@@ -4539,9 +4936,9 @@ var TransactionService = class {
|
|
|
4539
4936
|
};
|
|
4540
4937
|
|
|
4541
4938
|
// src/storage/blockchain/common.ts
|
|
4542
|
-
import { ethers } from "ethers";
|
|
4939
|
+
import { ethers as ethers2 } from "ethers";
|
|
4543
4940
|
var packZkpProof = (inputs, a, b, c) => {
|
|
4544
|
-
return new
|
|
4941
|
+
return new ethers2.AbiCoder().encode(
|
|
4545
4942
|
["uint256[] inputs", "uint256[2]", "uint256[2][2]", "uint256[2]"],
|
|
4546
4943
|
[inputs, a, b, c]
|
|
4547
4944
|
);
|
|
@@ -4992,6 +5389,7 @@ var ProtocolVersion = /* @__PURE__ */ ((ProtocolVersion2) => {
|
|
|
4992
5389
|
var AcceptAuthCircuits = /* @__PURE__ */ ((AcceptAuthCircuits2) => {
|
|
4993
5390
|
AcceptAuthCircuits2["AuthV2"] = "authV2";
|
|
4994
5391
|
AcceptAuthCircuits2["AuthV3"] = "authV3";
|
|
5392
|
+
AcceptAuthCircuits2["AuthV3_8_32"] = "authV3-8-32";
|
|
4995
5393
|
return AcceptAuthCircuits2;
|
|
4996
5394
|
})(AcceptAuthCircuits || {});
|
|
4997
5395
|
var AcceptJwzAlgorithms = /* @__PURE__ */ ((AcceptJwzAlgorithms2) => {
|
|
@@ -5081,6 +5479,20 @@ function isAcceptJwsAlgorithms(value) {
|
|
|
5081
5479
|
function isAcceptJwzAlgorithms(value) {
|
|
5082
5480
|
return Object.values(AcceptJwzAlgorithms).includes(value);
|
|
5083
5481
|
}
|
|
5482
|
+
var buildAcceptFromProvingMethodAlg = (provingMethodAlg) => {
|
|
5483
|
+
const [alg, circuitId] = provingMethodAlg.toString().split(":");
|
|
5484
|
+
return `${"iden3comm/v1" /* V1 */};env=${"application/iden3-zkp-json" /* ZKPMessage */};circuitId=${circuitId};alg=${alg}`;
|
|
5485
|
+
};
|
|
5486
|
+
var acceptHasProvingMethodAlg = (accept, provingMethodAlg) => {
|
|
5487
|
+
const [provingAlg, provingCircuitId] = provingMethodAlg.toString().split(":");
|
|
5488
|
+
for (const profile of accept) {
|
|
5489
|
+
const { env, circuits, alg } = parseAcceptProfile(profile);
|
|
5490
|
+
if (env === "application/iden3-zkp-json" /* ZKPMessage */ && circuits?.includes(provingCircuitId) && (!alg || alg?.includes(provingAlg))) {
|
|
5491
|
+
return true;
|
|
5492
|
+
}
|
|
5493
|
+
}
|
|
5494
|
+
return false;
|
|
5495
|
+
};
|
|
5084
5496
|
var buildAccept = (profiles) => {
|
|
5085
5497
|
const result = [];
|
|
5086
5498
|
for (const profile of profiles) {
|
|
@@ -5209,10 +5621,17 @@ var ZKPPacker = class {
|
|
|
5209
5621
|
this.provingParamsMap = provingParamsMap;
|
|
5210
5622
|
this.verificationParamsMap = verificationParamsMap;
|
|
5211
5623
|
this._opts = _opts;
|
|
5624
|
+
const supportedProvers = Array.from(this.provingParamsMap.keys()).map(
|
|
5625
|
+
(alg) => alg.split(":")[1]
|
|
5626
|
+
);
|
|
5627
|
+
const supportedVerifiers = Array.from(this.verificationParamsMap.keys()).map(
|
|
5628
|
+
(alg) => alg.split(":")[1]
|
|
5629
|
+
);
|
|
5630
|
+
this.supportedCircuitIds = [.../* @__PURE__ */ new Set([...supportedProvers, ...supportedVerifiers])];
|
|
5212
5631
|
}
|
|
5213
5632
|
supportedProtocolVersions = ["iden3comm/v1" /* V1 */];
|
|
5214
5633
|
supportedAlgorithms = ["groth16" /* Groth16 */];
|
|
5215
|
-
supportedCircuitIds
|
|
5634
|
+
supportedCircuitIds;
|
|
5216
5635
|
/**
|
|
5217
5636
|
* Packs a basic message using the specified parameters.
|
|
5218
5637
|
* @param msg - The basic message to pack.
|
|
@@ -5305,13 +5724,13 @@ var ZKPPacker = class {
|
|
|
5305
5724
|
var verifySender = async (token, msg) => {
|
|
5306
5725
|
switch (token.circuitId) {
|
|
5307
5726
|
case "authV2" /* AuthV2 */:
|
|
5727
|
+
case "authV3-8-32" /* AuthV3_8_32 */:
|
|
5728
|
+
case "authV3" /* AuthV3 */:
|
|
5308
5729
|
{
|
|
5309
5730
|
if (!msg.from) {
|
|
5310
5731
|
throw new Error(ErrSenderNotUsedTokenCreation);
|
|
5311
5732
|
}
|
|
5312
|
-
const authSignals = new AuthV2PubSignals().pubSignalsUnmarshal(
|
|
5313
|
-
byteEncoder.encode(JSON.stringify(token.zkProof.pub_signals))
|
|
5314
|
-
);
|
|
5733
|
+
const authSignals = (token.circuitId === "authV2" /* AuthV2 */ ? new AuthV2PubSignals() : new AuthV3PubSignals()).pubSignalsUnmarshal(byteEncoder.encode(JSON.stringify(token.zkProof.pub_signals)));
|
|
5315
5734
|
const did = DID6.parseFromId(authSignals.userID);
|
|
5316
5735
|
const msgHash = await token.getMessageHash();
|
|
5317
5736
|
const challenge = BytesHelper4.bytesToInt(msgHash.reverse());
|
|
@@ -5591,14 +6010,14 @@ var DiscoveryProtocolFeatureType = /* @__PURE__ */ ((DiscoveryProtocolFeatureTyp
|
|
|
5591
6010
|
})(DiscoveryProtocolFeatureType || {});
|
|
5592
6011
|
|
|
5593
6012
|
// src/iden3comm/handlers/auth.ts
|
|
5594
|
-
import { DID as DID8, getUnixTimestamp as
|
|
6013
|
+
import { DID as DID8, getUnixTimestamp as getUnixTimestamp4 } from "@iden3/js-iden3-core";
|
|
5595
6014
|
import { proving as proving3 } from "@iden3/js-jwz";
|
|
5596
6015
|
import * as uuid2 from "uuid";
|
|
5597
6016
|
|
|
5598
6017
|
// src/iden3comm/handlers/common.ts
|
|
5599
6018
|
import { getRandomBytes } from "@iden3/js-crypto";
|
|
5600
|
-
import { getUnixTimestamp } from "@iden3/js-iden3-core";
|
|
5601
|
-
import { ethers as
|
|
6019
|
+
import { getUnixTimestamp as getUnixTimestamp3 } from "@iden3/js-iden3-core";
|
|
6020
|
+
import { ethers as ethers3 } from "ethers";
|
|
5602
6021
|
var getGroupedQueries = (requestScope) => requestScope.reduce((acc, proofReq) => {
|
|
5603
6022
|
const groupId = proofReq.query.groupId;
|
|
5604
6023
|
if (!groupId) {
|
|
@@ -5765,8 +6184,8 @@ var calcChallengeAuthV2 = (senderAddress, zkpResponses) => {
|
|
|
5765
6184
|
};
|
|
5766
6185
|
});
|
|
5767
6186
|
return BigInt(
|
|
5768
|
-
|
|
5769
|
-
new
|
|
6187
|
+
ethers3.keccak256(
|
|
6188
|
+
new ethers3.AbiCoder().encode(
|
|
5770
6189
|
["address", "(uint256 requestId,bytes proof,bytes metadata)[]"],
|
|
5771
6190
|
[senderAddress, responses]
|
|
5772
6191
|
)
|
|
@@ -5774,16 +6193,17 @@ var calcChallengeAuthV2 = (senderAddress, zkpResponses) => {
|
|
|
5774
6193
|
) & BigInt("0x0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
|
|
5775
6194
|
};
|
|
5776
6195
|
var packMetadatas = (metas) => {
|
|
5777
|
-
return new
|
|
6196
|
+
return new ethers3.AbiCoder().encode(["tuple(string key,bytes value)[]"], [metas]);
|
|
5778
6197
|
};
|
|
5779
6198
|
var verifyExpiresTime = (message) => {
|
|
5780
|
-
if (message?.expires_time && message.expires_time <
|
|
6199
|
+
if (message?.expires_time && message.expires_time < getUnixTimestamp3(/* @__PURE__ */ new Date())) {
|
|
5781
6200
|
throw new Error("Message expired");
|
|
5782
6201
|
}
|
|
5783
6202
|
};
|
|
5784
6203
|
|
|
5785
6204
|
// src/iden3comm/handlers/message-handler.ts
|
|
5786
|
-
import { proving as proving2 } from "@iden3/js-jwz";
|
|
6205
|
+
import { Token as Token3, proving as proving2 } from "@iden3/js-jwz";
|
|
6206
|
+
var defaultProvingMethodAlg = proving2.provingMethodGroth16AuthV2Instance.methodAlg;
|
|
5787
6207
|
var AbstractMessageHandler = class {
|
|
5788
6208
|
nextMessageHandler;
|
|
5789
6209
|
setNext(messageHandler) {
|
|
@@ -5859,6 +6279,9 @@ var MessageHandler = class {
|
|
|
5859
6279
|
if (!this.messageHandler) {
|
|
5860
6280
|
return Promise.reject(new Error("Message handler not provided"));
|
|
5861
6281
|
}
|
|
6282
|
+
if (unpackedMediaType === "application/iden3-zkp-json" /* ZKPMessage */) {
|
|
6283
|
+
context.messageProvingMethodAlg = await getProvingMethodAlgFromJWZ(bytes);
|
|
6284
|
+
}
|
|
5862
6285
|
const response = await this.messageHandler.handle(message, context);
|
|
5863
6286
|
if (!response) {
|
|
5864
6287
|
return null;
|
|
@@ -5868,13 +6291,22 @@ var MessageHandler = class {
|
|
|
5868
6291
|
if (unpackedMediaType === "application/iden3-zkp-json" /* ZKPMessage */ && senderDid) {
|
|
5869
6292
|
packerParams = {
|
|
5870
6293
|
senderDID: senderDid,
|
|
5871
|
-
provingMethodAlg:
|
|
6294
|
+
provingMethodAlg: await getProvingMethodAlgFromJWZ(bytes)
|
|
5872
6295
|
};
|
|
5873
6296
|
return this._params.packageManager.packMessage(unpackedMediaType, response, packerParams);
|
|
5874
6297
|
}
|
|
5875
6298
|
return this._params.packageManager.packMessage("application/iden3comm-plain-json" /* PlainMessage */, response, packerParams);
|
|
5876
6299
|
}
|
|
5877
6300
|
};
|
|
6301
|
+
async function getProvingMethodAlgFromJWZ(bytes) {
|
|
6302
|
+
try {
|
|
6303
|
+
const tokenString = byteDecoder.decode(bytes);
|
|
6304
|
+
const token = await Token3.parse(tokenString);
|
|
6305
|
+
return token.method.methodAlg;
|
|
6306
|
+
} catch (e) {
|
|
6307
|
+
return defaultProvingMethodAlg;
|
|
6308
|
+
}
|
|
6309
|
+
}
|
|
5878
6310
|
|
|
5879
6311
|
// src/iden3comm/handlers/auth.ts
|
|
5880
6312
|
function createAuthorizationRequest(reason, sender, callbackUrl, opts) {
|
|
@@ -5895,8 +6327,8 @@ function createAuthorizationRequestWithMessage(reason, message, sender, callback
|
|
|
5895
6327
|
callbackUrl,
|
|
5896
6328
|
scope: opts?.scope ?? []
|
|
5897
6329
|
},
|
|
5898
|
-
created_time:
|
|
5899
|
-
expires_time: opts?.expires_time ?
|
|
6330
|
+
created_time: getUnixTimestamp4(/* @__PURE__ */ new Date()),
|
|
6331
|
+
expires_time: opts?.expires_time ? getUnixTimestamp4(opts.expires_time) : void 0,
|
|
5900
6332
|
attachments: opts?.attachments
|
|
5901
6333
|
};
|
|
5902
6334
|
return request;
|
|
@@ -5957,11 +6389,7 @@ var AuthHandler = class extends AbstractMessageHandler {
|
|
|
5957
6389
|
throw new Error("auth request should contain from field");
|
|
5958
6390
|
}
|
|
5959
6391
|
const responseType = PROTOCOL_MESSAGE_TYPE.AUTHORIZATION_RESPONSE_MESSAGE_TYPE;
|
|
5960
|
-
const mediaType = this.getSupportedMediaTypeByProfile(
|
|
5961
|
-
ctx,
|
|
5962
|
-
responseType,
|
|
5963
|
-
authRequest.body.accept
|
|
5964
|
-
);
|
|
6392
|
+
const mediaType = this.getSupportedMediaTypeByProfile(ctx, authRequest.body.accept);
|
|
5965
6393
|
const from = DID8.parse(authRequest.from);
|
|
5966
6394
|
const responseScope = await processZeroKnowledgeProofRequests(
|
|
5967
6395
|
to,
|
|
@@ -6005,7 +6433,10 @@ var AuthHandler = class extends AbstractMessageHandler {
|
|
|
6005
6433
|
});
|
|
6006
6434
|
const msgBytes = byteEncoder.encode(JSON.stringify(authResponse));
|
|
6007
6435
|
const packerOpts = opts.mediaType === "application/iden3comm-signed-json" /* SignedMessage */ ? opts.packerOptions : {
|
|
6008
|
-
provingMethodAlg:
|
|
6436
|
+
provingMethodAlg: this.getDefaultProvingMethodAlg(
|
|
6437
|
+
opts.preferredAuthProvingMethod,
|
|
6438
|
+
authRequest.body.accept
|
|
6439
|
+
)
|
|
6009
6440
|
};
|
|
6010
6441
|
const token = byteDecoder.decode(
|
|
6011
6442
|
await this._packerMgr.pack(opts.mediaType, msgBytes, {
|
|
@@ -6119,7 +6550,7 @@ var AuthHandler = class extends AbstractMessageHandler {
|
|
|
6119
6550
|
}
|
|
6120
6551
|
}
|
|
6121
6552
|
}
|
|
6122
|
-
getSupportedMediaTypeByProfile(ctx,
|
|
6553
|
+
getSupportedMediaTypeByProfile(ctx, profile) {
|
|
6123
6554
|
let mediaType;
|
|
6124
6555
|
if (!profile?.length) {
|
|
6125
6556
|
return ctx.mediaType || "application/iden3-zkp-json" /* ZKPMessage */;
|
|
@@ -6140,6 +6571,31 @@ var AuthHandler = class extends AbstractMessageHandler {
|
|
|
6140
6571
|
}
|
|
6141
6572
|
return mediaType;
|
|
6142
6573
|
}
|
|
6574
|
+
getDefaultProvingMethodAlg(preferredAuthProvingMethod, accept) {
|
|
6575
|
+
if (preferredAuthProvingMethod && this._packerMgr.isProfileSupported(
|
|
6576
|
+
"application/iden3-zkp-json" /* ZKPMessage */,
|
|
6577
|
+
buildAcceptFromProvingMethodAlg(preferredAuthProvingMethod)
|
|
6578
|
+
) && (!accept?.length || acceptHasProvingMethodAlg(accept, preferredAuthProvingMethod))) {
|
|
6579
|
+
return preferredAuthProvingMethod;
|
|
6580
|
+
}
|
|
6581
|
+
if (accept?.length) {
|
|
6582
|
+
const authV3_8_32 = proving3.provingMethodGroth16AuthV3_8_32Instance.methodAlg;
|
|
6583
|
+
if (acceptHasProvingMethodAlg(accept, authV3_8_32) && this._packerMgr.isProfileSupported(
|
|
6584
|
+
"application/iden3-zkp-json" /* ZKPMessage */,
|
|
6585
|
+
buildAcceptFromProvingMethodAlg(authV3_8_32)
|
|
6586
|
+
)) {
|
|
6587
|
+
return authV3_8_32;
|
|
6588
|
+
}
|
|
6589
|
+
const authV3 = proving3.provingMethodGroth16AuthV3Instance.methodAlg;
|
|
6590
|
+
if (acceptHasProvingMethodAlg(accept, authV3) && this._packerMgr.isProfileSupported(
|
|
6591
|
+
"application/iden3-zkp-json" /* ZKPMessage */,
|
|
6592
|
+
buildAcceptFromProvingMethodAlg(authV3)
|
|
6593
|
+
)) {
|
|
6594
|
+
return authV3;
|
|
6595
|
+
}
|
|
6596
|
+
}
|
|
6597
|
+
return defaultProvingMethodAlg;
|
|
6598
|
+
}
|
|
6143
6599
|
};
|
|
6144
6600
|
|
|
6145
6601
|
// src/storage/blockchain/onchain-revocation.ts
|
|
@@ -7127,7 +7583,6 @@ async function buildNodesUp(siblings, node) {
|
|
|
7127
7583
|
}
|
|
7128
7584
|
|
|
7129
7585
|
// src/iden3comm/handlers/fetch.ts
|
|
7130
|
-
import { proving as proving4 } from "@iden3/js-jwz";
|
|
7131
7586
|
import { DID as DID12 } from "@iden3/js-iden3-core";
|
|
7132
7587
|
import * as uuid5 from "uuid";
|
|
7133
7588
|
var FetchHandler = class _FetchHandler extends AbstractMessageHandler {
|
|
@@ -7212,7 +7667,7 @@ var FetchHandler = class _FetchHandler extends AbstractMessageHandler {
|
|
|
7212
7667
|
};
|
|
7213
7668
|
const msgBytes = byteEncoder.encode(JSON.stringify(fetchRequest));
|
|
7214
7669
|
const packerOpts = ctx.mediaType === "application/iden3comm-signed-json" /* SignedMessage */ ? ctx.packerOptions : {
|
|
7215
|
-
provingMethodAlg:
|
|
7670
|
+
provingMethodAlg: ctx?.packerOptions?.provingMethodAlg || defaultProvingMethodAlg
|
|
7216
7671
|
};
|
|
7217
7672
|
const senderDID = DID12.parse(offerMessage.to);
|
|
7218
7673
|
const token = byteDecoder.decode(
|
|
@@ -7275,6 +7730,25 @@ var FetchHandler = class _FetchHandler extends AbstractMessageHandler {
|
|
|
7275
7730
|
if (!opts?.allowExpiredMessages) {
|
|
7276
7731
|
verifyExpiresTime(offerMessage);
|
|
7277
7732
|
}
|
|
7733
|
+
if (!opts?.packerOptions?.provingMethodAlg) {
|
|
7734
|
+
const messageProvingMethodAlg = opts?.messageProvingMethodAlg || await getProvingMethodAlgFromJWZ(offer);
|
|
7735
|
+
const zkpPackerOptions = {
|
|
7736
|
+
provingMethodAlg: messageProvingMethodAlg,
|
|
7737
|
+
senderDID: DID12.parse(offerMessage.to)
|
|
7738
|
+
};
|
|
7739
|
+
if (!opts) {
|
|
7740
|
+
opts = {
|
|
7741
|
+
mediaType: "application/iden3-zkp-json" /* ZKPMessage */,
|
|
7742
|
+
packerOptions: zkpPackerOptions
|
|
7743
|
+
};
|
|
7744
|
+
}
|
|
7745
|
+
if (!opts.packerOptions?.provingMethodAlg) {
|
|
7746
|
+
opts.packerOptions = {
|
|
7747
|
+
...opts.packerOptions,
|
|
7748
|
+
...zkpPackerOptions
|
|
7749
|
+
};
|
|
7750
|
+
}
|
|
7751
|
+
}
|
|
7278
7752
|
const result = await this.handleOfferMessage(offerMessage, {
|
|
7279
7753
|
mediaType: opts?.mediaType,
|
|
7280
7754
|
headers: opts?.headers,
|
|
@@ -7393,7 +7867,7 @@ var FetchHandler = class _FetchHandler extends AbstractMessageHandler {
|
|
|
7393
7867
|
};
|
|
7394
7868
|
|
|
7395
7869
|
// src/iden3comm/handlers/contract-request.ts
|
|
7396
|
-
import { DID as DID13, ChainIds, getUnixTimestamp as
|
|
7870
|
+
import { DID as DID13, ChainIds, getUnixTimestamp as getUnixTimestamp5, BytesHelper as BytesHelper6 } from "@iden3/js-iden3-core";
|
|
7397
7871
|
var ContractRequestHandler = class extends AbstractMessageHandler {
|
|
7398
7872
|
/**
|
|
7399
7873
|
* Creates an instance of ContractRequestHandler.
|
|
@@ -7564,7 +8038,7 @@ var ContractRequestHandler = class extends AbstractMessageHandler {
|
|
|
7564
8038
|
transaction_data: request.body.transaction_data,
|
|
7565
8039
|
scope: []
|
|
7566
8040
|
},
|
|
7567
|
-
created_time:
|
|
8041
|
+
created_time: getUnixTimestamp5(/* @__PURE__ */ new Date())
|
|
7568
8042
|
};
|
|
7569
8043
|
for (const [txHash, zkpResponses] of txHashToZkpResponseMap) {
|
|
7570
8044
|
for (const zkpResponse of zkpResponses.responses) {
|
|
@@ -7628,7 +8102,6 @@ var ContractRequestHandler = class extends AbstractMessageHandler {
|
|
|
7628
8102
|
};
|
|
7629
8103
|
|
|
7630
8104
|
// src/iden3comm/handlers/refresh.ts
|
|
7631
|
-
import { proving as proving5, ProvingMethodAlg as ProvingMethodAlg2 } from "@iden3/js-jwz";
|
|
7632
8105
|
import { DID as DID14 } from "@iden3/js-iden3-core";
|
|
7633
8106
|
import * as uuid6 from "uuid";
|
|
7634
8107
|
var RefreshHandler = class {
|
|
@@ -7651,12 +8124,10 @@ var RefreshHandler = class {
|
|
|
7651
8124
|
throw new Error("self credentials do not support refresh");
|
|
7652
8125
|
}
|
|
7653
8126
|
const senderDID = DID14.parse(otherIdentifier);
|
|
7654
|
-
const
|
|
8127
|
+
const mediaType = opts?.mediaType || "application/iden3-zkp-json" /* ZKPMessage */;
|
|
8128
|
+
const packerOptions = opts?.packerOptions ?? {
|
|
7655
8129
|
senderDID,
|
|
7656
|
-
provingMethodAlg:
|
|
7657
|
-
proving5.provingMethodGroth16AuthV2Instance.methodAlg.alg,
|
|
7658
|
-
"authV2" /* AuthV2 */
|
|
7659
|
-
)
|
|
8130
|
+
provingMethodAlg: defaultProvingMethodAlg
|
|
7660
8131
|
};
|
|
7661
8132
|
const refreshMsg = {
|
|
7662
8133
|
id: uuid6.v4(),
|
|
@@ -7671,17 +8142,13 @@ var RefreshHandler = class {
|
|
|
7671
8142
|
to: credential.issuer
|
|
7672
8143
|
};
|
|
7673
8144
|
const msgBytes = byteEncoder.encode(JSON.stringify(refreshMsg));
|
|
7674
|
-
const
|
|
7675
|
-
"application/iden3-zkp-json" /* ZKPMessage */,
|
|
7676
|
-
msgBytes,
|
|
7677
|
-
zkpParams
|
|
7678
|
-
);
|
|
8145
|
+
const token = await this._options.packageManager.pack(mediaType, msgBytes, packerOptions);
|
|
7679
8146
|
const resp = await fetch(credential.refreshService.id, {
|
|
7680
8147
|
method: "post",
|
|
7681
8148
|
headers: {
|
|
7682
8149
|
"Content-Type": "application/json"
|
|
7683
8150
|
},
|
|
7684
|
-
body:
|
|
8151
|
+
body: token.buffer
|
|
7685
8152
|
});
|
|
7686
8153
|
if (resp.status !== 200) {
|
|
7687
8154
|
throw new Error(`could not refresh W3C credential, return status ${resp.status}`);
|
|
@@ -7697,7 +8164,6 @@ var RefreshHandler = class {
|
|
|
7697
8164
|
// src/iden3comm/handlers/revocation-status.ts
|
|
7698
8165
|
import { DID as DID15 } from "@iden3/js-iden3-core";
|
|
7699
8166
|
import * as uuid7 from "uuid";
|
|
7700
|
-
import { proving as proving6 } from "@iden3/js-jwz";
|
|
7701
8167
|
var RevocationStatusHandler = class extends AbstractMessageHandler {
|
|
7702
8168
|
/**
|
|
7703
8169
|
* Creates an instance of RevocationStatusHandler.
|
|
@@ -7799,7 +8265,7 @@ var RevocationStatusHandler = class extends AbstractMessageHandler {
|
|
|
7799
8265
|
treeState: opts.treeState
|
|
7800
8266
|
});
|
|
7801
8267
|
const packerOpts = opts.mediaType === "application/iden3comm-signed-json" /* SignedMessage */ ? opts.packerOptions : {
|
|
7802
|
-
provingMethodAlg:
|
|
8268
|
+
provingMethodAlg: opts.packerOptions?.provingMethodAlg || await getProvingMethodAlgFromJWZ(request)
|
|
7803
8269
|
};
|
|
7804
8270
|
if (!rsRequest.to) {
|
|
7805
8271
|
throw new Error(`failed request. empty 'to' field`);
|
|
@@ -7813,9 +8279,8 @@ var RevocationStatusHandler = class extends AbstractMessageHandler {
|
|
|
7813
8279
|
};
|
|
7814
8280
|
|
|
7815
8281
|
// src/iden3comm/handlers/credential-proposal.ts
|
|
7816
|
-
import { DID as DID16, getUnixTimestamp as
|
|
8282
|
+
import { DID as DID16, getUnixTimestamp as getUnixTimestamp6 } from "@iden3/js-iden3-core";
|
|
7817
8283
|
import * as uuid8 from "uuid";
|
|
7818
|
-
import { proving as proving7 } from "@iden3/js-jwz";
|
|
7819
8284
|
function createProposalRequest(sender, receiver, opts) {
|
|
7820
8285
|
const uuidv4 = uuid8.v4();
|
|
7821
8286
|
const request = {
|
|
@@ -7825,9 +8290,12 @@ function createProposalRequest(sender, receiver, opts) {
|
|
|
7825
8290
|
to: receiver.string(),
|
|
7826
8291
|
typ: "application/iden3comm-plain-json" /* PlainMessage */,
|
|
7827
8292
|
type: PROTOCOL_MESSAGE_TYPE.PROPOSAL_REQUEST_MESSAGE_TYPE,
|
|
7828
|
-
body:
|
|
7829
|
-
|
|
7830
|
-
|
|
8293
|
+
body: {
|
|
8294
|
+
credentials: opts.credentials,
|
|
8295
|
+
did_doc: opts.did_doc
|
|
8296
|
+
},
|
|
8297
|
+
created_time: getUnixTimestamp6(/* @__PURE__ */ new Date()),
|
|
8298
|
+
expires_time: opts?.expires_time ? getUnixTimestamp6(opts.expires_time) : void 0,
|
|
7831
8299
|
attachments: opts.attachments
|
|
7832
8300
|
};
|
|
7833
8301
|
return request;
|
|
@@ -7844,8 +8312,8 @@ function createProposal(sender, receiver, proposals, opts) {
|
|
|
7844
8312
|
body: {
|
|
7845
8313
|
proposals: proposals || []
|
|
7846
8314
|
},
|
|
7847
|
-
created_time:
|
|
7848
|
-
expires_time: opts?.expires_time ?
|
|
8315
|
+
created_time: getUnixTimestamp6(/* @__PURE__ */ new Date()),
|
|
8316
|
+
expires_time: opts?.expires_time ? getUnixTimestamp6(opts.expires_time) : void 0
|
|
7849
8317
|
};
|
|
7850
8318
|
return request;
|
|
7851
8319
|
}
|
|
@@ -7982,7 +8450,7 @@ var CredentialProposalHandler = class extends AbstractMessageHandler {
|
|
|
7982
8450
|
const message = await this.handleProposalRequestMessage(proposalRequest);
|
|
7983
8451
|
const response = byteEncoder.encode(JSON.stringify(message));
|
|
7984
8452
|
const packerOpts = this._params.packerParams.mediaType === "application/iden3comm-signed-json" /* SignedMessage */ ? this._params.packerParams.packerOptions : {
|
|
7985
|
-
provingMethodAlg:
|
|
8453
|
+
provingMethodAlg: this._params.packerParams.provingMethodAlg || await getProvingMethodAlgFromJWZ(request)
|
|
7986
8454
|
};
|
|
7987
8455
|
return this._packerMgr.pack(this._params.packerParams.mediaType, response, {
|
|
7988
8456
|
senderDID,
|
|
@@ -8006,10 +8474,8 @@ var CredentialProposalHandler = class extends AbstractMessageHandler {
|
|
|
8006
8474
|
};
|
|
8007
8475
|
|
|
8008
8476
|
// src/iden3comm/handlers/payment.ts
|
|
8009
|
-
import { DID as DID17, getUnixTimestamp as
|
|
8477
|
+
import { DID as DID17, getUnixTimestamp as getUnixTimestamp7 } from "@iden3/js-iden3-core";
|
|
8010
8478
|
import * as uuid9 from "uuid";
|
|
8011
|
-
import { proving as proving8 } from "@iden3/js-jwz";
|
|
8012
|
-
import { ethers as ethers3 } from "ethers";
|
|
8013
8479
|
function createPaymentRequest(sender, receiver, agent, payments, opts) {
|
|
8014
8480
|
const uuidv4 = uuid9.v4();
|
|
8015
8481
|
const request = {
|
|
@@ -8023,48 +8489,11 @@ function createPaymentRequest(sender, receiver, agent, payments, opts) {
|
|
|
8023
8489
|
agent,
|
|
8024
8490
|
payments
|
|
8025
8491
|
},
|
|
8026
|
-
created_time:
|
|
8027
|
-
expires_time: opts?.expires_time ?
|
|
8492
|
+
created_time: getUnixTimestamp7(/* @__PURE__ */ new Date()),
|
|
8493
|
+
expires_time: opts?.expires_time ? getUnixTimestamp7(opts.expires_time) : void 0
|
|
8028
8494
|
};
|
|
8029
8495
|
return request;
|
|
8030
8496
|
}
|
|
8031
|
-
async function verifyEIP712TypedData(data, resolver) {
|
|
8032
|
-
const paymentData = data.type === "Iden3PaymentRailsRequestV1" /* Iden3PaymentRailsRequestV1 */ ? {
|
|
8033
|
-
recipient: data.recipient,
|
|
8034
|
-
amount: data.amount,
|
|
8035
|
-
expirationDate: getUnixTimestamp5(new Date(data.expirationDate)),
|
|
8036
|
-
nonce: data.nonce,
|
|
8037
|
-
metadata: "0x"
|
|
8038
|
-
} : {
|
|
8039
|
-
tokenAddress: data.tokenAddress,
|
|
8040
|
-
recipient: data.recipient,
|
|
8041
|
-
amount: data.amount,
|
|
8042
|
-
expirationDate: getUnixTimestamp5(new Date(data.expirationDate)),
|
|
8043
|
-
nonce: data.nonce,
|
|
8044
|
-
metadata: "0x"
|
|
8045
|
-
};
|
|
8046
|
-
const proof = Array.isArray(data.proof) ? data.proof[0] : data.proof;
|
|
8047
|
-
const typesFetchResult = await fetch(proof.eip712.types);
|
|
8048
|
-
const types = await typesFetchResult.json();
|
|
8049
|
-
delete types.EIP712Domain;
|
|
8050
|
-
const recovered = ethers3.verifyTypedData(
|
|
8051
|
-
proof.eip712.domain,
|
|
8052
|
-
types,
|
|
8053
|
-
paymentData,
|
|
8054
|
-
proof.proofValue
|
|
8055
|
-
);
|
|
8056
|
-
const { didDocument } = await resolver.resolve(proof.verificationMethod);
|
|
8057
|
-
if (didDocument?.verificationMethod) {
|
|
8058
|
-
for (const verificationMethod of didDocument.verificationMethod) {
|
|
8059
|
-
if (verificationMethod.blockchainAccountId?.split(":").slice(-1)[0].toLowerCase() === recovered.toLowerCase()) {
|
|
8060
|
-
return recovered;
|
|
8061
|
-
}
|
|
8062
|
-
}
|
|
8063
|
-
} else {
|
|
8064
|
-
throw new Error("failed request. issuer DIDDocument does not contain any verificationMethods");
|
|
8065
|
-
}
|
|
8066
|
-
throw new Error(`failed request. no matching verificationMethod`);
|
|
8067
|
-
}
|
|
8068
8497
|
function createPayment(sender, receiver, payments, opts) {
|
|
8069
8498
|
const uuidv4 = uuid9.v4();
|
|
8070
8499
|
const request = {
|
|
@@ -8077,8 +8506,8 @@ function createPayment(sender, receiver, payments, opts) {
|
|
|
8077
8506
|
body: {
|
|
8078
8507
|
payments
|
|
8079
8508
|
},
|
|
8080
|
-
created_time:
|
|
8081
|
-
expires_time: opts?.expires_time ?
|
|
8509
|
+
created_time: getUnixTimestamp7(/* @__PURE__ */ new Date()),
|
|
8510
|
+
expires_time: opts?.expires_time ? getUnixTimestamp7(opts.expires_time) : void 0
|
|
8082
8511
|
};
|
|
8083
8512
|
return request;
|
|
8084
8513
|
}
|
|
@@ -8163,13 +8592,34 @@ var PaymentHandler = class extends AbstractMessageHandler {
|
|
|
8163
8592
|
)
|
|
8164
8593
|
);
|
|
8165
8594
|
break;
|
|
8595
|
+
case "Iden3PaymentRailsSolanaRequestV1" /* Iden3PaymentRailsSolanaRequestV1 */:
|
|
8596
|
+
payments.push(
|
|
8597
|
+
await this.handleIden3PaymentRailsSolanaRequestV1(selectedPayment, ctx.paymentHandler)
|
|
8598
|
+
);
|
|
8599
|
+
break;
|
|
8600
|
+
case "Iden3PaymentRailsSolanaSPLRequestV1" /* Iden3PaymentRailsSolanaSPLRequestV1 */:
|
|
8601
|
+
payments.push(
|
|
8602
|
+
await this.handleIden3PaymentRailsSolanaSPLRequestV1(
|
|
8603
|
+
{
|
|
8604
|
+
...selectedPayment,
|
|
8605
|
+
type: "Iden3PaymentRailsSolanaSPLRequestV1" /* Iden3PaymentRailsSolanaSPLRequestV1 */
|
|
8606
|
+
},
|
|
8607
|
+
ctx.paymentHandler
|
|
8608
|
+
)
|
|
8609
|
+
);
|
|
8610
|
+
break;
|
|
8166
8611
|
}
|
|
8167
8612
|
}
|
|
8168
8613
|
const paymentMessage = createPayment(senderDID, receiverDID, payments);
|
|
8169
|
-
const
|
|
8614
|
+
const mediaType = ctx?.mediaType || this._params.packerParams.mediaType || "application/iden3-zkp-json" /* ZKPMessage */;
|
|
8615
|
+
const packerParams = ctx?.packerOptions || this._params.packerParams;
|
|
8616
|
+
if (mediaType === "application/iden3-zkp-json" /* ZKPMessage */ && !packerParams?.provingMethodAlg) {
|
|
8617
|
+
packerParams.provingMethodAlg = ctx.messageProvingMethodAlg;
|
|
8618
|
+
}
|
|
8619
|
+
const response = await this.packMessage(paymentMessage, senderDID, mediaType, packerParams);
|
|
8170
8620
|
const agentResult = await fetch(paymentRequest.body.agent, {
|
|
8171
8621
|
method: "POST",
|
|
8172
|
-
body: response,
|
|
8622
|
+
body: response.buffer,
|
|
8173
8623
|
headers: {
|
|
8174
8624
|
"Content-Type": this._params.packerParams.mediaType === "application/iden3comm-plain-json" /* PlainMessage */ ? "application/json" : "application/octet-stream"
|
|
8175
8625
|
}
|
|
@@ -8198,12 +8648,32 @@ var PaymentHandler = class extends AbstractMessageHandler {
|
|
|
8198
8648
|
if (!opts?.allowExpiredMessages) {
|
|
8199
8649
|
verifyExpiresTime(paymentRequest);
|
|
8200
8650
|
}
|
|
8651
|
+
if (!opts?.mediaType) {
|
|
8652
|
+
opts.mediaType = this._params.packerParams.mediaType || "application/iden3-zkp-json" /* ZKPMessage */;
|
|
8653
|
+
}
|
|
8654
|
+
if (!opts.packerOptions) {
|
|
8655
|
+
opts.packerOptions = this._params.packerParams.packerOptions;
|
|
8656
|
+
}
|
|
8657
|
+
if (!opts?.packerOptions && opts.mediaType === "application/iden3comm-signed-json" /* SignedMessage */) {
|
|
8658
|
+
throw new Error(`jws packer options are required for ${"application/iden3comm-signed-json" /* SignedMessage */}`);
|
|
8659
|
+
}
|
|
8660
|
+
const senderDID = DID17.parse(paymentRequest.to);
|
|
8661
|
+
if (opts.mediaType === "application/iden3-zkp-json" /* ZKPMessage */ && !opts.packerOptions?.provingMethodAlg) {
|
|
8662
|
+
opts.packerOptions = {
|
|
8663
|
+
provingMethodAlg: await getProvingMethodAlgFromJWZ(request),
|
|
8664
|
+
senderDID
|
|
8665
|
+
};
|
|
8666
|
+
}
|
|
8201
8667
|
const agentMessage = await this.handlePaymentRequestMessage(paymentRequest, opts);
|
|
8202
8668
|
if (!agentMessage) {
|
|
8203
8669
|
return null;
|
|
8204
8670
|
}
|
|
8205
|
-
|
|
8206
|
-
|
|
8671
|
+
return this.packMessage(
|
|
8672
|
+
agentMessage,
|
|
8673
|
+
senderDID,
|
|
8674
|
+
opts.mediaType || "application/iden3-zkp-json" /* ZKPMessage */,
|
|
8675
|
+
opts.packerOptions
|
|
8676
|
+
);
|
|
8207
8677
|
}
|
|
8208
8678
|
/**
|
|
8209
8679
|
* @inheritdoc IPaymentHandler#handlePayment
|
|
@@ -8241,7 +8711,7 @@ var PaymentHandler = class extends AbstractMessageHandler {
|
|
|
8241
8711
|
/**
|
|
8242
8712
|
* @inheritdoc IPaymentHandler#createPaymentRailsV1
|
|
8243
8713
|
*/
|
|
8244
|
-
async createPaymentRailsV1(sender, receiver, agent, signer, payments) {
|
|
8714
|
+
async createPaymentRailsV1(sender, receiver, agent, signer, payments, createOptions) {
|
|
8245
8715
|
const paymentRequestInfo = [];
|
|
8246
8716
|
for (let i = 0; i < payments.length; i++) {
|
|
8247
8717
|
const { credentials, description } = payments[i];
|
|
@@ -8259,70 +8729,40 @@ var PaymentHandler = class extends AbstractMessageHandler {
|
|
|
8259
8729
|
if (!option) {
|
|
8260
8730
|
throw new Error(`failed request. no option for id ${optionId}`);
|
|
8261
8731
|
}
|
|
8262
|
-
if (option.type === "Iden3PaymentRailsERC20RequestV1" /* Iden3PaymentRailsERC20RequestV1 */ && !option.contractAddress) {
|
|
8732
|
+
if ((option.type === "Iden3PaymentRailsERC20RequestV1" /* Iden3PaymentRailsERC20RequestV1 */ || option.type === "Iden3PaymentRailsSolanaSPLRequestV1" /* Iden3PaymentRailsSolanaSPLRequestV1 */) && !option.contractAddress) {
|
|
8263
8733
|
throw new Error(`failed request. no token address for option id ${optionId}`);
|
|
8264
8734
|
}
|
|
8265
8735
|
const expirationDateRequired = expirationDate ?? new Date((/* @__PURE__ */ new Date()).setHours((/* @__PURE__ */ new Date()).getHours() + 1));
|
|
8266
|
-
|
|
8267
|
-
|
|
8268
|
-
|
|
8269
|
-
|
|
8270
|
-
|
|
8271
|
-
recipient,
|
|
8272
|
-
amount,
|
|
8273
|
-
expirationDate: getUnixTimestamp5(expirationDateRequired),
|
|
8274
|
-
nonce,
|
|
8275
|
-
metadata: "0x"
|
|
8276
|
-
} : {
|
|
8277
|
-
tokenAddress: option.contractAddress,
|
|
8278
|
-
recipient,
|
|
8279
|
-
amount,
|
|
8280
|
-
expirationDate: getUnixTimestamp5(expirationDateRequired),
|
|
8281
|
-
nonce,
|
|
8282
|
-
metadata: "0x"
|
|
8283
|
-
};
|
|
8284
|
-
const domain = {
|
|
8285
|
-
name: "MCPayment",
|
|
8286
|
-
version: "1.0.0",
|
|
8287
|
-
chainId,
|
|
8288
|
-
verifyingContract: paymentRails
|
|
8289
|
-
};
|
|
8290
|
-
const signature = await signer.signTypedData(domain, types, paymentData);
|
|
8291
|
-
const proof = [
|
|
8292
|
-
{
|
|
8293
|
-
type: "EthereumEip712Signature2021" /* EthereumEip712Signature2021 */,
|
|
8294
|
-
proofPurpose: "assertionMethod",
|
|
8295
|
-
proofValue: signature,
|
|
8296
|
-
verificationMethod: `did:pkh:eip155:${chainId}:${await signer.getAddress()}`,
|
|
8297
|
-
created: (/* @__PURE__ */ new Date()).toISOString(),
|
|
8298
|
-
eip712: {
|
|
8299
|
-
types: typeUrl,
|
|
8300
|
-
primaryType: "Iden3PaymentRailsRequestV1",
|
|
8301
|
-
domain
|
|
8302
|
-
}
|
|
8303
|
-
}
|
|
8304
|
-
];
|
|
8305
|
-
const d = {
|
|
8306
|
-
type: "Iden3PaymentRailsRequestV1" /* Iden3PaymentRailsRequestV1 */,
|
|
8307
|
-
"@context": [
|
|
8308
|
-
`https://schema.iden3.io/core/jsonld/payment.jsonld#${option.type}`,
|
|
8309
|
-
"https://w3id.org/security/suites/eip712sig-2021/v1"
|
|
8310
|
-
],
|
|
8311
|
-
recipient,
|
|
8312
|
-
amount: amount.toString(),
|
|
8313
|
-
expirationDate: expirationDateRequired.toISOString(),
|
|
8314
|
-
nonce: nonce.toString(),
|
|
8315
|
-
metadata: "0x",
|
|
8316
|
-
proof
|
|
8317
|
-
};
|
|
8318
|
-
dataArr.push(
|
|
8319
|
-
option.type === "Iden3PaymentRailsRequestV1" /* Iden3PaymentRailsRequestV1 */ ? d : {
|
|
8320
|
-
...d,
|
|
8321
|
-
type: option.type,
|
|
8322
|
-
tokenAddress: option.contractAddress || "",
|
|
8323
|
-
features: option.features || []
|
|
8736
|
+
if (option.type === "Iden3PaymentRailsSolanaRequestV1" /* Iden3PaymentRailsSolanaRequestV1 */ || option.type === "Iden3PaymentRailsSolanaSPLRequestV1" /* Iden3PaymentRailsSolanaSPLRequestV1 */) {
|
|
8737
|
+
if (!createOptions?.solSigner) {
|
|
8738
|
+
throw new Error(
|
|
8739
|
+
`please provide solana signer in context for ${option.type} payment type`
|
|
8740
|
+
);
|
|
8324
8741
|
}
|
|
8325
|
-
|
|
8742
|
+
const payment = await buildSolanaPayment(
|
|
8743
|
+
createOptions.solSigner,
|
|
8744
|
+
option,
|
|
8745
|
+
chainId,
|
|
8746
|
+
paymentRails,
|
|
8747
|
+
recipient,
|
|
8748
|
+
BigInt(amount),
|
|
8749
|
+
expirationDateRequired,
|
|
8750
|
+
nonce
|
|
8751
|
+
);
|
|
8752
|
+
dataArr.push(payment);
|
|
8753
|
+
} else {
|
|
8754
|
+
const payment = await buildEvmPayment(
|
|
8755
|
+
signer,
|
|
8756
|
+
option,
|
|
8757
|
+
chainId,
|
|
8758
|
+
paymentRails,
|
|
8759
|
+
recipient,
|
|
8760
|
+
BigInt(amount),
|
|
8761
|
+
expirationDateRequired,
|
|
8762
|
+
nonce
|
|
8763
|
+
);
|
|
8764
|
+
dataArr.push(payment);
|
|
8765
|
+
}
|
|
8326
8766
|
}
|
|
8327
8767
|
paymentRequestInfo.push({
|
|
8328
8768
|
data: dataArr,
|
|
@@ -8332,12 +8772,12 @@ var PaymentHandler = class extends AbstractMessageHandler {
|
|
|
8332
8772
|
}
|
|
8333
8773
|
return createPaymentRequest(sender, receiver, agent, paymentRequestInfo);
|
|
8334
8774
|
}
|
|
8335
|
-
async packMessage(message, senderDID) {
|
|
8775
|
+
async packMessage(message, senderDID, mediaType, packerParams) {
|
|
8336
8776
|
const responseEncoded = byteEncoder.encode(JSON.stringify(message));
|
|
8337
|
-
const packerOpts =
|
|
8338
|
-
provingMethodAlg:
|
|
8777
|
+
const packerOpts = mediaType === "application/iden3comm-signed-json" /* SignedMessage */ ? packerParams : {
|
|
8778
|
+
provingMethodAlg: packerParams?.provingMethodAlg || defaultProvingMethodAlg
|
|
8339
8779
|
};
|
|
8340
|
-
return await this._packerMgr.pack(
|
|
8780
|
+
return await this._packerMgr.pack(mediaType, responseEncoded, {
|
|
8341
8781
|
senderDID,
|
|
8342
8782
|
...packerOpts
|
|
8343
8783
|
});
|
|
@@ -8376,6 +8816,55 @@ var PaymentHandler = class extends AbstractMessageHandler {
|
|
|
8376
8816
|
}
|
|
8377
8817
|
};
|
|
8378
8818
|
}
|
|
8819
|
+
async handleIden3PaymentRailsSolanaRequestV1(data, paymentHandler) {
|
|
8820
|
+
if (data.expirationDate && new Date(data.expirationDate) < /* @__PURE__ */ new Date()) {
|
|
8821
|
+
throw new Error(`failed request. expired request`);
|
|
8822
|
+
}
|
|
8823
|
+
const isValid = await verifyIden3SolanaPaymentRequest(data, this._params.documentResolver);
|
|
8824
|
+
if (!isValid) {
|
|
8825
|
+
throw new Error(`failed request. invalid Solana payment request signature`);
|
|
8826
|
+
}
|
|
8827
|
+
const proof = Array.isArray(data.proof) ? data.proof[0] : data.proof;
|
|
8828
|
+
const signer = proof.verificationMethod.split(":").slice(-1)[0];
|
|
8829
|
+
if (this._params.allowedSigners && !this._params.allowedSigners.includes(signer)) {
|
|
8830
|
+
throw new Error(`failed request. signer is not in the allowed signers list`);
|
|
8831
|
+
}
|
|
8832
|
+
const txId = await paymentHandler(data);
|
|
8833
|
+
return {
|
|
8834
|
+
nonce: data.nonce,
|
|
8835
|
+
type: "Iden3PaymentRailsSolanaV1" /* Iden3PaymentRailsSolanaV1 */,
|
|
8836
|
+
"@context": "https://schema.iden3.io/core/jsonld/payment.jsonld#Iden3PaymentRailsSolanaV1",
|
|
8837
|
+
paymentData: {
|
|
8838
|
+
txId,
|
|
8839
|
+
chainId: proof.domain.chainId
|
|
8840
|
+
}
|
|
8841
|
+
};
|
|
8842
|
+
}
|
|
8843
|
+
async handleIden3PaymentRailsSolanaSPLRequestV1(data, paymentHandler) {
|
|
8844
|
+
if (data.expirationDate && new Date(data.expirationDate) < /* @__PURE__ */ new Date()) {
|
|
8845
|
+
throw new Error(`failed request. expired request`);
|
|
8846
|
+
}
|
|
8847
|
+
const isValid = await verifyIden3SolanaPaymentRequest(data, this._params.documentResolver);
|
|
8848
|
+
if (!isValid) {
|
|
8849
|
+
throw new Error(`failed request. invalid Solana payment request signature`);
|
|
8850
|
+
}
|
|
8851
|
+
const proof = Array.isArray(data.proof) ? data.proof[0] : data.proof;
|
|
8852
|
+
const signer = proof.verificationMethod.split(":").slice(-1)[0];
|
|
8853
|
+
if (this._params.allowedSigners && !this._params.allowedSigners.includes(signer)) {
|
|
8854
|
+
throw new Error(`failed request. signer is not in the allowed signers list`);
|
|
8855
|
+
}
|
|
8856
|
+
const txId = await paymentHandler(data);
|
|
8857
|
+
return {
|
|
8858
|
+
nonce: data.nonce,
|
|
8859
|
+
type: "Iden3PaymentRailsSolanaSPLV1" /* Iden3PaymentRailsSolanaSPLV1 */,
|
|
8860
|
+
"@context": "https://schema.iden3.io/core/jsonld/payment.jsonld#Iden3PaymentRailsSolanaSPLV1",
|
|
8861
|
+
paymentData: {
|
|
8862
|
+
txId,
|
|
8863
|
+
chainId: proof.domain.chainId,
|
|
8864
|
+
tokenAddress: data.tokenAddress
|
|
8865
|
+
}
|
|
8866
|
+
};
|
|
8867
|
+
}
|
|
8379
8868
|
async handleIden3PaymentRailsERC20RequestV1(data, paymentHandler, approveHandler) {
|
|
8380
8869
|
if (data.expirationDate && new Date(data.expirationDate) < /* @__PURE__ */ new Date()) {
|
|
8381
8870
|
throw new Error(`failed request. expired request`);
|
|
@@ -8407,7 +8896,7 @@ var PaymentHandler = class extends AbstractMessageHandler {
|
|
|
8407
8896
|
|
|
8408
8897
|
// src/iden3comm/handlers/discovery-protocol.ts
|
|
8409
8898
|
import * as uuid10 from "uuid";
|
|
8410
|
-
import { getUnixTimestamp as
|
|
8899
|
+
import { getUnixTimestamp as getUnixTimestamp8 } from "@iden3/js-iden3-core";
|
|
8411
8900
|
function createDiscoveryFeatureQueryMessage(queries, opts) {
|
|
8412
8901
|
const uuidv4 = uuid10.v4();
|
|
8413
8902
|
return {
|
|
@@ -8420,7 +8909,7 @@ function createDiscoveryFeatureQueryMessage(queries, opts) {
|
|
|
8420
8909
|
},
|
|
8421
8910
|
from: opts?.from,
|
|
8422
8911
|
to: opts?.to,
|
|
8423
|
-
created_time:
|
|
8912
|
+
created_time: getUnixTimestamp8(/* @__PURE__ */ new Date()),
|
|
8424
8913
|
expires_time: opts?.expires_time
|
|
8425
8914
|
};
|
|
8426
8915
|
}
|
|
@@ -8436,7 +8925,7 @@ function createDiscoveryFeatureDiscloseMessage(disclosures, opts) {
|
|
|
8436
8925
|
},
|
|
8437
8926
|
from: opts?.from,
|
|
8438
8927
|
to: opts?.to,
|
|
8439
|
-
created_time:
|
|
8928
|
+
created_time: getUnixTimestamp8(/* @__PURE__ */ new Date()),
|
|
8440
8929
|
expires_time: opts?.expires_time
|
|
8441
8930
|
};
|
|
8442
8931
|
}
|
|
@@ -8489,7 +8978,7 @@ var DiscoveryProtocolHandler = class extends AbstractMessageHandler {
|
|
|
8489
8978
|
createDiscoveryFeatureDiscloseMessage(disclosures, {
|
|
8490
8979
|
to: message.from,
|
|
8491
8980
|
from: message.to,
|
|
8492
|
-
expires_time: opts?.disclosureExpiresDate ?
|
|
8981
|
+
expires_time: opts?.disclosureExpiresDate ? getUnixTimestamp8(opts.disclosureExpiresDate) : void 0
|
|
8493
8982
|
})
|
|
8494
8983
|
);
|
|
8495
8984
|
}
|
|
@@ -11869,7 +12358,7 @@ var NativeProver = class _NativeProver {
|
|
|
11869
12358
|
if (!circuitData.wasm) {
|
|
11870
12359
|
throw new Error(`wasm file doesn't exist for circuit ${circuitId}`);
|
|
11871
12360
|
}
|
|
11872
|
-
const witnessCalculator = await witnessBuilder(circuitData.wasm);
|
|
12361
|
+
const witnessCalculator = await witnessBuilder(circuitData.wasm.buffer);
|
|
11873
12362
|
const parsedData = JSON.parse(byteDecoder.decode(inputs));
|
|
11874
12363
|
const wtnsBytes = await witnessCalculator.calculateWTNSBin(parsedData, 0);
|
|
11875
12364
|
if (!circuitData.provingKey) {
|
|
@@ -11892,7 +12381,7 @@ var NativeProver = class _NativeProver {
|
|
|
11892
12381
|
import { getDocumentLoader as getDocumentLoader3 } from "@iden3/js-jsonld-merklization";
|
|
11893
12382
|
|
|
11894
12383
|
// src/proof/provers/inputs-generator.ts
|
|
11895
|
-
import { DID as DID23, getUnixTimestamp as
|
|
12384
|
+
import { DID as DID23, getUnixTimestamp as getUnixTimestamp9 } from "@iden3/js-iden3-core";
|
|
11896
12385
|
var allOperations2 = Object.values(QueryOperators);
|
|
11897
12386
|
var v2Operations = [
|
|
11898
12387
|
0 /* NOOP */,
|
|
@@ -11926,6 +12415,8 @@ var circuitValidator = {
|
|
|
11926
12415
|
["credentialAtomicQueryV3-beta.1" /* AtomicQueryV3 */]: { maxQueriesCount: 1, supportedOperations: allOperations2 },
|
|
11927
12416
|
["credentialAtomicQueryV3OnChain-beta.1" /* AtomicQueryV3OnChain */]: { maxQueriesCount: 1, supportedOperations: allOperations2 },
|
|
11928
12417
|
["authV2" /* AuthV2 */]: { maxQueriesCount: 0, supportedOperations: [] },
|
|
12418
|
+
["authV3" /* AuthV3 */]: { maxQueriesCount: 0, supportedOperations: [] },
|
|
12419
|
+
["authV3-8-32" /* AuthV3_8_32 */]: { maxQueriesCount: 0, supportedOperations: [] },
|
|
11929
12420
|
["stateTransition" /* StateTransition */]: { maxQueriesCount: 0, supportedOperations: [] },
|
|
11930
12421
|
["linkedMultiQuery10-beta.1" /* LinkedMultiQuery10 */]: { maxQueriesCount: 10, supportedOperations: allOperations2 }
|
|
11931
12422
|
};
|
|
@@ -12040,7 +12531,7 @@ var InputGenerator = class {
|
|
|
12040
12531
|
incProof: { proof: circuitClaimData.proof, treeState: circuitClaimData.treeState },
|
|
12041
12532
|
nonRevProof: circuitClaimData.nonRevProof
|
|
12042
12533
|
};
|
|
12043
|
-
circuitInputs.currentTimeStamp =
|
|
12534
|
+
circuitInputs.currentTimeStamp = getUnixTimestamp9(/* @__PURE__ */ new Date());
|
|
12044
12535
|
circuitInputs.claimSubjectProfileNonce = BigInt(params.credentialSubjectProfileNonce);
|
|
12045
12536
|
circuitInputs.profileNonce = BigInt(params.authProfileNonce);
|
|
12046
12537
|
circuitInputs.skipClaimRevocationCheck = params.skipRevocation;
|
|
@@ -12096,7 +12587,7 @@ var InputGenerator = class {
|
|
|
12096
12587
|
incProof: { proof: circuitClaimData.proof, treeState: circuitClaimData.treeState },
|
|
12097
12588
|
nonRevProof: circuitClaimData.nonRevProof
|
|
12098
12589
|
};
|
|
12099
|
-
circuitInputs.currentTimeStamp =
|
|
12590
|
+
circuitInputs.currentTimeStamp = getUnixTimestamp9(/* @__PURE__ */ new Date());
|
|
12100
12591
|
circuitInputs.claimSubjectProfileNonce = BigInt(params.credentialSubjectProfileNonce);
|
|
12101
12592
|
circuitInputs.profileNonce = BigInt(params.authProfileNonce);
|
|
12102
12593
|
circuitInputs.skipClaimRevocationCheck = params.skipRevocation;
|
|
@@ -12127,7 +12618,7 @@ var InputGenerator = class {
|
|
|
12127
12618
|
const query = circuitQueries[0];
|
|
12128
12619
|
query.operator = this.transformV2QueryOperator(query.operator);
|
|
12129
12620
|
circuitInputs.query = query;
|
|
12130
|
-
circuitInputs.currentTimeStamp =
|
|
12621
|
+
circuitInputs.currentTimeStamp = getUnixTimestamp9(/* @__PURE__ */ new Date());
|
|
12131
12622
|
this.checkOperatorSupport(proofReq.circuitId, query.operator);
|
|
12132
12623
|
return circuitInputs.inputsMarshal();
|
|
12133
12624
|
};
|
|
@@ -12160,7 +12651,7 @@ var InputGenerator = class {
|
|
|
12160
12651
|
circuitInputs.skipClaimRevocationCheck = params.skipRevocation;
|
|
12161
12652
|
const query = circuitQueries[0];
|
|
12162
12653
|
circuitInputs.query = query;
|
|
12163
|
-
circuitInputs.currentTimeStamp =
|
|
12654
|
+
circuitInputs.currentTimeStamp = getUnixTimestamp9(/* @__PURE__ */ new Date());
|
|
12164
12655
|
if (authClaimData.treeState) {
|
|
12165
12656
|
circuitInputs.treeState = {
|
|
12166
12657
|
state: authClaimData.treeState?.state,
|
|
@@ -12230,7 +12721,7 @@ var InputGenerator = class {
|
|
|
12230
12721
|
const query = circuitQueries[0];
|
|
12231
12722
|
query.values = [16 /* SD */, 0 /* NOOP */].includes(query.operator) ? [] : query.values;
|
|
12232
12723
|
circuitInputs.query = query;
|
|
12233
|
-
circuitInputs.currentTimeStamp =
|
|
12724
|
+
circuitInputs.currentTimeStamp = getUnixTimestamp9(/* @__PURE__ */ new Date());
|
|
12234
12725
|
circuitInputs.proofType = proofType;
|
|
12235
12726
|
circuitInputs.linkNonce = params.linkNonce ?? BigInt(0);
|
|
12236
12727
|
circuitInputs.verifierID = params.verifierDid ? DID23.idFromDID(params.verifierDid) : void 0;
|
|
@@ -12282,7 +12773,7 @@ var InputGenerator = class {
|
|
|
12282
12773
|
const query = circuitQueries[0];
|
|
12283
12774
|
query.values = [16 /* SD */, 0 /* NOOP */].includes(query.operator) ? [] : query.values;
|
|
12284
12775
|
circuitInputs.query = query;
|
|
12285
|
-
circuitInputs.currentTimeStamp =
|
|
12776
|
+
circuitInputs.currentTimeStamp = getUnixTimestamp9(/* @__PURE__ */ new Date());
|
|
12286
12777
|
circuitInputs.proofType = proofType;
|
|
12287
12778
|
circuitInputs.linkNonce = params.linkNonce ?? BigInt(0);
|
|
12288
12779
|
circuitInputs.verifierID = params.verifierDid ? DID23.idFromDID(params.verifierDid) : void 0;
|
|
@@ -13280,26 +13771,22 @@ var ProofService = class {
|
|
|
13280
13771
|
}
|
|
13281
13772
|
/** {@inheritdoc IProofService.generateAuthProof} */
|
|
13282
13773
|
async generateAuthProof(circuitId, identifier, opts) {
|
|
13774
|
+
if (circuitId !== "authV2" /* AuthV2 */ && circuitId !== "authV3" /* AuthV3 */ && circuitId !== "authV3-8-32" /* AuthV3_8_32 */) {
|
|
13775
|
+
throw new Error("CircuitId is not supported");
|
|
13776
|
+
}
|
|
13283
13777
|
if (!opts) {
|
|
13284
13778
|
opts = {
|
|
13285
13779
|
challenge: 0n
|
|
13286
13780
|
};
|
|
13287
13781
|
}
|
|
13288
|
-
|
|
13289
|
-
|
|
13290
|
-
|
|
13291
|
-
|
|
13292
|
-
|
|
13293
|
-
|
|
13294
|
-
|
|
13295
|
-
|
|
13296
|
-
circuitId,
|
|
13297
|
-
proof: zkProof.proof,
|
|
13298
|
-
pub_signals: zkProof.pub_signals
|
|
13299
|
-
};
|
|
13300
|
-
default:
|
|
13301
|
-
throw new Error(`CircuitId ${circuitId} is not supported`);
|
|
13302
|
-
}
|
|
13782
|
+
const challenge = opts.challenge ? BytesHelper8.intToBytes(opts.challenge).reverse() : new Uint8Array(32);
|
|
13783
|
+
const authInputs = await this.generateAuthInputs(challenge, identifier, circuitId);
|
|
13784
|
+
const zkProof = await this._prover.generate(authInputs, circuitId);
|
|
13785
|
+
return {
|
|
13786
|
+
circuitId,
|
|
13787
|
+
proof: zkProof.proof,
|
|
13788
|
+
pub_signals: zkProof.pub_signals
|
|
13789
|
+
};
|
|
13303
13790
|
}
|
|
13304
13791
|
/** {@inheritdoc IProofService.transitState} */
|
|
13305
13792
|
async transitState(did, oldTreeState, isOldStateGenesis, stateStorage, ethSigner) {
|
|
@@ -13390,23 +13877,60 @@ var ProofService = class {
|
|
|
13390
13877
|
authInputs.gistProof = gistProof;
|
|
13391
13878
|
return authInputs.inputsMarshal();
|
|
13392
13879
|
}
|
|
13880
|
+
/** {@inheritdoc IProofService.generateAuthInputs} */
|
|
13881
|
+
async generateAuthInputs(hash, did, circuitId) {
|
|
13882
|
+
if (circuitId !== "authV2" /* AuthV2 */ && circuitId !== "authV3" /* AuthV3 */ && circuitId !== "authV3-8-32" /* AuthV3_8_32 */) {
|
|
13883
|
+
throw new Error("CircuitId is not supported");
|
|
13884
|
+
}
|
|
13885
|
+
const { nonce: authProfileNonce, genesisDID } = await this._identityWallet.getGenesisDIDMetadata(did);
|
|
13886
|
+
const challenge = BytesHelper8.bytesToInt(hash.reverse());
|
|
13887
|
+
const authPrepared = await this._inputsGenerator.prepareAuthBJJCredential(genesisDID);
|
|
13888
|
+
const signature = await this._identityWallet.signChallenge(challenge, authPrepared.credential);
|
|
13889
|
+
const id = DID26.idFromDID(genesisDID);
|
|
13890
|
+
const stateProof = await this._stateStorage.getGISTProof(id.bigInt());
|
|
13891
|
+
const gistProof = toGISTProof(stateProof);
|
|
13892
|
+
const authInputs = new AuthV3Inputs();
|
|
13893
|
+
if (circuitId === "authV3-8-32" /* AuthV3_8_32 */) {
|
|
13894
|
+
authInputs.mtLevel = 8;
|
|
13895
|
+
authInputs.mtLevelOnChain = 32;
|
|
13896
|
+
}
|
|
13897
|
+
authInputs.genesisID = id;
|
|
13898
|
+
authInputs.profileNonce = BigInt(authProfileNonce);
|
|
13899
|
+
authInputs.authClaim = authPrepared.coreClaim;
|
|
13900
|
+
authInputs.authClaimIncMtp = authPrepared.incProof.proof;
|
|
13901
|
+
authInputs.authClaimNonRevMtp = authPrepared.nonRevProof.proof;
|
|
13902
|
+
authInputs.treeState = authPrepared.incProof.treeState;
|
|
13903
|
+
authInputs.signature = signature;
|
|
13904
|
+
authInputs.challenge = challenge;
|
|
13905
|
+
authInputs.gistProof = gistProof;
|
|
13906
|
+
return authInputs.inputsMarshal();
|
|
13907
|
+
}
|
|
13393
13908
|
/** {@inheritdoc IProofService.generateAuthV2Proof} */
|
|
13394
13909
|
async generateAuthV2Proof(challenge, did) {
|
|
13395
|
-
const authInputs = await this.
|
|
13910
|
+
const authInputs = await this.generateAuthInputs(challenge, did, "authV2" /* AuthV2 */);
|
|
13396
13911
|
const zkProof = await this._prover.generate(authInputs, "authV2" /* AuthV2 */);
|
|
13397
13912
|
return zkProof;
|
|
13398
13913
|
}
|
|
13399
13914
|
async verifyState(circuitId, pubSignals, opts = {
|
|
13400
13915
|
acceptedStateTransitionDelay: constants_exports.DEFAULT_AUTH_VERIFY_DELAY
|
|
13401
13916
|
}) {
|
|
13402
|
-
if (circuitId !== "authV2" /* AuthV2 */) {
|
|
13917
|
+
if (circuitId !== "authV2" /* AuthV2 */ && circuitId !== "authV3" /* AuthV3 */ && circuitId !== "authV3-8-32" /* AuthV3_8_32 */) {
|
|
13403
13918
|
throw new Error(`CircuitId is not supported ${circuitId}`);
|
|
13404
13919
|
}
|
|
13405
|
-
|
|
13406
|
-
|
|
13407
|
-
|
|
13408
|
-
|
|
13409
|
-
|
|
13920
|
+
let gistRoot, userId;
|
|
13921
|
+
if (circuitId === "authV2" /* AuthV2 */) {
|
|
13922
|
+
const authV2PubSignals = new AuthV2PubSignals().pubSignalsUnmarshal(
|
|
13923
|
+
byteEncoder.encode(JSON.stringify(pubSignals))
|
|
13924
|
+
);
|
|
13925
|
+
gistRoot = authV2PubSignals.GISTRoot.bigInt();
|
|
13926
|
+
userId = authV2PubSignals.userID.bigInt();
|
|
13927
|
+
} else {
|
|
13928
|
+
const authV3PubSignals = new AuthV3PubSignals().pubSignalsUnmarshal(
|
|
13929
|
+
byteEncoder.encode(JSON.stringify(pubSignals))
|
|
13930
|
+
);
|
|
13931
|
+
gistRoot = authV3PubSignals.GISTRoot.bigInt();
|
|
13932
|
+
userId = authV3PubSignals.userID.bigInt();
|
|
13933
|
+
}
|
|
13410
13934
|
const globalStateInfo = await this._stateStorage.getGISTRootInfo(gistRoot, userId);
|
|
13411
13935
|
if (globalStateInfo.root !== gistRoot) {
|
|
13412
13936
|
throw new Error(`gist info contains invalid state`);
|
|
@@ -13477,7 +14001,7 @@ var IdentityWallet = class {
|
|
|
13477
14001
|
async createAuthCoreClaim(revNonce, seed) {
|
|
13478
14002
|
const keyId = await this._kms.createKeyFromSeed("BJJ" /* BabyJubJub */, seed);
|
|
13479
14003
|
const pubKeyHex = await this._kms.publicKey(keyId);
|
|
13480
|
-
const pubKey =
|
|
14004
|
+
const pubKey = PublicKey5.newFromHex(pubKeyHex);
|
|
13481
14005
|
const schemaHash = SchemaHash7.authSchemaHash;
|
|
13482
14006
|
const authClaim = Claim9.newClaim(
|
|
13483
14007
|
schemaHash,
|
|
@@ -13489,7 +14013,7 @@ var IdentityWallet = class {
|
|
|
13489
14013
|
}
|
|
13490
14014
|
async createAuthBJJCredential(did, pubKey, authClaim, currentState, revocationOpts) {
|
|
13491
14015
|
const authData = authClaim.getExpirationDate();
|
|
13492
|
-
const expiration = authData ?
|
|
14016
|
+
const expiration = authData ? getUnixTimestamp10(authData) : 0;
|
|
13493
14017
|
const request = {
|
|
13494
14018
|
credentialSchema: VerifiableConstants.AUTH.AUTH_BJJ_CREDENTIAL_SCHEMA_JSON_URL,
|
|
13495
14019
|
type: VerifiableConstants.AUTH.AUTH_BJJ_CREDENTIAL_TYPE,
|
|
@@ -14260,6 +14784,8 @@ export {
|
|
|
14260
14784
|
AuthMethod,
|
|
14261
14785
|
AuthV2Inputs,
|
|
14262
14786
|
AuthV2PubSignals,
|
|
14787
|
+
AuthV3Inputs,
|
|
14788
|
+
AuthV3PubSignals,
|
|
14263
14789
|
BJJSignatureProof2021,
|
|
14264
14790
|
BaseConfig,
|
|
14265
14791
|
BjjProvider,
|
|
@@ -14354,9 +14880,16 @@ export {
|
|
|
14354
14880
|
RefreshServiceType,
|
|
14355
14881
|
RevocationStatusHandler,
|
|
14356
14882
|
SDK_EVENTS,
|
|
14883
|
+
SOLANA_CHAIN_REF,
|
|
14357
14884
|
Scalar,
|
|
14358
14885
|
SearchError,
|
|
14359
14886
|
Sec256k1Provider,
|
|
14887
|
+
SolanaNativePaymentRequest,
|
|
14888
|
+
SolanaNativePaymentSchema,
|
|
14889
|
+
SolanaPaymentInstruction,
|
|
14890
|
+
SolanaPaymentInstructionSchema,
|
|
14891
|
+
SolanaSplPaymentRequest,
|
|
14892
|
+
SolanaSplPaymentSchema,
|
|
14360
14893
|
StandardJSONCredentialsQueryFilter,
|
|
14361
14894
|
StateTransitionInputs,
|
|
14362
14895
|
StateTransitionPubSignals,
|
|
@@ -14372,6 +14905,7 @@ export {
|
|
|
14372
14905
|
W3CCredential,
|
|
14373
14906
|
XSDNS,
|
|
14374
14907
|
ZKPPacker,
|
|
14908
|
+
acceptHasProvingMethodAlg,
|
|
14375
14909
|
availableTypesOperators,
|
|
14376
14910
|
base58ToBytes,
|
|
14377
14911
|
base64ToBytes,
|
|
@@ -14379,8 +14913,11 @@ export {
|
|
|
14379
14913
|
bigIntArrayToStringArray,
|
|
14380
14914
|
bigIntCompare,
|
|
14381
14915
|
buildAccept,
|
|
14916
|
+
buildAcceptFromProvingMethodAlg,
|
|
14382
14917
|
buildDIDFromEthPubKey,
|
|
14918
|
+
buildEvmPayment,
|
|
14383
14919
|
buildFieldPath,
|
|
14920
|
+
buildSolanaPayment,
|
|
14384
14921
|
buildTreeState,
|
|
14385
14922
|
buildVerifierId,
|
|
14386
14923
|
byteDecoder,
|
|
@@ -14423,6 +14960,7 @@ export {
|
|
|
14423
14960
|
defaultMTLevels,
|
|
14424
14961
|
defaultMTLevelsClaim,
|
|
14425
14962
|
defaultMTLevelsOnChain,
|
|
14963
|
+
defaultProvingMethodAlg,
|
|
14426
14964
|
defaultValueArraySize,
|
|
14427
14965
|
defineMerklizedRootPosition,
|
|
14428
14966
|
encodeBase64url,
|
|
@@ -14445,6 +14983,7 @@ export {
|
|
|
14445
14983
|
getOperatorNameByValue,
|
|
14446
14984
|
getPermitSignature,
|
|
14447
14985
|
getProperties,
|
|
14986
|
+
getProvingMethodAlgFromJWZ,
|
|
14448
14987
|
getSerializationAttrFromContext,
|
|
14449
14988
|
getSerializationAttrFromParsedContext,
|
|
14450
14989
|
getUserDIDFromCredential,
|
|
@@ -14478,6 +15017,7 @@ export {
|
|
|
14478
15017
|
resolveDidDocument,
|
|
14479
15018
|
resolvePath,
|
|
14480
15019
|
resolveVerificationMethods,
|
|
15020
|
+
serializeSolanaPaymentInstruction,
|
|
14481
15021
|
strMTHex,
|
|
14482
15022
|
stringByPath,
|
|
14483
15023
|
subjectPositionIndex,
|
|
@@ -14499,6 +15039,7 @@ export {
|
|
|
14499
15039
|
verifyExpiresTime,
|
|
14500
15040
|
verifyFieldValueInclusionNativeExistsSupport,
|
|
14501
15041
|
verifyFieldValueInclusionV2,
|
|
15042
|
+
verifyIden3SolanaPaymentRequest,
|
|
14502
15043
|
witnessBuilder
|
|
14503
15044
|
};
|
|
14504
15045
|
//# sourceMappingURL=index.js.map
|