@0xpolygonid/js-sdk 1.17.8 → 1.18.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 +976 -64
- package/dist/browser/esm/index.js.map +1 -1
- package/dist/browser/umd/index.js +976 -63
- package/dist/browser/umd/index.js.map +1 -1
- package/dist/node/cjs/circuits/atomic-query-mtp-v2-on-chain.js +10 -0
- package/dist/node/cjs/circuits/atomic-query-sig-v2-on-chain.js +10 -0
- package/dist/node/cjs/circuits/atomic-query-v3-on-chain.js +10 -0
- package/dist/node/cjs/iden3comm/constants.js +2 -0
- package/dist/node/cjs/iden3comm/handlers/contract-request.js +73 -10
- package/dist/node/cjs/storage/blockchain/abi/ZkpVerifier.json +530 -9
- package/dist/node/cjs/storage/blockchain/onchain-zkp-verifier.js +293 -42
- package/dist/node/cjs/utils/did-helper.js +37 -1
- package/dist/node/esm/circuits/atomic-query-mtp-v2-on-chain.js +10 -0
- package/dist/node/esm/circuits/atomic-query-sig-v2-on-chain.js +10 -0
- package/dist/node/esm/circuits/atomic-query-v3-on-chain.js +10 -0
- package/dist/node/esm/iden3comm/constants.js +2 -0
- package/dist/node/esm/iden3comm/handlers/contract-request.js +73 -10
- package/dist/node/esm/storage/blockchain/abi/ZkpVerifier.json +530 -9
- package/dist/node/esm/storage/blockchain/onchain-zkp-verifier.js +293 -42
- package/dist/node/esm/utils/did-helper.js +35 -0
- package/dist/types/circuits/atomic-query-mtp-v2-on-chain.d.ts +4 -2
- package/dist/types/circuits/atomic-query-sig-v2-on-chain.d.ts +4 -2
- package/dist/types/circuits/atomic-query-v3-on-chain.d.ts +4 -2
- package/dist/types/circuits/common.d.ts +31 -0
- package/dist/types/iden3comm/constants.d.ts +1 -0
- package/dist/types/iden3comm/handlers/contract-request.d.ts +14 -3
- package/dist/types/iden3comm/types/protocol/auth.d.ts +11 -1
- package/dist/types/iden3comm/types/protocol/contract-request.d.ts +16 -1
- package/dist/types/proof/verifiers/pub-signals-verifier.d.ts +2 -2
- package/dist/types/proof/verifiers/query.d.ts +4 -3
- package/dist/types/storage/blockchain/onchain-zkp-verifier.d.ts +44 -12
- package/dist/types/storage/entities/state.d.ts +44 -0
- package/dist/types/storage/interfaces/onchain-zkp-verifier.d.ts +22 -1
- package/dist/types/utils/did-helper.d.ts +12 -1
- package/dist/types/verifiable/presentation.d.ts +2 -2
- package/package.json +1 -1
|
@@ -181,5 +181,15 @@ class AtomicQueryMTPV2OnChainPubSignals extends common_1.BaseConfig {
|
|
|
181
181
|
fieldIdx++;
|
|
182
182
|
return this;
|
|
183
183
|
}
|
|
184
|
+
/** {@inheritDoc IStateInfoPubSignals.getStatesInfo} */
|
|
185
|
+
getStatesInfo() {
|
|
186
|
+
return {
|
|
187
|
+
states: [
|
|
188
|
+
{ id: this.issuerID, state: this.issuerClaimIdenState },
|
|
189
|
+
{ id: this.issuerID, state: this.issuerClaimNonRevState }
|
|
190
|
+
],
|
|
191
|
+
gists: [{ id: this.userID, root: this.gistRoot }]
|
|
192
|
+
};
|
|
193
|
+
}
|
|
184
194
|
}
|
|
185
195
|
exports.AtomicQueryMTPV2OnChainPubSignals = AtomicQueryMTPV2OnChainPubSignals;
|
|
@@ -231,5 +231,15 @@ class AtomicQuerySigV2OnChainPubSignals extends common_1.BaseConfig {
|
|
|
231
231
|
fieldIdx++;
|
|
232
232
|
return this;
|
|
233
233
|
}
|
|
234
|
+
/** {@inheritDoc IStateInfoPubSignals.getStatesInfo} */
|
|
235
|
+
getStatesInfo() {
|
|
236
|
+
return {
|
|
237
|
+
states: [
|
|
238
|
+
{ id: this.issuerID, state: this.issuerAuthState },
|
|
239
|
+
{ id: this.issuerID, state: this.issuerClaimNonRevState }
|
|
240
|
+
],
|
|
241
|
+
gists: [{ id: this.userID, root: this.gistRoot }]
|
|
242
|
+
};
|
|
243
|
+
}
|
|
234
244
|
}
|
|
235
245
|
exports.AtomicQuerySigV2OnChainPubSignals = AtomicQuerySigV2OnChainPubSignals;
|
|
@@ -307,5 +307,15 @@ class AtomicQueryV3OnChainPubSignals extends common_1.BaseConfig {
|
|
|
307
307
|
this.isBJJAuthEnabled = parseInt(sVals[fieldIdx]);
|
|
308
308
|
return this;
|
|
309
309
|
}
|
|
310
|
+
/** {@inheritDoc IStateInfoPubSignals.getStatesInfo} */
|
|
311
|
+
getStatesInfo() {
|
|
312
|
+
return {
|
|
313
|
+
states: [
|
|
314
|
+
{ id: this.issuerID, state: this.issuerState },
|
|
315
|
+
{ id: this.issuerID, state: this.issuerClaimNonRevState }
|
|
316
|
+
],
|
|
317
|
+
gists: [{ id: this.userID, root: this.gistRoot }]
|
|
318
|
+
};
|
|
319
|
+
}
|
|
310
320
|
}
|
|
311
321
|
exports.AtomicQueryV3OnChainPubSignals = AtomicQueryV3OnChainPubSignals;
|
|
@@ -34,6 +34,8 @@ exports.PROTOCOL_MESSAGE_TYPE = Object.freeze({
|
|
|
34
34
|
REVOCATION_STATUS_RESPONSE_MESSAGE_TYPE: `${IDEN3_PROTOCOL}revocation/1.0/status`,
|
|
35
35
|
// ContractInvokeRequestMessageType is type for request of contract invoke request
|
|
36
36
|
CONTRACT_INVOKE_REQUEST_MESSAGE_TYPE: `${IDEN3_PROTOCOL}proofs/1.0/contract-invoke-request`,
|
|
37
|
+
// ContractInvokeResponseMessageType is type for response of contract invoke request
|
|
38
|
+
CONTRACT_INVOKE_RESPONSE_MESSAGE_TYPE: `${IDEN3_PROTOCOL}proofs/1.0/contract-invoke-response`,
|
|
37
39
|
// CredentialOnchainOfferMessageType is type of message with credential onchain offering
|
|
38
40
|
CREDENTIAL_ONCHAIN_OFFER_MESSAGE_TYPE: `${IDEN3_PROTOCOL}credentials/1.0/onchain-offer`,
|
|
39
41
|
// ProposalRequestMessageType is type for proposal-request message
|
|
@@ -4,6 +4,7 @@ exports.ContractRequestHandler = void 0;
|
|
|
4
4
|
const models_1 = require("../../circuits/models");
|
|
5
5
|
const constants_1 = require("../constants");
|
|
6
6
|
const js_iden3_core_1 = require("@iden3/js-iden3-core");
|
|
7
|
+
const storage_1 = require("../../storage");
|
|
7
8
|
const common_1 = require("./common");
|
|
8
9
|
const message_handler_1 = require("./message-handler");
|
|
9
10
|
/**
|
|
@@ -36,9 +37,11 @@ class ContractRequestHandler extends message_handler_1.AbstractMessageHandler {
|
|
|
36
37
|
}
|
|
37
38
|
async handle(message, ctx) {
|
|
38
39
|
switch (message.type) {
|
|
39
|
-
case constants_1.PROTOCOL_MESSAGE_TYPE.CONTRACT_INVOKE_REQUEST_MESSAGE_TYPE:
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
case constants_1.PROTOCOL_MESSAGE_TYPE.CONTRACT_INVOKE_REQUEST_MESSAGE_TYPE: {
|
|
41
|
+
const ciMessage = message;
|
|
42
|
+
const txHashResponsesMap = await this.handleContractInvoke(ciMessage, ctx);
|
|
43
|
+
return this.createContractInvokeResponse(ciMessage, txHashResponsesMap);
|
|
44
|
+
}
|
|
42
45
|
default:
|
|
43
46
|
return super.handle(message, ctx);
|
|
44
47
|
}
|
|
@@ -58,7 +61,21 @@ class ContractRequestHandler extends message_handler_1.AbstractMessageHandler {
|
|
|
58
61
|
}
|
|
59
62
|
const verifierDid = message.from ? js_iden3_core_1.DID.parse(message.from) : undefined;
|
|
60
63
|
const zkpResponses = await (0, common_1.processZeroKnowledgeProofRequests)(did, message?.body?.scope, verifierDid, this._proofService, { ethSigner, challenge, supportedCircuits: this._supportedCircuits });
|
|
61
|
-
|
|
64
|
+
const methodId = message.body.transaction_data.method_id.replace('0x', '');
|
|
65
|
+
switch (methodId) {
|
|
66
|
+
case storage_1.FunctionSignatures.SubmitZKPResponseV2:
|
|
67
|
+
return this._zkpVerifier.submitZKPResponseV2(ethSigner, message.body.transaction_data, zkpResponses);
|
|
68
|
+
case storage_1.FunctionSignatures.SubmitZKPResponseV1: {
|
|
69
|
+
const txHashZkpResponseMap = await this._zkpVerifier.submitZKPResponse(ethSigner, message.body.transaction_data, zkpResponses);
|
|
70
|
+
const response = new Map();
|
|
71
|
+
for (const [txHash, zkpResponse] of txHashZkpResponseMap) {
|
|
72
|
+
response.set(txHash, [zkpResponse]);
|
|
73
|
+
}
|
|
74
|
+
return response;
|
|
75
|
+
}
|
|
76
|
+
default:
|
|
77
|
+
throw new Error(`Not supported method id. Only '${storage_1.FunctionSignatures.SubmitZKPResponseV1} and ${storage_1.FunctionSignatures.SubmitZKPResponseV2} are supported.'`);
|
|
78
|
+
}
|
|
62
79
|
}
|
|
63
80
|
/**
|
|
64
81
|
* unpacks contract-invoke request
|
|
@@ -76,8 +93,41 @@ class ContractRequestHandler extends message_handler_1.AbstractMessageHandler {
|
|
|
76
93
|
return ciRequest;
|
|
77
94
|
}
|
|
78
95
|
/**
|
|
79
|
-
*
|
|
96
|
+
* creates contract invoke response
|
|
97
|
+
* @private
|
|
98
|
+
* @beta
|
|
99
|
+
* @param {ContractInvokeRequest} request - ContractInvokeRequest
|
|
100
|
+
* @param { Map<string, ZeroKnowledgeProofResponse[]>} responses - map tx hash to array of ZeroKnowledgeProofResponses
|
|
101
|
+
* @returns `Promise<ContractInvokeResponse>`
|
|
102
|
+
*/
|
|
103
|
+
async createContractInvokeResponse(request, txHashToZkpResponseMap) {
|
|
104
|
+
const contractInvokeResponse = {
|
|
105
|
+
id: request.id,
|
|
106
|
+
thid: request.thid,
|
|
107
|
+
type: constants_1.PROTOCOL_MESSAGE_TYPE.CONTRACT_INVOKE_RESPONSE_MESSAGE_TYPE,
|
|
108
|
+
from: request.to,
|
|
109
|
+
to: request.from,
|
|
110
|
+
body: {
|
|
111
|
+
transaction_data: request.body.transaction_data,
|
|
112
|
+
reason: request.body.reason,
|
|
113
|
+
scope: []
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
for (const [txHash, zkpResponses] of txHashToZkpResponseMap) {
|
|
117
|
+
for (const zkpResponse of zkpResponses) {
|
|
118
|
+
contractInvokeResponse.body.scope.push({
|
|
119
|
+
txHash,
|
|
120
|
+
...zkpResponse
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return contractInvokeResponse;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* handle contract invoke request
|
|
128
|
+
* supports only 0xb68967e2 method id
|
|
80
129
|
* @beta
|
|
130
|
+
* @deprecated
|
|
81
131
|
* @param {did} did - sender DID
|
|
82
132
|
* @param {ContractInvokeRequest} request - contract invoke request
|
|
83
133
|
* @param {ContractInvokeHandlerOptions} opts - handler options
|
|
@@ -85,11 +135,24 @@ class ContractRequestHandler extends message_handler_1.AbstractMessageHandler {
|
|
|
85
135
|
*/
|
|
86
136
|
async handleContractInvokeRequest(did, request, opts) {
|
|
87
137
|
const ciRequest = await this.parseContractInvokeRequest(request);
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
138
|
+
if (ciRequest.body.transaction_data.method_id !== storage_1.FunctionSignatures.SubmitZKPResponseV1) {
|
|
139
|
+
throw new Error(`please use handle method to work with other method ids`);
|
|
140
|
+
}
|
|
141
|
+
if (ciRequest.type !== constants_1.PROTOCOL_MESSAGE_TYPE.CONTRACT_INVOKE_REQUEST_MESSAGE_TYPE) {
|
|
142
|
+
throw new Error('Invalid message type for contract invoke request');
|
|
143
|
+
}
|
|
144
|
+
const { ethSigner, challenge } = opts;
|
|
145
|
+
if (!ethSigner) {
|
|
146
|
+
throw new Error("Can't sign transaction. Provide Signer in options.");
|
|
147
|
+
}
|
|
148
|
+
const { chain_id } = ciRequest.body.transaction_data;
|
|
149
|
+
const networkFlag = Object.keys(js_iden3_core_1.ChainIds).find((key) => js_iden3_core_1.ChainIds[key] === chain_id);
|
|
150
|
+
if (!networkFlag) {
|
|
151
|
+
throw new Error(`Invalid chain id ${chain_id}`);
|
|
152
|
+
}
|
|
153
|
+
const verifierDid = ciRequest.from ? js_iden3_core_1.DID.parse(ciRequest.from) : undefined;
|
|
154
|
+
const zkpResponses = await (0, common_1.processZeroKnowledgeProofRequests)(did, ciRequest?.body?.scope, verifierDid, this._proofService, { ethSigner, challenge, supportedCircuits: this._supportedCircuits });
|
|
155
|
+
return this._zkpVerifier.submitZKPResponse(ethSigner, ciRequest.body.transaction_data, zkpResponses);
|
|
93
156
|
}
|
|
94
157
|
}
|
|
95
158
|
exports.ContractRequestHandler = ContractRequestHandler;
|