@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.
Files changed (55) hide show
  1. package/README.md +32 -212
  2. package/package.json +18 -9
  3. package/src/blobs/index.js +9 -0
  4. package/src/blobs/server.js +2 -0
  5. package/src/database/changes.js +1 -1
  6. package/src/database/dispatch.js +341 -209
  7. package/src/database/encryption.js +83 -33
  8. package/src/database/index.js +184 -83
  9. package/src/database/rotation.js +43 -30
  10. package/src/identity/index.js +20 -78
  11. package/src/index.js +3 -10
  12. package/src/lib/constants.js +2 -0
  13. package/src/lib/errors.js +3 -11
  14. package/src/lib/spec/index.js +136 -132
  15. package/src/lib/spec/schema.json +84 -99
  16. package/src/lib/utils.js +57 -3
  17. package/src/mailbox/inbox.js +103 -0
  18. package/src/mailbox/index.js +146 -0
  19. package/src/mailbox/post.js +69 -0
  20. package/src/network/discovery.js +26 -1
  21. package/src/network/index.js +105 -64
  22. package/src/network/presence.js +6 -2
  23. package/src/pairing/index.js +330 -254
  24. package/src/pairing/invite.js +83 -144
  25. package/src/pairing/request.js +54 -56
  26. package/src/rpc/index.js +18 -93
  27. package/src/rpc/peer.js +4 -1
  28. package/src/storage/index.js +78 -39
  29. package/types/blobs/index.d.ts +22 -9
  30. package/types/blobs/server.d.ts +4 -2
  31. package/types/database/changes.d.ts +2 -2
  32. package/types/database/dispatch.d.ts +19 -13
  33. package/types/database/encryption.d.ts +67 -29
  34. package/types/database/index.d.ts +144 -119
  35. package/types/database/rotation.d.ts +32 -13
  36. package/types/identity/index.d.ts +6 -47
  37. package/types/index.d.ts +3 -16
  38. package/types/lib/constants.d.ts +1 -0
  39. package/types/lib/errors.d.ts +3 -9
  40. package/types/lib/spec/index.d.ts +52 -16
  41. package/types/lib/utils.d.ts +40 -8
  42. package/types/mailbox/inbox.d.ts +52 -0
  43. package/types/mailbox/index.d.ts +111 -0
  44. package/types/mailbox/post.d.ts +37 -0
  45. package/types/network/discovery.d.ts +21 -5
  46. package/types/network/index.d.ts +64 -48
  47. package/types/network/presence.d.ts +17 -4
  48. package/types/pairing/index.d.ts +143 -134
  49. package/types/pairing/invite.d.ts +70 -114
  50. package/types/pairing/request.d.ts +58 -98
  51. package/types/rpc/index.d.ts +26 -44
  52. package/types/rpc/peer.d.ts +10 -7
  53. package/types/storage/index.d.ts +64 -54
  54. package/src/pairing/candidate.js +0 -123
  55. 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
- entries: Map<any, any>;
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
- _want(e: any, mode: any): void;
48
- _settle(e: any): void;
49
- _leave(e: any): void;
57
+ /** @private */
58
+ private _want;
59
+ /** @private */
60
+ private _settle;
61
+ /** @private */
62
+ private _leave;
50
63
  }
@@ -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
- * Network to host the BlindPairing member.
11
+ * The device's mailbox: replies are sent from there.
5
12
  */
6
- network: import('../network/index.js').Network;
13
+ mailbox: Mailbox;
7
14
  /**
8
- * Identity used to sign invites and derive the topic.
15
+ * The database the invites open. Its `invites` collection holds them, and apply admits their joins.
9
16
  */
10
- identity: import('../identity/index.js').Identity;
17
+ db: import('../database/index.js').Database;
18
+ };
19
+ export type InviteOpts = {
11
20
  /**
12
- * Optional override topic; defaults to `identity.publicKey`.
21
+ * Role granted, at most your own. Member by default.
13
22
  */
14
- topic?: Uint8Array;
23
+ role?: string;
15
24
  /**
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.
25
+ * How long it is valid: ms, or `'12h'`, `'2d'`… Never expires when omitted.
17
26
  */
18
- host?: boolean;
27
+ ttl?: number | string;
19
28
  /**
20
- * compact-encoding type for the invite payload `data`.
29
+ * Admit more than one joiner. Otherwise spent by the first.
21
30
  */
22
- inviteEncoding?: any;
31
+ reuse?: boolean;
23
32
  /**
24
- * compact-encoding type for the joiner-supplied `userData`.
33
+ * Its joins wait for a member to accept them, as requests.
25
34
  */
26
- joinerEncoding?: any;
35
+ confirm?: boolean;
27
36
  /**
28
- * Called when a background candidate fails to process.
37
+ * The app's payload in the invite, readable before joining: `Invite.parse(invite).data`.
29
38
  */
30
- onerror?: (err: Error) => void;
39
+ data?: Uint8Array | null;
31
40
  };
32
- export type CreateInviteOpts = {
41
+ export type JoinOpts = {
33
42
  /**
34
- * Role tag bound into the invite.
43
+ * Who joins: the member they become, and who signs the join.
35
44
  */
36
- role?: string;
45
+ identity: import('../identity/index.js').Identity;
37
46
  /**
38
- * TTL in ms; `0`/omitted = no expiry.
47
+ * The database's spec: the join is one of its ops.
39
48
  */
40
- expiresIn?: number;
49
+ spec: {
50
+ dispatch: {
51
+ encode: Function;
52
+ };
53
+ meta?: {
54
+ ns?: string;
55
+ version?: number;
56
+ };
57
+ };
41
58
  /**
42
- * Arbitrary payload (encoded via `inviteEncoding` when set).
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
- data?: any;
61
+ writer?: KeyPair;
45
62
  /**
46
- * Reusable until expiry/revoke; default `false` (consumed on first settle).
63
+ * Deadline for the reply, in ms; `0` waits until the invite expires, or for good. Defaults to 30000.
47
64
  */
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;
65
+ timeout?: number;
55
66
  /**
56
- * Deadline for the handshake, in ms. Defaults to 30000.
67
+ * Stops the join, rejecting it with `CLOSED`, as closing the mailbox does.
57
68
  */
58
- timeout?: number;
69
+ signal?: AbortSignal;
59
70
  };
60
71
  export type JoinResult = {
61
72
  key: Uint8Array;
62
73
  encryptionKey: Uint8Array | null;
63
- additional: Uint8Array | null;
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 {import('../network/index.js').Network} network Network to host the BlindPairing member.
68
- * @property {import('../identity/index.js').Identity} identity Identity used to sign invites and derive the topic.
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} CreateInviteOpts
76
- * @property {string} [role] Role tag bound into the invite.
77
- * @property {number} [expiresIn] TTL in ms; `0`/omitted = no expiry.
78
- * @property {any} [data] Arbitrary payload (encoded via `inviteEncoding` when set).
79
- * @property {boolean} [reuse] Reusable until expiry/revoke; default `false` (consumed on first settle).
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 {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.
83
- * @property {number} [timeout] Deadline for the handshake, in ms. Defaults to 30000.
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 {{ key: Uint8Array, encryptionKey: Uint8Array | null, additional: Uint8Array | null }} JoinResult
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
- * Blind-pairing membership wrapper. Hosts invites, dispatches incoming candidates to the
89
- * application for accept/deny, and provides the joiner side of the handshake.
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
- network: import("../index.js").Network;
93
- identity: import("../index.js").Identity;
94
- topic: Uint8Array<ArrayBufferLike>;
95
- host: boolean;
96
- inviteEncoding: any;
97
- joinerEncoding: any;
98
- _onerror: (err: Error) => void;
99
- onconsume: any;
100
- _blind: any;
101
- _member: any;
102
- _invites: Map<any, any>;
103
- _candidates: Set<any>;
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({ 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>;
136
+ constructor({ mailbox, db }?: PairingOpts);
137
+ /** @private */
138
+ private _open;
139
+ /** @private */
140
+ private _close;
114
141
  /**
115
- * Mint a new pairing invite. Returns its canonical wire form (z32 string).
142
+ * Mint an invite. Returns its wire form, a z32 string.
116
143
  *
117
- * @param {CreateInviteOpts} [opts]
144
+ * @param {InviteOpts} [opts]
118
145
  * @returns {Promise<string>}
119
146
  */
120
- createInvite({ role, expiresIn, data, reuse }?: CreateInviteOpts): Promise<string>;
147
+ invite({ role, ttl, reuse, confirm, data }?: InviteOpts): Promise<string>;
121
148
  /**
122
- * Look up the in-memory record for a minted invite by its string form.
149
+ * Revoke an invite, for every member. Needs the remove permission.
123
150
  *
124
- * @param {string} inviteStr
125
- * @returns {{ id: Uint8Array, seed: Uint8Array, publicKey: Uint8Array, invite: import('./invite.js').Invite, reuse: boolean } | null}
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
- suspend(): Promise<void>;
154
+ revoke(invite: string): Promise<boolean>;
169
155
  /**
170
- * Resume a suspended blind-pairing layer. Idempotent.
156
+ * A join waiting on a `confirm` invite, by its id in the `requests` collection.
171
157
  *
172
- * @returns {Promise<void>}
173
- */
174
- resume(): Promise<void>;
175
- _oncandidate(req: any): Promise<void>;
176
- /**
177
- * Resolve the resource discovery key an invite targets — without pairing.
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
- * @returns {Uint8Array | null}
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 isInvite(str: unknown): boolean;
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
- * Encoded payload (raw or via `encoding`).
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
- expiresIn: number;
9
+ key: Uint8Array;
48
10
  /**
49
- * Caller payload; encoded via `encoding` when provided.
11
+ * The database's address: a join is sealed to it.
50
12
  */
51
- data: any;
13
+ address: Uint8Array;
52
14
  /**
53
- * Raw blind-pairing invite to wrap.
15
+ * The invite's secret; its keypair proves a join.
54
16
  */
55
- blind: Uint8Array;
17
+ seed: Uint8Array;
56
18
  /**
57
- * compact-encoding type used to encode `data`.
19
+ * The node that added its record: a join links it, so no member applies the join first.
58
20
  */
59
- encoding?: any;
60
- };
61
- export type ParseInviteOpts = {
21
+ link: {
22
+ key: Uint8Array;
23
+ length: number;
24
+ } | null;
62
25
  /**
63
- * compact-encoding type used to decode the embedded payload.
26
+ * The app's payload, readable before joining. Unsigned: a hint, not proof.
64
27
  */
65
- encoding?: any;
28
+ data?: Uint8Array | null;
66
29
  };
67
30
  /**
68
31
  * @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.
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
- * 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.
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
- 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
- */
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
- * Discovery key of the wrapped blind-pairing invite — the topic it targets.
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
- get discoveryKey(): Uint8Array;
76
+ prove(writer: Uint8Array): Uint8Array;
77
+ /** @returns {string} The z32 wire form. */
78
+ toString(): string;
79
+ /** @private */
80
+ private _pair;
121
81
  /**
122
- * Verify the embedded signature against the encoded body.
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
- verify(): boolean;
89
+ static proven(id: Uint8Array, writer: Uint8Array, proof: Uint8Array): boolean;
127
90
  /**
128
- * Serialise to the canonical z32 wire form (cached).
91
+ * A new invite with a fresh seed.
129
92
  *
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
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({ 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.
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, { 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;
112
+ static parse(str: string): Invite;
157
113
  }