@swapkit/wallet-hardware 5.0.1 → 6.0.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.
- package/dist/THIRD_PARTY_LICENSES.md +2344 -0
- package/dist/chunk-09e51wma.js +4 -0
- package/dist/chunk-09e51wma.js.map +167 -0
- package/dist/chunk-0arpsm5f.js +4 -0
- package/dist/chunk-0arpsm5f.js.map +10 -0
- package/dist/chunk-1amf58aq.js +4 -0
- package/dist/{chunk-xkh15edk.js.map → chunk-1amf58aq.js.map} +2 -2
- package/dist/chunk-3t17wpjg.js +17 -0
- package/dist/chunk-3t17wpjg.js.map +29 -0
- package/dist/chunk-5c7b7z2d.js +4 -0
- package/dist/{chunk-20wx60bn.js.map → chunk-5c7b7z2d.js.map} +2 -2
- package/dist/chunk-5p3ttw6y.js +4 -0
- package/dist/{chunk-1jpcb30j.js.map → chunk-5p3ttw6y.js.map} +1 -1
- package/dist/chunk-dptbnkzm.js +64 -0
- package/dist/chunk-dptbnkzm.js.map +260 -0
- package/dist/chunk-ds2m83jp.js +5 -0
- package/dist/chunk-ds2m83jp.js.map +11 -0
- package/dist/chunk-eenx3cv6.js +4 -0
- package/dist/chunk-eenx3cv6.js.map +33 -0
- package/dist/chunk-gr3eswf1.js +4 -0
- package/dist/chunk-gr3eswf1.js.map +73 -0
- package/dist/{chunk-7fsaymh4.js → chunk-hg71hp4m.js} +3 -3
- package/dist/{chunk-7fsaymh4.js.map → chunk-hg71hp4m.js.map} +1 -1
- package/dist/chunk-jewm2ag3.js +5 -0
- package/dist/{chunk-4tbtxdxa.js.map → chunk-jewm2ag3.js.map} +2 -2
- package/dist/chunk-jzrytcrf.js +4 -0
- package/dist/chunk-jzrytcrf.js.map +12 -0
- package/dist/chunk-k3thje6a.js +4 -0
- package/dist/chunk-k3thje6a.js.map +9 -0
- package/dist/chunk-nhva847d.js +5 -0
- package/dist/chunk-nhva847d.js.map +9 -0
- package/dist/chunk-tm47brht.js +4 -0
- package/dist/chunk-tm47brht.js.map +140 -0
- package/dist/chunk-xmvg4cds.js +4 -0
- package/dist/chunk-xmvg4cds.js.map +127 -0
- package/dist/chunk-xx7cwpzq.js +4 -0
- package/dist/chunk-xx7cwpzq.js.map +9 -0
- package/dist/chunk-yrxe491r.js +20 -0
- package/dist/chunk-yrxe491r.js.map +17 -0
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/keepkey/index.cjs +2 -2
- package/dist/keepkey/index.cjs.map +2 -2
- package/dist/keepkey/index.js +2 -2
- package/dist/keepkey/index.js.map +2 -2
- package/dist/ledger/index.cjs +90 -2
- package/dist/ledger/index.cjs.map +830 -24
- package/dist/ledger/index.js +2 -2
- package/dist/ledger/index.js.map +21 -19
- package/dist/trezor/index.cjs +2 -2
- package/dist/trezor/index.cjs.map +5 -5
- package/dist/trezor/index.js +2 -2
- package/dist/trezor/index.js.map +3 -3
- package/dist/types/ledger/clients/bitcoin.d.ts +36 -0
- package/dist/types/ledger/clients/bitcoin.d.ts.map +1 -0
- package/dist/types/ledger/clients/cosmos.d.ts +38 -10
- package/dist/types/ledger/clients/cosmos.d.ts.map +1 -1
- package/dist/types/ledger/clients/evm.d.ts +37 -46
- package/dist/types/ledger/clients/evm.d.ts.map +1 -1
- package/dist/types/ledger/clients/near.d.ts +5 -2
- package/dist/types/ledger/clients/near.d.ts.map +1 -1
- package/dist/types/ledger/clients/sui.d.ts +8 -12
- package/dist/types/ledger/clients/sui.d.ts.map +1 -1
- package/dist/types/ledger/clients/thorchain/index.d.ts +34 -8
- package/dist/types/ledger/clients/thorchain/index.d.ts.map +1 -1
- package/dist/types/ledger/clients/thorchain/protocol.d.ts +58 -0
- package/dist/types/ledger/clients/thorchain/protocol.d.ts.map +1 -0
- package/dist/types/ledger/clients/tron.d.ts +11 -8
- package/dist/types/ledger/clients/tron.d.ts.map +1 -1
- package/dist/types/ledger/clients/utxo-legacy-adapter.d.ts +3 -2
- package/dist/types/ledger/clients/utxo-legacy-adapter.d.ts.map +1 -1
- package/dist/types/ledger/clients/utxo-legacy-outputs.d.ts +18 -0
- package/dist/types/ledger/clients/utxo-legacy-outputs.d.ts.map +1 -0
- package/dist/types/ledger/clients/utxo.d.ts +10 -13
- package/dist/types/ledger/clients/utxo.d.ts.map +1 -1
- package/dist/types/ledger/clients/xrp.d.ts +4 -1
- package/dist/types/ledger/clients/xrp.d.ts.map +1 -1
- package/dist/types/ledger/clients/zcash.d.ts +53 -0
- package/dist/types/ledger/clients/zcash.d.ts.map +1 -0
- package/dist/types/ledger/helpers/dmk.d.ts +24 -0
- package/dist/types/ledger/helpers/dmk.d.ts.map +1 -0
- package/dist/types/ledger/helpers/executeDeviceAction.d.ts +34 -0
- package/dist/types/ledger/helpers/executeDeviceAction.d.ts.map +1 -0
- package/dist/types/ledger/helpers/getLedgerAddress.d.ts +1 -1
- package/dist/types/ledger/helpers/getLedgerAddress.d.ts.map +1 -1
- package/dist/types/ledger/helpers/getLedgerClient.d.ts +10 -3
- package/dist/types/ledger/helpers/getLedgerClient.d.ts.map +1 -1
- package/dist/types/ledger/helpers/index.d.ts +2 -1
- package/dist/types/ledger/helpers/index.d.ts.map +1 -1
- package/dist/types/ledger/helpers/ledgerJsDmkBridge.d.ts +26 -0
- package/dist/types/ledger/helpers/ledgerJsDmkBridge.d.ts.map +1 -0
- package/dist/types/ledger/helpers/ledgerJsDmkTransport.d.ts +13 -0
- package/dist/types/ledger/helpers/ledgerJsDmkTransport.d.ts.map +1 -0
- package/dist/types/ledger/helpers/lowS.d.ts +6 -0
- package/dist/types/ledger/helpers/lowS.d.ts.map +1 -0
- package/dist/types/ledger/helpers/rawTx.d.ts +2 -0
- package/dist/types/ledger/helpers/rawTx.d.ts.map +1 -0
- package/dist/types/ledger/index.d.ts +19 -7
- package/dist/types/ledger/index.d.ts.map +1 -1
- package/dist/types/ledger/types.d.ts +6 -10
- package/dist/types/ledger/types.d.ts.map +1 -1
- package/dist/types/trezor/index.d.ts +2 -2
- package/dist/types/trezor/index.d.ts.map +1 -1
- package/package.json +36 -36
- package/src/ledger/clients/bitcoin.ts +575 -0
- package/src/ledger/clients/cosmos.ts +180 -51
- package/src/ledger/clients/evm.ts +238 -195
- package/src/ledger/clients/near.ts +43 -13
- package/src/ledger/clients/sui.ts +55 -68
- package/src/ledger/clients/thorchain/index.ts +210 -86
- package/src/ledger/clients/thorchain/protocol.ts +166 -0
- package/src/ledger/clients/tron.ts +49 -37
- package/src/ledger/clients/utxo-legacy-adapter.ts +35 -32
- package/src/ledger/clients/utxo-legacy-outputs.ts +122 -0
- package/src/ledger/clients/utxo.ts +108 -206
- package/src/ledger/clients/xrp.ts +39 -23
- package/src/ledger/clients/zcash.ts +440 -0
- package/src/ledger/helpers/dmk.ts +231 -0
- package/src/ledger/helpers/executeDeviceAction.ts +201 -0
- package/src/ledger/helpers/getLedgerClient.ts +101 -72
- package/src/ledger/helpers/index.ts +6 -1
- package/src/ledger/helpers/ledgerJsDmkBridge.ts +109 -0
- package/src/ledger/helpers/ledgerJsDmkTransport.ts +88 -0
- package/src/ledger/helpers/lowS.ts +30 -0
- package/src/ledger/helpers/rawTx.ts +12 -0
- package/src/ledger/index.ts +564 -369
- package/src/ledger/types.ts +15 -10
- package/src/trezor/index.ts +115 -27
- package/dist/chunk-1jpcb30j.js +0 -5
- package/dist/chunk-20wx60bn.js +0 -4
- package/dist/chunk-4tbtxdxa.js +0 -5
- package/dist/chunk-7v7cgm69.js +0 -4
- package/dist/chunk-7v7cgm69.js.map +0 -10
- package/dist/chunk-83g13ck6.js +0 -5
- package/dist/chunk-83g13ck6.js.map +0 -10
- package/dist/chunk-h2r568rz.js +0 -4
- package/dist/chunk-h2r568rz.js.map +0 -10
- package/dist/chunk-xkh15edk.js +0 -4
- package/dist/types/ledger/clients/thorchain/common.d.ts +0 -28
- package/dist/types/ledger/clients/thorchain/common.d.ts.map +0 -1
- package/dist/types/ledger/clients/thorchain/helpers.d.ts +0 -7
- package/dist/types/ledger/clients/thorchain/helpers.d.ts.map +0 -1
- package/dist/types/ledger/clients/thorchain/lib.d.ts +0 -22
- package/dist/types/ledger/clients/thorchain/lib.d.ts.map +0 -1
- package/dist/types/ledger/clients/thorchain/utils.d.ts +0 -2
- package/dist/types/ledger/clients/thorchain/utils.d.ts.map +0 -1
- package/dist/types/ledger/clients/utxo-psbt.d.ts +0 -18
- package/dist/types/ledger/clients/utxo-psbt.d.ts.map +0 -1
- package/dist/types/ledger/cosmosTypes.d.ts +0 -40
- package/dist/types/ledger/cosmosTypes.d.ts.map +0 -1
- package/dist/types/ledger/helpers/getLedgerTransport.d.ts +0 -3
- package/dist/types/ledger/helpers/getLedgerTransport.d.ts.map +0 -1
- package/dist/types/ledger/helpers/ledgerNetworkInfo.d.ts +0 -14
- package/dist/types/ledger/helpers/ledgerNetworkInfo.d.ts.map +0 -1
- package/dist/types/ledger/interfaces/CosmosLedgerInterface.d.ts +0 -14
- package/dist/types/ledger/interfaces/CosmosLedgerInterface.d.ts.map +0 -1
- package/src/ledger/clients/thorchain/common.ts +0 -93
- package/src/ledger/clients/thorchain/helpers.ts +0 -120
- package/src/ledger/clients/thorchain/lib.ts +0 -258
- package/src/ledger/clients/thorchain/utils.ts +0 -69
- package/src/ledger/clients/utxo-psbt.ts +0 -204
- package/src/ledger/cosmosTypes.ts +0 -98
- package/src/ledger/helpers/getLedgerTransport.ts +0 -102
- package/src/ledger/helpers/ledgerNetworkInfo.ts +0 -127
- package/src/ledger/interfaces/CosmosLedgerInterface.ts +0 -67
package/src/ledger/types.ts
CHANGED
|
@@ -1,42 +1,47 @@
|
|
|
1
|
+
import type { BitcoinLedger } from "./clients/bitcoin";
|
|
1
2
|
import type { CosmosLedger } from "./clients/cosmos";
|
|
2
3
|
import type {
|
|
3
4
|
ArbitrumLedger,
|
|
5
|
+
ArcLedger,
|
|
4
6
|
AuroraLedger,
|
|
5
7
|
AvalancheLedger,
|
|
6
8
|
BaseLedger,
|
|
9
|
+
BerachainLedger,
|
|
7
10
|
BinanceSmartChainLedger,
|
|
8
11
|
EthereumLedger,
|
|
9
12
|
GnosisLedger,
|
|
13
|
+
MonadLedger,
|
|
10
14
|
OptimismLedger,
|
|
11
15
|
PolygonLedger,
|
|
16
|
+
XLayerLedger,
|
|
12
17
|
} from "./clients/evm";
|
|
13
18
|
import type { SuiLedger } from "./clients/sui";
|
|
14
19
|
import type { THORChainLedger } from "./clients/thorchain";
|
|
15
20
|
import type { TronLedger } from "./clients/tron";
|
|
16
|
-
import type { BitcoinCashLedger,
|
|
21
|
+
import type { BitcoinCashLedger, DashLedger, DogecoinLedger, LitecoinLedger } from "./clients/utxo";
|
|
22
|
+
import type { ZcashLedger } from "./clients/zcash";
|
|
17
23
|
|
|
18
24
|
export type UTXOLedgerClients =
|
|
19
25
|
| ReturnType<typeof BitcoinLedger>
|
|
20
26
|
| ReturnType<typeof BitcoinCashLedger>
|
|
27
|
+
| ReturnType<typeof DashLedger>
|
|
21
28
|
| ReturnType<typeof DogecoinLedger>
|
|
22
|
-
| ReturnType<typeof LitecoinLedger
|
|
29
|
+
| ReturnType<typeof LitecoinLedger>
|
|
30
|
+
| ReturnType<typeof ZcashLedger>;
|
|
23
31
|
export type CosmosLedgerClients = CosmosLedger | THORChainLedger;
|
|
24
32
|
export type EVMLedgerClients =
|
|
25
33
|
| ReturnType<typeof ArbitrumLedger>
|
|
34
|
+
| ReturnType<typeof ArcLedger>
|
|
26
35
|
| ReturnType<typeof AuroraLedger>
|
|
27
36
|
| ReturnType<typeof AvalancheLedger>
|
|
28
37
|
| ReturnType<typeof BaseLedger>
|
|
38
|
+
| ReturnType<typeof BerachainLedger>
|
|
29
39
|
| ReturnType<typeof BinanceSmartChainLedger>
|
|
30
40
|
| ReturnType<typeof GnosisLedger>
|
|
31
41
|
| ReturnType<typeof EthereumLedger>
|
|
42
|
+
| ReturnType<typeof MonadLedger>
|
|
32
43
|
| ReturnType<typeof OptimismLedger>
|
|
33
|
-
| ReturnType<typeof PolygonLedger
|
|
44
|
+
| ReturnType<typeof PolygonLedger>
|
|
45
|
+
| ReturnType<typeof XLayerLedger>;
|
|
34
46
|
export type TronLedgerClient = ReturnType<typeof TronLedger>;
|
|
35
47
|
export type SuiLedgerClient = ReturnType<typeof SuiLedger>;
|
|
36
|
-
|
|
37
|
-
export type GetAddressAndPubKeyResponse = {
|
|
38
|
-
bech32_address: string;
|
|
39
|
-
compressed_pk: any;
|
|
40
|
-
error_message: string;
|
|
41
|
-
return_code: number;
|
|
42
|
-
};
|
package/src/trezor/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { hex } from "@scure/base";
|
|
1
2
|
import { HDKey, type Versions } from "@scure/bip32";
|
|
2
3
|
import {
|
|
3
4
|
Chain,
|
|
@@ -24,12 +25,12 @@ import {
|
|
|
24
25
|
type UTXOType,
|
|
25
26
|
} from "@swapkit/toolboxes/utxo";
|
|
26
27
|
import type { BTCNetwork, PCZT, Transaction, ZcashPSBT, ZcashTransaction } from "@swapkit/utxo-signer";
|
|
27
|
-
import { BCHSigHash, NETWORKS, ZcashVersionGroupId } from "@swapkit/utxo-signer";
|
|
28
28
|
import { createWallet, getWalletSupportedChains, type HardwareExtendedPublicKeyInfo } from "@swapkit/wallet-core";
|
|
29
29
|
|
|
30
30
|
import { applyMissingSpendingMetadata } from "../helpers/psbt";
|
|
31
31
|
|
|
32
32
|
type TrezorBip32Derivation = [Uint8Array, { fingerprint: number; path: number[] }];
|
|
33
|
+
type TrezorTapBip32Derivation = [Uint8Array, { der: { fingerprint: number; path: number[] }; hashes: Uint8Array[] }];
|
|
33
34
|
type TrezorCoreMode = "auto" | "iframe" | "popup" | "suite-desktop" | "suite-web";
|
|
34
35
|
type TrezorTransport = "BridgeTransport" | "WebUsbTransport" | "NodeUsbTransport";
|
|
35
36
|
type ConnectTrezorOptions = { address?: string };
|
|
@@ -52,15 +53,12 @@ const DEFAULT_TREZOR_CORE_MODE: TrezorCoreMode = "auto";
|
|
|
52
53
|
const DEFAULT_TREZOR_MANIFEST = { appName: "SwapKit", appUrl: "https://swapkit.dev", email: "support@swapkit.dev" };
|
|
53
54
|
const DEFAULT_TREZOR_TRANSPORTS = ["WebUsbTransport" as const];
|
|
54
55
|
const TREZOR_KEEP_SESSION_PARAMS = { keepSession: true } as const;
|
|
56
|
+
const BITCOIN_CASH_SIGHASH_ALL = 0x41;
|
|
55
57
|
const trezorXpubCache = new Map<string, TrezorExtendedPublicKeyInfo>();
|
|
56
58
|
let trezorSessionDispose: Promise<void> | undefined;
|
|
57
|
-
const EXTENDED_KEY_VERSION_CANDIDATES =
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
NETWORKS.dash.bip32,
|
|
61
|
-
NETWORKS.dogecoin.bip32,
|
|
62
|
-
NETWORKS.litecoin.bip32,
|
|
63
|
-
];
|
|
59
|
+
const EXTENDED_KEY_VERSION_CANDIDATES = (
|
|
60
|
+
[Chain.Bitcoin, Chain.BitcoinCash, Chain.Dash, Chain.Dogecoin, Chain.Litecoin] as const satisfies readonly UTXOChain[]
|
|
61
|
+
).map((chain) => getNetworkForChain(chain).bip32);
|
|
64
62
|
|
|
65
63
|
async function disconnectTrezorSession() {
|
|
66
64
|
trezorXpubCache.clear();
|
|
@@ -208,8 +206,12 @@ function decodeOpReturnData(script: Uint8Array): string | null {
|
|
|
208
206
|
return Buffer.from(script.slice(2, 2 + dataLen)).toString("hex");
|
|
209
207
|
}
|
|
210
208
|
|
|
211
|
-
function getScriptType(derivationPath: DerivationPathArray) {
|
|
209
|
+
function getScriptType(chain: Chain, derivationPath: DerivationPathArray) {
|
|
212
210
|
switch (derivationPath[0]) {
|
|
211
|
+
case 86:
|
|
212
|
+
return chain === Chain.Bitcoin
|
|
213
|
+
? ({ input: "SPENDTAPROOT", output: "PAYTOTAPROOT", utxo: UTXOScriptType.P2TR } as const)
|
|
214
|
+
: null;
|
|
213
215
|
case 84:
|
|
214
216
|
return { input: "SPENDWITNESS", output: "PAYTOWITNESS", utxo: UTXOScriptType.P2WPKH } as const;
|
|
215
217
|
case 49:
|
|
@@ -245,6 +247,37 @@ function getFirstBip32Derivation(input: { bip32Derivation?: unknown }): TrezorBi
|
|
|
245
247
|
return isTrezorBip32Derivation(firstDerivation) ? firstDerivation : undefined;
|
|
246
248
|
}
|
|
247
249
|
|
|
250
|
+
function isTrezorTapBip32Derivation(value: unknown): value is TrezorTapBip32Derivation {
|
|
251
|
+
if (!(Array.isArray(value) && value[0] instanceof Uint8Array)) return false;
|
|
252
|
+
const origin = value[1] as { der?: { path?: unknown }; hashes?: unknown } | undefined;
|
|
253
|
+
|
|
254
|
+
return Array.isArray(origin?.hashes) && Array.isArray(origin?.der?.path);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// Key-path origins carry no leaf hashes; take the one for the internal key, or the only one when it is unset.
|
|
258
|
+
function selectTapKeyOrigin(input: { tapBip32Derivation?: unknown; tapInternalKey?: Uint8Array }, inputIndex: number) {
|
|
259
|
+
const origins = Array.isArray(input.tapBip32Derivation) ? input.tapBip32Derivation : [];
|
|
260
|
+
if (origins.length === 0) return undefined;
|
|
261
|
+
|
|
262
|
+
const { tapInternalKey } = input;
|
|
263
|
+
const keyPathOrigins = origins.filter(
|
|
264
|
+
(origin): origin is TrezorTapBip32Derivation =>
|
|
265
|
+
isTrezorTapBip32Derivation(origin) &&
|
|
266
|
+
origin[1].hashes.length === 0 &&
|
|
267
|
+
(!tapInternalKey || hex.encode(origin[0]) === hex.encode(tapInternalKey)),
|
|
268
|
+
);
|
|
269
|
+
const [xOnlyKey, origin] = keyPathOrigins[0] ?? [];
|
|
270
|
+
|
|
271
|
+
if (keyPathOrigins.length !== 1 || !(xOnlyKey && origin)) {
|
|
272
|
+
throw new SwapKitError({
|
|
273
|
+
errorKey: "wallet_trezor_failed_to_sign_transaction",
|
|
274
|
+
info: { chain: Chain.Bitcoin, error: `Input ${inputIndex} has no single taproot key-path origin to sign with` },
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
return { path: origin.der.path, xOnlyKey };
|
|
279
|
+
}
|
|
280
|
+
|
|
248
281
|
function getPrevoutAmount(input: {
|
|
249
282
|
index?: number;
|
|
250
283
|
nonWitnessUtxo?: { outputs?: Array<{ amount?: bigint | number }> };
|
|
@@ -263,7 +296,7 @@ export function normalizeTrezorSignature(signatureHex: string, chain: Chain) {
|
|
|
263
296
|
const derLength = signature[1] !== undefined ? signature[1] + 2 : undefined;
|
|
264
297
|
|
|
265
298
|
if (derLength !== undefined && signature.length === derLength) {
|
|
266
|
-
return new Uint8Array([...signature, chain === Chain.BitcoinCash ?
|
|
299
|
+
return new Uint8Array([...signature, chain === Chain.BitcoinCash ? BITCOIN_CASH_SIGHASH_ALL : 0x01]);
|
|
267
300
|
}
|
|
268
301
|
|
|
269
302
|
return new Uint8Array(signature);
|
|
@@ -328,7 +361,7 @@ async function buildPCZTOutputsForTrezor(pczt: PCZT, address_n: number[], myAddr
|
|
|
328
361
|
|
|
329
362
|
async function decodeOutputAddress(script: Uint8Array): Promise<string | undefined> {
|
|
330
363
|
try {
|
|
331
|
-
const { OutScript, Address } = await import("@swapkit/utxo-signer");
|
|
364
|
+
const { OutScript, Address, NETWORKS } = await import("@swapkit/utxo-signer");
|
|
332
365
|
const decoded = OutScript.decode(script);
|
|
333
366
|
if (decoded.type === "pkh" || decoded.type === "pk") {
|
|
334
367
|
return Address(NETWORKS.zcash).encode(decoded);
|
|
@@ -378,11 +411,23 @@ function buildZcashTxInputsForTrezor(
|
|
|
378
411
|
return inputs;
|
|
379
412
|
}
|
|
380
413
|
|
|
381
|
-
function buildZcashTxOutputsForTrezor(
|
|
414
|
+
function buildZcashTxOutputsForTrezor({
|
|
415
|
+
addressN,
|
|
416
|
+
chain,
|
|
417
|
+
myAddress,
|
|
418
|
+
network,
|
|
419
|
+
tx,
|
|
420
|
+
}: {
|
|
421
|
+
addressN: number[];
|
|
422
|
+
chain: Chain;
|
|
423
|
+
myAddress: string;
|
|
424
|
+
network: BTCNetwork;
|
|
425
|
+
tx: ZcashTransaction;
|
|
426
|
+
}) {
|
|
382
427
|
const outputs = [];
|
|
383
428
|
for (let i = 0; i < tx.outputsLength; i++) {
|
|
384
429
|
const output = tx.getOutput(i);
|
|
385
|
-
const outputAddress = tx.getOutputAddress(i,
|
|
430
|
+
const outputAddress = tx.getOutputAddress(i, network);
|
|
386
431
|
const script = output.script;
|
|
387
432
|
|
|
388
433
|
if (output.amount === 0n && script?.length > 0 && script[0] === 0x6a) {
|
|
@@ -402,7 +447,7 @@ function buildZcashTxOutputsForTrezor(tx: ZcashTransaction, address_n: number[],
|
|
|
402
447
|
}
|
|
403
448
|
|
|
404
449
|
const isChangeAddress = outputAddress === myAddress;
|
|
405
|
-
const outputParam = isChangeAddress || !outputAddress ? { address_n } : { address: outputAddress };
|
|
450
|
+
const outputParam = isChangeAddress || !outputAddress ? { address_n: addressN } : { address: outputAddress };
|
|
406
451
|
outputs.push({ ...outputParam, amount: output.amount?.toString() || "0", script_type: "PAYTOADDRESS" as const });
|
|
407
452
|
}
|
|
408
453
|
return outputs;
|
|
@@ -509,9 +554,11 @@ async function getTrezorWallet<T extends Chain>({
|
|
|
509
554
|
case Chain.BinanceSmartChain:
|
|
510
555
|
case Chain.Ethereum:
|
|
511
556
|
case Chain.Gnosis:
|
|
557
|
+
case Chain.Hyperevm:
|
|
512
558
|
case Chain.Monad:
|
|
513
559
|
case Chain.Optimism:
|
|
514
560
|
case Chain.Polygon:
|
|
561
|
+
case Chain.Robinhood:
|
|
515
562
|
case Chain.XLayer: {
|
|
516
563
|
const { getProvider, getEvmToolboxAsync } = await import("@swapkit/toolboxes/evm");
|
|
517
564
|
const { getEVMSigner } = await import("./evmSigner");
|
|
@@ -586,10 +633,17 @@ async function getTrezorWallet<T extends Chain>({
|
|
|
586
633
|
const signZcashTransactionWithSerializedTx = async (tx: ZcashTransaction) => {
|
|
587
634
|
const TrezorConnect = (await import("@trezor/connect-web")).default;
|
|
588
635
|
const { hex: hexEncode } = await import("@scure/base");
|
|
636
|
+
const { NETWORKS, ZcashVersionGroupId } = await import("@swapkit/utxo-signer");
|
|
589
637
|
const address_n = hardenDerivationPath(derivationPath);
|
|
590
638
|
|
|
591
639
|
const inputs = buildZcashTxInputsForTrezor(tx, [], address_n, hexEncode);
|
|
592
|
-
const outputs = buildZcashTxOutputsForTrezor(
|
|
640
|
+
const outputs = buildZcashTxOutputsForTrezor({
|
|
641
|
+
addressN: address_n,
|
|
642
|
+
chain,
|
|
643
|
+
myAddress: address,
|
|
644
|
+
network: NETWORKS.zcash,
|
|
645
|
+
tx,
|
|
646
|
+
});
|
|
593
647
|
|
|
594
648
|
const result = await TrezorConnect.signTransaction({
|
|
595
649
|
branchId: tx.consensusBranchId,
|
|
@@ -686,13 +740,14 @@ async function getTrezorWallet<T extends Chain>({
|
|
|
686
740
|
case Chain.Litecoin: {
|
|
687
741
|
const { toCashAddress, getUtxoToolbox, stripPrefix } = await import("@swapkit/toolboxes/utxo");
|
|
688
742
|
const utxoChain = chain as UTXOChain;
|
|
689
|
-
const scriptType = getScriptType(derivationPath);
|
|
743
|
+
const scriptType = getScriptType(chain, derivationPath);
|
|
690
744
|
|
|
691
745
|
if (!scriptType) {
|
|
692
746
|
throw new SwapKitError({ errorKey: "wallet_trezor_derivation_path_not_supported", info: { derivationPath } });
|
|
693
747
|
}
|
|
694
748
|
|
|
695
749
|
const resolvedScriptType = scriptType;
|
|
750
|
+
const isTaproot = scriptType.utxo === UTXOScriptType.P2TR;
|
|
696
751
|
const toolboxParams = { scriptType: scriptType.utxo };
|
|
697
752
|
const coin = chain.toLowerCase();
|
|
698
753
|
|
|
@@ -795,10 +850,37 @@ async function getTrezorWallet<T extends Chain>({
|
|
|
795
850
|
const signerPubkeys: Uint8Array[] = [];
|
|
796
851
|
const trezorInputs = [];
|
|
797
852
|
|
|
798
|
-
|
|
799
|
-
|
|
853
|
+
async function prepareInputForSigning(inputIndex: number, input: ReturnType<Transaction["getInput"]>) {
|
|
854
|
+
if (isTaproot) {
|
|
855
|
+
let keyOrigin = selectTapKeyOrigin(input, inputIndex);
|
|
856
|
+
|
|
857
|
+
if (!keyOrigin) {
|
|
858
|
+
const [publicKey, { path }] = await getFallbackDerivation();
|
|
859
|
+
keyOrigin = { path, xOnlyKey: publicKey.slice(1) };
|
|
860
|
+
tx.updateInput(inputIndex, {
|
|
861
|
+
tapBip32Derivation: [[keyOrigin.xOnlyKey, { der: { fingerprint: 0, path }, hashes: [] }]],
|
|
862
|
+
});
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
// A BIP86 key-path input's internal key is the x-only key its origin names.
|
|
866
|
+
if (!input.tapInternalKey) tx.updateInput(inputIndex, { tapInternalKey: keyOrigin.xOnlyKey });
|
|
867
|
+
return keyOrigin.path;
|
|
868
|
+
}
|
|
869
|
+
|
|
800
870
|
const existingDerivation = getFirstBip32Derivation(input);
|
|
801
871
|
const derivation = existingDerivation ?? (await getFallbackDerivation());
|
|
872
|
+
signerPubkeys[inputIndex] = derivation[0];
|
|
873
|
+
|
|
874
|
+
if (!existingDerivation) {
|
|
875
|
+
tx.updateInput(inputIndex, { bip32Derivation: [derivation] });
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
await applyMissingSpendingMetadata({ chain: utxoChain, indexes: [inputIndex], publicKey: derivation[0], tx });
|
|
879
|
+
return derivation[1].path;
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
for (let inputIndex = 0; inputIndex < tx.inputsLength; inputIndex++) {
|
|
883
|
+
const input = tx.getInput(inputIndex);
|
|
802
884
|
const amount = getPrevoutAmount(input);
|
|
803
885
|
|
|
804
886
|
if (!input.txid || input.index === undefined || !amount) {
|
|
@@ -808,16 +890,10 @@ async function getTrezorWallet<T extends Chain>({
|
|
|
808
890
|
});
|
|
809
891
|
}
|
|
810
892
|
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
if (!existingDerivation) {
|
|
814
|
-
tx.updateInput(inputIndex, { bip32Derivation: [derivation] });
|
|
815
|
-
}
|
|
816
|
-
|
|
817
|
-
await applyMissingSpendingMetadata({ chain: utxoChain, indexes: [inputIndex], publicKey: derivation[0], tx });
|
|
893
|
+
const inputAddressN = await prepareInputForSigning(inputIndex, input);
|
|
818
894
|
|
|
819
895
|
trezorInputs.push({
|
|
820
|
-
address_n:
|
|
896
|
+
address_n: inputAddressN,
|
|
821
897
|
amount,
|
|
822
898
|
prev_hash: hexEncode.encode(input.txid),
|
|
823
899
|
prev_index: input.index,
|
|
@@ -856,8 +932,16 @@ async function getTrezorWallet<T extends Chain>({
|
|
|
856
932
|
}
|
|
857
933
|
|
|
858
934
|
result.payload.signatures.forEach((signatureHex, inputIndex) => {
|
|
935
|
+
if (!signatureHex) return;
|
|
936
|
+
|
|
937
|
+
// Taproot key-path signatures are Schnorr, not DER, and finalize from tapKeySig.
|
|
938
|
+
if (isTaproot) {
|
|
939
|
+
tx.updateInput(inputIndex, { tapKeySig: hexEncode.decode(signatureHex) });
|
|
940
|
+
return;
|
|
941
|
+
}
|
|
942
|
+
|
|
859
943
|
const pubkey = signerPubkeys[inputIndex];
|
|
860
|
-
if (!
|
|
944
|
+
if (!pubkey) return;
|
|
861
945
|
|
|
862
946
|
tx.updateInput(inputIndex, { partialSig: [[pubkey, normalizeTrezorSignature(signatureHex, chain)]] });
|
|
863
947
|
});
|
|
@@ -1378,10 +1462,12 @@ export const trezorWallet = createWallet({
|
|
|
1378
1462
|
[Chain.Ethereum]: true,
|
|
1379
1463
|
[Chain.Gnosis]: true,
|
|
1380
1464
|
[Chain.Dogecoin]: true,
|
|
1465
|
+
[Chain.Hyperevm]: true,
|
|
1381
1466
|
[Chain.Litecoin]: true,
|
|
1382
1467
|
[Chain.Monad]: true,
|
|
1383
1468
|
[Chain.Optimism]: true,
|
|
1384
1469
|
[Chain.Polygon]: true,
|
|
1470
|
+
[Chain.Robinhood]: true,
|
|
1385
1471
|
[Chain.XLayer]: true,
|
|
1386
1472
|
[Chain.Zcash]: true,
|
|
1387
1473
|
},
|
|
@@ -1401,10 +1487,12 @@ export const trezorWallet = createWallet({
|
|
|
1401
1487
|
Chain.Dogecoin,
|
|
1402
1488
|
Chain.Ethereum,
|
|
1403
1489
|
Chain.Gnosis,
|
|
1490
|
+
Chain.Hyperevm,
|
|
1404
1491
|
Chain.Litecoin,
|
|
1405
1492
|
Chain.Monad,
|
|
1406
1493
|
Chain.Optimism,
|
|
1407
1494
|
Chain.Polygon,
|
|
1495
|
+
Chain.Robinhood,
|
|
1408
1496
|
Chain.XLayer,
|
|
1409
1497
|
Chain.Zcash,
|
|
1410
1498
|
],
|
package/dist/chunk-1jpcb30j.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
var d=((a)=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(a,{get:(b,c)=>(typeof require<"u"?require:b)[c]}):a)(function(a){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+a+'" is not supported')});
|
|
2
|
-
export{d as e};
|
|
3
|
-
|
|
4
|
-
//# debugId=C12E7419EA3375B964756E2164756E21
|
|
5
|
-
//# sourceMappingURL=chunk-1jpcb30j.js.map
|
package/dist/chunk-20wx60bn.js
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import{e as Q}from"./chunk-1jpcb30j.js";import{ChainToChainId as b,derivationPathToString as $,SwapKitError as J,WalletOption as K}from"@swapkit/helpers";async function G({chain:_,derivationPath:C,provider:I}){let{AbstractSigner:f}=await import("ethers");class N extends f{address;chain;derivationPath;provider;constructor({chain:j,derivationPath:q,provider:B}){super(B);this.address="",this.chain=j,this.derivationPath=q,this.provider=B}getAddress=async()=>{if(!this.address){let q=await(await import("@trezor/connect-web")).default.ethereumGetAddress({path:$(this.derivationPath),showOnTrezor:!0});if(!q.success)throw new J({errorKey:"wallet_trezor_failed_to_get_address",info:{...q,chain:this.chain,derivationPath:this.derivationPath}});this.address=q.payload.address}return this.address};signMessage=async(j)=>{let B=await(await import("@trezor/connect-web")).default.ethereumSignMessage({message:j,path:$(this.derivationPath)});if(!B.success)throw new J({errorKey:"wallet_trezor_failed_to_sign_transaction",info:{...B,chain:this.chain,derivationPath:this.derivationPath,message:j}});return B.payload.signature};signTypedData=async(j,q,B,O)=>{let W=(await import("@trezor/connect-web")).default,{buildEIP712DomainType:U}=await import("@swapkit/toolboxes/evm"),{TypedDataEncoder:Z}=await import("ethers"),{EIP712Domain:X,...V}=q,A=O??Z.from(V).primaryType,M=U(j),D={domain:j,message:B,primaryType:A,types:{EIP712Domain:M,...V}},R=await W.ethereumSignTypedData({data:D,metamask_v4_compat:!0,path:$(this.derivationPath)});if(!R.success)throw new J({errorKey:"wallet_trezor_failed_to_sign_transaction",info:{chain:this.chain,error:R.payload.error}});return R.payload.signature.startsWith("0x")?R.payload.signature:`0x${R.payload.signature}`};signTransaction=async({to:j,gasLimit:q,value:B,data:O,nonce:W,maxFeePerGas:U,maxPriorityFeePerGas:Z,gasPrice:X})=>{if(!j)throw new J({errorKey:"wallet_missing_params",info:{to:j}});if(!q)throw new J({errorKey:"wallet_missing_params",info:{gasLimit:q}});let V=U!=null||Z!=null;if(V&&!U)throw new J({errorKey:"wallet_missing_params",info:{maxFeePerGas:U}});if(!(V||X))throw new J({errorKey:"wallet_missing_params",info:{gasPrice:X}});let A=(await import("@trezor/connect-web")).default,{toHexString:M}=await import("@swapkit/toolboxes/evm"),D=V?{maxFeePerGas:M(BigInt(U?.toString()||0)),maxPriorityFeePerGas:M(BigInt(Z?.toString()||0))}:X&&{gasPrice:M(BigInt(X?.toString()||0))}||{gasPrice:"0x0"},R=M(BigInt(W||await this.provider.getTransactionCount(await this.getAddress(),"pending"))),H={chainId:Number.parseInt(b[this.chain],10),data:O?.toString()||"0x",gasLimit:M(BigInt(q?.toString()||0)),nonce:R,to:j.toString(),value:M(BigInt(B?.toString()||0)),...D},{success:L,payload:Y}=await A.ethereumSignTransaction({path:$(this.derivationPath),transaction:H});if(!L)throw new J({errorKey:"wallet_trezor_failed_to_sign_transaction",info:{...Y,chain:this.chain,derivationPath:this.derivationPath}});let k=Y.serializedTx?Y.serializedTx.startsWith("0x")?Y.serializedTx:`0x${Y.serializedTx}`:void 0;if(!k)throw new J({errorKey:"wallet_trezor_failed_to_sign_transaction",info:{chain:this.chain,derivationPath:this.derivationPath}});return k};connect=(j)=>{if(!j)throw new J({errorKey:"wallet_provider_not_found",info:{chain:this.chain,derivationPath:this.derivationPath,wallet:K.TREZOR}});return new N({chain:this.chain,derivationPath:this.derivationPath,provider:j})}}return new N({chain:_,derivationPath:C,provider:I})}export{G as getEVMSigner};
|
|
2
|
-
|
|
3
|
-
//# debugId=52F319863E87D75D64756E2164756E21
|
|
4
|
-
//# sourceMappingURL=chunk-20wx60bn.js.map
|
package/dist/chunk-4tbtxdxa.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import{e as s}from"./chunk-1jpcb30j.js";async function d({chain:t,indexes:a,publicKey:i,tx:n}){let{getMissingSpendingMetadata:e,getNetworkForChain:o}=await import("@swapkit/toolboxes/utxo");for(let{index:r,...p}of e({chain:t,indexes:a,network:o(t),publicKey:i,tx:n}))n.updateInput(r,p)}
|
|
2
|
-
export{d};
|
|
3
|
-
|
|
4
|
-
//# debugId=400A1FA50F54FC1E64756E2164756E21
|
|
5
|
-
//# sourceMappingURL=chunk-4tbtxdxa.js.map
|
package/dist/chunk-7v7cgm69.js
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import{c as v}from"./chunk-83g13ck6.js";import{d as C}from"./chunk-4tbtxdxa.js";import{e as k}from"./chunk-1jpcb30j.js";import{base64 as P}from"@scure/base";import{HDKey as g}from"@scure/bip32";import{Chain as S,derivationPathToString as x,getWalletFormatFor as l,SwapKitError as F}from"@swapkit/helpers";var u={bitcoin:S.Bitcoin,litecoin:S.Litecoin};function s(G){switch(G){case"bech32":return"wpkh(@0/**)";case"p2sh":return"sh(wpkh(@0/**))";case"legacy":return"pkh(@0/**)";default:return"wpkh(@0/**)"}}function c(G){return typeof G==="string"?G:x(G)}function T(G){return G.replace(/^m\//,"").replace(/^\/+/,"")}function h(G){return G.replace(/^m\//,"").split("/").filter(Boolean).map((J)=>{let V=J.endsWith("'"),Z=Number.parseInt(V?J.slice(0,-1):J,10);return V?(Z|2147483648)>>>0:Z})}function o(G){for(let J=0;J<G.inputsLength;J++){let V=G.getInput(J);if(V.nonWitnessUtxo&&V.witnessUtxo)G.updateInput(J,{witnessUtxo:void 0})}}function d(G,J){let V=G.getInput(J);return Boolean(V.bip32Derivation?.length)}var L=({chain:G})=>{return(J,V)=>{let Z,w;async function j(){if(!Z){let q=V??await v(),{AppClient:Q}=await import("ledger-bitcoin");Z=new Q(q)}return Z}async function A(){if(!w)w=await(await j()).getMasterFingerprint();return w}let z=T(J?c(J):"84'/0'/0'/0/0"),U=z.split("/").filter(Boolean),E=U.slice(0,3).join("/"),O=U.slice(3),B=Number(O[0]??0),D=Number(O[1]??0),H=l(`m/${z}`),I=s(H),M,K;async function W(){let q=await j(),Q=await A();if(!M)M=await q.getExtendedPubkey(`m/${E}`);let{DefaultWalletPolicy:Y}=await import("ledger-bitcoin"),N=new Y(I,`[${Q}/${E}]${M}`);return{app:q,fpr:Q,policy:N,xpub:M}}async function _(){if(!K){let{xpub:q}=await W(),Y=g.fromExtendedKey(q).derive(`m/${B}/${D}`);if(!Y.publicKey)throw new F("wallet_ledger_get_address_error",{message:`Cannot derive leaf pubkey for ${G}`});K=Y.publicKey}return K}return{connect:async()=>{await j()},getAddress:async()=>{let{app:q,policy:Q}=await W(),Y=await q.getWalletAddress(Q,null,B,D,!1);if(!Y)throw new F("wallet_ledger_get_address_error",{message:`Cannot get ${G} address from ledger derivation path: ${z}`});return Y},getExtendedPublicKey:async(q=`m/${E}`)=>{return(await j()).getExtendedPubkey(`m/${T(q)}`)},getPublicKey:_,signTransaction:async(q)=>{let{app:Q,policy:Y,fpr:N}=await W(),f=Number.parseInt(N,16)>>>0,y=h(z),X=Array.from({length:q.inputsLength},($,R)=>R).filter(($)=>!d(q,$));if(X.length>0){let $=await _();for(let R of X)q.updateInput(R,{bip32Derivation:[[$,{fingerprint:f,path:y}]]})}if(H==="legacy")o(q);if(H==="p2sh")await C({chain:u[G],publicKey:await _(),tx:q});let m=P.encode(q.toPSBT(0)),b=await Q.signPsbt(m,Y,null);for(let[$,R]of b)q.updateInput($,{partialSig:[[new Uint8Array(R.pubkey),new Uint8Array(R.signature)]]});return q}}}},e=L({chain:"bitcoin"}),t=L({chain:"litecoin"});export{t as LitecoinPsbtLedger,e as BitcoinPsbtLedger};
|
|
2
|
-
|
|
3
|
-
//# debugId=196AC9353D4ED98464756E2164756E21
|
|
4
|
-
//# sourceMappingURL=chunk-7v7cgm69.js.map
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/ledger/clients/utxo-psbt.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"import type Transport from \"@ledgerhq/hw-transport\";\nimport { base64 } from \"@scure/base\";\nimport { HDKey } from \"@scure/bip32\";\nimport {\n Chain,\n type DerivationPathArray,\n derivationPathToString,\n getWalletFormatFor,\n SwapKitError,\n type UTXOChain,\n} from \"@swapkit/helpers\";\nimport type { Transaction } from \"@swapkit/utxo-signer\";\n\nimport { applyMissingSpendingMetadata } from \"../../helpers/psbt\";\nimport { getLedgerTransport } from \"../helpers/getLedgerTransport\";\n\ntype SupportedCoin = \"bitcoin\" | \"litecoin\";\n\nconst UTXO_CHAIN_FOR_COIN: Record<SupportedCoin, UTXOChain> = { bitcoin: Chain.Bitcoin, litecoin: Chain.Litecoin };\n\ntype DefaultDescriptorTemplate = \"wpkh(@0/**)\" | \"tr(@0/**)\" | \"sh(wpkh(@0/**))\" | \"pkh(@0/**)\";\n\nfunction templateForFormat(format: ReturnType<typeof getWalletFormatFor>): DefaultDescriptorTemplate {\n switch (format) {\n case \"bech32\":\n return \"wpkh(@0/**)\";\n case \"p2sh\":\n return \"sh(wpkh(@0/**))\";\n case \"legacy\":\n return \"pkh(@0/**)\";\n default:\n return \"wpkh(@0/**)\";\n }\n}\n\nfunction pathToString(path: DerivationPathArray | string): string {\n return typeof path === \"string\" ? path : derivationPathToString(path);\n}\n\nfunction normalizeLedgerPath(path: string): string {\n return path.replace(/^m\\//, \"\").replace(/^\\/+/, \"\");\n}\n\nfunction pathToNumberArray(path: string): number[] {\n return path\n .replace(/^m\\//, \"\")\n .split(\"/\")\n .filter(Boolean)\n .map((p) => {\n const hardened = p.endsWith(\"'\");\n const num = Number.parseInt(hardened ? p.slice(0, -1) : p, 10);\n return hardened ? (num | 0x80000000) >>> 0 : num;\n });\n}\n\nfunction dropWitnessUtxoFromLegacyInputs(tx: Transaction) {\n for (let inputIndex = 0; inputIndex < tx.inputsLength; inputIndex++) {\n const input = tx.getInput(inputIndex);\n\n if (input.nonWitnessUtxo && input.witnessUtxo) {\n tx.updateInput(inputIndex, { witnessUtxo: undefined });\n }\n }\n}\n\nfunction hasBip32Derivation(tx: Transaction, inputIndex: number) {\n const input = tx.getInput(inputIndex) as { bip32Derivation?: Array<unknown> };\n\n return Boolean(input.bip32Derivation?.length);\n}\n\nconst BaseLedgerPsbtUTXO = ({ chain }: { chain: SupportedCoin }) => {\n return (derivationPathArray?: DerivationPathArray | string, injectedTransport?: Transport) => {\n // Per-call state — each BitcoinPsbtLedger/LitecoinPsbtLedger invocation has its own\n // AppClient and master fingerprint so different consumers (e.g. concurrent MCP\n // sessions on different devices) cannot inherit each other's ledger bindings or xpub.\n let appClient: import(\"ledger-bitcoin\").AppClient | undefined;\n let masterFingerprint: string | undefined;\n\n async function getAppClient() {\n if (!appClient) {\n const transport = injectedTransport ?? (await getLedgerTransport());\n const { AppClient } = await import(\"ledger-bitcoin\");\n appClient = new AppClient(transport);\n }\n return appClient;\n }\n\n async function getFingerprint() {\n if (!masterFingerprint) {\n const app = await getAppClient();\n masterFingerprint = await app.getMasterFingerprint();\n }\n return masterFingerprint;\n }\n\n // Single-address account: change == index == 0 by default.\n const derivationPath = normalizeLedgerPath(\n derivationPathArray ? pathToString(derivationPathArray) : \"84'/0'/0'/0/0\",\n );\n const pathSegments = derivationPath.split(\"/\").filter(Boolean);\n const accountPath = pathSegments.slice(0, 3).join(\"/\");\n const leafSegments = pathSegments.slice(3);\n const change = Number(leafSegments[0] ?? 0);\n const addressIndex = Number(leafSegments[1] ?? 0);\n // getWalletFormatFor expects an m/-prefixed path (it reads the purpose\n // from the second segment); derivationPath is normalized without it.\n const format = getWalletFormatFor(`m/${derivationPath}`);\n const template = templateForFormat(format);\n\n let cachedAccountXpub: string | undefined;\n let cachedLeafPubkey: Uint8Array | undefined;\n\n async function buildPolicy() {\n const app = await getAppClient();\n const fpr = await getFingerprint();\n if (!cachedAccountXpub) {\n cachedAccountXpub = await app.getExtendedPubkey(`m/${accountPath}`);\n }\n const { DefaultWalletPolicy } = await import(\"ledger-bitcoin\");\n const policy = new DefaultWalletPolicy(template, `[${fpr}/${accountPath}]${cachedAccountXpub}`);\n return { app, fpr, policy, xpub: cachedAccountXpub };\n }\n\n async function getLeafPubkey() {\n if (!cachedLeafPubkey) {\n const { xpub } = await buildPolicy();\n const accountKey = HDKey.fromExtendedKey(xpub);\n const leaf = accountKey.derive(`m/${change}/${addressIndex}`);\n if (!leaf.publicKey) {\n throw new SwapKitError(\"wallet_ledger_get_address_error\", {\n message: `Cannot derive leaf pubkey for ${chain}`,\n });\n }\n cachedLeafPubkey = leaf.publicKey;\n }\n return cachedLeafPubkey;\n }\n\n return {\n connect: async () => {\n await getAppClient();\n },\n getAddress: async () => {\n const { app, policy } = await buildPolicy();\n const address = await app.getWalletAddress(policy, null, change, addressIndex, false);\n if (!address) {\n throw new SwapKitError(\"wallet_ledger_get_address_error\", {\n message: `Cannot get ${chain} address from ledger derivation path: ${derivationPath}`,\n });\n }\n return address;\n },\n getExtendedPublicKey: async (path = `m/${accountPath}`) => {\n const app = await getAppClient();\n return app.getExtendedPubkey(`m/${normalizeLedgerPath(path)}`);\n },\n getPublicKey: getLeafPubkey,\n signTransaction: async (tx: Transaction): Promise<Transaction> => {\n const { app, policy, fpr } = await buildPolicy();\n const fingerprintBE = Number.parseInt(fpr, 16) >>> 0;\n const pathNumbers = pathToNumberArray(derivationPath);\n const missingDerivationIndexes = Array.from({ length: tx.inputsLength }, (_, inputIndex) => inputIndex).filter(\n (inputIndex) => !hasBip32Derivation(tx, inputIndex),\n );\n\n if (missingDerivationIndexes.length > 0) {\n const leafPubkey = await getLeafPubkey();\n\n // Fallback for PSBTs that do not include per-input HD key origins.\n for (const inputIndex of missingDerivationIndexes) {\n tx.updateInput(inputIndex, {\n bip32Derivation: [[leafPubkey, { fingerprint: fingerprintBE, path: pathNumbers }]],\n });\n }\n }\n\n if (format === \"legacy\") {\n dropWitnessUtxoFromLegacyInputs(tx);\n }\n\n if (format === \"p2sh\") {\n await applyMissingSpendingMetadata({\n chain: UTXO_CHAIN_FOR_COIN[chain],\n publicKey: await getLeafPubkey(),\n tx,\n });\n }\n\n const psbtB64 = base64.encode(tx.toPSBT(0));\n const sigs = await app.signPsbt(psbtB64, policy, null);\n\n for (const [idx, partial] of sigs) {\n tx.updateInput(idx, { partialSig: [[new Uint8Array(partial.pubkey), new Uint8Array(partial.signature)]] });\n }\n\n return tx;\n },\n };\n };\n};\n\nexport const BitcoinPsbtLedger = BaseLedgerPsbtUTXO({ chain: \"bitcoin\" });\nexport const LitecoinPsbtLedger = BaseLedgerPsbtUTXO({ chain: \"litecoin\" });\n"
|
|
6
|
-
],
|
|
7
|
-
"mappings": "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",
|
|
8
|
-
"debugId": "196AC9353D4ED98464756E2164756E21",
|
|
9
|
-
"names": []
|
|
10
|
-
}
|
package/dist/chunk-83g13ck6.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import{e as M}from"./chunk-1jpcb30j.js";import{SwapKitError as F}from"@swapkit/helpers";var Q=()=>navigator?.usb,$=async()=>{let j=Q();if(typeof j?.getDevices!=="function")return{};let{ledgerUSBVendorId:z}=await import("@ledgerhq/devices"),G=(await j?.getDevices()).filter((P)=>P.vendorId===z);if(G.length>0)return G[0];return j?.requestDevice({filters:[{vendorId:z}]})},B=async()=>{let j=await $();if(!j)throw new F("wallet_ledger_device_not_found");if(j.opened||await j.open(),j.configuration===null)await j.selectConfiguration(1);try{await j.reset()}catch{}let z=j.configuration??j.configurations?.[0],y=z?.interfaces.find(({alternates:m})=>m.some(({interfaceClass:J})=>J===255))||z?.interfaces.find(({alternates:m})=>m.some(({interfaceClass:J})=>J===3));if(!y)throw await j.close(),new F("wallet_ledger_connection_error");let G=y.alternates?.find(({interfaceClass:m})=>m===3)?.interfaceClass,P=y.alternates?.find(({interfaceClass:m})=>m===255)?.interfaceClass;if(G&&!P){let m=(await import("@ledgerhq/hw-transport-webhid")).default;if(!await m.isSupported())throw await j.close(),new F("wallet_ledger_webhid_not_supported");return await m.create()}try{await j.claimInterface(y.interfaceNumber)}catch(m){throw await j.close(),new F("wallet_ledger_connection_claimed",m)}let X=(await import("@ledgerhq/hw-transport-webusb")).default;if(!await X.isSupported())throw new F("wallet_ledger_webusb_not_supported");let{DisconnectedDevice:_}=await import("@ledgerhq/errors"),Y=new X(j,y.interfaceNumber),Z=(m)=>{if(j===m.device)Q()?.removeEventListener("disconnect",Z),Y._emitDisconnect(new _)};return Q()?.addEventListener("disconnect",Z),Y};
|
|
2
|
-
export{B as c};
|
|
3
|
-
|
|
4
|
-
//# debugId=019B41E14551343964756E2164756E21
|
|
5
|
-
//# sourceMappingURL=chunk-83g13ck6.js.map
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/ledger/helpers/getLedgerTransport.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"import type Transport from \"@ledgerhq/hw-transport\";\nimport { SwapKitError } from \"@swapkit/helpers\";\n\nconst getNavigatorUsb = () =>\n navigator?.usb as unknown as {\n getDevices: () => Promise<any[]>;\n requestDevice: (requestObject: any) => Promise<any>;\n removeEventListener: (event: string, callback: (e: any) => void) => void;\n addEventListener: (event: string, callback: (e: any) => void) => void;\n };\n\nconst getLedgerDevices = async (): Promise<USBDevice> => {\n const navigatorUsb = getNavigatorUsb();\n\n if (typeof navigatorUsb?.getDevices !== \"function\") return {} as USBDevice;\n const { ledgerUSBVendorId } = await import(\"@ledgerhq/devices\");\n\n const devices = await navigatorUsb?.getDevices();\n const existingDevices = devices.filter((d) => d.vendorId === ledgerUSBVendorId);\n if (existingDevices.length > 0) return existingDevices[0];\n\n return navigatorUsb?.requestDevice({ filters: [{ vendorId: ledgerUSBVendorId }] });\n};\n\nexport const getLedgerTransport = async (): Promise<Transport> => {\n const device = await getLedgerDevices();\n\n if (!device) {\n throw new SwapKitError(\"wallet_ledger_device_not_found\");\n }\n\n device.opened || (await device.open());\n if (device.configuration === null) await device.selectConfiguration(1);\n\n try {\n await device.reset();\n } catch {\n // reset fails on devices that are already open\n }\n\n const configuration = device.configuration ?? device.configurations?.[0];\n\n const iface =\n configuration?.interfaces.find(({ alternates }: { alternates: { interfaceClass: number }[] }) =>\n alternates.some(({ interfaceClass }) => interfaceClass === 0xff),\n ) ||\n configuration?.interfaces.find(({ alternates }: { alternates: { interfaceClass: number }[] }) =>\n alternates.some(({ interfaceClass }) => interfaceClass === 0x03),\n );\n\n if (!iface) {\n await device.close();\n throw new SwapKitError(\"wallet_ledger_connection_error\");\n }\n\n const klass0x03 = (iface.alternates as any[])?.find(\n ({ interfaceClass }: { interfaceClass: number }) => interfaceClass === 0x03,\n )?.interfaceClass as number;\n\n const klass0xff = (iface.alternates as any[])?.find(\n ({ interfaceClass }: { interfaceClass: number }) => interfaceClass === 0xff,\n )?.interfaceClass as number;\n\n if (klass0x03 && !klass0xff) {\n // -------- HID class (NEAR, ETH, SOL, etc.) -> WebHID transport --------\n const TransportWebHID = (await import(\"@ledgerhq/hw-transport-webhid\")).default;\n const supported = await TransportWebHID.isSupported();\n if (!supported) {\n await device.close();\n throw new SwapKitError(\"wallet_ledger_webhid_not_supported\");\n }\n const transport = await TransportWebHID.create();\n return transport;\n }\n\n try {\n await device.claimInterface(iface.interfaceNumber);\n } catch (error: unknown) {\n await device.close();\n\n throw new SwapKitError(\"wallet_ledger_connection_claimed\", error);\n }\n\n const Transport = (await import(\"@ledgerhq/hw-transport-webusb\")).default;\n const isSupported = await Transport.isSupported();\n if (!isSupported) throw new SwapKitError(\"wallet_ledger_webusb_not_supported\");\n\n const { DisconnectedDevice } = await import(\"@ledgerhq/errors\");\n\n const transport = new Transport(device, iface.interfaceNumber);\n\n const onDisconnect = (e: any) => {\n if (device === e.device) {\n getNavigatorUsb()?.removeEventListener(\"disconnect\", onDisconnect);\n\n transport._emitDisconnect(new DisconnectedDevice());\n }\n };\n getNavigatorUsb()?.addEventListener(\"disconnect\", onDisconnect);\n\n return transport as Transport;\n};\n"
|
|
6
|
-
],
|
|
7
|
-
"mappings": "wCACA,uBAAS,yBAET,IAAM,EAAkB,IACtB,WAAW,IAOP,EAAmB,SAAgC,CACvD,IAAM,EAAe,EAAgB,EAErC,GAAI,OAAO,GAAc,aAAe,WAAY,MAAO,CAAC,EAC5D,IAAQ,qBAAsB,KAAa,6BAGrC,GADU,MAAM,GAAc,WAAW,GACf,OAAO,CAAC,IAAM,EAAE,WAAa,CAAiB,EAC9E,GAAI,EAAgB,OAAS,EAAG,OAAO,EAAgB,GAEvD,OAAO,GAAc,cAAc,CAAE,QAAS,CAAC,CAAE,SAAU,CAAkB,CAAC,CAAE,CAAC,GAGtE,EAAqB,SAAgC,CAChE,IAAM,EAAS,MAAM,EAAiB,EAEtC,GAAI,CAAC,EACH,MAAM,IAAI,EAAa,gCAAgC,EAIzD,GADA,EAAO,QAAW,MAAM,EAAO,KAAK,EAChC,EAAO,gBAAkB,KAAM,MAAM,EAAO,oBAAoB,CAAC,EAErE,GAAI,CACF,MAAM,EAAO,MAAM,EACnB,KAAM,EAIR,IAAM,EAAgB,EAAO,eAAiB,EAAO,iBAAiB,GAEhE,EACJ,GAAe,WAAW,KAAK,EAAG,gBAChC,EAAW,KAAK,EAAG,oBAAqB,IAAmB,GAAI,CACjE,GACA,GAAe,WAAW,KAAK,EAAG,gBAChC,EAAW,KAAK,EAAG,oBAAqB,IAAmB,CAAI,CACjE,EAEF,GAAI,CAAC,EAEH,MADA,MAAM,EAAO,MAAM,EACb,IAAI,EAAa,gCAAgC,EAGzD,IAAM,EAAa,EAAM,YAAsB,KAC7C,EAAG,oBAAiD,IAAmB,CACzE,GAAG,eAEG,EAAa,EAAM,YAAsB,KAC7C,EAAG,oBAAiD,IAAmB,GACzE,GAAG,eAEH,GAAI,GAAa,CAAC,EAAW,CAE3B,IAAM,GAAmB,KAAa,0CAAkC,QAExE,GAAI,CADc,MAAM,EAAgB,YAAY,EAGlD,MADA,MAAM,EAAO,MAAM,EACb,IAAI,EAAa,oCAAoC,EAG7D,OADkB,MAAM,EAAgB,OAAO,EAIjD,GAAI,CACF,MAAM,EAAO,eAAe,EAAM,eAAe,EACjD,MAAO,EAAgB,CAGvB,MAFA,MAAM,EAAO,MAAM,EAEb,IAAI,EAAa,mCAAoC,CAAK,EAGlE,IAAM,GAAa,KAAa,0CAAkC,QAElE,GAAI,CADgB,MAAM,EAAU,YAAY,EAC9B,MAAM,IAAI,EAAa,oCAAoC,EAE7E,IAAQ,sBAAuB,KAAa,4BAEtC,EAAY,IAAI,EAAU,EAAQ,EAAM,eAAe,EAEvD,EAAe,CAAC,IAAW,CAC/B,GAAI,IAAW,EAAE,OACf,EAAgB,GAAG,oBAAoB,aAAc,CAAY,EAEjE,EAAU,gBAAgB,IAAI,CAAoB,GAKtD,OAFA,EAAgB,GAAG,iBAAiB,aAAc,CAAY,EAEvD",
|
|
8
|
-
"debugId": "019B41E14551343964756E2164756E21",
|
|
9
|
-
"names": []
|
|
10
|
-
}
|
package/dist/chunk-h2r568rz.js
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import{e as M}from"./chunk-1jpcb30j.js";import{hex as N}from"@scure/base";import{SwapKitError as Y}from"@swapkit/helpers";async function Z(q,z){let{RawTx:B}=await import("@swapkit/utxo-signer"),{getUtxoApi:D}=await import("@swapkit/toolboxes/utxo"),G=[];for(let j=0;j<q.inputsLength;j++){let f=q.getInput(j);if(!f.txid||f.index===void 0)throw Error(`PSBT input ${j} is missing txid/index`);let J=N.encode(f.txid),O=f.nonWitnessUtxo?N.encode(B.encode(f.nonWitnessUtxo)):await D(z).getRawTx(J);if(!O)throw new Y("wallet_ledger_invalid_params",{chain:z,inputIndex:j,reason:"Unable to resolve previous transaction hex for Ledger signing",txid:J});let Q=f.witnessUtxo?{script:f.witnessUtxo.script,value:Number(f.witnessUtxo.amount)}:void 0,V=f.index!==void 0?f.nonWitnessUtxo?.outputs?.[f.index]:void 0,X=Q?.value??(V?Number(V.amount):0);G.push({hash:J,index:f.index,txHex:O,value:X,witnessUtxo:Q})}return G}async function _({legacyClient:q,chain:z,tx:B}){let D=await Z(B,z);return q.signTransaction(B,D)}function E({legacyClient:q,chain:z,address:B}){return{getAddress:async()=>B,signTransaction:async(D)=>{let G=await _({chain:z,legacyClient:q,tx:D}),{Transaction:j}=await import("@swapkit/utxo-signer");return j.fromRaw(N.decode(G))}}}export{_ as signLegacyPsbtTransaction,Z as extractInputsFromPsbt,E as createLegacyPsbtSigner};
|
|
2
|
-
|
|
3
|
-
//# debugId=86FA7B33FF0F340E64756E2164756E21
|
|
4
|
-
//# sourceMappingURL=chunk-h2r568rz.js.map
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/ledger/clients/utxo-legacy-adapter.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"import { hex } from \"@scure/base\";\nimport { SwapKitError, type UTXOChain } from \"@swapkit/helpers\";\nimport type { UTXOType } from \"@swapkit/toolboxes/utxo\";\nimport type { Transaction } from \"@swapkit/utxo-signer\";\n\n/**\n * Extract per-input metadata from a V3 PSBT in the shape the legacy\n * `@ledgerhq/hw-app-btc.createPaymentTransaction` adapter expects.\n *\n * The legacy Ledger signer still needs the full previous tx hex for\n * `btcApp.splitTransaction(hex)`. Some V3 PSBTs only include `witnessUtxo`,\n * so we fetch the previous raw tx when `nonWitnessUtxo` is absent.\n *\n * Single-address account assumption: all inputs share our derivation path.\n */\nexport async function extractInputsFromPsbt(tx: Transaction, chain: UTXOChain): Promise<UTXOType[]> {\n const { RawTx } = await import(\"@swapkit/utxo-signer\");\n const { getUtxoApi } = await import(\"@swapkit/toolboxes/utxo\");\n const inputs: UTXOType[] = [];\n\n for (let i = 0; i < tx.inputsLength; i++) {\n const input = tx.getInput(i);\n\n if (!input.txid || input.index === undefined) {\n throw new Error(`PSBT input ${i} is missing txid/index`);\n }\n\n const txid = hex.encode(input.txid);\n const txHex = input.nonWitnessUtxo\n ? hex.encode(RawTx.encode(input.nonWitnessUtxo))\n : await getUtxoApi(chain).getRawTx(txid);\n if (!txHex) {\n throw new SwapKitError(\"wallet_ledger_invalid_params\", {\n chain,\n inputIndex: i,\n reason: \"Unable to resolve previous transaction hex for Ledger signing\",\n txid,\n });\n }\n const witnessUtxo = input.witnessUtxo\n ? { script: input.witnessUtxo.script, value: Number(input.witnessUtxo.amount) }\n : undefined;\n const nonWitnessPrevout = input.index !== undefined ? input.nonWitnessUtxo?.outputs?.[input.index] : undefined;\n const value = witnessUtxo?.value ?? (nonWitnessPrevout ? Number(nonWitnessPrevout.amount) : 0);\n\n inputs.push({ hash: txid, index: input.index, txHex, value, witnessUtxo } as UTXOType);\n }\n\n return inputs;\n}\n\nexport async function signLegacyPsbtTransaction({\n legacyClient,\n chain,\n tx,\n}: {\n legacyClient: { signTransaction: (tx: Transaction, inputUtxos: UTXOType[]) => Promise<string> };\n chain: UTXOChain;\n tx: Transaction;\n}): Promise<string> {\n const inputUtxos = await extractInputsFromPsbt(tx, chain);\n return legacyClient.signTransaction(tx, inputUtxos);\n}\n\n/**\n * Build a toolbox-compatible signer from the existing legacy Ledger UTXO\n * client. Callers that need sign-and-broadcast should broadcast the raw hex\n * from `signLegacyPsbtTransaction` directly; the legacy Ledger app returns an\n * already-finalized transaction that should not be passed back to toolbox\n * finalization.\n */\nexport function createLegacyPsbtSigner({\n legacyClient,\n chain,\n address,\n}: {\n legacyClient: { signTransaction: (tx: Transaction, inputUtxos: UTXOType[]) => Promise<string> };\n chain: UTXOChain;\n address: string;\n}) {\n return {\n getAddress: async () => address,\n signTransaction: async (tx: Transaction): Promise<Transaction> => {\n const signedTxHex = await signLegacyPsbtTransaction({ chain, legacyClient, tx });\n\n const { Transaction: TxClass } = await import(\"@swapkit/utxo-signer\");\n // `Transaction.fromRaw` parses a serialised tx (no PSBT envelope) — exactly\n // what `createPaymentTransaction` returns.\n return TxClass.fromRaw(hex.decode(signedTxHex));\n },\n };\n}\n"
|
|
6
|
-
],
|
|
7
|
-
"mappings": "wCAAA,cAAS,oBACT,uBAAS,yBAcT,eAAsB,CAAqB,CAAC,EAAiB,EAAuC,CAClG,IAAQ,SAAU,KAAa,iCACvB,cAAe,KAAa,mCAC9B,EAAqB,CAAC,EAE5B,QAAS,EAAI,EAAG,EAAI,EAAG,aAAc,IAAK,CACxC,IAAM,EAAQ,EAAG,SAAS,CAAC,EAE3B,GAAI,CAAC,EAAM,MAAQ,EAAM,QAAU,OACjC,MAAU,MAAM,cAAc,yBAAyB,EAGzD,IAAM,EAAO,EAAI,OAAO,EAAM,IAAI,EAC5B,EAAQ,EAAM,eAChB,EAAI,OAAO,EAAM,OAAO,EAAM,cAAc,CAAC,EAC7C,MAAM,EAAW,CAAK,EAAE,SAAS,CAAI,EACzC,GAAI,CAAC,EACH,MAAM,IAAI,EAAa,+BAAgC,CACrD,QACA,WAAY,EACZ,OAAQ,gEACR,MACF,CAAC,EAEH,IAAM,EAAc,EAAM,YACtB,CAAE,OAAQ,EAAM,YAAY,OAAQ,MAAO,OAAO,EAAM,YAAY,MAAM,CAAE,EAC5E,OACE,EAAoB,EAAM,QAAU,OAAY,EAAM,gBAAgB,UAAU,EAAM,OAAS,OAC/F,EAAQ,GAAa,QAAU,EAAoB,OAAO,EAAkB,MAAM,EAAI,GAE5F,EAAO,KAAK,CAAE,KAAM,EAAM,MAAO,EAAM,MAAO,QAAO,QAAO,aAAY,CAAa,EAGvF,OAAO,EAGT,eAAsB,CAAyB,EAC7C,eACA,QACA,MAKkB,CAClB,IAAM,EAAa,MAAM,EAAsB,EAAI,CAAK,EACxD,OAAO,EAAa,gBAAgB,EAAI,CAAU,EAU7C,SAAS,CAAsB,EACpC,eACA,QACA,WAKC,CACD,MAAO,CACL,WAAY,SAAY,EACxB,gBAAiB,MAAO,IAA0C,CAChE,IAAM,EAAc,MAAM,EAA0B,CAAE,QAAO,eAAc,IAAG,CAAC,GAEvE,YAAa,GAAY,KAAa,gCAG9C,OAAO,EAAQ,QAAQ,EAAI,OAAO,CAAW,CAAC,EAElD",
|
|
8
|
-
"debugId": "86FA7B33FF0F340E64756E2164756E21",
|
|
9
|
-
"names": []
|
|
10
|
-
}
|
package/dist/chunk-xkh15edk.js
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import{b as z}from"./chunk-7fsaymh4.js";import"./chunk-1jpcb30j.js";import{Chain as W,DerivationPath as X,derivationPathToString as Y}from"@swapkit/helpers";import{getRippleToolbox as Z}from"@swapkit/toolboxes/ripple";var w=async({sdk:E,derivationPath:F})=>{let G=F?Y(F):`${X[W.Ripple]}/0`,{address:j}=await E.address.xrpGetAddress({address_n:z(G)}),y=await Z({signer:{getAddress:()=>Promise.resolve(j),signTransaction:()=>{throw Error("signTransaction not supported via toolbox")}}});return{...y,address:j,getAddress:()=>j,transfer:async({recipient:I,assetValue:M,memo:q})=>{let f=await y.createTransaction({assetValue:M,memo:q,recipient:I,sender:j}),O={type:"auth/StdTx",value:{fee:{amount:[{amount:"1000",denom:"drop"}],gas:"28000"},memo:q&&q.length>0?q:"",msg:[{type:"ripple-sdk/MsgSend",value:{amount:[{amount:f.Amount,denom:"drop"}],from_address:j,to_address:I}}],signatures:null}},Q={addressNList:z(G),flags:f.Flags===0?void 0:f.Flags,lastLedgerSequence:f.LastLedgerSequence?.toString(),payment:{amount:f.Amount,destination:f.Destination,destinationTag:(f.DestinationTag??"0").toString()},sequence:(f.Sequence??0).toString(),tx:O},J=JSON.parse(await E.xrp.xrpSignTransaction(Q)),K=J.tx_blob??J.value?.signatures?.[0]?.serializedTx;if(!K)throw Error("KeepKey XRP sign failed");let U=Buffer.from(K,"base64").toString("hex");return y.broadcastTransaction(U)}}};export{w as rippleWalletMethods};
|
|
2
|
-
|
|
3
|
-
//# debugId=B9E7C62A7E5CA45F64756E2164756E21
|
|
4
|
-
//# sourceMappingURL=chunk-xkh15edk.js.map
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export declare const CLA = 85;
|
|
2
|
-
export declare const CHUNK_SIZE = 250;
|
|
3
|
-
export declare const APP_KEY = "CSM";
|
|
4
|
-
export declare const INS: {
|
|
5
|
-
GET_ADDR_SECP256K1: number;
|
|
6
|
-
GET_VERSION: number;
|
|
7
|
-
INS_PUBLIC_KEY_SECP256K1: number;
|
|
8
|
-
SIGN_SECP256K1: number;
|
|
9
|
-
};
|
|
10
|
-
export declare const PAYLOAD_TYPE: {
|
|
11
|
-
ADD: number;
|
|
12
|
-
INIT: number;
|
|
13
|
-
LAST: number;
|
|
14
|
-
};
|
|
15
|
-
export declare const P1_VALUES: {
|
|
16
|
-
ONLY_RETRIEVE: number;
|
|
17
|
-
SHOW_ADDRESS_IN_DEVICE: number;
|
|
18
|
-
};
|
|
19
|
-
export declare const P2_VALUES: {
|
|
20
|
-
JSON: number;
|
|
21
|
-
};
|
|
22
|
-
export declare const ERROR_CODE: {
|
|
23
|
-
NoError: number;
|
|
24
|
-
};
|
|
25
|
-
export declare function errorCodeToString(statusCode: number): any;
|
|
26
|
-
export declare function processErrorResponse(response: any): any;
|
|
27
|
-
export declare function getVersion(transport: any): any;
|
|
28
|
-
//# sourceMappingURL=common.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../../../src/ledger/clients/thorchain/common.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,GAAG,KAAO,CAAC;AACxB,eAAO,MAAM,UAAU,MAAM,CAAC;AAC9B,eAAO,MAAM,OAAO,QAAQ,CAAC;AAE7B,eAAO,MAAM,GAAG;;;;;CAKf,CAAC;AAEF,eAAO,MAAM,YAAY;;;;CAAwC,CAAC;AAElE,eAAO,MAAM,SAAS;;;CAAwD,CAAC;AAE/E,eAAO,MAAM,SAAS;;CAAgB,CAAC;AAEvC,eAAO,MAAM,UAAU;;CAAsB,CAAC;AA2B9C,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,OAGnD;AAMD,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,GAAG,OAejD;AAED,wBAAgB,UAAU,CAAC,SAAS,EAAE,GAAG,OAsBxC"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export declare function serializePathv1(path: number[]): Buffer<ArrayBuffer>;
|
|
2
|
-
export declare function signSendChunkv1(app: any, chunkIdx: number, _chunkNum: number, chunk: Buffer, txType?: number): any;
|
|
3
|
-
export declare function publicKeyv1(app: any, data: Buffer): any;
|
|
4
|
-
export declare function serializePathv2(path: number[]): Buffer<ArrayBuffer>;
|
|
5
|
-
export declare function signSendChunkv2(app: any, chunkIdx: number, chunkNum: number, chunk: Buffer, txType?: number): any;
|
|
6
|
-
export declare function publicKeyv2(app: any, data: Buffer): any;
|
|
7
|
-
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../../../src/ledger/clients/thorchain/helpers.ts"],"names":[],"mappings":"AAGA,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,uBAkB7C;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,SAAiB,OAmBpH;AAeD,wBAAgB,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,OAejD;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,uBAkB7C;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,SAAiB,OAUnH;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,OAajD"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type Transport from "@ledgerhq/hw-transport";
|
|
2
|
-
export declare class THORChainApp {
|
|
3
|
-
transport: Transport;
|
|
4
|
-
versionResponse: any;
|
|
5
|
-
constructor(transport: any);
|
|
6
|
-
static serializeHRP(hrp: string): Buffer<ArrayBuffer>;
|
|
7
|
-
serializePath(path: number[]): Promise<Buffer<ArrayBuffer>>;
|
|
8
|
-
signGetChunks(path: number[], buffer: Buffer): Promise<Buffer<ArrayBuffer>[]>;
|
|
9
|
-
getVersion(): Promise<any>;
|
|
10
|
-
appInfo(): Promise<any>;
|
|
11
|
-
deviceInfo(): Promise<any>;
|
|
12
|
-
publicKey(path: number[]): Promise<any>;
|
|
13
|
-
getAddressAndPubKey(path: number[], hrp: string, showInDevice?: boolean): Promise<any>;
|
|
14
|
-
showAddressAndPubKey(path: number[], hrp: string): Promise<any>;
|
|
15
|
-
signSendChunk(chunkIdx: number, chunkNum: number, chunk: Buffer, txType?: number): any;
|
|
16
|
-
sign(path: number[], message: string, txType?: number): Promise<{
|
|
17
|
-
error_message: any;
|
|
18
|
-
return_code: any;
|
|
19
|
-
signature: null;
|
|
20
|
-
}>;
|
|
21
|
-
}
|
|
22
|
-
//# sourceMappingURL=lib.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../../../../../src/ledger/clients/thorchain/lib.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,wBAAwB,CAAC;AAuBpD,qBAAa,YAAY;IACvB,SAAS,EAAE,SAAS,CAAC;IACrB,eAAe,EAAE,GAAG,CAAC;gBAET,SAAS,EAAE,GAAG;IAQ1B,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,MAAM;IAUzB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE;IAiB5B,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM;IAiB5C,UAAU;IAShB,OAAO;IAyCP,UAAU;IA6CJ,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE;IAmBxB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,YAAY,UAAQ;IA4B3E,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM;IAIhD,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,SAAiB;IAWlF,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,SAAiB;;;;;CAqBpE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../src/ledger/clients/thorchain/utils.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,YAAY,GAAI,gBAAgB,GAAG,WAiE/C,CAAC"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type Transport from "@ledgerhq/hw-transport";
|
|
2
|
-
import { type DerivationPathArray } from "@swapkit/helpers";
|
|
3
|
-
import type { Transaction } from "@swapkit/utxo-signer";
|
|
4
|
-
export declare const BitcoinPsbtLedger: (derivationPathArray?: DerivationPathArray | string, injectedTransport?: Transport) => {
|
|
5
|
-
connect: () => Promise<void>;
|
|
6
|
-
getAddress: () => Promise<string>;
|
|
7
|
-
getExtendedPublicKey: (path?: string) => Promise<string>;
|
|
8
|
-
getPublicKey: () => Promise<Uint8Array<ArrayBufferLike>>;
|
|
9
|
-
signTransaction: (tx: Transaction) => Promise<Transaction>;
|
|
10
|
-
};
|
|
11
|
-
export declare const LitecoinPsbtLedger: (derivationPathArray?: DerivationPathArray | string, injectedTransport?: Transport) => {
|
|
12
|
-
connect: () => Promise<void>;
|
|
13
|
-
getAddress: () => Promise<string>;
|
|
14
|
-
getExtendedPublicKey: (path?: string) => Promise<string>;
|
|
15
|
-
getPublicKey: () => Promise<Uint8Array<ArrayBufferLike>>;
|
|
16
|
-
signTransaction: (tx: Transaction) => Promise<Transaction>;
|
|
17
|
-
};
|
|
18
|
-
//# sourceMappingURL=utxo-psbt.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utxo-psbt.d.ts","sourceRoot":"","sources":["../../../../src/ledger/clients/utxo-psbt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,wBAAwB,CAAC;AAGpD,OAAO,EAEL,KAAK,mBAAmB,EAKzB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AA+LxD,eAAO,MAAM,iBAAiB,yBAlIE,mBAAmB,GAAG,MAAM,sBAAsB,SAAS;;;;;0BAsFzD,WAAW,KAAG,OAAO,CAAC,WAAW,CAAC;CA4CK,CAAC;AAC1E,eAAO,MAAM,kBAAkB,yBAnIC,mBAAmB,GAAG,MAAM,sBAAsB,SAAS;;;;;0BAsFzD,WAAW,KAAG,OAAO,CAAC,WAAW,CAAC;CA6CO,CAAC"}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
export interface Coin {
|
|
2
|
-
readonly denom: string;
|
|
3
|
-
readonly amount: string;
|
|
4
|
-
}
|
|
5
|
-
export interface EncodeObject {
|
|
6
|
-
readonly typeUrl: string;
|
|
7
|
-
readonly value: any;
|
|
8
|
-
}
|
|
9
|
-
export interface AminoMsg {
|
|
10
|
-
readonly type: string;
|
|
11
|
-
readonly value: any;
|
|
12
|
-
}
|
|
13
|
-
export interface AminoMsgSend extends AminoMsg {
|
|
14
|
-
readonly type: "cosmos-sdk/MsgSend";
|
|
15
|
-
readonly value: {
|
|
16
|
-
/** Bech32 account address */
|
|
17
|
-
readonly from_address: string;
|
|
18
|
-
/** Bech32 account address */
|
|
19
|
-
readonly to_address: string;
|
|
20
|
-
readonly amount: readonly Coin[];
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
export interface AminoConverter {
|
|
24
|
-
readonly aminoType: string;
|
|
25
|
-
readonly toAmino: (value: any) => any;
|
|
26
|
-
readonly fromAmino: (value: any) => any;
|
|
27
|
-
}
|
|
28
|
-
/** A map from protobuf type URL to the AminoConverter implementation if supported on chain */
|
|
29
|
-
export type AminoConverters = Record<string, AminoConverter | "not_supported_by_chain">;
|
|
30
|
-
/**
|
|
31
|
-
* A map from Stargate message types as used in the messages's `Any` type
|
|
32
|
-
* to Amino types.
|
|
33
|
-
*/
|
|
34
|
-
export declare class AminoTypes {
|
|
35
|
-
private readonly register;
|
|
36
|
-
constructor(types: AminoConverters);
|
|
37
|
-
toAmino({ typeUrl, value }: EncodeObject): AminoMsg;
|
|
38
|
-
fromAmino({ type, value }: AminoMsg): EncodeObject;
|
|
39
|
-
}
|
|
40
|
-
//# sourceMappingURL=cosmosTypes.d.ts.map
|