Skip to content

Conversation

@matthiasgeihs
Copy link
Contributor

Adding support for bip340 signing.

@himanshuchawla009 himanshuchawla009 changed the title Add bip340 v4: Add bip340 Nov 25, 2024
@himanshuchawla009 himanshuchawla009 changed the base branch from master to v4 November 26, 2024 09:47
factorKey: string;
}

export enum SigType {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use this type from @toruslabs/constants package

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point. will do that.


note:
just realized that we use the KeyType type from @tkey/common-types (not from @toruslabs/constants). not sure if that's in issue.

this._tssLib = options.tssLib;
this._keyType = options.tssLib.keyType as KeyType;
this._sigType = (() => {
if (!(options.tssLib as V4TSSLibType).sigType) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this required to make sure that mpc core kit works with older tss libs which doesn't have sigType ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, basically, if we don't have the sigtype from the lib, then we derive it from the key type.

this is only needed if we want to maintain backwards compatibility. if don't need this, it's more straightforward.

you said we probably want backwards compatibility, but you didn't give a reason yet.

so, i think if we don't really need backwards compatibility, it would be better to drop it because it simplifies the code and makes it less error prone.

* For signature type ed25519, consider using _UNSAFE_exportTssEd25519Seed.
*/
public async _UNSAFE_exportTssKey(): Promise<string> {
if (this.keyType !== KeyType.secp256k1) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont we need to add corresponding sigType check for this as per function comments on top?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think so. exporting the private key scalar is a meaningful operation for all key types and sig types.

you are right that for ed25519 users probably want the seed in most cases. i'd still argue that providing the ability to export the scalar can still be useful (e.g., if the seed isn't available) and i don't see a reason why we should prevent it.

return (this._tssLib as V4TSSLibType).load();
} else if ((this._tssLib as V3TSSLibType).lib) {
return (this._tssLib as V3TSSLibType).lib as DKLSWasmLib | FrostWasmLib;
return (this._tssLib as V3TSSLibType).lib as DKLSWasmLib | FrostWasmLibEd25519 | FrostWasmLibBip340;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we can remove the support for older v3 tss libs in this version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

happy to drop the support for older versions. this will simplify some of the code as outlined above.

will add a commit that does so.

Copy link
Member

@himanshuchawla009 himanshuchawla009 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@himanshuchawla009 himanshuchawla009 merged commit 31fd129 into v4 Nov 28, 2024
1 check passed
@himanshuchawla009 himanshuchawla009 deleted the feat/bip340 branch November 28, 2024 07:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants