newKeychainTransaction method
Create a new keychain and build a transaction @param {String} seed Keychain's seed @param {List
Implementation
Transaction newKeychainTransaction(
String seed,
List<String> authorizedPublicKeys,
Uint8List originPrivateKey, {
String? serviceName,
String? derivationPath,
}) {
final keychain = Keychain(Uint8List.fromList(hexToUint8List(seed)));
if (serviceName!.isNotEmpty && derivationPath!.isNotEmpty) {
keychain.addService(serviceName, derivationPath);
}
final aesKey = uint8ListToHex(
Uint8List.fromList(
List<int>.generate(32, (int i) => Random.secure().nextInt(256)),
),
);
final authorizedKeys = List<AuthorizedKey>.empty(growable: true);
for (final key in authorizedPublicKeys) {
authorizedKeys.add(
AuthorizedKey(
encryptedSecretKey: uint8ListToHex(ecEncrypt(aesKey, key)),
publicKey: key,
),
);
}
return Transaction(type: 'keychain', data: Transaction.initData())
.setContent(jsonEncode(keychain.toDID()))
.addOwnership(aesEncrypt(keychain.encode(), aesKey), authorizedKeys)
.build(seed, 0)
.originSign(originPrivateKey);
}