Skip to content
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

keyring: remove lazy_static public keys hash maps #2387

Merged
merged 38 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
8ac1a1a
keyring: remove lazy_static hash maps
michalkucharczyk Nov 17, 2023
599045c
license fix
michalkucharczyk Nov 17, 2023
a76af76
no static cache
michalkucharczyk Nov 17, 2023
97bca05
missing change
michalkucharczyk Nov 17, 2023
e2121ca
sr25519+bandersnatch
michalkucharczyk Nov 20, 2023
8d2ea05
Merge branch 'master' into mku-remove-lazy-static-from-keyring
michalkucharczyk Nov 20, 2023
88ae185
Merge branch 'master' into mku-remove-lazy-static-from-keyring
michalkucharczyk Nov 21, 2023
25a0a89
public() method uses raw bytes
michalkucharczyk Nov 23, 2023
1a227a0
fix
michalkucharczyk Nov 24, 2023
981eade
Merge remote-tracking branch 'origin/master' into mku-remove-lazy-sta…
michalkucharczyk Nov 24, 2023
ebd6260
const fn hex2array util added
michalkucharczyk Nov 24, 2023
7d6d327
Merge branch 'master' into mku-remove-lazy-static-from-keyring
michalkucharczyk Nov 24, 2023
8d94b6b
hex2arr moved to sp_core
michalkucharczyk Nov 24, 2023
192a021
const keys added
michalkucharczyk Nov 25, 2023
84fccb0
one more try
michalkucharczyk Nov 25, 2023
006452b
Merge branch 'master' into mku-remove-lazy-static-from-keyring
michalkucharczyk Nov 25, 2023
9b90651
debugs removed
michalkucharczyk Nov 25, 2023
b1a0f00
".git/.scripts/commands/fmt/fmt.sh"
Nov 25, 2023
ae69b21
Merge branch 'master' into mku-remove-lazy-static-from-keyring
michalkucharczyk Nov 27, 2023
2e716dd
Merge branch 'master' into mku-remove-lazy-static-from-keyring
michalkucharczyk Nov 28, 2023
bcaacc6
hex2array: more tests + better doc
michalkucharczyk Nov 28, 2023
bfd8f05
Apply suggestions from code review
michalkucharczyk Nov 28, 2023
1406b91
better test
michalkucharczyk Nov 28, 2023
ab13181
doc fixed
michalkucharczyk Nov 28, 2023
f01fe2f
test simplified
michalkucharczyk Nov 28, 2023
1372cef
Merge branch 'master' into mku-remove-lazy-static-from-keyring
michalkucharczyk Dec 1, 2023
1649b92
Merge branch 'master' into mku-remove-lazy-static-from-keyring
michalkucharczyk Dec 1, 2023
8aab10a
Merge branch 'master' into mku-remove-lazy-static-from-keyring
michalkucharczyk Dec 6, 2023
96c3574
macro added
michalkucharczyk Dec 8, 2023
5697147
Merge remote-tracking branch 'origin/master' into mku-remove-lazy-sta…
michalkucharczyk Dec 8, 2023
62ba4f4
Apply suggestions from code review
michalkucharczyk Dec 8, 2023
b278916
fixes
michalkucharczyk Dec 8, 2023
0f7cccc
better naming
michalkucharczyk Dec 8, 2023
b725ac4
Apply suggestions from code review
michalkucharczyk Dec 8, 2023
b38e666
".git/.scripts/commands/update-ui/update-ui.sh"
Dec 8, 2023
ac8361f
Revert "".git/.scripts/commands/update-ui/update-ui.sh""
michalkucharczyk Dec 11, 2023
c8b2c2d
Merge branch 'master' into mku-remove-lazy-static-from-keyring
michalkucharczyk Dec 11, 2023
8e0d00e
Merge branch 'master' into mku-remove-lazy-static-from-keyring
michalkucharczyk Dec 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion substrate/primitives/core/src/const_hex2array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,19 @@
//! Provides a const function for converting a hex string to a `u8` array at compile time, when used
//! in the proper context.

/// Util that generates array from (static) string literal.
/// Provides a const array from given string literal.
///
/// Valid characters are `[0-9a-fA-F]`, and the hex string should not start
/// with the `0x` prefix.
#[macro_export]
macro_rules! hex2arr {
michalkucharczyk marked this conversation as resolved.
Show resolved Hide resolved
($input:expr) => {{
const PUBLIC_BYTES: [u8; $input.len() >> 1] = $crate::const_hex2array::hex2array($input);
PUBLIC_BYTES
michalkucharczyk marked this conversation as resolved.
Show resolved Hide resolved
}};
}

/// Generates array from (static) string literal.
///
/// Valid characters are `[0-9a-fA-F]`, and the hex string should not start
/// with the `0x` prefix.
Expand All @@ -31,6 +43,7 @@
///
/// The function will panic at runtime when used in a non-const context if the above conditions are
/// met.
#[doc(hidden)]
pub const fn hex2array<const N: usize>(hex: &str) -> [u8; N] {
michalkucharczyk marked this conversation as resolved.
Show resolved Hide resolved
const fn c2b(c: u8) -> u8 {
match c as char {
Expand Down Expand Up @@ -104,6 +117,16 @@ mod testh2b {
assert_eq!(T1, [69, 69]);
}

#[test]
fn t02m() {
assert_eq!(hex2arr!("0a10"), [10, 16]);
assert_eq!(hex2arr!("4545"), [69, 69]);
assert_eq!(
hex2arr!("000102030405060708090a0b0c0d0e0f"),
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
);
}

#[test]
fn t16() {
const T16: [u8; 16] = hex2array("000102030405060708090a0b0c0d0e0f");
Expand Down
10 changes: 1 addition & 9 deletions substrate/primitives/keyring/src/bandersnatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@
pub use sp_core::bandersnatch;
use sp_core::{
bandersnatch::{Pair, Public, Signature},
const_hex2array::hex2array as hex2arr,
crypto::UncheckedFrom,
ByteArray, Pair as PairT,
hex2arr, ByteArray, Pair as PairT,
};

/// Set of test accounts.
Expand Down Expand Up @@ -139,13 +138,6 @@ impl From<Keyring> for Pair {
}
}

macro_rules! hex2arr {
($input:expr) => {{
const PUBLIC_BYTES: [u8; PUBLIC_RAW_LEN] = hex2arr($input);
PUBLIC_BYTES
}};
}

impl From<Keyring> for [u8; PUBLIC_RAW_LEN] {
fn from(k: Keyring) -> Self {
match k {
Expand Down
12 changes: 2 additions & 10 deletions substrate/primitives/keyring/src/ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@

pub use sp_core::ed25519;
use sp_core::{
const_hex2array::hex2array as hex2arr,
ed25519::{Pair, Public, Signature},
ByteArray, Pair as PairT, H256,
hex2arr, ByteArray, Pair as PairT, H256,
};
use sp_runtime::AccountId32;

Expand Down Expand Up @@ -145,20 +144,13 @@ impl From<Keyring> for Pair {
}
}

macro_rules! hex2arr {
($input:expr) => {{
const PUBLIC_BYTES: [u8; 32] = hex2arr($input);
PUBLIC_BYTES
}};
}

impl From<Keyring> for [u8; 32] {
fn from(k: Keyring) -> Self {
match k {
Keyring::Alice =>
hex2arr!("88dc3417d5058ec4b4503e0c12ea1a0a89be200fe98922423d4334014fa6b0ee"),
Keyring::Bob =>
hex2arr("d17c2d7823ebf260fd138f2d7e27d114c0145d968b5ff5006125f2414fadae69"),
hex2arr!("d17c2d7823ebf260fd138f2d7e27d114c0145d968b5ff5006125f2414fadae69"),
Keyring::Charlie =>
hex2arr!("439660b36c6c03afafca027b910b4fecf99801834c62a5e6006f27d978de234f"),
Keyring::Dave =>
Expand Down
9 changes: 1 addition & 8 deletions substrate/primitives/keyring/src/sr25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

pub use sp_core::sr25519;
use sp_core::{
const_hex2array::hex2array as hex2arr,
hex2arr,
sr25519::{Pair, Public, Signature},
ByteArray, Pair as PairT, H256,
};
Expand Down Expand Up @@ -182,13 +182,6 @@ impl From<Keyring> for Pair {
}
}

macro_rules! hex2arr {
($input:expr) => {{
const PUBLIC_BYTES: [u8; 32] = hex2arr($input);
PUBLIC_BYTES
}};
}

impl From<Keyring> for [u8; 32] {
fn from(k: Keyring) -> Self {
match k {
Expand Down