@leofcoin/peernet 1.1.56 → 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.
Files changed (34) hide show
  1. package/exports/browser/browser-store.js +4 -3
  2. package/exports/browser/identity.d.ts +18 -0
  3. package/exports/browser/{index-9c85cd32.js → index-329e0324.js} +1 -1
  4. package/exports/browser/messages/chat.d.ts +1 -1
  5. package/exports/browser/messages/data-response.d.ts +1 -1
  6. package/exports/browser/messages/dht-response.d.ts +1 -1
  7. package/exports/browser/messages/dht.d.ts +1 -1
  8. package/exports/browser/messages/peer-response.d.ts +1 -1
  9. package/exports/browser/messages/peer.d.ts +1 -1
  10. package/exports/browser/messages/peernet.d.ts +1 -1
  11. package/exports/browser/messages/ps.d.ts +1 -1
  12. package/exports/browser/messages/request.d.ts +1 -1
  13. package/exports/browser/messages/response.d.ts +1 -1
  14. package/exports/browser/{messages-b66f5393.js → messages-000b7f84.js} +1 -1
  15. package/exports/browser/{peernet-2797014a.js → peernet-bfbe6fff.js} +223 -245
  16. package/exports/browser/peernet.d.ts +31 -13
  17. package/exports/browser/peernet.js +1 -1
  18. package/exports/peernet.js +17 -5
  19. package/exports/store.js +11 -9
  20. package/exports/types/identity.d.ts +18 -0
  21. package/exports/types/messages/chat.d.ts +1 -1
  22. package/exports/types/messages/data-response.d.ts +1 -1
  23. package/exports/types/messages/dht-response.d.ts +1 -1
  24. package/exports/types/messages/dht.d.ts +1 -1
  25. package/exports/types/messages/peer-response.d.ts +1 -1
  26. package/exports/types/messages/peer.d.ts +1 -1
  27. package/exports/types/messages/peernet.d.ts +1 -1
  28. package/exports/types/messages/ps.d.ts +1 -1
  29. package/exports/types/messages/request.d.ts +1 -1
  30. package/exports/types/messages/response.d.ts +1 -1
  31. package/exports/types/peernet.d.ts +31 -13
  32. package/package.json +3 -2
  33. package/src/identity.ts +11 -4
  34. package/src/peernet.ts +26 -3
@@ -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): 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: any, password: any): Promise<Peernet>;
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}
@@ -1,2 +1,2 @@
1
- export { P as default } from './peernet-2797014a.js';
1
+ export { P as default } from './peernet-bfbe6fff.js';
2
2
  import './value-4e80eeeb.js';
@@ -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
- globalThis.peernet.selectedAccount = new TextDecoder().decode(selected);
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
- globalThis.peernet.selectedAccount = accounts[0][1];
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,6 +358,10 @@ 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
  }
@@ -376,7 +382,7 @@ class Identity {
376
382
  return globalThis.navigator ? await qrcode.toDataURL(exported) : await qrcode.toString(exported, { type: 'terminal' });
377
383
  }
378
384
  async importQR(image, password) {
379
- const multiWIF = QrScanner.scanImage(image);
385
+ const multiWIF = await QrScanner.default.scanImage(image);
380
386
  return this.import(password, multiWIF);
381
387
  }
382
388
  }
@@ -456,12 +462,18 @@ class Peernet {
456
462
  get id() {
457
463
  return this.identity.id;
458
464
  }
465
+ get selectedAccount() {
466
+ return this.identity.selectedAccount;
467
+ }
459
468
  get accounts() {
460
469
  return this.identity.accounts;
461
470
  }
462
471
  get defaultStores() {
463
472
  return ['account', 'wallet', 'block', 'transaction', 'chain', 'data', 'message'];
464
473
  }
474
+ selectAccount(account) {
475
+ return this.identity.selectAccount(account);
476
+ }
465
477
  addProto(name, proto) {
466
478
  if (!globalThis.peernet.protos[name])
467
479
  globalThis.peernet.protos[name] = proto;
@@ -507,7 +519,7 @@ class Peernet {
507
519
  * @return {String} id - peerId
508
520
  */
509
521
  getConnection(id) {
510
- return this.client.connections[id];
522
+ return this.connections[id];
511
523
  }
512
524
  /**
513
525
  * @private
@@ -759,7 +771,7 @@ class Peernet {
759
771
  return;
760
772
  return await blockStore.put(hash, data);
761
773
  },
762
- has: async (hash) => await blockStore.has(hash, 'block'),
774
+ has: async (hash) => await blockStore.has(hash),
763
775
  };
764
776
  }
765
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
- let _root = root;
81
- if (home) _root = join(homedir(), root);
82
- if (readdirSync) try {
83
- readdirSync(_root);
84
- } catch (e) {
85
- mkdirp(_root);
86
- }
87
-
88
- return _root
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 {
@@ -0,0 +1,18 @@
1
+ export default class Identity {
2
+ #private;
3
+ network: any;
4
+ id: string;
5
+ selectedAccount: string;
6
+ constructor(network: string);
7
+ get accounts(): Promise<[[name: string, externalAddress: string, internalAddress: string]]>;
8
+ getAccounts(): Promise<[[name: string, externalAddress: string, internalAddress: string]]>;
9
+ load(password?: string): Promise<void>;
10
+ selectAccount(account: string): Promise<void> | Promise<IDBValidKey> | Promise<any[]>;
11
+ sign(hash: Uint8Array): any;
12
+ lock(password: string): void;
13
+ unlock(password: string): void;
14
+ export(password: string): Promise<any>;
15
+ import(password: any, encrypted: base58String): Promise<void>;
16
+ exportQR(password: string): Promise<string>;
17
+ importQR(image: File | Blob, password: string): Promise<void>;
18
+ }
@@ -1,4 +1,4 @@
1
- declare const ChatMessage_base: typeof import("../../node_modules/@leofcoin/codec-format-interface/dist/codec-format-interface.js").default;
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/dist/codec-format-interface.js").default;
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/dist/codec-format-interface.js").default;
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/dist/codec-format-interface.js").default;
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/dist/codec-format-interface.js").default;
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/dist/codec-format-interface.js").default;
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/dist/codec-format-interface.js").default;
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/dist/codec-format-interface.js").default;
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/dist/codec-format-interface.js").default;
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/dist/codec-format-interface.js").default;
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): 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: any, password: any): Promise<Peernet>;
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}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/peernet",
3
- "version": "1.1.56",
3
+ "version": "1.1.57",
4
4
  "description": "",
5
5
  "main": "src/peernet.js",
6
6
  "exports": {
@@ -32,7 +32,7 @@
32
32
  "@leofcoin/codecs": "^1.0.0",
33
33
  "@leofcoin/generate-account": "^2.0.0",
34
34
  "@leofcoin/identity-utils": "^1.0.2",
35
- "@leofcoin/multi-wallet": "^3.1.0",
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: MultiWallet.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
- globalThis.peernet.selectedAccount = new TextDecoder().decode(selected)
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
- globalThis.peernet.selectedAccount = accounts[0][1]
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,6 +65,11 @@ 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
  }
@@ -89,7 +96,7 @@ export default class Identity {
89
96
  }
90
97
 
91
98
  async importQR(image: File | Blob , password: string) {
92
- const multiWIF = QrScanner.scanImage(image)
99
+ const multiWIF = await QrScanner.default.scanImage(image)
93
100
  return this.import(password, multiWIF)
94
101
  }
95
102
  }
package/src/peernet.ts CHANGED
@@ -18,6 +18,19 @@ globalThis.leofcoin = globalThis.leofcoin || {}
18
18
  globalThis.pubsub = globalThis.pubsub || new PubSub()
19
19
  globalThis.globalSub = globalThis.globalSub || new PubSub()
20
20
 
21
+ declare global {
22
+ var LeofcoinStorage: typeof LeofcoinStorageClass
23
+ var peernet: Peernet
24
+ var pubsub: PubSub
25
+ var globalSub: PubSub
26
+ var blockStore: LeofcoinStorageClass
27
+ var transactionStore: LeofcoinStorageClass
28
+ var messageStore: LeofcoinStorageClass
29
+ var dataStore: LeofcoinStorageClass
30
+ var walletStore: LeofcoinStorageClass
31
+ var chainStore: LeofcoinStorageClass
32
+ }
33
+
21
34
  /**
22
35
  * @access public
23
36
  * @example
@@ -95,6 +108,10 @@ export default class Peernet {
95
108
  return this.identity.id
96
109
  }
97
110
 
111
+ get selectedAccount(): string {
112
+ return this.identity.selectedAccount
113
+ }
114
+
98
115
  get accounts(): Promise<[[name: string, externalAddress: string, internalAddress: string]]> {
99
116
  return this.identity.accounts
100
117
  }
@@ -103,6 +120,10 @@ export default class Peernet {
103
120
  return ['account', 'wallet', 'block', 'transaction', 'chain', 'data', 'message']
104
121
  }
105
122
 
123
+ selectAccount(account: string) {
124
+ return this.identity.selectAccount(account)
125
+ }
126
+
106
127
  addProto(name, proto) {
107
128
  if (!globalThis.peernet.protos[name]) globalThis.peernet.protos[name] = proto
108
129
  }
@@ -157,7 +178,7 @@ export default class Peernet {
157
178
  * @return {String} id - peerId
158
179
  */
159
180
  getConnection(id) {
160
- return this.client.connections[id]
181
+ return this.connections[id]
161
182
  }
162
183
 
163
184
  /**
@@ -168,7 +189,7 @@ export default class Peernet {
168
189
  *
169
190
  * @return {Promise} instance of Peernet
170
191
  */
171
- async _init(options, password): Promise<Peernet> {
192
+ async _init(options: {storePrefix?: string, root?: string}, password: string): Promise<Peernet> {
172
193
  this.storePrefix = options.storePrefix
173
194
  this.root = options.root
174
195
 
@@ -452,7 +473,7 @@ export default class Peernet {
452
473
  if (await blockStore.has(hash)) return
453
474
  return await blockStore.put(hash, data)
454
475
  },
455
- has: async (hash: string) => await blockStore.has(hash, 'block'),
476
+ has: async (hash: string) => await blockStore.has(hash),
456
477
  }
457
478
  }
458
479
 
@@ -750,4 +771,6 @@ export default class Peernet {
750
771
  return Buffer
751
772
  }
752
773
  }
774
+
775
+
753
776
  globalThis.Peernet = Peernet