Skip to content

Commit 2cd5401

Browse files
authored
Merge pull request #33 from akifoq/main
Merkle proofs: export new functions + throw on missing keys
2 parents 56f30d7 + 1733779 commit 2cd5401

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

src/dict/Dictionary.spec.ts

+2
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ describe('Dictionary', () => {
139139
dictHash
140140
);
141141
}
142+
143+
expect(() => d.generateMerkleProof([6])).toThrow();
142144
});
143145

144146
it('should generate merkle updates', () => {

src/dict/generateMerkleProof.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,11 @@ export function generateMerkleProofDirect<K extends DictionaryKeyTypes, V>(
103103
keys: K[],
104104
keyObject: DictionaryKey<K>
105105
): Cell {
106-
keys = keys.filter((key) => dict.has(key));
106+
keys.forEach((key) => {
107+
if (!dict.has(key)) {
108+
throw new Error(`Trying to generate merkle proof for a missing key "${key}"`)
109+
}
110+
})
107111
const s = beginCell().storeDictDirect(dict).asSlice();
108112
return doGenerateMerkleProof(
109113
'',

src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ export { Writable } from './boc/Writable';
2828
export { Dictionary, DictionaryKey, DictionaryKeyTypes, DictionaryValue } from './dict/Dictionary';
2929

3030
// Exotics
31-
export { exoticMerkleProof } from './boc/cell/exoticMerkleProof';
31+
export { exoticMerkleProof, convertToMerkleProof } from './boc/cell/exoticMerkleProof';
3232
export { exoticMerkleUpdate } from './boc/cell/exoticMerkleUpdate';
3333
export { exoticPruned } from './boc/cell/exoticPruned';
3434

3535
// Merkle trees
36-
export { generateMerkleProof } from './dict/generateMerkleProof'
36+
export { generateMerkleProof, generateMerkleProofDirect } from './dict/generateMerkleProof'
3737
export { generateMerkleUpdate } from './dict/generateMerkleUpdate'
3838

3939
// Tuples

0 commit comments

Comments
 (0)