parseSerializedSignature function

SignaturePubkeyPair parseSerializedSignature(
  1. String serializedSignature
)

Implementation

SignaturePubkeyPair parseSerializedSignature(
  String serializedSignature,
) {
  final bytes = base64Decode(serializedSignature);
  final signatureScheme = SIGNATURE_SCHEME_TO_FLAG.flagToScheme(bytes[0]);
  if (signatureScheme == SignatureScheme.MultiSig) {
    final signature = bytes.sublist(1);
    final multisig = MultiSigStruct.fromJson(SuiBcs.MultiSig.parse(signature));
    return SignaturePubkeyPair(signatureScheme, signature, multisig: multisig);
  }

  if (signatureScheme == SignatureScheme.ZkLogin) {
		final signatureBytes = bytes.sublist(1);
		final signature = parseZkLoginSignature(signatureBytes);
		final iss = extractClaimValue<String>(signature.inputs.issBase64Details, 'iss');
    final addressSeed = BigInt.parse(signature.inputs.addressSeed);
		final address = computeZkLoginAddressFromSeed(addressSeed, iss);
    final zkLgoin = {
				"inputs": signature.inputs,
				"maxEpoch": signature.maxEpoch,
				"userSignature": signature.userSignature,
				"iss": iss,
				"address": address,
        "addressSeed": addressSeed,
		};
    return SignaturePubkeyPair(signatureScheme, bytes, zkLogin: zkLgoin);
  }

  PublicKey getPublicKey(SignatureScheme scheme, Uint8List bytes) {
    switch (scheme) {
      case SignatureScheme.Ed25519:
        return Ed25519PublicKey.fromBytes(bytes);
      case SignatureScheme.Secp256k1:
        return Secp256PublicKey.fromBytes(bytes, SIGNATURE_SCHEME_TO_FLAG.Secp256k1);
      case SignatureScheme.Secp256r1:
        return Secp256PublicKey.fromBytes(bytes, SIGNATURE_SCHEME_TO_FLAG.Secp256r1);
      default:
        throw ArgumentError("Undefined Scheme: $scheme");
    }
  }

  int getPublicKeySize(SignatureScheme scheme) {
    switch (scheme) {
      case SignatureScheme.Ed25519:
        return 32;
      case SignatureScheme.Secp256k1:
      case SignatureScheme.Secp256r1:
        return 33;
      default:
        throw ArgumentError("Undefined Public Key Scheme: $scheme");
    }
  }

  final publicKeySize = getPublicKeySize(signatureScheme);
  final signature = bytes.sublist(1, bytes.length - publicKeySize);
  final pubkeyBytes = bytes.sublist(1 + signature.length);
  final pubKey = getPublicKey(signatureScheme, pubkeyBytes);

  return SignaturePubkeyPair(signatureScheme, signature, pubKey: pubKey);
}