@cero-base/core 2.2.1 → 2.3.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 +32 -212
- package/package.json +18 -9
- package/src/blobs/index.js +9 -0
- package/src/blobs/server.js +2 -0
- package/src/database/changes.js +1 -1
- package/src/database/dispatch.js +341 -209
- package/src/database/encryption.js +83 -33
- package/src/database/index.js +184 -83
- package/src/database/rotation.js +43 -30
- package/src/identity/index.js +20 -78
- package/src/index.js +3 -10
- package/src/lib/constants.js +2 -0
- package/src/lib/errors.js +3 -11
- package/src/lib/spec/index.js +136 -132
- package/src/lib/spec/schema.json +84 -99
- package/src/lib/utils.js +57 -3
- package/src/mailbox/inbox.js +103 -0
- package/src/mailbox/index.js +146 -0
- package/src/mailbox/post.js +69 -0
- package/src/network/discovery.js +26 -1
- package/src/network/index.js +105 -64
- package/src/network/presence.js +6 -2
- package/src/pairing/index.js +330 -254
- package/src/pairing/invite.js +83 -144
- package/src/pairing/request.js +54 -56
- package/src/rpc/index.js +18 -93
- package/src/rpc/peer.js +4 -1
- package/src/storage/index.js +78 -39
- package/types/blobs/index.d.ts +22 -9
- package/types/blobs/server.d.ts +4 -2
- package/types/database/changes.d.ts +2 -2
- package/types/database/dispatch.d.ts +19 -13
- package/types/database/encryption.d.ts +67 -29
- package/types/database/index.d.ts +144 -119
- package/types/database/rotation.d.ts +32 -13
- package/types/identity/index.d.ts +6 -47
- package/types/index.d.ts +3 -16
- package/types/lib/constants.d.ts +1 -0
- package/types/lib/errors.d.ts +3 -9
- package/types/lib/spec/index.d.ts +52 -16
- package/types/lib/utils.d.ts +40 -8
- package/types/mailbox/inbox.d.ts +52 -0
- package/types/mailbox/index.d.ts +111 -0
- package/types/mailbox/post.d.ts +37 -0
- package/types/network/discovery.d.ts +21 -5
- package/types/network/index.d.ts +64 -48
- package/types/network/presence.d.ts +17 -4
- package/types/pairing/index.d.ts +143 -134
- package/types/pairing/invite.d.ts +70 -114
- package/types/pairing/request.d.ts +58 -98
- package/types/rpc/index.d.ts +26 -44
- package/types/rpc/peer.d.ts +10 -7
- package/types/storage/index.d.ts +64 -54
- package/src/pairing/candidate.js +0 -123
- package/types/pairing/candidate.d.ts +0 -36
|
@@ -16,7 +16,17 @@ export declare class Presence {
|
|
|
16
16
|
active: number;
|
|
17
17
|
announced: number;
|
|
18
18
|
idle: number;
|
|
19
|
-
|
|
19
|
+
/** @type {Map<string, { topic: Uint8Array, pinned: boolean, refs: number, touched: number, off: boolean, discovery: import('./discovery.js').Discovery | null, timer: ReturnType<typeof setTimeout> | null, pending: 'active' | 'passive' | null }>} */
|
|
20
|
+
entries: Map<string, {
|
|
21
|
+
topic: Uint8Array;
|
|
22
|
+
pinned: boolean;
|
|
23
|
+
refs: number;
|
|
24
|
+
touched: number;
|
|
25
|
+
off: boolean;
|
|
26
|
+
discovery: import('./discovery.js').Discovery | null;
|
|
27
|
+
timer: ReturnType<typeof setTimeout> | null;
|
|
28
|
+
pending: 'active' | 'passive' | null;
|
|
29
|
+
}>;
|
|
20
30
|
/**
|
|
21
31
|
* @param {import('./index.js').Network} network
|
|
22
32
|
* @param {{ active?: number, announced?: number, idle?: number }} [opts]
|
|
@@ -44,7 +54,10 @@ export declare class Presence {
|
|
|
44
54
|
mode(topic: Uint8Array): 'active' | 'passive' | null;
|
|
45
55
|
refresh(): void;
|
|
46
56
|
close(): void;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
57
|
+
/** @private */
|
|
58
|
+
private _want;
|
|
59
|
+
/** @private */
|
|
60
|
+
private _settle;
|
|
61
|
+
/** @private */
|
|
62
|
+
private _leave;
|
|
50
63
|
}
|
package/types/pairing/index.d.ts
CHANGED
|
@@ -1,190 +1,199 @@
|
|
|
1
1
|
import ReadyResource from 'ready-resource';
|
|
2
|
+
import { Invite } from './invite.js';
|
|
3
|
+
import { Request } from './request.js';
|
|
4
|
+
import { Mailbox } from '../mailbox/index.js';
|
|
5
|
+
export type KeyPair = {
|
|
6
|
+
publicKey: Uint8Array;
|
|
7
|
+
secretKey: Uint8Array;
|
|
8
|
+
};
|
|
2
9
|
export type PairingOpts = {
|
|
3
10
|
/**
|
|
4
|
-
*
|
|
11
|
+
* The device's mailbox: replies are sent from there.
|
|
5
12
|
*/
|
|
6
|
-
|
|
13
|
+
mailbox: Mailbox;
|
|
7
14
|
/**
|
|
8
|
-
*
|
|
15
|
+
* The database the invites open. Its `invites` collection holds them, and apply admits their joins.
|
|
9
16
|
*/
|
|
10
|
-
|
|
17
|
+
db: import('../database/index.js').Database;
|
|
18
|
+
};
|
|
19
|
+
export type InviteOpts = {
|
|
11
20
|
/**
|
|
12
|
-
*
|
|
21
|
+
* Role granted, at most your own. Member by default.
|
|
13
22
|
*/
|
|
14
|
-
|
|
23
|
+
role?: string;
|
|
15
24
|
/**
|
|
16
|
-
*
|
|
25
|
+
* How long it is valid: ms, or `'12h'`, `'2d'`… Never expires when omitted.
|
|
17
26
|
*/
|
|
18
|
-
|
|
27
|
+
ttl?: number | string;
|
|
19
28
|
/**
|
|
20
|
-
*
|
|
29
|
+
* Admit more than one joiner. Otherwise spent by the first.
|
|
21
30
|
*/
|
|
22
|
-
|
|
31
|
+
reuse?: boolean;
|
|
23
32
|
/**
|
|
24
|
-
*
|
|
33
|
+
* Its joins wait for a member to accept them, as requests.
|
|
25
34
|
*/
|
|
26
|
-
|
|
35
|
+
confirm?: boolean;
|
|
27
36
|
/**
|
|
28
|
-
*
|
|
37
|
+
* The app's payload in the invite, readable before joining: `Invite.parse(invite).data`.
|
|
29
38
|
*/
|
|
30
|
-
|
|
39
|
+
data?: Uint8Array | null;
|
|
31
40
|
};
|
|
32
|
-
export type
|
|
41
|
+
export type JoinOpts = {
|
|
33
42
|
/**
|
|
34
|
-
*
|
|
43
|
+
* Who joins: the member they become, and who signs the join.
|
|
35
44
|
*/
|
|
36
|
-
|
|
45
|
+
identity: import('../identity/index.js').Identity;
|
|
37
46
|
/**
|
|
38
|
-
*
|
|
47
|
+
* The database's spec: the join is one of its ops.
|
|
39
48
|
*/
|
|
40
|
-
|
|
49
|
+
spec: {
|
|
50
|
+
dispatch: {
|
|
51
|
+
encode: Function;
|
|
52
|
+
};
|
|
53
|
+
meta?: {
|
|
54
|
+
ns?: string;
|
|
55
|
+
version?: number;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
41
58
|
/**
|
|
42
|
-
*
|
|
59
|
+
* Their writer keypair in the database, a fresh one by default. The join is its first block and its secret key owns the reply address: pass the same one to resume a join after a restart.
|
|
43
60
|
*/
|
|
44
|
-
|
|
61
|
+
writer?: KeyPair;
|
|
45
62
|
/**
|
|
46
|
-
*
|
|
63
|
+
* Deadline for the reply, in ms; `0` waits until the invite expires, or for good. Defaults to 30000.
|
|
47
64
|
*/
|
|
48
|
-
|
|
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;
|
|
65
|
+
timeout?: number;
|
|
55
66
|
/**
|
|
56
|
-
*
|
|
67
|
+
* Stops the join, rejecting it with `CLOSED`, as closing the mailbox does.
|
|
57
68
|
*/
|
|
58
|
-
|
|
69
|
+
signal?: AbortSignal;
|
|
59
70
|
};
|
|
60
71
|
export type JoinResult = {
|
|
61
72
|
key: Uint8Array;
|
|
62
73
|
encryptionKey: Uint8Array | null;
|
|
63
|
-
|
|
74
|
+
epochs: Array<{
|
|
75
|
+
epoch: number;
|
|
76
|
+
stamp: number;
|
|
77
|
+
entropy: Uint8Array;
|
|
78
|
+
}>;
|
|
79
|
+
/**
|
|
80
|
+
* The writer the join admitted: open the database with it.
|
|
81
|
+
*/
|
|
82
|
+
writer: KeyPair;
|
|
64
83
|
};
|
|
65
84
|
/**
|
|
85
|
+
* @typedef {{ publicKey: Uint8Array, secretKey: Uint8Array }} KeyPair
|
|
86
|
+
*
|
|
66
87
|
* @typedef {object} PairingOpts
|
|
67
|
-
* @property {
|
|
68
|
-
* @property {import('../
|
|
69
|
-
* @property {Uint8Array} [topic] Optional override topic; defaults to `identity.publicKey`.
|
|
70
|
-
* @property {boolean} [host] 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.
|
|
71
|
-
* @property {any} [inviteEncoding] compact-encoding type for the invite payload `data`.
|
|
72
|
-
* @property {any} [joinerEncoding] compact-encoding type for the joiner-supplied `userData`.
|
|
73
|
-
* @property {(err: Error) => void} [onerror] Called when a background candidate fails to process.
|
|
88
|
+
* @property {Mailbox} mailbox The device's mailbox: replies are sent from there.
|
|
89
|
+
* @property {import('../database/index.js').Database} db The database the invites open. Its `invites` collection holds them, and apply admits their joins.
|
|
74
90
|
*
|
|
75
|
-
* @typedef {object}
|
|
76
|
-
* @property {string} [role]
|
|
77
|
-
* @property {number} [
|
|
78
|
-
* @property {
|
|
79
|
-
* @property {boolean} [
|
|
91
|
+
* @typedef {object} InviteOpts
|
|
92
|
+
* @property {string} [role] Role granted, at most your own. Member by default.
|
|
93
|
+
* @property {number | string} [ttl] How long it is valid: ms, or `'12h'`, `'2d'`… Never expires when omitted.
|
|
94
|
+
* @property {boolean} [reuse] Admit more than one joiner. Otherwise spent by the first.
|
|
95
|
+
* @property {boolean} [confirm] Its joins wait for a member to accept them, as requests.
|
|
96
|
+
* @property {Uint8Array | null} [data] The app's payload in the invite, readable before joining: `Invite.parse(invite).data`.
|
|
80
97
|
*
|
|
81
98
|
* @typedef {object} JoinOpts
|
|
82
|
-
* @property {
|
|
83
|
-
* @property {number}
|
|
99
|
+
* @property {import('../identity/index.js').Identity} identity Who joins: the member they become, and who signs the join.
|
|
100
|
+
* @property {{ dispatch: { encode: Function }, meta?: { ns?: string, version?: number } }} spec The database's spec: the join is one of its ops.
|
|
101
|
+
* @property {KeyPair} [writer] Their writer keypair in the database, a fresh one by default. The join is its first block and its secret key owns the reply address: pass the same one to resume a join after a restart.
|
|
102
|
+
* @property {number} [timeout] Deadline for the reply, in ms; `0` waits until the invite expires, or for good. Defaults to 30000.
|
|
103
|
+
* @property {AbortSignal} [signal] Stops the join, rejecting it with `CLOSED`, as closing the mailbox does.
|
|
84
104
|
*
|
|
85
|
-
* @typedef {
|
|
105
|
+
* @typedef {object} JoinResult
|
|
106
|
+
* @property {Uint8Array} key
|
|
107
|
+
* @property {Uint8Array | null} encryptionKey
|
|
108
|
+
* @property {Array<{ epoch: number, stamp: number, entropy: Uint8Array }>} epochs
|
|
109
|
+
* @property {KeyPair} writer The writer the join admitted: open the database with it.
|
|
86
110
|
*/
|
|
87
111
|
/**
|
|
88
|
-
*
|
|
89
|
-
*
|
|
112
|
+
* Invites into a database. An invite is a record in the database; a joiner writes one signed
|
|
113
|
+
* `join` op into its own writer core and announces it to the database's peers, and apply admits
|
|
114
|
+
* it. The admission stays in the database until the joiner has its keys: every device of a member
|
|
115
|
+
* that may invite offers them while online, and the first one read settles it for all. A
|
|
116
|
+
* `confirm` invite's joins wait as requests until a member accepts or denies them; `'request'`
|
|
117
|
+
* fires for each new one.
|
|
118
|
+
* `Pairing.join` is the other side: write the join, wait for the reply.
|
|
90
119
|
*/
|
|
91
120
|
export declare class Pairing extends ReadyResource {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
121
|
+
mailbox: Mailbox;
|
|
122
|
+
db: import("../index.js").Database;
|
|
123
|
+
/** @type {Set<Request>} requests not answered yet: whoever attaches after one fired goes through these first */
|
|
124
|
+
pending: Set<Request>;
|
|
125
|
+
/** Whether this device answers the database's joins: it may invite, and invites or joiners owed their keys exist. */
|
|
126
|
+
serving: boolean;
|
|
127
|
+
/** @private */
|
|
128
|
+
_requests;
|
|
129
|
+
/** @private */
|
|
130
|
+
_replies;
|
|
131
|
+
/** @private */
|
|
132
|
+
_expiry;
|
|
133
|
+
/** @private */
|
|
134
|
+
_onupdate;
|
|
104
135
|
/** @param {PairingOpts} [opts] */
|
|
105
|
-
constructor({
|
|
106
|
-
/**
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
*/
|
|
111
|
-
get suspended(): boolean;
|
|
112
|
-
_open(): Promise<void>;
|
|
113
|
-
_close(): Promise<void>;
|
|
136
|
+
constructor({ mailbox, db }?: PairingOpts);
|
|
137
|
+
/** @private */
|
|
138
|
+
private _open;
|
|
139
|
+
/** @private */
|
|
140
|
+
private _close;
|
|
114
141
|
/**
|
|
115
|
-
* Mint
|
|
142
|
+
* Mint an invite. Returns its wire form, a z32 string.
|
|
116
143
|
*
|
|
117
|
-
* @param {
|
|
144
|
+
* @param {InviteOpts} [opts]
|
|
118
145
|
* @returns {Promise<string>}
|
|
119
146
|
*/
|
|
120
|
-
|
|
147
|
+
invite({ role, ttl, reuse, confirm, data }?: InviteOpts): Promise<string>;
|
|
121
148
|
/**
|
|
122
|
-
*
|
|
149
|
+
* Revoke an invite, for every member. Needs the remove permission.
|
|
123
150
|
*
|
|
124
|
-
* @param {string}
|
|
125
|
-
* @returns {
|
|
126
|
-
*/
|
|
127
|
-
recordOf(inviteStr: string): {
|
|
128
|
-
id: Uint8Array;
|
|
129
|
-
seed: Uint8Array;
|
|
130
|
-
publicKey: Uint8Array;
|
|
131
|
-
invite: import('./invite.js').Invite;
|
|
132
|
-
reuse: boolean;
|
|
133
|
-
} | null;
|
|
134
|
-
/**
|
|
135
|
-
* Reconcile the served-invite set with persisted rows (the room's `invites` collection).
|
|
136
|
-
*
|
|
137
|
-
* @param {Array<{ id: string, invite: Uint8Array, publicKey: Uint8Array, seed: Uint8Array, reuse?: boolean }>} rows
|
|
138
|
-
*/
|
|
139
|
-
syncRows(rows: Array<{
|
|
140
|
-
id: string;
|
|
141
|
-
invite: Uint8Array;
|
|
142
|
-
publicKey: Uint8Array;
|
|
143
|
-
seed: Uint8Array;
|
|
144
|
-
reuse?: boolean;
|
|
145
|
-
}>): void;
|
|
146
|
-
/**
|
|
147
|
-
* Forget a previously-minted invite. New candidates carrying it will be
|
|
148
|
-
* dropped silently.
|
|
149
|
-
*
|
|
150
|
-
* @param {string} inviteStr
|
|
151
|
-
* @returns {boolean}
|
|
152
|
-
*/
|
|
153
|
-
revoke(inviteStr: string): boolean;
|
|
154
|
-
/**
|
|
155
|
-
* Joiner side — start a pairing handshake against `inviteStr` and resolve
|
|
156
|
-
* with the host's response when the host confirms.
|
|
157
|
-
*
|
|
158
|
-
* @param {string} inviteStr
|
|
159
|
-
* @param {JoinOpts} [opts]
|
|
160
|
-
* @returns {Promise<JoinResult>}
|
|
161
|
-
*/
|
|
162
|
-
join(inviteStr: string, { userData, timeout }?: JoinOpts): Promise<JoinResult>;
|
|
163
|
-
/**
|
|
164
|
-
* Pause blind-pairing — keeps state, drops sockets. Idempotent.
|
|
165
|
-
*
|
|
166
|
-
* @returns {Promise<void>}
|
|
151
|
+
* @param {string} invite
|
|
152
|
+
* @returns {Promise<boolean>} Whether it was live.
|
|
167
153
|
*/
|
|
168
|
-
|
|
154
|
+
revoke(invite: string): Promise<boolean>;
|
|
169
155
|
/**
|
|
170
|
-
*
|
|
156
|
+
* A join waiting on a `confirm` invite, by its id in the `requests` collection.
|
|
171
157
|
*
|
|
172
|
-
* @
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
|
|
158
|
+
* @param {string} id
|
|
159
|
+
* @returns {Promise<Request>}
|
|
160
|
+
*/
|
|
161
|
+
request(id: string): Promise<Request>;
|
|
162
|
+
/** @private */
|
|
163
|
+
private _sync;
|
|
164
|
+
/** @private */
|
|
165
|
+
private _arm;
|
|
166
|
+
/** @private */
|
|
167
|
+
private _pending;
|
|
168
|
+
/** @private */
|
|
169
|
+
private _answer;
|
|
170
|
+
/** @private */
|
|
171
|
+
private _reply;
|
|
172
|
+
/** @private */
|
|
173
|
+
private _me;
|
|
174
|
+
/** @private */
|
|
175
|
+
private _checkGrant;
|
|
176
|
+
/**
|
|
177
|
+
* Join with an invite: write the join into the writer's own core, announce it to the
|
|
178
|
+
* database's peers, and resolve with the database's keys once a member replies.
|
|
178
179
|
*
|
|
180
|
+
* @param {Mailbox} mailbox
|
|
179
181
|
* @param {string} invite
|
|
180
|
-
* @
|
|
181
|
-
|
|
182
|
-
static inviteTopic(invite: string): Uint8Array | null;
|
|
183
|
-
/**
|
|
184
|
-
* Cheap structural test for a candidate invite string.
|
|
185
|
-
*
|
|
186
|
-
* @param {unknown} str
|
|
187
|
-
* @returns {boolean}
|
|
182
|
+
* @param {JoinOpts} opts
|
|
183
|
+
* @returns {Promise<JoinResult>}
|
|
188
184
|
*/
|
|
189
|
-
static
|
|
185
|
+
static join(mailbox: Mailbox, invite: string, { identity, spec, writer, timeout, signal }?: JoinOpts): Promise<JoinResult>;
|
|
190
186
|
}
|
|
187
|
+
/**
|
|
188
|
+
* A join's payload: sealed to the database's address, so only its members read who joins; proven
|
|
189
|
+
* by the invite over the writer; signed by the joiner's identity for this writer and reply address.
|
|
190
|
+
*
|
|
191
|
+
* @param {Invite} invite
|
|
192
|
+
* @param {import('../identity/index.js').Identity} identity
|
|
193
|
+
* @param {Uint8Array} writer
|
|
194
|
+
* @param {Uint8Array} reply
|
|
195
|
+
* @returns {{ box: Uint8Array }}
|
|
196
|
+
*/
|
|
197
|
+
export declare function sealJoin(invite: Invite, identity: import('../identity/index.js').Identity, writer: Uint8Array, reply: Uint8Array): {
|
|
198
|
+
box: Uint8Array;
|
|
199
|
+
};
|
|
@@ -1,157 +1,113 @@
|
|
|
1
1
|
export type InviteFields = {
|
|
2
|
-
/**
|
|
3
|
-
* Signer's long-lived public key.
|
|
4
|
-
*/
|
|
5
|
-
publicKey: Uint8Array;
|
|
6
|
-
/**
|
|
7
|
-
* Optional role tag baked into the signed body.
|
|
8
|
-
*/
|
|
9
|
-
role: string;
|
|
10
2
|
/**
|
|
11
3
|
* Absolute expiry timestamp; `0` means never.
|
|
12
4
|
*/
|
|
13
5
|
expires: number;
|
|
14
6
|
/**
|
|
15
|
-
*
|
|
16
|
-
*/
|
|
17
|
-
data: Uint8Array | null;
|
|
18
|
-
/**
|
|
19
|
-
* Raw blind-pairing invite handed to candidates.
|
|
20
|
-
*/
|
|
21
|
-
blind: Uint8Array;
|
|
22
|
-
/**
|
|
23
|
-
* Ed25519 signature over the canonical body.
|
|
24
|
-
*/
|
|
25
|
-
sig?: Uint8Array;
|
|
26
|
-
/**
|
|
27
|
-
* Cached z32 string form.
|
|
28
|
-
*/
|
|
29
|
-
_str?: string | null;
|
|
30
|
-
};
|
|
31
|
-
export type CreateInviteOpts = {
|
|
32
|
-
/**
|
|
33
|
-
* 64-byte Ed25519 secret key used to sign.
|
|
34
|
-
*/
|
|
35
|
-
secretKey: Uint8Array;
|
|
36
|
-
/**
|
|
37
|
-
* 32-byte Ed25519 public key matching `secretKey`.
|
|
38
|
-
*/
|
|
39
|
-
publicKey: Uint8Array;
|
|
40
|
-
/**
|
|
41
|
-
* Optional role tag for the joiner.
|
|
42
|
-
*/
|
|
43
|
-
role: string;
|
|
44
|
-
/**
|
|
45
|
-
* TTL in ms from now; `0` means never expires.
|
|
7
|
+
* Key of the database the invite opens.
|
|
46
8
|
*/
|
|
47
|
-
|
|
9
|
+
key: Uint8Array;
|
|
48
10
|
/**
|
|
49
|
-
*
|
|
11
|
+
* The database's address: a join is sealed to it.
|
|
50
12
|
*/
|
|
51
|
-
|
|
13
|
+
address: Uint8Array;
|
|
52
14
|
/**
|
|
53
|
-
*
|
|
15
|
+
* The invite's secret; its keypair proves a join.
|
|
54
16
|
*/
|
|
55
|
-
|
|
17
|
+
seed: Uint8Array;
|
|
56
18
|
/**
|
|
57
|
-
*
|
|
19
|
+
* The node that added its record: a join links it, so no member applies the join first.
|
|
58
20
|
*/
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
21
|
+
link: {
|
|
22
|
+
key: Uint8Array;
|
|
23
|
+
length: number;
|
|
24
|
+
} | null;
|
|
62
25
|
/**
|
|
63
|
-
*
|
|
26
|
+
* The app's payload, readable before joining. Unsigned: a hint, not proof.
|
|
64
27
|
*/
|
|
65
|
-
|
|
28
|
+
data?: Uint8Array | null;
|
|
66
29
|
};
|
|
67
30
|
/**
|
|
68
31
|
* @typedef {object} InviteFields
|
|
69
|
-
* @property {
|
|
70
|
-
* @property {
|
|
71
|
-
* @property {
|
|
72
|
-
* @property {Uint8Array
|
|
73
|
-
* @property {Uint8Array}
|
|
74
|
-
* @property {Uint8Array} [
|
|
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.
|
|
32
|
+
* @property {number} expires Absolute expiry timestamp; `0` means never.
|
|
33
|
+
* @property {Uint8Array} key Key of the database the invite opens.
|
|
34
|
+
* @property {Uint8Array} address The database's address: a join is sealed to it.
|
|
35
|
+
* @property {Uint8Array} seed The invite's secret; its keypair proves a join.
|
|
36
|
+
* @property {{ key: Uint8Array, length: number } | null} link The node that added its record: a join links it, so no member applies the join first.
|
|
37
|
+
* @property {Uint8Array | null} [data] The app's payload, readable before joining. Unsigned: a hint, not proof.
|
|
88
38
|
*/
|
|
89
39
|
/**
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
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.
|
|
40
|
+
* An invite: the database it opens, the address a join is sealed to, and a seed whose keypair
|
|
41
|
+
* proves the joiner holds the invite. Role and expiry come from the database's own record;
|
|
42
|
+
* `expires` is here so a joiner fails fast.
|
|
96
43
|
*/
|
|
97
44
|
export declare class Invite {
|
|
98
45
|
version: number;
|
|
99
|
-
publicKey: Uint8Array<ArrayBufferLike>;
|
|
100
|
-
role: string;
|
|
101
46
|
expires: number;
|
|
47
|
+
key: Uint8Array<ArrayBufferLike>;
|
|
48
|
+
address: Uint8Array<ArrayBufferLike>;
|
|
49
|
+
seed: Uint8Array<ArrayBufferLike>;
|
|
50
|
+
link: {
|
|
51
|
+
key: Uint8Array;
|
|
52
|
+
length: number;
|
|
53
|
+
};
|
|
102
54
|
data: Uint8Array<ArrayBufferLike>;
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
/** @param {InviteFields} fields */
|
|
108
|
-
constructor(
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
* @returns {boolean}
|
|
113
|
-
*/
|
|
55
|
+
/** @private */
|
|
56
|
+
_str;
|
|
57
|
+
/** @private */
|
|
58
|
+
_keyPair;
|
|
59
|
+
/** @param {InviteFields & { _str?: string }} fields */
|
|
60
|
+
constructor({ expires, key, address, seed, link, data, _str }: InviteFields & {
|
|
61
|
+
_str?: string;
|
|
62
|
+
});
|
|
63
|
+
/** @returns {boolean} Whether the invite is past its expiry (never when `expires === 0`). */
|
|
114
64
|
get expired(): boolean;
|
|
65
|
+
/** @returns {Uint8Array} Discovery key of the database the invite opens. */
|
|
66
|
+
get discoveryKey(): Uint8Array;
|
|
67
|
+
/** @returns {Uint8Array} The invite's id: the public key of its seed's keypair. */
|
|
68
|
+
get id(): Uint8Array;
|
|
115
69
|
/**
|
|
116
|
-
*
|
|
70
|
+
* Sign a writer with the invite's key, proving the join in that writer's core comes from its
|
|
71
|
+
* holder.
|
|
117
72
|
*
|
|
73
|
+
* @param {Uint8Array} writer
|
|
118
74
|
* @returns {Uint8Array}
|
|
119
75
|
*/
|
|
120
|
-
|
|
76
|
+
prove(writer: Uint8Array): Uint8Array;
|
|
77
|
+
/** @returns {string} The z32 wire form. */
|
|
78
|
+
toString(): string;
|
|
79
|
+
/** @private */
|
|
80
|
+
private _pair;
|
|
121
81
|
/**
|
|
122
|
-
*
|
|
82
|
+
* Whether `proof` is the invite `id`'s signature over `writer`.
|
|
123
83
|
*
|
|
84
|
+
* @param {Uint8Array} id
|
|
85
|
+
* @param {Uint8Array} writer
|
|
86
|
+
* @param {Uint8Array} proof
|
|
124
87
|
* @returns {boolean}
|
|
125
88
|
*/
|
|
126
|
-
|
|
89
|
+
static proven(id: Uint8Array, writer: Uint8Array, proof: Uint8Array): boolean;
|
|
127
90
|
/**
|
|
128
|
-
*
|
|
91
|
+
* A new invite with a fresh seed.
|
|
129
92
|
*
|
|
130
|
-
* @
|
|
131
|
-
*/
|
|
132
|
-
toString(): string;
|
|
133
|
-
/**
|
|
134
|
-
* Build and sign a new invite envelope wrapping a blind-pairing invite.
|
|
135
|
-
*
|
|
136
|
-
* @param {CreateInviteOpts} opts
|
|
93
|
+
* @param {{ ttl?: number | string, key: Uint8Array, address: Uint8Array, link?: { key: Uint8Array, length: number } | null, data?: Uint8Array | null }} opts
|
|
137
94
|
* @returns {Invite}
|
|
138
95
|
*/
|
|
139
|
-
static create({
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
96
|
+
static create({ ttl, key, address, link, data }: {
|
|
97
|
+
ttl?: number | string;
|
|
98
|
+
key: Uint8Array;
|
|
99
|
+
address: Uint8Array;
|
|
100
|
+
link?: {
|
|
101
|
+
key: Uint8Array;
|
|
102
|
+
length: number;
|
|
103
|
+
} | null;
|
|
104
|
+
data?: Uint8Array | null;
|
|
105
|
+
}): Invite;
|
|
106
|
+
/**
|
|
107
|
+
* Parse an invite string.
|
|
143
108
|
*
|
|
144
109
|
* @param {string} str
|
|
145
|
-
* @param {ParseInviteOpts} [opts]
|
|
146
110
|
* @returns {Invite}
|
|
147
111
|
*/
|
|
148
|
-
static parse(str: string
|
|
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;
|
|
112
|
+
static parse(str: string): Invite;
|
|
157
113
|
}
|