@0xpolygonid/js-sdk 1.12.0 → 1.13.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 +229 -2
- package/dist/browser/esm/index.js.map +1 -1
- package/dist/browser/umd/index.js +231 -1
- package/dist/browser/umd/index.js.map +1 -1
- package/dist/node/cjs/iden3comm/constants.js +5 -1
- 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/verifiable/constants.js +28 -1
- package/dist/node/esm/iden3comm/constants.js +5 -1
- 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/verifiable/constants.js +27 -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/payment.d.ts +47 -0
- package/dist/types/verifiable/constants.d.ts +24 -0
- package/package.json +1 -1
|
@@ -7443,6 +7443,33 @@ var RefreshServiceType;
|
|
|
7443
7443
|
(function (RefreshServiceType) {
|
|
7444
7444
|
RefreshServiceType["Iden3RefreshService2023"] = "Iden3RefreshService2023";
|
|
7445
7445
|
})(RefreshServiceType || (RefreshServiceType = {}));
|
|
7446
|
+
/**
|
|
7447
|
+
* PaymentRequestType type for payment requests
|
|
7448
|
+
*
|
|
7449
|
+
* @enum {string}
|
|
7450
|
+
*/
|
|
7451
|
+
var PaymentRequestType;
|
|
7452
|
+
(function (PaymentRequestType) {
|
|
7453
|
+
PaymentRequestType["PaymentRequest"] = "PaymentRequest";
|
|
7454
|
+
})(PaymentRequestType || (PaymentRequestType = {}));
|
|
7455
|
+
/**
|
|
7456
|
+
* PaymentRequestDataType type for payment requests
|
|
7457
|
+
*
|
|
7458
|
+
* @enum {string}
|
|
7459
|
+
*/
|
|
7460
|
+
var PaymentRequestDataType;
|
|
7461
|
+
(function (PaymentRequestDataType) {
|
|
7462
|
+
PaymentRequestDataType["Iden3PaymentRequestCryptoV1"] = "Iden3PaymentRequestCryptoV1";
|
|
7463
|
+
})(PaymentRequestDataType || (PaymentRequestDataType = {}));
|
|
7464
|
+
/**
|
|
7465
|
+
* PaymentType type for payment responses
|
|
7466
|
+
*
|
|
7467
|
+
* @enum {string}
|
|
7468
|
+
*/
|
|
7469
|
+
var PaymentType;
|
|
7470
|
+
(function (PaymentType) {
|
|
7471
|
+
PaymentType["Iden3PaymentCryptoV1"] = "Iden3PaymentCryptoV1";
|
|
7472
|
+
})(PaymentType || (PaymentType = {}));
|
|
7446
7473
|
|
|
7447
7474
|
/**
|
|
7448
7475
|
* Iden3SparseMerkleProof is a iden3 protocol merkle tree proof
|
|
@@ -53483,7 +53510,11 @@ const PROTOCOL_MESSAGE_TYPE = Object.freeze({
|
|
|
53483
53510
|
// ProposalRequestMessageType is type for proposal-request message
|
|
53484
53511
|
PROPOSAL_REQUEST_MESSAGE_TYPE: IDEN3_PROTOCOL + 'credentials/0.1/proposal-request',
|
|
53485
53512
|
// ProposalMessageType is type for proposal message
|
|
53486
|
-
PROPOSAL_MESSAGE_TYPE: IDEN3_PROTOCOL + 'credentials/0.1/proposal'
|
|
53513
|
+
PROPOSAL_MESSAGE_TYPE: IDEN3_PROTOCOL + 'credentials/0.1/proposal',
|
|
53514
|
+
// PaymentRequestMessageType is type for payment-request message
|
|
53515
|
+
PAYMENT_REQUEST_MESSAGE_TYPE: IDEN3_PROTOCOL + 'credentials/0.1/payment-request',
|
|
53516
|
+
// PaymentMessageType is type for payment message
|
|
53517
|
+
PAYMENT_MESSAGE_TYPE: IDEN3_PROTOCOL + 'credentials/0.1/payment'
|
|
53487
53518
|
});
|
|
53488
53519
|
/**
|
|
53489
53520
|
* Media types for iden3 comm communication protocol
|
|
@@ -58138,5 +58169,201 @@ class CredentialProposalHandler extends AbstractMessageHandler {
|
|
|
58138
58169
|
}
|
|
58139
58170
|
}
|
|
58140
58171
|
|
|
58141
|
-
|
|
58172
|
+
/**
|
|
58173
|
+
* @beta
|
|
58174
|
+
* createPaymentRequest is a function to create protocol payment-request message
|
|
58175
|
+
* @param {DID} sender - sender did
|
|
58176
|
+
* @param {DID} receiver - receiver did
|
|
58177
|
+
* @param {string} agent - agent URL
|
|
58178
|
+
* @param {PaymentRequestInfo[]} payments - payments
|
|
58179
|
+
* @returns `PaymentRequestMessage`
|
|
58180
|
+
*/
|
|
58181
|
+
function createPaymentRequest(sender, receiver, agent, payments) {
|
|
58182
|
+
const uuidv4 = v4();
|
|
58183
|
+
const request = {
|
|
58184
|
+
id: uuidv4,
|
|
58185
|
+
thid: uuidv4,
|
|
58186
|
+
from: sender.string(),
|
|
58187
|
+
to: receiver.string(),
|
|
58188
|
+
typ: MediaType.PlainMessage,
|
|
58189
|
+
type: PROTOCOL_MESSAGE_TYPE.PAYMENT_REQUEST_MESSAGE_TYPE,
|
|
58190
|
+
body: {
|
|
58191
|
+
agent,
|
|
58192
|
+
payments
|
|
58193
|
+
}
|
|
58194
|
+
};
|
|
58195
|
+
return request;
|
|
58196
|
+
}
|
|
58197
|
+
/**
|
|
58198
|
+
* @beta
|
|
58199
|
+
* createPayment is a function to create protocol payment message
|
|
58200
|
+
* @param {DID} sender - sender did
|
|
58201
|
+
* @param {DID} receiver - receiver did
|
|
58202
|
+
* @param {PaymentInfo[]} payments - payments
|
|
58203
|
+
* @returns `PaymentMessage`
|
|
58204
|
+
*/
|
|
58205
|
+
function createPayment(sender, receiver, payments) {
|
|
58206
|
+
const uuidv4 = v4();
|
|
58207
|
+
const request = {
|
|
58208
|
+
id: uuidv4,
|
|
58209
|
+
thid: uuidv4,
|
|
58210
|
+
from: sender.string(),
|
|
58211
|
+
to: receiver.string(),
|
|
58212
|
+
typ: MediaType.PlainMessage,
|
|
58213
|
+
type: PROTOCOL_MESSAGE_TYPE.PAYMENT_MESSAGE_TYPE,
|
|
58214
|
+
body: {
|
|
58215
|
+
payments
|
|
58216
|
+
}
|
|
58217
|
+
};
|
|
58218
|
+
return request;
|
|
58219
|
+
}
|
|
58220
|
+
/**
|
|
58221
|
+
*
|
|
58222
|
+
* Allows to process PaymentRequest protocol message
|
|
58223
|
+
* @beta
|
|
58224
|
+
* @class PaymentHandler
|
|
58225
|
+
* @implements implements IPaymentHandler interface
|
|
58226
|
+
*/
|
|
58227
|
+
class PaymentHandler extends AbstractMessageHandler {
|
|
58228
|
+
/**
|
|
58229
|
+
* @beta Creates an instance of PaymentHandler.
|
|
58230
|
+
* @param {IPackageManager} _packerMgr - package manager to unpack message envelope
|
|
58231
|
+
* @param {PaymentHandlerParams} _params - payment handler params
|
|
58232
|
+
*
|
|
58233
|
+
*/
|
|
58234
|
+
constructor(_packerMgr, _params) {
|
|
58235
|
+
super();
|
|
58236
|
+
this._packerMgr = _packerMgr;
|
|
58237
|
+
this._params = _params;
|
|
58238
|
+
}
|
|
58239
|
+
async handle(message, context) {
|
|
58240
|
+
switch (message.type) {
|
|
58241
|
+
case PROTOCOL_MESSAGE_TYPE.PAYMENT_REQUEST_MESSAGE_TYPE:
|
|
58242
|
+
return await this.handlePaymentRequestMessage(message, context);
|
|
58243
|
+
case PROTOCOL_MESSAGE_TYPE.PAYMENT_MESSAGE_TYPE:
|
|
58244
|
+
await this.handlePayment(message, context);
|
|
58245
|
+
return null;
|
|
58246
|
+
default:
|
|
58247
|
+
return super.handle(message, context);
|
|
58248
|
+
}
|
|
58249
|
+
}
|
|
58250
|
+
/**
|
|
58251
|
+
* @inheritdoc IPaymentHandler#parsePaymentRequest
|
|
58252
|
+
*/
|
|
58253
|
+
async parsePaymentRequest(request) {
|
|
58254
|
+
const { unpackedMessage: message } = await this._packerMgr.unpack(request);
|
|
58255
|
+
const paymentRequest = message;
|
|
58256
|
+
if (message.type !== PROTOCOL_MESSAGE_TYPE.PAYMENT_REQUEST_MESSAGE_TYPE) {
|
|
58257
|
+
throw new Error('Invalid media type');
|
|
58258
|
+
}
|
|
58259
|
+
return paymentRequest;
|
|
58260
|
+
}
|
|
58261
|
+
async handlePaymentRequestMessage(paymentRequest, ctx) {
|
|
58262
|
+
if (!paymentRequest.to) {
|
|
58263
|
+
throw new Error(`failed request. empty 'to' field`);
|
|
58264
|
+
}
|
|
58265
|
+
if (!paymentRequest.from) {
|
|
58266
|
+
throw new Error(`failed request. empty 'from' field`);
|
|
58267
|
+
}
|
|
58268
|
+
if (!paymentRequest.body?.payments?.length) {
|
|
58269
|
+
throw new Error(`failed request. no 'payments' in body`);
|
|
58270
|
+
}
|
|
58271
|
+
if (!ctx.paymentHandler) {
|
|
58272
|
+
throw new Error(`please provide payment handler in context`);
|
|
58273
|
+
}
|
|
58274
|
+
const senderDID = DID.parse(paymentRequest.to);
|
|
58275
|
+
const receiverDID = DID.parse(paymentRequest.from);
|
|
58276
|
+
const payments = [];
|
|
58277
|
+
for (let i = 0; i < paymentRequest.body.payments.length; i++) {
|
|
58278
|
+
const paymentReq = paymentRequest.body.payments[i];
|
|
58279
|
+
if (paymentReq.type !== PaymentRequestType.PaymentRequest) {
|
|
58280
|
+
throw new Error(`failed request. not supported '${paymentReq.type}' payment type `);
|
|
58281
|
+
}
|
|
58282
|
+
if (paymentReq.data.type !== PaymentRequestDataType.Iden3PaymentRequestCryptoV1) {
|
|
58283
|
+
throw new Error(`failed request. not supported '${paymentReq.data.type}' payment type `);
|
|
58284
|
+
}
|
|
58285
|
+
const txId = await ctx.paymentHandler(paymentReq.data);
|
|
58286
|
+
payments.push({
|
|
58287
|
+
id: paymentReq.data.id,
|
|
58288
|
+
type: PaymentType.Iden3PaymentCryptoV1,
|
|
58289
|
+
paymentData: {
|
|
58290
|
+
txId
|
|
58291
|
+
}
|
|
58292
|
+
});
|
|
58293
|
+
}
|
|
58294
|
+
const paymentMessage = createPayment(senderDID, receiverDID, payments);
|
|
58295
|
+
const response = await this.packMessage(paymentMessage, senderDID);
|
|
58296
|
+
const agentResult = await fetch(paymentRequest.body.agent, {
|
|
58297
|
+
method: 'POST',
|
|
58298
|
+
body: response,
|
|
58299
|
+
headers: {
|
|
58300
|
+
'Content-Type': 'application/octet-stream'
|
|
58301
|
+
}
|
|
58302
|
+
});
|
|
58303
|
+
const arrayBuffer = await agentResult.arrayBuffer();
|
|
58304
|
+
if (!arrayBuffer.byteLength) {
|
|
58305
|
+
return null;
|
|
58306
|
+
}
|
|
58307
|
+
const { unpackedMessage } = await this._packerMgr.unpack(new Uint8Array(arrayBuffer));
|
|
58308
|
+
return unpackedMessage;
|
|
58309
|
+
}
|
|
58310
|
+
/**
|
|
58311
|
+
* @inheritdoc IPaymentHandler#handlePaymentRequest
|
|
58312
|
+
*/
|
|
58313
|
+
async handlePaymentRequest(request, opts) {
|
|
58314
|
+
if (this._params.packerParams.mediaType === MediaType.SignedMessage &&
|
|
58315
|
+
!this._params.packerParams.packerOptions) {
|
|
58316
|
+
throw new Error(`jws packer options are required for ${MediaType.SignedMessage}`);
|
|
58317
|
+
}
|
|
58318
|
+
const paymentRequest = await this.parsePaymentRequest(request);
|
|
58319
|
+
if (!paymentRequest.from) {
|
|
58320
|
+
throw new Error(`failed request. empty 'from' field`);
|
|
58321
|
+
}
|
|
58322
|
+
if (!paymentRequest.to) {
|
|
58323
|
+
throw new Error(`failed request. empty 'to' field`);
|
|
58324
|
+
}
|
|
58325
|
+
const agentMessage = await this.handlePaymentRequestMessage(paymentRequest, opts);
|
|
58326
|
+
if (!agentMessage) {
|
|
58327
|
+
return null;
|
|
58328
|
+
}
|
|
58329
|
+
const senderDID = DID.parse(paymentRequest.to);
|
|
58330
|
+
return this.packMessage(agentMessage, senderDID);
|
|
58331
|
+
}
|
|
58332
|
+
/**
|
|
58333
|
+
* @inheritdoc IPaymentHandler#handlePayment
|
|
58334
|
+
*/
|
|
58335
|
+
async handlePayment(payment, opts) {
|
|
58336
|
+
if (opts.paymentRequest.from !== payment.to) {
|
|
58337
|
+
throw new Error(`sender of the request is not a target of response - expected ${opts.paymentRequest.from}, given ${payment.to}`);
|
|
58338
|
+
}
|
|
58339
|
+
if (!payment.body?.payments.length) {
|
|
58340
|
+
throw new Error(`failed request. empty 'payments' field in body`);
|
|
58341
|
+
}
|
|
58342
|
+
for (let i = 0; i < payment.body.payments.length; i++) {
|
|
58343
|
+
const p = payment.body?.payments[i];
|
|
58344
|
+
const paymentRequestData = opts.paymentRequest.body?.payments.find((r) => r.data.id === p.id);
|
|
58345
|
+
if (!paymentRequestData) {
|
|
58346
|
+
throw new Error(`can't find payment request for payment id ${p.id}`);
|
|
58347
|
+
}
|
|
58348
|
+
if (!opts.paymentValidationHandler) {
|
|
58349
|
+
throw new Error(`please provide payment validation handler in options`);
|
|
58350
|
+
}
|
|
58351
|
+
await opts.paymentValidationHandler(p.paymentData.txId, paymentRequestData.data);
|
|
58352
|
+
}
|
|
58353
|
+
}
|
|
58354
|
+
async packMessage(message, senderDID) {
|
|
58355
|
+
const responseEncoded = byteEncoder.encode(JSON.stringify(message));
|
|
58356
|
+
const packerOpts = this._params.packerParams.mediaType === MediaType.SignedMessage
|
|
58357
|
+
? this._params.packerParams.packerOptions
|
|
58358
|
+
: {
|
|
58359
|
+
provingMethodAlg: proving.provingMethodGroth16AuthV2Instance.methodAlg
|
|
58360
|
+
};
|
|
58361
|
+
return await this._packerMgr.pack(this._params.packerParams.mediaType, responseEncoded, {
|
|
58362
|
+
senderDID,
|
|
58363
|
+
...packerOpts
|
|
58364
|
+
});
|
|
58365
|
+
}
|
|
58366
|
+
}
|
|
58367
|
+
|
|
58368
|
+
export { AbstractMessageHandler, AbstractPrivateKeyStore, AgentResolver, AtomicQueryMTPV2Inputs, AtomicQueryMTPV2OnChainInputs, AtomicQueryMTPV2OnChainPubSignals, AtomicQueryMTPV2PubSignals, AtomicQuerySigV2Inputs, AtomicQuerySigV2OnChainCircuitInputs, AtomicQuerySigV2OnChainInputs, AtomicQuerySigV2OnChainPubSignals, AtomicQuerySigV2PubSignals, AtomicQueryV3Inputs, AtomicQueryV3OnChainInputs, AtomicQueryV3OnChainPubSignals, AtomicQueryV3PubSignals, AuthHandler, AuthV2Inputs, AuthV2PubSignals, BJJSignatureProof2021, BaseConfig, BjjProvider, BrowserDataSource, CircuitClaim, CircuitError, CircuitId, CircuitStorage, ContractRequestHandler, CredentialProposalHandler, CredentialStatusPublisherRegistry, CredentialStatusResolverRegistry, CredentialStatusType, CredentialStorage, CredentialWallet, DIDDocumentJSONSchema, DataPrepareHandlerFunc, Ed25519Provider, ErrorEmptyAuthClaimNonRevProof, ErrorEmptyAuthClaimProof, ErrorEmptyChallengeSignature, ErrorEmptyClaimNonRevProof, ErrorEmptyClaimProof, ErrorEmptyClaimSignature, ErrorEmptyIssuerAuthClaimNonRevProof, ErrorEmptyIssuerAuthClaimProof, ErrorUserStateInRelayClaimProof, EthStateStorage, FSCircuitStorage, FetchHandler, FilterQuery, Iden3OnchainSmtCredentialStatusPublisher, Iden3SmtRhsCredentialStatusPublisher, Iden3SparseMerkleTreeProof, IdentityStorage, IdentityWallet, InMemoryDataSource, InMemoryMerkleTreeStorage, InMemoryPrivateKeyStore, IndexedDBDataSource, IndexedDBPrivateKeyStore, InputGenerator, IssuerResolver, JSON_SCHEMA_VALIDATORS_REGISTRY, JWSPacker, JsonSchemaValidator, KMS, KmsKeyType, LDParser, LinkedMultiQueryInputs, LinkedMultiQueryPubSignals, LocalStoragePrivateKeyStore, MerkleTreeIndexedDBStorage, MerkleTreeLocalStorage, MerkleTreeType, MerklizedRootPosition, MessageBus, MessageHandler, NativeProver, OnChainResolver, OnChainRevocationStorage, OnChainZKPVerifier, Operators, constants as PROTOCOL_CONSTANTS, PackageManager, Parser, PaymentHandler, PaymentRequestDataType, PaymentRequestType, PaymentType, PlainPacker, ProofNode, ProofPurpose, ProofService, ProofType, PubSignalsVerifier, Query, QueryOperators, RHSResolver, RefreshHandler, RefreshServiceType, RevocationStatusHandler, SDK_EVENTS, Scalar, SearchError, Sec256k1Provider, StandardJSONCredentialsQueryFilter, StateTransitionInputs, StateTransitionPubSignals, SubjectPosition, TransactionService, ValueProof, Vector, VerifiableConstants, VerificationHandlerFunc, W3CCredential, XSDNS, ZKPPacker, availableTypesOperators, base58ToBytes$1 as base58ToBytes, base64ToBytes$1 as base64ToBytes, base64UrlToBytes, bigIntArrayToStringArray, bigIntCompare, buildDIDFromEthPubKey, buildFieldPath, buildTreeState, buildVerifierId, byteDecoder, byteEncoder, bytesToBase58$1 as bytesToBase58, bytesToBase64, bytesToBase64url$1 as bytesToBase64url, bytesToHex$3 as bytesToHex, cacheLoader, calculateCoreSchemaHash, calculateQueryHashV2, calculateQueryHashV3, checkCircuitOperator, checkCircuitQueriesLength, checkDataInField, checkQueryRequest, circuitValidator, comparatorOptions, createAuthorizationRequest, createAuthorizationRequestWithMessage, createPayment, createPaymentRequest, createProposal, createProposalRequest, createSchemaHash, createVerifiablePresentation, credentialSubjectKey, dataFillsSlot, decodeBase64url$1 as decodeBase64url, defaultEthConnectionConfig, defaultMTLevels, defaultMTLevelsClaim, defaultMTLevelsOnChain, defaultValueArraySize, defineMerklizedRootPosition, encodeBase64url, existenceToInt, extractProof, extractPublicKeyBytes, factoryComparer, fieldToByteArray, fieldValueFromVerifiablePresentation, fillCoreClaimSlot, fillSlot, findCredentialType, findValue, generateProfileDID, getFieldSlotIndex, getKMSIdByAuthCredential, getNodeAuxValue, getNodesRepresentation, getOperatorNameByValue, getProperties, getSerializationAttrFromContext, getSerializationAttrFromParsedContext, getUserDIDFromCredential, hexToBytes$3 as hexToBytes, isEthereumIdentity, isGenesisState, isGenesisStateId, isIssuerGenesis, isValidOperation, keyPath, mergeObjects, parseCoreClaimSlots, parseCredentialSubject, parseQueriesMetadata, parseQueryMetadata, parseSerializationAttr, prepareCircuitArrayValues, prepareSiblingsStr, processZeroKnowledgeProofRequests, pushHashesToRHS, resolveDIDDocumentAuth, resolvePath, resolveVerificationMethods, strMTHex, stringByPath, subjectPositionIndex, swapEndianness, toClaimNonRevStatus, toGISTProof, toRevocationStatus, transformQueryValueToBigInts, userStateError, validateDIDDocumentAuth, validateDisclosureNativeSDSupport, validateDisclosureV2Circuit, validateEmptyCredentialSubjectNoopNativeSupport, validateEmptyCredentialSubjectV2Circuit, validateOperators, validateTreeState, verifyFieldValueInclusionNativeExistsSupport, verifyFieldValueInclusionV2, witnessBuilder };
|
|
58142
58369
|
//# sourceMappingURL=index.js.map
|