@onchaindb/sdk 2.1.1 → 4.0.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/src/types.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  // Core OnDB Types
2
2
  import {QueryValue} from "./query-sdk";
3
- import {X402Quote} from "./x402/types";
3
+ import {X402PaymentRequiredResponse} from "./x402/types";
4
4
 
5
5
  export interface OnDBConfig {
6
6
  endpoint: string;
@@ -182,10 +182,10 @@ export interface ReadQueryWithPayment {
182
182
  quote_id: string;
183
183
  }
184
184
 
185
- // Union type for query responses - either data or quote
185
+ // Union type for query responses - either data or payment required
186
186
  export type QueryResult<T extends Record<string, any>> =
187
- | QueryResponse<T> // Normal response with data
188
- | X402Quote; // Quote response when payment required (x402 format)
187
+ | QueryResponse<T> // Normal response with data
188
+ | X402PaymentRequiredResponse; // Raw 402 response when payment required
189
189
 
190
190
  // Transaction Events
191
191
  export interface TransactionEvents {
@@ -230,7 +230,7 @@ export class ValidationError extends OnDBError {
230
230
  export class PaymentRequiredError extends OnDBError {
231
231
  constructor(
232
232
  message: string,
233
- public quote: X402Quote,
233
+ public paymentRequired: X402PaymentRequiredResponse,
234
234
  details?: any
235
235
  ) {
236
236
  super(message, 'PAYMENT_REQUIRED', 402, details);
package/src/x402/types.ts CHANGED
@@ -42,6 +42,21 @@ export interface X402PaymentRequirement {
42
42
  mimeType: string;
43
43
  /** Maximum timeout for payment in seconds */
44
44
  maxTimeoutSeconds: number;
45
+ /** Token decimals (e.g. 6 for TIA/USDC) */
46
+ tokenDecimals: number;
47
+ /** Token symbol (e.g. "TIA", "USDC") */
48
+ tokenSymbol: string;
49
+ /** Token name (e.g. "Celestia") */
50
+ tokenName: string;
51
+ /** Token version string */
52
+ tokenVersion: string;
53
+ /** Token metadata object */
54
+ tokenMetadata: {
55
+ decimals: number;
56
+ name: string;
57
+ symbol: string;
58
+ version: string;
59
+ };
45
60
  /** Extra extension data */
46
61
  extra?: X402Extra;
47
62
  }
@@ -50,6 +65,10 @@ export interface X402PaymentRequirement {
50
65
  * x402 Extra field with OnDB extensions
51
66
  */
52
67
  export interface X402Extra {
68
+ /** Extension name */
69
+ name?: string;
70
+ /** Extension version */
71
+ version?: string;
53
72
  /** Extension identifier */
54
73
  x402Extension?: string;
55
74
  /** Quote ID for this payment */
@@ -62,10 +81,6 @@ export interface X402Extra {
62
81
  paymentMethod?: PaymentMethod;
63
82
  /** x402 facilitator URL */
64
83
  facilitator?: string;
65
- /** Token symbol */
66
- tokenSymbol?: string;
67
- /** Token decimals */
68
- tokenDecimals?: number;
69
84
  /** Cost breakdown */
70
85
  costBreakdown?: Record<string, number>;
71
86
  /** Pricing information */
@@ -73,6 +88,8 @@ export interface X402Extra {
73
88
  baseAmount: string;
74
89
  baseAsset: string;
75
90
  premiumPercent?: number;
91
+ note?: string;
92
+ payoutSlippagePercent?: number;
76
93
  expiresAt?: number;
77
94
  };
78
95
  }
@@ -123,13 +140,13 @@ export interface X402NativePayload {
123
140
  export interface X402EvmPayload {
124
141
  /** EIP-712 signature */
125
142
  signature: string;
126
- /** ERC-3009 authorization */
143
+ /** ERC-3009 authorization — validAfter/validBefore must be decimal strings (uint256) */
127
144
  authorization: {
128
145
  from: string;
129
146
  to: string;
130
147
  value: string;
131
- validAfter: number;
132
- validBefore: number;
148
+ validAfter: string;
149
+ validBefore: string;
133
150
  nonce: string;
134
151
  };
135
152
  }
@@ -226,8 +243,8 @@ export interface X402FacilitatorPaymentResult {
226
243
  from: string;
227
244
  to: string;
228
245
  value: string;
229
- validAfter: number;
230
- validBefore: number;
246
+ validAfter: string;
247
+ validBefore: string;
231
248
  nonce: string;
232
249
  };
233
250
  };
package/src/x402/utils.ts CHANGED
@@ -55,6 +55,16 @@ function parsePaymentRequirement(req: any): X402PaymentRequirement {
55
55
  description: req.description,
56
56
  mimeType: req.mimeType || 'application/json',
57
57
  maxTimeoutSeconds: req.maxTimeoutSeconds || 300,
58
+ tokenDecimals: req.tokenDecimals ?? 6,
59
+ tokenSymbol: req.tokenSymbol ?? '',
60
+ tokenName: req.tokenName ?? '',
61
+ tokenVersion: req.tokenVersion ?? '',
62
+ tokenMetadata: req.tokenMetadata ?? {
63
+ decimals: req.tokenDecimals ?? 6,
64
+ name: req.tokenName ?? '',
65
+ symbol: req.tokenSymbol ?? '',
66
+ version: req.tokenVersion ?? '',
67
+ },
58
68
  extra: req.extra,
59
69
  };
60
70
  }
@@ -80,7 +90,7 @@ export function requirementToQuote(
80
90
  }
81
91
 
82
92
  // Calculate total cost (for display purposes)
83
- const decimals = extra.tokenDecimals || 6;
93
+ const decimals = requirement.tokenDecimals ?? 6;
84
94
  const totalCost = parseInt(amountRaw) / Math.pow(10, decimals);
85
95
 
86
96
  // Calculate expiration
@@ -97,7 +107,7 @@ export function requirementToQuote(
97
107
  chainType,
98
108
  network: requirement.network,
99
109
  asset: requirement.asset,
100
- tokenSymbol: extra.tokenSymbol || getTokenSymbol(requirement.asset),
110
+ tokenSymbol: requirement.tokenSymbol || getTokenSymbol(requirement.asset),
101
111
  tokenDecimals: decimals,
102
112
  paymentMethod: (extra.paymentMethod || 'native') as PaymentMethod,
103
113
  facilitator: extra.facilitator,
@@ -176,8 +186,8 @@ export interface EvmFacilitatorAuthorization {
176
186
  from: string;
177
187
  to: string;
178
188
  value: string;
179
- validAfter: number;
180
- validBefore: number;
189
+ validAfter: string;
190
+ validBefore: string;
181
191
  nonce: string;
182
192
  };
183
193
  }