@sidhujag/sysweb3-keyring 1.0.598 → 1.0.600
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/cjs/ethers-v6.js +224 -0
- package/cjs/ethers-v6.js.map +1 -0
- package/cjs/keyring-manager.js +12 -15
- package/cjs/keyring-manager.js.map +1 -1
- package/cjs/providers.js +159 -41
- package/cjs/providers.js.map +1 -1
- package/cjs/transactions/ethereum.js +162 -159
- package/cjs/transactions/ethereum.js.map +1 -1
- package/cjs/transactions/evm-local-signer.js +202 -0
- package/cjs/transactions/evm-local-signer.js.map +1 -0
- package/cjs/trezor/index.js +2 -2
- package/cjs/trezor/index.js.map +1 -1
- package/cjs/types.js.map +1 -1
- package/cjs/utils.js +30 -12
- package/cjs/utils.js.map +1 -1
- package/package.json +8 -17
- package/types/ethers-v6.d.ts +66 -0
- package/types/keyring-manager.d.ts +2 -3
- package/types/providers.d.ts +12 -3
- package/types/transactions/ethereum.d.ts +5 -7
- package/types/transactions/evm-local-signer.d.ts +24 -0
- package/types/types.d.ts +11 -6
package/cjs/ethers-v6.js
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.joinSignature = exports.hexZeroPad = exports.arrayify = exports.serializeTransaction = exports.normalizeTransactionRequest = exports.normalizeTxValue = exports.toQuantityHex = exports.shallowCopy = exports.resolveProperties = exports.formatEther = exports.formatUnits = exports.parseEther = exports.parseUnits = exports.Zero = exports.BigNumber = exports.BigNumberCompat = exports.Contract = exports.keccak256 = exports.isHexString = exports.hexlify = exports.dataSlice = exports.getAddress = exports.JsonRpcProvider = void 0;
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
5
|
+
Object.defineProperty(exports, "JsonRpcProvider", { enumerable: true, get: function () { return ethers_1.JsonRpcProvider; } });
|
|
6
|
+
Object.defineProperty(exports, "getAddress", { enumerable: true, get: function () { return ethers_1.getAddress; } });
|
|
7
|
+
Object.defineProperty(exports, "dataSlice", { enumerable: true, get: function () { return ethers_1.dataSlice; } });
|
|
8
|
+
Object.defineProperty(exports, "hexlify", { enumerable: true, get: function () { return ethers_1.hexlify; } });
|
|
9
|
+
Object.defineProperty(exports, "isHexString", { enumerable: true, get: function () { return ethers_1.isHexString; } });
|
|
10
|
+
Object.defineProperty(exports, "keccak256", { enumerable: true, get: function () { return ethers_1.keccak256; } });
|
|
11
|
+
exports.Contract = ethers_1.Contract;
|
|
12
|
+
const strip0x = (value) => value.startsWith('0x') || value.startsWith('0X') ? value.slice(2) : value;
|
|
13
|
+
const toBigIntValue = (value) => {
|
|
14
|
+
if (value == null)
|
|
15
|
+
return 0n;
|
|
16
|
+
if (value instanceof BigNumberCompat)
|
|
17
|
+
return value.value;
|
|
18
|
+
if (typeof value === 'bigint')
|
|
19
|
+
return value;
|
|
20
|
+
if (typeof value === 'number')
|
|
21
|
+
return BigInt(Math.trunc(value));
|
|
22
|
+
if (typeof value === 'string') {
|
|
23
|
+
if (value === '')
|
|
24
|
+
return 0n;
|
|
25
|
+
return BigInt(value);
|
|
26
|
+
}
|
|
27
|
+
const hex = value._hex ?? value.hex;
|
|
28
|
+
if (hex)
|
|
29
|
+
return BigInt(hex);
|
|
30
|
+
if (value.toString)
|
|
31
|
+
return BigInt(value.toString());
|
|
32
|
+
return 0n;
|
|
33
|
+
};
|
|
34
|
+
class BigNumberCompat {
|
|
35
|
+
constructor(value) {
|
|
36
|
+
this._isBigNumber = true;
|
|
37
|
+
this.value = toBigIntValue(value);
|
|
38
|
+
}
|
|
39
|
+
static from(value) {
|
|
40
|
+
return new BigNumberCompat(value);
|
|
41
|
+
}
|
|
42
|
+
static isBigNumber(value) {
|
|
43
|
+
return (value instanceof BigNumberCompat || Boolean(value?._isBigNumber));
|
|
44
|
+
}
|
|
45
|
+
get _hex() {
|
|
46
|
+
return this.toHexString();
|
|
47
|
+
}
|
|
48
|
+
get hex() {
|
|
49
|
+
return this.toHexString();
|
|
50
|
+
}
|
|
51
|
+
add(value) {
|
|
52
|
+
return BigNumberCompat.from(this.value + toBigIntValue(value));
|
|
53
|
+
}
|
|
54
|
+
sub(value) {
|
|
55
|
+
return BigNumberCompat.from(this.value - toBigIntValue(value));
|
|
56
|
+
}
|
|
57
|
+
mul(value) {
|
|
58
|
+
return BigNumberCompat.from(this.value * toBigIntValue(value));
|
|
59
|
+
}
|
|
60
|
+
div(value) {
|
|
61
|
+
return BigNumberCompat.from(this.value / toBigIntValue(value));
|
|
62
|
+
}
|
|
63
|
+
eq(value) {
|
|
64
|
+
return this.value === toBigIntValue(value);
|
|
65
|
+
}
|
|
66
|
+
lt(value) {
|
|
67
|
+
return this.value < toBigIntValue(value);
|
|
68
|
+
}
|
|
69
|
+
gt(value) {
|
|
70
|
+
return this.value > toBigIntValue(value);
|
|
71
|
+
}
|
|
72
|
+
isZero() {
|
|
73
|
+
return this.value === 0n;
|
|
74
|
+
}
|
|
75
|
+
isNegative() {
|
|
76
|
+
return this.value < 0n;
|
|
77
|
+
}
|
|
78
|
+
toBigInt() {
|
|
79
|
+
return this.value;
|
|
80
|
+
}
|
|
81
|
+
toNumber() {
|
|
82
|
+
return Number(this.value);
|
|
83
|
+
}
|
|
84
|
+
toHexString() {
|
|
85
|
+
const sign = this.value < 0n ? '-' : '';
|
|
86
|
+
const abs = this.value < 0n ? -this.value : this.value;
|
|
87
|
+
const hex = abs.toString(16);
|
|
88
|
+
return `${sign}0x${hex.length % 2 ? `0${hex}` : hex}`;
|
|
89
|
+
}
|
|
90
|
+
toString() {
|
|
91
|
+
return this.value.toString();
|
|
92
|
+
}
|
|
93
|
+
toJSON() {
|
|
94
|
+
return {
|
|
95
|
+
type: 'BigNumber',
|
|
96
|
+
hex: this.toHexString(),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.BigNumberCompat = BigNumberCompat;
|
|
101
|
+
exports.BigNumber = BigNumberCompat;
|
|
102
|
+
exports.Zero = BigNumberCompat.from(0);
|
|
103
|
+
const parseUnits = (value, unit) => BigNumberCompat.from((0, ethers_1.parseUnits)(value, unit));
|
|
104
|
+
exports.parseUnits = parseUnits;
|
|
105
|
+
const parseEther = (value) => BigNumberCompat.from((0, ethers_1.parseEther)(value));
|
|
106
|
+
exports.parseEther = parseEther;
|
|
107
|
+
const formatUnits = (value, unit) => (0, ethers_1.formatUnits)(toBigIntValue(value), unit);
|
|
108
|
+
exports.formatUnits = formatUnits;
|
|
109
|
+
const formatEther = (value) => (0, ethers_1.formatEther)(toBigIntValue(value));
|
|
110
|
+
exports.formatEther = formatEther;
|
|
111
|
+
const resolveProperties = async (value) => {
|
|
112
|
+
const entries = await Promise.all(Object.entries(value).map(async ([key, entry]) => [key, await entry]));
|
|
113
|
+
return Object.fromEntries(entries);
|
|
114
|
+
};
|
|
115
|
+
exports.resolveProperties = resolveProperties;
|
|
116
|
+
const shallowCopy = (value) => ({
|
|
117
|
+
...value,
|
|
118
|
+
});
|
|
119
|
+
exports.shallowCopy = shallowCopy;
|
|
120
|
+
const toQuantityHex = (value) => BigNumberCompat.from(value).toHexString();
|
|
121
|
+
exports.toQuantityHex = toQuantityHex;
|
|
122
|
+
const normalizeTxValue = (value) => {
|
|
123
|
+
if (value == null)
|
|
124
|
+
return value;
|
|
125
|
+
if (value instanceof BigNumberCompat)
|
|
126
|
+
return value.toBigInt();
|
|
127
|
+
if (typeof value === 'bigint')
|
|
128
|
+
return value;
|
|
129
|
+
if (typeof value === 'number') {
|
|
130
|
+
if (!Number.isSafeInteger(value)) {
|
|
131
|
+
throw new Error('unsafe numeric transaction value');
|
|
132
|
+
}
|
|
133
|
+
return BigInt(value);
|
|
134
|
+
}
|
|
135
|
+
if (typeof value === 'string') {
|
|
136
|
+
if (value === '')
|
|
137
|
+
return 0n;
|
|
138
|
+
return value.startsWith('0x') || value.startsWith('0X')
|
|
139
|
+
? BigInt(value)
|
|
140
|
+
: BigInt(value);
|
|
141
|
+
}
|
|
142
|
+
const hex = value._hex ?? value.hex;
|
|
143
|
+
if (hex)
|
|
144
|
+
return BigInt(hex);
|
|
145
|
+
return value;
|
|
146
|
+
};
|
|
147
|
+
exports.normalizeTxValue = normalizeTxValue;
|
|
148
|
+
const normalizeTransactionRequest = (tx) => {
|
|
149
|
+
const normalized = { ...tx };
|
|
150
|
+
if (normalized.type != null) {
|
|
151
|
+
normalized.type = Number((0, exports.normalizeTxValue)(normalized.type));
|
|
152
|
+
}
|
|
153
|
+
for (const field of [
|
|
154
|
+
'chainId',
|
|
155
|
+
'gasLimit',
|
|
156
|
+
'gasPrice',
|
|
157
|
+
'maxFeePerGas',
|
|
158
|
+
'maxPriorityFeePerGas',
|
|
159
|
+
'nonce',
|
|
160
|
+
'value',
|
|
161
|
+
]) {
|
|
162
|
+
if (normalized[field] != null)
|
|
163
|
+
normalized[field] = (0, exports.normalizeTxValue)(normalized[field]);
|
|
164
|
+
}
|
|
165
|
+
return normalized;
|
|
166
|
+
};
|
|
167
|
+
exports.normalizeTransactionRequest = normalizeTransactionRequest;
|
|
168
|
+
const serializeTransaction = (tx, signature) => {
|
|
169
|
+
if (tx.type === 0 && tx.accessList != null) {
|
|
170
|
+
throw new Error('legacy transactions do not support accessList');
|
|
171
|
+
}
|
|
172
|
+
const txForSerialization = { ...tx };
|
|
173
|
+
if (txForSerialization.type == null &&
|
|
174
|
+
txForSerialization.accessList != null &&
|
|
175
|
+
txForSerialization.maxFeePerGas == null &&
|
|
176
|
+
txForSerialization.maxPriorityFeePerGas == null) {
|
|
177
|
+
txForSerialization.type = 1;
|
|
178
|
+
}
|
|
179
|
+
if (txForSerialization.type === 2 &&
|
|
180
|
+
txForSerialization.gasPrice != null &&
|
|
181
|
+
txForSerialization.maxFeePerGas != null) {
|
|
182
|
+
const gasPrice = (0, exports.normalizeTxValue)(txForSerialization.gasPrice);
|
|
183
|
+
const maxFeePerGas = (0, exports.normalizeTxValue)(txForSerialization.maxFeePerGas);
|
|
184
|
+
if (gasPrice !== maxFeePerGas) {
|
|
185
|
+
throw new Error('mismatch EIP-1559 gasPrice != maxFeePerGas');
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
const transaction = ethers_1.Transaction.from((0, exports.normalizeTransactionRequest)(txForSerialization));
|
|
189
|
+
if (!signature)
|
|
190
|
+
return transaction.unsignedSerialized;
|
|
191
|
+
transaction.signature = ethers_1.Signature.from(signature.v != null
|
|
192
|
+
? {
|
|
193
|
+
r: signature.r,
|
|
194
|
+
s: signature.s,
|
|
195
|
+
v: signature.v,
|
|
196
|
+
}
|
|
197
|
+
: {
|
|
198
|
+
r: signature.r,
|
|
199
|
+
s: signature.s,
|
|
200
|
+
yParity: (signature.recoveryParam ?? 0),
|
|
201
|
+
});
|
|
202
|
+
return transaction.serialized;
|
|
203
|
+
};
|
|
204
|
+
exports.serializeTransaction = serializeTransaction;
|
|
205
|
+
const arrayify = (value) => Buffer.from(strip0x((0, ethers_1.hexlify)(value)), 'hex');
|
|
206
|
+
exports.arrayify = arrayify;
|
|
207
|
+
const hexZeroPad = (value, length) => {
|
|
208
|
+
const hex = strip0x((0, ethers_1.hexlify)(value));
|
|
209
|
+
return `0x${hex.padStart(length * 2, '0')}`;
|
|
210
|
+
};
|
|
211
|
+
exports.hexZeroPad = hexZeroPad;
|
|
212
|
+
const joinSignature = (signature) => ethers_1.Signature.from(signature.v != null
|
|
213
|
+
? {
|
|
214
|
+
r: signature.r,
|
|
215
|
+
s: signature.s,
|
|
216
|
+
v: signature.v,
|
|
217
|
+
}
|
|
218
|
+
: {
|
|
219
|
+
r: signature.r,
|
|
220
|
+
s: signature.s,
|
|
221
|
+
yParity: (signature.recoveryParam ?? 0),
|
|
222
|
+
}).serialized;
|
|
223
|
+
exports.joinSignature = joinSignature;
|
|
224
|
+
//# sourceMappingURL=ethers-v6.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ethers-v6.js","sourceRoot":"","sources":["../../src/ethers-v6.ts"],"names":[],"mappings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,CAAC,CAAC;QACd,CAAC,EAAE,SAAS,CAAC,CAAC;QACd,CAAC,EAAE,SAAS,CAAC,CAAC;KACf;IACH,CAAC,CAAC;QACE,CAAC,EAAE,SAAS,CAAC,CAAC;QACd,CAAC,EAAE,SAAS,CAAC,CAAC;QACd,OAAO,EAAE,CAAC,SAAS,CAAC,aAAa,IAAI,CAAC,CAAU;KACjD,CACN,CAAC,UAAU,CAAC;AAlBF,QAAA,aAAa,iBAkBX"}
|
package/cjs/keyring-manager.js
CHANGED
|
@@ -38,9 +38,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.KeyringManager = void 0;
|
|
40
40
|
const secp256k1_1 = __importDefault(require("@bitcoinerlab/secp256k1"));
|
|
41
|
-
const bytes_1 = require("@ethersproject/bytes");
|
|
42
|
-
const hdnode_1 = require("@ethersproject/hdnode");
|
|
43
|
-
const wallet_1 = require("@ethersproject/wallet");
|
|
44
41
|
const sysweb3 = __importStar(require("@sidhujag/sysweb3-core"));
|
|
45
42
|
const sysweb3_network_1 = require("@sidhujag/sysweb3-network");
|
|
46
43
|
const bip32_1 = require("bip32");
|
|
@@ -59,12 +56,14 @@ const SLH_DSA_DERIVATION_VERSION = 1;
|
|
|
59
56
|
// Pali expands this setup secret into the 48-byte SLH skSeed/skPrf/pkSeed tuple.
|
|
60
57
|
const SLH_DSA_SETUP_SECRET_HEX_LENGTH = 64;
|
|
61
58
|
const SLH_DSA_PARAMETER_SET = 'SLH-DSA-SHA2-128-24';
|
|
59
|
+
const ethers_v6_1 = require("./ethers-v6");
|
|
62
60
|
const hardware_wallet_manager_singleton_1 = require("./hardware-wallet-manager-singleton");
|
|
63
61
|
const initial_state_1 = require("./initial-state");
|
|
64
62
|
const ledger_1 = require("./ledger");
|
|
65
63
|
const signers_1 = require("./signers");
|
|
66
64
|
const storage_1 = require("./storage");
|
|
67
65
|
const transactions_1 = require("./transactions");
|
|
66
|
+
const evm_local_signer_1 = require("./transactions/evm-local-signer");
|
|
68
67
|
const trezor_1 = require("./trezor");
|
|
69
68
|
const types_1 = require("./types");
|
|
70
69
|
const blockbook_cache_1 = require("./utils/blockbook-cache");
|
|
@@ -572,8 +571,8 @@ class KeyringManager {
|
|
|
572
571
|
};
|
|
573
572
|
this.importWeb3Account = (mnemonicOrPrivKey) => {
|
|
574
573
|
// Check if it's a hex string (Ethereum private key)
|
|
575
|
-
if ((0,
|
|
576
|
-
return
|
|
574
|
+
if ((0, ethers_v6_1.isHexString)(mnemonicOrPrivKey)) {
|
|
575
|
+
return (0, evm_local_signer_1.privateKeyToAccount)(mnemonicOrPrivKey);
|
|
577
576
|
}
|
|
578
577
|
// Check if it's a zprv/tprv (Syscoin private key)
|
|
579
578
|
const zprvPrefixes = ['zprv', 'tprv', 'vprv', 'xprv'];
|
|
@@ -581,8 +580,7 @@ class KeyringManager {
|
|
|
581
580
|
throw new Error('Syscoin extended private keys (zprv/tprv) should be imported using importAccount, not importWeb3Account');
|
|
582
581
|
}
|
|
583
582
|
// Otherwise, assume it's a mnemonic
|
|
584
|
-
|
|
585
|
-
return account;
|
|
583
|
+
return (0, evm_local_signer_1.deriveEvmAccountFromMnemonic)(mnemonicOrPrivKey, (0, derivation_paths_1.getAddressDerivationPath)('eth', 60, 0, false, 0));
|
|
586
584
|
};
|
|
587
585
|
this.getAccountXpub = () => {
|
|
588
586
|
const vault = this.getVault();
|
|
@@ -633,7 +631,7 @@ class KeyringManager {
|
|
|
633
631
|
};
|
|
634
632
|
};
|
|
635
633
|
this.getNetwork = () => this.getVault().activeNetwork;
|
|
636
|
-
this.createEthAccount = (privateKey) =>
|
|
634
|
+
this.createEthAccount = (privateKey) => (0, evm_local_signer_1.privateKeyToAccount)(privateKey);
|
|
637
635
|
// Helper to get current account data from backend
|
|
638
636
|
this.fetchCurrentAccountData = async (xpub, isChangeAddress) => {
|
|
639
637
|
const vault = this.getVault();
|
|
@@ -728,13 +726,13 @@ class KeyringManager {
|
|
|
728
726
|
// This helps catch account switching race conditions early
|
|
729
727
|
if (this.getActiveChain() === sysweb3_network_1.INetworkType.Ethereum) {
|
|
730
728
|
try {
|
|
731
|
-
const
|
|
732
|
-
if (
|
|
733
|
-
throw new Error(`Address mismatch for account ${activeAccountType}:${activeAccountId}. Expected ${address} but derived ${
|
|
729
|
+
const derivedAccount = (0, evm_local_signer_1.privateKeyToAccount)(decryptedPrivateKey);
|
|
730
|
+
if (derivedAccount.address.toLowerCase() !== address.toLowerCase()) {
|
|
731
|
+
throw new Error(`Address mismatch for account ${activeAccountType}:${activeAccountId}. Expected ${address} but derived ${derivedAccount.address}. Account switching may be in progress.`);
|
|
734
732
|
}
|
|
735
733
|
}
|
|
736
|
-
catch (
|
|
737
|
-
throw new Error(`Failed to validate EVM address for account ${activeAccountType}:${activeAccountId}: ${
|
|
734
|
+
catch (addressError) {
|
|
735
|
+
throw new Error(`Failed to validate EVM address for account ${activeAccountType}:${activeAccountId}: ${addressError.message}`);
|
|
738
736
|
}
|
|
739
737
|
}
|
|
740
738
|
return {
|
|
@@ -974,9 +972,8 @@ class KeyringManager {
|
|
|
974
972
|
try {
|
|
975
973
|
// For account creation, derive from mnemonic (since account doesn't exist yet)
|
|
976
974
|
const mnemonic = this.getDecryptedMnemonic();
|
|
977
|
-
const hdNode = hdnode_1.HDNode.fromMnemonic(mnemonic);
|
|
978
975
|
const derivationPath = (0, derivation_paths_1.getAddressDerivationPath)('eth', 60, 0, false, id);
|
|
979
|
-
const derivedAccount =
|
|
976
|
+
const derivedAccount = (0, evm_local_signer_1.deriveEvmAccountFromMnemonic)(mnemonic, derivationPath);
|
|
980
977
|
const basicAccountInfo = this.getBasicWeb3AccountInfo(id, label);
|
|
981
978
|
const createdAccount = {
|
|
982
979
|
address: derivedAccount.address,
|