hypercorecrypto

package module
v0.0.0-...-aa79460 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2023 License: MIT Imports: 6 Imported by: 0

README

hypercorecrypto

Golang implementation of hypercore-crypto.

These are the crypto primitives used in hypercore, extracted into a separate module

import "github.com/tirith-tech/hypercorecrypto"

Usage

import (
	"fmt"

	crypto "github.com/tirith-tech/hypercorecrypto"
)

keyPair := crypto.NewKeyPair()
fmt.Println("Generated key pair:", keyPair)

API

keyPair := crypto.NewKeyPair()

Returns an ED25519 keypair that can used for tree signing.

signature := crypto.Sign(message, secretKey)

Signs a message (buffer).

verified := crypto.Verify(message, signature, publicKey)

Verifies a signature for a message.

hash := crypto.Data(data)

Hashes a leaf node in a merkle tree.

hash := crypto.Parent(a, b)

Hash a parent node in a merkle tree. a and b should look like this:

type TreeNode struct {
    Index uint64
    Hash  []byte
    Size  uint64
}
hash := crypto.Tree(peaks)

Hashes the merkle root of the tree. peaks should be an array of the peaks of the tree and should be of type TreeNode like above.

buffer := crypto.RandomBytes(size)

Returns a buffer containing random bytes of size size.

hash := crypto.DiscoveryKey(publicKey)

Return a hash derived from a publicKey that can used for discovery without disclosing the public key.

list := crypto.Namespace(name, count)

Make a list of namespaces from a specific publicly known name. Use this to namespace capabilities or hashes / signatures across algorithms.

License

MIT

Documentation

Index

Constants

View Source
const (
	LeafType   = byte(0)
	ParentType = byte(1)
	RootType   = byte(2)
	Hypercore  = "hypercore"
)

Variables

This section is empty.

Functions

func Data

func Data(data []byte) []byte

func DiscoveryKey

func DiscoveryKey(publicKey []byte) []byte

func Namespace

func Namespace(name []byte, count int) [][]byte

func Parent

func Parent(a, b TreeNode) []byte

func RandomBytes

func RandomBytes(n int) []byte

func Sign

func Sign(message, privateKey []byte) []byte

func Tree

func Tree(roots []TreeNode, out []byte) []byte

func ValidateKeyPair

func ValidateKeyPair(keyPair KeyPair) bool

func Verify

func Verify(message, signature, publicKey []byte) bool

func WriteUvarint

func WriteUvarint(w io.Writer, x uint64)

Types

type KeyPair

type KeyPair struct {
	PublicKey  []byte
	PrivateKey []byte
}

func KeyPairFromSeed

func KeyPairFromSeed(seed []byte) KeyPair

func NewKeyPair

func NewKeyPair() KeyPair

type TreeNode

type TreeNode struct {
	Index uint64
	Hash  []byte
	Size  uint64
}

Jump to

Keyboard shortcuts

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