@chipi-stack/backend 14.11.0 → 14.12.1
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/README.md +50 -0
- package/dist/index.d.mts +132 -2
- package/dist/index.d.ts +132 -2
- package/dist/index.js +108 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +109 -21
- package/dist/index.mjs.map +1 -1
- package/dist/skuPurchases.js +4 -2
- package/dist/skuPurchases.js.map +1 -1
- package/dist/skuPurchases.mjs +5 -3
- package/dist/skuPurchases.mjs.map +1 -1
- package/dist/transactions.js +4 -2
- package/dist/transactions.js.map +1 -1
- package/dist/transactions.mjs +5 -3
- package/dist/transactions.mjs.map +1 -1
- package/dist/wallets.js +4 -2
- package/dist/wallets.js.map +1 -1
- package/dist/wallets.mjs +5 -3
- package/dist/wallets.mjs.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -43,6 +43,56 @@ const tx = await sdk.transfer({
|
|
|
43
43
|
});
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
+
## Confirming a transaction
|
|
47
|
+
|
|
48
|
+
Every gasless write returns a transaction hash and nothing else, so
|
|
49
|
+
`waitForTransaction` answers the two questions that follow: did it succeed, and
|
|
50
|
+
what did it emit.
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
import { waitForTransaction } from "@chipi-stack/backend";
|
|
54
|
+
|
|
55
|
+
const receipt = await waitForTransaction(tx);
|
|
56
|
+
|
|
57
|
+
if (!receipt.success) {
|
|
58
|
+
throw new Error(receipt.revertReason ?? "reverted on chain");
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Raw events, decode against your own ABI.
|
|
62
|
+
const transferred = receipt.events.filter((e) => e.from_address === USDC);
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
A revert comes back as a **result** (`success: false` plus `revertReason`), not
|
|
66
|
+
a throw, because a revert is a normal outcome you branch on. Only "we do not
|
|
67
|
+
know yet" throws, meaning a timeout or transport failure, where retrying is the
|
|
68
|
+
correct response.
|
|
69
|
+
|
|
70
|
+
Options: `nodeUrl`, `retryIntervalMs` (default 3000) and `timeoutMs`
|
|
71
|
+
(default 300000). `nodeUrl` is your preferred endpoint rather than the only one
|
|
72
|
+
tried, since reading a receipt is idempotent and falls through the RPC chain.
|
|
73
|
+
|
|
74
|
+
## Treasuries
|
|
75
|
+
|
|
76
|
+
`sdk.treasury` drives a SHHH multisig from your own server. All three below need
|
|
77
|
+
a `sk_`, so keep them server-side.
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
// Discover a treasury instead of pinning its id in an env var.
|
|
81
|
+
const { items } = await sdk.treasury.list();
|
|
82
|
+
const ops = items.find((t) => t.name === "Ops Treasury");
|
|
83
|
+
|
|
84
|
+
// Require more signatures to borrow than to repay.
|
|
85
|
+
await sdk.treasury.setPolicy(ops.id, { sensitiveQuorum: 3 });
|
|
86
|
+
const policy = await sdk.treasury.getPolicy(ops.id);
|
|
87
|
+
|
|
88
|
+
// A transport bound to one treasury + owner, wireable into chipi-react's hooks.
|
|
89
|
+
const transport = sdk.treasury.forTreasury({ treasuryId: ops.id, ownerPubkey });
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
A quorum can only **raise** `requiredApprovals` above the wallet's on-chain
|
|
93
|
+
threshold. The chain is the hard floor, so a quorum below it produces proposals
|
|
94
|
+
that reach approved and then revert at execute.
|
|
95
|
+
|
|
46
96
|
## What you can ship
|
|
47
97
|
|
|
48
98
|
- **Wallet-as-a-service APIs** — provision and manage wallets for your users from your backend
|
package/dist/index.d.mts
CHANGED
|
@@ -157,7 +157,9 @@ declare class ChipiSessions {
|
|
|
157
157
|
* 1. Generated via `createSessionKey()`
|
|
158
158
|
* 2. Registered on-chain via `addSessionKeyToContract()`
|
|
159
159
|
*
|
|
160
|
-
* CHIPI
|
|
160
|
+
* CHIPI v29 and SHHH V8.4 only: both embed the SNIP-163 sessions
|
|
161
|
+
* component. Throws for any other wallet type, notably READY (Argent X),
|
|
162
|
+
* which does not. See `validateWalletSupportsSessions`.
|
|
161
163
|
*
|
|
162
164
|
* @param params - Session execution parameters
|
|
163
165
|
* @param bearerToken - Authentication token
|
|
@@ -418,6 +420,31 @@ interface ListTreasuriesResult {
|
|
|
418
420
|
limit: number;
|
|
419
421
|
hasMore: boolean;
|
|
420
422
|
}
|
|
423
|
+
/**
|
|
424
|
+
* Risk-tier quorum policy for one treasury.
|
|
425
|
+
*
|
|
426
|
+
* A proposal filed with `risk: "ROUTINE" | "SENSITIVE"` gets its
|
|
427
|
+
* `requiredApprovals` overridden server-side from the matching quorum, so you
|
|
428
|
+
* can require more signatures for `borrow` than for `repay` without changing
|
|
429
|
+
* the wallet's on-chain threshold.
|
|
430
|
+
*
|
|
431
|
+
* `null` means the tier has no policy and the client's `requiredApprovals`
|
|
432
|
+
* stands.
|
|
433
|
+
*/
|
|
434
|
+
interface TreasuryPolicy {
|
|
435
|
+
treasuryId: string;
|
|
436
|
+
name: string;
|
|
437
|
+
routineQuorum: number | null;
|
|
438
|
+
sensitiveQuorum: number | null;
|
|
439
|
+
}
|
|
440
|
+
interface SetTreasuryPolicyOptions {
|
|
441
|
+
/** Omit to leave unchanged. Pass `null` to clear the tier. */
|
|
442
|
+
routineQuorum?: number | null;
|
|
443
|
+
/** Omit to leave unchanged. Pass `null` to clear the tier. */
|
|
444
|
+
sensitiveQuorum?: number | null;
|
|
445
|
+
/** A `sk_`. Falls back to the SDK's configured `apiSecretKey`. */
|
|
446
|
+
bearerToken?: string;
|
|
447
|
+
}
|
|
421
448
|
interface ListTreasuriesOptions {
|
|
422
449
|
/** 1-based. Defaults to 1 server-side. */
|
|
423
450
|
page?: number;
|
|
@@ -494,6 +521,34 @@ declare class ChipiTreasury {
|
|
|
494
521
|
* ```
|
|
495
522
|
*/
|
|
496
523
|
list(options?: ListTreasuriesOptions): Promise<ListTreasuriesResult>;
|
|
524
|
+
/**
|
|
525
|
+
* Read a treasury's risk-tier quorum policy (`sk_`).
|
|
526
|
+
*/
|
|
527
|
+
getPolicy(treasuryId: string, options?: {
|
|
528
|
+
bearerToken?: string;
|
|
529
|
+
}): Promise<TreasuryPolicy>;
|
|
530
|
+
/**
|
|
531
|
+
* Set a treasury's risk-tier quorums (`sk_`).
|
|
532
|
+
*
|
|
533
|
+
* An omitted tier is left unchanged; passing `null` clears it. Configuring
|
|
534
|
+
* this used to require the dashboard, so an integrator driving governance
|
|
535
|
+
* from their own server could see a quorum applied to a proposal but never
|
|
536
|
+
* choose it.
|
|
537
|
+
*
|
|
538
|
+
* IMPORTANT: a quorum can only RAISE `requiredApprovals` above the wallet's
|
|
539
|
+
* on-chain threshold. The chain is the hard floor, so a quorum set below it
|
|
540
|
+
* produces proposals that reach `APPROVED` here and then revert at execute.
|
|
541
|
+
*
|
|
542
|
+
* Server-only: it needs a `sk_`.
|
|
543
|
+
*
|
|
544
|
+
* @example
|
|
545
|
+
* ```typescript
|
|
546
|
+
* // Founding a pool and borrowing need 3 owners; repaying needs the
|
|
547
|
+
* // wallet's own threshold.
|
|
548
|
+
* await sdk.treasury.setPolicy(treasuryId, { sensitiveQuorum: 3 });
|
|
549
|
+
* ```
|
|
550
|
+
*/
|
|
551
|
+
setPolicy(treasuryId: string, options?: SetTreasuryPolicyOptions): Promise<TreasuryPolicy>;
|
|
497
552
|
/**
|
|
498
553
|
* Build a {@link TreasuryTransport} for one treasury + owner. Wire the
|
|
499
554
|
* returned object directly into chipi-react's `useProposeAction` /
|
|
@@ -891,6 +946,81 @@ declare const signTypedDataArray: ({ params, }: {
|
|
|
891
946
|
params: SignTypedDataParams;
|
|
892
947
|
}) => Promise<string[]>;
|
|
893
948
|
|
|
949
|
+
/**
|
|
950
|
+
* Wait for a Starknet transaction and report what happened, without throwing
|
|
951
|
+
* on an on-chain revert.
|
|
952
|
+
*
|
|
953
|
+
* Every gasless write in this SDK returns a transaction hash and nothing else,
|
|
954
|
+
* so integrators were each writing the same receipt-polling loop to answer two
|
|
955
|
+
* questions: did it actually succeed, and what events did it emit. Getting that
|
|
956
|
+
* loop wrong is expensive in a money flow. A revert that reads as success
|
|
957
|
+
* double-credits a ledger; a timeout treated as failure strands a confirmed
|
|
958
|
+
* transfer.
|
|
959
|
+
*
|
|
960
|
+
* The contract here is deliberately narrow: a REVERTED transaction is a
|
|
961
|
+
* RESULT, not an exception, because a revert is a normal outcome your code
|
|
962
|
+
* must branch on. Exceptions are reserved for "we do not know yet": a timeout
|
|
963
|
+
* or a transport failure, where retrying is the correct response and treating
|
|
964
|
+
* it as failure would be wrong.
|
|
965
|
+
*/
|
|
966
|
+
/** One raw event from the receipt. Decode against your own ABI. */
|
|
967
|
+
interface ContractEventLog {
|
|
968
|
+
/** Emitting contract address. Filter on this before matching keys. */
|
|
969
|
+
from_address: string;
|
|
970
|
+
/** Indexed fields. `keys[0]` is the selector of the event name. */
|
|
971
|
+
keys: string[];
|
|
972
|
+
/** Non-indexed fields, in declaration order. */
|
|
973
|
+
data: string[];
|
|
974
|
+
}
|
|
975
|
+
interface WaitForTransactionResult {
|
|
976
|
+
transactionHash: string;
|
|
977
|
+
/** True only for an accepted, non-reverted transaction. */
|
|
978
|
+
success: boolean;
|
|
979
|
+
/** Raw `execution_status` from the node, when it reported one. */
|
|
980
|
+
executionStatus?: string;
|
|
981
|
+
/** Raw `finality_status` from the node, when it reported one. */
|
|
982
|
+
finalityStatus?: string;
|
|
983
|
+
/** Present when `success` is false and the node gave a reason. */
|
|
984
|
+
revertReason?: string;
|
|
985
|
+
/** Empty on a revert: reverted transactions emit no events. */
|
|
986
|
+
events: ContractEventLog[];
|
|
987
|
+
blockNumber?: number;
|
|
988
|
+
}
|
|
989
|
+
interface WaitForTransactionOptions {
|
|
990
|
+
/**
|
|
991
|
+
* Preferred endpoint. It is the caller's slot in the ordered RPC chain, not
|
|
992
|
+
* the only endpoint tried: reading a receipt is idempotent, so a transport
|
|
993
|
+
* failure falls through to the next endpoint rather than aborting the wait.
|
|
994
|
+
* Defaults to the endpoint the SDK already uses for CHIPI wallets.
|
|
995
|
+
*/
|
|
996
|
+
nodeUrl?: string;
|
|
997
|
+
/** Poll interval. Default 3000ms, roughly Starknet's block cadence. */
|
|
998
|
+
retryIntervalMs?: number;
|
|
999
|
+
/** Total budget before giving up. Default 300000ms (5 minutes). */
|
|
1000
|
+
timeoutMs?: number;
|
|
1001
|
+
}
|
|
1002
|
+
/**
|
|
1003
|
+
* Poll until `transactionHash` reaches a terminal state.
|
|
1004
|
+
*
|
|
1005
|
+
* @throws if the timeout elapses before the node sequences the transaction.
|
|
1006
|
+
* It does NOT throw when the transaction reverted: check `success`.
|
|
1007
|
+
*
|
|
1008
|
+
* @example
|
|
1009
|
+
* ```typescript
|
|
1010
|
+
* const txHash = await sdk.callAnyContract({ params, bearerToken });
|
|
1011
|
+
* const receipt = await sdk.waitForTransaction(txHash);
|
|
1012
|
+
*
|
|
1013
|
+
* if (!receipt.success) {
|
|
1014
|
+
* throw new Error(receipt.revertReason ?? "reverted on chain");
|
|
1015
|
+
* }
|
|
1016
|
+
*
|
|
1017
|
+
* const created = receipt.events.find(
|
|
1018
|
+
* (e) => e.from_address === FACTORY && e.keys[0] === POOL_CREATED_SELECTOR
|
|
1019
|
+
* );
|
|
1020
|
+
* ```
|
|
1021
|
+
*/
|
|
1022
|
+
declare function waitForTransaction(transactionHash: string, options?: WaitForTransactionOptions): Promise<WaitForTransactionResult>;
|
|
1023
|
+
|
|
894
1024
|
declare const encryptPrivateKey: (privateKey: string, password: string) => string;
|
|
895
1025
|
declare const decryptPrivateKey: (encryptedPrivateKey: string, password: string) => string;
|
|
896
1026
|
|
|
@@ -2635,4 +2765,4 @@ declare class ShhhAccount {
|
|
|
2635
2765
|
*/
|
|
2636
2766
|
declare function submitViaAccount(funded: Account): ShhhSubmit;
|
|
2637
2767
|
|
|
2638
|
-
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, 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, ShhhAccount, type ShhhAccountOptions, type ShhhExecuteOptions, type ShhhSignedExecution, type ShhhSubmit, type ShhhX402Wallet, TIMELOCK_SECONDS, type TreasuryProposal, type TreasuryProposalSignature, type TreasurySummary, type TreasuryTransport, VIEW_SELECTORS, 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, webauthnOwnerId, webauthnOwnerPubkeyParam, webauthnPubkeyFelts, wrapV2Snip12Envelope, wrapV2ThresholdEnvelope, x402Middleware };
|
|
2768
|
+
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -157,7 +157,9 @@ declare class ChipiSessions {
|
|
|
157
157
|
* 1. Generated via `createSessionKey()`
|
|
158
158
|
* 2. Registered on-chain via `addSessionKeyToContract()`
|
|
159
159
|
*
|
|
160
|
-
* CHIPI
|
|
160
|
+
* CHIPI v29 and SHHH V8.4 only: both embed the SNIP-163 sessions
|
|
161
|
+
* component. Throws for any other wallet type, notably READY (Argent X),
|
|
162
|
+
* which does not. See `validateWalletSupportsSessions`.
|
|
161
163
|
*
|
|
162
164
|
* @param params - Session execution parameters
|
|
163
165
|
* @param bearerToken - Authentication token
|
|
@@ -418,6 +420,31 @@ interface ListTreasuriesResult {
|
|
|
418
420
|
limit: number;
|
|
419
421
|
hasMore: boolean;
|
|
420
422
|
}
|
|
423
|
+
/**
|
|
424
|
+
* Risk-tier quorum policy for one treasury.
|
|
425
|
+
*
|
|
426
|
+
* A proposal filed with `risk: "ROUTINE" | "SENSITIVE"` gets its
|
|
427
|
+
* `requiredApprovals` overridden server-side from the matching quorum, so you
|
|
428
|
+
* can require more signatures for `borrow` than for `repay` without changing
|
|
429
|
+
* the wallet's on-chain threshold.
|
|
430
|
+
*
|
|
431
|
+
* `null` means the tier has no policy and the client's `requiredApprovals`
|
|
432
|
+
* stands.
|
|
433
|
+
*/
|
|
434
|
+
interface TreasuryPolicy {
|
|
435
|
+
treasuryId: string;
|
|
436
|
+
name: string;
|
|
437
|
+
routineQuorum: number | null;
|
|
438
|
+
sensitiveQuorum: number | null;
|
|
439
|
+
}
|
|
440
|
+
interface SetTreasuryPolicyOptions {
|
|
441
|
+
/** Omit to leave unchanged. Pass `null` to clear the tier. */
|
|
442
|
+
routineQuorum?: number | null;
|
|
443
|
+
/** Omit to leave unchanged. Pass `null` to clear the tier. */
|
|
444
|
+
sensitiveQuorum?: number | null;
|
|
445
|
+
/** A `sk_`. Falls back to the SDK's configured `apiSecretKey`. */
|
|
446
|
+
bearerToken?: string;
|
|
447
|
+
}
|
|
421
448
|
interface ListTreasuriesOptions {
|
|
422
449
|
/** 1-based. Defaults to 1 server-side. */
|
|
423
450
|
page?: number;
|
|
@@ -494,6 +521,34 @@ declare class ChipiTreasury {
|
|
|
494
521
|
* ```
|
|
495
522
|
*/
|
|
496
523
|
list(options?: ListTreasuriesOptions): Promise<ListTreasuriesResult>;
|
|
524
|
+
/**
|
|
525
|
+
* Read a treasury's risk-tier quorum policy (`sk_`).
|
|
526
|
+
*/
|
|
527
|
+
getPolicy(treasuryId: string, options?: {
|
|
528
|
+
bearerToken?: string;
|
|
529
|
+
}): Promise<TreasuryPolicy>;
|
|
530
|
+
/**
|
|
531
|
+
* Set a treasury's risk-tier quorums (`sk_`).
|
|
532
|
+
*
|
|
533
|
+
* An omitted tier is left unchanged; passing `null` clears it. Configuring
|
|
534
|
+
* this used to require the dashboard, so an integrator driving governance
|
|
535
|
+
* from their own server could see a quorum applied to a proposal but never
|
|
536
|
+
* choose it.
|
|
537
|
+
*
|
|
538
|
+
* IMPORTANT: a quorum can only RAISE `requiredApprovals` above the wallet's
|
|
539
|
+
* on-chain threshold. The chain is the hard floor, so a quorum set below it
|
|
540
|
+
* produces proposals that reach `APPROVED` here and then revert at execute.
|
|
541
|
+
*
|
|
542
|
+
* Server-only: it needs a `sk_`.
|
|
543
|
+
*
|
|
544
|
+
* @example
|
|
545
|
+
* ```typescript
|
|
546
|
+
* // Founding a pool and borrowing need 3 owners; repaying needs the
|
|
547
|
+
* // wallet's own threshold.
|
|
548
|
+
* await sdk.treasury.setPolicy(treasuryId, { sensitiveQuorum: 3 });
|
|
549
|
+
* ```
|
|
550
|
+
*/
|
|
551
|
+
setPolicy(treasuryId: string, options?: SetTreasuryPolicyOptions): Promise<TreasuryPolicy>;
|
|
497
552
|
/**
|
|
498
553
|
* Build a {@link TreasuryTransport} for one treasury + owner. Wire the
|
|
499
554
|
* returned object directly into chipi-react's `useProposeAction` /
|
|
@@ -891,6 +946,81 @@ declare const signTypedDataArray: ({ params, }: {
|
|
|
891
946
|
params: SignTypedDataParams;
|
|
892
947
|
}) => Promise<string[]>;
|
|
893
948
|
|
|
949
|
+
/**
|
|
950
|
+
* Wait for a Starknet transaction and report what happened, without throwing
|
|
951
|
+
* on an on-chain revert.
|
|
952
|
+
*
|
|
953
|
+
* Every gasless write in this SDK returns a transaction hash and nothing else,
|
|
954
|
+
* so integrators were each writing the same receipt-polling loop to answer two
|
|
955
|
+
* questions: did it actually succeed, and what events did it emit. Getting that
|
|
956
|
+
* loop wrong is expensive in a money flow. A revert that reads as success
|
|
957
|
+
* double-credits a ledger; a timeout treated as failure strands a confirmed
|
|
958
|
+
* transfer.
|
|
959
|
+
*
|
|
960
|
+
* The contract here is deliberately narrow: a REVERTED transaction is a
|
|
961
|
+
* RESULT, not an exception, because a revert is a normal outcome your code
|
|
962
|
+
* must branch on. Exceptions are reserved for "we do not know yet": a timeout
|
|
963
|
+
* or a transport failure, where retrying is the correct response and treating
|
|
964
|
+
* it as failure would be wrong.
|
|
965
|
+
*/
|
|
966
|
+
/** One raw event from the receipt. Decode against your own ABI. */
|
|
967
|
+
interface ContractEventLog {
|
|
968
|
+
/** Emitting contract address. Filter on this before matching keys. */
|
|
969
|
+
from_address: string;
|
|
970
|
+
/** Indexed fields. `keys[0]` is the selector of the event name. */
|
|
971
|
+
keys: string[];
|
|
972
|
+
/** Non-indexed fields, in declaration order. */
|
|
973
|
+
data: string[];
|
|
974
|
+
}
|
|
975
|
+
interface WaitForTransactionResult {
|
|
976
|
+
transactionHash: string;
|
|
977
|
+
/** True only for an accepted, non-reverted transaction. */
|
|
978
|
+
success: boolean;
|
|
979
|
+
/** Raw `execution_status` from the node, when it reported one. */
|
|
980
|
+
executionStatus?: string;
|
|
981
|
+
/** Raw `finality_status` from the node, when it reported one. */
|
|
982
|
+
finalityStatus?: string;
|
|
983
|
+
/** Present when `success` is false and the node gave a reason. */
|
|
984
|
+
revertReason?: string;
|
|
985
|
+
/** Empty on a revert: reverted transactions emit no events. */
|
|
986
|
+
events: ContractEventLog[];
|
|
987
|
+
blockNumber?: number;
|
|
988
|
+
}
|
|
989
|
+
interface WaitForTransactionOptions {
|
|
990
|
+
/**
|
|
991
|
+
* Preferred endpoint. It is the caller's slot in the ordered RPC chain, not
|
|
992
|
+
* the only endpoint tried: reading a receipt is idempotent, so a transport
|
|
993
|
+
* failure falls through to the next endpoint rather than aborting the wait.
|
|
994
|
+
* Defaults to the endpoint the SDK already uses for CHIPI wallets.
|
|
995
|
+
*/
|
|
996
|
+
nodeUrl?: string;
|
|
997
|
+
/** Poll interval. Default 3000ms, roughly Starknet's block cadence. */
|
|
998
|
+
retryIntervalMs?: number;
|
|
999
|
+
/** Total budget before giving up. Default 300000ms (5 minutes). */
|
|
1000
|
+
timeoutMs?: number;
|
|
1001
|
+
}
|
|
1002
|
+
/**
|
|
1003
|
+
* Poll until `transactionHash` reaches a terminal state.
|
|
1004
|
+
*
|
|
1005
|
+
* @throws if the timeout elapses before the node sequences the transaction.
|
|
1006
|
+
* It does NOT throw when the transaction reverted: check `success`.
|
|
1007
|
+
*
|
|
1008
|
+
* @example
|
|
1009
|
+
* ```typescript
|
|
1010
|
+
* const txHash = await sdk.callAnyContract({ params, bearerToken });
|
|
1011
|
+
* const receipt = await sdk.waitForTransaction(txHash);
|
|
1012
|
+
*
|
|
1013
|
+
* if (!receipt.success) {
|
|
1014
|
+
* throw new Error(receipt.revertReason ?? "reverted on chain");
|
|
1015
|
+
* }
|
|
1016
|
+
*
|
|
1017
|
+
* const created = receipt.events.find(
|
|
1018
|
+
* (e) => e.from_address === FACTORY && e.keys[0] === POOL_CREATED_SELECTOR
|
|
1019
|
+
* );
|
|
1020
|
+
* ```
|
|
1021
|
+
*/
|
|
1022
|
+
declare function waitForTransaction(transactionHash: string, options?: WaitForTransactionOptions): Promise<WaitForTransactionResult>;
|
|
1023
|
+
|
|
894
1024
|
declare const encryptPrivateKey: (privateKey: string, password: string) => string;
|
|
895
1025
|
declare const decryptPrivateKey: (encryptedPrivateKey: string, password: string) => string;
|
|
896
1026
|
|
|
@@ -2635,4 +2765,4 @@ declare class ShhhAccount {
|
|
|
2635
2765
|
*/
|
|
2636
2766
|
declare function submitViaAccount(funded: Account): ShhhSubmit;
|
|
2637
2767
|
|
|
2638
|
-
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, 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, ShhhAccount, type ShhhAccountOptions, type ShhhExecuteOptions, type ShhhSignedExecution, type ShhhSubmit, type ShhhX402Wallet, TIMELOCK_SECONDS, type TreasuryProposal, type TreasuryProposalSignature, type TreasurySummary, type TreasuryTransport, VIEW_SELECTORS, 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, webauthnOwnerId, webauthnOwnerPubkeyParam, webauthnPubkeyFelts, wrapV2Snip12Envelope, wrapV2ThresholdEnvelope, x402Middleware };
|
|
2768
|
+
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 };
|
package/dist/index.js
CHANGED
|
@@ -966,8 +966,10 @@ var executePaymasterTransaction = async ({
|
|
|
966
966
|
let walletType = wallet.walletType ?? "READY";
|
|
967
967
|
if (!wallet.walletType) {
|
|
968
968
|
try {
|
|
969
|
-
const
|
|
970
|
-
|
|
969
|
+
const onChainClassHash = await shared.withRpcFallback(
|
|
970
|
+
(provider2) => provider2.getClassHashAt(wallet.publicKey, "latest"),
|
|
971
|
+
{ fallbackUrl: shared.WALLET_RPC_ENDPOINTS.CHIPI }
|
|
972
|
+
);
|
|
971
973
|
walletType = shared.getWalletTypeFromClassHash(onChainClassHash) ?? "READY";
|
|
972
974
|
} catch {
|
|
973
975
|
}
|
|
@@ -2392,18 +2394,18 @@ var ChipiSessions = class {
|
|
|
2392
2394
|
async getSessionData(params) {
|
|
2393
2395
|
const { walletAddress, sessionPublicKey } = params;
|
|
2394
2396
|
try {
|
|
2395
|
-
const provider = new starknet.RpcProvider({
|
|
2396
|
-
nodeUrl: shared.WALLET_RPC_ENDPOINTS["CHIPI"]
|
|
2397
|
-
});
|
|
2398
2397
|
console.log("[ChipiSDK:Session:GetData] Querying session data", {
|
|
2399
2398
|
walletAddress: walletAddress.slice(0, 15) + "...",
|
|
2400
2399
|
sessionPubKey: sessionPublicKey.slice(0, 15) + "..."
|
|
2401
2400
|
});
|
|
2402
|
-
const result = await
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2401
|
+
const result = await shared.withRpcFallback(
|
|
2402
|
+
(provider) => provider.callContract({
|
|
2403
|
+
contractAddress: walletAddress,
|
|
2404
|
+
entrypoint: shared.SESSION_ENTRYPOINTS.GET_DATA,
|
|
2405
|
+
calldata: [sessionPublicKey]
|
|
2406
|
+
}),
|
|
2407
|
+
{ fallbackUrl: shared.WALLET_RPC_ENDPOINTS["CHIPI"] }
|
|
2408
|
+
);
|
|
2407
2409
|
const resultArray = Array.isArray(result) ? result : result.result || [];
|
|
2408
2410
|
if (resultArray.length < 4) {
|
|
2409
2411
|
console.warn("[ChipiSDK:Session:GetData] Unexpected response format", {
|
|
@@ -2474,7 +2476,9 @@ var ChipiSessions = class {
|
|
|
2474
2476
|
* 1. Generated via `createSessionKey()`
|
|
2475
2477
|
* 2. Registered on-chain via `addSessionKeyToContract()`
|
|
2476
2478
|
*
|
|
2477
|
-
* CHIPI
|
|
2479
|
+
* CHIPI v29 and SHHH V8.4 only: both embed the SNIP-163 sessions
|
|
2480
|
+
* component. Throws for any other wallet type, notably READY (Argent X),
|
|
2481
|
+
* which does not. See `validateWalletSupportsSessions`.
|
|
2478
2482
|
*
|
|
2479
2483
|
* @param params - Session execution parameters
|
|
2480
2484
|
* @param bearerToken - Authentication token
|
|
@@ -2690,19 +2694,19 @@ var ChipiSessions = class {
|
|
|
2690
2694
|
async getSpendingPolicy(params) {
|
|
2691
2695
|
const { walletAddress, sessionPublicKey, token } = params;
|
|
2692
2696
|
try {
|
|
2693
|
-
const provider = new starknet.RpcProvider({
|
|
2694
|
-
nodeUrl: shared.WALLET_RPC_ENDPOINTS["CHIPI"]
|
|
2695
|
-
});
|
|
2696
2697
|
console.log("[ChipiSDK:Session:GetSpendingPolicy] Querying spending policy", {
|
|
2697
2698
|
walletAddress: walletAddress.slice(0, 15) + "...",
|
|
2698
2699
|
sessionPubKey: sessionPublicKey.slice(0, 15) + "...",
|
|
2699
2700
|
token: token.slice(0, 15) + "..."
|
|
2700
2701
|
});
|
|
2701
|
-
const result = await
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2702
|
+
const result = await shared.withRpcFallback(
|
|
2703
|
+
(provider) => provider.callContract({
|
|
2704
|
+
contractAddress: walletAddress,
|
|
2705
|
+
entrypoint: shared.SESSION_ENTRYPOINTS.GET_SPENDING_POLICY,
|
|
2706
|
+
calldata: [sessionPublicKey, token]
|
|
2707
|
+
}),
|
|
2708
|
+
{ fallbackUrl: shared.WALLET_RPC_ENDPOINTS["CHIPI"] }
|
|
2709
|
+
);
|
|
2706
2710
|
const resultArray = Array.isArray(result) ? result : result.result || [];
|
|
2707
2711
|
if (resultArray.length < 8) {
|
|
2708
2712
|
console.warn("[ChipiSDK:Session:GetSpendingPolicy] Unexpected response format", {
|
|
@@ -2899,6 +2903,47 @@ var ChipiTreasury = class {
|
|
|
2899
2903
|
});
|
|
2900
2904
|
return { ...res, items: res.items ?? [] };
|
|
2901
2905
|
}
|
|
2906
|
+
/**
|
|
2907
|
+
* Read a treasury's risk-tier quorum policy (`sk_`).
|
|
2908
|
+
*/
|
|
2909
|
+
async getPolicy(treasuryId, options = {}) {
|
|
2910
|
+
return this.client.get({
|
|
2911
|
+
endpoint: `${shared.API_ENDPOINTS.TREASURIES}/${treasuryId}/policy`,
|
|
2912
|
+
bearerToken: this.secret(options.bearerToken)
|
|
2913
|
+
});
|
|
2914
|
+
}
|
|
2915
|
+
/**
|
|
2916
|
+
* Set a treasury's risk-tier quorums (`sk_`).
|
|
2917
|
+
*
|
|
2918
|
+
* An omitted tier is left unchanged; passing `null` clears it. Configuring
|
|
2919
|
+
* this used to require the dashboard, so an integrator driving governance
|
|
2920
|
+
* from their own server could see a quorum applied to a proposal but never
|
|
2921
|
+
* choose it.
|
|
2922
|
+
*
|
|
2923
|
+
* IMPORTANT: a quorum can only RAISE `requiredApprovals` above the wallet's
|
|
2924
|
+
* on-chain threshold. The chain is the hard floor, so a quorum set below it
|
|
2925
|
+
* produces proposals that reach `APPROVED` here and then revert at execute.
|
|
2926
|
+
*
|
|
2927
|
+
* Server-only: it needs a `sk_`.
|
|
2928
|
+
*
|
|
2929
|
+
* @example
|
|
2930
|
+
* ```typescript
|
|
2931
|
+
* // Founding a pool and borrowing need 3 owners; repaying needs the
|
|
2932
|
+
* // wallet's own threshold.
|
|
2933
|
+
* await sdk.treasury.setPolicy(treasuryId, { sensitiveQuorum: 3 });
|
|
2934
|
+
* ```
|
|
2935
|
+
*/
|
|
2936
|
+
async setPolicy(treasuryId, options = {}) {
|
|
2937
|
+
const { routineQuorum, sensitiveQuorum, bearerToken } = options;
|
|
2938
|
+
const body = {};
|
|
2939
|
+
if (routineQuorum !== void 0) body.routineQuorum = routineQuorum;
|
|
2940
|
+
if (sensitiveQuorum !== void 0) body.sensitiveQuorum = sensitiveQuorum;
|
|
2941
|
+
return this.client.patch({
|
|
2942
|
+
endpoint: `${shared.API_ENDPOINTS.TREASURIES}/${treasuryId}/policy`,
|
|
2943
|
+
bearerToken: this.secret(bearerToken),
|
|
2944
|
+
body
|
|
2945
|
+
});
|
|
2946
|
+
}
|
|
2902
2947
|
/**
|
|
2903
2948
|
* Build a {@link TreasuryTransport} for one treasury + owner. Wire the
|
|
2904
2949
|
* returned object directly into chipi-react's `useProposeAction` /
|
|
@@ -3583,6 +3628,49 @@ var ChipiBrowserSDK = class extends ChipiSDK {
|
|
|
3583
3628
|
// All methods are inherited from ChipiSDK
|
|
3584
3629
|
// bearerToken parameter is required for each authenticated request
|
|
3585
3630
|
};
|
|
3631
|
+
var DEFAULT_RETRY_INTERVAL_MS = 3e3;
|
|
3632
|
+
var DEFAULT_TIMEOUT_MS = 3e5;
|
|
3633
|
+
function isPending(finalityStatus) {
|
|
3634
|
+
return finalityStatus === void 0 || finalityStatus === "RECEIVED" || finalityStatus === "PENDING" || finalityStatus === "PRE_CONFIRMED";
|
|
3635
|
+
}
|
|
3636
|
+
async function waitForTransaction(transactionHash, options = {}) {
|
|
3637
|
+
const {
|
|
3638
|
+
nodeUrl = shared.WALLET_RPC_ENDPOINTS.CHIPI,
|
|
3639
|
+
retryIntervalMs = DEFAULT_RETRY_INTERVAL_MS,
|
|
3640
|
+
timeoutMs = DEFAULT_TIMEOUT_MS
|
|
3641
|
+
} = options;
|
|
3642
|
+
const deadline = Date.now() + timeoutMs;
|
|
3643
|
+
let lastError;
|
|
3644
|
+
for (; ; ) {
|
|
3645
|
+
try {
|
|
3646
|
+
const receipt = await shared.withRpcFallback(
|
|
3647
|
+
(provider) => provider.getTransactionReceipt(transactionHash),
|
|
3648
|
+
{ fallbackUrl: nodeUrl }
|
|
3649
|
+
);
|
|
3650
|
+
if (!isPending(receipt?.finality_status)) {
|
|
3651
|
+
const reverted = receipt.execution_status === "REVERTED";
|
|
3652
|
+
return {
|
|
3653
|
+
transactionHash,
|
|
3654
|
+
success: !reverted,
|
|
3655
|
+
executionStatus: receipt.execution_status,
|
|
3656
|
+
finalityStatus: receipt.finality_status,
|
|
3657
|
+
...reverted ? { revertReason: receipt.revert_reason ?? "reverted on chain" } : {},
|
|
3658
|
+
events: receipt.events ?? [],
|
|
3659
|
+
...receipt.block_number !== void 0 ? { blockNumber: receipt.block_number } : {}
|
|
3660
|
+
};
|
|
3661
|
+
}
|
|
3662
|
+
} catch (err) {
|
|
3663
|
+
lastError = err;
|
|
3664
|
+
}
|
|
3665
|
+
if (Date.now() + retryIntervalMs >= deadline) {
|
|
3666
|
+
const detail = lastError instanceof Error ? `: ${lastError.message}` : "";
|
|
3667
|
+
throw new Error(
|
|
3668
|
+
`Timed out after ${timeoutMs}ms waiting for ${transactionHash}${detail}. The transaction may still land; re-check before treating it as failed.`
|
|
3669
|
+
);
|
|
3670
|
+
}
|
|
3671
|
+
await new Promise((resolve) => setTimeout(resolve, retryIntervalMs));
|
|
3672
|
+
}
|
|
3673
|
+
}
|
|
3586
3674
|
|
|
3587
3675
|
// src/index.ts
|
|
3588
3676
|
init_encryption2();
|
|
@@ -4911,6 +4999,7 @@ exports.snip12HashToHexAsciiBytes = snip12HashToHexAsciiBytes;
|
|
|
4911
4999
|
exports.starkOwnerId = starkOwnerId;
|
|
4912
5000
|
exports.starkPubkeyFelts = starkPubkeyFelts;
|
|
4913
5001
|
exports.submitViaAccount = submitViaAccount;
|
|
5002
|
+
exports.waitForTransaction = waitForTransaction;
|
|
4914
5003
|
exports.webauthnOwnerId = webauthnOwnerId;
|
|
4915
5004
|
exports.webauthnOwnerPubkeyParam = webauthnOwnerPubkeyParam;
|
|
4916
5005
|
exports.webauthnPubkeyFelts = webauthnPubkeyFelts;
|