@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
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import type Transport from "@ledgerhq/hw-transport";
|
|
2
|
-
import { SwapKitError } from "@swapkit/helpers";
|
|
3
|
-
|
|
4
|
-
const getNavigatorUsb = () =>
|
|
5
|
-
navigator?.usb as unknown as {
|
|
6
|
-
getDevices: () => Promise<any[]>;
|
|
7
|
-
requestDevice: (requestObject: any) => Promise<any>;
|
|
8
|
-
removeEventListener: (event: string, callback: (e: any) => void) => void;
|
|
9
|
-
addEventListener: (event: string, callback: (e: any) => void) => void;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
const getLedgerDevices = async (): Promise<USBDevice> => {
|
|
13
|
-
const navigatorUsb = getNavigatorUsb();
|
|
14
|
-
|
|
15
|
-
if (typeof navigatorUsb?.getDevices !== "function") return {} as USBDevice;
|
|
16
|
-
const { ledgerUSBVendorId } = await import("@ledgerhq/devices");
|
|
17
|
-
|
|
18
|
-
const devices = await navigatorUsb?.getDevices();
|
|
19
|
-
const existingDevices = devices.filter((d) => d.vendorId === ledgerUSBVendorId);
|
|
20
|
-
if (existingDevices.length > 0) return existingDevices[0];
|
|
21
|
-
|
|
22
|
-
return navigatorUsb?.requestDevice({ filters: [{ vendorId: ledgerUSBVendorId }] });
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export const getLedgerTransport = async (): Promise<Transport> => {
|
|
26
|
-
const device = await getLedgerDevices();
|
|
27
|
-
|
|
28
|
-
if (!device) {
|
|
29
|
-
throw new SwapKitError("wallet_ledger_device_not_found");
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
device.opened || (await device.open());
|
|
33
|
-
if (device.configuration === null) await device.selectConfiguration(1);
|
|
34
|
-
|
|
35
|
-
try {
|
|
36
|
-
await device.reset();
|
|
37
|
-
} catch {
|
|
38
|
-
// reset fails on devices that are already open
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const configuration = device.configuration ?? device.configurations?.[0];
|
|
42
|
-
|
|
43
|
-
const iface =
|
|
44
|
-
configuration?.interfaces.find(({ alternates }: { alternates: { interfaceClass: number }[] }) =>
|
|
45
|
-
alternates.some(({ interfaceClass }) => interfaceClass === 0xff),
|
|
46
|
-
) ||
|
|
47
|
-
configuration?.interfaces.find(({ alternates }: { alternates: { interfaceClass: number }[] }) =>
|
|
48
|
-
alternates.some(({ interfaceClass }) => interfaceClass === 0x03),
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
if (!iface) {
|
|
52
|
-
await device.close();
|
|
53
|
-
throw new SwapKitError("wallet_ledger_connection_error");
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const klass0x03 = (iface.alternates as any[])?.find(
|
|
57
|
-
({ interfaceClass }: { interfaceClass: number }) => interfaceClass === 0x03,
|
|
58
|
-
)?.interfaceClass as number;
|
|
59
|
-
|
|
60
|
-
const klass0xff = (iface.alternates as any[])?.find(
|
|
61
|
-
({ interfaceClass }: { interfaceClass: number }) => interfaceClass === 0xff,
|
|
62
|
-
)?.interfaceClass as number;
|
|
63
|
-
|
|
64
|
-
if (klass0x03 && !klass0xff) {
|
|
65
|
-
// -------- HID class (NEAR, ETH, SOL, etc.) -> WebHID transport --------
|
|
66
|
-
const TransportWebHID = (await import("@ledgerhq/hw-transport-webhid")).default;
|
|
67
|
-
const supported = await TransportWebHID.isSupported();
|
|
68
|
-
if (!supported) {
|
|
69
|
-
await device.close();
|
|
70
|
-
throw new SwapKitError("wallet_ledger_webhid_not_supported");
|
|
71
|
-
}
|
|
72
|
-
const transport = await TransportWebHID.create();
|
|
73
|
-
return transport;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
try {
|
|
77
|
-
await device.claimInterface(iface.interfaceNumber);
|
|
78
|
-
} catch (error: unknown) {
|
|
79
|
-
await device.close();
|
|
80
|
-
|
|
81
|
-
throw new SwapKitError("wallet_ledger_connection_claimed", error);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const Transport = (await import("@ledgerhq/hw-transport-webusb")).default;
|
|
85
|
-
const isSupported = await Transport.isSupported();
|
|
86
|
-
if (!isSupported) throw new SwapKitError("wallet_ledger_webusb_not_supported");
|
|
87
|
-
|
|
88
|
-
const { DisconnectedDevice } = await import("@ledgerhq/errors");
|
|
89
|
-
|
|
90
|
-
const transport = new Transport(device, iface.interfaceNumber);
|
|
91
|
-
|
|
92
|
-
const onDisconnect = (e: any) => {
|
|
93
|
-
if (device === e.device) {
|
|
94
|
-
getNavigatorUsb()?.removeEventListener("disconnect", onDisconnect);
|
|
95
|
-
|
|
96
|
-
transport._emitDisconnect(new DisconnectedDevice());
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
getNavigatorUsb()?.addEventListener("disconnect", onDisconnect);
|
|
100
|
-
|
|
101
|
-
return transport as Transport;
|
|
102
|
-
};
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import type Transport from "@ledgerhq/hw-transport";
|
|
2
|
-
|
|
3
|
-
const LEDGER_CAL_SERVICE_URL = "https://crypto-assets-service.api.ledger.com/v1";
|
|
4
|
-
|
|
5
|
-
const LEDGER_DEVICE_TO_CAL_MODEL: Record<string, string> = {
|
|
6
|
-
apex: "apexp",
|
|
7
|
-
europa: "flex",
|
|
8
|
-
nanoS: "nanos",
|
|
9
|
-
nanoSP: "nanosp",
|
|
10
|
-
nanoX: "nanox",
|
|
11
|
-
stax: "stax",
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const APDU_CLA = 0xe0;
|
|
15
|
-
const APDU_CLA_PKI = 0xb0;
|
|
16
|
-
const APDU_INS_LOAD_CERTIFICATE = 0x06;
|
|
17
|
-
const LEDGER_KEY_USAGE_NETWORK = 0x0c;
|
|
18
|
-
const APDU_INS_PROVIDE_NETWORK_INFORMATION = 0x30;
|
|
19
|
-
const APDU_P1_FIRST_CHUNK = 0x01;
|
|
20
|
-
const APDU_P1_FOLLOWING_CHUNK = 0x00;
|
|
21
|
-
const APDU_P2_NETWORK_CONFIG = 0x00;
|
|
22
|
-
const APDU_P2_NETWORK_ICON = 0x01;
|
|
23
|
-
const APDU_MAX_CHUNK_SIZE = 0xff;
|
|
24
|
-
const TLV_TAG_DER_SIGNATURE = 0x15;
|
|
25
|
-
|
|
26
|
-
export type LedgerNetworkDescriptor = { data: string; icon?: string; signature: string };
|
|
27
|
-
|
|
28
|
-
type CalNetwork = {
|
|
29
|
-
chain_id: number;
|
|
30
|
-
descriptors?: Record<string, { data?: string; signatures?: { prod?: string } }>;
|
|
31
|
-
icons?: Record<string, string>;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export async function fetchLedgerNetworkCertificate(
|
|
35
|
-
deviceModelId: string,
|
|
36
|
-
fetchFn: typeof fetch = fetch,
|
|
37
|
-
): Promise<string | null> {
|
|
38
|
-
const calModel = LEDGER_DEVICE_TO_CAL_MODEL[deviceModelId];
|
|
39
|
-
if (!calModel) return null;
|
|
40
|
-
|
|
41
|
-
const url = `${LEDGER_CAL_SERVICE_URL}/certificates?output=descriptor&public_key_usage=network&target_device=${calModel}`;
|
|
42
|
-
const response = await fetchFn(url);
|
|
43
|
-
if (!response.ok) return null;
|
|
44
|
-
|
|
45
|
-
const certificates = (await response.json()) as Array<{
|
|
46
|
-
descriptor?: { data?: string; signatures?: { prod?: string } };
|
|
47
|
-
}>;
|
|
48
|
-
const descriptor = certificates[0]?.descriptor;
|
|
49
|
-
const signature = descriptor?.signatures?.prod;
|
|
50
|
-
|
|
51
|
-
if (!(descriptor?.data && signature)) return null;
|
|
52
|
-
|
|
53
|
-
return `${descriptor.data}${appendSignatureTlv(signature)}`;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export async function provideLedgerCertificate(transport: Transport, payloadHex: string) {
|
|
57
|
-
await transport.send(
|
|
58
|
-
APDU_CLA_PKI,
|
|
59
|
-
APDU_INS_LOAD_CERTIFICATE,
|
|
60
|
-
LEDGER_KEY_USAGE_NETWORK,
|
|
61
|
-
0x00,
|
|
62
|
-
Buffer.from(payloadHex, "hex"),
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export async function fetchLedgerNetworkDescriptor(
|
|
67
|
-
chainId: number,
|
|
68
|
-
deviceModelId: string,
|
|
69
|
-
fetchFn: typeof fetch = fetch,
|
|
70
|
-
): Promise<LedgerNetworkDescriptor | null> {
|
|
71
|
-
const calModel = LEDGER_DEVICE_TO_CAL_MODEL[deviceModelId];
|
|
72
|
-
if (!calModel) return null;
|
|
73
|
-
|
|
74
|
-
const url = `${LEDGER_CAL_SERVICE_URL}/networks?chain_id=${chainId}&output=chain_id,descriptors,icons`;
|
|
75
|
-
const response = await fetchFn(url);
|
|
76
|
-
if (!response.ok) return null;
|
|
77
|
-
|
|
78
|
-
const networks = (await response.json()) as CalNetwork[];
|
|
79
|
-
const network = networks.find((entry) => entry.chain_id === chainId);
|
|
80
|
-
const descriptor = network?.descriptors?.[calModel];
|
|
81
|
-
const signature = descriptor?.signatures?.prod;
|
|
82
|
-
|
|
83
|
-
if (!(descriptor?.data && signature)) return null;
|
|
84
|
-
|
|
85
|
-
return { data: descriptor.data, icon: network?.icons?.[calModel], signature };
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function appendSignatureTlv(signature: string) {
|
|
89
|
-
return encodeTlv(TLV_TAG_DER_SIGNATURE, Buffer.from(signature, "hex")).toString("hex");
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function encodeTlv(tag: number, value: Buffer) {
|
|
93
|
-
return Buffer.concat([Buffer.from([tag, value.length]), value]);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export function encodeNetworkInfoPayload({ data, signature }: LedgerNetworkDescriptor) {
|
|
97
|
-
const tlv = Buffer.concat([
|
|
98
|
-
Buffer.from(data, "hex"),
|
|
99
|
-
encodeTlv(TLV_TAG_DER_SIGNATURE, Buffer.from(signature, "hex")),
|
|
100
|
-
]);
|
|
101
|
-
const length = Buffer.alloc(2);
|
|
102
|
-
length.writeUInt16BE(tlv.length, 0);
|
|
103
|
-
return Buffer.concat([length, tlv]);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
async function sendChunked(transport: Transport, p2: number, payload: Buffer) {
|
|
107
|
-
for (let offset = 0; offset < payload.length; offset += APDU_MAX_CHUNK_SIZE) {
|
|
108
|
-
const p1 = offset === 0 ? APDU_P1_FIRST_CHUNK : APDU_P1_FOLLOWING_CHUNK;
|
|
109
|
-
const chunk = payload.subarray(offset, offset + APDU_MAX_CHUNK_SIZE);
|
|
110
|
-
await transport.send(APDU_CLA, APDU_INS_PROVIDE_NETWORK_INFORMATION, p1, p2, chunk);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export async function provideLedgerNetworkInformation(transport: Transport, descriptor: LedgerNetworkDescriptor) {
|
|
115
|
-
const payload = encodeNetworkInfoPayload(descriptor);
|
|
116
|
-
await sendChunked(transport, APDU_P2_NETWORK_CONFIG, payload);
|
|
117
|
-
|
|
118
|
-
if (!descriptor.icon) return { iconAccepted: false };
|
|
119
|
-
|
|
120
|
-
try {
|
|
121
|
-
await sendChunked(transport, APDU_P2_NETWORK_ICON, Buffer.from(descriptor.icon, "hex"));
|
|
122
|
-
return { iconAccepted: true };
|
|
123
|
-
} catch {
|
|
124
|
-
await sendChunked(transport, APDU_P2_NETWORK_CONFIG, payload);
|
|
125
|
-
return { iconAccepted: false };
|
|
126
|
-
}
|
|
127
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import type Transport from "@ledgerhq/hw-transport";
|
|
2
|
-
import { type DerivationPathArray, LedgerErrorCode, NetworkDerivationPath, SwapKitError } from "@swapkit/helpers";
|
|
3
|
-
|
|
4
|
-
import { THORChainApp } from "../clients/thorchain/lib";
|
|
5
|
-
import { getLedgerTransport } from "../helpers/getLedgerTransport";
|
|
6
|
-
|
|
7
|
-
export abstract class CosmosLedgerInterface {
|
|
8
|
-
ledgerTimeout = 50000;
|
|
9
|
-
derivationPath: DerivationPathArray | string = NetworkDerivationPath.GAIA;
|
|
10
|
-
transport: any;
|
|
11
|
-
ledgerApp: any;
|
|
12
|
-
chain: "thor" | "cosmos" = "thor";
|
|
13
|
-
|
|
14
|
-
private readonly injectedTransport?: Transport;
|
|
15
|
-
|
|
16
|
-
constructor(transport?: Transport) {
|
|
17
|
-
this.injectedTransport = transport;
|
|
18
|
-
if (transport) this.transport = transport;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
checkOrCreateTransportAndLedger = async (forceReconnect = false) => {
|
|
22
|
-
if (!forceReconnect && this.transport && this.ledgerApp) return;
|
|
23
|
-
|
|
24
|
-
try {
|
|
25
|
-
// Consumer owns the lifecycle of an injected transport, so forceReconnect
|
|
26
|
-
// only refreshes ledgerApp — the transport itself stays as passed in.
|
|
27
|
-
const needsNewTransport = !this.transport || (forceReconnect && !this.injectedTransport);
|
|
28
|
-
if (needsNewTransport) {
|
|
29
|
-
this.transport = this.injectedTransport ?? (await getLedgerTransport());
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
switch (this.chain) {
|
|
33
|
-
case "thor": {
|
|
34
|
-
this.ledgerApp = forceReconnect || !this.ledgerApp ? new THORChainApp(this.transport) : this.ledgerApp;
|
|
35
|
-
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
case "cosmos": {
|
|
40
|
-
const CosmosApp = (await import("@ledgerhq/hw-app-cosmos")).default;
|
|
41
|
-
this.ledgerApp = forceReconnect || !this.ledgerApp ? new CosmosApp(this.transport) : this.ledgerApp;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return this.ledgerApp;
|
|
46
|
-
} catch (error: unknown) {
|
|
47
|
-
throw new SwapKitError("wallet_ledger_connection_error", error);
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
validateResponse = (errorCode: LedgerErrorCode, message?: string) => {
|
|
52
|
-
switch (errorCode) {
|
|
53
|
-
case LedgerErrorCode.NoError:
|
|
54
|
-
return;
|
|
55
|
-
|
|
56
|
-
case LedgerErrorCode.LockedDevice:
|
|
57
|
-
throw new SwapKitError("wallet_ledger_device_locked", { message: `Ledger is locked: ${message}` });
|
|
58
|
-
|
|
59
|
-
case LedgerErrorCode.TC_NotFound:
|
|
60
|
-
throw new SwapKitError("wallet_ledger_device_not_found");
|
|
61
|
-
|
|
62
|
-
default: {
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
}
|