uvd-x402-sdk 2.56.0 → 2.57.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/index.d.mts +37 -1
- package/dist/index.d.ts +37 -1
- package/dist/index.js +73 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +71 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/dx402.ts +142 -1
- package/src/dx402.vectors.json +17 -0
- package/src/index.ts +4 -0
package/dist/index.d.mts
CHANGED
|
@@ -193,6 +193,42 @@ declare function payerKeyFromEvmSignature(signature: Uint8Array | string, digest
|
|
|
193
193
|
* Returns the bytes to upload. Nothing here touches the network.
|
|
194
194
|
*/
|
|
195
195
|
declare function sealEvidence(body: Uint8Array, payerKey: Uint8Array, paymentIdValue: string): Uint8Array;
|
|
196
|
+
/** The zero address, for the ed25519 form of the digest. */
|
|
197
|
+
declare const ZERO_ADDRESS: string;
|
|
198
|
+
/**
|
|
199
|
+
* The 32-byte digest a seller signs to prove an anchor is theirs.
|
|
200
|
+
*
|
|
201
|
+
* One canonical message across every curve. `payee` is the EVM address for a
|
|
202
|
+
* secp256k1 payee and the **zero address** for an ed25519 one — an ed25519
|
|
203
|
+
* address does not fit the `address` field, and the binding is already
|
|
204
|
+
* established by which key verifies the signature.
|
|
205
|
+
*
|
|
206
|
+
* `pointer` is whatever you send in the anchor, or the **empty string** when you
|
|
207
|
+
* send `sealed` and the facilitator issues the pointer itself: you cannot sign a
|
|
208
|
+
* value you have not seen.
|
|
209
|
+
*
|
|
210
|
+
* Getting this wrong throws nothing — it produces a signature that simply never
|
|
211
|
+
* verifies, and the anchor stays provisional with no clue why. The tests pin it
|
|
212
|
+
* against digests emitted by the facilitator's own Rust implementation.
|
|
213
|
+
*/
|
|
214
|
+
declare function anchorDigest(paymentId: string, contentHash: string, pointer: string, payee: string, chainId: number): Uint8Array;
|
|
215
|
+
/**
|
|
216
|
+
* Sign an anchor authorization with a Solana / Stellar ed25519 key.
|
|
217
|
+
*
|
|
218
|
+
* A Solana payee cannot produce an EIP-712 signature at all — its address is an
|
|
219
|
+
* ed25519 key — so requiring one would leave that chain unable to prove
|
|
220
|
+
* authorship even once the on-chain gate is enforced. This closes it today, with
|
|
221
|
+
* no RPC.
|
|
222
|
+
*/
|
|
223
|
+
declare function signAnchorEd25519(privateKey: Uint8Array, paymentId: string, contentHash: string, pointer?: string): string;
|
|
224
|
+
/**
|
|
225
|
+
* Sign an anchor authorization with an EVM secp256k1 key.
|
|
226
|
+
*
|
|
227
|
+
* `payee` must be the address of `privateKey` — the facilitator recovers the
|
|
228
|
+
* signer and compares, so declaring somebody else's address simply leaves the
|
|
229
|
+
* anchor provisional.
|
|
230
|
+
*/
|
|
231
|
+
declare function signAnchorEvm(privateKey: Uint8Array, paymentId: string, contentHash: string, pointer: string, payee: string, chainId: number): string;
|
|
196
232
|
|
|
197
233
|
/**
|
|
198
234
|
* Facilitator wallet addresses by chain type
|
|
@@ -841,4 +877,4 @@ interface EscrowPreAuthParams {
|
|
|
841
877
|
*/
|
|
842
878
|
declare function buildEscrowPreAuth(wallet: EscrowPreAuthSigner, params: EscrowPreAuthParams): Promise<string>;
|
|
843
879
|
|
|
844
|
-
export { type AnchoredEvidence, ContentHashMismatch, type CreateSignedFetchConfig, DX402Error, type ERC8128RequestOptions, ESCROW_DEPOSIT_LIMIT_USD, ESCROW_TIER_WINDOWS, EVENT_KINDS, EVIDENCE_HEADER, type EscrowNetworkConfig, type EscrowPaymentInfo, type EscrowPreAuthParams, type EscrowPreAuthSigner, type EscrowTierWindows, type EvidenceMode, EvidenceSkipped, FACILITATOR_ADDRESSES, type FacilitatorAddresses, KEEPALIVE_INTERVAL_MS, OPERATOR_FEE_BPS, type RecipientRole, type SSEFrame, SSEParser, type SignRequestOptions, type SignRequestWithSignerOptions, type SignatureBaseParams, type SignatureHeaders, type SignatureParamsInput, SigningWalletAdapter, type StreamTrafficEventsOptions, type TrafficEvent, type TrafficEventKind, TrafficStreamError, buildEscrowPreAuth, buildSignatureBase, buildSignatureParams, computeEscrowNonce, contentHash, createSignedFetch, dereferencePointer, paymentId as dx402PaymentId, ed25519ToX25519, evidenceFromHeaders, fetchNonce, getFacilitatorAddress, isEndToEnd, matchesFilters, parseEvidenceHeader, parseSealed, parseTrafficEvent, payerKeyFromEvmSignature, recoverEvidence, sealEvidence, sealedRoles, signRequest, signRequestWithSigner, signRequestWithWallet, streamTrafficEvents, unseal };
|
|
880
|
+
export { type AnchoredEvidence, ContentHashMismatch, type CreateSignedFetchConfig, DX402Error, type ERC8128RequestOptions, ESCROW_DEPOSIT_LIMIT_USD, ESCROW_TIER_WINDOWS, EVENT_KINDS, EVIDENCE_HEADER, type EscrowNetworkConfig, type EscrowPaymentInfo, type EscrowPreAuthParams, type EscrowPreAuthSigner, type EscrowTierWindows, type EvidenceMode, EvidenceSkipped, FACILITATOR_ADDRESSES, type FacilitatorAddresses, KEEPALIVE_INTERVAL_MS, OPERATOR_FEE_BPS, type RecipientRole, type SSEFrame, SSEParser, type SignRequestOptions, type SignRequestWithSignerOptions, type SignatureBaseParams, type SignatureHeaders, type SignatureParamsInput, SigningWalletAdapter, type StreamTrafficEventsOptions, type TrafficEvent, type TrafficEventKind, TrafficStreamError, ZERO_ADDRESS, anchorDigest, buildEscrowPreAuth, buildSignatureBase, buildSignatureParams, computeEscrowNonce, contentHash, createSignedFetch, dereferencePointer, paymentId as dx402PaymentId, ed25519ToX25519, evidenceFromHeaders, fetchNonce, getFacilitatorAddress, isEndToEnd, matchesFilters, parseEvidenceHeader, parseSealed, parseTrafficEvent, payerKeyFromEvmSignature, recoverEvidence, sealEvidence, sealedRoles, signAnchorEd25519, signAnchorEvm, signRequest, signRequestWithSigner, signRequestWithWallet, streamTrafficEvents, unseal };
|
package/dist/index.d.ts
CHANGED
|
@@ -193,6 +193,42 @@ declare function payerKeyFromEvmSignature(signature: Uint8Array | string, digest
|
|
|
193
193
|
* Returns the bytes to upload. Nothing here touches the network.
|
|
194
194
|
*/
|
|
195
195
|
declare function sealEvidence(body: Uint8Array, payerKey: Uint8Array, paymentIdValue: string): Uint8Array;
|
|
196
|
+
/** The zero address, for the ed25519 form of the digest. */
|
|
197
|
+
declare const ZERO_ADDRESS: string;
|
|
198
|
+
/**
|
|
199
|
+
* The 32-byte digest a seller signs to prove an anchor is theirs.
|
|
200
|
+
*
|
|
201
|
+
* One canonical message across every curve. `payee` is the EVM address for a
|
|
202
|
+
* secp256k1 payee and the **zero address** for an ed25519 one — an ed25519
|
|
203
|
+
* address does not fit the `address` field, and the binding is already
|
|
204
|
+
* established by which key verifies the signature.
|
|
205
|
+
*
|
|
206
|
+
* `pointer` is whatever you send in the anchor, or the **empty string** when you
|
|
207
|
+
* send `sealed` and the facilitator issues the pointer itself: you cannot sign a
|
|
208
|
+
* value you have not seen.
|
|
209
|
+
*
|
|
210
|
+
* Getting this wrong throws nothing — it produces a signature that simply never
|
|
211
|
+
* verifies, and the anchor stays provisional with no clue why. The tests pin it
|
|
212
|
+
* against digests emitted by the facilitator's own Rust implementation.
|
|
213
|
+
*/
|
|
214
|
+
declare function anchorDigest(paymentId: string, contentHash: string, pointer: string, payee: string, chainId: number): Uint8Array;
|
|
215
|
+
/**
|
|
216
|
+
* Sign an anchor authorization with a Solana / Stellar ed25519 key.
|
|
217
|
+
*
|
|
218
|
+
* A Solana payee cannot produce an EIP-712 signature at all — its address is an
|
|
219
|
+
* ed25519 key — so requiring one would leave that chain unable to prove
|
|
220
|
+
* authorship even once the on-chain gate is enforced. This closes it today, with
|
|
221
|
+
* no RPC.
|
|
222
|
+
*/
|
|
223
|
+
declare function signAnchorEd25519(privateKey: Uint8Array, paymentId: string, contentHash: string, pointer?: string): string;
|
|
224
|
+
/**
|
|
225
|
+
* Sign an anchor authorization with an EVM secp256k1 key.
|
|
226
|
+
*
|
|
227
|
+
* `payee` must be the address of `privateKey` — the facilitator recovers the
|
|
228
|
+
* signer and compares, so declaring somebody else's address simply leaves the
|
|
229
|
+
* anchor provisional.
|
|
230
|
+
*/
|
|
231
|
+
declare function signAnchorEvm(privateKey: Uint8Array, paymentId: string, contentHash: string, pointer: string, payee: string, chainId: number): string;
|
|
196
232
|
|
|
197
233
|
/**
|
|
198
234
|
* Facilitator wallet addresses by chain type
|
|
@@ -841,4 +877,4 @@ interface EscrowPreAuthParams {
|
|
|
841
877
|
*/
|
|
842
878
|
declare function buildEscrowPreAuth(wallet: EscrowPreAuthSigner, params: EscrowPreAuthParams): Promise<string>;
|
|
843
879
|
|
|
844
|
-
export { type AnchoredEvidence, ContentHashMismatch, type CreateSignedFetchConfig, DX402Error, type ERC8128RequestOptions, ESCROW_DEPOSIT_LIMIT_USD, ESCROW_TIER_WINDOWS, EVENT_KINDS, EVIDENCE_HEADER, type EscrowNetworkConfig, type EscrowPaymentInfo, type EscrowPreAuthParams, type EscrowPreAuthSigner, type EscrowTierWindows, type EvidenceMode, EvidenceSkipped, FACILITATOR_ADDRESSES, type FacilitatorAddresses, KEEPALIVE_INTERVAL_MS, OPERATOR_FEE_BPS, type RecipientRole, type SSEFrame, SSEParser, type SignRequestOptions, type SignRequestWithSignerOptions, type SignatureBaseParams, type SignatureHeaders, type SignatureParamsInput, SigningWalletAdapter, type StreamTrafficEventsOptions, type TrafficEvent, type TrafficEventKind, TrafficStreamError, buildEscrowPreAuth, buildSignatureBase, buildSignatureParams, computeEscrowNonce, contentHash, createSignedFetch, dereferencePointer, paymentId as dx402PaymentId, ed25519ToX25519, evidenceFromHeaders, fetchNonce, getFacilitatorAddress, isEndToEnd, matchesFilters, parseEvidenceHeader, parseSealed, parseTrafficEvent, payerKeyFromEvmSignature, recoverEvidence, sealEvidence, sealedRoles, signRequest, signRequestWithSigner, signRequestWithWallet, streamTrafficEvents, unseal };
|
|
880
|
+
export { type AnchoredEvidence, ContentHashMismatch, type CreateSignedFetchConfig, DX402Error, type ERC8128RequestOptions, ESCROW_DEPOSIT_LIMIT_USD, ESCROW_TIER_WINDOWS, EVENT_KINDS, EVIDENCE_HEADER, type EscrowNetworkConfig, type EscrowPaymentInfo, type EscrowPreAuthParams, type EscrowPreAuthSigner, type EscrowTierWindows, type EvidenceMode, EvidenceSkipped, FACILITATOR_ADDRESSES, type FacilitatorAddresses, KEEPALIVE_INTERVAL_MS, OPERATOR_FEE_BPS, type RecipientRole, type SSEFrame, SSEParser, type SignRequestOptions, type SignRequestWithSignerOptions, type SignatureBaseParams, type SignatureHeaders, type SignatureParamsInput, SigningWalletAdapter, type StreamTrafficEventsOptions, type TrafficEvent, type TrafficEventKind, TrafficStreamError, ZERO_ADDRESS, anchorDigest, buildEscrowPreAuth, buildSignatureBase, buildSignatureParams, computeEscrowNonce, contentHash, createSignedFetch, dereferencePointer, paymentId as dx402PaymentId, ed25519ToX25519, evidenceFromHeaders, fetchNonce, getFacilitatorAddress, isEndToEnd, matchesFilters, parseEvidenceHeader, parseSealed, parseTrafficEvent, payerKeyFromEvmSignature, recoverEvidence, sealEvidence, sealedRoles, signAnchorEd25519, signAnchorEvm, signRequest, signRequestWithSigner, signRequestWithWallet, streamTrafficEvents, unseal };
|
package/dist/index.js
CHANGED
|
@@ -289,6 +289,73 @@ function sealEvidence(body, payerKey, paymentIdValue) {
|
|
|
289
289
|
out.set(ciphertext, pos);
|
|
290
290
|
return out;
|
|
291
291
|
}
|
|
292
|
+
var ANCHOR_DOMAIN_NAME = "DX402 Anchor";
|
|
293
|
+
var ANCHOR_DOMAIN_VERSION = "1";
|
|
294
|
+
var ANCHOR_TYPE = "Dx402AnchorAuthorization(bytes32 paymentId,bytes32 contentHash,string pointer,address payee)";
|
|
295
|
+
var EIP712_DOMAIN_TYPE = "EIP712Domain(string name,string version,uint256 chainId)";
|
|
296
|
+
var ZERO_ADDRESS = "0x" + "00".repeat(20);
|
|
297
|
+
function concatBytes(...parts) {
|
|
298
|
+
const total = parts.reduce((n, p) => n + p.length, 0);
|
|
299
|
+
const out = new Uint8Array(total);
|
|
300
|
+
let pos = 0;
|
|
301
|
+
for (const p of parts) {
|
|
302
|
+
out.set(p, pos);
|
|
303
|
+
pos += p.length;
|
|
304
|
+
}
|
|
305
|
+
return out;
|
|
306
|
+
}
|
|
307
|
+
function uint256(n) {
|
|
308
|
+
const out = new Uint8Array(32);
|
|
309
|
+
let v = BigInt(n);
|
|
310
|
+
for (let i = 31; i >= 0 && v > 0n; i--) {
|
|
311
|
+
out[i] = Number(v & 0xffn);
|
|
312
|
+
v >>= 8n;
|
|
313
|
+
}
|
|
314
|
+
return out;
|
|
315
|
+
}
|
|
316
|
+
function anchorDigest(paymentId2, contentHash2, pointer, payee, chainId) {
|
|
317
|
+
const b32 = (value, field) => {
|
|
318
|
+
const raw = hexToBytes(value);
|
|
319
|
+
if (raw.length !== 32) throw new DX402Error(`${field} must be 32 bytes, got ${raw.length}`);
|
|
320
|
+
return raw;
|
|
321
|
+
};
|
|
322
|
+
const addr = hexToBytes(payee);
|
|
323
|
+
if (addr.length !== 20) {
|
|
324
|
+
throw new DX402Error(`payee must be a 20-byte address, got ${addr.length}`);
|
|
325
|
+
}
|
|
326
|
+
const enc = new TextEncoder();
|
|
327
|
+
const domainSeparator = sha3.keccak_256(
|
|
328
|
+
concatBytes(
|
|
329
|
+
sha3.keccak_256(enc.encode(EIP712_DOMAIN_TYPE)),
|
|
330
|
+
sha3.keccak_256(enc.encode(ANCHOR_DOMAIN_NAME)),
|
|
331
|
+
sha3.keccak_256(enc.encode(ANCHOR_DOMAIN_VERSION)),
|
|
332
|
+
uint256(chainId)
|
|
333
|
+
)
|
|
334
|
+
);
|
|
335
|
+
const structHash = sha3.keccak_256(
|
|
336
|
+
concatBytes(
|
|
337
|
+
sha3.keccak_256(enc.encode(ANCHOR_TYPE)),
|
|
338
|
+
b32(paymentId2, "paymentId"),
|
|
339
|
+
b32(contentHash2, "contentHash"),
|
|
340
|
+
sha3.keccak_256(enc.encode(pointer)),
|
|
341
|
+
new Uint8Array(12),
|
|
342
|
+
addr
|
|
343
|
+
)
|
|
344
|
+
);
|
|
345
|
+
return sha3.keccak_256(concatBytes(new Uint8Array([25, 1]), domainSeparator, structHash));
|
|
346
|
+
}
|
|
347
|
+
function signAnchorEd25519(privateKey, paymentId2, contentHash2, pointer = "") {
|
|
348
|
+
if (privateKey.length !== 32) {
|
|
349
|
+
throw new DX402Error(`ed25519 seed must be 32 bytes, got ${privateKey.length}`);
|
|
350
|
+
}
|
|
351
|
+
const digest = anchorDigest(paymentId2, contentHash2, pointer, ZERO_ADDRESS, 0);
|
|
352
|
+
return "0x" + bytesToHex(ed25519.ed25519.sign(digest, privateKey));
|
|
353
|
+
}
|
|
354
|
+
function signAnchorEvm(privateKey, paymentId2, contentHash2, pointer, payee, chainId) {
|
|
355
|
+
const digest = anchorDigest(paymentId2, contentHash2, pointer, payee, chainId);
|
|
356
|
+
const sig = secp256k1.secp256k1.sign(digest, privateKey);
|
|
357
|
+
return "0x" + bytesToHex(sig.toCompactRawBytes()) + (sig.recovery === 1 ? "01" : "00");
|
|
358
|
+
}
|
|
292
359
|
|
|
293
360
|
// src/types/index.ts
|
|
294
361
|
var CAIP2_IDENTIFIERS = {
|
|
@@ -3118,7 +3185,7 @@ function buildSignatureParams(params) {
|
|
|
3118
3185
|
parts.push(`alg="${ALG}"`);
|
|
3119
3186
|
return parts.join(";");
|
|
3120
3187
|
}
|
|
3121
|
-
var
|
|
3188
|
+
var ZERO_ADDRESS2 = "0x0000000000000000000000000000000000000000";
|
|
3122
3189
|
var USDC_DECIMALS = 6;
|
|
3123
3190
|
var ESCROW_DEPOSIT_LIMIT_USD = 100;
|
|
3124
3191
|
var OPERATOR_FEE_BPS = 1300;
|
|
@@ -3167,7 +3234,7 @@ function computeEscrowNonce(chainId, escrowAddress, paymentInfoTypehash, pi) {
|
|
|
3167
3234
|
const coder = ethers.ethers.AbiCoder.defaultAbiCoder();
|
|
3168
3235
|
const piTuple = [
|
|
3169
3236
|
ethers.ethers.getAddress(pi.operator),
|
|
3170
|
-
|
|
3237
|
+
ZERO_ADDRESS2,
|
|
3171
3238
|
// payer = 0 for the payer-agnostic hash
|
|
3172
3239
|
ethers.ethers.getAddress(pi.receiver),
|
|
3173
3240
|
ethers.ethers.getAddress(pi.token),
|
|
@@ -4092,6 +4159,8 @@ exports.X402Client = X402Client;
|
|
|
4092
4159
|
exports.X402Error = X402Error;
|
|
4093
4160
|
exports.X402_CORS_HEADERS = X402_CORS_HEADERS;
|
|
4094
4161
|
exports.X402_HEADER_NAMES = X402_HEADER_NAMES;
|
|
4162
|
+
exports.ZERO_ADDRESS = ZERO_ADDRESS;
|
|
4163
|
+
exports.anchorDigest = anchorDigest;
|
|
4095
4164
|
exports.buildEscrowPreAuth = buildEscrowPreAuth;
|
|
4096
4165
|
exports.buildPaymentRequirements = buildPaymentRequirements;
|
|
4097
4166
|
exports.buildSettleRequest = buildSettleRequest;
|
|
@@ -4163,6 +4232,8 @@ exports.payerKeyFromEvmSignature = payerKeyFromEvmSignature;
|
|
|
4163
4232
|
exports.recoverEvidence = recoverEvidence;
|
|
4164
4233
|
exports.sealEvidence = sealEvidence;
|
|
4165
4234
|
exports.sealedRoles = sealedRoles;
|
|
4235
|
+
exports.signAnchorEd25519 = signAnchorEd25519;
|
|
4236
|
+
exports.signAnchorEvm = signAnchorEvm;
|
|
4166
4237
|
exports.signRequest = signRequest;
|
|
4167
4238
|
exports.signRequestWithSigner = signRequestWithSigner;
|
|
4168
4239
|
exports.signRequestWithWallet = signRequestWithWallet;
|