@startuml
/'
Copyright 2017-2019 Government of Canada - Public Services and Procurement Canada - buyandsell.gc.ca

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0
or
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
'/

scale max 2000 width

title Class Diagram

class ErrorCode {
}

class VonAnchorError {
    +error_code
    +message
}

class SchemaKey {
}

class SchemaCache {
    -_schema_key2schema
    -_seq_no2schema_key
    +lock
    +__getitem__()
    +__setitem__()
    +contains()
    +index()
    +schema_key_for()
    +schemata()
    +feed()
    +clear()
}

class CredDefCache{
    +lock
}

class Tails {
    +reader_handle
    +rr_id
    +path
    +open()
    {static} +ok_hash()
    {static} +associate()
    {static} +dir()
    {static} +linked()
    {static} +links()
    {static} +unlinked()
    {static} +next_tag()
    {static} +current_rev_reg_id()
}

class RevoCacheEntry {
    +rev_reg_def
    +tails
    +cull()
    -_get_update()
    +rr_delta_frames
    +rr_state_frames
    +get_delta_json()
    +get_state_json()
}

class RevRegUpdateFrame {
    +qtime
    +timestamp
    +to
    +rr_update
}

class RevocationCache {
    +lock
}

class EndpointCache {
    +lock
}

class ArchivableCaches {
    {static} +clear()
    {static} +archdiive()
    {static} +parse()
    {static} +purge_archives()
}

class WalletManager {
    {static} +register_storage_library()
    -_defaults
    +default_storage_type
    +default_freshness_time
    +default_auto_remove
    +default_access
    -_config2indy()
    +create()
    +get()
    +export_wallet()
    +import_wallet()
    +reset()
    +remove()
}

class Wallet {
    +name
    +handle
    +config
    +auto_remove
    +access
    +access_creds
    +storage_type
    +did
    +verkey
    +create_local_did()
    +get_local_dids()
    +get_local_did()
    +get_anchor_did()
    +create_link_secret()
    -_write_link_secret_label()
    +get_link_secret_label()
    +open()
    +close()
    +remove()
    +create_signing_key()
    +get_signing_key()
    +replace_signing_key_metadata()
    +write_pairwise()
    +delete_pairwise()
    +get_pairwise()
    +write_non_secret()
    +delete_non_secret()
    +get_non_secret()
    +encrypt()
    +decrypt()
    +sign()
    +verify()
    +pack()
    +unpack()
    +reseed_init()
    +reseed_apply()
}

class KeyInfo {
    +verkey
    +metadata
}

class DIDInfo {
    +did
    +verkey
    +metadata
}

class StorageRecord {
    {static} +ok_tags()
    +type
    +id
    +value
    +tags
    +clear_tags
    +encr_tags
}

class StorageRecordSearch {
    {static} +OPTIONS_JSON
    -_wallet
    -_type
    -_query_json
    -_handle
    +opened
    +open()
    +fetch()
    +close()
}

class PairwiseInfo {
    +their_did
    +their_verkey
    +my_did
    +my_verkey
    +metadata
}

class EndpointInfo {
    +endpoint
    +ip_addr
    +port
    +verkey
}

enum Protocol {
    {static} +V_13
    {static} +V_14
    {static} +V_15
    {static} +V_16
    {static} +V_17
    {static} +V_18
    {static} +DEFAULT
}

class NodePoolManager {
    +protocol
    +add_config()
    +list()
    +get()
    +remove()
}

class NodePool {
    +name
    +handle
    +config
    +protocol
    +cache_id
    +open()
    +close()
    +refresh()
}

enum Predicate {
    {static} +LE
    {static} +LT
    {static} +GE
    {static} +GT
}

enum Role {
    {static} +STEWARD
    {static} +TRUSTEE
    {static} +TRUST_ANCHOR
    {static} +USER
    {static} +ROLE_REMOVE
}

class BaseAnchor {
    +pool
    +wallet
    +did
    +verkey
    -_submit()
    -_sign_submit()
    -_verkey_for()
    {static} +least_role()
    +open()
    +close()
    +reseed()
    +set_did_endpoint()
    +get_did_endpoint()
    +send_endpoint()
    +get_endpoint()
    +get_nym()
    +get_nym_role()
    +get_cred_def()
    +get_rev_reg_def()
    +get_schema()
    +encrypt()
    +decrypt()
    +sign()
    +verify()
    +get_txn()
}

class AnchorSmith {
    {static} +role()
    +send_nym()
}

class Origin {
    +send_schema()
}

class RevRegBuilder {
    {static} +get_state()
    {static} +dir_tails()
    {static} +dir_tails_sentinel()
    -_start_data_json()
    +external
    +_create_rev_reg()
    +dir_tails_top()
    +dir_tails_target()
    +serve()
    +stop()
}

enum State {
    {static} +RUNNING
    {static} +STOPPING
    {static} +ABSENT
}

class Issuer {
    -_send_rev_reg_def()
    -_set_rev_reg()
    -_sync_revoc_for_issue()
    -_create_cred_def()
    +rrbx
    +rrb
    +rrb()
    +open()
    +path_tails()
    +send_cred_def()
    +create_cred_offer()
    +create_cred()
    +revoke_cred()
    +get_box_ids_json()
}

class HolderProver {
    +config
    +dir_cache
    -_sync_revoc_for_proof()
    -_build_rr_delta_json()
    -_assert_link_secret()
    +build_req_creds_json()
    +dir_tails()
    +open()
    +close()
    +rev_regs()
    +offline_intervals()
    +create_link_secret()
    +create_cred_req()
    +set_cred_attr_tag_policy()
    +get_cred_attr_tag_policy()
    +store_cred()
    +delete_cred()
    +load_cache_for_proof()
    +get_box_ids_json()
    +get_cred_infos_by_q()
    +get_cred_infos_by_filter()
    +get_cred_info_by_id()
    +get_creds()
    +get_creds_by_id()
    +get_cred_briefs_by_proof_req_q()
    +create_proof()
    +reset_wallet()
}

class Verifier {
    +config
    +dir_cache
    -_build_rr_state_json()
    {static} +least_role()
    +build_proof_req_json()
    +load_cache_for_verification()
    +open()
    +verify_proof()
}

class TrusteeAnchor {
}

class NominalAnchor {
    {static} +least_role()
}

class SRIAnchor {
    {static} +least_role()
}

class BCRegistrarAnchor {
}

class OrgBookAnchor {
}

class OrgHubAnchor {
    {static} +least_role()
    +close()
}

enum PublicKeyType {
    {static} +RSA_SIG_2018
    {static} +ED25519_SIG_2018
    {static} +EDDSA_SA_SIG_SECP256K1
}

class PublicKey {
    +did
    +id
    +type
    +value
    +controller
    +authn
    +to_dict()
}

class Service {
    +did
    +idp
    +type
    +endpoint
    +to_dict()
}

class DIDDoc {
    +did
    +pubkey
    +authnkey
    +service
    +set()
    +to_json()
    +serialize()
    +add_service_pubkeys()
    {static} +from_json()
    {static} +deserialize()
}

VonAnchorError "1" *-up- "1" ErrorCode
SchemaCache -left-> SchemaKey
BaseAnchor -left-> SchemaKey

NodePoolManager "1" *-- "1" Protocol
NodePoolManager ..> NodePool
NodePool *-- Protocol

RevRegBuilder *-- State

BaseAnchor -up-> SchemaCache
BaseAnchor "1" *-left- "1" Wallet
BaseAnchor "1" *-up- "1" NodePool

RevoCacheEntry -up-> Tails
RevoCacheEntry "2" *-down- "n" RevRegUpdateFrame
RevocationCache -> RevoCacheEntry

WalletManager .left.> Wallet

Wallet --> KeyInfo
Wallet --> DIDInfo
Wallet --> PairwiseInfo
Wallet --> StorageRecord

StorageRecordSearch *-- Wallet

BaseAnchor --> EndpointInfo

BaseAnchor -up-> RevoCache
BaseAnchor --> EndpointCache

BaseAnchor -up-> CredDefCache
BaseAnchor <|-down- AnchorSmith
BaseAnchor <|-down- Origin
BaseAnchor <|-down- HolderProver
BaseAnchor <|-down- Verifier
BaseAnchor <|-right- NominalAnchor

AnchorSmith <|-down- TrusteeAnchor
BaseAnchor <|-down- RevRegBuilder
BaseAnchor <-- Issuer
Issuer *- RevRegBuilder

Origin <|-left- SRIAnchor
Issuer <|-left- SRIAnchor
Verifier <|-right- SRIAnchor

Issuer <|-up- BCRegistrarAnchor
Origin <|-up- BCRegistrarAnchor

HolderProver <|-down- OrgBookAnchor

OrgBookAnchor <|-- OrgHubAnchor
Issuer <|-- OrgHubAnchor
Origin <|-- OrgHubAnchor
Verifier <|-- OrgHubAnchor

HolderProver ..> ArchivableCaches
Verifier ..> ArchivableCaches
OrgHubAnchor ..> ArchivableCaches

HolderProver ..> Predicate
Verifier ..> Predicate

BaseAnchor ..> Role
AnchorSmith ..> Role
Verifier ..> Role
NominalAnchor ..> Role
OrgHubAnchor ..> Role
SRIAnchor ..> Role

PublicKey "1" *-- "1" PublicKeyType
DIDDoc "1" *-- "n" PublicKey
DIDDoc "1" *-- "n" Service
@enduml
