In BMTFile.sol, in the unit tests we add an additional property to ChunkInclusionProof named spanValue, that is the value return by getSpanValue, which is a little endian uint32 value.
The unit test fills this value using BN.js which has support for endianess.
// TODO: Move this logic to bmt.js
const proofChunksBigNumber = proofChunks.map((i: { span: Uint8Array; sisterSegments: Uint8Array[] }) => {
return {
// eslint-disable-next-line node/no-unsupported-features/es-syntax
...i,
// Note: It has to be exactly little endian with length of 8 bytes
spanValue: new BN(i.span).toBuffer('le', 8),
}
})
The struct in Solidity is:
struct ChunkInclusionProof{
// big endian value
uint64 span;
// little endian value
uint64 spanValue;
bytes32[] sisterSegments;
}
Ideally, bmt.js must implement spanValue and use BN.js to calculate the endianess, thus the unit test implementation can be removed, making for an easier fdp-contracts API to use for developers.
In BMTFile.sol, in the unit tests we add an additional property to ChunkInclusionProof named spanValue, that is the value return by getSpanValue, which is a little endian uint32 value.
The unit test fills this value using BN.js which has support for endianess.
The struct in Solidity is:
Ideally, bmt.js must implement
spanValueand use BN.js to calculate the endianess, thus the unit test implementation can be removed, making for an easier fdp-contracts API to use for developers.