block_io_go

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2020 License: MIT Imports: 12 Imported by: 0

README

BlockIo

This Golang library is the official Block.IO low-level SDK. To use the functions provided by this SDK, you will need a REST client of your choice, the Bitcoin, Litecoin, or Dogecoin API key(s) from Block.io and, if required by your use case, your PIN or secret keys.

Installation

  go get github.com/BlockIo/block_io-go

Usage

Example implementations

Method documentation

Signing
SignWithdrawRequestJson()
  func SignWithdrawRequestJson(pin string, withdrawData string) (string, error)

Signs JSON encoded signature requests returned from the /api/v2/withdraw* endpoints with a PIN-derived key and returns a JSON encoded string that can be posted to /api/v2/sign_and_finalize_withdrawal.

SignRequestJsonWithKey()
  func SignRequestJsonWithKey(ecKey *ECKey, data string) (string, error)

Signs JSON encoded strings returned from the /api/v2/sweep* and /api/v2/withdraw_dtrust*/ endpoints with a local ECKey and returns a JSON encoded string that can be posted to /api/v2/sign_and_finalize_* endpoints.

SignRequestJsonWithKeys()
  func SignRequestJsonWithKeys(ecKeys []*ECKey, data string) (string, error)

Signs JSON encoded strings returned from the /api/v2/withdraw_dtrust*/ endpoints with multiple local ECKeys and returns a JSON encoded string that can be posted to /api/v2/sign_and_finalize_* endpoints.

Key derivation
NewECKey()
  func NewECKey (d [32]byte, compressed bool) *ECKey

Creates an ECKey from a byte slice.

FromWIF()
  func FromWIF(strWif string) (*ECKey, error)

Creates an ECKey from a WIF-formatted string. Returns an error if the given string could not be

DeriveKeyFromHex()
  func DeriveKeyFromHex(hexPass string) (*ECKey, error)

Derives an ECKey from a hexadecimal encoded string by hashing it with sha256 once.

DeriveKeyFromString()
  func DeriveKeyFromString(pass string) *ECKey

Convenience function to derive an ECKey from a string seed by hashing it with sha256 once.

NOTE: Do not use this for deriving production keys!

Testing

  go test -v

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AESDecrypt

func AESDecrypt(cipherText []byte, key []byte) ([]byte, error)

func AESEncrypt

func AESEncrypt(clearText []byte, key []byte) ([]byte, error)

func PinToAesKey

func PinToAesKey(pin string) string

func SignDtrustRequest

func SignDtrustRequest(ecKeys []*ECKey, dtrustReqData SignatureData) (string, error)

DEPRECIATED. Use SignRequestWithKeys or SignRequestJsonWithKeys

func SignInputs

func SignInputs(ecKey *ECKey, hexData string) (string, error)

Sign any hex string

func SignRequestJsonWithKey added in v1.0.1

func SignRequestJsonWithKey(ecKey *ECKey, data string) (string, error)

Sign a JSON string withdrawal request with a custom ECKey

func SignRequestJsonWithKeys added in v1.0.1

func SignRequestJsonWithKeys(ecKeys []*ECKey, data string) (string, error)

Sign a JSON string withdrawal request with a set of custom ECKeys

func SignRequestWithKey added in v1.0.1

func SignRequestWithKey(eckey *ECKey, sigRequest *SignatureData) (string, error)

Sign a withdrawal request with a custom ECKey

func SignRequestWithKeys added in v1.0.1

func SignRequestWithKeys(ecKeys []*ECKey, sigRequest *SignatureData) (string, error)

Sign a withdrawal request with a set of custom ECKeys

func SignSweepRequest

func SignSweepRequest(ecKey *ECKey, sweepReqData SignatureData) (string, error)

DEPRECIATED. Use SignRequestWithKey or SignRequestJsonWithKey

func SignWithdrawRequest

func SignWithdrawRequest(pin string, withdrawData *SignatureData) (string, error)

Sign a withdrawal request with a pin

func SignWithdrawRequestJson added in v1.0.1

func SignWithdrawRequestJson(pin string, withdrawData string) (string, error)

Convenience withdrawal request function that takes a JSON string

func ValidateResponseJson added in v1.0.1

func ValidateResponseJson(responseJson string) error

Types

type BaseResponse

type BaseResponse struct {
	Status string      `json:"status"`
	Data   interface{} `json:"data"`
}

func ParseResponse

func ParseResponse(res string) (*BaseResponse, error)

type ECKey

type ECKey struct {
	Compressed bool
	// contains filtered or unexported fields
}

func DeriveKeyFromHex added in v1.0.1

func DeriveKeyFromHex(hexPass string) (*ECKey, error)

func DeriveKeyFromString added in v1.0.1

func DeriveKeyFromString(pass string) *ECKey

func ExtractKeyFromEncryptedPassphrase

func ExtractKeyFromEncryptedPassphrase(encryptedData string, b64Key string) (*ECKey, error)

func ExtractKeyFromPassphrase

func ExtractKeyFromPassphrase(hexPass string) *ECKey

DEPRECIATED: Please use DeriveKeyFromHex

func ExtractKeyFromPassphraseString

func ExtractKeyFromPassphraseString(pass string) *ECKey

DEPRECIATED: Please use DeriveKeyFromString

func FromWIF

func FromWIF(strWif string) (*ECKey, error)

func NewECKey

func NewECKey(d [32]byte, compressed bool) *ECKey

func (*ECKey) PrivateKey

func (eck *ECKey) PrivateKey() []byte

func (*ECKey) PrivateKeyHex

func (eck *ECKey) PrivateKeyHex() string

func (*ECKey) PublicKey

func (eck *ECKey) PublicKey() []byte

func (*ECKey) PublicKeyHex

func (eck *ECKey) PublicKeyHex() string

func (*ECKey) Sign

func (eck *ECKey) Sign(message []byte) ([]byte, error)

func (*ECKey) SignHex

func (eck *ECKey) SignHex(message []byte) (string, error)

type EncryptedPassphrase

type EncryptedPassphrase struct {
	Passphrase      string `json:"passphrase"`
	SignerAddress   string `json:"signer_address"`
	SignerPublicKey string `json:"signer_public_key"`
}

type ErrorData added in v1.0.1

type ErrorData struct {
	ErrorMessage string `json:"error_message"`
}

type ErrorResponse added in v1.0.1

type ErrorResponse struct {
	Status string    `json:"status"`
	Data   ErrorData `json:"data"`
}

func ParseErrorResponse added in v1.0.1

func ParseErrorResponse(res string) (*ErrorResponse, error)

type Inputs

type Inputs []struct {
	DataToSign       string  `json:"data_to_sign"`
	InputNo          int64   `json:"input_no"`
	SignaturesNeeded int64   `json:"signatures_needed"`
	Signers          Signers `json:"signers"`
}

type SignatureData

type SignatureData struct {
	EncryptedPassphrase  EncryptedPassphrase `json:"encrypted_passphrase"`
	Inputs               Inputs              `json:"inputs"`
	MoreSignaturesNeeded bool                `json:"more_signatures_needed"`
	ReferenceID          string              `json:"reference_id"`
	UnsignedTxHex        string              `json:"unsigned_tx_hex"`
}

func ParseSignatureResponse

func ParseSignatureResponse(res string) (*SignatureData, error)

type SignatureRes

type SignatureRes struct {
	Status string        `json:"status"`
	Data   SignatureData `json:"data"`
}

type Signers

type Signers []struct {
	SignedData      interface{} `json:"signed_data"`
	SignerAddress   string      `json:"signer_address"`
	SignerPublicKey string      `json:"signer_public_key"`
}

Jump to

Keyboard shortcuts

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