Skip to content

Commit

Permalink
Merge pull request #160 from GridPlus/hotfix-2
Browse files Browse the repository at this point in the history
Fixes issue introduced in v0.7.22
  • Loading branch information
alex-miller-0 authored Jun 15, 2021
2 parents 16314d8 + f91723f commit ff6e17e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion 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": "0.7.22",
"version": "0.7.23",
"description": "SDK to interact with GridPlus Lattice1 device",
"scripts": {
"commit": "git-cz",
Expand Down
12 changes: 8 additions & 4 deletions src/ethereum.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,10 +428,13 @@ function isBase10NumStr(x) {

// Ensure a param is represented by a buffer
// TODO: Remove circular dependency in util.js so that we can put this function there
function ensureHexBuffer(x) {
function ensureHexBuffer(x, zeroIsNull=true) {
try {
// For null values, return a 0-sized buffer
if (x === null) return Buffer.alloc(0);
// For null values, return a 0-sized buffer. For most situations we assume
// 0 should be represented with a zero-length buffer (e.g. for RLP-building
// txs), but it can also be treated as a 1-byte buffer (`00`) if needed
if (x === null || (x === 0 && zeroIsNull === true))
return Buffer.alloc(0);
const isNumber = typeof x === 'number' || isBase10NumStr(x);
// Otherwise try to get this converted to a hex string
if (isNumber) {
Expand Down Expand Up @@ -646,7 +649,8 @@ function parseEIP712Item(data, type, isEthers=false) {
data = `0x${data.toString('hex')}`
}
} else if (type === 'uint8' || type === 'uint16' || type === 'uint32' || type === 'uint64') {
data = parseInt(ensureHexBuffer(data).toString('hex'), 16)
// In this case we want the hex buffer to represent `0` as a 1-byte buffer (`00`)
data = parseInt(ensureHexBuffer(data, false).toString('hex'), 16)
} else if (type === 'uint256') {
let b = ensureHexBuffer(data);
// Edge case to handle 0-value bignums
Expand Down

0 comments on commit ff6e17e

Please sign in to comment.