From fb3823c66149d0663dd4ed733820c72e105c01e6 Mon Sep 17 00:00:00 2001 From: nazeh Date: Sat, 3 Aug 2024 13:45:14 +0300 Subject: [PATCH] feat(js): add Keypair.secretKey --- pubky/src/wasm/keys.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pubky/src/wasm/keys.rs b/pubky/src/wasm/keys.rs index ea5ea2c..fd82c4c 100644 --- a/pubky/src/wasm/keys.rs +++ b/pubky/src/wasm/keys.rs @@ -13,8 +13,8 @@ impl Keypair { Self(pkarr::Keypair::random()) } - #[wasm_bindgen] /// Generate a [Keypair] from a secret key. + #[wasm_bindgen(js_name = "fromSecretKey")] pub fn from_secret_key(secret_key: js_sys::Uint8Array) -> Self { let mut bytes = [0; 32]; secret_key.copy_to(&mut bytes); @@ -22,8 +22,14 @@ impl Keypair { Self(pkarr::Keypair::from_secret_key(&bytes)) } - #[wasm_bindgen(js_name = "publicKey")] + /// Returns the secret key of this keypair. + #[wasm_bindgen(js_name = "secretKey")] + pub fn secret_key(&self) -> js_sys::Uint8Array { + self.0.secret_key().as_slice().into() + } + /// Returns the [PublicKey] of this keypair. + #[wasm_bindgen(js_name = "publicKey")] pub fn public_key(&self) -> PublicKey { PublicKey(self.0.public_key()) }