Skip to content

Commit 91ef63b

Browse files
committed
Add reveal pk for submitting signed transfers
1 parent 6758f0a commit 91ef63b

File tree

5 files changed

+31
-7
lines changed

5 files changed

+31
-7
lines changed

apps/extension/src/Approvals/ApproveTransfer/ConfirmLedgerTransfer.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ export const ConfirmLedgerTransfer: React.FC<Props> = ({ msgId }) => {
3838
new GetTransferBytesMsg(msgId)
3939
);
4040

41+
// Retrieve publicKey from Ledger
42+
const { publicKey } = await ledger.getAddressAndPublicKey(path);
43+
4144
// Sign with Ledger
4245
const signatures = await ledger.sign(bytes, path);
4346
const { errorMessage, returnCode } = signatures;
@@ -53,7 +56,12 @@ export const ConfirmLedgerTransfer: React.FC<Props> = ({ msgId }) => {
5356
// Submit signatures for tx
5457
await requester.sendMessage(
5558
Ports.Background,
56-
new SubmitSignedTransferMsg(msgId, toBase64(bytes), signatures)
59+
new SubmitSignedTransferMsg(
60+
msgId,
61+
toBase64(bytes),
62+
signatures,
63+
publicKey
64+
)
5765
);
5866
setStatus(Status.Completed);
5967
} catch (e) {

apps/extension/src/background/ledger/handler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const handleSubmitSignedTransferMsg: (
5252
service: LedgerService
5353
) => InternalHandler<SubmitSignedTransferMsg> = (service) => {
5454
return async (_, msg) => {
55-
const { bytes, msgId, signatures } = msg;
56-
return await service.submitTransfer(msgId, bytes, signatures);
55+
const { bytes, publicKey, msgId, signatures } = msg;
56+
return await service.submitTransfer(msgId, bytes, signatures, publicKey);
5757
};
5858
};

apps/extension/src/background/ledger/messages.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ export class SubmitSignedTransferMsg extends Message<void> {
8787
constructor(
8888
public readonly msgId: string,
8989
public readonly bytes: string,
90-
public readonly signatures: ResponseSign
90+
public readonly signatures: ResponseSign,
91+
public readonly publicKey: string
9192
) {
9293
super();
9394
}
@@ -104,6 +105,10 @@ export class SubmitSignedTransferMsg extends Message<void> {
104105
if (!this.signatures) {
105106
throw new Error("No signatures were provided!");
106107
}
108+
109+
if (!this.publicKey) {
110+
throw new Error("No publicKey provided!");
111+
}
107112
}
108113

109114
route(): string {

apps/extension/src/background/ledger/service.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ export class LedgerService {
7171
async submitTransfer(
7272
msgId: string,
7373
bytes: string,
74-
signatures: ResponseSign
74+
signatures: ResponseSign,
75+
publicKey: string
7576
): Promise<void> {
7677
const txMsg = await this.txStore.get(msgId);
7778

@@ -89,7 +90,11 @@ export class LedgerService {
8990
);
9091

9192
try {
92-
await this.sdk.submit_signed_transfer(fromBase64(txMsg), signedTransfer);
93+
await this.sdk.submit_signed_transfer(
94+
publicKey,
95+
fromBase64(txMsg),
96+
signedTransfer
97+
);
9398

9499
// Clear pending tx if successful
95100
await this.txStore.set(msgId, null);

packages/shared/lib/src/sdk/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl Sdk {
133133
mut tx: Tx,
134134
pk: PublicKey,
135135
) -> Result<(), JsError> {
136-
// Build a transaction to reveal the signer of this transaction
136+
// Submit a reveal pk tx if necessary
137137
self.submit_reveal_pk(&args, tx.clone(), &pk).await?;
138138

139139
// Sign tx
@@ -203,11 +203,17 @@ impl Sdk {
203203
/// Submit signed transfer tx
204204
pub async fn submit_signed_transfer(
205205
&mut self,
206+
pk: String,
206207
tx_msg: &[u8],
207208
tx_bytes: &[u8],
208209
) -> Result<(), JsError> {
209210
let transfer_tx = Tx::try_from(tx_bytes).map_err(|e| JsError::from(e))?;
210211
let args = tx::transfer_tx_args(tx_msg, None, None).map_err(|e| JsError::from(e))?;
212+
let pk = PublicKey::from_str(&pk).map_err(JsError::from)?;
213+
214+
self.submit_reveal_pk(&args.tx, transfer_tx.clone(), &pk)
215+
.await?;
216+
211217
namada::ledger::tx::process_tx(&self.client, &mut self.wallet, &args.tx, transfer_tx)
212218
.await
213219
.map_err(JsError::from)?;

0 commit comments

Comments
 (0)