@withautonomi/ant-sdk 0.1.0 → 0.2.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 +56 -2
- package/index.d.ts +62 -461
- package/index.js +121 -687
- package/native.d.ts +794 -0
- package/native.js +728 -0
- package/package.json +16 -14
package/README.md
CHANGED
|
@@ -82,11 +82,62 @@ lifetime. So:
|
|
|
82
82
|
return `Promise`s driven on the addon's own runtime, so the event loop never
|
|
83
83
|
blocks.
|
|
84
84
|
|
|
85
|
+
## Errors
|
|
86
|
+
|
|
87
|
+
Every error the SDK throws or rejects with has a stable `code` naming its
|
|
88
|
+
variant, the same names the Python, Swift, Kotlin and C# bindings use. Match on
|
|
89
|
+
`code`, not on `message`: the message is for people and may change between
|
|
90
|
+
releases.
|
|
91
|
+
|
|
92
|
+
```js
|
|
93
|
+
import { isAntError } from '@withautonomi/ant-sdk'
|
|
94
|
+
|
|
95
|
+
try {
|
|
96
|
+
const data = await client.dataGetPublic(address)
|
|
97
|
+
} catch (err) {
|
|
98
|
+
if (isAntError(err) && err.code === 'NotFound') {
|
|
99
|
+
// nothing is stored at that address
|
|
100
|
+
} else {
|
|
101
|
+
throw err
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
| `code` | Meaning |
|
|
107
|
+
|---|---|
|
|
108
|
+
| `InitializationFailed` | The client could not start or connect. |
|
|
109
|
+
| `NetworkError` | A network operation failed, including too few peers. Usually worth retrying. |
|
|
110
|
+
| `PaymentError` | A payment failed. |
|
|
111
|
+
| `Timeout` | An operation timed out. |
|
|
112
|
+
| `InsufficientDiskSpace` | Not enough disk space for the operation. |
|
|
113
|
+
| `PartialUpload` | An upload stopped partway, after some on-chain spend. |
|
|
114
|
+
| `InvalidInput` | An argument was malformed (bad hex, wrong length, unknown network name, ...). |
|
|
115
|
+
| `NotFound` | Nothing is stored at a well-formed address. |
|
|
116
|
+
| `AlreadyExists` | The data is already stored. |
|
|
117
|
+
| `WalletNotConfigured` | A write needs a wallet and the client has none. |
|
|
118
|
+
| `InternalError` | Anything else. |
|
|
119
|
+
| `PointerFinal` | The pointer holds a final state (frozen or transferred): nothing can update or transfer it. |
|
|
120
|
+
| `PointerForked` | The pointer's owner signed two different final states. |
|
|
121
|
+
| `CloseGroupShortfall` | Too few of the close group answered or stored the record. Worth retrying; a `finalizePointer` that returns it keeps its paid attempt. |
|
|
122
|
+
| `CreationFailed` | A `Wallet` could not be built (e.g. a bad key or address). |
|
|
123
|
+
| `OperationFailed` | A `Wallet` operation failed (e.g. an RPC call). |
|
|
124
|
+
|
|
125
|
+
`isAntError(err)` narrows `err` to `AntError` (`code: AntErrorCode`) in
|
|
126
|
+
TypeScript, and `ANT_ERROR_CODES` lists every code. Passing a value of the wrong
|
|
127
|
+
JS type (a number where a string is expected, say) fails before the SDK runs,
|
|
128
|
+
with Node-API's own code (`StringExpected`, `InvalidArg`, ...); that is not an
|
|
129
|
+
`AntError`.
|
|
130
|
+
|
|
85
131
|
## Amounts and buffers
|
|
86
132
|
|
|
87
133
|
- Token/gas **amounts are decimal strings** (`storageCostAtto`, `gasCostWei`,
|
|
88
134
|
`amount`) — they exceed `Number.MAX_SAFE_INTEGER`. Counts and sizes are plain
|
|
89
135
|
numbers.
|
|
136
|
+
- A manifest records each size as an unsigned 64-bit integer, which can be more
|
|
137
|
+
than a number holds exactly. Manifest sizes (`size`, `exactSize`) are
|
|
138
|
+
therefore always exact numbers from 0 to `Number.MAX_SAFE_INTEGER`: building
|
|
139
|
+
with a size outside that range, or decoding a manifest that records one,
|
|
140
|
+
throws `InvalidInput` naming the entry. A size is never rounded or negative.
|
|
90
141
|
- Binary data is `Uint8Array`/`Buffer` in, `Buffer` out — zero-copy into Rust.
|
|
91
142
|
|
|
92
143
|
## Platform support
|
|
@@ -116,8 +167,11 @@ npm run build:debug # or: npm run build (release, optimized)
|
|
|
116
167
|
npm test # offline smoke tests
|
|
117
168
|
```
|
|
118
169
|
|
|
119
|
-
`npm run build` produces the platform `.node
|
|
120
|
-
`
|
|
170
|
+
`npm run build` produces the platform `.node` (git-ignored) and regenerates
|
|
171
|
+
`native.js` (loader) and `native.d.ts` (types). Those two are committed, and CI
|
|
172
|
+
fails if they drift from the `#[napi]` surface, so commit them after changing
|
|
173
|
+
it. `index.js` and `index.d.ts`, the package's entry points, are hand-written:
|
|
174
|
+
they re-export `native.*` and add the error codes. A live round-trip demo
|
|
121
175
|
against a local devnet is in [`examples/upload_download_demo.mjs`](examples/upload_download_demo.mjs).
|
|
122
176
|
|
|
123
177
|
## How it fits
|
package/index.d.ts
CHANGED
|
@@ -1,465 +1,66 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
/** Connect to a local test network (loopback). */
|
|
5
|
-
static connectLocal(dataDir?: string | undefined | null): Promise<Client>
|
|
6
|
-
/**
|
|
7
|
-
* Connect using explicit bootstrap peers (`/ip4/<ip>/udp/<port>/quic`
|
|
8
|
-
* multiaddr strings). Read-only; use a wallet/external-signer variant to
|
|
9
|
-
* write.
|
|
10
|
-
*/
|
|
11
|
-
static connect(peers: Array<string>, dataDir?: string | undefined | null): Promise<Client>
|
|
12
|
-
/**
|
|
13
|
-
* Connect to the Autonomi **production network** using the SDK's vendored
|
|
14
|
-
* bootstrap peers — no configuration. Read-only.
|
|
15
|
-
*/
|
|
16
|
-
static connectDefault(dataDir?: string | undefined | null): Promise<Client>
|
|
17
|
-
/**
|
|
18
|
-
* `connectDefault` with a wallet attached for writes, preset for the
|
|
19
|
-
* production EVM network.
|
|
20
|
-
*/
|
|
21
|
-
static connectDefaultWithWallet(privateKey: string, dataDir?: string | undefined | null): Promise<Client>
|
|
22
|
-
/**
|
|
23
|
-
* `connectDefault` configured for the **external-signer** flow (mobile
|
|
24
|
-
* wallets / WalletConnect): production peers + EVM network for quotes, no
|
|
25
|
-
* wallet attached.
|
|
26
|
-
*/
|
|
27
|
-
static connectDefaultForExternalSigner(dataDir?: string | undefined | null): Promise<Client>
|
|
28
|
-
/** Connect with a wallet configured for writes on a custom EVM network. */
|
|
29
|
-
static connectWithWallet(peers: Array<string>, privateKey: string, rpcUrl: string, paymentTokenAddress: string, paymentVaultAddress: string, dataDir?: string | undefined | null): Promise<Client>
|
|
30
|
-
/**
|
|
31
|
-
* Connect to a local devnet described by a devnet manifest JSON file (the
|
|
32
|
-
* file written by `ant-devnet`). **Development/testing only.** Fails if the
|
|
33
|
-
* manifest is missing, malformed, or has no `evm` section.
|
|
34
|
-
*/
|
|
35
|
-
static connectFromDevnetManifest(manifestPath: string, dataDir?: string | undefined | null): Promise<Client>
|
|
36
|
-
/**
|
|
37
|
-
* Like `connectFromDevnetManifest` but for the **external-signer** flow:
|
|
38
|
-
* configures the devnet EVM network for quotes but attaches no wallet.
|
|
39
|
-
*/
|
|
40
|
-
static connectFromDevnetManifestExternalSigner(manifestPath: string, dataDir?: string | undefined | null): Promise<Client>
|
|
41
|
-
/**
|
|
42
|
-
* Connect with an EVM network configured but **no wallet** — the
|
|
43
|
-
* external-signer entry point. Quote/price queries work; payment is signed
|
|
44
|
-
* off-device. Pay via `prepare*` + your signer + `finalize*`.
|
|
45
|
-
*/
|
|
46
|
-
static connectForExternalSigner(peers: Array<string>, rpcUrl: string, paymentTokenAddress: string, paymentVaultAddress: string, dataDir?: string | undefined | null): Promise<Client>
|
|
47
|
-
/** Store a single chunk on the network. */
|
|
48
|
-
chunkPut(data: Uint8Array): Promise<ChunkPutResult>
|
|
49
|
-
/** Retrieve a chunk by hex-encoded address. */
|
|
50
|
-
chunkGet(addressHex: string): Promise<Buffer>
|
|
51
|
-
/** Check whether a chunk exists on the network. */
|
|
52
|
-
chunkExists(addressHex: string): Promise<boolean>
|
|
53
|
-
/** Upload data publicly (retrievable by the returned address). */
|
|
54
|
-
dataPutPublic(data: Uint8Array, paymentMode: PaymentMode): Promise<DataPutPublicResult>
|
|
55
|
-
/** Retrieve public data by its hex-encoded data-map address. */
|
|
56
|
-
dataGetPublic(addressHex: string): Promise<Buffer>
|
|
57
|
-
/**
|
|
58
|
-
* Upload data privately. Returns the serialized data map (hex) — keep it
|
|
59
|
-
* secret; it is required to retrieve the data.
|
|
60
|
-
*/
|
|
61
|
-
dataPutPrivate(data: Uint8Array, paymentMode: PaymentMode): Promise<DataPutPrivateResult>
|
|
62
|
-
/** Retrieve private data using a hex-encoded data map. */
|
|
63
|
-
dataGetPrivate(dataMapHex: string): Promise<Buffer>
|
|
64
|
-
/**
|
|
65
|
-
* Upload a file from disk publicly. Returns the shareable address plus
|
|
66
|
-
* chunk/cost details.
|
|
67
|
-
*/
|
|
68
|
-
fileUploadPublic(path: string, paymentMode: PaymentMode): Promise<FilePutPublicResult>
|
|
69
|
-
/** `fileUploadPublic` with live progress (`Encrypting`/`Quoting`/`Storing`). */
|
|
70
|
-
fileUploadPublicWithProgress(path: string, paymentMode: PaymentMode, onProgress: (progress: ProgressUpdate) => void): Promise<FilePutPublicResult>
|
|
71
|
-
/**
|
|
72
|
-
* Upload a file from disk privately. Returns the serialized data map (hex);
|
|
73
|
-
* keep it secret to retrieve the file later.
|
|
74
|
-
*/
|
|
75
|
-
fileUploadPrivate(path: string, paymentMode: PaymentMode): Promise<FilePutPrivateResult>
|
|
76
|
-
/** `fileUploadPrivate` with live progress. */
|
|
77
|
-
fileUploadPrivateWithProgress(path: string, paymentMode: PaymentMode, onProgress: (progress: ProgressUpdate) => void): Promise<FilePutPrivateResult>
|
|
78
|
-
/** Download a public file to disk by hex-encoded address. */
|
|
79
|
-
fileDownloadPublic(addressHex: string, destPath: string): Promise<void>
|
|
80
|
-
/** Download a private file to disk by hex-encoded data map. */
|
|
81
|
-
fileDownloadPrivate(dataMapHex: string, destPath: string): Promise<void>
|
|
82
|
-
/**
|
|
83
|
-
* Publish an existing private data map (hex) as a public network chunk,
|
|
84
|
-
* returning its hex address — without re-uploading the underlying data.
|
|
85
|
-
*/
|
|
86
|
-
dataMapStore(dataMapHex: string): Promise<string>
|
|
87
|
-
/**
|
|
88
|
-
* Fetch a public data map by hex address and return it serialized (hex) —
|
|
89
|
-
* the inverse of `dataMapStore`.
|
|
90
|
-
*/
|
|
91
|
-
dataMapFetch(addressHex: string): Promise<string>
|
|
92
|
-
/**
|
|
93
|
-
* Estimate the cost of uploading a file *before* preparing or paying.
|
|
94
|
-
* Samples a few chunk addresses; fast and needs no wallet. Check
|
|
95
|
-
* `CostEstimate.confidence` before treating a `"0"` cost as free.
|
|
96
|
-
*/
|
|
97
|
-
estimateFileCost(path: string, paymentMode: PaymentMode): Promise<CostEstimate>
|
|
98
|
-
/** `estimateFileCost` with live progress (the `Encrypting` phase). */
|
|
99
|
-
estimateFileCostWithProgress(path: string, paymentMode: PaymentMode, onProgress: (progress: ProgressUpdate) => void): Promise<CostEstimate>
|
|
100
|
-
/** Approve token spend for storage payments (one-time; wallet-backed client). */
|
|
101
|
-
walletApprove(): Promise<void>
|
|
102
|
-
/**
|
|
103
|
-
* Phase 1: encrypt `data`, collect quotes, and return the payment summary.
|
|
104
|
-
* The prepared state is retained under the returned `uploadId` until finalize.
|
|
105
|
-
*/
|
|
106
|
-
prepareDataUpload(data: Uint8Array, visibility: Visibility): Promise<PreparedUploadInfo>
|
|
107
|
-
/** Phase 1 for a file on disk. */
|
|
108
|
-
prepareFileUpload(path: string, visibility: Visibility): Promise<PreparedUploadInfo>
|
|
109
|
-
/** Phase 1 for a file, with encryption/quoting progress. */
|
|
110
|
-
prepareFileUploadWithProgress(path: string, visibility: Visibility, onProgress: (progress: ProgressUpdate) => void): Promise<PreparedUploadInfo>
|
|
111
|
-
/**
|
|
112
|
-
* Phase 1.5: build the ordered transactions (ERC-20 `approve` + vault
|
|
113
|
-
* payment call(s)) the external wallet must sign to pay for a prepared
|
|
114
|
-
* upload. Empty when everything was already stored.
|
|
115
|
-
*/
|
|
116
|
-
paymentTransactions(uploadId: string): Promise<Array<TxRequest>>
|
|
117
|
-
/**
|
|
118
|
-
* Phase 2 (wave-batch): after the wallet has paid, finalize by supplying the
|
|
119
|
-
* `quoteHash -> txHash` map (both 0x-prefixed hex). Pass an empty map if
|
|
120
|
-
* everything was already stored.
|
|
121
|
-
*/
|
|
122
|
-
finalizeUpload(uploadId: string, txHashes: Record<string, string>): Promise<ExternalUploadResult>
|
|
123
|
-
/** `finalizeUpload` with live storing progress. */
|
|
124
|
-
finalizeUploadWithProgress(uploadId: string, txHashes: Record<string, string>, onProgress: (progress: ProgressUpdate) => void): Promise<ExternalUploadResult>
|
|
125
|
-
/**
|
|
126
|
-
* Phase 2 (merkle): finalize by supplying the `winnerPoolHash` read from the
|
|
127
|
-
* `MerklePaymentMade` event (see the `merkleWinnerPoolHash` free function).
|
|
128
|
-
*/
|
|
129
|
-
finalizeUploadMerkle(uploadId: string, winnerPoolHash: string): Promise<ExternalUploadResult>
|
|
130
|
-
/** `finalizeUploadMerkle` with live storing progress. */
|
|
131
|
-
finalizeUploadMerkleWithProgress(uploadId: string, winnerPoolHash: string, onProgress: (progress: ProgressUpdate) => void): Promise<ExternalUploadResult>
|
|
132
|
-
/**
|
|
133
|
-
* Discard a prepared upload that will not be finalized, freeing the chunk
|
|
134
|
-
* content it holds in memory. Returns `true` if an upload with this id was
|
|
135
|
-
* present. Safe to call with an unknown/already-finalized id.
|
|
136
|
-
*/
|
|
137
|
-
cancelUpload(uploadId: string): boolean
|
|
138
|
-
/**
|
|
139
|
-
* Download public data by address straight to a file on disk, reporting
|
|
140
|
-
* live progress (`Resolving` then `Downloading`). Returns bytes written.
|
|
141
|
-
*/
|
|
142
|
-
downloadPublicToFile(addressHex: string, destPath: string, onProgress: (progress: ProgressUpdate) => void): Promise<number>
|
|
143
|
-
/**
|
|
144
|
-
* Download private data by hex-encoded data map straight to a file on disk,
|
|
145
|
-
* reporting live progress. Returns bytes written.
|
|
146
|
-
*/
|
|
147
|
-
downloadPrivateToFile(dataMapHex: string, destPath: string, onProgress: (progress: ProgressUpdate) => void): Promise<number>
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export declare class Wallet {
|
|
151
|
-
/**
|
|
152
|
-
* Create a wallet from an EVM private key on a custom network (RPC URL +
|
|
153
|
-
* token/vault contract addresses). The private key is zeroized inside the
|
|
154
|
-
* core as soon as the wallet is built.
|
|
155
|
-
*/
|
|
156
|
-
static fromPrivateKey(privateKey: string, rpcUrl: string, paymentTokenAddress: string, paymentVaultAddress: string): Wallet
|
|
157
|
-
/** The wallet's public address (0x-prefixed hex). */
|
|
158
|
-
address(): string
|
|
159
|
-
/** Token balance in atto-tokens (base-10 string). */
|
|
160
|
-
balanceOfTokens(): Promise<string>
|
|
161
|
-
/** Gas-token balance in wei (base-10 string). */
|
|
162
|
-
balanceOfGasTokens(): Promise<string>
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* **Test hook — not part of the public API.** Fires `ticks` synthetic
|
|
167
|
-
* `Encrypting` progress updates through the same bridge every `*WithProgress`
|
|
168
|
-
* method uses, from a background thread, then resolves. Exists so the
|
|
169
|
-
* callback-exception containment (a throwing `onProgress` becomes an
|
|
170
|
-
* `AntProgressCallbackError` warning, never a fatal exception) has an offline
|
|
171
|
-
* regression test.
|
|
172
|
-
*/
|
|
173
|
-
export declare function _emitProgressForTest(onProgress: (progress: ProgressUpdate) => void, ticks: number): Promise<void>
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* The AntFfi SDK version (e.g. `"0.0.8"`) — matches the released SDK version
|
|
177
|
-
* shared across all bindings.
|
|
178
|
-
*/
|
|
179
|
-
export declare function antFfiVersion(): string
|
|
180
|
-
|
|
181
|
-
/** One candidate node inside a [`PoolCommitmentEntry`]. */
|
|
182
|
-
export interface CandidateNodeEntry {
|
|
183
|
-
/** 0x-prefixed EVM rewards address (20 bytes). */
|
|
184
|
-
rewardsAddress: string
|
|
185
|
-
/** Node price in atto-tokens (base-10 string). */
|
|
186
|
-
amount: string
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/** Result of storing a single chunk on the network. */
|
|
190
|
-
export interface ChunkPutResult {
|
|
191
|
-
/** Hex-encoded chunk address (32 bytes). */
|
|
192
|
-
address: string
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/** How much to trust a [`CostEstimate`]'s `storageCostAtto`. */
|
|
196
|
-
export declare enum CostConfidence {
|
|
197
|
-
/** Extrapolated from at least one live quote (the normal case). */
|
|
198
|
-
PricedSample = 0,
|
|
199
|
-
/** Every chunk was sampled and already stored; cost is exactly `"0"`. */
|
|
200
|
-
VerifiedAllAlreadyStored = 1,
|
|
201
|
-
/**
|
|
202
|
-
* Every *sampled* chunk was already stored but the tail was unsampled;
|
|
203
|
-
* `"0"` is a best-effort guess. Render as "likely already stored".
|
|
204
|
-
*/
|
|
205
|
-
AllSamplesAlreadyStoredIncomplete = 2
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* Estimated cost of uploading a file, produced *before* any payment by
|
|
210
|
-
* sampling a few of the file's chunk addresses. No wallet required.
|
|
211
|
-
*/
|
|
212
|
-
export interface CostEstimate {
|
|
213
|
-
/** Original file size in bytes. */
|
|
214
|
-
fileSize: number
|
|
215
|
-
/**
|
|
216
|
-
* Number of data chunks the file would split into (excludes the extra
|
|
217
|
-
* data-map chunk added for public uploads).
|
|
218
|
-
*/
|
|
219
|
-
chunkCount: number
|
|
220
|
-
/** Estimated storage cost in atto-tokens (base-10 string; may exceed u64). */
|
|
221
|
-
storageCostAtto: string
|
|
222
|
-
/**
|
|
223
|
-
* Rough estimated gas cost in wei (base-10 string). A heuristic, NOT a live
|
|
224
|
-
* gas-price query.
|
|
225
|
-
*/
|
|
226
|
-
estimatedGasCostWei: string
|
|
227
|
-
/** Payment mode that would be used. */
|
|
228
|
-
paymentMode: PaymentMode
|
|
229
|
-
/**
|
|
230
|
-
* How much to trust `storageCostAtto` — check before treating a `"0"` cost
|
|
231
|
-
* as free.
|
|
232
|
-
*/
|
|
233
|
-
confidence: CostConfidence
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/** Result of a private data upload (data map returned to caller, kept secret). */
|
|
237
|
-
export interface DataPutPrivateResult {
|
|
238
|
-
/** Hex-encoded serialized data map (caller keeps this secret). */
|
|
239
|
-
dataMap: string
|
|
240
|
-
/** Number of chunks stored. */
|
|
241
|
-
chunksStored: number
|
|
242
|
-
/** Payment mode that was used. */
|
|
243
|
-
paymentModeUsed: PaymentMode
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
/** Result of a public data upload (data map stored as a public chunk). */
|
|
247
|
-
export interface DataPutPublicResult {
|
|
248
|
-
/** Hex-encoded address of the stored data map. */
|
|
249
|
-
address: string
|
|
250
|
-
/** Number of chunks stored. */
|
|
251
|
-
chunksStored: number
|
|
252
|
-
/** Payment mode that was used. */
|
|
253
|
-
paymentModeUsed: PaymentMode
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/** Result of finalizing an external-signer upload. */
|
|
257
|
-
export interface ExternalUploadResult {
|
|
258
|
-
/** Hex-encoded serialized data map (for private retrieval; always present). */
|
|
259
|
-
dataMap: string
|
|
260
|
-
/** For public uploads: hex data-map address (shareable). Absent if private. */
|
|
261
|
-
address?: string
|
|
262
|
-
/** Number of chunks stored on the network. */
|
|
263
|
-
chunksStored: number
|
|
264
|
-
/** Total storage cost paid, in atto-tokens (base-10). "0" if all pre-existed. */
|
|
265
|
-
storageCostAtto: string
|
|
266
|
-
/** Total gas cost in wei (base-10). */
|
|
267
|
-
gasCostWei: string
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
/**
|
|
271
|
-
* Result of uploading a private file. Keep `dataMap` secret — it is required
|
|
272
|
-
* to retrieve the file and is not recoverable from the network.
|
|
273
|
-
*/
|
|
274
|
-
export interface FilePutPrivateResult {
|
|
275
|
-
/** Hex-encoded serialized data map (caller keeps this secret). */
|
|
276
|
-
dataMap: string
|
|
277
|
-
/** Number of chunks stored on the network. */
|
|
278
|
-
chunksStored: number
|
|
279
|
-
/** Total storage cost paid, in atto-tokens (base-10). "0" if all pre-existed. */
|
|
280
|
-
storageCostAtto: string
|
|
281
|
-
/** Total gas cost in wei (base-10). */
|
|
282
|
-
gasCostWei: string
|
|
283
|
-
/** Payment mode that was used. */
|
|
284
|
-
paymentModeUsed: PaymentMode
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
/** Result of uploading a public file. */
|
|
288
|
-
export interface FilePutPublicResult {
|
|
289
|
-
/** Hex-encoded address of the stored data map. */
|
|
290
|
-
address: string
|
|
291
|
-
/** Number of chunks stored on the network. */
|
|
292
|
-
chunksStored: number
|
|
293
|
-
/** Total storage cost paid, in atto-tokens (base-10). "0" if all pre-existed. */
|
|
294
|
-
storageCostAtto: string
|
|
295
|
-
/** Total gas cost in wei (base-10). */
|
|
296
|
-
gasCostWei: string
|
|
297
|
-
/** Payment mode that was used. */
|
|
298
|
-
paymentModeUsed: PaymentMode
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
/**
|
|
302
|
-
* Read the winning pool hash from a settled `payForMerkleTree` transaction (the
|
|
303
|
-
* `MerklePaymentMade` log emitted by `vaultAddress`), 0x-prefixed — pass it to
|
|
304
|
-
* `client.finalizeUploadMerkle`.
|
|
305
|
-
*/
|
|
306
|
-
export declare function merkleWinnerPoolHash(rpcUrl: string, vaultAddress: string, txHash: string): Promise<string>
|
|
307
|
-
|
|
308
|
-
/**
|
|
309
|
-
* On-chain configuration for a known Autonomi EVM network. `name` is one of
|
|
310
|
-
* `"arbitrum-one"` / `"arbitrum-sepolia-test"` (and their short aliases).
|
|
311
|
-
*/
|
|
312
|
-
export declare function networkInfo(name: string): NetworkInfo
|
|
313
|
-
|
|
314
|
-
/** On-chain configuration for a known Autonomi EVM network. */
|
|
315
|
-
export interface NetworkInfo {
|
|
316
|
-
/** EVM chain id (e.g. 42161 Arbitrum One, 421614 Arbitrum Sepolia). */
|
|
317
|
-
chainId: number
|
|
318
|
-
/** 0x-prefixed ANT payment-token address. */
|
|
319
|
-
tokenAddress: string
|
|
320
|
-
/** 0x-prefixed payment-vault address. */
|
|
321
|
-
vaultAddress: string
|
|
322
|
-
/** Default HTTPS RPC URL for the network. */
|
|
323
|
-
rpcUrl: string
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
/** A single on-chain payment the external wallet must settle. */
|
|
327
|
-
export interface PaymentEntry {
|
|
328
|
-
/** 0x-prefixed quote hash (32 bytes) — the key in the tx-hash map at finalize. */
|
|
329
|
-
quoteHash: string
|
|
330
|
-
/** 0x-prefixed EVM rewards address to pay. */
|
|
331
|
-
rewardsAddress: string
|
|
332
|
-
/** Amount to pay in atto-tokens (base-10 string; exceeds u64). */
|
|
333
|
-
amount: string
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
/** How an upload is paid for. */
|
|
337
|
-
export declare enum PaymentMode {
|
|
338
|
-
/** Let the SDK pick: merkle batching for large uploads, single otherwise. */
|
|
339
|
-
Auto = 0,
|
|
340
|
-
/** Merkle-batched payment — one on-chain payment covering many chunks. */
|
|
341
|
-
Merkle = 1,
|
|
342
|
-
/** Per-quote wave payment. */
|
|
343
|
-
Single = 2
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
/**
|
|
347
|
-
* Payment shape of a prepared external-signer upload — selects which finalize
|
|
348
|
-
* call to use (see [`PreparedUploadInfo`]).
|
|
349
|
-
*/
|
|
350
|
-
export declare enum PaymentType {
|
|
351
|
-
WaveBatch = 0,
|
|
352
|
-
Merkle = 1
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
/** One pool commitment for the merkle payment call. */
|
|
356
|
-
export interface PoolCommitmentEntry {
|
|
357
|
-
/** 0x-prefixed pool hash (32 bytes). */
|
|
358
|
-
poolHash: string
|
|
359
|
-
/** The pool's candidate nodes. */
|
|
360
|
-
candidates: Array<CandidateNodeEntry>
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
/**
|
|
364
|
-
* Summary of a prepared external-signer upload. `paymentType` selects which
|
|
365
|
-
* fields are meaningful and which finalize call to use (see the client's
|
|
366
|
-
* `paymentTransactions` / `finalizeUpload*` docs).
|
|
367
|
-
*/
|
|
368
|
-
export interface PreparedUploadInfo {
|
|
369
|
-
/** Opaque handle for this prepared upload; pass to the matching finalize call. */
|
|
370
|
-
uploadId: string
|
|
371
|
-
/** Payment shape — selects the finalize call. */
|
|
372
|
-
paymentType: PaymentType
|
|
373
|
-
/**
|
|
374
|
-
* Wave-batch only: per-quote payments to settle on-chain. Empty for merkle
|
|
375
|
-
* or if everything was already stored.
|
|
376
|
-
*/
|
|
377
|
-
payments: Array<PaymentEntry>
|
|
378
|
-
/** Wave-batch: total across all payments (atto-tokens, base-10). `"0"` for merkle. */
|
|
379
|
-
totalAmount: string
|
|
380
|
-
/** Merkle only: merkle tree depth for the `payForMerkleTree` call. 0 for wave-batch. */
|
|
381
|
-
depth: number
|
|
382
|
-
/** Merkle only: pool commitments for the `payForMerkleTree` call. Empty for wave-batch. */
|
|
383
|
-
poolCommitments: Array<PoolCommitmentEntry>
|
|
384
|
-
/** Merkle only: timestamp for the `payForMerkleTree` call. 0 for wave-batch. */
|
|
385
|
-
merklePaymentTimestamp: number
|
|
386
|
-
/**
|
|
387
|
-
* For public uploads: hex address the data is retrievable from after
|
|
388
|
-
* finalize. Absent for private uploads.
|
|
389
|
-
*/
|
|
390
|
-
dataMapAddress?: string
|
|
391
|
-
/** True if every chunk already existed on the network — nothing to pay. */
|
|
392
|
-
alreadyStored: boolean
|
|
393
|
-
}
|
|
1
|
+
// Public type declarations of @withautonomi/ant-sdk. Hand-written: the API
|
|
2
|
+
// surface lives in `native.d.ts`, which `napi build` generates; this file
|
|
3
|
+
// re-exports it and adds the error codes (V2-1913).
|
|
394
4
|
|
|
395
|
-
|
|
396
|
-
export declare enum ProgressPhase {
|
|
397
|
-
Encrypting = 0,
|
|
398
|
-
Quoting = 1,
|
|
399
|
-
Storing = 2,
|
|
400
|
-
Resolving = 3,
|
|
401
|
-
Downloading = 4
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
/**
|
|
405
|
-
* A progress update for a long-running upload or download. `total` is 0 when
|
|
406
|
-
* unknown yet (show an indeterminate bar); otherwise `done / total` is a 0..1
|
|
407
|
-
* fraction of the current phase.
|
|
408
|
-
*/
|
|
409
|
-
export interface ProgressUpdate {
|
|
410
|
-
phase: ProgressPhase
|
|
411
|
-
done: number
|
|
412
|
-
total: number
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
/** What a [`TxRequest`] is for. */
|
|
416
|
-
export declare enum TxKind {
|
|
417
|
-
/** ERC-20 allowance approval (sent to the token contract). */
|
|
418
|
-
Approve = 0,
|
|
419
|
-
/** The vault payment call. */
|
|
420
|
-
Pay = 1
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
/** Outcome of a settled transaction, from `waitForReceipt`. */
|
|
424
|
-
export interface TxReceipt {
|
|
425
|
-
/** `true` if the transaction succeeded (receipt status `0x1`). */
|
|
426
|
-
success: boolean
|
|
427
|
-
/** Gas units consumed (base-10 string). */
|
|
428
|
-
gasUsed: string
|
|
429
|
-
/** Effective gas price paid in wei (base-10 string). */
|
|
430
|
-
effectiveGasPrice: string
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
/**
|
|
434
|
-
* One transaction the external wallet must sign & send, in order, to pay for a
|
|
435
|
-
* prepared upload (produced by `client.paymentTransactions`).
|
|
436
|
-
*/
|
|
437
|
-
export interface TxRequest {
|
|
438
|
-
/** 0x-prefixed contract address to send the transaction to. */
|
|
439
|
-
to: string
|
|
440
|
-
/** 0x-prefixed ABI-encoded calldata for the transaction's `data` field. */
|
|
441
|
-
data: string
|
|
442
|
-
/** What this transaction is for (allowance approval vs the payment call). */
|
|
443
|
-
kind: TxKind
|
|
444
|
-
/**
|
|
445
|
-
* Wave-batch `Pay` only: the 0x-prefixed quote hashes this payment settles.
|
|
446
|
-
* Map each to the resulting tx hash to build the `finalizeUpload` map.
|
|
447
|
-
*/
|
|
448
|
-
quoteHashes: Array<string>
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
/**
|
|
452
|
-
* Whether an upload is publicly retrievable by address, or private (the data
|
|
453
|
-
* map is returned to the caller only).
|
|
454
|
-
*/
|
|
455
|
-
export declare enum Visibility {
|
|
456
|
-
Public = 0,
|
|
457
|
-
Private = 1
|
|
458
|
-
}
|
|
5
|
+
export * from './native'
|
|
459
6
|
|
|
460
7
|
/**
|
|
461
|
-
*
|
|
462
|
-
*
|
|
463
|
-
* `
|
|
8
|
+
* The stable `code` on every error a `Client` method, `Wallet` method or free
|
|
9
|
+
* function throws or rejects with. Codes name the error variant, matching the
|
|
10
|
+
* Python / Swift (`ClientError.NotFound`) and Kotlin / C#
|
|
11
|
+
* (`ClientException.NotFound`) bindings. `message` stays human-readable and
|
|
12
|
+
* may change between releases; match on `code`.
|
|
13
|
+
*
|
|
14
|
+
* Client errors:
|
|
15
|
+
* - `InitializationFailed`: the client could not start or connect.
|
|
16
|
+
* - `NetworkError`: a network operation failed (including too few peers).
|
|
17
|
+
* Usually worth retrying.
|
|
18
|
+
* - `PaymentError`: a payment failed.
|
|
19
|
+
* - `Timeout`: an operation timed out.
|
|
20
|
+
* - `InsufficientDiskSpace`: not enough disk space for the operation.
|
|
21
|
+
* - `PartialUpload`: an upload stopped partway, after some on-chain spend.
|
|
22
|
+
* - `InvalidInput`: an argument was malformed (bad hex, wrong length, ...).
|
|
23
|
+
* - `NotFound`: nothing is stored at a well-formed address.
|
|
24
|
+
* - `AlreadyExists`: the data is already stored.
|
|
25
|
+
* - `WalletNotConfigured`: a write needs a wallet and the client has none.
|
|
26
|
+
* - `InternalError`: anything else.
|
|
27
|
+
* - `PointerFinal`: the pointer holds a final state; nothing can move it.
|
|
28
|
+
* - `PointerForked`: the pointer's owner signed two different final states.
|
|
29
|
+
* - `CloseGroupShortfall`: too few of the close group answered or stored the
|
|
30
|
+
* record. Worth retrying; a pointer finalize keeps its paid attempt.
|
|
31
|
+
*
|
|
32
|
+
* Wallet errors:
|
|
33
|
+
* - `CreationFailed`: the wallet could not be built (e.g. a bad private key).
|
|
34
|
+
* - `OperationFailed`: a wallet operation failed (e.g. an RPC call).
|
|
35
|
+
*
|
|
36
|
+
* napi's own argument-conversion errors (a wrong JS type passed in) keep
|
|
37
|
+
* napi's codes, such as `InvalidArg`, and are not `AntError`s.
|
|
464
38
|
*/
|
|
465
|
-
export
|
|
39
|
+
export type AntErrorCode =
|
|
40
|
+
| 'InitializationFailed'
|
|
41
|
+
| 'NetworkError'
|
|
42
|
+
| 'PaymentError'
|
|
43
|
+
| 'Timeout'
|
|
44
|
+
| 'InsufficientDiskSpace'
|
|
45
|
+
| 'PartialUpload'
|
|
46
|
+
| 'InvalidInput'
|
|
47
|
+
| 'NotFound'
|
|
48
|
+
| 'AlreadyExists'
|
|
49
|
+
| 'WalletNotConfigured'
|
|
50
|
+
| 'InternalError'
|
|
51
|
+
| 'PointerFinal'
|
|
52
|
+
| 'PointerForked'
|
|
53
|
+
| 'CloseGroupShortfall'
|
|
54
|
+
| 'CreationFailed'
|
|
55
|
+
| 'OperationFailed'
|
|
56
|
+
|
|
57
|
+
/** An error from this SDK: a plain `Error` with a stable `code`. */
|
|
58
|
+
export interface AntError extends Error {
|
|
59
|
+
code: AntErrorCode
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Every `AntErrorCode`, in declaration order. */
|
|
63
|
+
export declare const ANT_ERROR_CODES: readonly AntErrorCode[]
|
|
64
|
+
|
|
65
|
+
/** True when `err` is an error from this SDK carrying one of the codes. */
|
|
66
|
+
export declare function isAntError(err: unknown): err is AntError
|