Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Commit

Permalink
fix: 🚑 Namespace secp256k1
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseTheRobot committed Sep 22, 2023
1 parent c54c849 commit 4c90af5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/signing/chains/ethereumSigner.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Secp256k1 from "../keys/secp256k1";
import { ecdsaVerify, publicKeyCreate } from "secp256k1";
import secp256k1 from "secp256k1";
import base64url from "base64url";
import { arrayify } from "@ethersproject/bytes";
import { Wallet } from "@ethersproject/wallet";
Expand All @@ -13,7 +13,7 @@ export default class EthereumSigner extends Secp256k1 {
constructor(key: string) {
if (key.startsWith("0x")) key = key.slice(2);
const b = Buffer.from(key, "hex");
const pub = publicKeyCreate(b, false);
const pub = secp256k1.publicKeyCreate(b, false);
super(key, Buffer.from(pub));
}

Expand All @@ -27,7 +27,7 @@ export default class EthereumSigner extends Secp256k1 {
static async verify(pk: string | Buffer, message: Uint8Array, signature: Uint8Array): Promise<boolean> {
// const address = ethers.utils.computeAddress(pk);
// return ethers.utils.verifyMessage(message, signature) === address;
return ecdsaVerify(
return secp256k1.ecdsaVerify(
signature.length === 65 ? signature.slice(0, -1) : signature,
arrayify(hashMessage(message)),
typeof pk === "string" ? base64url.toBuffer(pk) : pk,
Expand Down
6 changes: 3 additions & 3 deletions src/signing/keys/secp256k1.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Signer } from "../Signer";
import base64url from "base64url";
import { ecdsaSign, ecdsaVerify } from "secp256k1";
import secp256k1 from "secp256k1";
import { SignatureConfig, SIG_CONFIG } from "../../constants";
import keccak256 from "../keccak256";

Expand All @@ -27,13 +27,13 @@ export default class Secp256k1 implements Signer {
if (typeof pk === "string") p = base64url.toBuffer(pk);
let verified = false;
try {
verified = ecdsaVerify(signature, keccak256(Buffer.from(message)), p as Buffer);
verified = secp256k1.ecdsaVerify(signature, keccak256(Buffer.from(message)), p as Buffer);
// eslint-disable-next-line no-empty
} catch (e) {}
return verified;
}

async sign(message: Uint8Array): Promise<Uint8Array> {
return ecdsaSign(keccak256(Buffer.from(message)), Buffer.from(this.key)).signature;
return secp256k1.ecdsaSign(keccak256(Buffer.from(message)), Buffer.from(this.key)).signature;
}
}

0 comments on commit 4c90af5

Please sign in to comment.