@0xpolygonid/js-sdk 1.33.1 → 1.33.3
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 +1118 -718
- 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 +1325 -914
- package/dist/node/cjs/index.cjs.map +1 -1
- package/dist/node/esm/index.js +1118 -718
- package/dist/node/esm/index.js.map +1 -1
- package/dist/types/iden3comm/handlers/credential-proposal.d.ts.map +1 -1
- package/dist/types/iden3comm/handlers/payment.d.ts +14 -5
- package/dist/types/iden3comm/handlers/payment.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/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 +5 -1
- package/src/iden3comm/handlers/credential-proposal.ts +4 -1
- package/src/iden3comm/handlers/payment.ts +138 -131
- package/src/iden3comm/types/protocol/payment.ts +79 -10
- 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
package/dist/node/cjs/index.cjs
CHANGED
|
@@ -144,9 +144,16 @@ __export(index_exports, {
|
|
|
144
144
|
RefreshServiceType: () => RefreshServiceType,
|
|
145
145
|
RevocationStatusHandler: () => RevocationStatusHandler,
|
|
146
146
|
SDK_EVENTS: () => SDK_EVENTS,
|
|
147
|
+
SOLANA_CHAIN_REF: () => SOLANA_CHAIN_REF,
|
|
147
148
|
Scalar: () => Scalar,
|
|
148
149
|
SearchError: () => SearchError,
|
|
149
150
|
Sec256k1Provider: () => Sec256k1Provider,
|
|
151
|
+
SolanaNativePaymentRequest: () => SolanaNativePaymentRequest,
|
|
152
|
+
SolanaNativePaymentSchema: () => SolanaNativePaymentSchema,
|
|
153
|
+
SolanaPaymentInstruction: () => SolanaPaymentInstruction,
|
|
154
|
+
SolanaPaymentInstructionSchema: () => SolanaPaymentInstructionSchema,
|
|
155
|
+
SolanaSplPaymentRequest: () => SolanaSplPaymentRequest,
|
|
156
|
+
SolanaSplPaymentSchema: () => SolanaSplPaymentSchema,
|
|
150
157
|
StandardJSONCredentialsQueryFilter: () => StandardJSONCredentialsQueryFilter,
|
|
151
158
|
StateTransitionInputs: () => StateTransitionInputs,
|
|
152
159
|
StateTransitionPubSignals: () => StateTransitionPubSignals,
|
|
@@ -170,7 +177,9 @@ __export(index_exports, {
|
|
|
170
177
|
bigIntCompare: () => bigIntCompare,
|
|
171
178
|
buildAccept: () => buildAccept,
|
|
172
179
|
buildDIDFromEthPubKey: () => buildDIDFromEthPubKey,
|
|
180
|
+
buildEvmPayment: () => buildEvmPayment,
|
|
173
181
|
buildFieldPath: () => buildFieldPath,
|
|
182
|
+
buildSolanaPayment: () => buildSolanaPayment,
|
|
174
183
|
buildTreeState: () => buildTreeState,
|
|
175
184
|
buildVerifierId: () => buildVerifierId,
|
|
176
185
|
byteDecoder: () => byteDecoder,
|
|
@@ -268,6 +277,7 @@ __export(index_exports, {
|
|
|
268
277
|
resolveDidDocument: () => resolveDidDocument,
|
|
269
278
|
resolvePath: () => resolvePath,
|
|
270
279
|
resolveVerificationMethods: () => resolveVerificationMethods,
|
|
280
|
+
serializeSolanaPaymentInstruction: () => serializeSolanaPaymentInstruction,
|
|
271
281
|
strMTHex: () => strMTHex,
|
|
272
282
|
stringByPath: () => stringByPath,
|
|
273
283
|
subjectPositionIndex: () => subjectPositionIndex,
|
|
@@ -289,6 +299,7 @@ __export(index_exports, {
|
|
|
289
299
|
verifyExpiresTime: () => verifyExpiresTime,
|
|
290
300
|
verifyFieldValueInclusionNativeExistsSupport: () => verifyFieldValueInclusionNativeExistsSupport,
|
|
291
301
|
verifyFieldValueInclusionV2: () => verifyFieldValueInclusionV2,
|
|
302
|
+
verifyIden3SolanaPaymentRequest: () => verifyIden3SolanaPaymentRequest,
|
|
292
303
|
witnessBuilder: () => witnessBuilder
|
|
293
304
|
});
|
|
294
305
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -380,8 +391,8 @@ var KMS = class {
|
|
|
380
391
|
};
|
|
381
392
|
|
|
382
393
|
// src/kms/key-providers/bjj-provider.ts
|
|
383
|
-
var
|
|
384
|
-
var
|
|
394
|
+
var import_js_crypto6 = require("@iden3/js-crypto");
|
|
395
|
+
var import_js_iden3_core8 = require("@iden3/js-iden3-core");
|
|
385
396
|
|
|
386
397
|
// src/kms/store/abstract-key-store.ts
|
|
387
398
|
var AbstractPrivateKeyStore = class {
|
|
@@ -775,629 +786,370 @@ var bigIntCompare = (a, b) => {
|
|
|
775
786
|
return 0;
|
|
776
787
|
};
|
|
777
788
|
|
|
778
|
-
// src/
|
|
779
|
-
var
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
789
|
+
// src/utils/payments/solana.ts
|
|
790
|
+
var import_borsh = require("borsh");
|
|
791
|
+
var import_ed25519 = require("@noble/curves/ed25519");
|
|
792
|
+
|
|
793
|
+
// src/verifiable/proof.ts
|
|
794
|
+
var import_js_merkletree2 = require("@iden3/js-merkletree");
|
|
795
|
+
|
|
796
|
+
// src/verifiable/constants.ts
|
|
797
|
+
var VerifiableConstants = Object.freeze({
|
|
798
|
+
ERRORS: {
|
|
799
|
+
FiELD_IS_EMPTY: "fieldPath is empty",
|
|
800
|
+
CONTEXT_TYPE_IS_EMPTY: "ctxType is empty",
|
|
801
|
+
// ErrStateNotFound issuer state is genesis state.
|
|
802
|
+
IDENTITY_DOES_NOT_EXIST: "Identity does not exist",
|
|
803
|
+
IDENTITY_DOES_NOT_EXIST_CUSTOM_ERROR: "IdentityDoesNotExist",
|
|
804
|
+
NO_AUTH_CRED_FOUND: "no auth credentials found",
|
|
805
|
+
STATE_DOES_NOT_EXIST: "State does not exist",
|
|
806
|
+
STATE_DOES_NOT_EXIST_CUSTOM_ERROR: "StateDoesNotExist",
|
|
807
|
+
ROOT_DOES_NOT_EXIST: "Root does not exist",
|
|
808
|
+
ROOT_DOES_NOT_EXIST_CUSTOM_ERROR: "RootDoesNotExist",
|
|
809
|
+
// identity wallet
|
|
810
|
+
ID_WALLET_NO_CREDENTIAL_SATISFIED_QUERY: "no credential satisfied query",
|
|
811
|
+
ID_WALLET_SIGNER_IS_REQUIRED: "Ethereum signer is required to create Ethereum identities in order to transit state",
|
|
812
|
+
ID_WALLET_PROVER_IS_REQUIRED: "prover is required to generate proofs for non ethereum identities",
|
|
813
|
+
ID_WALLET_CORE_CLAIM_REQUIRED_IN_SIG_PROOF: "credential must have coreClaim representation in the signature proof",
|
|
814
|
+
ID_WALLET_CORE_CLAIM_REQUIRED_IN_ANY_PROOF: "credential must have coreClaim representation in proofs",
|
|
815
|
+
ID_WALLET_CORE_CLAIM_MISMATCH: "core claim representations is set in both proofs but they are not equal",
|
|
816
|
+
ID_WALLET_CORE_CLAIM_IS_NOT_SET: "core claim is not set in credential proofs",
|
|
817
|
+
ID_WALLET_PROFILE_OR_IDENTITY_NOT_FOUND: "profile or identity not found",
|
|
818
|
+
ID_WALLET_PROFILE_ALREADY_EXISTS: "profile with given nonce or verifier already exists",
|
|
819
|
+
ID_WALLET_PROFILE_ALREADY_EXISTS_VERIFIER_TAGS: "profile with given verifier and tags already exists",
|
|
820
|
+
ID_WALLET_ISSUER_AUTH_BJJ_CRED_MUST_HAVE_ANY_PROOF: "issuer auth credential must have proof",
|
|
821
|
+
ID_WALLET_ISSUER_AUTH_BJJ_CRED_MUST_HAVE_MTP_PROOF: "mtp is required for auth bjj key to issue new credentials",
|
|
822
|
+
// proof service
|
|
823
|
+
PROOF_SERVICE_NO_CREDENTIAL_FOR_IDENTITY_OR_PROFILE: "no credentials belong to did or its profiles",
|
|
824
|
+
PROOF_SERVICE_NO_CREDENTIAL_FOR_QUERY: "credential not found for query",
|
|
825
|
+
PROOF_SERVICE_PROFILE_GENESIS_DID_MISMATCH: "subject and auth profiles are not derived from the same did",
|
|
826
|
+
PROOF_SERVICE_NO_QUERIES_IN_ZKP_REQUEST: "no queries in zkp request",
|
|
827
|
+
// credential wallet
|
|
828
|
+
CREDENTIAL_WALLET_ALL_CREDENTIALS_ARE_REVOKED: "all claims are revoked"
|
|
829
|
+
},
|
|
830
|
+
CREDENTIAL_TYPE: {
|
|
831
|
+
// VerifiableCredential is a W3C verifiable credential type
|
|
832
|
+
W3C_VERIFIABLE_CREDENTIAL: "VerifiableCredential",
|
|
833
|
+
W3C_VERIFIABLE_PRESENTATION: "VerifiablePresentation"
|
|
834
|
+
},
|
|
835
|
+
CREDENTIAL_SUBJECT_PATH: "https://www.w3.org/2018/credentials#credentialSubject",
|
|
836
|
+
JSONLD_SCHEMA: {
|
|
837
|
+
// JSONLDSchemaIden3Credential is a schema for context with Iden3Credential type
|
|
838
|
+
IDEN3_CREDENTIAL: "https://schema.iden3.io/core/jsonld/iden3proofs.jsonld",
|
|
839
|
+
// JSONLDSchemaIden3DisplayMethod is a schema for context with Iden3BasicDisplayMethodV1 type
|
|
840
|
+
IDEN3_DISPLAY_METHOD: "https://schema.iden3.io/core/jsonld/displayMethod.jsonld",
|
|
841
|
+
// JSONLDSchemaW3CCredential2018 is a schema for context with VerifiableCredential type
|
|
842
|
+
W3C_CREDENTIAL_2018: "https://www.w3.org/2018/credentials/v1",
|
|
843
|
+
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"}}}`,
|
|
844
|
+
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"}}`,
|
|
845
|
+
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"}}}}`
|
|
846
|
+
},
|
|
847
|
+
// JsonSchema2023 JSON schema for verification of Iden3Credential
|
|
848
|
+
JSON_SCHEMA_VALIDATOR: "JsonSchema2023",
|
|
849
|
+
SERVICE_TYPE: {
|
|
850
|
+
// Iden3CommServiceType is service type for iden3comm protocol
|
|
851
|
+
IDEN3_COMM: "iden3-communication",
|
|
852
|
+
// PushNotificationServiceType is service type for delivering push notifications to identity
|
|
853
|
+
PUSH_NOTIFICATION: "push-notification"
|
|
854
|
+
},
|
|
855
|
+
AUTH: {
|
|
856
|
+
AUTH_BJJ_CREDENTIAL_HASH: "013fd3f623559d850fb5b02ff012d0e2",
|
|
857
|
+
AUTH_BJJ_CREDENTIAL_SCHEMA_JSON_URL: "https://schema.iden3.io/core/json/auth.json",
|
|
858
|
+
AUTH_BJJ_CREDENTIAL_SCHEMA_JSONLD_URL: "https://schema.iden3.io/core/jsonld/auth.jsonld",
|
|
859
|
+
AUTH_BJJ_CREDENTIAL_TYPE: "AuthBJJCredential",
|
|
860
|
+
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"}}}}}`,
|
|
861
|
+
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"}}}}}}]}`
|
|
805
862
|
}
|
|
863
|
+
});
|
|
864
|
+
var ProofType = /* @__PURE__ */ ((ProofType2) => {
|
|
865
|
+
ProofType2["BJJSignature"] = "BJJSignature2021";
|
|
866
|
+
ProofType2["Iden3SparseMerkleTreeProof"] = "Iden3SparseMerkleTreeProof";
|
|
867
|
+
return ProofType2;
|
|
868
|
+
})(ProofType || {});
|
|
869
|
+
var CredentialStatusType = /* @__PURE__ */ ((CredentialStatusType2) => {
|
|
870
|
+
CredentialStatusType2["SparseMerkleTreeProof"] = "SparseMerkleTreeProof";
|
|
871
|
+
CredentialStatusType2["Iden3ReverseSparseMerkleTreeProof"] = "Iden3ReverseSparseMerkleTreeProof";
|
|
872
|
+
CredentialStatusType2["Iden3commRevocationStatusV1"] = "Iden3commRevocationStatusV1.0";
|
|
873
|
+
CredentialStatusType2["Iden3OnchainSparseMerkleTreeProof2023"] = "Iden3OnchainSparseMerkleTreeProof2023";
|
|
874
|
+
return CredentialStatusType2;
|
|
875
|
+
})(CredentialStatusType || {});
|
|
876
|
+
var ProofPurpose = /* @__PURE__ */ ((ProofPurpose2) => {
|
|
877
|
+
ProofPurpose2["Authentication"] = "Authentication";
|
|
878
|
+
return ProofPurpose2;
|
|
879
|
+
})(ProofPurpose || {});
|
|
880
|
+
var MerklizedRootPosition = /* @__PURE__ */ ((MerklizedRootPosition4) => {
|
|
881
|
+
MerklizedRootPosition4["Index"] = "index";
|
|
882
|
+
MerklizedRootPosition4["Value"] = "value";
|
|
883
|
+
MerklizedRootPosition4["None"] = "";
|
|
884
|
+
return MerklizedRootPosition4;
|
|
885
|
+
})(MerklizedRootPosition || {});
|
|
886
|
+
var SubjectPosition = /* @__PURE__ */ ((SubjectPosition2) => {
|
|
887
|
+
SubjectPosition2["None"] = "";
|
|
888
|
+
SubjectPosition2["Index"] = "index";
|
|
889
|
+
SubjectPosition2["Value"] = "value";
|
|
890
|
+
return SubjectPosition2;
|
|
891
|
+
})(SubjectPosition || {});
|
|
892
|
+
var RefreshServiceType = /* @__PURE__ */ ((RefreshServiceType2) => {
|
|
893
|
+
RefreshServiceType2["Iden3RefreshService2023"] = "Iden3RefreshService2023";
|
|
894
|
+
return RefreshServiceType2;
|
|
895
|
+
})(RefreshServiceType || {});
|
|
896
|
+
var PaymentRequestDataType = /* @__PURE__ */ ((PaymentRequestDataType2) => {
|
|
897
|
+
PaymentRequestDataType2["Iden3PaymentRequestCryptoV1"] = "Iden3PaymentRequestCryptoV1";
|
|
898
|
+
PaymentRequestDataType2["Iden3PaymentRailsRequestV1"] = "Iden3PaymentRailsRequestV1";
|
|
899
|
+
PaymentRequestDataType2["Iden3PaymentRailsERC20RequestV1"] = "Iden3PaymentRailsERC20RequestV1";
|
|
900
|
+
PaymentRequestDataType2["Iden3PaymentRailsSolanaRequestV1"] = "Iden3PaymentRailsSolanaRequestV1";
|
|
901
|
+
PaymentRequestDataType2["Iden3PaymentRailsSolanaSPLRequestV1"] = "Iden3PaymentRailsSolanaSPLRequestV1";
|
|
902
|
+
return PaymentRequestDataType2;
|
|
903
|
+
})(PaymentRequestDataType || {});
|
|
904
|
+
var PaymentType = /* @__PURE__ */ ((PaymentType2) => {
|
|
905
|
+
PaymentType2["Iden3PaymentCryptoV1"] = "Iden3PaymentCryptoV1";
|
|
906
|
+
PaymentType2["Iden3PaymentRailsV1"] = "Iden3PaymentRailsV1";
|
|
907
|
+
PaymentType2["Iden3PaymentRailsERC20V1"] = "Iden3PaymentRailsERC20V1";
|
|
908
|
+
PaymentType2["Iden3PaymentRailsSolanaV1"] = "Iden3PaymentRailsSolanaV1";
|
|
909
|
+
PaymentType2["Iden3PaymentRailsSolanaSPLV1"] = "Iden3PaymentRailsSolanaSPLV1";
|
|
910
|
+
return PaymentType2;
|
|
911
|
+
})(PaymentType || {});
|
|
912
|
+
var SupportedPaymentProofType = /* @__PURE__ */ ((SupportedPaymentProofType2) => {
|
|
913
|
+
SupportedPaymentProofType2["EthereumEip712Signature2021"] = "EthereumEip712Signature2021";
|
|
914
|
+
SupportedPaymentProofType2["SolanaEd25519Signature2025"] = "SolanaEd25519Signature2025";
|
|
915
|
+
return SupportedPaymentProofType2;
|
|
916
|
+
})(SupportedPaymentProofType || {});
|
|
917
|
+
var SupportedCurrencies = /* @__PURE__ */ ((SupportedCurrencies2) => {
|
|
918
|
+
SupportedCurrencies2["ETH"] = "ETH";
|
|
919
|
+
SupportedCurrencies2["ETH_WEI"] = "ETHWEI";
|
|
920
|
+
SupportedCurrencies2["ETH_GWEI"] = "ETHGWEI";
|
|
921
|
+
SupportedCurrencies2["MATIC"] = "MATIC";
|
|
922
|
+
SupportedCurrencies2["POL"] = "POL";
|
|
923
|
+
return SupportedCurrencies2;
|
|
924
|
+
})(SupportedCurrencies || {});
|
|
925
|
+
var PaymentFeatures = /* @__PURE__ */ ((PaymentFeatures2) => {
|
|
926
|
+
PaymentFeatures2["EIP_2612"] = "EIP-2612";
|
|
927
|
+
return PaymentFeatures2;
|
|
928
|
+
})(PaymentFeatures || {});
|
|
929
|
+
var DisplayMethodType = /* @__PURE__ */ ((DisplayMethodType2) => {
|
|
930
|
+
DisplayMethodType2["Iden3BasicDisplayMethodV1"] = "Iden3BasicDisplayMethodV1";
|
|
931
|
+
return DisplayMethodType2;
|
|
932
|
+
})(DisplayMethodType || {});
|
|
933
|
+
var DEFAULT_CACHE_MAX_SIZE = 1e4;
|
|
934
|
+
var SOLANA_CHAIN_REF = Object.freeze({
|
|
935
|
+
DEVNET: "EtWTRABZaYq6iMfeYKouRu166VU2xqa1",
|
|
936
|
+
TESTNET: "4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z",
|
|
937
|
+
MAINNET: "5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp"
|
|
938
|
+
});
|
|
939
|
+
|
|
940
|
+
// src/verifiable/proof.ts
|
|
941
|
+
var import_js_crypto3 = require("@iden3/js-crypto");
|
|
942
|
+
var import_js_iden3_core2 = require("@iden3/js-iden3-core");
|
|
943
|
+
var Iden3SparseMerkleTreeProof = class _Iden3SparseMerkleTreeProof {
|
|
944
|
+
type;
|
|
945
|
+
issuerData;
|
|
946
|
+
mtp;
|
|
947
|
+
coreClaim;
|
|
806
948
|
/**
|
|
807
|
-
*
|
|
808
|
-
* @param {
|
|
809
|
-
* @returns kms key identifier
|
|
949
|
+
* Creates an instance of Iden3SparseMerkleTreeProof.
|
|
950
|
+
* @param {object} obj
|
|
810
951
|
*/
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
const publicKey = privateKey.public();
|
|
817
|
-
const kmsId = {
|
|
818
|
-
type: this.keyType,
|
|
819
|
-
id: keyPath(this.keyType, publicKey.hex())
|
|
820
|
-
};
|
|
821
|
-
await this.keyStore.importKey({ alias: kmsId.id, key: privateKey.hex() });
|
|
822
|
-
return kmsId;
|
|
952
|
+
constructor(obj) {
|
|
953
|
+
this.coreClaim = obj.coreClaim;
|
|
954
|
+
this.issuerData = obj.issuerData;
|
|
955
|
+
this.type = "Iden3SparseMerkleTreeProof" /* Iden3SparseMerkleTreeProof */;
|
|
956
|
+
this.mtp = obj.mtp;
|
|
823
957
|
}
|
|
824
958
|
/**
|
|
825
|
-
* Gets public key by kmsKeyId
|
|
826
959
|
*
|
|
827
|
-
* @param {KmsKeyId} keyId - key identifier
|
|
828
|
-
*/
|
|
829
|
-
async publicKey(keyId) {
|
|
830
|
-
const privateKey = await this.privateKey(keyId);
|
|
831
|
-
return privateKey.public().hex();
|
|
832
|
-
}
|
|
833
|
-
/**
|
|
834
|
-
* signs prepared payload of size,
|
|
835
|
-
* with a key id
|
|
836
960
|
*
|
|
837
|
-
* @
|
|
838
|
-
* @param {Uint8Array} data - data to sign (32 bytes)
|
|
839
|
-
* @returns Uint8Array signature
|
|
961
|
+
* @returns `json object in serialized presentation`
|
|
840
962
|
*/
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
const publicKey = await this.publicKey(keyId);
|
|
859
|
-
return import_js_crypto3.PublicKey.newFromCompressed(hexToBytes(publicKey)).verifyPoseidon(
|
|
860
|
-
import_js_iden3_core2.BytesHelper.bytesToInt(message),
|
|
861
|
-
import_js_crypto3.Signature.newFromCompressed(hexToBytes(signatureHex))
|
|
862
|
-
);
|
|
963
|
+
toJSON() {
|
|
964
|
+
const issuerId = this.issuerData.id;
|
|
965
|
+
return {
|
|
966
|
+
issuerData: {
|
|
967
|
+
id: issuerId.string(),
|
|
968
|
+
state: {
|
|
969
|
+
...this.issuerData.state,
|
|
970
|
+
rootOfRoots: this.issuerData.state.rootOfRoots.hex(),
|
|
971
|
+
claimsTreeRoot: this.issuerData.state.claimsTreeRoot.hex(),
|
|
972
|
+
revocationTreeRoot: this.issuerData.state.revocationTreeRoot.hex(),
|
|
973
|
+
value: this.issuerData.state.value.hex()
|
|
974
|
+
}
|
|
975
|
+
},
|
|
976
|
+
type: this.type,
|
|
977
|
+
coreClaim: this.coreClaim.hex(),
|
|
978
|
+
mtp: this.mtp.toJSON()
|
|
979
|
+
};
|
|
863
980
|
}
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
return allKeysFromKeyStore.filter((key) => key.alias.startsWith(this.keyType));
|
|
885
|
-
}
|
|
886
|
-
/**
|
|
887
|
-
* generates a ed25519 key from a seed phrase
|
|
888
|
-
* @param {Uint8Array} seed - byte array seed
|
|
889
|
-
* @returns {Promise<KmsKeyId>} kms key identifier
|
|
890
|
-
*/
|
|
891
|
-
async newPrivateKeyFromSeed(seed) {
|
|
892
|
-
if (seed.length !== 32) {
|
|
893
|
-
throw new Error("Seed should be 32 bytes");
|
|
981
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
982
|
+
static fromJSON(obj) {
|
|
983
|
+
let mtp;
|
|
984
|
+
if (obj?.mtp?.notEmpties && obj?.mtp?.depth && obj?.mtp?.siblings) {
|
|
985
|
+
const ne = obj?.mtp?.notEmpties;
|
|
986
|
+
const notEmpties = ne instanceof Uint8Array ? ne : new Uint8Array(Object.values(ne));
|
|
987
|
+
const siblingsHashes = obj?.mtp?.siblings.map(
|
|
988
|
+
(h) => import_js_merkletree2.Hash.fromString(JSON.stringify(h))
|
|
989
|
+
);
|
|
990
|
+
const allSiblings = import_js_merkletree2.Proof.buildAllSiblings(obj?.mtp?.depth, notEmpties, siblingsHashes);
|
|
991
|
+
let nodeAux = obj.mtp.nodeAux || obj.mtp.node_aux;
|
|
992
|
+
if (nodeAux) {
|
|
993
|
+
nodeAux = {
|
|
994
|
+
key: import_js_merkletree2.Hash.fromString(JSON.stringify(nodeAux.key)),
|
|
995
|
+
value: import_js_merkletree2.Hash.fromString(JSON.stringify(nodeAux.value))
|
|
996
|
+
};
|
|
997
|
+
}
|
|
998
|
+
mtp = new import_js_merkletree2.Proof({ existence: obj?.mtp.existence, nodeAux, siblings: allSiblings });
|
|
999
|
+
} else {
|
|
1000
|
+
mtp = import_js_merkletree2.Proof.fromJSON(obj.mtp);
|
|
894
1001
|
}
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
1002
|
+
return new _Iden3SparseMerkleTreeProof({
|
|
1003
|
+
coreClaim: new import_js_iden3_core2.Claim().fromHex(obj.coreClaim),
|
|
1004
|
+
mtp,
|
|
1005
|
+
issuerData: {
|
|
1006
|
+
id: import_js_iden3_core2.DID.parse(obj.issuerData.id),
|
|
1007
|
+
state: {
|
|
1008
|
+
...obj.issuerData.state,
|
|
1009
|
+
rootOfRoots: import_js_merkletree2.Hash.fromHex(obj.issuerData.state.rootOfRoots),
|
|
1010
|
+
claimsTreeRoot: import_js_merkletree2.Hash.fromHex(obj.issuerData.state.claimsTreeRoot),
|
|
1011
|
+
revocationTreeRoot: import_js_merkletree2.Hash.fromHex(obj.issuerData.state.revocationTreeRoot),
|
|
1012
|
+
value: import_js_merkletree2.Hash.fromHex(obj.issuerData.state.value)
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
903
1015
|
});
|
|
904
|
-
return kmsId;
|
|
905
|
-
}
|
|
906
|
-
/**
|
|
907
|
-
* Gets public key by kmsKeyId
|
|
908
|
-
* @param {KmsKeyId} keyId - key identifier
|
|
909
|
-
* @returns {Promise<string>} Public key as a hex string
|
|
910
|
-
*/
|
|
911
|
-
async publicKey(keyId) {
|
|
912
|
-
const privateKeyHex = await this.privateKey(keyId);
|
|
913
|
-
const publicKey = import_ed25519.ed25519.getPublicKey(privateKeyHex);
|
|
914
|
-
return bytesToHex(publicKey);
|
|
915
1016
|
}
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
1017
|
+
};
|
|
1018
|
+
var BJJSignatureProof2021 = class _BJJSignatureProof2021 {
|
|
1019
|
+
type;
|
|
1020
|
+
issuerData;
|
|
1021
|
+
signature;
|
|
1022
|
+
coreClaim;
|
|
1023
|
+
constructor(obj) {
|
|
1024
|
+
this.type = "BJJSignature2021" /* BJJSignature */;
|
|
1025
|
+
this.issuerData = obj.issuerData;
|
|
1026
|
+
this.coreClaim = obj.coreClaim;
|
|
1027
|
+
this.signature = obj.signature;
|
|
926
1028
|
}
|
|
927
1029
|
/**
|
|
928
|
-
*
|
|
929
|
-
*
|
|
930
|
-
* @
|
|
931
|
-
* @param keyId - The key identifier to use for verification.
|
|
932
|
-
* @returns A Promise that resolves to a boolean indicating whether the signature is valid.
|
|
1030
|
+
* toJSON is a method to serialize BJJSignatureProof2021 to json
|
|
1031
|
+
*
|
|
1032
|
+
* @returns `json object in serialized presentation`
|
|
933
1033
|
*/
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
1034
|
+
toJSON() {
|
|
1035
|
+
return {
|
|
1036
|
+
issuerData: {
|
|
1037
|
+
id: this.issuerData.id.string(),
|
|
1038
|
+
state: {
|
|
1039
|
+
...this.issuerData.state,
|
|
1040
|
+
rootOfRoots: this.issuerData.state.rootOfRoots.hex(),
|
|
1041
|
+
claimsTreeRoot: this.issuerData.state.claimsTreeRoot.hex(),
|
|
1042
|
+
revocationTreeRoot: this.issuerData.state.revocationTreeRoot.hex(),
|
|
1043
|
+
value: this.issuerData.state.value.hex()
|
|
1044
|
+
},
|
|
1045
|
+
mtp: this.issuerData.mtp.toJSON(),
|
|
1046
|
+
authCoreClaim: this.issuerData.authCoreClaim.hex(),
|
|
1047
|
+
credentialStatus: this.issuerData.credentialStatus
|
|
1048
|
+
},
|
|
1049
|
+
type: this.type,
|
|
1050
|
+
coreClaim: this.coreClaim.hex(),
|
|
1051
|
+
signature: import_js_crypto3.Hex.encodeString(this.signature.compress())
|
|
1052
|
+
};
|
|
937
1053
|
}
|
|
938
1054
|
/**
|
|
939
|
-
*
|
|
940
|
-
* @param
|
|
941
|
-
* @returns {Promise<string>} The private key associated with the keyId.
|
|
1055
|
+
* fromJSON is a method to deserialize BJJSignatureProof2021 from json
|
|
1056
|
+
* @param obj
|
|
942
1057
|
*/
|
|
943
|
-
|
|
944
|
-
|
|
1058
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1059
|
+
static fromJSON(obj) {
|
|
1060
|
+
return new _BJJSignatureProof2021({
|
|
1061
|
+
issuerData: {
|
|
1062
|
+
id: import_js_iden3_core2.DID.parse(obj.issuerData.id),
|
|
1063
|
+
mtp: import_js_merkletree2.Proof.fromJSON(obj.issuerData.mtp),
|
|
1064
|
+
state: {
|
|
1065
|
+
...obj.issuerData.state,
|
|
1066
|
+
rootOfRoots: import_js_merkletree2.Hash.fromHex(obj.issuerData.state.rootOfRoots),
|
|
1067
|
+
claimsTreeRoot: import_js_merkletree2.Hash.fromHex(obj.issuerData.state.claimsTreeRoot),
|
|
1068
|
+
revocationTreeRoot: import_js_merkletree2.Hash.fromHex(obj.issuerData.state.revocationTreeRoot),
|
|
1069
|
+
value: import_js_merkletree2.Hash.fromHex(obj.issuerData.state.value)
|
|
1070
|
+
},
|
|
1071
|
+
credentialStatus: obj.issuerData.credentialStatus,
|
|
1072
|
+
authCoreClaim: new import_js_iden3_core2.Claim().fromHex(obj.issuerData.authCoreClaim)
|
|
1073
|
+
},
|
|
1074
|
+
coreClaim: new import_js_iden3_core2.Claim().fromHex(obj.coreClaim),
|
|
1075
|
+
signature: import_js_crypto3.Signature.newFromCompressed(
|
|
1076
|
+
Uint8Array.from(import_js_crypto3.Hex.decodeString(obj.signature)).slice(0, 64)
|
|
1077
|
+
)
|
|
1078
|
+
});
|
|
945
1079
|
}
|
|
946
1080
|
};
|
|
947
1081
|
|
|
948
|
-
// src/
|
|
949
|
-
var
|
|
1082
|
+
// src/verifiable/credential.ts
|
|
1083
|
+
var import_js_iden3_core5 = require("@iden3/js-iden3-core");
|
|
1084
|
+
var import_js_merkletree3 = require("@iden3/js-merkletree");
|
|
1085
|
+
var import_js_jsonld_merklization2 = require("@iden3/js-jsonld-merklization");
|
|
1086
|
+
var import_js_crypto5 = require("@iden3/js-crypto");
|
|
1087
|
+
|
|
1088
|
+
// src/credentials/utils.ts
|
|
1089
|
+
var import_js_iden3_core3 = require("@iden3/js-iden3-core");
|
|
950
1090
|
var import_js_crypto4 = require("@iden3/js-crypto");
|
|
951
|
-
var
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
* key type that is handled by BJJ Provider
|
|
955
|
-
* @type {KmsKeyType}
|
|
956
|
-
*/
|
|
957
|
-
keyType;
|
|
958
|
-
_keyStore;
|
|
959
|
-
/**
|
|
960
|
-
* Creates an instance of BjjProvider.
|
|
961
|
-
* @param {KmsKeyType} keyType - kms key type
|
|
962
|
-
* @param {AbstractPrivateKeyStore} keyStore - key store for kms
|
|
963
|
-
*/
|
|
964
|
-
constructor(keyType, keyStore) {
|
|
965
|
-
if (keyType !== "Secp256k1" /* Secp256k1 */) {
|
|
966
|
-
throw new Error("Key type must be Secp256k1");
|
|
967
|
-
}
|
|
968
|
-
this.keyType = keyType;
|
|
969
|
-
this._keyStore = keyStore;
|
|
970
|
-
}
|
|
971
|
-
/**
|
|
972
|
-
* get all keys
|
|
973
|
-
* @returns list of keys
|
|
974
|
-
*/
|
|
975
|
-
async list() {
|
|
976
|
-
const allKeysFromKeyStore = await this._keyStore.list();
|
|
977
|
-
return allKeysFromKeyStore.filter((key) => key.alias.startsWith(this.keyType));
|
|
978
|
-
}
|
|
979
|
-
/**
|
|
980
|
-
* generates a baby jub jub key from a seed phrase
|
|
981
|
-
* @param {Uint8Array} seed - byte array seed
|
|
982
|
-
* @returns kms key identifier
|
|
983
|
-
*/
|
|
984
|
-
async newPrivateKeyFromSeed(seed) {
|
|
985
|
-
if (seed.length !== 32) {
|
|
986
|
-
throw new Error("Seed should be 32 bytes");
|
|
987
|
-
}
|
|
988
|
-
const publicKey = import_secp256k1.secp256k1.getPublicKey(seed);
|
|
989
|
-
const kmsId = {
|
|
990
|
-
type: this.keyType,
|
|
991
|
-
id: keyPath(this.keyType, bytesToHex(publicKey))
|
|
992
|
-
};
|
|
993
|
-
await this._keyStore.importKey({
|
|
994
|
-
alias: kmsId.id,
|
|
995
|
-
key: bytesToHex(seed).padStart(64, "0")
|
|
996
|
-
});
|
|
997
|
-
return kmsId;
|
|
998
|
-
}
|
|
999
|
-
/**
|
|
1000
|
-
* Gets public key by kmsKeyId
|
|
1001
|
-
*
|
|
1002
|
-
* @param {KmsKeyId} keyId - key identifier
|
|
1003
|
-
*/
|
|
1004
|
-
async publicKey(keyId) {
|
|
1005
|
-
const privateKeyHex = await this.privateKey(keyId);
|
|
1006
|
-
const publicKey = import_secp256k1.secp256k1.getPublicKey(privateKeyHex, false);
|
|
1007
|
-
return bytesToHex(publicKey);
|
|
1008
|
-
}
|
|
1009
|
-
/**
|
|
1010
|
-
* Signs the given data using the private key associated with the specified key identifier.
|
|
1011
|
-
* @param keyId - The key identifier to use for signing.
|
|
1012
|
-
* @param data - The data to sign.
|
|
1013
|
-
* @param opts - Signing options, such as the algorithm to use.
|
|
1014
|
-
* @returns A Promise that resolves to the signature as a Uint8Array.
|
|
1015
|
-
*/
|
|
1016
|
-
async sign(keyId, data, opts = { alg: "ES256K" }) {
|
|
1017
|
-
const privateKeyHex = await this.privateKey(keyId);
|
|
1018
|
-
const signatureBase64 = await (0, import_did_jwt.ES256KSigner)(
|
|
1019
|
-
(0, import_did_jwt.hexToBytes)(privateKeyHex),
|
|
1020
|
-
opts.alg === "ES256K-R"
|
|
1021
|
-
)(data);
|
|
1022
|
-
if (typeof signatureBase64 !== "string") {
|
|
1023
|
-
throw new Error("signatureBase64 must be a string");
|
|
1024
|
-
}
|
|
1025
|
-
return base64UrlToBytes(signatureBase64);
|
|
1091
|
+
var getUserDIDFromCredential = (issuerDID, credential) => {
|
|
1092
|
+
if (!credential.credentialSubject.id) {
|
|
1093
|
+
return issuerDID;
|
|
1026
1094
|
}
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
* @param message - The message to verify the signature against.
|
|
1030
|
-
* @param signatureHex - The signature to verify, as a hexadecimal string.
|
|
1031
|
-
* @param keyId - The key identifier to use for verification.
|
|
1032
|
-
* @returns A Promise that resolves to a boolean indicating whether the signature is valid.
|
|
1033
|
-
*/
|
|
1034
|
-
async verify(message, signatureHex, keyId) {
|
|
1035
|
-
const publicKeyHex = await this.publicKey(keyId);
|
|
1036
|
-
return import_secp256k1.secp256k1.verify(signatureHex, (0, import_js_crypto4.sha256)(message), publicKeyHex);
|
|
1095
|
+
if (typeof credential.credentialSubject.id !== "string") {
|
|
1096
|
+
throw new Error("credential subject `id` is not a string");
|
|
1037
1097
|
}
|
|
1038
|
-
|
|
1039
|
-
|
|
1098
|
+
return import_js_iden3_core3.DID.parse(credential.credentialSubject.id);
|
|
1099
|
+
};
|
|
1100
|
+
var getKMSIdByAuthCredential = (credential) => {
|
|
1101
|
+
if (!credential.type.includes("AuthBJJCredential")) {
|
|
1102
|
+
throw new Error("can't sign with not AuthBJJCredential credential");
|
|
1040
1103
|
}
|
|
1104
|
+
const x = credential.credentialSubject["x"];
|
|
1105
|
+
const y = credential.credentialSubject["y"];
|
|
1106
|
+
const pb = new import_js_crypto4.PublicKey([BigInt(x), BigInt(y)]);
|
|
1107
|
+
const kp = keyPath("BJJ" /* BabyJubJub */, pb.hex());
|
|
1108
|
+
return { type: "BJJ" /* BabyJubJub */, id: kp };
|
|
1041
1109
|
};
|
|
1042
1110
|
|
|
1043
|
-
// src/
|
|
1044
|
-
var
|
|
1045
|
-
var
|
|
1046
|
-
var
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
var
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
var
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
var
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
IDENTITY_DOES_NOT_EXIST: "Identity does not exist",
|
|
1061
|
-
IDENTITY_DOES_NOT_EXIST_CUSTOM_ERROR: "IdentityDoesNotExist",
|
|
1062
|
-
NO_AUTH_CRED_FOUND: "no auth credentials found",
|
|
1063
|
-
STATE_DOES_NOT_EXIST: "State does not exist",
|
|
1064
|
-
STATE_DOES_NOT_EXIST_CUSTOM_ERROR: "StateDoesNotExist",
|
|
1065
|
-
ROOT_DOES_NOT_EXIST: "Root does not exist",
|
|
1066
|
-
ROOT_DOES_NOT_EXIST_CUSTOM_ERROR: "RootDoesNotExist",
|
|
1067
|
-
// identity wallet
|
|
1068
|
-
ID_WALLET_NO_CREDENTIAL_SATISFIED_QUERY: "no credential satisfied query",
|
|
1069
|
-
ID_WALLET_SIGNER_IS_REQUIRED: "Ethereum signer is required to create Ethereum identities in order to transit state",
|
|
1070
|
-
ID_WALLET_PROVER_IS_REQUIRED: "prover is required to generate proofs for non ethereum identities",
|
|
1071
|
-
ID_WALLET_CORE_CLAIM_REQUIRED_IN_SIG_PROOF: "credential must have coreClaim representation in the signature proof",
|
|
1072
|
-
ID_WALLET_CORE_CLAIM_REQUIRED_IN_ANY_PROOF: "credential must have coreClaim representation in proofs",
|
|
1073
|
-
ID_WALLET_CORE_CLAIM_MISMATCH: "core claim representations is set in both proofs but they are not equal",
|
|
1074
|
-
ID_WALLET_CORE_CLAIM_IS_NOT_SET: "core claim is not set in credential proofs",
|
|
1075
|
-
ID_WALLET_PROFILE_OR_IDENTITY_NOT_FOUND: "profile or identity not found",
|
|
1076
|
-
ID_WALLET_PROFILE_ALREADY_EXISTS: "profile with given nonce or verifier already exists",
|
|
1077
|
-
ID_WALLET_PROFILE_ALREADY_EXISTS_VERIFIER_TAGS: "profile with given verifier and tags already exists",
|
|
1078
|
-
ID_WALLET_ISSUER_AUTH_BJJ_CRED_MUST_HAVE_ANY_PROOF: "issuer auth credential must have proof",
|
|
1079
|
-
ID_WALLET_ISSUER_AUTH_BJJ_CRED_MUST_HAVE_MTP_PROOF: "mtp is required for auth bjj key to issue new credentials",
|
|
1080
|
-
// proof service
|
|
1081
|
-
PROOF_SERVICE_NO_CREDENTIAL_FOR_IDENTITY_OR_PROFILE: "no credentials belong to did or its profiles",
|
|
1082
|
-
PROOF_SERVICE_NO_CREDENTIAL_FOR_QUERY: "credential not found for query",
|
|
1083
|
-
PROOF_SERVICE_PROFILE_GENESIS_DID_MISMATCH: "subject and auth profiles are not derived from the same did",
|
|
1084
|
-
PROOF_SERVICE_NO_QUERIES_IN_ZKP_REQUEST: "no queries in zkp request",
|
|
1085
|
-
// credential wallet
|
|
1086
|
-
CREDENTIAL_WALLET_ALL_CREDENTIALS_ARE_REVOKED: "all claims are revoked"
|
|
1087
|
-
},
|
|
1088
|
-
CREDENTIAL_TYPE: {
|
|
1089
|
-
// VerifiableCredential is a W3C verifiable credential type
|
|
1090
|
-
W3C_VERIFIABLE_CREDENTIAL: "VerifiableCredential",
|
|
1091
|
-
W3C_VERIFIABLE_PRESENTATION: "VerifiablePresentation"
|
|
1092
|
-
},
|
|
1093
|
-
CREDENTIAL_SUBJECT_PATH: "https://www.w3.org/2018/credentials#credentialSubject",
|
|
1094
|
-
JSONLD_SCHEMA: {
|
|
1095
|
-
// JSONLDSchemaIden3Credential is a schema for context with Iden3Credential type
|
|
1096
|
-
IDEN3_CREDENTIAL: "https://schema.iden3.io/core/jsonld/iden3proofs.jsonld",
|
|
1097
|
-
// JSONLDSchemaIden3DisplayMethod is a schema for context with Iden3BasicDisplayMethodV1 type
|
|
1098
|
-
IDEN3_DISPLAY_METHOD: "https://schema.iden3.io/core/jsonld/displayMethod.jsonld",
|
|
1099
|
-
// JSONLDSchemaW3CCredential2018 is a schema for context with VerifiableCredential type
|
|
1100
|
-
W3C_CREDENTIAL_2018: "https://www.w3.org/2018/credentials/v1",
|
|
1101
|
-
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"}}}`,
|
|
1102
|
-
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"}}`,
|
|
1103
|
-
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"}}}}`
|
|
1104
|
-
},
|
|
1105
|
-
// JsonSchema2023 JSON schema for verification of Iden3Credential
|
|
1106
|
-
JSON_SCHEMA_VALIDATOR: "JsonSchema2023",
|
|
1107
|
-
SERVICE_TYPE: {
|
|
1108
|
-
// Iden3CommServiceType is service type for iden3comm protocol
|
|
1109
|
-
IDEN3_COMM: "iden3-communication",
|
|
1110
|
-
// PushNotificationServiceType is service type for delivering push notifications to identity
|
|
1111
|
-
PUSH_NOTIFICATION: "push-notification"
|
|
1112
|
-
},
|
|
1113
|
-
AUTH: {
|
|
1114
|
-
AUTH_BJJ_CREDENTIAL_HASH: "013fd3f623559d850fb5b02ff012d0e2",
|
|
1115
|
-
AUTH_BJJ_CREDENTIAL_SCHEMA_JSON_URL: "https://schema.iden3.io/core/json/auth.json",
|
|
1116
|
-
AUTH_BJJ_CREDENTIAL_SCHEMA_JSONLD_URL: "https://schema.iden3.io/core/jsonld/auth.jsonld",
|
|
1117
|
-
AUTH_BJJ_CREDENTIAL_TYPE: "AuthBJJCredential",
|
|
1118
|
-
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"}}}}}`,
|
|
1119
|
-
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"}}}}}}]}`
|
|
1120
|
-
}
|
|
1121
|
-
});
|
|
1122
|
-
var ProofType = /* @__PURE__ */ ((ProofType2) => {
|
|
1123
|
-
ProofType2["BJJSignature"] = "BJJSignature2021";
|
|
1124
|
-
ProofType2["Iden3SparseMerkleTreeProof"] = "Iden3SparseMerkleTreeProof";
|
|
1125
|
-
return ProofType2;
|
|
1126
|
-
})(ProofType || {});
|
|
1127
|
-
var CredentialStatusType = /* @__PURE__ */ ((CredentialStatusType2) => {
|
|
1128
|
-
CredentialStatusType2["SparseMerkleTreeProof"] = "SparseMerkleTreeProof";
|
|
1129
|
-
CredentialStatusType2["Iden3ReverseSparseMerkleTreeProof"] = "Iden3ReverseSparseMerkleTreeProof";
|
|
1130
|
-
CredentialStatusType2["Iden3commRevocationStatusV1"] = "Iden3commRevocationStatusV1.0";
|
|
1131
|
-
CredentialStatusType2["Iden3OnchainSparseMerkleTreeProof2023"] = "Iden3OnchainSparseMerkleTreeProof2023";
|
|
1132
|
-
return CredentialStatusType2;
|
|
1133
|
-
})(CredentialStatusType || {});
|
|
1134
|
-
var ProofPurpose = /* @__PURE__ */ ((ProofPurpose2) => {
|
|
1135
|
-
ProofPurpose2["Authentication"] = "Authentication";
|
|
1136
|
-
return ProofPurpose2;
|
|
1137
|
-
})(ProofPurpose || {});
|
|
1138
|
-
var MerklizedRootPosition = /* @__PURE__ */ ((MerklizedRootPosition4) => {
|
|
1139
|
-
MerklizedRootPosition4["Index"] = "index";
|
|
1140
|
-
MerklizedRootPosition4["Value"] = "value";
|
|
1141
|
-
MerklizedRootPosition4["None"] = "";
|
|
1142
|
-
return MerklizedRootPosition4;
|
|
1143
|
-
})(MerklizedRootPosition || {});
|
|
1144
|
-
var SubjectPosition = /* @__PURE__ */ ((SubjectPosition2) => {
|
|
1145
|
-
SubjectPosition2["None"] = "";
|
|
1146
|
-
SubjectPosition2["Index"] = "index";
|
|
1147
|
-
SubjectPosition2["Value"] = "value";
|
|
1148
|
-
return SubjectPosition2;
|
|
1149
|
-
})(SubjectPosition || {});
|
|
1150
|
-
var RefreshServiceType = /* @__PURE__ */ ((RefreshServiceType2) => {
|
|
1151
|
-
RefreshServiceType2["Iden3RefreshService2023"] = "Iden3RefreshService2023";
|
|
1152
|
-
return RefreshServiceType2;
|
|
1153
|
-
})(RefreshServiceType || {});
|
|
1154
|
-
var PaymentRequestDataType = /* @__PURE__ */ ((PaymentRequestDataType2) => {
|
|
1155
|
-
PaymentRequestDataType2["Iden3PaymentRequestCryptoV1"] = "Iden3PaymentRequestCryptoV1";
|
|
1156
|
-
PaymentRequestDataType2["Iden3PaymentRailsRequestV1"] = "Iden3PaymentRailsRequestV1";
|
|
1157
|
-
PaymentRequestDataType2["Iden3PaymentRailsERC20RequestV1"] = "Iden3PaymentRailsERC20RequestV1";
|
|
1158
|
-
return PaymentRequestDataType2;
|
|
1159
|
-
})(PaymentRequestDataType || {});
|
|
1160
|
-
var PaymentType = /* @__PURE__ */ ((PaymentType2) => {
|
|
1161
|
-
PaymentType2["Iden3PaymentCryptoV1"] = "Iden3PaymentCryptoV1";
|
|
1162
|
-
PaymentType2["Iden3PaymentRailsV1"] = "Iden3PaymentRailsV1";
|
|
1163
|
-
PaymentType2["Iden3PaymentRailsERC20V1"] = "Iden3PaymentRailsERC20V1";
|
|
1164
|
-
return PaymentType2;
|
|
1165
|
-
})(PaymentType || {});
|
|
1166
|
-
var SupportedPaymentProofType = /* @__PURE__ */ ((SupportedPaymentProofType2) => {
|
|
1167
|
-
SupportedPaymentProofType2["EthereumEip712Signature2021"] = "EthereumEip712Signature2021";
|
|
1168
|
-
return SupportedPaymentProofType2;
|
|
1169
|
-
})(SupportedPaymentProofType || {});
|
|
1170
|
-
var SupportedCurrencies = /* @__PURE__ */ ((SupportedCurrencies2) => {
|
|
1171
|
-
SupportedCurrencies2["ETH"] = "ETH";
|
|
1172
|
-
SupportedCurrencies2["ETH_WEI"] = "ETHWEI";
|
|
1173
|
-
SupportedCurrencies2["ETH_GWEI"] = "ETHGWEI";
|
|
1174
|
-
SupportedCurrencies2["MATIC"] = "MATIC";
|
|
1175
|
-
SupportedCurrencies2["POL"] = "POL";
|
|
1176
|
-
return SupportedCurrencies2;
|
|
1177
|
-
})(SupportedCurrencies || {});
|
|
1178
|
-
var PaymentFeatures = /* @__PURE__ */ ((PaymentFeatures2) => {
|
|
1179
|
-
PaymentFeatures2["EIP_2612"] = "EIP-2612";
|
|
1180
|
-
return PaymentFeatures2;
|
|
1181
|
-
})(PaymentFeatures || {});
|
|
1182
|
-
var DisplayMethodType = /* @__PURE__ */ ((DisplayMethodType2) => {
|
|
1183
|
-
DisplayMethodType2["Iden3BasicDisplayMethodV1"] = "Iden3BasicDisplayMethodV1";
|
|
1184
|
-
return DisplayMethodType2;
|
|
1185
|
-
})(DisplayMethodType || {});
|
|
1186
|
-
var DEFAULT_CACHE_MAX_SIZE = 1e4;
|
|
1187
|
-
|
|
1188
|
-
// src/verifiable/proof.ts
|
|
1189
|
-
var import_js_crypto5 = require("@iden3/js-crypto");
|
|
1190
|
-
var import_js_iden3_core3 = require("@iden3/js-iden3-core");
|
|
1191
|
-
var Iden3SparseMerkleTreeProof = class _Iden3SparseMerkleTreeProof {
|
|
1192
|
-
type;
|
|
1193
|
-
issuerData;
|
|
1194
|
-
mtp;
|
|
1195
|
-
coreClaim;
|
|
1196
|
-
/**
|
|
1197
|
-
* Creates an instance of Iden3SparseMerkleTreeProof.
|
|
1198
|
-
* @param {object} obj
|
|
1199
|
-
*/
|
|
1200
|
-
constructor(obj) {
|
|
1201
|
-
this.coreClaim = obj.coreClaim;
|
|
1202
|
-
this.issuerData = obj.issuerData;
|
|
1203
|
-
this.type = "Iden3SparseMerkleTreeProof" /* Iden3SparseMerkleTreeProof */;
|
|
1204
|
-
this.mtp = obj.mtp;
|
|
1111
|
+
// src/verifiable/core-utils.ts
|
|
1112
|
+
var import_js_iden3_core4 = require("@iden3/js-iden3-core");
|
|
1113
|
+
var import_js_jsonld_merklization = require("@iden3/js-jsonld-merklization");
|
|
1114
|
+
var import_jsonld = __toESM(require("jsonld"), 1);
|
|
1115
|
+
var import_ethers2 = require("ethers");
|
|
1116
|
+
var credentialSubjectKey = "credentialSubject";
|
|
1117
|
+
var contextFullKey = "@context";
|
|
1118
|
+
var serializationFullKey = "iden3_serialization";
|
|
1119
|
+
var fieldPrefix = "iden3:v1:";
|
|
1120
|
+
var credentialSubjectFullKey = "https://www.w3.org/2018/credentials#credentialSubject";
|
|
1121
|
+
var verifiableCredentialFullKey = "https://www.w3.org/2018/credentials#VerifiableCredential";
|
|
1122
|
+
var typeFullKey = "@type";
|
|
1123
|
+
var getFieldSlotIndex = async (field, typeName, schemaBytes) => {
|
|
1124
|
+
let ctxDoc = JSON.parse(byteDecoder.decode(schemaBytes));
|
|
1125
|
+
ctxDoc = ctxDoc[contextFullKey];
|
|
1126
|
+
if (ctxDoc === void 0) {
|
|
1127
|
+
throw new Error("document has no @context");
|
|
1205
1128
|
}
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
...this.issuerData.state,
|
|
1218
|
-
rootOfRoots: this.issuerData.state.rootOfRoots.hex(),
|
|
1219
|
-
claimsTreeRoot: this.issuerData.state.claimsTreeRoot.hex(),
|
|
1220
|
-
revocationTreeRoot: this.issuerData.state.revocationTreeRoot.hex(),
|
|
1221
|
-
value: this.issuerData.state.value.hex()
|
|
1222
|
-
}
|
|
1223
|
-
},
|
|
1224
|
-
type: this.type,
|
|
1225
|
-
coreClaim: this.coreClaim.hex(),
|
|
1226
|
-
mtp: this.mtp.toJSON()
|
|
1227
|
-
};
|
|
1129
|
+
const ldCtx = await import_jsonld.default.processContext(
|
|
1130
|
+
await import_jsonld.default.processContext(null, null, {}),
|
|
1131
|
+
ctxDoc,
|
|
1132
|
+
{}
|
|
1133
|
+
);
|
|
1134
|
+
const serAttr = await getSerializationAttrFromParsedContext(
|
|
1135
|
+
ldCtx,
|
|
1136
|
+
typeName
|
|
1137
|
+
);
|
|
1138
|
+
if (!serAttr) {
|
|
1139
|
+
throw new Error("serialization attribute is not set");
|
|
1228
1140
|
}
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
nodeAux = {
|
|
1242
|
-
key: import_js_merkletree2.Hash.fromString(JSON.stringify(nodeAux.key)),
|
|
1243
|
-
value: import_js_merkletree2.Hash.fromString(JSON.stringify(nodeAux.value))
|
|
1244
|
-
};
|
|
1245
|
-
}
|
|
1246
|
-
mtp = new import_js_merkletree2.Proof({ existence: obj?.mtp.existence, nodeAux, siblings: allSiblings });
|
|
1247
|
-
} else {
|
|
1248
|
-
mtp = import_js_merkletree2.Proof.fromJSON(obj.mtp);
|
|
1249
|
-
}
|
|
1250
|
-
return new _Iden3SparseMerkleTreeProof({
|
|
1251
|
-
coreClaim: new import_js_iden3_core3.Claim().fromHex(obj.coreClaim),
|
|
1252
|
-
mtp,
|
|
1253
|
-
issuerData: {
|
|
1254
|
-
id: import_js_iden3_core3.DID.parse(obj.issuerData.id),
|
|
1255
|
-
state: {
|
|
1256
|
-
...obj.issuerData.state,
|
|
1257
|
-
rootOfRoots: import_js_merkletree2.Hash.fromHex(obj.issuerData.state.rootOfRoots),
|
|
1258
|
-
claimsTreeRoot: import_js_merkletree2.Hash.fromHex(obj.issuerData.state.claimsTreeRoot),
|
|
1259
|
-
revocationTreeRoot: import_js_merkletree2.Hash.fromHex(obj.issuerData.state.revocationTreeRoot),
|
|
1260
|
-
value: import_js_merkletree2.Hash.fromHex(obj.issuerData.state.value)
|
|
1261
|
-
}
|
|
1262
|
-
}
|
|
1263
|
-
});
|
|
1264
|
-
}
|
|
1265
|
-
};
|
|
1266
|
-
var BJJSignatureProof2021 = class _BJJSignatureProof2021 {
|
|
1267
|
-
type;
|
|
1268
|
-
issuerData;
|
|
1269
|
-
signature;
|
|
1270
|
-
coreClaim;
|
|
1271
|
-
constructor(obj) {
|
|
1272
|
-
this.type = "BJJSignature2021" /* BJJSignature */;
|
|
1273
|
-
this.issuerData = obj.issuerData;
|
|
1274
|
-
this.coreClaim = obj.coreClaim;
|
|
1275
|
-
this.signature = obj.signature;
|
|
1276
|
-
}
|
|
1277
|
-
/**
|
|
1278
|
-
* toJSON is a method to serialize BJJSignatureProof2021 to json
|
|
1279
|
-
*
|
|
1280
|
-
* @returns `json object in serialized presentation`
|
|
1281
|
-
*/
|
|
1282
|
-
toJSON() {
|
|
1283
|
-
return {
|
|
1284
|
-
issuerData: {
|
|
1285
|
-
id: this.issuerData.id.string(),
|
|
1286
|
-
state: {
|
|
1287
|
-
...this.issuerData.state,
|
|
1288
|
-
rootOfRoots: this.issuerData.state.rootOfRoots.hex(),
|
|
1289
|
-
claimsTreeRoot: this.issuerData.state.claimsTreeRoot.hex(),
|
|
1290
|
-
revocationTreeRoot: this.issuerData.state.revocationTreeRoot.hex(),
|
|
1291
|
-
value: this.issuerData.state.value.hex()
|
|
1292
|
-
},
|
|
1293
|
-
mtp: this.issuerData.mtp.toJSON(),
|
|
1294
|
-
authCoreClaim: this.issuerData.authCoreClaim.hex(),
|
|
1295
|
-
credentialStatus: this.issuerData.credentialStatus
|
|
1296
|
-
},
|
|
1297
|
-
type: this.type,
|
|
1298
|
-
coreClaim: this.coreClaim.hex(),
|
|
1299
|
-
signature: import_js_crypto5.Hex.encodeString(this.signature.compress())
|
|
1300
|
-
};
|
|
1301
|
-
}
|
|
1302
|
-
/**
|
|
1303
|
-
* fromJSON is a method to deserialize BJJSignatureProof2021 from json
|
|
1304
|
-
* @param obj
|
|
1305
|
-
*/
|
|
1306
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1307
|
-
static fromJSON(obj) {
|
|
1308
|
-
return new _BJJSignatureProof2021({
|
|
1309
|
-
issuerData: {
|
|
1310
|
-
id: import_js_iden3_core3.DID.parse(obj.issuerData.id),
|
|
1311
|
-
mtp: import_js_merkletree2.Proof.fromJSON(obj.issuerData.mtp),
|
|
1312
|
-
state: {
|
|
1313
|
-
...obj.issuerData.state,
|
|
1314
|
-
rootOfRoots: import_js_merkletree2.Hash.fromHex(obj.issuerData.state.rootOfRoots),
|
|
1315
|
-
claimsTreeRoot: import_js_merkletree2.Hash.fromHex(obj.issuerData.state.claimsTreeRoot),
|
|
1316
|
-
revocationTreeRoot: import_js_merkletree2.Hash.fromHex(obj.issuerData.state.revocationTreeRoot),
|
|
1317
|
-
value: import_js_merkletree2.Hash.fromHex(obj.issuerData.state.value)
|
|
1318
|
-
},
|
|
1319
|
-
credentialStatus: obj.issuerData.credentialStatus,
|
|
1320
|
-
authCoreClaim: new import_js_iden3_core3.Claim().fromHex(obj.issuerData.authCoreClaim)
|
|
1321
|
-
},
|
|
1322
|
-
coreClaim: new import_js_iden3_core3.Claim().fromHex(obj.coreClaim),
|
|
1323
|
-
signature: import_js_crypto5.Signature.newFromCompressed(
|
|
1324
|
-
Uint8Array.from(import_js_crypto5.Hex.decodeString(obj.signature)).slice(0, 64)
|
|
1325
|
-
)
|
|
1326
|
-
});
|
|
1327
|
-
}
|
|
1328
|
-
};
|
|
1329
|
-
|
|
1330
|
-
// src/verifiable/credential.ts
|
|
1331
|
-
var import_js_iden3_core6 = require("@iden3/js-iden3-core");
|
|
1332
|
-
var import_js_merkletree3 = require("@iden3/js-merkletree");
|
|
1333
|
-
var import_js_jsonld_merklization2 = require("@iden3/js-jsonld-merklization");
|
|
1334
|
-
var import_js_crypto7 = require("@iden3/js-crypto");
|
|
1335
|
-
|
|
1336
|
-
// src/credentials/utils.ts
|
|
1337
|
-
var import_js_iden3_core4 = require("@iden3/js-iden3-core");
|
|
1338
|
-
var import_js_crypto6 = require("@iden3/js-crypto");
|
|
1339
|
-
var getUserDIDFromCredential = (issuerDID, credential) => {
|
|
1340
|
-
if (!credential.credentialSubject.id) {
|
|
1341
|
-
return issuerDID;
|
|
1342
|
-
}
|
|
1343
|
-
if (typeof credential.credentialSubject.id !== "string") {
|
|
1344
|
-
throw new Error("credential subject `id` is not a string");
|
|
1345
|
-
}
|
|
1346
|
-
return import_js_iden3_core4.DID.parse(credential.credentialSubject.id);
|
|
1347
|
-
};
|
|
1348
|
-
var getKMSIdByAuthCredential = (credential) => {
|
|
1349
|
-
if (!credential.type.includes("AuthBJJCredential")) {
|
|
1350
|
-
throw new Error("can't sign with not AuthBJJCredential credential");
|
|
1351
|
-
}
|
|
1352
|
-
const x = credential.credentialSubject["x"];
|
|
1353
|
-
const y = credential.credentialSubject["y"];
|
|
1354
|
-
const pb = new import_js_crypto6.PublicKey([BigInt(x), BigInt(y)]);
|
|
1355
|
-
const kp = keyPath("BJJ" /* BabyJubJub */, pb.hex());
|
|
1356
|
-
return { type: "BJJ" /* BabyJubJub */, id: kp };
|
|
1357
|
-
};
|
|
1358
|
-
|
|
1359
|
-
// src/verifiable/core-utils.ts
|
|
1360
|
-
var import_js_iden3_core5 = require("@iden3/js-iden3-core");
|
|
1361
|
-
var import_js_jsonld_merklization = require("@iden3/js-jsonld-merklization");
|
|
1362
|
-
var import_jsonld = __toESM(require("jsonld"), 1);
|
|
1363
|
-
var import_ethers2 = require("ethers");
|
|
1364
|
-
var credentialSubjectKey = "credentialSubject";
|
|
1365
|
-
var contextFullKey = "@context";
|
|
1366
|
-
var serializationFullKey = "iden3_serialization";
|
|
1367
|
-
var fieldPrefix = "iden3:v1:";
|
|
1368
|
-
var credentialSubjectFullKey = "https://www.w3.org/2018/credentials#credentialSubject";
|
|
1369
|
-
var verifiableCredentialFullKey = "https://www.w3.org/2018/credentials#VerifiableCredential";
|
|
1370
|
-
var typeFullKey = "@type";
|
|
1371
|
-
var getFieldSlotIndex = async (field, typeName, schemaBytes) => {
|
|
1372
|
-
let ctxDoc = JSON.parse(byteDecoder.decode(schemaBytes));
|
|
1373
|
-
ctxDoc = ctxDoc[contextFullKey];
|
|
1374
|
-
if (ctxDoc === void 0) {
|
|
1375
|
-
throw new Error("document has no @context");
|
|
1376
|
-
}
|
|
1377
|
-
const ldCtx = await import_jsonld.default.processContext(
|
|
1378
|
-
await import_jsonld.default.processContext(null, null, {}),
|
|
1379
|
-
ctxDoc,
|
|
1380
|
-
{}
|
|
1381
|
-
);
|
|
1382
|
-
const serAttr = await getSerializationAttrFromParsedContext(
|
|
1383
|
-
ldCtx,
|
|
1384
|
-
typeName
|
|
1385
|
-
);
|
|
1386
|
-
if (!serAttr) {
|
|
1387
|
-
throw new Error("serialization attribute is not set");
|
|
1388
|
-
}
|
|
1389
|
-
const sPaths = parseSerializationAttr(serAttr);
|
|
1390
|
-
switch (field) {
|
|
1391
|
-
case sPaths.indexAPath:
|
|
1392
|
-
return 2;
|
|
1393
|
-
case sPaths.indexBPath:
|
|
1394
|
-
return 3;
|
|
1395
|
-
case sPaths.valueAPath:
|
|
1396
|
-
return 6;
|
|
1397
|
-
case sPaths.valueBPath:
|
|
1398
|
-
return 7;
|
|
1399
|
-
default:
|
|
1400
|
-
throw new Error(`field ${field} not specified in serialization info`);
|
|
1141
|
+
const sPaths = parseSerializationAttr(serAttr);
|
|
1142
|
+
switch (field) {
|
|
1143
|
+
case sPaths.indexAPath:
|
|
1144
|
+
return 2;
|
|
1145
|
+
case sPaths.indexBPath:
|
|
1146
|
+
return 3;
|
|
1147
|
+
case sPaths.valueAPath:
|
|
1148
|
+
return 6;
|
|
1149
|
+
case sPaths.valueBPath:
|
|
1150
|
+
return 7;
|
|
1151
|
+
default:
|
|
1152
|
+
throw new Error(`field ${field} not specified in serialization info`);
|
|
1401
1153
|
}
|
|
1402
1154
|
};
|
|
1403
1155
|
var fillCoreClaimSlot = async (slotData, mz, path) => {
|
|
@@ -1409,7 +1161,7 @@ var fillCoreClaimSlot = async (slotData, mz, path) => {
|
|
|
1409
1161
|
const p = await mz.resolveDocPath(path, mz.options);
|
|
1410
1162
|
const entry = await mz.entry(p);
|
|
1411
1163
|
const intVal = await entry.getValueMtEntry();
|
|
1412
|
-
const bytesVal =
|
|
1164
|
+
const bytesVal = import_js_iden3_core4.BytesHelper.intToBytes(intVal);
|
|
1413
1165
|
slotData.set(bytesVal, 0);
|
|
1414
1166
|
} catch (err) {
|
|
1415
1167
|
if (err.toString().includes("entry not found")) {
|
|
@@ -1524,7 +1276,7 @@ var parseCoreClaimSlots = async (ldCtx, mz, credentialType) => {
|
|
|
1524
1276
|
};
|
|
1525
1277
|
var calculateCoreSchemaHash = (schemaId) => {
|
|
1526
1278
|
const sHash = hexToBytes((0, import_ethers2.keccak256)(schemaId));
|
|
1527
|
-
return new
|
|
1279
|
+
return new import_js_iden3_core4.SchemaHash(sHash.slice(sHash.length - 16, sHash.length));
|
|
1528
1280
|
};
|
|
1529
1281
|
|
|
1530
1282
|
// src/verifiable/credential.ts
|
|
@@ -1606,8 +1358,8 @@ var W3CCredential = class _W3CCredential {
|
|
|
1606
1358
|
id: request.revocationOpts.issuerState ? `${credentialStatus.id.replace(/\/$/, "")}/node?state=${request.revocationOpts.issuerState}` : `${credentialStatus.id.replace(/\/$/, "")}`
|
|
1607
1359
|
};
|
|
1608
1360
|
case "Iden3OnchainSparseMerkleTreeProof2023" /* Iden3OnchainSparseMerkleTreeProof2023 */: {
|
|
1609
|
-
const issuerId =
|
|
1610
|
-
const chainId = (0,
|
|
1361
|
+
const issuerId = import_js_iden3_core5.DID.idFromDID(issuer);
|
|
1362
|
+
const chainId = (0, import_js_iden3_core5.getChainId)(import_js_iden3_core5.DID.blockchainFromId(issuerId), import_js_iden3_core5.DID.networkIdFromId(issuerId));
|
|
1611
1363
|
const searchParams = [
|
|
1612
1364
|
["revocationNonce", request.revocationOpts.nonce?.toString() || ""],
|
|
1613
1365
|
["contractAddress", `${chainId}:${request.revocationOpts.id}`],
|
|
@@ -1735,12 +1487,12 @@ var W3CCredential = class _W3CCredential {
|
|
|
1735
1487
|
opts.merklizedRootPosition = "index" /* Index */;
|
|
1736
1488
|
}
|
|
1737
1489
|
const schemaHash = calculateCoreSchemaHash(byteEncoder.encode(credentialType));
|
|
1738
|
-
const claim =
|
|
1490
|
+
const claim = import_js_iden3_core5.Claim.newClaim(
|
|
1739
1491
|
schemaHash,
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1492
|
+
import_js_iden3_core5.ClaimOptions.withIndexDataBytes(slots.indexA, slots.indexB),
|
|
1493
|
+
import_js_iden3_core5.ClaimOptions.withValueDataBytes(slots.valueA, slots.valueB),
|
|
1494
|
+
import_js_iden3_core5.ClaimOptions.withRevocationNonce(BigInt(opts.revNonce)),
|
|
1495
|
+
import_js_iden3_core5.ClaimOptions.withVersion(opts.version)
|
|
1744
1496
|
);
|
|
1745
1497
|
if (opts.updatable) {
|
|
1746
1498
|
claim.setFlagUpdatable(opts.updatable);
|
|
@@ -1749,8 +1501,8 @@ var W3CCredential = class _W3CCredential {
|
|
|
1749
1501
|
claim.setExpirationDate(new Date(this.expirationDate));
|
|
1750
1502
|
}
|
|
1751
1503
|
if (subjectId) {
|
|
1752
|
-
const did =
|
|
1753
|
-
const id =
|
|
1504
|
+
const did = import_js_iden3_core5.DID.parse(subjectId.toString());
|
|
1505
|
+
const id = import_js_iden3_core5.DID.idFromDID(did);
|
|
1754
1506
|
switch (opts.subjectPosition) {
|
|
1755
1507
|
case "":
|
|
1756
1508
|
case "index" /* Index */:
|
|
@@ -1851,26 +1603,26 @@ var W3CCredential = class _W3CCredential {
|
|
|
1851
1603
|
let merklizedRootPosition = "";
|
|
1852
1604
|
const merklizedPosition = coreClaim.getMerklizedPosition();
|
|
1853
1605
|
switch (merklizedPosition) {
|
|
1854
|
-
case
|
|
1606
|
+
case import_js_iden3_core5.MerklizedRootPosition.None:
|
|
1855
1607
|
merklizedRootPosition = "" /* None */;
|
|
1856
1608
|
break;
|
|
1857
|
-
case
|
|
1609
|
+
case import_js_iden3_core5.MerklizedRootPosition.Index:
|
|
1858
1610
|
merklizedRootPosition = "index" /* Index */;
|
|
1859
1611
|
break;
|
|
1860
|
-
case
|
|
1612
|
+
case import_js_iden3_core5.MerklizedRootPosition.Value:
|
|
1861
1613
|
merklizedRootPosition = "value" /* Value */;
|
|
1862
1614
|
break;
|
|
1863
1615
|
}
|
|
1864
1616
|
let subjectPosition = "";
|
|
1865
1617
|
const idPosition = coreClaim.getIdPosition();
|
|
1866
1618
|
switch (idPosition) {
|
|
1867
|
-
case
|
|
1619
|
+
case import_js_iden3_core5.IdPosition.None:
|
|
1868
1620
|
subjectPosition = "" /* None */;
|
|
1869
1621
|
break;
|
|
1870
|
-
case
|
|
1622
|
+
case import_js_iden3_core5.IdPosition.Index:
|
|
1871
1623
|
subjectPosition = "index" /* Index */;
|
|
1872
1624
|
break;
|
|
1873
|
-
case
|
|
1625
|
+
case import_js_iden3_core5.IdPosition.Value:
|
|
1874
1626
|
subjectPosition = "value" /* Value */;
|
|
1875
1627
|
break;
|
|
1876
1628
|
}
|
|
@@ -1890,9 +1642,9 @@ var W3CCredential = class _W3CCredential {
|
|
|
1890
1642
|
async verifyBJJSignatureProof(proof, coreClaim, resolverURL, userDID, credStatusResolverRegistry) {
|
|
1891
1643
|
const authClaim = proof.issuerData.authCoreClaim;
|
|
1892
1644
|
const rawSlotsInt = authClaim.rawSlotsAsInts();
|
|
1893
|
-
const pubKey = new
|
|
1645
|
+
const pubKey = new import_js_crypto5.PublicKey([rawSlotsInt[2], rawSlotsInt[3]]);
|
|
1894
1646
|
const { hi, hv } = coreClaim.hiHv();
|
|
1895
|
-
const claimHash =
|
|
1647
|
+
const claimHash = import_js_crypto5.poseidon.hash([hi, hv]);
|
|
1896
1648
|
const bjjValid = pubKey.verifyPoseidon(claimHash, proof.signature);
|
|
1897
1649
|
if (!bjjValid) {
|
|
1898
1650
|
throw new Error("signature is not valid");
|
|
@@ -1976,7 +1728,7 @@ function extractProof(proof) {
|
|
|
1976
1728
|
if (!p.coreClaim) {
|
|
1977
1729
|
throw new Error(`coreClaim field is not defined in proof type ${defaultProofType}`);
|
|
1978
1730
|
}
|
|
1979
|
-
const coreClaim = p.coreClaim instanceof
|
|
1731
|
+
const coreClaim = p.coreClaim instanceof import_js_iden3_core5.Claim ? p.coreClaim : new import_js_iden3_core5.Claim().fromHex(p.coreClaim);
|
|
1980
1732
|
return { claim: coreClaim, proofType: defaultProofType };
|
|
1981
1733
|
}
|
|
1982
1734
|
throw new Error("proof format is not supported");
|
|
@@ -1985,7 +1737,7 @@ function validateTreeState(treeState) {
|
|
|
1985
1737
|
const ctrHash = treeState.claimsTreeRoot ? import_js_merkletree3.Hash.fromHex(treeState.claimsTreeRoot) : new import_js_merkletree3.Hash();
|
|
1986
1738
|
const rtrHash = treeState.revocationTreeRoot ? import_js_merkletree3.Hash.fromHex(treeState.revocationTreeRoot) : new import_js_merkletree3.Hash();
|
|
1987
1739
|
const rorHash = treeState.rootOfRoots ? import_js_merkletree3.Hash.fromHex(treeState.rootOfRoots) : new import_js_merkletree3.Hash();
|
|
1988
|
-
const wantState =
|
|
1740
|
+
const wantState = import_js_crypto5.poseidon.hash([ctrHash.bigInt(), rtrHash.bigInt(), rorHash.bigInt()]);
|
|
1989
1741
|
const stateHash = treeState.state ? import_js_merkletree3.Hash.fromHex(treeState.state) : new import_js_merkletree3.Hash();
|
|
1990
1742
|
return wantState === stateHash.bigInt();
|
|
1991
1743
|
}
|
|
@@ -2299,18 +2051,666 @@ var DIDDocumentJSONSchema = `{
|
|
|
2299
2051
|
},
|
|
2300
2052
|
"deprecated": true
|
|
2301
2053
|
}
|
|
2302
|
-
},
|
|
2303
|
-
"required": [
|
|
2304
|
-
"id"
|
|
2305
|
-
]
|
|
2306
|
-
}`;
|
|
2054
|
+
},
|
|
2055
|
+
"required": [
|
|
2056
|
+
"id"
|
|
2057
|
+
]
|
|
2058
|
+
}`;
|
|
2059
|
+
|
|
2060
|
+
// src/utils/payments/solana.ts
|
|
2061
|
+
var import_js_iden3_core6 = require("@iden3/js-iden3-core");
|
|
2062
|
+
var import_web3 = require("@solana/web3.js");
|
|
2063
|
+
var SolanaNativePaymentRequest = class {
|
|
2064
|
+
version;
|
|
2065
|
+
chainId;
|
|
2066
|
+
verifyingContract;
|
|
2067
|
+
recipient;
|
|
2068
|
+
amount;
|
|
2069
|
+
expirationDate;
|
|
2070
|
+
nonce;
|
|
2071
|
+
metadata;
|
|
2072
|
+
constructor(fields) {
|
|
2073
|
+
this.version = fields.version;
|
|
2074
|
+
this.chainId = fields.chainId;
|
|
2075
|
+
this.verifyingContract = fields.verifyingContract;
|
|
2076
|
+
this.recipient = fields.recipient;
|
|
2077
|
+
this.amount = fields.amount;
|
|
2078
|
+
this.expirationDate = fields.expirationDate;
|
|
2079
|
+
this.nonce = fields.nonce;
|
|
2080
|
+
this.metadata = fields.metadata;
|
|
2081
|
+
}
|
|
2082
|
+
};
|
|
2083
|
+
var SolanaSplPaymentRequest = class {
|
|
2084
|
+
version;
|
|
2085
|
+
chainId;
|
|
2086
|
+
verifyingContract;
|
|
2087
|
+
tokenAddress;
|
|
2088
|
+
recipient;
|
|
2089
|
+
amount;
|
|
2090
|
+
expirationDate;
|
|
2091
|
+
nonce;
|
|
2092
|
+
metadata;
|
|
2093
|
+
constructor(fields) {
|
|
2094
|
+
this.version = fields.version;
|
|
2095
|
+
this.chainId = fields.chainId;
|
|
2096
|
+
this.verifyingContract = fields.verifyingContract;
|
|
2097
|
+
this.tokenAddress = fields.tokenAddress;
|
|
2098
|
+
this.recipient = fields.recipient;
|
|
2099
|
+
this.amount = fields.amount;
|
|
2100
|
+
this.expirationDate = fields.expirationDate;
|
|
2101
|
+
this.nonce = fields.nonce;
|
|
2102
|
+
this.metadata = fields.metadata;
|
|
2103
|
+
}
|
|
2104
|
+
};
|
|
2105
|
+
var SolanaNativePaymentSchema = /* @__PURE__ */ new Map([
|
|
2106
|
+
[
|
|
2107
|
+
SolanaNativePaymentRequest,
|
|
2108
|
+
{
|
|
2109
|
+
kind: "struct",
|
|
2110
|
+
fields: [
|
|
2111
|
+
["version", ["u8"]],
|
|
2112
|
+
["chainId", "u64"],
|
|
2113
|
+
["verifyingContract", ["u8", 32]],
|
|
2114
|
+
["recipient", ["u8", 32]],
|
|
2115
|
+
["amount", "u64"],
|
|
2116
|
+
["expirationDate", "u64"],
|
|
2117
|
+
["nonce", "u64"],
|
|
2118
|
+
["metadata", ["u8"]]
|
|
2119
|
+
]
|
|
2120
|
+
}
|
|
2121
|
+
]
|
|
2122
|
+
]);
|
|
2123
|
+
var SolanaSplPaymentSchema = /* @__PURE__ */ new Map([
|
|
2124
|
+
[
|
|
2125
|
+
SolanaSplPaymentRequest,
|
|
2126
|
+
{
|
|
2127
|
+
kind: "struct",
|
|
2128
|
+
fields: [
|
|
2129
|
+
["version", ["u8"]],
|
|
2130
|
+
["chainId", "u64"],
|
|
2131
|
+
["verifyingContract", ["u8", 32]],
|
|
2132
|
+
["tokenAddress", ["u8", 32]],
|
|
2133
|
+
["recipient", ["u8", 32]],
|
|
2134
|
+
["amount", "u64"],
|
|
2135
|
+
["expirationDate", "u64"],
|
|
2136
|
+
["nonce", "u64"],
|
|
2137
|
+
["metadata", ["u8"]]
|
|
2138
|
+
]
|
|
2139
|
+
}
|
|
2140
|
+
]
|
|
2141
|
+
]);
|
|
2142
|
+
var SolanaPaymentInstruction = class {
|
|
2143
|
+
recipient;
|
|
2144
|
+
amount;
|
|
2145
|
+
expiration_date;
|
|
2146
|
+
nonce;
|
|
2147
|
+
metadata;
|
|
2148
|
+
signature;
|
|
2149
|
+
constructor(fields) {
|
|
2150
|
+
this.recipient = fields.recipient;
|
|
2151
|
+
this.amount = fields.amount;
|
|
2152
|
+
this.expiration_date = fields.expiration_date;
|
|
2153
|
+
this.nonce = fields.nonce;
|
|
2154
|
+
this.metadata = fields.metadata;
|
|
2155
|
+
this.signature = fields.signature;
|
|
2156
|
+
}
|
|
2157
|
+
};
|
|
2158
|
+
var SolanaPaymentInstructionSchema = /* @__PURE__ */ new Map([
|
|
2159
|
+
[
|
|
2160
|
+
SolanaPaymentInstruction,
|
|
2161
|
+
{
|
|
2162
|
+
kind: "struct",
|
|
2163
|
+
fields: [
|
|
2164
|
+
["recipient", ["u8", 32]],
|
|
2165
|
+
["amount", "u64"],
|
|
2166
|
+
["expiration_date", "u64"],
|
|
2167
|
+
["nonce", "u64"],
|
|
2168
|
+
["metadata", ["u8"]],
|
|
2169
|
+
["signature", [64]]
|
|
2170
|
+
]
|
|
2171
|
+
}
|
|
2172
|
+
]
|
|
2173
|
+
]);
|
|
2174
|
+
var buildSolanaPayment = async (solSigner, option, chainId, paymentRails, recipient, amount, expirationDate, nonce) => {
|
|
2175
|
+
let serialized;
|
|
2176
|
+
const proofVersion = option.type === "Iden3PaymentRailsSolanaRequestV1" /* Iden3PaymentRailsSolanaRequestV1 */ ? "SolanaEd25519NativeV1" : "SolanaEd25519SPLV1";
|
|
2177
|
+
let chainRef = chainId;
|
|
2178
|
+
switch (chainId) {
|
|
2179
|
+
case "101":
|
|
2180
|
+
chainRef = SOLANA_CHAIN_REF.DEVNET;
|
|
2181
|
+
break;
|
|
2182
|
+
case "102":
|
|
2183
|
+
chainRef = SOLANA_CHAIN_REF.TESTNET;
|
|
2184
|
+
break;
|
|
2185
|
+
case "103":
|
|
2186
|
+
chainRef = SOLANA_CHAIN_REF.MAINNET;
|
|
2187
|
+
break;
|
|
2188
|
+
}
|
|
2189
|
+
if (option.type === "Iden3PaymentRailsSolanaRequestV1" /* Iden3PaymentRailsSolanaRequestV1 */) {
|
|
2190
|
+
const request = new SolanaNativePaymentRequest({
|
|
2191
|
+
version: byteEncoder.encode(proofVersion),
|
|
2192
|
+
chainId: BigInt(chainId),
|
|
2193
|
+
verifyingContract: new import_web3.PublicKey(paymentRails).toBytes(),
|
|
2194
|
+
recipient: new import_web3.PublicKey(recipient).toBytes(),
|
|
2195
|
+
amount: BigInt(amount),
|
|
2196
|
+
expirationDate: BigInt((0, import_js_iden3_core6.getUnixTimestamp)(expirationDate)),
|
|
2197
|
+
nonce,
|
|
2198
|
+
metadata: byteEncoder.encode("0x")
|
|
2199
|
+
});
|
|
2200
|
+
serialized = (0, import_borsh.serialize)(SolanaNativePaymentSchema, request);
|
|
2201
|
+
} else {
|
|
2202
|
+
if (!option.contractAddress) {
|
|
2203
|
+
throw new Error(`failed request. no contract address for ${option.type} payment type`);
|
|
2204
|
+
}
|
|
2205
|
+
const request = new SolanaSplPaymentRequest({
|
|
2206
|
+
version: byteEncoder.encode(proofVersion),
|
|
2207
|
+
chainId: BigInt(chainId),
|
|
2208
|
+
verifyingContract: new import_web3.PublicKey(paymentRails).toBytes(),
|
|
2209
|
+
tokenAddress: new import_web3.PublicKey(option.contractAddress).toBytes(),
|
|
2210
|
+
recipient: new import_web3.PublicKey(recipient).toBytes(),
|
|
2211
|
+
amount: BigInt(amount),
|
|
2212
|
+
expirationDate: BigInt((0, import_js_iden3_core6.getUnixTimestamp)(expirationDate)),
|
|
2213
|
+
nonce,
|
|
2214
|
+
metadata: byteEncoder.encode("0x")
|
|
2215
|
+
});
|
|
2216
|
+
serialized = (0, import_borsh.serialize)(SolanaSplPaymentSchema, request);
|
|
2217
|
+
}
|
|
2218
|
+
const privateKey = solSigner.secretKey.slice(0, 32);
|
|
2219
|
+
const signature = await import_ed25519.ed25519.sign(serialized, privateKey);
|
|
2220
|
+
const proof = [
|
|
2221
|
+
{
|
|
2222
|
+
type: "SolanaEd25519Signature2025" /* SolanaEd25519Signature2025 */,
|
|
2223
|
+
proofPurpose: "assertionMethod",
|
|
2224
|
+
proofValue: Buffer.from(signature).toString("hex"),
|
|
2225
|
+
created: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2226
|
+
verificationMethod: `did:pkh:solana:${chainRef}:${solSigner.publicKey.toBase58()}`,
|
|
2227
|
+
domain: {
|
|
2228
|
+
version: proofVersion,
|
|
2229
|
+
chainId,
|
|
2230
|
+
verifyingContract: paymentRails
|
|
2231
|
+
}
|
|
2232
|
+
}
|
|
2233
|
+
];
|
|
2234
|
+
const d = {
|
|
2235
|
+
type: "Iden3PaymentRailsSolanaRequestV1" /* Iden3PaymentRailsSolanaRequestV1 */,
|
|
2236
|
+
"@context": [
|
|
2237
|
+
`https://schema.iden3.io/core/jsonld/payment.jsonld#${option.type}`,
|
|
2238
|
+
"https://schema.iden3.io/core/jsonld/solanaEd25519.jsonld"
|
|
2239
|
+
],
|
|
2240
|
+
recipient,
|
|
2241
|
+
amount: amount.toString(),
|
|
2242
|
+
expirationDate: expirationDate.toISOString(),
|
|
2243
|
+
nonce: nonce.toString(),
|
|
2244
|
+
metadata: "0x",
|
|
2245
|
+
proof
|
|
2246
|
+
};
|
|
2247
|
+
if (option.type === "Iden3PaymentRailsSolanaRequestV1" /* Iden3PaymentRailsSolanaRequestV1 */) {
|
|
2248
|
+
return d;
|
|
2249
|
+
}
|
|
2250
|
+
return {
|
|
2251
|
+
...d,
|
|
2252
|
+
type: option.type,
|
|
2253
|
+
tokenAddress: option.contractAddress || "",
|
|
2254
|
+
features: option.features || []
|
|
2255
|
+
};
|
|
2256
|
+
};
|
|
2257
|
+
var serializeSolanaPaymentInstruction = (data) => {
|
|
2258
|
+
let serialized;
|
|
2259
|
+
const proof = Array.isArray(data.proof) ? data.proof[0] : data.proof;
|
|
2260
|
+
const proofVersion = data.type === "Iden3PaymentRailsSolanaRequestV1" /* Iden3PaymentRailsSolanaRequestV1 */ ? "SolanaEd25519NativeV1" : "SolanaEd25519SPLV1";
|
|
2261
|
+
if (data.type === "Iden3PaymentRailsSolanaRequestV1" /* Iden3PaymentRailsSolanaRequestV1 */) {
|
|
2262
|
+
const request = new SolanaNativePaymentRequest({
|
|
2263
|
+
version: byteEncoder.encode(proofVersion),
|
|
2264
|
+
chainId: BigInt(proof.domain.chainId),
|
|
2265
|
+
verifyingContract: new import_web3.PublicKey(proof.domain.verifyingContract).toBytes(),
|
|
2266
|
+
recipient: new import_web3.PublicKey(data.recipient).toBytes(),
|
|
2267
|
+
amount: BigInt(data.amount),
|
|
2268
|
+
expirationDate: BigInt((0, import_js_iden3_core6.getUnixTimestamp)(new Date(data.expirationDate))),
|
|
2269
|
+
nonce: BigInt(data.nonce),
|
|
2270
|
+
metadata: byteEncoder.encode("0x")
|
|
2271
|
+
});
|
|
2272
|
+
serialized = (0, import_borsh.serialize)(SolanaNativePaymentSchema, request);
|
|
2273
|
+
} else {
|
|
2274
|
+
const request = new SolanaSplPaymentRequest({
|
|
2275
|
+
version: byteEncoder.encode(proofVersion),
|
|
2276
|
+
chainId: BigInt(proof.domain.chainId),
|
|
2277
|
+
verifyingContract: new import_web3.PublicKey(proof.domain.verifyingContract).toBytes(),
|
|
2278
|
+
tokenAddress: new import_web3.PublicKey(data.tokenAddress).toBytes(),
|
|
2279
|
+
recipient: new import_web3.PublicKey(data.recipient).toBytes(),
|
|
2280
|
+
amount: BigInt(data.amount),
|
|
2281
|
+
expirationDate: BigInt((0, import_js_iden3_core6.getUnixTimestamp)(new Date(data.expirationDate))),
|
|
2282
|
+
nonce: BigInt(data.nonce),
|
|
2283
|
+
metadata: byteEncoder.encode("0x")
|
|
2284
|
+
});
|
|
2285
|
+
serialized = (0, import_borsh.serialize)(SolanaSplPaymentSchema, request);
|
|
2286
|
+
}
|
|
2287
|
+
return serialized;
|
|
2288
|
+
};
|
|
2289
|
+
var verifyIden3SolanaPaymentRequest = async (data, resolver) => {
|
|
2290
|
+
const proof = Array.isArray(data.proof) ? data.proof[0] : data.proof;
|
|
2291
|
+
let serialized;
|
|
2292
|
+
if (data.type === "Iden3PaymentRailsSolanaRequestV1" /* Iden3PaymentRailsSolanaRequestV1 */) {
|
|
2293
|
+
const request = new SolanaNativePaymentRequest({
|
|
2294
|
+
version: byteEncoder.encode(proof.domain.version),
|
|
2295
|
+
chainId: BigInt(proof.domain.chainId),
|
|
2296
|
+
verifyingContract: new import_web3.PublicKey(proof.domain.verifyingContract).toBytes(),
|
|
2297
|
+
recipient: new import_web3.PublicKey(data.recipient).toBytes(),
|
|
2298
|
+
amount: BigInt(data.amount),
|
|
2299
|
+
expirationDate: BigInt((0, import_js_iden3_core6.getUnixTimestamp)(new Date(data.expirationDate))),
|
|
2300
|
+
nonce: BigInt(data.nonce),
|
|
2301
|
+
metadata: byteEncoder.encode("0x")
|
|
2302
|
+
});
|
|
2303
|
+
serialized = (0, import_borsh.serialize)(SolanaNativePaymentSchema, request);
|
|
2304
|
+
} else {
|
|
2305
|
+
const request = new SolanaSplPaymentRequest({
|
|
2306
|
+
version: byteEncoder.encode(proof.domain.version),
|
|
2307
|
+
chainId: BigInt(proof.domain.chainId),
|
|
2308
|
+
verifyingContract: new import_web3.PublicKey(proof.domain.verifyingContract).toBytes(),
|
|
2309
|
+
tokenAddress: new import_web3.PublicKey(data.tokenAddress).toBytes(),
|
|
2310
|
+
recipient: new import_web3.PublicKey(data.recipient).toBytes(),
|
|
2311
|
+
amount: BigInt(data.amount),
|
|
2312
|
+
expirationDate: BigInt((0, import_js_iden3_core6.getUnixTimestamp)(new Date(data.expirationDate))),
|
|
2313
|
+
nonce: BigInt(data.nonce),
|
|
2314
|
+
metadata: byteEncoder.encode("0x")
|
|
2315
|
+
});
|
|
2316
|
+
serialized = (0, import_borsh.serialize)(SolanaSplPaymentSchema, request);
|
|
2317
|
+
}
|
|
2318
|
+
const { didDocument } = await resolver.resolve(proof.verificationMethod);
|
|
2319
|
+
let publicKeyMultibase;
|
|
2320
|
+
if (didDocument?.verificationMethod) {
|
|
2321
|
+
for (const verificationMethod of didDocument.verificationMethod) {
|
|
2322
|
+
if (verificationMethod.type === "Ed25519VerificationKey2020") {
|
|
2323
|
+
publicKeyMultibase = verificationMethod.publicKeyMultibase;
|
|
2324
|
+
}
|
|
2325
|
+
}
|
|
2326
|
+
}
|
|
2327
|
+
if (!publicKeyMultibase) {
|
|
2328
|
+
throw new Error("No Ed25519VerificationKey2020 found in DID document");
|
|
2329
|
+
}
|
|
2330
|
+
return import_ed25519.ed25519.verify(proof.proofValue, serialized, new import_web3.PublicKey(publicKeyMultibase).toBytes());
|
|
2331
|
+
};
|
|
2332
|
+
|
|
2333
|
+
// src/utils/payments/evm.ts
|
|
2334
|
+
var import_ethers3 = require("ethers");
|
|
2335
|
+
var import_js_iden3_core7 = require("@iden3/js-iden3-core");
|
|
2336
|
+
var buildEvmPayment = async (signer, option, chainId, paymentRails, recipient, amount, expirationDateRequired, nonce) => {
|
|
2337
|
+
const typeUrl = `https://schema.iden3.io/core/json/${option.type}.json`;
|
|
2338
|
+
const typesFetchResult = await fetch(typeUrl);
|
|
2339
|
+
const types = await typesFetchResult.json();
|
|
2340
|
+
delete types.EIP712Domain;
|
|
2341
|
+
const paymentData = option.type === "Iden3PaymentRailsRequestV1" /* Iden3PaymentRailsRequestV1 */ ? {
|
|
2342
|
+
recipient,
|
|
2343
|
+
amount,
|
|
2344
|
+
expirationDate: (0, import_js_iden3_core7.getUnixTimestamp)(expirationDateRequired),
|
|
2345
|
+
nonce,
|
|
2346
|
+
metadata: "0x"
|
|
2347
|
+
} : {
|
|
2348
|
+
tokenAddress: option.contractAddress,
|
|
2349
|
+
recipient,
|
|
2350
|
+
amount,
|
|
2351
|
+
expirationDate: (0, import_js_iden3_core7.getUnixTimestamp)(expirationDateRequired),
|
|
2352
|
+
nonce,
|
|
2353
|
+
metadata: "0x"
|
|
2354
|
+
};
|
|
2355
|
+
const domain = {
|
|
2356
|
+
name: "MCPayment",
|
|
2357
|
+
version: "1.0.0",
|
|
2358
|
+
chainId,
|
|
2359
|
+
verifyingContract: paymentRails
|
|
2360
|
+
};
|
|
2361
|
+
const signature = await signer.signTypedData(domain, types, paymentData);
|
|
2362
|
+
const proof = [
|
|
2363
|
+
{
|
|
2364
|
+
type: "EthereumEip712Signature2021" /* EthereumEip712Signature2021 */,
|
|
2365
|
+
proofPurpose: "assertionMethod",
|
|
2366
|
+
proofValue: signature,
|
|
2367
|
+
verificationMethod: `did:pkh:eip155:${chainId}:${await signer.getAddress()}`,
|
|
2368
|
+
created: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2369
|
+
eip712: {
|
|
2370
|
+
types: typeUrl,
|
|
2371
|
+
primaryType: "Iden3PaymentRailsRequestV1",
|
|
2372
|
+
domain
|
|
2373
|
+
}
|
|
2374
|
+
}
|
|
2375
|
+
];
|
|
2376
|
+
const d = {
|
|
2377
|
+
type: "Iden3PaymentRailsRequestV1" /* Iden3PaymentRailsRequestV1 */,
|
|
2378
|
+
"@context": [
|
|
2379
|
+
`https://schema.iden3.io/core/jsonld/payment.jsonld#${option.type}`,
|
|
2380
|
+
"https://w3id.org/security/suites/eip712sig-2021/v1"
|
|
2381
|
+
],
|
|
2382
|
+
recipient,
|
|
2383
|
+
amount: amount.toString(),
|
|
2384
|
+
expirationDate: expirationDateRequired.toISOString(),
|
|
2385
|
+
nonce: nonce.toString(),
|
|
2386
|
+
metadata: "0x",
|
|
2387
|
+
proof
|
|
2388
|
+
};
|
|
2389
|
+
if (option.type === "Iden3PaymentRailsRequestV1" /* Iden3PaymentRailsRequestV1 */) {
|
|
2390
|
+
return d;
|
|
2391
|
+
}
|
|
2392
|
+
return {
|
|
2393
|
+
...d,
|
|
2394
|
+
type: option.type,
|
|
2395
|
+
tokenAddress: option.contractAddress || "",
|
|
2396
|
+
features: option.features || []
|
|
2397
|
+
};
|
|
2398
|
+
};
|
|
2399
|
+
async function verifyEIP712TypedData(data, resolver) {
|
|
2400
|
+
const paymentData = data.type === "Iden3PaymentRailsRequestV1" /* Iden3PaymentRailsRequestV1 */ ? {
|
|
2401
|
+
recipient: data.recipient,
|
|
2402
|
+
amount: data.amount,
|
|
2403
|
+
expirationDate: (0, import_js_iden3_core7.getUnixTimestamp)(new Date(data.expirationDate)),
|
|
2404
|
+
nonce: data.nonce,
|
|
2405
|
+
metadata: "0x"
|
|
2406
|
+
} : {
|
|
2407
|
+
tokenAddress: data.tokenAddress,
|
|
2408
|
+
recipient: data.recipient,
|
|
2409
|
+
amount: data.amount,
|
|
2410
|
+
expirationDate: (0, import_js_iden3_core7.getUnixTimestamp)(new Date(data.expirationDate)),
|
|
2411
|
+
nonce: data.nonce,
|
|
2412
|
+
metadata: "0x"
|
|
2413
|
+
};
|
|
2414
|
+
const proof = Array.isArray(data.proof) ? data.proof[0] : data.proof;
|
|
2415
|
+
const typesFetchResult = await fetch(proof.eip712.types);
|
|
2416
|
+
const types = await typesFetchResult.json();
|
|
2417
|
+
delete types.EIP712Domain;
|
|
2418
|
+
const recovered = import_ethers3.ethers.verifyTypedData(
|
|
2419
|
+
proof.eip712.domain,
|
|
2420
|
+
types,
|
|
2421
|
+
paymentData,
|
|
2422
|
+
proof.proofValue
|
|
2423
|
+
);
|
|
2424
|
+
const { didDocument } = await resolver.resolve(proof.verificationMethod);
|
|
2425
|
+
if (didDocument?.verificationMethod) {
|
|
2426
|
+
for (const verificationMethod of didDocument.verificationMethod) {
|
|
2427
|
+
if (verificationMethod.blockchainAccountId?.split(":").slice(-1)[0].toLowerCase() === recovered.toLowerCase()) {
|
|
2428
|
+
return recovered;
|
|
2429
|
+
}
|
|
2430
|
+
}
|
|
2431
|
+
} else {
|
|
2432
|
+
throw new Error("failed request. issuer DIDDocument does not contain any verificationMethods");
|
|
2433
|
+
}
|
|
2434
|
+
throw new Error(`failed request. no matching verificationMethod`);
|
|
2435
|
+
}
|
|
2436
|
+
|
|
2437
|
+
// src/kms/key-providers/bjj-provider.ts
|
|
2438
|
+
var BjjProvider = class {
|
|
2439
|
+
/**
|
|
2440
|
+
* key type that is handled by BJJ Provider
|
|
2441
|
+
* @type {KmsKeyType}
|
|
2442
|
+
*/
|
|
2443
|
+
keyType;
|
|
2444
|
+
keyStore;
|
|
2445
|
+
/**
|
|
2446
|
+
* Creates an instance of BjjProvider.
|
|
2447
|
+
* @param {KmsKeyType} keyType - kms key type
|
|
2448
|
+
* @param {AbstractPrivateKeyStore} keyStore - key store for kms
|
|
2449
|
+
*/
|
|
2450
|
+
constructor(keyType, keyStore) {
|
|
2451
|
+
if (keyType !== "BJJ" /* BabyJubJub */) {
|
|
2452
|
+
throw new Error("Key type must be BabyJubJub");
|
|
2453
|
+
}
|
|
2454
|
+
this.keyType = keyType;
|
|
2455
|
+
this.keyStore = keyStore;
|
|
2456
|
+
}
|
|
2457
|
+
/**
|
|
2458
|
+
* get all keys
|
|
2459
|
+
* @returns list of keys
|
|
2460
|
+
*/
|
|
2461
|
+
async list() {
|
|
2462
|
+
const allKeysFromKeyStore = await this.keyStore.list();
|
|
2463
|
+
return allKeysFromKeyStore.filter((key) => key.alias.startsWith(this.keyType));
|
|
2464
|
+
}
|
|
2465
|
+
/**
|
|
2466
|
+
* generates a baby jub jub key from a seed phrase
|
|
2467
|
+
* @param {Uint8Array} seed - byte array seed
|
|
2468
|
+
* @returns kms key identifier
|
|
2469
|
+
*/
|
|
2470
|
+
async newPrivateKeyFromSeed(seed) {
|
|
2471
|
+
const newKey = new Uint8Array(32);
|
|
2472
|
+
newKey.set(Uint8Array.from(seed), 0);
|
|
2473
|
+
newKey.fill(seed.length, 32, 0);
|
|
2474
|
+
const privateKey = new import_js_crypto6.PrivateKey(seed);
|
|
2475
|
+
const publicKey = privateKey.public();
|
|
2476
|
+
const kmsId = {
|
|
2477
|
+
type: this.keyType,
|
|
2478
|
+
id: keyPath(this.keyType, publicKey.hex())
|
|
2479
|
+
};
|
|
2480
|
+
await this.keyStore.importKey({ alias: kmsId.id, key: privateKey.hex() });
|
|
2481
|
+
return kmsId;
|
|
2482
|
+
}
|
|
2483
|
+
/**
|
|
2484
|
+
* Gets public key by kmsKeyId
|
|
2485
|
+
*
|
|
2486
|
+
* @param {KmsKeyId} keyId - key identifier
|
|
2487
|
+
*/
|
|
2488
|
+
async publicKey(keyId) {
|
|
2489
|
+
const privateKey = await this.privateKey(keyId);
|
|
2490
|
+
return privateKey.public().hex();
|
|
2491
|
+
}
|
|
2492
|
+
/**
|
|
2493
|
+
* signs prepared payload of size,
|
|
2494
|
+
* with a key id
|
|
2495
|
+
*
|
|
2496
|
+
* @param {KmsKeyId} keyId - key identifier
|
|
2497
|
+
* @param {Uint8Array} data - data to sign (32 bytes)
|
|
2498
|
+
* @returns Uint8Array signature
|
|
2499
|
+
*/
|
|
2500
|
+
async sign(keyId, data) {
|
|
2501
|
+
if (data.length != 32) {
|
|
2502
|
+
throw new Error("data to sign is too large");
|
|
2503
|
+
}
|
|
2504
|
+
const i = import_js_iden3_core8.BytesHelper.bytesToInt(data);
|
|
2505
|
+
if (!(0, import_js_iden3_core8.checkBigIntInField)(i)) {
|
|
2506
|
+
throw new Error("data to sign is too large");
|
|
2507
|
+
}
|
|
2508
|
+
const privateKey = await this.privateKey(keyId);
|
|
2509
|
+
const signature = privateKey.signPoseidon(i);
|
|
2510
|
+
return signature.compress();
|
|
2511
|
+
}
|
|
2512
|
+
async privateKey(keyId) {
|
|
2513
|
+
const privateKeyHex = await this.keyStore.get({ alias: keyId.id });
|
|
2514
|
+
return new import_js_crypto6.PrivateKey(import_js_crypto6.Hex.decodeString(privateKeyHex));
|
|
2515
|
+
}
|
|
2516
|
+
async verify(message, signatureHex, keyId) {
|
|
2517
|
+
const publicKey = await this.publicKey(keyId);
|
|
2518
|
+
return import_js_crypto6.PublicKey.newFromCompressed(hexToBytes(publicKey)).verifyPoseidon(
|
|
2519
|
+
import_js_iden3_core8.BytesHelper.bytesToInt(message),
|
|
2520
|
+
import_js_crypto6.Signature.newFromCompressed(hexToBytes(signatureHex))
|
|
2521
|
+
);
|
|
2522
|
+
}
|
|
2523
|
+
};
|
|
2524
|
+
|
|
2525
|
+
// src/kms/key-providers/ed25519-provider.ts
|
|
2526
|
+
var import_ed255192 = require("@noble/curves/ed25519");
|
|
2527
|
+
var Ed25519Provider = class {
|
|
2528
|
+
/**
|
|
2529
|
+
* Creates an instance of Ed25519Provider.
|
|
2530
|
+
* @param {KmsKeyType} keyType - kms key type
|
|
2531
|
+
* @param {AbstractPrivateKeyStore} keyStore - key store for kms
|
|
2532
|
+
*/
|
|
2533
|
+
constructor(keyType, _keyStore) {
|
|
2534
|
+
this.keyType = keyType;
|
|
2535
|
+
this._keyStore = _keyStore;
|
|
2536
|
+
}
|
|
2537
|
+
/**
|
|
2538
|
+
* get all keys
|
|
2539
|
+
* @returns list of keys
|
|
2540
|
+
*/
|
|
2541
|
+
async list() {
|
|
2542
|
+
const allKeysFromKeyStore = await this._keyStore.list();
|
|
2543
|
+
return allKeysFromKeyStore.filter((key) => key.alias.startsWith(this.keyType));
|
|
2544
|
+
}
|
|
2545
|
+
/**
|
|
2546
|
+
* generates a ed25519 key from a seed phrase
|
|
2547
|
+
* @param {Uint8Array} seed - byte array seed
|
|
2548
|
+
* @returns {Promise<KmsKeyId>} kms key identifier
|
|
2549
|
+
*/
|
|
2550
|
+
async newPrivateKeyFromSeed(seed) {
|
|
2551
|
+
if (seed.length !== 32) {
|
|
2552
|
+
throw new Error("Seed should be 32 bytes");
|
|
2553
|
+
}
|
|
2554
|
+
const publicKey = import_ed255192.ed25519.getPublicKey(seed);
|
|
2555
|
+
const kmsId = {
|
|
2556
|
+
type: this.keyType,
|
|
2557
|
+
id: keyPath(this.keyType, bytesToHex(publicKey))
|
|
2558
|
+
};
|
|
2559
|
+
await this._keyStore.importKey({
|
|
2560
|
+
alias: kmsId.id,
|
|
2561
|
+
key: bytesToHex(seed)
|
|
2562
|
+
});
|
|
2563
|
+
return kmsId;
|
|
2564
|
+
}
|
|
2565
|
+
/**
|
|
2566
|
+
* Gets public key by kmsKeyId
|
|
2567
|
+
* @param {KmsKeyId} keyId - key identifier
|
|
2568
|
+
* @returns {Promise<string>} Public key as a hex string
|
|
2569
|
+
*/
|
|
2570
|
+
async publicKey(keyId) {
|
|
2571
|
+
const privateKeyHex = await this.privateKey(keyId);
|
|
2572
|
+
const publicKey = import_ed255192.ed25519.getPublicKey(privateKeyHex);
|
|
2573
|
+
return bytesToHex(publicKey);
|
|
2574
|
+
}
|
|
2575
|
+
/**
|
|
2576
|
+
* signs prepared payload of size,
|
|
2577
|
+
* with a key id
|
|
2578
|
+
* @param {KmsKeyId} keyId - key identifier
|
|
2579
|
+
* @param {Uint8Array} digest - data to sign (32 bytes)
|
|
2580
|
+
* @returns {Promise<Uint8Array>} signature
|
|
2581
|
+
*/
|
|
2582
|
+
async sign(keyId, digest) {
|
|
2583
|
+
const privateKeyHex = await this.privateKey(keyId);
|
|
2584
|
+
return import_ed255192.ed25519.sign(digest, privateKeyHex);
|
|
2585
|
+
}
|
|
2586
|
+
/**
|
|
2587
|
+
* Verifies a signature for the given message and key identifier.
|
|
2588
|
+
* @param digest - The message to verify the signature against.
|
|
2589
|
+
* @param signatureHex - The signature to verify, as a hexadecimal string.
|
|
2590
|
+
* @param keyId - The key identifier to use for verification.
|
|
2591
|
+
* @returns A Promise that resolves to a boolean indicating whether the signature is valid.
|
|
2592
|
+
*/
|
|
2593
|
+
async verify(digest, signatureHex, keyId) {
|
|
2594
|
+
const publicKeyHex = await this.publicKey(keyId);
|
|
2595
|
+
return import_ed255192.ed25519.verify(signatureHex, digest, publicKeyHex);
|
|
2596
|
+
}
|
|
2597
|
+
/**
|
|
2598
|
+
* Retrieves the private key for a given keyId from the key store.
|
|
2599
|
+
* @param {KmsKeyId} keyId - The identifier of the key to retrieve.
|
|
2600
|
+
* @returns {Promise<string>} The private key associated with the keyId.
|
|
2601
|
+
*/
|
|
2602
|
+
async privateKey(keyId) {
|
|
2603
|
+
return this._keyStore.get({ alias: keyId.id });
|
|
2604
|
+
}
|
|
2605
|
+
};
|
|
2606
|
+
|
|
2607
|
+
// src/kms/key-providers/secp256k1-provider.ts
|
|
2608
|
+
var import_secp256k1 = require("@noble/curves/secp256k1");
|
|
2609
|
+
var import_js_crypto7 = require("@iden3/js-crypto");
|
|
2610
|
+
var import_did_jwt = require("did-jwt");
|
|
2611
|
+
var Sec256k1Provider = class {
|
|
2612
|
+
/**
|
|
2613
|
+
* key type that is handled by BJJ Provider
|
|
2614
|
+
* @type {KmsKeyType}
|
|
2615
|
+
*/
|
|
2616
|
+
keyType;
|
|
2617
|
+
_keyStore;
|
|
2618
|
+
/**
|
|
2619
|
+
* Creates an instance of BjjProvider.
|
|
2620
|
+
* @param {KmsKeyType} keyType - kms key type
|
|
2621
|
+
* @param {AbstractPrivateKeyStore} keyStore - key store for kms
|
|
2622
|
+
*/
|
|
2623
|
+
constructor(keyType, keyStore) {
|
|
2624
|
+
if (keyType !== "Secp256k1" /* Secp256k1 */) {
|
|
2625
|
+
throw new Error("Key type must be Secp256k1");
|
|
2626
|
+
}
|
|
2627
|
+
this.keyType = keyType;
|
|
2628
|
+
this._keyStore = keyStore;
|
|
2629
|
+
}
|
|
2630
|
+
/**
|
|
2631
|
+
* get all keys
|
|
2632
|
+
* @returns list of keys
|
|
2633
|
+
*/
|
|
2634
|
+
async list() {
|
|
2635
|
+
const allKeysFromKeyStore = await this._keyStore.list();
|
|
2636
|
+
return allKeysFromKeyStore.filter((key) => key.alias.startsWith(this.keyType));
|
|
2637
|
+
}
|
|
2638
|
+
/**
|
|
2639
|
+
* generates a baby jub jub key from a seed phrase
|
|
2640
|
+
* @param {Uint8Array} seed - byte array seed
|
|
2641
|
+
* @returns kms key identifier
|
|
2642
|
+
*/
|
|
2643
|
+
async newPrivateKeyFromSeed(seed) {
|
|
2644
|
+
if (seed.length !== 32) {
|
|
2645
|
+
throw new Error("Seed should be 32 bytes");
|
|
2646
|
+
}
|
|
2647
|
+
const publicKey = import_secp256k1.secp256k1.getPublicKey(seed);
|
|
2648
|
+
const kmsId = {
|
|
2649
|
+
type: this.keyType,
|
|
2650
|
+
id: keyPath(this.keyType, bytesToHex(publicKey))
|
|
2651
|
+
};
|
|
2652
|
+
await this._keyStore.importKey({
|
|
2653
|
+
alias: kmsId.id,
|
|
2654
|
+
key: bytesToHex(seed).padStart(64, "0")
|
|
2655
|
+
});
|
|
2656
|
+
return kmsId;
|
|
2657
|
+
}
|
|
2658
|
+
/**
|
|
2659
|
+
* Gets public key by kmsKeyId
|
|
2660
|
+
*
|
|
2661
|
+
* @param {KmsKeyId} keyId - key identifier
|
|
2662
|
+
*/
|
|
2663
|
+
async publicKey(keyId) {
|
|
2664
|
+
const privateKeyHex = await this.privateKey(keyId);
|
|
2665
|
+
const publicKey = import_secp256k1.secp256k1.getPublicKey(privateKeyHex, false);
|
|
2666
|
+
return bytesToHex(publicKey);
|
|
2667
|
+
}
|
|
2668
|
+
/**
|
|
2669
|
+
* Signs the given data using the private key associated with the specified key identifier.
|
|
2670
|
+
* @param keyId - The key identifier to use for signing.
|
|
2671
|
+
* @param data - The data to sign.
|
|
2672
|
+
* @param opts - Signing options, such as the algorithm to use.
|
|
2673
|
+
* @returns A Promise that resolves to the signature as a Uint8Array.
|
|
2674
|
+
*/
|
|
2675
|
+
async sign(keyId, data, opts = { alg: "ES256K" }) {
|
|
2676
|
+
const privateKeyHex = await this.privateKey(keyId);
|
|
2677
|
+
const signatureBase64 = await (0, import_did_jwt.ES256KSigner)(
|
|
2678
|
+
(0, import_did_jwt.hexToBytes)(privateKeyHex),
|
|
2679
|
+
opts.alg === "ES256K-R"
|
|
2680
|
+
)(data);
|
|
2681
|
+
if (typeof signatureBase64 !== "string") {
|
|
2682
|
+
throw new Error("signatureBase64 must be a string");
|
|
2683
|
+
}
|
|
2684
|
+
return base64UrlToBytes(signatureBase64);
|
|
2685
|
+
}
|
|
2686
|
+
/**
|
|
2687
|
+
* Verifies a signature for the given message and key identifier.
|
|
2688
|
+
* @param message - The message to verify the signature against.
|
|
2689
|
+
* @param signatureHex - The signature to verify, as a hexadecimal string.
|
|
2690
|
+
* @param keyId - The key identifier to use for verification.
|
|
2691
|
+
* @returns A Promise that resolves to a boolean indicating whether the signature is valid.
|
|
2692
|
+
*/
|
|
2693
|
+
async verify(message, signatureHex, keyId) {
|
|
2694
|
+
const publicKeyHex = await this.publicKey(keyId);
|
|
2695
|
+
return import_secp256k1.secp256k1.verify(signatureHex, (0, import_js_crypto7.sha256)(message), publicKeyHex);
|
|
2696
|
+
}
|
|
2697
|
+
async privateKey(keyId) {
|
|
2698
|
+
return this._keyStore.get({ alias: keyId.id });
|
|
2699
|
+
}
|
|
2700
|
+
};
|
|
2701
|
+
|
|
2702
|
+
// src/identity/identity-wallet.ts
|
|
2703
|
+
var import_js_iden3_core42 = require("@iden3/js-iden3-core");
|
|
2704
|
+
var import_js_crypto12 = require("@iden3/js-crypto");
|
|
2705
|
+
var import_js_merkletree29 = require("@iden3/js-merkletree");
|
|
2307
2706
|
|
|
2308
2707
|
// src/identity/common.ts
|
|
2708
|
+
var import_js_iden3_core9 = require("@iden3/js-iden3-core");
|
|
2309
2709
|
var subjectPositionIndex = (idPosition) => {
|
|
2310
2710
|
switch (idPosition) {
|
|
2311
|
-
case
|
|
2711
|
+
case import_js_iden3_core9.IdPosition.Index:
|
|
2312
2712
|
return "index" /* Index */;
|
|
2313
|
-
case
|
|
2713
|
+
case import_js_iden3_core9.IdPosition.Value:
|
|
2314
2714
|
return "value" /* Value */;
|
|
2315
2715
|
default:
|
|
2316
2716
|
return "" /* None */;
|
|
@@ -2318,21 +2718,21 @@ var subjectPositionIndex = (idPosition) => {
|
|
|
2318
2718
|
};
|
|
2319
2719
|
var defineMerklizedRootPosition = (metadata, position) => {
|
|
2320
2720
|
if (!metadata?.serialization) {
|
|
2321
|
-
return
|
|
2721
|
+
return import_js_iden3_core9.MerklizedRootPosition.None;
|
|
2322
2722
|
}
|
|
2323
|
-
if (position != null && position !==
|
|
2723
|
+
if (position != null && position !== import_js_iden3_core9.MerklizedRootPosition.None) {
|
|
2324
2724
|
return position;
|
|
2325
2725
|
}
|
|
2326
|
-
return
|
|
2726
|
+
return import_js_iden3_core9.MerklizedRootPosition.Index;
|
|
2327
2727
|
};
|
|
2328
2728
|
var generateProfileDID = (did, profileNonce) => {
|
|
2329
|
-
const id =
|
|
2729
|
+
const id = import_js_iden3_core9.DID.idFromDID(did);
|
|
2330
2730
|
profileNonce = profileNonce ?? 0;
|
|
2331
2731
|
if (!isBigInt(profileNonce)) {
|
|
2332
2732
|
throw new Error("profile must be number or decimal string");
|
|
2333
2733
|
}
|
|
2334
|
-
const profile =
|
|
2335
|
-
return
|
|
2734
|
+
const profile = import_js_iden3_core9.Id.profileId(id, BigInt(profileNonce));
|
|
2735
|
+
return import_js_iden3_core9.DID.parseFromId(profile);
|
|
2336
2736
|
};
|
|
2337
2737
|
var isBigInt = (x) => {
|
|
2338
2738
|
try {
|
|
@@ -2346,7 +2746,7 @@ var isBigInt = (x) => {
|
|
|
2346
2746
|
var uuid14 = __toESM(require("uuid"), 1);
|
|
2347
2747
|
|
|
2348
2748
|
// src/schema-processor/utils.ts
|
|
2349
|
-
var
|
|
2749
|
+
var import_js_iden3_core10 = require("@iden3/js-iden3-core");
|
|
2350
2750
|
var swapEndianness = (buf) => buf.reverse();
|
|
2351
2751
|
function fieldToByteArray(field) {
|
|
2352
2752
|
let bigIntField;
|
|
@@ -2357,13 +2757,13 @@ function fieldToByteArray(field) {
|
|
|
2357
2757
|
} else {
|
|
2358
2758
|
throw new Error("field type is not supported");
|
|
2359
2759
|
}
|
|
2360
|
-
return
|
|
2760
|
+
return import_js_iden3_core10.BytesHelper.intToBytes(bigIntField);
|
|
2361
2761
|
}
|
|
2362
2762
|
function dataFillsSlot(slot, newData) {
|
|
2363
|
-
return (0,
|
|
2763
|
+
return (0, import_js_iden3_core10.checkBigIntInField)(import_js_iden3_core10.BytesHelper.bytesToInt(Uint8Array.from([...slot, ...newData])));
|
|
2364
2764
|
}
|
|
2365
2765
|
function checkDataInField(data) {
|
|
2366
|
-
return (0,
|
|
2766
|
+
return (0, import_js_iden3_core10.checkBigIntInField)(import_js_iden3_core10.BytesHelper.bytesToInt(data));
|
|
2367
2767
|
}
|
|
2368
2768
|
var createSchemaHash = (schemaId) => {
|
|
2369
2769
|
return calculateCoreSchemaHash(schemaId);
|
|
@@ -3110,7 +3510,7 @@ var ValueProof = class {
|
|
|
3110
3510
|
};
|
|
3111
3511
|
|
|
3112
3512
|
// src/circuits/atomic-query-mtp-v2.ts
|
|
3113
|
-
var
|
|
3513
|
+
var import_js_iden3_core11 = require("@iden3/js-iden3-core");
|
|
3114
3514
|
var import_js_merkletree6 = require("@iden3/js-merkletree");
|
|
3115
3515
|
var AtomicQueryMTPV2Inputs = class extends BaseConfig {
|
|
3116
3516
|
// auth
|
|
@@ -3223,11 +3623,11 @@ var AtomicQueryMTPV2PubSignals = class extends BaseConfig {
|
|
|
3223
3623
|
let fieldIdx = 0;
|
|
3224
3624
|
this.merklized = parseInt(sVals[fieldIdx]);
|
|
3225
3625
|
fieldIdx++;
|
|
3226
|
-
this.userID =
|
|
3626
|
+
this.userID = import_js_iden3_core11.Id.fromBigInt(BigInt(sVals[fieldIdx]));
|
|
3227
3627
|
fieldIdx++;
|
|
3228
3628
|
this.requestID = BigInt(sVals[fieldIdx]);
|
|
3229
3629
|
fieldIdx++;
|
|
3230
|
-
this.issuerID =
|
|
3630
|
+
this.issuerID = import_js_iden3_core11.Id.fromBigInt(BigInt(sVals[fieldIdx]));
|
|
3231
3631
|
fieldIdx++;
|
|
3232
3632
|
this.issuerClaimIdenState = import_js_merkletree6.Hash.fromString(sVals[fieldIdx]);
|
|
3233
3633
|
fieldIdx++;
|
|
@@ -3237,7 +3637,7 @@ var AtomicQueryMTPV2PubSignals = class extends BaseConfig {
|
|
|
3237
3637
|
fieldIdx++;
|
|
3238
3638
|
this.timestamp = parseInt(sVals[fieldIdx]);
|
|
3239
3639
|
fieldIdx++;
|
|
3240
|
-
this.claimSchema =
|
|
3640
|
+
this.claimSchema = import_js_iden3_core11.SchemaHash.newSchemaHashFromInt(BigInt(sVals[fieldIdx]));
|
|
3241
3641
|
fieldIdx++;
|
|
3242
3642
|
this.claimPathNotExists = parseInt(sVals[fieldIdx]);
|
|
3243
3643
|
fieldIdx++;
|
|
@@ -3256,7 +3656,7 @@ var AtomicQueryMTPV2PubSignals = class extends BaseConfig {
|
|
|
3256
3656
|
};
|
|
3257
3657
|
|
|
3258
3658
|
// src/circuits/atomic-query-mtp-v2-on-chain.ts
|
|
3259
|
-
var
|
|
3659
|
+
var import_js_iden3_core12 = require("@iden3/js-iden3-core");
|
|
3260
3660
|
var import_js_merkletree7 = require("@iden3/js-merkletree");
|
|
3261
3661
|
var AtomicQueryMTPV2OnChainInputs = class extends BaseConfig {
|
|
3262
3662
|
// auth
|
|
@@ -3401,7 +3801,7 @@ var AtomicQueryMTPV2OnChainPubSignals = class extends BaseConfig {
|
|
|
3401
3801
|
let fieldIdx = 0;
|
|
3402
3802
|
this.merklized = parseInt(sVals[fieldIdx]);
|
|
3403
3803
|
fieldIdx++;
|
|
3404
|
-
this.userID =
|
|
3804
|
+
this.userID = import_js_iden3_core12.Id.fromBigInt(BigInt(sVals[fieldIdx]));
|
|
3405
3805
|
fieldIdx++;
|
|
3406
3806
|
this.circuitQueryHash = BigInt(sVals[fieldIdx]);
|
|
3407
3807
|
fieldIdx++;
|
|
@@ -3411,7 +3811,7 @@ var AtomicQueryMTPV2OnChainPubSignals = class extends BaseConfig {
|
|
|
3411
3811
|
fieldIdx++;
|
|
3412
3812
|
this.gistRoot = import_js_merkletree7.Hash.fromString(sVals[fieldIdx]);
|
|
3413
3813
|
fieldIdx++;
|
|
3414
|
-
this.issuerID =
|
|
3814
|
+
this.issuerID = import_js_iden3_core12.Id.fromBigInt(BigInt(sVals[fieldIdx]));
|
|
3415
3815
|
fieldIdx++;
|
|
3416
3816
|
this.issuerClaimIdenState = import_js_merkletree7.Hash.fromString(sVals[fieldIdx]);
|
|
3417
3817
|
fieldIdx++;
|
|
@@ -3436,7 +3836,7 @@ var AtomicQueryMTPV2OnChainPubSignals = class extends BaseConfig {
|
|
|
3436
3836
|
};
|
|
3437
3837
|
|
|
3438
3838
|
// src/circuits/atomic-query-sig-v2.ts
|
|
3439
|
-
var
|
|
3839
|
+
var import_js_iden3_core13 = require("@iden3/js-iden3-core");
|
|
3440
3840
|
var import_js_merkletree8 = require("@iden3/js-merkletree");
|
|
3441
3841
|
var AtomicQuerySigV2Inputs = class extends BaseConfig {
|
|
3442
3842
|
requestID;
|
|
@@ -3583,13 +3983,13 @@ var AtomicQuerySigV2PubSignals = class extends BaseConfig {
|
|
|
3583
3983
|
let fieldIdx = 0;
|
|
3584
3984
|
this.merklized = parseInt(sVals[fieldIdx]);
|
|
3585
3985
|
fieldIdx++;
|
|
3586
|
-
this.userID =
|
|
3986
|
+
this.userID = import_js_iden3_core13.Id.fromBigInt(BigInt(sVals[fieldIdx]));
|
|
3587
3987
|
fieldIdx++;
|
|
3588
3988
|
this.issuerAuthState = import_js_merkletree8.Hash.fromString(sVals[fieldIdx]);
|
|
3589
3989
|
fieldIdx++;
|
|
3590
3990
|
this.requestID = BigInt(sVals[fieldIdx]);
|
|
3591
3991
|
fieldIdx++;
|
|
3592
|
-
this.issuerID =
|
|
3992
|
+
this.issuerID = import_js_iden3_core13.Id.fromBigInt(BigInt(sVals[fieldIdx]));
|
|
3593
3993
|
fieldIdx++;
|
|
3594
3994
|
this.isRevocationChecked = parseInt(sVals[fieldIdx]);
|
|
3595
3995
|
fieldIdx++;
|
|
@@ -3597,7 +3997,7 @@ var AtomicQuerySigV2PubSignals = class extends BaseConfig {
|
|
|
3597
3997
|
fieldIdx++;
|
|
3598
3998
|
this.timestamp = parseInt(sVals[fieldIdx]);
|
|
3599
3999
|
fieldIdx++;
|
|
3600
|
-
this.claimSchema =
|
|
4000
|
+
this.claimSchema = import_js_iden3_core13.SchemaHash.newSchemaHashFromInt(BigInt(sVals[fieldIdx]));
|
|
3601
4001
|
fieldIdx++;
|
|
3602
4002
|
this.claimPathNotExists = parseInt(sVals[fieldIdx]);
|
|
3603
4003
|
fieldIdx++;
|
|
@@ -3616,7 +4016,7 @@ var AtomicQuerySigV2PubSignals = class extends BaseConfig {
|
|
|
3616
4016
|
};
|
|
3617
4017
|
|
|
3618
4018
|
// src/circuits/atomic-query-v3.ts
|
|
3619
|
-
var
|
|
4019
|
+
var import_js_iden3_core14 = require("@iden3/js-iden3-core");
|
|
3620
4020
|
var import_js_merkletree9 = require("@iden3/js-merkletree");
|
|
3621
4021
|
var zero = "0";
|
|
3622
4022
|
var AtomicQueryV3Inputs = class extends BaseConfig {
|
|
@@ -3674,7 +4074,7 @@ var AtomicQueryV3Inputs = class extends BaseConfig {
|
|
|
3674
4074
|
s.issuerClaimSignatureR8x = zero;
|
|
3675
4075
|
s.issuerClaimSignatureR8y = zero;
|
|
3676
4076
|
s.issuerClaimSignatureS = zero;
|
|
3677
|
-
s.issuerAuthClaim = new
|
|
4077
|
+
s.issuerAuthClaim = new import_js_iden3_core14.Claim().marshalJson();
|
|
3678
4078
|
s.issuerAuthClaimMtp = prepareSiblingsStr(new import_js_merkletree9.Proof(), this.getMTLevel());
|
|
3679
4079
|
s.issuerAuthClaimsTreeRoot = zero;
|
|
3680
4080
|
s.issuerAuthRevTreeRoot = zero;
|
|
@@ -3821,7 +4221,7 @@ var AtomicQueryV3PubSignals = class extends BaseConfig {
|
|
|
3821
4221
|
let fieldIdx = 0;
|
|
3822
4222
|
this.merklized = parseInt(sVals[fieldIdx]);
|
|
3823
4223
|
fieldIdx++;
|
|
3824
|
-
this.userID =
|
|
4224
|
+
this.userID = import_js_iden3_core14.Id.fromBigInt(BigInt(sVals[fieldIdx]));
|
|
3825
4225
|
fieldIdx++;
|
|
3826
4226
|
this.issuerState = import_js_merkletree9.Hash.fromString(sVals[fieldIdx]);
|
|
3827
4227
|
fieldIdx++;
|
|
@@ -3835,7 +4235,7 @@ var AtomicQueryV3PubSignals = class extends BaseConfig {
|
|
|
3835
4235
|
fieldIdx++;
|
|
3836
4236
|
this.requestID = BigInt(sVals[fieldIdx]);
|
|
3837
4237
|
fieldIdx++;
|
|
3838
|
-
this.issuerID =
|
|
4238
|
+
this.issuerID = import_js_iden3_core14.Id.fromBigInt(BigInt(sVals[fieldIdx]));
|
|
3839
4239
|
fieldIdx++;
|
|
3840
4240
|
this.isRevocationChecked = parseInt(sVals[fieldIdx]);
|
|
3841
4241
|
fieldIdx++;
|
|
@@ -3843,7 +4243,7 @@ var AtomicQueryV3PubSignals = class extends BaseConfig {
|
|
|
3843
4243
|
fieldIdx++;
|
|
3844
4244
|
this.timestamp = parseInt(sVals[fieldIdx]);
|
|
3845
4245
|
fieldIdx++;
|
|
3846
|
-
this.claimSchema =
|
|
4246
|
+
this.claimSchema = import_js_iden3_core14.SchemaHash.newSchemaHashFromInt(BigInt(sVals[fieldIdx]));
|
|
3847
4247
|
fieldIdx++;
|
|
3848
4248
|
this.claimPathKey = BigInt(sVals[fieldIdx]);
|
|
3849
4249
|
fieldIdx++;
|
|
@@ -3858,7 +4258,7 @@ var AtomicQueryV3PubSignals = class extends BaseConfig {
|
|
|
3858
4258
|
this.valueArraySize = parseInt(sVals[fieldIdx]);
|
|
3859
4259
|
fieldIdx++;
|
|
3860
4260
|
if (sVals[fieldIdx] !== "0") {
|
|
3861
|
-
this.verifierID =
|
|
4261
|
+
this.verifierID = import_js_iden3_core14.Id.fromBigInt(BigInt(sVals[fieldIdx]));
|
|
3862
4262
|
}
|
|
3863
4263
|
fieldIdx++;
|
|
3864
4264
|
this.nullifierSessionID = BigInt(sVals[fieldIdx]);
|
|
@@ -3867,7 +4267,7 @@ var AtomicQueryV3PubSignals = class extends BaseConfig {
|
|
|
3867
4267
|
};
|
|
3868
4268
|
|
|
3869
4269
|
// src/circuits/atomic-query-v3-on-chain.ts
|
|
3870
|
-
var
|
|
4270
|
+
var import_js_iden3_core15 = require("@iden3/js-iden3-core");
|
|
3871
4271
|
var import_js_merkletree10 = require("@iden3/js-merkletree");
|
|
3872
4272
|
var zero2 = "0";
|
|
3873
4273
|
var AtomicQueryV3OnChainInputs = class extends BaseConfig {
|
|
@@ -3951,7 +4351,7 @@ var AtomicQueryV3OnChainInputs = class extends BaseConfig {
|
|
|
3951
4351
|
s.issuerClaimSignatureR8x = zero2;
|
|
3952
4352
|
s.issuerClaimSignatureR8y = zero2;
|
|
3953
4353
|
s.issuerClaimSignatureS = zero2;
|
|
3954
|
-
s.issuerAuthClaim = new
|
|
4354
|
+
s.issuerAuthClaim = new import_js_iden3_core15.Claim().marshalJson();
|
|
3955
4355
|
s.issuerAuthClaimMtp = prepareSiblingsStr(new import_js_merkletree10.Proof(), this.getMTLevel());
|
|
3956
4356
|
s.issuerAuthClaimsTreeRoot = zero2;
|
|
3957
4357
|
s.issuerAuthRevTreeRoot = zero2;
|
|
@@ -3963,7 +4363,7 @@ var AtomicQueryV3OnChainInputs = class extends BaseConfig {
|
|
|
3963
4363
|
s.issuerAuthState = zero2;
|
|
3964
4364
|
}
|
|
3965
4365
|
fillAuthWithZero(s) {
|
|
3966
|
-
s.authClaim = new
|
|
4366
|
+
s.authClaim = new import_js_iden3_core15.Claim().marshalJson();
|
|
3967
4367
|
s.userClaimsTreeRoot = import_js_merkletree10.ZERO_HASH.bigInt().toString();
|
|
3968
4368
|
s.userRevTreeRoot = import_js_merkletree10.ZERO_HASH.bigInt().toString();
|
|
3969
4369
|
s.userRootsTreeRoot = import_js_merkletree10.ZERO_HASH.bigInt().toString();
|
|
@@ -4134,7 +4534,7 @@ var AtomicQueryV3OnChainPubSignals = class extends BaseConfig {
|
|
|
4134
4534
|
pubSignalsUnmarshal(data) {
|
|
4135
4535
|
const sVals = JSON.parse(byteDecoder.decode(data));
|
|
4136
4536
|
let fieldIdx = 0;
|
|
4137
|
-
this.userID =
|
|
4537
|
+
this.userID = import_js_iden3_core15.Id.fromBigInt(BigInt(sVals[fieldIdx]));
|
|
4138
4538
|
fieldIdx++;
|
|
4139
4539
|
this.circuitQueryHash = BigInt(sVals[fieldIdx]);
|
|
4140
4540
|
fieldIdx++;
|
|
@@ -4154,7 +4554,7 @@ var AtomicQueryV3OnChainPubSignals = class extends BaseConfig {
|
|
|
4154
4554
|
fieldIdx++;
|
|
4155
4555
|
this.gistRoot = import_js_merkletree10.Hash.fromString(sVals[fieldIdx]);
|
|
4156
4556
|
fieldIdx++;
|
|
4157
|
-
this.issuerID =
|
|
4557
|
+
this.issuerID = import_js_iden3_core15.Id.fromBigInt(BigInt(sVals[fieldIdx]));
|
|
4158
4558
|
fieldIdx++;
|
|
4159
4559
|
this.issuerClaimNonRevState = import_js_merkletree10.Hash.fromString(sVals[fieldIdx]);
|
|
4160
4560
|
fieldIdx++;
|
|
@@ -4176,7 +4576,7 @@ var AtomicQueryV3OnChainPubSignals = class extends BaseConfig {
|
|
|
4176
4576
|
};
|
|
4177
4577
|
|
|
4178
4578
|
// src/circuits/atomic-query-sig-v2-on-chain.ts
|
|
4179
|
-
var
|
|
4579
|
+
var import_js_iden3_core16 = require("@iden3/js-iden3-core");
|
|
4180
4580
|
var import_js_merkletree11 = require("@iden3/js-merkletree");
|
|
4181
4581
|
var AtomicQuerySigV2OnChainInputs = class extends BaseConfig {
|
|
4182
4582
|
requestID;
|
|
@@ -4427,7 +4827,7 @@ var AtomicQuerySigV2OnChainPubSignals = class extends BaseConfig {
|
|
|
4427
4827
|
let fieldIdx = 0;
|
|
4428
4828
|
this.merklized = parseInt(sVals[fieldIdx]);
|
|
4429
4829
|
fieldIdx++;
|
|
4430
|
-
this.userID =
|
|
4830
|
+
this.userID = import_js_iden3_core16.Id.fromBigInt(BigInt(sVals[fieldIdx]));
|
|
4431
4831
|
fieldIdx++;
|
|
4432
4832
|
this.circuitQueryHash = BigInt(sVals[fieldIdx]);
|
|
4433
4833
|
fieldIdx++;
|
|
@@ -4439,7 +4839,7 @@ var AtomicQuerySigV2OnChainPubSignals = class extends BaseConfig {
|
|
|
4439
4839
|
fieldIdx++;
|
|
4440
4840
|
this.gistRoot = import_js_merkletree11.Hash.fromString(sVals[fieldIdx]);
|
|
4441
4841
|
fieldIdx++;
|
|
4442
|
-
this.issuerID =
|
|
4842
|
+
this.issuerID = import_js_iden3_core16.Id.fromBigInt(BigInt(sVals[fieldIdx]));
|
|
4443
4843
|
fieldIdx++;
|
|
4444
4844
|
this.isRevocationChecked = parseInt(sVals[fieldIdx]);
|
|
4445
4845
|
fieldIdx++;
|
|
@@ -4463,7 +4863,7 @@ var AtomicQuerySigV2OnChainPubSignals = class extends BaseConfig {
|
|
|
4463
4863
|
|
|
4464
4864
|
// src/circuits/auth-v2.ts
|
|
4465
4865
|
var import_js_merkletree12 = require("@iden3/js-merkletree");
|
|
4466
|
-
var
|
|
4866
|
+
var import_js_iden3_core17 = require("@iden3/js-iden3-core");
|
|
4467
4867
|
var AuthV2Inputs = class extends BaseConfig {
|
|
4468
4868
|
genesisID;
|
|
4469
4869
|
profileNonce;
|
|
@@ -4541,7 +4941,7 @@ var AuthV2PubSignals = class {
|
|
|
4541
4941
|
if (sVals.length !== len) {
|
|
4542
4942
|
throw new Error(`invalid number of Output values expected ${len} got ${sVals.length}`);
|
|
4543
4943
|
}
|
|
4544
|
-
this.userID =
|
|
4944
|
+
this.userID = import_js_iden3_core17.Id.fromBigInt(BigInt(sVals[0]));
|
|
4545
4945
|
this.challenge = BigInt(sVals[1]);
|
|
4546
4946
|
this.GISTRoot = import_js_merkletree12.Hash.fromString(sVals[2]);
|
|
4547
4947
|
return this;
|
|
@@ -4555,7 +4955,7 @@ var AuthV2PubSignals = class {
|
|
|
4555
4955
|
};
|
|
4556
4956
|
|
|
4557
4957
|
// src/circuits/state-transition.ts
|
|
4558
|
-
var
|
|
4958
|
+
var import_js_iden3_core18 = require("@iden3/js-iden3-core");
|
|
4559
4959
|
var import_js_merkletree13 = require("@iden3/js-merkletree");
|
|
4560
4960
|
var StateTransitionInputs = class extends BaseConfig {
|
|
4561
4961
|
id;
|
|
@@ -4630,7 +5030,7 @@ var StateTransitionPubSignals = class {
|
|
|
4630
5030
|
`invalid number of Output values expected ${fieldLength} got ${sVals.length}`
|
|
4631
5031
|
);
|
|
4632
5032
|
}
|
|
4633
|
-
this.userId =
|
|
5033
|
+
this.userId = import_js_iden3_core18.Id.fromBigInt(BigInt(sVals[0]));
|
|
4634
5034
|
this.oldUserState = import_js_merkletree13.Hash.fromString(sVals[1]);
|
|
4635
5035
|
this.newUserState = import_js_merkletree13.Hash.fromString(sVals[2]);
|
|
4636
5036
|
this.isOldStateGenesis = BigInt(sVals[3]) === BigInt(1);
|
|
@@ -4752,7 +5152,7 @@ var LinkedMultiQueryPubSignals = class {
|
|
|
4752
5152
|
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" }];
|
|
4753
5153
|
|
|
4754
5154
|
// src/storage/blockchain/state.ts
|
|
4755
|
-
var
|
|
5155
|
+
var import_js_iden3_core32 = require("@iden3/js-iden3-core");
|
|
4756
5156
|
|
|
4757
5157
|
// src/blockchain/transaction-service.ts
|
|
4758
5158
|
var TransactionService = class {
|
|
@@ -4801,9 +5201,9 @@ var TransactionService = class {
|
|
|
4801
5201
|
};
|
|
4802
5202
|
|
|
4803
5203
|
// src/storage/blockchain/common.ts
|
|
4804
|
-
var
|
|
5204
|
+
var import_ethers4 = require("ethers");
|
|
4805
5205
|
var packZkpProof = (inputs, a, b, c) => {
|
|
4806
|
-
return new
|
|
5206
|
+
return new import_ethers4.ethers.AbiCoder().encode(
|
|
4807
5207
|
["uint256[] inputs", "uint256[2]", "uint256[2][2]", "uint256[2]"],
|
|
4808
5208
|
[inputs, a, b, c]
|
|
4809
5209
|
);
|
|
@@ -5405,7 +5805,7 @@ var PackageManager = class {
|
|
|
5405
5805
|
|
|
5406
5806
|
// src/iden3comm/packers/zkp.ts
|
|
5407
5807
|
var import_js_jwz2 = require("@iden3/js-jwz");
|
|
5408
|
-
var
|
|
5808
|
+
var import_js_iden3_core19 = require("@iden3/js-iden3-core");
|
|
5409
5809
|
|
|
5410
5810
|
// src/iden3comm/constants.ts
|
|
5411
5811
|
var constants_exports = {};
|
|
@@ -5822,9 +6222,9 @@ var verifySender = async (token, msg) => {
|
|
|
5822
6222
|
const authSignals = new AuthV2PubSignals().pubSignalsUnmarshal(
|
|
5823
6223
|
byteEncoder.encode(JSON.stringify(token.zkProof.pub_signals))
|
|
5824
6224
|
);
|
|
5825
|
-
const did =
|
|
6225
|
+
const did = import_js_iden3_core19.DID.parseFromId(authSignals.userID);
|
|
5826
6226
|
const msgHash = await token.getMessageHash();
|
|
5827
|
-
const challenge =
|
|
6227
|
+
const challenge = import_js_iden3_core19.BytesHelper.bytesToInt(msgHash.reverse());
|
|
5828
6228
|
if (challenge !== authSignals.challenge) {
|
|
5829
6229
|
throw new Error(ErrSenderNotUsedTokenCreation);
|
|
5830
6230
|
}
|
|
@@ -6101,14 +6501,14 @@ var DiscoveryProtocolFeatureType = /* @__PURE__ */ ((DiscoveryProtocolFeatureTyp
|
|
|
6101
6501
|
})(DiscoveryProtocolFeatureType || {});
|
|
6102
6502
|
|
|
6103
6503
|
// src/iden3comm/handlers/auth.ts
|
|
6104
|
-
var
|
|
6504
|
+
var import_js_iden3_core21 = require("@iden3/js-iden3-core");
|
|
6105
6505
|
var import_js_jwz4 = require("@iden3/js-jwz");
|
|
6106
6506
|
var uuid2 = __toESM(require("uuid"), 1);
|
|
6107
6507
|
|
|
6108
6508
|
// src/iden3comm/handlers/common.ts
|
|
6109
6509
|
var import_js_crypto9 = require("@iden3/js-crypto");
|
|
6110
|
-
var
|
|
6111
|
-
var
|
|
6510
|
+
var import_js_iden3_core20 = require("@iden3/js-iden3-core");
|
|
6511
|
+
var import_ethers5 = require("ethers");
|
|
6112
6512
|
var getGroupedQueries = (requestScope) => requestScope.reduce((acc, proofReq) => {
|
|
6113
6513
|
const groupId = proofReq.query.groupId;
|
|
6114
6514
|
if (!groupId) {
|
|
@@ -6275,8 +6675,8 @@ var calcChallengeAuthV2 = (senderAddress, zkpResponses) => {
|
|
|
6275
6675
|
};
|
|
6276
6676
|
});
|
|
6277
6677
|
return BigInt(
|
|
6278
|
-
|
|
6279
|
-
new
|
|
6678
|
+
import_ethers5.ethers.keccak256(
|
|
6679
|
+
new import_ethers5.ethers.AbiCoder().encode(
|
|
6280
6680
|
["address", "(uint256 requestId,bytes proof,bytes metadata)[]"],
|
|
6281
6681
|
[senderAddress, responses]
|
|
6282
6682
|
)
|
|
@@ -6284,10 +6684,10 @@ var calcChallengeAuthV2 = (senderAddress, zkpResponses) => {
|
|
|
6284
6684
|
) & BigInt("0x0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
|
|
6285
6685
|
};
|
|
6286
6686
|
var packMetadatas = (metas) => {
|
|
6287
|
-
return new
|
|
6687
|
+
return new import_ethers5.ethers.AbiCoder().encode(["tuple(string key,bytes value)[]"], [metas]);
|
|
6288
6688
|
};
|
|
6289
6689
|
var verifyExpiresTime = (message) => {
|
|
6290
|
-
if (message?.expires_time && message.expires_time < (0,
|
|
6690
|
+
if (message?.expires_time && message.expires_time < (0, import_js_iden3_core20.getUnixTimestamp)(/* @__PURE__ */ new Date())) {
|
|
6291
6691
|
throw new Error("Message expired");
|
|
6292
6692
|
}
|
|
6293
6693
|
};
|
|
@@ -6405,8 +6805,8 @@ function createAuthorizationRequestWithMessage(reason, message, sender, callback
|
|
|
6405
6805
|
callbackUrl,
|
|
6406
6806
|
scope: opts?.scope ?? []
|
|
6407
6807
|
},
|
|
6408
|
-
created_time: (0,
|
|
6409
|
-
expires_time: opts?.expires_time ? (0,
|
|
6808
|
+
created_time: (0, import_js_iden3_core21.getUnixTimestamp)(/* @__PURE__ */ new Date()),
|
|
6809
|
+
expires_time: opts?.expires_time ? (0, import_js_iden3_core21.getUnixTimestamp)(opts.expires_time) : void 0,
|
|
6410
6810
|
attachments: opts?.attachments
|
|
6411
6811
|
};
|
|
6412
6812
|
return request;
|
|
@@ -6461,7 +6861,7 @@ var AuthHandler = class extends AbstractMessageHandler {
|
|
|
6461
6861
|
if (authRequest.type !== PROTOCOL_MESSAGE_TYPE.AUTHORIZATION_REQUEST_MESSAGE_TYPE) {
|
|
6462
6862
|
throw new Error("Invalid message type for authorization request");
|
|
6463
6863
|
}
|
|
6464
|
-
const to = authRequest.to ?
|
|
6864
|
+
const to = authRequest.to ? import_js_iden3_core21.DID.parse(authRequest.to) : ctx.senderDid;
|
|
6465
6865
|
const guid = uuid2.v4();
|
|
6466
6866
|
if (!authRequest.from) {
|
|
6467
6867
|
throw new Error("auth request should contain from field");
|
|
@@ -6472,7 +6872,7 @@ var AuthHandler = class extends AbstractMessageHandler {
|
|
|
6472
6872
|
responseType,
|
|
6473
6873
|
authRequest.body.accept
|
|
6474
6874
|
);
|
|
6475
|
-
const from =
|
|
6875
|
+
const from = import_js_iden3_core21.DID.parse(authRequest.from);
|
|
6476
6876
|
const responseScope = await processZeroKnowledgeProofRequests(
|
|
6477
6877
|
to,
|
|
6478
6878
|
authRequest?.body.scope,
|
|
@@ -6560,7 +6960,7 @@ var AuthHandler = class extends AbstractMessageHandler {
|
|
|
6560
6960
|
);
|
|
6561
6961
|
}
|
|
6562
6962
|
const params = proofRequest.params ?? {};
|
|
6563
|
-
params.verifierDid =
|
|
6963
|
+
params.verifierDid = import_js_iden3_core21.DID.parse(request.from);
|
|
6564
6964
|
const opts = [ctx.acceptedProofGenerationDelay, ctx.acceptedStateTransitionDelay].some(
|
|
6565
6965
|
(delay) => delay !== void 0
|
|
6566
6966
|
) ? {
|
|
@@ -6653,7 +7053,7 @@ var AuthHandler = class extends AbstractMessageHandler {
|
|
|
6653
7053
|
};
|
|
6654
7054
|
|
|
6655
7055
|
// src/storage/blockchain/onchain-revocation.ts
|
|
6656
|
-
var
|
|
7056
|
+
var import_ethers6 = require("ethers");
|
|
6657
7057
|
var import_js_merkletree16 = require("@iden3/js-merkletree");
|
|
6658
7058
|
|
|
6659
7059
|
// src/storage/blockchain/abi/CredentialStatusResolver.json
|
|
@@ -6671,8 +7071,8 @@ var OnChainRevocationStorage = class _OnChainRevocationStorage {
|
|
|
6671
7071
|
constructor(_config, contractAddress, _signer) {
|
|
6672
7072
|
this._config = _config;
|
|
6673
7073
|
this._signer = _signer;
|
|
6674
|
-
this._provider = new
|
|
6675
|
-
let contract = new
|
|
7074
|
+
this._provider = new import_ethers6.JsonRpcProvider(_config.url);
|
|
7075
|
+
let contract = new import_ethers6.Contract(contractAddress, CredentialStatusResolver_default, this._provider);
|
|
6676
7076
|
if (this._signer) {
|
|
6677
7077
|
this._signer = this._signer.connect(this._provider);
|
|
6678
7078
|
contract = contract.connect(this._signer);
|
|
@@ -6758,7 +7158,7 @@ var OnChainRevocationStorage = class _OnChainRevocationStorage {
|
|
|
6758
7158
|
};
|
|
6759
7159
|
|
|
6760
7160
|
// src/credentials/status/on-chain-revocation.ts
|
|
6761
|
-
var
|
|
7161
|
+
var import_js_iden3_core22 = require("@iden3/js-iden3-core");
|
|
6762
7162
|
var import_js_merkletree17 = require("@iden3/js-merkletree");
|
|
6763
7163
|
|
|
6764
7164
|
// src/storage/blockchain/errors.ts
|
|
@@ -6823,7 +7223,7 @@ var OnChainResolver = class {
|
|
|
6823
7223
|
if (revocationNonce !== credentialStatus.revocationNonce) {
|
|
6824
7224
|
throw new Error("revocationNonce does not match");
|
|
6825
7225
|
}
|
|
6826
|
-
const issuerId =
|
|
7226
|
+
const issuerId = import_js_iden3_core22.DID.idFromDID(issuer);
|
|
6827
7227
|
let latestIssuerState;
|
|
6828
7228
|
try {
|
|
6829
7229
|
const latestStateInfo = await this._stateStorage.getLatestStateById(issuerId.bigInt());
|
|
@@ -6848,7 +7248,7 @@ var OnChainResolver = class {
|
|
|
6848
7248
|
}
|
|
6849
7249
|
latestIssuerState = stateBigInt;
|
|
6850
7250
|
}
|
|
6851
|
-
const id =
|
|
7251
|
+
const id = import_js_iden3_core22.DID.idFromDID(issuer);
|
|
6852
7252
|
const onChainCaller = this._getOnChainRevocationStorageForIssuer(chainId, contractAddress);
|
|
6853
7253
|
const revocationStatus = await onChainCaller.getRevocationStatusByIdAndState(
|
|
6854
7254
|
id.bigInt(),
|
|
@@ -6905,7 +7305,7 @@ var OnChainResolver = class {
|
|
|
6905
7305
|
};
|
|
6906
7306
|
|
|
6907
7307
|
// src/credentials/status/reverse-sparse-merkle-tree.ts
|
|
6908
|
-
var
|
|
7308
|
+
var import_js_iden3_core23 = require("@iden3/js-iden3-core");
|
|
6909
7309
|
var import_js_merkletree19 = require("@iden3/js-merkletree");
|
|
6910
7310
|
|
|
6911
7311
|
// src/credentials/status/sparse-merkle-tree.ts
|
|
@@ -7031,7 +7431,7 @@ var RHSResolver = class {
|
|
|
7031
7431
|
* @returns Promise<RevocationStatus>
|
|
7032
7432
|
*/
|
|
7033
7433
|
async getStatus(credentialStatus, issuerDID, issuerData, genesisState) {
|
|
7034
|
-
const issuerId =
|
|
7434
|
+
const issuerId = import_js_iden3_core23.DID.idFromDID(issuerDID);
|
|
7035
7435
|
let latestState;
|
|
7036
7436
|
try {
|
|
7037
7437
|
const latestStateInfo = await this._state.getLatestStateById(issuerId.bigInt());
|
|
@@ -7173,16 +7573,16 @@ var RHSResolver = class {
|
|
|
7173
7573
|
}
|
|
7174
7574
|
};
|
|
7175
7575
|
function isIssuerGenesis(issuer, state) {
|
|
7176
|
-
const did =
|
|
7177
|
-
const id =
|
|
7178
|
-
const { method, blockchain, networkId } =
|
|
7179
|
-
const arr =
|
|
7180
|
-
const stateBigInt =
|
|
7181
|
-
const type = (0,
|
|
7182
|
-
return isGenesisStateId(
|
|
7576
|
+
const did = import_js_iden3_core23.DID.parse(issuer);
|
|
7577
|
+
const id = import_js_iden3_core23.DID.idFromDID(did);
|
|
7578
|
+
const { method, blockchain, networkId } = import_js_iden3_core23.DID.decodePartsFromId(id);
|
|
7579
|
+
const arr = import_js_iden3_core23.BytesHelper.hexToBytes(state);
|
|
7580
|
+
const stateBigInt = import_js_iden3_core23.BytesHelper.bytesToInt(arr);
|
|
7581
|
+
const type = (0, import_js_iden3_core23.buildDIDType)(method, blockchain, networkId);
|
|
7582
|
+
return isGenesisStateId(import_js_iden3_core23.DID.idFromDID(did).bigInt(), stateBigInt, type);
|
|
7183
7583
|
}
|
|
7184
7584
|
function isGenesisStateId(id, state, type) {
|
|
7185
|
-
const idFromState =
|
|
7585
|
+
const idFromState = import_js_iden3_core23.Id.idGenesisFromIdenState(type, state);
|
|
7186
7586
|
return id.toString() === idFromState.bigInt().toString();
|
|
7187
7587
|
}
|
|
7188
7588
|
|
|
@@ -7377,7 +7777,7 @@ var DidDocumentCredentialStatusResolver = class {
|
|
|
7377
7777
|
};
|
|
7378
7778
|
|
|
7379
7779
|
// src/credentials/credential-wallet.ts
|
|
7380
|
-
var
|
|
7780
|
+
var import_js_iden3_core24 = require("@iden3/js-iden3-core");
|
|
7381
7781
|
var uuid4 = __toESM(require("uuid"), 1);
|
|
7382
7782
|
var CredentialWallet = class {
|
|
7383
7783
|
/**
|
|
@@ -7439,7 +7839,7 @@ var CredentialWallet = class {
|
|
|
7439
7839
|
const mtpProof = cred.getIden3SparseMerkleTreeProof();
|
|
7440
7840
|
const sigProof = cred.getBJJSignature2021Proof();
|
|
7441
7841
|
const stateInfo = mtpProof ? mtpProof.issuerData.state : sigProof?.issuerData.state;
|
|
7442
|
-
const issuerDID =
|
|
7842
|
+
const issuerDID = import_js_iden3_core24.DID.parse(cred.issuer);
|
|
7443
7843
|
const userDID = getUserDIDFromCredential(issuerDID, cred);
|
|
7444
7844
|
const opts = {
|
|
7445
7845
|
issuerGenesisState: stateInfo,
|
|
@@ -7638,7 +8038,7 @@ async function buildNodesUp(siblings, node) {
|
|
|
7638
8038
|
|
|
7639
8039
|
// src/iden3comm/handlers/fetch.ts
|
|
7640
8040
|
var import_js_jwz5 = require("@iden3/js-jwz");
|
|
7641
|
-
var
|
|
8041
|
+
var import_js_iden3_core25 = require("@iden3/js-iden3-core");
|
|
7642
8042
|
var uuid5 = __toESM(require("uuid"), 1);
|
|
7643
8043
|
var FetchHandler = class _FetchHandler extends AbstractMessageHandler {
|
|
7644
8044
|
/**
|
|
@@ -7691,8 +8091,8 @@ var FetchHandler = class _FetchHandler extends AbstractMessageHandler {
|
|
|
7691
8091
|
}
|
|
7692
8092
|
const credentials = [];
|
|
7693
8093
|
for (const credentialInfo of offerMessage.body.credentials) {
|
|
7694
|
-
const issuerDID =
|
|
7695
|
-
const userDID =
|
|
8094
|
+
const issuerDID = import_js_iden3_core25.DID.parse(offerMessage.from);
|
|
8095
|
+
const userDID = import_js_iden3_core25.DID.parse(offerMessage.to);
|
|
7696
8096
|
const credential = await this.opts.onchainIssuer.getCredential(
|
|
7697
8097
|
issuerDID,
|
|
7698
8098
|
userDID,
|
|
@@ -7724,7 +8124,7 @@ var FetchHandler = class _FetchHandler extends AbstractMessageHandler {
|
|
|
7724
8124
|
const packerOpts = ctx.mediaType === "application/iden3comm-signed-json" /* SignedMessage */ ? ctx.packerOptions : {
|
|
7725
8125
|
provingMethodAlg: import_js_jwz5.proving.provingMethodGroth16AuthV2Instance.methodAlg
|
|
7726
8126
|
};
|
|
7727
|
-
const senderDID =
|
|
8127
|
+
const senderDID = import_js_iden3_core25.DID.parse(offerMessage.to);
|
|
7728
8128
|
const token = byteDecoder.decode(
|
|
7729
8129
|
await this._packerMgr.pack(ctx.mediaType, msgBytes, {
|
|
7730
8130
|
senderDID,
|
|
@@ -7814,8 +8214,8 @@ var FetchHandler = class _FetchHandler extends AbstractMessageHandler {
|
|
|
7814
8214
|
if (!msgRequest.from) {
|
|
7815
8215
|
throw new Error("failed request. empty 'from' field");
|
|
7816
8216
|
}
|
|
7817
|
-
const issuerDID =
|
|
7818
|
-
const userDID =
|
|
8217
|
+
const issuerDID = import_js_iden3_core25.DID.parse(msgRequest.to);
|
|
8218
|
+
const userDID = import_js_iden3_core25.DID.parse(msgRequest.from);
|
|
7819
8219
|
const credId = msgRequest.body?.id;
|
|
7820
8220
|
if (!credId) {
|
|
7821
8221
|
throw new Error("invalid credential id in fetch request body");
|
|
@@ -7903,7 +8303,7 @@ var FetchHandler = class _FetchHandler extends AbstractMessageHandler {
|
|
|
7903
8303
|
};
|
|
7904
8304
|
|
|
7905
8305
|
// src/iden3comm/handlers/contract-request.ts
|
|
7906
|
-
var
|
|
8306
|
+
var import_js_iden3_core26 = require("@iden3/js-iden3-core");
|
|
7907
8307
|
var ContractRequestHandler = class extends AbstractMessageHandler {
|
|
7908
8308
|
/**
|
|
7909
8309
|
* Creates an instance of ContractRequestHandler.
|
|
@@ -7950,11 +8350,11 @@ var ContractRequestHandler = class extends AbstractMessageHandler {
|
|
|
7950
8350
|
throw new Error("Can't sign transaction. Provide Signer in options.");
|
|
7951
8351
|
}
|
|
7952
8352
|
const { chain_id } = message.body.transaction_data;
|
|
7953
|
-
const networkFlag = Object.keys(
|
|
8353
|
+
const networkFlag = Object.keys(import_js_iden3_core26.ChainIds).find((key) => import_js_iden3_core26.ChainIds[key] === chain_id);
|
|
7954
8354
|
if (!networkFlag) {
|
|
7955
8355
|
throw new Error(`Invalid chain id ${chain_id}`);
|
|
7956
8356
|
}
|
|
7957
|
-
const verifierDid = message.from ?
|
|
8357
|
+
const verifierDid = message.from ? import_js_iden3_core26.DID.parse(message.from) : void 0;
|
|
7958
8358
|
const { scope = [] } = message.body;
|
|
7959
8359
|
const zkpResponses = await processZeroKnowledgeProofRequests(
|
|
7960
8360
|
did,
|
|
@@ -7963,7 +8363,7 @@ var ContractRequestHandler = class extends AbstractMessageHandler {
|
|
|
7963
8363
|
this._proofService,
|
|
7964
8364
|
{
|
|
7965
8365
|
ethSigner,
|
|
7966
|
-
challenge: challenge ??
|
|
8366
|
+
challenge: challenge ?? import_js_iden3_core26.BytesHelper.bytesToInt(hexToBytes(await ethSigner.getAddress())),
|
|
7967
8367
|
supportedCircuits: this._supportedCircuits
|
|
7968
8368
|
}
|
|
7969
8369
|
);
|
|
@@ -8003,7 +8403,7 @@ var ContractRequestHandler = class extends AbstractMessageHandler {
|
|
|
8003
8403
|
PROTOCOL_MESSAGE_TYPE.CONTRACT_INVOKE_REQUEST_MESSAGE_TYPE,
|
|
8004
8404
|
message.body.accept
|
|
8005
8405
|
);
|
|
8006
|
-
const identifier =
|
|
8406
|
+
const identifier = import_js_iden3_core26.DID.parse(message.to);
|
|
8007
8407
|
const { authProof } = await processProofAuth(identifier, this._proofService, {
|
|
8008
8408
|
supportedCircuits: this._supportedCircuits,
|
|
8009
8409
|
acceptProfile,
|
|
@@ -8074,7 +8474,7 @@ var ContractRequestHandler = class extends AbstractMessageHandler {
|
|
|
8074
8474
|
transaction_data: request.body.transaction_data,
|
|
8075
8475
|
scope: []
|
|
8076
8476
|
},
|
|
8077
|
-
created_time: (0,
|
|
8477
|
+
created_time: (0, import_js_iden3_core26.getUnixTimestamp)(/* @__PURE__ */ new Date())
|
|
8078
8478
|
};
|
|
8079
8479
|
for (const [txHash, zkpResponses] of txHashToZkpResponseMap) {
|
|
8080
8480
|
for (const zkpResponse of zkpResponses.responses) {
|
|
@@ -8117,11 +8517,11 @@ var ContractRequestHandler = class extends AbstractMessageHandler {
|
|
|
8117
8517
|
throw new Error("Can't sign transaction. Provide Signer in options.");
|
|
8118
8518
|
}
|
|
8119
8519
|
const { chain_id } = ciRequest.body.transaction_data;
|
|
8120
|
-
const networkFlag = Object.keys(
|
|
8520
|
+
const networkFlag = Object.keys(import_js_iden3_core26.ChainIds).find((key) => import_js_iden3_core26.ChainIds[key] === chain_id);
|
|
8121
8521
|
if (!networkFlag) {
|
|
8122
8522
|
throw new Error(`Invalid chain id ${chain_id}`);
|
|
8123
8523
|
}
|
|
8124
|
-
const verifierDid = ciRequest.from ?
|
|
8524
|
+
const verifierDid = ciRequest.from ? import_js_iden3_core26.DID.parse(ciRequest.from) : void 0;
|
|
8125
8525
|
const zkpResponses = await processZeroKnowledgeProofRequests(
|
|
8126
8526
|
did,
|
|
8127
8527
|
ciRequest?.body?.scope,
|
|
@@ -8139,7 +8539,7 @@ var ContractRequestHandler = class extends AbstractMessageHandler {
|
|
|
8139
8539
|
|
|
8140
8540
|
// src/iden3comm/handlers/refresh.ts
|
|
8141
8541
|
var import_js_jwz6 = require("@iden3/js-jwz");
|
|
8142
|
-
var
|
|
8542
|
+
var import_js_iden3_core27 = require("@iden3/js-iden3-core");
|
|
8143
8543
|
var uuid6 = __toESM(require("uuid"), 1);
|
|
8144
8544
|
var RefreshHandler = class {
|
|
8145
8545
|
/**
|
|
@@ -8160,7 +8560,7 @@ var RefreshHandler = class {
|
|
|
8160
8560
|
if (!otherIdentifier) {
|
|
8161
8561
|
throw new Error("self credentials do not support refresh");
|
|
8162
8562
|
}
|
|
8163
|
-
const senderDID =
|
|
8563
|
+
const senderDID = import_js_iden3_core27.DID.parse(otherIdentifier);
|
|
8164
8564
|
const zkpParams = {
|
|
8165
8565
|
senderDID,
|
|
8166
8566
|
provingMethodAlg: new import_js_jwz6.ProvingMethodAlg(
|
|
@@ -8205,7 +8605,7 @@ var RefreshHandler = class {
|
|
|
8205
8605
|
};
|
|
8206
8606
|
|
|
8207
8607
|
// src/iden3comm/handlers/revocation-status.ts
|
|
8208
|
-
var
|
|
8608
|
+
var import_js_iden3_core28 = require("@iden3/js-iden3-core");
|
|
8209
8609
|
var uuid7 = __toESM(require("uuid"), 1);
|
|
8210
8610
|
var import_js_jwz7 = require("@iden3/js-jwz");
|
|
8211
8611
|
var RevocationStatusHandler = class extends AbstractMessageHandler {
|
|
@@ -8247,7 +8647,7 @@ var RevocationStatusHandler = class extends AbstractMessageHandler {
|
|
|
8247
8647
|
if (!rsRequest.body?.revocation_nonce) {
|
|
8248
8648
|
throw new Error(`failed request. empty 'revocation_nonce' field`);
|
|
8249
8649
|
}
|
|
8250
|
-
const issuerDID =
|
|
8650
|
+
const issuerDID = import_js_iden3_core28.DID.parse(rsRequest.to);
|
|
8251
8651
|
const mtpWithTreeState = await this._identityWallet.generateNonRevocationMtpWithNonce(
|
|
8252
8652
|
issuerDID,
|
|
8253
8653
|
BigInt(rsRequest.body.revocation_nonce),
|
|
@@ -8314,7 +8714,7 @@ var RevocationStatusHandler = class extends AbstractMessageHandler {
|
|
|
8314
8714
|
if (!rsRequest.to) {
|
|
8315
8715
|
throw new Error(`failed request. empty 'to' field`);
|
|
8316
8716
|
}
|
|
8317
|
-
const senderDID =
|
|
8717
|
+
const senderDID = import_js_iden3_core28.DID.parse(rsRequest.to);
|
|
8318
8718
|
return this._packerMgr.pack(opts.mediaType, byteEncoder.encode(JSON.stringify(response)), {
|
|
8319
8719
|
senderDID,
|
|
8320
8720
|
...packerOpts
|
|
@@ -8323,7 +8723,7 @@ var RevocationStatusHandler = class extends AbstractMessageHandler {
|
|
|
8323
8723
|
};
|
|
8324
8724
|
|
|
8325
8725
|
// src/iden3comm/handlers/credential-proposal.ts
|
|
8326
|
-
var
|
|
8726
|
+
var import_js_iden3_core29 = require("@iden3/js-iden3-core");
|
|
8327
8727
|
var uuid8 = __toESM(require("uuid"), 1);
|
|
8328
8728
|
var import_js_jwz8 = require("@iden3/js-jwz");
|
|
8329
8729
|
function createProposalRequest(sender, receiver, opts) {
|
|
@@ -8335,9 +8735,12 @@ function createProposalRequest(sender, receiver, opts) {
|
|
|
8335
8735
|
to: receiver.string(),
|
|
8336
8736
|
typ: "application/iden3comm-plain-json" /* PlainMessage */,
|
|
8337
8737
|
type: PROTOCOL_MESSAGE_TYPE.PROPOSAL_REQUEST_MESSAGE_TYPE,
|
|
8338
|
-
body:
|
|
8339
|
-
|
|
8340
|
-
|
|
8738
|
+
body: {
|
|
8739
|
+
credentials: opts.credentials,
|
|
8740
|
+
did_doc: opts.did_doc
|
|
8741
|
+
},
|
|
8742
|
+
created_time: (0, import_js_iden3_core29.getUnixTimestamp)(/* @__PURE__ */ new Date()),
|
|
8743
|
+
expires_time: opts?.expires_time ? (0, import_js_iden3_core29.getUnixTimestamp)(opts.expires_time) : void 0,
|
|
8341
8744
|
attachments: opts.attachments
|
|
8342
8745
|
};
|
|
8343
8746
|
return request;
|
|
@@ -8354,8 +8757,8 @@ function createProposal(sender, receiver, proposals, opts) {
|
|
|
8354
8757
|
body: {
|
|
8355
8758
|
proposals: proposals || []
|
|
8356
8759
|
},
|
|
8357
|
-
created_time: (0,
|
|
8358
|
-
expires_time: opts?.expires_time ? (0,
|
|
8760
|
+
created_time: (0, import_js_iden3_core29.getUnixTimestamp)(/* @__PURE__ */ new Date()),
|
|
8761
|
+
expires_time: opts?.expires_time ? (0, import_js_iden3_core29.getUnixTimestamp)(opts.expires_time) : void 0
|
|
8359
8762
|
};
|
|
8360
8763
|
return request;
|
|
8361
8764
|
}
|
|
@@ -8488,7 +8891,7 @@ var CredentialProposalHandler = class extends AbstractMessageHandler {
|
|
|
8488
8891
|
if (!opts?.allowExpiredMessages) {
|
|
8489
8892
|
verifyExpiresTime(proposalRequest);
|
|
8490
8893
|
}
|
|
8491
|
-
const senderDID =
|
|
8894
|
+
const senderDID = import_js_iden3_core29.DID.parse(proposalRequest.from);
|
|
8492
8895
|
const message = await this.handleProposalRequestMessage(proposalRequest);
|
|
8493
8896
|
const response = byteEncoder.encode(JSON.stringify(message));
|
|
8494
8897
|
const packerOpts = this._params.packerParams.mediaType === "application/iden3comm-signed-json" /* SignedMessage */ ? this._params.packerParams.packerOptions : {
|
|
@@ -8516,10 +8919,9 @@ var CredentialProposalHandler = class extends AbstractMessageHandler {
|
|
|
8516
8919
|
};
|
|
8517
8920
|
|
|
8518
8921
|
// src/iden3comm/handlers/payment.ts
|
|
8519
|
-
var
|
|
8922
|
+
var import_js_iden3_core30 = require("@iden3/js-iden3-core");
|
|
8520
8923
|
var uuid9 = __toESM(require("uuid"), 1);
|
|
8521
8924
|
var import_js_jwz9 = require("@iden3/js-jwz");
|
|
8522
|
-
var import_ethers6 = require("ethers");
|
|
8523
8925
|
function createPaymentRequest(sender, receiver, agent, payments, opts) {
|
|
8524
8926
|
const uuidv4 = uuid9.v4();
|
|
8525
8927
|
const request = {
|
|
@@ -8533,48 +8935,11 @@ function createPaymentRequest(sender, receiver, agent, payments, opts) {
|
|
|
8533
8935
|
agent,
|
|
8534
8936
|
payments
|
|
8535
8937
|
},
|
|
8536
|
-
created_time: (0,
|
|
8537
|
-
expires_time: opts?.expires_time ? (0,
|
|
8938
|
+
created_time: (0, import_js_iden3_core30.getUnixTimestamp)(/* @__PURE__ */ new Date()),
|
|
8939
|
+
expires_time: opts?.expires_time ? (0, import_js_iden3_core30.getUnixTimestamp)(opts.expires_time) : void 0
|
|
8538
8940
|
};
|
|
8539
8941
|
return request;
|
|
8540
8942
|
}
|
|
8541
|
-
async function verifyEIP712TypedData(data, resolver) {
|
|
8542
|
-
const paymentData = data.type === "Iden3PaymentRailsRequestV1" /* Iden3PaymentRailsRequestV1 */ ? {
|
|
8543
|
-
recipient: data.recipient,
|
|
8544
|
-
amount: data.amount,
|
|
8545
|
-
expirationDate: (0, import_js_iden3_core28.getUnixTimestamp)(new Date(data.expirationDate)),
|
|
8546
|
-
nonce: data.nonce,
|
|
8547
|
-
metadata: "0x"
|
|
8548
|
-
} : {
|
|
8549
|
-
tokenAddress: data.tokenAddress,
|
|
8550
|
-
recipient: data.recipient,
|
|
8551
|
-
amount: data.amount,
|
|
8552
|
-
expirationDate: (0, import_js_iden3_core28.getUnixTimestamp)(new Date(data.expirationDate)),
|
|
8553
|
-
nonce: data.nonce,
|
|
8554
|
-
metadata: "0x"
|
|
8555
|
-
};
|
|
8556
|
-
const proof = Array.isArray(data.proof) ? data.proof[0] : data.proof;
|
|
8557
|
-
const typesFetchResult = await fetch(proof.eip712.types);
|
|
8558
|
-
const types = await typesFetchResult.json();
|
|
8559
|
-
delete types.EIP712Domain;
|
|
8560
|
-
const recovered = import_ethers6.ethers.verifyTypedData(
|
|
8561
|
-
proof.eip712.domain,
|
|
8562
|
-
types,
|
|
8563
|
-
paymentData,
|
|
8564
|
-
proof.proofValue
|
|
8565
|
-
);
|
|
8566
|
-
const { didDocument } = await resolver.resolve(proof.verificationMethod);
|
|
8567
|
-
if (didDocument?.verificationMethod) {
|
|
8568
|
-
for (const verificationMethod of didDocument.verificationMethod) {
|
|
8569
|
-
if (verificationMethod.blockchainAccountId?.split(":").slice(-1)[0].toLowerCase() === recovered.toLowerCase()) {
|
|
8570
|
-
return recovered;
|
|
8571
|
-
}
|
|
8572
|
-
}
|
|
8573
|
-
} else {
|
|
8574
|
-
throw new Error("failed request. issuer DIDDocument does not contain any verificationMethods");
|
|
8575
|
-
}
|
|
8576
|
-
throw new Error(`failed request. no matching verificationMethod`);
|
|
8577
|
-
}
|
|
8578
8943
|
function createPayment(sender, receiver, payments, opts) {
|
|
8579
8944
|
const uuidv4 = uuid9.v4();
|
|
8580
8945
|
const request = {
|
|
@@ -8587,8 +8952,8 @@ function createPayment(sender, receiver, payments, opts) {
|
|
|
8587
8952
|
body: {
|
|
8588
8953
|
payments
|
|
8589
8954
|
},
|
|
8590
|
-
created_time: (0,
|
|
8591
|
-
expires_time: opts?.expires_time ? (0,
|
|
8955
|
+
created_time: (0, import_js_iden3_core30.getUnixTimestamp)(/* @__PURE__ */ new Date()),
|
|
8956
|
+
expires_time: opts?.expires_time ? (0, import_js_iden3_core30.getUnixTimestamp)(opts.expires_time) : void 0
|
|
8592
8957
|
};
|
|
8593
8958
|
return request;
|
|
8594
8959
|
}
|
|
@@ -8642,8 +9007,8 @@ var PaymentHandler = class extends AbstractMessageHandler {
|
|
|
8642
9007
|
if (!ctx.paymentHandler) {
|
|
8643
9008
|
throw new Error(`please provide payment handler in context`);
|
|
8644
9009
|
}
|
|
8645
|
-
const senderDID =
|
|
8646
|
-
const receiverDID =
|
|
9010
|
+
const senderDID = import_js_iden3_core30.DID.parse(paymentRequest.to);
|
|
9011
|
+
const receiverDID = import_js_iden3_core30.DID.parse(paymentRequest.from);
|
|
8647
9012
|
const payments = [];
|
|
8648
9013
|
for (let i = 0; i < paymentRequest.body.payments.length; i++) {
|
|
8649
9014
|
const { data } = paymentRequest.body.payments[i];
|
|
@@ -8673,6 +9038,22 @@ var PaymentHandler = class extends AbstractMessageHandler {
|
|
|
8673
9038
|
)
|
|
8674
9039
|
);
|
|
8675
9040
|
break;
|
|
9041
|
+
case "Iden3PaymentRailsSolanaRequestV1" /* Iden3PaymentRailsSolanaRequestV1 */:
|
|
9042
|
+
payments.push(
|
|
9043
|
+
await this.handleIden3PaymentRailsSolanaRequestV1(selectedPayment, ctx.paymentHandler)
|
|
9044
|
+
);
|
|
9045
|
+
break;
|
|
9046
|
+
case "Iden3PaymentRailsSolanaSPLRequestV1" /* Iden3PaymentRailsSolanaSPLRequestV1 */:
|
|
9047
|
+
payments.push(
|
|
9048
|
+
await this.handleIden3PaymentRailsSolanaSPLRequestV1(
|
|
9049
|
+
{
|
|
9050
|
+
...selectedPayment,
|
|
9051
|
+
type: "Iden3PaymentRailsSolanaSPLRequestV1" /* Iden3PaymentRailsSolanaSPLRequestV1 */
|
|
9052
|
+
},
|
|
9053
|
+
ctx.paymentHandler
|
|
9054
|
+
)
|
|
9055
|
+
);
|
|
9056
|
+
break;
|
|
8676
9057
|
}
|
|
8677
9058
|
}
|
|
8678
9059
|
const paymentMessage = createPayment(senderDID, receiverDID, payments);
|
|
@@ -8712,7 +9093,7 @@ var PaymentHandler = class extends AbstractMessageHandler {
|
|
|
8712
9093
|
if (!agentMessage) {
|
|
8713
9094
|
return null;
|
|
8714
9095
|
}
|
|
8715
|
-
const senderDID =
|
|
9096
|
+
const senderDID = import_js_iden3_core30.DID.parse(paymentRequest.to);
|
|
8716
9097
|
return this.packMessage(agentMessage, senderDID);
|
|
8717
9098
|
}
|
|
8718
9099
|
/**
|
|
@@ -8751,7 +9132,7 @@ var PaymentHandler = class extends AbstractMessageHandler {
|
|
|
8751
9132
|
/**
|
|
8752
9133
|
* @inheritdoc IPaymentHandler#createPaymentRailsV1
|
|
8753
9134
|
*/
|
|
8754
|
-
async createPaymentRailsV1(sender, receiver, agent, signer, payments) {
|
|
9135
|
+
async createPaymentRailsV1(sender, receiver, agent, signer, payments, createOptions) {
|
|
8755
9136
|
const paymentRequestInfo = [];
|
|
8756
9137
|
for (let i = 0; i < payments.length; i++) {
|
|
8757
9138
|
const { credentials, description } = payments[i];
|
|
@@ -8769,70 +9150,40 @@ var PaymentHandler = class extends AbstractMessageHandler {
|
|
|
8769
9150
|
if (!option) {
|
|
8770
9151
|
throw new Error(`failed request. no option for id ${optionId}`);
|
|
8771
9152
|
}
|
|
8772
|
-
if (option.type === "Iden3PaymentRailsERC20RequestV1" /* Iden3PaymentRailsERC20RequestV1 */ && !option.contractAddress) {
|
|
9153
|
+
if ((option.type === "Iden3PaymentRailsERC20RequestV1" /* Iden3PaymentRailsERC20RequestV1 */ || option.type === "Iden3PaymentRailsSolanaSPLRequestV1" /* Iden3PaymentRailsSolanaSPLRequestV1 */) && !option.contractAddress) {
|
|
8773
9154
|
throw new Error(`failed request. no token address for option id ${optionId}`);
|
|
8774
9155
|
}
|
|
8775
9156
|
const expirationDateRequired = expirationDate ?? new Date((/* @__PURE__ */ new Date()).setHours((/* @__PURE__ */ new Date()).getHours() + 1));
|
|
8776
|
-
|
|
8777
|
-
|
|
8778
|
-
|
|
8779
|
-
|
|
8780
|
-
|
|
8781
|
-
recipient,
|
|
8782
|
-
amount,
|
|
8783
|
-
expirationDate: (0, import_js_iden3_core28.getUnixTimestamp)(expirationDateRequired),
|
|
8784
|
-
nonce,
|
|
8785
|
-
metadata: "0x"
|
|
8786
|
-
} : {
|
|
8787
|
-
tokenAddress: option.contractAddress,
|
|
8788
|
-
recipient,
|
|
8789
|
-
amount,
|
|
8790
|
-
expirationDate: (0, import_js_iden3_core28.getUnixTimestamp)(expirationDateRequired),
|
|
8791
|
-
nonce,
|
|
8792
|
-
metadata: "0x"
|
|
8793
|
-
};
|
|
8794
|
-
const domain = {
|
|
8795
|
-
name: "MCPayment",
|
|
8796
|
-
version: "1.0.0",
|
|
8797
|
-
chainId,
|
|
8798
|
-
verifyingContract: paymentRails
|
|
8799
|
-
};
|
|
8800
|
-
const signature = await signer.signTypedData(domain, types, paymentData);
|
|
8801
|
-
const proof = [
|
|
8802
|
-
{
|
|
8803
|
-
type: "EthereumEip712Signature2021" /* EthereumEip712Signature2021 */,
|
|
8804
|
-
proofPurpose: "assertionMethod",
|
|
8805
|
-
proofValue: signature,
|
|
8806
|
-
verificationMethod: `did:pkh:eip155:${chainId}:${await signer.getAddress()}`,
|
|
8807
|
-
created: (/* @__PURE__ */ new Date()).toISOString(),
|
|
8808
|
-
eip712: {
|
|
8809
|
-
types: typeUrl,
|
|
8810
|
-
primaryType: "Iden3PaymentRailsRequestV1",
|
|
8811
|
-
domain
|
|
8812
|
-
}
|
|
8813
|
-
}
|
|
8814
|
-
];
|
|
8815
|
-
const d = {
|
|
8816
|
-
type: "Iden3PaymentRailsRequestV1" /* Iden3PaymentRailsRequestV1 */,
|
|
8817
|
-
"@context": [
|
|
8818
|
-
`https://schema.iden3.io/core/jsonld/payment.jsonld#${option.type}`,
|
|
8819
|
-
"https://w3id.org/security/suites/eip712sig-2021/v1"
|
|
8820
|
-
],
|
|
8821
|
-
recipient,
|
|
8822
|
-
amount: amount.toString(),
|
|
8823
|
-
expirationDate: expirationDateRequired.toISOString(),
|
|
8824
|
-
nonce: nonce.toString(),
|
|
8825
|
-
metadata: "0x",
|
|
8826
|
-
proof
|
|
8827
|
-
};
|
|
8828
|
-
dataArr.push(
|
|
8829
|
-
option.type === "Iden3PaymentRailsRequestV1" /* Iden3PaymentRailsRequestV1 */ ? d : {
|
|
8830
|
-
...d,
|
|
8831
|
-
type: option.type,
|
|
8832
|
-
tokenAddress: option.contractAddress || "",
|
|
8833
|
-
features: option.features || []
|
|
9157
|
+
if (option.type === "Iden3PaymentRailsSolanaRequestV1" /* Iden3PaymentRailsSolanaRequestV1 */ || option.type === "Iden3PaymentRailsSolanaSPLRequestV1" /* Iden3PaymentRailsSolanaSPLRequestV1 */) {
|
|
9158
|
+
if (!createOptions?.solSigner) {
|
|
9159
|
+
throw new Error(
|
|
9160
|
+
`please provide solana signer in context for ${option.type} payment type`
|
|
9161
|
+
);
|
|
8834
9162
|
}
|
|
8835
|
-
|
|
9163
|
+
const payment = await buildSolanaPayment(
|
|
9164
|
+
createOptions.solSigner,
|
|
9165
|
+
option,
|
|
9166
|
+
chainId,
|
|
9167
|
+
paymentRails,
|
|
9168
|
+
recipient,
|
|
9169
|
+
BigInt(amount),
|
|
9170
|
+
expirationDateRequired,
|
|
9171
|
+
nonce
|
|
9172
|
+
);
|
|
9173
|
+
dataArr.push(payment);
|
|
9174
|
+
} else {
|
|
9175
|
+
const payment = await buildEvmPayment(
|
|
9176
|
+
signer,
|
|
9177
|
+
option,
|
|
9178
|
+
chainId,
|
|
9179
|
+
paymentRails,
|
|
9180
|
+
recipient,
|
|
9181
|
+
BigInt(amount),
|
|
9182
|
+
expirationDateRequired,
|
|
9183
|
+
nonce
|
|
9184
|
+
);
|
|
9185
|
+
dataArr.push(payment);
|
|
9186
|
+
}
|
|
8836
9187
|
}
|
|
8837
9188
|
paymentRequestInfo.push({
|
|
8838
9189
|
data: dataArr,
|
|
@@ -8886,6 +9237,55 @@ var PaymentHandler = class extends AbstractMessageHandler {
|
|
|
8886
9237
|
}
|
|
8887
9238
|
};
|
|
8888
9239
|
}
|
|
9240
|
+
async handleIden3PaymentRailsSolanaRequestV1(data, paymentHandler) {
|
|
9241
|
+
if (data.expirationDate && new Date(data.expirationDate) < /* @__PURE__ */ new Date()) {
|
|
9242
|
+
throw new Error(`failed request. expired request`);
|
|
9243
|
+
}
|
|
9244
|
+
const isValid = await verifyIden3SolanaPaymentRequest(data, this._params.documentResolver);
|
|
9245
|
+
if (!isValid) {
|
|
9246
|
+
throw new Error(`failed request. invalid Solana payment request signature`);
|
|
9247
|
+
}
|
|
9248
|
+
const proof = Array.isArray(data.proof) ? data.proof[0] : data.proof;
|
|
9249
|
+
const signer = proof.verificationMethod.split(":").slice(-1)[0];
|
|
9250
|
+
if (this._params.allowedSigners && !this._params.allowedSigners.includes(signer)) {
|
|
9251
|
+
throw new Error(`failed request. signer is not in the allowed signers list`);
|
|
9252
|
+
}
|
|
9253
|
+
const txId = await paymentHandler(data);
|
|
9254
|
+
return {
|
|
9255
|
+
nonce: data.nonce,
|
|
9256
|
+
type: "Iden3PaymentRailsSolanaV1" /* Iden3PaymentRailsSolanaV1 */,
|
|
9257
|
+
"@context": "https://schema.iden3.io/core/jsonld/payment.jsonld#Iden3PaymentRailsSolanaV1",
|
|
9258
|
+
paymentData: {
|
|
9259
|
+
txId,
|
|
9260
|
+
chainId: proof.domain.chainId
|
|
9261
|
+
}
|
|
9262
|
+
};
|
|
9263
|
+
}
|
|
9264
|
+
async handleIden3PaymentRailsSolanaSPLRequestV1(data, paymentHandler) {
|
|
9265
|
+
if (data.expirationDate && new Date(data.expirationDate) < /* @__PURE__ */ new Date()) {
|
|
9266
|
+
throw new Error(`failed request. expired request`);
|
|
9267
|
+
}
|
|
9268
|
+
const isValid = await verifyIden3SolanaPaymentRequest(data, this._params.documentResolver);
|
|
9269
|
+
if (!isValid) {
|
|
9270
|
+
throw new Error(`failed request. invalid Solana payment request signature`);
|
|
9271
|
+
}
|
|
9272
|
+
const proof = Array.isArray(data.proof) ? data.proof[0] : data.proof;
|
|
9273
|
+
const signer = proof.verificationMethod.split(":").slice(-1)[0];
|
|
9274
|
+
if (this._params.allowedSigners && !this._params.allowedSigners.includes(signer)) {
|
|
9275
|
+
throw new Error(`failed request. signer is not in the allowed signers list`);
|
|
9276
|
+
}
|
|
9277
|
+
const txId = await paymentHandler(data);
|
|
9278
|
+
return {
|
|
9279
|
+
nonce: data.nonce,
|
|
9280
|
+
type: "Iden3PaymentRailsSolanaSPLV1" /* Iden3PaymentRailsSolanaSPLV1 */,
|
|
9281
|
+
"@context": "https://schema.iden3.io/core/jsonld/payment.jsonld#Iden3PaymentRailsSolanaSPLV1",
|
|
9282
|
+
paymentData: {
|
|
9283
|
+
txId,
|
|
9284
|
+
chainId: proof.domain.chainId,
|
|
9285
|
+
tokenAddress: data.tokenAddress
|
|
9286
|
+
}
|
|
9287
|
+
};
|
|
9288
|
+
}
|
|
8889
9289
|
async handleIden3PaymentRailsERC20RequestV1(data, paymentHandler, approveHandler) {
|
|
8890
9290
|
if (data.expirationDate && new Date(data.expirationDate) < /* @__PURE__ */ new Date()) {
|
|
8891
9291
|
throw new Error(`failed request. expired request`);
|
|
@@ -8917,7 +9317,7 @@ var PaymentHandler = class extends AbstractMessageHandler {
|
|
|
8917
9317
|
|
|
8918
9318
|
// src/iden3comm/handlers/discovery-protocol.ts
|
|
8919
9319
|
var uuid10 = __toESM(require("uuid"), 1);
|
|
8920
|
-
var
|
|
9320
|
+
var import_js_iden3_core31 = require("@iden3/js-iden3-core");
|
|
8921
9321
|
function createDiscoveryFeatureQueryMessage(queries, opts) {
|
|
8922
9322
|
const uuidv4 = uuid10.v4();
|
|
8923
9323
|
return {
|
|
@@ -8930,7 +9330,7 @@ function createDiscoveryFeatureQueryMessage(queries, opts) {
|
|
|
8930
9330
|
},
|
|
8931
9331
|
from: opts?.from,
|
|
8932
9332
|
to: opts?.to,
|
|
8933
|
-
created_time: (0,
|
|
9333
|
+
created_time: (0, import_js_iden3_core31.getUnixTimestamp)(/* @__PURE__ */ new Date()),
|
|
8934
9334
|
expires_time: opts?.expires_time
|
|
8935
9335
|
};
|
|
8936
9336
|
}
|
|
@@ -8946,7 +9346,7 @@ function createDiscoveryFeatureDiscloseMessage(disclosures, opts) {
|
|
|
8946
9346
|
},
|
|
8947
9347
|
from: opts?.from,
|
|
8948
9348
|
to: opts?.to,
|
|
8949
|
-
created_time: (0,
|
|
9349
|
+
created_time: (0, import_js_iden3_core31.getUnixTimestamp)(/* @__PURE__ */ new Date()),
|
|
8950
9350
|
expires_time: opts?.expires_time
|
|
8951
9351
|
};
|
|
8952
9352
|
}
|
|
@@ -8999,7 +9399,7 @@ var DiscoveryProtocolHandler = class extends AbstractMessageHandler {
|
|
|
8999
9399
|
createDiscoveryFeatureDiscloseMessage(disclosures, {
|
|
9000
9400
|
to: message.from,
|
|
9001
9401
|
from: message.to,
|
|
9002
|
-
expires_time: opts?.disclosureExpiresDate ? (0,
|
|
9402
|
+
expires_time: opts?.disclosureExpiresDate ? (0, import_js_iden3_core31.getUnixTimestamp)(opts.disclosureExpiresDate) : void 0
|
|
9003
9403
|
})
|
|
9004
9404
|
);
|
|
9005
9405
|
}
|
|
@@ -9334,8 +9734,8 @@ var EthStateStorage = class {
|
|
|
9334
9734
|
this._disableCache = true;
|
|
9335
9735
|
}
|
|
9336
9736
|
getStateContractAndProviderForId(id) {
|
|
9337
|
-
const idTyped =
|
|
9338
|
-
const chainId = (0,
|
|
9737
|
+
const idTyped = import_js_iden3_core32.Id.fromBigInt(id);
|
|
9738
|
+
const chainId = (0, import_js_iden3_core32.getChainId)(import_js_iden3_core32.DID.blockchainFromId(idTyped), import_js_iden3_core32.DID.networkIdFromId(idTyped));
|
|
9339
9739
|
const config = this.networkByChainId(chainId);
|
|
9340
9740
|
const provider = new import_ethers7.JsonRpcProvider(config.url);
|
|
9341
9741
|
const stateContract = new import_ethers7.Contract(config.contractAddress, State_default, provider);
|
|
@@ -10159,7 +10559,7 @@ var ZkpVerifier_default = [
|
|
|
10159
10559
|
|
|
10160
10560
|
// src/storage/blockchain/onchain-zkp-verifier.ts
|
|
10161
10561
|
var import_universal_verifier_v2_abi = require("@iden3/universal-verifier-v2-abi");
|
|
10162
|
-
var
|
|
10562
|
+
var import_js_iden3_core33 = require("@iden3/js-iden3-core");
|
|
10163
10563
|
var import_js_merkletree23 = require("@iden3/js-merkletree");
|
|
10164
10564
|
var maxGasLimit = 10000000n;
|
|
10165
10565
|
var FunctionSignatures = /* @__PURE__ */ ((FunctionSignatures2) => {
|
|
@@ -10467,13 +10867,13 @@ var OnChainZKPVerifier = class _OnChainZKPVerifier {
|
|
|
10467
10867
|
)
|
|
10468
10868
|
].reduce((acc, s) => {
|
|
10469
10869
|
const info = JSON.parse(s);
|
|
10470
|
-
const id =
|
|
10471
|
-
const chainId = (0,
|
|
10870
|
+
const id = import_js_iden3_core33.Id.fromString(info.id);
|
|
10871
|
+
const chainId = (0, import_js_iden3_core33.chainIDfromDID)(import_js_iden3_core33.DID.parseFromId(id));
|
|
10472
10872
|
if (txDataChainId === chainId) {
|
|
10473
10873
|
return acc;
|
|
10474
10874
|
}
|
|
10475
10875
|
const promise = this.resolveDidDocumentEip712MessageAndSignature(
|
|
10476
|
-
|
|
10876
|
+
import_js_iden3_core33.DID.parseFromId(import_js_iden3_core33.Id.fromString(info.id)),
|
|
10477
10877
|
didResolverUrl,
|
|
10478
10878
|
{
|
|
10479
10879
|
[type]: import_js_merkletree23.Hash.fromString(info[type])
|
|
@@ -10623,21 +11023,21 @@ var OnChainZKPVerifier = class _OnChainZKPVerifier {
|
|
|
10623
11023
|
}
|
|
10624
11024
|
};
|
|
10625
11025
|
var packEthIdentityProof = (did) => {
|
|
10626
|
-
return `0x${bytesToHex(
|
|
11026
|
+
return `0x${bytesToHex(import_js_iden3_core33.BytesHelper.intToBytes(import_js_iden3_core33.DID.idFromDID(did).bigInt()))}`;
|
|
10627
11027
|
};
|
|
10628
11028
|
|
|
10629
11029
|
// src/storage/blockchain/onchain-issuer.ts
|
|
10630
|
-
var
|
|
11030
|
+
var import_js_iden3_core36 = require("@iden3/js-iden3-core");
|
|
10631
11031
|
var import_ethers10 = require("ethers");
|
|
10632
11032
|
var import_onchain_non_merklized_issuer_base_abi2 = require("@iden3/onchain-non-merklized-issuer-base-abi");
|
|
10633
11033
|
|
|
10634
11034
|
// src/storage/blockchain/onchain-issuer-adapter/non-merklized/version/v0.0.1/onchain-non-merklized-issuer-adapter.ts
|
|
10635
|
-
var
|
|
11035
|
+
var import_js_iden3_core34 = require("@iden3/js-iden3-core");
|
|
10636
11036
|
var import_onchain_non_merklized_issuer_base_abi = require("@iden3/onchain-non-merklized-issuer-base-abi");
|
|
10637
11037
|
var import_js_jsonld_merklization5 = require("@iden3/js-jsonld-merklization");
|
|
10638
11038
|
var import_js_merkletree24 = require("@iden3/js-merkletree");
|
|
10639
11039
|
var import_ethers9 = require("ethers");
|
|
10640
|
-
var
|
|
11040
|
+
var import_js_iden3_core35 = require("@iden3/js-iden3-core");
|
|
10641
11041
|
var OnchainNonMerklizedIssuerAdapter = class {
|
|
10642
11042
|
_contract;
|
|
10643
11043
|
_contractAddress;
|
|
@@ -10657,7 +11057,7 @@ var OnchainNonMerklizedIssuerAdapter = class {
|
|
|
10657
11057
|
}
|
|
10658
11058
|
this._chainId = ethConnectionConfig.chainId;
|
|
10659
11059
|
this._contractAddress = import_ethers9.ethers.getAddress(
|
|
10660
|
-
import_ethers9.ethers.hexlify(
|
|
11060
|
+
import_ethers9.ethers.hexlify(import_js_iden3_core34.Id.ethAddressFromId(import_js_iden3_core34.DID.idFromDID(issuerDid)))
|
|
10661
11061
|
);
|
|
10662
11062
|
this._contract = import_onchain_non_merklized_issuer_base_abi.NonMerklizedIssuerBase__factory.connect(
|
|
10663
11063
|
this._contractAddress,
|
|
@@ -10725,7 +11125,7 @@ var OnchainNonMerklizedIssuerAdapter = class {
|
|
|
10725
11125
|
* @param credentialSubjectFields Subject fields of the credential.
|
|
10726
11126
|
*/
|
|
10727
11127
|
async convertOnChainInfoToW3CCredential(credentialData, coreClaimBigInts, credentialSubjectFields) {
|
|
10728
|
-
const c = new
|
|
11128
|
+
const c = new import_js_iden3_core34.Claim().unMarshalJson(JSON.stringify(coreClaimBigInts.map((b) => b.toString())));
|
|
10729
11129
|
const credentialSubject = await this.convertCredentialSubject(
|
|
10730
11130
|
c,
|
|
10731
11131
|
credentialData.context,
|
|
@@ -10745,7 +11145,7 @@ var OnchainNonMerklizedIssuerAdapter = class {
|
|
|
10745
11145
|
nonce: Number(c.getRevocationNonce()),
|
|
10746
11146
|
type: "Iden3OnchainSparseMerkleTreeProof2023" /* Iden3OnchainSparseMerkleTreeProof2023 */
|
|
10747
11147
|
},
|
|
10748
|
-
issuanceDate: (0,
|
|
11148
|
+
issuanceDate: (0, import_js_iden3_core35.getDateFromUnixTimestamp)(Number(credentialData.issuanceDate)).getTime()
|
|
10749
11149
|
};
|
|
10750
11150
|
const existenceProof = await this.existenceProof(c);
|
|
10751
11151
|
const w3c = W3CCredential.fromCredentialRequest(this._issuerDid, credentialRequest);
|
|
@@ -10793,7 +11193,7 @@ var OnchainNonMerklizedIssuerAdapter = class {
|
|
|
10793
11193
|
}
|
|
10794
11194
|
case "http://www.w3.org/2001/XMLSchema#dateTime" /* DateTime */: {
|
|
10795
11195
|
const timestamp = BigInt(f.rawValue);
|
|
10796
|
-
const sourceTimestamp = (0,
|
|
11196
|
+
const sourceTimestamp = (0, import_js_iden3_core35.getDateFromUnixTimestamp)(Number(timestamp)).toISOString();
|
|
10797
11197
|
this.validateSourceValue(dataType, f.value, sourceTimestamp);
|
|
10798
11198
|
credentialSubject[f.key] = sourceTimestamp;
|
|
10799
11199
|
break;
|
|
@@ -10811,7 +11211,7 @@ var OnchainNonMerklizedIssuerAdapter = class {
|
|
|
10811
11211
|
}
|
|
10812
11212
|
credentialSubject["type"] = credentialType;
|
|
10813
11213
|
const subjectId = coreClaim.getId();
|
|
10814
|
-
const subjectDid =
|
|
11214
|
+
const subjectDid = import_js_iden3_core34.DID.parseFromId(subjectId);
|
|
10815
11215
|
credentialSubject["id"] = subjectDid.string();
|
|
10816
11216
|
return credentialSubject;
|
|
10817
11217
|
}
|
|
@@ -10900,7 +11300,7 @@ var OnchainIssuer = class {
|
|
|
10900
11300
|
merklizationOptions: this._onchainIssuerOptions?.merklizationOptions
|
|
10901
11301
|
});
|
|
10902
11302
|
await adapter.isInterfaceSupported();
|
|
10903
|
-
const { credentialData, coreClaimBigInts, credentialSubjectFields } = await adapter.getCredential(
|
|
11303
|
+
const { credentialData, coreClaimBigInts, credentialSubjectFields } = await adapter.getCredential(import_js_iden3_core36.DID.idFromDID(userDID), credentialId);
|
|
10904
11304
|
return await adapter.convertOnChainInfoToW3CCredential(
|
|
10905
11305
|
credentialData,
|
|
10906
11306
|
coreClaimBigInts,
|
|
@@ -10925,16 +11325,16 @@ var OnchainIssuer = class {
|
|
|
10925
11325
|
merklizationOptions: this._onchainIssuerOptions?.merklizationOptions
|
|
10926
11326
|
});
|
|
10927
11327
|
await adapter.isInterfaceSupported();
|
|
10928
|
-
return await adapter.getUserCredentialsIds(
|
|
11328
|
+
return await adapter.getUserCredentialsIds(import_js_iden3_core36.DID.idFromDID(userDID));
|
|
10929
11329
|
}
|
|
10930
11330
|
default:
|
|
10931
11331
|
throw new Error(`Unsupported adapter version ${response}`);
|
|
10932
11332
|
}
|
|
10933
11333
|
}
|
|
10934
11334
|
getContractConnection(did) {
|
|
10935
|
-
const issuerId =
|
|
10936
|
-
const chainId = (0,
|
|
10937
|
-
const contractAddress = import_ethers10.ethers.getAddress(import_ethers10.ethers.hexlify(
|
|
11335
|
+
const issuerId = import_js_iden3_core36.DID.idFromDID(did);
|
|
11336
|
+
const chainId = (0, import_js_iden3_core36.chainIDfromDID)(did);
|
|
11337
|
+
const contractAddress = import_ethers10.ethers.getAddress(import_ethers10.ethers.hexlify(import_js_iden3_core36.Id.ethAddressFromId(issuerId)));
|
|
10938
11338
|
const connection = this._ethConnectionConfig.find((c) => c.chainId === chainId);
|
|
10939
11339
|
if (!connection) {
|
|
10940
11340
|
throw new Error(`No connection found for chain ID ${chainId}`);
|
|
@@ -10949,7 +11349,7 @@ var OnchainIssuer = class {
|
|
|
10949
11349
|
|
|
10950
11350
|
// src/storage/blockchain/did-resolver-readonly-storage.ts
|
|
10951
11351
|
var import_js_merkletree25 = require("@iden3/js-merkletree");
|
|
10952
|
-
var
|
|
11352
|
+
var import_js_iden3_core37 = require("@iden3/js-iden3-core");
|
|
10953
11353
|
var import_ethers11 = require("ethers");
|
|
10954
11354
|
var DidResolverStateReadonlyStorage = class {
|
|
10955
11355
|
constructor(resolverUrl) {
|
|
@@ -10963,7 +11363,7 @@ var DidResolverStateReadonlyStorage = class {
|
|
|
10963
11363
|
}
|
|
10964
11364
|
async getGISTProof(id) {
|
|
10965
11365
|
const { didDocument } = await resolveDidDocument(
|
|
10966
|
-
|
|
11366
|
+
import_js_iden3_core37.DID.parseFromId(import_js_iden3_core37.Id.fromBigInt(id)),
|
|
10967
11367
|
this.resolverUrl
|
|
10968
11368
|
);
|
|
10969
11369
|
const { global } = this.getIden3StateInfo2023(didDocument);
|
|
@@ -10987,7 +11387,7 @@ var DidResolverStateReadonlyStorage = class {
|
|
|
10987
11387
|
}
|
|
10988
11388
|
async getGISTRootInfo(root, userId) {
|
|
10989
11389
|
const { didDocument } = await resolveDidDocument(
|
|
10990
|
-
|
|
11390
|
+
import_js_iden3_core37.DID.parseFromId(import_js_iden3_core37.Id.fromBigInt(userId)),
|
|
10991
11391
|
this.resolverUrl,
|
|
10992
11392
|
{
|
|
10993
11393
|
gist: import_js_merkletree25.Hash.fromBigInt(root)
|
|
@@ -11011,7 +11411,7 @@ var DidResolverStateReadonlyStorage = class {
|
|
|
11011
11411
|
async getStateInfo(id, state) {
|
|
11012
11412
|
const opts = state ? { state: import_js_merkletree25.Hash.fromBigInt(state) } : void 0;
|
|
11013
11413
|
const { didDocument } = await resolveDidDocument(
|
|
11014
|
-
|
|
11414
|
+
import_js_iden3_core37.DID.parseFromId(import_js_iden3_core37.Id.fromBigInt(id)),
|
|
11015
11415
|
this.resolverUrl,
|
|
11016
11416
|
opts
|
|
11017
11417
|
);
|
|
@@ -11900,7 +12300,7 @@ var FSCircuitStorage = class {
|
|
|
11900
12300
|
};
|
|
11901
12301
|
|
|
11902
12302
|
// src/proof/proof-service.ts
|
|
11903
|
-
var
|
|
12303
|
+
var import_js_iden3_core41 = require("@iden3/js-iden3-core");
|
|
11904
12304
|
|
|
11905
12305
|
// src/proof/common.ts
|
|
11906
12306
|
var import_js_merkletree28 = require("@iden3/js-merkletree");
|
|
@@ -12397,7 +12797,7 @@ var NativeProver = class _NativeProver {
|
|
|
12397
12797
|
var import_js_jsonld_merklization9 = require("@iden3/js-jsonld-merklization");
|
|
12398
12798
|
|
|
12399
12799
|
// src/proof/provers/inputs-generator.ts
|
|
12400
|
-
var
|
|
12800
|
+
var import_js_iden3_core38 = require("@iden3/js-iden3-core");
|
|
12401
12801
|
var allOperations2 = Object.values(QueryOperators);
|
|
12402
12802
|
var v2Operations = [
|
|
12403
12803
|
0 /* NOOP */,
|
|
@@ -12459,7 +12859,7 @@ var InputGenerator = class {
|
|
|
12459
12859
|
const smtProof = preparedCredential.credential.getIden3SparseMerkleTreeProof();
|
|
12460
12860
|
const circuitClaim = new CircuitClaim();
|
|
12461
12861
|
circuitClaim.claim = preparedCredential.credentialCoreClaim;
|
|
12462
|
-
circuitClaim.issuerId =
|
|
12862
|
+
circuitClaim.issuerId = import_js_iden3_core38.DID.idFromDID(import_js_iden3_core38.DID.parse(preparedCredential.credential.issuer));
|
|
12463
12863
|
if (smtProof) {
|
|
12464
12864
|
circuitClaim.proof = smtProof.mtp;
|
|
12465
12865
|
circuitClaim.treeState = {
|
|
@@ -12534,7 +12934,7 @@ var InputGenerator = class {
|
|
|
12534
12934
|
const circuitClaimData = await this.newCircuitClaimData(preparedCredential);
|
|
12535
12935
|
circuitClaimData.nonRevProof = toClaimNonRevStatus(preparedCredential.revStatus);
|
|
12536
12936
|
const circuitInputs = new AtomicQueryMTPV2Inputs();
|
|
12537
|
-
circuitInputs.id =
|
|
12937
|
+
circuitInputs.id = import_js_iden3_core38.DID.idFromDID(identifier);
|
|
12538
12938
|
circuitInputs.requestID = BigInt(proofReq.id);
|
|
12539
12939
|
const query = circuitQueries[0];
|
|
12540
12940
|
query.operator = this.transformV2QueryOperator(query.operator);
|
|
@@ -12545,7 +12945,7 @@ var InputGenerator = class {
|
|
|
12545
12945
|
incProof: { proof: circuitClaimData.proof, treeState: circuitClaimData.treeState },
|
|
12546
12946
|
nonRevProof: circuitClaimData.nonRevProof
|
|
12547
12947
|
};
|
|
12548
|
-
circuitInputs.currentTimeStamp = (0,
|
|
12948
|
+
circuitInputs.currentTimeStamp = (0, import_js_iden3_core38.getUnixTimestamp)(/* @__PURE__ */ new Date());
|
|
12549
12949
|
circuitInputs.claimSubjectProfileNonce = BigInt(params.credentialSubjectProfileNonce);
|
|
12550
12950
|
circuitInputs.profileNonce = BigInt(params.authProfileNonce);
|
|
12551
12951
|
circuitInputs.skipClaimRevocationCheck = params.skipRevocation;
|
|
@@ -12567,8 +12967,8 @@ var InputGenerator = class {
|
|
|
12567
12967
|
});
|
|
12568
12968
|
circuitClaimData.nonRevProof = toClaimNonRevStatus(preparedCredential.revStatus);
|
|
12569
12969
|
const circuitInputs = new AtomicQueryMTPV2OnChainInputs();
|
|
12570
|
-
const id =
|
|
12571
|
-
circuitInputs.id =
|
|
12970
|
+
const id = import_js_iden3_core38.DID.idFromDID(identifier);
|
|
12971
|
+
circuitInputs.id = import_js_iden3_core38.DID.idFromDID(identifier);
|
|
12572
12972
|
circuitInputs.requestID = BigInt(proofReq.id);
|
|
12573
12973
|
const stateProof = await this._stateStorage.getGISTProof(id.bigInt());
|
|
12574
12974
|
const gistProof = toGISTProof(stateProof);
|
|
@@ -12601,7 +13001,7 @@ var InputGenerator = class {
|
|
|
12601
13001
|
incProof: { proof: circuitClaimData.proof, treeState: circuitClaimData.treeState },
|
|
12602
13002
|
nonRevProof: circuitClaimData.nonRevProof
|
|
12603
13003
|
};
|
|
12604
|
-
circuitInputs.currentTimeStamp = (0,
|
|
13004
|
+
circuitInputs.currentTimeStamp = (0, import_js_iden3_core38.getUnixTimestamp)(/* @__PURE__ */ new Date());
|
|
12605
13005
|
circuitInputs.claimSubjectProfileNonce = BigInt(params.credentialSubjectProfileNonce);
|
|
12606
13006
|
circuitInputs.profileNonce = BigInt(params.authProfileNonce);
|
|
12607
13007
|
circuitInputs.skipClaimRevocationCheck = params.skipRevocation;
|
|
@@ -12618,7 +13018,7 @@ var InputGenerator = class {
|
|
|
12618
13018
|
const circuitClaimData = await this.newCircuitClaimData(preparedCredential);
|
|
12619
13019
|
circuitClaimData.nonRevProof = toClaimNonRevStatus(preparedCredential.revStatus);
|
|
12620
13020
|
const circuitInputs = new AtomicQuerySigV2Inputs();
|
|
12621
|
-
circuitInputs.id =
|
|
13021
|
+
circuitInputs.id = import_js_iden3_core38.DID.idFromDID(identifier);
|
|
12622
13022
|
circuitInputs.claim = {
|
|
12623
13023
|
issuerID: circuitClaimData?.issuerId,
|
|
12624
13024
|
signatureProof: circuitClaimData.signatureProof,
|
|
@@ -12632,7 +13032,7 @@ var InputGenerator = class {
|
|
|
12632
13032
|
const query = circuitQueries[0];
|
|
12633
13033
|
query.operator = this.transformV2QueryOperator(query.operator);
|
|
12634
13034
|
circuitInputs.query = query;
|
|
12635
|
-
circuitInputs.currentTimeStamp = (0,
|
|
13035
|
+
circuitInputs.currentTimeStamp = (0, import_js_iden3_core38.getUnixTimestamp)(/* @__PURE__ */ new Date());
|
|
12636
13036
|
this.checkOperatorSupport(proofReq.circuitId, query.operator);
|
|
12637
13037
|
return circuitInputs.inputsMarshal();
|
|
12638
13038
|
};
|
|
@@ -12651,7 +13051,7 @@ var InputGenerator = class {
|
|
|
12651
13051
|
});
|
|
12652
13052
|
circuitClaimData.nonRevProof = toClaimNonRevStatus(preparedCredential.revStatus);
|
|
12653
13053
|
const circuitInputs = new AtomicQuerySigV2OnChainInputs();
|
|
12654
|
-
const id =
|
|
13054
|
+
const id = import_js_iden3_core38.DID.idFromDID(identifier);
|
|
12655
13055
|
circuitInputs.id = id;
|
|
12656
13056
|
circuitInputs.claim = {
|
|
12657
13057
|
issuerID: circuitClaimData.issuerId,
|
|
@@ -12665,7 +13065,7 @@ var InputGenerator = class {
|
|
|
12665
13065
|
circuitInputs.skipClaimRevocationCheck = params.skipRevocation;
|
|
12666
13066
|
const query = circuitQueries[0];
|
|
12667
13067
|
circuitInputs.query = query;
|
|
12668
|
-
circuitInputs.currentTimeStamp = (0,
|
|
13068
|
+
circuitInputs.currentTimeStamp = (0, import_js_iden3_core38.getUnixTimestamp)(/* @__PURE__ */ new Date());
|
|
12669
13069
|
if (authClaimData.treeState) {
|
|
12670
13070
|
circuitInputs.treeState = {
|
|
12671
13071
|
state: authClaimData.treeState?.state,
|
|
@@ -12720,7 +13120,7 @@ var InputGenerator = class {
|
|
|
12720
13120
|
break;
|
|
12721
13121
|
}
|
|
12722
13122
|
const circuitInputs = new AtomicQueryV3Inputs();
|
|
12723
|
-
circuitInputs.id =
|
|
13123
|
+
circuitInputs.id = import_js_iden3_core38.DID.idFromDID(identifier);
|
|
12724
13124
|
circuitInputs.claim = {
|
|
12725
13125
|
issuerID: circuitClaimData?.issuerId,
|
|
12726
13126
|
signatureProof: circuitClaimData.signatureProof,
|
|
@@ -12735,10 +13135,10 @@ var InputGenerator = class {
|
|
|
12735
13135
|
const query = circuitQueries[0];
|
|
12736
13136
|
query.values = [16 /* SD */, 0 /* NOOP */].includes(query.operator) ? [] : query.values;
|
|
12737
13137
|
circuitInputs.query = query;
|
|
12738
|
-
circuitInputs.currentTimeStamp = (0,
|
|
13138
|
+
circuitInputs.currentTimeStamp = (0, import_js_iden3_core38.getUnixTimestamp)(/* @__PURE__ */ new Date());
|
|
12739
13139
|
circuitInputs.proofType = proofType;
|
|
12740
13140
|
circuitInputs.linkNonce = params.linkNonce ?? BigInt(0);
|
|
12741
|
-
circuitInputs.verifierID = params.verifierDid ?
|
|
13141
|
+
circuitInputs.verifierID = params.verifierDid ? import_js_iden3_core38.DID.idFromDID(params.verifierDid) : void 0;
|
|
12742
13142
|
circuitInputs.nullifierSessionID = proofReq.params?.nullifierSessionId ? BigInt(proofReq.params?.nullifierSessionId?.toString()) : BigInt(0);
|
|
12743
13143
|
this.checkOperatorSupport(proofReq.circuitId, query.operator);
|
|
12744
13144
|
return circuitInputs.inputsMarshal();
|
|
@@ -12750,7 +13150,7 @@ var InputGenerator = class {
|
|
|
12750
13150
|
params,
|
|
12751
13151
|
circuitQueries
|
|
12752
13152
|
}) => {
|
|
12753
|
-
const id =
|
|
13153
|
+
const id = import_js_iden3_core38.DID.idFromDID(identifier);
|
|
12754
13154
|
const circuitClaimData = await this.newCircuitClaimData(preparedCredential);
|
|
12755
13155
|
circuitClaimData.nonRevProof = toClaimNonRevStatus(preparedCredential.revStatus);
|
|
12756
13156
|
let proofType;
|
|
@@ -12772,7 +13172,7 @@ var InputGenerator = class {
|
|
|
12772
13172
|
break;
|
|
12773
13173
|
}
|
|
12774
13174
|
const circuitInputs = new AtomicQueryV3OnChainInputs();
|
|
12775
|
-
circuitInputs.id =
|
|
13175
|
+
circuitInputs.id = import_js_iden3_core38.DID.idFromDID(identifier);
|
|
12776
13176
|
circuitInputs.claim = {
|
|
12777
13177
|
issuerID: circuitClaimData?.issuerId,
|
|
12778
13178
|
signatureProof: circuitClaimData.signatureProof,
|
|
@@ -12787,10 +13187,10 @@ var InputGenerator = class {
|
|
|
12787
13187
|
const query = circuitQueries[0];
|
|
12788
13188
|
query.values = [16 /* SD */, 0 /* NOOP */].includes(query.operator) ? [] : query.values;
|
|
12789
13189
|
circuitInputs.query = query;
|
|
12790
|
-
circuitInputs.currentTimeStamp = (0,
|
|
13190
|
+
circuitInputs.currentTimeStamp = (0, import_js_iden3_core38.getUnixTimestamp)(/* @__PURE__ */ new Date());
|
|
12791
13191
|
circuitInputs.proofType = proofType;
|
|
12792
13192
|
circuitInputs.linkNonce = params.linkNonce ?? BigInt(0);
|
|
12793
|
-
circuitInputs.verifierID = params.verifierDid ?
|
|
13193
|
+
circuitInputs.verifierID = params.verifierDid ? import_js_iden3_core38.DID.idFromDID(params.verifierDid) : void 0;
|
|
12794
13194
|
circuitInputs.nullifierSessionID = proofReq.params?.nullifierSessionId ? BigInt(proofReq.params?.nullifierSessionId?.toString()) : BigInt(0);
|
|
12795
13195
|
const isEthIdentity = isEthereumIdentity(identifier);
|
|
12796
13196
|
circuitInputs.isBJJAuthEnabled = isEthIdentity ? 0 : 1;
|
|
@@ -12851,16 +13251,16 @@ var InputGenerator = class {
|
|
|
12851
13251
|
};
|
|
12852
13252
|
|
|
12853
13253
|
// src/proof/verifiers/pub-signals-verifier.ts
|
|
12854
|
-
var
|
|
13254
|
+
var import_js_iden3_core40 = require("@iden3/js-iden3-core");
|
|
12855
13255
|
var import_js_jsonld_merklization8 = require("@iden3/js-jsonld-merklization");
|
|
12856
13256
|
|
|
12857
13257
|
// src/proof/verifiers/query.ts
|
|
12858
|
-
var
|
|
13258
|
+
var import_js_iden3_core39 = require("@iden3/js-iden3-core");
|
|
12859
13259
|
var import_js_jsonld_merklization7 = require("@iden3/js-jsonld-merklization");
|
|
12860
13260
|
var import_ethers13 = require("ethers");
|
|
12861
13261
|
var defaultProofGenerationDelayOpts = 24 * 60 * 60 * 1e3;
|
|
12862
13262
|
async function checkQueryRequest(query, queriesMetadata, ldContext, outputs, circuitId, schemaLoader, opts) {
|
|
12863
|
-
const userDID =
|
|
13263
|
+
const userDID = import_js_iden3_core39.DID.parseFromId(outputs.issuerId);
|
|
12864
13264
|
const issuerAllowed = !query.allowedIssuers || query.allowedIssuers?.some((issuer) => issuer === "*" || issuer === userDID.string());
|
|
12865
13265
|
if (!issuerAllowed) {
|
|
12866
13266
|
throw new Error("issuer is not in allowed list");
|
|
@@ -12883,7 +13283,7 @@ async function checkQueryRequest(query, queriesMetadata, ldContext, outputs, cir
|
|
|
12883
13283
|
if (opts?.acceptedProofGenerationDelay) {
|
|
12884
13284
|
acceptedProofGenerationDelay = opts.acceptedProofGenerationDelay;
|
|
12885
13285
|
}
|
|
12886
|
-
const timeDiff = Date.now() - (0,
|
|
13286
|
+
const timeDiff = Date.now() - (0, import_js_iden3_core39.getDateFromUnixTimestamp)(Number(outputs.timestamp)).getTime();
|
|
12887
13287
|
if (timeDiff > acceptedProofGenerationDelay) {
|
|
12888
13288
|
throw new Error("generated proof is outdated");
|
|
12889
13289
|
}
|
|
@@ -13349,7 +13749,7 @@ var PubSignalsVerifier = class {
|
|
|
13349
13749
|
if (!verifierDIDParam) {
|
|
13350
13750
|
throw new Error("verifierDid is required");
|
|
13351
13751
|
}
|
|
13352
|
-
const id =
|
|
13752
|
+
const id = import_js_iden3_core40.DID.idFromDID(verifierDIDParam);
|
|
13353
13753
|
if (verifierID.bigInt() != id.bigInt()) {
|
|
13354
13754
|
throw new Error("wrong verifier is used for nullification");
|
|
13355
13755
|
}
|
|
@@ -13396,7 +13796,7 @@ var PubSignalsVerifier = class {
|
|
|
13396
13796
|
acceptedStateTransitionDelay = opts.acceptedStateTransitionDelay;
|
|
13397
13797
|
}
|
|
13398
13798
|
if (!gist.latest) {
|
|
13399
|
-
const timeDiff = Date.now() - (0,
|
|
13799
|
+
const timeDiff = Date.now() - (0, import_js_iden3_core40.getDateFromUnixTimestamp)(Number(gist.transitionTimestamp)).getTime();
|
|
13400
13800
|
if (timeDiff > acceptedStateTransitionDelay) {
|
|
13401
13801
|
throw new Error("global state is outdated");
|
|
13402
13802
|
}
|
|
@@ -13483,7 +13883,7 @@ var PubSignalsVerifier = class {
|
|
|
13483
13883
|
return multiQueryPubSignals;
|
|
13484
13884
|
};
|
|
13485
13885
|
verifyIdOwnership = (sender, challenge) => {
|
|
13486
|
-
const senderId =
|
|
13886
|
+
const senderId = import_js_iden3_core40.DID.idFromDID(import_js_iden3_core40.DID.parse(sender));
|
|
13487
13887
|
if (senderId.string() !== this.userId.string()) {
|
|
13488
13888
|
throw new Error(
|
|
13489
13889
|
`sender id is not used for proof creation, expected ${sender}, user from public signals: ${this.userId.string()}`
|
|
@@ -13548,7 +13948,7 @@ var PubSignalsVerifier = class {
|
|
|
13548
13948
|
}
|
|
13549
13949
|
async resolve(id, state) {
|
|
13550
13950
|
const idBigInt = id.bigInt();
|
|
13551
|
-
const did =
|
|
13951
|
+
const did = import_js_iden3_core40.DID.parseFromId(id);
|
|
13552
13952
|
const isGenesis = isGenesisState(did, state);
|
|
13553
13953
|
let contractState;
|
|
13554
13954
|
try {
|
|
@@ -13626,7 +14026,7 @@ var PubSignalsVerifier = class {
|
|
|
13626
14026
|
);
|
|
13627
14027
|
const acceptedStateTransitionDelay = opts?.acceptedStateTransitionDelay ?? constants_exports.DEFAULT_PROOF_VERIFY_DELAY;
|
|
13628
14028
|
if (!issuerNonRevStateResolved.latest) {
|
|
13629
|
-
const timeDiff = Date.now() - (0,
|
|
14029
|
+
const timeDiff = Date.now() - (0, import_js_iden3_core40.getDateFromUnixTimestamp)(Number(issuerNonRevStateResolved.transitionTimestamp)).getTime();
|
|
13630
14030
|
if (timeDiff > acceptedStateTransitionDelay) {
|
|
13631
14031
|
throw new Error("issuer state is outdated");
|
|
13632
14032
|
}
|
|
@@ -13715,7 +14115,7 @@ var ProofService = class {
|
|
|
13715
14115
|
credentialCoreClaim,
|
|
13716
14116
|
revStatus: credentialWithRevStatus.revStatus
|
|
13717
14117
|
};
|
|
13718
|
-
const subjectDID =
|
|
14118
|
+
const subjectDID = import_js_iden3_core41.DID.parse(preparedCredential.credential.credentialSubject["id"]);
|
|
13719
14119
|
const { nonce: credentialSubjectProfileNonce, genesisDID: subjectGenesisDID } = await this._identityWallet.getGenesisDIDMetadata(subjectDID);
|
|
13720
14120
|
if (subjectGenesisDID.string() !== genesisDID.string()) {
|
|
13721
14121
|
throw new Error(VerifiableConstants.ERRORS.PROOF_SERVICE_PROFILE_GENESIS_DID_MISMATCH);
|
|
@@ -13728,7 +14128,7 @@ var ProofService = class {
|
|
|
13728
14128
|
}
|
|
13729
14129
|
const mtPosition = preparedCredential.credentialCoreClaim.getMerklizedPosition();
|
|
13730
14130
|
let mk;
|
|
13731
|
-
if (mtPosition !==
|
|
14131
|
+
if (mtPosition !== import_js_iden3_core41.MerklizedRootPosition.None) {
|
|
13732
14132
|
mk = await preparedCredential.credential.merklize(this._ldOptions);
|
|
13733
14133
|
}
|
|
13734
14134
|
const context = proofReq.query["context"];
|
|
@@ -13794,7 +14194,7 @@ var ProofService = class {
|
|
|
13794
14194
|
switch (circuitId) {
|
|
13795
14195
|
case "authV2" /* AuthV2 */:
|
|
13796
14196
|
{
|
|
13797
|
-
const challenge = opts.challenge ?
|
|
14197
|
+
const challenge = opts.challenge ? import_js_iden3_core41.BytesHelper.intToBytes(opts.challenge).reverse() : new Uint8Array(32);
|
|
13798
14198
|
zkProof = await this.generateAuthV2Proof(challenge, identifier);
|
|
13799
14199
|
}
|
|
13800
14200
|
return {
|
|
@@ -13877,10 +14277,10 @@ var ProofService = class {
|
|
|
13877
14277
|
throw new Error("CircuitId is not supported");
|
|
13878
14278
|
}
|
|
13879
14279
|
const { nonce: authProfileNonce, genesisDID } = await this._identityWallet.getGenesisDIDMetadata(did);
|
|
13880
|
-
const challenge =
|
|
14280
|
+
const challenge = import_js_iden3_core41.BytesHelper.bytesToInt(hash.reverse());
|
|
13881
14281
|
const authPrepared = await this._inputsGenerator.prepareAuthBJJCredential(genesisDID);
|
|
13882
14282
|
const signature = await this._identityWallet.signChallenge(challenge, authPrepared.credential);
|
|
13883
|
-
const id =
|
|
14283
|
+
const id = import_js_iden3_core41.DID.idFromDID(genesisDID);
|
|
13884
14284
|
const stateProof = await this._stateStorage.getGISTProof(id.bigInt());
|
|
13885
14285
|
const gistProof = toGISTProof(stateProof);
|
|
13886
14286
|
const authInputs = new AuthV2Inputs();
|
|
@@ -13920,7 +14320,7 @@ var ProofService = class {
|
|
|
13920
14320
|
if (globalStateInfo.replacedAtTimestamp === 0n) {
|
|
13921
14321
|
throw new Error(`state was replaced, but replaced time unknown`);
|
|
13922
14322
|
}
|
|
13923
|
-
const timeDiff = Date.now() - (0,
|
|
14323
|
+
const timeDiff = Date.now() - (0, import_js_iden3_core41.getDateFromUnixTimestamp)(Number(globalStateInfo.replacedAtTimestamp)).getTime();
|
|
13924
14324
|
if (timeDiff > (opts?.acceptedStateTransitionDelay ?? constants_exports.DEFAULT_AUTH_VERIFY_DELAY)) {
|
|
13925
14325
|
throw new Error("global state is outdated");
|
|
13926
14326
|
}
|
|
@@ -13983,18 +14383,18 @@ var IdentityWallet = class {
|
|
|
13983
14383
|
const keyId = await this._kms.createKeyFromSeed("BJJ" /* BabyJubJub */, seed);
|
|
13984
14384
|
const pubKeyHex = await this._kms.publicKey(keyId);
|
|
13985
14385
|
const pubKey = import_js_crypto12.PublicKey.newFromHex(pubKeyHex);
|
|
13986
|
-
const schemaHash =
|
|
13987
|
-
const authClaim =
|
|
14386
|
+
const schemaHash = import_js_iden3_core42.SchemaHash.authSchemaHash;
|
|
14387
|
+
const authClaim = import_js_iden3_core42.Claim.newClaim(
|
|
13988
14388
|
schemaHash,
|
|
13989
|
-
|
|
13990
|
-
|
|
14389
|
+
import_js_iden3_core42.ClaimOptions.withIndexDataInts(pubKey.p[0], pubKey.p[1]),
|
|
14390
|
+
import_js_iden3_core42.ClaimOptions.withRevocationNonce(BigInt(0))
|
|
13991
14391
|
);
|
|
13992
14392
|
authClaim.setRevocationNonce(BigInt(revNonce));
|
|
13993
14393
|
return { authClaim, pubKey };
|
|
13994
14394
|
}
|
|
13995
14395
|
async createAuthBJJCredential(did, pubKey, authClaim, currentState, revocationOpts) {
|
|
13996
14396
|
const authData = authClaim.getExpirationDate();
|
|
13997
|
-
const expiration = authData ? (0,
|
|
14397
|
+
const expiration = authData ? (0, import_js_iden3_core42.getUnixTimestamp)(authData) : 0;
|
|
13998
14398
|
const request = {
|
|
13999
14399
|
credentialSchema: VerifiableConstants.AUTH.AUTH_BJJ_CREDENTIAL_SCHEMA_JSON_URL,
|
|
14000
14400
|
type: VerifiableConstants.AUTH.AUTH_BJJ_CREDENTIAL_TYPE,
|
|
@@ -14043,13 +14443,13 @@ var IdentityWallet = class {
|
|
|
14043
14443
|
);
|
|
14044
14444
|
const ctr = await claimsTree.root();
|
|
14045
14445
|
const currentState = (0, import_js_merkletree29.hashElems)([ctr.bigInt(), import_js_merkletree29.ZERO_HASH.bigInt(), import_js_merkletree29.ZERO_HASH.bigInt()]);
|
|
14046
|
-
const didType = (0,
|
|
14047
|
-
opts.method ||
|
|
14048
|
-
opts.blockchain ||
|
|
14049
|
-
opts.networkId ||
|
|
14446
|
+
const didType = (0, import_js_iden3_core42.buildDIDType)(
|
|
14447
|
+
opts.method || import_js_iden3_core42.DidMethod.Iden3,
|
|
14448
|
+
opts.blockchain || import_js_iden3_core42.Blockchain.Polygon,
|
|
14449
|
+
opts.networkId || import_js_iden3_core42.NetworkId.Amoy
|
|
14050
14450
|
);
|
|
14051
|
-
const identifier =
|
|
14052
|
-
const did =
|
|
14451
|
+
const identifier = import_js_iden3_core42.Id.idGenesisFromIdenState(didType, currentState.bigInt());
|
|
14452
|
+
const did = import_js_iden3_core42.DID.parseFromId(identifier);
|
|
14053
14453
|
await this._storage.mt.bindMerkleTreeToNewIdentifier(tmpIdentifier, did.string());
|
|
14054
14454
|
const oldTreeState = {
|
|
14055
14455
|
revocationRoot: import_js_merkletree29.ZERO_HASH,
|
|
@@ -14133,10 +14533,10 @@ var IdentityWallet = class {
|
|
|
14133
14533
|
throw new Error(VerifiableConstants.ERRORS.ID_WALLET_SIGNER_IS_REQUIRED);
|
|
14134
14534
|
}
|
|
14135
14535
|
const currentState = import_js_merkletree29.ZERO_HASH;
|
|
14136
|
-
const didType = (0,
|
|
14137
|
-
opts.method ||
|
|
14138
|
-
opts.blockchain ||
|
|
14139
|
-
opts.networkId ||
|
|
14536
|
+
const didType = (0, import_js_iden3_core42.buildDIDType)(
|
|
14537
|
+
opts.method || import_js_iden3_core42.DidMethod.Iden3,
|
|
14538
|
+
opts.blockchain || import_js_iden3_core42.Blockchain.Polygon,
|
|
14539
|
+
opts.networkId || import_js_iden3_core42.NetworkId.Amoy
|
|
14140
14540
|
);
|
|
14141
14541
|
const keyIdEth = await this._kms.createKeyFromSeed("Secp256k1" /* Secp256k1 */, opts.seed);
|
|
14142
14542
|
const pubKeyHexEth = (await this._kms.publicKey(keyIdEth)).slice(2);
|
|
@@ -14166,13 +14566,13 @@ var IdentityWallet = class {
|
|
|
14166
14566
|
async getGenesisDIDMetadata(did) {
|
|
14167
14567
|
const identity = await this._storage.identity.getIdentity(did.string());
|
|
14168
14568
|
if (identity) {
|
|
14169
|
-
return { nonce: 0, genesisDID:
|
|
14569
|
+
return { nonce: 0, genesisDID: import_js_iden3_core42.DID.parse(identity.did) };
|
|
14170
14570
|
}
|
|
14171
14571
|
const profile = await this._storage.identity.getProfileById(did.string());
|
|
14172
14572
|
if (!profile) {
|
|
14173
14573
|
throw new Error(VerifiableConstants.ERRORS.ID_WALLET_PROFILE_OR_IDENTITY_NOT_FOUND);
|
|
14174
14574
|
}
|
|
14175
|
-
return { nonce: profile.nonce, genesisDID:
|
|
14575
|
+
return { nonce: profile.nonce, genesisDID: import_js_iden3_core42.DID.parse(profile.genesisIdentifier) };
|
|
14176
14576
|
}
|
|
14177
14577
|
/** {@inheritDoc IIdentityWallet.createProfile} */
|
|
14178
14578
|
async createProfile(did, nonce, verifier, tags) {
|
|
@@ -14316,13 +14716,13 @@ var IdentityWallet = class {
|
|
|
14316
14716
|
async sign(message, credential) {
|
|
14317
14717
|
const keyKMSId = getKMSIdByAuthCredential(credential);
|
|
14318
14718
|
const payload = import_js_crypto12.poseidon.hashBytes(message);
|
|
14319
|
-
const signature = await this._kms.sign(keyKMSId,
|
|
14719
|
+
const signature = await this._kms.sign(keyKMSId, import_js_iden3_core42.BytesHelper.intToBytes(payload));
|
|
14320
14720
|
return import_js_crypto12.Signature.newFromCompressed(signature);
|
|
14321
14721
|
}
|
|
14322
14722
|
/** {@inheritDoc IIdentityWallet.signChallenge} */
|
|
14323
14723
|
async signChallenge(challenge, credential) {
|
|
14324
14724
|
const keyKMSId = getKMSIdByAuthCredential(credential);
|
|
14325
|
-
const signature = await this._kms.sign(keyKMSId,
|
|
14725
|
+
const signature = await this._kms.sign(keyKMSId, import_js_iden3_core42.BytesHelper.intToBytes(challenge));
|
|
14326
14726
|
return import_js_crypto12.Signature.newFromCompressed(signature);
|
|
14327
14727
|
}
|
|
14328
14728
|
/** {@inheritDoc IIdentityWallet.issueCredential} */
|
|
@@ -14602,7 +15002,7 @@ var IdentityWallet = class {
|
|
|
14602
15002
|
state: newTreeModel.state,
|
|
14603
15003
|
rootOfRoots
|
|
14604
15004
|
};
|
|
14605
|
-
const userId =
|
|
15005
|
+
const userId = import_js_iden3_core42.DID.idFromDID(did);
|
|
14606
15006
|
let proof;
|
|
14607
15007
|
const isEthIdentity = isEthereumIdentity(did);
|
|
14608
15008
|
let txId;
|
|
@@ -14860,9 +15260,16 @@ var jsonLDMerklizer = __toESM(require("@iden3/js-jsonld-merklization"), 1);
|
|
|
14860
15260
|
RefreshServiceType,
|
|
14861
15261
|
RevocationStatusHandler,
|
|
14862
15262
|
SDK_EVENTS,
|
|
15263
|
+
SOLANA_CHAIN_REF,
|
|
14863
15264
|
Scalar,
|
|
14864
15265
|
SearchError,
|
|
14865
15266
|
Sec256k1Provider,
|
|
15267
|
+
SolanaNativePaymentRequest,
|
|
15268
|
+
SolanaNativePaymentSchema,
|
|
15269
|
+
SolanaPaymentInstruction,
|
|
15270
|
+
SolanaPaymentInstructionSchema,
|
|
15271
|
+
SolanaSplPaymentRequest,
|
|
15272
|
+
SolanaSplPaymentSchema,
|
|
14866
15273
|
StandardJSONCredentialsQueryFilter,
|
|
14867
15274
|
StateTransitionInputs,
|
|
14868
15275
|
StateTransitionPubSignals,
|
|
@@ -14886,7 +15293,9 @@ var jsonLDMerklizer = __toESM(require("@iden3/js-jsonld-merklization"), 1);
|
|
|
14886
15293
|
bigIntCompare,
|
|
14887
15294
|
buildAccept,
|
|
14888
15295
|
buildDIDFromEthPubKey,
|
|
15296
|
+
buildEvmPayment,
|
|
14889
15297
|
buildFieldPath,
|
|
15298
|
+
buildSolanaPayment,
|
|
14890
15299
|
buildTreeState,
|
|
14891
15300
|
buildVerifierId,
|
|
14892
15301
|
byteDecoder,
|
|
@@ -14984,6 +15393,7 @@ var jsonLDMerklizer = __toESM(require("@iden3/js-jsonld-merklization"), 1);
|
|
|
14984
15393
|
resolveDidDocument,
|
|
14985
15394
|
resolvePath,
|
|
14986
15395
|
resolveVerificationMethods,
|
|
15396
|
+
serializeSolanaPaymentInstruction,
|
|
14987
15397
|
strMTHex,
|
|
14988
15398
|
stringByPath,
|
|
14989
15399
|
subjectPositionIndex,
|
|
@@ -15005,6 +15415,7 @@ var jsonLDMerklizer = __toESM(require("@iden3/js-jsonld-merklization"), 1);
|
|
|
15005
15415
|
verifyExpiresTime,
|
|
15006
15416
|
verifyFieldValueInclusionNativeExistsSupport,
|
|
15007
15417
|
verifyFieldValueInclusionV2,
|
|
15418
|
+
verifyIden3SolanaPaymentRequest,
|
|
15008
15419
|
witnessBuilder
|
|
15009
15420
|
});
|
|
15010
15421
|
//# sourceMappingURL=index.cjs.map
|