@leofcoin/peernet 1.2.26 → 1.2.28
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/exports/browser/{browser-D-r0O9Qn.js → browser-CWeoyGUw.js} +1 -1
- package/exports/browser/{browser-_hiyXwPp.js → browser-DvU1xNFS.js} +1 -1
- package/exports/browser/{client-U5AYtQje.js → client-B-jyclOB.js} +35 -5
- package/exports/browser/{identity-ChyyZSve.js → identity-CYVPDmkf.js} +7 -2
- package/exports/browser/identity.js +1 -1
- package/exports/browser/{index-BD0Anx7_.js → index-Bxr5Iztg.js} +1 -1
- package/exports/browser/{messages-Dr5w-bq6.js → messages-FMRAS8QX.js} +2 -2
- package/exports/browser/{peernet-DHQj_MFb.js → peernet-CRbrmeU3.js} +3 -3
- package/exports/browser/peernet.js +2 -2
- package/exports/identity.js +6 -1
- package/exports/types/peernet.d.ts +36 -3
- package/package.json +2 -2
- package/src/identity.ts +6 -1
- package/test/fresh-empty-store.js +15 -0
- package/test/peernet.test.js +19 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { L as LittlePubSub, d as deflate_1, i as inflate_1, c as createDebugger } from './peernet-
|
|
2
|
-
import './identity-
|
|
1
|
+
import { L as LittlePubSub, d as deflate_1, i as inflate_1, c as createDebugger } from './peernet-CRbrmeU3.js';
|
|
2
|
+
import './identity-CYVPDmkf.js';
|
|
3
3
|
import 'crypto';
|
|
4
4
|
import './value-C3vAp-wb.js';
|
|
5
5
|
|
|
@@ -232,7 +232,7 @@ class SocketRequestClient {
|
|
|
232
232
|
const init = async () => {
|
|
233
233
|
// @ts-ignore
|
|
234
234
|
if (!globalThis.WebSocket && !this.#experimentalWebsocket)
|
|
235
|
-
globalThis.WebSocket = (await import('./browser-
|
|
235
|
+
globalThis.WebSocket = (await import('./browser-DvU1xNFS.js').then(function (n) { return n.b; })).default.w3cwebsocket;
|
|
236
236
|
const client = new WebSocket(this.#url, this.#protocol);
|
|
237
237
|
if (this.#experimentalWebsocket) {
|
|
238
238
|
client.addEventListener('error', this.onerror);
|
|
@@ -1104,6 +1104,27 @@ class CircuitPeer {
|
|
|
1104
1104
|
}
|
|
1105
1105
|
}
|
|
1106
1106
|
|
|
1107
|
+
/** Normalize current star announcements and the legacy peer-id-only format. */
|
|
1108
|
+
const normalizePeerAnnouncement = (value) => {
|
|
1109
|
+
if (typeof value === 'string') {
|
|
1110
|
+
const peerId = value.trim();
|
|
1111
|
+
return peerId && peerId !== 'undefined' ? { peerId } : null;
|
|
1112
|
+
}
|
|
1113
|
+
if (!value || typeof value !== 'object')
|
|
1114
|
+
return null;
|
|
1115
|
+
const candidate = value;
|
|
1116
|
+
if (typeof candidate.peerId !== 'string')
|
|
1117
|
+
return null;
|
|
1118
|
+
const peerId = candidate.peerId.trim();
|
|
1119
|
+
if (!peerId || peerId === 'undefined')
|
|
1120
|
+
return null;
|
|
1121
|
+
return {
|
|
1122
|
+
peerId,
|
|
1123
|
+
version: typeof candidate.version === 'string' ? candidate.version : undefined,
|
|
1124
|
+
transport: candidate.transport
|
|
1125
|
+
};
|
|
1126
|
+
};
|
|
1127
|
+
|
|
1107
1128
|
// Simple CRC32 implementation
|
|
1108
1129
|
const crc32 = (data) => {
|
|
1109
1130
|
let crc = 0xffffffff;
|
|
@@ -1303,7 +1324,7 @@ class Client {
|
|
|
1303
1324
|
}
|
|
1304
1325
|
}
|
|
1305
1326
|
async #loadNodeWebrtcImplementation() {
|
|
1306
|
-
const koushWrtcModule = await import('./browser-
|
|
1327
|
+
const koushWrtcModule = await import('./browser-CWeoyGUw.js').then(function (n) { return n.b; });
|
|
1307
1328
|
const koushWrtc = koushWrtcModule.default;
|
|
1308
1329
|
if (!isWrtcImplementation(koushWrtc)) {
|
|
1309
1330
|
throw new Error('@koush/wrtc does not match required wrtc contract');
|
|
@@ -1853,7 +1874,16 @@ class Client {
|
|
|
1853
1874
|
this.#peerTransportKinds.set(peerId, 'webrtc');
|
|
1854
1875
|
return peer;
|
|
1855
1876
|
};
|
|
1856
|
-
#peerJoined = async (
|
|
1877
|
+
#peerJoined = async (announcement, star) => {
|
|
1878
|
+
const normalized = normalizePeerAnnouncement(announcement);
|
|
1879
|
+
if (!normalized) {
|
|
1880
|
+
debug('ignored malformed peer announcement');
|
|
1881
|
+
return;
|
|
1882
|
+
}
|
|
1883
|
+
const { peerId, transport } = normalized;
|
|
1884
|
+
// Legacy stars announce only the peer id. This value is used for transport
|
|
1885
|
+
// negotiation; applications still perform their own version handshake.
|
|
1886
|
+
const version = normalized.version ?? this.version;
|
|
1857
1887
|
if (this.peerId === peerId)
|
|
1858
1888
|
return;
|
|
1859
1889
|
// Stars can announce the same peer more than once while its transport is
|
|
@@ -8323,7 +8323,12 @@ class Identity {
|
|
|
8323
8323
|
const importee = await import('./prompts/password.js');
|
|
8324
8324
|
password = await importee.default();
|
|
8325
8325
|
}
|
|
8326
|
-
|
|
8326
|
+
// LevelDB opens lazily. Touch both stores before freshIdentity clears them;
|
|
8327
|
+
// clearing a brand-new, unopened store throws LEVEL_DATABASE_NOT_OPEN.
|
|
8328
|
+
const [accountExists] = await Promise.all([
|
|
8329
|
+
globalThis.accountStore.has('public'),
|
|
8330
|
+
globalThis.walletStore.has('identity')
|
|
8331
|
+
]);
|
|
8327
8332
|
if (accountExists && !fresh) {
|
|
8328
8333
|
const pub = await globalThis.accountStore.get('public');
|
|
8329
8334
|
this.id = JSON.parse(new TextDecoder().decode(pub)).walletId;
|
|
@@ -8331,7 +8336,7 @@ class Identity {
|
|
|
8331
8336
|
this.selectedAccount = new TextDecoder().decode(selected);
|
|
8332
8337
|
}
|
|
8333
8338
|
else {
|
|
8334
|
-
const importee = await import(/* webpackChunkName: "generate-account" */ './index-
|
|
8339
|
+
const importee = await import(/* webpackChunkName: "generate-account" */ './index-Bxr5Iztg.js');
|
|
8335
8340
|
const { identity, accounts } = await importee.default(password, this.network);
|
|
8336
8341
|
if (fresh) {
|
|
8337
8342
|
await globalThis.accountStore.clear();
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { I as default, r as resolveAccountWallets } from './identity-
|
|
1
|
+
export { I as default, r as resolveAccountWallets } from './identity-CYVPDmkf.js';
|
|
2
2
|
import 'crypto';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as index$2, b as base, a as base58$1, c as index$3, d as index$4, e as index$5, f as createSHA512, g as createSHA384, h as createSHA256, j as createSHA224, k as createSHA1, I as Identity } from './identity-
|
|
1
|
+
import { i as index$2, b as base, a as base58$1, c as index$3, d as index$4, e as index$5, f as createSHA512, g as createSHA384, h as createSHA256, j as createSHA224, k as createSHA1, I as Identity } from './identity-CYVPDmkf.js';
|
|
2
2
|
import { K as KeyPath, a as KeyValue } from './value-C3vAp-wb.js';
|
|
3
3
|
|
|
4
4
|
const getTargets = () => Array.from([]);
|
|
@@ -8615,7 +8615,7 @@ class Peernet {
|
|
|
8615
8615
|
await getAddress();
|
|
8616
8616
|
this.storePrefix = options.storePrefix;
|
|
8617
8617
|
this.root = options.root;
|
|
8618
|
-
const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile } = await import(/* webpackChunkName: "messages" */ './messages-
|
|
8618
|
+
const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile } = await import(/* webpackChunkName: "messages" */ './messages-FMRAS8QX.js');
|
|
8619
8619
|
/**
|
|
8620
8620
|
* proto Object containing protos
|
|
8621
8621
|
* @type {Object}
|
|
@@ -8662,7 +8662,7 @@ class Peernet {
|
|
|
8662
8662
|
if (this.#starting || this.#started)
|
|
8663
8663
|
return;
|
|
8664
8664
|
this.#starting = true;
|
|
8665
|
-
const importee = await import('./client-
|
|
8665
|
+
const importee = await import('./client-B-jyclOB.js');
|
|
8666
8666
|
/**
|
|
8667
8667
|
* @access public
|
|
8668
8668
|
* @type {PeernetClient}
|
package/exports/identity.js
CHANGED
|
@@ -68,7 +68,12 @@ class Identity {
|
|
|
68
68
|
const importee = await import('./prompts/password.js');
|
|
69
69
|
password = await importee.default();
|
|
70
70
|
}
|
|
71
|
-
|
|
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;
|
|
@@ -86,14 +86,47 @@ export default class Peernet {
|
|
|
86
86
|
*
|
|
87
87
|
* @return {Array} peerId
|
|
88
88
|
*/
|
|
89
|
-
get peers(): [string,
|
|
89
|
+
get peers(): [string, {
|
|
90
|
+
connected: boolean;
|
|
91
|
+
initiator: boolean;
|
|
92
|
+
peerId: string;
|
|
93
|
+
channelName: string;
|
|
94
|
+
on: (event: string, handler: (...args: unknown[]) => void) => unknown;
|
|
95
|
+
off: (event: string, handler: (...args: unknown[]) => void) => unknown;
|
|
96
|
+
signal: (signalData: unknown) => void;
|
|
97
|
+
destroy: () => void;
|
|
98
|
+
send: (data: Uint8Array, id?: string) => void;
|
|
99
|
+
request: (data: Uint8Array, id?: string) => Promise<Uint8Array>;
|
|
100
|
+
}][];
|
|
90
101
|
get connections(): {
|
|
91
|
-
[index: string]:
|
|
102
|
+
[index: string]: {
|
|
103
|
+
connected: boolean;
|
|
104
|
+
initiator: boolean;
|
|
105
|
+
peerId: string;
|
|
106
|
+
channelName: string;
|
|
107
|
+
on: (event: string, handler: (...args: unknown[]) => void) => unknown;
|
|
108
|
+
off: (event: string, handler: (...args: unknown[]) => void) => unknown;
|
|
109
|
+
signal: (signalData: unknown) => void;
|
|
110
|
+
destroy: () => void;
|
|
111
|
+
send: (data: Uint8Array, id?: string) => void;
|
|
112
|
+
request: (data: Uint8Array, id?: string) => Promise<Uint8Array>;
|
|
113
|
+
};
|
|
92
114
|
};
|
|
93
115
|
/**
|
|
94
116
|
* @return {String} id - peerId
|
|
95
117
|
*/
|
|
96
|
-
getConnection(id: any):
|
|
118
|
+
getConnection(id: any): {
|
|
119
|
+
connected: boolean;
|
|
120
|
+
initiator: boolean;
|
|
121
|
+
peerId: string;
|
|
122
|
+
channelName: string;
|
|
123
|
+
on: (event: string, handler: (...args: unknown[]) => void) => unknown;
|
|
124
|
+
off: (event: string, handler: (...args: unknown[]) => void) => unknown;
|
|
125
|
+
signal: (signalData: unknown) => void;
|
|
126
|
+
destroy: () => void;
|
|
127
|
+
send: (data: Uint8Array, id?: string) => void;
|
|
128
|
+
request: (data: Uint8Array, id?: string) => Promise<Uint8Array>;
|
|
129
|
+
};
|
|
97
130
|
/**
|
|
98
131
|
* @private
|
|
99
132
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leofcoin/peernet",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.28",
|
|
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.
|
|
115
|
+
"@netpeer/swarm": "^0.9.11",
|
|
116
116
|
"@vandeurenglenn/base58": "^1.1.9",
|
|
117
117
|
"@vandeurenglenn/debug": "^1.4.0",
|
|
118
118
|
"@vandeurenglenn/little-pubsub": "^1.5.2",
|
package/src/identity.ts
CHANGED
|
@@ -87,7 +87,12 @@ export default class Identity {
|
|
|
87
87
|
password = await importee.default()
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
|
|
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')
|
package/test/peernet.test.js
CHANGED
|
@@ -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')
|