@withautonomi/autonomi 0.4.2 → 0.4.4

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