@cero-base/cero 1.14.0 → 1.14.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 +6 -6
- package/src/handle/index.js +1 -1
- package/src/index.js +10 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cero-base/cero",
|
|
3
|
-
"version": "1.14.
|
|
3
|
+
"version": "1.14.1",
|
|
4
4
|
"description": "The ideal p2p API — everything is a handle, handles contain refs, refs contain rows.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -95,15 +95,15 @@
|
|
|
95
95
|
"test:node": "ls test/*.test.js | xargs -P1 -n1 brittle-node"
|
|
96
96
|
},
|
|
97
97
|
"dependencies": {
|
|
98
|
-
"@cero-base/core": "^1.14.
|
|
98
|
+
"@cero-base/core": "^1.14.1",
|
|
99
99
|
"b4a": "^1.8.1",
|
|
100
100
|
"bare-abort-controller": "^1.1.2",
|
|
101
101
|
"bare-crypto": "^1.15.3",
|
|
102
|
-
"bare-fs": "^4.8.
|
|
102
|
+
"bare-fs": "^4.8.1",
|
|
103
103
|
"bare-path": "^3.1.1",
|
|
104
104
|
"ble-swarm": "^2.2.0",
|
|
105
105
|
"compact-encoding": "^3.3.2",
|
|
106
|
-
"corestore": "^7.12.
|
|
106
|
+
"corestore": "^7.12.2",
|
|
107
107
|
"hrpc": "^4.3.1",
|
|
108
108
|
"hypercore": "^11.35.2",
|
|
109
109
|
"hypercore-crypto": "^3.7.0",
|
|
@@ -113,13 +113,13 @@
|
|
|
113
113
|
"hyperschema": "^1.22.0",
|
|
114
114
|
"ready-resource": "^1.2.0",
|
|
115
115
|
"safety-catch": "^1.0.3",
|
|
116
|
-
"streamx": "^2.28.
|
|
116
|
+
"streamx": "^2.28.1",
|
|
117
117
|
"suspendify": "^1.7.2",
|
|
118
118
|
"z32": "^1.1.0"
|
|
119
119
|
},
|
|
120
120
|
"devDependencies": {
|
|
121
121
|
"@hyperswarm/testnet": "^3.1.4",
|
|
122
|
-
"bare-events": "^2.9.
|
|
122
|
+
"bare-events": "^2.9.2",
|
|
123
123
|
"bare-fetch": "^3.2.0",
|
|
124
124
|
"bare-process": "^4.5.1",
|
|
125
125
|
"bare-url": "^2.5.2",
|
package/src/handle/index.js
CHANGED
|
@@ -212,7 +212,7 @@ export class Handle extends ReadyResource {
|
|
|
212
212
|
}
|
|
213
213
|
const store = this.store.store
|
|
214
214
|
await this.store.close()
|
|
215
|
-
if (this._discovery)
|
|
215
|
+
if (this._discovery) this._discovery.destroy().catch(safetyCatch)
|
|
216
216
|
await this.network.close()
|
|
217
217
|
await store.close()
|
|
218
218
|
if (this._storage) await this._storage.close()
|
package/src/index.js
CHANGED
|
@@ -111,7 +111,7 @@ export async function cero(dir, spec, opts = {}) {
|
|
|
111
111
|
await local.ready()
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
const identity = await resolveIdentity(opts, local)
|
|
114
|
+
const { identity, fresh } = await resolveIdentity(opts, local)
|
|
115
115
|
const writer = local ? (await local.store.get('keypair')).data : null
|
|
116
116
|
|
|
117
117
|
// Channel stamp: a storage remembers its channel; reopening it under a different channel —
|
|
@@ -133,7 +133,9 @@ export async function cero(dir, spec, opts = {}) {
|
|
|
133
133
|
})
|
|
134
134
|
await network.ready()
|
|
135
135
|
discovery = network.join(identity.topic)
|
|
136
|
-
|
|
136
|
+
// a freshly minted identity has no peers yet — flushing the announce
|
|
137
|
+
// before proceeding only delays first onboarding
|
|
138
|
+
if (!fresh) await Promise.race([discovery.flush(), new Promise((r) => setTimeout(r, FLUSH))])
|
|
137
139
|
|
|
138
140
|
me = new Handle({
|
|
139
141
|
storage,
|
|
@@ -315,18 +317,18 @@ cero.use = (...exts) => {
|
|
|
315
317
|
}
|
|
316
318
|
|
|
317
319
|
async function resolveIdentity(opts, local) {
|
|
318
|
-
if (opts.identity) return opts.identity
|
|
320
|
+
if (opts.identity) return { identity: opts.identity, fresh: false }
|
|
319
321
|
|
|
320
322
|
const provided = opts.seed || (opts.phrase && Identity.toSeed(opts.phrase))
|
|
321
323
|
if (provided) {
|
|
322
324
|
if (local) await local.store.set('master', { seed: provided })
|
|
323
|
-
return Identity.fromSeed(provided)
|
|
325
|
+
return { identity: await Identity.fromSeed(provided), fresh: false }
|
|
324
326
|
}
|
|
325
327
|
|
|
326
328
|
const stored = local && (await local.store.get('master')).data?.seed
|
|
327
|
-
if (stored) return Identity.fromSeed(stored)
|
|
329
|
+
if (stored) return { identity: await Identity.fromSeed(stored), fresh: false }
|
|
328
330
|
|
|
329
|
-
const
|
|
330
|
-
if (local) await local.store.set('master', { seed:
|
|
331
|
-
return fresh
|
|
331
|
+
const identity = await Identity.generate({ words: opts.words })
|
|
332
|
+
if (local) await local.store.set('master', { seed: identity.seed })
|
|
333
|
+
return { identity, fresh: true }
|
|
332
334
|
}
|