Skip to content

Commit

Permalink
Default value for issuedAt (spruceid#134)
Browse files Browse the repository at this point in the history
* Default issuedAt to now if none

* Bump version

* Move issuedAt generation to toMessage function

* Mark option as optinal

* Fix issuedAt assignment
  • Loading branch information
w4ll3 authored Oct 24, 2022
1 parent a9c707e commit 053f16b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
20 changes: 9 additions & 11 deletions package-lock.json

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

9 changes: 6 additions & 3 deletions packages/siwe/lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class SiweMessage {
* characters. */
nonce: string;
/**ISO 8601 datetime string of the current time. */
issuedAt: string;
issuedAt?: string;
/**ISO 8601 datetime string that, if present, indicates when the signed
* authentication message is no longer valid. */
expirationTime?: string;
Expand Down Expand Up @@ -112,6 +112,7 @@ export class SiweMessage {
const suffixArray = [uriField, versionField, chainField, nonceField];

this.issuedAt = this.issuedAt || new Date().toISOString();

suffixArray.push(`Issued At: ${this.issuedAt}`);

if (this.expirationTime) {
Expand Down Expand Up @@ -411,8 +412,10 @@ export class SiweMessage {
}

/** `issuedAt` conforms to ISO-8601 and is a valid date. */
if (!isValidISO8601Date(this.issuedAt)) {
throw new Error(SiweErrorType.INVALID_TIME_FORMAT);
if(this.issuedAt) {
if (!isValidISO8601Date(this.issuedAt)) {
throw new Error(SiweErrorType.INVALID_TIME_FORMAT);
}
}

/** `expirationTime` conforms to ISO-8601 and is a valid date. */
Expand Down
11 changes: 6 additions & 5 deletions packages/siwe/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 packages/siwe/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "siwe",
"version": "2.1.2",
"version": "2.1.3",
"description": "Sign-In with Ethereum",
"main": "dist/siwe.js",
"types": "dist/siwe.d.ts",
Expand Down

0 comments on commit 053f16b

Please sign in to comment.