address

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

README

Address

build Go Report Card License

Yet another address format which mirrors EthereumNodeRecords except ENR's are serialized in RLP encoding, and here protobuf is used.

I was too bored on a sunday and wrote this.

Specification

The address record specification is written here

Usage

Refer the unit tests for usage.

package main

import (
	"fmt"
	"github.com/SangameswaranRS/address"
)

func main() {
	// Simple record creation
	record, privKey, err := address.NewRecord("8.8.8.8", 9090)
	// play with record.

	// if you already have a priv key:( Priv keys are serializable, you may
	// store it as you wish)
	record, err = address.NewRecordWithPrivateKey(privKey, "69.69.69.69", 6969)
	if err != nil {
		panic(err)
	}
	fmt.Println(address.Pretty(record))
}
Roadmap v0.0.1
  • Key interfaces and proto definitions.
  • ECDSA Curve support for key.
  • Basic record usages for IPV4.
  • Unit tests.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidPeerId    = errors.New("invalid peer id")
	ErrInvalidSignature = errors.New("invalid signature")
	ErrInvalidPubKey    = errors.New("invalid pub key")
	ErrMarshal          = errors.New("error while marshalling pub key")
	ErrPrelimCheck      = errors.New("mandatory fields missing")
	ErrInvalidIp        = errors.New("invalid ip address")
	ErrInvalidPort      = errors.New("invalid port")
)

Functions

func DecodeToPeerId added in v0.0.3

func DecodeToPeerId(idEncoded string) ([]byte, error)

DecodeToPeerId decodes the peer id from string to byte array

func EncodePeerId added in v0.0.3

func EncodePeerId(id []byte) string

EncodePeerId encodes the peer id to a string

func MarshalRecord

func MarshalRecord(record *proto.NodeRecord) ([]byte, error)

MarshalRecord marshals a record for transport

func NewRecord

func NewRecord(ipv4 string, port int) (*proto.NodeRecord, crypto.PrivateKey, error)

NewRecord generates a new node record, with an autogenerated private key.

func NewRecordWithOptions added in v0.0.3

func NewRecordWithOptions(key crypto.PrivateKey, options ...Option) (*proto.NodeRecord, error)

NewRecordWithOptions returns a new record with the specified options.

func NewRecordWithPrivateKey

func NewRecordWithPrivateKey(privateKey crypto.PrivateKey, ipv4 string, port int) (*proto.NodeRecord, error)

NewRecordWithPrivateKey creates a new record with the specified parameters.

func Pretty

func Pretty(record *proto.NodeRecord) string

Pretty just returns a human readable string

func SignNodeRecord

func SignNodeRecord(privateKey crypto.PrivateKey, record *proto.NodeRecord) (*proto.NodeRecord, error)

SignNodeRecord signs a node record.

func UnMarshalRecord

func UnMarshalRecord(b []byte) (*proto.NodeRecord, error)

UnMarshalRecord unmarshalls the record.

func ValidateId added in v0.0.3

func ValidateId(id []byte) bool

ValidateId validates the length of the Id. For most operations, we worry only about the length Encoding and other verifications should already be done as a part of VerifyRecord

func ValidateIp added in v0.0.3

func ValidateIp(ip string) bool

ValidateIp returns if the given ip string is valid

func ValidatePort added in v0.0.3

func ValidatePort(port int) bool

ValidatePort returns if the given port is valid or not For validation, ephemeral ports are not allowed.

func VerifyRecord

func VerifyRecord(record *proto.NodeRecord) (bool, error)

VerifyRecord verifies the given record.

func VerifyRecordWithPubKey added in v0.0.2

func VerifyRecordWithPubKey(pubKey crypto.PublicKey, record *proto.NodeRecord) (bool, error)

VerifyRecordWithPubKey verifies the signature of the node record.

Types

type Option added in v0.0.3

type Option func(record *proto.NodeRecord) error

func WithIpV4 added in v0.0.3

func WithIpV4(ipv4 string) Option

WithIpV4 returns an Option that returns err when ipv4 is invalid

func WithIpV6 added in v0.0.3

func WithIpV6(ipv6 string) Option

WithIpV6 returns an Option that returns err when ipv6 is invalid

func WithPort added in v0.0.3

func WithPort(port int) Option

WithPort returns an option for adding port.

func WithPrivateKey added in v0.0.3

func WithPrivateKey(privateKey crypto.PrivateKey) Option

WithPrivateKey returns an option for adding "pubKey" & ID fields. It derives the public key & ID from the Specified private key

func WithRelays added in v0.0.3

func WithRelays(relays ...*proto.NodeRecord) Option

WithRelays returns an option that could be used for adding relays

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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