@ar.io/sdk 3.24.0 → 4.0.0-alpha.2

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.
Files changed (169) hide show
  1. package/README.md +757 -589
  2. package/lib/esm/cli/cli.js +188 -152
  3. package/lib/esm/cli/commands/antCommands.js +23 -58
  4. package/lib/esm/cli/commands/arnsPurchaseCommands.js +48 -30
  5. package/lib/esm/cli/commands/escrowCommands.js +227 -0
  6. package/lib/esm/cli/commands/gatewayWriteCommands.js +140 -23
  7. package/lib/esm/cli/commands/pruneCommands.js +154 -0
  8. package/lib/esm/cli/commands/readCommands.js +22 -3
  9. package/lib/esm/cli/commands/transfer.js +6 -6
  10. package/lib/esm/cli/options.js +124 -58
  11. package/lib/esm/cli/utils.js +303 -175
  12. package/lib/esm/common/ant-registry.js +17 -143
  13. package/lib/esm/common/ant.js +44 -1167
  14. package/lib/esm/common/faucet.js +17 -6
  15. package/lib/esm/common/index.js +0 -4
  16. package/lib/esm/common/io.js +25 -1412
  17. package/lib/esm/constants.js +13 -19
  18. package/lib/esm/solana/ant-readable.js +724 -0
  19. package/lib/esm/solana/ant-registry-readable.js +133 -0
  20. package/lib/esm/solana/ant-registry-writeable.js +472 -0
  21. package/lib/esm/solana/ant-writeable.js +384 -0
  22. package/lib/esm/solana/ata.js +70 -0
  23. package/lib/esm/solana/canonical-message.js +128 -0
  24. package/lib/esm/solana/clusters.js +111 -0
  25. package/lib/esm/solana/constants.js +146 -0
  26. package/lib/esm/solana/delegation-math.js +112 -0
  27. package/lib/esm/solana/deserialize.js +711 -0
  28. package/lib/esm/solana/escrow.js +839 -0
  29. package/lib/{cjs/utils/json.js → esm/solana/events.js} +15 -10
  30. package/lib/esm/solana/funding-plan.js +699 -0
  31. package/lib/esm/solana/index.js +126 -0
  32. package/lib/esm/solana/instruction.js +39 -0
  33. package/lib/esm/solana/io-readable.js +2182 -0
  34. package/lib/esm/solana/io-writeable.js +3196 -0
  35. package/lib/esm/solana/json-rpc.js +90 -0
  36. package/lib/esm/solana/metadata.js +81 -0
  37. package/lib/esm/solana/mpl-core.js +192 -0
  38. package/lib/esm/solana/pda.js +332 -0
  39. package/lib/esm/solana/predict-prescribed-observers.js +110 -0
  40. package/lib/esm/solana/retry.js +117 -0
  41. package/lib/esm/solana/rpc-circuit-breaker.js +258 -0
  42. package/lib/esm/solana/send.js +372 -0
  43. package/lib/esm/solana/spawn-ant.js +224 -0
  44. package/lib/esm/solana/types.js +1 -0
  45. package/lib/esm/types/ant.js +27 -15
  46. package/lib/esm/types/io.js +8 -11
  47. package/lib/esm/utils/ant.js +0 -63
  48. package/lib/esm/utils/index.js +0 -3
  49. package/lib/esm/version.js +1 -1
  50. package/lib/types/cli/commands/antCommands.d.ts +5 -13
  51. package/lib/types/cli/commands/arnsPurchaseCommands.d.ts +33 -7
  52. package/lib/types/cli/commands/escrowCommands.d.ts +68 -0
  53. package/lib/types/cli/commands/gatewayWriteCommands.d.ts +12 -11
  54. package/lib/types/cli/commands/pruneCommands.d.ts +31 -0
  55. package/lib/types/cli/commands/readCommands.d.ts +27 -22
  56. package/lib/types/cli/commands/transfer.d.ts +9 -9
  57. package/lib/types/cli/options.d.ts +76 -21
  58. package/lib/types/cli/types.d.ts +11 -13
  59. package/lib/types/cli/utils.d.ts +71 -31
  60. package/lib/types/common/ant-registry.d.ts +49 -47
  61. package/lib/types/common/ant.d.ts +54 -539
  62. package/lib/types/common/faucet.d.ts +20 -8
  63. package/lib/types/common/index.d.ts +0 -3
  64. package/lib/types/common/io.d.ts +66 -258
  65. package/lib/types/constants.d.ts +11 -18
  66. package/lib/types/solana/ant-readable.d.ts +180 -0
  67. package/lib/types/solana/ant-registry-readable.d.ts +105 -0
  68. package/lib/types/solana/ant-registry-writeable.d.ts +249 -0
  69. package/lib/types/solana/ant-writeable.d.ts +177 -0
  70. package/lib/types/solana/ata.d.ts +44 -0
  71. package/lib/types/solana/canonical-message.d.ts +121 -0
  72. package/lib/types/solana/clusters.d.ts +109 -0
  73. package/lib/types/solana/constants.d.ts +119 -0
  74. package/lib/types/solana/delegation-math.d.ts +45 -0
  75. package/lib/types/solana/deserialize.d.ts +262 -0
  76. package/lib/types/solana/escrow.d.ts +480 -0
  77. package/lib/types/solana/events.d.ts +38 -0
  78. package/lib/types/solana/funding-plan.d.ts +225 -0
  79. package/lib/types/solana/index.d.ts +87 -0
  80. package/lib/types/solana/instruction.d.ts +39 -0
  81. package/lib/types/solana/io-readable.d.ts +499 -0
  82. package/lib/types/solana/io-writeable.d.ts +893 -0
  83. package/lib/types/solana/json-rpc.d.ts +47 -0
  84. package/lib/types/solana/metadata.d.ts +84 -0
  85. package/lib/types/solana/mpl-core.d.ts +120 -0
  86. package/lib/types/solana/pda.d.ts +95 -0
  87. package/lib/types/solana/predict-prescribed-observers.d.ts +28 -0
  88. package/lib/types/solana/retry.d.ts +62 -0
  89. package/lib/types/solana/rpc-circuit-breaker.d.ts +78 -0
  90. package/lib/types/solana/send.d.ts +94 -0
  91. package/lib/types/solana/spawn-ant.d.ts +145 -0
  92. package/lib/types/solana/types.d.ts +82 -0
  93. package/lib/types/types/ant-registry.d.ts +43 -4
  94. package/lib/types/types/ant.d.ts +114 -96
  95. package/lib/types/types/common.d.ts +18 -74
  96. package/lib/types/types/faucet.d.ts +2 -2
  97. package/lib/types/types/io.d.ts +244 -158
  98. package/lib/types/types/token.d.ts +0 -12
  99. package/lib/types/utils/ant.d.ts +1 -12
  100. package/lib/types/utils/index.d.ts +0 -3
  101. package/lib/types/version.d.ts +1 -1
  102. package/package.json +36 -33
  103. package/lib/cjs/cli/cli.js +0 -822
  104. package/lib/cjs/cli/commands/antCommands.js +0 -113
  105. package/lib/cjs/cli/commands/arnsPurchaseCommands.js +0 -212
  106. package/lib/cjs/cli/commands/gatewayWriteCommands.js +0 -210
  107. package/lib/cjs/cli/commands/readCommands.js +0 -215
  108. package/lib/cjs/cli/commands/transfer.js +0 -159
  109. package/lib/cjs/cli/options.js +0 -470
  110. package/lib/cjs/cli/types.js +0 -2
  111. package/lib/cjs/cli/utils.js +0 -639
  112. package/lib/cjs/common/ant-registry.js +0 -155
  113. package/lib/cjs/common/ant-versions.js +0 -93
  114. package/lib/cjs/common/ant.js +0 -1182
  115. package/lib/cjs/common/arweave.js +0 -27
  116. package/lib/cjs/common/contracts/ao-process.js +0 -224
  117. package/lib/cjs/common/error.js +0 -64
  118. package/lib/cjs/common/faucet.js +0 -150
  119. package/lib/cjs/common/hyperbeam/hb.js +0 -173
  120. package/lib/cjs/common/index.js +0 -42
  121. package/lib/cjs/common/io.js +0 -1423
  122. package/lib/cjs/common/logger.js +0 -83
  123. package/lib/cjs/common/loggers/winston.js +0 -68
  124. package/lib/cjs/common/marketplace.js +0 -731
  125. package/lib/cjs/common/turbo.js +0 -223
  126. package/lib/cjs/constants.js +0 -41
  127. package/lib/cjs/node/index.js +0 -39
  128. package/lib/cjs/package.json +0 -1
  129. package/lib/cjs/types/ant-registry.js +0 -2
  130. package/lib/cjs/types/ant.js +0 -168
  131. package/lib/cjs/types/common.js +0 -2
  132. package/lib/cjs/types/faucet.js +0 -2
  133. package/lib/cjs/types/index.js +0 -37
  134. package/lib/cjs/types/io.js +0 -51
  135. package/lib/cjs/types/token.js +0 -116
  136. package/lib/cjs/utils/ant.js +0 -108
  137. package/lib/cjs/utils/ao.js +0 -432
  138. package/lib/cjs/utils/arweave.js +0 -285
  139. package/lib/cjs/utils/base64.js +0 -62
  140. package/lib/cjs/utils/hash.js +0 -56
  141. package/lib/cjs/utils/index.js +0 -38
  142. package/lib/cjs/utils/processes.js +0 -173
  143. package/lib/cjs/utils/random.js +0 -30
  144. package/lib/cjs/utils/schema.js +0 -15
  145. package/lib/cjs/utils/url.js +0 -37
  146. package/lib/cjs/version.js +0 -20
  147. package/lib/cjs/web/index.js +0 -41
  148. package/lib/esm/common/ant-versions.js +0 -87
  149. package/lib/esm/common/arweave.js +0 -21
  150. package/lib/esm/common/contracts/ao-process.js +0 -220
  151. package/lib/esm/common/hyperbeam/hb.js +0 -169
  152. package/lib/esm/common/marketplace.js +0 -724
  153. package/lib/esm/common/turbo.js +0 -215
  154. package/lib/esm/node/index.js +0 -20
  155. package/lib/esm/utils/ao.js +0 -420
  156. package/lib/esm/utils/arweave.js +0 -271
  157. package/lib/esm/utils/processes.js +0 -167
  158. package/lib/esm/web/index.js +0 -20
  159. package/lib/types/common/ant-versions.d.ts +0 -39
  160. package/lib/types/common/arweave.d.ts +0 -17
  161. package/lib/types/common/contracts/ao-process.d.ts +0 -47
  162. package/lib/types/common/hyperbeam/hb.d.ts +0 -88
  163. package/lib/types/common/marketplace.d.ts +0 -568
  164. package/lib/types/common/turbo.d.ts +0 -61
  165. package/lib/types/node/index.d.ts +0 -20
  166. package/lib/types/utils/ao.d.ts +0 -80
  167. package/lib/types/utils/arweave.d.ts +0 -79
  168. package/lib/types/utils/processes.d.ts +0 -39
  169. package/lib/types/web/index.d.ts +0 -20
@@ -0,0 +1,480 @@
1
+ /**
2
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /**
17
+ * Solana ANT-escrow and Token-escrow clients — `ario-ant-escrow` program.
18
+ *
19
+ * ANTEscrow holds a Metaplex Core ANT NFT in trustless custody and
20
+ * releases it after on-chain verification of an Arweave RSA-PSS-4096 or
21
+ * Ethereum ECDSA signature over a canonical claim message.
22
+ *
23
+ * TokenEscrow holds ARIO SPL tokens (liquid or vaulted) in trustless
24
+ * custody with the same multi-protocol claim flow.
25
+ *
26
+ * Design: `docs/ANT_ESCROW_DESIGN.md` (account model, canonical message
27
+ * format, threat model). Plan: `docs/ANT_ESCROW_IMPLEMENTATION_PLAN.md`.
28
+ *
29
+ * All instruction encoding is delegated to the Codama-generated builders
30
+ * in `./generated/ant-escrow/instructions/` — they own the discriminator,
31
+ * Borsh codec, and account-meta wiring derived from the on-chain IDL.
32
+ */
33
+ import { type Address, type Commitment, type Instruction, type TransactionSigner } from '@solana/kit';
34
+ import { type EscrowAnt, type EscrowToken } from '@ar.io/solana-contracts/ant-escrow';
35
+ import type { ILogger } from '../common/logger.js';
36
+ import type { SolanaRpc, SolanaRpcSubscriptions } from './types.js';
37
+ export type EscrowProtocol = 'arweave' | 'ethereum';
38
+ export interface EscrowAntState {
39
+ /** On-chain schema version, as decoded by the generated client. */
40
+ version: EscrowAnt['version'];
41
+ bump: number;
42
+ depositor: Address;
43
+ antMint: Address;
44
+ recipientProtocol: EscrowProtocol;
45
+ recipientPubkey: Uint8Array;
46
+ nonce: Uint8Array;
47
+ depositSlot: bigint;
48
+ }
49
+ export interface ANTEscrowConfig {
50
+ rpc: SolanaRpc;
51
+ rpcSubscriptions?: SolanaRpcSubscriptions;
52
+ signer?: TransactionSigner;
53
+ programId?: Address;
54
+ /**
55
+ * ario-core program id. Currently unused (post-ADR-022 the SDK no longer
56
+ * builds a sibling `vaulted_transfer`; active vault claims are rejected
57
+ * with `VaultStillLocked`). Retained for forward-compat — if the active
58
+ * re-lock path is ever revived via the direct-CPI restoration playbook
59
+ * (contracts `docs/RESTORE_ACTIVE_VAULT_RELOCK.md`), this is the program
60
+ * the new claim ABI would need to reference. Defaults to
61
+ * {@link ARIO_CORE_PROGRAM_ID}.
62
+ */
63
+ coreProgram?: Address;
64
+ commitment?: Commitment;
65
+ logger?: ILogger;
66
+ }
67
+ /**
68
+ * Solana-backed client for the trustless ANT-escrow program. All write
69
+ * methods require both `rpcSubscriptions` and `signer`; read methods
70
+ * only need `rpc`.
71
+ */
72
+ export declare class ANTEscrow {
73
+ protected readonly rpc: SolanaRpc;
74
+ protected readonly rpcSubscriptions?: SolanaRpcSubscriptions;
75
+ protected readonly signer?: TransactionSigner;
76
+ readonly programId: Address;
77
+ protected readonly commitment: Commitment;
78
+ protected readonly logger: ILogger;
79
+ constructor(config: ANTEscrowConfig);
80
+ static init(config: ANTEscrowConfig): ANTEscrow;
81
+ /** Fetch the on-chain `EscrowAnt` for an ANT mint, or `null` if no
82
+ * active escrow exists. Uses the Codama-generated decoder. */
83
+ get(antMint: Address): Promise<EscrowAntState | null>;
84
+ /** Address of the EscrowAnt PDA for an ANT mint (no RPC call). */
85
+ getPda(antMint: Address): Promise<Address>;
86
+ /**
87
+ * Lock an ANT into escrow. The signer (depositor) must currently own
88
+ * the asset; mpl-core's TransferV1 CPI enforces this.
89
+ *
90
+ * `recipient.publicKey` length must match `recipient.protocol`:
91
+ * - `'arweave'` → 512-byte RSA-4096 modulus (the JWK `n` field)
92
+ * - `'ethereum'` → 20-byte address
93
+ */
94
+ deposit(args: {
95
+ antMint: Address;
96
+ recipient: {
97
+ protocol: EscrowProtocol;
98
+ publicKey: Uint8Array;
99
+ };
100
+ }): Promise<string>;
101
+ depositIx(args: {
102
+ antMint: Address;
103
+ recipient: {
104
+ protocol: EscrowProtocol;
105
+ publicKey: Uint8Array;
106
+ };
107
+ }, depositor: TransactionSigner): Promise<Instruction>;
108
+ /**
109
+ * Re-target the escrow at a new recipient identity. Rotates the
110
+ * on-chain nonce, invalidating any in-flight claim signatures bound
111
+ * to the prior recipient.
112
+ */
113
+ updateRecipient(args: {
114
+ antMint: Address;
115
+ newRecipient: {
116
+ protocol: EscrowProtocol;
117
+ publicKey: Uint8Array;
118
+ };
119
+ }): Promise<string>;
120
+ /**
121
+ * Pull an escrowed ANT back to the depositor. Closes the escrow PDA
122
+ * and refunds rent.
123
+ */
124
+ cancel(args: {
125
+ antMint: Address;
126
+ }): Promise<string>;
127
+ /**
128
+ * Submit an Arweave RSA-PSS-4096 signature to release the ANT.
129
+ * Anyone can submit (the fee payer = `signer`); only `claimant`
130
+ * receives the ANT, and only the original `depositor` receives rent.
131
+ */
132
+ claimArweave(args: {
133
+ antMint: Address;
134
+ claimant: Address;
135
+ signature: Uint8Array;
136
+ saltLen?: number;
137
+ }): Promise<string>;
138
+ /**
139
+ * Build the ANT-claim-via-Arweave-attested instruction.
140
+ *
141
+ * **API note**: this method previously took user-side RSA-PSS params
142
+ * (`signature`, `saltLen`, `messageNonce`). The on-chain ix was
143
+ * renamed to `claim_ant_arweave_attested` (canonical contracts
144
+ * `ar-io-solana-contracts` PR-19+): verification is now via
145
+ * instruction-introspection of a preceding Ed25519 sigverify ix
146
+ * issued by the off-chain attestor (see
147
+ * `migration/attestor/`). Those data args are no longer fed to the
148
+ * builder. Callers MUST prepend the attestor's sigverify ix to the
149
+ * transaction or it will fail on-chain. A higher-level helper that
150
+ * fetches the attestor's signature and assembles the full tx is
151
+ * tracked as a follow-up.
152
+ *
153
+ * @deprecated Args `signature`, `saltLen`, `messageNonce` are
154
+ * ignored. Use the new attested flow.
155
+ */
156
+ claimArweaveIx(args: {
157
+ antMint: Address;
158
+ claimant: Address;
159
+ /** @deprecated unused — superseded by attestor sigverify ix */
160
+ signature?: Uint8Array;
161
+ /** @deprecated unused — superseded by attestor sigverify ix */
162
+ saltLen?: number;
163
+ depositor: Address;
164
+ /** 32-byte nonce from the on-chain Escrow PDA; still part of the
165
+ * canonical claim payload that the attestor signs. */
166
+ messageNonce: Uint8Array;
167
+ }): Promise<Instruction>;
168
+ /** Submit an Ethereum ECDSA secp256k1 + EIP-191 signature. */
169
+ claimEthereum(args: {
170
+ antMint: Address;
171
+ claimant: Address;
172
+ signature: Uint8Array;
173
+ }): Promise<string>;
174
+ claimEthereumIx(args: {
175
+ antMint: Address;
176
+ claimant: Address;
177
+ signature: Uint8Array;
178
+ depositor: Address;
179
+ messageNonce: Uint8Array;
180
+ }): Promise<Instruction>;
181
+ private send;
182
+ private requireSigner;
183
+ private requireEscrow;
184
+ private assertPubkeyLen;
185
+ }
186
+ export type EscrowAssetType = 'token' | 'vault';
187
+ export interface EscrowTokenState {
188
+ /** On-chain schema version, as decoded by the generated client. */
189
+ version: EscrowToken['version'];
190
+ bump: number;
191
+ depositor: Address;
192
+ assetType: EscrowAssetType;
193
+ amount: bigint;
194
+ arioMint: Address;
195
+ assetId: Uint8Array;
196
+ recipientProtocol: EscrowProtocol;
197
+ recipientPubkey: Uint8Array;
198
+ nonce: Uint8Array;
199
+ depositSlot: bigint;
200
+ vaultEndTimestamp: bigint;
201
+ vaultRevocable: boolean;
202
+ }
203
+ /**
204
+ * Forward clock-skew buffer (seconds) added to `vault_end_timestamp` before
205
+ * the SDK considers a vault claimable. The SDK reads wall-clock time
206
+ * (`Date.now()`) while the on-chain gate reads Solana cluster time, and
207
+ * the two can disagree by several seconds. The buffer biases every skew
208
+ * race into the *friendly* direction: the SDK rejects when the chain
209
+ * would actually accept (user retries 30s later, succeeds), never the
210
+ * reverse (user submits a doomed tx and sees the raw on-chain error).
211
+ *
212
+ * 30s is conservative — Solana cluster clock typically drifts <2s vs
213
+ * wall clock — but matches the order of magnitude of the previously-used
214
+ * `60s` introspection tolerance in the removed `vault_introspect` module.
215
+ */
216
+ export declare const CLOCK_SKEW_TOLERANCE_SECONDS = 30n;
217
+ /**
218
+ * Returns `true` when a vault escrow is past its unlock timestamp by at
219
+ * least {@link CLOCK_SKEW_TOLERANCE_SECONDS}. Non-throwing companion to
220
+ * {@link assertVaultClaimable} for UI gating (e.g. enabling/disabling a
221
+ * Submit button without showing an error).
222
+ */
223
+ export declare function isVaultClaimable(escrow: EscrowTokenState): boolean;
224
+ /**
225
+ * Pre-flight the on-chain `VaultStillLocked` gate (ADR-022): refuse to build
226
+ * a claim tx while the vault is still locked, with a small forward
227
+ * {@link CLOCK_SKEW_TOLERANCE_SECONDS} buffer so wall/cluster clock skew
228
+ * biases into the friendly direction. Surfaces the unlock timestamp so
229
+ * callers / UIs can show "claimable after <date>" instead of a doomed tx.
230
+ *
231
+ * Exported for unit-testability; not part of the public SDK surface — call the
232
+ * high-level `claimVaultArweave` / `claimVaultEthereum` instead, which invoke
233
+ * this guard internally.
234
+ *
235
+ * @internal
236
+ */
237
+ export declare function assertVaultClaimable(escrow: EscrowTokenState): void;
238
+ /**
239
+ * Solana-backed client for the trustless token/vault escrow program. All
240
+ * write methods require both `rpcSubscriptions` and `signer`; read methods
241
+ * only need `rpc`.
242
+ *
243
+ * Uses the same config shape as {@link ANTEscrow}.
244
+ */
245
+ export declare class TokenEscrow {
246
+ protected readonly rpc: SolanaRpc;
247
+ protected readonly rpcSubscriptions?: SolanaRpcSubscriptions;
248
+ protected readonly signer?: TransactionSigner;
249
+ readonly programId: Address;
250
+ readonly coreProgram: Address;
251
+ protected readonly commitment: Commitment;
252
+ protected readonly logger: ILogger;
253
+ constructor(config: ANTEscrowConfig);
254
+ static init(config: ANTEscrowConfig): TokenEscrow;
255
+ /**
256
+ * Fetch the on-chain `EscrowToken` for a depositor and asset ID, or
257
+ * `null` if no active escrow exists. Uses the Codama-generated decoder.
258
+ */
259
+ get(depositor: Address, assetId: Uint8Array): Promise<EscrowTokenState | null>;
260
+ /**
261
+ * Fetch the on-chain `EscrowToken` for a vault escrow, or `null` if
262
+ * no active escrow exists.
263
+ */
264
+ getVault(depositor: Address, assetId: Uint8Array): Promise<EscrowTokenState | null>;
265
+ /** Address of the EscrowToken PDA (no RPC call). */
266
+ getTokenPda(depositor: Address, assetId: Uint8Array): Promise<Address>;
267
+ /** Address of the EscrowVault PDA (no RPC call). */
268
+ getVaultPda(depositor: Address, assetId: Uint8Array): Promise<Address>;
269
+ /**
270
+ * Deposit liquid ARIO tokens into escrow for a designated Arweave or
271
+ * Ethereum recipient. Prepends a create-ATA-idempotent instruction for
272
+ * the escrow PDA's token account in the same transaction.
273
+ */
274
+ depositTokens(args: {
275
+ assetId: Uint8Array;
276
+ amount: bigint;
277
+ arioMint: Address;
278
+ depositorTokenAccount: Address;
279
+ recipient: {
280
+ protocol: EscrowProtocol;
281
+ publicKey: Uint8Array;
282
+ };
283
+ }): Promise<string>;
284
+ /**
285
+ * Deposit ARIO tokens into escrow as a vaulted (time-locked) position.
286
+ * Same as `depositTokens` but additionally records the lock duration
287
+ * and revocability flag. Uses the vault PDA seed.
288
+ */
289
+ depositVault(args: {
290
+ assetId: Uint8Array;
291
+ amount: bigint;
292
+ arioMint: Address;
293
+ lockDurationSeconds: bigint;
294
+ revocable: boolean;
295
+ depositorTokenAccount: Address;
296
+ recipient: {
297
+ protocol: EscrowProtocol;
298
+ publicKey: Uint8Array;
299
+ };
300
+ }): Promise<string>;
301
+ /**
302
+ * Submit an Arweave RSA-PSS-4096 signature to release escrowed tokens.
303
+ * Anyone can submit (fee payer = `signer`); only `claimant` receives
304
+ * the tokens, and `depositor` receives rent.
305
+ */
306
+ claimTokensArweave(args: {
307
+ depositor: Address;
308
+ assetId: Uint8Array;
309
+ claimant: Address;
310
+ claimantTokenAccount: Address;
311
+ escrowTokenAccount: Address;
312
+ signature: Uint8Array;
313
+ saltLen?: number;
314
+ }): Promise<string>;
315
+ /**
316
+ * @deprecated Args `signature`, `saltLen`, `messageNonce` are ignored.
317
+ * Use the new attested flow — see `claimArweaveIx` doc.
318
+ */
319
+ claimTokensArweaveIx(args: {
320
+ depositor: Address;
321
+ assetId: Uint8Array;
322
+ claimant: Address;
323
+ claimantTokenAccount: Address;
324
+ escrowTokenAccount: Address;
325
+ /** @deprecated unused — superseded by attestor sigverify ix */
326
+ signature?: Uint8Array;
327
+ /** @deprecated unused — superseded by attestor sigverify ix */
328
+ saltLen?: number;
329
+ /** 32-byte nonce from the on-chain Escrow PDA. */
330
+ messageNonce: Uint8Array;
331
+ }): Promise<Instruction>;
332
+ /**
333
+ * Submit an Ethereum ECDSA secp256k1 + EIP-191 signature to release
334
+ * escrowed tokens.
335
+ */
336
+ claimTokensEthereum(args: {
337
+ depositor: Address;
338
+ assetId: Uint8Array;
339
+ claimant: Address;
340
+ claimantTokenAccount: Address;
341
+ escrowTokenAccount: Address;
342
+ signature: Uint8Array;
343
+ }): Promise<string>;
344
+ claimTokensEthereumIx(args: {
345
+ depositor: Address;
346
+ assetId: Uint8Array;
347
+ claimant: Address;
348
+ claimantTokenAccount: Address;
349
+ escrowTokenAccount: Address;
350
+ signature: Uint8Array;
351
+ messageNonce: Uint8Array;
352
+ }): Promise<Instruction>;
353
+ /**
354
+ * **Use {@link claimVaultArweaveIx} instead** — this single-send wrapper
355
+ * cannot work end-to-end for the Arweave attested vault-claim path,
356
+ * because the on-chain `claim_vault_arweave_attested` handler requires
357
+ * an Ed25519Program native sigverify ix at idx-1 of the claim ix
358
+ * (introspected via `instructions_sysvar`). That sigverify ix carries
359
+ * the attestor's Ed25519 signature over the canonical claim message
360
+ * and is built by the *integrator* (who calls the off-chain attestor
361
+ * service for the signature, per ADR-017) — the SDK has no attestor
362
+ * URL or client to do this for the caller.
363
+ *
364
+ * Calling this method instead of composing via
365
+ * {@link claimVaultArweaveIx} will hit `MissingAttestation` on-chain.
366
+ * It is kept only for ABI continuity; new code must use
367
+ * {@link claimVaultArweaveIx} and prepend the attestor sigverify ix.
368
+ *
369
+ * @deprecated cannot succeed alone — see {@link claimVaultArweaveIx}.
370
+ */
371
+ claimVaultArweave(_args: {
372
+ depositor: Address;
373
+ assetId: Uint8Array;
374
+ claimant: Address;
375
+ claimantTokenAccount: Address;
376
+ escrowTokenAccount: Address;
377
+ signature: Uint8Array;
378
+ saltLen?: number;
379
+ }): Promise<string>;
380
+ /**
381
+ * Build a `claim_vault_arweave_attested` instruction (without sending).
382
+ * Mirror of {@link claimTokensArweaveIx} for the vault-claim path:
383
+ * returns the bare claim ix so the caller can prepend the attestor's
384
+ * Ed25519Program sigverify ix and submit the bundle in one tx.
385
+ *
386
+ * The on-chain handler:
387
+ * - Reads the preceding Ed25519Program native sigverify ix from
388
+ * `instructions_sysvar` to confirm the attestor signed the canonical
389
+ * claim message.
390
+ * - Rejects with `VaultStillLocked` if `clock < vault_end_timestamp`
391
+ * (ADR-022). Callers should pre-flight with {@link isVaultClaimable}
392
+ * (non-throwing) or {@link assertVaultClaimable} (throws with the
393
+ * unlock timestamp) before composing the tx.
394
+ * - On the expired path, transfers the escrowed amount liquid to
395
+ * `claimantTokenAccount` and closes the escrow PDA.
396
+ *
397
+ * Composition (frontend pattern):
398
+ * ```ts
399
+ * const escrow = await tokenEscrow.requireVaultEscrow(depositor, assetId);
400
+ * assertVaultClaimable(escrow); // pre-flight
401
+ * const canonical = canonicalMessage({ ... }); // build message
402
+ * const attestation = await attestor.attest({ ... }); // attestor service
403
+ * const ed25519Ix = buildEd25519SigverifyIx(
404
+ * attestation.attestorPubkey, attestation.signature, canonical,
405
+ * );
406
+ * const claimIx = await tokenEscrow.claimVaultArweaveIx({
407
+ * depositor, assetId, claimant, claimantTokenAccount,
408
+ * escrowTokenAccount, messageNonce: escrow.nonce,
409
+ * });
410
+ * // Idempotent-create the claimant ATA if it's the canonical derivation.
411
+ * await sendTx([createAtaIx?, ed25519Ix, claimIx]);
412
+ * ```
413
+ */
414
+ claimVaultArweaveIx(args: {
415
+ depositor: Address;
416
+ assetId: Uint8Array;
417
+ claimant: Address;
418
+ claimantTokenAccount: Address;
419
+ escrowTokenAccount: Address;
420
+ /** 32-byte nonce from the on-chain EscrowToken PDA (`escrow.nonce`). */
421
+ messageNonce: Uint8Array;
422
+ }): Promise<Instruction>;
423
+ /**
424
+ * Submit an Ethereum ECDSA signature to release escrowed vault tokens. See
425
+ * {@link claimVaultArweave} — same lock semantics: vaults are only claimable
426
+ * after `vault_end_timestamp`; active (still-locked) claims throw pre-flight
427
+ * and are rejected on-chain with `VaultStillLocked` (ADR-022 / BD-107).
428
+ */
429
+ claimVaultEthereum(args: {
430
+ depositor: Address;
431
+ assetId: Uint8Array;
432
+ claimant: Address;
433
+ claimantTokenAccount: Address;
434
+ escrowTokenAccount: Address;
435
+ signature: Uint8Array;
436
+ }): Promise<string>;
437
+ /**
438
+ /**
439
+ * Idempotent-create the claimant's canonical ATA when needed.
440
+ *
441
+ * The claim handler delivers liquid tokens directly to
442
+ * `claimantTokenAccount` (post-ADR-022 there's only the liquid path for
443
+ * vaults). If the claimant is a fresh wallet that has never held this
444
+ * mint, the ATA doesn't exist and the tx fails with `AccountNotInitialized`
445
+ * (#3012).
446
+ *
447
+ * Returns `null` when the caller passed a non-canonical
448
+ * `claimantTokenAccount` (manually-created non-ATA token account,
449
+ * presumably already exists — caller's responsibility).
450
+ */
451
+ private _createClaimantAtaIfCanonical;
452
+ /**
453
+ * Cancel a token or vault escrow deposit and return the tokens to the
454
+ * depositor. Only callable by the original depositor.
455
+ */
456
+ cancel(args: {
457
+ assetId: Uint8Array;
458
+ assetType: EscrowAssetType;
459
+ depositorTokenAccount: Address;
460
+ escrowTokenAccount: Address;
461
+ }): Promise<string>;
462
+ /**
463
+ * Re-target the escrow at a new recipient identity. Rotates the
464
+ * on-chain nonce, invalidating any in-flight claim signatures.
465
+ */
466
+ updateRecipient(args: {
467
+ assetId: Uint8Array;
468
+ assetType: EscrowAssetType;
469
+ newRecipient: {
470
+ protocol: EscrowProtocol;
471
+ publicKey: Uint8Array;
472
+ };
473
+ }): Promise<string>;
474
+ private send;
475
+ private requireSigner;
476
+ private requireTokenEscrow;
477
+ private requireVaultEscrow;
478
+ private assertPubkeyLen;
479
+ private assertAssetIdLen;
480
+ }
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /**
17
+ * AR.IO Solana event decoders — STUB.
18
+ *
19
+ * The local event codegen pipeline has been removed. Event decoders will be
20
+ * restored once `@ar.io/solana-contracts` publishes them. Until then, the
21
+ * parse functions return empty arrays and the union types are `never`.
22
+ */
23
+ import type { Rpc, Signature, SolanaRpcApi } from '@solana/kit';
24
+ /** Placeholder — no event variants are available until the contracts package ships event decoders. */
25
+ export type AnyArioCoreEvent = never;
26
+ export type AnyArioGarEvent = never;
27
+ export type AnyArioArnsEvent = never;
28
+ export type AnyArioAntEvent = never;
29
+ export type AnyArioAntEscrowEvent = never;
30
+ export type AnyEvent = AnyArioCoreEvent | AnyArioGarEvent | AnyArioArnsEvent | AnyArioAntEvent | AnyArioAntEscrowEvent;
31
+ export type EventName = never;
32
+ export declare function parseEventsFromLogs(_logs: readonly string[]): AnyEvent[];
33
+ export declare function parseTransactionEvents(_rpc: Rpc<SolanaRpcApi>, _signature: Signature, _opts?: {
34
+ commitment?: 'processed' | 'confirmed' | 'finalized';
35
+ }): Promise<AnyEvent[]>;
36
+ export declare function isEvent<N extends EventName>(ev: AnyEvent, _name: N): ev is Extract<AnyEvent, {
37
+ name: N;
38
+ }>;