Skip to content

Instantly share code, notes, and snippets.

View cmdruid's full-sized avatar
💭
Looking to contribute

cmd cmdruid

💭
Looking to contribute
  • Freelance
  • Austin, TX
  • 03:57 (UTC -06:00)
View GitHub Profile
@cmdruid
cmdruid / filter.ts
Last active October 10, 2024 13:04
Nostr Event Filter Example
/** Basic implementation of NIP 01 filters in typescript. */
interface Event {
id : string
kind : number
created_at : number
pubkey : string
subject ?: string
content : string
sig : string
@cmdruid
cmdruid / asyncPipe.ts
Last active December 30, 2022 00:17
ES6 Asynchronous Pipe Function, in Typescript
// Useful for type-checking your pipe middleware.
export type PipeMethod<T> = (input : T) => Promise<T>
// Return type for the pipe method.
type PipeReturn<T> = (input: T, catcher: Function) => Promise<PipeOutput<T>>
// Object returned by the pipe method.
interface PipeOutput<T> {
errors: unknown[];
output: T
@cmdruid
cmdruid / cloudflare-worker.js
Last active September 5, 2024 13:59
Import a (modified) NostrEmitter into a Cloudlfare Worker
/* Cloudflare Worker Script */
import NostrEmitter from './emitter.js'
const delay = (ms = 1000) => new Promise((r, _) => setTimeout(r, ms))
export default {
async fetch(request) {
let cache
const emitter = new NostrEmitter()
@cmdruid
cmdruid / ripemd160.js
Created October 20, 2022 21:57
Pure Javascript version of ripemd160 algorithm.
// Copyright (c) 2021 Pieter Wuille
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
// Revised and converted to Javascript by Christopher Scott.
function bytesToBigInt(bytes) {
let num = 0n
for (let i = bytes.length - 1; i >= 0; i--) {
num = (num * 256n) + BigInt(bytes[i])
}
@cmdruid
cmdruid / letsencrypt.example.com
Created June 28, 2022 19:49
Example letsencrypt nginx configuration for lightning node.
server {
listen 443 ssl;
listen [::]:443 ssl ipv6only=on;
listen example.com:9735 ssl;
listen example.com:9737 ssl;
server_name example.com;
@cmdruid
cmdruid / simpleCrypto.mjs
Created June 12, 2022 19:14
A simple library for symmetric encryption / decryption using the standard WebCrypto module.
import { webcrypto as crypto } from 'crypto';
const IV_LENGTH = 16, // Length of init vector.
SECRET_KEY = process.env.SECRET_KEY;
let cryptoKey; // Cached CryptoKey object.
export async function encrypt(plaintext) {
/* Encrypt a string using the server's encryption key. */
const ec = new TextEncoder(),
@cmdruid
cmdruid / jgrep.sh
Last active May 2, 2022 04:59
Simple script that extracts the value for a given key within a JSON output.
#!/bin/sh
## Takes an input pipe of JSON, and outputs the value for a given key.
set -e
usage() {
printf "
Takes an input pipe of JSON, and outputs the value for a given key. \n
Usage: some_JSON_output | jgrep key \n
"
@cmdruid
cmdruid / onionport.sh
Created April 18, 2022 07:05
Forward traffic from a local port to an onion address.
#!/bin/sh
## Bind a local port and forward its traffic to an onion address.
## Requires socat to be installed, and a tor proxy to be running.
###############################################################################
# Environment
###############################################################################
SOCKS_HOST="127.0.0.1"
SOCKS_PORT="9050"
@cmdruid
cmdruid / lndconnect_sample.sh
Created April 18, 2022 05:12
Format credentials as lndconnect URL and generate QR code.
#!/bin/sh
## Format credentials as lndconnect URL and generate QR code.
## Requires qrencode package.
HOST_ADDR="ADDRESS:PORT"
HOST_CERT=`cat /path/to/certificate.pem | sed '1d;$d' | tr -d '=' | tr '/+' '_-' | tr -d '\n'`
MACAROON=`base64 /path/to/access.macaroon | tr -d '=' | tr '/+' '_-' | tr -d '\n'`
echo "lndconnect://$HOST_ADDR?cert=$HOST_CERT&macaroon=$MACAROON" | qrencode -o /path/to/save/qrcode.png
@cmdruid
cmdruid / rpcauth.sh
Last active April 21, 2022 03:09
POSIX compliant script for generating Bitcoin RPC credentials.
#!/bin/sh
## POSIX compliant script for generating Bitcoin RPC credentials.
## Requires xxd and openssl packages to be installed.
## Distributed under the MIT software license.
###############################################################################
# Environment
###############################################################################
RPCAUTH_USER="bitcoin"