@leofcoin/peernet 1.1.79 → 1.1.81
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/.esdoc.json +10 -10
- package/.gitattributes +2 -2
- package/.prettierrc +7 -7
- package/.travis.yml +27 -27
- package/BREAKING_CHANGES.md +34 -34
- package/LICENSE +21 -21
- package/README.md +72 -72
- package/deploy.js +8 -8
- 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-C0VVXIWm.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-CEwkDK9g.js} +10 -489
- package/exports/browser/{messages-lzTD4EMU.js → messages-BdevLRCA.js} +167 -166
- package/exports/browser/peernet-DEIKLS2i.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/{messages-T3M-Ff1E.js → messages-BmpgEM4y.js} +163 -163
- package/exports/peernet.js +189 -273
- package/exports/src/prompts/password.js +3 -3
- package/exports/store.js +9 -2
- package/exports/types/identity.d.ts +1 -1
- package/exports/types/peernet.d.ts +7 -7
- package/index.html +19 -19
- package/package.json +71 -62
- package/rollup.config.js +63 -63
- package/src/dht/dht.ts +147 -147
- package/src/discovery/peer-discovery.js +75 -75
- package/src/errors/errors.js +12 -12
- package/src/handlers/data.js +15 -15
- package/src/handlers/message.js +34 -34
- package/src/identity.ts +104 -104
- package/src/messages/chat.js +13 -13
- package/src/messages/data-response.js +13 -13
- package/src/messages/data.js +17 -17
- package/src/messages/dht-response.js +13 -13
- package/src/messages/dht.js +21 -21
- package/src/messages/file-link.js +17 -17
- package/src/messages/file.js +17 -17
- package/src/messages/peer-response.js +13 -13
- package/src/messages/peer.js +13 -13
- package/src/messages/peernet.js +13 -13
- package/src/messages/ps.js +13 -13
- package/src/messages/request.js +13 -13
- package/src/messages/response.js +13 -13
- package/src/messages.js +13 -13
- package/src/peer-info.js +9 -9
- package/src/peernet.ts +817 -817
- package/src/prompts/password/browser.js +1 -1
- package/src/prompts/password/node.js +6 -6
- package/src/proto/chat-message.proto.js +6 -6
- package/src/proto/data-response.proto.js +4 -4
- package/src/proto/data.proto.js +4 -4
- package/src/proto/dht-response.proto.js +4 -4
- package/src/proto/dht.proto.js +4 -4
- package/src/proto/file-link.proto.js +5 -5
- package/src/proto/file.proto.js +5 -5
- package/src/proto/peer-response.proto.js +3 -3
- package/src/proto/peer.proto.js +3 -3
- package/src/proto/peernet.proto.js +7 -7
- package/src/proto/ps.proto.js +4 -4
- package/src/proto/request.proto.js +4 -4
- package/src/proto/response.proto.js +3 -3
- package/src/types.ts +25 -25
- package/src/utils/utils.js +77 -77
- package/test/client.js +14 -14
- package/test/codec.js +56 -56
- package/test/hash.js +13 -13
- package/test/index.js +3 -3
- package/test/lastBlock.js +7 -7
- package/test/messages.js +26 -26
- package/test/peernet.js +17 -17
- package/test/peernet.test.js +159 -0
- package/test.js +62 -62
- package/test2.js +13 -13
- package/test3.js +15 -15
- package/test4.js +7 -7
- package/tsconfig.json +11 -13
- /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/peernet.js
CHANGED
|
@@ -3,146 +3,147 @@ 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
|
-
const BufferToUint8Array = (data) => {
|
|
13
|
-
if (data.type === 'Buffer') {
|
|
14
|
-
data = new Uint8Array(data.data);
|
|
15
|
-
}
|
|
16
|
-
return data
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const protoFor = (message) => {
|
|
20
|
-
const codec = new Codec(message);
|
|
21
|
-
if (!codec.name) throw new Error(`proto not found ${message}`)
|
|
22
|
-
const Proto = globalThis.peernet.protos[codec.name];
|
|
23
|
-
if (!Proto) throw new Error(`No proto defined for ${codec.name}`)
|
|
24
|
-
return new Proto(message)
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* wether or not a peernet daemon is active
|
|
29
|
-
* @return {Boolean}
|
|
30
|
-
*/
|
|
31
|
-
const hasDaemon = async () => {
|
|
32
|
-
try {
|
|
33
|
-
let response = await fetch('http://127.0.0.1:1000/api/version');
|
|
34
|
-
response = await response.json();
|
|
35
|
-
return Boolean(response.client === '@peernet/api/http')
|
|
36
|
-
} catch (e) {
|
|
37
|
-
return false
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const https = () => {
|
|
42
|
-
if (!globalThis.location) return false
|
|
43
|
-
return Boolean(globalThis.location.protocol === 'https:')
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Get current environment
|
|
48
|
-
* @return {String} current environment [node, electron, browser]
|
|
49
|
-
*/
|
|
50
|
-
const environment = () => {
|
|
51
|
-
const _navigator = globalThis.navigator;
|
|
52
|
-
if (!_navigator) {
|
|
53
|
-
return 'node'
|
|
54
|
-
} else if (_navigator && /electron/i.test(_navigator.userAgent)) {
|
|
55
|
-
return 'electron'
|
|
56
|
-
} else {
|
|
57
|
-
return 'browser'
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* * Get current environment
|
|
63
|
-
* @return {Object} result
|
|
64
|
-
* @property {Boolean} reult.daemon whether or not daemon is running
|
|
65
|
-
* @property {Boolean} reult.environment Current environment
|
|
66
|
-
*/
|
|
67
|
-
const target = async () => {
|
|
68
|
-
let daemon = false;
|
|
69
|
-
if (!https()) daemon = await hasDaemon();
|
|
70
|
-
|
|
71
|
-
return { daemon, environment: environment() }
|
|
13
|
+
const BufferToUint8Array = (data) => {
|
|
14
|
+
if (data.type === 'Buffer') {
|
|
15
|
+
data = new Uint8Array(data.data);
|
|
16
|
+
}
|
|
17
|
+
return data
|
|
72
18
|
};
|
|
73
19
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
return
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
if (
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
20
|
+
const protoFor = (message) => {
|
|
21
|
+
const codec = new Codec(message);
|
|
22
|
+
if (!codec.name) throw new Error(`proto not found ${message}`)
|
|
23
|
+
const Proto = globalThis.peernet.protos[codec.name];
|
|
24
|
+
if (!Proto) throw new Error(`No proto defined for ${codec.name}`)
|
|
25
|
+
return new Proto(message)
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* wether or not a peernet daemon is active
|
|
30
|
+
* @return {Boolean}
|
|
31
|
+
*/
|
|
32
|
+
const hasDaemon = async () => {
|
|
33
|
+
try {
|
|
34
|
+
let response = await fetch('http://127.0.0.1:1000/api/version');
|
|
35
|
+
response = await response.json();
|
|
36
|
+
return Boolean(response.client === '@peernet/api/http')
|
|
37
|
+
} catch (e) {
|
|
38
|
+
return false
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const https = () => {
|
|
43
|
+
if (!globalThis.location) return false
|
|
44
|
+
return Boolean(globalThis.location.protocol === 'https:')
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Get current environment
|
|
49
|
+
* @return {String} current environment [node, electron, browser]
|
|
50
|
+
*/
|
|
51
|
+
const environment = () => {
|
|
52
|
+
const _navigator = globalThis.navigator;
|
|
53
|
+
if (!_navigator) {
|
|
54
|
+
return 'node'
|
|
55
|
+
} else if (_navigator && /electron/i.test(_navigator.userAgent)) {
|
|
56
|
+
return 'electron'
|
|
57
|
+
} else {
|
|
58
|
+
return 'browser'
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* * Get current environment
|
|
64
|
+
* @return {Object} result
|
|
65
|
+
* @property {Boolean} reult.daemon whether or not daemon is running
|
|
66
|
+
* @property {Boolean} reult.environment Current environment
|
|
67
|
+
*/
|
|
68
|
+
const target = async () => {
|
|
69
|
+
let daemon = false;
|
|
70
|
+
if (!https()) daemon = await hasDaemon();
|
|
71
|
+
|
|
72
|
+
return { daemon, environment: environment() }
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
class PeerDiscovery {
|
|
76
|
+
constructor(id) {
|
|
77
|
+
this.id = id;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
_getPeerId(id) {
|
|
81
|
+
if (!peernet.peerMap || (peernet.peerMap && peernet.peerMap.size === 0)) return false
|
|
82
|
+
|
|
83
|
+
for (const entry of [...peernet.peerMap.entries()]) {
|
|
84
|
+
for (const _id of entry[1]) {
|
|
85
|
+
if (_id === id) return entry[0]
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async discover(peer) {
|
|
91
|
+
let id = this._getPeerId(peer.id);
|
|
92
|
+
if (id) return id
|
|
93
|
+
const data = await new peernet.protos['peernet-peer']({ id: this.id });
|
|
94
|
+
const node = await peernet.prepareMessage(peer.id, data.encoded);
|
|
95
|
+
|
|
96
|
+
let response = await peer.request(node.encoded);
|
|
97
|
+
response = await protoFor(response);
|
|
98
|
+
response = await new peernet.protos['peernet-peer-response'](response.decoded.data);
|
|
99
|
+
|
|
100
|
+
id = response.decoded.id;
|
|
101
|
+
if (id === this.id) return
|
|
102
|
+
|
|
103
|
+
if (!peernet.peerMap.has(id)) peernet.peerMap.set(id, [peer.id]);
|
|
104
|
+
else {
|
|
105
|
+
const connections = peernet.peerMap.get(id);
|
|
106
|
+
if (connections.indexOf(peer.id) === -1) {
|
|
107
|
+
connections.push(peer.id);
|
|
108
|
+
peernet.peerMap.set(peer.id, connections);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return id
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async discoverHandler(message, peer) {
|
|
115
|
+
const { id, proto } = message;
|
|
116
|
+
// if (typeof message.data === 'string') message.data = Buffer.from(message.data)
|
|
117
|
+
if (proto.name === 'peernet-peer') {
|
|
118
|
+
const from = proto.decoded.id;
|
|
119
|
+
if (from === this.id) return
|
|
120
|
+
|
|
121
|
+
if (!peernet.peerMap.has(from)) peernet.peerMap.set(from, [peer.id]);
|
|
122
|
+
else {
|
|
123
|
+
const connections = peernet.peerMap.get(from);
|
|
124
|
+
if (connections.indexOf(peer.id) === -1) {
|
|
125
|
+
connections.push(peer.id);
|
|
126
|
+
peernet.peerMap.set(from, connections);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
const data = await new peernet.protos['peernet-peer-response']({ id: this.id });
|
|
130
|
+
const node = await peernet.prepareMessage(from, data.encoded);
|
|
131
|
+
|
|
132
|
+
peer.write(Buffer.from(JSON.stringify({ id, data: node.encoded })));
|
|
133
|
+
} else if (proto.name === 'peernet-peer-response') {
|
|
134
|
+
const from = proto.decoded.id;
|
|
135
|
+
if (from === this.id) return
|
|
136
|
+
|
|
137
|
+
if (!peernet.peerMap.has(from)) peernet.peerMap.set(from, [peer.id]);
|
|
138
|
+
else {
|
|
139
|
+
const connections = peernet.peerMap.get(from);
|
|
140
|
+
if (connections.indexOf(peer.id) === -1) {
|
|
141
|
+
connections.push(peer.id);
|
|
142
|
+
peernet.peerMap.set(from, connections);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
146
147
|
}
|
|
147
148
|
|
|
148
149
|
/**
|
|
@@ -254,146 +255,61 @@ class DhtEarth {
|
|
|
254
255
|
}
|
|
255
256
|
}
|
|
256
257
|
|
|
257
|
-
class MessageHandler {
|
|
258
|
-
constructor(network) {
|
|
259
|
-
this.network = network;
|
|
260
|
-
}
|
|
261
|
-
/**
|
|
262
|
-
* hash and sign message
|
|
263
|
-
*
|
|
264
|
-
* @param {object} message
|
|
265
|
-
* @param {Buffer} message.from peer id
|
|
266
|
-
* @param {Buffer} message.to peer id
|
|
267
|
-
* @param {string} message.data Peernet message
|
|
268
|
-
* (PeernetMessage excluded) encoded as a string
|
|
269
|
-
* @return message
|
|
270
|
-
*/
|
|
271
|
-
async hashAndSignMessage(message) {
|
|
272
|
-
const hash = await message.peernetHash;
|
|
273
|
-
message.decoded.signature = globalThis.identity.sign(hash.buffer);
|
|
274
|
-
return message
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
/**
|
|
278
|
-
* @param {String} from - peer id
|
|
279
|
-
* @param {String} to - peer id
|
|
280
|
-
* @param {String|PeernetMessage} data - data encoded message string
|
|
281
|
-
* or the messageNode itself
|
|
282
|
-
*/
|
|
283
|
-
async prepareMessage(message) {
|
|
284
|
-
if (message.keys.includes('signature')) {
|
|
285
|
-
message = await this.hashAndSignMessage(message);
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
return message
|
|
289
|
-
}
|
|
258
|
+
class MessageHandler {
|
|
259
|
+
constructor(network) {
|
|
260
|
+
this.network = network;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* hash and sign message
|
|
264
|
+
*
|
|
265
|
+
* @param {object} message
|
|
266
|
+
* @param {Buffer} message.from peer id
|
|
267
|
+
* @param {Buffer} message.to peer id
|
|
268
|
+
* @param {string} message.data Peernet message
|
|
269
|
+
* (PeernetMessage excluded) encoded as a string
|
|
270
|
+
* @return message
|
|
271
|
+
*/
|
|
272
|
+
async hashAndSignMessage(message) {
|
|
273
|
+
const hash = await message.peernetHash;
|
|
274
|
+
message.decoded.signature = globalThis.identity.sign(hash.buffer);
|
|
275
|
+
return message
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* @param {String} from - peer id
|
|
280
|
+
* @param {String} to - peer id
|
|
281
|
+
* @param {String|PeernetMessage} data - data encoded message string
|
|
282
|
+
* or the messageNode itself
|
|
283
|
+
*/
|
|
284
|
+
async prepareMessage(message) {
|
|
285
|
+
if (message.keys.includes('signature')) {
|
|
286
|
+
message = await this.hashAndSignMessage(message);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
return message
|
|
290
|
+
}
|
|
290
291
|
}
|
|
291
292
|
|
|
292
|
-
const dataHandler = async (message) => {
|
|
293
|
-
if (!message) return
|
|
294
|
-
|
|
295
|
-
try {
|
|
296
|
-
const { data, id, from, peer } = message;
|
|
297
|
-
const proto = await protoFor(data);
|
|
298
|
-
peernet._protoHandler({ id, proto }, peernet.connections[from] || peer, from);
|
|
299
|
-
} catch (error) {
|
|
300
|
-
console.error(error);
|
|
301
|
-
}
|
|
293
|
+
const dataHandler = async (message) => {
|
|
294
|
+
if (!message) return
|
|
295
|
+
|
|
296
|
+
try {
|
|
297
|
+
const { data, id, from, peer } = message;
|
|
298
|
+
const proto = await protoFor(data);
|
|
299
|
+
peernet._protoHandler({ id, proto }, peernet.connections[from] || peer, from);
|
|
300
|
+
} catch (error) {
|
|
301
|
+
console.error(error);
|
|
302
|
+
}
|
|
302
303
|
};
|
|
303
304
|
|
|
304
|
-
const dhtError = (proto) => {
|
|
305
|
-
const text = `Received proto ${proto.name} expected peernet-dht-response`;
|
|
306
|
-
return new Error(`Routing error: ${text}`)
|
|
307
|
-
};
|
|
308
|
-
|
|
309
|
-
const nothingFoundError = (hash) => {
|
|
310
|
-
return new Error(`nothing found for ${hash}`)
|
|
305
|
+
const dhtError = (proto) => {
|
|
306
|
+
const text = `Received proto ${proto.name} expected peernet-dht-response`;
|
|
307
|
+
return new Error(`Routing error: ${text}`)
|
|
311
308
|
};
|
|
312
309
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
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
|
-
}
|
|
310
|
+
const nothingFoundError = (hash) => {
|
|
311
|
+
return new Error(`nothing found for ${hash}`)
|
|
312
|
+
};
|
|
397
313
|
|
|
398
314
|
globalThis.LeofcoinStorage = Storage;
|
|
399
315
|
globalThis.leofcoin = globalThis.leofcoin || {};
|
|
@@ -517,7 +433,7 @@ class Peernet {
|
|
|
517
433
|
* @return {Array} peerId
|
|
518
434
|
*/
|
|
519
435
|
get peers() {
|
|
520
|
-
return Object.entries(this.client?.connections);
|
|
436
|
+
return Object.entries(this.client?.connections || {});
|
|
521
437
|
}
|
|
522
438
|
get connections() {
|
|
523
439
|
return this.client?.connections || {};
|
|
@@ -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-BmpgEM4y.js');
|
|
545
461
|
/**
|
|
546
462
|
* proto Object containing protos
|
|
547
463
|
* @type {Object}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import inquirer from 'inquirer';
|
|
2
2
|
|
|
3
|
-
var node = async () => {
|
|
4
|
-
const answers = await inquirer.prompt({ type: 'password', name: 'password', message: 'Enter password' });
|
|
5
|
-
return answers.password
|
|
3
|
+
var node = async () => {
|
|
4
|
+
const answers = await inquirer.prompt({ type: 'password', name: 'password', message: 'Enter password' });
|
|
5
|
+
return answers.password
|
|
6
6
|
};
|
|
7
7
|
|
|
8
8
|
export { node as default };
|
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/index.html
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en" dir="ltr">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8">
|
|
5
|
-
<title></title>
|
|
6
|
-
</head>
|
|
7
|
-
<body>
|
|
8
|
-
<!-- <script src="./dist/browser/peernet.js">
|
|
9
|
-
</script> -->
|
|
10
|
-
|
|
11
|
-
<script type="module">
|
|
12
|
-
import './exports/browser/peernet.js';
|
|
13
|
-
(async () => {
|
|
14
|
-
const peernet = await new Peernet({network: 'leofcoin:peach', networkVersion: 'peach'})
|
|
15
|
-
peernet.addRequestHandler('lastBlock', () => new peernet.protos['peernet-response']({response: new TextEncoder().encode(100)}))
|
|
16
|
-
})()
|
|
17
|
-
</script>
|
|
18
|
-
</body>
|
|
19
|
-
</html>
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en" dir="ltr">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<title></title>
|
|
6
|
+
</head>
|
|
7
|
+
<body>
|
|
8
|
+
<!-- <script src="./dist/browser/peernet.js">
|
|
9
|
+
</script> -->
|
|
10
|
+
|
|
11
|
+
<script type="module">
|
|
12
|
+
import './exports/browser/peernet.js';
|
|
13
|
+
(async () => {
|
|
14
|
+
const peernet = await new Peernet({network: 'leofcoin:peach', networkVersion: 'peach'})
|
|
15
|
+
peernet.addRequestHandler('lastBlock', () => new peernet.protos['peernet-response']({response: new TextEncoder().encode(100)}))
|
|
16
|
+
})()
|
|
17
|
+
</script>
|
|
18
|
+
</body>
|
|
19
|
+
</html>
|