multikey

package
v0.0.0-...-79141c5 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: Apache-2.0, MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeriveVerificationMethod

func DeriveVerificationMethod(id did.URL, v Verifier) did.VerificationMethod

func DeriveVerifier

func DeriveVerifier(_ context.Context, mat did.VerificationMaterial) (ucan.Verifier, error)

DeriveVerifier produces a ucan.Verifier from Multikey did.VerificationMaterial.

func FormatSigner

func FormatSigner(signer Signer) string

Format formats a multikey.Signer into a multibase encoded string (Base64pad).

func FormatVerifier

func FormatVerifier(verifier Verifier) string

Format formats a multikey.Verifier into a multibase encoded string (Base58BTC).

func KeyDID

func KeyDID(v Verifier) did.DID

KeyDID returns the `did:key` DID corresponding to the given Verifier's public key. This may not be the same DID that is using this key in some particular context, but it's a DID that *can* use it, and is the only `did:key` DID that can use it. If this key was found on a `did:key` DID, then this is by definition the DID it was found on. If this key was found on, for example, a `did:web` DID, then this is not.

func NewIssuer

func NewIssuer(did did.DID, signer Signer) issuer

NewIssuer creates a new multikey Issuer with the given DID and multikey signer. The two may be completely unrelated: creating a useful Issuer is the caller's responsibility.

func Register

func Register(code multicodec.Code, d Decoder)

Register registers a Decoder for a given Multicodec code. The code should be the Multicodec code tagged `key` in the multicodec table.

Types

type Decoder

type Decoder func([]byte) (Verifier, error)

Decoder decodes multiformat-tagged public key bytes into a Verifier.

type Issuer

type Issuer interface {
	ucan.Principal
	Signer
	String() string
}

Issuer is a ucan.Issuer whose signer is specifically a multikey Signer.

func KeyIssuer

func KeyIssuer(s Signer) Issuer

KeyIssuer wraps a Signer to produce a ucan.Issuer using the signer's KeyDID as the issuer DID.

type Signer

type Signer interface {
	ucan.Signer

	Code() multicodec.Code

	// Bytes returns the private key bytes with multiformats prefix varint.
	Bytes() []byte

	// Raw returns the bytes of the private key without multiformats tags.
	Raw() []byte

	// PrivateKey returns the private key in whatever format the underlying
	// implementation uses. Where possible, this should be a type that
	// ["crypto/x509".MarshalPKCS8PrivateKey] supports.
	PrivateKey() any

	// PublicKey returns the public key in whatever format the underlying
	// implementation uses. Where possible, this should be a type that
	// ["crypto/x509".MarshalPKIXPublicKey] supports.
	PublicKey() any

	// KeyDID is a convenience for `Verifier().KeyDID()`.
	KeyDID() did.DID
}

Signer is a multikey signer. It contains the private key bytes and can sign with them.

type Verifier

type Verifier interface {
	ucan.Verifier

	Code() multicodec.Code

	// Bytes returns the public key bytes with multiformats prefix varint.
	Bytes() []byte

	// Raw returns the bytes of the public key without multiformats tags.
	Raw() []byte

	// PublicKey returns the public key in whatever format the underlying
	// implementation uses. Where possible, this should be a type that
	// ["crypto/x509".MarshalPKIXPublicKey] supports.
	PublicKey() any

	// KeyDID returns the `did:key` DID corresponding to this Verifier's public
	// key (which is not necessarily the same DID as the issuer of a token this
	// Verifier can verify).
	KeyDID() did.DID
}

Verifier is a multikey verifier. It contains the public key bytes and can verify signatures with them.

func Parse

func Parse(mk string) (Verifier, error)

Parses a Multikey string into a Verifier.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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