import {Identifier, Lsat} from 'lsat-js'
// can use any macaroon utility as long it follows lib-macaroon standard
import * as Macaroon from 'macaroon'
const identifier = new Identifier({
paymentHash: Buffer.from(paymentHash, 'hex'),
})
const macaroon = Macaroon.newMacaroon({
version: 1,
rootKey: signingKey,
identifier: identifier.toString(),
location: window.location.origin,
})
const lsat = Lsat.fromMacaroon(getRawMacaroon(macaroon), payreq)
lsat.toJSON()
import {Lsat} from 'lsat-js'
// challenge must be a base64 encodedstring
const lsat = Lsat.fromChallenge(challenge)
// Lsat.fromHeader(header) accomplishes the same thing
// for a challenge with the "LSAT" prefix, which describes
// the _type_ of challenge WWW-Authenticate challenge
lsat.toJSON()
import {Lsat} from 'lsat-js'
// challenge must be a base64 encoded string
const lsat = Lsat.fromToken(token)
lsat.toJSON()
import {Lsat} from 'lsat-js'
const lsat = Lsat.fromToken(token)
// throws if the preimage is malformed or does not match
lsat.setPreimage(secret)
lsat.toJSON()
import {Lsat} from 'lsat-js'
const lsat = Lsat.fromMacaroon(macaroon)
const caveat = Caveat.decode('test=success')
lsat.addFirstPartyCaveat(caveat)
lsat.toToken()
import {Lsat, Caveat} from 'lsat-js'
const lsat = Lsat.fromToken(token)
import {
Lsat,
expirationSatisfier,
verifyMacaroonCaveats
} from 'lsat-js'
const lsat = Lsat.fromToken(token)
// check if is expired based on (optional) expiration caveat
lsat.isExpired()
// checks LSAT preimage
lsat.isSatisfied()
// checks caveats are satisfied and macaroon signature is valid
verifyMacaroonCaveats(
lsat.baseMacaroon,
signingKey,
// must pass all satisfiers necessary for validation
expirationSatisfier
)
lsat.toJSON()
The LSATs generated here have an expiration caveat attached, giving you timed access (with some buffer) from the time of LSAT generation (not payment). Use the data derived from the response and displayed in the right column in the playground to check validity.