-
Notifications
You must be signed in to change notification settings - Fork 404
feat(stronghold): support secp256k1 curve #2724
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
base: v2
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -256,6 +256,76 @@ class ProcedureExecutor { | |||||
} | ||||||
}).then((n) => Uint8Array.from(n)) | ||||||
} | ||||||
|
||||||
/** | ||||||
* Gets the Secp256k1Ecdsa public key of a SLIP10 private key. | ||||||
* @param privateKeyLocation The location of the private key. Must be the `outputLocation` of a previous call to `deriveSLIP10`. | ||||||
* @returns A promise resolving to the public key hex string. | ||||||
* | ||||||
* @since 2.1.0 | ||||||
*/ | ||||||
async getSecp256k1EcdsaPublicKey( | ||||||
privateKeyLocation: Location | ||||||
): Promise<Uint8Array> { | ||||||
return await invoke<number[]>('plugin:stronghold|execute_procedure', { | ||||||
...this.procedureArgs, | ||||||
procedure: { | ||||||
type: 'PublicKey', | ||||||
payload: { | ||||||
type: 'Secp256k1Ecdsa', | ||||||
privateKey: privateKeyLocation | ||||||
} | ||||||
} | ||||||
}).then((n) => Uint8Array.from(n)) | ||||||
} | ||||||
|
||||||
/** | ||||||
* Gets the EVM address of a SLIP10 private key. | ||||||
* @param privateKeyLocation The location of the private key. Must be the `outputLocation` of a previous call to `deriveSLIP10`. | ||||||
* @returns A promise resolving to the EVM address | ||||||
* | ||||||
* @since 2.1.0 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
*/ | ||||||
async getSecp256k1EcdsaEvmAddress( | ||||||
privateKeyLocation: Location | ||||||
): Promise<Uint8Array> { | ||||||
return await invoke<number[]>('plugin:stronghold|execute_procedure', { | ||||||
...this.procedureArgs, | ||||||
procedure: { | ||||||
type: 'GetEvmAddress', | ||||||
payload: { | ||||||
privateKey: privateKeyLocation | ||||||
} | ||||||
} | ||||||
}).then((n) => Uint8Array.from(n)) | ||||||
} | ||||||
|
||||||
/** | ||||||
* Creates a Secp256k1Ecdsa signature from a private key. | ||||||
* @param flavor The hash type | ||||||
* @param privateKeyLocation The location of the record where the private key is stored. Must be the `outputLocation` of a previous call to `deriveSLIP10`. | ||||||
* @param msg The message to sign. | ||||||
* @returns A promise resolving to the signature hex string. | ||||||
* | ||||||
* @since 2.1.0 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
*/ | ||||||
async signSecp256k1Ecdsa( | ||||||
flavor: 'Keccak256' | 'Sha256', | ||||||
privateKeyLocation: Location, | ||||||
msg: string | ||||||
): Promise<Uint8Array> { | ||||||
return await invoke<number[]>('plugin:stronghold|execute_procedure', { | ||||||
...this.procedureArgs, | ||||||
procedure: { | ||||||
type: 'Secp256k1EcdsaSign', | ||||||
payload: { | ||||||
flavor, | ||||||
privateKey: privateKeyLocation, | ||||||
msg | ||||||
} | ||||||
} | ||||||
}).then((n) => Uint8Array.from(n)) | ||||||
} | ||||||
} | ||||||
|
||||||
export class Client { | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,9 +20,9 @@ use std::{ | |
use crypto::keys::bip39; | ||
use iota_stronghold::{ | ||
procedures::{ | ||
BIP39Generate, BIP39Recover, Curve, Ed25519Sign, KeyType as StrongholdKeyType, | ||
MnemonicLanguage, PublicKey, Slip10Derive, Slip10DeriveInput, Slip10Generate, | ||
StrongholdProcedure, | ||
BIP39Generate, BIP39Recover, Curve, Ed25519Sign, GetEvmAddress, | ||
KeyType as StrongholdKeyType, MnemonicLanguage, PublicKey, Secp256k1EcdsaFlavor, | ||
Secp256k1EcdsaSign, Slip10Derive, Slip10DeriveInput, Slip10Generate, StrongholdProcedure, | ||
}, | ||
Client, Location, | ||
}; | ||
|
@@ -107,13 +107,15 @@ impl From<Slip10DeriveInputDto> for Slip10DeriveInput { | |
pub enum KeyType { | ||
Ed25519, | ||
X25519, | ||
Secp256k1Ecdsa, | ||
} | ||
|
||
impl From<KeyType> for StrongholdKeyType { | ||
fn from(ty: KeyType) -> StrongholdKeyType { | ||
match ty { | ||
KeyType::Ed25519 => StrongholdKeyType::Ed25519, | ||
KeyType::X25519 => StrongholdKeyType::X25519, | ||
KeyType::Secp256k1Ecdsa => StrongholdKeyType::Secp256k1Ecdsa, | ||
} | ||
} | ||
} | ||
|
@@ -129,7 +131,7 @@ impl<'de> Deserialize<'de> for KeyType { | |
type Value = KeyType; | ||
|
||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { | ||
formatter.write_str("ed25519 or x25519") | ||
formatter.write_str("ed25519, x25519, or secp256k1_ecdsa") | ||
} | ||
|
||
fn visit_str<E>(self, value: &str) -> std::result::Result<Self::Value, E> | ||
|
@@ -139,6 +141,7 @@ impl<'de> Deserialize<'de> for KeyType { | |
match value.to_lowercase().as_str() { | ||
"ed25519" => Ok(KeyType::Ed25519), | ||
"x25519" => Ok(KeyType::X25519), | ||
"secp256k1_ecdsa" => Ok(KeyType::Secp256k1Ecdsa), | ||
_ => Err(serde::de::Error::custom("unknown key type")), | ||
} | ||
} | ||
|
@@ -182,6 +185,16 @@ enum ProcedureDto { | |
private_key: LocationDto, | ||
msg: String, | ||
}, | ||
GetEvmAddress { | ||
#[serde(rename = "privateKey")] | ||
private_key: LocationDto, | ||
}, | ||
Secp256k1EcdsaSign { | ||
flavor: Secp256k1EcdsaFlavor, | ||
#[serde(rename = "privateKey")] | ||
private_key: LocationDto, | ||
msg: String, | ||
}, | ||
Comment on lines
+188
to
+197
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i couldn't try the changes yet but is this enum not missing a |
||
} | ||
|
||
impl From<ProcedureDto> for StrongholdProcedure { | ||
|
@@ -231,6 +244,20 @@ impl From<ProcedureDto> for StrongholdProcedure { | |
msg: msg.as_bytes().to_vec(), | ||
}) | ||
} | ||
ProcedureDto::GetEvmAddress { private_key } => { | ||
StrongholdProcedure::GetEvmAddress(GetEvmAddress { | ||
private_key: private_key.into(), | ||
}) | ||
} | ||
ProcedureDto::Secp256k1EcdsaSign { | ||
flavor, | ||
private_key, | ||
msg, | ||
} => StrongholdProcedure::Secp256k1EcdsaSign(Secp256k1EcdsaSign { | ||
flavor, | ||
private_key: private_key.into(), | ||
msg: msg.as_bytes().to_vec(), | ||
}), | ||
} | ||
} | ||
} | ||
|
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.