BIP32 производят разные приватные ключи в nodejs и dart (трепетание) (то же самое мнемони c) - PullRequest
0 голосов
/ 02 мая 2020

Здравствуйте, у меня возникли проблемы с BIP32

Я использую библиотеку BIP32 в nodejs и dart (трепетание)

в dart (трепетание). все мнемони c просто неверны некоторые мнемони c

в 1000 мнемони c разные приватные ключи 1-2 мнемони c

ниже дартс производнаяPath ,,

что неправильно в этом коде:

Помогите мне, пожалуйста.

  BIP32 derivePath(String path) {
        final regex = new RegExp(r"^(m\/)?(\d+'?\/)*\d+'?$");
        if (!regex.hasMatch(path)) throw new ArgumentError("Expected BIP32 Path");
        List<String> splitPath = path.split("/");
        if (splitPath[0] == "m") {
          if (parentFingerprint != 0) throw new ArgumentError("Expected master, got child");
          splitPath = splitPath.sublist(1);
          print("splitPath: "+ splitPath);
        }

        print("splitPath: "+ splitPath);
        return splitPath.fold(this, (BIP32 prevHd,String indexStr) {
          int index;
          if (indexStr.substring(indexStr.length - 1) == "'") {
            index = int.parse(indexStr.substring(0, indexStr.length - 1));
            return prevHd.deriveHardened(index);
          } else {
            index = int.parse(indexStr);
            return prevHd.derive(index);
          }
        });
      }



BIP32 derive(int index) {
    if (index > UINT32_MAX || index < 0) throw new ArgumentError("Expected UInt32");
    final isHardened = index >= HIGHEST_BIT;
    Uint8List data = new Uint8List(37);
    if (isHardened) {
      if (isNeutered()) {
        throw new ArgumentError("Missing private key for hardened child key");
      }
      data[0] = 0x00;
      data.setRange(1, 33, privateKey);
      data.buffer.asByteData().setUint32(33, index);
    } else {
      data.setRange(0, 33, publicKey);
      data.buffer.asByteData().setUint32(33, index);
    }
    final I = hmacSHA512(chainCode, data);
    final IL = I.sublist(0, 32);
    final IR = I.sublist(32);
    if (!ecc.isPrivate(IL)) {
      return derive(index + 1);
    }
    BIP32 hd;
    if (!isNeutered()) {
      final ki = ecc.privateAdd(privateKey, IL);
      if (ki == null) return derive(index + 1);
      hd = BIP32.fromPrivateKey(ki, IR, network);
    } else {
      final ki = ecc.pointAddScalar(publicKey, IL, true);
      if (ki == null) return derive(index + 1);
      hd = BIP32.fromPublicKey(ki, IR, network);
    }
    hd.depth = depth + 1;
    hd.index = index;
    hd.parentFingerprint = fingerprint.buffer.asByteData().getUint32(0);

    return hd;
  }
  BIP32 deriveHardened(int index) {
    if (index > UINT31_MAX || index < 0) throw new ArgumentError("Expected UInt31");
    return this.derive(index + HIGHEST_BIT);
  }
...