Skip to content

Commit

Permalink
feat: update signature verification parsing (Vagabonds-Labs#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
brolag authored Nov 4, 2024
1 parent 40d8a3b commit 03ed761
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
6 changes: 3 additions & 3 deletions apps/web/src/providers/starknet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ export default function StarknetProvider({
}) {
const connectors = [
// TODO: add ArgentX
// new InjectedConnector({
// options: { id: "argentX" },
// }),
new InjectedConnector({
options: { id: "argentX" },
}),
new InjectedConnector({
options: { id: "braavos" },
}),
Expand Down
20 changes: 9 additions & 11 deletions apps/web/src/utils/signinWithStarknet.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Account, type Signature } from "starknet";
import { type TypedData, shortString } from "starknet";
import type { WeierstrassSignatureType } from "starknet";
import type { ArraySignatureType } from "starknet";

import {
CHAIN_ID,
DOMAIN_NAME,
Expand Down Expand Up @@ -29,15 +30,9 @@ export const createMessageStructure = (message: string): TypedData => ({
},
});

export const parseSignatureString = (
signatureString: string,
): WeierstrassSignatureType => {
export const parseSignatureString = (signatureString: string) => {
try {
const sig = signatureString.split(",");
return {
r: BigInt(sig[1] ?? 0),
s: BigInt(sig[2] ?? 0),
} as WeierstrassSignatureType;
return signatureString.split(",").map((s) => BigInt(s));
} catch (error) {
console.error(
"Error parsing signature:",
Expand Down Expand Up @@ -71,11 +66,14 @@ export const validateCredentials = (
export const verifySignature = async (
address: string,
message: TypedData,
signature: Signature,
signature: bigint[],
): Promise<boolean> => {
try {
const account = new Account(provider, address, SIGNER);
const isValid = await account.verifyMessage(message, signature);
const isValid = await account.verifyMessage(
message,
signature as unknown as ArraySignatureType,
);

return isValid;
} catch (error) {
Expand Down

0 comments on commit 03ed761

Please sign in to comment.