dart-bitcoin / bip32-dart

A BIP32 compatible library for Flutter writing by Dart.
MIT License
19 stars 33 forks source link

fixed for invalid derivation result for specific path #2

Closed keninqiu closed 4 years ago

keninqiu commented 4 years ago

When do Uint8List dt = toBuffer((dd + tt) % n); It will happened the length of dt is smaller than 32. We have to make sure the length is always 32.

longhoangwkm commented 4 years ago

Could you help me add test to cover this code, Thanks!

keninqiu commented 4 years ago

import 'package:bip39/bip39.dart' as bip39; import 'package:bip32/bip32.dart' as bip32; import 'package:hex/hex.dart';

test() { const randomMnemonic = 'culture sound obey clean pretty medal churn behind chief cactus alley ready'; var seed = bip39.mnemonicToSeed(randomMnemonic); var root = bip32.BIP32.fromSeed(seed); var child = root.derivePath("m/44'/60'/0'/0/0"); var publicKey = HEX.encode(child.publicKey); print(publicKey); }

You can check it from https://iancoleman.io/bip39/. the publicKey should be 0x020c91d155e52b37d4d7d2c9127501a00a841acd8ef1d7b05f3079120df145da6a But the code shows 02cbdc25dcdde03ac8d2b3cf785d035ae86e99e662c26f99ab8ab6d0e5f3554e86

longhoangwkm commented 4 years ago

Thanks @keninqiu. I merged