@cero-base/core 1.18.2 → 2.0.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 +14 -11
- package/src/blobs/index.js +17 -17
- package/src/blobs/server.js +0 -2
- package/src/database/changes.js +34 -60
- package/src/database/dispatch.js +156 -245
- package/src/database/encryption.js +22 -52
- package/src/database/envelope.js +1 -3
- package/src/database/index.js +514 -513
- package/src/database/rotation.js +191 -193
- package/src/identity/index.js +8 -12
- package/src/index.js +5 -9
- package/src/lib/constants.js +3 -12
- package/src/lib/errors.js +6 -10
- package/src/lib/schema.js +2 -5
- package/src/lib/utils.js +55 -38
- package/src/network/index.js +138 -166
- package/src/pairing/candidate.js +123 -0
- package/src/pairing/index.js +36 -267
- package/src/pairing/invite.js +3 -4
- package/src/pairing/request.js +96 -0
- package/src/rpc/index.js +4 -14
- package/src/rpc/peer.js +3 -7
- package/src/storage/index.js +36 -49
- package/types/blobs/codec.d.ts +8 -8
- package/types/blobs/index.d.ts +38 -37
- package/types/blobs/server.d.ts +8 -10
- package/types/database/changes.d.ts +3 -8
- package/types/database/dispatch.d.ts +28 -25
- package/types/database/encryption.d.ts +22 -30
- package/types/database/envelope.d.ts +2 -2
- package/types/database/index.d.ts +196 -221
- package/types/database/rotation.d.ts +47 -30
- package/types/identity/index.d.ts +83 -87
- package/types/index.d.ts +42 -55
- package/types/lib/constants.d.ts +34 -38
- package/types/lib/errors.d.ts +16 -20
- package/types/lib/schema.d.ts +49 -42
- package/types/lib/spec/index.d.ts +29 -55
- package/types/lib/utils.d.ts +26 -20
- package/types/network/discovery.d.ts +7 -7
- package/types/network/index.d.ts +64 -72
- package/types/pairing/candidate.d.ts +36 -0
- package/types/pairing/index.d.ts +91 -151
- package/types/pairing/invite.d.ts +91 -91
- package/types/pairing/request.d.ts +133 -0
- package/types/rpc/client.d.ts +2 -2
- package/types/rpc/index.d.ts +30 -33
- package/types/rpc/peer.d.ts +11 -11
- package/types/rpc/server.d.ts +2 -2
- package/types/storage/index.d.ts +70 -71
- 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/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,49 +79,16 @@
|
|
|
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
|
-
* Blind-pairing membership wrapper. Hosts invites, dispatches incoming
|
|
38
|
-
*
|
|
39
|
-
* side of the handshake. All wire payloads are signed and routed through
|
|
40
|
-
* the supplied network.
|
|
88
|
+
* Blind-pairing membership wrapper. Hosts invites, dispatches incoming candidates to the
|
|
89
|
+
* application for accept/deny, and provides the joiner side of the handshake.
|
|
41
90
|
*/
|
|
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);
|
|
91
|
+
export declare class Pairing extends ReadyResource {
|
|
61
92
|
network: import("../index.js").Network;
|
|
62
93
|
identity: import("../index.js").Identity;
|
|
63
94
|
topic: Uint8Array<ArrayBufferLike>;
|
|
@@ -70,6 +101,16 @@ export class Pairing extends ReadyResource {
|
|
|
70
101
|
_member: any;
|
|
71
102
|
_invites: Map<any, any>;
|
|
72
103
|
_candidates: Set<any>;
|
|
104
|
+
/** @param {PairingOpts} [opts] */
|
|
105
|
+
constructor({ network, identity, topic, host, inviteEncoding, joinerEncoding, onerror, onconsume }?: PairingOpts);
|
|
106
|
+
/**
|
|
107
|
+
* Whether the underlying blind-pairing layer is suspended.
|
|
108
|
+
*
|
|
109
|
+
* @returns {boolean}
|
|
110
|
+
*/
|
|
111
|
+
get suspended(): boolean;
|
|
112
|
+
_open(): Promise<void>;
|
|
113
|
+
_close(): Promise<void>;
|
|
73
114
|
/**
|
|
74
115
|
* Mint a new pairing invite. Returns its canonical wire form (z32 string).
|
|
75
116
|
*
|
|
@@ -87,15 +128,11 @@ export class Pairing extends ReadyResource {
|
|
|
87
128
|
id: Uint8Array;
|
|
88
129
|
seed: Uint8Array;
|
|
89
130
|
publicKey: Uint8Array;
|
|
90
|
-
invite: import(
|
|
131
|
+
invite: import('./invite.js').Invite;
|
|
91
132
|
reuse: boolean;
|
|
92
133
|
} | null;
|
|
93
134
|
/**
|
|
94
|
-
* Reconcile the served-invite set with persisted rows (the room's `invites`
|
|
95
|
-
* collection). Adds unknown rows so ANY member replica can serve them across
|
|
96
|
-
* restarts; drops replicated records whose row disappeared (revoked or
|
|
97
|
-
* consumed elsewhere). Locally-minted records not yet visible as rows are
|
|
98
|
-
* kept.
|
|
135
|
+
* Reconcile the served-invite set with persisted rows (the room's `invites` collection).
|
|
99
136
|
*
|
|
100
137
|
* @param {Array<{ id: string, invite: Uint8Array, publicKey: Uint8Array, seed: Uint8Array, reuse?: boolean }>} rows
|
|
101
138
|
*/
|
|
@@ -123,12 +160,6 @@ export class Pairing extends ReadyResource {
|
|
|
123
160
|
* @returns {Promise<JoinResult>}
|
|
124
161
|
*/
|
|
125
162
|
join(inviteStr: string, { userData, timeout }?: JoinOpts): Promise<JoinResult>;
|
|
126
|
-
/**
|
|
127
|
-
* Whether the underlying blind-pairing layer is suspended.
|
|
128
|
-
*
|
|
129
|
-
* @returns {boolean}
|
|
130
|
-
*/
|
|
131
|
-
get suspended(): boolean;
|
|
132
163
|
/**
|
|
133
164
|
* Pause blind-pairing — keeps state, drops sockets. Idempotent.
|
|
134
165
|
*
|
|
@@ -142,109 +173,18 @@ export class Pairing extends ReadyResource {
|
|
|
142
173
|
*/
|
|
143
174
|
resume(): Promise<void>;
|
|
144
175
|
_oncandidate(req: any): Promise<void>;
|
|
145
|
-
}
|
|
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
176
|
/**
|
|
178
|
-
*
|
|
179
|
-
|
|
180
|
-
|
|
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).
|
|
177
|
+
* Resolve the resource discovery key an invite targets — without pairing.
|
|
178
|
+
*
|
|
179
|
+
* @param {string} invite
|
|
180
|
+
* @returns {Uint8Array | null}
|
|
242
181
|
*/
|
|
243
|
-
|
|
182
|
+
static inviteTopic(invite: string): Uint8Array | null;
|
|
244
183
|
/**
|
|
245
|
-
*
|
|
184
|
+
* Cheap structural test for a candidate invite string.
|
|
185
|
+
*
|
|
186
|
+
* @param {unknown} str
|
|
187
|
+
* @returns {boolean}
|
|
246
188
|
*/
|
|
247
|
-
|
|
248
|
-
}
|
|
249
|
-
import ReadyResource from 'ready-resource';
|
|
250
|
-
import { Invite } from './invite.js';
|
|
189
|
+
static isInvite(str: unknown): boolean;
|
|
190
|
+
}
|
|
@@ -1,94 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @typedef {object} InviteFields
|
|
3
|
-
* @property {Uint8Array} publicKey Signer's long-lived public key.
|
|
4
|
-
* @property {string} role Optional role tag baked into the signed body.
|
|
5
|
-
* @property {number} expires Absolute expiry timestamp; `0` means never.
|
|
6
|
-
* @property {Uint8Array | null} data Encoded payload (raw or via `encoding`).
|
|
7
|
-
* @property {Uint8Array} blind Raw blind-pairing invite handed to candidates.
|
|
8
|
-
* @property {Uint8Array} [sig] Ed25519 signature over the canonical body.
|
|
9
|
-
* @property {string | null} [_str] Cached z32 string form.
|
|
10
|
-
*
|
|
11
|
-
* @typedef {object} CreateInviteOpts
|
|
12
|
-
* @property {Uint8Array} secretKey 64-byte Ed25519 secret key used to sign.
|
|
13
|
-
* @property {Uint8Array} publicKey 32-byte Ed25519 public key matching `secretKey`.
|
|
14
|
-
* @property {string} role Optional role tag for the joiner.
|
|
15
|
-
* @property {number} expiresIn TTL in ms from now; `0` means never expires.
|
|
16
|
-
* @property {any} data Caller payload; encoded via `encoding` when provided.
|
|
17
|
-
* @property {Uint8Array} blind Raw blind-pairing invite to wrap.
|
|
18
|
-
* @property {any} [encoding] compact-encoding type used to encode `data`.
|
|
19
|
-
*
|
|
20
|
-
* @typedef {object} ParseInviteOpts
|
|
21
|
-
* @property {any} [encoding] compact-encoding type used to decode the embedded payload.
|
|
22
|
-
*/
|
|
23
|
-
/**
|
|
24
|
-
* Signed, expirable pairing invite. Wraps a blind-pairing invite with a
|
|
25
|
-
* role, optional payload and an Ed25519 signature so the host can be
|
|
26
|
-
* authenticated by the joiner before any handshake happens.
|
|
27
|
-
*
|
|
28
|
-
* @property {any} [_rawData] Decoded payload kept alongside the encoded `data` for convenience.
|
|
29
|
-
* @property {Uint8Array} _discoveryKey Cached discovery key of the wrapped blind invite.
|
|
30
|
-
*/
|
|
31
|
-
export class Invite {
|
|
32
|
-
/**
|
|
33
|
-
* Build and sign a new invite envelope wrapping a blind-pairing invite.
|
|
34
|
-
*
|
|
35
|
-
* @param {CreateInviteOpts} opts
|
|
36
|
-
* @returns {Invite}
|
|
37
|
-
*/
|
|
38
|
-
static create({ secretKey, publicKey, role, expiresIn, data, blind, encoding }: CreateInviteOpts): Invite;
|
|
39
|
-
/**
|
|
40
|
-
* Parse a z32 invite string, verify its signature and (optionally) decode
|
|
41
|
-
* its payload.
|
|
42
|
-
*
|
|
43
|
-
* @param {string} str
|
|
44
|
-
* @param {ParseInviteOpts} [opts]
|
|
45
|
-
* @returns {Invite}
|
|
46
|
-
*/
|
|
47
|
-
static parse(str: string, { encoding }?: ParseInviteOpts): Invite;
|
|
48
|
-
/**
|
|
49
|
-
* Cheap structural test — does `str` decode as an invite envelope? Does not
|
|
50
|
-
* verify the signature.
|
|
51
|
-
*
|
|
52
|
-
* @param {unknown} str
|
|
53
|
-
* @returns {boolean}
|
|
54
|
-
*/
|
|
55
|
-
static isInvite(str: unknown): boolean;
|
|
56
|
-
/** @param {InviteFields} fields */
|
|
57
|
-
constructor(fields: InviteFields);
|
|
58
|
-
version: number;
|
|
59
|
-
publicKey: Uint8Array<ArrayBufferLike>;
|
|
60
|
-
role: string;
|
|
61
|
-
expires: number;
|
|
62
|
-
data: Uint8Array<ArrayBufferLike>;
|
|
63
|
-
blind: Uint8Array<ArrayBufferLike>;
|
|
64
|
-
sig: Uint8Array<ArrayBufferLike>;
|
|
65
|
-
_str: string;
|
|
66
|
-
_discoveryKey: any;
|
|
67
|
-
/**
|
|
68
|
-
* Whether the invite is past its TTL (always `false` when `expires === 0`).
|
|
69
|
-
*
|
|
70
|
-
* @returns {boolean}
|
|
71
|
-
*/
|
|
72
|
-
get expired(): boolean;
|
|
73
|
-
/**
|
|
74
|
-
* Discovery key of the wrapped blind-pairing invite — the topic it targets.
|
|
75
|
-
*
|
|
76
|
-
* @returns {Uint8Array}
|
|
77
|
-
*/
|
|
78
|
-
get discoveryKey(): Uint8Array;
|
|
79
|
-
/**
|
|
80
|
-
* Verify the embedded signature against the encoded body.
|
|
81
|
-
*
|
|
82
|
-
* @returns {boolean}
|
|
83
|
-
*/
|
|
84
|
-
verify(): boolean;
|
|
85
|
-
/**
|
|
86
|
-
* Serialise to the canonical z32 wire form (cached).
|
|
87
|
-
*
|
|
88
|
-
* @returns {string}
|
|
89
|
-
*/
|
|
90
|
-
toString(): string;
|
|
91
|
-
}
|
|
92
1
|
export type InviteFields = {
|
|
93
2
|
/**
|
|
94
3
|
* Signer's long-lived public key.
|
|
@@ -155,3 +64,94 @@ export type ParseInviteOpts = {
|
|
|
155
64
|
*/
|
|
156
65
|
encoding?: any;
|
|
157
66
|
};
|
|
67
|
+
/**
|
|
68
|
+
* @typedef {object} InviteFields
|
|
69
|
+
* @property {Uint8Array} publicKey Signer's long-lived public key.
|
|
70
|
+
* @property {string} role Optional role tag baked into the signed body.
|
|
71
|
+
* @property {number} expires Absolute expiry timestamp; `0` means never.
|
|
72
|
+
* @property {Uint8Array | null} data Encoded payload (raw or via `encoding`).
|
|
73
|
+
* @property {Uint8Array} blind Raw blind-pairing invite handed to candidates.
|
|
74
|
+
* @property {Uint8Array} [sig] Ed25519 signature over the canonical body.
|
|
75
|
+
* @property {string | null} [_str] Cached z32 string form.
|
|
76
|
+
*
|
|
77
|
+
* @typedef {object} CreateInviteOpts
|
|
78
|
+
* @property {Uint8Array} secretKey 64-byte Ed25519 secret key used to sign.
|
|
79
|
+
* @property {Uint8Array} publicKey 32-byte Ed25519 public key matching `secretKey`.
|
|
80
|
+
* @property {string} role Optional role tag for the joiner.
|
|
81
|
+
* @property {number} expiresIn TTL in ms from now; `0` means never expires.
|
|
82
|
+
* @property {any} data Caller payload; encoded via `encoding` when provided.
|
|
83
|
+
* @property {Uint8Array} blind Raw blind-pairing invite to wrap.
|
|
84
|
+
* @property {any} [encoding] compact-encoding type used to encode `data`.
|
|
85
|
+
*
|
|
86
|
+
* @typedef {object} ParseInviteOpts
|
|
87
|
+
* @property {any} [encoding] compact-encoding type used to decode the embedded payload.
|
|
88
|
+
*/
|
|
89
|
+
/**
|
|
90
|
+
* Signed, expirable pairing invite. Wraps a blind-pairing invite with a role, optional
|
|
91
|
+
* payload and an Ed25519 signature so the host can be authenticated by the joiner before
|
|
92
|
+
* any handshake happens.
|
|
93
|
+
*
|
|
94
|
+
* @property {any} [_rawData] Decoded payload kept alongside the encoded `data` for convenience.
|
|
95
|
+
* @property {Uint8Array} _discoveryKey Cached discovery key of the wrapped blind invite.
|
|
96
|
+
*/
|
|
97
|
+
export declare class Invite {
|
|
98
|
+
version: number;
|
|
99
|
+
publicKey: Uint8Array<ArrayBufferLike>;
|
|
100
|
+
role: string;
|
|
101
|
+
expires: number;
|
|
102
|
+
data: Uint8Array<ArrayBufferLike>;
|
|
103
|
+
blind: Uint8Array<ArrayBufferLike>;
|
|
104
|
+
sig: Uint8Array<ArrayBufferLike>;
|
|
105
|
+
_str: string;
|
|
106
|
+
_discoveryKey: any;
|
|
107
|
+
/** @param {InviteFields} fields */
|
|
108
|
+
constructor(fields: InviteFields);
|
|
109
|
+
/**
|
|
110
|
+
* Whether the invite is past its TTL (always `false` when `expires === 0`).
|
|
111
|
+
*
|
|
112
|
+
* @returns {boolean}
|
|
113
|
+
*/
|
|
114
|
+
get expired(): boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Discovery key of the wrapped blind-pairing invite — the topic it targets.
|
|
117
|
+
*
|
|
118
|
+
* @returns {Uint8Array}
|
|
119
|
+
*/
|
|
120
|
+
get discoveryKey(): Uint8Array;
|
|
121
|
+
/**
|
|
122
|
+
* Verify the embedded signature against the encoded body.
|
|
123
|
+
*
|
|
124
|
+
* @returns {boolean}
|
|
125
|
+
*/
|
|
126
|
+
verify(): boolean;
|
|
127
|
+
/**
|
|
128
|
+
* Serialise to the canonical z32 wire form (cached).
|
|
129
|
+
*
|
|
130
|
+
* @returns {string}
|
|
131
|
+
*/
|
|
132
|
+
toString(): string;
|
|
133
|
+
/**
|
|
134
|
+
* Build and sign a new invite envelope wrapping a blind-pairing invite.
|
|
135
|
+
*
|
|
136
|
+
* @param {CreateInviteOpts} opts
|
|
137
|
+
* @returns {Invite}
|
|
138
|
+
*/
|
|
139
|
+
static create({ secretKey, publicKey, role, expiresIn, data, blind, encoding }: CreateInviteOpts): Invite;
|
|
140
|
+
/**
|
|
141
|
+
* Parse a z32 invite string, verify its signature and (optionally) decode
|
|
142
|
+
* its payload.
|
|
143
|
+
*
|
|
144
|
+
* @param {string} str
|
|
145
|
+
* @param {ParseInviteOpts} [opts]
|
|
146
|
+
* @returns {Invite}
|
|
147
|
+
*/
|
|
148
|
+
static parse(str: string, { encoding }?: ParseInviteOpts): Invite;
|
|
149
|
+
/**
|
|
150
|
+
* Cheap structural test — does `str` decode as an invite envelope? Does not
|
|
151
|
+
* verify the signature.
|
|
152
|
+
*
|
|
153
|
+
* @param {unknown} str
|
|
154
|
+
* @returns {boolean}
|
|
155
|
+
*/
|
|
156
|
+
static isInvite(str: unknown): boolean;
|
|
157
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
export declare const STATUS_ACCEPTED = 0;
|
|
2
|
+
export declare const STATUS_DENIED = 1;
|
|
3
|
+
export declare const Response: {
|
|
4
|
+
preencode(state: any, m: any): void;
|
|
5
|
+
encode(state: any, m: any): void;
|
|
6
|
+
decode(state: any): {
|
|
7
|
+
status: any;
|
|
8
|
+
reason: any;
|
|
9
|
+
key: any;
|
|
10
|
+
encryptionKey: any;
|
|
11
|
+
extra: any;
|
|
12
|
+
};
|
|
13
|
+
} | {
|
|
14
|
+
preencode(state: any, m: any): void;
|
|
15
|
+
encode(state: any, m: any): void;
|
|
16
|
+
decode(state: any): {
|
|
17
|
+
data: any;
|
|
18
|
+
};
|
|
19
|
+
} | {
|
|
20
|
+
preencode(state: any, m: any): void;
|
|
21
|
+
encode(state: any, m: any): void;
|
|
22
|
+
decode(state: any): {
|
|
23
|
+
id: any;
|
|
24
|
+
name: any;
|
|
25
|
+
role: any;
|
|
26
|
+
noAccept: boolean;
|
|
27
|
+
};
|
|
28
|
+
} | {
|
|
29
|
+
preencode(state: any, m: any): void;
|
|
30
|
+
encode(state: any, m: any): void;
|
|
31
|
+
decode(state: any): {
|
|
32
|
+
coreKey: any;
|
|
33
|
+
blockOffset: any;
|
|
34
|
+
blockLength: any;
|
|
35
|
+
byteOffset: any;
|
|
36
|
+
byteLength: any;
|
|
37
|
+
type: any;
|
|
38
|
+
};
|
|
39
|
+
} | {
|
|
40
|
+
preencode(state: any, m: any): void;
|
|
41
|
+
encode(state: any, m: any): void;
|
|
42
|
+
decode(state: any): {
|
|
43
|
+
prev: any;
|
|
44
|
+
next: any;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
export type ConfirmOpts = {
|
|
48
|
+
/**
|
|
49
|
+
* 32-byte resource key delivered to the joiner; required at runtime.
|
|
50
|
+
*/
|
|
51
|
+
key?: Uint8Array;
|
|
52
|
+
/**
|
|
53
|
+
* Optional 32-byte symmetric key.
|
|
54
|
+
*/
|
|
55
|
+
encryptionKey?: Uint8Array | null;
|
|
56
|
+
/**
|
|
57
|
+
* Extra opaque bytes piggybacked on the response.
|
|
58
|
+
*/
|
|
59
|
+
additional?: Uint8Array | null;
|
|
60
|
+
};
|
|
61
|
+
export type RequestOpts = {
|
|
62
|
+
/**
|
|
63
|
+
* Owning Pairing instance.
|
|
64
|
+
*/
|
|
65
|
+
pairing: import('./index.js').Pairing;
|
|
66
|
+
/**
|
|
67
|
+
* blind-pairing candidate request being answered.
|
|
68
|
+
*/
|
|
69
|
+
req: any;
|
|
70
|
+
/**
|
|
71
|
+
* Invite the candidate paired against.
|
|
72
|
+
*/
|
|
73
|
+
invite: import('./invite.js').Invite;
|
|
74
|
+
/**
|
|
75
|
+
* Per-invite seed used to sign the response.
|
|
76
|
+
*/
|
|
77
|
+
seed: Uint8Array;
|
|
78
|
+
/**
|
|
79
|
+
* Decoded joiner payload (raw bytes when no encoding).
|
|
80
|
+
*/
|
|
81
|
+
userData: any;
|
|
82
|
+
/**
|
|
83
|
+
* Called once when the candidate is confirmed or denied.
|
|
84
|
+
*/
|
|
85
|
+
onsettle: () => void;
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* @typedef {object} ConfirmOpts
|
|
89
|
+
* @property {Uint8Array} [key] 32-byte resource key delivered to the joiner; required at runtime.
|
|
90
|
+
* @property {Uint8Array | null} [encryptionKey] Optional 32-byte symmetric key.
|
|
91
|
+
* @property {Uint8Array | null} [additional] Extra opaque bytes piggybacked on the response.
|
|
92
|
+
*
|
|
93
|
+
* @typedef {object} RequestOpts
|
|
94
|
+
* @property {import('./index.js').Pairing} pairing Owning Pairing instance.
|
|
95
|
+
* @property {any} req blind-pairing candidate request being answered.
|
|
96
|
+
* @property {import('./invite.js').Invite} invite Invite the candidate paired against.
|
|
97
|
+
* @property {Uint8Array} seed Per-invite seed used to sign the response.
|
|
98
|
+
* @property {any} userData Decoded joiner payload (raw bytes when no encoding).
|
|
99
|
+
* @property {() => void} onsettle Called once when the candidate is confirmed or denied.
|
|
100
|
+
*/
|
|
101
|
+
/**
|
|
102
|
+
* Internal — a pairing request from an incoming candidate, awaiting the host's
|
|
103
|
+
* accept/deny.
|
|
104
|
+
*
|
|
105
|
+
* @property {boolean} _settled Whether confirm/deny has already run.
|
|
106
|
+
*/
|
|
107
|
+
export declare class Request {
|
|
108
|
+
pairing: import("./index.js").Pairing;
|
|
109
|
+
_req: any;
|
|
110
|
+
_seed: Uint8Array<ArrayBufferLike>;
|
|
111
|
+
_settled: boolean;
|
|
112
|
+
_onsettle: () => void;
|
|
113
|
+
invite: import("./invite.js").Invite;
|
|
114
|
+
userData: any;
|
|
115
|
+
publicKey: any;
|
|
116
|
+
/** @param {RequestOpts} opts */
|
|
117
|
+
constructor(opts: RequestOpts);
|
|
118
|
+
/**
|
|
119
|
+
* Accept the candidate and reveal the resource key. Idempotent.
|
|
120
|
+
*
|
|
121
|
+
* @param {ConfirmOpts} opts
|
|
122
|
+
* @returns {Promise<void>}
|
|
123
|
+
*/
|
|
124
|
+
confirm({ key, encryptionKey, additional }?: ConfirmOpts): Promise<void>;
|
|
125
|
+
/**
|
|
126
|
+
* Reject the candidate with an optional reason. Idempotent.
|
|
127
|
+
*
|
|
128
|
+
* @param {string} [reason]
|
|
129
|
+
* @returns {Promise<void>}
|
|
130
|
+
*/
|
|
131
|
+
deny(reason?: string): Promise<void>;
|
|
132
|
+
_respond(envelope: any): void;
|
|
133
|
+
}
|
package/types/rpc/client.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { RPCPeer } from './peer.js';
|
|
1
2
|
/**
|
|
2
3
|
* Client-side RPC adapter — issues requests over the framed IPC stream.
|
|
3
4
|
* All wiring lives in {@link RPCPeer}; this is the client-named role.
|
|
4
5
|
*/
|
|
5
|
-
export class RPCClient extends RPCPeer {
|
|
6
|
+
export declare class RPCClient extends RPCPeer {
|
|
6
7
|
}
|
|
7
|
-
import { RPCPeer } from './peer.js';
|
package/types/rpc/index.d.ts
CHANGED
|
@@ -1,36 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* @property {{ encode: (type: string, value: any) => Uint8Array, decode: (type: string, buf: Uint8Array) => any, getEncoding?: (name: string) => any }} schema hyperschema-shaped module.
|
|
4
|
-
* @property {{ ns?: string }} [meta] Optional metadata; `ns` controls envelope type fqns.
|
|
5
|
-
* @property {any} [rpc] hrpc constructor used by RPCServer/RPCClient.
|
|
6
|
-
* @property {Codec} [codec] Filled in by `bindCodec`.
|
|
7
|
-
*
|
|
8
|
-
* @typedef {object} Codec
|
|
9
|
-
* @property {(type: string, row: any) => Uint8Array} encodeRow
|
|
10
|
-
* @property {(type: string, buf: Uint8Array) => any} decodeRow
|
|
11
|
-
* @property {(type: string, rows: any[]) => Uint8Array} encodeRows
|
|
12
|
-
* @property {(type: string, changes: Array<{ prev: any, next: any }>) => Uint8Array} encodeChanges
|
|
13
|
-
* @property {(type: string, buf: Uint8Array) => Array<{ prev: any, next: any }>} decodeChanges
|
|
14
|
-
* @property {(type: string, buf: Uint8Array) => any[]} decodeRows
|
|
15
|
-
* @property {(q: any) => Uint8Array} encodeQuery
|
|
16
|
-
* @property {(buf: Uint8Array) => any} decodeQuery
|
|
17
|
-
* @property {(row: any) => Uint8Array} encodeCreate
|
|
18
|
-
* @property {(buf: Uint8Array) => any} decodeCreate
|
|
19
|
-
* @property {(handle: any, op: string, data: any) => Uint8Array} encodeAction
|
|
20
|
-
* @property {(handle: any, op: string, buf: Uint8Array) => any} decodeAction
|
|
21
|
-
*/
|
|
22
|
-
/**
|
|
23
|
-
* Attach a `codec` namespace to a hyperschema-shaped `spec`. Looks up
|
|
24
|
-
* envelope types using the spec's namespace (`@<ns>/rows` etc.) and falls
|
|
25
|
-
* back to the bundled `@cero/*` envelopes when the spec has not declared
|
|
26
|
-
* its own. Returns the spec for chaining.
|
|
27
|
-
*
|
|
28
|
-
* @param {Spec} spec
|
|
29
|
-
* @returns {Spec}
|
|
30
|
-
*/
|
|
31
|
-
export function bindCodec(spec: Spec): Spec;
|
|
32
|
-
export { RPCServer } from "./server.js";
|
|
33
|
-
export { RPCClient } from "./client.js";
|
|
1
|
+
export { RPCServer } from './server.js';
|
|
2
|
+
export { RPCClient } from './client.js';
|
|
34
3
|
export type Spec = {
|
|
35
4
|
/**
|
|
36
5
|
* hyperschema-shaped module.
|
|
@@ -75,3 +44,31 @@ export type Codec = {
|
|
|
75
44
|
encodeAction: (handle: any, op: string, data: any) => Uint8Array;
|
|
76
45
|
decodeAction: (handle: any, op: string, buf: Uint8Array) => any;
|
|
77
46
|
};
|
|
47
|
+
/**
|
|
48
|
+
* @typedef {object} Spec
|
|
49
|
+
* @property {{ encode: (type: string, value: any) => Uint8Array, decode: (type: string, buf: Uint8Array) => any, getEncoding?: (name: string) => any }} schema hyperschema-shaped module.
|
|
50
|
+
* @property {{ ns?: string }} [meta] Optional metadata; `ns` controls envelope type fqns.
|
|
51
|
+
* @property {any} [rpc] hrpc constructor used by RPCServer/RPCClient.
|
|
52
|
+
* @property {Codec} [codec] Filled in by `bindCodec`.
|
|
53
|
+
*
|
|
54
|
+
* @typedef {object} Codec
|
|
55
|
+
* @property {(type: string, row: any) => Uint8Array} encodeRow
|
|
56
|
+
* @property {(type: string, buf: Uint8Array) => any} decodeRow
|
|
57
|
+
* @property {(type: string, rows: any[]) => Uint8Array} encodeRows
|
|
58
|
+
* @property {(type: string, changes: Array<{ prev: any, next: any }>) => Uint8Array} encodeChanges
|
|
59
|
+
* @property {(type: string, buf: Uint8Array) => Array<{ prev: any, next: any }>} decodeChanges
|
|
60
|
+
* @property {(type: string, buf: Uint8Array) => any[]} decodeRows
|
|
61
|
+
* @property {(q: any) => Uint8Array} encodeQuery
|
|
62
|
+
* @property {(buf: Uint8Array) => any} decodeQuery
|
|
63
|
+
* @property {(row: any) => Uint8Array} encodeCreate
|
|
64
|
+
* @property {(buf: Uint8Array) => any} decodeCreate
|
|
65
|
+
* @property {(handle: any, op: string, data: any) => Uint8Array} encodeAction
|
|
66
|
+
* @property {(handle: any, op: string, buf: Uint8Array) => any} decodeAction
|
|
67
|
+
*/
|
|
68
|
+
/**
|
|
69
|
+
* Attach a `codec` namespace to a hyperschema-shaped `spec`.
|
|
70
|
+
*
|
|
71
|
+
* @param {Spec} spec
|
|
72
|
+
* @returns {Spec}
|
|
73
|
+
*/
|
|
74
|
+
export declare function bindCodec(spec: Spec): Spec;
|