@0xpolygonid/js-sdk 1.33.1 → 1.34.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 +1322 -781
- package/dist/browser/esm/index.js.map +1 -1
- package/dist/browser/umd/index.global.js +182 -59
- package/dist/browser/umd/index.global.js.map +1 -1
- package/dist/node/cjs/index.cjs +2059 -1495
- package/dist/node/cjs/index.cjs.map +1 -1
- package/dist/node/esm/index.js +1322 -781
- package/dist/node/esm/index.js.map +1 -1
- package/dist/types/circuits/auth-v3.d.ts +20 -0
- package/dist/types/circuits/auth-v3.d.ts.map +1 -0
- package/dist/types/circuits/index.d.ts +1 -0
- package/dist/types/circuits/index.d.ts.map +1 -1
- package/dist/types/circuits/models.d.ts +2 -0
- package/dist/types/circuits/models.d.ts.map +1 -1
- package/dist/types/iden3comm/constants.d.ts +2 -1
- package/dist/types/iden3comm/constants.d.ts.map +1 -1
- package/dist/types/iden3comm/handlers/auth.d.ts +4 -1
- package/dist/types/iden3comm/handlers/auth.d.ts.map +1 -1
- package/dist/types/iden3comm/handlers/contract-request.d.ts +1 -1
- package/dist/types/iden3comm/handlers/contract-request.d.ts.map +1 -1
- package/dist/types/iden3comm/handlers/credential-proposal.d.ts +2 -2
- package/dist/types/iden3comm/handlers/credential-proposal.d.ts.map +1 -1
- package/dist/types/iden3comm/handlers/fetch.d.ts +2 -2
- package/dist/types/iden3comm/handlers/fetch.d.ts.map +1 -1
- package/dist/types/iden3comm/handlers/message-handler.d.ts +12 -0
- package/dist/types/iden3comm/handlers/message-handler.d.ts.map +1 -1
- package/dist/types/iden3comm/handlers/payment.d.ts +18 -6
- package/dist/types/iden3comm/handlers/payment.d.ts.map +1 -1
- package/dist/types/iden3comm/handlers/refresh.d.ts +4 -1
- package/dist/types/iden3comm/handlers/refresh.d.ts.map +1 -1
- package/dist/types/iden3comm/handlers/revocation-status.d.ts +4 -4
- package/dist/types/iden3comm/handlers/revocation-status.d.ts.map +1 -1
- package/dist/types/iden3comm/packers/zkp.d.ts.map +1 -1
- package/dist/types/iden3comm/types/protocol/payment.d.ts +58 -9
- package/dist/types/iden3comm/types/protocol/payment.d.ts.map +1 -1
- package/dist/types/iden3comm/utils/accept-profile.d.ts +3 -0
- package/dist/types/iden3comm/utils/accept-profile.d.ts.map +1 -1
- package/dist/types/proof/proof-service.d.ts +13 -0
- package/dist/types/proof/proof-service.d.ts.map +1 -1
- package/dist/types/proof/provers/inputs-generator.d.ts.map +1 -1
- package/dist/types/utils/index.d.ts +2 -0
- package/dist/types/utils/index.d.ts.map +1 -1
- package/dist/types/utils/payments/evm.d.ts +19 -0
- package/dist/types/utils/payments/evm.d.ts.map +1 -0
- package/dist/types/utils/payments/solana.d.ts +88 -0
- package/dist/types/utils/payments/solana.d.ts.map +1 -0
- package/dist/types/verifiable/constants.d.ts +16 -3
- package/dist/types/verifiable/constants.d.ts.map +1 -1
- package/package.json +7 -3
- package/src/circuits/auth-v3.ts +19 -0
- package/src/circuits/index.ts +1 -0
- package/src/circuits/models.ts +5 -1
- package/src/iden3comm/constants.ts +2 -1
- package/src/iden3comm/handlers/auth.ts +54 -11
- package/src/iden3comm/handlers/contract-request.ts +1 -1
- package/src/iden3comm/handlers/credential-proposal.ts +12 -6
- package/src/iden3comm/handlers/fetch.ts +29 -6
- package/src/iden3comm/handlers/message-handler.ts +28 -2
- package/src/iden3comm/handlers/payment.ts +190 -144
- package/src/iden3comm/handlers/refresh.ts +9 -13
- package/src/iden3comm/handlers/revocation-status.ts +9 -7
- package/src/iden3comm/packers/zkp.ts +18 -8
- package/src/iden3comm/types/protocol/payment.ts +79 -10
- package/src/iden3comm/utils/accept-profile.ts +24 -0
- package/src/proof/proof-service.ts +93 -25
- package/src/proof/provers/inputs-generator.ts +2 -0
- package/src/proof/provers/prover.ts +1 -1
- package/src/utils/index.ts +2 -0
- package/src/utils/payments/evm.ts +152 -0
- package/src/utils/payments/solana.ts +360 -0
- package/src/verifiable/constants.ts +17 -3
|
@@ -1,22 +1,32 @@
|
|
|
1
1
|
import { PROTOCOL_MESSAGE_TYPE } from '../constants';
|
|
2
2
|
import { MediaType } from '../constants';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
BasicMessage,
|
|
5
|
+
IPackageManager,
|
|
6
|
+
JWSPackerParams,
|
|
7
|
+
PackerParams,
|
|
8
|
+
ZKPPackerParams
|
|
9
|
+
} from '../types';
|
|
4
10
|
|
|
5
11
|
import { DID, getUnixTimestamp } from '@iden3/js-iden3-core';
|
|
6
12
|
import * as uuid from 'uuid';
|
|
7
|
-
import {
|
|
8
|
-
import { byteEncoder } from '../../utils';
|
|
13
|
+
import { buildSolanaPayment, byteEncoder, verifyIden3SolanaPaymentRequest } from '../../utils';
|
|
9
14
|
import {
|
|
10
15
|
AbstractMessageHandler,
|
|
11
16
|
BasicHandlerOptions,
|
|
12
|
-
IProtocolMessageHandler
|
|
17
|
+
IProtocolMessageHandler,
|
|
18
|
+
defaultProvingMethodAlg,
|
|
19
|
+
getProvingMethodAlgFromJWZ
|
|
13
20
|
} from './message-handler';
|
|
14
21
|
import {
|
|
15
|
-
EthereumEip712Signature2021,
|
|
16
22
|
Iden3PaymentCryptoV1,
|
|
17
23
|
Iden3PaymentRailsERC20RequestV1,
|
|
18
24
|
Iden3PaymentRailsERC20V1,
|
|
19
25
|
Iden3PaymentRailsRequestV1,
|
|
26
|
+
Iden3PaymentRailsSolanaRequestV1,
|
|
27
|
+
Iden3PaymentRailsSolanaSPLRequestV1,
|
|
28
|
+
Iden3PaymentRailsSolanaSPLV1,
|
|
29
|
+
Iden3PaymentRailsSolanaV1,
|
|
20
30
|
Iden3PaymentRailsV1,
|
|
21
31
|
Iden3PaymentRequestCryptoV1,
|
|
22
32
|
MultiChainPaymentConfig,
|
|
@@ -26,15 +36,12 @@ import {
|
|
|
26
36
|
PaymentRequestTypeUnion,
|
|
27
37
|
PaymentTypeUnion
|
|
28
38
|
} from '../types/protocol/payment';
|
|
29
|
-
import {
|
|
30
|
-
|
|
31
|
-
PaymentRequestDataType,
|
|
32
|
-
PaymentType,
|
|
33
|
-
SupportedPaymentProofType
|
|
34
|
-
} from '../../verifiable';
|
|
35
|
-
import { Signer, ethers } from 'ethers';
|
|
39
|
+
import { PaymentFeatures, PaymentRequestDataType, PaymentType } from '../../verifiable';
|
|
40
|
+
import { Signer } from 'ethers';
|
|
36
41
|
import { Resolvable } from 'did-resolver';
|
|
37
42
|
import { verifyExpiresTime } from './common';
|
|
43
|
+
import { Keypair } from '@solana/web3.js';
|
|
44
|
+
import { buildEvmPayment, verifyEIP712TypedData } from '../../utils/payments/evm';
|
|
38
45
|
|
|
39
46
|
/** @beta PaymentRequestCreationOptions represents payment-request creation options */
|
|
40
47
|
export type PaymentRequestCreationOptions = {
|
|
@@ -46,6 +53,12 @@ export type PaymentCreationOptions = {
|
|
|
46
53
|
expires_time?: Date;
|
|
47
54
|
};
|
|
48
55
|
|
|
56
|
+
/** @beta CreatePaymentRailsV1Options holds options for PaymentRailsV1 creation */
|
|
57
|
+
export type CreatePaymentRailsV1Options = {
|
|
58
|
+
ethSigner?: Signer;
|
|
59
|
+
solSigner?: Keypair;
|
|
60
|
+
};
|
|
61
|
+
|
|
49
62
|
/**
|
|
50
63
|
* @beta
|
|
51
64
|
* createPaymentRequest is a function to create protocol payment-request message
|
|
@@ -80,55 +93,6 @@ export function createPaymentRequest(
|
|
|
80
93
|
return request;
|
|
81
94
|
}
|
|
82
95
|
|
|
83
|
-
export async function verifyEIP712TypedData(
|
|
84
|
-
data: Iden3PaymentRailsRequestV1 | Iden3PaymentRailsERC20RequestV1,
|
|
85
|
-
resolver: Resolvable
|
|
86
|
-
): Promise<string> {
|
|
87
|
-
const paymentData =
|
|
88
|
-
data.type === PaymentRequestDataType.Iden3PaymentRailsRequestV1
|
|
89
|
-
? {
|
|
90
|
-
recipient: data.recipient,
|
|
91
|
-
amount: data.amount,
|
|
92
|
-
expirationDate: getUnixTimestamp(new Date(data.expirationDate)),
|
|
93
|
-
nonce: data.nonce,
|
|
94
|
-
metadata: '0x'
|
|
95
|
-
}
|
|
96
|
-
: {
|
|
97
|
-
tokenAddress: data.tokenAddress,
|
|
98
|
-
recipient: data.recipient,
|
|
99
|
-
amount: data.amount,
|
|
100
|
-
expirationDate: getUnixTimestamp(new Date(data.expirationDate)),
|
|
101
|
-
nonce: data.nonce,
|
|
102
|
-
metadata: '0x'
|
|
103
|
-
};
|
|
104
|
-
const proof = Array.isArray(data.proof) ? data.proof[0] : data.proof;
|
|
105
|
-
const typesFetchResult = await fetch(proof.eip712.types);
|
|
106
|
-
const types = await typesFetchResult.json();
|
|
107
|
-
delete types.EIP712Domain;
|
|
108
|
-
const recovered = ethers.verifyTypedData(
|
|
109
|
-
proof.eip712.domain,
|
|
110
|
-
types,
|
|
111
|
-
paymentData,
|
|
112
|
-
proof.proofValue
|
|
113
|
-
);
|
|
114
|
-
|
|
115
|
-
const { didDocument } = await resolver.resolve(proof.verificationMethod);
|
|
116
|
-
if (didDocument?.verificationMethod) {
|
|
117
|
-
for (const verificationMethod of didDocument.verificationMethod) {
|
|
118
|
-
if (
|
|
119
|
-
verificationMethod.blockchainAccountId?.split(':').slice(-1)[0].toLowerCase() ===
|
|
120
|
-
recovered.toLowerCase()
|
|
121
|
-
) {
|
|
122
|
-
return recovered;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
} else {
|
|
126
|
-
throw new Error('failed request. issuer DIDDocument does not contain any verificationMethods');
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
throw new Error(`failed request. no matching verificationMethod`);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
96
|
/**
|
|
133
97
|
* @beta
|
|
134
98
|
* PaymentRailsInfo represents payment info for payment rails
|
|
@@ -227,16 +191,18 @@ export interface IPaymentHandler {
|
|
|
227
191
|
* @param {DID} sender - sender did
|
|
228
192
|
* @param {DID} receiver - receiver did
|
|
229
193
|
* @param {string} agent - agent URL
|
|
230
|
-
* @param {Signer} signer -
|
|
194
|
+
* @param {Signer} signer - ETH signer
|
|
231
195
|
* @param payments - payment options
|
|
196
|
+
* @param {CreatePaymentRailsV1Options} createOptions - options for payment rails creation
|
|
232
197
|
* @returns {Promise<PaymentRequestMessage>}
|
|
233
198
|
*/
|
|
234
199
|
createPaymentRailsV1(
|
|
235
200
|
sender: DID,
|
|
236
201
|
receiver: DID,
|
|
237
202
|
agent: string,
|
|
238
|
-
signer: Signer,
|
|
239
|
-
payments: PaymentRailsInfo[]
|
|
203
|
+
signer: Signer, // the same as createOptions.ethSigner (for compatibility)
|
|
204
|
+
payments: PaymentRailsInfo[],
|
|
205
|
+
createOptions?: CreatePaymentRailsV1Options
|
|
240
206
|
): Promise<PaymentRequestMessage>;
|
|
241
207
|
}
|
|
242
208
|
|
|
@@ -248,6 +214,8 @@ export type PaymentRequestMessageHandlerOptions = BasicHandlerOptions & {
|
|
|
248
214
|
*/
|
|
249
215
|
nonce: string;
|
|
250
216
|
erc20TokenApproveHandler?: (data: Iden3PaymentRailsERC20RequestV1) => Promise<string>;
|
|
217
|
+
packerOptions?: JWSPackerParams | ZKPPackerParams;
|
|
218
|
+
mediaType?: MediaType;
|
|
251
219
|
};
|
|
252
220
|
|
|
253
221
|
/** @beta PaymentHandlerOptions represents payment handler options */
|
|
@@ -380,15 +348,36 @@ export class PaymentHandler
|
|
|
380
348
|
)
|
|
381
349
|
);
|
|
382
350
|
break;
|
|
351
|
+
case PaymentRequestDataType.Iden3PaymentRailsSolanaRequestV1:
|
|
352
|
+
payments.push(
|
|
353
|
+
await this.handleIden3PaymentRailsSolanaRequestV1(selectedPayment, ctx.paymentHandler)
|
|
354
|
+
);
|
|
355
|
+
break;
|
|
356
|
+
case PaymentRequestDataType.Iden3PaymentRailsSolanaSPLRequestV1:
|
|
357
|
+
payments.push(
|
|
358
|
+
await this.handleIden3PaymentRailsSolanaSPLRequestV1(
|
|
359
|
+
{
|
|
360
|
+
...selectedPayment,
|
|
361
|
+
type: PaymentRequestDataType.Iden3PaymentRailsSolanaSPLRequestV1
|
|
362
|
+
},
|
|
363
|
+
ctx.paymentHandler
|
|
364
|
+
)
|
|
365
|
+
);
|
|
366
|
+
break;
|
|
383
367
|
}
|
|
384
368
|
}
|
|
385
369
|
|
|
386
370
|
const paymentMessage = createPayment(senderDID, receiverDID, payments);
|
|
387
|
-
const
|
|
371
|
+
const mediaType = ctx?.mediaType || this._params.packerParams.mediaType || MediaType.ZKPMessage;
|
|
372
|
+
const packerParams = ctx?.packerOptions || this._params.packerParams;
|
|
373
|
+
if (mediaType === MediaType.ZKPMessage && !packerParams?.provingMethodAlg) {
|
|
374
|
+
packerParams.provingMethodAlg = ctx.messageProvingMethodAlg;
|
|
375
|
+
}
|
|
376
|
+
const response = await this.packMessage(paymentMessage, senderDID, mediaType, packerParams);
|
|
388
377
|
|
|
389
378
|
const agentResult = await fetch(paymentRequest.body.agent, {
|
|
390
379
|
method: 'POST',
|
|
391
|
-
body: response,
|
|
380
|
+
body: response.buffer as ArrayBuffer,
|
|
392
381
|
headers: {
|
|
393
382
|
'Content-Type':
|
|
394
383
|
this._params.packerParams.mediaType === MediaType.PlainMessage
|
|
@@ -430,13 +419,33 @@ export class PaymentHandler
|
|
|
430
419
|
if (!opts?.allowExpiredMessages) {
|
|
431
420
|
verifyExpiresTime(paymentRequest);
|
|
432
421
|
}
|
|
422
|
+
if (!opts?.mediaType) {
|
|
423
|
+
opts.mediaType = this._params.packerParams.mediaType || MediaType.ZKPMessage;
|
|
424
|
+
}
|
|
425
|
+
if (!opts.packerOptions) {
|
|
426
|
+
opts.packerOptions = this._params.packerParams.packerOptions;
|
|
427
|
+
}
|
|
428
|
+
if (!opts?.packerOptions && opts.mediaType === MediaType.SignedMessage) {
|
|
429
|
+
throw new Error(`jws packer options are required for ${MediaType.SignedMessage}`);
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
const senderDID = DID.parse(paymentRequest.to);
|
|
433
|
+
if (opts.mediaType === MediaType.ZKPMessage && !opts.packerOptions?.provingMethodAlg) {
|
|
434
|
+
opts.packerOptions = {
|
|
435
|
+
provingMethodAlg: await getProvingMethodAlgFromJWZ(request),
|
|
436
|
+
senderDID
|
|
437
|
+
};
|
|
438
|
+
}
|
|
433
439
|
const agentMessage = await this.handlePaymentRequestMessage(paymentRequest, opts);
|
|
434
440
|
if (!agentMessage) {
|
|
435
441
|
return null;
|
|
436
442
|
}
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
443
|
+
return this.packMessage(
|
|
444
|
+
agentMessage,
|
|
445
|
+
senderDID,
|
|
446
|
+
opts.mediaType || MediaType.ZKPMessage,
|
|
447
|
+
opts.packerOptions
|
|
448
|
+
);
|
|
440
449
|
}
|
|
441
450
|
|
|
442
451
|
/**
|
|
@@ -490,12 +499,18 @@ export class PaymentHandler
|
|
|
490
499
|
receiver: DID,
|
|
491
500
|
agent: string,
|
|
492
501
|
signer: Signer,
|
|
493
|
-
payments: PaymentRailsInfo[]
|
|
502
|
+
payments: PaymentRailsInfo[],
|
|
503
|
+
createOptions?: CreatePaymentRailsV1Options
|
|
494
504
|
): Promise<PaymentRequestMessage> {
|
|
495
505
|
const paymentRequestInfo: PaymentRequestInfo[] = [];
|
|
496
506
|
for (let i = 0; i < payments.length; i++) {
|
|
497
507
|
const { credentials, description } = payments[i];
|
|
498
|
-
const dataArr: (
|
|
508
|
+
const dataArr: (
|
|
509
|
+
| Iden3PaymentRailsRequestV1
|
|
510
|
+
| Iden3PaymentRailsERC20RequestV1
|
|
511
|
+
| Iden3PaymentRailsSolanaRequestV1
|
|
512
|
+
| Iden3PaymentRailsSolanaSPLRequestV1
|
|
513
|
+
)[] = [];
|
|
499
514
|
for (let j = 0; j < payments[i].options.length; j++) {
|
|
500
515
|
const { nonce, amount, chainId, optionId, expirationDate } = payments[i].options[j];
|
|
501
516
|
|
|
@@ -512,82 +527,51 @@ export class PaymentHandler
|
|
|
512
527
|
throw new Error(`failed request. no option for id ${optionId}`);
|
|
513
528
|
}
|
|
514
529
|
if (
|
|
515
|
-
option.type === PaymentRequestDataType.Iden3PaymentRailsERC20RequestV1
|
|
530
|
+
(option.type === PaymentRequestDataType.Iden3PaymentRailsERC20RequestV1 ||
|
|
531
|
+
option.type === PaymentRequestDataType.Iden3PaymentRailsSolanaSPLRequestV1) &&
|
|
516
532
|
!option.contractAddress
|
|
517
533
|
) {
|
|
518
534
|
throw new Error(`failed request. no token address for option id ${optionId}`);
|
|
519
535
|
}
|
|
520
536
|
const expirationDateRequired =
|
|
521
537
|
expirationDate ?? new Date(new Date().setHours(new Date().getHours() + 1));
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
amount: amount,
|
|
532
|
-
expirationDate: getUnixTimestamp(expirationDateRequired),
|
|
533
|
-
nonce,
|
|
534
|
-
metadata: '0x'
|
|
535
|
-
}
|
|
536
|
-
: {
|
|
537
|
-
tokenAddress: option.contractAddress,
|
|
538
|
-
recipient,
|
|
539
|
-
amount: amount,
|
|
540
|
-
expirationDate: getUnixTimestamp(expirationDateRequired),
|
|
541
|
-
nonce,
|
|
542
|
-
metadata: '0x'
|
|
543
|
-
};
|
|
544
|
-
|
|
545
|
-
const domain = {
|
|
546
|
-
name: 'MCPayment',
|
|
547
|
-
version: '1.0.0',
|
|
548
|
-
chainId,
|
|
549
|
-
verifyingContract: paymentRails
|
|
550
|
-
};
|
|
551
|
-
const signature = await signer.signTypedData(domain, types, paymentData);
|
|
552
|
-
const proof: EthereumEip712Signature2021[] = [
|
|
553
|
-
{
|
|
554
|
-
type: SupportedPaymentProofType.EthereumEip712Signature2021,
|
|
555
|
-
proofPurpose: 'assertionMethod',
|
|
556
|
-
proofValue: signature,
|
|
557
|
-
verificationMethod: `did:pkh:eip155:${chainId}:${await signer.getAddress()}`,
|
|
558
|
-
created: new Date().toISOString(),
|
|
559
|
-
eip712: {
|
|
560
|
-
types: typeUrl,
|
|
561
|
-
primaryType: 'Iden3PaymentRailsRequestV1',
|
|
562
|
-
domain
|
|
563
|
-
}
|
|
538
|
+
|
|
539
|
+
if (
|
|
540
|
+
option.type === PaymentRequestDataType.Iden3PaymentRailsSolanaRequestV1 ||
|
|
541
|
+
option.type === PaymentRequestDataType.Iden3PaymentRailsSolanaSPLRequestV1
|
|
542
|
+
) {
|
|
543
|
+
if (!createOptions?.solSigner) {
|
|
544
|
+
throw new Error(
|
|
545
|
+
`please provide solana signer in context for ${option.type} payment type`
|
|
546
|
+
);
|
|
564
547
|
}
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
548
|
+
|
|
549
|
+
const payment = await buildSolanaPayment(
|
|
550
|
+
createOptions.solSigner,
|
|
551
|
+
option,
|
|
552
|
+
chainId,
|
|
553
|
+
paymentRails,
|
|
554
|
+
recipient,
|
|
555
|
+
BigInt(amount),
|
|
556
|
+
expirationDateRequired,
|
|
557
|
+
nonce
|
|
558
|
+
);
|
|
559
|
+
dataArr.push(payment);
|
|
560
|
+
} else {
|
|
561
|
+
const payment = await buildEvmPayment(
|
|
562
|
+
signer,
|
|
563
|
+
option,
|
|
564
|
+
chainId,
|
|
565
|
+
paymentRails,
|
|
566
|
+
recipient,
|
|
567
|
+
BigInt(amount),
|
|
568
|
+
expirationDateRequired,
|
|
569
|
+
nonce
|
|
570
|
+
);
|
|
571
|
+
dataArr.push(payment);
|
|
572
|
+
}
|
|
590
573
|
}
|
|
574
|
+
|
|
591
575
|
paymentRequestInfo.push({
|
|
592
576
|
data: dataArr,
|
|
593
577
|
credentials,
|
|
@@ -597,15 +581,20 @@ export class PaymentHandler
|
|
|
597
581
|
return createPaymentRequest(sender, receiver, agent, paymentRequestInfo);
|
|
598
582
|
}
|
|
599
583
|
|
|
600
|
-
private async packMessage(
|
|
584
|
+
private async packMessage(
|
|
585
|
+
message: BasicMessage,
|
|
586
|
+
senderDID: DID,
|
|
587
|
+
mediaType: MediaType,
|
|
588
|
+
packerParams?: PackerParams
|
|
589
|
+
): Promise<Uint8Array> {
|
|
601
590
|
const responseEncoded = byteEncoder.encode(JSON.stringify(message));
|
|
602
591
|
const packerOpts =
|
|
603
|
-
|
|
604
|
-
?
|
|
592
|
+
mediaType === MediaType.SignedMessage
|
|
593
|
+
? packerParams
|
|
605
594
|
: {
|
|
606
|
-
provingMethodAlg:
|
|
595
|
+
provingMethodAlg: packerParams?.provingMethodAlg || defaultProvingMethodAlg
|
|
607
596
|
};
|
|
608
|
-
return await this._packerMgr.pack(
|
|
597
|
+
return await this._packerMgr.pack(mediaType, responseEncoded, {
|
|
609
598
|
senderDID,
|
|
610
599
|
...packerOpts
|
|
611
600
|
});
|
|
@@ -654,6 +643,63 @@ export class PaymentHandler
|
|
|
654
643
|
};
|
|
655
644
|
}
|
|
656
645
|
|
|
646
|
+
private async handleIden3PaymentRailsSolanaRequestV1(
|
|
647
|
+
data: Iden3PaymentRailsSolanaRequestV1,
|
|
648
|
+
paymentHandler: (data: Iden3PaymentRailsSolanaRequestV1) => Promise<string>
|
|
649
|
+
): Promise<Iden3PaymentRailsSolanaV1> {
|
|
650
|
+
if (data.expirationDate && new Date(data.expirationDate) < new Date()) {
|
|
651
|
+
throw new Error(`failed request. expired request`);
|
|
652
|
+
}
|
|
653
|
+
const isValid = await verifyIden3SolanaPaymentRequest(data, this._params.documentResolver);
|
|
654
|
+
if (!isValid) {
|
|
655
|
+
throw new Error(`failed request. invalid Solana payment request signature`);
|
|
656
|
+
}
|
|
657
|
+
const proof = Array.isArray(data.proof) ? data.proof[0] : data.proof;
|
|
658
|
+
const signer = proof.verificationMethod.split(':').slice(-1)[0];
|
|
659
|
+
if (this._params.allowedSigners && !this._params.allowedSigners.includes(signer)) {
|
|
660
|
+
throw new Error(`failed request. signer is not in the allowed signers list`);
|
|
661
|
+
}
|
|
662
|
+
const txId = await paymentHandler(data);
|
|
663
|
+
return {
|
|
664
|
+
nonce: data.nonce,
|
|
665
|
+
type: PaymentType.Iden3PaymentRailsSolanaV1,
|
|
666
|
+
'@context': 'https://schema.iden3.io/core/jsonld/payment.jsonld#Iden3PaymentRailsSolanaV1',
|
|
667
|
+
paymentData: {
|
|
668
|
+
txId,
|
|
669
|
+
chainId: proof.domain.chainId
|
|
670
|
+
}
|
|
671
|
+
};
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
private async handleIden3PaymentRailsSolanaSPLRequestV1(
|
|
675
|
+
data: Iden3PaymentRailsSolanaSPLRequestV1,
|
|
676
|
+
paymentHandler: (data: Iden3PaymentRailsSolanaSPLRequestV1) => Promise<string>
|
|
677
|
+
): Promise<Iden3PaymentRailsSolanaSPLV1> {
|
|
678
|
+
if (data.expirationDate && new Date(data.expirationDate) < new Date()) {
|
|
679
|
+
throw new Error(`failed request. expired request`);
|
|
680
|
+
}
|
|
681
|
+
const isValid = await verifyIden3SolanaPaymentRequest(data, this._params.documentResolver);
|
|
682
|
+
if (!isValid) {
|
|
683
|
+
throw new Error(`failed request. invalid Solana payment request signature`);
|
|
684
|
+
}
|
|
685
|
+
const proof = Array.isArray(data.proof) ? data.proof[0] : data.proof;
|
|
686
|
+
const signer = proof.verificationMethod.split(':').slice(-1)[0];
|
|
687
|
+
if (this._params.allowedSigners && !this._params.allowedSigners.includes(signer)) {
|
|
688
|
+
throw new Error(`failed request. signer is not in the allowed signers list`);
|
|
689
|
+
}
|
|
690
|
+
const txId = await paymentHandler(data);
|
|
691
|
+
return {
|
|
692
|
+
nonce: data.nonce,
|
|
693
|
+
type: PaymentType.Iden3PaymentRailsSolanaSPLV1,
|
|
694
|
+
'@context': 'https://schema.iden3.io/core/jsonld/payment.jsonld#Iden3PaymentRailsSolanaSPLV1',
|
|
695
|
+
paymentData: {
|
|
696
|
+
txId,
|
|
697
|
+
chainId: proof.domain.chainId,
|
|
698
|
+
tokenAddress: data.tokenAddress
|
|
699
|
+
}
|
|
700
|
+
};
|
|
701
|
+
}
|
|
702
|
+
|
|
657
703
|
private async handleIden3PaymentRailsERC20RequestV1(
|
|
658
704
|
data: Iden3PaymentRailsERC20RequestV1,
|
|
659
705
|
paymentHandler: (data: Iden3PaymentRailsERC20RequestV1) => Promise<string>,
|
|
@@ -5,16 +5,16 @@ import {
|
|
|
5
5
|
CredentialIssuanceMessage,
|
|
6
6
|
CredentialRefreshMessage,
|
|
7
7
|
IPackageManager,
|
|
8
|
+
JWSPackerParams,
|
|
8
9
|
ZKPPackerParams
|
|
9
10
|
} from '../types';
|
|
10
11
|
|
|
11
12
|
import { RefreshServiceType, W3CCredential } from '../../verifiable';
|
|
12
13
|
import { byteEncoder } from '../../utils';
|
|
13
|
-
import { proving, ProvingMethodAlg } from '@iden3/js-jwz';
|
|
14
14
|
import { DID } from '@iden3/js-iden3-core';
|
|
15
15
|
import { ICredentialWallet } from '../../credentials';
|
|
16
|
-
import { CircuitId } from '../../circuits';
|
|
17
16
|
import * as uuid from 'uuid';
|
|
17
|
+
import { defaultProvingMethodAlg } from './message-handler';
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* RefreshHandlerOptions contains options for RefreshHandler
|
|
@@ -35,6 +35,8 @@ export interface RefreshHandlerOptions {
|
|
|
35
35
|
*/
|
|
36
36
|
export interface RefreshOptions {
|
|
37
37
|
reason?: string;
|
|
38
|
+
packerOptions?: JWSPackerParams | ZKPPackerParams;
|
|
39
|
+
mediaType?: MediaType;
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
/**
|
|
@@ -88,12 +90,10 @@ export class RefreshHandler implements IRefreshHandler {
|
|
|
88
90
|
|
|
89
91
|
const senderDID = DID.parse(otherIdentifier);
|
|
90
92
|
|
|
91
|
-
const
|
|
93
|
+
const mediaType = opts?.mediaType || MediaType.ZKPMessage;
|
|
94
|
+
const packerOptions = opts?.packerOptions ?? {
|
|
92
95
|
senderDID,
|
|
93
|
-
provingMethodAlg:
|
|
94
|
-
proving.provingMethodGroth16AuthV2Instance.methodAlg.alg,
|
|
95
|
-
CircuitId.AuthV2
|
|
96
|
-
)
|
|
96
|
+
provingMethodAlg: defaultProvingMethodAlg
|
|
97
97
|
};
|
|
98
98
|
|
|
99
99
|
const refreshMsg: CredentialRefreshMessage = {
|
|
@@ -110,17 +110,13 @@ export class RefreshHandler implements IRefreshHandler {
|
|
|
110
110
|
};
|
|
111
111
|
|
|
112
112
|
const msgBytes = byteEncoder.encode(JSON.stringify(refreshMsg));
|
|
113
|
-
const
|
|
114
|
-
MediaType.ZKPMessage,
|
|
115
|
-
msgBytes,
|
|
116
|
-
zkpParams
|
|
117
|
-
);
|
|
113
|
+
const token = await this._options.packageManager.pack(mediaType, msgBytes, packerOptions);
|
|
118
114
|
const resp = await fetch(credential.refreshService.id, {
|
|
119
115
|
method: 'post',
|
|
120
116
|
headers: {
|
|
121
117
|
'Content-Type': 'application/json'
|
|
122
118
|
},
|
|
123
|
-
body:
|
|
119
|
+
body: token.buffer as ArrayBuffer
|
|
124
120
|
});
|
|
125
121
|
|
|
126
122
|
if (resp.status !== 200) {
|
|
@@ -5,7 +5,8 @@ import {
|
|
|
5
5
|
IPackageManager,
|
|
6
6
|
JWSPackerParams,
|
|
7
7
|
RevocationStatusRequestMessage,
|
|
8
|
-
RevocationStatusResponseMessage
|
|
8
|
+
RevocationStatusResponseMessage,
|
|
9
|
+
ZKPPackerParams
|
|
9
10
|
} from '../types';
|
|
10
11
|
|
|
11
12
|
import { DID } from '@iden3/js-iden3-core';
|
|
@@ -13,12 +14,12 @@ import * as uuid from 'uuid';
|
|
|
13
14
|
import { RevocationStatus } from '../../verifiable';
|
|
14
15
|
import { TreeState } from '../../circuits';
|
|
15
16
|
import { byteEncoder } from '../../utils';
|
|
16
|
-
import { proving } from '@iden3/js-jwz';
|
|
17
17
|
import { IIdentityWallet } from '../../identity';
|
|
18
18
|
import {
|
|
19
19
|
AbstractMessageHandler,
|
|
20
20
|
BasicHandlerOptions,
|
|
21
|
-
IProtocolMessageHandler
|
|
21
|
+
IProtocolMessageHandler,
|
|
22
|
+
getProvingMethodAlgFromJWZ
|
|
22
23
|
} from './message-handler';
|
|
23
24
|
import { verifyExpiresTime } from './common';
|
|
24
25
|
|
|
@@ -29,10 +30,10 @@ import { verifyExpiresTime } from './common';
|
|
|
29
30
|
* @property packerOptions - Optional parameters for the JWS packer.
|
|
30
31
|
* @property treeState - Optional tree state to be used.
|
|
31
32
|
*/
|
|
32
|
-
export type RevocationStatusMessageHandlerOptions = {
|
|
33
|
+
export type RevocationStatusMessageHandlerOptions = BasicHandlerOptions & {
|
|
33
34
|
senderDid: DID;
|
|
34
35
|
mediaType: MediaType;
|
|
35
|
-
packerOptions?: JWSPackerParams;
|
|
36
|
+
packerOptions?: JWSPackerParams | ZKPPackerParams;
|
|
36
37
|
treeState?: TreeState;
|
|
37
38
|
};
|
|
38
39
|
|
|
@@ -66,7 +67,7 @@ export interface IRevocationStatusHandler {
|
|
|
66
67
|
/** RevocationStatusHandlerOptions represents revocation status handler options */
|
|
67
68
|
export type RevocationStatusHandlerOptions = BasicHandlerOptions & {
|
|
68
69
|
mediaType: MediaType;
|
|
69
|
-
packerOptions?: JWSPackerParams;
|
|
70
|
+
packerOptions?: JWSPackerParams | ZKPPackerParams;
|
|
70
71
|
treeState?: TreeState;
|
|
71
72
|
};
|
|
72
73
|
|
|
@@ -212,7 +213,8 @@ export class RevocationStatusHandler
|
|
|
212
213
|
opts.mediaType === MediaType.SignedMessage
|
|
213
214
|
? opts.packerOptions
|
|
214
215
|
: {
|
|
215
|
-
provingMethodAlg:
|
|
216
|
+
provingMethodAlg:
|
|
217
|
+
opts.packerOptions?.provingMethodAlg || (await getProvingMethodAlgFromJWZ(request))
|
|
216
218
|
};
|
|
217
219
|
|
|
218
220
|
if (!rsRequest.to) {
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
ZKPPackerParams
|
|
10
10
|
} from '../types';
|
|
11
11
|
import { Token, Header, ProvingMethodAlg, proving } from '@iden3/js-jwz';
|
|
12
|
-
import { AuthV2PubSignals, CircuitId } from '../../circuits/index';
|
|
12
|
+
import { AuthV2PubSignals, AuthV3PubSignals, CircuitId } from '../../circuits/index';
|
|
13
13
|
import { BytesHelper, DID } from '@iden3/js-iden3-core';
|
|
14
14
|
import { bytesToProtocolMessage } from '../utils/envelope';
|
|
15
15
|
import {
|
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
ErrStateVerificationFailed,
|
|
21
21
|
ErrUnknownCircuitID
|
|
22
22
|
} from '../errors';
|
|
23
|
-
import {
|
|
23
|
+
import { AcceptJwzAlgorithms, MediaType, ProtocolVersion } from '../constants';
|
|
24
24
|
import { byteDecoder, byteEncoder } from '../../utils';
|
|
25
25
|
import { DEFAULT_AUTH_VERIFY_DELAY } from '../constants';
|
|
26
26
|
import { parseAcceptProfile } from '../utils';
|
|
@@ -88,8 +88,7 @@ export class VerificationHandlerFunc {
|
|
|
88
88
|
export class ZKPPacker implements IPacker {
|
|
89
89
|
private readonly supportedProtocolVersions = [ProtocolVersion.V1];
|
|
90
90
|
private readonly supportedAlgorithms = [AcceptJwzAlgorithms.Groth16];
|
|
91
|
-
private readonly supportedCircuitIds
|
|
92
|
-
|
|
91
|
+
private readonly supportedCircuitIds: string[];
|
|
93
92
|
/**
|
|
94
93
|
* Creates an instance of ZKPPacker.
|
|
95
94
|
* @param {Map<string, ProvingParams>} provingParamsMap - string is derived by JSON.parse(ProvingMethodAlg)
|
|
@@ -101,7 +100,16 @@ export class ZKPPacker implements IPacker {
|
|
|
101
100
|
private readonly _opts: StateVerificationOpts = {
|
|
102
101
|
acceptedStateTransitionDelay: DEFAULT_AUTH_VERIFY_DELAY
|
|
103
102
|
}
|
|
104
|
-
) {
|
|
103
|
+
) {
|
|
104
|
+
const supportedProvers = Array.from(this.provingParamsMap.keys()).map(
|
|
105
|
+
(alg) => alg.split(':')[1]
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
const supportedVerifiers = Array.from(this.verificationParamsMap.keys()).map(
|
|
109
|
+
(alg) => alg.split(':')[1]
|
|
110
|
+
);
|
|
111
|
+
this.supportedCircuitIds = [...new Set([...supportedProvers, ...supportedVerifiers])];
|
|
112
|
+
}
|
|
105
113
|
|
|
106
114
|
/**
|
|
107
115
|
* Packs a basic message using the specified parameters.
|
|
@@ -216,13 +224,15 @@ export class ZKPPacker implements IPacker {
|
|
|
216
224
|
const verifySender = async (token: Token, msg: BasicMessage): Promise<void> => {
|
|
217
225
|
switch (token.circuitId) {
|
|
218
226
|
case CircuitId.AuthV2:
|
|
227
|
+
case CircuitId.AuthV3_8_32:
|
|
228
|
+
case CircuitId.AuthV3:
|
|
219
229
|
{
|
|
220
230
|
if (!msg.from) {
|
|
221
231
|
throw new Error(ErrSenderNotUsedTokenCreation);
|
|
222
232
|
}
|
|
223
|
-
const authSignals =
|
|
224
|
-
|
|
225
|
-
);
|
|
233
|
+
const authSignals = (
|
|
234
|
+
token.circuitId === CircuitId.AuthV2 ? new AuthV2PubSignals() : new AuthV3PubSignals()
|
|
235
|
+
).pubSignalsUnmarshal(byteEncoder.encode(JSON.stringify(token.zkProof.pub_signals)));
|
|
226
236
|
const did = DID.parseFromId(authSignals.userID);
|
|
227
237
|
|
|
228
238
|
const msgHash = await token.getMessageHash();
|