forked from FuelLabs/sway
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add ecr lib * Add todo comment * Add recover_pubkey and refactor ecr * Fixup * Update comments * Add comments to ec-recover asm block * Modify asm * Clean up asm * Fix B512 field assignment * Fix ordering of lib deps * Remove ec_recover, to be added in separate PR * Clean up comments
- Loading branch information
Showing
2 changed files
with
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
library ecr; | ||
|
||
use ::b512::B512; | ||
use ::address::Address; | ||
|
||
/// Recover the address derived from the private key used to sign a message | ||
pub fn ec_recover_address(signature: B512, msg_hash: b256) -> Address { | ||
let address = asm(pub_key_buffer, sig_ptr: signature.hi, hash: msg_hash, addr_buffer, sixty_four: 64) { | ||
move pub_key_buffer sp; // mv sp to pub_key result buffer. | ||
cfei i64; | ||
ecr pub_key_buffer sig_ptr hash; // recover public_key from sig & hash | ||
move addr_buffer sp; // mv sp to addr result buffer. | ||
cfei i32; | ||
s256 addr_buffer pub_key_buffer sixty_four; // hash 64 bytes to the addr_buffer | ||
addr_buffer: b256 | ||
}; | ||
|
||
~Address::from(address) | ||
} |
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 |
---|---|---|
|
@@ -10,5 +10,6 @@ dep context; | |
dep address; | ||
dep block; | ||
dep result; | ||
dep ecr; | ||
|
||
use core::*; |