stringToPublicKey function

IKey stringToPublicKey(
  1. String s
)

Convert key in s to binary form

Implementation

IKey stringToPublicKey(String s) {
  if (s.substring(0, 3) == 'EOS') {
    var whole = base58ToBinary(publicKeyDataSize + 4, s.substring(3));
    var key = IKey(KeyType.k1, Uint8List(publicKeyDataSize));
    for (var i = 0; i < publicKeyDataSize; ++i) {
      key.data[i] = whole[i];
    }
    var dg = Digest("RIPEMD-160");
    var digest = dg.process(key.data);
    if (digest[0] != whole[publicKeyDataSize] ||
        digest[1] != whole[34] ||
        digest[2] != whole[35] ||
        digest[3] != whole[36]) {
      throw "checksum doesn't match";
    }
    return key;
  } else if (s.substring(0, 7) == 'PUB_K1_') {
    return stringToKey(s.substring(7), KeyType.k1, publicKeyDataSize, 'K1');
  } else if (s.substring(0, 7) == 'PUB_R1_') {
    return stringToKey(s.substring(7), KeyType.r1, publicKeyDataSize, 'R1');
  } else {
    throw 'unrecognized public key format';
  }
}