From cf9862ae1608f3cf18d297718ba258f06f8c342d Mon Sep 17 00:00:00 2001 From: lbqds Date: Thu, 22 Aug 2024 17:02:03 +0800 Subject: [PATCH] Update ledger sdk to 0.6.0 --- packages/extension/package.json | 2 +- .../actions/ApproveTransactionScreen.tsx | 46 +------------ yarn.lock | 67 +++---------------- 3 files changed, 14 insertions(+), 101 deletions(-) diff --git a/packages/extension/package.json b/packages/extension/package.json index bd4dd37b..a550f014 100644 --- a/packages/extension/package.json +++ b/packages/extension/package.json @@ -5,7 +5,7 @@ "license": "MIT", "devDependencies": { "@alephium/get-extension-wallet": "^1.5.0", - "@alephium/ledger-app": "0.5.2", + "@alephium/ledger-app": "0.6.0", "@alephium/token-list": "0.0.19", "@alephium/web3": "^1.5.0", "@alephium/web3-test": "^1.5.0", diff --git a/packages/extension/src/ui/features/actions/ApproveTransactionScreen.tsx b/packages/extension/src/ui/features/actions/ApproveTransactionScreen.tsx index eb425ece..0cd83198 100644 --- a/packages/extension/src/ui/features/actions/ApproveTransactionScreen.tsx +++ b/packages/extension/src/ui/features/actions/ApproveTransactionScreen.tsx @@ -1,5 +1,4 @@ import { AlephiumApp as LedgerApp } from "@alephium/ledger-app" -import { TokenMetadata, MAX_TOKEN_SIZE, MAX_TOKEN_SYMBOL_LENGTH } from "@alephium/ledger-app" import { ALPH_TOKEN_ID, ONE_ALPH, prettifyTokenAmount, TransactionBuilder } from "@alephium/web3" import { getHDWalletPath } from "@alephium/web3-wallet" import { L1, icons } from "@argent/ui" @@ -11,14 +10,13 @@ import { ReviewTransactionResult, TransactionParams, } from "../../../shared/actionQueue/types" -import { BaseTokenWithBalance, Token } from "../../../shared/token/type" -import { isEqualTokenId } from "../../services/token" +import { BaseTokenWithBalance } from "../../../shared/token/type" import { useAppState } from "../../app.state" import { routes } from "../../routes" import { usePageTracking } from "../../services/analytics" import { rejectAction } from "../../services/backgroundActions" import { Account } from "../accounts/Account" -import { useAllTokensWithBalance, useFungibleTokensWithBalance } from "../accountTokens/tokens.state" +import { useAllTokensWithBalance } from "../accountTokens/tokens.state" import { getLedgerApp } from "../ledger/utils" import { useNetwork } from "../networks/useNetworks" import { ConfirmScreen } from "./ConfirmScreen" @@ -211,7 +209,6 @@ export const ApproveTransactionScreen: FC = ({ selectedAccount?.networkId ?? "unknown", ) - const { tokenDetails: fungibleTokens } = useFungibleTokensWithBalance(selectedAccount) const useLedger = selectedAccount !== undefined && selectedAccount.signer.type === "ledger" const [ledgerState, setLedgerState] = useState< @@ -265,7 +262,7 @@ export const ApproveTransactionScreen: FC = ({ selectedAccount.signer.derivationIndex, ) const unsignedTx = Buffer.from(buildResult.result.unsignedTx, "hex") - const signature = await ledgerSignTx(app, path, unsignedTx, fungibleTokens, transaction) + const signature = await app.signUnsignedTx(path, unsignedTx) setLedgerState("succeeded") onSubmit({ ...buildResult, signature }) await app.close() @@ -359,40 +356,3 @@ export const ApproveTransactionScreen: FC = ({ ) } - -async function ledgerSignTx( - ledgerApp: LedgerApp, - path: string, - unsignedTx: Buffer, - fungibleTokens: Token[], - params: TransactionParams -) { - if (params.type !== 'TRANSFER') { - return ledgerApp.signUnsignedTx(path, unsignedTx) - } - const tokens: TokenMetadata[] = [] - const allTokenIds = params - .params - .destinations - .map((d) => d.tokens?.map((t) => t.id) ?? []) - .flat() - for (const tokenId of allTokenIds) { - if (tokens.length === MAX_TOKEN_SIZE) { - break - } - if (tokens.find((t) => isEqualTokenId(t.tokenId, tokenId)) !== undefined) { - continue - } - const tokenInfo = fungibleTokens.find((t) => isEqualTokenId(t.id, tokenId)) - if (tokenInfo === undefined || !tokenInfo.verified || tokenInfo.symbol.length > MAX_TOKEN_SYMBOL_LENGTH) { - continue - } - tokens.push({ - version: 0, - tokenId: tokenInfo.id, - symbol: tokenInfo.symbol, - decimals: tokenInfo.decimals - }) - } - return ledgerApp.signUnsignedTx(path, unsignedTx, tokens) -} diff --git a/yarn.lock b/yarn.lock index b6be4933..bc981069 100644 --- a/yarn.lock +++ b/yarn.lock @@ -26,13 +26,14 @@ "@alephium/web3" "^1.5.0" bowser "^2.11.0" -"@alephium/ledger-app@0.5.2": - version "0.5.2" - resolved "https://registry.yarnpkg.com/@alephium/ledger-app/-/ledger-app-0.5.2.tgz#2451c11af2974e9681b7b7967fe523c3f78045cd" - integrity sha512-1PEi9z6D4pq7cbfqUmDRiL2UooFDUVdX2v9STMAgcI9a5nJfGfx51rD1hYdLvElPGcj/yeafud4CUgr5cCvmsw== +"@alephium/ledger-app@0.6.0": + version "0.6.0" + resolved "https://registry.yarnpkg.com/@alephium/ledger-app/-/ledger-app-0.6.0.tgz#60fffa10b707391cd4bcfecfcb6592658c9621e5" + integrity sha512-qszjWh1R30YRaxggPSa6le9Hu1XFQTKFJnn2C7z8QLC6I5DcF4QRjFPbeRJVSSZc2GMvLsIvt7oUlFLjcvBiHA== dependencies: - "@alephium/web3" "^1.2.0" + "@alephium/web3" "^1.5.0" "@ledgerhq/hw-transport" "6.31.0" + blakejs "^1.2.1" "@alephium/token-list@0.0.19": version "0.0.19" @@ -62,24 +63,6 @@ elliptic "6.5.4" fs-extra "10.0.1" -"@alephium/web3@^1.2.0": - version "1.2.1" - resolved "https://registry.yarnpkg.com/@alephium/web3/-/web3-1.2.1.tgz#1a7155efb1ca5900baecb159294381c9e5fc35db" - integrity sha512-YrlSqMIwd9zh1L/4oTGxONMJXijzb+JX6ZFtSPite9FM1I9Zdle9Fc4BFRHRpAujpIyH9ECcfuGvzMCYaHLxGw== - dependencies: - "@noble/secp256k1" "1.7.1" - base-x "4.0.0" - bignumber.js "^9.1.1" - binary-parser "2.2.1" - blakejs "1.2.1" - bn.js "5.2.1" - cross-fetch "^3.1.5" - crypto-browserify "^3.12.0" - elliptic "6.5.4" - eventemitter3 "^4.0.7" - path-browserify "^1.0.1" - stream-browserify "^3.0.0" - "@alephium/web3@^1.5.0": version "1.5.0" resolved "https://registry.yarnpkg.com/@alephium/web3/-/web3-1.5.0.tgz#2949fd08fb1650a930c66730353957cdbef0dce0" @@ -8457,11 +8440,6 @@ binary-extensions@^2.0.0: resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.2.0.tgz#75f502eeaf9ffde42fc98829645be4ea76bd9e2d" integrity sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA== -binary-parser@2.2.1: - version "2.2.1" - resolved "https://registry.yarnpkg.com/binary-parser/-/binary-parser-2.2.1.tgz#4edc6da2dc56db73fa5ba450dfe6382ede8294ce" - integrity sha512-5ATpz/uPDgq5GgEDxTB4ouXCde7q2lqAQlSdBRQVl/AJnxmQmhIfyxJx+0MGu//D5rHQifkfGbWWlaysG0o9NA== - bindings@^1.5.0: version "1.5.0" resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.5.0.tgz#10353c9e945334bc0511a6d90b38fbc7c9c504df" @@ -8505,7 +8483,7 @@ bl@^4.0.3, bl@^4.1.0: inherits "^2.0.4" readable-stream "^3.4.0" -blakejs@1.2.1: +blakejs@1.2.1, blakejs@^1.2.1: version "1.2.1" resolved "https://registry.yarnpkg.com/blakejs/-/blakejs-1.2.1.tgz#5057e4206eadb4a97f7c0b6e197a505042fc3814" integrity sha512-QXUSXI3QVc/gJME0dBpXrag1kbzOqCjCX8/b54ntNyW6sjtoqxqRk3LTmXzaJoh71zMsDCjM+47jS7XiwN/+fQ== @@ -21291,16 +21269,7 @@ string-natural-compare@^3.0.1: resolved "https://registry.yarnpkg.com/string-natural-compare/-/string-natural-compare-3.0.1.tgz#7a42d58474454963759e8e8b7ae63d71c1e7fdf4" integrity sha512-n3sPwynL1nwKi3WJ6AIsClwBMa0zTi54fn2oLU6ndfTSIO05xaznjSf15PcBZU6FNWbmN5Q6cxT4V5hGvB4taw== -"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@^1.0.2 || 2 || 3 || 4", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.2, string-width@^4.2.3: +"string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.2, string-width@^4.2.3: 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== @@ -21400,7 +21369,7 @@ stringify-object@^3.3.0: is-obj "^1.0.1" is-regexp "^1.0.0" -"strip-ansi-cjs@npm:strip-ansi@^6.0.1": +"strip-ansi-cjs@npm:strip-ansi@^6.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== @@ -21414,13 +21383,6 @@ strip-ansi@^3.0.1: dependencies: ansi-regex "^2.0.0" -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== - dependencies: - ansi-regex "^5.0.1" - strip-ansi@^7.0.1: version "7.0.1" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.0.1.tgz#61740a08ce36b61e50e65653f07060d000975fb2" @@ -23740,7 +23702,7 @@ worker-rpc@^0.1.0: dependencies: microevent.ts "~0.1.1" -"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0": +"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0: version "7.0.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== @@ -23758,15 +23720,6 @@ wrap-ansi@^6.2.0: string-width "^4.1.0" strip-ansi "^6.0.0" -wrap-ansi@^7.0.0: - version "7.0.0" - resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" - integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== - dependencies: - ansi-styles "^4.0.0" - string-width "^4.1.0" - strip-ansi "^6.0.0" - wrap-ansi@^8.1.0: version "8.1.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"