buildTransaction method

({KeyPair keyPair, Transaction transaction}) buildTransaction(
  1. Transaction transaction,
  2. String serviceName,
  3. int index, {
  4. String pathSuffix = '',
  5. String? curve = 'ed25519',
  6. String? hashAlgo = 'sha256',
})

Implementation

({Transaction transaction, KeyPair keyPair}) buildTransaction(
  Transaction transaction,
  String serviceName,
  int index, {
  String pathSuffix = '',
  String? curve = 'ed25519',
  String? hashAlgo = 'sha256',
}) {
  final keypair =
      deriveKeypair(serviceName, index: index, pathSuffix: pathSuffix);
  final transactionWithAddress = transaction.copyWith(
    address: Address(
      address: uint8ListToHex(
        deriveAddress(
          serviceName,
          index: index + 1,
          pathSuffix: pathSuffix,
        ),
      ),
    ),
    previousPublicKey: uint8ListToHex(
      Uint8List.fromList(keypair.publicKey!),
    ),
  );
  final payloadForPreviousSignature =
      transactionWithAddress.previousSignaturePayload();
  final previousSignature =
      crypto.sign(payloadForPreviousSignature, keypair.privateKey);

  return (
    transaction:
        transactionWithAddress.setPreviousSignatureAndPreviousPublicKey(
      uint8ListToHex(previousSignature),
      uint8ListToHex(
        Uint8List.fromList(keypair.publicKey!),
      ),
    ),
    keyPair: keypair
  );
}