@minca/core 0.1.14 → 0.1.16
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 +4 -4
- package/dist/elements/auth-styles.d.ts +1 -1
- package/dist/elements/auth-styles.d.ts.map +1 -1
- package/dist/elements/auth-styles.js +21 -4
- package/dist/elements/auth-styles.js.map +1 -1
- package/dist/elements/minca-auth.d.ts.map +1 -1
- package/dist/elements/minca-auth.js +151 -57
- package/dist/elements/minca-auth.js.map +1 -1
- package/dist/files/space-files.d.ts +15 -3
- package/dist/files/space-files.d.ts.map +1 -1
- package/dist/files/space-files.js +225 -37
- package/dist/files/space-files.js.map +1 -1
- package/dist/identity/abilities.d.ts +2 -0
- package/dist/identity/abilities.d.ts.map +1 -1
- package/dist/identity/abilities.js +2 -0
- package/dist/identity/abilities.js.map +1 -1
- package/dist/identity/account-vault.d.ts +15 -71
- package/dist/identity/account-vault.d.ts.map +1 -1
- package/dist/identity/account-vault.js +45 -104
- package/dist/identity/account-vault.js.map +1 -1
- package/dist/identity/channel.d.ts +3 -9
- package/dist/identity/channel.d.ts.map +1 -1
- package/dist/identity/channel.js +42 -42
- package/dist/identity/channel.js.map +1 -1
- package/dist/identity/contact-key.d.ts +14 -29
- package/dist/identity/contact-key.d.ts.map +1 -1
- package/dist/identity/contact-key.js +31 -51
- package/dist/identity/contact-key.js.map +1 -1
- package/dist/identity/crypto-p256.d.ts.map +1 -1
- package/dist/identity/crypto-p256.js +39 -53
- package/dist/identity/crypto-p256.js.map +1 -1
- package/dist/identity/hpke.d.ts.map +1 -1
- package/dist/identity/hpke.js +19 -19
- package/dist/identity/hpke.js.map +1 -1
- package/dist/identity/identity-manager.d.ts.map +1 -1
- package/dist/identity/identity-manager.js +1 -2
- package/dist/identity/identity-manager.js.map +1 -1
- package/dist/identity/policy.d.ts.map +1 -1
- package/dist/identity/policy.js +35 -61
- package/dist/identity/policy.js.map +1 -1
- package/dist/identity/recovery-code.d.ts +2 -8
- package/dist/identity/recovery-code.d.ts.map +1 -1
- package/dist/identity/recovery-code.js +4 -11
- package/dist/identity/recovery-code.js.map +1 -1
- package/dist/identity/root-signer.d.ts +1 -6
- package/dist/identity/root-signer.d.ts.map +1 -1
- package/dist/identity/root-signer.js +12 -15
- package/dist/identity/root-signer.js.map +1 -1
- package/dist/identity/ucan.d.ts.map +1 -1
- package/dist/identity/ucan.js +48 -39
- package/dist/identity/ucan.js.map +1 -1
- package/dist/identity/webauthn.d.ts +6 -11
- package/dist/identity/webauthn.d.ts.map +1 -1
- package/dist/identity/webauthn.js +18 -30
- package/dist/identity/webauthn.js.map +1 -1
- package/dist/inbox/inbox.d.ts.map +1 -1
- package/dist/inbox/inbox.js +40 -30
- package/dist/inbox/inbox.js.map +1 -1
- package/dist/inbox/index.d.ts +2 -0
- package/dist/inbox/index.d.ts.map +1 -1
- package/dist/inbox/index.js +1 -0
- package/dist/inbox/index.js.map +1 -1
- package/dist/inbox/names.d.ts +54 -0
- package/dist/inbox/names.d.ts.map +1 -0
- package/dist/inbox/names.js +299 -0
- package/dist/inbox/names.js.map +1 -0
- package/dist/index.d.ts +3 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -12
- package/dist/index.js.map +1 -1
- package/dist/network/mesh.d.ts +7 -20
- package/dist/network/mesh.d.ts.map +1 -1
- package/dist/network/mesh.js +267 -245
- package/dist/network/mesh.js.map +1 -1
- package/dist/network/relay-link.d.ts +31 -0
- package/dist/network/relay-link.d.ts.map +1 -0
- package/dist/network/relay-link.js +62 -0
- package/dist/network/relay-link.js.map +1 -0
- package/dist/network/relay-minca.d.ts +12 -1
- package/dist/network/relay-minca.d.ts.map +1 -1
- package/dist/network/relay-minca.js +25 -55
- package/dist/network/relay-minca.js.map +1 -1
- package/dist/network/relay-nostr.d.ts +14 -3
- package/dist/network/relay-nostr.d.ts.map +1 -1
- package/dist/network/relay-nostr.js +34 -72
- package/dist/network/relay-nostr.js.map +1 -1
- package/dist/network/relay-socket.d.ts +1 -1
- package/dist/network/relay-socket.d.ts.map +1 -1
- package/dist/network/relay-socket.js +3 -1
- package/dist/network/relay-socket.js.map +1 -1
- package/dist/network/relays.d.ts +26 -17
- package/dist/network/relays.d.ts.map +1 -1
- package/dist/network/relays.js +21 -28
- package/dist/network/relays.js.map +1 -1
- package/dist/network/rendezvous.d.ts +1 -1
- package/dist/network/rendezvous.d.ts.map +1 -1
- package/dist/network/rendezvous.js +2 -2
- package/dist/network/rendezvous.js.map +1 -1
- package/dist/node/actions.d.ts.map +1 -1
- package/dist/node/actions.js +56 -39
- package/dist/node/actions.js.map +1 -1
- package/dist/node/api.d.ts +6 -0
- package/dist/node/api.d.ts.map +1 -1
- package/dist/node/api.js +6 -0
- package/dist/node/api.js.map +1 -1
- package/dist/node/carrier.d.ts +5 -0
- package/dist/node/carrier.d.ts.map +1 -1
- package/dist/node/carrier.js +94 -73
- package/dist/node/carrier.js.map +1 -1
- package/dist/node/copy.d.ts +8 -7
- package/dist/node/copy.d.ts.map +1 -1
- package/dist/node/copy.js +54 -56
- package/dist/node/copy.js.map +1 -1
- package/dist/node/host.d.ts +39 -65
- package/dist/node/host.d.ts.map +1 -1
- package/dist/node/host.js +362 -379
- package/dist/node/host.js.map +1 -1
- package/dist/node/index.d.ts +2 -2
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +1 -1
- package/dist/node/index.js.map +1 -1
- package/dist/node/node-carriers.d.ts +35 -0
- package/dist/node/node-carriers.d.ts.map +1 -0
- package/dist/node/node-carriers.js +562 -0
- package/dist/node/node-carriers.js.map +1 -0
- package/dist/node/node-contacts.d.ts +11 -0
- package/dist/node/node-contacts.d.ts.map +1 -0
- package/dist/node/node-contacts.js +808 -0
- package/dist/node/node-contacts.js.map +1 -0
- package/dist/node/node-context.d.ts +76 -0
- package/dist/node/node-context.d.ts.map +1 -0
- package/dist/node/node-context.js +54 -0
- package/dist/node/node-context.js.map +1 -0
- package/dist/node/node-hosting.d.ts +20 -0
- package/dist/node/node-hosting.d.ts.map +1 -0
- package/dist/node/node-hosting.js +449 -0
- package/dist/node/node-hosting.js.map +1 -0
- package/dist/node/node-records.d.ts +18 -0
- package/dist/node/node-records.d.ts.map +1 -0
- package/dist/node/node-records.js +262 -0
- package/dist/node/node-records.js.map +1 -0
- package/dist/node/node.d.ts.map +1 -1
- package/dist/node/node.js +197 -1989
- package/dist/node/node.js.map +1 -1
- package/dist/node/remote.d.ts +5 -6
- package/dist/node/remote.d.ts.map +1 -1
- package/dist/node/remote.js +272 -260
- package/dist/node/remote.js.map +1 -1
- package/dist/node/space-catalog.d.ts +40 -0
- package/dist/node/space-catalog.d.ts.map +1 -0
- package/dist/node/space-catalog.js +158 -0
- package/dist/node/space-catalog.js.map +1 -0
- package/dist/node/space-checks.d.ts +25 -0
- package/dist/node/space-checks.d.ts.map +1 -0
- package/dist/node/space-checks.js +343 -0
- package/dist/node/space-checks.js.map +1 -0
- package/dist/node/space-history.d.ts +37 -0
- package/dist/node/space-history.d.ts.map +1 -0
- package/dist/node/space-history.js +350 -0
- package/dist/node/space-history.js.map +1 -0
- package/dist/node/space-holding.d.ts +49 -0
- package/dist/node/space-holding.d.ts.map +1 -0
- package/dist/node/space-holding.js +267 -0
- package/dist/node/space-holding.js.map +1 -0
- package/dist/node/space-index.d.ts +41 -0
- package/dist/node/space-index.d.ts.map +1 -0
- package/dist/node/space-index.js +217 -0
- package/dist/node/space-index.js.map +1 -0
- package/dist/node/space-keys.d.ts +34 -0
- package/dist/node/space-keys.d.ts.map +1 -0
- package/dist/node/space-keys.js +309 -0
- package/dist/node/space-keys.js.map +1 -0
- package/dist/node/space-lines.d.ts +33 -0
- package/dist/node/space-lines.d.ts.map +1 -0
- package/dist/node/space-lines.js +145 -0
- package/dist/node/space-lines.js.map +1 -0
- package/dist/node/space-membership.d.ts +69 -0
- package/dist/node/space-membership.d.ts.map +1 -0
- package/dist/node/space-membership.js +242 -0
- package/dist/node/space-membership.js.map +1 -0
- package/dist/node/space-mirrors.d.ts +43 -0
- package/dist/node/space-mirrors.d.ts.map +1 -0
- package/dist/node/space-mirrors.js +125 -0
- package/dist/node/space-mirrors.js.map +1 -0
- package/dist/node/space-peers.d.ts +104 -0
- package/dist/node/space-peers.d.ts.map +1 -0
- package/dist/node/space-peers.js +595 -0
- package/dist/node/space-peers.js.map +1 -0
- package/dist/node/space-profiles.d.ts +18 -0
- package/dist/node/space-profiles.d.ts.map +1 -0
- package/dist/node/space-profiles.js +105 -0
- package/dist/node/space-profiles.js.map +1 -0
- package/dist/node/space-rules.d.ts +29 -0
- package/dist/node/space-rules.d.ts.map +1 -0
- package/dist/node/space-rules.js +144 -0
- package/dist/node/space-rules.js.map +1 -0
- package/dist/node/space-runtime.d.ts +104 -143
- package/dist/node/space-runtime.d.ts.map +1 -1
- package/dist/node/space-runtime.js +293 -3954
- package/dist/node/space-runtime.js.map +1 -1
- package/dist/node/space-standing.d.ts +20 -0
- package/dist/node/space-standing.d.ts.map +1 -0
- package/dist/node/space-standing.js +317 -0
- package/dist/node/space-standing.js.map +1 -0
- package/dist/node/space-versions.d.ts +104 -0
- package/dist/node/space-versions.d.ts.map +1 -0
- package/dist/node/space-versions.js +153 -0
- package/dist/node/space-versions.js.map +1 -0
- package/dist/node/space-warrants.d.ts +25 -0
- package/dist/node/space-warrants.d.ts.map +1 -0
- package/dist/node/space-warrants.js +214 -0
- package/dist/node/space-warrants.js.map +1 -0
- package/dist/node/space-writing.d.ts +72 -0
- package/dist/node/space-writing.d.ts.map +1 -0
- package/dist/node/space-writing.js +440 -0
- package/dist/node/space-writing.js.map +1 -0
- package/dist/node/stores.d.ts +19 -50
- package/dist/node/stores.d.ts.map +1 -1
- package/dist/node/stores.js +14 -33
- package/dist/node/stores.js.map +1 -1
- package/dist/node/types.d.ts +225 -305
- package/dist/node/types.d.ts.map +1 -1
- package/dist/node/usage.d.ts +2 -24
- package/dist/node/usage.d.ts.map +1 -1
- package/dist/node/usage.js +118 -102
- package/dist/node/usage.js.map +1 -1
- package/dist/node/watch-notifications.d.ts.map +1 -1
- package/dist/node/watch-notifications.js +32 -29
- package/dist/node/watch-notifications.js.map +1 -1
- package/dist/node/worker.d.ts +5 -6
- package/dist/node/worker.d.ts.map +1 -1
- package/dist/node/worker.js +80 -72
- package/dist/node/worker.js.map +1 -1
- package/dist/node/writer-keys.d.ts +5 -6
- package/dist/node/writer-keys.d.ts.map +1 -1
- package/dist/node/writer-keys.js +66 -57
- package/dist/node/writer-keys.js.map +1 -1
- package/dist/node/writers.d.ts +12 -19
- package/dist/node/writers.d.ts.map +1 -1
- package/dist/node/writers.js +7 -15
- package/dist/node/writers.js.map +1 -1
- package/dist/privacy/direct.d.ts.map +1 -1
- package/dist/privacy/direct.js +31 -27
- package/dist/privacy/direct.js.map +1 -1
- package/dist/privacy/space-encryption.d.ts.map +1 -1
- package/dist/privacy/space-encryption.js +5 -9
- package/dist/privacy/space-encryption.js.map +1 -1
- package/dist/query/computed.d.ts.map +1 -1
- package/dist/query/computed.js +78 -77
- package/dist/query/computed.js.map +1 -1
- package/dist/query/engine.d.ts +3 -4
- package/dist/query/engine.d.ts.map +1 -1
- package/dist/query/engine.js +93 -86
- package/dist/query/engine.js.map +1 -1
- package/dist/query/filter.d.ts +8 -10
- package/dist/query/filter.d.ts.map +1 -1
- package/dist/query/filter.js +144 -161
- package/dist/query/filter.js.map +1 -1
- package/dist/records/cel-types.d.ts.map +1 -1
- package/dist/records/cel-types.js +13 -27
- package/dist/records/cel-types.js.map +1 -1
- package/dist/records/cel.d.ts.map +1 -1
- package/dist/records/cel.js +177 -242
- package/dist/records/cel.js.map +1 -1
- package/dist/records/rules.d.ts.map +1 -1
- package/dist/records/rules.js +46 -50
- package/dist/records/rules.js.map +1 -1
- package/dist/records/topics.d.ts.map +1 -1
- package/dist/records/topics.js +18 -22
- package/dist/records/topics.js.map +1 -1
- package/dist/schema/collection-def.d.ts.map +1 -1
- package/dist/schema/collection-def.js +16 -5
- package/dist/schema/collection-def.js.map +1 -1
- package/dist/schemas/automations.d.ts +16 -15
- package/dist/schemas/automations.d.ts.map +1 -1
- package/dist/schemas/automations.js +203 -165
- package/dist/schemas/automations.js.map +1 -1
- package/dist/schemas/blueprints.d.ts.map +1 -1
- package/dist/schemas/blueprints.js +14 -13
- package/dist/schemas/blueprints.js.map +1 -1
- package/dist/schemas/connectors.d.ts +12 -0
- package/dist/schemas/connectors.d.ts.map +1 -1
- package/dist/schemas/connectors.js +16 -11
- package/dist/schemas/connectors.js.map +1 -1
- package/dist/schemas/contacts.d.ts +57 -0
- package/dist/schemas/contacts.d.ts.map +1 -1
- package/dist/schemas/contacts.js +32 -0
- package/dist/schemas/contacts.js.map +1 -1
- package/dist/schemas/cron.d.ts.map +1 -1
- package/dist/schemas/cron.js +27 -28
- package/dist/schemas/cron.js.map +1 -1
- package/dist/schemas/defined.d.ts +6 -0
- package/dist/schemas/defined.d.ts.map +1 -0
- package/dist/schemas/defined.js +7 -0
- package/dist/schemas/defined.js.map +1 -0
- package/dist/schemas/fragments.d.ts +22 -2
- package/dist/schemas/fragments.d.ts.map +1 -1
- package/dist/schemas/fragments.js +20 -12
- package/dist/schemas/fragments.js.map +1 -1
- package/dist/schemas/guides.d.ts +3 -1
- package/dist/schemas/guides.d.ts.map +1 -1
- package/dist/schemas/guides.js +13 -12
- package/dist/schemas/guides.js.map +1 -1
- package/dist/schemas/index.d.ts +2 -2
- package/dist/schemas/index.d.ts.map +1 -1
- package/dist/schemas/index.js +18 -14
- package/dist/schemas/index.js.map +1 -1
- package/dist/schemas/library/annotations.d.ts +30 -0
- package/dist/schemas/library/annotations.d.ts.map +1 -1
- package/dist/schemas/library/annotations.js +1 -0
- package/dist/schemas/library/annotations.js.map +1 -1
- package/dist/schemas/library/community.d.ts +28 -0
- package/dist/schemas/library/community.d.ts.map +1 -1
- package/dist/schemas/library/life.d.ts +62 -2
- package/dist/schemas/library/life.d.ts.map +1 -1
- package/dist/schemas/library/media.d.ts +36 -0
- package/dist/schemas/library/media.d.ts.map +1 -1
- package/dist/schemas/library/money.d.ts +74 -2
- package/dist/schemas/library/money.d.ts.map +1 -1
- package/dist/schemas/library/planning.d.ts +56 -0
- package/dist/schemas/library/planning.d.ts.map +1 -1
- package/dist/schemas/library/publishing.d.ts +80 -4
- package/dist/schemas/library/publishing.d.ts.map +1 -1
- package/dist/schemas/library/social.d.ts +44 -0
- package/dist/schemas/library/social.d.ts.map +1 -1
- package/dist/session/account-hint.d.ts.map +1 -1
- package/dist/session/account-hint.js +8 -5
- package/dist/session/account-hint.js.map +1 -1
- package/dist/session/auth.d.ts +36 -2
- package/dist/session/auth.d.ts.map +1 -1
- package/dist/session/auth.js +95 -2
- package/dist/session/auth.js.map +1 -1
- package/dist/session/connect.d.ts +1 -0
- package/dist/session/connect.d.ts.map +1 -1
- package/dist/session/connect.js +3 -1
- package/dist/session/connect.js.map +1 -1
- package/dist/session/credentials.d.ts +8 -26
- package/dist/session/credentials.d.ts.map +1 -1
- package/dist/session/credentials.js +14 -32
- package/dist/session/credentials.js.map +1 -1
- package/dist/session/index.d.ts +1 -0
- package/dist/session/index.d.ts.map +1 -1
- package/dist/session/index.js +1 -0
- package/dist/session/index.js.map +1 -1
- package/dist/session/pairing.d.ts.map +1 -1
- package/dist/session/pairing.js +92 -88
- package/dist/session/pairing.js.map +1 -1
- package/dist/session/password-strength.d.ts.map +1 -1
- package/dist/session/password-strength.js +37 -37
- package/dist/session/password-strength.js.map +1 -1
- package/dist/session/places.d.ts.map +1 -1
- package/dist/session/places.js +18 -13
- package/dist/session/places.js.map +1 -1
- package/dist/session/popup.d.ts +13 -0
- package/dist/session/popup.d.ts.map +1 -0
- package/dist/session/popup.js +23 -0
- package/dist/session/popup.js.map +1 -0
- package/dist/space/constitution.d.ts.map +1 -1
- package/dist/space/constitution.js +22 -29
- package/dist/space/constitution.js.map +1 -1
- package/dist/space/grants.d.ts.map +1 -1
- package/dist/space/grants.js +37 -39
- package/dist/space/grants.js.map +1 -1
- package/dist/space/invite-link.d.ts.map +1 -1
- package/dist/space/invite-link.js +33 -33
- package/dist/space/invite-link.js.map +1 -1
- package/dist/space/own-automations.d.ts +13 -24
- package/dist/space/own-automations.d.ts.map +1 -1
- package/dist/space/own-automations.js +47 -37
- package/dist/space/own-automations.js.map +1 -1
- package/dist/space/roles.d.ts +56 -80
- package/dist/space/roles.d.ts.map +1 -1
- package/dist/space/roles.js +448 -441
- package/dist/space/roles.js.map +1 -1
- package/dist/space/space-access.d.ts +3 -4
- package/dist/space/space-access.d.ts.map +1 -1
- package/dist/space/space-access.js +3 -8
- package/dist/space/space-access.js.map +1 -1
- package/dist/storage/blob/directory.d.ts.map +1 -1
- package/dist/storage/blob/directory.js +39 -32
- package/dist/storage/blob/directory.js.map +1 -1
- package/dist/storage/blob/s3.d.ts.map +1 -1
- package/dist/storage/blob/s3.js +21 -19
- package/dist/storage/blob/s3.js.map +1 -1
- package/dist/storage/blob-store.d.ts +0 -9
- package/dist/storage/blob-store.d.ts.map +1 -1
- package/dist/storage/directory-access.d.ts +8 -32
- package/dist/storage/directory-access.d.ts.map +1 -1
- package/dist/storage/directory-access.js +11 -36
- package/dist/storage/directory-access.js.map +1 -1
- package/dist/storage/encrypted-adapter.d.ts +12 -32
- package/dist/storage/encrypted-adapter.d.ts.map +1 -1
- package/dist/storage/encrypted-adapter.js +31 -54
- package/dist/storage/encrypted-adapter.js.map +1 -1
- package/dist/storage/folder-adapter.d.ts +12 -26
- package/dist/storage/folder-adapter.d.ts.map +1 -1
- package/dist/storage/folder-adapter.js +37 -54
- package/dist/storage/folder-adapter.js.map +1 -1
- package/dist/storage/folder-reconcile.d.ts +12 -26
- package/dist/storage/folder-reconcile.d.ts.map +1 -1
- package/dist/storage/folder-reconcile.js +39 -48
- package/dist/storage/folder-reconcile.js.map +1 -1
- package/dist/storage/indexeddb-adapter.d.ts +2 -6
- package/dist/storage/indexeddb-adapter.d.ts.map +1 -1
- package/dist/storage/indexeddb-adapter.js +60 -114
- package/dist/storage/indexeddb-adapter.js.map +1 -1
- package/dist/storage/mirror.d.ts +0 -29
- package/dist/storage/mirror.d.ts.map +1 -1
- package/dist/storage/mirror.js +153 -110
- package/dist/storage/mirror.js.map +1 -1
- package/dist/storage/segment.d.ts.map +1 -1
- package/dist/storage/segment.js +3 -7
- package/dist/storage/segment.js.map +1 -1
- package/dist/storage/storage-provider.d.ts +6 -11
- package/dist/storage/storage-provider.d.ts.map +1 -1
- package/dist/storage/storage-provider.js +112 -116
- package/dist/storage/storage-provider.js.map +1 -1
- package/dist/sync/sync-engine.d.ts +10 -44
- package/dist/sync/sync-engine.d.ts.map +1 -1
- package/dist/sync/sync-engine.js +245 -247
- package/dist/sync/sync-engine.js.map +1 -1
- package/dist/sync/sync-messages.d.ts +1 -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/utils/guards.d.ts +1 -0
- package/dist/utils/guards.d.ts.map +1 -1
- package/dist/utils/guards.js +1 -0
- package/dist/utils/guards.js.map +1 -1
- package/dist/utils/hmac.d.ts +5 -0
- package/dist/utils/hmac.d.ts.map +1 -0
- package/dist/utils/hmac.js +20 -0
- package/dist/utils/hmac.js.map +1 -0
- package/dist/utils/map.d.ts +10 -0
- package/dist/utils/map.d.ts.map +1 -0
- package/dist/utils/map.js +30 -0
- package/dist/utils/map.js.map +1 -0
- package/dist/utils/serial.d.ts +2 -0
- package/dist/utils/serial.d.ts.map +1 -1
- package/dist/utils/serial.js +9 -0
- package/dist/utils/serial.js.map +1 -1
- package/dist/validation/capability-gate.d.ts +7 -15
- package/dist/validation/capability-gate.d.ts.map +1 -1
- package/dist/validation/capability-gate.js +32 -36
- package/dist/validation/capability-gate.js.map +1 -1
- package/dist/validation/crypto-gate.d.ts.map +1 -1
- package/dist/validation/crypto-gate.js +12 -21
- package/dist/validation/crypto-gate.js.map +1 -1
- package/docs/README.md +3 -2
- package/docs/actions.md +47 -20
- package/docs/automations.md +1 -1
- package/docs/blueprints-and-guides.md +57 -13
- package/docs/building-an-app.md +11 -8
- package/docs/collections.md +33 -5
- package/docs/contacts.md +34 -1
- package/docs/contracts.md +1 -1
- package/docs/direct-messages.md +1 -1
- package/docs/inbox.md +5 -11
- package/docs/node.md +36 -26
- package/docs/records-and-queries.md +1 -1
- package/docs/sign-in.md +54 -26
- package/docs/spaces.md +6 -6
- package/docs/standard-library.md +33 -31
- package/docs/storage.md +37 -15
- package/docs/usernames.md +161 -0
- package/docs/warrants.md +1 -1
- package/package.json +2 -21
- package/dist/calls/calls.d.ts +0 -140
- package/dist/calls/calls.d.ts.map +0 -1
- package/dist/calls/calls.js +0 -861
- package/dist/calls/calls.js.map +0 -1
- package/dist/calls/index.d.ts +0 -4
- package/dist/calls/index.d.ts.map +0 -1
- package/dist/calls/index.js +0 -3
- package/dist/calls/index.js.map +0 -1
- package/dist/react/context.d.ts +0 -81
- package/dist/react/context.d.ts.map +0 -1
- package/dist/react/context.js +0 -97
- package/dist/react/context.js.map +0 -1
- package/dist/react/follow.d.ts +0 -11
- package/dist/react/follow.d.ts.map +0 -1
- package/dist/react/follow.js +0 -7
- package/dist/react/follow.js.map +0 -1
- package/dist/react/index.d.ts +0 -44
- package/dist/react/index.d.ts.map +0 -1
- package/dist/react/index.js +0 -40
- package/dist/react/index.js.map +0 -1
- package/dist/react/minca-auth.d.ts +0 -19
- package/dist/react/minca-auth.d.ts.map +0 -1
- package/dist/react/minca-auth.js +0 -36
- package/dist/react/minca-auth.js.map +0 -1
- package/dist/react/use-calls.d.ts +0 -21
- package/dist/react/use-calls.d.ts.map +0 -1
- package/dist/react/use-calls.js +0 -39
- package/dist/react/use-calls.js.map +0 -1
- package/dist/react/use-invite-link.d.ts +0 -24
- package/dist/react/use-invite-link.d.ts.map +0 -1
- package/dist/react/use-invite-link.js +0 -62
- package/dist/react/use-invite-link.js.map +0 -1
- package/dist/react/use-live.d.ts +0 -16
- package/dist/react/use-live.d.ts.map +0 -1
- package/dist/react/use-live.js +0 -56
- package/dist/react/use-live.js.map +0 -1
- package/dist/react/use-my-name.d.ts +0 -12
- package/dist/react/use-my-name.d.ts.map +0 -1
- package/dist/react/use-my-name.js +0 -38
- package/dist/react/use-my-name.js.map +0 -1
- package/dist/react/use-names.d.ts +0 -7
- package/dist/react/use-names.d.ts.map +0 -1
- package/dist/react/use-names.js +0 -13
- package/dist/react/use-names.js.map +0 -1
- package/dist/react/use-network.d.ts +0 -9
- package/dist/react/use-network.d.ts.map +0 -1
- package/dist/react/use-network.js +0 -33
- package/dist/react/use-network.js.map +0 -1
- package/dist/react/use-query.d.ts +0 -14
- package/dist/react/use-query.d.ts.map +0 -1
- package/dist/react/use-query.js +0 -26
- package/dist/react/use-query.js.map +0 -1
- package/dist/react/use-space.d.ts +0 -29
- package/dist/react/use-space.d.ts.map +0 -1
- package/dist/react/use-space.js +0 -57
- package/dist/react/use-space.js.map +0 -1
- package/dist/react/use-spaces.d.ts +0 -29
- package/dist/react/use-spaces.d.ts.map +0 -1
- package/dist/react/use-spaces.js +0 -78
- package/dist/react/use-spaces.js.map +0 -1
- package/docs/calls.md +0 -189
|
@@ -0,0 +1,808 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module node-contacts
|
|
3
|
+
* The account as others meet it: its profile, its contacts and the spaces
|
|
4
|
+
* for two they talk in, and its inbox.
|
|
5
|
+
*/
|
|
6
|
+
import { cached } from '../utils/map.js';
|
|
7
|
+
import { parseSpaceInvite } from '../space/space-manager.js';
|
|
8
|
+
import { checkInvitation } from '../space/invitation.js';
|
|
9
|
+
import { checkSpace } from '../space/constitution.js';
|
|
10
|
+
import { team } from '../space/presets.js';
|
|
11
|
+
import { isAvatarRef, PROFILE_COLLECTION, PROFILE_KEY, } from '../space/account-registry.js';
|
|
12
|
+
import { contactPublicKey, deriveInboxKeyBytes, deriveInboxSignKeyBytes } from '../identity/contact-key.js';
|
|
13
|
+
import { contact as contactSchema, contactRequest as contactRequestSchema, inbox as inboxSchema, knock as knockSchema, spaceInvite as spaceInviteSchema, } from '../schemas/contacts.js';
|
|
14
|
+
import { claimUsername, formatUsername, parseUsername, resolveUsername } from '../inbox/names.js';
|
|
15
|
+
import { clip, encodeInbox, inboxTopic, KNOCK_TTL_SECONDS, knockId, MAX_INBOX_PLACES, openKnock, readInbox as readInboxCode, sealKnock, signPurge, } from '../inbox/inbox.js';
|
|
16
|
+
import { relayKind } from '../network/relays.js';
|
|
17
|
+
import { base64UrlDecode } from '../utils/encoding.js';
|
|
18
|
+
import { isRecord } from '../utils/guards.js';
|
|
19
|
+
import { usableRelays } from './space-peers.js';
|
|
20
|
+
import { ensureDefined, errorText, inBackground } from './node-context.js';
|
|
21
|
+
const DAY_MS = 24 * 3600 * 1000;
|
|
22
|
+
export function createNodeContacts(ctx) {
|
|
23
|
+
const { config, provider, registry, mailbox, accountSpaceId, contactsSpaceId, contactKeys } = ctx;
|
|
24
|
+
// ─── The profile ───────────────────────────────────────────────────
|
|
25
|
+
//
|
|
26
|
+
// The account's name and picture, kept in its registry, and told to each
|
|
27
|
+
// space it uses as that space opens.
|
|
28
|
+
/**
|
|
29
|
+
* The account's profile, from its registry — null without an account key,
|
|
30
|
+
* or before one is set. One record: its current version is the name, by the
|
|
31
|
+
* ordering rule, the same on every device whatever their clocks say.
|
|
32
|
+
*/
|
|
33
|
+
async function ownProfile() {
|
|
34
|
+
if (!accountSpaceId)
|
|
35
|
+
return null;
|
|
36
|
+
const profile = await (await ctx.runtime(accountSpaceId)).get(PROFILE_KEY);
|
|
37
|
+
if (!profile?.verified || profile.root !== config.signer.did || typeof profile.body?.name !== 'string')
|
|
38
|
+
return null;
|
|
39
|
+
const avatar = profile.body.avatar;
|
|
40
|
+
return {
|
|
41
|
+
name: profile.body.name,
|
|
42
|
+
updatedAt: profile.updatedAt,
|
|
43
|
+
...(isAvatarRef(avatar) ? { avatar } : {}),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
const ownName = async () => (await ownProfile())?.name ?? config.accountName ?? null;
|
|
47
|
+
/**
|
|
48
|
+
* Tells a space who this account is. Done when the space opens and when the
|
|
49
|
+
* name changes — not by opening every space, which would start syncing them
|
|
50
|
+
* all; a space not open now hears on its next open.
|
|
51
|
+
*/
|
|
52
|
+
async function publishProfile(spaceId, open) {
|
|
53
|
+
if (ctx.narrowNote || (await ctx.kindOf(spaceId)))
|
|
54
|
+
return;
|
|
55
|
+
const own = await ownProfile();
|
|
56
|
+
if (!own)
|
|
57
|
+
return;
|
|
58
|
+
const base = { name: own.name, ...(contactKeys ? { contactKey: contactKeys.publicKey } : {}) };
|
|
59
|
+
const held = await heldAvatar(open);
|
|
60
|
+
const copied = held?.source === own.avatar?.hash ? held : undefined;
|
|
61
|
+
// The name goes out now with the picture the space has; a new picture follows once copied,
|
|
62
|
+
// which may wait on its bytes reaching this device.
|
|
63
|
+
const shown = own.avatar ? (copied ?? held) : undefined;
|
|
64
|
+
await open.publishProfile({ ...base, ...(shown ? { avatar: shown } : {}) });
|
|
65
|
+
if (own.avatar && !copied)
|
|
66
|
+
inBackground(avatarIn(spaceId, open, own.avatar).then((avatar) => open.publishProfile({ ...base, avatar })));
|
|
67
|
+
}
|
|
68
|
+
/** The account's picture as this space shows it */
|
|
69
|
+
async function heldAvatar(open) {
|
|
70
|
+
const avatar = (await open.profiles()).find((profile) => profile.did === config.signer.did)?.avatar;
|
|
71
|
+
return isAvatarRef(avatar) ? avatar : undefined;
|
|
72
|
+
}
|
|
73
|
+
const avatarCopies = new Map();
|
|
74
|
+
/**
|
|
75
|
+
* The account's picture as a file of this space: members can't read the
|
|
76
|
+
* registry, so each space holds its own copy, made once per picture.
|
|
77
|
+
*/
|
|
78
|
+
function avatarIn(spaceId, open, avatar) {
|
|
79
|
+
return cached(avatarCopies, `${spaceId}:${avatar.hash}`, async () => {
|
|
80
|
+
const held = await heldAvatar(open);
|
|
81
|
+
if (held?.source === avatar.hash)
|
|
82
|
+
return held;
|
|
83
|
+
const registryRt = await ctx.requireAccount('Copying the picture');
|
|
84
|
+
const copy = await open.addFile(await registryRt.readFile(avatar));
|
|
85
|
+
return { ...copy, mime: avatar.mime, source: avatar.hash };
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
async function publishProfileToOpenSpaces() {
|
|
89
|
+
for (const [spaceId, open] of ctx.runtimes) {
|
|
90
|
+
await open.then((rt) => publishProfile(spaceId, rt)).catch(() => { });
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/** Writes the account's profile, and tells every open space */
|
|
94
|
+
async function writeProfile(registryRt, profile) {
|
|
95
|
+
const written = await registryRt.upsertSystem(PROFILE_COLLECTION, PROFILE_KEY, profile);
|
|
96
|
+
ctx.emit({ type: 'account' });
|
|
97
|
+
await publishProfileToOpenSpaces();
|
|
98
|
+
return { ...profile, updatedAt: written.updatedAt };
|
|
99
|
+
}
|
|
100
|
+
const account = Object.freeze({
|
|
101
|
+
profile: ownProfile,
|
|
102
|
+
async setName(name) {
|
|
103
|
+
const registryRt = await ctx.requireAccount('Renaming across devices');
|
|
104
|
+
const trimmed = name.trim();
|
|
105
|
+
if (!trimmed)
|
|
106
|
+
throw new Error('A name cannot be empty');
|
|
107
|
+
const avatar = (await ownProfile())?.avatar;
|
|
108
|
+
return writeProfile(registryRt, { name: trimmed, ...(avatar ? { avatar } : {}) });
|
|
109
|
+
},
|
|
110
|
+
async setAvatar(image, options = {}) {
|
|
111
|
+
const registryRt = await ctx.requireAccount('Changing the picture across devices');
|
|
112
|
+
const name = (await ownName()) ?? options.name?.trim();
|
|
113
|
+
if (!name)
|
|
114
|
+
throw new Error('Give the account a name first');
|
|
115
|
+
if (image && !image.mime.startsWith('image/'))
|
|
116
|
+
throw new Error('A picture is an image');
|
|
117
|
+
const avatar = image ? { ...(await registryRt.addFile(image.bytes)), mime: image.mime } : null;
|
|
118
|
+
return writeProfile(registryRt, { name, ...(avatar ? { avatar } : {}) });
|
|
119
|
+
},
|
|
120
|
+
async picture() {
|
|
121
|
+
const avatar = (await ownProfile())?.avatar;
|
|
122
|
+
if (!avatar || !accountSpaceId)
|
|
123
|
+
return null;
|
|
124
|
+
return { bytes: await (await ctx.runtime(accountSpaceId)).readFile(avatar), mime: avatar.mime };
|
|
125
|
+
},
|
|
126
|
+
revoke: async (key, options) => (await ctx.requireAccount('Revoking in the account registry')).revoke(key, options),
|
|
127
|
+
});
|
|
128
|
+
// ─── Contacts ──────────────────────────────────────────────────────
|
|
129
|
+
//
|
|
130
|
+
// One `std.contact` per person in the contacts space, keyed by their DID.
|
|
131
|
+
// Asking someone is a knock left as a `std.contact-request` in a space you
|
|
132
|
+
// share: the signed invite to a new space for two, sealed to their contact
|
|
133
|
+
// key, so it opens only for them, and only as from the account that left it.
|
|
134
|
+
// The key `onePer: ['did']` derives, so the record for someone is the same one on every device.
|
|
135
|
+
const contactRecordKey = async (did) => (await contactsRuntime()).onePerKey(contactSchema.name, { did }, { onePer: contactSchema.rules.onePer });
|
|
136
|
+
async function contactsRuntime() {
|
|
137
|
+
if (!contactsSpaceId)
|
|
138
|
+
throw new Error('This app was not given your contacts. Connect to your account home again, and allow contacts.');
|
|
139
|
+
return ctx.runtime(contactsSpaceId);
|
|
140
|
+
}
|
|
141
|
+
/** What this account wrote in its contacts space, in a collection that `check` takes; none without one */
|
|
142
|
+
async function ownContactRecords(collection, check) {
|
|
143
|
+
if (!contactsSpaceId)
|
|
144
|
+
return [];
|
|
145
|
+
return ctx.ownRecords(await contactsRuntime(), { collection }, check);
|
|
146
|
+
}
|
|
147
|
+
/** Making and joining spaces for two needs a note good for every space — whole-account access. */
|
|
148
|
+
function requireEverywhere(what) {
|
|
149
|
+
// As a knock needs: `/account/write` for the whole account (spec 01 §8, 07).
|
|
150
|
+
if (ctx.narrowNote) {
|
|
151
|
+
throw new Error(`${what} makes or joins a space, which needs access to your whole account. Connect to your account home again, and ask for it.`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
async function contactRecords() {
|
|
155
|
+
const listed = await ownContactRecords(contactSchema.name, (record) => typeof record.body?.did === 'string' && typeof record.body.name === 'string');
|
|
156
|
+
// One record per person, under the key their DID gives.
|
|
157
|
+
const found = [];
|
|
158
|
+
for (const record of listed)
|
|
159
|
+
if (record.key === (await contactRecordKey(record.body.did)))
|
|
160
|
+
found.push(record);
|
|
161
|
+
return found;
|
|
162
|
+
}
|
|
163
|
+
/** Whoever the account blocked */
|
|
164
|
+
const blockedDids = async () => new Set((await contactRecords()).flatMap(({ body }) => (body.blocked === true ? [body.did] : [])));
|
|
165
|
+
function requireContactKeys() {
|
|
166
|
+
if (!contactKeys)
|
|
167
|
+
throw new Error("This app can't read contact requests. Connect to your account home again, and allow contacts.");
|
|
168
|
+
}
|
|
169
|
+
function contactView(record) {
|
|
170
|
+
const body = record.body;
|
|
171
|
+
return Object.freeze({
|
|
172
|
+
did: body.did,
|
|
173
|
+
name: body.name,
|
|
174
|
+
space: typeof body.space === 'string' ? body.space : null,
|
|
175
|
+
...(typeof body.note === 'string' ? { note: body.note } : {}),
|
|
176
|
+
blocked: body.blocked === true,
|
|
177
|
+
...(typeof body.username === 'string' ? { username: body.username } : {}),
|
|
178
|
+
updatedAt: record.updatedAt,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
async function writeContact(body) {
|
|
182
|
+
const open = await contactsRuntime();
|
|
183
|
+
await ensureDefined(open, contactSchema);
|
|
184
|
+
// One per person: writing again is the next version of their record.
|
|
185
|
+
return contactView(await open.put(contactSchema.name, body));
|
|
186
|
+
}
|
|
187
|
+
/** Whether an account holds a place in a space */
|
|
188
|
+
async function joined(spaceId, did) {
|
|
189
|
+
return (await (await ctx.runtime(spaceId)).access()).members.some((member) => member.did === did);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* The space an invite from `did` is for, its id and name, checked as joining
|
|
193
|
+
* would check it: signed by `did`, for the space whose constitution it
|
|
194
|
+
* carries. Null for anything less.
|
|
195
|
+
*/
|
|
196
|
+
async function invitedTo(invite, did) {
|
|
197
|
+
try {
|
|
198
|
+
const { space, signed, invite: secret, invitedBy } = parseSpaceInvite(invite);
|
|
199
|
+
if (invitedBy !== did || (await checkSpace(space)) !== null)
|
|
200
|
+
return null;
|
|
201
|
+
if ((await checkInvitation(signed, provider, secret)) !== null)
|
|
202
|
+
return null;
|
|
203
|
+
return { id: space.id, name: space.name };
|
|
204
|
+
}
|
|
205
|
+
catch {
|
|
206
|
+
return null;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
/** An invite of yours a contact used: closed, so nobody joins with it again, and deleted */
|
|
210
|
+
async function settleInvite(record, did) {
|
|
211
|
+
const { space, invite } = record.body;
|
|
212
|
+
if (!(await registry.get(space)) || !(await joined(space, did)))
|
|
213
|
+
return;
|
|
214
|
+
await ctx.spaces.closeInvite(space, invite).catch(() => { });
|
|
215
|
+
const pair = record.space;
|
|
216
|
+
await (await ctx.runtime(pair)).remove(record.key);
|
|
217
|
+
}
|
|
218
|
+
/** Leaves a space for two, unless another contact still names it */
|
|
219
|
+
async function leavePairSpace(spaceId, did) {
|
|
220
|
+
if (!spaceId || !(await registry.get(spaceId)))
|
|
221
|
+
return;
|
|
222
|
+
if ((await contactRecords()).some((record) => record.body.did !== did && record.body.space === spaceId))
|
|
223
|
+
return;
|
|
224
|
+
await ctx.spaces.leave(spaceId);
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* A knock left in a space as a contact request, opened — or null when it
|
|
228
|
+
* isn't one sealed to this account's contact key, by the account that wrote it.
|
|
229
|
+
*/
|
|
230
|
+
async function openMail(record) {
|
|
231
|
+
if (!config.contactKey ||
|
|
232
|
+
!contactKeys ||
|
|
233
|
+
!record?.verified ||
|
|
234
|
+
record.collection !== contactRequestSchema.name)
|
|
235
|
+
return null;
|
|
236
|
+
const body = record.body;
|
|
237
|
+
if (!isRecord(body) || body.to !== contactKeys.publicKey || typeof body.sealed !== 'string')
|
|
238
|
+
return null;
|
|
239
|
+
const opened = await openKnock([config.contactKey], body.sealed, provider);
|
|
240
|
+
if (!opened || opened.from !== record.root || opened.from === config.signer.did)
|
|
241
|
+
return null;
|
|
242
|
+
return opened;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* A space for two and a knock that invites someone to it, sealed to `to`:
|
|
246
|
+
* their inbox key or their contact key. The space waits for a carrier to
|
|
247
|
+
* hold it before the knock is made, so they can join with every device of
|
|
248
|
+
* this account away (`spaces.carried`).
|
|
249
|
+
*/
|
|
250
|
+
async function makePair(to, names, note) {
|
|
251
|
+
const pair = await ctx.spaces.create({
|
|
252
|
+
name: `${clip(names.mine, 64)} & ${clip(names.theirs, 64)}`,
|
|
253
|
+
visibility: 'private',
|
|
254
|
+
...team,
|
|
255
|
+
});
|
|
256
|
+
try {
|
|
257
|
+
const invite = await ctx.spaces.invite(pair.id, { role: 'editor' });
|
|
258
|
+
const { signed, invite: secret } = parseSpaceInvite(invite);
|
|
259
|
+
if (!secret)
|
|
260
|
+
throw new Error('The invite to the space for two opens no role');
|
|
261
|
+
const carried = await ctx.spaces.carried(pair.id);
|
|
262
|
+
const sealed = await sealKnock(to, { invite: signed, secret: base64UrlDecode(secret), name: names.mine, ...(note ? { note } : {}) }, ctx.looseSigner(), provider);
|
|
263
|
+
return { space: pair.id, invite, sealed, carried };
|
|
264
|
+
}
|
|
265
|
+
catch (error) {
|
|
266
|
+
await ctx.spaces.leave(pair.id).catch(() => { });
|
|
267
|
+
throw error;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
const contacts = Object.freeze({
|
|
271
|
+
async space() {
|
|
272
|
+
return contactsSpaceId;
|
|
273
|
+
},
|
|
274
|
+
async list() {
|
|
275
|
+
return (await contactRecords())
|
|
276
|
+
.map(contactView)
|
|
277
|
+
.sort((a, b) => a.name.localeCompare(b.name) || a.did.localeCompare(b.did));
|
|
278
|
+
},
|
|
279
|
+
async get(did) {
|
|
280
|
+
const record = (await contactRecords()).find((found) => found.body.did === did);
|
|
281
|
+
return record ? contactView(record) : null;
|
|
282
|
+
},
|
|
283
|
+
async put(contact) {
|
|
284
|
+
if (!contact.did.startsWith('did:'))
|
|
285
|
+
throw new Error('A contact needs their account DID');
|
|
286
|
+
const name = contact.name.trim().slice(0, 200);
|
|
287
|
+
if (!name)
|
|
288
|
+
throw new Error('A contact needs a name');
|
|
289
|
+
return writeContact({
|
|
290
|
+
did: contact.did,
|
|
291
|
+
name,
|
|
292
|
+
...(contact.space ? { space: contact.space } : {}),
|
|
293
|
+
...(contact.note ? { note: contact.note.slice(0, 2000) } : {}),
|
|
294
|
+
});
|
|
295
|
+
},
|
|
296
|
+
async remove(did) {
|
|
297
|
+
const found = await contacts.get(did);
|
|
298
|
+
if (!found)
|
|
299
|
+
return;
|
|
300
|
+
await leavePairSpace(found.space, did);
|
|
301
|
+
const key = await contactRecordKey(did);
|
|
302
|
+
if (key)
|
|
303
|
+
await (await contactsRuntime()).remove(key);
|
|
304
|
+
},
|
|
305
|
+
async block(did) {
|
|
306
|
+
const found = await contacts.get(did);
|
|
307
|
+
await leavePairSpace(found?.space ?? null, did);
|
|
308
|
+
await writeContact({
|
|
309
|
+
did,
|
|
310
|
+
name: found?.name ?? did,
|
|
311
|
+
blocked: true,
|
|
312
|
+
...(found?.note ? { note: found.note } : {}),
|
|
313
|
+
});
|
|
314
|
+
},
|
|
315
|
+
async ask(spaceId, did, options = {}) {
|
|
316
|
+
requireEverywhere('Adding a contact');
|
|
317
|
+
if (did === config.signer.did)
|
|
318
|
+
throw new Error('That is you');
|
|
319
|
+
if (!contactsSpaceId)
|
|
320
|
+
await contactsRuntime();
|
|
321
|
+
const shared = await ctx.runtime(spaceId);
|
|
322
|
+
const profiles = await shared.profiles();
|
|
323
|
+
const theirs = profiles.find((profile) => profile.did === did);
|
|
324
|
+
if (!theirs?.contactKey) {
|
|
325
|
+
throw new Error("They can't be asked here yet: their profile in this space has no contact key. It appears once they open the space in an up-to-date app.");
|
|
326
|
+
}
|
|
327
|
+
const mine = (await ownName()) ?? profiles.find((profile) => profile.did === config.signer.did)?.name ?? 'Me';
|
|
328
|
+
const note = options.note?.trim().slice(0, 2000);
|
|
329
|
+
const made = await makePair(theirs.contactKey, { mine, theirs: theirs.name }, note);
|
|
330
|
+
await ensureDefined(shared, contactRequestSchema);
|
|
331
|
+
await writeContact({ did, name: theirs.name, space: made.space });
|
|
332
|
+
const request = await shared.put(contactRequestSchema.name, {
|
|
333
|
+
to: theirs.contactKey,
|
|
334
|
+
sealed: made.sealed,
|
|
335
|
+
});
|
|
336
|
+
return { space: made.space, request: request.key, carried: made.carried };
|
|
337
|
+
},
|
|
338
|
+
async requests(spaceId) {
|
|
339
|
+
requireContactKeys();
|
|
340
|
+
const shared = await ctx.runtime(spaceId);
|
|
341
|
+
const blocked = await blockedDids();
|
|
342
|
+
const names = new Map((await shared.profiles()).map((profile) => [profile.did, profile.name]));
|
|
343
|
+
const found = [];
|
|
344
|
+
for (const record of await shared.list({ collection: contactRequestSchema.name })) {
|
|
345
|
+
const opened = await openMail(record);
|
|
346
|
+
if (!opened || blocked.has(opened.from))
|
|
347
|
+
continue;
|
|
348
|
+
// Already accepted, here or on another device.
|
|
349
|
+
if (await registry.get(opened.pairSpace))
|
|
350
|
+
continue;
|
|
351
|
+
found.push({
|
|
352
|
+
space: spaceId,
|
|
353
|
+
key: record.key,
|
|
354
|
+
from: opened.from,
|
|
355
|
+
name: names.get(opened.from) ?? null,
|
|
356
|
+
...(opened.note ? { note: opened.note } : {}),
|
|
357
|
+
pairSpace: opened.pairSpace,
|
|
358
|
+
createdAt: record.createdAt,
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
return found;
|
|
362
|
+
},
|
|
363
|
+
async accept(spaceId, requestKey) {
|
|
364
|
+
requireEverywhere('Accepting a contact request');
|
|
365
|
+
requireContactKeys();
|
|
366
|
+
const shared = await ctx.runtime(spaceId);
|
|
367
|
+
const opened = await openMail(await shared.get(requestKey));
|
|
368
|
+
if (!opened)
|
|
369
|
+
throw new Error('That contact request is gone, or is not for you.');
|
|
370
|
+
await ctx.spaces.join(opened.invite);
|
|
371
|
+
const name = (await shared.profiles()).find((profile) => profile.did === opened.from)?.name ??
|
|
372
|
+
(await contacts.get(opened.from))?.name ??
|
|
373
|
+
opened.name;
|
|
374
|
+
return writeContact({ did: opened.from, name, space: opened.pairSpace });
|
|
375
|
+
},
|
|
376
|
+
async others(did) {
|
|
377
|
+
const found = await contacts.get(did);
|
|
378
|
+
if (!found?.space || !(await registry.get(found.space)))
|
|
379
|
+
return [];
|
|
380
|
+
const open = await ctx.runtime(found.space);
|
|
381
|
+
const [{ members }, profiles, status] = await Promise.all([
|
|
382
|
+
open.access(),
|
|
383
|
+
open.profiles(),
|
|
384
|
+
open.status(),
|
|
385
|
+
]);
|
|
386
|
+
const seen = new Set([
|
|
387
|
+
...members.map((member) => member.did),
|
|
388
|
+
...profiles.map((profile) => profile.did),
|
|
389
|
+
...Object.values(status.accounts),
|
|
390
|
+
]);
|
|
391
|
+
return [...seen].filter((account) => account !== config.signer.did && account !== did).sort();
|
|
392
|
+
},
|
|
393
|
+
async invite(did, spaceId, options = {}) {
|
|
394
|
+
requireEverywhere('Inviting someone');
|
|
395
|
+
const contact = await contacts.get(did);
|
|
396
|
+
if (contact?.blocked)
|
|
397
|
+
throw new Error(`You blocked ${contact.name}`);
|
|
398
|
+
// Only someone whose account you have seen join your space for two: never whoever a name leads to.
|
|
399
|
+
if (!contact?.space || !(await registry.get(contact.space)) || !(await joined(contact.space, did)))
|
|
400
|
+
throw new Error(`${contact?.name ?? 'They'} haven't joined your space for two yet`);
|
|
401
|
+
if (!(await registry.get(spaceId)))
|
|
402
|
+
throw new Error("You don't hold that space");
|
|
403
|
+
const invite = await ctx.spaces.invite(spaceId, options.role ? { role: options.role } : {});
|
|
404
|
+
const pair = await ctx.runtime(contact.space);
|
|
405
|
+
await ensureDefined(pair, spaceInviteSchema);
|
|
406
|
+
// One per space: inviting again replaces the invite left before.
|
|
407
|
+
await pair.put(spaceInviteSchema.name, { space: spaceId, invite });
|
|
408
|
+
},
|
|
409
|
+
async invites() {
|
|
410
|
+
const held = new Set((await ctx.spaces.list()).map((summary) => summary.id));
|
|
411
|
+
const found = [];
|
|
412
|
+
for (const { body } of await contactRecords()) {
|
|
413
|
+
const { did, space: pairSpace, blocked } = body;
|
|
414
|
+
if (blocked || !pairSpace || !held.has(pairSpace))
|
|
415
|
+
continue;
|
|
416
|
+
const pair = await ctx.runtime(pairSpace);
|
|
417
|
+
for (const record of await pair.list({ collection: spaceInviteSchema.name })) {
|
|
418
|
+
if (!record.verified || typeof record.body?.invite !== 'string')
|
|
419
|
+
continue;
|
|
420
|
+
if (record.root === config.signer.did) {
|
|
421
|
+
await settleInvite(record, did).catch(() => { });
|
|
422
|
+
continue;
|
|
423
|
+
}
|
|
424
|
+
// Only the contact leaves invites here, and the invite itself says which space.
|
|
425
|
+
const space = record.root === did ? await invitedTo(record.body.invite, did) : null;
|
|
426
|
+
if (!space || space.id !== record.body.space || held.has(space.id))
|
|
427
|
+
continue;
|
|
428
|
+
found.push(Object.freeze({
|
|
429
|
+
from: did,
|
|
430
|
+
space: space.id,
|
|
431
|
+
name: space.name,
|
|
432
|
+
invite: record.body.invite,
|
|
433
|
+
pairSpace,
|
|
434
|
+
key: record.key,
|
|
435
|
+
createdAt: record.createdAt,
|
|
436
|
+
}));
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
return found.sort((a, b) => b.createdAt.localeCompare(a.createdAt));
|
|
440
|
+
},
|
|
441
|
+
async join(pairSpace, key) {
|
|
442
|
+
const contact = (await contactRecords()).find(({ body }) => body.space === pairSpace)?.body;
|
|
443
|
+
const record = await (await ctx.runtime(pairSpace)).get(key);
|
|
444
|
+
if (!contact || contact.blocked || record?.root !== contact.did || !record.verified)
|
|
445
|
+
throw new Error('That invite is gone: they may have taken it back');
|
|
446
|
+
// Its maker closes and deletes it once they see you there; until then it is hidden, as you hold the space.
|
|
447
|
+
return ctx.spaces.join(record.body.invite);
|
|
448
|
+
},
|
|
449
|
+
});
|
|
450
|
+
// ─── The inbox ─────────────────────────────────────────────────────
|
|
451
|
+
//
|
|
452
|
+
// Its settings are a `std.inbox` in the contacts space; its keys derive from
|
|
453
|
+
// the contact key and its `gen`, so every device with the contact key opens
|
|
454
|
+
// the same inbox. A knock you left is a `std.knock` until someone else joins
|
|
455
|
+
// the space for two: only the inbox key's holder could open the invite, so
|
|
456
|
+
// that is them. See `packages/core/src/inbox/inbox.ts`.
|
|
457
|
+
/** Knocks seen in this node's inbox, by id: opened (null when they didn't check out), and until when to keep them */
|
|
458
|
+
const knockCache = new Map();
|
|
459
|
+
/** Knocks that didn't check out, by id, and until when they are not opened again: one dated a little ahead may pass later */
|
|
460
|
+
const failed = new Map();
|
|
461
|
+
/** The inbox is the account's own, in its contacts space: only a key acting as the account opens one, as every peer checks */
|
|
462
|
+
const inboxAllowed = () => contactsSpaceId !== null && !ctx.narrowNote;
|
|
463
|
+
function requireContactKey(what) {
|
|
464
|
+
// The inbox is the account's: a key whose note doesn't grant `/account/write` never opens one or knocks.
|
|
465
|
+
if (!inboxAllowed())
|
|
466
|
+
throw new Error(`This key's note doesn't let it use your inbox. ${what} is the person's to do.`);
|
|
467
|
+
if (!config.contactKey)
|
|
468
|
+
throw new Error(`${what} needs your contact key. Connect to your account home again, and allow contacts.`);
|
|
469
|
+
return config.contactKey;
|
|
470
|
+
}
|
|
471
|
+
/** An inbox's keys, from the contact key and its gen */
|
|
472
|
+
async function inboxKeys(gen) {
|
|
473
|
+
const contactKey = requireContactKey('Your inbox');
|
|
474
|
+
const key = await deriveInboxKeyBytes(contactKey, gen);
|
|
475
|
+
const sign = await deriveInboxSignKeyBytes(contactKey, gen);
|
|
476
|
+
const signPublic = contactPublicKey(sign);
|
|
477
|
+
return { key, sign, publicKey: contactPublicKey(key), signPublic, topic: await inboxTopic(signPublic) };
|
|
478
|
+
}
|
|
479
|
+
/** The account's inbox: the newest `std.inbox` of the highest gen */
|
|
480
|
+
async function inboxRecord() {
|
|
481
|
+
const records = await ownContactRecords(inboxSchema.name, (record) => Number.isSafeInteger(record.body?.gen) && record.body.gen >= 0 && Array.isArray(record.body.places));
|
|
482
|
+
return (records.sort((a, b) => b.body.gen - a.body.gen || b.updatedAt.localeCompare(a.updatedAt))[0] ?? null);
|
|
483
|
+
}
|
|
484
|
+
async function inboxView(record) {
|
|
485
|
+
const body = record.body;
|
|
486
|
+
const keys = await inboxKeys(body.gen);
|
|
487
|
+
return Object.freeze({
|
|
488
|
+
gen: body.gen,
|
|
489
|
+
...(body.name ? { name: body.name } : {}),
|
|
490
|
+
key: keys.publicKey,
|
|
491
|
+
sign: keys.signPublic,
|
|
492
|
+
places: Object.freeze([...body.places]),
|
|
493
|
+
code: await encodeInbox(keys.sign, {
|
|
494
|
+
key: keys.publicKey,
|
|
495
|
+
sign: keys.signPublic,
|
|
496
|
+
gen: body.gen,
|
|
497
|
+
places: body.places,
|
|
498
|
+
...(body.name ? { name: body.name } : {}),
|
|
499
|
+
}, provider),
|
|
500
|
+
...(body.username ? { username: body.username } : {}),
|
|
501
|
+
...(body.usernameUntil ? { usernameUntil: body.usernameUntil } : {}),
|
|
502
|
+
updatedAt: record.updatedAt,
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
/** Writes the inbox's settings, checked the way a knocker will read its code */
|
|
506
|
+
async function writeInbox(body, current) {
|
|
507
|
+
const keys = await inboxKeys(body.gen);
|
|
508
|
+
const { gen, places, name } = body;
|
|
509
|
+
await encodeInbox(keys.sign, { gen, places, ...(name ? { name } : {}), key: keys.publicKey, sign: keys.signPublic }, provider);
|
|
510
|
+
const open = await contactsRuntime();
|
|
511
|
+
await ensureDefined(open, inboxSchema);
|
|
512
|
+
return inboxView(current ? await open.update(current.key, body) : await open.put(inboxSchema.name, body));
|
|
513
|
+
}
|
|
514
|
+
/** Clears knocks from every mailbox an inbox names that can purge, as its owner; how many did */
|
|
515
|
+
async function purgeInbox(body, ids) {
|
|
516
|
+
const keys = await inboxKeys(body.gen);
|
|
517
|
+
const done = await Promise.allSettled(body.places
|
|
518
|
+
.filter((place) => relayKind(place)?.can.purge)
|
|
519
|
+
.map((place) => mailbox.purge(place, keys.topic, keys.signPublic, ids, (nonce) => signPurge(keys.sign, keys.topic, nonce, ids))));
|
|
520
|
+
return done.filter((result) => result.status === 'fulfilled').length;
|
|
521
|
+
}
|
|
522
|
+
/** Forgets every knock seen: what the mailboxes held is gone */
|
|
523
|
+
function forgetKnocks() {
|
|
524
|
+
knockCache.clear();
|
|
525
|
+
failed.clear();
|
|
526
|
+
}
|
|
527
|
+
// ─── The username ──────────────────────────────────────────────────
|
|
528
|
+
//
|
|
529
|
+
// A name at a domain that leads to the inbox's code (spec 07 §9), claimed on
|
|
530
|
+
// the domain's name service (`packages/core/docs/usernames.md`). It is kept
|
|
531
|
+
// in `std.inbox`, so every device points it at the code when the code
|
|
532
|
+
// changes, and renews it before its year is up.
|
|
533
|
+
/** Renew a name this long before it lapses */
|
|
534
|
+
const RENEW_BEFORE_MS = 30 * DAY_MS;
|
|
535
|
+
/** When this node last looked whether the name needs renewing */
|
|
536
|
+
let renewChecked = 0;
|
|
537
|
+
/** Points the inbox's username at its code now, and keeps when it lapses */
|
|
538
|
+
/**
|
|
539
|
+
* The inbox's settings, with its username pointed at the code they make
|
|
540
|
+
* first: a name service that is down leaves everything as it was, never the
|
|
541
|
+
* name leading to an inbox nobody reads.
|
|
542
|
+
*/
|
|
543
|
+
async function named(body) {
|
|
544
|
+
if (!body.username)
|
|
545
|
+
return body;
|
|
546
|
+
const keys = await inboxKeys(body.gen);
|
|
547
|
+
const { gen, places, name } = body;
|
|
548
|
+
const code = await encodeInbox(keys.sign, { gen, places, ...(name ? { name } : {}), key: keys.publicKey, sign: keys.signPublic }, provider);
|
|
549
|
+
const until = await claimUsername(body.username, requireContactKey('Your username'), code);
|
|
550
|
+
return { ...body, usernameUntil: until };
|
|
551
|
+
}
|
|
552
|
+
/** Claims the name again when its year is nearly up; at most once an hour */
|
|
553
|
+
async function renewName() {
|
|
554
|
+
if (Date.now() - renewChecked < 3600_000)
|
|
555
|
+
return;
|
|
556
|
+
renewChecked = Date.now();
|
|
557
|
+
const current = await inboxRecord();
|
|
558
|
+
const { username, usernameUntil = 0 } = current?.body ?? {};
|
|
559
|
+
if (current && username && usernameUntil - Date.now() < RENEW_BEFORE_MS)
|
|
560
|
+
await writeInbox(await named(current.body), current);
|
|
561
|
+
}
|
|
562
|
+
const sentRecords = () => ownContactRecords(knockSchema.name, (record) => typeof record.body?.space === 'string' && typeof record.body.invite === 'string');
|
|
563
|
+
/**
|
|
564
|
+
* Knocks of yours: one someone joined becomes a contact, and its invite is
|
|
565
|
+
* closed; one nobody joined within the knock's life is let go, space and all.
|
|
566
|
+
*/
|
|
567
|
+
async function settleSent() {
|
|
568
|
+
for (const record of await sentRecords()) {
|
|
569
|
+
const { space, name, invite, username } = record.body;
|
|
570
|
+
if (!(await registry.get(space))) {
|
|
571
|
+
await (await contactsRuntime()).remove(record.key);
|
|
572
|
+
continue;
|
|
573
|
+
}
|
|
574
|
+
const open = await ctx.runtime(space);
|
|
575
|
+
// Only the holder of the inbox key could open the invite: whoever joined first is them.
|
|
576
|
+
const joiner = (await open.access()).members.find((member) => member.did !== config.signer.did)?.did;
|
|
577
|
+
if (joiner) {
|
|
578
|
+
// Whoever else the invite reached, nobody more joins with it.
|
|
579
|
+
await ctx.spaces.closeInvite(space, invite).catch(() => { });
|
|
580
|
+
const given = (await open.profiles()).find((profile) => profile.did === joiner)?.name;
|
|
581
|
+
await writeContact({ did: joiner, name: given ?? name, space, ...(username ? { username } : {}) });
|
|
582
|
+
await (await contactsRuntime()).remove(record.key);
|
|
583
|
+
}
|
|
584
|
+
else if (Date.now() - Date.parse(record.createdAt) > KNOCK_TTL_SECONDS * 1000 + DAY_MS) {
|
|
585
|
+
await ctx.spaces.leave(space).catch(() => { });
|
|
586
|
+
await (await contactsRuntime()).remove(record.key);
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
/** What the mailboxes of this node's inbox hold now, opened and cached */
|
|
591
|
+
async function readKnocks() {
|
|
592
|
+
const now = Date.now();
|
|
593
|
+
for (const [id, cached] of knockCache)
|
|
594
|
+
if (cached.until <= now)
|
|
595
|
+
knockCache.delete(id);
|
|
596
|
+
const record = await inboxRecord();
|
|
597
|
+
if (!record)
|
|
598
|
+
return [];
|
|
599
|
+
const { gen, places } = record.body;
|
|
600
|
+
const keys = await inboxKeys(gen);
|
|
601
|
+
// Every mailbox in full: an inbox holds 64 knocks at most, and one cleared on another device goes here too.
|
|
602
|
+
const held = await knocksAt(places, keys.topic);
|
|
603
|
+
const found = [];
|
|
604
|
+
for (const [id, blob] of held) {
|
|
605
|
+
const opened = knockCache.get(id)?.opened ?? (await openOnce(id, blob, keys.key, now));
|
|
606
|
+
if (opened)
|
|
607
|
+
found.push({ id, opened });
|
|
608
|
+
}
|
|
609
|
+
return found;
|
|
610
|
+
}
|
|
611
|
+
/** What the mailboxes hold under a topic, by knock id */
|
|
612
|
+
async function knocksAt(places, topic) {
|
|
613
|
+
const held = new Map();
|
|
614
|
+
const fetched = await Promise.allSettled(places.map((place) => mailbox.fetch(place, topic)));
|
|
615
|
+
for (const result of fetched) {
|
|
616
|
+
if (result.status !== 'fulfilled')
|
|
617
|
+
continue;
|
|
618
|
+
// A relay's id is only its word: a knock is filed under the hash of what it is.
|
|
619
|
+
for (const item of result.value)
|
|
620
|
+
held.set(await knockId(item.blob), item.blob);
|
|
621
|
+
}
|
|
622
|
+
return held;
|
|
623
|
+
}
|
|
624
|
+
/** Opens a knock; one that failed waits a while before it is tried again */
|
|
625
|
+
async function openOnce(id, blob, key, now) {
|
|
626
|
+
if ((failed.get(id) ?? 0) > now)
|
|
627
|
+
return null;
|
|
628
|
+
const opened = await openKnock([key], blob, provider);
|
|
629
|
+
if (opened)
|
|
630
|
+
knockCache.set(id, { opened, until: opened.at + KNOCK_TTL_SECONDS * 1000 });
|
|
631
|
+
else
|
|
632
|
+
failed.set(id, now + 15 * 60_000);
|
|
633
|
+
return opened;
|
|
634
|
+
}
|
|
635
|
+
const inbox = Object.freeze({
|
|
636
|
+
async get() {
|
|
637
|
+
if (!config.contactKey || !inboxAllowed())
|
|
638
|
+
return null;
|
|
639
|
+
const record = await inboxRecord();
|
|
640
|
+
return record ? inboxView(record) : null;
|
|
641
|
+
},
|
|
642
|
+
async open(options = {}) {
|
|
643
|
+
requireContactKey('Opening your inbox');
|
|
644
|
+
if (!contactsSpaceId)
|
|
645
|
+
await contactsRuntime();
|
|
646
|
+
const current = await inboxRecord();
|
|
647
|
+
const places = [...(options.places ?? current?.body?.places ?? usableRelays(config.network))].slice(0, MAX_INBOX_PLACES);
|
|
648
|
+
if (places.length === 0)
|
|
649
|
+
throw new Error('An inbox needs a mailbox to hold its knocks, and this node has none.');
|
|
650
|
+
const name = clip((options.name ?? current?.body?.name ?? (await ownName()) ?? '').trim(), 64);
|
|
651
|
+
const { username, usernameUntil } = current?.body ?? {};
|
|
652
|
+
const next = {
|
|
653
|
+
gen: current?.body?.gen ?? 0,
|
|
654
|
+
places,
|
|
655
|
+
...(name ? { name } : {}),
|
|
656
|
+
...(username ? { username, ...(usernameUntil ? { usernameUntil } : {}) } : {}),
|
|
657
|
+
};
|
|
658
|
+
// A code that says something new: the name leads to it before anything is written.
|
|
659
|
+
const said = (body) => JSON.stringify([body?.places, body?.name ?? null]);
|
|
660
|
+
return writeInbox(current && said(current.body) !== said(next) ? await named(next) : next, current);
|
|
661
|
+
},
|
|
662
|
+
async rotate() {
|
|
663
|
+
requireContactKey('Replacing your inbox');
|
|
664
|
+
const current = await inboxRecord();
|
|
665
|
+
if (!current)
|
|
666
|
+
return inbox.open();
|
|
667
|
+
const next = await named({ ...current.body, gen: current.body.gen + 1 });
|
|
668
|
+
// What waits in the old one goes with it.
|
|
669
|
+
await purgeInbox(current.body, null).catch(() => 0);
|
|
670
|
+
forgetKnocks();
|
|
671
|
+
return writeInbox(next, current);
|
|
672
|
+
},
|
|
673
|
+
async claim(username) {
|
|
674
|
+
requireEverywhere('Claiming a username');
|
|
675
|
+
const key = requireContactKey('Claiming a username');
|
|
676
|
+
const parsed = parseUsername(username);
|
|
677
|
+
if (!parsed)
|
|
678
|
+
throw new Error('That is not a username, like leif@minca.social');
|
|
679
|
+
const shown = formatUsername(parsed);
|
|
680
|
+
const view = (await inbox.get()) ?? (await inbox.open());
|
|
681
|
+
const until = await claimUsername(shown, key, view.code);
|
|
682
|
+
const current = await inboxRecord();
|
|
683
|
+
if (!current)
|
|
684
|
+
throw new Error('Your inbox is not open');
|
|
685
|
+
const previous = current.body.username;
|
|
686
|
+
const written = await writeInbox({ ...current.body, username: shown, usernameUntil: until }, current);
|
|
687
|
+
// One name at a time: the one before leads nowhere now.
|
|
688
|
+
if (previous && previous !== shown)
|
|
689
|
+
await claimUsername(previous, key, null).catch(() => 0);
|
|
690
|
+
return written;
|
|
691
|
+
},
|
|
692
|
+
async release() {
|
|
693
|
+
requireEverywhere('Giving up a username');
|
|
694
|
+
const key = requireContactKey('Giving up a username');
|
|
695
|
+
const current = await inboxRecord();
|
|
696
|
+
const username = current?.body?.username;
|
|
697
|
+
if (!current || !username)
|
|
698
|
+
throw new Error('You have no username');
|
|
699
|
+
await claimUsername(username, key, null);
|
|
700
|
+
const { gen, places, name } = current.body;
|
|
701
|
+
return writeInbox({ gen, places, ...(name ? { name } : {}) }, current);
|
|
702
|
+
},
|
|
703
|
+
async clear() {
|
|
704
|
+
requireContactKey('Clearing your inbox');
|
|
705
|
+
const current = await inboxRecord();
|
|
706
|
+
if (!current)
|
|
707
|
+
throw new Error('Your inbox is not open');
|
|
708
|
+
if ((await purgeInbox(current.body, null)) === 0)
|
|
709
|
+
throw new Error("None of your inbox's mailboxes could be reached and cleared.");
|
|
710
|
+
forgetKnocks();
|
|
711
|
+
},
|
|
712
|
+
async knock(target, options = {}) {
|
|
713
|
+
requireContactKey('Knocking');
|
|
714
|
+
requireEverywhere('Knocking');
|
|
715
|
+
const username = parseUsername(target);
|
|
716
|
+
const code = username ? (await resolveUsername(target, provider)).code : target;
|
|
717
|
+
const theirs = await readInboxCode(code, provider);
|
|
718
|
+
if ((await inbox.get())?.key === theirs.key)
|
|
719
|
+
throw new Error('That is your own inbox');
|
|
720
|
+
if (!contactsSpaceId)
|
|
721
|
+
await contactsRuntime();
|
|
722
|
+
const mine = (await ownName()) ?? 'Someone';
|
|
723
|
+
const name = theirs.name ?? 'Contact';
|
|
724
|
+
const made = await makePair(theirs.key, { mine, theirs: name }, options.note);
|
|
725
|
+
const topic = await inboxTopic(theirs.sign);
|
|
726
|
+
const left = await Promise.allSettled(theirs.places.map((place) => mailbox.drop(place, topic, made.sealed, KNOCK_TTL_SECONDS)));
|
|
727
|
+
if (!left.some((result) => result.status === 'fulfilled')) {
|
|
728
|
+
await ctx.spaces.leave(made.space).catch(() => { });
|
|
729
|
+
const reasons = left
|
|
730
|
+
.map((result) => (result.status === 'rejected' ? errorText(result.reason) : ''))
|
|
731
|
+
.filter(Boolean);
|
|
732
|
+
throw new Error(`None of their inbox's mailboxes took the knock. ${reasons.join('; ')}`);
|
|
733
|
+
}
|
|
734
|
+
const open = await contactsRuntime();
|
|
735
|
+
await ensureDefined(open, knockSchema);
|
|
736
|
+
await open.put(knockSchema.name, {
|
|
737
|
+
space: made.space,
|
|
738
|
+
name,
|
|
739
|
+
invite: made.invite,
|
|
740
|
+
...(username ? { username: formatUsername(username) } : {}),
|
|
741
|
+
});
|
|
742
|
+
return { space: made.space, carried: made.carried };
|
|
743
|
+
},
|
|
744
|
+
async knocks() {
|
|
745
|
+
requireContactKey('Reading knocks');
|
|
746
|
+
await settleSent().catch(() => { });
|
|
747
|
+
await renewName().catch(() => { });
|
|
748
|
+
const blocked = await blockedDids();
|
|
749
|
+
const found = [];
|
|
750
|
+
for (const { id, opened } of await readKnocks()) {
|
|
751
|
+
if (opened.from === config.signer.did || blocked.has(opened.from))
|
|
752
|
+
continue;
|
|
753
|
+
// Already accepted, here or on another device.
|
|
754
|
+
if (await registry.get(opened.pairSpace))
|
|
755
|
+
continue;
|
|
756
|
+
found.push(Object.freeze({
|
|
757
|
+
id,
|
|
758
|
+
from: opened.from,
|
|
759
|
+
name: opened.name,
|
|
760
|
+
...(opened.note ? { note: opened.note } : {}),
|
|
761
|
+
pairSpace: opened.pairSpace,
|
|
762
|
+
at: new Date(opened.at).toISOString(),
|
|
763
|
+
}));
|
|
764
|
+
}
|
|
765
|
+
return found.sort((a, b) => b.at.localeCompare(a.at));
|
|
766
|
+
},
|
|
767
|
+
async sent() {
|
|
768
|
+
await settleSent().catch(() => { });
|
|
769
|
+
return (await sentRecords()).map((record) => Object.freeze({
|
|
770
|
+
space: record.body.space,
|
|
771
|
+
name: record.body.name,
|
|
772
|
+
...(record.body.username ? { username: record.body.username } : {}),
|
|
773
|
+
at: record.createdAt,
|
|
774
|
+
}));
|
|
775
|
+
},
|
|
776
|
+
async accept(id) {
|
|
777
|
+
requireContactKey('Accepting a knock');
|
|
778
|
+
requireEverywhere('Accepting a knock');
|
|
779
|
+
if (!knockCache.get(id)?.opened)
|
|
780
|
+
await readKnocks();
|
|
781
|
+
const knocked = knockCache.get(id)?.opened;
|
|
782
|
+
if (!knocked)
|
|
783
|
+
throw new Error('That knock is gone: it expired, or your inbox was cleared or replaced.');
|
|
784
|
+
await ctx.spaces.join(knocked.invite);
|
|
785
|
+
const known = await contacts.get(knocked.from);
|
|
786
|
+
const contact = await writeContact({
|
|
787
|
+
did: knocked.from,
|
|
788
|
+
name: known?.name ?? knocked.name,
|
|
789
|
+
space: knocked.pairSpace,
|
|
790
|
+
});
|
|
791
|
+
// Done with: nobody needs it in the mailboxes any more.
|
|
792
|
+
const current = await inboxRecord();
|
|
793
|
+
if (current)
|
|
794
|
+
await purgeInbox(current.body, [id]).catch(() => 0);
|
|
795
|
+
knockCache.delete(id);
|
|
796
|
+
return contact;
|
|
797
|
+
},
|
|
798
|
+
async dismiss(id) {
|
|
799
|
+
requireContactKey('Dismissing a knock');
|
|
800
|
+
const current = await inboxRecord();
|
|
801
|
+
if (current)
|
|
802
|
+
await purgeInbox(current.body, [id]);
|
|
803
|
+
knockCache.delete(id);
|
|
804
|
+
},
|
|
805
|
+
});
|
|
806
|
+
return Object.freeze({ account, contacts, inbox, publishProfile, publishProfileToOpenSpaces });
|
|
807
|
+
}
|
|
808
|
+
//# sourceMappingURL=node-contacts.js.map
|