key

package
v0.0.0-...-3eefbbf Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2023 License: Apache-2.0 Imports: 16 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// Prefix did:key prefix
	Prefix = "did:key"

	// Expansion options
	EnableEncryptionKeyDerivationOption = "EnableEncryptionKeyDerivation"
	PublicKeyFormatOption               = "PublicKeyFormat"
)

Variables

View Source
var (
	EnableEncryptionKeyDerivation = Option{
		Name:  EnableEncryptionKeyDerivationOption,
		Value: true,
	}

	DisableEncryptionKeyDerivation = Option{
		Name:  EnableEncryptionKeyDerivationOption,
		Value: false,
	}

	PublicKeyFormatJSONWebKey2020 = Option{
		Name:  PublicKeyFormatOption,
		Value: cryptosuite.JSONWebKey2020Type,
	}

	PublicKeyFormatMultibase = Option{
		Name:  PublicKeyFormatOption,
		Value: cryptosuite.MultikeyType,
	}
)

Functions

func GetSupportedDIDKeyTypes

func GetSupportedDIDKeyTypes() []crypto.KeyType

func IsSupportedDIDKeyType

func IsSupportedDIDKeyType(kt crypto.KeyType) bool

func MultibaseEncodedKey

func MultibaseEncodedKey(kt crypto.KeyType, publicKey []byte) (string, error)

MultibaseEncodedKey takes a key type and a public key value and returns the multibase encoded key

Types

type DIDKey

type DIDKey string

func CreateDIDKey

func CreateDIDKey(kt crypto.KeyType, publicKey []byte) (*DIDKey, error)

CreateDIDKey constructs a did:key from a specific key type and its corresponding public key This method does not attempt to validate that the provided public key is of the specified key type. A safer method is `GenerateDIDKey` which handles key generation based on the provided key type.

func GenerateDIDKey

func GenerateDIDKey(kt crypto.KeyType) (gocrypto.PrivateKey, *DIDKey, error)

GenerateDIDKey takes in a key type value that this library supports and constructs a conformant did:key identifier. The function returns the associated private key value cast to the generic golang crypto.PrivateKey interface. To use the private key, it is recommended to re-cast to the associated type. For example, called with the input for a secp256k1 key: privKey, didKey, err := GenerateDIDKey(SECP256k1) if err != nil { ... } // where secp is an import alias to the secp256k1 library we use "github.com/decred/dcrd/dcrec/secp256k1/v4" secpPrivKey, ok := privKey.(secp.PrivateKey) if !ok { ... }

func (DIDKey) Decode

func (d DIDKey) Decode() ([]byte, crypto.KeyType, error)

Decode takes a did:key and returns the underlying public key value as bytes, the key type, and a possible error https://w3c-ccg.github.io/did-method-key/#document-creation-algorithm

func (DIDKey) Expand

func (d DIDKey) Expand(opts ...Option) (*did.Document, error)

Expand turns the DID key into a compliant DID Document Accepts the following options:

  • EnableEncryptionKeyDerivationOption (default to true)
  • PublicKeyFormatOption (defaults to JWK)

TODO(gabe) support BLS curves https://github.com/decentralgabe/ssi-sdk/issues/381

func (DIDKey) IsValid

func (d DIDKey) IsValid() bool

func (DIDKey) Method

func (DIDKey) Method() did.Method

func (DIDKey) String

func (d DIDKey) String() string

func (DIDKey) Suffix

func (d DIDKey) Suffix() (string, error)

Suffix returns the value without the `did:key` prefix

type Option

type Option struct {
	Name  string
	Value any
}

type Resolver

type Resolver struct{}

func (Resolver) Methods

func (Resolver) Methods() []did.Method

func (Resolver) Resolve

Jump to

Keyboard shortcuts

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