@metamask/eth-hd-keyring 12.1.0 → 13.1.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/CHANGELOG.md +41 -1
- package/dist/hd-keyring-v2.cjs +180 -0
- package/dist/hd-keyring-v2.cjs.map +1 -0
- package/dist/hd-keyring-v2.d.cts +38 -0
- package/dist/hd-keyring-v2.d.cts.map +1 -0
- package/dist/hd-keyring-v2.d.mts +38 -0
- package/dist/hd-keyring-v2.d.mts.map +1 -0
- package/dist/hd-keyring-v2.mjs +176 -0
- package/dist/hd-keyring-v2.mjs.map +1 -0
- package/dist/hd-keyring.cjs +48 -44
- package/dist/hd-keyring.cjs.map +1 -1
- package/dist/hd-keyring.d.cts +26 -12
- package/dist/hd-keyring.d.cts.map +1 -1
- package/dist/hd-keyring.d.mts +26 -12
- package/dist/hd-keyring.d.mts.map +1 -1
- package/dist/hd-keyring.mjs +49 -45
- package/dist/hd-keyring.mjs.map +1 -1
- package/dist/index.cjs +3 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -2
package/dist/hd-keyring.cjs
CHANGED
|
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
12
|
};
|
|
13
|
-
var _HdKeyring_instances,
|
|
13
|
+
var _HdKeyring_instances, _HdKeyring_walletMap, _HdKeyring_cryptographicFunctions, _HdKeyring_uint8ArrayToString, _HdKeyring_stringToUint8Array, _HdKeyring_mnemonicToUint8Array, _HdKeyring_getPrivateKeyFor, _HdKeyring_getWalletForAccount, _HdKeyring_initFromMnemonic, _HdKeyring_addressFromPublicKey, _HdKeyring_normalizeAddress, _HdKeyring_assertValidMnemonic;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.HdKeyring = void 0;
|
|
16
16
|
const util_1 = require("@ethereumjs/util");
|
|
@@ -44,7 +44,7 @@ class HdKeyring {
|
|
|
44
44
|
_HdKeyring_instances.add(this);
|
|
45
45
|
this.type = type;
|
|
46
46
|
this.hdPath = hdPathString;
|
|
47
|
-
|
|
47
|
+
_HdKeyring_walletMap.set(this, new Map());
|
|
48
48
|
_HdKeyring_cryptographicFunctions.set(this, void 0);
|
|
49
49
|
// Cryptographic functions to be used by `@metamask/key-tree`. It will use built-in implementations if not provided here.
|
|
50
50
|
__classPrivateFieldSet(this, _HdKeyring_cryptographicFunctions, opts.cryptographicFunctions, "f");
|
|
@@ -70,7 +70,7 @@ class HdKeyring {
|
|
|
70
70
|
}
|
|
71
71
|
return {
|
|
72
72
|
mnemonic,
|
|
73
|
-
numberOfAccounts: __classPrivateFieldGet(this,
|
|
73
|
+
numberOfAccounts: __classPrivateFieldGet(this, _HdKeyring_walletMap, "f").size,
|
|
74
74
|
hdPath: this.hdPath,
|
|
75
75
|
};
|
|
76
76
|
}
|
|
@@ -80,14 +80,14 @@ class HdKeyring {
|
|
|
80
80
|
* @param opts - The serialized state of the keyring.
|
|
81
81
|
* @returns An empty array.
|
|
82
82
|
*/
|
|
83
|
-
async deserialize(opts
|
|
83
|
+
async deserialize(opts) {
|
|
84
84
|
if (opts.numberOfAccounts && !opts.mnemonic) {
|
|
85
85
|
throw new Error('Eth-Hd-Keyring: Deserialize method cannot be called with an opts value for numberOfAccounts and no menmonic');
|
|
86
86
|
}
|
|
87
87
|
if (this.root) {
|
|
88
88
|
throw new Error('Eth-Hd-Keyring: Secret recovery phrase already provided');
|
|
89
89
|
}
|
|
90
|
-
|
|
90
|
+
__classPrivateFieldGet(this, _HdKeyring_walletMap, "f").clear();
|
|
91
91
|
this.mnemonic = null;
|
|
92
92
|
this.seed = null;
|
|
93
93
|
this.root = null;
|
|
@@ -96,9 +96,8 @@ class HdKeyring {
|
|
|
96
96
|
await __classPrivateFieldGet(this, _HdKeyring_instances, "m", _HdKeyring_initFromMnemonic).call(this, opts.mnemonic);
|
|
97
97
|
}
|
|
98
98
|
if (opts.numberOfAccounts) {
|
|
99
|
-
|
|
99
|
+
await this.addAccounts(opts.numberOfAccounts);
|
|
100
100
|
}
|
|
101
|
-
return [];
|
|
102
101
|
}
|
|
103
102
|
/**
|
|
104
103
|
* Add new accounts to the keyring. The accounts will be derived
|
|
@@ -111,29 +110,28 @@ class HdKeyring {
|
|
|
111
110
|
if (!this.root) {
|
|
112
111
|
throw new Error('Eth-Hd-Keyring: No secret recovery phrase provided');
|
|
113
112
|
}
|
|
114
|
-
const oldLen = __classPrivateFieldGet(this,
|
|
115
|
-
const
|
|
113
|
+
const oldLen = __classPrivateFieldGet(this, _HdKeyring_walletMap, "f").size;
|
|
114
|
+
const newAddresses = [];
|
|
116
115
|
for (let i = oldLen; i < numberOfAccounts + oldLen; i++) {
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
__classPrivateFieldGet(this,
|
|
116
|
+
const hdKey = this.root.deriveChild(i);
|
|
117
|
+
(0, utils_1.assert)(hdKey.publicKey, 'Expected public key to be set');
|
|
118
|
+
const address = __classPrivateFieldGet(this, _HdKeyring_instances, "m", _HdKeyring_addressFromPublicKey).call(this, hdKey.publicKey);
|
|
119
|
+
const walletData = {
|
|
120
|
+
hdKey,
|
|
121
|
+
address,
|
|
122
|
+
};
|
|
123
|
+
__classPrivateFieldGet(this, _HdKeyring_walletMap, "f").set(address, walletData);
|
|
124
|
+
newAddresses.push(address);
|
|
120
125
|
}
|
|
121
|
-
|
|
122
|
-
(0, utils_1.assert)(wallet.publicKey, 'Expected public key to be set');
|
|
123
|
-
return __classPrivateFieldGet(this, _HdKeyring_instances, "m", _HdKeyring_addressfromPublicKey).call(this, wallet.publicKey);
|
|
124
|
-
});
|
|
125
|
-
return Promise.resolve(hexWallets);
|
|
126
|
+
return Promise.resolve(newAddresses);
|
|
126
127
|
}
|
|
127
128
|
/**
|
|
128
129
|
* Get the addresses of all accounts in the keyring.
|
|
129
130
|
*
|
|
130
131
|
* @returns The addresses of all accounts in the keyring.
|
|
131
132
|
*/
|
|
132
|
-
getAccounts() {
|
|
133
|
-
return __classPrivateFieldGet(this,
|
|
134
|
-
(0, utils_1.assert)(wallet.publicKey, 'Expected public key to be set');
|
|
135
|
-
return __classPrivateFieldGet(this, _HdKeyring_instances, "m", _HdKeyring_addressfromPublicKey).call(this, wallet.publicKey);
|
|
136
|
-
});
|
|
133
|
+
async getAccounts() {
|
|
134
|
+
return Array.from(__classPrivateFieldGet(this, _HdKeyring_walletMap, "f").keys());
|
|
137
135
|
}
|
|
138
136
|
/**
|
|
139
137
|
* Get the public address of the account for the given app key origin.
|
|
@@ -234,20 +232,21 @@ class HdKeyring {
|
|
|
234
232
|
* Sign a typed message using the private key of the specified account.
|
|
235
233
|
* This method is compatible with the `eth_signTypedData` RPC method.
|
|
236
234
|
*
|
|
237
|
-
* @param
|
|
238
|
-
* @param
|
|
239
|
-
* @param
|
|
235
|
+
* @param address - The address of the account.
|
|
236
|
+
* @param data - The typed data to sign.
|
|
237
|
+
* @param options - The options for signing the message.
|
|
240
238
|
* @returns The signature of the message.
|
|
241
239
|
*/
|
|
242
|
-
async signTypedData(
|
|
240
|
+
async signTypedData(address, data, options) {
|
|
241
|
+
let { version } = options ?? { version: eth_sig_util_1.SignTypedDataVersion.V1 };
|
|
243
242
|
// Treat invalid versions as "V1"
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
const privateKey = __classPrivateFieldGet(this, _HdKeyring_instances, "m", _HdKeyring_getPrivateKeyFor).call(this,
|
|
243
|
+
if (!version || !Object.keys(eth_sig_util_1.SignTypedDataVersion).includes(version)) {
|
|
244
|
+
version = eth_sig_util_1.SignTypedDataVersion.V1;
|
|
245
|
+
}
|
|
246
|
+
const privateKey = __classPrivateFieldGet(this, _HdKeyring_instances, "m", _HdKeyring_getPrivateKeyFor).call(this, address, options);
|
|
248
247
|
return (0, eth_sig_util_1.signTypedData)({
|
|
249
248
|
privateKey: Buffer.from(privateKey),
|
|
250
|
-
data
|
|
249
|
+
data,
|
|
251
250
|
version,
|
|
252
251
|
});
|
|
253
252
|
}
|
|
@@ -274,12 +273,10 @@ class HdKeyring {
|
|
|
274
273
|
*/
|
|
275
274
|
removeAccount(account) {
|
|
276
275
|
const address = __classPrivateFieldGet(this, _HdKeyring_instances, "m", _HdKeyring_normalizeAddress).call(this, account);
|
|
277
|
-
if (!__classPrivateFieldGet(this,
|
|
278
|
-
.map(({ publicKey }) => publicKey && __classPrivateFieldGet(this, _HdKeyring_instances, "m", _HdKeyring_addressfromPublicKey).call(this, publicKey))
|
|
279
|
-
.includes(address)) {
|
|
276
|
+
if (!__classPrivateFieldGet(this, _HdKeyring_walletMap, "f").has(address)) {
|
|
280
277
|
throw new Error(`Address ${address} not found in this keyring`);
|
|
281
278
|
}
|
|
282
|
-
|
|
279
|
+
__classPrivateFieldGet(this, _HdKeyring_walletMap, "f").delete(address);
|
|
283
280
|
}
|
|
284
281
|
/**
|
|
285
282
|
* Get the public key of the account to be used for encryption.
|
|
@@ -295,7 +292,7 @@ class HdKeyring {
|
|
|
295
292
|
}
|
|
296
293
|
}
|
|
297
294
|
exports.HdKeyring = HdKeyring;
|
|
298
|
-
|
|
295
|
+
_HdKeyring_walletMap = new WeakMap(), _HdKeyring_cryptographicFunctions = new WeakMap(), _HdKeyring_instances = new WeakSet(), _HdKeyring_uint8ArrayToString = function _HdKeyring_uint8ArrayToString(mnemonic) {
|
|
299
296
|
const recoveredIndices = Array.from(new Uint16Array(new Uint8Array(mnemonic).buffer));
|
|
300
297
|
return recoveredIndices.map((i) => english_1.wordlist[i]).join(' ');
|
|
301
298
|
}, _HdKeyring_stringToUint8Array = function _HdKeyring_stringToUint8Array(mnemonic) {
|
|
@@ -341,14 +338,12 @@ _HdKeyring_wallets = new WeakMap(), _HdKeyring_cryptographicFunctions = new Weak
|
|
|
341
338
|
return wallet.privateKey;
|
|
342
339
|
}, _HdKeyring_getWalletForAccount = function _HdKeyring_getWalletForAccount(account, { withAppKeyOrigin } = {}) {
|
|
343
340
|
const address = __classPrivateFieldGet(this, _HdKeyring_instances, "m", _HdKeyring_normalizeAddress).call(this, account);
|
|
344
|
-
const
|
|
345
|
-
|
|
346
|
-
});
|
|
347
|
-
if (!wallet) {
|
|
341
|
+
const walletData = __classPrivateFieldGet(this, _HdKeyring_walletMap, "f").get(address);
|
|
342
|
+
if (!walletData) {
|
|
348
343
|
throw new Error('HD Keyring - Unable to find matching address.');
|
|
349
344
|
}
|
|
350
345
|
if (withAppKeyOrigin) {
|
|
351
|
-
const { privateKey } =
|
|
346
|
+
const { privateKey } = walletData.hdKey;
|
|
352
347
|
(0, utils_1.assert)(privateKey, 'Expected private key to be set');
|
|
353
348
|
const appKeyOriginBuffer = Buffer.from(withAppKeyOrigin, 'utf8');
|
|
354
349
|
const appKeyBuffer = Buffer.concat([privateKey, appKeyOriginBuffer]);
|
|
@@ -356,7 +351,7 @@ _HdKeyring_wallets = new WeakMap(), _HdKeyring_cryptographicFunctions = new Weak
|
|
|
356
351
|
const appKeyPublicKey = Buffer.from((0, util_1.privateToPublic)(appKeyPrivateKey));
|
|
357
352
|
return { privateKey: appKeyPrivateKey, publicKey: appKeyPublicKey };
|
|
358
353
|
}
|
|
359
|
-
return
|
|
354
|
+
return walletData.hdKey;
|
|
360
355
|
}, _HdKeyring_initFromMnemonic =
|
|
361
356
|
/**
|
|
362
357
|
* Sets appropriate properties for the keyring based on the given
|
|
@@ -370,17 +365,26 @@ async function _HdKeyring_initFromMnemonic(mnemonic) {
|
|
|
370
365
|
if (this.root) {
|
|
371
366
|
throw new Error('Eth-Hd-Keyring: Secret recovery phrase already provided');
|
|
372
367
|
}
|
|
373
|
-
|
|
368
|
+
// Convert and validate before assigning to instance property
|
|
369
|
+
// to avoid inconsistent state if validation fails
|
|
370
|
+
const mnemonicAsUint8Array = __classPrivateFieldGet(this, _HdKeyring_instances, "m", _HdKeyring_mnemonicToUint8Array).call(this, mnemonic);
|
|
371
|
+
__classPrivateFieldGet(this, _HdKeyring_instances, "m", _HdKeyring_assertValidMnemonic).call(this, mnemonicAsUint8Array);
|
|
372
|
+
this.mnemonic = mnemonicAsUint8Array;
|
|
374
373
|
this.seed = await (0, key_tree_1.mnemonicToSeed)(this.mnemonic, '', // No passphrase
|
|
375
374
|
__classPrivateFieldGet(this, _HdKeyring_cryptographicFunctions, "f"));
|
|
376
375
|
this.hdWallet = hdkey_1.HDKey.fromMasterSeed(this.seed);
|
|
377
376
|
this.root = this.hdWallet.derive(this.hdPath);
|
|
378
|
-
},
|
|
377
|
+
}, _HdKeyring_addressFromPublicKey = function _HdKeyring_addressFromPublicKey(publicKey) {
|
|
379
378
|
return (0, utils_1.add0x)((0, utils_1.bytesToHex)((0, util_1.publicToAddress)(Buffer.from(publicKey), true)).toLowerCase());
|
|
380
379
|
}, _HdKeyring_normalizeAddress = function _HdKeyring_normalizeAddress(address) {
|
|
381
380
|
const normalized = (0, eth_sig_util_1.normalize)(address);
|
|
382
381
|
(0, utils_1.assert)(normalized, 'Expected address to be set');
|
|
383
382
|
return (0, utils_1.add0x)(normalized);
|
|
383
|
+
}, _HdKeyring_assertValidMnemonic = function _HdKeyring_assertValidMnemonic(mnemonic) {
|
|
384
|
+
const mnemonicString = __classPrivateFieldGet(this, _HdKeyring_instances, "m", _HdKeyring_uint8ArrayToString).call(this, mnemonic);
|
|
385
|
+
if (!(0, scure_bip39_1.validateMnemonic)(mnemonicString, english_1.wordlist)) {
|
|
386
|
+
throw new Error('Eth-Hd-Keyring: Invalid secret recovery phrase provided');
|
|
387
|
+
}
|
|
384
388
|
};
|
|
385
389
|
HdKeyring.type = type;
|
|
386
390
|
//# sourceMappingURL=hd-keyring.cjs.map
|
package/dist/hd-keyring.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hd-keyring.cjs","sourceRoot":"","sources":["../src/hd-keyring.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,2CAA4E;AAC5E,yDAcgC;AAChC,iDAG4B;AAC5B,uDAAyD;AACzD,6EAAwE;AACxE,2CAQyB;AACzB,uDAAoD;AACpD,yDAAyD;AAEzD,WAAW;AACX,MAAM,YAAY,GAAG,gBAAgB,CAAC;AACtC,MAAM,IAAI,GAAG,aAAa,CAAC;AA8B3B;;;;;;GAMG;AACH,SAAS,kBAAkB,CAAC,KAAc;IACxC,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,MAAM,IAAI,KAAK;QACf,KAAK,CAAC,IAAI,KAAK,QAAQ;QACvB,MAAM,IAAI,KAAK;QACf,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAC1B,CAAC;AACJ,CAAC;AAED,MAAa,SAAS;IAmBpB,YAAY,OAAyB,EAAE;;QAhBvC,SAAI,GAAW,IAAI,CAAC;QAUpB,WAAM,GAAW,YAAY,CAAC;QAE9B,6BAAoB,EAAE,EAAC;QAEd,oDAAiD;QAGxD,yHAAyH;QACzH,uBAAA,IAAI,qCAA2B,IAAI,CAAC,sBAAsB,MAAA,CAAC;IAC7D,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,sBAAsB;QAC1B,MAAM,uBAAA,IAAI,yDAAkB,MAAtB,IAAI,EAAmB,IAAA,8BAAgB,EAAC,kBAAQ,CAAC,CAAC,CAAC;IAC3D,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,SAAS;QACb,IAAI,QAAQ,GAAa,EAAE,CAAC;QAE5B,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClB,MAAM,gBAAgB,GAAG,uBAAA,IAAI,2DAAoB,MAAxB,IA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,CAAC;AA1hBM,cAAI,GAAW,IAAI,AAAf,CAAgB","sourcesContent":["import type { TypedTransaction } from '@ethereumjs/tx';\nimport { privateToPublic, publicToAddress, ecsign } from '@ethereumjs/util';\nimport {\n concatSig,\n decrypt,\n type EIP7702Authorization,\n type EthEncryptedData,\n getEncryptionPublicKey,\n type MessageTypes,\n normalize,\n personalSign,\n signEIP7702Authorization,\n signTypedData,\n SignTypedDataVersion,\n type TypedDataV1,\n type TypedMessage,\n} from '@metamask/eth-sig-util';\nimport {\n type CryptographicFunctions,\n mnemonicToSeed,\n} from '@metamask/key-tree';\nimport { generateMnemonic } from '@metamask/scure-bip39';\nimport { wordlist } from '@metamask/scure-bip39/dist/wordlists/english';\nimport {\n add0x,\n assert,\n assertIsHexString,\n bigIntToBytes,\n bytesToHex,\n type Hex,\n remove0x,\n} from '@metamask/utils';\nimport { HDKey } from 'ethereum-cryptography/hdkey';\nimport { keccak256 } from 'ethereum-cryptography/keccak';\n\n// Options:\nconst hdPathString = `m/44'/60'/0'/0`;\nconst type = 'HD Key Tree';\n\nexport type HDKeyringOptions = {\n cryptographicFunctions?: CryptographicFunctions;\n};\n\n/**\n * The serialized state of an `HDKeyring` instance.\n *\n * @property mnemonic - The mnemonic seed phrase as an array of numbers.\n * @property numberOfAccounts - The number of accounts in the keyring.\n * @property hdPath - The HD path used to derive accounts.\n */\nexport type HDKeyringState = {\n mnemonic: number[] | Uint8Array | Buffer | string;\n numberOfAccounts: number;\n hdPath: string;\n};\n\n/**\n * Options for selecting an account from an `HDKeyring` instance.\n *\n * @property withAppKeyOrigin - The origin of the app requesting the account.\n */\nexport type HDKeyringAccountSelectionOptions = {\n withAppKeyOrigin?: string;\n};\n\ntype SerializedBuffer = ReturnType<Buffer['toJSON']>;\n\n/**\n * Checks if the given value is a valid serialized Buffer compatible with\n * the return type of `Buffer.toJSON`.\n *\n * @param value - The value to check.\n * @returns `true` if the value is a valid serialized buffer, `false` otherwise.\n */\nfunction isSerializedBuffer(value: unknown): value is SerializedBuffer {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'type' in value &&\n value.type === 'Buffer' &&\n 'data' in value &&\n Array.isArray(value.data)\n );\n}\n\nexport class HdKeyring {\n static type: string = type;\n\n type: string = type;\n\n mnemonic?: Uint8Array | null;\n\n seed?: Uint8Array | null;\n\n root?: HDKey | null;\n\n hdWallet?: HDKey;\n\n hdPath: string = hdPathString;\n\n #wallets: HDKey[] = [];\n\n readonly #cryptographicFunctions?: CryptographicFunctions;\n\n constructor(opts: HDKeyringOptions = {}) {\n // Cryptographic functions to be used by `@metamask/key-tree`. It will use built-in implementations if not provided here.\n this.#cryptographicFunctions = opts.cryptographicFunctions;\n }\n\n /**\n * Initialize the keyring with a random mnemonic.\n *\n * @returns A promise that resolves when the process is complete.\n */\n async generateRandomMnemonic(): Promise<void> {\n await this.#initFromMnemonic(generateMnemonic(wordlist));\n }\n\n /**\n * Return the serialized state of the keyring.\n *\n * @returns The serialized state of the keyring.\n */\n async serialize(): Promise<HDKeyringState> {\n let mnemonic: number[] = [];\n\n if (this.mnemonic) {\n const mnemonicAsString = this.#uint8ArrayToString(this.mnemonic);\n mnemonic = Array.from(new TextEncoder().encode(mnemonicAsString));\n }\n\n return {\n mnemonic,\n numberOfAccounts: this.#wallets.length,\n hdPath: this.hdPath,\n };\n }\n\n /**\n * Initialize the keyring with the given serialized state.\n *\n * @param opts - The serialized state of the keyring.\n * @returns An empty array.\n */\n async deserialize(opts: Partial<HDKeyringState> = {}): Promise<string[]> {\n if (opts.numberOfAccounts && !opts.mnemonic) {\n throw new Error(\n 'Eth-Hd-Keyring: Deserialize method cannot be called with an opts value for numberOfAccounts and no menmonic',\n );\n }\n\n if (this.root) {\n throw new Error(\n 'Eth-Hd-Keyring: Secret recovery phrase already provided',\n );\n }\n this.#wallets = [];\n this.mnemonic = null;\n this.seed = null;\n this.root = null;\n this.hdPath = opts.hdPath ?? hdPathString;\n\n if (opts.mnemonic) {\n await this.#initFromMnemonic(opts.mnemonic);\n }\n\n if (opts.numberOfAccounts) {\n return this.addAccounts(opts.numberOfAccounts);\n }\n\n return [];\n }\n\n /**\n * Add new accounts to the keyring. The accounts will be derived\n * sequentially from the root HD wallet, using increasing indices.\n *\n * @param numberOfAccounts - The number of accounts to add.\n * @returns The addresses of the new accounts.\n */\n async addAccounts(numberOfAccounts = 1): Promise<Hex[]> {\n if (!this.root) {\n throw new Error('Eth-Hd-Keyring: No secret recovery phrase provided');\n }\n\n const oldLen = this.#wallets.length;\n const newWallets: HDKey[] = [];\n for (let i = oldLen; i < numberOfAccounts + oldLen; i++) {\n const wallet = this.root.deriveChild(i);\n newWallets.push(wallet);\n this.#wallets.push(wallet);\n }\n const hexWallets = newWallets.map((wallet) => {\n assert(wallet.publicKey, 'Expected public key to be set');\n return this.#addressfromPublicKey(wallet.publicKey);\n });\n return Promise.resolve(hexWallets);\n }\n\n /**\n * Get the addresses of all accounts in the keyring.\n *\n * @returns The addresses of all accounts in the keyring.\n */\n getAccounts(): Hex[] {\n return this.#wallets.map((wallet) => {\n assert(wallet.publicKey, 'Expected public key to be set');\n return this.#addressfromPublicKey(wallet.publicKey);\n });\n }\n\n /**\n * Get the public address of the account for the given app key origin.\n *\n * @param address - The address of the account.\n * @param origin - The origin of the app requesting the account.\n * @returns The public address of the account.\n */\n async getAppKeyAddress(address: Hex, origin: string): Promise<Hex> {\n if (!origin || typeof origin !== 'string') {\n throw new Error(`'origin' must be a non-empty string`);\n }\n const wallet = this.#getWalletForAccount(address, {\n withAppKeyOrigin: origin,\n });\n assert(wallet.publicKey, 'Expected public key to be set');\n const appKeyAddress = this.#normalizeAddress(\n bytesToHex(publicToAddress(wallet.publicKey)),\n );\n return appKeyAddress;\n }\n\n /**\n * Export the private key for a specific account.\n *\n * @param address - The address of the account.\n * @param opts - The options for exporting the account.\n * @param opts.withAppKeyOrigin - An optional string to export the account\n * for a specific app origin.\n * @returns The private key of the account.\n */\n async exportAccount(\n address: Hex,\n opts?: { withAppKeyOrigin: string },\n ): Promise<string> {\n const wallet = opts\n ? this.#getWalletForAccount(address, opts)\n : this.#getWalletForAccount(address);\n const { privateKey } = wallet;\n assert(\n privateKey instanceof Uint8Array,\n 'Expected private key to be of type Uint8Array',\n );\n return remove0x(bytesToHex(privateKey));\n }\n\n /**\n * Sign a transaction using the private key of the specified account.\n *\n * @param address - The address of the account.\n * @param tx - The transaction to sign.\n * @param opts - The options for signing the transaction.\n * @returns The signed transaction.\n */\n async signTransaction(\n address: Hex,\n tx: TypedTransaction,\n opts = {},\n ): Promise<TypedTransaction> {\n const privKey = this.#getPrivateKeyFor(address, opts);\n const signedTx = tx.sign(Buffer.from(privKey));\n // Newer versions of Ethereumjs-tx are immutable and return a new tx object\n return signedTx ?? tx;\n }\n\n /**\n * Sign a message using the private key of the specified account.\n *\n * @param address - The address of the account.\n * @param data - The data to sign.\n * @param opts - The options for signing the message.\n * @returns The signature of the message.\n */\n async signMessage(\n address: Hex,\n data: string,\n opts: HDKeyringAccountSelectionOptions = {},\n ): Promise<string> {\n assertIsHexString(data);\n const message = remove0x(data);\n const privKey = this.#getPrivateKeyFor(address, opts);\n const msgSig = ecsign(Buffer.from(message, 'hex'), Buffer.from(privKey));\n const rawMsgSig = concatSig(\n Buffer.from(bigIntToBytes(msgSig.v)),\n Buffer.from(msgSig.r),\n Buffer.from(msgSig.s),\n );\n return rawMsgSig;\n }\n\n /**\n * Sign a personal message using the private key of the specified account.\n * This method is compatible with the `personal_sign` RPC method.\n *\n * @param address - The address of the account.\n * @param msgHex - The message to sign.\n * @param opts - The options for signing the message.\n * @returns The signature of the message.\n */\n async signPersonalMessage(\n address: Hex,\n msgHex: string,\n opts: HDKeyringAccountSelectionOptions = {},\n ): Promise<string> {\n const privKey = this.#getPrivateKeyFor(address, opts);\n const privateKey = Buffer.from(privKey);\n return personalSign({ privateKey, data: msgHex });\n }\n\n /**\n * Decrypt an encrypted message using the private key of the specified account.\n * The message must be encrypted using the public key of the account.\n * This method is compatible with the `eth_decryptMessage` RPC method\n *\n * @param withAccount - The address of the account.\n * @param encryptedData - The encrypted data.\n * @returns The decrypted message.\n */\n async decryptMessage(\n withAccount: Hex,\n encryptedData: EthEncryptedData,\n ): Promise<string> {\n const wallet = this.#getWalletForAccount(withAccount);\n const { privateKey: privateKeyAsUint8Array } = wallet;\n assert(privateKeyAsUint8Array, 'Expected private key to be set');\n const privateKeyAsHex = Buffer.from(privateKeyAsUint8Array).toString('hex');\n return decrypt({ privateKey: privateKeyAsHex, encryptedData });\n }\n\n /**\n * Sign a typed message using the private key of the specified account.\n * This method is compatible with the `eth_signTypedData` RPC method.\n *\n * @param withAccount - The address of the account.\n * @param typedData - The typed data to sign.\n * @param opts - The options for signing the message.\n * @returns The signature of the message.\n */\n async signTypedData<Types extends MessageTypes>(\n withAccount: Hex,\n typedData: TypedDataV1 | TypedMessage<Types>,\n opts: HDKeyringAccountSelectionOptions & {\n version: SignTypedDataVersion;\n } = { version: SignTypedDataVersion.V1 },\n ): Promise<string> {\n // Treat invalid versions as \"V1\"\n const version = Object.keys(SignTypedDataVersion).includes(opts.version)\n ? opts.version\n : SignTypedDataVersion.V1;\n\n const privateKey = this.#getPrivateKeyFor(withAccount, opts);\n return signTypedData({\n privateKey: Buffer.from(privateKey),\n data: typedData,\n version,\n });\n }\n\n /**\n * Sign an EIP-7702 authorization using the private key of the specified account.\n * This method is compatible with the EIP-7702 standard for enabling smart contract code for EOAs.\n *\n * @param withAccount - The address of the account.\n * @param authorization - The EIP-7702 authorization to sign.\n * @param opts - The options for selecting the account.\n * @returns The signature of the authorization.\n */\n async signEip7702Authorization(\n withAccount: Hex,\n authorization: EIP7702Authorization,\n opts?: HDKeyringAccountSelectionOptions,\n ): Promise<string> {\n const privateKey = this.#getPrivateKeyFor(withAccount, opts);\n return signEIP7702Authorization({\n privateKey: Buffer.from(privateKey),\n authorization,\n });\n }\n\n /**\n * Remove an account from the keyring.\n *\n * @param account - The address of the account to remove.\n */\n removeAccount(account: Hex): void {\n const address = this.#normalizeAddress(account);\n if (\n !this.#wallets\n .map(\n ({ publicKey }) => publicKey && this.#addressfromPublicKey(publicKey),\n )\n .includes(address)\n ) {\n throw new Error(`Address ${address} not found in this keyring`);\n }\n\n this.#wallets = this.#wallets.filter(\n ({ publicKey }) =>\n publicKey && this.#addressfromPublicKey(publicKey) !== address,\n );\n }\n\n /**\n * Get the public key of the account to be used for encryption.\n *\n * @param withAccount - The address of the account.\n * @param opts - The options for selecting the account.\n * @returns The public key of the account.\n */\n async getEncryptionPublicKey(\n withAccount: Hex,\n opts: HDKeyringAccountSelectionOptions = {},\n ): Promise<string> {\n const privKey = this.#getPrivateKeyFor(withAccount, opts);\n const publicKey = getEncryptionPublicKey(remove0x(bytesToHex(privKey)));\n return publicKey;\n }\n\n /**\n * Convert a Uint8Array mnemonic to a secret recovery phrase,\n * using the english wordlist.\n *\n * @param mnemonic - The Uint8Array mnemonic.\n * @returns The string mnemonic.\n */\n #uint8ArrayToString(mnemonic: Uint8Array): string {\n const recoveredIndices = Array.from(\n new Uint16Array(new Uint8Array(mnemonic).buffer),\n );\n return recoveredIndices.map((i) => wordlist[i]).join(' ');\n }\n\n /**\n * Convert a secret recovery phrase to a Uint8Array mnemonic,\n * using the english wordlist.\n *\n * @param mnemonic - The string mnemonic.\n * @returns The Uint8Array mnemonic.\n */\n #stringToUint8Array(mnemonic: string): Uint8Array {\n const indices = mnemonic.split(' ').map((word) => wordlist.indexOf(word));\n return new Uint8Array(new Uint16Array(indices).buffer);\n }\n\n /**\n * Convert a mnemonic to a Uint8Array mnemonic.\n *\n * @param mnemonic - The mnemonic seed phrase.\n * @returns The Uint8Array mnemonic.\n */\n #mnemonicToUint8Array(\n mnemonic: Buffer | SerializedBuffer | string | Uint8Array | number[],\n ): Uint8Array {\n let mnemonicData: unknown = mnemonic;\n // When using `Buffer.toJSON()`, the Buffer is serialized into an object\n // with the structure `{ type: 'Buffer', data: [...] }`\n if (isSerializedBuffer(mnemonic)) {\n mnemonicData = mnemonic.data;\n }\n\n if (\n // this block is for backwards compatibility with vaults that were previously stored as buffers, number arrays or plain text strings\n typeof mnemonicData === 'string' ||\n Buffer.isBuffer(mnemonicData) ||\n Array.isArray(mnemonicData)\n ) {\n let mnemonicAsString: string;\n if (Array.isArray(mnemonicData)) {\n mnemonicAsString = Buffer.from(mnemonicData).toString();\n } else if (Buffer.isBuffer(mnemonicData)) {\n mnemonicAsString = mnemonicData.toString();\n } else {\n mnemonicAsString = mnemonicData;\n }\n return this.#stringToUint8Array(mnemonicAsString);\n } else if (\n mnemonicData instanceof Object &&\n !(mnemonicData instanceof Uint8Array)\n ) {\n // when encrypted/decrypted the Uint8Array becomes a js object we need to cast back to a Uint8Array\n return Uint8Array.from(Object.values(mnemonicData));\n }\n\n assert(mnemonicData instanceof Uint8Array, 'Expected Uint8Array mnemonic');\n return mnemonicData;\n }\n\n /**\n * Get the private key for the specified account.\n *\n * @param address - The address of the account.\n * @param opts - The options for selecting the account.\n * @returns The private key of the account.\n */\n #getPrivateKeyFor(\n address: Hex,\n opts?: HDKeyringAccountSelectionOptions,\n ): Uint8Array | Buffer {\n if (!address) {\n throw new Error('Must specify address.');\n }\n const wallet = this.#getWalletForAccount(address, opts);\n assert(wallet.privateKey, 'Missing private key');\n return wallet.privateKey;\n }\n\n /**\n * Get the wallet for the specified account.\n *\n * @param account - The address of the account.\n * @returns The wallet for the account as HDKey.\n */\n #getWalletForAccount(account: Hex): HDKey;\n\n /**\n * Get the wallet for the specified account and app origin.\n *\n * @param account - The address of the account.\n * @param opts - The options for selecting the account.\n * @returns A key pair representing the wallet.\n */\n #getWalletForAccount(\n accounts: Hex,\n opts: { withAppKeyOrigin: string },\n ): { privateKey: Buffer; publicKey: Buffer };\n\n /**\n * Get the wallet for the specified account with optional\n * additional options.\n *\n * @param account - The address of the account.\n * @param opts - The options for selecting the account.\n * @returns A key pair representing the wallet.\n */\n #getWalletForAccount(\n account: Hex,\n opts?: HDKeyringAccountSelectionOptions,\n ): HDKey | { privateKey: Buffer; publicKey: Buffer };\n\n #getWalletForAccount(\n account: Hex,\n { withAppKeyOrigin }: HDKeyringAccountSelectionOptions = {},\n ): HDKey | { privateKey: Buffer; publicKey: Buffer } {\n const address = this.#normalizeAddress(account);\n const wallet = this.#wallets.find(({ publicKey }) => {\n return publicKey && this.#addressfromPublicKey(publicKey) === address;\n });\n if (!wallet) {\n throw new Error('HD Keyring - Unable to find matching address.');\n }\n\n if (withAppKeyOrigin) {\n const { privateKey } = wallet;\n assert(privateKey, 'Expected private key to be set');\n const appKeyOriginBuffer = Buffer.from(withAppKeyOrigin, 'utf8');\n const appKeyBuffer = Buffer.concat([privateKey, appKeyOriginBuffer]);\n const appKeyPrivateKey = Buffer.from(keccak256(appKeyBuffer));\n const appKeyPublicKey = Buffer.from(privateToPublic(appKeyPrivateKey));\n return { privateKey: appKeyPrivateKey, publicKey: appKeyPublicKey };\n }\n\n return wallet;\n }\n\n /**\n * Sets appropriate properties for the keyring based on the given\n * BIP39-compliant mnemonic.\n *\n * @param mnemonic - A seed phrase represented\n * as a string, an array of UTF-8 bytes, or a Buffer. Mnemonic input\n * passed as type buffer or array of UTF-8 bytes must be NFKD normalized.\n */\n async #initFromMnemonic(\n mnemonic: string | number[] | Buffer | Uint8Array,\n ): Promise<void> {\n if (this.root) {\n throw new Error(\n 'Eth-Hd-Keyring: Secret recovery phrase already provided',\n );\n }\n\n this.mnemonic = this.#mnemonicToUint8Array(mnemonic);\n\n this.seed = await mnemonicToSeed(\n this.mnemonic,\n '', // No passphrase\n this.#cryptographicFunctions,\n );\n this.hdWallet = HDKey.fromMasterSeed(this.seed);\n this.root = this.hdWallet.derive(this.hdPath);\n }\n\n /**\n * Get the address of the account from the public key.\n *\n * @param publicKey - The public key of the account.\n * @returns The address of the account.\n */\n #addressfromPublicKey(publicKey: Uint8Array): Hex {\n return add0x(\n bytesToHex(publicToAddress(Buffer.from(publicKey), true)).toLowerCase(),\n );\n }\n\n /**\n * Normalize an address to a lower-cased '0x'-prefixed hex string.\n *\n * @param address - The address to normalize.\n * @returns The normalized address.\n */\n #normalizeAddress(address: string): Hex {\n const normalized = normalize(address);\n assert(normalized, 'Expected address to be set');\n return add0x(normalized);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"hd-keyring.cjs","sourceRoot":"","sources":["../src/hd-keyring.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,2CAA4E;AAC5E,yDAcgC;AAChC,iDAG4B;AAE5B,uDAA2E;AAC3E,6EAAwE;AACxE,2CAQyB;AACzB,uDAAoD;AACpD,yDAAyD;AAEzD,WAAW;AACX,MAAM,YAAY,GAAG,gBAAgB,CAAC;AACtC,MAAM,IAAI,GAAG,aAAa,CAAC;AAuD3B;;;;;;GAMG;AACH,SAAS,kBAAkB,CAAC,KAAc;IACxC,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,MAAM,IAAI,KAAK;QACf,KAAK,CAAC,IAAI,KAAK,QAAQ;QACvB,MAAM,IAAI,KAAK;QACf,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAC1B,CAAC;AACJ,CAAC;AAED,MAAa,SAAS;IAmBpB,YAAY,OAAyB,EAAE;;QAhBvC,SAAI,GAAW,IAAI,CAAC;QAUpB,WAAM,GAAW,YAAY,CAAC;QAErB,+BAAa,IAAI,GAAG,EAAmB,EAAC;QAExC,oDAAiD;QAGxD,yHAAyH;QACzH,uBAAA,IAAI,qCAA2B,IAAI,CAAC,sBAAsB,MAAA,CAAC;IAC7D,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,sBAAsB;QAC1B,MAAM,uBAAA,IAAI,yDAAkB,MAAtB,IAAI,EAAmB,IAAA,8BAAgB,EAAC,kBAAQ,CAAC,CAAC,CAAC;IAC3D,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,SAAS;QACb,IAAI,QAAQ,GAAa,EAAE,CAAC;QAE5B,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClB,MAAM,gB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ic, publicToAddress, ecsign } from '@ethereumjs/util';\nimport {\n concatSig,\n decrypt,\n type EIP7702Authorization,\n type EthEncryptedData,\n getEncryptionPublicKey,\n type MessageTypes,\n normalize,\n personalSign,\n signEIP7702Authorization,\n signTypedData,\n SignTypedDataVersion,\n type TypedDataV1,\n type TypedMessage,\n} from '@metamask/eth-sig-util';\nimport {\n type CryptographicFunctions,\n mnemonicToSeed,\n} from '@metamask/key-tree';\nimport type { Keyring } from '@metamask/keyring-utils';\nimport { generateMnemonic, validateMnemonic } from '@metamask/scure-bip39';\nimport { wordlist } from '@metamask/scure-bip39/dist/wordlists/english';\nimport {\n add0x,\n assert,\n assertIsHexString,\n bigIntToBytes,\n bytesToHex,\n type Hex,\n remove0x,\n} from '@metamask/utils';\nimport { HDKey } from 'ethereum-cryptography/hdkey';\nimport { keccak256 } from 'ethereum-cryptography/keccak';\n\n// Options:\nconst hdPathString = `m/44'/60'/0'/0`;\nconst type = 'HD Key Tree';\n\ntype Mnemonic = string | number[] | SerializedBuffer | Buffer | Uint8Array;\n\nexport type HDKeyringOptions = {\n cryptographicFunctions?: CryptographicFunctions;\n};\n\n/**\n * The serialized state of an `HDKeyring` instance.\n *\n * @property mnemonic - The mnemonic seed phrase as an array of numbers.\n * @property numberOfAccounts - The number of accounts in the keyring.\n * @property hdPath - The HD path used to derive accounts.\n */\nexport type SerializedHDKeyringState = {\n mnemonic: number[];\n numberOfAccounts: number;\n hdPath: string;\n};\n\n/**\n * An object that can be passed to the Keyring.deserialize method to initialize\n * an `HDKeyring` instance.\n *\n * @property mnemonic - The mnemonic seed phrase as an array of numbers.\n * @property numberOfAccounts - The number of accounts in the keyring.\n * @property hdPath - The HD path used to derive accounts.\n */\nexport type DeserializableHDKeyringState = Omit<\n SerializedHDKeyringState,\n 'mnemonic'\n> & {\n mnemonic: number[] | SerializedBuffer | string;\n};\n\n/**\n * Options for selecting an account from an `HDKeyring` instance.\n *\n * @property withAppKeyOrigin - The origin of the app requesting the account.\n */\nexport type HDKeyringAccountSelectionOptions = {\n withAppKeyOrigin?: string;\n};\n\ntype SerializedBuffer = ReturnType<Buffer['toJSON']>;\n\n/**\n * Wallet storage object that contains both the HDKey and pre-computed address.\n */\ntype WalletData = {\n hdKey: HDKey;\n address: Hex;\n};\n\n/**\n * Checks if the given value is a valid serialized Buffer compatible with\n * the return type of `Buffer.toJSON`.\n *\n * @param value - The value to check.\n * @returns `true` if the value is a valid serialized buffer, `false` otherwise.\n */\nfunction isSerializedBuffer(value: unknown): value is SerializedBuffer {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'type' in value &&\n value.type === 'Buffer' &&\n 'data' in value &&\n Array.isArray(value.data)\n );\n}\n\nexport class HdKeyring implements Keyring {\n static type: string = type;\n\n type: string = type;\n\n mnemonic?: Uint8Array | null;\n\n seed?: Uint8Array | null;\n\n root?: HDKey | null;\n\n hdWallet?: HDKey;\n\n hdPath: string = hdPathString;\n\n readonly #walletMap = new Map<Hex, WalletData>();\n\n readonly #cryptographicFunctions?: CryptographicFunctions;\n\n constructor(opts: HDKeyringOptions = {}) {\n // Cryptographic functions to be used by `@metamask/key-tree`. It will use built-in implementations if not provided here.\n this.#cryptographicFunctions = opts.cryptographicFunctions;\n }\n\n /**\n * Initialize the keyring with a random mnemonic.\n *\n * @returns A promise that resolves when the process is complete.\n */\n async generateRandomMnemonic(): Promise<void> {\n await this.#initFromMnemonic(generateMnemonic(wordlist));\n }\n\n /**\n * Return the serialized state of the keyring.\n *\n * @returns The serialized state of the keyring.\n */\n async serialize(): Promise<SerializedHDKeyringState> {\n let mnemonic: number[] = [];\n\n if (this.mnemonic) {\n const mnemonicAsString = this.#uint8ArrayToString(this.mnemonic);\n mnemonic = Array.from(new TextEncoder().encode(mnemonicAsString));\n }\n\n return {\n mnemonic,\n numberOfAccounts: this.#walletMap.size,\n hdPath: this.hdPath,\n };\n }\n\n /**\n * Initialize the keyring with the given serialized state.\n *\n * @param opts - The serialized state of the keyring.\n * @returns An empty array.\n */\n async deserialize(\n opts: Partial<DeserializableHDKeyringState>,\n ): Promise<void> {\n if (opts.numberOfAccounts && !opts.mnemonic) {\n throw new Error(\n 'Eth-Hd-Keyring: Deserialize method cannot be called with an opts value for numberOfAccounts and no menmonic',\n );\n }\n\n if (this.root) {\n throw new Error(\n 'Eth-Hd-Keyring: Secret recovery phrase already provided',\n );\n }\n\n this.#walletMap.clear();\n this.mnemonic = null;\n this.seed = null;\n this.root = null;\n this.hdPath = opts.hdPath ?? hdPathString;\n\n if (opts.mnemonic) {\n await this.#initFromMnemonic(opts.mnemonic);\n }\n\n if (opts.numberOfAccounts) {\n await this.addAccounts(opts.numberOfAccounts);\n }\n }\n\n /**\n * Add new accounts to the keyring. The accounts will be derived\n * sequentially from the root HD wallet, using increasing indices.\n *\n * @param numberOfAccounts - The number of accounts to add.\n * @returns The addresses of the new accounts.\n */\n async addAccounts(numberOfAccounts = 1): Promise<Hex[]> {\n if (!this.root) {\n throw new Error('Eth-Hd-Keyring: No secret recovery phrase provided');\n }\n\n const oldLen = this.#walletMap.size;\n const newAddresses: Hex[] = [];\n for (let i = oldLen; i < numberOfAccounts + oldLen; i++) {\n const hdKey = this.root.deriveChild(i);\n assert(hdKey.publicKey, 'Expected public key to be set');\n\n const address = this.#addressFromPublicKey(hdKey.publicKey);\n const walletData: WalletData = {\n hdKey,\n address,\n };\n\n this.#walletMap.set(address, walletData);\n newAddresses.push(address);\n }\n\n return Promise.resolve(newAddresses);\n }\n\n /**\n * Get the addresses of all accounts in the keyring.\n *\n * @returns The addresses of all accounts in the keyring.\n */\n async getAccounts(): Promise<Hex[]> {\n return Array.from(this.#walletMap.keys());\n }\n\n /**\n * Get the public address of the account for the given app key origin.\n *\n * @param address - The address of the account.\n * @param origin - The origin of the app requesting the account.\n * @returns The public address of the account.\n */\n async getAppKeyAddress(address: Hex, origin: string): Promise<Hex> {\n if (!origin || typeof origin !== 'string') {\n throw new Error(`'origin' must be a non-empty string`);\n }\n const wallet = this.#getWalletForAccount(address, {\n withAppKeyOrigin: origin,\n });\n assert(wallet.publicKey, 'Expected public key to be set');\n const appKeyAddress = this.#normalizeAddress(\n bytesToHex(publicToAddress(wallet.publicKey)),\n );\n return appKeyAddress;\n }\n\n /**\n * Export the private key for a specific account.\n *\n * @param address - The address of the account.\n * @param opts - The options for exporting the account.\n * @param opts.withAppKeyOrigin - An optional string to export the account\n * for a specific app origin.\n * @returns The private key of the account.\n */\n async exportAccount(\n address: Hex,\n opts?: { withAppKeyOrigin: string },\n ): Promise<string> {\n const wallet = opts\n ? this.#getWalletForAccount(address, opts)\n : this.#getWalletForAccount(address);\n const { privateKey } = wallet;\n assert(\n privateKey instanceof Uint8Array,\n 'Expected private key to be of type Uint8Array',\n );\n return remove0x(bytesToHex(privateKey));\n }\n\n /**\n * Sign a transaction using the private key of the specified account.\n *\n * @param address - The address of the account.\n * @param tx - The transaction to sign.\n * @param opts - The options for signing the transaction.\n * @returns The signed transaction.\n */\n async signTransaction(\n address: Hex,\n tx: TypedTransaction,\n opts = {},\n ): Promise<TypedTransaction> {\n const privKey = this.#getPrivateKeyFor(address, opts);\n const signedTx = tx.sign(Buffer.from(privKey));\n // Newer versions of Ethereumjs-tx are immutable and return a new tx object\n return signedTx ?? tx;\n }\n\n /**\n * Sign a message using the private key of the specified account.\n *\n * @param address - The address of the account.\n * @param data - The data to sign.\n * @param opts - The options for signing the message.\n * @returns The signature of the message.\n */\n async signMessage(\n address: Hex,\n data: string,\n opts: HDKeyringAccountSelectionOptions = {},\n ): Promise<string> {\n assertIsHexString(data);\n const message = remove0x(data);\n const privKey = this.#getPrivateKeyFor(address, opts);\n const msgSig = ecsign(Buffer.from(message, 'hex'), Buffer.from(privKey));\n const rawMsgSig = concatSig(\n Buffer.from(bigIntToBytes(msgSig.v)),\n Buffer.from(msgSig.r),\n Buffer.from(msgSig.s),\n );\n return rawMsgSig;\n }\n\n /**\n * Sign a personal message using the private key of the specified account.\n * This method is compatible with the `personal_sign` RPC method.\n *\n * @param address - The address of the account.\n * @param msgHex - The message to sign.\n * @param opts - The options for signing the message.\n * @returns The signature of the message.\n */\n async signPersonalMessage(\n address: Hex,\n msgHex: string,\n opts: HDKeyringAccountSelectionOptions = {},\n ): Promise<string> {\n const privKey = this.#getPrivateKeyFor(address, opts);\n const privateKey = Buffer.from(privKey);\n return personalSign({ privateKey, data: msgHex });\n }\n\n /**\n * Decrypt an encrypted message using the private key of the specified account.\n * The message must be encrypted using the public key of the account.\n * This method is compatible with the `eth_decryptMessage` RPC method\n *\n * @param withAccount - The address of the account.\n * @param encryptedData - The encrypted data.\n * @returns The decrypted message.\n */\n async decryptMessage(\n withAccount: Hex,\n encryptedData: EthEncryptedData,\n ): Promise<string> {\n const wallet = this.#getWalletForAccount(withAccount);\n const { privateKey: privateKeyAsUint8Array } = wallet;\n assert(privateKeyAsUint8Array, 'Expected private key to be set');\n const privateKeyAsHex = Buffer.from(privateKeyAsUint8Array).toString('hex');\n return decrypt({ privateKey: privateKeyAsHex, encryptedData });\n }\n\n /**\n * Sign a typed message using the private key of the specified account.\n * This method is compatible with the `eth_signTypedData` RPC method.\n *\n * @param address - The address of the account.\n * @param data - The typed data to sign.\n * @param options - The options for signing the message.\n * @returns The signature of the message.\n */\n async signTypedData<\n Version extends SignTypedDataVersion,\n Types extends MessageTypes,\n Options extends { version?: Version },\n >(\n address: Hex,\n data: Version extends 'V1' ? TypedDataV1 : TypedMessage<Types>,\n options?: HDKeyringAccountSelectionOptions & Options,\n ): Promise<string> {\n let { version } = options ?? { version: SignTypedDataVersion.V1 };\n\n // Treat invalid versions as \"V1\"\n if (!version || !Object.keys(SignTypedDataVersion).includes(version)) {\n version = SignTypedDataVersion.V1;\n }\n\n const privateKey = this.#getPrivateKeyFor(address, options);\n return signTypedData({\n privateKey: Buffer.from(privateKey),\n data,\n version,\n });\n }\n\n /**\n * Sign an EIP-7702 authorization using the private key of the specified account.\n * This method is compatible with the EIP-7702 standard for enabling smart contract code for EOAs.\n *\n * @param withAccount - The address of the account.\n * @param authorization - The EIP-7702 authorization to sign.\n * @param opts - The options for selecting the account.\n * @returns The signature of the authorization.\n */\n async signEip7702Authorization(\n withAccount: Hex,\n authorization: EIP7702Authorization,\n opts?: HDKeyringAccountSelectionOptions,\n ): Promise<string> {\n const privateKey = this.#getPrivateKeyFor(withAccount, opts);\n return signEIP7702Authorization({\n privateKey: Buffer.from(privateKey),\n authorization,\n });\n }\n\n /**\n * Remove an account from the keyring.\n *\n * @param account - The address of the account to remove.\n */\n removeAccount(account: Hex): void {\n const address = this.#normalizeAddress(account);\n\n if (!this.#walletMap.has(address)) {\n throw new Error(`Address ${address} not found in this keyring`);\n }\n\n this.#walletMap.delete(address);\n }\n\n /**\n * Get the public key of the account to be used for encryption.\n *\n * @param withAccount - The address of the account.\n * @param opts - The options for selecting the account.\n * @returns The public key of the account.\n */\n async getEncryptionPublicKey(\n withAccount: Hex,\n opts: HDKeyringAccountSelectionOptions = {},\n ): Promise<string> {\n const privKey = this.#getPrivateKeyFor(withAccount, opts);\n const publicKey = getEncryptionPublicKey(remove0x(bytesToHex(privKey)));\n return publicKey;\n }\n\n /**\n * Convert a Uint8Array mnemonic to a secret recovery phrase,\n * using the english wordlist.\n *\n * @param mnemonic - The Uint8Array mnemonic.\n * @returns The string mnemonic.\n */\n #uint8ArrayToString(mnemonic: Uint8Array): string {\n const recoveredIndices = Array.from(\n new Uint16Array(new Uint8Array(mnemonic).buffer),\n );\n return recoveredIndices.map((i) => wordlist[i]).join(' ');\n }\n\n /**\n * Convert a secret recovery phrase to a Uint8Array mnemonic,\n * using the english wordlist.\n *\n * @param mnemonic - The string mnemonic.\n * @returns The Uint8Array mnemonic.\n */\n #stringToUint8Array(mnemonic: string): Uint8Array {\n const indices = mnemonic.split(' ').map((word) => wordlist.indexOf(word));\n return new Uint8Array(new Uint16Array(indices).buffer);\n }\n\n /**\n * Convert a mnemonic to a Uint8Array mnemonic.\n *\n * @param mnemonic - The mnemonic seed phrase.\n * @returns The Uint8Array mnemonic.\n */\n #mnemonicToUint8Array(mnemonic: Mnemonic): Uint8Array {\n let mnemonicData: unknown = mnemonic;\n // When using `Buffer.toJSON()`, the Buffer is serialized into an object\n // with the structure `{ type: 'Buffer', data: [...] }`\n if (isSerializedBuffer(mnemonic)) {\n mnemonicData = mnemonic.data;\n }\n\n if (\n // this block is for backwards compatibility with vaults that were previously stored as buffers, number arrays or plain text strings\n typeof mnemonicData === 'string' ||\n Buffer.isBuffer(mnemonicData) ||\n Array.isArray(mnemonicData)\n ) {\n let mnemonicAsString: string;\n if (Array.isArray(mnemonicData)) {\n mnemonicAsString = Buffer.from(mnemonicData).toString();\n } else if (Buffer.isBuffer(mnemonicData)) {\n mnemonicAsString = mnemonicData.toString();\n } else {\n mnemonicAsString = mnemonicData;\n }\n return this.#stringToUint8Array(mnemonicAsString);\n } else if (\n mnemonicData instanceof Object &&\n !(mnemonicData instanceof Uint8Array)\n ) {\n // when encrypted/decrypted the Uint8Array becomes a js object we need to cast back to a Uint8Array\n return Uint8Array.from(Object.values(mnemonicData));\n }\n\n assert(mnemonicData instanceof Uint8Array, 'Expected Uint8Array mnemonic');\n return mnemonicData;\n }\n\n /**\n * Get the private key for the specified account.\n *\n * @param address - The address of the account.\n * @param opts - The options for selecting the account.\n * @returns The private key of the account.\n */\n #getPrivateKeyFor(\n address: Hex,\n opts?: HDKeyringAccountSelectionOptions,\n ): Uint8Array | Buffer {\n if (!address) {\n throw new Error('Must specify address.');\n }\n const wallet = this.#getWalletForAccount(address, opts);\n assert(wallet.privateKey, 'Missing private key');\n return wallet.privateKey;\n }\n\n /**\n * Get the wallet for the specified account.\n *\n * @param account - The address of the account.\n * @returns The wallet for the account as HDKey.\n */\n #getWalletForAccount(account: Hex): HDKey;\n\n /**\n * Get the wallet for the specified account and app origin.\n *\n * @param account - The address of the account.\n * @param opts - The options for selecting the account.\n * @returns A key pair representing the wallet.\n */\n #getWalletForAccount(\n accounts: Hex,\n opts: { withAppKeyOrigin: string },\n ): { privateKey: Buffer; publicKey: Buffer };\n\n /**\n * Get the wallet for the specified account with optional\n * additional options.\n *\n * @param account - The address of the account.\n * @param opts - The options for selecting the account.\n * @returns A key pair representing the wallet.\n */\n #getWalletForAccount(\n account: Hex,\n opts?: HDKeyringAccountSelectionOptions,\n ): HDKey | { privateKey: Buffer; publicKey: Buffer };\n\n #getWalletForAccount(\n account: Hex,\n { withAppKeyOrigin }: HDKeyringAccountSelectionOptions = {},\n ): HDKey | { privateKey: Buffer; publicKey: Buffer } {\n const address = this.#normalizeAddress(account);\n const walletData = this.#walletMap.get(address);\n if (!walletData) {\n throw new Error('HD Keyring - Unable to find matching address.');\n }\n\n if (withAppKeyOrigin) {\n const { privateKey } = walletData.hdKey;\n assert(privateKey, 'Expected private key to be set');\n const appKeyOriginBuffer = Buffer.from(withAppKeyOrigin, 'utf8');\n const appKeyBuffer = Buffer.concat([privateKey, appKeyOriginBuffer]);\n const appKeyPrivateKey = Buffer.from(keccak256(appKeyBuffer));\n const appKeyPublicKey = Buffer.from(privateToPublic(appKeyPrivateKey));\n return { privateKey: appKeyPrivateKey, publicKey: appKeyPublicKey };\n }\n\n return walletData.hdKey;\n }\n\n /**\n * Sets appropriate properties for the keyring based on the given\n * BIP39-compliant mnemonic.\n *\n * @param mnemonic - A seed phrase represented\n * as a string, an array of UTF-8 bytes, or a Buffer. Mnemonic input\n * passed as type buffer or array of UTF-8 bytes must be NFKD normalized.\n */\n async #initFromMnemonic(mnemonic: Mnemonic): Promise<void> {\n if (this.root) {\n throw new Error(\n 'Eth-Hd-Keyring: Secret recovery phrase already provided',\n );\n }\n\n // Convert and validate before assigning to instance property\n // to avoid inconsistent state if validation fails\n const mnemonicAsUint8Array = this.#mnemonicToUint8Array(mnemonic);\n this.#assertValidMnemonic(mnemonicAsUint8Array);\n this.mnemonic = mnemonicAsUint8Array;\n\n this.seed = await mnemonicToSeed(\n this.mnemonic,\n '', // No passphrase\n this.#cryptographicFunctions,\n );\n this.hdWallet = HDKey.fromMasterSeed(this.seed);\n this.root = this.hdWallet.derive(this.hdPath);\n }\n\n /**\n * Get the address of the account from the public key.\n *\n * @param publicKey - The public key of the account.\n * @returns The address of the account.\n */\n #addressFromPublicKey(publicKey: Uint8Array): Hex {\n return add0x(\n bytesToHex(publicToAddress(Buffer.from(publicKey), true)).toLowerCase(),\n );\n }\n\n /**\n * Normalize an address to a lower-cased '0x'-prefixed hex string.\n *\n * @param address - The address to normalize.\n * @returns The normalized address.\n */\n #normalizeAddress(address: string): Hex {\n const normalized = normalize(address);\n assert(normalized, 'Expected address to be set');\n return add0x(normalized);\n }\n\n /**\n * Assert that the mnemonic seed phrase is valid.\n * Throws an error if the mnemonic is not a valid BIP39 phrase.\n *\n * @param mnemonic - The mnemonic seed phrase to validate (as Uint8Array).\n * @throws If the mnemonic is not a valid BIP39 secret recovery phrase.\n */\n #assertValidMnemonic(mnemonic: Uint8Array): void {\n const mnemonicString = this.#uint8ArrayToString(mnemonic);\n if (!validateMnemonic(mnemonicString, wordlist)) {\n throw new Error(\n 'Eth-Hd-Keyring: Invalid secret recovery phrase provided',\n );\n }\n }\n}\n"]}
|
package/dist/hd-keyring.d.cts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { TypedTransaction } from "@ethereumjs/tx";
|
|
2
2
|
import { type EIP7702Authorization, type EthEncryptedData, type MessageTypes, SignTypedDataVersion, type TypedDataV1, type TypedMessage } from "@metamask/eth-sig-util";
|
|
3
3
|
import { type CryptographicFunctions } from "@metamask/key-tree";
|
|
4
|
+
import type { Keyring } from "@metamask/keyring-utils";
|
|
4
5
|
import { type Hex } from "@metamask/utils";
|
|
5
6
|
import { HDKey } from "ethereum-cryptography/hdkey";
|
|
6
7
|
export type HDKeyringOptions = {
|
|
@@ -13,11 +14,22 @@ export type HDKeyringOptions = {
|
|
|
13
14
|
* @property numberOfAccounts - The number of accounts in the keyring.
|
|
14
15
|
* @property hdPath - The HD path used to derive accounts.
|
|
15
16
|
*/
|
|
16
|
-
export type
|
|
17
|
-
mnemonic: number[]
|
|
17
|
+
export type SerializedHDKeyringState = {
|
|
18
|
+
mnemonic: number[];
|
|
18
19
|
numberOfAccounts: number;
|
|
19
20
|
hdPath: string;
|
|
20
21
|
};
|
|
22
|
+
/**
|
|
23
|
+
* An object that can be passed to the Keyring.deserialize method to initialize
|
|
24
|
+
* an `HDKeyring` instance.
|
|
25
|
+
*
|
|
26
|
+
* @property mnemonic - The mnemonic seed phrase as an array of numbers.
|
|
27
|
+
* @property numberOfAccounts - The number of accounts in the keyring.
|
|
28
|
+
* @property hdPath - The HD path used to derive accounts.
|
|
29
|
+
*/
|
|
30
|
+
export type DeserializableHDKeyringState = Omit<SerializedHDKeyringState, 'mnemonic'> & {
|
|
31
|
+
mnemonic: number[] | SerializedBuffer | string;
|
|
32
|
+
};
|
|
21
33
|
/**
|
|
22
34
|
* Options for selecting an account from an `HDKeyring` instance.
|
|
23
35
|
*
|
|
@@ -26,7 +38,8 @@ export type HDKeyringState = {
|
|
|
26
38
|
export type HDKeyringAccountSelectionOptions = {
|
|
27
39
|
withAppKeyOrigin?: string;
|
|
28
40
|
};
|
|
29
|
-
|
|
41
|
+
type SerializedBuffer = ReturnType<Buffer['toJSON']>;
|
|
42
|
+
export declare class HdKeyring implements Keyring {
|
|
30
43
|
#private;
|
|
31
44
|
static type: string;
|
|
32
45
|
type: string;
|
|
@@ -47,14 +60,14 @@ export declare class HdKeyring {
|
|
|
47
60
|
*
|
|
48
61
|
* @returns The serialized state of the keyring.
|
|
49
62
|
*/
|
|
50
|
-
serialize(): Promise<
|
|
63
|
+
serialize(): Promise<SerializedHDKeyringState>;
|
|
51
64
|
/**
|
|
52
65
|
* Initialize the keyring with the given serialized state.
|
|
53
66
|
*
|
|
54
67
|
* @param opts - The serialized state of the keyring.
|
|
55
68
|
* @returns An empty array.
|
|
56
69
|
*/
|
|
57
|
-
deserialize(opts
|
|
70
|
+
deserialize(opts: Partial<DeserializableHDKeyringState>): Promise<void>;
|
|
58
71
|
/**
|
|
59
72
|
* Add new accounts to the keyring. The accounts will be derived
|
|
60
73
|
* sequentially from the root HD wallet, using increasing indices.
|
|
@@ -68,7 +81,7 @@ export declare class HdKeyring {
|
|
|
68
81
|
*
|
|
69
82
|
* @returns The addresses of all accounts in the keyring.
|
|
70
83
|
*/
|
|
71
|
-
getAccounts(): Hex[]
|
|
84
|
+
getAccounts(): Promise<Hex[]>;
|
|
72
85
|
/**
|
|
73
86
|
* Get the public address of the account for the given app key origin.
|
|
74
87
|
*
|
|
@@ -131,14 +144,14 @@ export declare class HdKeyring {
|
|
|
131
144
|
* Sign a typed message using the private key of the specified account.
|
|
132
145
|
* This method is compatible with the `eth_signTypedData` RPC method.
|
|
133
146
|
*
|
|
134
|
-
* @param
|
|
135
|
-
* @param
|
|
136
|
-
* @param
|
|
147
|
+
* @param address - The address of the account.
|
|
148
|
+
* @param data - The typed data to sign.
|
|
149
|
+
* @param options - The options for signing the message.
|
|
137
150
|
* @returns The signature of the message.
|
|
138
151
|
*/
|
|
139
|
-
signTypedData<
|
|
140
|
-
version
|
|
141
|
-
}): Promise<string>;
|
|
152
|
+
signTypedData<Version extends SignTypedDataVersion, Types extends MessageTypes, Options extends {
|
|
153
|
+
version?: Version;
|
|
154
|
+
}>(address: Hex, data: Version extends 'V1' ? TypedDataV1 : TypedMessage<Types>, options?: HDKeyringAccountSelectionOptions & Options): Promise<string>;
|
|
142
155
|
/**
|
|
143
156
|
* Sign an EIP-7702 authorization using the private key of the specified account.
|
|
144
157
|
* This method is compatible with the EIP-7702 standard for enabling smart contract code for EOAs.
|
|
@@ -164,4 +177,5 @@ export declare class HdKeyring {
|
|
|
164
177
|
*/
|
|
165
178
|
getEncryptionPublicKey(withAccount: Hex, opts?: HDKeyringAccountSelectionOptions): Promise<string>;
|
|
166
179
|
}
|
|
180
|
+
export {};
|
|
167
181
|
//# sourceMappingURL=hd-keyring.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hd-keyring.d.cts","sourceRoot":"","sources":["../src/hd-keyring.ts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EACZ,IAAI,EAAE,MAAM,EACZ,IAAI,GAAE,gCAAqC,GAC1C,OAAO,CAAC,MAAM,CAAC;IAalB;;;;;;;;OAQG;IACG,mBAAmB,CACvB,OAAO,EAAE,GAAG,EACZ,MAAM,EAAE,MAAM,EACd,IAAI,GAAE,gCAAqC,GAC1C,OAAO,CAAC,MAAM,CAAC;IAMlB;;;;;;;;OAQG;IACG,cAAc,CAClB,WAAW,EAAE,GAAG,EAChB,aAAa,EAAE,gBAAgB,GAC9B,OAAO,CAAC,MAAM,CAAC;IAQlB;;;;;;;;OAQG;IACG,aAAa,CACjB,OAAO,SAAS,oBAAoB,EACpC,KAAK,SAAS,YAAY,EAC1B,OAAO,SAAS;QAAE,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,EAErC,OAAO,EAAE,GAAG,EACZ,IAAI,EAAE,OAAO,SAAS,IAAI,GAAG,WAAW,GAAG,YAAY,CAAC,KAAK,CAAC,EAC9D,OAAO,CAAC,EAAE,gCAAgC,GAAG,OAAO,GACnD,OAAO,CAAC,MAAM,CAAC;IAgBlB;;;;;;;;OAQG;IACG,wBAAwB,CAC5B,WAAW,EAAE,GAAG,EAChB,aAAa,EAAE,oBAAoB,EACnC,IAAI,CAAC,EAAE,gCAAgC,GACtC,OAAO,CAAC,MAAM,CAAC;IAQlB;;;;OAIG;IACH,aAAa,CAAC,OAAO,EAAE,GAAG,GAAG,IAAI;IAUjC;;;;;;OAMG;IACG,sBAAsB,CAC1B,WAAW,EAAE,GAAG,EAChB,IAAI,GAAE,gCAAqC,GAC1C,OAAO,CAAC,MAAM,CAAC;CAyNnB"}
|
package/dist/hd-keyring.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { TypedTransaction } from "@ethereumjs/tx";
|
|
2
2
|
import { type EIP7702Authorization, type EthEncryptedData, type MessageTypes, SignTypedDataVersion, type TypedDataV1, type TypedMessage } from "@metamask/eth-sig-util";
|
|
3
3
|
import { type CryptographicFunctions } from "@metamask/key-tree";
|
|
4
|
+
import type { Keyring } from "@metamask/keyring-utils";
|
|
4
5
|
import { type Hex } from "@metamask/utils";
|
|
5
6
|
import { HDKey } from "ethereum-cryptography/hdkey";
|
|
6
7
|
export type HDKeyringOptions = {
|
|
@@ -13,11 +14,22 @@ export type HDKeyringOptions = {
|
|
|
13
14
|
* @property numberOfAccounts - The number of accounts in the keyring.
|
|
14
15
|
* @property hdPath - The HD path used to derive accounts.
|
|
15
16
|
*/
|
|
16
|
-
export type
|
|
17
|
-
mnemonic: number[]
|
|
17
|
+
export type SerializedHDKeyringState = {
|
|
18
|
+
mnemonic: number[];
|
|
18
19
|
numberOfAccounts: number;
|
|
19
20
|
hdPath: string;
|
|
20
21
|
};
|
|
22
|
+
/**
|
|
23
|
+
* An object that can be passed to the Keyring.deserialize method to initialize
|
|
24
|
+
* an `HDKeyring` instance.
|
|
25
|
+
*
|
|
26
|
+
* @property mnemonic - The mnemonic seed phrase as an array of numbers.
|
|
27
|
+
* @property numberOfAccounts - The number of accounts in the keyring.
|
|
28
|
+
* @property hdPath - The HD path used to derive accounts.
|
|
29
|
+
*/
|
|
30
|
+
export type DeserializableHDKeyringState = Omit<SerializedHDKeyringState, 'mnemonic'> & {
|
|
31
|
+
mnemonic: number[] | SerializedBuffer | string;
|
|
32
|
+
};
|
|
21
33
|
/**
|
|
22
34
|
* Options for selecting an account from an `HDKeyring` instance.
|
|
23
35
|
*
|
|
@@ -26,7 +38,8 @@ export type HDKeyringState = {
|
|
|
26
38
|
export type HDKeyringAccountSelectionOptions = {
|
|
27
39
|
withAppKeyOrigin?: string;
|
|
28
40
|
};
|
|
29
|
-
|
|
41
|
+
type SerializedBuffer = ReturnType<Buffer['toJSON']>;
|
|
42
|
+
export declare class HdKeyring implements Keyring {
|
|
30
43
|
#private;
|
|
31
44
|
static type: string;
|
|
32
45
|
type: string;
|
|
@@ -47,14 +60,14 @@ export declare class HdKeyring {
|
|
|
47
60
|
*
|
|
48
61
|
* @returns The serialized state of the keyring.
|
|
49
62
|
*/
|
|
50
|
-
serialize(): Promise<
|
|
63
|
+
serialize(): Promise<SerializedHDKeyringState>;
|
|
51
64
|
/**
|
|
52
65
|
* Initialize the keyring with the given serialized state.
|
|
53
66
|
*
|
|
54
67
|
* @param opts - The serialized state of the keyring.
|
|
55
68
|
* @returns An empty array.
|
|
56
69
|
*/
|
|
57
|
-
deserialize(opts
|
|
70
|
+
deserialize(opts: Partial<DeserializableHDKeyringState>): Promise<void>;
|
|
58
71
|
/**
|
|
59
72
|
* Add new accounts to the keyring. The accounts will be derived
|
|
60
73
|
* sequentially from the root HD wallet, using increasing indices.
|
|
@@ -68,7 +81,7 @@ export declare class HdKeyring {
|
|
|
68
81
|
*
|
|
69
82
|
* @returns The addresses of all accounts in the keyring.
|
|
70
83
|
*/
|
|
71
|
-
getAccounts(): Hex[]
|
|
84
|
+
getAccounts(): Promise<Hex[]>;
|
|
72
85
|
/**
|
|
73
86
|
* Get the public address of the account for the given app key origin.
|
|
74
87
|
*
|
|
@@ -131,14 +144,14 @@ export declare class HdKeyring {
|
|
|
131
144
|
* Sign a typed message using the private key of the specified account.
|
|
132
145
|
* This method is compatible with the `eth_signTypedData` RPC method.
|
|
133
146
|
*
|
|
134
|
-
* @param
|
|
135
|
-
* @param
|
|
136
|
-
* @param
|
|
147
|
+
* @param address - The address of the account.
|
|
148
|
+
* @param data - The typed data to sign.
|
|
149
|
+
* @param options - The options for signing the message.
|
|
137
150
|
* @returns The signature of the message.
|
|
138
151
|
*/
|
|
139
|
-
signTypedData<
|
|
140
|
-
version
|
|
141
|
-
}): Promise<string>;
|
|
152
|
+
signTypedData<Version extends SignTypedDataVersion, Types extends MessageTypes, Options extends {
|
|
153
|
+
version?: Version;
|
|
154
|
+
}>(address: Hex, data: Version extends 'V1' ? TypedDataV1 : TypedMessage<Types>, options?: HDKeyringAccountSelectionOptions & Options): Promise<string>;
|
|
142
155
|
/**
|
|
143
156
|
* Sign an EIP-7702 authorization using the private key of the specified account.
|
|
144
157
|
* This method is compatible with the EIP-7702 standard for enabling smart contract code for EOAs.
|
|
@@ -164,4 +177,5 @@ export declare class HdKeyring {
|
|
|
164
177
|
*/
|
|
165
178
|
getEncryptionPublicKey(withAccount: Hex, opts?: HDKeyringAccountSelectionOptions): Promise<string>;
|
|
166
179
|
}
|
|
180
|
+
export {};
|
|
167
181
|
//# sourceMappingURL=hd-keyring.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hd-keyring.d.mts","sourceRoot":"","sources":["../src/hd-keyring.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,uBAAuB;AAEvD,OAAO,EAGL,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EAErB,KAAK,YAAY,EAKjB,oBAAoB,EACpB,KAAK,WAAW,EAChB,KAAK,YAAY,EAClB,+BAA+B;AAChC,OAAO,EACL,KAAK,sBAAsB,EAE5B,2BAA2B;
|
|
1
|
+
{"version":3,"file":"hd-keyring.d.mts","sourceRoot":"","sources":["../src/hd-keyring.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,uBAAuB;AAEvD,OAAO,EAGL,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EAErB,KAAK,YAAY,EAKjB,oBAAoB,EACpB,KAAK,WAAW,EAChB,KAAK,YAAY,EAClB,+BAA+B;AAChC,OAAO,EACL,KAAK,sBAAsB,EAE5B,2BAA2B;AAC5B,OAAO,KAAK,EAAE,OAAO,EAAE,gCAAgC;AAGvD,OAAO,EAML,KAAK,GAAG,EAET,wBAAwB;AACzB,OAAO,EAAE,KAAK,EAAE,oCAAoC;AASpD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,sBAAsB,CAAC,EAAE,sBAAsB,CAAC;CACjD,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,wBAAwB,GAAG;IACrC,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,gBAAgB,EAAE,MAAM,CA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