Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## Unreleased
- Preserve the sign of positive EIP-712 signed integers supplied as JavaScript numbers.
- Reset unfinished sessions when connecting to firmware v9.28.0 or newer, allowing host
reconnects while the device remains powered on.

Expand Down
7 changes: 0 additions & 7 deletions src/internal/eth/eip712.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,6 @@ export function encodeValue(
}
case DataType.INT: {
const n = parseIntValue(value);
if (typeof value === 'number') {
const bytes = bigIntToSignedBytesBE(n);
if (bytes.length > 0 && bytes[0] === 0x00) {
return bytes.subarray(1);
}
return bytes;
}
return bigIntToSignedBytesBE(n);
}
case DataType.BOOL: {
Expand Down
15 changes: 15 additions & 0 deletions test/eth-eip712.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,21 @@ describe('encodeValue', () => {
]);
});

it.each([
[0, '00'], [1, '01'], [-1, 'ff'],
[127, '7f'], [128, '0080'], [129, '0081'],
[-127, '81'], [-128, '80'], [-129, 'ff7f'],
[255, '00ff'], [256, '0100'], [-255, 'ff01'], [-256, 'ff00'],
[32767, '7fff'], [32768, '008000'],
[-32768, '8000'], [-32769, 'ff7fff'],
[65535, '00ffff'], [65536, '010000'],
] as const)('encodes signed %s consistently across input types', (value, expected) => {
const typ = parseType('int64', empty);
for (const input of [value, String(value), BigInt(value)]) {
expect(Buffer.from(encodeValue(typ, input)).toString('hex')).toBe(expected);
}
});

it('encodes booleans', () => {
expect(Array.from(encodeValue(parseType('bool', empty), false))).toEqual([0]);
expect(Array.from(encodeValue(parseType('bool', empty), true))).toEqual([1]);
Expand Down
Loading