@leofcoin/peernet 1.1.79 → 1.1.80
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-WUe24rfW.js → browser-DQJ6xf_F.js} +3 -3
- package/exports/browser/browser-store.js +168 -22
- package/exports/browser/{client-I9x7CFr1.js → client-Depp28gl.js} +66 -32
- package/exports/browser/{peernet-DULgegxE.js → identity-CQ_ieRiz.js} +2232 -13425
- package/exports/browser/identity.d.ts +1 -1
- package/exports/browser/identity.js +1 -0
- package/exports/browser/{index-sw14JvKD.js → index-BeqbCwUk.js} +1 -2
- package/exports/browser/{index-In1Jzp-v.js → index-DqPlTtAJ.js} +428 -416
- package/exports/browser/{messages-lzTD4EMU.js → messages-RYLqPGkg.js} +3 -2
- package/exports/browser/peernet-B7TZP-Wg.js +13220 -0
- package/exports/browser/peernet.d.ts +7 -7
- package/exports/browser/peernet.js +3 -2
- package/exports/identity.js +92 -0
- package/exports/peernet.js +7 -91
- package/exports/store.js +9 -2
- package/exports/types/identity.d.ts +1 -1
- package/exports/types/peernet.d.ts +7 -7
- package/package.json +34 -25
- package/rollup.config.js +2 -2
- package/test/peernet.test.js +159 -0
- package/tsconfig.json +2 -4
- /package/exports/browser/{browser-AyxSBUXj.js → browser-pguCHlVu.js} +0 -0
- /package/exports/browser/{qr-scanner-worker.min-RaSiJc_R.js → qr-scanner-worker.min-Dy0qkKA4.js} +0 -0
- /package/exports/browser/{value-wzPYMxsX.js → value-C3vAp-wb.js} +0 -0
- /package/exports/{messages-T3M-Ff1E.js → messages-CRhtDipD.js} +0 -0
|
@@ -71,7 +71,7 @@ export default class Peernet {
|
|
|
71
71
|
get selectedAccount(): string;
|
|
72
72
|
get accounts(): Promise<[[name: string, externalAddress: string, internalAddress: string]]>;
|
|
73
73
|
get defaultStores(): string[];
|
|
74
|
-
selectAccount(account: string): Promise<
|
|
74
|
+
selectAccount(account: string): Promise<unknown>;
|
|
75
75
|
addProto(name: any, proto: any): void;
|
|
76
76
|
addCodec(codec: any): void;
|
|
77
77
|
addStore(name: any, prefix: any, root: any, isPrivate?: boolean): Promise<void>;
|
|
@@ -131,12 +131,12 @@ export default class Peernet {
|
|
|
131
131
|
providersFor(hash: string, store?: undefined): Promise<import("./dht/dht.js").DHTProviderMapValue>;
|
|
132
132
|
get block(): {
|
|
133
133
|
get: (hash: string) => Promise<any>;
|
|
134
|
-
put: (hash: string, data: Uint8Array) => Promise<
|
|
134
|
+
put: (hash: string, data: Uint8Array) => Promise<unknown>;
|
|
135
135
|
has: (hash: string) => Promise<boolean | any[]>;
|
|
136
136
|
};
|
|
137
137
|
get transaction(): {
|
|
138
138
|
get: (hash: string) => Promise<any>;
|
|
139
|
-
put: (hash: string, data: Uint8Array) => Promise<
|
|
139
|
+
put: (hash: string, data: Uint8Array) => Promise<unknown>;
|
|
140
140
|
has: (hash: string) => Promise<boolean | any[]>;
|
|
141
141
|
};
|
|
142
142
|
requestData(hash: any, store: any): any;
|
|
@@ -153,7 +153,7 @@ export default class Peernet {
|
|
|
153
153
|
* @param {String} hash
|
|
154
154
|
* @param {Buffer} message
|
|
155
155
|
*/
|
|
156
|
-
put: (hash: any, message: any) => Promise<
|
|
156
|
+
put: (hash: any, message: any) => Promise<unknown>;
|
|
157
157
|
/**
|
|
158
158
|
* @param {String} hash
|
|
159
159
|
* @return {Boolean}
|
|
@@ -173,7 +173,7 @@ export default class Peernet {
|
|
|
173
173
|
* @param {String} hash
|
|
174
174
|
* @param {Buffer} data
|
|
175
175
|
*/
|
|
176
|
-
put: (hash: any, data: any) => Promise<
|
|
176
|
+
put: (hash: any, data: any) => Promise<unknown>;
|
|
177
177
|
/**
|
|
178
178
|
* @param {String} hash
|
|
179
179
|
* @return {Boolean}
|
|
@@ -193,7 +193,7 @@ export default class Peernet {
|
|
|
193
193
|
* @param {String} hash
|
|
194
194
|
* @param {Buffer} data
|
|
195
195
|
*/
|
|
196
|
-
put: (hash: any, data: any) => Promise<
|
|
196
|
+
put: (hash: any, data: any) => Promise<unknown>;
|
|
197
197
|
/**
|
|
198
198
|
* @param {String} hash
|
|
199
199
|
* @return {Boolean}
|
|
@@ -223,7 +223,7 @@ export default class Peernet {
|
|
|
223
223
|
* @param {Buffer} data
|
|
224
224
|
* @param {String} storeName - storeName to access
|
|
225
225
|
*/
|
|
226
|
-
put(hash: string, data: Uint8Array, storeName?: string | LeofcoinStorageClass): Promise<
|
|
226
|
+
put(hash: string, data: Uint8Array, storeName?: string | LeofcoinStorageClass): Promise<unknown>;
|
|
227
227
|
/**
|
|
228
228
|
* @param {String} hash
|
|
229
229
|
* @return {Boolean}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export { P as default } from './peernet-
|
|
2
|
-
import './
|
|
1
|
+
export { P as default } from './peernet-B7TZP-Wg.js';
|
|
2
|
+
import './identity-CQ_ieRiz.js';
|
|
3
|
+
import './value-C3vAp-wb.js';
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import MultiWallet from '@leofcoin/multi-wallet';
|
|
2
|
+
import base58 from '@vandeurenglenn/base58';
|
|
3
|
+
import { decrypt } from '@leofcoin/identity-utils';
|
|
4
|
+
import QrScanner from 'qr-scanner';
|
|
5
|
+
import qrcode from 'qrcode';
|
|
6
|
+
|
|
7
|
+
class Identity {
|
|
8
|
+
#wallet;
|
|
9
|
+
network;
|
|
10
|
+
id;
|
|
11
|
+
selectedAccount;
|
|
12
|
+
constructor(network) {
|
|
13
|
+
this.network = network;
|
|
14
|
+
}
|
|
15
|
+
get accounts() {
|
|
16
|
+
return this.getAccounts();
|
|
17
|
+
}
|
|
18
|
+
async getAccounts() {
|
|
19
|
+
let accounts = await globalThis.walletStore.get('accounts');
|
|
20
|
+
accounts = new TextDecoder().decode(accounts);
|
|
21
|
+
return JSON.parse(accounts);
|
|
22
|
+
}
|
|
23
|
+
async load(password) {
|
|
24
|
+
if (password && password.includes('.txt')) {
|
|
25
|
+
const { readFile } = await import('fs/promises');
|
|
26
|
+
try {
|
|
27
|
+
password = (await readFile(password)).toString();
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
console.error(error);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (!password) {
|
|
34
|
+
// @ts-ignore
|
|
35
|
+
const importee = await import('./src/prompts/password.js');
|
|
36
|
+
password = await importee.default();
|
|
37
|
+
}
|
|
38
|
+
const accountExists = await globalThis.accountStore.has('public');
|
|
39
|
+
if (accountExists) {
|
|
40
|
+
const pub = await globalThis.accountStore.get('public');
|
|
41
|
+
this.id = JSON.parse(new TextDecoder().decode(pub)).walletId;
|
|
42
|
+
const selected = await globalThis.walletStore.get('selected-account');
|
|
43
|
+
this.selectedAccount = new TextDecoder().decode(selected);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
const importee = await import(/* webpackChunkName: "generate-account" */ '@leofcoin/generate-account');
|
|
47
|
+
const { identity, accounts } = await importee.default(password, this.network);
|
|
48
|
+
await globalThis.accountStore.put('public', JSON.stringify({ walletId: identity.walletId }));
|
|
49
|
+
await globalThis.walletStore.put('version', String(1));
|
|
50
|
+
await globalThis.walletStore.put('accounts', JSON.stringify(accounts));
|
|
51
|
+
await globalThis.walletStore.put('selected-account', accounts[0][1]);
|
|
52
|
+
await globalThis.walletStore.put('identity', JSON.stringify(identity));
|
|
53
|
+
this.selectedAccount = accounts[0][1];
|
|
54
|
+
this.id = identity.walletId;
|
|
55
|
+
}
|
|
56
|
+
const identity = JSON.parse(new TextDecoder().decode(await globalThis.walletStore.get('identity')));
|
|
57
|
+
this.#wallet = new MultiWallet(this.network);
|
|
58
|
+
const multiWIF = await decrypt(password, base58.decode(identity.multiWIF));
|
|
59
|
+
await this.#wallet.fromMultiWif(multiWIF);
|
|
60
|
+
}
|
|
61
|
+
selectAccount(account) {
|
|
62
|
+
this.selectedAccount = account;
|
|
63
|
+
return walletStore.put('selected-account', account);
|
|
64
|
+
}
|
|
65
|
+
sign(hash) {
|
|
66
|
+
return this.#wallet.sign(hash.subarray(0, 32));
|
|
67
|
+
}
|
|
68
|
+
lock(password) {
|
|
69
|
+
this.#wallet.lock(password);
|
|
70
|
+
}
|
|
71
|
+
unlock(password) {
|
|
72
|
+
this.#wallet.unlock(password);
|
|
73
|
+
}
|
|
74
|
+
async export(password) {
|
|
75
|
+
return this.#wallet.export(password);
|
|
76
|
+
}
|
|
77
|
+
async import(password, encrypted) {
|
|
78
|
+
await this.#wallet.import(password, encrypted);
|
|
79
|
+
}
|
|
80
|
+
async exportQR(password) {
|
|
81
|
+
const exported = await this.export(password);
|
|
82
|
+
return globalThis.navigator
|
|
83
|
+
? await qrcode.toDataURL(exported)
|
|
84
|
+
: await qrcode.toString(exported, { type: 'terminal' });
|
|
85
|
+
}
|
|
86
|
+
async importQR(image, password) {
|
|
87
|
+
const multiWIF = await QrScanner.default.scanImage(image);
|
|
88
|
+
return this.import(password, multiWIF);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export { Identity as default };
|
package/exports/peernet.js
CHANGED
|
@@ -3,11 +3,12 @@ import PubSub from '@vandeurenglenn/little-pubsub';
|
|
|
3
3
|
import { Codec } from '@leofcoin/codec-format-interface';
|
|
4
4
|
import { Storage } from '@leofcoin/storage';
|
|
5
5
|
import { utils } from '@leofcoin/codecs';
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
6
|
+
import Identity from './identity.js';
|
|
7
|
+
import '@leofcoin/multi-wallet';
|
|
8
|
+
import '@vandeurenglenn/base58';
|
|
9
|
+
import '@leofcoin/identity-utils';
|
|
10
|
+
import 'qr-scanner';
|
|
11
|
+
import 'qrcode';
|
|
11
12
|
|
|
12
13
|
const BufferToUint8Array = (data) => {
|
|
13
14
|
if (data.type === 'Buffer') {
|
|
@@ -310,91 +311,6 @@ const nothingFoundError = (hash) => {
|
|
|
310
311
|
return new Error(`nothing found for ${hash}`)
|
|
311
312
|
};
|
|
312
313
|
|
|
313
|
-
class Identity {
|
|
314
|
-
#wallet;
|
|
315
|
-
network;
|
|
316
|
-
id;
|
|
317
|
-
selectedAccount;
|
|
318
|
-
constructor(network) {
|
|
319
|
-
this.network = network;
|
|
320
|
-
}
|
|
321
|
-
get accounts() {
|
|
322
|
-
return this.getAccounts();
|
|
323
|
-
}
|
|
324
|
-
async getAccounts() {
|
|
325
|
-
let accounts = await globalThis.walletStore.get('accounts');
|
|
326
|
-
accounts = new TextDecoder().decode(accounts);
|
|
327
|
-
return JSON.parse(accounts);
|
|
328
|
-
}
|
|
329
|
-
async load(password) {
|
|
330
|
-
if (password && password.includes('.txt')) {
|
|
331
|
-
const { readFile } = await import('fs/promises');
|
|
332
|
-
try {
|
|
333
|
-
password = (await readFile(password)).toString();
|
|
334
|
-
}
|
|
335
|
-
catch (error) {
|
|
336
|
-
console.error(error);
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
if (!password) {
|
|
340
|
-
// @ts-ignore
|
|
341
|
-
const importee = await import('./src/prompts/password.js');
|
|
342
|
-
password = await importee.default();
|
|
343
|
-
}
|
|
344
|
-
const accountExists = await globalThis.accountStore.has('public');
|
|
345
|
-
if (accountExists) {
|
|
346
|
-
const pub = await globalThis.accountStore.get('public');
|
|
347
|
-
this.id = JSON.parse(new TextDecoder().decode(pub)).walletId;
|
|
348
|
-
const selected = await globalThis.walletStore.get('selected-account');
|
|
349
|
-
this.selectedAccount = new TextDecoder().decode(selected);
|
|
350
|
-
}
|
|
351
|
-
else {
|
|
352
|
-
const importee = await import(/* webpackChunkName: "generate-account" */ '@leofcoin/generate-account');
|
|
353
|
-
const { identity, accounts } = await importee.default(password, this.network);
|
|
354
|
-
await globalThis.accountStore.put('public', JSON.stringify({ walletId: identity.walletId }));
|
|
355
|
-
await globalThis.walletStore.put('version', String(1));
|
|
356
|
-
await globalThis.walletStore.put('accounts', JSON.stringify(accounts));
|
|
357
|
-
await globalThis.walletStore.put('selected-account', accounts[0][1]);
|
|
358
|
-
await globalThis.walletStore.put('identity', JSON.stringify(identity));
|
|
359
|
-
this.selectedAccount = accounts[0][1];
|
|
360
|
-
this.id = identity.walletId;
|
|
361
|
-
}
|
|
362
|
-
const identity = JSON.parse(new TextDecoder().decode(await globalThis.walletStore.get('identity')));
|
|
363
|
-
this.#wallet = new MultiWallet(this.network);
|
|
364
|
-
const multiWIF = await decrypt(password, base58.decode(identity.multiWIF));
|
|
365
|
-
await this.#wallet.fromMultiWif(multiWIF);
|
|
366
|
-
}
|
|
367
|
-
selectAccount(account) {
|
|
368
|
-
this.selectedAccount = account;
|
|
369
|
-
return walletStore.put('selected-account', account);
|
|
370
|
-
}
|
|
371
|
-
sign(hash) {
|
|
372
|
-
return this.#wallet.sign(hash.subarray(0, 32));
|
|
373
|
-
}
|
|
374
|
-
lock(password) {
|
|
375
|
-
this.#wallet.lock(password);
|
|
376
|
-
}
|
|
377
|
-
unlock(password) {
|
|
378
|
-
this.#wallet.unlock(password);
|
|
379
|
-
}
|
|
380
|
-
async export(password) {
|
|
381
|
-
return this.#wallet.export(password);
|
|
382
|
-
}
|
|
383
|
-
async import(password, encrypted) {
|
|
384
|
-
await this.#wallet.import(password, encrypted);
|
|
385
|
-
}
|
|
386
|
-
async exportQR(password) {
|
|
387
|
-
const exported = await this.export(password);
|
|
388
|
-
return globalThis.navigator
|
|
389
|
-
? await qrcode.toDataURL(exported)
|
|
390
|
-
: await qrcode.toString(exported, { type: 'terminal' });
|
|
391
|
-
}
|
|
392
|
-
async importQR(image, password) {
|
|
393
|
-
const multiWIF = await QrScanner.default.scanImage(image);
|
|
394
|
-
return this.import(password, multiWIF);
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
|
|
398
314
|
globalThis.LeofcoinStorage = Storage;
|
|
399
315
|
globalThis.leofcoin = globalThis.leofcoin || {};
|
|
400
316
|
globalThis.pubsub = globalThis.pubsub || new PubSub();
|
|
@@ -541,7 +457,7 @@ class Peernet {
|
|
|
541
457
|
this.root = options.root;
|
|
542
458
|
const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile
|
|
543
459
|
// FolderMessageResponse
|
|
544
|
-
} = await import(/* webpackChunkName: "messages" */ './messages-
|
|
460
|
+
} = await import(/* webpackChunkName: "messages" */ './messages-CRhtDipD.js');
|
|
545
461
|
/**
|
|
546
462
|
* proto Object containing protos
|
|
547
463
|
* @type {Object}
|
package/exports/store.js
CHANGED
|
@@ -97,9 +97,9 @@ class Store {
|
|
|
97
97
|
name;
|
|
98
98
|
root;
|
|
99
99
|
version;
|
|
100
|
-
async init(name, root, version) {
|
|
100
|
+
async init(name, root, version, inworker, homedir) {
|
|
101
101
|
this.name = name;
|
|
102
|
-
this.root = await init(root);
|
|
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
105
|
}
|
|
@@ -153,6 +153,13 @@ class Store {
|
|
|
153
153
|
}
|
|
154
154
|
return keys;
|
|
155
155
|
}
|
|
156
|
+
async size() {
|
|
157
|
+
let size = 0;
|
|
158
|
+
for await (const [key, value] of this.db.iterator()) {
|
|
159
|
+
size += value?.length ?? 0;
|
|
160
|
+
}
|
|
161
|
+
return size;
|
|
162
|
+
}
|
|
156
163
|
/**
|
|
157
164
|
*
|
|
158
165
|
* @param {object} options { limit, gt, lt, reverse }
|
|
@@ -8,7 +8,7 @@ export default class Identity {
|
|
|
8
8
|
get accounts(): Promise<[[name: string, externalAddress: string, internalAddress: string]]>;
|
|
9
9
|
getAccounts(): Promise<[[name: string, externalAddress: string, internalAddress: string]]>;
|
|
10
10
|
load(password?: string): Promise<void>;
|
|
11
|
-
selectAccount(account: string): Promise<
|
|
11
|
+
selectAccount(account: string): Promise<unknown>;
|
|
12
12
|
sign(hash: Uint8Array): any;
|
|
13
13
|
lock(password: string): void;
|
|
14
14
|
unlock(password: string): void;
|
|
@@ -71,7 +71,7 @@ export default class Peernet {
|
|
|
71
71
|
get selectedAccount(): string;
|
|
72
72
|
get accounts(): Promise<[[name: string, externalAddress: string, internalAddress: string]]>;
|
|
73
73
|
get defaultStores(): string[];
|
|
74
|
-
selectAccount(account: string): Promise<
|
|
74
|
+
selectAccount(account: string): Promise<unknown>;
|
|
75
75
|
addProto(name: any, proto: any): void;
|
|
76
76
|
addCodec(codec: any): void;
|
|
77
77
|
addStore(name: any, prefix: any, root: any, isPrivate?: boolean): Promise<void>;
|
|
@@ -131,12 +131,12 @@ export default class Peernet {
|
|
|
131
131
|
providersFor(hash: string, store?: undefined): Promise<import("./dht/dht.js").DHTProviderMapValue>;
|
|
132
132
|
get block(): {
|
|
133
133
|
get: (hash: string) => Promise<any>;
|
|
134
|
-
put: (hash: string, data: Uint8Array) => Promise<
|
|
134
|
+
put: (hash: string, data: Uint8Array) => Promise<unknown>;
|
|
135
135
|
has: (hash: string) => Promise<boolean | any[]>;
|
|
136
136
|
};
|
|
137
137
|
get transaction(): {
|
|
138
138
|
get: (hash: string) => Promise<any>;
|
|
139
|
-
put: (hash: string, data: Uint8Array) => Promise<
|
|
139
|
+
put: (hash: string, data: Uint8Array) => Promise<unknown>;
|
|
140
140
|
has: (hash: string) => Promise<boolean | any[]>;
|
|
141
141
|
};
|
|
142
142
|
requestData(hash: any, store: any): any;
|
|
@@ -153,7 +153,7 @@ export default class Peernet {
|
|
|
153
153
|
* @param {String} hash
|
|
154
154
|
* @param {Buffer} message
|
|
155
155
|
*/
|
|
156
|
-
put: (hash: any, message: any) => Promise<
|
|
156
|
+
put: (hash: any, message: any) => Promise<unknown>;
|
|
157
157
|
/**
|
|
158
158
|
* @param {String} hash
|
|
159
159
|
* @return {Boolean}
|
|
@@ -173,7 +173,7 @@ export default class Peernet {
|
|
|
173
173
|
* @param {String} hash
|
|
174
174
|
* @param {Buffer} data
|
|
175
175
|
*/
|
|
176
|
-
put: (hash: any, data: any) => Promise<
|
|
176
|
+
put: (hash: any, data: any) => Promise<unknown>;
|
|
177
177
|
/**
|
|
178
178
|
* @param {String} hash
|
|
179
179
|
* @return {Boolean}
|
|
@@ -193,7 +193,7 @@ export default class Peernet {
|
|
|
193
193
|
* @param {String} hash
|
|
194
194
|
* @param {Buffer} data
|
|
195
195
|
*/
|
|
196
|
-
put: (hash: any, data: any) => Promise<
|
|
196
|
+
put: (hash: any, data: any) => Promise<unknown>;
|
|
197
197
|
/**
|
|
198
198
|
* @param {String} hash
|
|
199
199
|
* @return {Boolean}
|
|
@@ -223,7 +223,7 @@ export default class Peernet {
|
|
|
223
223
|
* @param {Buffer} data
|
|
224
224
|
* @param {String} storeName - storeName to access
|
|
225
225
|
*/
|
|
226
|
-
put(hash: string, data: Uint8Array, storeName?: string | LeofcoinStorageClass): Promise<
|
|
226
|
+
put(hash: string, data: Uint8Array, storeName?: string | LeofcoinStorageClass): Promise<unknown>;
|
|
227
227
|
/**
|
|
228
228
|
* @param {String} hash
|
|
229
229
|
* @return {Boolean}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leofcoin/peernet",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.80",
|
|
4
4
|
"description": "",
|
|
5
5
|
"browser": "./exports/browser/peernet.js",
|
|
6
6
|
"exports": {
|
|
@@ -9,6 +9,11 @@
|
|
|
9
9
|
"require": "./exports/commonjs/peernet.js",
|
|
10
10
|
"types": "./exports/types/peernet.d.ts"
|
|
11
11
|
},
|
|
12
|
+
"./identity": {
|
|
13
|
+
"import": "./exports/identity.js",
|
|
14
|
+
"require": "./exports/commonjs/identity.js",
|
|
15
|
+
"types": "./exports/types/identity.d.ts"
|
|
16
|
+
},
|
|
12
17
|
"./browser": "./exports/browser/peernet.js"
|
|
13
18
|
},
|
|
14
19
|
"type": "module",
|
|
@@ -18,7 +23,7 @@
|
|
|
18
23
|
"scripts": {
|
|
19
24
|
"build": "rollup -c",
|
|
20
25
|
"watch": "rollup -c -w",
|
|
21
|
-
"test": "
|
|
26
|
+
"test": "npx mocha test/peernet.test.ts",
|
|
22
27
|
"server": "discovery-swarm-webrtc --port=4000",
|
|
23
28
|
"demo": "jsproject --serve ./ --port 6868"
|
|
24
29
|
},
|
|
@@ -26,37 +31,41 @@
|
|
|
26
31
|
"author": "",
|
|
27
32
|
"license": "MIT",
|
|
28
33
|
"dependencies": {
|
|
29
|
-
"@leofcoin/codec-format-interface": "^1.
|
|
30
|
-
"@leofcoin/codecs": "^1.0.
|
|
31
|
-
"@leofcoin/generate-account": "^2.0.
|
|
34
|
+
"@leofcoin/codec-format-interface": "^1.7.11",
|
|
35
|
+
"@leofcoin/codecs": "^1.0.6",
|
|
36
|
+
"@leofcoin/generate-account": "^2.0.3",
|
|
32
37
|
"@leofcoin/identity-utils": "^1.0.2",
|
|
33
|
-
"@leofcoin/multi-wallet": "^3.1.
|
|
34
|
-
"@leofcoin/storage": "^3.
|
|
35
|
-
"@netpeer/p2pt-swarm": "^1.3.
|
|
36
|
-
"@netpeer/swarm": "^0.8.
|
|
37
|
-
"@vandeurenglenn/base32": "^1.
|
|
38
|
-
"@vandeurenglenn/base58": "^1.1.
|
|
39
|
-
"@vandeurenglenn/debug": "^1.
|
|
40
|
-
"@vandeurenglenn/is-hex": "^1.
|
|
41
|
-
"@vandeurenglenn/little-pubsub": "^1.
|
|
42
|
-
"inquirer": "^
|
|
38
|
+
"@leofcoin/multi-wallet": "^3.1.8",
|
|
39
|
+
"@leofcoin/storage": "^3.5.32",
|
|
40
|
+
"@netpeer/p2pt-swarm": "^1.3.6",
|
|
41
|
+
"@netpeer/swarm": "^0.8.16",
|
|
42
|
+
"@vandeurenglenn/base32": "^1.2.4",
|
|
43
|
+
"@vandeurenglenn/base58": "^1.1.9",
|
|
44
|
+
"@vandeurenglenn/debug": "^1.2.5",
|
|
45
|
+
"@vandeurenglenn/is-hex": "^1.1.1",
|
|
46
|
+
"@vandeurenglenn/little-pubsub": "^1.5.1",
|
|
47
|
+
"inquirer": "^10.2.2",
|
|
43
48
|
"multi-signature": "^1.3.1",
|
|
44
49
|
"qr-scanner": "^1.4.2",
|
|
45
|
-
"qrcode": "^1.5.
|
|
46
|
-
"socket-request-client": "^2.0.
|
|
47
|
-
"socket-request-server": "^1.6.
|
|
50
|
+
"qrcode": "^1.5.4",
|
|
51
|
+
"socket-request-client": "^2.0.9",
|
|
52
|
+
"socket-request-server": "^1.6.17"
|
|
48
53
|
},
|
|
49
54
|
"devDependencies": {
|
|
50
|
-
"@
|
|
55
|
+
"@jest/globals": "^29.7.0",
|
|
56
|
+
"@rollup/plugin-commonjs": "^26.0.1",
|
|
51
57
|
"@rollup/plugin-json": "^6.1.0",
|
|
52
58
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
53
59
|
"@rollup/plugin-typescript": "^11.1.6",
|
|
54
60
|
"@rollup/plugin-wasm": "^6.2.2",
|
|
55
|
-
"@types/bs58check": "^2.1.
|
|
56
|
-
"@types/node": "^
|
|
57
|
-
"@types/qrcode": "^1.5.
|
|
58
|
-
"@types/secp256k1": "^4.0.
|
|
59
|
-
"@types/varint": "^6.0.
|
|
60
|
-
"
|
|
61
|
+
"@types/bs58check": "^2.1.2",
|
|
62
|
+
"@types/node": "^22.5.5",
|
|
63
|
+
"@types/qrcode": "^1.5.5",
|
|
64
|
+
"@types/secp256k1": "^4.0.6",
|
|
65
|
+
"@types/varint": "^6.0.3",
|
|
66
|
+
"chai": "^5.1.1",
|
|
67
|
+
"cross-env": "^7.0.3",
|
|
68
|
+
"rollup": "^4.21.3",
|
|
69
|
+
"sinon": "^19.0.2"
|
|
61
70
|
}
|
|
62
71
|
}
|
package/rollup.config.js
CHANGED
|
@@ -9,7 +9,7 @@ rimraf.sync('./exports/**')
|
|
|
9
9
|
|
|
10
10
|
export default [
|
|
11
11
|
{
|
|
12
|
-
input: ['./src/peernet.ts', './node_modules/@leofcoin/storage/exports/browser-store.js'],
|
|
12
|
+
input: ['./src/peernet.ts', './src/identity.ts', './node_modules/@leofcoin/storage/exports/browser-store.js'],
|
|
13
13
|
output: {
|
|
14
14
|
format: 'es',
|
|
15
15
|
dir: './exports/browser'
|
|
@@ -31,7 +31,7 @@ export default [
|
|
|
31
31
|
external: ['./prompts/password.js']
|
|
32
32
|
},
|
|
33
33
|
{
|
|
34
|
-
input: ['./src/peernet.ts', './node_modules/@leofcoin/storage/exports/store.js'],
|
|
34
|
+
input: ['./src/peernet.ts', './src/identity.ts', './node_modules/@leofcoin/storage/exports/store.js'],
|
|
35
35
|
output: {
|
|
36
36
|
format: 'es',
|
|
37
37
|
dir: './exports'
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import Peernet from '../exports/peernet.js'
|
|
2
|
+
import Identity from '../exports/identity.js'
|
|
3
|
+
import { expect } from 'chai'
|
|
4
|
+
import sinon from 'sinon'
|
|
5
|
+
import networks from '@leofcoin/networks'
|
|
6
|
+
|
|
7
|
+
const network = networks.leofcoin.peach
|
|
8
|
+
|
|
9
|
+
let options
|
|
10
|
+
let password
|
|
11
|
+
options = {
|
|
12
|
+
network: 'leofcoin:peach',
|
|
13
|
+
stars: network.stars,
|
|
14
|
+
root: '.testnet',
|
|
15
|
+
version: '1.0.0',
|
|
16
|
+
storePrefix: 'test'
|
|
17
|
+
}
|
|
18
|
+
password = 'password'
|
|
19
|
+
const peernet = await new Peernet(options, password)
|
|
20
|
+
|
|
21
|
+
describe('Peernet', async () => {
|
|
22
|
+
// beforeEach(async () => {
|
|
23
|
+
// })
|
|
24
|
+
|
|
25
|
+
it('should initialize with the correct network', () => {
|
|
26
|
+
expect(peernet.network).to.equal('leofcoin:peach')
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('should initialize with the correct version', () => {
|
|
30
|
+
expect(peernet.version).to.equal('1.0.0')
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it('should initialize with the correct store prefix', () => {
|
|
34
|
+
expect(peernet.storePrefix).to.equal('test')
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it('should have an identity instance', () => {
|
|
38
|
+
expect(peernet.identity).to.be.instanceOf(Identity)
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('should have a DHT instance', () => {
|
|
42
|
+
expect(peernet.dht).to.not.be.undefined
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it('should start the client', async () => {
|
|
46
|
+
const startSpy = sinon.spy(peernet, 'start')
|
|
47
|
+
await peernet.start()
|
|
48
|
+
expect(startSpy.calledOnce).to.be.true
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
it('should add a proto', () => {
|
|
52
|
+
const protoName = 'test-proto'
|
|
53
|
+
const proto = {}
|
|
54
|
+
peernet.addProto(protoName, proto)
|
|
55
|
+
expect(globalThis.peernet.protos[protoName]).to.equal(proto)
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
it('should add a codec', () => {
|
|
59
|
+
const codec = { name: 'test-codec' }
|
|
60
|
+
const addCodecSpy = sinon.spy(peernet, 'addCodec')
|
|
61
|
+
peernet.addCodec(codec)
|
|
62
|
+
expect(addCodecSpy.calledOnceWith(codec)).to.be.true
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it('should select an account', async () => {
|
|
66
|
+
const account = 'test-account'
|
|
67
|
+
const selectAccountSpy = sinon.spy(peernet.identity, 'selectAccount')
|
|
68
|
+
await peernet.selectAccount(account)
|
|
69
|
+
expect(selectAccountSpy.calledOnceWith(account)).to.be.true
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it('should prepare a message', () => {
|
|
73
|
+
const data = { message: 'test' }
|
|
74
|
+
const prepareMessageSpy = sinon.spy(peernet._messageHandler, 'prepareMessage')
|
|
75
|
+
peernet.prepareMessage(data)
|
|
76
|
+
expect(prepareMessageSpy.calledOnceWith(data)).to.be.true
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
it('should get peers', () => {
|
|
80
|
+
const peers = peernet.peers
|
|
81
|
+
expect(peers).to.be.an('array')
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
it('should get connections', () => {
|
|
85
|
+
const connections = peernet.connections
|
|
86
|
+
expect(connections).to.be.an('object')
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
it('should get a connection by id', () => {
|
|
90
|
+
const id = 'test-id'
|
|
91
|
+
const connection = peernet.getConnection(id)
|
|
92
|
+
expect(connection).to.be.undefined // Assuming no connections are established in the test
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
// it('should handle DHT', async () => {
|
|
96
|
+
// const peer = {}
|
|
97
|
+
// const id = 'test-id'
|
|
98
|
+
// const proto = { decoded: { hash: 'test-hash', store: 'test-store' } }
|
|
99
|
+
// const handleDHTSpy = sinon.spy(peernet, 'handleDHT')
|
|
100
|
+
// await peernet.handleDHT(peer, id, proto)
|
|
101
|
+
// expect(handleDHTSpy.calledOnceWith(peer, id, proto)).to.be.true
|
|
102
|
+
// })
|
|
103
|
+
|
|
104
|
+
it('should handle data', async () => {
|
|
105
|
+
const peer = {}
|
|
106
|
+
const id = 'test-id'
|
|
107
|
+
const proto = { decoded: { hash: 'test-hash', store: 'test-store' } }
|
|
108
|
+
const handleDataSpy = sinon.spy(peernet, 'handleData')
|
|
109
|
+
await peernet.handleData(peer, id, proto)
|
|
110
|
+
expect(handleDataSpy.calledOnceWith(peer, id, proto)).to.be.true
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
it('should handle request', async () => {
|
|
114
|
+
const peer = {}
|
|
115
|
+
const id = 'test-id'
|
|
116
|
+
const proto = { decoded: { request: 'test-request' } }
|
|
117
|
+
const handleRequestSpy = sinon.spy(peernet, 'handleRequest')
|
|
118
|
+
await peernet.handleRequest(peer, id, proto)
|
|
119
|
+
expect(handleRequestSpy.calledOnceWith(peer, id, proto)).to.be.true
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
it('should walk the network', async () => {
|
|
123
|
+
const hash = 'test-hash'
|
|
124
|
+
const walkSpy = sinon.spy(peernet, 'walk')
|
|
125
|
+
await peernet.walk(hash)
|
|
126
|
+
expect(walkSpy.calledOnceWith(hash)).to.be.true
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
// it('should find providers for a hash', async () => {
|
|
130
|
+
// const hash = 'test-hash'
|
|
131
|
+
// const providers = await peernet.providersFor(hash)
|
|
132
|
+
// expect(providers).to.be.undefined // Assuming no providers are found in the test
|
|
133
|
+
// })
|
|
134
|
+
|
|
135
|
+
// it('should request data', async () => {
|
|
136
|
+
// const hash = 'test-hash'
|
|
137
|
+
// const requestDataSpy = sinon.spy(peernet, 'requestData')
|
|
138
|
+
// await peernet.requestData(hash, 'data')
|
|
139
|
+
// expect(requestDataSpy.calledOnceWith(hash, 'data')).to.be.true
|
|
140
|
+
// })
|
|
141
|
+
|
|
142
|
+
it('should publish data', async () => {
|
|
143
|
+
const topic = 'test-topic'
|
|
144
|
+
const data = 'test-data'
|
|
145
|
+
const publishSpy = sinon.spy(peernet, 'publish')
|
|
146
|
+
await peernet.publish(topic, data)
|
|
147
|
+
expect(publishSpy.calledOnceWith(topic, data)).to.be.true
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
it('should subscribe to a topic', async () => {
|
|
151
|
+
const topic = 'test-topic'
|
|
152
|
+
const callback = sinon.spy()
|
|
153
|
+
const subscribeSpy = sinon.spy(peernet, 'subscribe')
|
|
154
|
+
await peernet.subscribe(topic, callback)
|
|
155
|
+
expect(subscribeSpy.calledOnceWith(topic, callback)).to.be.true
|
|
156
|
+
|
|
157
|
+
process.exit()
|
|
158
|
+
})
|
|
159
|
+
})
|
package/tsconfig.json
CHANGED
|
File without changes
|
/package/exports/browser/{qr-scanner-worker.min-RaSiJc_R.js → qr-scanner-worker.min-Dy0qkKA4.js}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|