@koralabs/handle-chat-sdk 0.0.13 → 1.0.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 +6 -0
- package/README.md +97 -0
- package/assets/libsignal_bg.wasm +0 -0
- package/examples/guardian-flow.mjs +88 -0
- package/examples/quickstart.mjs +74 -0
- package/lib/libsignal-wasm/pkg/handle_libsignal_wasm.d.ts +187 -0
- package/lib/libsignal-wasm/pkg/handle_libsignal_wasm.js +860 -0
- package/lib/src/chat/ChatService.d.ts +113 -0
- package/lib/src/chat/ChatService.js +643 -0
- package/lib/src/chat/anchor.d.ts +17 -0
- package/lib/src/chat/anchor.js +43 -0
- package/lib/src/chat/blob.d.ts +41 -0
- package/lib/src/chat/blob.js +146 -0
- package/lib/src/chat/chainDirectory.d.ts +29 -0
- package/lib/src/chat/chainDirectory.js +51 -0
- package/lib/src/chat/directory.d.ts +14 -0
- package/lib/src/chat/directory.js +14 -0
- package/lib/src/chat/guardian.d.ts +73 -0
- package/lib/src/chat/guardian.js +55 -0
- package/lib/src/chat/identity.d.ts +28 -0
- package/lib/src/chat/identity.js +55 -0
- package/lib/src/chat/invite.d.ts +12 -0
- package/lib/src/chat/invite.js +55 -0
- package/lib/src/chat/mesh/b2b.d.ts +17 -0
- package/lib/src/chat/mesh/b2b.js +50 -0
- package/lib/src/chat/mesh/client.d.ts +25 -0
- package/lib/src/chat/mesh/client.js +133 -0
- package/lib/src/chat/mesh/node.d.ts +12 -0
- package/lib/src/chat/mesh/node.js +46 -0
- package/lib/src/chat/mesh/presenceAuth.d.ts +19 -0
- package/lib/src/chat/mesh/presenceAuth.js +46 -0
- package/lib/src/chat/mesh/protocol.d.ts +57 -0
- package/lib/src/chat/mesh/protocol.js +8 -0
- package/lib/src/chat/mesh/webrtcAddr.d.ts +3 -0
- package/lib/src/chat/mesh/webrtcAddr.js +14 -0
- package/lib/src/chat/mesh/wire.d.ts +5 -0
- package/lib/src/chat/mesh/wire.js +36 -0
- package/lib/src/chat/message.d.ts +28 -0
- package/lib/src/chat/message.js +92 -0
- package/lib/src/chat/publish.d.ts +6 -0
- package/lib/src/chat/publish.js +22 -0
- package/lib/src/chat/qr.d.ts +9 -0
- package/lib/src/chat/qr.js +25 -0
- package/lib/src/chat/receipt.d.ts +17 -0
- package/lib/src/chat/receipt.js +22 -0
- package/lib/src/chat/sessionStore.d.ts +65 -0
- package/lib/src/chat/sessionStore.js +138 -0
- package/lib/src/chat/transport.d.ts +51 -0
- package/lib/src/chat/transport.js +79 -0
- package/lib/src/index.d.ts +19 -0
- package/lib/src/index.js +18 -0
- package/lib/src/memory.d.ts +18 -0
- package/lib/src/memory.js +44 -0
- package/lib/src/signal/SignalEngine.d.ts +68 -0
- package/lib/src/signal/SignalEngine.js +121 -0
- package/package.json +43 -19
- package/index.d.ts +0 -8
- package/index.js +0 -8
- package/interfaces/Chat.d.ts +0 -33
- package/interfaces/Chat.js +0 -1
- package/interfaces/Directory.d.ts +0 -27
- package/interfaces/Directory.js +0 -1
- package/interfaces/SessionMessage.d.ts +0 -15
- package/interfaces/SessionMessage.js +0 -1
- package/interfaces/Store.d.ts +0 -29
- package/interfaces/Store.js +0 -1
- package/lib/SignalDirectory.d.ts +0 -23
- package/lib/SignalDirectory.js +0 -157
- package/lib/SignalProtocolStore.d.ts +0 -46
- package/lib/SignalProtocolStore.js +0 -195
- package/lib/helper.d.ts +0 -2
- package/lib/helper.js +0 -17
- package/lib/helper.test.d.ts +0 -1
- package/lib/helper.test.js +0 -10
- package/lib/message-helper.d.ts +0 -20
- package/lib/message-helper.js +0 -53
package/LICENSE
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
@koralabs/handle-chat-sdk is licensed under the GNU Affero General Public License v3.0 only
|
|
2
|
+
(AGPL-3.0-only): https://www.gnu.org/licenses/agpl-3.0.html
|
|
3
|
+
|
|
4
|
+
The package embeds libsignal (https://github.com/signalapp/libsignal), which is AGPLv3, via the
|
|
5
|
+
libsignal-wasm build in the sibling chat.handle.me repository. Versions 0.0.x of this package were
|
|
6
|
+
published under MIT with a different implementation; v1.0.0 onward is AGPL-3.0-only.
|
package/README.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# @koralabs/handle-chat-sdk
|
|
2
|
+
|
|
3
|
+
## Contributor test policy
|
|
4
|
+
|
|
5
|
+
Tests and coverage run locally only, never in GitHub Actions, directly or through lifecycle scripts, composites, workflow templates, or shared helpers. Preserve local test commands. Build, lint, publication, deployment, and production guards remain permitted. Remove obsolete required test checks when retiring them.
|
|
6
|
+
|
|
7
|
+
The programmatic client for **handle-to-handle end-to-end-encrypted chat** — the messaging layer
|
|
8
|
+
behind [chat.handle.me](../chat.handle.me), consumable from any app or tool. v1 replaces the legacy
|
|
9
|
+
0.0.x SDK (which used an outdated libsignal port) with the modern stack: the **latest official
|
|
10
|
+
libsignal compiled to WASM** (X3DH + Double Ratchet + PQXDH), **wallet-rooted identities**
|
|
11
|
+
(sign-to-derive: one CIP-30 signature, stored nowhere), and the **SSR guardian payloads** that make
|
|
12
|
+
chat the delivery medium for [secrets.handle.me](../secrets.handle.me).
|
|
13
|
+
|
|
14
|
+
Built **from chat.handle.me's source** — that repo is the single source of truth; `npm run build`
|
|
15
|
+
compiles its client core (`src/chat`, `src/signal`, the libsignal WASM) into `lib/` + `assets/`.
|
|
16
|
+
|
|
17
|
+
## Working examples (run them)
|
|
18
|
+
|
|
19
|
+
Building needs read access to the private `koralabs/chat.handle.me` checkout beside this one, Node 22+, and its pinned libsignal WASM toolchain. See [docs/local-verification.md](docs/local-verification.md) for the exact local build-and-test steps.
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install && npm run build
|
|
23
|
+
node examples/quickstart.mjs # two handles, one E2E round trip, zero infrastructure
|
|
24
|
+
node examples/guardian-flow.mjs # the four SSR guardian payloads over the medium
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Both run in plain Node and are executed by `npm test` — the examples can't rot.
|
|
28
|
+
|
|
29
|
+
## Quickstart (what quickstart.mjs does)
|
|
30
|
+
|
|
31
|
+
```js
|
|
32
|
+
import { readFile } from 'node:fs/promises';
|
|
33
|
+
import {
|
|
34
|
+
ChatService, deriveSeedFromWallet, initSignalWasm, MemoryDirectory, MemoryHub
|
|
35
|
+
} from '@koralabs/handle-chat-sdk';
|
|
36
|
+
|
|
37
|
+
// Node has no origin to fetch the WASM from — hand it the bytes. Browsers skip this:
|
|
38
|
+
// the default fetches /public/libsignal_bg.wasm from the serving origin (ship assets/libsignal_bg.wasm there).
|
|
39
|
+
await initSignalWasm({ module_or_path: await readFile(new URL('../assets/libsignal_bg.wasm', import.meta.url)) });
|
|
40
|
+
|
|
41
|
+
// Identity = sign-to-derive: seed is the wallet's signature over a fixed message; nothing is stored.
|
|
42
|
+
// In an app, signData is the connected CIP-30 wallet's api.signData.
|
|
43
|
+
const seed = await deriveSeedFromWallet(signData, stakeAddressHex);
|
|
44
|
+
|
|
45
|
+
const directory = new MemoryDirectory(); // app: LocalStorageDirectory / on-chain anchors
|
|
46
|
+
const hub = new MemoryHub(); // app: BroadcastChannelTransport / MeshTransport
|
|
47
|
+
const alice = new ChatService('$alice', directory, hub.transport(), null); // null = no at-rest vault (Node)
|
|
48
|
+
await alice.start(seed); // derives identity, provisions Signal, publishes bundle
|
|
49
|
+
|
|
50
|
+
bob.openChat('$alice'); // outbound session from her published bundle
|
|
51
|
+
bob.send('$alice', 'hey — sealed all the way'); // E2E; relays only ever see ciphertext
|
|
52
|
+
alice.onMessage((m) => console.log(m.from, m.text));
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Handles are canonically `$`-prefixed (`$alice`); one wallet signature covers every handle the
|
|
56
|
+
wallet controls, and each handle gets a distinct key (HKDF, info = handle).
|
|
57
|
+
|
|
58
|
+
## Programmatic messages & the guardian payloads
|
|
59
|
+
|
|
60
|
+
Typed messages are `ContentMessage`s (`{ mime, body, meta }`) sent with `sendContent`. The four
|
|
61
|
+
SSR payloads ride the vendor MIME tree (`application/vnd.handle.<kind>+json`) and their
|
|
62
|
+
`shard`/`session` fields are **opaque** to chat:
|
|
63
|
+
|
|
64
|
+
```js
|
|
65
|
+
import { guardianInvite, guardianConsent, recoveryNotify, approvalCoordination, parseGuardian } from '@koralabs/handle-chat-sdk';
|
|
66
|
+
|
|
67
|
+
owner.sendContent('$gwen', guardianInvite({ secretRef, label: 'Wallet seed', shard })); // encrypted piece
|
|
68
|
+
gwen.sendContent('$olivia', guardianConsent({ secretRef, accept: true, // "the key is
|
|
69
|
+
gekPub: Buffer.from(gwen.myIdentityKey()).toString('base64') })); // handed over the medium"
|
|
70
|
+
owner.sendContent('$gwen', recoveryNotify({ secretRef, session })); // recovery starts
|
|
71
|
+
gwen.sendContent('$olivia', approvalCoordination({ secretRef, approve: true, shard })); // piece comes back
|
|
72
|
+
|
|
73
|
+
service.onMessage((m) => { const p = parseGuardian(m.content); if (p) handle(p.kind, p.value); });
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
The real Shamir shards, session blobs, and threshold crypto live in `@koralabs/kora-secrets-crypto`
|
|
77
|
+
/ secrets.handle.me — see its `lib/chat-medium.ts` for the production payload contents.
|
|
78
|
+
|
|
79
|
+
## In the browser
|
|
80
|
+
|
|
81
|
+
- Serve `assets/libsignal_bg.wasm` at exactly **`/public/libsignal_bg.wasm`** on your origin
|
|
82
|
+
(and allow `'wasm-unsafe-eval'` in `script-src` if you set a CSP).
|
|
83
|
+
- Same-origin tabs: `new ChatService(handle, new LocalStorageDirectory(), new BroadcastChannelTransport())`.
|
|
84
|
+
- Cross-origin / cross-device: `new MeshTransport(helperMultiaddr)` against chat.handle.me's mesh
|
|
85
|
+
helper (`node --import tsx mesh-helper/server.ts <port>` there); first contact travels by invite
|
|
86
|
+
link — `inviteUrl(origin, handle, service.myBundle())` on one side, `openChatWithBundle(parseInviteUrl(url))`
|
|
87
|
+
on the other. `qrSvg(url)` renders the QR.
|
|
88
|
+
- Persistence: omit the vault argument to get the encrypted-at-rest IndexedDB vault keyed by the
|
|
89
|
+
identity seed; pass `null` (tests/Node) to disable.
|
|
90
|
+
|
|
91
|
+
Living integrations: chat.handle.me (the full UI) and secrets.handle.me (`src/chat-client.ts` —
|
|
92
|
+
provisioning, invite links, guardian flows against this exact surface).
|
|
93
|
+
|
|
94
|
+
## License
|
|
95
|
+
|
|
96
|
+
AGPL-3.0-only — the SDK embeds [libsignal](https://github.com/signalapp/libsignal) (AGPLv3) via
|
|
97
|
+
chat.handle.me's `libsignal-wasm` build.
|
|
Binary file
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// Working example — the four SSR guardian payloads over chat, created programmatically:
|
|
2
|
+
//
|
|
3
|
+
// guardian-invite → guardian-consent → recovery-notify → approval-coordination
|
|
4
|
+
//
|
|
5
|
+
// Run from the repo root after `npm run build`: node examples/guardian-flow.mjs
|
|
6
|
+
//
|
|
7
|
+
// Chat is the MEDIUM: every payload rides an E2E session as application/vnd.handle.<kind>+json,
|
|
8
|
+
// and the `shard`/`session` fields are opaque base64 the SDK never interprets. The real Shamir
|
|
9
|
+
// shards, session blobs, and threshold crypto come from secrets.handle.me (@koralabs/kora-secrets-*);
|
|
10
|
+
// the demo bytes below just prove the transport contract round-trips them verbatim.
|
|
11
|
+
import { readFile } from 'node:fs/promises';
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
approvalCoordination,
|
|
15
|
+
ChatService,
|
|
16
|
+
deriveSeedFromWallet,
|
|
17
|
+
guardianConsent,
|
|
18
|
+
guardianInvite,
|
|
19
|
+
initSignalWasm,
|
|
20
|
+
MemoryDirectory,
|
|
21
|
+
MemoryHub,
|
|
22
|
+
parseGuardian,
|
|
23
|
+
recoveryNotify
|
|
24
|
+
} from '@koralabs/handle-chat-sdk';
|
|
25
|
+
|
|
26
|
+
await initSignalWasm({ module_or_path: await readFile(new URL('../assets/libsignal_bg.wasm', import.meta.url)) });
|
|
27
|
+
|
|
28
|
+
const walletSignData = (walletSecret) => async (_addressHex, payloadHex) => {
|
|
29
|
+
const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(`${walletSecret}|${payloadHex}`));
|
|
30
|
+
return { signature: Buffer.from(digest).toString('hex'), key: '' };
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const directory = new MemoryDirectory();
|
|
34
|
+
const hub = new MemoryHub();
|
|
35
|
+
const owner = new ChatService('$olivia', directory, hub.transport(), null);
|
|
36
|
+
await owner.start(await deriveSeedFromWallet(walletSignData('olivia-wallet'), 'e0' + '33'.repeat(28)));
|
|
37
|
+
const guardian = new ChatService('$gwen', directory, hub.transport(), null);
|
|
38
|
+
await guardian.start(await deriveSeedFromWallet(walletSignData('gwen-wallet'), 'e0' + '44'.repeat(28)));
|
|
39
|
+
|
|
40
|
+
// Route every inbound guardian payload to a promise queue, keyed by arrival order.
|
|
41
|
+
const guardianPayloads = (service) => {
|
|
42
|
+
const queue = [];
|
|
43
|
+
const waiters = [];
|
|
44
|
+
service.onMessage((m) => {
|
|
45
|
+
const p = parseGuardian(m.content);
|
|
46
|
+
if (!p) return;
|
|
47
|
+
const item = { from: m.from, ...p };
|
|
48
|
+
const w = waiters.shift();
|
|
49
|
+
if (w) w(item);
|
|
50
|
+
else queue.push(item);
|
|
51
|
+
});
|
|
52
|
+
return () => (queue.length ? Promise.resolve(queue.shift()) : new Promise((r) => waiters.push(r)));
|
|
53
|
+
};
|
|
54
|
+
const atGuardian = guardianPayloads(guardian);
|
|
55
|
+
const atOwner = guardianPayloads(owner);
|
|
56
|
+
|
|
57
|
+
owner.openChat('$gwen');
|
|
58
|
+
|
|
59
|
+
// 1. guardian-invite — the ask, then (after consent, in the real flow) the encrypted shard.
|
|
60
|
+
const secretRef = 'f0f06f776e6572'; // secrets.handle.me's policy id; the SDK just routes it
|
|
61
|
+
const shard = Buffer.from('demo-shard: in production this is an encrypted Shamir share').toString('base64');
|
|
62
|
+
owner.sendContent('$gwen', guardianInvite({ secretRef, label: 'Wallet seed', shard }));
|
|
63
|
+
const invite = await atGuardian();
|
|
64
|
+
console.log(`[$gwen] ${invite.kind} from ${invite.from}: guard “${invite.value.label}”`);
|
|
65
|
+
|
|
66
|
+
// 2. guardian-consent — accepting hands back the guardian's wallet-rooted identity key
|
|
67
|
+
// ("the key is handed over the medium"): SSR encrypts her real shard to exactly this key.
|
|
68
|
+
const gekPub = Buffer.from(guardian.myIdentityKey()).toString('base64');
|
|
69
|
+
guardian.sendContent('$olivia', guardianConsent({ secretRef, accept: true, label: invite.value.label, gekPub }));
|
|
70
|
+
const consent = await atOwner();
|
|
71
|
+
console.log(`[$olivia] ${consent.kind}: accept=${consent.value.accept}, gekPub ${Buffer.from(consent.value.gekPub, 'base64').length} bytes`);
|
|
72
|
+
|
|
73
|
+
// 3. recovery-notify — later, the owner starts a recovery; `session` carries the opaque
|
|
74
|
+
// recovery-session context the guardian's approval crypto needs.
|
|
75
|
+
const session = Buffer.from(JSON.stringify({ demo: 'session blob — policy ref + session id + session pub' })).toString('base64');
|
|
76
|
+
owner.sendContent('$gwen', recoveryNotify({ secretRef, label: 'Wallet seed', session }));
|
|
77
|
+
const notify = await atGuardian();
|
|
78
|
+
console.log(`[$gwen] ${notify.kind}: recovery of “${notify.value.label}” (session ${notify.value.session.length} b64 chars)`);
|
|
79
|
+
|
|
80
|
+
// 4. approval-coordination — the guardian approves and returns the (re-encrypted) piece.
|
|
81
|
+
guardian.sendContent('$olivia', approvalCoordination({ secretRef, approve: true, label: notify.value.label, shard: invite.value.shard }));
|
|
82
|
+
const approval = await atOwner();
|
|
83
|
+
const roundTripped = Buffer.from(approval.value.shard, 'base64').toString();
|
|
84
|
+
console.log(`[$olivia] ${approval.kind}: approve=${approval.value.approve}, shard intact=${roundTripped.startsWith('demo-shard')}`);
|
|
85
|
+
|
|
86
|
+
owner.stop();
|
|
87
|
+
guardian.stop();
|
|
88
|
+
console.log('✓ guardian flow complete — all four payloads round-tripped over the medium');
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// Working example — two handles talk end-to-end encrypted in ONE Node process: wallet-rooted
|
|
2
|
+
// identities (sign-to-derive), libsignal WASM sessions, and an in-memory transport/directory.
|
|
3
|
+
// No browser, no relay, no network. Run from the repo root after `npm run build`:
|
|
4
|
+
//
|
|
5
|
+
// node examples/quickstart.mjs
|
|
6
|
+
//
|
|
7
|
+
// In an app you swap the two Memory* seams for the real ones: LocalStorageDirectory +
|
|
8
|
+
// BroadcastChannelTransport (same-origin tabs) or MeshTransport (cross-origin, via the relay),
|
|
9
|
+
// and the signData stub for the connected CIP-30 wallet's `api.signData`.
|
|
10
|
+
import { readFile } from 'node:fs/promises';
|
|
11
|
+
|
|
12
|
+
import {
|
|
13
|
+
ChatService,
|
|
14
|
+
deriveSeedFromWallet,
|
|
15
|
+
initSignalWasm,
|
|
16
|
+
MemoryDirectory,
|
|
17
|
+
MemoryHub
|
|
18
|
+
} from '@koralabs/handle-chat-sdk';
|
|
19
|
+
|
|
20
|
+
// Node has no origin to fetch the WASM from — hand it the bytes. (Browsers skip this line;
|
|
21
|
+
// the default fetches /public/libsignal_bg.wasm from the serving origin.)
|
|
22
|
+
await initSignalWasm({ module_or_path: await readFile(new URL('../assets/libsignal_bg.wasm', import.meta.url)) });
|
|
23
|
+
|
|
24
|
+
// A deterministic stand-in for a CIP-30 wallet's signData: same "wallet", same signature, so the
|
|
25
|
+
// identity re-derives forever and is stored nowhere. Real apps pass the wallet API's signData.
|
|
26
|
+
const walletSignData = (walletSecret) => async (_addressHex, payloadHex) => {
|
|
27
|
+
const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(`${walletSecret}|${payloadHex}`));
|
|
28
|
+
return { signature: Buffer.from(digest).toString('hex'), key: '' };
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const directory = new MemoryDirectory();
|
|
32
|
+
const hub = new MemoryHub();
|
|
33
|
+
|
|
34
|
+
// One wallet signature each → seed → per-handle identity. `null` disables the IndexedDB vault
|
|
35
|
+
// (Node has none); apps omit the argument to get encrypted-at-rest persistence for free.
|
|
36
|
+
const aliceSeed = await deriveSeedFromWallet(walletSignData('alice-demo-wallet'), 'e0' + '11'.repeat(28));
|
|
37
|
+
const bobSeed = await deriveSeedFromWallet(walletSignData('bob-demo-wallet'), 'e0' + '22'.repeat(28));
|
|
38
|
+
|
|
39
|
+
const alice = new ChatService('$alice', directory, hub.transport(), null);
|
|
40
|
+
await alice.start(aliceSeed); // publishes her prekey bundle to the directory
|
|
41
|
+
|
|
42
|
+
const bob = new ChatService('$bob', directory, hub.transport(), null);
|
|
43
|
+
await bob.start(bobSeed);
|
|
44
|
+
|
|
45
|
+
// A tiny promise inbox so the example reads top-to-bottom.
|
|
46
|
+
const inbox = (service) => {
|
|
47
|
+
const queue = [];
|
|
48
|
+
const waiters = [];
|
|
49
|
+
service.onMessage((m) => {
|
|
50
|
+
const w = waiters.shift();
|
|
51
|
+
if (w) w(m);
|
|
52
|
+
else queue.push(m);
|
|
53
|
+
});
|
|
54
|
+
return () => (queue.length ? Promise.resolve(queue.shift()) : new Promise((r) => waiters.push(r)));
|
|
55
|
+
};
|
|
56
|
+
const aliceNext = inbox(alice);
|
|
57
|
+
const bobNext = inbox(bob);
|
|
58
|
+
|
|
59
|
+
// Bob opens the session by resolving Alice's published bundle (cold lookup). Across origins you'd
|
|
60
|
+
// use an invite link instead: inviteUrl(...) on one side, openChatWithBundle(parseInviteUrl(...)) on the other.
|
|
61
|
+
if (!bob.openChat('$alice')) throw new Error('directory lookup failed');
|
|
62
|
+
|
|
63
|
+
bob.send('$alice', 'hey $alice — sealed all the way');
|
|
64
|
+
const got = await aliceNext();
|
|
65
|
+
console.log(`[$alice] ${got.from}: ${got.text}`);
|
|
66
|
+
|
|
67
|
+
// Alice's reply needs no lookup — decrypting Bob's first message gave her a return session.
|
|
68
|
+
alice.send('$bob', 'sealed right back at you');
|
|
69
|
+
const reply = await bobNext();
|
|
70
|
+
console.log(`[$bob] ${reply.from}: ${reply.text}`);
|
|
71
|
+
|
|
72
|
+
alice.stop();
|
|
73
|
+
bob.stop();
|
|
74
|
+
console.log('✓ quickstart complete — two identities, one E2E round trip, zero infrastructure');
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* One end of a Signal session: a wallet-rooted identity + the in-memory Signal stores.
|
|
6
|
+
*/
|
|
7
|
+
export class Account {
|
|
8
|
+
private constructor();
|
|
9
|
+
free(): void;
|
|
10
|
+
[Symbol.dispose](): void;
|
|
11
|
+
/**
|
|
12
|
+
* Tier 2: the per-conversation labels `remote` deposits at FOR me — `prev ++ current ++ next` (3 × 32),
|
|
13
|
+
* covering a rotation boundary + clock skew. Directional: `from = peer, to = me`. I subscribe to the
|
|
14
|
+
* union of these (over all known contacts) plus my public first-contact slot (`myTopics`).
|
|
15
|
+
*/
|
|
16
|
+
convRecvTopics(remote: string, now_ms: number): Uint8Array;
|
|
17
|
+
/**
|
|
18
|
+
* Tier 2: the per-conversation label I deposit a message to `remote` at (current epoch only — the peer
|
|
19
|
+
* subscribes prev/cur/next). Directional: `from = me, to = peer`. Unguessable to anyone without one of
|
|
20
|
+
* the two identity private keys.
|
|
21
|
+
*/
|
|
22
|
+
convSendTopic(remote: string, now_ms: number): Uint8Array;
|
|
23
|
+
/**
|
|
24
|
+
* Generate + store a signed pre-key and a Kyber (PQXDH) pre-key, and return the serialized
|
|
25
|
+
* publishable bundle (this is what goes in the on-chain anchor). Signed-pre-key-only: no
|
|
26
|
+
* one-time pre-key, so the same anchor serves every sender.
|
|
27
|
+
*/
|
|
28
|
+
createBundle(): Uint8Array;
|
|
29
|
+
/**
|
|
30
|
+
* Decrypt a message from `remote` (the `[type_code] ++ body` produced by `encrypt`).
|
|
31
|
+
*/
|
|
32
|
+
decrypt(remote: string, msg: Uint8Array): Uint8Array;
|
|
33
|
+
/**
|
|
34
|
+
* Encrypt to `remote`. Returns `[type_code]` (1 = prekey, 2 = whisper) followed by the
|
|
35
|
+
* serialized Signal ciphertext.
|
|
36
|
+
*/
|
|
37
|
+
encrypt(remote: string, plaintext: Uint8Array, now_ms: number): Uint8Array;
|
|
38
|
+
/**
|
|
39
|
+
* Serialize the per-device session state for persistence: the Double-Ratchet `SessionRecord` and
|
|
40
|
+
* learned identity key for each known `remote`, plus our own signed + Kyber pre-keys (so a peer who
|
|
41
|
+
* processed our published anchor can still first-contact us after a reopen). The identity key pair
|
|
42
|
+
* itself is NOT included — it is re-derived from the wallet on the next sign-in, never stored. The
|
|
43
|
+
* caller encrypts this blob at rest under a wallet-derived key.
|
|
44
|
+
*/
|
|
45
|
+
exportState(remotes: string[]): Uint8Array;
|
|
46
|
+
/**
|
|
47
|
+
* Build an account from a 32-byte identity private key (derived in JS from the wallet/seed)
|
|
48
|
+
* plus a deterministic registration id. The key doubles as the Signal identity key.
|
|
49
|
+
*/
|
|
50
|
+
static fromIdentity(handle: string, identity_priv: Uint8Array, registration_id: number): Account;
|
|
51
|
+
/**
|
|
52
|
+
* Restore state produced by `exportState` into a freshly-created account (same wallet identity). Idempotent
|
|
53
|
+
* per record; re-running just overwrites with the same bytes.
|
|
54
|
+
*/
|
|
55
|
+
importState(blob: Uint8Array): void;
|
|
56
|
+
/**
|
|
57
|
+
* My routing topics for the current epoch and its neighbours (previous + next), so I keep receiving
|
|
58
|
+
* across a rotation boundary + minor clock skew. The relay never sees my handle — only these opaque,
|
|
59
|
+
* rotating labels. Returns `prev ++ current ++ next` (3 × 32 bytes). A peer deposits at my CURRENT
|
|
60
|
+
* label via `peerTopic`.
|
|
61
|
+
*/
|
|
62
|
+
myTopics(now_ms: number): Uint8Array;
|
|
63
|
+
/**
|
|
64
|
+
* The peer's identity public key as authenticated by their established session (33 bytes), or `None` if
|
|
65
|
+
* no session/identity for `remote`. This is the key the ratchet + libsignal's trusted-identity gate
|
|
66
|
+
* vouch for — the caller uses it as the per-conversation TRUSTED key (verify-once-then-warn): it survives
|
|
67
|
+
* a reopen via the persisted session state, independent of the live (mutable) on-chain anchor.
|
|
68
|
+
*/
|
|
69
|
+
peerIdentityKey(remote: string): Uint8Array | undefined;
|
|
70
|
+
/**
|
|
71
|
+
* A peer's CURRENT-epoch routing topic — the label I deposit a message at. Derived from the peer's
|
|
72
|
+
* identity key (held from their bundle or an inbound message) + the current epoch. Requires an
|
|
73
|
+
* established session/identity for `remote`.
|
|
74
|
+
*/
|
|
75
|
+
peerTopic(remote: string, now_ms: number): Uint8Array;
|
|
76
|
+
/**
|
|
77
|
+
* My presence-auth Ed25519 PUBLIC key (32 bytes). Goes in the published bundle so first-contact senders
|
|
78
|
+
* derive my public slot `HKDF(presence_auth_pub, epoch)`; the helper verifies my registrations against it.
|
|
79
|
+
*/
|
|
80
|
+
presenceAuthPub(): Uint8Array;
|
|
81
|
+
/**
|
|
82
|
+
* Process a peer's serialized bundle, establishing an outbound session to `remote`.
|
|
83
|
+
*/
|
|
84
|
+
processBundle(remote: string, bundle: Uint8Array, now_ms: number): void;
|
|
85
|
+
/**
|
|
86
|
+
* A PEER's current-epoch public first-contact slot from their presence-auth pub key (in their bundle):
|
|
87
|
+
* `HKDF(peer_presence_auth_pub, epoch)`. Lets a first-contact sender address the peer's public slot.
|
|
88
|
+
*/
|
|
89
|
+
publicSlotTopicFor(pa_pub: Uint8Array, now_ms: number): Uint8Array;
|
|
90
|
+
/**
|
|
91
|
+
* My PUBLIC first-contact slot labels for prev/cur/next epoch (3 × 32 bytes) — `HKDF(presence_auth_pub,
|
|
92
|
+
* epoch)`. Keyed by the presence-auth PUBLIC key (in my bundle) so the helper can bind a registration to
|
|
93
|
+
* it; a first-contact sender derives the same from my bundle. Replaces the identity-key-derived public
|
|
94
|
+
* slot once wired through.
|
|
95
|
+
*/
|
|
96
|
+
publicSlotTopics(now_ms: number): Uint8Array;
|
|
97
|
+
/**
|
|
98
|
+
* Sealed-sender decrypt. Opens the outer seal with our identity key ALONE (no sender hint on the
|
|
99
|
+
* wire), recovers the sender's handle + claimed identity key from the sealed certificate, decrypts
|
|
100
|
+
* the inner Signal message (which authenticates the sender via the ratchet), and enforces that the
|
|
101
|
+
* certificate's key equals the session-authenticated identity. The caller still cross-checks
|
|
102
|
+
* handle↔key against the on-chain anchor — that is the chain-as-CA trust decision.
|
|
103
|
+
*/
|
|
104
|
+
sealedReceive(ciphertext: Uint8Array, now_ms: number): SealedIncoming;
|
|
105
|
+
/**
|
|
106
|
+
* Sealed-sender encrypt to `remote`. The sender's handle rides inside an authenticated, sealed
|
|
107
|
+
* `UnidentifiedSenderMessageContent` — never on the wire — so a relay learns only the ciphertext.
|
|
108
|
+
* The certificate is self-signed by our identity key (chain-rooted, no Signal server). Returns the
|
|
109
|
+
* envelope body.
|
|
110
|
+
*/
|
|
111
|
+
sealedSend(remote: string, plaintext: Uint8Array, now_ms: number): Uint8Array;
|
|
112
|
+
/**
|
|
113
|
+
* Sign a presence registration: a standard Ed25519 signature (64 bytes) over `topic ‖ addr ‖ epoch_le`.
|
|
114
|
+
* The helper checks `topic == HKDF(presence_auth_pub, epoch)` and verifies this signature — so only the
|
|
115
|
+
* holder of the identity (hence the presence-auth key) can register the public slot (audit J).
|
|
116
|
+
*/
|
|
117
|
+
signPresence(topic: Uint8Array, addr: string, epoch: number): Uint8Array;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* What `sealedReceive` returns: the recovered sender handle, the certificate identity key (33-byte
|
|
122
|
+
* libsignal serialization, for the caller's anchor cross-check), and the decrypted plaintext.
|
|
123
|
+
*/
|
|
124
|
+
export class SealedIncoming {
|
|
125
|
+
private constructor();
|
|
126
|
+
free(): void;
|
|
127
|
+
[Symbol.dispose](): void;
|
|
128
|
+
readonly identityKey: Uint8Array;
|
|
129
|
+
readonly plaintext: Uint8Array;
|
|
130
|
+
readonly sender: string;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
134
|
+
|
|
135
|
+
export interface InitOutput {
|
|
136
|
+
readonly memory: WebAssembly.Memory;
|
|
137
|
+
readonly __wbg_account_free: (a: number, b: number) => void;
|
|
138
|
+
readonly __wbg_sealedincoming_free: (a: number, b: number) => void;
|
|
139
|
+
readonly account_convRecvTopics: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
140
|
+
readonly account_convSendTopic: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
141
|
+
readonly account_createBundle: (a: number, b: number) => void;
|
|
142
|
+
readonly account_decrypt: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
143
|
+
readonly account_encrypt: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
144
|
+
readonly account_exportState: (a: number, b: number, c: number, d: number) => void;
|
|
145
|
+
readonly account_fromIdentity: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
146
|
+
readonly account_importState: (a: number, b: number, c: number, d: number) => void;
|
|
147
|
+
readonly account_myTopics: (a: number, b: number, c: number) => void;
|
|
148
|
+
readonly account_peerIdentityKey: (a: number, b: number, c: number, d: number) => void;
|
|
149
|
+
readonly account_peerTopic: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
150
|
+
readonly account_presenceAuthPub: (a: number, b: number) => void;
|
|
151
|
+
readonly account_processBundle: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
152
|
+
readonly account_publicSlotTopicFor: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
153
|
+
readonly account_publicSlotTopics: (a: number, b: number, c: number) => void;
|
|
154
|
+
readonly account_sealedReceive: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
155
|
+
readonly account_sealedSend: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
156
|
+
readonly account_signPresence: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
157
|
+
readonly sealedincoming_identityKey: (a: number, b: number) => void;
|
|
158
|
+
readonly sealedincoming_plaintext: (a: number, b: number) => void;
|
|
159
|
+
readonly sealedincoming_sender: (a: number, b: number) => void;
|
|
160
|
+
readonly __wbindgen_export: (a: number, b: number) => number;
|
|
161
|
+
readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
|
162
|
+
readonly __wbindgen_export3: (a: number) => void;
|
|
163
|
+
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
164
|
+
readonly __wbindgen_export4: (a: number, b: number, c: number) => void;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
171
|
+
* a precompiled `WebAssembly.Module`.
|
|
172
|
+
*
|
|
173
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
174
|
+
*
|
|
175
|
+
* @returns {InitOutput}
|
|
176
|
+
*/
|
|
177
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
181
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
182
|
+
*
|
|
183
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
184
|
+
*
|
|
185
|
+
* @returns {Promise<InitOutput>}
|
|
186
|
+
*/
|
|
187
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|