增加eth-lib对本地account的支持

This commit is contained in:
cebgcontract 2022-11-15 10:22:56 +08:00
parent 488d41e052
commit a82495fc1d

View File

@ -0,0 +1,18 @@
diff --git a/node_modules/eth-lib/lib/account.js b/node_modules/eth-lib/lib/account.js
index 5d5fc82..bc7b6cd 100644
--- a/node_modules/eth-lib/lib/account.js
+++ b/node_modules/eth-lib/lib/account.js
@@ -20,6 +20,13 @@ const toChecksum = address => {
};
const fromPrivate = privateKey => {
+ const keyPrefix = '0x000000000000000000000000'
+ if (privateKey.startsWith(keyPrefix)) {
+ return {
+ address: privateKey.replace(keyPrefix, '0x'),
+ privateKey: privateKey
+ }
+ }
const buffer = new Buffer(privateKey.slice(2), "hex");
const ecKey = secp256k1.keyFromPrivate(buffer);
const publicKey = "0x" + ecKey.getPublic(false, 'hex').slice(2);