From 1262015320c35d1b48a32622abcbc23a4e07e9ad Mon Sep 17 00:00:00 2001 From: stefanMadzharov <83451593+stefanMadzharov@users.noreply.github.com> Date: Sat, 12 Oct 2024 08:01:03 +0300 Subject: [PATCH 1/4] Journal processing for Risc0 (#225) Co-authored-by: Stefan Madzharov Co-authored-by: feltroid Prime <96737978+feltroidprime@users.noreply.github.com> --- .../groth16_contract_generator/calldata.py | 2 +- .../generator_risc0.py | 14 ++++++-------- .../parsing_utils.py | 19 ++++++++----------- .../src/groth16_verifier.cairo | 11 ++++++----- src/src/circuits/dummy.cairo | 3 ++- src/src/circuits/ec.cairo | 3 ++- src/src/circuits/isogeny.cairo | 15 +++------------ src/src/utils/calldata.cairo | 12 ++++++------ src/src/utils/risc0.cairo | 17 +++++++++++++++-- 9 files changed, 49 insertions(+), 47 deletions(-) diff --git a/hydra/garaga/starknet/groth16_contract_generator/calldata.py b/hydra/garaga/starknet/groth16_contract_generator/calldata.py index b540beaa..5c768462 100644 --- a/hydra/garaga/starknet/groth16_contract_generator/calldata.py +++ b/hydra/garaga/starknet/groth16_contract_generator/calldata.py @@ -32,7 +32,7 @@ def groth16_calldata_from_vk_and_proof( calldata.extend(proof.serialize_to_calldata()) calldata.extend(mpc.serialize_to_calldata()) - if proof.image_id and proof.journal_digest: + if proof.image_id and proof.journal: # Risc0 mode. print("Risc0 mode") msm = MSMCalldataBuilder( diff --git a/hydra/garaga/starknet/groth16_contract_generator/generator_risc0.py b/hydra/garaga/starknet/groth16_contract_generator/generator_risc0.py index a0d48e4d..01b099eb 100644 --- a/hydra/garaga/starknet/groth16_contract_generator/generator_risc0.py +++ b/hydra/garaga/starknet/groth16_contract_generator/generator_risc0.py @@ -71,8 +71,8 @@ def gen_risc0_groth16_verifier( use garaga::definitions::{{G1Point, G1G2Pair}}; use garaga::groth16::{{multi_pairing_check_{curve_id.name.lower()}_3P_2F_with_extra_miller_loop_result}}; use garaga::ec_ops::{{G1PointTrait, G2PointTrait, ec_safe_add}}; - use garaga::utils::risc0::compute_receipt_claim; - use garaga::utils::calldata::{{FullProofWithHintsRisc0, deserialize_full_proof_with_hints_risc0}}; + use garaga::utils::risc0::{{compute_receipt_claim, journal_sha256}}; + use garaga::utils::calldata::deserialize_full_proof_with_hints_risc0; use super::{{N_FREE_PUBLIC_INPUTS, vk, ic, precomputed_lines, T}}; const ECIP_OPS_CLASS_HASH: felt252 = {hex(ecip_class_hash)}; @@ -93,7 +93,7 @@ def gen_risc0_groth16_verifier( let groth16_proof = fph.groth16_proof; let image_id = fph.image_id; - let journal_digest = fph.journal_digest; + let journal = fph.journal; let mpcheck_hint = fph.mpcheck_hint; let small_Q = fph.small_Q; let msm_hint = fph.msm_hint; @@ -104,6 +104,7 @@ def gen_risc0_groth16_verifier( let ic = ic.span(); + let journal_digest = journal_sha256(journal); let claim_digest = compute_receipt_claim(image_id, journal_digest); // Start serialization with the hint array directly to avoid copying it. @@ -142,10 +143,7 @@ def gen_risc0_groth16_verifier( small_Q ); if check == true {{ - self - .process_public_inputs( - starknet::get_caller_address(), claim_digest - ); + self.process_public_inputs(starknet::get_caller_address(), journal); return true; }} else {{ return false; @@ -155,7 +153,7 @@ def gen_risc0_groth16_verifier( #[generate_trait] impl InternalFunctions of InternalFunctionsTrait {{ fn process_public_inputs( - ref self: ContractState, user: ContractAddress, claim_digest: u256, + ref self: ContractState, user: ContractAddress, public_inputs: Span, ) {{ // Process the public inputs with respect to the caller address (user). // Update the storage, emit events, call other contracts, etc. }} diff --git a/hydra/garaga/starknet/groth16_contract_generator/parsing_utils.py b/hydra/garaga/starknet/groth16_contract_generator/parsing_utils.py index 93134f7a..a1353ad3 100644 --- a/hydra/garaga/starknet/groth16_contract_generator/parsing_utils.py +++ b/hydra/garaga/starknet/groth16_contract_generator/parsing_utils.py @@ -304,7 +304,7 @@ class Groth16Proof: public_inputs: List[int] = dataclasses.field(default_factory=list) curve_id: CurveID = None image_id: bytes = None # Only used for risc0 proofs - journal_digest: bytes = None # Only used for risc0 proofs + journal: bytes = None # Only used for risc0 proofs def __post_init__(self): assert ( @@ -387,7 +387,6 @@ def _from_risc0( CONTROL_ROOT: int = RISC0_CONTROL_ROOT, BN254_CONTROL_ID: int = RISC0_BN254_CONTROL_ID, ) -> "Groth16Proof": - assert len(image_id) <= 32, "image_id must be 32 bytes" CONTROL_ROOT_0, CONTROL_ROOT_1 = split_digest(CONTROL_ROOT) proof = seal[4:] @@ -424,7 +423,7 @@ def _from_risc0( BN254_CONTROL_ID, ], image_id=image_id, - journal_digest=journal_digest, + journal=journal, ) def serialize_to_calldata(self) -> list[int]: @@ -437,21 +436,19 @@ def serialize_to_calldata(self) -> list[int]: cd.extend(io.bigint_split(self.b.y[1])) cd.extend(io.bigint_split(self.c.x)) cd.extend(io.bigint_split(self.c.y)) - if self.image_id and self.journal_digest: + if self.image_id and self.journal: # Risc0 mode. - # Public inputs will be reconstructed from image id and journal digest. + # Public inputs will be reconstructed from image id and journal. image_id_u256 = io.bigint_split( int.from_bytes(self.image_id, "big"), 8, 2**32 )[::-1] - journal_digest_u256 = io.bigint_split( - int.from_bytes(self.journal_digest, "big"), 8, 2**32 - )[::-1] + journal = list(self.journal) # Span of u32, length 8. cd.append(8) cd.extend(image_id_u256) - # Span of u32, length 8. - cd.append(8) - cd.extend(journal_digest_u256) + # Span of u8, length depends on input + cd.append(len(self.journal)) + cd.extend(journal) else: cd.append(len(self.public_inputs)) for pub in self.public_inputs: diff --git a/src/contracts/risc0_verifier_bn254/src/groth16_verifier.cairo b/src/contracts/risc0_verifier_bn254/src/groth16_verifier.cairo index 9032567f..a0d22a5c 100644 --- a/src/contracts/risc0_verifier_bn254/src/groth16_verifier.cairo +++ b/src/contracts/risc0_verifier_bn254/src/groth16_verifier.cairo @@ -13,8 +13,8 @@ mod Risc0Groth16VerifierBN254 { use garaga::definitions::{G1Point, G1G2Pair}; use garaga::groth16::{multi_pairing_check_bn254_3P_2F_with_extra_miller_loop_result}; use garaga::ec_ops::{G1PointTrait, G2PointTrait, ec_safe_add}; - use garaga::utils::risc0::compute_receipt_claim; - use garaga::utils::calldata::{FullProofWithHintsRisc0, deserialize_full_proof_with_hints_risc0}; + use garaga::utils::risc0::{compute_receipt_claim, journal_sha256}; + use garaga::utils::calldata::deserialize_full_proof_with_hints_risc0; use super::{N_FREE_PUBLIC_INPUTS, vk, ic, precomputed_lines, T}; const ECIP_OPS_CLASS_HASH: felt252 = @@ -35,7 +35,7 @@ mod Risc0Groth16VerifierBN254 { let groth16_proof = fph.groth16_proof; let image_id = fph.image_id; - let journal_digest = fph.journal_digest; + let journal = fph.journal; let mpcheck_hint = fph.mpcheck_hint; let small_Q = fph.small_Q; let msm_hint = fph.msm_hint; @@ -46,6 +46,7 @@ mod Risc0Groth16VerifierBN254 { let ic = ic.span(); + let journal_digest = journal_sha256(journal); let claim_digest = compute_receipt_claim(image_id, journal_digest); // Start serialization with the hint array directly to avoid copying it. @@ -84,7 +85,7 @@ mod Risc0Groth16VerifierBN254 { small_Q ); if check == true { - self.process_public_inputs(starknet::get_caller_address(), claim_digest); + self.process_public_inputs(starknet::get_caller_address(), journal); return true; } else { return false; @@ -94,7 +95,7 @@ mod Risc0Groth16VerifierBN254 { #[generate_trait] impl InternalFunctions of InternalFunctionsTrait { fn process_public_inputs( - ref self: ContractState, user: ContractAddress, claim_digest: u256, + ref self: ContractState, user: ContractAddress, public_inputs: Span, ) { // Process the public inputs with respect to the caller address (user). // Update the storage, emit events, call other contracts, etc. } diff --git a/src/src/circuits/dummy.cairo b/src/src/circuits/dummy.cairo index 1d24697a..6deda304 100644 --- a/src/src/circuits/dummy.cairo +++ b/src/src/circuits/dummy.cairo @@ -9,7 +9,8 @@ use core::circuit::CircuitElement as CE; use core::circuit::CircuitInput as CI; use garaga::definitions::{ get_a, get_b, get_p, get_g, get_min_one, G1Point, G2Point, E12D, u288, E12DMulQuotient, - G1G2Pair, BNProcessedPair, BLSProcessedPair, MillerLoopResultScalingFactor, G2Line + G1G2Pair, BNProcessedPair, BLSProcessedPair, MillerLoopResultScalingFactor, G2Line, + get_BLS12_381_modulus, get_BN254_modulus }; use garaga::ec_ops::{SlopeInterceptOutput, FunctionFeltEvaluations, FunctionFelt}; use core::option::Option; diff --git a/src/src/circuits/ec.cairo b/src/src/circuits/ec.cairo index 95b81cbb..b7cdf0a9 100644 --- a/src/src/circuits/ec.cairo +++ b/src/src/circuits/ec.cairo @@ -9,7 +9,8 @@ use core::circuit::CircuitElement as CE; use core::circuit::CircuitInput as CI; use garaga::definitions::{ get_a, get_b, get_p, get_g, get_min_one, G1Point, G2Point, E12D, u288, E12DMulQuotient, - G1G2Pair, BNProcessedPair, BLSProcessedPair, MillerLoopResultScalingFactor, G2Line + G1G2Pair, BNProcessedPair, BLSProcessedPair, MillerLoopResultScalingFactor, G2Line, + get_BLS12_381_modulus, get_BN254_modulus }; use garaga::ec_ops::{SlopeInterceptOutput, FunctionFeltEvaluations, FunctionFelt}; use core::option::Option; diff --git a/src/src/circuits/isogeny.cairo b/src/src/circuits/isogeny.cairo index 7af82c5f..8dfbd6a0 100644 --- a/src/src/circuits/isogeny.cairo +++ b/src/src/circuits/isogeny.cairo @@ -9,7 +9,8 @@ use core::circuit::CircuitElement as CE; use core::circuit::CircuitInput as CI; use garaga::definitions::{ get_a, get_b, get_p, get_g, get_min_one, G1Point, G2Point, E12D, u288, E12DMulQuotient, - G1G2Pair, BNProcessedPair, BLSProcessedPair, MillerLoopResultScalingFactor, G2Line + G1G2Pair, BNProcessedPair, BLSProcessedPair, MillerLoopResultScalingFactor, G2Line, + get_BLS12_381_modulus, get_BN254_modulus }; use garaga::ec_ops::{SlopeInterceptOutput, FunctionFeltEvaluations, FunctionFelt}; use core::option::Option; @@ -288,17 +289,7 @@ fn run_BLS12_381_APPLY_ISOGENY_BLS12_381_circuit(pt: G1Point) -> (G1Point,) { let t105 = circuit_mul(t73, t104); let t106 = circuit_mul(t105, in55); - let modulus = TryInto::< - _, CircuitModulus - >::try_into( - [ - 0xb153ffffb9feffffffffaaab, - 0x6730d2a0f6b0f6241eabfffe, - 0x434bacd764774b84f38512bf, - 0x1a0111ea397fe69a4b1ba7b6 - ] - ) - .unwrap(); // BLS12_381 prime field modulus + let modulus = get_BLS12_381_modulus(); // BLS12_381 prime field modulus let mut circuit_inputs = (t43, t106,).new_inputs(); // Prefill constants: diff --git a/src/src/utils/calldata.cairo b/src/src/utils/calldata.cairo index 3d001ee3..52393af5 100644 --- a/src/src/utils/calldata.cairo +++ b/src/src/utils/calldata.cairo @@ -24,7 +24,7 @@ struct FullProofWithHintsBLS12_381 { struct FullProofWithHintsRisc0 { groth16_proof: Groth16ProofRaw, image_id: Span, - journal_digest: Span, + journal: Span, mpcheck_hint: MPCheckHintBN254, small_Q: E12DMulQuotient, msm_hint: Array, @@ -117,11 +117,11 @@ fn deserialize_full_proof_with_hints_risc0( image_id.append((*serialized.pop_front().unwrap()).try_into().unwrap()); }; - let n_journal_digest: u32 = (*serialized.pop_front().unwrap()).try_into().unwrap(); - let mut journal_digest: Array = array![]; + let n_journal: u32 = (*serialized.pop_front().unwrap()).try_into().unwrap(); + let mut journal: Array = array![]; for _ in 0 - ..n_journal_digest { - journal_digest.append((*serialized.pop_front().unwrap()).try_into().unwrap()); + ..n_journal { + journal.append((*serialized.pop_front().unwrap()).try_into().unwrap()); }; let groth16_proof = Groth16ProofRaw { a: a, b: b, c: c }; @@ -429,7 +429,7 @@ fn deserialize_full_proof_with_hints_risc0( return FullProofWithHintsRisc0 { groth16_proof: groth16_proof, image_id: image_id.span(), - journal_digest: journal_digest.span(), + journal: journal.span(), mpcheck_hint: mpcheck_hint, small_Q: small_Q, msm_hint: msm_hint diff --git a/src/src/utils/risc0.cairo b/src/src/utils/risc0.cairo index f7acfd67..edcdff90 100644 --- a/src/src/utils/risc0.cairo +++ b/src/src/utils/risc0.cairo @@ -1,7 +1,6 @@ -use core::sha256::compute_sha256_u32_array; +use core::sha256::{compute_sha256_u32_array, compute_sha256_byte_array}; use garaga::utils::usize_assert_eq; - // sha256(b"risc0.ReceiptClaim") = // 0xcb1fefcd1f2d9a64975cbbbf6e161e2914434b0cbb9960b84df5d717e86b48af const TAG_DIGEST: [ @@ -33,6 +32,20 @@ fn uint256_byte_reverse(x: u256) -> u256 { let new_high = integer::u128_byte_reverse(x.low); return u256 { low: new_low, high: new_high }; } + +pub fn journal_sha256(journal: Span) -> Span { + let journal_arr: Array = journal.into(); + let mut journal_byte_arr = ""; + + for byte in journal_arr { + journal_byte_arr.append_byte(byte); + }; + + let journal_digest = compute_sha256_byte_array(@journal_byte_arr); + + return journal_digest.span(); +} + // https://github.com/risc0/risc0-ethereum/blob/34d2fee4ca6b5fb354a8a1a00c43f8945097bfe5/contracts/src/IRiscZeroVerifier.sol#L71-L98 pub fn compute_receipt_claim(image_id: Span, journal_digest: Span) -> u256 { usize_assert_eq(image_id.len(), 8); From 081118924d148706fb749e244ec2d2444160d7b6 Mon Sep 17 00:00:00 2001 From: feltroid Prime <96737978+feltroidprime@users.noreply.github.com> Date: Mon, 14 Oct 2024 14:06:36 +0200 Subject: [PATCH 2/4] CairoZero: Update ExtensionFieldModuloCircuit. (#227) --- .../garaga/extension_field_modulo_circuit.py | 131 ++++++------------ 1 file changed, 44 insertions(+), 87 deletions(-) diff --git a/hydra/garaga/extension_field_modulo_circuit.py b/hydra/garaga/extension_field_modulo_circuit.py index 80609da1..8cecf86a 100644 --- a/hydra/garaga/extension_field_modulo_circuit.py +++ b/hydra/garaga/extension_field_modulo_circuit.py @@ -176,6 +176,8 @@ def create_powers_of_Z( max_degree = self.extension_degree if isinstance(Z, PyFelt): Z = self.write_cairo_native_felt(Z) + elif isinstance(Z, int): + Z = self.write_cairo_native_felt(self.field(Z)) elif isinstance(Z, ModuloCircuitElement): pass else: @@ -566,100 +568,64 @@ def update_RHS_state( ) return - def get_Z_and_nondeterministic_Q( - self, extension_degree: int, mock: bool = False - ) -> tuple[PyFelt, tuple[list[PyFelt], list[PyFelt]]]: - nondeterministic_Qs = [Polynomial([self.field.zero()]) for _ in range(2)] - # Start by hashing circuit input - if self.hash_input: - self.transcript.hash_limbs_multi(self.circuit_input) - + def finalize_circuit( + self, + extension_degree: int = None, + mock=False, + ): + ######### Flags ######### + extension_degree = extension_degree or self.extension_degree double_extension = self.accumulate_poly_instructions[1].n > 0 - - # Compute Random Linear Combination coefficients acc_indexes = [0, 1] if double_extension else [0] + ######################### - for acc_index in acc_indexes: - for i, instruction_type in enumerate( - self.accumulate_poly_instructions[acc_index].types - ): - # print(f"{i=}, Hashing {instruction_type}") - match instruction_type: - case AccPolyInstructionType.MUL: - self.transcript.hash_limbs_multi( - self.accumulate_poly_instructions[acc_index].Ris[i], - self.accumulate_poly_instructions[acc_index].r_sparsities[ - i - ], - ) - case AccPolyInstructionType.SQUARE_TORUS: - self.transcript.hash_limbs_multi( - self.accumulate_poly_instructions[acc_index].Ris[i] - ) - - case AccPolyInstructionType.DIV: - self.transcript.hash_limbs_multi( - self.accumulate_poly_instructions[acc_index].Pis[i][0], - ) + ################ Get base rlc coefficient c0 ################ + if self.hash_input: + self.transcript.hash_limbs_multi(self.circuit_input) + self.transcript.hash_limbs_multi(self.commitments) - case _: - raise ValueError( - f"Unknown instruction type: {instruction_type}" - ) + c0 = self.write_cairo_native_felt(self.field(self.transcript.s1)) + ################################################################## + ################ Compute Qs ################ + Qs = [Polynomial([self.field.zero()]) for _ in range(2)] + for acc_index in acc_indexes: + self.accumulate_poly_instructions[acc_index].rlc_coeffs.append(c0) + # Computes Q = Σ(ci * Qi) + Qs[acc_index] = self.accumulate_poly_instructions[acc_index].Qis[0] * c0 + for i in range(1, self.accumulate_poly_instructions[acc_index].n): self.accumulate_poly_instructions[acc_index].rlc_coeffs.append( - self.write_cairo_native_felt(self.field(self.transcript.RLC_coeff)) + self.mul( + self.accumulate_poly_instructions[acc_index].rlc_coeffs[i - 1], + c0, + ) ) - # Computes Q = Σ(ci * Qi) - for i, coeff in enumerate( - self.accumulate_poly_instructions[acc_index].rlc_coeffs - ): - nondeterministic_Qs[acc_index] += ( - self.accumulate_poly_instructions[acc_index].Qis[i] * coeff + Qs[acc_index] += ( + self.accumulate_poly_instructions[acc_index].Qis[i] + * self.accumulate_poly_instructions[acc_index].rlc_coeffs[i] ) - - # Extend Q with zeros if needed to match the expected degree. - nondeterministic_Qs[acc_index] = nondeterministic_Qs[acc_index].get_coeffs() - nondeterministic_Qs[acc_index] = nondeterministic_Qs[acc_index] + [ - self.field.zero() - ] * ( - (acc_index + 1) * extension_degree - - 1 - - len(nondeterministic_Qs[acc_index]) + Qs[acc_index] = Qs[acc_index].get_coeffs() + # Extend Q with zeros if needed to match the minimal expected degree. + Qs[acc_index] = Qs[acc_index] + [self.field.zero()] * ( + (acc_index + 1) * extension_degree - 1 - len(Qs[acc_index]) ) - # HASH(COMMIT0, COMMIT1, Q0, Q1) - # Add Q to transcript to get Z. - if not mock: - self.transcript.hash_limbs_multi(nondeterministic_Qs[0]) - if double_extension: - self.transcript.hash_limbs_multi(nondeterministic_Qs[1]) + ################################################################## - Z = self.field(self.transcript.continuable_hash) - - return (Z, nondeterministic_Qs) - - def finalize_circuit( - self, - extension_degree: int = None, - mock=False, - ): - # print("\n Finalize Circuit") - extension_degree = extension_degree or self.extension_degree + Q = [self.write_elements(Qs[0], WriteOps.COMMIT)] - z, Qs = self.get_Z_and_nondeterministic_Q(extension_degree, mock) compute_z_up_to = max(max(len(Qs[0]), len(Qs[1])) - 1, extension_degree) - # print(f"{self.name} compute_z_up_to: {compute_z_up_to}") - - Q = [self.write_elements(Qs[0], WriteOps.COMMIT)] - double_extension = self.accumulate_poly_instructions[1].n > 0 + self.big_q_len = len(Q[0]) + self.transcript.hash_limbs_multi(Q[0]) if double_extension: Q.append(self.write_elements(Qs[1], WriteOps.COMMIT)) + self.transcript.hash_limbs_multi(Q[1]) compute_z_up_to = max(compute_z_up_to, extension_degree * 2) + self.big_q_len = self.big_q_len + len(Q[1]) - self.create_powers_of_Z(z, mock=mock, max_degree=compute_z_up_to) + z = self.transcript.continuable_hash - acc_indexes = [0, 1] if double_extension else [0] + self.create_powers_of_Z(z, mock=mock, max_degree=compute_z_up_to) for acc_index in acc_indexes: for i in range(self.accumulate_poly_instructions[acc_index].n): @@ -710,7 +676,6 @@ def finalize_circuit( else: eq_check = self.sub(rhs, lhs) self.extend_output([eq_check]) - return True def summarize(self): @@ -740,12 +705,12 @@ def compile_circuit_cairo_zero( "add_offsets_ptr", "mul_offsets_ptr", "output_offsets_ptr", - "poseidon_indexes_ptr", ], "felt": [ "constants_ptr_len", "input_len", "commitments_len", + "big_Q_len", "witnesses_len", "output_len", "continuous_output", @@ -759,7 +724,6 @@ def compile_circuit_cairo_zero( }, ) -> str: dw_arrays = self.values_segment.get_dw_lookups() - dw_arrays["poseidon_indexes_ptr"] = self.transcript.poseidon_ptr_indexes name = function_name or self.values_segment.name function_name = f"get_{name}_circuit" code = f"func {function_name}()->(circuit:{self.class_name}*)" + "{" + "\n" @@ -774,6 +738,7 @@ def compile_circuit_cairo_zero( code += f"let input_len = {len(self.values_segment.segment_stacks[WriteOps.INPUT])*N_LIMBS};\n" code += f"let commitments_len = {len(self.commitments)*N_LIMBS};\n" code += f"let witnesses_len = {len(self.values_segment.segment_stacks[WriteOps.WITNESS])*N_LIMBS};\n" + code += f"let big_Q_len = {self.big_q_len*N_LIMBS};\n" code += f"let output_len = {len(self.output)*N_LIMBS};\n" continuous_output = self.continuous_output code += f"let continuous_output = {1 if continuous_output else 0};\n" @@ -827,14 +792,6 @@ def compile_circuit_cairo_zero( for val in dw_values: code += f"\t dw {val};\n" - elif dw_array_name in [ - "poseidon_indexes_ptr", - ]: - for val in dw_values: - code += ( - f"\t dw {POSEIDON_BUILTIN_SIZE*val+POSEIDON_OUTPUT_S1_INDEX};\n" - ) - code += "\n" code += "}\n" return code From 3956fffbcfef7e6762eeb59618fa74327fadc502 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 15 Oct 2024 11:40:16 +0200 Subject: [PATCH 3/4] Bump rollup from 4.21.2 to 4.24.0 in /tools/npm/garaga_ts (#228) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- tools/npm/garaga_ts/package-lock.json | 164 ++++++++++++-------------- tools/npm/garaga_ts/package.json | 2 +- 2 files changed, 74 insertions(+), 92 deletions(-) diff --git a/tools/npm/garaga_ts/package-lock.json b/tools/npm/garaga_ts/package-lock.json index 3b3fc230..26feafb4 100644 --- a/tools/npm/garaga_ts/package-lock.json +++ b/tools/npm/garaga_ts/package-lock.json @@ -12,7 +12,7 @@ "@types/jest": "^29.5.13", "@types/node": "^22.7.4", "jest": "^29.7.0", - "rollup": "^4.21.2", + "rollup": "^4.24.0", "rollup-plugin-dts": "^6.1.1", "ts-jest": "^29.2.5", "ts-node": "^10.9.2", @@ -1291,224 +1291,208 @@ } }, "node_modules/@rollup/rollup-android-arm-eabi": { - "version": "4.21.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.21.2.tgz", - "integrity": "sha512-fSuPrt0ZO8uXeS+xP3b+yYTCBUd05MoSp2N/MFOgjhhUhMmchXlpTQrTpI8T+YAwAQuK7MafsCOxW7VrPMrJcg==", + "version": "4.24.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.24.0.tgz", + "integrity": "sha512-Q6HJd7Y6xdB48x8ZNVDOqsbh2uByBhgK8PiQgPhwkIw/HC/YX5Ghq2mQY5sRMZWHb3VsFkWooUVOZHKr7DmDIA==", "cpu": [ "arm" ], "dev": true, - "license": "MIT", "optional": true, "os": [ "android" ] }, "node_modules/@rollup/rollup-android-arm64": { - "version": "4.21.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.21.2.tgz", - "integrity": "sha512-xGU5ZQmPlsjQS6tzTTGwMsnKUtu0WVbl0hYpTPauvbRAnmIvpInhJtgjj3mcuJpEiuUw4v1s4BimkdfDWlh7gA==", + "version": "4.24.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.24.0.tgz", + "integrity": "sha512-ijLnS1qFId8xhKjT81uBHuuJp2lU4x2yxa4ctFPtG+MqEE6+C5f/+X/bStmxapgmwLwiL3ih122xv8kVARNAZA==", "cpu": [ "arm64" ], "dev": true, - "license": "MIT", "optional": true, "os": [ "android" ] }, "node_modules/@rollup/rollup-darwin-arm64": { - "version": "4.21.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.21.2.tgz", - "integrity": "sha512-99AhQ3/ZMxU7jw34Sq8brzXqWH/bMnf7ZVhvLk9QU2cOepbQSVTns6qoErJmSiAvU3InRqC2RRZ5ovh1KN0d0Q==", + "version": "4.24.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.24.0.tgz", + "integrity": "sha512-bIv+X9xeSs1XCk6DVvkO+S/z8/2AMt/2lMqdQbMrmVpgFvXlmde9mLcbQpztXm1tajC3raFDqegsH18HQPMYtA==", "cpu": [ "arm64" ], "dev": true, - "license": "MIT", "optional": true, "os": [ "darwin" ] }, "node_modules/@rollup/rollup-darwin-x64": { - "version": "4.21.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.21.2.tgz", - "integrity": "sha512-ZbRaUvw2iN/y37x6dY50D8m2BnDbBjlnMPotDi/qITMJ4sIxNY33HArjikDyakhSv0+ybdUxhWxE6kTI4oX26w==", + "version": "4.24.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.24.0.tgz", + "integrity": "sha512-X6/nOwoFN7RT2svEQWUsW/5C/fYMBe4fnLK9DQk4SX4mgVBiTA9h64kjUYPvGQ0F/9xwJ5U5UfTbl6BEjaQdBQ==", "cpu": [ "x64" ], "dev": true, - "license": "MIT", "optional": true, "os": [ "darwin" ] }, "node_modules/@rollup/rollup-linux-arm-gnueabihf": { - "version": "4.21.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.21.2.tgz", - "integrity": "sha512-ztRJJMiE8nnU1YFcdbd9BcH6bGWG1z+jP+IPW2oDUAPxPjo9dverIOyXz76m6IPA6udEL12reYeLojzW2cYL7w==", + "version": "4.24.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.24.0.tgz", + "integrity": "sha512-0KXvIJQMOImLCVCz9uvvdPgfyWo93aHHp8ui3FrtOP57svqrF/roSSR5pjqL2hcMp0ljeGlU4q9o/rQaAQ3AYA==", "cpu": [ "arm" ], "dev": true, - "license": "MIT", "optional": true, "os": [ "linux" ] }, "node_modules/@rollup/rollup-linux-arm-musleabihf": { - "version": "4.21.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-musleabihf/-/rollup-linux-arm-musleabihf-4.21.2.tgz", - "integrity": "sha512-flOcGHDZajGKYpLV0JNc0VFH361M7rnV1ee+NTeC/BQQ1/0pllYcFmxpagltANYt8FYf9+kL6RSk80Ziwyhr7w==", + "version": "4.24.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-musleabihf/-/rollup-linux-arm-musleabihf-4.24.0.tgz", + "integrity": "sha512-it2BW6kKFVh8xk/BnHfakEeoLPv8STIISekpoF+nBgWM4d55CZKc7T4Dx1pEbTnYm/xEKMgy1MNtYuoA8RFIWw==", "cpu": [ "arm" ], "dev": true, - "license": "MIT", "optional": true, "os": [ "linux" ] }, "node_modules/@rollup/rollup-linux-arm64-gnu": { - "version": "4.21.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.21.2.tgz", - "integrity": "sha512-69CF19Kp3TdMopyteO/LJbWufOzqqXzkrv4L2sP8kfMaAQ6iwky7NoXTp7bD6/irKgknDKM0P9E/1l5XxVQAhw==", + "version": "4.24.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.24.0.tgz", + "integrity": "sha512-i0xTLXjqap2eRfulFVlSnM5dEbTVque/3Pi4g2y7cxrs7+a9De42z4XxKLYJ7+OhE3IgxvfQM7vQc43bwTgPwA==", "cpu": [ "arm64" ], "dev": true, - "license": "MIT", "optional": true, "os": [ "linux" ] }, "node_modules/@rollup/rollup-linux-arm64-musl": { - "version": "4.21.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.21.2.tgz", - "integrity": "sha512-48pD/fJkTiHAZTnZwR0VzHrao70/4MlzJrq0ZsILjLW/Ab/1XlVUStYyGt7tdyIiVSlGZbnliqmult/QGA2O2w==", + "version": "4.24.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.24.0.tgz", + "integrity": "sha512-9E6MKUJhDuDh604Qco5yP/3qn3y7SLXYuiC0Rpr89aMScS2UAmK1wHP2b7KAa1nSjWJc/f/Lc0Wl1L47qjiyQw==", "cpu": [ "arm64" ], "dev": true, - "license": "MIT", "optional": true, "os": [ "linux" ] }, "node_modules/@rollup/rollup-linux-powerpc64le-gnu": { - "version": "4.21.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-powerpc64le-gnu/-/rollup-linux-powerpc64le-gnu-4.21.2.tgz", - "integrity": "sha512-cZdyuInj0ofc7mAQpKcPR2a2iu4YM4FQfuUzCVA2u4HI95lCwzjoPtdWjdpDKyHxI0UO82bLDoOaLfpZ/wviyQ==", + "version": "4.24.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-powerpc64le-gnu/-/rollup-linux-powerpc64le-gnu-4.24.0.tgz", + "integrity": "sha512-2XFFPJ2XMEiF5Zi2EBf4h73oR1V/lycirxZxHZNc93SqDN/IWhYYSYj8I9381ikUFXZrz2v7r2tOVk2NBwxrWw==", "cpu": [ "ppc64" ], "dev": true, - "license": "MIT", "optional": true, "os": [ "linux" ] }, "node_modules/@rollup/rollup-linux-riscv64-gnu": { - "version": "4.21.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.21.2.tgz", - "integrity": "sha512-RL56JMT6NwQ0lXIQmMIWr1SW28z4E4pOhRRNqwWZeXpRlykRIlEpSWdsgNWJbYBEWD84eocjSGDu/XxbYeCmwg==", + "version": "4.24.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.24.0.tgz", + "integrity": "sha512-M3Dg4hlwuntUCdzU7KjYqbbd+BLq3JMAOhCKdBE3TcMGMZbKkDdJ5ivNdehOssMCIokNHFOsv7DO4rlEOfyKpg==", "cpu": [ "riscv64" ], "dev": true, - "license": "MIT", "optional": true, "os": [ "linux" ] }, "node_modules/@rollup/rollup-linux-s390x-gnu": { - "version": "4.21.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-s390x-gnu/-/rollup-linux-s390x-gnu-4.21.2.tgz", - "integrity": "sha512-PMxkrWS9z38bCr3rWvDFVGD6sFeZJw4iQlhrup7ReGmfn7Oukrr/zweLhYX6v2/8J6Cep9IEA/SmjXjCmSbrMQ==", + "version": "4.24.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-s390x-gnu/-/rollup-linux-s390x-gnu-4.24.0.tgz", + "integrity": "sha512-mjBaoo4ocxJppTorZVKWFpy1bfFj9FeCMJqzlMQGjpNPY9JwQi7OuS1axzNIk0nMX6jSgy6ZURDZ2w0QW6D56g==", "cpu": [ "s390x" ], "dev": true, - "license": "MIT", "optional": true, "os": [ "linux" ] }, "node_modules/@rollup/rollup-linux-x64-gnu": { - "version": "4.21.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.21.2.tgz", - "integrity": "sha512-B90tYAUoLhU22olrafY3JQCFLnT3NglazdwkHyxNDYF/zAxJt5fJUB/yBoWFoIQ7SQj+KLe3iL4BhOMa9fzgpw==", + "version": "4.24.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.24.0.tgz", + "integrity": "sha512-ZXFk7M72R0YYFN5q13niV0B7G8/5dcQ9JDp8keJSfr3GoZeXEoMHP/HlvqROA3OMbMdfr19IjCeNAnPUG93b6A==", "cpu": [ "x64" ], "dev": true, - "license": "MIT", "optional": true, "os": [ "linux" ] }, "node_modules/@rollup/rollup-linux-x64-musl": { - "version": "4.21.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.21.2.tgz", - "integrity": "sha512-7twFizNXudESmC9oneLGIUmoHiiLppz/Xs5uJQ4ShvE6234K0VB1/aJYU3f/4g7PhssLGKBVCC37uRkkOi8wjg==", + "version": "4.24.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.24.0.tgz", + "integrity": "sha512-w1i+L7kAXZNdYl+vFvzSZy8Y1arS7vMgIy8wusXJzRrPyof5LAb02KGr1PD2EkRcl73kHulIID0M501lN+vobQ==", "cpu": [ "x64" ], "dev": true, - "license": "MIT", "optional": true, "os": [ "linux" ] }, "node_modules/@rollup/rollup-win32-arm64-msvc": { - "version": "4.21.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.21.2.tgz", - "integrity": "sha512-9rRero0E7qTeYf6+rFh3AErTNU1VCQg2mn7CQcI44vNUWM9Ze7MSRS/9RFuSsox+vstRt97+x3sOhEey024FRQ==", + "version": "4.24.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.24.0.tgz", + "integrity": "sha512-VXBrnPWgBpVDCVY6XF3LEW0pOU51KbaHhccHw6AS6vBWIC60eqsH19DAeeObl+g8nKAz04QFdl/Cefta0xQtUQ==", "cpu": [ "arm64" ], "dev": true, - "license": "MIT", "optional": true, "os": [ "win32" ] }, "node_modules/@rollup/rollup-win32-ia32-msvc": { - "version": "4.21.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.21.2.tgz", - "integrity": "sha512-5rA4vjlqgrpbFVVHX3qkrCo/fZTj1q0Xxpg+Z7yIo3J2AilW7t2+n6Q8Jrx+4MrYpAnjttTYF8rr7bP46BPzRw==", + "version": "4.24.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.24.0.tgz", + "integrity": "sha512-xrNcGDU0OxVcPTH/8n/ShH4UevZxKIO6HJFK0e15XItZP2UcaiLFd5kiX7hJnqCbSztUF8Qot+JWBC/QXRPYWQ==", "cpu": [ "ia32" ], "dev": true, - "license": "MIT", "optional": true, "os": [ "win32" ] }, "node_modules/@rollup/rollup-win32-x64-msvc": { - "version": "4.21.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.21.2.tgz", - "integrity": "sha512-6UUxd0+SKomjdzuAcp+HAmxw1FlGBnl1v2yEPSabtx4lBfdXHDVsW7+lQkgz9cNFJGY3AWR7+V8P5BqkD9L9nA==", + "version": "4.24.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.24.0.tgz", + "integrity": "sha512-fbMkAF7fufku0N2dE5TBXcNlg0pt0cJue4xBRE2Qc5Vqikxr4VCgKj/ht6SMdFcOacVA9rqF70APJ8RN/4vMJw==", "cpu": [ "x64" ], "dev": true, - "license": "MIT", "optional": true, "os": [ "win32" @@ -1604,11 +1588,10 @@ } }, "node_modules/@types/estree": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.5.tgz", - "integrity": "sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==", - "dev": true, - "license": "MIT" + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.6.tgz", + "integrity": "sha512-AYnb1nQyY49te+VRAVgmzfcgjYS91mY5P0TKUDCLEM+gNnA+3T6rWITXRLYCpahpqSQbN5cE+gHpnPyXjHWxcw==", + "dev": true }, "node_modules/@types/graceful-fs": { "version": "4.1.9", @@ -5094,13 +5077,12 @@ } }, "node_modules/rollup": { - "version": "4.21.2", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.21.2.tgz", - "integrity": "sha512-e3TapAgYf9xjdLvKQCkQTnbTKd4a6jwlpQSJJFokHGaX2IVjoEqkIIhiQfqsi0cdwlOD+tQGuOd5AJkc5RngBw==", + "version": "4.24.0", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.24.0.tgz", + "integrity": "sha512-DOmrlGSXNk1DM0ljiQA+i+o0rSLhtii1je5wgk60j49d1jHT5YYttBv1iWOnYSTG+fZZESUOSNiAl89SIet+Cg==", "dev": true, - "license": "MIT", "dependencies": { - "@types/estree": "1.0.5" + "@types/estree": "1.0.6" }, "bin": { "rollup": "dist/bin/rollup" @@ -5110,22 +5092,22 @@ "npm": ">=8.0.0" }, "optionalDependencies": { - "@rollup/rollup-android-arm-eabi": "4.21.2", - "@rollup/rollup-android-arm64": "4.21.2", - "@rollup/rollup-darwin-arm64": "4.21.2", - "@rollup/rollup-darwin-x64": "4.21.2", - "@rollup/rollup-linux-arm-gnueabihf": "4.21.2", - "@rollup/rollup-linux-arm-musleabihf": "4.21.2", - "@rollup/rollup-linux-arm64-gnu": "4.21.2", - "@rollup/rollup-linux-arm64-musl": "4.21.2", - "@rollup/rollup-linux-powerpc64le-gnu": "4.21.2", - "@rollup/rollup-linux-riscv64-gnu": "4.21.2", - "@rollup/rollup-linux-s390x-gnu": "4.21.2", - "@rollup/rollup-linux-x64-gnu": "4.21.2", - "@rollup/rollup-linux-x64-musl": "4.21.2", - "@rollup/rollup-win32-arm64-msvc": "4.21.2", - "@rollup/rollup-win32-ia32-msvc": "4.21.2", - "@rollup/rollup-win32-x64-msvc": "4.21.2", + "@rollup/rollup-android-arm-eabi": "4.24.0", + "@rollup/rollup-android-arm64": "4.24.0", + "@rollup/rollup-darwin-arm64": "4.24.0", + "@rollup/rollup-darwin-x64": "4.24.0", + "@rollup/rollup-linux-arm-gnueabihf": "4.24.0", + "@rollup/rollup-linux-arm-musleabihf": "4.24.0", + "@rollup/rollup-linux-arm64-gnu": "4.24.0", + "@rollup/rollup-linux-arm64-musl": "4.24.0", + "@rollup/rollup-linux-powerpc64le-gnu": "4.24.0", + "@rollup/rollup-linux-riscv64-gnu": "4.24.0", + "@rollup/rollup-linux-s390x-gnu": "4.24.0", + "@rollup/rollup-linux-x64-gnu": "4.24.0", + "@rollup/rollup-linux-x64-musl": "4.24.0", + "@rollup/rollup-win32-arm64-msvc": "4.24.0", + "@rollup/rollup-win32-ia32-msvc": "4.24.0", + "@rollup/rollup-win32-x64-msvc": "4.24.0", "fsevents": "~2.3.2" } }, diff --git a/tools/npm/garaga_ts/package.json b/tools/npm/garaga_ts/package.json index 54a7045d..139e53d8 100644 --- a/tools/npm/garaga_ts/package.json +++ b/tools/npm/garaga_ts/package.json @@ -23,7 +23,7 @@ "@types/jest": "^29.5.13", "@types/node": "^22.7.4", "jest": "^29.7.0", - "rollup": "^4.21.2", + "rollup": "^4.24.0", "rollup-plugin-dts": "^6.1.1", "ts-jest": "^29.2.5", "ts-node": "^10.9.2", From 584cad66d067aa6c04447fe06a00c7be99bc2445 Mon Sep 17 00:00:00 2001 From: Rodrigo Ferreira Date: Wed, 16 Oct 2024 01:24:13 -0300 Subject: [PATCH 4/4] NPM package documentation (#213) --- docs/gitbook/installation/npm-package.md | 123 ++++++++++++++++++++++- 1 file changed, 122 insertions(+), 1 deletion(-) diff --git a/docs/gitbook/installation/npm-package.md b/docs/gitbook/installation/npm-package.md index 7ae32e34..e823d343 100644 --- a/docs/gitbook/installation/npm-package.md +++ b/docs/gitbook/installation/npm-package.md @@ -1,3 +1,124 @@ # Npm package -soon +## Installation via NPM Registry (recommended) + +The easiest way to install Garaga is via your prefered Node.js package manager, such as `npm` or `yarn`. + +1. Open your terminal or command prompt. +2. Run the following command: + + ```bash + npm i -S garaga + ``` + + or + + ```bash + yarn add garaga + ``` + +## Building the package from source code + +The package can be build directly from source code by cloning the garaga repository. Make sure you have both [Rust](https://www.rust-lang.org/tools/install) and [Node.js](https://nodejs.org/en/learn/getting-started/how-to-install-nodejs) installed in you machine. + +1. Open your terminal or command prompt. +2. Install `wasm-pack` by running: + + ```bash + cargo install wasm-pack + ``` + +3. Run the following commands: + + ```bash + git clone https://github.com/keep-starknet-strange/garaga.git + cd tools/npm/garaga_ts + npm ci + npm run build + npm pack + ``` + +4. The .tgz file with the package contents will be available in the current folder. +5. Install the .tgz file in your project + + ```bash + npm i -S + ``` + +For reproducible builds, one can use instead docker compose. Make sure [docker](https://docs.docker.com/engine/install/) is installed in you machine. + +1. Open your terminal or command prompt. +2. Run the following commands: + + ```bash + git clone https://github.com/keep-starknet-strange/garaga.git + cd tools/npm/garaga_ts + docker compose up --build + ``` + +3. The .tgz file with the package contents will be available in the current folder. +4. Install the .tgz file in your project + + ```bash + npm i -S + ``` + +## Development notes + +The Garaga NPM package is a mixed package. It is implemented in TypeScript but also reuses Rust code targeted to WebAssembly (WASM) with the help of [`wasm-pack`](https://rustwasm.github.io/wasm-pack/). + +The `src` folder is organized into two subfolders: `node` which contains the implementation in TypeScript; and `wasm` which has the interoperabilty code produced by `wasm-pack`. + +Changes to the TypeScript library should only be made to files under the `node` subfolder. Changes to the Rust implementation requires regenerating files under the `wasm` subfolder. + +Onces changes are in place they can be made permanent into the repository by committing the contents of both folders. Here is the bulk of the process: + +1. Open your terminal or command prompt. +2. Use `git` to clone the repository: + + ```bash + git clone https://github.com/keep-starknet-strange/garaga.git + cd tools/npm/garaga_ts + npm ci + ``` + +3. If you make TypeScript only changes, you can quickly rebuild the package using the `build:node` NPM script: + + ```bash + npm run build:node + npm pack + ``` + +4. If instead you make Rust changes, it is necessary to generate the WASM interoperability code using the `build` NPM script: + + ```bash + npm run build + npm pack + ``` + +5. However, before commiting changes, it is necessary to generate the WASM interoperability code in a reproducible manner using docker: + + ```bash + docker compose up --build + git commit . + ``` +### How `wasm-pack` is used to achieve interoperability + +Internaly the `build` NPM script uses `wasm-pack` to produce the WASM interoperability code. This is achieved by running + + ```bash + cd tools/garaga_rs && wasm-pack build --target web --out-dir ../npm/garaga_ts/src/wasm/pkg --release --no-default-features + cd tools/npm/garaga_ts && node patch.wasm.cjs + ``` +Let's unpack it. + +In the Rust source folder we run `wasm-pack` in `--target web` mode. This generates TypeScript code targeting web pages. +The `--release` option is required to minimize the size of the WASM module. +And the `--no-default-features` disables the need to build non WASM features of garaga_rs. + +Once the `wasm-pack` is done, the code is generated under the folder `src/wasm/pkg` of garaga_ts that houses the TypeScript source code. + +We then run a custom script `patch.wasm.cjs` which makes minimal changes to the code generated by wasm-pack to facilitate seamless support of the WASM module in both the browser and Node.js. +Basically it converts the WASM module to a [Base64](https://en.wikipedia.org/wiki/Base64) string that can be loaded in a portable way in both environments, amongst other minor tweaks. + +(It is important to note that the use of a custom script is only required so long `wasm-pack` itself does not provide a more portable/universal target mode.)