@swapkit/wallet-hardware 5.0.1 → 6.0.1
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 +183 -68
- 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();
|
|
@@ -201,15 +199,63 @@ function tryNormalizeTrezorExtendedPublicKey(xpub: string | undefined, chain: UT
|
|
|
201
199
|
}
|
|
202
200
|
}
|
|
203
201
|
|
|
204
|
-
function decodeOpReturnData(script: Uint8Array)
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
202
|
+
async function decodeOpReturnData(script: Uint8Array) {
|
|
203
|
+
const { Script } = await import("@swapkit/utxo-signer");
|
|
204
|
+
|
|
205
|
+
try {
|
|
206
|
+
const [opcode, data] = Script.decode(script);
|
|
207
|
+
const bytes = data === 0 ? new Uint8Array() : data;
|
|
208
|
+
if (opcode !== "RETURN" || !(bytes instanceof Uint8Array)) return null;
|
|
209
|
+
|
|
210
|
+
// Trezor rebuilds the script from the data, so only accept scripts it reproduces byte for byte
|
|
211
|
+
return hex.encode(Script.encode(["RETURN", bytes])) === hex.encode(script) ? hex.encode(bytes) : null;
|
|
212
|
+
} catch {
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
async function toTrezorOpReturnOutput(script: Uint8Array, amount: bigint | undefined, chain: Chain) {
|
|
218
|
+
if (amount !== 0n) {
|
|
219
|
+
throw new SwapKitError({
|
|
220
|
+
errorKey: "wallet_trezor_failed_to_sign_transaction",
|
|
221
|
+
info: { chain, error: "OP_RETURN output carrying value cannot be signed" },
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const opReturnData = await decodeOpReturnData(script);
|
|
226
|
+
|
|
227
|
+
if (opReturnData === null) {
|
|
228
|
+
throw new SwapKitError({
|
|
229
|
+
errorKey: "wallet_trezor_failed_to_sign_transaction",
|
|
230
|
+
info: { chain, error: "Malformed OP_RETURN output cannot be signed" },
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return { amount: "0", op_return_data: opReturnData, script_type: "PAYTOOPRETURN" as const };
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
async function assertTransactionCarriesMemo(tx: Transaction, memo: string, chain: Chain) {
|
|
238
|
+
if (!memo) return;
|
|
239
|
+
|
|
240
|
+
const expected = hex.encode(new TextEncoder().encode(memo));
|
|
241
|
+
|
|
242
|
+
for (let i = 0; i < tx.outputsLength; i++) {
|
|
243
|
+
const script = tx.getOutput(i).script;
|
|
244
|
+
if (script?.[0] === 0x6a && (await decodeOpReturnData(script)) === expected) return;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
throw new SwapKitError({
|
|
248
|
+
errorKey: "wallet_trezor_failed_to_sign_transaction",
|
|
249
|
+
info: { chain, error: "Transaction does not carry the provided memo" },
|
|
250
|
+
});
|
|
209
251
|
}
|
|
210
252
|
|
|
211
|
-
function getScriptType(derivationPath: DerivationPathArray) {
|
|
253
|
+
function getScriptType(chain: Chain, derivationPath: DerivationPathArray) {
|
|
212
254
|
switch (derivationPath[0]) {
|
|
255
|
+
case 86:
|
|
256
|
+
return chain === Chain.Bitcoin
|
|
257
|
+
? ({ input: "SPENDTAPROOT", output: "PAYTOTAPROOT", utxo: UTXOScriptType.P2TR } as const)
|
|
258
|
+
: null;
|
|
213
259
|
case 84:
|
|
214
260
|
return { input: "SPENDWITNESS", output: "PAYTOWITNESS", utxo: UTXOScriptType.P2WPKH } as const;
|
|
215
261
|
case 49:
|
|
@@ -245,6 +291,37 @@ function getFirstBip32Derivation(input: { bip32Derivation?: unknown }): TrezorBi
|
|
|
245
291
|
return isTrezorBip32Derivation(firstDerivation) ? firstDerivation : undefined;
|
|
246
292
|
}
|
|
247
293
|
|
|
294
|
+
function isTrezorTapBip32Derivation(value: unknown): value is TrezorTapBip32Derivation {
|
|
295
|
+
if (!(Array.isArray(value) && value[0] instanceof Uint8Array)) return false;
|
|
296
|
+
const origin = value[1] as { der?: { path?: unknown }; hashes?: unknown } | undefined;
|
|
297
|
+
|
|
298
|
+
return Array.isArray(origin?.hashes) && Array.isArray(origin?.der?.path);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// Key-path origins carry no leaf hashes; take the one for the internal key, or the only one when it is unset.
|
|
302
|
+
function selectTapKeyOrigin(input: { tapBip32Derivation?: unknown; tapInternalKey?: Uint8Array }, inputIndex: number) {
|
|
303
|
+
const origins = Array.isArray(input.tapBip32Derivation) ? input.tapBip32Derivation : [];
|
|
304
|
+
if (origins.length === 0) return undefined;
|
|
305
|
+
|
|
306
|
+
const { tapInternalKey } = input;
|
|
307
|
+
const keyPathOrigins = origins.filter(
|
|
308
|
+
(origin): origin is TrezorTapBip32Derivation =>
|
|
309
|
+
isTrezorTapBip32Derivation(origin) &&
|
|
310
|
+
origin[1].hashes.length === 0 &&
|
|
311
|
+
(!tapInternalKey || hex.encode(origin[0]) === hex.encode(tapInternalKey)),
|
|
312
|
+
);
|
|
313
|
+
const [xOnlyKey, origin] = keyPathOrigins[0] ?? [];
|
|
314
|
+
|
|
315
|
+
if (keyPathOrigins.length !== 1 || !(xOnlyKey && origin)) {
|
|
316
|
+
throw new SwapKitError({
|
|
317
|
+
errorKey: "wallet_trezor_failed_to_sign_transaction",
|
|
318
|
+
info: { chain: Chain.Bitcoin, error: `Input ${inputIndex} has no single taproot key-path origin to sign with` },
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
return { path: origin.der.path, xOnlyKey };
|
|
323
|
+
}
|
|
324
|
+
|
|
248
325
|
function getPrevoutAmount(input: {
|
|
249
326
|
index?: number;
|
|
250
327
|
nonWitnessUtxo?: { outputs?: Array<{ amount?: bigint | number }> };
|
|
@@ -263,7 +340,7 @@ export function normalizeTrezorSignature(signatureHex: string, chain: Chain) {
|
|
|
263
340
|
const derLength = signature[1] !== undefined ? signature[1] + 2 : undefined;
|
|
264
341
|
|
|
265
342
|
if (derLength !== undefined && signature.length === derLength) {
|
|
266
|
-
return new Uint8Array([...signature, chain === Chain.BitcoinCash ?
|
|
343
|
+
return new Uint8Array([...signature, chain === Chain.BitcoinCash ? BITCOIN_CASH_SIGHASH_ALL : 0x01]);
|
|
267
344
|
}
|
|
268
345
|
|
|
269
346
|
return new Uint8Array(signature);
|
|
@@ -294,16 +371,9 @@ async function buildPCZTOutputsForTrezor(pczt: PCZT, address_n: number[], myAddr
|
|
|
294
371
|
const output = pczt.getOutput(i);
|
|
295
372
|
const script = output.scriptPubkey;
|
|
296
373
|
|
|
297
|
-
if (
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
outputs.push({ amount: "0", op_return_data: opReturnData, script_type: "PAYTOOPRETURN" as const });
|
|
301
|
-
continue;
|
|
302
|
-
}
|
|
303
|
-
throw new SwapKitError({
|
|
304
|
-
errorKey: "wallet_trezor_failed_to_sign_transaction",
|
|
305
|
-
info: { chain, error: "Malformed OP_RETURN output cannot be signed" },
|
|
306
|
-
});
|
|
374
|
+
if (script?.[0] === 0x6a) {
|
|
375
|
+
outputs.push(await toTrezorOpReturnOutput(script, output.value, chain));
|
|
376
|
+
continue;
|
|
307
377
|
}
|
|
308
378
|
|
|
309
379
|
const outputAddress = await decodeOutputAddress(script);
|
|
@@ -328,7 +398,7 @@ async function buildPCZTOutputsForTrezor(pczt: PCZT, address_n: number[], myAddr
|
|
|
328
398
|
|
|
329
399
|
async function decodeOutputAddress(script: Uint8Array): Promise<string | undefined> {
|
|
330
400
|
try {
|
|
331
|
-
const { OutScript, Address } = await import("@swapkit/utxo-signer");
|
|
401
|
+
const { OutScript, Address, NETWORKS } = await import("@swapkit/utxo-signer");
|
|
332
402
|
const decoded = OutScript.decode(script);
|
|
333
403
|
if (decoded.type === "pkh" || decoded.type === "pk") {
|
|
334
404
|
return Address(NETWORKS.zcash).encode(decoded);
|
|
@@ -378,19 +448,27 @@ function buildZcashTxInputsForTrezor(
|
|
|
378
448
|
return inputs;
|
|
379
449
|
}
|
|
380
450
|
|
|
381
|
-
function buildZcashTxOutputsForTrezor(
|
|
451
|
+
async function buildZcashTxOutputsForTrezor({
|
|
452
|
+
addressN,
|
|
453
|
+
chain,
|
|
454
|
+
myAddress,
|
|
455
|
+
network,
|
|
456
|
+
tx,
|
|
457
|
+
}: {
|
|
458
|
+
addressN: number[];
|
|
459
|
+
chain: Chain;
|
|
460
|
+
myAddress: string;
|
|
461
|
+
network: BTCNetwork;
|
|
462
|
+
tx: ZcashTransaction;
|
|
463
|
+
}) {
|
|
382
464
|
const outputs = [];
|
|
383
465
|
for (let i = 0; i < tx.outputsLength; i++) {
|
|
384
466
|
const output = tx.getOutput(i);
|
|
385
|
-
const outputAddress = tx.getOutputAddress(i,
|
|
467
|
+
const outputAddress = tx.getOutputAddress(i, network);
|
|
386
468
|
const script = output.script;
|
|
387
469
|
|
|
388
|
-
if (
|
|
389
|
-
|
|
390
|
-
if (opReturnData) {
|
|
391
|
-
outputs.push({ amount: "0", op_return_data: opReturnData, script_type: "PAYTOOPRETURN" as const });
|
|
392
|
-
continue;
|
|
393
|
-
}
|
|
470
|
+
if (script?.[0] === 0x6a) {
|
|
471
|
+
outputs.push(await toTrezorOpReturnOutput(script, output.amount, chain));
|
|
394
472
|
continue;
|
|
395
473
|
}
|
|
396
474
|
|
|
@@ -402,18 +480,17 @@ function buildZcashTxOutputsForTrezor(tx: ZcashTransaction, address_n: number[],
|
|
|
402
480
|
}
|
|
403
481
|
|
|
404
482
|
const isChangeAddress = outputAddress === myAddress;
|
|
405
|
-
const outputParam = isChangeAddress || !outputAddress ? { address_n } : { address: outputAddress };
|
|
483
|
+
const outputParam = isChangeAddress || !outputAddress ? { address_n: addressN } : { address: outputAddress };
|
|
406
484
|
outputs.push({ ...outputParam, amount: output.amount?.toString() || "0", script_type: "PAYTOADDRESS" as const });
|
|
407
485
|
}
|
|
408
486
|
return outputs;
|
|
409
487
|
}
|
|
410
488
|
|
|
411
|
-
function buildUtxoOutputsForTrezor(
|
|
489
|
+
async function buildUtxoOutputsForTrezor(
|
|
412
490
|
tx: Transaction,
|
|
413
491
|
network: BTCNetwork,
|
|
414
492
|
address_n: number[],
|
|
415
493
|
myAddress: string,
|
|
416
|
-
memo: string,
|
|
417
494
|
chain: Chain,
|
|
418
495
|
scriptType: { input: string; output: string },
|
|
419
496
|
toCashAddress: (addr: string) => string,
|
|
@@ -424,17 +501,12 @@ function buildUtxoOutputsForTrezor(
|
|
|
424
501
|
const output = tx.getOutput(i);
|
|
425
502
|
const outputAddress = tx.getOutputAddress(i, network);
|
|
426
503
|
|
|
427
|
-
if (
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
amount: "0",
|
|
432
|
-
op_return_data: opReturnData ?? Buffer.from(memo).toString("hex"),
|
|
433
|
-
script_type: "PAYTOOPRETURN",
|
|
434
|
-
});
|
|
435
|
-
continue;
|
|
436
|
-
}
|
|
504
|
+
if (output.script?.[0] === 0x6a) {
|
|
505
|
+
outputs.push(await toTrezorOpReturnOutput(output.script, output.amount, chain));
|
|
506
|
+
continue;
|
|
507
|
+
}
|
|
437
508
|
|
|
509
|
+
if (!outputAddress) {
|
|
438
510
|
throw new SwapKitError({
|
|
439
511
|
errorKey: "wallet_trezor_failed_to_sign_transaction",
|
|
440
512
|
info: { chain, error: "Unable to decode output address from scriptPubkey" },
|
|
@@ -509,9 +581,11 @@ async function getTrezorWallet<T extends Chain>({
|
|
|
509
581
|
case Chain.BinanceSmartChain:
|
|
510
582
|
case Chain.Ethereum:
|
|
511
583
|
case Chain.Gnosis:
|
|
584
|
+
case Chain.Hyperevm:
|
|
512
585
|
case Chain.Monad:
|
|
513
586
|
case Chain.Optimism:
|
|
514
587
|
case Chain.Polygon:
|
|
588
|
+
case Chain.Robinhood:
|
|
515
589
|
case Chain.XLayer: {
|
|
516
590
|
const { getProvider, getEvmToolboxAsync } = await import("@swapkit/toolboxes/evm");
|
|
517
591
|
const { getEVMSigner } = await import("./evmSigner");
|
|
@@ -586,10 +660,17 @@ async function getTrezorWallet<T extends Chain>({
|
|
|
586
660
|
const signZcashTransactionWithSerializedTx = async (tx: ZcashTransaction) => {
|
|
587
661
|
const TrezorConnect = (await import("@trezor/connect-web")).default;
|
|
588
662
|
const { hex: hexEncode } = await import("@scure/base");
|
|
663
|
+
const { NETWORKS, ZcashVersionGroupId } = await import("@swapkit/utxo-signer");
|
|
589
664
|
const address_n = hardenDerivationPath(derivationPath);
|
|
590
665
|
|
|
591
666
|
const inputs = buildZcashTxInputsForTrezor(tx, [], address_n, hexEncode);
|
|
592
|
-
const outputs = buildZcashTxOutputsForTrezor(
|
|
667
|
+
const outputs = await buildZcashTxOutputsForTrezor({
|
|
668
|
+
addressN: address_n,
|
|
669
|
+
chain,
|
|
670
|
+
myAddress: address,
|
|
671
|
+
network: NETWORKS.zcash,
|
|
672
|
+
tx,
|
|
673
|
+
});
|
|
593
674
|
|
|
594
675
|
const result = await TrezorConnect.signTransaction({
|
|
595
676
|
branchId: tx.consensusBranchId,
|
|
@@ -686,13 +767,14 @@ async function getTrezorWallet<T extends Chain>({
|
|
|
686
767
|
case Chain.Litecoin: {
|
|
687
768
|
const { toCashAddress, getUtxoToolbox, stripPrefix } = await import("@swapkit/toolboxes/utxo");
|
|
688
769
|
const utxoChain = chain as UTXOChain;
|
|
689
|
-
const scriptType = getScriptType(derivationPath);
|
|
770
|
+
const scriptType = getScriptType(chain, derivationPath);
|
|
690
771
|
|
|
691
772
|
if (!scriptType) {
|
|
692
773
|
throw new SwapKitError({ errorKey: "wallet_trezor_derivation_path_not_supported", info: { derivationPath } });
|
|
693
774
|
}
|
|
694
775
|
|
|
695
776
|
const resolvedScriptType = scriptType;
|
|
777
|
+
const isTaproot = scriptType.utxo === UTXOScriptType.P2TR;
|
|
696
778
|
const toolboxParams = { scriptType: scriptType.utxo };
|
|
697
779
|
const coin = chain.toLowerCase();
|
|
698
780
|
|
|
@@ -724,16 +806,17 @@ async function getTrezorWallet<T extends Chain>({
|
|
|
724
806
|
const baseToolbox = getUtxoToolbox(chain, toolboxParams);
|
|
725
807
|
|
|
726
808
|
const signTransaction = async (tx: Transaction, inputs: UTXOType[], memo = "") => {
|
|
809
|
+
await assertTransactionCarriesMemo(tx, memo, chain);
|
|
810
|
+
|
|
727
811
|
const TrezorConnect = (await import("@trezor/connect-web")).default;
|
|
728
812
|
const address_n = hardenDerivationPath(derivationPath);
|
|
729
813
|
const network = getNetworkForChain(chain as UTXOChain);
|
|
730
814
|
|
|
731
|
-
const outputs = buildUtxoOutputsForTrezor(
|
|
815
|
+
const outputs = await buildUtxoOutputsForTrezor(
|
|
732
816
|
tx,
|
|
733
817
|
network,
|
|
734
818
|
address_n,
|
|
735
819
|
address,
|
|
736
|
-
memo,
|
|
737
820
|
chain,
|
|
738
821
|
resolvedScriptType,
|
|
739
822
|
toCashAddress,
|
|
@@ -795,10 +878,37 @@ async function getTrezorWallet<T extends Chain>({
|
|
|
795
878
|
const signerPubkeys: Uint8Array[] = [];
|
|
796
879
|
const trezorInputs = [];
|
|
797
880
|
|
|
798
|
-
|
|
799
|
-
|
|
881
|
+
async function prepareInputForSigning(inputIndex: number, input: ReturnType<Transaction["getInput"]>) {
|
|
882
|
+
if (isTaproot) {
|
|
883
|
+
let keyOrigin = selectTapKeyOrigin(input, inputIndex);
|
|
884
|
+
|
|
885
|
+
if (!keyOrigin) {
|
|
886
|
+
const [publicKey, { path }] = await getFallbackDerivation();
|
|
887
|
+
keyOrigin = { path, xOnlyKey: publicKey.slice(1) };
|
|
888
|
+
tx.updateInput(inputIndex, {
|
|
889
|
+
tapBip32Derivation: [[keyOrigin.xOnlyKey, { der: { fingerprint: 0, path }, hashes: [] }]],
|
|
890
|
+
});
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
// A BIP86 key-path input's internal key is the x-only key its origin names.
|
|
894
|
+
if (!input.tapInternalKey) tx.updateInput(inputIndex, { tapInternalKey: keyOrigin.xOnlyKey });
|
|
895
|
+
return keyOrigin.path;
|
|
896
|
+
}
|
|
897
|
+
|
|
800
898
|
const existingDerivation = getFirstBip32Derivation(input);
|
|
801
899
|
const derivation = existingDerivation ?? (await getFallbackDerivation());
|
|
900
|
+
signerPubkeys[inputIndex] = derivation[0];
|
|
901
|
+
|
|
902
|
+
if (!existingDerivation) {
|
|
903
|
+
tx.updateInput(inputIndex, { bip32Derivation: [derivation] });
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
await applyMissingSpendingMetadata({ chain: utxoChain, indexes: [inputIndex], publicKey: derivation[0], tx });
|
|
907
|
+
return derivation[1].path;
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
for (let inputIndex = 0; inputIndex < tx.inputsLength; inputIndex++) {
|
|
911
|
+
const input = tx.getInput(inputIndex);
|
|
802
912
|
const amount = getPrevoutAmount(input);
|
|
803
913
|
|
|
804
914
|
if (!input.txid || input.index === undefined || !amount) {
|
|
@@ -808,16 +918,10 @@ async function getTrezorWallet<T extends Chain>({
|
|
|
808
918
|
});
|
|
809
919
|
}
|
|
810
920
|
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
if (!existingDerivation) {
|
|
814
|
-
tx.updateInput(inputIndex, { bip32Derivation: [derivation] });
|
|
815
|
-
}
|
|
816
|
-
|
|
817
|
-
await applyMissingSpendingMetadata({ chain: utxoChain, indexes: [inputIndex], publicKey: derivation[0], tx });
|
|
921
|
+
const inputAddressN = await prepareInputForSigning(inputIndex, input);
|
|
818
922
|
|
|
819
923
|
trezorInputs.push({
|
|
820
|
-
address_n:
|
|
924
|
+
address_n: inputAddressN,
|
|
821
925
|
amount,
|
|
822
926
|
prev_hash: hexEncode.encode(input.txid),
|
|
823
927
|
prev_index: input.index,
|
|
@@ -826,12 +930,11 @@ async function getTrezorWallet<T extends Chain>({
|
|
|
826
930
|
});
|
|
827
931
|
}
|
|
828
932
|
|
|
829
|
-
const outputs = buildUtxoOutputsForTrezor(
|
|
933
|
+
const outputs = await buildUtxoOutputsForTrezor(
|
|
830
934
|
tx,
|
|
831
935
|
network,
|
|
832
936
|
address_n,
|
|
833
937
|
address,
|
|
834
|
-
"",
|
|
835
938
|
chain,
|
|
836
939
|
resolvedScriptType,
|
|
837
940
|
toCashAddress,
|
|
@@ -856,8 +959,16 @@ async function getTrezorWallet<T extends Chain>({
|
|
|
856
959
|
}
|
|
857
960
|
|
|
858
961
|
result.payload.signatures.forEach((signatureHex, inputIndex) => {
|
|
962
|
+
if (!signatureHex) return;
|
|
963
|
+
|
|
964
|
+
// Taproot key-path signatures are Schnorr, not DER, and finalize from tapKeySig.
|
|
965
|
+
if (isTaproot) {
|
|
966
|
+
tx.updateInput(inputIndex, { tapKeySig: hexEncode.decode(signatureHex) });
|
|
967
|
+
return;
|
|
968
|
+
}
|
|
969
|
+
|
|
859
970
|
const pubkey = signerPubkeys[inputIndex];
|
|
860
|
-
if (!
|
|
971
|
+
if (!pubkey) return;
|
|
861
972
|
|
|
862
973
|
tx.updateInput(inputIndex, { partialSig: [[pubkey, normalizeTrezorSignature(signatureHex, chain)]] });
|
|
863
974
|
});
|
|
@@ -893,12 +1004,11 @@ async function getTrezorWallet<T extends Chain>({
|
|
|
893
1004
|
});
|
|
894
1005
|
}
|
|
895
1006
|
|
|
896
|
-
const outputs = buildUtxoOutputsForTrezor(
|
|
1007
|
+
const outputs = await buildUtxoOutputsForTrezor(
|
|
897
1008
|
tx,
|
|
898
1009
|
network,
|
|
899
1010
|
address_n,
|
|
900
1011
|
address,
|
|
901
|
-
"",
|
|
902
1012
|
chain,
|
|
903
1013
|
resolvedScriptType,
|
|
904
1014
|
toCashAddress,
|
|
@@ -936,16 +1046,17 @@ async function getTrezorWallet<T extends Chain>({
|
|
|
936
1046
|
}>,
|
|
937
1047
|
memo = "",
|
|
938
1048
|
) => {
|
|
1049
|
+
await assertTransactionCarriesMemo(tx, memo, chain);
|
|
1050
|
+
|
|
939
1051
|
const TrezorConnect = (await import("@trezor/connect-web")).default;
|
|
940
1052
|
const network = getNetworkForChain(chain as UTXOChain);
|
|
941
1053
|
const baseAddressN = hardenDerivationPath(derivationPath.slice(0, 3) as unknown as DerivationPathArray);
|
|
942
1054
|
|
|
943
|
-
const outputs = buildUtxoOutputsForTrezor(
|
|
1055
|
+
const outputs = await buildUtxoOutputsForTrezor(
|
|
944
1056
|
tx,
|
|
945
1057
|
network,
|
|
946
1058
|
baseAddressN,
|
|
947
1059
|
address,
|
|
948
|
-
memo,
|
|
949
1060
|
chain,
|
|
950
1061
|
resolvedScriptType,
|
|
951
1062
|
toCashAddress,
|
|
@@ -1378,10 +1489,12 @@ export const trezorWallet = createWallet({
|
|
|
1378
1489
|
[Chain.Ethereum]: true,
|
|
1379
1490
|
[Chain.Gnosis]: true,
|
|
1380
1491
|
[Chain.Dogecoin]: true,
|
|
1492
|
+
[Chain.Hyperevm]: true,
|
|
1381
1493
|
[Chain.Litecoin]: true,
|
|
1382
1494
|
[Chain.Monad]: true,
|
|
1383
1495
|
[Chain.Optimism]: true,
|
|
1384
1496
|
[Chain.Polygon]: true,
|
|
1497
|
+
[Chain.Robinhood]: true,
|
|
1385
1498
|
[Chain.XLayer]: true,
|
|
1386
1499
|
[Chain.Zcash]: true,
|
|
1387
1500
|
},
|
|
@@ -1401,10 +1514,12 @@ export const trezorWallet = createWallet({
|
|
|
1401
1514
|
Chain.Dogecoin,
|
|
1402
1515
|
Chain.Ethereum,
|
|
1403
1516
|
Chain.Gnosis,
|
|
1517
|
+
Chain.Hyperevm,
|
|
1404
1518
|
Chain.Litecoin,
|
|
1405
1519
|
Chain.Monad,
|
|
1406
1520
|
Chain.Optimism,
|
|
1407
1521
|
Chain.Polygon,
|
|
1522
|
+
Chain.Robinhood,
|
|
1408
1523
|
Chain.XLayer,
|
|
1409
1524
|
Chain.Zcash,
|
|
1410
1525
|
],
|
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
|