Conversation
…e language SDKs and remove the obsolete js_sdk.js file.
…_core_sdk.js to streamline the SDK.
- Implemented "Get balance" feature to retrieve wallet balance using an API key and specified chain. - Added "Send" feature to transfer funds to a destination address, requiring API key, PKP public key, chain, destination address, and amount. - Integrated event listeners for both functionalities to handle user interactions and display results or errors accordingly.
- Improved user interface for "Get balance" and "Send" features, ensuring better user experience. - Added validation for input fields to prevent errors during fund transfers. - Updated event listeners to provide clearer feedback on transaction status.
- Updated API methods to include get_api_key_balance and get_pkp_balance for improved balance retrieval. - Enhanced user interface with accordion sections for better organization of transfer functionalities. - Updated input labels and button texts for clarity in user interactions.
- Added new API methods for retrieving user balances and improved error handling during fund transfers. - Refined user interface elements for better clarity and organization of transfer functionalities. - Implemented additional validation for input fields to enhance user experience.
- Improved API methods for balance retrieval and fund transfers, enhancing error handling. - Updated user interface for better organization and clarity of transfer functionalities. - Added further validation for input fields to improve user experience.
- Deleted core SDK, transfer SDK, and PKP sign documentation files to streamline the project. - Removed associated markdown files that were no longer relevant to the current API structure.
- Added logout functionality and updated button visibility in app.js for improved user experience. - Modified balance retrieval logic to ensure correct token symbols are displayed. - Introduced new API endpoint for retrieving address balances and updated existing chain retrieval method to use query parameters for better browser compatibility. - Enhanced UI layout in index.html to include a logout button and improved styling in styles.css for better organization. - Updated RPC URL for the Avalanche testnet in chain_info.rs for accuracy.
- Updated API methods for improved balance retrieval and fund transfers, ensuring better error handling. - Enhanced user interface elements for clarity and organization of functionalities. - Added validation for input fields to improve user experience and prevent errors during transactions.
There was a problem hiding this comment.
Pull request overview
This PR restructures several shared Lit Node types and test helpers to support an SDK wrapper, primarily by moving common test utilities into lit-node-testnet and relocating shared models into lit-node-core.
Changes:
- Move test helper modules (
auth_sig,pkp,session_sigs,lit_actions) fromlit-nodetests intolit-node-testnet::commonand update test imports accordingly. - Move
PayedEndpointandSessionKeySignedMessageV2tolit-node-coreand updatelit-nodemodules to import them from there.
Reviewed changes
Copilot reviewed 42 out of 43 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| rust/lit-node/lit-node/tests/integration/signing.rs | Update PKP helper imports to lit-node-testnet |
| rust/lit-node/lit-node/tests/integration/shadow.rs | Update auth/pkp helper imports to lit-node-testnet |
| rust/lit-node/lit-node/tests/integration/session_sigs.rs | Switch helpers to lit-node-testnet; add local init_test |
| rust/lit-node/lit-node/tests/integration/lit_actions.rs | Switch helper imports to lit-node-testnet |
| rust/lit-node/lit-node/tests/integration/epoch_change_long.rs | Change RNG usage to lit-node-testnet::rand::shared_rng() |
| rust/lit-node/lit-node/tests/integration/backup_datil_long.rs | Update auth/pkp helper imports to lit-node-testnet |
| rust/lit-node/lit-node/tests/common/web_user_tests.rs | Swap helper imports to lit-node-testnet::common |
| rust/lit-node/lit-node/tests/common/mod.rs | Remove exported helper modules moved to lit-node-testnet |
| rust/lit-node/lit-node/tests/common/ecdsa.rs | Switch PKP helper imports to lit-node-testnet |
| rust/lit-node/lit-node/tests/acceptance/payment.rs | Use lit_node_core::PayedEndpoint + lit_core::bytes_to_hex |
| rust/lit-node/lit-node/src/utils/web.rs | Import SessionKeySignedMessageV2 from lit-node-core |
| rust/lit-node/lit-node/src/tasks/payment.rs | Import PayedEndpoint from lit-node-core |
| rust/lit-node/lit-node/src/payment/selection.rs | Import PayedEndpoint + session key model from lit-node-core |
| rust/lit-node/lit-node/src/payment/payment_tracker.rs | Import PayedEndpoint from lit-node-core |
| rust/lit-node/lit-node/src/payment/payment_delegation.rs | Import PayedEndpoint + session key model from lit-node-core |
| rust/lit-node/lit-node/src/payment/mod.rs | Remove payed_endpoint module export (moved to core) |
| rust/lit-node/lit-node/src/models/mod.rs | Remove models::auth module export (moved to core) |
| rust/lit-node/lit-node/src/endpoints/web_client.rs | Import PayedEndpoint + session key model from lit-node-core |
| rust/lit-node/lit-node/src/endpoints/versions/v2.rs | Import PayedEndpoint from lit-node-core |
| rust/lit-node/lit-node/src/endpoints/pkp.rs | Import PayedEndpoint + session key model from lit-node-core |
| rust/lit-node/lit-node/src/config/chain.rs | Import PayedEndpoint from lit-node-core |
| rust/lit-node/lit-node/src/auth/session_sigs.rs | Import SessionKeySignedMessageV2 from lit-node-core (incl tests) |
| rust/lit-node/lit-node/src/auth/auth_material.rs | Update tests to import session key model from lit-node-core |
| rust/lit-node/lit-node/live_testnet_b.toml | Remove unused live testnet sample config |
| rust/lit-node/lit-node/Cargo.toml | Use workspace deps for siwe, siwe-recap, tracing |
| rust/lit-node/lit-node-testnet/src/validator.rs | Switch random selection to shared RNG helper |
| rust/lit-node/lit-node-testnet/src/testnet/datil/mod.rs | Avoid panic if cached node accounts file missing |
| rust/lit-node/lit-node-testnet/src/rand.rs | Add shared_rng() helper and rename thread RNG getter |
| rust/lit-node/lit-node-testnet/src/node_collection.rs | Make handshake_nodes public; change socket address formatting |
| rust/lit-node/lit-node-testnet/src/lib.rs | Export new common module |
| rust/lit-node/lit-node-testnet/src/end_user/pkp/mainnet.rs | Minor formatting-only change |
| rust/lit-node/lit-node-testnet/src/end_user/mod.rs | Add from_secret_key, PKP pubkey lookup, logging tweaks |
| rust/lit-node/lit-node-testnet/src/common/session_sigs.rs | Remove init_test; adjust imports |
| rust/lit-node/lit-node-testnet/src/common/pkp.rs | Fix imports; add tracing usage |
| rust/lit-node/lit-node-testnet/src/common/mod.rs | New shared test helper module root |
| rust/lit-node/lit-node-testnet/src/common/lit_actions.rs | Move lit-actions helpers into lit-node-testnet::common |
| rust/lit-node/lit-node-testnet/src/common/auth_sig.rs | Use lit_node_core models + lit_core encoding utils |
| rust/lit-node/lit-node-testnet/Cargo.toml | Add dependencies needed by new common helpers |
| rust/lit-node/lit-node-core/src/models/session_key.rs | Fix intra-crate import; remove debug logging |
| rust/lit-node/lit-node-core/src/models/payed_endpoint.rs | Simplify parse error type to core Error::Parse |
| rust/lit-node/lit-node-core/src/models.rs | Export payed_endpoint + session_key from core models |
| rust/lit-node/Cargo.toml | Add workspace member + workspace deps for siwe, tracing, etc. |
| rust/lit-node/Cargo.lock | Lockfile updates incl. new lit-node-simple-api package |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| pub fn shared_rng() -> Arc<Mutex<ThreadRng>> { | ||
| let shared_rng = Arc::new(Mutex::new(get_thread_rng())); | ||
| shared_rng | ||
| } | ||
|
|
There was a problem hiding this comment.
shared_rng() returns Arc<Mutex<ThreadRng>>, but ThreadRng contains Rc<UnsafeCell<...>> and is not Send, so it cannot be put behind std::sync::Mutex (this should fail to compile). Also, shared_rng() creates a brand new Arc<Mutex<_>> on every call, so callers don't actually share the same RNG instance. Consider using a global OnceLock<Mutex<StdRng>> (or similar) for a truly shared RNG, or keep RNG thread-local and avoid wrapping it in Arc<Mutex<...>>.
| pub fn shared_rng() -> Arc<Mutex<ThreadRng>> { | |
| let shared_rng = Arc::new(Mutex::new(get_thread_rng())); | |
| shared_rng | |
| } | |
| pub fn shared_rng() -> ThreadRng { | |
| get_thread_rng() | |
| } |
There was a problem hiding this comment.
This is intentional to allow it to work inside a multi-threaded environment - the API server.
| let ip = Ipv4Addr::from_bits(validator.ip); | ||
| let scheme = if ip == Ipv4Addr::LOCALHOST { | ||
| "http" | ||
| } else { | ||
| "https" | ||
| }; | ||
| let socket_address = format!("{}://{}:{}", scheme, ip, validator.port); | ||
| NodeSet { | ||
| socket_address: socket_address, | ||
| value: 1, | ||
| } |
There was a problem hiding this comment.
NodeSet.socket_address is being constructed with a scheme prefix (e.g. http://1.2.3.4:7470). The Rust SDK request builder later formats URLs as {url_prefix}://{socket_address}/{api_path}, so including the scheme here will produce invalid URLs like http://http://.... Keep socket_address as host:port only and let UrlPrefix control the scheme.
There was a problem hiding this comment.
I'm not sure that this is true - otherwise all the tests would fail 🤷
| pub fn from_secret_key(testnet: &Testnet, secret_key: &[u8]) -> Self { | ||
|
|
||
| let wallet = LocalWallet::from_bytes(secret_key).unwrap().with_chain_id(testnet.chain_id); | ||
| info!("Wallet address from secret key: {:?}", wallet.address()); |
There was a problem hiding this comment.
from_secret_key uses LocalWallet::from_bytes(secret_key).unwrap(), which will panic on invalid input and makes the API harder to use safely (especially if this is intended for an SDK wrapper). Consider returning a Result<Self, _> (or anyhow::Result<Self>) and propagating the error instead of unwrapping.
There was a problem hiding this comment.
TBD if we do this, or let it failed. Currently it's all test code, and it's wrapped inside a rocket server for external use. The endpoint will certainly panic, but that doesn't bring things down. ( Definitely not graceful, though ).
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
WHAT
A few changes to enable the SDK wrapper!
These changes aren't functional, and most simply involve moving models out of the
lit-nodeproject and intolit-node-coreproject, so that they are properly useable by external parties. This is the continuation of a process set up original by Mike when he started writing the rust SDK.The net result is that we have a lot of namespace changes.
There are also a couple of extra helper functions in the SDK that get consumed by the wrapper project.
FROM COPILOT