hirosystems / stacks.js

JavaScript libraries for identity, auth, storage and transactions on the Stacks blockchain.
https://stacks.js.org
MIT License
944 stars 307 forks source link

feat: Add non-sequential multi-sig support #1710

Closed janniks closed 5 days ago

janniks commented 1 week ago

This PR was published to npm with the version 6.15.0 e.g. npm install @stacks/common@6.15.0 --save-exact

Related:


Adds a useNonSequentialMultiSig flag to multi-sig transaction creation methods. (Along with the internals to support it)

So far this opt is marked @experimental, since the interface of the default could change. (And we likely want to see how the authorization type plays out on mainnet, before switching fully)

Example

      const tx = await makeSTXTokenTransfer({
        recipient: 'STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6',
        amount: 12_345n,
        fee: 1_000n,
        nonce: 2n,
        network: 'testnet',

        numSignatures: required,
        publicKeys: [k1, k2, k3],
        signerKeys: [k3, k1], // could sign in any order (even if serializing in between and not sharing state)

        useNonSequentialMultiSig: true, // <--- NEW OPTIONAL FLAG
      });

Comment

The separate signing test really shows there is more work needed to make this easy to use for folks building a "real" multi-sig experience -- with serializing the transaction in between signatures. This could be added as a separate issue or addressed in a breaking change (there is an opportunity to clean up the TransactionSigner as well, which is intertwined with the StacksTransaction class).

Follow up thoughts: This can probably be addressed with one mutating public method on the StacksTransaction called something like .finalize() or .finalizeMultiSig(), which ensures the transaction-auth-fields are in the intended order. (Might need the list of public-keys again, or can do an opinionated .sort first, but technically should work for legacy multi-sig as well).

vercel[bot] commented 1 week ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
stacksjs-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 28, 2024 6:50pm
codecov[bot] commented 1 week ago

Codecov Report

Attention: Patch coverage is 95.09804% with 5 lines in your changes missing coverage. Please review. Files Patch % Lines
packages/transactions/src/builders.ts 88.09% 5 Missing :warning:

:loudspeaker: Thoughts on this report? Let us know!

janniks commented 1 week ago

Ready for re-review @jbencin 🙏