signTransaction method

  1. @override
Future<Map<String, dynamic>> signTransaction(
  1. dynamic transaction
)

Send transaction objects to MyAlgo for approval. If approved, the response is an array of signed transaction objects, with the binary blob field base64 encoded to prevent transmission issues.

Implementation

@override
Future<Map<String, dynamic>> signTransaction(dynamic transaction) async {
  if (transaction is Map<String, dynamic>) {
    transaction = mapToJSObj(transaction);
  }
  var c = Completer<Map<String, dynamic>>();
  promiseToFuture(myAlgo.signTransaction([transaction])).then((value) {
    if (value is! List || value.isEmpty) {
      return c.completeError('Invalid transaction');
    }

    final transactions = value.map((tx) {
      final txId = getProperty(tx, 'txID') ?? '';
      final blob = getProperty(tx, 'blob') ?? [];

      return <String, dynamic>{
        'txId': txId,
        'blob': base64Encode(blob),
      };
    }).toList();

    return c.complete(transactions[0]);
  }).onError((error, stackTrace) => c.completeError(_handleError(error)));

  return c.future;
}