cryptosuite

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	W3CSecurityContext                  string = "https://w3id.org/security/v2"
	Ed25519VerificationKey2020Context   string = "https://w3id.org/security/suites/ed25519-2020/v1"
	X25519KeyAgreementKey2020Context    string = "https://w3id.org/security/suites/x25519-2020/v1"
	SECP256k1VerificationKey2019Context string = "https://w3id.org/security/suites/secp256k1-2019/v1"
	JSONWebKey2020Context               string = "https://w3id.org/security/suites/jws-2020/v1"
	Multikey2021Context                 string = "https://w3id.org/security/suites/multikey-2021/v1"
	BLS12381G2Key2020Context            string = "https://w3id.org/security/suites/bls12381-2020/v1"

	AssertionMethod ProofPurpose = "assertionMethod"
	Authentication  ProofPurpose = "authentication"

	JWTFormat PayloadFormat = "jwt"
	LDPFormat PayloadFormat = "ldp"
)

Variables

This section is empty.

Functions

func EnsureRequiredContexts

func EnsureRequiredContexts(context []any, requiredContexts []string) []any

EnsureRequiredContexts attempt to verify that string context(s) exist in the context interface

func GetContextsFromProvable

func GetContextsFromProvable(p WithEmbeddedProof) ([]any, error)

GetContextsFromProvable searches from a Linked Data `@context` property in the document and returns the value associated with the context, if it exists.

Types

type CryptoSuite

type CryptoSuite interface {
	CryptoSuiteInfo

	// Sign https://w3c-ccg.github.io/data-integrity-spec/#proof-algorithm
	// this method mutates the provided provable object, adding a `proof` block`
	Sign(s Signer, p WithEmbeddedProof) error
	// Verify https://w3c-ccg.github.io/data-integrity-spec/#proof-verification-algorithm
	Verify(v Verifier, p WithEmbeddedProof) error
}

CryptoSuite encapsulates the behavior of a proof type as per the W3C specification on data integrity https://w3c-ccg.github.io/data-integrity-spec/#creating-new-proof-types

type CryptoSuiteInfo

type CryptoSuiteInfo interface {
	ID() string
	Type() LDKeyType
	CanonicalizationAlgorithm() string
	MessageDigestAlgorithm() gocrypto.Hash
	SignatureAlgorithm() SignatureType
	RequiredContexts() []string
}

type CryptoSuiteProofType

type CryptoSuiteProofType interface {
	Marshal(data any) ([]byte, error)
	Canonicalize(marshaled []byte) (*string, error)
	// CreateVerifyHash https://www.w3.org/community/reports/credentials/CG-FINAL-data-integrity-20220722/#create-verify-hash-algorithm
	CreateVerifyHash(doc map[string]any, proof crypto.Proof, proofOptions *ProofOptions) ([]byte, error)
	// Digest runs a given digest algorithm https://www.w3.org/community/reports/credentials/CG-FINAL-data-integrity-20220722/#dfn-message-digest-algorithm
	// on a canonizliaed document prior to signing. Sometimes implementations will be a no-op as digesting is handled
	// by the signature algorithm itself.
	Digest(tbd []byte) ([]byte, error)
}

CryptoSuiteProofType is an interface that defines functionality needed to sign and verify data It encapsulates the functionality defined by the data integrity proof type specification https://www.w3.org/community/reports/credentials/CG-FINAL-data-integrity-20220722/#creating-new-proof-types

type GenericProvable

type GenericProvable map[string]any

GenericProvable represents a provable that is not constrained by a specific type

func (*GenericProvable) GetProof

func (g *GenericProvable) GetProof() *crypto.Proof

func (*GenericProvable) SetProof

func (g *GenericProvable) SetProof(p *crypto.Proof)

type LDKeyType

type LDKeyType string
const (
	JSONWebKey2020Type                LDKeyType = "JsonWebKey2020"
	X25519KeyAgreementKey2020         LDKeyType = "X25519KeyAgreementKey2020"
	Ed25519VerificationKey2020        LDKeyType = "Ed25519VerificationKey2020"
	X25519KeyAgreementKey2019         LDKeyType = "X25519KeyAgreementKey2019"
	Ed25519VerificationKey2018        LDKeyType = "Ed25519VerificationKey2018"
	ECDSASECP256k1VerificationKey2019 LDKeyType = "EcdsaSecp256k1VerificationKey2019"
	MultikeyType                      LDKeyType = "Multikey"
	P256Key2021                       LDKeyType = "P256Key2021"
	P384Key2021                       LDKeyType = "P384Key2021"
	P521Key2021                       LDKeyType = "P521Key2021"
	BLS12381G1Key2020                 LDKeyType = "Bls12381G1Key2020"
	BLS12381G2Key2020                 LDKeyType = "Bls12381G2Key2020"
)

func (LDKeyType) String

func (ld LDKeyType) String() string

type PayloadFormat

type PayloadFormat string

type ProofOptions

type ProofOptions struct {
	// JSON-LD contexts to add to the proof
	Contexts []any

	// Indexes of the credential subject to require be revealed in BBS+ signatures
	RevealIndexes []int
}

type ProofPurpose

type ProofPurpose string

type SignatureType

type SignatureType string

type Signer

type Signer interface {
	Sign(tbs []byte) ([]byte, error)

	GetKeyID() string
	GetSignatureType() SignatureType
	GetSigningAlgorithm() string

	SetProofPurpose(purpose ProofPurpose)
	GetProofPurpose() ProofPurpose

	SetPayloadFormat(format PayloadFormat)
	GetPayloadFormat() PayloadFormat
}

type Verifier

type Verifier interface {
	Verify(message, signature []byte) error
	GetKeyID() string
}

type WithEmbeddedProof

type WithEmbeddedProof interface {
	GetProof() *crypto.Proof
	SetProof(p *crypto.Proof)
}

WithEmbeddedProof is an interface that defines functionality needed to get/set proofs on objects with embedded proofs

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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