Skip to content

Commit 86d6def

Browse files
committed
fix(utils): convert big number to binary number
1 parent 99c8a9f commit 86d6def

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @returns The relative array of bits.
66
*/
77
export function keyToPath(key: string | bigint): number[] {
8-
const bits = typeof key === "bigint" ? key.toString(16) : hexToBin(key as string)
8+
const bits = typeof key === "bigint" ? key.toString(2) : hexToBin(key as string)
99

1010
return bits.padStart(256, "0").split("").reverse().map(Number)
1111
}

test/smt.test.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,20 @@ describe("Sparse Merkle tree", () => {
210210
const tree2 = await smt.newMemEmptyTrie()
211211
const entries: any = [
212212
[
213-
BigInt("21109732704509421332430788199653083726879915217937906224230620716237676751825"),
214-
BigInt("2831490642350834363479855895896472449222271133340542668358367923560293907626")
213+
BigInt("20438969296305830531522370305156029982566273432331621236661483041446048135547"),
214+
BigInt("17150136040889237739751319962368206600863150289695545292530539263327413090784")
215215
],
216216
[
217-
BigInt("11261494335128908291348759183228049614138863748694001088920573059515194150558"),
218-
BigInt("19888788720420510634339318541055455303900497018439146284554761253419098060032")
217+
BigInt("8459688297517826598613412977307486050019239051864711035321718508109192087854"),
218+
BigInt("8510347201346963732943571140849185725417245763047403804445415726302354045170")
219+
],
220+
[
221+
BigInt("18746990989203767017840856832962652635369613415011636432610873672704085238844"),
222+
BigInt("10223238458026721676606706894638558676629446348345239719814856822628482567791")
223+
],
224+
[
225+
BigInt("13924553918840562069536446401916499801909138643922241340476956069386532478098"),
226+
BigInt("13761779908325789083343687318102407319424329800042729673292939195255502025802")
219227
]
220228
]
221229

0 commit comments

Comments
 (0)