sign method
Takes the SigningRequest object, constructs a Pact Payload with it and signs it with the keyPair.
Implementation
@override
SignResult sign({
required SignRequest request,
required KadenaSignKeyPair keyPair,
}) {
try {
final PactCommandPayload payload = PactCommandPayload(
networkId: request.networkId,
payload: CommandPayload(
exec: ExecMessage(
data: request.data,
code: request.code,
),
),
signers: [
SignerCapabilities(
pubKey: request.signingPubKey,
clist: request.caps.map((e) => e.cap).toList(),
),
],
meta: CommandMetadata(
chainId: request.chainId,
gasLimit: request.gasLimit,
gasPrice: request.gasPrice,
sender: request.sender,
ttl: request.ttl,
creationTime: DateTime.now().millisecondsSinceEpoch - 1000,
),
nonce: DateTime.now().toIso8601String(),
);
final String cmd = jsonEncode(payload.toJson());
final hashAndSign = CryptoLib.hashAndSign(
message: cmd,
privateKey: keyPair.privateKey,
);
return SignResult(
pactCommand: PactCommand(
cmd: cmd,
hash: hashAndSign.hash,
sigs: [
Signer(
sig: hashAndSign.sig,
),
],
),
);
} catch (e) {
return SignResult(
error: SignRequestError(
msg: 'Invalid signing request',
),
);
}
}