@reef-knot/ledger-connector 5.2.0-alpha.4 → 5.2.0
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/hid/account.d.ts +8 -1
- package/dist/hid/account.d.ts.map +1 -1
- package/dist/hid/account.js +23 -3
- package/dist/hid/connector.d.ts +5 -2
- package/dist/hid/connector.d.ts.map +1 -1
- package/dist/hid/connector.js +78 -70
- package/dist/hid/index.d.ts +1 -0
- package/dist/hid/index.d.ts.map +1 -1
- package/dist/hid/index.js +2 -1
- package/dist/hid/provider.d.ts +8 -5
- package/dist/hid/provider.d.ts.map +1 -1
- package/dist/hid/provider.js +5 -3
- package/dist/index.js +2 -1
- package/package.json +2 -2
package/dist/hid/account.d.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import type Eth from '@ledgerhq/hw-app-eth';
|
|
2
2
|
import { type Address, type LocalAccount } from 'viem';
|
|
3
3
|
export type WithEthApp = <T>(callback: (eth: Eth) => T | Promise<T>) => Promise<T>;
|
|
4
|
-
export
|
|
4
|
+
export type LedgerAccountOptions = {
|
|
5
|
+
forceClearSign?: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare class ClearSignUnavailableError extends Error {
|
|
8
|
+
name: string;
|
|
9
|
+
constructor();
|
|
10
|
+
}
|
|
11
|
+
export declare const createLedgerAccount: (address: Address, path: string, withEthApp: WithEthApp, { forceClearSign }?: LedgerAccountOptions) => LocalAccount;
|
|
5
12
|
//# sourceMappingURL=account.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../../src/hid/account.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,sBAAsB,CAAC;AAE5C,OAAO,EAOL,KAAK,OAAO,
|
|
1
|
+
{"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../../src/hid/account.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,sBAAsB,CAAC;AAE5C,OAAO,EAOL,KAAK,OAAO,EAEZ,KAAK,YAAY,EAGlB,MAAM,MAAM,CAAC;AAId,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,EACzB,QAAQ,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,KACnC,OAAO,CAAC,CAAC,CAAC,CAAC;AAEhB,MAAM,MAAM,oBAAoB,GAAG;IAEjC,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B,CAAC;AAMF,qBAAa,yBAA0B,SAAQ,KAAK;IACzC,IAAI,SAA+B;;CAK7C;AA4BD,eAAO,MAAM,mBAAmB,GAC9B,SAAS,OAAO,EAChB,MAAM,MAAM,EACZ,YAAY,UAAU,EACtB,qBAA4B,oBAAyB,KACpD,YA4FC,CAAC"}
|
package/dist/hid/account.js
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import { bytesToHex, getTypesForEIP712Domain, hashStruct, serializeSignature, serializeTransaction, stringToHex } from "viem";
|
|
2
2
|
import { toAccount } from "viem/accounts";
|
|
3
3
|
//#region src/hid/account.ts
|
|
4
|
+
var ClearSignUnavailableError = class extends Error {
|
|
5
|
+
constructor() {
|
|
6
|
+
super("The transaction cannot be clear signed on the device.");
|
|
7
|
+
this.name = "ClearSignUnavailableError";
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
const hasCalldata = (data) => !!data && data !== "0x";
|
|
11
|
+
const isEmptyResolution = (resolution) => !resolution || [
|
|
12
|
+
resolution.erc20Tokens,
|
|
13
|
+
resolution.nfts,
|
|
14
|
+
resolution.externalPlugin,
|
|
15
|
+
resolution.plugin
|
|
16
|
+
].every((descriptors) => descriptors.length === 0);
|
|
4
17
|
const RESOLUTION_CONFIG = {
|
|
5
18
|
erc20: true,
|
|
6
19
|
externalPlugins: true,
|
|
@@ -12,11 +25,18 @@ const toSignatureHex = ({ r, s, v }) => serializeSignature({
|
|
|
12
25
|
s: `0x${s}`,
|
|
13
26
|
v: BigInt(v)
|
|
14
27
|
});
|
|
15
|
-
const createLedgerAccount = (address, path, withEthApp) => toAccount({
|
|
28
|
+
const createLedgerAccount = (address, path, withEthApp, { forceClearSign = false } = {}) => toAccount({
|
|
16
29
|
address,
|
|
17
30
|
async signTransaction(transaction, { serializer = serializeTransaction } = {}) {
|
|
18
31
|
const unsignedRawTx = (await serializer(transaction)).slice(2);
|
|
19
|
-
const { r, s, v } = await withEthApp((eth) =>
|
|
32
|
+
const { r, s, v } = await withEthApp(async (eth) => {
|
|
33
|
+
const resolution = await eth.ledgerService.resolveTransaction(unsignedRawTx, eth.loadConfig, RESOLUTION_CONFIG).catch((error) => {
|
|
34
|
+
if (forceClearSign) throw error;
|
|
35
|
+
return null;
|
|
36
|
+
});
|
|
37
|
+
if (forceClearSign && hasCalldata(transaction.data) && isEmptyResolution(resolution)) throw new ClearSignUnavailableError();
|
|
38
|
+
return eth.signTransaction(path, unsignedRawTx, resolution);
|
|
39
|
+
});
|
|
20
40
|
return serializer(transaction, {
|
|
21
41
|
r: `0x${r}`,
|
|
22
42
|
s: `0x${s}`,
|
|
@@ -53,4 +73,4 @@ const createLedgerAccount = (address, path, withEthApp) => toAccount({
|
|
|
53
73
|
}
|
|
54
74
|
});
|
|
55
75
|
//#endregion
|
|
56
|
-
export { createLedgerAccount };
|
|
76
|
+
export { ClearSignUnavailableError, createLedgerAccount };
|
package/dist/hid/connector.d.ts
CHANGED
|
@@ -2,11 +2,14 @@ import { Chain } from 'wagmi/chains';
|
|
|
2
2
|
import type { LedgerHQProvider } from './provider';
|
|
3
3
|
export declare const idLedgerHid = "ledgerHID";
|
|
4
4
|
export declare const name = "Ledger";
|
|
5
|
-
|
|
5
|
+
type LedgerHIDConnectorOptions = {
|
|
6
6
|
rpc: Record<number, string>;
|
|
7
7
|
defaultChain: Chain;
|
|
8
|
-
|
|
8
|
+
forceClearSign?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export declare function ledgerHIDConnector({ rpc, defaultChain, forceClearSign, }: LedgerHIDConnectorOptions): import("wagmi").CreateConnectorFn<LedgerHQProvider, Record<string, unknown>, Record<string, unknown>>;
|
|
9
11
|
export declare namespace ledgerHIDConnector {
|
|
10
12
|
var type: "ledgerHID";
|
|
11
13
|
}
|
|
14
|
+
export {};
|
|
12
15
|
//# sourceMappingURL=connector.d.ts.map
|
|
@@ -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;
|
|
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;AAE7B,KAAK,yBAAyB,GAAG;IAC/B,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5B,YAAY,EAAE,KAAK,CAAC;IAGpB,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B,CAAC;AAGF,wBAAgB,kBAAkB,CAAC,EACjC,GAAG,EACH,YAAY,EACZ,cAAc,GACf,EAAE,yBAAyB,yGAqI3B;yBAzIe,kBAAkB"}
|
package/dist/hid/connector.js
CHANGED
|
@@ -5,86 +5,94 @@ import { SwitchChainError } from "viem";
|
|
|
5
5
|
const idLedgerHid = "ledgerHID";
|
|
6
6
|
const name = "Ledger";
|
|
7
7
|
ledgerHIDConnector.type = "ledgerHID";
|
|
8
|
-
function ledgerHIDConnector({ rpc, defaultChain }) {
|
|
8
|
+
function ledgerHIDConnector({ rpc, defaultChain, forceClearSign }) {
|
|
9
9
|
const providers = {};
|
|
10
10
|
let currentChainId = restoreLedgerChainId();
|
|
11
|
-
return createConnector(({ chains, emitter }) =>
|
|
12
|
-
|
|
13
|
-
name,
|
|
14
|
-
type: ledgerHIDConnector.type,
|
|
15
|
-
async getProvider({ chainId } = {}) {
|
|
16
|
-
const chain = chains.find((x) => x.id === (chainId ?? currentChainId)) ?? defaultChain;
|
|
17
|
-
if (!providers[chain.id]) {
|
|
18
|
-
const { LedgerHQProvider } = await import("./provider.js");
|
|
19
|
-
providers[chain.id] = new LedgerHQProvider({
|
|
20
|
-
chain,
|
|
21
|
-
rpcUrl: rpc?.[chain.id],
|
|
22
|
-
supportedChainIds: chains.map((x) => x.id)
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
return providers[chain.id];
|
|
26
|
-
},
|
|
27
|
-
async connect({ chainId, withCapabilities = false } = {}) {
|
|
28
|
-
try {
|
|
29
|
-
currentChainId = chainId ?? currentChainId;
|
|
30
|
-
const provider = await this.getProvider({ chainId: currentChainId });
|
|
31
|
-
provider.on("disconnect", this.onDisconnect);
|
|
32
|
-
const account = await provider.enable();
|
|
33
|
-
const connectedChainId = await this.getChainId();
|
|
34
|
-
currentChainId = connectedChainId;
|
|
35
|
-
saveLedgerChainId(connectedChainId);
|
|
36
|
-
return {
|
|
37
|
-
accounts: withCapabilities ? [{
|
|
38
|
-
address: account,
|
|
39
|
-
capabilities: {}
|
|
40
|
-
}] : [account],
|
|
41
|
-
chainId: connectedChainId
|
|
42
|
-
};
|
|
43
|
-
} catch (error) {
|
|
44
|
-
currentChainId = restoreLedgerChainId();
|
|
45
|
-
return checkError(error);
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
async disconnect() {
|
|
11
|
+
return createConnector(({ chains, emitter }) => {
|
|
12
|
+
const forgetSession = () => {
|
|
49
13
|
Object.values(providers).forEach((provider) => {
|
|
50
|
-
provider.removeListener("disconnect",
|
|
14
|
+
provider.removeListener("disconnect", onDisconnect);
|
|
51
15
|
provider.resetAccount();
|
|
52
16
|
});
|
|
53
17
|
currentChainId = void 0;
|
|
54
18
|
clearLedgerDerivationPath();
|
|
55
19
|
clearLedgerChainId();
|
|
56
20
|
clearLedgerAccount();
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
},
|
|
61
|
-
async getChainId() {
|
|
62
|
-
return (await this.getProvider()).chain.id;
|
|
63
|
-
},
|
|
64
|
-
async isAuthorized() {
|
|
65
|
-
try {
|
|
66
|
-
if (!await this.getProvider()) throw new ConnectorNotFoundError();
|
|
67
|
-
const [account] = await this.getAccounts();
|
|
68
|
-
return !!account;
|
|
69
|
-
} catch (e) {
|
|
70
|
-
console.error(e);
|
|
71
|
-
return false;
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
|
-
async switchChain({ chainId }) {
|
|
75
|
-
const chain = chains.find((x) => x.id === chainId);
|
|
76
|
-
if (!chain) throw new SwitchChainError(new ChainNotConfiguredError());
|
|
77
|
-
currentChainId = chainId;
|
|
78
|
-
saveLedgerChainId(chainId);
|
|
79
|
-
emitter.emit("change", { chainId });
|
|
80
|
-
return chain;
|
|
81
|
-
},
|
|
82
|
-
onDisconnect() {
|
|
21
|
+
};
|
|
22
|
+
const onDisconnect = () => {
|
|
23
|
+
forgetSession();
|
|
83
24
|
emitter.emit("disconnect");
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
id: idLedgerHid,
|
|
28
|
+
name,
|
|
29
|
+
type: ledgerHIDConnector.type,
|
|
30
|
+
async getProvider({ chainId } = {}) {
|
|
31
|
+
const chain = chains.find((x) => x.id === (chainId ?? currentChainId)) ?? defaultChain;
|
|
32
|
+
if (!providers[chain.id]) {
|
|
33
|
+
const { LedgerHQProvider } = await import("./provider.js");
|
|
34
|
+
providers[chain.id] = new LedgerHQProvider({
|
|
35
|
+
chain,
|
|
36
|
+
rpcUrl: rpc?.[chain.id],
|
|
37
|
+
supportedChainIds: chains.map((x) => x.id),
|
|
38
|
+
forceClearSign
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return providers[chain.id];
|
|
42
|
+
},
|
|
43
|
+
async connect({ chainId, withCapabilities = false } = {}) {
|
|
44
|
+
try {
|
|
45
|
+
currentChainId = chainId ?? currentChainId;
|
|
46
|
+
const provider = await this.getProvider({ chainId: currentChainId });
|
|
47
|
+
provider.on("disconnect", onDisconnect);
|
|
48
|
+
const account = await provider.enable();
|
|
49
|
+
const connectedChainId = await this.getChainId();
|
|
50
|
+
currentChainId = connectedChainId;
|
|
51
|
+
saveLedgerChainId(connectedChainId);
|
|
52
|
+
return {
|
|
53
|
+
accounts: withCapabilities ? [{
|
|
54
|
+
address: account,
|
|
55
|
+
capabilities: {}
|
|
56
|
+
}] : [account],
|
|
57
|
+
chainId: connectedChainId
|
|
58
|
+
};
|
|
59
|
+
} catch (error) {
|
|
60
|
+
currentChainId = restoreLedgerChainId();
|
|
61
|
+
return checkError(error);
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
async disconnect() {
|
|
65
|
+
forgetSession();
|
|
66
|
+
},
|
|
67
|
+
async getAccounts() {
|
|
68
|
+
return [await (await this.getProvider()).getAddress()];
|
|
69
|
+
},
|
|
70
|
+
async getChainId() {
|
|
71
|
+
return (await this.getProvider()).chain.id;
|
|
72
|
+
},
|
|
73
|
+
async isAuthorized() {
|
|
74
|
+
try {
|
|
75
|
+
if (!await this.getProvider()) throw new ConnectorNotFoundError();
|
|
76
|
+
const [account] = await this.getAccounts();
|
|
77
|
+
return !!account;
|
|
78
|
+
} catch (e) {
|
|
79
|
+
console.error(e);
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
async switchChain({ chainId }) {
|
|
84
|
+
const chain = chains.find((x) => x.id === chainId);
|
|
85
|
+
if (!chain) throw new SwitchChainError(new ChainNotConfiguredError());
|
|
86
|
+
currentChainId = chainId;
|
|
87
|
+
saveLedgerChainId(chainId);
|
|
88
|
+
emitter.emit("change", { chainId });
|
|
89
|
+
return chain;
|
|
90
|
+
},
|
|
91
|
+
onDisconnect,
|
|
92
|
+
onAccountsChanged() {},
|
|
93
|
+
onChainChanged() {}
|
|
94
|
+
};
|
|
95
|
+
});
|
|
88
96
|
}
|
|
89
97
|
//#endregion
|
|
90
98
|
export { idLedgerHid, ledgerHIDConnector, name };
|
package/dist/hid/index.d.ts
CHANGED
package/dist/hid/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hid/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hid/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/hid/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { LS_KEY_DERIVATION_PATH } from "./constants.js";
|
|
2
2
|
import { idLedgerHid, ledgerHIDConnector } from "./connector.js";
|
|
3
|
-
|
|
3
|
+
import { ClearSignUnavailableError } from "./account.js";
|
|
4
|
+
export { ClearSignUnavailableError, LS_KEY_DERIVATION_PATH, idLedgerHid, ledgerHIDConnector };
|
package/dist/hid/provider.d.ts
CHANGED
|
@@ -7,6 +7,12 @@ type RequestArguments = {
|
|
|
7
7
|
};
|
|
8
8
|
type ProviderEvent = 'disconnect';
|
|
9
9
|
type Listener = () => void;
|
|
10
|
+
type LedgerHQProviderOptions = {
|
|
11
|
+
chain: Chain;
|
|
12
|
+
rpcUrl?: string;
|
|
13
|
+
supportedChainIds?: number[];
|
|
14
|
+
forceClearSign?: boolean;
|
|
15
|
+
};
|
|
10
16
|
export declare class LedgerHQProvider {
|
|
11
17
|
readonly chain: Chain;
|
|
12
18
|
device?: HIDDevice;
|
|
@@ -18,11 +24,8 @@ export declare class LedgerHQProvider {
|
|
|
18
24
|
private walletClient?;
|
|
19
25
|
private listeners;
|
|
20
26
|
private readonly supportedChainIds;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
rpcUrl?: string;
|
|
24
|
-
supportedChainIds?: number[];
|
|
25
|
-
});
|
|
27
|
+
private readonly forceClearSign;
|
|
28
|
+
constructor({ chain, rpcUrl, supportedChainIds, forceClearSign, }: LedgerHQProviderOptions);
|
|
26
29
|
on(event: ProviderEvent, listener: Listener): void;
|
|
27
30
|
removeListener(event: ProviderEvent, listener: Listener): void;
|
|
28
31
|
emit(event: ProviderEvent): 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;IAItE,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAW;
|
|
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,KAAK,uBAAuB,GAAG;IAC7B,KAAK,EAAE,KAAK,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B,CAAC;AAEF,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;IAItE,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAW;IAE7C,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAU;gBAE7B,EACV,KAAK,EACL,MAAM,EACN,iBAAiB,EACjB,cAAsB,GACvB,EAAE,uBAAuB;IAiB1B,EAAE,CAAC,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,QAAQ;IAI3C,cAAc,CAAC,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,QAAQ;IAIvD,IAAI,CAAC,KAAK,EAAE,aAAa;IAMzB,IAAI,cAAc,WAQjB;IAEK,aAAa;IAQb,YAAY,IAAI,OAAO,CAAC,eAAe,CAAC;IAc9C,UAAU,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAoB3D,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC;IAyBhC,YAAY;IAMN,UAAU,IAAI,OAAO,CAAC,YAAY,CAAC;YAuC3B,WAAW;IAoBnB,UAAU,IAAI,OAAO,CAAC,OAAO,CAAC;IAOpC,OAAO,CAAC,eAAe;YAQT,eAAe;YAUf,eAAe;IA4EvB,OAAO,CAAC,EAAE,MAAM,EAAE,MAAW,EAAE,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;CA2E3E"}
|
package/dist/hid/provider.js
CHANGED
|
@@ -26,11 +26,12 @@ const withDeviceSession = (fn) => {
|
|
|
26
26
|
return result;
|
|
27
27
|
};
|
|
28
28
|
var LedgerHQProvider = class {
|
|
29
|
-
constructor({ chain, rpcUrl, supportedChainIds }) {
|
|
29
|
+
constructor({ chain, rpcUrl, supportedChainIds, forceClearSign = false }) {
|
|
30
30
|
this.listeners = {};
|
|
31
31
|
this.chain = chain;
|
|
32
32
|
this.rpcUrl = rpcUrl;
|
|
33
33
|
this.supportedChainIds = supportedChainIds ?? [chain.id];
|
|
34
|
+
this.forceClearSign = forceClearSign;
|
|
34
35
|
if (!rpcUrl) console.warn(`[reef-knot] No RPC URL configured for chain ${chain.id} (${chain.name}), falling back to its default public RPC endpoint`);
|
|
35
36
|
}
|
|
36
37
|
on(event, listener) {
|
|
@@ -118,7 +119,7 @@ var LedgerHQProvider = class {
|
|
|
118
119
|
}
|
|
119
120
|
return cb(eth);
|
|
120
121
|
});
|
|
121
|
-
this.account = createLedgerAccount(address, path, withVerifyingEthApp);
|
|
122
|
+
this.account = createLedgerAccount(address, path, withVerifyingEthApp, { forceClearSign: this.forceClearSign });
|
|
122
123
|
this.accountPath = path;
|
|
123
124
|
this.walletClient = void 0;
|
|
124
125
|
}
|
|
@@ -169,7 +170,8 @@ var LedgerHQProvider = class {
|
|
|
169
170
|
const walletClient = await this.getWalletClient();
|
|
170
171
|
const account = walletClient.account;
|
|
171
172
|
if (transaction.from && (!isAddress(transaction.from) || !isAddressEqual(transaction.from, account.address))) throw new Error("from address mismatch");
|
|
172
|
-
const type = transaction.type ? TX_TYPES[transaction.type] : void 0;
|
|
173
|
+
const type = transaction.type != null ? TX_TYPES[transaction.type] : void 0;
|
|
174
|
+
if (transaction.type != null && !type) throw new Error(`Unsupported transaction type ${transaction.type}`);
|
|
173
175
|
const request = {
|
|
174
176
|
account,
|
|
175
177
|
chain: this.chain,
|
package/dist/index.js
CHANGED
|
@@ -3,5 +3,6 @@ import { isIframe, isLedgerLive } from "./iframe/helpers.js";
|
|
|
3
3
|
import "./iframe/index.js";
|
|
4
4
|
import { LS_KEY_DERIVATION_PATH } from "./hid/constants.js";
|
|
5
5
|
import { idLedgerHid, ledgerHIDConnector } from "./hid/connector.js";
|
|
6
|
+
import { ClearSignUnavailableError } from "./hid/account.js";
|
|
6
7
|
import "./hid/index.js";
|
|
7
|
-
export { LS_KEY_DERIVATION_PATH, idLedgerHid, idLedgerLive, isIframe, isLedgerLive, ledgerHIDConnector, ledgerLiveConnector, name };
|
|
8
|
+
export { ClearSignUnavailableError, LS_KEY_DERIVATION_PATH, idLedgerHid, idLedgerLive, isIframe, isLedgerLive, ledgerHIDConnector, ledgerLiveConnector, name };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reef-knot/ledger-connector",
|
|
3
|
-
"version": "5.2.0
|
|
3
|
+
"version": "5.2.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"eslint-config-custom": "*",
|
|
46
46
|
"happy-dom": "^20.0.0",
|
|
47
47
|
"viem": ">=2.50",
|
|
48
|
-
"vitest": "^
|
|
48
|
+
"vitest": "^4.1.11",
|
|
49
49
|
"wagmi": ">=3.6"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|