@xrpl-wallet-kit/adapter-ledger 0.1.23 → 0.2.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/README.md CHANGED
@@ -31,8 +31,8 @@ const kit = createWalletKit({
31
31
  ## Runtime Notes
32
32
 
33
33
  - Requires a browser with WebHID or WebUSB support.
34
- - Requires a connected, unlocked Ledger device with XRP installed. During explicit connection, `autoOpenApp` requests XRP directly on the hardware (default `true`); confirm on the device when prompted. It never launches or requires Ledger Live desktop. This option is available since 0.1.23.
35
- - Already-open XRP is left alone. Another device app is closed before requesting XRP. App switches can disconnect USB temporarily: reconnection attempts use only the originally selected device handle, never another authorized Ledger. If browser permission/re-enumeration prevents recovery, open XRP manually and select the device again.
34
+ - Requires a connected, unlocked Ledger with the selected app installed. During explicit connect, `autoOpenApp` (default `true`) requests XRP for XRPL or XAH (Xahau) for Xahau directly on the hardware; confirm on the device when prompted. It never launches Ledger Live desktop or installs an app. XRP auto-opening is available since 0.1.23; XAH auto-opening is unreleased.
35
+ - An already-open matching app is left alone. Another device app is closed before requesting the selected app. App switches can disconnect USB temporarily: reconnection attempts use only the originally selected device handle, never another authorized Ledger. If recovery or OS app launch is unsupported, open the selected app manually and select the device again. No automatic XAH-to-XRP fallback occurs.
36
36
  - Hardware wallets are explicit user-presence devices. `restoreSession()` returns `null` and does not silently reconnect after refresh.
37
37
  - Default derivation path is `44'/144'/0'/0/0`.
38
38
  - `signTransaction()` signs without submit.
@@ -61,6 +61,14 @@ createLedgerAdapter({
61
61
 
62
62
  Use `connectLedger` in tests or custom integrations to inject a prebuilt Ledger session.
63
63
 
64
+ For controlled Xahau compatibility testing with the XRP app, explicitly use
65
+ `deviceApp: "XRP"`; default Xahau connections request `"XAH"`. Use
66
+ `autoOpenApp: false` to manage the app manually. Connection metadata records
67
+ `requestedDeviceApp`, not a claim of independently verified device app identity.
68
+ Default client Ledger remains XRPL-only until explicitly opted into Xahau.
69
+ Launching XAH successfully does not establish support for every transaction,
70
+ Hook field, device or app version, and never enables blind signing.
71
+
64
72
  ## Testing
65
73
 
66
74
  On 2026-10-13, the maintainer reported that documented Ledger transaction
@@ -4,6 +4,7 @@ export interface LedgerAppTransport {
4
4
  send?(cla: number, ins: number, p1: number, p2: number, data?: Buffer): Promise<Uint8Array>;
5
5
  }
6
6
  interface OpenAppOptions {
7
+ app?: "XRP" | "XAH";
7
8
  signal?: AbortSignal;
8
9
  timeoutMs: number;
9
10
  assertCurrent(): void;
@@ -12,6 +13,7 @@ interface OpenAppOptions {
12
13
  reopen(transport: LedgerAppTransport): Promise<LedgerAppTransport>;
13
14
  }
14
15
  /** Ledger OS APDUs, not Ledger Live: B0/01 query, B0/A7 close, E0/D8 open. */
15
- export declare function ensureLedgerXrpApp(initial: LedgerAppTransport, options: OpenAppOptions): Promise<LedgerAppTransport>;
16
+ export declare function ensureLedgerApp(initial: LedgerAppTransport, options: OpenAppOptions): Promise<LedgerAppTransport>;
17
+ export declare const ensureLedgerXrpApp: (initial: LedgerAppTransport, options: OpenAppOptions) => Promise<LedgerAppTransport>;
16
18
  export {};
17
19
  //# sourceMappingURL=device-app.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"device-app.d.ts","sourceRoot":"","sources":["../src/device-app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,MAAM,WAAW,kBAAkB;IACjC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,IAAI,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CAC7F;AAED,UAAU,cAAc;IACtB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,IAAI,IAAI,CAAC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
1
  import { Buffer } from "buffer";
2
2
  import { waitForWalletRequest, WalletKitError, WalletKitErrorCode } from "@xrpl-wallet-kit/core";
3
- const manual = () => new Error("Open the XRP app on your Ledger device, then connect again. Ledger Live desktop is not required.");
3
+ const manual = (app) => new Error(`Open ${app} on Ledger. Reconnect.`);
4
4
  const status = (error) => error?.statusCode;
5
5
  const unsupported = (error) => [0x6d00, 0x6e00, 0x6511, 0x650f, 0x6807].includes(status(error) ?? 0);
6
6
  const disconnected = (error) => status(error) === undefined && /disconnect|device.*lost|device.*not.*found/i.test(String(error));
7
7
  const isDashboard = (name) => ["BOLOS", "OLOS", "OLOS\0", "DASHBOARD"].includes(name);
8
- function appName(response) {
8
+ function appName(response, target) {
9
9
  const length = response[1];
10
10
  if (response[0] !== 1 || !length || length + 4 > response.length)
11
- throw manual();
11
+ throw manual(target);
12
12
  return Buffer.from(response.subarray(2, length + 2)).toString("ascii").toUpperCase();
13
13
  }
14
14
  /** Ledger OS APDUs, not Ledger Live: B0/01 query, B0/A7 close, E0/D8 open. */
15
- export async function ensureLedgerXrpApp(initial, options) {
15
+ export async function ensureLedgerApp(initial, options) {
16
+ const target = options.app ?? "XRP";
16
17
  if (!initial.send)
17
18
  return initial;
18
19
  let transport = initial;
@@ -22,7 +23,7 @@ export async function ensureLedgerXrpApp(initial, options) {
22
23
  if (options.signal?.aborted)
23
24
  throw new WalletKitError(WalletKitErrorCode.REQUEST_CANCELLED, "Ledger connection cancelled.");
24
25
  if (Date.now() >= deadline)
25
- throw new WalletKitError(WalletKitErrorCode.REQUEST_TIMEOUT, "Ledger app opening timed out. Check your Ledger device.");
26
+ throw new WalletKitError(WalletKitErrorCode.REQUEST_TIMEOUT, "Ledger timed out. Check device.");
26
27
  };
27
28
  const bounded = async (operation) => {
28
29
  active();
@@ -53,7 +54,7 @@ export async function ensureLedgerXrpApp(initial, options) {
53
54
  while (true) {
54
55
  active();
55
56
  try {
56
- const name = appName(await send(0xb0, 0x01));
57
+ const name = appName(await send(0xb0, 0x01), target);
57
58
  if (name === expected || expected === "BOLOS" && isDashboard(name))
58
59
  return;
59
60
  }
@@ -72,21 +73,21 @@ export async function ensureLedgerXrpApp(initial, options) {
72
73
  }
73
74
  }
74
75
  if (Date.now() >= readyDeadline)
75
- throw manual();
76
+ throw manual(target);
76
77
  await bounded(() => new Promise(resolve => setTimeout(resolve, 250)));
77
78
  }
78
79
  };
79
80
  let name;
80
81
  try {
81
- name = appName(await send(0xb0, 0x01));
82
+ name = appName(await send(0xb0, 0x01), target);
82
83
  }
83
84
  catch (error) {
84
- // Older apps may lack the OS query. Preserve the existing XRP connection path.
85
+ // Older apps may lack the OS query. Let the selected app's address API report readiness.
85
86
  if (unsupported(error))
86
87
  return initial;
87
88
  throw error;
88
89
  }
89
- if (name === "XRP")
90
+ if (name === target)
90
91
  return transport;
91
92
  options.onOpening();
92
93
  const switchApp = async (cla, ins, data) => {
@@ -95,7 +96,7 @@ export async function ensureLedgerXrpApp(initial, options) {
95
96
  }
96
97
  catch (error) {
97
98
  if (unsupported(error))
98
- throw manual();
99
+ throw manual(target);
99
100
  if (!disconnected(error))
100
101
  throw error; // Never retry a rejection or locked-device error.
101
102
  }
@@ -104,7 +105,8 @@ export async function ensureLedgerXrpApp(initial, options) {
104
105
  await switchApp(0xb0, 0xa7);
105
106
  await waitForApp("BOLOS");
106
107
  }
107
- await switchApp(0xe0, 0xd8, Buffer.from("XRP", "ascii"));
108
- await waitForApp("XRP");
108
+ await switchApp(0xe0, 0xd8, Buffer.from(target, "ascii"));
109
+ await waitForApp(target);
109
110
  return transport;
110
111
  }
112
+ export const ensureLedgerXrpApp = (initial, options) => ensureLedgerApp(initial, { ...options, app: "XRP" });
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { BaseWalletAdapter } from "@xrpl-wallet-kit/core";
2
+ import type { WalletChainFilter } from "@xrpl-wallet-kit/core";
2
3
  import type { ConnectOptions, ConnectResult, SignAndSubmitRequest, SignTransactionRequest, SignTransactionResult, TxResult, WalletCapabilities, WalletMetadata, WalletSession } from "@xrpl-wallet-kit/core";
3
4
  export declare const LEDGER_ICON = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyOCIgaGVpZ2h0PSIyOCIgZmlsbD0ibm9uZSI+PHBhdGggZmlsbD0iIzAwMCIgZD0iTTAgMGgyOHYyOEgweiIvPjxwYXRoIGZpbGw9IiNmZmYiIGZpbGwtcnVsZT0iZXZlbm9kZCIgZD0iTTExLjY1IDQuNEg0LjRWOWgxLjFWNS41bDYuMTUtLjA0VjQuNFptLjA1IDUuOTV2Ny4yNWg0LjZ2LTEuMWgtMy41bC0uMDQtNi4xNUgxMS43Wk00LjQgMjMuNmg3LjI1di0xLjA2TDUuNSAyMi41VjE5SDQuNHY0LjZaTTE2LjM1IDQuNGg3LjI1VjloLTEuMVY1LjVsLTYuMTUtLjA0VjQuNFptNy4yNSAxOS4yaC03LjI1di0xLjA2bDYuMTUtLjA0VjE5aDEuMXY0LjZaIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiLz48L3N2Zz4=";
4
5
  export declare enum LedgerDeviceState {
@@ -10,13 +11,16 @@ export declare enum LedgerDeviceState {
10
11
  UNKNOWN = "UNKNOWN"
11
12
  }
12
13
  export interface LedgerAdapterOptions {
14
+ supportedChains?: WalletChainFilter;
13
15
  connectLedger?: () => Promise<LedgerSession>;
14
16
  accountIndex?: number;
15
17
  derivationPath?: string;
16
18
  preferWebHID?: boolean;
17
19
  timeout?: number;
18
- /** Request XRP on the hardware device during explicit connect. Default true. */
20
+ /** Request the chain's app on the hardware device during explicit connect. Default true. */
19
21
  autoOpenApp?: boolean;
22
+ /** Defaults to XAH on Xahau, XRP on XRPL. Override only for controlled device compatibility testing. */
23
+ deviceApp?: "XRP" | "XAH";
20
24
  onDeviceState?: (state: LedgerDeviceState) => void;
21
25
  icon?: string;
22
26
  }
@@ -52,6 +56,7 @@ export declare class LedgerAdapter extends BaseWalletAdapter {
52
56
  private derivationPath;
53
57
  private connectionGeneration;
54
58
  private connectionAbort?;
59
+ private protocolContext?;
55
60
  constructor(options?: LedgerAdapterOptions);
56
61
  isAvailable(): Promise<boolean>;
57
62
  connect(options: ConnectOptions): Promise<ConnectResult>;
@@ -73,6 +78,7 @@ export declare class LedgerAdapter extends BaseWalletAdapter {
73
78
  private mapSigningError;
74
79
  private withTimeout;
75
80
  private isMultisignTransaction;
81
+ private getDeviceApp;
76
82
  }
77
83
  export declare function createLedgerAdapter(options?: LedgerAdapterOptions): LedgerAdapter;
78
84
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAuF,MAAM,uBAAuB,CAAC;AAG/I,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,oBAAoB,EACpB,sBAAsB,EACtB,qBAAqB,EACrB,QAAQ,EACR,kBAAkB,EAClB,cAAc,EACd,aAAa,EAEd,MAAM,uBAAuB,CAAC;AAE/B,eAAO,MAAM,WAAW,uiBAC8gB,CAAC;AAYviB,oBAAY,iBAAiB;IAC3B,aAAa,kBAAkB;IAC/B,MAAM,WAAW;IACjB,YAAY,iBAAiB;IAC7B,WAAW,gBAAgB;IAC3B,KAAK,UAAU;IACf,OAAO,YAAY;CACpB;AAED,MAAM,WAAW,oBAAoB;IACnC,aAAa,CAAC,EAAE,MAAM,OAAO,CAAC,aAAa,CAAC,CAAC;IAC7C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gFAAgF;IAChF,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,IAAI,CAAC;IACnD,IAAI,CAAC,EAAE,M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dapter, createWalletError, validateMultisignTransaction, WalletKitError, WalletKitErrorCode } from "@xrpl-wallet-kit/core";
2
- import { ensureLedgerXrpApp } from "./device-app.js";
1
+ import { BaseWalletAdapter, createWalletError, validateMultisignTransaction, WalletKitError, WalletKitErrorCode, getProviderHint, isLegacyNetwork, adapterSupportsNetwork, prepareProtocolTransaction } from "@xrpl-wallet-kit/core";
2
+ import { ensureLedgerApp } from "./device-app.js";
3
3
  export const LEDGER_ICON = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyOCIgaGVpZ2h0PSIyOCIgZmlsbD0ibm9uZSI+PHBhdGggZmlsbD0iIzAwMCIgZD0iTTAgMGgyOHYyOEgweiIvPjxwYXRoIGZpbGw9IiNmZmYiIGZpbGwtcnVsZT0iZXZlbm9kZCIgZD0iTTExLjY1IDQuNEg0LjRWOWgxLjFWNS41bDYuMTUtLjA0VjQuNFptLjA1IDUuOTV2Ny4yNWg0LjZ2LTEuMWgtMy41bC0uMDQtNi4xNUgxMS43Wk00LjQgMjMuNmg3LjI1di0xLjA2TDUuNSAyMi41VjE5SDQuNHY0LjZaTTE2LjM1IDQuNGg3LjI1VjloLTEuMVY1LjVsLTYuMTUtLjA0VjQuNFptNy4yNSAxOS4yaC03LjI1di0xLjA2bDYuMTUtLjA0VjE5aDEuMXY0LjZaIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiLz48L3N2Zz4=";
4
4
  const DEFAULT_TIMEOUT = 60000;
5
5
  const DEFAULT_ACCOUNT_INDEX = 0;
@@ -24,6 +24,10 @@ export class LedgerAdapter extends BaseWalletAdapter {
24
24
  signAndSubmit: true
25
25
  };
26
26
  this.connectionGeneration = 0;
27
+ if (options.supportedChains) {
28
+ this.adapterApiVersion = "1.2";
29
+ this.capabilities.details = { supportedChains: structuredClone(options.supportedChains), transactionModes: ["sign-only", "sign-and-submit"] };
30
+ }
27
31
  this.derivationPath = options.derivationPath ?? getDerivationPath(options.accountIndex ?? DEFAULT_ACCOUNT_INDEX);
28
32
  this.metadata = {
29
33
  id: "ledger",
@@ -38,6 +42,13 @@ export class LedgerAdapter extends BaseWalletAdapter {
38
42
  return getLedgerBrowserSupport().supported;
39
43
  }
40
44
  async connect(options) {
45
+ if (options.network && !adapterSupportsNetwork(this, options.network))
46
+ throw createWalletError.networkNotSupported("Ledger", options.network.id);
47
+ if (options.network && !isLegacyNetwork(options.network) && !options.protocolContext)
48
+ throw createWalletError.networkNotSupported("Ledger (runtime required)", options.network.id);
49
+ this.protocolContext = options.network && !isLegacyNetwork(options.network) ? options.protocolContext : undefined;
50
+ if (options.network && !isLegacyNetwork(options.network))
51
+ getProviderHint(options.network, "ledgerApp");
41
52
  this.connectionAbort?.abort();
42
53
  const controller = new AbortController();
43
54
  this.connectionAbort = controller;
@@ -75,7 +86,8 @@ export class LedgerAdapter extends BaseWalletAdapter {
75
86
  connectedAt: Date.now(),
76
87
  metadata: {
77
88
  derivationPath: this.session.derivationPath ?? this.derivationPath,
78
- appVersion: this.session.appVersion
89
+ appVersion: this.session.appVersion,
90
+ requestedDeviceApp: this.getDeviceApp()
79
91
  }
80
92
  }
81
93
  };
@@ -96,6 +108,7 @@ export class LedgerAdapter extends BaseWalletAdapter {
96
108
  return null;
97
109
  }
98
110
  async disconnect() {
111
+ this.protocolContext = undefined;
99
112
  this.connectionAbort?.abort();
100
113
  this.connectionGeneration++;
101
114
  this.session = undefined;
@@ -103,6 +116,11 @@ export class LedgerAdapter extends BaseWalletAdapter {
103
116
  await this.cleanup();
104
117
  }
105
118
  async signAndSubmit(request) {
119
+ const context = this.protocolContext;
120
+ if (context) {
121
+ const result = await this.signTransaction(request);
122
+ return request.submit === false ? { ...result, status: "signed" } : context.protocol.submit(result.txBlob, context.network, request);
123
+ }
106
124
  if (!this.session)
107
125
  throw createWalletError.notConnected();
108
126
  if (this.isMultisignTransaction(request.txJson)) {
@@ -123,6 +141,33 @@ export class LedgerAdapter extends BaseWalletAdapter {
123
141
  async signTransaction(request) {
124
142
  if (!this.session)
125
143
  throw createWalletError.notConnected();
144
+ const context = this.protocolContext;
145
+ if (context) {
146
+ const generation = this.connectionGeneration;
147
+ const session = this.session;
148
+ const account = { address: session.address, publicKey: session.publicKey, network: context.network };
149
+ const tx = await prepareProtocolTransaction(context, request, account);
150
+ const current = () => {
151
+ if (generation !== this.connectionGeneration || this.session !== session || request.signal?.aborted)
152
+ throw createWalletError.notConnected();
153
+ };
154
+ current();
155
+ let blob;
156
+ if (this.xrp) {
157
+ const signature = await this.signOnDevice(tx, context.protocol.encode(tx), "Confirm Xahau transaction on Ledger.");
158
+ current();
159
+ blob = context.protocol.encode({ ...tx, TxnSignature: signature.toUpperCase() });
160
+ }
161
+ else
162
+ blob = (await session.signTransaction(tx, false)).txBlob;
163
+ current();
164
+ if (!blob)
165
+ throw createWalletError.signFailed(new Error("Ledger returned no signed blob"));
166
+ const verified = context.protocol.verify(blob, tx, account, context.network, request);
167
+ await context.protocol.prepare(tx, account, context.network, request);
168
+ current();
169
+ return { txBlob: verified.txBlob, signed: true, raw: { hash: verified.hash, appVersion: session.appVersion } };
170
+ }
126
171
  const multisign = this.isMultisignTransaction(request.txJson);
127
172
  const result = multisign
128
173
  ? await this.signMultisignTransaction(request.txJson)
@@ -153,7 +198,7 @@ export class LedgerAdapter extends BaseWalletAdapter {
153
198
  if (generation !== this.connectionGeneration)
154
199
  throw createWalletError.notConnected();
155
200
  const path = getDerivationPath(index);
156
- const account = await this.withTimeout(xrp.getAddress(path, false, false), "Ledger account lookup timeout. Please check your Ledger device.");
201
+ const account = await this.withTimeout(xrp.getAddress(path, false, false), "Ledger lookup timed out. Check device.");
157
202
  if (generation !== this.connectionGeneration)
158
203
  throw createWalletError.notConnected();
159
204
  accounts.push({
@@ -185,7 +230,8 @@ export class LedgerAdapter extends BaseWalletAdapter {
185
230
  };
186
231
  assertCurrent();
187
232
  if (this.options.autoOpenApp !== false) {
188
- transport = await ensureLedgerXrpApp(transport, {
233
+ transport = await ensureLedgerApp(transport, {
234
+ app: this.getDeviceApp(),
189
235
  signal: options.signal, timeoutMs: options.timeoutMs ?? this.options.timeout ?? DEFAULT_TIMEOUT, assertCurrent,
190
236
  onOpening: () => {
191
237
  this.options.onDeviceState?.(LedgerDeviceState.OPENING_APP);
@@ -198,9 +244,9 @@ export class LedgerAdapter extends BaseWalletAdapter {
198
244
  assertCurrent();
199
245
  const Xrp = await loadLedgerXrpApp();
200
246
  const xrp = new Xrp(transport);
201
- const account = await this.withTimeout(xrp.getAddress(this.derivationPath, false, false), "Ledger connection timeout. Please check your Ledger device.");
247
+ const account = await this.withTimeout(xrp.getAddress(this.derivationPath, false, false), "Ledger timed out. Check device.");
202
248
  if (!account.address)
203
- throw new Error("Ledger did not return an XRPL address");
249
+ throw new Error("Ledger did not return an address");
204
250
  // App version is diagnostic only; older apps may not implement this APDU.
205
251
  let appVersion;
206
252
  try {
@@ -236,14 +282,14 @@ export class LedgerAdapter extends BaseWalletAdapter {
236
282
  async reopenSameDevice(previous) {
237
283
  const native = previous;
238
284
  if (!native.device || !native.constructor.open)
239
- throw new Error("Open XRP on your Ledger device and select it again in the browser.");
285
+ throw new Error(`Open ${this.getDeviceApp()}. Reselect Ledger.`);
240
286
  return native.constructor.open(native.device);
241
287
  }
242
288
  async signWithDefaultLedger(tx, submit = true) {
243
289
  if (!this.xrp || !this.session)
244
290
  throw createWalletError.notConnected();
245
291
  if (!this.network)
246
- throw createWalletError.connectionFailed(this.metadata.name, new Error("XRPL network is required for Ledger signing"));
292
+ throw createWalletError.connectionFailed(this.metadata.name, new Error("Select a network for Ledger signing"));
247
293
  if (this.isMultisignTransaction(tx)) {
248
294
  throw createWalletError.unsupportedMethod("XRPL multisigning through the single-sign path", this.metadata.name);
249
295
  }
@@ -279,7 +325,7 @@ export class LedgerAdapter extends BaseWalletAdapter {
279
325
  txForSigning.SigningPubKey = publicKey.toUpperCase();
280
326
  const signingBlob = encode(txForSigning).toUpperCase();
281
327
  assertCurrent();
282
- const signature = await this.signOnDevice(txForSigning, signingBlob, "Ledger signing timeout. Please confirm the transaction on your Ledger device.");
328
+ const signature = await this.signOnDevice(txForSigning, signingBlob, "Signing timed out. Check Ledger.");
283
329
  assertCurrent();
284
330
  this.verifyDeviceSignature(encodeForSigning(txForSigning), signature, publicKey, verifyKeypairSignature);
285
331
  const signedTx = {
@@ -322,7 +368,7 @@ export class LedgerAdapter extends BaseWalletAdapter {
322
368
  if (!this.xrp || !this.session)
323
369
  throw createWalletError.notConnected();
324
370
  if (!this.network)
325
- throw createWalletError.connectionFailed(this.metadata.name, new Error("XRPL network is required for Ledger signing"));
371
+ throw createWalletError.connectionFailed(this.metadata.name, new Error("Select a network for Ledger signing"));
326
372
  const session = this.session;
327
373
  const device = this.xrp;
328
374
  const generation = this.connectionGeneration;
@@ -338,7 +384,7 @@ export class LedgerAdapter extends BaseWalletAdapter {
338
384
  // The XRP app adds the multisign prefix and signer AccountID itself.
339
385
  const signingBlob = encode(prepared).toUpperCase();
340
386
  assertCurrent();
341
- const signature = await this.signOnDevice(prepared, signingBlob, "Ledger multisigning timeout. Please confirm the transaction on your Ledger device.");
387
+ const signature = await this.signOnDevice(prepared, signingBlob, "Multisign timed out. Check Ledger.");
342
388
  assertCurrent();
343
389
  this.verifyDeviceSignature(encodeForMultiSigning(prepared, session.address), signature, publicKey, verifyKeypairSignature);
344
390
  const signer = { Signer: { Account: session.address, SigningPubKey: publicKey, TxnSignature: signature.toUpperCase() } };
@@ -425,7 +471,7 @@ export class LedgerAdapter extends BaseWalletAdapter {
425
471
  mapConnectionError(error) {
426
472
  if (isWalletKitErrorLike(error))
427
473
  return error;
428
- const parsed = parseLedgerError(error);
474
+ const parsed = parseLedgerError(error, this.getDeviceApp());
429
475
  if (parsed.timeout)
430
476
  return createWalletError.requestTimeout(parsed.message, error);
431
477
  if (parsed.rejected)
@@ -438,7 +484,7 @@ export class LedgerAdapter extends BaseWalletAdapter {
438
484
  mapSigningError(error) {
439
485
  if (isWalletKitErrorLike(error))
440
486
  return error;
441
- const parsed = parseLedgerError(error);
487
+ const parsed = parseLedgerError(error, this.getDeviceApp());
442
488
  if (parsed.timeout)
443
489
  return createWalletError.requestTimeout(parsed.message, error);
444
490
  if (parsed.rejected)
@@ -465,6 +511,9 @@ export class LedgerAdapter extends BaseWalletAdapter {
465
511
  const txJson = asRecord(tx);
466
512
  return txJson.SigningPubKey === "" || Array.isArray(txJson.Signers);
467
513
  }
514
+ getDeviceApp() {
515
+ return this.options.deviceApp ?? (this.network ? getProviderHint(this.network, "ledgerApp") : "XRP");
516
+ }
468
517
  }
469
518
  export function createLedgerAdapter(options) {
470
519
  return new LedgerAdapter(options);
@@ -494,7 +543,7 @@ function getLedgerBrowserSupport() {
494
543
  message: webHID || webUSB ? "Ledger transport is supported" : "This browser does not support Ledger WebHID/WebUSB transport"
495
544
  };
496
545
  }
497
- function parseLedgerError(error) {
546
+ function parseLedgerError(error, app = "XRP") {
498
547
  const message = getLedgerErrorMessage(error);
499
548
  const statusCode = getLedgerStatusCode(error);
500
549
  const lower = message.toLowerCase();
@@ -505,14 +554,15 @@ function parseLedgerError(error) {
505
554
  return { state: LedgerDeviceState.UNKNOWN, message: message || "Ledger request timed out", rejected: false, timeout: true };
506
555
  }
507
556
  if (statusCode === 0x6804 || /locked|pin/.test(lower)) {
508
- return { state: LedgerDeviceState.LOCKED, message: "Ledger is locked. Please unlock your Ledger device.", rejected: false, timeout: false };
557
+ return { state: LedgerDeviceState.LOCKED, message: "Unlock your Ledger.", rejected: false, timeout: false };
509
558
  }
510
- if ([0x6e00, 0x6511, 0x650f].includes(statusCode ?? 0) || /app.*open|xrp.*app|cla_not_supported/.test(lower)) {
511
- return { state: LedgerDeviceState.APP_NOT_OPEN, message: /connect again|select.*again/.test(lower)
512
- ? message : "Please open the XRP app on your Ledger device.", rejected: false, timeout: false };
559
+ if ([0x6e00, 0x6511, 0x650f].includes(statusCode ?? 0) || /app.*open|(?:xrp|xah|xahau).*app|open (?:the )?(?:xrp|xah)|cla_not_supported/.test(lower)) {
560
+ return { state: LedgerDeviceState.APP_NOT_OPEN, message: /select.*again|reselect/.test(lower)
561
+ ? `Open ${app}. Reselect Ledger.` : /connect again|reconnect/.test(lower)
562
+ ? `Open ${app} on Ledger. Reconnect.` : `Open ${app} on Ledger.`, rejected: false, timeout: false };
513
563
  }
514
564
  if (/no device|device.*not found|disconnected|cannot open device|transport/i.test(message)) {
515
- return { state: LedgerDeviceState.NOT_CONNECTED, message: "Ledger device not found. Please connect and unlock your Ledger device.", rejected: false, timeout: false };
565
+ return { state: LedgerDeviceState.NOT_CONNECTED, message: "Connect and unlock Ledger.", rejected: false, timeout: false };
516
566
  }
517
567
  return { state: LedgerDeviceState.UNKNOWN, message: message || "Unknown Ledger error", rejected: false, timeout: false };
518
568
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xrpl-wallet-kit/adapter-ledger",
3
- "version": "0.1.23",
3
+ "version": "0.2.1",
4
4
  "description": "Ledger hardware wallet adapter for XRPL Wallet Kit.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -25,7 +25,7 @@
25
25
  "@ledgerhq/hw-app-xrp": "^6.28.0",
26
26
  "@ledgerhq/hw-transport-webhid": "^6.28.0",
27
27
  "@ledgerhq/hw-transport-webusb": "^6.28.0",
28
- "@xrpl-wallet-kit/core": "0.1.23"
28
+ "@xrpl-wallet-kit/core": "0.2.1"
29
29
  },
30
30
  "peerDependencies": {
31
31
  "xrpl": "^4.0.0 || ^5.0.0"