Remove ecr.sw
files and introduce crypto
module
#5747
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
The std-lib currently contains the
ecr.sw
andevm/ecr.sw
files which have the following functions:ec_recover()
ec_recover_r1()
ed_verify()
ec_recover_address()
ec_recover_address_r1()
ec_recover_evm_address()
There are a number of issues with this including no type safety for signatures from different elliptic curves, functions split across multiple files, poor naming, and generic arguments. All of these are resolved by this PR which removes both
ecr.sw
files replaces them with acrypto
module which syntatically matches Rust.The following new types are introduced:
PublicKey
- 64 byte public keyMessege
- Hashed message authenticated by a signatureSecp256k1
- A secp256k1 signatureSecp256r1
- A secp256r1 signatureEd25519
- An ed25519 signatureSignature
- An ECDSA signatureAll original functionally is retained with the new module. The following new functionality is added:
verify()
- Verify that a signature matches given public key. NOTE: Only new functionality for secp256k1 and secp256r1 signatures.verify_address()
- Verify that a signature matches given address.verify_evm_address()
- Verify that a signature matches given evm address.Example of changes for recovering a public key:
Example of changes for recovering an Address:
Complete recovery example using the
Signature
type:Checklist
Breaking*
orNew Feature
labels where relevant.