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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/config.ts","../src/scval.ts","../src/auth.ts","../src/payments.ts","../src/events.ts","../src/state.ts"],"names":["xdr","Address","hash","authorizeEntry","nativeToScVal","TransactionBuilder","BASE_FEE","Operation","rpc","scValToNative","Contract","u32ScVal","u64ScVal","bytesN32ScVal","addressScVal"],"mappings":";;;;;AAwCO,IAAM,OAAA,GAAyB;AAAA,EACpC,OAAA,EAAS,SAAA;AAAA,EACT,MAAA,EAAQ,qCAAA;AAAA,EACR,iBAAA,EAAmB,mCAAA;AAAA,EACnB,SAAA,EAAW;AAAA,IACT,YAAA,EAAc,0DAAA;AAAA,IACd,YAAA,EAAc,0DAAA;AAAA,IACd,cAAA,EAAgB,0DAAA;AAAA,IAChB,eAAA,EAAiB,0DAAA;AAAA,IACjB,cAAA,EAAgB,0DAAA;AAAA,IAChB,eAAA,EAAiB,0DAAA;AAAA,IACjB,YAAA,EAAc;AAAA;AAElB;AASO,IAAM,0BAAA,GAA6B;AAanC,IAAM,mBAAA,GAAsB;AAoB5B,SAAS,kBAAA,CACd,SAAA,EACA,MAAA,GAAA,CAAkB,OAAO,OAAA,KAAY,WAAA,GAAc,OAAA,CAAQ,GAAA,GAAM,mBAAmB,CAAA,GAAI,MAAA,KAAc,EAAA,EACvF;AACf,EAAA,IAAI,CAAC,MAAA,EAAQ;AACX,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,uFAAuF,mBAAmB,CAAA,qIAAA;AAAA,KAC5G;AAAA,EACF;AACA,EAAA,OAAO;A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AEA,eAAsB,qBAAA,CAAsB,KAAoB,aAAA,EAA4C;AAC1G,EAAA,OAAQ,MAAM,YAAA;AAAA,IACZ,GAAA;AAAA,IACA,aAAA;AAAA,IACA,IAAI,SAAA,CAAU,cAAA;AAAA,IACd;AAAA,GACF;AACF","file":"index.cjs","sourcesContent":["/**\n * Network configuration for `sta-sdk`.\n *\n * `testnet` is populated with the live, currently-deployed contract set --\n * the `smart_account` address is the account_factory-deployed treasury from\n * the smart-contracts repo's docs/TESTNET_FACTORY_DEPLOYMENT.md §13.2,\n * which runs the fixed contract code (see docs/SECURITY_REVIEW_STRICT.md\n * finding 29). The older hand-deployed treasury from docs/TESTNET_DEPLOYMENT.md\n * predates that fix and is not the default here.\n *\n * `MAINNET` stays `undefined` until `buildMainnetConfig` is actually called\n * with real, deployed contract addresses -- no mainnet deployment exists\n * yet, and nothing here fabricates one. What *is* ready now is the rest of\n * the mainnet shape: the real, verified mainnet network passphrase\n * (`MAINNET_NETWORK_PASSPHRASE`, a fixed protocol constant, unlike an RPC\n * URL) and `buildMainnetConfig` itself, so wiring in a real mainnet\n * deployment later is \"call this function with the six addresses,\" not a\n * code change.\n */\n\nexport interface ContractAddresses {\n smartAccount: string;\n policyEngine: string;\n intentRegistry: string;\n recoveryManager: string;\n accountFactory: string;\n /** Never called directly by a client (see docs/DAPP_INTEGRATION_SPEC.md\n * §1) -- recorded for reference and for building auth-entry\n * sub-invocations by hand. */\n transferAdapter: string;\n splitAdapter: string;\n}\n\nexport interface NetworkConfig {\n network: \"testnet\" | \"mainnet\";\n rpcUrl: string;\n networkPassphrase: string;\n contracts: ContractAddresses;\n}\n\nexport const TESTNET: NetworkConfig = {\n network: \"testnet\",\n rpcUrl: \"https://soroban-testnet.stellar.org\",\n networkPassphrase: \"Test SDF Network ; September 2015\",\n contracts: {\n smartAccount: \"CD6GY4UUTNPW4TUV7LDL5SELN4BBHJG4KDDT3W6G23DY6XCGM75MULMQ\",\n policyEngine: \"CCOP7NRMST5K6TL7FBDMX25LDEPW3DSFBOGBIKVFIDNAAZY7GBMVP3M4\",\n intentRegistry: \"CAFIATSIZQSBILZJWVT4PVDXPVITJHLP6LPAVKDRHCA7I7XPZSLTRPUS\",\n recoveryManager: \"CCHC4YKVYS3CAZUOUYWYTEMQ6TZDW75WB2BGENUC2CDWDX5RH7NMKZWU\",\n accountFactory: \"CAQQTRRYNXIQGFVNCTMTBJDXW3PN7O44KPT7GWCCE4FRKTOHDBCWGUZO\",\n transferAdapter: \"CBRYGIR3ORDW5LE6J7AVPSKRNTMRUYHD6FVPHQMJGPQLQ5FQUZ2U6GFH\",\n splitAdapter: \"CBQA7UI7QN6RN4IZT7WPDHWTK2OO7J4FH2KMCVJGKMKVFGDURD63UQ7U\",\n },\n};\n\n/**\n * Stellar's mainnet (Public Network) passphrase -- a fixed protocol\n * constant defined by the network itself (verified against\n * https://developers.stellar.org/docs/encyclopedia/network-passphrases),\n * not something that depends on which contracts (if any) are deployed.\n * Safe to hardcode, unlike a mainnet RPC URL (see `buildMainnetConfig`).\n */\nexport const MAINNET_NETWORK_PASSPHRASE = \"Public Global Stellar Network ; September 2015\";\n\n/**\n * Unlike testnet (SDF hosts `https://soroban-testnet.stellar.org` for\n * free), SDF does **not** operate a free public mainnet Soroban RPC\n * endpoint -- confirmed against\n * https://developers.stellar.org/docs/data/apis/rpc/providers, which\n * lists only third-party ecosystem providers (QuickNode, Ankr, Tatum,\n * Blockdaemon, etc.) for mainnet. There is no single correct default to\n * hardcode here, so `buildMainnetConfig` reads this env var instead of\n * assuming a provider on your behalf -- set it to whichever provider's\n * URL you've chosen, or pass `rpcUrl` to that function directly.\n */\nexport const MAINNET_RPC_URL_ENV = \"STA_MAINNET_RPC_URL\";\n\n/**\n * Builds a mainnet `NetworkConfig` once the contracts are actually deployed\n * there. No mainnet deployment exists yet -- this function exists so this\n * module is ready to receive real mainnet addresses the moment a\n * deployment happens, not to fabricate one now.\n *\n * A `NetworkConfig` with `network: \"mainnet\"` and real signing keys\n * submits real, fee-paying, fund-moving transactions against Stellar's\n * production ledger -- don't build one just to \"try it out\" with testnet\n * addresses.\n *\n * @param contracts The six real contract addresses from an actual mainnet\n * deployment record (mirroring how `TESTNET.contracts` above is sourced\n * from the smart-contracts repo's docs/TESTNET_FACTORY_DEPLOYMENT.md).\n * @param rpcUrl Your chosen mainnet RPC provider's URL. Defaults to\n * `process.env[MAINNET_RPC_URL_ENV]`; throws if neither is supplied,\n * rather than silently falling back to some hardcoded provider.\n */\nexport function buildMainnetConfig(\n contracts: ContractAddresses,\n rpcUrl: string = (typeof process !== \"undefined\" ? process.env?.[MAINNET_RPC_URL_ENV] : undefined) ?? \"\",\n): NetworkConfig {\n if (!rpcUrl) {\n throw new Error(\n `Mainnet RPC URL not configured -- pass one explicitly to buildMainnetConfig, or set ${MAINNET_RPC_URL_ENV}. SDF hosts no free public mainnet endpoint; see https://developers.stellar.org/docs/data/apis/rpc/providers for ecosystem providers.`,\n );\n }\n return {\n network: \"mainnet\",\n rpcUrl,\n networkPassphrase: MAINNET_NETWORK_PASSPHRASE,\n contracts,\n };\n}\n\n/** `undefined` until `buildMainnetConfig` is actually called with real,\n * deployed contract addresses -- see this module's doc comment and that\n * function's. No mainnet deployment exists yet. */\nexport const MAINNET: NetworkConfig | undefined = undefined;\n\nexport const NETWORKS = {\n testnet: TESTNET,\n mainnet: MAINNET,\n} as const;\n","import { xdr } from \"@stellar/stellar-sdk\";\n\n/**\n * Builds the `ScMap` representation of a Soroban `#[contracttype]` struct.\n *\n * Keys are sorted, because the Soroban host requires it: an unsorted map is\n * rejected before the contract runs, with `Error(Object, InvalidInput)` and the\n * diagnostic \"ScMap was not sorted by key for conversion to host object\". The\n * Rust field declaration order is irrelevant to the wire format, so building\n * these maps in struct order — the intuitive thing to do — silently produces\n * calls that can never succeed.\n *\n * Plain string comparison is byte-order comparison here: Soroban symbols are\n * restricted to `[a-zA-Z0-9_]`, so UTF-16 code-unit order and UTF-8 byte order\n * agree.\n */\nexport function structScVal(fields: Record<string, xdr.ScVal>): xdr.ScVal {\n return xdr.ScVal.scvMap(\n Object.entries(fields)\n .sort(([left], [right]) => (left < right ? -1 : left > right ? 1 : 0))\n .map(\n ([key, val]) =>\n new xdr.ScMapEntry({\n key: xdr.ScVal.scvSymbol(key),\n val,\n }),\n ),\n );\n}\n","/**\n * `smart_account`'s custom-account authorization: \"Entry A\" / \"Entry B\"\n * construction (\"sta-sdk\").\n *\n * Deliberately does not depend on the Stellar CLI's generated per-contract\n * bindings (`stellar contract bindings typescript`) for this encoding:\n * those bindings pin to a specific `@stellar/stellar-sdk` major, and\n * loading a second major of the same classes (`Address`, `xdr.ScVal`, ...)\n * in a consumer's bundle risks `instanceof` mismatches between them. This\n * module hand-encodes the `AuthPayload` struct shape directly instead\n * (`smartAccountAuthPayloadScVal` below), verified against the real\n * `#[contracttype]` definition (`{ signers: Map<Signer, Bytes>,\n * context_rule_ids: Vec<u32> }`) rather than derived from a generated\n * client's `Spec`.\n *\n * `smart_account` implements Soroban's `CustomAccountInterface`\n * (`__check_auth`), composed from OpenZeppelin's `stellar-accounts` crate.\n * Any call that does `env.current_contract_address().require_auth()` --\n * every fund-moving or schedule-creating entrypoint -- needs the\n * transaction to carry a `SorobanAuthorizationEntry` whose\n * `credentials.signature` is not a signature at all, but a\n * contract-defined `AuthPayload` struct.\n *\n * Two entries are required per required `Signer::Delegated` signer:\n *\n * - **Entry A** (once, for `smart_account` itself): the `AuthPayload`\n * structure -- no wallet interaction, assembled directly from the\n * caller-supplied context rule id(s).\n * - **Entry B** (one per required signer): a standard classic-account\n * authorization entry for the nested\n * `addr.require_auth_for_args((auth_digest,))` call -- this is what a\n * wallet (or a raw `Keypair`, server-side) actually signs, via\n * `@stellar/stellar-sdk`'s own `authorizeEntry`.\n */\nimport { Address, hash, Keypair, xdr, type SigningCallback } from \"@stellar/stellar-sdk\";\nimport { authorizeEntry } from \"@stellar/stellar-sdk\";\n\nimport { structScVal } from \"./scval\";\n\nexport interface SubInvocationSpec {\n contractId: string;\n functionName: string;\n args: xdr.ScVal[];\n subInvocations?: xdr.SorobanAuthorizedInvocation[];\n}\n\nexport function buildInvocation(spec: SubInvocationSpec): xdr.SorobanAuthorizedInvocation {\n const fn = new xdr.InvokeContractArgs({\n contractAddress: new Address(spec.contractId).toScAddress(),\n functionName: spec.functionName,\n args: spec.args,\n });\n const func = xdr.SorobanAuthorizedFunction.sorobanAuthorizedFunctionTypeContractFn(fn);\n return new xdr.SorobanAuthorizedInvocation({\n function: func,\n subInvocations: spec.subInvocations ?? [],\n });\n}\n\nfunction networkId(networkPassphrase: string): Buffer {\n return hash(Buffer.from(networkPassphrase));\n}\n\n/** The standard Soroban authorization-entry signature payload: the hash of\n * the `HashIdPreimage::SorobanAuthorization` preimage over a given\n * invocation, nonce, and expiration ledger. Every `Address` credential\n * (custom-account or classic) signs a value derived from this. */\nexport function signaturePayload(\n invocation: xdr.SorobanAuthorizedInvocation,\n nonce: bigint,\n signatureExpirationLedger: number,\n networkPassphrase: string,\n): Buffer {\n const preimage = xdr.HashIdPreimage.envelopeTypeSorobanAuthorization(\n new xdr.HashIdPreimageSorobanAuthorization({\n networkId: networkId(networkPassphrase),\n nonce: xdr.Int64.fromString(nonce.toString()),\n signatureExpirationLedger,\n invocation,\n }),\n );\n return hash(preimage.toXDR());\n}\n\nfunction randomNonce(): bigint {\n // 62-bit random nonce, matching the upstream SDK's scripts/execute_signer_authorized_call.py.\n const high = BigInt(Math.floor(Math.random() * 2 ** 30));\n const low = BigInt(Math.floor(Math.random() * 2 ** 32));\n return (high << 32n) | low;\n}\n\n/**\n * Builds and signs one ordinary classic-account `SorobanAuthorizationEntry`\n * -- an `Address` credential whose signature is a real Ed25519 signature\n * (via `authorizeEntry`), not a contract-defined payload like\n * `smart_account`'s `AuthPayload`. Shared by Entry B of\n * `buildSmartAccountAuthEntries` (the nested `__check_auth` call a\n * `Signer::Delegated` wallet signs) and `buildExecutorAuthEntry` (the\n * relayer's `mark_child_executed` authorization) -- both are the same\n * mechanism pointed at a different invocation/address.\n */\nasync function buildClassicAuthEntry(\n address: string,\n invocation: xdr.SorobanAuthorizedInvocation,\n sign: Keypair | SigningCallback,\n signatureExpirationLedger: number,\n networkPassphrase: string,\n): Promise<xdr.SorobanAuthorizationEntry> {\n const nonce = randomNonce();\n const unsignedEntry = new xdr.SorobanAuthorizationEntry({\n credentials: xdr.SorobanCredentials.sorobanCredentialsAddress(\n new xdr.SorobanAddressCredentials({\n address: new Address(address).toScAddress(),\n nonce: xdr.Int64.fromString(nonce.toString()),\n signatureExpirationLedger,\n signature: xdr.ScVal.scvVoid(),\n }),\n ),\n rootInvocation: invocation,\n });\n return authorizeEntry(unsignedEntry, sign, signatureExpirationLedger, networkPassphrase);\n}\n\n/** Encodes `smart_account`'s `AuthPayload { signers: Map<Signer, Bytes>,\n * context_rule_ids: Vec<u32> }` directly against the contract's known\n * struct shape -- see this module's doc comment for why this replaces\n * upstream's `spec.nativeToScVal` call. `Signer::Delegated(address)` is\n * the enum variant encoding (a two-element vector: the variant's symbol,\n * then its payload) every delegated-signer call in this workspace uses;\n * the signature bytes are empty because `do_check_auth` does not check\n * them for a delegated signer (the wallet's classic signature on Entry B\n * is what's actually verified). */\nfunction smartAccountAuthPayloadScVal(signerAddress: string, contextRuleIdsScVal: xdr.ScVal): xdr.ScVal {\n const signerKey = xdr.ScVal.scvVec([\n xdr.ScVal.scvSymbol(\"Delegated\"),\n new Address(signerAddress).toScVal(),\n ]);\n const signersMap = xdr.ScVal.scvMap([\n new xdr.ScMapEntry({ key: signerKey, val: xdr.ScVal.scvBytes(Buffer.alloc(0)) }),\n ]);\n return structScVal({\n context_rule_ids: contextRuleIdsScVal,\n signers: signersMap,\n });\n}\n\nexport interface BuildSmartAccountAuthOptions {\n smartAccountId: string;\n /** The actual `smart_account` call being authorized (its root\n * invocation) -- e.g. `execute_transfer_payment(...)`. Declare any\n * further sub-invocations that must be pre-cleared by this SAME entry\n * as its `subInvocations`. */\n rootInvocation: xdr.SorobanAuthorizedInvocation;\n /** G-address of the `Signer::Delegated` wallet authorizing this call. */\n signerAddress: string;\n /** Signs Entry B's classic authorization entry -- a raw `Keypair` for\n * server-side use, or a `SigningCallback` forwarding to a connected\n * wallet's `signAuthEntry`. */\n sign: Keypair | SigningCallback;\n networkPassphrase: string;\n /** Context rule id(s) the signer is registered under, one per auth\n * context reaching `__check_auth` (root + any declared\n * sub-invocation). Default: `[0]` (the founding rule), applied to every\n * context. */\n contextRuleIds?: number[];\n signatureExpirationLedger: number;\n}\n\n/**\n * Builds Entry A + Entry B for a single required `Signer::Delegated`.\n *\n * KNOWN ISSUE: for a multi-signer context rule (threshold > 1), calling\n * this once per signer and attaching each pair produces N separate\n * Entry As, each with a single-key `signers` map. That does not match\n * `DAPP_INTEGRATION_SPEC.md` §5.4, which specifies one shared Entry A\n * carrying all N signers' keys plus N Entry Bs (one per signer) collected\n * against that same Entry A over time. Multi-signer callers should not\n * rely on this function as-is until that's reconciled -- track before\n * shipping real M-of-N threshold support.\n */\nexport async function buildSmartAccountAuthEntries(\n opts: BuildSmartAccountAuthOptions,\n): Promise<[xdr.SorobanAuthorizationEntry, xdr.SorobanAuthorizationEntry]> {\n const contextRuleIds = opts.contextRuleIds ?? [0];\n const nonceA = randomNonce();\n const sigPayloadA = signaturePayload(\n opts.rootInvocation,\n nonceA,\n opts.signatureExpirationLedger,\n opts.networkPassphrase,\n );\n\n const contextRuleIdsScVal = xdr.ScVal.scvVec(\n contextRuleIds.map((id) => xdr.ScVal.scvU32(id)),\n );\n const authDigest = hash(\n Buffer.concat([Buffer.from(sigPayloadA), Buffer.from(contextRuleIdsScVal.toXDR())]),\n );\n\n const entryA = new xdr.SorobanAuthorizationEntry({\n credentials: xdr.SorobanCredentials.sorobanCredentialsAddress(\n new xdr.SorobanAddressCredentials({\n address: new Address(opts.smartAccountId).toScAddress(),\n nonce: xdr.Int64.fromString(nonceA.toString()),\n signatureExpirationLedger: opts.signatureExpirationLedger,\n signature: smartAccountAuthPayloadScVal(opts.signerAddress, contextRuleIdsScVal),\n }),\n ),\n rootInvocation: opts.rootInvocation,\n });\n\n const nestedInvocation = buildInvocation({\n contractId: opts.smartAccountId,\n functionName: \"__check_auth\",\n args: [xdr.ScVal.scvBytes(authDigest)],\n });\n const entryB = await buildClassicAuthEntry(\n opts.signerAddress,\n nestedInvocation,\n opts.sign,\n opts.signatureExpirationLedger,\n opts.networkPassphrase,\n );\n\n return [entryA, entryB];\n}\n\nexport interface BuildExecutorAuthOptions {\n intentRegistryId: string;\n intentId: Buffer;\n childSequence: number;\n executorAddress: string;\n sign: Keypair | SigningCallback;\n networkPassphrase: string;\n signatureExpirationLedger: number;\n}\n\n/**\n * Authorizes `intent_registry.mark_child_executed`, the *only* real\n * authorization check in `execute_scheduled_payment`'s whole call graph.\n *\n * `SourceAccount`/auto-fill credentials only cover a `require_auth()` at\n * the ROOT of the invocation tree; `mark_child_executed`'s\n * `executor.require_auth()` is two levels deep (`execute_scheduled_payment\n * -> intent_registry.mark_child_executed -> ensure_executor`), so it needs\n * an explicit entry, built and signed the same way as any other non-root\n * classic-account authorization -- this is *not* custom-account machinery\n * (the executor is a plain account), so no `AuthPayload`/Entry-A-Entry-B\n * pairing is involved, just one ordinary signed entry rooted directly at\n * `mark_child_executed`. Verified against live testnet (see the\n * smart-contracts repo's docs/TESTNET_FACTORY_DEPLOYMENT.md §8 and\n * docs/DAPP_INTEGRATION_SPEC.md §8), and independently against this same\n * failure mode in this dApp's own `src/lib/relayer/executor.ts`.\n */\nexport async function buildExecutorAuthEntry(\n opts: BuildExecutorAuthOptions,\n): Promise<xdr.SorobanAuthorizationEntry> {\n const invocation = buildInvocation({\n contractId: opts.intentRegistryId,\n functionName: \"mark_child_executed\",\n args: [xdr.ScVal.scvBytes(opts.intentId), xdr.ScVal.scvU32(opts.childSequence)],\n });\n return buildClassicAuthEntry(\n opts.executorAddress,\n invocation,\n opts.sign,\n opts.signatureExpirationLedger,\n opts.networkPassphrase,\n );\n}\n","/**\n * Transaction-preparation helpers: prepare -> simulate -> approve. Each\n * function returns a prepared, auth-entry-attached `Transaction` --\n * simulated (fee/resource estimation) with the custom `smart_account`\n * `AuthPayload` entries already present, ready for the caller to sign the\n * envelope with a fee-paying account and submit (see `signAndSubmit`\n * below). None of these functions touch a wallet directly -- signing is\n * always an injected `Keypair | SigningCallback` (see `auth.ts`), so a\n * browser dApp can swap in a connected wallet's `signAuthEntry` without\n * changing anything here.\n *\n * Call args are hand-encoded (`transferArgs`, `splitArgs`,\n * `scheduledIntentScVal`, below) against the contracts' real signatures,\n * rather than through a generated-bindings client's\n * `.spec.funcArgsToScVals(...)` -- see `auth.ts`'s module doc comment for\n * why this SDK avoids depending on those generated bindings directly.\n */\nimport {\n Account,\n Address,\n Keypair,\n Operation,\n TransactionBuilder,\n BASE_FEE,\n nativeToScVal,\n rpc,\n xdr,\n type SigningCallback,\n type Transaction,\n} from \"@stellar/stellar-sdk\";\n\nimport { structScVal } from \"./scval\";\nimport { buildExecutorAuthEntry, buildInvocation, buildSmartAccountAuthEntries } from \"./auth\";\nimport type { NetworkConfig } from \"./config\";\n\nconst DEFAULT_EXPIRATION_WINDOW_LEDGERS = 100;\nconst POLL_INTERVAL_MS = 3000;\nconst MAX_POLL_ATTEMPTS = 40; // ~2 minutes at POLL_INTERVAL_MS\n\nfunction addressScVal(id: string) {\n return new Address(id).toScVal();\n}\n\nfunction i128ScVal(value: bigint) {\n return nativeToScVal(value, { type: \"i128\" });\n}\n\nfunction u32ScVal(value: number) {\n return nativeToScVal(value, { type: \"u32\" });\n}\n\nfunction u64ScVal(value: bigint) {\n return nativeToScVal(value, { type: \"u64\" });\n}\n\nfunction boolScVal(value: boolean) {\n return nativeToScVal(value);\n}\n\nfunction bytesN32ScVal(value: Buffer) {\n if (value.length !== 32) {\n throw new Error(\"Expected exactly 32 bytes.\");\n }\n return xdr.ScVal.scvBytes(value);\n}\n\n/**\n * Builds, simulates, and returns a prepared `Transaction` invoking one\n * contract function with a given set of auth entries already attached.\n * Shared scaffolding for every `prepare*` helper below (signer-authored\n * `smart_account` calls and the relayer's `execute_scheduled_payment`\n * alike) -- only the auth entries and operation args actually differ\n * between them. Takes an already-fetched `sourceAccount` rather than\n * fetching it itself, so callers can build auth entries (a signing round\n * trip, possibly a wallet prompt) and fetch the source account\n * concurrently instead of serially.\n */\nfunction buildAndPrepareTransaction(\n server: rpc.Server,\n net: NetworkConfig,\n sourceAccount: Account,\n contract: string,\n functionName: string,\n args: xdr.ScVal[],\n auth: xdr.SorobanAuthorizationEntry[],\n): Promise<Transaction> {\n const builder = new TransactionBuilder(sourceAccount, {\n fee: BASE_FEE,\n networkPassphrase: net.networkPassphrase,\n })\n .addOperation(Operation.invokeContractFunction({ contract, function: functionName, args, auth }))\n .setTimeout(120)\n .build();\n\n return server.prepareTransaction(builder);\n}\n\nexport interface PrepareOptions {\n net: NetworkConfig;\n /** Any funded account that pays the network fee -- independent of who\n * authorizes the `smart_account` call. Only its public key is needed to\n * build the transaction. */\n feeSourceAddress: string;\n signerAddress: string;\n sign: Keypair | SigningCallback;\n contextRuleIds?: number[];\n}\n\nasync function prepareSmartAccountCall(\n opts: PrepareOptions,\n functionName: string,\n args: xdr.ScVal[],\n): Promise<Transaction> {\n const server = new rpc.Server(opts.net.rpcUrl);\n const latestLedger = await server.getLatestLedger();\n const signatureExpirationLedger = latestLedger.sequence + DEFAULT_EXPIRATION_WINDOW_LEDGERS;\n\n const rootInvocation = buildInvocation({\n contractId: opts.net.contracts.smartAccount,\n functionName,\n args,\n });\n\n // Neither depends on the other's result -- run the signing round trip\n // (possibly a wallet prompt) and the account-fetch RPC call concurrently\n // rather than paying both latencies serially.\n const [[entryA, entryB], sourceAccount] = await Promise.all([\n buildSmartAccountAuthEntries({\n smartAccountId: opts.net.contracts.smartAccount,\n rootInvocation,\n signerAddress: opts.signerAddress,\n sign: opts.sign,\n networkPassphrase: opts.net.networkPassphrase,\n contextRuleIds: opts.contextRuleIds,\n signatureExpirationLedger,\n }),\n server.getAccount(opts.feeSourceAddress),\n ]);\n\n return buildAndPrepareTransaction(\n server,\n opts.net,\n sourceAccount,\n opts.net.contracts.smartAccount,\n functionName,\n args,\n [entryA, entryB],\n );\n}\n\nexport interface TransferPaymentArgs {\n asset: string;\n destination: string;\n amount: bigint;\n nonce: bigint;\n expectedPolicyVersion: number;\n}\n\nexport async function prepareTransferPayment(\n opts: PrepareOptions,\n payment: TransferPaymentArgs,\n): Promise<Transaction> {\n const args = [\n addressScVal(payment.asset),\n addressScVal(payment.destination),\n i128ScVal(payment.amount),\n u64ScVal(payment.nonce),\n u32ScVal(payment.expectedPolicyVersion),\n ];\n return prepareSmartAccountCall(opts, \"execute_transfer_payment\", args);\n}\n\nexport interface SplitPaymentArgs {\n asset: string;\n recipients: string[];\n amounts: bigint[];\n nonce: bigint;\n expectedPolicyVersion: number;\n}\n\nexport async function prepareSplitPayment(\n opts: PrepareOptions,\n payment: SplitPaymentArgs,\n): Promise<Transaction> {\n const args = [\n addressScVal(payment.asset),\n xdr.ScVal.scvVec(payment.recipients.map(addressScVal)),\n xdr.ScVal.scvVec(payment.amounts.map(i128ScVal)),\n u64ScVal(payment.nonce),\n u32ScVal(payment.expectedPolicyVersion),\n ];\n return prepareSmartAccountCall(opts, \"execute_split_payment\", args);\n}\n\nexport interface ScheduledIntentArgs {\n intent_id: Buffer;\n asset: string;\n destination: string;\n amount: bigint;\n start_ledger: number;\n end_ledger: number;\n interval_ledgers: number;\n max_executions: number;\n /** Ignored/overwritten server-side, pinned to `0` at creation -- pass any\n * placeholder value; read the resolved field back from the\n * `IntentCreated` event or a follow-up `get_intent` read. */\n execution_count: number;\n /** Ignored/overwritten server-side, pinned to `policy_engine.version()`\n * at creation time -- see `execution_count` above. */\n policy_version: number;\n /** Ignored/overwritten server-side, pinned to the currently configured\n * `transfer_adapter` at creation time -- see `execution_count` above. */\n adapter: string;\n cancelled: boolean;\n}\n\nfunction scheduledIntentScVal(intent: ScheduledIntentArgs) {\n return structScVal({\n intent_id: bytesN32ScVal(intent.intent_id),\n asset: addressScVal(intent.asset),\n destination: addressScVal(intent.destination),\n amount: i128ScVal(intent.amount),\n start_ledger: u32ScVal(intent.start_ledger),\n end_ledger: u32ScVal(intent.end_ledger),\n interval_ledgers: u32ScVal(intent.interval_ledgers),\n max_executions: u32ScVal(intent.max_executions),\n execution_count: u32ScVal(intent.execution_count),\n policy_version: u32ScVal(intent.policy_version),\n adapter: addressScVal(intent.adapter),\n cancelled: boolScVal(intent.cancelled),\n });\n}\n\n/** `intent`'s caller-supplied `policy_version`/`adapter` are ignored and\n * overwritten by the contract (pinned to current values at approval time)\n * -- pass any placeholder value; read the resolved fields back from the\n * `IntentCreated` event or a follow-up `get_intent` read. */\nexport async function prepareScheduledPayment(\n opts: PrepareOptions,\n intent: ScheduledIntentArgs,\n): Promise<Transaction> {\n const args = [scheduledIntentScVal(intent)];\n return prepareSmartAccountCall(opts, \"create_scheduled_payment\", args);\n}\n\nexport async function prepareCancelScheduledPayment(\n opts: PrepareOptions,\n intentId: Buffer,\n): Promise<Transaction> {\n const args = [bytesN32ScVal(intentId)];\n return prepareSmartAccountCall(opts, \"cancel_scheduled_payment\", args);\n}\n\n/** Signs the transaction envelope with the fee-paying account's key\n * (independent of the `smart_account` auth entries, already attached by\n * `prepare*`) and submits it, polling until a terminal status. */\nexport async function signAndSubmit(\n net: NetworkConfig,\n tx: Transaction,\n feeSourceKeypair: Keypair,\n): Promise<rpc.Api.GetSuccessfulTransactionResponse> {\n const server = new rpc.Server(net.rpcUrl);\n tx.sign(feeSourceKeypair);\n const sendResponse = await server.sendTransaction(tx);\n if (sendResponse.status === \"ERROR\") {\n throw new Error(`sendTransaction failed: ${JSON.stringify(sendResponse.errorResult)}`);\n }\n\n let response = await server.getTransaction(sendResponse.hash);\n for (\n let attempt = 0;\n response.status === rpc.Api.GetTransactionStatus.NOT_FOUND && attempt < MAX_POLL_ATTEMPTS;\n attempt++\n ) {\n await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL_MS));\n response = await server.getTransaction(sendResponse.hash);\n }\n if (response.status === rpc.Api.GetTransactionStatus.NOT_FOUND) {\n throw new Error(\n `transaction ${sendResponse.hash} not found after ${MAX_POLL_ATTEMPTS} polling attempts`,\n );\n }\n if (response.status !== rpc.Api.GetTransactionStatus.SUCCESS) {\n throw new Error(`transaction ${sendResponse.hash} failed: ${JSON.stringify(response)}`);\n }\n return response;\n}\n\nexport interface RelayerExecuteOptions {\n net: NetworkConfig;\n intentId: Buffer;\n childSequence: number;\n executorAddress: string;\n sign: Keypair | SigningCallback;\n}\n\n/**\n * Prepares a relayer's `execute_scheduled_payment` call. Unlike the\n * signer-authored payment helpers above, this needs no `smart_account`\n * `AuthPayload` at all -- only an explicit authorization entry for\n * `intent_registry.mark_child_executed`'s `Executor` requirement (see\n * `buildExecutorAuthEntry`'s doc comment in `auth.ts`).\n */\nexport async function prepareRelayerExecution(opts: RelayerExecuteOptions): Promise<Transaction> {\n const server = new rpc.Server(opts.net.rpcUrl);\n const latestLedger = await server.getLatestLedger();\n const signatureExpirationLedger = latestLedger.sequence + DEFAULT_EXPIRATION_WINDOW_LEDGERS;\n\n const [executorEntry, sourceAccount] = await Promise.all([\n buildExecutorAuthEntry({\n intentRegistryId: opts.net.contracts.intentRegistry,\n intentId: opts.intentId,\n childSequence: opts.childSequence,\n executorAddress: opts.executorAddress,\n sign: opts.sign,\n networkPassphrase: opts.net.networkPassphrase,\n signatureExpirationLedger,\n }),\n server.getAccount(opts.executorAddress),\n ]);\n\n const args = [bytesN32ScVal(opts.intentId), u32ScVal(opts.childSequence)];\n return buildAndPrepareTransaction(\n server,\n opts.net,\n sourceAccount,\n opts.net.contracts.smartAccount,\n \"execute_scheduled_payment\",\n args,\n [executorEntry],\n );\n}\n\nexport { Account };\n","/**\n * Typed event parsing. Depends only on `@stellar/stellar-sdk`'s\n * `xdr`/`scValToNative` -- no generated per-contract bindings involved.\n * Keep in sync by hand if the source contracts' `#[contractevent]`\n * definitions change — there is no automated link between this package\n * and the contracts repo.\n *\n * The Stellar CLI's generated bindings expose function signatures, errors,\n * and structs from a contract's spec, but not its `#[contractevent]`\n * definitions — those are hand-typed here, against the actual struct\n * definitions in each contract's `src/lib.rs`, and are exposed as\n * first-class types rather than raw event XDR.\n *\n * Every `#[contractevent]` struct is encoded on-chain as: topics[0] = the\n * event's short topic symbol (see the smart-contracts repo's\n * docs/DAPP_INTEGRATION_SPEC.md §10.4), followed by any further\n * `#[topic]`-tagged fields, then a data map of the remaining fields keyed\n * by their Rust field name.\n */\nimport { scValToNative, xdr } from \"@stellar/stellar-sdk\";\n\nexport interface TransferPaid {\n asset: string;\n destination: string;\n amount: bigint;\n nonce: bigint;\n}\n\nexport interface SplitPaid {\n asset: string;\n recipient_count: number;\n nonce: bigint;\n}\n\nexport interface ScheduledPaymentExecuted {\n intent_id: Buffer;\n child_sequence: number;\n asset: string;\n destination: string;\n amount: bigint;\n}\n\nexport interface PolicyValidated {\n operation: string;\n asset: string;\n destination: string;\n amount: bigint;\n expected_version: number;\n}\n\nexport interface IntentCreated {\n intent_id: Buffer;\n}\n\nexport interface IntentCancelled {\n intent_id: Buffer;\n}\n\nexport interface ChildExecuted {\n intent_id: Buffer;\n child_sequence: number;\n}\n\nexport interface RecoveryOpened {\n request_id: Buffer;\n}\n\nexport interface RecoveryApproved {\n request_id: Buffer;\n guardian: string;\n}\n\nexport interface RecoveryFinalized {\n request_id: Buffer;\n replacement_owner: string;\n}\n\nexport interface RecoveryApplied {\n request_id: Buffer;\n replacement_owner: string;\n}\n\nexport interface GuardianFreezeRequested {\n guardian: string;\n}\n\nexport interface Frozen {\n triggered_by_guardian: boolean;\n}\n\n/** Every event type this module knows how to decode, keyed by its on-chain\n * topic symbol. Add new entries here as new contract events are curated. */\nexport interface EventMap {\n pay_ok: TransferPaid;\n splt_ok: SplitPaid;\n auto_ok: ScheduledPaymentExecuted;\n pol_ok: PolicyValidated;\n intent: IntentCreated;\n cancel: IntentCancelled;\n exec: ChildExecuted;\n open: RecoveryOpened;\n appr: RecoveryApproved;\n final: RecoveryFinalized;\n recover: RecoveryApplied;\n gfreeze: GuardianFreezeRequested;\n frozen: Frozen;\n}\n\nexport type ParsedEvent =\n | { [K in keyof EventMap]: { topic: K; event: EventMap[K] } }[keyof EventMap]\n | { topic: string; event: Record<string, unknown> };\n\nfunction topicSymbol(event: xdr.ContractEvent): string | undefined {\n const body = event.body().v0();\n const first = body.topics()[0];\n return first?.switch().name === \"scvSymbol\" ? first.sym().toString() : undefined;\n}\n\n/** `#[contractevent]`'s `#[topic]`-tagged fields, beyond the topic symbol\n * itself, in declaration order -- these live in `topics[1..]`, not the\n * data map, and (unlike the data map) carry no field names on-chain, so\n * this ordering must match each event struct's actual field order in its\n * `src/lib.rs`. Topic symbols are not globally unique across contracts\n * (e.g. `intent_registry`'s `IntentCancelled` and `recovery_manager`'s\n * `RecoveryCancelled` both use `\"cancel\"`) -- this map only covers the\n * events in `EventMap`; a topic outside it decodes as the untyped\n * catch-all below regardless of which contract emitted it. */\nconst TOPIC_FIELDS: Record<keyof EventMap, string[]> = {\n pay_ok: [\"asset\", \"destination\"],\n splt_ok: [\"asset\"],\n auto_ok: [\"intent_id\"],\n pol_ok: [\"operation\"],\n intent: [\"intent_id\"],\n cancel: [\"intent_id\"],\n exec: [\"intent_id\"],\n open: [\"request_id\"],\n appr: [\"request_id\", \"guardian\"],\n final: [\"request_id\"],\n recover: [\"request_id\"],\n gfreeze: [\"guardian\"],\n frozen: [],\n};\n\nfunction decodeFields(event: xdr.ContractEvent): Record<string, unknown> {\n const body = event.body().v0();\n const topics = body.topics();\n const topic = topicSymbol(event);\n const topicFieldNames = topic && topic in TOPIC_FIELDS ? TOPIC_FIELDS[topic as keyof EventMap] : [];\n\n const fromTopics: Record<string, unknown> = {};\n topicFieldNames.forEach((name, i) => {\n fromTopics[name] = scValToNative(topics[i + 1]);\n });\n\n const native = scValToNative(body.data());\n const fromData = native && typeof native === \"object\" ? (native as Record<string, unknown>) : {};\n\n return { ...fromTopics, ...fromData };\n}\n\n/** Parses one `xdr.ContractEvent` into its typed shape, matched by topic,\n * merging `#[topic]`-tagged fields (from `topics[1..]`) with the data map\n * -- both are needed to reconstruct the full `#[contractevent]` struct.\n * Unknown topics still parse -- as `{ topic, event: <raw decoded map> }`\n * -- rather than throwing, so a caller can log/inspect an event this\n * module doesn't have a named type for yet. */\nexport function parseContractEvent(event: xdr.ContractEvent): ParsedEvent {\n const topic = topicSymbol(event);\n const fields = decodeFields(event);\n return { topic: topic ?? \"\", event: fields } as ParsedEvent;\n}\n\n/** Parses every event from a `getTransaction` response's\n * `events.contractEventsXdr` (one array of events per operation -- this\n * dApp's transactions always have exactly one operation, so pass\n * `contractEventsXdr[0]`). */\nexport function parseContractEvents(events: xdr.ContractEvent[]): ParsedEvent[] {\n return events.map(parseContractEvent);\n}\n\nexport function findEvent<T extends keyof EventMap>(\n events: ParsedEvent[],\n topic: T,\n): EventMap[T] | undefined {\n const found = events.find((e) => e.topic === topic);\n return found?.event as EventMap[T] | undefined;\n}\n","/**\n * First-class typed reads for policy-version, replay-state (nonce), and\n * recovery-state. Every function here is a read-only simulation (no\n * signature, no submission), built directly on\n * `rpc.Server.simulateTransaction` rather than a generated per-contract\n * `Client` -- see `auth.ts`'s module doc comment for why this SDK avoids\n * depending on generated bindings directly. One consequence: every\n * function here takes an explicit `sourceAddress` (a real, funded account\n * to build the simulation transaction from -- `getAccount` fails for one\n * that doesn't exist on-chain).\n *\n * Every type below (`AccountStatus`, `ContextRule`, `ScheduledIntent`,\n * `RecoveryRequest`, `WasmHashes`) is verified directly against the real\n * `#[contracttype]` struct definitions in the source contracts (and the\n * `stellar-accounts` OZ crate for `ContextRule`), not reconstructed from\n * observed JSON shapes.\n */\nimport { Contract, TransactionBuilder, BASE_FEE, rpc, scValToNative, nativeToScVal, xdr } from \"@stellar/stellar-sdk\";\n\nimport type { NetworkConfig } from \"./config\";\n\nexport interface AccountStatus {\n initialized: boolean;\n paused: boolean;\n frozen: boolean;\n policy_version_hint: number;\n}\n\n/** From the vendored `stellar-accounts` OZ crate\n * (`smart_account::storage::ContextRule`), not this workspace's own\n * contracts -- `get_context_rule`'s actual return type. */\nexport interface ContextRule {\n id: number;\n context_type: string;\n name: string;\n signers: unknown[];\n signer_ids: number[];\n policies: string[];\n policy_ids: number[];\n valid_until?: number;\n}\n\nexport interface ScheduledIntent {\n intent_id: Buffer;\n asset: string;\n destination: string;\n amount: bigint;\n start_ledger: number;\n end_ledger: number;\n interval_ledgers: number;\n max_executions: number;\n execution_count: number;\n policy_version: number;\n adapter: string;\n cancelled: boolean;\n}\n\nexport interface RecoveryRequest {\n request_id: Buffer;\n replacement_owner: string;\n replacement_signers: unknown[];\n replacement_policies: Record<string, unknown>;\n earliest_ledger: number;\n approvers: string[];\n cancelled: boolean;\n finalized: boolean;\n}\n\nexport interface WasmHashes {\n policy_engine: Buffer;\n intent_registry: Buffer;\n recovery_manager: Buffer;\n transfer_adapter: Buffer;\n split_adapter: Buffer;\n smart_account: Buffer;\n}\n\nfunction isSimulationError(\n simulation: rpc.Api.SimulateTransactionResponse,\n): simulation is rpc.Api.SimulateTransactionErrorResponse {\n return \"error\" in simulation;\n}\n\nasync function simulateRead(\n net: NetworkConfig,\n sourceAddress: string,\n contractId: string,\n method: string,\n args: xdr.ScVal[] = [],\n): Promise<unknown> {\n const server = new rpc.Server(net.rpcUrl);\n const source = await server.getAccount(sourceAddress);\n const tx = new TransactionBuilder(source, { fee: BASE_FEE, networkPassphrase: net.networkPassphrase })\n .addOperation(new Contract(contractId).call(method, ...args))\n .setTimeout(60)\n .build();\n\n const simulation = await server.simulateTransaction(tx);\n if (isSimulationError(simulation)) {\n throw new Error(simulation.error);\n }\n return simulation.result?.retval ? scValToNative(simulation.result.retval) : null;\n}\n\nfunction u32ScVal(value: number) {\n return nativeToScVal(value, { type: \"u32\" });\n}\n\nfunction u64ScVal(value: bigint) {\n return nativeToScVal(value, { type: \"u64\" });\n}\n\nfunction bytesN32ScVal(value: Buffer) {\n if (value.length !== 32) {\n throw new Error(\"Expected exactly 32 bytes.\");\n }\n return xdr.ScVal.scvBytes(value);\n}\n\nfunction addressScVal(value: string) {\n return nativeToScVal(value, { type: \"address\" });\n}\n\n/** `smart_account.status()` -- check before offering any payment action; a\n * paused or frozen treasury should disable the payment UI, not let the\n * user hit a rejected simulation. */\nexport async function readAccountStatus(\n net: NetworkConfig,\n sourceAddress: string,\n): Promise<AccountStatus> {\n return (await simulateRead(net, sourceAddress, net.contracts.smartAccount, \"status\")) as AccountStatus;\n}\n\nexport async function readOwner(net: NetworkConfig, sourceAddress: string): Promise<string | null> {\n const result = await simulateRead(net, sourceAddress, net.contracts.smartAccount, \"get_owner\");\n return typeof result === \"string\" ? result : null;\n}\n\n/** Rule IDs are `0..count`, not necessarily contiguous after removals --\n * check existence with `readContextRule`, don't assume. */\nexport async function readContextRulesCount(net: NetworkConfig, sourceAddress: string): Promise<number> {\n const result = await simulateRead(net, sourceAddress, net.contracts.smartAccount, \"get_context_rules_count\");\n return Number(result ?? 0);\n}\n\nexport async function readContextRule(\n net: NetworkConfig,\n sourceAddress: string,\n contextRuleId: number,\n): Promise<ContextRule> {\n return (await simulateRead(net, sourceAddress, net.contracts.smartAccount, \"get_context_rule\", [\n u32ScVal(contextRuleId),\n ])) as ContextRule;\n}\n\nexport async function isNonceUsed(net: NetworkConfig, sourceAddress: string, nonce: bigint): Promise<boolean> {\n const result = await simulateRead(net, sourceAddress, net.contracts.smartAccount, \"is_nonce_used\", [\n u64ScVal(nonce),\n ]);\n return Boolean(result);\n}\n\n/** The authoritative current policy version -- read fresh immediately\n * before building a payment, never cached across a user session (a stale\n * value here causes a clean `VersionMismatch` rejection rather than\n * executing under outdated rules). */\nexport async function readPolicyVersion(net: NetworkConfig, sourceAddress: string): Promise<number> {\n const result = await simulateRead(net, sourceAddress, net.contracts.policyEngine, \"version\");\n return Number(result ?? 1);\n}\n\nexport async function readScheduledIntent(\n net: NetworkConfig,\n sourceAddress: string,\n intentId: Buffer,\n): Promise<ScheduledIntent> {\n return (await simulateRead(net, sourceAddress, net.contracts.intentRegistry, \"get_intent\", [\n bytesN32ScVal(intentId),\n ])) as ScheduledIntent;\n}\n\nexport async function isChildExecuted(\n net: NetworkConfig,\n sourceAddress: string,\n intentId: Buffer,\n childSequence: number,\n): Promise<boolean> {\n const result = await simulateRead(net, sourceAddress, net.contracts.intentRegistry, \"is_child_executed\", [\n bytesN32ScVal(intentId),\n u32ScVal(childSequence),\n ]);\n return Boolean(result);\n}\n\n/** Recovery-request state -- first-class typed state, not a raw XDR blob. */\nexport async function readRecoveryRequest(\n net: NetworkConfig,\n sourceAddress: string,\n requestId: Buffer,\n): Promise<RecoveryRequest> {\n return (await simulateRead(net, sourceAddress, net.contracts.recoveryManager, \"request_status\", [\n bytesN32ScVal(requestId),\n ])) as RecoveryRequest;\n}\n\nexport async function readLiveApprovalCount(\n net: NetworkConfig,\n sourceAddress: string,\n requestId: Buffer,\n): Promise<number> {\n const result = await simulateRead(net, sourceAddress, net.contracts.recoveryManager, \"live_approval_count\", [\n bytesN32ScVal(requestId),\n ]);\n return Number(result ?? 0);\n}\n\nexport async function isGuardian(\n net: NetworkConfig,\n sourceAddress: string,\n guardian: string,\n): Promise<boolean> {\n const result = await simulateRead(net, sourceAddress, net.contracts.recoveryManager, \"is_guardian\", [\n addressScVal(guardian),\n ]);\n return Boolean(result);\n}\n\n/** Monotonically increasing, never-cleared -- compare against a locally\n * stored \"last applied\" value to detect a pending guardian freeze rather\n * than treating this as a boolean. */\nexport async function readGuardianFreezeEpoch(net: NetworkConfig, sourceAddress: string): Promise<number> {\n const result = await simulateRead(net, sourceAddress, net.contracts.recoveryManager, \"guardian_freeze_epoch\");\n return Number(result ?? 0);\n}\n\nexport async function readFactoryWasmHashes(net: NetworkConfig, sourceAddress: string): Promise<WasmHashes> {\n return (await simulateRead(\n net,\n sourceAddress,\n net.contracts.accountFactory,\n \"get_wasm_hashes\",\n )) as WasmHashes;\n}\n"]}
|
package/dist/index.d.cts
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 };
|