Skip to content

Instantly share code, notes, and snippets.

import math
def mergesort(arr, helper=None, low=0, high=None):
print(arr, helper, low, high)
if high == None:
print("Setting high...")
high = len(arr) - 1
if helper is None:
print("Setting helper...")
import math
def search(l, term, offset=0):
# find the middle
# find length of list and divide by two
list_len = len(l)
if list_len <= 0:
return None
middle = math.floor(list_len / 2)
@tgoldenberg
tgoldenberg / index.js
Last active November 21, 2018 19:41
Proof of Concept for a KYC provider digital currency
/**
* Proof of concept for a KYC-enabled digital currency
* In short, a user submits their information to a KYC provider (Oracle) along with proof of identity (similar to Jumio, etc.)
* KYC provider provides signature for the user's identity.
*
* The user can then share pieces of the identity with the relevant
* signature for transactions. This logic can even be part of the transaction validation logic of the digital currency.
* What follows is just a simple example that can be run via NodeJS.
*/
@tgoldenberg
tgoldenberg / tx.md
Last active February 21, 2021 17:33
Description of Bitcoin Transactions

Transaction (Tx)

Name Description
vin list of inputs
vout list of outputs

Input

Name Description
@tgoldenberg
tgoldenberg / ecdsaExample.js
Last active February 21, 2021 17:34
Example of Elliptic Curve Digital Signature Algorithm
const RIPEMD160 = require('ripemd160');
const EC = require('elliptic').ec;
const sha256 = require('js-sha256');
const ec = new EC('secp256k1'); // Bitcoin uses Elliptic Curve Digital Signing Algorithm (ECDSA) to verify transactions
let message = 'I want to send this money'; // This would normally be the transaction hash with amount of money, publicScriptKey
let publicKey = '040c1fbe8b870d636823963ff21ba6e5250571848714203a08ae8700e0d97a1d7bb94ae888af72ac9a4fe02d558599d27c8986398902fa9ac0c1654f5839db1af5';
let privateKey = '2ec6d2808dc7b9d11e49516cfc747435feae8e9872d63c92bc5bde68a894199f';
@tgoldenberg
tgoldenberg / addresses.js
Created April 10, 2018 20:34
ECC Addresses
const secureRandom = require('secure-random');
const ec = require('elliptic').ec;
const ecdsa = new ec('secp256k1');
function generateAddress() {
const max = Buffer.from("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364140", 'hex');
let isInvalid = true;
let privateKey;
while (isInvalid) {
@tgoldenberg
tgoldenberg / tcp_ip.js
Created April 10, 2018 02:44
Basic networking
const net = require('net');
const network = require('network');
const uuid = require('uuid');
const SHA256 = require('js-sha256');
const port = parseInt(process.env.PORT);
function handleConnection(conn) {
console.log('> New client connection: ', conn.remoteAddress, conn.remotePort);
conn.setEncoding('utf8');
@tgoldenberg
tgoldenberg / blockstack
Created March 31, 2018 14:41
blockstack
Verifying my Blockstack ID is secured with the address 1BWE9yVyk8hvDfoKCqMSSLQ6UvE7veo1yN https://explorer.blockstack.org/address/1BWE9yVyk8hvDfoKCqMSSLQ6UvE7veo1yN
@tgoldenberg
tgoldenberg / messageEncryption.js
Last active March 24, 2018 02:57
Encrypt messages with ECIES
import decode from 'jwt-decode';
import jwt from 'njwt';
import { ec } from 'elliptic';
var eccrypto = require('eccrypto');
var crypto = require('crypto');
// sender
var privKey1 = crypto.randomBytes(32);
var pubKey1 = eccrypto.getPublic(privKey1);
@tgoldenberg
tgoldenberg / startMining.js
Created March 18, 2018 16:57
function that initiates mining for a new block
import BlockClass from 'classes/Block';
import BlockModel from 'models/Block';
import SHA256 from 'js-sha256';
import { isNodeSynced } from 'net/isNodeSynced';
import { isTxValid } from 'utils/validateBlock';
import request from 'utils/request';
import store from 'store/store';
const MIN_TX_PER_BLOCK = 1;