@piprail/sdk 2.8.0 → 2.10.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.
Files changed (39) hide show
  1. package/CHANGELOG.md +124 -0
  2. package/README.md +7 -4
  3. package/dist/{algorand-WJL6VRXW.js → algorand-AA3WXKW4.js} +1 -1
  4. package/dist/{algorand-EKD34T4Q.cjs → algorand-FCEECDG6.cjs} +32 -32
  5. package/dist/{aptos-CVHLVMAF.cjs → aptos-GHJPO6JJ.cjs} +31 -31
  6. package/dist/{aptos-WMPFEASY.js → aptos-LY67Q6QF.js} +1 -1
  7. package/dist/chunk-3SBTJKAG.js +92 -0
  8. package/dist/chunk-CQQI5IJX.cjs +92 -0
  9. package/dist/{chunk-VPENSVOI.cjs → chunk-MWBT7MCE.cjs} +7 -3
  10. package/dist/chunk-O4UQOZ4Z.cjs +14 -0
  11. package/dist/{chunk-W3HOMXOF.js → chunk-SC2ZYDHD.js} +6 -2
  12. package/dist/chunk-SK3CB7UA.js +14 -0
  13. package/dist/index.cjs +2247 -425
  14. package/dist/index.d.cts +3094 -2583
  15. package/dist/index.d.ts +3094 -2583
  16. package/dist/index.js +1937 -115
  17. package/dist/ledger-OQos-tmj.d.cts +925 -0
  18. package/dist/ledger-OQos-tmj.d.ts +925 -0
  19. package/dist/{near-NYFMX2KA.cjs → near-6KAQVVG2.cjs} +26 -26
  20. package/dist/{near-QV4IOZNX.js → near-FZBUICCS.js} +1 -1
  21. package/dist/node.cjs +38 -0
  22. package/dist/node.d.cts +16 -0
  23. package/dist/node.d.ts +16 -0
  24. package/dist/node.js +38 -0
  25. package/dist/receipt-NNEID77X.js +14 -0
  26. package/dist/receipt-QCDPMWNF.cjs +14 -0
  27. package/dist/{solana-Z34OWXMO.js → solana-ELUWO6N5.js} +1 -1
  28. package/dist/{solana-L342QCSV.cjs → solana-MYF4HBO4.cjs} +32 -32
  29. package/dist/{stellar-PWC4LETJ.js → stellar-ASP2THL2.js} +2 -2
  30. package/dist/{stellar-YEXRVR3W.cjs → stellar-CRWBSX4E.cjs} +21 -21
  31. package/dist/{sui-VEOGHBYE.js → sui-FZIKZNVI.js} +14 -4
  32. package/dist/{sui-EFRSCDWN.cjs → sui-Y4RLKKE2.cjs} +29 -19
  33. package/dist/{ton-N7KSPSAR.js → ton-7GKCTC5H.js} +1 -1
  34. package/dist/{ton-LZKJWYHV.cjs → ton-AOR3EURW.cjs} +16 -16
  35. package/dist/{tron-WKDUQVZR.js → tron-BMCWN5SS.js} +8 -2
  36. package/dist/{tron-DQU4WTGQ.cjs → tron-OMXB6EW2.cjs} +31 -25
  37. package/dist/{xrpl-6B4IYRWI.js → xrpl-DD7TJL5L.js} +1 -1
  38. package/dist/{xrpl-K3U3SBF4.cjs → xrpl-Y6SQNYLC.cjs} +20 -20
  39. package/package.json +11 -1
@@ -0,0 +1,92 @@
1
+ // src/drivers/evm/receipt.ts
2
+ import {
3
+ recoverTypedDataAddress,
4
+ getAddress
5
+ } from "viem";
6
+ var RECEIPT_DOMAIN = Object.freeze({
7
+ name: "x402 receipt",
8
+ version: "1",
9
+ chainId: 1
10
+ });
11
+ var RECEIPT_TYPES = Object.freeze({
12
+ Receipt: [
13
+ { name: "version", type: "uint256" },
14
+ { name: "network", type: "string" },
15
+ { name: "resourceUrl", type: "string" },
16
+ { name: "payer", type: "string" },
17
+ { name: "issuedAt", type: "uint256" },
18
+ { name: "transaction", type: "string" }
19
+ ]
20
+ });
21
+ var RECEIPT_PRIMARY_TYPE = "Receipt";
22
+ function receiptMessage(input) {
23
+ return {
24
+ version: 1n,
25
+ network: input.network,
26
+ resourceUrl: input.resourceUrl,
27
+ payer: input.payer,
28
+ issuedAt: BigInt(input.issuedAt),
29
+ // §5.3: unused optional fields are the empty string in the SIGNED message, never omitted.
30
+ transaction: input.transaction ?? ""
31
+ };
32
+ }
33
+ async function signReceiptEvm(wallet, input) {
34
+ const adapter = wallet._native;
35
+ const account = adapter.account;
36
+ const walletClient = adapter.walletClient;
37
+ const signature = await walletClient.signTypedData({
38
+ account,
39
+ domain: RECEIPT_DOMAIN,
40
+ types: RECEIPT_TYPES,
41
+ primaryType: RECEIPT_PRIMARY_TYPE,
42
+ message: receiptMessage(input)
43
+ });
44
+ return {
45
+ format: "eip712",
46
+ signature,
47
+ // The address that actually produced the signature (the bound wallet). A
48
+ // verifier re-recovers + checks it equals the trusted `payTo`.
49
+ signer: account.address,
50
+ payload: {
51
+ version: 1,
52
+ network: input.network,
53
+ resourceUrl: input.resourceUrl,
54
+ payer: input.payer,
55
+ issuedAt: input.issuedAt,
56
+ transaction: input.transaction ?? ""
57
+ }
58
+ };
59
+ }
60
+ async function verifyReceiptAttestationEvm(input) {
61
+ try {
62
+ const recovered = await recoverTypedDataAddress({
63
+ domain: RECEIPT_DOMAIN,
64
+ types: RECEIPT_TYPES,
65
+ primaryType: RECEIPT_PRIMARY_TYPE,
66
+ message: receiptMessage(input),
67
+ signature: input.signature
68
+ });
69
+ let expected;
70
+ let actual;
71
+ try {
72
+ expected = getAddress(input.payTo);
73
+ actual = getAddress(recovered);
74
+ } catch {
75
+ return { ok: false, signer: recovered, reason: "bad-address" };
76
+ }
77
+ if (actual !== expected) {
78
+ return { ok: false, signer: recovered, reason: "signer-mismatch" };
79
+ }
80
+ return { ok: true, signer: recovered };
81
+ } catch {
82
+ return { ok: false, reason: "invalid-signature" };
83
+ }
84
+ }
85
+
86
+ export {
87
+ RECEIPT_DOMAIN,
88
+ RECEIPT_TYPES,
89
+ RECEIPT_PRIMARY_TYPE,
90
+ signReceiptEvm,
91
+ verifyReceiptAttestationEvm
92
+ };
@@ -0,0 +1,92 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }// src/drivers/evm/receipt.ts
2
+
3
+
4
+
5
+ var _viem = require('viem');
6
+ var RECEIPT_DOMAIN = Object.freeze({
7
+ name: "x402 receipt",
8
+ version: "1",
9
+ chainId: 1
10
+ });
11
+ var RECEIPT_TYPES = Object.freeze({
12
+ Receipt: [
13
+ { name: "version", type: "uint256" },
14
+ { name: "network", type: "string" },
15
+ { name: "resourceUrl", type: "string" },
16
+ { name: "payer", type: "string" },
17
+ { name: "issuedAt", type: "uint256" },
18
+ { name: "transaction", type: "string" }
19
+ ]
20
+ });
21
+ var RECEIPT_PRIMARY_TYPE = "Receipt";
22
+ function receiptMessage(input) {
23
+ return {
24
+ version: 1n,
25
+ network: input.network,
26
+ resourceUrl: input.resourceUrl,
27
+ payer: input.payer,
28
+ issuedAt: BigInt(input.issuedAt),
29
+ // §5.3: unused optional fields are the empty string in the SIGNED message, never omitted.
30
+ transaction: _nullishCoalesce(input.transaction, () => ( ""))
31
+ };
32
+ }
33
+ async function signReceiptEvm(wallet, input) {
34
+ const adapter = wallet._native;
35
+ const account = adapter.account;
36
+ const walletClient = adapter.walletClient;
37
+ const signature = await walletClient.signTypedData({
38
+ account,
39
+ domain: RECEIPT_DOMAIN,
40
+ types: RECEIPT_TYPES,
41
+ primaryType: RECEIPT_PRIMARY_TYPE,
42
+ message: receiptMessage(input)
43
+ });
44
+ return {
45
+ format: "eip712",
46
+ signature,
47
+ // The address that actually produced the signature (the bound wallet). A
48
+ // verifier re-recovers + checks it equals the trusted `payTo`.
49
+ signer: account.address,
50
+ payload: {
51
+ version: 1,
52
+ network: input.network,
53
+ resourceUrl: input.resourceUrl,
54
+ payer: input.payer,
55
+ issuedAt: input.issuedAt,
56
+ transaction: _nullishCoalesce(input.transaction, () => ( ""))
57
+ }
58
+ };
59
+ }
60
+ async function verifyReceiptAttestationEvm(input) {
61
+ try {
62
+ const recovered = await _viem.recoverTypedDataAddress.call(void 0, {
63
+ domain: RECEIPT_DOMAIN,
64
+ types: RECEIPT_TYPES,
65
+ primaryType: RECEIPT_PRIMARY_TYPE,
66
+ message: receiptMessage(input),
67
+ signature: input.signature
68
+ });
69
+ let expected;
70
+ let actual;
71
+ try {
72
+ expected = _viem.getAddress.call(void 0, input.payTo);
73
+ actual = _viem.getAddress.call(void 0, recovered);
74
+ } catch (e) {
75
+ return { ok: false, signer: recovered, reason: "bad-address" };
76
+ }
77
+ if (actual !== expected) {
78
+ return { ok: false, signer: recovered, reason: "signer-mismatch" };
79
+ }
80
+ return { ok: true, signer: recovered };
81
+ } catch (e2) {
82
+ return { ok: false, reason: "invalid-signature" };
83
+ }
84
+ }
85
+
86
+
87
+
88
+
89
+
90
+
91
+
92
+ exports.RECEIPT_DOMAIN = RECEIPT_DOMAIN; exports.RECEIPT_TYPES = RECEIPT_TYPES; exports.RECEIPT_PRIMARY_TYPE = RECEIPT_PRIMARY_TYPE; exports.signReceiptEvm = signReceiptEvm; exports.verifyReceiptAttestationEvm = verifyReceiptAttestationEvm;
@@ -133,9 +133,12 @@ function rejectForeignToken(token, family, network) {
133
133
  }
134
134
 
135
135
  // src/util/units.ts
136
+ var MAX_DECIMALS = 100;
136
137
  function assertValidDecimals(decimals, fn) {
137
- if (!Number.isSafeInteger(decimals) || decimals < 0) {
138
- throw new Error(`${fn}: decimals must be a non-negative safe integer (got ${decimals}).`);
138
+ if (!Number.isSafeInteger(decimals) || decimals < 0 || decimals > MAX_DECIMALS) {
139
+ throw new Error(
140
+ `${fn}: decimals must be a non-negative integer \u2264 ${MAX_DECIMALS} (got ${decimals}).`
141
+ );
139
142
  }
140
143
  }
141
144
  function parseUnits(value, decimals) {
@@ -220,4 +223,5 @@ function assertNoLegacyWalletKey(wallet, family) {
220
223
 
221
224
 
222
225
 
223
- exports.PipRailError = PipRailError; exports.InsufficientFundsError = InsufficientFundsError; exports.RecipientNotReadyError = RecipientNotReadyError; exports.toInsufficientFundsError = toInsufficientFundsError; exports.WrongChainError = WrongChainError; exports.PaymentTimeoutError = PaymentTimeoutError; exports.MaxRetriesExceededError = MaxRetriesExceededError; exports.PaymentDeclinedError = PaymentDeclinedError; exports.ConfirmationTimeoutError = ConfirmationTimeoutError; exports.SettlementError = SettlementError; exports.InvalidEnvelopeError = InvalidEnvelopeError; exports.NoCompatibleAcceptError = NoCompatibleAcceptError; exports.UnsupportedSchemeError = UnsupportedSchemeError; exports.NonReplayableBodyError = NonReplayableBodyError; exports.WalletRequiredError = WalletRequiredError; exports.WrongFamilyError = WrongFamilyError; exports.UnknownTokenError = UnknownTokenError; exports.MissingDriverError = MissingDriverError; exports.UnsupportedNetworkError = UnsupportedNetworkError; exports.assertNoLegacyWalletKey = assertNoLegacyWalletKey; exports.rejectForeignToken = rejectForeignToken; exports.parseUnits = parseUnits; exports.floorUnits = floorUnits; exports.formatUnits = formatUnits; exports.nativeCost = nativeCost;
226
+
227
+ exports.PipRailError = PipRailError; exports.InsufficientFundsError = InsufficientFundsError; exports.RecipientNotReadyError = RecipientNotReadyError; exports.toInsufficientFundsError = toInsufficientFundsError; exports.WrongChainError = WrongChainError; exports.PaymentTimeoutError = PaymentTimeoutError; exports.MaxRetriesExceededError = MaxRetriesExceededError; exports.PaymentDeclinedError = PaymentDeclinedError; exports.ConfirmationTimeoutError = ConfirmationTimeoutError; exports.SettlementError = SettlementError; exports.InvalidEnvelopeError = InvalidEnvelopeError; exports.NoCompatibleAcceptError = NoCompatibleAcceptError; exports.UnsupportedSchemeError = UnsupportedSchemeError; exports.NonReplayableBodyError = NonReplayableBodyError; exports.WalletRequiredError = WalletRequiredError; exports.WrongFamilyError = WrongFamilyError; exports.UnknownTokenError = UnknownTokenError; exports.MissingDriverError = MissingDriverError; exports.UnsupportedNetworkError = UnsupportedNetworkError; exports.assertNoLegacyWalletKey = assertNoLegacyWalletKey; exports.rejectForeignToken = rejectForeignToken; exports.MAX_DECIMALS = MAX_DECIMALS; exports.parseUnits = parseUnits; exports.floorUnits = floorUnits; exports.formatUnits = formatUnits; exports.nativeCost = nativeCost;
@@ -0,0 +1,14 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/spendstore.ts
2
+ function memorySpendStore(seed = []) {
3
+ const records = [...seed];
4
+ return {
5
+ load: () => [...records],
6
+ append: (r) => {
7
+ records.push(r);
8
+ }
9
+ };
10
+ }
11
+
12
+
13
+
14
+ exports.memorySpendStore = memorySpendStore;
@@ -133,9 +133,12 @@ function rejectForeignToken(token, family, network) {
133
133
  }
134
134
 
135
135
  // src/util/units.ts
136
+ var MAX_DECIMALS = 100;
136
137
  function assertValidDecimals(decimals, fn) {
137
- if (!Number.isSafeInteger(decimals) || decimals < 0) {
138
- throw new Error(`${fn}: decimals must be a non-negative safe integer (got ${decimals}).`);
138
+ if (!Number.isSafeInteger(decimals) || decimals < 0 || decimals > MAX_DECIMALS) {
139
+ throw new Error(
140
+ `${fn}: decimals must be a non-negative integer \u2264 ${MAX_DECIMALS} (got ${decimals}).`
141
+ );
139
142
  }
140
143
  }
141
144
  function parseUnits(value, decimals) {
@@ -216,6 +219,7 @@ export {
216
219
  UnsupportedNetworkError,
217
220
  assertNoLegacyWalletKey,
218
221
  rejectForeignToken,
222
+ MAX_DECIMALS,
219
223
  parseUnits,
220
224
  floorUnits,
221
225
  formatUnits,
@@ -0,0 +1,14 @@
1
+ // src/spendstore.ts
2
+ function memorySpendStore(seed = []) {
3
+ const records = [...seed];
4
+ return {
5
+ load: () => [...records],
6
+ append: (r) => {
7
+ records.push(r);
8
+ }
9
+ };
10
+ }
11
+
12
+ export {
13
+ memorySpendStore
14
+ };