Topl Bip Library
用于在 Flutter 中构建 Topl 区块链钱包移动应用程序的库。请阅读 文档 以获取更多信息。
关于
该项目是 Flutter/Dart 移动应用程序开发人员的 Topl 区块链入口。目前正在进行中。
它将为目前正在积极开发的 Ribn 钱包提供支持。
当前特点
- CIP-1852 HD 钱包兼容性
- Topl 特定的 BIP32 确定性密钥生成器
- 与 BIP39 兼容的助记词
- BIP32-ED25519 扩展密钥(用于签名交易)
- 密钥生成器工具,利用 PBKDF2(为助记词提供额外的安全性)
正在积极开发的功能
- 创建、广播和跟踪交易和费用
- 签名和验证消息
- 管理私钥和公钥
- 列出、创建、更新或删除钱包
计划功能
- 质押账户的实用工具
- 自定义资产交易
- 智能合约
BIP32 用法
import 'package:bip_topl/bip_topl.dart';
import 'package:pinenacl/x25519.dart';
void main() {
const coder = HexCoder.instance;
const derivator = Bip32Ed25519KeyDerivation.instance;
const keyPair = {
'xprv':
'c0b712f4c0e2df68d0054112efb081a7fdf8a3ca920994bf555c40e4c249354993f774ae91005da8c69b2c4c59fa80d741ecea6722262a6b4576d259cf60ef30c05763f0b510942627d0c8b414358841a19748ec43e1135d2f0c4d81583188e1',
'xpub':
'906d68169c8bbfc3f0cd901461c4c824e9ab7cdbaf38b7b6bd66e54da0411109c05763f0b510942627d0c8b414358841a19748ec43e1135d2f0c4d81583188e1'
};
const address_ix = 0;
// generate master public and private key from encoded keyPair
final masterPrivateKey =
Bip32SigningKey.decode(keyPair['xprv']!, coder: coder);
final masterPublicKey = Bip32VerifyKey.decode(keyPair['xpub']!, coder: coder);
print(Base58Encoder.instance.encode(masterPrivateKey
.rawKey)); //4rUU8Ee5K6h663ByMBLRjXgs9GYsFsTiUFujbfSvDpKjFuEfErc9QFfs4F1fej5jJ6gwavr2zU66c6ASagaqyZcb
print(Base58Encoder.instance.encode(
masterPublicKey.rawKey)); //AinUA7J1kBiyvDZ8nPL8BoCE9PBxPjKzUfoyhpXAGTXn
//BIP-44 path: m / purpose' / coin_type' / account_ix' / change_chain / address_ix
//You can iterate through a CIP-1852 path by deriving based on each index at a time. For this example, we will only use one idx.
final derivedPrv = derivator.ckdPriv(masterPrivateKey, address_ix);
final derivedPub = derivator.ckdPub(masterPublicKey, address_ix);
print(Base58Encoder.instance.encode(derivedPrv
.rawKey)); //2JAppvWBAgmd7B6s1XDcNPrxtSfT5MCcnhuVxeNKLYHyyqa3U9FE6BD85QPVtn6iWAisSq2WKyvbZFzmEA1rYbMP
print(Base58Encoder.instance.encode(
derivedPub.rawKey)); //AGj1p3atP5m2UVxXrBBtmniWQyV4HZGkVesii922zwj6
}
BIP39 用法
// BIP39 Mnemonics
// Can be used to generate the root key of a given HDTree, an address, or simply convert bits to mnemonic for human friendly value
// For more details about the protocol, see
// [Bitcoin Improvement Proposal 39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki)
import 'dart:math';
import 'package:bip_topl/bip_topl.dart';
void main() {
const mnemonic =
'legal winner thank year wave sausage worth useful legal winner thank yellow';
// mnemonic to entropy
final entropy = mnemonicToEntropy(mnemonic, 'english');
print(entropy); // 7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f
// mnemonic to seedHex
// accepts an optional passphrase to strengthen the security of the mnemonic
final seedHex = mnemonicToSeedHex(mnemonic, passphrase: 'TREZOR');
print(
seedHex); //2e8905819b8723fe2c1d161860e5ee1830318dbf49a83bd451cfb8440c28bd6fa457fe1296106559a3c80937a1c1069be3a3a5bd381ee6260e8d9739fce1f607
//entropy to mnemonic
final code = entropyToMnemonic(entropy);
print(
code); //legal winner thank year wave sausage worth useful legal winner thank yellow
// validate Mnemonic
final validation = validateMnemonic(code, 'english');
print(validation); // true
// generateMnemonic with 15 words
final words = generateMnemonic(Random.secure(), strength: 160);
print(words); // should be random 15 word mnemonic
}