@cero-base/core 2.12.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +8 -8
- package/src/blobs/codec.js +25 -0
- package/src/blobs/index.js +5 -2
- package/src/blobs/server.js +2 -2
- package/src/database/dispatch.js +803 -204
- package/src/database/encryption.js +25 -21
- package/src/database/index.js +720 -123
- package/src/database/rotation.js +333 -38
- package/src/lib/constants.js +10 -0
- package/src/lib/errors.js +8 -0
- package/src/lib/schema.js +12 -2
- package/src/lib/spec/index.js +10 -5
- package/src/lib/spec/schema.json +13 -1
- package/src/lib/utils.js +24 -3
- package/src/mailbox/inbox.js +368 -41
- package/src/mailbox/index.js +75 -20
- package/src/mailbox/post.js +13 -8
- package/src/network/index.js +12 -5
- package/src/pairing/index.js +343 -57
- package/src/pairing/invite.js +36 -12
- package/src/pairing/response.js +78 -0
- package/src/push/index.js +20 -2
- package/types/blobs/codec.d.ts +13 -0
- package/types/blobs/index.d.ts +2 -0
- package/types/database/dispatch.d.ts +51 -7
- package/types/database/encryption.d.ts +13 -5
- package/types/database/index.d.ts +190 -19
- package/types/database/rotation.d.ts +85 -2
- package/types/lib/constants.d.ts +4 -0
- package/types/lib/errors.d.ts +6 -0
- package/types/lib/schema.d.ts +11 -0
- package/types/lib/utils.d.ts +2 -0
- package/types/mailbox/inbox.d.ts +78 -10
- package/types/mailbox/index.d.ts +42 -16
- package/types/mailbox/post.d.ts +7 -5
- package/types/pairing/index.d.ts +53 -8
- package/types/pairing/invite.d.ts +27 -8
- package/types/pairing/response.d.ts +50 -0
- package/types/push/index.d.ts +12 -2
package/types/mailbox/inbox.d.ts
CHANGED
|
@@ -10,19 +10,32 @@ export declare function keyPair(secret: Uint8Array): {
|
|
|
10
10
|
secretKey: Uint8Array;
|
|
11
11
|
};
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
13
|
+
* A handled row old enough to forget; one whose `handled` is no time is not.
|
|
14
|
+
*
|
|
15
|
+
* @param {import('./index.js').Mail} mail
|
|
16
|
+
* @returns {boolean}
|
|
17
|
+
*/
|
|
18
|
+
export declare function aged({ handled }: import('./index.js').Mail): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Erase the core a message travelled in, once nothing reads it. Corestore leaves a core that
|
|
21
|
+
* still has a session open, and that is an error here, not silence. Nothing is erased once `live`
|
|
22
|
+
* says no, or the store is closing. Resolves true once no such core is stored.
|
|
15
23
|
*
|
|
16
24
|
* @param {import('corestore')} store
|
|
17
25
|
* @param {Uint8Array} key
|
|
18
|
-
* @
|
|
26
|
+
* @param {() => boolean} [live]
|
|
27
|
+
* @returns {Promise<boolean>}
|
|
19
28
|
*/
|
|
20
|
-
export declare function erase(store: import('corestore'), key: Uint8Array): Promise<
|
|
29
|
+
export declare function erase(store: import('corestore'), key: Uint8Array, live?: () => boolean): Promise<boolean>;
|
|
21
30
|
/**
|
|
22
|
-
* Receives at the address a secret owns, direct from the sender or from a mirror. A message
|
|
23
|
-
*
|
|
31
|
+
* Receives at the address a secret owns, direct from the sender or from a mirror. A message is
|
|
32
|
+
* kept in `box` from before its block is read until `onmessage` resolves, as a row naming its
|
|
33
|
+
* core, never the message, and its id stays there for HANDLED_FOR once handled; one that does not
|
|
34
|
+
* open in time, or that `onmessage` resolves `false` on, is dropped.
|
|
24
35
|
* A core the inbox fetched is erased once dropped, or once handled with `keep` false; one this
|
|
25
|
-
* device held already is left alone
|
|
36
|
+
* device held already is left alone, and so is one whose message is found at a start in a row
|
|
37
|
+
* written before its block was read: that row does not say the inbox fetched it, so nothing is
|
|
38
|
+
* erased for it, whatever `keep` says or `onmessage` resolves.
|
|
26
39
|
*/
|
|
27
40
|
export declare class Inbox extends ReadyResource {
|
|
28
41
|
network: import("../index.js").Network;
|
|
@@ -35,8 +48,31 @@ export declare class Inbox extends ReadyResource {
|
|
|
35
48
|
onmessage: (message: Uint8Array) => unknown;
|
|
36
49
|
onerror: (err: Error) => void;
|
|
37
50
|
keep: boolean;
|
|
51
|
+
timeout: number;
|
|
52
|
+
/** @private */
|
|
53
|
+
_mail;
|
|
54
|
+
/** @private */
|
|
55
|
+
_turns;
|
|
56
|
+
/** @private */
|
|
57
|
+
_load;
|
|
58
|
+
/** @private */
|
|
59
|
+
_behind;
|
|
60
|
+
/** @private */
|
|
61
|
+
_reading;
|
|
62
|
+
/** @private */
|
|
63
|
+
_kept;
|
|
64
|
+
/** @private */
|
|
65
|
+
_handled;
|
|
66
|
+
/** @private */
|
|
67
|
+
_erasing;
|
|
68
|
+
/** @private */
|
|
69
|
+
_landing;
|
|
70
|
+
/** @private */
|
|
71
|
+
_waiting;
|
|
72
|
+
/** @private */
|
|
73
|
+
_after;
|
|
38
74
|
/** @private */
|
|
39
|
-
|
|
75
|
+
_siblings;
|
|
40
76
|
/** @private */
|
|
41
77
|
_session;
|
|
42
78
|
/** @private */
|
|
@@ -44,22 +80,54 @@ export declare class Inbox extends ReadyResource {
|
|
|
44
80
|
/**
|
|
45
81
|
* @param {import('../network/index.js').Network} network
|
|
46
82
|
* @param {Uint8Array} secret
|
|
47
|
-
* @param {{ box: import('./index.js').Box, onmessage: (message: Uint8Array) => unknown, onerror: (err: Error) => void, keep?: boolean }} opts
|
|
83
|
+
* @param {{ box: import('./index.js').Box, onmessage: (message: Uint8Array) => unknown, onerror: (err: Error) => void, keep?: boolean, timeout?: number, after?: Promise<void>[], siblings?: () => Inbox[] }} opts `after`: closes to wait for before it opens. `siblings`: the other inboxes on its box at its address, as of the call.
|
|
48
84
|
*/
|
|
49
|
-
constructor(network: import('../network/index.js').Network, secret: Uint8Array, { box, onmessage, onerror, keep }: {
|
|
85
|
+
constructor(network: import('../network/index.js').Network, secret: Uint8Array, { box, onmessage, onerror, keep, timeout, after, siblings }: {
|
|
50
86
|
box: import('./index.js').Box;
|
|
51
87
|
onmessage: (message: Uint8Array) => unknown;
|
|
52
88
|
onerror: (err: Error) => void;
|
|
53
89
|
keep?: boolean;
|
|
90
|
+
timeout?: number;
|
|
91
|
+
after?: Promise<void>[];
|
|
92
|
+
siblings?: () => Inbox[];
|
|
54
93
|
});
|
|
55
94
|
/** @private */
|
|
56
95
|
private _open;
|
|
57
96
|
/** @private */
|
|
58
97
|
private _close;
|
|
98
|
+
/**
|
|
99
|
+
* Take over the reads an inbox that closed at this address left unsettled: each waits for its
|
|
100
|
+
* block as it did there, so one that lands after that close is still handed over.
|
|
101
|
+
*
|
|
102
|
+
* @returns {Promise<void>}
|
|
103
|
+
*/
|
|
104
|
+
inherit(): Promise<void>;
|
|
105
|
+
/** @private */
|
|
106
|
+
private _keep;
|
|
59
107
|
/** @private */
|
|
60
108
|
private _onannounce;
|
|
61
109
|
/** @private */
|
|
110
|
+
private _forget;
|
|
111
|
+
/** @private */
|
|
112
|
+
private _next;
|
|
113
|
+
/** @private */
|
|
114
|
+
private _settle;
|
|
115
|
+
/** @private */
|
|
62
116
|
private _read;
|
|
63
117
|
/** @private */
|
|
118
|
+
private _land;
|
|
119
|
+
/** @private */
|
|
120
|
+
private _resume;
|
|
121
|
+
/** @private */
|
|
122
|
+
private _unseal;
|
|
123
|
+
/** @private */
|
|
124
|
+
private _erase;
|
|
125
|
+
/** @private */
|
|
126
|
+
private _drop;
|
|
127
|
+
/** @private */
|
|
64
128
|
private _handle;
|
|
129
|
+
/** @private */
|
|
130
|
+
private _remember;
|
|
131
|
+
/** @private */
|
|
132
|
+
private _prune;
|
|
65
133
|
}
|
package/types/mailbox/index.d.ts
CHANGED
|
@@ -12,22 +12,37 @@ export type Mail = {
|
|
|
12
12
|
* Where it goes, or where it arrived.
|
|
13
13
|
*/
|
|
14
14
|
address: Uint8Array;
|
|
15
|
+
/**
|
|
16
|
+
* Sent: as `sealed` says. Received: empty, it stays in its core.
|
|
17
|
+
*/
|
|
15
18
|
message: Uint8Array;
|
|
16
19
|
/**
|
|
17
20
|
* Where a sent message waits for an owner who is offline.
|
|
18
21
|
*/
|
|
19
22
|
mirrors?: Uint8Array[];
|
|
20
23
|
/**
|
|
21
|
-
* False erases the sender's copy once
|
|
24
|
+
* False erases the sender's copy once a device or a mirror stored it.
|
|
22
25
|
*/
|
|
23
26
|
keep?: boolean;
|
|
24
27
|
/**
|
|
25
|
-
* The inbox fetched the core it arrived in, so it may erase it.
|
|
28
|
+
* The inbox fetched the core it arrived in, so it may erase it; on a handled row, it still has to.
|
|
26
29
|
*/
|
|
27
30
|
fetched?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* When it was handled: the id is remembered for a while.
|
|
33
|
+
*/
|
|
34
|
+
handled?: number;
|
|
35
|
+
/**
|
|
36
|
+
* Sent: `message` is sealed to the address, not in the clear.
|
|
37
|
+
*/
|
|
38
|
+
sealed?: boolean;
|
|
28
39
|
};
|
|
29
40
|
export type Box = {
|
|
30
41
|
list: () => Promise<Mail[]>;
|
|
42
|
+
/**
|
|
43
|
+
* The one row under an id, null when there is none.
|
|
44
|
+
*/
|
|
45
|
+
get: (id: string) => Promise<Mail | null>;
|
|
31
46
|
put: (mail: Mail) => Promise<unknown>;
|
|
32
47
|
del: (id: string) => Promise<unknown>;
|
|
33
48
|
};
|
|
@@ -37,7 +52,7 @@ export type MailboxOpts = {
|
|
|
37
52
|
*/
|
|
38
53
|
inbox?: Box;
|
|
39
54
|
/**
|
|
40
|
-
* Keeps a sent message until
|
|
55
|
+
* Keeps a sent message until a device or a mirror stored it.
|
|
41
56
|
*/
|
|
42
57
|
outbox?: Box;
|
|
43
58
|
/**
|
|
@@ -50,27 +65,30 @@ export type MailboxOpts = {
|
|
|
50
65
|
* @property {string} id Unique per message, hex.
|
|
51
66
|
* @property {string} [name] The core it travels in, so a restart sends it on the same core.
|
|
52
67
|
* @property {Uint8Array} address Where it goes, or where it arrived.
|
|
53
|
-
* @property {Uint8Array} message
|
|
68
|
+
* @property {Uint8Array} message Sent: as `sealed` says. Received: empty, it stays in its core.
|
|
54
69
|
* @property {Uint8Array[]} [mirrors] Where a sent message waits for an owner who is offline.
|
|
55
|
-
* @property {boolean} [keep] False erases the sender's copy once
|
|
56
|
-
* @property {boolean} [fetched] The inbox fetched the core it arrived in, so it may erase it.
|
|
70
|
+
* @property {boolean} [keep] False erases the sender's copy once a device or a mirror stored it.
|
|
71
|
+
* @property {boolean} [fetched] The inbox fetched the core it arrived in, so it may erase it; on a handled row, it still has to.
|
|
72
|
+
* @property {number} [handled] When it was handled: the id is remembered for a while.
|
|
73
|
+
* @property {boolean} [sealed] Sent: `message` is sealed to the address, not in the clear.
|
|
57
74
|
*
|
|
58
75
|
* @typedef {object} Box Where mail is kept; memory unless given a persistent one.
|
|
59
76
|
* @property {() => Promise<Mail[]>} list
|
|
77
|
+
* @property {(id: string) => Promise<Mail | null>} get The one row under an id, null when there is none.
|
|
60
78
|
* @property {(mail: Mail) => Promise<unknown>} put
|
|
61
79
|
* @property {(id: string) => Promise<unknown>} del
|
|
62
80
|
*
|
|
63
81
|
* @typedef {object} MailboxOpts
|
|
64
82
|
* @property {Box} [inbox] Keeps a received message until it was handled.
|
|
65
|
-
* @property {Box} [outbox] Keeps a sent message until
|
|
83
|
+
* @property {Box} [outbox] Keeps a sent message until a device or a mirror stored it.
|
|
66
84
|
* @property {(err: Error) => void} [onerror] Called when a message fails to be handled or sent.
|
|
67
85
|
*/
|
|
68
86
|
/**
|
|
69
87
|
* A device's mailbox. It receives at the addresses it holds the secret of, and sends to any
|
|
70
|
-
* address. Both ends keep their mail until it is done with: the outbox until
|
|
71
|
-
* the inbox until it was handled. Give it persistent boxes and that survives a
|
|
72
|
-
* sends again what was not
|
|
73
|
-
* arrive twice, never not at all.
|
|
88
|
+
* address. Both ends keep their mail until it is done with: the outbox until a device or a
|
|
89
|
+
* mirror stored it, the inbox until it was handled. Give it persistent boxes and that survives a
|
|
90
|
+
* restart: it sends again what was not stored and hands over again what was not handled, so a
|
|
91
|
+
* message may arrive twice, never not at all.
|
|
74
92
|
*/
|
|
75
93
|
export declare class Mailbox extends ReadyResource {
|
|
76
94
|
network: import("../index.js").Network;
|
|
@@ -109,25 +127,29 @@ export declare class Mailbox extends ReadyResource {
|
|
|
109
127
|
/**
|
|
110
128
|
* Receive the messages sent to the address `secret` owns, until the returned inbox closes.
|
|
111
129
|
* A message stays in the inbox until `onmessage` resolves; one it did not finish is handed
|
|
112
|
-
* over again the next time this address is received.
|
|
130
|
+
* over again the next time this address is received. One it resolves `false` on was not for
|
|
131
|
+
* this address: it is erased as one that does not open. A message that was being read when the
|
|
132
|
+
* app was killed or its inbox closed is handed over at the next start and stays on the device,
|
|
133
|
+
* whatever `keep` says or `onmessage` resolves.
|
|
113
134
|
*
|
|
114
135
|
* @param {Uint8Array} secret
|
|
115
136
|
* @param {(message: Uint8Array) => unknown} onmessage
|
|
116
|
-
* @param {{ keep?: boolean }} [opts]
|
|
137
|
+
* @param {{ keep?: boolean, timeout?: number }} [opts] `keep`: false erases each message from this device once handled. `timeout`: ms a message has to arrive once announced, and again to be handled, 30 s by default.
|
|
117
138
|
* @returns {{ close: () => Promise<void> }}
|
|
118
139
|
*/
|
|
119
|
-
receive(secret: Uint8Array, onmessage: (message: Uint8Array) => unknown, { keep }?: {
|
|
140
|
+
receive(secret: Uint8Array, onmessage: (message: Uint8Array) => unknown, { keep, timeout }?: {
|
|
120
141
|
keep?: boolean;
|
|
142
|
+
timeout?: number;
|
|
121
143
|
}): {
|
|
122
144
|
close: () => Promise<void>;
|
|
123
145
|
};
|
|
124
146
|
/**
|
|
125
147
|
* Send a message to an address. Resolves once the outbox keeps it; it is delivered in the
|
|
126
|
-
* background, and dropped from the outbox once
|
|
148
|
+
* background, and dropped from the outbox once the owner or a mirror stored it.
|
|
127
149
|
*
|
|
128
150
|
* @param {Uint8Array} address
|
|
129
151
|
* @param {Uint8Array} message
|
|
130
|
-
* @param {{ mirrors?: Uint8Array[], keep?: boolean }} [opts] `mirrors`: where it waits for an owner who is offline, the network's by default. `keep`: false erases it from this device once
|
|
152
|
+
* @param {{ mirrors?: Uint8Array[], keep?: boolean }} [opts] `mirrors`: where it waits for an owner who is offline, the network's by default. `keep`: false erases it from this device once a device or a mirror stored it.
|
|
131
153
|
* @returns {Promise<void>}
|
|
132
154
|
*/
|
|
133
155
|
send(address: Uint8Array, message: Uint8Array, { mirrors, keep }?: {
|
|
@@ -137,5 +159,9 @@ export declare class Mailbox extends ReadyResource {
|
|
|
137
159
|
/** @private */
|
|
138
160
|
private _deliver;
|
|
139
161
|
/** @private */
|
|
162
|
+
private _erase;
|
|
163
|
+
/** @private */
|
|
164
|
+
private _owed;
|
|
165
|
+
/** @private */
|
|
140
166
|
private _track;
|
|
141
167
|
}
|
package/types/mailbox/post.d.ts
CHANGED
|
@@ -2,14 +2,15 @@ import ReadyResource from 'ready-resource';
|
|
|
2
2
|
/**
|
|
3
3
|
* One sealed message on its way to an address: written to a fresh core, announced to peers
|
|
4
4
|
* receiving at the address, and deposited on `mirrors` for an owner who is offline.
|
|
5
|
-
* `delivered` resolves
|
|
5
|
+
* `delivered` resolves once it is stored, by the owner or by a mirror holding it for them.
|
|
6
6
|
* Given a `core` instead, it announces that core as it is; given a `name`, the core is the
|
|
7
|
-
* store's core of that name, and a message it already holds is not written twice.
|
|
7
|
+
* store's core of that name, and a message it already holds is not written twice. `sealed` says
|
|
8
|
+
* the message is sealed to the address already.
|
|
8
9
|
*/
|
|
9
10
|
export declare class Post extends ReadyResource {
|
|
10
11
|
network: import("../index.js").Network;
|
|
11
12
|
address: Uint8Array<ArrayBufferLike>;
|
|
12
|
-
message:
|
|
13
|
+
message: any;
|
|
13
14
|
mirrors: Uint8Array<ArrayBufferLike>[];
|
|
14
15
|
name: string;
|
|
15
16
|
/** @type {Promise<void>} */
|
|
@@ -26,12 +27,13 @@ export declare class Post extends ReadyResource {
|
|
|
26
27
|
* @param {import('../network/index.js').Network} network
|
|
27
28
|
* @param {Uint8Array} address
|
|
28
29
|
* @param {Uint8Array | null} message
|
|
29
|
-
* @param {{ mirrors?: Uint8Array[], core?: import('hypercore'), name?: string }} [opts]
|
|
30
|
+
* @param {{ mirrors?: Uint8Array[], core?: import('hypercore'), name?: string, sealed?: boolean }} [opts]
|
|
30
31
|
*/
|
|
31
|
-
constructor(network: import('../network/index.js').Network, address: Uint8Array, message: Uint8Array | null, { mirrors, core, name }?: {
|
|
32
|
+
constructor(network: import('../network/index.js').Network, address: Uint8Array, message: Uint8Array | null, { mirrors, core, name, sealed }?: {
|
|
32
33
|
mirrors?: Uint8Array[];
|
|
33
34
|
core?: import('hypercore');
|
|
34
35
|
name?: string;
|
|
36
|
+
sealed?: boolean;
|
|
35
37
|
});
|
|
36
38
|
/** @private */
|
|
37
39
|
private _open;
|
package/types/pairing/index.d.ts
CHANGED
|
@@ -62,6 +62,8 @@ export type JoinOpts = {
|
|
|
62
62
|
meta?: {
|
|
63
63
|
ns?: string;
|
|
64
64
|
version?: number;
|
|
65
|
+
start?: number;
|
|
66
|
+
encoding?: Record<string, number>;
|
|
65
67
|
};
|
|
66
68
|
};
|
|
67
69
|
/**
|
|
@@ -118,7 +120,7 @@ export type JoinResult = {
|
|
|
118
120
|
*
|
|
119
121
|
* @typedef {object} JoinOpts
|
|
120
122
|
* @property {import('../identity/index.js').Identity} identity Who joins: the member they become, and who signs the join.
|
|
121
|
-
* @property {{ dispatch: { encode: Function }, meta?: { ns?: string, version?: number } }} spec The database's spec: the join is one of its ops.
|
|
123
|
+
* @property {{ dispatch: { encode: Function }, meta?: { ns?: string, version?: number, start?: number, encoding?: Record<string, number> } }} spec The database's spec: the join is one of its ops.
|
|
122
124
|
* @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.
|
|
123
125
|
* @property {number} [timeout] Deadline for the reply, in ms; `0` waits until the invite expires, or for good. Defaults to 30000.
|
|
124
126
|
* @property {AbortSignal} [signal] Stops the join, rejecting it with `CLOSED`, as closing the mailbox does.
|
|
@@ -135,10 +137,17 @@ export type JoinResult = {
|
|
|
135
137
|
* Invites into a database. An invite is a record in the database; a joiner writes one signed
|
|
136
138
|
* `join` op into its own writer core and announces it to the database's peers, and apply admits
|
|
137
139
|
* it. The admission stays in the database until the joiner has its keys: every device of a member
|
|
138
|
-
* that may invite offers them while online, and the first one read settles it for all.
|
|
140
|
+
* that may invite offers them while online, and the first one read settles it for all. Under an
|
|
141
|
+
* invite with an address of its own, being let in is a promise: no member and no seat until a device
|
|
142
|
+
* of the joiner, holding the keys, claims its seat. Its keys are offered until a member that may
|
|
143
|
+
* invite sees that device seated and settles the promise, or until the invite expires, whoever
|
|
144
|
+
* reads them. A join
|
|
139
145
|
* turned away with an invite the database knows, spent, revoked or older than the joiner's
|
|
140
146
|
* removal, is answered the same way with `DENIED` and the reason. A `confirm` invite's joins wait
|
|
141
147
|
* as rows of `requests` until a member accepts or denies one by its id.
|
|
148
|
+
* Where the database's version keeps an invite's secret on its record, the invite has an address
|
|
149
|
+
* of its own: its joins are sealed to it, and its answers follow the tag only that secret and the
|
|
150
|
+
* joiner's reply address make. Elsewhere an invite carries the database's address.
|
|
142
151
|
* `Pairing.join` is the other side: write the join, wait for the reply.
|
|
143
152
|
*/
|
|
144
153
|
export declare class Pairing extends ReadyResource {
|
|
@@ -151,9 +160,15 @@ export declare class Pairing extends ReadyResource {
|
|
|
151
160
|
/** @private */
|
|
152
161
|
_denials;
|
|
153
162
|
/** @private */
|
|
163
|
+
_keys;
|
|
164
|
+
/** @private */
|
|
165
|
+
_inbox;
|
|
166
|
+
/** @private */
|
|
154
167
|
_expiry;
|
|
155
168
|
/** @private */
|
|
156
169
|
_onupdate;
|
|
170
|
+
/** @private */
|
|
171
|
+
_onepoch;
|
|
157
172
|
/** @param {PairingOpts} [opts] */
|
|
158
173
|
constructor({ mailbox, db }?: PairingOpts);
|
|
159
174
|
/** @private */
|
|
@@ -166,11 +181,13 @@ export declare class Pairing extends ReadyResource {
|
|
|
166
181
|
* @param {InviteOpts} [opts]
|
|
167
182
|
* @returns {Promise<string>}
|
|
168
183
|
*/
|
|
169
|
-
invite(
|
|
184
|
+
invite(opts?: InviteOpts): Promise<string>;
|
|
185
|
+
/** @private */
|
|
186
|
+
private _secret;
|
|
170
187
|
/**
|
|
171
188
|
* Revoke an invite, for every member. Needs the remove permission.
|
|
172
189
|
*
|
|
173
|
-
* @param {string} invite
|
|
190
|
+
* @param {string} invite The code, or the id its `invites` row holds.
|
|
174
191
|
* @returns {Promise<boolean>} Whether it was live.
|
|
175
192
|
*/
|
|
176
193
|
revoke(invite: string): Promise<boolean>;
|
|
@@ -185,6 +202,8 @@ export declare class Pairing extends ReadyResource {
|
|
|
185
202
|
accept(id: string, { role, proof }?: AcceptOpts): Promise<void>;
|
|
186
203
|
/**
|
|
187
204
|
* Refuse a join waiting on a `confirm` invite, by its id in `requests`, with an optional reason.
|
|
205
|
+
* On a join already let in by a promise, it withdraws the promise: that needs the remove
|
|
206
|
+
* permission.
|
|
188
207
|
*
|
|
189
208
|
* @param {string} id
|
|
190
209
|
* @param {string} [reason]
|
|
@@ -196,10 +215,20 @@ export declare class Pairing extends ReadyResource {
|
|
|
196
215
|
/** @private */
|
|
197
216
|
private _sync;
|
|
198
217
|
/** @private */
|
|
218
|
+
private _done;
|
|
219
|
+
/** @private */
|
|
199
220
|
private _arm;
|
|
200
221
|
/** @private */
|
|
201
222
|
private _answer;
|
|
202
223
|
/** @private */
|
|
224
|
+
private _deliver;
|
|
225
|
+
/** @private */
|
|
226
|
+
private _seat;
|
|
227
|
+
/** @private */
|
|
228
|
+
private _seats;
|
|
229
|
+
/** @private */
|
|
230
|
+
private _onkeys;
|
|
231
|
+
/** @private */
|
|
203
232
|
private _offer;
|
|
204
233
|
/** @private */
|
|
205
234
|
private _post;
|
|
@@ -219,18 +248,34 @@ export declare class Pairing extends ReadyResource {
|
|
|
219
248
|
* @returns {Promise<JoinResult>}
|
|
220
249
|
*/
|
|
221
250
|
static join(mailbox: Mailbox, invite: string, { identity, spec, writer, timeout, signal, keep }?: JoinOpts): Promise<JoinResult>;
|
|
251
|
+
/**
|
|
252
|
+
* Take back a join that waits for a member: the writer's own core says so after its join, and
|
|
253
|
+
* the database drops the request unless a member let it in first. Announced as the join was.
|
|
254
|
+
* Called again with the same writer, it announces the cancel already written.
|
|
255
|
+
*
|
|
256
|
+
* @param {Mailbox} mailbox
|
|
257
|
+
* @param {string} invite
|
|
258
|
+
* @param {{ spec: JoinOpts['spec'], writer: KeyPair }} opts The writer that joined.
|
|
259
|
+
* @returns {Promise<void>} Resolves once a peer or a mirror holds it, rejects `CLOSED` when the mailbox closes first.
|
|
260
|
+
*/
|
|
261
|
+
static cancel(mailbox: Mailbox, invite: string, { spec, writer }: {
|
|
262
|
+
spec: JoinOpts['spec'];
|
|
263
|
+
writer: KeyPair;
|
|
264
|
+
}): Promise<void>;
|
|
222
265
|
}
|
|
223
266
|
/**
|
|
224
|
-
* A join's payload: sealed to the
|
|
225
|
-
*
|
|
226
|
-
* for this writer and reply
|
|
267
|
+
* A join's payload: sealed to the invite's address, so only those who hold its row read who joins,
|
|
268
|
+
* every member for an invite that carries the database's address; proven by the invite over the
|
|
269
|
+
* writer; signed by the joiner's device, under its chain to the identity, for this writer and reply
|
|
270
|
+
* address. An invite with an address of its own is named in the clear, so apply finds its secret.
|
|
227
271
|
*
|
|
228
272
|
* @param {Invite} invite
|
|
229
273
|
* @param {import('../identity/index.js').Identity} identity
|
|
230
274
|
* @param {Uint8Array} writer
|
|
231
275
|
* @param {Uint8Array} reply
|
|
232
|
-
* @returns {{ box: Uint8Array }}
|
|
276
|
+
* @returns {{ box: Uint8Array, invite?: Uint8Array }}
|
|
233
277
|
*/
|
|
234
278
|
export declare function sealJoin(invite: Invite, identity: import('../identity/index.js').Identity, writer: Uint8Array, reply: Uint8Array): {
|
|
235
279
|
box: Uint8Array;
|
|
280
|
+
invite?: Uint8Array;
|
|
236
281
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export declare const STAMPED = 2;
|
|
1
2
|
export type InviteFields = {
|
|
2
3
|
/**
|
|
3
4
|
* Absolute expiry timestamp; `0` means never.
|
|
@@ -8,7 +9,7 @@ export type InviteFields = {
|
|
|
8
9
|
*/
|
|
9
10
|
key: Uint8Array;
|
|
10
11
|
/**
|
|
11
|
-
*
|
|
12
|
+
* Where a join is sealed to: the invite's own address, or the database's.
|
|
12
13
|
*/
|
|
13
14
|
address: Uint8Array;
|
|
14
15
|
/**
|
|
@@ -26,20 +27,35 @@ export type InviteFields = {
|
|
|
26
27
|
* The app's payload, readable before joining. Unsigned: a hint, not proof.
|
|
27
28
|
*/
|
|
28
29
|
data?: Uint8Array | null;
|
|
30
|
+
/**
|
|
31
|
+
* The stamp its record was written with, which its joins take; `0` for none.
|
|
32
|
+
*/
|
|
33
|
+
stamp?: number;
|
|
34
|
+
/**
|
|
35
|
+
* The invite's form: `STAMPED` once the stamp is past its database's start, or with an address of its own.
|
|
36
|
+
*/
|
|
37
|
+
version?: number;
|
|
38
|
+
/**
|
|
39
|
+
* Whether the address is the invite's own: its join names it and its answers are tagged.
|
|
40
|
+
*/
|
|
41
|
+
own?: boolean;
|
|
29
42
|
};
|
|
30
43
|
/**
|
|
31
44
|
* @typedef {object} InviteFields
|
|
32
45
|
* @property {number} expires Absolute expiry timestamp; `0` means never.
|
|
33
46
|
* @property {Uint8Array} key Key of the database the invite opens.
|
|
34
|
-
* @property {Uint8Array} address
|
|
47
|
+
* @property {Uint8Array} address Where a join is sealed to: the invite's own address, or the database's.
|
|
35
48
|
* @property {Uint8Array} seed The invite's secret; its keypair proves a join.
|
|
36
49
|
* @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
50
|
* @property {Uint8Array | null} [data] The app's payload, readable before joining. Unsigned: a hint, not proof.
|
|
51
|
+
* @property {number} [stamp] The stamp its record was written with, which its joins take; `0` for none.
|
|
52
|
+
* @property {number} [version] The invite's form: `STAMPED` once the stamp is past its database's start, or with an address of its own.
|
|
53
|
+
* @property {boolean} [own] Whether the address is the invite's own: its join names it and its answers are tagged.
|
|
38
54
|
*/
|
|
39
55
|
/**
|
|
40
|
-
* An invite: the database it opens, the address a join is sealed to,
|
|
41
|
-
* proves the joiner holds the invite. Role and expiry come from the
|
|
42
|
-
* `expires` is here so a joiner fails fast.
|
|
56
|
+
* An invite: the database it opens, the address a join is sealed to, its own or the database's,
|
|
57
|
+
* and a seed whose keypair proves the joiner holds the invite. Role and expiry come from the
|
|
58
|
+
* database's own record; `expires` is here so a joiner fails fast.
|
|
43
59
|
*/
|
|
44
60
|
export declare class Invite {
|
|
45
61
|
version: number;
|
|
@@ -52,12 +68,14 @@ export declare class Invite {
|
|
|
52
68
|
length: number;
|
|
53
69
|
};
|
|
54
70
|
data: Uint8Array<ArrayBufferLike>;
|
|
71
|
+
stamp: number;
|
|
72
|
+
own: boolean;
|
|
55
73
|
/** @private */
|
|
56
74
|
_str;
|
|
57
75
|
/** @private */
|
|
58
76
|
_keyPair;
|
|
59
77
|
/** @param {InviteFields & { _str?: string }} fields */
|
|
60
|
-
constructor({ expires, key, address, seed, link, data, _str }: InviteFields & {
|
|
78
|
+
constructor({ version, expires, key, address, seed, link, data, stamp, own, _str }: InviteFields & {
|
|
61
79
|
_str?: string;
|
|
62
80
|
});
|
|
63
81
|
/** @returns {boolean} Whether the invite is past its expiry (never when `expires === 0`). */
|
|
@@ -90,10 +108,10 @@ export declare class Invite {
|
|
|
90
108
|
/**
|
|
91
109
|
* A new invite with a fresh seed.
|
|
92
110
|
*
|
|
93
|
-
* @param {{ ttl?: number | string, key: Uint8Array, address: Uint8Array, link?: { key: Uint8Array, length: number } | null, data?: Uint8Array | null }} opts
|
|
111
|
+
* @param {{ ttl?: number | string, key: Uint8Array, address: Uint8Array, link?: { key: Uint8Array, length: number } | null, data?: Uint8Array | null, own?: boolean }} opts
|
|
94
112
|
* @returns {Invite}
|
|
95
113
|
*/
|
|
96
|
-
static create({ ttl, key, address, link, data }: {
|
|
114
|
+
static create({ ttl, key, address, link, data, own }: {
|
|
97
115
|
ttl?: number | string;
|
|
98
116
|
key: Uint8Array;
|
|
99
117
|
address: Uint8Array;
|
|
@@ -102,6 +120,7 @@ export declare class Invite {
|
|
|
102
120
|
length: number;
|
|
103
121
|
} | null;
|
|
104
122
|
data?: Uint8Array | null;
|
|
123
|
+
own?: boolean;
|
|
105
124
|
}): Invite;
|
|
106
125
|
/**
|
|
107
126
|
* Parse an invite string.
|
|
@@ -12,3 +12,53 @@ export declare const Response: import('compact-encoding').Encoder<{
|
|
|
12
12
|
entropy: Uint8Array;
|
|
13
13
|
}> | null;
|
|
14
14
|
}>;
|
|
15
|
+
/**
|
|
16
|
+
* The tag of an encoded answer, keyed by what the invite's address and the joiner's reply address
|
|
17
|
+
* share: each end makes it from its own secret key and the other's address, and nobody else can.
|
|
18
|
+
*
|
|
19
|
+
* @param {Uint8Array} answer The answer as it is sent.
|
|
20
|
+
* @param {Uint8Array} secretKey This end's secret key.
|
|
21
|
+
* @param {Uint8Array} publicKey The other end's address.
|
|
22
|
+
* @returns {Uint8Array | null} Null for an address that shares nothing.
|
|
23
|
+
*/
|
|
24
|
+
export declare function tag(answer: Uint8Array, secretKey: Uint8Array, publicKey: Uint8Array): Uint8Array | null;
|
|
25
|
+
/**
|
|
26
|
+
* The answer in a message that starts with its tag: the bytes after it, null when the tag is not
|
|
27
|
+
* the one its two ends make over them.
|
|
28
|
+
*
|
|
29
|
+
* @param {Uint8Array} message
|
|
30
|
+
* @param {Uint8Array} secretKey
|
|
31
|
+
* @param {Uint8Array} publicKey
|
|
32
|
+
* @returns {Uint8Array | null}
|
|
33
|
+
*/
|
|
34
|
+
export declare function proven(message: Uint8Array, secretKey: Uint8Array, publicKey: Uint8Array): Uint8Array | null;
|
|
35
|
+
/**
|
|
36
|
+
* Keys sent to a device that asked, as they are sent: the sender's writer key, then its device's
|
|
37
|
+
* signature over the room, the writer they go to and the answer, then the answer.
|
|
38
|
+
*
|
|
39
|
+
* @param {Uint8Array} answer
|
|
40
|
+
* @param {{ room: Uint8Array, to: Uint8Array, writer: Uint8Array, secretKey: Uint8Array }} opts
|
|
41
|
+
* @returns {Uint8Array}
|
|
42
|
+
*/
|
|
43
|
+
export declare function signed(answer: Uint8Array, { room, to, writer, secretKey }: {
|
|
44
|
+
room: Uint8Array;
|
|
45
|
+
to: Uint8Array;
|
|
46
|
+
writer: Uint8Array;
|
|
47
|
+
secretKey: Uint8Array;
|
|
48
|
+
}): Uint8Array;
|
|
49
|
+
/**
|
|
50
|
+
* The sender and the answer of signed keys, null unless the device key `keyOf` gives for the
|
|
51
|
+
* sender's writer signed them for this room and this writer.
|
|
52
|
+
*
|
|
53
|
+
* @param {Uint8Array} message
|
|
54
|
+
* @param {{ room: Uint8Array, to: Uint8Array }} opts
|
|
55
|
+
* @param {(writer: Uint8Array) => Uint8Array | null | undefined} keyOf
|
|
56
|
+
* @returns {{ writer: Uint8Array, answer: Uint8Array } | null}
|
|
57
|
+
*/
|
|
58
|
+
export declare function signer(message: Uint8Array, { room, to }: {
|
|
59
|
+
room: Uint8Array;
|
|
60
|
+
to: Uint8Array;
|
|
61
|
+
}, keyOf: (writer: Uint8Array) => Uint8Array | null | undefined): {
|
|
62
|
+
writer: Uint8Array;
|
|
63
|
+
answer: Uint8Array;
|
|
64
|
+
} | null;
|
package/types/push/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export type Handle = {
|
|
2
2
|
id: string;
|
|
3
3
|
key: Uint8Array;
|
|
4
|
+
writers?: Uint8Array[];
|
|
4
5
|
};
|
|
5
6
|
export type Block = {
|
|
6
7
|
index: number;
|
|
@@ -14,13 +15,22 @@ export type Hit = Handle & {
|
|
|
14
15
|
block: Block | null;
|
|
15
16
|
};
|
|
16
17
|
/**
|
|
17
|
-
* @typedef {{ id: string, key: Uint8Array }} Handle A handle this device holds: its id
|
|
18
|
+
* @typedef {{ id: string, key: Uint8Array, writers?: Uint8Array[] }} Handle A handle this device holds: its id, its database key and the writer keys that may write to it now, none when not given.
|
|
18
19
|
* @typedef {{ index: number, value: Uint8Array, writer: Uint8Array }} Block The block a push carries when it fits: its index, its bytes as the writer's core holds them, and the writer's key.
|
|
19
20
|
* @typedef {Handle & { length: number, newer: boolean, ref: string | null, block: Block | null }} Hit The handle a push is about, the length it proves, whether this device is behind it, the ref the write was on, and the block when it rode along.
|
|
20
21
|
*/
|
|
22
|
+
/**
|
|
23
|
+
* The topic a push names: its handle's discovery key in hex, the string a device subscribes to.
|
|
24
|
+
* Null when the payload does not decode.
|
|
25
|
+
*
|
|
26
|
+
* @param {Uint8Array} payload
|
|
27
|
+
* @returns {string | null}
|
|
28
|
+
*/
|
|
29
|
+
export declare function topic(payload: Uint8Array): string | null;
|
|
21
30
|
/**
|
|
22
31
|
* Verify a push payload against this device's storage: the one the gateway sent, decoded from the
|
|
23
|
-
* platform's message. Null when it is about no handle given, is forged,
|
|
32
|
+
* platform's message. Null when it is about no handle given, is forged, comes from a core that is
|
|
33
|
+
* not among the handle's writers, or does not decode.
|
|
24
34
|
*
|
|
25
35
|
* @param {import('hypercore-storage')} storage The corestore's storage; may be opened read-only.
|
|
26
36
|
* @param {Uint8Array} payload
|