GithubHelp home page GithubHelp logo

bip32-dart's Issues

Update to pointycastle 2.0 broke things

Hi,

I have the following code:

final mnemonic = bip39.generateMnemonic();
final seed = bip39.mnemonicToSeed(mnemonic);
final root = bip32.BIP32.fromSeed(seed); // error: Private key not in range [1, n] since pointycastle 2.0

Line three throws an error Private key not in range [1, n]

The same code seems to work well when overriding dependencies with an old pointycastle version:

dependency_overrides:
  pointycastle: ^1.0.2

Thank you.

Can't derive xpub

When deriving an xpub I have the error Missing private key for hardened child key. Aren't you supposed to be able to derive with only the public key, for watch only wallets for example ?

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

void main(List<String> arguments) {
  final base58 = 'xpub661MyMwAqRbcFxtSX21UXfaDwmdN5zmJ1C8t1cjviNkkW6gXCd7AcfciXRuhPerjhnpziEXb2fsWkAVsNEJhgM5BPgnenuDDXVPbJSadrUG';
  final node = bip32.BIP32.fromBase58(base58);
  final derived = node.derivePath("m/44'/0'/0'/0/0");
  }

NetworkType

why don't work NetworkType

into codes used NetworkType that can as argument gave to this code 'bip32.BIP32.fromSeed(seed)' and with not giving this argument, bitcoin network is default but at all no matter and dont work!!!

Publish the latest updates on pub.dev

Hello, would it be possible to publish on pub.dev the changes made with this pr #3?
We have developed a package based on these libraries, but the address derivation is wrong because there is no pull request fix.
Thanks

Error when using ecc.sign(hash,x)

I‘ve got an error when using function sign(hash, x) which is import 'package:bip32/src/utils/ecurve.dart' as ecc;

var key = '8c39fb3d889b6be22850254dc7ce3247c559d9f968785d88251ee4457633e335';
var msg = '6ad99bc30926fd79cf5a977044088fd298a59728c5b0c1040713d3a8e1c1e69b';

var sig = sign(Uint8List.fromList(HEX.decode(msg)), Uint8List.fromList(HEX.decode(key)));

The expected sig is 00349f1a2df670db4ec676674489f12684afb0ca8225e02a1299c01b8c9c99804837d43fce2267e2200526f0ad304360a5371f859698c2a1c042004c85f1c985

But it throw an error:

Unhandled exception:
Bad state: Too few elements
#0      _TypedIntListMixin.setRange (dart:typed_data-patch/typed_data_patch.dart:408:7)
#1      sign (package:bip32/src/utils/ecurve.dart:134:10)
#2      sign (file:///D:/intchains/TEST/wallet/sign.dart:104:10)
#3      main (file:///D:/intchains/TEST/wallet/sign.dart:94:13)
#5      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)

I just found it’s because the length of encodeBigInt(sig.r) is 31, but buffer.setRange(0, 32, list) need 32.
If the result encodeBigInt(sig.r) can be length 32 with 0 fixed in the front of the list, it will be right.

I hope this problem can be fixed.

negativeFlag bug

Hi

into codes used negativeFlag, In the event that not implement or declare for that !!!!

bip32-1.0.10/lib/src/utils/ecurve.dart:236:74: Error: Getter not found: 'negativeFlag'.
needsPaddingByte = ((number >> (rawSize - 1) * 8) & negativeFlag) == negativeFlag ? 1 : 0;
...................................................................................................... ^^^^^^^^^^^^

Upgrade pointycastle version

I want to use bip32 and the newest version of the pointycastle library.
But since bip32 depends on an older version of pointycastle, it would be awesome if you could update the used version.

invalid derivation result for specific path

seed:xprv9s21ZrQH143K3Jpuz63XbuGs9CH9xG4sniVBBRVm6AJR57D9arxWz6FkXF3JSxSK7jUmVA11AdWa6ZsUtwGztE4QT5i8Y457RRPvMCc39rY
path: m/1'/199007533'/627785449'/1521366139'/1'
result: xprvA39a1i4ieYqGXFQSJ1HtoUVPqzUXU1JgUW4RMgzhv8HuPvkjWBKpMCxFGU4tJKfH83m6QmiWUe2w1zfQBxRkoAoSVtYE6ZbA9RDBjZiPU7M
expected: xprvA39a1i4ieYqGUQ7G1KGnaGzGwm7v3emjms3QN4jZ3HPeubXjshA3XjD5XFaiNgWFvoyC2NV5jN4eFcsVhkrWkvwR4qjdPbue3kpt6Ur3JRf

expected value verified both using bitcoinjs/bip32 as well as bip32.org.

Looks like the derivation is skipping to the next index due to the check in bip_base.dart#109

Deriving m/1'/199007533'/627785449'/1521366139' produces the correct result so only the last segment causes the issue.

Test code:

  test('bug', () {
    final hd = BIP32.fromBase58('xprv9s21ZrQH143K3Jpuz63XbuGs9CH9xG4sniVBBRVm6AJR57D9arxWz6FkXF3JSxSK7jUmVA11AdWa6ZsUtwGztE4QT5i8Y457RRPvMCc39rY');
    final d = hd.derivePath("m/1'/199007533'/627785449'/1521366139'/1'");
    expect(d.toBase58(), 'xprvA39a1i4ieYqGUQ7G1KGnaGzGwm7v3emjms3QN4jZ3HPeubXjshA3XjD5XFaiNgWFvoyC2NV5jN4eFcsVhkrWkvwR4qjdPbue3kpt6Ur3JRf');
  });

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.