-1

I am trying to generate a master key using BIP32 library.

I do the following:

mport 'package:dart_bip32/dart_bip32.dart' as bip32;
import 'package:dart_mnemonic/dart_mnemonic.dart';

final mnemo = Mnemonic(language: Language.english, length: 12);
final BIP32 rootKey = bip32.BIP32.fromSeed(mnemo.seed);
print(rootKey.toBase58());
///xprv9s21ZrQH143K2TBr73E3SPEwGRdjca3r5nK44nyUaw61krVUtEdfrFj4f5nJ2k1EAMK4PLPk8f2AKsc13J4e7Z6a17Tkr3MPcUMBUqNLztS

But it turns out that I can only get the extended key. And this is not the original key, right? How can I generate the original key?

Next I try to follow the LnUrl-auth specification (LUD-04, LUD-05 ) to get the linkingPrivKey.

But due to the inability to get the original key, this is not possible.

final BIP32 derivedKey = rootKey.derivePath("m/138'/0");
final hmacSha256 = Hmac(sha256, derivedKey.privateKey!);
final derivationMaterial = hmacSha256.convert(baseUrl.codeUnits);

final stream = derivationMaterial.bytes.sublist(0, 16);

    final pathSuffix = List.generate(4, (index) {
      if (index ~/ 4 == 0) {
        final croppedList =
            Uint8List.fromList(stream.sublist(index * 4, index * 4 + 4));
        return ByteData.sublistView(croppedList).getUint32(0);
      }
    });

    final linkingKey = rootKey.derivePath(
        "m/138'/${pathSuffix[0]}/${pathSuffix[1]}/${pathSuffix[2]}/${pathSuffix[3]}");

I will be very grateful for explanations and any help!

kannt_im
  • 9
  • 3
  • What should be the *original* key? Post a link to your reference! Actually, the master keys correspond to the extended keys. The private extended key is the concatenation of private key and chain code, the corresponding public extended key is the concatenation of the public key associated with the private key and the same chain code. If you mean with *original* key the private key: This alone is not sufficient to derive the child keys, for this the chain code (and thus the extended priavte key) is needed. – Topaco Sep 01 '23 at 06:41

0 Answers0