{"id":18733177,"url":"https://github.com/bioforestchain/wallet-util","last_synced_at":"2025-11-14T00:30:17.219Z","repository":{"id":115190134,"uuid":"558802406","full_name":"BioforestChain/wallet-util","owner":"BioforestChain","description":null,"archived":false,"fork":false,"pushed_at":"2024-03-11T02:37:42.000Z","size":1772,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-28T15:46:07.826Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BioforestChain.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2022-10-28T10:30:28.000Z","updated_at":"2022-11-04T03:34:32.000Z","dependencies_parsed_at":"2024-03-11T03:35:09.774Z","dependency_job_id":null,"html_url":"https://github.com/BioforestChain/wallet-util","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/BioforestChain%2Fwallet-util","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BioforestChain%2Fwallet-util/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BioforestChain%2Fwallet-util/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BioforestChain%2Fwallet-util/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BioforestChain","download_url":"https://codeload.github.com/BioforestChain/wallet-util/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239605124,"owners_count":19666998,"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":[],"created_at":"2024-11-07T15:08:57.072Z","updated_at":"2025-11-14T00:30:17.108Z","avatar_url":"https://github.com/BioforestChain.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# wallet-util\n\nweb3 wallet util for browser.\n一个 Web3 钱包所需的 js 库，专门为现代浏览器环境进行优化。\n\nthe javascript file \u003c 200kb, wasm \u003c 200kb. (js module and wasm files are loaded on demand).\njs 部分不到 300kb, wasm 不到 200kb，采用按需加载。\n\n## How to use in browser 如何在浏览器中使用\n\n\u003e this bundle should not be rebundle again. so just put bundle files to your assets/static folder.\n\u003e 本项目已经是一个打包完成的项目，所以直接把它放到您的资源文件夹内，切莫在您的编译文件中再次进行导入，这极有可能会导致二次编译打包，从而失去最佳的优化。\n\n1. download the bundle 安装依赖\n   ```bash\n   npm install @bnqkl/wallet-util -D\n   ```\n1. coye those bundle files(`node_module/@bnqkl/wallet-util/build/web`) to your assets folder. 将 `node_module/@bnqkl/wallet-util/build/web` 中的内容拷贝到您的资源资源文件夹中.\n   ```bash\n   copy -r ./node_module/@bnqkl/wallet-util/build/web/* ./static/wallet-util/\n   ```\n1. import and setup. 导入并进行初始化.\n\n   1. in your html 在 html 文件中导入并安装\n\n      ```html\n      \u003c!-- eg: index.html --\u003e\n      \u003cscript type=\"module\"\u003e\n        import { setup, walletUtil } from './static/wallet-util';\n        setup({\n          // wasm files will use `fetch` to download.\n          // 这里将会用 `fetch` 来下载 wasm 文件.\n          wasmBaseUrl: './static/wallet-util/assets',\n        });\n        globalThis.walletUtil = walletUtil;\n      \u003c/script\u003e\n      ```\n\n   1. in your typescript declaration file: _在你的全局类型定义文件中，定义 walletUtil：_\n\n      ```ts\n      /* eg: global.d.ts */\n      declare const walletUtil: Promise\u003c\n        typeof import('@bnqkl/wallet-util')['$WalletUtil']\n      \u003e;\n      ```\n\n   1. in you typescript project file: _在你的项目代码中，使用它：_\n\n      ```ts\n      const {\n        bip39: { calcForDerivationPath, DERIVATION_PATH },\n        networks: { COIN_SYMBOL },\n      } = await walletUtil;\n\n      const testRes = await calcForDerivationPath(\n        COIN_SYMBOL.ETH,\n        '208ea2315c340b913f36f8cca16ed04396b3ec2ce0a20bb4eec7f473824af7a32217161f65f93901dd9ebaf2d3b090cee46355b853f513dff8e75f3a4f5245f6',\n        DERIVATION_PATH.ETH,\n        0, // index\n      );\n      console.log(testRes);\n      ```\n\n## API 接口\n\n```ts\nimport { setup, walletUtil, modules } from './static/wallet-util';\n```\n\n1. `setup` Initial Installation. _初始化安装_\n1. `walletUtil` Wallet function. _钱包功能_\n   1. `generateRandomMnemonic` Generate mnemonics. _生成助记词_\n   1. `calcForDerivationPath` Calculate addresses based on coin-derived paths. _计算基于币种派生路径的地址_\n1. `modules` Various core modules. _各类核心模块_\n   1. `getBitcoin`\n   1. `getTinySecp256k1`\n   1. `getBip39`\n   1. `getBip32`\n   1. `getEcpair`\n   1. `getNetworks` Web3 networks, including their coin information. _Web3 网络，包括它们的币种信息_\n   1. `getEthereumUtil`\n\n### export type/interface 导出的类型定义\n\n1. `$CoinName` All Currencies Nouns. _所有币种名词_\n1. `$DerivationPath` Derivation paths for all coins. _所有币种的派生路径_\n1. `$NetworkName` All network names. _所有网络名称_\n1. `$Network` Data structure of a network. _一个网络的数据结构_\n1. `$Language` All coin nomenclature species. _所有的助记词语种_\n1. `$Sha3Bits` Sha3 supported export lengths. _Sha3 所支持的导出长度_\n\n## Hot it work? 项目原理\n\nInspired by [iancoleman.io/bip39/](iancoleman.io/bip39/) _受到 [iancoleman.io/bip39/](iancoleman.io/bip39/) 的启发_\n\n\u003e Github: [github.com/iancoleman/bip39](https://github.com/iancoleman/bip39)\n\nI have audited and rewritten the code for almost all core modules:\n几乎所有核心的模块我都对代码进行了审计并重写：\n\n1. The biggest change is `hash-wasm`. Almost the entire library was rewritten and the synchronization interface was exposed.\n   _其中力度最大的是 `hash-wasm`。几乎整个库重写，并暴露出了同步的接口。_\n   \u003e The prerequisite for using the synchronization interface is to `prepare`, that is, to download and compile wasm. _使用同步的接口前提是要进行 `prepare`，也就是 wasm 的下载与编译的工作。_\n1. The overall project style also revolves around this step. _整体项目风格也是围绕这个步骤展开：_\n   1. the `_setup.mts` file is used to pre-process the module's synchronization functions. `_setup.mts` _文件用来对模块的同步函数进行预处理_\n   1. the dependencies between modules are first reflected in each module's own `_setup.mts`. _模块之间的依赖首先会在各个模块自身的 `_setup.mts` 中体现出来_\n1. I replaced `secp256k1` with `tiny-secp256k1` because the latter is optimized for nodejs and uses a lot of js for the web version for compatibility. _然后是 `tiny-secp256k1`，我用它替换了 `secp256k1`，因为后者主要针对 nodejs 优化，对于 web 版本的使用了大量的 js 来做兼容。_\n   \u003e `tiny-secp256k1` is mainly a modification of its installation logic to make it more intuitive to install and use in the browser\n   \u003e . _`tiny-secp256k1` 主要是修改了它的安装逻辑，使之能更加直观地在浏览器中安装并使用_\n1. `bs58check`, `bip32`, `bip39`, `bitcoinjs-lib`, `ethereumjs-util` modules, replacing the modules it depends on while keeping the original project source code as much as possible. _接着是 `bs58check`、`bip32`、`bip39`、`bitcoinjs-lib`、`ethereumjs-util` 这些模块，在尽可能保持原有项目源码的情况下，对它所依赖的模块进行了替换。_\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbioforestchain%2Fwallet-util","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbioforestchain%2Fwallet-util","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbioforestchain%2Fwallet-util/lists"}