Skip to content

Commit

Permalink
update ledger library & cleanup error state (#1051)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeesunikim committed Sep 20, 2024
1 parent e931c0d commit ae09df0
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 52 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
},
"dependencies": {
"@creit.tech/stellar-wallets-kit": "^0.8.2",
"@ledgerhq/hw-app-str": "^6.28.6",
"@ledgerhq/hw-transport-webusb": "^6.28.6",
"@ledgerhq/hw-app-str": "^7.0.3",
"@ledgerhq/hw-transport-webusb": "^6.29.3",
"@stellar/design-system": "^2.0.0-beta.16",
"@stellar/stellar-sdk": "^12.2.0",
"@stellar/stellar-xdr-json-web": "^0.0.2",
Expand Down
1 change: 1 addition & 0 deletions src/app/(sidebar)/transaction/sign/components/Overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export const Overview = () => {

const signWithHardware = async () => {
setHardwareSigSuccess(false);
setHardwareSigErrorMsg("");
updateSignedTx("");

setIsLoading(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export const SignWithWallet = ({
};

return (
<Button size="md" variant="secondary" onClick={onSignWithWallet}>
<Button size="md" variant="tertiary" onClick={onSignWithWallet}>
Sign with wallet
</Button>
);
Expand Down
19 changes: 5 additions & 14 deletions src/helpers/txHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
xdr,
} from "@stellar/stellar-sdk";
import LedgerTransportWebUSB from "@ledgerhq/hw-transport-webusb";
import LedgerStr from "@ledgerhq/hw-app-str";
import Str from "@ledgerhq/hw-app-str";
import TrezorConnect, { StellarSignedTx } from "@trezor/connect-web";
import transformTransaction from "@trezor/connect-plugin-stellar";

Expand Down Expand Up @@ -72,16 +72,6 @@ const buildFeeBumpTx = ({
return result;
};

/* Sign Transaction related */
interface LedgerApi {
getPublicKey(path: string): Promise<{ publicKey: string }>;
signHash(path: string, hash: Buffer): Promise<{ signature: Buffer }>;
signTransaction(
path: string,
transaction: Buffer,
): Promise<{ signature: Buffer }>;
}

const signTx = ({
txXdr,
signers,
Expand Down Expand Up @@ -179,11 +169,12 @@ const signWithLedger = async ({
return error;
};

const signTxWithLedger = async (ledgerApi: LedgerApi, isHash: boolean) => {
const signTxWithLedger = async (ledgerApi: Str, isHash: boolean) => {
let ledgerSignature;

try {
const { publicKey } = await ledgerApi.getPublicKey(bipPath);
const { rawPublicKey } = await ledgerApi.getPublicKey(bipPath);
const publicKey = StrKey.encodeEd25519PublicKey(rawPublicKey);

if (isHash) {
const { signature } = await ledgerApi.signHash(
Expand Down Expand Up @@ -215,7 +206,7 @@ const signWithLedger = async ({

try {
const transport = await LedgerTransportWebUSB.request();
const ledgerApi = new LedgerStr(transport);
const ledgerApi = new Str(transport);
return await signTxWithLedger(ledgerApi, isHash);
} catch (error) {
const ledgerError = error as LedgerErrorResponse;
Expand Down
3 changes: 0 additions & 3 deletions src/styles/globals.scss
Original file line number Diff line number Diff line change
Expand Up @@ -918,9 +918,6 @@
margin-top: pxToRem(25px);
}
}
.Button {
border: 0;
}
}
}

Expand Down
84 changes: 52 additions & 32 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -462,48 +462,47 @@
"@jridgewell/resolve-uri" "^3.1.0"
"@jridgewell/sourcemap-codec" "^1.4.14"

"@ledgerhq/devices@^8.3.0":
version "8.3.0"
resolved "https://registry.yarnpkg.com/@ledgerhq/devices/-/devices-8.3.0.tgz#a1e1a21608e162fb3a512f57863bf9842b29493f"
integrity sha512-h5Scr+yIae8yjPOViCHLdMjpqn4oC2Whrsq8LinRxe48LEGMdPqSV1yY7+3Ch827wtzNpMv+/ilKnd8rY+rTlg==
"@ledgerhq/devices@^8.4.3":
version "8.4.3"
resolved "https://registry.yarnpkg.com/@ledgerhq/devices/-/devices-8.4.3.tgz#4c296df4dd4af6f1085d728609b6931a640baf86"
integrity sha512-+ih+M27E6cm6DHrmw3GbS3mEaznCyFc0e62VdQux40XK2psgYhL2yBPftM4KCrBYm1UbHqXzqLN+Jb7rNIzsHg==
dependencies:
"@ledgerhq/errors" "^6.16.4"
"@ledgerhq/errors" "^6.19.0"
"@ledgerhq/logs" "^6.12.0"
rxjs "^7.8.1"
semver "^7.3.5"

"@ledgerhq/errors@^6.16.4":
version "6.16.4"
resolved "https://registry.yarnpkg.com/@ledgerhq/errors/-/errors-6.16.4.tgz#a38baffe8b096d9fff3ad839cadb55704c8d8e7b"
integrity sha512-M57yFaLYSN+fZCX0E0zUqOmrV6eipK+s5RhijHoUNlHUqrsvUz7iRQgpd5gRgHB5VkIjav7KdaZjKiWGcHovaQ==
"@ledgerhq/errors@^6.19.0":
version "6.19.0"
resolved "https://registry.yarnpkg.com/@ledgerhq/errors/-/errors-6.19.0.tgz#ed4f01df3dabfcdeb0b073159d66cb5f2d086243"
integrity sha512-c3Jid7euMSnpHFp8H7iPtsmKDjwbTjlG46YKdw+RpCclsqtBx1uQDlYmcbP1Yv9201kVlUFUhhP4H623k8xzlQ==

"@ledgerhq/hw-app-str@^6.28.6":
version "6.28.6"
resolved "https://registry.yarnpkg.com/@ledgerhq/hw-app-str/-/hw-app-str-6.28.6.tgz#1d2562b75e4cb8ffa14441323fad21589e2e4bce"
integrity sha512-sQCbtqyY9kUZIppy4OsLZflMfCjDWO15U3MI8UylfWZfr+dW2Lki4HFHrpgqRvaSMzp/DkLStX37Iy7On83kPg==
"@ledgerhq/hw-app-str@^7.0.3":
version "7.0.3"
resolved "https://registry.yarnpkg.com/@ledgerhq/hw-app-str/-/hw-app-str-7.0.3.tgz#615047faae9281fdb493f8eb1d3c802e83ec36db"
integrity sha512-Vcid9lipSk/+Rcle5d78QTtHeGe5s0eLwKgaVpKO9NKd7hMYHROY9XNrKCZz6tX6qionoCUsO3tkCQI60NmMDw==
dependencies:
"@ledgerhq/hw-transport" "^6.30.6"
base32.js "^0.1.0"
sha.js "^2.3.6"
tweetnacl "^1.0.3"
"@ledgerhq/errors" "^6.19.0"
"@ledgerhq/hw-transport" "^6.31.3"
bip32-path "^0.4.2"

"@ledgerhq/hw-transport-webusb@^6.28.6":
version "6.28.6"
resolved "https://registry.yarnpkg.com/@ledgerhq/hw-transport-webusb/-/hw-transport-webusb-6.28.6.tgz#c17c193578da112ef76769e4ce72129d40d87faa"
integrity sha512-rzICsvhcFcL4wSAvRPe+b9EEWB8cxj6yWy3FZdfs7ufi/0muNpFXWckWv1TC34em55sGXu2cMcwMKXg/O/Lc0Q==
"@ledgerhq/hw-transport-webusb@^6.29.3":
version "6.29.3"
resolved "https://registry.yarnpkg.com/@ledgerhq/hw-transport-webusb/-/hw-transport-webusb-6.29.3.tgz#ad507563c10f38626d8f747fd15efcde2356689c"
integrity sha512-8XGeJAOhWz8iulv2kpi/XPPkm0hGxPVcuhla/VOXSegVF8XKqZBgQGJmIzeJSMf9vSdzAmaGLpn4OtxB1nnJog==
dependencies:
"@ledgerhq/devices" "^8.3.0"
"@ledgerhq/errors" "^6.16.4"
"@ledgerhq/hw-transport" "^6.30.6"
"@ledgerhq/devices" "^8.4.3"
"@ledgerhq/errors" "^6.19.0"
"@ledgerhq/hw-transport" "^6.31.3"
"@ledgerhq/logs" "^6.12.0"

"@ledgerhq/hw-transport@^6.30.6":
version "6.30.6"
resolved "https://registry.yarnpkg.com/@ledgerhq/hw-transport/-/hw-transport-6.30.6.tgz#c6d84672ac4828f311831998f4101ea205215a6d"
integrity sha512-fT0Z4IywiuJuZrZE/+W0blkV5UCotDPFTYKLkKCLzYzuE6javva7D/ajRaIeR+hZ4kTmKF4EqnsmDCXwElez+w==
"@ledgerhq/hw-transport@^6.31.3":
version "6.31.3"
resolved "https://registry.yarnpkg.com/@ledgerhq/hw-transport/-/hw-transport-6.31.3.tgz#ceecea278ee200dbb8d7e2ce5e47e09a287c1611"
integrity sha512-rFplkHWF5NXtlYwAusqLlMu298NHtRD+2q/jrTYc//uu/xJO9LkDIgKid6IVF2+e1Wj7yX6YQVrU6L0Yu1ntEw==
dependencies:
"@ledgerhq/devices" "^8.3.0"
"@ledgerhq/errors" "^6.16.4"
"@ledgerhq/devices" "^8.4.3"
"@ledgerhq/errors" "^6.19.0"
"@ledgerhq/logs" "^6.12.0"
events "^3.3.0"

Expand Down Expand Up @@ -2132,6 +2131,11 @@ bindings@^1.3.0:
dependencies:
file-uri-to-path "1.0.0"

bip32-path@^0.4.2:
version "0.4.2"
resolved "https://registry.yarnpkg.com/bip32-path/-/bip32-path-0.4.2.tgz#5db0416ad6822712f077836e2557b8697c0c7c99"
integrity sha512-ZBMCELjJfcNMkz5bDuJ1WrYvjlhEF5k6mQ8vUr4N7MbVRsXei7ZOg8VhhwMfNiW68NWmLkgkc6WvTickrLGprQ==

bip66@^1.1.5:
version "1.1.5"
resolved "https://registry.yarnpkg.com/bip66/-/bip66-1.1.5.tgz#01fa8748785ca70955d5011217d1b3139969ca22"
Expand Down Expand Up @@ -5368,7 +5372,16 @@ string-argv@~0.3.2:
resolved "https://registry.yarnpkg.com/string-argv/-/string-argv-0.3.2.tgz#2b6d0ef24b656274d957d54e0a4bbf6153dc02b6"
integrity sha512-aqD2Q0144Z+/RqG52NeHEkZauTAUWJO8c6yTftGJKO3Tja5tUgIfmIl6kExvhtxSDP7fXB6DvzkfMpCd/F3G+Q==

"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0:
"string-width-cjs@npm:string-width@^4.2.0":
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
dependencies:
emoji-regex "^8.0.0"
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

string-width@^4.1.0, string-width@^4.2.0:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand Down Expand Up @@ -5448,7 +5461,14 @@ string_decoder@^1.1.1:
dependencies:
safe-buffer "~5.2.0"

"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"

strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
Expand Down

0 comments on commit ae09df0

Please sign in to comment.