Permalink
Browse files

add more features to the Redeem Keys (Address creation and from_bytes)

  • Loading branch information...
NicolasDP committed Jan 10, 2019
1 parent 633b48f commit e3dd5065eb2d88a97a701e4ab6ea175ac9c031ca
Showing with 20 additions and 0 deletions.
  1. +20 −0 cardano-wallet/src/lib.rs
@@ -952,6 +952,13 @@ use self::cardano::redeem;
pub struct PrivateRedeemKey(redeem::PrivateKey);
#[wasm_bindgen]
impl PrivateRedeemKey {
/// retrieve the private redeeming key from the given bytes (expect 64 bytes)
pub fn from_bytes(bytes: &[u8]) -> Result<PrivateRedeemKey, JsValue> {
redeem::PrivateKey::from_slice(bytes)
.map_err(|e| JsValue::from_str(&format! {"{:?}", e}))
.map(PrivateRedeemKey)
}

/// retrieve a private key from the given hexadecimal string
pub fn from_hex(hex: &str) -> Result<PrivateRedeemKey, JsValue> {
redeem::PrivateKey::from_hex(hex)
@@ -994,6 +1001,19 @@ impl PublicRedeemKey {
pub fn verify(&self, data: &[u8], signature: &RedeemSignature) -> bool {
self.0.verify(&signature.0, data)
}

/// generate the address for this redeeming key
pub fn address(&self, settings: &BlockchainSettings) -> Address {
let address_type = address::AddrType::ATRedeem;
let spending_data = address::SpendingData::RedeemASD(self.0.clone());
let attributes =
address::Attributes::new_bootstrap_era(None, settings.protocol_magic.into());
Address(address::ExtendedAddr::new(
address_type,
spending_data,
attributes,
))
}
}

#[wasm_bindgen]

0 comments on commit e3dd506

Please sign in to comment.