keyGen method

Future<String> keyGen(
  1. String name, {
  2. String type = 'ed25519',
  3. int? size,
})

Returns a Future that resolves to the IPNS name (base36-encoded libp2p-key CID) of a newly generated Ed25519 key stored under name.

type currently only accepts 'ed25519'. Ed25519 keys have a fixed 256-bit size, so size must be null or 256; any other value is rejected rather than silently ignored.

The key is stored in the node's encrypted keystore, which must be unlocked first (see SecurityManager.unlockKeystore). Once stored, the key can be used by passing name as keyName to publishIPNS.

Throws ArgumentError if type is unsupported or size is not 256. Throws StateError if the keystore is locked or name already exists.

Implementation

Future<String> keyGen(
  String name, {
  String type = 'ed25519',
  int? size,
}) async {
  if (type.toLowerCase() != 'ed25519') {
    throw ArgumentError.value(
      type,
      'type',
      'Only ed25519 keys are supported for IPNS publishing',
    );
  }
  if (size != null && size != 256) {
    throw ArgumentError.value(
      size,
      'size',
      'Ed25519 keys are fixed at 256 bits; omit size or pass 256',
    );
  }
  final publicKey = await _container.get<SecurityManager>().generateSecureKey(
    name,
  );
  return deriveIpnsName(publicKey);
}