Skip to content

Instantly share code, notes, and snippets.

@afk11
afk11 / gist:a3f1174f30e1e8d9ed2d
Created May 23, 2014 01:44
Decompress bitcoin public keys (PHP)
// Decompressing a compressed bitcoin public key.
// Will require a big number library, with functions for modular exponent, square root (mod prime), and modulus.
// Requires gmp, and mathyass danters ecclib
public static function decompress_public_key($key)
{
$y_byte = substr($key, 0, 2);
$x_coordinate = substr($key, 2);
// Convert x hexadecimal to a decimal
@afk11
afk11 / gist:bbd9657b91e9a68d054f
Last active August 29, 2015 14:03
Print the time to wait before each pool has < 1% probability of producing a longer chain, based on current pool hashrates.
<?php
// Average block time in minutes.
$avg_block_time = file_get_contents("https://blockchain.info/q/interval")/60;
// Pools page..
$pools_page = file_get_contents("https://blockchain.info/pools?timespan=4days");
// Obtain the JSON string blockchain embeds in their page for the graph
$lines = explode("\n",$pools_page);
@afk11
afk11 / gist:a9d5198c205879c25c01
Created July 5, 2014 12:32
Bitcore BIP32 key deriv + raw transaction signing (not working at present)
<!DOCTYPE html>
<html>
<head>
<title>User Registration</title>
<script src="bitcorelatest.js"></script>
<script>
// Derive given private key index..
function get_bip32_key(path) {
@afk11
afk11 / gist:a3d3a661d499e1cf2dd7
Last active August 29, 2015 14:10
Bash script to take a screenshot and upload to a remote webhost
#!/bin/bash
mkdir /tmp/screenio
echo "Enter screenshot filename:"
read filename
scrot /tmp/screenio/$filename.png
scp /tmp/screenio/$filename.png thelab:/var/www/thomaskerin.io/uploads/
echo "Uploaded to https://thomaskerin.io/uploads/$filename.png"
echo ""
@afk11
afk11 / Scalar_mult_benchmarks.md
Last active June 11, 2016 16:32
PHPECC operation benchmarks

Without patch

Scalar mult benchmarks

Number of curves tested: 4
Number of iterations per curve: 500
secp256k1 --- Total: 23.179268121719 / Avg run: 0.046358536243439
nist-p192 --- Total: 15.343150854111 / Avg run: 0.030686301708221
nist-p256 --- Total: 23.433343887329 / Avg run: 0.046866687774658
nist-p521 --- Total: 73.456861019135 / Avg run: 0.14691372203827

Changelog

Fixed

  • Transaction & block versions are signed integers (#662)

Removed

  • Minimum node version: v0.4 (#750)
  • Removed buffer-equals/buffer-compare (#650)
  • Removed ecdsa.calcPubKeyRecoveryParam(), ecdsa.recoverPubKey() (#456)
  • Removed coin network: Dogecoin (#675)

Signing scripts with logical operators

Full script

HASH160 DUP <R-HASH> EQUAL
IF
    "24h" CHECKSEQUENCEVERIFY
    2DROP
    <Alice's pubkey>

ELSE

package wallet
import (
"bytes"
"github.com/btccom/mrsign/bip32util"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil"
@afk11
afk11 / bitcoinjs-signing.md
Last active September 6, 2017 15:55
BitcoinJS transaction signing internals - update, enhancements, to the moon

It starts with a Signer..

s = Signer(tx)

The signer lets you peek at InputSigners.

iS = s.input(nIn, txOut, [rs], [ws])

this step involves classification of
  • bare scriptPubKey: txOut
#!/usr/bin/env php
<?php
if ($argc < 1) {
die("missing directory");
} else if ($argv < 2) {
die("missing search string");
}
$dir = $argv[1];