@cero-base/core 1.18.1 → 1.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -6
- package/package.json +9 -9
- package/src/blobs/index.js +2 -2
- package/src/database/changes.js +37 -59
- package/src/database/dispatch.js +31 -45
- package/src/database/index.js +395 -343
- package/src/database/rotation.js +201 -189
- package/src/identity/index.js +3 -3
- package/src/lib/utils.js +50 -18
- package/src/pairing/candidate.js +125 -0
- package/src/pairing/index.js +6 -223
- package/src/pairing/request.js +102 -0
- package/src/storage/index.js +11 -18
- package/types/blobs/codec.d.ts +8 -8
- package/types/blobs/index.d.ts +34 -33
- package/types/blobs/server.d.ts +8 -8
- package/types/database/changes.d.ts +5 -7
- package/types/database/dispatch.d.ts +30 -23
- package/types/database/encryption.d.ts +14 -10
- package/types/database/envelope.d.ts +2 -2
- package/types/database/index.d.ts +173 -181
- package/types/database/rotation.d.ts +53 -30
- package/types/identity/index.d.ts +81 -81
- package/types/index.d.ts +37 -51
- package/types/lib/constants.d.ts +34 -38
- package/types/lib/errors.d.ts +10 -10
- package/types/lib/schema.d.ts +47 -37
- package/types/lib/spec/index.d.ts +29 -55
- package/types/lib/utils.d.ts +27 -17
- package/types/network/discovery.d.ts +7 -7
- package/types/network/index.d.ts +50 -48
- package/types/pairing/candidate.d.ts +37 -0
- package/types/pairing/index.d.ts +87 -139
- package/types/pairing/invite.d.ts +88 -88
- package/types/pairing/request.d.ts +135 -0
- package/types/rpc/client.d.ts +2 -2
- package/types/rpc/index.d.ts +33 -33
- package/types/rpc/peer.d.ts +9 -7
- package/types/rpc/server.d.ts +2 -2
- package/types/storage/index.d.ts +70 -68
- package/src/database/bootstrap.js +0 -133
- package/src/database/hooks.js +0 -112
- package/src/database/membership.js +0 -67
- package/types/database/bootstrap.d.ts +0 -20
- package/types/database/hooks.d.ts +0 -8
- package/types/database/membership.d.ts +0 -7
package/types/lib/utils.d.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
+
export { WRITE, INVITE, ASSIGN, REMOVE } from './constants.js';
|
|
1
2
|
/**
|
|
2
3
|
* Generate a short opaque id (z32-encoded 16 random bytes).
|
|
3
4
|
*
|
|
4
5
|
* @returns {string}
|
|
5
6
|
*/
|
|
6
|
-
export function genId(): string;
|
|
7
|
-
|
|
8
|
-
export function
|
|
7
|
+
export declare function genId(): string;
|
|
8
|
+
/** @type {(dbKey: Uint8Array, writer: Uint8Array, appender: Uint8Array) => Uint8Array} */
|
|
9
|
+
export declare function admission(dbKey: Uint8Array<ArrayBufferLike>, writer: Uint8Array<ArrayBufferLike>, appender: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
10
|
+
/** @type {(dbKey: Uint8Array, writer: Uint8Array) => Uint8Array} */
|
|
11
|
+
export declare function ownership(dbKey: Uint8Array<ArrayBufferLike>, writer: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
9
12
|
/**
|
|
10
13
|
* Whether `role` is granted `perm` under the default policy.
|
|
11
14
|
*
|
|
@@ -13,10 +16,10 @@ export function claimWriterPayload(dbKey: Uint8Array, writer: Uint8Array): Uint8
|
|
|
13
16
|
* @param {string} perm
|
|
14
17
|
* @returns {boolean}
|
|
15
18
|
*/
|
|
16
|
-
export function can(role: string, perm: string): boolean;
|
|
17
|
-
export function isRank(role: any): boolean;
|
|
18
|
-
export function grants(a: any, b: any): boolean;
|
|
19
|
-
export function outranks(a: any, b: any): boolean;
|
|
19
|
+
export declare function can(role: string, perm: string): boolean;
|
|
20
|
+
export declare function isRank(role: any): boolean;
|
|
21
|
+
export declare function grants(a: any, b: any): boolean;
|
|
22
|
+
export declare function outranks(a: any, b: any): boolean;
|
|
20
23
|
/**
|
|
21
24
|
* Stream-of-snapshots primitive. Couples a `get` (returns the latest value)
|
|
22
25
|
* with a `watch` (re-fires on change) and emits the newest snapshot every
|
|
@@ -28,21 +31,28 @@ export function outranks(a: any, b: any): boolean;
|
|
|
28
31
|
* @param {(fn: () => void) => (() => void) | void} args.watch
|
|
29
32
|
* @returns {import('streamx').Readable<T>}
|
|
30
33
|
*/
|
|
31
|
-
export function subscribe<T>({ get, watch }: {
|
|
34
|
+
export declare function subscribe<T>({ get, watch }: {
|
|
32
35
|
get: () => Promise<T> | T;
|
|
33
36
|
watch: (fn: () => void) => (() => void) | void;
|
|
34
|
-
}): import(
|
|
35
|
-
export function searchHit(row: any, term: any, fields: any): boolean;
|
|
37
|
+
}): import('streamx').Readable<T>;
|
|
38
|
+
export declare function searchHit(row: any, term: any, fields: any): boolean;
|
|
36
39
|
/**
|
|
37
|
-
*
|
|
40
|
+
* The in-memory query grammar over rows: equality on any non-reserved field,
|
|
41
|
+
* id ranges, `search`, then `reverse` and `limit`.
|
|
38
42
|
*
|
|
39
|
-
* @
|
|
43
|
+
* @param {any[]} rows
|
|
44
|
+
* @param {Record<string, any>} [query]
|
|
45
|
+
* @returns {any[]}
|
|
40
46
|
*/
|
|
41
|
-
export
|
|
47
|
+
export declare function filter(rows: any[], query?: Record<string, any>): any[];
|
|
42
48
|
/**
|
|
43
|
-
*
|
|
49
|
+
* Run `cb` when `signal` aborts — or immediately if it already has. No-op
|
|
50
|
+
* without a signal. The listener removes itself on fire. Returns a disposer that
|
|
51
|
+
* detaches the listener early, so a manual unsubscribe doesn't leave it lingering
|
|
52
|
+
* on a long-lived signal.
|
|
44
53
|
*
|
|
45
|
-
* @
|
|
54
|
+
* @param {AbortSignal | undefined} signal
|
|
55
|
+
* @param {() => void} cb
|
|
56
|
+
* @returns {(() => void) | undefined}
|
|
46
57
|
*/
|
|
47
|
-
export
|
|
48
|
-
export { WRITE, INVITE, ASSIGN, REMOVE } from "./constants.js";
|
|
58
|
+
export declare function onAbort(signal: AbortSignal | undefined, cb: () => void): (() => void) | undefined;
|
|
@@ -2,19 +2,19 @@
|
|
|
2
2
|
* Handle for a single topic membership on a {@link Network}. Wraps a hyperswarm
|
|
3
3
|
* PeerDiscovery session and lets it switch between active/passive announce/lookup.
|
|
4
4
|
*/
|
|
5
|
-
export class Discovery {
|
|
5
|
+
export declare class Discovery {
|
|
6
|
+
network: import("./index.js").Network;
|
|
7
|
+
session: any;
|
|
8
|
+
_mode: "active" | "passive";
|
|
9
|
+
_destroyed: boolean;
|
|
6
10
|
/**
|
|
7
11
|
* @param {import('./index.js').Network} network Owning network.
|
|
8
12
|
* @param {any} session Hyperswarm PeerDiscovery session from `swarm.join()`.
|
|
9
13
|
* @param {'active' | 'passive'} mode
|
|
10
14
|
*/
|
|
11
|
-
constructor(network: import(
|
|
12
|
-
network: import("./index.js").Network;
|
|
13
|
-
session: any;
|
|
14
|
-
_mode: "active" | "passive";
|
|
15
|
-
_destroyed: boolean;
|
|
15
|
+
constructor(network: import('./index.js').Network, session: any, mode: 'active' | 'passive');
|
|
16
16
|
/** @returns {'active' | 'passive'} */
|
|
17
|
-
get mode():
|
|
17
|
+
get mode(): 'active' | 'passive';
|
|
18
18
|
/** @returns {boolean} */
|
|
19
19
|
get destroyed(): boolean;
|
|
20
20
|
/**
|
package/types/network/index.d.ts
CHANGED
|
@@ -1,4 +1,46 @@
|
|
|
1
|
-
|
|
1
|
+
import ReadyResource from 'ready-resource';
|
|
2
|
+
import { Discovery } from './discovery.js';
|
|
3
|
+
export declare function channelTopic(topic: any, channel: any): any;
|
|
4
|
+
export type NetworkOpts = {
|
|
5
|
+
/**
|
|
6
|
+
* Long-lived keypair used as the swarm identity.
|
|
7
|
+
*/
|
|
8
|
+
identity?: import('../identity/index.js').Identity;
|
|
9
|
+
/**
|
|
10
|
+
* Custom DHT bootstrap nodes.
|
|
11
|
+
*/
|
|
12
|
+
bootstrap?: Array<{
|
|
13
|
+
host: string;
|
|
14
|
+
port: number;
|
|
15
|
+
}>;
|
|
16
|
+
/**
|
|
17
|
+
* Incoming-connection filter.
|
|
18
|
+
*/
|
|
19
|
+
firewall?: (remotePublicKey: Uint8Array, payload: any) => boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Relay public keys to tunnel through.
|
|
22
|
+
*/
|
|
23
|
+
relayThrough?: Uint8Array[];
|
|
24
|
+
/**
|
|
25
|
+
* Reconnect backoff tiers in ms; the default escalates to ~10min, far too slow for local nets.
|
|
26
|
+
*/
|
|
27
|
+
backoffs?: number[];
|
|
28
|
+
/**
|
|
29
|
+
* Optional network-isolation label; only same-channel peers meet.
|
|
30
|
+
*/
|
|
31
|
+
channel?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Corestore; required for mirrors (blind peers replicate its cores).
|
|
34
|
+
*/
|
|
35
|
+
store?: any;
|
|
36
|
+
/**
|
|
37
|
+
* Blind-peer public keys; each attached room/blob core is mirrored through them for offline sync.
|
|
38
|
+
*/
|
|
39
|
+
mirrors?: Array<string | Uint8Array>;
|
|
40
|
+
};
|
|
41
|
+
export type Replicable = {
|
|
42
|
+
replicate: (stream: any) => any;
|
|
43
|
+
};
|
|
2
44
|
/**
|
|
3
45
|
* @typedef {object} NetworkOpts
|
|
4
46
|
* @property {import('../identity/index.js').Identity} [identity] Long-lived keypair used as the swarm identity.
|
|
@@ -16,9 +58,7 @@ export function channelTopic(topic: any, channel: any): any;
|
|
|
16
58
|
* Hyperswarm peer-discovery + replication multiplexer. Wraps a swarm and a
|
|
17
59
|
* shared wakeup channel, replicating any attached resource onto every peer.
|
|
18
60
|
*/
|
|
19
|
-
export class Network extends ReadyResource {
|
|
20
|
-
/** @param {NetworkOpts} [opts] */
|
|
21
|
-
constructor({ identity, bootstrap, firewall, relayThrough, backoffs, channel, store, mirrors }?: NetworkOpts);
|
|
61
|
+
export declare class Network extends ReadyResource {
|
|
22
62
|
identity: import("../index.js").Identity;
|
|
23
63
|
bootstrap: {
|
|
24
64
|
host: string;
|
|
@@ -32,7 +72,7 @@ export class Network extends ReadyResource {
|
|
|
32
72
|
mirrors: any[];
|
|
33
73
|
_swarm: any;
|
|
34
74
|
wakeup: any;
|
|
35
|
-
info:
|
|
75
|
+
info: object;
|
|
36
76
|
_peerInfo: Map<any, any>;
|
|
37
77
|
_infoSenders: Set<any>;
|
|
38
78
|
_replicateables: Set<any>;
|
|
@@ -40,6 +80,8 @@ export class Network extends ReadyResource {
|
|
|
40
80
|
_injected: Set<any>;
|
|
41
81
|
_blind: any;
|
|
42
82
|
_blindPeering: any;
|
|
83
|
+
/** @param {NetworkOpts} [opts] */
|
|
84
|
+
constructor({ identity, bootstrap, firewall, relayThrough, backoffs, channel, store, mirrors }?: NetworkOpts);
|
|
43
85
|
/** @returns {any} The underlying hyperswarm, or null before ready / after close. */
|
|
44
86
|
get swarm(): any;
|
|
45
87
|
/**
|
|
@@ -97,6 +139,7 @@ export class Network extends ReadyResource {
|
|
|
97
139
|
get connections(): Set<any>;
|
|
98
140
|
/** @returns {boolean} */
|
|
99
141
|
get suspended(): boolean;
|
|
142
|
+
_open(): Promise<void>;
|
|
100
143
|
/**
|
|
101
144
|
* Wait for pending DHT announces and lookups to settle, bounded by timeout.
|
|
102
145
|
*
|
|
@@ -118,6 +161,7 @@ export class Network extends ReadyResource {
|
|
|
118
161
|
* @returns {Promise<void>}
|
|
119
162
|
*/
|
|
120
163
|
resume(): Promise<void>;
|
|
164
|
+
_close(): Promise<void>;
|
|
121
165
|
/**
|
|
122
166
|
* Announce/lookup on a 32-byte topic and return a Discovery handle.
|
|
123
167
|
*
|
|
@@ -126,7 +170,7 @@ export class Network extends ReadyResource {
|
|
|
126
170
|
* @returns {Discovery}
|
|
127
171
|
*/
|
|
128
172
|
join(topic: Uint8Array, { mode }?: {
|
|
129
|
-
mode?:
|
|
173
|
+
mode?: 'active' | 'passive';
|
|
130
174
|
}): Discovery;
|
|
131
175
|
/**
|
|
132
176
|
* Register a replicable resource (hypercore, autobee, hyperdb).
|
|
@@ -153,45 +197,3 @@ export class Network extends ReadyResource {
|
|
|
153
197
|
*/
|
|
154
198
|
replicate(target: Replicable): void;
|
|
155
199
|
}
|
|
156
|
-
export type NetworkOpts = {
|
|
157
|
-
/**
|
|
158
|
-
* Long-lived keypair used as the swarm identity.
|
|
159
|
-
*/
|
|
160
|
-
identity?: import("../identity/index.js").Identity;
|
|
161
|
-
/**
|
|
162
|
-
* Custom DHT bootstrap nodes.
|
|
163
|
-
*/
|
|
164
|
-
bootstrap?: Array<{
|
|
165
|
-
host: string;
|
|
166
|
-
port: number;
|
|
167
|
-
}>;
|
|
168
|
-
/**
|
|
169
|
-
* Incoming-connection filter.
|
|
170
|
-
*/
|
|
171
|
-
firewall?: (remotePublicKey: Uint8Array, payload: any) => boolean;
|
|
172
|
-
/**
|
|
173
|
-
* Relay public keys to tunnel through.
|
|
174
|
-
*/
|
|
175
|
-
relayThrough?: Uint8Array[];
|
|
176
|
-
/**
|
|
177
|
-
* Reconnect backoff tiers in ms; the default escalates to ~10min, far too slow for local nets.
|
|
178
|
-
*/
|
|
179
|
-
backoffs?: number[];
|
|
180
|
-
/**
|
|
181
|
-
* Optional network-isolation label; only same-channel peers meet.
|
|
182
|
-
*/
|
|
183
|
-
channel?: string;
|
|
184
|
-
/**
|
|
185
|
-
* Corestore; required for mirrors (blind peers replicate its cores).
|
|
186
|
-
*/
|
|
187
|
-
store?: any;
|
|
188
|
-
/**
|
|
189
|
-
* Blind-peer public keys; each attached room/blob core is mirrored through them for offline sync.
|
|
190
|
-
*/
|
|
191
|
-
mirrors?: Array<string | Uint8Array>;
|
|
192
|
-
};
|
|
193
|
-
export type Replicable = {
|
|
194
|
-
replicate: (stream: any) => any;
|
|
195
|
-
};
|
|
196
|
-
import ReadyResource from 'ready-resource';
|
|
197
|
-
import { Discovery } from './discovery.js';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal — the joiner side: a candidate's handshake state machine (this *is* the
|
|
3
|
+
* blind-pairing `addCandidate`). One-shot: created by `Pairing.join()`, settled
|
|
4
|
+
* exactly once via `_done` or `_fail`.
|
|
5
|
+
*
|
|
6
|
+
* @property {any} _candidate blind-pairing addCandidate handle (null until started).
|
|
7
|
+
* @property {ReturnType<typeof setTimeout> | null} _timer Pending timeout, if any.
|
|
8
|
+
* @property {((result: any) => void) | null} _resolve Promise resolver, set in `start`.
|
|
9
|
+
* @property {((err: Error) => void) | null} _reject Promise rejecter, set in `start`.
|
|
10
|
+
* @property {boolean} _settled Whether the handshake has already settled.
|
|
11
|
+
*/
|
|
12
|
+
export declare class Candidate {
|
|
13
|
+
pairing: import("./index.js").Pairing;
|
|
14
|
+
invite: import("./invite.js").Invite;
|
|
15
|
+
userData: Uint8Array<ArrayBufferLike>;
|
|
16
|
+
timeout: number;
|
|
17
|
+
_candidate: any;
|
|
18
|
+
_timer: number;
|
|
19
|
+
_resolve: (value: import("./index.js").JoinResult | PromiseLike<import("./index.js").JoinResult>) => void;
|
|
20
|
+
_reject: (reason?: any) => void;
|
|
21
|
+
_settled: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* @param {import('./index.js').Pairing} pairing
|
|
24
|
+
* @param {import('./invite.js').Invite} invite
|
|
25
|
+
* @param {Uint8Array | null} userData
|
|
26
|
+
* @param {number} timeout
|
|
27
|
+
*/
|
|
28
|
+
constructor(pairing: import('./index.js').Pairing, invite: import('./invite.js').Invite, userData: Uint8Array | null, timeout: number);
|
|
29
|
+
/**
|
|
30
|
+
* Kick off the handshake; returns a promise that settles with the host response.
|
|
31
|
+
*
|
|
32
|
+
* @returns {Promise<import('./index.js').JoinResult>}
|
|
33
|
+
*/
|
|
34
|
+
start(): Promise<import('./index.js').JoinResult>;
|
|
35
|
+
_done(result: any): void;
|
|
36
|
+
_fail(err: any): void;
|
|
37
|
+
}
|
package/types/pairing/index.d.ts
CHANGED
|
@@ -1,3 +1,67 @@
|
|
|
1
|
+
import ReadyResource from 'ready-resource';
|
|
2
|
+
export type PairingOpts = {
|
|
3
|
+
/**
|
|
4
|
+
* Network to host the BlindPairing member.
|
|
5
|
+
*/
|
|
6
|
+
network: import('../network/index.js').Network;
|
|
7
|
+
/**
|
|
8
|
+
* Identity used to sign invites and derive the topic.
|
|
9
|
+
*/
|
|
10
|
+
identity: import('../identity/index.js').Identity;
|
|
11
|
+
/**
|
|
12
|
+
* Optional override topic; defaults to `identity.publicKey`.
|
|
13
|
+
*/
|
|
14
|
+
topic?: Uint8Array;
|
|
15
|
+
/**
|
|
16
|
+
* Register the member listener that serves invites (default `true`). Join-only pairings pass `false` — a listener is one-per-topic, so a joiner registering one collides with any concurrent join.
|
|
17
|
+
*/
|
|
18
|
+
host?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* compact-encoding type for the invite payload `data`.
|
|
21
|
+
*/
|
|
22
|
+
inviteEncoding?: any;
|
|
23
|
+
/**
|
|
24
|
+
* compact-encoding type for the joiner-supplied `userData`.
|
|
25
|
+
*/
|
|
26
|
+
joinerEncoding?: any;
|
|
27
|
+
/**
|
|
28
|
+
* Called when a background candidate fails to process.
|
|
29
|
+
*/
|
|
30
|
+
onerror?: (err: Error) => void;
|
|
31
|
+
};
|
|
32
|
+
export type CreateInviteOpts = {
|
|
33
|
+
/**
|
|
34
|
+
* Role tag bound into the invite.
|
|
35
|
+
*/
|
|
36
|
+
role?: string;
|
|
37
|
+
/**
|
|
38
|
+
* TTL in ms; `0`/omitted = no expiry.
|
|
39
|
+
*/
|
|
40
|
+
expiresIn?: number;
|
|
41
|
+
/**
|
|
42
|
+
* Arbitrary payload (encoded via `inviteEncoding` when set).
|
|
43
|
+
*/
|
|
44
|
+
data?: any;
|
|
45
|
+
/**
|
|
46
|
+
* Reusable until expiry/revoke; default `false` (consumed on first settle).
|
|
47
|
+
*/
|
|
48
|
+
reuse?: boolean;
|
|
49
|
+
};
|
|
50
|
+
export type JoinOpts = {
|
|
51
|
+
/**
|
|
52
|
+
* Payload sent with the candidate request. Required: blind-pairing derives the handshake token from it, so a candidate without one is never served.
|
|
53
|
+
*/
|
|
54
|
+
userData: any;
|
|
55
|
+
/**
|
|
56
|
+
* Deadline for the handshake, in ms. Defaults to 30000.
|
|
57
|
+
*/
|
|
58
|
+
timeout?: number;
|
|
59
|
+
};
|
|
60
|
+
export type JoinResult = {
|
|
61
|
+
key: Uint8Array;
|
|
62
|
+
encryptionKey: Uint8Array | null;
|
|
63
|
+
additional: Uint8Array | null;
|
|
64
|
+
};
|
|
1
65
|
/**
|
|
2
66
|
* @typedef {object} PairingOpts
|
|
3
67
|
* @property {import('../network/index.js').Network} network Network to host the BlindPairing member.
|
|
@@ -15,23 +79,10 @@
|
|
|
15
79
|
* @property {boolean} [reuse] Reusable until expiry/revoke; default `false` (consumed on first settle).
|
|
16
80
|
*
|
|
17
81
|
* @typedef {object} JoinOpts
|
|
18
|
-
* @property {any}
|
|
82
|
+
* @property {any} userData Payload sent with the candidate request. Required: blind-pairing derives the handshake token from it, so a candidate without one is never served.
|
|
19
83
|
* @property {number} [timeout] Deadline for the handshake, in ms. Defaults to 30000.
|
|
20
84
|
*
|
|
21
|
-
* @typedef {object} ConfirmOpts
|
|
22
|
-
* @property {Uint8Array} [key] 32-byte resource key delivered to the joiner; required at runtime.
|
|
23
|
-
* @property {Uint8Array | null} [encryptionKey] Optional 32-byte symmetric key.
|
|
24
|
-
* @property {Uint8Array | null} [additional] Extra opaque bytes piggybacked on the response.
|
|
25
|
-
*
|
|
26
85
|
* @typedef {{ key: Uint8Array, encryptionKey: Uint8Array | null, additional: Uint8Array | null }} JoinResult
|
|
27
|
-
*
|
|
28
|
-
* @typedef {object} RequestOpts
|
|
29
|
-
* @property {Pairing} pairing Owning Pairing instance.
|
|
30
|
-
* @property {any} req blind-pairing candidate request being answered.
|
|
31
|
-
* @property {Invite} invite Invite the candidate paired against.
|
|
32
|
-
* @property {Uint8Array} seed Per-invite seed used to sign the response.
|
|
33
|
-
* @property {any} userData Decoded joiner payload (raw bytes when no encoding).
|
|
34
|
-
* @property {() => void} onsettle Called once when the candidate is confirmed or denied.
|
|
35
86
|
*/
|
|
36
87
|
/**
|
|
37
88
|
* Blind-pairing membership wrapper. Hosts invites, dispatches incoming
|
|
@@ -39,25 +90,7 @@
|
|
|
39
90
|
* side of the handshake. All wire payloads are signed and routed through
|
|
40
91
|
* the supplied network.
|
|
41
92
|
*/
|
|
42
|
-
export class Pairing extends ReadyResource {
|
|
43
|
-
/**
|
|
44
|
-
* Resolve the resource discovery key an invite targets — without pairing.
|
|
45
|
-
* Lets callers detect "already joined" before any handshake. Returns `null`
|
|
46
|
-
* for an unparseable invite.
|
|
47
|
-
*
|
|
48
|
-
* @param {string} invite
|
|
49
|
-
* @returns {Uint8Array | null}
|
|
50
|
-
*/
|
|
51
|
-
static inviteTopic(invite: string): Uint8Array | null;
|
|
52
|
-
/**
|
|
53
|
-
* Cheap structural test for a candidate invite string.
|
|
54
|
-
*
|
|
55
|
-
* @param {unknown} str
|
|
56
|
-
* @returns {boolean}
|
|
57
|
-
*/
|
|
58
|
-
static isInvite(str: unknown): boolean;
|
|
59
|
-
/** @param {PairingOpts} [opts] */
|
|
60
|
-
constructor({ network, identity, topic, host, inviteEncoding, joinerEncoding, onerror, onconsume }?: PairingOpts);
|
|
93
|
+
export declare class Pairing extends ReadyResource {
|
|
61
94
|
network: import("../index.js").Network;
|
|
62
95
|
identity: import("../index.js").Identity;
|
|
63
96
|
topic: Uint8Array<ArrayBufferLike>;
|
|
@@ -70,6 +103,19 @@ export class Pairing extends ReadyResource {
|
|
|
70
103
|
_member: any;
|
|
71
104
|
_invites: Map<any, any>;
|
|
72
105
|
_candidates: Set<any>;
|
|
106
|
+
/** @param {PairingOpts} [opts] */
|
|
107
|
+
constructor({ network, identity, topic, host, inviteEncoding, joinerEncoding, onerror, onconsume }?: PairingOpts);
|
|
108
|
+
_open(): Promise<void>;
|
|
109
|
+
_close(): Promise<void>;
|
|
110
|
+
/**
|
|
111
|
+
* Resolve the resource discovery key an invite targets — without pairing.
|
|
112
|
+
* Lets callers detect "already joined" before any handshake. Returns `null`
|
|
113
|
+
* for an unparseable invite.
|
|
114
|
+
*
|
|
115
|
+
* @param {string} invite
|
|
116
|
+
* @returns {Uint8Array | null}
|
|
117
|
+
*/
|
|
118
|
+
static inviteTopic(invite: string): Uint8Array | null;
|
|
73
119
|
/**
|
|
74
120
|
* Mint a new pairing invite. Returns its canonical wire form (z32 string).
|
|
75
121
|
*
|
|
@@ -87,7 +133,7 @@ export class Pairing extends ReadyResource {
|
|
|
87
133
|
id: Uint8Array;
|
|
88
134
|
seed: Uint8Array;
|
|
89
135
|
publicKey: Uint8Array;
|
|
90
|
-
invite: import(
|
|
136
|
+
invite: import('./invite.js').Invite;
|
|
91
137
|
reuse: boolean;
|
|
92
138
|
} | null;
|
|
93
139
|
/**
|
|
@@ -114,6 +160,13 @@ export class Pairing extends ReadyResource {
|
|
|
114
160
|
* @returns {boolean}
|
|
115
161
|
*/
|
|
116
162
|
revoke(inviteStr: string): boolean;
|
|
163
|
+
/**
|
|
164
|
+
* Cheap structural test for a candidate invite string.
|
|
165
|
+
*
|
|
166
|
+
* @param {unknown} str
|
|
167
|
+
* @returns {boolean}
|
|
168
|
+
*/
|
|
169
|
+
static isInvite(str: unknown): boolean;
|
|
117
170
|
/**
|
|
118
171
|
* Joiner side — start a pairing handshake against `inviteStr` and resolve
|
|
119
172
|
* with the host's response when the host confirms.
|
|
@@ -143,108 +196,3 @@ export class Pairing extends ReadyResource {
|
|
|
143
196
|
resume(): Promise<void>;
|
|
144
197
|
_oncandidate(req: any): Promise<void>;
|
|
145
198
|
}
|
|
146
|
-
export type PairingOpts = {
|
|
147
|
-
/**
|
|
148
|
-
* Network to host the BlindPairing member.
|
|
149
|
-
*/
|
|
150
|
-
network: import("../network/index.js").Network;
|
|
151
|
-
/**
|
|
152
|
-
* Identity used to sign invites and derive the topic.
|
|
153
|
-
*/
|
|
154
|
-
identity: import("../identity/index.js").Identity;
|
|
155
|
-
/**
|
|
156
|
-
* Optional override topic; defaults to `identity.publicKey`.
|
|
157
|
-
*/
|
|
158
|
-
topic?: Uint8Array;
|
|
159
|
-
/**
|
|
160
|
-
* Register the member listener that serves invites (default `true`). Join-only pairings pass `false` — a listener is one-per-topic, so a joiner registering one collides with any concurrent join.
|
|
161
|
-
*/
|
|
162
|
-
host?: boolean;
|
|
163
|
-
/**
|
|
164
|
-
* compact-encoding type for the invite payload `data`.
|
|
165
|
-
*/
|
|
166
|
-
inviteEncoding?: any;
|
|
167
|
-
/**
|
|
168
|
-
* compact-encoding type for the joiner-supplied `userData`.
|
|
169
|
-
*/
|
|
170
|
-
joinerEncoding?: any;
|
|
171
|
-
/**
|
|
172
|
-
* Called when a background candidate fails to process.
|
|
173
|
-
*/
|
|
174
|
-
onerror?: (err: Error) => void;
|
|
175
|
-
};
|
|
176
|
-
export type CreateInviteOpts = {
|
|
177
|
-
/**
|
|
178
|
-
* Role tag bound into the invite.
|
|
179
|
-
*/
|
|
180
|
-
role?: string;
|
|
181
|
-
/**
|
|
182
|
-
* TTL in ms; `0`/omitted = no expiry.
|
|
183
|
-
*/
|
|
184
|
-
expiresIn?: number;
|
|
185
|
-
/**
|
|
186
|
-
* Arbitrary payload (encoded via `inviteEncoding` when set).
|
|
187
|
-
*/
|
|
188
|
-
data?: any;
|
|
189
|
-
/**
|
|
190
|
-
* Reusable until expiry/revoke; default `false` (consumed on first settle).
|
|
191
|
-
*/
|
|
192
|
-
reuse?: boolean;
|
|
193
|
-
};
|
|
194
|
-
export type JoinOpts = {
|
|
195
|
-
/**
|
|
196
|
-
* Payload sent with the candidate request.
|
|
197
|
-
*/
|
|
198
|
-
userData?: any;
|
|
199
|
-
/**
|
|
200
|
-
* Deadline for the handshake, in ms. Defaults to 30000.
|
|
201
|
-
*/
|
|
202
|
-
timeout?: number;
|
|
203
|
-
};
|
|
204
|
-
export type ConfirmOpts = {
|
|
205
|
-
/**
|
|
206
|
-
* 32-byte resource key delivered to the joiner; required at runtime.
|
|
207
|
-
*/
|
|
208
|
-
key?: Uint8Array;
|
|
209
|
-
/**
|
|
210
|
-
* Optional 32-byte symmetric key.
|
|
211
|
-
*/
|
|
212
|
-
encryptionKey?: Uint8Array | null;
|
|
213
|
-
/**
|
|
214
|
-
* Extra opaque bytes piggybacked on the response.
|
|
215
|
-
*/
|
|
216
|
-
additional?: Uint8Array | null;
|
|
217
|
-
};
|
|
218
|
-
export type JoinResult = {
|
|
219
|
-
key: Uint8Array;
|
|
220
|
-
encryptionKey: Uint8Array | null;
|
|
221
|
-
additional: Uint8Array | null;
|
|
222
|
-
};
|
|
223
|
-
export type RequestOpts = {
|
|
224
|
-
/**
|
|
225
|
-
* Owning Pairing instance.
|
|
226
|
-
*/
|
|
227
|
-
pairing: Pairing;
|
|
228
|
-
/**
|
|
229
|
-
* blind-pairing candidate request being answered.
|
|
230
|
-
*/
|
|
231
|
-
req: any;
|
|
232
|
-
/**
|
|
233
|
-
* Invite the candidate paired against.
|
|
234
|
-
*/
|
|
235
|
-
invite: Invite;
|
|
236
|
-
/**
|
|
237
|
-
* Per-invite seed used to sign the response.
|
|
238
|
-
*/
|
|
239
|
-
seed: Uint8Array;
|
|
240
|
-
/**
|
|
241
|
-
* Decoded joiner payload (raw bytes when no encoding).
|
|
242
|
-
*/
|
|
243
|
-
userData: any;
|
|
244
|
-
/**
|
|
245
|
-
* Called once when the candidate is confirmed or denied.
|
|
246
|
-
*/
|
|
247
|
-
onsettle: () => void;
|
|
248
|
-
};
|
|
249
|
-
import ReadyResource from 'ready-resource';
|
|
250
|
-
import { Invite } from './invite.js';
|