@swapkit/wallet-hardware 4.9.8 → 4.9.9
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/ledger/index.cjs +3 -3
- package/dist/ledger/index.cjs.map +4 -4
- package/dist/ledger/index.js +3 -3
- package/dist/ledger/index.js.map +4 -4
- package/dist/types/ledger/clients/thorchain/index.d.ts +3 -0
- package/dist/types/ledger/clients/thorchain/index.d.ts.map +1 -1
- package/dist/types/ledger/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/ledger/clients/thorchain/index.ts +37 -0
- package/src/ledger/index.ts +5 -105
package/src/ledger/index.ts
CHANGED
|
@@ -10,11 +10,9 @@ import {
|
|
|
10
10
|
getRPCUrl,
|
|
11
11
|
NetworkDerivationPath,
|
|
12
12
|
SwapKitError,
|
|
13
|
-
THORConfig,
|
|
14
13
|
type UTXOChain,
|
|
15
14
|
WalletOption,
|
|
16
15
|
} from "@swapkit/helpers";
|
|
17
|
-
import type { ThorchainDepositParams } from "@swapkit/toolboxes/cosmos";
|
|
18
16
|
import {
|
|
19
17
|
addInputsAndOutputs,
|
|
20
18
|
assertDerivationIndex,
|
|
@@ -80,10 +78,10 @@ export const ledgerWallet = createWallet({
|
|
|
80
78
|
[Chain.Polygon]: true,
|
|
81
79
|
[Chain.Ripple]: true,
|
|
82
80
|
[Chain.Sui]: true,
|
|
81
|
+
[Chain.THORChain]: true,
|
|
83
82
|
[Chain.Tron]: true,
|
|
84
83
|
[Chain.XLayer]: true,
|
|
85
84
|
// ZEC: still on bespoke signPCZT path
|
|
86
|
-
// THORChain: needs signAmino added to THORChainLedger (V3 plan PR)
|
|
87
85
|
},
|
|
88
86
|
name: "connectLedger",
|
|
89
87
|
supportedChains: [
|
|
@@ -126,32 +124,6 @@ function reduceMemo(memo?: string, affiliateAddress = "t") {
|
|
|
126
124
|
return removedAffiliate?.substring(0, removedAffiliate.lastIndexOf(":"));
|
|
127
125
|
}
|
|
128
126
|
|
|
129
|
-
function recursivelyOrderKeys(unordered: any) {
|
|
130
|
-
// If it's an array - recursively order any
|
|
131
|
-
// dictionary items within the array
|
|
132
|
-
if (Array.isArray(unordered)) {
|
|
133
|
-
unordered.forEach((item, index) => {
|
|
134
|
-
unordered[index] = recursivelyOrderKeys(item);
|
|
135
|
-
});
|
|
136
|
-
return unordered;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// If it's an object - let's order the keys
|
|
140
|
-
if (typeof unordered !== "object") return unordered;
|
|
141
|
-
const ordered: any = {};
|
|
142
|
-
const sortedKeys = Object.keys(unordered).sort();
|
|
143
|
-
|
|
144
|
-
for (const key of sortedKeys) {
|
|
145
|
-
ordered[key] = recursivelyOrderKeys(unordered[key]);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return ordered;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
function stringifyKeysInOrder(data: any) {
|
|
152
|
-
return JSON.stringify(recursivelyOrderKeys(data));
|
|
153
|
-
}
|
|
154
|
-
|
|
155
127
|
async function getWalletMethods({
|
|
156
128
|
chain,
|
|
157
129
|
derivationPath,
|
|
@@ -444,85 +416,13 @@ async function getWalletMethods({
|
|
|
444
416
|
}
|
|
445
417
|
|
|
446
418
|
case Chain.THORChain: {
|
|
447
|
-
const { SignMode } = await import("cosmjs-types/cosmos/tx/signing/v1beta1/signing.js");
|
|
448
|
-
const { TxRaw } = await import("cosmjs-types/cosmos/tx/v1beta1/tx.js");
|
|
449
|
-
const importedSigning = await import("@cosmjs/proto-signing");
|
|
450
|
-
const encodePubkey = importedSigning.encodePubkey ?? importedSigning.default?.encodePubkey;
|
|
451
|
-
const makeAuthInfoBytes = importedSigning.makeAuthInfoBytes ?? importedSigning.default?.makeAuthInfoBytes;
|
|
452
|
-
const {
|
|
453
|
-
createStargateClient,
|
|
454
|
-
buildEncodedTxBody,
|
|
455
|
-
getCosmosToolbox,
|
|
456
|
-
buildAminoMsg,
|
|
457
|
-
getDefaultChainFee,
|
|
458
|
-
fromBase64,
|
|
459
|
-
parseAminoMessageForDirectSigning,
|
|
460
|
-
} = await import("@swapkit/toolboxes/cosmos");
|
|
461
|
-
const toolbox = getCosmosToolbox(chain);
|
|
462
419
|
const signer = await getLedgerClient({ chain, derivationPath, transport });
|
|
420
|
+
const { getCosmosToolbox } = await import("@swapkit/toolboxes/cosmos");
|
|
421
|
+
const toolbox = getCosmosToolbox(chain, { signer });
|
|
463
422
|
const address = await getLedgerAddress({ chain, ledgerClient: signer });
|
|
423
|
+
const { sign: signMessage } = signer;
|
|
464
424
|
|
|
465
|
-
|
|
466
|
-
const { pubkey: value, signTransaction, sign: signMessage } = signer;
|
|
467
|
-
|
|
468
|
-
// ANCHOR (@Chillios): Same parts in methods + can extract StargateClient init to toolbox
|
|
469
|
-
const thorchainTransfer = async ({
|
|
470
|
-
memo = "",
|
|
471
|
-
assetValue,
|
|
472
|
-
...rest
|
|
473
|
-
}: GenericTransferParams | ThorchainDepositParams) => {
|
|
474
|
-
const account = await toolbox.getAccount(address);
|
|
475
|
-
if (!account) throw new SwapKitError("wallet_ledger_invalid_account");
|
|
476
|
-
if (!assetValue) throw new SwapKitError("wallet_ledger_invalid_asset");
|
|
477
|
-
if (!value) throw new SwapKitError("wallet_ledger_pubkey_not_found");
|
|
478
|
-
|
|
479
|
-
const { accountNumber, sequence: sequenceNumber } = account;
|
|
480
|
-
const sequence = (sequenceNumber || 0).toString();
|
|
481
|
-
|
|
482
|
-
const orderedMessages = recursivelyOrderKeys([buildAminoMsg({ assetValue, memo, sender: address, ...rest })]);
|
|
483
|
-
|
|
484
|
-
// get tx signing msg
|
|
485
|
-
const rawSendTx = stringifyKeysInOrder({
|
|
486
|
-
account_number: accountNumber?.toString(),
|
|
487
|
-
chain_id: THORConfig.chainId,
|
|
488
|
-
fee,
|
|
489
|
-
memo,
|
|
490
|
-
msgs: orderedMessages,
|
|
491
|
-
sequence,
|
|
492
|
-
});
|
|
493
|
-
|
|
494
|
-
const signatures = await signTransaction(rawSendTx, sequence);
|
|
495
|
-
if (!signatures) throw new SwapKitError("wallet_ledger_signing_error");
|
|
496
|
-
|
|
497
|
-
const pubkey = encodePubkey({ type: "tendermint/PubKeySecp256k1", value });
|
|
498
|
-
const msgs = orderedMessages.map(parseAminoMessageForDirectSigning);
|
|
499
|
-
const bodyBytes = await buildEncodedTxBody({ chain, memo, msgs });
|
|
500
|
-
|
|
501
|
-
const authInfoBytes = makeAuthInfoBytes(
|
|
502
|
-
[{ pubkey, sequence: Number(sequence) }],
|
|
503
|
-
fee.amount,
|
|
504
|
-
Number.parseInt(fee.gas, 10),
|
|
505
|
-
undefined,
|
|
506
|
-
undefined,
|
|
507
|
-
SignMode.SIGN_MODE_LEGACY_AMINO_JSON,
|
|
508
|
-
);
|
|
509
|
-
|
|
510
|
-
const signature = signatures?.[0]?.signature ? fromBase64(signatures[0].signature) : Uint8Array.from([]);
|
|
511
|
-
|
|
512
|
-
const txRaw = TxRaw.fromPartial({ authInfoBytes, bodyBytes, signatures: [signature] });
|
|
513
|
-
const txBytes = TxRaw.encode(txRaw).finish();
|
|
514
|
-
const rpcUrl = await getRPCUrl(Chain.THORChain);
|
|
515
|
-
|
|
516
|
-
const broadcaster = await createStargateClient(rpcUrl);
|
|
517
|
-
const { transactionHash } = await broadcaster.broadcastTx(txBytes);
|
|
518
|
-
|
|
519
|
-
return transactionHash;
|
|
520
|
-
};
|
|
521
|
-
|
|
522
|
-
const transfer = (params: GenericTransferParams) => thorchainTransfer(params);
|
|
523
|
-
const deposit = (params: ThorchainDepositParams) => thorchainTransfer(params);
|
|
524
|
-
|
|
525
|
-
return { ...toolbox, address, deposit, signMessage, transfer };
|
|
425
|
+
return { ...toolbox, address, signMessage };
|
|
526
426
|
}
|
|
527
427
|
|
|
528
428
|
case Chain.Near: {
|