feat(btc): expose coinselect sortingStrategy for deterministic output ordering, OK-50996#10493
Conversation
Document the plan to expose sortingStrategy parameter in @onekeyfe/coinselect witness.js for deterministic output ordering. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…nsactions Expose sortingStrategy parameter through coinSelectWithWitness to control BTC transaction output ordering. When opReturn is present (protocol transactions like THORSwap), use 'none' strategy to guarantee the payment address appears as the first output. Regular transfers continue using the default 'random' strategy for privacy.
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 53f7835c05
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Warning Review the following alerts detected in dependencies. According to your organization's Security Policy, it is recommended to resolve "Warn" alerts. Learn more about Socket for GitHub.
|
… ordering, OK-50996 (OneKeyHQ#10493) * docs: add coinselect sorting strategy design doc Document the plan to expose sortingStrategy parameter in @onekeyfe/coinselect witness.js for deterministic output ordering. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * docs: add coinselect sortingStrategy implementation plan Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat(btc): pass sortingStrategy to coinSelectWithWitness for swap transactions Expose sortingStrategy parameter through coinSelectWithWitness to control BTC transaction output ordering. When opReturn is present (protocol transactions like THORSwap), use 'none' strategy to guarantee the payment address appears as the first output. Regular transfers continue using the default 'random' strategy for privacy. * chore: upgrade sdk * chore: delete plan docs --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Summary
sortingStrategyparameter throughcoinSelectWithWitnessto control BTC transaction output orderingopReturnpresence), use'none'strategy to guarantee payment address as the first output'random'strategy for privacyIntent & Context
Third-party protocols (e.g., THORSwap) require the
toaddress to appear as the first output in BTC transactions. The@onekeyfe/coinselectSDK uses a'random'sorting strategy by default, which randomly inserts the change output before or after the payment output (~50% chance). This breaks protocol requirements.The coinselect SDK was updated in OneKeyHQ/coinselect#17 to accept an optional
sortingStrategyparameter. This PR wires that parameter through the app-monorepo call chain.Design Decisions
opReturn: Presence ofopReturnintransfersInforeliably indicates a protocol transaction (THORSwap, etc.), not a regular user transfer. This avoids adding new fields toITransferInfo.'random'sorting for privacy (prevents observers from identifying payment vs change outputs by position).undefinedas default: When nosortingStrategyis passed, the SDK defaults to'random', maintaining full backward compatibility.Changes Detail
packages/core/src/utils/coinSelectUtils.ts: AddedICoinSelectSortingStrategytype; addedsortingStrategytoICoinSelectWithWitnessOptionsand passed it through to the SDKpackages/kit-bg/src/vaults/impls/btc/Vault.ts: PasssortingStrategy: 'none'whenopReturnis present in transfer infoRisk Assessment
opReturn(THORSwap-style swaps). Regular transfers and PSBT-based swaps are unaffected.Test plan
opReturnproduce payment address as first output