keys

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2025 License: Apache-2.0 Imports: 16 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// KeyPrefix indicates a decentralized identifier that uses the key method
	KeyPrefix = "did:key"
	// MulticodecKindRSAPubKey rsa-x509-pub https://github.com/multiformats/multicodec/pull/226
	MulticodecKindRSAPubKey = 0x1205
	// MulticodecKindEd25519PubKey ed25519-pub
	MulticodecKindEd25519PubKey = 0xed
	// MulticodecKindSecp256k1PubKey secp256k1-pub
	MulticodecKindSecp256k1PubKey = 0xe7
)

Variables

This section is empty.

Functions

func GetMulticodecType

func GetMulticodecType(keyType int) (uint64, error)

GetMulticodecType returns the multicodec type for a given crypto key type. This is useful for external validation and encoding operations.

func ValidateFormat

func ValidateFormat(didString string) error

ValidateFormat validates that the DID string conforms to proper did:key format. This ensures the DID follows the W3C DID specification with proper multicodec encoding.

Types

type DID

type DID struct {
	crypto.PubKey
}

DID is a DID:key identifier

func NewDID

func NewDID(pub crypto.PubKey) (DID, error)

NewDID constructs an Identifier from a public key

func NewFromMPCPubKey

func NewFromMPCPubKey(pubKeyBytes []byte) (DID, error)

NewFromMPCPubKey creates a DID from MPC enclave public key bytes. This is specifically designed for MPC enclave integration where public key bytes are provided directly from the enclave without additional encoding.

func NewFromPubKey

func NewFromPubKey(pub PubKey) DID

NewFromPubKey constructs an Identifier from a public key

func Parse

func Parse(keystr string) (DID, error)

Parse turns a string into a key method ID

func (DID) Address

func (id DID) Address() (string, error)

Address derives a blockchain-compatible address from the DID. This provides a consistent address format for use across different blockchain contexts.

func (DID) CompressedPubKey

func (id DID) CompressedPubKey() ([]byte, error)

CompressedPubKey returns the compressed public key bytes for Secp256k1 keys. For other key types, returns the raw public key bytes.

func (DID) MulticodecType

func (id DID) MulticodecType() uint64

MulticodecType indicates the type for this multicodec

func (DID) PublicKey

func (id DID) PublicKey() crypto.PubKey

PublicKey returns the underlying crypto.PubKey

func (DID) String

func (id DID) String() string

String returns this did:key formatted as a string

func (DID) VerifyKey

func (id DID) VerifyKey() (any, error)

VerifyKey returns the backing implementation for a public key, one of: *rsa.PublicKey, ed25519.PublicKey

type DIDMethod

type DIDMethod string
const (
	DIDMethodKey      DIDMethod = "key"
	DIDMethodSonr     DIDMethod = "sonr"
	DIDMehthodBitcoin DIDMethod = "btcr"
	DIDMethodEthereum DIDMethod = "ethr"
	DIDMethodCbor     DIDMethod = "cbor"
	DIDMethodCID      DIDMethod = "cid"
	DIDMethodIPFS     DIDMethod = "ipfs"
)

func (DIDMethod) String

func (d DIDMethod) String() string

type PubKey

type PubKey interface {
	Bytes() []byte
	Raw() ([]byte, error)
	Equals(b p2pcrypto.Key) bool
	Type() p2ppb.KeyType
	Hex() string
	Verify(msg []byte, sig []byte) (bool, error)
}

func NewPubKey

func NewPubKey(pk curves.Point) PubKey

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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