Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion packages/core/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ class ThresholdKey implements ITKey {
if (useTSS) {
if (!this.metadata.tssPolyCommits[this.tssTag]) {
// if tss shares have not been created for this tssTag, create new tss sharing
await this._initializeNewTSSKey(this.tssTag, deviceTSSShare, factorPub);
await this._initializeNewTSSKey(this.tssTag, deviceTSSShare, factorPub, deviceTSSIndex);
}
}

Expand Down Expand Up @@ -458,6 +458,27 @@ class ThresholdKey implements ITKey {
return this.getTSSCommits()[0];
}

setTssTag(tssTag: string): void {
this.tssTag = tssTag;
}

async createTaggedTSSShare(factorPub: Point, tssShare: BN, tssIndex: number) {
if (!this.privKey) throw CoreError.default("tkey must be reconstructed");
if (!this.metadata) throw CoreError.metadataUndefined();
if (!this.tssTag) throw CoreError.default("tssTag must be set");
if (this.metadata.factorPubs[this.tssTag]) throw CoreError.default(`tssTag ${this.tssTag} already exists`);

const { factorEncs, factorPubs, tssPolyCommits } = await this._initializeNewTSSKey(this.tssTag, tssShare, factorPub, tssIndex);
this.metadata.addTSSData({
tssTag: this.tssTag,
tssNonce: 0,
tssPolyCommits,
factorPubs,
factorEncs,
});
await this._syncShareMetadata();
}

/**
* catchupToLatestShare recursively loops fetches metadata of the provided share and checks if there is an encrypted share for it.
* @param shareStore - share to start of with
Expand Down
16 changes: 14 additions & 2 deletions packages/default/test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,14 @@ export function getServiceProvider(params) {
return new ServiceProviderBase({ postboxKey: isEmptyProvider ? null : PRIVATE_KEY });
}

const MockServers = [new MockServer(), new MockServer(), new MockServer(), new MockServer(), new MockServer()];
export async function setupTSSMocks(opts) {
let { serviceProvider, verifierName, verifierId, maxTSSNonceToSimulate, tssTag } = opts;
let { serviceProvider, verifierName, verifierId, maxTSSNonceToSimulate, tssTag, postboxKey } = opts;
tssTag = tssTag || "default";
serviceProvider._setVerifierNameVerifierId(verifierName, verifierId);
const vid = serviceProvider.getVerifierNameVerifierId();
maxTSSNonceToSimulate = maxTSSNonceToSimulate || 1;
const serverEndpoints = [new MockServer(), new MockServer(), new MockServer(), new MockServer(), new MockServer()];
const serverEndpoints = MockServers;
const serverCount = serverEndpoints.length;
const serverPrivKeys = [];
for (let i = 0; i < serverCount; i++) {
Expand Down Expand Up @@ -96,6 +97,11 @@ export async function setupTSSMocks(opts) {
}

serviceProvider._setTSSNodeDetails(serverEndpoints, serverPubKeys, serverThreshold);
// serviceProvider.rs = { ...serviceProvider.sssEndpoints }
if (!postboxKey) {
const postboxKeyGenerated = new BN(generatePrivate());
serviceProvider.postboxKey = postboxKeyGenerated.toString(16, 64);
}

return {
serverEndpoints,
Expand Down Expand Up @@ -182,3 +188,9 @@ export async function assignTssDkgKeys(opts) {
// serverDKGPubKeys,
};
}

export async function executeAtomicAsyncTasks(tasks) {
for (const task of tasks) {
await task(); // Assuming task is an async function
}
}
Loading