Skip to content

Instantly share code, notes, and snippets.

View junderw's full-sized avatar

Jonathan Underwood junderw

  • Tokyo, Japan
  • 16:18 (UTC +09:00)
View GitHub Profile
@junderw
junderw / cold-key-BOLT.md
Created April 7, 2017 03:31
This BOLT is a recommendation on how to support cold key storage methods to allow for larger amounts of locked funds to be safely stored in channels with minimized risk when the machine is compromised.

BOLT #N: Recommendations for Cold Storage of Keys

Abstract

For Lightning nodes (especially nodes set up explicitly for earning money routing payments) to work properly, they should have the signing keys for their part of the 2-of-2 multisig script available to their node at all times in order to sign.

This makes it nearly impossible for someone to run a 24/7 lightning node using cold keys without sacrificing transaction throughput to the speed a human can perform their cold signing steps.

Motivation

// npm install git://github.com/bitcoinjs/bitcoinjs-lib.git#56dfb873d3f05817e19befa976592bc0f371a6d3
// installing the above commit of bitcoinjslib will allow you to take the var redeemScript and
// create a bech32 raw segwit address with this function:
// var bech32address = bitcoin.address.fromOutputScript(redeemScript)
var bitcoin = require('bitcoinjs-lib')
var mnemonic = require('bip39')
// log output near bottom
function main() {
// mnemonic seed starts here
var seed = mnemonic.mnemonicToSeed('print common jewel hospital hip fish auction indicate depth ignore ship tissue')
@junderw
junderw / convertSegwit.js
Created September 6, 2017 06:41
Convert all your existing addresses from bitcoind to segwit P2SH addresses (multisig will not work)
'use strict';
// first, run sudo apt-get install jq nodejs npm
// second, run npm install bluebird co to install dependencies, and make sure bitcoin-cli can run these commands.
// third, run node thisScript.js and it will change all the addresses on your bitcoind into segwit addresses.
var Promise = require('bluebird');
var co = require('co');
var exec = Promise.promisify(require('child_process').exec);
var main = function() {
@junderw
junderw / pbkdf2.js
Created May 6, 2018 07:07
pbkdf2 for modern browsers' JavaScript
async function pbkdf2(message, salt, iterations, keyLen, algorithm) {
const msgBuffer = new TextEncoder('utf-8').encode(message)
const msgUint8Array = new Uint8Array(msgBuffer)
const saltBuffer = new TextEncoder('utf-8').encode(salt)
const saltUint8Array = new Uint8Array(saltBuffer)
const key = await crypto.subtle.importKey('raw', msgUint8Array, { name: 'PBKDF2' }, false, ['deriveBits'])
const buffer = await crypto.subtle.deriveBits({ "name": 'PBKDF2', "salt": saltUint8Array, "iterations": iterations, "hash": algorithm }, key, keyLen * 8)
const hashArray = Array.from(new Uint8Array(buffer))
const hashHex = hashArray.map(b => ('00' + b.toString(16)).slice(-2)).join('')
return hashHex
@junderw
junderw / .bashrc
Created June 16, 2018 03:03
Function for adding keybase subteam
make_keybase_subteam(){
# usage:
# make_keybase_subteam myteam newsubteam
# creates the subteam, sets good defaults, then turns it into a big team.
# will automatically join subteam.
if [ -z "$1" ]; then
echo "need to specify team name"
return 1
else
@junderw
junderw / csp.js
Created July 6, 2018 06:27
An efficient way of writing CSP directives in NodeJS using template literals. (You can copy and paste URLs, domains, whatever from excel sheet columns and vice versa)
const CSP_DIRECTIVES = `
default-src
'self'
;
object-src
'none'
;
report-uri
someURL
@junderw
junderw / lightning_handson_JP.sh
Last active September 25, 2018 09:04
Bitcoin TestnetのDockerを先ず始めてみましょう。
# これを実行して lnd を起動
LIST=(\
188.166.148.62:18333 \
159.203.125.125:18333 \
); \
INDEX=$((RANDOM % 2)); \
NODE=${LIST[$INDEX]}; \
docker run -d \
-v /tmp/lndock:/root/.lnd \
-v /tmp/lndockdata:/data \
@junderw
junderw / createNewRegtestServer.sh
Last active November 19, 2018 09:33
Simple setup for Ubuntu 18.04 server
### new ubuntu 18.04 server
### Be sure to run
# sudo apt-get update && sudo apt-get -y upgrade && sudo reboot
### For security updates
### Then run this script with passwordless sudo account ubuntu (default for ubuntu AWS EC2):
# CERTDOMAIN=something.yourdomain.com CERTEMAIL=mailname@yourdomain.com ./thisScript.sh
# Install Bitcoin 0.17.0 etc.
sudo add-apt-repository -y ppa:bitcoin/bitcoin &>/dev/null
sudo apt-get update &>/dev/null
@junderw
junderw / create_dockers.sh
Created February 8, 2018 02:51
lndのDockerを利用して、A <> B <> C の2チャンネル構成を構築するためのスクリプト
#!/bin/bash
# docker, docker-compose, bash, jq, sed 必要。
# このスクリプトはLinuxで作られたので、各コマンドの細かい使い方が違ってたらすみません。
# OSXは使ったことないので。。。
#
# lndのgithubをクローンしないといけません。例えば:
#
# rm -rf /tmp/lndtest
# mkdir -p /tmp/lndtest
@junderw
junderw / nordvpnconnect.sh
Created December 29, 2018 16:11
NordVPN: JPN or USA to connect to the country you want.
#!/bin/bash
SELECTION=$1
if [ -z "$1" ]
then
SELECTION="JPN"
fi
# Default JPN
CODE=108