Repository navigation
refactor: key wallet clippy warnings #123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
ef52ce3
6f3a964
05ac46b
1a4fb90
6870686
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -423,7 +423,7 @@ typedef struct { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FFI wrapper for ManagedWalletInfo that includes transaction checking capabilities | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| typedef struct { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ManagedWalletInfo *inner; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FFIManagedWalletInfo *inner; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } FFIManagedWallet; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -3789,16 +3789,30 @@ void wallet_manager_free_addresses(char **addresses, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Encrypt a private key with BIP38 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Safety | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| This function is unsafe because it dereferences raw pointers: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `private_key` must be a valid, null-terminated C string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `passphrase` must be a valid, null-terminated C string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `error` must be a valid pointer to an FFIError or null | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| char *bip38_encrypt_private_key(const char *private_key, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const char *passphrase, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FFINetwork network, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FFINetwork _network, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FFIError *error) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+3792
to
3805
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BIP38 encrypt docs: document allocation/free and current unimplemented behavior The header doesn’t say how to free the returned string and that this currently always returns NULL with WALLET_ERROR (feature disabled or not implemented). Please document both; also note Apply this header doc tweak (mirror in Rust doc comments so cbindgen regenerates it): -/*
- Encrypt a private key with BIP38
-
- # Safety
-
- This function is unsafe because it dereferences raw pointers:
- - `private_key` must be a valid, null-terminated C string
- - `passphrase` must be a valid, null-terminated C string
- - `error` must be a valid pointer to an FFIError or null
- */
+/*
+ Encrypt a private key with BIP38
+
+ Returns: newly allocated C string on success; NULL on error.
+ - Free the returned string with `string_free`.
+ - Currently unimplemented: returns NULL and sets error->code = WALLET_ERROR (or when the `bip38` feature is disabled).
+ - Note: `_network` is reserved/ignored at present.
+
+ # Safety
+ This function is unsafe because it dereferences raw pointers:
+ - `private_key` must be a valid, null-terminated C string
+ - `passphrase` must be a valid, null-terminated C string
+ - `error` must be a valid pointer to an FFIError or null
+ */📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Decrypt a BIP38 encrypted private key | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Safety | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| This function is unsafe because it dereferences raw pointers: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `encrypted_key` must be a valid, null-terminated C string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `passphrase` must be a valid, null-terminated C string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `error` must be a valid pointer to an FFIError or null | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
3808
to
3816
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FFI contract: document allocation/ownership for BIP38 decrypt State who frees the returned string and typical error path. -/*
- Decrypt a BIP38 encrypted private key
-
- # Safety
+/*
+ Decrypt a BIP38 encrypted private key
+
+ Returns: newly allocated C string (WIF) on success; NULL on error.
+ - Free the returned string with `string_free`.
+
+ # Safety
This function is unsafe because it dereferences raw pointers:
- `encrypted_key` must be a valid, null-terminated C string
- `passphrase` must be a valid, null-terminated C string
- `error` must be a valid pointer to an FFIError or null
*/📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| char *bip38_decrypt_private_key(const char *encrypted_key, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Make FFIManagedWallet opaque; avoid exposing inner pointer and ABI fragility
Publicly exposing the
innerfield invites consumers to dereference internals and makes future refactors risky. Prefer an opaque handle and keep mutations behind API calls. Also, several APIs still acceptFFIManagedWalletInfo*directly (e.g., Lines 2728–2754, 2749–2754), which defeats the wrapper; consider unifying on one handle type.Proposed header-side shape (implement by adjusting Rust types/cbindgen config, not by hand-editing this generated file):
Verification script to find mixed usage of
FFIManagedWalletandFFIManagedWalletInfoin FFI entry points:🏁 Script executed:
Length of output: 4718
Make FFIManagedWallet opaque and consolidate on one handle
FFIManagedWallet is currently a concrete struct exposing an
innerpointer (key-wallet-ffi/include/key_wallet_ffi.h:425–429), which couples consumers to Rust’s layout and risks ABI breakage. Switch to an opaque forward declaration and update all APIs—e.g., managed_wallet_get_next_bip44_receive_address (line 2728) and managed_wallet_get_next_bip44_change_address (line 2749)—to takeFFIManagedWallet*instead ofFFIManagedWalletInfo*.📝 Committable suggestion
🤖 Prompt for AI Agents