@withautonomi/autonomi 0.6.0 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/Cargo.toml +2 -2
  2. package/package.json +5 -5
  3. package/src/lib.rs +67 -12
package/Cargo.toml CHANGED
@@ -1,7 +1,7 @@
1
1
  [package]
2
2
  edition = "2024"
3
3
  name = "autonomi-nodejs"
4
- version = "0.2.0"
4
+ version = "0.2.2"
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.6.0" }
12
+ autonomi = { path = "../autonomi", version = "0.6.2" }
13
13
  bytes = { version = "1.0.1", features = ["serde"] }
14
14
  eyre = "0.6.12"
15
15
  futures = "0.3"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@withautonomi/autonomi",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
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.6.0",
61
- "@withautonomi/autonomi-darwin-x64": "0.6.0",
62
- "@withautonomi/autonomi-linux-x64-gnu": "0.6.0",
63
- "@withautonomi/autonomi-darwin-arm64": "0.6.0"
60
+ "@withautonomi/autonomi-win32-x64-msvc": "0.6.2",
61
+ "@withautonomi/autonomi-darwin-x64": "0.6.2",
62
+ "@withautonomi/autonomi-linux-x64-gnu": "0.6.2",
63
+ "@withautonomi/autonomi-darwin-arm64": "0.6.2"
64
64
  }
65
65
  }
package/src/lib.rs CHANGED
@@ -116,6 +116,16 @@ impl Client {
116
116
  Network(self.0.evm_network().clone())
117
117
  }
118
118
 
119
+ /// Set the payment mode for uploads.
120
+ #[napi]
121
+ pub fn with_payment_mode(&self, payment_mode: PaymentMode) -> Self {
122
+ let mode = match payment_mode {
123
+ PaymentMode::Standard => autonomi::PaymentMode::Standard,
124
+ PaymentMode::SingleNode => autonomi::PaymentMode::SingleNode,
125
+ };
126
+ Self(self.0.clone().with_payment_mode(mode))
127
+ }
128
+
119
129
  // Chunks
120
130
 
121
131
  /// Get a chunk from the network.
@@ -787,9 +797,9 @@ impl Client {
787
797
 
788
798
  /// Get the user data from the vault
789
799
  #[napi]
790
- pub async fn get_user_data_from_vault(&self, secret_key: &VaultSecretKey) -> Result<UserData> {
800
+ pub async fn vault_get_user_data(&self, secret_key: &VaultSecretKey) -> Result<UserData> {
791
801
  self.0
792
- .get_user_data_from_vault(&secret_key.0)
802
+ .vault_get_user_data(&secret_key.0)
793
803
  .await
794
804
  .map(UserData)
795
805
  .map_err(map_error)
@@ -799,14 +809,14 @@ impl Client {
799
809
  ///
800
810
  /// Returns the total cost of the put operation
801
811
  #[napi]
802
- pub async fn put_user_data_to_vault(
812
+ pub async fn vault_put_user_data(
803
813
  &self,
804
814
  secret_key: &VaultSecretKey,
805
815
  payment_option: &PaymentOption,
806
816
  user_data: &UserData,
807
817
  ) -> Result</* AttoTokens */ String> {
808
818
  self.0
809
- .put_user_data_to_vault(&secret_key.0, payment_option.0.clone(), user_data.0.clone())
819
+ .vault_put_user_data(&secret_key.0, payment_option.0.clone(), user_data.0.clone())
810
820
  .await
811
821
  .map(|c| c.to_string())
812
822
  .map_err(map_error)
@@ -816,15 +826,11 @@ impl Client {
816
826
  ///
817
827
  /// Returns the content type of the bytes in the vault.
818
828
  #[napi]
819
- pub async fn fetch_and_decrypt_vault(
829
+ pub async fn vault_get(
820
830
  &self,
821
831
  secret_key: &VaultSecretKey,
822
832
  ) -> Result</* (Bytes, VaultContentType) */ tuple_result::FetchAndDecryptVault> {
823
- let (data, content_type) = self
824
- .0
825
- .fetch_and_decrypt_vault(&secret_key.0)
826
- .await
827
- .map_err(map_error)?;
833
+ let (data, content_type) = self.0.vault_get(&secret_key.0).await.map_err(map_error)?;
828
834
 
829
835
  Ok(tuple_result::FetchAndDecryptVault { data, content_type })
830
836
  }
@@ -855,7 +861,7 @@ impl Client {
855
861
  /// It is recommended to use the hash of the app name or unique identifier as the content type.
856
862
 
857
863
  #[napi]
858
- pub async fn write_bytes_to_vault(
864
+ pub async fn vault_put(
859
865
  &self,
860
866
  data: Buffer,
861
867
  payment_option: &PaymentOption,
@@ -865,7 +871,7 @@ impl Client {
865
871
  let data = Bytes::copy_from_slice(&data);
866
872
 
867
873
  self.0
868
- .write_bytes_to_vault(
874
+ .vault_put(
869
875
  data,
870
876
  payment_option.0.clone(),
871
877
  &secret_key.0,
@@ -876,6 +882,46 @@ impl Client {
876
882
  .map_err(map_error)
877
883
  }
878
884
 
885
+ /// @deprecated Use `vault_get_user_data` instead. This function will be removed in a future version.
886
+ #[napi]
887
+ pub async fn get_user_data_from_vault(&self, secret_key: &VaultSecretKey) -> Result<UserData> {
888
+ self.vault_get_user_data(secret_key).await
889
+ }
890
+
891
+ /// @deprecated Use `vault_put_user_data` instead. This function will be removed in a future version.
892
+ #[napi]
893
+ pub async fn put_user_data_to_vault(
894
+ &self,
895
+ secret_key: &VaultSecretKey,
896
+ payment_option: &PaymentOption,
897
+ user_data: &UserData,
898
+ ) -> Result</* AttoTokens */ String> {
899
+ self.vault_put_user_data(secret_key, payment_option, user_data)
900
+ .await
901
+ }
902
+
903
+ /// @deprecated Use `vault_get` instead. This function will be removed in a future version.
904
+ #[napi]
905
+ pub async fn fetch_and_decrypt_vault(
906
+ &self,
907
+ secret_key: &VaultSecretKey,
908
+ ) -> Result</* (Bytes, VaultContentType) */ tuple_result::FetchAndDecryptVault> {
909
+ self.vault_get(secret_key).await
910
+ }
911
+
912
+ /// @deprecated Use `vault_put` instead. This function will be removed in a future version.
913
+ #[napi]
914
+ pub async fn write_bytes_to_vault(
915
+ &self,
916
+ data: Buffer,
917
+ payment_option: &PaymentOption,
918
+ secret_key: &VaultSecretKey,
919
+ content_type: &VaultContentType,
920
+ ) -> Result</* AttoTokens */ String> {
921
+ self.vault_put(data, payment_option, secret_key, content_type)
922
+ .await
923
+ }
924
+
879
925
  // Registers
880
926
 
881
927
  /// Get the register history, starting from the root to the latest entry.
@@ -1569,6 +1615,15 @@ impl TransactionConfig {
1569
1615
  }
1570
1616
  }
1571
1617
 
1618
+ /// Payment strategy for uploads
1619
+ #[napi]
1620
+ pub enum PaymentMode {
1621
+ /// Default mode: Pay 3 nodes
1622
+ Standard,
1623
+ /// Alternative mode: Pay only the median priced node with 3x the quoted amount
1624
+ SingleNode,
1625
+ }
1626
+
1572
1627
  /// Options for making payments on the network
1573
1628
  #[napi]
1574
1629
  pub struct PaymentOption(autonomi::client::payment::PaymentOption);