@metamask-previews/eth-hd-keyring 9.0.1-0aca2ee → 9.0.1-15a8cd2

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 CHANGED
@@ -7,12 +7,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
- ### Changed
11
-
12
- - **BREAKING**: This package now has no default export ([#161](https://github.com/MetaMask/accounts/pull/161))
13
- - **BREAKING**: Added types to `HdKeyring` ([#161](https://github.com/MetaMask/accounts/pull/161))
14
- - All methods on `HdKeyring` retain their existing signatures, but now have types.
15
-
16
10
  ## [9.0.1]
17
11
 
18
12
  ### Changed
package/dist/index.cjs CHANGED
@@ -1,18 +1,241 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
2
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./hd-keyring.cjs"), exports);
3
+ const util_1 = require("@ethereumjs/util");
4
+ const eth_sig_util_1 = require("@metamask/eth-sig-util");
5
+ const key_tree_1 = require("@metamask/key-tree");
6
+ const scure_bip39_1 = require("@metamask/scure-bip39");
7
+ const english_1 = require("@metamask/scure-bip39/dist/wordlists/english.js");
8
+ const utils_1 = require("@metamask/utils");
9
+ const hdkey_1 = require("ethereum-cryptography/hdkey");
10
+ const keccak_1 = require("ethereum-cryptography/keccak");
11
+ const utils_2 = require("ethereum-cryptography/utils");
12
+ // Options:
13
+ const hdPathString = `m/44'/60'/0'/0`;
14
+ const type = 'HD Key Tree';
15
+ class HdKeyring {
16
+ /* PUBLIC METHODS */
17
+ constructor(opts = {}) {
18
+ this.type = type;
19
+ this._wallets = [];
20
+ // Cryptographic functions to be used by `@metamask/key-tree`. It will use built-in implementations if not provided here.
21
+ this._cryptographicFunctions = opts.cryptographicFunctions;
22
+ }
23
+ async generateRandomMnemonic() {
24
+ await this._initFromMnemonic((0, scure_bip39_1.generateMnemonic)(english_1.wordlist));
25
+ }
26
+ _uint8ArrayToString(mnemonic) {
27
+ const recoveredIndices = Array.from(new Uint16Array(new Uint8Array(mnemonic).buffer));
28
+ return recoveredIndices.map((i) => english_1.wordlist[i]).join(' ');
29
+ }
30
+ _stringToUint8Array(mnemonic) {
31
+ const indices = mnemonic.split(' ').map((word) => english_1.wordlist.indexOf(word));
32
+ return new Uint8Array(new Uint16Array(indices).buffer);
33
+ }
34
+ _mnemonicToUint8Array(mnemonic) {
35
+ let mnemonicData = mnemonic;
36
+ // when encrypted/decrypted, buffers get cast into js object with a property type set to buffer
37
+ if (mnemonic && mnemonic.type && mnemonic.type === 'Buffer') {
38
+ mnemonicData = mnemonic.data;
39
+ }
40
+ if (
41
+ // this block is for backwards compatibility with vaults that were previously stored as buffers, number arrays or plain text strings
42
+ typeof mnemonicData === 'string' ||
43
+ Buffer.isBuffer(mnemonicData) ||
44
+ Array.isArray(mnemonicData)) {
45
+ let mnemonicAsString = mnemonicData;
46
+ if (Array.isArray(mnemonicData)) {
47
+ mnemonicAsString = Buffer.from(mnemonicData).toString();
48
+ }
49
+ else if (Buffer.isBuffer(mnemonicData)) {
50
+ mnemonicAsString = mnemonicData.toString();
51
+ }
52
+ return this._stringToUint8Array(mnemonicAsString);
53
+ }
54
+ else if (mnemonicData instanceof Object &&
55
+ !(mnemonicData instanceof Uint8Array)) {
56
+ // when encrypted/decrypted the Uint8Array becomes a js object we need to cast back to a Uint8Array
57
+ return Uint8Array.from(Object.values(mnemonicData));
58
+ }
59
+ return mnemonicData;
60
+ }
61
+ async serialize() {
62
+ const mnemonicAsString = this._uint8ArrayToString(this.mnemonic);
63
+ const uint8ArrayMnemonic = new TextEncoder('utf-8').encode(mnemonicAsString);
64
+ return {
65
+ mnemonic: Array.from(uint8ArrayMnemonic),
66
+ numberOfAccounts: this._wallets.length,
67
+ hdPath: this.hdPath,
68
+ };
69
+ }
70
+ async deserialize(opts = {}) {
71
+ if (opts.numberOfAccounts && !opts.mnemonic) {
72
+ throw new Error('Eth-Hd-Keyring: Deserialize method cannot be called with an opts value for numberOfAccounts and no menmonic');
73
+ }
74
+ if (this.root) {
75
+ throw new Error('Eth-Hd-Keyring: Secret recovery phrase already provided');
76
+ }
77
+ this.opts = opts;
78
+ this._wallets = [];
79
+ this.mnemonic = null;
80
+ this.root = null;
81
+ this.hdPath = opts.hdPath || hdPathString;
82
+ if (opts.mnemonic) {
83
+ await this._initFromMnemonic(opts.mnemonic);
84
+ }
85
+ if (opts.numberOfAccounts) {
86
+ return this.addAccounts(opts.numberOfAccounts);
87
+ }
88
+ return [];
89
+ }
90
+ addAccounts(numberOfAccounts = 1) {
91
+ if (!this.root) {
92
+ throw new Error('Eth-Hd-Keyring: No secret recovery phrase provided');
93
+ }
94
+ const oldLen = this._wallets.length;
95
+ const newWallets = [];
96
+ for (let i = oldLen; i < numberOfAccounts + oldLen; i++) {
97
+ const wallet = this.root.deriveChild(i);
98
+ newWallets.push(wallet);
99
+ this._wallets.push(wallet);
100
+ }
101
+ const hexWallets = newWallets.map((w) => {
102
+ return this._addressfromPublicKey(w.publicKey);
103
+ });
104
+ return Promise.resolve(hexWallets);
105
+ }
106
+ getAccounts() {
107
+ return this._wallets.map((w) => this._addressfromPublicKey(w.publicKey));
108
+ }
109
+ /* BASE KEYRING METHODS */
110
+ // returns an address specific to an app
111
+ async getAppKeyAddress(address, origin) {
112
+ if (!origin || typeof origin !== 'string') {
113
+ throw new Error(`'origin' must be a non-empty string`);
114
+ }
115
+ const wallet = this._getWalletForAccount(address, {
116
+ withAppKeyOrigin: origin,
117
+ });
118
+ const appKeyAddress = (0, eth_sig_util_1.normalize)((0, util_1.publicToAddress)(wallet.publicKey).toString('hex'));
119
+ return appKeyAddress;
120
+ }
121
+ // exportAccount should return a hex-encoded private key:
122
+ async exportAccount(address, opts = {}) {
123
+ const wallet = this._getWalletForAccount(address, opts);
124
+ return (0, utils_2.bytesToHex)(wallet.privateKey);
125
+ }
126
+ // tx is an instance of the ethereumjs-transaction class.
127
+ async signTransaction(address, tx, opts = {}) {
128
+ const privKey = this._getPrivateKeyFor(address, opts);
129
+ const signedTx = tx.sign(privKey);
130
+ // Newer versions of Ethereumjs-tx are immutable and return a new tx object
131
+ return signedTx === undefined ? tx : signedTx;
132
+ }
133
+ // For eth_sign, we need to sign arbitrary data:
134
+ async signMessage(address, data, opts = {}) {
135
+ (0, utils_1.assertIsHexString)(data);
136
+ const message = (0, utils_1.remove0x)(data);
137
+ const privKey = this._getPrivateKeyFor(address, opts);
138
+ const msgSig = (0, util_1.ecsign)(Buffer.from(message, 'hex'), privKey);
139
+ const rawMsgSig = (0, eth_sig_util_1.concatSig)(msgSig.v, msgSig.r, msgSig.s);
140
+ return rawMsgSig;
141
+ }
142
+ // For personal_sign, we need to prefix the message:
143
+ async signPersonalMessage(address, msgHex, opts = {}) {
144
+ const privKey = this._getPrivateKeyFor(address, opts);
145
+ const privateKey = Buffer.from(privKey, 'hex');
146
+ const sig = (0, eth_sig_util_1.personalSign)({ privateKey, data: msgHex });
147
+ return sig;
148
+ }
149
+ // For eth_decryptMessage:
150
+ async decryptMessage(withAccount, encryptedData) {
151
+ const wallet = this._getWalletForAccount(withAccount);
152
+ const { privateKey: privateKeyAsUint8Array } = wallet;
153
+ const privateKeyAsHex = Buffer.from(privateKeyAsUint8Array).toString('hex');
154
+ const sig = (0, eth_sig_util_1.decrypt)({ privateKey: privateKeyAsHex, encryptedData });
155
+ return sig;
156
+ }
157
+ // personal_signTypedData, signs data along with the schema
158
+ async signTypedData(withAccount, typedData, opts = { version: eth_sig_util_1.SignTypedDataVersion.V1 }) {
159
+ // Treat invalid versions as "V1"
160
+ const version = Object.keys(eth_sig_util_1.SignTypedDataVersion).includes(opts.version)
161
+ ? opts.version
162
+ : eth_sig_util_1.SignTypedDataVersion.V1;
163
+ const privateKey = this._getPrivateKeyFor(withAccount, opts);
164
+ return (0, eth_sig_util_1.signTypedData)({ privateKey, data: typedData, version });
165
+ }
166
+ removeAccount(account) {
167
+ const address = (0, eth_sig_util_1.normalize)(account);
168
+ if (!this._wallets
169
+ .map(({ publicKey }) => this._addressfromPublicKey(publicKey))
170
+ .includes(address)) {
171
+ throw new Error(`Address ${address} not found in this keyring`);
172
+ }
173
+ this._wallets = this._wallets.filter(({ publicKey }) => this._addressfromPublicKey(publicKey) !== address);
174
+ }
175
+ // get public key for nacl
176
+ async getEncryptionPublicKey(withAccount, opts = {}) {
177
+ const privKey = this._getPrivateKeyFor(withAccount, opts);
178
+ const publicKey = (0, eth_sig_util_1.getEncryptionPublicKey)(privKey);
179
+ return publicKey;
180
+ }
181
+ getFingerprint() {
182
+ const firstIndexFingerprint = this.root.deriveChild(0).fingerprint;
183
+ console.log('firstIndexFingerprint', firstIndexFingerprint);
184
+ const fingerprint = (0, keccak_1.keccak256)(Buffer.from(this.root.deriveChild(0).fingerprint.toString()));
185
+ console.log('fingerPrint', fingerprint);
186
+ const result = Buffer.from(fingerprint).toString('hex');
187
+ console.log('result', result);
188
+ return result;
189
+ }
190
+ _getPrivateKeyFor(address, opts = {}) {
191
+ if (!address) {
192
+ throw new Error('Must specify address.');
193
+ }
194
+ const wallet = this._getWalletForAccount(address, opts);
195
+ return wallet.privateKey;
196
+ }
197
+ _getWalletForAccount(account, opts = {}) {
198
+ const address = (0, eth_sig_util_1.normalize)(account);
199
+ let wallet = this._wallets.find(({ publicKey }) => {
200
+ return this._addressfromPublicKey(publicKey) === address;
201
+ });
202
+ if (!wallet) {
203
+ throw new Error('HD Keyring - Unable to find matching address.');
204
+ }
205
+ if (opts.withAppKeyOrigin) {
206
+ const { privateKey } = wallet;
207
+ const appKeyOriginBuffer = Buffer.from(opts.withAppKeyOrigin, 'utf8');
208
+ const appKeyBuffer = Buffer.concat([privateKey, appKeyOriginBuffer]);
209
+ const appKeyPrivateKey = (0, util_1.arrToBufArr)((0, keccak_1.keccak256)(appKeyBuffer, 256));
210
+ const appKeyPublicKey = (0, util_1.privateToPublic)(appKeyPrivateKey);
211
+ wallet = { privateKey: appKeyPrivateKey, publicKey: appKeyPublicKey };
212
+ }
213
+ return wallet;
214
+ }
215
+ /* PRIVATE / UTILITY METHODS */
216
+ /**
217
+ * Sets appropriate properties for the keyring based on the given
218
+ * BIP39-compliant mnemonic.
219
+ *
220
+ * @param {string|Array<number>|Buffer} mnemonic - A seed phrase represented
221
+ * as a string, an array of UTF-8 bytes, or a Buffer. Mnemonic input
222
+ * passed as type buffer or array of UTF-8 bytes must be NFKD normalized.
223
+ */
224
+ async _initFromMnemonic(mnemonic) {
225
+ if (this.root) {
226
+ throw new Error('Eth-Hd-Keyring: Secret recovery phrase already provided');
227
+ }
228
+ this.mnemonic = this._mnemonicToUint8Array(mnemonic);
229
+ const seed = await (0, key_tree_1.mnemonicToSeed)(this.mnemonic, '', // No passphrase
230
+ this._cryptographicFunctions);
231
+ this.hdWallet = hdkey_1.HDKey.fromMasterSeed(seed);
232
+ this.root = this.hdWallet.derive(this.hdPath);
233
+ }
234
+ // small helper function to convert publicKey in Uint8Array form to a publicAddress as a hex
235
+ _addressfromPublicKey(publicKey) {
236
+ return (0, util_1.bufferToHex)((0, util_1.publicToAddress)(Buffer.from(publicKey), true)).toLowerCase();
237
+ }
238
+ }
239
+ HdKeyring.type = type;
240
+ exports.default = HdKeyring;
18
241
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAA6B","sourcesContent":["export * from './hd-keyring';\n"]}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":";;AAAA,2CAM0B;AAC1B,yDAQgC;AAChC,iDAAoD;AACpD,uDAAyD;AACzD,6EAAwE;AACxE,2CAA8D;AAC9D,uDAAoD;AACpD,yDAAyD;AACzD,uDAAyD;AAEzD,WAAW;AACX,MAAM,YAAY,GAAG,gBAAgB,CAAC;AACtC,MAAM,IAAI,GAAG,aAAa,CAAC;AAE3B,MAAM,SAAS;IACb,oBAAoB;IACpB,YAAY,IAAI,GAAG,EAAE;QACnB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QACnB,yHAAyH;QACzH,IAAI,CAAC,uBAAuB,GAAG,IAAI,CAAC,sBAAsB,CAAC;IAC7D,CAAC;IAED,KAAK,CAAC,sBAAsB;QAC1B,MAAM,IAAI,CAAC,iBAAiB,CAAC,IAAA,8BAAgB,EAAC,kBAAQ,CAAC,CAAC,CAAC;IAC3D,CAAC;IAED,mBAAmB,CAAC,QAAQ;QAC1B,MAAM,gBAAgB,GAAG,KAAK,CAAC,IAAI,CACjC,IAAI,WAAW,CAAC,IAAI,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CACjD,CAAC;QACF,OAAO,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,kBAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC5D,CAAC;IAED,mBAAmB,CAAC,QAAQ;QAC1B,MAAM,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,kBAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC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GAAG,IAAA,sBAAe,EAAC,gBAAgB,CAAC,CAAC;YAC1D,MAAM,GAAG,EAAE,UAAU,EAAE,gBAAgB,EAAE,SAAS,EAAE,eAAe,EAAE,CAAC;QACxE,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,+BAA+B;IAE/B;;;;;;;OAOG;IACH,KAAK,CAAC,iBAAiB,CAAC,QAAQ;QAC9B,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YACd,MAAM,IAAI,KAAK,CACb,yDAAyD,CAC1D,CAAC;QACJ,CAAC;QAED,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,qBAAqB,CAAC,QAAQ,CAAC,CAAC;QAErD,MAAM,IAAI,GAAG,MAAM,IAAA,yBAAc,EAC/B,IAAI,CAAC,QAAQ,EACb,EAAE,EAAE,gBAAgB;QACpB,IAAI,CAAC,uBAAuB,CAC7B,CAAC;QACF,IAAI,CAAC,QAAQ,GAAG,aAAK,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QAC3C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAChD,CAAC;IAED,4FAA4F;IAC5F,qBAAqB,CAAC,SAAS;QAC7B,OAAO,IAAA,kBAAW,EAChB,IAAA,sBAAe,EAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,CAAC,CAC9C,CAAC,WAAW,EAAE,CAAC;IAClB,CAAC;CACF;AAED,SAAS,CAAC,IAAI,GAAG,IAAI,CAAC;AACtB,kBAAe,SAAS,CAAC","sourcesContent":["import {\n privateToPublic,\n publicToAddress,\n ecsign,\n arrToBufArr,\n bufferToHex,\n} from '@ethereumjs/util';\nimport {\n concatSig,\n decrypt,\n getEncryptionPublicKey,\n normalize,\n personalSign,\n signTypedData,\n SignTypedDataVersion,\n} from '@metamask/eth-sig-util';\nimport { mnemonicToSeed } from '@metamask/key-tree';\nimport { generateMnemonic } from '@metamask/scure-bip39';\nimport { wordlist } from '@metamask/scure-bip39/dist/wordlists/english';\nimport { assertIsHexString, remove0x } from '@metamask/utils';\nimport { HDKey } from 'ethereum-cryptography/hdkey';\nimport { keccak256 } from 'ethereum-cryptography/keccak';\nimport { bytesToHex } from 'ethereum-cryptography/utils';\n\n// Options:\nconst hdPathString = `m/44'/60'/0'/0`;\nconst type = 'HD Key Tree';\n\nclass HdKeyring {\n /* PUBLIC METHODS */\n constructor(opts = {}) {\n this.type = type;\n this._wallets = [];\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 async generateRandomMnemonic() {\n await this._initFromMnemonic(generateMnemonic(wordlist));\n }\n\n _uint8ArrayToString(mnemonic) {\n const recoveredIndices = Array.from(\n new Uint16Array(new Uint8Array(mnemonic).buffer),\n );\n return recoveredIndices.map((i) => wordlist[i]).join(' ');\n }\n\n _stringToUint8Array(mnemonic) {\n const indices = mnemonic.split(' ').map((word) => wordlist.indexOf(word));\n return new Uint8Array(new Uint16Array(indices).buffer);\n }\n\n _mnemonicToUint8Array(mnemonic) {\n let mnemonicData = mnemonic;\n // when encrypted/decrypted, buffers get cast into js object with a property type set to buffer\n if (mnemonic && mnemonic.type && mnemonic.type === 'Buffer') {\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 = mnemonicData;\n if (Array.isArray(mnemonicData)) {\n mnemonicAsString = Buffer.from(mnemonicData).toString();\n } else if (Buffer.isBuffer(mnemonicData)) {\n mnemonicAsString = mnemonicData.toString();\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 return mnemonicData;\n }\n\n async serialize() {\n const mnemonicAsString = this._uint8ArrayToString(this.mnemonic);\n const uint8ArrayMnemonic = new TextEncoder('utf-8').encode(\n mnemonicAsString,\n );\n\n return {\n mnemonic: Array.from(uint8ArrayMnemonic),\n numberOfAccounts: this._wallets.length,\n hdPath: this.hdPath,\n };\n }\n\n async deserialize(opts = {}) {\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.opts = opts;\n this._wallets = [];\n this.mnemonic = 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 addAccounts(numberOfAccounts = 1) {\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 = [];\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((w) => {\n return this._addressfromPublicKey(w.publicKey);\n });\n return Promise.resolve(hexWallets);\n }\n\n getAccounts() {\n return this._wallets.map((w) => this._addressfromPublicKey(w.publicKey));\n }\n\n /* BASE KEYRING METHODS */\n\n // returns an address specific to an app\n async getAppKeyAddress(address, origin) {\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 const appKeyAddress = normalize(\n publicToAddress(wallet.publicKey).toString('hex'),\n );\n\n return appKeyAddress;\n }\n\n // exportAccount should return a hex-encoded private key:\n async exportAccount(address, opts = {}) {\n const wallet = this._getWalletForAccount(address, opts);\n return bytesToHex(wallet.privateKey);\n }\n\n // tx is an instance of the ethereumjs-transaction class.\n async signTransaction(address, tx, opts = {}) {\n const privKey = this._getPrivateKeyFor(address, opts);\n const signedTx = tx.sign(privKey);\n // Newer versions of Ethereumjs-tx are immutable and return a new tx object\n return signedTx === undefined ? tx : signedTx;\n }\n\n // For eth_sign, we need to sign arbitrary data:\n async signMessage(address, data, opts = {}) {\n assertIsHexString(data);\n const message = remove0x(data);\n const privKey = this._getPrivateKeyFor(address, opts);\n const msgSig = ecsign(Buffer.from(message, 'hex'), privKey);\n const rawMsgSig = concatSig(msgSig.v, msgSig.r, msgSig.s);\n return rawMsgSig;\n }\n\n // For personal_sign, we need to prefix the message:\n async signPersonalMessage(address, msgHex, opts = {}) {\n const privKey = this._getPrivateKeyFor(address, opts);\n const privateKey = Buffer.from(privKey, 'hex');\n const sig = personalSign({ privateKey, data: msgHex });\n return sig;\n }\n\n // For eth_decryptMessage:\n async decryptMessage(withAccount, encryptedData) {\n const wallet = this._getWalletForAccount(withAccount);\n const { privateKey: privateKeyAsUint8Array } = wallet;\n const privateKeyAsHex = Buffer.from(privateKeyAsUint8Array).toString('hex');\n const sig = decrypt({ privateKey: privateKeyAsHex, encryptedData });\n return sig;\n }\n\n // personal_signTypedData, signs data along with the schema\n async signTypedData(\n withAccount,\n typedData,\n opts = { version: SignTypedDataVersion.V1 },\n ) {\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({ privateKey, data: typedData, version });\n }\n\n removeAccount(account) {\n const address = normalize(account);\n if (\n !this._wallets\n .map(({ publicKey }) => this._addressfromPublicKey(publicKey))\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 }) => this._addressfromPublicKey(publicKey) !== address,\n );\n }\n\n // get public key for nacl\n async getEncryptionPublicKey(withAccount, opts = {}) {\n const privKey = this._getPrivateKeyFor(withAccount, opts);\n const publicKey = getEncryptionPublicKey(privKey);\n return publicKey;\n }\n\n getFingerprint() {\n const firstIndexFingerprint = this.root.deriveChild(0).fingerprint;\n console.log('firstIndexFingerprint', firstIndexFingerprint);\n const fingerprint = keccak256(\n Buffer.from(this.root.deriveChild(0).fingerprint.toString()),\n );\n console.log('fingerPrint', fingerprint);\n const result = Buffer.from(fingerprint).toString('hex');\n console.log('result', result);\n return result;\n }\n\n _getPrivateKeyFor(address, opts = {}) {\n if (!address) {\n throw new Error('Must specify address.');\n }\n const wallet = this._getWalletForAccount(address, opts);\n return wallet.privateKey;\n }\n\n _getWalletForAccount(account, opts = {}) {\n const address = normalize(account);\n let wallet = this._wallets.find(({ publicKey }) => {\n return this._addressfromPublicKey(publicKey) === address;\n });\n if (!wallet) {\n throw new Error('HD Keyring - Unable to find matching address.');\n }\n\n if (opts.withAppKeyOrigin) {\n const { privateKey } = wallet;\n const appKeyOriginBuffer = Buffer.from(opts.withAppKeyOrigin, 'utf8');\n const appKeyBuffer = Buffer.concat([privateKey, appKeyOriginBuffer]);\n const appKeyPrivateKey = arrToBufArr(keccak256(appKeyBuffer, 256));\n const appKeyPublicKey = privateToPublic(appKeyPrivateKey);\n wallet = { privateKey: appKeyPrivateKey, publicKey: appKeyPublicKey };\n }\n\n return wallet;\n }\n\n /* PRIVATE / UTILITY METHODS */\n\n /**\n * Sets appropriate properties for the keyring based on the given\n * BIP39-compliant mnemonic.\n *\n * @param {string|Array<number>|Buffer} 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) {\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 const seed = await mnemonicToSeed(\n this.mnemonic,\n '', // No passphrase\n this._cryptographicFunctions,\n );\n this.hdWallet = HDKey.fromMasterSeed(seed);\n this.root = this.hdWallet.derive(this.hdPath);\n }\n\n // small helper function to convert publicKey in Uint8Array form to a publicAddress as a hex\n _addressfromPublicKey(publicKey) {\n return bufferToHex(\n publicToAddress(Buffer.from(publicKey), true),\n ).toLowerCase();\n }\n}\n\nHdKeyring.type = type;\nexport default HdKeyring;\n"]}
package/dist/index.d.cts CHANGED
@@ -1,2 +1,55 @@
1
- export * from "./hd-keyring.cjs";
1
+ export default HdKeyring;
2
+ declare class HdKeyring {
3
+ constructor(opts?: {});
4
+ type: string;
5
+ _wallets: any[];
6
+ _cryptographicFunctions: any;
7
+ generateRandomMnemonic(): Promise<void>;
8
+ _uint8ArrayToString(mnemonic: any): string;
9
+ _stringToUint8Array(mnemonic: any): Uint8Array;
10
+ _mnemonicToUint8Array(mnemonic: any): any;
11
+ serialize(): Promise<{
12
+ mnemonic: number[];
13
+ numberOfAccounts: number;
14
+ hdPath: any;
15
+ }>;
16
+ deserialize(opts?: {}): Promise<string[]>;
17
+ opts: {} | undefined;
18
+ mnemonic: any;
19
+ root: HDKey | null | undefined;
20
+ hdPath: any;
21
+ addAccounts(numberOfAccounts?: number): Promise<string[]>;
22
+ getAccounts(): string[];
23
+ getAppKeyAddress(address: any, origin: any): Promise<string | undefined>;
24
+ exportAccount(address: any, opts?: {}): Promise<string>;
25
+ signTransaction(address: any, tx: any, opts?: {}): Promise<any>;
26
+ signMessage(address: any, data: any, opts?: {}): Promise<string>;
27
+ signPersonalMessage(address: any, msgHex: any, opts?: {}): Promise<string>;
28
+ decryptMessage(withAccount: any, encryptedData: any): Promise<string>;
29
+ signTypedData(withAccount: any, typedData: any, opts?: {
30
+ version: SignTypedDataVersion;
31
+ }): Promise<string>;
32
+ removeAccount(account: any): void;
33
+ getEncryptionPublicKey(withAccount: any, opts?: {}): Promise<string>;
34
+ getFingerprint(): string;
35
+ _getPrivateKeyFor(address: any, opts?: {}): any;
36
+ _getWalletForAccount(account: any, opts?: {}): any;
37
+ /**
38
+ * Sets appropriate properties for the keyring based on the given
39
+ * BIP39-compliant mnemonic.
40
+ *
41
+ * @param {string|Array<number>|Buffer} mnemonic - A seed phrase represented
42
+ * as a string, an array of UTF-8 bytes, or a Buffer. Mnemonic input
43
+ * passed as type buffer or array of UTF-8 bytes must be NFKD normalized.
44
+ */
45
+ _initFromMnemonic(mnemonic: string | Array<number> | Buffer): Promise<void>;
46
+ hdWallet: HDKey | undefined;
47
+ _addressfromPublicKey(publicKey: any): string;
48
+ }
49
+ declare namespace HdKeyring {
50
+ export { type };
51
+ }
52
+ import { HDKey } from "ethereum-cryptography/hdkey";
53
+ import { SignTypedDataVersion } from "@metamask/eth-sig-util";
54
+ declare const type: "HD Key Tree";
2
55
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,iCAA6B"}
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":";AA4BA;IAEE,uBAKC;IAJC,aAAgB;IAChB,gBAAkB;IAElB,6BAA0D;IAG5D,wCAEC;IAED,2CAKC;IAED,+CAGC;IAED,0CA4BC;IAED;;;;OAWC;IAED,0CA2BC;IAfC,qBAAgB;IAEhB,cAAoB;IACpB,+BAAgB;IAChB,YAAyC;IAa3C,0DAgBC;IAED,wBAEC;IAKD,yEAYC;IAGD,wDAGC;IAGD,gEAKC;IAGD,iEAOC;IAGD,2EAKC;IAGD,sEAMC;IAGD;;wBAYC;IAED,kCAaC;IAGD,qEAIC;IAED,yBAUC;IAED,gDAMC;IAED,mDAmBC;IAID;;;;;;;OAOG;IACH,4BAJW,MAAM,GAAC,KAAK,CAAC,MAAM,CAAC,GAAC,MAAM,iBAoBrC;IAFC,4BAA0C;IAK5C,8CAIC;CACF;;;;;;AAnSD,kCAA2B"}
package/dist/index.d.mts CHANGED
@@ -1,2 +1,55 @@
1
- export * from "./hd-keyring.mjs";
1
+ export default HdKeyring;
2
+ declare class HdKeyring {
3
+ constructor(opts?: {});
4
+ type: string;
5
+ _wallets: any[];
6
+ _cryptographicFunctions: any;
7
+ generateRandomMnemonic(): Promise<void>;
8
+ _uint8ArrayToString(mnemonic: any): string;
9
+ _stringToUint8Array(mnemonic: any): Uint8Array;
10
+ _mnemonicToUint8Array(mnemonic: any): any;
11
+ serialize(): Promise<{
12
+ mnemonic: number[];
13
+ numberOfAccounts: number;
14
+ hdPath: any;
15
+ }>;
16
+ deserialize(opts?: {}): Promise<string[]>;
17
+ opts: {} | undefined;
18
+ mnemonic: any;
19
+ root: HDKey | null | undefined;
20
+ hdPath: any;
21
+ addAccounts(numberOfAccounts?: number): Promise<string[]>;
22
+ getAccounts(): string[];
23
+ getAppKeyAddress(address: any, origin: any): Promise<string | undefined>;
24
+ exportAccount(address: any, opts?: {}): Promise<string>;
25
+ signTransaction(address: any, tx: any, opts?: {}): Promise<any>;
26
+ signMessage(address: any, data: any, opts?: {}): Promise<string>;
27
+ signPersonalMessage(address: any, msgHex: any, opts?: {}): Promise<string>;
28
+ decryptMessage(withAccount: any, encryptedData: any): Promise<string>;
29
+ signTypedData(withAccount: any, typedData: any, opts?: {
30
+ version: SignTypedDataVersion;
31
+ }): Promise<string>;
32
+ removeAccount(account: any): void;
33
+ getEncryptionPublicKey(withAccount: any, opts?: {}): Promise<string>;
34
+ getFingerprint(): string;
35
+ _getPrivateKeyFor(address: any, opts?: {}): any;
36
+ _getWalletForAccount(account: any, opts?: {}): any;
37
+ /**
38
+ * Sets appropriate properties for the keyring based on the given
39
+ * BIP39-compliant mnemonic.
40
+ *
41
+ * @param {string|Array<number>|Buffer} mnemonic - A seed phrase represented
42
+ * as a string, an array of UTF-8 bytes, or a Buffer. Mnemonic input
43
+ * passed as type buffer or array of UTF-8 bytes must be NFKD normalized.
44
+ */
45
+ _initFromMnemonic(mnemonic: string | Array<number> | Buffer): Promise<void>;
46
+ hdWallet: HDKey | undefined;
47
+ _addressfromPublicKey(publicKey: any): string;
48
+ }
49
+ declare namespace HdKeyring {
50
+ export { type };
51
+ }
52
+ import { HDKey } from "ethereum-cryptography/hdkey";
53
+ import { SignTypedDataVersion } from "@metamask/eth-sig-util";
54
+ declare const type: "HD Key Tree";
2
55
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,iCAA6B"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":";AA4BA;IAEE,uBAKC;IAJC,aAAgB;IAChB,gBAAkB;IAElB,6BAA0D;IAG5D,wCAEC;IAED,2CAKC;IAED,+CAGC;IAED,0CA4BC;IAED;;;;OAWC;IAED,0CA2BC;IAfC,qBAAgB;IAEhB,cAAoB;IACpB,+BAAgB;IAChB,YAAyC;IAa3C,0DAgBC;IAED,wBAEC;IAKD,yEAYC;IAGD,wDAGC;IAGD,gEAKC;IAGD,iEAOC;IAGD,2EAKC;IAGD,sEAMC;IAGD;;wBAYC;IAED,kCAaC;IAGD,qEAIC;IAED,yBAUC;IAED,gDAMC;IAED,mDAmBC;IAID;;;;;;;OAOG;IACH,4BAJW,MAAM,GAAC,KAAK,CAAC,MAAM,CAAC,GAAC,MAAM,iBAoBrC;IAFC,4BAA0C;IAK5C,8CAIC;CACF;;;;;;AAnSD,kCAA2B"}