module Registry declares *

data ClearExpiredResult:
  success: bool
  error: string
  count_keys: u64
  count_records: u64
  count_tombstones: u64

data Key:
  id: string
  label: string
  owner_peer_id: string
  timestamp_created: u64
  challenge: []u8
  challenge_type: string
  signature: []u8

data RecordMetadata:
  key_id: string
  issued_by: string
  peer_id: string
  timestamp_issued: u64
  solution: []u8
  value: string
  relay_id: []string
  service_id: []string
  issuer_signature: []u8

data Record:
  metadata: RecordMetadata
  timestamp_created: u64
  signature: []u8

data Tombstone:
  key_id: string
  issued_by: string
  peer_id: string
  timestamp_issued: u64
  solution: []u8
  issuer_signature: []u8

data EvictStaleItem:
  key: Key
  records: []Record
  tombstones: []Tombstone

data EvictStaleResult:
  success: bool
  error: string
  results: []EvictStaleItem

data GetKeyMetadataResult:
  success: bool
  error: string
  key: Key

data GetRecordsResult:
  success: bool
  error: string
  result: []Record

data GetTombstonesResult:
  success: bool
  error: string
  result: []Tombstone

data MergeKeysResult:
  success: bool
  error: string
  key: Key

data MergeResult:
  success: bool
  error: string
  result: []Record

data RegisterKeyResult:
  success: bool
  error: string
  key_id: string

data RegistryResult:
  success: bool
  error: string

data RepublishRecordsResult:
  success: bool
  error: string
  updated: u64

data WeightResult:
  success: bool
  weight: u32
  peer_id: string
  error: string

service Registry("registry"):
  add_tombstone(key_id: string, issued_by: string, peer_id: string, timestamp_issued: u64, solution: []u8, signature: []u8, current_timestamp_sec: u64) -> RegistryResult
  clear_expired(current_timestamp_sec: u64) -> ClearExpiredResult
  create_record_metadata(key_id: string, issued_by: string, timestamp_issued: u64, value: string, peer_id: string, relay_id: []string, service_id: []string, solution: []u8, signature: []u8) -> RecordMetadata
  evict_stale(current_timestamp_sec: u64) -> EvictStaleResult
  get_key_bytes(label: string, owner_peer_id: []string, timestamp_created: u64, challenge: []u8, challenge_type: string) -> []u8
  get_key_id(label: string, peer_id: string) -> string
  get_key_metadata(key_id: string) -> GetKeyMetadataResult
  get_record_bytes(metadata: RecordMetadata, timestamp_created: u64) -> []u8
  get_record_metadata_bytes(key_id: string, issued_by: string, timestamp_issued: u64, value: string, peer_id: string, relay_id: []string, service_id: []string, solution: []u8) -> []u8
  get_records(key_id: string, current_timestamp_sec: u64) -> GetRecordsResult
  get_stale_local_records(current_timestamp_sec: u64) -> GetRecordsResult
  get_tombstone_bytes(key_id: string, issued_by: string, peer_id: string, timestamp_issued: u64, solution: []u8) -> []u8
  get_tombstones(key_id: string, current_timestamp_sec: u64) -> GetTombstonesResult
  merge(records: [][]Record) -> MergeResult
  merge_keys(keys: []Key) -> MergeKeysResult
  merge_two(a: []Record, b: []Record) -> MergeResult
  put_record(metadata: RecordMetadata, timestamp_created: u64, signature: []u8, weight: WeightResult, current_timestamp_sec: u64) -> RegistryResult
  register_key(label: string, owner_peer_id: []string, timestamp_created: u64, challenge: []u8, challenge_type: string, signature: []u8, weight: WeightResult, current_timestamp_sec: u64) -> RegisterKeyResult
  republish_key(key: Key, weight: WeightResult, current_timestamp_sec: u64) -> RegistryResult
  republish_records(records: []Record, weights: []WeightResult, current_timestamp_sec: u64) -> RepublishRecordsResult
  republish_tombstones(tombstones: []Tombstone, current_timestamp_sec: u64) -> RegistryResult
  set_expired_timeout(timeout_sec: u64)  
  set_stale_timeout(timeout_sec: u64)  
