@reef-knot/ledger-connector 5.2.0-alpha.2 → 5.2.0-alpha.4
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/__tests__/ssr.test.d.ts +2 -0
- package/dist/__tests__/ssr.test.d.ts.map +1 -0
- package/dist/hid/__tests__/connector.test.d.ts +2 -0
- package/dist/hid/__tests__/connector.test.d.ts.map +1 -0
- package/dist/hid/__tests__/fixtures.d.ts +86 -0
- package/dist/hid/__tests__/fixtures.d.ts.map +1 -0
- package/dist/hid/__tests__/helpers.test.d.ts +2 -0
- package/dist/hid/__tests__/helpers.test.d.ts.map +1 -0
- package/dist/hid/__tests__/provider.test.d.ts +2 -0
- package/dist/hid/__tests__/provider.test.d.ts.map +1 -0
- package/dist/hid/connector.d.ts.map +1 -1
- package/dist/hid/connector.js +2 -1
- package/dist/hid/helpers.d.ts.map +1 -1
- package/dist/hid/helpers.js +2 -1
- package/dist/hid/provider.d.ts +3 -1
- package/dist/hid/provider.d.ts.map +1 -1
- package/dist/hid/provider.js +6 -1
- package/dist/iframe/__tests__/connector.test.d.ts +2 -0
- package/dist/iframe/__tests__/connector.test.d.ts.map +1 -0
- package/dist/iframe/__tests__/fake-ledger-live.d.ts +27 -0
- package/dist/iframe/__tests__/fake-ledger-live.d.ts.map +1 -0
- package/dist/iframe/__tests__/helpers.test.d.ts +2 -0
- package/dist/iframe/__tests__/helpers.test.d.ts.map +1 -0
- package/dist/iframe/connector.d.ts.map +1 -1
- package/dist/iframe/connector.js +104 -89
- package/package.json +5 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ssr.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/ssr.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connector.test.d.ts","sourceRoot":"","sources":["../../../src/hid/__tests__/connector.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { RecordStore } from '@ledgerhq/hw-transport-mocker';
|
|
2
|
+
import type { Address } from 'viem';
|
|
3
|
+
import type { LedgerHQProvider } from '../provider';
|
|
4
|
+
export declare const DERIVATION_PATH = "m/44'/60'/0'/0/0";
|
|
5
|
+
export declare const DERIVATION_PATH_B = "m/44'/60'/1'/0/0";
|
|
6
|
+
export declare const ADDRESS_A: Address;
|
|
7
|
+
export declare const ADDRESS_B: Address;
|
|
8
|
+
export declare const SIGNATURE_R: `0x${string}`;
|
|
9
|
+
export declare const SIGNATURE_S: `0x${string}`;
|
|
10
|
+
export declare const MESSAGE_SIGNATURE: string;
|
|
11
|
+
export declare const APP_CONFIG = "=> e006000000\n<= 010109009000";
|
|
12
|
+
export declare const DEVICE_LOCKED = "=> e006000000\n<= 5515";
|
|
13
|
+
export declare const getAddressExchange: (address: Address) => string;
|
|
14
|
+
export declare const getAddressExchangeForPathB: (address: Address) => string;
|
|
15
|
+
export declare const PERSONAL_SIGN_MESSAGE = "reef-knot";
|
|
16
|
+
export declare const PERSONAL_SIGN: string;
|
|
17
|
+
export declare const LEGACY_TX: {
|
|
18
|
+
readonly type: "legacy";
|
|
19
|
+
readonly chainId: 1;
|
|
20
|
+
readonly nonce: 0;
|
|
21
|
+
readonly gasPrice: 1000000000n;
|
|
22
|
+
readonly gas: 21000n;
|
|
23
|
+
readonly to: `0x${string}`;
|
|
24
|
+
readonly value: 1n;
|
|
25
|
+
};
|
|
26
|
+
export declare const SIGN_TX: string;
|
|
27
|
+
export declare const FILLED_LEGACY_TX: {
|
|
28
|
+
readonly gasPrice: 1200000000n;
|
|
29
|
+
readonly type: "legacy";
|
|
30
|
+
readonly chainId: 1;
|
|
31
|
+
readonly nonce: 0;
|
|
32
|
+
readonly gas: 21000n;
|
|
33
|
+
readonly to: `0x${string}`;
|
|
34
|
+
readonly value: 1n;
|
|
35
|
+
};
|
|
36
|
+
export declare const SIGN_TX_FILLED: string;
|
|
37
|
+
export declare const TX_1559: {
|
|
38
|
+
readonly chainId: 1;
|
|
39
|
+
readonly nonce: 0;
|
|
40
|
+
readonly maxPriorityFeePerGas: 1000000000n;
|
|
41
|
+
readonly maxFeePerGas: 2000000000n;
|
|
42
|
+
readonly gas: 21000n;
|
|
43
|
+
readonly to: `0x${string}`;
|
|
44
|
+
readonly value: 1n;
|
|
45
|
+
};
|
|
46
|
+
export declare const SIGN_TX_1559: string;
|
|
47
|
+
export declare const TX_2930: {
|
|
48
|
+
readonly chainId: 1;
|
|
49
|
+
readonly type: "eip2930";
|
|
50
|
+
readonly nonce: 0;
|
|
51
|
+
readonly gasPrice: 1000000000n;
|
|
52
|
+
readonly gas: 21000n;
|
|
53
|
+
readonly to: `0x${string}`;
|
|
54
|
+
readonly value: 1n;
|
|
55
|
+
readonly accessList: readonly [];
|
|
56
|
+
};
|
|
57
|
+
export declare const SIGN_TX_2930: string;
|
|
58
|
+
export declare const TYPED_DATA: {
|
|
59
|
+
domain: {
|
|
60
|
+
name: string;
|
|
61
|
+
version: string;
|
|
62
|
+
chainId: number;
|
|
63
|
+
};
|
|
64
|
+
types: {
|
|
65
|
+
EIP712Domain: {
|
|
66
|
+
name: string;
|
|
67
|
+
type: string;
|
|
68
|
+
}[];
|
|
69
|
+
Mail: {
|
|
70
|
+
name: string;
|
|
71
|
+
type: string;
|
|
72
|
+
}[];
|
|
73
|
+
};
|
|
74
|
+
primaryType: string;
|
|
75
|
+
message: {
|
|
76
|
+
contents: string;
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
export declare const EIP712_REJECT = "=> b001000000\n<= 6d00";
|
|
80
|
+
export declare const EIP712_HASHED: string;
|
|
81
|
+
export declare const injectReplayer: (provider: LedgerHQProvider, ...exchanges: string[]) => RecordStore;
|
|
82
|
+
export declare const injectReplayerWithDevice: (provider: LedgerHQProvider, device: HIDDevice, ...exchanges: string[]) => RecordStore;
|
|
83
|
+
export declare const stubHid: () => {
|
|
84
|
+
unplug: (device: HIDDevice) => void;
|
|
85
|
+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;;;;;;;;;;;;;;;;;;;;CAYtB,CAAC;AAIF,eAAO,MAAM,aAAa,2BAA2B,CAAC;AAEtD,eAAO,MAAM,aAAa,QAEO,CAAC;AAKlC,eAAO,MAAM,cAAc,GACzB,UAAU,gBAAgB,EAC1B,GAAG,WAAW,MAAM,EAAE,gBAOvB,CAAC;AAIF,eAAO,MAAM,wBAAwB,GACnC,UAAU,gBAAgB,EAC1B,QAAQ,SAAS,EACjB,GAAG,WAAW,MAAM,EAAE,gBAQvB,CAAC;AAIF,eAAO,MAAM,OAAO;qBAaC,SAAS;CAK7B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.test.d.ts","sourceRoot":"","sources":["../../../src/hid/__tests__/helpers.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.test.d.ts","sourceRoot":"","sources":["../../../src/hid/__tests__/provider.test.ts"],"names":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connector.d.ts","sourceRoot":"","sources":["../../src/hid/connector.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAUrC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACnD,eAAO,MAAM,WAAW,cAAc,CAAC;AACvC,eAAO,MAAM,IAAI,WAAW,CAAC;AAG7B,wBAAgB,kBAAkB,CAAC,EACjC,GAAG,EACH,YAAY,GACb,EAAE;IACD,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5B,YAAY,EAAE,KAAK,CAAC;CACrB,
|
|
1
|
+
{"version":3,"file":"connector.d.ts","sourceRoot":"","sources":["../../src/hid/connector.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAUrC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACnD,eAAO,MAAM,WAAW,cAAc,CAAC;AACvC,eAAO,MAAM,IAAI,WAAW,CAAC;AAG7B,wBAAgB,kBAAkB,CAAC,EACjC,GAAG,EACH,YAAY,GACb,EAAE;IACD,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5B,YAAY,EAAE,KAAK,CAAC;CACrB,yGAiIA;yBAvIe,kBAAkB"}
|
package/dist/hid/connector.js
CHANGED
|
@@ -18,7 +18,8 @@ function ledgerHIDConnector({ rpc, defaultChain }) {
|
|
|
18
18
|
const { LedgerHQProvider } = await import("./provider.js");
|
|
19
19
|
providers[chain.id] = new LedgerHQProvider({
|
|
20
20
|
chain,
|
|
21
|
-
rpcUrl: rpc?.[chain.id]
|
|
21
|
+
rpcUrl: rpc?.[chain.id],
|
|
22
|
+
supportedChainIds: chains.map((x) => x.id)
|
|
22
23
|
});
|
|
23
24
|
}
|
|
24
25
|
return providers[chain.id];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/hid/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,OAAO,EAAE,MAAM,MAAM,CAAC;AAO/C,MAAM,MAAM,sBAAsB,GAAG;IACnC,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAAI,OAAO,OAAO,KAAG,OACc,CAAC;AAEpE,eAAO,MAAM,UAAU,GAAI,OAAO,GAAG,KAAG,KAmBvC,CAAC;AAEF,eAAO,MAAM,yBAAyB,
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/hid/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,OAAO,EAAE,MAAM,MAAM,CAAC;AAO/C,MAAM,MAAM,sBAAsB,GAAG;IACnC,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAAI,OAAO,OAAO,KAAG,OACc,CAAC;AAEpE,eAAO,MAAM,UAAU,GAAI,OAAO,GAAG,KAAG,KAmBvC,CAAC;AAEF,eAAO,MAAM,yBAAyB,YAIrC,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAI,SAAS,MAAM,SAGhD,CAAC;AAEF,eAAO,MAAM,oBAAoB,QAAO,MAAM,GAAG,SAMhD,CAAC;AAEF,eAAO,MAAM,kBAAkB,YAG9B,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAI,SAAS,sBAAsB,SAGhE,CAAC;AAEF,eAAO,MAAM,oBAAoB,QAAO,sBAAsB,GAAG,SAchE,CAAC;AAEF,eAAO,MAAM,kBAAkB,YAG9B,CAAC"}
|
package/dist/hid/helpers.js
CHANGED
|
@@ -9,7 +9,8 @@ const checkError = (error) => {
|
|
|
9
9
|
throw error;
|
|
10
10
|
};
|
|
11
11
|
const clearLedgerDerivationPath = () => {
|
|
12
|
-
window
|
|
12
|
+
if (typeof window === "undefined") return;
|
|
13
|
+
window.localStorage.removeItem(LS_KEY_DERIVATION_PATH);
|
|
13
14
|
};
|
|
14
15
|
const saveLedgerChainId = (chainId) => {
|
|
15
16
|
if (typeof window === "undefined") return;
|
package/dist/hid/provider.d.ts
CHANGED
|
@@ -17,9 +17,11 @@ export declare class LedgerHQProvider {
|
|
|
17
17
|
private publicClient?;
|
|
18
18
|
private walletClient?;
|
|
19
19
|
private listeners;
|
|
20
|
-
|
|
20
|
+
private readonly supportedChainIds;
|
|
21
|
+
constructor({ chain, rpcUrl, supportedChainIds, }: {
|
|
21
22
|
chain: Chain;
|
|
22
23
|
rpcUrl?: string;
|
|
24
|
+
supportedChainIds?: number[];
|
|
23
25
|
});
|
|
24
26
|
on(event: ProviderEvent, listener: Listener): void;
|
|
25
27
|
removeListener(event: ProviderEvent, listener: Listener): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/hid/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,sBAAsB,CAAC;AAC5C,OAAO,KAAK,eAAe,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAYL,KAAK,OAAO,EACZ,KAAK,KAAK,EAEV,KAAK,YAAY,EAIlB,MAAM,MAAM,CAAC;AA6Cd,KAAK,gBAAgB,GAAG;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC;CACpB,CAAC;AAEF,KAAK,aAAa,GAAG,YAAY,CAAC;AAClC,KAAK,QAAQ,GAAG,MAAM,IAAI,CAAC;AAE3B,qBAAa,gBAAgB;IAC3B,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IAEf,MAAM,CAAC,EAAE,SAAS,CAAC;IAEnB,SAAS,CAAC,EAAE,OAAO,eAAe,CAAC;IAE1C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAS;IAEjC,OAAO,CAAC,OAAO,CAAC,CAAe;IAE/B,OAAO,CAAC,WAAW,CAAC,CAAS;IAE7B,OAAO,CAAC,YAAY,CAAC,CAAe;IAEpC,OAAO,CAAC,YAAY,CAAC,CAAe;IAEpC,OAAO,CAAC,SAAS,CAAqD;
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/hid/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,sBAAsB,CAAC;AAC5C,OAAO,KAAK,eAAe,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAYL,KAAK,OAAO,EACZ,KAAK,KAAK,EAEV,KAAK,YAAY,EAIlB,MAAM,MAAM,CAAC;AA6Cd,KAAK,gBAAgB,GAAG;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC;CACpB,CAAC;AAEF,KAAK,aAAa,GAAG,YAAY,CAAC;AAClC,KAA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,OAAO,CAAC,EAAE,MAAM,EAAE,MAAW,EAAE,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;CA2E3E"}
|
package/dist/hid/provider.js
CHANGED
|
@@ -26,10 +26,11 @@ const withDeviceSession = (fn) => {
|
|
|
26
26
|
return result;
|
|
27
27
|
};
|
|
28
28
|
var LedgerHQProvider = class {
|
|
29
|
-
constructor({ chain, rpcUrl }) {
|
|
29
|
+
constructor({ chain, rpcUrl, supportedChainIds }) {
|
|
30
30
|
this.listeners = {};
|
|
31
31
|
this.chain = chain;
|
|
32
32
|
this.rpcUrl = rpcUrl;
|
|
33
|
+
this.supportedChainIds = supportedChainIds ?? [chain.id];
|
|
33
34
|
if (!rpcUrl) console.warn(`[reef-knot] No RPC URL configured for chain ${chain.id} (${chain.name}), falling back to its default public RPC endpoint`);
|
|
34
35
|
}
|
|
35
36
|
on(event, listener) {
|
|
@@ -223,6 +224,10 @@ var LedgerHQProvider = class {
|
|
|
223
224
|
case "eth_signTypedData_v4":
|
|
224
225
|
if (typeof params[1] !== "string") throw new Error("eth_signTypedData_v4 arg 1 is not a string");
|
|
225
226
|
return (await this.getAccount()).signTypedData(JSON.parse(params[1]));
|
|
227
|
+
case "wallet_getCapabilities": {
|
|
228
|
+
const chainIds = ((Array.isArray(params[1]) ? params[1].filter((value) => isHex(value)).map((value) => hexToNumber(value)) : void 0) ?? this.supportedChainIds).filter((chainId) => this.supportedChainIds.includes(chainId));
|
|
229
|
+
return Object.fromEntries(chainIds.map((chainId) => [numberToHex(chainId), {}]));
|
|
230
|
+
}
|
|
226
231
|
default: {
|
|
227
232
|
if (method.startsWith("wallet_") || UNSUPPORTED_WALLET_METHODS.has(method)) throw new MethodNotSupportedRpcError(/* @__PURE__ */ new Error(`The method ${method} is not supported`), { method });
|
|
228
233
|
const rpcRequest = this.getPublicClient().request;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connector.test.d.ts","sourceRoot":"","sources":["../../../src/iframe/__tests__/connector.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { MinimalEventSourceInterface, MinimalEventTargetInterface } from '@ledgerhq/iframe-provider';
|
|
2
|
+
type JsonRpcRequest = {
|
|
3
|
+
jsonrpc: '2.0';
|
|
4
|
+
id: number;
|
|
5
|
+
method: string;
|
|
6
|
+
params?: unknown[];
|
|
7
|
+
};
|
|
8
|
+
export type HostHandlers = Record<string, (params: unknown[]) => unknown>;
|
|
9
|
+
export declare class HostRpcError extends Error {
|
|
10
|
+
readonly code: number;
|
|
11
|
+
constructor(code: number, message: string);
|
|
12
|
+
}
|
|
13
|
+
export declare class FakeLedgerLive implements MinimalEventSourceInterface, MinimalEventTargetInterface {
|
|
14
|
+
private readonly handlers;
|
|
15
|
+
readonly calls: {
|
|
16
|
+
method: string;
|
|
17
|
+
params: unknown[];
|
|
18
|
+
}[];
|
|
19
|
+
private listeners;
|
|
20
|
+
constructor(handlers: HostHandlers);
|
|
21
|
+
addEventListener(_type: 'message', listener: (event: MessageEvent) => void): void;
|
|
22
|
+
postMessage(message: JsonRpcRequest): void;
|
|
23
|
+
emitEvent(method: string, params: unknown[]): void;
|
|
24
|
+
private dispatch;
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=fake-ledger-live.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fake-ledger-live.d.ts","sourceRoot":"","sources":["../../../src/iframe/__tests__/fake-ledger-live.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,2BAA2B,EAC3B,2BAA2B,EAC5B,MAAM,2BAA2B,CAAC;AAEnC,KAAK,cAAc,GAAG;IACpB,OAAO,EAAE,KAAK,CAAC;IACf,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,CAAC;AAG1E,qBAAa,YAAa,SAAQ,KAAK;aAEnB,IAAI,EAAE,MAAM;gBAAZ,IAAI,EAAE,MAAM,EAC5B,OAAO,EAAE,MAAM;CAIlB;AAKD,qBAAa,cACX,YAAW,2BAA2B,EAAE,2BAA2B;IAMvD,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAJrC,QAAQ,CAAC,KAAK,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,OAAO,EAAE,CAAA;KAAE,EAAE,CAAM;IAE7D,OAAO,CAAC,SAAS,CAA4C;gBAEhC,QAAQ,EAAE,YAAY;IAEnD,gBAAgB,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI;IAI1E,WAAW,CAAC,OAAO,EAAE,cAAc;IA0BnC,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE;IAI3C,OAAO,CAAC,QAAQ;CAKjB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.test.d.ts","sourceRoot":"","sources":["../../../src/iframe/__tests__/helpers.test.ts"],"names":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connector.d.ts","sourceRoot":"","sources":["../../src/iframe/connector.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAC/E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAEvD,eAAO,MAAM,YAAY,eAAe,CAAC;AACzC,eAAO,MAAM,IAAI,gBAAgB,CAAC;AAElC,KAAK,uBAAuB,GAAG;IAC7B,OAAO,CAAC,EAAE,6BAA6B,CAAC;IACxC,YAAY,EAAE,KAAK,CAAC;CACrB,CAAC;AAGF,wBAAgB,mBAAmB,CAAC,EAClC,OAAO,EACP,YAAY,GACb,EAAE,uBAAuB,
|
|
1
|
+
{"version":3,"file":"connector.d.ts","sourceRoot":"","sources":["../../src/iframe/connector.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAC/E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAEvD,eAAO,MAAM,YAAY,eAAe,CAAC;AACzC,eAAO,MAAM,IAAI,gBAAgB,CAAC;AAElC,KAAK,uBAAuB,GAAG;IAC7B,OAAO,CAAC,EAAE,6BAA6B,CAAC;IACxC,YAAY,EAAE,KAAK,CAAC;CACrB,CAAC;AAGF,wBAAgB,mBAAmB,CAAC,EAClC,OAAO,EACP,YAAY,GACb,EAAE,uBAAuB,6GAmKzB;yBAtKe,mBAAmB"}
|
package/dist/iframe/connector.js
CHANGED
|
@@ -6,99 +6,114 @@ const name = "Ledger Live";
|
|
|
6
6
|
ledgerLiveConnector.type = "ledgerLive";
|
|
7
7
|
function ledgerLiveConnector({ options, defaultChain }) {
|
|
8
8
|
const providers = {};
|
|
9
|
-
return createConnector(({ chains, emitter }) =>
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
return createConnector(({ chains, emitter }) => {
|
|
10
|
+
const handlers = {
|
|
11
|
+
onAccountsChanged: (accounts) => {
|
|
12
|
+
if (accounts.length === 0 || !accounts[0]) {
|
|
13
|
+
emitter.emit("disconnect");
|
|
14
|
+
handlers.detach();
|
|
15
|
+
} else emitter.emit("change", { accounts });
|
|
16
|
+
},
|
|
17
|
+
onChainChanged: (chainId) => {
|
|
18
|
+
emitter.emit("change", { chainId: Number(chainId) });
|
|
19
|
+
},
|
|
20
|
+
detach: () => {
|
|
21
|
+
Object.values(providers).forEach((provider) => {
|
|
22
|
+
provider.removeListener("accountsChanged", handlers.onAccountsChanged);
|
|
23
|
+
provider.removeListener("chainChanged", handlers.onChainChanged);
|
|
24
|
+
});
|
|
18
25
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
if (chainId && currentChainId !== chainId && this.switchChain) currentChainId = (await this.switchChain({ chainId })).id;
|
|
30
|
-
return {
|
|
31
|
-
accounts: withCapabilities ? accounts.map((address) => ({
|
|
32
|
-
address,
|
|
33
|
-
capabilities: {}
|
|
34
|
-
})) : accounts,
|
|
35
|
-
chainId: currentChainId
|
|
36
|
-
};
|
|
37
|
-
} catch (error) {
|
|
38
|
-
if (error instanceof Error) {
|
|
39
|
-
if (error.code === 4001) throw new UserRejectedRequestError(error);
|
|
40
|
-
throw new ResourceUnavailableRpcError(error);
|
|
26
|
+
};
|
|
27
|
+
return {
|
|
28
|
+
id: idLedgerLive,
|
|
29
|
+
name,
|
|
30
|
+
type: ledgerLiveConnector.type,
|
|
31
|
+
async getProvider({ chainId } = {}) {
|
|
32
|
+
const chain = chains.find((x) => x.id === chainId) ?? defaultChain;
|
|
33
|
+
if (!providers[chain.id]) {
|
|
34
|
+
const { LedgerIFrameProvider } = await import("./provider.js");
|
|
35
|
+
providers[chain.id] = new LedgerIFrameProvider(options);
|
|
41
36
|
}
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
37
|
+
return providers[chain.id];
|
|
38
|
+
},
|
|
39
|
+
async connect({ chainId, withCapabilities } = {}) {
|
|
40
|
+
try {
|
|
41
|
+
const provider = await this.getProvider();
|
|
42
|
+
handlers.detach();
|
|
43
|
+
provider.on("accountsChanged", handlers.onAccountsChanged);
|
|
44
|
+
provider.on("chainChanged", handlers.onChainChanged);
|
|
45
|
+
emitter.emit("message", { type: "connecting" });
|
|
46
|
+
const accounts = await this.getAccounts();
|
|
47
|
+
let currentChainId = await this.getChainId();
|
|
48
|
+
if (chainId && currentChainId !== chainId && this.switchChain) currentChainId = (await this.switchChain({ chainId })).id;
|
|
49
|
+
return {
|
|
50
|
+
accounts: withCapabilities ? accounts.map((address) => ({
|
|
51
|
+
address,
|
|
52
|
+
capabilities: {}
|
|
53
|
+
})) : accounts,
|
|
54
|
+
chainId: currentChainId
|
|
55
|
+
};
|
|
56
|
+
} catch (error) {
|
|
57
|
+
if (error instanceof Error) {
|
|
58
|
+
if (error?.code === 4001) throw new UserRejectedRequestError(error);
|
|
59
|
+
throw new ResourceUnavailableRpcError(error);
|
|
62
60
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
async switchChain({ chainId }) {
|
|
65
|
+
const provider = await this.getProvider();
|
|
66
|
+
const id = numberToHex(chainId);
|
|
67
|
+
try {
|
|
68
|
+
await provider.send("wallet_switchEthereumChain", [{ chainId: id }]);
|
|
69
|
+
return chains.find((x) => x.id === chainId) ?? {
|
|
70
|
+
id: chainId,
|
|
71
|
+
name: `Chain ${id}`,
|
|
72
|
+
network: `${id}`,
|
|
73
|
+
nativeCurrency: {
|
|
74
|
+
decimals: 18,
|
|
75
|
+
name: "Ether",
|
|
76
|
+
symbol: "ETH"
|
|
77
|
+
},
|
|
78
|
+
rpcUrls: {
|
|
79
|
+
default: { http: [""] },
|
|
80
|
+
public: { http: [""] }
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
} catch (error) {
|
|
84
|
+
const message = typeof error === "string" ? error : error?.message;
|
|
85
|
+
if (/user rejected request/i.test(message)) throw new UserRejectedRequestError(error);
|
|
86
|
+
throw new SwitchChainNotSupportedError({ connector: { name } });
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
async getAccounts() {
|
|
90
|
+
return (await (await this.getProvider()).send("eth_requestAccounts")).map((account) => getAddress(account));
|
|
91
|
+
},
|
|
92
|
+
async getChainId() {
|
|
93
|
+
const chainId = await (await this.getProvider()).send("eth_chainId");
|
|
94
|
+
return Number(chainId);
|
|
95
|
+
},
|
|
96
|
+
async isAuthorized() {
|
|
97
|
+
try {
|
|
98
|
+
return !!(await (await this.getProvider()).send("eth_accounts"))[0];
|
|
99
|
+
} catch {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
onAccountsChanged(accounts) {
|
|
104
|
+
handlers.onAccountsChanged(accounts);
|
|
105
|
+
},
|
|
106
|
+
onChainChanged(chainId) {
|
|
107
|
+
handlers.onChainChanged(chainId);
|
|
108
|
+
},
|
|
109
|
+
async disconnect() {
|
|
110
|
+
handlers.detach();
|
|
111
|
+
},
|
|
112
|
+
onDisconnect() {
|
|
86
113
|
emitter.emit("disconnect");
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
onChainChanged(chainId) {
|
|
91
|
-
emitter.emit("change", { chainId: Number(chainId) });
|
|
92
|
-
},
|
|
93
|
-
async disconnect() {
|
|
94
|
-
const provider = await this.getProvider();
|
|
95
|
-
provider.removeListener("accountsChanged", this.onAccountsChanged);
|
|
96
|
-
provider.removeListener("chainChanged", this.onChainChanged);
|
|
97
|
-
},
|
|
98
|
-
onDisconnect() {
|
|
99
|
-
emitter.emit("disconnect");
|
|
100
|
-
}
|
|
101
|
-
}));
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
});
|
|
102
117
|
}
|
|
103
118
|
//#endregion
|
|
104
119
|
export { idLedgerLive, ledgerLiveConnector, name };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reef-knot/ledger-connector",
|
|
3
|
-
"version": "5.2.0-alpha.
|
|
3
|
+
"version": "5.2.0-alpha.4",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -35,13 +35,17 @@
|
|
|
35
35
|
"build": "yarn run -T tsdown",
|
|
36
36
|
"dev": "yarn run -T tsdown --watch",
|
|
37
37
|
"lint": "eslint --ext ts,tsx,js,mjs .",
|
|
38
|
+
"test": "vitest run",
|
|
38
39
|
"typecheck": "tsc --noEmit"
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
42
|
+
"@ledgerhq/hw-transport-mocker": "6.34.7",
|
|
41
43
|
"@types/w3c-web-hid": "^1.0.7",
|
|
42
44
|
"build-config": "*",
|
|
43
45
|
"eslint-config-custom": "*",
|
|
46
|
+
"happy-dom": "^20.0.0",
|
|
44
47
|
"viem": ">=2.50",
|
|
48
|
+
"vitest": "^3.2.4",
|
|
45
49
|
"wagmi": ">=3.6"
|
|
46
50
|
},
|
|
47
51
|
"dependencies": {
|