go_bitpay_client

package module
v0.0.0-...-78ae864 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 11, 2014 License: MIT Imports: 19 Imported by: 0

README

go-bitpay-client

GoDoc

Wrapper for the Bitpay API. This library leverages the great btcec library for private/public authentication.

go-bitpay-client is still alpha and not all operations are currently supported. The cli is installed via:

go get github.com/drewwells/go-bitpay-client/go-bitpay
go-bitpay

Getting started

Use the node wrapper to generate your client tokens. This part isn't implement in Go yet see here. Be sure your account is the correct type (test account for test.bitpay.com or prod account for www.bitpay.com). For the rest of this setup, the docs will assume you are using the test environment.

bitpay keygen
bitpay pair

bitpay generates key files in the ~/.bitpay folder. The keys generated now need to be hex encoded, this function will do that: https://github.com/bitpay/bitauth/blob/master/lib/bitauth.js#L12. The results should be a long series of numbers and LOWER CASE letters. Save this as your pub and priv values in the .env file.

Go back to go-bitpay-client project root and copy .env.sample to .env. This file stores all the credentials needed for negotiating with the bitpay server. Generate a token based off your PUBLIC key, this can be done a few different ways. Try this one. If it doesn't work please pull request to fix it, thanks! In order to do this, you need to set the publickey value in your .env file. This is your public key, hint: your public key the format is camelcase with numbers.

go get github.com/drewwells/go-bitpay-client/go-bitpay
go-bitpay token

You will receive a new token and a pairing code. Login to your account and enter this pairing code on the api-tokens page. Add this token to the .env file as 'token'.

Development

Getting started with Go https://golang.org/doc/install

Learning Go

Setup an .env file with your private, public keys and user id. Copy .env.sample and fill in these values. Keys are currently generated via debugging the Node API. Fork or checkout this project.

go get github.com/drewwells/go-bitpay-client
cd $GOPATH/src/github.com/drewwells/go-bitpay-client
go run bitpay/main.go

Help

If you're getting stuck with invalid sin or invalid token, bitauth is the source of truth. Try playing around with those examples with your credentials (located in ~/.bitpay).

Documentation

Index

Examples

Constants

View Source
const (
	MAIN      = 0x01
	TESTNET   = 0x11
	EPHEMERAL = 0x02
)

Variables

This section is empty.

Functions

func Bill

func Bill() []byte

Create a bill

func Bills

func Bills() []byte

List all bills

func DoubleShaHash

func DoubleShaHash(out, b []byte)

DoubleShaHash performs 2 sha256 checksums and sets the bytes of dst.

func GenerateKeyGen

func GenerateKeyGen() ([]byte, []byte, error)

Create a new Bitcoin compliant private and public key pair.

func Invoice

func Invoice() []byte

Invoice creates a currency invoice

curl https://bitpay.com/api/invoice \
  -u ApiKey \
  -d price=10.00 \
  -d currency=USD

func Keygen

func Keygen() ([]byte, []byte, []byte)

Keygen returns private, public (compressed), and SIN

func PublicFromPrivate

func PublicFromPrivate(priv []byte, compressed bool) []byte

Reference for generating compressed keys github.com/piotrnar/gocoin/blob/master/lib/btc

func Rates

func Rates() []byte

func RimpHash

func RimpHash(out, in []byte)

RimpHash performs a ripemd160 hash following a sha256 hash returning the ripemd160 checksum.

func Sin

func Sin(key []byte) []byte

Sin accepts as input hex encoded compressed PublicKey and returns a SIN (Secure Identity Number) Learn more: https://en.bitcoin.it/wiki/Identity_protocol_v1#SIN_record

Example
txt := make([]byte, hex.DecodedLen(len(TESTPRIV)))
hex.Decode(txt, TESTPRIV)
pub := PublicFromPrivate(txt, false)
pubcomp := PublicFromPrivate(txt, true)

sin := Sin(pubcomp)

fmt.Printf("Public:  %x\n", string(pub))
fmt.Printf("PubComp: %x\n", string(pubcomp))
fmt.Printf("Sin:     %s\n", string(sin))
Output:

Public:  04c6072aad509c88edad53756abc01f00f9e3feeb08fd748b4081964bae97e253214b138fb752811e8aa2d1661ecc7a408b27aaa3bdcaee408f52530c61a007953
PubComp: 03c6072aad509c88edad53756abc01f00f9e3feeb08fd748b4081964bae97e2532
Sin:     TfFabGCCATnbxfYRYfkCjM1RDC64aZfRJAu

func Token

func Token() []byte

Creates or claims an access token

Types

type Config

type Config struct {
	Global struct {
		Public, Private, End, Sin, Token string
	}
}

type PublicKey

type PublicKey []byte

Directories

Path Synopsis
encoding
base58
Base58 is a group of binary-to-text encoding schemes used to represent large integers as alphanumeric text.
Base58 is a group of binary-to-text encoding schemes used to represent large integers as alphanumeric text.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL