Coder Social home page Coder Social logo

go-identity's Introduction

Identity

Build Status Coverage Status

The Identity library is an official reference implementation of identities and addresses in the Republic Protocol, written in Go. It supports the generation and use of Republic key pairs, Republic IDs, Republic addresses, and Republic multi-addresses.

Key Pairs

To create an identity, or an address, in the Republic Protocol an ECDSA key pair is required. This key pair is the same as those used by Bitcoin and Ethereum.

keyPair, err := identity.NewKeyPair()

ID

Republic IDs are used to identity miners and traders in the Republic Protocol, and are required when registering with the Registrar. To generate an ID, take the first 20 bytes of the Keccak-256 hash of your public key.

keyPair, err := identity.NewKeyPair()
id := keyPair.ID()
fmt.Println(id)

An example output of this code snippet is given below.

[247 107 192 130 208 33 69 182 183 127 237 24 22 83 157 99 207 221 9 243]

Address

Republic addresses are URL compatible encoding of an ID. To generate an address, take the Base58 encoding of the multi-hash of an ID. The Bitcoin alphabet for Base58 encoding must be used. For more information about multi-hashes, see https://multiformats.io/multihash.

keyPair, err := identity.NewKeyPair()
address := keyPair.Address()
fmt.Println(address)

An example output of this code snippet is given below.

8MGHyHWxQ5zUzXXnK5b6LkWGFCWSyX

Multi-address

Republic multi-addresses are a form of network address that can represent multiple different networking layers in a single address. In the Republic Protocol, they are used to hold network addresses and Republic addresses. At the moment, the network address is excepted to be an IPv4 address and a TCP port. In future, it may change to be an I2P address that provides a greater level of anonymity. For more information about multi-addresses, see https://multiformats.io/multiaddr.

keyPair, err := identity.NewKeyPair()
multi, err := keyPair.MultiAddress()
multi, err = identity.NewMultiAddressFromString(fmt.Sprintf("/ip4/127.0.0.1/tcp/80/republic/%s", multi.String())
fmt.Println(multi.String())
fmt.Println(multi.ValueForProtocol(identity.RepublicCode))
fmt.Println(multi.ValueForProtocol(identity.IP4Code))
fmt.Println(multi.ValueForProtocol(identity.TCPCode))

An example output of this code snippet is given below.

/ip4/127.0.0.1/tcp/80/republic/8MGfbzAMS59Gb4cSjpm34soGNYsM2f
8MGfbzAMS59Gb4cSjpm34soGNYsM2f <nil>
127.0.0.1 <nil>
80 <nil>

Tests

To run the test suite, install Ginkgo.

go get github.com/onsi/ginkgo/ginkgo

Now we can run the tests.

ginkgo -v

License

The Identity library was developed by the Republic Protocol team and is available under the MIT license. For more information, see our website https://republicprotocol.com.

go-identity's People

Contributors

tok-kkk avatar loongy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.