package model import "errors" const ( // KeyTypeOnion - a cwtch address KeyTypeOnion = "onion" // bulletin board // KeyTypeTokenOnion - a cwtch peer with a PoW based token protocol KeyTypeTokenOnion = "token_onion" //KeyTypePrivacyPass - a privacy pass based token server KeyTypePrivacyPass = "pp_key" ) // Key provides a wrapper for a generic public key identifier (could be an onion address, a zcash address etc.) type Key string // KeyBundle manages a collection of related keys for various different services. type KeyBundle struct { Keys map[string]Key } // HasKey returns true if the bundle has a public key of a given type. func (kb *KeyBundle) HasKey(name string) bool { _, exists := kb.Keys[name] return exists } // GetKey retrieves a key with a given type from the bundle func (kb *KeyBundle) GetKey(name string) (Key, error) { key, exists := kb.Keys[name] if exists { return key, nil } return "", errors.New("no such key") } // AttributeBundle returns a map that can be used as part of a peer attribute bundle func (kb *KeyBundle) AttributeBundle() map[string]string { ab := make(map[string]string) for k, v := range kb.Keys { ab[k] = string(v) } return ab }