Skip to content

Commit

Permalink
Merge pull request #59 from picketapi/devstein/better-error-messages
Browse files Browse the repository at this point in the history
Throw Errors on Missing Params for Creating Signing Message
  • Loading branch information
devstein authored Mar 1, 2023
2 parents 51a4297 + a0072e9 commit 37ea679
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@picketapi/picket-js",
"version": "0.0.99",
"version": "0.0.100",
"description": "Javascript client for the Picket API",
"main": "dist/index.mjs",
"types": "dist/index.d.ts",
Expand Down
12 changes: 12 additions & 0 deletions src/connect/ConnectModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,18 @@ const getErrorMessage = ({
if (err.msg.toLowerCase().includes("invalid project key")) {
return "Invalid API key. Copy your project's publishable key from your Picket dashboard: https://picketapi.com/dashboard";
}
if (
err.msg
.toLowerCase()
.includes("required to create a SIWE signing message")
) {
return "Missing required context parameters for SIWE";
}
if (
err.msg.toLowerCase().includes("required to create a signing message")
) {
return "Missing required parameters to create a signing message";
}
// @ts-ignore TS isn't respecting "msg" in err
if (err.msg.toLowerCase().includes("invalid signature")) {
return "Signature expired. Please try again.";
Expand Down
32 changes: 32 additions & 0 deletions src/picket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,17 @@ export class Picket {

static createSigningMessage(args: SigningMessageRequest) {
const { format = SigningMessageFormat.SIMPLE } = args;

if (!args.nonce) {
throw new Error("'nonce' is required to create a signing message");
}

if (!args.walletAddress) {
throw new Error(
"'walletAddress' is required to create a signing message"
);
}

if (format === SigningMessageFormat.SIMPLE) {
const { statement, walletAddress, nonce } =
args as SigningMessageRequestSimple;
Expand All @@ -690,6 +701,27 @@ export class Picket {
chainType,
} = args as SigningMessageRequestSIWE;

// validate parameters
if (!statement) {
throw new Error(
"'statement' is required to create a SIWE signing message"
);
}
if (!domain) {
throw new Error("'domain' is required to create a SIWE signing message");
}
if (!uri) {
throw new Error("'uri' is required to create a SIWE signing message");
}
if (!issuedAt) {
throw new Error(
"'issuedAt' is required to create a SIWE signing message"
);
}
if (!chainId) {
throw new Error("'chainId' is required to create a SIWE signing message");
}

const message = new SiweMessage({
address: walletAddress,
nonce,
Expand Down

0 comments on commit 37ea679

Please sign in to comment.