Skip to content

Commit 2ce56c9

Browse files
committed
update: add test for batch signing
1 parent 3cfdbbf commit 2ce56c9

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/mpcCoreKit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
754754
throw CoreKitError.default(`sign not supported for key type ${this.keyType}`);
755755
}
756756

757-
public async sign_batch(data: Buffer[], hashed: boolean[] = [false], secp256k1Precompute?: Secp256k1PrecomputedClient): Promise<Buffer[]> {
757+
public async sign_batch(data: Buffer[], hashed: boolean[], secp256k1Precompute?: Secp256k1PrecomputedClient): Promise<Buffer[]> {
758758
// NOTE: Checks here must ensure a batch is only submitted to dkls, frost does not support batch signatures.
759759
if (this.keyType === KeyType.secp256k1) {
760760
this.wasmLib = await this.loadTssWasm();

tests/login.spec.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,37 @@ variable.forEach((testVariable) => {
168168
assert(pubkey2.eq(publicKeyPoint));
169169
});
170170

171+
await t.test("#able to sign batch", async function () {
172+
const coreKitInstance = newCoreKitInstance();
173+
await coreKitInstance.init({ handleRedirectResult: false, rehydrate: false });
174+
const localToken = await mockLogin2(email);
175+
await coreKitInstance.loginWithJWT({
176+
verifier: "torus-test-health",
177+
verifierId: email,
178+
idToken: localToken.idToken,
179+
});
180+
const msg = "hello world";
181+
const msgBuffer = Buffer.from(msg);
182+
const msgHash = keccak256(msgBuffer);
183+
const secp256k1 = new EC("secp256k1");
184+
185+
const buffers = [];
186+
buffers.push(msgHash);
187+
buffers.push(msgHash);
188+
189+
const hashed = [];
190+
hashed.push(true);
191+
hashed.push(true);
192+
193+
const signatures = await coreKitInstance.sign_batch(buffers,hashed)
194+
for (let i = 0; i < signatures.length; i++) {
195+
const signature = sigToRSV(signatures[i]);
196+
const pubkey = secp256k1.recoverPubKey(msgHash, signature, signature.v) as EllipticPoint;
197+
const publicKeyPoint = bufferToElliptic(coreKitInstance.getPubKey());
198+
assert(pubkey.eq(publicKeyPoint));
199+
}
200+
});
201+
171202
await t.test("#Login and sign with different account/wallet index", async function () {
172203
const vid = stringGen(10);
173204
const coreKitInstance = newCoreKitInstance();

0 commit comments

Comments
 (0)