generatePubKeyHashAddress function

ToplAddress generatePubKeyHashAddress(
  1. Bip32PublicKey publicKey,
  2. NetworkId networkPrefix,
  3. String propositionType
)

Generate Hash Address using the Public Key and Network Prefix First parameter is the Base-58 encoded byte list of the public key The second parameter is the prefix of the network where the address will be used Third is the type of proposition used Returns the address and whether or not the operation was successful

Implementation

ToplAddress generatePubKeyHashAddress(
    Bip32PublicKey publicKey, NetworkId networkPrefix, String propositionType) {
  final b = BytesBuilder();

  // validate propositionType

  if (!isValidPropositionType(propositionType)) {
    throw ArgumentError('Invalid proposition type provided');
  }

  // validate public key
  if (publicKey.rawKey.length != 32) {
    throw ArgumentError('Invalid publicKey length');
  }

  // network hex + proposition hex
  b.add([networkPrefix, propositionMap[propositionType] ?? 0x01]);
  b.add(createHash(Uint8List.fromList(publicKey.rawKey)));
  final concatEvidence = b.toBytes().sublist(0, 34);
  b.clear();
  b.add(concatEvidence);
  final address = b.toBytes().sublist(0, ToplAddress.addressSize);
  return ToplAddress(address,
      networkId: networkPrefix,
      proposition: PropositionType.fromName(propositionType));
}