@withautonomi/autonomi 0.4.4 → 0.5.1

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/Cargo.toml CHANGED
@@ -1,7 +1,7 @@
1
1
  [package]
2
2
  edition = "2021"
3
3
  name = "autonomi-nodejs"
4
- version = "0.1.0"
4
+ version = "0.1.1"
5
5
  description = "NodeJS bindings for the autonomi client"
6
6
  license = "GPL-3.0"
7
7
 
@@ -9,7 +9,7 @@ license = "GPL-3.0"
9
9
  crate-type = ["cdylib"]
10
10
 
11
11
  [dependencies]
12
- autonomi = { path = "../autonomi", version = "0.4.4" }
12
+ autonomi = { path = "../autonomi", version = "0.5.1" }
13
13
  bytes = { version = "1.0.1", features = ["serde"] }
14
14
  eyre = "0.6.12"
15
15
  futures = "0.3"
Binary file
package/index.d.ts CHANGED
@@ -24,6 +24,8 @@ export declare class Client {
24
24
  * See `init_with_config`.
25
25
  */
26
26
  static initLocal(): Promise<Client>
27
+ /** Initialize a client that is configured to be connected to the alpha network. */
28
+ static initAlpha(): Promise<Client>
27
29
  /**
28
30
  * Initialize a client that bootstraps from a list of peers.
29
31
  *
@@ -199,7 +201,7 @@ export declare class Client {
199
201
  */
200
202
  vaultCost(owner: VaultSecretKey, maxSize: bigint): Promise<string>
201
203
  /**
202
- * Put data into the clients VaultPacket
204
+ * Put data into the client's VaultPacket
203
205
  *
204
206
  * Dynamically expand the vault capacity by paying for more space (Scratchpad) when needed.
205
207
  *
@@ -218,7 +220,7 @@ export declare class Client {
218
220
  /**
219
221
  * Create a new register key from a SecretKey and a name.
220
222
  *
221
- * 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.
223
+ * 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.
222
224
  */
223
225
  static registerKeyFromName(owner: SecretKey, name: string): SecretKey
224
226
  /** Create a new RegisterValue from bytes, make sure the bytes are not longer than REGISTER_VALUE_SIZE */
@@ -236,7 +238,7 @@ export declare class Client {
236
238
  registerUpdate(owner: SecretKey, newValue: Uint8Array, paymentOption: PaymentOption): Promise<string>
237
239
  /** Get the current value of the register */
238
240
  registerGet(addr: RegisterAddress): Promise<Uint8Array>
239
- /** Get the cost of a register operation. Returns the cost of creation if it doesnt exist, else returns the cost of an update */
241
+ /** Get the cost of a register operation. Returns the cost of creation if it doesn't exist, else returns the cost of an update */
240
242
  registerCost(owner: PublicKey): Promise<string>
241
243
  }
242
244
  export declare class ChunkPut {
@@ -386,6 +388,19 @@ export declare class Wallet {
386
388
  balance(): Promise<string>
387
389
  /** Returns the current balance of gas tokens in the wallet */
388
390
  balanceOfGas(): Promise<string>
391
+ /** Sets the transaction configuration for the wallet. */
392
+ setTransactionConfig(config: TransactionConfig): void
393
+ }
394
+ /** Transaction configuration for wallets */
395
+ export declare class TransactionConfig {
396
+ /** Use the current market price for fee per gas. WARNING: This can result in unexpected high gas fees! */
397
+ static auto(): TransactionConfig
398
+ /** Use the current market price for fee per gas, but with an upper limit. */
399
+ static limitedAuto(limit: bigint): TransactionConfig
400
+ /** Use no max fee per gas. WARNING: This can result in unexpected high gas fees! */
401
+ static unlimited(): TransactionConfig
402
+ /** Use a custom max fee per gas in WEI. */
403
+ static custom(fee: bigint): TransactionConfig
389
404
  }
390
405
  /** Options for making payments on the network */
391
406
  export declare class PaymentOption {
@@ -450,7 +465,7 @@ export declare class Pointer {
450
465
  * This pointer would be stored on the network at the provided key's public key.
451
466
  * There can only be one pointer at a time at the same address (one per key).
452
467
  */
453
- constructor(owner: SecretKey, counter: number, target: PointerTarget)
468
+ constructor(owner: SecretKey, counter: bigint, target: PointerTarget)
454
469
  /** Get the address of the pointer */
455
470
  address(): PointerAddress
456
471
  /** Get the owner of the pointer */
@@ -465,7 +480,7 @@ export declare class Pointer {
465
480
  * Get the counter of the pointer, the higher the counter, the more recent the pointer is
466
481
  * Similarly to counter CRDTs only the latest version (highest counter) of the pointer is kept on the network
467
482
  */
468
- counter(): number
483
+ counter(): bigint
469
484
  /** Verifies if the pointer has a valid signature */
470
485
  verifySignature(): boolean
471
486
  /** Size of the pointer */
package/index.js CHANGED
@@ -310,7 +310,7 @@ if (!nativeBinding) {
310
310
  throw new Error(`Failed to load native binding`)
311
311
  }
312
312
 
313
- const { Client, ChunkPut, GraphEntryPut, ScratchpadPut, PointerPut, DataPutResult, DataPutPublicResult, ArchivePutResult, ArchivePutPublicResult, DirContentUpload, DirUpload, FileContentUpload, DirContentUploadPublic, DirUploadPublic, FileContentUploadPublic, FetchAndDecryptVault, RegisterCreate, GraphEntryDescendant, XorName, ChunkAddress, GraphEntryAddress, DataAddress, ArchiveAddress, Wallet, PaymentOption, Network, PublicKey, SecretKey, GraphEntry, Pointer, PointerTarget, PointerAddress, Scratchpad, ScratchpadAddress, DataMapChunk, PrivateArchiveDataMap, PrivateArchive, VaultSecretKey, UserData, VaultContentType, Metadata, RegisterAddress, RegisterHistory, PublicArchive } = nativeBinding
313
+ const { Client, ChunkPut, GraphEntryPut, ScratchpadPut, PointerPut, DataPutResult, DataPutPublicResult, ArchivePutResult, ArchivePutPublicResult, DirContentUpload, DirUpload, FileContentUpload, DirContentUploadPublic, DirUploadPublic, FileContentUploadPublic, FetchAndDecryptVault, RegisterCreate, GraphEntryDescendant, XorName, ChunkAddress, GraphEntryAddress, DataAddress, ArchiveAddress, Wallet, TransactionConfig, PaymentOption, Network, PublicKey, SecretKey, GraphEntry, Pointer, PointerTarget, PointerAddress, Scratchpad, ScratchpadAddress, DataMapChunk, PrivateArchiveDataMap, PrivateArchive, VaultSecretKey, UserData, VaultContentType, Metadata, RegisterAddress, RegisterHistory, PublicArchive } = nativeBinding
314
314
 
315
315
  module.exports.Client = Client
316
316
  module.exports.ChunkPut = ChunkPut
@@ -336,6 +336,7 @@ module.exports.GraphEntryAddress = GraphEntryAddress
336
336
  module.exports.DataAddress = DataAddress
337
337
  module.exports.ArchiveAddress = ArchiveAddress
338
338
  module.exports.Wallet = Wallet
339
+ module.exports.TransactionConfig = TransactionConfig
339
340
  module.exports.PaymentOption = PaymentOption
340
341
  module.exports.Network = Network
341
342
  module.exports.PublicKey = PublicKey
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@withautonomi/autonomi",
3
- "version": "0.4.4",
3
+ "version": "0.5.1",
4
4
  "description": "NodeJS bindings for Autonomi client",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -57,9 +57,9 @@
57
57
  "includeVersion": true
58
58
  },
59
59
  "optionalDependencies": {
60
- "@withautonomi/autonomi-win32-x64-msvc": "0.4.4",
61
- "@withautonomi/autonomi-darwin-x64": "0.4.4",
62
- "@withautonomi/autonomi-linux-x64-gnu": "0.4.4",
63
- "@withautonomi/autonomi-darwin-arm64": "0.4.4"
60
+ "@withautonomi/autonomi-win32-x64-msvc": "0.5.1",
61
+ "@withautonomi/autonomi-darwin-x64": "0.5.1",
62
+ "@withautonomi/autonomi-linux-x64-gnu": "0.5.1",
63
+ "@withautonomi/autonomi-darwin-arm64": "0.5.1"
64
64
  }
65
65
  }
package/src/lib.rs CHANGED
@@ -72,6 +72,14 @@ impl Client {
72
72
  Ok(Self(client))
73
73
  }
74
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)?;
79
+
80
+ Ok(Self(client))
81
+ }
82
+
75
83
  /// Initialize a client that bootstraps from a list of peers.
76
84
  ///
77
85
  /// If any of the provided peers is a global address, the client will not be local.
@@ -143,12 +151,6 @@ impl Client {
143
151
  Ok(cost.to_string())
144
152
  }
145
153
 
146
- // /// Upload chunks and retry failed uploads up to RETRY_ATTEMPTS times.
147
- // #[napi]
148
- // pub async fn upload_chunks_with_retries(&self, chunks: Vec<Chunk>, receipt: &Receipt) -> Vec<(Chunk, PutError)> {
149
- // todo!()
150
- // }
151
-
152
154
  // Graph entries
153
155
 
154
156
  /// Fetches a GraphEntry from the network.
@@ -168,7 +170,7 @@ impl Client {
168
170
  pub async fn graph_entry_check_existance(&self, address: &GraphEntryAddress) -> Result<bool> {
169
171
  let exists = self
170
172
  .0
171
- .graph_entry_check_existance(&address.0)
173
+ .graph_entry_check_existence(&address.0)
172
174
  .await
173
175
  .map_err(map_error)?;
174
176
 
@@ -217,7 +219,7 @@ impl Client {
217
219
  #[napi]
218
220
  pub async fn pointer_check_existance(&self, address: &PointerAddress) -> Result<bool> {
219
221
  self.0
220
- .pointer_check_existance(&address.0)
222
+ .pointer_check_existence(&address.0)
221
223
  .await
222
224
  .map_err(map_error)
223
225
  }
@@ -314,7 +316,7 @@ impl Client {
314
316
  #[napi]
315
317
  pub async fn scratchpad_check_existance(&self, address: &ScratchpadAddress) -> Result<bool> {
316
318
  self.0
317
- .scratchpad_check_existance(&address.0)
319
+ .scratchpad_check_existence(&address.0)
318
320
  .await
319
321
  .map_err(map_error)
320
322
  }
@@ -791,7 +793,7 @@ impl Client {
791
793
  Ok(cost.to_string())
792
794
  }
793
795
 
794
- /// Put data into the clients VaultPacket
796
+ /// Put data into the client's VaultPacket
795
797
  ///
796
798
  /// Dynamically expand the vault capacity by paying for more space (Scratchpad) when needed.
797
799
  ///
@@ -836,7 +838,7 @@ impl Client {
836
838
 
837
839
  /// Create a new register key from a SecretKey and a name.
838
840
  ///
839
- /// 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.
840
842
  #[napi]
841
843
  pub fn register_key_from_name(owner: &SecretKey, name: String) -> SecretKey {
842
844
  let key = autonomi::Client::register_key_from_name(&owner.0, &name);
@@ -903,7 +905,7 @@ impl Client {
903
905
  .map_err(map_error)
904
906
  }
905
907
 
906
- /// 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
907
909
  #[napi]
908
910
  pub async fn register_cost(&self, owner: &PublicKey) -> Result</* AttoTokens */ String> {
909
911
  let cost = self
@@ -1449,6 +1451,67 @@ impl Wallet {
1449
1451
 
1450
1452
  Ok(balance.to_string())
1451
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
+ }
1452
1515
  }
1453
1516
 
1454
1517
  /// Options for making payments on the network
@@ -1702,8 +1765,13 @@ impl Pointer {
1702
1765
  /// This pointer would be stored on the network at the provided key's public key.
1703
1766
  /// There can only be one pointer at a time at the same address (one per key).
1704
1767
  #[napi(constructor)]
1705
- pub fn new(owner: &SecretKey, counter: u32, target: &PointerTarget) -> Self {
1706
- Pointer(autonomi::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
+ )))
1707
1775
  }
1708
1776
 
1709
1777
  /// Get the address of the pointer
@@ -1739,7 +1807,7 @@ impl Pointer {
1739
1807
  /// Get the counter of the pointer, the higher the counter, the more recent the pointer is
1740
1808
  /// Similarly to counter CRDTs only the latest version (highest counter) of the pointer is kept on the network
1741
1809
  #[napi]
1742
- pub fn counter(&self) -> u32 {
1810
+ pub fn counter(&self) -> u64 {
1743
1811
  self.0.counter()
1744
1812
  }
1745
1813