feat: update to freenet-stdlib 0.1.32 with new DelegateCtx API#79
feat: update to freenet-stdlib 0.1.32 with new DelegateCtx API#79
Conversation
Update chat-delegate to use the new DelegateInterface::process signature that includes a DelegateCtx parameter for mutable context access. Changes: - Bump freenet-stdlib from 0.1.30 to 0.1.32 - Update process() signature to include ctx: &mut DelegateCtx - Update all test calls to pass &mut DelegateCtx::default() The delegate still uses the legacy message-based pattern for secret management (GetSecretRequest/SetSecretRequest), which remains supported. The new DelegateCtx provides optional host function API for context and secrets that can be adopted incrementally. Related: freenet/freenet-core#2844
Replace the message-passing pattern (GetSecretRequest/GetSecretResponse) with direct host function calls via DelegateCtx. This eliminates round-trips and simplifies the delegate significantly: - Use ctx.get_secret(), ctx.set_secret(), ctx.remove_secret() directly - Remove pending operation state tracking (no longer needed) - Remove PendingOperation, ChatDelegateContext complexity - Simplify all handlers to return responses immediately The new API from freenet-stdlib 0.1.32 provides synchronous secret access within the process() call, making the old async pattern unnecessary. [AI-assisted - Claude]
Review SummaryThis PR correctly implements the migration from async message-passing to synchronous Bugs Found1. In ctx.set_secret(&secret_key, &value); // Returns bool, ignoredThe client receives a success response even if the operation actually failed. This should check the return value and propagate failures. 2. Non-atomic index updates Store operations do:
If step 1 succeeds but step 4 fails, the secret is orphaned (stored but not in index, so Test Coverage GapsSigning key operations have zero test coverage:
These are critical for River's message authentication. Recommend adding:
Tests run as no-ops in non-WASM:
Documentation Items
Housekeeping
Questions
[AI-assisted - Claude] |
- Check return value of ctx.set_secret() in WASM builds to propagate failures instead of silently succeeding when storage fails - In non-WASM test builds, skip the check since DelegateCtx always returns false - Add tests for signing key operations: - test_store_signing_key: Verify StoreSigningKeyResponse - test_get_public_key_not_found: Verify GetPublicKeyResponse when no key - test_sign_message_without_key_returns_error: Verify error path for signing Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Summary
Update to freenet-stdlib 0.1.32 which adds the
DelegateCtxparameter toDelegateInterface::process(). This PR fully adopts the new host function API for direct secret access.Changes
API Update:
DelegateInterface::process()signature to accept&mut DelegateCtx#[delegate]macroMajor Refactoring:
DelegateCtxctx.get_secret(),ctx.set_secret(),ctx.remove_secret()directly within handlersPendingOperation,SecretIdKey, and complexChatDelegateContextstructuresCode Reduction:
Why This Approach
The new freenet-stdlib 0.1.32 API provides synchronous secret access within the
process()call. This eliminates the need for:Each handler can now directly read/write secrets and return a response in a single call.
Testing
[AI-assisted - Claude]