@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
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The on-chain anchor codec: a handle's published Signal key-bundle, carried in Cardano transaction
|
|
3
|
+
* metadata (CIP-20-style), label 7368 → `[handle, ...64-char hex chunks of the bundle]`. Mirrors
|
|
4
|
+
* `poc/`'s `ChainAnchorStore` codec. Pure data — no chain or crypto deps, so it unit-tests in node.
|
|
5
|
+
*
|
|
6
|
+
* The bundle is `SignalEngine.createBundle()` output (idPub + signed pre-key + Kyber, self-signed by the
|
|
7
|
+
* identity key). What binds it to the handle is provenance: the anchor is published from the handle
|
|
8
|
+
* owner's address, so only the owner can write it. (Resolve verifies that — see the ChainAnchorStore.)
|
|
9
|
+
*/
|
|
10
|
+
export const ANCHOR_METADATA_LABEL = 7368n;
|
|
11
|
+
/** Cardano metadata strings cap at 64 bytes; hex is ASCII so 64 chars = 64 bytes. */
|
|
12
|
+
const CHUNK = 64;
|
|
13
|
+
const bytesToHex = (b) => Array.from(b, (x) => x.toString(16).padStart(2, "0")).join("");
|
|
14
|
+
const hexToBytes = (hex) => {
|
|
15
|
+
const clean = hex.length % 2 === 0 ? hex : `0${hex}`;
|
|
16
|
+
const out = new Uint8Array(clean.length / 2);
|
|
17
|
+
for (let i = 0; i < out.length; i++)
|
|
18
|
+
out[i] = parseInt(clean.slice(i * 2, i * 2 + 2), 16);
|
|
19
|
+
return out;
|
|
20
|
+
};
|
|
21
|
+
const chunk = (s, n) => {
|
|
22
|
+
const out = [];
|
|
23
|
+
for (let i = 0; i < s.length; i += n)
|
|
24
|
+
out.push(s.slice(i, i + n));
|
|
25
|
+
return out;
|
|
26
|
+
};
|
|
27
|
+
/** Build the metadata value for a handle's bundle: `[handle, ...hex chunks]`. */
|
|
28
|
+
export function encodeAnchorMetadata(handle, bundle) {
|
|
29
|
+
return [handle, ...chunk(bytesToHex(bundle), CHUNK)];
|
|
30
|
+
}
|
|
31
|
+
/** Decode a metadata value back into `{ handle, bundle }`, or null if it isn't a well-formed anchor. */
|
|
32
|
+
export function decodeAnchorMetadata(value) {
|
|
33
|
+
if (!Array.isArray(value) || value.length < 2)
|
|
34
|
+
return null;
|
|
35
|
+
const parts = value;
|
|
36
|
+
if (!parts.every((p) => typeof p === "string"))
|
|
37
|
+
return null;
|
|
38
|
+
const [handle, ...chunks] = parts;
|
|
39
|
+
const hex = chunks.join("");
|
|
40
|
+
if (!/^[0-9a-fA-F]*$/.test(hex) || hex.length === 0)
|
|
41
|
+
return null;
|
|
42
|
+
return { handle, bundle: hexToBytes(hex) };
|
|
43
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Large-blob media streaming. Inlining a multi-MB image/audio/video in one sealed message is wrong for the
|
|
3
|
+
* mesh (a giant ciphertext through the mailbox / WebRTC). Instead a blob is encrypted under a random
|
|
4
|
+
* per-blob key, **content-addressed** by the hash of its ciphertext, chunked, and streamed as:
|
|
5
|
+
* - one `blob-ref` payload (small JSON: ref, mime, name, size, key, iv, chunk count, the message id), and
|
|
6
|
+
* - N `blob-chunk` payloads (raw ciphertext bytes — no base64 bloat — tagged with ref + index).
|
|
7
|
+
* All ride the typed-message channel, so they're E2E for free. The recipient reassembles, verifies the
|
|
8
|
+
* hash, decrypts, and surfaces a normal media message. Per-blob encryption keeps the design ready for an
|
|
9
|
+
* out-of-band/relay blob store later (the chunks are already ciphertext, the key travels inline via Signal).
|
|
10
|
+
*/
|
|
11
|
+
import { type ContentMessage } from "./message";
|
|
12
|
+
export declare const BLOB_REF_KIND = "blob-ref";
|
|
13
|
+
export declare const BLOB_REF_MIME: string;
|
|
14
|
+
export declare const BLOB_CHUNK_MIME = "application/vnd.handle.blob-chunk";
|
|
15
|
+
export declare const BLOB_THRESHOLD: number;
|
|
16
|
+
export declare const CHUNK_SIZE: number;
|
|
17
|
+
export declare const MAX_BLOB_SIZE: number;
|
|
18
|
+
export declare const MAX_CHUNKS: number;
|
|
19
|
+
export interface BlobRef {
|
|
20
|
+
id: string;
|
|
21
|
+
ref: string;
|
|
22
|
+
mime: string;
|
|
23
|
+
name?: string;
|
|
24
|
+
size: number;
|
|
25
|
+
key: string;
|
|
26
|
+
iv: string;
|
|
27
|
+
chunks: number;
|
|
28
|
+
}
|
|
29
|
+
/** Encrypt + chunk a blob into a ref message + chunk messages (all typed, E2E via Signal). */
|
|
30
|
+
export declare function buildBlobMessages(id: string, mime: string, bytes: Uint8Array, name?: string): Promise<{
|
|
31
|
+
ref: ContentMessage;
|
|
32
|
+
chunks: ContentMessage[];
|
|
33
|
+
}>;
|
|
34
|
+
export declare const isBlobRef: (c: ContentMessage) => boolean;
|
|
35
|
+
export declare const isBlobChunk: (c: ContentMessage) => boolean;
|
|
36
|
+
export declare const isBlobPart: (c: ContentMessage) => boolean;
|
|
37
|
+
export declare const parseBlobRef: (c: ContentMessage) => BlobRef | null;
|
|
38
|
+
export declare class BlobAssembler {
|
|
39
|
+
#private;
|
|
40
|
+
accept(c: ContentMessage): Promise<ContentMessage | null>;
|
|
41
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Large-blob media streaming. Inlining a multi-MB image/audio/video in one sealed message is wrong for the
|
|
3
|
+
* mesh (a giant ciphertext through the mailbox / WebRTC). Instead a blob is encrypted under a random
|
|
4
|
+
* per-blob key, **content-addressed** by the hash of its ciphertext, chunked, and streamed as:
|
|
5
|
+
* - one `blob-ref` payload (small JSON: ref, mime, name, size, key, iv, chunk count, the message id), and
|
|
6
|
+
* - N `blob-chunk` payloads (raw ciphertext bytes — no base64 bloat — tagged with ref + index).
|
|
7
|
+
* All ride the typed-message channel, so they're E2E for free. The recipient reassembles, verifies the
|
|
8
|
+
* hash, decrypts, and surfaces a normal media message. Per-blob encryption keeps the design ready for an
|
|
9
|
+
* out-of-band/relay blob store later (the chunks are already ciphertext, the key travels inline via Signal).
|
|
10
|
+
*/
|
|
11
|
+
import { mediaMessage, jsonMime, jsonMessage, messageJson } from "./message.js";
|
|
12
|
+
export const BLOB_REF_KIND = "blob-ref";
|
|
13
|
+
export const BLOB_REF_MIME = jsonMime(BLOB_REF_KIND);
|
|
14
|
+
export const BLOB_CHUNK_MIME = "application/vnd.handle.blob-chunk";
|
|
15
|
+
export const BLOB_THRESHOLD = 32 * 1024; // bodies larger than this stream; smaller inline
|
|
16
|
+
export const CHUNK_SIZE = 16 * 1024;
|
|
17
|
+
// Anti-DoS limits — a malicious peer must not be able to exhaust memory via the reassembler.
|
|
18
|
+
export const MAX_BLOB_SIZE = 25 * 1024 * 1024; // largest blob we'll reassemble (~25 MB)
|
|
19
|
+
export const MAX_CHUNKS = Math.ceil(MAX_BLOB_SIZE / CHUNK_SIZE) + 2;
|
|
20
|
+
const MAX_PENDING_BLOBS = 24; // concurrent in-flight blobs
|
|
21
|
+
const MAX_PENDING_BYTES = 48 * 1024 * 1024; // total buffered chunk bytes across all in-flight blobs
|
|
22
|
+
const toHex = (b) => Array.from(b, (x) => x.toString(16).padStart(2, "0")).join("");
|
|
23
|
+
const toB64 = (b) => {
|
|
24
|
+
let s = "";
|
|
25
|
+
for (const x of b)
|
|
26
|
+
s += String.fromCharCode(x);
|
|
27
|
+
return btoa(s);
|
|
28
|
+
};
|
|
29
|
+
const fromB64 = (s) => Uint8Array.from(atob(s), (c) => c.charCodeAt(0));
|
|
30
|
+
/** Guaranteed ArrayBuffer-backed copy — WebCrypto's BufferSource rejects the generic Uint8Array under TS 5.7. */
|
|
31
|
+
const ab = (x) => {
|
|
32
|
+
const out = new Uint8Array(x.byteLength);
|
|
33
|
+
out.set(x);
|
|
34
|
+
return out;
|
|
35
|
+
};
|
|
36
|
+
const concat = (parts) => {
|
|
37
|
+
const out = new Uint8Array(parts.reduce((n, p) => n + p.length, 0));
|
|
38
|
+
let i = 0;
|
|
39
|
+
for (const p of parts) {
|
|
40
|
+
out.set(p, i);
|
|
41
|
+
i += p.length;
|
|
42
|
+
}
|
|
43
|
+
return out;
|
|
44
|
+
};
|
|
45
|
+
async function seal(plain) {
|
|
46
|
+
const key = crypto.getRandomValues(new Uint8Array(32));
|
|
47
|
+
const iv = crypto.getRandomValues(new Uint8Array(12));
|
|
48
|
+
const ck = await crypto.subtle.importKey("raw", ab(key), "AES-GCM", false, ["encrypt"]);
|
|
49
|
+
const ct = new Uint8Array(await crypto.subtle.encrypt({ name: "AES-GCM", iv: ab(iv) }, ck, ab(plain)));
|
|
50
|
+
return { ct, key, iv };
|
|
51
|
+
}
|
|
52
|
+
async function open(ct, key, iv) {
|
|
53
|
+
const ck = await crypto.subtle.importKey("raw", ab(key), "AES-GCM", false, ["decrypt"]);
|
|
54
|
+
return new Uint8Array(await crypto.subtle.decrypt({ name: "AES-GCM", iv: ab(iv) }, ck, ab(ct)));
|
|
55
|
+
}
|
|
56
|
+
const hash = async (b) => toHex(new Uint8Array(await crypto.subtle.digest("SHA-256", ab(b))));
|
|
57
|
+
/** Encrypt + chunk a blob into a ref message + chunk messages (all typed, E2E via Signal). */
|
|
58
|
+
export async function buildBlobMessages(id, mime, bytes, name) {
|
|
59
|
+
const { ct, key, iv } = await seal(bytes);
|
|
60
|
+
const ref = await hash(ct);
|
|
61
|
+
const parts = [];
|
|
62
|
+
for (let o = 0; o < ct.length; o += CHUNK_SIZE)
|
|
63
|
+
parts.push(ct.subarray(o, o + CHUNK_SIZE));
|
|
64
|
+
const refMsg = jsonMessage(BLOB_REF_KIND, {
|
|
65
|
+
id,
|
|
66
|
+
ref,
|
|
67
|
+
mime,
|
|
68
|
+
name,
|
|
69
|
+
size: bytes.length,
|
|
70
|
+
key: toB64(key),
|
|
71
|
+
iv: toB64(iv),
|
|
72
|
+
chunks: parts.length,
|
|
73
|
+
});
|
|
74
|
+
const chunks = parts.map((c, i) => mediaMessage(BLOB_CHUNK_MIME, c, { ref, i: String(i) }));
|
|
75
|
+
return { ref: refMsg, chunks };
|
|
76
|
+
}
|
|
77
|
+
export const isBlobRef = (c) => c.mime === BLOB_REF_MIME;
|
|
78
|
+
export const isBlobChunk = (c) => c.mime === BLOB_CHUNK_MIME;
|
|
79
|
+
export const isBlobPart = (c) => isBlobRef(c) || isBlobChunk(c);
|
|
80
|
+
export const parseBlobRef = (c) => (isBlobRef(c) ? messageJson(c) : null);
|
|
81
|
+
export class BlobAssembler {
|
|
82
|
+
#pending = new Map();
|
|
83
|
+
#totalBytes = 0;
|
|
84
|
+
async accept(c) {
|
|
85
|
+
const refMeta = parseBlobRef(c);
|
|
86
|
+
if (refMeta) {
|
|
87
|
+
// Reject implausible refs up front (anti-DoS): bounded chunk count + declared size.
|
|
88
|
+
if (!Number.isInteger(refMeta.chunks) || refMeta.chunks < 1 || refMeta.chunks > MAX_CHUNKS)
|
|
89
|
+
return null;
|
|
90
|
+
if (!Number.isInteger(refMeta.size) || refMeta.size < 0 || refMeta.size > MAX_BLOB_SIZE)
|
|
91
|
+
return null;
|
|
92
|
+
const e = this.#pending.get(refMeta.ref) ?? this.#fresh(refMeta.ref);
|
|
93
|
+
e.meta = refMeta;
|
|
94
|
+
return this.#tryComplete(refMeta.ref);
|
|
95
|
+
}
|
|
96
|
+
if (isBlobChunk(c)) {
|
|
97
|
+
const ref = c.meta?.ref;
|
|
98
|
+
const i = Number(c.meta?.i);
|
|
99
|
+
if (!ref || !Number.isInteger(i) || i < 0 || i >= MAX_CHUNKS || c.body.length > CHUNK_SIZE)
|
|
100
|
+
return null;
|
|
101
|
+
const e = this.#pending.get(ref) ?? this.#fresh(ref);
|
|
102
|
+
if (e.meta && i >= e.meta.chunks)
|
|
103
|
+
return null; // index past the declared count
|
|
104
|
+
if (!e.parts.has(i)) {
|
|
105
|
+
e.parts.set(i, c.body);
|
|
106
|
+
e.bytes += c.body.length;
|
|
107
|
+
this.#totalBytes += c.body.length;
|
|
108
|
+
this.#evict();
|
|
109
|
+
}
|
|
110
|
+
return this.#tryComplete(ref);
|
|
111
|
+
}
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
#fresh(ref) {
|
|
115
|
+
const e = { parts: new Map(), bytes: 0 };
|
|
116
|
+
this.#pending.set(ref, e);
|
|
117
|
+
return e;
|
|
118
|
+
}
|
|
119
|
+
#drop(ref) {
|
|
120
|
+
const e = this.#pending.get(ref);
|
|
121
|
+
if (e) {
|
|
122
|
+
this.#totalBytes -= e.bytes;
|
|
123
|
+
this.#pending.delete(ref);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/** Evict oldest in-flight blobs until within the concurrent-blob + total-byte caps. */
|
|
127
|
+
#evict() {
|
|
128
|
+
while (this.#pending.size > MAX_PENDING_BLOBS || this.#totalBytes > MAX_PENDING_BYTES) {
|
|
129
|
+
const oldest = this.#pending.keys().next().value;
|
|
130
|
+
if (oldest === undefined)
|
|
131
|
+
break;
|
|
132
|
+
this.#drop(oldest);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
async #tryComplete(ref) {
|
|
136
|
+
const e = this.#pending.get(ref);
|
|
137
|
+
if (!e?.meta || e.parts.size < e.meta.chunks)
|
|
138
|
+
return null;
|
|
139
|
+
const ct = concat(Array.from({ length: e.meta.chunks }, (_, i) => e.parts.get(i) ?? new Uint8Array(0)));
|
|
140
|
+
this.#drop(ref);
|
|
141
|
+
if ((await hash(ct)) !== ref)
|
|
142
|
+
return null; // integrity failure — drop
|
|
143
|
+
const plain = await open(ct, fromB64(e.meta.key), fromB64(e.meta.iv));
|
|
144
|
+
return mediaMessage(e.meta.mime, plain, { name: e.meta.name ?? "", id: e.meta.id });
|
|
145
|
+
}
|
|
146
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chain-as-directory resolution (read side): given a handle, find its published Signal key-bundle on
|
|
3
|
+
* Cardano. Fetch-only — Handle API for handle→address, Blockfrost for the address's anchor metadata —
|
|
4
|
+
* so it stays browser-light (no @cardano-sdk in the app bundle). The bundle is bound to the handle by
|
|
5
|
+
* provenance: it sits in a tx from the handle's own resolved address.
|
|
6
|
+
*
|
|
7
|
+
* Publish (the write side) is intentionally NOT here — building a Cardano tx in the browser means
|
|
8
|
+
* bundling @cardano-sdk (heavy) or a backend tx-builder; that's an open architecture decision.
|
|
9
|
+
*/
|
|
10
|
+
export interface ChainAnchorConfig {
|
|
11
|
+
env: "preview" | "preprod" | "mainnet";
|
|
12
|
+
blockfrostApiKey: string;
|
|
13
|
+
/** Injectable for tests; defaults to global fetch. */
|
|
14
|
+
fetchImpl?: typeof fetch;
|
|
15
|
+
}
|
|
16
|
+
export declare class ChainAnchorStore {
|
|
17
|
+
private readonly apiBase;
|
|
18
|
+
private readonly bfBase;
|
|
19
|
+
private readonly blockfrostApiKey;
|
|
20
|
+
private readonly fetchImpl;
|
|
21
|
+
constructor(cfg: ChainAnchorConfig);
|
|
22
|
+
/** Resolve a handle's published bundle from chain (newest anchor wins), or null if none. */
|
|
23
|
+
resolve(handle: string, max?: number): Promise<Uint8Array | null>;
|
|
24
|
+
/** Resolve by a known address (skips the Handle API lookup). */
|
|
25
|
+
resolveByAddress(address: string, handle: string, max?: number): Promise<Uint8Array | null>;
|
|
26
|
+
/** handle → the address its NFT resolves to (where its owner publishes the anchor). */
|
|
27
|
+
private handleAddress;
|
|
28
|
+
private bf;
|
|
29
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { decodeAnchorMetadata, ANCHOR_METADATA_LABEL } from "./anchor.js";
|
|
2
|
+
export class ChainAnchorStore {
|
|
3
|
+
apiBase;
|
|
4
|
+
bfBase;
|
|
5
|
+
blockfrostApiKey;
|
|
6
|
+
fetchImpl;
|
|
7
|
+
constructor(cfg) {
|
|
8
|
+
this.apiBase = `https://${cfg.env === "mainnet" ? "" : `${cfg.env}.`}api.handle.me`;
|
|
9
|
+
this.bfBase = `https://cardano-${cfg.env}.blockfrost.io/api/v0`;
|
|
10
|
+
this.blockfrostApiKey = cfg.blockfrostApiKey;
|
|
11
|
+
this.fetchImpl = cfg.fetchImpl ?? fetch;
|
|
12
|
+
}
|
|
13
|
+
/** Resolve a handle's published bundle from chain (newest anchor wins), or null if none. */
|
|
14
|
+
async resolve(handle, max = 25) {
|
|
15
|
+
const address = await this.handleAddress(handle);
|
|
16
|
+
if (!address)
|
|
17
|
+
return null;
|
|
18
|
+
return this.resolveByAddress(address, handle, max);
|
|
19
|
+
}
|
|
20
|
+
/** Resolve by a known address (skips the Handle API lookup). */
|
|
21
|
+
async resolveByAddress(address, handle, max = 25) {
|
|
22
|
+
const txs = (await this.bf(`/addresses/${address}/transactions?order=desc&count=${max}`));
|
|
23
|
+
for (const { tx_hash } of txs) {
|
|
24
|
+
const md = (await this.bf(`/txs/${tx_hash}/metadata`));
|
|
25
|
+
const entry = md.find((m) => String(m.label) === String(ANCHOR_METADATA_LABEL));
|
|
26
|
+
if (!entry)
|
|
27
|
+
continue;
|
|
28
|
+
const decoded = decodeAnchorMetadata(entry.json_metadata);
|
|
29
|
+
if (decoded && decoded.handle === handle)
|
|
30
|
+
return decoded.bundle;
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
/** handle → the address its NFT resolves to (where its owner publishes the anchor). */
|
|
35
|
+
async handleAddress(handle) {
|
|
36
|
+
const name = handle.replace(/^\$/, "");
|
|
37
|
+
const res = await this.fetchImpl(`${this.apiBase}/handles/${name}`);
|
|
38
|
+
if (!res.ok)
|
|
39
|
+
return null;
|
|
40
|
+
const data = (await res.json());
|
|
41
|
+
return data.resolved_addresses?.ada ?? null;
|
|
42
|
+
}
|
|
43
|
+
async bf(path) {
|
|
44
|
+
const res = await this.fetchImpl(`${this.bfBase}${path}`, {
|
|
45
|
+
headers: { project_id: this.blockfrostApiKey },
|
|
46
|
+
});
|
|
47
|
+
if (!res.ok)
|
|
48
|
+
throw new Error(`Blockfrost ${path}: ${res.status}`);
|
|
49
|
+
return res.json();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The anchor directory seam: publish/look up a handle's published Signal bundle.
|
|
3
|
+
* DEMO impl = localStorage (shared across same-origin tabs). Production swaps in the on-chain
|
|
4
|
+
* `ChainAnchorStore` (Cardano preview) — same interface.
|
|
5
|
+
*/
|
|
6
|
+
export interface Directory {
|
|
7
|
+
publish(handle: string, bundle: Uint8Array): void;
|
|
8
|
+
resolve(handle: string): Uint8Array | null;
|
|
9
|
+
}
|
|
10
|
+
export declare class LocalStorageDirectory implements Directory {
|
|
11
|
+
private key;
|
|
12
|
+
publish(handle: string, bundle: Uint8Array): void;
|
|
13
|
+
resolve(handle: string): Uint8Array | null;
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { hexToBytes } from "./identity.js";
|
|
2
|
+
const bytesToHex = (b) => Array.from(b, (x) => x.toString(16).padStart(2, "0")).join("");
|
|
3
|
+
export class LocalStorageDirectory {
|
|
4
|
+
key(handle) {
|
|
5
|
+
return `handlechat:bundle:${handle}`;
|
|
6
|
+
}
|
|
7
|
+
publish(handle, bundle) {
|
|
8
|
+
localStorage.setItem(this.key(handle), bytesToHex(bundle));
|
|
9
|
+
}
|
|
10
|
+
resolve(handle) {
|
|
11
|
+
const hex = localStorage.getItem(this.key(handle));
|
|
12
|
+
return hex ? hexToBytes(hex) : null;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The guardian protocol — Social Secret Recovery (secrets.handle.me) riding on chat. chat is the MEDIUM:
|
|
3
|
+
* it provides handle-addressed E2E sessions + these structured payloads; the SSR crypto (Shamir/threshold
|
|
4
|
+
* splitting, on-chain guardian policies) lives in secrets.handle.me. The `shard` here is OPAQUE to chat —
|
|
5
|
+
* a guardian holds whatever bytes the principal hands it and returns them verbatim on an approved recovery.
|
|
6
|
+
*
|
|
7
|
+
* Flow: principal → `guardian-invite` (with a shard) → guardian → `guardian-consent` (accept/decline).
|
|
8
|
+
* Later, recovering user → `recovery-notify` → each guardian → `approval-coordination` (returning the shard).
|
|
9
|
+
* Built on the typed-message foundation — each payload is `application/vnd.handle.<kind>+json`, so it's
|
|
10
|
+
* E2E-encrypted for free and a relay sees only ciphertext.
|
|
11
|
+
*/
|
|
12
|
+
import { type ContentMessage } from "./message";
|
|
13
|
+
export declare const GUARDIAN_KINDS: readonly ["guardian-invite", "guardian-consent", "recovery-notify", "approval-coordination"];
|
|
14
|
+
export type GuardianKind = (typeof GUARDIAN_KINDS)[number];
|
|
15
|
+
/** Principal asks a candidate to guard a secret; `shard` is the opaque piece the guardian will hold. */
|
|
16
|
+
export interface GuardianInvite {
|
|
17
|
+
secretRef: string;
|
|
18
|
+
label?: string;
|
|
19
|
+
shard?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface GuardianConsent {
|
|
22
|
+
secretRef: string;
|
|
23
|
+
accept: boolean;
|
|
24
|
+
label?: string;
|
|
25
|
+
gekPub?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface RecoveryNotify {
|
|
28
|
+
secretRef: string;
|
|
29
|
+
label?: string;
|
|
30
|
+
session?: string;
|
|
31
|
+
}
|
|
32
|
+
export interface ApprovalCoordination {
|
|
33
|
+
secretRef: string;
|
|
34
|
+
approve: boolean;
|
|
35
|
+
label?: string;
|
|
36
|
+
shard?: string;
|
|
37
|
+
}
|
|
38
|
+
export type GuardianPayload = {
|
|
39
|
+
kind: "guardian-invite";
|
|
40
|
+
value: GuardianInvite;
|
|
41
|
+
} | {
|
|
42
|
+
kind: "guardian-consent";
|
|
43
|
+
value: GuardianConsent;
|
|
44
|
+
} | {
|
|
45
|
+
kind: "recovery-notify";
|
|
46
|
+
value: RecoveryNotify;
|
|
47
|
+
} | {
|
|
48
|
+
kind: "approval-coordination";
|
|
49
|
+
value: ApprovalCoordination;
|
|
50
|
+
};
|
|
51
|
+
export declare const guardianInvite: (v: GuardianInvite) => ContentMessage;
|
|
52
|
+
export declare const guardianConsent: (v: GuardianConsent) => ContentMessage;
|
|
53
|
+
export declare const recoveryNotify: (v: RecoveryNotify) => ContentMessage;
|
|
54
|
+
export declare const approvalCoordination: (v: ApprovalCoordination) => ContentMessage;
|
|
55
|
+
export declare const isGuardian: (c: ContentMessage) => boolean;
|
|
56
|
+
/** Parse a typed message into a guardian payload, or null if it isn't one. The body is peer-controlled,
|
|
57
|
+
* so malformed JSON is "not a guardian payload" (null), never an exception that breaks rendering. */
|
|
58
|
+
export declare function parseGuardian(c: ContentMessage): GuardianPayload | null;
|
|
59
|
+
/** A thread entry as far as guardian lookups care. */
|
|
60
|
+
export interface ThreadEntry {
|
|
61
|
+
from: string;
|
|
62
|
+
content: ContentMessage;
|
|
63
|
+
}
|
|
64
|
+
/** The human label from the invite that introduced `secretRef` (so reply cards read well). */
|
|
65
|
+
export declare const inviteLabel: (thread: readonly ThreadEntry[], secretRef: string) => string | undefined;
|
|
66
|
+
/** The opaque shard handed over in the guardian-invite for `secretRef`. A shard-bearing invite wins over a
|
|
67
|
+
* shard-less consent ask with the same ref. */
|
|
68
|
+
export declare const heldShard: (thread: readonly ThreadEntry[], secretRef: string) => string | undefined;
|
|
69
|
+
/** The most recent guardian-invite `me` sent in this thread, for starting recovery. */
|
|
70
|
+
export declare function findMyInvite(thread: readonly ThreadEntry[], me: string | null): {
|
|
71
|
+
secretRef: string;
|
|
72
|
+
label?: string;
|
|
73
|
+
} | null;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The guardian protocol — Social Secret Recovery (secrets.handle.me) riding on chat. chat is the MEDIUM:
|
|
3
|
+
* it provides handle-addressed E2E sessions + these structured payloads; the SSR crypto (Shamir/threshold
|
|
4
|
+
* splitting, on-chain guardian policies) lives in secrets.handle.me. The `shard` here is OPAQUE to chat —
|
|
5
|
+
* a guardian holds whatever bytes the principal hands it and returns them verbatim on an approved recovery.
|
|
6
|
+
*
|
|
7
|
+
* Flow: principal → `guardian-invite` (with a shard) → guardian → `guardian-consent` (accept/decline).
|
|
8
|
+
* Later, recovering user → `recovery-notify` → each guardian → `approval-coordination` (returning the shard).
|
|
9
|
+
* Built on the typed-message foundation — each payload is `application/vnd.handle.<kind>+json`, so it's
|
|
10
|
+
* E2E-encrypted for free and a relay sees only ciphertext.
|
|
11
|
+
*/
|
|
12
|
+
import { jsonMessage, jsonMime, messageJson } from "./message.js";
|
|
13
|
+
export const GUARDIAN_KINDS = ["guardian-invite", "guardian-consent", "recovery-notify", "approval-coordination"];
|
|
14
|
+
// ---- builders (→ typed ContentMessage) ----
|
|
15
|
+
export const guardianInvite = (v) => jsonMessage("guardian-invite", v);
|
|
16
|
+
export const guardianConsent = (v) => jsonMessage("guardian-consent", v);
|
|
17
|
+
export const recoveryNotify = (v) => jsonMessage("recovery-notify", v);
|
|
18
|
+
export const approvalCoordination = (v) => jsonMessage("approval-coordination", v);
|
|
19
|
+
const KIND_BY_MIME = new Map(GUARDIAN_KINDS.map((k) => [jsonMime(k), k]));
|
|
20
|
+
export const isGuardian = (c) => KIND_BY_MIME.has(c.mime);
|
|
21
|
+
/** Parse a typed message into a guardian payload, or null if it isn't one. The body is peer-controlled,
|
|
22
|
+
* so malformed JSON is "not a guardian payload" (null), never an exception that breaks rendering. */
|
|
23
|
+
export function parseGuardian(c) {
|
|
24
|
+
const kind = KIND_BY_MIME.get(c.mime);
|
|
25
|
+
if (!kind)
|
|
26
|
+
return null;
|
|
27
|
+
let value;
|
|
28
|
+
try {
|
|
29
|
+
value = messageJson(c);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
if (value === null || typeof value !== "object")
|
|
35
|
+
return null;
|
|
36
|
+
return { kind, value };
|
|
37
|
+
}
|
|
38
|
+
const invitesFor = (thread, secretRef) => thread.flatMap((m) => {
|
|
39
|
+
const p = parseGuardian(m.content);
|
|
40
|
+
return p?.kind === "guardian-invite" && p.value.secretRef === secretRef ? [{ from: m.from, value: p.value }] : [];
|
|
41
|
+
});
|
|
42
|
+
/** The human label from the invite that introduced `secretRef` (so reply cards read well). */
|
|
43
|
+
export const inviteLabel = (thread, secretRef) => invitesFor(thread, secretRef).find((i) => i.value.label)?.value.label;
|
|
44
|
+
/** The opaque shard handed over in the guardian-invite for `secretRef`. A shard-bearing invite wins over a
|
|
45
|
+
* shard-less consent ask with the same ref. */
|
|
46
|
+
export const heldShard = (thread, secretRef) => invitesFor(thread, secretRef).find((i) => i.value.shard)?.value.shard;
|
|
47
|
+
/** The most recent guardian-invite `me` sent in this thread, for starting recovery. */
|
|
48
|
+
export function findMyInvite(thread, me) {
|
|
49
|
+
for (let i = thread.length - 1; i >= 0; i--) {
|
|
50
|
+
const p = parseGuardian(thread[i].content);
|
|
51
|
+
if (p?.kind === "guardian-invite" && thread[i].from === me)
|
|
52
|
+
return { secretRef: p.value.secretRef, label: p.value.label };
|
|
53
|
+
}
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export interface DerivedIdentity {
|
|
2
|
+
priv: Uint8Array;
|
|
3
|
+
registrationId: number;
|
|
4
|
+
}
|
|
5
|
+
export declare function deriveIdentity(seed: Uint8Array, handle: string): Promise<DerivedIdentity>;
|
|
6
|
+
/** Hex string → bytes. */
|
|
7
|
+
export declare const hexToBytes: (hex: string) => Uint8Array;
|
|
8
|
+
/** The handle-independent message a wallet signs to derive its chat identity. Must stay identical across
|
|
9
|
+
* chat and secrets.handle.me so a handle has ONE identity key everywhere. */
|
|
10
|
+
export declare const IDENTITY_MESSAGE = "koralabs:handle-identity:derive:v1";
|
|
11
|
+
/** A CIP-30 data signature (COSE_Sign1 + COSE_Key, both hex). */
|
|
12
|
+
export interface DataSignature {
|
|
13
|
+
signature: string;
|
|
14
|
+
key: string;
|
|
15
|
+
}
|
|
16
|
+
/** The slice of CIP-30 we need: sign arbitrary data with the wallet key (CIP-8). */
|
|
17
|
+
export type SignData = (addressHex: string, payloadHex: string) => Promise<DataSignature>;
|
|
18
|
+
/**
|
|
19
|
+
* Sign-to-derive: the identity seed is the wallet's signature over {@link IDENTITY_MESSAGE} at the stake
|
|
20
|
+
* address. Re-signing reproduces it (deterministic wallets), so nothing is stored. The handle is folded
|
|
21
|
+
* in later by {@link deriveIdentity}, so one signature covers every handle the wallet controls.
|
|
22
|
+
*/
|
|
23
|
+
export declare function deriveSeedFromWallet(signData: SignData, stakeAddressHex: string): Promise<Uint8Array>;
|
|
24
|
+
/**
|
|
25
|
+
* Enroll-time guard: a wallet that randomizes its signatures can't reproduce the identity on a later
|
|
26
|
+
* visit, silently orphaning every session. Sign the same message twice and fail loudly if they differ.
|
|
27
|
+
*/
|
|
28
|
+
export declare function assertDeterministicSigning(signData: SignData, stakeAddressHex: string): Promise<void>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Derive the wallet-rooted chat identity in the browser (WebCrypto HKDF → 32-byte key for the WASM
|
|
3
|
+
* SignalEngine), byte-compatible with `poc/`'s derivation (same salt + info=handle).
|
|
4
|
+
*
|
|
5
|
+
* The seed is the wallet's signature over a fixed, handle-independent message at its stake address
|
|
6
|
+
* (sign-to-derive). It is stored nowhere — re-signing reproduces it. One signature serves all of a
|
|
7
|
+
* wallet's handles; `deriveIdentity(seed, handle)` makes each handle's key distinct.
|
|
8
|
+
*/
|
|
9
|
+
const enc = new TextEncoder();
|
|
10
|
+
const SALT = enc.encode("koralabs:handle-identity:x25519:v1");
|
|
11
|
+
async function hkdf(seed, info, lenBytes) {
|
|
12
|
+
const key = await crypto.subtle.importKey("raw", new Uint8Array(seed), "HKDF", false, ["deriveBits"]);
|
|
13
|
+
const bits = await crypto.subtle.deriveBits({ name: "HKDF", hash: "SHA-256", salt: new Uint8Array(SALT), info: new Uint8Array(enc.encode(info)) }, key, lenBytes * 8);
|
|
14
|
+
return new Uint8Array(bits);
|
|
15
|
+
}
|
|
16
|
+
export async function deriveIdentity(seed, handle) {
|
|
17
|
+
const priv = await hkdf(seed, handle, 32);
|
|
18
|
+
const [hi = 0, lo = 0] = await hkdf(seed, `${handle}:regid`, 2);
|
|
19
|
+
return { priv, registrationId: (((hi << 8) | lo) % 16383) + 1 };
|
|
20
|
+
}
|
|
21
|
+
/** Hex string → bytes. */
|
|
22
|
+
export const hexToBytes = (hex) => {
|
|
23
|
+
const clean = hex.length % 2 === 0 ? hex : `0${hex}`;
|
|
24
|
+
const out = new Uint8Array(clean.length / 2);
|
|
25
|
+
for (let i = 0; i < out.length; i++)
|
|
26
|
+
out[i] = parseInt(clean.slice(i * 2, i * 2 + 2), 16);
|
|
27
|
+
return out;
|
|
28
|
+
};
|
|
29
|
+
/** The handle-independent message a wallet signs to derive its chat identity. Must stay identical across
|
|
30
|
+
* chat and secrets.handle.me so a handle has ONE identity key everywhere. */
|
|
31
|
+
export const IDENTITY_MESSAGE = "koralabs:handle-identity:derive:v1";
|
|
32
|
+
const utf8ToHex = (s) => Array.from(enc.encode(s), (b) => b.toString(16).padStart(2, "0")).join("");
|
|
33
|
+
/**
|
|
34
|
+
* Sign-to-derive: the identity seed is the wallet's signature over {@link IDENTITY_MESSAGE} at the stake
|
|
35
|
+
* address. Re-signing reproduces it (deterministic wallets), so nothing is stored. The handle is folded
|
|
36
|
+
* in later by {@link deriveIdentity}, so one signature covers every handle the wallet controls.
|
|
37
|
+
*/
|
|
38
|
+
export async function deriveSeedFromWallet(signData, stakeAddressHex) {
|
|
39
|
+
const { signature } = await signData(stakeAddressHex, utf8ToHex(IDENTITY_MESSAGE));
|
|
40
|
+
if (!signature)
|
|
41
|
+
throw new Error("wallet returned an empty signature");
|
|
42
|
+
return hexToBytes(signature);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Enroll-time guard: a wallet that randomizes its signatures can't reproduce the identity on a later
|
|
46
|
+
* visit, silently orphaning every session. Sign the same message twice and fail loudly if they differ.
|
|
47
|
+
*/
|
|
48
|
+
export async function assertDeterministicSigning(signData, stakeAddressHex) {
|
|
49
|
+
const payload = utf8ToHex(IDENTITY_MESSAGE);
|
|
50
|
+
const [a, b] = await Promise.all([signData(stakeAddressHex, payload), signData(stakeAddressHex, payload)]);
|
|
51
|
+
if (a.signature !== b.signature) {
|
|
52
|
+
throw new Error("This wallet produces a different signature each time, so it can't reproduce your chat identity. " +
|
|
53
|
+
"Use a wallet with deterministic (RFC 8032) signing.");
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare function encodeInvite(handle: string, bundle: Uint8Array): string;
|
|
2
|
+
export declare function decodeInvite(payload: string): {
|
|
3
|
+
handle: string;
|
|
4
|
+
bundle: Uint8Array;
|
|
5
|
+
};
|
|
6
|
+
/** A shareable invite URL: `<origin>/#i=<payload>`. */
|
|
7
|
+
export declare const inviteUrl: (origin: string, handle: string, bundle: Uint8Array) => string;
|
|
8
|
+
/** Pull an invite out of a URL (or null if there isn't one). */
|
|
9
|
+
export declare function parseInviteUrl(url: string): {
|
|
10
|
+
handle: string;
|
|
11
|
+
bundle: Uint8Array;
|
|
12
|
+
} | null;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Out-of-band invite: the no-transaction first-contact path. An invite carries the same thing a chain
|
|
3
|
+
* anchor would — a handle + its Signal key-bundle — but you hand it to someone directly (a URL or a QR),
|
|
4
|
+
* so the trust is "you got it from them." Chain-agnostic: identical on Cardano, Bitcoin, anywhere.
|
|
5
|
+
*
|
|
6
|
+
* Wire format (then base64url): `[2-byte handle length][handle utf8][bundle bytes]`.
|
|
7
|
+
*/
|
|
8
|
+
const toB64url = (bytes) => {
|
|
9
|
+
let bin = "";
|
|
10
|
+
for (const b of bytes)
|
|
11
|
+
bin += String.fromCharCode(b);
|
|
12
|
+
return btoa(bin).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
13
|
+
};
|
|
14
|
+
const fromB64url = (s) => {
|
|
15
|
+
const b64 = s.replace(/-/g, "+").replace(/_/g, "/");
|
|
16
|
+
const bin = atob(b64);
|
|
17
|
+
return Uint8Array.from(bin, (c) => c.charCodeAt(0));
|
|
18
|
+
};
|
|
19
|
+
export function encodeInvite(handle, bundle) {
|
|
20
|
+
const h = new TextEncoder().encode(handle);
|
|
21
|
+
if (h.length > 0xffff)
|
|
22
|
+
throw new Error("handle too long");
|
|
23
|
+
const out = new Uint8Array(2 + h.length + bundle.length);
|
|
24
|
+
out[0] = (h.length >> 8) & 0xff;
|
|
25
|
+
out[1] = h.length & 0xff;
|
|
26
|
+
out.set(h, 2);
|
|
27
|
+
out.set(bundle, 2 + h.length);
|
|
28
|
+
return toB64url(out);
|
|
29
|
+
}
|
|
30
|
+
export function decodeInvite(payload) {
|
|
31
|
+
const bytes = fromB64url(payload.trim());
|
|
32
|
+
if (bytes.length < 2)
|
|
33
|
+
throw new Error("invite too short");
|
|
34
|
+
const hLen = (bytes[0] << 8) | bytes[1];
|
|
35
|
+
if (bytes.length < 2 + hLen)
|
|
36
|
+
throw new Error("invite truncated");
|
|
37
|
+
return {
|
|
38
|
+
handle: new TextDecoder().decode(bytes.subarray(2, 2 + hLen)),
|
|
39
|
+
bundle: bytes.subarray(2 + hLen),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/** A shareable invite URL: `<origin>/#i=<payload>`. */
|
|
43
|
+
export const inviteUrl = (origin, handle, bundle) => `${origin}/#i=${encodeInvite(handle, bundle)}`;
|
|
44
|
+
/** Pull an invite out of a URL (or null if there isn't one). */
|
|
45
|
+
export function parseInviteUrl(url) {
|
|
46
|
+
const m = url.match(/[#&]i=([A-Za-z0-9_-]+)/);
|
|
47
|
+
if (!m)
|
|
48
|
+
return null;
|
|
49
|
+
try {
|
|
50
|
+
return decodeInvite(m[1]);
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Libp2p } from "@libp2p/interface";
|
|
2
|
+
/**
|
|
3
|
+
* The device-mesh primitive: two browsers connect **directly** over WebRTC. A circuit-relay superpeer
|
|
4
|
+
* only brokers the handshake (it carries no conversation); after that the data channel is peer-to-peer.
|
|
5
|
+
* Self-contained (own module) so its WebRTC deps load only when direct delivery is used — not in the
|
|
6
|
+
* mailbox mesh chunk. Ported from `poc/src/browser/b2b.ts`.
|
|
7
|
+
*/
|
|
8
|
+
export declare const B2B_PROTOCOL = "/handle-chat/b2b/1.0.0";
|
|
9
|
+
/** A browser node that can be dialed directly over WebRTC, reachable for the handshake via a relay. */
|
|
10
|
+
export declare function createWebrtcNode(): Promise<Libp2p>;
|
|
11
|
+
/** Reserve a relay slot, accept direct messages, and return our dialable /webrtc address. */
|
|
12
|
+
export declare function startDirectListener(relayAddr: string, onMessage: (text: string) => void): Promise<{
|
|
13
|
+
node: Libp2p;
|
|
14
|
+
addr: string;
|
|
15
|
+
}>;
|
|
16
|
+
/** Connect to a peer's /webrtc address (handshake brokered by the relay) and send directly. */
|
|
17
|
+
export declare function dialDirect(node: Libp2p, targetAddr: string, text: string): Promise<void>;
|