@reef-knot/ledger-connector 5.2.0-alpha.3 → 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.
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ssr.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ssr.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/ssr.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=connector.test.d.ts.map
@@ -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
+ };
86
+ //# sourceMappingURL=fixtures.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fixtures.d.ts","sourceRoot":"","sources":["../../../src/hid/__tests__/fixtures.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,WAAW,EACZ,MAAM,+BAA+B,CAAC;AAEvC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAOpD,eAAO,MAAM,eAAe,qBAAqB,CAAC;AAClD,eAAO,MAAM,iBAAiB,qBAAqB,CAAC;AAEpD,eAAO,MAAM,SAAS,EAAE,OAAsD,CAAC;AAC/E,eAAO,MAAM,SAAS,EAAE,OAAsD,CAAC;AAE/E,eAAO,MAAM,WAAW,eAAkC,CAAC;AAC3D,eAAO,MAAM,WAAW,eAAkC,CAAC;AAE3D,eAAO,MAAM,iBAAiB,QAA6C,CAAC;AAW5E,eAAO,MAAM,UAAU,mCAAmC,CAAC;AAG3D,eAAO,MAAM,aAAa,2BAA2B,CAAC;AAGtD,eAAO,MAAM,kBAAkB,GAAI,SAAS,OAAO,WAEa,CAAC;AAEjE,eAAO,MAAM,0BAA0B,GAAI,SAAS,OAAO,WAEK,CAAC;AAEjE,eAAO,MAAM,qBAAqB,cAAc,CAAC;AACjD,eAAO,MAAM,aAAa,QAEO,CAAC;AAIlC,eAAO,MAAM,SAAS;;;;;;;;CAQZ,CAAC;AACX,eAAO,MAAM,OAAO,QAEa,CAAC;AAIlC,eAAO,MAAM,gBAAgB;;;;;;;;CAGnB,CAAC;AACX,eAAO,MAAM,cAAc,QAEM,CAAC;AAGlC,eAAO,MAAM,OAAO;;;;;;;;CAQV,CAAC;AACX,eAAO,MAAM,YAAY,QAEQ,CAAC;AAGlC,eAAO,MAAM,OAAO;;;;;;;;;CASV,CAAC;AACX,eAAO,MAAM,YAAY,QAEQ,CAAC;AAElC,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=helpers.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.test.d.ts","sourceRoot":"","sources":["../../../src/hid/__tests__/helpers.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=provider.test.d.ts.map
@@ -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":"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,YAErC,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"}
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"}
@@ -9,7 +9,8 @@ const checkError = (error) => {
9
9
  throw error;
10
10
  };
11
11
  const clearLedgerDerivationPath = () => {
12
- window?.localStorage.removeItem(LS_KEY_DERIVATION_PATH);
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;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=connector.test.d.ts.map
@@ -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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=helpers.test.d.ts.map
@@ -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,6GA0IzB;yBA7Ie,mBAAmB"}
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"}
@@ -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
- id: idLedgerLive,
11
- name,
12
- type: ledgerLiveConnector.type,
13
- async getProvider({ chainId } = {}) {
14
- const chain = chains.find((x) => x.id === chainId) ?? defaultChain;
15
- if (!providers[chain.id]) {
16
- const { LedgerIFrameProvider } = await import("./provider.js");
17
- providers[chain.id] = new LedgerIFrameProvider(options);
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
- return providers[chain.id];
20
- },
21
- async connect({ chainId, withCapabilities } = {}) {
22
- try {
23
- const provider = await this.getProvider();
24
- provider.on("accountsChanged", this.onAccountsChanged);
25
- provider.on("chainChanged", this.onChainChanged);
26
- emitter.emit("message", { type: "connecting" });
27
- const accounts = await this.getAccounts();
28
- let currentChainId = await this.getChainId();
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
- throw error;
43
- }
44
- },
45
- async switchChain({ chainId }) {
46
- const provider = await this.getProvider();
47
- const id = numberToHex(chainId);
48
- try {
49
- await provider.send("wallet_switchEthereumChain", [{ chainId: id }]);
50
- return chains.find((x) => x.id === chainId) ?? {
51
- id: chainId,
52
- name: `Chain ${id}`,
53
- network: `${id}`,
54
- nativeCurrency: {
55
- decimals: 18,
56
- name: "Ether",
57
- symbol: "ETH"
58
- },
59
- rpcUrls: {
60
- default: { http: [""] },
61
- public: { http: [""] }
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
- } catch (error) {
65
- const message = typeof error === "string" ? error : error?.message;
66
- if (/user rejected request/i.test(message)) throw new UserRejectedRequestError(error);
67
- throw new SwitchChainNotSupportedError({ connector: { name } });
68
- }
69
- },
70
- async getAccounts() {
71
- return (await (await this.getProvider()).send("eth_requestAccounts")).map((account) => getAddress(account));
72
- },
73
- async getChainId() {
74
- const chainId = await (await this.getProvider()).send("eth_chainId");
75
- return Number(chainId);
76
- },
77
- async isAuthorized() {
78
- try {
79
- return !!(await (await this.getProvider()).send("eth_accounts"))[0];
80
- } catch {
81
- return false;
82
- }
83
- },
84
- onAccountsChanged(accounts) {
85
- if (accounts.length === 0 || !accounts[0]) {
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
- this.disconnect();
88
- } else emitter.emit("change", { accounts });
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",
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": {