feat: accept optional walletProvider to unblock third-party OPNet wallets#128
Open
bitbragi wants to merge 1 commit into
Open
feat: accept optional walletProvider to unblock third-party OPNet wallets#128bitbragi wants to merge 1 commit into
bitbragi wants to merge 1 commit into
Conversation
…lets Closes btc-vision#127. Currently, TransactionFactory and MessageSigner auto-detect window.opnet.web3 as the sole browser signing provider. This blocks any third-party OPNet-compatible wallet (injected at other window globals such as window.myscribe) from being used through the documented `signer: null` browser flow — even when the caller has explicitly connected a different wallet via @btc-vision/walletconnect. This commit adds an optional `walletProvider?: Web3Provider` parameter to the public signing entry points: TransactionFactory: - createCancellableTransaction(params, walletProvider?) - signInteraction(params, walletProvider?) - signDeployment(params, walletProvider?) - createBTCTransfer(params, walletProvider?) MessageSigner: - signMessageAuto(message, keypair?, walletProvider?) - tweakAndSignMessageAuto(message, keypair?, network?, walletProvider?) - signMLDSAMessageAuto(message, mldsaKeypair?, walletProvider?) - trySignSchnorrWithOPWallet(message, walletProvider?) - trySignMLDSAWithOPWallet(message, walletProvider?) - verifyMLDSAWithOPWallet(message, signature, walletProvider?) - getMLDSAPublicKeyFromOPWallet(walletProvider?) Behavior: - When `walletProvider` is provided, it is used directly instead of auto-detecting window.opnet.web3. - When omitted, all methods fall through to the existing auto-detect path (via new TransactionFactory.getDefaultBrowserWallet() helper), preserving full backward compatibility. TransactionFactory's four private detect*OPWallet helpers now route through getDefaultBrowserWallet() for the auto-detect fallback, eliminating the repeated window.opnet null checks. For trySignSchnorrWithOPWallet, when an explicit Web3Provider is passed it uses `walletProvider.signSchnorr(messageHex)` (part of the Web3Provider interface). The legacy auto-detect path continues to use the OPWallet's signData method, unchanged. All 838 existing tests pass; no regressions. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Author
|
End-to-end testing setup is ready if helpful for review. The dApp-side change is one line — passing const { walletInstance } = useWalletConnect();
const web3 = (walletInstance as any)?.web3 as Web3Provider | undefined;
const result = await factory.signDeployment(
{ ...params, signer: null, mldsaSigner: null },
web3, // routes to the connected wallet instead of window.opnet auto-detect
);(The cast goes away once Happy to stand up a public demo on testnet.myscribe.org or answer any questions about the API shape. If you'd prefer a different approach (constructor injection, a registry pattern, something else), just say the word — the implementation is small enough that redesign is cheap. |
bitbragi
pushed a commit
to MyScribe-Ecosystem/opnet-upstream-pr
that referenced
this pull request
Apr 19, 2026
Closes the routing gap for third-party OPNet-compatible wallets when invoking contract methods via the fluent API (`contract.method(...).sendTransaction(...)`). Currently, CallResult.signTransaction() calls `factory.signInteraction(params)` without forwarding any wallet provider. TransactionFactory then auto-detects window.opnet.web3, which means all contract interactions route to OP_WALLET even when the dApp has connected a different wallet via @btc-vision/walletconnect. This change adds an optional `walletProvider?: Web3Provider` field to the TransactionParameters interface and forwards it to `factory.signInteraction()`. Behavior is unchanged when omitted (current auto-detect path preserved). Companion to btc-vision/transaction#128, which adds the corresponding parameter to `TransactionFactory.signInteraction()`. This PR requires that one to be merged first (or published as a prerelease) before it can build against the published package. ## Usage const { walletInstance } = useWalletConnect(); const web3 = (walletInstance as any)?.web3; // post-walletconnect hook typed exposure const result = contract.someMethod(args); await result.sendTransaction({ ...existingParams, walletProvider: web3, // routes to the connected wallet }); ## Testing - `npm run build` passes with no errors - `npm test` — 300 existing tests pass. Two pre-existing failures in `test/utxos-manager.test.ts` (unrelated to this change — same failures exist on main). - Manual end-to-end test: verified the combined fix (this PR + btc-vision/transaction#128 + btc-vision/walletconnect#23) correctly routes MyScribe Wallet contract interactions on testnet.myscribe.org. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Author
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.
Closes #127.
Summary
TransactionFactoryandMessageSignercurrently auto-detectwindow.opnet.web3as the sole browser signing provider. This blocks any third-party OPNet-compatible wallet (injected at other window globals, such aswindow.myscribe) from being used through the documentedsigner: nullbrowser flow — even when the caller has explicitly connected a different wallet via@btc-vision/walletconnect.This PR adds an optional
walletProvider?: Web3Providerparameter to every public signing entry point. When provided, it is used directly instead of auto-detectingwindow.opnet.web3. When omitted, all methods fall through to the existing auto-detect path — preserving full backward compatibility.Changes
src/transaction/TransactionFactory.tswalletProvider?: Web3Providerparameter on the four public signing entry points:createCancellableTransaction(params, walletProvider?)signInteraction(params, walletProvider?)signDeployment(params, walletProvider?)createBTCTransfer(params, walletProvider?)detect*OPWallethelpers now accept and use the same parameter.getDefaultBrowserWallet(): Web3Provider | nullthat wraps the existingwindow.opnet.web3auto-detect logic. Replaces the four duplicated null-check blocks.src/keypair/MessageSigner.tssignMessageAuto(message, keypair?, walletProvider?)tweakAndSignMessageAuto(message, keypair?, network?, walletProvider?)signMLDSAMessageAuto(message, mldsaKeypair?, walletProvider?)trySignSchnorrWithOPWallet(message, walletProvider?)trySignMLDSAWithOPWallet(message, walletProvider?)verifyMLDSAWithOPWallet(message, signature, walletProvider?)getMLDSAPublicKeyFromOPWallet(walletProvider?)trySignSchnorrWithOPWallet: when an explicitWeb3Provideris passed, it useswalletProvider.signSchnorr(messageHex)(part of theWeb3Providerinterface). The legacy auto-detect path continues to useOPWallet.signData(...), unchanged.Not modified:
signMessageECDSAAuto/trySignECDSAWithOPWallet—Web3Providerhas no ECDSA method, so these remain OP_WALLET-only. Can be extended later ifWeb3Providerever adds an ECDSA method.signConsolidatedInteraction— does not call anydetect*OPWalletpath; requires an explicit signer already.Backward compatibility
walletProvideris passed, behavior is identical to today (auto-detectwindow.opnet.web3).WindowWithWalletsinterface, theOPWallettype, or any exported public types.Testing
npm run build— clean, no ESLint or TypeScript errorsnpm run check:circular— no circular dependenciesnpm test— 838 tests pass, 6 skipped, 0 failed (verified no regressions)How this unblocks multi-wallet OPNet dApps
With this change + the companion PR btc-vision/walletconnect#23, a dApp can route signing through the currently-connected wallet regardless of which OPNet-compatible wallet the user selected:
If the dApp doesn't care about multi-wallet support, omitting the second argument preserves today's OP_WALLET auto-detect behavior exactly.
Documentation
A handful of
documentation/**/*.mdfiles referencewindow.opnet.web3as the sole signing path. Happy to follow up with a docs PR once this API shape is locked in — kept it out of this diff to keep the change surgical and easy to review.