quicksignSingleCommand method

  1. @override
QuicksignResponse quicksignSingleCommand({
  1. required List<KadenaSignKeyPair> keyPairs,
  2. required CommandSigData commandSigData,
})
override

Takes a commandSigData and signs it with the keyPair. See https://github.com/kadena-io/KIPs/blob/master/kip-0015.md for the CommandSigData spec, and how you are meant to sign it, and respond to errors while signing.

Implementation

@override
QuicksignResponse quicksignSingleCommand({
  required List<KadenaSignKeyPair> keyPairs,
  required CommandSigData commandSigData,
}) {
  bool signed = false;
  Uint8List hash = CryptoLib.blakeHashToBinary(commandSigData.cmd);

  // Loop through the requests signatures
  for (QuicksignSigner sig in commandSigData.sigs) {
    // Loop through the key pairs
    for (KadenaSignKeyPair keyPair in keyPairs) {
      // If the public key matches the key pair public key
      if (sig.pubKey == keyPair.publicKey) {
        try {
          // Sign the hash
          final String signature = CryptoLib.signHashBytes(
            hash: hash,
            privateKey: keyPair.privateKey,
          );

          // Add the signature to the sig object
          sig.sig = signature;
        } catch (e) {
          // If there was an error
          return QuicksignResponse(
            commandSigData: commandSigData,
            outcome: QuicksignOutcome(
              result: QuicksignOutcome.failure,
              msg: '${Constants.quicksignSignFailure}${keyPair.publicKey}',
            ),
          );
        }

        // We have "signed" it even if there is an error
        signed = true;
      }
    }
  }

  if (signed) {
    // Create the outcome object
    final outcome = QuicksignOutcome(
      result: QuicksignOutcome.success,
      hash: CryptoLib.base64UrlBinHash(hash),
    );

    // Create the response object and append it to the responses
    return QuicksignResponse(
      commandSigData: commandSigData,
      outcome: outcome,
    );
  } else {
    // If the keypair was not found, no sig!
    return QuicksignResponse(
      commandSigData: commandSigData,
      outcome: QuicksignOutcome(
        result: QuicksignOutcome.noSig,
      ),
    );
  }
}