@0xpolygonid/js-sdk 1.24.1 → 1.26.0
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 +376 -748
- package/dist/browser/esm/index.js.map +1 -1
- package/dist/browser/umd/index.js +377 -747
- package/dist/browser/umd/index.js.map +1 -1
- package/dist/node/cjs/circuits/auth-v2.js +6 -0
- package/dist/node/cjs/iden3comm/constants.js +6 -1
- package/dist/node/cjs/iden3comm/handlers/auth.js +16 -24
- package/dist/node/cjs/iden3comm/handlers/contract-request.js +7 -1
- package/dist/node/cjs/iden3comm/handlers/discovery-protocol.js +198 -0
- package/dist/node/cjs/iden3comm/handlers/index.js +1 -0
- package/dist/node/cjs/iden3comm/handlers/payment.js +27 -46
- package/dist/node/cjs/iden3comm/packageManager.js +12 -0
- package/dist/node/cjs/iden3comm/packers/jws.js +8 -7
- package/dist/node/cjs/iden3comm/packers/plain.js +8 -2
- package/dist/node/cjs/iden3comm/packers/zkp.js +10 -12
- package/dist/node/cjs/iden3comm/types/index.js +1 -0
- package/dist/node/cjs/iden3comm/types/protocol/discovery-protocol.js +16 -0
- package/dist/node/cjs/iden3comm/utils/contract-request.utils.js +59 -0
- package/dist/node/cjs/iden3comm/utils/index.js +1 -0
- package/dist/node/cjs/proof/proof-service.js +6 -0
- package/dist/node/cjs/storage/blockchain/onchain-zkp-verifier.js +56 -47
- package/dist/node/cjs/utils/did-helper.js +8 -3
- package/dist/node/cjs/verifiable/constants.js +1 -2
- package/dist/node/esm/circuits/auth-v2.js +6 -0
- package/dist/node/esm/iden3comm/constants.js +6 -1
- package/dist/node/esm/iden3comm/handlers/auth.js +17 -25
- package/dist/node/esm/iden3comm/handlers/contract-request.js +7 -1
- package/dist/node/esm/iden3comm/handlers/discovery-protocol.js +169 -0
- package/dist/node/esm/iden3comm/handlers/index.js +1 -0
- package/dist/node/esm/iden3comm/handlers/payment.js +28 -46
- package/dist/node/esm/iden3comm/packageManager.js +12 -0
- package/dist/node/esm/iden3comm/packers/jws.js +9 -8
- package/dist/node/esm/iden3comm/packers/plain.js +9 -3
- package/dist/node/esm/iden3comm/packers/zkp.js +11 -13
- package/dist/node/esm/iden3comm/types/index.js +1 -0
- package/dist/node/esm/iden3comm/types/protocol/discovery-protocol.js +13 -0
- package/dist/node/esm/iden3comm/utils/contract-request.utils.js +54 -0
- package/dist/node/esm/iden3comm/utils/index.js +1 -0
- package/dist/node/esm/proof/proof-service.js +6 -0
- package/dist/node/esm/storage/blockchain/onchain-zkp-verifier.js +58 -49
- package/dist/node/esm/utils/did-helper.js +8 -3
- package/dist/node/esm/verifiable/constants.js +1 -2
- package/dist/types/circuits/auth-v2.d.ts +3 -2
- package/dist/types/iden3comm/constants.d.ts +2 -0
- package/dist/types/iden3comm/handlers/discovery-protocol.d.ts +100 -0
- package/dist/types/iden3comm/handlers/index.d.ts +1 -0
- package/dist/types/iden3comm/handlers/payment.d.ts +5 -9
- package/dist/types/iden3comm/packageManager.d.ts +2 -0
- package/dist/types/iden3comm/packers/jws.d.ts +2 -1
- package/dist/types/iden3comm/packers/plain.d.ts +1 -0
- package/dist/types/iden3comm/packers/zkp.d.ts +3 -2
- package/dist/types/iden3comm/types/index.d.ts +1 -0
- package/dist/types/iden3comm/types/packageManager.d.ts +6 -0
- package/dist/types/iden3comm/types/protocol/discovery-protocol.d.ts +41 -0
- package/dist/types/iden3comm/types/protocol/payment.d.ts +6 -5
- package/dist/types/iden3comm/utils/contract-request.utils.d.ts +20 -0
- package/dist/types/iden3comm/utils/index.d.ts +1 -0
- package/dist/types/proof/proof-service.d.ts +10 -0
- package/dist/types/storage/blockchain/onchain-zkp-verifier.d.ts +2 -0
- package/dist/types/verifiable/constants.d.ts +2 -3
- package/package.json +1 -1
|
@@ -92,5 +92,11 @@ class AuthV2PubSignals {
|
|
|
92
92
|
this.GISTRoot = js_merkletree_1.Hash.fromString(sVals[2]);
|
|
93
93
|
return this;
|
|
94
94
|
}
|
|
95
|
+
getStatesInfo() {
|
|
96
|
+
return {
|
|
97
|
+
states: [],
|
|
98
|
+
gists: [{ id: this.userID, root: this.GISTRoot }]
|
|
99
|
+
};
|
|
100
|
+
}
|
|
95
101
|
}
|
|
96
102
|
exports.AuthV2PubSignals = AuthV2PubSignals;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DEFAULT_AUTH_VERIFY_DELAY = exports.DEFAULT_PROOF_VERIFY_DELAY = exports.defaultAcceptProfile = exports.AcceptJwsAlgorithms = exports.AcceptJwzAlgorithms = exports.AcceptAuthCircuits = exports.ProtocolVersion = exports.SUPPORTED_PUBLIC_KEY_TYPES = exports.MediaType = exports.PROTOCOL_MESSAGE_TYPE = void 0;
|
|
4
4
|
const IDEN3_PROTOCOL = 'https://iden3-communication.io/';
|
|
5
|
+
const DIDCOMM_PROTOCOL = 'https://didcomm.org/';
|
|
5
6
|
/**
|
|
6
7
|
* Constants for Iden3 protocol
|
|
7
8
|
*/
|
|
@@ -45,7 +46,11 @@ exports.PROTOCOL_MESSAGE_TYPE = Object.freeze({
|
|
|
45
46
|
// PaymentRequestMessageType is type for payment-request message
|
|
46
47
|
PAYMENT_REQUEST_MESSAGE_TYPE: `${IDEN3_PROTOCOL}credentials/0.1/payment-request`,
|
|
47
48
|
// PaymentMessageType is type for payment message
|
|
48
|
-
PAYMENT_MESSAGE_TYPE: `${IDEN3_PROTOCOL}credentials/0.1/payment
|
|
49
|
+
PAYMENT_MESSAGE_TYPE: `${IDEN3_PROTOCOL}credentials/0.1/payment`,
|
|
50
|
+
// DiscoveryProtocolQueriesMessageType is type for didcomm discovery protocol queries
|
|
51
|
+
DISCOVERY_PROTOCOL_QUERIES_MESSAGE_TYPE: `${DIDCOMM_PROTOCOL}discover-features/2.0/queries`,
|
|
52
|
+
// DiscoveryProtocolDiscloseMessageType is type for didcomm discovery protocol disclose
|
|
53
|
+
DISCOVERY_PROTOCOL_DISCLOSE_MESSAGE_TYPE: `${DIDCOMM_PROTOCOL}discover-features/2.0/disclose`
|
|
49
54
|
});
|
|
50
55
|
/**
|
|
51
56
|
* Media types for iden3 comm communication protocol
|
|
@@ -287,32 +287,24 @@ class AuthHandler extends message_handler_1.AbstractMessageHandler {
|
|
|
287
287
|
}
|
|
288
288
|
getSupportedMediaTypeByProfile(ctx, responseType, profile) {
|
|
289
289
|
let mediaType;
|
|
290
|
-
if (profile?.length) {
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
(responseTypeVersion < 1 || responseTypeVersion >= 2))) {
|
|
299
|
-
continue;
|
|
300
|
-
}
|
|
301
|
-
// 2. check packer support
|
|
302
|
-
if (this._packerMgr.isProfileSupported(env, acceptProfile)) {
|
|
303
|
-
supportedMediaTypes.push(env);
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
if (!supportedMediaTypes.length) {
|
|
307
|
-
throw new Error('no packer with profile which meets `accept` header requirements');
|
|
308
|
-
}
|
|
309
|
-
mediaType = supportedMediaTypes[0];
|
|
310
|
-
if (ctx.mediaType && supportedMediaTypes.includes(ctx.mediaType)) {
|
|
311
|
-
mediaType = ctx.mediaType;
|
|
290
|
+
if (!profile?.length) {
|
|
291
|
+
return ctx.mediaType || constants_1.MediaType.ZKPMessage;
|
|
292
|
+
}
|
|
293
|
+
const supportedMediaTypes = [];
|
|
294
|
+
for (const acceptProfile of profile) {
|
|
295
|
+
const { env } = (0, utils_2.parseAcceptProfile)(acceptProfile);
|
|
296
|
+
if (this._packerMgr.isProfileSupported(env, acceptProfile)) {
|
|
297
|
+
supportedMediaTypes.push(env);
|
|
312
298
|
}
|
|
313
299
|
}
|
|
314
|
-
|
|
315
|
-
|
|
300
|
+
if (!supportedMediaTypes.length) {
|
|
301
|
+
throw new Error('no packer with profile which meets `accept` header requirements');
|
|
302
|
+
}
|
|
303
|
+
mediaType = supportedMediaTypes.includes(constants_1.MediaType.ZKPMessage)
|
|
304
|
+
? constants_1.MediaType.ZKPMessage
|
|
305
|
+
: supportedMediaTypes[0];
|
|
306
|
+
if (ctx.mediaType && supportedMediaTypes.includes(ctx.mediaType)) {
|
|
307
|
+
mediaType = ctx.mediaType;
|
|
316
308
|
}
|
|
317
309
|
return mediaType;
|
|
318
310
|
}
|
|
@@ -30,6 +30,7 @@ class ContractRequestHandler extends message_handler_1.AbstractMessageHandler {
|
|
|
30
30
|
this._proofService = _proofService;
|
|
31
31
|
this._zkpVerifier = _zkpVerifier;
|
|
32
32
|
this._supportedCircuits = [
|
|
33
|
+
models_1.CircuitId.AuthV2,
|
|
33
34
|
models_1.CircuitId.AtomicQueryMTPV2OnChain,
|
|
34
35
|
models_1.CircuitId.AtomicQuerySigV2OnChain,
|
|
35
36
|
models_1.CircuitId.AtomicQueryV3OnChain
|
|
@@ -60,7 +61,12 @@ class ContractRequestHandler extends message_handler_1.AbstractMessageHandler {
|
|
|
60
61
|
throw new Error(`Invalid chain id ${chain_id}`);
|
|
61
62
|
}
|
|
62
63
|
const verifierDid = message.from ? js_iden3_core_1.DID.parse(message.from) : undefined;
|
|
63
|
-
const
|
|
64
|
+
const { scope = [] } = message.body;
|
|
65
|
+
const zkpResponses = await (0, common_1.processZeroKnowledgeProofRequests)(did, scope, verifierDid, this._proofService, {
|
|
66
|
+
ethSigner,
|
|
67
|
+
challenge,
|
|
68
|
+
supportedCircuits: this._supportedCircuits
|
|
69
|
+
});
|
|
64
70
|
const methodId = message.body.transaction_data.method_id.replace('0x', '');
|
|
65
71
|
switch (methodId) {
|
|
66
72
|
case storage_1.FunctionSignatures.SubmitZKPResponseV2:
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.DiscoveryProtocolHandler = exports.createDiscoveryFeatureDiscloseMessage = exports.createDiscoveryFeatureQueryMessage = void 0;
|
|
27
|
+
const constants_1 = require("../constants");
|
|
28
|
+
const uuid = __importStar(require("uuid"));
|
|
29
|
+
const discovery_protocol_1 = require("../types/protocol/discovery-protocol");
|
|
30
|
+
const message_handler_1 = require("./message-handler");
|
|
31
|
+
const js_iden3_core_1 = require("@iden3/js-iden3-core");
|
|
32
|
+
const common_1 = require("./common");
|
|
33
|
+
/**
|
|
34
|
+
* @beta
|
|
35
|
+
* createDiscoveryFeatureQueryMessage is a function to create didcomm protocol discovery-feature query message
|
|
36
|
+
* @param opts - discovery-feature query options
|
|
37
|
+
* @returns `DiscoverFeatureQueriesMessage`
|
|
38
|
+
*/
|
|
39
|
+
function createDiscoveryFeatureQueryMessage(queries, opts) {
|
|
40
|
+
const uuidv4 = uuid.v4();
|
|
41
|
+
return {
|
|
42
|
+
id: uuidv4,
|
|
43
|
+
thid: uuidv4,
|
|
44
|
+
typ: constants_1.MediaType.PlainMessage,
|
|
45
|
+
type: constants_1.PROTOCOL_MESSAGE_TYPE.DISCOVERY_PROTOCOL_QUERIES_MESSAGE_TYPE,
|
|
46
|
+
body: {
|
|
47
|
+
queries
|
|
48
|
+
},
|
|
49
|
+
from: opts?.from,
|
|
50
|
+
to: opts?.to,
|
|
51
|
+
created_time: (0, js_iden3_core_1.getUnixTimestamp)(new Date()),
|
|
52
|
+
expires_time: opts?.expires_time
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
exports.createDiscoveryFeatureQueryMessage = createDiscoveryFeatureQueryMessage;
|
|
56
|
+
/**
|
|
57
|
+
* @beta
|
|
58
|
+
* createDiscoveryFeatureDiscloseMessage is a function to create didcomm protocol discovery-feature disclose message
|
|
59
|
+
* @param {DiscoverFeatureDisclosure[]} disclosures - array of disclosures
|
|
60
|
+
* @param opts - basic message options
|
|
61
|
+
* @returns `DiscoverFeatureQueriesMessage`
|
|
62
|
+
*/
|
|
63
|
+
function createDiscoveryFeatureDiscloseMessage(disclosures, opts) {
|
|
64
|
+
const uuidv4 = uuid.v4();
|
|
65
|
+
return {
|
|
66
|
+
id: uuidv4,
|
|
67
|
+
typ: constants_1.MediaType.PlainMessage,
|
|
68
|
+
thid: uuidv4,
|
|
69
|
+
type: constants_1.PROTOCOL_MESSAGE_TYPE.DISCOVERY_PROTOCOL_DISCLOSE_MESSAGE_TYPE,
|
|
70
|
+
body: {
|
|
71
|
+
disclosures
|
|
72
|
+
},
|
|
73
|
+
from: opts?.from,
|
|
74
|
+
to: opts?.to,
|
|
75
|
+
created_time: (0, js_iden3_core_1.getUnixTimestamp)(new Date()),
|
|
76
|
+
expires_time: opts?.expires_time
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
exports.createDiscoveryFeatureDiscloseMessage = createDiscoveryFeatureDiscloseMessage;
|
|
80
|
+
/**
|
|
81
|
+
*
|
|
82
|
+
* Handler for discovery protocol
|
|
83
|
+
*
|
|
84
|
+
* @public
|
|
85
|
+
* @beta
|
|
86
|
+
* @class DiscoveryProtocolHandler
|
|
87
|
+
* @implements implements DiscoveryProtocolHandler interface
|
|
88
|
+
*/
|
|
89
|
+
class DiscoveryProtocolHandler extends message_handler_1.AbstractMessageHandler {
|
|
90
|
+
/**
|
|
91
|
+
* Creates an instance of DiscoveryProtocolHandler.
|
|
92
|
+
* @param {DiscoveryProtocolOptions} _options - discovery protocol options
|
|
93
|
+
*/
|
|
94
|
+
constructor(_options) {
|
|
95
|
+
super();
|
|
96
|
+
this._options = _options;
|
|
97
|
+
const headers = [
|
|
98
|
+
'id',
|
|
99
|
+
'typ',
|
|
100
|
+
'type',
|
|
101
|
+
'thid',
|
|
102
|
+
'body',
|
|
103
|
+
'from',
|
|
104
|
+
'to',
|
|
105
|
+
'created_time',
|
|
106
|
+
'expires_time'
|
|
107
|
+
];
|
|
108
|
+
if (!_options.headers) {
|
|
109
|
+
_options.headers = headers;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* @inheritdoc IProtocolMessageHandler#handle
|
|
114
|
+
*/
|
|
115
|
+
async handle(message, context) {
|
|
116
|
+
switch (message.type) {
|
|
117
|
+
case constants_1.PROTOCOL_MESSAGE_TYPE.DISCOVERY_PROTOCOL_QUERIES_MESSAGE_TYPE:
|
|
118
|
+
return await this.handleDiscoveryQuery(message, context);
|
|
119
|
+
default:
|
|
120
|
+
return super.handle(message, context);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* @inheritdoc IDiscoveryProtocolHandler#handleDiscoveryQuery
|
|
125
|
+
*/
|
|
126
|
+
async handleDiscoveryQuery(message, opts) {
|
|
127
|
+
if (!opts?.allowExpiredMessages) {
|
|
128
|
+
(0, common_1.verifyExpiresTime)(message);
|
|
129
|
+
}
|
|
130
|
+
const disclosures = [];
|
|
131
|
+
for (const query of message.body.queries) {
|
|
132
|
+
disclosures.push(...this.handleQuery(query));
|
|
133
|
+
}
|
|
134
|
+
return Promise.resolve(createDiscoveryFeatureDiscloseMessage(disclosures, {
|
|
135
|
+
to: message.from,
|
|
136
|
+
from: message.to,
|
|
137
|
+
expires_time: opts?.disclosureExpiresDate
|
|
138
|
+
? (0, js_iden3_core_1.getUnixTimestamp)(opts.disclosureExpiresDate)
|
|
139
|
+
: undefined
|
|
140
|
+
}));
|
|
141
|
+
}
|
|
142
|
+
handleQuery(query) {
|
|
143
|
+
let result = [];
|
|
144
|
+
switch (query[discovery_protocol_1.DiscoverFeatureQueryType.FeatureType]) {
|
|
145
|
+
case discovery_protocol_1.DiscoveryProtocolFeatureType.Accept:
|
|
146
|
+
result = this.handleAcceptQuery();
|
|
147
|
+
break;
|
|
148
|
+
case discovery_protocol_1.DiscoveryProtocolFeatureType.Protocol:
|
|
149
|
+
result = this.handleProtocolQuery();
|
|
150
|
+
break;
|
|
151
|
+
case discovery_protocol_1.DiscoveryProtocolFeatureType.GoalCode:
|
|
152
|
+
result = this.handleGoalCodeQuery();
|
|
153
|
+
break;
|
|
154
|
+
case discovery_protocol_1.DiscoveryProtocolFeatureType.Header:
|
|
155
|
+
result = this.handleHeaderQuery();
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
return this.handleMatch(result, query.match);
|
|
159
|
+
}
|
|
160
|
+
handleAcceptQuery() {
|
|
161
|
+
const acceptProfiles = this._options.packageManager.getSupportedProfiles();
|
|
162
|
+
return acceptProfiles.map((profile) => ({
|
|
163
|
+
[discovery_protocol_1.DiscoverFeatureQueryType.FeatureType]: discovery_protocol_1.DiscoveryProtocolFeatureType.Accept,
|
|
164
|
+
id: profile
|
|
165
|
+
}));
|
|
166
|
+
}
|
|
167
|
+
handleProtocolQuery() {
|
|
168
|
+
return (this._options.protocols?.map((protocol) => ({
|
|
169
|
+
[discovery_protocol_1.DiscoverFeatureQueryType.FeatureType]: discovery_protocol_1.DiscoveryProtocolFeatureType.Protocol,
|
|
170
|
+
id: protocol
|
|
171
|
+
})) ?? []);
|
|
172
|
+
}
|
|
173
|
+
handleGoalCodeQuery() {
|
|
174
|
+
return (this._options.goalCodes?.map((goalCode) => ({
|
|
175
|
+
[discovery_protocol_1.DiscoverFeatureQueryType.FeatureType]: discovery_protocol_1.DiscoveryProtocolFeatureType.GoalCode,
|
|
176
|
+
id: goalCode
|
|
177
|
+
})) ?? []);
|
|
178
|
+
}
|
|
179
|
+
handleHeaderQuery() {
|
|
180
|
+
return (this._options.headers?.map((header) => ({
|
|
181
|
+
[discovery_protocol_1.DiscoverFeatureQueryType.FeatureType]: discovery_protocol_1.DiscoveryProtocolFeatureType.Header,
|
|
182
|
+
id: header
|
|
183
|
+
})) ?? []);
|
|
184
|
+
}
|
|
185
|
+
handleMatch(disclosures, match) {
|
|
186
|
+
if (!match || match === '*') {
|
|
187
|
+
return disclosures;
|
|
188
|
+
}
|
|
189
|
+
const regExp = this.wildcardToRegExp(match);
|
|
190
|
+
return disclosures.filter((disclosure) => regExp.test(disclosure.id));
|
|
191
|
+
}
|
|
192
|
+
wildcardToRegExp(match) {
|
|
193
|
+
// Escape special regex characters, then replace `*` with `.*`
|
|
194
|
+
const regexPattern = match.replace(/[.+^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '.*');
|
|
195
|
+
return new RegExp(`^${regexPattern}$`);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
exports.DiscoveryProtocolHandler = DiscoveryProtocolHandler;
|
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.PaymentHandler = exports.createPayment = exports.
|
|
26
|
+
exports.PaymentHandler = exports.createPayment = exports.verifyEIP712TypedData = exports.createPaymentRequest = void 0;
|
|
27
27
|
const constants_1 = require("../constants");
|
|
28
28
|
const constants_2 = require("../constants");
|
|
29
29
|
const js_iden3_core_1 = require("@iden3/js-iden3-core");
|
|
@@ -63,11 +63,10 @@ function createPaymentRequest(sender, receiver, agent, payments, opts) {
|
|
|
63
63
|
}
|
|
64
64
|
exports.createPaymentRequest = createPaymentRequest;
|
|
65
65
|
async function verifyEIP712TypedData(data, resolver) {
|
|
66
|
-
const convertedAmount = await convertPaymentAmount(data.amount, data.currency);
|
|
67
66
|
const paymentData = data.type === verifiable_1.PaymentRequestDataType.Iden3PaymentRailsRequestV1
|
|
68
67
|
? {
|
|
69
68
|
recipient: data.recipient,
|
|
70
|
-
amount:
|
|
69
|
+
amount: data.amount,
|
|
71
70
|
expirationDate: (0, js_iden3_core_1.getUnixTimestamp)(new Date(data.expirationDate)),
|
|
72
71
|
nonce: data.nonce,
|
|
73
72
|
metadata: '0x'
|
|
@@ -75,7 +74,7 @@ async function verifyEIP712TypedData(data, resolver) {
|
|
|
75
74
|
: {
|
|
76
75
|
tokenAddress: data.tokenAddress,
|
|
77
76
|
recipient: data.recipient,
|
|
78
|
-
amount:
|
|
77
|
+
amount: data.amount,
|
|
79
78
|
expirationDate: (0, js_iden3_core_1.getUnixTimestamp)(new Date(data.expirationDate)),
|
|
80
79
|
nonce: data.nonce,
|
|
81
80
|
metadata: '0x'
|
|
@@ -100,31 +99,6 @@ async function verifyEIP712TypedData(data, resolver) {
|
|
|
100
99
|
throw new Error(`failed request. no matching verificationMethod`);
|
|
101
100
|
}
|
|
102
101
|
exports.verifyEIP712TypedData = verifyEIP712TypedData;
|
|
103
|
-
async function convertPaymentAmount(amount, currency) {
|
|
104
|
-
let convertedAmount = 0n;
|
|
105
|
-
switch (currency) {
|
|
106
|
-
case verifiable_1.SupportedCurrencies.ETH:
|
|
107
|
-
case verifiable_1.SupportedCurrencies.POL:
|
|
108
|
-
case verifiable_1.SupportedCurrencies.MATIC:
|
|
109
|
-
convertedAmount = (0, ethers_1.parseEther)(amount.toString());
|
|
110
|
-
break;
|
|
111
|
-
case verifiable_1.SupportedCurrencies.ETH_WEI:
|
|
112
|
-
convertedAmount = (0, ethers_1.parseUnits)(amount.toString(), 'wei');
|
|
113
|
-
break;
|
|
114
|
-
case verifiable_1.SupportedCurrencies.ETH_GWEI:
|
|
115
|
-
convertedAmount = (0, ethers_1.parseUnits)(amount.toString(), 'gwei');
|
|
116
|
-
break;
|
|
117
|
-
case verifiable_1.SupportedCurrencies.USDC:
|
|
118
|
-
case verifiable_1.SupportedCurrencies.USDT: {
|
|
119
|
-
convertedAmount = (0, ethers_1.parseUnits)(amount.toString(), 6);
|
|
120
|
-
break;
|
|
121
|
-
}
|
|
122
|
-
default:
|
|
123
|
-
throw new Error(`failed request. unsupported currency ${currency}`);
|
|
124
|
-
}
|
|
125
|
-
return convertedAmount;
|
|
126
|
-
}
|
|
127
|
-
exports.convertPaymentAmount = convertPaymentAmount;
|
|
128
102
|
/**
|
|
129
103
|
* @beta
|
|
130
104
|
* createPayment is a function to create protocol payment message
|
|
@@ -312,35 +286,38 @@ class PaymentHandler extends message_handler_1.AbstractMessageHandler {
|
|
|
312
286
|
for (let i = 0; i < payments.length; i++) {
|
|
313
287
|
const { credentials, description } = payments[i];
|
|
314
288
|
const dataArr = [];
|
|
315
|
-
for (let j = 0; j < payments[i].
|
|
316
|
-
const {
|
|
289
|
+
for (let j = 0; j < payments[i].options.length; j++) {
|
|
290
|
+
const { nonce, amount, chainId, optionId, expirationDate } = payments[i].options[j];
|
|
317
291
|
const multiChainConfig = this._params.multiChainPaymentConfig?.find((c) => c.chainId === chainId);
|
|
318
292
|
if (!multiChainConfig) {
|
|
319
293
|
throw new Error(`failed request. no config for chain ${chainId}`);
|
|
320
294
|
}
|
|
321
|
-
const { recipient,
|
|
322
|
-
const
|
|
323
|
-
if (
|
|
324
|
-
throw new Error(`failed request. no
|
|
295
|
+
const { recipient, paymentRails, options } = multiChainConfig;
|
|
296
|
+
const option = options.find((t) => t.id === optionId);
|
|
297
|
+
if (!option) {
|
|
298
|
+
throw new Error(`failed request. no option for id ${optionId}`);
|
|
299
|
+
}
|
|
300
|
+
if (option.type === verifiable_1.PaymentRequestDataType.Iden3PaymentRailsERC20RequestV1 &&
|
|
301
|
+
!option.contractAddress) {
|
|
302
|
+
throw new Error(`failed request. no token address for option id ${optionId}`);
|
|
325
303
|
}
|
|
326
304
|
const expirationDateRequired = expirationDate ?? new Date(new Date().setHours(new Date().getHours() + 1));
|
|
327
|
-
const typeUrl = `https://schema.iden3.io/core/json/${type}.json`;
|
|
305
|
+
const typeUrl = `https://schema.iden3.io/core/json/${option.type}.json`;
|
|
328
306
|
const typesFetchResult = await fetch(typeUrl);
|
|
329
307
|
const types = await typesFetchResult.json();
|
|
330
308
|
delete types.EIP712Domain;
|
|
331
|
-
const
|
|
332
|
-
const paymentData = type === verifiable_1.PaymentRequestDataType.Iden3PaymentRailsRequestV1
|
|
309
|
+
const paymentData = option.type === verifiable_1.PaymentRequestDataType.Iden3PaymentRailsRequestV1
|
|
333
310
|
? {
|
|
334
311
|
recipient,
|
|
335
|
-
amount:
|
|
312
|
+
amount: amount,
|
|
336
313
|
expirationDate: (0, js_iden3_core_1.getUnixTimestamp)(expirationDateRequired),
|
|
337
314
|
nonce,
|
|
338
315
|
metadata: '0x'
|
|
339
316
|
}
|
|
340
317
|
: {
|
|
341
|
-
tokenAddress,
|
|
318
|
+
tokenAddress: option.contractAddress,
|
|
342
319
|
recipient,
|
|
343
|
-
amount:
|
|
320
|
+
amount: amount,
|
|
344
321
|
expirationDate: (0, js_iden3_core_1.getUnixTimestamp)(expirationDateRequired),
|
|
345
322
|
nonce,
|
|
346
323
|
metadata: '0x'
|
|
@@ -349,7 +326,7 @@ class PaymentHandler extends message_handler_1.AbstractMessageHandler {
|
|
|
349
326
|
name: 'MCPayment',
|
|
350
327
|
version: '1.0.0',
|
|
351
328
|
chainId,
|
|
352
|
-
verifyingContract:
|
|
329
|
+
verifyingContract: paymentRails
|
|
353
330
|
};
|
|
354
331
|
const signature = await signer.signTypedData(domain, types, paymentData);
|
|
355
332
|
const proof = [
|
|
@@ -369,20 +346,24 @@ class PaymentHandler extends message_handler_1.AbstractMessageHandler {
|
|
|
369
346
|
const d = {
|
|
370
347
|
type: verifiable_1.PaymentRequestDataType.Iden3PaymentRailsRequestV1,
|
|
371
348
|
'@context': [
|
|
372
|
-
`https://schema.iden3.io/core/jsonld/payment.jsonld#${type}`,
|
|
349
|
+
`https://schema.iden3.io/core/jsonld/payment.jsonld#${option.type}`,
|
|
373
350
|
'https://w3id.org/security/suites/eip712sig-2021/v1'
|
|
374
351
|
],
|
|
375
352
|
recipient,
|
|
376
353
|
amount: amount.toString(),
|
|
377
|
-
currency,
|
|
378
354
|
expirationDate: expirationDateRequired.toISOString(),
|
|
379
355
|
nonce: nonce.toString(),
|
|
380
356
|
metadata: '0x',
|
|
381
357
|
proof
|
|
382
358
|
};
|
|
383
|
-
dataArr.push(type === verifiable_1.PaymentRequestDataType.Iden3PaymentRailsRequestV1
|
|
359
|
+
dataArr.push(option.type === verifiable_1.PaymentRequestDataType.Iden3PaymentRailsRequestV1
|
|
384
360
|
? d
|
|
385
|
-
: {
|
|
361
|
+
: {
|
|
362
|
+
...d,
|
|
363
|
+
type: option.type,
|
|
364
|
+
tokenAddress: option.contractAddress || '',
|
|
365
|
+
features: option.features || []
|
|
366
|
+
});
|
|
386
367
|
}
|
|
387
368
|
paymentRequestInfo.push({
|
|
388
369
|
data: dataArr,
|
|
@@ -18,6 +18,18 @@ class PackageManager {
|
|
|
18
18
|
constructor() {
|
|
19
19
|
this.packers = new Map();
|
|
20
20
|
}
|
|
21
|
+
/** {@inheritDoc IPackageManager.getSupportedProfiles} */
|
|
22
|
+
getSupportedProfiles() {
|
|
23
|
+
const acceptProfiles = [];
|
|
24
|
+
const mediaTypes = this.getSupportedMediaTypes();
|
|
25
|
+
for (const mediaType of mediaTypes) {
|
|
26
|
+
const p = this.packers.get(mediaType);
|
|
27
|
+
if (p) {
|
|
28
|
+
acceptProfiles.push(...p.getSupportedProfiles());
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return [...new Set(acceptProfiles)];
|
|
32
|
+
}
|
|
21
33
|
/** {@inheritDoc IPackageManager.isProfileSupported} */
|
|
22
34
|
isProfileSupported(mediaType, profile) {
|
|
23
35
|
const p = this.packers.get(mediaType);
|
|
@@ -27,6 +27,8 @@ class JWSPacker {
|
|
|
27
27
|
constructor(_kms, _documentResolver) {
|
|
28
28
|
this._kms = _kms;
|
|
29
29
|
this._documentResolver = _documentResolver;
|
|
30
|
+
this.supportedAlgorithms = [constants_1.AcceptJwsAlgorithms.ES256K, constants_1.AcceptJwsAlgorithms.ES256KR];
|
|
31
|
+
this.supportedProtocolVersions = [constants_1.ProtocolVersion.V1];
|
|
30
32
|
}
|
|
31
33
|
/**
|
|
32
34
|
* Packs the given payload and returns a promise that resolves to the packed data.
|
|
@@ -89,24 +91,23 @@ class JWSPacker {
|
|
|
89
91
|
}
|
|
90
92
|
/** {@inheritDoc IPacker.getSupportedProfiles} */
|
|
91
93
|
getSupportedProfiles() {
|
|
92
|
-
return
|
|
94
|
+
return this.supportedProtocolVersions.map((v) => `${v};env=${this.mediaType()};alg=${this.supportedAlgorithms.join(',')}`);
|
|
93
95
|
}
|
|
94
96
|
/** {@inheritDoc IPacker.isProfileSupported} */
|
|
95
97
|
isProfileSupported(profile) {
|
|
96
|
-
const { env, circuits, alg } = (0, utils_2.parseAcceptProfile)(profile);
|
|
98
|
+
const { protocolVersion, env, circuits, alg } = (0, utils_2.parseAcceptProfile)(profile);
|
|
99
|
+
if (!this.supportedProtocolVersions.includes(protocolVersion)) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
97
102
|
if (env !== this.mediaType()) {
|
|
98
103
|
return false;
|
|
99
104
|
}
|
|
100
105
|
if (circuits) {
|
|
101
106
|
throw new Error(`Circuits are not supported for ${env} media type`);
|
|
102
107
|
}
|
|
103
|
-
const
|
|
104
|
-
const algSupported = !alg?.length || alg.some((a) => supportedAlgArr.includes(a));
|
|
108
|
+
const algSupported = !alg?.length || alg.some((a) => this.supportedAlgorithms.includes(a));
|
|
105
109
|
return algSupported;
|
|
106
110
|
}
|
|
107
|
-
getSupportedAlgorithms() {
|
|
108
|
-
return [constants_1.AcceptJwsAlgorithms.ES256K, constants_1.AcceptJwsAlgorithms.ES256KR];
|
|
109
|
-
}
|
|
110
111
|
async resolveDidDoc(from) {
|
|
111
112
|
let didDocument;
|
|
112
113
|
try {
|
|
@@ -12,6 +12,9 @@ const utils_2 = require("../utils");
|
|
|
12
12
|
* @implements implements IPacker interface
|
|
13
13
|
*/
|
|
14
14
|
class PlainPacker {
|
|
15
|
+
constructor() {
|
|
16
|
+
this.supportedProtocolVersions = [constants_1.ProtocolVersion.V1];
|
|
17
|
+
}
|
|
15
18
|
/**
|
|
16
19
|
* Packs a basic message using the specified parameters.
|
|
17
20
|
*
|
|
@@ -55,11 +58,14 @@ class PlainPacker {
|
|
|
55
58
|
}
|
|
56
59
|
/** {@inheritDoc IPacker.getSupportedProfiles} */
|
|
57
60
|
getSupportedProfiles() {
|
|
58
|
-
return
|
|
61
|
+
return this.supportedProtocolVersions.map((v) => `${v};env=${this.mediaType()}`);
|
|
59
62
|
}
|
|
60
63
|
/** {@inheritDoc IPacker.isProfileSupported} */
|
|
61
64
|
isProfileSupported(profile) {
|
|
62
|
-
const { env, circuits, alg } = (0, utils_2.parseAcceptProfile)(profile);
|
|
65
|
+
const { protocolVersion, env, circuits, alg } = (0, utils_2.parseAcceptProfile)(profile);
|
|
66
|
+
if (!this.supportedProtocolVersions.includes(protocolVersion)) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
63
69
|
if (env !== this.mediaType()) {
|
|
64
70
|
return false;
|
|
65
71
|
}
|
|
@@ -83,6 +83,9 @@ class ZKPPacker {
|
|
|
83
83
|
this.provingParamsMap = provingParamsMap;
|
|
84
84
|
this.verificationParamsMap = verificationParamsMap;
|
|
85
85
|
this._opts = _opts;
|
|
86
|
+
this.supportedProtocolVersions = [constants_1.ProtocolVersion.V1];
|
|
87
|
+
this.supportedAlgorithms = [constants_1.AcceptJwzAlgorithms.Groth16];
|
|
88
|
+
this.supportedCircuitIds = [constants_1.AcceptAuthCircuits.AuthV2];
|
|
86
89
|
}
|
|
87
90
|
/**
|
|
88
91
|
* Packs a basic message using the specified parameters.
|
|
@@ -144,28 +147,23 @@ class ZKPPacker {
|
|
|
144
147
|
}
|
|
145
148
|
/** {@inheritDoc IPacker.getSupportedProfiles} */
|
|
146
149
|
getSupportedProfiles() {
|
|
147
|
-
return
|
|
148
|
-
`env=${this.mediaType()}&alg=${this.getSupportedAlgorithms().join(',')}&circuitIds=${this.getSupportedCircuitIds().join(',')}`
|
|
149
|
-
];
|
|
150
|
+
return this.supportedProtocolVersions.map((v) => `${v};env=${this.mediaType()};alg=${this.supportedAlgorithms.join(',')};circuitIds=${this.supportedCircuitIds.join(',')}`);
|
|
150
151
|
}
|
|
151
152
|
/** {@inheritDoc IPacker.isProfileSupported} */
|
|
152
153
|
isProfileSupported(profile) {
|
|
153
|
-
const { env, circuits, alg } = (0, utils_2.parseAcceptProfile)(profile);
|
|
154
|
+
const { protocolVersion, env, circuits, alg } = (0, utils_2.parseAcceptProfile)(profile);
|
|
155
|
+
if (!this.supportedProtocolVersions.includes(protocolVersion)) {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
154
158
|
if (env !== this.mediaType()) {
|
|
155
159
|
return false;
|
|
156
160
|
}
|
|
157
|
-
const supportedCircuitIds = this.
|
|
161
|
+
const supportedCircuitIds = this.supportedCircuitIds;
|
|
158
162
|
const circuitIdSupported = !circuits?.length || circuits.some((c) => supportedCircuitIds.includes(c));
|
|
159
|
-
const supportedAlgArr = this.
|
|
163
|
+
const supportedAlgArr = this.supportedAlgorithms;
|
|
160
164
|
const algSupported = !alg?.length || alg.some((a) => supportedAlgArr.includes(a));
|
|
161
165
|
return algSupported && circuitIdSupported;
|
|
162
166
|
}
|
|
163
|
-
getSupportedAlgorithms() {
|
|
164
|
-
return [constants_1.AcceptJwzAlgorithms.Groth16];
|
|
165
|
-
}
|
|
166
|
-
getSupportedCircuitIds() {
|
|
167
|
-
return [constants_1.AcceptAuthCircuits.AuthV2];
|
|
168
|
-
}
|
|
169
167
|
}
|
|
170
168
|
exports.ZKPPacker = ZKPPacker;
|
|
171
169
|
const verifySender = async (token, msg) => {
|
|
@@ -23,6 +23,7 @@ __exportStar(require("./protocol/contract-request"), exports);
|
|
|
23
23
|
__exportStar(require("./protocol/proposal-request"), exports);
|
|
24
24
|
__exportStar(require("./protocol/payment"), exports);
|
|
25
25
|
__exportStar(require("./protocol/accept-profile"), exports);
|
|
26
|
+
__exportStar(require("./protocol/discovery-protocol"), exports);
|
|
26
27
|
__exportStar(require("./packer"), exports);
|
|
27
28
|
__exportStar(require("./models"), exports);
|
|
28
29
|
__exportStar(require("./packageManager"), exports);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DiscoveryProtocolFeatureType = exports.DiscoverFeatureQueryType = void 0;
|
|
4
|
+
/** @beta DiscoverFeatureQueryType is enum for query type fields */
|
|
5
|
+
var DiscoverFeatureQueryType;
|
|
6
|
+
(function (DiscoverFeatureQueryType) {
|
|
7
|
+
DiscoverFeatureQueryType["FeatureType"] = "feature-type";
|
|
8
|
+
})(DiscoverFeatureQueryType = exports.DiscoverFeatureQueryType || (exports.DiscoverFeatureQueryType = {}));
|
|
9
|
+
/** @beta DiscoveryProtocolFeatureType is enum for supported feature-types */
|
|
10
|
+
var DiscoveryProtocolFeatureType;
|
|
11
|
+
(function (DiscoveryProtocolFeatureType) {
|
|
12
|
+
DiscoveryProtocolFeatureType["Accept"] = "accept";
|
|
13
|
+
DiscoveryProtocolFeatureType["Protocol"] = "protocol";
|
|
14
|
+
DiscoveryProtocolFeatureType["GoalCode"] = "goal-code";
|
|
15
|
+
DiscoveryProtocolFeatureType["Header"] = "header";
|
|
16
|
+
})(DiscoveryProtocolFeatureType = exports.DiscoveryProtocolFeatureType || (exports.DiscoveryProtocolFeatureType = {}));
|