Skip to content

Commit 5bac894

Browse files
committed
fix: rename signECDSA function name
fix multicurve test to use new storage instance fix useClientGeneratedTSSKey bug
1 parent d4ebfbc commit 5bac894

File tree

6 files changed

+18
-19
lines changed

6 files changed

+18
-19
lines changed

src/interfaces.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ export interface ICoreKit {
486486
* - hashed: The data is already hashed. Do not hash again. Only works for ecdsa-secp256k1.
487487
* - secp256k1Precompute: Provide a precomputed client for faster signing. Only works for ecdsa-secp256k1.
488488
*/
489-
signECDSA(
489+
sign_ECDSA_secp256k1(
490490
data: Buffer,
491491
opts?: {
492492
hashed?: boolean;

src/mpcCoreKit.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ export class Web3AuthMPCCoreKit implements ICoreKit, IMPCContext {
890890
};
891891
}
892892

893-
public async signECDSA(data: Uint8Array, opts?: { hashed?: boolean; secp256k1Precompute?: Secp256k1PrecomputedClient }) {
893+
public async sign_ECDSA_secp256k1(data: Uint8Array, opts?: { hashed?: boolean; secp256k1Precompute?: Secp256k1PrecomputedClient }) {
894894
if (!this.supportedCurveKeyTypes.has(KeyType.secp256k1)) {
895895
throw CoreKitError.default(`secp256k1 KeyTYpe is not supported, please configure secp256k1 curve key type `);
896896
}
@@ -899,8 +899,7 @@ export class Web3AuthMPCCoreKit implements ICoreKit, IMPCContext {
899899
}
900900
const { hashed = false, secp256k1Precompute } = opts || {};
901901

902-
// TODO: replace buffer to uint8array
903-
const sig = await this.sign_ECDSA_secp256k1(Buffer.from(data), hashed, secp256k1Precompute);
902+
const sig = await this._sign_ECDSA_secp256k1(Buffer.from(data), hashed, secp256k1Precompute);
904903
return Buffer.concat([sig.r, sig.s, Buffer.from([sig.v])]);
905904
}
906905

@@ -946,7 +945,6 @@ export class Web3AuthMPCCoreKit implements ICoreKit, IMPCContext {
946945
}
947946

948947
// mutation function
949-
950948
async deleteFactor(factorPub: Point, factorKey?: BNString): Promise<void> {
951949
if (!this.state.factorKey) {
952950
throw CoreKitError.factorKeyNotPresent("factorKey not present in state when deleting a factor.");
@@ -1177,9 +1175,11 @@ export class Web3AuthMPCCoreKit implements ICoreKit, IMPCContext {
11771175
if (keyType === KeyType.ed25519) {
11781176
const k = generateEd25519Seed();
11791177
importKey.ed25519 = k.toString("hex");
1180-
} else if (keyType === KeyType.secp256k1 && !!this.options.useClientGeneratedTSSKey) {
1181-
const k = secp256k1.genKeyPair().getPrivate();
1182-
importKey.secp256k1 = scalarBNToBufferSEC1(k).toString("hex");
1178+
} else if (keyType === KeyType.secp256k1) {
1179+
if (this.options.useClientGeneratedTSSKey) {
1180+
const k = secp256k1.genKeyPair().getPrivate();
1181+
importKey.secp256k1 = scalarBNToBufferSEC1(k).toString("hex");
1182+
}
11831183
} else {
11841184
throw CoreKitError.default(`Unsupported key type and sig type combination `);
11851185
}
@@ -1648,7 +1648,7 @@ export class Web3AuthMPCCoreKit implements ICoreKit, IMPCContext {
16481648
return this.tkey.computeAccountNonce(this.state.accountIndex);
16491649
}
16501650

1651-
private async sign_ECDSA_secp256k1(data: Buffer, hashed: boolean = false, precomputedTssClient?: Secp256k1PrecomputedClient) {
1651+
private async _sign_ECDSA_secp256k1(data: Buffer, hashed: boolean = false, precomputedTssClient?: Secp256k1PrecomputedClient) {
16521652
const executeSign = async (client: Client, serverCoeffs: Record<string, string>, hashedData: Buffer, signatures: string[]) => {
16531653
const { r, s, recoveryParam } = await client.sign(hashedData.toString("base64"), true, "", "keccak256", {
16541654
signatures,

src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ export function makeEthereumSigner(kit: Web3AuthMPCCoreKit): EthereumSigner {
202202
}
203203
return {
204204
sign: async (msgHash: Buffer) => {
205-
const sig = await kit.signECDSA(msgHash, { hashed: true });
205+
const sig = await kit.sign_ECDSA_secp256k1(msgHash, { hashed: true });
206206
return sigToRSV(sig);
207207
},
208208
getPublic: async () => {

tests/backwardCompatible.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ variable.forEach((testVariable) => {
122122
const msg = "hello world";
123123
const msgBuffer = Buffer.from(msg);
124124
const msgHash = keccak256(msgBuffer);
125-
const signature = sigToRSV(await coreKitInstance.signECDSA(msgHash, { hashed: true } ));
125+
const signature = sigToRSV(await coreKitInstance.sign_ECDSA_secp256k1(msgHash, { hashed: true } ));
126126

127127
const secp256k1 = new EC("secp256k1");
128128
const pubkey = secp256k1.recoverPubKey(msgHash, signature, signature.v) as EllipticPoint;

tests/login.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,13 @@ variable.forEach((testVariable) => {
156156
const secp256k1 = new EC("secp256k1");
157157

158158
// Sign hash.
159-
const signature = sigToRSV(await coreKitInstance.signECDSA(msgHash, { hashed: true }));
159+
const signature = sigToRSV(await coreKitInstance.sign_ECDSA_secp256k1(msgHash, { hashed: true }));
160160
const pubkey = secp256k1.recoverPubKey(msgHash, signature, signature.v) as EllipticPoint;
161161
const publicKeyPoint = bufferToElliptic(coreKitInstance.getPubKey(keyType));
162162
assert(pubkey.eq(publicKeyPoint));
163163

164164
// Sign full message.
165-
const signature2 = sigToRSV(await coreKitInstance.signECDSA(msgBuffer));
165+
const signature2 = sigToRSV(await coreKitInstance.sign_ECDSA_secp256k1(msgBuffer));
166166
const pubkey2 = secp256k1.recoverPubKey(msgHash, signature2, signature2.v) as EllipticPoint;
167167
assert(pubkey2.eq(publicKeyPoint));
168168
});
@@ -186,7 +186,7 @@ variable.forEach((testVariable) => {
186186
const msg = "hello world 1";
187187
const msgBuffer = Buffer.from(msg);
188188
const msgHash = keccak256(msgBuffer);
189-
const signature1 = sigToRSV(await coreKitInstance.signECDSA(msgHash, { hashed: true }));
189+
const signature1 = sigToRSV(await coreKitInstance.sign_ECDSA_secp256k1(msgHash, { hashed: true }));
190190

191191
const pubkeyIndex0 = secp256k1.recoverPubKey(msgHash, signature1, signature1.v);
192192
const publicKeyPoint0 = bufferToElliptic(coreKitInstance.getPubKey(keyType));
@@ -198,7 +198,7 @@ variable.forEach((testVariable) => {
198198
const msgBuffer1 = Buffer.from(msg1);
199199
const msgHash1 = keccak256(msgBuffer1);
200200

201-
const signature2 = sigToRSV(await coreKitInstance.signECDSA(msgHash1, { hashed: true }));
201+
const signature2 = sigToRSV(await coreKitInstance.sign_ECDSA_secp256k1(msgHash1, { hashed: true }));
202202

203203
const pubkeyIndex1 = secp256k1.recoverPubKey(msgHash1, signature2, signature2.v) as EllipticPoint;
204204
const publicKeyPoint1 = bufferToElliptic(coreKitInstance.getPubKey(keyType));
@@ -211,7 +211,7 @@ variable.forEach((testVariable) => {
211211
const msg2 = "hello world 3";
212212
const msgBuffer2 = Buffer.from(msg2);
213213
const msgHash2 = keccak256(msgBuffer2);
214-
const signature3 = sigToRSV(await coreKitInstance.signECDSA(msgHash2, { hashed: true }));
214+
const signature3 = sigToRSV(await coreKitInstance.sign_ECDSA_secp256k1(msgHash2, { hashed: true }));
215215

216216
const pubkeyIndex2 = secp256k1.recoverPubKey(msgHash2, signature3, signature3.v) as EllipticPoint;
217217
const publicKeyPoint2 = bufferToElliptic(coreKitInstance.getPubKey(keyType));

tests/multiCurveTest.spec.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { schnorr as bip340 } from '@noble/curves/secp256k1';
2020

2121
const web3AuthNetwork = WEB3AUTH_NETWORK.DEVNET;
2222
const manualSync = false;
23-
const storageInstance = new MemoryStorage();
2423
const verifierId = "multicurvetest"
2524

2625
const mockSL = new MockStorageLayer({
@@ -36,7 +35,7 @@ describe("multiCurveTest", () => {
3635
baseUrl: "http://localhost:3000",
3736
uxMode: "nodejs",
3837
supportedKeyTypes: [KeyType.secp256k1, KeyType.ed25519],
39-
storage: storageInstance,
38+
storage: new MemoryStorage(),
4039
manualSync,
4140
});
4241

@@ -46,7 +45,7 @@ describe("multiCurveTest", () => {
4645

4746
const hash = keccak_256(message);
4847
instance.addTssLibs([dklslib]);
49-
const result = await instance.signECDSA(Buffer.from(hash), {hashed: true})
48+
const result = await instance.sign_ECDSA_secp256k1(Buffer.from(hash), {hashed: true})
5049
const {r, s } = sigToRSV(result);
5150

5251
const validsecp256k1 = secp256k1.verify({

0 commit comments

Comments
 (0)