@0xpolygonid/js-sdk 1.12.0 → 1.14.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 +281 -18
- package/dist/browser/esm/index.js.map +1 -1
- package/dist/browser/umd/index.js +283 -17
- package/dist/browser/umd/index.js.map +1 -1
- package/dist/node/cjs/iden3comm/constants.js +5 -1
- package/dist/node/cjs/iden3comm/handlers/fetch.js +26 -12
- package/dist/node/cjs/iden3comm/handlers/index.js +1 -0
- package/dist/node/cjs/iden3comm/handlers/payment.js +232 -0
- package/dist/node/cjs/iden3comm/types/index.js +1 -0
- package/dist/node/cjs/iden3comm/types/protocol/payment.js +2 -0
- package/dist/node/cjs/proof/common.js +17 -4
- package/dist/node/cjs/verifiable/constants.js +37 -1
- package/dist/node/esm/iden3comm/constants.js +5 -1
- package/dist/node/esm/iden3comm/handlers/fetch.js +26 -12
- package/dist/node/esm/iden3comm/handlers/index.js +1 -0
- package/dist/node/esm/iden3comm/handlers/payment.js +203 -0
- package/dist/node/esm/iden3comm/types/index.js +1 -0
- package/dist/node/esm/iden3comm/types/protocol/payment.js +1 -0
- package/dist/node/esm/proof/common.js +17 -4
- package/dist/node/esm/verifiable/constants.js +36 -0
- package/dist/types/iden3comm/constants.d.ts +2 -0
- package/dist/types/iden3comm/handlers/index.d.ts +1 -0
- package/dist/types/iden3comm/handlers/message-handler.d.ts +2 -1
- package/dist/types/iden3comm/handlers/payment.d.ts +100 -0
- package/dist/types/iden3comm/types/index.d.ts +1 -0
- package/dist/types/iden3comm/types/protocol/credentials.d.ts +3 -3
- package/dist/types/iden3comm/types/protocol/payment.d.ts +48 -0
- package/dist/types/verifiable/constants.d.ts +32 -0
- package/package.json +1 -1
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { PROTOCOL_MESSAGE_TYPE } from '../constants';
|
|
2
|
+
import { MediaType } from '../constants';
|
|
3
|
+
import { DID } from '@iden3/js-iden3-core';
|
|
4
|
+
import * as uuid from 'uuid';
|
|
5
|
+
import { proving } from '@iden3/js-jwz';
|
|
6
|
+
import { byteEncoder } from '../../utils';
|
|
7
|
+
import { AbstractMessageHandler } from './message-handler';
|
|
8
|
+
import { PaymentRequestDataType, PaymentRequestType, PaymentType } from '../../verifiable';
|
|
9
|
+
/**
|
|
10
|
+
* @beta
|
|
11
|
+
* createPaymentRequest is a function to create protocol payment-request message
|
|
12
|
+
* @param {DID} sender - sender did
|
|
13
|
+
* @param {DID} receiver - receiver did
|
|
14
|
+
* @param {string} agent - agent URL
|
|
15
|
+
* @param {PaymentRequestInfo[]} payments - payments
|
|
16
|
+
* @returns `PaymentRequestMessage`
|
|
17
|
+
*/
|
|
18
|
+
export function createPaymentRequest(sender, receiver, agent, payments) {
|
|
19
|
+
const uuidv4 = uuid.v4();
|
|
20
|
+
const request = {
|
|
21
|
+
id: uuidv4,
|
|
22
|
+
thid: uuidv4,
|
|
23
|
+
from: sender.string(),
|
|
24
|
+
to: receiver.string(),
|
|
25
|
+
typ: MediaType.PlainMessage,
|
|
26
|
+
type: PROTOCOL_MESSAGE_TYPE.PAYMENT_REQUEST_MESSAGE_TYPE,
|
|
27
|
+
body: {
|
|
28
|
+
agent,
|
|
29
|
+
payments
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
return request;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* @beta
|
|
36
|
+
* createPayment is a function to create protocol payment message
|
|
37
|
+
* @param {DID} sender - sender did
|
|
38
|
+
* @param {DID} receiver - receiver did
|
|
39
|
+
* @param {PaymentInfo[]} payments - payments
|
|
40
|
+
* @returns `PaymentMessage`
|
|
41
|
+
*/
|
|
42
|
+
export function createPayment(sender, receiver, payments) {
|
|
43
|
+
const uuidv4 = uuid.v4();
|
|
44
|
+
const request = {
|
|
45
|
+
id: uuidv4,
|
|
46
|
+
thid: uuidv4,
|
|
47
|
+
from: sender.string(),
|
|
48
|
+
to: receiver.string(),
|
|
49
|
+
typ: MediaType.PlainMessage,
|
|
50
|
+
type: PROTOCOL_MESSAGE_TYPE.PAYMENT_MESSAGE_TYPE,
|
|
51
|
+
body: {
|
|
52
|
+
payments
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
return request;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
*
|
|
59
|
+
* Allows to process PaymentRequest protocol message
|
|
60
|
+
* @beta
|
|
61
|
+
* @class PaymentHandler
|
|
62
|
+
* @implements implements IPaymentHandler interface
|
|
63
|
+
*/
|
|
64
|
+
export class PaymentHandler extends AbstractMessageHandler {
|
|
65
|
+
/**
|
|
66
|
+
* @beta Creates an instance of PaymentHandler.
|
|
67
|
+
* @param {IPackageManager} _packerMgr - package manager to unpack message envelope
|
|
68
|
+
* @param {PaymentHandlerParams} _params - payment handler params
|
|
69
|
+
*
|
|
70
|
+
*/
|
|
71
|
+
constructor(_packerMgr, _params) {
|
|
72
|
+
super();
|
|
73
|
+
this._packerMgr = _packerMgr;
|
|
74
|
+
this._params = _params;
|
|
75
|
+
}
|
|
76
|
+
async handle(message, context) {
|
|
77
|
+
switch (message.type) {
|
|
78
|
+
case PROTOCOL_MESSAGE_TYPE.PAYMENT_REQUEST_MESSAGE_TYPE:
|
|
79
|
+
return await this.handlePaymentRequestMessage(message, context);
|
|
80
|
+
case PROTOCOL_MESSAGE_TYPE.PAYMENT_MESSAGE_TYPE:
|
|
81
|
+
await this.handlePayment(message, context);
|
|
82
|
+
return null;
|
|
83
|
+
default:
|
|
84
|
+
return super.handle(message, context);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* @inheritdoc IPaymentHandler#parsePaymentRequest
|
|
89
|
+
*/
|
|
90
|
+
async parsePaymentRequest(request) {
|
|
91
|
+
const { unpackedMessage: message } = await this._packerMgr.unpack(request);
|
|
92
|
+
const paymentRequest = message;
|
|
93
|
+
if (message.type !== PROTOCOL_MESSAGE_TYPE.PAYMENT_REQUEST_MESSAGE_TYPE) {
|
|
94
|
+
throw new Error('Invalid media type');
|
|
95
|
+
}
|
|
96
|
+
return paymentRequest;
|
|
97
|
+
}
|
|
98
|
+
async handlePaymentRequestMessage(paymentRequest, ctx) {
|
|
99
|
+
if (!paymentRequest.to) {
|
|
100
|
+
throw new Error(`failed request. empty 'to' field`);
|
|
101
|
+
}
|
|
102
|
+
if (!paymentRequest.from) {
|
|
103
|
+
throw new Error(`failed request. empty 'from' field`);
|
|
104
|
+
}
|
|
105
|
+
if (!paymentRequest.body?.payments?.length) {
|
|
106
|
+
throw new Error(`failed request. no 'payments' in body`);
|
|
107
|
+
}
|
|
108
|
+
if (!ctx.paymentHandler) {
|
|
109
|
+
throw new Error(`please provide payment handler in context`);
|
|
110
|
+
}
|
|
111
|
+
const senderDID = DID.parse(paymentRequest.to);
|
|
112
|
+
const receiverDID = DID.parse(paymentRequest.from);
|
|
113
|
+
const payments = [];
|
|
114
|
+
for (let i = 0; i < paymentRequest.body.payments.length; i++) {
|
|
115
|
+
const paymentReq = paymentRequest.body.payments[i];
|
|
116
|
+
if (paymentReq.type !== PaymentRequestType.PaymentRequest) {
|
|
117
|
+
throw new Error(`failed request. not supported '${paymentReq.type}' payment type `);
|
|
118
|
+
}
|
|
119
|
+
if (paymentReq.data.type !== PaymentRequestDataType.Iden3PaymentRequestCryptoV1) {
|
|
120
|
+
throw new Error(`failed request. not supported '${paymentReq.data.type}' payment type `);
|
|
121
|
+
}
|
|
122
|
+
const txId = await ctx.paymentHandler(paymentReq.data);
|
|
123
|
+
payments.push({
|
|
124
|
+
id: paymentReq.data.id,
|
|
125
|
+
type: PaymentType.Iden3PaymentCryptoV1,
|
|
126
|
+
paymentData: {
|
|
127
|
+
txId
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
const paymentMessage = createPayment(senderDID, receiverDID, payments);
|
|
132
|
+
const response = await this.packMessage(paymentMessage, senderDID);
|
|
133
|
+
const agentResult = await fetch(paymentRequest.body.agent, {
|
|
134
|
+
method: 'POST',
|
|
135
|
+
body: response,
|
|
136
|
+
headers: {
|
|
137
|
+
'Content-Type': 'application/octet-stream'
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
const arrayBuffer = await agentResult.arrayBuffer();
|
|
141
|
+
if (!arrayBuffer.byteLength) {
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
const { unpackedMessage } = await this._packerMgr.unpack(new Uint8Array(arrayBuffer));
|
|
145
|
+
return unpackedMessage;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* @inheritdoc IPaymentHandler#handlePaymentRequest
|
|
149
|
+
*/
|
|
150
|
+
async handlePaymentRequest(request, opts) {
|
|
151
|
+
if (this._params.packerParams.mediaType === MediaType.SignedMessage &&
|
|
152
|
+
!this._params.packerParams.packerOptions) {
|
|
153
|
+
throw new Error(`jws packer options are required for ${MediaType.SignedMessage}`);
|
|
154
|
+
}
|
|
155
|
+
const paymentRequest = await this.parsePaymentRequest(request);
|
|
156
|
+
if (!paymentRequest.from) {
|
|
157
|
+
throw new Error(`failed request. empty 'from' field`);
|
|
158
|
+
}
|
|
159
|
+
if (!paymentRequest.to) {
|
|
160
|
+
throw new Error(`failed request. empty 'to' field`);
|
|
161
|
+
}
|
|
162
|
+
const agentMessage = await this.handlePaymentRequestMessage(paymentRequest, opts);
|
|
163
|
+
if (!agentMessage) {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
const senderDID = DID.parse(paymentRequest.to);
|
|
167
|
+
return this.packMessage(agentMessage, senderDID);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* @inheritdoc IPaymentHandler#handlePayment
|
|
171
|
+
*/
|
|
172
|
+
async handlePayment(payment, opts) {
|
|
173
|
+
if (opts.paymentRequest.from !== payment.to) {
|
|
174
|
+
throw new Error(`sender of the request is not a target of response - expected ${opts.paymentRequest.from}, given ${payment.to}`);
|
|
175
|
+
}
|
|
176
|
+
if (!payment.body?.payments.length) {
|
|
177
|
+
throw new Error(`failed request. empty 'payments' field in body`);
|
|
178
|
+
}
|
|
179
|
+
for (let i = 0; i < payment.body.payments.length; i++) {
|
|
180
|
+
const p = payment.body?.payments[i];
|
|
181
|
+
const paymentRequestData = opts.paymentRequest.body?.payments.find((r) => r.data.id === p.id);
|
|
182
|
+
if (!paymentRequestData) {
|
|
183
|
+
throw new Error(`can't find payment request for payment id ${p.id}`);
|
|
184
|
+
}
|
|
185
|
+
if (!opts.paymentValidationHandler) {
|
|
186
|
+
throw new Error(`please provide payment validation handler in options`);
|
|
187
|
+
}
|
|
188
|
+
await opts.paymentValidationHandler(p.paymentData.txId, paymentRequestData.data);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
async packMessage(message, senderDID) {
|
|
192
|
+
const responseEncoded = byteEncoder.encode(JSON.stringify(message));
|
|
193
|
+
const packerOpts = this._params.packerParams.mediaType === MediaType.SignedMessage
|
|
194
|
+
? this._params.packerParams.packerOptions
|
|
195
|
+
: {
|
|
196
|
+
provingMethodAlg: proving.provingMethodGroth16AuthV2Instance.methodAlg
|
|
197
|
+
};
|
|
198
|
+
return await this._packerMgr.pack(this._params.packerParams.mediaType, responseEncoded, {
|
|
199
|
+
senderDID,
|
|
200
|
+
...packerOpts
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -123,10 +123,23 @@ export const parseQueryMetadata = async (propertyQuery, ldContextJSON, credentia
|
|
|
123
123
|
if (!isValidOperation(query.datatype, propertyQuery.operator)) {
|
|
124
124
|
throw new Error(`operator ${propertyQuery.operator} is not supported for datatype ${query.datatype}`);
|
|
125
125
|
}
|
|
126
|
-
|
|
127
|
-
propertyQuery.
|
|
128
|
-
|
|
129
|
-
|
|
126
|
+
if ((propertyQuery.operator === Operators.NOOP || propertyQuery.operator === Operators.SD) &&
|
|
127
|
+
propertyQuery.operatorValue) {
|
|
128
|
+
throw new Error(`operator value should be undefined for ${propertyQuery.operator} operator`);
|
|
129
|
+
}
|
|
130
|
+
let values;
|
|
131
|
+
switch (propertyQuery.operator) {
|
|
132
|
+
case Operators.NOOP:
|
|
133
|
+
case Operators.SD:
|
|
134
|
+
values = [];
|
|
135
|
+
break;
|
|
136
|
+
case Operators.EXISTS:
|
|
137
|
+
values = transformExistsValue(propertyQuery.operatorValue);
|
|
138
|
+
break;
|
|
139
|
+
default:
|
|
140
|
+
values = await transformQueryValueToBigInts(propertyQuery.operatorValue, query.datatype);
|
|
141
|
+
}
|
|
142
|
+
query.values = values;
|
|
130
143
|
}
|
|
131
144
|
return query;
|
|
132
145
|
};
|
|
@@ -110,3 +110,39 @@ export var RefreshServiceType;
|
|
|
110
110
|
(function (RefreshServiceType) {
|
|
111
111
|
RefreshServiceType["Iden3RefreshService2023"] = "Iden3RefreshService2023";
|
|
112
112
|
})(RefreshServiceType || (RefreshServiceType = {}));
|
|
113
|
+
/**
|
|
114
|
+
* PaymentRequestType type for payment requests
|
|
115
|
+
* @beta
|
|
116
|
+
* @enum {string}
|
|
117
|
+
*/
|
|
118
|
+
export var PaymentRequestType;
|
|
119
|
+
(function (PaymentRequestType) {
|
|
120
|
+
PaymentRequestType["PaymentRequest"] = "PaymentRequest";
|
|
121
|
+
})(PaymentRequestType || (PaymentRequestType = {}));
|
|
122
|
+
/**
|
|
123
|
+
* PaymentRequestDataType type for payment requests
|
|
124
|
+
* @beta
|
|
125
|
+
* @enum {string}
|
|
126
|
+
*/
|
|
127
|
+
export var PaymentRequestDataType;
|
|
128
|
+
(function (PaymentRequestDataType) {
|
|
129
|
+
PaymentRequestDataType["Iden3PaymentRequestCryptoV1"] = "Iden3PaymentRequestCryptoV1";
|
|
130
|
+
})(PaymentRequestDataType || (PaymentRequestDataType = {}));
|
|
131
|
+
/**
|
|
132
|
+
* PaymentType type for payment responses
|
|
133
|
+
* @beta
|
|
134
|
+
* @enum {string}
|
|
135
|
+
*/
|
|
136
|
+
export var PaymentType;
|
|
137
|
+
(function (PaymentType) {
|
|
138
|
+
PaymentType["Iden3PaymentCryptoV1"] = "Iden3PaymentCryptoV1";
|
|
139
|
+
})(PaymentType || (PaymentType = {}));
|
|
140
|
+
/**
|
|
141
|
+
* Media types for Payment supported currencies
|
|
142
|
+
* @beta
|
|
143
|
+
* @enum {number}
|
|
144
|
+
*/
|
|
145
|
+
export var SupportedCurrencies;
|
|
146
|
+
(function (SupportedCurrencies) {
|
|
147
|
+
SupportedCurrencies["ETH"] = "ETH";
|
|
148
|
+
})(SupportedCurrencies || (SupportedCurrencies = {}));
|
|
@@ -19,6 +19,8 @@ export declare const PROTOCOL_MESSAGE_TYPE: Readonly<{
|
|
|
19
19
|
CREDENTIAL_ONCHAIN_OFFER_MESSAGE_TYPE: string;
|
|
20
20
|
PROPOSAL_REQUEST_MESSAGE_TYPE: string;
|
|
21
21
|
PROPOSAL_MESSAGE_TYPE: string;
|
|
22
|
+
PAYMENT_REQUEST_MESSAGE_TYPE: string;
|
|
23
|
+
PAYMENT_MESSAGE_TYPE: string;
|
|
22
24
|
}>;
|
|
23
25
|
/**
|
|
24
26
|
* Media types for iden3 comm communication protocol
|
|
@@ -2,6 +2,7 @@ import { BasicMessage, IPackageManager } from '../types';
|
|
|
2
2
|
import { AuthMessageHandlerOptions } from './auth';
|
|
3
3
|
import { RevocationStatusMessageHandlerOptions } from './revocation-status';
|
|
4
4
|
import { ContractMessageHandlerOptions } from './contract-request';
|
|
5
|
+
import { PaymentHandlerOptions, PaymentRequestMessageHandlerOptions } from './payment';
|
|
5
6
|
/**
|
|
6
7
|
* iden3 Protocol message handler interface
|
|
7
8
|
*/
|
|
@@ -77,7 +78,7 @@ export declare class MessageHandler {
|
|
|
77
78
|
* @param context - An object containing information specific to the type of message being handled.
|
|
78
79
|
* @returns A Promise that resolves to a Uint8Array of the packed response, or null if no response was generated.
|
|
79
80
|
*/
|
|
80
|
-
handleMessage(bytes: Uint8Array, context: AuthMessageHandlerOptions | ContractMessageHandlerOptions | RevocationStatusMessageHandlerOptions |
|
|
81
|
+
handleMessage(bytes: Uint8Array, context: AuthMessageHandlerOptions | ContractMessageHandlerOptions | RevocationStatusMessageHandlerOptions | PaymentRequestMessageHandlerOptions | PaymentHandlerOptions | {
|
|
81
82
|
[key: string]: unknown;
|
|
82
83
|
}): Promise<Uint8Array | null>;
|
|
83
84
|
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { BasicMessage, IPackageManager, PackerParams } from '../types';
|
|
2
|
+
import { DID } from '@iden3/js-iden3-core';
|
|
3
|
+
import { AbstractMessageHandler, IProtocolMessageHandler } from './message-handler';
|
|
4
|
+
import { PaymentInfo, PaymentMessage, PaymentRequestDataInfo, PaymentRequestInfo, PaymentRequestMessage } from '../types/protocol/payment';
|
|
5
|
+
/**
|
|
6
|
+
* @beta
|
|
7
|
+
* createPaymentRequest is a function to create protocol payment-request message
|
|
8
|
+
* @param {DID} sender - sender did
|
|
9
|
+
* @param {DID} receiver - receiver did
|
|
10
|
+
* @param {string} agent - agent URL
|
|
11
|
+
* @param {PaymentRequestInfo[]} payments - payments
|
|
12
|
+
* @returns `PaymentRequestMessage`
|
|
13
|
+
*/
|
|
14
|
+
export declare function createPaymentRequest(sender: DID, receiver: DID, agent: string, payments: PaymentRequestInfo[]): PaymentRequestMessage;
|
|
15
|
+
/**
|
|
16
|
+
* @beta
|
|
17
|
+
* createPayment is a function to create protocol payment message
|
|
18
|
+
* @param {DID} sender - sender did
|
|
19
|
+
* @param {DID} receiver - receiver did
|
|
20
|
+
* @param {PaymentInfo[]} payments - payments
|
|
21
|
+
* @returns `PaymentMessage`
|
|
22
|
+
*/
|
|
23
|
+
export declare function createPayment(sender: DID, receiver: DID, payments: PaymentInfo[]): PaymentMessage;
|
|
24
|
+
/**
|
|
25
|
+
* @beta
|
|
26
|
+
* Interface that allows the processing of the payment-request and payment protocol messages
|
|
27
|
+
*
|
|
28
|
+
* @interface IPaymentHandler
|
|
29
|
+
*/
|
|
30
|
+
export interface IPaymentHandler {
|
|
31
|
+
/**
|
|
32
|
+
* @beta
|
|
33
|
+
* unpacks payment-request
|
|
34
|
+
* @param {Uint8Array} request - raw byte message
|
|
35
|
+
* @returns `Promise<PaymentRequestMessage>`
|
|
36
|
+
*/
|
|
37
|
+
parsePaymentRequest(request: Uint8Array): Promise<PaymentRequestMessage>;
|
|
38
|
+
/**
|
|
39
|
+
* @beta
|
|
40
|
+
* handle payment-request
|
|
41
|
+
* @param {Uint8Array} request - raw byte message
|
|
42
|
+
* @param {PaymentRequestMessageHandlerOptions} opts - handler options
|
|
43
|
+
* @returns {Promise<Uint8Array>} - agent message or null
|
|
44
|
+
*/
|
|
45
|
+
handlePaymentRequest(request: Uint8Array, opts: PaymentRequestMessageHandlerOptions): Promise<Uint8Array | null>;
|
|
46
|
+
/**
|
|
47
|
+
* @beta
|
|
48
|
+
* handle payment protocol message
|
|
49
|
+
* @param {PaymentMessage} payment - payment message
|
|
50
|
+
* @param {PaymentHandlerOptions} opts - options
|
|
51
|
+
* @returns `Promise<void>`
|
|
52
|
+
*/
|
|
53
|
+
handlePayment(payment: PaymentMessage, opts: PaymentHandlerOptions): Promise<void>;
|
|
54
|
+
}
|
|
55
|
+
/** @beta PaymentRequestMessageHandlerOptions represents payment-request handler options */
|
|
56
|
+
export type PaymentRequestMessageHandlerOptions = {
|
|
57
|
+
paymentHandler: (data: PaymentRequestDataInfo) => Promise<string>;
|
|
58
|
+
};
|
|
59
|
+
/** @beta PaymentHandlerOptions represents payment handler options */
|
|
60
|
+
export type PaymentHandlerOptions = {
|
|
61
|
+
paymentRequest: PaymentRequestMessage;
|
|
62
|
+
paymentValidationHandler: (txId: string, data: PaymentRequestDataInfo) => Promise<void>;
|
|
63
|
+
};
|
|
64
|
+
/** @beta PaymentHandlerParams represents payment handler params */
|
|
65
|
+
export type PaymentHandlerParams = {
|
|
66
|
+
packerParams: PackerParams;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
*
|
|
70
|
+
* Allows to process PaymentRequest protocol message
|
|
71
|
+
* @beta
|
|
72
|
+
* @class PaymentHandler
|
|
73
|
+
* @implements implements IPaymentHandler interface
|
|
74
|
+
*/
|
|
75
|
+
export declare class PaymentHandler extends AbstractMessageHandler implements IPaymentHandler, IProtocolMessageHandler {
|
|
76
|
+
private readonly _packerMgr;
|
|
77
|
+
private readonly _params;
|
|
78
|
+
/**
|
|
79
|
+
* @beta Creates an instance of PaymentHandler.
|
|
80
|
+
* @param {IPackageManager} _packerMgr - package manager to unpack message envelope
|
|
81
|
+
* @param {PaymentHandlerParams} _params - payment handler params
|
|
82
|
+
*
|
|
83
|
+
*/
|
|
84
|
+
constructor(_packerMgr: IPackageManager, _params: PaymentHandlerParams);
|
|
85
|
+
handle(message: BasicMessage, context: PaymentRequestMessageHandlerOptions | PaymentHandlerOptions): Promise<BasicMessage | null>;
|
|
86
|
+
/**
|
|
87
|
+
* @inheritdoc IPaymentHandler#parsePaymentRequest
|
|
88
|
+
*/
|
|
89
|
+
parsePaymentRequest(request: Uint8Array): Promise<PaymentRequestMessage>;
|
|
90
|
+
private handlePaymentRequestMessage;
|
|
91
|
+
/**
|
|
92
|
+
* @inheritdoc IPaymentHandler#handlePaymentRequest
|
|
93
|
+
*/
|
|
94
|
+
handlePaymentRequest(request: Uint8Array, opts: PaymentRequestMessageHandlerOptions): Promise<Uint8Array | null>;
|
|
95
|
+
/**
|
|
96
|
+
* @inheritdoc IPaymentHandler#handlePayment
|
|
97
|
+
*/
|
|
98
|
+
handlePayment(payment: PaymentMessage, opts: PaymentHandlerOptions): Promise<void>;
|
|
99
|
+
private packMessage;
|
|
100
|
+
}
|
|
@@ -18,7 +18,7 @@ export type CredentialsOfferMessage = Required<BasicMessage> & {
|
|
|
18
18
|
/** CredentialsOfferMessageBody is struct the represents offer message */
|
|
19
19
|
export type CredentialsOfferMessageBody = {
|
|
20
20
|
url: string;
|
|
21
|
-
credentials:
|
|
21
|
+
credentials: CredentialOffer[];
|
|
22
22
|
};
|
|
23
23
|
/** CredentialsOnchainOfferMessage represent Iden3message for credential onhcain offer message */
|
|
24
24
|
export type CredentialsOnchainOfferMessage = Required<BasicMessage> & {
|
|
@@ -26,7 +26,7 @@ export type CredentialsOnchainOfferMessage = Required<BasicMessage> & {
|
|
|
26
26
|
};
|
|
27
27
|
/** CredentialsOnchainOfferMessageBody is struct the represents onchain offer message body */
|
|
28
28
|
export type CredentialsOnchainOfferMessageBody = {
|
|
29
|
-
credentials:
|
|
29
|
+
credentials: CredentialOffer[];
|
|
30
30
|
transaction_data: ContractInvokeTransactionData;
|
|
31
31
|
};
|
|
32
32
|
/** CredentialOffer is structure to fetch credential */
|
|
@@ -36,7 +36,7 @@ export type CredentialOffer = {
|
|
|
36
36
|
};
|
|
37
37
|
/** CredentialIssuanceMessage represent Iden3message for credential issuance */
|
|
38
38
|
export type CredentialIssuanceMessage = Required<BasicMessage> & {
|
|
39
|
-
body
|
|
39
|
+
body: IssuanceMessageBody;
|
|
40
40
|
};
|
|
41
41
|
/** IssuanceMessageBody is struct the represents message when credential is issued */
|
|
42
42
|
export type IssuanceMessageBody = {
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { BasicMessage } from '../';
|
|
2
|
+
import { PaymentRequestDataType, PaymentRequestType, PaymentType } from '../../../verifiable';
|
|
3
|
+
/** @beta PaymentRequestMessage is struct the represents payment-request message */
|
|
4
|
+
export type PaymentRequestMessage = BasicMessage & {
|
|
5
|
+
body?: PaymentRequestMessageBody;
|
|
6
|
+
};
|
|
7
|
+
/** @beta PaymentRequestMessageBody is struct the represents body for payment-request */
|
|
8
|
+
export type PaymentRequestMessageBody = {
|
|
9
|
+
agent: string;
|
|
10
|
+
payments: PaymentRequestInfo[];
|
|
11
|
+
};
|
|
12
|
+
/** @beta PaymentRequestInfo is struct the represents payment info for payment-request */
|
|
13
|
+
export type PaymentRequestInfo = {
|
|
14
|
+
credentials: {
|
|
15
|
+
type: string;
|
|
16
|
+
context: string;
|
|
17
|
+
}[];
|
|
18
|
+
type: PaymentRequestType;
|
|
19
|
+
data: PaymentRequestDataInfo;
|
|
20
|
+
expiration?: string;
|
|
21
|
+
description?: string;
|
|
22
|
+
};
|
|
23
|
+
/** @beta PaymentRequestDataInfo is struct the represents payment data info for payment-request */
|
|
24
|
+
export type PaymentRequestDataInfo = {
|
|
25
|
+
type: PaymentRequestDataType;
|
|
26
|
+
amount: string;
|
|
27
|
+
id: number;
|
|
28
|
+
chainId: number;
|
|
29
|
+
address: string;
|
|
30
|
+
currency: string;
|
|
31
|
+
signature?: string;
|
|
32
|
+
};
|
|
33
|
+
/** @beta PaymentMessage is struct the represents payment message */
|
|
34
|
+
export type PaymentMessage = BasicMessage & {
|
|
35
|
+
body?: PaymentMessageBody;
|
|
36
|
+
};
|
|
37
|
+
/** @beta PaymentMessageBody is struct the represents body for payment message */
|
|
38
|
+
export type PaymentMessageBody = {
|
|
39
|
+
payments: PaymentInfo[];
|
|
40
|
+
};
|
|
41
|
+
/** @beta PaymentInfo is struct the represents payment info for payment */
|
|
42
|
+
export type PaymentInfo = {
|
|
43
|
+
id: number;
|
|
44
|
+
type: PaymentType;
|
|
45
|
+
paymentData: {
|
|
46
|
+
txId: string;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
@@ -85,3 +85,35 @@ export declare enum SubjectPosition {
|
|
|
85
85
|
export declare enum RefreshServiceType {
|
|
86
86
|
Iden3RefreshService2023 = "Iden3RefreshService2023"
|
|
87
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* PaymentRequestType type for payment requests
|
|
90
|
+
* @beta
|
|
91
|
+
* @enum {string}
|
|
92
|
+
*/
|
|
93
|
+
export declare enum PaymentRequestType {
|
|
94
|
+
PaymentRequest = "PaymentRequest"
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* PaymentRequestDataType type for payment requests
|
|
98
|
+
* @beta
|
|
99
|
+
* @enum {string}
|
|
100
|
+
*/
|
|
101
|
+
export declare enum PaymentRequestDataType {
|
|
102
|
+
Iden3PaymentRequestCryptoV1 = "Iden3PaymentRequestCryptoV1"
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* PaymentType type for payment responses
|
|
106
|
+
* @beta
|
|
107
|
+
* @enum {string}
|
|
108
|
+
*/
|
|
109
|
+
export declare enum PaymentType {
|
|
110
|
+
Iden3PaymentCryptoV1 = "Iden3PaymentCryptoV1"
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Media types for Payment supported currencies
|
|
114
|
+
* @beta
|
|
115
|
+
* @enum {number}
|
|
116
|
+
*/
|
|
117
|
+
export declare enum SupportedCurrencies {
|
|
118
|
+
ETH = "ETH"
|
|
119
|
+
}
|