Giter VIP home page Giter VIP logo

brave-payments-tools's Introduction

brave-payments-tools (Deprecated)

Based on this blog post, and similar to the BitGo cli tool, but tailored more for batch-like operations.

To emphasize:

  • files are transferred between the cold machine and the networked machine via USB stick;

  • after one-time configuration, the cold machine is never connected to the network; and,

  • recovery files are distributed to N trusted actors via USB stick, with at least M trusted actors required to co-operate in order to recovery the passphrases for the private keys.

Originally this tool worked for Bitcoin wallets using the BitGo API; the current invocation of this tool also works for BAT wallets using the Uphold API.

BAT/Uphold

Creating a Wallet

To summarize:

  1. A keypair is created on the cold machine, the private key are encrypted with a user-supplied passphrase, a keychains file is prepared for the networked machine, and (partial) recovery files are generated for distribution.

  2. The keychains file is used by the networked machine to create an protected wallet on the Uphold server.

On the Cold Machine

% bin/offline-create-keychains
prompt: User Keychain passphrase: ******

wrote keychains-779826ce-a74f-4d61-907a-0d238db9808f.json
wrote recovery_0_2_3-779826ce-a74f-4d61-907a-0d238db9808f.json
wrote recovery_1_2_3-779826ce-a74f-4d61-907a-0d238db9808f.json
wrote recovery_2_2_3-779826ce-a74f-4d61-907a-0d238db9808f.json

The passphrase is used to encrypt the private key for the user keychain. A strong password must be used for each (Requiring at least 10^17 guesses according to zxcvbn.) Private keys are encrypted using

sjcl.encrypt(passPhrase, privateKey, { iter: 100000, ks: 256, salt: sjcl.random.randomWords(2, 0) })

The keychains file is kept on the cold machine and transferred to the networked machine, e.g.,

{
  "userKey": {
    "label": "user",
    "xpub": "73932b241ff10386f467fc2ba5ca8ee75e72efdad2ba505488b0be0a315d04b9",
    "encryptedXprv": "...",
    "payload": {
      "requestType": "httpSignature",
      "signedTx": {
        "headers": {
          "digest": "SHA-256=od4jPanrP3J+emLcom2IhZ481Sfc0rJ77AmH+JTYoxc=",
          "signature": "...",
        },
        "body": {
          "label": "publisher-settlement-001",
          "currency": "BAT",
          "publicKey": "73932b241ff10386f467fc2ba5ca8ee75e72efdad2ba505488b0be0a315d04b9"
        },
        "octets": "..."
      }
    }
  },
  "config": {
    "env": "prod"
  }
}

The recovery files are immediately copied to N different USB sticks and then "securely" deleted from the cold machine. These recovery files can be used to reconstruct the user key using Shamir's threshold secret sharing scheme.

On the Networked Machine

% bin/online-create-wallet \
    --keychains keychains-779826ce-a74f-4d61-907a-0d238db9808f.json
prompt: OTP: ...
prompt: Application access-token: ...

wrote wallet-779826ce-a74f-4d61-907a-0d238db9808f.json

The wallet file has no sensitive information, and is kept on the networked machine, e.g.,

{
  "config": {
    "env": "prod"
  },
  "label": "publisher-settlement-001",
  "authenticate": {},
  "wallet": {
    "id": "5f83690f-5b25-40f5-820d-d0607cd0df12",
    "label": "publisher-settlement-001",
    "currency": "BAT"
  }
}

Submitting a Transaction

To summarize:

  1. A payments file is prepared on the networked machine, e.g.,

     [
       {
         "publisher": "homespun.io",
         "altcurrency": "BAT",
         "probi": "8508274545667666166",
         "fees": "447803923456192956",
         "authority": "github:mrose17",
         "transactionId": "c7f33832-6db8-4ee3-98dc-ff7b1c12f9bb",
         "address": "09633c3d-1470-4ca5-ac48-df825164f6df",
         "currency": "USD"
       },
       ...
     ]
    

    which contains a list of publisher settlements

  2. An unsigned transaction is created, and then transferred to the cold machine.

  3. On the cold machine, the transaction is signed (requiring the operator to enter the passphrase for the keypair's private key).

  4. The signed transaction is then transferred to the networked machine and submitted to the BitGo server.

On the Networked Machine

% bin/online-create-transaction \
    --wallet wallet-779826ce-a74f-4d61-907a-0d238db9808f.json \
    --payments payments-batch1.json 
prompt: OTP: ...
prompt: Application access-token: ...

wrote unsigned-batch1.json

This file is then transferred to the cold machine, e.g.,

{
  "config": {
    "env": "prod"
  },
  "unsignedTxs": [
    {
      "denomination": {
        "amount": "8.508274545667666166",
        "currency": "BAT"
      },
      "destination": "09633c3d-1470-4ca5-ac48-df825164f6df",
      "message": "c7f33832-6db8-4ee3-98dc-ff7b1c12f9bb",
      "id": "5f83690f-5b25-40f5-820d-d0607cd0df12",
      "label": "publisher-settlement-001"
    },
    ...
  ],
  "authenticate": {}
}

On the Cold Machine

% bin/offline-sign-transaction \
    --unsignedTx unsigned-batch1.json
prompt: User Keychain passphrase: ******

wrote signed-batch1.json

This file is then transferred to the networked machine, e.g.,

{
  "config": {
    "env": "test"
  },
  "signedTxs": [
    {
      "id": "5f83690f-5b25-40f5-820d-d0607cd0df12",
      "requestType": "httpSignature",
      "signedTx": {
        "headers": {
          "digest": "SHA-256=Cuv9iXCLZWSJ18Zo1wJkE/b1xhUEpBpySbYKC95yfEA=",
          "signature": "..."
        },
        "body": {
          "denomination": {
            "amount": "8.508274545667666166",
            "currency": "BAT"
          },
          "destination": "09633c3d-1470-4ca5-ac48-df825164f6df",
          "message": "c7f33832-6db8-4ee3-98dc-ff7b1c12f9bb"
        },
        "octets": "..."
      }
    },
    ...
  ],
  "authenticate": {}
}

On the Networked Machine

% bin/online-submit-transaction \
    --signedTx signed-batch1.json
prompt: OTP: ...
prompt: Application access-token: ...

wrote submit-batch1.json

The resulting file may be archived, e.g.,

[
  {
    "publisher": "homespun.io",
    "altcurrency": "BAT",
    "probi": "8508274545667666166",
    "fees": "447803923456192956",
    "authority": "github:mrose17",
    "transactionId": "c7f33832-6db8-4ee3-98dc-ff7b1c12f9bb",
    "address": "09633c3d-1470-4ca5-ac48-df825164f6df",
    "currency": "USD",
    "status": "completed",
    "message": "c7f33832-6db8-4ee3-98dc-ff7b1c12f9bb",
    "hash": "58361892-b073-464d-a7df-c9741ab9c8bd",
    "walletId": "5f83690f-5b25-40f5-820d-d0607cd0df12",
    "tx": "...",
    "amount": "1.57",
    "commission": "0.04",
    "fee": "0.00"
  },
  ...
]

The payments, unsigned transaction, and signed transaction files should be archived for auditing purposes.

Bitcoin/BitGo

Creating a Wallet

To summarize:

  1. Two keypairs are created on the cold machine, the private keys are encrypted with user-supplied passphrases, a keychains file is prepared for the networked machine, and (partial) recovery files are generated for distribution.

  2. The keychains file is used by the networked machine to create an HD wallet on the BitGo server.

On the Cold Machine

% bin/offline-create-keychains
prompt: User Keychain passphrase: ******
prompt: Backup Keychain passphrase: ******

wrote keychains-779826ce-a74f-4d61-907a-0d238db9808f.json
wrote recovery_0_2_3-779826ce-a74f-4d61-907a-0d238db9808f.json
wrote recovery_1_2_3-779826ce-a74f-4d61-907a-0d238db9808f.json
wrote recovery_2_2_3-779826ce-a74f-4d61-907a-0d238db9808f.json

The two passphrases are used to encrypt the private key for the user and backup keychains, respectively. A strong password must be used for each (Requiring at least 10^17 guesses according to zxcvbn.) Private keys are encrypted using

sjcl.encrypt(passPhrase, privateKey, { iter: 100000, ks: 256, salt: sjcl.random.randomWords(2, 0) })

The keychains file is kept on the cold machine and transferred to the networked machine, e.g.,

{
  "userKey": {
    "xpub": "xpub..."
    "label": "user",
    "encryptedXprv": "{...}"
  },
  "backupKey": {
    "xpub": "xpub...",
    "label": "backup",
    "encryptedXprv": "{...}"
  }
}

The recovery files are immediately copied to N different USB sticks, e.g.,

{
  "userKey": {
    "xpub": "xpub..."
    "label": "user",
    "encryptedXprv": "{...}",
    "share_0": "..."
  },
  "backupKey": {
    "xpub": "xpub...",
    "label": "backup",
    "encryptedXprv": "{...}",
    "share_0": "..."
  }
}

and then "securely" deleted from the cold machine. These recovery files can be used to reconstruct the user and backup keys using Shamir's threshold secret sharing scheme.

On the Networked Machine

% bin/online-create-wallet \
    --keychains keychains-779826ce-a74f-4d61-907a-0d238db9808f.json
prompt: BitGo email-address:
prompt: BitGo password-address:
prompt: OTP:
prompt: Application access-token: ...

wrote wallet-779826ce-a74f-4d61-907a-0d238db9808f.json

The wallet file has no sensitive information, and is kept on the networked machine, e.g.,

{
  "label": "779826ce-a74f-4d61-907a-0d238db9808f",
  "authenticate": {
    "username": ""
  },
  "wallet": {
    "id": "33bKSJbCoXWuue89bYhqFvSyHZ1MzvZJt8"
  }
}

Submitting a Transaction

To summarize:

  1. A payments file is prepared on the networked machine, e.g.,

     { "1JQPqfRW2xKKQkFWd62MvZq2Ed7B7x8KU" : 500000 }
    

    which contains a list of Bitcoin addresses to be credited.

  2. An unsigned transaction is created, and then transferred to the cold machine.

  3. On the cold machine, the transaction is signed (requiring the operator to enter the passphrase for the user keypair's private key).

  4. The signed transaction is then transferred to the networked machine and submitted to the BitGo server.

On the Networked Machine

% bin/online-create-transaction \
    --wallet wallet-779826ce-a74f-4d61-907a-0d238db9808f.json \
    --payments payments-batch1.json 
prompt: Application access-token: ...

wrote unsigned-batch1.json

This file is then transferred to the cold machine, e.g.,

{
  "transactionHex": "...",
  "unspents": [ ... ],
  "fee": 33953,
  "changeAddresses": [
    {
      "address": "3JDpx9s3Pit6BnNBQ467dJFPNjHGRAwQu9",
      "amount": 982616
    }
  ],
  "walletId": "33bKSJbCoXWuue89bYhqFvSyHZ1MzvZJt8",
  "walletKeychains": [ ... ],
  "feeRate": 51600,
  "estimatedSize": 658,
  "travelInfos": [],
  "authenticate": {
    "username": ""
  }
}

On the Cold Machine

% bin/offline-sign-transaction \
    --unsignedTx unsigned-batch1.json
prompt: User Keychain passphrase: ******

wrote signed-batch1.json

This file is then transferred to the networked machine, e.g.,

{
  "tx": "...",
  "walletId": "33bKSJbCoXWuue89bYhqFvSyHZ1MzvZJt8",
  "authenticate": {
    "username": ""
  }
}

On the Networked Machine

% bin/online-submit-transaction \
    --signedTx signed-batch1.json
prompt: Application access-token: ...

wrote submit-batch1.json

The resulting file may be archived, e.g.,

{
  "status": "accepted",
  "tx": "...",
  "hash": "e5a18cb5718844122cc1b23d898e0a03942f34b1cb90e8d8958e77e3c7b4c61c",
  "instant": false,
  "walletId": "33bKSJbCoXWuue89bYhqFvSyHZ1MzvZJt8",
  "message": "batch1"
}

The payments, unsigned transaction, and signed transaction files should be archived for auditing purposes.

Passphrase Recovery

M of the N trusted actors place their recovery files on the cold machine and run

% bin/offline-recover-passphrases *.json

This outputs the passphrases used to encrypt the private keys for the keypair(s). The recovery files should then be "securely" deleted from the third machine.

brave-payments-tools's People

Contributors

evq avatar mrose17 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

brave-payments-tools's Issues

Collective/threshold signatures

Right now, the usage model of the brave-payments-tools cli is that there is an offline machine with a keychain that can sign transactions, and an online machine that talks to the Uphold service and sends the transactions to them to execute. That means that the offline machine has unilateral power to cryptographically authorize transactions for Uphold.

(The keychain is also encrypted with a passphrase, and for recovery purposes, we also use Shamir's secret-sharing scheme to save a copy of the passphrase for the keychain split k-of-n ways. The point remains that whoever has the offline machine and the passphrase has unilateral power to authorize transactions.)

It would be nice if we could arrange that there were never a single machine with unilateral power to authorize transactions for Uphold, so that it always takes at least two parties to authorize a transaction for high-value wallets. The signatures in question are standard Ed25519 signatures, and it turns out there is a relatively easy way to distribute key generation and signing for Ed25519 into an n-of-n collective signature scheme with no changes to the verifier.

(k-of-n for thresholds k < n is harder and probably requires changes to the verifier; there's an I-D in progress on that subject, though of course if we could change the verifier a concatenation of k signatures from keys the verifier confirms distinct would work without fancy math.)

Although there's probably no implementation of this readily available, it is not far off from a standard Ed25519 signer either -- just requires a few extra additions on the curve. Obviously I would want to consult a Real Cryptographer first before implementing and deploying this, but here's a description of the scheme with references: https://crypto.stackexchange.com/a/50450

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.