decodeIss method

  1. @override
Uint8List decodeIss(
  1. String issuer
)
override

Gets the public key from the issuer

Implementation

@override
Uint8List decodeIss(String issuer) {
  List<String> split = issuer.split(DID_DELIMITER);
  if (split[0] != DID_PREFIX || split[1] != DID_METHOD) {
    throw IssuerDecodeError(issuer, 'Issuer must be a DID with method "key"');
  }
  final String multicodec = split[2];

  // Check the base
  String base = multicodec[0];
  if (base != multicodecEd25519Base) {
    throw IssuerDecodeError(
      issuer,
      'Issuer must be a key in the multicodec format',
    );
  }

  // Decode
  final Uint8List bytes = base58.decode(multicodec.substring(1));

  // Check the header
  String header = base58.encode(bytes.sublist(0, 2));
  if (header != multicodecEd25519Header) {
    throw IssuerDecodeError(
      issuer,
      'Issuer must be a public key with type "Ed25519',
    );
  }

  // Slice off the public key and validate the length
  final Uint8List publicKey = bytes.sublist(2);
  if (publicKey.length != multicodecEd25519Length) {
    throw IssuerDecodeError(
      issuer,
      'Issuer must be public key with length 32 bytes',
    );
  }

  return publicKey;
}