@chipi-stack/backend 14.13.1 → 14.15.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/{client-CqD_yGH0.d.mts → client-D6SDBu5p.d.mts} +3 -1
- package/dist/{client-CqD_yGH0.d.ts → client-D6SDBu5p.d.ts} +3 -1
- package/dist/index.d.mts +277 -9
- package/dist/index.d.ts +277 -9
- package/dist/index.js +594 -147
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +586 -149
- package/dist/index.mjs.map +1 -1
- package/dist/skuPurchases.d.mts +1 -1
- package/dist/skuPurchases.d.ts +1 -1
- package/dist/skuPurchases.js +1 -1
- package/dist/skuPurchases.js.map +1 -1
- package/dist/skuPurchases.mjs +1 -1
- package/dist/skuPurchases.mjs.map +1 -1
- package/dist/skus.d.mts +1 -1
- package/dist/skus.d.ts +1 -1
- package/dist/transactions.d.mts +2 -2
- package/dist/transactions.d.ts +2 -2
- package/dist/transactions.js +1 -1
- package/dist/transactions.js.map +1 -1
- package/dist/transactions.mjs +1 -1
- package/dist/transactions.mjs.map +1 -1
- package/dist/{wallets-DxKnh21Q.d.ts → wallets-C541u9mn.d.ts} +1 -1
- package/dist/{wallets-CYCLyyXY.d.mts → wallets-CX42j3eN.d.mts} +1 -1
- package/dist/wallets.d.mts +2 -2
- package/dist/wallets.d.ts +2 -2
- package/package.json +3 -3
|
@@ -26,10 +26,12 @@ declare class ChipiClient {
|
|
|
26
26
|
params?: Record<string, any>;
|
|
27
27
|
bearerToken?: string;
|
|
28
28
|
}): Promise<T>;
|
|
29
|
-
post<T>({ endpoint, bearerToken, body, }: {
|
|
29
|
+
post<T>({ endpoint, bearerToken, body, headers, }: {
|
|
30
30
|
endpoint: string;
|
|
31
31
|
bearerToken: string;
|
|
32
32
|
body?: Record<string, any>;
|
|
33
|
+
/** Extra request headers, e.g. `X-PAYMENT`. Cannot override auth or content type. */
|
|
34
|
+
headers?: Record<string, string>;
|
|
33
35
|
}): Promise<T>;
|
|
34
36
|
put<T>({ endpoint, bearerToken, body, }: {
|
|
35
37
|
endpoint: string;
|
|
@@ -26,10 +26,12 @@ declare class ChipiClient {
|
|
|
26
26
|
params?: Record<string, any>;
|
|
27
27
|
bearerToken?: string;
|
|
28
28
|
}): Promise<T>;
|
|
29
|
-
post<T>({ endpoint, bearerToken, body, }: {
|
|
29
|
+
post<T>({ endpoint, bearerToken, body, headers, }: {
|
|
30
30
|
endpoint: string;
|
|
31
31
|
bearerToken: string;
|
|
32
32
|
body?: Record<string, any>;
|
|
33
|
+
/** Extra request headers, e.g. `X-PAYMENT`. Cannot override auth or content type. */
|
|
34
|
+
headers?: Record<string, string>;
|
|
33
35
|
}): Promise<T>;
|
|
34
36
|
put<T>({ endpoint, bearerToken, body, }: {
|
|
35
37
|
endpoint: string;
|
package/dist/index.d.mts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import * as _chipi_stack_types from '@chipi-stack/types';
|
|
2
|
-
import { CreateSessionKeyParams, SessionKeyData, AddSessionKeyParams, RevokeSessionKeyParams, GetSessionDataParams, SessionDataResponse, ExecuteWithSessionParams, SetSpendingPolicyParams, GetSpendingPolicyParams, SpendingPolicyData, RemoveSpendingPolicyParams, 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, X402ClientConfig, PaymentRequirement, X402PaymentConfig, ShhhSignerKind } from '@chipi-stack/types';
|
|
2
|
+
import { CreateSessionKeyParams, SessionKeyData, AddSessionKeyParams, SetupSessionParams, RevokeSessionKeyParams, GetSessionDataParams, SessionDataResponse, ExecuteWithSessionParams, SetSpendingPolicyParams, GetSpendingPolicyParams, SpendingPolicyData, RemoveSpendingPolicyParams, Currency, AiSignalsParams, AiSignals, ThinkParams, ThinkOptions, ThinkResponse, AiExecuteParams, AiExecuteResponse, AiChatParams, AiChatResponse, AiPricesParams, AiPrices, AiModelsResponse, ThinkDecision, 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, SessionConfig, Call as Call$1, SpendingPolicyConfig, X402ClientConfig, PaymentRequirement, X402PaymentConfig, ShhhSignerKind } from '@chipi-stack/types';
|
|
3
3
|
export * from '@chipi-stack/types';
|
|
4
4
|
export { Chain, ChainToken, Currency } from '@chipi-stack/types';
|
|
5
|
-
import { C as ChipiWallets } from './wallets-
|
|
6
|
-
export { E as ExecuteMigrateResponse, M as MigrateChipiWalletToShhhParams, a as MigrationOutcome, P as PrepareMigrateResponse, m as migrateChipiWalletToShhh } from './wallets-
|
|
5
|
+
import { C as ChipiWallets } from './wallets-CX42j3eN.mjs';
|
|
6
|
+
export { E as ExecuteMigrateResponse, M as MigrateChipiWalletToShhhParams, a as MigrationOutcome, P as PrepareMigrateResponse, m as migrateChipiWalletToShhh } from './wallets-CX42j3eN.mjs';
|
|
7
7
|
import { ChipiTransactions } from './transactions.mjs';
|
|
8
8
|
import { ChipiSkuPurchases } from './skuPurchases.mjs';
|
|
9
9
|
import { ChipiSkus } from './skus.mjs';
|
|
10
|
-
import { C as ChipiClient } from './client-
|
|
10
|
+
import { C as ChipiClient } from './client-D6SDBu5p.mjs';
|
|
11
11
|
import { Call, ProviderInterface, Account } from 'starknet';
|
|
12
12
|
|
|
13
13
|
/**
|
|
@@ -101,6 +101,31 @@ declare class ChipiSessions {
|
|
|
101
101
|
* ```
|
|
102
102
|
*/
|
|
103
103
|
addSessionKeyToContract(params: AddSessionKeyParams, bearerToken: string): Promise<string>;
|
|
104
|
+
/**
|
|
105
|
+
* Register a session and its spending policies in ONE owner-signed transaction.
|
|
106
|
+
*
|
|
107
|
+
* Equivalent to `addSessionKeyToContract` followed by one `setSpendingPolicy`
|
|
108
|
+
* per token, but the owner signs once (one passkey prompt) and the session
|
|
109
|
+
* never exists on-chain without its caps.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* const txHash = await sdk.sessions.setupSession({
|
|
114
|
+
* encryptKey,
|
|
115
|
+
* wallet,
|
|
116
|
+
* sessionConfig: {
|
|
117
|
+
* sessionPublicKey: session.publicKey,
|
|
118
|
+
* validUntil: session.validUntil,
|
|
119
|
+
* maxCalls: 500,
|
|
120
|
+
* allowedEntrypoints: ["transfer", "approve"],
|
|
121
|
+
* },
|
|
122
|
+
* spendingPolicies: [
|
|
123
|
+
* { token: USDC, maxPerCall: 5_000_000n, maxPerWindow: 20_000_000n, windowSeconds: 86400 },
|
|
124
|
+
* ],
|
|
125
|
+
* }, bearerToken);
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
setupSession(params: SetupSessionParams, bearerToken: string): Promise<string>;
|
|
104
129
|
/**
|
|
105
130
|
* Revoke a session key from the smart contract.
|
|
106
131
|
*
|
|
@@ -192,10 +217,6 @@ declare class ChipiSessions {
|
|
|
192
217
|
* ```
|
|
193
218
|
*/
|
|
194
219
|
executeTransactionWithSession(params: ExecuteWithSessionParams, bearerToken: string): Promise<string>;
|
|
195
|
-
/**
|
|
196
|
-
* Split a bigint into Cairo u256 representation (low u128, high u128).
|
|
197
|
-
*/
|
|
198
|
-
private splitU256;
|
|
199
220
|
/**
|
|
200
221
|
* Reconstruct a bigint from Cairo u256 (low, high) hex strings.
|
|
201
222
|
*/
|
|
@@ -564,6 +585,109 @@ declare class ChipiTreasury {
|
|
|
564
585
|
forTreasury(config: ForTreasuryConfig): TreasuryTransport;
|
|
565
586
|
}
|
|
566
587
|
|
|
588
|
+
/**
|
|
589
|
+
* Whether `/v1/ai/think` returned a structured decision you can act on.
|
|
590
|
+
*
|
|
591
|
+
* `false` for a non-JSON reply (`{ raw }`) and for any `action` outside
|
|
592
|
+
* `swap | supply | withdraw | hold`. Treat `false` as `hold`. This checks the
|
|
593
|
+
* shape only: the amounts and tokens are still yours to validate.
|
|
594
|
+
*/
|
|
595
|
+
declare function isThinkDecision(decision: unknown): decision is ThinkDecision;
|
|
596
|
+
/**
|
|
597
|
+
* Chipi AI API: prices, market signals, a DeFi decision engine, swap call
|
|
598
|
+
* building and general chat, billed to your organization's credits.
|
|
599
|
+
*
|
|
600
|
+
* Server-only. Every method authenticates with the SDK's secret key (`sk_`)
|
|
601
|
+
* and refuses to run without one, so a public key in the browser can never
|
|
602
|
+
* spend your credits through this client.
|
|
603
|
+
*
|
|
604
|
+
* Errors come back as `ChipiApiError` with the API's code and HTTP status:
|
|
605
|
+
* `INSUFFICIENT_BALANCE` (402) when credits run out, `MODEL_RATE_LIMITED`
|
|
606
|
+
* (429), `SIGNALS_UNAVAILABLE` (503) while signals warm up after a backend restart.
|
|
607
|
+
*
|
|
608
|
+
* @example
|
|
609
|
+
* ```typescript
|
|
610
|
+
* const sdk = new ChipiServerSDK({ apiPublicKey, apiSecretKey });
|
|
611
|
+
*
|
|
612
|
+
* const signals = await sdk.ai.signals({ tokens: ["ETH", "STRK"] });
|
|
613
|
+
* const { decision } = await sdk.ai.think({ portfolio, riskScore: 4 });
|
|
614
|
+
* if (isThinkDecision(decision) && decision.action === "swap") {
|
|
615
|
+
* const { calls } = await sdk.ai.execute({
|
|
616
|
+
* chain: "starknet",
|
|
617
|
+
* action: "swap",
|
|
618
|
+
* from: decision.from!,
|
|
619
|
+
* to: decision.to!,
|
|
620
|
+
* amountUsd: 10,
|
|
621
|
+
* walletAddress,
|
|
622
|
+
* });
|
|
623
|
+
* }
|
|
624
|
+
* ```
|
|
625
|
+
*/
|
|
626
|
+
declare class ChipiAi {
|
|
627
|
+
private client;
|
|
628
|
+
private apiSecretKey?;
|
|
629
|
+
/** Needed only to pay think calls with `payWithSession`. */
|
|
630
|
+
private sessions?;
|
|
631
|
+
constructor(client: ChipiClient, apiSecretKey?: string | undefined,
|
|
632
|
+
/** Needed only to pay think calls with `payWithSession`. */
|
|
633
|
+
sessions?: ChipiSessions | undefined);
|
|
634
|
+
private secret;
|
|
635
|
+
/**
|
|
636
|
+
* `GET /v1/ai/signals`: technical signals per token, market sentiment and
|
|
637
|
+
* DeFi yields. Free up to a monthly quota per organization, then billed per call.
|
|
638
|
+
*/
|
|
639
|
+
signals(params?: AiSignalsParams): Promise<AiSignals>;
|
|
640
|
+
/**
|
|
641
|
+
* `POST /v1/ai/think`: one DeFi decision for a portfolio, with the latest
|
|
642
|
+
* signals and your risk parameters injected into the prompt.
|
|
643
|
+
*
|
|
644
|
+
* The decision is advice, not an order: check it with `isThinkDecision` and
|
|
645
|
+
* enforce your own limits before executing anything.
|
|
646
|
+
*
|
|
647
|
+
* **Paying per call (x402).** With `payWithSession`, a 402 that carries a
|
|
648
|
+
* session-transfer offer (credits short, x402 on) is paid with the agent's
|
|
649
|
+
* session key: a USDC `transfer` to the offer's `payTo`, then the same call
|
|
650
|
+
* again with `X-PAYMENT`. The price must be at most `maxAmount`, `model`
|
|
651
|
+
* must be payable and the input within `maxPromptBytes`, all checked before
|
|
652
|
+
* paying. The session must whitelist `transfer` and cap USDC. A payment
|
|
653
|
+
* that was made but not served is reported in `error.details.xPayment`;
|
|
654
|
+
* pass it back as `options.xPayment` to retry without paying again.
|
|
655
|
+
*
|
|
656
|
+
* @example
|
|
657
|
+
* ```typescript
|
|
658
|
+
* const res = await sdk.ai.think(
|
|
659
|
+
* { portfolio, model: "haiku" },
|
|
660
|
+
* { payWithSession: { encryptKey, wallet, session, maxAmount: 20_000n } } // $0.02 at most
|
|
661
|
+
* );
|
|
662
|
+
* res.x402Payment; // set when the call was paid over x402
|
|
663
|
+
* ```
|
|
664
|
+
*/
|
|
665
|
+
think(params: ThinkParams, options?: ThinkOptions): Promise<ThinkResponse>;
|
|
666
|
+
private postThink;
|
|
667
|
+
/**
|
|
668
|
+
* Pay one think call with a session-key USDC transfer, then send it again
|
|
669
|
+
* with `X-PAYMENT`. Every check that can refuse the call runs before the
|
|
670
|
+
* transfer; the transfer counts only once its receipt shows the USDC moved.
|
|
671
|
+
*/
|
|
672
|
+
private payAndThink;
|
|
673
|
+
/**
|
|
674
|
+
* `POST /v1/ai/execute`: unsigned AVNU swap calls (approve + swap) for
|
|
675
|
+
* `walletAddress`. Nothing is submitted; sign the calls with a session key
|
|
676
|
+
* or the owner's key.
|
|
677
|
+
*/
|
|
678
|
+
execute(params: AiExecuteParams): Promise<AiExecuteResponse>;
|
|
679
|
+
/** `POST /v1/ai/chat`: general-purpose chat, billed per token. */
|
|
680
|
+
chat(params: AiChatParams): Promise<AiChatResponse>;
|
|
681
|
+
/**
|
|
682
|
+
* `GET /v1/ai/prices`: USD prices and 1h / 24h / 7d changes, refreshed about
|
|
683
|
+
* every 30 seconds. No credits are charged, but like every `sdk.ai` method it
|
|
684
|
+
* needs the SDK's secret key (`sk_`).
|
|
685
|
+
*/
|
|
686
|
+
prices(params?: AiPricesParams): Promise<AiPrices>;
|
|
687
|
+
/** `GET /v1/ai/models`: available models, prices and limits. */
|
|
688
|
+
models(): Promise<AiModelsResponse>;
|
|
689
|
+
}
|
|
690
|
+
|
|
567
691
|
/**
|
|
568
692
|
* PaymasterAdapter implementation that uses Chipi's backend API for gasless transactions.
|
|
569
693
|
*
|
|
@@ -666,6 +790,8 @@ declare class ChipiSDK {
|
|
|
666
790
|
readonly sessions: ChipiSessions;
|
|
667
791
|
readonly exchanges: ChipiExchanges;
|
|
668
792
|
readonly treasury: ChipiTreasury;
|
|
793
|
+
/** AI API (`/v1/ai/*`). Server-only: needs `apiSecretKey` (`sk_`). */
|
|
794
|
+
readonly ai: ChipiAi;
|
|
669
795
|
constructor(config: ChipiSDKConfig);
|
|
670
796
|
/**
|
|
671
797
|
* Resolve bearer token - uses provided token or falls back to apiSecretKey
|
|
@@ -953,6 +1079,47 @@ declare const signTypedDataArray: ({ params, }: {
|
|
|
953
1079
|
params: SignTypedDataParams;
|
|
954
1080
|
}) => Promise<string[]>;
|
|
955
1081
|
|
|
1082
|
+
/** `add_or_update_session_key(session_key, valid_until, max_calls, allowed_entrypoints)` */
|
|
1083
|
+
declare function buildAddSessionKeyCall(walletAddress: string, sessionConfig: SessionConfig): Call$1;
|
|
1084
|
+
/** `revoke_session_key(session_key)` */
|
|
1085
|
+
declare function buildRevokeSessionKeyCall(walletAddress: string, sessionPublicKey: string): Call$1;
|
|
1086
|
+
/**
|
|
1087
|
+
* Validate a spending policy the way the contract interprets it.
|
|
1088
|
+
* Throws `INVALID_SPENDING_POLICY`.
|
|
1089
|
+
*/
|
|
1090
|
+
declare function validateSpendingPolicyConfig(config: SpendingPolicyConfig): void;
|
|
1091
|
+
/**
|
|
1092
|
+
* `set_spending_policy(session_key, token, max_per_call: u256, max_per_window: u256, window_seconds: u64)`
|
|
1093
|
+
*
|
|
1094
|
+
* Contract semantics worth knowing: `maxPerWindow = 0` disables the policy
|
|
1095
|
+
* (unlimited), `maxPerCall = 0` with a window blocks every metered spend, and
|
|
1096
|
+
* only `transfer` / `approve` / `increase_allowance` are metered.
|
|
1097
|
+
*/
|
|
1098
|
+
declare function buildSetSpendingPolicyCall(walletAddress: string, config: SpendingPolicyConfig): Call$1;
|
|
1099
|
+
/** `remove_spending_policy(session_key, token)` */
|
|
1100
|
+
declare function buildRemoveSpendingPolicyCall(walletAddress: string, sessionPublicKey: string, token: string): Call$1;
|
|
1101
|
+
/**
|
|
1102
|
+
* Register a session and cap it per token in one multicall: the session is
|
|
1103
|
+
* added first, then one `set_spending_policy` per entry. Each policy's
|
|
1104
|
+
* `sessionPublicKey` must match the session being registered.
|
|
1105
|
+
*/
|
|
1106
|
+
declare function buildSessionSetupCalls(walletAddress: string, sessionConfig: SessionConfig, spendingPolicies?: ReadonlyArray<Omit<SpendingPolicyConfig, "sessionPublicKey">>): Call$1[];
|
|
1107
|
+
|
|
1108
|
+
/**
|
|
1109
|
+
* Normalize a session whitelist to the hex selectors the contract compares against.
|
|
1110
|
+
*
|
|
1111
|
+
* `add_or_update_session_key` stores raw felts and the account matches them
|
|
1112
|
+
* against `call.selector`, so every entry must be a selector. Names were
|
|
1113
|
+
* previously forwarded unchanged: on CHIPI the paymaster encoded `"transfer"`
|
|
1114
|
+
* as a short string (registration succeeded, every session call then failed the
|
|
1115
|
+
* whitelist); on SHHH `BigInt("transfer")` threw while serialising calldata.
|
|
1116
|
+
*
|
|
1117
|
+
* - `0x…` hex and decimal felts pass through (as hex).
|
|
1118
|
+
* - Cairo identifiers (`"transfer"`, `"multi_route_swap"`) become their selector.
|
|
1119
|
+
* - Anything else throws `SESSION_ENTRYPOINT_NOT_ALLOWED`.
|
|
1120
|
+
*/
|
|
1121
|
+
declare function normalizeEntrypoints(entrypoints: readonly string[]): string[];
|
|
1122
|
+
|
|
956
1123
|
/**
|
|
957
1124
|
* Wait for a Starknet transaction and report what happened, without throwing
|
|
958
1125
|
* on an on-chain revert.
|
|
@@ -1200,6 +1367,107 @@ interface X402MiddlewareFlatConfig {
|
|
|
1200
1367
|
*/
|
|
1201
1368
|
declare function x402Middleware(config: X402MiddlewareConfig | X402MiddlewareFlatConfig): (req: any, res: any, next: any) => Promise<any>;
|
|
1202
1369
|
|
|
1370
|
+
/**
|
|
1371
|
+
* Remembers which transaction hashes already paid for something.
|
|
1372
|
+
*
|
|
1373
|
+
* `consume` must be atomic: return `true` the first time a hash is seen and
|
|
1374
|
+
* `false` on every later call, also across concurrent requests. Back it with a
|
|
1375
|
+
* unique index in your database (`INSERT ... ON CONFLICT DO NOTHING`) in
|
|
1376
|
+
* production; the default in-memory store forgets everything on restart and is
|
|
1377
|
+
* not shared between instances.
|
|
1378
|
+
*/
|
|
1379
|
+
interface TxHashStore {
|
|
1380
|
+
/**
|
|
1381
|
+
* `transactionHash` arrives normalised: lowercase `0x` hex without leading
|
|
1382
|
+
* zeros, so `0x0abc` and `0x000…abc` are the same key. Pad it yourself if you
|
|
1383
|
+
* compare it with RPC output.
|
|
1384
|
+
*/
|
|
1385
|
+
consume(transactionHash: string): boolean | Promise<boolean>;
|
|
1386
|
+
}
|
|
1387
|
+
interface SessionTxVerifierConfig extends WaitForTransactionOptions {
|
|
1388
|
+
/** Default: in memory (single process, lost on restart). */
|
|
1389
|
+
txHashStore?: TxHashStore;
|
|
1390
|
+
/** Receipt source. Default: `waitForTransaction` with the options above. */
|
|
1391
|
+
getReceipt?: (transactionHash: string, options: WaitForTransactionOptions) => Promise<WaitForTransactionResult>;
|
|
1392
|
+
}
|
|
1393
|
+
interface VerifyTransferParams {
|
|
1394
|
+
/** The hash the payer sent you, e.g. from `executeTransactionWithSession`. */
|
|
1395
|
+
transactionHash: string;
|
|
1396
|
+
/** ERC-20 contract, e.g. USDC. */
|
|
1397
|
+
token: string;
|
|
1398
|
+
/** The paying wallet. */
|
|
1399
|
+
from: string;
|
|
1400
|
+
/** Your receiving address. */
|
|
1401
|
+
to: string;
|
|
1402
|
+
/** Smallest acceptable amount, in the token's base units. */
|
|
1403
|
+
minAmount: bigint;
|
|
1404
|
+
}
|
|
1405
|
+
type VerifyTransferFailure =
|
|
1406
|
+
/** The transaction reverted on chain. */
|
|
1407
|
+
"REVERTED"
|
|
1408
|
+
/** No `Transfer` from `token` with this `from` and `to`. */
|
|
1409
|
+
| "TRANSFER_NOT_FOUND"
|
|
1410
|
+
/** A matching `Transfer` exists but moved less than `minAmount`. */
|
|
1411
|
+
| "AMOUNT_TOO_LOW"
|
|
1412
|
+
/** This hash already paid for something (replay). */
|
|
1413
|
+
| "ALREADY_USED";
|
|
1414
|
+
type VerifyTransferResult = {
|
|
1415
|
+
valid: true;
|
|
1416
|
+
transactionHash: string;
|
|
1417
|
+
amount: bigint;
|
|
1418
|
+
blockNumber?: number;
|
|
1419
|
+
} | {
|
|
1420
|
+
valid: false;
|
|
1421
|
+
transactionHash: string;
|
|
1422
|
+
reason: VerifyTransferFailure;
|
|
1423
|
+
detail?: string;
|
|
1424
|
+
};
|
|
1425
|
+
/**
|
|
1426
|
+
* Check on chain that a transaction paid you, and that it pays only once.
|
|
1427
|
+
*
|
|
1428
|
+
* Use it when a client pays by sending the transfer itself (for example an
|
|
1429
|
+
* agent with a session key calling `executeTransactionWithSession`) and hands
|
|
1430
|
+
* you the hash. A transaction hash, or a `SUCCESS` status from an API, is not
|
|
1431
|
+
* proof of payment: the transfer may have reverted, gone elsewhere, moved less,
|
|
1432
|
+
* or already been used for an earlier request. This reads the receipt and
|
|
1433
|
+
* accepts only a successful transaction whose `Transfer` event from `token`
|
|
1434
|
+
* moves at least `minAmount` from `from` to `to`, then consumes the hash.
|
|
1435
|
+
*
|
|
1436
|
+
* Opt-in and independent of `X402Facilitator`, whose behaviour is unchanged.
|
|
1437
|
+
*
|
|
1438
|
+
* **Who is `from`.** Transaction hashes and `Transfer` events are public. If
|
|
1439
|
+
* `from` comes from the request, anyone watching your address can submit a
|
|
1440
|
+
* payer's hash first and consume it: they get the service, the payer gets
|
|
1441
|
+
* `ALREADY_USED`. Take `from` from the caller's authenticated identity (your
|
|
1442
|
+
* session, an API key bound to a wallet) whenever you have one. For anonymous
|
|
1443
|
+
* payers this is first-come-first-served; keep it to low-value calls.
|
|
1444
|
+
*
|
|
1445
|
+
* `verifyTransfer` waits for the transaction to be sequenced and throws only
|
|
1446
|
+
* when it cannot tell (timeout, RPC failure): retry those. Every other outcome
|
|
1447
|
+
* is a result.
|
|
1448
|
+
*
|
|
1449
|
+
* @example
|
|
1450
|
+
* ```typescript
|
|
1451
|
+
* const verifier = new SessionTxVerifier({ txHashStore: dbStore });
|
|
1452
|
+
*
|
|
1453
|
+
* const result = await verifier.verifyTransfer({
|
|
1454
|
+
* transactionHash,
|
|
1455
|
+
* token: USDC,
|
|
1456
|
+
* from: agentWallet,
|
|
1457
|
+
* to: TREASURY,
|
|
1458
|
+
* minAmount: 1_000n, // $0.001 in USDC base units
|
|
1459
|
+
* });
|
|
1460
|
+
* if (!result.valid) return new Response(result.reason, { status: 402 });
|
|
1461
|
+
* ```
|
|
1462
|
+
*/
|
|
1463
|
+
declare class SessionTxVerifier {
|
|
1464
|
+
private readonly store;
|
|
1465
|
+
private readonly getReceipt;
|
|
1466
|
+
private readonly receiptOptions;
|
|
1467
|
+
constructor(config?: SessionTxVerifierConfig);
|
|
1468
|
+
verifyTransfer(params: VerifyTransferParams): Promise<VerifyTransferResult>;
|
|
1469
|
+
}
|
|
1470
|
+
|
|
1203
1471
|
/**
|
|
1204
1472
|
* SNIP-12 typed-data hash for `OutsideExecution` — TypeScript reference.
|
|
1205
1473
|
*
|
|
@@ -2777,4 +3045,4 @@ declare class ShhhAccount {
|
|
|
2777
3045
|
*/
|
|
2778
3046
|
declare function submitViaAccount(funded: Account): ShhhSubmit;
|
|
2779
3047
|
|
|
2780
|
-
export { ANY_CALLER_FELT, APPLE_ISSUER, type AppleTokenResponse, type ApproveBody, BOOTSTRAP_DOMAIN_SEPARATOR, type BootstrapMessageParams, type BuildBootstrapSignedCallParams, type BuildMigrationCallsParams, ChipiBrowserSDK, ChipiClient, ChipiPaymasterAdapter, ChipiSDK, ChipiServerSDK, ChipiSessions, ChipiSkuPurchases, ChipiSkus, ChipiTransactions, ChipiTreasury, ChipiWallets, type ComputeAddressInput, type ContractEventLog, DEFAULT_OP_EXPIRY_SECONDS, type Eip191Pubkey, type ExecuteResult, type ForTreasuryConfig, ISIGNER_CANONICAL_LABEL, ISIGNER_ID, ISRC9_V2_ID, type JwtAppleSubPubkey, type ListTreasuriesOptions, type ListTreasuriesResult, MAX_OE_VALIDITY_WINDOW_SECONDS, MIN_THRESHOLD_OWNERS, type MultisigAllowance, type NewOwnerInput, OE_DOMAIN_NAME, OE_DOMAIN_REVISION, OE_DOMAIN_VERSION, OP_ADD_OWNER, OP_REMOVE_OWNER, OP_ROTATE_OWNER, OP_SET_THRESHOLD, type OutsideExecution, type OwnerRole, type ProposeBody, ROLE_GUARDIAN, ROLE_OWNER, SIG_VERSION_V1_HEX_ASCII, SIG_VERSION_V2_SNIP12, SIG_VERSION_V2_THRESHOLD, STARKNET_MESSAGE_PREFIX, type SetTreasuryPolicyOptions, ShhhAccount, type ShhhAccountOptions, type ShhhExecuteOptions, type ShhhSignedExecution, type ShhhSubmit, type ShhhX402Wallet, TIMELOCK_SECONDS, type TreasuryPolicy, type TreasuryProposal, type TreasuryProposalSignature, type TreasurySummary, type TreasuryTransport, VIEW_SELECTORS, type WaitForTransactionOptions, type WaitForTransactionResult, type WebAuthnPubkey, X402Facilitator, type X402FacilitatorCreateOptions, type X402MiddlewareConfig, type X402MiddlewareFlatConfig, X402ShhhClient, type X402ShhhClientConfig, assertValidV2Snip12Envelope, buildBootstrapSignedCall, buildCancelPendingOpCall, buildCancelRecoveryCall, buildEd25519Envelope, buildEd25519EnvelopeFromSignature, buildEip191EnvelopeFromPrivateKey, buildEip191EnvelopeFromSignature, buildExecuteAddOwnerCall, buildExecuteRemoveOwnerCall, buildExecuteRotateOwnerCall, buildExecuteSetThresholdCall, buildFinalizeRecoveryCall, buildInitiateRecoveryCall, buildJwtAppleSubEnvelopeFromTestKey, buildJwtAppleSubEnvelopeFromTokenResponse, buildMigrationCalls, buildOutsideExecution, buildProposeAddOwnerCall, buildProposeRemoveOwnerCall, buildProposeRotateOwnerCall, buildProposeSetThresholdCall, buildStarkEnvelope, buildThresholdEnvelope, buildWebAuthnEnvelopeFromAssertion, buildWebAuthnEnvelopeFromPrivateKey, byteArrayToFelts, computeAddressSalt, computeBootstrapMessage, computeISignerId, computeOeHash, computeShhhAddress, computeSnip12Hash, decryptPrivateKey, ed25519OwnerId, ed25519OwnerPubkeyParam, ed25519PubkeyFelts, ed25519SignedBytes, eip191OwnerId, eip191OwnerPubkeyParam, eip191PubkeyFelts, encryptPrivateKey, estimateThresholdGasOverhead, executeShhhSponsoredRaw, hashCall, hashCalls, hashOutsideExecutionStruct, hashStarknetDomain, isReadyToExecute, jwtAppleSubHash, jwtAppleSubOwnerId, jwtAppleSubPubkeyFelts, labelToFelt, locateSubClaim, messageHashToNonceB64url, ownerCommitment, parseAppleIdToken, parseDerEcdsaSignature, parseEip191Signature, parseThresholdEnvelope, resolveShhhChainId, secondsUntilExecutable, serializeExecuteFromOutsideV2Calldata, signBootstrapMessage, signTypedData, signTypedDataArray, snip12HashToHexAsciiBytes, starkOwnerId, starkPubkeyFelts, submitViaAccount, waitForTransaction, webauthnOwnerId, webauthnOwnerPubkeyParam, webauthnPubkeyFelts, wrapV2Snip12Envelope, wrapV2ThresholdEnvelope, x402Middleware };
|
|
3048
|
+
export { ANY_CALLER_FELT, APPLE_ISSUER, type AppleTokenResponse, type ApproveBody, BOOTSTRAP_DOMAIN_SEPARATOR, type BootstrapMessageParams, type BuildBootstrapSignedCallParams, type BuildMigrationCallsParams, ChipiAi, ChipiBrowserSDK, ChipiClient, ChipiPaymasterAdapter, ChipiSDK, ChipiServerSDK, ChipiSessions, ChipiSkuPurchases, ChipiSkus, ChipiTransactions, ChipiTreasury, ChipiWallets, type ComputeAddressInput, type ContractEventLog, DEFAULT_OP_EXPIRY_SECONDS, type Eip191Pubkey, type ExecuteResult, type ForTreasuryConfig, ISIGNER_CANONICAL_LABEL, ISIGNER_ID, ISRC9_V2_ID, type JwtAppleSubPubkey, type ListTreasuriesOptions, type ListTreasuriesResult, MAX_OE_VALIDITY_WINDOW_SECONDS, MIN_THRESHOLD_OWNERS, type MultisigAllowance, type NewOwnerInput, OE_DOMAIN_NAME, OE_DOMAIN_REVISION, OE_DOMAIN_VERSION, OP_ADD_OWNER, OP_REMOVE_OWNER, OP_ROTATE_OWNER, OP_SET_THRESHOLD, type OutsideExecution, type OwnerRole, type ProposeBody, ROLE_GUARDIAN, ROLE_OWNER, SIG_VERSION_V1_HEX_ASCII, SIG_VERSION_V2_SNIP12, SIG_VERSION_V2_THRESHOLD, STARKNET_MESSAGE_PREFIX, SessionTxVerifier, type SessionTxVerifierConfig, type SetTreasuryPolicyOptions, ShhhAccount, type ShhhAccountOptions, type ShhhExecuteOptions, type ShhhSignedExecution, type ShhhSubmit, type ShhhX402Wallet, TIMELOCK_SECONDS, type TreasuryPolicy, type TreasuryProposal, type TreasuryProposalSignature, type TreasurySummary, type TreasuryTransport, type TxHashStore, VIEW_SELECTORS, type VerifyTransferFailure, type VerifyTransferParams, type VerifyTransferResult, type WaitForTransactionOptions, type WaitForTransactionResult, type WebAuthnPubkey, X402Facilitator, type X402FacilitatorCreateOptions, type X402MiddlewareConfig, type X402MiddlewareFlatConfig, X402ShhhClient, type X402ShhhClientConfig, assertValidV2Snip12Envelope, buildAddSessionKeyCall, buildBootstrapSignedCall, buildCancelPendingOpCall, buildCancelRecoveryCall, buildEd25519Envelope, buildEd25519EnvelopeFromSignature, buildEip191EnvelopeFromPrivateKey, buildEip191EnvelopeFromSignature, buildExecuteAddOwnerCall, buildExecuteRemoveOwnerCall, buildExecuteRotateOwnerCall, buildExecuteSetThresholdCall, buildFinalizeRecoveryCall, buildInitiateRecoveryCall, buildJwtAppleSubEnvelopeFromTestKey, buildJwtAppleSubEnvelopeFromTokenResponse, buildMigrationCalls, buildOutsideExecution, buildProposeAddOwnerCall, buildProposeRemoveOwnerCall, buildProposeRotateOwnerCall, buildProposeSetThresholdCall, buildRemoveSpendingPolicyCall, buildRevokeSessionKeyCall, buildSessionSetupCalls, buildSetSpendingPolicyCall, buildStarkEnvelope, buildThresholdEnvelope, buildWebAuthnEnvelopeFromAssertion, buildWebAuthnEnvelopeFromPrivateKey, byteArrayToFelts, computeAddressSalt, computeBootstrapMessage, computeISignerId, computeOeHash, computeShhhAddress, computeSnip12Hash, decryptPrivateKey, ed25519OwnerId, ed25519OwnerPubkeyParam, ed25519PubkeyFelts, ed25519SignedBytes, eip191OwnerId, eip191OwnerPubkeyParam, eip191PubkeyFelts, encryptPrivateKey, estimateThresholdGasOverhead, executeShhhSponsoredRaw, hashCall, hashCalls, hashOutsideExecutionStruct, hashStarknetDomain, isReadyToExecute, isThinkDecision, jwtAppleSubHash, jwtAppleSubOwnerId, jwtAppleSubPubkeyFelts, labelToFelt, locateSubClaim, messageHashToNonceB64url, normalizeEntrypoints, ownerCommitment, parseAppleIdToken, parseDerEcdsaSignature, parseEip191Signature, parseThresholdEnvelope, resolveShhhChainId, secondsUntilExecutable, serializeExecuteFromOutsideV2Calldata, signBootstrapMessage, signTypedData, signTypedDataArray, snip12HashToHexAsciiBytes, starkOwnerId, starkPubkeyFelts, submitViaAccount, validateSpendingPolicyConfig, waitForTransaction, webauthnOwnerId, webauthnOwnerPubkeyParam, webauthnPubkeyFelts, wrapV2Snip12Envelope, wrapV2ThresholdEnvelope, x402Middleware };
|