did

package
v0.0.0-...-55a0270 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2022 License: Apache-2.0 Imports: 11 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// AdminDIDKey the key for ledger value of admin did
	AdminDIDKey = "admin_did"

	// InitialKey the key reference assigned to the first key in a DID Doc
	InitialKey = "key-1"

	IONDIDMethod = "did:ion:"

	// SchemaContext is the JSON-LD @context value that points to the W3C DID v1 context.
	// Workday has chosen not to use JSON-LD for DID Documents.
	// Deprecated: This field is kept for historical purposes only. New documents should exclude it.
	SchemaContext = "https://w3id.org/did/v1"
)
View Source
const (
	KeyDIDMethod = "did:key:"

	// https://tools.ietf.org/html/rfc8037#appendix-A.2
	OctetKeyPairType = "OKP"
	Ed25519Curve     = "Ed25519"
)
View Source
const (
	WorkDIDMethod = "did:work:"
)

Variables

This section is empty.

Functions

func AsVerifier

func AsVerifier(keyDef KeyDef) (proof.Verifier, error)

AsVerifier builds a verifier given a key definition that can be used to verify signed objects by the key in the definition

func ExtractEdPublicKeyFromDID

func ExtractEdPublicKeyFromDID(did DID) (ed25519.PublicKey, error)

ExtractEdPublicKeyFromDID extracts an Ed25519 Public Key from a DID Key.

func GenerateKeyID

func GenerateKeyID(did DID, fragment string) string

GenerateKeyID builds a fully qualified key reference given a DID and a key fragment

Types

type AdminDID

type AdminDID struct {
	ID DID `json:"id"`
}

Struct to contain identifier for an Admin DID

type CredentialDefinition

type CredentialDefinition struct {
	CredDefDID DID    `json:"did"`
	IssuerDID  DID    `json:"issuerDid"`
	SchemaID   string `json:"schemaId"`
}

CredentialDefinition JSON Schema Represents an identity that binds an issuer to a schema that allows specific issuance

type DID

type DID string

DID is a Decentralized Identifier conforming to https://www.w3.org/TR/did-core/#did-syntax

func ExtractDIDFromKeyRef

func ExtractDIDFromKeyRef(keyRef string) DID

ExtractDIDFromKeyRef parses a key reference in the form of DID#keyID and returns the DID. If the key reference doesn't contain a hash "#" symbol, the entire key reference is returned.

func GenerateDID

func GenerateDID(publicKey ed25519.PublicKey) DID

GenerateDID generates a Decentralized ID in the form of "did:work:<id>" based on an Ed25519 public key. Workday's DID method uses the first 16 bytes of the public key as a unique random value, assuming that the caller generates a new random key pair when creating a new ID.

func GenerateDIDFromB64PubKey

func GenerateDIDFromB64PubKey(edBase64PubKey string) (DID, error)

GenerateDIDFromB64PubKey converts a base64 encoded Ed25519 public key into a Decentralized ID. See GenerateDID.

func GenerateDIDKey

func GenerateDIDKey(publicKey ed25519.PublicKey) DID

GenerateDIDKey generates a non-registry based Decentralized DID in the form of "did:key:<id>" based on an Ed25519 public key. The DID Key Method expands a cryptographic public key into a DID Document. Note: As of May 2020, the DID Key method is still in unofficial draft (https://w3c-ccg.github.io/did-method-key)

func GenerateDIDKeyFromB64PubKey

func GenerateDIDKeyFromB64PubKey(edBase64PubKey string) (did DID, err error)

GenerateDIDKeyFromB64PubKey converts a base64 encoded Ed25519 public key into a DID Key. See GenerateDIDKey.

func (DID) HashCode

func (did DID) HashCode() string

HashCode returns the DID as a string suitable for hashing

func (DID) String

func (did DID) String() string

String returns the DID as a string (conforming to `fmt.Stringer`)

func (DID) ToShortFormDid

func (did DID) ToShortFormDid() DID

ToShortFormDid returns the short-form version of the DID

type DIDDoc

type DIDDoc struct {
	// Deprecated: left here for backward compatibility. All new DID Docs should exclude this property.
	SchemaContext        StringOrArray `json:"@context,omitempty"`
	ID                   DID           `json:"id"`
	PublicKey            []KeyDef      `json:"publicKey"`                    // Deprecated: use `VerificationMethod`
	Authentication       []KeyRef      `json:"authentication"`               // TODO: optional
	Service              []ServiceDef  `json:"service"`                      // TODO: optional
	VerificationMethod   []KeyDef      `json:"verificationMethod,omitempty"` // TODO: required
	AssertionMethod      []KeyRef      `json:"assertionMethod,omitempty"`
	CapabilityInvocation []KeyRef      `json:"capabilityInvocation,omitempty"`
	CapabilityDelegation []KeyRef      `json:"capabilityDelegation,omitempty"`
	KeyAgreement         []KeyRef      `json:"keyAgreement,omitempty"`
	AlsoKnownAs          []URI         `json:"alsoKnownAs,omitempty"`
	Controller           StringOrArray `json:"controller,omitempty"`
	Proof                *proof.Proof  `json:"proof,omitempty"`
}

DIDDoc a W3C compliant signed DID Document

func AddKeyToDIDDoc

func AddKeyToDIDDoc(doc DIDDoc, keyToAdd KeyDef, signingKey ed25519.PrivateKey, signingKeyRef string) (*DIDDoc, error)

AddKeyToDIDDoc takes a DID Doc, a key to add, and a signing key and its reference. The signing key must match the key that the current DID Doc is signed with, this is used to update the proof on the document and authenticate the update action. The check is based on the deterministic generation of the DID, which is only applicable for did:work DIDs. Conflict checking is done on the key reference.

func DeactivateDIDDoc

func DeactivateDIDDoc(doc DIDDoc, key ed25519.PrivateKey) (*DIDDoc, error)

DeactivateDIDDoc creates a deactivated DID Document. Returns an error if the Signer fails to generate the digital signature. Uses the same signature type as is on the provided DID Doc

func DeactivateDIDDocGeneric

func DeactivateDIDDocGeneric(signer proof.Signer, signatureType proof.SignatureType, did DID) (*DIDDoc, error)

DeactivateDIDDocGeneric creates a deactivated DID Document. Returns an error if the Signer fails to generate the digital signature.

func GenerateWorkDIDDoc

func GenerateWorkDIDDoc(keyType proof.KeyType, signatureType proof.SignatureType) (*DIDDoc, ed25519.PrivateKey)

func GenerateWorkDIDDocWithContext

func GenerateWorkDIDDocWithContext(keyType proof.KeyType, signatureType proof.SignatureType, context []string) (*DIDDoc, ed25519.PrivateKey)

func (*DIDDoc) GetProof

func (d *DIDDoc) GetProof() *proof.Proof

func (*DIDDoc) GetPublicKey

func (d *DIDDoc) GetPublicKey(keyID string) *KeyDef

func (*DIDDoc) GetVerificationMethod

func (d *DIDDoc) GetVerificationMethod() []KeyDef

func (*DIDDoc) IsEmpty

func (d *DIDDoc) IsEmpty() bool

func (*DIDDoc) SetProof

func (d *DIDDoc) SetProof(p *proof.Proof)

type JWK

type JWK struct {
	KTY string `json:"kty"`
	CRV string `json:"crv"`
	X   string `json:"x"`
	Y   string `json:"y,omitempty"`
}

type KeyDef

type KeyDef struct {
	ID              URI           `json:"id"`
	Type            proof.KeyType `json:"type"`
	Controller      DID           `json:"controller"`
	PublicKeyBase58 string        `json:"publicKeyBase58,omitempty"`
	PublicKeyJwk    *JWK          `json:"publicKeyJwk,omitempty"`
}

KeyDef represents a DID public key (also known as Verification Method)

func GetProofCreatorKeyDef

func GetProofCreatorKeyDef(didDoc DIDDoc) (*KeyDef, error)

GetProofCreatorKeyDef returns the Key Definition that can be used to verify the Proof on the given DID Document. This assumes that DID Documents are self-signed, which is always the case in Workday. Returns an error if the public key is not found.

func (*KeyDef) GetDecodedPublicKey

func (k *KeyDef) GetDecodedPublicKey() ([]byte, error)

func (*KeyDef) GetKeyFragment

func (k *KeyDef) GetKeyFragment() (string, error)

func (*KeyDef) IsEmpty

func (k *KeyDef) IsEmpty() bool

type KeyRef

type KeyRef struct {
	Ref *string
	Def *KeyDef
}

KeyRef is either a string or an embedded KeyDef

func (KeyRef) MarshalJSON

func (o KeyRef) MarshalJSON() ([]byte, error)

func (*KeyRef) UnmarshalJSON

func (o *KeyRef) UnmarshalJSON(data []byte) error

type ServiceDef

type ServiceDef struct {
	ID              URI         `json:"id"`
	Type            string      `json:"type"`
	ServiceEndpoint interface{} `json:"serviceEndpoint"` // string, array, or map

}

type StringOrArray

type StringOrArray []string

StringOrArray is a string or an ordered set of strings

func (StringOrArray) MarshalJSON

func (s StringOrArray) MarshalJSON() ([]byte, error)

func (*StringOrArray) UnmarshalJSON

func (s *StringOrArray) UnmarshalJSON(data []byte) error

type URI

type URI = string

URI is a string conforming to https://tools.ietf.org/html/rfc3986

Jump to

Keyboard shortcuts

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