@interop/wallet-core 0.94.0 → 0.95.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/README.md +21 -20
  2. package/dist/clientAnnex/mend.js +4 -1
  3. package/dist/clientAnnex/mend.js.map +1 -1
  4. package/dist/clients/index.d.ts +3 -2
  5. package/dist/clients/index.d.ts.map +1 -1
  6. package/dist/clients/index.js +3 -2
  7. package/dist/clients/index.js.map +1 -1
  8. package/dist/clients/listing.d.ts +19 -12
  9. package/dist/clients/listing.d.ts.map +1 -1
  10. package/dist/clients/listing.js +69 -22
  11. package/dist/clients/listing.js.map +1 -1
  12. package/dist/connections/didKey.d.ts +25 -0
  13. package/dist/connections/didKey.d.ts.map +1 -0
  14. package/dist/connections/didKey.js +49 -0
  15. package/dist/connections/didKey.js.map +1 -0
  16. package/dist/connections/entry.d.ts +226 -0
  17. package/dist/connections/entry.d.ts.map +1 -0
  18. package/dist/connections/entry.js +287 -0
  19. package/dist/connections/entry.js.map +1 -0
  20. package/dist/connections/errors.d.ts +33 -0
  21. package/dist/connections/errors.d.ts.map +1 -0
  22. package/dist/connections/errors.js +36 -0
  23. package/dist/connections/errors.js.map +1 -0
  24. package/dist/connections/grants.d.ts +94 -0
  25. package/dist/connections/grants.d.ts.map +1 -0
  26. package/dist/connections/grants.js +120 -0
  27. package/dist/connections/grants.js.map +1 -0
  28. package/dist/connections/index.d.ts +47 -0
  29. package/dist/connections/index.d.ts.map +1 -0
  30. package/dist/connections/index.js +40 -0
  31. package/dist/connections/index.js.map +1 -0
  32. package/dist/connections/read.d.ts +82 -0
  33. package/dist/connections/read.d.ts.map +1 -0
  34. package/dist/connections/read.js +100 -0
  35. package/dist/connections/read.js.map +1 -0
  36. package/dist/connections/resourceId.d.ts +36 -0
  37. package/dist/connections/resourceId.d.ts.map +1 -0
  38. package/dist/connections/resourceId.js +49 -0
  39. package/dist/connections/resourceId.js.map +1 -0
  40. package/dist/connections/store.d.ts +103 -0
  41. package/dist/connections/store.d.ts.map +1 -0
  42. package/dist/connections/store.js +67 -0
  43. package/dist/connections/store.js.map +1 -0
  44. package/dist/connections/upsert.d.ts +214 -0
  45. package/dist/connections/upsert.d.ts.map +1 -0
  46. package/dist/connections/upsert.js +468 -0
  47. package/dist/connections/upsert.js.map +1 -0
  48. package/dist/connections/writers.d.ts +217 -0
  49. package/dist/connections/writers.d.ts.map +1 -0
  50. package/dist/connections/writers.js +485 -0
  51. package/dist/connections/writers.js.map +1 -0
  52. package/dist/enrollment/onboardingResponse.d.ts +3 -3
  53. package/dist/enrollment/onboardingResponse.d.ts.map +1 -1
  54. package/dist/enrollment/onboardingResponse.js +17 -13
  55. package/dist/enrollment/onboardingResponse.js.map +1 -1
  56. package/dist/keys/index.d.ts +0 -7
  57. package/dist/keys/index.d.ts.map +1 -1
  58. package/dist/keys/index.js +0 -6
  59. package/dist/keys/index.js.map +1 -1
  60. package/dist/labelText.d.ts +30 -3
  61. package/dist/labelText.d.ts.map +1 -1
  62. package/dist/labelText.js +35 -3
  63. package/dist/labelText.js.map +1 -1
  64. package/dist/menders/ids.d.ts +1 -1
  65. package/dist/menders/ids.d.ts.map +1 -1
  66. package/dist/menders/ids.js +7 -2
  67. package/dist/menders/ids.js.map +1 -1
  68. package/dist/space/collections.d.ts +15 -25
  69. package/dist/space/collections.d.ts.map +1 -1
  70. package/dist/space/collections.js +19 -29
  71. package/dist/space/collections.js.map +1 -1
  72. package/dist/space/index.d.ts +4 -3
  73. package/dist/space/index.d.ts.map +1 -1
  74. package/dist/space/index.js +4 -3
  75. package/dist/space/index.js.map +1 -1
  76. package/package.json +8 -8
  77. package/dist/keys/clientLabels.d.ts +0 -85
  78. package/dist/keys/clientLabels.d.ts.map +0 -1
  79. package/dist/keys/clientLabels.js +0 -96
  80. package/dist/keys/clientLabels.js.map +0 -1
  81. package/dist/keys/wasLabelsStore.d.ts +0 -33
  82. package/dist/keys/wasLabelsStore.d.ts.map +0 -1
  83. package/dist/keys/wasLabelsStore.js +0 -35
  84. package/dist/keys/wasLabelsStore.js.map +0 -1
  85. package/dist/writers/entry.d.ts +0 -95
  86. package/dist/writers/entry.d.ts.map +0 -1
  87. package/dist/writers/entry.js +0 -90
  88. package/dist/writers/entry.js.map +0 -1
  89. package/dist/writers/index.d.ts +0 -17
  90. package/dist/writers/index.d.ts.map +0 -1
  91. package/dist/writers/index.js +0 -14
  92. package/dist/writers/index.js.map +0 -1
  93. package/dist/writers/roster.d.ts +0 -152
  94. package/dist/writers/roster.d.ts.map +0 -1
  95. package/dist/writers/roster.js +0 -365
  96. package/dist/writers/roster.js.map +0 -1
  97. package/dist/writers/store.d.ts +0 -71
  98. package/dist/writers/store.d.ts.map +0 -1
  99. package/dist/writers/store.js +0 -55
  100. package/dist/writers/store.js.map +0 -1
@@ -0,0 +1,217 @@
1
+ import type { ConnectionEntry, ConnectionWriterPolicy } from './entry.js';
2
+ import type { ConnectionsListing } from './read.js';
3
+ import type { ConnectionIdKey } from './resourceId.js';
4
+ import type { ConnectionsStore } from './store.js';
5
+ /**
6
+ * The writer first-seen record, kept by the client: the account and
7
+ * `writerId` this client's writer first appeared under, and when it last
8
+ * touched its member. One slot, so a writer that moves to another account
9
+ * starts over.
10
+ */
11
+ export interface WriterFirstSeenRecord {
12
+ accountDid: string;
13
+ writerId: string;
14
+ /**
15
+ * ISO 8601 UTC start of the session the record was written in.
16
+ */
17
+ firstSessionAt: string;
18
+ /**
19
+ * ISO 8601 UTC time of the latest successful registration or touch.
20
+ */
21
+ lastTouchedAt?: string;
22
+ }
23
+ /**
24
+ * The seam for the writer first-seen record. Where it lives is the wallet's
25
+ * choice: it rides the session's persistence, and a forget of this client's
26
+ * local state clears it along with the `writerId`.
27
+ */
28
+ export interface WriterFirstSeenStore {
29
+ get(): Promise<unknown>;
30
+ put(record: WriterFirstSeenRecord): Promise<void>;
31
+ }
32
+ /**
33
+ * What {@link registerConnectionWriter} did.
34
+ *
35
+ * - `deferred` -- the writer has not yet been encountered in a second session
36
+ * under this account; the first-seen record is (re)written and the
37
+ * directory is untouched.
38
+ * - `fresh` -- the latest touch is within the touch interval; no I/O.
39
+ * - `registered` -- the writer member was added (the entry created if it was
40
+ * absent).
41
+ * - `touched` -- the writer member's `lastSeen` was advanced.
42
+ * - `raced` -- every attempt lost a conditional write; the next call retries.
43
+ * - `unlisted` -- no entry stands and the verified document does not list
44
+ * this client, so none is created.
45
+ * - `retired` -- the entry is retired and the verified document no longer
46
+ * lists this client; nothing is written.
47
+ * - `kind-mismatch` -- the entry at this client's id is not a
48
+ * `wallet-client` entry; nothing is written, and the caller logs it.
49
+ * - `refused` -- the entry cannot be parsed, or comes from a newer build;
50
+ * nothing is written.
51
+ */
52
+ export type WriterRegistrationOutcome = 'deferred' | 'fresh' | 'registered' | 'touched' | 'raced' | 'unlisted' | 'retired' | 'kind-mismatch' | 'refused';
53
+ /**
54
+ * Registers this client's writer on its own `wallet-client` entry once the
55
+ * writer is encountered in a second session under the account, and touches
56
+ * the member's `lastSeen` at most once per touch interval after that. Call it
57
+ * on the wallet's connect or sync path; calls within the interval cost no
58
+ * I/O. The interval runs from the last settled call, whatever its outcome,
59
+ * so an entry this client cannot write (`unlisted`, `retired`,
60
+ * `kind-mismatch`, `refused`) is re-read once per interval and not on every
61
+ * call. Only `raced` leaves the next call to try again at once.
62
+ *
63
+ * An absent entry is created (`kind: 'wallet-client'`, `id` this client's
64
+ * did:key, `name` the platform label), which converges a lost
65
+ * enrollment-time write, but only while the verified account document lists
66
+ * this client. A retired entry is un-retired while the document lists this
67
+ * client (a forget torn after its retirement) and left alone otherwise. A
68
+ * new member first makes room under the per-entry writer cap.
69
+ *
70
+ * @param options {object}
71
+ * @param options.store {ConnectionsStore}
72
+ * @param options.hmacKey {ConnectionIdKey} the collection's blinded-index
73
+ * key
74
+ * @param options.local {WriterFirstSeenStore}
75
+ * @param options.accountDid {string} the account the first-seen record is
76
+ * kept under
77
+ * @param options.did {string} this client's did:key
78
+ * @param options.writerId {string} this client's writer
79
+ * @param options.label {string} the coarse platform self-description a new
80
+ * member (and a new entry's `name`) takes; held to the display-name rule,
81
+ * and refused with a `TypeError` outside it
82
+ * @param options.listedInDocument {boolean} whether the verified account
83
+ * document lists this client
84
+ * @param options.sessionStartedAt {Date} when the current session began; a
85
+ * first-seen record written at or after it is this session's own
86
+ * @param [options.now] {Date}
87
+ * @param [options.policy] {Partial<ConnectionWriterPolicy>}
88
+ * @returns {Promise<WriterRegistrationOutcome>}
89
+ */
90
+ export declare function registerConnectionWriter({ store, hmacKey, local, accountDid, did, writerId, label, listedInDocument, sessionStartedAt, now, policy }: {
91
+ store: ConnectionsStore;
92
+ hmacKey: ConnectionIdKey;
93
+ local: WriterFirstSeenStore;
94
+ accountDid: string;
95
+ did: string;
96
+ writerId: string;
97
+ label: string;
98
+ listedInDocument: boolean;
99
+ sessionStartedAt: Date;
100
+ now?: Date;
101
+ policy?: Partial<ConnectionWriterPolicy>;
102
+ }): Promise<WriterRegistrationOutcome>;
103
+ /**
104
+ * What {@link touchConnectionWriter} did.
105
+ *
106
+ * - `unregistered` -- no listed entry carries the writer; nothing is written.
107
+ * - `retired` -- the writer's entry is retired; nothing is written.
108
+ * - `fresh` -- the member was touched within the touch interval.
109
+ * - `touched` -- the member's `lastSeen` was advanced.
110
+ * - `refused` -- the entry cannot be written by this build.
111
+ * - `raced` -- every attempt lost a conditional write.
112
+ */
113
+ export type WriterTouchOutcome = 'unregistered' | 'retired' | 'fresh' | 'touched' | 'refused' | 'raced';
114
+ /**
115
+ * Touches a registered writer's member from a pulled revision's `writerId`:
116
+ * the remembered session's pull path, throttled like the client's own touch.
117
+ * The writer is found in a listing already read, so the call costs no extra
118
+ * listing read, and a member the listing shows as fresh costs no I/O at all.
119
+ * An unregistered `writerId` is ignored, and so is a writer on a retired
120
+ * entry, so a replayed revision cannot keep a departed client's writer
121
+ * alive.
122
+ *
123
+ * @param options {object}
124
+ * @param options.store {ConnectionsStore}
125
+ * @param options.hmacKey {ConnectionIdKey}
126
+ * @param options.listing {ConnectionsListing} the latest listing read
127
+ * @param options.writerId {string} the pulled revision's `writerId`
128
+ * @param [options.now] {Date}
129
+ * @param [options.policy] {Partial<ConnectionWriterPolicy>}
130
+ * @returns {Promise<WriterTouchOutcome>}
131
+ */
132
+ export declare function touchConnectionWriter({ store, hmacKey, listing, writerId, now, policy }: {
133
+ store: ConnectionsStore;
134
+ hmacKey: ConnectionIdKey;
135
+ listing: ConnectionsListing;
136
+ writerId: string;
137
+ now?: Date;
138
+ policy?: Partial<ConnectionWriterPolicy>;
139
+ }): Promise<WriterTouchOutcome>;
140
+ /**
141
+ * The outcome of a sweep: the listing with each written entry replaced by
142
+ * what was written, the writers it changed, and the entries whose write
143
+ * failed for a reason other than a lost race, each with the error the store
144
+ * raised, for the caller's log.
145
+ */
146
+ export interface ConnectionWritersSweep {
147
+ listing: ConnectionsListing;
148
+ markedInactive: string[];
149
+ dropped: string[];
150
+ failed: Array<{
151
+ resourceId: string;
152
+ err: unknown;
153
+ }>;
154
+ }
155
+ /**
156
+ * Sweeps every entry of a listing already read: the per-entry two-phase
157
+ * expiry of `writers`, run at the directory listing read on both session
158
+ * kinds. Safe to run from any replica, and concurrently. Every write is
159
+ * conditional on the ETag the listing read, and a lost race is skipped: the
160
+ * entry as read still labels its revisions. Any other failed write is skipped
161
+ * the same way and reported in `failed`, so one unreachable entry does not
162
+ * fail the listing read the sweep rides on; the next sweep converges it. An
163
+ * entry this build cannot write (a newer `version`), or one read without an
164
+ * ETag, is left alone.
165
+ *
166
+ * @param options {object}
167
+ * @param options.store {ConnectionsStore}
168
+ * @param options.listing {ConnectionsListing}
169
+ * @param [options.now] {Date}
170
+ * @param [options.policy] {Partial<ConnectionWriterPolicy>}
171
+ * @returns {Promise<ConnectionWritersSweep>}
172
+ */
173
+ export declare function sweepConnectionWriters({ store, listing, now, policy }: {
174
+ store: ConnectionsStore;
175
+ listing: ConnectionsListing;
176
+ now?: Date;
177
+ policy?: Partial<ConnectionWriterPolicy>;
178
+ }): Promise<ConnectionWritersSweep>;
179
+ /**
180
+ * How a history view renders one revision's writer. `undefined` from
181
+ * {@link resolveWriter} means no entry carries the writer: the view renders
182
+ * its fallback label ("another session").
183
+ */
184
+ export interface ResolvedWriter {
185
+ /**
186
+ * The entry's display name: the user's `label`, else its `name`, else the
187
+ * writer member's platform label.
188
+ */
189
+ label: string;
190
+ active: boolean;
191
+ /**
192
+ * Whether the writer's entry is retired.
193
+ */
194
+ retired: boolean;
195
+ /**
196
+ * Present only when the entry's did:key carries a signing key the verified
197
+ * account document lists. The view may then link the revision to that
198
+ * client's row.
199
+ */
200
+ clientSigningKeyMultibase?: string;
201
+ }
202
+ /**
203
+ * Resolves a revision's `writerId` against the directory's entries.
204
+ *
205
+ * @param options {object}
206
+ * @param options.writerId {string}
207
+ * @param options.entries {ConnectionEntry[]} the listed entries
208
+ * @param options.enrolledSigningKeys {ReadonlySet<string>} the signing-key
209
+ * multibases of the enrolled clients in the verified account document
210
+ * @returns {ResolvedWriter | undefined}
211
+ */
212
+ export declare function resolveWriter({ writerId, entries, enrolledSigningKeys }: {
213
+ writerId: string;
214
+ entries: ConnectionEntry[];
215
+ enrolledSigningKeys: ReadonlySet<string>;
216
+ }): ResolvedWriter | undefined;
217
+ //# sourceMappingURL=writers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"writers.d.ts","sourceRoot":"","sources":["../../src/connections/writers.ts"],"names":[],"mappings":"AA8BA,OAAO,KAAK,EACV,eAAe,EAEf,sBAAsB,EACvB,MAAM,YAAY,CAAA;AACnB,OAAO,KAAK,EAAE,kBAAkB,EAAkB,MAAM,WAAW,CAAA;AAEnE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAIlD;;;;;GAKG;AACH,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE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