generateSignRequest method
Build a keystone-sign-request (6101). Reply: keystone-sign-result
(6102).
Implementation
SignRequest<TronSignatureResult> generateSignRequest(
TronSignRequestProps props,
) {
final requestId = resolveRequestId(_context, props.requestId);
parsePath(props.path); // validate shape; the wire carries the string form
final xfp = normalizeXfp(props.xfp);
if (props.rawData.isEmpty) {
throw EraSdkError('invalid-props', 'rawData must not be empty');
}
if (!_hex64.hasMatch(props.latestBlock.hash)) {
throw EraSdkError(
'invalid-props',
'latestBlock.hash must be the FULL 64-hex block id (the device slices ref_block_hash from it)',
);
}
final proto = encodeSignRequestProto(TronSignRequestProto(
// Zero-padded to eight characters: the firmware parses this string with
// a hex reader that yields 0 for anything shorter than 4 bytes, and a
// zero fingerprint fails validation — a wallet whose fingerprint starts
// with a zero byte (1 in 256) could not sign at all without the pad.
xfpHex: xfpToHex(xfp),
signId: uuidStringify(requestId),
hdPath: props.path,
timestamp: props.timestamp ?? 0,
decimals: props.display?.decimals ?? 6,
token: props.display?.token ?? '',
contractAddress: props.display?.contractAddress,
from: props.display?.from,
to: props.display?.to,
memo: props.display?.memo,
value: props.display?.value,
fee: props.display?.fee,
latestBlock: props.latestBlock,
rawData: props.rawData,
));
final ur = Ur(
'keystone-sign-request',
cborEncode(cbMap([
(1, cbBytes(gzipCompress(proto))),
(2, cbText(props.origin ?? _context.origin)),
])),
);
return makeSignRequest(
ur: ur,
requestId: requestId,
replyTypes: _replyTypes,
context: _context,
parse: (reply) => _parseTronSignature(reply, requestId),
);
}