@faremeter/wallet-ledger 0.1.2 → 0.5.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/src/evm.d.ts +2 -2
- package/dist/src/evm.d.ts.map +1 -1
- package/dist/src/evm.js +6 -6
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -0
- package/dist/src/interface.d.ts +10 -0
- package/dist/src/interface.d.ts.map +1 -0
- package/dist/src/interface.js +14 -0
- package/dist/src/logger.d.ts +2 -0
- package/dist/src/logger.d.ts.map +1 -0
- package/dist/src/logger.js +2 -0
- package/dist/src/transport.d.ts.map +1 -1
- package/dist/src/transport.js +2 -1
- package/dist/src/types.d.ts +5 -0
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/utils.d.ts +2 -1
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +6 -14
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -7
- package/src/evm.ts +7 -8
- package/src/index.ts +1 -0
- package/src/interface.ts +25 -0
- package/src/logger.ts +3 -0
- package/src/transport.ts +2 -1
- package/src/types.ts +6 -0
- package/src/utils.ts +7 -14
package/dist/src/evm.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { LedgerEvmWallet } from "./types.js";
|
|
2
|
-
export declare function createLedgerEvmWallet(network: string, derivationPath: string): Promise<LedgerEvmWallet>;
|
|
1
|
+
import type { LedgerEvmWallet, UserInterface } from "./types.js";
|
|
2
|
+
export declare function createLedgerEvmWallet(ui: UserInterface, network: string, derivationPath: string): Promise<LedgerEvmWallet>;
|
|
3
3
|
//# sourceMappingURL=evm.d.ts.map
|
package/dist/src/evm.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evm.d.ts","sourceRoot":"","sources":["../../src/evm.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AA+
|
|
1
|
+
{"version":3,"file":"evm.d.ts","sourceRoot":"","sources":["../../src/evm.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AA+B9D,wBAAsB,qBAAqB,CACzC,EAAE,EAAE,aAAa,EACjB,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,eAAe,CAAC,CAmK1B"}
|
package/dist/src/evm.js
CHANGED
|
@@ -26,7 +26,7 @@ const NETWORK_CONFIGS = new Map([
|
|
|
26
26
|
},
|
|
27
27
|
],
|
|
28
28
|
]);
|
|
29
|
-
export async function createLedgerEvmWallet(network, derivationPath) {
|
|
29
|
+
export async function createLedgerEvmWallet(ui, network, derivationPath) {
|
|
30
30
|
const config = NETWORK_CONFIGS.get(network);
|
|
31
31
|
if (!config) {
|
|
32
32
|
throw new Error(`Unsupported network: ${network}. Supported networks: ${Array.from(NETWORK_CONFIGS.keys()).join(", ")}`);
|
|
@@ -118,16 +118,16 @@ export async function createLedgerEvmWallet(network, derivationPath) {
|
|
|
118
118
|
primaryType,
|
|
119
119
|
types,
|
|
120
120
|
});
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
121
|
+
ui.message("\nEIP-712 hashes calculated:");
|
|
122
|
+
ui.message(` Domain separator: ${domainSeparator}`);
|
|
123
|
+
ui.message(` Message hash: ${messageHash}`);
|
|
124
|
+
ui.message(`\nPlease approve the transaction on your Ledger device...`);
|
|
125
125
|
const result = await eth.signEIP712HashedMessage(derivationPath, domainSeparator.slice(2), messageHash.slice(2));
|
|
126
126
|
const signature = `0x${result.r}${result.s}${result.v.toString(16).padStart(2, "0")}`;
|
|
127
127
|
return signature;
|
|
128
128
|
}
|
|
129
129
|
catch (error) {
|
|
130
|
-
|
|
130
|
+
ui.message(`EIP-712 signing failed: ${error}`);
|
|
131
131
|
throw error;
|
|
132
132
|
}
|
|
133
133
|
},
|
package/dist/src/index.d.ts
CHANGED
|
@@ -2,4 +2,5 @@ export { createLedgerEvmWallet } from "./evm.js";
|
|
|
2
2
|
export { createLedgerSolanaWallet } from "./solana.js";
|
|
3
3
|
export { selectLedgerAccount } from "./utils.js";
|
|
4
4
|
export type { LedgerEvmWallet, LedgerSolanaWallet } from "./types.js";
|
|
5
|
+
export * from "./interface.js";
|
|
5
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,OAAO,CAAC;AAC9C,OAAO,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAC9C,YAAY,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,OAAO,CAAC;AAC9C,OAAO,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAC9C,YAAY,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AACnE,cAAc,aAAa,CAAC"}
|
package/dist/src/index.js
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type createReadlineInterfaceArgs = {
|
|
2
|
+
stdin: NodeJS.ReadableStream;
|
|
3
|
+
stdout: NodeJS.WritableStream;
|
|
4
|
+
};
|
|
5
|
+
export declare function createReadlineInterface(args: createReadlineInterfaceArgs): Promise<{
|
|
6
|
+
message: (msg: string) => undefined;
|
|
7
|
+
question: (q: string) => Promise<string>;
|
|
8
|
+
close: () => Promise<void>;
|
|
9
|
+
}>;
|
|
10
|
+
//# sourceMappingURL=interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../src/interface.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,2BAA2B,GAAG;IACxC,KAAK,EAAE,MAAM,CAAC,cAAc,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC,cAAc,CAAC;CAC/B,CAAC;AAEF,wBAAsB,uBAAuB,CAC3C,IAAI,EAAE,2BAA2B;mBAShB,MAAM;kBACD,MAAM;;GAM7B"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export async function createReadlineInterface(args) {
|
|
2
|
+
const readline = await import("readline");
|
|
3
|
+
const rl = readline.createInterface({
|
|
4
|
+
input: args.stdin,
|
|
5
|
+
output: args.stdout,
|
|
6
|
+
});
|
|
7
|
+
return {
|
|
8
|
+
message: (msg) => void args.stdout.write(msg + "\n"),
|
|
9
|
+
question: async (q) => new Promise((resolve) => {
|
|
10
|
+
rl.question(q, resolve);
|
|
11
|
+
}),
|
|
12
|
+
close: async () => rl.close(),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,MAAM,mCAA4C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../src/transport.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../src/transport.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,SAAS,MAAM,wBAAwB,CAAC;AAcpD,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,CAoB1D;AAED,wBAAsB,eAAe,CAAC,UAAU,SAAI,GAAG,OAAO,CAAC,SAAS,CAAC,CAyCxE"}
|
package/dist/src/transport.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { logger } from "./logger.js";
|
|
1
2
|
const LEDGER_ERRORS = {
|
|
2
3
|
"0x5515": "Ledger is locked. Please unlock your device.",
|
|
3
4
|
"0x6511": "Please unlock your Ledger and open the correct app.",
|
|
@@ -45,7 +46,7 @@ export async function createTransport(maxRetries = 3) {
|
|
|
45
46
|
const errorMessage = translatedError.message;
|
|
46
47
|
if (i < maxRetries - 1 &&
|
|
47
48
|
(errorMessage.includes("USB") || errorMessage.includes("device"))) {
|
|
48
|
-
|
|
49
|
+
logger.warning(`USB connection attempt ${i + 1} failed, retrying...`);
|
|
49
50
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
50
51
|
continue;
|
|
51
52
|
}
|
package/dist/src/types.d.ts
CHANGED
|
@@ -19,4 +19,9 @@ export interface LedgerTransportWrapper {
|
|
|
19
19
|
transport: Transport;
|
|
20
20
|
close: () => Promise<void>;
|
|
21
21
|
}
|
|
22
|
+
export interface UserInterface {
|
|
23
|
+
message: (msg: string) => void;
|
|
24
|
+
question: (prompt: string) => Promise<string>;
|
|
25
|
+
close: () => Promise<void>;
|
|
26
|
+
}
|
|
22
27
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/src/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,GAAG,EACH,YAAY,EACZ,uBAAuB,EACvB,mBAAmB,EACpB,MAAM,MAAM,CAAC;AACd,OAAO,KAAK,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvE,OAAO,KAAK,SAAS,MAAM,wBAAwB,CAAC;AAEpD,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,GAAG,CAAC;IACb,MAAM,EAA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;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,SAAS,CAAC;IACrB,iBAAiB,EAAE,CACjB,EAAE,EAAE,oBAAoB,KACrB,OAAO,CAAC,oBAAoB,CAAC,CAAC;IACnC,UAAU,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACjC;AAED,MAAM,WAAW,sBAAsB;IACrC,SAAS,EAAE,SAAS,CAAC;IACrB,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IAC9C,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B"}
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import type { UserInterface } from "./types.js";
|
|
2
|
+
export declare function selectLedgerAccount(ui: UserInterface, type: "evm" | "solana", numAccounts?: number): Promise<{
|
|
2
3
|
path: string;
|
|
3
4
|
address: string;
|
|
4
5
|
} | null>;
|
package/dist/src/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAU7C,wBAAsB,mBAAmB,CACvC,EAAE,EAAE,aAAa,EACjB,IAAI,EAAE,KAAK,GAAG,QAAQ,EACtB,WAAW,SAAI,GACd,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC,CAyDnD"}
|
package/dist/src/utils.js
CHANGED
|
@@ -8,9 +8,9 @@ function evmDerivationPath(index) {
|
|
|
8
8
|
function solanaDerivationPath(index) {
|
|
9
9
|
return `44'/501'/${index}'`;
|
|
10
10
|
}
|
|
11
|
-
export async function selectLedgerAccount(type, numAccounts = 5) {
|
|
11
|
+
export async function selectLedgerAccount(ui, type, numAccounts = 5) {
|
|
12
12
|
const isEvm = type === "evm";
|
|
13
|
-
|
|
13
|
+
ui.message(`\nScanning first ${numAccounts} ${isEvm ? "Ethereum" : "Solana"} accounts...`);
|
|
14
14
|
const accounts = [];
|
|
15
15
|
const transport = await createTransport();
|
|
16
16
|
try {
|
|
@@ -30,7 +30,7 @@ export async function selectLedgerAccount(type, numAccounts = 5) {
|
|
|
30
30
|
? address
|
|
31
31
|
: `0x${address}`;
|
|
32
32
|
accounts.push({ path, address: normalizedAddress });
|
|
33
|
-
|
|
33
|
+
ui.message(`${i + 1}. ${normalizedAddress}`);
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
else {
|
|
@@ -47,25 +47,17 @@ export async function selectLedgerAccount(type, numAccounts = 5) {
|
|
|
47
47
|
const publicKey = new PublicKey(result.address);
|
|
48
48
|
const address = publicKey.toBase58();
|
|
49
49
|
accounts.push({ path, address });
|
|
50
|
-
|
|
50
|
+
ui.message(`${i + 1}. ${address}`);
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
finally {
|
|
55
55
|
await transport.close();
|
|
56
56
|
}
|
|
57
|
-
const
|
|
58
|
-
const rl = readline.createInterface({
|
|
59
|
-
input: process.stdin,
|
|
60
|
-
output: process.stdout,
|
|
61
|
-
});
|
|
62
|
-
const selection = await new Promise((resolve) => {
|
|
63
|
-
rl.question(`\nSelect account (1-${numAccounts}): `, resolve);
|
|
64
|
-
});
|
|
65
|
-
rl.close();
|
|
57
|
+
const selection = await ui.question(`\nSelect account (1-${numAccounts}): `);
|
|
66
58
|
const index = parseInt(selection) - 1;
|
|
67
59
|
if (index < 0 || index >= accounts.length) {
|
|
68
|
-
|
|
60
|
+
ui.message("Invalid selection");
|
|
69
61
|
return null;
|
|
70
62
|
}
|
|
71
63
|
return accounts[index] ?? null;
|