generateKeyPair function

Future<RelayAuthKeyPair> generateKeyPair([
  1. Uint8List? seed
])

Implementation

Future<RelayAuthKeyPair> generateKeyPair([Uint8List? seed]) async {
  // seed ??= Uint8List.fromList(randomBytes(KEY_PAIR_SEED_LENGTH));
  ed.PrivateKey privateKey;
  ed.PublicKey publicKey;
  if (seed == null) {
    final keyPair = ed.generateKey();
    privateKey = keyPair.privateKey;
    publicKey = keyPair.publicKey;
  } else {
    privateKey = ed.newKeyFromSeed(seed);
    publicKey = ed.public(privateKey);
  }

  return RelayAuthKeyPair(
    privateKeyBytes: privateKey.bytes,
    privateKey: hex.encode(privateKey.bytes),
    publicKeyBytes: publicKey.bytes,
    publicKey: hex.encode(publicKey.bytes),
  );

  // NW
  // final kP = await bc.Ed25519().newKeyPair();
  // final pvtKey = await kP.extractPrivateKeyBytes();
  // final pbcKey = (await kP.extractPublicKey()).bytes;
  // return RelayAuthKeyPair(
  //   privateKeyBytes: pvtKey,
  //   privateKey: hex.encode(pvtKey),
  //   publicKeyBytes: pbcKey,
  //   publicKey: hex.encode(pbcKey),
  // );
}