@0xpolygonid/js-sdk 1.29.0 → 1.29.2

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 (35) hide show
  1. package/dist/browser/esm/index.js +8997 -8920
  2. package/dist/browser/esm/index.js.map +1 -1
  3. package/dist/browser/umd/index.js +8998 -8917
  4. package/dist/browser/umd/index.js.map +1 -1
  5. package/dist/node/cjs/iden3comm/handlers/auth.js +1 -1
  6. package/dist/node/cjs/iden3comm/handlers/common.js +79 -23
  7. package/dist/node/cjs/iden3comm/handlers/contract-request.js +8 -7
  8. package/dist/node/cjs/iden3comm/utils/index.js +0 -1
  9. package/dist/node/cjs/proof/proof-service.js +0 -1
  10. package/dist/node/cjs/proof/provers/inputs-generator.js +2 -4
  11. package/dist/node/cjs/storage/blockchain/common.js +19 -0
  12. package/dist/node/cjs/storage/blockchain/onchain-zkp-verifier.js +122 -94
  13. package/dist/node/cjs/storage/blockchain/state.js +2 -2
  14. package/dist/node/esm/iden3comm/handlers/auth.js +1 -1
  15. package/dist/node/esm/iden3comm/handlers/common.js +78 -24
  16. package/dist/node/esm/iden3comm/handlers/contract-request.js +9 -8
  17. package/dist/node/esm/iden3comm/utils/index.js +0 -1
  18. package/dist/node/esm/proof/proof-service.js +0 -1
  19. package/dist/node/esm/proof/provers/inputs-generator.js +2 -4
  20. package/dist/node/esm/storage/blockchain/common.js +14 -0
  21. package/dist/node/esm/storage/blockchain/onchain-zkp-verifier.js +120 -94
  22. package/dist/node/esm/storage/blockchain/state.js +1 -1
  23. package/dist/types/iden3comm/handlers/common.d.ts +32 -5
  24. package/dist/types/iden3comm/types/protocol/auth.d.ts +5 -5
  25. package/dist/types/iden3comm/types/protocol/contract-request.d.ts +16 -5
  26. package/dist/types/iden3comm/utils/index.d.ts +0 -1
  27. package/dist/types/proof/proof-service.d.ts +3 -3
  28. package/dist/types/proof/provers/inputs-generator.d.ts +3 -0
  29. package/dist/types/storage/blockchain/common.d.ts +7 -0
  30. package/dist/types/storage/blockchain/onchain-zkp-verifier.d.ts +45 -6
  31. package/dist/types/storage/interfaces/onchain-zkp-verifier.d.ts +9 -4
  32. package/package.json +1 -1
  33. package/dist/node/cjs/iden3comm/utils/contract-request.utils.js +0 -74
  34. package/dist/node/esm/iden3comm/utils/contract-request.utils.js +0 -67
  35. package/dist/types/iden3comm/utils/contract-request.utils.d.ts +0 -27
@@ -1,6 +1,8 @@
1
+ import { GlobalStateUpdate, IdentityStateUpdate } from '../../../storage/entities/state';
1
2
  import { PROTOCOL_MESSAGE_TYPE } from '../../constants';
2
3
  import { BasicMessage } from '../packer';
3
- import { DIDDocument, ZeroKnowledgeProofRequest, ZeroKnowledgeProofResponse } from './auth';
4
+ import { DIDDocument, ZeroKnowledgeProofAuthResponse, ZeroKnowledgeProofRequest, ZeroKnowledgeProofResponse } from './auth';
5
+ import { DID } from '@iden3/js-iden3-core';
4
6
  /** ContractInvokeRequest represents structure of contract invoke request object */
5
7
  export type ContractInvokeRequest = BasicMessage & {
6
8
  body: ContractInvokeRequestBody;
@@ -24,8 +26,8 @@ export type ContractInvokeResponseBody = {
24
26
  scope: Array<OnChainZeroKnowledgeProofResponse>;
25
27
  transaction_data: ContractInvokeTransactionData;
26
28
  did_doc?: DIDDocument;
27
- crossChainProofs?: string[];
28
- authProofs?: AuthProofResponse[];
29
+ crossChainProof?: CrossChainProof;
30
+ authProof?: AuthProof;
29
31
  };
30
32
  /** OnChainZeroKnowledgeProofResponse represents structure of onchain zero knowledge proof response */
31
33
  export type OnChainZeroKnowledgeProofResponse = ZeroKnowledgeProofResponse & {
@@ -38,10 +40,19 @@ export type ContractInvokeTransactionData = {
38
40
  chain_id: number;
39
41
  network?: string;
40
42
  };
43
+ export type AuthProofEthIdentity = {
44
+ userDid: DID;
45
+ };
46
+ export type AuthProofZKP = {
47
+ zkp: ZeroKnowledgeProofAuthResponse;
48
+ };
41
49
  /** AuthProofResponse represents structure of zkp response */
42
- export type AuthProofResponse = {
50
+ export type AuthProof = {
43
51
  authMethod: AuthMethod;
44
- proof: string;
52
+ } & (AuthProofEthIdentity | AuthProofZKP);
53
+ export type CrossChainProof = {
54
+ globalStateProofs: GlobalStateUpdate[];
55
+ identityStateProofs: IdentityStateUpdate[];
45
56
  };
46
57
  export declare enum AuthMethod {
47
58
  AUTHV2 = "authV2",
@@ -1,5 +1,4 @@
1
1
  export * from './envelope';
2
2
  export * from './message';
3
3
  export * from './did';
4
- export * from './contract-request.utils';
5
4
  export * from './accept-profile';
@@ -9,7 +9,7 @@ import { ZKProof } from '@iden3/js-jwz';
9
9
  import { Signer } from 'ethers';
10
10
  import { StateVerificationOpts, JSONObject, ZeroKnowledgeProofRequest, ZeroKnowledgeProofResponse, ZeroKnowledgeProofAuthResponse } from '../iden3comm';
11
11
  import { ICircuitStorage, IStateStorage } from '../storage';
12
- import { ProofGenerationOptions } from './provers/inputs-generator';
12
+ import { AuthProofGenerationOptions, ProofGenerationOptions } from './provers/inputs-generator';
13
13
  import { VerifyOpts } from './verifiers';
14
14
  export interface QueryWithFieldName {
15
15
  query: Query;
@@ -90,7 +90,7 @@ export interface IProofService {
90
90
  *
91
91
  * @returns `Promise<ZeroKnowledgeProofResponse>`
92
92
  */
93
- generateAuthProof(circuitId: CircuitId, identifier: DID, opts?: ProofGenerationOptions): Promise<ZeroKnowledgeProofAuthResponse>;
93
+ generateAuthProof(circuitId: CircuitId, identifier: DID, opts?: AuthProofGenerationOptions): Promise<ZeroKnowledgeProofAuthResponse>;
94
94
  /**
95
95
  * state verification function
96
96
  *
@@ -149,7 +149,7 @@ export declare class ProofService implements IProofService {
149
149
  /** {@inheritdoc IProofService.generateProof} */
150
150
  generateProof(proofReq: ZeroKnowledgeProofRequest, identifier: DID, opts?: ProofGenerationOptions): Promise<ZeroKnowledgeProofResponse>;
151
151
  /** {@inheritdoc IProofService.generateAuthProof} */
152
- generateAuthProof(circuitId: CircuitId, identifier: DID, opts?: ProofGenerationOptions): Promise<ZeroKnowledgeProofAuthResponse>;
152
+ generateAuthProof(circuitId: CircuitId, identifier: DID, opts?: AuthProofGenerationOptions): Promise<ZeroKnowledgeProofAuthResponse>;
153
153
  /** {@inheritdoc IProofService.transitState} */
154
154
  transitState(did: DID, oldTreeState: TreeState, isOldStateGenesis: boolean, stateStorage: IStateStorage, // for compatibility with previous versions we leave this parameter
155
155
  ethSigner: Signer): Promise<string>;
@@ -18,6 +18,9 @@ export type ProofGenerationOptions = {
18
18
  verifierDid?: DID;
19
19
  linkNonce?: bigint;
20
20
  };
21
+ export type AuthProofGenerationOptions = {
22
+ challenge?: bigint;
23
+ };
21
24
  export type ProofInputsParams = ProofGenerationOptions & DIDProfileMetadata;
22
25
  type InputContext = {
23
26
  preparedCredential: PreparedCredential;
@@ -0,0 +1,7 @@
1
+ import { ProofData } from '@iden3/js-jwz';
2
+ export declare const packZkpProof: (inputs: string[], a: string[], b: string[][], c: string[]) => string;
3
+ export declare const prepareZkpProof: (proof: ProofData) => {
4
+ a: string[];
5
+ b: string[][];
6
+ c: string[];
7
+ };
@@ -1,7 +1,8 @@
1
1
  import { Signer } from 'ethers';
2
2
  import { EthConnectionConfig } from './state';
3
3
  import { IOnChainZKPVerifier } from '../interfaces/onchain-zkp-verifier';
4
- import { AuthProofResponse, ContractInvokeTransactionData, JsonDocumentObjectValue, ZeroKnowledgeInvokeResponse, ZeroKnowledgeProofResponse } from '../../iden3comm';
4
+ import { AuthMethod, AuthProof, ContractInvokeTransactionData, CrossChainProof, JsonDocumentObjectValue, ZeroKnowledgeInvokeResponse, ZeroKnowledgeProofResponse } from '../../iden3comm';
5
+ import { DID } from '@iden3/js-iden3-core';
5
6
  import { GlobalStateUpdate } from '../entities/state';
6
7
  /**
7
8
  * Supported function signature for SubmitZKPResponse
@@ -22,6 +23,31 @@ export declare enum FunctionSignatures {
22
23
  export type OnChainZKPVerifierOptions = {
23
24
  didResolverUrl?: string;
24
25
  };
26
+ type ProofPreparationResult = {
27
+ requestId: string | number;
28
+ proof: ZeroKnowledgeProofResponse;
29
+ encoded: string;
30
+ metadata: string;
31
+ };
32
+ export type TxPreparationResultSubmitResponse = {
33
+ authProof: {
34
+ raw: AuthProof;
35
+ encoded: string;
36
+ };
37
+ crossChainProof: {
38
+ raw: CrossChainProof;
39
+ encoded: string;
40
+ };
41
+ proofs: ProofPreparationResult[];
42
+ };
43
+ export declare const toTxDataArgs: (res: TxPreparationResultSubmitResponse) => (string | {
44
+ requestId: string | number;
45
+ proof: string;
46
+ metadata: string;
47
+ }[] | {
48
+ authMethod: AuthMethod;
49
+ proof: string;
50
+ })[];
25
51
  /**
26
52
  * OnChainZKPVerifier is a class that allows to interact with the OnChainZKPVerifier contract
27
53
  * and submitZKPResponse.
@@ -60,17 +86,30 @@ export declare class OnChainZKPVerifier implements IOnChainZKPVerifier {
60
86
  /**
61
87
  * {@inheritDoc IOnChainVerifierMultiQuery.submitResponse}
62
88
  */
63
- submitResponse(ethSigner: Signer, txData: ContractInvokeTransactionData, authResponse: AuthProofResponse, responses: ZeroKnowledgeProofResponse[]): Promise<Map<string, ZeroKnowledgeInvokeResponse>>;
64
- static prepareTxArgsSubmit(resolverUrl: string, txData: ContractInvokeTransactionData, authResponse: AuthProofResponse, responses: ZeroKnowledgeProofResponse[]): Promise<JsonDocumentObjectValue[]>;
65
- prepareTxArgsSubmit(txData: ContractInvokeTransactionData, authResponse: AuthProofResponse, responses: ZeroKnowledgeProofResponse[]): Promise<JsonDocumentObjectValue[]>;
89
+ submitResponse(ethSigner: Signer, txData: ContractInvokeTransactionData, responses: ZeroKnowledgeProofResponse[], authProof: AuthProof): Promise<Map<string, ZeroKnowledgeInvokeResponse>>;
90
+ static prepareTxArgsSubmit(resolverUrl: string, txData: ContractInvokeTransactionData, responses: ZeroKnowledgeProofResponse[], authProof: AuthProof): Promise<{
91
+ result: TxPreparationResultSubmitResponse;
92
+ txDataArgs: JsonDocumentObjectValue[];
93
+ }>;
94
+ prepareTxArgsSubmit(txData: ContractInvokeTransactionData, responses: ZeroKnowledgeProofResponse[], authProof: AuthProof): Promise<{
95
+ result: TxPreparationResultSubmitResponse;
96
+ txDataArgs: JsonDocumentObjectValue[];
97
+ }>;
98
+ private static checkSupportedCircuit;
66
99
  private static getCrossChainResolvers;
67
100
  static prepareTxArgsSubmitV2(resolverUrl: string, txData: ContractInvokeTransactionData, zkProofResponses: ZeroKnowledgeProofResponse[]): Promise<JsonDocumentObjectValue[]>;
68
101
  prepareTxArgsSubmitV2(txData: ContractInvokeTransactionData, zkProofResponses: ZeroKnowledgeProofResponse[]): Promise<JsonDocumentObjectValue[]>;
69
- private static _processProof;
102
+ private static getUpdateResolutions;
70
103
  private static packCrossChainProofs;
71
104
  static packGlobalStateMsg(msg: GlobalStateUpdate): string;
72
105
  private static packIdentityStateMsg;
73
- private static packMetadatas;
74
106
  private static getOnChainGistRootStatePubSignals;
75
107
  private static resolveDidDocumentEip712MessageAndSignature;
76
108
  }
109
+ /**
110
+ * Packs an Ethereum identity proof from a Decentralized Identifier (DID).
111
+ * @param did - Decentralized Identifier (DID) to pack.
112
+ * @returns A hexadecimal string representing the packed DID identity proof.
113
+ */
114
+ export declare const packEthIdentityProof: (did: DID) => string;
115
+ export {};
@@ -1,5 +1,6 @@
1
1
  import { Signer } from 'ethers';
2
- import { AuthProofResponse, ContractInvokeTransactionData, JsonDocumentObjectValue, ZeroKnowledgeInvokeResponse, ZeroKnowledgeProofResponse } from '../../iden3comm';
2
+ import { AuthProof, ContractInvokeTransactionData, JsonDocumentObjectValue, ZeroKnowledgeInvokeResponse, ZeroKnowledgeProofResponse } from '../../iden3comm';
3
+ import { TxPreparationResultSubmitResponse } from '../blockchain/onchain-zkp-verifier';
3
4
  /**
4
5
  * Interface that defines methods for ZKP verifier
5
6
  *
@@ -32,9 +33,10 @@ export interface IOnChainZKPVerifier {
32
33
  * @param {txData} ContractInvokeTransactionData - transaction data
33
34
  * @param {AuthProofResponse} authResponse - authResponse
34
35
  * @param {ZeroKnowledgeProofMultiQueryResponse[]} responses - singleResponses and groupedResponses
36
+ * @param {ZeroKnowledgeProofAuthResponse} [authProof] - authProof in case of authV2
35
37
  * @returns {Promise<Map<string, ZeroKnowledgeInvokeResponse>>} - map of transaction hash - ZeroKnowledgeInvokeResponse
36
38
  */
37
- submitResponse(ethSigner: Signer, txData: ContractInvokeTransactionData, authResponse: AuthProofResponse, responses: ZeroKnowledgeProofResponse[]): Promise<Map<string, ZeroKnowledgeInvokeResponse>>;
39
+ submitResponse(ethSigner: Signer, txData: ContractInvokeTransactionData, responses: ZeroKnowledgeProofResponse[], authProof: AuthProof): Promise<Map<string, ZeroKnowledgeInvokeResponse>>;
38
40
  /**
39
41
  * Returns tx args for the ZKP verifier contract submission (singe tx args for each response).
40
42
  * @param txData
@@ -50,8 +52,11 @@ export interface IOnChainZKPVerifier {
50
52
  /**
51
53
  * Returns args for the verifier multi-query contract submission (single tx args for an array of responses).
52
54
  * @param {txData} ContractInvokeTransactionData - transaction data
53
- * @param {AuthProofResponse} authResponse - authResponse
55
+ * @param {authProof} AuthProof - AuthProof
54
56
  * @param {ZeroKnowledgeProofMultiQueryResponse[]} responses - singleResponses and groupedResponses
55
57
  */
56
- prepareTxArgsSubmit(txData: ContractInvokeTransactionData, authResponse: AuthProofResponse, responses: ZeroKnowledgeProofResponse[]): Promise<JsonDocumentObjectValue[]>;
58
+ prepareTxArgsSubmit(txData: ContractInvokeTransactionData, responses: ZeroKnowledgeProofResponse[], authProof: AuthProof): Promise<{
59
+ result: TxPreparationResultSubmitResponse;
60
+ txDataArgs: JsonDocumentObjectValue[];
61
+ }>;
57
62
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xpolygonid/js-sdk",
3
- "version": "1.29.0",
3
+ "version": "1.29.2",
4
4
  "description": "SDK to work with Polygon ID",
5
5
  "main": "dist/node/cjs/index.js",
6
6
  "module": "dist/node/esm/index.js",
@@ -1,74 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.prepareZkpProof = exports.packZkpProof = exports.prepareAuthV2ZeroKnowledgeResponse = exports.calculateRequestIdForCircuit = void 0;
4
- const ethers_1 = require("ethers");
5
- const utils_1 = require("../../utils");
6
- const circuits_1 = require("../../circuits");
7
- const js_crypto_1 = require("@iden3/js-crypto");
8
- /**
9
- * @beta
10
- * Retrieves the request ID from circuit string.
11
- * CircuitId.AuthV2 - 940499666
12
- * @returns The request ID.
13
- */
14
- function calculateRequestIdForCircuit(circuitId) {
15
- const circuitHash = (0, ethers_1.keccak256)(utils_1.byteEncoder.encode(circuitId));
16
- const dataView = new DataView(js_crypto_1.Hex.decodeString(circuitHash.replace('0x', '')).buffer);
17
- const id = dataView.getUint32(0);
18
- return id;
19
- }
20
- exports.calculateRequestIdForCircuit = calculateRequestIdForCircuit;
21
- /**
22
- * Prepares the zero-knowledge proof response for the AuthV2 circuit.
23
- * @beta
24
- * @param address - The address associated with the request.
25
- * @param senderDid - The sender's decentralized identifier (DID).
26
- * @param proofService - The proof service used to generate the proof.
27
- * @returns A promise that resolves to an array of ZeroKnowledgeProofResponse objects.
28
- */
29
- async function prepareAuthV2ZeroKnowledgeResponse(address, senderDid, proofService) {
30
- const circuitId = circuits_1.CircuitId.AuthV2;
31
- // this is now hardcoded calculated value for 'authV2' that can be changed in the future.
32
- const id = 940499666;
33
- if ((0, utils_1.isEthereumIdentity)(senderDid)) {
34
- return [
35
- {
36
- circuitId,
37
- id,
38
- pub_signals: [],
39
- proof: {
40
- pi_a: [],
41
- pi_b: [],
42
- pi_c: [],
43
- protocol: 'groth16'
44
- }
45
- }
46
- ];
47
- }
48
- const hash = Uint8Array.from([...(0, utils_1.hexToBytes)(address), ...new Uint8Array(12)]).reverse();
49
- const { proof, pub_signals } = await proofService.generateAuthV2Proof(hash, senderDid);
50
- return [
51
- {
52
- circuitId,
53
- id,
54
- pub_signals,
55
- proof
56
- }
57
- ];
58
- }
59
- exports.prepareAuthV2ZeroKnowledgeResponse = prepareAuthV2ZeroKnowledgeResponse;
60
- const packZkpProof = (inputs, a, b, c) => {
61
- return new ethers_1.ethers.AbiCoder().encode(['uint256[] inputs', 'uint256[2]', 'uint256[2][2]', 'uint256[2]'], [inputs, a, b, c]);
62
- };
63
- exports.packZkpProof = packZkpProof;
64
- const prepareZkpProof = (proof) => {
65
- return {
66
- a: proof.pi_a.slice(0, 2),
67
- b: [
68
- [proof.pi_b[0][1], proof.pi_b[0][0]],
69
- [proof.pi_b[1][1], proof.pi_b[1][0]]
70
- ],
71
- c: proof.pi_c.slice(0, 2)
72
- };
73
- };
74
- exports.prepareZkpProof = prepareZkpProof;
@@ -1,67 +0,0 @@
1
- import { ethers, keccak256 } from 'ethers';
2
- import { byteEncoder, hexToBytes, isEthereumIdentity } from '../../utils';
3
- import { CircuitId } from '../../circuits';
4
- import { Hex } from '@iden3/js-crypto';
5
- /**
6
- * @beta
7
- * Retrieves the request ID from circuit string.
8
- * CircuitId.AuthV2 - 940499666
9
- * @returns The request ID.
10
- */
11
- export function calculateRequestIdForCircuit(circuitId) {
12
- const circuitHash = keccak256(byteEncoder.encode(circuitId));
13
- const dataView = new DataView(Hex.decodeString(circuitHash.replace('0x', '')).buffer);
14
- const id = dataView.getUint32(0);
15
- return id;
16
- }
17
- /**
18
- * Prepares the zero-knowledge proof response for the AuthV2 circuit.
19
- * @beta
20
- * @param address - The address associated with the request.
21
- * @param senderDid - The sender's decentralized identifier (DID).
22
- * @param proofService - The proof service used to generate the proof.
23
- * @returns A promise that resolves to an array of ZeroKnowledgeProofResponse objects.
24
- */
25
- export async function prepareAuthV2ZeroKnowledgeResponse(address, senderDid, proofService) {
26
- const circuitId = CircuitId.AuthV2;
27
- // this is now hardcoded calculated value for 'authV2' that can be changed in the future.
28
- const id = 940499666;
29
- if (isEthereumIdentity(senderDid)) {
30
- return [
31
- {
32
- circuitId,
33
- id,
34
- pub_signals: [],
35
- proof: {
36
- pi_a: [],
37
- pi_b: [],
38
- pi_c: [],
39
- protocol: 'groth16'
40
- }
41
- }
42
- ];
43
- }
44
- const hash = Uint8Array.from([...hexToBytes(address), ...new Uint8Array(12)]).reverse();
45
- const { proof, pub_signals } = await proofService.generateAuthV2Proof(hash, senderDid);
46
- return [
47
- {
48
- circuitId,
49
- id,
50
- pub_signals,
51
- proof
52
- }
53
- ];
54
- }
55
- export const packZkpProof = (inputs, a, b, c) => {
56
- return new ethers.AbiCoder().encode(['uint256[] inputs', 'uint256[2]', 'uint256[2][2]', 'uint256[2]'], [inputs, a, b, c]);
57
- };
58
- export const prepareZkpProof = (proof) => {
59
- return {
60
- a: proof.pi_a.slice(0, 2),
61
- b: [
62
- [proof.pi_b[0][1], proof.pi_b[0][0]],
63
- [proof.pi_b[1][1], proof.pi_b[1][0]]
64
- ],
65
- c: proof.pi_c.slice(0, 2)
66
- };
67
- };
@@ -1,27 +0,0 @@
1
- import { CircuitId } from '../../circuits';
2
- import { DID } from '@iden3/js-iden3-core';
3
- import { IProofService } from '../../proof';
4
- import { ZeroKnowledgeProofResponse } from '../types';
5
- import { ProofData } from '@iden3/js-jwz';
6
- /**
7
- * @beta
8
- * Retrieves the request ID from circuit string.
9
- * CircuitId.AuthV2 - 940499666
10
- * @returns The request ID.
11
- */
12
- export declare function calculateRequestIdForCircuit(circuitId: CircuitId): number;
13
- /**
14
- * Prepares the zero-knowledge proof response for the AuthV2 circuit.
15
- * @beta
16
- * @param address - The address associated with the request.
17
- * @param senderDid - The sender's decentralized identifier (DID).
18
- * @param proofService - The proof service used to generate the proof.
19
- * @returns A promise that resolves to an array of ZeroKnowledgeProofResponse objects.
20
- */
21
- export declare function prepareAuthV2ZeroKnowledgeResponse(address: string, senderDid: DID, proofService: IProofService): Promise<ZeroKnowledgeProofResponse[]>;
22
- export declare const packZkpProof: (inputs: string[], a: string[], b: string[][], c: string[]) => string;
23
- export declare const prepareZkpProof: (proof: ProofData) => {
24
- a: string[];
25
- b: string[][];
26
- c: string[];
27
- };