ceramic-cacao
Advanced tools
Comparing version 0.0.6 to 0.0.7
@@ -12,5 +12,5 @@ import * as multiformats from 'multiformats'; | ||
nonce: string; | ||
iat: number; | ||
nbf?: number; | ||
exp?: number; | ||
iat: string; | ||
nbf?: string; | ||
exp?: string; | ||
statement?: string; | ||
@@ -29,3 +29,3 @@ requestId?: string; | ||
export declare type VerifyOptions = { | ||
atTime?: number; | ||
atTime?: number | string; | ||
}; | ||
@@ -32,0 +32,0 @@ export declare namespace Cacao { |
@@ -45,3 +45,3 @@ "use strict"; | ||
domain: siweMessage.domain, | ||
iat: Date.parse(siweMessage.issuedAt), | ||
iat: siweMessage.issuedAt, | ||
iss: `did:pkh:eip155:${siweMessage.chainId}:${siweMessage.address}`, | ||
@@ -59,6 +59,6 @@ aud: siweMessage.uri, | ||
if (siweMessage.notBefore) { | ||
cacao.p.nbf = Date.parse(siweMessage.notBefore); | ||
cacao.p.nbf = siweMessage.notBefore; | ||
} | ||
if (siweMessage.expirationTime) { | ||
cacao.p.exp = Date.parse(siweMessage.expirationTime); | ||
cacao.p.exp = siweMessage.expirationTime; | ||
} | ||
@@ -89,7 +89,15 @@ if (siweMessage.statement) { | ||
} | ||
const atTime = options.atTime ? options.atTime : Date.now(); | ||
if (cacao.p.iat > atTime || cacao.p.nbf > atTime) { | ||
let atTime = Date.now(); | ||
if (options.atTime) { | ||
if (typeof options.atTime === 'string') { | ||
atTime = Date.parse(options.atTime); | ||
} else { | ||
// Assuming options.atTime is a UNIX timestamp with seconds-precision | ||
atTime = options.atTime * 1000; | ||
} | ||
} | ||
if (Date.parse(cacao.p.iat) > atTime || Date.parse(cacao.p.nbf) > atTime) { | ||
throw new Error(`CACAO is not valid yet`); | ||
} | ||
if (cacao.p.exp < atTime) { | ||
if (Date.parse(cacao.p.exp) < atTime) { | ||
throw new Error(`CACAO has expired`); | ||
@@ -96,0 +104,0 @@ } |
{ | ||
"name": "ceramic-cacao", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "Typescript library for Ceramic OCAP", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
76922
782