@withautonomi/autonomi 0.4.3 → 0.5.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/src/lib.rs CHANGED
@@ -1,19 +1,6 @@
1
1
  use std::{path::PathBuf, str::FromStr};
2
2
 
3
- use autonomi::{
4
- chunk::DataMapChunk,
5
- client::{data::DataAddress, payment::PaymentOption},
6
- files::{
7
- archive_private::PrivateArchiveDataMap, archive_public::ArchiveAddress, Metadata,
8
- PrivateArchive, PublicArchive,
9
- },
10
- pointer::PointerTarget,
11
- register::{RegisterAddress, RegisterHistory},
12
- vault::{UserData, VaultContentType, VaultSecretKey},
13
- AttoTokens, Bytes, Chunk, ChunkAddress, Client, GraphEntry, GraphEntryAddress, Multiaddr,
14
- Network, Pointer, PointerAddress, PublicKey, Scratchpad, ScratchpadAddress, SecretKey,
15
- Signature, Wallet, XorName,
16
- };
3
+ use autonomi::{AttoTokens, Bytes, Chunk, Multiaddr, Signature};
17
4
 
18
5
  use napi::bindgen_prelude::*;
19
6
  use napi_derive::napi;
@@ -60,17 +47,17 @@ fn uint8_array_to_array<const LEN: usize>(value: Uint8Array, arg: &str) -> Resul
60
47
  }
61
48
 
62
49
  /// Represents a client for the Autonomi network.
63
- #[napi(js_name = "Client")]
64
- pub struct JsClient(Client);
50
+ #[napi]
51
+ pub struct Client(autonomi::Client);
65
52
 
66
53
  #[napi]
67
- impl JsClient {
54
+ impl Client {
68
55
  /// Initialize the client with default configuration.
69
56
  ///
70
57
  /// See `init_with_config`.
71
58
  #[napi(factory)]
72
59
  pub async fn init() -> Result<Self> {
73
- let client = Client::init().await.map_err(map_error)?;
60
+ let client = autonomi::Client::init().await.map_err(map_error)?;
74
61
 
75
62
  Ok(Self(client))
76
63
  }
@@ -80,7 +67,15 @@ impl JsClient {
80
67
  /// See `init_with_config`.
81
68
  #[napi(factory)]
82
69
  pub async fn init_local() -> Result<Self> {
83
- let client = Client::init_local().await.map_err(map_error)?;
70
+ let client = autonomi::Client::init_local().await.map_err(map_error)?;
71
+
72
+ Ok(Self(client))
73
+ }
74
+
75
+ /// Initialize a client that is configured to be connected to the alpha network.
76
+ #[napi(factory)]
77
+ pub async fn init_alpha() -> Result<Self> {
78
+ let client = autonomi::Client::init_alpha().await.map_err(map_error)?;
84
79
 
85
80
  Ok(Self(client))
86
81
  }
@@ -96,7 +91,9 @@ impl JsClient {
96
91
  .collect::<std::result::Result<Vec<Multiaddr>, _>>()
97
92
  .map_err(map_error)?;
98
93
 
99
- let client = Client::init_with_peers(peers).await.map_err(map_error)?;
94
+ let client = autonomi::Client::init_with_peers(peers)
95
+ .await
96
+ .map_err(map_error)?;
100
97
 
101
98
  Ok(Self(client))
102
99
  }
@@ -112,15 +109,15 @@ impl JsClient {
112
109
  // }
113
110
 
114
111
  #[napi]
115
- pub fn evm_network(&self) -> JsNetwork {
116
- JsNetwork(self.0.evm_network().clone())
112
+ pub fn evm_network(&self) -> Network {
113
+ Network(self.0.evm_network().clone())
117
114
  }
118
115
 
119
116
  // Chunks
120
117
 
121
118
  /// Get a chunk from the network.
122
119
  #[napi]
123
- pub async fn chunk_get(&self, addr: &JsChunkAddress) -> Result<Buffer> {
120
+ pub async fn chunk_get(&self, addr: &ChunkAddress) -> Result<Buffer> {
124
121
  let chunk = self.0.chunk_get(&addr.0).await.map_err(map_error)?;
125
122
 
126
123
  Ok(Buffer::from(chunk.value.to_vec()))
@@ -133,7 +130,7 @@ impl JsClient {
133
130
  pub async fn chunk_put(
134
131
  &self,
135
132
  data: Buffer,
136
- payment_option: &JsPaymentOption,
133
+ payment_option: &PaymentOption,
137
134
  ) -> Result<tuple_result::ChunkPut> {
138
135
  let chunk = Chunk::new(Bytes::from(data.as_ref().to_vec()));
139
136
 
@@ -148,38 +145,32 @@ impl JsClient {
148
145
 
149
146
  /// Get the cost of a chunk.
150
147
  #[napi]
151
- pub async fn chunk_cost(&self, addr: &JsChunkAddress) -> Result</* AttoTokens */ String> {
148
+ pub async fn chunk_cost(&self, addr: &ChunkAddress) -> Result</* AttoTokens */ String> {
152
149
  let cost = self.0.chunk_cost(&addr.0).await.map_err(map_error)?;
153
150
 
154
151
  Ok(cost.to_string())
155
152
  }
156
153
 
157
- // /// Upload chunks and retry failed uploads up to RETRY_ATTEMPTS times.
158
- // #[napi]
159
- // pub async fn upload_chunks_with_retries(&self, chunks: Vec<Chunk>, receipt: &Receipt) -> Vec<(Chunk, PutError)> {
160
- // todo!()
161
- // }
162
-
163
154
  // Graph entries
164
155
 
165
156
  /// Fetches a GraphEntry from the network.
166
157
  #[napi]
167
- pub async fn graph_entry_get(&self, address: &JsGraphEntryAddress) -> Result<JsGraphEntry> {
158
+ pub async fn graph_entry_get(&self, address: &GraphEntryAddress) -> Result<GraphEntry> {
168
159
  let graph_entry = self
169
160
  .0
170
161
  .graph_entry_get(&address.0)
171
162
  .await
172
163
  .map_err(map_error)?;
173
164
 
174
- Ok(JsGraphEntry(graph_entry))
165
+ Ok(GraphEntry(graph_entry))
175
166
  }
176
167
 
177
168
  /// Check if a graph_entry exists on the network
178
169
  #[napi]
179
- pub async fn graph_entry_check_existance(&self, address: &JsGraphEntryAddress) -> Result<bool> {
170
+ pub async fn graph_entry_check_existance(&self, address: &GraphEntryAddress) -> Result<bool> {
180
171
  let exists = self
181
172
  .0
182
- .graph_entry_check_existance(&address.0)
173
+ .graph_entry_check_existence(&address.0)
183
174
  .await
184
175
  .map_err(map_error)?;
185
176
 
@@ -190,9 +181,9 @@ impl JsClient {
190
181
  #[napi]
191
182
  pub async fn graph_entry_put(
192
183
  &self,
193
- entry: &JsGraphEntry,
194
- payment_option: &JsPaymentOption,
195
- ) -> Result</* (AttoTokens, JsGraphEntryAddress) */ tuple_result::GraphEntryPut> {
184
+ entry: &GraphEntry,
185
+ payment_option: &PaymentOption,
186
+ ) -> Result</* (AttoTokens, GraphEntryAddress) */ tuple_result::GraphEntryPut> {
196
187
  let (cost, addr) = self
197
188
  .0
198
189
  .graph_entry_put(entry.0.clone(), payment_option.0.clone())
@@ -204,7 +195,7 @@ impl JsClient {
204
195
 
205
196
  /// Get the cost to create a GraphEntry
206
197
  #[napi]
207
- pub async fn graph_entry_cost(&self, key: &JsPublicKey) -> Result</* AttoTokens */ String> {
198
+ pub async fn graph_entry_cost(&self, key: &PublicKey) -> Result</* AttoTokens */ String> {
208
199
  self.0
209
200
  .graph_entry_cost(&key.0)
210
201
  .await
@@ -216,36 +207,36 @@ impl JsClient {
216
207
 
217
208
  /// Get a pointer from the network
218
209
  #[napi]
219
- pub async fn pointer_get(&self, address: &JsPointerAddress) -> Result<JsPointer> {
210
+ pub async fn pointer_get(&self, address: &PointerAddress) -> Result<Pointer> {
220
211
  self.0
221
212
  .pointer_get(&address.0)
222
213
  .await
223
- .map(JsPointer)
214
+ .map(Pointer)
224
215
  .map_err(map_error)
225
216
  }
226
217
 
227
218
  /// Check if a pointer exists on the network
228
219
  #[napi]
229
- pub async fn pointer_check_existance(&self, address: &JsPointerAddress) -> Result<bool> {
220
+ pub async fn pointer_check_existance(&self, address: &PointerAddress) -> Result<bool> {
230
221
  self.0
231
- .pointer_check_existance(&address.0)
222
+ .pointer_check_existence(&address.0)
232
223
  .await
233
224
  .map_err(map_error)
234
225
  }
235
226
 
236
227
  /// Verify a pointer
237
228
  #[napi]
238
- pub fn pointer_verify(pointer: &JsPointer) -> Result<()> {
239
- Client::pointer_verify(&pointer.0).map_err(map_error)
229
+ pub fn pointer_verify(pointer: &Pointer) -> Result<()> {
230
+ autonomi::Client::pointer_verify(&pointer.0).map_err(map_error)
240
231
  }
241
232
 
242
233
  /// Manually store a pointer on the network
243
234
  #[napi]
244
235
  pub async fn pointer_put(
245
236
  &self,
246
- pointer: &JsPointer,
247
- payment_option: &JsPaymentOption,
248
- ) -> Result</* (AttoTokens, JsPointerAddress) */ tuple_result::PointerPut> {
237
+ pointer: &Pointer,
238
+ payment_option: &PaymentOption,
239
+ ) -> Result</* (AttoTokens, PointerAddress) */ tuple_result::PointerPut> {
249
240
  let (cost, addr) = self
250
241
  .0
251
242
  .pointer_put(pointer.0.clone(), payment_option.0.clone())
@@ -261,10 +252,10 @@ impl JsClient {
261
252
  #[napi]
262
253
  pub async fn pointer_create(
263
254
  &self,
264
- owner: &JsSecretKey,
265
- target: &JsPointerTarget,
266
- payment_option: &JsPaymentOption,
267
- ) -> Result</* (AttoTokens, JsPointerAddress) */ tuple_result::PointerPut> {
255
+ owner: &SecretKey,
256
+ target: &PointerTarget,
257
+ payment_option: &PaymentOption,
258
+ ) -> Result</* (AttoTokens, PointerAddress) */ tuple_result::PointerPut> {
268
259
  let (cost, addr) = self
269
260
  .0
270
261
  .pointer_create(&owner.0, target.0.clone(), payment_option.0.clone())
@@ -281,11 +272,7 @@ impl JsClient {
281
272
  /// Only the latest version of the pointer is kept on the Network,
282
273
  /// previous versions will be overwritten and unrecoverable.
283
274
  #[napi]
284
- pub async fn pointer_update(
285
- &self,
286
- owner: &JsSecretKey,
287
- target: &JsPointerTarget,
288
- ) -> Result<()> {
275
+ pub async fn pointer_update(&self, owner: &SecretKey, target: &PointerTarget) -> Result<()> {
289
276
  self.0
290
277
  .pointer_update(&owner.0, target.0.clone())
291
278
  .await
@@ -294,7 +281,7 @@ impl JsClient {
294
281
 
295
282
  /// Calculate the cost of storing a pointer
296
283
  #[napi]
297
- pub async fn pointer_cost(&self, key: &JsPublicKey) -> Result</* AttoTokens */ String> {
284
+ pub async fn pointer_cost(&self, key: &PublicKey) -> Result</* AttoTokens */ String> {
298
285
  let cost = self.0.pointer_cost(&key.0).await.map_err(map_error)?;
299
286
 
300
287
  Ok(cost.to_string())
@@ -306,47 +293,47 @@ impl JsClient {
306
293
  #[napi]
307
294
  pub async fn scratchpad_get_from_public_key(
308
295
  &self,
309
- public_key: &JsPublicKey,
310
- ) -> Result<JsScratchpad> {
296
+ public_key: &PublicKey,
297
+ ) -> Result<Scratchpad> {
311
298
  self.0
312
299
  .scratchpad_get_from_public_key(&public_key.0)
313
300
  .await
314
- .map(JsScratchpad)
301
+ .map(Scratchpad)
315
302
  .map_err(map_error)
316
303
  }
317
304
 
318
305
  /// Get Scratchpad from the Network
319
306
  #[napi]
320
- pub async fn scratchpad_get(&self, address: &JsScratchpadAddress) -> Result<JsScratchpad> {
307
+ pub async fn scratchpad_get(&self, address: &ScratchpadAddress) -> Result<Scratchpad> {
321
308
  self.0
322
309
  .scratchpad_get(&address.0)
323
310
  .await
324
- .map(JsScratchpad)
311
+ .map(Scratchpad)
325
312
  .map_err(map_error)
326
313
  }
327
314
 
328
315
  /// Check if a scratchpad exists on the network
329
316
  #[napi]
330
- pub async fn scratchpad_check_existance(&self, address: &JsScratchpadAddress) -> Result<bool> {
317
+ pub async fn scratchpad_check_existance(&self, address: &ScratchpadAddress) -> Result<bool> {
331
318
  self.0
332
- .scratchpad_check_existance(&address.0)
319
+ .scratchpad_check_existence(&address.0)
333
320
  .await
334
321
  .map_err(map_error)
335
322
  }
336
323
 
337
324
  /// Verify a scratchpad
338
325
  #[napi]
339
- pub fn scratchpad_verify(scratchpad: &JsScratchpad) -> Result<()> {
340
- Client::scratchpad_verify(&scratchpad.0).map_err(map_error)
326
+ pub fn scratchpad_verify(scratchpad: &Scratchpad) -> Result<()> {
327
+ autonomi::Client::scratchpad_verify(&scratchpad.0).map_err(map_error)
341
328
  }
342
329
 
343
330
  /// Manually store a scratchpad on the network
344
331
  #[napi]
345
332
  pub async fn scratchpad_put(
346
333
  &self,
347
- scratchpad: &JsScratchpad,
348
- payment_option: &JsPaymentOption,
349
- ) -> Result</* (AttoTokens, JsScratchpadAddress) */ tuple_result::ScratchpadPut> {
334
+ scratchpad: &Scratchpad,
335
+ payment_option: &PaymentOption,
336
+ ) -> Result</* (AttoTokens, ScratchpadAddress) */ tuple_result::ScratchpadPut> {
350
337
  let (cost, addr) = self
351
338
  .0
352
339
  .scratchpad_put(scratchpad.0.clone(), payment_option.0.clone())
@@ -364,11 +351,11 @@ impl JsClient {
364
351
  #[napi]
365
352
  pub async fn scratchpad_create(
366
353
  &self,
367
- owner: &JsSecretKey,
354
+ owner: &SecretKey,
368
355
  content_type: BigInt, // `u64`
369
356
  initial_data: Buffer,
370
- payment_option: &JsPaymentOption,
371
- ) -> Result</* (AttoTokens, JsScratchpadAddress) */ tuple_result::ScratchpadPut> {
357
+ payment_option: &PaymentOption,
358
+ ) -> Result</* (AttoTokens, ScratchpadAddress) */ tuple_result::ScratchpadPut> {
372
359
  let content_type = big_int_to_u64(content_type, "content_type")?;
373
360
 
374
361
  let (cost, addr) = self
@@ -393,7 +380,7 @@ impl JsClient {
393
380
  #[napi]
394
381
  pub async fn scratchpad_update(
395
382
  &self,
396
- owner: &JsSecretKey,
383
+ owner: &SecretKey,
397
384
  content_type: BigInt, // `u64`
398
385
  data: Buffer,
399
386
  ) -> Result<()> {
@@ -407,7 +394,7 @@ impl JsClient {
407
394
 
408
395
  /// Get the cost of creating a new Scratchpad
409
396
  #[napi]
410
- pub async fn scratchpad_cost(&self, owner: &JsPublicKey) -> Result</* AttoTokens */ String> {
397
+ pub async fn scratchpad_cost(&self, owner: &PublicKey) -> Result</* AttoTokens */ String> {
411
398
  let cost = self.0.scratchpad_cost(&owner.0).await.map_err(map_error)?;
412
399
 
413
400
  Ok(cost.to_string())
@@ -417,7 +404,7 @@ impl JsClient {
417
404
 
418
405
  /// Fetch a blob of (private) data from the network
419
406
  #[napi]
420
- pub async fn data_get(&self, data_map: &JsDataMapChunk) -> Result<Buffer> {
407
+ pub async fn data_get(&self, data_map: &DataMapChunk) -> Result<Buffer> {
421
408
  let data = self.0.data_get(&data_map.0).await.map_err(map_error)?;
422
409
 
423
410
  Ok(Buffer::from(data.as_ref()))
@@ -431,8 +418,8 @@ impl JsClient {
431
418
  pub async fn data_put(
432
419
  &self,
433
420
  data: Buffer,
434
- payment_option: &JsPaymentOption,
435
- ) -> Result</* (AttoTokens, JsDataMapChunk) */ tuple_result::DataPutResult> {
421
+ payment_option: &PaymentOption,
422
+ ) -> Result</* (AttoTokens, DataMapChunk) */ tuple_result::DataPutResult> {
436
423
  let data = Bytes::copy_from_slice(&data);
437
424
 
438
425
  let (cost, data_map) = self
@@ -446,7 +433,7 @@ impl JsClient {
446
433
 
447
434
  /// Fetch a blob of data from the network
448
435
  #[napi]
449
- pub async fn data_get_public(&self, addr: &JsDataAddress) -> Result<Buffer> {
436
+ pub async fn data_get_public(&self, addr: &DataAddress) -> Result<Buffer> {
450
437
  let data = self.0.data_get_public(&addr.0).await.map_err(map_error)?;
451
438
 
452
439
  Ok(Buffer::from(data.as_ref()))
@@ -459,8 +446,8 @@ impl JsClient {
459
446
  pub async fn data_put_public(
460
447
  &self,
461
448
  data: Buffer,
462
- payment_option: &JsPaymentOption,
463
- ) -> Result</* (AttoTokens, JsDataAddress) */ tuple_result::DataPutPublicResult> {
449
+ payment_option: &PaymentOption,
450
+ ) -> Result</* (AttoTokens, DataAddress) */ tuple_result::DataPutPublicResult> {
464
451
  let data = Bytes::copy_from_slice(&data);
465
452
 
466
453
  let (cost, addr) = self
@@ -488,19 +475,19 @@ impl JsClient {
488
475
 
489
476
  /// Fetch a PrivateArchive from the network
490
477
  #[napi]
491
- pub async fn archive_get(&self, addr: &JsPrivateArchiveDataMap) -> Result<JsPrivateArchive> {
478
+ pub async fn archive_get(&self, addr: &PrivateArchiveDataMap) -> Result<PrivateArchive> {
492
479
  let archive = self.0.archive_get(&addr.0).await.map_err(map_error)?;
493
480
 
494
- Ok(JsPrivateArchive(archive))
481
+ Ok(PrivateArchive(archive))
495
482
  }
496
483
 
497
484
  /// Upload a PrivateArchive to the network
498
485
  #[napi]
499
486
  pub async fn archive_put(
500
487
  &self,
501
- archive: &JsPrivateArchive,
502
- payment_option: &JsPaymentOption,
503
- ) -> Result</*(AttoTokens, JsPrivateArchiveDataMap)*/ tuple_result::ArchivePutResult> {
488
+ archive: &PrivateArchive,
489
+ payment_option: &PaymentOption,
490
+ ) -> Result</*(AttoTokens, PrivateArchiveDataMap)*/ tuple_result::ArchivePutResult> {
504
491
  let (cost, data_map) = self
505
492
  .0
506
493
  .archive_put(&archive.0, payment_option.0.clone())
@@ -514,23 +501,23 @@ impl JsClient {
514
501
 
515
502
  /// Fetch an archive from the network
516
503
  #[napi]
517
- pub async fn archive_get_public(&self, addr: &JsArchiveAddress) -> Result<JsPublicArchive> {
504
+ pub async fn archive_get_public(&self, addr: &ArchiveAddress) -> Result<PublicArchive> {
518
505
  let archive = self
519
506
  .0
520
507
  .archive_get_public(&addr.0)
521
508
  .await
522
509
  .map_err(map_error)?;
523
510
 
524
- Ok(JsPublicArchive(archive))
511
+ Ok(PublicArchive(archive))
525
512
  }
526
513
 
527
514
  /// Upload an archive to the network
528
515
  #[napi]
529
516
  pub async fn archive_put_public(
530
517
  &self,
531
- archive: &JsPublicArchive,
532
- payment_option: &JsPaymentOption,
533
- ) -> Result</* (AttoTokens, JsArchiveAddress) */ tuple_result::ArchivePutPublicResult> {
518
+ archive: &PublicArchive,
519
+ payment_option: &PaymentOption,
520
+ ) -> Result</* (AttoTokens, ArchiveAddress) */ tuple_result::ArchivePutPublicResult> {
534
521
  let (cost, addr) = self
535
522
  .0
536
523
  .archive_put_public(&archive.0, payment_option.0.clone())
@@ -542,7 +529,7 @@ impl JsClient {
542
529
 
543
530
  /// Get the cost to upload an archive
544
531
  #[napi]
545
- pub async fn archive_cost(&self, archive: &JsPublicArchive) -> Result</* AttoTokens */ String> {
532
+ pub async fn archive_cost(&self, archive: &PublicArchive) -> Result</* AttoTokens */ String> {
546
533
  let cost = self
547
534
  .0
548
535
  .archive_cost(&archive.0.clone())
@@ -558,7 +545,7 @@ impl JsClient {
558
545
  #[napi]
559
546
  pub async fn file_download(
560
547
  &self,
561
- data_map: &JsDataMapChunk,
548
+ data_map: &DataMapChunk,
562
549
  to_dest: /* PathBuf */ String,
563
550
  ) -> Result<()> {
564
551
  let to_dest = PathBuf::from(to_dest);
@@ -573,7 +560,7 @@ impl JsClient {
573
560
  #[napi]
574
561
  pub async fn dir_download(
575
562
  &self,
576
- archive_access: &JsPrivateArchiveDataMap,
563
+ archive_access: &PrivateArchiveDataMap,
577
564
  to_dest: /* PathBuf */ String,
578
565
  ) -> Result<()> {
579
566
  let to_dest = PathBuf::from(to_dest);
@@ -594,8 +581,8 @@ impl JsClient {
594
581
  pub async fn dir_content_upload(
595
582
  &self,
596
583
  dir_path: /* PathBuf */ String,
597
- payment_option: &JsPaymentOption,
598
- ) -> Result</* (AttoTokens, JsPrivateArchive) */ tuple_result::DirContentUpload> {
584
+ payment_option: &PaymentOption,
585
+ ) -> Result</* (AttoTokens, PrivateArchive) */ tuple_result::DirContentUpload> {
599
586
  let dir_path = PathBuf::from(dir_path);
600
587
 
601
588
  let (cost, archive) = self
@@ -614,8 +601,8 @@ impl JsClient {
614
601
  pub async fn dir_upload(
615
602
  &self,
616
603
  dir_path: /* PathBuf */ String,
617
- payment_option: &JsPaymentOption,
618
- ) -> Result</* (AttoTokens, JsPrivateArchiveDataMap) */ tuple_result::DirUpload> {
604
+ payment_option: &PaymentOption,
605
+ ) -> Result</* (AttoTokens, PrivateArchiveDataMap) */ tuple_result::DirUpload> {
619
606
  let dir_path = PathBuf::from(dir_path);
620
607
 
621
608
  let (cost, data_map) = self
@@ -633,8 +620,8 @@ impl JsClient {
633
620
  pub async fn file_content_upload(
634
621
  &self,
635
622
  path: /* PathBuf */ String,
636
- payment_option: &JsPaymentOption,
637
- ) -> Result</* (AttoTokens, JsDataMapChunk) */ tuple_result::FileContentUpload> {
623
+ payment_option: &PaymentOption,
624
+ ) -> Result</* (AttoTokens, DataMapChunk) */ tuple_result::FileContentUpload> {
638
625
  let path = PathBuf::from(path);
639
626
 
640
627
  let (cost, data_map) = self
@@ -650,7 +637,7 @@ impl JsClient {
650
637
  #[napi]
651
638
  pub async fn file_download_public(
652
639
  &self,
653
- data_addr: &JsDataAddress,
640
+ data_addr: &DataAddress,
654
641
  to_dest: /* PathBuf */ String,
655
642
  ) -> Result<()> {
656
643
  let to_dest = PathBuf::from(to_dest);
@@ -665,7 +652,7 @@ impl JsClient {
665
652
  #[napi]
666
653
  pub async fn dir_download_public(
667
654
  &self,
668
- archive_addr: &JsArchiveAddress,
655
+ archive_addr: &ArchiveAddress,
669
656
  to_dest: /* PathBuf */ String,
670
657
  ) -> Result<()> {
671
658
  let to_dest = PathBuf::from(to_dest);
@@ -685,8 +672,8 @@ impl JsClient {
685
672
  pub async fn dir_content_upload_public(
686
673
  &self,
687
674
  dir_path: /* PathBuf */ String,
688
- payment_option: &JsPaymentOption,
689
- ) -> Result</* (AttoTokens, JsPublicArchive) */ tuple_result::DirContentUploadPublic> {
675
+ payment_option: &PaymentOption,
676
+ ) -> Result</* (AttoTokens, PublicArchive) */ tuple_result::DirContentUploadPublic> {
690
677
  let dir_path = PathBuf::from(dir_path);
691
678
 
692
679
  let (cost, archive) = self
@@ -705,8 +692,8 @@ impl JsClient {
705
692
  pub async fn dir_upload_public(
706
693
  &self,
707
694
  dir_path: /* PathBuf */ String,
708
- payment_option: &JsPaymentOption,
709
- ) -> Result</* (AttoTokens, JsArchiveAddress) */ tuple_result::DirUploadPublic> {
695
+ payment_option: &PaymentOption,
696
+ ) -> Result</* (AttoTokens, ArchiveAddress) */ tuple_result::DirUploadPublic> {
710
697
  let dir_path = PathBuf::from(dir_path);
711
698
 
712
699
  let (cost, addr) = self
@@ -724,8 +711,8 @@ impl JsClient {
724
711
  pub async fn file_content_upload_public(
725
712
  &self,
726
713
  _path: /* PathBuf */ String,
727
- _payment_option: &JsPaymentOption,
728
- ) -> Result</* (AttoTokens, JsDataAddress) */ tuple_result::FileContentUploadPublic> {
714
+ _payment_option: &PaymentOption,
715
+ ) -> Result</* (AttoTokens, DataAddress) */ tuple_result::FileContentUploadPublic> {
729
716
  todo!()
730
717
  }
731
718
 
@@ -745,14 +732,11 @@ impl JsClient {
745
732
 
746
733
  /// Get the user data from the vault
747
734
  #[napi]
748
- pub async fn get_user_data_from_vault(
749
- &self,
750
- secret_key: &JsVaultSecretKey,
751
- ) -> Result<JsUserData> {
735
+ pub async fn get_user_data_from_vault(&self, secret_key: &VaultSecretKey) -> Result<UserData> {
752
736
  self.0
753
737
  .get_user_data_from_vault(&secret_key.0)
754
738
  .await
755
- .map(JsUserData)
739
+ .map(UserData)
756
740
  .map_err(map_error)
757
741
  }
758
742
 
@@ -762,9 +746,9 @@ impl JsClient {
762
746
  #[napi]
763
747
  pub async fn put_user_data_to_vault(
764
748
  &self,
765
- secret_key: &JsVaultSecretKey,
766
- payment_option: &JsPaymentOption,
767
- user_data: &JsUserData,
749
+ secret_key: &VaultSecretKey,
750
+ payment_option: &PaymentOption,
751
+ user_data: &UserData,
768
752
  ) -> Result</* AttoTokens */ String> {
769
753
  self.0
770
754
  .put_user_data_to_vault(&secret_key.0, payment_option.0.clone(), user_data.0.clone())
@@ -779,8 +763,8 @@ impl JsClient {
779
763
  #[napi]
780
764
  pub async fn fetch_and_decrypt_vault(
781
765
  &self,
782
- secret_key: &JsVaultSecretKey,
783
- ) -> Result</* (Bytes, JsVaultContentType) */ tuple_result::FetchAndDecryptVault> {
766
+ secret_key: &VaultSecretKey,
767
+ ) -> Result</* (Bytes, VaultContentType) */ tuple_result::FetchAndDecryptVault> {
784
768
  let (data, content_type) = self
785
769
  .0
786
770
  .fetch_and_decrypt_vault(&secret_key.0)
@@ -795,7 +779,7 @@ impl JsClient {
795
779
  #[napi]
796
780
  pub async fn vault_cost(
797
781
  &self,
798
- owner: &JsVaultSecretKey,
782
+ owner: &VaultSecretKey,
799
783
  max_size: /* u64 */ BigInt,
800
784
  ) -> Result</* AttoTokens */ String> {
801
785
  let max_size = big_int_to_u64(max_size, "max_size")?;
@@ -809,7 +793,7 @@ impl JsClient {
809
793
  Ok(cost.to_string())
810
794
  }
811
795
 
812
- /// Put data into the clients VaultPacket
796
+ /// Put data into the client's VaultPacket
813
797
  ///
814
798
  /// Dynamically expand the vault capacity by paying for more space (Scratchpad) when needed.
815
799
  ///
@@ -819,9 +803,9 @@ impl JsClient {
819
803
  pub async fn write_bytes_to_vault(
820
804
  &self,
821
805
  data: Buffer,
822
- payment_option: &JsPaymentOption,
823
- secret_key: &JsVaultSecretKey,
824
- content_type: &JsVaultContentType,
806
+ payment_option: &PaymentOption,
807
+ secret_key: &VaultSecretKey,
808
+ content_type: &VaultContentType,
825
809
  ) -> Result</* AttoTokens */ String> {
826
810
  let data = Bytes::copy_from_slice(&data);
827
811
 
@@ -846,25 +830,25 @@ impl JsClient {
846
830
  /// RegisterHistory::next can be used to get the values one by one, from the first to the latest entry.
847
831
  /// RegisterHistory::collect can be used to get all the register values from the history from the first to the latest entry.
848
832
  #[napi]
849
- pub fn register_history(&self, addr: &JsRegisterAddress) -> JsRegisterHistory {
833
+ pub fn register_history(&self, addr: &RegisterAddress) -> RegisterHistory {
850
834
  let history = self.0.register_history(&addr.0);
851
835
 
852
- JsRegisterHistory(Mutex::new(history))
836
+ RegisterHistory(Mutex::new(history))
853
837
  }
854
838
 
855
839
  /// Create a new register key from a SecretKey and a name.
856
840
  ///
857
- /// This derives a new SecretKey from the owners SecretKey using the name. Note that you will need to keep track of the names you used to create the register key.
841
+ /// 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.
858
842
  #[napi]
859
- pub fn register_key_from_name(owner: &JsSecretKey, name: String) -> JsSecretKey {
860
- let key = Client::register_key_from_name(&owner.0, &name);
861
- JsSecretKey(key)
843
+ pub fn register_key_from_name(owner: &SecretKey, name: String) -> SecretKey {
844
+ let key = autonomi::Client::register_key_from_name(&owner.0, &name);
845
+ SecretKey(key)
862
846
  }
863
847
 
864
848
  /// Create a new RegisterValue from bytes, make sure the bytes are not longer than REGISTER_VALUE_SIZE
865
849
  #[napi]
866
- pub fn register_value_from_bytes(bytes: &[u8]) -> Result</* JsRegisterValue */ Uint8Array> {
867
- Client::register_value_from_bytes(bytes)
850
+ pub fn register_value_from_bytes(bytes: &[u8]) -> Result</* RegisterValue */ Uint8Array> {
851
+ autonomi::Client::register_value_from_bytes(bytes)
868
852
  .map(Uint8Array::from)
869
853
  .map_err(map_error)
870
854
  }
@@ -875,10 +859,10 @@ impl JsClient {
875
859
  #[napi]
876
860
  pub async fn register_create(
877
861
  &self,
878
- owner: &JsSecretKey,
862
+ owner: &SecretKey,
879
863
  initial_value: /* RegisterValue */ Uint8Array,
880
- payment_option: &JsPaymentOption,
881
- ) -> Result</* (AttoTokens, JsRegisterAddress) */ tuple_result::RegisterCreate> {
864
+ payment_option: &PaymentOption,
865
+ ) -> Result</* (AttoTokens, RegisterAddress) */ tuple_result::RegisterCreate> {
882
866
  let initial_value: [u8; 32] = uint8_array_to_array(initial_value, "initial_value")?;
883
867
 
884
868
  let (cost, addr) = self
@@ -892,13 +876,13 @@ impl JsClient {
892
876
 
893
877
  /// Update the value of a register.
894
878
  ////
895
- /// The register needs to be created first with Client::register_create
879
+ /// The register needs to be created first with autonomi::Client::register_create
896
880
  #[napi]
897
881
  pub async fn register_update(
898
882
  &self,
899
- owner: &JsSecretKey,
883
+ owner: &SecretKey,
900
884
  new_value: /* RegisterValue */ Uint8Array,
901
- payment_option: &JsPaymentOption,
885
+ payment_option: &PaymentOption,
902
886
  ) -> Result</* AttoTokens */ String> {
903
887
  let new_value: [u8; 32] = uint8_array_to_array(new_value, "new_value")?;
904
888
  self.0
@@ -912,8 +896,8 @@ impl JsClient {
912
896
  #[napi]
913
897
  pub async fn register_get(
914
898
  &self,
915
- addr: &JsRegisterAddress,
916
- ) -> Result</* JsRegisterValue */ Uint8Array> {
899
+ addr: &RegisterAddress,
900
+ ) -> Result</* RegisterValue */ Uint8Array> {
917
901
  self.0
918
902
  .register_get(&addr.0)
919
903
  .await
@@ -921,9 +905,9 @@ impl JsClient {
921
905
  .map_err(map_error)
922
906
  }
923
907
 
924
- /// Get the cost of a register operation. Returns the cost of creation if it doesnt exist, else returns the cost of an update
908
+ /// Get the cost of a register operation. Returns the cost of creation if it doesn't exist, else returns the cost of an update
925
909
  #[napi]
926
- pub async fn register_cost(&self, owner: &JsPublicKey) -> Result</* AttoTokens */ String> {
910
+ pub async fn register_cost(&self, owner: &PublicKey) -> Result</* AttoTokens */ String> {
927
911
  let cost = self
928
912
  .0
929
913
  .register_cost(&owner.0.clone())
@@ -956,14 +940,14 @@ impl JsClient {
956
940
  // }
957
941
  }
958
942
 
943
+ // These types exists because NAPI-RS does not support returning tuples.
959
944
  pub mod tuple_result {
960
945
  use super::*;
961
946
 
962
- // This type exists because NAPI-RS does not support returning tuples.
963
947
  #[napi]
964
948
  pub struct ChunkPut {
965
949
  pub(crate) cost: AttoTokens,
966
- pub(crate) addr: ChunkAddress, // Can't be `JsChunkAddress` as NAPI-RS expects a reference in that case.
950
+ pub(crate) addr: autonomi::ChunkAddress, // Can not be `ChunkAddress` as NAPI-RS expects a reference in that case.
967
951
  }
968
952
  #[napi]
969
953
  impl ChunkPut {
@@ -972,15 +956,15 @@ pub mod tuple_result {
972
956
  self.cost.to_string()
973
957
  }
974
958
  #[napi(getter)]
975
- pub fn addr(&self) -> JsChunkAddress {
976
- JsChunkAddress(self.addr)
959
+ pub fn addr(&self) -> ChunkAddress {
960
+ ChunkAddress(self.addr)
977
961
  }
978
962
  }
979
963
 
980
964
  #[napi]
981
965
  pub struct GraphEntryPut {
982
966
  pub(crate) cost: AttoTokens,
983
- pub(crate) addr: GraphEntryAddress,
967
+ pub(crate) addr: autonomi::GraphEntryAddress,
984
968
  }
985
969
  #[napi]
986
970
  impl GraphEntryPut {
@@ -989,15 +973,15 @@ pub mod tuple_result {
989
973
  self.cost.to_string()
990
974
  }
991
975
  #[napi(getter)]
992
- pub fn addr(&self) -> JsGraphEntryAddress {
993
- JsGraphEntryAddress(self.addr)
976
+ pub fn addr(&self) -> GraphEntryAddress {
977
+ GraphEntryAddress(self.addr)
994
978
  }
995
979
  }
996
980
 
997
981
  #[napi]
998
982
  pub struct ScratchpadPut {
999
983
  pub(crate) cost: AttoTokens,
1000
- pub(crate) addr: ScratchpadAddress,
984
+ pub(crate) addr: autonomi::ScratchpadAddress,
1001
985
  }
1002
986
  #[napi]
1003
987
  impl ScratchpadPut {
@@ -1006,15 +990,15 @@ pub mod tuple_result {
1006
990
  self.cost.to_string()
1007
991
  }
1008
992
  #[napi(getter)]
1009
- pub fn addr(&self) -> JsScratchpadAddress {
1010
- JsScratchpadAddress(self.addr)
993
+ pub fn addr(&self) -> ScratchpadAddress {
994
+ ScratchpadAddress(self.addr)
1011
995
  }
1012
996
  }
1013
997
 
1014
998
  #[napi]
1015
999
  pub struct PointerPut {
1016
1000
  pub(crate) cost: AttoTokens,
1017
- pub(crate) addr: PointerAddress,
1001
+ pub(crate) addr: autonomi::PointerAddress,
1018
1002
  }
1019
1003
  #[napi]
1020
1004
  impl PointerPut {
@@ -1023,15 +1007,15 @@ pub mod tuple_result {
1023
1007
  self.cost.to_string()
1024
1008
  }
1025
1009
  #[napi(getter)]
1026
- pub fn addr(&self) -> JsPointerAddress {
1027
- JsPointerAddress(self.addr)
1010
+ pub fn addr(&self) -> PointerAddress {
1011
+ PointerAddress(self.addr)
1028
1012
  }
1029
1013
  }
1030
1014
 
1031
1015
  #[napi]
1032
1016
  pub struct DataPutResult {
1033
1017
  pub(crate) cost: AttoTokens,
1034
- pub(crate) data_map: DataMapChunk,
1018
+ pub(crate) data_map: autonomi::data::private::DataMapChunk,
1035
1019
  }
1036
1020
  #[napi]
1037
1021
  impl DataPutResult {
@@ -1040,15 +1024,15 @@ pub mod tuple_result {
1040
1024
  self.cost.to_string()
1041
1025
  }
1042
1026
  #[napi(getter)]
1043
- pub fn data_map(&self) -> JsDataMapChunk {
1044
- JsDataMapChunk(self.data_map.clone())
1027
+ pub fn data_map(&self) -> DataMapChunk {
1028
+ DataMapChunk(self.data_map.clone())
1045
1029
  }
1046
1030
  }
1047
1031
 
1048
1032
  #[napi]
1049
1033
  pub struct DataPutPublicResult {
1050
1034
  pub(crate) cost: AttoTokens,
1051
- pub(crate) addr: DataAddress,
1035
+ pub(crate) addr: autonomi::data::DataAddress,
1052
1036
  }
1053
1037
  #[napi]
1054
1038
  impl DataPutPublicResult {
@@ -1057,15 +1041,15 @@ pub mod tuple_result {
1057
1041
  self.cost.to_string()
1058
1042
  }
1059
1043
  #[napi(getter)]
1060
- pub fn addr(&self) -> JsDataAddress {
1061
- JsDataAddress(self.addr)
1044
+ pub fn addr(&self) -> DataAddress {
1045
+ DataAddress(self.addr)
1062
1046
  }
1063
1047
  }
1064
1048
 
1065
1049
  #[napi]
1066
1050
  pub struct ArchivePutResult {
1067
1051
  pub(crate) cost: AttoTokens,
1068
- pub(crate) data_map: PrivateArchiveDataMap,
1052
+ pub(crate) data_map: autonomi::files::archive_private::PrivateArchiveDataMap,
1069
1053
  }
1070
1054
  #[napi]
1071
1055
  impl ArchivePutResult {
@@ -1074,15 +1058,15 @@ pub mod tuple_result {
1074
1058
  self.cost.to_string()
1075
1059
  }
1076
1060
  #[napi(getter)]
1077
- pub fn data_map(&self) -> JsPrivateArchiveDataMap {
1078
- JsPrivateArchiveDataMap(self.data_map.clone())
1061
+ pub fn data_map(&self) -> PrivateArchiveDataMap {
1062
+ PrivateArchiveDataMap(self.data_map.clone())
1079
1063
  }
1080
1064
  }
1081
1065
 
1082
1066
  #[napi]
1083
1067
  pub struct ArchivePutPublicResult {
1084
1068
  pub(crate) cost: AttoTokens,
1085
- pub(crate) addr: DataAddress,
1069
+ pub(crate) addr: autonomi::data::DataAddress,
1086
1070
  }
1087
1071
  #[napi]
1088
1072
  impl ArchivePutPublicResult {
@@ -1091,15 +1075,15 @@ pub mod tuple_result {
1091
1075
  self.cost.to_string()
1092
1076
  }
1093
1077
  #[napi(getter)]
1094
- pub fn addr(&self) -> JsDataAddress {
1095
- JsDataAddress(self.addr)
1078
+ pub fn addr(&self) -> DataAddress {
1079
+ DataAddress(self.addr)
1096
1080
  }
1097
1081
  }
1098
1082
 
1099
1083
  #[napi]
1100
1084
  pub struct DirContentUpload {
1101
1085
  pub(crate) cost: AttoTokens,
1102
- pub(crate) archive: PrivateArchive,
1086
+ pub(crate) archive: autonomi::files::PrivateArchive,
1103
1087
  }
1104
1088
  #[napi]
1105
1089
  impl DirContentUpload {
@@ -1108,15 +1092,15 @@ pub mod tuple_result {
1108
1092
  self.cost.to_string()
1109
1093
  }
1110
1094
  #[napi(getter)]
1111
- pub fn archive(&self) -> JsPrivateArchive {
1112
- JsPrivateArchive(self.archive.clone())
1095
+ pub fn archive(&self) -> PrivateArchive {
1096
+ PrivateArchive(self.archive.clone())
1113
1097
  }
1114
1098
  }
1115
1099
 
1116
1100
  #[napi]
1117
1101
  pub struct DirUpload {
1118
1102
  pub(crate) cost: AttoTokens,
1119
- pub(crate) data_map: DataMapChunk,
1103
+ pub(crate) data_map: autonomi::data::private::DataMapChunk,
1120
1104
  }
1121
1105
  #[napi]
1122
1106
  impl DirUpload {
@@ -1125,15 +1109,15 @@ pub mod tuple_result {
1125
1109
  self.cost.to_string()
1126
1110
  }
1127
1111
  #[napi(getter)]
1128
- pub fn data_map(&self) -> JsDataMapChunk {
1129
- JsDataMapChunk(self.data_map.clone())
1112
+ pub fn data_map(&self) -> DataMapChunk {
1113
+ DataMapChunk(self.data_map.clone())
1130
1114
  }
1131
1115
  }
1132
1116
 
1133
1117
  #[napi]
1134
1118
  pub struct FileContentUpload {
1135
1119
  pub(crate) cost: AttoTokens,
1136
- pub(crate) data_map: DataMapChunk,
1120
+ pub(crate) data_map: autonomi::data::private::DataMapChunk,
1137
1121
  }
1138
1122
  #[napi]
1139
1123
  impl FileContentUpload {
@@ -1142,15 +1126,15 @@ pub mod tuple_result {
1142
1126
  self.cost.to_string()
1143
1127
  }
1144
1128
  #[napi(getter)]
1145
- pub fn data_map(&self) -> JsDataMapChunk {
1146
- JsDataMapChunk(self.data_map.clone())
1129
+ pub fn data_map(&self) -> DataMapChunk {
1130
+ DataMapChunk(self.data_map.clone())
1147
1131
  }
1148
1132
  }
1149
1133
 
1150
1134
  #[napi]
1151
1135
  pub struct DirContentUploadPublic {
1152
1136
  pub(crate) cost: AttoTokens,
1153
- pub(crate) archive: PublicArchive,
1137
+ pub(crate) archive: autonomi::files::PublicArchive,
1154
1138
  }
1155
1139
  #[napi]
1156
1140
  impl DirContentUploadPublic {
@@ -1159,15 +1143,15 @@ pub mod tuple_result {
1159
1143
  self.cost.to_string()
1160
1144
  }
1161
1145
  #[napi(getter)]
1162
- pub fn addr(&self) -> JsPublicArchive {
1163
- JsPublicArchive(self.archive.clone())
1146
+ pub fn addr(&self) -> PublicArchive {
1147
+ PublicArchive(self.archive.clone())
1164
1148
  }
1165
1149
  }
1166
1150
 
1167
1151
  #[napi]
1168
1152
  pub struct DirUploadPublic {
1169
1153
  pub(crate) cost: AttoTokens,
1170
- pub(crate) addr: ArchiveAddress,
1154
+ pub(crate) addr: autonomi::files::archive_public::ArchiveAddress,
1171
1155
  }
1172
1156
  #[napi]
1173
1157
  impl DirUploadPublic {
@@ -1176,15 +1160,15 @@ pub mod tuple_result {
1176
1160
  self.cost.to_string()
1177
1161
  }
1178
1162
  #[napi(getter)]
1179
- pub fn addr(&self) -> JsArchiveAddress {
1180
- JsArchiveAddress(self.addr)
1163
+ pub fn addr(&self) -> ArchiveAddress {
1164
+ ArchiveAddress(self.addr)
1181
1165
  }
1182
1166
  }
1183
1167
 
1184
1168
  #[napi]
1185
1169
  pub struct FileContentUploadPublic {
1186
1170
  pub(crate) cost: AttoTokens,
1187
- pub(crate) addr: PointerAddress,
1171
+ pub(crate) addr: autonomi::PointerAddress,
1188
1172
  }
1189
1173
  #[napi]
1190
1174
  impl FileContentUploadPublic {
@@ -1193,15 +1177,15 @@ pub mod tuple_result {
1193
1177
  self.cost.to_string()
1194
1178
  }
1195
1179
  #[napi(getter)]
1196
- pub fn addr(&self) -> JsPointerAddress {
1197
- JsPointerAddress(self.addr)
1180
+ pub fn addr(&self) -> PointerAddress {
1181
+ PointerAddress(self.addr)
1198
1182
  }
1199
1183
  }
1200
1184
 
1201
1185
  #[napi]
1202
1186
  pub struct FetchAndDecryptVault {
1203
1187
  pub(crate) data: Bytes,
1204
- pub(crate) content_type: VaultContentType,
1188
+ pub(crate) content_type: autonomi::vault::VaultContentType,
1205
1189
  }
1206
1190
  #[napi]
1207
1191
  impl FetchAndDecryptVault {
@@ -1218,7 +1202,7 @@ pub mod tuple_result {
1218
1202
  #[napi]
1219
1203
  pub struct RegisterCreate {
1220
1204
  pub(crate) cost: AttoTokens,
1221
- pub(crate) addr: RegisterAddress,
1205
+ pub(crate) addr: autonomi::register::RegisterAddress,
1222
1206
  }
1223
1207
  #[napi]
1224
1208
  impl RegisterCreate {
@@ -1227,21 +1211,21 @@ pub mod tuple_result {
1227
1211
  self.cost.to_string()
1228
1212
  }
1229
1213
  #[napi(getter)]
1230
- pub fn addr(&self) -> JsRegisterAddress {
1231
- JsRegisterAddress(self.addr)
1214
+ pub fn addr(&self) -> RegisterAddress {
1215
+ RegisterAddress(self.addr)
1232
1216
  }
1233
1217
  }
1234
1218
 
1235
1219
  #[napi]
1236
1220
  pub struct GraphEntryDescendant {
1237
- pub(crate) public_key: PublicKey,
1221
+ pub(crate) public_key: autonomi::PublicKey,
1238
1222
  pub(crate) content: [u8; 32],
1239
1223
  }
1240
1224
  #[napi]
1241
1225
  impl GraphEntryDescendant {
1242
1226
  #[napi(getter)]
1243
- pub fn public_key(&self) -> JsPublicKey {
1244
- JsPublicKey(self.public_key)
1227
+ pub fn public_key(&self) -> PublicKey {
1228
+ PublicKey(self.public_key)
1245
1229
  }
1246
1230
  #[napi(getter)]
1247
1231
  pub fn content(&self) -> Uint8Array {
@@ -1267,41 +1251,41 @@ pub mod tuple_result {
1267
1251
  /// i. e. the points with IDs `x` and `y` are considered to have distance `x xor y`.
1268
1252
  ///
1269
1253
  /// [1]: https://en.wikipedia.org/wiki/Kademlia#System_details
1270
- #[napi(js_name = "XorName")]
1271
- pub struct JsXorName(XorName);
1272
1254
  #[napi]
1273
- impl JsXorName {
1255
+ pub struct XorName(autonomi::XorName);
1256
+ #[napi]
1257
+ impl XorName {
1274
1258
  /// Generate a XorName for the given content.
1275
1259
  #[napi(factory)]
1276
1260
  pub fn from_content(content: &[u8]) -> Self {
1277
- Self(XorName::from_content_parts(&[content]))
1261
+ Self(autonomi::XorName::from_content_parts(&[content]))
1278
1262
  }
1279
1263
 
1280
1264
  /// Generate a random XorName
1281
1265
  #[napi(factory)]
1282
1266
  pub fn random() -> Self {
1283
- Self(XorName::random(&mut rand::thread_rng()))
1267
+ Self(autonomi::XorName::random(&mut rand::thread_rng()))
1284
1268
  }
1285
1269
  }
1286
1270
 
1287
1271
  /// Address of a chunk.
1288
1272
  ///
1289
1273
  /// It is derived from the content of the chunk.
1290
- #[napi(js_name = "ChunkAddress")]
1291
- pub struct JsChunkAddress(ChunkAddress);
1274
+ #[napi]
1275
+ pub struct ChunkAddress(autonomi::ChunkAddress);
1292
1276
 
1293
1277
  #[napi]
1294
- impl JsChunkAddress {
1278
+ impl ChunkAddress {
1295
1279
  /// Creates a new ChunkAddress.
1296
1280
  #[napi(constructor)]
1297
- pub fn new(xor_name: &JsXorName) -> Self {
1298
- Self(ChunkAddress::new(xor_name.0))
1281
+ pub fn new(xor_name: &XorName) -> Self {
1282
+ Self(autonomi::ChunkAddress::new(xor_name.0))
1299
1283
  }
1300
1284
 
1301
1285
  /// Returns the XorName.
1302
1286
  #[napi]
1303
- pub fn xorname(&self) -> JsXorName {
1304
- JsXorName(*self.0.xorname())
1287
+ pub fn xorname(&self) -> XorName {
1288
+ XorName(*self.0.xorname())
1305
1289
  }
1306
1290
 
1307
1291
  /// Returns the hex string representation of the address.
@@ -1313,7 +1297,7 @@ impl JsChunkAddress {
1313
1297
  /// Creates a new ChunkAddress from a hex string.
1314
1298
  #[napi(factory)]
1315
1299
  pub fn from_hex(hex: String) -> Result<Self> {
1316
- let addr = ChunkAddress::from_hex(&hex).map_err(map_error)?;
1300
+ let addr = autonomi::ChunkAddress::from_hex(&hex).map_err(map_error)?;
1317
1301
 
1318
1302
  Ok(Self(addr))
1319
1303
  }
@@ -1322,22 +1306,22 @@ impl JsChunkAddress {
1322
1306
  /// Address of a `GraphEntry`.
1323
1307
  ///
1324
1308
  /// It is derived from the owner's unique public key
1325
- #[napi(js_name = "GraphEntryAddress")]
1326
- pub struct JsGraphEntryAddress(GraphEntryAddress);
1309
+ #[napi]
1310
+ pub struct GraphEntryAddress(autonomi::GraphEntryAddress);
1327
1311
 
1328
1312
  #[napi]
1329
- impl JsGraphEntryAddress {
1313
+ impl GraphEntryAddress {
1330
1314
  /// Creates a new GraphEntryAddress.
1331
1315
  #[napi(constructor)]
1332
- pub fn new(owner: &JsPublicKey) -> Self {
1333
- Self(GraphEntryAddress::new(owner.0))
1316
+ pub fn new(owner: &PublicKey) -> Self {
1317
+ Self(autonomi::GraphEntryAddress::new(owner.0))
1334
1318
  }
1335
1319
 
1336
1320
  /// Return the network name of the scratchpad.
1337
1321
  /// This is used to locate the scratchpad on the network.
1338
1322
  #[napi]
1339
- pub fn xorname(&self) -> JsXorName {
1340
- JsXorName(self.0.xorname())
1323
+ pub fn xorname(&self) -> XorName {
1324
+ XorName(self.0.xorname())
1341
1325
  }
1342
1326
 
1343
1327
  /// Serialize this `GraphEntryAddress` into a hex-encoded string.
@@ -1349,27 +1333,27 @@ impl JsGraphEntryAddress {
1349
1333
  /// Parse a hex-encoded string into a `GraphEntryAddress`.
1350
1334
  #[napi(factory)]
1351
1335
  pub fn from_hex(hex: String) -> Result<Self> {
1352
- let addr = GraphEntryAddress::from_hex(&hex).map_err(map_error)?;
1336
+ let addr = autonomi::GraphEntryAddress::from_hex(&hex).map_err(map_error)?;
1353
1337
 
1354
1338
  Ok(Self(addr))
1355
1339
  }
1356
1340
  }
1357
1341
 
1358
- #[napi(js_name = "DataAddress")]
1359
- pub struct JsDataAddress(DataAddress);
1342
+ #[napi]
1343
+ pub struct DataAddress(autonomi::data::DataAddress);
1360
1344
 
1361
1345
  #[napi]
1362
- impl JsDataAddress {
1346
+ impl DataAddress {
1363
1347
  /// Creates a new DataAddress.
1364
1348
  #[napi(constructor)]
1365
- pub fn new(xor_name: &JsXorName) -> Self {
1366
- Self(DataAddress::new(xor_name.0))
1349
+ pub fn new(xor_name: &XorName) -> Self {
1350
+ Self(autonomi::data::DataAddress::new(xor_name.0))
1367
1351
  }
1368
1352
 
1369
1353
  /// Returns the XorName.
1370
1354
  #[napi]
1371
- pub fn xorname(&self) -> JsXorName {
1372
- JsXorName(*self.0.xorname())
1355
+ pub fn xorname(&self) -> XorName {
1356
+ XorName(*self.0.xorname())
1373
1357
  }
1374
1358
 
1375
1359
  /// Returns the hex string representation of the address.
@@ -1381,25 +1365,29 @@ impl JsDataAddress {
1381
1365
  /// Creates a new DataAddress from a hex string.
1382
1366
  #[napi(factory)]
1383
1367
  pub fn from_hex(hex: String) -> Result<Self> {
1384
- DataAddress::from_hex(&hex).map(Self).map_err(map_error)
1368
+ autonomi::data::DataAddress::from_hex(&hex)
1369
+ .map(Self)
1370
+ .map_err(map_error)
1385
1371
  }
1386
1372
  }
1387
1373
 
1388
- #[napi(js_name = "ArchiveAddress")]
1389
- pub struct JsArchiveAddress(ArchiveAddress);
1374
+ #[napi]
1375
+ pub struct ArchiveAddress(autonomi::files::archive_public::ArchiveAddress);
1390
1376
 
1391
1377
  #[napi]
1392
- impl JsArchiveAddress {
1378
+ impl ArchiveAddress {
1393
1379
  /// Creates a new ArchiveAddress.
1394
1380
  #[napi(constructor)]
1395
- pub fn new(xor_name: &JsXorName) -> Self {
1396
- Self(ArchiveAddress::new(xor_name.0))
1381
+ pub fn new(xor_name: &XorName) -> Self {
1382
+ Self(autonomi::files::archive_public::ArchiveAddress::new(
1383
+ xor_name.0,
1384
+ ))
1397
1385
  }
1398
1386
 
1399
1387
  /// Returns the XorName.
1400
1388
  #[napi]
1401
- pub fn xorname(&self) -> JsXorName {
1402
- JsXorName(*self.0.xorname())
1389
+ pub fn xorname(&self) -> XorName {
1390
+ XorName(*self.0.xorname())
1403
1391
  }
1404
1392
 
1405
1393
  /// Returns the hex string representation of the address.
@@ -1411,26 +1399,28 @@ impl JsArchiveAddress {
1411
1399
  /// Creates a new ArchiveAddress from a hex string.
1412
1400
  #[napi(factory)]
1413
1401
  pub fn from_hex(hex: String) -> Result<Self> {
1414
- ArchiveAddress::from_hex(&hex).map(Self).map_err(map_error)
1402
+ autonomi::files::archive_public::ArchiveAddress::from_hex(&hex)
1403
+ .map(Self)
1404
+ .map_err(map_error)
1415
1405
  }
1416
1406
  }
1417
1407
 
1418
1408
  /// A wallet for interacting with the network's payment system
1419
- #[napi(js_name = "Wallet")]
1420
- pub struct JsWallet(Wallet);
1409
+ #[napi]
1410
+ pub struct Wallet(autonomi::Wallet);
1421
1411
 
1422
1412
  #[napi]
1423
- impl JsWallet {
1413
+ impl Wallet {
1424
1414
  /// Convenience function that creates a new Wallet with a random EthereumWallet.
1425
- pub fn new_with_random_wallet(network: Network) -> Self {
1426
- JsWallet(Wallet::new_with_random_wallet(network))
1415
+ pub fn new_with_random_wallet(network: autonomi::Network) -> Self {
1416
+ Wallet(autonomi::Wallet::new_with_random_wallet(network))
1427
1417
  }
1428
1418
 
1429
1419
  /// Creates a new Wallet based on the given Ethereum private key. It will fail with Error::PrivateKeyInvalid if private_key is invalid.
1430
1420
  #[napi(factory)]
1431
- pub fn new_from_private_key(network: &JsNetwork, private_key: String) -> Result<Self> {
1432
- let wallet =
1433
- Wallet::new_from_private_key(network.0.clone(), &private_key).map_err(map_error)?;
1421
+ pub fn new_from_private_key(network: &Network, private_key: String) -> Result<Self> {
1422
+ let wallet = autonomi::Wallet::new_from_private_key(network.0.clone(), &private_key)
1423
+ .map_err(map_error)?;
1434
1424
 
1435
1425
  Ok(Self(wallet))
1436
1426
  }
@@ -1442,8 +1432,8 @@ impl JsWallet {
1442
1432
  }
1443
1433
 
1444
1434
  /// Returns the `Network` of this wallet.
1445
- pub fn network(&self) -> JsNetwork {
1446
- JsNetwork(self.0.network().clone())
1435
+ pub fn network(&self) -> Network {
1436
+ Network(self.0.network().clone())
1447
1437
  }
1448
1438
 
1449
1439
  /// Returns the raw balance of payment tokens in the wallet
@@ -1461,17 +1451,78 @@ impl JsWallet {
1461
1451
 
1462
1452
  Ok(balance.to_string())
1463
1453
  }
1454
+
1455
+ /// Sets the transaction configuration for the wallet.
1456
+ #[napi]
1457
+ pub fn set_transaction_config(&mut self, config: &TransactionConfig) {
1458
+ self.0.set_transaction_config(config.0.clone())
1459
+ }
1460
+ }
1461
+
1462
+ /// Transaction configuration for wallets
1463
+ #[napi]
1464
+ pub struct TransactionConfig(autonomi::TransactionConfig);
1465
+
1466
+ #[napi]
1467
+ impl TransactionConfig {
1468
+ /// Use the current market price for fee per gas. WARNING: This can result in unexpected high gas fees!
1469
+ #[napi(factory)]
1470
+ pub fn auto() -> Self {
1471
+ Self(autonomi::TransactionConfig {
1472
+ max_fee_per_gas: autonomi::MaxFeePerGas::Auto,
1473
+ })
1474
+ }
1475
+
1476
+ /// Use the current market price for fee per gas, but with an upper limit.
1477
+ #[napi(factory)]
1478
+ pub fn limited_auto(limit: BigInt) -> Result<Self> {
1479
+ let (_signed, value, lossless) = limit.get_u128();
1480
+ if !lossless {
1481
+ return Err(napi::Error::new(
1482
+ Status::InvalidArg,
1483
+ "expected limit to fit in a u128",
1484
+ ));
1485
+ }
1486
+
1487
+ Ok(Self(autonomi::TransactionConfig {
1488
+ max_fee_per_gas: autonomi::MaxFeePerGas::LimitedAuto(value),
1489
+ }))
1490
+ }
1491
+
1492
+ /// Use no max fee per gas. WARNING: This can result in unexpected high gas fees!
1493
+ #[napi(factory)]
1494
+ pub fn unlimited() -> Self {
1495
+ Self(autonomi::TransactionConfig {
1496
+ max_fee_per_gas: autonomi::MaxFeePerGas::Unlimited,
1497
+ })
1498
+ }
1499
+
1500
+ /// Use a custom max fee per gas in WEI.
1501
+ #[napi(factory)]
1502
+ pub fn custom(fee: BigInt) -> Result<Self> {
1503
+ let (_signed, value, lossless) = fee.get_u128();
1504
+ if !lossless {
1505
+ return Err(napi::Error::new(
1506
+ Status::InvalidArg,
1507
+ "expected fee to fit in a u128",
1508
+ ));
1509
+ }
1510
+
1511
+ Ok(Self(autonomi::TransactionConfig {
1512
+ max_fee_per_gas: autonomi::MaxFeePerGas::Custom(value),
1513
+ }))
1514
+ }
1464
1515
  }
1465
1516
 
1466
1517
  /// Options for making payments on the network
1467
- #[napi(js_name = "PaymentOption")]
1468
- pub struct JsPaymentOption(PaymentOption);
1518
+ #[napi]
1519
+ pub struct PaymentOption(autonomi::client::payment::PaymentOption);
1469
1520
 
1470
1521
  #[napi]
1471
- impl JsPaymentOption {
1522
+ impl PaymentOption {
1472
1523
  #[napi(factory)]
1473
- pub fn from_wallet(wallet: &JsWallet) -> Self {
1474
- Self(PaymentOption::from(&wallet.0))
1524
+ pub fn from_wallet(wallet: &Wallet) -> Self {
1525
+ Self(autonomi::client::payment::PaymentOption::from(&wallet.0))
1475
1526
  }
1476
1527
 
1477
1528
  #[napi(factory)]
@@ -1480,23 +1531,23 @@ impl JsPaymentOption {
1480
1531
  }
1481
1532
  }
1482
1533
 
1483
- #[napi(js_name = "Network")]
1484
- pub struct JsNetwork(Network);
1534
+ #[napi]
1535
+ pub struct Network(autonomi::Network);
1485
1536
 
1486
1537
  #[napi]
1487
- impl JsNetwork {
1538
+ impl Network {
1488
1539
  #[napi(constructor)]
1489
1540
  pub fn new(local: bool) -> Result<Self> {
1490
- let network = Network::new(local).map_err(map_error)?;
1541
+ let network = autonomi::Network::new(local).map_err(map_error)?;
1491
1542
  Ok(Self(network))
1492
1543
  }
1493
1544
  }
1494
1545
 
1495
- #[napi(js_name = "PublicKey")]
1496
- pub struct JsPublicKey(PublicKey);
1546
+ #[napi]
1547
+ pub struct PublicKey(autonomi::PublicKey);
1497
1548
 
1498
1549
  #[napi]
1499
- impl JsPublicKey {
1550
+ impl PublicKey {
1500
1551
  /// Returns a byte string representation of the public key.
1501
1552
  #[napi]
1502
1553
  pub fn to_bytes(&self) -> Uint8Array {
@@ -1507,7 +1558,7 @@ impl JsPublicKey {
1507
1558
  #[napi(factory)]
1508
1559
  pub fn from_bytes(bytes: Uint8Array) -> Result<Self> {
1509
1560
  let bytes = uint8_array_to_array(bytes, "bytes")?;
1510
- let key = PublicKey::from_bytes(bytes).map_err(map_error)?;
1561
+ let key = autonomi::PublicKey::from_bytes(bytes).map_err(map_error)?;
1511
1562
  Ok(Self(key))
1512
1563
  }
1513
1564
 
@@ -1520,26 +1571,26 @@ impl JsPublicKey {
1520
1571
  /// Creates a new PublicKey from a hex string.
1521
1572
  #[napi(factory)]
1522
1573
  pub fn from_hex(hex: String) -> Result<Self> {
1523
- let key = PublicKey::from_hex(&hex).map_err(map_error)?;
1574
+ let key = autonomi::PublicKey::from_hex(&hex).map_err(map_error)?;
1524
1575
  Ok(Self(key))
1525
1576
  }
1526
1577
  }
1527
1578
 
1528
- #[napi(js_name = "SecretKey")]
1529
- pub struct JsSecretKey(SecretKey);
1579
+ #[napi]
1580
+ pub struct SecretKey(autonomi::SecretKey);
1530
1581
 
1531
1582
  #[napi]
1532
- impl JsSecretKey {
1583
+ impl SecretKey {
1533
1584
  /// Generate a random SecretKey
1534
1585
  #[napi(factory)]
1535
1586
  pub fn random() -> Self {
1536
- Self(SecretKey::random())
1587
+ Self(autonomi::SecretKey::random())
1537
1588
  }
1538
1589
 
1539
1590
  /// Returns the public key corresponding to this secret key.
1540
1591
  #[napi]
1541
- pub fn public_key(&self) -> JsPublicKey {
1542
- JsPublicKey(self.0.public_key())
1592
+ pub fn public_key(&self) -> PublicKey {
1593
+ PublicKey(self.0.public_key())
1543
1594
  }
1544
1595
 
1545
1596
  /// Converts the secret key to big endian bytes
@@ -1552,7 +1603,7 @@ impl JsSecretKey {
1552
1603
  #[napi(factory)]
1553
1604
  pub fn from_bytes(bytes: Uint8Array) -> Result<Self> {
1554
1605
  let bytes = uint8_array_to_array(bytes, "bytes")?;
1555
- let key = SecretKey::from_bytes(bytes).map_err(map_error)?;
1606
+ let key = autonomi::SecretKey::from_bytes(bytes).map_err(map_error)?;
1556
1607
  Ok(Self(key))
1557
1608
  }
1558
1609
 
@@ -1565,23 +1616,23 @@ impl JsSecretKey {
1565
1616
  /// Creates a new SecretKey from a hex string.
1566
1617
  #[napi(factory)]
1567
1618
  pub fn from_hex(hex: String) -> Result<Self> {
1568
- let key = SecretKey::from_hex(&hex).map_err(map_error)?;
1619
+ let key = autonomi::SecretKey::from_hex(&hex).map_err(map_error)?;
1569
1620
  Ok(Self(key))
1570
1621
  }
1571
1622
  }
1572
1623
 
1573
- #[napi(js_name = "GraphEntry")]
1574
- pub struct JsGraphEntry(GraphEntry);
1624
+ #[napi]
1625
+ pub struct GraphEntry(autonomi::GraphEntry);
1575
1626
 
1576
1627
  #[napi]
1577
- impl JsGraphEntry {
1628
+ impl GraphEntry {
1578
1629
  /// Create a new graph entry, signing it with the provided secret key.
1579
1630
  #[napi(constructor)]
1580
1631
  pub fn new(
1581
- owner: &JsSecretKey,
1582
- parents: Vec<&JsPublicKey>,
1632
+ owner: &SecretKey,
1633
+ parents: Vec<&PublicKey>,
1583
1634
  content: Uint8Array,
1584
- descendants: Vec<(&JsPublicKey, Uint8Array)>,
1635
+ descendants: Vec<(&PublicKey, Uint8Array)>,
1585
1636
  ) -> Result<Self> {
1586
1637
  let content: [u8; 32] = uint8_array_to_array(content, "content")?;
1587
1638
 
@@ -1593,9 +1644,9 @@ impl JsGraphEntry {
1593
1644
  let content_array: [u8; 32] = uint8_array_to_array(content.clone(), "content")?;
1594
1645
  Ok((pk.0, content_array))
1595
1646
  })
1596
- .collect::<Result<Vec<(PublicKey, [u8; 32])>>>()?;
1647
+ .collect::<Result<Vec<(autonomi::PublicKey, [u8; 32])>>>()?;
1597
1648
 
1598
- Ok(Self(GraphEntry::new(
1649
+ Ok(Self(autonomi::GraphEntry::new(
1599
1650
  &owner.0,
1600
1651
  parents,
1601
1652
  content,
@@ -1606,17 +1657,17 @@ impl JsGraphEntry {
1606
1657
  /// Create a new graph entry with the signature already calculated.
1607
1658
  #[napi(factory)]
1608
1659
  pub fn new_with_signature(
1609
- owner: &JsPublicKey,
1610
- parents: Vec<&JsPublicKey>,
1660
+ owner: &PublicKey,
1661
+ parents: Vec<&PublicKey>,
1611
1662
  content: Uint8Array,
1612
- descendants: Vec<(&JsPublicKey, Uint8Array)>,
1663
+ descendants: Vec<(&PublicKey, Uint8Array)>,
1613
1664
  signature: Uint8Array,
1614
1665
  ) -> Result<Self> {
1615
1666
  let content: [u8; 32] = uint8_array_to_array(content, "content")?;
1616
1667
 
1617
1668
  let parents = parents.iter().map(|p| p.0).collect();
1618
1669
 
1619
- let descendants_result: Result<Vec<(PublicKey, [u8; 32])>> = descendants
1670
+ let descendants_result: Result<Vec<(autonomi::PublicKey, [u8; 32])>> = descendants
1620
1671
  .iter()
1621
1672
  .map(|(pk, content)| {
1622
1673
  let content_array: [u8; 32] = uint8_array_to_array(content.clone(), "content")?;
@@ -1629,7 +1680,7 @@ impl JsGraphEntry {
1629
1680
  let signature = uint8_array_to_array(signature, "signature")?;
1630
1681
  let signature = Signature::from_bytes(signature).map_err(map_error)?;
1631
1682
 
1632
- Ok(Self(GraphEntry::new_with_signature(
1683
+ Ok(Self(autonomi::GraphEntry::new_with_signature(
1633
1684
  owner.0,
1634
1685
  parents,
1635
1686
  content,
@@ -1640,20 +1691,20 @@ impl JsGraphEntry {
1640
1691
 
1641
1692
  /// Get the address of the graph entry
1642
1693
  #[napi]
1643
- pub fn address(&self) -> JsGraphEntryAddress {
1644
- JsGraphEntryAddress(self.0.address())
1694
+ pub fn address(&self) -> GraphEntryAddress {
1695
+ GraphEntryAddress(self.0.address())
1645
1696
  }
1646
1697
 
1647
1698
  /// Get the owner of the graph entry
1648
1699
  #[napi]
1649
- pub fn owner(&self) -> JsPublicKey {
1650
- JsPublicKey(self.0.owner)
1700
+ pub fn owner(&self) -> PublicKey {
1701
+ PublicKey(self.0.owner)
1651
1702
  }
1652
1703
 
1653
1704
  /// Get the parents of the graph entry
1654
1705
  #[napi]
1655
- pub fn parents(&self) -> Vec<JsPublicKey> {
1656
- self.0.parents.iter().map(|p| JsPublicKey(*p)).collect()
1706
+ pub fn parents(&self) -> Vec<PublicKey> {
1707
+ self.0.parents.iter().map(|p| PublicKey(*p)).collect()
1657
1708
  }
1658
1709
 
1659
1710
  /// Get the content of the graph entry
@@ -1705,35 +1756,40 @@ impl JsGraphEntry {
1705
1756
  }
1706
1757
  }
1707
1758
 
1708
- #[napi(js_name = "Pointer")]
1709
- pub struct JsPointer(Pointer);
1759
+ #[napi]
1760
+ pub struct Pointer(autonomi::Pointer);
1710
1761
 
1711
1762
  #[napi]
1712
- impl JsPointer {
1763
+ impl Pointer {
1713
1764
  /// Create a new pointer, signing it with the provided secret key.
1714
1765
  /// This pointer would be stored on the network at the provided key's public key.
1715
1766
  /// There can only be one pointer at a time at the same address (one per key).
1716
1767
  #[napi(constructor)]
1717
- pub fn new(owner: &JsSecretKey, counter: u32, target: &JsPointerTarget) -> Self {
1718
- JsPointer(Pointer::new(&owner.0, counter, target.0.clone()))
1768
+ pub fn new(owner: &SecretKey, counter: BigInt, target: &PointerTarget) -> Result<Self> {
1769
+ let counter = big_int_to_u64(counter, "counter")?;
1770
+ Ok(Pointer(autonomi::Pointer::new(
1771
+ &owner.0,
1772
+ counter,
1773
+ target.0.clone(),
1774
+ )))
1719
1775
  }
1720
1776
 
1721
1777
  /// Get the address of the pointer
1722
1778
  #[napi]
1723
- pub fn address(&self) -> JsPointerAddress {
1724
- JsPointerAddress(self.0.address())
1779
+ pub fn address(&self) -> PointerAddress {
1780
+ PointerAddress(self.0.address())
1725
1781
  }
1726
1782
 
1727
1783
  /// Get the owner of the pointer
1728
1784
  #[napi]
1729
- pub fn owner(&self) -> JsPublicKey {
1730
- JsPublicKey(*self.0.owner())
1785
+ pub fn owner(&self) -> PublicKey {
1786
+ PublicKey(*self.0.owner())
1731
1787
  }
1732
1788
 
1733
1789
  /// Get the target of the pointer
1734
1790
  #[napi]
1735
- pub fn target(&self) -> JsPointerTarget {
1736
- JsPointerTarget(self.0.target().clone())
1791
+ pub fn target(&self) -> PointerTarget {
1792
+ PointerTarget(self.0.target().clone())
1737
1793
  }
1738
1794
 
1739
1795
  /// Get the bytes that were signed for this pointer
@@ -1744,14 +1800,14 @@ impl JsPointer {
1744
1800
 
1745
1801
  /// Get the xorname of the pointer target
1746
1802
  #[napi]
1747
- pub fn xorname(&self) -> JsXorName {
1748
- JsXorName(self.0.xorname())
1803
+ pub fn xorname(&self) -> XorName {
1804
+ XorName(self.0.xorname())
1749
1805
  }
1750
1806
 
1751
1807
  /// Get the counter of the pointer, the higher the counter, the more recent the pointer is
1752
1808
  /// Similarly to counter CRDTs only the latest version (highest counter) of the pointer is kept on the network
1753
1809
  #[napi]
1754
- pub fn counter(&self) -> u32 {
1810
+ pub fn counter(&self) -> u64 {
1755
1811
  self.0.counter()
1756
1812
  }
1757
1813
 
@@ -1764,19 +1820,19 @@ impl JsPointer {
1764
1820
  /// Size of the pointer
1765
1821
  #[napi]
1766
1822
  pub fn size() -> usize {
1767
- Pointer::size()
1823
+ autonomi::Pointer::size()
1768
1824
  }
1769
1825
  }
1770
1826
 
1771
- #[napi(js_name = "PointerTarget")]
1772
- pub struct JsPointerTarget(PointerTarget);
1827
+ #[napi]
1828
+ pub struct PointerTarget(autonomi::pointer::PointerTarget);
1773
1829
 
1774
1830
  #[napi]
1775
- impl JsPointerTarget {
1831
+ impl PointerTarget {
1776
1832
  /// Returns the xorname of the target
1777
1833
  #[napi]
1778
- pub fn xorname(&self) -> JsXorName {
1779
- JsXorName(self.0.xorname())
1834
+ pub fn xorname(&self) -> XorName {
1835
+ XorName(self.0.xorname())
1780
1836
  }
1781
1837
 
1782
1838
  /// Returns the hex string representation of the target
@@ -1787,51 +1843,51 @@ impl JsPointerTarget {
1787
1843
 
1788
1844
  /// Creates a new PointerTarget from a ChunkAddress
1789
1845
  #[napi(factory, js_name = "ChunkAddress")]
1790
- pub fn from_chunk_address(addr: &JsChunkAddress) -> Self {
1791
- Self(PointerTarget::ChunkAddress(addr.0))
1846
+ pub fn from_chunk_address(addr: &ChunkAddress) -> Self {
1847
+ Self(autonomi::pointer::PointerTarget::ChunkAddress(addr.0))
1792
1848
  }
1793
1849
 
1794
1850
  /// Creates a new PointerTarget from a GraphEntryAddress
1795
1851
  #[napi(factory, js_name = "GraphEntryAddress")]
1796
- pub fn from_graph_entry_address(addr: &JsGraphEntryAddress) -> Self {
1797
- Self(PointerTarget::GraphEntryAddress(addr.0))
1852
+ pub fn from_graph_entry_address(addr: &GraphEntryAddress) -> Self {
1853
+ Self(autonomi::pointer::PointerTarget::GraphEntryAddress(addr.0))
1798
1854
  }
1799
1855
 
1800
1856
  /// Creates a new PointerTarget from a PointerAddress
1801
1857
  #[napi(factory, js_name = "PointerAddress")]
1802
- pub fn from_pointer_address(addr: &JsPointerAddress) -> Self {
1803
- Self(PointerTarget::PointerAddress(addr.0))
1858
+ pub fn from_pointer_address(addr: &PointerAddress) -> Self {
1859
+ Self(autonomi::pointer::PointerTarget::PointerAddress(addr.0))
1804
1860
  }
1805
1861
 
1806
1862
  /// Creates a new PointerTarget from a ScratchpadAddress
1807
1863
  #[napi(factory, js_name = "ScratchpadAddress")]
1808
- pub fn from_scratchpad_address(addr: &JsScratchpadAddress) -> Self {
1809
- Self(PointerTarget::ScratchpadAddress(addr.0))
1864
+ pub fn from_scratchpad_address(addr: &ScratchpadAddress) -> Self {
1865
+ Self(autonomi::pointer::PointerTarget::ScratchpadAddress(addr.0))
1810
1866
  }
1811
1867
  }
1812
1868
 
1813
- #[napi(js_name = "PointerAddress")]
1814
- pub struct JsPointerAddress(PointerAddress);
1869
+ #[napi]
1870
+ pub struct PointerAddress(autonomi::PointerAddress);
1815
1871
 
1816
1872
  #[napi]
1817
- impl JsPointerAddress {
1873
+ impl PointerAddress {
1818
1874
  /// Creates a new PointerAddress.
1819
1875
  #[napi(constructor)]
1820
- pub fn new(owner: &JsPublicKey) -> Self {
1821
- Self(PointerAddress::new(owner.0))
1876
+ pub fn new(owner: &PublicKey) -> Self {
1877
+ Self(autonomi::PointerAddress::new(owner.0))
1822
1878
  }
1823
1879
 
1824
1880
  /// Return the network name of the pointer.
1825
1881
  /// This is used to locate the pointer on the network.
1826
1882
  #[napi]
1827
- pub fn xorname(&self) -> JsXorName {
1828
- JsXorName(self.0.xorname())
1883
+ pub fn xorname(&self) -> XorName {
1884
+ XorName(self.0.xorname())
1829
1885
  }
1830
1886
 
1831
1887
  /// Return the owner.
1832
1888
  #[napi]
1833
- pub fn owner(&self) -> JsPublicKey {
1834
- JsPublicKey(*self.0.owner())
1889
+ pub fn owner(&self) -> PublicKey {
1890
+ PublicKey(*self.0.owner())
1835
1891
  }
1836
1892
 
1837
1893
  /// Serialize this PointerAddress into a hex-encoded string.
@@ -1843,20 +1899,20 @@ impl JsPointerAddress {
1843
1899
  /// Parse a hex-encoded string into a PointerAddress.
1844
1900
  #[napi(factory)]
1845
1901
  pub fn from_hex(hex: String) -> Result<Self> {
1846
- let addr = PointerAddress::from_hex(&hex).map_err(map_error)?;
1902
+ let addr = autonomi::PointerAddress::from_hex(&hex).map_err(map_error)?;
1847
1903
  Ok(Self(addr))
1848
1904
  }
1849
1905
  }
1850
1906
 
1851
- #[napi(js_name = "Scratchpad")]
1852
- pub struct JsScratchpad(Scratchpad);
1907
+ #[napi]
1908
+ pub struct Scratchpad(autonomi::Scratchpad);
1853
1909
 
1854
1910
  #[napi]
1855
- impl JsScratchpad {
1911
+ impl Scratchpad {
1856
1912
  /// Create a new scratchpad, signing it with the provided secret key.
1857
1913
  #[napi(constructor)]
1858
1914
  pub fn new(
1859
- owner: &JsSecretKey,
1915
+ owner: &SecretKey,
1860
1916
  data_encoding: BigInt, // `u64`
1861
1917
  data: Buffer,
1862
1918
  counter: BigInt, // `u64`
@@ -1865,7 +1921,7 @@ impl JsScratchpad {
1865
1921
  let counter = big_int_to_u64(counter, "counter")?;
1866
1922
  let data = Bytes::copy_from_slice(&data);
1867
1923
 
1868
- Ok(Self(Scratchpad::new(
1924
+ Ok(Self(autonomi::Scratchpad::new(
1869
1925
  &owner.0,
1870
1926
  data_encoding,
1871
1927
  &data,
@@ -1875,14 +1931,14 @@ impl JsScratchpad {
1875
1931
 
1876
1932
  /// Get the address of the scratchpad
1877
1933
  #[napi]
1878
- pub fn address(&self) -> JsScratchpadAddress {
1879
- JsScratchpadAddress(*self.0.address())
1934
+ pub fn address(&self) -> ScratchpadAddress {
1935
+ ScratchpadAddress(*self.0.address())
1880
1936
  }
1881
1937
 
1882
1938
  /// Get the owner of the scratchpad
1883
1939
  #[napi]
1884
- pub fn owner(&self) -> JsPublicKey {
1885
- JsPublicKey(*self.0.owner())
1940
+ pub fn owner(&self) -> PublicKey {
1941
+ PublicKey(*self.0.owner())
1886
1942
  }
1887
1943
 
1888
1944
  /// Get the data encoding (content type) of the scratchpad
@@ -1893,7 +1949,7 @@ impl JsScratchpad {
1893
1949
 
1894
1950
  /// Decrypt the data of the scratchpad
1895
1951
  #[napi]
1896
- pub fn decrypt_data(&self, key: &JsSecretKey) -> Result<Buffer> {
1952
+ pub fn decrypt_data(&self, key: &SecretKey) -> Result<Buffer> {
1897
1953
  let data = self.0.decrypt_data(&key.0).map_err(map_error)?;
1898
1954
  Ok(Buffer::from(data.to_vec()))
1899
1955
  }
@@ -1911,28 +1967,28 @@ impl JsScratchpad {
1911
1967
  }
1912
1968
  }
1913
1969
 
1914
- #[napi(js_name = "ScratchpadAddress")]
1915
- pub struct JsScratchpadAddress(ScratchpadAddress);
1970
+ #[napi]
1971
+ pub struct ScratchpadAddress(autonomi::ScratchpadAddress);
1916
1972
 
1917
1973
  #[napi]
1918
- impl JsScratchpadAddress {
1974
+ impl ScratchpadAddress {
1919
1975
  /// Creates a new ScratchpadAddress.
1920
1976
  #[napi(constructor)]
1921
- pub fn new(owner: &JsPublicKey) -> Self {
1922
- Self(ScratchpadAddress::new(owner.0))
1977
+ pub fn new(owner: &PublicKey) -> Self {
1978
+ Self(autonomi::ScratchpadAddress::new(owner.0))
1923
1979
  }
1924
1980
 
1925
1981
  /// Return the network name of the scratchpad.
1926
1982
  /// This is used to locate the scratchpad on the network.
1927
1983
  #[napi]
1928
- pub fn xorname(&self) -> JsXorName {
1929
- JsXorName(self.0.xorname())
1984
+ pub fn xorname(&self) -> XorName {
1985
+ XorName(self.0.xorname())
1930
1986
  }
1931
1987
 
1932
1988
  /// Return the owner.
1933
1989
  #[napi]
1934
- pub fn owner(&self) -> JsPublicKey {
1935
- JsPublicKey(*self.0.owner())
1990
+ pub fn owner(&self) -> PublicKey {
1991
+ PublicKey(*self.0.owner())
1936
1992
  }
1937
1993
 
1938
1994
  /// Serialize this ScratchpadAddress into a hex-encoded string.
@@ -1944,19 +2000,19 @@ impl JsScratchpadAddress {
1944
2000
  /// Parse a hex-encoded string into a ScratchpadAddress.
1945
2001
  #[napi(factory)]
1946
2002
  pub fn from_hex(hex: String) -> Result<Self> {
1947
- let addr = ScratchpadAddress::from_hex(&hex).map_err(map_error)?;
2003
+ let addr = autonomi::ScratchpadAddress::from_hex(&hex).map_err(map_error)?;
1948
2004
  Ok(Self(addr))
1949
2005
  }
1950
2006
  }
1951
2007
 
1952
- #[napi(js_name = "DataMapChunk")]
1953
- pub struct JsDataMapChunk(DataMapChunk);
2008
+ #[napi]
2009
+ pub struct DataMapChunk(autonomi::data::private::DataMapChunk);
1954
2010
 
1955
- #[napi(js_name = "PrivateArchiveDataMap")]
1956
- pub struct JsPrivateArchiveDataMap(PrivateArchiveDataMap);
2011
+ #[napi]
2012
+ pub struct PrivateArchiveDataMap(autonomi::files::archive_private::PrivateArchiveDataMap);
1957
2013
 
1958
2014
  #[napi]
1959
- impl JsPrivateArchiveDataMap {
2015
+ impl PrivateArchiveDataMap {
1960
2016
  /// Serialize this PrivateArchiveDataMap into a hex-encoded string.
1961
2017
  #[napi]
1962
2018
  pub fn to_hex(&self) -> String {
@@ -1966,26 +2022,27 @@ impl JsPrivateArchiveDataMap {
1966
2022
  /// Parse a hex-encoded string into a PrivateArchiveDataMap.
1967
2023
  #[napi(factory)]
1968
2024
  pub fn from_hex(hex: String) -> Result<Self> {
1969
- let data_map = PrivateArchiveDataMap::from_hex(&hex).map_err(map_error)?;
2025
+ let data_map = autonomi::files::archive_private::PrivateArchiveDataMap::from_hex(&hex)
2026
+ .map_err(map_error)?;
1970
2027
  Ok(Self(data_map))
1971
2028
  }
1972
2029
  }
1973
2030
 
1974
- #[napi(js_name = "PrivateArchive")]
1975
- pub struct JsPrivateArchive(PrivateArchive);
2031
+ #[napi]
2032
+ pub struct PrivateArchive(autonomi::files::PrivateArchive);
1976
2033
 
1977
2034
  #[napi]
1978
- impl JsPrivateArchive {
2035
+ impl PrivateArchive {
1979
2036
  /// Create a new empty local archive
1980
2037
  #[napi(constructor)]
1981
2038
  #[allow(clippy::new_without_default, reason = "`Default` not useful")]
1982
2039
  pub fn new() -> Self {
1983
- Self(PrivateArchive::new())
2040
+ Self(autonomi::files::PrivateArchive::new())
1984
2041
  }
1985
2042
 
1986
2043
  /// Add a file to a local archive
1987
2044
  #[napi]
1988
- pub fn add_file(&mut self, path: String, data_map: &JsDataMapChunk, metadata: &JsMetadata) {
2045
+ pub fn add_file(&mut self, path: String, data_map: &DataMapChunk, metadata: &Metadata) {
1989
2046
  self.0
1990
2047
  .add_file(PathBuf::from(path), data_map.0.clone(), metadata.0.clone());
1991
2048
  }
@@ -2016,8 +2073,8 @@ impl JsPrivateArchive {
2016
2073
 
2017
2074
  /// List all data maps of the files in the archive
2018
2075
  #[napi]
2019
- pub fn data_maps(&self) -> Vec<JsDataMapChunk> {
2020
- self.0.data_maps().into_iter().map(JsDataMapChunk).collect()
2076
+ pub fn data_maps(&self) -> Vec<DataMapChunk> {
2077
+ self.0.data_maps().into_iter().map(DataMapChunk).collect()
2021
2078
  }
2022
2079
 
2023
2080
  /// Convert the archive to bytes
@@ -2037,7 +2094,7 @@ impl JsPrivateArchive {
2037
2094
  #[napi(factory)]
2038
2095
  pub fn from_bytes(data: Buffer) -> Result<Self> {
2039
2096
  let bytes = Bytes::from(data.as_ref().to_vec());
2040
- let archive = PrivateArchive::from_bytes(bytes).map_err(|e| {
2097
+ let archive = autonomi::files::PrivateArchive::from_bytes(bytes).map_err(|e| {
2041
2098
  napi::Error::new(
2042
2099
  Status::GenericFailure,
2043
2100
  format!("Failed to deserialize archive: {e:?}"),
@@ -2049,31 +2106,31 @@ impl JsPrivateArchive {
2049
2106
 
2050
2107
  /// Merge with another archive
2051
2108
  #[napi]
2052
- pub fn merge(&mut self, other: &JsPrivateArchive) {
2109
+ pub fn merge(&mut self, other: &PrivateArchive) {
2053
2110
  self.0.merge(&other.0);
2054
2111
  }
2055
2112
  }
2056
2113
 
2057
- #[napi(js_name = "VaultSecretKey")]
2058
- pub struct JsVaultSecretKey(VaultSecretKey);
2114
+ #[napi]
2115
+ pub struct VaultSecretKey(autonomi::vault::VaultSecretKey);
2059
2116
 
2060
- #[napi(js_name = "UserData")]
2061
- pub struct JsUserData(UserData);
2117
+ #[napi]
2118
+ pub struct UserData(autonomi::vault::UserData);
2062
2119
 
2063
- #[napi(js_name = "VaultContentType")]
2064
- pub struct JsVaultContentType(VaultContentType);
2120
+ #[napi]
2121
+ pub struct VaultContentType(autonomi::vault::VaultContentType);
2065
2122
 
2066
2123
  /// File metadata
2067
- #[napi(js_name = "Metadata")]
2068
- pub struct JsMetadata(Metadata);
2124
+ #[napi]
2125
+ pub struct Metadata(autonomi::files::Metadata);
2069
2126
 
2070
2127
  #[napi]
2071
- impl JsMetadata {
2128
+ impl Metadata {
2072
2129
  /// Create a new metadata struct with the current time as uploaded, created and modified.
2073
2130
  #[napi(factory)]
2074
2131
  pub fn new_with_size(size: BigInt) -> Result<Self> {
2075
2132
  let size = big_int_to_u64(size, "size")?;
2076
- Ok(Self(Metadata::new_with_size(size)))
2133
+ Ok(Self(autonomi::files::Metadata::new_with_size(size)))
2077
2134
  }
2078
2135
 
2079
2136
  /// Create new metadata with all custom fields
@@ -2099,7 +2156,7 @@ impl JsMetadata {
2099
2156
  /// Create a new empty metadata struct with zeros
2100
2157
  #[napi(factory)]
2101
2158
  pub fn empty() -> Self {
2102
- Self(Metadata::empty())
2159
+ Self(autonomi::files::Metadata::empty())
2103
2160
  }
2104
2161
 
2105
2162
  /// Get the creation timestamp
@@ -2127,33 +2184,33 @@ impl JsMetadata {
2127
2184
  }
2128
2185
  }
2129
2186
 
2130
- #[napi(js_name = "RegisterAddress")]
2131
- pub struct JsRegisterAddress(RegisterAddress);
2187
+ #[napi]
2188
+ pub struct RegisterAddress(autonomi::register::RegisterAddress);
2132
2189
 
2133
2190
  #[napi]
2134
- impl JsRegisterAddress {
2191
+ impl RegisterAddress {
2135
2192
  /// Creates a new RegisterAddress.
2136
2193
  #[napi(constructor)]
2137
- pub fn new(owner: &JsPublicKey) -> Self {
2138
- Self(RegisterAddress::new(owner.0))
2194
+ pub fn new(owner: &PublicKey) -> Self {
2195
+ Self(autonomi::register::RegisterAddress::new(owner.0))
2139
2196
  }
2140
2197
 
2141
2198
  /// Get the owner of the register
2142
2199
  #[napi]
2143
- pub fn owner(&self) -> JsPublicKey {
2144
- JsPublicKey(self.0.owner())
2200
+ pub fn owner(&self) -> PublicKey {
2201
+ PublicKey(self.0.owner())
2145
2202
  }
2146
2203
 
2147
2204
  /// Get the underlying graph root address
2148
2205
  #[napi]
2149
- pub fn to_underlying_graph_root(&self) -> JsGraphEntryAddress {
2150
- JsGraphEntryAddress(self.0.to_underlying_graph_root())
2206
+ pub fn to_underlying_graph_root(&self) -> GraphEntryAddress {
2207
+ GraphEntryAddress(self.0.to_underlying_graph_root())
2151
2208
  }
2152
2209
 
2153
2210
  /// Get the underlying head pointer address
2154
2211
  #[napi]
2155
- pub fn to_underlying_head_pointer(&self) -> JsPointerAddress {
2156
- JsPointerAddress(self.0.to_underlying_head_pointer())
2212
+ pub fn to_underlying_head_pointer(&self) -> PointerAddress {
2213
+ PointerAddress(self.0.to_underlying_head_pointer())
2157
2214
  }
2158
2215
 
2159
2216
  /// Serialize this RegisterAddress into a hex-encoded string.
@@ -2165,16 +2222,16 @@ impl JsRegisterAddress {
2165
2222
  /// Parse a hex-encoded string into a RegisterAddress.
2166
2223
  #[napi(factory)]
2167
2224
  pub fn from_hex(hex: String) -> Result<Self> {
2168
- let addr = RegisterAddress::from_hex(&hex).map_err(map_error)?;
2225
+ let addr = autonomi::register::RegisterAddress::from_hex(&hex).map_err(map_error)?;
2169
2226
  Ok(Self(addr))
2170
2227
  }
2171
2228
  }
2172
2229
 
2173
- #[napi(js_name = "RegisterHistory")]
2174
- pub struct JsRegisterHistory(Mutex<RegisterHistory>);
2230
+ #[napi]
2231
+ pub struct RegisterHistory(Mutex<autonomi::register::RegisterHistory>);
2175
2232
 
2176
2233
  #[napi]
2177
- impl JsRegisterHistory {
2234
+ impl RegisterHistory {
2178
2235
  // Somehow without this stub, NAPI-RS fails to create this object with an error:
2179
2236
  // error: `Failed to get constructor of class`
2180
2237
  #[allow(clippy::new_without_default, reason = "`Default` not useful")]
@@ -2206,21 +2263,21 @@ impl JsRegisterHistory {
2206
2263
  }
2207
2264
  }
2208
2265
 
2209
- #[napi(js_name = "PublicArchive")]
2210
- pub struct JsPublicArchive(PublicArchive);
2266
+ #[napi]
2267
+ pub struct PublicArchive(autonomi::files::PublicArchive);
2211
2268
 
2212
2269
  #[napi]
2213
- impl JsPublicArchive {
2270
+ impl PublicArchive {
2214
2271
  /// Create a new empty local archive
2215
2272
  #[napi(constructor)]
2216
2273
  #[allow(clippy::new_without_default, reason = "`Default` not useful")]
2217
2274
  pub fn new() -> Self {
2218
- Self(PublicArchive::new())
2275
+ Self(autonomi::files::PublicArchive::new())
2219
2276
  }
2220
2277
 
2221
2278
  /// Add a file to a local archive
2222
2279
  #[napi]
2223
- pub fn add_file(&mut self, path: String, data_addr: &JsDataAddress, metadata: &JsMetadata) {
2280
+ pub fn add_file(&mut self, path: String, data_addr: &DataAddress, metadata: &Metadata) {
2224
2281
  self.0
2225
2282
  .add_file(PathBuf::from(path), data_addr.0, metadata.0.clone());
2226
2283
  }
@@ -2251,8 +2308,8 @@ impl JsPublicArchive {
2251
2308
 
2252
2309
  /// List all data addresses of the files in the archive
2253
2310
  #[napi]
2254
- pub fn addresses(&self) -> Vec<JsDataAddress> {
2255
- self.0.addresses().into_iter().map(JsDataAddress).collect()
2311
+ pub fn addresses(&self) -> Vec<DataAddress> {
2312
+ self.0.addresses().into_iter().map(DataAddress).collect()
2256
2313
  }
2257
2314
 
2258
2315
  /// Convert the archive to bytes
@@ -2272,7 +2329,7 @@ impl JsPublicArchive {
2272
2329
  #[napi(factory)]
2273
2330
  pub fn from_bytes(data: Buffer) -> Result<Self> {
2274
2331
  let bytes = Bytes::from(data.as_ref().to_vec());
2275
- let archive = PublicArchive::from_bytes(bytes).map_err(|e| {
2332
+ let archive = autonomi::files::PublicArchive::from_bytes(bytes).map_err(|e| {
2276
2333
  napi::Error::new(
2277
2334
  Status::GenericFailure,
2278
2335
  format!("Failed to deserialize archive: {e:?}"),
@@ -2284,7 +2341,7 @@ impl JsPublicArchive {
2284
2341
 
2285
2342
  /// Merge with another archive
2286
2343
  #[napi]
2287
- pub fn merge(&mut self, other: &JsPublicArchive) {
2344
+ pub fn merge(&mut self, other: &PublicArchive) {
2288
2345
  self.0.merge(&other.0);
2289
2346
  }
2290
2347
  }