@@ -74,11 +74,57 @@ fn parse_bp_key(key: JsValue) -> Option<AccountSecretKey> {
7474 )
7575}
7676
77+ /// Starts a Mina node in a WASM environment and returns an RPC interface.
78+ ///
79+ /// This is the main entry point for running a Mina node from JavaScript/WASM.
80+ /// It spawns the node in a separate thread, sets up all necessary components,
81+ /// and returns an RPC sender that can be used to communicate with the running
82+ /// node.
83+ ///
84+ /// # Arguments
85+ ///
86+ /// * `block_producer` - Block producer configuration as a JavaScript value.
87+ /// Can be one of:
88+ /// - `null`/`undefined`: No block production
89+ /// - `string`: Plain text secret key
90+ /// - `[encrypted_key, password]`: Array with encrypted key and password
91+ /// * `seed_nodes_urls` - Optional list of URLs to fetch peer lists from.
92+ /// Each URL should return newline-separated peer addresses. This is similar
93+ /// to the `--peer-list-url` flag in the native node, but allows multiple URLs
94+ /// to be supplied.
95+ /// * `seed_nodes_addresses` - Optional list of peer addresses to connect to
96+ /// directly, in [WebRTC Multiaddr-ish format](https://o1-labs.github.io/mina-rust/docs/developers/webrtc#address-format-differences)
97+ /// This is directly comparable to the `--peers` flag in the native node.
98+ /// * `genesis_config_url` - Optional URL to fetch genesis configuration from.
99+ /// Genesis config must be in bin_prot format. If not provided, uses the default
100+ /// devnet configuration.
101+ ///
102+ /// # Returns
103+ ///
104+ /// An `RpcSender` that can be used to send RPC commands to the running node.
105+ ///
106+ /// # Panics
107+ ///
108+ /// Panics if:
109+ /// - Block producer key parsing fails
110+ /// - Node setup or build fails
111+ /// - Genesis configuration cannot be fetched
112+ ///
113+ /// # Example
114+ ///
115+ /// ```javascript
116+ /// const rpc = await run(
117+ /// null, // No block production
118+ /// ["https://bootnodes.minaprotocol.com/networks/devnet-webrtc.txt"],
119+ /// ["/PEER_ID/https/webrtc-peer-signaling.example.com/443"],
120+ /// null, // Use the default devnet configuration
121+ /// );
122+ /// ```
77123#[ wasm_bindgen]
78124pub async fn run (
79125 block_producer : JsValue ,
80126 seed_nodes_urls : Option < Vec < String > > ,
81- seed_nodes_fixed : Option < Vec < String > > ,
127+ seed_nodes_addresses : Option < Vec < String > > ,
82128 genesis_config_url : Option < String > ,
83129) -> RpcSender {
84130 let block_producer = parse_bp_key ( block_producer) ;
@@ -89,7 +135,7 @@ pub async fn run(
89135 let mut node = setup_node (
90136 block_producer,
91137 seed_nodes_urls,
92- seed_nodes_fixed ,
138+ seed_nodes_addresses ,
93139 genesis_config_url,
94140 )
95141 . await ;
@@ -106,7 +152,7 @@ pub async fn run(
106152async fn setup_node (
107153 block_producer : Option < AccountSecretKey > ,
108154 seed_nodes_urls : Option < Vec < String > > ,
109- seed_nodes_fixed : Option < Vec < String > > ,
155+ seed_nodes_addresses : Option < Vec < String > > ,
110156 genesis_config_url : Option < String > ,
111157) -> mina_node_common:: Node < NodeService > {
112158 let block_verifier_index = BlockVerifier :: make ( ) . await ;
@@ -127,7 +173,8 @@ async fn setup_node(
127173 . work_verifier_index ( work_verifier_index. clone ( ) ) ;
128174
129175 // TODO(binier): refactor
130- let mut all_raw_peers = seed_nodes_fixed. unwrap_or_default ( ) ;
176+ let mut all_raw_peers = seed_nodes_addresses. unwrap_or_default ( ) ;
177+
131178 if let Some ( seed_nodes_urls) = seed_nodes_urls {
132179 for seed_nodes_url in seed_nodes_urls {
133180 let peers = :: node:: core:: http:: get_bytes ( & seed_nodes_url) . await ;
0 commit comments