Skip to content

Instantly share code, notes, and snippets.

View matiu's full-sized avatar

ematiu matiu

  • Bitpay Inc.
  • Tucuman, Argentina
View GitHub Profile
var b = require('bitcore');
var priv = new b.PrivateKey();
var pub = new b.PublicKey(priv);
var inputs =
[ { txid: 'e872a0fda0afd0bce31ddfd9229c9eca2a68e4746615b8a0902b7a657b83676d',
vout: 8,
amount: 100,
scriptPubKey: b.Script.buildPublicKeyHashOut(pub).toBuffer().toString('hex') } ] ;

Client / Sign and extract DER

var clientSign = function(tx, xpriv, n) {
  //Derive proper key to sign, for each input
  var privs = [],
    derived = {};
  var xpriv = new Bitcore.HDPrivateKey(someXPrivKey[0]);

  _.each(tx.inputs, function(i) {
@matiu
matiu / gist:3663f71080002321de9b
Last active August 29, 2015 14:15
bit wallet

Normal Operation

bit create myWallet 2-3
bit address
bit send <>

Hoy

  var storage = new Client.FileStorage({
    filename: args.file || process.env['BIT_FILE'],
  });
  var c = new Client({
    storage: storage,
    baseUrl: args.host || process.env['BIT_HOST'],
    verbose: args.verbose,
  });
@matiu
matiu / gist:50eb38b77f03284a5cc9
Last active August 29, 2015 14:16
BWS access schema

BWS Access Control

There are 3 tiers of access control

  1. Access is controlled at the server

All requests to an existing wallet must be signed by a private key and are verified by the server. All copayers have a always valid private key, m/1/1, and can generate more with restricted access thru the grantAccess removeAccess API.

Extra access keys pairs are always derived from the extended master private key using m/1/x.

  • createTX
    • output: 1bitcoin
    • amount: 1BTC
    • useCoinJoin: true
      • coinJoinToSignTimeout: 1hr
      • coinJoinToBroadcastTimeout: 24hr
      • coinJoinTimeoutPolicy: broadcastWithoutCoinJoin | rejectByServer
@matiu
matiu / gist:61c9f529efeeba66c0e2
Created June 3, 2015 17:35
How to verify Copay file signatures
  1. Download signature file
  2. Check it by running:
$ gpg --verify \
 $FILENAME.sig \
 $FILENAME

# If should say:

 "Good signature from "Copay (visit copay.io) "
@matiu
matiu / gist:f7b4afb3781c9f7c735435f19602db31
Last active June 23, 2021 21:21
Test new opcodes - bitcoin Cash
  1. run bitcoin-abc with: ./bitcoind -regtest -monolithactivationtime=0
  2. create some UTXOs: ./bitcoin-cli generate 100
  3. grab one UTXO: ./bitcoin-cli listunspent (grab the last TXIDs, vout; we will call them here: TXID: 64be40b2688e8767fc62f8556d3b9ee608aae28894b867f8228ac5aa74325aff vout: 0
  4. create a TX with the script you want to test, using P2SH: bitcoin-tx -regtest -json -create in=64be40b2688e8767fc62f8556d3b9ee608aae28894b867f8228ac5aa74325aff:0 outscript=49.999:"XOR 1 DUP":S (last :S is to use P2SH) => hex: 0200000001ff5a3274aac58a22f867b89488e2aa08e69e3b6d55f862fc67878e68b240be640000000000ffffffff01606b042a0100000017a9145944649bbd7f8d554b993e74f7b7884d2c78a2908700000000
  5. sign it:
Using bitcoin-abc 0.17 hash: 855043153da2d7d5d4d577eede5ecf22f2c87080,
running bitcoind with: `-regtest -monolithactivationtime=0`
1. Base line
- send 10 p2pkh TX/s, 10 seconds. Check CPU and IO load.
- send 10 (small) op_ret TX/s, 100 seconds. Check CPU and IO load and mem usage.
2. Tests
@matiu
matiu / csp.md
Created November 29, 2018 14:56
Copay and Bitpay Wallet Network Restrictions

To prevent unautorized network access, Copay and Bitpay Wallet v5.3.0 and above use the following Content Security Policy (CSP)

  <meta http-equiv="Content-Security-Policy" content="default-src 'self' 'unsafe-eval' https://bws.bitpay.com
  https://bitpay.com https://auth.shapeshift.io https://shapeshift.io https://api.coinbase.com https://coinbase.com; 
  img-src 'self' data:; style-src 'self' 'unsafe-inline'; font-src 'self' data:">

This restrict network connections to the listed hosts only. As a consecuence, accessing self-hosted Bitcore Wallet Service (BWS) hosts will not be allowed.