@0xpolygonid/js-sdk 1.21.3 → 1.24.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.
Files changed (114) hide show
  1. package/dist/browser/esm/index.js +4378 -545
  2. package/dist/browser/esm/index.js.map +1 -1
  3. package/dist/browser/umd/index.js +4388 -545
  4. package/dist/browser/umd/index.js.map +1 -1
  5. package/dist/node/cjs/credentials/credential-wallet.js +11 -78
  6. package/dist/node/cjs/credentials/index.js +1 -0
  7. package/dist/node/cjs/credentials/status/did-resolver-revocation.js +21 -0
  8. package/dist/node/cjs/iden3comm/constants.js +25 -1
  9. package/dist/node/cjs/iden3comm/handlers/auth.js +52 -8
  10. package/dist/node/cjs/iden3comm/handlers/common.js +13 -1
  11. package/dist/node/cjs/iden3comm/handlers/contract-request.js +5 -1
  12. package/dist/node/cjs/iden3comm/handlers/credential-proposal.js +14 -3
  13. package/dist/node/cjs/iden3comm/handlers/fetch.js +44 -2
  14. package/dist/node/cjs/iden3comm/handlers/message-handler.js +4 -0
  15. package/dist/node/cjs/iden3comm/handlers/payment.js +265 -28
  16. package/dist/node/cjs/iden3comm/handlers/revocation-status.js +4 -0
  17. package/dist/node/cjs/iden3comm/index.js +1 -0
  18. package/dist/node/cjs/iden3comm/packageManager.js +12 -0
  19. package/dist/node/cjs/iden3comm/packers/jws.js +21 -0
  20. package/dist/node/cjs/iden3comm/packers/plain.js +19 -0
  21. package/dist/node/cjs/iden3comm/packers/zkp.js +25 -0
  22. package/dist/node/cjs/iden3comm/types/index.js +1 -0
  23. package/dist/node/cjs/iden3comm/types/protocol/accept-profile.js +2 -0
  24. package/dist/node/cjs/iden3comm/utils/accept-profile.js +107 -0
  25. package/dist/node/cjs/iden3comm/utils/index.js +1 -0
  26. package/dist/node/cjs/storage/blockchain/abi/ERC20.json +1 -0
  27. package/dist/node/cjs/storage/blockchain/abi/ERC20Permit.json +1 -0
  28. package/dist/node/cjs/storage/blockchain/did-resolver-readonly-storage.js +72 -0
  29. package/dist/node/cjs/storage/blockchain/erc20-helper.js +59 -0
  30. package/dist/node/cjs/storage/blockchain/index.js +3 -0
  31. package/dist/node/cjs/storage/blockchain/onchain-issuer-adapter/non-merklized/version/v0.0.1/onchain-non-merklized-issuer-adapter.js +245 -0
  32. package/dist/node/cjs/storage/blockchain/onchain-issuer.js +82 -0
  33. package/dist/node/cjs/storage/blockchain/onchain-zkp-verifier.js +38 -34
  34. package/dist/node/cjs/storage/interfaces/index.js +1 -0
  35. package/dist/node/cjs/storage/interfaces/onchain-issuer.js +2 -0
  36. package/dist/node/cjs/utils/did-helper.js +3 -3
  37. package/dist/node/cjs/verifiable/constants.js +29 -11
  38. package/dist/node/cjs/verifiable/credential.js +86 -0
  39. package/dist/node/esm/credentials/credential-wallet.js +12 -79
  40. package/dist/node/esm/credentials/index.js +1 -0
  41. package/dist/node/esm/credentials/status/did-resolver-revocation.js +17 -0
  42. package/dist/node/esm/iden3comm/constants.js +24 -0
  43. package/dist/node/esm/iden3comm/handlers/auth.js +55 -11
  44. package/dist/node/esm/iden3comm/handlers/common.js +11 -0
  45. package/dist/node/esm/iden3comm/handlers/contract-request.js +7 -3
  46. package/dist/node/esm/iden3comm/handlers/credential-proposal.js +15 -4
  47. package/dist/node/esm/iden3comm/handlers/fetch.js +44 -2
  48. package/dist/node/esm/iden3comm/handlers/message-handler.js +4 -0
  49. package/dist/node/esm/iden3comm/handlers/payment.js +264 -29
  50. package/dist/node/esm/iden3comm/handlers/revocation-status.js +4 -0
  51. package/dist/node/esm/iden3comm/index.js +1 -0
  52. package/dist/node/esm/iden3comm/packageManager.js +12 -0
  53. package/dist/node/esm/iden3comm/packers/jws.js +22 -1
  54. package/dist/node/esm/iden3comm/packers/plain.js +19 -0
  55. package/dist/node/esm/iden3comm/packers/zkp.js +26 -1
  56. package/dist/node/esm/iden3comm/types/index.js +1 -0
  57. package/dist/node/esm/iden3comm/types/protocol/accept-profile.js +1 -0
  58. package/dist/node/esm/iden3comm/utils/accept-profile.js +102 -0
  59. package/dist/node/esm/iden3comm/utils/index.js +1 -0
  60. package/dist/node/esm/storage/blockchain/abi/ERC20.json +1 -0
  61. package/dist/node/esm/storage/blockchain/abi/ERC20Permit.json +1 -0
  62. package/dist/node/esm/storage/blockchain/did-resolver-readonly-storage.js +68 -0
  63. package/dist/node/esm/storage/blockchain/erc20-helper.js +51 -0
  64. package/dist/node/esm/storage/blockchain/index.js +3 -0
  65. package/dist/node/esm/storage/blockchain/onchain-issuer-adapter/non-merklized/version/v0.0.1/onchain-non-merklized-issuer-adapter.js +241 -0
  66. package/dist/node/esm/storage/blockchain/onchain-issuer.js +78 -0
  67. package/dist/node/esm/storage/blockchain/onchain-zkp-verifier.js +38 -34
  68. package/dist/node/esm/storage/interfaces/index.js +1 -0
  69. package/dist/node/esm/storage/interfaces/onchain-issuer.js +1 -0
  70. package/dist/node/esm/utils/did-helper.js +3 -3
  71. package/dist/node/esm/verifiable/constants.js +28 -10
  72. package/dist/node/esm/verifiable/credential.js +88 -2
  73. package/dist/types/credentials/credential-wallet.d.ts +0 -6
  74. package/dist/types/credentials/index.d.ts +1 -0
  75. package/dist/types/credentials/models.d.ts +8 -0
  76. package/dist/types/credentials/status/did-resolver-revocation.d.ts +7 -0
  77. package/dist/types/iden3comm/constants.d.ts +16 -0
  78. package/dist/types/iden3comm/handlers/auth.d.ts +19 -7
  79. package/dist/types/iden3comm/handlers/common.d.ts +7 -1
  80. package/dist/types/iden3comm/handlers/contract-request.d.ts +2 -2
  81. package/dist/types/iden3comm/handlers/credential-proposal.d.ts +9 -4
  82. package/dist/types/iden3comm/handlers/fetch.d.ts +30 -6
  83. package/dist/types/iden3comm/handlers/message-handler.d.ts +6 -0
  84. package/dist/types/iden3comm/handlers/payment.d.ts +71 -10
  85. package/dist/types/iden3comm/handlers/revocation-status.d.ts +2 -2
  86. package/dist/types/iden3comm/index.d.ts +1 -0
  87. package/dist/types/iden3comm/packageManager.d.ts +4 -0
  88. package/dist/types/iden3comm/packers/jws.d.ts +5 -0
  89. package/dist/types/iden3comm/packers/plain.d.ts +4 -0
  90. package/dist/types/iden3comm/packers/zkp.d.ts +6 -0
  91. package/dist/types/iden3comm/types/index.d.ts +1 -0
  92. package/dist/types/iden3comm/types/packageManager.d.ts +14 -0
  93. package/dist/types/iden3comm/types/packer.d.ts +25 -0
  94. package/dist/types/iden3comm/types/protocol/accept-profile.d.ts +7 -0
  95. package/dist/types/iden3comm/types/protocol/auth.d.ts +1 -0
  96. package/dist/types/iden3comm/types/protocol/credentials.d.ts +6 -6
  97. package/dist/types/iden3comm/types/protocol/messages.d.ts +2 -2
  98. package/dist/types/iden3comm/types/protocol/payment.d.ts +87 -13
  99. package/dist/types/iden3comm/types/protocol/proof.d.ts +3 -3
  100. package/dist/types/iden3comm/types/protocol/revocation.d.ts +2 -2
  101. package/dist/types/iden3comm/utils/accept-profile.d.ts +3 -0
  102. package/dist/types/iden3comm/utils/index.d.ts +1 -0
  103. package/dist/types/storage/blockchain/did-resolver-readonly-storage.d.ts +16 -0
  104. package/dist/types/storage/blockchain/erc20-helper.d.ts +19 -0
  105. package/dist/types/storage/blockchain/index.d.ts +3 -0
  106. package/dist/types/storage/blockchain/onchain-issuer-adapter/non-merklized/version/v0.0.1/onchain-non-merklized-issuer-adapter.d.ts +66 -0
  107. package/dist/types/storage/blockchain/onchain-issuer.d.ts +40 -0
  108. package/dist/types/storage/blockchain/onchain-zkp-verifier.d.ts +11 -12
  109. package/dist/types/storage/entities/state.d.ts +2 -0
  110. package/dist/types/storage/interfaces/index.d.ts +1 -0
  111. package/dist/types/storage/interfaces/onchain-issuer.d.ts +12 -0
  112. package/dist/types/verifiable/constants.d.ts +28 -11
  113. package/dist/types/verifiable/credential.d.ts +15 -2
  114. package/package.json +3 -2
@@ -0,0 +1 @@
1
+ [{ "inputs": [{ "internalType": "uint256", "name": "initialSupply", "type": "uint256" }], "stateMutability": "nonpayable", "type": "constructor" }, { "inputs": [{ "internalType": "address", "name": "spender", "type": "address" }, { "internalType": "uint256", "name": "allowance", "type": "uint256" }, { "internalType": "uint256", "name": "needed", "type": "uint256" }], "name": "ERC20InsufficientAllowance", "type": "error" }, { "inputs": [{ "internalType": "address", "name": "sender", "type": "address" }, { "internalType": "uint256", "name": "balance", "type": "uint256" }, { "internalType": "uint256", "name": "needed", "type": "uint256" }], "name": "ERC20InsufficientBalance", "type": "error" }, { "inputs": [{ "internalType": "address", "name": "approver", "type": "address" }], "name": "ERC20InvalidApprover", "type": "error" }, { "inputs": [{ "internalType": "address", "name": "receiver", "type": "address" }], "name": "ERC20InvalidReceiver", "type": "error" }, { "inputs": [{ "internalType": "address", "name": "sender", "type": "address" }], "name": "ERC20InvalidSender", "type": "error" }, { "inputs": [{ "internalType": "address", "name": "spender", "type": "address" }], "name": "ERC20InvalidSpender", "type": "error" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "address", "name": "owner", "type": "address" }, { "indexed": true, "internalType": "address", "name": "spender", "type": "address" }, { "indexed": false, "internalType": "uint256", "name": "value", "type": "uint256" }], "name": "Approval", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "address", "name": "from", "type": "address" }, { "indexed": true, "internalType": "address", "name": "to", "type": "address" }, { "indexed": false, "internalType": "uint256", "name": "value", "type": "uint256" }], "name": "Transfer", "type": "event" }, { "inputs": [{ "internalType": "address", "name": "owner", "type": "address" }, { "internalType": "address", "name": "spender", "type": "address" }], "name": "allowance", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "spender", "type": "address" }, { "internalType": "uint256", "name": "value", "type": "uint256" }], "name": "approve", "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "account", "type": "address" }], "name": "balanceOf", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "decimals", "outputs": [{ "internalType": "uint8", "name": "", "type": "uint8" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "name", "outputs": [{ "internalType": "string", "name": "", "type": "string" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "symbol", "outputs": [{ "internalType": "string", "name": "", "type": "string" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "totalSupply", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "to", "type": "address" }, { "internalType": "uint256", "name": "value", "type": "uint256" }], "name": "transfer", "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "from", "type": "address" }, { "internalType": "address", "name": "to", "type": "address" }, { "internalType": "uint256", "name": "value", "type": "uint256" }], "name": "transferFrom", "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], "stateMutability": "nonpayable", "type": "function" }]
@@ -0,0 +1 @@
1
+ [{ "inputs": [], "name": "ECDSAInvalidSignature", "type": "error" }, { "inputs": [{ "internalType": "uint256", "name": "length", "type": "uint256" }], "name": "ECDSAInvalidSignatureLength", "type": "error" }, { "inputs": [{ "internalType": "bytes32", "name": "s", "type": "bytes32" }], "name": "ECDSAInvalidSignatureS", "type": "error" }, { "inputs": [{ "internalType": "address", "name": "spender", "type": "address" }, { "internalType": "uint256", "name": "allowance", "type": "uint256" }, { "internalType": "uint256", "name": "needed", "type": "uint256" }], "name": "ERC20InsufficientAllowance", "type": "error" }, { "inputs": [{ "internalType": "address", "name": "sender", "type": "address" }, { "internalType": "uint256", "name": "balance", "type": "uint256" }, { "internalType": "uint256", "name": "needed", "type": "uint256" }], "name": "ERC20InsufficientBalance", "type": "error" }, { "inputs": [{ "internalType": "address", "name": "approver", "type": "address" }], "name": "ERC20InvalidApprover", "type": "error" }, { "inputs": [{ "internalType": "address", "name": "receiver", "type": "address" }], "name": "ERC20InvalidReceiver", "type": "error" }, { "inputs": [{ "internalType": "address", "name": "sender", "type": "address" }], "name": "ERC20InvalidSender", "type": "error" }, { "inputs": [{ "internalType": "address", "name": "spender", "type": "address" }], "name": "ERC20InvalidSpender", "type": "error" }, { "inputs": [{ "internalType": "uint256", "name": "deadline", "type": "uint256" }], "name": "ERC2612ExpiredSignature", "type": "error" }, { "inputs": [{ "internalType": "address", "name": "signer", "type": "address" }, { "internalType": "address", "name": "owner", "type": "address" }], "name": "ERC2612InvalidSigner", "type": "error" }, { "inputs": [{ "internalType": "address", "name": "account", "type": "address" }, { "internalType": "uint256", "name": "currentNonce", "type": "uint256" }], "name": "InvalidAccountNonce", "type": "error" }, { "inputs": [], "name": "InvalidShortString", "type": "error" }, { "inputs": [{ "internalType": "string", "name": "str", "type": "string" }], "name": "StringTooLong", "type": "error" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "address", "name": "owner", "type": "address" }, { "indexed": true, "internalType": "address", "name": "spender", "type": "address" }, { "indexed": false, "internalType": "uint256", "name": "value", "type": "uint256" }], "name": "Approval", "type": "event" }, { "anonymous": false, "inputs": [], "name": "EIP712DomainChanged", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "address", "name": "from", "type": "address" }, { "indexed": true, "internalType": "address", "name": "to", "type": "address" }, { "indexed": false, "internalType": "uint256", "name": "value", "type": "uint256" }], "name": "Transfer", "type": "event" }, { "inputs": [], "name": "DOMAIN_SEPARATOR", "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "owner", "type": "address" }, { "internalType": "address", "name": "spender", "type": "address" }], "name": "allowance", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "spender", "type": "address" }, { "internalType": "uint256", "name": "value", "type": "uint256" }], "name": "approve", "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "account", "type": "address" }], "name": "balanceOf", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "decimals", "outputs": [{ "internalType": "uint8", "name": "", "type": "uint8" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "eip712Domain", "outputs": [{ "internalType": "bytes1", "name": "fields", "type": "bytes1" }, { "internalType": "string", "name": "name", "type": "string" }, { "internalType": "string", "name": "version", "type": "string" }, { "internalType": "uint256", "name": "chainId", "type": "uint256" }, { "internalType": "address", "name": "verifyingContract", "type": "address" }, { "internalType": "bytes32", "name": "salt", "type": "bytes32" }, { "internalType": "uint256[]", "name": "extensions", "type": "uint256[]" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "name", "outputs": [{ "internalType": "string", "name": "", "type": "string" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "owner", "type": "address" }], "name": "nonces", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "owner", "type": "address" }, { "internalType": "address", "name": "spender", "type": "address" }, { "internalType": "uint256", "name": "value", "type": "uint256" }, { "internalType": "uint256", "name": "deadline", "type": "uint256" }, { "internalType": "uint8", "name": "v", "type": "uint8" }, { "internalType": "bytes32", "name": "r", "type": "bytes32" }, { "internalType": "bytes32", "name": "s", "type": "bytes32" }], "name": "permit", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "symbol", "outputs": [{ "internalType": "string", "name": "", "type": "string" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "totalSupply", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "to", "type": "address" }, { "internalType": "uint256", "name": "value", "type": "uint256" }], "name": "transfer", "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "from", "type": "address" }, { "internalType": "address", "name": "to", "type": "address" }, { "internalType": "uint256", "name": "value", "type": "uint256" }], "name": "transferFrom", "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], "stateMutability": "nonpayable", "type": "function" }]
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DidResolverStateReadonlyStorage = void 0;
4
+ const js_merkletree_1 = require("@iden3/js-merkletree");
5
+ const utils_1 = require("../../utils");
6
+ const js_iden3_core_1 = require("@iden3/js-iden3-core");
7
+ const ethers_1 = require("ethers");
8
+ class DidResolverStateReadonlyStorage {
9
+ constructor(resolverUrl) {
10
+ this.resolverUrl = resolverUrl;
11
+ }
12
+ async getLatestStateById(id) {
13
+ return this.getStateInfo(id);
14
+ }
15
+ async getStateInfoByIdAndState(id, state) {
16
+ return this.getStateInfo(id, state);
17
+ }
18
+ async getGISTProof(id) {
19
+ const { didDocument } = await (0, utils_1.resolveDidDocument)(js_iden3_core_1.DID.parseFromId(js_iden3_core_1.Id.fromBigInt(id)), this.resolverUrl);
20
+ const { global } = this.getIden3StateInfo2023(didDocument);
21
+ if (!global) {
22
+ throw new Error('GIST root not found');
23
+ }
24
+ const { proof } = global;
25
+ if (!proof) {
26
+ throw new Error('GIST proof not found');
27
+ }
28
+ return {
29
+ root: global.root,
30
+ existence: proof.existence,
31
+ siblings: proof.siblings?.map((sibling) => BigInt(sibling)),
32
+ index: BigInt(0),
33
+ value: BigInt(0),
34
+ auxExistence: !!proof.node_aux,
35
+ auxIndex: proof.node_aux ? BigInt(proof.node_aux.key) : BigInt(0),
36
+ auxValue: proof.node_aux ? BigInt(proof.node_aux.value) : BigInt(0)
37
+ };
38
+ }
39
+ async getGISTRootInfo(root, userId) {
40
+ const { didDocument } = await (0, utils_1.resolveDidDocument)(js_iden3_core_1.DID.parseFromId(js_iden3_core_1.Id.fromBigInt(userId)), this.resolverUrl, {
41
+ gist: js_merkletree_1.Hash.fromBigInt(root)
42
+ });
43
+ const { global } = this.getIden3StateInfo2023(didDocument);
44
+ if (!global) {
45
+ throw new Error('GIST root not found');
46
+ }
47
+ return global;
48
+ }
49
+ getRpcProvider() {
50
+ return new ethers_1.JsonRpcProvider();
51
+ }
52
+ publishState() {
53
+ throw new Error('publishState method not implemented.');
54
+ }
55
+ publishStateGeneric() {
56
+ throw new Error('publishStateGeneric method not implemented.');
57
+ }
58
+ async getStateInfo(id, state) {
59
+ const opts = state ? { state: js_merkletree_1.Hash.fromBigInt(state) } : undefined;
60
+ const { didDocument } = await (0, utils_1.resolveDidDocument)(js_iden3_core_1.DID.parseFromId(js_iden3_core_1.Id.fromBigInt(id)), this.resolverUrl, opts);
61
+ const { info } = this.getIden3StateInfo2023(didDocument);
62
+ return { ...info };
63
+ }
64
+ getIden3StateInfo2023(didDocument) {
65
+ const vm = didDocument.verificationMethod?.find((i) => i.type === 'Iden3StateInfo2023');
66
+ if (!vm) {
67
+ throw new Error('Iden3StateInfo2023 verification method not found');
68
+ }
69
+ return vm;
70
+ }
71
+ }
72
+ exports.DidResolverStateReadonlyStorage = DidResolverStateReadonlyStorage;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getERC20Decimals = exports.getPermitSignature = void 0;
7
+ const ethers_1 = require("ethers");
8
+ const ERC20Permit_json_1 = __importDefault(require("./abi/ERC20Permit.json"));
9
+ const ERC20_json_1 = __importDefault(require("./abi/ERC20.json"));
10
+ /**
11
+ * @beta
12
+ * getPermitSignature is a function to create EIP712 Permit signature
13
+ * @param {Signer} signer - User who owns the tokens
14
+ * @param {string} tokenAddress - EIP-2612 contract address
15
+ * @param {string} spender - The contract address that will spend tokens
16
+ * @param {bigint} value - Amount of tokens to approve
17
+ * @param {number} deadline - Timestamp when the permit expires
18
+ * @returns {Promise<PaymentRequestMessage>}
19
+ */
20
+ async function getPermitSignature(signer, tokenAddress, spender, value, deadline) {
21
+ const erc20PermitContract = new ethers_1.Contract(tokenAddress, ERC20Permit_json_1.default, signer);
22
+ const nonce = await erc20PermitContract.nonces(await signer.getAddress());
23
+ const domainData = await erc20PermitContract.eip712Domain();
24
+ const domain = {
25
+ name: domainData[1],
26
+ version: domainData[2],
27
+ chainId: domainData[3],
28
+ verifyingContract: tokenAddress
29
+ };
30
+ const types = {
31
+ Permit: [
32
+ { name: 'owner', type: 'address' },
33
+ { name: 'spender', type: 'address' },
34
+ { name: 'value', type: 'uint256' },
35
+ { name: 'nonce', type: 'uint256' },
36
+ { name: 'deadline', type: 'uint256' }
37
+ ]
38
+ };
39
+ const message = {
40
+ owner: await signer.getAddress(),
41
+ spender: spender,
42
+ value: value,
43
+ nonce: nonce,
44
+ deadline: deadline
45
+ };
46
+ return signer.signTypedData(domain, types, message);
47
+ }
48
+ exports.getPermitSignature = getPermitSignature;
49
+ /**
50
+ * @beta
51
+ * getERC20Decimals is a function to retrieve the number of decimals of an ERC20 token
52
+ * @param {string} tokenAddress - Token address
53
+ * @param {ethers.ContractRunner} runner - Contract runner
54
+ */
55
+ async function getERC20Decimals(tokenAddress, runner) {
56
+ const erc20Contract = new ethers_1.Contract(tokenAddress, ERC20_json_1.default, runner);
57
+ return erc20Contract.decimals();
58
+ }
59
+ exports.getERC20Decimals = getERC20Decimals;
@@ -17,3 +17,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./state"), exports);
18
18
  __exportStar(require("./onchain-zkp-verifier"), exports);
19
19
  __exportStar(require("./onchain-revocation"), exports);
20
+ __exportStar(require("./onchain-issuer"), exports);
21
+ __exportStar(require("./did-resolver-readonly-storage"), exports);
22
+ __exportStar(require("./erc20-helper"), exports);
@@ -0,0 +1,245 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OnchainNonMerklizedIssuerAdapter = void 0;
4
+ const js_iden3_core_1 = require("@iden3/js-iden3-core");
5
+ const onchain_non_merklized_issuer_base_abi_1 = require("@iden3/onchain-non-merklized-issuer-base-abi");
6
+ const verifiable_1 = require("../../../../../../verifiable");
7
+ const js_jsonld_merklization_1 = require("@iden3/js-jsonld-merklization");
8
+ const circuits_1 = require("../../../../../../circuits");
9
+ const js_merkletree_1 = require("@iden3/js-merkletree");
10
+ const ethers_1 = require("ethers");
11
+ const js_iden3_core_2 = require("@iden3/js-iden3-core");
12
+ var NonMerklizedIssuerInterfaces;
13
+ (function (NonMerklizedIssuerInterfaces) {
14
+ NonMerklizedIssuerInterfaces["InterfaceDetection"] = "0x01ffc9a7";
15
+ NonMerklizedIssuerInterfaces["InterfaceNonMerklizedIssuer"] = "0x58874949";
16
+ NonMerklizedIssuerInterfaces["InterfaceGetCredential"] = "0x5d1ca631";
17
+ })(NonMerklizedIssuerInterfaces || (NonMerklizedIssuerInterfaces = {}));
18
+ var ValueHashes;
19
+ (function (ValueHashes) {
20
+ ValueHashes["BooleanTrue"] = "18586133768512220936620570745912940619677854269274689475585506675881198879027";
21
+ ValueHashes["BooleanFalse"] = "19014214495641488759237505126948346942972912379615652741039992445865937985820";
22
+ })(ValueHashes || (ValueHashes = {}));
23
+ /**
24
+ * `OnchainNonMerklizedIssuerAdapter` provides functionality to interact with a non-merklized on-chain credential issuer.
25
+ * This adapter enables interface detection, credential retrieval, and conversion to the W3C Verifiable Credential format.
26
+ *
27
+ * @public
28
+ * @beta
29
+ * @class OnchainNonMerklizedIssuerAdapter
30
+ */
31
+ class OnchainNonMerklizedIssuerAdapter {
32
+ /**
33
+ * Initializes an instance of `OnchainNonMerklizedIssuerAdapter`.
34
+ *
35
+ * @param ethConnectionConfig The configuration for the Ethereum connection.
36
+ * @param issuerDid The decentralized identifier (DID) of the issuer.
37
+ * @param merklizationOptions Optional settings for merklization.
38
+ */
39
+ constructor(ethConnectionConfig, issuerDid, options) {
40
+ if (!ethConnectionConfig.chainId) {
41
+ throw new Error('Chain ID is required');
42
+ }
43
+ this._chainId = ethConnectionConfig.chainId;
44
+ this._contractAddress = ethers_1.ethers.getAddress(ethers_1.ethers.hexlify(js_iden3_core_1.Id.ethAddressFromId(js_iden3_core_1.DID.idFromDID(issuerDid))));
45
+ this._contract = onchain_non_merklized_issuer_base_abi_1.NonMerklizedIssuerBase__factory.connect(this._contractAddress, new ethers_1.ethers.JsonRpcProvider(ethConnectionConfig.url));
46
+ this._issuerDid = issuerDid;
47
+ this._merklizationOptions = options?.merklizationOptions;
48
+ }
49
+ /**
50
+ * Checks if the contract supports required interfaces.
51
+ * Throws an error if any required interface is unsupported.
52
+ *
53
+ * @throws Error - If required interfaces are not supported.
54
+ */
55
+ async isInterfaceSupported() {
56
+ const supportedInterfaces = [
57
+ {
58
+ name: 'Interface detection ERC-165',
59
+ value: NonMerklizedIssuerInterfaces.InterfaceDetection
60
+ },
61
+ {
62
+ name: 'Interface non-merklized issuer',
63
+ value: NonMerklizedIssuerInterfaces.InterfaceNonMerklizedIssuer
64
+ },
65
+ {
66
+ name: 'Interface get credential',
67
+ value: NonMerklizedIssuerInterfaces.InterfaceGetCredential
68
+ }
69
+ ];
70
+ const unsupportedInterfaces = await Promise.all(supportedInterfaces.map(async (interfaceObj) => {
71
+ const isSupported = await this._contract.supportsInterface(interfaceObj.value);
72
+ return isSupported ? null : interfaceObj.name;
73
+ }));
74
+ const unsupportedInterfacesFiltered = unsupportedInterfaces.filter((interfaceName) => interfaceName !== null);
75
+ if (unsupportedInterfacesFiltered.length > 0) {
76
+ throw new Error(`Unsupported interfaces: ${unsupportedInterfacesFiltered.join(', ')}`);
77
+ }
78
+ }
79
+ /**
80
+ * Retrieves a credential from the on-chain non-merklized contract.
81
+ * @param userId The user's core.Id.
82
+ * @param credentialId The unique identifier of the credential.
83
+ */
84
+ async getCredential(userId, credentialId) {
85
+ const [credentialData, coreClaimBigInts, credentialSubjectFields] = await this._contract.getCredential(userId.bigInt(), credentialId);
86
+ return { credentialData, coreClaimBigInts, credentialSubjectFields };
87
+ }
88
+ /**
89
+ * Retrieves the credential IDs of a user.
90
+ * @param userId The user's core.Id.
91
+ * @returns An array of credential IDs.
92
+ */
93
+ async getUserCredentialsIds(userId) {
94
+ return this._contract.getUserCredentialIds(userId.bigInt());
95
+ }
96
+ /**
97
+ * Converts on-chain credential to a verifiable credential.
98
+ *
99
+ * @param credentialData Data structure of the credential from the contract.
100
+ * @param coreClaimBigInts Claim data in bigint format.
101
+ * @param credentialSubjectFields Subject fields of the credential.
102
+ */
103
+ async convertOnChainInfoToW3CCredential(credentialData, coreClaimBigInts, credentialSubjectFields) {
104
+ const c = new js_iden3_core_1.Claim().unMarshalJson(JSON.stringify(coreClaimBigInts.map((b) => b.toString())));
105
+ const credentialSubject = await this.convertCredentialSubject(c, credentialData.context, credentialData._type, credentialSubjectFields);
106
+ const credentialRequest = {
107
+ id: this.credentialId(credentialData.id),
108
+ credentialSchema: credentialData.credentialSchema.id,
109
+ type: credentialData._type,
110
+ credentialSubject: credentialSubject,
111
+ expiration: c.getExpirationDate()?.getTime(),
112
+ displayMethod: this.convertDisplayMethod(credentialData.displayMethod),
113
+ context: credentialData.context,
114
+ revocationOpts: {
115
+ id: this._contractAddress,
116
+ nonce: Number(c.getRevocationNonce()),
117
+ type: verifiable_1.CredentialStatusType.Iden3OnchainSparseMerkleTreeProof2023
118
+ },
119
+ issuanceDate: (0, js_iden3_core_2.getDateFromUnixTimestamp)(Number(credentialData.issuanceDate)).getTime()
120
+ };
121
+ const existenceProof = await this.existenceProof(c);
122
+ const w3c = verifiable_1.W3CCredential.fromCredentialRequest(this._issuerDid, credentialRequest);
123
+ w3c.proof = [existenceProof];
124
+ return w3c;
125
+ }
126
+ credentialId(id) {
127
+ return `urn:iden3:onchain:${this._chainId}:${this._contractAddress}:${id}`;
128
+ }
129
+ async convertCredentialSubject(coreClaim, contractContexts, credentialType, credentialSubjectFields) {
130
+ const contractContextsStr = JSON.stringify({
131
+ '@context': contractContexts
132
+ });
133
+ const credentialSubject = {};
134
+ for (const f of credentialSubjectFields) {
135
+ const dataType = await js_jsonld_merklization_1.Path.newTypeFromContext(contractContextsStr, `${credentialType}.${f.key}`, this._merklizationOptions);
136
+ switch (dataType) {
137
+ case circuits_1.XSDNS.Boolean: {
138
+ switch (f.rawValue.toString()) {
139
+ case ValueHashes.BooleanTrue:
140
+ credentialSubject[f.key] = true;
141
+ break;
142
+ case ValueHashes.BooleanFalse:
143
+ credentialSubject[f.key] = false;
144
+ break;
145
+ }
146
+ break;
147
+ }
148
+ case (circuits_1.XSDNS.NonNegativeInteger,
149
+ circuits_1.XSDNS.NonPositiveInteger,
150
+ circuits_1.XSDNS.NegativeInteger,
151
+ circuits_1.XSDNS.PositiveInteger):
152
+ {
153
+ credentialSubject[f.key] = f.value.toString();
154
+ break;
155
+ }
156
+ case circuits_1.XSDNS.Integer: {
157
+ credentialSubject[f.key] = Number(f.value);
158
+ break;
159
+ }
160
+ case circuits_1.XSDNS.String: {
161
+ this.validateSourceValue(dataType, f.value, f.rawValue);
162
+ credentialSubject[f.key] = f.rawValue;
163
+ break;
164
+ }
165
+ case circuits_1.XSDNS.DateTime: {
166
+ const timestamp = BigInt(f.rawValue);
167
+ const sourceTimestamp = (0, js_iden3_core_2.getDateFromUnixTimestamp)(Number(timestamp)).toISOString();
168
+ this.validateSourceValue(dataType, f.value, sourceTimestamp);
169
+ credentialSubject[f.key] = sourceTimestamp;
170
+ break;
171
+ }
172
+ case circuits_1.XSDNS.Double: {
173
+ const rawFloat = Number(f.rawValue);
174
+ this.validateSourceValue(dataType, f.value, rawFloat);
175
+ credentialSubject[f.key] = rawFloat;
176
+ break;
177
+ }
178
+ default: {
179
+ throw new Error(`Unsupported data type ${dataType}`);
180
+ }
181
+ }
182
+ }
183
+ credentialSubject['type'] = credentialType;
184
+ const subjectId = coreClaim.getId();
185
+ const subjectDid = js_iden3_core_1.DID.parseFromId(subjectId);
186
+ credentialSubject['id'] = subjectDid.string();
187
+ return credentialSubject;
188
+ }
189
+ async existenceProof(coreClaim) {
190
+ const [mtpProof, stateInfo] = await this._contract.getClaimProofWithStateInfo(coreClaim.hIndex());
191
+ if (!mtpProof.existence) {
192
+ throw new Error('Claim does not exist');
193
+ }
194
+ const latestStateHash = js_merkletree_1.Hash.fromBigInt(stateInfo.state);
195
+ const latestClaimsOfRootHash = js_merkletree_1.Hash.fromBigInt(stateInfo.claimsRoot);
196
+ const latestRevocationOfRootHash = js_merkletree_1.Hash.fromBigInt(stateInfo.revocationsRoot);
197
+ const latestRootsOfRootHash = js_merkletree_1.Hash.fromBigInt(stateInfo.rootsRoot);
198
+ const p = new js_merkletree_1.Proof({
199
+ siblings: mtpProof.siblings.map((s) => js_merkletree_1.Hash.fromBigInt(s)),
200
+ existence: mtpProof.existence,
201
+ nodeAux: mtpProof.auxExistence
202
+ ? {
203
+ key: js_merkletree_1.Hash.fromBigInt(mtpProof.auxIndex),
204
+ value: js_merkletree_1.Hash.fromBigInt(mtpProof.auxValue)
205
+ }
206
+ : undefined
207
+ });
208
+ return new verifiable_1.Iden3SparseMerkleTreeProof({
209
+ issuerData: {
210
+ id: this._issuerDid,
211
+ state: {
212
+ value: latestStateHash,
213
+ claimsTreeRoot: latestClaimsOfRootHash,
214
+ revocationTreeRoot: latestRevocationOfRootHash,
215
+ rootOfRoots: latestRootsOfRootHash
216
+ }
217
+ },
218
+ mtp: p,
219
+ coreClaim: coreClaim
220
+ });
221
+ }
222
+ async validateSourceValue(dataType, originHash, source) {
223
+ const sourceHash = await js_jsonld_merklization_1.Merklizer.hashValue(dataType, source);
224
+ if (sourceHash !== originHash) {
225
+ throw new Error(`Invalid source value for ${dataType} type`);
226
+ }
227
+ }
228
+ convertDisplayMethod(onchainDisplayMethod) {
229
+ if (!onchainDisplayMethod.id || !onchainDisplayMethod._type) {
230
+ return undefined;
231
+ }
232
+ switch (onchainDisplayMethod._type) {
233
+ case verifiable_1.DisplayMethodType.Iden3BasicDisplayMethodV1: {
234
+ return {
235
+ id: onchainDisplayMethod.id,
236
+ type: verifiable_1.DisplayMethodType.Iden3BasicDisplayMethodV1
237
+ };
238
+ }
239
+ default: {
240
+ throw new Error(`Unsupported display method type ${onchainDisplayMethod._type}`);
241
+ }
242
+ }
243
+ }
244
+ }
245
+ exports.OnchainNonMerklizedIssuerAdapter = OnchainNonMerklizedIssuerAdapter;
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OnchainIssuer = void 0;
4
+ const js_iden3_core_1 = require("@iden3/js-iden3-core");
5
+ const ethers_1 = require("ethers");
6
+ const onchain_non_merklized_issuer_base_abi_1 = require("@iden3/onchain-non-merklized-issuer-base-abi");
7
+ const onchain_non_merklized_issuer_adapter_1 = require("./onchain-issuer-adapter/non-merklized/version/v0.0.1/onchain-non-merklized-issuer-adapter");
8
+ /**
9
+ * Represents an adapter for interacting with on-chain issuers.
10
+ *
11
+ * @public
12
+ * @beta
13
+ * @class OnchainIssuer
14
+ */
15
+ class OnchainIssuer {
16
+ /**
17
+ * Initializes an instance of `Adapter`.
18
+ * @param config The configuration for the Ethereum connection.
19
+ * @param merklizationOptions Optional settings for merklization.
20
+ */
21
+ constructor(config, options) {
22
+ this._ethConnectionConfig = config;
23
+ this._onchainIssuerOptions = options;
24
+ }
25
+ /**
26
+ * Retrieves a credential from the on-chain issuer.
27
+ * @param issuerDID The issuer's core.DID.
28
+ * @param userId The user's core.Id.
29
+ * @param credentialId The unique identifier of the credential.
30
+ */
31
+ async getCredential(issuerDID, userDID, credentialId) {
32
+ const { contract, connection } = this.getContractConnection(issuerDID);
33
+ const response = await contract.getCredentialAdapterVersion();
34
+ switch (response) {
35
+ case '0.0.1': {
36
+ const adapter = new onchain_non_merklized_issuer_adapter_1.OnchainNonMerklizedIssuerAdapter(connection, issuerDID, {
37
+ merklizationOptions: this._onchainIssuerOptions?.merklizationOptions
38
+ });
39
+ await adapter.isInterfaceSupported();
40
+ const { credentialData, coreClaimBigInts, credentialSubjectFields } = await adapter.getCredential(js_iden3_core_1.DID.idFromDID(userDID), credentialId);
41
+ return await adapter.convertOnChainInfoToW3CCredential(credentialData, coreClaimBigInts, credentialSubjectFields);
42
+ }
43
+ default:
44
+ throw new Error(`Unsupported adapter version ${response}`);
45
+ }
46
+ }
47
+ /**
48
+ * Retrieves the credential identifiers for a user from the on-chain issuer.
49
+ * @param issuerDID The issuer's core.DID.
50
+ * @param userId The user's core.Id.
51
+ */
52
+ async getUserCredentialIds(issuerDID, userDID) {
53
+ const { contract, connection } = this.getContractConnection(issuerDID);
54
+ const response = await contract.getCredentialAdapterVersion();
55
+ switch (response) {
56
+ case '0.0.1': {
57
+ const adapter = new onchain_non_merklized_issuer_adapter_1.OnchainNonMerklizedIssuerAdapter(connection, issuerDID, {
58
+ merklizationOptions: this._onchainIssuerOptions?.merklizationOptions
59
+ });
60
+ await adapter.isInterfaceSupported();
61
+ return await adapter.getUserCredentialsIds(js_iden3_core_1.DID.idFromDID(userDID));
62
+ }
63
+ default:
64
+ throw new Error(`Unsupported adapter version ${response}`);
65
+ }
66
+ }
67
+ getContractConnection(did) {
68
+ const issuerId = js_iden3_core_1.DID.idFromDID(did);
69
+ const chainId = (0, js_iden3_core_1.chainIDfromDID)(did);
70
+ const contractAddress = ethers_1.ethers.getAddress(ethers_1.ethers.hexlify(js_iden3_core_1.Id.ethAddressFromId(issuerId)));
71
+ const connection = this._ethConnectionConfig.find((c) => c.chainId === chainId);
72
+ if (!connection) {
73
+ throw new Error(`No connection found for chain ID ${chainId}`);
74
+ }
75
+ if (!connection.url) {
76
+ throw new Error(`No URL found for chain ID ${chainId}`);
77
+ }
78
+ const contract = new ethers_1.Contract(contractAddress, onchain_non_merklized_issuer_base_abi_1.INonMerklizedIssuerABI, new ethers_1.ethers.JsonRpcProvider(connection.url));
79
+ return { contract, connection };
80
+ }
81
+ }
82
+ exports.OnchainIssuer = OnchainIssuer;
@@ -43,23 +43,8 @@ class OnChainZKPVerifier {
43
43
  constructor(_configs, _opts) {
44
44
  this._configs = _configs;
45
45
  this._opts = _opts;
46
- /**
47
- * supported circuits
48
- */
49
- this._supportedCircuits = [
50
- circuits_1.CircuitId.AtomicQueryMTPV2OnChain,
51
- circuits_1.CircuitId.AtomicQuerySigV2OnChain,
52
- circuits_1.CircuitId.AtomicQueryV3OnChain
53
- ];
54
- /**
55
- * abi coder to encode/decode structures to solidity bytes
56
- */
57
- this._abiCoder = new ethers_1.ethers.AbiCoder();
58
46
  }
59
- /**
60
- * {@inheritDoc IOnChainZKPVerifier.prepareTxArgsSubmitV1}
61
- */
62
- async prepareTxArgsSubmitV1(txData, zkProofResponse) {
47
+ static async prepareTxArgsSubmitV1(txData, zkProofResponse) {
63
48
  if (txData.method_id.replace('0x', '') !== FunctionSignatures.SubmitZKPResponseV1) {
64
49
  throw new Error(`prepareTxArgsSubmitV1 function doesn't implement requested method id. Only '0x${FunctionSignatures.SubmitZKPResponseV1}' is supported.`);
65
50
  }
@@ -77,6 +62,12 @@ class OnChainZKPVerifier {
77
62
  ];
78
63
  return payload;
79
64
  }
65
+ /**
66
+ * {@inheritDoc IOnChainZKPVerifier.prepareTxArgsSubmitV1}
67
+ */
68
+ async prepareTxArgsSubmitV1(txData, zkProofResponse) {
69
+ return OnChainZKPVerifier.prepareTxArgsSubmitV1(txData, zkProofResponse);
70
+ }
80
71
  /**
81
72
  * {@inheritDoc IOnChainZKPVerifier.submitZKPResponse}
82
73
  */
@@ -166,13 +157,10 @@ class OnChainZKPVerifier {
166
157
  const { txnHash } = await transactionService.sendTransactionRequest(ethSigner, request);
167
158
  return new Map().set(txnHash, zkProofResponses);
168
159
  }
169
- async prepareTxArgsSubmitV2(txData, zkProofResponses) {
160
+ static async prepareTxArgsSubmitV2(resolverUrl, txData, zkProofResponses) {
170
161
  if (txData.method_id.replace('0x', '') !== FunctionSignatures.SubmitZKPResponseV2) {
171
162
  throw new Error(`submit cross chain doesn't implement requested method id. Only '0x${FunctionSignatures.SubmitZKPResponseV2}' is supported.`);
172
163
  }
173
- if (!this._opts?.didResolverUrl) {
174
- throw new Error(`did resolver url required for crosschain verification`);
175
- }
176
164
  const gistUpdateArr = [];
177
165
  const stateUpdateArr = [];
178
166
  const payload = [];
@@ -197,7 +185,9 @@ class OnChainZKPVerifier {
197
185
  continue;
198
186
  }
199
187
  gistUpdateResolutionsPending.push(JSON.stringify(gist));
200
- gistUpdateResolutions.push(this.resolveDidDocumentEip712MessageAndSignature(js_iden3_core_1.DID.parseFromId(gist.id), this._opts.didResolverUrl, { gist: gist.root }));
188
+ gistUpdateResolutions.push(this.resolveDidDocumentEip712MessageAndSignature(js_iden3_core_1.DID.parseFromId(gist.id), resolverUrl, {
189
+ gist: gist.root
190
+ }));
201
191
  }
202
192
  const stateUpdateResolutions = [];
203
193
  for (const state of stateInfo.states) {
@@ -206,7 +196,7 @@ class OnChainZKPVerifier {
206
196
  continue;
207
197
  }
208
198
  stateUpdateResolutionsPending.push(JSON.stringify(state));
209
- stateUpdateResolutions.push(this.resolveDidDocumentEip712MessageAndSignature(js_iden3_core_1.DID.parseFromId(state.id), this._opts.didResolverUrl, {
199
+ stateUpdateResolutions.push(this.resolveDidDocumentEip712MessageAndSignature(js_iden3_core_1.DID.parseFromId(state.id), resolverUrl, {
210
200
  state: state.state
211
201
  }));
212
202
  }
@@ -240,10 +230,16 @@ class OnChainZKPVerifier {
240
230
  const crossChainProofs = this.packCrossChainProofs(gistUpdateArr, stateUpdateArr);
241
231
  return [payload, crossChainProofs];
242
232
  }
243
- packZkpProof(inputs, a, b, c) {
244
- return this._abiCoder.encode(['uint256[] inputs', 'uint256[2]', 'uint256[2][2]', 'uint256[2]'], [inputs, a, b, c]);
233
+ async prepareTxArgsSubmitV2(txData, zkProofResponses) {
234
+ if (!this._opts?.didResolverUrl) {
235
+ throw new Error(`did resolver url required for crosschain verification`);
236
+ }
237
+ return OnChainZKPVerifier.prepareTxArgsSubmitV2(this._opts.didResolverUrl, txData, zkProofResponses);
238
+ }
239
+ static packZkpProof(inputs, a, b, c) {
240
+ return new ethers_1.ethers.AbiCoder().encode(['uint256[] inputs', 'uint256[2]', 'uint256[2][2]', 'uint256[2]'], [inputs, a, b, c]);
245
241
  }
246
- packCrossChainProofs(gistUpdateArr, stateUpdateArr) {
242
+ static packCrossChainProofs(gistUpdateArr, stateUpdateArr) {
247
243
  const proofs = [];
248
244
  for (const globalStateUpdate of gistUpdateArr) {
249
245
  proofs.push({
@@ -257,10 +253,10 @@ class OnChainZKPVerifier {
257
253
  proof: this.packIdentityStateMsg(stateUpdate)
258
254
  });
259
255
  }
260
- return this._abiCoder.encode(['tuple(' + 'string proofType,' + 'bytes proof' + ')[]'], [proofs]);
256
+ return new ethers_1.ethers.AbiCoder().encode(['tuple(' + 'string proofType,' + 'bytes proof' + ')[]'], [proofs]);
261
257
  }
262
- packGlobalStateMsg(msg) {
263
- return this._abiCoder.encode([
258
+ static packGlobalStateMsg(msg) {
259
+ return new ethers_1.ethers.AbiCoder().encode([
264
260
  'tuple(' +
265
261
  'tuple(' +
266
262
  'uint256 timestamp,' +
@@ -272,8 +268,8 @@ class OnChainZKPVerifier {
272
268
  ')'
273
269
  ], [msg]);
274
270
  }
275
- packIdentityStateMsg(msg) {
276
- return this._abiCoder.encode([
271
+ static packIdentityStateMsg(msg) {
272
+ return new ethers_1.ethers.AbiCoder().encode([
277
273
  'tuple(' +
278
274
  'tuple(' +
279
275
  'uint256 timestamp,' +
@@ -285,10 +281,10 @@ class OnChainZKPVerifier {
285
281
  ')'
286
282
  ], [msg]);
287
283
  }
288
- packMetadatas(metas) {
289
- return this._abiCoder.encode(['tuple(' + 'string key,' + 'bytes value' + ')[]'], [metas]);
284
+ static packMetadatas(metas) {
285
+ return new ethers_1.ethers.AbiCoder().encode(['tuple(' + 'string key,' + 'bytes value' + ')[]'], [metas]);
290
286
  }
291
- getOnChainGistRootStatePubSignals(onChainCircuitId, inputs) {
287
+ static getOnChainGistRootStatePubSignals(onChainCircuitId, inputs) {
292
288
  let atomicQueryPubSignals;
293
289
  switch (onChainCircuitId) {
294
290
  case circuits_1.CircuitId.AtomicQueryMTPV2OnChain:
@@ -305,7 +301,7 @@ class OnChainZKPVerifier {
305
301
  atomicQueryPubSignals.pubSignalsUnmarshal(encodedInputs);
306
302
  return atomicQueryPubSignals.getStatesInfo();
307
303
  }
308
- async resolveDidDocumentEip712MessageAndSignature(did, resolverUrl, opts) {
304
+ static async resolveDidDocumentEip712MessageAndSignature(did, resolverUrl, opts) {
309
305
  const didDoc = await (0, utils_1.resolveDidDocument)(did, resolverUrl, {
310
306
  ...opts,
311
307
  signature: utils_1.DIDDocumentSignature.EthereumEip712Signature2021
@@ -339,3 +335,11 @@ class OnChainZKPVerifier {
339
335
  }
340
336
  }
341
337
  exports.OnChainZKPVerifier = OnChainZKPVerifier;
338
+ /**
339
+ * supported circuits
340
+ */
341
+ OnChainZKPVerifier._supportedCircuits = [
342
+ circuits_1.CircuitId.AtomicQueryMTPV2OnChain,
343
+ circuits_1.CircuitId.AtomicQuerySigV2OnChain,
344
+ circuits_1.CircuitId.AtomicQueryV3OnChain
345
+ ];