@thruputchain/client 0.27.0 → 0.29.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/README.md +120 -22
- package/dist/{actions-DK_XBeVy.cjs → actions-B2gV8Vzr.cjs} +297 -73
- package/dist/actions-B2gV8Vzr.cjs.map +1 -0
- package/dist/actions-UEYKD22C.js +653 -0
- package/dist/actions-UEYKD22C.js.map +1 -0
- package/dist/actions.cjs +4 -8
- package/dist/actions.d.cts +4 -4
- package/dist/actions.d.ts +4 -4
- package/dist/actions.js +3 -3
- package/dist/{artifact-BM_MVzhL.d.ts → artifact-RIAPVmVX.d.cts} +4 -3
- package/dist/artifact-RIAPVmVX.d.cts.map +1 -0
- package/dist/{artifact-BM_MVzhL.d.cts → artifact-RIAPVmVX.d.ts} +4 -3
- package/dist/artifact-RIAPVmVX.d.ts.map +1 -0
- package/dist/{contract-Cu8Qv94_.js → contract-BOlNskwd.js} +235 -87
- package/dist/contract-BOlNskwd.js.map +1 -0
- package/dist/{contract-DPm2BJTu.cjs → contract-D_vxUudr.cjs} +281 -109
- package/dist/contract-D_vxUudr.cjs.map +1 -0
- package/dist/contract.cjs +1 -5
- package/dist/contract.d.cts +4 -4
- package/dist/contract.d.ts +4 -4
- package/dist/contract.js +2 -2
- package/dist/contracts.cjs +5 -5
- package/dist/contracts.d.cts +19 -4
- package/dist/contracts.d.cts.map +1 -1
- package/dist/contracts.d.ts +19 -4
- package/dist/contracts.d.ts.map +1 -1
- package/dist/contracts.js +4 -4
- package/dist/decimal-BX7abv5J.cjs +171 -0
- package/dist/decimal-BX7abv5J.cjs.map +1 -0
- package/dist/decimal-CoHOISys.js +124 -0
- package/dist/decimal-CoHOISys.js.map +1 -0
- package/dist/{dev_wallet-BcvX_xT4.cjs → dev_wallet-BVChhV6j.cjs} +85 -6
- package/dist/dev_wallet-BVChhV6j.cjs.map +1 -0
- package/dist/{dev_wallet-B5R5JJaw.js → dev_wallet-D9LuPZ-h.js} +84 -5
- package/dist/dev_wallet-D9LuPZ-h.js.map +1 -0
- package/dist/{execution-C8oQgpO3.d.cts → execution-pSt6k620.d.cts} +23 -50
- package/dist/execution-pSt6k620.d.cts.map +1 -0
- package/dist/{execution-DsZzqv_C.d.ts → execution-uiuFPV0d.d.ts} +23 -50
- package/dist/execution-uiuFPV0d.d.ts.map +1 -0
- package/dist/{hex-DIcaALXL.js → hex-B8D-jBgz.js} +2 -2
- package/dist/{hex-DIcaALXL.js.map → hex-B8D-jBgz.js.map} +1 -1
- package/dist/{hex-DkGpiZ5e.cjs → hex-CSDZ9d6z.cjs} +2 -2
- package/dist/{hex-DkGpiZ5e.cjs.map → hex-CSDZ9d6z.cjs.map} +1 -1
- package/dist/{index-rrP1HJ2Z.d.cts → index-B1efA-Y_.d.ts} +24 -21
- package/dist/index-B1efA-Y_.d.ts.map +1 -0
- package/dist/{index-Zaz-e8Sy.d.ts → index-BGmH_Sm7.d.cts} +12 -62
- package/dist/index-BGmH_Sm7.d.cts.map +1 -0
- package/dist/{index-CHnfHuQo.d.ts → index-BZ5j5P5d.d.ts} +11 -9
- package/dist/index-BZ5j5P5d.d.ts.map +1 -0
- package/dist/{index-BmQN3jAS.d.cts → index-BfYEEVHm.d.cts} +3 -13
- package/dist/index-BfYEEVHm.d.cts.map +1 -0
- package/dist/{index-CuzB95QT.d.cts → index-BhOeIyrZ.d.cts} +11 -9
- package/dist/index-BhOeIyrZ.d.cts.map +1 -0
- package/dist/{index-B5KqSHeL.d.cts → index-BsvYcU_Y.d.cts} +2 -2
- package/dist/{index-B5KqSHeL.d.cts.map → index-BsvYcU_Y.d.cts.map} +1 -1
- package/dist/{index-hqEnT64w.d.ts → index-Btl_jMCT.d.ts} +3 -13
- package/dist/index-Btl_jMCT.d.ts.map +1 -0
- package/dist/{index-C3qDR1J5.d.cts → index-CG-q0j9w.d.ts} +12 -62
- package/dist/index-CG-q0j9w.d.ts.map +1 -0
- package/dist/index-CPtBvHE8.d.ts +145 -0
- package/dist/index-CPtBvHE8.d.ts.map +1 -0
- package/dist/{index-CKqC9N4o.d.ts → index-DBKsOzCN.d.cts} +24 -21
- package/dist/index-DBKsOzCN.d.cts.map +1 -0
- package/dist/index-Xre-0Jka.d.cts +145 -0
- package/dist/index-Xre-0Jka.d.cts.map +1 -0
- package/dist/index.cjs +39 -68
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -17
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +12 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +27 -38
- package/dist/index.js.map +1 -1
- package/dist/provider.cjs +3 -3
- package/dist/provider.cjs.map +1 -1
- package/dist/provider.d.cts +2 -1
- package/dist/provider.d.ts +2 -1
- package/dist/provider.js +3 -3
- package/dist/provider.js.map +1 -1
- package/dist/{codec-BOjoJjC5.js → readError-B3Rz7rgs.js} +673 -56
- package/dist/readError-B3Rz7rgs.js.map +1 -0
- package/dist/{codec-C4LJ0g8v.cjs → readError-COcEDNoZ.cjs} +677 -96
- package/dist/readError-COcEDNoZ.cjs.map +1 -0
- package/dist/requestAirdrop-DBCOST2B.d.ts +1818 -0
- package/dist/requestAirdrop-DBCOST2B.d.ts.map +1 -0
- package/dist/requestAirdrop-T1eVn3l5.d.cts +1818 -0
- package/dist/requestAirdrop-T1eVn3l5.d.cts.map +1 -0
- package/dist/sendInvocation-185ZJrta.cjs +583 -0
- package/dist/sendInvocation-185ZJrta.cjs.map +1 -0
- package/dist/sendInvocation-DBaNWhr3.js +439 -0
- package/dist/sendInvocation-DBaNWhr3.js.map +1 -0
- package/dist/signed-op.cjs +2 -2
- package/dist/signed-op.d.cts +2 -2
- package/dist/signed-op.d.ts +1 -1
- package/dist/signed-op.js +2 -2
- package/dist/{signedOp-BDUZhfJn.cjs → signedOp-CVyeJ5ig.cjs} +3 -3
- package/dist/{signedOp-BDUZhfJn.cjs.map → signedOp-CVyeJ5ig.cjs.map} +1 -1
- package/dist/{signedOp-Kx8u8_3I.js → signedOp-D6WYZG9j.js} +3 -3
- package/dist/{signedOp-Kx8u8_3I.js.map → signedOp-D6WYZG9j.js.map} +1 -1
- package/dist/{signed_op-CAcYYRm6.cjs → signed_op-BBsDKOlD.cjs} +4 -4
- package/dist/{signed_op-CAcYYRm6.cjs.map → signed_op-BBsDKOlD.cjs.map} +1 -1
- package/dist/{signed_op-BrLxDrDb.d.cts → signed_op-BvbOHWKK.d.ts} +3 -3
- package/dist/{signed_op-DbRq3_Hb.d.ts.map → signed_op-BvbOHWKK.d.ts.map} +1 -1
- package/dist/{signed_op-DbRq3_Hb.d.ts → signed_op-DoHFpSH4.d.cts} +3 -3
- package/dist/{signed_op-BrLxDrDb.d.cts.map → signed_op-DoHFpSH4.d.cts.map} +1 -1
- package/dist/{signed_op-Dxn7-lRu.js → signed_op-h9X9-vBL.js} +3 -3
- package/dist/{signed_op-Dxn7-lRu.js.map → signed_op-h9X9-vBL.js.map} +1 -1
- package/dist/transport-BhWZxHcz.cjs +528 -0
- package/dist/transport-BhWZxHcz.cjs.map +1 -0
- package/dist/transport-EyDYuibb.js +504 -0
- package/dist/transport-EyDYuibb.js.map +1 -0
- package/dist/transport.cjs +6 -13
- package/dist/transport.d.cts +3 -3
- package/dist/transport.d.ts +3 -3
- package/dist/transport.js +4 -4
- package/dist/types-VYjJcTip.d.cts +161 -0
- package/dist/types-VYjJcTip.d.cts.map +1 -0
- package/dist/types-VYjJcTip.d.ts +161 -0
- package/dist/types-VYjJcTip.d.ts.map +1 -0
- package/dist/{validation-eXATmgO0.js → validation-BLQ64Dfh.js} +3 -3
- package/dist/validation-BLQ64Dfh.js.map +1 -0
- package/dist/{validation-4w-vDGAi.cjs → validation-CZqtmMLJ.cjs} +3 -3
- package/dist/validation-CZqtmMLJ.cjs.map +1 -0
- package/dist/{wallet-5wt9wLG3.js → wallet-NlZiI4-3.js} +161 -77
- package/dist/wallet-NlZiI4-3.js.map +1 -0
- package/dist/{wallet-Blh7oas7.cjs → wallet-UvyXtxh5.cjs} +161 -77
- package/dist/wallet-UvyXtxh5.cjs.map +1 -0
- package/dist/wallet.cjs +2 -8
- package/dist/wallet.d.cts +4 -3
- package/dist/wallet.d.ts +4 -3
- package/dist/wallet.js +3 -3
- package/package.json +2 -2
- package/dist/actions-1LmkZcfS.js +0 -430
- package/dist/actions-1LmkZcfS.js.map +0 -1
- package/dist/actions-DK_XBeVy.cjs.map +0 -1
- package/dist/artifact-BM_MVzhL.d.cts.map +0 -1
- package/dist/artifact-BM_MVzhL.d.ts.map +0 -1
- package/dist/client-DocSdzOL.d.cts +0 -790
- package/dist/client-DocSdzOL.d.cts.map +0 -1
- package/dist/client-DocSdzOL.d.ts +0 -790
- package/dist/client-DocSdzOL.d.ts.map +0 -1
- package/dist/codec-BOjoJjC5.js.map +0 -1
- package/dist/codec-C4LJ0g8v.cjs.map +0 -1
- package/dist/contract-Cu8Qv94_.js.map +0 -1
- package/dist/contract-DPm2BJTu.cjs.map +0 -1
- package/dist/dev_wallet-B5R5JJaw.js.map +0 -1
- package/dist/dev_wallet-BcvX_xT4.cjs.map +0 -1
- package/dist/execution-C8oQgpO3.d.cts.map +0 -1
- package/dist/execution-DsZzqv_C.d.ts.map +0 -1
- package/dist/index-BmQN3jAS.d.cts.map +0 -1
- package/dist/index-C3qDR1J5.d.cts.map +0 -1
- package/dist/index-CHnfHuQo.d.ts.map +0 -1
- package/dist/index-CIHK7Ew9.d.cts +0 -303
- package/dist/index-CIHK7Ew9.d.cts.map +0 -1
- package/dist/index-CIHK7Ew9.d.ts +0 -303
- package/dist/index-CIHK7Ew9.d.ts.map +0 -1
- package/dist/index-CKqC9N4o.d.ts.map +0 -1
- package/dist/index-CuzB95QT.d.cts.map +0 -1
- package/dist/index-Zaz-e8Sy.d.ts.map +0 -1
- package/dist/index-hqEnT64w.d.ts.map +0 -1
- package/dist/index-rrP1HJ2Z.d.cts.map +0 -1
- package/dist/readError-Cz3bveZa.cjs +0 -622
- package/dist/readError-Cz3bveZa.cjs.map +0 -1
- package/dist/readError-Z5zuylri.js +0 -569
- package/dist/readError-Z5zuylri.js.map +0 -1
- package/dist/readViews-BvMHbiaF.d.ts +0 -609
- package/dist/readViews-BvMHbiaF.d.ts.map +0 -1
- package/dist/readViews-CQOY5v4o.d.cts +0 -609
- package/dist/readViews-CQOY5v4o.d.cts.map +0 -1
- package/dist/sendInvocation-8TEMrJ_M.cjs +0 -661
- package/dist/sendInvocation-8TEMrJ_M.cjs.map +0 -1
- package/dist/sendInvocation-CkeMyLk1.js +0 -505
- package/dist/sendInvocation-CkeMyLk1.js.map +0 -1
- package/dist/transport-DqlfAsuH.cjs +0 -279
- package/dist/transport-DqlfAsuH.cjs.map +0 -1
- package/dist/transport-PstrCcBv.js +0 -261
- package/dist/transport-PstrCcBv.js.map +0 -1
- package/dist/validation-4w-vDGAi.cjs.map +0 -1
- package/dist/validation-eXATmgO0.js.map +0 -1
- package/dist/wallet-5wt9wLG3.js.map +0 -1
- package/dist/wallet-Blh7oas7.cjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sendInvocation-185ZJrta.cjs","names":["DefaultWallet","bytesEqual","DevWallet","codec","hashSignedTransaction","codec","ThruputError","isThruputError","isLocalError","classifyReadError","receiptFacts","isUnsupportedRpcValue","ThruputError","contractDecodeFailed","transactionResultUndecodable","codec","createTransaction","sign","rpcIncompatible","codec"],"sources":["../src/actions/deadline.ts","../src/wallet/invocationAdapter.ts","../src/wallet/executionWait.ts","../src/transaction/submissionEvidence.ts","../src/wallet/transactionErrors.ts","../src/wallet/execution.ts","../src/actions/wallet/prepareTransaction.ts","../src/actions/wallet/sendInvocation.ts"],"sourcesContent":["/** Run one operation within the caller's wall-clock budget and cancellation signal. */\nexport async function beforeDeadline<T>(\n operation: (signal: AbortSignal) => Promise<T>,\n deadline: number,\n caller: AbortSignal | undefined,\n timeout: () => Error,\n): Promise<T> {\n caller?.throwIfAborted();\n if (performance.now() >= deadline) throw timeout();\n const controller = new AbortController();\n const signal = caller\n ? AbortSignal.any([caller, controller.signal])\n : controller.signal;\n let timer: ReturnType<typeof setTimeout> | undefined;\n let onAbort = () => {};\n try {\n return await Promise.race([\n new Promise<T>((_, reject) => {\n onAbort = () => reject(signal.reason);\n signal.addEventListener(\"abort\", onAbort, { once: true });\n timer = setTimeout(\n () => controller.abort(timeout()),\n Math.ceil(Math.max(0, deadline - performance.now())),\n );\n }),\n operation(signal),\n ]);\n } finally {\n if (timer !== undefined) clearTimeout(timer);\n signal.removeEventListener(\"abort\", onAbort);\n controller.abort();\n }\n}\nexport function validateTimer(value: number, field: string): void {\n if (!Number.isFinite(value) || value < 0 || value > 2147483647)\n throw new RangeError(`${field} must be between 0 and 2147483647`);\n}\nexport function waitDelay(delay: number, signal: AbortSignal): Promise<void> {\n return new Promise((resolve, reject) => {\n signal.throwIfAborted();\n const finish = () => {\n signal.removeEventListener(\"abort\", abort);\n resolve();\n };\n const timer = setTimeout(finish, delay);\n const abort = () => {\n clearTimeout(timer);\n signal.removeEventListener(\"abort\", abort);\n reject(signal.reason);\n };\n signal.addEventListener(\"abort\", abort, { once: true });\n });\n}\n","import {\n codec,\n contractAddress,\n serialize,\n type ContractAddress,\n type GasAmount,\n type Invocation,\n} from \"@thruputchain/protocol\";\nimport { fixedBytes } from \"@thruputchain/xdr\";\nimport { bytesEqual } from \"../contract/event.js\";\nimport { DefaultWallet } from \"../contracts/default_wallet.js\";\nimport { DevWallet } from \"../contracts/dev_wallet.js\";\nimport { MAX_DEFAULT_WALLET_CALLS } from \"../provider/validation.js\";\nimport type { ContractDeployment, DeploymentOptions } from \"./deployment.js\";\nimport type { TransactionReceipt } from \"../types/rpc.js\";\n\n/** Common inputs for wrapping one inner invocation through a wallet contract. */\nexport interface WalletExecutionRequest {\n readonly invocation: Invocation;\n /** Gas available to the wallet's root invocation. */\n readonly gasLimit: GasAmount;\n}\n\n/** Ordered inner calls for one atomic DefaultWallet execution. */\nexport interface WalletBatchExecutionRequest {\n readonly invocations: readonly Invocation[];\n /** Gas available to the complete wallet root, including all calls. */\n readonly gasLimit: GasAmount;\n}\n\n/** Build a root batch directly, copying call bytes before asynchronous work. */\nexport function createDefaultWalletBatchInvocation(\n accountAddress: ContractAddress,\n request: WalletBatchExecutionRequest,\n): Invocation {\n if (\n !Array.isArray(request.invocations) ||\n request.invocations.length < 1 ||\n request.invocations.length > MAX_DEFAULT_WALLET_CALLS\n )\n throw new RangeError(\"DefaultWallet requires 1 to 16 calls\");\n return DefaultWallet.v0_1.execute.invocation(\n contractAddress(new Uint8Array(accountAddress)),\n request.gasLimit,\n {\n // This builder mints no auth tokens and forwards none.\n mints: [],\n calls: request.invocations.map((inner) => ({\n target: contractAddress(new Uint8Array(inner.invoked_address)),\n entrypoint: fixedBytes(new Uint8Array(inner.entrypoint), 8),\n gas_limit: inner.gas_limit,\n calldata: new Uint8Array(inner.calldata),\n tokens: [],\n })),\n },\n );\n}\n\n/** Converts a wallet-specific execution request into a root invocation. */\nexport interface WalletInvocationAdapter<\n TRequest extends WalletExecutionRequest = WalletExecutionRequest,\n> {\n /** Build a root deployment when supported by this wallet. */\n createDeploymentInvocation?(\n account: ContractAddress,\n deployment: ContractDeployment,\n options: DeploymentOptions,\n ): Invocation;\n /** Decode the address returned by a root deployment. */\n decodeDeploymentReceipt?(receipt: TransactionReceipt): ContractAddress;\n /** Child return buffers in call order, or null when this wallet discards them. */\n decodeExecutionReturns?(\n receipt: TransactionReceipt,\n ): readonly Uint8Array[] | null;\n /** Build one atomic root for multiple calls when this wallet supports it. */\n createBatchRootInvocation?(\n account: ContractAddress,\n request: WalletBatchExecutionRequest,\n ): Invocation;\n createRootInvocation(\n accountAddress: ContractAddress,\n request: TRequest,\n ): Invocation;\n}\n\n/** Define an invocation adapter while preserving its request type. */\nexport function defineWalletInvocationAdapter<\n TRequest extends WalletExecutionRequest,\n>(\n adapter: WalletInvocationAdapter<TRequest>,\n): WalletInvocationAdapter<TRequest> {\n return adapter;\n}\n\n/** Wrap one call through the native-compatible DefaultWallet interface. */\nexport const defaultWalletAdapter = defineWalletInvocationAdapter({\n createBatchRootInvocation: createDefaultWalletBatchInvocation,\n decodeExecutionReturns: (receipt) =>\n DefaultWallet.v0_1.execute.decodeReceipt(receipt).value,\n createDeploymentInvocation(account, deployment, options) {\n if (\n options.initializer &&\n !bytesEqual(options.initializer.invoked_address, deployment.address)\n )\n throw new Error(\n \"Initializer must target the predicted deployment address\",\n );\n // The wallet takes an i128, but a deployment never funds a negative amount.\n if (options.amount < 0n)\n throw new RangeError(\"Deployment amount must not be negative\");\n return DefaultWallet.v0_1.deploy.invocation(account, options.gasLimit, {\n nonce: fixedBytes(deployment.deploymentNonce, 32),\n contractHash: fixedBytes(deployment.contractHash, 32),\n amount: options.amount,\n initializer: options.initializer\n ? {\n entrypoint: fixedBytes(options.initializer.entrypoint, 8),\n gas_limit: options.initializer.gas_limit,\n calldata: options.initializer.calldata,\n }\n : null,\n });\n },\n decodeDeploymentReceipt: (receipt) =>\n DefaultWallet.v0_1.deploy.decodeReceipt(receipt).value,\n createRootInvocation(\n accountAddress: ContractAddress,\n request: WalletExecutionRequest,\n ): Invocation {\n return createDefaultWalletBatchInvocation(accountAddress, {\n invocations: [request.invocation],\n gasLimit: request.gasLimit,\n });\n },\n});\n\n/** Wrap one call through the legacy DevWallet. Unified deployment is unsupported. */\nexport const devWalletAdapter = defineWalletInvocationAdapter({\n decodeExecutionReturns: () => null,\n createRootInvocation(\n accountAddress: ContractAddress,\n request: WalletExecutionRequest,\n ): Invocation {\n return DevWallet.v0_1.doAction.invocation(\n contractAddress(new Uint8Array(accountAddress)),\n request.gasLimit,\n {\n invocationBytes: serialize(request.invocation, codec.Invocation),\n },\n );\n },\n});\n","import { validateTimer } from \"../actions/deadline.js\";\nimport type { WaitForTransactionReceiptOptions } from \"../actions/public/waitForTransactionReceipt.js\";\n\n/**\n * Check execution wait options before preparing or signing, so an invalid\n * option never leaves a signed or sent transaction. `knownCommitment` applies\n * only to observing an existing hash, so execution rejects it.\n * @internal\n */\nexport function validateExecutionWait(\n wait: WaitForTransactionReceiptOptions | undefined,\n): void {\n validateTimer(wait?.timeoutMs ?? 30000, \"timeoutMs\");\n validateTimer(wait?.pollingIntervalMs ?? 250, \"pollingIntervalMs\");\n if (wait?.knownCommitment !== undefined)\n throw new TypeError(\n \"knownCommitment applies only when observing an existing transaction\",\n );\n}\n","import { codec, deserialize } from \"@thruputchain/protocol\";\nimport { hashSignedTransaction } from \"../derivation/transactionHash.js\";\n\n/** Exact signed bytes, their transaction hash, and the signing network. */\nexport interface SubmissionEvidence {\n readonly signedTransaction: Uint8Array;\n readonly transactionHash: Uint8Array;\n readonly networkHash: Uint8Array;\n}\n/** Snapshot approved bytes before submission; accessor copies protect the retained record. */\nexport function createSubmissionEvidence(\n bytes: Uint8Array,\n network: Uint8Array,\n): SubmissionEvidence {\n const signedTransaction = new Uint8Array(bytes);\n const networkHash = new Uint8Array(network);\n if (networkHash.length !== 32)\n throw new RangeError(\"networkHash must contain 32 bytes\");\n const transactionHash = hashSignedTransaction(\n deserialize(signedTransaction, codec.SignedTransaction),\n );\n return Object.freeze({\n get signedTransaction() {\n return signedTransaction.slice();\n },\n get transactionHash() {\n return transactionHash.slice();\n },\n get networkHash() {\n return networkHash.slice();\n },\n });\n}\n","import { toBase58 } from \"../encoding.js\";\nimport { isThruputError, ThruputError } from \"../errors/thruputError.js\";\nimport type { TransactionOutcomeUnknownContext } from \"../errors/codes.js\";\nimport type { TransactionReason } from \"../errors/transaction.js\";\nimport { classifyReadError } from \"../transport/readError.js\";\nimport { isLocalError } from \"../rpc/localError.js\";\nimport type { SubmissionEvidence } from \"../transaction/submissionEvidence.js\";\n\n// Internal constructors for transaction errors. Public APIs re-export none of these.\n\n/** The client did not dispatch the signed transaction. */\nexport function transactionNotSubmitted(\n submission: SubmissionEvidence,\n reason: TransactionReason,\n cause: unknown,\n): ThruputError<\"transactionNotSubmitted\"> {\n return new ThruputError(\n \"transactionNotSubmitted\",\n `Transaction ${toBase58(submission.transactionHash)} was not submitted`,\n {\n cause,\n transaction: {\n hash: submission.transactionHash,\n outcome: \"notSubmitted\",\n reason,\n submission,\n },\n },\n );\n}\n\n/** Submission stopped, and the outcome is unknown. Never resend. */\nexport function transactionOutcomeUnknown(\n submission: SubmissionEvidence,\n reason: TransactionReason,\n cause: unknown,\n context: TransactionOutcomeUnknownContext = {},\n): ThruputError<\"transactionOutcomeUnknown\"> {\n return new ThruputError(\n \"transactionOutcomeUnknown\",\n `Could not complete transaction ${toBase58(submission.transactionHash)}`,\n {\n context,\n cause,\n transaction: {\n hash: submission.transactionHash,\n outcome: \"unknown\",\n reason,\n submission,\n },\n },\n );\n}\n\n/** Add the signed bytes, and an earlier submission failure, to an observation error. */\nexport function withSubmission(\n error: unknown,\n submission: SubmissionEvidence,\n submissionError?: unknown,\n): ThruputError<\"transactionOutcomeUnknown\"> {\n const extra = submissionError === undefined ? {} : { submissionError };\n if (!isThruputError(error, \"transactionOutcomeUnknown\") || !error.transaction)\n return transactionOutcomeUnknown(\n submission,\n \"observationFailed\",\n error,\n extra,\n );\n return new ThruputError(\"transactionOutcomeUnknown\", error.message, {\n context: { ...error.context, ...extra },\n ...(error.cause === undefined ? {} : { cause: error.cause }),\n transaction: { ...error.transaction, submission },\n });\n}\n\n/**\n * True when the error is the caller's abort reason. An abort reason can be any\n * value, so never read its code as evidence about this transaction.\n */\nexport function isCancellation(\n cause: unknown,\n signal: AbortSignal | undefined,\n): boolean {\n return signal?.aborted === true && cause === signal.reason;\n}\n\n/**\n * True when a local check of this client rejected the request before dispatch.\n * The code alone is not proof: a transport can throw the same code after it\n * sent the request.\n */\nexport function isLocalRequestError(\n cause: unknown,\n signal: AbortSignal | undefined,\n): boolean {\n return (\n !isCancellation(cause, signal) &&\n isLocalError(cause) &&\n (isThruputError(cause, \"rpcRequestInvalid\") ||\n isThruputError(cause, \"rpcIncompatible\"))\n );\n}\n\n/** A failure before dispatch, after signing and `onSigned`. */\nexport function reasonBeforeDispatch(\n cause: unknown,\n signal: AbortSignal | undefined,\n): TransactionReason {\n if (signal?.aborted) return \"cancelled\";\n if (isLocalRequestError(cause, signal)) return \"requestInvalid\";\n if (isTimeout(cause)) return \"timeout\";\n return \"notDispatched\";\n}\n\n/** True when the node answered that it did not admit the transaction. */\nexport function isNodeRejection(cause: unknown): boolean {\n return (\n isThruputError(cause, \"nativeRpcError\") &&\n (cause.context.kind === \"invalidParams\" ||\n cause.context.kind === \"transactionInvalid\" ||\n cause.context.kind === \"transactionRejected\")\n );\n}\n\n/** A failure after dispatch. None of these proves that the node did not receive it. */\nexport function reasonAfterDispatch(\n cause: unknown,\n signal: AbortSignal | undefined,\n): TransactionReason {\n if (signal?.aborted) return \"cancelled\";\n if (isNodeRejection(cause)) return \"nodeRejected\";\n if (isTimeout(cause)) return \"timeout\";\n if (classifyReadError(cause) === \"transient\") return \"disconnected\";\n return \"submissionFailed\";\n}\n\n/** A deadline error. Uses the web-standard `TimeoutError` name. */\nexport function timeoutError(message: string): DOMException {\n return new DOMException(message, \"TimeoutError\");\n}\n\nfunction isTimeout(cause: unknown): boolean {\n return (\n cause !== null &&\n typeof cause === \"object\" &&\n \"name\" in cause &&\n cause.name === \"TimeoutError\"\n );\n}\n","import { isUnsupportedRpcValue } from \"../rpc/unsupported.js\";\nimport { ThruputError } from \"../errors/thruputError.js\";\nimport {\n receiptFacts,\n transactionResultUndecodable,\n} from \"../errors/transaction.js\";\nimport { contractDecodeFailed } from \"../contract/errors.js\";\nimport { gasAmount, type GasAmount } from \"@thruputchain/protocol\";\nimport type { CoreThruputClient } from \"../client.js\";\nimport type { TransactionReceipt } from \"../types/rpc.js\";\nimport type { WaitForTransactionReceiptOptions } from \"../actions/public/waitForTransactionReceipt.js\";\nimport type { ContractCall } from \"../contract/method.js\";\nimport {\n defaultWalletAdapter,\n type WalletInvocationAdapter,\n} from \"./invocationAdapter.js\";\nimport { beforeDeadline } from \"../actions/deadline.js\";\nimport { validateExecutionWait } from \"./executionWait.js\";\nimport { toBase58 } from \"../encoding.js\";\nimport type { RpcSendTransactionResult } from \"../rpc/generated.js\";\nimport {\n createSubmissionEvidence,\n type SubmissionEvidence,\n} from \"../transaction/submissionEvidence.js\";\nimport {\n isCancellation,\n isLocalRequestError,\n isNodeRejection,\n reasonAfterDispatch,\n reasonBeforeDispatch,\n timeoutError,\n transactionNotSubmitted,\n transactionOutcomeUnknown,\n withSubmission,\n} from \"./transactionErrors.js\";\n\n/**\n * Require successful execution. A failed execution throws code\n * `transactionFailed`; an unsupported execution value throws code\n * `transactionOutcomeUnsupported`, never inferred to be success or failure.\n * Both keep the complete receipt in `transaction.receipt`.\n */\nexport function assertTransactionSuccess(\n receipt: TransactionReceipt,\n submission?: SubmissionEvidence,\n): asserts receipt is TransactionReceipt & {\n execution: { result: \"return\"; returnData: Uint8Array };\n} {\n const hash = toBase58(receipt.transactionHash);\n const facts = receiptFacts(receipt, \"outcomeUnsupported\", submission);\n if (facts.outcome === \"succeeded\") return;\n const { execution } = receipt;\n if (facts.outcome === \"failed\" && !isUnsupportedRpcValue(execution))\n throw new ThruputError(\n \"transactionFailed\",\n `Transaction ${hash} execution failed (${execution.result})`,\n { transaction: facts },\n );\n throw new ThruputError(\n \"transactionOutcomeUnsupported\",\n `Transaction ${hash} has an unsupported execution outcome`,\n { transaction: facts },\n );\n}\n\n/**\n * Keep low-level future values intact, but never project them into an admitted\n * hash. An admission value other than `accepted` throws code\n * `transactionAdmissionUnsupported` with outcome `unknown`.\n */\nexport function assertTransactionAdmission(\n response: RpcSendTransactionResult,\n submission?: SubmissionEvidence,\n): void {\n if (response.admission !== \"accepted\")\n throw new ThruputError(\n \"transactionAdmissionUnsupported\",\n \"Transaction submission returned an unsupported admission outcome\",\n {\n context: { response },\n transaction: {\n hash: submission?.transactionHash ?? response.transactionHash,\n outcome: \"unknown\",\n reason: \"admissionUnsupported\",\n ...(submission ? { submission } : {}),\n },\n },\n );\n}\nexport {\n createSubmissionEvidence,\n type SubmissionEvidence,\n} from \"../transaction/submissionEvidence.js\";\nexport interface ExecutionResult {\n transactionHash: Uint8Array;\n receipt: TransactionReceipt;\n submission?: SubmissionEvidence;\n}\n/**\n * Submit once, then reconcile only by reads. No path replaces or repeats signed\n * bytes. Every failure has `transaction` facts with the signed bytes:\n * `transactionNotSubmitted` before dispatch, otherwise\n * `transactionOutcomeUnknown`. `wasDispatched` reports whether these bytes have\n * been sent, by this call or an earlier one; when it is `true`, no failure is\n * `notSubmitted`.\n */\nexport async function submitAndObserve(\n client: Pick<CoreThruputClient, \"waitForTransactionReceipt\">,\n evidence: SubmissionEvidence,\n submit: (signal: AbortSignal) => Promise<void>,\n options?: WaitForTransactionReceiptOptions,\n wasDispatched?: () => boolean,\n): Promise<ExecutionResult> {\n const submission = createSubmissionEvidence(\n evidence.signedTransaction,\n evidence.networkHash,\n );\n // An invalid option must fail before the transaction can be sent.\n validateExecutionWait(options);\n const timeoutMs = options?.timeoutMs ?? 30000;\n const deadline = performance.now() + timeoutMs;\n const signal = options?.signal;\n // The caller may know that identical bytes were sent before this call.\n const stopped = wasDispatched?.()\n ? transactionOutcomeUnknown\n : transactionNotSubmitted;\n if (signal?.aborted) throw stopped(submission, \"cancelled\", signal.reason);\n if (timeoutMs === 0)\n throw stopped(\n submission,\n \"timeout\",\n timeoutError(\"Transaction submission timed out before dispatch\"),\n );\n let submissionError: unknown;\n try {\n await beforeDeadline(submit, deadline, signal, () =>\n timeoutError(\"Transaction submission timed out\"),\n );\n } catch (cause) {\n // When the caller tracks dispatch, only its answer can prove the\n // transaction was not sent; an error code alone cannot.\n const dispatched = wasDispatched?.();\n if (\n dispatched === false ||\n (dispatched === undefined && isLocalRequestError(cause, signal))\n )\n throw transactionNotSubmitted(\n submission,\n reasonBeforeDispatch(cause, signal),\n cause,\n );\n if (!isCancellation(cause, signal) && isNodeRejection(cause))\n throw transactionOutcomeUnknown(submission, \"nodeRejected\", cause);\n if (signal?.aborted || performance.now() >= deadline)\n throw transactionOutcomeUnknown(\n submission,\n reasonAfterDispatch(cause, signal),\n cause,\n );\n // The node may have the transaction. Observe it; never submit again.\n submissionError = cause;\n }\n try {\n const receipt = await client.waitForTransactionReceipt(\n submission.transactionHash,\n {\n ...options,\n expectedNetworkHash: submission.networkHash,\n timeoutMs: Math.max(0, deadline - performance.now()),\n },\n );\n return { transactionHash: receipt.transactionHash, receipt, submission };\n } catch (cause) {\n throw withSubmission(cause, submission, submissionError);\n }\n}\n/** Wait for a committed receipt, then require execution success. */\nexport async function waitForExecution(\n client: Pick<CoreThruputClient, \"waitForTransactionReceipt\">,\n hash: Uint8Array,\n options?: WaitForTransactionReceiptOptions,\n): Promise<ExecutionResult> {\n const receipt = await client.waitForTransactionReceipt(hash, options);\n assertTransactionSuccess(receipt);\n return { transactionHash: receipt.transactionHash, receipt };\n}\n\n/** Ordered result types for a tuple of calls. */\nexport type CallResults<T extends readonly ContractCall[]> = {\n [K in keyof T]: T[K] extends ContractCall<infer R> ? R : never;\n};\n\n/**\n * Decode DefaultWallet child returns without modifying the root receipt.\n * Works after disconnect and preserves call order. Supply an adapter for other\n * wallets. Wallets such as DevWallet that discard child return data report\n * unavailable results. Failed wallet receipts are not decoded with a child ABI:\n * even a single child call does not establish where an abort originated.\n */\nexport function decodeExecution<T extends readonly ContractCall[]>(\n receipt: TransactionReceipt,\n calls: T,\n adapter: WalletInvocationAdapter = defaultWalletAdapter,\n submission?: SubmissionEvidence,\n): CallResults<T> {\n // Even one child call can fail in the wallet root; its abort bytes are not a child receipt.\n assertTransactionSuccess(receipt, submission);\n let results: CallResults<T> | undefined;\n try {\n const buffers = adapter.decodeExecutionReturns?.(receipt);\n if (buffers != null) {\n if (buffers.length !== calls.length)\n throw contractDecodeFailed(\n `Returned ${buffers.length} child results; expected ${calls.length}`,\n );\n results = calls.map((call, index) =>\n call.method.decodeReturn(buffers[index]!),\n ) as CallResults<T>;\n }\n } catch (cause) {\n // Wrap everything, even a ThruputError from the adapter, so the facts\n // always describe this receipt.\n throw transactionResultUndecodable(receipt, cause, submission);\n }\n if (results === undefined) throw resultUnavailable(receipt, submission);\n return results;\n}\n\n/** Execution succeeded, but this wallet does not preserve child return buffers. */\nfunction resultUnavailable(\n receipt: TransactionReceipt,\n submission?: SubmissionEvidence,\n): ThruputError<\"transactionResultUnavailable\"> {\n return new ThruputError(\n \"transactionResultUnavailable\",\n `Transaction ${toBase58(receipt.transactionHash)} committed successfully, but its wallet does not expose child return data`,\n { transaction: receiptFacts(receipt, \"resultUnavailable\", submission) },\n );\n}\n\n/**\n * Sum explicit child budgets and a calibrated wallet overhead, checking u64 bounds.\n * This is not gas estimation. Calibrate budgets against the target runtime and\n * workload; there is no universally safe wallet overhead. Root gas reserves\n * scheduling capacity against the sender's free native-token balance. Storage\n * deposits are a separate requirement, and funding a target contract does not\n * sponsor root gas.\n */\nexport function walletGasLimit(\n calls: readonly { gas_limit: GasAmount }[],\n overhead: GasAmount,\n): GasAmount {\n const limits = [overhead, ...calls.map((call) => call.gas_limit)];\n if (limits.some((limit) => typeof limit !== \"bigint\" || limit < 0n))\n throw new RangeError(\"Gas budgets must be nonnegative bigint values\");\n const total = limits.reduce((sum, limit) => sum + limit, 0n);\n if (total > 0xffff_ffff_ffff_ffffn)\n throw new RangeError(\"Root gas budget exceeds u64\");\n return gasAmount(total);\n}\n","import {\n blockHeight,\n codec,\n deserialize,\n serialize,\n type BlockHeight,\n type Contract,\n type Invocation,\n type Transaction,\n} from \"@thruputchain/protocol\";\nimport type { CoreThruputClient } from \"../../client.js\";\nimport type { WalletAccount } from \"../../wallet/account.js\";\nimport { createTransaction } from \"../../transaction/build.js\";\n\nconst int64Max = 0x7fff_ffff_ffff_ffffn;\nconst uint64Max = 0xffff_ffff_ffff_ffffn;\nconst defaultExpiryBlocks = 100n;\n\n/** Inputs for preparing one wallet-authorized transaction. */\nexport interface PrepareTransactionRequest {\n /** Explicit root invocation. Smart-wallet wrapping is caller-controlled. */\n readonly invocation: Invocation;\n readonly contractsToDeploy?: readonly Contract[];\n readonly nonce?: bigint;\n readonly blockExpiryHeight?: BlockHeight;\n readonly expiryBlocks?: bigint;\n}\n\n/** Prepare an unsigned transaction for a wallet account. */\nexport async function prepareTransaction(\n client: Pick<CoreThruputClient, \"getChainTip\">,\n account: Pick<WalletAccount, \"address\" | \"authClaim\">,\n request: PrepareTransactionRequest,\n): Promise<Transaction> {\n const invocation = deserialize(\n serialize(request.invocation, codec.Invocation),\n codec.Invocation,\n );\n const contractsToDeploy = (request.contractsToDeploy ?? []).map((contract) =>\n deserialize(serialize(contract, codec.Contract), codec.Contract),\n );\n const authClaim = deserialize(\n serialize(account.authClaim, codec.AuthClaim),\n codec.AuthClaim,\n );\n\n if (!bytesEqual(invocation.invoked_address, account.address)) {\n throw new Error(\"Root invocation address must match the wallet account\");\n }\n if (\n request.blockExpiryHeight !== undefined &&\n request.expiryBlocks !== undefined\n ) {\n throw new Error(\n \"blockExpiryHeight and expiryBlocks are mutually exclusive\",\n );\n }\n\n const nonce = request.nonce ?? randomUint64();\n validateRange(nonce, 0n, uint64Max, \"nonce\");\n\n let expiry: bigint;\n if (request.blockExpiryHeight !== undefined) {\n expiry = request.blockExpiryHeight;\n validateRange(expiry, 0n, int64Max, \"blockExpiryHeight\");\n } else {\n const expiryBlocks = request.expiryBlocks ?? defaultExpiryBlocks;\n validateRange(expiryBlocks, 1n, int64Max, \"expiryBlocks\");\n const tip = await client.getChainTip();\n expiry = tip.blockHeight + expiryBlocks;\n validateRange(expiry, 0n, int64Max, \"blockExpiryHeight\");\n }\n\n return createTransaction({\n invocation,\n uniquifier: {\n block_expiry_height: blockHeight(expiry),\n nonce,\n },\n contracts_to_deploy: contractsToDeploy,\n auth_claim: authClaim,\n });\n}\n\nfunction randomUint64(): bigint {\n const bytes = crypto.getRandomValues(new Uint8Array(8));\n return new DataView(\n bytes.buffer,\n bytes.byteOffset,\n bytes.byteLength,\n ).getBigUint64(0);\n}\n\nfunction validateRange(\n value: bigint,\n min: bigint,\n max: bigint,\n name: string,\n): void {\n if (typeof value !== \"bigint\" || value < min || value > max) {\n throw new RangeError(`${name} must be between ${min} and ${max}`);\n }\n}\n\nfunction bytesEqual(left: Uint8Array, right: Uint8Array): boolean {\n if (left.length !== right.length) return false;\n return left.every((byte, index) => byte === right[index]);\n}\n","import type {\n SHA256Hash,\n SignedTransaction,\n Transaction,\n NetworkHash,\n} from \"@thruputchain/protocol\";\nimport { codec, serialize, sha256Hash } from \"@thruputchain/protocol\";\nimport {\n createSubmissionEvidence,\n assertTransactionAdmission,\n type SubmissionEvidence,\n} from \"../../wallet/execution.js\";\nimport { rpcIncompatible } from \"../../rpc/client.js\";\nimport {\n isLocalRequestError,\n reasonAfterDispatch,\n reasonBeforeDispatch,\n transactionNotSubmitted,\n transactionOutcomeUnknown,\n} from \"../../wallet/transactionErrors.js\";\nimport type { CoreThruputClient } from \"../../client.js\";\nimport type { WalletAccount } from \"../../wallet/account.js\";\nimport { signTransaction as sign } from \"../../transaction/sign.js\";\nimport {\n prepareTransaction,\n type PrepareTransactionRequest,\n} from \"./prepareTransaction.js\";\n\n/** Sign a transaction with a wallet account's configured signers. */\nexport function signWalletTransaction(\n account: WalletAccount,\n transaction: Transaction,\n networkHash: NetworkHash,\n): Promise<SignedTransaction> {\n return sign(transaction, account.signers, networkHash);\n}\n\n/** Prepare, sign, and submit one explicit root invocation. */\nexport async function sendInvocation(\n client: Pick<\n CoreThruputClient,\n \"getChainTip\" | \"sendTransaction\" | \"requireMethods\" | \"discovery\"\n >,\n account: WalletAccount,\n networkHash: NetworkHash,\n request: PrepareTransactionRequest,\n controls: {\n signal?: AbortSignal;\n onSigned?: (evidence: SubmissionEvidence) => void | Promise<void>;\n } = {},\n): Promise<SHA256Hash> {\n controls.signal?.throwIfAborted();\n client.requireMethods([\"getChainTip\", \"sendTransaction\"]);\n const signingNetwork = new Uint8Array(networkHash) as NetworkHash;\n const checkNetwork = () => {\n const discovered = client.discovery.network.networkHash;\n if (\n signingNetwork.length !== 32 ||\n discovered.length !== 32 ||\n signingNetwork.some((value, index) => value !== discovered[index])\n )\n throw rpcIncompatible(\n \"network\",\n \"Signing network does not match endpoint discovery\",\n );\n };\n checkNetwork();\n const signers = account.signers.map(({ signer, publicKeyId }) => ({\n signer,\n publicKeyId,\n }));\n const transaction = await prepareTransaction(client, account, request);\n // Do not sign a transaction the caller has cancelled.\n controls.signal?.throwIfAborted();\n checkNetwork();\n const signed = await sign(transaction, signers, signingNetwork);\n const evidence = createSubmissionEvidence(\n serialize(signed, codec.SignedTransaction),\n signingNetwork,\n );\n // Do not persist a transaction the caller cancelled while it was signed.\n if (controls.signal?.aborted)\n throw transactionNotSubmitted(\n evidence,\n \"cancelled\",\n controls.signal.reason,\n );\n try {\n await controls.onSigned?.(evidence);\n } catch (cause) {\n throw transactionNotSubmitted(evidence, \"persistenceFailed\", cause);\n }\n try {\n controls.signal?.throwIfAborted();\n checkNetwork();\n } catch (cause) {\n throw transactionNotSubmitted(\n evidence,\n reasonBeforeDispatch(cause, controls.signal),\n cause,\n );\n }\n let result;\n try {\n result = await client.sendTransaction(\n { signedTransaction: evidence.signedTransaction },\n { signal: controls.signal },\n );\n } catch (cause) {\n if (isLocalRequestError(cause, controls.signal))\n throw transactionNotSubmitted(evidence, \"requestInvalid\", cause);\n throw transactionOutcomeUnknown(\n evidence,\n reasonAfterDispatch(cause, controls.signal),\n cause,\n );\n }\n assertTransactionAdmission(result, evidence);\n return sha256Hash(result.transactionHash);\n}\n"],"mappings":";;;;;;;;;;;;;AACA,eAAsB,eACpB,WACA,UACA,QACA,SACY;CACZ,QAAQ,eAAe;CACvB,IAAI,YAAY,IAAI,KAAK,UAAU,MAAM,QAAQ;CACjD,MAAM,aAAa,IAAI,gBAAgB;CACvC,MAAM,SAAS,SACX,YAAY,IAAI,CAAC,QAAQ,WAAW,MAAM,CAAC,IAC3C,WAAW;CACf,IAAI;CACJ,IAAI,gBAAgB,CAAC;CACrB,IAAI;EACF,OAAO,MAAM,QAAQ,KAAK,CACxB,IAAI,SAAY,GAAG,WAAW;GAC5B,gBAAgB,OAAO,OAAO,MAA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S,MAAM,GAC5C,MAAM,wBAAwB,UAAU,kBAAkB,KAAK;EACjE,MAAM,0BACJ,UACA,oBAAoB,OAAO,SAAS,MAAM,GAC1C,KACF;CACF;CACA,2BAA2B,QAAQ,QAAQ;CAC3C,QAAA,GAAA,uBAAA,WAAA,CAAkB,OAAO,eAAe;AAC1C"}
|
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
import { a as isUnsupportedRpcValue, o as ThruputError, s as isThruputError } from "./decimal-CoHOISys.js";
|
|
2
|
+
import { g as toBase58 } from "./hex-B8D-jBgz.js";
|
|
3
|
+
import { C as contractDecodeFailed, F as transactionResultUndecodable, M as receiptFacts, o as bytesEqual$1 } from "./contract-BOlNskwd.js";
|
|
4
|
+
import { r as createTransaction, t as signTransaction } from "./sign-DVIRyW8Y.js";
|
|
5
|
+
import { t as hashSignedTransaction } from "./transactionHash-CO9ajbvU.js";
|
|
6
|
+
import { i as isLocalError, r as rpcIncompatible, t as classifyReadError } from "./readError-B3Rz7rgs.js";
|
|
7
|
+
import { r as DefaultWallet, t as DevWallet } from "./dev_wallet-D9LuPZ-h.js";
|
|
8
|
+
import "./validation-BLQ64Dfh.js";
|
|
9
|
+
import { blockHeight, codec, contractAddress, deserialize, gasAmount, serialize, sha256Hash } from "@thruputchain/protocol";
|
|
10
|
+
import { fixedBytes } from "@thruputchain/xdr";
|
|
11
|
+
//#region src/actions/deadline.ts
|
|
12
|
+
/** Run one operation within the caller's wall-clock budget and cancellation signal. */
|
|
13
|
+
async function beforeDeadline(operation, deadline, caller, timeout) {
|
|
14
|
+
caller?.throwIfAborted();
|
|
15
|
+
if (performance.now() >= deadline) throw timeout();
|
|
16
|
+
const controller = new AbortController();
|
|
17
|
+
const signal = caller ? AbortSignal.any([caller, controller.signal]) : controller.signal;
|
|
18
|
+
let timer;
|
|
19
|
+
let onAbort = () => {};
|
|
20
|
+
try {
|
|
21
|
+
return await Promise.race([new Promise((_, reject) => {
|
|
22
|
+
onAbort = () => reject(signal.reason);
|
|
23
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
24
|
+
timer = setTimeout(() => controller.abort(timeout()), Math.ceil(Math.max(0, deadline - performance.now())));
|
|
25
|
+
}), operation(signal)]);
|
|
26
|
+
} finally {
|
|
27
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
28
|
+
signal.removeEventListener("abort", onAbort);
|
|
29
|
+
controller.abort();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function validateTimer(value, field) {
|
|
33
|
+
if (!Number.isFinite(value) || value < 0 || value > 2147483647) throw new RangeError(`${field} must be between 0 and 2147483647`);
|
|
34
|
+
}
|
|
35
|
+
function waitDelay(delay, signal) {
|
|
36
|
+
return new Promise((resolve, reject) => {
|
|
37
|
+
signal.throwIfAborted();
|
|
38
|
+
const finish = () => {
|
|
39
|
+
signal.removeEventListener("abort", abort);
|
|
40
|
+
resolve();
|
|
41
|
+
};
|
|
42
|
+
const timer = setTimeout(finish, delay);
|
|
43
|
+
const abort = () => {
|
|
44
|
+
clearTimeout(timer);
|
|
45
|
+
signal.removeEventListener("abort", abort);
|
|
46
|
+
reject(signal.reason);
|
|
47
|
+
};
|
|
48
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/wallet/invocationAdapter.ts
|
|
53
|
+
/** Build a root batch directly, copying call bytes before asynchronous work. */
|
|
54
|
+
function createDefaultWalletBatchInvocation(accountAddress, request) {
|
|
55
|
+
if (!Array.isArray(request.invocations) || request.invocations.length < 1 || request.invocations.length > 16) throw new RangeError("DefaultWallet requires 1 to 16 calls");
|
|
56
|
+
return DefaultWallet.v0_1.execute.invocation(contractAddress(new Uint8Array(accountAddress)), request.gasLimit, {
|
|
57
|
+
mints: [],
|
|
58
|
+
calls: request.invocations.map((inner) => ({
|
|
59
|
+
target: contractAddress(new Uint8Array(inner.invoked_address)),
|
|
60
|
+
entrypoint: fixedBytes(new Uint8Array(inner.entrypoint), 8),
|
|
61
|
+
gas_limit: inner.gas_limit,
|
|
62
|
+
calldata: new Uint8Array(inner.calldata),
|
|
63
|
+
tokens: []
|
|
64
|
+
}))
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/** Define an invocation adapter while preserving its request type. */
|
|
68
|
+
function defineWalletInvocationAdapter(adapter) {
|
|
69
|
+
return adapter;
|
|
70
|
+
}
|
|
71
|
+
/** Wrap one call through the native-compatible DefaultWallet interface. */
|
|
72
|
+
const defaultWalletAdapter = defineWalletInvocationAdapter({
|
|
73
|
+
createBatchRootInvocation: createDefaultWalletBatchInvocation,
|
|
74
|
+
decodeExecutionReturns: (receipt) => DefaultWallet.v0_1.execute.decodeReceipt(receipt).value,
|
|
75
|
+
createDeploymentInvocation(account, deployment, options) {
|
|
76
|
+
if (options.initializer && !bytesEqual$1(options.initializer.invoked_address, deployment.address)) throw new Error("Initializer must target the predicted deployment address");
|
|
77
|
+
if (options.amount < 0n) throw new RangeError("Deployment amount must not be negative");
|
|
78
|
+
return DefaultWallet.v0_1.deploy.invocation(account, options.gasLimit, {
|
|
79
|
+
nonce: fixedBytes(deployment.deploymentNonce, 32),
|
|
80
|
+
contractHash: fixedBytes(deployment.contractHash, 32),
|
|
81
|
+
amount: options.amount,
|
|
82
|
+
initializer: options.initializer ? {
|
|
83
|
+
entrypoint: fixedBytes(options.initializer.entrypoint, 8),
|
|
84
|
+
gas_limit: options.initializer.gas_limit,
|
|
85
|
+
calldata: options.initializer.calldata
|
|
86
|
+
} : null
|
|
87
|
+
});
|
|
88
|
+
},
|
|
89
|
+
decodeDeploymentReceipt: (receipt) => DefaultWallet.v0_1.deploy.decodeReceipt(receipt).value,
|
|
90
|
+
createRootInvocation(accountAddress, request) {
|
|
91
|
+
return createDefaultWalletBatchInvocation(accountAddress, {
|
|
92
|
+
invocations: [request.invocation],
|
|
93
|
+
gasLimit: request.gasLimit
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
/** Wrap one call through the legacy DevWallet. Unified deployment is unsupported. */
|
|
98
|
+
const devWalletAdapter = defineWalletInvocationAdapter({
|
|
99
|
+
decodeExecutionReturns: () => null,
|
|
100
|
+
createRootInvocation(accountAddress, request) {
|
|
101
|
+
return DevWallet.v0_1.doAction.invocation(contractAddress(new Uint8Array(accountAddress)), request.gasLimit, { invocationBytes: serialize(request.invocation, codec.Invocation) });
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
//#endregion
|
|
105
|
+
//#region src/wallet/executionWait.ts
|
|
106
|
+
/**
|
|
107
|
+
* Check execution wait options before preparing or signing, so an invalid
|
|
108
|
+
* option never leaves a signed or sent transaction. `knownCommitment` applies
|
|
109
|
+
* only to observing an existing hash, so execution rejects it.
|
|
110
|
+
* @internal
|
|
111
|
+
*/
|
|
112
|
+
function validateExecutionWait(wait) {
|
|
113
|
+
validateTimer(wait?.timeoutMs ?? 3e4, "timeoutMs");
|
|
114
|
+
validateTimer(wait?.pollingIntervalMs ?? 250, "pollingIntervalMs");
|
|
115
|
+
if (wait?.knownCommitment !== void 0) throw new TypeError("knownCommitment applies only when observing an existing transaction");
|
|
116
|
+
}
|
|
117
|
+
//#endregion
|
|
118
|
+
//#region src/transaction/submissionEvidence.ts
|
|
119
|
+
/** Snapshot approved bytes before submission; accessor copies protect the retained record. */
|
|
120
|
+
function createSubmissionEvidence(bytes, network) {
|
|
121
|
+
const signedTransaction = new Uint8Array(bytes);
|
|
122
|
+
const networkHash = new Uint8Array(network);
|
|
123
|
+
if (networkHash.length !== 32) throw new RangeError("networkHash must contain 32 bytes");
|
|
124
|
+
const transactionHash = hashSignedTransaction(deserialize(signedTransaction, codec.SignedTransaction));
|
|
125
|
+
return Object.freeze({
|
|
126
|
+
get signedTransaction() {
|
|
127
|
+
return signedTransaction.slice();
|
|
128
|
+
},
|
|
129
|
+
get transactionHash() {
|
|
130
|
+
return transactionHash.slice();
|
|
131
|
+
},
|
|
132
|
+
get networkHash() {
|
|
133
|
+
return networkHash.slice();
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
//#endregion
|
|
138
|
+
//#region src/wallet/transactionErrors.ts
|
|
139
|
+
/** The client did not dispatch the signed transaction. */
|
|
140
|
+
function transactionNotSubmitted(submission, reason, cause) {
|
|
141
|
+
return new ThruputError("transactionNotSubmitted", `Transaction ${toBase58(submission.transactionHash)} was not submitted`, {
|
|
142
|
+
cause,
|
|
143
|
+
transaction: {
|
|
144
|
+
hash: submission.transactionHash,
|
|
145
|
+
outcome: "notSubmitted",
|
|
146
|
+
reason,
|
|
147
|
+
submission
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
/** Submission stopped, and the outcome is unknown. Never resend. */
|
|
152
|
+
function transactionOutcomeUnknown(submission, reason, cause, context = {}) {
|
|
153
|
+
return new ThruputError("transactionOutcomeUnknown", `Could not complete transaction ${toBase58(submission.transactionHash)}`, {
|
|
154
|
+
context,
|
|
155
|
+
cause,
|
|
156
|
+
transaction: {
|
|
157
|
+
hash: submission.transactionHash,
|
|
158
|
+
outcome: "unknown",
|
|
159
|
+
reason,
|
|
160
|
+
submission
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
/** Add the signed bytes, and an earlier submission failure, to an observation error. */
|
|
165
|
+
function withSubmission(error, submission, submissionError) {
|
|
166
|
+
const extra = submissionError === void 0 ? {} : { submissionError };
|
|
167
|
+
if (!isThruputError(error, "transactionOutcomeUnknown") || !error.transaction) return transactionOutcomeUnknown(submission, "observationFailed", error, extra);
|
|
168
|
+
return new ThruputError("transactionOutcomeUnknown", error.message, {
|
|
169
|
+
context: {
|
|
170
|
+
...error.context,
|
|
171
|
+
...extra
|
|
172
|
+
},
|
|
173
|
+
...error.cause === void 0 ? {} : { cause: error.cause },
|
|
174
|
+
transaction: {
|
|
175
|
+
...error.transaction,
|
|
176
|
+
submission
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* True when the error is the caller's abort reason. An abort reason can be any
|
|
182
|
+
* value, so never read its code as evidence about this transaction.
|
|
183
|
+
*/
|
|
184
|
+
function isCancellation(cause, signal) {
|
|
185
|
+
return signal?.aborted === true && cause === signal.reason;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* True when a local check of this client rejected the request before dispatch.
|
|
189
|
+
* The code alone is not proof: a transport can throw the same code after it
|
|
190
|
+
* sent the request.
|
|
191
|
+
*/
|
|
192
|
+
function isLocalRequestError(cause, signal) {
|
|
193
|
+
return !isCancellation(cause, signal) && isLocalError(cause) && (isThruputError(cause, "rpcRequestInvalid") || isThruputError(cause, "rpcIncompatible"));
|
|
194
|
+
}
|
|
195
|
+
/** A failure before dispatch, after signing and `onSigned`. */
|
|
196
|
+
function reasonBeforeDispatch(cause, signal) {
|
|
197
|
+
if (signal?.aborted) return "cancelled";
|
|
198
|
+
if (isLocalRequestError(cause, signal)) return "requestInvalid";
|
|
199
|
+
if (isTimeout(cause)) return "timeout";
|
|
200
|
+
return "notDispatched";
|
|
201
|
+
}
|
|
202
|
+
/** True when the node answered that it did not admit the transaction. */
|
|
203
|
+
function isNodeRejection(cause) {
|
|
204
|
+
return isThruputError(cause, "nativeRpcError") && (cause.context.kind === "invalidParams" || cause.context.kind === "transactionInvalid" || cause.context.kind === "transactionRejected");
|
|
205
|
+
}
|
|
206
|
+
/** A failure after dispatch. None of these proves that the node did not receive it. */
|
|
207
|
+
function reasonAfterDispatch(cause, signal) {
|
|
208
|
+
if (signal?.aborted) return "cancelled";
|
|
209
|
+
if (isNodeRejection(cause)) return "nodeRejected";
|
|
210
|
+
if (isTimeout(cause)) return "timeout";
|
|
211
|
+
if (classifyReadError(cause) === "transient") return "disconnected";
|
|
212
|
+
return "submissionFailed";
|
|
213
|
+
}
|
|
214
|
+
/** A deadline error. Uses the web-standard `TimeoutError` name. */
|
|
215
|
+
function timeoutError(message) {
|
|
216
|
+
return new DOMException(message, "TimeoutError");
|
|
217
|
+
}
|
|
218
|
+
function isTimeout(cause) {
|
|
219
|
+
return cause !== null && typeof cause === "object" && "name" in cause && cause.name === "TimeoutError";
|
|
220
|
+
}
|
|
221
|
+
//#endregion
|
|
222
|
+
//#region src/wallet/execution.ts
|
|
223
|
+
/**
|
|
224
|
+
* Require successful execution. A failed execution throws code
|
|
225
|
+
* `transactionFailed`; an unsupported execution value throws code
|
|
226
|
+
* `transactionOutcomeUnsupported`, never inferred to be success or failure.
|
|
227
|
+
* Both keep the complete receipt in `transaction.receipt`.
|
|
228
|
+
*/
|
|
229
|
+
function assertTransactionSuccess(receipt, submission) {
|
|
230
|
+
const hash = toBase58(receipt.transactionHash);
|
|
231
|
+
const facts = receiptFacts(receipt, "outcomeUnsupported", submission);
|
|
232
|
+
if (facts.outcome === "succeeded") return;
|
|
233
|
+
const { execution } = receipt;
|
|
234
|
+
if (facts.outcome === "failed" && !isUnsupportedRpcValue(execution)) throw new ThruputError("transactionFailed", `Transaction ${hash} execution failed (${execution.result})`, { transaction: facts });
|
|
235
|
+
throw new ThruputError("transactionOutcomeUnsupported", `Transaction ${hash} has an unsupported execution outcome`, { transaction: facts });
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Keep low-level future values intact, but never project them into an admitted
|
|
239
|
+
* hash. An admission value other than `accepted` throws code
|
|
240
|
+
* `transactionAdmissionUnsupported` with outcome `unknown`.
|
|
241
|
+
*/
|
|
242
|
+
function assertTransactionAdmission(response, submission) {
|
|
243
|
+
if (response.admission !== "accepted") throw new ThruputError("transactionAdmissionUnsupported", "Transaction submission returned an unsupported admission outcome", {
|
|
244
|
+
context: { response },
|
|
245
|
+
transaction: {
|
|
246
|
+
hash: submission?.transactionHash ?? response.transactionHash,
|
|
247
|
+
outcome: "unknown",
|
|
248
|
+
reason: "admissionUnsupported",
|
|
249
|
+
...submission ? { submission } : {}
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Submit once, then reconcile only by reads. No path replaces or repeats signed
|
|
255
|
+
* bytes. Every failure has `transaction` facts with the signed bytes:
|
|
256
|
+
* `transactionNotSubmitted` before dispatch, otherwise
|
|
257
|
+
* `transactionOutcomeUnknown`. `wasDispatched` reports whether these bytes have
|
|
258
|
+
* been sent, by this call or an earlier one; when it is `true`, no failure is
|
|
259
|
+
* `notSubmitted`.
|
|
260
|
+
*/
|
|
261
|
+
async function submitAndObserve(client, evidence, submit, options, wasDispatched) {
|
|
262
|
+
const submission = createSubmissionEvidence(evidence.signedTransaction, evidence.networkHash);
|
|
263
|
+
validateExecutionWait(options);
|
|
264
|
+
const timeoutMs = options?.timeoutMs ?? 3e4;
|
|
265
|
+
const deadline = performance.now() + timeoutMs;
|
|
266
|
+
const signal = options?.signal;
|
|
267
|
+
const stopped = wasDispatched?.() ? transactionOutcomeUnknown : transactionNotSubmitted;
|
|
268
|
+
if (signal?.aborted) throw stopped(submission, "cancelled", signal.reason);
|
|
269
|
+
if (timeoutMs === 0) throw stopped(submission, "timeout", timeoutError("Transaction submission timed out before dispatch"));
|
|
270
|
+
let submissionError;
|
|
271
|
+
try {
|
|
272
|
+
await beforeDeadline(submit, deadline, signal, () => timeoutError("Transaction submission timed out"));
|
|
273
|
+
} catch (cause) {
|
|
274
|
+
const dispatched = wasDispatched?.();
|
|
275
|
+
if (dispatched === false || dispatched === void 0 && isLocalRequestError(cause, signal)) throw transactionNotSubmitted(submission, reasonBeforeDispatch(cause, signal), cause);
|
|
276
|
+
if (!isCancellation(cause, signal) && isNodeRejection(cause)) throw transactionOutcomeUnknown(submission, "nodeRejected", cause);
|
|
277
|
+
if (signal?.aborted || performance.now() >= deadline) throw transactionOutcomeUnknown(submission, reasonAfterDispatch(cause, signal), cause);
|
|
278
|
+
submissionError = cause;
|
|
279
|
+
}
|
|
280
|
+
try {
|
|
281
|
+
const receipt = await client.waitForTransactionReceipt(submission.transactionHash, {
|
|
282
|
+
...options,
|
|
283
|
+
expectedNetworkHash: submission.networkHash,
|
|
284
|
+
timeoutMs: Math.max(0, deadline - performance.now())
|
|
285
|
+
});
|
|
286
|
+
return {
|
|
287
|
+
transactionHash: receipt.transactionHash,
|
|
288
|
+
receipt,
|
|
289
|
+
submission
|
|
290
|
+
};
|
|
291
|
+
} catch (cause) {
|
|
292
|
+
throw withSubmission(cause, submission, submissionError);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
/** Wait for a committed receipt, then require execution success. */
|
|
296
|
+
async function waitForExecution(client, hash, options) {
|
|
297
|
+
const receipt = await client.waitForTransactionReceipt(hash, options);
|
|
298
|
+
assertTransactionSuccess(receipt);
|
|
299
|
+
return {
|
|
300
|
+
transactionHash: receipt.transactionHash,
|
|
301
|
+
receipt
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Decode DefaultWallet child returns without modifying the root receipt.
|
|
306
|
+
* Works after disconnect and preserves call order. Supply an adapter for other
|
|
307
|
+
* wallets. Wallets such as DevWallet that discard child return data report
|
|
308
|
+
* unavailable results. Failed wallet receipts are not decoded with a child ABI:
|
|
309
|
+
* even a single child call does not establish where an abort originated.
|
|
310
|
+
*/
|
|
311
|
+
function decodeExecution(receipt, calls, adapter = defaultWalletAdapter, submission) {
|
|
312
|
+
assertTransactionSuccess(receipt, submission);
|
|
313
|
+
let results;
|
|
314
|
+
try {
|
|
315
|
+
const buffers = adapter.decodeExecutionReturns?.(receipt);
|
|
316
|
+
if (buffers != null) {
|
|
317
|
+
if (buffers.length !== calls.length) throw contractDecodeFailed(`Returned ${buffers.length} child results; expected ${calls.length}`);
|
|
318
|
+
results = calls.map((call, index) => call.method.decodeReturn(buffers[index]));
|
|
319
|
+
}
|
|
320
|
+
} catch (cause) {
|
|
321
|
+
throw transactionResultUndecodable(receipt, cause, submission);
|
|
322
|
+
}
|
|
323
|
+
if (results === void 0) throw resultUnavailable(receipt, submission);
|
|
324
|
+
return results;
|
|
325
|
+
}
|
|
326
|
+
/** Execution succeeded, but this wallet does not preserve child return buffers. */
|
|
327
|
+
function resultUnavailable(receipt, submission) {
|
|
328
|
+
return new ThruputError("transactionResultUnavailable", `Transaction ${toBase58(receipt.transactionHash)} committed successfully, but its wallet does not expose child return data`, { transaction: receiptFacts(receipt, "resultUnavailable", submission) });
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Sum explicit child budgets and a calibrated wallet overhead, checking u64 bounds.
|
|
332
|
+
* This is not gas estimation. Calibrate budgets against the target runtime and
|
|
333
|
+
* workload; there is no universally safe wallet overhead. Root gas reserves
|
|
334
|
+
* scheduling capacity against the sender's free native-token balance. Storage
|
|
335
|
+
* deposits are a separate requirement, and funding a target contract does not
|
|
336
|
+
* sponsor root gas.
|
|
337
|
+
*/
|
|
338
|
+
function walletGasLimit(calls, overhead) {
|
|
339
|
+
const limits = [overhead, ...calls.map((call) => call.gas_limit)];
|
|
340
|
+
if (limits.some((limit) => typeof limit !== "bigint" || limit < 0n)) throw new RangeError("Gas budgets must be nonnegative bigint values");
|
|
341
|
+
const total = limits.reduce((sum, limit) => sum + limit, 0n);
|
|
342
|
+
if (total > 18446744073709551615n) throw new RangeError("Root gas budget exceeds u64");
|
|
343
|
+
return gasAmount(total);
|
|
344
|
+
}
|
|
345
|
+
//#endregion
|
|
346
|
+
//#region src/actions/wallet/prepareTransaction.ts
|
|
347
|
+
const int64Max = 9223372036854775807n;
|
|
348
|
+
const uint64Max = 18446744073709551615n;
|
|
349
|
+
const defaultExpiryBlocks = 100n;
|
|
350
|
+
/** Prepare an unsigned transaction for a wallet account. */
|
|
351
|
+
async function prepareTransaction(client, account, request) {
|
|
352
|
+
const invocation = deserialize(serialize(request.invocation, codec.Invocation), codec.Invocation);
|
|
353
|
+
const contractsToDeploy = (request.contractsToDeploy ?? []).map((contract) => deserialize(serialize(contract, codec.Contract), codec.Contract));
|
|
354
|
+
const authClaim = deserialize(serialize(account.authClaim, codec.AuthClaim), codec.AuthClaim);
|
|
355
|
+
if (!bytesEqual(invocation.invoked_address, account.address)) throw new Error("Root invocation address must match the wallet account");
|
|
356
|
+
if (request.blockExpiryHeight !== void 0 && request.expiryBlocks !== void 0) throw new Error("blockExpiryHeight and expiryBlocks are mutually exclusive");
|
|
357
|
+
const nonce = request.nonce ?? randomUint64();
|
|
358
|
+
validateRange(nonce, 0n, uint64Max, "nonce");
|
|
359
|
+
let expiry;
|
|
360
|
+
if (request.blockExpiryHeight !== void 0) {
|
|
361
|
+
expiry = request.blockExpiryHeight;
|
|
362
|
+
validateRange(expiry, 0n, int64Max, "blockExpiryHeight");
|
|
363
|
+
} else {
|
|
364
|
+
const expiryBlocks = request.expiryBlocks ?? defaultExpiryBlocks;
|
|
365
|
+
validateRange(expiryBlocks, 1n, int64Max, "expiryBlocks");
|
|
366
|
+
expiry = (await client.getChainTip()).blockHeight + expiryBlocks;
|
|
367
|
+
validateRange(expiry, 0n, int64Max, "blockExpiryHeight");
|
|
368
|
+
}
|
|
369
|
+
return createTransaction({
|
|
370
|
+
invocation,
|
|
371
|
+
uniquifier: {
|
|
372
|
+
block_expiry_height: blockHeight(expiry),
|
|
373
|
+
nonce
|
|
374
|
+
},
|
|
375
|
+
contracts_to_deploy: contractsToDeploy,
|
|
376
|
+
auth_claim: authClaim
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
function randomUint64() {
|
|
380
|
+
const bytes = crypto.getRandomValues(new Uint8Array(8));
|
|
381
|
+
return new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength).getBigUint64(0);
|
|
382
|
+
}
|
|
383
|
+
function validateRange(value, min, max, name) {
|
|
384
|
+
if (typeof value !== "bigint" || value < min || value > max) throw new RangeError(`${name} must be between ${min} and ${max}`);
|
|
385
|
+
}
|
|
386
|
+
function bytesEqual(left, right) {
|
|
387
|
+
if (left.length !== right.length) return false;
|
|
388
|
+
return left.every((byte, index) => byte === right[index]);
|
|
389
|
+
}
|
|
390
|
+
//#endregion
|
|
391
|
+
//#region src/actions/wallet/sendInvocation.ts
|
|
392
|
+
/** Sign a transaction with a wallet account's configured signers. */
|
|
393
|
+
function signWalletTransaction(account, transaction, networkHash) {
|
|
394
|
+
return signTransaction(transaction, account.signers, networkHash);
|
|
395
|
+
}
|
|
396
|
+
/** Prepare, sign, and submit one explicit root invocation. */
|
|
397
|
+
async function sendInvocation(client, account, networkHash, request, controls = {}) {
|
|
398
|
+
controls.signal?.throwIfAborted();
|
|
399
|
+
client.requireMethods(["getChainTip", "sendTransaction"]);
|
|
400
|
+
const signingNetwork = new Uint8Array(networkHash);
|
|
401
|
+
const checkNetwork = () => {
|
|
402
|
+
const discovered = client.discovery.network.networkHash;
|
|
403
|
+
if (signingNetwork.length !== 32 || discovered.length !== 32 || signingNetwork.some((value, index) => value !== discovered[index])) throw rpcIncompatible("network", "Signing network does not match endpoint discovery");
|
|
404
|
+
};
|
|
405
|
+
checkNetwork();
|
|
406
|
+
const signers = account.signers.map(({ signer, publicKeyId }) => ({
|
|
407
|
+
signer,
|
|
408
|
+
publicKeyId
|
|
409
|
+
}));
|
|
410
|
+
const transaction = await prepareTransaction(client, account, request);
|
|
411
|
+
controls.signal?.throwIfAborted();
|
|
412
|
+
checkNetwork();
|
|
413
|
+
const evidence = createSubmissionEvidence(serialize(await signTransaction(transaction, signers, signingNetwork), codec.SignedTransaction), signingNetwork);
|
|
414
|
+
if (controls.signal?.aborted) throw transactionNotSubmitted(evidence, "cancelled", controls.signal.reason);
|
|
415
|
+
try {
|
|
416
|
+
await controls.onSigned?.(evidence);
|
|
417
|
+
} catch (cause) {
|
|
418
|
+
throw transactionNotSubmitted(evidence, "persistenceFailed", cause);
|
|
419
|
+
}
|
|
420
|
+
try {
|
|
421
|
+
controls.signal?.throwIfAborted();
|
|
422
|
+
checkNetwork();
|
|
423
|
+
} catch (cause) {
|
|
424
|
+
throw transactionNotSubmitted(evidence, reasonBeforeDispatch(cause, controls.signal), cause);
|
|
425
|
+
}
|
|
426
|
+
let result;
|
|
427
|
+
try {
|
|
428
|
+
result = await client.sendTransaction({ signedTransaction: evidence.signedTransaction }, { signal: controls.signal });
|
|
429
|
+
} catch (cause) {
|
|
430
|
+
if (isLocalRequestError(cause, controls.signal)) throw transactionNotSubmitted(evidence, "requestInvalid", cause);
|
|
431
|
+
throw transactionOutcomeUnknown(evidence, reasonAfterDispatch(cause, controls.signal), cause);
|
|
432
|
+
}
|
|
433
|
+
assertTransactionAdmission(result, evidence);
|
|
434
|
+
return sha256Hash(result.transactionHash);
|
|
435
|
+
}
|
|
436
|
+
//#endregion
|
|
437
|
+
export { validateTimer as C, beforeDeadline as S, validateExecutionWait as _, assertTransactionSuccess as a, defineWalletInvocationAdapter as b, waitForExecution as c, isLocalRequestError as d, reasonAfterDispatch as f, createSubmissionEvidence as g, transactionOutcomeUnknown as h, assertTransactionAdmission as i, walletGasLimit as l, transactionNotSubmitted as m, signWalletTransaction as n, decodeExecution as o, reasonBeforeDispatch as p, prepareTransaction as r, submitAndObserve as s, sendInvocation as t, isCancellation as u, createDefaultWalletBatchInvocation as v, waitDelay as w, devWalletAdapter as x, defaultWalletAdapter as y };
|
|
438
|
+
|
|
439
|
+
//# sourceMappingURL=sendInvocation-DBaNWhr3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sendInvocation-DBaNWhr3.js","names":["bytesEqual","sign"],"sources":["../src/actions/deadline.ts","../src/wallet/invocationAdapter.ts","../src/wallet/executionWait.ts","../src/transaction/submissionEvidence.ts","../src/wallet/transactionErrors.ts","../src/wallet/execution.ts","../src/actions/wallet/prepareTransaction.ts","../src/actions/wallet/sendInvocation.ts"],"sourcesContent":["/** Run one operation within the caller's wall-clock budget and cancellation signal. */\nexport async function beforeDeadline<T>(\n operation: (signal: AbortSignal) => Promise<T>,\n deadline: number,\n caller: AbortSignal | undefined,\n timeout: () => Error,\n): Promise<T> {\n caller?.throwIfAborted();\n if (performance.now() >= deadline) throw timeout();\n const controller = new AbortController();\n const signal = caller\n ? AbortSignal.any([caller, controller.signal])\n : controller.signal;\n let timer: ReturnType<typeof setTimeout> | undefined;\n let onAbort = () => {};\n try {\n return await Promise.race([\n new Promise<T>((_, reject) => {\n onAbort = () => reject(signal.reason);\n signal.addEventListener(\"abort\", onAbort, { once: true });\n timer = setTimeout(\n () => controller.abort(timeout()),\n Math.ceil(Math.max(0, deadline - performance.now())),\n );\n }),\n operation(signal),\n ]);\n } finally {\n if (timer !== undefined) clearTimeout(timer);\n signal.removeEventListener(\"abort\", onAbort);\n controller.abort();\n }\n}\nexport function validateTimer(value: number, field: string): void {\n if (!Number.isFinite(value) || value < 0 || value > 2147483647)\n throw new RangeError(`${field} must be between 0 and 2147483647`);\n}\nexport function waitDelay(delay: number, signal: AbortSignal): Promise<void> {\n return new Promise((resolve, reject) => {\n signal.throwIfAborted();\n const finish = () => {\n signal.removeEventListener(\"abort\", abort);\n resolve();\n };\n const timer = setTimeout(finish, delay);\n const abort = () => {\n clearTimeout(timer);\n signal.removeEventListener(\"abort\", abort);\n reject(signal.reason);\n };\n signal.addEventListener(\"abort\", abort, { once: true });\n });\n}\n","import {\n codec,\n contractAddress,\n serialize,\n type ContractAddress,\n type GasAmount,\n type Invocation,\n} from \"@thruputchain/protocol\";\nimport { fixedBytes } from \"@thruputchain/xdr\";\nimport { bytesEqual } from \"../contract/event.js\";\nimport { DefaultWallet } from \"../contracts/default_wallet.js\";\nimport { DevWallet } from \"../contracts/dev_wallet.js\";\nimport { MAX_DEFAULT_WALLET_CALLS } from \"../provider/validation.js\";\nimport type { ContractDeployment, DeploymentOptions } from \"./deployment.js\";\nimport type { TransactionReceipt } from \"../types/rpc.js\";\n\n/** Common inputs for wrapping one inner invocation through a wallet contract. */\nexport interface WalletExecutionRequest {\n readonly invocation: Invocation;\n /** Gas available to the wallet's root invocation. */\n readonly gasLimit: GasAmount;\n}\n\n/** Ordered inner calls for one atomic DefaultWallet execution. */\nexport interface WalletBatchExecutionRequest {\n readonly invocations: readonly Invocation[];\n /** Gas available to the complete wallet root, including all calls. */\n readonly gasLimit: GasAmount;\n}\n\n/** Build a root batch directly, copying call bytes before asynchronous work. */\nexport function createDefaultWalletBatchInvocation(\n accountAddress: ContractAddress,\n request: WalletBatchExecutionRequest,\n): Invocation {\n if (\n !Array.isArray(request.invocations) ||\n request.invocations.length < 1 ||\n request.invocations.length > MAX_DEFAULT_WALLET_CALLS\n )\n throw new RangeError(\"DefaultWallet requires 1 to 16 calls\");\n return DefaultWallet.v0_1.execute.invocation(\n contractAddress(new Uint8Array(accountAddress)),\n request.gasLimit,\n {\n // This builder mints no auth tokens and forwards none.\n mints: [],\n calls: request.invocations.map((inner) => ({\n target: contractAddress(new Uint8Array(inner.invoked_address)),\n entrypoint: fixedBytes(new Uint8Array(inner.entrypoint), 8),\n gas_limit: inner.gas_limit,\n calldata: new Uint8Array(inner.calldata),\n tokens: [],\n })),\n },\n );\n}\n\n/** Converts a wallet-specific execution request into a root invocation. */\nexport interface WalletInvocationAdapter<\n TRequest extends WalletExecutionRequest = WalletExecutionRequest,\n> {\n /** Build a root deployment when supported by this wallet. */\n createDeploymentInvocation?(\n account: ContractAddress,\n deployment: ContractDeployment,\n options: DeploymentOptions,\n ): Invocation;\n /** Decode the address returned by a root deployment. */\n decodeDeploymentReceipt?(receipt: TransactionReceipt): ContractAddress;\n /** Child return buffers in call order, or null when this wallet discards them. */\n decodeExecutionReturns?(\n receipt: TransactionReceipt,\n ): readonly Uint8Array[] | null;\n /** Build one atomic root for multiple calls when this wallet supports it. */\n createBatchRootInvocation?(\n account: ContractAddress,\n request: WalletBatchExecutionRequest,\n ): Invocation;\n createRootInvocation(\n accountAddress: ContractAddress,\n request: TRequest,\n ): Invocation;\n}\n\n/** Define an invocation adapter while preserving its request type. */\nexport function defineWalletInvocationAdapter<\n TRequest extends WalletExecutionRequest,\n>(\n adapter: WalletInvocationAdapter<TRequest>,\n): WalletInvocationAdapter<TRequest> {\n return adapter;\n}\n\n/** Wrap one call through the native-compatible DefaultWallet interface. */\nexport const defaultWalletAdapter = defineWalletInvocationAdapter({\n createBatchRootInvocation: createDefaultWalletBatchInvocation,\n decodeExecutionReturns: (receipt) =>\n DefaultWallet.v0_1.execute.decodeReceipt(receipt).value,\n createDeploymentInvocation(account, deployment, options) {\n if (\n options.initializer &&\n !bytesEqual(options.initializer.invoked_address, deployment.address)\n )\n throw new Error(\n \"Initializer must target the predicted deployment address\",\n );\n // The wallet takes an i128, but a deployment never funds a negative amount.\n if (options.amount < 0n)\n throw new RangeError(\"Deployment amount must not be negative\");\n return DefaultWallet.v0_1.deploy.invocation(account, options.gasLimit, {\n nonce: fixedBytes(deployment.deploymentNonce, 32),\n contractHash: fixedBytes(deployment.contractHash, 32),\n amount: options.amount,\n initializer: options.initializer\n ? {\n entrypoint: fixedBytes(options.initializer.entrypoint, 8),\n gas_limit: options.initializer.gas_limit,\n calldata: options.initializer.calldata,\n }\n : null,\n });\n },\n decodeDeploymentReceipt: (receipt) =>\n DefaultWallet.v0_1.deploy.decodeReceipt(receipt).value,\n createRootInvocation(\n accountAddress: ContractAddress,\n request: WalletExecutionRequest,\n ): Invocation {\n return createDefaultWalletBatchInvocation(accountAddress, {\n invocations: [request.invocation],\n gasLimit: request.gasLimit,\n });\n },\n});\n\n/** Wrap one call through the legacy DevWallet. Unified deployment is unsupported. */\nexport const devWalletAdapter = defineWalletInvocationAdapter({\n decodeExecutionReturns: () => null,\n createRootInvocation(\n accountAddress: ContractAddress,\n request: WalletExecutionRequest,\n ): Invocation {\n return DevWallet.v0_1.doAction.invocation(\n contractAddress(new Uint8Array(accountAddress)),\n request.gasLimit,\n {\n invocationBytes: serialize(request.invocation, codec.Invocation),\n },\n );\n },\n});\n","import { validateTimer } from \"../actions/deadline.js\";\nimport type { WaitForTransactionReceiptOptions } from \"../actions/public/waitForTransactionReceipt.js\";\n\n/**\n * Check execution wait options before preparing or signing, so an invalid\n * option never leaves a signed or sent transaction. `knownCommitment` applies\n * only to observing an existing hash, so execution rejects it.\n * @internal\n */\nexport function validateExecutionWait(\n wait: WaitForTransactionReceiptOptions | undefined,\n): void {\n validateTimer(wait?.timeoutMs ?? 30000, \"timeoutMs\");\n validateTimer(wait?.pollingIntervalMs ?? 250, \"pollingIntervalMs\");\n if (wait?.knownCommitment !== undefined)\n throw new TypeError(\n \"knownCommitment applies only when observing an existing transaction\",\n );\n}\n","import { codec, deserialize } from \"@thruputchain/protocol\";\nimport { hashSignedTransaction } from \"../derivation/transactionHash.js\";\n\n/** Exact signed bytes, their transaction hash, and the signing network. */\nexport interface SubmissionEvidence {\n readonly signedTransaction: Uint8Array;\n readonly transactionHash: Uint8Array;\n readonly networkHash: Uint8Array;\n}\n/** Snapshot approved bytes before submission; accessor copies protect the retained record. */\nexport function createSubmissionEvidence(\n bytes: Uint8Array,\n network: Uint8Array,\n): SubmissionEvidence {\n const signedTransaction = new Uint8Array(bytes);\n const networkHash = new Uint8Array(network);\n if (networkHash.length !== 32)\n throw new RangeError(\"networkHash must contain 32 bytes\");\n const transactionHash = hashSignedTransaction(\n deserialize(signedTransaction, codec.SignedTransaction),\n );\n return Object.freeze({\n get signedTransaction() {\n return signedTransaction.slice();\n },\n get transactionHash() {\n return transactionHash.slice();\n },\n get networkHash() {\n return networkHash.slice();\n },\n });\n}\n","import { toBase58 } from \"../encoding.js\";\nimport { isThruputError, ThruputError } from \"../errors/thruputError.js\";\nimport type { TransactionOutcomeUnknownContext } from \"../errors/codes.js\";\nimport type { TransactionReason } from \"../errors/transaction.js\";\nimport { classifyReadError } from \"../transport/readError.js\";\nimport { isLocalError } from \"../rpc/localError.js\";\nimport type { SubmissionEvidence } from \"../transaction/submissionEvidence.js\";\n\n// Internal constructors for transaction errors. Public APIs re-export none of these.\n\n/** The client did not dispatch the signed transaction. */\nexport function transactionNotSubmitted(\n submission: SubmissionEvidence,\n reason: TransactionReason,\n cause: unknown,\n): ThruputError<\"transactionNotSubmitted\"> {\n return new ThruputError(\n \"transactionNotSubmitted\",\n `Transaction ${toBase58(submission.transactionHash)} was not submitted`,\n {\n cause,\n transaction: {\n hash: submission.transactionHash,\n outcome: \"notSubmitted\",\n reason,\n submission,\n },\n },\n );\n}\n\n/** Submission stopped, and the outcome is unknown. Never resend. */\nexport function transactionOutcomeUnknown(\n submission: SubmissionEvidence,\n reason: TransactionReason,\n cause: unknown,\n context: TransactionOutcomeUnknownContext = {},\n): ThruputError<\"transactionOutcomeUnknown\"> {\n return new ThruputError(\n \"transactionOutcomeUnknown\",\n `Could not complete transaction ${toBase58(submission.transactionHash)}`,\n {\n context,\n cause,\n transaction: {\n hash: submission.transactionHash,\n outcome: \"unknown\",\n reason,\n submission,\n },\n },\n );\n}\n\n/** Add the signed bytes, and an earlier submission failure, to an observation error. */\nexport function withSubmission(\n error: unknown,\n submission: SubmissionEvidence,\n submissionError?: unknown,\n): ThruputError<\"transactionOutcomeUnknown\"> {\n const extra = submissionError === undefined ? {} : { submissionError };\n if (!isThruputError(error, \"transactionOutcomeUnknown\") || !error.transaction)\n return transactionOutcomeUnknown(\n submission,\n \"observationFailed\",\n error,\n extra,\n );\n return new ThruputError(\"transactionOutcomeUnknown\", error.message, {\n context: { ...error.context, ...extra },\n ...(error.cause === undefined ? {} : { cause: error.cause }),\n transaction: { ...error.transaction, submission },\n });\n}\n\n/**\n * True when the error is the caller's abort reason. An abort reason can be any\n * value, so never read its code as evidence about this transaction.\n */\nexport function isCancellation(\n cause: unknown,\n signal: AbortSignal | undefined,\n): boolean {\n return signal?.aborted === true && cause === signal.reason;\n}\n\n/**\n * True when a local check of this client rejected the request before dispatch.\n * The code alone is not proof: a transport can throw the same code after it\n * sent the request.\n */\nexport function isLocalRequestError(\n cause: unknown,\n signal: AbortSignal | undefined,\n): boolean {\n return (\n !isCancellation(cause, signal) &&\n isLocalError(cause) &&\n (isThruputError(cause, \"rpcRequestInvalid\") ||\n isThruputError(cause, \"rpcIncompatible\"))\n );\n}\n\n/** A failure before dispatch, after signing and `onSigned`. */\nexport function reasonBeforeDispatch(\n cause: unknown,\n signal: AbortSignal | undefined,\n): TransactionReason {\n if (signal?.aborted) return \"cancelled\";\n if (isLocalRequestError(cause, signal)) return \"requestInvalid\";\n if (isTimeout(cause)) return \"timeout\";\n return \"notDispatched\";\n}\n\n/** True when the node answered that it did not admit the transaction. */\nexport function isNodeRejection(cause: unknown): boolean {\n return (\n isThruputError(cause, \"nativeRpcError\") &&\n (cause.context.kind === \"invalidParams\" ||\n cause.context.kind === \"transactionInvalid\" ||\n cause.context.kind === \"transactionRejected\")\n );\n}\n\n/** A failure after dispatch. None of these proves that the node did not receive it. */\nexport function reasonAfterDispatch(\n cause: unknown,\n signal: AbortSignal | undefined,\n): TransactionReason {\n if (signal?.aborted) return \"cancelled\";\n if (isNodeRejection(cause)) return \"nodeRejected\";\n if (isTimeout(cause)) return \"timeout\";\n if (classifyReadError(cause) === \"transient\") return \"disconnected\";\n return \"submissionFailed\";\n}\n\n/** A deadline error. Uses the web-standard `TimeoutError` name. */\nexport function timeoutError(message: string): DOMException {\n return new DOMException(message, \"TimeoutError\");\n}\n\nfunction isTimeout(cause: unknown): boolean {\n return (\n cause !== null &&\n typeof cause === \"object\" &&\n \"name\" in cause &&\n cause.name === \"TimeoutError\"\n );\n}\n","import { isUnsupportedRpcValue } from \"../rpc/unsupported.js\";\nimport { ThruputError } from \"../errors/thruputError.js\";\nimport {\n receiptFacts,\n transactionResultUndecodable,\n} from \"../errors/transaction.js\";\nimport { contractDecodeFailed } from \"../contract/errors.js\";\nimport { gasAmount, type GasAmount } from \"@thruputchain/protocol\";\nimport type { CoreThruputClient } from \"../client.js\";\nimport type { TransactionReceipt } from \"../types/rpc.js\";\nimport type { WaitForTransactionReceiptOptions } from \"../actions/public/waitForTransactionReceipt.js\";\nimport type { ContractCall } from \"../contract/method.js\";\nimport {\n defaultWalletAdapter,\n type WalletInvocationAdapter,\n} from \"./invocationAdapter.js\";\nimport { beforeDeadline } from \"../actions/deadline.js\";\nimport { validateExecutionWait } from \"./executionWait.js\";\nimport { toBase58 } from \"../encoding.js\";\nimport type { RpcSendTransactionResult } from \"../rpc/generated.js\";\nimport {\n createSubmissionEvidence,\n type SubmissionEvidence,\n} from \"../transaction/submissionEvidence.js\";\nimport {\n isCancellation,\n isLocalRequestError,\n isNodeRejection,\n reasonAfterDispatch,\n reasonBeforeDispatch,\n timeoutError,\n transactionNotSubmitted,\n transactionOutcomeUnknown,\n withSubmission,\n} from \"./transactionErrors.js\";\n\n/**\n * Require successful execution. A failed execution throws code\n * `transactionFailed`; an unsupported execution value throws code\n * `transactionOutcomeUnsupported`, never inferred to be success or failure.\n * Both keep the complete receipt in `transaction.receipt`.\n */\nexport function assertTransactionSuccess(\n receipt: TransactionReceipt,\n submission?: SubmissionEvidence,\n): asserts receipt is TransactionReceipt & {\n execution: { result: \"return\"; returnData: Uint8Array };\n} {\n const hash = toBase58(receipt.transactionHash);\n const facts = receiptFacts(receipt, \"outcomeUnsupported\", submission);\n if (facts.outcome === \"succeeded\") return;\n const { execution } = receipt;\n if (facts.outcome === \"failed\" && !isUnsupportedRpcValue(execution))\n throw new ThruputError(\n \"transactionFailed\",\n `Transaction ${hash} execution failed (${execution.result})`,\n { transaction: facts },\n );\n throw new ThruputError(\n \"transactionOutcomeUnsupported\",\n `Transaction ${hash} has an unsupported execution outcome`,\n { transaction: facts },\n );\n}\n\n/**\n * Keep low-level future values intact, but never project them into an admitted\n * hash. An admission value other than `accepted` throws code\n * `transactionAdmissionUnsupported` with outcome `unknown`.\n */\nexport function assertTransactionAdmission(\n response: RpcSendTransactionResult,\n submission?: SubmissionEvidence,\n): void {\n if (response.admission !== \"accepted\")\n throw new ThruputError(\n \"transactionAdmissionUnsupported\",\n \"Transaction submission returned an unsupported admission outcome\",\n {\n context: { response },\n transaction: {\n hash: submission?.transactionHash ?? response.transactionHash,\n outcome: \"unknown\",\n reason: \"admissionUnsupported\",\n ...(submission ? { submission } : {}),\n },\n },\n );\n}\nexport {\n createSubmissionEvidence,\n type SubmissionEvidence,\n} from \"../transaction/submissionEvidence.js\";\nexport interface ExecutionResult {\n transactionHash: Uint8Array;\n receipt: TransactionReceipt;\n submission?: SubmissionEvidence;\n}\n/**\n * Submit once, then reconcile only by reads. No path replaces or repeats signed\n * bytes. Every failure has `transaction` facts with the signed bytes:\n * `transactionNotSubmitted` before dispatch, otherwise\n * `transactionOutcomeUnknown`. `wasDispatched` reports whether these bytes have\n * been sent, by this call or an earlier one; when it is `true`, no failure is\n * `notSubmitted`.\n */\nexport async function submitAndObserve(\n client: Pick<CoreThruputClient, \"waitForTransactionReceipt\">,\n evidence: SubmissionEvidence,\n submit: (signal: AbortSignal) => Promise<void>,\n options?: WaitForTransactionReceiptOptions,\n wasDispatched?: () => boolean,\n): Promise<ExecutionResult> {\n const submission = createSubmissionEvidence(\n evidence.signedTransaction,\n evidence.networkHash,\n );\n // An invalid option must fail before the transaction can be sent.\n validateExecutionWait(options);\n const timeoutMs = options?.timeoutMs ?? 30000;\n const deadline = performance.now() + timeoutMs;\n const signal = options?.signal;\n // The caller may know that identical bytes were sent before this call.\n const stopped = wasDispatched?.()\n ? transactionOutcomeUnknown\n : transactionNotSubmitted;\n if (signal?.aborted) throw stopped(submission, \"cancelled\", signal.reason);\n if (timeoutMs === 0)\n throw stopped(\n submission,\n \"timeout\",\n timeoutError(\"Transaction submission timed out before dispatch\"),\n );\n let submissionError: unknown;\n try {\n await beforeDeadline(submit, deadline, signal, () =>\n timeoutError(\"Transaction submission timed out\"),\n );\n } catch (cause) {\n // When the caller tracks dispatch, only its answer can prove the\n // transaction was not sent; an error code alone cannot.\n const dispatched = wasDispatched?.();\n if (\n dispatched === false ||\n (dispatched === undefined && isLocalRequestError(cause, signal))\n )\n throw transactionNotSubmitted(\n submission,\n reasonBeforeDispatch(cause, signal),\n cause,\n );\n if (!isCancellation(cause, signal) && isNodeRejection(cause))\n throw transactionOutcomeUnknown(submission, \"nodeRejected\", cause);\n if (signal?.aborted || performance.now() >= deadline)\n throw transactionOutcomeUnknown(\n submission,\n reasonAfterDispatch(cause, signal),\n cause,\n );\n // The node may have the transaction. Observe it; never submit again.\n submissionError = cause;\n }\n try {\n const receipt = await client.waitForTransactionReceipt(\n submission.transactionHash,\n {\n ...options,\n expectedNetworkHash: submission.networkHash,\n timeoutMs: Math.max(0, deadline - performance.now()),\n },\n );\n return { transactionHash: receipt.transactionHash, receipt, submission };\n } catch (cause) {\n throw withSubmission(cause, submission, submissionError);\n }\n}\n/** Wait for a committed receipt, then require execution success. */\nexport async function waitForExecution(\n client: Pick<CoreThruputClient, \"waitForTransactionReceipt\">,\n hash: Uint8Array,\n options?: WaitForTransactionReceiptOptions,\n): Promise<ExecutionResult> {\n const receipt = await client.waitForTransactionReceipt(hash, options);\n assertTransactionSuccess(receipt);\n return { transactionHash: receipt.transactionHash, receipt };\n}\n\n/** Ordered result types for a tuple of calls. */\nexport type CallResults<T extends readonly ContractCall[]> = {\n [K in keyof T]: T[K] extends ContractCall<infer R> ? R : never;\n};\n\n/**\n * Decode DefaultWallet child returns without modifying the root receipt.\n * Works after disconnect and preserves call order. Supply an adapter for other\n * wallets. Wallets such as DevWallet that discard child return data report\n * unavailable results. Failed wallet receipts are not decoded with a child ABI:\n * even a single child call does not establish where an abort originated.\n */\nexport function decodeExecution<T extends readonly ContractCall[]>(\n receipt: TransactionReceipt,\n calls: T,\n adapter: WalletInvocationAdapter = defaultWalletAdapter,\n submission?: SubmissionEvidence,\n): CallResults<T> {\n // Even one child call can fail in the wallet root; its abort bytes are not a child receipt.\n assertTransactionSuccess(receipt, submission);\n let results: CallResults<T> | undefined;\n try {\n const buffers = adapter.decodeExecutionReturns?.(receipt);\n if (buffers != null) {\n if (buffers.length !== calls.length)\n throw contractDecodeFailed(\n `Returned ${buffers.length} child results; expected ${calls.length}`,\n );\n results = calls.map((call, index) =>\n call.method.decodeReturn(buffers[index]!),\n ) as CallResults<T>;\n }\n } catch (cause) {\n // Wrap everything, even a ThruputError from the adapter, so the facts\n // always describe this receipt.\n throw transactionResultUndecodable(receipt, cause, submission);\n }\n if (results === undefined) throw resultUnavailable(receipt, submission);\n return results;\n}\n\n/** Execution succeeded, but this wallet does not preserve child return buffers. */\nfunction resultUnavailable(\n receipt: TransactionReceipt,\n submission?: SubmissionEvidence,\n): ThruputError<\"transactionResultUnavailable\"> {\n return new ThruputError(\n \"transactionResultUnavailable\",\n `Transaction ${toBase58(receipt.transactionHash)} committed successfully, but its wallet does not expose child return data`,\n { transaction: receiptFacts(receipt, \"resultUnavailable\", submission) },\n );\n}\n\n/**\n * Sum explicit child budgets and a calibrated wallet overhead, checking u64 bounds.\n * This is not gas estimation. Calibrate budgets against the target runtime and\n * workload; there is no universally safe wallet overhead. Root gas reserves\n * scheduling capacity against the sender's free native-token balance. Storage\n * deposits are a separate requirement, and funding a target contract does not\n * sponsor root gas.\n */\nexport function walletGasLimit(\n calls: readonly { gas_limit: GasAmount }[],\n overhead: GasAmount,\n): GasAmount {\n const limits = [overhead, ...calls.map((call) => call.gas_limit)];\n if (limits.some((limit) => typeof limit !== \"bigint\" || limit < 0n))\n throw new RangeError(\"Gas budgets must be nonnegative bigint values\");\n const total = limits.reduce((sum, limit) => sum + limit, 0n);\n if (total > 0xffff_ffff_ffff_ffffn)\n throw new RangeError(\"Root gas budget exceeds u64\");\n return gasAmount(total);\n}\n","import {\n blockHeight,\n codec,\n deserialize,\n serialize,\n type BlockHeight,\n type Contract,\n type Invocation,\n type Transaction,\n} from \"@thruputchain/protocol\";\nimport type { CoreThruputClient } from \"../../client.js\";\nimport type { WalletAccount } from \"../../wallet/account.js\";\nimport { createTransaction } from \"../../transaction/build.js\";\n\nconst int64Max = 0x7fff_ffff_ffff_ffffn;\nconst uint64Max = 0xffff_ffff_ffff_ffffn;\nconst defaultExpiryBlocks = 100n;\n\n/** Inputs for preparing one wallet-authorized transaction. */\nexport interface PrepareTransactionRequest {\n /** Explicit root invocation. Smart-wallet wrapping is caller-controlled. */\n readonly invocation: Invocation;\n readonly contractsToDeploy?: readonly Contract[];\n readonly nonce?: bigint;\n readonly blockExpiryHeight?: BlockHeight;\n readonly expiryBlocks?: bigint;\n}\n\n/** Prepare an unsigned transaction for a wallet account. */\nexport async function prepareTransaction(\n client: Pick<CoreThruputClient, \"getChainTip\">,\n account: Pick<WalletAccount, \"address\" | \"authClaim\">,\n request: PrepareTransactionRequest,\n): Promise<Transaction> {\n const invocation = deserialize(\n serialize(request.invocation, codec.Invocation),\n codec.Invocation,\n );\n const contractsToDeploy = (request.contractsToDeploy ?? []).map((contract) =>\n deserialize(serialize(contract, codec.Contract), codec.Contract),\n );\n const authClaim = deserialize(\n serialize(account.authClaim, codec.AuthClaim),\n codec.AuthClaim,\n );\n\n if (!bytesEqual(invocation.invoked_address, account.address)) {\n throw new Error(\"Root invocation address must match the wallet account\");\n }\n if (\n request.blockExpiryHeight !== undefined &&\n request.expiryBlocks !== undefined\n ) {\n throw new Error(\n \"blockExpiryHeight and expiryBlocks are mutually exclusive\",\n );\n }\n\n const nonce = request.nonce ?? randomUint64();\n validateRange(nonce, 0n, uint64Max, \"nonce\");\n\n let expiry: bigint;\n if (request.blockExpiryHeight !== undefined) {\n expiry = request.blockExpiryHeight;\n validateRange(expiry, 0n, int64Max, \"blockExpiryHeight\");\n } else {\n const expiryBlocks = request.expiryBlocks ?? defaultExpiryBlocks;\n validateRange(expiryBlocks, 1n, int64Max, \"expiryBlocks\");\n const tip = await client.getChainTip();\n expiry = tip.blockHeight + expiryBlocks;\n validateRange(expiry, 0n, int64Max, \"blockExpiryHeight\");\n }\n\n return createTransaction({\n invocation,\n uniquifier: {\n block_expiry_height: blockHeight(expiry),\n nonce,\n },\n contracts_to_deploy: contractsToDeploy,\n auth_claim: authClaim,\n });\n}\n\nfunction randomUint64(): bigint {\n const bytes = crypto.getRandomValues(new Uint8Array(8));\n return new DataView(\n bytes.buffer,\n bytes.byteOffset,\n bytes.byteLength,\n ).getBigUint64(0);\n}\n\nfunction validateRange(\n value: bigint,\n min: bigint,\n max: bigint,\n name: string,\n): void {\n if (typeof value !== \"bigint\" || value < min || value > max) {\n throw new RangeError(`${name} must be between ${min} and ${max}`);\n }\n}\n\nfunction bytesEqual(left: Uint8Array, right: Uint8Array): boolean {\n if (left.length !== right.length) return false;\n return left.every((byte, index) => byte === right[index]);\n}\n","import type {\n SHA256Hash,\n SignedTransaction,\n Transaction,\n NetworkHash,\n} from \"@thruputchain/protocol\";\nimport { codec, serialize, sha256Hash } from \"@thruputchain/protocol\";\nimport {\n createSubmissionEvidence,\n assertTransactionAdmission,\n type SubmissionEvidence,\n} from \"../../wallet/execution.js\";\nimport { rpcIncompatible } from \"../../rpc/client.js\";\nimport {\n isLocalRequestError,\n reasonAfterDispatch,\n reasonBeforeDispatch,\n transactionNotSubmitted,\n transactionOutcomeUnknown,\n} from \"../../wallet/transactionErrors.js\";\nimport type { CoreThruputClient } from \"../../client.js\";\nimport type { WalletAccount } from \"../../wallet/account.js\";\nimport { signTransaction as sign } from \"../../transaction/sign.js\";\nimport {\n prepareTransaction,\n type PrepareTransactionRequest,\n} from \"./prepareTransaction.js\";\n\n/** Sign a transaction with a wallet account's configured signers. */\nexport function signWalletTransaction(\n account: WalletAccount,\n transaction: Transaction,\n networkHash: NetworkHash,\n): Promise<SignedTransaction> {\n return sign(transaction, account.signers, networkHash);\n}\n\n/** Prepare, sign, and submit one explicit root invocation. */\nexport async function sendInvocation(\n client: Pick<\n CoreThruputClient,\n \"getChainTip\" | \"sendTransaction\" | \"requireMethods\" | \"discovery\"\n >,\n account: WalletAccount,\n networkHash: NetworkHash,\n request: PrepareTransactionRequest,\n controls: {\n signal?: AbortSignal;\n onSigned?: (evidence: SubmissionEvidence) => void | Promise<void>;\n } = {},\n): Promise<SHA256Hash> {\n controls.signal?.throwIfAborted();\n client.requireMethods([\"getChainTip\", \"sendTransaction\"]);\n const signingNetwork = new Uint8Array(networkHash) as NetworkHash;\n const checkNetwork = () => {\n const discovered = client.discovery.network.networkHash;\n if (\n signingNetwork.length !== 32 ||\n discovered.length !== 32 ||\n signingNetwork.some((value, index) => value !== discovered[index])\n )\n throw rpcIncompatible(\n \"network\",\n \"Signing network does not match endpoint discovery\",\n );\n };\n checkNetwork();\n const signers = account.signers.map(({ signer, publicKeyId }) => ({\n signer,\n publicKeyId,\n }));\n const transaction = await prepareTransaction(client, account, request);\n // Do not sign a transaction the caller has cancelled.\n controls.signal?.throwIfAborted();\n checkNetwork();\n const signed = await sign(transaction, signers, signingNetwork);\n const evidence = createSubmissionEvidence(\n serialize(signed, codec.SignedTransaction),\n signingNetwork,\n );\n // Do not persist a transaction the caller cancelled while it was signed.\n if (controls.signal?.aborted)\n throw transactionNotSubmitted(\n evidence,\n \"cancelled\",\n controls.signal.reason,\n );\n try {\n await controls.onSigned?.(evidence);\n } catch (cause) {\n throw transactionNotSubmitted(evidence, \"persistenceFailed\", cause);\n }\n try {\n controls.signal?.throwIfAborted();\n checkNetwork();\n } catch (cause) {\n throw transactionNotSubmitted(\n evidence,\n reasonBeforeDispatch(cause, controls.signal),\n cause,\n );\n }\n let result;\n try {\n result = await client.sendTransaction(\n { signedTransaction: evidence.signedTransaction },\n { signal: controls.signal },\n );\n } catch (cause) {\n if (isLocalRequestError(cause, controls.signal))\n throw transactionNotSubmitted(evidence, \"requestInvalid\", cause);\n throw transactionOutcomeUnknown(\n evidence,\n reasonAfterDispatch(cause, controls.signal),\n cause,\n );\n }\n assertTransactionAdmission(result, evidence);\n return sha256Hash(result.transactionHash);\n}\n"],"mappings":";;;;;;;;;;;;AACA,eAAsB,eACpB,WACA,UACA,QACA,SACY;CACZ,QAAQ,eAAe;CACvB,IAAI,YAAY,IAAI,KAAK,UAAU,MAAM,QAAQ;CACjD,MAAM,aAAa,IAAI,gBAAgB;CACvC,MAAM,SAAS,SACX,YAAY,IAAI,CAAC,QAAQ,WAAW,MAAM,CAAC,IAC3C,WAAW;CACf,IAAI;CACJ,IAAI,gBAAgB,CAAC;CACrB,IAAI;EACF,OAAO,MAAM,QAAQ,KAAK,CACxB,IAAI,SAAY,GAAG,WAAW;GAC5B,gBAAgB,OAAO,OAAO,MAAM;GACpC,OAAO,iBAAiB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