-
-
Notifications
You must be signed in to change notification settings - Fork 51
feat: support multicurve #304
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
8a4e614
af85c8e
17b4e40
3aa1816
5bb7e6d
c08c487
23f565a
bcc2b42
30ada0c
5a42797
0189290
fc2f298
6ff795d
057f794
e4f22fb
7e75b16
93f266b
f14236c
5187baa
35dc228
3efc4e8
5e037af
a7ecc46
cd4332d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,8 @@ import { | |
| FactorEnc, | ||
| getPubKeyPoint, | ||
| IMetadata, | ||
| ISerializable, | ||
| ITssMetadata, | ||
| KeyType, | ||
| Point, | ||
| PolyIDAndShares, | ||
|
|
@@ -27,6 +29,97 @@ import stringify from "json-stable-stringify"; | |
| import CoreError from "./errors"; | ||
| import { polyCommitmentEval } from "./lagrangeInterpolatePolynomial"; | ||
|
|
||
| const METADATA_VERSION = 1; | ||
|
|
||
| export class TssMetadata implements ITssMetadata, ISerializable { | ||
| tssKeyTypes: { | ||
| [tssTag: string]: KeyType; | ||
| }; | ||
|
|
||
| tssNonces: { | ||
| [tssTag: string]: number; | ||
| }; | ||
|
|
||
| tssPolyCommits: { | ||
| [tssTag: string]: Point[]; | ||
| }; | ||
|
|
||
| factorPubs: { | ||
| [tssTag: string]: Point[]; | ||
| }; | ||
|
|
||
| factorEncs: { | ||
| [tssTag: string]: { | ||
| [factorPubID: string]: FactorEnc; | ||
| }; | ||
| }; | ||
|
|
||
| constructor() { | ||
| this.tssKeyTypes = {}; | ||
| this.tssNonces = {}; | ||
| this.tssPolyCommits = {}; | ||
| this.factorPubs = {}; | ||
| this.factorEncs = {}; | ||
| } | ||
|
|
||
| static fromJSON(value: StringifiedType): TssMetadata { | ||
| const { tssKeyTypes, tssPolyCommits, tssNonces, factorPubs, factorEncs } = value; | ||
| const tssMetadata = new TssMetadata(); | ||
|
|
||
| if (tssKeyTypes) { | ||
| for (const key in tssKeyTypes) { | ||
| tssMetadata.tssKeyTypes[key] = tssKeyTypes[key]; | ||
| } | ||
| } | ||
| if (tssPolyCommits) { | ||
| for (const key in tssPolyCommits) { | ||
| tssMetadata.tssPolyCommits[key] = (tssPolyCommits as Record<string, Point[]>)[key].map((obj) => new Point(obj.x, obj.y)); | ||
| } | ||
| } | ||
| if (tssNonces) { | ||
| for (const key in tssNonces) { | ||
| tssMetadata.tssNonces[key] = tssNonces[key]; | ||
| } | ||
| } | ||
| if (factorPubs) { | ||
| for (const key in factorPubs) { | ||
| tssMetadata.factorPubs[key] = (factorPubs as Record<string, Point[]>)[key].map((obj) => new Point(obj.x, obj.y)); | ||
| } | ||
| } | ||
| if (factorEncs) tssMetadata.factorEncs = factorEncs; | ||
|
|
||
| return tssMetadata; | ||
| } | ||
|
|
||
| toJSON(): StringifiedType { | ||
| return { | ||
| tssKeyTypes: this.tssKeyTypes, | ||
| tssNonces: this.tssNonces, | ||
| tssPolyCommits: this.tssPolyCommits, | ||
| factorPubs: this.factorPubs, | ||
| factorEncs: this.factorEncs, | ||
| }; | ||
| } | ||
|
|
||
| update(tssData: { | ||
| tssTag: string; | ||
| tssKeyType?: KeyType; | ||
| tssNonce?: number; | ||
| tssPolyCommits?: Point[]; | ||
| factorPubs?: Point[]; | ||
| factorEncs?: { | ||
| [factorPubID: string]: FactorEnc; | ||
| }; | ||
| }) { | ||
| const { tssKeyType, tssTag, tssNonce, tssPolyCommits, factorPubs, factorEncs } = tssData; | ||
| if (tssKeyType) this.tssKeyTypes[tssTag] = tssKeyType; | ||
| if (tssNonce !== undefined) this.tssNonces[tssTag] = tssNonce; | ||
| if (tssPolyCommits) this.tssPolyCommits[tssTag] = tssPolyCommits; | ||
| if (factorPubs) this.factorPubs[tssTag] = factorPubs; | ||
| if (factorEncs) this.factorEncs[tssTag] = factorEncs; | ||
| } | ||
| } | ||
|
|
||
| class Metadata implements IMetadata { | ||
| pubKey: Point; | ||
|
|
||
|
|
@@ -73,6 +166,13 @@ class Metadata implements IMetadata { | |
| }; | ||
| }; | ||
|
|
||
| tss?: { | ||
|
ieow marked this conversation as resolved.
Outdated
|
||
| secp256k1: TssMetadata; | ||
| ed25519: TssMetadata; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make this a Record of |
||
| }; | ||
|
|
||
| version = METADATA_VERSION; | ||
|
|
||
| constructor(input: Point) { | ||
| this.publicPolynomials = {}; | ||
| this.publicShares = {}; | ||
|
|
@@ -90,41 +190,46 @@ class Metadata implements IMetadata { | |
| } | ||
|
|
||
| static fromJSON(value: StringifiedType): Metadata { | ||
| const { pubKey, polyIDList, generalStore, tkeyStore, scopedStore, nonce, tssKeyTypes, tssPolyCommits, tssNonces, factorPubs, factorEncs } = value; | ||
| const { | ||
| pubKey, | ||
| polyIDList, | ||
| generalStore, | ||
| tkeyStore, | ||
| scopedStore, | ||
| nonce, | ||
| tssKeyTypes, | ||
| tssPolyCommits, | ||
| tssNonces, | ||
| factorPubs, | ||
| factorEncs, | ||
| tss, | ||
| version, | ||
| } = value; | ||
| const point = Point.fromSEC1(secp256k1, pubKey); | ||
| const metadata = new Metadata(point); | ||
| metadata.version = version || METADATA_VERSION; | ||
|
|
||
| const unserializedPolyIDList: PolyIDAndShares[] = []; | ||
|
|
||
| if (generalStore) metadata.generalStore = generalStore; | ||
| if (tkeyStore) metadata.tkeyStore = tkeyStore; | ||
| if (scopedStore) metadata.scopedStore = scopedStore; | ||
| if (nonce) metadata.nonce = nonce; | ||
|
|
||
| if (tssKeyTypes) { | ||
| metadata.tssKeyTypes = {}; | ||
| for (const key in tssKeyTypes) { | ||
| metadata.tssKeyTypes[key] = tssKeyTypes[key]; | ||
| } | ||
| } | ||
| if (tssPolyCommits) { | ||
| metadata.tssPolyCommits = {}; | ||
| for (const key in tssPolyCommits) { | ||
| metadata.tssPolyCommits[key] = (tssPolyCommits as Record<string, Point[]>)[key].map((obj) => new Point(obj.x, obj.y)); | ||
| } | ||
| } | ||
| if (tssNonces) { | ||
| metadata.tssNonces = {}; | ||
| for (const key in tssNonces) { | ||
| metadata.tssNonces[key] = tssNonces[key]; | ||
| } | ||
| } | ||
| if (factorPubs) { | ||
| metadata.factorPubs = {}; | ||
| for (const key in factorPubs) { | ||
| metadata.factorPubs[key] = (factorPubs as Record<string, Point[]>)[key].map((obj) => new Point(obj.x, obj.y)); | ||
| if (version === 1) { | ||
| metadata.tss = tss; | ||
| } else if (tssKeyTypes) { | ||
| const tssData = TssMetadata.fromJSON({ | ||
| tssKeyTypes, | ||
| tssPolyCommits, | ||
| tssNonces, | ||
| factorPubs, | ||
| factorEncs, | ||
| }); | ||
| if (tssData.tssKeyTypes.default) { | ||
| metadata.tss[tssData.tssKeyTypes.default] = tssData; | ||
| } | ||
| } | ||
| if (factorEncs) metadata.factorEncs = factorEncs; | ||
|
|
||
| for (let i = 0; i < polyIDList.length; i += 1) { | ||
| const serializedPolyID: string = polyIDList[i]; | ||
|
|
@@ -327,11 +432,8 @@ class Metadata implements IMetadata { | |
| generalStore: this.generalStore, | ||
| tkeyStore: this.tkeyStore, | ||
| nonce: this.nonce, | ||
| ...(this.tssKeyTypes && { tssKeyTypes: this.tssKeyTypes }), | ||
| ...(this.tssNonces && { tssNonces: this.tssNonces }), | ||
| ...(this.tssPolyCommits && { tssPolyCommits: this.tssPolyCommits }), | ||
| ...(this.factorPubs && { factorPubs: this.factorPubs }), | ||
| ...(this.factorEncs && { factorEncs: this.factorEncs }), | ||
| tss: this.tss, | ||
| version: this.version, | ||
| }; | ||
| } | ||
|
|
||
|
|
@@ -348,12 +450,16 @@ class Metadata implements IMetadata { | |
| [factorPubID: string]: FactorEnc; | ||
| }; | ||
| }): void { | ||
| const { tssKeyType, tssTag, tssNonce, tssPolyCommits, factorPubs, factorEncs } = tssData; | ||
| if (tssKeyType) this.tssKeyTypes[tssTag] = tssKeyType; | ||
| if (tssNonce !== undefined) this.tssNonces[tssTag] = tssNonce; | ||
| if (tssPolyCommits) this.tssPolyCommits[tssTag] = tssPolyCommits; | ||
| if (factorPubs) this.factorPubs[tssTag] = factorPubs; | ||
| if (factorEncs) this.factorEncs[tssTag] = factorEncs; | ||
| if (tssData.tssKeyType === KeyType.ed25519) this.tss.ed25519.update(tssData); | ||
| else if (tssData.tssKeyType === KeyType.secp256k1) this.tss.secp256k1.update(tssData); | ||
| } | ||
|
|
||
| getTssData(tssKeyType: KeyType): ITssMetadata { | ||
| if (tssKeyType === KeyType.secp256k1) { | ||
| return this.tss?.secp256k1; | ||
| } else if (tssKeyType === KeyType.ed25519) { | ||
| return this.tss?.ed25519; | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,7 +27,7 @@ | |
| "@toruslabs/customauth": "^20.3.0", | ||
| "@toruslabs/http-helpers": "^7.0.0", | ||
| "@toruslabs/rss-client": "^2.0.1", | ||
| "@toruslabs/torus.js": "^15.1.0", | ||
| "@toruslabs/torus.js": "file:../../../torus.js/toruslabs-torus.js-15.1.1.tgz", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove! This PR should not be marked as ready for review! |
||
| "@types/bn.js": "^5.1.5", | ||
| "bn.js": "^5.2.1", | ||
| "elliptic": "^6.5.5", | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
I think it would be good if we can provide some comments for the interface fields