newAccessKeychainTransaction method
Create a new access keychain and build a transaction @param {String} seed Access keychain's seed @param {Uint8List} keychainAddress Keychain's transaction address @param {Uint8List} originPrivateKey Origin private key to attest the transaction
Implementation
Transaction newAccessKeychainTransaction(
String seed,
Uint8List keychainAddress,
Uint8List originPrivateKey,
) {
final aesKey = uint8ListToHex(
Uint8List.fromList(
List<int>.generate(32, (int i) => Random.secure().nextInt(256)),
),
);
final keypair = deriveKeyPair(seed, 0);
final encryptedSecretKey = ecEncrypt(aesKey, keypair.publicKey);
final authorizedKeys = <AuthorizedKey>[
AuthorizedKey(
publicKey: uint8ListToHex(keypair.publicKey),
encryptedSecretKey: uint8ListToHex(encryptedSecretKey),
)
];
return Transaction(type: 'keychain_access', data: Transaction.initData())
.addOwnership(aesEncrypt(keychainAddress, aesKey), authorizedKeys)
.build(seed, 0)
.originSign(originPrivateKey);
}