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

Commit

Permalink
feat: ⬆️ upgrade secp256k1, solana wallet adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseTheRobot committed Sep 21, 2023
1 parent 31d5875 commit 83e4778
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"prepare": "yarn run ensure-build"
},
"devDependencies": {
"@solana/wallet-adapter-base": "^0.9.2",
"@solana/wallet-adapter-base": "^0.9.23",
"@types/bs58": "^4.0.1",
"@types/jest": "^29.2.5",
"@types/multistream": "^2.1.1",
Expand Down Expand Up @@ -142,7 +142,7 @@
"base64url": "^3.0.1",
"bs58": "^4.0.1",
"keccak": "^3.0.2",
"secp256k1": "^4.0.2"
"secp256k1": "^5.0.0"
},
"optionalDependencies": {
"@randlabs/myalgo-connect": "^1.1.2",
Expand Down
2 changes: 1 addition & 1 deletion src/signing/chains/InjectedTypedEthereumSigner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class InjectedTypedEthereumSigner extends InjectedEthereumSigner
private address: string;

async ready(): Promise<void> {
this.address = (await this.signer.getAddress()).toLowerCase();
this.address = (await this.signer.getAddress()).toString().toLowerCase();
this.publicKey = Buffer.from(this.address); // pk *is* address
}

Expand Down
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 secp256k1 from "secp256k1";
import { ecdsaVerify, publicKeyCreate } 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 = secp256k1.publicKeyCreate(b, false);
const pub = 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 secp256k1.ecdsaVerify(
return ecdsaVerify(
signature.length === 65 ? signature.slice(0, -1) : signature,
arrayify(hashMessage(message)),
typeof pk === "string" ? base64url.toBuffer(pk) : pk,
Expand Down
1 change: 1 addition & 0 deletions src/signing/chains/injectedSolanaSigner.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Signer } from "../index";
import base64url from "base64url";
import { SIG_CONFIG } from "../../constants";
// @ts-expect-error types
import type { MessageSignerWalletAdapter } from "@solana/wallet-adapter-base";
import { verify } from "@noble/ed25519";

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 secp256k1 from "secp256k1";
import { ecdsaSign, ecdsaVerify } 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 = secp256k1.ecdsaVerify(signature, keccak256(Buffer.from(message)), p as Buffer);
verified = 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 secp256k1.ecdsaSign(keccak256(Buffer.from(message)), Buffer.from(this.key)).signature;
return ecdsaSign(keccak256(Buffer.from(message)), Buffer.from(this.key)).signature;
}
}

0 comments on commit 83e4778

Please sign in to comment.