@leofcoin/peernet 1.1.55 → 1.1.57
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-store.js +4 -3
- package/exports/browser/identity.d.ts +7 -4
- package/exports/browser/{index-ba1b3977.js → index-329e0324.js} +1 -1
- package/exports/browser/messages/chat.d.ts +1 -1
- package/exports/browser/messages/data-response.d.ts +1 -1
- package/exports/browser/messages/dht-response.d.ts +1 -1
- package/exports/browser/messages/dht.d.ts +1 -1
- package/exports/browser/messages/peer-response.d.ts +1 -1
- package/exports/browser/messages/peer.d.ts +1 -1
- package/exports/browser/messages/peernet.d.ts +1 -1
- package/exports/browser/messages/ps.d.ts +1 -1
- package/exports/browser/messages/request.d.ts +1 -1
- package/exports/browser/messages/response.d.ts +1 -1
- package/exports/browser/{messages-dd1ad11c.js → messages-000b7f84.js} +1 -1
- package/exports/browser/{peernet-d5023a29.js → peernet-bfbe6fff.js} +943 -884
- package/exports/browser/peernet.d.ts +32 -14
- package/exports/browser/peernet.js +1 -1
- package/exports/peernet.js +26 -12
- package/exports/store.js +11 -9
- package/exports/types/identity.d.ts +7 -4
- package/exports/types/messages/chat.d.ts +1 -1
- package/exports/types/messages/data-response.d.ts +1 -1
- package/exports/types/messages/dht-response.d.ts +1 -1
- package/exports/types/messages/dht.d.ts +1 -1
- package/exports/types/messages/peer-response.d.ts +1 -1
- package/exports/types/messages/peer.d.ts +1 -1
- package/exports/types/messages/peernet.d.ts +1 -1
- package/exports/types/messages/ps.d.ts +1 -1
- package/exports/types/messages/request.d.ts +1 -1
- package/exports/types/messages/response.d.ts +1 -1
- package/exports/types/peernet.d.ts +32 -14
- package/package.json +4 -3
- package/src/identity.ts +21 -10
- package/src/peernet.ts +26 -3
- package/tsconfig.json +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
2
|
import '@vandeurenglenn/debug';
|
|
3
|
+
import PubSub from '@vandeurenglenn/little-pubsub';
|
|
3
4
|
import PeerDiscovery from './discovery/peer-discovery.js';
|
|
4
5
|
import DHT from './dht/dht.js';
|
|
5
6
|
import MessageHandler from './handlers/message.js';
|
|
@@ -7,6 +8,18 @@ import LeofcoinStorageClass from '@leofcoin/storage';
|
|
|
7
8
|
import Identity from './identity.js';
|
|
8
9
|
import swarm from '@netpeer/p2pt-swarm';
|
|
9
10
|
import P2PTPeer from '@netpeer/p2pt-swarm/peer';
|
|
11
|
+
declare global {
|
|
12
|
+
var LeofcoinStorage: typeof LeofcoinStorageClass;
|
|
13
|
+
var peernet: Peernet;
|
|
14
|
+
var pubsub: PubSub;
|
|
15
|
+
var globalSub: PubSub;
|
|
16
|
+
var blockStore: LeofcoinStorageClass;
|
|
17
|
+
var transactionStore: LeofcoinStorageClass;
|
|
18
|
+
var messageStore: LeofcoinStorageClass;
|
|
19
|
+
var dataStore: LeofcoinStorageClass;
|
|
20
|
+
var walletStore: LeofcoinStorageClass;
|
|
21
|
+
var chainStore: LeofcoinStorageClass;
|
|
22
|
+
}
|
|
10
23
|
/**
|
|
11
24
|
* @access public
|
|
12
25
|
* @example
|
|
@@ -54,8 +67,10 @@ export default class Peernet {
|
|
|
54
67
|
*/
|
|
55
68
|
constructor(options: any, password: any);
|
|
56
69
|
get id(): string;
|
|
70
|
+
get selectedAccount(): string;
|
|
57
71
|
get accounts(): Promise<[[name: string, externalAddress: string, internalAddress: string]]>;
|
|
58
72
|
get defaultStores(): string[];
|
|
73
|
+
selectAccount(account: string): Promise<void> | Promise<IDBValidKey> | Promise<any[]>;
|
|
59
74
|
addProto(name: any, proto: any): void;
|
|
60
75
|
addCodec(codec: any): any;
|
|
61
76
|
addStore(name: any, prefix: any, root: any, isPrivate?: boolean): Promise<void>;
|
|
@@ -74,7 +89,7 @@ export default class Peernet {
|
|
|
74
89
|
/**
|
|
75
90
|
* @return {String} id - peerId
|
|
76
91
|
*/
|
|
77
|
-
getConnection(id: any):
|
|
92
|
+
getConnection(id: any): P2PTPeer;
|
|
78
93
|
/**
|
|
79
94
|
* @private
|
|
80
95
|
*
|
|
@@ -83,7 +98,10 @@ export default class Peernet {
|
|
|
83
98
|
*
|
|
84
99
|
* @return {Promise} instance of Peernet
|
|
85
100
|
*/
|
|
86
|
-
_init(options:
|
|
101
|
+
_init(options: {
|
|
102
|
+
storePrefix?: string;
|
|
103
|
+
root?: string;
|
|
104
|
+
}, password: string): Promise<Peernet>;
|
|
87
105
|
start(): Promise<void>;
|
|
88
106
|
addRequestHandler(name: any, method: any): void;
|
|
89
107
|
sendMessage(peer: any, id: any, data: any): Promise<void>;
|
|
@@ -111,13 +129,13 @@ export default class Peernet {
|
|
|
111
129
|
providersFor(hash: string, store?: undefined): Promise<import("./dht/dht.js").DHTProviderMapValue>;
|
|
112
130
|
get block(): {
|
|
113
131
|
get: (hash: string) => Promise<any>;
|
|
114
|
-
put: (hash: string, data: Uint8Array) => Promise<any>;
|
|
115
|
-
has: (hash: string) => Promise<any>;
|
|
132
|
+
put: (hash: string, data: Uint8Array) => Promise<void | any[] | IDBValidKey>;
|
|
133
|
+
has: (hash: string) => Promise<boolean | any[]>;
|
|
116
134
|
};
|
|
117
135
|
get transaction(): {
|
|
118
136
|
get: (hash: string) => Promise<any>;
|
|
119
|
-
put: (hash: string, data: Uint8Array) => Promise<any>;
|
|
120
|
-
has: (hash: string) => Promise<any>;
|
|
137
|
+
put: (hash: string, data: Uint8Array) => Promise<void | any[] | IDBValidKey>;
|
|
138
|
+
has: (hash: string) => Promise<boolean | any[]>;
|
|
121
139
|
};
|
|
122
140
|
requestData(hash: any, store: any): any;
|
|
123
141
|
get message(): {
|
|
@@ -133,12 +151,12 @@ export default class Peernet {
|
|
|
133
151
|
* @param {String} hash
|
|
134
152
|
* @param {Buffer} message
|
|
135
153
|
*/
|
|
136
|
-
put: (hash: any, message: any) => Promise<any>;
|
|
154
|
+
put: (hash: any, message: any) => Promise<void | any[] | IDBValidKey>;
|
|
137
155
|
/**
|
|
138
156
|
* @param {String} hash
|
|
139
157
|
* @return {Boolean}
|
|
140
158
|
*/
|
|
141
|
-
has: (hash: any) => Promise<any>;
|
|
159
|
+
has: (hash: any) => Promise<boolean | any[]>;
|
|
142
160
|
};
|
|
143
161
|
get data(): {
|
|
144
162
|
/**
|
|
@@ -153,12 +171,12 @@ export default class Peernet {
|
|
|
153
171
|
* @param {String} hash
|
|
154
172
|
* @param {Buffer} data
|
|
155
173
|
*/
|
|
156
|
-
put: (hash: any, data: any) => Promise<any>;
|
|
174
|
+
put: (hash: any, data: any) => Promise<void | any[] | IDBValidKey>;
|
|
157
175
|
/**
|
|
158
176
|
* @param {String} hash
|
|
159
177
|
* @return {Boolean}
|
|
160
178
|
*/
|
|
161
|
-
has: (hash: any) => Promise<any>;
|
|
179
|
+
has: (hash: any) => Promise<boolean | any[]>;
|
|
162
180
|
};
|
|
163
181
|
get folder(): {
|
|
164
182
|
/**
|
|
@@ -173,12 +191,12 @@ export default class Peernet {
|
|
|
173
191
|
* @param {String} hash
|
|
174
192
|
* @param {Buffer} data
|
|
175
193
|
*/
|
|
176
|
-
put: (hash: any, data: any) => Promise<any>;
|
|
194
|
+
put: (hash: any, data: any) => Promise<void | any[] | IDBValidKey>;
|
|
177
195
|
/**
|
|
178
196
|
* @param {String} hash
|
|
179
197
|
* @return {Boolean}
|
|
180
198
|
*/
|
|
181
|
-
has: (hash: any) => Promise<any>;
|
|
199
|
+
has: (hash: any) => Promise<boolean | any[]>;
|
|
182
200
|
};
|
|
183
201
|
addFolder(files: any): Promise<any>;
|
|
184
202
|
ls(hash: any, options: any): Promise<any[]>;
|
|
@@ -203,7 +221,7 @@ export default class Peernet {
|
|
|
203
221
|
* @param {Buffer} data
|
|
204
222
|
* @param {String} storeName - storeName to access
|
|
205
223
|
*/
|
|
206
|
-
put(hash: string, data: Uint8Array, storeName?: string | LeofcoinStorageClass): Promise<any>;
|
|
224
|
+
put(hash: string, data: Uint8Array, storeName?: string | LeofcoinStorageClass): Promise<void | any[] | IDBValidKey>;
|
|
207
225
|
/**
|
|
208
226
|
* @param {String} hash
|
|
209
227
|
* @return {Boolean}
|
|
@@ -221,6 +239,6 @@ export default class Peernet {
|
|
|
221
239
|
* @param {Method} cb
|
|
222
240
|
*/
|
|
223
241
|
subscribe(topic: string, callback: Function): Promise<void>;
|
|
224
|
-
removePeer(peer: any): Promise<
|
|
242
|
+
removePeer(peer: any): Promise<boolean>;
|
|
225
243
|
get Buffer(): BufferConstructor;
|
|
226
244
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { P as default } from './peernet-
|
|
1
|
+
export { P as default } from './peernet-bfbe6fff.js';
|
|
2
2
|
import './value-4e80eeeb.js';
|
package/exports/peernet.js
CHANGED
|
@@ -5,7 +5,7 @@ import LeofcoinStorageClass from '@leofcoin/storage';
|
|
|
5
5
|
import { utils } from '@leofcoin/codecs';
|
|
6
6
|
import MultiWallet from '@leofcoin/multi-wallet';
|
|
7
7
|
import base58 from '@vandeurenglenn/base58';
|
|
8
|
-
import { decrypt
|
|
8
|
+
import { decrypt } from '@leofcoin/identity-utils';
|
|
9
9
|
import QrScanner from 'qr-scanner';
|
|
10
10
|
import qrcode from 'qrcode';
|
|
11
11
|
|
|
@@ -308,6 +308,7 @@ class Identity {
|
|
|
308
308
|
#wallet;
|
|
309
309
|
network;
|
|
310
310
|
id;
|
|
311
|
+
selectedAccount;
|
|
311
312
|
constructor(network) {
|
|
312
313
|
this.network = network;
|
|
313
314
|
}
|
|
@@ -330,6 +331,7 @@ class Identity {
|
|
|
330
331
|
}
|
|
331
332
|
}
|
|
332
333
|
if (!password) {
|
|
334
|
+
// @ts-ignore
|
|
333
335
|
const importee = await import('./src/prompts/password.js');
|
|
334
336
|
password = await importee.default();
|
|
335
337
|
}
|
|
@@ -338,7 +340,7 @@ class Identity {
|
|
|
338
340
|
const pub = await globalThis.accountStore.get('public');
|
|
339
341
|
this.id = JSON.parse(new TextDecoder().decode(pub)).walletId;
|
|
340
342
|
const selected = await globalThis.walletStore.get('selected-account');
|
|
341
|
-
|
|
343
|
+
this.selectedAccount = new TextDecoder().decode(selected);
|
|
342
344
|
}
|
|
343
345
|
else {
|
|
344
346
|
const importee = await import(/* webpackChunkName: "generate-account" */ '@leofcoin/generate-account');
|
|
@@ -348,7 +350,7 @@ class Identity {
|
|
|
348
350
|
await globalThis.walletStore.put('accounts', JSON.stringify(accounts));
|
|
349
351
|
await globalThis.walletStore.put('selected-account', accounts[0][1]);
|
|
350
352
|
await globalThis.walletStore.put('identity', JSON.stringify(identity));
|
|
351
|
-
|
|
353
|
+
this.selectedAccount = accounts[0][1];
|
|
352
354
|
this.id = identity.walletId;
|
|
353
355
|
}
|
|
354
356
|
const identity = JSON.parse(new TextDecoder().decode(await globalThis.walletStore.get('identity')));
|
|
@@ -356,25 +358,31 @@ class Identity {
|
|
|
356
358
|
const multiWIF = await decrypt(password, base58.decode(identity.multiWIF));
|
|
357
359
|
await this.#wallet.fromMultiWif(multiWIF);
|
|
358
360
|
}
|
|
361
|
+
selectAccount(account) {
|
|
362
|
+
this.selectedAccount = account;
|
|
363
|
+
return walletStore.put('selected-account', account);
|
|
364
|
+
}
|
|
359
365
|
sign(hash) {
|
|
360
366
|
return this.#wallet.sign(hash.subarray(0, 32));
|
|
361
367
|
}
|
|
368
|
+
lock(password) {
|
|
369
|
+
this.#wallet.lock(password);
|
|
370
|
+
}
|
|
371
|
+
unlock(password) {
|
|
372
|
+
this.#wallet.unlock(password);
|
|
373
|
+
}
|
|
362
374
|
async export(password) {
|
|
363
|
-
|
|
364
|
-
const encypted = await encrypt(password, multiWIF);
|
|
365
|
-
return base58.encode(encypted);
|
|
375
|
+
return this.#wallet.export(password);
|
|
366
376
|
}
|
|
367
377
|
async import(password, encrypted) {
|
|
368
|
-
this.#wallet
|
|
369
|
-
const decrypted = await decrypt(password, base58.decode(encrypted));
|
|
370
|
-
await this.#wallet.fromMultiWif(decrypted);
|
|
378
|
+
await this.#wallet.import(password, encrypted);
|
|
371
379
|
}
|
|
372
380
|
async exportQR(password) {
|
|
373
381
|
const exported = await this.export(password);
|
|
374
382
|
return globalThis.navigator ? await qrcode.toDataURL(exported) : await qrcode.toString(exported, { type: 'terminal' });
|
|
375
383
|
}
|
|
376
384
|
async importQR(image, password) {
|
|
377
|
-
const multiWIF = QrScanner.scanImage(image);
|
|
385
|
+
const multiWIF = await QrScanner.default.scanImage(image);
|
|
378
386
|
return this.import(password, multiWIF);
|
|
379
387
|
}
|
|
380
388
|
}
|
|
@@ -454,12 +462,18 @@ class Peernet {
|
|
|
454
462
|
get id() {
|
|
455
463
|
return this.identity.id;
|
|
456
464
|
}
|
|
465
|
+
get selectedAccount() {
|
|
466
|
+
return this.identity.selectedAccount;
|
|
467
|
+
}
|
|
457
468
|
get accounts() {
|
|
458
469
|
return this.identity.accounts;
|
|
459
470
|
}
|
|
460
471
|
get defaultStores() {
|
|
461
472
|
return ['account', 'wallet', 'block', 'transaction', 'chain', 'data', 'message'];
|
|
462
473
|
}
|
|
474
|
+
selectAccount(account) {
|
|
475
|
+
return this.identity.selectAccount(account);
|
|
476
|
+
}
|
|
463
477
|
addProto(name, proto) {
|
|
464
478
|
if (!globalThis.peernet.protos[name])
|
|
465
479
|
globalThis.peernet.protos[name] = proto;
|
|
@@ -505,7 +519,7 @@ class Peernet {
|
|
|
505
519
|
* @return {String} id - peerId
|
|
506
520
|
*/
|
|
507
521
|
getConnection(id) {
|
|
508
|
-
return this.
|
|
522
|
+
return this.connections[id];
|
|
509
523
|
}
|
|
510
524
|
/**
|
|
511
525
|
* @private
|
|
@@ -757,7 +771,7 @@ class Peernet {
|
|
|
757
771
|
return;
|
|
758
772
|
return await blockStore.put(hash, data);
|
|
759
773
|
},
|
|
760
|
-
has: async (hash) => await blockStore.has(hash
|
|
774
|
+
has: async (hash) => await blockStore.has(hash),
|
|
761
775
|
};
|
|
762
776
|
}
|
|
763
777
|
get transaction() {
|
package/exports/store.js
CHANGED
|
@@ -77,15 +77,17 @@ class KeyValue {
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
const init = (root, home = true) => {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
readdirSync
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
80
|
+
let _root = root;
|
|
81
|
+
if (home)
|
|
82
|
+
_root = join(homedir(), root);
|
|
83
|
+
if (readdirSync)
|
|
84
|
+
try {
|
|
85
|
+
readdirSync(_root);
|
|
86
|
+
}
|
|
87
|
+
catch (e) {
|
|
88
|
+
mkdirp(_root);
|
|
89
|
+
}
|
|
90
|
+
return _root;
|
|
89
91
|
};
|
|
90
92
|
|
|
91
93
|
class Store {
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
import MultiWallet from '@leofcoin/multi-wallet';
|
|
2
1
|
export default class Identity {
|
|
3
2
|
#private;
|
|
4
|
-
network:
|
|
3
|
+
network: any;
|
|
5
4
|
id: string;
|
|
5
|
+
selectedAccount: string;
|
|
6
6
|
constructor(network: string);
|
|
7
7
|
get accounts(): Promise<[[name: string, externalAddress: string, internalAddress: string]]>;
|
|
8
8
|
getAccounts(): Promise<[[name: string, externalAddress: string, internalAddress: string]]>;
|
|
9
9
|
load(password?: string): Promise<void>;
|
|
10
|
+
selectAccount(account: string): Promise<void> | Promise<IDBValidKey> | Promise<any[]>;
|
|
10
11
|
sign(hash: Uint8Array): any;
|
|
11
|
-
|
|
12
|
+
lock(password: string): void;
|
|
13
|
+
unlock(password: string): void;
|
|
14
|
+
export(password: string): Promise<any>;
|
|
12
15
|
import(password: any, encrypted: base58String): Promise<void>;
|
|
13
|
-
exportQR(password: string): Promise<
|
|
16
|
+
exportQR(password: string): Promise<string>;
|
|
14
17
|
importQR(image: File | Blob, password: string): Promise<void>;
|
|
15
18
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare const ChatMessage_base: typeof import("../../node_modules/@leofcoin/codec-format-interface/
|
|
1
|
+
declare const ChatMessage_base: typeof import("../../node_modules/@leofcoin/codec-format-interface/exports/codec-format-interface.js").default;
|
|
2
2
|
export default class ChatMessage extends ChatMessage_base {
|
|
3
3
|
constructor(buffer: any);
|
|
4
4
|
get messageName(): string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare const DataMessageResponse_base: typeof import("../../node_modules/@leofcoin/codec-format-interface/
|
|
1
|
+
declare const DataMessageResponse_base: typeof import("../../node_modules/@leofcoin/codec-format-interface/exports/codec-format-interface.js").default;
|
|
2
2
|
export default class DataMessageResponse extends DataMessageResponse_base {
|
|
3
3
|
constructor(data: any);
|
|
4
4
|
get messageName(): string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare const DHTMessageResponse_base: typeof import("../../node_modules/@leofcoin/codec-format-interface/
|
|
1
|
+
declare const DHTMessageResponse_base: typeof import("../../node_modules/@leofcoin/codec-format-interface/exports/codec-format-interface.js").default;
|
|
2
2
|
export default class DHTMessageResponse extends DHTMessageResponse_base {
|
|
3
3
|
constructor(data: any);
|
|
4
4
|
get messageName(): string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare const DHTMessage_base: typeof import("../../node_modules/@leofcoin/codec-format-interface/
|
|
1
|
+
declare const DHTMessage_base: typeof import("../../node_modules/@leofcoin/codec-format-interface/exports/codec-format-interface.js").default;
|
|
2
2
|
/**
|
|
3
3
|
* @example `
|
|
4
4
|
new DHTMessage(hash, store)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare const PeerMessageResponse_base: typeof import("../../node_modules/@leofcoin/codec-format-interface/
|
|
1
|
+
declare const PeerMessageResponse_base: typeof import("../../node_modules/@leofcoin/codec-format-interface/exports/codec-format-interface.js").default;
|
|
2
2
|
export default class PeerMessageResponse extends PeerMessageResponse_base {
|
|
3
3
|
constructor(data: any);
|
|
4
4
|
get messageName(): string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare const PeerMessage_base: typeof import("../../node_modules/@leofcoin/codec-format-interface/
|
|
1
|
+
declare const PeerMessage_base: typeof import("../../node_modules/@leofcoin/codec-format-interface/exports/codec-format-interface.js").default;
|
|
2
2
|
export default class PeerMessage extends PeerMessage_base {
|
|
3
3
|
constructor(data: any);
|
|
4
4
|
get messageName(): string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare const PeernetMessage_base: typeof import("../../node_modules/@leofcoin/codec-format-interface/
|
|
1
|
+
declare const PeernetMessage_base: typeof import("../../node_modules/@leofcoin/codec-format-interface/exports/codec-format-interface.js").default;
|
|
2
2
|
export default class PeernetMessage extends PeernetMessage_base {
|
|
3
3
|
constructor(buffer: any);
|
|
4
4
|
get messageName(): string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare const PsMessage_base: typeof import("../../node_modules/@leofcoin/codec-format-interface/
|
|
1
|
+
declare const PsMessage_base: typeof import("../../node_modules/@leofcoin/codec-format-interface/exports/codec-format-interface.js").default;
|
|
2
2
|
export default class PsMessage extends PsMessage_base {
|
|
3
3
|
constructor(buffer: any);
|
|
4
4
|
get messageName(): string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare const RequestMessage_base: typeof import("../../node_modules/@leofcoin/codec-format-interface/
|
|
1
|
+
declare const RequestMessage_base: typeof import("../../node_modules/@leofcoin/codec-format-interface/exports/codec-format-interface.js").default;
|
|
2
2
|
export default class RequestMessage extends RequestMessage_base {
|
|
3
3
|
constructor(data: any);
|
|
4
4
|
get messageName(): string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare const ResponseMessage_base: typeof import("../../node_modules/@leofcoin/codec-format-interface/
|
|
1
|
+
declare const ResponseMessage_base: typeof import("../../node_modules/@leofcoin/codec-format-interface/exports/codec-format-interface.js").default;
|
|
2
2
|
export default class ResponseMessage extends ResponseMessage_base {
|
|
3
3
|
constructor(data: any);
|
|
4
4
|
get messageName(): string;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
2
|
import '@vandeurenglenn/debug';
|
|
3
|
+
import PubSub from '@vandeurenglenn/little-pubsub';
|
|
3
4
|
import PeerDiscovery from './discovery/peer-discovery.js';
|
|
4
5
|
import DHT from './dht/dht.js';
|
|
5
6
|
import MessageHandler from './handlers/message.js';
|
|
@@ -7,6 +8,18 @@ import LeofcoinStorageClass from '@leofcoin/storage';
|
|
|
7
8
|
import Identity from './identity.js';
|
|
8
9
|
import swarm from '@netpeer/p2pt-swarm';
|
|
9
10
|
import P2PTPeer from '@netpeer/p2pt-swarm/peer';
|
|
11
|
+
declare global {
|
|
12
|
+
var LeofcoinStorage: typeof LeofcoinStorageClass;
|
|
13
|
+
var peernet: Peernet;
|
|
14
|
+
var pubsub: PubSub;
|
|
15
|
+
var globalSub: PubSub;
|
|
16
|
+
var blockStore: LeofcoinStorageClass;
|
|
17
|
+
var transactionStore: LeofcoinStorageClass;
|
|
18
|
+
var messageStore: LeofcoinStorageClass;
|
|
19
|
+
var dataStore: LeofcoinStorageClass;
|
|
20
|
+
var walletStore: LeofcoinStorageClass;
|
|
21
|
+
var chainStore: LeofcoinStorageClass;
|
|
22
|
+
}
|
|
10
23
|
/**
|
|
11
24
|
* @access public
|
|
12
25
|
* @example
|
|
@@ -54,8 +67,10 @@ export default class Peernet {
|
|
|
54
67
|
*/
|
|
55
68
|
constructor(options: any, password: any);
|
|
56
69
|
get id(): string;
|
|
70
|
+
get selectedAccount(): string;
|
|
57
71
|
get accounts(): Promise<[[name: string, externalAddress: string, internalAddress: string]]>;
|
|
58
72
|
get defaultStores(): string[];
|
|
73
|
+
selectAccount(account: string): Promise<void> | Promise<IDBValidKey> | Promise<any[]>;
|
|
59
74
|
addProto(name: any, proto: any): void;
|
|
60
75
|
addCodec(codec: any): any;
|
|
61
76
|
addStore(name: any, prefix: any, root: any, isPrivate?: boolean): Promise<void>;
|
|
@@ -74,7 +89,7 @@ export default class Peernet {
|
|
|
74
89
|
/**
|
|
75
90
|
* @return {String} id - peerId
|
|
76
91
|
*/
|
|
77
|
-
getConnection(id: any):
|
|
92
|
+
getConnection(id: any): P2PTPeer;
|
|
78
93
|
/**
|
|
79
94
|
* @private
|
|
80
95
|
*
|
|
@@ -83,7 +98,10 @@ export default class Peernet {
|
|
|
83
98
|
*
|
|
84
99
|
* @return {Promise} instance of Peernet
|
|
85
100
|
*/
|
|
86
|
-
_init(options:
|
|
101
|
+
_init(options: {
|
|
102
|
+
storePrefix?: string;
|
|
103
|
+
root?: string;
|
|
104
|
+
}, password: string): Promise<Peernet>;
|
|
87
105
|
start(): Promise<void>;
|
|
88
106
|
addRequestHandler(name: any, method: any): void;
|
|
89
107
|
sendMessage(peer: any, id: any, data: any): Promise<void>;
|
|
@@ -111,13 +129,13 @@ export default class Peernet {
|
|
|
111
129
|
providersFor(hash: string, store?: undefined): Promise<import("./dht/dht.js").DHTProviderMapValue>;
|
|
112
130
|
get block(): {
|
|
113
131
|
get: (hash: string) => Promise<any>;
|
|
114
|
-
put: (hash: string, data: Uint8Array) => Promise<any>;
|
|
115
|
-
has: (hash: string) => Promise<any>;
|
|
132
|
+
put: (hash: string, data: Uint8Array) => Promise<void | any[] | IDBValidKey>;
|
|
133
|
+
has: (hash: string) => Promise<boolean | any[]>;
|
|
116
134
|
};
|
|
117
135
|
get transaction(): {
|
|
118
136
|
get: (hash: string) => Promise<any>;
|
|
119
|
-
put: (hash: string, data: Uint8Array) => Promise<any>;
|
|
120
|
-
has: (hash: string) => Promise<any>;
|
|
137
|
+
put: (hash: string, data: Uint8Array) => Promise<void | any[] | IDBValidKey>;
|
|
138
|
+
has: (hash: string) => Promise<boolean | any[]>;
|
|
121
139
|
};
|
|
122
140
|
requestData(hash: any, store: any): any;
|
|
123
141
|
get message(): {
|
|
@@ -133,12 +151,12 @@ export default class Peernet {
|
|
|
133
151
|
* @param {String} hash
|
|
134
152
|
* @param {Buffer} message
|
|
135
153
|
*/
|
|
136
|
-
put: (hash: any, message: any) => Promise<any>;
|
|
154
|
+
put: (hash: any, message: any) => Promise<void | any[] | IDBValidKey>;
|
|
137
155
|
/**
|
|
138
156
|
* @param {String} hash
|
|
139
157
|
* @return {Boolean}
|
|
140
158
|
*/
|
|
141
|
-
has: (hash: any) => Promise<any>;
|
|
159
|
+
has: (hash: any) => Promise<boolean | any[]>;
|
|
142
160
|
};
|
|
143
161
|
get data(): {
|
|
144
162
|
/**
|
|
@@ -153,12 +171,12 @@ export default class Peernet {
|
|
|
153
171
|
* @param {String} hash
|
|
154
172
|
* @param {Buffer} data
|
|
155
173
|
*/
|
|
156
|
-
put: (hash: any, data: any) => Promise<any>;
|
|
174
|
+
put: (hash: any, data: any) => Promise<void | any[] | IDBValidKey>;
|
|
157
175
|
/**
|
|
158
176
|
* @param {String} hash
|
|
159
177
|
* @return {Boolean}
|
|
160
178
|
*/
|
|
161
|
-
has: (hash: any) => Promise<any>;
|
|
179
|
+
has: (hash: any) => Promise<boolean | any[]>;
|
|
162
180
|
};
|
|
163
181
|
get folder(): {
|
|
164
182
|
/**
|
|
@@ -173,12 +191,12 @@ export default class Peernet {
|
|
|
173
191
|
* @param {String} hash
|
|
174
192
|
* @param {Buffer} data
|
|
175
193
|
*/
|
|
176
|
-
put: (hash: any, data: any) => Promise<any>;
|
|
194
|
+
put: (hash: any, data: any) => Promise<void | any[] | IDBValidKey>;
|
|
177
195
|
/**
|
|
178
196
|
* @param {String} hash
|
|
179
197
|
* @return {Boolean}
|
|
180
198
|
*/
|
|
181
|
-
has: (hash: any) => Promise<any>;
|
|
199
|
+
has: (hash: any) => Promise<boolean | any[]>;
|
|
182
200
|
};
|
|
183
201
|
addFolder(files: any): Promise<any>;
|
|
184
202
|
ls(hash: any, options: any): Promise<any[]>;
|
|
@@ -203,7 +221,7 @@ export default class Peernet {
|
|
|
203
221
|
* @param {Buffer} data
|
|
204
222
|
* @param {String} storeName - storeName to access
|
|
205
223
|
*/
|
|
206
|
-
put(hash: string, data: Uint8Array, storeName?: string | LeofcoinStorageClass): Promise<any>;
|
|
224
|
+
put(hash: string, data: Uint8Array, storeName?: string | LeofcoinStorageClass): Promise<void | any[] | IDBValidKey>;
|
|
207
225
|
/**
|
|
208
226
|
* @param {String} hash
|
|
209
227
|
* @return {Boolean}
|
|
@@ -221,6 +239,6 @@ export default class Peernet {
|
|
|
221
239
|
* @param {Method} cb
|
|
222
240
|
*/
|
|
223
241
|
subscribe(topic: string, callback: Function): Promise<void>;
|
|
224
|
-
removePeer(peer: any): Promise<
|
|
242
|
+
removePeer(peer: any): Promise<boolean>;
|
|
225
243
|
get Buffer(): BufferConstructor;
|
|
226
244
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leofcoin/peernet",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.57",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src/peernet.js",
|
|
6
6
|
"exports": {
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"@leofcoin/codec-format-interface": "^1.6.0",
|
|
32
32
|
"@leofcoin/codecs": "^1.0.0",
|
|
33
33
|
"@leofcoin/generate-account": "^2.0.0",
|
|
34
|
-
"@leofcoin/identity-utils": "^1.0.
|
|
35
|
-
"@leofcoin/multi-wallet": "^3.
|
|
34
|
+
"@leofcoin/identity-utils": "^1.0.2",
|
|
35
|
+
"@leofcoin/multi-wallet": "^3.1.4",
|
|
36
36
|
"@leofcoin/peernet-swarm": "^1.1.0",
|
|
37
37
|
"@leofcoin/storage": "^3.0.0",
|
|
38
38
|
"@netpeer/p2pt-swarm": "^1.3.2",
|
|
@@ -56,6 +56,7 @@
|
|
|
56
56
|
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
57
57
|
"@rollup/plugin-wasm": "^6.1.1",
|
|
58
58
|
"@types/bs58check": "^2.1.0",
|
|
59
|
+
"@types/qrcode": "^1.5.2",
|
|
59
60
|
"@types/secp256k1": "^4.0.3",
|
|
60
61
|
"@types/varint": "^6.0.1",
|
|
61
62
|
"browserify": "^17.0.0",
|
package/src/identity.ts
CHANGED
|
@@ -6,8 +6,9 @@ import qrcode from 'qrcode'
|
|
|
6
6
|
|
|
7
7
|
export default class Identity {
|
|
8
8
|
#wallet: MultiWallet
|
|
9
|
-
network
|
|
9
|
+
network
|
|
10
10
|
id: string
|
|
11
|
+
selectedAccount: string
|
|
11
12
|
|
|
12
13
|
constructor(network: string) {
|
|
13
14
|
this.network = network
|
|
@@ -34,6 +35,7 @@ export default class Identity {
|
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
37
|
if (!password) {
|
|
38
|
+
// @ts-ignore
|
|
37
39
|
const importee: { default: () => Promise<string> } = await import('./prompts/password.js')
|
|
38
40
|
password = await importee.default()
|
|
39
41
|
}
|
|
@@ -43,7 +45,7 @@ export default class Identity {
|
|
|
43
45
|
const pub = await globalThis.accountStore.get('public')
|
|
44
46
|
this.id = JSON.parse(new TextDecoder().decode(pub)).walletId;
|
|
45
47
|
const selected = await globalThis.walletStore.get('selected-account')
|
|
46
|
-
|
|
48
|
+
this.selectedAccount = new TextDecoder().decode(selected)
|
|
47
49
|
} else {
|
|
48
50
|
const importee = await import(/* webpackChunkName: "generate-account" */ '@leofcoin/generate-account')
|
|
49
51
|
const {identity, accounts} = await importee.default(password, this.network)
|
|
@@ -54,7 +56,7 @@ export default class Identity {
|
|
|
54
56
|
await globalThis.walletStore.put('selected-account', accounts[0][1])
|
|
55
57
|
await globalThis.walletStore.put('identity', JSON.stringify(identity))
|
|
56
58
|
|
|
57
|
-
|
|
59
|
+
this.selectedAccount = accounts[0][1]
|
|
58
60
|
this.id = identity.walletId
|
|
59
61
|
}
|
|
60
62
|
const identity = JSON.parse(new TextDecoder().decode(await globalThis.walletStore.get('identity')))
|
|
@@ -63,20 +65,29 @@ export default class Identity {
|
|
|
63
65
|
await this.#wallet.fromMultiWif(multiWIF)
|
|
64
66
|
}
|
|
65
67
|
|
|
68
|
+
selectAccount(account: string) {
|
|
69
|
+
this.selectedAccount = account
|
|
70
|
+
return walletStore.put('selected-account', account)
|
|
71
|
+
}
|
|
72
|
+
|
|
66
73
|
sign(hash: Uint8Array) {
|
|
67
74
|
return this.#wallet.sign(hash.subarray(0, 32))
|
|
68
75
|
}
|
|
69
76
|
|
|
77
|
+
lock(password: string) {
|
|
78
|
+
this.#wallet.lock(password)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
unlock(password: string) {
|
|
82
|
+
this.#wallet.unlock(password)
|
|
83
|
+
}
|
|
84
|
+
|
|
70
85
|
async export(password: string) {
|
|
71
|
-
|
|
72
|
-
const encypted = await encrypt(password, multiWIF)
|
|
73
|
-
return base58.encode(encypted)
|
|
86
|
+
return this.#wallet.export(password)
|
|
74
87
|
}
|
|
75
88
|
|
|
76
89
|
async import(password, encrypted: base58String) {
|
|
77
|
-
this.#wallet
|
|
78
|
-
const decrypted = await decrypt(password, base58.decode(encrypted))
|
|
79
|
-
await this.#wallet.fromMultiWif(decrypted)
|
|
90
|
+
await this.#wallet.import(password, encrypted)
|
|
80
91
|
}
|
|
81
92
|
|
|
82
93
|
async exportQR(password: string) {
|
|
@@ -85,7 +96,7 @@ export default class Identity {
|
|
|
85
96
|
}
|
|
86
97
|
|
|
87
98
|
async importQR(image: File | Blob , password: string) {
|
|
88
|
-
const multiWIF = QrScanner.scanImage(image)
|
|
99
|
+
const multiWIF = await QrScanner.default.scanImage(image)
|
|
89
100
|
return this.import(password, multiWIF)
|
|
90
101
|
}
|
|
91
102
|
}
|