quicksign method
QuicksignResult
quicksign({
- required QuicksignRequest request,
- required List<
KadenaSignKeyPair> keyPairs,
override
Takes the QuicksignRequest object and signs each cmd in the request. See https://github.com/kadena-io/KIPs/blob/jam/quicksign/kip-0015.md for the Quicksign spec. This accepts multiple key pairs because the signing wallet might contain multiple keys.
Implementation
@override
QuicksignResult quicksign({
required QuicksignRequest request,
required List<KadenaSignKeyPair> keyPairs,
}) {
List<QuicksignResponse> responses = [];
// Loop through the list of commands
for (CommandSigData command in request.commandSigDatas) {
bool signed = false;
Uint8List hash = CryptoLib.blakeHashToBinary(command.cmd);
// Loop through the requests signatures
for (QuicksignSigner sig in command.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
final response = QuicksignResponse(
commandSigData: command,
outcome: QuicksignOutcome(
result: QuicksignOutcome.failure,
msg: '${Constants.quicksignSignFailure}${keyPair.publicKey}',
),
);
responses.add(response);
}
// 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
final response = QuicksignResponse(
commandSigData: command,
outcome: outcome,
);
responses.add(response);
} else {
// If the keypair was not found, no sig!
final response = QuicksignResponse(
commandSigData: command,
outcome: QuicksignOutcome(
result: QuicksignOutcome.noSig,
),
);
responses.add(response);
}
}
return QuicksignResult(
responses: responses,
);
}