newAccessKeychainTransaction method
Create a new access keychain and build a transaction
seed
: Access keychain's seedkeychainAddress
: Keychain's transaction addressoriginPrivateKey
: Origin private key to attest the transaction
Implementation
Transaction newAccessKeychainTransaction(
String seed,
Uint8List keychainAddress,
Uint8List originPrivateKey,
int blockchainTxVersion,
) {
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(
Uint8List.fromList(keypair.publicKey!),
),
encryptedSecretKey: uint8ListToHex(encryptedSecretKey),
),
];
return Transaction(
type: 'keychain_access',
version: blockchainTxVersion,
data: Transaction.initData(),
)
.addOwnership(
uint8ListToHex(aesEncrypt(keychainAddress, aesKey)),
authorizedKeys,
)
.build(seed, 0)
.transaction
.originSign(uint8ListToHex(originPrivateKey));
}