Skip to content

Commit

Permalink
feat!: remove public key from ed25519 private key (#4856)
Browse files Browse the repository at this point in the history
Signed-off-by: Shanin Roman <[email protected]>
  • Loading branch information
Erigara authored Jul 17, 2024
1 parent 537e595 commit d971c1a
Show file tree
Hide file tree
Showing 17 changed files with 114 additions and 71 deletions.
2 changes: 1 addition & 1 deletion client/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ mod tests {
[account]
domain = "wonderland"
public_key = "ed0120CE7FA46C9DCE7EA4B125E2E36BDB63EA33073E7590AC92816AE1E861B7048B03"
private_key = "802640CCF31D85E3B32A4BEA59987CE0C78E3B8E2DB93881468AB2435FE45D5C9DCD53CE7FA46C9DCE7EA4B125E2E36BDB63EA33073E7590AC92816AE1E861B7048B03"
private_key = "802620CCF31D85E3B32A4BEA59987CE0C78E3B8E2DB93881468AB2435FE45D5C9DCD53"

[transaction]
time_to_live_ms = 100_000
Expand Down
3 changes: 2 additions & 1 deletion client/tests/integration/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ use test_samples::{ALICE_ID, BOB_ID};

const ADMIN_PUBLIC_KEY_MULTIHASH: &str =
"ed012076E5CA9698296AF9BE2CA45F525CB3BCFDEB7EE068BA56F973E9DD90564EF4FC";
const ADMIN_PRIVATE_KEY_MULTIHASH: &str = "802640A4DE33BCA99A254ED6265D1F0FB69DFE42B77F89F6C2E478498E1831BF6D81F276E5CA9698296AF9BE2CA45F525CB3BCFDEB7EE068BA56F973E9DD90564EF4FC";
const ADMIN_PRIVATE_KEY_MULTIHASH: &str =
"802620A4DE33BCA99A254ED6265D1F0FB69DFE42B77F89F6C2E478498E1831BF6D81F2";

#[test]
fn executor_upgrade_should_work() -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion config/iroha_test_config.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
chain = "00000000-0000-0000-0000-000000000000"
public_key = "ed01201C61FAF8FE94E253B93114240394F79A607B7FA55F9E5A41EBEC74B88055768B"
private_key = "802640282ED9F3CF92811C3818DBC4AE594ED59DC1A2F78E4241E31924E101D6B1FB831C61FAF8FE94E253B93114240394F79A607B7FA55F9E5A41EBEC74B88055768B"
private_key = "802620282ED9F3CF92811C3818DBC4AE594ED59DC1A2F78E4241E31924E101D6B1FB83"

[network]
address = "127.0.0.1:1337"
Expand Down
2 changes: 1 addition & 1 deletion config/tests/fixtures/base.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
chain = "0"
public_key = "ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB"
private_key = "8026408F4C15E5D664DA3F13778801D23D4E89B76E94C1B94B389544168B6CB894F84F8BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB"
private_key = "8026208F4C15E5D664DA3F13778801D23D4E89B76E94C1B94B389544168B6CB894F84F"

[network]
address = "127.0.0.1:1337"
Expand Down
2 changes: 1 addition & 1 deletion config/tests/fixtures/full.env
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CHAIN=0-0
PUBLIC_KEY=ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB
PRIVATE_KEY=8026408F4C15E5D664DA3F13778801D23D4E89B76E94C1B94B389544168B6CB894F84F8BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB
PRIVATE_KEY=8026208F4C15E5D664DA3F13778801D23D4E89B76E94C1B94B389544168B6CB894F84F
P2P_ADDRESS=127.0.0.1:5432
GENESIS_PUBLIC_KEY=ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB
GENESIS=./genesis.signed.scale
Expand Down
2 changes: 1 addition & 1 deletion config/tests/fixtures/full.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

chain = "0"
public_key = "ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB"
private_key = "8026408F4C15E5D664DA3F13778801D23D4E89B76E94C1B94B389544168B6CB894F84F8BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB"
private_key = "8026208F4C15E5D664DA3F13778801D23D4E89B76E94C1B94B389544168B6CB894F84F"

[genesis]
public_key = "ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB"
Expand Down
2 changes: 1 addition & 1 deletion config/tests/fixtures/minimal_file_and_env.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ extends = "base_trusted_peers.toml"

chain = "0"
public_key = "ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB"
private_key = "8026408F4C15E5D664DA3F13778801D23D4E89B76E94C1B94B389544168B6CB894F84F8BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB"
private_key = "8026208F4C15E5D664DA3F13778801D23D4E89B76E94C1B94B389544168B6CB894F84F"

[network]
address = "127.0.0.1:1337"
Expand Down
2 changes: 1 addition & 1 deletion configs/swarm/client.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ password = "ilovetea"
[account]
domain = "wonderland"
public_key = "ed0120CE7FA46C9DCE7EA4B125E2E36BDB63EA33073E7590AC92816AE1E861B7048B03"
private_key = "802640CCF31D85E3B32A4BEA59987CE0C78E3B8E2DB93881468AB2435FE45D5C9DCD53CE7FA46C9DCE7EA4B125E2E36BDB63EA33073E7590AC92816AE1E861B7048B03"
private_key = "802620CCF31D85E3B32A4BEA59987CE0C78E3B8E2DB93881468AB2435FE45D5C9DCD53"
10 changes: 5 additions & 5 deletions configs/swarm/docker-compose.local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ services:
environment:
CHAIN: 00000000-0000-0000-0000-000000000000
PUBLIC_KEY: ed0120A98BAFB0663CE08D75EBD506FEC38A84E576A7C9B0897693ED4B04FD9EF2D18D
PRIVATE_KEY: 802640A4DFC16789FBF9A588525E4AC7F791AC51B12AEE8919EACC03EB2FC31D32C692A98BAFB0663CE08D75EBD506FEC38A84E576A7C9B0897693ED4B04FD9EF2D18D
PRIVATE_KEY: 802620A4DFC16789FBF9A588525E4AC7F791AC51B12AEE8919EACC03EB2FC31D32C692
P2P_ADDRESS: 0.0.0.0:1337
API_ADDRESS: 0.0.0.0:8080
GENESIS_PUBLIC_KEY: ed01204164BF554923ECE1FD412D241036D863A6AE430476C898248B8237D77534CFC4
TRUSTED_PEERS: '[{"address":"irohad2:1339","public_key":"ed01204EE2FCD53E1730AF142D1E23951198678295047F9314B4006B0CB61850B1DB10"},{"address":"irohad1:1338","public_key":"ed01209897952D14BDFAEA780087C38FF3EB800CB20B882748FC95A575ADB9CD2CB21D"},{"address":"irohad3:1340","public_key":"ed0120CACF3A84B8DC8710CE9D6B968EE95EC7EE4C93C85858F026F3B4417F569592CE"}]'
GENESIS_PRIVATE_KEY: 80264082B3BDE54AEBECA4146257DA0DE8D59D8E46D5FE34887DCD8072866792FCB3AD4164BF554923ECE1FD412D241036D863A6AE430476C898248B8237D77534CFC4
GENESIS_PRIVATE_KEY: 80262082B3BDE54AEBECA4146257DA0DE8D59D8E46D5FE34887DCD8072866792FCB3AD
GENESIS: /tmp/genesis.signed.scale
TOPOLOGY: '[{"address":"irohad2:1339","public_key":"ed01204EE2FCD53E1730AF142D1E23951198678295047F9314B4006B0CB61850B1DB10"},{"address":"irohad1:1338","public_key":"ed01209897952D14BDFAEA780087C38FF3EB800CB20B882748FC95A575ADB9CD2CB21D"},{"address":"irohad0:1337","public_key":"ed0120A98BAFB0663CE08D75EBD506FEC38A84E576A7C9B0897693ED4B04FD9EF2D18D"},{"address":"irohad3:1340","public_key":"ed0120CACF3A84B8DC8710CE9D6B968EE95EC7EE4C93C85858F026F3B4417F569592CE"}]'
ports:
Expand Down Expand Up @@ -54,7 +54,7 @@ services:
environment:
CHAIN: 00000000-0000-0000-0000-000000000000
PUBLIC_KEY: ed01209897952D14BDFAEA780087C38FF3EB800CB20B882748FC95A575ADB9CD2CB21D
PRIVATE_KEY: 8026403ECA64ADC23DC106C9D703233375EA6AC345AD7299FF3AD45F355DE6CD1B55109897952D14BDFAEA780087C38FF3EB800CB20B882748FC95A575ADB9CD2CB21D
PRIVATE_KEY: 8026203ECA64ADC23DC106C9D703233375EA6AC345AD7299FF3AD45F355DE6CD1B5510
P2P_ADDRESS: 0.0.0.0:1338
API_ADDRESS: 0.0.0.0:8081
GENESIS_PUBLIC_KEY: ed01204164BF554923ECE1FD412D241036D863A6AE430476C898248B8237D77534CFC4
Expand All @@ -79,7 +79,7 @@ services:
environment:
CHAIN: 00000000-0000-0000-0000-000000000000
PUBLIC_KEY: ed01204EE2FCD53E1730AF142D1E23951198678295047F9314B4006B0CB61850B1DB10
PRIVATE_KEY: 8026407B1C78F733EDAFD6AF9BAC3A0D6C5A494557DD031609A4FDD9796EEF471D928C4EE2FCD53E1730AF142D1E23951198678295047F9314B4006B0CB61850B1DB10
PRIVATE_KEY: 8026207B1C78F733EDAFD6AF9BAC3A0D6C5A494557DD031609A4FDD9796EEF471D928C
P2P_ADDRESS: 0.0.0.0:1339
API_ADDRESS: 0.0.0.0:8082
GENESIS_PUBLIC_KEY: ed01204164BF554923ECE1FD412D241036D863A6AE430476C898248B8237D77534CFC4
Expand All @@ -104,7 +104,7 @@ services:
environment:
CHAIN: 00000000-0000-0000-0000-000000000000
PUBLIC_KEY: ed0120CACF3A84B8DC8710CE9D6B968EE95EC7EE4C93C85858F026F3B4417F569592CE
PRIVATE_KEY: 8026406C7FF4CA09D395C7B7332C654099406E929C6238942E3CE85155CC1A5E2CF519CACF3A84B8DC8710CE9D6B968EE95EC7EE4C93C85858F026F3B4417F569592CE
PRIVATE_KEY: 8026206C7FF4CA09D395C7B7332C654099406E929C6238942E3CE85155CC1A5E2CF519
P2P_ADDRESS: 0.0.0.0:1340
API_ADDRESS: 0.0.0.0:8083
GENESIS_PUBLIC_KEY: ed01204164BF554923ECE1FD412D241036D863A6AE430476C898248B8237D77534CFC4
Expand Down
4 changes: 2 additions & 2 deletions configs/swarm/docker-compose.single.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ services:
environment:
CHAIN: 00000000-0000-0000-0000-000000000000
PUBLIC_KEY: ed0120A98BAFB0663CE08D75EBD506FEC38A84E576A7C9B0897693ED4B04FD9EF2D18D
PRIVATE_KEY: 802640A4DFC16789FBF9A588525E4AC7F791AC51B12AEE8919EACC03EB2FC31D32C692A98BAFB0663CE08D75EBD506FEC38A84E576A7C9B0897693ED4B04FD9EF2D18D
PRIVATE_KEY: 802620A4DFC16789FBF9A588525E4AC7F791AC51B12AEE8919EACC03EB2FC31D32C692
P2P_ADDRESS: 0.0.0.0:1337
API_ADDRESS: 0.0.0.0:8080
GENESIS_PUBLIC_KEY: ed01204164BF554923ECE1FD412D241036D863A6AE430476C898248B8237D77534CFC4
GENESIS_PRIVATE_KEY: 80264082B3BDE54AEBECA4146257DA0DE8D59D8E46D5FE34887DCD8072866792FCB3AD4164BF554923ECE1FD412D241036D863A6AE430476C898248B8237D77534CFC4
GENESIS_PRIVATE_KEY: 80262082B3BDE54AEBECA4146257DA0DE8D59D8E46D5FE34887DCD8072866792FCB3AD
GENESIS: /tmp/genesis.signed.scale
TOPOLOGY: '[{"address":"irohad0:1337","public_key":"ed0120A98BAFB0663CE08D75EBD506FEC38A84E576A7C9B0897693ED4B04FD9EF2D18D"}]'
ports:
Expand Down
10 changes: 5 additions & 5 deletions configs/swarm/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ services:
environment:
CHAIN: 00000000-0000-0000-0000-000000000000
PUBLIC_KEY: ed0120A98BAFB0663CE08D75EBD506FEC38A84E576A7C9B0897693ED4B04FD9EF2D18D
PRIVATE_KEY: 802640A4DFC16789FBF9A588525E4AC7F791AC51B12AEE8919EACC03EB2FC31D32C692A98BAFB0663CE08D75EBD506FEC38A84E576A7C9B0897693ED4B04FD9EF2D18D
PRIVATE_KEY: 802620A4DFC16789FBF9A588525E4AC7F791AC51B12AEE8919EACC03EB2FC31D32C692
P2P_ADDRESS: 0.0.0.0:1337
API_ADDRESS: 0.0.0.0:8080
GENESIS_PUBLIC_KEY: ed01204164BF554923ECE1FD412D241036D863A6AE430476C898248B8237D77534CFC4
TRUSTED_PEERS: '[{"address":"irohad2:1339","public_key":"ed01204EE2FCD53E1730AF142D1E23951198678295047F9314B4006B0CB61850B1DB10"},{"address":"irohad1:1338","public_key":"ed01209897952D14BDFAEA780087C38FF3EB800CB20B882748FC95A575ADB9CD2CB21D"},{"address":"irohad3:1340","public_key":"ed0120CACF3A84B8DC8710CE9D6B968EE95EC7EE4C93C85858F026F3B4417F569592CE"}]'
GENESIS_PRIVATE_KEY: 80264082B3BDE54AEBECA4146257DA0DE8D59D8E46D5FE34887DCD8072866792FCB3AD4164BF554923ECE1FD412D241036D863A6AE430476C898248B8237D77534CFC4
GENESIS_PRIVATE_KEY: 80262082B3BDE54AEBECA4146257DA0DE8D59D8E46D5FE34887DCD8072866792FCB3AD
GENESIS: /tmp/genesis.signed.scale
TOPOLOGY: '[{"address":"irohad2:1339","public_key":"ed01204EE2FCD53E1730AF142D1E23951198678295047F9314B4006B0CB61850B1DB10"},{"address":"irohad1:1338","public_key":"ed01209897952D14BDFAEA780087C38FF3EB800CB20B882748FC95A575ADB9CD2CB21D"},{"address":"irohad0:1337","public_key":"ed0120A98BAFB0663CE08D75EBD506FEC38A84E576A7C9B0897693ED4B04FD9EF2D18D"},{"address":"irohad3:1340","public_key":"ed0120CACF3A84B8DC8710CE9D6B968EE95EC7EE4C93C85858F026F3B4417F569592CE"}]'
ports:
Expand Down Expand Up @@ -49,7 +49,7 @@ services:
environment:
CHAIN: 00000000-0000-0000-0000-000000000000
PUBLIC_KEY: ed01209897952D14BDFAEA780087C38FF3EB800CB20B882748FC95A575ADB9CD2CB21D
PRIVATE_KEY: 8026403ECA64ADC23DC106C9D703233375EA6AC345AD7299FF3AD45F355DE6CD1B55109897952D14BDFAEA780087C38FF3EB800CB20B882748FC95A575ADB9CD2CB21D
PRIVATE_KEY: 8026203ECA64ADC23DC106C9D703233375EA6AC345AD7299FF3AD45F355DE6CD1B5510
P2P_ADDRESS: 0.0.0.0:1338
API_ADDRESS: 0.0.0.0:8081
GENESIS_PUBLIC_KEY: ed01204164BF554923ECE1FD412D241036D863A6AE430476C898248B8237D77534CFC4
Expand All @@ -71,7 +71,7 @@ services:
environment:
CHAIN: 00000000-0000-0000-0000-000000000000
PUBLIC_KEY: ed01204EE2FCD53E1730AF142D1E23951198678295047F9314B4006B0CB61850B1DB10
PRIVATE_KEY: 8026407B1C78F733EDAFD6AF9BAC3A0D6C5A494557DD031609A4FDD9796EEF471D928C4EE2FCD53E1730AF142D1E23951198678295047F9314B4006B0CB61850B1DB10
PRIVATE_KEY: 8026207B1C78F733EDAFD6AF9BAC3A0D6C5A494557DD031609A4FDD9796EEF471D928C
P2P_ADDRESS: 0.0.0.0:1339
API_ADDRESS: 0.0.0.0:8082
GENESIS_PUBLIC_KEY: ed01204164BF554923ECE1FD412D241036D863A6AE430476C898248B8237D77534CFC4
Expand All @@ -93,7 +93,7 @@ services:
environment:
CHAIN: 00000000-0000-0000-0000-000000000000
PUBLIC_KEY: ed0120CACF3A84B8DC8710CE9D6B968EE95EC7EE4C93C85858F026F3B4417F569592CE
PRIVATE_KEY: 8026406C7FF4CA09D395C7B7332C654099406E929C6238942E3CE85155CC1A5E2CF519CACF3A84B8DC8710CE9D6B968EE95EC7EE4C93C85858F026F3B4417F569592CE
PRIVATE_KEY: 8026206C7FF4CA09D395C7B7332C654099406E929C6238942E3CE85155CC1A5E2CF519
P2P_ADDRESS: 0.0.0.0:1340
API_ADDRESS: 0.0.0.0:8083
GENESIS_PUBLIC_KEY: ed01204164BF554923ECE1FD412D241036D863A6AE430476C898248B8237D77534CFC4
Expand Down
Binary file modified configs/swarm/executor.wasm
Binary file not shown.
54 changes: 33 additions & 21 deletions crypto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ impl PrivateKey {
fn payload(&self) -> Vec<u8> {
use crate::secrecy::ExposeSecret;
match self.0.expose_secret() {
PrivateKeyInner::Ed25519(key) => key.to_keypair_bytes().to_vec(),
PrivateKeyInner::Ed25519(key) => key.to_bytes().to_vec(),
PrivateKeyInner::Secp256k1(key) => key.to_bytes().to_vec(),
PrivateKeyInner::BlsNormal(key) => key.to_bytes(),
PrivateKeyInner::BlsSmall(key) => key.to_bytes(),
Expand Down Expand Up @@ -1009,13 +1009,17 @@ mod tests {

#[test]
fn key_pair_match() {
KeyPair::new("ed012059C8A4DA1EBB5380F74ABA51F502714652FDCCE9611FAFB9904E4A3C4D382774"
.parse()
.expect("Public key not in mulithash format"),
PrivateKey::from_hex(
Algorithm::Ed25519,
"93CA389FC2979F3F7D2A7F8B76C70DE6D5EAF5FA58D4F93CB8B0FB298D398ACC59C8A4DA1EBB5380F74ABA51F502714652FDCCE9611FAFB9904E4A3C4D382774"
).expect("Private key not hex encoded")).unwrap();
KeyPair::new(
"ed012059C8A4DA1EBB5380F74ABA51F502714652FDCCE9611FAFB9904E4A3C4D382774"
.parse()
.expect("Public key not in mulithash format"),
PrivateKey::from_hex(
Algorithm::Ed25519,
"93CA389FC2979F3F7D2A7F8B76C70DE6D5EAF5FA58D4F93CB8B0FB298D398ACC",
)
.expect("Private key not hex encoded"),
)
.unwrap();

KeyPair::new("ea01309060D021340617E9554CCBC2CF3CC3DB922A9BA323ABDF7C271FCC6EF69BE7A8DEBCA7D9E96C0F0089ABA22CDAADE4A2"
.parse()
Expand Down Expand Up @@ -1066,13 +1070,17 @@ mod tests {

#[test]
fn key_pair_mismatch() {
KeyPair::new("ed012059C8A4DA1EBB5380F74ABA51F502714652FDCCE9611FAFB9904E4A3C4D382774"
.parse()
.expect("Public key not in mulithash format"),
PrivateKey::from_hex(
Algorithm::Ed25519,
"3A7991AF1ABB77F3FD27CC148404A6AE4439D095A63591B77C788D53F708A02A1509A611AD6D97B01D871E58ED00C8FD7C3917B6CA61A8C2833A19E000AAC2E4"
).expect("Private key not valid")).unwrap_err();
KeyPair::new(
"ed012059C8A4DA1EBB5380F74ABA51F502714652FDCCE9611FAFB9904E4A3C4D382774"
.parse()
.expect("Public key not in mulithash format"),
PrivateKey::from_hex(
Algorithm::Ed25519,
"3A7991AF1ABB77F3FD27CC148404A6AE4439D095A63591B77C788D53F708A02A",
)
.expect("Private key not valid"),
)
.unwrap_err();

KeyPair::new("ea01309060D021340617E9554CCBC2CF3CC3DB922A9BA323ABDF7C271FCC6EF69BE7A8DEBCA7D9E96C0F0089ABA22CDAADE4A2"
.parse()
Expand Down Expand Up @@ -1155,17 +1163,21 @@ mod tests {
assert_test_json_serde!(
json!({
"public_key": "ed01201509A611AD6D97B01D871E58ED00C8FD7C3917B6CA61A8C2833A19E000AAC2E4",
"private_key": "8026403A7991AF1ABB77F3FD27CC148404A6AE4439D095A63591B77C788D53F708A02A1509A611AD6D97B01D871E58ED00C8FD7C3917B6CA61A8C2833A19E000AAC2E4"
"private_key": "8026203A7991AF1ABB77F3FD27CC148404A6AE4439D095A63591B77C788D53F708A02A"
}),
TestJson {
public_key: PublicKey::from_hex(
Algorithm::Ed25519,
"1509A611AD6D97B01D871E58ED00C8FD7C3917B6CA61A8C2833A19E000AAC2E4"
).unwrap(),
private_key: ExposedPrivateKey(PrivateKey::from_hex(
Algorithm::Ed25519,
"3a7991af1abb77f3fd27cc148404a6ae4439d095a63591b77c788d53f708a02a1509a611ad6d97b01d871e58ed00c8fd7c3917b6ca61a8c2833a19e000aac2e4",
).unwrap())
)
.unwrap(),
private_key: ExposedPrivateKey(
PrivateKey::from_hex(
Algorithm::Ed25519,
"3a7991af1abb77f3fd27cc148404a6ae4439d095a63591b77c788d53f708a02a",
)
.unwrap()
)
}
);
}
Expand Down
8 changes: 4 additions & 4 deletions crypto/src/multihash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,9 @@ mod tests {
fn test_encode_private_key() {
let algorithm = Algorithm::Ed25519;
let payload =
hex_decode("8F4C15E5D664DA3F13778801D23D4E89B76E94C1B94B389544168B6CB894F84F8BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB").unwrap();
hex_decode("8F4C15E5D664DA3F13778801D23D4E89B76E94C1B94B389544168B6CB894F84F").unwrap();
let multihash =
hex_decode("8026408F4C15E5D664DA3F13778801D23D4E89B76E94C1B94B389544168B6CB894F84F8BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB")
hex_decode("8026208F4C15E5D664DA3F13778801D23D4E89B76E94C1B94B389544168B6CB894F84F")
.unwrap();
assert_eq!(encode_private_key(algorithm, &payload).unwrap(), multihash);
}
Expand All @@ -225,9 +225,9 @@ mod tests {
fn test_decode_private_key() {
let algorithm = Algorithm::Ed25519;
let payload =
hex_decode("8F4C15E5D664DA3F13778801D23D4E89B76E94C1B94B389544168B6CB894F84F8BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB").unwrap();
hex_decode("8F4C15E5D664DA3F13778801D23D4E89B76E94C1B94B389544168B6CB894F84F").unwrap();
let multihash =
hex_decode("8026408F4C15E5D664DA3F13778801D23D4E89B76E94C1B94B389544168B6CB894F84F8BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB")
hex_decode("8026208F4C15E5D664DA3F13778801D23D4E89B76E94C1B94B389544168B6CB894F84F")
.unwrap();
assert_eq!(
decode_private_key(&multihash).unwrap(),
Expand Down
10 changes: 6 additions & 4 deletions crypto/src/signature/ed25519.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use core::convert::TryFrom;
use core::convert::{Infallible, TryFrom};

use ed25519_dalek::Signature;
#[cfg(feature = "rand")]
Expand Down Expand Up @@ -51,7 +51,9 @@ impl Ed25519Sha512 {
}

pub fn parse_private_key(payload: &[u8]) -> Result<PrivateKey, ParseError> {
parse_fixed_size(payload, PrivateKey::from_keypair_bytes)
parse_fixed_size(payload, |bytes| {
Ok::<_, Infallible>(PrivateKey::from_bytes(bytes))
})
}

pub fn sign(message: &[u8], sk: &PrivateKey) -> Vec<u8> {
Expand All @@ -78,7 +80,7 @@ mod test {

const MESSAGE_1: &[u8] = b"This is a dummy message for use with tests";
const SIGNATURE_1: &str = "451b5b8e8725321541954997781de51f4142e4a56bab68d24f6a6b92615de5eefb74134138315859a32c7cf5fe5a488bc545e2e08e5eedfd1fb10188d532d808";
const PRIVATE_KEY: &str = "1c1179a560d092b90458fe6ab8291215a427fcd6b3927cb240701778ef55201927c96646f2d4632d4fc241f84cbc427fbc3ecaa95becba55088d6c7b81fc5bbf";
const PRIVATE_KEY: &str = "1c1179a560d092b90458fe6ab8291215a427fcd6b3927cb240701778ef552019";
const PUBLIC_KEY: &str = "27c96646f2d4632d4fc241f84cbc427fbc3ecaa95becba55088d6c7b81fc5bbf";

fn key_pair_factory() -> (ed25519::PublicKey, ed25519::PrivateKey) {
Expand Down Expand Up @@ -168,7 +170,7 @@ mod test {
let err = Ed25519Sha512::parse_private_key(&[1, 2, 3]).unwrap_err();
assert_eq!(
err,
ParseError("the payload size is incorrect: expected 64, but got 3".to_string())
ParseError("the payload size is incorrect: expected 32, but got 3".to_string())
);
}
}
Loading

0 comments on commit d971c1a

Please sign in to comment.