@leofcoin/peernet 1.1.78 → 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-P2HFBJsB.js → browser-DQJ6xf_F.js} +3 -3
- package/exports/browser/browser-store.js +168 -22
- package/exports/browser/{client-5mPwJbpC.js → client-Depp28gl.js} +66 -32
- package/exports/browser/{peernet-x3p3hKA5.js → identity-CQ_ieRiz.js} +2236 -13421
- package/exports/browser/identity.d.ts +1 -1
- package/exports/browser/identity.js +1 -0
- package/exports/browser/{index-fC0k-d_O.js → index-BeqbCwUk.js} +1 -2
- package/exports/browser/{index-00QxgDks.js → index-DqPlTtAJ.js} +7 -9
- package/exports/browser/{messages-rdtq6jgH.js → messages-RYLqPGkg.js} +3 -2
- package/exports/browser/peernet-B7TZP-Wg.js +13220 -0
- package/exports/browser/peernet.d.ts +8 -8
- package/exports/browser/peernet.js +3 -2
- package/exports/identity.js +92 -0
- package/exports/peernet.js +25 -101
- package/exports/store.js +9 -2
- package/exports/types/identity.d.ts +1 -1
- package/exports/types/peernet.d.ts +8 -8
- package/package.json +34 -25
- package/rollup.config.js +2 -2
- package/src/peernet.ts +16 -12
- 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>;
|
|
@@ -108,7 +108,7 @@ export default class Peernet {
|
|
|
108
108
|
addRequestHandler(name: any, method: any): void;
|
|
109
109
|
sendMessage(peer: any, id: any, data: any): Promise<any>;
|
|
110
110
|
handleDHT(peer: any, id: any, proto: any): Promise<void>;
|
|
111
|
-
handleData(peer: any, id: any, proto: any): Promise<
|
|
111
|
+
handleData(peer: any, id: any, proto: any): Promise<any>;
|
|
112
112
|
handleRequest(peer: any, id: any, proto: any): Promise<void>;
|
|
113
113
|
/**
|
|
114
114
|
* @private
|
|
@@ -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}
|
|
@@ -704,18 +620,26 @@ class Peernet {
|
|
|
704
620
|
async handleData(peer, id, proto) {
|
|
705
621
|
let { hash, store } = proto.decoded;
|
|
706
622
|
let data;
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
data
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
623
|
+
try {
|
|
624
|
+
store = globalThis[`${store}Store`] || (await this.whichStore([...this.stores], hash));
|
|
625
|
+
if (store && !store.private) {
|
|
626
|
+
data = await store.get(hash);
|
|
627
|
+
if (data) {
|
|
628
|
+
data = await new globalThis.peernet.protos['peernet-data-response']({
|
|
629
|
+
hash,
|
|
630
|
+
data
|
|
631
|
+
});
|
|
632
|
+
const node = await this.prepareMessage(data);
|
|
633
|
+
this.sendMessage(peer, id, node.encoded);
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
else {
|
|
637
|
+
// ban (trying to access private st)
|
|
717
638
|
}
|
|
718
639
|
}
|
|
640
|
+
catch (error) {
|
|
641
|
+
return this.requestData(hash, store);
|
|
642
|
+
}
|
|
719
643
|
}
|
|
720
644
|
async handleRequest(peer, id, proto) {
|
|
721
645
|
const method = this.requestProtos[proto.decoded.request];
|
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>;
|
|
@@ -108,7 +108,7 @@ export default class Peernet {
|
|
|
108
108
|
addRequestHandler(name: any, method: any): void;
|
|
109
109
|
sendMessage(peer: any, id: any, data: any): Promise<any>;
|
|
110
110
|
handleDHT(peer: any, id: any, proto: any): Promise<void>;
|
|
111
|
-
handleData(peer: any, id: any, proto: any): Promise<
|
|
111
|
+
handleData(peer: any, id: any, proto: any): Promise<any>;
|
|
112
112
|
handleRequest(peer: any, id: any, proto: any): Promise<void>;
|
|
113
113
|
/**
|
|
114
114
|
* @private
|
|
@@ -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'
|
package/src/peernet.ts
CHANGED
|
@@ -390,22 +390,26 @@ export default class Peernet {
|
|
|
390
390
|
async handleData(peer, id, proto) {
|
|
391
391
|
let { hash, store } = proto.decoded
|
|
392
392
|
let data
|
|
393
|
-
|
|
393
|
+
try {
|
|
394
|
+
store = globalThis[`${store}Store`] || (await this.whichStore([...this.stores], hash))
|
|
394
395
|
|
|
395
|
-
|
|
396
|
-
|
|
396
|
+
if (store && !store.private) {
|
|
397
|
+
data = await store.get(hash)
|
|
397
398
|
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
399
|
+
if (data) {
|
|
400
|
+
data = await new globalThis.peernet.protos['peernet-data-response']({
|
|
401
|
+
hash,
|
|
402
|
+
data
|
|
403
|
+
})
|
|
403
404
|
|
|
404
|
-
|
|
405
|
-
|
|
405
|
+
const node = await this.prepareMessage(data)
|
|
406
|
+
this.sendMessage(peer, id, node.encoded)
|
|
407
|
+
}
|
|
408
|
+
} else {
|
|
409
|
+
// ban (trying to access private st)
|
|
406
410
|
}
|
|
407
|
-
}
|
|
408
|
-
|
|
411
|
+
} catch (error) {
|
|
412
|
+
return this.requestData(hash, store)
|
|
409
413
|
}
|
|
410
414
|
}
|
|
411
415
|
|