1- import { binding } from "./binding.js" ;
1+ import { getBinding } from "./binding.js" ;
22
33// this is to sync the constant from zig to Bun which is 0xffffffff
4- const NOT_FOUND_INDEX = binding . getNotFoundIndex ( ) ;
4+ const NOT_FOUND_INDEX = 0xffffffff ;
55
66const registry = new FinalizationRegistry ( ( ptr ) => {
7+ const binding = getBinding ( ) ;
78 binding . destroyPubkeyIndexMap ( ptr ) ;
89} ) ;
910
@@ -16,6 +17,7 @@ export class PubkeyIndexMap {
1617 // see https://bun.sh/docs/api/ffi#pointers
1718 private native_ptr : number ;
1819 constructor ( ) {
20+ const binding = getBinding ( ) ;
1921 const pointer = binding . createPubkeyIndexMap ( ) ;
2022 if ( pointer == null ) {
2123 throw new Error ( "Failed to create PubkeyIndexMap" ) ;
@@ -25,6 +27,7 @@ export class PubkeyIndexMap {
2527 }
2628
2729 get ( key : Uint8Array ) : number | null {
30+ const binding = getBinding ( ) ;
2831 const index = binding . pubkeyIndexMapGet ( this . native_ptr , key , key . length ) ;
2932 if ( index === NOT_FOUND_INDEX ) {
3033 return null ;
@@ -33,6 +36,7 @@ export class PubkeyIndexMap {
3336 }
3437
3538 set ( key : Uint8Array , value : number ) : void {
39+ const binding = getBinding ( ) ;
3640 const res = binding . pubkeyIndexMapSet (
3741 this . native_ptr ,
3842 key ,
@@ -45,18 +49,22 @@ export class PubkeyIndexMap {
4549 }
4650
4751 has ( key : Uint8Array ) : boolean {
52+ const binding = getBinding ( ) ;
4853 return binding . pubkeyIndexMapHas ( this . native_ptr , key , key . length ) ;
4954 }
5055
5156 size ( ) : number {
57+ const binding = getBinding ( ) ;
5258 return binding . pubkeyIndexMapSize ( this . native_ptr ) ;
5359 }
5460
5561 delete ( key : Uint8Array ) : boolean {
62+ const binding = getBinding ( ) ;
5663 return binding . pubkeyIndexMapDelete ( this . native_ptr , key , key . length ) ;
5764 }
5865
5966 clear ( ) : void {
67+ const binding = getBinding ( ) ;
6068 binding . pubkeyIndexMapClear ( this . native_ptr ) ;
6169 }
6270}
0 commit comments