@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
package/dist/network/mesh.js
CHANGED
|
@@ -1,3 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One set of connections for every space a node has open.
|
|
3
|
+
*
|
|
4
|
+
* A node holds one socket per relay and one WebRTC connection per peer, however
|
|
5
|
+
* many spaces the two share. Each space is a room: it joins the room on the
|
|
6
|
+
* relays, and on every connection proves itself separately (`peer-auth.ts`)
|
|
7
|
+
* before a byte of it crosses. A peer you share one space with is a peer only
|
|
8
|
+
* in that one.
|
|
9
|
+
*
|
|
10
|
+
* Everything on a connection is a JSON frame `{ room?, type, from, payload }`.
|
|
11
|
+
* The offers peers carry for each other (`introductions.ts`) carry no room of
|
|
12
|
+
* their own beyond the signal's.
|
|
13
|
+
*
|
|
14
|
+
* ```
|
|
15
|
+
* A → B { room, __auth-hello, { nonce: Nₐ } } either side, once it knows the other is in the room
|
|
16
|
+
* B → A { room, __auth-hello, { nonce: N_b } }
|
|
17
|
+
* A → B { room, __auth-proof, proof over N_b } (none in a room without auth)
|
|
18
|
+
* B → A { room, __auth-proof, proof over Nₐ }
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* A connection that ends up in no room is closed.
|
|
22
|
+
*/
|
|
23
|
+
import { getOrAdd } from '../utils/map.js';
|
|
1
24
|
import { utf8Encode, utf8Decode } from '../utils/encoding.js';
|
|
2
25
|
import { createEmitter } from '../utils/events.js';
|
|
3
26
|
import { isObject } from '../utils/guards.js';
|
|
@@ -11,23 +34,20 @@ const ICE_REFRESH_MS = 10 * 60_000;
|
|
|
11
34
|
/** How long to wait for them before going ahead with what there is */
|
|
12
35
|
const ICE_WAIT_MS = 1500;
|
|
13
36
|
/**
|
|
14
|
-
* How long a connection has to open before it is given up
|
|
15
|
-
*
|
|
16
|
-
* marked as tried is not offered to again, so without this it is lost until
|
|
17
|
-
* one side restarts. Once given up, the peer's next hello brings the next
|
|
18
|
-
* offer. Each try waits twice as long, up to the cap.
|
|
37
|
+
* How long a connection has to open before it is given up, doubling with each
|
|
38
|
+
* try up to the cap. An unanswered offer never fails on its own.
|
|
19
39
|
*/
|
|
20
40
|
const CONNECT_TIMEOUT_MS = 20_000;
|
|
21
41
|
const MAX_CONNECT_TIMEOUT_MS = 5 * 60_000;
|
|
22
42
|
/** A relayed signal older or newer than this is a replay, or a clock too far off */
|
|
23
43
|
const SIGNAL_WINDOW_MS = 120_000;
|
|
24
|
-
/** Signals from one origin a room acts on within that window
|
|
44
|
+
/** Signals from one origin a room acts on within that window */
|
|
25
45
|
const MAX_SIGNALS_ACTED = 256;
|
|
26
|
-
/** Origins whose times are held at once, across rooms
|
|
46
|
+
/** Origins whose times are held at once, across rooms */
|
|
27
47
|
const MAX_ORIGINS_HELD = 1024;
|
|
28
48
|
/** A relayed description longer than this is not taken: one with its candidates is a few KB */
|
|
29
49
|
const MAX_SDP_CHARS = 32_000;
|
|
30
|
-
/** Peers whose failed tries are remembered
|
|
50
|
+
/** Peers whose failed tries are remembered */
|
|
31
51
|
const MAX_TRIED = 512;
|
|
32
52
|
export function createMesh(config) {
|
|
33
53
|
const { did } = config;
|
|
@@ -35,36 +55,32 @@ export function createMesh(config) {
|
|
|
35
55
|
const configuredIce = config.iceServers ?? DEFAULT_ICE_SERVERS;
|
|
36
56
|
let relayIce = null;
|
|
37
57
|
let iceAskedAt = 0;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
iceAskedAt = 0;
|
|
41
|
-
changed();
|
|
42
|
-
});
|
|
43
|
-
const currentIce = () => relayIce && relayIce.expiresAt > Date.now() ? [...configuredIce, ...relayIce.servers] : configuredIce;
|
|
58
|
+
const hasTurn = () => relayIce !== null && relayIce.expiresAt > Date.now();
|
|
59
|
+
const currentIce = () => relayIce && hasTurn() ? [...configuredIce, ...relayIce.servers] : configuredIce;
|
|
44
60
|
const transport = config.createTransport?.(currentIce) ?? createRTCTransport({ iceServers: currentIce });
|
|
45
61
|
const introduce = config.introductions !== false;
|
|
46
62
|
const authTimeoutMs = config.authTimeoutMs ?? 10_000;
|
|
63
|
+
const provider = createP256Provider();
|
|
47
64
|
const rooms = new Map();
|
|
48
65
|
/** Relays each room's space names, for its room only */
|
|
49
66
|
const roomRelays = new Map();
|
|
50
67
|
/** Connections that are open */
|
|
51
68
|
const links = new Set();
|
|
52
|
-
/** Peers a connection has been started with, so
|
|
69
|
+
/** Peers a connection has been started with, so it is not opened twice */
|
|
53
70
|
const attempted = new Set();
|
|
54
71
|
/** Rooms to greet a peer in once its connection opens */
|
|
55
72
|
const expected = new Map();
|
|
56
|
-
/**
|
|
73
|
+
/** Open connections waiting to be put to use in some room, or closed */
|
|
57
74
|
const idle = new Map();
|
|
58
75
|
/** Connections started and not yet open, each with the timer that gives up on it */
|
|
59
76
|
const pending = new Map();
|
|
60
|
-
/** Failed tries per peer
|
|
77
|
+
/** Failed tries per peer; forgotten once a connection opens */
|
|
61
78
|
const tries = new Map();
|
|
62
79
|
const seenSignals = createSeenSignals();
|
|
63
|
-
|
|
80
|
+
/** The times of signals acted on, by `room origin`, within the window */
|
|
81
|
+
const actedOn = new Map();
|
|
64
82
|
/** When this node last sent a signal over the mesh: each later than the one before */
|
|
65
83
|
let introducedAt = 0;
|
|
66
|
-
/** The times of signals acted on from each origin in each room, within the two minutes, by `room origin` */
|
|
67
|
-
const actedOn = new Map();
|
|
68
84
|
let started = null;
|
|
69
85
|
const changes = new Set();
|
|
70
86
|
const changed = () => {
|
|
@@ -72,37 +88,15 @@ export function createMesh(config) {
|
|
|
72
88
|
listener();
|
|
73
89
|
};
|
|
74
90
|
signaling.on('status', changed);
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
if (held)
|
|
79
|
-
clearTimeout(held.timer);
|
|
80
|
-
const tried = tries.get(peer) ?? 0;
|
|
81
|
-
const wait = Math.min(CONNECT_TIMEOUT_MS * 2 ** tried, MAX_CONNECT_TIMEOUT_MS);
|
|
82
|
-
const timer = setTimeout(() => {
|
|
83
|
-
pending.delete(peer);
|
|
84
|
-
if (links.has(peer))
|
|
85
|
-
return;
|
|
86
|
-
tries.delete(peer);
|
|
87
|
-
tries.set(peer, tried + 1);
|
|
88
|
-
// A map iterates in insertion order: the first is the oldest.
|
|
89
|
-
if (tries.size > MAX_TRIED)
|
|
90
|
-
tries.delete(tries.keys().next().value ?? peer);
|
|
91
|
-
transport.close(peer);
|
|
92
|
-
attempted.delete(peer);
|
|
93
|
-
expected.delete(peer);
|
|
94
|
-
changed();
|
|
95
|
-
}, wait);
|
|
96
|
-
pending.set(peer, { since: held?.since ?? Date.now(), tries: tried, timer });
|
|
91
|
+
signaling.on('ice', (servers, expiresAt) => {
|
|
92
|
+
relayIce = { servers, expiresAt };
|
|
93
|
+
iceAskedAt = 0;
|
|
97
94
|
changed();
|
|
98
|
-
};
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
if (pending.delete(peer))
|
|
104
|
-
changed();
|
|
105
|
-
};
|
|
95
|
+
});
|
|
96
|
+
const roomList = () => [...rooms.values()];
|
|
97
|
+
/** Peers proved in at least one room: the only ones anything but a handshake is taken from */
|
|
98
|
+
const isAdmitted = (peer) => roomList().some((room) => room.peers.has(peer));
|
|
99
|
+
const isInUse = (peer) => roomList().some((room) => room.peers.has(peer) || room.handshakes.has(peer));
|
|
106
100
|
const fail = (error) => {
|
|
107
101
|
const err = error instanceof Error ? error : new Error(String(error));
|
|
108
102
|
for (const room of rooms.values())
|
|
@@ -113,13 +107,37 @@ export function createMesh(config) {
|
|
|
113
107
|
transport.send(peer, utf8Encode(JSON.stringify({ ...frame, from: did })));
|
|
114
108
|
}
|
|
115
109
|
catch {
|
|
116
|
-
//
|
|
117
|
-
// disconnect event will tidy up.
|
|
110
|
+
// Closed since it was listed; the disconnect tidies up.
|
|
118
111
|
}
|
|
119
112
|
};
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
113
|
+
// ─── Connection attempts ────────────────────────────────────────────
|
|
114
|
+
/** Gives an attempt a deadline, after which the peer is forgotten until heard of again. */
|
|
115
|
+
const watch = (peer) => {
|
|
116
|
+
const held = pending.get(peer);
|
|
117
|
+
if (held)
|
|
118
|
+
clearTimeout(held.timer);
|
|
119
|
+
const tried = tries.get(peer) ?? 0;
|
|
120
|
+
const wait = Math.min(CONNECT_TIMEOUT_MS * 2 ** tried, MAX_CONNECT_TIMEOUT_MS);
|
|
121
|
+
const timer = setTimeout(() => giveUp(peer, tried), wait);
|
|
122
|
+
pending.set(peer, { since: held?.since ?? Date.now(), tries: tried, timer });
|
|
123
|
+
changed();
|
|
124
|
+
};
|
|
125
|
+
const giveUp = (peer, tried) => {
|
|
126
|
+
pending.delete(peer);
|
|
127
|
+
if (links.has(peer))
|
|
128
|
+
return;
|
|
129
|
+
setNewest(tries, peer, tried + 1, MAX_TRIED);
|
|
130
|
+
transport.close(peer);
|
|
131
|
+
attempted.delete(peer);
|
|
132
|
+
expected.delete(peer);
|
|
133
|
+
changed();
|
|
134
|
+
};
|
|
135
|
+
const unwatch = (peer) => {
|
|
136
|
+
clearTimeout(pending.get(peer)?.timer);
|
|
137
|
+
if (pending.delete(peer))
|
|
138
|
+
changed();
|
|
139
|
+
};
|
|
140
|
+
/** Forgets a connection, closed by either side. */
|
|
123
141
|
const lost = (peer) => {
|
|
124
142
|
clearTimeout(idle.get(peer));
|
|
125
143
|
idle.delete(peer);
|
|
@@ -131,11 +149,8 @@ export function createMesh(config) {
|
|
|
131
149
|
for (const room of rooms.values())
|
|
132
150
|
drop(room, peer);
|
|
133
151
|
};
|
|
134
|
-
/** Closes a connection that no room has a use for. */
|
|
135
152
|
const closeIfIdle = (peer) => {
|
|
136
|
-
if (!links.has(peer))
|
|
137
|
-
return;
|
|
138
|
-
if ([...rooms.values()].some((room) => room.peers.has(peer) || room.handshakes.has(peer)))
|
|
153
|
+
if (!links.has(peer) || isInUse(peer))
|
|
139
154
|
return;
|
|
140
155
|
transport.close(peer);
|
|
141
156
|
// Closing it here is not always reported back as a disconnect.
|
|
@@ -143,9 +158,7 @@ export function createMesh(config) {
|
|
|
143
158
|
};
|
|
144
159
|
// ─── Proving, per room ──────────────────────────────────────────────
|
|
145
160
|
const endHandshake = (room, peer) => {
|
|
146
|
-
|
|
147
|
-
if (handshake)
|
|
148
|
-
clearTimeout(handshake.timer);
|
|
161
|
+
clearTimeout(room.handshakes.get(peer)?.timer);
|
|
149
162
|
room.handshakes.delete(peer);
|
|
150
163
|
};
|
|
151
164
|
const refuse = (room, peer) => {
|
|
@@ -157,50 +170,60 @@ export function createMesh(config) {
|
|
|
157
170
|
const room = rooms.get(name);
|
|
158
171
|
if (!room || room.peers.has(peer))
|
|
159
172
|
return null;
|
|
160
|
-
|
|
161
|
-
if (
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}
|
|
173
|
+
const held = room.handshakes.get(peer);
|
|
174
|
+
if (held)
|
|
175
|
+
return held;
|
|
176
|
+
const handshake = {
|
|
177
|
+
nonce: peerNonce(),
|
|
178
|
+
proved: false,
|
|
179
|
+
verified: room.auth === null,
|
|
180
|
+
timer: setTimeout(() => refuse(room, peer), authTimeoutMs),
|
|
181
|
+
};
|
|
182
|
+
room.handshakes.set(peer, handshake);
|
|
183
|
+
sendFrame(peer, { room: name, type: AUTH_HELLO_MESSAGE, payload: { nonce: handshake.nonce } });
|
|
171
184
|
return handshake;
|
|
172
185
|
};
|
|
186
|
+
/** Their hello: prove ourselves over their nonce. */
|
|
187
|
+
const onHello = async (name, room, peer, payload) => {
|
|
188
|
+
const handshake = greet(name, peer);
|
|
189
|
+
const nonce = isObject(payload) ? payload.nonce : undefined;
|
|
190
|
+
if (!handshake || handshake.proved || typeof nonce !== 'string')
|
|
191
|
+
return;
|
|
192
|
+
handshake.proved = true;
|
|
193
|
+
if (!room.auth)
|
|
194
|
+
return;
|
|
195
|
+
const proof = await room.auth.prove(peer, nonce, transport.binding?.(peer) ?? null);
|
|
196
|
+
sendFrame(peer, { room: name, type: AUTH_PROOF_MESSAGE, payload: proof });
|
|
197
|
+
};
|
|
198
|
+
/** Their proof: check it over our nonce */
|
|
199
|
+
const onProof = async (room, peer, payload) => {
|
|
200
|
+
const handshake = room.handshakes.get(peer);
|
|
201
|
+
if (!handshake || handshake.verified || !room.auth)
|
|
202
|
+
return 'ignored';
|
|
203
|
+
const binding = transport.binding?.(peer) ?? null;
|
|
204
|
+
if (!(await room.auth.check(peer, handshake.nonce, binding, payload)))
|
|
205
|
+
return 'refused';
|
|
206
|
+
handshake.verified = true;
|
|
207
|
+
return 'verified';
|
|
208
|
+
};
|
|
173
209
|
const onHandshake = async (name, peer, type, payload) => {
|
|
174
210
|
const room = rooms.get(name);
|
|
175
211
|
if (!room)
|
|
176
212
|
return;
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
const handshake = greet(name, peer);
|
|
180
|
-
const nonce = isObject(payload) ? payload.nonce : undefined;
|
|
181
|
-
if (!handshake || handshake.proved || typeof nonce !== 'string')
|
|
182
|
-
return;
|
|
183
|
-
handshake.proved = true;
|
|
184
|
-
if (room.auth)
|
|
185
|
-
sendFrame(peer, {
|
|
186
|
-
room: name,
|
|
187
|
-
type: AUTH_PROOF_MESSAGE,
|
|
188
|
-
payload: await room.auth.prove(peer, nonce, binding),
|
|
189
|
-
});
|
|
190
|
-
}
|
|
213
|
+
if (type === AUTH_HELLO_MESSAGE)
|
|
214
|
+
await onHello(name, room, peer, payload);
|
|
191
215
|
else {
|
|
192
|
-
const
|
|
193
|
-
if (
|
|
216
|
+
const outcome = await onProof(room, peer, payload);
|
|
217
|
+
if (outcome === 'ignored')
|
|
194
218
|
return;
|
|
195
|
-
if (
|
|
219
|
+
if (outcome === 'refused')
|
|
196
220
|
return refuse(room, peer);
|
|
197
|
-
handshake.verified = true;
|
|
198
221
|
}
|
|
199
222
|
const handshake = room.handshakes.get(peer);
|
|
200
|
-
if (handshake?.proved
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
223
|
+
if (!handshake?.proved || !handshake.verified || rooms.get(name) !== room)
|
|
224
|
+
return;
|
|
225
|
+
endHandshake(room, peer);
|
|
226
|
+
admit(name, room, peer);
|
|
204
227
|
};
|
|
205
228
|
/** A connection becomes a peer in a room: announced, and introduced to the room's others. */
|
|
206
229
|
const admit = (name, room, peer) => {
|
|
@@ -210,8 +233,7 @@ export function createMesh(config) {
|
|
|
210
233
|
changed();
|
|
211
234
|
if (!introduce)
|
|
212
235
|
return;
|
|
213
|
-
//
|
|
214
|
-
// side with the higher identifier waiting for an offer nobody will send.
|
|
236
|
+
// Both ways: told only the newcomer, the higher DID would wait for an offer nobody sends.
|
|
215
237
|
const others = [...room.peers.keys()].filter((other) => other !== peer);
|
|
216
238
|
if (others.length === 0)
|
|
217
239
|
return;
|
|
@@ -222,42 +244,33 @@ export function createMesh(config) {
|
|
|
222
244
|
const drop = (room, peer) => {
|
|
223
245
|
endHandshake(room, peer);
|
|
224
246
|
const info = room.peers.get(peer);
|
|
225
|
-
if (info
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
247
|
+
if (!info || !room.peers.delete(peer))
|
|
248
|
+
return;
|
|
249
|
+
room.events.emit('peer-disconnected', info);
|
|
250
|
+
changed();
|
|
229
251
|
};
|
|
230
252
|
// ─── Connecting ─────────────────────────────────────────────────────
|
|
231
253
|
//
|
|
232
|
-
// A relay gets you your first connection
|
|
233
|
-
//
|
|
234
|
-
|
|
235
|
-
/** Pushes somebody's signaling out to the room's other peers, skipping where it came from. */
|
|
254
|
+
// A relay gets you your first connection; after that, the peers you reach
|
|
255
|
+
// carry offers to the ones you don't.
|
|
256
|
+
/** Pushes a signal out to the room's other peers, skipping where it came from. */
|
|
236
257
|
const floodSignal = (name, signal, except) => {
|
|
237
|
-
for (const peer of rooms.get(name)?.peers.keys() ?? [])
|
|
258
|
+
for (const peer of rooms.get(name)?.peers.keys() ?? [])
|
|
238
259
|
if (peer !== except)
|
|
239
260
|
sendFrame(peer, { room: name, type: SIGNAL_MESSAGE, payload: signal });
|
|
240
|
-
}
|
|
241
261
|
};
|
|
242
|
-
/** Through the room's peers
|
|
262
|
+
/** Through the room's peers, signed by this node so nobody passing it on can change it */
|
|
243
263
|
const throughMesh = (target, name) => (kind, data) => {
|
|
244
264
|
if (!isObject(data) || typeof data.sdp !== 'string')
|
|
245
265
|
return;
|
|
246
|
-
const at = (introducedAt = Math.max(Date.now(), introducedAt + 1));
|
|
247
266
|
const { sdp } = data;
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
kind,
|
|
253
|
-
data: { type: kind, sdp },
|
|
254
|
-
at,
|
|
255
|
-
sig,
|
|
256
|
-
hops: MAX_HOPS,
|
|
257
|
-
}))
|
|
267
|
+
const at = (introducedAt = Math.max(Date.now(), introducedAt + 1));
|
|
268
|
+
const fields = { origin: did, target, kind, at, sdp };
|
|
269
|
+
void signLabel(provider, config.key, introductionLabel(name, fields))
|
|
270
|
+
.then((sig) => floodSignal(name, relayedSignal(fields, sig, MAX_HOPS)))
|
|
258
271
|
.catch(() => { });
|
|
259
272
|
};
|
|
260
|
-
/** Through the relays, in one room
|
|
273
|
+
/** Through the relays, in one room, to the box the peer's message came with */
|
|
261
274
|
const throughRelay = (target, room, box) => (kind, data) => signaling.signal(kind, target, data, room, box);
|
|
262
275
|
const offerTo = async (peer, deliver) => {
|
|
263
276
|
watch(peer);
|
|
@@ -270,22 +283,17 @@ export function createMesh(config) {
|
|
|
270
283
|
};
|
|
271
284
|
/** Acts on a peer's offer or answer, sending the answer back the way the offer came. */
|
|
272
285
|
const onSignal = async (peer, kind, data, deliver) => {
|
|
273
|
-
// A
|
|
274
|
-
// not: anyone can put someone else's name on one.
|
|
286
|
+
// A proved connection is not replaced by an unproved offer: anyone can put someone's name on one.
|
|
275
287
|
if (!data || typeof data !== 'object' || isAdmitted(peer))
|
|
276
288
|
return;
|
|
289
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- setRemoteDescription checks it and throws into the catch below
|
|
290
|
+
const description = data;
|
|
277
291
|
try {
|
|
278
|
-
if (kind === '
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
deliver('answer', await transport.handleOffer(peer, data));
|
|
284
|
-
}
|
|
285
|
-
else {
|
|
286
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- setRemoteDescription checks it and throws into the catch below
|
|
287
|
-
await transport.handleAnswer(peer, data);
|
|
288
|
-
}
|
|
292
|
+
if (kind === 'answer')
|
|
293
|
+
return await transport.handleAnswer(peer, description);
|
|
294
|
+
attempted.add(peer);
|
|
295
|
+
watch(peer);
|
|
296
|
+
deliver('answer', await transport.handleOffer(peer, description));
|
|
289
297
|
}
|
|
290
298
|
catch (err) {
|
|
291
299
|
fail(err);
|
|
@@ -299,36 +307,32 @@ export function createMesh(config) {
|
|
|
299
307
|
greet(name, peer);
|
|
300
308
|
return;
|
|
301
309
|
}
|
|
302
|
-
(expected
|
|
303
|
-
if (offer
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
310
|
+
getOrAdd(expected, peer, () => new Set()).add(name);
|
|
311
|
+
if (!offer || attempted.has(peer))
|
|
312
|
+
return;
|
|
313
|
+
attempted.add(peer);
|
|
314
|
+
void offerTo(peer, offer);
|
|
307
315
|
};
|
|
308
|
-
// Both sides hear each other's hello
|
|
316
|
+
// Both sides hear each other's hello; one rule says who offers.
|
|
309
317
|
signaling.on('peer-joined', (peer, room) => meet(room, peer, shouldInitiate(did, peer) ? throughRelay(peer, room) : null));
|
|
310
|
-
signaling.on('signal', (
|
|
311
|
-
|
|
312
|
-
|
|
318
|
+
signaling.on('signal', ({ from, type, payload, room, box }) => {
|
|
319
|
+
void onSignal(from, type, payload, throughRelay(from, room, box));
|
|
320
|
+
});
|
|
321
|
+
const onPeerList = (name, peers) => {
|
|
313
322
|
if (!introduce || !Array.isArray(peers))
|
|
314
323
|
return;
|
|
315
|
-
for (const peer of peers.slice(0, MAX_INTRODUCED))
|
|
316
|
-
if (
|
|
317
|
-
|
|
318
|
-
// Both sides are told about each other at the same moment, so without a
|
|
319
|
-
// rule both would offer and there would be two half-open connections to
|
|
320
|
-
// unpick. Comparing identifiers is free and both sides always agree.
|
|
321
|
-
meet(name, peer, shouldInitiate(did, peer) ? throughMesh(peer, name) : null);
|
|
322
|
-
}
|
|
324
|
+
for (const peer of peers.slice(0, MAX_INTRODUCED))
|
|
325
|
+
if (isPeerDid(peer))
|
|
326
|
+
meet(name, peer, shouldInitiate(did, peer) ? throughMesh(peer, name) : null);
|
|
323
327
|
};
|
|
324
328
|
/** Whether a signal from an origin in a room is new: none from it there was acted on with this time */
|
|
325
329
|
const isNewSignal = (name, origin, at) => {
|
|
330
|
+
const old = Date.now() - SIGNAL_WINDOW_MS;
|
|
326
331
|
const times = actedOn.get(`${name} ${origin}`);
|
|
327
332
|
if (!times) {
|
|
328
333
|
if (actedOn.size < MAX_ORIGINS_HELD)
|
|
329
334
|
return true;
|
|
330
|
-
// Full: let go of origins whose times are all past the window
|
|
331
|
-
const old = Date.now() - SIGNAL_WINDOW_MS;
|
|
335
|
+
// Full: let go of origins whose times are all past the window.
|
|
332
336
|
for (const [key, held] of actedOn)
|
|
333
337
|
if ([...held].every((time) => time < old))
|
|
334
338
|
actedOn.delete(key);
|
|
@@ -341,39 +345,62 @@ export function createMesh(config) {
|
|
|
341
345
|
actedOn.delete(`${name} ${origin}`);
|
|
342
346
|
return !times.has(at) && times.size < MAX_SIGNALS_ACTED;
|
|
343
347
|
};
|
|
344
|
-
const onRelayedSignal = async (from, name,
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
const { origin, target, kind, at, sig, hops } = signal;
|
|
348
|
-
const { sdp } = signal.data;
|
|
349
|
-
if (!isPeerDid(origin) || origin === did || !isPeerDid(target) || !isSignalKind(kind))
|
|
348
|
+
const onRelayedSignal = async (from, name, payload) => {
|
|
349
|
+
const signal = readSignal(payload);
|
|
350
|
+
if (!signal || signal.origin === did)
|
|
350
351
|
return;
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
return;
|
|
355
|
-
// Checked before the signature, so a copy arriving again costs nothing: for this node, by
|
|
356
|
-
// its origin's time; to pass on, by the same, recorded only once its signature checks out.
|
|
352
|
+
const { origin, target, kind, at, sdp, sig, hops } = signal;
|
|
353
|
+
const forUs = target === did;
|
|
354
|
+
// Checked before the signature, so a copy arriving again costs nothing.
|
|
357
355
|
const passed = `${name}|${origin}|${at}`;
|
|
358
|
-
if (
|
|
356
|
+
if (forUs ? !isNewSignal(name, origin, at) : seenSignals.has(passed))
|
|
359
357
|
return;
|
|
360
|
-
|
|
361
|
-
if (!(await verifyBy(provider, origin, sig, introductionLabel(name, { origin, target, kind, at, sdp }))))
|
|
358
|
+
if (!(await verifyBy(provider, origin, sig, introductionLabel(name, signal))))
|
|
362
359
|
return;
|
|
363
|
-
if (
|
|
360
|
+
if (forUs) {
|
|
364
361
|
if (!isNewSignal(name, origin, at))
|
|
365
362
|
return;
|
|
366
|
-
|
|
367
|
-
(actedOn.get(key) ?? actedOn.set(key, new Set()).get(key)).add(at);
|
|
363
|
+
getOrAdd(actedOn, `${name} ${origin}`, () => new Set()).add(at);
|
|
368
364
|
void onSignal(origin, kind, { type: kind, sdp }, throughMesh(origin, name));
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
if (typeof hops !== 'number' || hops <= 0 || typeof sig !== 'string' || !seenSignals.accept(passed))
|
|
368
|
+
return;
|
|
369
|
+
// Never further than we would send it ourselves.
|
|
370
|
+
floodSignal(name, relayedSignal(signal, sig, Math.min(hops, MAX_HOPS) - 1), from);
|
|
371
|
+
};
|
|
372
|
+
const onFrame = (peer, frame) => {
|
|
373
|
+
const { type, payload } = frame;
|
|
374
|
+
const name = typeof frame.room === 'string' ? frame.room : null;
|
|
375
|
+
if (typeof type !== 'string')
|
|
376
|
+
return;
|
|
377
|
+
// Before a peer has proved itself somewhere, the handshake is all there is.
|
|
378
|
+
if (type === AUTH_HELLO_MESSAGE || type === AUTH_PROOF_MESSAGE) {
|
|
379
|
+
if (!name)
|
|
380
|
+
return;
|
|
381
|
+
void onHandshake(name, peer, type, payload).catch(() => {
|
|
382
|
+
const room = rooms.get(name);
|
|
383
|
+
if (room)
|
|
384
|
+
refuse(room, peer);
|
|
385
|
+
});
|
|
386
|
+
return;
|
|
369
387
|
}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
388
|
+
if (!isAdmitted(peer))
|
|
389
|
+
return;
|
|
390
|
+
const room = name ? rooms.get(name) : undefined;
|
|
391
|
+
if (!name || !room?.peers.has(peer))
|
|
392
|
+
return;
|
|
393
|
+
if (type === SIGNAL_MESSAGE)
|
|
394
|
+
return void onRelayedSignal(peer, name, payload).catch(() => { });
|
|
395
|
+
if (type === PEERS_MESSAGE)
|
|
396
|
+
return onPeerList(name, payload);
|
|
397
|
+
if (type === LEAVE_MESSAGE) {
|
|
398
|
+
drop(room, peer);
|
|
399
|
+
return closeIfIdle(peer);
|
|
376
400
|
}
|
|
401
|
+
// The sender is the connection it arrived on, not whatever the frame claims.
|
|
402
|
+
if (!isControlMessage(type))
|
|
403
|
+
room.events.emit('message', { type, from: peer, payload });
|
|
377
404
|
};
|
|
378
405
|
transport.on('connected', (peer) => {
|
|
379
406
|
unwatch(peer);
|
|
@@ -385,10 +412,11 @@ export function createMesh(config) {
|
|
|
385
412
|
greet(name, peer);
|
|
386
413
|
expected.delete(peer);
|
|
387
414
|
// The other side greets in the rooms it knows we share; if none does, the connection has no use.
|
|
388
|
-
|
|
415
|
+
const timer = setTimeout(() => {
|
|
389
416
|
idle.delete(peer);
|
|
390
417
|
closeIfIdle(peer);
|
|
391
|
-
}, authTimeoutMs)
|
|
418
|
+
}, authTimeoutMs);
|
|
419
|
+
idle.set(peer, timer);
|
|
392
420
|
});
|
|
393
421
|
transport.on('disconnected', lost);
|
|
394
422
|
transport.on('data', (peer, data) => {
|
|
@@ -399,39 +427,8 @@ export function createMesh(config) {
|
|
|
399
427
|
catch {
|
|
400
428
|
return fail(new Error('Failed to parse incoming message'));
|
|
401
429
|
}
|
|
402
|
-
if (
|
|
403
|
-
|
|
404
|
-
const { type, payload } = frame;
|
|
405
|
-
const name = typeof frame.room === 'string' ? frame.room : null;
|
|
406
|
-
if (typeof type !== 'string')
|
|
407
|
-
return;
|
|
408
|
-
// Before a peer has proved itself somewhere, the handshake is all there is.
|
|
409
|
-
if (type === AUTH_HELLO_MESSAGE || type === AUTH_PROOF_MESSAGE) {
|
|
410
|
-
if (name)
|
|
411
|
-
void onHandshake(name, peer, type, payload).catch(() => {
|
|
412
|
-
const room = rooms.get(name);
|
|
413
|
-
if (room)
|
|
414
|
-
refuse(room, peer);
|
|
415
|
-
});
|
|
416
|
-
return;
|
|
417
|
-
}
|
|
418
|
-
if (!isAdmitted(peer))
|
|
419
|
-
return;
|
|
420
|
-
const room = name ? rooms.get(name) : undefined;
|
|
421
|
-
if (!name || !room?.peers.has(peer))
|
|
422
|
-
return;
|
|
423
|
-
if (type === SIGNAL_MESSAGE)
|
|
424
|
-
return void onRelayedSignal(peer, name, payload).catch(() => { });
|
|
425
|
-
if (type === PEERS_MESSAGE)
|
|
426
|
-
return handlePeerList(name, payload);
|
|
427
|
-
if (type === LEAVE_MESSAGE) {
|
|
428
|
-
drop(room, peer);
|
|
429
|
-
return closeIfIdle(peer);
|
|
430
|
-
}
|
|
431
|
-
// Mesh housekeeping never reaches the space. The sender is the connection
|
|
432
|
-
// it arrived on, not whatever the frame claims.
|
|
433
|
-
if (!isControlMessage(type))
|
|
434
|
-
room.events.emit('message', { type, from: peer, payload });
|
|
430
|
+
if (isObject(frame))
|
|
431
|
+
onFrame(peer, frame);
|
|
435
432
|
});
|
|
436
433
|
transport.on('error', (peer, error) => fail(new Error(`Transport error with peer ${peer}: ${error.message}`)));
|
|
437
434
|
// ─── Rooms ──────────────────────────────────────────────────────────
|
|
@@ -442,15 +439,38 @@ export function createMesh(config) {
|
|
|
442
439
|
});
|
|
443
440
|
return started;
|
|
444
441
|
};
|
|
442
|
+
/** The last room is gone: let go of every timer and the relays. */
|
|
443
|
+
const stop = () => {
|
|
444
|
+
for (const timer of idle.values())
|
|
445
|
+
clearTimeout(timer);
|
|
446
|
+
idle.clear();
|
|
447
|
+
for (const { timer } of pending.values())
|
|
448
|
+
clearTimeout(timer);
|
|
449
|
+
pending.clear();
|
|
450
|
+
tries.clear();
|
|
451
|
+
signaling.disconnect();
|
|
452
|
+
started = null;
|
|
453
|
+
};
|
|
454
|
+
/** Waits for a relay's TURN offer, briefly: relays without TURN never answer. */
|
|
455
|
+
const askForIce = () => new Promise((resolve) => {
|
|
456
|
+
const done = () => {
|
|
457
|
+
clearTimeout(timer);
|
|
458
|
+
signaling.off('ice', done);
|
|
459
|
+
resolve();
|
|
460
|
+
};
|
|
461
|
+
const timer = setTimeout(done, ICE_WAIT_MS);
|
|
462
|
+
signaling.on('ice', done);
|
|
463
|
+
signaling.requestIce();
|
|
464
|
+
});
|
|
445
465
|
return {
|
|
446
466
|
status: () => ({
|
|
447
467
|
relays: signaling.relays(),
|
|
448
468
|
links: [...links].map((peer) => ({
|
|
449
469
|
peer,
|
|
450
|
-
rooms:
|
|
470
|
+
rooms: roomList().filter((room) => room.peers.has(peer)).length,
|
|
451
471
|
})),
|
|
452
472
|
connecting: [...pending].map(([peer, { since, tries: tried }]) => ({ peer, since, tries: tried })),
|
|
453
|
-
turn:
|
|
473
|
+
turn: hasTurn(),
|
|
454
474
|
}),
|
|
455
475
|
subscribe(listener) {
|
|
456
476
|
changes.add(listener);
|
|
@@ -462,17 +482,7 @@ export function createMesh(config) {
|
|
|
462
482
|
// A relay that did not answer last time has no TURN; don't wait on it every call.
|
|
463
483
|
if (signaling.isConnected() && stale && Date.now() - iceAskedAt > ICE_REFRESH_MS) {
|
|
464
484
|
iceAskedAt = Date.now();
|
|
465
|
-
|
|
466
|
-
await new Promise((resolve) => {
|
|
467
|
-
const done = () => {
|
|
468
|
-
clearTimeout(timer);
|
|
469
|
-
signaling.off('ice', done);
|
|
470
|
-
resolve();
|
|
471
|
-
};
|
|
472
|
-
const timer = setTimeout(done, ICE_WAIT_MS);
|
|
473
|
-
signaling.on('ice', done);
|
|
474
|
-
signaling.requestIce();
|
|
475
|
-
});
|
|
485
|
+
await askForIce();
|
|
476
486
|
}
|
|
477
487
|
return currentIce();
|
|
478
488
|
},
|
|
@@ -485,12 +495,8 @@ export function createMesh(config) {
|
|
|
485
495
|
signaling.join(name, relays);
|
|
486
496
|
},
|
|
487
497
|
join(name, auth = null) {
|
|
488
|
-
const room = {
|
|
489
|
-
|
|
490
|
-
peers: new Map(),
|
|
491
|
-
handshakes: new Map(),
|
|
492
|
-
events: createEmitter(),
|
|
493
|
-
};
|
|
498
|
+
const room = { auth, peers: new Map(), handshakes: new Map(), events: createEmitter() };
|
|
499
|
+
const isCurrent = () => rooms.get(name) === room;
|
|
494
500
|
const send = (peer, message) => {
|
|
495
501
|
if (room.peers.has(peer))
|
|
496
502
|
sendFrame(peer, { room: name, type: message.type, payload: message.payload });
|
|
@@ -504,7 +510,7 @@ export function createMesh(config) {
|
|
|
504
510
|
await start();
|
|
505
511
|
},
|
|
506
512
|
disconnect() {
|
|
507
|
-
if (
|
|
513
|
+
if (!isCurrent())
|
|
508
514
|
return;
|
|
509
515
|
for (const peer of room.peers.keys())
|
|
510
516
|
sendFrame(peer, { room: name, type: LEAVE_MESSAGE });
|
|
@@ -515,17 +521,8 @@ export function createMesh(config) {
|
|
|
515
521
|
signaling.leave(name);
|
|
516
522
|
for (const peer of [...links])
|
|
517
523
|
closeIfIdle(peer);
|
|
518
|
-
if (rooms.size === 0)
|
|
519
|
-
|
|
520
|
-
clearTimeout(timer);
|
|
521
|
-
idle.clear();
|
|
522
|
-
for (const { timer } of pending.values())
|
|
523
|
-
clearTimeout(timer);
|
|
524
|
-
pending.clear();
|
|
525
|
-
tries.clear();
|
|
526
|
-
signaling.disconnect();
|
|
527
|
-
started = null;
|
|
528
|
-
}
|
|
524
|
+
if (rooms.size === 0)
|
|
525
|
+
stop();
|
|
529
526
|
},
|
|
530
527
|
send,
|
|
531
528
|
broadcast: (message) => {
|
|
@@ -533,7 +530,7 @@ export function createMesh(config) {
|
|
|
533
530
|
send(peer, message);
|
|
534
531
|
},
|
|
535
532
|
drop(peer) {
|
|
536
|
-
if (
|
|
533
|
+
if (!isCurrent() || !room.peers.has(peer))
|
|
537
534
|
return;
|
|
538
535
|
// Only this room: the connection may still serve spaces the two share.
|
|
539
536
|
sendFrame(peer, { room: name, type: LEAVE_MESSAGE });
|
|
@@ -543,11 +540,36 @@ export function createMesh(config) {
|
|
|
543
540
|
getPeers: () => [...room.peers.values()],
|
|
544
541
|
on: room.events.on,
|
|
545
542
|
off: room.events.off,
|
|
546
|
-
//
|
|
547
|
-
// depends on a relay being up.
|
|
543
|
+
// Reachable: after the first introduction that no longer depends on a relay.
|
|
548
544
|
isConnected: () => signaling.isConnected() || room.peers.size > 0,
|
|
549
545
|
});
|
|
550
546
|
},
|
|
551
547
|
};
|
|
552
548
|
}
|
|
549
|
+
/** A relayed signal's fields, if it has the shape of one and is within the window */
|
|
550
|
+
function readSignal(signal) {
|
|
551
|
+
if (!isObject(signal) || !isObject(signal.data))
|
|
552
|
+
return null;
|
|
553
|
+
const { origin, target, kind, at, sig, hops } = signal;
|
|
554
|
+
const { sdp } = signal.data;
|
|
555
|
+
if (!isPeerDid(origin) || !isPeerDid(target) || !isSignalKind(kind))
|
|
556
|
+
return null;
|
|
557
|
+
if (signal.data.type !== kind || typeof sdp !== 'string' || sdp.length > MAX_SDP_CHARS)
|
|
558
|
+
return null;
|
|
559
|
+
if (typeof at !== 'number' || !Number.isSafeInteger(at) || Math.abs(Date.now() - at) > SIGNAL_WINDOW_MS)
|
|
560
|
+
return null;
|
|
561
|
+
return { origin, target, kind, at, sdp, sig, hops };
|
|
562
|
+
}
|
|
563
|
+
function relayedSignal(fields, sig, hops) {
|
|
564
|
+
const { origin, target, kind, at, sdp } = fields;
|
|
565
|
+
return { origin, target, kind, data: { type: kind, sdp }, at, sig, hops };
|
|
566
|
+
}
|
|
567
|
+
/** Sets `key` as the newest entry, letting the oldest go past `limit` */
|
|
568
|
+
function setNewest(map, key, value, limit) {
|
|
569
|
+
map.delete(key);
|
|
570
|
+
map.set(key, value);
|
|
571
|
+
// A map iterates in insertion order: the first is the oldest.
|
|
572
|
+
if (map.size > limit)
|
|
573
|
+
map.delete(map.keys().next().value ?? key);
|
|
574
|
+
}
|
|
553
575
|
//# sourceMappingURL=mesh.js.map
|