Documentation ¶
Index ¶
- Constants
- Variables
- func ExtractEncoding(v string) (mbase.Encoding, error)
- func NewTokenContext(ctx context.Context, token Token) context.Context
- func ToAddr(id ID) ma.Multiaddr
- type Credentials
- type ID
- func (i ID) Bytes() []byte
- func (i ID) Defined() bool
- func (i ID) Encode(base mbase.Encoder) string
- func (i ID) Equals(o ID) bool
- func (i ID) KeyString() string
- func (i ID) Loggable() map[string]interface{}
- func (i ID) MarshalBinary() ([]byte, error)
- func (i ID) MarshalText() ([]byte, error)
- func (i ID) String() string
- func (i ID) StringOfBase(base mbase.Encoding) (string, error)
- func (i *ID) UnmarshalBinary(data []byte) error
- func (i *ID) UnmarshalText(text []byte) error
- func (i ID) Variant() Variant
- func (i ID) Version() uint64
- type IDSlice
- type Identity
- type Info
- type Key
- type Libp2pIdentity
- type Libp2pPubKey
- type LogInfo
- type PubKey
- type Token
- type Variant
Constants ¶
const ( // Name is the protocol slug. Name = "thread" // Code is the protocol code. Code = 406 // Version is the current protocol version. Version = "0.0.1" // Protocol is the threads protocol tag. Protocol protocol.ID = "/" + Name + "/" + Version )
const (
V1 = 0x01
)
Versions.
Variables ¶
var ( // ErrVarintBuffSmall means that a buffer passed to the ID parser was not // long enough, or did not contain an invalid ID. ErrVarintBuffSmall = fmt.Errorf("reading varint: buffer too small") // ErrVarintTooBig means that the varint in the given ID was above the // limit of 2^64. ErrVarintTooBig = fmt.Errorf("reading varint: varint bigger than 64bits" + " and not supported") // ErrIDTooShort means that the ID passed to decode was not long // enough to be a valid ID. ErrIDTooShort = fmt.Errorf("id too short") )
var ( // ErrInvalidKey indicates an invalid byte slice was given to KeyFromBytes. ErrInvalidKey = fmt.Errorf("invalid key") )
var ErrInvalidToken = fmt.Errorf("invalid thread token")
ErrInvalidToken indicates the token is invalid.
var ErrTokenNotFound = fmt.Errorf("thread token not found")
ErrTokenNotFound indicates the token was not found in the context.
var Undef = ID{}
Undef can be used to represent a nil or undefined Cid, using Cid{} directly is also acceptable.
Functions ¶
func ExtractEncoding ¶
Extract the encoding from an ID. If Decode on the same string did not return an error neither will this function.
func NewTokenContext ¶ added in v0.1.13
NewTokenContext adds Token to a context.
Types ¶
type Credentials ¶ added in v0.1.13
type Credentials struct {
Secure bool
}
Credentials implements PerRPCCredentials, allowing context values to be included in request metadata.
func (Credentials) GetRequestMetadata ¶ added in v0.1.13
func (Credentials) RequireTransportSecurity ¶ added in v0.1.13
func (c Credentials) RequireTransportSecurity() bool
type ID ¶
type ID struct {
// contains filtered or unexported fields
}
ID represents a self-describing thread identifier. It is formed by a Version, a Variant, and a random number of a given length.
func Cast ¶
Cast takes an ID data slice, parses it and returns an ID. For IDV1, the data buffer is in the form:
<version><variant><random-number>
Please use decode when parsing a regular ID string, as Cast does not expect multibase-encoded data. Cast accepts the output of ID.Bytes().
func Decode ¶
Decode parses an ID-encoded string and returns an ID object. For IDV1, an ID-encoded string is primarily a multibase string:
<multibase-type-code><base-encoded-string>
The base-encoded string represents a:
<version><variant><random-number>
func (ID) Bytes ¶
Bytes returns the byte representation of an ID. The output of bytes can be parsed back into an ID with Cast().
func (ID) Defined ¶
Defined returns true if an ID is defined. Calling any other methods on an undefined ID will result in undefined behavior.
func (ID) Encode ¶
Encode return the string representation of an ID in a given base when applicable.
func (ID) Loggable ¶
Loggable returns a Loggable (as defined by https://godoc.org/github.com/ipfs/go-log).
func (ID) MarshalBinary ¶
MarshalBinary is equivalent to Bytes(). It implements the encoding.BinaryMarshaler interface.
func (ID) MarshalText ¶
MarshalText is equivalent to String(). It implements the encoding.TextMarshaler interface.
func (ID) String ¶
String returns the default string representation of an ID. Currently, Base32 is used as the encoding for the multibase string.
func (ID) StringOfBase ¶
String returns the string representation of an ID encoded is selected base.
func (*ID) UnmarshalBinary ¶
UnmarshalBinary is equivalent to Cast(). It implements the encoding.BinaryUnmarshaler interface.
func (*ID) UnmarshalText ¶
UnmarshalText is equivalent to Decode(). It implements the encoding.TextUnmarshaler interface.
type Identity ¶ added in v0.1.13
type Identity interface { // Sign the given bytes cryptographically. Sign(context.Context, []byte) ([]byte, error) // Return a public key paired with this identity. GetPublic() PubKey }
Identity represents an entity capable of signing a message and returning the associated public key for verification. In many cases, this will just be a private key, but callers can use any setup that suits their needs.
func NewLibp2pIdentity ¶ added in v0.1.13
NewLibp2pIdentity returns a new Libp2pIdentity.
type Key ¶ added in v0.1.12
type Key struct {
// contains filtered or unexported fields
}
Key is a thread encryption key with two components. Service key is used to encrypt outer log record linkages. Read key is used to encrypt inner record events.
func KeyFromBytes ¶ added in v0.1.12
KeyFromBytes returns a key by wrapping k.
func KeyFromString ¶ added in v0.1.12
KeyFromString returns a key by decoding a base32-encoded string.
func NewRandomKey ¶ added in v0.1.12
func NewRandomKey() Key
NewRandomKey returns a random key, which includes a service and read key.
func NewRandomServiceKey ¶ added in v0.1.12
func NewRandomServiceKey() Key
NewRandomServiceKey returns a random service-only key.
func NewServiceKey ¶ added in v0.1.12
NewServiceKey wraps a service-only key.
func (Key) Defined ¶ added in v0.1.12
Defined returns whether or not key has any defined components. Since it's not possible to have a read key w/o a service key, we just need to check service key.
func (Key) MarshalBinary ¶ added in v0.1.12
MarshalBinary implements BinaryMarshaler.
func (Key) String ¶ added in v0.1.12
String returns the base32-encoded string representation of raw key bytes. For example, Full: "brv7t5l2h55uklz5qwpntcat26csaasfchzof3emmdy6povabcd3a2to2qdkqdkto2prfhizerqqudqsdvwherbiy4nazqxjejgdr4oy" Service: "bp2vvqody5zm6yqycsnazb4kpqvycbdosos352zvpsorxce5koh7q"
type Libp2pIdentity ¶ added in v0.1.13
Libp2pIdentity wraps crypto.PrivKey, overwriting GetPublic with thread.PubKey.
func (*Libp2pIdentity) GetPublic ¶ added in v0.1.13
func (p *Libp2pIdentity) GetPublic() PubKey
type Libp2pPubKey ¶ added in v0.1.13
Libp2pPubKey wraps crypto.PubKey.
func (*Libp2pPubKey) MarshalBinary ¶ added in v0.1.13
func (p *Libp2pPubKey) MarshalBinary() ([]byte, error)
func (*Libp2pPubKey) String ¶ added in v0.1.13
func (p *Libp2pPubKey) String() string
func (*Libp2pPubKey) UnmarshalBinary ¶ added in v0.1.13
func (p *Libp2pPubKey) UnmarshalBinary(bytes []byte) (err error)
func (*Libp2pPubKey) UnmarshalString ¶ added in v0.1.13
func (p *Libp2pPubKey) UnmarshalString(str string) error
type LogInfo ¶
type LogInfo struct { ID peer.ID PubKey crypto.PubKey PrivKey crypto.PrivKey Addrs []ma.Multiaddr Head cid.Cid }
LogInfo holds log keys, addresses, and heads.
type PubKey ¶ added in v0.1.13
type PubKey interface { encoding.BinaryMarshaler encoding.BinaryUnmarshaler // String encodes the public key into a base64 string. fmt.Stringer // UnmarshalString decodes a public key from a base64 string. UnmarshalString(string) error // Verify that 'sig' is the signed hash of 'data' Verify(data []byte, sig []byte) (bool, error) }
Pubkey can be anything that provides a verify method.
func NewLibp2pPubKey ¶ added in v0.1.13
NewLibp2pPubKey returns a new PubKey.
func ValidateToken ¶ added in v0.1.13
ValidateToken returns non-nil if token was issued by issuer. If token is present and valid, the embedded public key is returned. If token is not present, both the returned public key and error will be nil.
type Token ¶ added in v0.1.13
type Token string
Token is a concrete type for a JWT token string, which provides a claim to an identity.
func NewToken ¶ added in v0.1.13
NewToken issues a new JWT token from issuer for the given pubic key.
func NewTokenFromMD ¶ added in v0.1.13
NewTokenFromMD returns Token from the given context, if present.