Skip to content

Commit ff6e17e

Browse files
Merge pull request #160 from GridPlus/hotfix-2
Fixes issue introduced in v0.7.22
2 parents 16314d8 + f91723f commit ff6e17e

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gridplus-sdk",
3-
"version": "0.7.22",
3+
"version": "0.7.23",
44
"description": "SDK to interact with GridPlus Lattice1 device",
55
"scripts": {
66
"commit": "git-cz",

src/ethereum.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -428,10 +428,13 @@ function isBase10NumStr(x) {
428428

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

0 commit comments

Comments
 (0)