Skip to content

Commit

Permalink
feat: proper flow for ledger txs from masp source
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszjasiuk committed Jan 27, 2025
1 parent f3ca926 commit 1c6d586
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 29 deletions.
31 changes: 25 additions & 6 deletions apps/extension/src/Approvals/ConfirmSignLedgerTx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@ import clsx from "clsx";
import { ReactNode, useCallback, useEffect, useState } from "react";

import { ActionButton, Stack } from "@namada/components";
import { Ledger, makeBip44Path, makeSaplingPath } from "@namada/sdk/web";
import {
Ledger,
makeBip44Path,
makeSaplingPath,
TxType,
} from "@namada/sdk/web";
import { LedgerError, ResponseSign } from "@zondax/ledger-namada";

import { fromBase64, toBase64 } from "@cosmjs/encoding";
import { chains } from "@namada/chains";
import { TransferProps } from "@namada/types";
import { PageHeader } from "App/Common";
import { ApprovalDetails, Status } from "Approvals/Approvals";
import {
Expand All @@ -18,7 +24,7 @@ import {
import { QueryAccountDetailsMsg } from "background/keyring";
import { useRequester } from "hooks/useRequester";
import { Ports } from "router";
import { closeCurrentTab } from "utils";
import { closeCurrentTab, parseTransferType } from "utils";
import { ApproveIcon } from "./ApproveIcon";
import { LedgerIcon } from "./LedgerIcon";
import { StatusBox } from "./StatusBox";
Expand Down Expand Up @@ -66,7 +72,7 @@ export const ConfirmSignLedgerTx: React.FC<Props> = ({ details }) => {
useState<React.ReactNode>();
const [isLedgerConnected, setIsLedgerConnected] = useState(false);
const [ledger, setLedger] = useState<Ledger>();
const { msgId, signer } = details;
const { msgId, signer, txDetails } = details;

useEffect(() => {
if (status === Status.Completed) {
Expand Down Expand Up @@ -182,7 +188,6 @@ export const ConfirmSignLedgerTx: React.FC<Props> = ({ details }) => {

try {
// TODO: we have to check if the signer is disposable or not
const isDisposableSigner = false;

const accountDetails = await requester.sendMessage(
Ports.Background,
Expand Down Expand Up @@ -220,6 +225,20 @@ export const ConfirmSignLedgerTx: React.FC<Props> = ({ details }) => {
const signatures: ResponseSign[] = [];
const maspSignatures: string[] = [];

const transferTypes = txDetails.flatMap((details) =>
details.commitments
.filter((cmt) => cmt.txType === TxType.Transfer)
.map(
(cmt) =>
parseTransferType(cmt as TransferProps, details.wrapperFeePayer)
.type
)
);
// For now we work under the assumption that we can't batch transfers from masp with other tx types
const fromMasp =
transferTypes.includes("Shielded") ||
transferTypes.includes("Unshielding");

for await (const tx of pendingTxs) {
if (txCount > 1) {
setStepTwoDescription(
Expand All @@ -231,7 +250,7 @@ export const ConfirmSignLedgerTx: React.FC<Props> = ({ details }) => {
);
}

if (isDisposableSigner) {
if (fromMasp) {
const zip32Path = makeSaplingPath(chains.namada.bip44.coinType, {
account: path.account,
});
Expand All @@ -248,7 +267,7 @@ export const ConfirmSignLedgerTx: React.FC<Props> = ({ details }) => {

setStepTwoDescription(<p>Submitting...</p>);

if (isDisposableSigner) {
if (fromMasp) {
await requester.sendMessage(
Ports.Background,
new ReplaceMaspSignaturesMsg(msgId, maspSignatures)
Expand Down
1 change: 0 additions & 1 deletion apps/extension/src/background/approvals/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ export class SubmitApprovedSignLedgerTxMsg extends Message<void> {
}
}

// returns base64 encoded tx
export class ReplaceMaspSignaturesMsg extends Message<void> {
public static type(): MessageType {
return MessageType.ReplaceMaspSignatures;
Expand Down
2 changes: 1 addition & 1 deletion apps/extension/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export const isShieldedPool = (address: string): boolean => {
*/
export const parseTransferType = (
tx: TransferProps,
wrapperFeePayer?: string
wrapperFeePayer: string
): { source: string; target: string; type: TransferType } => {
const { sources, targets } = tx;
const source = sources[0].owner;
Expand Down
29 changes: 8 additions & 21 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3209,7 +3209,7 @@ __metadata:
languageName: node
linkType: hard

"@ledgerhq/devices@npm:8.4.4, @ledgerhq/devices@npm:^8.4.4":
"@ledgerhq/devices@npm:^8.4.4":
version: 8.4.4
resolution: "@ledgerhq/devices@npm:8.4.4"
dependencies:
Expand All @@ -3228,18 +3228,6 @@ __metadata:
languageName: node
linkType: hard

"@ledgerhq/hw-transport-webhid@npm:^6.29.4":
version: 6.30.0
resolution: "@ledgerhq/hw-transport-webhid@npm:6.30.0"
dependencies:
"@ledgerhq/devices": "npm:8.4.4"
"@ledgerhq/errors": "npm:^6.19.1"
"@ledgerhq/hw-transport": "npm:^6.31.4"
"@ledgerhq/logs": "npm:^6.12.0"
checksum: 10c0/1cb6ddb50127d6cb73d80259e10da687a2b7aa87ebbac8cc3e770ac5b95a3ef0001bdaf77109da0eb62509cb8668a9642858b59cb0ff355c1adb0fe2114c532c
languageName: node
linkType: hard

"@ledgerhq/hw-transport-webusb@npm:^6.29.4":
version: 6.29.4
resolution: "@ledgerhq/hw-transport-webusb@npm:6.29.4"
Expand Down Expand Up @@ -3430,7 +3418,6 @@ __metadata:
"@cosmjs/encoding": "npm:^0.29.0"
"@dao-xyz/borsh": "npm:^5.1.5"
"@ledgerhq/hw-transport": "npm:^6.31.4"
"@ledgerhq/hw-transport-webhid": "npm:^6.29.4"
"@ledgerhq/hw-transport-webusb": "npm:^6.29.4"
"@svgr/webpack": "npm:^6.3.1"
"@types/chrome": "npm:^0.0.237"
Expand All @@ -3443,7 +3430,7 @@ __metadata:
"@types/w3c-web-usb": "npm:^1.0.10"
"@types/webextension-polyfill": "npm:^0.10.6"
"@types/zxcvbn": "npm:^4.4.1"
"@zondax/ledger-namada": "npm:^1.0.0"
"@zondax/ledger-namada": "npm:^2.0.0"
bignumber.js: "npm:^9.1.1"
buffer: "npm:^6.0.3"
copy-webpack-plugin: "npm:^11.0.0"
Expand Down Expand Up @@ -3707,11 +3694,10 @@ __metadata:
"@cosmjs/encoding": "npm:^0.29.0"
"@dao-xyz/borsh": "npm:^5.1.5"
"@ledgerhq/hw-transport": "npm:^6.31.4"
"@ledgerhq/hw-transport-webhid": "npm:^6.29.4"
"@ledgerhq/hw-transport-webusb": "npm:^6.29.4"
"@types/jest": "npm:^29.5.12"
"@types/node": "npm:^20.11.4"
"@zondax/ledger-namada": "npm:^1.0.0"
"@zondax/ledger-namada": "npm:^2.0.0"
babel-jest: "npm:^29.0.3"
bignumber.js: "npm:^9.1.1"
buffer: "npm:^6.0.3"
Expand All @@ -3727,6 +3713,7 @@ __metadata:
jest-mock-server: "npm:^0.1.0"
jsdoc-babel: "npm:^0.5.0"
rimraf: "npm:^5.0.5"
semver: "npm:^7.6.3"
slip44: "npm:^3.0.18"
ts-jest: "npm:^29.2.5"
ts-node: "npm:^10.9.1"
Expand Down Expand Up @@ -6072,12 +6059,12 @@ __metadata:
languageName: node
linkType: hard

"@zondax/ledger-namada@npm:^1.0.0":
version: 1.0.0
resolution: "@zondax/ledger-namada@npm:1.0.0"
"@zondax/ledger-namada@npm:^2.0.0":
version: 2.0.0
resolution: "@zondax/ledger-namada@npm:2.0.0"
dependencies:
"@ledgerhq/hw-transport": "npm:^6.30.6"
checksum: 10c0/f7490964ccd41f9a63f2bc8d89ea9f01e7d6a58be796db0b454a3f1455dcc8dc8dd578a8642aa0f0799c93f838e8e3afd69f59f7e9947816b9471338c2b9dd63
checksum: 10c0/1fa2a9a537bc42df01444332529a606ed77f608a2cc1dbb029915ed854ff447976930a4338c2d68d50d98869828cd76b1a4f4b5c2c989fd84af7b66d55dc51fc
languageName: node
linkType: hard

Expand Down

0 comments on commit 1c6d586

Please sign in to comment.