@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,587 +0,0 @@
1
- /**
2
- * @module session/connect
3
- * An app using an account without ever seeing its seed. The app opens the
4
- * account home in a popup with its own non-exportable key; the person approves
5
- * there, and the home signs a note (a delegation) letting that key write in the
6
- * spaces given, which every peer checks. The two sides talk by `postMessage`,
7
- * each checking the other's origin as the browser reports it.
8
- */
9
- import { createP256Provider } from '../identity/crypto-p256.js';
10
- import { didOf, didToPublicKey } from '../identity/did.js';
11
- import { canonicalize } from '../schema/version.js';
12
- import { idbOnce } from '../identity/idb.js';
13
- import { base64UrlDecode, base64UrlEncode, utf8Encode } from '../utils/encoding.js';
14
- import { verifyNote } from '../identity/ucan.js';
15
- import { ALL_COMMAND, grantsRecordsOnly, noteTerms, READ_COMMAND, RECORDS_COMMAND, } from '../identity/abilities.js';
16
- import { startPageNode } from '../node/worker.js';
17
- import { checkFoundingRoles } from '../space/grants.js';
18
- import { parseSpaceInvite } from '../space/space-manager.js';
19
- import { soleFounder } from '../space/constitution.js';
20
- import { checkProposal, MAX_PROPOSALS } from '../space/own-automations.js';
21
- import { defaultStorage, guardedStorage } from './stay-signed-in.js';
22
- import { isObject, unref } from '../utils/guards.js';
23
- import { popupFeatures } from './popup.js';
24
- import { markStep } from '../utils/step.js';
25
- /** Messages between an app and the home it opened */
26
- const HELLO = 'minca:hello';
27
- const REQUEST = 'minca:request';
28
- const GRANT = 'minca:grant';
29
- const DENIED = 'minca:denied';
30
- /** Whether a request the home received is a proposal rather than a connection */
31
- export const isProposeRequest = (request) => 'kind' in request && request.kind === 'propose';
32
- /** The longest a home gives a note for */
33
- export const MAX_GRANT_DAYS = 365;
34
- /** A grant's format: 2 since its note is a delegation in the UCAN 1.0 profile (spec 01 §7) */
35
- export const GRANT_VERSION = 2;
36
- /**
37
- * Turns what a person typed into a home's connect page:
38
- * `minca.example.com` → `https://minca.example.com/connect`. Plain `http` only
39
- * for this machine, where development happens.
40
- * @throws When it is not a web address
41
- */
42
- export function homeAddress(input) {
43
- const trimmed = input.trim();
44
- if (!trimmed)
45
- throw new Error('Type the address of your account home.');
46
- const local = /^(localhost|127\.0\.0\.1|\[::1\])(:\d+)?(\/|$)/.test(trimmed);
47
- const withScheme = /^[a-z][a-z0-9+.-]*:\/\//i.test(trimmed)
48
- ? trimmed
49
- : `${local ? 'http' : 'https'}://${trimmed}`;
50
- let url;
51
- try {
52
- url = new URL(withScheme);
53
- }
54
- catch {
55
- throw new Error(`"${trimmed}" isn’t a web address. Type one like home.minca.social.`);
56
- }
57
- const loopback = ['localhost', '127.0.0.1', '[::1]'].includes(url.hostname);
58
- // Browsers parse more than they should ("not a url" becomes a host), so ask
59
- // for a name that could be a real domain.
60
- if (!loopback && !/^([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)+[a-z]{2,}$/i.test(url.hostname)) {
61
- throw new Error(`"${trimmed}" isn’t a web address. Type one like home.minca.social.`);
62
- }
63
- if (url.protocol !== 'https:' && !(url.protocol === 'http:' && loopback)) {
64
- throw new Error('An account home must be on https://. Check the address.');
65
- }
66
- if (url.pathname === '/' || url.pathname === '')
67
- url.pathname = '/connect';
68
- url.hash = '';
69
- url.search = '';
70
- return url.href;
71
- }
72
- /**
73
- * The terms of the note a grant carries, for these spaces. Writing is every
74
- * command; `records` is records only, for a key the account trusts less: it
75
- * can't define collections, change who may do what, or write for the
76
- * account (`identity/abilities.ts`).
77
- */
78
- export function grantTerms(access, spaceIds) {
79
- const command = access === 'write' ? ALL_COMMAND : access === 'records' ? RECORDS_COMMAND : READ_COMMAND;
80
- return noteTerms(command, spaceIds);
81
- }
82
- // ─── The app's side ──────────────────────────────────────────────────
83
- /** What a key signs to show it is the one a connect request names */
84
- const KEY_PROOF = 'minca/connect-key/v1';
85
- /**
86
- * The statement, terms included: a proof a program hands a home over a code
87
- * can't ask for an app's connection, nor for more than records, nor be used
88
- * at another home.
89
- */
90
- const keyStatement = (audience, terms) => utf8Encode(canonicalize({
91
- audience,
92
- ...(terms.via === 'code' ? { origin: terms.origin } : {}),
93
- proof: KEY_PROOF,
94
- recordsOnly: terms.recordsOnly,
95
- via: terms.via,
96
- }));
97
- /** The terms a request names, as the home received it from `origin` */
98
- export const requestTerms = (request, origin) => request.via === 'code'
99
- ? { via: 'code', recordsOnly: request.recordsOnly === true, origin }
100
- : { via: 'popup', recordsOnly: request.recordsOnly === true };
101
- /** A key's proof that it holds itself, for a connect request with these terms (`ConnectRequest.proof`) */
102
- export async function keyProof(key, terms = { via: 'popup', recordsOnly: false }) {
103
- return base64UrlEncode(await createP256Provider().sign(key.keys.privateKey, keyStatement(key.did, terms)));
104
- }
105
- /** Whether `proof` was made by the key `audience` names, for a request with these terms */
106
- export async function checkKeyProof(audience, proof, terms) {
107
- if (typeof proof !== 'string')
108
- return false;
109
- try {
110
- const provider = createP256Provider();
111
- const publicKey = await provider.importPublicKey(didToPublicKey(audience).publicKeyBytes);
112
- return await provider.verify(publicKey, base64UrlDecode(proof), keyStatement(audience, terms));
113
- }
114
- catch {
115
- return false;
116
- }
117
- }
118
- const KEY_DB = 'minca-app-key';
119
- /**
120
- * This app's key: derived from a seed made once and kept in this site's
121
- * IndexedDB. A script that gets into the page can read the seed, as it can
122
- * the session of any web app; the grant made out to the key runs out, and
123
- * the account home can take it back sooner.
124
- */
125
- export async function appKey(name = 'default') {
126
- const stored = await idbOnce(KEY_DB, 'keys', 'readonly', (store) => store.get(name));
127
- const seed = stored instanceof Uint8Array ? stored : globalThis.crypto.getRandomValues(new Uint8Array(32));
128
- if (seed !== stored)
129
- await idbOnce(KEY_DB, 'keys', 'readwrite', (store) => store.put(seed, name));
130
- return appKeyFromSeed(seed);
131
- }
132
- /** The app key a seed stands for */
133
- export async function appKeyFromSeed(seed) {
134
- const keys = await createP256Provider().deriveKeyPairFromSeed(seed);
135
- return { keys, did: await didOf(keys.publicKey), seed };
136
- }
137
- /** Forgets this app's key. The next connection makes a new one. */
138
- export async function forgetAppKey(name = 'default') {
139
- await idbOnce(KEY_DB, 'keys', 'readwrite', (store) => store.delete(name));
140
- }
141
- /**
142
- * Opens the home and asks for access. Call it from a click — browsers only
143
- * allow a popup that a person asked for.
144
- *
145
- * @returns The grant, checked: signed by the account, made out to this app's key
146
- * @throws When the popup is blocked, closed, denied, or the answer does not check out
147
- */
148
- export async function connectToHome(options) {
149
- const homeUrl = new URL(options.home, globalThis.location.href);
150
- // Opened before anything is awaited, so it still counts as the click's.
151
- const popup = openHome(homeUrl);
152
- const request = (async () => {
153
- const key = (await options.key) ?? (await appKey(options.keyName));
154
- const proof = await keyProof(key, { via: 'popup', recordsOnly: options.request.recordsOnly === true });
155
- return { v: 1, audience: key.did, proof, ...options.request };
156
- })();
157
- const grant = await askHome(popup, homeUrl.origin, request, options.timeoutMs);
158
- const { audience } = await request;
159
- await checkGrant(grant, audience, { recordsOnly: options.request.recordsOnly === true });
160
- return { ...grant, home: homeUrl.href };
161
- }
162
- /**
163
- * Asks a home to use this carrier — a browser extension, say — for the
164
- * account. Call it from a click, in a page that stays open until the answer
165
- * comes: an extension's toolbar popup closes the moment the home's window
166
- * takes focus, and the answer would have nowhere to go.
167
- *
168
- * @param options.key The carrier's own key; it becomes its name to peers
169
- * @returns The grant, checked: an invite to a private carry space the account made
170
- */
171
- export async function connectCarrier(options) {
172
- const homeUrl = new URL(options.home, globalThis.location.href);
173
- const popup = openHome(homeUrl);
174
- const request = keyProof(options.key).then((proof) => ({
175
- v: 1,
176
- audience: options.key.did,
177
- proof,
178
- access: 'carry',
179
- ...(options.name ? { name: options.name } : {}),
180
- }));
181
- const grant = await askHome(popup, homeUrl.origin, request, options.timeoutMs);
182
- checkCarryGrant(grant);
183
- return { ...grant, home: homeUrl.href };
184
- }
185
- /**
186
- * Offers the person automations that notify them, from an app already connected to their
187
- * home. Call it from a click on something that asked for it — "Notify me" —
188
- * in a page that stays open: the home opens in a popup, and the person keeps
189
- * the ones they want. The app shows the notifications itself
190
- * (`watchNotifications`).
191
- *
192
- * @param options.home The home it connected to — a grant's `home`
193
- * @returns What the home added or found; an empty list when the person kept none
194
- * @throws When the popup is blocked, closed or denied, or the home knows no connection from here
195
- */
196
- export async function proposeToHome(options) {
197
- if (options.automations.length === 0 || options.automations.length > MAX_PROPOSALS)
198
- throw new Error(`Propose 1 to ${MAX_PROPOSALS} automations.`);
199
- const homeUrl = new URL(options.home, globalThis.location.href);
200
- const popup = openHome(homeUrl);
201
- const request = {
202
- v: 2,
203
- kind: 'propose',
204
- ...(options.name ? { name: options.name } : {}),
205
- automations: options.automations,
206
- };
207
- const answer = await askHome(popup, homeUrl.origin, request, options.timeoutMs);
208
- if (answer?.kind !== 'proposed' || !Array.isArray(answer.automations))
209
- throw new Error('Your account home did not answer the proposal.');
210
- return answer;
211
- }
212
- /** Refuses a carry grant that is not an invite to a private space the account made. */
213
- function checkCarryGrant(grant) {
214
- if (grant?.kind !== 'carry' || typeof grant.did !== 'string' || typeof grant.carry?.invite !== 'string') {
215
- throw new Error('The home did not answer with a way to carry your spaces.');
216
- }
217
- const invite = parseSpaceInvite(grant.carry.invite);
218
- if (invite.space.id !== grant.carry.space ||
219
- soleFounder(invite.space) !== grant.did ||
220
- invite.space.visibility !== 'private' ||
221
- !invite.key) {
222
- throw new Error('The carry space the home named does not check out.');
223
- }
224
- if (grant.pod !== null &&
225
- (typeof grant.pod?.dataPath !== 'string' ||
226
- grant.pod.dataPath.split('/').some((part) => !part || part === '..'))) {
227
- throw new Error('The pod the home named does not check out.');
228
- }
229
- }
230
- function openHome(homeUrl) {
231
- const popup = globalThis.open(homeUrl.href, 'minca-home', popupFeatures(460, 720));
232
- if (!popup)
233
- throw new Error('The browser blocked the window your account home opens in. Allow pop-ups for this site, then try again.');
234
- return popup;
235
- }
236
- /**
237
- * Sends the request when the home says hello, and again every half second
238
- * until it answers, only ever to the home's origin; then waits for the answer,
239
- * which the caller checks. A phone may hardly run this page while the home is
240
- * in front, so the hello can arrive before the request is made, or be missed:
241
- * it listens from the start, and the repeats reach a home that has loaded.
242
- */
243
- function askHome(popup, homeOrigin, request, timeoutMs = 10 * 60_000) {
244
- return new Promise((resolve, reject) => {
245
- let finished = false;
246
- const done = (finish) => {
247
- if (finished)
248
- return;
249
- finished = true;
250
- globalThis.removeEventListener('message', onMessage);
251
- globalThis.clearInterval(watch);
252
- globalThis.clearTimeout(timer);
253
- finish();
254
- };
255
- let made = null;
256
- // Until the home says hello, the popup may still be a blank page of this origin: posting there only logs an error.
257
- let heard = false;
258
- const send = () => {
259
- if (made && heard && !finished)
260
- popup.postMessage({ type: REQUEST, request: made }, homeOrigin);
261
- };
262
- const ready = Promise.resolve(request);
263
- ready.then((value) => {
264
- made = value;
265
- }, () => { });
266
- ready.catch((error) => done(() => {
267
- popup.close();
268
- reject(error instanceof Error ? error : new Error(String(error)));
269
- }));
270
- const onMessage = (event) => {
271
- // Only the popup we opened, at the address we opened it on.
272
- if (event.source !== popup || event.origin !== homeOrigin)
273
- return;
274
- const data = event.data;
275
- if (!isObject(data))
276
- return;
277
- if (data.type === HELLO) {
278
- heard = true;
279
- void ready.then(send, () => { });
280
- }
281
- else if (data.type === GRANT && data.grant)
282
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- checkGrant, checkCarryGrant and proposeToHome check it
283
- done(() => resolve(data.grant));
284
- else if (data.type === DENIED)
285
- done(() => reject(new Error(typeof data.reason === 'string' ? data.reason : 'You didn’t allow it at your account home.')));
286
- };
287
- const watch = globalThis.setInterval(() => {
288
- if (popup.closed)
289
- done(() => reject(new Error('Your account home was closed before you allowed it. Try again.')));
290
- // Until the home answers; one that has its request already ignores the rest.
291
- else
292
- send();
293
- }, 500);
294
- const timer = globalThis.setTimeout(() => done(() => reject(new Error('Your account home didn’t answer. Check its address, and try again.'))), timeoutMs);
295
- globalThis.addEventListener('message', onMessage);
296
- });
297
- }
298
- /**
299
- * Refuses a grant that is not a valid note from the account to this key, or,
300
- * when records only were asked for, one that grants more.
301
- */
302
- export async function checkGrant(grant, audience, asked = {}) {
303
- if (!isObject(grant) || grant.v !== GRANT_VERSION || typeof grant.did !== 'string') {
304
- throw new Error('That is not a grant.');
305
- }
306
- const verified = await verifyNote(grant.note, createP256Provider());
307
- if (!verified.valid)
308
- throw new Error(`The grant does not check out: ${verified.reason}`);
309
- if (verified.audience !== audience)
310
- throw new Error('The grant was made out to a different key.');
311
- if (verified.root !== grant.did)
312
- throw new Error('The grant was not signed by the account it names.');
313
- if (asked.recordsOnly && !grantsRecordsOnly(grant.note))
314
- throw new Error('The grant gives more than records, which is all that was asked for.');
315
- }
316
- /**
317
- * A signer that answers with the note the home gave — the app holds nothing
318
- * else. Given a getter, it answers with whichever grant is current.
319
- */
320
- export function grantSigner(grant) {
321
- const current = typeof grant === 'function' ? grant : () => grant;
322
- return {
323
- get did() {
324
- return current()?.did ?? '';
325
- },
326
- async delegate({ audience }) {
327
- const now = current();
328
- if (!now || grantExpired(now))
329
- throw new Error('Access has run out. Connect to your account home again.');
330
- if (now.note.payload.aud !== audience)
331
- throw new Error('The key this app was connected with is gone. Connect to your account home again.');
332
- return now.note;
333
- },
334
- };
335
- }
336
- /** Whether a grant's note has run out */
337
- export const grantExpired = (grant) => grant.expiresAt <= Math.floor(Date.now() / 1000);
338
- /**
339
- * Watches a node started under a grant: `onExpired` once its note runs out,
340
- * `onRevoked` for each space where the home revoked its key.
341
- * @returns How to stop watching
342
- */
343
- export function watchGrant(node, grant, on) {
344
- let timer;
345
- // A timer waits at most 2^31 − 1 ms, some 24 days: a note that runs longer is looked at again then.
346
- const arm = () => {
347
- const left = Math.min(Math.max(grant.expiresAt * 1000 - Date.now(), 0), 2 ** 31 - 1);
348
- timer = globalThis.setTimeout(() => (grantExpired(grant) ? on.onExpired?.() : arm()), left);
349
- // It says when the note ran out; it is no reason for a process to stay up.
350
- unref(timer);
351
- };
352
- if (on.onExpired)
353
- arm();
354
- const unsubscribe = node.subscribe((event) => {
355
- if (event.type === 'revoked')
356
- on.onRevoked?.(event.space);
357
- });
358
- return () => {
359
- globalThis.clearTimeout(timer);
360
- unsubscribe();
361
- };
362
- }
363
- /** Whether a kept grant still works: one kept in an older format holds a note no peer reads now */
364
- export const usableGrant = (grant) => !!grant && grant.v === GRANT_VERSION && !grantExpired(grant);
365
- /**
366
- * Starts a node acting for the account, under a grant.
367
- *
368
- * It joins the granted spaces (again, harmlessly, on later starts) and keeps
369
- * its data in this site's storage. It has no account key: it sees the spaces
370
- * it was given, not the account's whole list.
371
- *
372
- * In a space that names a keeper it holds only the collections the app uses
373
- * (`cache`); pass `cache: false` to hold every space whole.
374
- */
375
- export async function startConnectedNode(params) {
376
- const key = params.key ?? (await appKey());
377
- const { relays, ...keys } = nodeOptionsFromGrant(params.grant, params.network?.relays);
378
- const network = params.network || relays.length ? { ...params.network, relays } : undefined;
379
- const node = await startPageNode({
380
- signer: grantSigner(params.grant),
381
- sessionKeySeed: key.seed,
382
- stores: { indexedDB: `minca-app:${params.grant.did}` },
383
- ...(network ? { network } : {}),
384
- ...(params.cache === false ? {} : { cache: params.cache ?? {} }),
385
- ...keys,
386
- }, params);
387
- markStep('connection: node started, joining the spaces the grant names');
388
- await joinGranted(node, params.grant);
389
- return node;
390
- }
391
- /**
392
- * What a node started under a grant takes from it: the keys it carries, and
393
- * the home's relays as well as the app's, so the two always share one.
394
- */
395
- export function nodeOptionsFromGrant(grant, relays = []) {
396
- return {
397
- relays: [...new Set([...relays, ...(grant.relays ?? [])])],
398
- ...(grant.accountKey ? { accountKey: base64UrlDecode(grant.accountKey) } : {}),
399
- // Never under records only, whatever the home sent: it opens contact requests and knocks.
400
- ...(grant.contactKey && !grantsRecordsOnly(grant.note)
401
- ? { contactKey: base64UrlDecode(grant.contactKey) }
402
- : {}),
403
- ...(grant.contactsSpace ? { contactsSpace: grant.contactsSpace } : {}),
404
- ...(grant.name ? { accountName: grant.name } : {}),
405
- };
406
- }
407
- /**
408
- * Joins the spaces a grant names that the node doesn't hold yet: again,
409
- * harmlessly, on later starts. A space that won't join throws, unless
410
- * `onError` takes it and the rest are joined.
411
- */
412
- export async function joinGranted(node, grant, onError) {
413
- const held = new Set((await node.spaces.list()).map((space) => space.id));
414
- for (const { id, invite, memberKey } of grant.spaces) {
415
- if (held.has(id))
416
- continue;
417
- const joining = node.spaces.join(invite, memberKey ? { memberKey: base64UrlDecode(memberKey) } : {});
418
- await (onError ? joining.catch(onError) : joining);
419
- }
420
- }
421
- /**
422
- * Where an app keeps its grants between visits: one per account, each made
423
- * out to a key of its own, so two accounts never show peers one key.
424
- */
425
- export function grantStore(storage = defaultStorage(), key = 'minca.grants') {
426
- const kept = guardedStorage(storage);
427
- const all = () =>
428
- // One kept in an older format holds a note no peer reads now: connecting again replaces it.
429
- (kept.read(key) ?? []).filter((each) => each?.grant?.v === GRANT_VERSION && typeof each.keyName === 'string');
430
- return {
431
- /** Every account, the one connected first first; an expired grant stays, to show and renew */
432
- list: all,
433
- get: (did) => all().find((each) => each.grant.did === did) ?? null,
434
- save(grant, keyName) {
435
- const before = all();
436
- const found = before.some((each) => each.grant.did === grant.did);
437
- kept.write(key, found
438
- ? before.map((each) => (each.grant.did === grant.did ? { grant, keyName } : each))
439
- : [...before, { grant, keyName }]);
440
- },
441
- forget: (did) => kept.write(key, all().filter((each) => each.grant.did !== did)),
442
- };
443
- }
444
- /**
445
- * Waits for the app that opened this page to say what it wants. It says hello
446
- * once, and listens long: on a phone the app's tab behind this one may not run
447
- * for a while, and its request (which it repeats) comes when it does.
448
- * @returns The request, or null when this page was not opened by an app, the app's window closed, or none came in time
449
- */
450
- export function receiveConnectRequest(timeoutMs = 10 * 60_000) {
451
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- lib.dom has it as any, and an opener on another origin is no instanceof Window here
452
- const opener = globalThis.opener;
453
- if (!opener)
454
- return Promise.resolve(null);
455
- return new Promise((resolve) => {
456
- const stop = () => {
457
- globalThis.removeEventListener('message', onMessage);
458
- globalThis.clearTimeout(timer);
459
- globalThis.clearInterval(watch);
460
- };
461
- const onMessage = (event) => {
462
- if (event.source !== opener)
463
- return;
464
- const data = event.data;
465
- if (!isObject(data) || data.type !== REQUEST)
466
- return;
467
- stop();
468
- // A request this home cannot read — often an app newer than the home —
469
- // is answered, not ignored: otherwise both sides wait with nothing said.
470
- if (!isRequest(data.request, event.origin)) {
471
- opener.postMessage({
472
- type: DENIED,
473
- reason: 'Your account home did not understand what was asked. It may be older than this app — update it, or use another home.',
474
- }, event.origin);
475
- globalThis.setTimeout(() => globalThis.close(), 100);
476
- resolve(null);
477
- return;
478
- }
479
- const origin = event.origin;
480
- const reply = (message, closeAfter) => {
481
- opener.postMessage(message, origin);
482
- // A moment's grace, so the answer is delivered before the window goes.
483
- const close = () => void globalThis.setTimeout(() => globalThis.close(), 100);
484
- void (closeAfter ?? Promise.resolve()).then(close, close);
485
- };
486
- resolve({
487
- request: data.request,
488
- origin,
489
- approve: (answer, closeAfter) => reply({ type: GRANT, grant: answer }, closeAfter),
490
- deny: (reason) => reply({ type: DENIED, reason: reason ?? 'Access was not given.' }),
491
- });
492
- };
493
- const timer = globalThis.setTimeout(() => {
494
- stop();
495
- resolve(null);
496
- }, timeoutMs);
497
- const watch = globalThis.setInterval(() => {
498
- if (!opener.closed)
499
- return;
500
- stop();
501
- resolve(null);
502
- }, 500);
503
- globalThis.addEventListener('message', onMessage);
504
- // Nothing secret in a hello, so any origin may hear it; the request that
505
- // answers it is what names the app. Said once: a page that takes over the
506
- // app's tab later is not told where this home is.
507
- opener.postMessage({ type: HELLO }, '*');
508
- });
509
- }
510
- /** Every field a request may carry; one with any other is refused, not read in part */
511
- const REQUEST_FIELDS = new Set([
512
- 'v',
513
- 'audience',
514
- 'proof',
515
- 'name',
516
- 'access',
517
- 'scope',
518
- 'create',
519
- 'contacts',
520
- 'chooseSpaces',
521
- 'recordsOnly',
522
- 'via',
523
- 'days',
524
- ]);
525
- const PROPOSE_FIELDS = new Set(['v', 'kind', 'name', 'automations']);
526
- const onlyFields = (value, fields) => Object.keys(value).every((field) => fields.has(field));
527
- function isRequest(value, origin) {
528
- if (!isObject(value))
529
- return false;
530
- const proposal = value;
531
- if (proposal.kind !== undefined) {
532
- return (onlyFields(proposal, PROPOSE_FIELDS) &&
533
- proposal.v === 2 &&
534
- proposal.kind === 'propose' &&
535
- (proposal.name === undefined || (typeof proposal.name === 'string' && proposal.name.length <= 80)) &&
536
- Array.isArray(proposal.automations) &&
537
- proposal.automations.length > 0 &&
538
- isProposals(proposal.automations, origin));
539
- }
540
- const request = value;
541
- return (onlyFields(request, REQUEST_FIELDS) &&
542
- request.v === 1 &&
543
- typeof request.audience === 'string' &&
544
- request.audience.startsWith('did:key:') &&
545
- typeof request.proof === 'string' &&
546
- request.proof.length <= 200 &&
547
- (request.access === 'read' || request.access === 'write' || request.access === 'carry') &&
548
- (request.scope === undefined || request.scope === 'spaces' || request.scope === 'account') &&
549
- (request.name === undefined || (typeof request.name === 'string' && request.name.length <= 80)) &&
550
- (request.contacts === undefined || typeof request.contacts === 'boolean') &&
551
- (request.chooseSpaces === undefined || typeof request.chooseSpaces === 'boolean') &&
552
- (request.create === undefined || isNewSpaces(request.create)) &&
553
- (request.days === undefined ||
554
- (typeof request.days === 'number' &&
555
- Number.isInteger(request.days) &&
556
- request.days >= 1 &&
557
- request.days <= MAX_GRANT_DAYS)) &&
558
- // A program's key comes to the home over a code (`connect-code.ts`), never from an app.
559
- request.via === undefined &&
560
- // Records only: in spaces that exist, none made for it, no contacts and no carrying.
561
- (request.recordsOnly === undefined ||
562
- request.recordsOnly === false ||
563
- (request.recordsOnly === true &&
564
- request.access !== 'carry' &&
565
- request.create === undefined &&
566
- !request.contacts)));
567
- }
568
- /** Automations an app proposes: few, each one it could offer, each click leading back to it */
569
- function isProposals(value, origin) {
570
- return (Array.isArray(value) &&
571
- value.length <= MAX_PROPOSALS &&
572
- value.every((proposal) => checkProposal(proposal, origin) === null));
573
- }
574
- /** At most this many spaces made for an app in one go */
575
- const MAX_CREATE = 8;
576
- /** Spaces an app asks to have made: few, named, with a visibility — the roles are checked when they are made */
577
- function isNewSpaces(value) {
578
- return (Array.isArray(value) &&
579
- value.length <= MAX_CREATE &&
580
- value.every((space) => !!space &&
581
- typeof space.name === 'string' &&
582
- space.name.trim().length > 0 &&
583
- space.name.length <= 80 &&
584
- (space.visibility === 'private' || space.visibility === 'public') &&
585
- (space.roles === undefined || checkFoundingRoles(space.roles) === null)));
586
- }
587
- //# sourceMappingURL=connect.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"connect.js","sourceRoot":"","sources":["../../src/session/connect.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACpF,OAAO,EAAE,UAAU,EAAmB,MAAM,qBAAqB,CAAC;AAClE,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,SAAS,EACT,YAAY,EACZ,eAAe,GAEhB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,aAAa,EAAmB,MAAM,mBAAmB,CAAC;AAInE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,aAAa,EAA2B,MAAM,6BAA6B,CAAC;AACpG,OAAO,EAAE,cAAc,EAAE,cAAc,EAAsB,MAAM,qBAAqB,CAAC;AACzF,OAAO,EAAE,QAAQ,EAAE,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