blsPublicToBbsPublicKey method

Uint8List blsPublicToBbsPublicKey(
  1. Uint8List blsPublicKey,
  2. int messageCount
)

Converts a BLS public key into a BBS public key.

BLS public keys are message-agnostic, while BBS public keys are message-specific. This function generates a BBS public key from a BLS public key for a given number of messages. It leverages an FFI call to the native BBS+ library for the conversion, ensuring compatibility with the BBS+ cryptographic protocols.

Implementation

Uint8List blsPublicToBbsPublicKey(Uint8List blsPublicKey, int messageCount) {
  final seedPtr = ByteArrayHelper.allocate(blsPublicKey);
  final out = calloc<ByteBuffer>();
  final err = calloc<ExternError>();

  final result =
      bbs.blsPublicKeyToBbsKey(seedPtr.ref, messageCount, out, err);

  if (result != 0) {
    final msg = err.ref.message == nullptr
        ? 'Unknown error'
        : err.ref.message.toDartString();
    calloc.free(err);
    calloc.free(out);
    calloc.free(seedPtr.ref.data);
    calloc.free(seedPtr);
    throw Exception('blsPublicKeyToBbsKey failed: $msg');
  }

  final bbsKey = out.ref.data.asTypedList(out.ref.len);

  calloc.free(err);
  calloc.free(out);
  calloc.free(seedPtr.ref.data);
  calloc.free(seedPtr);

  return Uint8List.fromList(bbsKey);
}