@xrpl-wallet-kit/adapter-ledger 0.1.14 → 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 +5 -2
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +56 -9
- package/package.json +57 -57
package/README.md
CHANGED
|
@@ -36,7 +36,9 @@ const kit = createWalletKit({
|
|
|
36
36
|
- Default derivation path is `44'/144'/0'/0/0`.
|
|
37
37
|
- `signTransaction()` signs without submit.
|
|
38
38
|
- `signAndSubmit()` signs and submits when requested by the caller.
|
|
39
|
-
- XRPL multisigning
|
|
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.
|
|
40
42
|
|
|
41
43
|
## Options
|
|
42
44
|
|
|
@@ -62,7 +64,8 @@ Hardware transport should be mocked in unit tests. Manual smoke testing should c
|
|
|
62
64
|
- connect success;
|
|
63
65
|
- disconnect cleanup;
|
|
64
66
|
- `submit:false` signed transaction result;
|
|
65
|
-
- multisign
|
|
67
|
+
- multisign sign-only contribution and malformed pre-populated `Signers` input;
|
|
68
|
+
- multisign submission fails closed;
|
|
66
69
|
- user rejection on device.
|
|
67
70
|
|
|
68
71
|
## Links
|
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
|
|
65
|
+
private isMultisignTransaction;
|
|
63
66
|
}
|
|
64
67
|
export declare function createLedgerAdapter(options?: LedgerAdapterOptions): LedgerAdapter;
|
|
65
68
|
export {};
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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,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;AAUviB,oBAAY,iBAAiB;IAC3B,aAAa,kBAAkB;IAC/B,MAAM,WAAW;IACjB,YAAY,iBAAiB;IAC7B,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,IAAI,CAAC,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pB,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.
|
|
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
|
|
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.
|
|
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
|
-
|
|
342
|
+
isMultisignTransaction(tx) {
|
|
294
343
|
const txJson = asRecord(tx);
|
|
295
|
-
|
|
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,57 +1,57 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@xrpl-wallet-kit/adapter-ledger",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "Ledger hardware wallet adapter for XRPL Wallet Kit.",
|
|
5
|
-
"license": "MIT",
|
|
6
|
-
"type": "module",
|
|
7
|
-
"main": "./dist/index.js",
|
|
8
|
-
"types": "./dist/index.d.ts",
|
|
9
|
-
"exports": {
|
|
10
|
-
".": {
|
|
11
|
-
"types": "./dist/index.d.ts",
|
|
12
|
-
"import": "./dist/index.js"
|
|
13
|
-
}
|
|
14
|
-
},
|
|
15
|
-
"files": [
|
|
16
|
-
"dist",
|
|
17
|
-
"README.md"
|
|
18
|
-
],
|
|
19
|
-
"scripts": {
|
|
20
|
-
"build": "tsc -p tsconfig.json"
|
|
21
|
-
},
|
|
22
|
-
"dependencies": {
|
|
23
|
-
"@ledgerhq/errors": "^6.16.0",
|
|
24
|
-
"@ledgerhq/hw-app-xrp": "^6.28.0",
|
|
25
|
-
"@ledgerhq/hw-transport": "^6.28.0",
|
|
26
|
-
"@ledgerhq/hw-transport-webhid": "^6.28.0",
|
|
27
|
-
"@ledgerhq/hw-transport-webusb": "^6.28.0",
|
|
28
|
-
"@xrpl-wallet-kit/core": "0.1.
|
|
29
|
-
"buffer": "^6.0.3"
|
|
30
|
-
},
|
|
31
|
-
"peerDependencies": {
|
|
32
|
-
"xrpl": "^4.0.0 || ^5.0.0"
|
|
33
|
-
},
|
|
34
|
-
"devDependencies": {
|
|
35
|
-
"xrpl": "^4.0.0"
|
|
36
|
-
},
|
|
37
|
-
"publishConfig": {
|
|
38
|
-
"access": "public"
|
|
39
|
-
},
|
|
40
|
-
"repository": {
|
|
41
|
-
"type": "git",
|
|
42
|
-
"url": "git+https://github.com/XRPDomains/xrpl-wallet-kit.git"
|
|
43
|
-
},
|
|
44
|
-
"homepage": "https://github.com/XRPDomains/xrpl-wallet-kit#readme",
|
|
45
|
-
"bugs": {
|
|
46
|
-
"url": "https://github.com/XRPDomains/xrpl-wallet-kit/issues"
|
|
47
|
-
},
|
|
48
|
-
"keywords": [
|
|
49
|
-
"xrpl",
|
|
50
|
-
"wallet",
|
|
51
|
-
"wallet-adapter",
|
|
52
|
-
"wallet-kit",
|
|
53
|
-
"xrp-ledger",
|
|
54
|
-
"web3",
|
|
55
|
-
"adapter"
|
|
56
|
-
]
|
|
57
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@xrpl-wallet-kit/adapter-ledger",
|
|
3
|
+
"version": "0.1.15",
|
|
4
|
+
"description": "Ledger hardware wallet adapter for XRPL Wallet Kit.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc -p tsconfig.json"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@ledgerhq/errors": "^6.16.0",
|
|
24
|
+
"@ledgerhq/hw-app-xrp": "^6.28.0",
|
|
25
|
+
"@ledgerhq/hw-transport": "^6.28.0",
|
|
26
|
+
"@ledgerhq/hw-transport-webhid": "^6.28.0",
|
|
27
|
+
"@ledgerhq/hw-transport-webusb": "^6.28.0",
|
|
28
|
+
"@xrpl-wallet-kit/core": "0.1.15",
|
|
29
|
+
"buffer": "^6.0.3"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"xrpl": "^4.0.0 || ^5.0.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"xrpl": "^4.0.0"
|
|
36
|
+
},
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
},
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "git+https://github.com/XRPDomains/xrpl-wallet-kit.git"
|
|
43
|
+
},
|
|
44
|
+
"homepage": "https://github.com/XRPDomains/xrpl-wallet-kit#readme",
|
|
45
|
+
"bugs": {
|
|
46
|
+
"url": "https://github.com/XRPDomains/xrpl-wallet-kit/issues"
|
|
47
|
+
},
|
|
48
|
+
"keywords": [
|
|
49
|
+
"xrpl",
|
|
50
|
+
"wallet",
|
|
51
|
+
"wallet-adapter",
|
|
52
|
+
"wallet-kit",
|
|
53
|
+
"xrp-ledger",
|
|
54
|
+
"web3",
|
|
55
|
+
"adapter"
|
|
56
|
+
]
|
|
57
|
+
}
|