sta-sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +107 -0
- package/dist/index.cjs +498 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +484 -0
- package/dist/index.d.ts +484 -0
- package/dist/index.js +462 -0
- package/dist/index.js.map +1 -0
- package/package.json +59 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
import { Keypair, SigningCallback, xdr, Transaction, rpc } from '@stellar/stellar-sdk';
|
|
2
|
+
export { Account } from '@stellar/stellar-sdk';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Network configuration for `sta-sdk`.
|
|
6
|
+
*
|
|
7
|
+
* `testnet` is populated with the live, currently-deployed contract set --
|
|
8
|
+
* the `smart_account` address is the account_factory-deployed treasury from
|
|
9
|
+
* the smart-contracts repo's docs/TESTNET_FACTORY_DEPLOYMENT.md §13.2,
|
|
10
|
+
* which runs the fixed contract code (see docs/SECURITY_REVIEW_STRICT.md
|
|
11
|
+
* finding 29). The older hand-deployed treasury from docs/TESTNET_DEPLOYMENT.md
|
|
12
|
+
* predates that fix and is not the default here.
|
|
13
|
+
*
|
|
14
|
+
* `MAINNET` stays `undefined` until `buildMainnetConfig` is actually called
|
|
15
|
+
* with real, deployed contract addresses -- no mainnet deployment exists
|
|
16
|
+
* yet, and nothing here fabricates one. What *is* ready now is the rest of
|
|
17
|
+
* the mainnet shape: the real, verified mainnet network passphrase
|
|
18
|
+
* (`MAINNET_NETWORK_PASSPHRASE`, a fixed protocol constant, unlike an RPC
|
|
19
|
+
* URL) and `buildMainnetConfig` itself, so wiring in a real mainnet
|
|
20
|
+
* deployment later is "call this function with the six addresses," not a
|
|
21
|
+
* code change.
|
|
22
|
+
*/
|
|
23
|
+
interface ContractAddresses {
|
|
24
|
+
smartAccount: string;
|
|
25
|
+
policyEngine: string;
|
|
26
|
+
intentRegistry: string;
|
|
27
|
+
recoveryManager: string;
|
|
28
|
+
accountFactory: string;
|
|
29
|
+
/** Never called directly by a client (see docs/DAPP_INTEGRATION_SPEC.md
|
|
30
|
+
* §1) -- recorded for reference and for building auth-entry
|
|
31
|
+
* sub-invocations by hand. */
|
|
32
|
+
transferAdapter: string;
|
|
33
|
+
splitAdapter: string;
|
|
34
|
+
}
|
|
35
|
+
interface NetworkConfig {
|
|
36
|
+
network: "testnet" | "mainnet";
|
|
37
|
+
rpcUrl: string;
|
|
38
|
+
networkPassphrase: string;
|
|
39
|
+
contracts: ContractAddresses;
|
|
40
|
+
}
|
|
41
|
+
declare const TESTNET: NetworkConfig;
|
|
42
|
+
/**
|
|
43
|
+
* Stellar's mainnet (Public Network) passphrase -- a fixed protocol
|
|
44
|
+
* constant defined by the network itself (verified against
|
|
45
|
+
* https://developers.stellar.org/docs/encyclopedia/network-passphrases),
|
|
46
|
+
* not something that depends on which contracts (if any) are deployed.
|
|
47
|
+
* Safe to hardcode, unlike a mainnet RPC URL (see `buildMainnetConfig`).
|
|
48
|
+
*/
|
|
49
|
+
declare const MAINNET_NETWORK_PASSPHRASE = "Public Global Stellar Network ; September 2015";
|
|
50
|
+
/**
|
|
51
|
+
* Unlike testnet (SDF hosts `https://soroban-testnet.stellar.org` for
|
|
52
|
+
* free), SDF does **not** operate a free public mainnet Soroban RPC
|
|
53
|
+
* endpoint -- confirmed against
|
|
54
|
+
* https://developers.stellar.org/docs/data/apis/rpc/providers, which
|
|
55
|
+
* lists only third-party ecosystem providers (QuickNode, Ankr, Tatum,
|
|
56
|
+
* Blockdaemon, etc.) for mainnet. There is no single correct default to
|
|
57
|
+
* hardcode here, so `buildMainnetConfig` reads this env var instead of
|
|
58
|
+
* assuming a provider on your behalf -- set it to whichever provider's
|
|
59
|
+
* URL you've chosen, or pass `rpcUrl` to that function directly.
|
|
60
|
+
*/
|
|
61
|
+
declare const MAINNET_RPC_URL_ENV = "STA_MAINNET_RPC_URL";
|
|
62
|
+
/**
|
|
63
|
+
* Builds a mainnet `NetworkConfig` once the contracts are actually deployed
|
|
64
|
+
* there. No mainnet deployment exists yet -- this function exists so this
|
|
65
|
+
* module is ready to receive real mainnet addresses the moment a
|
|
66
|
+
* deployment happens, not to fabricate one now.
|
|
67
|
+
*
|
|
68
|
+
* A `NetworkConfig` with `network: "mainnet"` and real signing keys
|
|
69
|
+
* submits real, fee-paying, fund-moving transactions against Stellar's
|
|
70
|
+
* production ledger -- don't build one just to "try it out" with testnet
|
|
71
|
+
* addresses.
|
|
72
|
+
*
|
|
73
|
+
* @param contracts The six real contract addresses from an actual mainnet
|
|
74
|
+
* deployment record (mirroring how `TESTNET.contracts` above is sourced
|
|
75
|
+
* from the smart-contracts repo's docs/TESTNET_FACTORY_DEPLOYMENT.md).
|
|
76
|
+
* @param rpcUrl Your chosen mainnet RPC provider's URL. Defaults to
|
|
77
|
+
* `process.env[MAINNET_RPC_URL_ENV]`; throws if neither is supplied,
|
|
78
|
+
* rather than silently falling back to some hardcoded provider.
|
|
79
|
+
*/
|
|
80
|
+
declare function buildMainnetConfig(contracts: ContractAddresses, rpcUrl?: string): NetworkConfig;
|
|
81
|
+
/** `undefined` until `buildMainnetConfig` is actually called with real,
|
|
82
|
+
* deployed contract addresses -- see this module's doc comment and that
|
|
83
|
+
* function's. No mainnet deployment exists yet. */
|
|
84
|
+
declare const MAINNET: NetworkConfig | undefined;
|
|
85
|
+
declare const NETWORKS: {
|
|
86
|
+
readonly testnet: NetworkConfig;
|
|
87
|
+
readonly mainnet: undefined;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* `smart_account`'s custom-account authorization: "Entry A" / "Entry B"
|
|
92
|
+
* construction ("sta-sdk").
|
|
93
|
+
*
|
|
94
|
+
* Deliberately does not depend on the Stellar CLI's generated per-contract
|
|
95
|
+
* bindings (`stellar contract bindings typescript`) for this encoding:
|
|
96
|
+
* those bindings pin to a specific `@stellar/stellar-sdk` major, and
|
|
97
|
+
* loading a second major of the same classes (`Address`, `xdr.ScVal`, ...)
|
|
98
|
+
* in a consumer's bundle risks `instanceof` mismatches between them. This
|
|
99
|
+
* module hand-encodes the `AuthPayload` struct shape directly instead
|
|
100
|
+
* (`smartAccountAuthPayloadScVal` below), verified against the real
|
|
101
|
+
* `#[contracttype]` definition (`{ signers: Map<Signer, Bytes>,
|
|
102
|
+
* context_rule_ids: Vec<u32> }`) rather than derived from a generated
|
|
103
|
+
* client's `Spec`.
|
|
104
|
+
*
|
|
105
|
+
* `smart_account` implements Soroban's `CustomAccountInterface`
|
|
106
|
+
* (`__check_auth`), composed from OpenZeppelin's `stellar-accounts` crate.
|
|
107
|
+
* Any call that does `env.current_contract_address().require_auth()` --
|
|
108
|
+
* every fund-moving or schedule-creating entrypoint -- needs the
|
|
109
|
+
* transaction to carry a `SorobanAuthorizationEntry` whose
|
|
110
|
+
* `credentials.signature` is not a signature at all, but a
|
|
111
|
+
* contract-defined `AuthPayload` struct.
|
|
112
|
+
*
|
|
113
|
+
* Two entries are required per required `Signer::Delegated` signer:
|
|
114
|
+
*
|
|
115
|
+
* - **Entry A** (once, for `smart_account` itself): the `AuthPayload`
|
|
116
|
+
* structure -- no wallet interaction, assembled directly from the
|
|
117
|
+
* caller-supplied context rule id(s).
|
|
118
|
+
* - **Entry B** (one per required signer): a standard classic-account
|
|
119
|
+
* authorization entry for the nested
|
|
120
|
+
* `addr.require_auth_for_args((auth_digest,))` call -- this is what a
|
|
121
|
+
* wallet (or a raw `Keypair`, server-side) actually signs, via
|
|
122
|
+
* `@stellar/stellar-sdk`'s own `authorizeEntry`.
|
|
123
|
+
*/
|
|
124
|
+
|
|
125
|
+
interface SubInvocationSpec {
|
|
126
|
+
contractId: string;
|
|
127
|
+
functionName: string;
|
|
128
|
+
args: xdr.ScVal[];
|
|
129
|
+
subInvocations?: xdr.SorobanAuthorizedInvocation[];
|
|
130
|
+
}
|
|
131
|
+
declare function buildInvocation(spec: SubInvocationSpec): xdr.SorobanAuthorizedInvocation;
|
|
132
|
+
/** The standard Soroban authorization-entry signature payload: the hash of
|
|
133
|
+
* the `HashIdPreimage::SorobanAuthorization` preimage over a given
|
|
134
|
+
* invocation, nonce, and expiration ledger. Every `Address` credential
|
|
135
|
+
* (custom-account or classic) signs a value derived from this. */
|
|
136
|
+
declare function signaturePayload(invocation: xdr.SorobanAuthorizedInvocation, nonce: bigint, signatureExpirationLedger: number, networkPassphrase: string): Buffer;
|
|
137
|
+
interface BuildSmartAccountAuthOptions {
|
|
138
|
+
smartAccountId: string;
|
|
139
|
+
/** The actual `smart_account` call being authorized (its root
|
|
140
|
+
* invocation) -- e.g. `execute_transfer_payment(...)`. Declare any
|
|
141
|
+
* further sub-invocations that must be pre-cleared by this SAME entry
|
|
142
|
+
* as its `subInvocations`. */
|
|
143
|
+
rootInvocation: xdr.SorobanAuthorizedInvocation;
|
|
144
|
+
/** G-address of the `Signer::Delegated` wallet authorizing this call. */
|
|
145
|
+
signerAddress: string;
|
|
146
|
+
/** Signs Entry B's classic authorization entry -- a raw `Keypair` for
|
|
147
|
+
* server-side use, or a `SigningCallback` forwarding to a connected
|
|
148
|
+
* wallet's `signAuthEntry`. */
|
|
149
|
+
sign: Keypair | SigningCallback;
|
|
150
|
+
networkPassphrase: string;
|
|
151
|
+
/** Context rule id(s) the signer is registered under, one per auth
|
|
152
|
+
* context reaching `__check_auth` (root + any declared
|
|
153
|
+
* sub-invocation). Default: `[0]` (the founding rule), applied to every
|
|
154
|
+
* context. */
|
|
155
|
+
contextRuleIds?: number[];
|
|
156
|
+
signatureExpirationLedger: number;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Builds Entry A + Entry B for a single required `Signer::Delegated`.
|
|
160
|
+
*
|
|
161
|
+
* KNOWN ISSUE: for a multi-signer context rule (threshold > 1), calling
|
|
162
|
+
* this once per signer and attaching each pair produces N separate
|
|
163
|
+
* Entry As, each with a single-key `signers` map. That does not match
|
|
164
|
+
* `DAPP_INTEGRATION_SPEC.md` §5.4, which specifies one shared Entry A
|
|
165
|
+
* carrying all N signers' keys plus N Entry Bs (one per signer) collected
|
|
166
|
+
* against that same Entry A over time. Multi-signer callers should not
|
|
167
|
+
* rely on this function as-is until that's reconciled -- track before
|
|
168
|
+
* shipping real M-of-N threshold support.
|
|
169
|
+
*/
|
|
170
|
+
declare function buildSmartAccountAuthEntries(opts: BuildSmartAccountAuthOptions): Promise<[xdr.SorobanAuthorizationEntry, xdr.SorobanAuthorizationEntry]>;
|
|
171
|
+
interface BuildExecutorAuthOptions {
|
|
172
|
+
intentRegistryId: string;
|
|
173
|
+
intentId: Buffer;
|
|
174
|
+
childSequence: number;
|
|
175
|
+
executorAddress: string;
|
|
176
|
+
sign: Keypair | SigningCallback;
|
|
177
|
+
networkPassphrase: string;
|
|
178
|
+
signatureExpirationLedger: number;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Authorizes `intent_registry.mark_child_executed`, the *only* real
|
|
182
|
+
* authorization check in `execute_scheduled_payment`'s whole call graph.
|
|
183
|
+
*
|
|
184
|
+
* `SourceAccount`/auto-fill credentials only cover a `require_auth()` at
|
|
185
|
+
* the ROOT of the invocation tree; `mark_child_executed`'s
|
|
186
|
+
* `executor.require_auth()` is two levels deep (`execute_scheduled_payment
|
|
187
|
+
* -> intent_registry.mark_child_executed -> ensure_executor`), so it needs
|
|
188
|
+
* an explicit entry, built and signed the same way as any other non-root
|
|
189
|
+
* classic-account authorization -- this is *not* custom-account machinery
|
|
190
|
+
* (the executor is a plain account), so no `AuthPayload`/Entry-A-Entry-B
|
|
191
|
+
* pairing is involved, just one ordinary signed entry rooted directly at
|
|
192
|
+
* `mark_child_executed`. Verified against live testnet (see the
|
|
193
|
+
* smart-contracts repo's docs/TESTNET_FACTORY_DEPLOYMENT.md §8 and
|
|
194
|
+
* docs/DAPP_INTEGRATION_SPEC.md §8), and independently against this same
|
|
195
|
+
* failure mode in this dApp's own `src/lib/relayer/executor.ts`.
|
|
196
|
+
*/
|
|
197
|
+
declare function buildExecutorAuthEntry(opts: BuildExecutorAuthOptions): Promise<xdr.SorobanAuthorizationEntry>;
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Transaction-preparation helpers: prepare -> simulate -> approve. Each
|
|
201
|
+
* function returns a prepared, auth-entry-attached `Transaction` --
|
|
202
|
+
* simulated (fee/resource estimation) with the custom `smart_account`
|
|
203
|
+
* `AuthPayload` entries already present, ready for the caller to sign the
|
|
204
|
+
* envelope with a fee-paying account and submit (see `signAndSubmit`
|
|
205
|
+
* below). None of these functions touch a wallet directly -- signing is
|
|
206
|
+
* always an injected `Keypair | SigningCallback` (see `auth.ts`), so a
|
|
207
|
+
* browser dApp can swap in a connected wallet's `signAuthEntry` without
|
|
208
|
+
* changing anything here.
|
|
209
|
+
*
|
|
210
|
+
* Call args are hand-encoded (`transferArgs`, `splitArgs`,
|
|
211
|
+
* `scheduledIntentScVal`, below) against the contracts' real signatures,
|
|
212
|
+
* rather than through a generated-bindings client's
|
|
213
|
+
* `.spec.funcArgsToScVals(...)` -- see `auth.ts`'s module doc comment for
|
|
214
|
+
* why this SDK avoids depending on those generated bindings directly.
|
|
215
|
+
*/
|
|
216
|
+
|
|
217
|
+
interface PrepareOptions {
|
|
218
|
+
net: NetworkConfig;
|
|
219
|
+
/** Any funded account that pays the network fee -- independent of who
|
|
220
|
+
* authorizes the `smart_account` call. Only its public key is needed to
|
|
221
|
+
* build the transaction. */
|
|
222
|
+
feeSourceAddress: string;
|
|
223
|
+
signerAddress: string;
|
|
224
|
+
sign: Keypair | SigningCallback;
|
|
225
|
+
contextRuleIds?: number[];
|
|
226
|
+
}
|
|
227
|
+
interface TransferPaymentArgs {
|
|
228
|
+
asset: string;
|
|
229
|
+
destination: string;
|
|
230
|
+
amount: bigint;
|
|
231
|
+
nonce: bigint;
|
|
232
|
+
expectedPolicyVersion: number;
|
|
233
|
+
}
|
|
234
|
+
declare function prepareTransferPayment(opts: PrepareOptions, payment: TransferPaymentArgs): Promise<Transaction>;
|
|
235
|
+
interface SplitPaymentArgs {
|
|
236
|
+
asset: string;
|
|
237
|
+
recipients: string[];
|
|
238
|
+
amounts: bigint[];
|
|
239
|
+
nonce: bigint;
|
|
240
|
+
expectedPolicyVersion: number;
|
|
241
|
+
}
|
|
242
|
+
declare function prepareSplitPayment(opts: PrepareOptions, payment: SplitPaymentArgs): Promise<Transaction>;
|
|
243
|
+
interface ScheduledIntentArgs {
|
|
244
|
+
intent_id: Buffer;
|
|
245
|
+
asset: string;
|
|
246
|
+
destination: string;
|
|
247
|
+
amount: bigint;
|
|
248
|
+
start_ledger: number;
|
|
249
|
+
end_ledger: number;
|
|
250
|
+
interval_ledgers: number;
|
|
251
|
+
max_executions: number;
|
|
252
|
+
/** Ignored/overwritten server-side, pinned to `0` at creation -- pass any
|
|
253
|
+
* placeholder value; read the resolved field back from the
|
|
254
|
+
* `IntentCreated` event or a follow-up `get_intent` read. */
|
|
255
|
+
execution_count: number;
|
|
256
|
+
/** Ignored/overwritten server-side, pinned to `policy_engine.version()`
|
|
257
|
+
* at creation time -- see `execution_count` above. */
|
|
258
|
+
policy_version: number;
|
|
259
|
+
/** Ignored/overwritten server-side, pinned to the currently configured
|
|
260
|
+
* `transfer_adapter` at creation time -- see `execution_count` above. */
|
|
261
|
+
adapter: string;
|
|
262
|
+
cancelled: boolean;
|
|
263
|
+
}
|
|
264
|
+
/** `intent`'s caller-supplied `policy_version`/`adapter` are ignored and
|
|
265
|
+
* overwritten by the contract (pinned to current values at approval time)
|
|
266
|
+
* -- pass any placeholder value; read the resolved fields back from the
|
|
267
|
+
* `IntentCreated` event or a follow-up `get_intent` read. */
|
|
268
|
+
declare function prepareScheduledPayment(opts: PrepareOptions, intent: ScheduledIntentArgs): Promise<Transaction>;
|
|
269
|
+
declare function prepareCancelScheduledPayment(opts: PrepareOptions, intentId: Buffer): Promise<Transaction>;
|
|
270
|
+
/** Signs the transaction envelope with the fee-paying account's key
|
|
271
|
+
* (independent of the `smart_account` auth entries, already attached by
|
|
272
|
+
* `prepare*`) and submits it, polling until a terminal status. */
|
|
273
|
+
declare function signAndSubmit(net: NetworkConfig, tx: Transaction, feeSourceKeypair: Keypair): Promise<rpc.Api.GetSuccessfulTransactionResponse>;
|
|
274
|
+
interface RelayerExecuteOptions {
|
|
275
|
+
net: NetworkConfig;
|
|
276
|
+
intentId: Buffer;
|
|
277
|
+
childSequence: number;
|
|
278
|
+
executorAddress: string;
|
|
279
|
+
sign: Keypair | SigningCallback;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Prepares a relayer's `execute_scheduled_payment` call. Unlike the
|
|
283
|
+
* signer-authored payment helpers above, this needs no `smart_account`
|
|
284
|
+
* `AuthPayload` at all -- only an explicit authorization entry for
|
|
285
|
+
* `intent_registry.mark_child_executed`'s `Executor` requirement (see
|
|
286
|
+
* `buildExecutorAuthEntry`'s doc comment in `auth.ts`).
|
|
287
|
+
*/
|
|
288
|
+
declare function prepareRelayerExecution(opts: RelayerExecuteOptions): Promise<Transaction>;
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Typed event parsing. Depends only on `@stellar/stellar-sdk`'s
|
|
292
|
+
* `xdr`/`scValToNative` -- no generated per-contract bindings involved.
|
|
293
|
+
* Keep in sync by hand if the source contracts' `#[contractevent]`
|
|
294
|
+
* definitions change — there is no automated link between this package
|
|
295
|
+
* and the contracts repo.
|
|
296
|
+
*
|
|
297
|
+
* The Stellar CLI's generated bindings expose function signatures, errors,
|
|
298
|
+
* and structs from a contract's spec, but not its `#[contractevent]`
|
|
299
|
+
* definitions — those are hand-typed here, against the actual struct
|
|
300
|
+
* definitions in each contract's `src/lib.rs`, and are exposed as
|
|
301
|
+
* first-class types rather than raw event XDR.
|
|
302
|
+
*
|
|
303
|
+
* Every `#[contractevent]` struct is encoded on-chain as: topics[0] = the
|
|
304
|
+
* event's short topic symbol (see the smart-contracts repo's
|
|
305
|
+
* docs/DAPP_INTEGRATION_SPEC.md §10.4), followed by any further
|
|
306
|
+
* `#[topic]`-tagged fields, then a data map of the remaining fields keyed
|
|
307
|
+
* by their Rust field name.
|
|
308
|
+
*/
|
|
309
|
+
|
|
310
|
+
interface TransferPaid {
|
|
311
|
+
asset: string;
|
|
312
|
+
destination: string;
|
|
313
|
+
amount: bigint;
|
|
314
|
+
nonce: bigint;
|
|
315
|
+
}
|
|
316
|
+
interface SplitPaid {
|
|
317
|
+
asset: string;
|
|
318
|
+
recipient_count: number;
|
|
319
|
+
nonce: bigint;
|
|
320
|
+
}
|
|
321
|
+
interface ScheduledPaymentExecuted {
|
|
322
|
+
intent_id: Buffer;
|
|
323
|
+
child_sequence: number;
|
|
324
|
+
asset: string;
|
|
325
|
+
destination: string;
|
|
326
|
+
amount: bigint;
|
|
327
|
+
}
|
|
328
|
+
interface PolicyValidated {
|
|
329
|
+
operation: string;
|
|
330
|
+
asset: string;
|
|
331
|
+
destination: string;
|
|
332
|
+
amount: bigint;
|
|
333
|
+
expected_version: number;
|
|
334
|
+
}
|
|
335
|
+
interface IntentCreated {
|
|
336
|
+
intent_id: Buffer;
|
|
337
|
+
}
|
|
338
|
+
interface IntentCancelled {
|
|
339
|
+
intent_id: Buffer;
|
|
340
|
+
}
|
|
341
|
+
interface ChildExecuted {
|
|
342
|
+
intent_id: Buffer;
|
|
343
|
+
child_sequence: number;
|
|
344
|
+
}
|
|
345
|
+
interface RecoveryOpened {
|
|
346
|
+
request_id: Buffer;
|
|
347
|
+
}
|
|
348
|
+
interface RecoveryApproved {
|
|
349
|
+
request_id: Buffer;
|
|
350
|
+
guardian: string;
|
|
351
|
+
}
|
|
352
|
+
interface RecoveryFinalized {
|
|
353
|
+
request_id: Buffer;
|
|
354
|
+
replacement_owner: string;
|
|
355
|
+
}
|
|
356
|
+
interface RecoveryApplied {
|
|
357
|
+
request_id: Buffer;
|
|
358
|
+
replacement_owner: string;
|
|
359
|
+
}
|
|
360
|
+
interface GuardianFreezeRequested {
|
|
361
|
+
guardian: string;
|
|
362
|
+
}
|
|
363
|
+
interface Frozen {
|
|
364
|
+
triggered_by_guardian: boolean;
|
|
365
|
+
}
|
|
366
|
+
/** Every event type this module knows how to decode, keyed by its on-chain
|
|
367
|
+
* topic symbol. Add new entries here as new contract events are curated. */
|
|
368
|
+
interface EventMap {
|
|
369
|
+
pay_ok: TransferPaid;
|
|
370
|
+
splt_ok: SplitPaid;
|
|
371
|
+
auto_ok: ScheduledPaymentExecuted;
|
|
372
|
+
pol_ok: PolicyValidated;
|
|
373
|
+
intent: IntentCreated;
|
|
374
|
+
cancel: IntentCancelled;
|
|
375
|
+
exec: ChildExecuted;
|
|
376
|
+
open: RecoveryOpened;
|
|
377
|
+
appr: RecoveryApproved;
|
|
378
|
+
final: RecoveryFinalized;
|
|
379
|
+
recover: RecoveryApplied;
|
|
380
|
+
gfreeze: GuardianFreezeRequested;
|
|
381
|
+
frozen: Frozen;
|
|
382
|
+
}
|
|
383
|
+
type ParsedEvent = {
|
|
384
|
+
[K in keyof EventMap]: {
|
|
385
|
+
topic: K;
|
|
386
|
+
event: EventMap[K];
|
|
387
|
+
};
|
|
388
|
+
}[keyof EventMap] | {
|
|
389
|
+
topic: string;
|
|
390
|
+
event: Record<string, unknown>;
|
|
391
|
+
};
|
|
392
|
+
/** Parses one `xdr.ContractEvent` into its typed shape, matched by topic,
|
|
393
|
+
* merging `#[topic]`-tagged fields (from `topics[1..]`) with the data map
|
|
394
|
+
* -- both are needed to reconstruct the full `#[contractevent]` struct.
|
|
395
|
+
* Unknown topics still parse -- as `{ topic, event: <raw decoded map> }`
|
|
396
|
+
* -- rather than throwing, so a caller can log/inspect an event this
|
|
397
|
+
* module doesn't have a named type for yet. */
|
|
398
|
+
declare function parseContractEvent(event: xdr.ContractEvent): ParsedEvent;
|
|
399
|
+
/** Parses every event from a `getTransaction` response's
|
|
400
|
+
* `events.contractEventsXdr` (one array of events per operation -- this
|
|
401
|
+
* dApp's transactions always have exactly one operation, so pass
|
|
402
|
+
* `contractEventsXdr[0]`). */
|
|
403
|
+
declare function parseContractEvents(events: xdr.ContractEvent[]): ParsedEvent[];
|
|
404
|
+
declare function findEvent<T extends keyof EventMap>(events: ParsedEvent[], topic: T): EventMap[T] | undefined;
|
|
405
|
+
|
|
406
|
+
interface AccountStatus {
|
|
407
|
+
initialized: boolean;
|
|
408
|
+
paused: boolean;
|
|
409
|
+
frozen: boolean;
|
|
410
|
+
policy_version_hint: number;
|
|
411
|
+
}
|
|
412
|
+
/** From the vendored `stellar-accounts` OZ crate
|
|
413
|
+
* (`smart_account::storage::ContextRule`), not this workspace's own
|
|
414
|
+
* contracts -- `get_context_rule`'s actual return type. */
|
|
415
|
+
interface ContextRule {
|
|
416
|
+
id: number;
|
|
417
|
+
context_type: string;
|
|
418
|
+
name: string;
|
|
419
|
+
signers: unknown[];
|
|
420
|
+
signer_ids: number[];
|
|
421
|
+
policies: string[];
|
|
422
|
+
policy_ids: number[];
|
|
423
|
+
valid_until?: number;
|
|
424
|
+
}
|
|
425
|
+
interface ScheduledIntent {
|
|
426
|
+
intent_id: Buffer;
|
|
427
|
+
asset: string;
|
|
428
|
+
destination: string;
|
|
429
|
+
amount: bigint;
|
|
430
|
+
start_ledger: number;
|
|
431
|
+
end_ledger: number;
|
|
432
|
+
interval_ledgers: number;
|
|
433
|
+
max_executions: number;
|
|
434
|
+
execution_count: number;
|
|
435
|
+
policy_version: number;
|
|
436
|
+
adapter: string;
|
|
437
|
+
cancelled: boolean;
|
|
438
|
+
}
|
|
439
|
+
interface RecoveryRequest {
|
|
440
|
+
request_id: Buffer;
|
|
441
|
+
replacement_owner: string;
|
|
442
|
+
replacement_signers: unknown[];
|
|
443
|
+
replacement_policies: Record<string, unknown>;
|
|
444
|
+
earliest_ledger: number;
|
|
445
|
+
approvers: string[];
|
|
446
|
+
cancelled: boolean;
|
|
447
|
+
finalized: boolean;
|
|
448
|
+
}
|
|
449
|
+
interface WasmHashes {
|
|
450
|
+
policy_engine: Buffer;
|
|
451
|
+
intent_registry: Buffer;
|
|
452
|
+
recovery_manager: Buffer;
|
|
453
|
+
transfer_adapter: Buffer;
|
|
454
|
+
split_adapter: Buffer;
|
|
455
|
+
smart_account: Buffer;
|
|
456
|
+
}
|
|
457
|
+
/** `smart_account.status()` -- check before offering any payment action; a
|
|
458
|
+
* paused or frozen treasury should disable the payment UI, not let the
|
|
459
|
+
* user hit a rejected simulation. */
|
|
460
|
+
declare function readAccountStatus(net: NetworkConfig, sourceAddress: string): Promise<AccountStatus>;
|
|
461
|
+
declare function readOwner(net: NetworkConfig, sourceAddress: string): Promise<string | null>;
|
|
462
|
+
/** Rule IDs are `0..count`, not necessarily contiguous after removals --
|
|
463
|
+
* check existence with `readContextRule`, don't assume. */
|
|
464
|
+
declare function readContextRulesCount(net: NetworkConfig, sourceAddress: string): Promise<number>;
|
|
465
|
+
declare function readContextRule(net: NetworkConfig, sourceAddress: string, contextRuleId: number): Promise<ContextRule>;
|
|
466
|
+
declare function isNonceUsed(net: NetworkConfig, sourceAddress: string, nonce: bigint): Promise<boolean>;
|
|
467
|
+
/** The authoritative current policy version -- read fresh immediately
|
|
468
|
+
* before building a payment, never cached across a user session (a stale
|
|
469
|
+
* value here causes a clean `VersionMismatch` rejection rather than
|
|
470
|
+
* executing under outdated rules). */
|
|
471
|
+
declare function readPolicyVersion(net: NetworkConfig, sourceAddress: string): Promise<number>;
|
|
472
|
+
declare function readScheduledIntent(net: NetworkConfig, sourceAddress: string, intentId: Buffer): Promise<ScheduledIntent>;
|
|
473
|
+
declare function isChildExecuted(net: NetworkConfig, sourceAddress: string, intentId: Buffer, childSequence: number): Promise<boolean>;
|
|
474
|
+
/** Recovery-request state -- first-class typed state, not a raw XDR blob. */
|
|
475
|
+
declare function readRecoveryRequest(net: NetworkConfig, sourceAddress: string, requestId: Buffer): Promise<RecoveryRequest>;
|
|
476
|
+
declare function readLiveApprovalCount(net: NetworkConfig, sourceAddress: string, requestId: Buffer): Promise<number>;
|
|
477
|
+
declare function isGuardian(net: NetworkConfig, sourceAddress: string, guardian: string): Promise<boolean>;
|
|
478
|
+
/** Monotonically increasing, never-cleared -- compare against a locally
|
|
479
|
+
* stored "last applied" value to detect a pending guardian freeze rather
|
|
480
|
+
* than treating this as a boolean. */
|
|
481
|
+
declare function readGuardianFreezeEpoch(net: NetworkConfig, sourceAddress: string): Promise<number>;
|
|
482
|
+
declare function readFactoryWasmHashes(net: NetworkConfig, sourceAddress: string): Promise<WasmHashes>;
|
|
483
|
+
|
|
484
|
+
export { type AccountStatus, type BuildExecutorAuthOptions, type BuildSmartAccountAuthOptions, type ChildExecuted, type ContextRule, type ContractAddresses, type EventMap, type Frozen, type GuardianFreezeRequested, type IntentCancelled, type IntentCreated, MAINNET, MAINNET_NETWORK_PASSPHRASE, MAINNET_RPC_URL_ENV, NETWORKS, type NetworkConfig, type ParsedEvent, type PolicyValidated, type PrepareOptions, type RecoveryApplied, type RecoveryApproved, type RecoveryFinalized, type RecoveryOpened, type RecoveryRequest, type RelayerExecuteOptions, type ScheduledIntent, type ScheduledIntentArgs, type ScheduledPaymentExecuted, type SplitPaid, type SplitPaymentArgs, type SubInvocationSpec, TESTNET, type TransferPaid, type TransferPaymentArgs, type WasmHashes, buildExecutorAuthEntry, buildInvocation, buildMainnetConfig, buildSmartAccountAuthEntries, findEvent, isChildExecuted, isGuardian, isNonceUsed, parseContractEvent, parseContractEvents, prepareCancelScheduledPayment, prepareRelayerExecution, prepareScheduledPayment, prepareSplitPayment, prepareTransferPayment, readAccountStatus, readContextRule, readContextRulesCount, readFactoryWasmHashes, readGuardianFreezeEpoch, readLiveApprovalCount, readOwner, readPolicyVersion, readRecoveryRequest, readScheduledIntent, signAndSubmit, signaturePayload };
|