harness

package
v0.5.13 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2026 License: BSD-2-Clause Imports: 12 Imported by: 0

Documentation

Overview

Package harness provides shared test infrastructure for DIDComm interoperability testing.

Index

Constants

View Source
const (
	AliceDID = "did:example:alice"
	BobDID   = "did:example:bob"
)

TestDIDs are the DIDs used in interop tests.

Variables

This section is empty.

Functions

func ExtractDIDFromKeyID

func ExtractDIDFromKeyID(keyID string) string

ExtractDIDFromKeyID extracts the DID from a key ID (DID URL).

Types

type KeyPair

type KeyPair struct {
	KID        string
	PrivateJWK jwk.Key
	PublicJWK  jwk.Key
	PrivateRaw any
	PublicRaw  any
}

KeyPair holds a private/public key pair in JWK format.

func (*KeyPair) ToJSON

func (kp *KeyPair) ToJSON() (string, error)

ToJSON returns the key pair as JSON for debugging.

type MockDIDDocument

type MockDIDDocument struct {
	ID                 string
	KeyAgreement       []MockVerificationMethod
	Authentication     []MockVerificationMethod
	AssertionMethod    []MockVerificationMethod
	VerificationMethod []MockVerificationMethod
	Service            []MockService
}

MockDIDDocument represents a simplified DID Document for testing.

type MockKeyStore

type MockKeyStore struct {
	// contains filtered or unexported fields
}

MockKeyStore provides private key storage for tests.

func NewMockKeyStore

func NewMockKeyStore() *MockKeyStore

NewMockKeyStore creates a new mock key store.

func NewMockKeyStoreFromTestKeys

func NewMockKeyStoreFromTestKeys(keys *TestKeys, forDID string) *MockKeyStore

NewMockKeyStoreFromTestKeys creates a key store populated with test keys.

func NewMockKeyStoreFromWellKnownKeys

func NewMockKeyStoreFromWellKnownKeys(forDID string) (*MockKeyStore, error)

NewMockKeyStoreFromWellKnownKeys creates a key store from the DIDComm spec keys.

func (*MockKeyStore) AddPrivateKey

func (ks *MockKeyStore) AddPrivateKey(keyID string, key jwk.Key)

AddPrivateKey adds a private key to the store.

func (*MockKeyStore) GetPrivateKey

func (ks *MockKeyStore) GetPrivateKey(keyID string) (jwk.Key, error)

GetPrivateKey retrieves a private key by ID.

func (*MockKeyStore) ListKeyIDs

func (ks *MockKeyStore) ListKeyIDs() []string

ListKeyIDs returns all key IDs in the store.

type MockResolver

type MockResolver struct {
	// contains filtered or unexported fields
}

MockResolver provides DID resolution for interoperability tests. It holds pre-configured DID Documents with verification methods and key agreement keys.

func NewMockResolver

func NewMockResolver(testKeys *TestKeys) (*MockResolver, error)

NewMockResolver creates a new mock resolver with the given test keys.

func NewMockResolverWithWellKnownKeys

func NewMockResolverWithWellKnownKeys() (*MockResolver, error)

NewMockResolverWithWellKnownKeys creates a resolver using the DIDComm spec test vector keys.

func (*MockResolver) AddDocument

func (r *MockResolver) AddDocument(doc *MockDIDDocument)

AddDocument adds a DID Document to the resolver.

func (*MockResolver) AddKey

func (r *MockResolver) AddKey(keyID string, key jwk.Key)

AddKey adds a key to the resolver by key ID.

func (*MockResolver) GetAuthenticationKeys

func (r *MockResolver) GetAuthenticationKeys(ctx context.Context, did string) ([]jwk.Key, error)

GetAuthenticationKeys returns all authentication keys for a DID.

func (*MockResolver) GetKeyAgreementKeys

func (r *MockResolver) GetKeyAgreementKeys(ctx context.Context, did string) ([]jwk.Key, error)

GetKeyAgreementKeys returns all key agreement keys for a DID.

func (*MockResolver) GetServiceEndpoint

func (r *MockResolver) GetServiceEndpoint(ctx context.Context, did string) (string, error)

GetServiceEndpoint returns the DIDComm messaging service endpoint for a DID.

func (*MockResolver) Resolve

func (r *MockResolver) Resolve(ctx context.Context, did string) (*MockDIDDocument, error)

Resolve resolves a DID to its DID Document.

func (*MockResolver) ResolveKey

func (r *MockResolver) ResolveKey(ctx context.Context, keyID string) (jwk.Key, error)

ResolveKey resolves a key ID (DID URL) to a JWK.

type MockService

type MockService struct {
	ID              string
	Type            string
	ServiceEndpoint string
}

MockService represents a service endpoint in a DID Document.

type MockVerificationMethod

type MockVerificationMethod struct {
	ID           string
	Type         string
	Controller   string
	PublicKeyJWK jwk.Key
}

MockVerificationMethod represents a verification method in a DID Document.

type TestKeys

type TestKeys struct {
	// Ed25519 signing keys
	AliceEdSign *KeyPair
	BobEdSign   *KeyPair

	// X25519 key agreement keys
	AliceX25519 *KeyPair
	BobX25519   *KeyPair

	// P-256 keys (signing and key agreement)
	AliceP256 *KeyPair
	BobP256   *KeyPair

	// P-384 keys (signing and key agreement)
	AliceP384 *KeyPair
	BobP384   *KeyPair
}

TestKeys holds all cryptographic key pairs for testing. These keys are deterministically generated from seed for reproducibility.

func NewTestKeys

func NewTestKeys() (*TestKeys, error)

NewTestKeys generates a complete set of test keys for interoperability testing.

type WellKnownTestVectorKeys

type WellKnownTestVectorKeys struct {
	// Alice's keys from the spec
	AliceKeyAgreementX25519 jwk.Key
	AliceKeyAgreementP256   jwk.Key
	AliceKeyAgreementP384   jwk.Key
	AliceKeyAgreementP521   jwk.Key
	AliceAuthKeyEd25519     jwk.Key

	// Bob's keys from the spec
	BobKeyAgreementX25519 jwk.Key
	BobKeyAgreementP256   jwk.Key
	BobKeyAgreementP384   jwk.Key
	BobKeyAgreementP521   jwk.Key
}

WellKnownTestVectorKeys contains the DIDComm spec test vector keys. These are from Appendix C of the DIDComm v2.1 specification.

func LoadWellKnownKeys

func LoadWellKnownKeys() (*WellKnownTestVectorKeys, error)

LoadWellKnownKeys loads the DIDComm spec test vector keys. These keys are from the official DIDComm test vectors.

Jump to

Keyboard shortcuts

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