@bowl42/keywire 0.0.0-stage → 0.3.1
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/LICENSE +21 -0
- package/README.md +118 -2
- package/dist/app.d.ts +2 -0
- package/dist/app.js +13 -0
- package/dist/app.js.map +1 -0
- package/dist/bytes.d.ts +1 -0
- package/dist/bytes.js +7 -0
- package/dist/bytes.js.map +1 -0
- package/dist/client.d.ts +66 -0
- package/dist/client.js +846 -0
- package/dist/client.js.map +1 -0
- package/dist/compress/block.d.ts +51 -0
- package/dist/compress/block.js +667 -0
- package/dist/compress/block.js.map +1 -0
- package/dist/compress/deflate.d.ts +7 -0
- package/dist/compress/deflate.js +603 -0
- package/dist/compress/deflate.js.map +1 -0
- package/dist/compress/index.d.ts +6 -0
- package/dist/compress/index.js +13 -0
- package/dist/compress/index.js.map +1 -0
- package/dist/compress/inflate.d.ts +21 -0
- package/dist/compress/inflate.js +380 -0
- package/dist/compress/inflate.js.map +1 -0
- package/dist/compress/wasm.d.ts +50 -0
- package/dist/compress/wasm.js +192 -0
- package/dist/compress/wasm.js.map +1 -0
- package/dist/compress/zlib-wasm.d.ts +15 -0
- package/dist/compress/zlib-wasm.js +18 -0
- package/dist/compress/zlib-wasm.js.map +1 -0
- package/dist/conn.d.ts +126 -0
- package/dist/conn.js +685 -0
- package/dist/conn.js.map +1 -0
- package/dist/dial/index.d.ts +3 -0
- package/dist/dial/index.js +10 -0
- package/dist/dial/index.js.map +1 -0
- package/dist/discovery/index.d.ts +16 -0
- package/dist/discovery/index.js +173 -0
- package/dist/discovery/index.js.map +1 -0
- package/dist/discovery/reach.d.ts +4 -0
- package/dist/discovery/reach.js +36 -0
- package/dist/discovery/reach.js.map +1 -0
- package/dist/domain.d.ts +3 -0
- package/dist/domain.js +12 -0
- package/dist/domain.js.map +1 -0
- package/dist/errors.d.ts +7 -0
- package/dist/errors.js +49 -0
- package/dist/errors.js.map +1 -0
- package/dist/extension.d.ts +53 -0
- package/dist/extension.js +158 -0
- package/dist/extension.js.map +1 -0
- package/dist/forward.d.ts +11 -0
- package/dist/forward.js +125 -0
- package/dist/forward.js.map +1 -0
- package/dist/framed-stream.d.ts +14 -0
- package/dist/framed-stream.js +113 -0
- package/dist/framed-stream.js.map +1 -0
- package/dist/gen/keywire/discovery/v1/discovery_pb.d.ts +105 -0
- package/dist/gen/keywire/discovery/v1/discovery_pb.js +57 -0
- package/dist/gen/keywire/discovery/v1/discovery_pb.js.map +1 -0
- package/dist/gen/keywire/state/v1/state_pb.d.ts +988 -0
- package/dist/gen/keywire/state/v1/state_pb.js +184 -0
- package/dist/gen/keywire/state/v1/state_pb.js.map +1 -0
- package/dist/gen/keywire/v1/forward_pb.d.ts +53 -0
- package/dist/gen/keywire/v1/forward_pb.js +58 -0
- package/dist/gen/keywire/v1/forward_pb.js.map +1 -0
- package/dist/gen/keywire/v1/guest_pb.d.ts +322 -0
- package/dist/gen/keywire/v1/guest_pb.js +100 -0
- package/dist/gen/keywire/v1/guest_pb.js.map +1 -0
- package/dist/gen/keywire/v1/pair_pb.d.ts +106 -0
- package/dist/gen/keywire/v1/pair_pb.js +45 -0
- package/dist/gen/keywire/v1/pair_pb.js.map +1 -0
- package/dist/gen/keywire/v1/relay_pb.d.ts +116 -0
- package/dist/gen/keywire/v1/relay_pb.js +20 -0
- package/dist/gen/keywire/v1/relay_pb.js.map +1 -0
- package/dist/gen/keywire/v1/roster_pb.d.ts +213 -0
- package/dist/gen/keywire/v1/roster_pb.js +77 -0
- package/dist/gen/keywire/v1/roster_pb.js.map +1 -0
- package/dist/gen/keywire/v1/sync_pb.d.ts +68 -0
- package/dist/gen/keywire/v1/sync_pb.js +24 -0
- package/dist/gen/keywire/v1/sync_pb.js.map +1 -0
- package/dist/guest/equal-bytes.d.ts +1 -0
- package/dist/guest/equal-bytes.js +10 -0
- package/dist/guest/equal-bytes.js.map +1 -0
- package/dist/guest/hello.d.ts +4 -0
- package/dist/guest/hello.js +42 -0
- package/dist/guest/hello.js.map +1 -0
- package/dist/guest/invite-frame.d.ts +8 -0
- package/dist/guest/invite-frame.js +44 -0
- package/dist/guest/invite-frame.js.map +1 -0
- package/dist/guest/invite.d.ts +17 -0
- package/dist/guest/invite.js +86 -0
- package/dist/guest/invite.js.map +1 -0
- package/dist/guest/relay-hello.d.ts +2 -0
- package/dist/guest/relay-hello.js +38 -0
- package/dist/guest/relay-hello.js.map +1 -0
- package/dist/guest/revocations.d.ts +12 -0
- package/dist/guest/revocations.js +134 -0
- package/dist/guest/revocations.js.map +1 -0
- package/dist/guest/roster.d.ts +2 -0
- package/dist/guest/roster.js +14 -0
- package/dist/guest/roster.js.map +1 -0
- package/dist/guest/token-payload.d.ts +2 -0
- package/dist/guest/token-payload.js +71 -0
- package/dist/guest/token-payload.js.map +1 -0
- package/dist/guest-conn.d.ts +20 -0
- package/dist/guest-conn.js +99 -0
- package/dist/guest-conn.js.map +1 -0
- package/dist/guest-relay.d.ts +7 -0
- package/dist/guest-relay.js +45 -0
- package/dist/guest-relay.js.map +1 -0
- package/dist/guest.d.ts +20 -0
- package/dist/guest.js +99 -0
- package/dist/guest.js.map +1 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/msg-path.d.ts +9 -0
- package/dist/msg-path.js +2 -0
- package/dist/msg-path.js.map +1 -0
- package/dist/mux/byte-queue.d.ts +9 -0
- package/dist/mux/byte-queue.js +62 -0
- package/dist/mux/byte-queue.js.map +1 -0
- package/dist/mux/codec.d.ts +30 -0
- package/dist/mux/codec.js +23 -0
- package/dist/mux/codec.js.map +1 -0
- package/dist/mux/errors.d.ts +23 -0
- package/dist/mux/errors.js +47 -0
- package/dist/mux/errors.js.map +1 -0
- package/dist/mux/frame.d.ts +44 -0
- package/dist/mux/frame.js +161 -0
- package/dist/mux/frame.js.map +1 -0
- package/dist/mux/nexttask.d.ts +1 -0
- package/dist/mux/nexttask.js +19 -0
- package/dist/mux/nexttask.js.map +1 -0
- package/dist/mux/session.d.ts +69 -0
- package/dist/mux/session.js +586 -0
- package/dist/mux/session.js.map +1 -0
- package/dist/mux/signal.d.ts +5 -0
- package/dist/mux/signal.js +14 -0
- package/dist/mux/signal.js.map +1 -0
- package/dist/mux/stream.d.ts +34 -0
- package/dist/mux/stream.js +620 -0
- package/dist/mux/stream.js.map +1 -0
- package/dist/nodekit/device.d.ts +40 -0
- package/dist/nodekit/device.js +188 -0
- package/dist/nodekit/device.js.map +1 -0
- package/dist/nodekit/index.d.ts +5 -0
- package/dist/nodekit/index.js +8 -0
- package/dist/nodekit/index.js.map +1 -0
- package/dist/nodekit/indexeddb.d.ts +2 -0
- package/dist/nodekit/indexeddb.js +114 -0
- package/dist/nodekit/indexeddb.js.map +1 -0
- package/dist/nodekit/pair-device.d.ts +27 -0
- package/dist/nodekit/pair-device.js +44 -0
- package/dist/nodekit/pair-device.js.map +1 -0
- package/dist/nodekit/sealed-signer.d.ts +22 -0
- package/dist/nodekit/sealed-signer.js +74 -0
- package/dist/nodekit/sealed-signer.js.map +1 -0
- package/dist/nodekit/store.d.ts +22 -0
- package/dist/nodekit/store.js +21 -0
- package/dist/nodekit/store.js.map +1 -0
- package/dist/noise/backend.d.ts +25 -0
- package/dist/noise/backend.js +2 -0
- package/dist/noise/backend.js.map +1 -0
- package/dist/noise/backends.d.ts +4 -0
- package/dist/noise/backends.js +19 -0
- package/dist/noise/backends.js.map +1 -0
- package/dist/noise/cipher.d.ts +18 -0
- package/dist/noise/cipher.js +69 -0
- package/dist/noise/cipher.js.map +1 -0
- package/dist/noise/crypto.d.ts +11 -0
- package/dist/noise/crypto.js +47 -0
- package/dist/noise/crypto.js.map +1 -0
- package/dist/noise/handshake.d.ts +28 -0
- package/dist/noise/handshake.js +183 -0
- package/dist/noise/handshake.js.map +1 -0
- package/dist/noise/import.d.ts +2 -0
- package/dist/noise/import.js +16 -0
- package/dist/noise/import.js.map +1 -0
- package/dist/noise/noble.d.ts +2 -0
- package/dist/noise/noble.js +51 -0
- package/dist/noise/noble.js.map +1 -0
- package/dist/noise/pair-code.d.ts +2 -0
- package/dist/noise/pair-code.js +11 -0
- package/dist/noise/pair-code.js.map +1 -0
- package/dist/noise/pkcs8.d.ts +3 -0
- package/dist/noise/pkcs8.js +18 -0
- package/dist/noise/pkcs8.js.map +1 -0
- package/dist/noise/sealed.d.ts +21 -0
- package/dist/noise/sealed.js +40 -0
- package/dist/noise/sealed.js.map +1 -0
- package/dist/noise/symmetric.d.ts +17 -0
- package/dist/noise/symmetric.js +56 -0
- package/dist/noise/symmetric.js.map +1 -0
- package/dist/noise/webcrypto.d.ts +3 -0
- package/dist/noise/webcrypto.js +98 -0
- package/dist/noise/webcrypto.js.map +1 -0
- package/dist/pair-relay.d.ts +4 -0
- package/dist/pair-relay.js +46 -0
- package/dist/pair-relay.js.map +1 -0
- package/dist/pair.d.ts +7 -0
- package/dist/pair.js +50 -0
- package/dist/pair.js.map +1 -0
- package/dist/paths/link.d.ts +33 -0
- package/dist/paths/link.js +132 -0
- package/dist/paths/link.js.map +1 -0
- package/dist/paths/node-paths.d.ts +10 -0
- package/dist/paths/node-paths.js +41 -0
- package/dist/paths/node-paths.js.map +1 -0
- package/dist/paths/path.d.ts +11 -0
- package/dist/paths/path.js +25 -0
- package/dist/paths/path.js.map +1 -0
- package/dist/paths/race.d.ts +18 -0
- package/dist/paths/race.js +157 -0
- package/dist/paths/race.js.map +1 -0
- package/dist/paths/relay-sessions.d.ts +11 -0
- package/dist/paths/relay-sessions.js +93 -0
- package/dist/paths/relay-sessions.js.map +1 -0
- package/dist/paths/upgrades.d.ts +12 -0
- package/dist/paths/upgrades.js +58 -0
- package/dist/paths/upgrades.js.map +1 -0
- package/dist/relay-server/admission.d.ts +24 -0
- package/dist/relay-server/admission.js +140 -0
- package/dist/relay-server/admission.js.map +1 -0
- package/dist/relay-server/config.d.ts +28 -0
- package/dist/relay-server/config.js +47 -0
- package/dist/relay-server/config.js.map +1 -0
- package/dist/relay-server/discovery/addr.d.ts +18 -0
- package/dist/relay-server/discovery/addr.js +211 -0
- package/dist/relay-server/discovery/addr.js.map +1 -0
- package/dist/relay-server/discovery/directory.d.ts +42 -0
- package/dist/relay-server/discovery/directory.js +101 -0
- package/dist/relay-server/discovery/directory.js.map +1 -0
- package/dist/relay-server/discovery/http.d.ts +10 -0
- package/dist/relay-server/discovery/http.js +172 -0
- package/dist/relay-server/discovery/http.js.map +1 -0
- package/dist/relay-server/discovery/index.d.ts +6 -0
- package/dist/relay-server/discovery/index.js +15 -0
- package/dist/relay-server/discovery/index.js.map +1 -0
- package/dist/relay-server/discovery/listing.d.ts +24 -0
- package/dist/relay-server/discovery/listing.js +115 -0
- package/dist/relay-server/discovery/listing.js.map +1 -0
- package/dist/relay-server/discovery/options.d.ts +39 -0
- package/dist/relay-server/discovery/options.js +97 -0
- package/dist/relay-server/discovery/options.js.map +1 -0
- package/dist/relay-server/discovery/service.d.ts +21 -0
- package/dist/relay-server/discovery/service.js +409 -0
- package/dist/relay-server/discovery/service.js.map +1 -0
- package/dist/relay-server/forward.d.ts +3 -0
- package/dist/relay-server/forward.js +97 -0
- package/dist/relay-server/forward.js.map +1 -0
- package/dist/relay-server/handshake.d.ts +10 -0
- package/dist/relay-server/handshake.js +36 -0
- package/dist/relay-server/handshake.js.map +1 -0
- package/dist/relay-server/index.d.ts +6 -0
- package/dist/relay-server/index.js +10 -0
- package/dist/relay-server/index.js.map +1 -0
- package/dist/relay-server/relay.d.ts +25 -0
- package/dist/relay-server/relay.js +392 -0
- package/dist/relay-server/relay.js.map +1 -0
- package/dist/relay-server/service-read.d.ts +4 -0
- package/dist/relay-server/service-read.js +16 -0
- package/dist/relay-server/service-read.js.map +1 -0
- package/dist/relay-server/service.d.ts +25 -0
- package/dist/relay-server/service.js +8 -0
- package/dist/relay-server/service.js.map +1 -0
- package/dist/relay-server/session.d.ts +60 -0
- package/dist/relay-server/session.js +35 -0
- package/dist/relay-server/session.js.map +1 -0
- package/dist/relay-server/url.d.ts +1 -0
- package/dist/relay-server/url.js +8 -0
- package/dist/relay-server/url.js.map +1 -0
- package/dist/relay-url.d.ts +2 -0
- package/dist/relay-url.js +11 -0
- package/dist/relay-url.js.map +1 -0
- package/dist/relay.d.ts +5 -0
- package/dist/relay.js +60 -0
- package/dist/relay.js.map +1 -0
- package/dist/roster/admission.d.ts +17 -0
- package/dist/roster/admission.js +85 -0
- package/dist/roster/admission.js.map +1 -0
- package/dist/roster/credentials.d.ts +5 -0
- package/dist/roster/credentials.js +72 -0
- package/dist/roster/credentials.js.map +1 -0
- package/dist/roster/digest.d.ts +3 -0
- package/dist/roster/digest.js +23 -0
- package/dist/roster/digest.js.map +1 -0
- package/dist/roster/envelope.d.ts +11 -0
- package/dist/roster/envelope.js +35 -0
- package/dist/roster/envelope.js.map +1 -0
- package/dist/roster/errors.d.ts +6 -0
- package/dist/roster/errors.js +11 -0
- package/dist/roster/errors.js.map +1 -0
- package/dist/roster/limits.d.ts +25 -0
- package/dist/roster/limits.js +26 -0
- package/dist/roster/limits.js.map +1 -0
- package/dist/roster/merge.d.ts +10 -0
- package/dist/roster/merge.js +101 -0
- package/dist/roster/merge.js.map +1 -0
- package/dist/roster/name.d.ts +1 -0
- package/dist/roster/name.js +7 -0
- package/dist/roster/name.js.map +1 -0
- package/dist/roster/order.d.ts +5 -0
- package/dist/roster/order.js +22 -0
- package/dist/roster/order.js.map +1 -0
- package/dist/roster/ownership.d.ts +9 -0
- package/dist/roster/ownership.js +42 -0
- package/dist/roster/ownership.js.map +1 -0
- package/dist/roster/retain.d.ts +2 -0
- package/dist/roster/retain.js +55 -0
- package/dist/roster/retain.js.map +1 -0
- package/dist/roster/revocations.d.ts +5 -0
- package/dist/roster/revocations.js +37 -0
- package/dist/roster/revocations.js.map +1 -0
- package/dist/roster/scan.d.ts +16 -0
- package/dist/roster/scan.js +194 -0
- package/dist/roster/scan.js.map +1 -0
- package/dist/roster/state.d.ts +34 -0
- package/dist/roster/state.js +204 -0
- package/dist/roster/state.js.map +1 -0
- package/dist/roster/statement.d.ts +38 -0
- package/dist/roster/statement.js +176 -0
- package/dist/roster/statement.js.map +1 -0
- package/dist/roster/types.d.ts +35 -0
- package/dist/roster/types.js +2 -0
- package/dist/roster/types.js.map +1 -0
- package/dist/roster/verify.d.ts +3 -0
- package/dist/roster/verify.js +63 -0
- package/dist/roster/verify.js.map +1 -0
- package/dist/roster-sync/apply.d.ts +2 -0
- package/dist/roster-sync/apply.js +23 -0
- package/dist/roster-sync/apply.js.map +1 -0
- package/dist/roster-sync/exchange.d.ts +3 -0
- package/dist/roster-sync/exchange.js +25 -0
- package/dist/roster-sync/exchange.js.map +1 -0
- package/dist/roster-sync/frame.d.ts +17 -0
- package/dist/roster-sync/frame.js +66 -0
- package/dist/roster-sync/frame.js.map +1 -0
- package/dist/roster-sync/records.d.ts +8 -0
- package/dist/roster-sync/records.js +78 -0
- package/dist/roster-sync/records.js.map +1 -0
- package/dist/roster-sync/sync.d.ts +12 -0
- package/dist/roster-sync/sync.js +69 -0
- package/dist/roster-sync/sync.js.map +1 -0
- package/dist/rtc.d.ts +15 -0
- package/dist/rtc.js +275 -0
- package/dist/rtc.js.map +1 -0
- package/dist/state/errors.d.ts +30 -0
- package/dist/state/errors.js +72 -0
- package/dist/state/errors.js.map +1 -0
- package/dist/state/index.d.ts +6 -0
- package/dist/state/index.js +11 -0
- package/dist/state/index.js.map +1 -0
- package/dist/state/limits.d.ts +34 -0
- package/dist/state/limits.js +115 -0
- package/dist/state/limits.js.map +1 -0
- package/dist/state/remote.d.ts +217 -0
- package/dist/state/remote.js +1934 -0
- package/dist/state/remote.js.map +1 -0
- package/dist/state/shared.d.ts +56 -0
- package/dist/state/shared.js +300 -0
- package/dist/state/shared.js.map +1 -0
- package/dist/state/state.d.ts +118 -0
- package/dist/state/state.js +1048 -0
- package/dist/state/state.js.map +1 -0
- package/dist/state/store.d.ts +31 -0
- package/dist/state/store.js +375 -0
- package/dist/state/store.js.map +1 -0
- package/dist/state/wire.d.ts +43 -0
- package/dist/state/wire.js +179 -0
- package/dist/state/wire.js.map +1 -0
- package/dist/strict-proto.d.ts +10 -0
- package/dist/strict-proto.js +167 -0
- package/dist/strict-proto.js.map +1 -0
- package/dist/token.d.ts +18 -0
- package/dist/token.js +60 -0
- package/dist/token.js.map +1 -0
- package/dist/urls.d.ts +7 -0
- package/dist/urls.js +117 -0
- package/dist/urls.js.map +1 -0
- package/dist/ws.d.ts +19 -0
- package/dist/ws.js +143 -0
- package/dist/ws.js.map +1 -0
- package/package.json +72 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Bowl42
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,119 @@
|
|
|
1
|
-
#
|
|
1
|
+
# keywire
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
End-to-end encrypted transport between your own devices, for browsers and
|
|
4
|
+
Node: pairing, Noise channels, direct paths and relays. It speaks the same
|
|
5
|
+
protocol as the Go implementation, `github.com/Bowl42/keywire/go`.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { Client, generateKeypair, pair, Roster } from "@bowl42/keywire";
|
|
9
|
+
|
|
10
|
+
const keypair = await generateKeypair();
|
|
11
|
+
// Pairing gives the roster: who is admitted, and where each Node is.
|
|
12
|
+
const { records } = await pair("wss://device.example/", {
|
|
13
|
+
app: "example.chat",
|
|
14
|
+
network,
|
|
15
|
+
keypair,
|
|
16
|
+
remote,
|
|
17
|
+
secret,
|
|
18
|
+
name: "Laptop",
|
|
19
|
+
onCode: (code) => console.log("compare", code),
|
|
20
|
+
});
|
|
21
|
+
const client = new Client({
|
|
22
|
+
app: "example.chat",
|
|
23
|
+
network,
|
|
24
|
+
keypair,
|
|
25
|
+
roster: Roster.open(network, records, Date.now()),
|
|
26
|
+
saveRoster: (records) => save(records),
|
|
27
|
+
});
|
|
28
|
+
// An address learned outside the roster, such as where it paired, helps.
|
|
29
|
+
await client.connect("wss://device.example/", remote);
|
|
30
|
+
// Devices are reached by key: a Node at its endpoints, through other
|
|
31
|
+
// Nodes or its relays; a member through the Nodes that hold it.
|
|
32
|
+
const stream = await client.openStream(remote);
|
|
33
|
+
const { peer, stream: incoming } = await client.acceptStream();
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
The Client keeps connected to the Network's Nodes, which makes this device
|
|
37
|
+
reachable; `passive: true` connects only on demand instead, as for a device
|
|
38
|
+
saving battery. `keywire/dial` makes a single connection over a path of
|
|
39
|
+
your choosing, for tools and relay tests.
|
|
40
|
+
|
|
41
|
+
`keywire/state`, optional and bundled only if imported, keeps shared
|
|
42
|
+
collections every device of the Network holds in step over the Client's
|
|
43
|
+
connections, and is a client of the collections, logs, commands and blobs
|
|
44
|
+
its Nodes serve. Its limits are yours; devices of a Network should share
|
|
45
|
+
them:
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { indexedDBStore, State } from "@bowl42/keywire/state";
|
|
49
|
+
|
|
50
|
+
const state = await State.open({
|
|
51
|
+
store: indexedDBStore("state"),
|
|
52
|
+
collections: [
|
|
53
|
+
{
|
|
54
|
+
name: "settings",
|
|
55
|
+
participants: "admitted",
|
|
56
|
+
limits: { maxValue: 256 << 10, maxBytes: 4 << 20 },
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
});
|
|
60
|
+
const client = new Client({ app, network, keypair, roster, extensions: [state.extension()] });
|
|
61
|
+
await state.update((tx) => tx.put("settings", "theme", new TextEncoder().encode("dark")));
|
|
62
|
+
state.watch("settings", () => render([...state.rows("settings")]));
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
`keywire/nodekit` pairs a device and keeps it, in IndexedDB or a store of
|
|
66
|
+
your own, with the roster it holds; runs a Client as that device, which
|
|
67
|
+
keeps the roster in the store as it syncs; and tells of its standing:
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
import { indexedDBDeviceStore, KeptDevice, pairDevice } from "@bowl42/keywire/nodekit";
|
|
71
|
+
|
|
72
|
+
const store = indexedDBDeviceStore();
|
|
73
|
+
const device =
|
|
74
|
+
(await KeptDevice.open(store)) ??
|
|
75
|
+
(await pairDevice(
|
|
76
|
+
{ network, node: remote, url, secret },
|
|
77
|
+
{ app: "example.chat", name: "Laptop", store },
|
|
78
|
+
));
|
|
79
|
+
const client = device.client({ app: "example.chat" });
|
|
80
|
+
device.watch(async ({ standing, lapsing }) => {
|
|
81
|
+
if (standing !== "ok") await device.forget();
|
|
82
|
+
else if (lapsing) warn("not renewed: connect to a Node soon");
|
|
83
|
+
});
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Its Nodes renew the grant of a device in use; the Client keeps connected
|
|
87
|
+
to them unless `passive`.
|
|
88
|
+
|
|
89
|
+
See https://github.com/Bowl42/keywire for the protocol and examples.
|
|
90
|
+
|
|
91
|
+
License: MIT
|
|
92
|
+
|
|
93
|
+
Streams can be compressed. The codec is a separate entry point, so a bundle
|
|
94
|
+
that does not use it carries none of it; a stream asks for compression
|
|
95
|
+
when it is opened, and is compressed where both devices support it:
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
import { deflate } from "@bowl42/keywire/compress";
|
|
99
|
+
|
|
100
|
+
const client = new Client({ ...options, compression: deflate });
|
|
101
|
+
const stream = await client.openStream(remote, undefined, { compress: true });
|
|
102
|
+
stream.setWriteCompression(false); // a secret goes plain, out of the context
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
`compressionMode` (on `Client`, `dial`, `pair`, `acceptPath` and guest
|
|
106
|
+
dialing) chooses what this device compresses of what it sends: `"auto"` by
|
|
107
|
+
default, `"off"` for none, `"force"` for all a stream asks for. `"off"`
|
|
108
|
+
opens streams uncompressed and writes plain on compressed streams a peer
|
|
109
|
+
opens; it does not stop this device decoding. A connection in TypeScript
|
|
110
|
+
never counts as end-to-end loopback (a WebSocket does not tell its socket),
|
|
111
|
+
so `"auto"` compresses as `"force"` does; an application that knows it runs
|
|
112
|
+
on the same host as its Node passes `"off"`, where compressing costs more
|
|
113
|
+
time than it saves.
|
|
114
|
+
|
|
115
|
+
The codec encodes and decodes with zlib-rs built to WebAssembly, inline in
|
|
116
|
+
`keywire/compress`, where WebAssembly runs; a page whose
|
|
117
|
+
Content-Security-Policy does not allow `'wasm-unsafe-eval'`, or a runtime
|
|
118
|
+
without WebAssembly, gets keywire's own JavaScript encoder and decoder
|
|
119
|
+
instead, slower, on the same wire.
|
package/dist/app.d.ts
ADDED
package/dist/app.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// MAX_APP bounds an application identifier, in bytes.
|
|
2
|
+
export const MAX_APP = 64;
|
|
3
|
+
// validApp says whether app may identify an application: 1 to MAX_APP bytes
|
|
4
|
+
// of lowercase ASCII letters, digits, ".", "-" and "_", as in "chat" or
|
|
5
|
+
// "com.example.chat".
|
|
6
|
+
//
|
|
7
|
+
// Every handshake between devices binds the application identifier, so
|
|
8
|
+
// devices of different applications never complete one, even on the same
|
|
9
|
+
// Network keys. Relays carry no application identifier and serve any.
|
|
10
|
+
export function validApp(app) {
|
|
11
|
+
return /^[a-z0-9._-]{1,64}$/.test(app);
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=app.js.map
|
package/dist/app.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,MAAM,CAAC,MAAM,OAAO,GAAG,EAAE,CAAC;AAE1B,4EAA4E;AAC5E,wEAAwE;AACxE,sBAAsB;AACtB,EAAE;AACF,uEAAuE;AACvE,yEAAyE;AACzE,sEAAsE;AACtE,MAAM,UAAU,QAAQ,CAAC,GAAW;IAClC,OAAO,qBAAqB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACzC,CAAC"}
|
package/dist/bytes.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function copyBytes(b: Uint8Array): Uint8Array<ArrayBuffer>;
|
package/dist/bytes.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// copyBytes copies b into memory of its own. Uint8Array.prototype.slice
|
|
2
|
+
// would do, but a Node Buffer's slice is a view of the same memory, so a
|
|
3
|
+
// secret or key kept from a caller's Buffer would stay the caller's.
|
|
4
|
+
export function copyBytes(b) {
|
|
5
|
+
return new Uint8Array(b);
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=bytes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bytes.js","sourceRoot":"","sources":["../src/bytes.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,yEAAyE;AACzE,qEAAqE;AACrE,MAAM,UAAU,SAAS,CAAC,CAAa;IACrC,OAAO,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;AAC3B,CAAC"}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { type CompressionMode, type Limits, type StreamOptions } from "./conn.ts";
|
|
2
|
+
import { type Extension } from "./extension.ts";
|
|
3
|
+
import type { Compression } from "./mux/codec.ts";
|
|
4
|
+
import type { Stream } from "./mux/stream.ts";
|
|
5
|
+
import type { Bytes, Keypair } from "./noise/crypto.ts";
|
|
6
|
+
import { type NodePath } from "./paths/path.ts";
|
|
7
|
+
import type { Dialers } from "./paths/race.ts";
|
|
8
|
+
import { type NetworkEvents } from "./paths/upgrades.ts";
|
|
9
|
+
import type { Roster } from "./roster/state.ts";
|
|
10
|
+
export interface ClientOptions {
|
|
11
|
+
app: string;
|
|
12
|
+
domain?: string;
|
|
13
|
+
network: Bytes;
|
|
14
|
+
keypair: Keypair;
|
|
15
|
+
roster: Roster;
|
|
16
|
+
saveRoster?: (records: Uint8Array[]) => Promise<void> | void;
|
|
17
|
+
extensions?: readonly Extension[];
|
|
18
|
+
onError?: (error: unknown) => void;
|
|
19
|
+
limits?: Limits;
|
|
20
|
+
dialers?: Partial<Dialers>;
|
|
21
|
+
stun?: string[];
|
|
22
|
+
events?: NetworkEvents | null;
|
|
23
|
+
passive?: boolean;
|
|
24
|
+
retryMinMs?: number;
|
|
25
|
+
retryMaxMs?: number;
|
|
26
|
+
acceptQueue?: number;
|
|
27
|
+
acceptPerPeer?: number;
|
|
28
|
+
compression?: Compression;
|
|
29
|
+
compressionMode?: CompressionMode;
|
|
30
|
+
pendingHandshakes?: number;
|
|
31
|
+
}
|
|
32
|
+
export interface PeerState {
|
|
33
|
+
key: Bytes;
|
|
34
|
+
path: NodePath;
|
|
35
|
+
since: number;
|
|
36
|
+
rtt: number;
|
|
37
|
+
via?: {
|
|
38
|
+
relay: string;
|
|
39
|
+
} | {
|
|
40
|
+
carrier: Bytes;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export interface Reaching {
|
|
44
|
+
key: Bytes;
|
|
45
|
+
dialing: boolean;
|
|
46
|
+
retryAtMs?: number;
|
|
47
|
+
failures: number;
|
|
48
|
+
}
|
|
49
|
+
export interface Incoming {
|
|
50
|
+
peer: Bytes;
|
|
51
|
+
stream: Stream;
|
|
52
|
+
}
|
|
53
|
+
export declare class Client {
|
|
54
|
+
#private;
|
|
55
|
+
constructor(opts: ClientOptions);
|
|
56
|
+
connect(url: string, key: Bytes, signal?: AbortSignal): Promise<void>;
|
|
57
|
+
syncRoster(key: Bytes, signal?: AbortSignal): Promise<void>;
|
|
58
|
+
ready(key: Bytes, signal?: AbortSignal): Promise<void>;
|
|
59
|
+
openStream(key: Bytes, signal?: AbortSignal, options?: StreamOptions): Promise<Stream>;
|
|
60
|
+
openExtensionStream(key: Bytes, service: number, signal?: AbortSignal, options?: StreamOptions): Promise<Stream>;
|
|
61
|
+
acceptStream(signal?: AbortSignal): Promise<Incoming>;
|
|
62
|
+
peers(): PeerState[];
|
|
63
|
+
reaching(): Reaching[];
|
|
64
|
+
watch(f: (peers: PeerState[], reaching: Reaching[]) => void): () => void;
|
|
65
|
+
close(): void;
|
|
66
|
+
}
|