@faremeter/wallet-ledger 0.16.0 → 0.17.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 CHANGED
@@ -1,4 +1,15 @@
1
1
  import { type ChainInfo } from "@faremeter/types/evm";
2
2
  import type { LedgerEvmWallet, UserInterface } from "./types.js";
3
+ /**
4
+ * Creates a Ledger hardware wallet interface for EVM chains.
5
+ *
6
+ * Connects to a Ledger device and returns a wallet that can sign
7
+ * transactions and EIP-712 typed data.
8
+ *
9
+ * @param ui - User interface for displaying prompts and messages.
10
+ * @param chain - EVM chain configuration.
11
+ * @param derivationPath - BIP-44 derivation path (e.g., "m/44'/60'/0'/0/0").
12
+ * @returns A Ledger EVM wallet interface.
13
+ */
3
14
  export declare function createLedgerEvmWallet(ui: UserInterface, chain: ChainInfo, derivationPath: string): Promise<LedgerEvmWallet>;
4
15
  //# sourceMappingURL=evm.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"evm.d.ts","sourceRoot":"","sources":["../../src/evm.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGtD,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE9D,wBAAsB,qBAAqB,CACzC,EAAE,EAAE,aAAa,EACjB,KAAK,EAAE,SAAS,EAChB,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,eAAe,CAAC,CAuJ1B"}
1
+ {"version":3,"file":"evm.d.ts","sourceRoot":"","sources":["../../src/evm.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGtD,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE9D;;;;;;;;;;GAUG;AACH,wBAAsB,qBAAqB,CACzC,EAAE,EAAE,aAAa,EACjB,KAAK,EAAE,SAAS,EAChB,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,eAAe,CAAC,CAuJ1B"}
package/dist/src/evm.js CHANGED
@@ -3,6 +3,17 @@ import Eth from "@ledgerhq/hw-app-eth/lib-es/Eth.js";
3
3
  import {} from "@faremeter/types/evm";
4
4
  import { type } from "arktype";
5
5
  import { createTransport } from "./transport.js";
6
+ /**
7
+ * Creates a Ledger hardware wallet interface for EVM chains.
8
+ *
9
+ * Connects to a Ledger device and returns a wallet that can sign
10
+ * transactions and EIP-712 typed data.
11
+ *
12
+ * @param ui - User interface for displaying prompts and messages.
13
+ * @param chain - EVM chain configuration.
14
+ * @param derivationPath - BIP-44 derivation path (e.g., "m/44'/60'/0'/0/0").
15
+ * @returns A Ledger EVM wallet interface.
16
+ */
6
17
  export async function createLedgerEvmWallet(ui, chain, derivationPath) {
7
18
  const transport = await createTransport();
8
19
  const eth = new Eth(transport);
@@ -1,3 +1,9 @@
1
+ /**
2
+ * @title Ledger Wallet Package
3
+ * @sidebarTitle Wallet Ledger
4
+ * @description Ledger hardware wallet integration for EVM and Solana
5
+ * @packageDocumentation
6
+ */
1
7
  export { createLedgerEvmWallet } from "./evm.js";
2
8
  export { createLedgerSolanaWallet } from "./solana.js";
3
9
  export { selectLedgerAccount } from "./utils.js";
@@ -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;AACnE,cAAc,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,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
@@ -1,3 +1,9 @@
1
+ /**
2
+ * @title Ledger Wallet Package
3
+ * @sidebarTitle Wallet Ledger
4
+ * @description Ledger hardware wallet integration for EVM and Solana
5
+ * @packageDocumentation
6
+ */
1
7
  export { createLedgerEvmWallet } from "./evm.js";
2
8
  export { createLedgerSolanaWallet } from "./solana.js";
3
9
  export { selectLedgerAccount } from "./utils.js";
@@ -1,7 +1,21 @@
1
+ /**
2
+ * Arguments for creating a readline-based user interface.
3
+ */
1
4
  export type createReadlineInterfaceArgs = {
5
+ /** Input stream (typically process.stdin). */
2
6
  stdin: NodeJS.ReadableStream;
7
+ /** Output stream (typically process.stdout). */
3
8
  stdout: NodeJS.WritableStream;
4
9
  };
10
+ /**
11
+ * Creates a readline-based user interface for Ledger interactions.
12
+ *
13
+ * Provides a simple terminal interface for displaying messages and
14
+ * prompting for user input during account selection.
15
+ *
16
+ * @param args - Input and output streams for the readline interface.
17
+ * @returns A UserInterface implementation using Node.js readline.
18
+ */
5
19
  export declare function createReadlineInterface(args: createReadlineInterfaceArgs): Promise<{
6
20
  message: (msg: string) => undefined;
7
21
  question: (q: string) => Promise<string>;
@@ -1 +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"}
1
+ {"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../src/interface.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,MAAM,2BAA2B,GAAG;IACxC,8CAA8C;IAC9C,KAAK,EAAE,MAAM,CAAC,cAAc,CAAC;IAC7B,gDAAgD;IAChD,MAAM,EAAE,MAAM,CAAC,cAAc,CAAC;CAC/B,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAsB,uBAAuB,CAC3C,IAAI,EAAE,2BAA2B;mBAShB,MAAM;kBACD,MAAM;;GAM7B"}
@@ -1,3 +1,12 @@
1
+ /**
2
+ * Creates a readline-based user interface for Ledger interactions.
3
+ *
4
+ * Provides a simple terminal interface for displaying messages and
5
+ * prompting for user input during account selection.
6
+ *
7
+ * @param args - Input and output streams for the readline interface.
8
+ * @returns A UserInterface implementation using Node.js readline.
9
+ */
1
10
  export async function createReadlineInterface(args) {
2
11
  const readline = await import("readline");
3
12
  const rl = readline.createInterface({
@@ -1,3 +1,13 @@
1
1
  import type { LedgerSolanaWallet } from "./types.js";
2
+ /**
3
+ * Creates a Ledger hardware wallet interface for Solana.
4
+ *
5
+ * Connects to a Ledger device and returns a wallet that can sign
6
+ * Solana versioned transactions.
7
+ *
8
+ * @param network - Solana network identifier (e.g., "mainnet-beta", "devnet").
9
+ * @param derivationPath - BIP-44 derivation path (e.g., "44'/501'/0'").
10
+ * @returns A Ledger Solana wallet interface.
11
+ */
2
12
  export declare function createLedgerSolanaWallet(network: string, derivationPath: string): Promise<LedgerSolanaWallet>;
3
13
  //# sourceMappingURL=solana.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"solana.d.ts","sourceRoot":"","sources":["../../src/solana.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAElD,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,kBAAkB,CAAC,CA0B7B"}
1
+ {"version":3,"file":"solana.d.ts","sourceRoot":"","sources":["../../src/solana.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAElD;;;;;;;;;GASG;AACH,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,kBAAkB,CAAC,CA6B7B"}
@@ -1,20 +1,32 @@
1
1
  import { PublicKey, VersionedTransaction } from "@solana/web3.js";
2
2
  import Solana from "@ledgerhq/hw-app-solana/lib-es/Solana.js";
3
3
  import { createTransport } from "./transport.js";
4
+ /**
5
+ * Creates a Ledger hardware wallet interface for Solana.
6
+ *
7
+ * Connects to a Ledger device and returns a wallet that can sign
8
+ * Solana versioned transactions.
9
+ *
10
+ * @param network - Solana network identifier (e.g., "mainnet-beta", "devnet").
11
+ * @param derivationPath - BIP-44 derivation path (e.g., "44'/501'/0'").
12
+ * @returns A Ledger Solana wallet interface.
13
+ */
4
14
  export async function createLedgerSolanaWallet(network, derivationPath) {
5
15
  const transport = await createTransport();
6
16
  const solana = new Solana(transport);
7
17
  const { address } = await solana.getAddress(derivationPath);
8
18
  const publicKey = new PublicKey(address);
19
+ const signTransaction = async (tx) => {
20
+ const message = tx.message.serialize();
21
+ const signature = await solana.signTransaction(derivationPath, Buffer.from(message));
22
+ tx.addSignature(publicKey, signature.signature);
23
+ return tx;
24
+ };
9
25
  return {
10
26
  network,
11
27
  publicKey,
12
- updateTransaction: async (tx) => {
13
- const message = tx.message.serialize();
14
- const signature = await solana.signTransaction(derivationPath, Buffer.from(message));
15
- tx.addSignature(publicKey, signature.signature);
16
- return tx;
17
- },
28
+ partiallySignTransaction: signTransaction,
29
+ updateTransaction: signTransaction,
18
30
  disconnect: async () => {
19
31
  await transport.close();
20
32
  },
@@ -2,6 +2,9 @@ import type { Hex, TransactionSerializable, TypedDataDefinition } from "viem";
2
2
  import { evm } from "@faremeter/types";
3
3
  import type { PublicKey, VersionedTransaction } from "@solana/web3.js";
4
4
  import type Transport from "@ledgerhq/hw-transport";
5
+ /**
6
+ * Ledger hardware wallet interface for EVM chains.
7
+ */
5
8
  export interface LedgerEvmWallet {
6
9
  chain: evm.ChainInfo;
7
10
  address: Hex;
@@ -9,9 +12,13 @@ export interface LedgerEvmWallet {
9
12
  signTypedData: (params: TypedDataDefinition) => Promise<Hex>;
10
13
  disconnect: () => Promise<void>;
11
14
  }
15
+ /**
16
+ * Ledger hardware wallet interface for Solana.
17
+ */
12
18
  export interface LedgerSolanaWallet {
13
19
  network: string;
14
20
  publicKey: PublicKey;
21
+ partiallySignTransaction: (tx: VersionedTransaction) => Promise<VersionedTransaction>;
15
22
  updateTransaction: (tx: VersionedTransaction) => Promise<VersionedTransaction>;
16
23
  disconnect: () => Promise<void>;
17
24
  }
@@ -19,9 +26,18 @@ export interface LedgerTransportWrapper {
19
26
  transport: Transport;
20
27
  close: () => Promise<void>;
21
28
  }
29
+ /**
30
+ * User interface abstraction for Ledger interactions.
31
+ *
32
+ * Used to display prompts and receive user input during
33
+ * device selection and account enumeration.
34
+ */
22
35
  export interface UserInterface {
36
+ /** Displays a message to the user. */
23
37
  message: (msg: string) => void;
38
+ /** Prompts the user for input and returns their response. */
24
39
  question: (prompt: string) => Promise<string>;
40
+ /** Closes the interface and releases resources. */
25
41
  close: () => Promise<void>;
26
42
  }
27
43
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,MAAM,MAAM,CAAC;AAC9E,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvE,OAAO,KAAK,SAAS,MAAM,wBAAwB,CAAC;AAEpD,MAAM,WAAW,eAAe;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B,KAAK,EAAE,GAAG,CAAC,SAAS,CAAC;IACrB,OAAO,EAAE,GAAG,CAAC;IACb,eAAe,EAAE,CAAC,EAAE,EAAE,uBAAuB,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;IAC/D,aAAa,EAAE,CAAC,MAAM,EAAE,mBAAmB,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;IAC7D,UAAU,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACjC;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,SAAS,CAAC;IACrB,wBAAwB,EAAE,CACxB,EAAE,EAAE,oBAAoB,KACrB,OAAO,CAAC,oBAAoB,CAAC,CAAC;IACnC,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;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC5B,sCAAsC;IACtC,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,6DAA6D;IAC7D,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IAC9C,mDAAmD;IACnD,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B"}
@@ -1,4 +1,15 @@
1
1
  import type { UserInterface } from "./types.js";
2
+ /**
3
+ * Interactively selects a Ledger account from the device.
4
+ *
5
+ * Enumerates accounts on the connected Ledger device and prompts the
6
+ * user to select one via the provided user interface.
7
+ *
8
+ * @param ui - User interface for displaying accounts and receiving selection.
9
+ * @param type - Account type to enumerate ("evm" or "solana").
10
+ * @param numAccounts - Number of accounts to scan (default: 5).
11
+ * @returns The selected account's derivation path and address, or null if selection cancelled.
12
+ */
2
13
  export declare function selectLedgerAccount(ui: UserInterface, type: "evm" | "solana", numAccounts?: number): Promise<{
3
14
  path: string;
4
15
  address: string;
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAU7C;;;;;;;;;;GAUG;AACH,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,6 +8,17 @@ function evmDerivationPath(index) {
8
8
  function solanaDerivationPath(index) {
9
9
  return `44'/501'/${index}'`;
10
10
  }
11
+ /**
12
+ * Interactively selects a Ledger account from the device.
13
+ *
14
+ * Enumerates accounts on the connected Ledger device and prompts the
15
+ * user to select one via the provided user interface.
16
+ *
17
+ * @param ui - User interface for displaying accounts and receiving selection.
18
+ * @param type - Account type to enumerate ("evm" or "solana").
19
+ * @param numAccounts - Number of accounts to scan (default: 5).
20
+ * @returns The selected account's derivation path and address, or null if selection cancelled.
21
+ */
11
22
  export async function selectLedgerAccount(ui, type, numAccounts = 5) {
12
23
  const isEvm = type === "evm";
13
24
  ui.message(`\nScanning first ${numAccounts} ${isEvm ? "Ethereum" : "Solana"} accounts...`);