@metamask/eth-hd-keyring 9.0.0 → 10.0.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 +23 -1
- package/dist/index.cjs +286 -131
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +157 -44
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +157 -44
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +289 -137
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,E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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 _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"]}
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AACA,2CAM0B;AAC1B,yDAcgC;AAChC,iDAG4B;AAC5B,uDAAyD;AACzD,6EAAwE;AACxE,2CAMyB;AACzB,uDAAoD;AACpD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,CAAC;IAErD,MAAM,IAAI,GAAG,MAAM,IAAA,yBAAc,EAC/B,IAAI,CAAC,QAAQ,EACb,EAAE,EAAE,gBAAgB;IACpB,uBAAA,IAAI,yCAAwB,CAC7B,CAAC;IACF,IAAI,CAAC,QAAQ,GAAG,aAAK,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;IAC3C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAChD,CAAC,6EAQqB,SAAqB;IACzC,OAAO,IAAA,aAAK,EACV,IAAA,kBAAW,EAAC,IAAA,sBAAe,EAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,WAAW,EAAE,CACzE,CAAC;AACJ,CAAC,qEAQiB,OAAe;IAC/B,MAAM,UAAU,GAAG,IAAA,wBAAS,EAAC,OAAO,CAAC,CAAC;IACtC,IAAA,cAAM,EAAC,UAAU,EAAE,4BAA4B,CAAC,CAAC;IACjD,OAAO,IAAA,aAAK,EAAC,UAAU,CAAC,CAAC;AAC3B,CAAC;AAxhBM,cAAI,GAAW,IAAI,AAAf,CAAgB;AA2hB7B,kBAAe,SAAS,CAAC","sourcesContent":["import type { TypedTransaction } from '@ethereumjs/tx';\nimport {\n privateToPublic,\n publicToAddress,\n ecsign,\n arrToBufArr,\n bufferToHex,\n} 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 type Hex,\n remove0x,\n} 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\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\nclass HdKeyring {\n static type: string = type;\n\n type: string = type;\n\n mnemonic?: 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.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 publicToAddress(wallet.publicKey).toString('hex'),\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 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 // WARN: verify this cast to Buffer\n msgSig.v as unknown as Buffer,\n msgSig.r,\n 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(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 = arrToBufArr(keccak256(appKeyBuffer));\n const appKeyPublicKey = 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 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 /**\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 bufferToHex(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\nexport default HdKeyring;\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,54 +1,167 @@
|
|
|
1
|
-
|
|
1
|
+
import type { TypedTransaction } from "@ethereumjs/tx";
|
|
2
|
+
import { type EIP7702Authorization, type EthEncryptedData, type MessageTypes, SignTypedDataVersion, type TypedDataV1, type TypedMessage } from "@metamask/eth-sig-util";
|
|
3
|
+
import { type CryptographicFunctions } from "@metamask/key-tree";
|
|
4
|
+
import { type Hex } from "@metamask/utils";
|
|
5
|
+
import { HDKey } from "ethereum-cryptography/hdkey";
|
|
6
|
+
export type HDKeyringOptions = {
|
|
7
|
+
cryptographicFunctions?: CryptographicFunctions;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* The serialized state of an `HDKeyring` instance.
|
|
11
|
+
*
|
|
12
|
+
* @property mnemonic - The mnemonic seed phrase as an array of numbers.
|
|
13
|
+
* @property numberOfAccounts - The number of accounts in the keyring.
|
|
14
|
+
* @property hdPath - The HD path used to derive accounts.
|
|
15
|
+
*/
|
|
16
|
+
export type HDKeyringState = {
|
|
17
|
+
mnemonic: number[] | Uint8Array | Buffer | string;
|
|
18
|
+
numberOfAccounts: number;
|
|
19
|
+
hdPath: string;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Options for selecting an account from an `HDKeyring` instance.
|
|
23
|
+
*
|
|
24
|
+
* @property withAppKeyOrigin - The origin of the app requesting the account.
|
|
25
|
+
*/
|
|
26
|
+
export type HDKeyringAccountSelectionOptions = {
|
|
27
|
+
withAppKeyOrigin?: string;
|
|
28
|
+
};
|
|
2
29
|
declare class HdKeyring {
|
|
3
|
-
|
|
30
|
+
#private;
|
|
31
|
+
static type: string;
|
|
4
32
|
type: string;
|
|
5
|
-
|
|
6
|
-
|
|
33
|
+
mnemonic?: Uint8Array | null;
|
|
34
|
+
root?: HDKey | null;
|
|
35
|
+
hdWallet?: HDKey;
|
|
36
|
+
hdPath: string;
|
|
37
|
+
constructor(opts?: HDKeyringOptions);
|
|
38
|
+
/**
|
|
39
|
+
* Initialize the keyring with a random mnemonic.
|
|
40
|
+
*
|
|
41
|
+
* @returns A promise that resolves when the process is complete.
|
|
42
|
+
*/
|
|
7
43
|
generateRandomMnemonic(): Promise<void>;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
44
|
+
/**
|
|
45
|
+
* Return the serialized state of the keyring.
|
|
46
|
+
*
|
|
47
|
+
* @returns The serialized state of the keyring.
|
|
48
|
+
*/
|
|
49
|
+
serialize(): Promise<HDKeyringState>;
|
|
50
|
+
/**
|
|
51
|
+
* Initialize the keyring with the given serialized state.
|
|
52
|
+
*
|
|
53
|
+
* @param opts - The serialized state of the keyring.
|
|
54
|
+
* @returns An empty array.
|
|
55
|
+
*/
|
|
56
|
+
deserialize(opts?: Partial<HDKeyringState>): Promise<string[]>;
|
|
57
|
+
/**
|
|
58
|
+
* Add new accounts to the keyring. The accounts will be derived
|
|
59
|
+
* sequentially from the root HD wallet, using increasing indices.
|
|
60
|
+
*
|
|
61
|
+
* @param numberOfAccounts - The number of accounts to add.
|
|
62
|
+
* @returns The addresses of the new accounts.
|
|
63
|
+
*/
|
|
64
|
+
addAccounts(numberOfAccounts?: number): Promise<Hex[]>;
|
|
65
|
+
/**
|
|
66
|
+
* Get the addresses of all accounts in the keyring.
|
|
67
|
+
*
|
|
68
|
+
* @returns The addresses of all accounts in the keyring.
|
|
69
|
+
*/
|
|
70
|
+
getAccounts(): Hex[];
|
|
71
|
+
/**
|
|
72
|
+
* Get the public address of the account for the given app key origin.
|
|
73
|
+
*
|
|
74
|
+
* @param address - The address of the account.
|
|
75
|
+
* @param origin - The origin of the app requesting the account.
|
|
76
|
+
* @returns The public address of the account.
|
|
77
|
+
*/
|
|
78
|
+
getAppKeyAddress(address: Hex, origin: string): Promise<Hex>;
|
|
79
|
+
/**
|
|
80
|
+
* Export the private key for a specific account.
|
|
81
|
+
*
|
|
82
|
+
* @param address - The address of the account.
|
|
83
|
+
* @param opts - The options for exporting the account.
|
|
84
|
+
* @param opts.withAppKeyOrigin - An optional string to export the account
|
|
85
|
+
* for a specific app origin.
|
|
86
|
+
* @returns The private key of the account.
|
|
87
|
+
*/
|
|
88
|
+
exportAccount(address: Hex, opts?: {
|
|
89
|
+
withAppKeyOrigin: string;
|
|
90
|
+
}): Promise<string>;
|
|
91
|
+
/**
|
|
92
|
+
* Sign a transaction using the private key of the specified account.
|
|
93
|
+
*
|
|
94
|
+
* @param address - The address of the account.
|
|
95
|
+
* @param tx - The transaction to sign.
|
|
96
|
+
* @param opts - The options for signing the transaction.
|
|
97
|
+
* @returns The signed transaction.
|
|
98
|
+
*/
|
|
99
|
+
signTransaction(address: Hex, tx: TypedTransaction, opts?: {}): Promise<TypedTransaction>;
|
|
100
|
+
/**
|
|
101
|
+
* Sign a message using the private key of the specified account.
|
|
102
|
+
*
|
|
103
|
+
* @param address - The address of the account.
|
|
104
|
+
* @param data - The data to sign.
|
|
105
|
+
* @param opts - The options for signing the message.
|
|
106
|
+
* @returns The signature of the message.
|
|
107
|
+
*/
|
|
108
|
+
signMessage(address: Hex, data: string, opts?: HDKeyringAccountSelectionOptions): Promise<string>;
|
|
109
|
+
/**
|
|
110
|
+
* Sign a personal message using the private key of the specified account.
|
|
111
|
+
* This method is compatible with the `personal_sign` RPC method.
|
|
112
|
+
*
|
|
113
|
+
* @param address - The address of the account.
|
|
114
|
+
* @param msgHex - The message to sign.
|
|
115
|
+
* @param opts - The options for signing the message.
|
|
116
|
+
* @returns The signature of the message.
|
|
117
|
+
*/
|
|
118
|
+
signPersonalMessage(address: Hex, msgHex: string, opts?: HDKeyringAccountSelectionOptions): Promise<string>;
|
|
119
|
+
/**
|
|
120
|
+
* Decrypt an encrypted message using the private key of the specified account.
|
|
121
|
+
* The message must be encrypted using the public key of the account.
|
|
122
|
+
* This method is compatible with the `eth_decryptMessage` RPC method
|
|
123
|
+
*
|
|
124
|
+
* @param withAccount - The address of the account.
|
|
125
|
+
* @param encryptedData - The encrypted data.
|
|
126
|
+
* @returns The decrypted message.
|
|
127
|
+
*/
|
|
128
|
+
decryptMessage(withAccount: Hex, encryptedData: EthEncryptedData): Promise<string>;
|
|
129
|
+
/**
|
|
130
|
+
* Sign a typed message using the private key of the specified account.
|
|
131
|
+
* This method is compatible with the `eth_signTypedData` RPC method.
|
|
132
|
+
*
|
|
133
|
+
* @param withAccount - The address of the account.
|
|
134
|
+
* @param typedData - The typed data to sign.
|
|
135
|
+
* @param opts - The options for signing the message.
|
|
136
|
+
* @returns The signature of the message.
|
|
137
|
+
*/
|
|
138
|
+
signTypedData<Types extends MessageTypes>(withAccount: Hex, typedData: TypedDataV1 | TypedMessage<Types>, opts?: HDKeyringAccountSelectionOptions & {
|
|
30
139
|
version: SignTypedDataVersion;
|
|
31
140
|
}): Promise<string>;
|
|
32
|
-
removeAccount(account: any): void;
|
|
33
|
-
getEncryptionPublicKey(withAccount: any, opts?: {}): Promise<string>;
|
|
34
|
-
_getPrivateKeyFor(address: any, opts?: {}): any;
|
|
35
|
-
_getWalletForAccount(account: any, opts?: {}): any;
|
|
36
141
|
/**
|
|
37
|
-
*
|
|
38
|
-
*
|
|
142
|
+
* Sign an EIP-7702 authorization using the private key of the specified account.
|
|
143
|
+
* This method is compatible with the EIP-7702 standard for enabling smart contract code for EOAs.
|
|
39
144
|
*
|
|
40
|
-
* @param
|
|
41
|
-
*
|
|
42
|
-
*
|
|
145
|
+
* @param withAccount - The address of the account.
|
|
146
|
+
* @param authorization - The EIP-7702 authorization to sign.
|
|
147
|
+
* @param opts - The options for selecting the account.
|
|
148
|
+
* @returns The signature of the authorization.
|
|
43
149
|
*/
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
150
|
+
signEip7702Authorization(withAccount: Hex, authorization: EIP7702Authorization, opts?: HDKeyringAccountSelectionOptions): Promise<string>;
|
|
151
|
+
/**
|
|
152
|
+
* Remove an account from the keyring.
|
|
153
|
+
*
|
|
154
|
+
* @param account - The address of the account to remove.
|
|
155
|
+
*/
|
|
156
|
+
removeAccount(account: Hex): void;
|
|
157
|
+
/**
|
|
158
|
+
* Get the public key of the account to be used for encryption.
|
|
159
|
+
*
|
|
160
|
+
* @param withAccount - The address of the account.
|
|
161
|
+
* @param opts - The options for selecting the account.
|
|
162
|
+
* @returns The public key of the account.
|
|
163
|
+
*/
|
|
164
|
+
getEncryptionPublicKey(withAccount: Hex, opts?: HDKeyringAccountSelectionOptions): Promise<string>;
|
|
50
165
|
}
|
|
51
|
-
|
|
52
|
-
import { SignTypedDataVersion } from "@metamask/eth-sig-util";
|
|
53
|
-
declare const type: "HD Key Tree";
|
|
166
|
+
export default HdKeyring;
|
|
54
167
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,uBAAuB;AAQvD,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;AAG5B,OAAO,EAIL,KAAK,GAAG,EAET,wBAAwB;AACzB,OAAO,EAAE,KAAK,EAAE,oCAAoC;AAQpD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,sBAAsB,CAAC,EAAE,sBAAsB,CAAC;CACjD,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,EAAE,MAAM,EAAE,GAAG,UAAU,GAAG,MAAM,GAAG,MAAM,CAAC;IAClD,gBAAgB,EAAE,MAAM,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,gCAAgC,GAAG;IAC7C,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,CAAC;AAsBF,cAAM,SAAS;;IACb,MAAM,CAAC,IAAI,EAAE,MAAM,CAAQ;IAE3B,IAAI,EAAE,M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AC;IAMlB;;;;;;;;OAQG;IACG,cAAc,CAClB,WAAW,EAAE,GAAG,EAChB,aAAa,EAAE,gBAAgB,GAC9B,OAAO,CAAC,MAAM,CAAC;IAQlB;;;;;;;;OAQG;IACG,aAAa,CAAC,KAAK,SAAS,YAAY,EAC5C,WAAW,EAAE,GAAG,EAChB,SAAS,EAAE,WAAW,GAAG,YAAY,CAAC,KAAK,CAAC,EAC5C,IAAI,GAAE,gCAAgC,GAAG;QACvC,OAAO,EAAE,oBAAoB,CAAC;KACQ,GACvC,OAAO,CAAC,MAAM,CAAC;IAclB;;;;;;;;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;IAkBjC;;;;;;OAMG;IACG,sBAAsB,CAC1B,WAAW,EAAE,GAAG,EAChB,IAAI,GAAE,gCAAqC,GAC1C,OAAO,CAAC,MAAM,CAAC;CA2MnB;AAED,eAAe,SAAS,CAAC"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,54 +1,167 @@
|
|
|
1
|
-
|
|
1
|
+
import type { TypedTransaction } from "@ethereumjs/tx";
|
|
2
|
+
import { type EIP7702Authorization, type EthEncryptedData, type MessageTypes, SignTypedDataVersion, type TypedDataV1, type TypedMessage } from "@metamask/eth-sig-util";
|
|
3
|
+
import { type CryptographicFunctions } from "@metamask/key-tree";
|
|
4
|
+
import { type Hex } from "@metamask/utils";
|
|
5
|
+
import { HDKey } from "ethereum-cryptography/hdkey";
|
|
6
|
+
export type HDKeyringOptions = {
|
|
7
|
+
cryptographicFunctions?: CryptographicFunctions;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* The serialized state of an `HDKeyring` instance.
|
|
11
|
+
*
|
|
12
|
+
* @property mnemonic - The mnemonic seed phrase as an array of numbers.
|
|
13
|
+
* @property numberOfAccounts - The number of accounts in the keyring.
|
|
14
|
+
* @property hdPath - The HD path used to derive accounts.
|
|
15
|
+
*/
|
|
16
|
+
export type HDKeyringState = {
|
|
17
|
+
mnemonic: number[] | Uint8Array | Buffer | string;
|
|
18
|
+
numberOfAccounts: number;
|
|
19
|
+
hdPath: string;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Options for selecting an account from an `HDKeyring` instance.
|
|
23
|
+
*
|
|
24
|
+
* @property withAppKeyOrigin - The origin of the app requesting the account.
|
|
25
|
+
*/
|
|
26
|
+
export type HDKeyringAccountSelectionOptions = {
|
|
27
|
+
withAppKeyOrigin?: string;
|
|
28
|
+
};
|
|
2
29
|
declare class HdKeyring {
|
|
3
|
-
|
|
30
|
+
#private;
|
|
31
|
+
static type: string;
|
|
4
32
|
type: string;
|
|
5
|
-
|
|
6
|
-
|
|
33
|
+
mnemonic?: Uint8Array | null;
|
|
34
|
+
root?: HDKey | null;
|
|
35
|
+
hdWallet?: HDKey;
|
|
36
|
+
hdPath: string;
|
|
37
|
+
constructor(opts?: HDKeyringOptions);
|
|
38
|
+
/**
|
|
39
|
+
* Initialize the keyring with a random mnemonic.
|
|
40
|
+
*
|
|
41
|
+
* @returns A promise that resolves when the process is complete.
|
|
42
|
+
*/
|
|
7
43
|
generateRandomMnemonic(): Promise<void>;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
44
|
+
/**
|
|
45
|
+
* Return the serialized state of the keyring.
|
|
46
|
+
*
|
|
47
|
+
* @returns The serialized state of the keyring.
|
|
48
|
+
*/
|
|
49
|
+
serialize(): Promise<HDKeyringState>;
|
|
50
|
+
/**
|
|
51
|
+
* Initialize the keyring with the given serialized state.
|
|
52
|
+
*
|
|
53
|
+
* @param opts - The serialized state of the keyring.
|
|
54
|
+
* @returns An empty array.
|
|
55
|
+
*/
|
|
56
|
+
deserialize(opts?: Partial<HDKeyringState>): Promise<string[]>;
|
|
57
|
+
/**
|
|
58
|
+
* Add new accounts to the keyring. The accounts will be derived
|
|
59
|
+
* sequentially from the root HD wallet, using increasing indices.
|
|
60
|
+
*
|
|
61
|
+
* @param numberOfAccounts - The number of accounts to add.
|
|
62
|
+
* @returns The addresses of the new accounts.
|
|
63
|
+
*/
|
|
64
|
+
addAccounts(numberOfAccounts?: number): Promise<Hex[]>;
|
|
65
|
+
/**
|
|
66
|
+
* Get the addresses of all accounts in the keyring.
|
|
67
|
+
*
|
|
68
|
+
* @returns The addresses of all accounts in the keyring.
|
|
69
|
+
*/
|
|
70
|
+
getAccounts(): Hex[];
|
|
71
|
+
/**
|
|
72
|
+
* Get the public address of the account for the given app key origin.
|
|
73
|
+
*
|
|
74
|
+
* @param address - The address of the account.
|
|
75
|
+
* @param origin - The origin of the app requesting the account.
|
|
76
|
+
* @returns The public address of the account.
|
|
77
|
+
*/
|
|
78
|
+
getAppKeyAddress(address: Hex, origin: string): Promise<Hex>;
|
|
79
|
+
/**
|
|
80
|
+
* Export the private key for a specific account.
|
|
81
|
+
*
|
|
82
|
+
* @param address - The address of the account.
|
|
83
|
+
* @param opts - The options for exporting the account.
|
|
84
|
+
* @param opts.withAppKeyOrigin - An optional string to export the account
|
|
85
|
+
* for a specific app origin.
|
|
86
|
+
* @returns The private key of the account.
|
|
87
|
+
*/
|
|
88
|
+
exportAccount(address: Hex, opts?: {
|
|
89
|
+
withAppKeyOrigin: string;
|
|
90
|
+
}): Promise<string>;
|
|
91
|
+
/**
|
|
92
|
+
* Sign a transaction using the private key of the specified account.
|
|
93
|
+
*
|
|
94
|
+
* @param address - The address of the account.
|
|
95
|
+
* @param tx - The transaction to sign.
|
|
96
|
+
* @param opts - The options for signing the transaction.
|
|
97
|
+
* @returns The signed transaction.
|
|
98
|
+
*/
|
|
99
|
+
signTransaction(address: Hex, tx: TypedTransaction, opts?: {}): Promise<TypedTransaction>;
|
|
100
|
+
/**
|
|
101
|
+
* Sign a message using the private key of the specified account.
|
|
102
|
+
*
|
|
103
|
+
* @param address - The address of the account.
|
|
104
|
+
* @param data - The data to sign.
|
|
105
|
+
* @param opts - The options for signing the message.
|
|
106
|
+
* @returns The signature of the message.
|
|
107
|
+
*/
|
|
108
|
+
signMessage(address: Hex, data: string, opts?: HDKeyringAccountSelectionOptions): Promise<string>;
|
|
109
|
+
/**
|
|
110
|
+
* Sign a personal message using the private key of the specified account.
|
|
111
|
+
* This method is compatible with the `personal_sign` RPC method.
|
|
112
|
+
*
|
|
113
|
+
* @param address - The address of the account.
|
|
114
|
+
* @param msgHex - The message to sign.
|
|
115
|
+
* @param opts - The options for signing the message.
|
|
116
|
+
* @returns The signature of the message.
|
|
117
|
+
*/
|
|
118
|
+
signPersonalMessage(address: Hex, msgHex: string, opts?: HDKeyringAccountSelectionOptions): Promise<string>;
|
|
119
|
+
/**
|
|
120
|
+
* Decrypt an encrypted message using the private key of the specified account.
|
|
121
|
+
* The message must be encrypted using the public key of the account.
|
|
122
|
+
* This method is compatible with the `eth_decryptMessage` RPC method
|
|
123
|
+
*
|
|
124
|
+
* @param withAccount - The address of the account.
|
|
125
|
+
* @param encryptedData - The encrypted data.
|
|
126
|
+
* @returns The decrypted message.
|
|
127
|
+
*/
|
|
128
|
+
decryptMessage(withAccount: Hex, encryptedData: EthEncryptedData): Promise<string>;
|
|
129
|
+
/**
|
|
130
|
+
* Sign a typed message using the private key of the specified account.
|
|
131
|
+
* This method is compatible with the `eth_signTypedData` RPC method.
|
|
132
|
+
*
|
|
133
|
+
* @param withAccount - The address of the account.
|
|
134
|
+
* @param typedData - The typed data to sign.
|
|
135
|
+
* @param opts - The options for signing the message.
|
|
136
|
+
* @returns The signature of the message.
|
|
137
|
+
*/
|
|
138
|
+
signTypedData<Types extends MessageTypes>(withAccount: Hex, typedData: TypedDataV1 | TypedMessage<Types>, opts?: HDKeyringAccountSelectionOptions & {
|
|
30
139
|
version: SignTypedDataVersion;
|
|
31
140
|
}): Promise<string>;
|
|
32
|
-
removeAccount(account: any): void;
|
|
33
|
-
getEncryptionPublicKey(withAccount: any, opts?: {}): Promise<string>;
|
|
34
|
-
_getPrivateKeyFor(address: any, opts?: {}): any;
|
|
35
|
-
_getWalletForAccount(account: any, opts?: {}): any;
|
|
36
141
|
/**
|
|
37
|
-
*
|
|
38
|
-
*
|
|
142
|
+
* Sign an EIP-7702 authorization using the private key of the specified account.
|
|
143
|
+
* This method is compatible with the EIP-7702 standard for enabling smart contract code for EOAs.
|
|
39
144
|
*
|
|
40
|
-
* @param
|
|
41
|
-
*
|
|
42
|
-
*
|
|
145
|
+
* @param withAccount - The address of the account.
|
|
146
|
+
* @param authorization - The EIP-7702 authorization to sign.
|
|
147
|
+
* @param opts - The options for selecting the account.
|
|
148
|
+
* @returns The signature of the authorization.
|
|
43
149
|
*/
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
150
|
+
signEip7702Authorization(withAccount: Hex, authorization: EIP7702Authorization, opts?: HDKeyringAccountSelectionOptions): Promise<string>;
|
|
151
|
+
/**
|
|
152
|
+
* Remove an account from the keyring.
|
|
153
|
+
*
|
|
154
|
+
* @param account - The address of the account to remove.
|
|
155
|
+
*/
|
|
156
|
+
removeAccount(account: Hex): void;
|
|
157
|
+
/**
|
|
158
|
+
* Get the public key of the account to be used for encryption.
|
|
159
|
+
*
|
|
160
|
+
* @param withAccount - The address of the account.
|
|
161
|
+
* @param opts - The options for selecting the account.
|
|
162
|
+
* @returns The public key of the account.
|
|
163
|
+
*/
|
|
164
|
+
getEncryptionPublicKey(withAccount: Hex, opts?: HDKeyringAccountSelectionOptions): Promise<string>;
|
|
50
165
|
}
|
|
51
|
-
|
|
52
|
-
import { SignTypedDataVersion } from "@metamask/eth-sig-util";
|
|
53
|
-
declare const type: "HD Key Tree";
|
|
166
|
+
export default HdKeyring;
|
|
54
167
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,uBAAuB;AAQvD,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;AAG5B,OAAO,EAIL,KAAK,GAAG,EAET,wBAAwB;AACzB,OAAO,EAAE,KAAK,EAAE,oCAAoC;AAQpD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,sBAAsB,CAAC,EAAE,sBAAsB,CAAC;CACjD,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,EAAE,MAAM,EAAE,GAAG,UAAU,GAAG,MAAM,GAAG,MAAM,CAAC;IAClD,gBAAgB,EAAE,MAAM,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,gCAAgC,GAAG;IAC7C,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,CAAC;AAsBF,cAAM,SAAS;;IACb,MAAM,CAAC,IAAI,EAAE,MAAM,CAAQ;IAE3B,IAAI,EAAE,MAAM,CAAQ;IAEpB,QAAQ,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC;IAE7B,IAAI,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC;IAE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