Skip to content

Commit

Permalink
Merge pull request #534 from GridPlus/dev
Browse files Browse the repository at this point in the history
v2.5.2
  • Loading branch information
alex-miller-0 committed May 1, 2023
2 parents c68322c + b9325aa commit c4dd6f7
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 12 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.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gridplus-sdk",
"version": "2.5.1",
"version": "2.5.2",
"description": "SDK to interact with GridPlus Lattice1 device",
"scripts": {
"build": "NODE_ENV=production tsc -p tsconfig.json",
Expand Down Expand Up @@ -109,4 +109,4 @@
"vitest": "^0.15.2"
},
"license": "MIT"
}
}
35 changes: 35 additions & 0 deletions src/__test__/e2e/eth.msg.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,41 @@ describe('ETH Messages', () => {
await runEthMsg(buildEthMsgReq(msg, 'eip712'), client);
});

it('Should test Vertex message', async () => {
const msg = {
'types': {
'EIP712Domain': [
{'name': 'name', 'type': 'string'},
{'name': 'version', 'type': 'string'},
{'name': 'chainId', 'type': 'uint256'},
{'name': 'verifyingContract', 'type': 'address'}
],
'Order': [
{'name': 'sender', 'type': 'bytes32'},
{'name': 'priceX18', 'type': 'int128'},
{'name': 'amount', 'type': 'int128'},
{'name': 'expiration', 'type': 'uint64'},
{'name': 'nonce', 'type': 'uint64'},
],
},
'primaryType': 'Order',
'domain': {
'name': 'Vertex',
'version': '0.0.1',
'chainId': '42161',
'verifyingContract': '0xf03f457a30e598d5020164a339727ef40f2b8fbc'
},
'message': {
'sender': '0x841fe4876763357975d60da128d8a54bb045d76a64656661756c740000000000',
'priceX18': '28898000000000000000000',
'amount': '-10000000000000000',
'expiration': '4611687701117784255',
'nonce': '1764428860167815857',
},
};
await runEthMsg(buildEthMsgReq(msg, 'eip712'), client);
})

it('Should test a large 1inch transaction', async () => {
const msg = {
domain: {
Expand Down
26 changes: 18 additions & 8 deletions src/ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -868,10 +868,27 @@ function parseEIP712Item(data, type, forJSParser = false) {
if (forJSParser) {
data = `0x${data.toString('hex')}`;
}
} else if (
ethMsgProtocol.TYPED_DATA.typeCodes[type] &&
(type.indexOf('uint') === -1 && type.indexOf('int') > -1)
) {
// Handle signed integers using bignumber.js directly
// `bignumber.js` is needed for `cbor` encoding, which gets sent to the Lattice and plays
// nicely with its firmware cbor lib.
// NOTE: If we instantiate a `bignumber.js` object, it will not match what `borc` creates
// when run inside of the browser (i.e. MetaMask). Thus we introduce this hack to make sure
// we are creating a compatible type.
// TODO: Find another cbor lib that is compataible with the firmware's lib in a browser
// context. This is surprisingly difficult - I tried several libs and only cbor/borc have
// worked (borc is a supposedly "browser compatible" version of cbor)
data = new cbor.Encoder().semanticTypes[1][0](data);
} else if (
ethMsgProtocol.TYPED_DATA.typeCodes[type] &&
(type.indexOf('uint') > -1 || type.indexOf('int') > -1)
) {
// For uints, convert to a buffer and do some sanity checking.
// Note that we could probably just use bignumber.js directly as we do with
// signed ints, but this code is battle tested and we don't want to change it.
let b = ensureHexBuffer(data);
// Edge case to handle 0-value bignums
if (b.length === 0) {
Expand All @@ -882,14 +899,7 @@ function parseEIP712Item(data, type, forJSParser = false) {
// For EIP712 encoding in this module we need strings to represent the numbers
data = `0x${b.toString('hex')}`;
} else {
// `bignumber.js` is needed for `cbor` encoding, which gets sent to the Lattice and plays
// nicely with its firmware cbor lib.
// NOTE: If we instantiate a `bignumber.js` object, it will not match what `borc` creates
// when run inside of the browser (i.e. MetaMask). Thus we introduce this hack to make sure
// we are creating a compatible type.
// TODO: Find another cbor lib that is compataible with the firmware's lib in a browser
// context. This is surprisingly difficult - I tried several libs and only cbor/borc have
// worked (borc is a supposedly "browser compatible" version of cbor)
// Load into bignumber.js used by cbor lib
data = new cbor.Encoder().semanticTypes[1][0](b.toString('hex'), 16);
}
} else if (type === 'bool') {
Expand Down

0 comments on commit c4dd6f7

Please sign in to comment.