uvd-x402-sdk 2.76.0 → 2.78.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/backend/index.d.mts +85 -2
- package/dist/backend/index.d.ts +85 -2
- package/dist/backend/index.js +65 -2
- package/dist/backend/index.js.map +1 -1
- package/dist/backend/index.mjs +61 -3
- package/dist/backend/index.mjs.map +1 -1
- package/dist/index.d.mts +1 -3
- package/dist/index.d.ts +1 -3
- package/dist/index.js +71 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +67 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/backend/index.ts +187 -2
- package/src/dx402.ts +7 -2
- package/src/index.ts +7 -0
package/dist/index.d.mts
CHANGED
|
@@ -4,7 +4,7 @@ export { A as AlgorandPaymentPayload, C as CAIP2_IDENTIFIERS, a as CAIP2_TO_CHAI
|
|
|
4
4
|
import { S as SigningWalletAdapter } from './wallet-0cX9Pw2F.mjs';
|
|
5
5
|
export { E as EIP3009Authorization, a as EIP3009Params } from './wallet-0cX9Pw2F.mjs';
|
|
6
6
|
export { E as EnvKeyAdapter, O as OWSWallet, a as OWSWalletAdapter } from './ows-CYIVd4xO.mjs';
|
|
7
|
-
export { AMBIGUOUS_LEASE_REASONS, DEFAULT_FACILITATOR_RETRIES, DEFAULT_RETRY_AFTER_SECONDS, FacilitatorClient, FacilitatorClientOptions, FacilitatorErrorInfo, FacilitatorFailureFields, FacilitatorFetchOptions, HonoMiddlewareOptions, MAX_RETRY_AFTER_SECONDS, PaymentAcceptance, PaymentMiddlewareOptions, PaymentPayloadV2, PaymentRequirementsV2, REPLAYABLE_LEASE_REASONS, ResourceInfoV2, SettleRequestV2, VerifiedPaymentState, VerifyRequestV2, WRITER_LEASE_REASONS, WriterLeaseReason, X402_CORS_HEADERS, X402_HEADER_NAMES, buildPaymentRequirements, buildSettleRequest, buildSettleRequestV2, buildVerifyRequest, buildVerifyRequestV2, create402Response, createHonoMiddleware, createPaymentMiddleware, extractPaymentFromHeaders, facilitatorFetch, getCorsHeaders, isAmbiguousLeaseReason, isReplayableLeaseReason, parseRetryAfterSeconds, readFacilitatorError } from './backend/index.mjs';
|
|
7
|
+
export { AMBIGUOUS_LEASE_REASONS, DEFAULT_FACILITATOR_RETRIES, DEFAULT_RETRY_AFTER_SECONDS, FacilitatorClient, FacilitatorClientOptions, FacilitatorErrorInfo, FacilitatorFailureFields, FacilitatorFetchOptions, HonoMiddlewareOptions, MAX_RETRY_AFTER_SECONDS, PaymentAcceptance, PaymentMiddlewareOptions, PaymentPayloadV2, PaymentRequirementsV2, REPLAYABLE_LEASE_REASONS, ResourceInfoV2, SettleRequestV2, VerifiedPaymentState, VerifyRequestV2, WRITER_LEASE_REASONS, WriterLeaseReason, X402_CORS_HEADERS, X402_HEADER_NAMES, buildPaymentRequirements, buildSettleRequest, buildSettleRequestForVersion, buildSettleRequestV2, buildVerifyRequest, buildVerifyRequestForVersion, buildVerifyRequestV2, create402Response, createHonoMiddleware, createPaymentMiddleware, extractPaymentFromHeaders, facilitatorFetch, getCorsHeaders, isAmbiguousLeaseReason, isReplayableLeaseReason, parseRetryAfterSeconds, readFacilitatorError, resolveEnvelopeVersion, toPaymentRequirementsV2, toResourceInfoV2 } from './backend/index.mjs';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* DX402 `durable-evidence`: recover a paid response after the fact.
|
|
@@ -369,8 +369,6 @@ declare function sellerDigestFor(paymentId: string, contentHash: string, payee:
|
|
|
369
369
|
/**
|
|
370
370
|
* Largest `POST /dx402/anchor` request the facilitator accepts, mirroring its
|
|
371
371
|
* `MAX_REQUEST_BODY_BYTES` (default 64 KiB, an anti-OOM bound on every route).
|
|
372
|
-
* After base64 inflation and ~600 bytes of metadata this leaves ~47 KB of
|
|
373
|
-
* plaintext.
|
|
374
372
|
*/
|
|
375
373
|
declare const ANCHOR_MAX_REQUEST_BYTES: number;
|
|
376
374
|
declare function anchorEvidence(body: Uint8Array, opts: AnchorOptions): Promise<Record<string, unknown>>;
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export { A as AlgorandPaymentPayload, C as CAIP2_IDENTIFIERS, a as CAIP2_TO_CHAI
|
|
|
4
4
|
import { S as SigningWalletAdapter } from './wallet-0cX9Pw2F.js';
|
|
5
5
|
export { E as EIP3009Authorization, a as EIP3009Params } from './wallet-0cX9Pw2F.js';
|
|
6
6
|
export { E as EnvKeyAdapter, O as OWSWallet, a as OWSWalletAdapter } from './ows-DTDixPzO.js';
|
|
7
|
-
export { AMBIGUOUS_LEASE_REASONS, DEFAULT_FACILITATOR_RETRIES, DEFAULT_RETRY_AFTER_SECONDS, FacilitatorClient, FacilitatorClientOptions, FacilitatorErrorInfo, FacilitatorFailureFields, FacilitatorFetchOptions, HonoMiddlewareOptions, MAX_RETRY_AFTER_SECONDS, PaymentAcceptance, PaymentMiddlewareOptions, PaymentPayloadV2, PaymentRequirementsV2, REPLAYABLE_LEASE_REASONS, ResourceInfoV2, SettleRequestV2, VerifiedPaymentState, VerifyRequestV2, WRITER_LEASE_REASONS, WriterLeaseReason, X402_CORS_HEADERS, X402_HEADER_NAMES, buildPaymentRequirements, buildSettleRequest, buildSettleRequestV2, buildVerifyRequest, buildVerifyRequestV2, create402Response, createHonoMiddleware, createPaymentMiddleware, extractPaymentFromHeaders, facilitatorFetch, getCorsHeaders, isAmbiguousLeaseReason, isReplayableLeaseReason, parseRetryAfterSeconds, readFacilitatorError } from './backend/index.js';
|
|
7
|
+
export { AMBIGUOUS_LEASE_REASONS, DEFAULT_FACILITATOR_RETRIES, DEFAULT_RETRY_AFTER_SECONDS, FacilitatorClient, FacilitatorClientOptions, FacilitatorErrorInfo, FacilitatorFailureFields, FacilitatorFetchOptions, HonoMiddlewareOptions, MAX_RETRY_AFTER_SECONDS, PaymentAcceptance, PaymentMiddlewareOptions, PaymentPayloadV2, PaymentRequirementsV2, REPLAYABLE_LEASE_REASONS, ResourceInfoV2, SettleRequestV2, VerifiedPaymentState, VerifyRequestV2, WRITER_LEASE_REASONS, WriterLeaseReason, X402_CORS_HEADERS, X402_HEADER_NAMES, buildPaymentRequirements, buildSettleRequest, buildSettleRequestForVersion, buildSettleRequestV2, buildVerifyRequest, buildVerifyRequestForVersion, buildVerifyRequestV2, create402Response, createHonoMiddleware, createPaymentMiddleware, extractPaymentFromHeaders, facilitatorFetch, getCorsHeaders, isAmbiguousLeaseReason, isReplayableLeaseReason, parseRetryAfterSeconds, readFacilitatorError, resolveEnvelopeVersion, toPaymentRequirementsV2, toResourceInfoV2 } from './backend/index.js';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* DX402 `durable-evidence`: recover a paid response after the fact.
|
|
@@ -369,8 +369,6 @@ declare function sellerDigestFor(paymentId: string, contentHash: string, payee:
|
|
|
369
369
|
/**
|
|
370
370
|
* Largest `POST /dx402/anchor` request the facilitator accepts, mirroring its
|
|
371
371
|
* `MAX_REQUEST_BODY_BYTES` (default 64 KiB, an anti-OOM bound on every route).
|
|
372
|
-
* After base64 inflation and ~600 bytes of metadata this leaves ~47 KB of
|
|
373
|
-
* plaintext.
|
|
374
372
|
*/
|
|
375
373
|
declare const ANCHOR_MAX_REQUEST_BYTES: number;
|
|
376
374
|
declare function anchorEvidence(body: Uint8Array, opts: AnchorOptions): Promise<Record<string, unknown>>;
|
package/dist/index.js
CHANGED
|
@@ -1638,6 +1638,12 @@ async function anchorEvidence(body, opts) {
|
|
|
1638
1638
|
// `sealed` -> it hosts and derives the pointer; `pointer` alone -> it uses
|
|
1639
1639
|
// yours; neither -> error (x402-rs `dx402/service.rs`).
|
|
1640
1640
|
...pointer !== void 0 ? { pointer } : { sealed: toBase64(blob) },
|
|
1641
|
+
// Declared, not measured. Since x402-rs 2.3.0 the facilitator records
|
|
1642
|
+
// the store that ACTUALLY took the bytes and returns that, so a response
|
|
1643
|
+
// may name a different backend than the request did -- `ipfs` where you
|
|
1644
|
+
// said `s3`, because a deployment whose primary is Pinata wrote there.
|
|
1645
|
+
// That is the facilitator correcting the record, not a mismatch to
|
|
1646
|
+
// assert on.
|
|
1641
1647
|
backend: opts.backend ?? (pointer !== void 0 ? backendForPointer(pointer) : "s3"),
|
|
1642
1648
|
contentHash: hash,
|
|
1643
1649
|
keyAlg: opts.payerKey.length === 32 ? "ECIES-X25519" : "ECIES-secp256k1",
|
|
@@ -3939,6 +3945,54 @@ function buildSettleRequest(paymentHeader, requirements) {
|
|
|
3939
3945
|
paymentRequirements: requirements
|
|
3940
3946
|
};
|
|
3941
3947
|
}
|
|
3948
|
+
function isCaip2Network(network) {
|
|
3949
|
+
return network.includes(":");
|
|
3950
|
+
}
|
|
3951
|
+
function toResourceInfoV2(requirements) {
|
|
3952
|
+
return {
|
|
3953
|
+
url: requirements.resource,
|
|
3954
|
+
description: requirements.description ?? DEFAULT_PAYMENT_DESCRIPTION,
|
|
3955
|
+
mimeType: requirements.mimeType ?? DEFAULT_PAYMENT_MIME_TYPE
|
|
3956
|
+
};
|
|
3957
|
+
}
|
|
3958
|
+
function toPaymentRequirementsV2(requirements) {
|
|
3959
|
+
return {
|
|
3960
|
+
scheme: requirements.scheme,
|
|
3961
|
+
network: isCaip2Network(requirements.network) ? requirements.network : chainToCAIP2(requirements.network),
|
|
3962
|
+
asset: requirements.asset,
|
|
3963
|
+
amount: requirements.maxAmountRequired,
|
|
3964
|
+
payTo: requirements.payTo,
|
|
3965
|
+
// Required by the facilitator: omitting it is a 400, measured the same day.
|
|
3966
|
+
maxTimeoutSeconds: requirements.maxTimeoutSeconds ?? DEFAULT_PAYMENT_TIMEOUT_SECONDS,
|
|
3967
|
+
...requirements.extra !== void 0 ? { extra: requirements.extra } : {}
|
|
3968
|
+
};
|
|
3969
|
+
}
|
|
3970
|
+
function resolveEnvelopeVersion(paymentHeader, requirements, requested = "auto") {
|
|
3971
|
+
if (requested !== "auto") {
|
|
3972
|
+
return requested;
|
|
3973
|
+
}
|
|
3974
|
+
return isCaip2Network(paymentHeader.network) || isCaip2Network(requirements.network) ? 2 : 1;
|
|
3975
|
+
}
|
|
3976
|
+
function buildVerifyRequestForVersion(paymentHeader, requirements, version) {
|
|
3977
|
+
if (version === 2) {
|
|
3978
|
+
return buildVerifyRequestV2(
|
|
3979
|
+
paymentHeader.payload,
|
|
3980
|
+
toResourceInfoV2(requirements),
|
|
3981
|
+
toPaymentRequirementsV2(requirements)
|
|
3982
|
+
);
|
|
3983
|
+
}
|
|
3984
|
+
return buildVerifyRequest(paymentHeader, requirements);
|
|
3985
|
+
}
|
|
3986
|
+
function buildSettleRequestForVersion(paymentHeader, requirements, version) {
|
|
3987
|
+
if (version === 2) {
|
|
3988
|
+
return buildSettleRequestV2(
|
|
3989
|
+
paymentHeader.payload,
|
|
3990
|
+
toResourceInfoV2(requirements),
|
|
3991
|
+
toPaymentRequirementsV2(requirements)
|
|
3992
|
+
);
|
|
3993
|
+
}
|
|
3994
|
+
return buildSettleRequest(paymentHeader, requirements);
|
|
3995
|
+
}
|
|
3942
3996
|
var X402_CORS_HEADERS = {
|
|
3943
3997
|
"Access-Control-Allow-Headers": "Content-Type, X-PAYMENT, PAYMENT-SIGNATURE, Authorization",
|
|
3944
3998
|
"Access-Control-Expose-Headers": "X-PAYMENT-RESPONSE, PAYMENT-RESPONSE, PAYMENT-REQUIRED",
|
|
@@ -3962,11 +4016,13 @@ var FacilitatorClient = class {
|
|
|
3962
4016
|
timeout;
|
|
3963
4017
|
explicitTimeout;
|
|
3964
4018
|
retries;
|
|
4019
|
+
x402Version;
|
|
3965
4020
|
constructor(options = {}) {
|
|
3966
4021
|
this.baseUrl = options.baseUrl || "https://facilitator.ultravioletadao.xyz";
|
|
3967
4022
|
this.explicitTimeout = options.timeout !== void 0;
|
|
3968
4023
|
this.timeout = options.timeout || 3e4;
|
|
3969
4024
|
this.retries = options.retries;
|
|
4025
|
+
this.x402Version = options.x402Version ?? "auto";
|
|
3970
4026
|
}
|
|
3971
4027
|
/**
|
|
3972
4028
|
* Get timeout for a specific network, using per-chain defaults when no explicit timeout was set.
|
|
@@ -3992,7 +4048,11 @@ var FacilitatorClient = class {
|
|
|
3992
4048
|
* @returns Verification result
|
|
3993
4049
|
*/
|
|
3994
4050
|
async verify(paymentHeader, requirements) {
|
|
3995
|
-
const body =
|
|
4051
|
+
const body = buildVerifyRequestForVersion(
|
|
4052
|
+
paymentHeader,
|
|
4053
|
+
requirements,
|
|
4054
|
+
resolveEnvelopeVersion(paymentHeader, requirements, this.x402Version)
|
|
4055
|
+
);
|
|
3996
4056
|
try {
|
|
3997
4057
|
const { response, error } = await facilitatorFetch(
|
|
3998
4058
|
`${this.baseUrl}/verify`,
|
|
@@ -4031,7 +4091,11 @@ var FacilitatorClient = class {
|
|
|
4031
4091
|
* @returns Settlement result with transaction hash
|
|
4032
4092
|
*/
|
|
4033
4093
|
async settle(paymentHeader, requirements) {
|
|
4034
|
-
const body =
|
|
4094
|
+
const body = buildSettleRequestForVersion(
|
|
4095
|
+
paymentHeader,
|
|
4096
|
+
requirements,
|
|
4097
|
+
resolveEnvelopeVersion(paymentHeader, requirements, this.x402Version)
|
|
4098
|
+
);
|
|
4035
4099
|
const settleTimeout = this.getTimeout(requirements.network);
|
|
4036
4100
|
try {
|
|
4037
4101
|
const { response, error } = await facilitatorFetch(
|
|
@@ -4739,11 +4803,13 @@ exports.availableBackends = availableBackends;
|
|
|
4739
4803
|
exports.buildEscrowPreAuth = buildEscrowPreAuth;
|
|
4740
4804
|
exports.buildPaymentRequirements = buildPaymentRequirements;
|
|
4741
4805
|
exports.buildSettleRequest = buildSettleRequest;
|
|
4806
|
+
exports.buildSettleRequestForVersion = buildSettleRequestForVersion;
|
|
4742
4807
|
exports.buildSettleRequestV2 = buildSettleRequestV2;
|
|
4743
4808
|
exports.buildSignatureBase = buildSignatureBase;
|
|
4744
4809
|
exports.buildSignatureParams = buildSignatureParams;
|
|
4745
4810
|
exports.buildTokenMetadata = buildTokenMetadata;
|
|
4746
4811
|
exports.buildVerifyRequest = buildVerifyRequest;
|
|
4812
|
+
exports.buildVerifyRequestForVersion = buildVerifyRequestForVersion;
|
|
4747
4813
|
exports.buildVerifyRequestV2 = buildVerifyRequestV2;
|
|
4748
4814
|
exports.caip2ToChain = caip2ToChain;
|
|
4749
4815
|
exports.chainToCAIP2 = chainToCAIP2;
|
|
@@ -4818,6 +4884,7 @@ exports.readFacilitatorError = readFacilitatorError;
|
|
|
4818
4884
|
exports.recoverEvidence = recoverEvidence;
|
|
4819
4885
|
exports.replaySafeTypedData = replaySafeTypedData;
|
|
4820
4886
|
exports.resolveDelegation = resolveDelegation;
|
|
4887
|
+
exports.resolveEnvelopeVersion = resolveEnvelopeVersion;
|
|
4821
4888
|
exports.rpcDelegationResolver = rpcDelegationResolver;
|
|
4822
4889
|
exports.sealEvidence = sealEvidence;
|
|
4823
4890
|
exports.sealEvidenceTo = sealEvidenceTo;
|
|
@@ -4829,6 +4896,8 @@ exports.signRequest = signRequest;
|
|
|
4829
4896
|
exports.signRequestWithSigner = signRequestWithSigner;
|
|
4830
4897
|
exports.signRequestWithWallet = signRequestWithWallet;
|
|
4831
4898
|
exports.streamTrafficEvents = streamTrafficEvents;
|
|
4899
|
+
exports.toPaymentRequirementsV2 = toPaymentRequirementsV2;
|
|
4900
|
+
exports.toResourceInfoV2 = toResourceInfoV2;
|
|
4832
4901
|
exports.unseal = unseal;
|
|
4833
4902
|
exports.validateAmount = validateAmount;
|
|
4834
4903
|
exports.validateRecipient = validateRecipient;
|