Go

You are here:
< Back

Installation

go get github.com/qredit/go-crypto/crypto

Development setup

If you want to contribute to the code of this package execute the following commands

  1. Fork the package
  2. Clone your forked repository
$ git clone https://github.com/<githubusername>/go-crypto
  1. Next, move into the fresh cloned directory
$ cd go-crypto
  1. Install the dependencies
# -t will also fetch dependencies related to tests
$ go get -t ./... 
  1. Dependencies are now installed, you can now run the tests to see if everything is running like it should
$ go test ./...

Include

package main

import (
    qredit_crypto "github.com/qredit/go-crypto/crypto"
    "github.com/davecgh/go-spew/spew"
)

Transactions

Sign

transaction := qredit_crypto.BuildTransfer("address", uint64(amount), "Hello World", "top secret", "second top secret")

spew.Dump(transaction)

Serialize (AIP11)

transaction := qredit_crypto.DeserializeTransaction("serialized_transaction")

serialized := qredit_crypto.SerializeTransaction(transaction)

spew.Dump(serialized)

#Deserialize (AIP11)

transaction := qredit_crypto.DeserializeTransaction("serialized_transaction")

spew.Dump(transaction)

Message

Sign

message, _ := qredit_crypto.SignMessage("Hello World", "top secret")

spew.Dump(message)

Verify

message, _ := qredit_crypto.SignMessage("Hello World", "top secret")

spew.Dump(message.Verify())

Identities

Address

Get an address from a passphrase

address, _ := qredit_crypto.AddressFromPassphrase('this is a top secret passphrase')

spew.Dump(address)

Get an address from a public key

publicKey, _ := qredit_crypto.PublicKeyFromPassphrase('this is a top secret passphrase')

spew.Dump(publicKey.ToAddress())

Get an address from a private key

privateKey, _ := qredit_crypto.PrivateKeyFromPassphrase('this is a top secret passphrase')

spew.Dump(privateKey.ToAddress())

Validate an address

spew.Dump(ValidateAddress('D61mfSggzbvQgTUe6JhYKH2doHaqJ3Dyib'))

Private Key

Get a private key from a passphrase

privateKey, _ := qredit_crypto.PrivateKeyFromPassphrase('this is a top secret passphrase')

spew.Dump(privateKey)

Get a private key instance object from hex

privateKey, _ := qredit_crypto.PrivateKeyFromHex('d8839c2432bfd0a67ef10a804ba991eabba19f154a3d707917681d45822a5712')

spew.Dump(privateKey)

Public Key

Get a public key from a passphrase

publicKey, _ := qredit_crypto.PublicKeyFromPassphrase('this is a top secret passphrase')

spew.Dump(publicKey)

Get a public key instance object from hex

publicKey, _ := qredit_crypto.PublicKeyFromHex('034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192')

spew.Dump(publicKey)

WIF

Get a WIF from a passphrase

privateKey, _ := qredit_crypto.PrivateKeyFromPassphrase('this is a top secret passphrase')

spew.Dump(privateKey.ToWif())
Last Updated On January 15, 2019