@chipi-stack/backend 14.13.0 → 14.14.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 +245 -6
- package/dist/index.d.ts +245 -6
- package/dist/index.js +394 -104
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +386 -106
- package/dist/index.mjs.map +1 -1
- package/dist/skuPurchases.js +3 -3
- package/dist/skuPurchases.js.map +1 -1
- package/dist/skuPurchases.mjs +3 -3
- package/dist/skuPurchases.mjs.map +1 -1
- package/dist/transactions.d.mts +1 -1
- package/dist/transactions.d.ts +1 -1
- package/dist/transactions.js +3 -3
- package/dist/transactions.js.map +1 -1
- package/dist/transactions.mjs +3 -3
- package/dist/transactions.mjs.map +1 -1
- package/dist/wallets.js +2 -2
- package/dist/wallets.js.map +1 -1
- package/dist/wallets.mjs +2 -2
- package/dist/wallets.mjs.map +1 -1
- package/package.json +3 -3
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, 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, 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
5
|
import { C as ChipiWallets } from './wallets-CYCLyyXY.mjs';
|
|
@@ -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,80 @@ 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
|
+
constructor(client: ChipiClient, apiSecretKey?: string | undefined);
|
|
630
|
+
private secret;
|
|
631
|
+
/**
|
|
632
|
+
* `GET /v1/ai/signals`: technical signals per token, market sentiment and
|
|
633
|
+
* DeFi yields. Free up to a monthly quota per organization, then billed per call.
|
|
634
|
+
*/
|
|
635
|
+
signals(params?: AiSignalsParams): Promise<AiSignals>;
|
|
636
|
+
/**
|
|
637
|
+
* `POST /v1/ai/think`: one DeFi decision for a portfolio, with the latest
|
|
638
|
+
* signals and your risk parameters injected into the prompt.
|
|
639
|
+
*
|
|
640
|
+
* The decision is advice, not an order: check it with `isThinkDecision` and
|
|
641
|
+
* enforce your own limits before executing anything.
|
|
642
|
+
*/
|
|
643
|
+
think(params: ThinkParams): Promise<ThinkResponse>;
|
|
644
|
+
/**
|
|
645
|
+
* `POST /v1/ai/execute`: unsigned AVNU swap calls (approve + swap) for
|
|
646
|
+
* `walletAddress`. Nothing is submitted; sign the calls with a session key
|
|
647
|
+
* or the owner's key.
|
|
648
|
+
*/
|
|
649
|
+
execute(params: AiExecuteParams): Promise<AiExecuteResponse>;
|
|
650
|
+
/** `POST /v1/ai/chat`: general-purpose chat, billed per token. */
|
|
651
|
+
chat(params: AiChatParams): Promise<AiChatResponse>;
|
|
652
|
+
/**
|
|
653
|
+
* `GET /v1/ai/prices`: USD prices and 1h / 24h / 7d changes, refreshed about
|
|
654
|
+
* every 30 seconds. No credits are charged, but like every `sdk.ai` method it
|
|
655
|
+
* needs the SDK's secret key (`sk_`).
|
|
656
|
+
*/
|
|
657
|
+
prices(params?: AiPricesParams): Promise<AiPrices>;
|
|
658
|
+
/** `GET /v1/ai/models`: available models, prices and limits. */
|
|
659
|
+
models(): Promise<AiModelsResponse>;
|
|
660
|
+
}
|
|
661
|
+
|
|
567
662
|
/**
|
|
568
663
|
* PaymasterAdapter implementation that uses Chipi's backend API for gasless transactions.
|
|
569
664
|
*
|
|
@@ -666,6 +761,8 @@ declare class ChipiSDK {
|
|
|
666
761
|
readonly sessions: ChipiSessions;
|
|
667
762
|
readonly exchanges: ChipiExchanges;
|
|
668
763
|
readonly treasury: ChipiTreasury;
|
|
764
|
+
/** AI API (`/v1/ai/*`). Server-only: needs `apiSecretKey` (`sk_`). */
|
|
765
|
+
readonly ai: ChipiAi;
|
|
669
766
|
constructor(config: ChipiSDKConfig);
|
|
670
767
|
/**
|
|
671
768
|
* Resolve bearer token - uses provided token or falls back to apiSecretKey
|
|
@@ -953,6 +1050,47 @@ declare const signTypedDataArray: ({ params, }: {
|
|
|
953
1050
|
params: SignTypedDataParams;
|
|
954
1051
|
}) => Promise<string[]>;
|
|
955
1052
|
|
|
1053
|
+
/** `add_or_update_session_key(session_key, valid_until, max_calls, allowed_entrypoints)` */
|
|
1054
|
+
declare function buildAddSessionKeyCall(walletAddress: string, sessionConfig: SessionConfig): Call$1;
|
|
1055
|
+
/** `revoke_session_key(session_key)` */
|
|
1056
|
+
declare function buildRevokeSessionKeyCall(walletAddress: string, sessionPublicKey: string): Call$1;
|
|
1057
|
+
/**
|
|
1058
|
+
* Validate a spending policy the way the contract interprets it.
|
|
1059
|
+
* Throws `INVALID_SPENDING_POLICY`.
|
|
1060
|
+
*/
|
|
1061
|
+
declare function validateSpendingPolicyConfig(config: SpendingPolicyConfig): void;
|
|
1062
|
+
/**
|
|
1063
|
+
* `set_spending_policy(session_key, token, max_per_call: u256, max_per_window: u256, window_seconds: u64)`
|
|
1064
|
+
*
|
|
1065
|
+
* Contract semantics worth knowing: `maxPerWindow = 0` disables the policy
|
|
1066
|
+
* (unlimited), `maxPerCall = 0` with a window blocks every metered spend, and
|
|
1067
|
+
* only `transfer` / `approve` / `increase_allowance` are metered.
|
|
1068
|
+
*/
|
|
1069
|
+
declare function buildSetSpendingPolicyCall(walletAddress: string, config: SpendingPolicyConfig): Call$1;
|
|
1070
|
+
/** `remove_spending_policy(session_key, token)` */
|
|
1071
|
+
declare function buildRemoveSpendingPolicyCall(walletAddress: string, sessionPublicKey: string, token: string): Call$1;
|
|
1072
|
+
/**
|
|
1073
|
+
* Register a session and cap it per token in one multicall: the session is
|
|
1074
|
+
* added first, then one `set_spending_policy` per entry. Each policy's
|
|
1075
|
+
* `sessionPublicKey` must match the session being registered.
|
|
1076
|
+
*/
|
|
1077
|
+
declare function buildSessionSetupCalls(walletAddress: string, sessionConfig: SessionConfig, spendingPolicies?: ReadonlyArray<Omit<SpendingPolicyConfig, "sessionPublicKey">>): Call$1[];
|
|
1078
|
+
|
|
1079
|
+
/**
|
|
1080
|
+
* Normalize a session whitelist to the hex selectors the contract compares against.
|
|
1081
|
+
*
|
|
1082
|
+
* `add_or_update_session_key` stores raw felts and the account matches them
|
|
1083
|
+
* against `call.selector`, so every entry must be a selector. Names were
|
|
1084
|
+
* previously forwarded unchanged: on CHIPI the paymaster encoded `"transfer"`
|
|
1085
|
+
* as a short string (registration succeeded, every session call then failed the
|
|
1086
|
+
* whitelist); on SHHH `BigInt("transfer")` threw while serialising calldata.
|
|
1087
|
+
*
|
|
1088
|
+
* - `0x…` hex and decimal felts pass through (as hex).
|
|
1089
|
+
* - Cairo identifiers (`"transfer"`, `"multi_route_swap"`) become their selector.
|
|
1090
|
+
* - Anything else throws `SESSION_ENTRYPOINT_NOT_ALLOWED`.
|
|
1091
|
+
*/
|
|
1092
|
+
declare function normalizeEntrypoints(entrypoints: readonly string[]): string[];
|
|
1093
|
+
|
|
956
1094
|
/**
|
|
957
1095
|
* Wait for a Starknet transaction and report what happened, without throwing
|
|
958
1096
|
* on an on-chain revert.
|
|
@@ -1200,6 +1338,107 @@ interface X402MiddlewareFlatConfig {
|
|
|
1200
1338
|
*/
|
|
1201
1339
|
declare function x402Middleware(config: X402MiddlewareConfig | X402MiddlewareFlatConfig): (req: any, res: any, next: any) => Promise<any>;
|
|
1202
1340
|
|
|
1341
|
+
/**
|
|
1342
|
+
* Remembers which transaction hashes already paid for something.
|
|
1343
|
+
*
|
|
1344
|
+
* `consume` must be atomic: return `true` the first time a hash is seen and
|
|
1345
|
+
* `false` on every later call, also across concurrent requests. Back it with a
|
|
1346
|
+
* unique index in your database (`INSERT ... ON CONFLICT DO NOTHING`) in
|
|
1347
|
+
* production; the default in-memory store forgets everything on restart and is
|
|
1348
|
+
* not shared between instances.
|
|
1349
|
+
*/
|
|
1350
|
+
interface TxHashStore {
|
|
1351
|
+
/**
|
|
1352
|
+
* `transactionHash` arrives normalised: lowercase `0x` hex without leading
|
|
1353
|
+
* zeros, so `0x0abc` and `0x000…abc` are the same key. Pad it yourself if you
|
|
1354
|
+
* compare it with RPC output.
|
|
1355
|
+
*/
|
|
1356
|
+
consume(transactionHash: string): boolean | Promise<boolean>;
|
|
1357
|
+
}
|
|
1358
|
+
interface SessionTxVerifierConfig extends WaitForTransactionOptions {
|
|
1359
|
+
/** Default: in memory (single process, lost on restart). */
|
|
1360
|
+
txHashStore?: TxHashStore;
|
|
1361
|
+
/** Receipt source. Default: `waitForTransaction` with the options above. */
|
|
1362
|
+
getReceipt?: (transactionHash: string, options: WaitForTransactionOptions) => Promise<WaitForTransactionResult>;
|
|
1363
|
+
}
|
|
1364
|
+
interface VerifyTransferParams {
|
|
1365
|
+
/** The hash the payer sent you, e.g. from `executeTransactionWithSession`. */
|
|
1366
|
+
transactionHash: string;
|
|
1367
|
+
/** ERC-20 contract, e.g. USDC. */
|
|
1368
|
+
token: string;
|
|
1369
|
+
/** The paying wallet. */
|
|
1370
|
+
from: string;
|
|
1371
|
+
/** Your receiving address. */
|
|
1372
|
+
to: string;
|
|
1373
|
+
/** Smallest acceptable amount, in the token's base units. */
|
|
1374
|
+
minAmount: bigint;
|
|
1375
|
+
}
|
|
1376
|
+
type VerifyTransferFailure =
|
|
1377
|
+
/** The transaction reverted on chain. */
|
|
1378
|
+
"REVERTED"
|
|
1379
|
+
/** No `Transfer` from `token` with this `from` and `to`. */
|
|
1380
|
+
| "TRANSFER_NOT_FOUND"
|
|
1381
|
+
/** A matching `Transfer` exists but moved less than `minAmount`. */
|
|
1382
|
+
| "AMOUNT_TOO_LOW"
|
|
1383
|
+
/** This hash already paid for something (replay). */
|
|
1384
|
+
| "ALREADY_USED";
|
|
1385
|
+
type VerifyTransferResult = {
|
|
1386
|
+
valid: true;
|
|
1387
|
+
transactionHash: string;
|
|
1388
|
+
amount: bigint;
|
|
1389
|
+
blockNumber?: number;
|
|
1390
|
+
} | {
|
|
1391
|
+
valid: false;
|
|
1392
|
+
transactionHash: string;
|
|
1393
|
+
reason: VerifyTransferFailure;
|
|
1394
|
+
detail?: string;
|
|
1395
|
+
};
|
|
1396
|
+
/**
|
|
1397
|
+
* Check on chain that a transaction paid you, and that it pays only once.
|
|
1398
|
+
*
|
|
1399
|
+
* Use it when a client pays by sending the transfer itself (for example an
|
|
1400
|
+
* agent with a session key calling `executeTransactionWithSession`) and hands
|
|
1401
|
+
* you the hash. A transaction hash, or a `SUCCESS` status from an API, is not
|
|
1402
|
+
* proof of payment: the transfer may have reverted, gone elsewhere, moved less,
|
|
1403
|
+
* or already been used for an earlier request. This reads the receipt and
|
|
1404
|
+
* accepts only a successful transaction whose `Transfer` event from `token`
|
|
1405
|
+
* moves at least `minAmount` from `from` to `to`, then consumes the hash.
|
|
1406
|
+
*
|
|
1407
|
+
* Opt-in and independent of `X402Facilitator`, whose behaviour is unchanged.
|
|
1408
|
+
*
|
|
1409
|
+
* **Who is `from`.** Transaction hashes and `Transfer` events are public. If
|
|
1410
|
+
* `from` comes from the request, anyone watching your address can submit a
|
|
1411
|
+
* payer's hash first and consume it: they get the service, the payer gets
|
|
1412
|
+
* `ALREADY_USED`. Take `from` from the caller's authenticated identity (your
|
|
1413
|
+
* session, an API key bound to a wallet) whenever you have one. For anonymous
|
|
1414
|
+
* payers this is first-come-first-served; keep it to low-value calls.
|
|
1415
|
+
*
|
|
1416
|
+
* `verifyTransfer` waits for the transaction to be sequenced and throws only
|
|
1417
|
+
* when it cannot tell (timeout, RPC failure): retry those. Every other outcome
|
|
1418
|
+
* is a result.
|
|
1419
|
+
*
|
|
1420
|
+
* @example
|
|
1421
|
+
* ```typescript
|
|
1422
|
+
* const verifier = new SessionTxVerifier({ txHashStore: dbStore });
|
|
1423
|
+
*
|
|
1424
|
+
* const result = await verifier.verifyTransfer({
|
|
1425
|
+
* transactionHash,
|
|
1426
|
+
* token: USDC,
|
|
1427
|
+
* from: agentWallet,
|
|
1428
|
+
* to: TREASURY,
|
|
1429
|
+
* minAmount: 1_000n, // $0.001 in USDC base units
|
|
1430
|
+
* });
|
|
1431
|
+
* if (!result.valid) return new Response(result.reason, { status: 402 });
|
|
1432
|
+
* ```
|
|
1433
|
+
*/
|
|
1434
|
+
declare class SessionTxVerifier {
|
|
1435
|
+
private readonly store;
|
|
1436
|
+
private readonly getReceipt;
|
|
1437
|
+
private readonly receiptOptions;
|
|
1438
|
+
constructor(config?: SessionTxVerifierConfig);
|
|
1439
|
+
verifyTransfer(params: VerifyTransferParams): Promise<VerifyTransferResult>;
|
|
1440
|
+
}
|
|
1441
|
+
|
|
1203
1442
|
/**
|
|
1204
1443
|
* SNIP-12 typed-data hash for `OutsideExecution` — TypeScript reference.
|
|
1205
1444
|
*
|
|
@@ -2777,4 +3016,4 @@ declare class ShhhAccount {
|
|
|
2777
3016
|
*/
|
|
2778
3017
|
declare function submitViaAccount(funded: Account): ShhhSubmit;
|
|
2779
3018
|
|
|
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 };
|
|
3019
|
+
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 };
|
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, 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, 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
5
|
import { C as ChipiWallets } from './wallets-DxKnh21Q.js';
|
|
@@ -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,80 @@ 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
|
+
constructor(client: ChipiClient, apiSecretKey?: string | undefined);
|
|
630
|
+
private secret;
|
|
631
|
+
/**
|
|
632
|
+
* `GET /v1/ai/signals`: technical signals per token, market sentiment and
|
|
633
|
+
* DeFi yields. Free up to a monthly quota per organization, then billed per call.
|
|
634
|
+
*/
|
|
635
|
+
signals(params?: AiSignalsParams): Promise<AiSignals>;
|
|
636
|
+
/**
|
|
637
|
+
* `POST /v1/ai/think`: one DeFi decision for a portfolio, with the latest
|
|
638
|
+
* signals and your risk parameters injected into the prompt.
|
|
639
|
+
*
|
|
640
|
+
* The decision is advice, not an order: check it with `isThinkDecision` and
|
|
641
|
+
* enforce your own limits before executing anything.
|
|
642
|
+
*/
|
|
643
|
+
think(params: ThinkParams): Promise<ThinkResponse>;
|
|
644
|
+
/**
|
|
645
|
+
* `POST /v1/ai/execute`: unsigned AVNU swap calls (approve + swap) for
|
|
646
|
+
* `walletAddress`. Nothing is submitted; sign the calls with a session key
|
|
647
|
+
* or the owner's key.
|
|
648
|
+
*/
|
|
649
|
+
execute(params: AiExecuteParams): Promise<AiExecuteResponse>;
|
|
650
|
+
/** `POST /v1/ai/chat`: general-purpose chat, billed per token. */
|
|
651
|
+
chat(params: AiChatParams): Promise<AiChatResponse>;
|
|
652
|
+
/**
|
|
653
|
+
* `GET /v1/ai/prices`: USD prices and 1h / 24h / 7d changes, refreshed about
|
|
654
|
+
* every 30 seconds. No credits are charged, but like every `sdk.ai` method it
|
|
655
|
+
* needs the SDK's secret key (`sk_`).
|
|
656
|
+
*/
|
|
657
|
+
prices(params?: AiPricesParams): Promise<AiPrices>;
|
|
658
|
+
/** `GET /v1/ai/models`: available models, prices and limits. */
|
|
659
|
+
models(): Promise<AiModelsResponse>;
|
|
660
|
+
}
|
|
661
|
+
|
|
567
662
|
/**
|
|
568
663
|
* PaymasterAdapter implementation that uses Chipi's backend API for gasless transactions.
|
|
569
664
|
*
|
|
@@ -666,6 +761,8 @@ declare class ChipiSDK {
|
|
|
666
761
|
readonly sessions: ChipiSessions;
|
|
667
762
|
readonly exchanges: ChipiExchanges;
|
|
668
763
|
readonly treasury: ChipiTreasury;
|
|
764
|
+
/** AI API (`/v1/ai/*`). Server-only: needs `apiSecretKey` (`sk_`). */
|
|
765
|
+
readonly ai: ChipiAi;
|
|
669
766
|
constructor(config: ChipiSDKConfig);
|
|
670
767
|
/**
|
|
671
768
|
* Resolve bearer token - uses provided token or falls back to apiSecretKey
|
|
@@ -953,6 +1050,47 @@ declare const signTypedDataArray: ({ params, }: {
|
|
|
953
1050
|
params: SignTypedDataParams;
|
|
954
1051
|
}) => Promise<string[]>;
|
|
955
1052
|
|
|
1053
|
+
/** `add_or_update_session_key(session_key, valid_until, max_calls, allowed_entrypoints)` */
|
|
1054
|
+
declare function buildAddSessionKeyCall(walletAddress: string, sessionConfig: SessionConfig): Call$1;
|
|
1055
|
+
/** `revoke_session_key(session_key)` */
|
|
1056
|
+
declare function buildRevokeSessionKeyCall(walletAddress: string, sessionPublicKey: string): Call$1;
|
|
1057
|
+
/**
|
|
1058
|
+
* Validate a spending policy the way the contract interprets it.
|
|
1059
|
+
* Throws `INVALID_SPENDING_POLICY`.
|
|
1060
|
+
*/
|
|
1061
|
+
declare function validateSpendingPolicyConfig(config: SpendingPolicyConfig): void;
|
|
1062
|
+
/**
|
|
1063
|
+
* `set_spending_policy(session_key, token, max_per_call: u256, max_per_window: u256, window_seconds: u64)`
|
|
1064
|
+
*
|
|
1065
|
+
* Contract semantics worth knowing: `maxPerWindow = 0` disables the policy
|
|
1066
|
+
* (unlimited), `maxPerCall = 0` with a window blocks every metered spend, and
|
|
1067
|
+
* only `transfer` / `approve` / `increase_allowance` are metered.
|
|
1068
|
+
*/
|
|
1069
|
+
declare function buildSetSpendingPolicyCall(walletAddress: string, config: SpendingPolicyConfig): Call$1;
|
|
1070
|
+
/** `remove_spending_policy(session_key, token)` */
|
|
1071
|
+
declare function buildRemoveSpendingPolicyCall(walletAddress: string, sessionPublicKey: string, token: string): Call$1;
|
|
1072
|
+
/**
|
|
1073
|
+
* Register a session and cap it per token in one multicall: the session is
|
|
1074
|
+
* added first, then one `set_spending_policy` per entry. Each policy's
|
|
1075
|
+
* `sessionPublicKey` must match the session being registered.
|
|
1076
|
+
*/
|
|
1077
|
+
declare function buildSessionSetupCalls(walletAddress: string, sessionConfig: SessionConfig, spendingPolicies?: ReadonlyArray<Omit<SpendingPolicyConfig, "sessionPublicKey">>): Call$1[];
|
|
1078
|
+
|
|
1079
|
+
/**
|
|
1080
|
+
* Normalize a session whitelist to the hex selectors the contract compares against.
|
|
1081
|
+
*
|
|
1082
|
+
* `add_or_update_session_key` stores raw felts and the account matches them
|
|
1083
|
+
* against `call.selector`, so every entry must be a selector. Names were
|
|
1084
|
+
* previously forwarded unchanged: on CHIPI the paymaster encoded `"transfer"`
|
|
1085
|
+
* as a short string (registration succeeded, every session call then failed the
|
|
1086
|
+
* whitelist); on SHHH `BigInt("transfer")` threw while serialising calldata.
|
|
1087
|
+
*
|
|
1088
|
+
* - `0x…` hex and decimal felts pass through (as hex).
|
|
1089
|
+
* - Cairo identifiers (`"transfer"`, `"multi_route_swap"`) become their selector.
|
|
1090
|
+
* - Anything else throws `SESSION_ENTRYPOINT_NOT_ALLOWED`.
|
|
1091
|
+
*/
|
|
1092
|
+
declare function normalizeEntrypoints(entrypoints: readonly string[]): string[];
|
|
1093
|
+
|
|
956
1094
|
/**
|
|
957
1095
|
* Wait for a Starknet transaction and report what happened, without throwing
|
|
958
1096
|
* on an on-chain revert.
|
|
@@ -1200,6 +1338,107 @@ interface X402MiddlewareFlatConfig {
|
|
|
1200
1338
|
*/
|
|
1201
1339
|
declare function x402Middleware(config: X402MiddlewareConfig | X402MiddlewareFlatConfig): (req: any, res: any, next: any) => Promise<any>;
|
|
1202
1340
|
|
|
1341
|
+
/**
|
|
1342
|
+
* Remembers which transaction hashes already paid for something.
|
|
1343
|
+
*
|
|
1344
|
+
* `consume` must be atomic: return `true` the first time a hash is seen and
|
|
1345
|
+
* `false` on every later call, also across concurrent requests. Back it with a
|
|
1346
|
+
* unique index in your database (`INSERT ... ON CONFLICT DO NOTHING`) in
|
|
1347
|
+
* production; the default in-memory store forgets everything on restart and is
|
|
1348
|
+
* not shared between instances.
|
|
1349
|
+
*/
|
|
1350
|
+
interface TxHashStore {
|
|
1351
|
+
/**
|
|
1352
|
+
* `transactionHash` arrives normalised: lowercase `0x` hex without leading
|
|
1353
|
+
* zeros, so `0x0abc` and `0x000…abc` are the same key. Pad it yourself if you
|
|
1354
|
+
* compare it with RPC output.
|
|
1355
|
+
*/
|
|
1356
|
+
consume(transactionHash: string): boolean | Promise<boolean>;
|
|
1357
|
+
}
|
|
1358
|
+
interface SessionTxVerifierConfig extends WaitForTransactionOptions {
|
|
1359
|
+
/** Default: in memory (single process, lost on restart). */
|
|
1360
|
+
txHashStore?: TxHashStore;
|
|
1361
|
+
/** Receipt source. Default: `waitForTransaction` with the options above. */
|
|
1362
|
+
getReceipt?: (transactionHash: string, options: WaitForTransactionOptions) => Promise<WaitForTransactionResult>;
|
|
1363
|
+
}
|
|
1364
|
+
interface VerifyTransferParams {
|
|
1365
|
+
/** The hash the payer sent you, e.g. from `executeTransactionWithSession`. */
|
|
1366
|
+
transactionHash: string;
|
|
1367
|
+
/** ERC-20 contract, e.g. USDC. */
|
|
1368
|
+
token: string;
|
|
1369
|
+
/** The paying wallet. */
|
|
1370
|
+
from: string;
|
|
1371
|
+
/** Your receiving address. */
|
|
1372
|
+
to: string;
|
|
1373
|
+
/** Smallest acceptable amount, in the token's base units. */
|
|
1374
|
+
minAmount: bigint;
|
|
1375
|
+
}
|
|
1376
|
+
type VerifyTransferFailure =
|
|
1377
|
+
/** The transaction reverted on chain. */
|
|
1378
|
+
"REVERTED"
|
|
1379
|
+
/** No `Transfer` from `token` with this `from` and `to`. */
|
|
1380
|
+
| "TRANSFER_NOT_FOUND"
|
|
1381
|
+
/** A matching `Transfer` exists but moved less than `minAmount`. */
|
|
1382
|
+
| "AMOUNT_TOO_LOW"
|
|
1383
|
+
/** This hash already paid for something (replay). */
|
|
1384
|
+
| "ALREADY_USED";
|
|
1385
|
+
type VerifyTransferResult = {
|
|
1386
|
+
valid: true;
|
|
1387
|
+
transactionHash: string;
|
|
1388
|
+
amount: bigint;
|
|
1389
|
+
blockNumber?: number;
|
|
1390
|
+
} | {
|
|
1391
|
+
valid: false;
|
|
1392
|
+
transactionHash: string;
|
|
1393
|
+
reason: VerifyTransferFailure;
|
|
1394
|
+
detail?: string;
|
|
1395
|
+
};
|
|
1396
|
+
/**
|
|
1397
|
+
* Check on chain that a transaction paid you, and that it pays only once.
|
|
1398
|
+
*
|
|
1399
|
+
* Use it when a client pays by sending the transfer itself (for example an
|
|
1400
|
+
* agent with a session key calling `executeTransactionWithSession`) and hands
|
|
1401
|
+
* you the hash. A transaction hash, or a `SUCCESS` status from an API, is not
|
|
1402
|
+
* proof of payment: the transfer may have reverted, gone elsewhere, moved less,
|
|
1403
|
+
* or already been used for an earlier request. This reads the receipt and
|
|
1404
|
+
* accepts only a successful transaction whose `Transfer` event from `token`
|
|
1405
|
+
* moves at least `minAmount` from `from` to `to`, then consumes the hash.
|
|
1406
|
+
*
|
|
1407
|
+
* Opt-in and independent of `X402Facilitator`, whose behaviour is unchanged.
|
|
1408
|
+
*
|
|
1409
|
+
* **Who is `from`.** Transaction hashes and `Transfer` events are public. If
|
|
1410
|
+
* `from` comes from the request, anyone watching your address can submit a
|
|
1411
|
+
* payer's hash first and consume it: they get the service, the payer gets
|
|
1412
|
+
* `ALREADY_USED`. Take `from` from the caller's authenticated identity (your
|
|
1413
|
+
* session, an API key bound to a wallet) whenever you have one. For anonymous
|
|
1414
|
+
* payers this is first-come-first-served; keep it to low-value calls.
|
|
1415
|
+
*
|
|
1416
|
+
* `verifyTransfer` waits for the transaction to be sequenced and throws only
|
|
1417
|
+
* when it cannot tell (timeout, RPC failure): retry those. Every other outcome
|
|
1418
|
+
* is a result.
|
|
1419
|
+
*
|
|
1420
|
+
* @example
|
|
1421
|
+
* ```typescript
|
|
1422
|
+
* const verifier = new SessionTxVerifier({ txHashStore: dbStore });
|
|
1423
|
+
*
|
|
1424
|
+
* const result = await verifier.verifyTransfer({
|
|
1425
|
+
* transactionHash,
|
|
1426
|
+
* token: USDC,
|
|
1427
|
+
* from: agentWallet,
|
|
1428
|
+
* to: TREASURY,
|
|
1429
|
+
* minAmount: 1_000n, // $0.001 in USDC base units
|
|
1430
|
+
* });
|
|
1431
|
+
* if (!result.valid) return new Response(result.reason, { status: 402 });
|
|
1432
|
+
* ```
|
|
1433
|
+
*/
|
|
1434
|
+
declare class SessionTxVerifier {
|
|
1435
|
+
private readonly store;
|
|
1436
|
+
private readonly getReceipt;
|
|
1437
|
+
private readonly receiptOptions;
|
|
1438
|
+
constructor(config?: SessionTxVerifierConfig);
|
|
1439
|
+
verifyTransfer(params: VerifyTransferParams): Promise<VerifyTransferResult>;
|
|
1440
|
+
}
|
|
1441
|
+
|
|
1203
1442
|
/**
|
|
1204
1443
|
* SNIP-12 typed-data hash for `OutsideExecution` — TypeScript reference.
|
|
1205
1444
|
*
|
|
@@ -2777,4 +3016,4 @@ declare class ShhhAccount {
|
|
|
2777
3016
|
*/
|
|
2778
3017
|
declare function submitViaAccount(funded: Account): ShhhSubmit;
|
|
2779
3018
|
|
|
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 };
|
|
3019
|
+
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 };
|