@@ -767,7 +767,79 @@ pub fn BeaconStateView_getSingleProof(env: napi.Env, cb: napi.CallbackInfo(1)) !
767767 return result ;
768768}
769769
770- // pub fn BeaconStateView_createMultiProof
770+ /// Create a compact multi-proof from a descriptor.
771+ /// Arguments:
772+ /// - arg 0: descriptor (Uint8Array)
773+ /// Returns: {type: string, leaves: Uint8Array[], descriptor: Uint8Array}
774+ pub fn BeaconStateView_createMultiProof (env : napi.Env , cb : napi .CallbackInfo (1 )) ! napi.Value {
775+ const persistent_merkle_tree = @import ("persistent_merkle_tree" );
776+ const cached_state = try env .unwrap (CachedBeaconState , cb .this ());
777+
778+ const descriptor_info = try cb .arg (0 ).getTypedarrayInfo ();
779+ if (descriptor_info .array_type != .uint8 ) {
780+ try env .throwTypeError ("Expected descriptor to be a Uint8Array" );
781+ return env .getNull ();
782+ }
783+ const descriptor = descriptor_info .data ;
784+
785+ // Get the root node from the state
786+ try cached_state .state .commit ();
787+ const root_node = switch (cached_state .state .* ) {
788+ inline else = > | * state | state .base_view .data .root ,
789+ };
790+
791+ // Create proof input for compact multi-proof
792+ const proof_input = persistent_merkle_tree.proof.ProofInput {
793+ .compactMulti = .{ .descriptor = descriptor },
794+ };
795+
796+ var proof = persistent_merkle_tree .proof .createProof (
797+ allocator ,
798+ & pool .pool ,
799+ root_node ,
800+ proof_input ,
801+ ) catch {
802+ try env .throwError ("STATE_ERROR" , "Failed to create proof" );
803+ return env .getNull ();
804+ };
805+ defer proof .deinit (allocator );
806+
807+ // Create result object matching Proof interface
808+ const result = try env .createObject ();
809+
810+ // Add type field
811+ const proof_type_str = switch (proof ) {
812+ inline else = > | _ , tag | @tagName (tag ),
813+ };
814+ try result .setNamedProperty ("type" , try env .createStringUtf8 (proof_type_str ));
815+
816+ // Extract data based on proof type
817+ switch (proof ) {
818+ .compactMulti = > | compact | {
819+ // Create leaves array
820+ const leaves_array = try env .createArray ();
821+ for (compact .leaves , 0.. ) | leaf , i | {
822+ var leaf_bytes : [* ]u8 = undefined ;
823+ const leaf_buf = try env .createArrayBuffer (32 , & leaf_bytes );
824+ @memcpy (leaf_bytes [0.. 32], & leaf );
825+ try leaves_array .setElement (@intCast (i ), try env .createTypedarray (.uint8 , 32 , leaf_buf , 0 ));
826+ }
827+ try result .setNamedProperty ("leaves" , leaves_array );
828+
829+ // Create descriptor Uint8Array
830+ var descriptor_bytes : [* ]u8 = undefined ;
831+ const descriptor_buf = try env .createArrayBuffer (compact .descriptor .len , & descriptor_bytes );
832+ @memcpy (descriptor_bytes [0.. compact .descriptor .len ], compact .descriptor );
833+ try result .setNamedProperty ("descriptor" , try env .createTypedarray (.uint8 , compact .descriptor .len , descriptor_buf , 0 ));
834+ },
835+ else = > {
836+ try env .throwError ("STATE_ERROR" , "Unexpected proof type" );
837+ return env .getNull ();
838+ },
839+ }
840+
841+ return result ;
842+ }
771843
772844pub fn BeaconStateView_computeUnrealizedCheckpoints (env : napi.Env , cb : napi .CallbackInfo (0 )) ! napi.Value {
773845 const cached_state = try env .unwrap (CachedBeaconState , cb .this ());
@@ -995,7 +1067,7 @@ pub fn register(env: napi.Env, exports: napi.Value) !void {
9951067 method (0 , BeaconStateView_getFinalizedRootProof ),
9961068 // method(1, BeaconStateView_getSyncCommitteesWitness),
9971069 method (1 , BeaconStateView_getSingleProof ),
998- // method(1, BeaconStateView_createMultiProof),
1070+ method (1 , BeaconStateView_createMultiProof ),
9991071
10001072 method (0 , BeaconStateView_computeUnrealizedCheckpoints ),
10011073
0 commit comments