@cero-base/core 2.9.0 → 2.10.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/package.json +1 -1
- package/src/mailbox/index.js +11 -0
- package/src/network/index.js +7 -3
- package/types/mailbox/index.d.ts +11 -0
- package/types/network/index.d.ts +4 -4
package/package.json
CHANGED
package/src/mailbox/index.js
CHANGED
|
@@ -64,6 +64,17 @@ export class Mailbox extends ReadyResource {
|
|
|
64
64
|
return keyPair(secret).publicKey
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
/**
|
|
68
|
+
* The key pair behind the address: seal to `publicKey` with `crypto.encrypt`, open with
|
|
69
|
+
* `crypto.decrypt(sealed, pair)`.
|
|
70
|
+
*
|
|
71
|
+
* @param {Uint8Array} secret
|
|
72
|
+
* @returns {{ publicKey: Uint8Array, secretKey: Uint8Array }}
|
|
73
|
+
*/
|
|
74
|
+
static keyPair(secret) {
|
|
75
|
+
return keyPair(secret)
|
|
76
|
+
}
|
|
77
|
+
|
|
67
78
|
/** @private */
|
|
68
79
|
async _open() {
|
|
69
80
|
await this.network.ready()
|
package/src/network/index.js
CHANGED
|
@@ -19,6 +19,10 @@ import { Presence } from './presence.js'
|
|
|
19
19
|
const SILENT_TIMEOUT = 3000
|
|
20
20
|
const RELOOKUPS = [5000, 20000, 60000]
|
|
21
21
|
|
|
22
|
+
function toKey(k) {
|
|
23
|
+
return typeof k === 'string' ? decodeKey(k) : k
|
|
24
|
+
}
|
|
25
|
+
|
|
22
26
|
/** @type {(topic: Uint8Array, channel: string | null) => Uint8Array} */
|
|
23
27
|
export function channelTopic(topic, channel) {
|
|
24
28
|
return channel ? hash([topic, b4a.from(channel)]) : topic
|
|
@@ -28,7 +32,7 @@ export function channelTopic(topic, channel) {
|
|
|
28
32
|
* @typedef {object} NetworkOpts
|
|
29
33
|
* @property {Array<{ host: string, port: number }>} [bootstrap] Custom DHT bootstrap nodes.
|
|
30
34
|
* @property {(remotePublicKey: Uint8Array, payload: unknown) => boolean} [firewall] Incoming-connection filter.
|
|
31
|
-
* @property {Uint8Array
|
|
35
|
+
* @property {Array<string | Uint8Array>} [relayThrough] Blind relay public keys; a connection goes through one only when a direct one fails or this device sits behind a randomizing NAT.
|
|
32
36
|
* @property {number[]} [backoffs] Reconnect backoff tiers in ms; the default escalates to ~10min, far too slow for local nets.
|
|
33
37
|
* @property {string} [channel] Optional network-isolation label; only same-channel peers meet.
|
|
34
38
|
* @property {import('corestore')} store Corestore; every connection replicates it, so every core it holds rides every peer.
|
|
@@ -58,13 +62,13 @@ export class Network extends ReadyResource {
|
|
|
58
62
|
if (!store) throw CeroError.REQUIRED('store')
|
|
59
63
|
this.bootstrap = bootstrap || null
|
|
60
64
|
this.firewall = firewall || null
|
|
61
|
-
this.relayThrough = relayThrough || null
|
|
65
|
+
this.relayThrough = relayThrough?.map(toKey) || null
|
|
62
66
|
this.backoffs = backoffs || null
|
|
63
67
|
this.channel = channel || null
|
|
64
68
|
/** @type {import('corestore')} */
|
|
65
69
|
this.store = store
|
|
66
70
|
/** @type {Uint8Array[]} */
|
|
67
|
-
this.mirrors = (mirrors || []).map(
|
|
71
|
+
this.mirrors = (mirrors || []).map(toKey)
|
|
68
72
|
|
|
69
73
|
/** @private */
|
|
70
74
|
this._swarm = null
|
package/types/mailbox/index.d.ts
CHANGED
|
@@ -91,6 +91,17 @@ export declare class Mailbox extends ReadyResource {
|
|
|
91
91
|
* @returns {Uint8Array}
|
|
92
92
|
*/
|
|
93
93
|
static getAddress(secret: Uint8Array): Uint8Array;
|
|
94
|
+
/**
|
|
95
|
+
* The key pair behind the address: seal to `publicKey` with `crypto.encrypt`, open with
|
|
96
|
+
* `crypto.decrypt(sealed, pair)`.
|
|
97
|
+
*
|
|
98
|
+
* @param {Uint8Array} secret
|
|
99
|
+
* @returns {{ publicKey: Uint8Array, secretKey: Uint8Array }}
|
|
100
|
+
*/
|
|
101
|
+
static keyPair(secret: Uint8Array): {
|
|
102
|
+
publicKey: Uint8Array;
|
|
103
|
+
secretKey: Uint8Array;
|
|
104
|
+
};
|
|
94
105
|
/** @private */
|
|
95
106
|
private _open;
|
|
96
107
|
/** @private */
|
package/types/network/index.d.ts
CHANGED
|
@@ -16,9 +16,9 @@ export type NetworkOpts = {
|
|
|
16
16
|
*/
|
|
17
17
|
firewall?: (remotePublicKey: Uint8Array, payload: unknown) => boolean;
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
19
|
+
* Blind relay public keys; a connection goes through one only when a direct one fails or this device sits behind a randomizing NAT.
|
|
20
20
|
*/
|
|
21
|
-
relayThrough?: Uint8Array
|
|
21
|
+
relayThrough?: Array<string | Uint8Array>;
|
|
22
22
|
/**
|
|
23
23
|
* Reconnect backoff tiers in ms; the default escalates to ~10min, far too slow for local nets.
|
|
24
24
|
*/
|
|
@@ -52,7 +52,7 @@ export type NetworkOpts = {
|
|
|
52
52
|
* @typedef {object} NetworkOpts
|
|
53
53
|
* @property {Array<{ host: string, port: number }>} [bootstrap] Custom DHT bootstrap nodes.
|
|
54
54
|
* @property {(remotePublicKey: Uint8Array, payload: unknown) => boolean} [firewall] Incoming-connection filter.
|
|
55
|
-
* @property {Uint8Array
|
|
55
|
+
* @property {Array<string | Uint8Array>} [relayThrough] Blind relay public keys; a connection goes through one only when a direct one fails or this device sits behind a randomizing NAT.
|
|
56
56
|
* @property {number[]} [backoffs] Reconnect backoff tiers in ms; the default escalates to ~10min, far too slow for local nets.
|
|
57
57
|
* @property {string} [channel] Optional network-isolation label; only same-channel peers meet.
|
|
58
58
|
* @property {import('corestore')} store Corestore; every connection replicates it, so every core it holds rides every peer.
|
|
@@ -70,7 +70,7 @@ export declare class Network extends ReadyResource {
|
|
|
70
70
|
port: number;
|
|
71
71
|
}[];
|
|
72
72
|
firewall: (remotePublicKey: Uint8Array, payload: unknown) => boolean;
|
|
73
|
-
relayThrough:
|
|
73
|
+
relayThrough: any[];
|
|
74
74
|
backoffs: number[];
|
|
75
75
|
channel: string;
|
|
76
76
|
/** @type {import('corestore')} */
|