-
Notifications
You must be signed in to change notification settings - Fork 315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add non-sequential multi-sig support #1710
Conversation
…y change in the future)
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Codecov ReportAttention: Patch coverage is
📢 Thoughts on this report? Let us know! |
numSignatures: number; | ||
publicKeys: string[]; | ||
} | ||
export type UnsignedMultiSigTokenTransferOptions = TokenTransferOptions & UnsignedMultiSigOptions; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored these types to be more reusable. Does anybody think the change from interface
to type
is a problem?
signer.appendOrigin(publicKeyFromBytes(hexToBytes(publicKey))); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jbencin you'll notice this now differs from the blockchain make
methods, but I think is more correct. We try to sign/append in order of public-keys, rather than first all signs and then all appends (not exactly sure why that was in the code previously, but seems to be inspired by stacks-core methods)
const stacksPublicKeys = pubKeys.map(createStacksPublicKey); | ||
const publicKeys = pubKeys.slice(); | ||
|
||
// sort public keys (only for newer non-sequential multi-sig for backwards compatibility) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be handled the same way in all multisig transaction types: We recommend that the user sort their pubkeys when creating, but we can't force it because users may have funds in accounts that don't use the recommended ordering
You could add a boolean
argument, or create another version of this function, createMultiSigSpendingConditionSorted
, if you want to provide sorting functionality to the user. But you can't just assume the user wants it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. I would like to be more opinionated about it, so maybe sorting can be the default and we add a disablePublicKeySorting
flag. But yeah, this should be a part of all the helpers then as well.. Will change 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or maybe not, 🤔 technically the developer can still update and replace conditions/modes/etc. on any transaction fairly easily in Stacks.js (assuming they know what they're doing). Similar to how we don't really expose p2wsh multi-sig, we can "hide" the unsorted variant a bit more as well 🤷🏻♀️ trying to find a balance for users to be able to get less wrong by accident.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even with sequential multisig transactions, it was customary to sort the pubkeys before creating a transaction, but it was never enforced. So new multisig types should not handle this differently
One thing you could do, which would work for both types and would be backwards compatible, is to add an optional address
parameter. Users would be encouraged to supply the address of the multisig account, and you could check if the pubkeys generate that address, first in the order given, then sort them and try in that order. If it doesn't match in either order, return an error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lovely approach!!! I really like this more than another config flag!! 👏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just thinking about next breaking release, I would like to change the default behavior to "sorted" to guide the ecosystem to the preferred way
.
Ready for re-review @jbencin 🙏 |
privateKey.data.byteLength === PRIVATE_KEY_COMPRESSED_LENGTH | ||
? PubKeyEncoding.Compressed | ||
: PubKeyEncoding.Uncompressed, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be safer to have a switch
here, and fail if privateKey.data.byteLength
isn't PRIVATE_KEY_COMPRESSED_LENGTH
or PRIVATE_KEY_UNCOMPRESSED_LENGTH
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work here! Any of the discussions that are still open I consider very minor and won't hold up approval for them
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
Comment