summaryrefslogtreecommitdiffstats
path: root/store/src/store_protocol.capnp
blob: 039a794c3c51c9e6d58f31b914855bec2743b4ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
@0xf4bd406fa822c9db;

interface Node {
  open @0 (domain: Text, networkPolicy: NetworkPolicy, ephemeral: Bool, name: Text)
         -> (result: Result(Store));
  iter @1 (domainPrefix: Text) -> (result: Result(StoreIter));
  iterKeys @2 () -> (result: Result(KeyIter));
  log @3 () -> (result: Result(LogIter));

  interface Store {
    add @0 (label: Text, fingerprint: Text) -> (result: Result(Binding));
    lookup @1 (label: Text) -> (result: Result(Binding));
    delete @2 () -> (result: Result(Unit));
    iter @3 () -> (result: Result(BindingIter));
    log @4 () -> (result: Result(LogIter));
  }

  interface Binding {
    stats @0 () -> (result: Result(Stats));
    key @1 () -> (result: Result(Key));
    import @2 (key: Data, force: Bool) -> (result: Result(Data));
    delete @3 () -> (result: Result(Unit));
    registerEncryption @4 () ->   (result: Result(Stats));
    registerVerification @5 () -> (result: Result(Stats));
    log @6 () -> (result: Result(LogIter));
  }

  interface Key {
    stats @0 () -> (result: Result(Stats));
    tpk @1() -> (result: Result(Data));
    import @2 (key: Data) -> (result: Result(Data));
    log @3 () -> (result: Result(LogIter));
  }

  # Iterators.
  interface StoreIter {
    next @0 () -> (result: Result(Item));

    struct Item {
      domain @0 :Text;
      name @1 :Text;
      networkPolicy @2 :NetworkPolicy;
      entries @3 :UInt64;
      store @4 :Store;
    }
  }

  interface BindingIter {
    next @0 () -> (result: Result(Item));

    struct Item {
      label @0 :Text;
      fingerprint @1 :Text;
      binding @2 :Binding;
    }
  }

  interface KeyIter {
    next @0 () -> (result: Result(Item));

    struct Item {
      fingerprint @0 :Text;
      bindings @1 :UInt64;
      key @2 :Key;
    }
  }

  interface LogIter {
    next @0 () -> (result: Result(Entry));

    struct Entry {
      timestamp @0 :Int64;
      store     @1 :Store;
      binding   @2 :Binding;
      key       @3 :Key;
      slug      @4 :Text;
      message   @5 :Text;
      error     @6 :Text;
    }
  }

  # Unit struct.  Useful with Result.
  struct Unit {}

  struct Stats {
    created @0 :Int64;
    updated @1 :Int64;
    encryptionCount   @2 :Int64;
    encryptionFirst   @3 :Int64;
    encryptionLast    @4 :Int64;
    verificationCount @5 :Int64;
    verificationFirst @6 :Int64;
    verificationLast  @7 :Int64;
  }

  struct Log {
    timestamp @0 :Int64;
    item @1 :Text;
    message @2 :Text;
    error @3 :Text;
  }

  enum NetworkPolicy {
    offline @0;
    anonymized @1;
    encrypted @2;
    insecure @3;
  }

  enum Error {
    unspecified @0;
    notFound @1;
    conflict @2;
    systemError @3;
    malformedKey @4;
    networkPolicyViolationOffline @5;
    networkPolicyViolationAnonymized @6;
    networkPolicyViolationEncrypted @7;
    networkPolicyViolationInsecure @8;
  }

  struct Result(T) {
    union {
      ok @0 :T;
      err @1 :Error;
    }
  }
}