Comparing version 3.18.0 to 3.18.1
import typedDataExample from '../../__mocks__/typedDataExample.json'; | ||
import typedDataStructArrayExample from '../../__mocks__/typedDataStructArrayExample.json'; | ||
import { number } from '../../src'; | ||
@@ -12,3 +13,8 @@ import { BigNumberish } from '../../src/utils/number'; | ||
); | ||
const typeEncodingStructArr = encodeType(typedDataStructArrayExample, 'Mail'); | ||
expect(typeEncodingStructArr).toMatchInlineSnapshot( | ||
`"Mail(from:Person,to:Person,posts_len:felt,posts:Post*)Person(name:felt,wallet:felt)Post(title:felt,content:felt)"` | ||
); | ||
}); | ||
test('should get right type hash', () => { | ||
@@ -27,3 +33,12 @@ const typeHashDomain = getTypeHash(typedDataExample, 'StarkNetDomain'); | ||
); | ||
const typeHashPost = getTypeHash(typedDataStructArrayExample, 'Post'); | ||
expect(typeHashPost).toMatchInlineSnapshot( | ||
`"0x1d71e69bf476486b43cdcfaf5a85c00bb2d954c042b281040e513080388356d"` | ||
); | ||
const typeHashMailWithStructArray = getTypeHash(typedDataStructArrayExample, 'Mail'); | ||
expect(typeHashMailWithStructArray).toMatchInlineSnapshot( | ||
`"0x873b878e35e258fc99e3085d5aaad3a81a0c821f189c08b30def2cde55ff27"` | ||
); | ||
}); | ||
test('should get right hash for StarkNetDomain', () => { | ||
@@ -35,2 +50,3 @@ const hash = getStructHash(typedDataExample, 'StarkNetDomain', typedDataExample.domain as any); | ||
}); | ||
test('should get right hash for entire message', () => { | ||
@@ -41,2 +57,10 @@ const hash = getMessageHash(typedDataExample, '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826'); | ||
); | ||
const hashStructArr = getMessageHash( | ||
typedDataStructArrayExample, | ||
'0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826' | ||
); | ||
expect(hashStructArr).toMatchInlineSnapshot( | ||
`"0x5914ed2764eca2e6a41eb037feefd3d2e33d9af6225a9e7fe31ac943ff712c"` | ||
); | ||
}); | ||
@@ -43,0 +67,0 @@ |
@@ -0,1 +1,7 @@ | ||
## [3.18.1](https://github.com/0xs34n/starknet.js/compare/v3.18.0...v3.18.1) (2022-07-23) | ||
### Bug Fixes | ||
- struct array hashing ([e1f82df](https://github.com/0xs34n/starknet.js/commit/e1f82dfd575be4c84b291c33f8169bf367493603)) | ||
# [3.18.0](https://github.com/0xs34n/starknet.js/compare/v3.17.0...v3.18.0) (2022-07-23) | ||
@@ -2,0 +8,0 @@ |
@@ -74,2 +74,7 @@ "use strict"; | ||
} | ||
// Include pointers (struct arrays) | ||
if (type[type.length - 1] === '*') { | ||
// eslint-disable-next-line no-param-reassign | ||
type = type.slice(0, -1); | ||
} | ||
if (dependencies.includes(type)) { | ||
@@ -128,2 +133,11 @@ return dependencies; | ||
} | ||
if (Object.keys(typedData.types) | ||
.map(function (x) { return "".concat(x, "*"); }) | ||
.includes(type)) { | ||
var structHashes = data.map(function (struct) { | ||
// eslint-disable-next-line @typescript-eslint/no-use-before-define | ||
return (0, exports.getStructHash)(typedData, type.slice(0, -1), struct); | ||
}); | ||
return [type, (0, hash_1.computeHashOnElements)(structHashes)]; | ||
} | ||
if (type === 'felt*') { | ||
@@ -130,0 +144,0 @@ return ['felt*', (0, hash_1.computeHashOnElements)(data)]; |
{ | ||
"name": "starknet", | ||
"version": "3.18.0", | ||
"version": "3.18.1", | ||
"description": "JavaScript library for StarkNet", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -39,2 +39,8 @@ import { computeHashOnElements, getSelectorFromName } from '../hash'; | ||
// Include pointers (struct arrays) | ||
if (type[type.length - 1] === '*') { | ||
// eslint-disable-next-line no-param-reassign | ||
type = type.slice(0, -1); | ||
} | ||
if (dependencies.includes(type)) { | ||
@@ -106,2 +112,14 @@ return dependencies; | ||
if ( | ||
Object.keys(typedData.types) | ||
.map((x) => `${x}*`) | ||
.includes(type) | ||
) { | ||
const structHashes: string[] = (data as unknown[]).map((struct) => { | ||
// eslint-disable-next-line @typescript-eslint/no-use-before-define | ||
return getStructHash(typedData, type.slice(0, -1), struct as Record<string, unknown>); | ||
}); | ||
return [type, computeHashOnElements(structHashes)]; | ||
} | ||
if (type === 'felt*') { | ||
@@ -108,0 +126,0 @@ return ['felt*', computeHashOnElements(data as string[])]; |
@@ -103,2 +103,7 @@ 'use strict'; | ||
} | ||
// Include pointers (struct arrays) | ||
if (type[type.length - 1] === '*') { | ||
// eslint-disable-next-line no-param-reassign | ||
type = type.slice(0, -1); | ||
} | ||
if (dependencies.includes(type)) { | ||
@@ -178,2 +183,15 @@ return dependencies; | ||
} | ||
if ( | ||
Object.keys(typedData.types) | ||
.map(function (x) { | ||
return ''.concat(x, '*'); | ||
}) | ||
.includes(type) | ||
) { | ||
var structHashes = data.map(function (struct) { | ||
// eslint-disable-next-line @typescript-eslint/no-use-before-define | ||
return (0, exports.getStructHash)(typedData, type.slice(0, -1), struct); | ||
}); | ||
return [type, (0, hash_1.computeHashOnElements)(structHashes)]; | ||
} | ||
if (type === 'felt*') { | ||
@@ -180,0 +198,0 @@ return ['felt*', (0, hash_1.computeHashOnElements)(data)]; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6113076
255
160179