ripple: bitbucket.org/dchapes/ripple/crypto/rkey Index | Examples | Files

package rkey

import "bitbucket.org/dchapes/ripple/crypto/rkey"

Package rkey, short for Ripple key, implements Ripple Account Families as documented at https://ripple.com/wiki/Account_Family. This includes the ability to decode a Ripple secret key (sXXX) into the family of private and public ECDSA keys and the associated Ripple addresses.

Most types implement text marshaling (via encoding.TextMarshaler) to go to and from the Ripple base58 encoding. For example

s := new(FamilySeed);      s.UnmarshalText('sXXXX')
f := new(PublicGenerator); f.UnmarshalText('fXXXX')
p := new(AcctPrivateKey);  p.UnmarshalText('pXXXX')
a := new(AcctPublicKey);   a.UnmarshalText('aXXXX')

GenerateSeed can be used to generate a new random FamilySeed and get the matching keys and Ripple address.

The types are structured like the following pseudo-code:

FamilySeed struct {
    Seed: 128 bit random number, encoded as sXXX
    PrivateGenerator struct {
        D
        PublicGenerator struct {
             X, Y: encoded as fXXX (from the compressed point)
        }
    }
}
PrivateGenerator.Generate(int) -> AcctPrivateKey, encoded as pXXX
PublicGenerator.Generate(int)  -> AcctPublicKey,  encoded as aXXX

Thus creating a FamilySeed also creates the generators. It's also possible to create and use just a PublicGenerator or just an AcctPublicKey without knowing the FamilySeed, PrivateGenerator, etc.

TODO(dchapes): Currently all types implement Key which is an exported interface. This probably shouldn't be exported and ideally a better/cleaner implementation would be used.

Code:

package main

import (
    "bitbucket.org/dchapes/ripple/crypto/rkey"
    "fmt"
)

const secret = "sp6JS7f14BuwFY8Mw6bTtLKWauoUs"

func main() {
    s, _ := rkey.NewFamilySeed(secret)
    pubkey := s.PrivateGenerator.PublicGenerator.Generate(0)
    addr := pubkey.Address()
    fmt.Println("secret:", secret, "address:", addr)
}

Index

Examples

Package Files

accountid.go doc.go encode.go familyseed.go privategenerator.go privatekey.go publicgenerator.go publickey.go version.go

type AccountId Uses

type AccountId struct {
    Id *big.Int
}

An AccountId is a hash of a public key.

Its Ripple base58 encoding starts with `r` as is the Ripple address.

TODO(dchapes): remove?

func NewAccountId Uses

func NewAccountId(text string) (*AccountId, error)

func (*AccountId) MarshalText Uses

func (r *AccountId) MarshalText() ([]byte, error)

func (*AccountId) UnmarshalText Uses

func (r *AccountId) UnmarshalText(text []byte) error

type AcctPrivateKey Uses

type AcctPrivateKey ecdsa.PrivateKey

An AcctPrivateKey is a specific ECDSA private key within an account family.

Its Ripple base58 encoding starts with `p`.

func NewAcctPrivateKey Uses

func NewAcctPrivateKey(text string) (*AcctPrivateKey, error)

func (*AcctPrivateKey) MarshalText Uses

func (p *AcctPrivateKey) MarshalText() ([]byte, error)

func (*AcctPrivateKey) UnmarshalText Uses

func (p *AcctPrivateKey) UnmarshalText(text []byte) error

type AcctPublicKey Uses

type AcctPublicKey ecdsa.PublicKey

An AcctPublicKey is a specific ECDSA public key within an account family.

Its Ripple base58 encoding starts with `a`.

func NewAcctPublicKey Uses

func NewAcctPublicKey(text string) (*AcctPublicKey, error)

func (*AcctPublicKey) AccountId Uses

func (p *AcctPublicKey) AccountId() *AccountId

AccountId returns the account id (aka Ripple address) for this public key.

TODO(dchapes): remove?

func (*AcctPublicKey) Address Uses

func (p *AcctPublicKey) Address() string

Address returns the Ripple address of this public key.

func (*AcctPublicKey) MarshalJSON Uses

func (p *AcctPublicKey) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface. Ripple uses a DER style encoding in JSON Ripple transactions rather than base58 encoding.

func (*AcctPublicKey) MarshalText Uses

func (a *AcctPublicKey) MarshalText() ([]byte, error)

func (*AcctPublicKey) UnmarshalJSON Uses

func (p *AcctPublicKey) UnmarshalJSON(in []byte) error

UnmarshalJSON implements the json.Unmarshaler interface. Ripple uses a DER style encoding in JSON Ripple transactions rather than base58 encoding.

func (*AcctPublicKey) UnmarshalText Uses

func (a *AcctPublicKey) UnmarshalText(text []byte) error

type FamilySeed Uses

type FamilySeed struct {
    Seed *big.Int
    PrivateGenerator
}

A FamilySeed, also called the Ripple secret, is a 128 bit random number used to generate all the private keys, public keys, and Ripple addresses within the account family.

Its Ripple base58 encoding starts with `s`.

func GenerateSeed Uses

func GenerateSeed() (*FamilySeed, error)

GenerateSeed uses crypto/rand to generate a new random FamilySeed.

func NewFamilySeed Uses

func NewFamilySeed(text string) (*FamilySeed, error)

func NewSeed Uses

func NewSeed(i *big.Int) (*FamilySeed, error)

NewSeed uses the provided Int, which must be <=128 bits long, as a FamilySeed.

func (*FamilySeed) MarshalText Uses

func (s *FamilySeed) MarshalText() ([]byte, error)

func (*FamilySeed) UnmarshalText Uses

func (s *FamilySeed) UnmarshalText(text []byte) error

type Key Uses

type Key interface {
    encoding.TextMarshaler
    encoding.TextUnmarshaler
    // contains filtered or unexported methods
}

Key is ??? TODO(dchapes): should this even be exported? Is there a better/cleaner way to implement this.

func New Uses

func New(text string) (Key, error)

New returns a new Key decoded from a Ripple base58 encoded text.

type PrivateGenerator Uses

type PrivateGenerator struct {
    D   *big.Int
    PublicGenerator
}

A PrivateGenerator, also called the root private key or master private key, is effectively a ECDSA private key used to make the PrivateGenerator (the matching ECDSA public key) and the individual AcctPrivateKey's within the account family.

With the private generator, all the private keys can be determined.

func (*PrivateGenerator) Generate Uses

func (g *PrivateGenerator) Generate(idx uint32) *AcctPrivateKey

Generate is used to generate the AcctPrivateKey for sequence idx in this account family.

type PublicGenerator Uses

type PublicGenerator struct {
    X, Y *big.Int
}

A PublicGenerator, also called the root/master public key or family generator, is effectively a ECDSA public key used to make the individual AcctPublicKey's within the account family.

The PublicGenerator is so named because it generates the public keys, not because it should be made public.

With the public generator, anyone can determine which accounts are in the family.

Caution: With the public generator and any one private key, the private generator can be determined. For this reason, export of individual private keys should not be allowed when the accounts are part of a family.

Its Ripple base58 encoding starts with `f`

func NewPublicGenerator Uses

func NewPublicGenerator(text string) (*PublicGenerator, error)

func (*PublicGenerator) Generate Uses

func (g *PublicGenerator) Generate(idx uint32) *AcctPublicKey

Generate is used to generate the AcctPublicKey for sequence idx in this account family.

func (*PublicGenerator) MarshalText Uses

func (f *PublicGenerator) MarshalText() ([]byte, error)

func (*PublicGenerator) UnmarshalText Uses

func (f *PublicGenerator) UnmarshalText(text []byte) error

Package rkey imports 13 packages (graph) and is imported by 1 packages. Updated 2019-04-22. Refresh now. Tools for package owners.