Skip to content

Commit 1fec577

Browse files
committed
expanded docstrings for methods without full return type descriptions
1 parent e17086b commit 1fec577

File tree

7 files changed

+60
-0
lines changed

7 files changed

+60
-0
lines changed

wasm/src/ledger/transition.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,22 +176,32 @@ impl Transition {
176176
}
177177

178178
/// Get the transition public key of the transition.
179+
///
180+
/// @returns {Group} Transition public key
179181
pub fn tpk(&self) -> Group {
180182
Group::from(self.0.tpk())
181183
}
182184

183185
/// Get the transition view key of the transition.
186+
///
187+
/// @param {ViewKey} view_key The view key of the transition signer.
188+
///
189+
/// @returns {Field} Transition view key
184190
pub fn tvk(&self, view_key: &ViewKey) -> Field {
185191
let tpk = self.tpk();
186192
tpk.scalar_multiply(&view_key.to_scalar()).to_x_coordinate()
187193
}
188194

189195
/// Get the transition commitment of the transition.
196+
///
197+
/// @returns {Field} Transition commitment
190198
pub fn tcm(&self) -> Field {
191199
Field::from(self.0.tcm())
192200
}
193201

194202
/// Get the transition signer commitment of the transition.
203+
///
204+
/// @returns {Field} Transition signer commitment
195205
pub fn scm(&self) -> Field {
196206
Field::from(self.0.scm())
197207
}

wasm/src/programs/data/ciphertext.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ impl Ciphertext {
5757

5858
/// Decrypt a ciphertext using the view key of the transition signer, transition public key, and
5959
/// (program, function, index) tuple.
60+
///
61+
/// @param {ViewKey} view_key The view key of the transition signer.
62+
/// @param {Group} transition_public_key The transition public key used to encrypt the ciphertext.
63+
/// @param {string} program The program ID of the function that encrypted the ciphertext.
64+
/// @param {string} function_name The function name that encrypted the ciphertext.
65+
/// @param {u16} index The index of the input parameter that was encrypted.
66+
///
67+
/// @returns {Plaintext} The decrypted plaintext.
6068
#[wasm_bindgen(js_name = decryptWithTransitionInfo)]
6169
pub fn decrypt_with_transition_info(
6270
&self,
@@ -82,6 +90,13 @@ impl Ciphertext {
8290
}
8391

8492
/// Decrypt a ciphertext using the transition view key and a (program, function, index) tuple.
93+
///
94+
/// @param {Field} transition_view_key The transition view key that was used to encrypt the ciphertext.
95+
/// @param {string} program The program ID of the function that encrypted the ciphertext.
96+
/// @param {string} function_name The function name that encrypted the ciphertext.
97+
/// @param {u16} index The index of the input parameter that was encrypted.
98+
///
99+
/// @returns {Plaintext} The decrypted plaintext.
85100
#[wasm_bindgen(js_name = decryptWithTransitionViewKey)]
86101
pub fn decrypt_with_transition_view_key(
87102
&self,

wasm/src/programs/data/plaintext.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,21 @@ impl Plaintext {
7373
}
7474

7575
/// Encrypt a plaintext with an address and randomizer.
76+
///
77+
/// @param {Address} address The address to encrypt the plaintext for.
78+
/// @param {Scalar} randomizer The randomizer to use for encryption.
79+
///
80+
/// @returns {Ciphertext} The encrypted ciphertext.
81+
#[wasm_bindgen(js_name = encrypt)]
7682
pub fn encrypt(&self, address: &Address, randomizer: &Scalar) -> Result<Ciphertext, String> {
7783
self.0.encrypt(address, **randomizer).map_err(|e| e.to_string()).map(Ciphertext::from)
7884
}
7985

8086
/// Encrypt a plaintext with a transition view key.
87+
///
88+
/// @param {Field} transition_view_key The transition view key to use for encryption.
89+
///
90+
/// @returns {Ciphertext} The encrypted ciphertext.
8191
#[wasm_bindgen(js_name = encryptSymmetric)]
8292
pub fn encrypt_symmetric(&self, transition_view_key: &Field) -> Result<Ciphertext, String> {
8393
self.0.encrypt_symmetric(**transition_view_key).map_err(|e| e.to_string()).map(Ciphertext::from)
@@ -106,6 +116,8 @@ impl Plaintext {
106116
}
107117

108118
/// Get the left endian byte array representation of the plaintext.
119+
///
120+
/// @returns {Uint8Array} The left endian byte array representation of the plaintext.
109121
#[wasm_bindgen(js_name = "toBytesLe")]
110122
pub fn to_bytes_le(&self) -> Result<Uint8Array, String> {
111123
let rust_bytes = self.0.to_bytes_le().map_err(|e| e.to_string())?;
@@ -125,6 +137,8 @@ impl Plaintext {
125137
}
126138

127139
/// Get the left endian boolean array representation of the bits of the plaintext.
140+
///
141+
/// @returns {Array} The left endian boolean array representation of the bits of the plaintext.
128142
#[wasm_bindgen(js_name = "toBitsLe")]
129143
pub fn to_bits_le(&self) -> Array {
130144
to_bits_array_le!(self)
@@ -143,6 +157,8 @@ impl Plaintext {
143157
}
144158

145159
/// Get the field array representation of the plaintext.
160+
///
161+
/// @returns {Array} The field array representation of the plaintext.
146162
#[wasm_bindgen(js_name = "toFields")]
147163
pub fn to_fields(&self) -> Result<Array, String> {
148164
let native = self.0.clone();

wasm/src/programs/offline_query.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,17 @@ impl OfflineQuery {
6464
}
6565

6666
/// Get a json string representation of the offline query object
67+
///
68+
/// @returns {string} JSON string representation of the offline query object
6769
#[wasm_bindgen(js_name = "toString")]
6870
#[allow(clippy::inherent_to_string)]
6971
pub fn to_string(&self) -> String {
7072
serde_json::to_string(&self).unwrap()
7173
}
7274

7375
/// Create an offline query object from a json string representation
76+
///
77+
/// @param {string} s JSON string representation of the offline query object
7478
#[wasm_bindgen(js_name = "fromString")]
7579
pub fn from_string(s: &str) -> Result<OfflineQuery, String> {
7680
serde_json::from_str(s).map_err(|e| e.to_string())

wasm/src/programs/request.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,17 @@ pub struct ExecutionRequest(RequestNative);
4444
#[wasm_bindgen]
4545
impl ExecutionRequest {
4646
/// Returns the request as a string.
47+
///
48+
/// @returns {string} String representation of the request.
4749
#[wasm_bindgen(js_name = "toString")]
4850
#[allow(clippy::inherent_to_string)]
4951
pub fn to_string(&self) -> String {
5052
self.0.to_string()
5153
}
5254

5355
/// Builds a request object from a string representation of a request.
56+
///
57+
/// @param {string} request String representation of the request.
5458
#[wasm_bindgen(js_name = "fromString")]
5559
pub fn from_string(request: String) -> Result<ExecutionRequest, String> {
5660
Ok(ExecutionRequest(RequestNative::from_str(&request).map_err(|e| e.to_string())?))

wasm/src/record/record_ciphertext.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ impl RecordCiphertext {
110110
}
111111

112112
/// Get the left endian byte array representation of the record ciphertext.
113+
///
114+
/// @returns {Uint8Array} Left endian byte array representation of the record ciphertext.
113115
#[wasm_bindgen(js_name = "toBytesLe")]
114116
pub fn to_bytes_le(&self) -> Result<Uint8Array, String> {
115117
let bytes_vec = self.0.to_bytes_le().map_err(|e| e.to_string())?;
@@ -118,12 +120,16 @@ impl RecordCiphertext {
118120
}
119121

120122
/// Get the left endian boolean array representation of the record ciphertext bits.
123+
///
124+
/// returns {Array} Left endian boolean array representation of the bits of the record ciphertext.
121125
#[wasm_bindgen(js_name = "toBitsLe")]
122126
pub fn to_bits_le(&self) -> Array {
123127
to_bits_array_le!(self)
124128
}
125129

126130
/// Get the field array representation of the record ciphertext.
131+
///
132+
/// @returns {Array} Field array representation of the record ciphertext.
127133
#[wasm_bindgen(js_name = "toFields")]
128134
pub fn to_fields(&self) -> Result<Array, String> {
129135
let native = self.0.clone();
@@ -145,6 +151,8 @@ impl RecordCiphertext {
145151
}
146152

147153
/// Get the record nonce.
154+
///
155+
/// @returns {Group} The record nonce.
148156
pub fn nonce(&self) -> Group {
149157
Group::from(self.0.nonce())
150158
}

wasm/src/record/record_plaintext.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ impl RecordPlaintext {
7474
Self::from_str(record).map_err(|_| "The record plaintext string provided was invalid".into())
7575
}
7676

77+
// Get a record plaintext from
7778
#[wasm_bindgen(js_name = getMember)]
7879
pub fn get_member(&self, input: String) -> Result<Plaintext, String> {
7980
let entry = self
@@ -91,6 +92,8 @@ impl RecordPlaintext {
9192
}
9293

9394
/// Get the owner of the record.
95+
///
96+
/// @returns {Address} Address of the owner of the record.
9497
pub fn owner(&self) -> Result<Address, String> {
9598
match self.0.owner() {
9699
Owner::<CurrentNetwork, PlaintextNative>::Public(owner) => Ok(Address::from(*owner)),

0 commit comments

Comments
 (0)