@minca/core 0.3.1 → 0.4.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 (212) hide show
  1. package/README.md +2 -2
  2. package/dist/{session → hosting}/hosting.d.ts +1 -1
  3. package/dist/{session → hosting}/hosting.d.ts.map +1 -1
  4. package/dist/{session → hosting}/hosting.js.map +1 -1
  5. package/dist/index.d.ts +20 -28
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +16 -19
  8. package/dist/index.js.map +1 -1
  9. package/dist/network/mesh.d.ts.map +1 -1
  10. package/dist/network/mesh.js +13 -3
  11. package/dist/network/mesh.js.map +1 -1
  12. package/dist/network/network-manager.d.ts +5 -0
  13. package/dist/network/network-manager.d.ts.map +1 -1
  14. package/dist/network/network-manager.js +3 -0
  15. package/dist/network/network-manager.js.map +1 -1
  16. package/dist/network/peer-auth.d.ts +17 -5
  17. package/dist/network/peer-auth.d.ts.map +1 -1
  18. package/dist/network/peer-auth.js +19 -9
  19. package/dist/network/peer-auth.js.map +1 -1
  20. package/dist/network/rtc-transport.d.ts.map +1 -1
  21. package/dist/network/rtc-transport.js +1 -0
  22. package/dist/network/rtc-transport.js.map +1 -1
  23. package/dist/network/transport.d.ts +12 -0
  24. package/dist/network/transport.d.ts.map +1 -1
  25. package/dist/network/ws-transport.d.ts +1 -1
  26. package/dist/network/ws-transport.d.ts.map +1 -1
  27. package/dist/network/ws-transport.js +14 -4
  28. package/dist/network/ws-transport.js.map +1 -1
  29. package/dist/node/index.d.ts +1 -5
  30. package/dist/node/index.d.ts.map +1 -1
  31. package/dist/node/index.js +0 -3
  32. package/dist/node/index.js.map +1 -1
  33. package/dist/node/node-hosting.js +1 -1
  34. package/dist/node/node-records.js +1 -1
  35. package/dist/node/node-records.js.map +1 -1
  36. package/dist/node/node.d.ts.map +1 -1
  37. package/dist/node/node.js +18 -0
  38. package/dist/node/node.js.map +1 -1
  39. package/dist/node/space-mirrors.d.ts +1 -1
  40. package/dist/node/space-mirrors.d.ts.map +1 -1
  41. package/dist/node/space-mirrors.js +17 -5
  42. package/dist/node/space-mirrors.js.map +1 -1
  43. package/dist/node/space-peers.d.ts +2 -0
  44. package/dist/node/space-peers.d.ts.map +1 -1
  45. package/dist/node/space-peers.js +41 -8
  46. package/dist/node/space-peers.js.map +1 -1
  47. package/dist/node/space-runtime.d.ts +4 -2
  48. package/dist/node/space-runtime.d.ts.map +1 -1
  49. package/dist/node/space-runtime.js +3 -2
  50. package/dist/node/space-runtime.js.map +1 -1
  51. package/dist/node/space-standing.d.ts.map +1 -1
  52. package/dist/node/space-standing.js +12 -38
  53. package/dist/node/space-standing.js.map +1 -1
  54. package/dist/node/space-warrants.js +1 -1
  55. package/dist/node/space-warrants.js.map +1 -1
  56. package/dist/node/space-writing.d.ts.map +1 -1
  57. package/dist/node/space-writing.js +12 -32
  58. package/dist/node/space-writing.js.map +1 -1
  59. package/dist/node/stores.d.ts +2 -58
  60. package/dist/node/stores.d.ts.map +1 -1
  61. package/dist/node/stores.js +1 -74
  62. package/dist/node/stores.js.map +1 -1
  63. package/dist/node/types.d.ts +3 -3
  64. package/dist/node/types.d.ts.map +1 -1
  65. package/dist/node/writer-keys.d.ts +15 -14
  66. package/dist/node/writer-keys.d.ts.map +1 -1
  67. package/dist/node/writer-keys.js +3 -113
  68. package/dist/node/writer-keys.js.map +1 -1
  69. package/dist/records/key.d.ts +16 -19
  70. package/dist/records/key.d.ts.map +1 -1
  71. package/dist/records/key.js +53 -45
  72. package/dist/records/key.js.map +1 -1
  73. package/dist/records/rules.d.ts +1 -1
  74. package/dist/records/rules.d.ts.map +1 -1
  75. package/dist/records/rules.js +6 -4
  76. package/dist/records/rules.js.map +1 -1
  77. package/dist/storage/body-cache.d.ts +6 -3
  78. package/dist/storage/body-cache.d.ts.map +1 -1
  79. package/dist/storage/body-cache.js +37 -14
  80. package/dist/storage/body-cache.js.map +1 -1
  81. package/dist/storage/mirror.d.ts.map +1 -1
  82. package/dist/storage/mirror.js +35 -16
  83. package/dist/storage/mirror.js.map +1 -1
  84. package/dist/storage/segment.d.ts +6 -2
  85. package/dist/storage/segment.d.ts.map +1 -1
  86. package/dist/storage/segment.js +8 -4
  87. package/dist/storage/segment.js.map +1 -1
  88. package/dist/storage/shared-store.d.ts +32 -0
  89. package/dist/storage/shared-store.d.ts.map +1 -0
  90. package/dist/storage/{folder-reconcile.js → shared-store.js} +15 -15
  91. package/dist/storage/shared-store.js.map +1 -0
  92. package/dist/storage/storage-provider.d.ts +0 -9
  93. package/dist/storage/storage-provider.d.ts.map +1 -1
  94. package/dist/storage/storage-provider.js +8 -8
  95. package/dist/storage/storage-provider.js.map +1 -1
  96. package/dist/sync/sync-engine.d.ts +7 -0
  97. package/dist/sync/sync-engine.d.ts.map +1 -1
  98. package/dist/sync/sync-engine.js +179 -47
  99. package/dist/sync/sync-engine.js.map +1 -1
  100. package/dist/sync/sync-messages.d.ts +1 -1
  101. package/dist/sync/sync-messages.js +1 -1
  102. package/dist/types.d.ts +19 -0
  103. package/dist/types.d.ts.map +1 -1
  104. package/dist/types.js +4 -0
  105. package/dist/types.js.map +1 -1
  106. package/dist/utils/index.d.ts +5 -5
  107. package/dist/utils/index.d.ts.map +1 -1
  108. package/dist/utils/index.js +5 -5
  109. package/dist/utils/index.js.map +1 -1
  110. package/docs/README.md +3 -2
  111. package/docs/building-an-app.md +2 -2
  112. package/docs/node.md +24 -20
  113. package/docs/query-format.md +6 -5
  114. package/docs/records-and-queries.md +12 -13
  115. package/docs/storage.md +41 -15
  116. package/package.json +10 -19
  117. package/dist/identity/account-store.d.ts +0 -83
  118. package/dist/identity/account-store.d.ts.map +0 -1
  119. package/dist/identity/account-store.js +0 -234
  120. package/dist/identity/account-store.js.map +0 -1
  121. package/dist/identity/device-key.d.ts +0 -26
  122. package/dist/identity/device-key.d.ts.map +0 -1
  123. package/dist/identity/device-key.js +0 -48
  124. package/dist/identity/device-key.js.map +0 -1
  125. package/dist/identity/idb.d.ts +0 -19
  126. package/dist/identity/idb.d.ts.map +0 -1
  127. package/dist/identity/idb.js +0 -56
  128. package/dist/identity/idb.js.map +0 -1
  129. package/dist/node/worker.d.ts +0 -91
  130. package/dist/node/worker.d.ts.map +0 -1
  131. package/dist/node/worker.js +0 -344
  132. package/dist/node/worker.js.map +0 -1
  133. package/dist/node-worker.d.ts +0 -2
  134. package/dist/node-worker.d.ts.map +0 -1
  135. package/dist/node-worker.js +0 -16
  136. package/dist/node-worker.js.map +0 -1
  137. package/dist/session/account-hint.d.ts +0 -13
  138. package/dist/session/account-hint.d.ts.map +0 -1
  139. package/dist/session/account-hint.js +0 -54
  140. package/dist/session/account-hint.js.map +0 -1
  141. package/dist/session/channel-room.d.ts +0 -26
  142. package/dist/session/channel-room.d.ts.map +0 -1
  143. package/dist/session/channel-room.js +0 -56
  144. package/dist/session/channel-room.js.map +0 -1
  145. package/dist/session/connect-code.d.ts +0 -127
  146. package/dist/session/connect-code.d.ts.map +0 -1
  147. package/dist/session/connect-code.js +0 -408
  148. package/dist/session/connect-code.js.map +0 -1
  149. package/dist/session/connect.d.ts +0 -393
  150. package/dist/session/connect.d.ts.map +0 -1
  151. package/dist/session/connect.js +0 -587
  152. package/dist/session/connect.js.map +0 -1
  153. package/dist/session/connection.d.ts +0 -141
  154. package/dist/session/connection.d.ts.map +0 -1
  155. package/dist/session/connection.js +0 -344
  156. package/dist/session/connection.js.map +0 -1
  157. package/dist/session/index.d.ts +0 -24
  158. package/dist/session/index.d.ts.map +0 -1
  159. package/dist/session/index.js +0 -18
  160. package/dist/session/index.js.map +0 -1
  161. package/dist/session/pairing.d.ts +0 -97
  162. package/dist/session/pairing.d.ts.map +0 -1
  163. package/dist/session/pairing.js +0 -251
  164. package/dist/session/pairing.js.map +0 -1
  165. package/dist/session/places.d.ts +0 -71
  166. package/dist/session/places.d.ts.map +0 -1
  167. package/dist/session/places.js +0 -130
  168. package/dist/session/places.js.map +0 -1
  169. package/dist/session/popup.d.ts +0 -13
  170. package/dist/session/popup.d.ts.map +0 -1
  171. package/dist/session/popup.js +0 -23
  172. package/dist/session/popup.js.map +0 -1
  173. package/dist/session/stay-signed-in.d.ts +0 -48
  174. package/dist/session/stay-signed-in.d.ts.map +0 -1
  175. package/dist/session/stay-signed-in.js +0 -141
  176. package/dist/session/stay-signed-in.js.map +0 -1
  177. package/dist/storage/blob/directory.d.ts +0 -14
  178. package/dist/storage/blob/directory.d.ts.map +0 -1
  179. package/dist/storage/blob/directory.js +0 -87
  180. package/dist/storage/blob/directory.js.map +0 -1
  181. package/dist/storage/blob/memory.d.ts +0 -6
  182. package/dist/storage/blob/memory.d.ts.map +0 -1
  183. package/dist/storage/blob/memory.js +0 -20
  184. package/dist/storage/blob/memory.js.map +0 -1
  185. package/dist/storage/blob/s3.d.ts +0 -16
  186. package/dist/storage/blob/s3.d.ts.map +0 -1
  187. package/dist/storage/blob/s3.js +0 -91
  188. package/dist/storage/blob/s3.js.map +0 -1
  189. package/dist/storage/directory-access.d.ts +0 -36
  190. package/dist/storage/directory-access.d.ts.map +0 -1
  191. package/dist/storage/directory-access.js +0 -89
  192. package/dist/storage/directory-access.js.map +0 -1
  193. package/dist/storage/folder-adapter.d.ts +0 -100
  194. package/dist/storage/folder-adapter.d.ts.map +0 -1
  195. package/dist/storage/folder-adapter.js +0 -232
  196. package/dist/storage/folder-adapter.js.map +0 -1
  197. package/dist/storage/folder-reconcile.d.ts +0 -33
  198. package/dist/storage/folder-reconcile.d.ts.map +0 -1
  199. package/dist/storage/folder-reconcile.js.map +0 -1
  200. package/dist/storage/index.d.ts +0 -6
  201. package/dist/storage/index.d.ts.map +0 -1
  202. package/dist/storage/index.js +0 -5
  203. package/dist/storage/index.js.map +0 -1
  204. package/dist/storage/indexeddb-adapter.d.ts +0 -8
  205. package/dist/storage/indexeddb-adapter.d.ts.map +0 -1
  206. package/dist/storage/indexeddb-adapter.js +0 -128
  207. package/dist/storage/indexeddb-adapter.js.map +0 -1
  208. package/dist/storage/sqlite-adapter.d.ts +0 -57
  209. package/dist/storage/sqlite-adapter.d.ts.map +0 -1
  210. package/dist/storage/sqlite-adapter.js +0 -213
  211. package/dist/storage/sqlite-adapter.js.map +0 -1
  212. /package/dist/{session → hosting}/hosting.js +0 -0
@@ -1,393 +0,0 @@
1
- import { type Delegation } from '../identity/ucan.js';
2
- import { type NoteTerms } from '../identity/abilities.js';
3
- import type { RootSigner } from '../identity/root-signer.js';
4
- import { type WorkerLike } from '../node/worker.js';
5
- import type { StoreFactory } from '../node/stores.js';
6
- import type { Version } from '../types.js';
7
- import type { CacheConfig, NewSpace, NodeNetworkConfig, P2PNode } from '../node/types.js';
8
- import { type AutomationProposal } from '../space/own-automations.js';
9
- import { type KeyValueStore } from './stay-signed-in.js';
10
- /** What an app asks a home for */
11
- export interface ConnectRequest {
12
- readonly v: 1;
13
- /** The app's key — the note is made out to it */
14
- readonly audience: string;
15
- /**
16
- * That key's signature over what it agreed to (`keyProof`): its DID, how it
17
- * reached the app (`via`) and whether it asked for records only. So a
18
- * request can only name a key its sender holds, for what that key asked:
19
- * disconnecting revokes the key, and must never revoke someone else's.
20
- */
21
- readonly proof: string;
22
- /** What the app calls itself. Shown, but never trusted: the home shows the origin too. */
23
- readonly name?: string;
24
- /**
25
- * `write` to change the spaces it is given, `read` only to look. `carry` is
26
- * for a carrier — a browser extension keeping the spaces online — which gets
27
- * passes and no keys (`connectCarrier`).
28
- */
29
- readonly access: 'read' | 'write' | 'carry';
30
- /**
31
- * `spaces` (the default): only the spaces the person picks, and any made for
32
- * the app. `account`: every space, the account's space list, and making and
33
- * joining spaces itself — for an app that is a view onto the whole account.
34
- * Either way the app never gets the seed.
35
- */
36
- readonly scope?: 'spaces' | 'account';
37
- /** Spaces the home should make for the app, and give it */
38
- readonly create?: ReadonlyArray<NewSpace>;
39
- /**
40
- * The account's contacts: the contacts space, and the contact key that opens
41
- * contact requests sent to the account. Asking someone, or accepting, also
42
- * needs `account` scope — both make or join a space for two.
43
- */
44
- readonly contacts?: boolean;
45
- /** Whether to offer the person's existing spaces to pick from. Default true. */
46
- readonly chooseSpaces?: boolean;
47
- /**
48
- * A note that grants writing records and nothing more (`/record`), so
49
- * every peer refuses its key changing a space's collections or who may do
50
- * what, or writing in the account's own spaces. No contact key, no spaces
51
- * made for it, and no carrying.
52
- */
53
- readonly recordsOnly?: boolean;
54
- /**
55
- * `code`: the key is a program's, which reached the home itself over a
56
- * connect code (`connect-code.ts`); the home makes such a request, an app
57
- * never sends one. The home keeps its connection by its key. Absent: an
58
- * app's own key.
59
- */
60
- readonly via?: 'code';
61
- /** How many days the note should last, 1–365. The home decides; default 7. */
62
- readonly days?: number;
63
- }
64
- /**
65
- * What an app already connected to a home asks for when the person wants to
66
- * be notified: automations of the account's own, and nothing else. Never part of connecting — a
67
- * person signing in has asked for nothing yet. The home knows the app by the
68
- * origin the browser reports, and refuses one it has no connection for, a
69
- * carrier's and a program's connected by code.
70
- */
71
- export interface ProposeRequest {
72
- readonly v: 2;
73
- readonly kind: 'propose';
74
- /** What it calls itself. Shown, never trusted. */
75
- readonly name?: string;
76
- /** 1 to 8 automations to offer the person */
77
- readonly automations: ReadonlyArray<AutomationProposal>;
78
- }
79
- /** What the home answers a {@link ProposeRequest} with, once the person decided */
80
- export interface Proposed {
81
- readonly v: 2;
82
- readonly kind: 'proposed';
83
- /** The automations added or found, by the person's yes: none when they kept none */
84
- readonly automations: ReadonlyArray<{
85
- readonly id: string;
86
- readonly name: string;
87
- }>;
88
- /**
89
- * For an app given the whole account: every version of those automations,
90
- * signed, so its node holds them at once rather than once it meets another
91
- * of the account's devices, which may be long after the home's window closed.
92
- */
93
- readonly versions?: ReadonlyArray<Version>;
94
- }
95
- /** Whether a request the home received is a proposal rather than a connection */
96
- export declare const isProposeRequest: (request: ConnectRequest | ProposeRequest) => request is ProposeRequest;
97
- /** The longest a home gives a note for */
98
- export declare const MAX_GRANT_DAYS = 365;
99
- /** A space an app was given */
100
- export interface GrantedSpace {
101
- readonly id: string;
102
- readonly name: string;
103
- /** What the app joins it with — carrying the key, for a private space */
104
- readonly invite: string;
105
- /**
106
- * For a private space: the account's member key there (base64url,
107
- * `deriveMemberKeyBytes`), which opens the space's next key when it
108
- * changes. It opens nothing else.
109
- */
110
- readonly memberKey?: string;
111
- }
112
- /** A grant's format: 2 since its note is a delegation in the UCAN 1.0 profile (spec 01 §7) */
113
- export declare const GRANT_VERSION = 2;
114
- /** What the home hands back when the person approves */
115
- export interface Grant {
116
- readonly v: typeof GRANT_VERSION;
117
- /** The account's identity — what the app acts for */
118
- readonly did: string;
119
- /** The account's name, for showing who is connected */
120
- readonly name: string;
121
- /** The signed note: the account → the app's key, for these spaces, until `expiresAt` */
122
- readonly note: Delegation;
123
- readonly access: 'read' | 'write';
124
- readonly scope: 'spaces' | 'account';
125
- readonly spaces: ReadonlyArray<GrantedSpace>;
126
- /**
127
- * With `account` scope: the key the account's space list is derived from
128
- * (base64url), so the app sees every space and adds the ones it makes or
129
- * joins. It opens every private space in the account — which is what whole
130
- * account access means — but it cannot sign as the account.
131
- */
132
- readonly accountKey?: string;
133
- /**
134
- * With `contacts`, or `account` scope: the contact key's private scalar
135
- * (base64url), which opens contact requests sent to the account
136
- * (`deriveContactKeyBytes`). It cannot sign as the account.
137
- */
138
- readonly contactKey?: string;
139
- /** With `contacts`: which of `spaces` is the account's contacts space */
140
- readonly contactsSpace?: string;
141
- /** Unix seconds */
142
- readonly expiresAt: number;
143
- /** The home that granted it, so the app can go back there */
144
- readonly home: string;
145
- /**
146
- * Relays the home meets peers on. A home someone runs themselves may use
147
- * different ones from the app, and two peers that share no relay never
148
- * meet — so the app joins these as well.
149
- */
150
- readonly relays?: ReadonlyArray<string>;
151
- }
152
- /**
153
- * What the home hands a carrier: a way into its carry space, which holds a
154
- * pass for each of the account's spaces — and nothing that reads or writes
155
- * them (`space/pass.ts`).
156
- */
157
- export interface CarryGrant {
158
- readonly v: 1;
159
- readonly kind: 'carry';
160
- /** The account it carries for */
161
- readonly did: string;
162
- /** The account's name, for showing whose spaces these are */
163
- readonly name: string;
164
- /** The carry space, and the view-only invite to it */
165
- readonly carry: {
166
- readonly space: string;
167
- readonly invite: string;
168
- };
169
- /**
170
- * Where the account keeps its data, when it lives in a pod: the path inside
171
- * the pod folder, and the folder's name to help the person find it. Null
172
- * when the account lives in the home's browser storage.
173
- */
174
- readonly pod: {
175
- readonly dataPath: string;
176
- readonly folder: string;
177
- } | null;
178
- readonly relays?: ReadonlyArray<string>;
179
- /** The home that granted it */
180
- readonly home: string;
181
- }
182
- /**
183
- * Turns what a person typed into a home's connect page:
184
- * `minca.example.com` → `https://minca.example.com/connect`. Plain `http` only
185
- * for this machine, where development happens.
186
- * @throws When it is not a web address
187
- */
188
- export declare function homeAddress(input: string): string;
189
- /**
190
- * The terms of the note a grant carries, for these spaces. Writing is every
191
- * command; `records` is records only, for a key the account trusts less: it
192
- * can't define collections, change who may do what, or write for the
193
- * account (`identity/abilities.ts`).
194
- */
195
- export declare function grantTerms(access: 'read' | 'write' | 'records', spaceIds: ReadonlyArray<string> | 'all'): NoteTerms;
196
- /**
197
- * What a key agrees to in a connect request: how it reached the home, how
198
- * much it asks for, and, for a program's key handed over a code, the home it
199
- * was handed to.
200
- */
201
- export type KeyTerms =
202
- /** An app's own key */
203
- {
204
- readonly via: 'popup';
205
- readonly recordsOnly: boolean;
206
- }
207
- /** A program's key, handed to the home at `origin` over a connect code */
208
- | {
209
- readonly via: 'code';
210
- readonly recordsOnly: boolean;
211
- readonly origin: string;
212
- };
213
- /** The terms a request names, as the home received it from `origin` */
214
- export declare const requestTerms: (request: Pick<ConnectRequest, 'via' | 'recordsOnly'>, origin: string) => KeyTerms;
215
- /** A key's proof that it holds itself, for a connect request with these terms (`ConnectRequest.proof`) */
216
- export declare function keyProof(key: {
217
- readonly keys: CryptoKeyPair;
218
- readonly did: string;
219
- }, terms?: KeyTerms): Promise<string>;
220
- /** Whether `proof` was made by the key `audience` names, for a request with these terms */
221
- export declare function checkKeyProof(audience: string, proof: unknown, terms: KeyTerms): Promise<boolean>;
222
- export interface AppKey {
223
- readonly keys: CryptoKeyPair;
224
- readonly did: string;
225
- }
226
- /** An app key with what it is derived from: what a node in a worker is handed, since a `CryptoKey` can't be */
227
- export interface SeededAppKey extends AppKey {
228
- readonly seed: Uint8Array;
229
- }
230
- /**
231
- * This app's key: derived from a seed made once and kept in this site's
232
- * IndexedDB. A script that gets into the page can read the seed, as it can
233
- * the session of any web app; the grant made out to the key runs out, and
234
- * the account home can take it back sooner.
235
- */
236
- export declare function appKey(name?: string): Promise<SeededAppKey>;
237
- /** The app key a seed stands for */
238
- export declare function appKeyFromSeed(seed: Uint8Array): Promise<SeededAppKey>;
239
- /** Forgets this app's key. The next connection makes a new one. */
240
- export declare function forgetAppKey(name?: string): Promise<void>;
241
- export interface ConnectOptions {
242
- /** The home's connect page, e.g. `https://minca.example/connect` */
243
- readonly home: string;
244
- /** What to ask for; `audience`, `proof` and `via` are filled in */
245
- readonly request: Omit<ConnectRequest, 'v' | 'audience' | 'proof' | 'via'>;
246
- /** The key to ask for, or its promise, awaited once the popup is open. Default: {@link appKey} under `keyName`. */
247
- readonly key?: AppKey | Promise<AppKey>;
248
- /** Which of this app's keys to use when `key` is not given. Default `default`. */
249
- readonly keyName?: string;
250
- /** How long to wait for the person. Default 10 minutes. */
251
- readonly timeoutMs?: number;
252
- }
253
- /**
254
- * Opens the home and asks for access. Call it from a click — browsers only
255
- * allow a popup that a person asked for.
256
- *
257
- * @returns The grant, checked: signed by the account, made out to this app's key
258
- * @throws When the popup is blocked, closed, denied, or the answer does not check out
259
- */
260
- export declare function connectToHome(options: ConnectOptions): Promise<Grant>;
261
- /**
262
- * Asks a home to use this carrier — a browser extension, say — for the
263
- * account. Call it from a click, in a page that stays open until the answer
264
- * comes: an extension's toolbar popup closes the moment the home's window
265
- * takes focus, and the answer would have nowhere to go.
266
- *
267
- * @param options.key The carrier's own key; it becomes its name to peers
268
- * @returns The grant, checked: an invite to a private carry space the account made
269
- */
270
- export declare function connectCarrier(options: {
271
- readonly home: string;
272
- readonly key: AppKey;
273
- readonly name?: string;
274
- readonly timeoutMs?: number;
275
- }): Promise<CarryGrant>;
276
- /**
277
- * Offers the person automations that notify them, from an app already connected to their
278
- * home. Call it from a click on something that asked for it — "Notify me" —
279
- * in a page that stays open: the home opens in a popup, and the person keeps
280
- * the ones they want. The app shows the notifications itself
281
- * (`watchNotifications`).
282
- *
283
- * @param options.home The home it connected to — a grant's `home`
284
- * @returns What the home added or found; an empty list when the person kept none
285
- * @throws When the popup is blocked, closed or denied, or the home knows no connection from here
286
- */
287
- export declare function proposeToHome(options: {
288
- readonly home: string;
289
- readonly automations: ReadonlyArray<AutomationProposal>;
290
- readonly name?: string;
291
- readonly timeoutMs?: number;
292
- }): Promise<Proposed>;
293
- /**
294
- * Refuses a grant that is not a valid note from the account to this key, or,
295
- * when records only were asked for, one that grants more.
296
- */
297
- export declare function checkGrant(grant: Grant, audience: string, asked?: {
298
- readonly recordsOnly?: boolean;
299
- }): Promise<void>;
300
- /**
301
- * A signer that answers with the note the home gave — the app holds nothing
302
- * else. Given a getter, it answers with whichever grant is current.
303
- */
304
- export declare function grantSigner(grant: Grant | (() => Grant | null)): RootSigner;
305
- /** Whether a grant's note has run out */
306
- export declare const grantExpired: (grant: Pick<Grant, 'expiresAt'>) => boolean;
307
- /**
308
- * Watches a node started under a grant: `onExpired` once its note runs out,
309
- * `onRevoked` for each space where the home revoked its key.
310
- * @returns How to stop watching
311
- */
312
- export declare function watchGrant(node: Pick<P2PNode, 'subscribe'>, grant: Pick<Grant, 'expiresAt'>, on: {
313
- readonly onExpired?: () => void;
314
- readonly onRevoked?: (space: string) => void;
315
- }): () => void;
316
- /** Whether a kept grant still works: one kept in an older format holds a note no peer reads now */
317
- export declare const usableGrant: (grant: Grant | null) => boolean;
318
- /**
319
- * Starts a node acting for the account, under a grant.
320
- *
321
- * It joins the granted spaces (again, harmlessly, on later starts) and keeps
322
- * its data in this site's storage. It has no account key: it sees the spaces
323
- * it was given, not the account's whole list.
324
- *
325
- * In a space that names a keeper it holds only the collections the app uses
326
- * (`cache`); pass `cache: false` to hold every space whole.
327
- */
328
- export declare function startConnectedNode(params: {
329
- readonly grant: Grant;
330
- readonly key?: SeededAppKey;
331
- readonly network?: NodeNetworkConfig;
332
- readonly stores?: StoreFactory;
333
- readonly cache?: CacheConfig | false;
334
- /** Runs the node in a worker, off the page's main thread. Not with `stores`, which a worker can't be handed. */
335
- readonly worker?: () => WorkerLike;
336
- }): Promise<P2PNode>;
337
- /**
338
- * What a node started under a grant takes from it: the keys it carries, and
339
- * the home's relays as well as the app's, so the two always share one.
340
- */
341
- export declare function nodeOptionsFromGrant(grant: Grant, relays?: ReadonlyArray<string>): {
342
- relays: string[];
343
- accountKey?: Uint8Array<ArrayBuffer> | undefined;
344
- contactKey?: Uint8Array<ArrayBuffer> | undefined;
345
- contactsSpace?: string | undefined;
346
- accountName?: string | undefined;
347
- };
348
- /**
349
- * Joins the spaces a grant names that the node doesn't hold yet: again,
350
- * harmlessly, on later starts. A space that won't join throws, unless
351
- * `onError` takes it and the rest are joined.
352
- */
353
- export declare function joinGranted(node: P2PNode, grant: Grant, onError?: (error: unknown) => void): Promise<void>;
354
- /** An account an app is connected to: its grant, and the name of the app key it is made out to ({@link appKey}) */
355
- export interface KeptGrant {
356
- readonly grant: Grant;
357
- readonly keyName: string;
358
- }
359
- /**
360
- * Where an app keeps its grants between visits: one per account, each made
361
- * out to a key of its own, so two accounts never show peers one key.
362
- */
363
- export declare function grantStore(storage?: KeyValueStore | null, key?: string): {
364
- /** Every account, the one connected first first; an expired grant stays, to show and renew */
365
- list: () => ReadonlyArray<KeptGrant>;
366
- get: (did: string) => KeptGrant | null;
367
- save(grant: Grant, keyName: string): void;
368
- forget: (did: string) => void;
369
- };
370
- /** A request as the home received it */
371
- export interface IncomingRequest {
372
- readonly request: ConnectRequest | ProposeRequest;
373
- /** Where it came from, as the browser reports it — the only name to trust */
374
- readonly origin: string;
375
- /** For a program connected by code: the six digits the person gives the program, which keeps its note only then */
376
- readonly check?: string;
377
- /**
378
- * Sends the answer back to that origin, and closes the window — once
379
- * `closeAfter` settles, when given: what this window's node wrote for the
380
- * asker may still have to reach it.
381
- */
382
- approve(answer: Omit<Grant, 'home'> | Omit<CarryGrant, 'home'> | Proposed, closeAfter?: Promise<unknown>): void;
383
- /** Says no, and closes the window */
384
- deny(reason?: string): void;
385
- }
386
- /**
387
- * Waits for the app that opened this page to say what it wants. It says hello
388
- * once, and listens long: on a phone the app's tab behind this one may not run
389
- * for a while, and its request (which it repeats) comes when it does.
390
- * @returns The request, or null when this page was not opened by an app, the app's window closed, or none came in time
391
- */
392
- export declare function receiveConnectRequest(timeoutMs?: number): Promise<IncomingRequest | null>;
393
- //# sourceMappingURL=connect.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../../src/session/connect.ts"],"names":[],"mappings":"AAaA,OAAO,EAAc,KAAK,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAML,KAAK,SAAS,EACf,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAiB,KAAK,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAI1F,OAAO,EAAgC,KAAK,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACpG,OAAO,EAAkC,KAAK,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAWzF,kCAAkC;AAClC,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC;IACd,iDAAiD;IACjD,QAAQ,CAAC,Q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