@withautonomi/autonomi 0.2.2-rc.3 → 0.4.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.
- package/.yarnrc.yml +3 -0
- package/Cargo.toml +24 -0
- package/build.rs +5 -0
- package/index.d.ts +648 -0
- package/index.js +358 -0
- package/package.json +49 -19
- package/src/lib.rs +2290 -0
- package/README.md +0 -30
- package/autonomi.d.ts +0 -314
- package/autonomi.js +0 -1447
- package/autonomi_bg.wasm +0 -0
package/.yarnrc.yml
ADDED
package/Cargo.toml
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
edition = "2021"
|
|
3
|
+
name = "autonomi-nodejs"
|
|
4
|
+
version = "0.1.0"
|
|
5
|
+
description = "NodeJS bindings for the autonomi client"
|
|
6
|
+
license = "GPL-3.0"
|
|
7
|
+
|
|
8
|
+
[lib]
|
|
9
|
+
crate-type = ["cdylib"]
|
|
10
|
+
|
|
11
|
+
[dependencies]
|
|
12
|
+
autonomi = { path = "../autonomi" }
|
|
13
|
+
bytes = { version = "1.0.1", features = ["serde"] }
|
|
14
|
+
eyre = "0.6.12"
|
|
15
|
+
futures = "0.3"
|
|
16
|
+
napi = { version = "2.12.2", default-features = false, features = ["napi4", "napi6", "tokio_rt", "serde-json"] }
|
|
17
|
+
napi-derive = "2.12.2"
|
|
18
|
+
rand = "0.8.5"
|
|
19
|
+
serde = { version = "1.0.133", features = ["derive", "rc"] }
|
|
20
|
+
serde_json = "1.0"
|
|
21
|
+
tokio = { version = "1", features = ["full"] }
|
|
22
|
+
|
|
23
|
+
[build-dependencies]
|
|
24
|
+
napi-build = "2.0.1"
|
package/build.rs
ADDED
package/index.d.ts
ADDED
|
@@ -0,0 +1,648 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/* auto-generated by NAPI-RS */
|
|
5
|
+
|
|
6
|
+
export interface ArchiveFile {
|
|
7
|
+
path: string
|
|
8
|
+
created: bigint
|
|
9
|
+
modified: bigint
|
|
10
|
+
size: bigint
|
|
11
|
+
extra?: string
|
|
12
|
+
}
|
|
13
|
+
export type JsClient = Client
|
|
14
|
+
/** Represents a client for the Autonomi network. */
|
|
15
|
+
export declare class Client {
|
|
16
|
+
/**
|
|
17
|
+
* Initialize the client with default configuration.
|
|
18
|
+
*
|
|
19
|
+
* See `init_with_config`.
|
|
20
|
+
*/
|
|
21
|
+
static init(): Promise<JsClient>
|
|
22
|
+
/**
|
|
23
|
+
* Initialize a client that is configured to be local.
|
|
24
|
+
*
|
|
25
|
+
* See `init_with_config`.
|
|
26
|
+
*/
|
|
27
|
+
static initLocal(): Promise<JsClient>
|
|
28
|
+
/**
|
|
29
|
+
* Initialize a client that bootstraps from a list of peers.
|
|
30
|
+
*
|
|
31
|
+
* If any of the provided peers is a global address, the client will not be local.
|
|
32
|
+
*/
|
|
33
|
+
static initWithPeers(peers: Array<string>): Promise<Client>
|
|
34
|
+
evmNetwork(): JsNetwork
|
|
35
|
+
/** Get a chunk from the network. */
|
|
36
|
+
chunkGet(addr: JsChunkAddress): Promise<Buffer>
|
|
37
|
+
/**
|
|
38
|
+
* Manually upload a chunk to the network.
|
|
39
|
+
*
|
|
40
|
+
* It is recommended to use the `data_put` method instead to upload data.
|
|
41
|
+
*/
|
|
42
|
+
chunkPut(data: Buffer, paymentOption: JsPaymentOption): Promise<ChunkPut>
|
|
43
|
+
/** Get the cost of a chunk. */
|
|
44
|
+
chunkCost(addr: JsChunkAddress): Promise<string>
|
|
45
|
+
/** Fetches a GraphEntry from the network. */
|
|
46
|
+
graphEntryGet(address: JsGraphEntryAddress): Promise<JsGraphEntry>
|
|
47
|
+
/** Check if a graph_entry exists on the network */
|
|
48
|
+
graphEntryCheckExistance(address: JsGraphEntryAddress): Promise<boolean>
|
|
49
|
+
/** Manually puts a GraphEntry to the network. */
|
|
50
|
+
graphEntryPut(entry: JsGraphEntry, paymentOption: JsPaymentOption): Promise<GraphEntryPut>
|
|
51
|
+
/** Get the cost to create a GraphEntry */
|
|
52
|
+
graphEntryCost(key: JsPublicKey): Promise<string>
|
|
53
|
+
/** Get a pointer from the network */
|
|
54
|
+
pointerGet(address: JsPointerAddress): Promise<JsPointer>
|
|
55
|
+
/** Check if a pointer exists on the network */
|
|
56
|
+
pointerCheckExistance(address: JsPointerAddress): Promise<boolean>
|
|
57
|
+
/** Verify a pointer */
|
|
58
|
+
static pointerVerify(pointer: JsPointer): void
|
|
59
|
+
/** Manually store a pointer on the network */
|
|
60
|
+
pointerPut(pointer: JsPointer, paymentOption: JsPaymentOption): Promise<PointerPut>
|
|
61
|
+
/**
|
|
62
|
+
* Create a new pointer on the network.
|
|
63
|
+
*
|
|
64
|
+
* Make sure that the owner key is not already used for another pointer as each key is associated with one pointer
|
|
65
|
+
*/
|
|
66
|
+
pointerCreate(owner: JsSecretKey, target: JsPointerTarget, paymentOption: JsPaymentOption): Promise<PointerPut>
|
|
67
|
+
/**
|
|
68
|
+
* Update an existing pointer to point to a new target on the network.
|
|
69
|
+
*
|
|
70
|
+
* The pointer needs to be created first with Client::pointer_put.
|
|
71
|
+
* This operation is free as the pointer was already paid for at creation.
|
|
72
|
+
* Only the latest version of the pointer is kept on the Network,
|
|
73
|
+
* previous versions will be overwritten and unrecoverable.
|
|
74
|
+
*/
|
|
75
|
+
pointerUpdate(owner: JsSecretKey, target: JsPointerTarget): Promise<void>
|
|
76
|
+
/** Calculate the cost of storing a pointer */
|
|
77
|
+
pointerCost(key: JsPublicKey): Promise<string>
|
|
78
|
+
/** Get Scratchpad from the Network. A Scratchpad is stored at the owner's public key so we can derive the address from it. */
|
|
79
|
+
scratchpadGetFromPublicKey(publicKey: JsPublicKey): Promise<JsScratchpad>
|
|
80
|
+
/** Get Scratchpad from the Network */
|
|
81
|
+
scratchpadGet(address: JsScratchpadAddress): Promise<JsScratchpad>
|
|
82
|
+
/** Check if a scratchpad exists on the network */
|
|
83
|
+
scratchpadCheckExistance(address: JsScratchpadAddress): Promise<boolean>
|
|
84
|
+
/** Verify a scratchpad */
|
|
85
|
+
static scratchpadVerify(scratchpad: JsScratchpad): void
|
|
86
|
+
/** Manually store a scratchpad on the network */
|
|
87
|
+
scratchpadPut(scratchpad: JsScratchpad, paymentOption: JsPaymentOption): Promise<ScratchpadPut>
|
|
88
|
+
/**
|
|
89
|
+
* Create a new scratchpad to the network.
|
|
90
|
+
*
|
|
91
|
+
* Make sure that the owner key is not already used for another scratchpad as each key is associated with one scratchpad. The data will be encrypted with the owner key before being stored on the network. The content type is used to identify the type of data stored in the scratchpad, the choice is up to the caller.
|
|
92
|
+
*
|
|
93
|
+
* Returns the cost and the address of the scratchpad.
|
|
94
|
+
*/
|
|
95
|
+
scratchpadCreate(owner: JsSecretKey, contentType: bigint, initialData: Buffer, paymentOption: JsPaymentOption): Promise<ScratchpadPut>
|
|
96
|
+
/**
|
|
97
|
+
* Update an existing scratchpad to the network.
|
|
98
|
+
* The scratchpad needs to be created first with Client::scratchpad_create.
|
|
99
|
+
* This operation is free as the scratchpad was already paid for at creation.
|
|
100
|
+
* Only the latest version of the scratchpad is kept on the Network,
|
|
101
|
+
* previous versions will be overwritten and unrecoverable.
|
|
102
|
+
*/
|
|
103
|
+
scratchpadUpdate(owner: JsSecretKey, contentType: bigint, data: Buffer): Promise<void>
|
|
104
|
+
/** Get the cost of creating a new Scratchpad */
|
|
105
|
+
scratchpadCost(owner: JsPublicKey): Promise<string>
|
|
106
|
+
/** Fetch a blob of (private) data from the network */
|
|
107
|
+
dataGet(dataMap: JsDataMapChunk): Promise<Buffer>
|
|
108
|
+
/**
|
|
109
|
+
* Upload a piece of private data to the network. This data will be self-encrypted.
|
|
110
|
+
* The DataMapChunk is not uploaded to the network, keeping the data private.
|
|
111
|
+
*
|
|
112
|
+
* Returns the DataMapChunk containing the map to the encrypted chunks.
|
|
113
|
+
*/
|
|
114
|
+
dataPut(data: Buffer, paymentOption: JsPaymentOption): Promise<DataPutResult>
|
|
115
|
+
/** Fetch a blob of data from the network */
|
|
116
|
+
dataGetPublic(addr: JsDataAddress): Promise<Buffer>
|
|
117
|
+
/**
|
|
118
|
+
* Upload a piece of data to the network. This data is publicly accessible.
|
|
119
|
+
*
|
|
120
|
+
* Returns the Data Address at which the data was stored.
|
|
121
|
+
*/
|
|
122
|
+
dataPutPublic(data: Buffer, paymentOption: JsPaymentOption): Promise<DataPutPublicResult>
|
|
123
|
+
/** Get the estimated cost of storing a piece of data. */
|
|
124
|
+
dataCost(data: Buffer): Promise<string>
|
|
125
|
+
/** Fetch a PrivateArchive from the network */
|
|
126
|
+
archiveGet(addr: JsPrivateArchiveDataMap): Promise<JsPrivateArchive>
|
|
127
|
+
/** Upload a PrivateArchive to the network */
|
|
128
|
+
archivePut(archive: JsPrivateArchive, paymentOption: JsPaymentOption): Promise<ArchivePutResult>
|
|
129
|
+
/** Fetch an archive from the network */
|
|
130
|
+
archiveGetPublic(addr: JsArchiveAddress): Promise<JsPublicArchive>
|
|
131
|
+
/** Upload an archive to the network */
|
|
132
|
+
archivePutPublic(archive: JsPublicArchive, paymentOption: JsPaymentOption): Promise<ArchivePutPublicResult>
|
|
133
|
+
/** Get the cost to upload an archive */
|
|
134
|
+
archiveCost(archive: JsPublicArchive): Promise<string>
|
|
135
|
+
/** Download a private file from network to local file system */
|
|
136
|
+
fileDownload(dataMap: JsDataMapChunk, toDest: string): Promise<void>
|
|
137
|
+
/** Download a private directory from network to local file system */
|
|
138
|
+
dirDownload(archiveAccess: JsPrivateArchiveDataMap, toDest: string): Promise<void>
|
|
139
|
+
/**
|
|
140
|
+
* Upload the content of all files in a directory to the network.
|
|
141
|
+
* The directory is recursively walked and each file is uploaded to the network.
|
|
142
|
+
*
|
|
143
|
+
* The data maps of these (private) files are not uploaded but returned within
|
|
144
|
+
* the PrivateArchive return type.
|
|
145
|
+
*/
|
|
146
|
+
dirContentUpload(dirPath: string, paymentOption: JsPaymentOption): Promise<DirContentUpload>
|
|
147
|
+
/**
|
|
148
|
+
* Same as Client::dir_content_upload but also uploads the archive (privately) to the network.
|
|
149
|
+
*
|
|
150
|
+
* Returns the PrivateArchiveDataMap allowing the private archive to be downloaded from the network.
|
|
151
|
+
*/
|
|
152
|
+
dirUpload(dirPath: string, paymentOption: JsPaymentOption): Promise<DirUpload>
|
|
153
|
+
/**
|
|
154
|
+
* Upload the content of a private file to the network. Reads file, splits into
|
|
155
|
+
* chunks, uploads chunks, uploads datamap, returns DataMapChunk (pointing to the datamap)
|
|
156
|
+
*/
|
|
157
|
+
fileContentUpload(path: string, paymentOption: JsPaymentOption): Promise<FileContentUpload>
|
|
158
|
+
/** Download file from network to local file system */
|
|
159
|
+
fileDownloadPublic(dataAddr: JsDataAddress, toDest: string): Promise<void>
|
|
160
|
+
/** Download directory from network to local file system */
|
|
161
|
+
dirDownloadPublic(archiveAddr: JsArchiveAddress, toDest: string): Promise<void>
|
|
162
|
+
/**
|
|
163
|
+
* Upload the content of all files in a directory to the network. The directory is recursively walked and each file is uploaded to the network.
|
|
164
|
+
*
|
|
165
|
+
* The data maps of these files are uploaded on the network, making the individual files publicly available.
|
|
166
|
+
*
|
|
167
|
+
* This returns, but does not upload (!),the PublicArchive containing the data maps of the uploaded files.
|
|
168
|
+
*/
|
|
169
|
+
dirContentUploadPublic(dirPath: string, paymentOption: JsPaymentOption): Promise<DirContentUploadPublic>
|
|
170
|
+
/**
|
|
171
|
+
* Same as Client::dir_content_upload_public but also uploads the archive to the network.
|
|
172
|
+
*
|
|
173
|
+
* Returns the ArchiveAddress of the uploaded archive.
|
|
174
|
+
*/
|
|
175
|
+
dirUploadPublic(dirPath: string, paymentOption: JsPaymentOption): Promise<DirUploadPublic>
|
|
176
|
+
/**
|
|
177
|
+
* Upload the content of a file to the network. Reads file, splits into chunks,
|
|
178
|
+
* uploads chunks, uploads datamap, returns DataAddr (pointing to the datamap)
|
|
179
|
+
*/
|
|
180
|
+
fileContentUploadPublic(path: string, paymentOption: JsPaymentOption): Promise<FileContentUploadPublic>
|
|
181
|
+
/** Get the cost to upload a file/dir to the network. quick and dirty implementation, please refactor once files are cleanly implemented */
|
|
182
|
+
fileCost(path: string): Promise<string>
|
|
183
|
+
/** Get the user data from the vault */
|
|
184
|
+
getUserDataFromVault(secretKey: JsVaultSecretKey): Promise<JsUserData>
|
|
185
|
+
/**
|
|
186
|
+
* Put the user data to the vault
|
|
187
|
+
*
|
|
188
|
+
* Returns the total cost of the put operation
|
|
189
|
+
*/
|
|
190
|
+
putUserDataToVault(secretKey: JsVaultSecretKey, paymentOption: JsPaymentOption, userData: JsUserData): Promise<string>
|
|
191
|
+
/**
|
|
192
|
+
* Retrieves and returns a decrypted vault if one exists.
|
|
193
|
+
*
|
|
194
|
+
* Returns the content type of the bytes in the vault.
|
|
195
|
+
*/
|
|
196
|
+
fetchAndDecryptVault(secretKey: JsVaultSecretKey): Promise<FetchAndDecryptVault>
|
|
197
|
+
/**
|
|
198
|
+
* Get the cost of creating a new vault A quick estimation of cost:
|
|
199
|
+
* num_of_graph_entry * graph_entry_cost + num_of_scratchpad * scratchpad_cost
|
|
200
|
+
*/
|
|
201
|
+
vaultCost(owner: JsVaultSecretKey, maxSize: bigint): Promise<string>
|
|
202
|
+
/**
|
|
203
|
+
* Put data into the client’s VaultPacket
|
|
204
|
+
*
|
|
205
|
+
* Dynamically expand the vault capacity by paying for more space (Scratchpad) when needed.
|
|
206
|
+
*
|
|
207
|
+
* It is recommended to use the hash of the app name or unique identifier as the content type.
|
|
208
|
+
*/
|
|
209
|
+
writeBytesToVault(data: Buffer, paymentOption: JsPaymentOption, secretKey: JsVaultSecretKey, contentType: JsVaultContentType): Promise<string>
|
|
210
|
+
/**
|
|
211
|
+
* Get the register history, starting from the root to the latest entry.
|
|
212
|
+
*
|
|
213
|
+
* This returns a RegisterHistory that can be use to get the register values from the history.
|
|
214
|
+
*
|
|
215
|
+
* RegisterHistory::next can be used to get the values one by one, from the first to the latest entry.
|
|
216
|
+
* RegisterHistory::collect can be used to get all the register values from the history from the first to the latest entry.
|
|
217
|
+
*/
|
|
218
|
+
registerHistory(addr: JsRegisterAddress): JsRegisterHistory
|
|
219
|
+
/**
|
|
220
|
+
* Create a new register key from a SecretKey and a name.
|
|
221
|
+
*
|
|
222
|
+
* This derives a new SecretKey from the owner’s SecretKey using the name. Note that you will need to keep track of the names you used to create the register key.
|
|
223
|
+
*/
|
|
224
|
+
static registerKeyFromName(owner: JsSecretKey, name: string): JsSecretKey
|
|
225
|
+
/** Create a new RegisterValue from bytes, make sure the bytes are not longer than REGISTER_VALUE_SIZE */
|
|
226
|
+
static registerValueFromBytes(bytes: Uint8Array): Uint8Array
|
|
227
|
+
/**
|
|
228
|
+
* Create a new register with an initial value.
|
|
229
|
+
*
|
|
230
|
+
* Note that two payments are required, one for the underlying GraphEntry and one for the crate::Pointer
|
|
231
|
+
*/
|
|
232
|
+
registerCreate(owner: JsSecretKey, initialValue: Uint8Array, paymentOption: JsPaymentOption): Promise<RegisterCreate>
|
|
233
|
+
/**
|
|
234
|
+
* Update the value of a register.
|
|
235
|
+
* The register needs to be created first with Client::register_create
|
|
236
|
+
*/
|
|
237
|
+
registerUpdate(owner: JsSecretKey, newValue: Uint8Array, paymentOption: JsPaymentOption): Promise<string>
|
|
238
|
+
/** Get the current value of the register */
|
|
239
|
+
registerGet(addr: JsRegisterAddress): Promise<Uint8Array>
|
|
240
|
+
/** Get the cost of a register operation. Returns the cost of creation if it doesn’t exist, else returns the cost of an update */
|
|
241
|
+
registerCost(owner: JsPublicKey): Promise<string>
|
|
242
|
+
}
|
|
243
|
+
export declare class ChunkPut {
|
|
244
|
+
get cost(): string
|
|
245
|
+
get addr(): JsChunkAddress
|
|
246
|
+
}
|
|
247
|
+
export declare class GraphEntryPut {
|
|
248
|
+
get cost(): string
|
|
249
|
+
get addr(): JsGraphEntryAddress
|
|
250
|
+
}
|
|
251
|
+
export declare class ScratchpadPut {
|
|
252
|
+
get cost(): string
|
|
253
|
+
get addr(): JsScratchpadAddress
|
|
254
|
+
}
|
|
255
|
+
export declare class PointerPut {
|
|
256
|
+
get cost(): string
|
|
257
|
+
get addr(): JsPointerAddress
|
|
258
|
+
}
|
|
259
|
+
export declare class DataPutResult {
|
|
260
|
+
get cost(): string
|
|
261
|
+
get dataMap(): JsDataMapChunk
|
|
262
|
+
}
|
|
263
|
+
export declare class DataPutPublicResult {
|
|
264
|
+
get cost(): string
|
|
265
|
+
get addr(): JsDataAddress
|
|
266
|
+
}
|
|
267
|
+
export declare class ArchivePutResult {
|
|
268
|
+
get cost(): string
|
|
269
|
+
get dataMap(): JsPrivateArchiveDataMap
|
|
270
|
+
}
|
|
271
|
+
export declare class ArchivePutPublicResult {
|
|
272
|
+
get cost(): string
|
|
273
|
+
get addr(): JsDataAddress
|
|
274
|
+
}
|
|
275
|
+
export declare class DirContentUpload {
|
|
276
|
+
get cost(): string
|
|
277
|
+
get archive(): JsPrivateArchive
|
|
278
|
+
}
|
|
279
|
+
export declare class DirUpload {
|
|
280
|
+
get cost(): string
|
|
281
|
+
get dataMap(): JsDataMapChunk
|
|
282
|
+
}
|
|
283
|
+
export declare class FileContentUpload {
|
|
284
|
+
get cost(): string
|
|
285
|
+
get dataMap(): JsDataMapChunk
|
|
286
|
+
}
|
|
287
|
+
export declare class DirContentUploadPublic {
|
|
288
|
+
get cost(): string
|
|
289
|
+
get addr(): JsPublicArchive
|
|
290
|
+
}
|
|
291
|
+
export declare class DirUploadPublic {
|
|
292
|
+
get cost(): string
|
|
293
|
+
get addr(): JsArchiveAddress
|
|
294
|
+
}
|
|
295
|
+
export declare class FileContentUploadPublic {
|
|
296
|
+
get cost(): string
|
|
297
|
+
get addr(): JsPointerAddress
|
|
298
|
+
}
|
|
299
|
+
export declare class FetchAndDecryptVault {
|
|
300
|
+
get data(): Buffer
|
|
301
|
+
get contentType(): bigint
|
|
302
|
+
}
|
|
303
|
+
export declare class RegisterCreate {
|
|
304
|
+
get cost(): string
|
|
305
|
+
get addr(): JsRegisterAddress
|
|
306
|
+
}
|
|
307
|
+
export declare class GraphEntryDescendant {
|
|
308
|
+
get publicKey(): JsPublicKey
|
|
309
|
+
get content(): Uint8Array
|
|
310
|
+
}
|
|
311
|
+
export type JsXorName = XorName
|
|
312
|
+
/**
|
|
313
|
+
* A 256-bit number, viewed as a point in XOR space.
|
|
314
|
+
*
|
|
315
|
+
* This wraps an array of 32 bytes, i. e. a number between 0 and 2<sup>256</sup> - 1.
|
|
316
|
+
*
|
|
317
|
+
* XOR space is the space of these numbers, with the [XOR metric][1] as a notion of distance,
|
|
318
|
+
* i. e. the points with IDs `x` and `y` are considered to have distance `x xor y`.
|
|
319
|
+
*
|
|
320
|
+
* [1]: https://en.wikipedia.org/wiki/Kademlia#System_details
|
|
321
|
+
*/
|
|
322
|
+
export declare class XorName {
|
|
323
|
+
/** Generate a XorName for the given content. */
|
|
324
|
+
static fromContent(content: Uint8Array): JsXorName
|
|
325
|
+
/** Generate a random XorName */
|
|
326
|
+
static random(): JsXorName
|
|
327
|
+
}
|
|
328
|
+
export type JsChunkAddress = ChunkAddress
|
|
329
|
+
/**
|
|
330
|
+
* Address of a chunk.
|
|
331
|
+
*
|
|
332
|
+
* It is derived from the content of the chunk.
|
|
333
|
+
*/
|
|
334
|
+
export declare class ChunkAddress {
|
|
335
|
+
/** Creates a new ChunkAddress. */
|
|
336
|
+
constructor(xorName: XorName)
|
|
337
|
+
/** Returns the XorName. */
|
|
338
|
+
xorname(): XorName
|
|
339
|
+
/** Returns the hex string representation of the address. */
|
|
340
|
+
toHex(): string
|
|
341
|
+
/** Creates a new ChunkAddress from a hex string. */
|
|
342
|
+
static fromHex(hex: string): JsChunkAddress
|
|
343
|
+
}
|
|
344
|
+
export type JsGraphEntryAddress = GraphEntryAddress
|
|
345
|
+
/**
|
|
346
|
+
* Address of a `GraphEntry`.
|
|
347
|
+
*
|
|
348
|
+
* It is derived from the owner's unique public key
|
|
349
|
+
*/
|
|
350
|
+
export declare class GraphEntryAddress {
|
|
351
|
+
/** Creates a new GraphEntryAddress. */
|
|
352
|
+
constructor(owner: JsPublicKey)
|
|
353
|
+
/**
|
|
354
|
+
* Return the network name of the scratchpad.
|
|
355
|
+
* This is used to locate the scratchpad on the network.
|
|
356
|
+
*/
|
|
357
|
+
xorname(): XorName
|
|
358
|
+
/** Serialize this `GraphEntryAddress` into a hex-encoded string. */
|
|
359
|
+
toHex(): string
|
|
360
|
+
/** Parse a hex-encoded string into a `GraphEntryAddress`. */
|
|
361
|
+
static fromHex(hex: string): JsGraphEntryAddress
|
|
362
|
+
}
|
|
363
|
+
export type JsDataAddress = DataAddress
|
|
364
|
+
export declare class DataAddress {
|
|
365
|
+
/** Creates a new DataAddress. */
|
|
366
|
+
constructor(xorName: XorName)
|
|
367
|
+
/** Returns the XorName. */
|
|
368
|
+
xorname(): XorName
|
|
369
|
+
/** Returns the hex string representation of the address. */
|
|
370
|
+
toHex(): string
|
|
371
|
+
/** Creates a new DataAddress from a hex string. */
|
|
372
|
+
static fromHex(hex: string): JsDataAddress
|
|
373
|
+
}
|
|
374
|
+
export type JsArchiveAddress = ArchiveAddress
|
|
375
|
+
export declare class ArchiveAddress {
|
|
376
|
+
/** Creates a new ArchiveAddress. */
|
|
377
|
+
constructor(xorName: XorName)
|
|
378
|
+
/** Returns the XorName. */
|
|
379
|
+
xorname(): XorName
|
|
380
|
+
/** Returns the hex string representation of the address. */
|
|
381
|
+
toHex(): string
|
|
382
|
+
/** Creates a new ArchiveAddress from a hex string. */
|
|
383
|
+
static fromHex(hex: string): JsArchiveAddress
|
|
384
|
+
}
|
|
385
|
+
export type JsWallet = Wallet
|
|
386
|
+
/** A wallet for interacting with the network's payment system */
|
|
387
|
+
export declare class Wallet {
|
|
388
|
+
/** Creates a new Wallet based on the given Ethereum private key. It will fail with Error::PrivateKeyInvalid if private_key is invalid. */
|
|
389
|
+
static newFromPrivateKey(network: JsNetwork, privateKey: string): JsWallet
|
|
390
|
+
/** Returns a string representation of the wallet's address */
|
|
391
|
+
address(): string
|
|
392
|
+
/** Returns the raw balance of payment tokens in the wallet */
|
|
393
|
+
balance(): Promise<string>
|
|
394
|
+
/** Returns the current balance of gas tokens in the wallet */
|
|
395
|
+
balanceOfGas(): Promise<string>
|
|
396
|
+
}
|
|
397
|
+
export type JsPaymentOption = PaymentOption
|
|
398
|
+
/** Options for making payments on the network */
|
|
399
|
+
export declare class PaymentOption {
|
|
400
|
+
static fromWallet(wallet: Wallet): JsPaymentOption
|
|
401
|
+
static fromReceipt(): JsPaymentOption
|
|
402
|
+
}
|
|
403
|
+
export type JsNetwork = Network
|
|
404
|
+
export declare class Network {
|
|
405
|
+
constructor(local: boolean)
|
|
406
|
+
}
|
|
407
|
+
export type JsPublicKey = PublicKey
|
|
408
|
+
export declare class PublicKey {
|
|
409
|
+
/** Returns a byte string representation of the public key. */
|
|
410
|
+
toBytes(): Uint8Array
|
|
411
|
+
/** Returns the key with the given representation, if valid. */
|
|
412
|
+
static fromBytes(bytes: Uint8Array): JsPublicKey
|
|
413
|
+
/** Returns the hex string representation of the public key. */
|
|
414
|
+
toHex(): string
|
|
415
|
+
/** Creates a new PublicKey from a hex string. */
|
|
416
|
+
static fromHex(hex: string): JsPublicKey
|
|
417
|
+
}
|
|
418
|
+
export type JsSecretKey = SecretKey
|
|
419
|
+
export declare class SecretKey {
|
|
420
|
+
/** Generate a random SecretKey */
|
|
421
|
+
static random(): JsSecretKey
|
|
422
|
+
/** Returns the public key corresponding to this secret key. */
|
|
423
|
+
publicKey(): PublicKey
|
|
424
|
+
/** Converts the secret key to big endian bytes */
|
|
425
|
+
toBytes(): Uint8Array
|
|
426
|
+
/** Deserialize from big endian bytes */
|
|
427
|
+
static fromBytes(bytes: Uint8Array): JsSecretKey
|
|
428
|
+
/** Returns the hex string representation of the secret key. */
|
|
429
|
+
toHex(): string
|
|
430
|
+
/** Creates a new SecretKey from a hex string. */
|
|
431
|
+
static fromHex(hex: string): JsSecretKey
|
|
432
|
+
}
|
|
433
|
+
export type JsGraphEntry = GraphEntry
|
|
434
|
+
export declare class GraphEntry {
|
|
435
|
+
/** Create a new graph entry, signing it with the provided secret key. */
|
|
436
|
+
constructor(owner: SecretKey, parents: Array<PublicKey>, content: Uint8Array, descendants: Array<[PublicKey, Uint8Array]>)
|
|
437
|
+
/** Create a new graph entry with the signature already calculated. */
|
|
438
|
+
static newWithSignature(owner: PublicKey, parents: Array<PublicKey>, content: Uint8Array, descendants: Array<[PublicKey, Uint8Array]>, signature: Uint8Array): JsGraphEntry
|
|
439
|
+
/** Get the address of the graph entry */
|
|
440
|
+
address(): GraphEntryAddress
|
|
441
|
+
/** Get the owner of the graph entry */
|
|
442
|
+
owner(): PublicKey
|
|
443
|
+
/** Get the parents of the graph entry */
|
|
444
|
+
parents(): Array<PublicKey>
|
|
445
|
+
/** Get the content of the graph entry */
|
|
446
|
+
content(): Buffer
|
|
447
|
+
/** Get the descendants of the graph entry */
|
|
448
|
+
descendants(): Array<GraphEntryDescendant>
|
|
449
|
+
/** Get the bytes that were signed for this graph entry */
|
|
450
|
+
bytesForSignature(): Buffer
|
|
451
|
+
/** Verifies if the graph entry has a valid signature */
|
|
452
|
+
verifySignature(): boolean
|
|
453
|
+
/** Size of the graph entry */
|
|
454
|
+
size(): bigint
|
|
455
|
+
get signature(): Uint8Array
|
|
456
|
+
/** Returns true if the graph entry is too big */
|
|
457
|
+
isTooBig(): boolean
|
|
458
|
+
}
|
|
459
|
+
export type JsPointer = Pointer
|
|
460
|
+
export declare class Pointer {
|
|
461
|
+
/**
|
|
462
|
+
* Create a new pointer, signing it with the provided secret key.
|
|
463
|
+
* This pointer would be stored on the network at the provided key's public key.
|
|
464
|
+
* There can only be one pointer at a time at the same address (one per key).
|
|
465
|
+
*/
|
|
466
|
+
constructor(owner: SecretKey, counter: number, target: JsPointerTarget)
|
|
467
|
+
/** Get the address of the pointer */
|
|
468
|
+
address(): JsPointerAddress
|
|
469
|
+
/** Get the owner of the pointer */
|
|
470
|
+
owner(): PublicKey
|
|
471
|
+
/** Get the target of the pointer */
|
|
472
|
+
target(): JsPointerTarget
|
|
473
|
+
/** Get the bytes that were signed for this pointer */
|
|
474
|
+
bytesForSignature(): Buffer
|
|
475
|
+
/** Get the xorname of the pointer target */
|
|
476
|
+
xorname(): XorName
|
|
477
|
+
/**
|
|
478
|
+
* Get the counter of the pointer, the higher the counter, the more recent the pointer is
|
|
479
|
+
* Similarly to counter CRDTs only the latest version (highest counter) of the pointer is kept on the network
|
|
480
|
+
*/
|
|
481
|
+
counter(): number
|
|
482
|
+
/** Verifies if the pointer has a valid signature */
|
|
483
|
+
verifySignature(): boolean
|
|
484
|
+
/** Size of the pointer */
|
|
485
|
+
static size(): bigint
|
|
486
|
+
}
|
|
487
|
+
export type JsPointerTarget = PointerTarget
|
|
488
|
+
export declare class PointerTarget {
|
|
489
|
+
/** Returns the xorname of the target */
|
|
490
|
+
xorname(): XorName
|
|
491
|
+
/** Returns the hex string representation of the target */
|
|
492
|
+
toHex(): string
|
|
493
|
+
/** Creates a new PointerTarget from a ChunkAddress */
|
|
494
|
+
static ChunkAddress(addr: ChunkAddress): JsPointerTarget
|
|
495
|
+
/** Creates a new PointerTarget from a GraphEntryAddress */
|
|
496
|
+
static GraphEntryAddress(addr: GraphEntryAddress): JsPointerTarget
|
|
497
|
+
/** Creates a new PointerTarget from a PointerAddress */
|
|
498
|
+
static PointerAddress(addr: JsPointerAddress): JsPointerTarget
|
|
499
|
+
/** Creates a new PointerTarget from a ScratchpadAddress */
|
|
500
|
+
static ScratchpadAddress(addr: JsScratchpadAddress): JsPointerTarget
|
|
501
|
+
}
|
|
502
|
+
export type JsPointerAddress = PointerAddress
|
|
503
|
+
export declare class PointerAddress {
|
|
504
|
+
/** Creates a new PointerAddress. */
|
|
505
|
+
constructor(owner: PublicKey)
|
|
506
|
+
/**
|
|
507
|
+
* Return the network name of the pointer.
|
|
508
|
+
* This is used to locate the pointer on the network.
|
|
509
|
+
*/
|
|
510
|
+
xorname(): XorName
|
|
511
|
+
/** Return the owner. */
|
|
512
|
+
owner(): PublicKey
|
|
513
|
+
/** Serialize this PointerAddress into a hex-encoded string. */
|
|
514
|
+
toHex(): string
|
|
515
|
+
/** Parse a hex-encoded string into a PointerAddress. */
|
|
516
|
+
static fromHex(hex: string): JsPointerAddress
|
|
517
|
+
}
|
|
518
|
+
export type JsScratchpad = Scratchpad
|
|
519
|
+
export declare class Scratchpad {
|
|
520
|
+
/** Create a new scratchpad, signing it with the provided secret key. */
|
|
521
|
+
constructor(owner: SecretKey, dataEncoding: bigint, data: Buffer, counter: bigint)
|
|
522
|
+
/** Get the address of the scratchpad */
|
|
523
|
+
address(): JsScratchpadAddress
|
|
524
|
+
/** Get the owner of the scratchpad */
|
|
525
|
+
owner(): PublicKey
|
|
526
|
+
/** Get the data encoding (content type) of the scratchpad */
|
|
527
|
+
dataEncoding(): bigint
|
|
528
|
+
/** Decrypt the data of the scratchpad */
|
|
529
|
+
decryptData(key: SecretKey): Buffer
|
|
530
|
+
/** Get the counter of the scratchpad */
|
|
531
|
+
counter(): bigint
|
|
532
|
+
/** Verify the signature of the scratchpad */
|
|
533
|
+
verifySignature(): boolean
|
|
534
|
+
}
|
|
535
|
+
export type JsScratchpadAddress = ScratchpadAddress
|
|
536
|
+
export declare class ScratchpadAddress {
|
|
537
|
+
/** Creates a new ScratchpadAddress. */
|
|
538
|
+
constructor(owner: PublicKey)
|
|
539
|
+
/**
|
|
540
|
+
* Return the network name of the scratchpad.
|
|
541
|
+
* This is used to locate the scratchpad on the network.
|
|
542
|
+
*/
|
|
543
|
+
xorname(): XorName
|
|
544
|
+
/** Return the owner. */
|
|
545
|
+
owner(): PublicKey
|
|
546
|
+
/** Serialize this ScratchpadAddress into a hex-encoded string. */
|
|
547
|
+
toHex(): string
|
|
548
|
+
/** Parse a hex-encoded string into a ScratchpadAddress. */
|
|
549
|
+
static fromHex(hex: string): JsScratchpadAddress
|
|
550
|
+
}
|
|
551
|
+
export type JsDataMapChunk = DataMapChunk
|
|
552
|
+
export declare class DataMapChunk { }
|
|
553
|
+
export type JsPrivateArchiveDataMap = PrivateArchiveDataMap
|
|
554
|
+
export declare class PrivateArchiveDataMap {
|
|
555
|
+
/** Serialize this PrivateArchiveDataMap into a hex-encoded string. */
|
|
556
|
+
toHex(): string
|
|
557
|
+
/** Parse a hex-encoded string into a PrivateArchiveDataMap. */
|
|
558
|
+
static fromHex(hex: string): JsPrivateArchiveDataMap
|
|
559
|
+
}
|
|
560
|
+
export type JsPrivateArchive = PrivateArchive
|
|
561
|
+
export declare class PrivateArchive {
|
|
562
|
+
/** Create a new empty local archive */
|
|
563
|
+
constructor()
|
|
564
|
+
/** Add a file to a local archive */
|
|
565
|
+
addFile(path: string, dataMap: DataMapChunk, metadata: JsMetadata): void
|
|
566
|
+
/** Rename a file in an archive */
|
|
567
|
+
renameFile(oldPath: string, newPath: string): void
|
|
568
|
+
/** List all files in the archive with their metadata */
|
|
569
|
+
files(): Array<ArchiveFile>
|
|
570
|
+
/** List all data maps of the files in the archive */
|
|
571
|
+
dataMaps(): Array<DataMapChunk>
|
|
572
|
+
/** Convert the archive to bytes */
|
|
573
|
+
toBytes(): Buffer
|
|
574
|
+
/** Create an archive from bytes */
|
|
575
|
+
static fromBytes(data: Buffer): JsPrivateArchive
|
|
576
|
+
/** Merge with another archive */
|
|
577
|
+
merge(other: PrivateArchive): void
|
|
578
|
+
}
|
|
579
|
+
export type JsVaultSecretKey = VaultSecretKey
|
|
580
|
+
export declare class VaultSecretKey { }
|
|
581
|
+
export type JsUserData = UserData
|
|
582
|
+
export declare class UserData { }
|
|
583
|
+
export type JsVaultContentType = VaultContentType
|
|
584
|
+
export declare class VaultContentType { }
|
|
585
|
+
export type JsMetadata = Metadata
|
|
586
|
+
/** File metadata */
|
|
587
|
+
export declare class Metadata {
|
|
588
|
+
/** Create a new metadata struct with the current time as uploaded, created and modified. */
|
|
589
|
+
static newWithSize(size: bigint): JsMetadata
|
|
590
|
+
/** Create new metadata with all custom fields */
|
|
591
|
+
static withCustomFields(created: bigint, modified: bigint, size: bigint, extra?: string | undefined | null): JsMetadata
|
|
592
|
+
/** Create a new empty metadata struct with zeros */
|
|
593
|
+
static empty(): JsMetadata
|
|
594
|
+
/** Get the creation timestamp */
|
|
595
|
+
get created(): bigint
|
|
596
|
+
/** Get the modification timestamp */
|
|
597
|
+
get modified(): bigint
|
|
598
|
+
/** Get the file size */
|
|
599
|
+
get size(): bigint
|
|
600
|
+
/** Get the extra metadata */
|
|
601
|
+
get extra(): string | null
|
|
602
|
+
}
|
|
603
|
+
export type JsRegisterAddress = RegisterAddress
|
|
604
|
+
export declare class RegisterAddress {
|
|
605
|
+
/** Creates a new RegisterAddress. */
|
|
606
|
+
constructor(owner: PublicKey)
|
|
607
|
+
/** Get the owner of the register */
|
|
608
|
+
owner(): PublicKey
|
|
609
|
+
/** Get the underlying graph root address */
|
|
610
|
+
toUnderlyingGraphRoot(): GraphEntryAddress
|
|
611
|
+
/** Get the underlying head pointer address */
|
|
612
|
+
toUnderlyingHeadPointer(): PointerAddress
|
|
613
|
+
/** Serialize this RegisterAddress into a hex-encoded string. */
|
|
614
|
+
toHex(): string
|
|
615
|
+
/** Parse a hex-encoded string into a RegisterAddress. */
|
|
616
|
+
static fromHex(hex: string): JsRegisterAddress
|
|
617
|
+
}
|
|
618
|
+
export type JsRegisterHistory = RegisterHistory
|
|
619
|
+
export declare class RegisterHistory {
|
|
620
|
+
constructor()
|
|
621
|
+
/**
|
|
622
|
+
* Fetch and go to the next register value from the history.
|
|
623
|
+
*
|
|
624
|
+
* Returns null when we reached the end.
|
|
625
|
+
*/
|
|
626
|
+
next(): Promise<Uint8Array | null>
|
|
627
|
+
/** Get all the register values from the history, starting from the first to the latest entry */
|
|
628
|
+
collect(): Promise<Array<Uint8Array>>
|
|
629
|
+
}
|
|
630
|
+
export type JsPublicArchive = PublicArchive
|
|
631
|
+
export declare class PublicArchive {
|
|
632
|
+
/** Create a new empty local archive */
|
|
633
|
+
constructor()
|
|
634
|
+
/** Add a file to a local archive */
|
|
635
|
+
addFile(path: string, dataAddr: DataAddress, metadata: Metadata): void
|
|
636
|
+
/** Rename a file in an archive */
|
|
637
|
+
renameFile(oldPath: string, newPath: string): void
|
|
638
|
+
/** List all files in the archive with their metadata */
|
|
639
|
+
files(): Array<ArchiveFile>
|
|
640
|
+
/** List all data addresses of the files in the archive */
|
|
641
|
+
addresses(): Array<DataAddress>
|
|
642
|
+
/** Convert the archive to bytes */
|
|
643
|
+
toBytes(): Buffer
|
|
644
|
+
/** Create an archive from bytes */
|
|
645
|
+
static fromBytes(data: Buffer): JsPublicArchive
|
|
646
|
+
/** Merge with another archive */
|
|
647
|
+
merge(other: PublicArchive): void
|
|
648
|
+
}
|