Skip to content

Commit a5e1b4a

Browse files
authored
Merge pull request #1099 from ProvableHQ/rr-use-value-type-for-signatures
[Feature] Add signing methods for Plaintext and Record types
2 parents 627631e + d507379 commit a5e1b4a

File tree

8 files changed

+690
-233
lines changed

8 files changed

+690
-233
lines changed

docs/api_reference/sdk-src_wasm.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,21 @@ __*return*__ | [Field](sdk-src_wasm.md) | *The transition view key.*
814814

815815
---
816816

817+
### `decryptSender(view_key, record, sender_ciphertext) ► Address`
818+
819+
![modifier: public](images/badges/modifier-public.svg) ![modifier: static](images/badges/modifier-static.svg)
820+
821+
Decrypt the sender ciphertext associated with a record.
822+
823+
Parameters | Type | Description
824+
--- | --- | ---
825+
__view_key__ | `ViewKey` | *View key associated with the record.*
826+
__record__ | [RecordPlaintext](sdk-src_wasm.md) | *Record plaintext associated with a sender.*
827+
__sender_ciphertext__ | [Field](sdk-src_wasm.md) | *Sender ciphertext associated with the record.*
828+
__*return*__ | [Address](sdk-src_wasm.md) | *address of the sender.*
829+
830+
---
831+
817832
### `checkOwnedRecords(view_key, records) ► Vec.<RecordCiphertext>`
818833

819834
![modifier: public](images/badges/modifier-public.svg) ![modifier: static](images/badges/modifier-static.svg)
@@ -842,6 +857,20 @@ __*return*__ | `vec.<RecordPlaintext>` | *The decrypted record plaintexts.*
842857

843858
---
844859

860+
### `decryptSenderWithRvk(record_view_key, sender_ciphertext) ► Address`
861+
862+
![modifier: public](images/badges/modifier-public.svg) ![modifier: static](images/badges/modifier-static.svg)
863+
864+
Decrypt the sender ciphertext associated with the record with the record view key.
865+
866+
Parameters | Type | Description
867+
--- | --- | ---
868+
__record_view_key__ | [Field](sdk-src_wasm.md) | *Record view key associated with the record.*
869+
__sender_ciphertext__ | [Field](sdk-src_wasm.md) | *Sender ciphertext associated with the record.*
870+
__*return*__ | [Address](sdk-src_wasm.md) | *the address of the sender.*
871+
872+
---
873+
845874
### `generateRecordViewKey(view_key, record_ciphertext) ► Field`
846875

847876
![modifier: public](images/badges/modifier-public.svg) ![modifier: static](images/badges/modifier-static.svg)
@@ -1863,6 +1892,19 @@ __*return*__ | [PrivateKey](sdk-src_wasm.md) | **
18631892
18641893
## Methods
18651894
1895+
### `sign_value(message) ► Signature`
1896+
1897+
![modifier: public](images/badges/modifier-public.svg)
1898+
1899+
Sign an instance of a valid Aleo data type or record.
1900+
1901+
Parameters | Type | Description
1902+
--- | --- | ---
1903+
__message__ | `String` | *The string representation of the Aleo datatype or record to sign.*
1904+
__*return*__ | [Signature](sdk-src_wasm.md) | *Signature of the message.*
1905+
1906+
---
1907+
18661908
### `to_address() ► Address`
18671909
18681910
![modifier: public](images/badges/modifier-public.svg)
@@ -3172,6 +3214,20 @@ __*return*__ | [RecordPlaintext](sdk-src_wasm.md) | *The record plaintext.*
31723214
31733215
---
31743216
3217+
### `decryptSender(view_key, sender_ciphertext) ► Address`
3218+
3219+
![modifier: public](images/badges/modifier-public.svg)
3220+
3221+
Decrypt the sender ciphertext associated with the record.
3222+
3223+
Parameters | Type | Description
3224+
--- | --- | ---
3225+
__view_key__ | `ViewKey` | *View key associated with the record.*
3226+
__sender_ciphertext__ | [Field](sdk-src_wasm.md) | *Sender ciphertext associated with the record.*
3227+
__*return*__ | [Address](sdk-src_wasm.md) | *address of the sender.*
3228+
3229+
---
3230+
31753231
### `recordViewKey(view_key) ► Group`
31763232
31773233
![modifier: public](images/badges/modifier-public.svg)
@@ -3537,6 +3593,20 @@ Cryptographic signature of a message signed by an Aleo account
35373593
35383594
## Methods
35393595
3596+
### `signValue(private_key, message) ► Signature`
3597+
3598+
![modifier: public](images/badges/modifier-public.svg) ![modifier: static](images/badges/modifier-static.svg)
3599+
3600+
Sign an instance of a valid Aleo data type or record.
3601+
3602+
Parameters | Type | Description
3603+
--- | --- | ---
3604+
__private_key__ | [PrivateKey](sdk-src_wasm.md) | *The private key used to sign the message.*
3605+
__message__ | `String` | *The string representation of the Aleo datatype or record to sign.*
3606+
__*return*__ | [Signature](sdk-src_wasm.md) | *Signature of the message.*
3607+
3608+
---
3609+
35403610
### `to_address() ► Address`
35413611
35423612
![modifier: public](images/badges/modifier-public.svg)
@@ -3611,6 +3681,20 @@ __*return*__ | [Plaintext](sdk-src_wasm.md) | **
36113681
36123682
---
36133683
3684+
### `verifyValue(address, message) ► boolean`
3685+
3686+
![modifier: public](images/badges/modifier-public.svg)
3687+
3688+
Verify a signature over an Aleo datatype or record by an address.
3689+
3690+
Parameters | Type | Description
3691+
--- | --- | ---
3692+
__address__ | [Address](sdk-src_wasm.md) | *The address used to verify the signature.*
3693+
__message__ | `String` | *The message to verify, which must be the string representation of a valid Aleo datatype or record.*
3694+
__*return*__ | `boolean` | *True if the signature is valid, false otherwise.*
3695+
3696+
---
3697+
36143698
### `fromBytesLe(bytes) ► Signature`
36153699
36163700
![modifier: public](images/badges/modifier-public.svg) ![modifier: static](images/badges/modifier-static.svg)

wasm/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@provablehq/wasm",
33
"version": "0.9.8",
4-
"type":"module",
4+
"type": "module",
55
"description": "SnarkVM WASM binaries with javascript bindings",
66
"collaborators": [
77
"The Provable Team"
@@ -43,8 +43,8 @@
4343
},
4444
"devDependencies": {
4545
"@rollup/plugin-virtual": "^3.0.2",
46-
"@wasm-tool/rollup-plugin-rust": "^3.0.4",
47-
"binaryen": "^121.0.0",
46+
"@wasm-tool/rollup-plugin-rust": "^3.0.5",
47+
"binaryen": "^124.0.0",
4848
"rimraf": "^6.0.1",
4949
"rollup": "^4.32.0"
5050
}

wasm/src/account/private_key.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,15 @@ impl PrivateKey {
100100
Signature::sign(self, message)
101101
}
102102

103+
/// Sign an instance of a valid Aleo data type or record.
104+
///
105+
/// @param {String} message The string representation of the Aleo datatype or record to sign.
106+
/// @returns {Signature} Signature of the message.
107+
#[wasm_bindgen(js_name = "signValue")]
108+
pub fn sign_value(&self, message: &str) -> Result<Signature, String> {
109+
Ok(Signature::sign_value(self, message)?)
110+
}
111+
103112
/// Get a new randomly generated private key ciphertext using a secret. The secret is sensitive
104113
/// and will be needed to decrypt the private key later, so it should be stored securely
105114
///
@@ -261,4 +270,19 @@ mod tests {
261270
assert!(signature.verify_bytes(&private_key.to_address(), &message));
262271
}
263272
}
273+
274+
#[wasm_bindgen_test]
275+
pub fn test_signature_over_fields() {
276+
for _ in 0..ITERATIONS {
277+
// Sample a new private key and message.
278+
let private_key = PrivateKey::new();
279+
let rand_val: u64 = StdRng::from_entropy().gen();
280+
let message = format!("{rand_val}field");
281+
282+
// Sign the message.
283+
let signature = private_key.sign_value(&message).unwrap();
284+
// Check the signature is valid.
285+
assert!(signature.verify_value(&private_key.to_address(), &message).unwrap());
286+
}
287+
}
264288
}

0 commit comments

Comments
 (0)