33//! Implements 256-bit derivation paths for DashPay contact keys
44
55use crate :: error:: WasmSdkError ;
6+ use crate :: queries:: utils:: deserialize_required_query;
67use crate :: sdk:: WasmSdk ;
78use dash_sdk:: dpp:: dashcore;
89use dash_sdk:: dpp:: dashcore:: secp256k1:: Secp256k1 ;
910use dash_sdk:: dpp:: key_wallet:: { bip32, DerivationPath , ExtendedPrivKey } ;
1011use std:: str:: FromStr ;
1112use tracing:: debug;
1213use wasm_bindgen:: prelude:: * ;
13- use crate :: queries:: utils:: deserialize_required_query;
1414
1515// TypeScript option bags (module scope) for extended derivation helpers
1616#[ wasm_bindgen( typescript_custom_section) ]
@@ -78,9 +78,15 @@ impl WasmSdk {
7878 /// This supports DIP14/DIP15 paths with identity IDs
7979 #[ wasm_bindgen( js_name = "deriveKeyFromSeedWithExtendedPath" ) ]
8080 pub fn derive_key_from_seed_with_extended_path (
81- #[ wasm_bindgen( unchecked_param_type = "DeriveKeyFromSeedWithExtendedPathOptions" ) ] opts : JsValue ,
81+ #[ wasm_bindgen( unchecked_param_type = "DeriveKeyFromSeedWithExtendedPathOptions" ) ]
82+ opts : JsValue ,
8283 ) -> Result < JsValue , WasmSdkError > {
83- let DeriveFromExtendedPathInput { mnemonic, passphrase, path, network } = deserialize_required_query (
84+ let DeriveFromExtendedPathInput {
85+ mnemonic,
86+ passphrase,
87+ path,
88+ network,
89+ } = deserialize_required_query (
8490 opts,
8591 "Options object is required" ,
8692 "deriveKeyFromSeedWithExtendedPath options" ,
@@ -188,7 +194,15 @@ impl WasmSdk {
188194 pub fn derive_dashpay_contact_key (
189195 #[ wasm_bindgen( unchecked_param_type = "DeriveDashpayContactKeyOptions" ) ] opts : JsValue ,
190196 ) -> Result < JsValue , WasmSdkError > {
191- let DeriveDashpayContactKeyInput { mnemonic, passphrase, sender_identity_id, receiver_identity_id, account, address_index, network } = deserialize_required_query (
197+ let DeriveDashpayContactKeyInput {
198+ mnemonic,
199+ passphrase,
200+ sender_identity_id,
201+ receiver_identity_id,
202+ account,
203+ address_index,
204+ network,
205+ } = deserialize_required_query (
192206 opts,
193207 "Options object is required" ,
194208 "deriveDashpayContactKey options" ,
@@ -210,9 +224,11 @@ impl WasmSdk {
210224 receiver_identity_id. to_string ( )
211225 } else {
212226 // Decode base58 to bytes, then convert to hex
213- let bytes = bs58:: decode ( & receiver_identity_id) . into_vec ( ) . map_err ( |e| {
214- WasmSdkError :: invalid_argument ( format ! ( "Invalid receiver identity ID: {}" , e) )
215- } ) ?;
227+ let bytes = bs58:: decode ( & receiver_identity_id)
228+ . into_vec ( )
229+ . map_err ( |e| {
230+ WasmSdkError :: invalid_argument ( format ! ( "Invalid receiver identity ID: {}" , e) )
231+ } ) ?;
216232 format ! ( "0x{}" , hex:: encode( bytes) )
217233 } ;
218234
@@ -238,8 +254,9 @@ impl WasmSdk {
238254 "network" : network,
239255 } ) ;
240256
241- let js_opts = serde_wasm_bindgen:: to_value ( & opts)
242- . map_err ( |e| WasmSdkError :: serialization ( format ! ( "Failed to serialize options: {}" , e) ) ) ?;
257+ let js_opts = serde_wasm_bindgen:: to_value ( & opts) . map_err ( |e| {
258+ WasmSdkError :: serialization ( format ! ( "Failed to serialize options: {}" , e) )
259+ } ) ?;
243260
244261 // Use the extended derivation function
245262 let result = Self :: derive_key_from_seed_with_extended_path ( js_opts) ?;
0 commit comments