@leofcoin/peernet 0.18.7 → 1.0.0
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 +141 -141
- package/exports/browser/browser.js +3 -0
- package/exports/browser/{client-4e947338.js → client-94d84d27.js} +2 -2
- package/exports/browser/{index-9f9f4d27.js → index-5a93c9c3.js} +7 -9
- package/exports/browser/{messages-d87e15a0.js → messages-c820f513.js} +2 -2
- package/exports/browser/{index-f3625c4a.js → peernet-1908438f.js} +3413 -317
- package/exports/browser/peernet.js +2 -2
- package/exports/browser/prompts/password/browser.d.ts +2 -0
- package/exports/browser/prompts/password/node.d.ts +2 -0
- package/exports/browser/{value-40634404.js → value-157ab062.js} +59 -59
- package/exports/node.js +8 -0
- package/exports/peernet.js +91 -33
- package/exports/prompts/password/browser.d.ts +2 -0
- package/exports/prompts/password/node.d.ts +2 -0
- package/exports/store.js +210 -212
- package/package.json +3 -2
- package/rollup.config.js +8 -2
- package/src/handlers/message.js +2 -9
- package/src/identity.ts +93 -0
- package/src/peernet.ts +18 -36
- package/src/prompts/password/browser.js +1 -0
- package/src/prompts/password/node.js +6 -0
- package/exports/browser/peernet-29c659a0.js +0 -3000
package/src/peernet.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { encapsulatedError, dhtError,
|
|
|
10
10
|
|
|
11
11
|
import LeofcoinStorage from '@leofcoin/storage'
|
|
12
12
|
import { utils as codecUtils } from '@leofcoin/codecs'
|
|
13
|
+
import Identity from './identity.js'
|
|
13
14
|
globalThis.LeofcoinStorage = LeofcoinStorage
|
|
14
15
|
|
|
15
16
|
globalThis.leofcoin = globalThis.leofcoin || {}
|
|
@@ -21,6 +22,7 @@ globalThis.globalSub = globalThis.globalSub || new PubSub(true)
|
|
|
21
22
|
* const peernet = new Peernet();
|
|
22
23
|
*/
|
|
23
24
|
export default class Peernet {
|
|
25
|
+
identity: Identity
|
|
24
26
|
stores: [] = []
|
|
25
27
|
/**
|
|
26
28
|
* @type {Object}
|
|
@@ -54,7 +56,7 @@ export default class Peernet {
|
|
|
54
56
|
* @example
|
|
55
57
|
* const peernet = new Peernet({network: 'leofcoin', root: '.leofcoin'});
|
|
56
58
|
*/
|
|
57
|
-
constructor(options: options) {
|
|
59
|
+
constructor(options: options, password) {
|
|
58
60
|
/**
|
|
59
61
|
* @property {String} network - current network
|
|
60
62
|
*/
|
|
@@ -74,7 +76,15 @@ export default class Peernet {
|
|
|
74
76
|
up: 0,
|
|
75
77
|
down: 0,
|
|
76
78
|
}
|
|
77
|
-
return this._init(options)
|
|
79
|
+
return this._init(options, password)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
get id() {
|
|
83
|
+
return this.identity.id
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
get accounts(): Promise<[[name: string, externalAddress: string, internalAddress: string]]> {
|
|
87
|
+
return this.identity.accounts
|
|
78
88
|
}
|
|
79
89
|
|
|
80
90
|
get defaultStores() {
|
|
@@ -146,7 +156,7 @@ export default class Peernet {
|
|
|
146
156
|
*
|
|
147
157
|
* @return {Promise} instance of Peernet
|
|
148
158
|
*/
|
|
149
|
-
async _init(options) {
|
|
159
|
+
async _init(options, password) {
|
|
150
160
|
this.requestProtos = {}
|
|
151
161
|
this.storePrefix = options.storePrefix
|
|
152
162
|
this.root = options.root
|
|
@@ -201,37 +211,10 @@ export default class Peernet {
|
|
|
201
211
|
await this.addStore(store, options.storePrefix, options.root)
|
|
202
212
|
}
|
|
203
213
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
let accounts = await walletStore.get('accounts')
|
|
209
|
-
accounts = new TextDecoder().decode(accounts)
|
|
210
|
-
const selected = await walletStore.get('selected-account')
|
|
211
|
-
globalThis.peernet.selectedAccount = new TextDecoder().decode(selected)
|
|
212
|
-
|
|
213
|
-
// fixing account issue (string while needs to be a JSON)
|
|
214
|
-
// TODO: remove when on mainnet
|
|
215
|
-
try {
|
|
216
|
-
this.accounts = JSON.parse(accounts)
|
|
217
|
-
} catch {
|
|
218
|
-
this.accounts = [accounts.split(',')]
|
|
219
|
-
}
|
|
220
|
-
} else {
|
|
221
|
-
const importee = await import(/* webpackChunkName: "generate-account" */ '@leofcoin/generate-account')
|
|
222
|
-
const generateAccount = importee.default
|
|
223
|
-
const {identity, accounts, config} = await generateAccount(this.network)
|
|
224
|
-
// await accountStore.put('config', JSON.stringify(config));
|
|
225
|
-
await accountStore.put('public', JSON.stringify({walletId: identity.walletId}));
|
|
226
|
-
|
|
227
|
-
await walletStore.put('version', String(1))
|
|
228
|
-
await walletStore.put('accounts', JSON.stringify(accounts))
|
|
229
|
-
await walletStore.put('selected-account', accounts[0][1])
|
|
230
|
-
await walletStore.put('identity', JSON.stringify(identity))
|
|
231
|
-
|
|
232
|
-
globalThis.peernet.selectedAccount = accounts[0][1]
|
|
233
|
-
this.id = identity.walletId
|
|
234
|
-
}
|
|
214
|
+
this.identity = new Identity(this.network)
|
|
215
|
+
await this.identity.load(password)
|
|
216
|
+
|
|
217
|
+
|
|
235
218
|
this._peerHandler = new PeerDiscovery(this.id)
|
|
236
219
|
this.peerId = this.id
|
|
237
220
|
|
|
@@ -344,7 +327,7 @@ export default class Peernet {
|
|
|
344
327
|
this.handleDHT(peer, id, proto)
|
|
345
328
|
break
|
|
346
329
|
}
|
|
347
|
-
case '
|
|
330
|
+
case 'peernet-data': {
|
|
348
331
|
this.handleData(peer, id, proto)
|
|
349
332
|
break
|
|
350
333
|
}
|
|
@@ -480,7 +463,6 @@ export default class Peernet {
|
|
|
480
463
|
})
|
|
481
464
|
if (closest[0]) data = await closest[0].request(node.encoded)
|
|
482
465
|
}
|
|
483
|
-
data = new Uint8Array(Object.values(data))
|
|
484
466
|
const proto = await protoFor(data)
|
|
485
467
|
// TODO: store data automaticly or not
|
|
486
468
|
return BufferToUint8Array(proto.decoded.data)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default async () => prompt('enter password')
|