importAddressForKeysPair static method

AddressObject? importAddressForKeysPair(
  1. String keys, {
  2. KeyPair? keyPair,
})

Imports an AddressObject using a key pair string.

This method takes a space-separated string containing a public key and a private key, verifies the validity of the key pair using the NosoSigner, and creates an AddressObject if the verification is successful and the key lengths are valid.

Parameters:

  • keys A space-separated string containing a public key and a private key.
  • keyPair An optional parameter of type KeyPair to provide a custom KeyPair for verification.

Returns: An AddressObject if the key pair is valid; otherwise, returns null.

Implementation

static AddressObject? importAddressForKeysPair(String keys,
    {KeyPair? keyPair}) {
  KeyPair valueKeys = keyPair == null
      ? KeyPair(publicKey: "", privateKey: "").fromString(keys)
      : keyPair;

  if (!valueKeys.isValid()) {
    return null;
  }

  bool verification = NosoSigner().verifyKeysPair(KeyPair(
      publicKey: valueKeys.publicKey, privateKey: valueKeys.privateKey));
  if (!verification) {
    return null;
  }
  return AddressObject(
      hash: NosoCore().getAddressFromPublicKey(valueKeys.publicKey),
      privateKey: valueKeys.privateKey,
      publicKey: valueKeys.publicKey);
}