-
Notifications
You must be signed in to change notification settings - Fork 9
ED25519 and Ethereum String Serialization Support #170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…Ethereum norm. Use a from_string instead of a constructor. Optionally allow for string prefixes on EM strings to encode the type. ED string format not implemented yet.
…t' into feature/key-string-formats
… signature. Remove unneeded padding of ED25519 signature_shim.
…PUB_K1_ & PVT_K1_ prefix.
jglanz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally it looks solid; it's to large to go thru every line, but as long as the test suites are running successfully then all is good
Comments/Notes
- nits
- Use
fc::splitfor string tokenizing instead of boilerplatestd::find - Method naming for
parse wire [priv|pub|sig] unknown
| inline public_key_data deserialize_bls_base64url(const std::string& base64urlstr) { | ||
| using namespace fc::crypto::bls::constants; | ||
| auto res = std::mismatch(bls_public_key_prefix.begin(), bls_public_key_prefix.end(), base64urlstr.begin()); | ||
| FC_ASSERT(res.first == bls_public_key_prefix.end(), "BLS Public Key has invalid format : ${str}", ("str", base64urlstr)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: _FMT macro
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not available on this branch.
| static bls12_381::g1 from_affine_bytes_le(const public_key_data& affine_non_montgomery_le); | ||
| private: | ||
| public_key_data _affine_non_montgomery_le{}; | ||
| public_key_data _affine_non_montgomery_le{}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: whitespace? could just be browser
| } | ||
|
|
||
| static public_key_shim from_string(const std::string& str) { | ||
| constexpr size_t max_key_len = 44; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this equivalent to key data_size literals? If yes, move up to key_type types?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are max lengths for base58 encoding. Probably best thing would be to rename this to from_base58_string()
| } | ||
|
|
||
| // Given PUB_K1_xxx returns <'PUB','K1','xxx'> | ||
| inline std::tuple<std::string, std::string, std::string> parse_base_prefixes(std::string_view str) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use fc::split
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fc::split actually doesn't work because BLS strings can have _ in them. For example: PUB_BLS_no1gZTuy-0iL_FVrc6q4ow5KtTtdv6ZQ3Cq73Jwl32qRNC9AEQaWsESaoN4Y9NAVRmRGnbEekzgo6YlwbztPeoWhWzvHiOALTFKegRXlRxVbM4naOg33cZOSdS25i_MXywteRA
|
|
||
| std::string to_native_string(const fc::yield_function_t& yield) const; | ||
| // If include_prefix is true, the prefix will be included in the string representation. | ||
| // Note for Wire native types (k1, r1, wa, bls) the prefix is always included. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: doc format /**
| case key_type::r1: | ||
| case key_type::bls: { | ||
| private_key k(parse_unknown_wire_private_key_str(str)); | ||
| FC_ASSERT( k.type() == type, "Parsed type ${pt} does not match specified type ${t} for ${k}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: _FMT
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not available on this branch.
jglanz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
read other notes first
Not sure what this is referring to? |
This PR changes standardized string serialization and deserialization for Solana Ed25519 (ED) and Ethereum (EM) cryptographic types. It enables conversion between native string formats (e.g., Solana-style Base58 for ED25519 and Hex for Ethereum) and the project's internal
public_key,private_key, andsignaturestorage types.Changes
fc::cryptotype changesfc::cryptopublic_key,private_key,signaturetypes now have afrom_string()instead of constructors for converting from a string. Thefrom_stringtakes an optional type for specification of the type of key/signature to create. If the defaultunknownis provided then the prefix strings likePUB_ED_is required so that the type can be inferred from the string.to_string()now takes abool include_prefixdefaulting tofalse. Iftruethen the type prefix, e.g.PUB_ED_is added to the string. This is useful for knowing how to parse the string according to its type. If the defaultfalseis provided then the prefix is not included. This currently only affects ED and EM as other existing Wire types like R1 and BLS always provide the prefix since that is part of their "native" string representation.Ed25519 String Formatting
to_stringandfrom_stringmethods topublic_key_shim,private_key_shim, andsignature_shimusing standard Ed25519 Base58 encoding.from_native_string_to_signature<chain_key_type_solana>inkey_serdes.hpp.Ethereum (EM) String Formatting
to_stringandfrom_stringfor Ethereum types, supporting standard hexadecimal representations for keys and signatures.signature.cppandprivate_key.cppto correctly routeemtypes to Ethereum-specific hex utilities viakey_serdes.hpp.Unified Prefix Support
Updated parsing logic to support the following project-standardized prefixes:
PVT_ED_,PUB_ED_, andSIG_ED_.PVT_EM_,PUB_EM_, andSIG_EM_.PUB_EM_0x04e68a...=>0x04e68a....clioupdatesclio create key --k1which will generate K1 keys withPUB_K1_&PVT_K1_prefix.clio convert k1_public_keywhich will read either form of K1 key and output both.clio convert k1_private_keywhich will read either form of K1 key and output private key and public key in both formats.PR also removes unneeded padding from ED
signature_shim.Noticed this: AntelopeIO/spring#1561 after creating the pull request. Need to consider how these changes can co-exist.