bytesWrapDerSignature function

Uint8List bytesWrapDerSignature(
  1. Uint8List rawSignature
)

Implementation

Uint8List bytesWrapDerSignature(Uint8List rawSignature) {
  if (rawSignature.length != 64) {
    throw 'Raw signature length has to be length 64';
  }

  final r = rawSignature.sublist(0, 32);
  final s = rawSignature.sublist(32);

  Uint8List joinBytes(Uint8List arr) {
    if (arr[0] > 0x80) {
      return Uint8List.fromList([0x02, 0x21, 0x0, ...arr]);
    } else {
      return Uint8List.fromList([0x02, 0x20, ...arr]);
    }
  }

  final rBytes = joinBytes(r);
  final sBytes = joinBytes(s);

  final b1 = rBytes.length + sBytes.length;

  return Uint8List.fromList([0x30, b1, ...rBytes, ...sBytes]);
}