-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### What Expose `secp256k1` and `keccak256` in the SDK. ### Why `secp256k1` is a widely used cryptographic signature algorithm and `keccak256` is a widely used hashing algorithm. Exposing these functions will allow smart contract developers to utilize these algorithms in their applications without having to implement them themselves. ### Follow on work * ~Pending [this discussion](#1023 (comment)) on best practices I will call `check_env` where applicable.~ ### Known limitations N/A ------ **Github Issue**: [surface new crypto functions in SDK](#970) --------- Co-authored-by: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com>
- Loading branch information
1 parent
4efef11
commit b5cc44a
Showing
4 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use crate::{bytesn, Env, IntoVal}; | ||
|
||
#[test] | ||
fn test_keccak256() { | ||
let env = Env::default(); | ||
|
||
let bytes = b"test vector for soroban".into_val(&env); | ||
let expect = bytesn!( | ||
&env, | ||
0x352fe2eaddf44eb02eb3eab1f8d6ff4ba426df4f1734b1e3f210d621ee8853d9 | ||
); | ||
assert_eq!(env.crypto().keccak256(&bytes), expect); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use crate::{bytesn, Env}; | ||
|
||
#[test] | ||
fn test_recover_key_ecdsa_secp256k1() { | ||
let env = Env::default(); | ||
|
||
// From: https://github.com/ethereum/go-ethereum/blob/90d5bd85bcf2919ac2735a47fde675213348a0a6/crypto/secp256k1/secp256_test.go#L204-L217 | ||
let message_digest = bytesn!( | ||
&env, | ||
0xce0677bb30baa8cf067c88db9811f4333d131bf8bcf12fe7065d211dce971008 | ||
); | ||
let signature = bytesn!( | ||
&env, | ||
0x90f27b8b488db00b00606796d2987f6a5f59ae62ea05effe84fef5b8b0e549984a691139ad57a3f0b906637673aa2f63d1f55cb1a69199d4009eea23ceaddc93 | ||
); | ||
let recovery_id = 1; | ||
let expected_public_key = bytesn!( | ||
&env, | ||
0x04e32df42865e97135acfb65f3bae71bdc86f4d49150ad6a440b6f15878109880a0a2b2667f7e725ceea70c673093bf67663e0312623c8e091b13cf2c0f11ef652 | ||
); | ||
assert_eq!( | ||
env.crypto() | ||
.secp256k1_recover(&message_digest, &signature, recovery_id), | ||
expected_public_key | ||
); | ||
} |