@minca/core 0.2.0 → 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.
- package/README.md +2 -2
- package/dist/{session → hosting}/hosting.d.ts +2 -8
- package/dist/hosting/hosting.d.ts.map +1 -0
- package/dist/{session → hosting}/hosting.js +3 -3
- package/dist/hosting/hosting.js.map +1 -0
- package/dist/identity/abilities.d.ts +0 -2
- package/dist/identity/abilities.d.ts.map +1 -1
- package/dist/identity/abilities.js +2 -2
- package/dist/identity/abilities.js.map +1 -1
- package/dist/identity/account-vault.d.ts +0 -2
- package/dist/identity/account-vault.d.ts.map +1 -1
- package/dist/identity/account-vault.js +1 -1
- package/dist/identity/account-vault.js.map +1 -1
- package/dist/identity/crypto-p256.d.ts +1 -1
- package/dist/identity/crypto-p256.d.ts.map +1 -1
- package/dist/identity/ucan.d.ts +2 -1
- package/dist/identity/ucan.d.ts.map +1 -1
- package/dist/identity/ucan.js +1 -1
- package/dist/identity/ucan.js.map +1 -1
- package/dist/inbox/inbox.d.ts +0 -21
- package/dist/inbox/inbox.d.ts.map +1 -1
- package/dist/inbox/inbox.js +4 -4
- package/dist/inbox/inbox.js.map +1 -1
- package/dist/inbox/index.d.ts +4 -5
- package/dist/inbox/index.d.ts.map +1 -1
- package/dist/inbox/index.js +2 -3
- package/dist/inbox/index.js.map +1 -1
- package/dist/inbox/names.d.ts +0 -4
- package/dist/inbox/names.d.ts.map +1 -1
- package/dist/inbox/names.js +2 -2
- package/dist/inbox/names.js.map +1 -1
- package/dist/index.d.ts +50 -84
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +38 -60
- package/dist/index.js.map +1 -1
- package/dist/network/mesh.d.ts.map +1 -1
- package/dist/network/mesh.js +23 -3
- package/dist/network/mesh.js.map +1 -1
- package/dist/network/network-manager.d.ts +5 -0
- package/dist/network/network-manager.d.ts.map +1 -1
- package/dist/network/network-manager.js +3 -0
- package/dist/network/network-manager.js.map +1 -1
- package/dist/network/peer-auth.d.ts +17 -5
- package/dist/network/peer-auth.d.ts.map +1 -1
- package/dist/network/peer-auth.js +19 -9
- package/dist/network/peer-auth.js.map +1 -1
- package/dist/network/rendezvous.d.ts +2 -0
- package/dist/network/rendezvous.d.ts.map +1 -1
- package/dist/network/rendezvous.js +5 -0
- package/dist/network/rendezvous.js.map +1 -1
- package/dist/network/rtc-transport.d.ts.map +1 -1
- package/dist/network/rtc-transport.js +9 -3
- package/dist/network/rtc-transport.js.map +1 -1
- package/dist/network/transport.d.ts +12 -0
- package/dist/network/transport.d.ts.map +1 -1
- package/dist/network/ws-transport.d.ts +1 -1
- package/dist/network/ws-transport.d.ts.map +1 -1
- package/dist/network/ws-transport.js +14 -4
- package/dist/network/ws-transport.js.map +1 -1
- package/dist/node/carrier.d.ts +1 -33
- package/dist/node/carrier.d.ts.map +1 -1
- package/dist/node/carrier.js +38 -68
- package/dist/node/carrier.js.map +1 -1
- package/dist/node/index.d.ts +5 -16
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +2 -9
- package/dist/node/index.js.map +1 -1
- package/dist/node/node-carriers.d.ts.map +1 -1
- package/dist/node/node-carriers.js +21 -52
- package/dist/node/node-carriers.js.map +1 -1
- package/dist/node/node-context.d.ts +0 -2
- package/dist/node/node-context.d.ts.map +1 -1
- package/dist/node/node-context.js.map +1 -1
- package/dist/node/node-hosting.d.ts.map +1 -1
- package/dist/node/node-hosting.js +14 -5
- package/dist/node/node-hosting.js.map +1 -1
- package/dist/node/node-records.js +2 -2
- package/dist/node/node-records.js.map +1 -1
- package/dist/node/node.d.ts.map +1 -1
- package/dist/node/node.js +152 -36
- package/dist/node/node.js.map +1 -1
- package/dist/node/space-checks.d.ts +3 -1
- package/dist/node/space-checks.d.ts.map +1 -1
- package/dist/node/space-checks.js +7 -3
- package/dist/node/space-checks.js.map +1 -1
- package/dist/node/space-holding.d.ts +5 -0
- package/dist/node/space-holding.d.ts.map +1 -1
- package/dist/node/space-holding.js +90 -5
- package/dist/node/space-holding.js.map +1 -1
- package/dist/node/space-lines.d.ts +3 -0
- package/dist/node/space-lines.d.ts.map +1 -1
- package/dist/node/space-lines.js +13 -1
- package/dist/node/space-lines.js.map +1 -1
- package/dist/node/space-membership.js +4 -4
- package/dist/node/space-membership.js.map +1 -1
- package/dist/node/space-mirrors.d.ts +1 -1
- package/dist/node/space-mirrors.d.ts.map +1 -1
- package/dist/node/space-mirrors.js +17 -5
- package/dist/node/space-mirrors.js.map +1 -1
- package/dist/node/space-peers.d.ts +7 -2
- package/dist/node/space-peers.d.ts.map +1 -1
- package/dist/node/space-peers.js +44 -10
- package/dist/node/space-peers.js.map +1 -1
- package/dist/node/space-runtime.d.ts +7 -3
- package/dist/node/space-runtime.d.ts.map +1 -1
- package/dist/node/space-runtime.js +32 -10
- package/dist/node/space-runtime.js.map +1 -1
- package/dist/node/space-standing.d.ts +1 -1
- package/dist/node/space-standing.d.ts.map +1 -1
- package/dist/node/space-standing.js +23 -42
- package/dist/node/space-standing.js.map +1 -1
- package/dist/node/space-warrants.js +1 -1
- package/dist/node/space-warrants.js.map +1 -1
- package/dist/node/space-writing.d.ts.map +1 -1
- package/dist/node/space-writing.js +21 -32
- package/dist/node/space-writing.js.map +1 -1
- package/dist/node/stores.d.ts +9 -57
- package/dist/node/stores.d.ts.map +1 -1
- package/dist/node/stores.js +1 -72
- package/dist/node/stores.js.map +1 -1
- package/dist/node/types.d.ts +19 -8
- package/dist/node/types.d.ts.map +1 -1
- package/dist/node/writer-keys.d.ts +15 -14
- package/dist/node/writer-keys.d.ts.map +1 -1
- package/dist/node/writer-keys.js +3 -115
- package/dist/node/writer-keys.js.map +1 -1
- package/dist/privacy/direct.d.ts +0 -7
- package/dist/privacy/direct.d.ts.map +1 -1
- package/dist/privacy/direct.js +2 -2
- package/dist/privacy/direct.js.map +1 -1
- package/dist/query/filter.d.ts +0 -2
- package/dist/query/filter.d.ts.map +1 -1
- package/dist/query/filter.js +1 -1
- package/dist/query/filter.js.map +1 -1
- package/dist/query/types.d.ts +2 -6
- package/dist/query/types.d.ts.map +1 -1
- package/dist/query/types.js.map +1 -1
- package/dist/records/key.d.ts +18 -19
- package/dist/records/key.d.ts.map +1 -1
- package/dist/records/key.js +55 -43
- package/dist/records/key.js.map +1 -1
- package/dist/records/links.js +1 -1
- package/dist/records/rules.d.ts +1 -1
- package/dist/records/rules.d.ts.map +1 -1
- package/dist/records/rules.js +6 -4
- package/dist/records/rules.js.map +1 -1
- package/dist/schemas/direct.d.ts +70 -0
- package/dist/schemas/direct.d.ts.map +1 -0
- package/dist/schemas/direct.js +39 -0
- package/dist/schemas/direct.js.map +1 -0
- package/dist/schemas/index.d.ts +10 -73
- package/dist/schemas/index.d.ts.map +1 -1
- package/dist/schemas/index.js +8 -66
- package/dist/schemas/index.js.map +1 -1
- package/dist/space/account-registry.d.ts +0 -3
- package/dist/space/account-registry.d.ts.map +1 -1
- package/dist/space/account-registry.js.map +1 -1
- package/dist/space/own-automations.d.ts +51 -95
- package/dist/space/own-automations.d.ts.map +1 -1
- package/dist/space/own-automations.js +100 -295
- package/dist/space/own-automations.js.map +1 -1
- package/dist/space/pass.d.ts +8 -3
- package/dist/space/pass.d.ts.map +1 -1
- package/dist/space/pass.js +4 -3
- package/dist/space/pass.js.map +1 -1
- package/dist/space/space-manager.d.ts +1 -3
- package/dist/space/space-manager.d.ts.map +1 -1
- package/dist/space/space-manager.js +5 -7
- package/dist/space/space-manager.js.map +1 -1
- package/dist/storage/body-cache.d.ts +29 -0
- package/dist/storage/body-cache.d.ts.map +1 -0
- package/dist/storage/body-cache.js +64 -0
- package/dist/storage/body-cache.js.map +1 -0
- package/dist/storage/encrypted-adapter.d.ts +0 -5
- package/dist/storage/encrypted-adapter.d.ts.map +1 -1
- package/dist/storage/encrypted-adapter.js +1 -1
- package/dist/storage/encrypted-adapter.js.map +1 -1
- package/dist/storage/mirror.d.ts.map +1 -1
- package/dist/storage/mirror.js +35 -16
- package/dist/storage/mirror.js.map +1 -1
- package/dist/storage/segment.d.ts +6 -2
- package/dist/storage/segment.d.ts.map +1 -1
- package/dist/storage/segment.js +8 -4
- package/dist/storage/segment.js.map +1 -1
- package/dist/storage/shared-store.d.ts +32 -0
- package/dist/storage/shared-store.d.ts.map +1 -0
- package/dist/storage/{folder-reconcile.js → shared-store.js} +15 -15
- package/dist/storage/shared-store.js.map +1 -0
- package/dist/storage/storage-provider.d.ts +19 -9
- package/dist/storage/storage-provider.d.ts.map +1 -1
- package/dist/storage/storage-provider.js +155 -62
- package/dist/storage/storage-provider.js.map +1 -1
- package/dist/sync/sync-engine.d.ts +17 -4
- package/dist/sync/sync-engine.d.ts.map +1 -1
- package/dist/sync/sync-engine.js +298 -84
- package/dist/sync/sync-engine.js.map +1 -1
- package/dist/sync/sync-messages.d.ts +5 -1
- package/dist/sync/sync-messages.d.ts.map +1 -1
- package/dist/sync/sync-messages.js +1 -1
- package/dist/sync/sync-messages.js.map +1 -1
- package/dist/types.d.ts +19 -7
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +4 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/index.d.ts +5 -5
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +5 -5
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/step.d.ts +8 -0
- package/dist/utils/step.d.ts.map +1 -0
- package/dist/utils/step.js +15 -0
- package/dist/utils/step.js.map +1 -0
- package/docs/README.md +4 -3
- package/docs/actions.md +41 -2
- package/docs/agents.md +13 -10
- package/docs/automations.md +16 -48
- package/docs/blueprints-and-guides.md +2 -2
- package/docs/bots.md +3 -3
- package/docs/building-an-app.md +2 -2
- package/docs/collections.md +2 -4
- package/docs/computed.md +1 -2
- package/docs/node.md +108 -40
- package/docs/proposing-collections.md +3 -3
- package/docs/query-format.md +6 -5
- package/docs/records-and-queries.md +12 -13
- package/docs/sign-in.md +16 -16
- package/docs/spaces.md +0 -5
- package/docs/standard-library.md +6 -8
- package/docs/storage.md +114 -22
- package/docs/usernames.md +1 -1
- package/package.json +15 -25
- package/dist/identity/account-store.d.ts +0 -83
- package/dist/identity/account-store.d.ts.map +0 -1
- package/dist/identity/account-store.js +0 -234
- package/dist/identity/account-store.js.map +0 -1
- package/dist/identity/device-key.d.ts +0 -26
- package/dist/identity/device-key.d.ts.map +0 -1
- package/dist/identity/device-key.js +0 -48
- package/dist/identity/device-key.js.map +0 -1
- package/dist/identity/idb.d.ts +0 -19
- package/dist/identity/idb.d.ts.map +0 -1
- package/dist/identity/idb.js +0 -56
- package/dist/identity/idb.js.map +0 -1
- package/dist/node/actions.d.ts +0 -85
- package/dist/node/actions.d.ts.map +0 -1
- package/dist/node/actions.js +0 -921
- package/dist/node/actions.js.map +0 -1
- package/dist/node/host.d.ts +0 -187
- package/dist/node/host.d.ts.map +0 -1
- package/dist/node/host.js +0 -818
- package/dist/node/host.js.map +0 -1
- package/dist/node/usage.d.ts +0 -32
- package/dist/node/usage.d.ts.map +0 -1
- package/dist/node/usage.js +0 -217
- package/dist/node/usage.js.map +0 -1
- package/dist/node/watch-notifications.d.ts +0 -25
- package/dist/node/watch-notifications.d.ts.map +0 -1
- package/dist/node/watch-notifications.js +0 -166
- package/dist/node/watch-notifications.js.map +0 -1
- package/dist/node/worker.d.ts +0 -83
- package/dist/node/worker.d.ts.map +0 -1
- package/dist/node/worker.js +0 -305
- package/dist/node/worker.js.map +0 -1
- package/dist/node-worker.d.ts +0 -2
- package/dist/node-worker.d.ts.map +0 -1
- package/dist/node-worker.js +0 -16
- package/dist/node-worker.js.map +0 -1
- package/dist/schemas/automations.d.ts +0 -390
- package/dist/schemas/automations.d.ts.map +0 -1
- package/dist/schemas/automations.js +0 -619
- package/dist/schemas/automations.js.map +0 -1
- package/dist/schemas/blueprints.d.ts +0 -122
- package/dist/schemas/blueprints.d.ts.map +0 -1
- package/dist/schemas/blueprints.js +0 -337
- package/dist/schemas/blueprints.js.map +0 -1
- package/dist/schemas/choosing.d.ts +0 -19
- package/dist/schemas/choosing.d.ts.map +0 -1
- package/dist/schemas/choosing.js +0 -69
- package/dist/schemas/choosing.js.map +0 -1
- package/dist/schemas/connectors.d.ts +0 -202
- package/dist/schemas/connectors.d.ts.map +0 -1
- package/dist/schemas/connectors.js +0 -140
- package/dist/schemas/connectors.js.map +0 -1
- package/dist/schemas/cron.d.ts +0 -14
- package/dist/schemas/cron.d.ts.map +0 -1
- package/dist/schemas/cron.js +0 -75
- package/dist/schemas/cron.js.map +0 -1
- package/dist/schemas/geo.d.ts +0 -63
- package/dist/schemas/geo.d.ts.map +0 -1
- package/dist/schemas/geo.js +0 -131
- package/dist/schemas/geo.js.map +0 -1
- package/dist/schemas/guides.d.ts +0 -26
- package/dist/schemas/guides.d.ts.map +0 -1
- package/dist/schemas/guides.js +0 -33
- package/dist/schemas/guides.js.map +0 -1
- package/dist/schemas/library/annotations.d.ts +0 -616
- package/dist/schemas/library/annotations.d.ts.map +0 -1
- package/dist/schemas/library/annotations.js +0 -156
- package/dist/schemas/library/annotations.js.map +0 -1
- package/dist/schemas/library/collections.d.ts +0 -211
- package/dist/schemas/library/collections.d.ts.map +0 -1
- package/dist/schemas/library/collections.js +0 -57
- package/dist/schemas/library/collections.js.map +0 -1
- package/dist/schemas/library/community.d.ts +0 -1136
- package/dist/schemas/library/community.d.ts.map +0 -1
- package/dist/schemas/library/community.js +0 -315
- package/dist/schemas/library/community.js.map +0 -1
- package/dist/schemas/library/life.d.ts +0 -1440
- package/dist/schemas/library/life.d.ts.map +0 -1
- package/dist/schemas/library/life.js +0 -202
- package/dist/schemas/library/life.js.map +0 -1
- package/dist/schemas/library/media.d.ts +0 -1002
- package/dist/schemas/library/media.d.ts.map +0 -1
- package/dist/schemas/library/media.js +0 -110
- package/dist/schemas/library/media.js.map +0 -1
- package/dist/schemas/library/money.d.ts +0 -1221
- package/dist/schemas/library/money.d.ts.map +0 -1
- package/dist/schemas/library/money.js +0 -168
- package/dist/schemas/library/money.js.map +0 -1
- package/dist/schemas/library/planning.d.ts +0 -1107
- package/dist/schemas/library/planning.d.ts.map +0 -1
- package/dist/schemas/library/planning.js +0 -214
- package/dist/schemas/library/planning.js.map +0 -1
- package/dist/schemas/library/publishing.d.ts +0 -1499
- package/dist/schemas/library/publishing.d.ts.map +0 -1
- package/dist/schemas/library/publishing.js +0 -285
- package/dist/schemas/library/publishing.js.map +0 -1
- package/dist/schemas/library/social.d.ts +0 -1257
- package/dist/schemas/library/social.d.ts.map +0 -1
- package/dist/schemas/library/social.js +0 -147
- package/dist/schemas/library/social.js.map +0 -1
- package/dist/schemas/standard.d.ts +0 -21
- package/dist/schemas/standard.d.ts.map +0 -1
- package/dist/schemas/standard.js +0 -39
- package/dist/schemas/standard.js.map +0 -1
- package/dist/session/account-hint.d.ts +0 -13
- package/dist/session/account-hint.d.ts.map +0 -1
- package/dist/session/account-hint.js +0 -54
- package/dist/session/account-hint.js.map +0 -1
- package/dist/session/auth.d.ts +0 -411
- package/dist/session/auth.d.ts.map +0 -1
- package/dist/session/auth.js +0 -1529
- package/dist/session/auth.js.map +0 -1
- package/dist/session/channel-room.d.ts +0 -26
- package/dist/session/channel-room.d.ts.map +0 -1
- package/dist/session/channel-room.js +0 -56
- package/dist/session/channel-room.js.map +0 -1
- package/dist/session/connect-code.d.ts +0 -127
- package/dist/session/connect-code.d.ts.map +0 -1
- package/dist/session/connect-code.js +0 -408
- package/dist/session/connect-code.js.map +0 -1
- package/dist/session/connect.d.ts +0 -386
- package/dist/session/connect.d.ts.map +0 -1
- package/dist/session/connect.js +0 -583
- package/dist/session/connect.js.map +0 -1
- package/dist/session/connection.d.ts +0 -135
- package/dist/session/connection.d.ts.map +0 -1
- package/dist/session/connection.js +0 -215
- package/dist/session/connection.js.map +0 -1
- package/dist/session/credentials.d.ts +0 -30
- package/dist/session/credentials.d.ts.map +0 -1
- package/dist/session/credentials.js +0 -63
- package/dist/session/credentials.js.map +0 -1
- package/dist/session/hosting.d.ts.map +0 -1
- package/dist/session/hosting.js.map +0 -1
- package/dist/session/index.d.ts +0 -29
- package/dist/session/index.d.ts.map +0 -1
- package/dist/session/index.js +0 -21
- package/dist/session/index.js.map +0 -1
- package/dist/session/pairing.d.ts +0 -97
- package/dist/session/pairing.d.ts.map +0 -1
- package/dist/session/pairing.js +0 -251
- package/dist/session/pairing.js.map +0 -1
- package/dist/session/password-strength.d.ts +0 -22
- package/dist/session/password-strength.d.ts.map +0 -1
- package/dist/session/password-strength.js +0 -130
- package/dist/session/password-strength.js.map +0 -1
- package/dist/session/places.d.ts +0 -71
- package/dist/session/places.d.ts.map +0 -1
- package/dist/session/places.js +0 -130
- package/dist/session/places.js.map +0 -1
- package/dist/session/popup.d.ts +0 -13
- package/dist/session/popup.d.ts.map +0 -1
- package/dist/session/popup.js +0 -23
- package/dist/session/popup.js.map +0 -1
- package/dist/session/stay-signed-in.d.ts +0 -49
- package/dist/session/stay-signed-in.d.ts.map +0 -1
- package/dist/session/stay-signed-in.js +0 -141
- package/dist/session/stay-signed-in.js.map +0 -1
- package/dist/storage/blob/directory.d.ts +0 -14
- package/dist/storage/blob/directory.d.ts.map +0 -1
- package/dist/storage/blob/directory.js +0 -87
- package/dist/storage/blob/directory.js.map +0 -1
- package/dist/storage/blob/memory.d.ts +0 -6
- package/dist/storage/blob/memory.d.ts.map +0 -1
- package/dist/storage/blob/memory.js +0 -20
- package/dist/storage/blob/memory.js.map +0 -1
- package/dist/storage/blob/s3.d.ts +0 -16
- package/dist/storage/blob/s3.d.ts.map +0 -1
- package/dist/storage/blob/s3.js +0 -91
- package/dist/storage/blob/s3.js.map +0 -1
- package/dist/storage/directory-access.d.ts +0 -36
- package/dist/storage/directory-access.d.ts.map +0 -1
- package/dist/storage/directory-access.js +0 -89
- package/dist/storage/directory-access.js.map +0 -1
- package/dist/storage/folder-adapter.d.ts +0 -94
- package/dist/storage/folder-adapter.d.ts.map +0 -1
- package/dist/storage/folder-adapter.js +0 -215
- package/dist/storage/folder-adapter.js.map +0 -1
- package/dist/storage/folder-reconcile.d.ts +0 -33
- package/dist/storage/folder-reconcile.d.ts.map +0 -1
- package/dist/storage/folder-reconcile.js.map +0 -1
- package/dist/storage/index.d.ts +0 -6
- package/dist/storage/index.d.ts.map +0 -1
- package/dist/storage/index.js +0 -5
- package/dist/storage/index.js.map +0 -1
- package/dist/storage/indexeddb-adapter.d.ts +0 -8
- package/dist/storage/indexeddb-adapter.d.ts.map +0 -1
- package/dist/storage/indexeddb-adapter.js +0 -103
- package/dist/storage/indexeddb-adapter.js.map +0 -1
package/docs/storage.md
CHANGED
|
@@ -188,7 +188,7 @@ compaction left.
|
|
|
188
188
|
`~/.local/state/minca`, then `<first 16 hex of SHA-256 of the home's
|
|
189
189
|
path>/<account id>/stores`. A
|
|
190
190
|
command and the daemon share it, and the daemon finds the command's writes
|
|
191
|
-
(`
|
|
191
|
+
(`reconcileSharedStore`). Writer keys are beside it in `writer-keys/`. Older
|
|
192
192
|
slots left in the home, and `writers/`, are not read, so two versions of
|
|
193
193
|
minca never sign with one key. `minca agent` and the commands an agent runs
|
|
194
194
|
keep each session's key and stores in a slot of `<home>/agent`
|
|
@@ -258,12 +258,13 @@ last compaction left, it compacts them, keeping only what its store holds.
|
|
|
258
258
|
It keeps its state in the store `mirrors/<space id>/<n>`, where `n` is the
|
|
259
259
|
mirror's index:
|
|
260
260
|
|
|
261
|
-
| Key | Value
|
|
262
|
-
| --------------------------- |
|
|
263
|
-
| `mirror:writer` | The writer id
|
|
264
|
-
| `mirror:counter` | The segment counter, in decimal
|
|
265
|
-
| `mirror:read:<segment key>` | `1`, for each segment read or written
|
|
266
|
-
| `mirror:known:<version id>` | `1`, for each version known to be there
|
|
261
|
+
| Key | Value |
|
|
262
|
+
| --------------------------- | ------------------------------------------------------------------------------------- |
|
|
263
|
+
| `mirror:writer` | The writer id |
|
|
264
|
+
| `mirror:counter` | The segment counter, in decimal |
|
|
265
|
+
| `mirror:read:<segment key>` | `1`, for each segment read or written |
|
|
266
|
+
| `mirror:known:<version id>` | `1`, for each version known to be there |
|
|
267
|
+
| `mirror:left` | How many segments the last compaction left, in decimal: the next waits for twice that |
|
|
267
268
|
|
|
268
269
|
"Known" is everything it uploaded or read, so nobody uploads everyone
|
|
269
270
|
else's versions again. It reads the `mirror:known:` entries once, when it
|
|
@@ -310,28 +311,77 @@ With `commit`, placing a version is one atomic write. Without it, versions go
|
|
|
310
311
|
first, then the entries in one batch, then the deletes. So no entry ever
|
|
311
312
|
names a version that isn't there.
|
|
312
313
|
|
|
313
|
-
The library's adapters are
|
|
314
|
-
(
|
|
315
|
-
|
|
314
|
+
The library's adapters are in `@minca/storage`, one entry point each:
|
|
315
|
+
IndexedDB (`/indexeddb`, [above](#indexeddb)), a directory (`/folder`, for a
|
|
316
|
+
data folder's registry and a node's stores on disk), SQLite (`/sqlite`,
|
|
317
|
+
[below](#sqlite)), S3 (`/s3`, for [mirrors](#mirrors)) and memory
|
|
318
|
+
(`/memory`, for tests). `@minca/core` keeps the interfaces and the sealing
|
|
319
|
+
wrapper, `createEncryptedAdapter`.
|
|
320
|
+
|
|
321
|
+
A directory store keeps its versions and its entries' keys in memory, so a
|
|
322
|
+
query or a listing reads no directory. It reads the keys again when the node
|
|
323
|
+
reloads it. The values stay on disk, since they include file chunks. A data
|
|
324
|
+
folder's registry is written by every app of the account and reloaded by
|
|
325
|
+
none, so it reads the disk each time instead (`shared`).
|
|
326
|
+
|
|
327
|
+
Since the keys are in memory, one process writes a directory store, or the
|
|
328
|
+
node that has it open watches it: the daemon finds a command's writes to a
|
|
329
|
+
space's store when it reloads, every two seconds. Until then a key another
|
|
330
|
+
writer deleted is still listed, though it reads as missing.
|
|
331
|
+
|
|
332
|
+
### SQLite
|
|
333
|
+
|
|
334
|
+
`sqliteStores(db)` keeps every store of a node in one SQLite database. A
|
|
335
|
+
host keeps its stores this way. Pass it a connection: `DatabaseSync` from
|
|
336
|
+
`node:sqlite` in Node, or `Database` from `bun:sqlite` in Bun. The library
|
|
337
|
+
imports no driver, so it runs wherever one does.
|
|
338
|
+
|
|
339
|
+
```ts
|
|
340
|
+
import { sqliteStores, type SqliteDatabase } from '@minca/storage/sqlite';
|
|
341
|
+
declare const DatabaseSync: new (file: string) => SqliteDatabase;
|
|
342
|
+
// ---cut---
|
|
343
|
+
// import { DatabaseSync } from 'node:sqlite';
|
|
344
|
+
const stores = sqliteStores(new DatabaseSync('node.sqlite'));
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
Each store is a path, and its entries and version bodies are rows. Every
|
|
348
|
+
write is one transaction, and listing a prefix reads an index. A key may not
|
|
349
|
+
hold U+0000. It keeps
|
|
350
|
+
nothing in memory between calls, so there is nothing to reload, and nothing
|
|
351
|
+
polls it. One process writes the database. `stores.size(path)` gives what a
|
|
352
|
+
store takes, in bytes.
|
|
353
|
+
|
|
354
|
+
Closing a store leaves the database open, since the other stores share it.
|
|
355
|
+
Close the connection when the node is done.
|
|
316
356
|
|
|
317
357
|
## The store in memory
|
|
318
358
|
|
|
319
359
|
A store reads its entries once, then keeps what it needs in memory: each
|
|
320
360
|
collection's set of records, and the entries it read or wrote. It also keeps
|
|
321
|
-
|
|
361
|
+
version bodies, letting the one used longest ago go first. A body never
|
|
322
362
|
changes, so this is always safe. An entry read while a change was landing is
|
|
323
363
|
not kept.
|
|
324
364
|
|
|
365
|
+
Each store keeps up to 32 MB of bodies of its own, unless its store factory
|
|
366
|
+
has a `cache`. Then all the stores share that one. The SQLite stores share
|
|
367
|
+
16 MB, since reading a body again is cheap: the bodies a node keeps then
|
|
368
|
+
take the same memory however many spaces it holds, and however large their
|
|
369
|
+
records are. The cache counts bytes, not bodies, and a body larger than a
|
|
370
|
+
quarter of it isn't kept at all. Each open space still
|
|
371
|
+
keeps its sets and entries.
|
|
372
|
+
|
|
325
373
|
When another writer changes the same store, the node reads all of it again
|
|
326
374
|
(`invalidate`):
|
|
327
375
|
|
|
328
|
-
- **Tabs in one browser.**
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
376
|
+
- **Tabs in one browser.** The app in this repository runs one node for all
|
|
377
|
+
of a site's tabs in a `SharedWorker`, one per account and key. Its stores
|
|
378
|
+
have that one writer, so there's nothing to tell, and a tab the browser
|
|
379
|
+
freezes holds nothing another waits on. The account home does the same.
|
|
380
|
+
- **In a browser without shared workers** each tab runs its node in a worker
|
|
381
|
+
of its own. Tabs tell each other through a
|
|
382
|
+
`BroadcastChannel` named `minca-node:<root DID>:<space id>`. Only the tab
|
|
383
|
+
in view runs its node, one at a time per account, so a frozen tab holds no
|
|
384
|
+
store another is waiting on.
|
|
335
385
|
- **Writers on a shared folder** are found by reading it again
|
|
336
386
|
([data folders](#data-folders)).
|
|
337
387
|
|
|
@@ -339,6 +389,23 @@ The store's fingerprint, in `spaces.status`, is the Negentropy fingerprint
|
|
|
339
389
|
of every collection together, as hex. Two nodes with the same fingerprint
|
|
340
390
|
hold the same data.
|
|
341
391
|
|
|
392
|
+
### Planned: stores that scale with what is in use
|
|
393
|
+
|
|
394
|
+
> **Planned.** Not built yet.
|
|
395
|
+
|
|
396
|
+
- **Sync sets that don't rebuild.** Today a write to a collection drops its
|
|
397
|
+
sorted set, and the next sync sorts it again. Kept in blocks, each with its
|
|
398
|
+
sum, a write would change one block, and a sync in progress would keep the
|
|
399
|
+
blocks it started with.
|
|
400
|
+
- **Files beside the database.** File chunks are 256 KiB, past the size SQLite
|
|
401
|
+
reads faster than separate files. A host would keep them as files under a
|
|
402
|
+
budget, with its bucket holding them all, and the database would know which
|
|
403
|
+
files each version names, so deleting what nothing names is one query.
|
|
404
|
+
- **Spaces open while used.** A host would close a space that has been idle,
|
|
405
|
+
and open it again when a peer asks for it.
|
|
406
|
+
- **The same store in the browser.** IndexedDB answering what SQLite does,
|
|
407
|
+
before deciding whether a browser needs SQLite at all.
|
|
408
|
+
|
|
342
409
|
## Pacing sync
|
|
343
410
|
|
|
344
411
|
The spec says which sync messages go, and when a peer must answer. How often
|
|
@@ -353,10 +420,35 @@ a node speaks, and how much it asks for at once, is its own choice:
|
|
|
353
420
|
| Stale after | 30 s | A silent session, or an unanswered `want`, is dropped and found again later |
|
|
354
421
|
| Versions waiting | 1,000 | Versions held back for later wait in memory. Past 1,000 the oldest go |
|
|
355
422
|
| Refusals remembered | 10,000 | A refused version isn't asked of that peer again. Past 10,000 the oldest are forgotten |
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
423
|
+
| A message's versions | 1 MB, besides the 200 | Large records go a few to a message, so a space of photos syncs like one of notes |
|
|
424
|
+
| Sending what's lacked | a message at a time | Read from the store as it goes, after the connection drains below 1 MB |
|
|
425
|
+
| Taking in | one message from a peer at a time | Past 8 waiting, the node stops reading from that peer until 2 are left |
|
|
426
|
+
|
|
427
|
+
A node sends what a peer lacks a message at a time, reading it from its
|
|
428
|
+
store as it goes, and only once the connection has under 1 MB left to
|
|
429
|
+
send; it answers a `want` the same way. A record's versions still go
|
|
430
|
+
together: the store is read once to learn which record each version is of,
|
|
431
|
+
then again to send. Until what a session found the peer lacks has been
|
|
432
|
+
sent, the collection isn't level with the peer, and no new session starts
|
|
433
|
+
for it, so a slow link is never sent the same versions twice.
|
|
434
|
+
|
|
435
|
+
So with honest peers, a node's memory follows how many it talks to, not
|
|
436
|
+
how large their spaces are: a host taking in a 150 MB space, or handing it
|
|
437
|
+
to a new device, holds a few megabytes of it at a time. The connection is
|
|
438
|
+
what waits. A sender whose socket is backed up stops reading from its
|
|
439
|
+
store, and a receiver that has stopped reading lets the network hold the
|
|
440
|
+
rest. Pausing needs a connection that can pause: a host's sockets can,
|
|
441
|
+
WebRTC and a browser's WebSocket can't. A dishonest peer can still send
|
|
442
|
+
messages as large as the connection takes, eight of them before a host
|
|
443
|
+
stops reading.
|
|
444
|
+
|
|
445
|
+
The side that starts reconciling begins with the space's own records
|
|
446
|
+
(`sys.*`, profiles among them), then the rest from the collection it holds
|
|
447
|
+
fewest versions of to the most, so a long log goes last. Which side starts is
|
|
448
|
+
down to the peers' ids. A new device that starts holds nothing yet, so past
|
|
449
|
+
`sys.*` it goes in the order the peer named the collections. The node asks
|
|
450
|
+
first for `sys.*` too, and for earlier versions a waiting version needs.
|
|
451
|
+
Everything else waits its turn. An id already asked for is not asked again.
|
|
360
452
|
|
|
361
453
|
A session with a peer that is running and has heard something in the last
|
|
362
454
|
30 s isn't started again. It runs once more when it ends.
|
package/docs/usernames.md
CHANGED
|
@@ -57,7 +57,7 @@ Pass `usernames` to `createMincaAuth`, and the account is made with a
|
|
|
57
57
|
username: the create screen asks for one.
|
|
58
58
|
|
|
59
59
|
```ts
|
|
60
|
-
import { createMincaAuth } from '@minca/
|
|
60
|
+
import { createMincaAuth } from '@minca/auth';
|
|
61
61
|
|
|
62
62
|
const auth = createMincaAuth({ usernames: 'minca.social' });
|
|
63
63
|
```
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@minca/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "
|
|
5
|
+
"description": "The Minca protocol: identity, signed records, spaces, the network and sync, and a node that holds them",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "git+https://github.com/leifriksheim/minca.git",
|
|
@@ -21,47 +21,38 @@
|
|
|
21
21
|
"types": "./dist/index.d.ts",
|
|
22
22
|
"import": "./dist/index.js"
|
|
23
23
|
},
|
|
24
|
-
"./storage": {
|
|
25
|
-
"@minca/source": "./src/storage/index.ts",
|
|
26
|
-
"types": "./dist/storage/index.d.ts",
|
|
27
|
-
"import": "./dist/storage/index.js"
|
|
28
|
-
},
|
|
29
|
-
"./node-worker": {
|
|
30
|
-
"@minca/source": "./src/node-worker.ts",
|
|
31
|
-
"types": "./dist/node-worker.d.ts",
|
|
32
|
-
"import": "./dist/node-worker.js"
|
|
33
|
-
},
|
|
34
|
-
"./node": {
|
|
35
|
-
"@minca/source": "./src/node/index.ts",
|
|
36
|
-
"types": "./dist/node/index.d.ts",
|
|
37
|
-
"import": "./dist/node/index.js"
|
|
38
|
-
},
|
|
39
24
|
"./schemas": {
|
|
40
25
|
"@minca/source": "./src/schemas/index.ts",
|
|
41
26
|
"types": "./dist/schemas/index.d.ts",
|
|
42
27
|
"import": "./dist/schemas/index.js"
|
|
43
28
|
},
|
|
44
|
-
"./session": {
|
|
45
|
-
"@minca/source": "./src/session/index.ts",
|
|
46
|
-
"types": "./dist/session/index.d.ts",
|
|
47
|
-
"import": "./dist/session/index.js"
|
|
48
|
-
},
|
|
49
29
|
"./inbox": {
|
|
50
30
|
"@minca/source": "./src/inbox/index.ts",
|
|
51
31
|
"types": "./dist/inbox/index.d.ts",
|
|
52
32
|
"import": "./dist/inbox/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./utils": {
|
|
35
|
+
"@minca/source": "./src/utils/index.ts",
|
|
36
|
+
"types": "./dist/utils/index.d.ts",
|
|
37
|
+
"import": "./dist/utils/index.js"
|
|
53
38
|
}
|
|
54
39
|
},
|
|
55
40
|
"scripts": {
|
|
56
41
|
"build": "rm -rf dist && tsc",
|
|
57
42
|
"typecheck": "tsc --noEmit && tsc -p tests",
|
|
58
|
-
"test": "node --experimental-vm-modules --import tsx --test --test-concurrency=8 --test-timeout=60000 --test-force-exit tests/*.test.ts",
|
|
43
|
+
"test": "node --experimental-vm-modules --conditions=@minca/source --import tsx --test --test-concurrency=8 --test-timeout=60000 --test-force-exit tests/*.test.ts",
|
|
59
44
|
"prepack": "node ../../scripts/npm-readme.mjs",
|
|
60
45
|
"postpack": "rm -f README.md",
|
|
61
46
|
"prepublishOnly": "npm run build"
|
|
62
47
|
},
|
|
63
48
|
"devDependencies": {
|
|
49
|
+
"@minca/actions": "*",
|
|
50
|
+
"@minca/auth": "*",
|
|
51
|
+
"@minca/session": "*",
|
|
52
|
+
"@minca/std": "*",
|
|
53
|
+
"@minca/storage": "*",
|
|
64
54
|
"@types/ws": "^8.18.2",
|
|
55
|
+
"esbuild": "^0.28.2",
|
|
65
56
|
"tsx": "^4.19.0",
|
|
66
57
|
"typescript": "^7.0.2",
|
|
67
58
|
"ws": "^8.22.0",
|
|
@@ -75,8 +66,7 @@
|
|
|
75
66
|
"@cfworker/json-schema": "^4.1.1",
|
|
76
67
|
"@noble/curves": "^2.4.0",
|
|
77
68
|
"@noble/hashes": "^2.4.0",
|
|
78
|
-
"@scure/base": "^2.4.0"
|
|
79
|
-
"aws4fetch": "^1.0.20"
|
|
69
|
+
"@scure/base": "^2.4.0"
|
|
80
70
|
},
|
|
81
71
|
"publishConfig": {
|
|
82
72
|
"access": "public"
|
|
@@ -1,83 +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 type { DirectoryHandleLike } from '../storage/folder-adapter.js';
|
|
25
|
-
import { type AccountVault } from './account-vault.js';
|
|
26
|
-
/** What can be known about an account without unlocking it */
|
|
27
|
-
export interface AccountSummary {
|
|
28
|
-
/** Stable, random, and the name of this account's subtree */
|
|
29
|
-
readonly id: string;
|
|
30
|
-
/** What the person called it. A label — never part of any key. */
|
|
31
|
-
readonly name: string;
|
|
32
|
-
readonly did: string;
|
|
33
|
-
readonly createdAt: string;
|
|
34
|
-
/**
|
|
35
|
-
* Where this account's spaces live, relative to the store root.
|
|
36
|
-
*
|
|
37
|
-
* Carried rather than computed so that a row filed again under a fresh id
|
|
38
|
-
* keeps pointing at the subtree its data already lives in.
|
|
39
|
-
*/
|
|
40
|
-
readonly dataPath: string;
|
|
41
|
-
readonly lastUsedAt?: string;
|
|
42
|
-
}
|
|
43
|
-
export interface AccountStore {
|
|
44
|
-
readonly kind: 'folder' | 'browser';
|
|
45
|
-
/**
|
|
46
|
-
* Every account here, most recently used first.
|
|
47
|
-
*
|
|
48
|
-
* At most one entry per identity. Two rows for one DID is always a mistake —
|
|
49
|
-
* they would appear as separate accounts in a picker while being the same
|
|
50
|
-
* person — so a duplicate is collapsed onto the most recently used.
|
|
51
|
-
*/
|
|
52
|
-
list(): Promise<ReadonlyArray<AccountSummary>>;
|
|
53
|
-
/** One account's locked keys */
|
|
54
|
-
read(id: string): Promise<AccountVault | null>;
|
|
55
|
-
/** Adds or replaces an account */
|
|
56
|
-
write(summary: AccountSummary, vault: AccountVault): Promise<void>;
|
|
57
|
-
/** Forgets an account, and everything it owns */
|
|
58
|
-
remove(id: string): Promise<void>;
|
|
59
|
-
}
|
|
60
|
-
/** Where a brand new account keeps its spaces. */
|
|
61
|
-
export declare function accountDataPath(id: string): string;
|
|
62
|
-
/** A short, stable, filename-safe id for a new account. */
|
|
63
|
-
export declare function newAccountId(): string;
|
|
64
|
-
/**
|
|
65
|
-
* Whether an id has the shape {@link newAccountId} gives one.
|
|
66
|
-
*
|
|
67
|
-
* An id names a directory, and `remove` deletes that directory with everything
|
|
68
|
-
* in it. The list it comes from is a plain file in a folder that may be synced
|
|
69
|
-
* or shared, so an id is checked before it is trusted with a path.
|
|
70
|
-
*/
|
|
71
|
-
export declare function isAccountId(id: unknown): id is string;
|
|
72
|
-
/** Opens the accounts kept in a folder. */
|
|
73
|
-
export declare function createFolderAccountStore(dir: DirectoryHandleLike): AccountStore;
|
|
74
|
-
/**
|
|
75
|
-
* Opens the accounts kept in this browser, for when there is no folder.
|
|
76
|
-
*
|
|
77
|
-
* Same shape as a folder store, so nothing above has to know which it got —
|
|
78
|
-
* the difference is only that no other origin can read this one.
|
|
79
|
-
*
|
|
80
|
-
* @param dbName Overridable for tests
|
|
81
|
-
*/
|
|
82
|
-
export declare function createBrowserAccountStore(dbName?: string): Promise<AccountStore>;
|
|
83
|
-
//# sourceMappingURL=account-store.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"account-store.d.ts","sourceRoot":"","sources":["../../src/identity/account-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAExE,OAAO,EAAkB,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAMvE,8DAA8D;AAC9D,MAAM,WAAW,cAAc;IAC7B,6DAA6D;IAC7D,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,kEAAkE;IAClE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B;;;;;OAKG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,SAAS,CAAC;IACpC;;;;;;OAMG;IACH,IAAI,IAAI,OAAO,CAAC,aAAa,CAAC,cAAc,CAAC,CAAC,CAAC;IAC/C,gCAAgC;IAChC,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;IAC/C,kCAAkC;IAClC,KAAK,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnE,iDAAiD;IACjD,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACnC;AAMD,kDAAkD;AAClD,wBAAgB,eAAe,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAElD;AAED,2DAA2D;AAC3D,wBAAgB,YAAY,IAAI,MAAM,CAKrC;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,EAAE,EAAE,OAAO,GAAG,EAAE,IAAI,MAAM,CAErD;AAgED,2CAA2C;AAC3C,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,mBAAmB,GAAG,YAAY,CAyF/E;AA0BD;;;;;;;GAOG;AACH,wBAAsB,yBAAyB,CAAC,MAAM,SAAU,GAAG,OAAO,CAAC,YAAY,CAAC,CA6BvF"}
|
|
@@ -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,CA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O,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,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"}
|