@0xpolygonid/js-sdk 1.30.0 → 1.31.1
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 +200 -47
- package/dist/browser/esm/index.js.map +1 -1
- package/dist/browser/umd/index.js +202 -46
- package/dist/browser/umd/index.js.map +1 -1
- package/dist/node/cjs/credentials/credential-wallet.js +1 -1
- package/dist/node/cjs/iden3comm/handlers/common.js +51 -24
- package/dist/node/cjs/identity/identity-wallet.js +12 -12
- package/dist/node/cjs/proof/proof-service.js +5 -4
- package/dist/node/cjs/proof/verifiers/query.js +25 -1
- package/dist/node/cjs/schema-processor/json/validator.js +11 -0
- package/dist/node/cjs/verifiable/constants.js +20 -1
- package/dist/node/cjs/verifiable/presentation.js +3 -3
- package/dist/node/esm/credentials/credential-wallet.js +1 -1
- package/dist/node/esm/iden3comm/handlers/common.js +51 -24
- package/dist/node/esm/identity/identity-wallet.js +12 -12
- package/dist/node/esm/proof/proof-service.js +6 -5
- package/dist/node/esm/proof/verifiers/query.js +21 -0
- package/dist/node/esm/schema-processor/json/validator.js +11 -0
- package/dist/node/esm/verifiable/constants.js +20 -1
- package/dist/node/esm/verifiable/presentation.js +3 -3
- package/dist/types/iden3comm/types/protocol/auth.d.ts +2 -2
- package/dist/types/proof/verifiers/query.d.ts +3 -0
- package/dist/types/verifiable/constants.d.ts +16 -0
- package/package.json +1 -1
|
@@ -11388,7 +11388,26 @@ var PolygonIdSdk = (function (exports) {
|
|
|
11388
11388
|
CONTEXT_TYPE_IS_EMPTY: 'ctxType is empty',
|
|
11389
11389
|
// ErrStateNotFound issuer state is genesis state.
|
|
11390
11390
|
IDENTITY_DOES_NOT_EXIST: 'Identity does not exist',
|
|
11391
|
-
NO_AUTH_CRED_FOUND: 'no auth credentials found'
|
|
11391
|
+
NO_AUTH_CRED_FOUND: 'no auth credentials found',
|
|
11392
|
+
// identity wallet
|
|
11393
|
+
ID_WALLET_NO_CREDENTIAL_SATISFIED_QUERY: 'no credential satisfied query',
|
|
11394
|
+
ID_WALLET_SIGNER_IS_REQUIRED: 'Ethereum signer is required to create Ethereum identities in order to transit state',
|
|
11395
|
+
ID_WALLET_PROVER_IS_REQUIRED: 'prover is required to generate proofs for non ethereum identities',
|
|
11396
|
+
ID_WALLET_CORE_CLAIM_REQUIRED_IN_SIG_PROOF: 'credential must have coreClaim representation in the signature proof',
|
|
11397
|
+
ID_WALLET_CORE_CLAIM_REQUIRED_IN_ANY_PROOF: 'credential must have coreClaim representation in proofs',
|
|
11398
|
+
ID_WALLET_CORE_CLAIM_MISMATCH: 'core claim representations is set in both proofs but they are not equal',
|
|
11399
|
+
ID_WALLET_CORE_CLAIM_IS_NOT_SET: 'core claim is not set in credential proofs',
|
|
11400
|
+
ID_WALLET_PROFILE_OR_IDENTITY_NOT_FOUND: 'profile or identity not found',
|
|
11401
|
+
ID_WALLET_PROFILE_ALREADY_EXISTS: 'profile with given nonce or verifier already exists',
|
|
11402
|
+
ID_WALLET_ISSUER_AUTH_BJJ_CRED_MUST_HAVE_ANY_PROOF: 'issuer auth credential must have proof',
|
|
11403
|
+
ID_WALLET_ISSUER_AUTH_BJJ_CRED_MUST_HAVE_MTP_PROOF: 'mtp is required for auth bjj key to issue new credentials',
|
|
11404
|
+
// proof service
|
|
11405
|
+
PROOF_SERVICE_NO_CREDENTIAL_FOR_IDENTITY_OR_PROFILE: 'no credentials belong to did or its profiles',
|
|
11406
|
+
PROOF_SERVICE_NO_CREDENTIAL_FOR_QUERY: 'credential not found for query',
|
|
11407
|
+
PROOF_SERVICE_PROFILE_GENESIS_DID_MISMATCH: 'subject and auth profiles are not derived from the same did',
|
|
11408
|
+
PROOF_SERVICE_NO_QUERIES_IN_ZKP_REQUEST: 'no queries in zkp request',
|
|
11409
|
+
// credential wallet
|
|
11410
|
+
CREDENTIAL_WALLET_ALL_CREDENTIALS_ARE_REVOKED: 'all claims are revoked'
|
|
11392
11411
|
},
|
|
11393
11412
|
CREDENTIAL_TYPE: {
|
|
11394
11413
|
// VerifiableCredential is a W3C verifiable credential type
|
|
@@ -37772,12 +37791,12 @@ var PolygonIdSdk = (function (exports) {
|
|
|
37772
37791
|
}
|
|
37773
37792
|
const skeleton = {
|
|
37774
37793
|
'@context': baseContext,
|
|
37775
|
-
|
|
37794
|
+
type: VerifiableConstants.CREDENTIAL_TYPE.W3C_VERIFIABLE_PRESENTATION,
|
|
37776
37795
|
verifiableCredential: {
|
|
37777
37796
|
'@context': ldContext,
|
|
37778
|
-
|
|
37797
|
+
type: vcTypes,
|
|
37779
37798
|
credentialSubject: {
|
|
37780
|
-
|
|
37799
|
+
type: tp
|
|
37781
37800
|
}
|
|
37782
37801
|
}
|
|
37783
37802
|
};
|
|
@@ -48209,6 +48228,7 @@ var PolygonIdSdk = (function (exports) {
|
|
|
48209
48228
|
validator = ajv ?? defaultJSONSchemaValidator;
|
|
48210
48229
|
if (validator.formats && !Object.keys(validator.formats).length) {
|
|
48211
48230
|
addFormats(validator);
|
|
48231
|
+
addCustomFormats(validator);
|
|
48212
48232
|
}
|
|
48213
48233
|
const validate = (schema.$id ? validator.getSchema(schema.$id) : undefined) || validator.compile(schema);
|
|
48214
48234
|
const valid = validate(data);
|
|
@@ -48219,6 +48239,16 @@ var PolygonIdSdk = (function (exports) {
|
|
|
48219
48239
|
return true;
|
|
48220
48240
|
}
|
|
48221
48241
|
}
|
|
48242
|
+
function addCustomFormats(validator) {
|
|
48243
|
+
validator.addFormat('positive-integer', {
|
|
48244
|
+
type: 'string',
|
|
48245
|
+
validate: (positiveIntegerStr) => /^[1-9]\d*$/.test(positiveIntegerStr)
|
|
48246
|
+
});
|
|
48247
|
+
validator.addFormat('non-negative-integer', {
|
|
48248
|
+
type: 'string',
|
|
48249
|
+
validate: (nonNegativeIntegerStr) => /^(0|[1-9]\d*)$/.test(nonNegativeIntegerStr)
|
|
48250
|
+
});
|
|
48251
|
+
}
|
|
48222
48252
|
|
|
48223
48253
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
48224
48254
|
/**
|
|
@@ -57574,6 +57604,82 @@ var PolygonIdSdk = (function (exports) {
|
|
|
57574
57604
|
}))) + "00";
|
|
57575
57605
|
}
|
|
57576
57606
|
|
|
57607
|
+
const regexBytes = new RegExp("^bytes([0-9]+)$");
|
|
57608
|
+
const regexNumber = new RegExp("^(u?int)([0-9]*)$");
|
|
57609
|
+
const regexArray = new RegExp("^(.*)\\[([0-9]*)\\]$");
|
|
57610
|
+
function _pack(type, value, isArray) {
|
|
57611
|
+
switch (type) {
|
|
57612
|
+
case "address":
|
|
57613
|
+
if (isArray) {
|
|
57614
|
+
return getBytes(zeroPadValue(value, 32));
|
|
57615
|
+
}
|
|
57616
|
+
return getBytes(getAddress(value));
|
|
57617
|
+
case "string":
|
|
57618
|
+
return toUtf8Bytes(value);
|
|
57619
|
+
case "bytes":
|
|
57620
|
+
return getBytes(value);
|
|
57621
|
+
case "bool":
|
|
57622
|
+
value = (!!value ? "0x01" : "0x00");
|
|
57623
|
+
if (isArray) {
|
|
57624
|
+
return getBytes(zeroPadValue(value, 32));
|
|
57625
|
+
}
|
|
57626
|
+
return getBytes(value);
|
|
57627
|
+
}
|
|
57628
|
+
let match = type.match(regexNumber);
|
|
57629
|
+
if (match) {
|
|
57630
|
+
let signed = (match[1] === "int");
|
|
57631
|
+
let size = parseInt(match[2] || "256");
|
|
57632
|
+
assertArgument((!match[2] || match[2] === String(size)) && (size % 8 === 0) && size !== 0 && size <= 256, "invalid number type", "type", type);
|
|
57633
|
+
if (isArray) {
|
|
57634
|
+
size = 256;
|
|
57635
|
+
}
|
|
57636
|
+
if (signed) {
|
|
57637
|
+
value = toTwos(value, size);
|
|
57638
|
+
}
|
|
57639
|
+
return getBytes(zeroPadValue(toBeArray(value), size / 8));
|
|
57640
|
+
}
|
|
57641
|
+
match = type.match(regexBytes);
|
|
57642
|
+
if (match) {
|
|
57643
|
+
const size = parseInt(match[1]);
|
|
57644
|
+
assertArgument(String(size) === match[1] && size !== 0 && size <= 32, "invalid bytes type", "type", type);
|
|
57645
|
+
assertArgument(dataLength(value) === size, `invalid value for ${type}`, "value", value);
|
|
57646
|
+
if (isArray) {
|
|
57647
|
+
return getBytes(zeroPadBytes(value, 32));
|
|
57648
|
+
}
|
|
57649
|
+
return value;
|
|
57650
|
+
}
|
|
57651
|
+
match = type.match(regexArray);
|
|
57652
|
+
if (match && Array.isArray(value)) {
|
|
57653
|
+
const baseType = match[1];
|
|
57654
|
+
const count = parseInt(match[2] || String(value.length));
|
|
57655
|
+
assertArgument(count === value.length, `invalid array length for ${type}`, "value", value);
|
|
57656
|
+
const result = [];
|
|
57657
|
+
value.forEach(function (value) {
|
|
57658
|
+
result.push(_pack(baseType, value, true));
|
|
57659
|
+
});
|
|
57660
|
+
return getBytes(concat(result));
|
|
57661
|
+
}
|
|
57662
|
+
assertArgument(false, "invalid type", "type", type);
|
|
57663
|
+
}
|
|
57664
|
+
// @TODO: Array Enum
|
|
57665
|
+
/**
|
|
57666
|
+
* Computes the [[link-solc-packed]] representation of %%values%%
|
|
57667
|
+
* respectively to their %%types%%.
|
|
57668
|
+
*
|
|
57669
|
+
* @example:
|
|
57670
|
+
* addr = "0x8ba1f109551bd432803012645ac136ddd64dba72"
|
|
57671
|
+
* solidityPacked([ "address", "uint" ], [ addr, 45 ]);
|
|
57672
|
+
* //_result:
|
|
57673
|
+
*/
|
|
57674
|
+
function solidityPacked(types, values) {
|
|
57675
|
+
assertArgument(types.length === values.length, "wrong number of values; expected ${ types.length }", "values", values);
|
|
57676
|
+
const tight = [];
|
|
57677
|
+
types.forEach(function (type, index) {
|
|
57678
|
+
tight.push(_pack(type, values[index]));
|
|
57679
|
+
});
|
|
57680
|
+
return hexlify(concat(tight));
|
|
57681
|
+
}
|
|
57682
|
+
|
|
57577
57683
|
//import { TypedDataDomain, TypedDataField } from "@ethersproject/providerabstract-signer";
|
|
57578
57684
|
const padding = new Uint8Array(32);
|
|
57579
57685
|
padding.fill(0);
|
|
@@ -92676,34 +92782,60 @@ var PolygonIdSdk = (function (exports) {
|
|
|
92676
92782
|
const groupedCredentialsCache = new Map();
|
|
92677
92783
|
const zkpResponses = [];
|
|
92678
92784
|
for (const proofReq of requestScope) {
|
|
92679
|
-
|
|
92680
|
-
|
|
92681
|
-
|
|
92682
|
-
|
|
92683
|
-
|
|
92684
|
-
|
|
92685
|
-
if (groupId) {
|
|
92686
|
-
if (!combinedQueryData) {
|
|
92687
|
-
throw new Error(`Invalid group id ${query.groupId}`);
|
|
92688
|
-
}
|
|
92689
|
-
const combinedQuery = combinedQueryData.query;
|
|
92690
|
-
if (!groupedCredentialsCache.has(groupId)) {
|
|
92691
|
-
const credWithRevStatus = await proofService.findCredentialByProofQuery(to, combinedQueryData.query);
|
|
92692
|
-
if (!credWithRevStatus.cred) {
|
|
92693
|
-
throw new Error(`Credential not found for query ${JSON.stringify(combinedQuery)}`);
|
|
92785
|
+
let zkpRes;
|
|
92786
|
+
try {
|
|
92787
|
+
const isCircuitSupported = opts.supportedCircuits.includes(proofReq.circuitId);
|
|
92788
|
+
if (!isCircuitSupported) {
|
|
92789
|
+
if (proofReq.optional) {
|
|
92790
|
+
continue;
|
|
92694
92791
|
}
|
|
92695
|
-
|
|
92792
|
+
throw new Error(`Circuit ${proofReq.circuitId} is not allowed`);
|
|
92696
92793
|
}
|
|
92794
|
+
const query = proofReq.query;
|
|
92795
|
+
const groupId = query.groupId;
|
|
92796
|
+
const combinedQueryData = combinedQueries.get(groupId);
|
|
92797
|
+
if (groupId) {
|
|
92798
|
+
if (!combinedQueryData) {
|
|
92799
|
+
throw new Error(`Invalid group id ${query.groupId}`);
|
|
92800
|
+
}
|
|
92801
|
+
const combinedQuery = combinedQueryData.query;
|
|
92802
|
+
if (!groupedCredentialsCache.has(groupId)) {
|
|
92803
|
+
const credWithRevStatus = await proofService.findCredentialByProofQuery(to, combinedQueryData.query);
|
|
92804
|
+
if (!credWithRevStatus.cred) {
|
|
92805
|
+
if (proofReq.optional) {
|
|
92806
|
+
continue;
|
|
92807
|
+
}
|
|
92808
|
+
throw new Error(VerifiableConstants.ERRORS.PROOF_SERVICE_NO_CREDENTIAL_FOR_QUERY +
|
|
92809
|
+
`${JSON.stringify(combinedQuery)}`);
|
|
92810
|
+
}
|
|
92811
|
+
groupedCredentialsCache.set(groupId, credWithRevStatus);
|
|
92812
|
+
}
|
|
92813
|
+
}
|
|
92814
|
+
const credWithRevStatus = groupedCredentialsCache.get(groupId);
|
|
92815
|
+
zkpRes = await proofService.generateProof(proofReq, to, {
|
|
92816
|
+
verifierDid: from,
|
|
92817
|
+
challenge: opts.challenge,
|
|
92818
|
+
skipRevocation: Boolean(query.skipClaimRevocationCheck),
|
|
92819
|
+
credential: credWithRevStatus?.cred,
|
|
92820
|
+
credentialRevocationStatus: credWithRevStatus?.revStatus,
|
|
92821
|
+
linkNonce: combinedQueryData?.linkNonce ? BigInt(combinedQueryData.linkNonce) : undefined
|
|
92822
|
+
});
|
|
92823
|
+
}
|
|
92824
|
+
catch (error) {
|
|
92825
|
+
const expectedErrors = [
|
|
92826
|
+
VerifiableConstants.ERRORS.PROOF_SERVICE_NO_CREDENTIAL_FOR_IDENTITY_OR_PROFILE,
|
|
92827
|
+
VerifiableConstants.ERRORS.ID_WALLET_NO_CREDENTIAL_SATISFIED_QUERY,
|
|
92828
|
+
VerifiableConstants.ERRORS.CREDENTIAL_WALLET_ALL_CREDENTIALS_ARE_REVOKED
|
|
92829
|
+
];
|
|
92830
|
+
// handle only errors in case credential is not found and it is optional proof request - otherwise throw
|
|
92831
|
+
if (error instanceof Error &&
|
|
92832
|
+
(expectedErrors.includes(error.message) ||
|
|
92833
|
+
error.message.includes(VerifiableConstants.ERRORS.PROOF_SERVICE_NO_CREDENTIAL_FOR_QUERY)) &&
|
|
92834
|
+
proofReq.optional) {
|
|
92835
|
+
continue;
|
|
92836
|
+
}
|
|
92837
|
+
throw error;
|
|
92697
92838
|
}
|
|
92698
|
-
const credWithRevStatus = groupedCredentialsCache.get(groupId);
|
|
92699
|
-
const zkpRes = await proofService.generateProof(proofReq, to, {
|
|
92700
|
-
verifierDid: from,
|
|
92701
|
-
challenge: opts.challenge,
|
|
92702
|
-
skipRevocation: Boolean(query.skipClaimRevocationCheck),
|
|
92703
|
-
credential: credWithRevStatus?.cred,
|
|
92704
|
-
credentialRevocationStatus: credWithRevStatus?.revStatus,
|
|
92705
|
-
linkNonce: combinedQueryData?.linkNonce ? BigInt(combinedQueryData.linkNonce) : undefined
|
|
92706
|
-
});
|
|
92707
92839
|
zkpResponses.push(zkpRes);
|
|
92708
92840
|
}
|
|
92709
92841
|
return zkpResponses;
|
|
@@ -94371,7 +94503,7 @@ var PolygonIdSdk = (function (exports) {
|
|
|
94371
94503
|
}
|
|
94372
94504
|
return { cred, revStatus };
|
|
94373
94505
|
}
|
|
94374
|
-
throw new Error(
|
|
94506
|
+
throw new Error(VerifiableConstants.ERRORS.CREDENTIAL_WALLET_ALL_CREDENTIALS_ARE_REVOKED);
|
|
94375
94507
|
}
|
|
94376
94508
|
}
|
|
94377
94509
|
|
|
@@ -102524,6 +102656,26 @@ var PolygonIdSdk = (function (exports) {
|
|
|
102524
102656
|
}
|
|
102525
102657
|
return await value.mtEntry();
|
|
102526
102658
|
};
|
|
102659
|
+
function calculateGroupId(requestIds) {
|
|
102660
|
+
const types = Array(requestIds.length).fill('uint256');
|
|
102661
|
+
const groupID = BigInt(keccak256(solidityPacked(types, requestIds))) &
|
|
102662
|
+
// It should fit in a field number in the circuit (max 253 bits). With this we truncate to 252 bits for the group ID
|
|
102663
|
+
BigInt('0x0FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF');
|
|
102664
|
+
return groupID;
|
|
102665
|
+
}
|
|
102666
|
+
function calculateRequestId(requestParams, creatorAddress) {
|
|
102667
|
+
// 0x0000000000000000FFFF...FF. Reserved first 8 bytes for the request Id type and future use
|
|
102668
|
+
// 0x00010000000000000000...00. First 2 bytes for the request Id type
|
|
102669
|
+
// - 0x0000... for old request Ids with uint64
|
|
102670
|
+
// - 0x0001... for new request Ids with uint256
|
|
102671
|
+
const requestId = (BigInt(keccak256(solidityPacked(['bytes', 'address'], [requestParams, creatorAddress]))) &
|
|
102672
|
+
BigInt('0x0000000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF')) +
|
|
102673
|
+
BigInt('0x0001000000000000000000000000000000000000000000000000000000000000');
|
|
102674
|
+
return requestId;
|
|
102675
|
+
}
|
|
102676
|
+
function calculateMultiRequestId(requestIds, groupIds, creatorAddress) {
|
|
102677
|
+
return BigInt(keccak256(solidityPacked(['uint256[]', 'uint256[]', 'address'], [requestIds, groupIds, creatorAddress])));
|
|
102678
|
+
}
|
|
102527
102679
|
|
|
102528
102680
|
function calculateQueryHashV2(values, schema, slotIndex, operator, claimPathKey, claimPathNotExists) {
|
|
102529
102681
|
const expValue = prepareCircuitArrayValues(values, 64);
|
|
@@ -103057,7 +103209,8 @@ var PolygonIdSdk = (function (exports) {
|
|
|
103057
103209
|
credentialWithRevStatus = { cred: opts.credential, revStatus };
|
|
103058
103210
|
}
|
|
103059
103211
|
if (!credentialWithRevStatus.cred) {
|
|
103060
|
-
throw new Error(
|
|
103212
|
+
throw new Error(VerifiableConstants.ERRORS.PROOF_SERVICE_NO_CREDENTIAL_FOR_QUERY +
|
|
103213
|
+
` ${JSON.stringify(proofReq.query)}`);
|
|
103061
103214
|
}
|
|
103062
103215
|
const credentialCoreClaim = await this._identityWallet.getCoreClaimFromCredential(credentialWithRevStatus.cred);
|
|
103063
103216
|
const { nonce: authProfileNonce, genesisDID } = await this._identityWallet.getGenesisDIDMetadata(identifier);
|
|
@@ -103069,11 +103222,11 @@ var PolygonIdSdk = (function (exports) {
|
|
|
103069
103222
|
const subjectDID = DID.parse(preparedCredential.credential.credentialSubject['id']);
|
|
103070
103223
|
const { nonce: credentialSubjectProfileNonce, genesisDID: subjectGenesisDID } = await this._identityWallet.getGenesisDIDMetadata(subjectDID);
|
|
103071
103224
|
if (subjectGenesisDID.string() !== genesisDID.string()) {
|
|
103072
|
-
throw new Error(
|
|
103225
|
+
throw new Error(VerifiableConstants.ERRORS.PROOF_SERVICE_PROFILE_GENESIS_DID_MISMATCH);
|
|
103073
103226
|
}
|
|
103074
103227
|
const propertiesMetadata = parseCredentialSubject(proofReq.query.credentialSubject);
|
|
103075
103228
|
if (!propertiesMetadata.length) {
|
|
103076
|
-
throw new Error(
|
|
103229
|
+
throw new Error(VerifiableConstants.ERRORS.PROOF_SERVICE_NO_QUERIES_IN_ZKP_REQUEST);
|
|
103077
103230
|
}
|
|
103078
103231
|
const mtPosition = preparedCredential.credentialCoreClaim.getMerklizedPosition();
|
|
103079
103232
|
let mk;
|
|
@@ -103257,7 +103410,7 @@ var PolygonIdSdk = (function (exports) {
|
|
|
103257
103410
|
async findCredentialByProofQuery(did, query) {
|
|
103258
103411
|
const credentials = await this._identityWallet.findOwnedCredentialsByDID(did, query);
|
|
103259
103412
|
if (!credentials.length) {
|
|
103260
|
-
throw new Error(
|
|
103413
|
+
throw new Error(VerifiableConstants.ERRORS.PROOF_SERVICE_NO_CREDENTIAL_FOR_IDENTITY_OR_PROFILE);
|
|
103261
103414
|
}
|
|
103262
103415
|
// For EQ / IN / NIN / LT / GT operations selective if credential satisfies query - we can get any.
|
|
103263
103416
|
// TODO: choose credential for selective credentials
|
|
@@ -103456,7 +103609,7 @@ var PolygonIdSdk = (function (exports) {
|
|
|
103456
103609
|
let credential;
|
|
103457
103610
|
const ethSigner = opts.ethSigner;
|
|
103458
103611
|
if (opts.createBjjCredential && !ethSigner) {
|
|
103459
|
-
throw new Error(
|
|
103612
|
+
throw new Error(VerifiableConstants.ERRORS.ID_WALLET_SIGNER_IS_REQUIRED);
|
|
103460
103613
|
}
|
|
103461
103614
|
const currentState = ZERO_HASH; // In Ethereum identities we don't have an initial state with the auth credential
|
|
103462
103615
|
const didType = buildDIDType(opts.method || DidMethod.Iden3, opts.blockchain || Blockchain.Polygon, opts.networkId || NetworkId.Amoy);
|
|
@@ -103494,7 +103647,7 @@ var PolygonIdSdk = (function (exports) {
|
|
|
103494
103647
|
}
|
|
103495
103648
|
const profile = await this._storage.identity.getProfileById(did.string());
|
|
103496
103649
|
if (!profile) {
|
|
103497
|
-
throw new Error(
|
|
103650
|
+
throw new Error(VerifiableConstants.ERRORS.ID_WALLET_PROFILE_OR_IDENTITY_NOT_FOUND);
|
|
103498
103651
|
}
|
|
103499
103652
|
return { nonce: profile.nonce, genesisDID: DID.parse(profile.genesisIdentifier) };
|
|
103500
103653
|
}
|
|
@@ -103504,7 +103657,7 @@ var PolygonIdSdk = (function (exports) {
|
|
|
103504
103657
|
const identityProfiles = await this._storage.identity.getProfilesByGenesisIdentifier(did.string());
|
|
103505
103658
|
const existingProfile = identityProfiles.find((p) => p.nonce == nonce || p.verifier == verifier);
|
|
103506
103659
|
if (existingProfile) {
|
|
103507
|
-
throw new Error(
|
|
103660
|
+
throw new Error(VerifiableConstants.ERRORS.ID_WALLET_PROFILE_ALREADY_EXISTS);
|
|
103508
103661
|
}
|
|
103509
103662
|
await this._storage.identity.saveProfile({
|
|
103510
103663
|
id: profileDID.string(),
|
|
@@ -103653,11 +103806,11 @@ var PolygonIdSdk = (function (exports) {
|
|
|
103653
103806
|
const coreClaimHash = z$2.hash([hi, hv]);
|
|
103654
103807
|
const signature = await this.signChallenge(coreClaimHash, issuerAuthBJJCredential);
|
|
103655
103808
|
if (!issuerAuthBJJCredential.proof) {
|
|
103656
|
-
throw new Error(
|
|
103809
|
+
throw new Error(VerifiableConstants.ERRORS.ID_WALLET_ISSUER_AUTH_BJJ_CRED_MUST_HAVE_ANY_PROOF);
|
|
103657
103810
|
}
|
|
103658
103811
|
const mtpAuthBJJProof = issuerAuthBJJCredential.getIden3SparseMerkleTreeProof();
|
|
103659
103812
|
if (!mtpAuthBJJProof) {
|
|
103660
|
-
throw new Error(
|
|
103813
|
+
throw new Error(VerifiableConstants.ERRORS.ID_WALLET_ISSUER_AUTH_BJJ_CRED_MUST_HAVE_MTP_PROOF);
|
|
103661
103814
|
}
|
|
103662
103815
|
const sigProof = new BJJSignatureProof2021({
|
|
103663
103816
|
issuerData: {
|
|
@@ -103697,7 +103850,7 @@ var PolygonIdSdk = (function (exports) {
|
|
|
103697
103850
|
const issuerTree = await this.getDIDTreeModel(issuerDID);
|
|
103698
103851
|
const coreClaim = await this.getCoreClaimFromCredential(credential);
|
|
103699
103852
|
if (!coreClaim) {
|
|
103700
|
-
throw new Error(
|
|
103853
|
+
throw new Error(VerifiableConstants.ERRORS.ID_WALLET_CORE_CLAIM_REQUIRED_IN_ANY_PROOF);
|
|
103701
103854
|
}
|
|
103702
103855
|
const nonce = coreClaim.getRevocationNonce();
|
|
103703
103856
|
await issuerTree.revocationTree.add(nonce, BigInt(0));
|
|
@@ -103720,7 +103873,7 @@ var PolygonIdSdk = (function (exports) {
|
|
|
103720
103873
|
// credential must have a bjj signature proof
|
|
103721
103874
|
const coreClaim = credential.getCoreClaimFromProof(exports.ProofType.BJJSignature);
|
|
103722
103875
|
if (!coreClaim) {
|
|
103723
|
-
throw new Error(
|
|
103876
|
+
throw new Error(VerifiableConstants.ERRORS.ID_WALLET_CORE_CLAIM_REQUIRED_IN_SIG_PROOF);
|
|
103724
103877
|
}
|
|
103725
103878
|
await this._storage.mt.addToMerkleTree(issuerDID.string(), exports.MerkleTreeType.Claims, coreClaim.hIndex(), coreClaim.hValue());
|
|
103726
103879
|
}
|
|
@@ -103752,7 +103905,7 @@ var PolygonIdSdk = (function (exports) {
|
|
|
103752
103905
|
const coreClaim = credential.getCoreClaimFromProof(exports.ProofType.BJJSignature) ||
|
|
103753
103906
|
(await credential.toCoreClaim(opts));
|
|
103754
103907
|
if (!coreClaim) {
|
|
103755
|
-
throw new Error(
|
|
103908
|
+
throw new Error(VerifiableConstants.ERRORS.ID_WALLET_CORE_CLAIM_REQUIRED_IN_SIG_PROOF);
|
|
103756
103909
|
}
|
|
103757
103910
|
const mtpWithProof = await this.generateCoreClaimMtp(issuerDID, coreClaim, treeState);
|
|
103758
103911
|
const mtpProof = new Iden3SparseMerkleTreeProof({
|
|
@@ -103820,10 +103973,10 @@ var PolygonIdSdk = (function (exports) {
|
|
|
103820
103973
|
if (coreClaimFromMtpProof &&
|
|
103821
103974
|
coreClaimFromSigProof &&
|
|
103822
103975
|
coreClaimFromMtpProof.hex() !== coreClaimFromSigProof.hex()) {
|
|
103823
|
-
throw new Error(
|
|
103976
|
+
throw new Error(VerifiableConstants.ERRORS.ID_WALLET_CORE_CLAIM_MISMATCH);
|
|
103824
103977
|
}
|
|
103825
103978
|
if (!coreClaimFromMtpProof && !coreClaimFromSigProof) {
|
|
103826
|
-
throw new Error(
|
|
103979
|
+
throw new Error(VerifiableConstants.ERRORS.ID_WALLET_CORE_CLAIM_IS_NOT_SET);
|
|
103827
103980
|
}
|
|
103828
103981
|
//eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
103829
103982
|
const coreClaim = coreClaimFromMtpProof ?? coreClaimFromSigProof;
|
|
@@ -103832,7 +103985,7 @@ var PolygonIdSdk = (function (exports) {
|
|
|
103832
103985
|
async findOwnedCredentialsByDID(did, query) {
|
|
103833
103986
|
const credentials = await this._credentialWallet.findByQuery(query);
|
|
103834
103987
|
if (!credentials.length) {
|
|
103835
|
-
throw new Error(
|
|
103988
|
+
throw new Error(VerifiableConstants.ERRORS.ID_WALLET_NO_CREDENTIAL_SATISFIED_QUERY);
|
|
103836
103989
|
}
|
|
103837
103990
|
const { genesisDID } = await this.getGenesisDIDMetadata(did);
|
|
103838
103991
|
const profiles = await this.getProfilesByDID(genesisDID);
|
|
@@ -103872,7 +104025,7 @@ var PolygonIdSdk = (function (exports) {
|
|
|
103872
104025
|
let txId;
|
|
103873
104026
|
if (!isEthIdentity) {
|
|
103874
104027
|
if (!prover) {
|
|
103875
|
-
throw new Error(
|
|
104028
|
+
throw new Error(VerifiableConstants.ERRORS.ID_WALLET_PROVER_IS_REQUIRED);
|
|
103876
104029
|
}
|
|
103877
104030
|
// generate the proof
|
|
103878
104031
|
const authInfo = await this._inputsGenerator.prepareAuthBJJCredential(did, oldTreeState);
|
|
@@ -104113,8 +104266,11 @@ var PolygonIdSdk = (function (exports) {
|
|
|
104113
104266
|
exports.cacheLoader = cacheLoader;
|
|
104114
104267
|
exports.calcChallengeAuthV2 = calcChallengeAuthV2;
|
|
104115
104268
|
exports.calculateCoreSchemaHash = calculateCoreSchemaHash;
|
|
104269
|
+
exports.calculateGroupId = calculateGroupId;
|
|
104270
|
+
exports.calculateMultiRequestId = calculateMultiRequestId;
|
|
104116
104271
|
exports.calculateQueryHashV2 = calculateQueryHashV2;
|
|
104117
104272
|
exports.calculateQueryHashV3 = calculateQueryHashV3;
|
|
104273
|
+
exports.calculateRequestId = calculateRequestId;
|
|
104118
104274
|
exports.checkCircuitOperator = checkCircuitOperator;
|
|
104119
104275
|
exports.checkCircuitQueriesLength = checkCircuitQueriesLength;
|
|
104120
104276
|
exports.checkDataInField = checkDataInField;
|