{"id":15694333,"url":"https://github.com/pcaversaccio/mnemonic-to-private-key","last_synced_at":"2025-05-08T22:15:17.831Z","repository":{"id":105100524,"uuid":"386551474","full_name":"pcaversaccio/mnemonic-to-private-key","owner":"pcaversaccio","description":"A JavaScript script that converts the mnemonic phrase into a wallet private key using the ethers.js library.","archived":false,"fork":false,"pushed_at":"2023-02-06T13:33:33.000Z","size":163,"stargazers_count":18,"open_issues_count":0,"forks_count":5,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-05-08T22:15:09.647Z","etag":null,"topics":["ethereum","ethersjs","javascript","mnemonic-phrase","private-key"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"wtfpl","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pcaversaccio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-07-16T07:36:12.000Z","updated_at":"2025-05-03T20:35:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"d9979392-d7b6-4168-b9d7-6b483fd84478","html_url":"https://github.com/pcaversaccio/mnemonic-to-private-key","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pcaversaccio%2Fmnemonic-to-private-key","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pcaversaccio%2Fmnemonic-to-private-key/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pcaversaccio%2Fmnemonic-to-private-key/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pcaversaccio%2Fmnemonic-to-private-key/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pcaversaccio","download_url":"https://codeload.github.com/pcaversaccio/mnemonic-to-private-key/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253154977,"owners_count":21862623,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ethereum","ethersjs","javascript","mnemonic-phrase","private-key"],"created_at":"2024-10-03T18:56:38.737Z","updated_at":"2025-05-08T22:15:17.805Z","avatar_url":"https://github.com/pcaversaccio.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# From Mnemonic Phrase to Private Key\n\nThe JavaScript-based file [`script.js`](./script.js) converts the mnemonic phrase into a wallet private key using the [ethers.js](https://docs.ethers.io/v6) library and the default derivation path `m/44'/60'/0'/0/0`. First, create a `secrets.json` file that includes the mnemonic phrase. The file should look like the following (make sure to always [`.gitignore`](./.gitignore) it!):\n\n```json\n{\n  \"seedPhrase\": \"brain theme ...\"\n}\n```\n\nThen run `npm i` first and thereafter `node .\\script.js`.\n\n## Background on Deriving Path\n\nWe define the following 5 levels in the [BIP32](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki) path:\n\n```\nm / purpose' / coin_type' / account' / change / address_index\n```\n\n\u003e `m = Master`\n\nEach level has a special meaning, described in the sections below. Apostrophe in the path indicates that [BIP32](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki) hardened derivation is used. Generally, there are two posible types of [BIP32](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki) derivation, _hardened_ or _non-hardened_. In standard [BIP32](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki) path notation, hardened derivation at a particular level is indicated by an apostrophe. For example, the following example of hardened derivation is used for the first three levels, while for the last two levels non-hardened derivation is used:\n\n```\nm / 44' / 0' / 1' / 1 / 33\n```\n\n\u003e With non-hardened keys, you can prove a child public key is linked to a parent public key using just the public keys. You can also derive public child keys from a public parent key, which enables watch-only wallets. With hardened child keys, you cannot prove that a child public key is linked to a parent public key.\n\n### `purpose`\n\n`purpose` is a constant set to `44'` (or `0x8000002C`) following the [BIP43](https://github.com/bitcoin/bips/blob/master/bip-0043.mediawiki) recommendation. It indicates that the subtree of this node is used according to this specification.\n\n\u003e Hardened derivation is used at this level.\n\n### `coin_type`\n\nOne master node (seed) can be used for unlimited number of independent cryptocurrencies such as Bitcoin, Litecoin, or Ethereum. However, sharing the same space for various cryptocurrencies has some disadvantages.\n\nThis level creates a separate subtree for every cryptocurrency, avoiding reusing addresses across cryptocurrency and improving privacy issues.\n\n`coin_type` is a constant, set for each cryptocurrency. Cryptocurrency developers can ask for registering unused number for their project.\n\n\u003e Hardened derivation is used at this level.\n\n### `account`\n\nThis level splits the key space into independent user identities, so the wallet never mixes the coins across different accounts.\n\nUsers can use these accounts to organise the funds in the same fashion as bank accounts; for donation purposes (where all addresses are considered public), for saving purposes, for common expenses etc.\n\nAccounts are numbered from index `0` in sequentially increasing manner. This number is used as child index in [BIP32](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki) derivation.\n\n\u003e Hardened derivation is used at this level. Furthermore, the software in use should prevent a creation of an account if a previous account does not have a transaction history (meaning none of its addresses have been used before). It needs to discover all used accounts after importing the seed from an external source.\n\n### `change`\n\nConstant `0` is used for external chain and constant `1` for internal chain (also known as change addresses). External chain is used for addresses that are meant to be visible outside of the wallet (e.g. for receiving payments). Internal chain is used for addresses which are not meant to be visible outside of the wallet and is used for return transaction change.\n\n\u003e Non-hardened a.k.a public derivation is used at this level.\n\n### `address_index`\n\nAddresses are numbered from index `0` in sequentially increasing manner. This number is used as child index in [BIP32](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki) derivation.\n\n\u003e Non-hardened derivation is used at this level.\n\n### Visualisation\n\n![](assets/img/derivation_path.png)\n\n## References\n\n[1] https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki\n\n[2] https://github.com/bitcoin/bips/blob/master/bip-0043.mediawiki\n\n[3] https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki#path-levels\n\n[4] https://wiki.trezor.io/Hardened_and_non-hardened_derivation\n\n[5] https://learnmeabitcoin.com/technical/derivation-paths\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpcaversaccio%2Fmnemonic-to-private-key","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpcaversaccio%2Fmnemonic-to-private-key","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpcaversaccio%2Fmnemonic-to-private-key/lists"}