Documentation ¶
Index ¶
- Variables
- func Base58Decode(s string) ([]byte, error)
- func Base58Encode(in []byte) string
- func ExportPrivateKey(k *PrivateKey, testnet bool) string
- func GetUint(buf []byte, p, n int) (v uint64, err error)
- func GetVarUint(buf []byte, p int) (uint64, int, error)
- func Hash160(data []byte) []byte
- func Hash256(data []byte) []byte
- func PutUint(n uint, j int) []byte
- func PutVarUint(n uint) []byte
- func RipeMD160(data []byte) []byte
- func Sha1(data []byte) []byte
- func Sha256(data []byte) []byte
- func SignY(p *Point) (int, error)
- func Solve(x *math.Int) (*math.Int, bool)
- func Verify(key *PublicKey, hash []byte, sig *Signature) bool
- type Curve
- type DissectedTransaction
- type Point
- func (p *Point) Add(q *Point) *Point
- func (p *Point) Bytes(compressed bool) []byte
- func (p *Point) Double() *Point
- func (p *Point) Equals(q *Point) bool
- func (p *Point) IsInf() bool
- func (p *Point) IsOnCurve() bool
- func (p *Point) Mult(k *math.Int) *Point
- func (p *Point) Neg() *Point
- func (p *Point) String() string
- func (p *Point) X() *math.Int
- func (p *Point) Y() *math.Int
- type PrivateKey
- type PublicKey
- type Signature
Constants ¶
This section is empty.
Variables ¶
Inf is the point at "infinity"
Functions ¶
func Base58Decode ¶
Base58Decode converts a base58 representation into byte array
func Base58Encode ¶
Base58Encode converts byte array to base58 string representation
func ExportPrivateKey ¶
func ExportPrivateKey(k *PrivateKey, testnet bool) string
ExportPrivateKey returns a private key in SIPA format
func GetUint ¶
GetUint converts 'n' bytes in a buffer 'buf' starting at position 'p' into an unsigned integer.
func GetVarUint ¶
GetVarUint gets a variable length unsigned integer from a buffer.
Types ¶
type Curve ¶
type Curve struct { // P is the generator of the underlying field "F_p" // = 2^256 - 2^32 - 2^9 - 2^8 - 2^7 - 2^6 - 2^4 - 1 P *math.Int // Gx is the x-coord of the base point Gx *math.Int // Gy is the y-coord of the base point Gy *math.Int // N is the order of G N *math.Int // curve parameter (=7) B *math.Int }
Curve is the elliptic curve used for Bitcoin (Secp256k1)
type DissectedTransaction ¶
type DissectedTransaction struct { Version uint64 // version number of the transaction LockTime uint64 // locktime of the transaction Content [][]byte // list of transaction segments VinSeq []uint64 // list of sequence numbers of vin slots VinSlot int // active vin slot index Signable []byte // signable transaction }
DissectedTransaction is dissected raw transaction for easier manipulation.
func NewDissectedTransaction ¶
func NewDissectedTransaction(rawHex string) (dt *DissectedTransaction, err error)
NewDissectedTransaction dissects a raw transaction into its defining segments. A binary encoded raw transaction looks like this:
------+-------------+---------+--------------------------------- Level | Field | length | Value/Comment ------+-------------+---------+--------------------------------- 0 | VERSION | 4 | version 0 | N_VIN | var | Number of Vin defs to follow ------+-------------+---------+--------------------------------- 1 | VIN:TXID | 32 | Transaction ID 1 | VIN:N | 4 | VOUT number in transaction 1 | VIN:SCRIPT | | scriptSig (hex-encoded) ------+-------------+---------+--------------------------------- 2 | SCRIPT:LEN | var | Length of script 2 | SCRIPT:DATA | <n> | Script data ------+-------------+---------+--------------------------------- 1 | VIN:SEQ | | sequence number ------+-------------+---------+--------------------------------- 0 | N_VOUT | var | Number of Vout defs to follow ------+-------------+---------+--------------------------------- 1 | VOUT:AMOUNT | 8 | Number of Satoshis (1e-8 btc) 1 | VOUT:SCRIPT | | scriptPubkey ------+-------------+---------+--------------------------------- 2 | SCRIPT:LEN | var | Length of script 2 | SCRIPT:DATA | <n> | Script data ------+-------------+---------+--------------------------------- 0 | LOCKTIME | 4 | locktime ------+-------------+---------+---------------------------------
func (*DissectedTransaction) Bytes ¶
func (d *DissectedTransaction) Bytes() (buf []byte)
Bytes returns a flat binary array of as a raw transaction.
func (*DissectedTransaction) PrepareForSign ¶
func (d *DissectedTransaction) PrepareForSign(vin int, scr []byte) error
PrepareForSign prepares a dissected raw transaction for a given vin script for signature.
func (*DissectedTransaction) Sign ¶
func (d *DissectedTransaction) Sign(prv *PrivateKey, hashType byte) ([]byte, error)
Sign signs a prepared transaction with a private key
type Point ¶
type Point struct {
// contains filtered or unexported fields
}
Point (x,y) on the curve
func NewPointFromBytes ¶
NewPointFromBytes reconstructs a Point from binary representation.
func (*Point) Mult ¶
Mult multiplies a Point on the curve with a scalar value k using a Montgomery multiplication approach
type PrivateKey ¶
PrivateKey is a random factor 'd' for the base Point that yields the associated PublicKey (Point on the curve (x,y) = d*G)
func GenerateKeys ¶
func GenerateKeys(compr bool) *PrivateKey
GenerateKeys creates a new set of keys. [http://www.nsa.gov/ia/_files/ecdsa.pdf] page 19f but with a different range (value 1 and 2 for exponent are not allowed)
func ImportPrivateKey ¶
func ImportPrivateKey(keydata string, testnet bool) (*PrivateKey, error)
ImportPrivateKey imports a private key in SIPA format
func PrivateKeyFromBytes ¶
func PrivateKeyFromBytes(b []byte) (*PrivateKey, error)
PrivateKeyFromBytes returns a private key from a byte representation.
func (*PrivateKey) Bytes ¶
func (k *PrivateKey) Bytes() []byte
Bytes returns a byte representation of private key.
type PublicKey ¶
PublicKey is a Point on the elliptic curve: (x,y) = d*G, where 'G' is the base Point of the curve and 'd' is the secret private factor (private key)
func PublicKeyFromBytes ¶
PublicKeyFromBytes returns a public key from a byte representation.
type Signature ¶
Signature is a Bitcoin signature in scripts.
func NewSignatureFromASN1 ¶
NewSignatureFromASN1 returns a signature from an ASN.1-encoded sequence.
func Sign ¶
func Sign(key *PrivateKey, hash []byte) *Signature
Sign a hash value with private key. [http://www.nsa.gov/ia/_files/ecdsa.pdf, page 13f]