@swapkit/wallet-hardware 4.2.11 → 4.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/dist/LICENSE +246 -0
  2. package/dist/{chunk-7fsaymh4.js → chunk-1jexf7qt.js} +3 -3
  3. package/dist/{chunk-7fsaymh4.js.map → chunk-1jexf7qt.js.map} +1 -1
  4. package/dist/chunk-1jpcb30j.js +5 -0
  5. package/dist/{chunk-fazw0jvt.js.map → chunk-1jpcb30j.js.map} +1 -1
  6. package/dist/chunk-4fapcrj9.js +5 -0
  7. package/dist/chunk-4fapcrj9.js.map +10 -0
  8. package/dist/chunk-d54qkn5p.js +4 -0
  9. package/dist/chunk-d54qkn5p.js.map +10 -0
  10. package/dist/chunk-jj2v7mke.js +4 -0
  11. package/dist/chunk-jj2v7mke.js.map +10 -0
  12. package/dist/chunk-p94hfx8x.js +4 -0
  13. package/dist/{chunk-zzfbcc7e.js.map → chunk-p94hfx8x.js.map} +1 -1
  14. package/dist/chunk-skvfn1dg.js +4 -0
  15. package/dist/chunk-skvfn1dg.js.map +10 -0
  16. package/dist/{chunk-37bgpz1y.js → chunk-ybje7f3s.js} +3 -3
  17. package/dist/{chunk-37bgpz1y.js.map → chunk-ybje7f3s.js.map} +1 -1
  18. package/dist/keepkey/index.cjs +2 -2
  19. package/dist/keepkey/index.cjs.map +5 -5
  20. package/dist/keepkey/index.js +2 -2
  21. package/dist/keepkey/index.js.map +5 -5
  22. package/dist/ledger/index.cjs +3 -3
  23. package/dist/ledger/index.cjs.map +11 -10
  24. package/dist/ledger/index.js +3 -3
  25. package/dist/ledger/index.js.map +11 -10
  26. package/dist/trezor/index.cjs +2 -2
  27. package/dist/trezor/index.cjs.map +3 -3
  28. package/dist/trezor/index.js +2 -2
  29. package/dist/trezor/index.js.map +3 -3
  30. package/dist/types/core.d.ts +18 -0
  31. package/dist/types/core.d.ts.map +1 -0
  32. package/dist/types/keepkey/chains/evm.d.ts +2 -2
  33. package/dist/types/keepkey/chains/evm.d.ts.map +1 -1
  34. package/dist/types/keepkey/chains/ripple.d.ts +15 -8
  35. package/dist/types/keepkey/chains/ripple.d.ts.map +1 -1
  36. package/dist/types/keepkey/chains/utxo.d.ts +331 -5
  37. package/dist/types/keepkey/chains/utxo.d.ts.map +1 -1
  38. package/dist/types/keepkey/index.d.ts +3 -3
  39. package/dist/types/keepkey/index.d.ts.map +1 -1
  40. package/dist/types/ledger/clients/evm.d.ts +3 -2
  41. package/dist/types/ledger/clients/evm.d.ts.map +1 -1
  42. package/dist/types/ledger/clients/sui.d.ts +27 -0
  43. package/dist/types/ledger/clients/sui.d.ts.map +1 -0
  44. package/dist/types/ledger/clients/thorchain/lib.d.ts.map +1 -1
  45. package/dist/types/ledger/clients/utxo.d.ts +43 -7
  46. package/dist/types/ledger/clients/utxo.d.ts.map +1 -1
  47. package/dist/types/ledger/clients/xrp.d.ts +2 -2
  48. package/dist/types/ledger/clients/xrp.d.ts.map +1 -1
  49. package/dist/types/ledger/helpers/getLedgerAddress.d.ts.map +1 -1
  50. package/dist/types/ledger/helpers/getLedgerClient.d.ts +4 -1
  51. package/dist/types/ledger/helpers/getLedgerClient.d.ts.map +1 -1
  52. package/dist/types/ledger/index.d.ts +3 -3
  53. package/dist/types/ledger/index.d.ts.map +1 -1
  54. package/dist/types/ledger/types.d.ts +2 -0
  55. package/dist/types/ledger/types.d.ts.map +1 -1
  56. package/dist/types/trezor/evmSigner.d.ts +2 -2
  57. package/dist/types/trezor/evmSigner.d.ts.map +1 -1
  58. package/dist/types/trezor/index.d.ts +3 -3
  59. package/dist/types/trezor/index.d.ts.map +1 -1
  60. package/package.json +51 -40
  61. package/dist/chunk-4k7gb7ss.js +0 -4
  62. package/dist/chunk-4k7gb7ss.js.map +0 -10
  63. package/dist/chunk-93cj7bky.js +0 -4
  64. package/dist/chunk-93cj7bky.js.map +0 -10
  65. package/dist/chunk-fazw0jvt.js +0 -4
  66. package/dist/chunk-zzfbcc7e.js +0 -5
  67. package/src/index.ts +0 -1
  68. package/src/keepkey/chains/cosmos.ts +0 -69
  69. package/src/keepkey/chains/evm.ts +0 -114
  70. package/src/keepkey/chains/mayachain.ts +0 -98
  71. package/src/keepkey/chains/ripple.ts +0 -88
  72. package/src/keepkey/chains/thorchain.ts +0 -93
  73. package/src/keepkey/chains/utxo.ts +0 -137
  74. package/src/keepkey/coins.ts +0 -67
  75. package/src/keepkey/index.ts +0 -155
  76. package/src/ledger/clients/cosmos.ts +0 -84
  77. package/src/ledger/clients/evm.ts +0 -141
  78. package/src/ledger/clients/near.ts +0 -63
  79. package/src/ledger/clients/thorchain/common.ts +0 -93
  80. package/src/ledger/clients/thorchain/helpers.ts +0 -120
  81. package/src/ledger/clients/thorchain/index.ts +0 -87
  82. package/src/ledger/clients/thorchain/lib.ts +0 -278
  83. package/src/ledger/clients/thorchain/utils.ts +0 -69
  84. package/src/ledger/clients/tron.ts +0 -85
  85. package/src/ledger/clients/utxo.ts +0 -154
  86. package/src/ledger/clients/xrp.ts +0 -50
  87. package/src/ledger/cosmosTypes.ts +0 -98
  88. package/src/ledger/helpers/getLedgerAddress.ts +0 -69
  89. package/src/ledger/helpers/getLedgerClient.ts +0 -117
  90. package/src/ledger/helpers/getLedgerTransport.ts +0 -102
  91. package/src/ledger/helpers/index.ts +0 -3
  92. package/src/ledger/index.ts +0 -299
  93. package/src/ledger/interfaces/CosmosLedgerInterface.ts +0 -54
  94. package/src/ledger/types.ts +0 -40
  95. package/src/trezor/evmSigner.ts +0 -177
  96. package/src/trezor/index.ts +0 -349
@@ -1,141 +0,0 @@
1
- import type EthereumApp from "@ledgerhq/hw-app-eth";
2
- import {
3
- ChainId,
4
- type DerivationPathArray,
5
- derivationPathToString,
6
- NetworkDerivationPath,
7
- SwapKitError,
8
- } from "@swapkit/helpers";
9
- import { AbstractSigner, type Provider, type TransactionRequest } from "ethers";
10
-
11
- import { getLedgerTransport } from "../helpers/getLedgerTransport";
12
-
13
- class EVMLedgerInterface extends AbstractSigner {
14
- chainId: ChainId = ChainId.Ethereum;
15
- derivationPath = "";
16
- ledgerApp: InstanceType<typeof EthereumApp> | null = null;
17
- ledgerTimeout = 50000;
18
-
19
- constructor({
20
- provider,
21
- derivationPath = NetworkDerivationPath.OP,
22
- chainId = ChainId.Optimism,
23
- }: { provider: Provider; derivationPath?: DerivationPathArray | string; chainId?: ChainId }) {
24
- super(provider);
25
-
26
- this.chainId = chainId || ChainId.Ethereum;
27
- this.derivationPath = typeof derivationPath === "string" ? derivationPath : derivationPathToString(derivationPath);
28
-
29
- Object.defineProperty(this, "provider", { enumerable: true, value: provider || null, writable: false });
30
- }
31
-
32
- connect = (provider: Provider) =>
33
- new EVMLedgerInterface({ chainId: this.chainId, derivationPath: this.derivationPath, provider });
34
-
35
- checkOrCreateTransportAndLedger = async () => {
36
- if (this.ledgerApp) return;
37
- await this.createTransportAndLedger();
38
- };
39
-
40
- createTransportAndLedger = async () => {
41
- const transport = await getLedgerTransport();
42
- const EthereumApp = (await import("@ledgerhq/hw-app-eth")).default;
43
-
44
- this.ledgerApp = new EthereumApp(transport);
45
- };
46
-
47
- getAddress = async () => {
48
- const response = await this.getAddressAndPubKey();
49
- if (!response) throw new SwapKitError("wallet_ledger_failed_to_get_address");
50
- return response.address;
51
- };
52
-
53
- getAddressAndPubKey = async () => {
54
- await this.createTransportAndLedger();
55
- return this.ledgerApp?.getAddress(this.derivationPath);
56
- };
57
-
58
- showAddressAndPubKey = async () => {
59
- await this.createTransportAndLedger();
60
- return this.ledgerApp?.getAddress(this.derivationPath, true);
61
- };
62
-
63
- signMessage = async (messageHex: string) => {
64
- const { Signature } = await import("ethers");
65
- await this.createTransportAndLedger();
66
-
67
- const sig = await this.ledgerApp?.signPersonalMessage(this.derivationPath, messageHex);
68
-
69
- if (!sig) throw new SwapKitError("wallet_ledger_signing_error");
70
-
71
- sig.r = `0x${sig.r}`;
72
- sig.s = `0x${sig.s}`;
73
- return Signature.from(sig).serialized;
74
- };
75
-
76
- sendTransaction = async (tx: TransactionRequest): Promise<any> => {
77
- if (!this.provider) throw new SwapKitError("wallet_ledger_no_provider");
78
-
79
- const signedTxHex = await this.signTransaction(tx);
80
-
81
- return await this.provider.broadcastTransaction(signedTxHex);
82
- };
83
-
84
- signTypedData(): Promise<string> {
85
- throw new SwapKitError("wallet_ledger_method_not_supported", { method: "signTypedData" });
86
- }
87
-
88
- signTransaction = async (tx: TransactionRequest) => {
89
- const { Transaction } = await import("ethers");
90
- await this.createTransportAndLedger();
91
-
92
- const transactionCount = await this.provider?.getTransactionCount(tx.from || (await this.getAddress()));
93
-
94
- const baseTx = {
95
- chainId: tx.chainId || this.chainId,
96
- data: tx.data,
97
- gasLimit: tx.gasLimit,
98
- ...(tx.gasPrice && { gasPrice: tx.gasPrice }),
99
- ...(!tx.gasPrice &&
100
- tx.maxFeePerGas && { maxFeePerGas: tx.maxFeePerGas, maxPriorityFeePerGas: tx.maxPriorityFeePerGas }),
101
- nonce: tx.nonce !== undefined ? Number((tx.nonce || transactionCount || 0).toString()) : transactionCount,
102
- to: tx.to?.toString(),
103
- type: tx.type && !Number.isNaN(tx.type) ? tx.type : tx.maxFeePerGas ? 2 : 0,
104
- value: tx.value,
105
- };
106
-
107
- // ledger expects the tx to be serialized without the 0x prefix
108
- const unsignedTx = Transaction.from(baseTx).unsignedSerialized.slice(2);
109
-
110
- const { ledgerService } = await import("@ledgerhq/hw-app-eth");
111
-
112
- const resolution = await ledgerService.resolveTransaction(unsignedTx, {}, { erc20: true, externalPlugins: true });
113
-
114
- const signature = await this.ledgerApp?.signTransaction(this.derivationPath, unsignedTx, resolution);
115
-
116
- if (!signature) throw new SwapKitError("wallet_ledger_signing_error");
117
-
118
- const { r, s, v } = signature;
119
-
120
- return Transaction.from({ ...baseTx, signature: { r: `0x${r}`, s: `0x${s}`, v: Number(BigInt(v)) } }).serialized;
121
- };
122
- }
123
-
124
- type LedgerParams = { provider: Provider; derivationPath?: DerivationPathArray };
125
-
126
- export const ArbitrumLedger = (params: LedgerParams) =>
127
- new EVMLedgerInterface({ ...params, chainId: ChainId.Arbitrum });
128
- export const AuroraLedger = (params: LedgerParams) => new EVMLedgerInterface({ ...params, chainId: ChainId.Aurora });
129
- export const AvalancheLedger = (params: LedgerParams) =>
130
- new EVMLedgerInterface({ ...params, chainId: ChainId.Avalanche });
131
- export const BaseLedger = (params: LedgerParams) => new EVMLedgerInterface({ ...params, chainId: ChainId.Base });
132
- export const EthereumLedger = (params: LedgerParams) =>
133
- new EVMLedgerInterface({ ...params, chainId: ChainId.Ethereum });
134
- export const GnosisLedger = (params: LedgerParams) => new EVMLedgerInterface({ ...params, chainId: ChainId.Gnosis });
135
- export const OptimismLedger = (params: LedgerParams) =>
136
- new EVMLedgerInterface({ ...params, chainId: ChainId.Optimism });
137
- export const PolygonLedger = (params: LedgerParams) => new EVMLedgerInterface({ ...params, chainId: ChainId.Polygon });
138
- export const BinanceSmartChainLedger = (params: LedgerParams) =>
139
- new EVMLedgerInterface({ ...params, chainId: ChainId.BinanceSmartChain });
140
- export const MonadLedger = (params: LedgerParams) => new EVMLedgerInterface({ ...params, chainId: ChainId.Monad });
141
- export const XLayerLedger = (params: LedgerParams) => new EVMLedgerInterface({ ...params, chainId: ChainId.XLayer });
@@ -1,63 +0,0 @@
1
- import type { SignedTransaction, Transaction } from "@near-js/transactions";
2
- import type { DerivationPathArray } from "@swapkit/helpers";
3
- import type { NearSigner } from "@swapkit/toolboxes/near";
4
- import { getLedgerTransport } from "../helpers/getLedgerTransport";
5
-
6
- export async function getNearLedgerClient(derivationPath?: DerivationPathArray) {
7
- const Near = (await import("@ledgerhq/hw-app-near")).default;
8
- const { Chain, NetworkDerivationPath, SwapKitError } = await import("@swapkit/helpers");
9
- const transport = await getLedgerTransport();
10
- const nearApp = new Near(transport);
11
-
12
- const path = (derivationPath || NetworkDerivationPath[Chain.Near]).join("'/").concat("'");
13
-
14
- const { address, publicKey: pubKeyHex } = await nearApp.getAddress(path);
15
-
16
- const signer = {
17
- getAddress() {
18
- return Promise.resolve(address);
19
- },
20
- async getPublicKey() {
21
- const { PublicKey } = await import("@near-js/crypto");
22
- return PublicKey.fromString(`ed25519:${pubKeyHex}`);
23
- },
24
-
25
- signDelegateAction(_delegateAction: any) {
26
- return Promise.reject(
27
- new SwapKitError("wallet_ledger_method_not_supported", { method: "signDelegateAction", wallet: "Ledger" }),
28
- );
29
- },
30
-
31
- signNep413Message(
32
- _message: string,
33
- _accountId: string,
34
- _recipient: string,
35
- _nonce: Uint8Array,
36
- _callbackUrl?: string,
37
- ) {
38
- return Promise.reject(
39
- new SwapKitError("wallet_ledger_method_not_supported", { method: "signNep413Message", wallet: "Ledger" }),
40
- );
41
- },
42
-
43
- async signTransaction(transaction: Transaction) {
44
- const { Signature, SignedTransaction } = await import("@near-js/transactions");
45
- try {
46
- const signatureArray = await nearApp.signTransaction(transaction.encode(), path);
47
- if (!signatureArray) {
48
- throw new Error("Signature undefined");
49
- }
50
-
51
- const signature = new Signature({ data: signatureArray, keyType: 0 });
52
-
53
- const signedTransaction = new SignedTransaction({ signature, transaction });
54
-
55
- return [signatureArray, signedTransaction] as [Uint8Array<ArrayBufferLike>, SignedTransaction];
56
- } catch (error) {
57
- throw new SwapKitError("wallet_ledger_signing_error", { error });
58
- }
59
- },
60
- };
61
-
62
- return signer as NearSigner;
63
- }
@@ -1,93 +0,0 @@
1
- export const CLA = 0x55;
2
- export const CHUNK_SIZE = 250;
3
- export const APP_KEY = "CSM";
4
-
5
- export const INS = {
6
- GET_ADDR_SECP256K1: 0x04,
7
- GET_VERSION: 0x00,
8
- INS_PUBLIC_KEY_SECP256K1: 0x01, // Obsolete
9
- SIGN_SECP256K1: 0x02,
10
- };
11
-
12
- export const PAYLOAD_TYPE = { ADD: 0x01, INIT: 0x00, LAST: 0x02 };
13
-
14
- export const P1_VALUES = { ONLY_RETRIEVE: 0x00, SHOW_ADDRESS_IN_DEVICE: 0x01 };
15
-
16
- export const P2_VALUES = { JSON: 0x0 };
17
-
18
- export const ERROR_CODE = { NoError: 0x9000 };
19
-
20
- const ERROR_DESCRIPTION: any = {
21
- 1: "U2F: Unknown",
22
- 2: "U2F: Bad request",
23
- 3: "U2F: Configuration unsupported",
24
- 4: "U2F: Device Ineligible",
25
- 5: "U2F: Timeout",
26
- 14: "Timeout",
27
- 25600: "Execution Error",
28
- 26368: "Wrong Length",
29
- 26626: "Error deriving keys",
30
- 27010: "Empty Buffer",
31
- 27011: "Output buffer too small",
32
- 27012: "Data is invalid",
33
- 27013: "Conditions not satisfied",
34
- 27014: "Transaction rejected",
35
- 27264: "Bad key handle",
36
- 27392: "Invalid P1/P2",
37
- 27904: "Instruction not supported",
38
- 28160: "App does not seem to be open",
39
- 28416: "Unknown error",
40
- 28417: "Sign/verify error",
41
- 36864: "No errors",
42
- 36865: "Device is busy",
43
- };
44
-
45
- export function errorCodeToString(statusCode: number) {
46
- if (statusCode in ERROR_DESCRIPTION) return ERROR_DESCRIPTION[statusCode];
47
- return `Unknown Status Code: ${statusCode}`;
48
- }
49
-
50
- function isDict(v: any) {
51
- return typeof v === "object" && v !== null && !Array.isArray(v) && !(v instanceof Date);
52
- }
53
-
54
- export function processErrorResponse(response: any) {
55
- if (response) {
56
- if (isDict(response)) {
57
- if (Object.hasOwn(response, "statusCode")) {
58
- return { error_message: errorCodeToString(response.statusCode), return_code: response.statusCode };
59
- }
60
-
61
- if (Object.hasOwn(response, "return_code") && Object.hasOwn(response, "error_message")) {
62
- return response;
63
- }
64
- }
65
- return { error_message: response.toString(), return_code: 0xffff };
66
- }
67
-
68
- return { error_message: response.toString(), return_code: 0xffff };
69
- }
70
-
71
- export function getVersion(transport: any) {
72
- return transport.send(CLA, INS.GET_VERSION, 0, 0).then((response: any) => {
73
- const errorCodeData = response.slice(-2);
74
- const returnCode = errorCodeData[0] * 256 + errorCodeData[1];
75
-
76
- let targetId = 0;
77
- if (response.length >= 9) {
78
- targetId = (response[5] << 24) + (response[6] << 16) + (response[7] << 8) + (response[8] << 0);
79
- }
80
-
81
- return {
82
- device_locked: response[4] === 1,
83
- error_message: errorCodeToString(returnCode),
84
- major: response[1],
85
- minor: response[2],
86
- patch: response[3],
87
- return_code: returnCode,
88
- target_id: targetId.toString(16),
89
- // ///
90
- test_mode: response[0] !== 0,
91
- };
92
- }, processErrorResponse);
93
- }
@@ -1,120 +0,0 @@
1
- import { SwapKitError } from "@swapkit/helpers";
2
- import { CLA, ERROR_CODE, errorCodeToString, INS, P2_VALUES, PAYLOAD_TYPE, processErrorResponse } from "./common";
3
-
4
- export function serializePathv1(path: number[]) {
5
- if (path == null || path.length < 3) {
6
- throw new SwapKitError("wallet_ledger_invalid_params", { reason: "Path too short" });
7
- }
8
- if (path.length > 10) {
9
- throw new SwapKitError("wallet_ledger_invalid_params", { reason: "Path too long" });
10
- }
11
- const buf = Buffer.alloc(1 + 4 * path.length);
12
- buf.writeUInt8(path.length, 0);
13
- for (let i = 0; i < path.length; i += 1) {
14
- let v = path[i] || 0;
15
- if (i < 3) {
16
- // eslint-disable-next-line no-bitwise
17
- v |= 0x80000000; // Harden
18
- }
19
- buf.writeInt32LE(v, 1 + i * 4);
20
- }
21
- return buf;
22
- }
23
-
24
- export function signSendChunkv1(app: any, chunkIdx: number, _chunkNum: number, chunk: Buffer, txType = P2_VALUES.JSON) {
25
- return app.transport
26
- .send(CLA, INS.SIGN_SECP256K1, chunkIdx, txType, chunk, [ERROR_CODE.NoError, 0x6984, 0x6a80])
27
- .then((response: any) => {
28
- const errorCodeData = response.slice(-2);
29
- const returnCode = errorCodeData[0] * 256 + errorCodeData[1];
30
- let errorMessage = errorCodeToString(returnCode);
31
-
32
- if (returnCode === 0x6a80 || returnCode === 0x6984) {
33
- errorMessage = `${errorMessage} : ${response.slice(0, response.length - 2).toString("ascii")}`;
34
- }
35
-
36
- let signature: any = null;
37
- if (response.length > 2) {
38
- signature = response.slice(0, response.length - 2);
39
- }
40
-
41
- return { error_message: errorMessage, return_code: returnCode, signature };
42
- }, processErrorResponse);
43
- }
44
-
45
- function compressPublicKey(publicKey: Buffer) {
46
- if (publicKey.length !== 65) {
47
- throw new SwapKitError("wallet_ledger_invalid_params", {
48
- reason: "decompressed public key length should be 65 bytes",
49
- });
50
- }
51
- const y = publicKey.slice(33, 65);
52
-
53
- // @ts-expect-error
54
- const z = Buffer.from([2 + (y[y.length - 1] & 1)]);
55
- return Buffer.concat([z, publicKey.slice(1, 33)]);
56
- }
57
-
58
- export function publicKeyv1(app: any, data: Buffer) {
59
- return app.transport
60
- .send(CLA, INS.INS_PUBLIC_KEY_SECP256K1, 0, 0, data, [ERROR_CODE.NoError])
61
- .then((response: any) => {
62
- const errorCodeData = response.slice(-2);
63
- const returnCode = errorCodeData[0] * 256 + errorCodeData[1];
64
- const pk = Buffer.from(response.slice(0, 65));
65
-
66
- return {
67
- compressed_pk: compressPublicKey(pk),
68
- error_message: errorCodeToString(returnCode),
69
- pk,
70
- return_code: returnCode,
71
- };
72
- }, processErrorResponse);
73
- }
74
-
75
- export function serializePathv2(path: number[]) {
76
- if (!path || path.length !== 5) {
77
- throw new SwapKitError("wallet_ledger_invalid_params", { reason: "Path must be exactly 5 elements" });
78
- }
79
-
80
- const buf = Buffer.alloc(20);
81
- // @ts-expect-error
82
- buf.writeUInt32LE(0x80000000 + path[0], 0);
83
- // @ts-expect-error
84
- buf.writeUInt32LE(0x80000000 + path[1], 4);
85
- // @ts-expect-error
86
- buf.writeUInt32LE(0x80000000 + path[2], 8);
87
- // @ts-expect-error
88
- buf.writeUInt32LE(path[3], 12);
89
- // @ts-expect-error
90
- buf.writeUInt32LE(path[4], 16);
91
-
92
- return buf;
93
- }
94
-
95
- export function signSendChunkv2(app: any, chunkIdx: number, chunkNum: number, chunk: Buffer, txType = P2_VALUES.JSON) {
96
- let payloadType = PAYLOAD_TYPE.ADD;
97
- if (chunkIdx === 1) {
98
- payloadType = PAYLOAD_TYPE.INIT;
99
- }
100
- if (chunkIdx === chunkNum) {
101
- payloadType = PAYLOAD_TYPE.LAST;
102
- }
103
-
104
- return signSendChunkv1(app, payloadType, 0, chunk, txType);
105
- }
106
-
107
- export function publicKeyv2(app: any, data: Buffer) {
108
- return app.transport.send(CLA, INS.GET_ADDR_SECP256K1, 0, 0, data, [ERROR_CODE.NoError]).then((response: any) => {
109
- const errorCodeData = response.slice(-2);
110
- const returnCode = errorCodeData[0] * 256 + errorCodeData[1];
111
- const compressedPk = Buffer.from(response.slice(0, 33));
112
-
113
- return {
114
- compressed_pk: compressedPk,
115
- error_message: errorCodeToString(returnCode),
116
- pk: "OBSOLETE PROPERTY",
117
- return_code: returnCode,
118
- };
119
- }, processErrorResponse);
120
- }
@@ -1,87 +0,0 @@
1
- import { base64 } from "@scure/base";
2
- import { type DerivationPathArray, NetworkDerivationPath, SwapKitError } from "@swapkit/helpers";
3
-
4
- import { CosmosLedgerInterface } from "../../interfaces/CosmosLedgerInterface";
5
- import type { GetAddressAndPubKeyResponse } from "../../types";
6
- import { getSignature } from "./utils";
7
-
8
- export class THORChainLedger extends CosmosLedgerInterface {
9
- private pubKey: string | null = null;
10
-
11
- derivationPath: DerivationPathArray;
12
-
13
- constructor(derivationPath: DerivationPathArray = NetworkDerivationPath.THOR) {
14
- super();
15
- this.chain = "thor";
16
- this.derivationPath = derivationPath;
17
- }
18
-
19
- get pubkey() {
20
- return this.pubKey;
21
- }
22
-
23
- connect = async () => {
24
- await this.checkOrCreateTransportAndLedger();
25
- const { compressed_pk, bech32_address }: GetAddressAndPubKeyResponse = await this.getAddressAndPubKey();
26
-
27
- this.pubKey = base64.encode(compressed_pk);
28
-
29
- return bech32_address;
30
- };
31
-
32
- getAddressAndPubKey = async () => {
33
- await this.checkOrCreateTransportAndLedger(true);
34
-
35
- const response: GetAddressAndPubKeyResponse = await this.ledgerApp.getAddressAndPubKey(
36
- this.derivationPath,
37
- this.chain,
38
- );
39
-
40
- this.validateResponse(response.return_code, response.error_message);
41
-
42
- return response;
43
- };
44
-
45
- showAddressAndPubKey = async () => {
46
- await this.checkOrCreateTransportAndLedger(true);
47
-
48
- const response: GetAddressAndPubKeyResponse = await this.ledgerApp.showAddressAndPubKey(
49
- this.derivationPath,
50
- this.chain,
51
- );
52
-
53
- this.validateResponse(response.return_code, response.error_message);
54
-
55
- return response;
56
- };
57
-
58
- signTransaction = async (rawTx: string, sequence = "0") => {
59
- await this.checkOrCreateTransportAndLedger(true);
60
-
61
- const { return_code, error_message, signature } = await this.ledgerApp.sign(this.derivationPath, rawTx);
62
-
63
- if (!this.pubKey) throw new SwapKitError("wallet_ledger_pubkey_not_found");
64
-
65
- this.validateResponse(return_code, error_message);
66
-
67
- return [
68
- {
69
- pub_key: { type: "tendermint/PubKeySecp256k1", value: this.pubKey },
70
- sequence,
71
- signature: getSignature(signature),
72
- },
73
- ];
74
- };
75
-
76
- sign = async (message: string) => {
77
- await this.checkOrCreateTransportAndLedger(true);
78
-
79
- const { return_code, error_message, signature } = await this.ledgerApp.sign(this.derivationPath, message);
80
-
81
- if (!this.pubKey) throw new SwapKitError("wallet_ledger_pubkey_not_found");
82
-
83
- this.validateResponse(return_code, error_message);
84
-
85
- return getSignature(signature);
86
- };
87
- }