newAccessKeychainTransaction method

Transaction newAccessKeychainTransaction(
  1. String seed,
  2. Uint8List keychainAddress,
  3. Uint8List originPrivateKey,
  4. int blockchainTxVersion,
)

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,
  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));
}