sign method
SignResult
sign({
- required PactCommandPayload payload,
- required KadenaSignKeyPair keyPair,
override
Takes the SigningRequest object, constructs a Pact Payload with it and signs it with the keyPair.
Implementation
@override
SignResult sign({
required PactCommandPayload payload,
required KadenaSignKeyPair keyPair,
}) {
try {
// Double encode it so it gets backslashes,
// which will be added when you jsonEncode the PactCommand
final String cmd = jsonEncode(payload);
// print(jsonEncode(payload));
// print('signing payload');
// print(cmd);
// print(jsonDecode(cmd));
// print(PactCommandPayload.fromJson(jsonDecode(jsonDecode(cmd))));
// print('swag');
final hashAndSign = CryptoLib.hashAndSign(
message: cmd,
privateKey: keyPair.privateKey,
);
final PactCommand signedCmd = PactCommand(
cmd: cmd,
hash: hashAndSign.hash,
sigs: [
Signer(
sig: hashAndSign.sig,
),
],
);
return SignResult(
body: signedCmd,
signedCmd: signedCmd,
);
} catch (e) {
// print(e);
return SignResult(
error: SignRequestError(
msg: 'Invalid signing request',
),
);
}
}