Skip to content

Instantly share code, notes, and snippets.

@zed-wong
Created April 15, 2025 09:33
Show Gist options
  • Save zed-wong/4f3751c9775c833b262d24bb7721ab3a to your computer and use it in GitHub Desktop.
Save zed-wong/4f3751c9775c833b262d24bb7721ab3a to your computer and use it in GitHub Desktop.

单私钥派生多链地址方式表(Universal Key Derivation)

本文档说明如何从一个唯一的 Ed25519 私钥(如 Mixin Bot 私钥),统一派生出多链的地址与私钥,以实现自动化资产管理与跨链操作。


Step 1:主私钥与统一入口

输入

  • Mixin Bot 的 Ed25519 私钥(64字节,Base64或Hex格式)

转换方式

  • 使用 HKDF(HMAC-SHA512)从私钥生成 64字节 entropy
const entropy = hkdf(mixinPrivateKey, salt = 'mrmarket-universal-seed', 64 bytes);
  • 所有后续链地址派生均基于此 entropy
  • 派生具有确定性、一致性、可恢复性

Step 2:多链派生结构表

链名 派生路径 密钥曲线 地址格式 需要库 备注
Bitcoin (BTC) m/44'/0'/0'/0/0 secp256k1 Base58 bitcoinjs-lib 标准兼容
Ethereum (ETH) m/44'/60'/0'/0/0 secp256k1 0x hex ethers.js 含所有 EVM 链
Polygon / BNB / Arbitrum / Optimism / Base / Fantom m/44'/60'/0'/0/0 secp256k1 0x hex 同上 共用 ETH 地址结构
TRON (TRX) m/44'/195'/0'/0/0 secp256k1 Base58 tronweb ETH 公钥转换
Solana (SOL) m/44'/501'/0'/0' ed25519 Base58 @solana/web3.js, ed25519-hd-key 直接支持
Sui m/44'/784'/0'/0'/0' ed25519 0x hex @mysten/sui.js BCS地址结构
Aptos m/44'/637'/0'/0'/0' ed25519 0x hex aptos SDK 路径固定
Cosmos / Osmosis / Kava m/44'/118'/0'/0/0 secp256k1 bech32 @cosmjs/launchpad 通用 Cosmos 系
Binance Chain (BEP2) m/44'/714'/0'/0/0 secp256k1 bnb1... @binance-chain/javascript-sdk 与 BNB EVM 不同
Cardano m/1852'/1815'/0'/0/0 ed25519-bip32 addr1... cardano-serialization-lib 需 extended 曲线
Polkadot / Kusama / Moonbeam 自定义(取entropy前32字节) sr25519 ss58 @polkadot/util-crypto 使用 sr25519
Stellar m/44'/148'/0' ed25519 G... stellar-sdk SLIP-0010兼容
Near 无路径,原生seed ed25519 ed25519 pubkey near-api-js 不支持路径结构
Tezos m/44'/1729'/0'/0' ed25519 tz1... taquito, conseiljs 支持助记词/seed
Algorand 无路径,原生seed ed25519 algo addr algosdk 从seed生成
Elrond (MultiversX) m/44'/508'/0'/0/0 ed25519 erd1... @elrondnetwork/erdjs 正常支持
Thorchain m/44'/931'/0'/0/0 secp256k1 bech32 @cosmjs Cosmos 系
Zilliqa m/44'/313'/0'/0/0 secp256k1 0x hex zilliqa-js 类 ETH 格式

Step 3:统一派生代码结构建议

export function deriveAllAddresses(entropy: Buffer) {
  return {
    btc: deriveBTC(entropy),
    eth: deriveETH(entropy),
    sol: deriveSolana(entropy),
    sui: deriveSui(entropy),
    aptos: deriveAptos(entropy),
    cosmos: deriveCosmos(entropy),
    tron: deriveTRX(entropy),
    cardano: deriveCardano(entropy),
    polkadot: derivePolkadot(entropy),
    // ...其他链
  }
}

附录:CoinType 对照(用于 BIP44)

链名 Coin Type
Bitcoin 0
Ethereum / EVM 60
TRON 195
Cosmos 118
Binance Chain 714
Cardano 1815
Aptos 637
Sui 784
Tezos 1729
Stellar 148
Elrond 508
Zilliqa 313

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment