import {Identifier, Lsat} from 'lsat-js'
// can use any macaroon utility as long it follows lib-macaroon standard
import { MacaroonsBuilder } from 'macaroons.js'
const identifier = new Identifier({
paymentHash: Buffer.from(paymentHash, 'hex'),
})
const builder = new MacaroonsBuilder(
window.location.origin,
signingKey,
identifier.toString()
)
const lsat = Lsat.fromMacaroon(macaroon.serialize(), 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 encodedstring
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, Caveat} from 'lsat-js'
const lsat = Lsat.fromToken(token)
import {
Lsat,
expirationSatisfier,
verifyFirstPartyMacaroon
} 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
verifyFirstPartyMacaroon(
lsat.baseMacaroon,
signingKey,
// must pass all satisfiers necessary for validation
expirationSatisfier
)
lsat.toJSON()
The LSATs generated here have an expiration caveat attached, giving you ~40 seconds of 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.
Currently the demo is TESTNET ONLY.