package key

Import Path
	github.com/tmc/go-iroh/key (on go.dev)

Dependency Relation
	imports 9 packages, and imported by 11 packages

Involved Source Files Package key provides Ed25519 keys, signatures, and endpoint identifiers for go-iroh. A [SecretKey] signs messages and derives a [PublicKey]. Use [PublicKey] for cryptographic operations and [EndpointID] for network-facing endpoint identities. Keys and endpoint IDs render as lowercase hex by default; [EndpointID.Z32] returns the z-base-32 form used in pkarr names. The Go API is not stable before v1 and may change in any v0 release. key.go key_core.go
Package-Level Type Names (total 4)
/* sort by: | */
EndpointID is a network-facing identifier for an endpoint. Use EndpointID in network-facing APIs and [PublicKey] when performing cryptographic operations. Bytes returns the endpoint id as a 32-byte array. Compare returns -1, 0, or +1 comparing id and other by their raw bytes. It gives EndpointID a total order suitable for sorting and map-free ordered use. Equal reports whether id and other are the same endpoint id. IsZero reports whether id is the unusable zero value. MarshalBinary implements encoding.BinaryMarshaler, producing the 32 raw bytes. MarshalText implements encoding.TextMarshaler, producing the hex form. PublicKey returns id as a public key for cryptographic operations. Short returns a short, friendly hex string of the first 5 bytes of the endpoint id, for logging. It is not a complete or parseable representation. String returns the lowercase-hex encoding of the endpoint id. It is the canonical human-readable form and round-trips through [ParseEndpointID]. UnmarshalBinary implements encoding.BinaryUnmarshaler from 32 raw bytes. UnmarshalText implements encoding.TextUnmarshaler, parsing the hex or base32 form. Z32 encodes the endpoint id in z-base-32, the encoding used by pkarr domain names. EndpointID : encoding.BinaryMarshaler *EndpointID : encoding.BinaryUnmarshaler EndpointID : encoding.TextMarshaler *EndpointID : encoding.TextUnmarshaler EndpointID : expvar.Var EndpointID : fmt.Stringer EndpointID : gopkg.in/yaml.v3.IsZeroer func EndpointIDFromSlice(b []byte) (EndpointID, error) func NewEndpointID(b [32]byte) (EndpointID, error) func ParseEndpointID(s string) (EndpointID, error) func ParseEndpointIDZ32(s string) (EndpointID, error) func PublicKey.EndpointID() EndpointID func github.com/tmc/go-iroh/internal/socket.Addr.Relay() (netaddr.RelayURL, EndpointID, bool) func github.com/tmc/go-iroh/internal/socket.(*RemoteStateActor).ID() EndpointID func github.com/tmc/go-iroh/internal/socket.(*Socket).LookupEndpointID(m socket.EndpointIDMappedAddr) (EndpointID, bool) func github.com/tmc/go-iroh/iroh.(*Conn).RemoteID() EndpointID func github.com/tmc/go-iroh/iroh.(*Connecting).RemoteID() EndpointID func github.com/tmc/go-iroh/iroh.(*Endpoint).ID() EndpointID func github.com/tmc/go-iroh/iroh.Item.EndpointID() EndpointID func EndpointID.Compare(other EndpointID) int func EndpointID.Equal(other EndpointID) bool func github.com/tmc/go-iroh/dns.(*Resolver).LookupEndpointByID(ctx context.Context, id EndpointID, origin string) (dns.EndpointInfo, error) func github.com/tmc/go-iroh/internal/socket.RelayAddr(url netaddr.RelayURL, eid EndpointID) socket.Addr func github.com/tmc/go-iroh/internal/socket.(*RemoteMap).Actor(id EndpointID) *socket.RemoteStateActor func github.com/tmc/go-iroh/internal/socket.(*RemoteMap).AddConnection(remote EndpointID, conn socket.Connection) <-chan socket.PathEvent func github.com/tmc/go-iroh/internal/socket.(*RemoteMap).AddConnectionActor(remote EndpointID, conn socket.Connection) (<-chan socket.PathEvent, *socket.RemoteStateActor) func github.com/tmc/go-iroh/internal/socket.(*RemoteMap).RemoteInfo(id EndpointID) (socket.RemoteInfo, bool) func github.com/tmc/go-iroh/internal/socket.(*Socket).EndpointIDMappedAddrFor(id EndpointID) socket.EndpointIDMappedAddr func github.com/tmc/go-iroh/internal/socket.(*Socket).EvictRemote(id EndpointID, addrs []socket.Addr) func github.com/tmc/go-iroh/internal/socket.(*Socket).PathAddr(remoteID EndpointID, ra net.Addr) socket.Addr func github.com/tmc/go-iroh/internal/socket.(*Socket).RelayMappedAddrFor(url netaddr.RelayURL, eid EndpointID) socket.RelayMappedAddr func github.com/tmc/go-iroh/iroh.ServerName(id EndpointID) string func github.com/tmc/go-iroh/iroh.(*AddressLookupServices).Resolve(ctx context.Context, id EndpointID) iter.Seq2[iroh.Item, error] func github.com/tmc/go-iroh/iroh.AddressResolver.Resolve(ctx context.Context, id EndpointID) iter.Seq2[iroh.Item, error] func github.com/tmc/go-iroh/iroh.AddressResolverFunc.Resolve(ctx context.Context, id EndpointID) iter.Seq2[iroh.Item, error] func github.com/tmc/go-iroh/iroh.(*DNSAddressLookup).Resolve(ctx context.Context, id EndpointID) iter.Seq2[iroh.Item, error] func github.com/tmc/go-iroh/iroh.(*Endpoint).RemoteInfo(remote EndpointID) (iroh.RemoteInfo, bool) func github.com/tmc/go-iroh/iroh.(*MemoryLookup).GetEndpointInfo(id EndpointID) (dns.EndpointInfo, bool) func github.com/tmc/go-iroh/iroh.(*MemoryLookup).RemoveEndpointInfo(id EndpointID) (dns.EndpointInfo, bool) func github.com/tmc/go-iroh/iroh.(*MemoryLookup).Resolve(ctx context.Context, id EndpointID) iter.Seq2[iroh.Item, error] func github.com/tmc/go-iroh/iroh.(*PkarrResolver).Resolve(ctx context.Context, id EndpointID) iter.Seq2[iroh.Item, error] func github.com/tmc/go-iroh/iroh.(*StaticLookup).Resolve(ctx context.Context, id EndpointID) iter.Seq2[iroh.Item, error] func github.com/tmc/go-iroh/netaddr.NewEndpointAddr(id EndpointID, addrs ...netaddr.TransportAddr) netaddr.EndpointAddr
PublicKey is a public Ed25519 key. It is verified to be a valid curve point when created. The zero value is not usable; construct a PublicKey with [NewPublicKey], [ParsePublicKey], or [SecretKey.Public]. Bytes returns the public key as a 32-byte array. Compare returns -1, 0, or +1 comparing k and other by their raw bytes. It gives PublicKey a total order suitable for sorting and map-free ordered use. Ed25519 returns the key as a crypto/ed25519 public key. The returned slice is a copy and may be modified by the caller. EndpointID returns the endpoint identifier for k. Equal reports whether k and other are the same key. IsZero reports whether k is the unusable zero value. MarshalBinary implements encoding.BinaryMarshaler, producing the 32 raw bytes. MarshalText implements encoding.TextMarshaler, producing the hex form. Short returns a short, friendly hex string of the first 5 bytes of the key, for logging. It is not a complete or parseable representation. String returns the lowercase-hex encoding of the key. It is the canonical human-readable form and round-trips through [ParsePublicKey]. UnmarshalBinary implements encoding.BinaryUnmarshaler from 32 raw bytes. UnmarshalText implements encoding.TextUnmarshaler, parsing the hex or base32 form. Verify reports whether sig is a valid signature of message by k. It returns nil on success and [ErrInvalidSignature] otherwise. Verification uses crypto/ed25519 (cofactored, RFC 8032). The Rust reference uses ed25519-dalek's verify_strict (cofactorless). The two agree for every signature an honest iroh peer produces; they differ only for adversarially malleable signatures, which iroh drops anyway. This divergence is benign for iroh's drop-on-failure model (relay handshake, TLS raw-key, and pkarr packet verification all reject on failure). PublicKey : encoding.BinaryMarshaler *PublicKey : encoding.BinaryUnmarshaler PublicKey : encoding.TextMarshaler *PublicKey : encoding.TextUnmarshaler PublicKey : expvar.Var PublicKey : fmt.Stringer PublicKey : gopkg.in/yaml.v3.IsZeroer func NewPublicKey(b [32]byte) (PublicKey, error) func ParsePublicKey(s string) (PublicKey, error) func PublicKeyFromEd25519(k ed25519.PublicKey) (PublicKey, error) func PublicKeyFromSlice(b []byte) (PublicKey, error) func EndpointID.PublicKey() PublicKey func SecretKey.Public() PublicKey func github.com/tmc/go-iroh/dns.(*SignedPacket).PublicKey() PublicKey func github.com/tmc/go-iroh/internal/pkarr.(*SignedPacket).PublicKey() PublicKey func PublicKey.Compare(other PublicKey) int func PublicKey.Equal(other PublicKey) bool func github.com/tmc/go-iroh/internal/pkarr.FromRelayPayload(pub PublicKey, payload []byte) (*pkarr.SignedPacket, error)
SecretKey is a secret endpoint identity key. Its public part can always be recovered. Go has no destructors, so unlike the Rust original this type is not cleared automatically. Call [SecretKey.Clear] to overwrite the key material when a long-lived secret is no longer needed. The zero value is not usable; construct with [GenerateSecretKey], [NewSecretKey], or [ParseSecretKey]. Bytes returns the 32-byte seed of the secret key. The public part can be recovered from it. Clear overwrites k's key material and resets k to the zero value. It does not clear copies already made by value or by [SecretKey.Bytes], [SecretKey.Ed25519], or [SecretKey.MarshalBinary]. Ed25519 returns the key as a crypto/ed25519 private key. The returned key is a copy and satisfies crypto.Signer. IsZero reports whether k is the unusable zero value. MarshalBinary implements encoding.BinaryMarshaler, producing the 32-byte seed. Public returns the public key of this secret key. Sign signs msg and returns the signature. UnmarshalBinary implements encoding.BinaryUnmarshaler from a 32-byte seed. SecretKey : encoding.BinaryMarshaler *SecretKey : encoding.BinaryUnmarshaler SecretKey : gopkg.in/yaml.v3.IsZeroer func GenerateSecretKey() (SecretKey, error) func NewSecretKey(seed [32]byte) SecretKey func ParseSecretKey(s string) (SecretKey, error) func SecretKeyFromEd25519(k ed25519.PrivateKey) (SecretKey, error) func SecretKeyFromSlice(b []byte) (SecretKey, error) func github.com/tmc/go-iroh/iroh.(*Endpoint).SecretKey() SecretKey func github.com/pancsta/asyncmachine-go/pkg/rpc.GenerateSecretKey() (SecretKey, error) func github.com/tmc/go-iroh/dns.EndpointInfo.ToSignedPacket(secretKey SecretKey, ttl uint32) (*dns.SignedPacket, error) func github.com/tmc/go-iroh/internal/pkarr.FromTxtStrings(sk SecretKey, name string, values []string, ttl uint32) (*pkarr.SignedPacket, error) func github.com/tmc/go-iroh/internal/relayproto.NewClientAuth(secretKey SecretKey, challenge relayproto.ServerChallenge) relayproto.ClientAuth func github.com/tmc/go-iroh/internal/relayproto.NewKeyMaterialClientAuth(secretKey SecretKey, state *tls.ConnectionState) (relayproto.KeyMaterialClientAuth, error) func github.com/tmc/go-iroh/iroh.N0PkarrPublisher(secretKey SecretKey, cfg *iroh.PkarrPublisherConfig) (*iroh.PkarrPublisher, error) func github.com/tmc/go-iroh/iroh.NewPkarrPublisher(secretKey SecretKey, relayURL string, cfg *iroh.PkarrPublisherConfig) (*iroh.PkarrPublisher, error) func github.com/tmc/go-iroh/iroh.WithSecretKey(sk SecretKey) iroh.Option
Signature is a signature produced by a [SecretKey]. Bytes returns the signature as a 64-byte array. Ed25519 returns the signature bytes used by crypto/ed25519. The returned slice is a copy and may be modified by the caller. Equal reports whether s and other are the same signature. MarshalBinary implements encoding.BinaryMarshaler, producing the 64 raw signature bytes. MarshalText implements encoding.TextMarshaler, producing the hex form. String returns the lowercase-hex encoding of the signature. UnmarshalBinary implements encoding.BinaryUnmarshaler from 64 raw bytes. UnmarshalText implements encoding.TextUnmarshaler, parsing the hex form. Signature : encoding.BinaryMarshaler *Signature : encoding.BinaryUnmarshaler Signature : encoding.TextMarshaler *Signature : encoding.TextUnmarshaler Signature : expvar.Var Signature : fmt.Stringer func NewSignature(b [64]byte) Signature func SignatureFromEd25519(sig []byte) (Signature, error) func SignatureFromSlice(b []byte) (Signature, error) func SecretKey.Sign(msg []byte) Signature func github.com/tmc/go-iroh/internal/pkarr.(*SignedPacket).Signature() Signature func PublicKey.Verify(message []byte, sig Signature) error func Signature.Equal(other Signature) bool
Package-Level Functions (total 16)
EndpointIDFromSlice constructs an EndpointID from a byte slice.
GenerateSecretKey generates a new SecretKey using crypto/ed25519.
NewEndpointID constructs an EndpointID from a 32-byte array.
NewPublicKey constructs a PublicKey from a 32-byte array. It returns [ErrInvalidKeyData] if the bytes do not decompress to a valid Ed25519 curve point. It never fails for bytes returned from [PublicKey.Bytes].
NewSecretKey constructs a SecretKey from its 32-byte seed.
NewSignature constructs a Signature from its 64 raw bytes.
ParseEndpointID parses an EndpointID from its hex or base32 string form.
ParseEndpointIDZ32 parses an endpoint id from its z-base-32 encoding.
ParsePublicKey parses a PublicKey from its hex or base32 string form. A string of exactly 64 characters is decoded as lowercase hex; otherwise it is decoded as RFC 4648 base32 (no padding, case-insensitive). [PublicKey.String] always produces the hex form.
ParseSecretKey parses a SecretKey from its hex or base32 string form, matching the rules of [ParsePublicKey].
PublicKeyFromEd25519 constructs a PublicKey from a crypto/ed25519 public key.
PublicKeyFromSlice constructs a PublicKey from a byte slice. It returns [ErrInvalidKeyLength] if the slice is not 32 bytes and [ErrInvalidKeyData] if the bytes are not a valid curve point.
SecretKeyFromEd25519 constructs a SecretKey from a crypto/ed25519 private key. The private key is copied.
SecretKeyFromSlice constructs a SecretKey from a 32-byte seed slice. It returns [ErrInvalidKeyLength] if the slice is not 32 bytes.
SignatureFromEd25519 constructs a Signature from a crypto/ed25519 signature.
SignatureFromSlice constructs a Signature from a byte slice. It returns [ErrInvalidSignatureParse] if the slice is not 64 bytes.
Package-Level Variables (total 6)
ErrDecodeBase32 is returned when a string cannot be decoded as base32.
ErrDecodeHex is returned when a string cannot be decoded as hex.
ErrInvalidKeyData is returned when bytes do not represent a valid Ed25519 curve point.
ErrInvalidKeyLength is returned when key bytes have the wrong length.
ErrInvalidSignature is returned when signature verification fails.
ErrInvalidSignatureParse is returned when bytes cannot be parsed as an Ed25519 signature.
Package-Level Constants (total 4)
PrivateKeySize is the size of an Ed25519 private key, in bytes.
PublicKeySize is the size of an Ed25519 public key, in bytes.
SeedSize is the size of an Ed25519 private key seed, in bytes.
SignatureSize is the size of an Ed25519 signature, in bytes.