import config from "$config"; import { fail, getUser } from "$lib/utils"; import fastifyPassport from "@fastify/passport"; import jwt from "passport-jwt"; export const admin = { preValidation: fastifyPassport.authenticate( "jwt", { session: false }, (req, res, err, user, info) => { if (!user.admin) return res.code(401).send("unauthorized"); req.user = user; }, ), }; export const optional = { preValidation: fastifyPassport.authenticate( "jwt", { session: false }, (req, res, err, user, info) => { req.user = user; }, ), }; export const auth = { preValidation: fastifyPassport.authenticate("jwt", { authInfo: false, session: false, }), }; export const requirePin = async ({ body, user }) => { if (!user || (user.pin && user.pin !== body.pin)) fail("Invalid pin"); }; export const jwtStrategy = new jwt.Strategy( { jwtFromRequest: jwt.ExtractJwt.fromExtractors([ jwt.ExtractJwt.fromAuthHeaderAsBearerToken(), (req) => (req.cookies ? req.cookies.token : null), ]), secretOrKey: config.jwt, passReqToCallback: true, }, async (req, payload, next) => { const { originalUrl: u, method: m } = req; let { id } = payload; const wl = { GET: ["/invoice", "/payments"], POST: ["/invoice"] }; if (id.endsWith("-ro") && wl[m].some((p) => u.startsWith(p))) id = id.slice(0, -3); const user = await getUser(id); next(null, user); }, ); coinos server — legacy coinos.io backend (Lightning, on-chain, Liquid)coinos
aboutsummaryrefslogtreecommitdiffstats
path: root/bcore.js
blob: f33451b224d6059333d1600db55ab8786c6af671 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import bitcoin from 'bitcoinjs-lib'
import Bitcoin from 'bitcoin-core'
import zmq from 'zeromq'

const sock = zmq.socket('sub')

;(async () => {
  let b = new Bitcoin({
    username: 'adam',
    password: 'MPJzfq97',
    port: 18332,
  })
  let res = await b.getBlockCount()
  console.log(res)

  sock.connect('tcp://127.0.0.1:18502')
  sock.subscribe('rawtx')
  sock.on('message', (t, m) => {
    let tx = bitcoin.Transaction.fromBuffer(m)
    console.log(tx)
  })
})()