Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ledger sdk to 0.6.0 #213

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -211,7 +209,6 @@ export const ApproveTransactionScreen: FC<ApproveTransactionScreenProps> = ({
selectedAccount?.networkId ?? "unknown",
)

const { tokenDetails: fungibleTokens } = useFungibleTokensWithBalance(selectedAccount)
const useLedger =
selectedAccount !== undefined && selectedAccount.signer.type === "ledger"
const [ledgerState, setLedgerState] = useState<
Expand Down Expand Up @@ -265,7 +262,7 @@ export const ApproveTransactionScreen: FC<ApproveTransactionScreenProps> = ({
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()
Expand Down Expand Up @@ -359,40 +356,3 @@ export const ApproveTransactionScreen: FC<ApproveTransactionScreenProps> = ({
</ConfirmScreen>
)
}

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)
}
67 changes: 10 additions & 57 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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==
Expand Down Expand Up @@ -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==
Expand Down Expand Up @@ -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==
Expand All @@ -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"
Expand Down Expand Up @@ -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==
Expand All @@ -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"
Expand Down
Loading