@chipi-stack/backend 14.0.0 → 14.1.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 CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _chipi_stack_types from '@chipi-stack/types';
2
- import { CreateSessionKeyParams, SessionKeyData, AddSessionKeyParams, RevokeSessionKeyParams, GetSessionDataParams, SessionDataResponse, ExecuteWithSessionParams, Currency, ChipiSDKConfig, ExecuteTransactionParams, TransferParams, ApproveParams, CallAnyContractParams, CreateWalletParams, CreateWalletResponse, RecordSendTransactionParams, Transaction, GetTransactionListQuery, PaginatedResponse, GetWalletParams, GetTokenBalanceParams, GetTokenBalanceResponse, CreateSkuPurchaseParams, GetSkuListQuery, Sku, ChipiServerSDKConfig, ChipiBrowserSDKConfig } from '@chipi-stack/types';
2
+ import { CreateSessionKeyParams, SessionKeyData, AddSessionKeyParams, RevokeSessionKeyParams, GetSessionDataParams, SessionDataResponse, ExecuteWithSessionParams, Currency, PaymasterAdapter, PaymasterAccount, X402FacilitatorConfig, NonceStore, PaymentPayload, VerifyResponse, SettleResponse, ChipiSDKConfig, ExecuteTransactionParams, SignTypedDataParams, SignTypedDataResult, TransferParams, ApproveParams, CallAnyContractParams, CreateWalletParams, CreateWalletResponse, RecordSendTransactionParams, Transaction, GetTransactionListQuery, PaginatedResponse, GetWalletParams, GetTokenBalanceParams, GetTokenBalanceResponse, CreateSkuPurchaseParams, GetSkuListQuery, Sku, TransactionStatusResponse, PrepareWalletUpgradeParams, PrepareWalletUpgradeResponse, ExecuteWalletUpgradeParams, ExecuteWalletUpgradeResponse, ChipiServerSDKConfig, ChipiBrowserSDKConfig, X402PaymentConfig } from '@chipi-stack/types';
3
3
  export * from '@chipi-stack/types';
4
4
  export { Chain, ChainToken } from '@chipi-stack/types';
5
5
  import { ChipiWallets } from './wallets.mjs';
@@ -7,6 +7,7 @@ import { ChipiTransactions } from './transactions.mjs';
7
7
  import { ChipiSkuPurchases } from './skuPurchases.mjs';
8
8
  import { ChipiSkus } from './skus.mjs';
9
9
  import { C as ChipiClient } from './client-CqD_yGH0.mjs';
10
+ import { Call } from 'starknet';
10
11
 
11
12
  /**
12
13
  * Session key management for CHIPI wallets (SNIP-9 compatible).
@@ -175,6 +176,94 @@ declare class ChipiExchanges {
175
176
  getUsdAmount(currencyAmount: number, currency: Currency, bearerToken: string): Promise<number>;
176
177
  }
177
178
 
179
+ /**
180
+ * PaymasterAdapter implementation that uses Chipi's backend API for gasless transactions.
181
+ *
182
+ * Flow:
183
+ * 1. Detect wallet type from on-chain class hash
184
+ * 2. Call /transactions/prepare-typed-data to get TypedData
185
+ * 3. Call account.signMessage(typedData) — triggers wallet popup for external wallets
186
+ * 4. Call /transactions/execute-sponsored-transaction with signature
187
+ * 5. Return transaction hash
188
+ */
189
+ declare class ChipiPaymasterAdapter implements PaymasterAdapter {
190
+ private readonly client;
191
+ private readonly bearerToken;
192
+ constructor(client: ChipiClient, bearerToken: string);
193
+ execute({ account, calls }: {
194
+ account: PaymasterAccount;
195
+ calls: Call[];
196
+ }): Promise<string>;
197
+ }
198
+
199
+ /** Options for the static X402Facilitator.create() factory */
200
+ interface X402FacilitatorCreateOptions {
201
+ /** API public key for ChipiClient */
202
+ apiKey: string;
203
+ /** Bearer token for paymaster API calls */
204
+ bearerToken: string;
205
+ /** Custom nonce store (default: in-memory) */
206
+ nonceStore?: NonceStore;
207
+ /** RPC provider for on-chain signature verification */
208
+ provider?: X402FacilitatorConfig["provider"];
209
+ }
210
+ /**
211
+ * x402 Payment Facilitator for Starknet.
212
+ *
213
+ * Implements the "facilitator" role in the x402 protocol:
214
+ * - verify(): Validate payment signature, amount, asset, nonce replay
215
+ * - settle(): Execute the USDC transfer via Chipi's paymaster
216
+ *
217
+ * Settlement reuses Chipi's existing gasless infrastructure
218
+ * (prepare-typed-data → sign → execute-sponsored-transaction).
219
+ */
220
+ declare class X402Facilitator {
221
+ private readonly client;
222
+ private readonly bearerToken;
223
+ private readonly nonceStore;
224
+ private readonly provider;
225
+ constructor(client: ChipiClient, bearerToken: string, config?: X402FacilitatorConfig);
226
+ /**
227
+ * Factory method for simpler instantiation.
228
+ *
229
+ * @example
230
+ * ```typescript
231
+ * const facilitator = X402Facilitator.create({
232
+ * apiKey: process.env.CHIPI_API_KEY!,
233
+ * bearerToken: process.env.CHIPI_BEARER_TOKEN!,
234
+ * });
235
+ * ```
236
+ */
237
+ static create(options: X402FacilitatorCreateOptions): X402Facilitator;
238
+ /**
239
+ * Verify a payment signature is valid (doesn't execute the transfer).
240
+ *
241
+ * Checks:
242
+ * 1. Nonce has not been used (replay protection)
243
+ * 2. Payment has not expired (validUntil > now)
244
+ * 3. Asset is USDC mainnet
245
+ * 4. Amount is positive
246
+ * 5. Addresses are non-empty
247
+ */
248
+ verify(payment: PaymentPayload): Promise<VerifyResponse>;
249
+ /**
250
+ * Verify the SNIP-12 signature on a payment payload.
251
+ *
252
+ * If an RPC provider is configured, reconstructs the typed data, computes the
253
+ * message hash, and calls `is_valid_signature()` on the sender's account contract.
254
+ * Otherwise falls back to a presence-only check (backwards compatible).
255
+ */
256
+ private verifySignature;
257
+ /**
258
+ * Settle a verified payment by executing the USDC transfer via paymaster.
259
+ *
260
+ * IMPORTANT: Mark nonce as consumed BEFORE executing to prevent concurrent replays.
261
+ * If the transfer fails after nonce consumption, the nonce is still burned
262
+ * (caller should implement idempotency at a higher level if needed).
263
+ */
264
+ settle(payment: PaymentPayload): Promise<SettleResponse>;
265
+ }
266
+
178
267
  /**
179
268
  * Main Chipi SDK class
180
269
  */
@@ -193,6 +282,37 @@ declare class ChipiSDK {
193
282
  * Resolve bearer token - uses provided token or falls back to apiSecretKey
194
283
  */
195
284
  private resolveBearerToken;
285
+ /**
286
+ * Create a PaymasterAdapter for use with TxBuilder.sendSponsored().
287
+ *
288
+ * @example
289
+ * ```typescript
290
+ * const sdk = new ChipiServerSDK({ apiPublicKey: "pk_...", apiSecretKey: "sk_..." });
291
+ * const paymaster = sdk.createPaymasterAdapter();
292
+ *
293
+ * const txHash = await new TxBuilder(account, { paymaster })
294
+ * .transfer(USDC, [{ to, amount }])
295
+ * .sendSponsored(); // gasless!
296
+ * ```
297
+ */
298
+ createPaymasterAdapter(bearerToken?: string): ChipiPaymasterAdapter;
299
+ /**
300
+ * Create an X402Facilitator for verifying and settling x402 payments.
301
+ *
302
+ * @example
303
+ * ```typescript
304
+ * const facilitator = sdk.createX402Facilitator();
305
+ *
306
+ * // With custom nonce store (Redis)
307
+ * const facilitator = sdk.createX402Facilitator(bearerToken, {
308
+ * nonceStore: {
309
+ * has: async (nonce) => (await redis.sismember("x402:nonces", nonce)) === 1,
310
+ * consume: async (nonce) => (await redis.sadd("x402:nonces", nonce)) === 1,
311
+ * },
312
+ * });
313
+ * ```
314
+ */
315
+ createX402Facilitator(bearerToken?: string, config?: X402FacilitatorConfig): X402Facilitator;
196
316
  /**
197
317
  * Execute a gasless transaction
198
318
  */
@@ -238,6 +358,27 @@ declare class ChipiSDK {
238
358
  params: ExecuteWithSessionParams;
239
359
  bearerToken?: string;
240
360
  }): Promise<string>;
361
+ /**
362
+ * Sign SNIP-12 typed data without executing a transaction.
363
+ *
364
+ * Purely local operation: decrypt private key → sign → return { r, s }.
365
+ * No API calls are made. Useful for x402 payment signatures and other
366
+ * off-chain signing flows.
367
+ *
368
+ * @example
369
+ * ```typescript
370
+ * const { r, s } = await sdk.signTypedData({
371
+ * params: {
372
+ * encryptKey: pin,
373
+ * wallet,
374
+ * typedData: snip12TypedData,
375
+ * },
376
+ * });
377
+ * ```
378
+ */
379
+ signTypedData({ params, }: {
380
+ params: SignTypedDataParams;
381
+ }): Promise<SignTypedDataResult>;
241
382
  /**
242
383
  * Transfer tokens
243
384
  */
@@ -286,6 +427,25 @@ declare class ChipiSDK {
286
427
  getSkuPurchase(id: string, bearerToken?: string): Promise<Transaction>;
287
428
  getSkuList(params: GetSkuListQuery, bearerToken?: string): Promise<PaginatedResponse<Sku>>;
288
429
  getSku(id: string, bearerToken?: string): Promise<Sku>;
430
+ /**
431
+ * Get a single transaction by hash or internal ID
432
+ */
433
+ getTransaction(hashOrId: string, bearerToken?: string): Promise<Transaction>;
434
+ /**
435
+ * Get on-chain transaction status (supports polling for confirmation)
436
+ */
437
+ getTransactionStatus(hash: string, bearerToken?: string): Promise<TransactionStatusResponse>;
438
+ /**
439
+ * Prepare a wallet upgrade (e.g., READY → CHIPI or CHIPI v29 → v33).
440
+ * Returns typed data that must be signed by the wallet owner.
441
+ * Server-only: requires API secret key.
442
+ */
443
+ prepareWalletUpgrade(params: PrepareWalletUpgradeParams, bearerToken?: string): Promise<PrepareWalletUpgradeResponse>;
444
+ /**
445
+ * Execute a wallet upgrade after signing.
446
+ * Server-only: requires API secret key.
447
+ */
448
+ executeWalletUpgrade(params: ExecuteWalletUpgradeParams, bearerToken?: string): Promise<ExecuteWalletUpgradeResponse>;
289
449
  getUsdAmount(currencyAmount: number, currency: Currency, bearerToken?: string): Promise<number>;
290
450
  }
291
451
 
@@ -362,7 +522,73 @@ declare class ChipiBrowserSDK extends ChipiSDK {
362
522
  constructor(config: ChipiBrowserSDKConfig);
363
523
  }
364
524
 
525
+ /**
526
+ * Sign SNIP-12 typed data without executing a transaction.
527
+ *
528
+ * This is a purely local operation:
529
+ * 1. Decrypt the private key using the encryption key (PIN)
530
+ * 2. Create a starknet Account
531
+ * 3. Sign the typed data with account.signMessage()
532
+ * 4. Normalize and return { r, s }
533
+ *
534
+ * No API calls are made. Useful for x402 payment signatures and other
535
+ * off-chain signing flows where you need a SNIP-12 signature but don't
536
+ * want to execute a transaction.
537
+ */
538
+ declare const signTypedData: ({ params, }: {
539
+ params: SignTypedDataParams;
540
+ }) => Promise<SignTypedDataResult>;
541
+
365
542
  declare const encryptPrivateKey: (privateKey: string, password: string) => string;
366
543
  declare const decryptPrivateKey: (encryptedPrivateKey: string, password: string) => string;
367
544
 
368
- export { ChipiBrowserSDK, ChipiClient, ChipiSDK, ChipiServerSDK, ChipiSessions, ChipiSkuPurchases, ChipiSkus, ChipiTransactions, ChipiWallets, decryptPrivateKey, encryptPrivateKey };
545
+ interface X402MiddlewareConfig {
546
+ /** x402 facilitator instance for verify + settle */
547
+ facilitator: X402Facilitator;
548
+ /** Payment configuration for this endpoint */
549
+ paymentConfig: X402PaymentConfig;
550
+ /** Verify-only mode: verify payment but don't settle (default: false) */
551
+ verifyOnly?: boolean;
552
+ }
553
+ /**
554
+ * Flat convenience config — detected when `amount` + `recipient` are present.
555
+ * Avoids nesting paymentConfig.
556
+ */
557
+ interface X402MiddlewareFlatConfig {
558
+ /** x402 facilitator instance */
559
+ facilitator: X402Facilitator;
560
+ /** Amount in human-readable USDC (e.g. "0.01") */
561
+ amount: string;
562
+ /** Recipient (merchant) address */
563
+ recipient: string;
564
+ /** Human-readable description */
565
+ description?: string;
566
+ /** Verify-only mode (default: false) */
567
+ verifyOnly?: boolean;
568
+ }
569
+ /**
570
+ * Express-compatible middleware for monetizing API endpoints with x402.
571
+ *
572
+ * When no X-PAYMENT header is present, returns 402 with payment requirement.
573
+ * When a valid payment is present, verifies and settles it, then calls next().
574
+ * The settled transaction info is attached to `req.x402`.
575
+ *
576
+ * @example
577
+ * ```typescript
578
+ * // Nested config (original)
579
+ * x402Middleware({
580
+ * facilitator,
581
+ * paymentConfig: { amount: "0.01", payTo: "0xYOUR_ADDRESS" },
582
+ * })
583
+ *
584
+ * // Flat config (convenience)
585
+ * x402Middleware({
586
+ * facilitator,
587
+ * amount: "0.01",
588
+ * recipient: "0xYOUR_ADDRESS",
589
+ * })
590
+ * ```
591
+ */
592
+ declare function x402Middleware(config: X402MiddlewareConfig | X402MiddlewareFlatConfig): (req: any, res: any, next: any) => Promise<any>;
593
+
594
+ export { ChipiBrowserSDK, ChipiClient, ChipiPaymasterAdapter, ChipiSDK, ChipiServerSDK, ChipiSessions, ChipiSkuPurchases, ChipiSkus, ChipiTransactions, ChipiWallets, X402Facilitator, type X402FacilitatorCreateOptions, type X402MiddlewareConfig, type X402MiddlewareFlatConfig, decryptPrivateKey, encryptPrivateKey, signTypedData, x402Middleware };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _chipi_stack_types from '@chipi-stack/types';
2
- import { CreateSessionKeyParams, SessionKeyData, AddSessionKeyParams, RevokeSessionKeyParams, GetSessionDataParams, SessionDataResponse, ExecuteWithSessionParams, Currency, ChipiSDKConfig, ExecuteTransactionParams, TransferParams, ApproveParams, CallAnyContractParams, CreateWalletParams, CreateWalletResponse, RecordSendTransactionParams, Transaction, GetTransactionListQuery, PaginatedResponse, GetWalletParams, GetTokenBalanceParams, GetTokenBalanceResponse, CreateSkuPurchaseParams, GetSkuListQuery, Sku, ChipiServerSDKConfig, ChipiBrowserSDKConfig } from '@chipi-stack/types';
2
+ import { CreateSessionKeyParams, SessionKeyData, AddSessionKeyParams, RevokeSessionKeyParams, GetSessionDataParams, SessionDataResponse, ExecuteWithSessionParams, Currency, PaymasterAdapter, PaymasterAccount, X402FacilitatorConfig, NonceStore, PaymentPayload, VerifyResponse, SettleResponse, ChipiSDKConfig, ExecuteTransactionParams, SignTypedDataParams, SignTypedDataResult, TransferParams, ApproveParams, CallAnyContractParams, CreateWalletParams, CreateWalletResponse, RecordSendTransactionParams, Transaction, GetTransactionListQuery, PaginatedResponse, GetWalletParams, GetTokenBalanceParams, GetTokenBalanceResponse, CreateSkuPurchaseParams, GetSkuListQuery, Sku, TransactionStatusResponse, PrepareWalletUpgradeParams, PrepareWalletUpgradeResponse, ExecuteWalletUpgradeParams, ExecuteWalletUpgradeResponse, ChipiServerSDKConfig, ChipiBrowserSDKConfig, X402PaymentConfig } from '@chipi-stack/types';
3
3
  export * from '@chipi-stack/types';
4
4
  export { Chain, ChainToken } from '@chipi-stack/types';
5
5
  import { ChipiWallets } from './wallets.js';
@@ -7,6 +7,7 @@ import { ChipiTransactions } from './transactions.js';
7
7
  import { ChipiSkuPurchases } from './skuPurchases.js';
8
8
  import { ChipiSkus } from './skus.js';
9
9
  import { C as ChipiClient } from './client-CqD_yGH0.js';
10
+ import { Call } from 'starknet';
10
11
 
11
12
  /**
12
13
  * Session key management for CHIPI wallets (SNIP-9 compatible).
@@ -175,6 +176,94 @@ declare class ChipiExchanges {
175
176
  getUsdAmount(currencyAmount: number, currency: Currency, bearerToken: string): Promise<number>;
176
177
  }
177
178
 
179
+ /**
180
+ * PaymasterAdapter implementation that uses Chipi's backend API for gasless transactions.
181
+ *
182
+ * Flow:
183
+ * 1. Detect wallet type from on-chain class hash
184
+ * 2. Call /transactions/prepare-typed-data to get TypedData
185
+ * 3. Call account.signMessage(typedData) — triggers wallet popup for external wallets
186
+ * 4. Call /transactions/execute-sponsored-transaction with signature
187
+ * 5. Return transaction hash
188
+ */
189
+ declare class ChipiPaymasterAdapter implements PaymasterAdapter {
190
+ private readonly client;
191
+ private readonly bearerToken;
192
+ constructor(client: ChipiClient, bearerToken: string);
193
+ execute({ account, calls }: {
194
+ account: PaymasterAccount;
195
+ calls: Call[];
196
+ }): Promise<string>;
197
+ }
198
+
199
+ /** Options for the static X402Facilitator.create() factory */
200
+ interface X402FacilitatorCreateOptions {
201
+ /** API public key for ChipiClient */
202
+ apiKey: string;
203
+ /** Bearer token for paymaster API calls */
204
+ bearerToken: string;
205
+ /** Custom nonce store (default: in-memory) */
206
+ nonceStore?: NonceStore;
207
+ /** RPC provider for on-chain signature verification */
208
+ provider?: X402FacilitatorConfig["provider"];
209
+ }
210
+ /**
211
+ * x402 Payment Facilitator for Starknet.
212
+ *
213
+ * Implements the "facilitator" role in the x402 protocol:
214
+ * - verify(): Validate payment signature, amount, asset, nonce replay
215
+ * - settle(): Execute the USDC transfer via Chipi's paymaster
216
+ *
217
+ * Settlement reuses Chipi's existing gasless infrastructure
218
+ * (prepare-typed-data → sign → execute-sponsored-transaction).
219
+ */
220
+ declare class X402Facilitator {
221
+ private readonly client;
222
+ private readonly bearerToken;
223
+ private readonly nonceStore;
224
+ private readonly provider;
225
+ constructor(client: ChipiClient, bearerToken: string, config?: X402FacilitatorConfig);
226
+ /**
227
+ * Factory method for simpler instantiation.
228
+ *
229
+ * @example
230
+ * ```typescript
231
+ * const facilitator = X402Facilitator.create({
232
+ * apiKey: process.env.CHIPI_API_KEY!,
233
+ * bearerToken: process.env.CHIPI_BEARER_TOKEN!,
234
+ * });
235
+ * ```
236
+ */
237
+ static create(options: X402FacilitatorCreateOptions): X402Facilitator;
238
+ /**
239
+ * Verify a payment signature is valid (doesn't execute the transfer).
240
+ *
241
+ * Checks:
242
+ * 1. Nonce has not been used (replay protection)
243
+ * 2. Payment has not expired (validUntil > now)
244
+ * 3. Asset is USDC mainnet
245
+ * 4. Amount is positive
246
+ * 5. Addresses are non-empty
247
+ */
248
+ verify(payment: PaymentPayload): Promise<VerifyResponse>;
249
+ /**
250
+ * Verify the SNIP-12 signature on a payment payload.
251
+ *
252
+ * If an RPC provider is configured, reconstructs the typed data, computes the
253
+ * message hash, and calls `is_valid_signature()` on the sender's account contract.
254
+ * Otherwise falls back to a presence-only check (backwards compatible).
255
+ */
256
+ private verifySignature;
257
+ /**
258
+ * Settle a verified payment by executing the USDC transfer via paymaster.
259
+ *
260
+ * IMPORTANT: Mark nonce as consumed BEFORE executing to prevent concurrent replays.
261
+ * If the transfer fails after nonce consumption, the nonce is still burned
262
+ * (caller should implement idempotency at a higher level if needed).
263
+ */
264
+ settle(payment: PaymentPayload): Promise<SettleResponse>;
265
+ }
266
+
178
267
  /**
179
268
  * Main Chipi SDK class
180
269
  */
@@ -193,6 +282,37 @@ declare class ChipiSDK {
193
282
  * Resolve bearer token - uses provided token or falls back to apiSecretKey
194
283
  */
195
284
  private resolveBearerToken;
285
+ /**
286
+ * Create a PaymasterAdapter for use with TxBuilder.sendSponsored().
287
+ *
288
+ * @example
289
+ * ```typescript
290
+ * const sdk = new ChipiServerSDK({ apiPublicKey: "pk_...", apiSecretKey: "sk_..." });
291
+ * const paymaster = sdk.createPaymasterAdapter();
292
+ *
293
+ * const txHash = await new TxBuilder(account, { paymaster })
294
+ * .transfer(USDC, [{ to, amount }])
295
+ * .sendSponsored(); // gasless!
296
+ * ```
297
+ */
298
+ createPaymasterAdapter(bearerToken?: string): ChipiPaymasterAdapter;
299
+ /**
300
+ * Create an X402Facilitator for verifying and settling x402 payments.
301
+ *
302
+ * @example
303
+ * ```typescript
304
+ * const facilitator = sdk.createX402Facilitator();
305
+ *
306
+ * // With custom nonce store (Redis)
307
+ * const facilitator = sdk.createX402Facilitator(bearerToken, {
308
+ * nonceStore: {
309
+ * has: async (nonce) => (await redis.sismember("x402:nonces", nonce)) === 1,
310
+ * consume: async (nonce) => (await redis.sadd("x402:nonces", nonce)) === 1,
311
+ * },
312
+ * });
313
+ * ```
314
+ */
315
+ createX402Facilitator(bearerToken?: string, config?: X402FacilitatorConfig): X402Facilitator;
196
316
  /**
197
317
  * Execute a gasless transaction
198
318
  */
@@ -238,6 +358,27 @@ declare class ChipiSDK {
238
358
  params: ExecuteWithSessionParams;
239
359
  bearerToken?: string;
240
360
  }): Promise<string>;
361
+ /**
362
+ * Sign SNIP-12 typed data without executing a transaction.
363
+ *
364
+ * Purely local operation: decrypt private key → sign → return { r, s }.
365
+ * No API calls are made. Useful for x402 payment signatures and other
366
+ * off-chain signing flows.
367
+ *
368
+ * @example
369
+ * ```typescript
370
+ * const { r, s } = await sdk.signTypedData({
371
+ * params: {
372
+ * encryptKey: pin,
373
+ * wallet,
374
+ * typedData: snip12TypedData,
375
+ * },
376
+ * });
377
+ * ```
378
+ */
379
+ signTypedData({ params, }: {
380
+ params: SignTypedDataParams;
381
+ }): Promise<SignTypedDataResult>;
241
382
  /**
242
383
  * Transfer tokens
243
384
  */
@@ -286,6 +427,25 @@ declare class ChipiSDK {
286
427
  getSkuPurchase(id: string, bearerToken?: string): Promise<Transaction>;
287
428
  getSkuList(params: GetSkuListQuery, bearerToken?: string): Promise<PaginatedResponse<Sku>>;
288
429
  getSku(id: string, bearerToken?: string): Promise<Sku>;
430
+ /**
431
+ * Get a single transaction by hash or internal ID
432
+ */
433
+ getTransaction(hashOrId: string, bearerToken?: string): Promise<Transaction>;
434
+ /**
435
+ * Get on-chain transaction status (supports polling for confirmation)
436
+ */
437
+ getTransactionStatus(hash: string, bearerToken?: string): Promise<TransactionStatusResponse>;
438
+ /**
439
+ * Prepare a wallet upgrade (e.g., READY → CHIPI or CHIPI v29 → v33).
440
+ * Returns typed data that must be signed by the wallet owner.
441
+ * Server-only: requires API secret key.
442
+ */
443
+ prepareWalletUpgrade(params: PrepareWalletUpgradeParams, bearerToken?: string): Promise<PrepareWalletUpgradeResponse>;
444
+ /**
445
+ * Execute a wallet upgrade after signing.
446
+ * Server-only: requires API secret key.
447
+ */
448
+ executeWalletUpgrade(params: ExecuteWalletUpgradeParams, bearerToken?: string): Promise<ExecuteWalletUpgradeResponse>;
289
449
  getUsdAmount(currencyAmount: number, currency: Currency, bearerToken?: string): Promise<number>;
290
450
  }
291
451
 
@@ -362,7 +522,73 @@ declare class ChipiBrowserSDK extends ChipiSDK {
362
522
  constructor(config: ChipiBrowserSDKConfig);
363
523
  }
364
524
 
525
+ /**
526
+ * Sign SNIP-12 typed data without executing a transaction.
527
+ *
528
+ * This is a purely local operation:
529
+ * 1. Decrypt the private key using the encryption key (PIN)
530
+ * 2. Create a starknet Account
531
+ * 3. Sign the typed data with account.signMessage()
532
+ * 4. Normalize and return { r, s }
533
+ *
534
+ * No API calls are made. Useful for x402 payment signatures and other
535
+ * off-chain signing flows where you need a SNIP-12 signature but don't
536
+ * want to execute a transaction.
537
+ */
538
+ declare const signTypedData: ({ params, }: {
539
+ params: SignTypedDataParams;
540
+ }) => Promise<SignTypedDataResult>;
541
+
365
542
  declare const encryptPrivateKey: (privateKey: string, password: string) => string;
366
543
  declare const decryptPrivateKey: (encryptedPrivateKey: string, password: string) => string;
367
544
 
368
- export { ChipiBrowserSDK, ChipiClient, ChipiSDK, ChipiServerSDK, ChipiSessions, ChipiSkuPurchases, ChipiSkus, ChipiTransactions, ChipiWallets, decryptPrivateKey, encryptPrivateKey };
545
+ interface X402MiddlewareConfig {
546
+ /** x402 facilitator instance for verify + settle */
547
+ facilitator: X402Facilitator;
548
+ /** Payment configuration for this endpoint */
549
+ paymentConfig: X402PaymentConfig;
550
+ /** Verify-only mode: verify payment but don't settle (default: false) */
551
+ verifyOnly?: boolean;
552
+ }
553
+ /**
554
+ * Flat convenience config — detected when `amount` + `recipient` are present.
555
+ * Avoids nesting paymentConfig.
556
+ */
557
+ interface X402MiddlewareFlatConfig {
558
+ /** x402 facilitator instance */
559
+ facilitator: X402Facilitator;
560
+ /** Amount in human-readable USDC (e.g. "0.01") */
561
+ amount: string;
562
+ /** Recipient (merchant) address */
563
+ recipient: string;
564
+ /** Human-readable description */
565
+ description?: string;
566
+ /** Verify-only mode (default: false) */
567
+ verifyOnly?: boolean;
568
+ }
569
+ /**
570
+ * Express-compatible middleware for monetizing API endpoints with x402.
571
+ *
572
+ * When no X-PAYMENT header is present, returns 402 with payment requirement.
573
+ * When a valid payment is present, verifies and settles it, then calls next().
574
+ * The settled transaction info is attached to `req.x402`.
575
+ *
576
+ * @example
577
+ * ```typescript
578
+ * // Nested config (original)
579
+ * x402Middleware({
580
+ * facilitator,
581
+ * paymentConfig: { amount: "0.01", payTo: "0xYOUR_ADDRESS" },
582
+ * })
583
+ *
584
+ * // Flat config (convenience)
585
+ * x402Middleware({
586
+ * facilitator,
587
+ * amount: "0.01",
588
+ * recipient: "0xYOUR_ADDRESS",
589
+ * })
590
+ * ```
591
+ */
592
+ declare function x402Middleware(config: X402MiddlewareConfig | X402MiddlewareFlatConfig): (req: any, res: any, next: any) => Promise<any>;
593
+
594
+ export { ChipiBrowserSDK, ChipiClient, ChipiPaymasterAdapter, ChipiSDK, ChipiServerSDK, ChipiSessions, ChipiSkuPurchases, ChipiSkus, ChipiTransactions, ChipiWallets, X402Facilitator, type X402FacilitatorCreateOptions, type X402MiddlewareConfig, type X402MiddlewareFlatConfig, decryptPrivateKey, encryptPrivateKey, signTypedData, x402Middleware };