@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,234 +0,0 @@
1
- /**
2
- * @module account-store
3
- * The accounts that live somewhere — in a folder, or in this browser.
4
- *
5
- * A folder is a disk, not a person. Several people can keep accounts in one, and
6
- * one person can keep several: work and personal, or a spare for testing. So the
7
- * folder holds a list of who has an account in it, and a subtree per account.
8
- *
9
- * ```
10
- * <folder>/
11
- * accounts.json name, DID and id of each account
12
- * accounts/<id>/account.json that account's keys, locked
13
- * accounts/<id>/stores/... that account's spaces
14
- * ```
15
- *
16
- * **The list is readable without unlocking anything**, which it has to be — you
17
- * cannot offer someone a choice of accounts without knowing their names. So
18
- * whoever holds the folder can see how many accounts are in it and what they
19
- * are called. What they cannot do is open one.
20
- *
21
- * A browser with no folder keeps the same shape in IndexedDB, so the app above
22
- * has one model rather than two.
23
- */
24
- import { readFolderFile, writeFolderFile } from '../storage/folder-adapter.js';
25
- import { isAccountVault } from './account-vault.js';
26
- import { base64UrlEncode, utf8Encode, utf8Decode } from '../utils/encoding.js';
27
- import { protocolError } from '../utils/errors.js';
28
- import { isRecord } from '../utils/guards.js';
29
- import { idbRun, openDb } from './idb.js';
30
- const LIST_FILE = 'accounts.json';
31
- const ACCOUNTS_DIR = 'accounts';
32
- const VAULT_FILE = 'account.json';
33
- /** Where a brand new account keeps its spaces. */
34
- export function accountDataPath(id) {
35
- return `${ACCOUNTS_DIR}/${id}/stores`;
36
- }
37
- /** A short, stable, filename-safe id for a new account. */
38
- export function newAccountId() {
39
- return base64UrlEncode(globalThis.crypto.getRandomValues(new Uint8Array(8)))
40
- .replace(/[^a-z0-9]/gi, '')
41
- .toLowerCase()
42
- .slice(0, 12);
43
- }
44
- /**
45
- * Whether an id has the shape {@link newAccountId} gives one.
46
- *
47
- * An id names a directory, and `remove` deletes that directory with everything
48
- * in it. The list it comes from is a plain file in a folder that may be synced
49
- * or shared, so an id is checked before it is trusted with a path.
50
- */
51
- export function isAccountId(id) {
52
- return typeof id === 'string' && /^[a-z0-9]{1,12}$/.test(id);
53
- }
54
- /**
55
- * Whether a row points somewhere this store could have put it.
56
- *
57
- * `dataPath` is carried, not computed, but there is only one shape it can
58
- * honestly have: an account subtree. Usually the subtree is the row's own —
59
- * though a row filed again under a fresh id keeps the one its data already
60
- * lives in. Anything else, `../../elsewhere` above all, is someone editing the
61
- * list to aim an account at files outside the folder.
62
- */
63
- function isTrustworthy(account) {
64
- if (!isRecord(account) || !isAccountId(account.id) || typeof account.dataPath !== 'string')
65
- return false;
66
- const [accounts, id, stores, ...more] = account.dataPath.split('/');
67
- return accounts === ACCOUNTS_DIR && isAccountId(id) && stores === 'stores' && more.length === 0;
68
- }
69
- /** A row read back from the list; the fields beyond id and path are taken as written. */
70
- function isTrustworthyRow(row) {
71
- return isTrustworthy(row);
72
- }
73
- function checkId(id) {
74
- if (!isAccountId(id))
75
- throw new TypeError(`Not an account id: ${JSON.stringify(id)}`);
76
- }
77
- /** Most recently used first, so the picker opens on the likely one. */
78
- function byRecency(a, b) {
79
- return (b.lastUsedAt ?? b.createdAt).localeCompare(a.lastUsedAt ?? a.createdAt);
80
- }
81
- /**
82
- * Most recently used first, one row per identity.
83
- *
84
- * A summary is a label on an identity, so two of them for one DID means the
85
- * same person listed twice — which is confusing at best and, once they point
86
- * at different data paths, a way to lose track of where anything is.
87
- */
88
- function collapse(accounts) {
89
- const seen = new Set();
90
- return [...accounts].sort(byRecency).filter((account) => {
91
- if (seen.has(account.did))
92
- return false;
93
- seen.add(account.did);
94
- return true;
95
- });
96
- }
97
- function parseList(bytes) {
98
- if (!bytes)
99
- return [];
100
- try {
101
- const parsed = JSON.parse(utf8Decode(bytes));
102
- // A row that fails the check is skipped, not repaired: it was not written
103
- // by this store, so there is no telling what it was meant to be.
104
- return isRecord(parsed) && Array.isArray(parsed.accounts) ? parsed.accounts.filter(isTrustworthyRow) : [];
105
- }
106
- catch {
107
- throw protocolError('FOLDER_ACCOUNT_UNREADABLE', `${LIST_FILE} in that folder is not valid JSON.`, 'Move it aside and sign in with your code to write a fresh one — no account ' +
108
- 'data is lost, only the list of which accounts exist.');
109
- }
110
- }
111
- /** Opens the accounts kept in a folder. */
112
- export function createFolderAccountStore(dir) {
113
- async function readList() {
114
- return parseList(await readFolderFile(dir, LIST_FILE));
115
- }
116
- async function writeList(accounts) {
117
- await writeFolderFile(dir, LIST_FILE, utf8Encode(`${JSON.stringify({ version: 1, accounts }, null, 2)}\n`));
118
- }
119
- /** The directory holding one account's keys. */
120
- async function accountDir(id, create) {
121
- try {
122
- const accounts = await dir.getDirectoryHandle(ACCOUNTS_DIR, { create });
123
- return await accounts.getDirectoryHandle(id, { create });
124
- }
125
- catch (error) {
126
- if (error instanceof Error && error.name === 'NotFoundError')
127
- return null;
128
- throw error;
129
- }
130
- }
131
- return Object.freeze({
132
- kind: 'folder',
133
- async list() {
134
- return collapse(await readList());
135
- },
136
- async read(id) {
137
- if (!isAccountId(id))
138
- return null;
139
- const home = await accountDir(id, false);
140
- if (!home)
141
- return null;
142
- const bytes = await readFolderFile(home, VAULT_FILE);
143
- if (!bytes)
144
- return null;
145
- try {
146
- const vault = JSON.parse(utf8Decode(bytes));
147
- if (!isAccountVault(vault))
148
- throw new Error('not a vault');
149
- return vault;
150
- }
151
- catch {
152
- throw protocolError('FOLDER_ACCOUNT_UNREADABLE', `The keys for that account could not be read.`, 'The file may have been edited by hand. Sign in with your code to write a new one.');
153
- }
154
- },
155
- async write(summary, vault) {
156
- if (!isTrustworthy(summary)) {
157
- throw new TypeError(`Account ${JSON.stringify(summary.id)} does not have a valid id and data path`);
158
- }
159
- const home = await accountDir(summary.id, true);
160
- // Only the folder itself being gone makes creating inside it fail this way.
161
- if (!home)
162
- throw protocolError('FOLDER_GONE', 'Your pod folder could not be found.', 'It may have been moved, renamed or deleted. Choose it again, or keep this account in the browser instead.');
163
- await writeFolderFile(home, VAULT_FILE, utf8Encode(`${JSON.stringify(vault, null, 2)}\n`));
164
- // Drops any row for the same identity as well as the same id: the caller
165
- // has just said which account this is.
166
- const accounts = (await readList()).filter((account) => account.id !== summary.id && account.did !== summary.did);
167
- await writeList([...accounts, summary]);
168
- },
169
- async remove(id) {
170
- checkId(id);
171
- await writeList((await readList()).filter((account) => account.id !== id));
172
- try {
173
- const accounts = await dir.getDirectoryHandle(ACCOUNTS_DIR);
174
- await accounts.removeEntry(id, { recursive: true });
175
- }
176
- catch (error) {
177
- // Already gone, or the browser will not recurse. The list no longer
178
- // mentions it either way.
179
- if (!(error instanceof Error) || error.name !== 'NotFoundError')
180
- throw error;
181
- }
182
- },
183
- });
184
- }
185
- // ─── Accounts kept in this browser ─────────────────────────────────────
186
- const DB_NAME = 'minca-accounts';
187
- const STORE = 'accounts';
188
- const LIST_KEY = '__list';
189
- function idbGet(db, key) {
190
- return idbRun(db, STORE, 'readonly', (store) => store.get(key));
191
- }
192
- /** The list as this store wrote it; unlike a folder's, no other origin can edit it */
193
- async function idbList(db) {
194
- const rows = await idbGet(db, LIST_KEY);
195
- return isSummaryList(rows) ? rows : [];
196
- }
197
- function isSummaryList(rows) {
198
- return Array.isArray(rows);
199
- }
200
- async function idbPut(db, key, value) {
201
- await idbRun(db, STORE, 'readwrite', (store) => store.put(value, key));
202
- }
203
- /**
204
- * Opens the accounts kept in this browser, for when there is no folder.
205
- *
206
- * Same shape as a folder store, so nothing above has to know which it got —
207
- * the difference is only that no other origin can read this one.
208
- *
209
- * @param dbName Overridable for tests
210
- */
211
- export async function createBrowserAccountStore(dbName = DB_NAME) {
212
- const db = await openDb(dbName, STORE);
213
- return Object.freeze({
214
- kind: 'browser',
215
- async list() {
216
- return collapse(await idbList(db));
217
- },
218
- async read(id) {
219
- const vault = await idbGet(db, id);
220
- return isAccountVault(vault) ? vault : null;
221
- },
222
- async write(summary, vault) {
223
- await idbPut(db, summary.id, vault);
224
- const accounts = (await idbList(db)).filter((account) => account.id !== summary.id && account.did !== summary.did);
225
- await idbPut(db, LIST_KEY, [...accounts, summary]);
226
- },
227
- async remove(id) {
228
- await idbRun(db, STORE, 'readwrite', (store) => store.delete(id));
229
- const accounts = (await idbList(db)).filter((account) => account.id !== id);
230
- await idbPut(db, LIST_KEY, accounts);
231
- },
232
- });
233
- }
234
- //# sourceMappingURL=account-store.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"account-store.js","sourceRoot":"","sources":["../../src/identity/account-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAGH,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/E,OAAO,EAAE,cAAc,EAAqB,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAC/E,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAsC1C,MAAM,SAAS,GAAG,eAAe,CAAC;AAClC,MAAM,YAAY,GAAG,UAAU,CAAC;AAChC,MAAM,UAAU,GAAG,cAAc,CAAC;AAElC,kDAAkD;AAClD,MAAM,UAAU,eAAe,CAAC,EAAU;IACxC,OAAO,GAAG,YAAY,IAAI,EAAE,SAAS,CAAC;AACxC,CAAC;AAED,2DAA2D;AAC3D,MAAM,UAAU,YAAY;IAC1B,OAAO,eAAe,CAAC,UAAU,CAAC,MAAM,CAAC,eAAe,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;SACzE,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC;SAC1B,WAAW,EAAE;SACb,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAClB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UA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AAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;YAC5E,MAAM,MAAM,CAAC,EAAE,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;QACvC,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
@@ -1,26 +0,0 @@
1
- /**
2
- * @module device-key
3
- * The key that unlocks an account on one device: random, non-extractable, in
4
- * this origin's storage, with a passkey as the gate in front of it (many
5
- * passkey providers lack PRF, so the passkey is not the source of the secret).
6
- * The gate is this code, not cryptography; what it protects against is
7
- * someone holding a copy of the folder without this storage.
8
- */
9
- /** A local key, and the id a wrap records to find it again. */
10
- export interface DeviceKey {
11
- readonly id: string;
12
- readonly key: CryptoKey;
13
- }
14
- /**
15
- * Makes a key for this device and remembers it. Non-extractable on purpose:
16
- * a CryptoKey survives IndexedDB, and no code path can turn it back into bytes.
17
- */
18
- export declare function createDeviceKey(dbName?: string): Promise<DeviceKey>;
19
- /**
20
- * Finds a device key by id. Absent is a normal answer: the wrap was made in
21
- * another browser, or storage has been cleared since.
22
- */
23
- export declare function getDeviceKey(id: string, dbName?: string): Promise<CryptoKey | null>;
24
- /** Forgets a device key, which makes its wrap permanently unopenable */
25
- export declare function deleteDeviceKey(id: string, dbName?: string): Promise<void>;
26
- //# sourceMappingURL=device-key.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"device-key.d.ts","sourceRoot":"","sources":["../../src/identity/device-key.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAQH,+DAA+D;AAC/D,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC;CACzB;AAED;;;GAGG;AACH,wBAAsB,eAAe,CAAC,MAAM,SAAU,GAAG,OAAO,CAAC,SAAS,CAAC,CAQ1E;AAED;;;GAGG;AACH,wBAAsB,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,SAAU,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,CAO1F;AAED,wEAAwE;AACxE,wBAAsB,eAAe,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,SAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAMjF"}
@@ -1,48 +0,0 @@
1
- /**
2
- * @module device-key
3
- * The key that unlocks an account on one device: random, non-extractable, in
4
- * this origin's storage, with a passkey as the gate in front of it (many
5
- * passkey providers lack PRF, so the passkey is not the source of the secret).
6
- * The gate is this code, not cryptography; what it protects against is
7
- * someone holding a copy of the folder without this storage.
8
- */
9
- import { base64UrlEncode } from '../utils/encoding.js';
10
- import { idbOnce } from './idb.js';
11
- const DB_NAME = 'minca-device-keys';
12
- const STORE = 'keys';
13
- /**
14
- * Makes a key for this device and remembers it. Non-extractable on purpose:
15
- * a CryptoKey survives IndexedDB, and no code path can turn it back into bytes.
16
- */
17
- export async function createDeviceKey(dbName = DB_NAME) {
18
- const key = await globalThis.crypto.subtle.generateKey({ name: 'AES-GCM', length: 256 }, false, [
19
- 'encrypt',
20
- 'decrypt',
21
- ]);
22
- const id = base64UrlEncode(globalThis.crypto.getRandomValues(new Uint8Array(12)));
23
- await idbOnce(dbName, STORE, 'readwrite', (store) => store.put(key, id));
24
- return { id, key };
25
- }
26
- /**
27
- * Finds a device key by id. Absent is a normal answer: the wrap was made in
28
- * another browser, or storage has been cleared since.
29
- */
30
- export async function getDeviceKey(id, dbName = DB_NAME) {
31
- try {
32
- const key = await idbOnce(dbName, STORE, 'readonly', (store) => store.get(id));
33
- return key instanceof CryptoKey ? key : null;
34
- }
35
- catch {
36
- return null;
37
- }
38
- }
39
- /** Forgets a device key, which makes its wrap permanently unopenable */
40
- export async function deleteDeviceKey(id, dbName = DB_NAME) {
41
- try {
42
- await idbOnce(dbName, STORE, 'readwrite', (store) => store.delete(id));
43
- }
44
- catch {
45
- // Already gone.
46
- }
47
- }
48
- //# sourceMappingURL=device-key.js.map
@@ -1 +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AAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,wEAAwE;AACxE,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,EAAU,EAAE,MAAM,GAAG,OAAO;IAChE,IAAI,CAAC;QACH,MAAM,OAAO,CAAC,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;IACzE,CAAC;IAAC,MAAM,CAAC;QACP,gBAAgB;IAClB,CAAC;AACH,CAAC"}
@@ -1,19 +0,0 @@
1
- /**
2
- * @module identity/idb
3
- * The little of IndexedDB the small browser stores need: one object store per
4
- * database, and requests as promises.
5
- */
6
- /** Opens a database, creating its one object store the first time */
7
- export declare function openDb(dbName: string, storeName: string): Promise<IDBDatabase>;
8
- /** What a request gives back */
9
- export declare function requestResult<T>(request: IDBRequest<T>): Promise<T>;
10
- /** Settles when a transaction commits */
11
- export declare function transactionDone(tx: IDBTransaction): Promise<void>;
12
- /**
13
- * One request against an open database's store. Whatever this origin stored
14
- * comes back unchecked, so the caller checks it; a write settles once committed.
15
- */
16
- export declare function idbRun(db: IDBDatabase, storeName: string, mode: IDBTransactionMode, run: (store: IDBObjectStore) => IDBRequest): Promise<unknown>;
17
- /** `idbRun`, opening the database around it */
18
- export declare function idbOnce(dbName: string, storeName: string, mode: IDBTransactionMode, run: (store: IDBObjectStore) => IDBRequest): Promise<unknown>;
19
- //# sourceMappingURL=idb.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"idb.d.ts","sourceRoot":"","sources":["../../src/identity/idb.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,qEAAqE;AACrE,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAW9E;AAED,gCAAgC;AAChC,wBAAgB,aAAa,CAAC,CAAC,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAKnE;AAED,yCAAyC;AACzC,wBAAgB,eAAe,CAAC,EAAE,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAMjE;AAED;;;GAGG;AACH,wBAAsB,MAAM,CAC1B,EAAE,EAAE,WAAW,EACf,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,kBAAkB,EACxB,GAAG,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,UAAU,GACzC,OAAO,CAAC,OAAO,CAAC,CAOlB;AAED,+CAA+C;AAC/C,wBAAsB,OAAO,CAC3B,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,kBAAkB,EACxB,GAAG,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,UAAU,GACzC,OAAO,CAAC,OAAO,CAAC,CAOlB"}
@@ -1,56 +0,0 @@
1
- /**
2
- * @module identity/idb
3
- * The little of IndexedDB the small browser stores need: one object store per
4
- * database, and requests as promises.
5
- */
6
- /** Opens a database, creating its one object store the first time */
7
- export function openDb(dbName, storeName) {
8
- return new Promise((resolve, reject) => {
9
- const request = globalThis.indexedDB.open(dbName, 1);
10
- request.onupgradeneeded = () => {
11
- if (!request.result.objectStoreNames.contains(storeName)) {
12
- request.result.createObjectStore(storeName);
13
- }
14
- };
15
- request.onsuccess = () => resolve(request.result);
16
- request.onerror = () => reject(request.error ?? new Error(`Could not open ${dbName}`));
17
- });
18
- }
19
- /** What a request gives back */
20
- export function requestResult(request) {
21
- return new Promise((resolve, reject) => {
22
- request.onsuccess = () => resolve(request.result);
23
- request.onerror = () => reject(request.error ?? new Error('IndexedDB request failed'));
24
- });
25
- }
26
- /** Settles when a transaction commits */
27
- export function transactionDone(tx) {
28
- return new Promise((resolve, reject) => {
29
- tx.oncomplete = () => resolve();
30
- tx.onerror = () => reject(tx.error ?? new Error('IndexedDB transaction failed'));
31
- tx.onabort = () => reject(tx.error ?? new Error('Transaction aborted'));
32
- });
33
- }
34
- /**
35
- * One request against an open database's store. Whatever this origin stored
36
- * comes back unchecked, so the caller checks it; a write settles once committed.
37
- */
38
- export async function idbRun(db, storeName, mode, run) {
39
- const tx = db.transaction(storeName, mode);
40
- const [value] = await Promise.all([
41
- requestResult(run(tx.objectStore(storeName))),
42
- mode === 'readwrite' ? transactionDone(tx) : undefined,
43
- ]);
44
- return value;
45
- }
46
- /** `idbRun`, opening the database around it */
47
- export async function idbOnce(dbName, storeName, mode, run) {
48
- const db = await openDb(dbName, storeName);
49
- try {
50
- return await idbRun(db, storeName, mode, run);
51
- }
52
- finally {
53
- db.close();
54
- }
55
- }
56
- //# sourceMappingURL=idb.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"idb.js","sourceRoot":"","sources":["../../src/identity/idb.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,qEAAqE;AACrE,MAAM,UAAU,MAAM,CAAC,MAAc,EAAE,SAAiB;IACtD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,OAAO,GAAG,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QACrD,OAAO,CAAC,eAAe,GAAG,GAAG,EAAE;YAC7B,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;gBACzD,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC;YAC9C,CAAC;QACH,CAAC,CAAC;QACF,OAAO,CAAC,SAAS,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAClD,OAAO,CAAC,OAAO,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,IAAI,IAAI,KAAK,CAAC,kBAAkB,MAAM,EAAE,CAAC,CAAC,CAAC;IACzF,CA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AC,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS;KACvD,CAAC,CAAC;IACH,OAAO,KAAK,CAAC;AACf,CAAC;AAED,+CAA+C;AAC/C,MAAM,CAAC,KAAK,UAAU,OAAO,CAC3B,MAAc,EACd,SAAiB,EACjB,IAAwB,EACxB,GAA0C;IAE1C,MAAM,EAAE,GAAG,MAAM,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAC3C,IAAI,CAAC;QACH,OAAO,MAAM,MAAM,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;IAChD,CAAC;YAAS,CAAC;QACT,EAAE,CAAC,KAAK,EAAE,CAAC;IACb,CAAC;AACH,CAAC"}
@@ -1,91 +0,0 @@
1
- /**
2
- * @module node/worker
3
- * A browser node in a worker, off the page's main thread, so checking
4
- * signatures, decrypting and syncing never make the page stutter.
5
- *
6
- * The page calls {@link startNodeInWorker} and gets a node with the usual API.
7
- * The worker runs {@link runNodeWorker} (the `@minca/core/node-worker`
8
- * entry does it) and holds the node itself. Two things stay on the page: the
9
- * root signer, since a passkey needs a document and a key in a tab should stay
10
- * there, and WebRTC, since not every browser has it in workers. The worker
11
- * reaches both by message.
12
- *
13
- * In a `SharedWorker`, the tabs that open the same account's stores with the
14
- * same key share one node: one copy in memory, one set of connections. Each
15
- * tab brings its signer and its WebRTC; the node uses the WebRTC of the tab
16
- * open longest. It closes when the last tab leaves. A tab that goes without
17
- * saying so is noticed by a Web Lock it holds while open.
18
- *
19
- * No `CryptoKey` is ever sent to the worker: WebKit drops, without an error,
20
- * a message to a shared worker that holds one, and can't read one back from
21
- * IndexedDB there either. A session key reaches the worker as the seed it is
22
- * derived from (`sessionKeySeed`), and the worker signs with it itself.
23
- */
24
- import type { RootSigner } from '../identity/root-signer.js';
25
- import { type StoreFactory, type WorkerStores } from './stores.js';
26
- import type { NodeConfig, NodeNetworkConfig, P2PNode } from './types.js';
27
- /**
28
- * What a worker needs to start a node: `NodeConfig`, less what can't be sent
29
- * to it. The signer stays on the page, and the stores are described.
30
- */
31
- export interface WorkerNodeConfig extends Pick<NodeConfig, 'accountKey' | 'contactKey' | 'contactsSpace' | 'sessionTtlSeconds' | 'cache'> {
32
- readonly stores: WorkerStores;
33
- /** What the key to sign with is derived from, when the signer already named it (`NodeConfig.sessionKey`) */
34
- readonly sessionKeySeed?: Uint8Array;
35
- readonly network?: Pick<NodeNetworkConfig, 'relays' | 'nodes' | 'hosts' | 'iceServers'>;
36
- }
37
- /** What the page starts a node with: the signer stays on the page */
38
- export type PageNodeConfig = WorkerNodeConfig & {
39
- readonly signer: RootSigner;
40
- };
41
- /** What of a network config reaches the worker: plain data, never transports */
42
- export declare function workerNetwork(network: NodeNetworkConfig): NonNullable<WorkerNodeConfig['network']>;
43
- /** A `Worker`, a `SharedWorker`'s port, or a port to either */
44
- export interface WorkerLike {
45
- postMessage(message: unknown, transfer: Transferable[]): void;
46
- /** A dedicated worker ends with the node it holds */
47
- terminate?(): void;
48
- /** Where a worker that fails to load says so (a `Worker`, or a `SharedWorker` beside its port) */
49
- addEventListener?(type: 'error', listener: () => void): void;
50
- }
51
- /** The name of the error when a worker never said the node started: it failed to load, or took too long */
52
- export declare const WORKER_NOT_STARTED = "WorkerNotStarted";
53
- /**
54
- * Starts a node in `worker`, or joins the one it already runs for the same
55
- * account and stores (a `SharedWorker`), and returns it, used from here.
56
- * Closing it lets go of it from this tab: the signer and connections kept
57
- * here stop, a dedicated worker ends, and a shared node closes once no tab
58
- * uses it.
59
- *
60
- * @param worker Running `runNodeWorker`, as `@minca/core/node-worker` does
61
- * @param config.signer Who the node acts for; its key stays on this side
62
- * @param startTimeoutMs How long to wait for the worker to say the node started. Default 30 s.
63
- * @throws When the worker could not start the node, with its reason, or said nothing in time
64
- */
65
- export declare function startNodeInWorker(worker: WorkerLike, config: PageNodeConfig, startTimeoutMs?: number): Promise<P2PNode>;
66
- /**
67
- * Starts a page's node: in `worker` when one is given, or here. The stores
68
- * are described so a worker can open them; `stores` replaces them here only.
69
- */
70
- export declare function startPageNode(config: Omit<PageNodeConfig, 'network'> & {
71
- readonly network?: NodeNetworkConfig;
72
- }, options?: {
73
- readonly worker?: () => WorkerLike;
74
- readonly stores?: StoreFactory;
75
- }): Promise<P2PNode>;
76
- /** What `runNodeWorker` listens on: a dedicated worker's scope, or a shared worker's */
77
- interface WorkerScope {
78
- addEventListener(type: 'message' | 'connect', listener: (event: MessageEvent) => void): void;
79
- }
80
- /**
81
- * In a worker: starts a node when a page asks (`startNodeInWorker`), or lets
82
- * the page share the one already running for the same account and stores,
83
- * and serves it until the last page using it lets go. In a `SharedWorker`
84
- * each page arrives by `connect`.
85
- */
86
- export declare function runNodeWorker(scope?: WorkerScope, options?: {
87
- /** Opens the stores the page described. Default `workerStores`; a test hands out memory ones. */
88
- readonly openStores?: (stores: WorkerStores) => StoreFactory;
89
- }): void;
90
- export {};
91
- //# sourceMappingURL=worker.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../../src/node/worker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAQ7D,OAAO,EAA+B,KAAK,YAAY,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAChG,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAGzE;;;GAGG;AACH,MAAM,WAAW,gBAAiB,SAAQ,IAAI,CAC5C,UAAU,EACV,YAAY,GAAG,YAAY,GAAG,eAAe,GAAG,mBAAmB,GAAG,OAAO,CAC9E;IACC,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,4GAA4G;IAC5G,QAAQ,CAAC,cAAc,CAAC,EAAE,UAAU,CAAC;IACrC,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,CA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