@tcswap/wallet-hardware 4.2.16
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.
- package/dist/chunk-1w9rn6fj.js +5 -0
- package/dist/chunk-1w9rn6fj.js.map +10 -0
- package/dist/chunk-1z3vq8v6.js +4 -0
- package/dist/chunk-1z3vq8v6.js.map +10 -0
- package/dist/chunk-3jd7804n.js +4 -0
- package/dist/chunk-3jd7804n.js.map +10 -0
- package/dist/chunk-4pybhxzx.js +4 -0
- package/dist/chunk-4pybhxzx.js.map +10 -0
- package/dist/chunk-9kbkdt6e.js +4 -0
- package/dist/chunk-9kbkdt6e.js.map +10 -0
- package/dist/chunk-eng8tyvd.js +4 -0
- package/dist/chunk-eng8tyvd.js.map +10 -0
- package/dist/chunk-fazw0jvt.js +4 -0
- package/dist/chunk-fazw0jvt.js.map +9 -0
- package/dist/chunk-zzfbcc7e.js +5 -0
- package/dist/chunk-zzfbcc7e.js.map +9 -0
- package/dist/index.cjs +4 -0
- package/dist/index.cjs.map +9 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +9 -0
- package/dist/keepkey/index.cjs +4 -0
- package/dist/keepkey/index.cjs.map +15 -0
- package/dist/keepkey/index.js +4 -0
- package/dist/keepkey/index.js.map +15 -0
- package/dist/ledger/index.cjs +5 -0
- package/dist/ledger/index.cjs.map +25 -0
- package/dist/ledger/index.js +5 -0
- package/dist/ledger/index.js.map +25 -0
- package/dist/trezor/index.cjs +4 -0
- package/dist/trezor/index.cjs.map +10 -0
- package/dist/trezor/index.js +4 -0
- package/dist/trezor/index.js.map +10 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/keepkey/chains/cosmos.d.ts +7 -0
- package/dist/types/keepkey/chains/cosmos.d.ts.map +1 -0
- package/dist/types/keepkey/chains/evm.d.ts +29 -0
- package/dist/types/keepkey/chains/evm.d.ts.map +1 -0
- package/dist/types/keepkey/chains/mayachain.d.ts +10 -0
- package/dist/types/keepkey/chains/mayachain.d.ts.map +1 -0
- package/dist/types/keepkey/chains/ripple.d.ts +37 -0
- package/dist/types/keepkey/chains/ripple.d.ts.map +1 -0
- package/dist/types/keepkey/chains/thorchain.d.ts +10 -0
- package/dist/types/keepkey/chains/thorchain.d.ts.map +1 -0
- package/dist/types/keepkey/chains/utxo.d.ts +25 -0
- package/dist/types/keepkey/chains/utxo.d.ts.map +1 -0
- package/dist/types/keepkey/coins.d.ts +15 -0
- package/dist/types/keepkey/coins.d.ts.map +1 -0
- package/dist/types/keepkey/index.d.ts +15 -0
- package/dist/types/keepkey/index.d.ts.map +1 -0
- package/dist/types/ledger/clients/cosmos.d.ts +23 -0
- package/dist/types/ledger/clients/cosmos.d.ts.map +1 -0
- package/dist/types/ledger/clients/evm.d.ts +52 -0
- package/dist/types/ledger/clients/evm.d.ts.map +1 -0
- package/dist/types/ledger/clients/near.d.ts +7 -0
- package/dist/types/ledger/clients/near.d.ts.map +1 -0
- package/dist/types/ledger/clients/thorchain/common.d.ts +28 -0
- package/dist/types/ledger/clients/thorchain/common.d.ts.map +1 -0
- package/dist/types/ledger/clients/thorchain/helpers.d.ts +10 -0
- package/dist/types/ledger/clients/thorchain/helpers.d.ts.map +1 -0
- package/dist/types/ledger/clients/thorchain/index.d.ts +25 -0
- package/dist/types/ledger/clients/thorchain/index.d.ts.map +1 -0
- package/dist/types/ledger/clients/thorchain/lib.d.ts +25 -0
- package/dist/types/ledger/clients/thorchain/lib.d.ts.map +1 -0
- package/dist/types/ledger/clients/thorchain/utils.d.ts +5 -0
- package/dist/types/ledger/clients/thorchain/utils.d.ts.map +1 -0
- package/dist/types/ledger/clients/tron.d.ts +26 -0
- package/dist/types/ledger/clients/tron.d.ts.map +1 -0
- package/dist/types/ledger/clients/utxo.d.ts +43 -0
- package/dist/types/ledger/clients/utxo.d.ts.map +1 -0
- package/dist/types/ledger/clients/xrp.d.ts +11 -0
- package/dist/types/ledger/clients/xrp.d.ts.map +1 -0
- package/dist/types/ledger/cosmosTypes.d.ts +43 -0
- package/dist/types/ledger/cosmosTypes.d.ts.map +1 -0
- package/dist/types/ledger/helpers/getLedgerAddress.d.ts +10 -0
- package/dist/types/ledger/helpers/getLedgerAddress.d.ts.map +1 -0
- package/dist/types/ledger/helpers/getLedgerClient.d.ts +42 -0
- package/dist/types/ledger/helpers/getLedgerClient.d.ts.map +1 -0
- package/dist/types/ledger/helpers/getLedgerTransport.d.ts +6 -0
- package/dist/types/ledger/helpers/getLedgerTransport.d.ts.map +1 -0
- package/dist/types/ledger/helpers/index.d.ts +4 -0
- package/dist/types/ledger/helpers/index.d.ts.map +1 -0
- package/dist/types/ledger/index.d.ts +14 -0
- package/dist/types/ledger/index.d.ts.map +1 -0
- package/dist/types/ledger/interfaces/CosmosLedgerInterface.d.ts +14 -0
- package/dist/types/ledger/interfaces/CosmosLedgerInterface.d.ts.map +1 -0
- package/dist/types/ledger/types.d.ts +16 -0
- package/dist/types/ledger/types.d.ts.map +1 -0
- package/dist/types/trezor/evmSigner.d.ts +32 -0
- package/dist/types/trezor/evmSigner.d.ts.map +1 -0
- package/dist/types/trezor/index.d.ts +14 -0
- package/dist/types/trezor/index.d.ts.map +1 -0
- package/package.json +101 -0
- package/src/index.ts +1 -0
- package/src/keepkey/chains/cosmos.ts +69 -0
- package/src/keepkey/chains/evm.ts +117 -0
- package/src/keepkey/chains/mayachain.ts +102 -0
- package/src/keepkey/chains/ripple.ts +88 -0
- package/src/keepkey/chains/thorchain.ts +97 -0
- package/src/keepkey/chains/utxo.ts +141 -0
- package/src/keepkey/coins.ts +70 -0
- package/src/keepkey/index.ts +159 -0
- package/src/ledger/clients/cosmos.ts +83 -0
- package/src/ledger/clients/evm.ts +145 -0
- package/src/ledger/clients/near.ts +67 -0
- package/src/ledger/clients/thorchain/common.ts +93 -0
- package/src/ledger/clients/thorchain/helpers.ts +124 -0
- package/src/ledger/clients/thorchain/index.ts +91 -0
- package/src/ledger/clients/thorchain/lib.ts +282 -0
- package/src/ledger/clients/thorchain/utils.ts +71 -0
- package/src/ledger/clients/tron.ts +84 -0
- package/src/ledger/clients/utxo.ts +158 -0
- package/src/ledger/clients/xrp.ts +50 -0
- package/src/ledger/cosmosTypes.ts +102 -0
- package/src/ledger/helpers/getLedgerAddress.ts +73 -0
- package/src/ledger/helpers/getLedgerClient.ts +121 -0
- package/src/ledger/helpers/getLedgerTransport.ts +106 -0
- package/src/ledger/helpers/index.ts +3 -0
- package/src/ledger/index.ts +303 -0
- package/src/ledger/interfaces/CosmosLedgerInterface.ts +58 -0
- package/src/ledger/types.ts +40 -0
- package/src/trezor/evmSigner.ts +181 -0
- package/src/trezor/index.ts +350 -0
package/package.json
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
{
|
|
2
|
+
"author": "swapkit-oss",
|
|
3
|
+
"dependencies": {
|
|
4
|
+
"@cosmjs/crypto": "0.37.0",
|
|
5
|
+
"@keepkey/keepkey-sdk": "~0.2.62",
|
|
6
|
+
"@ledgerhq/devices": "~8.7.0",
|
|
7
|
+
"@ledgerhq/errors": "~6.27.0",
|
|
8
|
+
"@ledgerhq/hw-app-btc": "~10.12.0",
|
|
9
|
+
"@ledgerhq/hw-app-cosmos": "~6.32.9",
|
|
10
|
+
"@ledgerhq/hw-app-eth": "~6.47.0",
|
|
11
|
+
"@ledgerhq/hw-app-near": "~6.31.9",
|
|
12
|
+
"@ledgerhq/hw-app-trx": "~6.31.9",
|
|
13
|
+
"@ledgerhq/hw-app-xrp": "~6.32.7",
|
|
14
|
+
"@ledgerhq/hw-transport": "~6.31.0",
|
|
15
|
+
"@ledgerhq/hw-transport-webhid": "~6.30.9",
|
|
16
|
+
"@ledgerhq/hw-transport-webusb": "~6.29.13",
|
|
17
|
+
"@ledgerhq/wallet-api-client": "~1.12.4",
|
|
18
|
+
"@near-js/crypto": "~2.5.0",
|
|
19
|
+
"@near-js/transactions": "~2.5.0",
|
|
20
|
+
"@scure/base": "~2.0.0",
|
|
21
|
+
"@tcswap/helpers": "4.5.15",
|
|
22
|
+
"@tcswap/toolboxes": "4.3.15",
|
|
23
|
+
"@tcswap/wallet-core": "4.0.59",
|
|
24
|
+
"@trezor/connect-web": "~9.6.4",
|
|
25
|
+
"cosmjs-types": "~0.10.1",
|
|
26
|
+
"ethers": "^6.14.0",
|
|
27
|
+
"ripple-binary-codec": "2.5.1",
|
|
28
|
+
"ts-pattern": "^5.9.0"
|
|
29
|
+
},
|
|
30
|
+
"description": "USwap - Wallet Hardware",
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@cosmjs/crypto": "0.37.0",
|
|
33
|
+
"@keepkey/keepkey-sdk": "0.2.62",
|
|
34
|
+
"@ledgerhq/devices": "8.7.0",
|
|
35
|
+
"@ledgerhq/errors": "6.27.0",
|
|
36
|
+
"@ledgerhq/hw-app-btc": "10.12.0",
|
|
37
|
+
"@ledgerhq/hw-app-cosmos": "6.32.9",
|
|
38
|
+
"@ledgerhq/hw-app-eth": "6.47.0",
|
|
39
|
+
"@ledgerhq/hw-app-near": "6.31.9",
|
|
40
|
+
"@ledgerhq/hw-app-trx": "6.31.9",
|
|
41
|
+
"@ledgerhq/hw-app-xrp": "6.32.7",
|
|
42
|
+
"@ledgerhq/hw-transport": "6.31.10",
|
|
43
|
+
"@ledgerhq/hw-transport-webhid": "6.30.9",
|
|
44
|
+
"@ledgerhq/hw-transport-webusb": "6.29.13",
|
|
45
|
+
"@ledgerhq/wallet-api-client": "1.12.4",
|
|
46
|
+
"@near-js/crypto": "2.5.0",
|
|
47
|
+
"@near-js/transactions": "2.5.0",
|
|
48
|
+
"@scure/base": "2.0.0",
|
|
49
|
+
"@trezor/connect-web": "9.6.4",
|
|
50
|
+
"cosmjs-types": "0.10.1",
|
|
51
|
+
"ethers": "6.15.0",
|
|
52
|
+
"ripple-binary-codec": "2.5.1",
|
|
53
|
+
"ts-pattern": "5.9.0"
|
|
54
|
+
},
|
|
55
|
+
"exports": {
|
|
56
|
+
".": {
|
|
57
|
+
"bun": "./src/index.ts",
|
|
58
|
+
"import": "./dist/index.js",
|
|
59
|
+
"require": "./dist/index.cjs",
|
|
60
|
+
"types": "./dist/types/index.d.ts"
|
|
61
|
+
},
|
|
62
|
+
"./keepkey": {
|
|
63
|
+
"bun": "./src/keepkey/index.ts",
|
|
64
|
+
"import": "./dist/keepkey/index.js",
|
|
65
|
+
"require": "./dist/keepkey/index.cjs",
|
|
66
|
+
"types": "./dist/types/keepkey/index.d.ts"
|
|
67
|
+
},
|
|
68
|
+
"./ledger": {
|
|
69
|
+
"bun": "./src/ledger/index.ts",
|
|
70
|
+
"import": "./dist/ledger/index.js",
|
|
71
|
+
"require": "./dist/ledger/index.cjs",
|
|
72
|
+
"types": "./dist/types/ledger/index.d.ts"
|
|
73
|
+
},
|
|
74
|
+
"./trezor": {
|
|
75
|
+
"bun": "./src/trezor/index.ts",
|
|
76
|
+
"import": "./dist/trezor/index.js",
|
|
77
|
+
"require": "./dist/trezor/index.cjs",
|
|
78
|
+
"types": "./dist/types/trezor/index.d.ts"
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
"files": ["dist/", "src/"],
|
|
82
|
+
"homepage": "https://github.com/thorchain/TCSwap",
|
|
83
|
+
"license": "Apache-2.0",
|
|
84
|
+
"name": "@tcswap/wallet-hardware",
|
|
85
|
+
"repository": {
|
|
86
|
+
"directory": "packages/wallet-hardware",
|
|
87
|
+
"type": "git",
|
|
88
|
+
"url": "git+https://github.com/thorchain/TCSwap.git"
|
|
89
|
+
},
|
|
90
|
+
"scripts": {
|
|
91
|
+
"build": "bun run ./build.ts",
|
|
92
|
+
"build:clean": "rm -rf dist && bun run ./build.ts",
|
|
93
|
+
"clean": "rm -rf dist node_modules *.tsbuildinfo",
|
|
94
|
+
"test": "echo 'bun test'",
|
|
95
|
+
"test:ci": "echo 'bun test --coverage'",
|
|
96
|
+
"type-check": "bun tsc --noEmit",
|
|
97
|
+
"type-check:go": "tsgo"
|
|
98
|
+
},
|
|
99
|
+
"type": "module",
|
|
100
|
+
"version": "4.2.16"
|
|
101
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { KeepKeySdk } from "@keepkey/keepkey-sdk";
|
|
2
|
+
import type { GenericTransferParams } from "@tcswap/helpers";
|
|
3
|
+
import {
|
|
4
|
+
Chain,
|
|
5
|
+
DerivationPath,
|
|
6
|
+
type DerivationPathArray,
|
|
7
|
+
derivationPathToString,
|
|
8
|
+
GAIAConfig,
|
|
9
|
+
getRPCUrl,
|
|
10
|
+
} from "@tcswap/helpers";
|
|
11
|
+
|
|
12
|
+
import { bip32ToAddressNList } from "../coins";
|
|
13
|
+
|
|
14
|
+
export async function cosmosWalletMethods({
|
|
15
|
+
sdk,
|
|
16
|
+
derivationPath,
|
|
17
|
+
}: {
|
|
18
|
+
sdk: KeepKeySdk;
|
|
19
|
+
derivationPath?: DerivationPathArray;
|
|
20
|
+
}): Promise<any> {
|
|
21
|
+
const { DEFAULT_COSMOS_FEE_MAINNET, getCosmosToolbox, getFeeRateFromSwapKit, createStargateClient } = await import(
|
|
22
|
+
"@tcswap/toolboxes/cosmos"
|
|
23
|
+
);
|
|
24
|
+
const derivationPathString = derivationPath ? derivationPathToString(derivationPath) : `${DerivationPath.GAIA}/0`;
|
|
25
|
+
|
|
26
|
+
const { address: fromAddress } = (await sdk.address.cosmosGetAddress({
|
|
27
|
+
address_n: bip32ToAddressNList(derivationPathString),
|
|
28
|
+
})) as { address: string };
|
|
29
|
+
|
|
30
|
+
const toolbox = await getCosmosToolbox(Chain.Cosmos);
|
|
31
|
+
|
|
32
|
+
if (DEFAULT_COSMOS_FEE_MAINNET.amount[0]) {
|
|
33
|
+
DEFAULT_COSMOS_FEE_MAINNET.amount[0].amount = String(await getFeeRateFromSwapKit(GAIAConfig.chainId, 500));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// TODO support other cosmos assets
|
|
37
|
+
const transfer = async ({ assetValue, recipient, memo }: GenericTransferParams) => {
|
|
38
|
+
const amount = assetValue.getBaseValue("string");
|
|
39
|
+
const accountInfo = await toolbox.getAccount(fromAddress);
|
|
40
|
+
|
|
41
|
+
const keepKeySignedTx = await sdk.cosmos.cosmosSignAmino({
|
|
42
|
+
signDoc: {
|
|
43
|
+
account_number: accountInfo?.accountNumber.toString() ?? "",
|
|
44
|
+
chain_id: GAIAConfig.chainId,
|
|
45
|
+
fee: DEFAULT_COSMOS_FEE_MAINNET,
|
|
46
|
+
memo: memo || "",
|
|
47
|
+
msgs: [
|
|
48
|
+
{
|
|
49
|
+
type: "cosmos-sdk/MsgSend",
|
|
50
|
+
value: { amount: [{ amount, denom: "uatom" }], from_address: fromAddress, to_address: recipient },
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
sequence: accountInfo?.sequence.toString() ?? "",
|
|
54
|
+
},
|
|
55
|
+
signerAddress: fromAddress,
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const decodedBytes = atob(keepKeySignedTx.serialized);
|
|
59
|
+
const uint8Array = new Uint8Array(decodedBytes.length).map((_, i) => decodedBytes.charCodeAt(i));
|
|
60
|
+
|
|
61
|
+
const rpcUrl = await getRPCUrl(Chain.Cosmos);
|
|
62
|
+
const client = await createStargateClient(rpcUrl);
|
|
63
|
+
const response = await client.broadcastTx(uint8Array);
|
|
64
|
+
|
|
65
|
+
return response.transactionHash;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
return { ...toolbox, address: fromAddress, transfer };
|
|
69
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Modifications © 2025 Horizontal Systems.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { KeepKeySdk } from "@keepkey/keepkey-sdk";
|
|
6
|
+
import {
|
|
7
|
+
type Chain,
|
|
8
|
+
ChainToChainId,
|
|
9
|
+
type DerivationPathArray,
|
|
10
|
+
derivationPathToString,
|
|
11
|
+
NetworkDerivationPath,
|
|
12
|
+
USwapError,
|
|
13
|
+
} from "@tcswap/helpers";
|
|
14
|
+
import type { JsonRpcProvider, Provider, TransactionRequest } from "ethers";
|
|
15
|
+
import { AbstractSigner } from "ethers";
|
|
16
|
+
|
|
17
|
+
import { bip32ToAddressNList } from "../coins";
|
|
18
|
+
|
|
19
|
+
interface KeepKeyEVMSignerParams {
|
|
20
|
+
sdk: KeepKeySdk;
|
|
21
|
+
chain: Chain;
|
|
22
|
+
derivationPath?: DerivationPathArray;
|
|
23
|
+
provider: Provider | JsonRpcProvider;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export class KeepKeySigner extends AbstractSigner {
|
|
27
|
+
private sdk: KeepKeySdk;
|
|
28
|
+
private chain: Chain;
|
|
29
|
+
private derivationPath: DerivationPathArray;
|
|
30
|
+
private address: string;
|
|
31
|
+
readonly provider: Provider | JsonRpcProvider;
|
|
32
|
+
|
|
33
|
+
constructor({ sdk, chain, derivationPath, provider }: KeepKeyEVMSignerParams) {
|
|
34
|
+
super();
|
|
35
|
+
this.sdk = sdk;
|
|
36
|
+
this.chain = chain;
|
|
37
|
+
this.derivationPath = derivationPath || NetworkDerivationPath.ETH;
|
|
38
|
+
this.address = "";
|
|
39
|
+
this.provider = provider;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
signTypedData(): Promise<string> {
|
|
43
|
+
throw new USwapError("wallet_keepkey_method_not_supported", { method: "signTypedData" });
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
getAddress = async () => {
|
|
47
|
+
if (this.address) return this.address;
|
|
48
|
+
const { address } = await this.sdk.address.ethereumGetAddress({
|
|
49
|
+
address_n: bip32ToAddressNList(derivationPathToString(this.derivationPath)),
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
this.address = address;
|
|
53
|
+
return address;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
signMessage = (message: string) => this.sdk.eth.ethSign({ address: this.address, message }) as Promise<string>;
|
|
57
|
+
|
|
58
|
+
signTransaction = async ({
|
|
59
|
+
to,
|
|
60
|
+
value,
|
|
61
|
+
gasLimit,
|
|
62
|
+
nonce,
|
|
63
|
+
data,
|
|
64
|
+
maxFeePerGas,
|
|
65
|
+
maxPriorityFeePerGas,
|
|
66
|
+
gasPrice,
|
|
67
|
+
}: TransactionRequest) => {
|
|
68
|
+
if (!to) throw new USwapError("wallet_keepkey_invalid_params", { reason: "Missing to address" });
|
|
69
|
+
if (!gasLimit) throw new USwapError("wallet_keepkey_invalid_params", { reason: "Missing gasLimit" });
|
|
70
|
+
if (!data) throw new USwapError("wallet_keepkey_invalid_params", { reason: "Missing data" });
|
|
71
|
+
|
|
72
|
+
const isEIP1559 = !!((maxFeePerGas || maxPriorityFeePerGas) && !gasPrice);
|
|
73
|
+
if (isEIP1559 && !maxFeePerGas)
|
|
74
|
+
throw new USwapError("wallet_keepkey_invalid_params", { reason: "Missing maxFeePerGas" });
|
|
75
|
+
if (isEIP1559 && !maxPriorityFeePerGas)
|
|
76
|
+
throw new USwapError("wallet_keepkey_invalid_params", { reason: "Missing maxPriorityFeePerGas" });
|
|
77
|
+
if (!(isEIP1559 || gasPrice)) throw new USwapError("wallet_keepkey_invalid_params", { reason: "Missing gasPrice" });
|
|
78
|
+
|
|
79
|
+
const { toHexString } = await import("@tcswap/toolboxes/evm");
|
|
80
|
+
|
|
81
|
+
const nonceValue = nonce
|
|
82
|
+
? BigInt(nonce)
|
|
83
|
+
: BigInt(await this.provider.getTransactionCount(await this.getAddress(), "pending"));
|
|
84
|
+
|
|
85
|
+
const input = {
|
|
86
|
+
addressNList: [2147483692, 2147483708, 2147483648, 0, 0],
|
|
87
|
+
chainId: toHexString(BigInt(ChainToChainId[this.chain])),
|
|
88
|
+
data,
|
|
89
|
+
from: this.address,
|
|
90
|
+
gas: toHexString(BigInt(gasLimit)),
|
|
91
|
+
nonce: toHexString(nonceValue),
|
|
92
|
+
to: to.toString(),
|
|
93
|
+
value: toHexString(BigInt(value || 0)),
|
|
94
|
+
...(isEIP1559 && {
|
|
95
|
+
maxFeePerGas: toHexString(BigInt(maxFeePerGas?.toString() || "0")),
|
|
96
|
+
maxPriorityFeePerGas: toHexString(BigInt(maxPriorityFeePerGas?.toString() || "0")),
|
|
97
|
+
}),
|
|
98
|
+
...(!isEIP1559 && {
|
|
99
|
+
// Fixed syntax error and structure here
|
|
100
|
+
gasPrice: toHexString(BigInt(gasPrice?.toString() || "0")),
|
|
101
|
+
}),
|
|
102
|
+
};
|
|
103
|
+
const responseSign = await this.sdk.eth.ethSignTransaction(input);
|
|
104
|
+
return responseSign.serialized;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
sendTransaction = async (tx: TransactionRequest): Promise<any> => {
|
|
108
|
+
if (!this.provider) throw new USwapError("wallet_keepkey_no_provider");
|
|
109
|
+
|
|
110
|
+
const signedTxHex = await this.signTransaction(tx);
|
|
111
|
+
|
|
112
|
+
return await this.provider.broadcastTransaction(signedTxHex);
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
connect = (provider: Provider) =>
|
|
116
|
+
new KeepKeySigner({ chain: this.chain, derivationPath: this.derivationPath, provider, sdk: this.sdk });
|
|
117
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Modifications © 2025 Horizontal Systems.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { KeepKeySdk } from "@keepkey/keepkey-sdk";
|
|
6
|
+
import {
|
|
7
|
+
type AssetValue,
|
|
8
|
+
Chain,
|
|
9
|
+
DerivationPath,
|
|
10
|
+
type DerivationPathArray,
|
|
11
|
+
derivationPathToString,
|
|
12
|
+
type GenericTransferParams,
|
|
13
|
+
getRPCUrl,
|
|
14
|
+
MAYAConfig,
|
|
15
|
+
USwapError,
|
|
16
|
+
} from "@tcswap/helpers";
|
|
17
|
+
import type { ThorchainDepositParams } from "@tcswap/toolboxes/cosmos";
|
|
18
|
+
|
|
19
|
+
import { bip32ToAddressNList } from "../coins";
|
|
20
|
+
|
|
21
|
+
type SignTransactionParams = { assetValue: AssetValue; recipient?: string; sender: string; memo: string | undefined };
|
|
22
|
+
|
|
23
|
+
export async function mayachainWalletMethods({
|
|
24
|
+
sdk,
|
|
25
|
+
derivationPath,
|
|
26
|
+
}: {
|
|
27
|
+
sdk: KeepKeySdk;
|
|
28
|
+
derivationPath?: DerivationPathArray;
|
|
29
|
+
}): Promise<any> {
|
|
30
|
+
const { createStargateClient, getCosmosToolbox } = await import("@tcswap/toolboxes/cosmos");
|
|
31
|
+
|
|
32
|
+
const toolbox = await getCosmosToolbox(Chain.Maya);
|
|
33
|
+
const derivationPathString = derivationPath ? derivationPathToString(derivationPath) : `${DerivationPath.MAYA}/0`;
|
|
34
|
+
|
|
35
|
+
const { address: fromAddress } = (await sdk.address.mayachainGetAddress({
|
|
36
|
+
address_n: bip32ToAddressNList(derivationPathString),
|
|
37
|
+
})) as { address: string };
|
|
38
|
+
|
|
39
|
+
const signTransaction = async ({ assetValue, recipient, sender, memo }: SignTransactionParams) => {
|
|
40
|
+
const importedAmino = await import("@cosmjs/amino");
|
|
41
|
+
const makeSignDoc = importedAmino.makeSignDoc ?? importedAmino.default?.makeSignDoc;
|
|
42
|
+
const { getDenomWithChain } = await import("@tcswap/toolboxes/cosmos");
|
|
43
|
+
|
|
44
|
+
const account = await toolbox.getAccount(sender);
|
|
45
|
+
if (!account) throw new USwapError("wallet_keepkey_account_not_found");
|
|
46
|
+
const { accountNumber, sequence = 0 } = account;
|
|
47
|
+
const amount = assetValue.getBaseValue("string");
|
|
48
|
+
|
|
49
|
+
const isTransfer = recipient && recipient !== "";
|
|
50
|
+
|
|
51
|
+
// TODO check if we can move to toolbox created msg
|
|
52
|
+
const msg = isTransfer
|
|
53
|
+
? {
|
|
54
|
+
type: "mayachain/MsgSend",
|
|
55
|
+
value: {
|
|
56
|
+
amount: [{ amount, denom: assetValue.symbol.toLowerCase() }],
|
|
57
|
+
from_address: sender,
|
|
58
|
+
to_address: recipient,
|
|
59
|
+
},
|
|
60
|
+
}
|
|
61
|
+
: {
|
|
62
|
+
type: "mayachain/MsgDeposit",
|
|
63
|
+
value: { coins: [{ amount, asset: getDenomWithChain(assetValue) }], memo, signer: sender },
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const signDoc = makeSignDoc(
|
|
67
|
+
[msg],
|
|
68
|
+
{ amount: [], gas: "500000000" },
|
|
69
|
+
MAYAConfig.chainId,
|
|
70
|
+
memo,
|
|
71
|
+
accountNumber?.toString(),
|
|
72
|
+
sequence,
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
const sdkMethod = isTransfer ? sdk.mayachain.mayachainSignAminoTransfer : sdk.mayachain.mayachainSignAminoDeposit;
|
|
76
|
+
|
|
77
|
+
// @ts-expect-error TC
|
|
78
|
+
const signedTx = await sdkMethod({ signDoc, signerAddress: sender });
|
|
79
|
+
const decodedBytes = atob(signedTx.serialized);
|
|
80
|
+
return new Uint8Array(decodedBytes.length).map((_, i) => decodedBytes.charCodeAt(i));
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const transfer = async ({ assetValue, recipient, memo }: GenericTransferParams) => {
|
|
84
|
+
const rpcUrl = await getRPCUrl(Chain.Maya);
|
|
85
|
+
const stargateClient = await createStargateClient(rpcUrl);
|
|
86
|
+
const signedTransaction = await signTransaction({ assetValue, memo, recipient, sender: fromAddress });
|
|
87
|
+
const { transactionHash } = await stargateClient.broadcastTx(signedTransaction);
|
|
88
|
+
|
|
89
|
+
return transactionHash;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const deposit = async ({ assetValue, memo }: ThorchainDepositParams) => {
|
|
93
|
+
const rpcUrl = await getRPCUrl(Chain.Maya);
|
|
94
|
+
const stargateClient = await createStargateClient(rpcUrl);
|
|
95
|
+
const signedTransaction = await signTransaction({ assetValue, memo, sender: fromAddress });
|
|
96
|
+
const { transactionHash } = await stargateClient.broadcastTx(signedTransaction);
|
|
97
|
+
|
|
98
|
+
return transactionHash;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
return { ...toolbox, address: fromAddress, deposit, transfer };
|
|
102
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { KeepKeySdk } from "@keepkey/keepkey-sdk";
|
|
2
|
+
import {
|
|
3
|
+
Chain,
|
|
4
|
+
DerivationPath,
|
|
5
|
+
type DerivationPathArray,
|
|
6
|
+
derivationPathToString,
|
|
7
|
+
type GenericTransferParams,
|
|
8
|
+
} from "@tcswap/helpers";
|
|
9
|
+
import { getRippleToolbox } from "@tcswap/toolboxes/ripple";
|
|
10
|
+
import { bip32ToAddressNList } from "../coins";
|
|
11
|
+
|
|
12
|
+
export const rippleWalletMethods = async ({
|
|
13
|
+
sdk,
|
|
14
|
+
derivationPath,
|
|
15
|
+
}: {
|
|
16
|
+
sdk: KeepKeySdk;
|
|
17
|
+
derivationPath?: DerivationPathArray;
|
|
18
|
+
}) => {
|
|
19
|
+
// Derivation path handling (default to standard XRP 44'/144'/0'/0/0)
|
|
20
|
+
const derivationPathString = derivationPath
|
|
21
|
+
? derivationPathToString(derivationPath)
|
|
22
|
+
: `${DerivationPath[Chain.Ripple]}/0`;
|
|
23
|
+
|
|
24
|
+
// Fetch address from KeepKey
|
|
25
|
+
const { address } = await (sdk as any).address.xrpGetAddress({
|
|
26
|
+
address_n: bip32ToAddressNList(derivationPathString),
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// Inject minimal signer so toolbox's address helpers work
|
|
30
|
+
const signer = {
|
|
31
|
+
getAddress: () => Promise.resolve(address),
|
|
32
|
+
signTransaction: () => {
|
|
33
|
+
throw new Error("signTransaction not supported via toolbox");
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const toolbox = await getRippleToolbox({ signer });
|
|
38
|
+
|
|
39
|
+
const transfer = async ({ recipient, assetValue, memo }: GenericTransferParams) => {
|
|
40
|
+
// Build XRPL Payment tx using toolbox helper
|
|
41
|
+
const tx = await toolbox.createTransaction({ assetValue, memo, recipient, sender: address });
|
|
42
|
+
|
|
43
|
+
// Convert toolbox Payment tx into KeepKey StdTx wrapper (KeepKey-specific format)
|
|
44
|
+
const stdTx = {
|
|
45
|
+
type: "auth/StdTx",
|
|
46
|
+
value: {
|
|
47
|
+
fee: { amount: [{ amount: "1000", denom: "drop" }], gas: "28000" },
|
|
48
|
+
memo: memo && memo.length > 0 ? memo : "",
|
|
49
|
+
msg: [
|
|
50
|
+
{
|
|
51
|
+
type: "ripple-sdk/MsgSend",
|
|
52
|
+
value: { amount: [{ amount: tx.Amount, denom: "drop" }], from_address: address, to_address: recipient },
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
signatures: null,
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const unsignedTx = {
|
|
60
|
+
addressNList: bip32ToAddressNList(derivationPathString),
|
|
61
|
+
flags: tx.Flags === 0 ? undefined : tx.Flags,
|
|
62
|
+
lastLedgerSequence: tx.LastLedgerSequence?.toString(),
|
|
63
|
+
payment: {
|
|
64
|
+
amount: tx.Amount,
|
|
65
|
+
destination: tx.Destination,
|
|
66
|
+
destinationTag: (tx.DestinationTag ?? "0").toString(),
|
|
67
|
+
},
|
|
68
|
+
sequence: (tx.Sequence ?? 0).toString(),
|
|
69
|
+
tx: stdTx,
|
|
70
|
+
} as any;
|
|
71
|
+
|
|
72
|
+
// Sign with KeepKey
|
|
73
|
+
const responseSign = JSON.parse(await (sdk as any).xrp.xrpSignTransaction(unsignedTx));
|
|
74
|
+
|
|
75
|
+
// keepkey-sdk may return either { tx_blob } or StdTx with Base64 serializedTx
|
|
76
|
+
const txBlob: string | undefined =
|
|
77
|
+
(responseSign as any).tx_blob ?? (responseSign as any).value?.signatures?.[0]?.serializedTx;
|
|
78
|
+
if (!txBlob) throw new Error("KeepKey XRP sign failed");
|
|
79
|
+
|
|
80
|
+
const buffer = Buffer.from(txBlob, "base64");
|
|
81
|
+
const txBlobHex = buffer.toString("hex");
|
|
82
|
+
|
|
83
|
+
// Broadcast signed tx via toolbox
|
|
84
|
+
return toolbox.broadcastTransaction(txBlobHex);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
return { ...toolbox, address, getAddress: () => address, transfer };
|
|
88
|
+
};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Modifications © 2025 Horizontal Systems.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { KeepKeySdk, TypesThorchainSignDocDeposit, TypesThorchainSignDocTransfer } from "@keepkey/keepkey-sdk";
|
|
6
|
+
import {
|
|
7
|
+
type AssetValue,
|
|
8
|
+
Chain,
|
|
9
|
+
DerivationPath,
|
|
10
|
+
type DerivationPathArray,
|
|
11
|
+
derivationPathToString,
|
|
12
|
+
type GenericTransferParams,
|
|
13
|
+
getRPCUrl,
|
|
14
|
+
THORConfig,
|
|
15
|
+
USwapError,
|
|
16
|
+
} from "@tcswap/helpers";
|
|
17
|
+
import type { ThorchainDepositParams } from "@tcswap/toolboxes/cosmos";
|
|
18
|
+
|
|
19
|
+
import { bip32ToAddressNList } from "../coins";
|
|
20
|
+
|
|
21
|
+
type SignTransactionParams = { assetValue: AssetValue; recipient?: string; sender: string; memo: string | undefined };
|
|
22
|
+
|
|
23
|
+
export async function thorchainWalletMethods({
|
|
24
|
+
sdk,
|
|
25
|
+
derivationPath,
|
|
26
|
+
}: {
|
|
27
|
+
sdk: KeepKeySdk;
|
|
28
|
+
derivationPath?: DerivationPathArray;
|
|
29
|
+
}): Promise<any> {
|
|
30
|
+
const importedAmino = await import("@cosmjs/amino");
|
|
31
|
+
const makeSignDoc = importedAmino.makeSignDoc ?? importedAmino.default?.makeSignDoc;
|
|
32
|
+
const { buildAminoMsg, getDefaultChainFee, createStargateClient, getCosmosToolbox } = await import(
|
|
33
|
+
"@tcswap/toolboxes/cosmos"
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const toolbox = await getCosmosToolbox(Chain.THORChain);
|
|
37
|
+
const derivationPathString = derivationPath ? derivationPathToString(derivationPath) : `${DerivationPath.THOR}/0`;
|
|
38
|
+
|
|
39
|
+
const { address: fromAddress } = (await sdk.address.thorchainGetAddress({
|
|
40
|
+
address_n: bip32ToAddressNList(derivationPathString),
|
|
41
|
+
})) as { address: string };
|
|
42
|
+
|
|
43
|
+
const signTransaction = async ({ assetValue, recipient, sender, memo }: SignTransactionParams) => {
|
|
44
|
+
const account = await toolbox.getAccount(sender);
|
|
45
|
+
if (!account) throw new USwapError("wallet_keepkey_account_not_found");
|
|
46
|
+
const { accountNumber, sequence = 0 } = account;
|
|
47
|
+
|
|
48
|
+
const isTransfer = recipient && recipient !== "";
|
|
49
|
+
const msg = buildAminoMsg({ assetValue, memo, recipient, sender });
|
|
50
|
+
|
|
51
|
+
const signDoc = makeSignDoc(
|
|
52
|
+
[msg],
|
|
53
|
+
getDefaultChainFee(Chain.THORChain),
|
|
54
|
+
THORConfig.chainId,
|
|
55
|
+
memo,
|
|
56
|
+
accountNumber?.toString(),
|
|
57
|
+
sequence,
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
const signedTx = isTransfer
|
|
61
|
+
? await sdk.thorchain.thorchainSignAminoTransfer({
|
|
62
|
+
signDoc: signDoc as TypesThorchainSignDocTransfer,
|
|
63
|
+
signerAddress: sender,
|
|
64
|
+
})
|
|
65
|
+
: await sdk.thorchain.thorchainSignAminoDeposit({
|
|
66
|
+
signDoc: signDoc as TypesThorchainSignDocDeposit,
|
|
67
|
+
signerAddress: sender,
|
|
68
|
+
});
|
|
69
|
+
const decodedBytes = atob(signedTx.serialized);
|
|
70
|
+
return new Uint8Array(decodedBytes.length).map((_, i) => decodedBytes.charCodeAt(i));
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const transfer = async ({ assetValue, recipient, memo }: GenericTransferParams) => {
|
|
74
|
+
const rpcUrl = await getRPCUrl(Chain.THORChain);
|
|
75
|
+
const stargateClient = await createStargateClient(rpcUrl);
|
|
76
|
+
const signedTransaction = await signTransaction({ assetValue, memo, recipient, sender: fromAddress });
|
|
77
|
+
const { transactionHash } = await stargateClient.broadcastTx(signedTransaction);
|
|
78
|
+
|
|
79
|
+
return transactionHash;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const deposit = async ({ assetValue, memo }: ThorchainDepositParams) => {
|
|
83
|
+
const rpcUrl = await getRPCUrl(Chain.THORChain);
|
|
84
|
+
const stargateClient = await createStargateClient(rpcUrl);
|
|
85
|
+
const signedTransaction = await signTransaction({ assetValue, memo, sender: fromAddress });
|
|
86
|
+
const { transactionHash } = await stargateClient.broadcastTx(signedTransaction);
|
|
87
|
+
|
|
88
|
+
return transactionHash;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// const signMessage = async (message: string) => {
|
|
92
|
+
// const stargateClient = await createStargateClient(RPCUrl.THORChain);
|
|
93
|
+
// // return signedTx;
|
|
94
|
+
// };
|
|
95
|
+
|
|
96
|
+
return { ...toolbox, address: fromAddress, deposit, transfer };
|
|
97
|
+
}
|