diff --git a/apps/extension/src/Approvals/ApproveBond/ConfirmLedgerBond.tsx b/apps/extension/src/Approvals/ApproveBond/ConfirmLedgerBond.tsx index e76a8b642..fdb6f1a05 100644 --- a/apps/extension/src/Approvals/ApproveBond/ConfirmLedgerBond.tsx +++ b/apps/extension/src/Approvals/ApproveBond/ConfirmLedgerBond.tsx @@ -99,10 +99,13 @@ export const ConfirmLedgerBond: React.FC = ({ const ledger = await Ledger.init(); try { + setStatusInfo("Querying for public key on chain..."); const pk = await queryPublicKey(address); if (!pk) { - setStatusInfo("Review and approve reveal pk on your Ledger"); + setStatusInfo( + "Public key not found! Review and approve reveal pk on your Ledger" + ); await revealPk(ledger, publicKey); } diff --git a/apps/extension/src/background/ledger/service.ts b/apps/extension/src/background/ledger/service.ts index 46ca54b3f..78cda2ec7 100644 --- a/apps/extension/src/background/ledger/service.ts +++ b/apps/extension/src/background/ledger/service.ts @@ -76,9 +76,14 @@ export class LedgerService { signatures: ResponseSign ): Promise { const { - wrapperSignature: { raw: wrapperSig }, - rawSignature: { raw: rawSig }, - } = signatures; + wrapperSignature: { + raw: { data: wrapperSig }, + }, + rawSignature: { + raw: { data: rawSig }, + }, + // TODO: We need the correct type updated in ResponseSign + } = signatures as any; // eslint-disable-line if (!wrapperSig) { throw new Error("No wrapper signature was produced!"); @@ -88,14 +93,13 @@ export class LedgerService { throw new Error("No raw signature was produced!"); } - const signedRevealPk = await this.sdk.sign_tx( - fromBase64(bytes), - new Uint8Array(wrapperSig), - new Uint8Array(rawSig) - ); - try { - await this.sdk.submit_signed_reveal_pk(fromBase64(txMsg), signedRevealPk); + await this.sdk.submit_signed_reveal_pk( + fromBase64(txMsg), + fromBase64(bytes), + new Uint8Array(wrapperSig), + new Uint8Array(rawSig) + ); } catch (e) { console.warn(e); } @@ -148,9 +152,14 @@ export class LedgerService { } const { - wrapperSignature: { raw: wrapperSig }, - rawSignature: { raw: rawSig }, - } = signatures; + wrapperSignature: { + raw: { data: wrapperSig }, + }, + rawSignature: { + raw: { data: rawSig }, + }, + // TODO: We need the correct type updated in ResponseSign + } = signatures as any; // eslint-disable-line if (!wrapperSig) { throw new Error("No wrapper signature was produced!"); @@ -160,14 +169,13 @@ export class LedgerService { throw new Error("No raw signature was produced!"); } - const signedTransfer = await this.sdk.sign_tx( - fromBase64(bytes), - new Uint8Array(wrapperSig), - new Uint8Array(rawSig) - ); - try { - await this.sdk.submit_signed_transfer(fromBase64(txMsg), signedTransfer); + await this.sdk.submit_signed_transfer( + fromBase64(txMsg), + fromBase64(bytes), + new Uint8Array(wrapperSig), + new Uint8Array(rawSig) + ); // Clear pending tx if successful await this.txStore.set(msgId, null); @@ -233,6 +241,7 @@ export class LedgerService { // TODO: We need the correct type updated in ResponseSign } = signatures as any; // eslint-disable-line + console.log({ wrapperSig, rawSig }); if (!wrapperSig) { throw new Error("No wrapper signature was produced!"); } @@ -241,14 +250,13 @@ export class LedgerService { throw new Error("No raw signature was produced!"); } - const signedBond = await this.sdk.sign_tx( - fromBase64(bytes), - new Uint8Array(wrapperSig), - new Uint8Array(rawSig) - ); - try { - await this.sdk.submit_signed_bond(fromBase64(txMsg), signedBond); + await this.sdk.submit_signed_bond( + fromBase64(txMsg), + fromBase64(bytes), + new Uint8Array(wrapperSig), + new Uint8Array(rawSig) + ); // Clear pending tx if successful await this.txStore.set(msgId, null); diff --git a/packages/shared/lib/src/sdk/mod.rs b/packages/shared/lib/src/sdk/mod.rs index 876ef234c..de30e3729 100644 --- a/packages/shared/lib/src/sdk/mod.rs +++ b/packages/shared/lib/src/sdk/mod.rs @@ -1,4 +1,4 @@ -use crate::utils::to_js_result; +use crate::utils::{console_log, to_js_result}; use crate::{ rpc_client::HttpClient, sdk::masp::WebShieldedUtils, @@ -183,8 +183,10 @@ impl Sdk { &mut self, tx_msg: &[u8], tx_bytes: &[u8], + wrapper_sig_bytes: &[u8], + raw_sig_bytes: &[u8], ) -> Result<(), JsError> { - let reveal_pk_tx = Tx::try_from_slice(&tx_bytes).map_err(JsError::from)?; + let reveal_pk_tx = self.sign_tx(tx_bytes, wrapper_sig_bytes, raw_sig_bytes)?; let args = tx::reveal_pk_tx_args(tx_msg).map_err(JsError::from)?; namada::ledger::tx::process_tx(&self.client, &mut self.wallet, &args.tx, reveal_pk_tx) @@ -239,12 +241,12 @@ impl Sdk { } // Append signatures and return tx bytes - pub fn sign_tx( + fn sign_tx( &self, tx_bytes: &[u8], wrapper_sig_bytes: &[u8], raw_sig_bytes: &[u8], - ) -> Result { + ) -> Result { let mut tx: Tx = Tx::try_from_slice(tx_bytes).map_err(JsError::from)?; let wrapper_sig = Signature::try_from_slice(wrapper_sig_bytes).map_err(JsError::from)?; @@ -254,8 +256,9 @@ impl Sdk { tx.protocol_filter(); tx.add_section(Section::Signature(wrapper_sig)); - let bytes = tx.try_to_vec().map_err(JsError::from)?; - to_js_result(Vec::from(bytes)) + console_log(&format!("Tx: {:?}", &tx)); + + Ok(tx) } /// Submit signed transfer tx @@ -263,8 +266,10 @@ impl Sdk { &mut self, tx_msg: &[u8], tx_bytes: &[u8], + wrapper_sig_bytes: &[u8], + raw_sig_bytes: &[u8], ) -> Result<(), JsError> { - let transfer_tx = Tx::try_from_slice(&tx_bytes).map_err(JsError::from)?; + let transfer_tx = self.sign_tx(tx_bytes, wrapper_sig_bytes, raw_sig_bytes)?; let args = tx::transfer_tx_args(tx_msg, None, None).map_err(JsError::from)?; let verification_key = args.tx.verification_key.clone(); let pk = validate_pk(verification_key)?; @@ -339,8 +344,10 @@ impl Sdk { &mut self, tx_msg: &[u8], tx_bytes: &[u8], + wrapper_sig_bytes: &[u8], + raw_sig_bytes: &[u8], ) -> Result<(), JsError> { - let bond_tx = Tx::try_from_slice(&tx_bytes).map_err(JsError::from)?; + let bond_tx = self.sign_tx(tx_bytes, wrapper_sig_bytes, raw_sig_bytes)?; let args = tx::bond_tx_args(tx_msg, None).map_err(JsError::from)?; namada::ledger::tx::process_tx(&self.client, &mut self.wallet, &args.tx, bond_tx) @@ -373,8 +380,10 @@ impl Sdk { &mut self, tx_msg: &[u8], tx_bytes: &[u8], + wrapper_sig_bytes: &[u8], + raw_sig_bytes: &[u8], ) -> Result<(), JsError> { - let bond_tx = Tx::try_from(tx_bytes).map_err(JsError::from)?; + let bond_tx = self.sign_tx(tx_bytes, wrapper_sig_bytes, raw_sig_bytes)?; let args = tx::unbond_tx_args(tx_msg, None).map_err(JsError::from)?; let verification_key = args.tx.verification_key.clone(); let pk = validate_pk(verification_key)?;