feat(core): optional beforeSign hook on BaseWallet (refuse-before-sign) - #599
Open
twzrd-sol wants to merge 2 commits into
Open
feat(core): optional beforeSign hook on BaseWallet (refuse-before-sign)#599twzrd-sol wants to merge 2 commits into
twzrd-sol wants to merge 2 commits into
Conversation
Add a dependency-free pre-sign policy seat on the only complete force point: wrap BaseWallet at SolanaAgentKit construction so every sign / signAndSend / signAll / send path can refuse before signature. Default unset = zero behavior change. signMessage is not guarded. Plugins that call agent.wallet directly cannot bypass the hook. Config.beforeSign + exported wrapWallet + unit tests (9).
Author
|
@thearyanag, could you review this v2 core API change? Cold validation is green: 9 focused tests, repo-wide Biome, TypeScript, and the full monorepo build; the hook is opt-in and adds no dependency or default behavior. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
SAK actions spend through
BaseWallet(signTransaction/signAndSendTransaction/signAllTransactions, plus optionalsendTransaction). Once an agent can sign, the expensive failure mode is sending to a bad counterparty.Today there is no first-class place for a host to refuse before sign without forking N plugins. Hooking only
signOrSendTXis incomplete: many plugins callagent.wallet.signAndSendTransactiondirectly.Proposal (minimal, zero default behavior change)
config.beforeSign?: (ctx) => void | Promise<void>.SolanaAgentKitwraps the providedBaseWalletat construction so every sign/send path invokes the hook first; throw/reject aborts sign.agent.wallet ===the original wallet).signMessageis intentionally not guarded (not a spend path).Also exported:
wrapWallet(wallet, beforeSign)for hosts that want to wrap without going through the constructor.Why wallet wrap (not only
signOrSendTX)This is the only complete refuse-before-sign seat: plugins that call the wallet directly cannot bypass the policy.
What this is not
Tests
9 unit tests in
packages/core/src/utils/wrapWallet.test.ts:Covers: hook invocation, throw/async reject aborts, signAll, send path, VersionedTransaction, constructor wiring, identity when unset.
Files
packages/core/src/utils/wrapWallet.ts(new)packages/core/src/utils/wrapWallet.test.ts(new)packages/core/src/types/index.ts—Config.beforeSignpackages/core/src/agent/index.ts— constructor wrappackages/core/src/index.ts— exportHappy to adjust the type shape or naming if maintainers prefer a different surface.