@leofcoin/peernet 1.2.27 → 1.2.29

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.
@@ -1,4 +1,4 @@
1
- export { P as default } from './peernet-r_9IyzTe.js';
2
- import './identity-ChyyZSve.js';
1
+ export { P as default } from './peernet-Ca1iM2tN.js';
2
+ import './identity-CYVPDmkf.js';
3
3
  import './value-C3vAp-wb.js';
4
4
  import 'crypto';
@@ -68,7 +68,12 @@ class Identity {
68
68
  const importee = await import('./prompts/password.js');
69
69
  password = await importee.default();
70
70
  }
71
- const accountExists = await globalThis.accountStore.has('public');
71
+ // LevelDB opens lazily. Touch both stores before freshIdentity clears them;
72
+ // clearing a brand-new, unopened store throws LEVEL_DATABASE_NOT_OPEN.
73
+ const [accountExists] = await Promise.all([
74
+ globalThis.accountStore.has('public'),
75
+ globalThis.walletStore.has('identity')
76
+ ]);
72
77
  if (accountExists && !fresh) {
73
78
  const pub = await globalThis.accountStore.get('public');
74
79
  this.id = JSON.parse(new TextDecoder().decode(pub)).walletId;
package/exports/store.js CHANGED
@@ -102,6 +102,9 @@ class Store {
102
102
  this.root = await init(root, homedir);
103
103
  this.version = version;
104
104
  this.db = new ClassicLevel(join(this.root, this.name), { valueEncoding: 'view' });
105
+ if (typeof this.db.open === 'function') {
106
+ await this.db.open();
107
+ }
105
108
  }
106
109
  toKeyPath(key) {
107
110
  if (!key.isKeyPath())
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/peernet",
3
- "version": "1.2.27",
3
+ "version": "1.2.29",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",
@@ -112,7 +112,7 @@
112
112
  "@leofcoin/multi-wallet": "^3.1.8",
113
113
  "@leofcoin/storage": "^3.5.38",
114
114
  "@mapbox/node-pre-gyp": "^2.0.3",
115
- "@netpeer/swarm": "^0.9.11",
115
+ "@netpeer/swarm": "^0.9.12",
116
116
  "@vandeurenglenn/base58": "^1.1.9",
117
117
  "@vandeurenglenn/debug": "^1.4.0",
118
118
  "@vandeurenglenn/little-pubsub": "^1.5.2",
@@ -129,6 +129,7 @@
129
129
  "@rollup/plugin-wasm": "^6.2.2",
130
130
  "@types/node": "^25.9.1",
131
131
  "@types/qrcode": "^1.5.6",
132
+ "rimraf": "^5.0.10",
132
133
  "rollup": "^4.60.4",
133
134
  "tslib": "^2.8.1",
134
135
  "typescript": "^6.0.2"
package/rollup.config.js CHANGED
@@ -4,7 +4,7 @@ import json from '@rollup/plugin-json'
4
4
  import wasm from '@rollup/plugin-wasm'
5
5
  import { readdir, readFile, writeFile } from 'node:fs/promises'
6
6
  import { extname, relative, sep } from 'node:path'
7
- import rimraf from 'rimraf'
7
+ import { rimrafSync } from 'rimraf'
8
8
  import typescript from '@rollup/plugin-typescript'
9
9
 
10
10
  const toPosix = (value) => value.split(sep).join('/')
@@ -82,7 +82,7 @@ const runtimeFirstExports = ({ exportsDir = 'exports', declarationsDir = 'export
82
82
  }
83
83
  })
84
84
 
85
- rimraf.sync('./exports/**')
85
+ rimrafSync('./exports/**')
86
86
 
87
87
  export default [
88
88
  {
package/src/identity.ts CHANGED
@@ -87,7 +87,12 @@ export default class Identity {
87
87
  password = await importee.default()
88
88
  }
89
89
 
90
- const accountExists = await globalThis.accountStore.has('public')
90
+ // LevelDB opens lazily. Touch both stores before freshIdentity clears them;
91
+ // clearing a brand-new, unopened store throws LEVEL_DATABASE_NOT_OPEN.
92
+ const [accountExists] = await Promise.all([
93
+ globalThis.accountStore.has('public'),
94
+ globalThis.walletStore.has('identity')
95
+ ])
91
96
  if (accountExists && !fresh) {
92
97
  const pub = await globalThis.accountStore.get('public')
93
98
  this.id = JSON.parse(new TextDecoder().decode(pub)).walletId
@@ -0,0 +1,15 @@
1
+ import Peernet from '../exports/peernet.js'
2
+
3
+ const peernet = await new Peernet(
4
+ {
5
+ network: 'leofcoin:peach',
6
+ stars: [],
7
+ root: process.argv[2],
8
+ autoStart: false,
9
+ freshIdentity: true
10
+ },
11
+ 'fresh-empty-store-test'
12
+ )
13
+
14
+ if (!peernet.id || !peernet.selectedAccount) throw new Error('fresh identity was not initialized')
15
+ console.log('FRESH_IDENTITY_READY')
@@ -1,6 +1,11 @@
1
1
  import test from 'node:test'
2
2
  import assert from 'node:assert/strict'
3
3
  import { readFile } from 'node:fs/promises'
4
+ import { execFile } from 'node:child_process'
5
+ import { mkdtemp, rm } from 'node:fs/promises'
6
+ import { tmpdir } from 'node:os'
7
+ import { join } from 'node:path'
8
+ import { promisify } from 'node:util'
4
9
 
5
10
  import Peernet from '../exports/peernet.js'
6
11
  import Identity, { resolveAccountWallets } from '../exports/identity.js'
@@ -18,6 +23,20 @@ const options = {
18
23
 
19
24
  const password = 'password'
20
25
  const peernet = await new Peernet(options, password)
26
+ const execFileAsync = promisify(execFile)
27
+
28
+ test('freshIdentity initializes against a completely empty store root', async () => {
29
+ const root = await mkdtemp(join(tmpdir(), 'peernet-fresh-identity-'))
30
+ try {
31
+ const { stdout } = await execFileAsync(process.execPath, ['test/fresh-empty-store.js', root], {
32
+ cwd: new URL('..', import.meta.url),
33
+ timeout: 20_000
34
+ })
35
+ assert.match(stdout, /FRESH_IDENTITY_READY/)
36
+ } finally {
37
+ await rm(root, { recursive: true, force: true })
38
+ }
39
+ })
21
40
 
22
41
  test('node bundle uses a portable password prompt import', async () => {
23
42
  const identityBundle = await readFile(new URL('../exports/identity.js', import.meta.url), 'utf8')
@@ -0,0 +1,84 @@
1
+ ✔ initializes with provided options (0.407125ms)
2
+ ✔ exposes identity instance (0.051667ms)
3
+ ✔ has a DHT instance (0.04425ms)
4
+ ✔ returns peers and connections safely (0.267542ms)
5
+ ✔ provides callable helpers (0.048958ms)
6
+ ✔ pubsub subscribe registers callback (10.395584ms)
7
+ ✔ addProto registers protocol (0.160417ms)
8
+ ✔ addProto does not overwrite existing protocol (0.057709ms)
9
+ ✔ addCodec is callable (0.063084ms)
10
+ ✔ selectAccount delegates to identity (0.068584ms)
11
+ ✔ identity has loaded account data (0.241875ms)
12
+ ✔ peerId matches identity id (0.031375ms)
13
+ ✔ data store operations (0.030125ms)
14
+ ✔ get attempts to retrieve from store (0.035667ms)
15
+ ✔ message object provides get/put/has (0.053917ms)
16
+ ✔ data object provides get/put/has (0.045833ms)
17
+ ✔ block object provides get/put/has (0.067375ms)
18
+ ✔ transaction object provides get/put/has (0.042333ms)
19
+ ✔ folder object provides get/put/has (0.034167ms)
20
+ ✔ Buffer property is available (0.024417ms)
21
+ ✔ handleData is callable (0.017709ms)
22
+ ✔ handleDHT is callable (0.016167ms)
23
+ ✔ handleRequest is callable (0.016417ms)
24
+ ✔ walk is callable (0.015459ms)
25
+ ✔ providersFor is callable (0.015583ms)
26
+ ✔ addRequestHandler is callable (0.015375ms)
27
+ ✔ sendMessage is callable (0.01625ms)
28
+ ✔ start method exists (0.02675ms)
29
+ ✔ default stores are initialized (0.0275ms)
30
+ ✔ identity has all expected methods (0.020084ms)
31
+ ✔ identity wallet is loaded (0.019333ms)
32
+ ✔ selected account is set (0.016208ms)
33
+ ✔ error handling methods exist (0.017083ms)
34
+ DEBUG_HANDLE_DATA: entering in-memory branch { hash: 'BA43QACTNQLBH6SW7NO7ZQ63I3USRUBTD5DOWLEUFJGMY6JN2BSUAES54X' }
35
+ DEBUG_HANDLE_DATA: got from _inMemoryBroadcasts {
36
+ type: 'object',
37
+ isUint8Array: true,
38
+ length: 34,
39
+ slice: [
40
+ 230, 224, 1, 5, 47,
41
+ 116, 101, 115, 116, 21,
42
+ 104, 101, 108, 108, 111,
43
+ 32
44
+ ]
45
+ }
46
+ ✔ in-memory broadcast and handleData returns correct data (4.52275ms)
47
+ DEBUG_HANDLE_DATA: entering in-memory branch { hash: 'BA43QACYLVOY2HRRGV4NOUDQ3GWPQ7YZVBBM5DOKGZIY4UOYMS3K3JSCVV' }
48
+ DEBUG_HANDLE_DATA: got from _inMemoryBroadcasts {
49
+ type: 'object',
50
+ isUint8Array: true,
51
+ length: 1048599,
52
+ slice: [
53
+ 230, 224, 1, 13, 47, 108,
54
+ 97, 114, 103, 101, 45, 98,
55
+ 105, 110, 97, 114
56
+ ]
57
+ }
58
+ DEBUG_TEST receivedBuffer {
59
+ type: 'object',
60
+ isUint8Array: true,
61
+ length: 1048576,
62
+ slice: [
63
+ 0, 1, 2, 3, 4, 5,
64
+ 6, 7, 8, 9, 10, 11,
65
+ 12, 13, 14, 15
66
+ ]
67
+ }
68
+ DEBUG_TEST originalBuffer {
69
+ length: 1048576,
70
+ slice: [
71
+ 0, 1, 2, 3, 4, 5,
72
+ 6, 7, 8, 9, 10, 11,
73
+ 12, 13, 14, 15
74
+ ]
75
+ }
76
+ ✔ in-memory broadcast and handleData supports large binary data (163.195292ms)
77
+ ℹ tests 35
78
+ ℹ suites 0
79
+ ℹ pass 35
80
+ ℹ fail 0
81
+ ℹ cancelled 0
82
+ ℹ skipped 0
83
+ ℹ todo 0
84
+ ℹ duration_ms 366.132458