derDecode static method

Uint8List derDecode(
  1. BinaryBlob key
)

Implementation

static Uint8List derDecode(BinaryBlob key) {
  final expectedLength = Secp256k1PublicKey.DER_PREFIX.length +
      Secp256k1PublicKey.RAW_KEY_LENGTH;
  if (key.byteLength != expectedLength) {
    final bl = key.byteLength;
    throw "secp256k1 DER-encoded public key must be $expectedLength bytes long (is $bl)";
  }
  final rawKey = key.sublist(Secp256k1PublicKey.DER_PREFIX.length);
  if (!u8aEq(derEncode(rawKey), key)) {
    throw 'secp256k1 DER-encoded public key is invalid. A valid secp256k1 DER-encoded public key '
        "must have the following prefix: ${Secp256k1PublicKey.DER_PREFIX}";
  }
  return rawKey;
}