PaymentCode.fromPublicKey constructor

PaymentCode.fromPublicKey({
  1. required Uint8List pubKey,
  2. required Uint8List chainCode,
  3. bool segwit = false,
})

Implementation

factory PaymentCode.fromPublicKey({
  required Uint8List pubKey,
  required Uint8List chainCode,
  bool segwit = false,
}) {
  if (pubKey.length != 33) {
    throw ArgumentError('Public key must be 33 bytes (compressed)');
  }
  if (chainCode.length != 32) {
    throw ArgumentError('Chain code must be 32 bytes');
  }

  final payload = Uint8List(80);
  payload[0] = version;
  payload[1] = segwit ? 0x01 : 0x00;
  payload.setRange(2, 35, pubKey);
  payload.setRange(35, 67, chainCode);
  // 67..79 reserved
  return PaymentCode(payload);
}