@xrpl-wallet-kit/adapter-ledger 0.1.13 → 0.1.15

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
@@ -1,71 +1,74 @@
1
- # @xrpl-wallet-kit/adapter-ledger
2
-
3
- Ledger hardware wallet adapter for XRPL Wallet Kit.
4
-
5
- This adapter connects to Ledger devices through WebHID or WebUSB, reads an XRPL account from the XRP app, and supports signed transaction flows for XRPL dApps.
6
-
7
- ## Capabilities
8
-
9
- - `connect`
10
- - `disconnect`
11
- - `signTransaction`
12
- - `signAndSubmit`
13
-
14
- ## Install
15
-
16
- ```bash
17
- npm install @xrpl-wallet-kit/adapter-ledger
18
- ```
19
-
20
- ## Usage
21
-
22
- ```ts
23
- import { createWalletKit } from "@xrpl-wallet-kit/client";
24
- import { createLedgerAdapter } from "@xrpl-wallet-kit/adapter-ledger";
25
-
26
- const kit = createWalletKit({
27
- adapters: [createLedgerAdapter()]
28
- });
29
- ```
30
-
31
- ## Runtime Notes
32
-
33
- - Requires a browser with WebHID or WebUSB support.
34
- - Requires a connected Ledger device with the XRP app open.
35
- - Hardware wallets are explicit user-presence devices. `restoreSession()` returns `null` and does not silently reconnect after refresh.
36
- - Default derivation path is `44'/144'/0'/0/0`.
37
- - `signTransaction()` signs without submit.
38
- - `signAndSubmit()` signs and submits when requested by the caller.
39
- - XRPL multisigning is intentionally not advertised. Payloads that contain multisign shape such as `SigningPubKey: ""` or `Signers` fail with `UNSUPPORTED_METHOD` before the adapter delegates signing.
40
-
41
- ## Options
42
-
43
- ```ts
44
- createLedgerAdapter({
45
- accountIndex: 0,
46
- derivationPath: "44'/144'/0'/0/0",
47
- preferWebHID: true,
48
- timeout: 60000
49
- });
50
- ```
51
-
52
- Use `connectLedger` in tests or custom integrations to inject a prebuilt Ledger session.
53
-
54
- ## Testing
55
-
56
- Hardware transport should be mocked in unit tests. Manual smoke testing should cover:
57
-
58
- - unsupported browser;
59
- - device disconnected;
60
- - device locked;
61
- - XRP app not open;
62
- - connect success;
63
- - disconnect cleanup;
64
- - `submit:false` signed transaction result;
65
- - multisign payloads fail closed;
66
- - user rejection on device.
67
-
68
- ## Links
69
-
70
- - Ledger: https://www.ledger.com
71
- - XRPL Wallet Kit: https://github.com/XRPDomains/xrpl-wallet-kit
1
+ # @xrpl-wallet-kit/adapter-ledger
2
+
3
+ Ledger hardware wallet adapter for XRPL Wallet Kit.
4
+
5
+ This adapter connects to Ledger devices through WebHID or WebUSB, reads an XRPL account from the XRP app, and supports signed transaction flows for XRPL dApps.
6
+
7
+ ## Capabilities
8
+
9
+ - `connect`
10
+ - `disconnect`
11
+ - `signTransaction`
12
+ - `signAndSubmit`
13
+
14
+ ## Install
15
+
16
+ ```bash
17
+ npm install @xrpl-wallet-kit/adapter-ledger
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ ```ts
23
+ import { createWalletKit } from "@xrpl-wallet-kit/client";
24
+ import { createLedgerAdapter } from "@xrpl-wallet-kit/adapter-ledger";
25
+
26
+ const kit = createWalletKit({
27
+ adapters: [createLedgerAdapter()]
28
+ });
29
+ ```
30
+
31
+ ## Runtime Notes
32
+
33
+ - Requires a browser with WebHID or WebUSB support.
34
+ - Requires a connected Ledger device with the XRP app open.
35
+ - Hardware wallets are explicit user-presence devices. `restoreSession()` returns `null` and does not silently reconnect after refresh.
36
+ - Default derivation path is `44'/144'/0'/0/0`.
37
+ - `signTransaction()` signs without submit.
38
+ - `signAndSubmit()` signs and submits when requested by the caller.
39
+ - `signTransaction()` supports XRPL multisigning when `SigningPubKey` is empty. It returns a signed blob plus the signer contribution under `raw.signer`/`raw.signedTx` for the dApp to combine with other signers.
40
+ - `signAndSubmit()` rejects multisign payloads with `UNSUPPORTED_METHOD`; the dApp must combine a quorum of signer contributions before submission.
41
+ - A custom `connectLedger` session must implement `signMultisignTransaction()` to opt into multisigning.
42
+
43
+ ## Options
44
+
45
+ ```ts
46
+ createLedgerAdapter({
47
+ accountIndex: 0,
48
+ derivationPath: "44'/144'/0'/0/0",
49
+ preferWebHID: true,
50
+ timeout: 60000
51
+ });
52
+ ```
53
+
54
+ Use `connectLedger` in tests or custom integrations to inject a prebuilt Ledger session.
55
+
56
+ ## Testing
57
+
58
+ Hardware transport should be mocked in unit tests. Manual smoke testing should cover:
59
+
60
+ - unsupported browser;
61
+ - device disconnected;
62
+ - device locked;
63
+ - XRP app not open;
64
+ - connect success;
65
+ - disconnect cleanup;
66
+ - `submit:false` signed transaction result;
67
+ - multisign sign-only contribution and malformed pre-populated `Signers` input;
68
+ - multisign submission fails closed;
69
+ - user rejection on device.
70
+
71
+ ## Links
72
+
73
+ - Ledger: https://www.ledger.com
74
+ - XRPL Wallet Kit: https://github.com/XRPDomains/xrpl-wallet-kit
package/dist/index.d.ts CHANGED
@@ -21,6 +21,7 @@ export interface LedgerSession {
21
21
  publicKey?: string;
22
22
  derivationPath?: string;
23
23
  signTransaction(tx: unknown, submit?: boolean): Promise<LedgerSignResult>;
24
+ signMultisignTransaction?(tx: unknown): Promise<LedgerSignResult>;
24
25
  }
25
26
  interface LedgerAccount {
26
27
  address: string;
@@ -54,12 +55,14 @@ export declare class LedgerAdapter extends BaseWalletAdapter {
54
55
  getAccounts(count?: number, startIndex?: number): Promise<LedgerAccount[]>;
55
56
  private connectDefaultLedger;
56
57
  private signWithDefaultLedger;
58
+ private signMultisignTransaction;
59
+ private signMultisignWithDefaultLedger;
57
60
  private createTransport;
58
61
  private cleanup;
59
62
  private mapConnectionError;
60
63
  private mapSigningError;
61
64
  private withTimeout;
62
- private assertSingleSignTransaction;
65
+ private isMultisignTransaction;
63
66
  }
64
67
  export declare function createLedgerAdapter(options?: LedgerAdapterOptions): LedgerAdapter;
65
68
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAqB,MAAM,uBAAuB,CAAC;AAC7E,OAAO,KAAK,EACV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,CAAC,OAAO,CAAC,CAAgB;IAChC,OAAO,CAAC,OAAO,CAAC,CAAc;IAC9B,OAAO,CAAC,SAAS,CAAC,CAAkB;IACpC,OAAO,CAAC,GAAG,CAAC,CAAe;IAC3B,OAAO,CAAC,cAAc,CAAS;gBAEX,OAAO,GAAE,oBAAyB;IAahD,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAI/B,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC;IAmCxD,cAAc,CAAC,QAAQ,EAAE,aAAa,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;IAKtE,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAM3B,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,QAAQ,CAAC;IAqB/D,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAiBhF,WAAW,CAAC,KAAK,SAAI,EAAE,UAAU,SAAI,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;YA+BxD,oBAAoB;YAyBpB,qBAAqB;YAgErB,wBAAwB;YAMxB,8BAA8B;YAsC9B,eAAe;YAwBf,OAAO;IAYrB,OAAO,CAAC,kBAAkB;IAW1B,OAAO,CAAC,eAAe;YAQT,WAAW;IAezB,OAAO,CAAC,sBAAsB;CAI/B;AAED,wBAAgB,mBAAmB,CAAC,OAAO,CAAC,EAAE,oBAAoB,iBAEjE"}
package/dist/index.js CHANGED
@@ -79,7 +79,9 @@ export class LedgerAdapter extends BaseWalletAdapter {
79
79
  async signAndSubmit(request) {
80
80
  if (!this.session)
81
81
  throw createWalletError.notConnected();
82
- this.assertSingleSignTransaction(request.txJson);
82
+ if (this.isMultisignTransaction(request.txJson)) {
83
+ throw createWalletError.unsupportedMethod("multisign submission", this.metadata.name);
84
+ }
83
85
  try {
84
86
  const result = await this.session.signTransaction(request.txJson, request.submit ?? true);
85
87
  return {
@@ -99,9 +101,11 @@ export class LedgerAdapter extends BaseWalletAdapter {
99
101
  async signTransaction(request) {
100
102
  if (!this.session)
101
103
  throw createWalletError.notConnected();
102
- this.assertSingleSignTransaction(request.txJson);
103
104
  try {
104
- const result = await this.session.signTransaction(request.txJson, false);
105
+ const multisign = this.isMultisignTransaction(request.txJson);
106
+ const result = multisign
107
+ ? await this.signMultisignTransaction(request.txJson)
108
+ : await this.session.signTransaction(request.txJson, false);
105
109
  return {
106
110
  txBlob: result.txBlob,
107
111
  signed: result.signed ?? Boolean(result.txBlob),
@@ -156,7 +160,8 @@ export class LedgerAdapter extends BaseWalletAdapter {
156
160
  address: account.address,
157
161
  publicKey: account.publicKey,
158
162
  derivationPath: this.derivationPath,
159
- signTransaction: (tx, submit) => this.signWithDefaultLedger(tx, submit)
163
+ signTransaction: (tx, submit) => this.signWithDefaultLedger(tx, submit),
164
+ signMultisignTransaction: (tx) => this.signMultisignWithDefaultLedger(tx)
160
165
  };
161
166
  }
162
167
  async signWithDefaultLedger(tx, submit = true) {
@@ -164,7 +169,9 @@ export class LedgerAdapter extends BaseWalletAdapter {
164
169
  throw createWalletError.notConnected();
165
170
  if (!this.network)
166
171
  throw createWalletError.connectionFailed(this.metadata.name, new Error("XRPL network is required for Ledger signing"));
167
- this.assertSingleSignTransaction(tx);
172
+ if (this.isMultisignTransaction(tx)) {
173
+ throw createWalletError.unsupportedMethod("XRPL multisigning through the single-sign path", this.metadata.name);
174
+ }
168
175
  const { Client, encode } = await import("xrpl");
169
176
  const client = new Client(this.network.rpcUrl);
170
177
  await client.connect();
@@ -212,6 +219,48 @@ export class LedgerAdapter extends BaseWalletAdapter {
212
219
  await client.disconnect();
213
220
  }
214
221
  }
222
+ async signMultisignTransaction(tx) {
223
+ if (!this.session)
224
+ throw createWalletError.notConnected();
225
+ if (this.session.signMultisignTransaction)
226
+ return this.session.signMultisignTransaction(tx);
227
+ throw createWalletError.unsupportedMethod("XRPL multisigning for injected Ledger sessions", this.metadata.name);
228
+ }
229
+ async signMultisignWithDefaultLedger(tx) {
230
+ if (!this.xrp || !this.session)
231
+ throw createWalletError.notConnected();
232
+ if (!this.network)
233
+ throw createWalletError.connectionFailed(this.metadata.name, new Error("XRPL network is required for Ledger signing"));
234
+ const { Client, encode, encodeForMultiSigning } = await import("xrpl");
235
+ const client = new Client(this.network.rpcUrl);
236
+ await client.connect();
237
+ try {
238
+ const input = asRecord(tx);
239
+ if (Array.isArray(input.Signers) && input.Signers.length > 0) {
240
+ throw createWalletError.unsupportedMethod("adding a signer to a populated Signers array", this.metadata.name);
241
+ }
242
+ const prepared = await client.autofill({
243
+ ...input,
244
+ Account: typeof input.Account === "string" ? input.Account : this.session.address,
245
+ SigningPubKey: ""
246
+ });
247
+ delete prepared.TxnSignature;
248
+ delete prepared.Signers;
249
+ prepared.SigningPubKey = "";
250
+ const publicKey = (this.session.publicKey ?? (await this.xrp.getAddress(this.derivationPath, false, false)).publicKey).toUpperCase();
251
+ const signingBlob = encodeForMultiSigning(prepared, this.session.address).toUpperCase();
252
+ const signature = await this.withTimeout(this.xrp.signTransaction(this.derivationPath, signingBlob), "Ledger multisigning timeout. Please confirm the transaction on your Ledger device.");
253
+ if (!signature)
254
+ throw new Error("Ledger did not return a transaction signature");
255
+ const signer = { Signer: { Account: this.session.address, SigningPubKey: publicKey, TxnSignature: signature.toUpperCase() } };
256
+ const signedTx = { ...prepared, Signers: [signer] };
257
+ const txBlob = encode(signedTx);
258
+ return { txBlob, signed: true, raw: { txBlob, signedTx, signer } };
259
+ }
260
+ finally {
261
+ await client.disconnect();
262
+ }
263
+ }
215
264
  async createTransport() {
216
265
  const support = getLedgerBrowserSupport();
217
266
  if (!support.supported)
@@ -290,11 +339,9 @@ export class LedgerAdapter extends BaseWalletAdapter {
290
339
  clearTimeout(timer);
291
340
  }
292
341
  }
293
- assertSingleSignTransaction(tx) {
342
+ isMultisignTransaction(tx) {
294
343
  const txJson = asRecord(tx);
295
- if (txJson.SigningPubKey === "" || Array.isArray(txJson.Signers)) {
296
- throw createWalletError.unsupportedMethod("XRPL multisigning", this.metadata.name);
297
- }
344
+ return txJson.SigningPubKey === "" || Array.isArray(txJson.Signers);
298
345
  }
299
346
  }
300
347
  export function createLedgerAdapter(options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xrpl-wallet-kit/adapter-ledger",
3
- "version": "0.1.13",
3
+ "version": "0.1.15",
4
4
  "description": "Ledger hardware wallet adapter for XRPL Wallet Kit.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -25,11 +25,11 @@
25
25
  "@ledgerhq/hw-transport": "^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.13",
28
+ "@xrpl-wallet-kit/core": "0.1.15",
29
29
  "buffer": "^6.0.3"
30
30
  },
31
31
  "peerDependencies": {
32
- "xrpl": "^4.0.0"
32
+ "xrpl": "^4.0.0 || ^5.0.0"
33
33
  },
34
34
  "devDependencies": {
35
35
  "xrpl": "^4.0.0"