Skip to content

Commit 2a4322d

Browse files
committed
fix: update interface and comment
rename function name
1 parent 7723c8a commit 2a4322d

File tree

6 files changed

+40
-17
lines changed

6 files changed

+40
-17
lines changed

src/interfaces.ts

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -478,21 +478,44 @@ export interface ICoreKit {
478478
commitChanges(): Promise<void>;
479479

480480
/**
481-
* Create a signature for the given data.
481+
* Create a SECP256K1 ECDSA signature for the given data.
482+
* will throw if secp256k1 is not configured as supported keyType
483+
* will thrwo if dkls lib is not added prior signing
482484
*
483485
* Options:
484486
* - hashed: The data is already hashed. Do not hash again. Only works for ecdsa-secp256k1.
485487
* - secp256k1Precompute: Provide a precomputed client for faster signing. Only works for ecdsa-secp256k1.
488+
*/
489+
signECDSA(
490+
data: Buffer,
491+
opts?: {
492+
hashed?: boolean;
493+
secp256k1Precompute?: Secp256k1PrecomputedClient;
494+
}
495+
): Promise<Buffer>;
496+
497+
/**
498+
* Create a BIP340 signature for the given data.
499+
* will throw if secp256k1 is not configured as supported keyType
500+
* will thrwo if bip340 frost lib is not added prior signing
501+
*
502+
* Options:
486503
* - keyTweak: Provide a bip340 key tweak. Only works for bip340.
487504
*/
488-
// sign(
489-
// data: Buffer,
490-
// opts?: {
491-
// hashed?: boolean;
492-
// secp256k1Precompute?: Secp256k1PrecomputedClient;
493-
// keyTweak?: BN;
494-
// }
495-
// ): Promise<Buffer>;
505+
signBIP340(
506+
data: Buffer,
507+
opts?: {
508+
keyTweak?: BN;
509+
}
510+
): Promise<Buffer>;
511+
512+
/**
513+
* Create a ED25519 signature for the given data.
514+
* will throw if ed25519 is not configured as supported keyType
515+
* will thrwo if ed25519 frost lib is not added prior signing
516+
*
517+
*/
518+
signED25519(data: Buffer): Promise<Buffer>;
496519

497520
/**
498521
* WARNING: Use with caution. This will export the private signing key.

src/mpcCoreKit.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ export class Web3AuthMPCCoreKit implements ICoreKit, IMPCContext {
900900
return Buffer.concat([sig.r, sig.s, Buffer.from([sig.v])]);
901901
}
902902

903-
public async signBip340(data: Uint8Array, opts?: { hashed?: boolean; keyTweak?: BN }) {
903+
public async signBIP340(data: Uint8Array, opts?: { hashed?: boolean; keyTweak?: BN }) {
904904
if (!this.supportedCurveKeyTypes.has(KeyType.secp256k1)) {
905905
throw CoreKitError.default(`secp256k1 KeyTYpe is not supported, please configure secp256k1 curve key type `);
906906
}
@@ -922,7 +922,7 @@ export class Web3AuthMPCCoreKit implements ICoreKit, IMPCContext {
922922
return this.sign_frost({ data: Buffer.from(data), frostlib, keyTweak: opts?.keyTweak });
923923
}
924924

925-
public async signEd25519(data: Uint8Array) {
925+
public async signED25519(data: Uint8Array) {
926926
if (!this.supportedCurveKeyTypes.has(KeyType.ed25519)) {
927927
throw CoreKitError.default(`ed25519 KeyTYpe is not supported, please configure ed25519 curve key type `);
928928
}

src/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ export function makeBip340Signer(kit: Web3AuthMPCCoreKit): Bip340Signer {
219219

220220
return {
221221
sign: async (msgHash: Buffer) => {
222-
return kit.signBip340(msgHash, { hashed: false });
222+
return kit.signBIP340(msgHash, { hashed: false });
223223
},
224224
getPublic: async () => {
225225
const pk = Point.fromSEC1(secp256k1, kit.getPubKey(KeyType.secp256k1).toString("hex"));
@@ -234,7 +234,7 @@ export function makeEd25519Signer(kit: Web3AuthMPCCoreKit): Ed25519Signer {
234234
}
235235
return {
236236
sign: async (msgHash: Buffer) => {
237-
return kit.signEd25519(msgHash);
237+
return kit.signED25519(msgHash);
238238
},
239239
getPublic: async () => {
240240
return kit.getPubKeyEd25519();

tests/bip340.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ variable.forEach((testVariable) => {
151151
const msg = "hello world";
152152
const msgBuffer = Buffer.from(msg);
153153

154-
const signature = await coreKitInstance.signBip340(msgBuffer);
154+
const signature = await coreKitInstance.signBIP340(msgBuffer);
155155
const pk = coreKitInstance.getPubKeyBip340();
156156
const valid = bip340.verify(signature, msgBuffer, pk);
157157
assert(valid);

tests/ed25519.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ variable.forEach((testVariable) => {
148148
const msg = "hello world";
149149
const msgBuffer = Buffer.from(msg);
150150

151-
const signature = ed25519().makeSignature((await coreKitInstance.signEd25519(msgBuffer)).toString("hex"));
151+
const signature = ed25519().makeSignature((await coreKitInstance.signED25519(msgBuffer)).toString("hex"));
152152
const valid = ed25519().verify(msgBuffer, signature, coreKitInstance.getPubKeyEd25519());
153153
assert(valid);
154154
});

tests/multiCurveTest.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ describe("multiCurveTest", () => {
5656
expect(validsecp256k1).eq(true);
5757

5858
instance.addTssLibs([frostBip340lib]);
59-
const result2 = await instance.signBip340( Buffer.from(utf8ToBytes(message)), {hashed: false})
59+
const result2 = await instance.signBIP340( Buffer.from(utf8ToBytes(message)), {hashed: false})
6060

6161
const validb340 = bip340.verify(bytesToHex(result2), bytesToHex(utf8ToBytes(message)), bytesToHex(instance.getPubKeyBip340()));
6262
expect(validb340).eq(true);
6363

6464

6565
instance.addTssLibs([frostLib]);
66-
const result3 = await instance.signEd25519(Buffer.from(message))
66+
const result3 = await instance.signED25519(Buffer.from(message))
6767
const valided25519 = ed25519.verify(bytesToHex(result3), bytesToHex(Buffer.from(message)), bytesToHex( new Uint8Array(instance.getPubKeyEd25519()) ) )
6868
expect(valided25519).eq(true);
6969

0 commit comments

Comments
 (0)