Skip to content

Commit

Permalink
Merge pull request #379 from GridPlus/dev
Browse files Browse the repository at this point in the history
v1.2.4
  • Loading branch information
alex-miller-0 authored May 3, 2022
2 parents 3be9142 + f0e0175 commit a6f124c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gridplus-sdk",
"version": "1.2.3",
"version": "1.2.4",
"description": "SDK to interact with GridPlus Lattice1 device",
"scripts": {
"build": "tsc -p tsconfig.json",
Expand Down
14 changes: 9 additions & 5 deletions src/genericSigning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ export const buildGenericSigningMsgRequest = function (req) {
const { encoding } = encodedPayload;
let { payloadBuf } = encodedPayload;
const payloadDataSz = payloadBuf.length;
// Size of data payload that can be included in the first/base request
const maxExpandedSz = baseDataSz + extraDataMaxFrames * extraDataFrameSz;
// Sanity checks
if (!payloadDataSz) {
throw new Error('Payload could not be handled.');
Expand All @@ -71,7 +73,12 @@ export const buildGenericSigningMsgRequest = function (req) {

// If there is a decoder attached to our payload, add it to
// the data field of the request.
if (decoder && calldataDecoding && decoder.length <= calldataDecoding.maxSz) {
const hasDecoder = (decoder && calldataDecoding && decoder.length <= calldataDecoding.maxSz);
// Make sure the payload AND decoder data fits in the firmware buffer.
// If it doesn't, we can't include the decoder because the payload will likely
// be pre-hashed and the decoder data isn't part of the message to sign.
const decoderFits = (hasDecoder && payloadBuf.length + decoder.length <= maxExpandedSz);
if (hasDecoder && decoderFits) {
const decoderBuf = Buffer.alloc(8 + decoder.length);
// First write th reserved word
decoderBuf.writeUInt32LE(calldataDecoding.reserved, 0);
Expand Down Expand Up @@ -110,17 +117,14 @@ export const buildGenericSigningMsgRequest = function (req) {
buf.writeUInt8(omitPubkey ? 1 : 0, off);
off += 1;

// Size of data payload that can be included in the first/base request
const maxExpandedSz = baseDataSz + extraDataMaxFrames * extraDataFrameSz;
// Flow data into extraData requests if applicable
const extraDataPayloads = [];
let prehash = null;

let didPrehash = false;
if (payloadBuf.length > baseDataSz) {
if (prehashAllowed && payloadBuf.length > maxExpandedSz) {
// If we prehash, we need to provide the full payload size, including
// any calldata decoder bytes.
// If we prehash, we need to provide the full payload size
buf.writeUInt16LE(payloadBuf.length, off);
off += 2;
didPrehash = true;
Expand Down

0 comments on commit a6f124c

Please sign in to comment.