@injectivelabs/wallet-ledger 1.19.22 → 1.19.23
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/cjs/index.cjs +30 -7
- package/dist/esm/index.js +31 -8
- package/package.json +5 -5
package/dist/cjs/index.cjs
CHANGED
|
@@ -167,6 +167,29 @@ var LedgerTransport$1 = class LedgerTransport$1 {
|
|
|
167
167
|
|
|
168
168
|
//#endregion
|
|
169
169
|
//#region src/strategy/Ledger/Eip1193Provider.ts
|
|
170
|
+
const signTypedDataMethods = new Set([
|
|
171
|
+
"eth_signTypedData",
|
|
172
|
+
"eth_signTypedData_v3",
|
|
173
|
+
"eth_signTypedData_v4"
|
|
174
|
+
]);
|
|
175
|
+
const signMessageMethods = new Set(["eth_sign", "personal_sign"]);
|
|
176
|
+
const isEthAddress = (value) => typeof value === "string" && /^0x[a-fA-F0-9]{40}$/.test(value);
|
|
177
|
+
const getTypedDataParam = (method, params) => {
|
|
178
|
+
const typedData = isEthAddress(params[0]) ? params[1] : params[0];
|
|
179
|
+
if (typedData == null || typeof typedData === "string" && typedData.length === 0) throw new Error(`Missing typed data parameter for ${method}`);
|
|
180
|
+
return typeof typedData === "string" ? typedData : JSON.stringify(typedData);
|
|
181
|
+
};
|
|
182
|
+
const getMessageParam = (method, params) => {
|
|
183
|
+
let message = params[0];
|
|
184
|
+
if (method === "eth_sign" || isEthAddress(params[0])) message = params[1];
|
|
185
|
+
if (!(message instanceof Uint8Array) && (typeof message !== "string" || message.length === 0)) throw new Error(`Missing message parameter for ${method}`);
|
|
186
|
+
return message;
|
|
187
|
+
};
|
|
188
|
+
const getMessageHex = (message) => {
|
|
189
|
+
if (message instanceof Uint8Array) return (0, viem.toHex)(message).replace(/^0x/, "");
|
|
190
|
+
if (typeof message === "string" && message.startsWith("0x")) return message.replace(/^0x/, "");
|
|
191
|
+
return (0, viem.toHex)(String(message)).replace(/^0x/, "");
|
|
192
|
+
};
|
|
170
193
|
var LedgerEip1193Provider = class {
|
|
171
194
|
ledger;
|
|
172
195
|
derivationPath;
|
|
@@ -231,18 +254,18 @@ var LedgerEip1193Provider = class {
|
|
|
231
254
|
return (0, __injectivelabs_wallet_base.getEvmChainConfig)(this.chainId);
|
|
232
255
|
}
|
|
233
256
|
async request(args) {
|
|
234
|
-
if (args.method === "eth_requestAccounts") return [await this.getAddress()];
|
|
235
|
-
if (args.method
|
|
236
|
-
if (!args.params[0]) throw new Error(
|
|
237
|
-
return this.signMessage(args.params
|
|
257
|
+
if (args.method === "eth_requestAccounts" || args.method === "eth_accounts") return [await this.getAddress()];
|
|
258
|
+
if (signMessageMethods.has(args.method)) {
|
|
259
|
+
if (!args.params[0]) throw new Error(`Missing parameter for ${args.method}`);
|
|
260
|
+
return this.signMessage(getMessageHex(getMessageParam(args.method, args.params)));
|
|
238
261
|
}
|
|
239
262
|
if (args.method === "eth_signTransaction") {
|
|
240
263
|
if (!args.params[0]) throw new Error("Missing parameter for eth_signTransaction");
|
|
241
264
|
return this.signTransaction(args.params[0]);
|
|
242
265
|
}
|
|
243
|
-
if (args.method
|
|
244
|
-
if (!args.params[0]) throw new Error(
|
|
245
|
-
return this.signTypedData(args.params
|
|
266
|
+
if (signTypedDataMethods.has(args.method)) {
|
|
267
|
+
if (!args.params[0]) throw new Error(`Missing parameter for ${args.method}`);
|
|
268
|
+
return this.signTypedData(getTypedDataParam(args.method, args.params));
|
|
246
269
|
}
|
|
247
270
|
if (args.method === "eth_chainId") return `0x${this.chainId.toString(16)}`;
|
|
248
271
|
if (args.method === "wallet_switchEthereumChain") return this.setChainId(args.params[0]?.chainId || "0x1");
|
package/dist/esm/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { hashDomain, hashStruct, serializeTransaction } from "viem";
|
|
1
|
+
import { hashDomain, hashStruct, serializeTransaction, toHex } from "viem";
|
|
2
2
|
import { TxGrpcApi } from "@injectivelabs/sdk-ts/core/tx";
|
|
3
3
|
import { addHexPrefix, hexToUint8Array, publicKeyToAddress, safeBigIntStringify, sortObjectByKeys, stringToUint8Array, toUtf8, uint8ArrayToBase64, uint8ArrayToHex } from "@injectivelabs/sdk-ts/utils";
|
|
4
4
|
import { CosmosWalletException, ErrorType, GeneralException, LedgerCosmosException, LedgerException, TransactionException, UnspecifiedErrorCode, WalletException } from "@injectivelabs/exceptions";
|
|
@@ -166,6 +166,29 @@ var LedgerTransport$1 = class LedgerTransport$1 {
|
|
|
166
166
|
|
|
167
167
|
//#endregion
|
|
168
168
|
//#region src/strategy/Ledger/Eip1193Provider.ts
|
|
169
|
+
const signTypedDataMethods = new Set([
|
|
170
|
+
"eth_signTypedData",
|
|
171
|
+
"eth_signTypedData_v3",
|
|
172
|
+
"eth_signTypedData_v4"
|
|
173
|
+
]);
|
|
174
|
+
const signMessageMethods = new Set(["eth_sign", "personal_sign"]);
|
|
175
|
+
const isEthAddress = (value) => typeof value === "string" && /^0x[a-fA-F0-9]{40}$/.test(value);
|
|
176
|
+
const getTypedDataParam = (method, params) => {
|
|
177
|
+
const typedData = isEthAddress(params[0]) ? params[1] : params[0];
|
|
178
|
+
if (typedData == null || typeof typedData === "string" && typedData.length === 0) throw new Error(`Missing typed data parameter for ${method}`);
|
|
179
|
+
return typeof typedData === "string" ? typedData : JSON.stringify(typedData);
|
|
180
|
+
};
|
|
181
|
+
const getMessageParam = (method, params) => {
|
|
182
|
+
let message = params[0];
|
|
183
|
+
if (method === "eth_sign" || isEthAddress(params[0])) message = params[1];
|
|
184
|
+
if (!(message instanceof Uint8Array) && (typeof message !== "string" || message.length === 0)) throw new Error(`Missing message parameter for ${method}`);
|
|
185
|
+
return message;
|
|
186
|
+
};
|
|
187
|
+
const getMessageHex = (message) => {
|
|
188
|
+
if (message instanceof Uint8Array) return toHex(message).replace(/^0x/, "");
|
|
189
|
+
if (typeof message === "string" && message.startsWith("0x")) return message.replace(/^0x/, "");
|
|
190
|
+
return toHex(String(message)).replace(/^0x/, "");
|
|
191
|
+
};
|
|
169
192
|
var LedgerEip1193Provider = class {
|
|
170
193
|
ledger;
|
|
171
194
|
derivationPath;
|
|
@@ -230,18 +253,18 @@ var LedgerEip1193Provider = class {
|
|
|
230
253
|
return getEvmChainConfig(this.chainId);
|
|
231
254
|
}
|
|
232
255
|
async request(args) {
|
|
233
|
-
if (args.method === "eth_requestAccounts") return [await this.getAddress()];
|
|
234
|
-
if (args.method
|
|
235
|
-
if (!args.params[0]) throw new Error(
|
|
236
|
-
return this.signMessage(args.params
|
|
256
|
+
if (args.method === "eth_requestAccounts" || args.method === "eth_accounts") return [await this.getAddress()];
|
|
257
|
+
if (signMessageMethods.has(args.method)) {
|
|
258
|
+
if (!args.params[0]) throw new Error(`Missing parameter for ${args.method}`);
|
|
259
|
+
return this.signMessage(getMessageHex(getMessageParam(args.method, args.params)));
|
|
237
260
|
}
|
|
238
261
|
if (args.method === "eth_signTransaction") {
|
|
239
262
|
if (!args.params[0]) throw new Error("Missing parameter for eth_signTransaction");
|
|
240
263
|
return this.signTransaction(args.params[0]);
|
|
241
264
|
}
|
|
242
|
-
if (args.method
|
|
243
|
-
if (!args.params[0]) throw new Error(
|
|
244
|
-
return this.signTypedData(args.params
|
|
265
|
+
if (signTypedDataMethods.has(args.method)) {
|
|
266
|
+
if (!args.params[0]) throw new Error(`Missing parameter for ${args.method}`);
|
|
267
|
+
return this.signTypedData(getTypedDataParam(args.method, args.params));
|
|
245
268
|
}
|
|
246
269
|
if (args.method === "eth_chainId") return `0x${this.chainId.toString(16)}`;
|
|
247
270
|
if (args.method === "wallet_switchEthereumChain") return this.setChainId(args.params[0]?.chainId || "0x1");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@injectivelabs/wallet-ledger",
|
|
3
|
-
"version": "1.19.
|
|
3
|
+
"version": "1.19.23",
|
|
4
4
|
"description": "Ledger wallet strategy for use with @injectivelabs/wallet-core.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -49,10 +49,10 @@
|
|
|
49
49
|
"@ledgerhq/hw-transport-webusb": "^6.29.13",
|
|
50
50
|
"buffer": "^6.0.3",
|
|
51
51
|
"viem": "^2.41.2",
|
|
52
|
-
"@injectivelabs/exceptions": "1.19.
|
|
53
|
-
"@injectivelabs/sdk-ts": "1.19.
|
|
54
|
-
"@injectivelabs/ts-types": "1.19.
|
|
55
|
-
"@injectivelabs/wallet-base": "1.19.
|
|
52
|
+
"@injectivelabs/exceptions": "1.19.23",
|
|
53
|
+
"@injectivelabs/sdk-ts": "1.19.23",
|
|
54
|
+
"@injectivelabs/ts-types": "1.19.23",
|
|
55
|
+
"@injectivelabs/wallet-base": "1.19.23"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
58
|
"@ethersproject/abi": "^5.7.0",
|