@leofcoin/peernet 1.2.25 → 1.2.26
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-BOiH47em.js → browser-D-r0O9Qn.js} +1 -1
- package/exports/browser/{browser-BuaFyOQj.js → browser-_hiyXwPp.js} +1 -1
- package/exports/browser/{client-B2wkkpij.js → client-U5AYtQje.js} +4 -4
- package/exports/browser/{identity-DWchlbmt.js → identity-ChyyZSve.js} +7 -3
- package/exports/browser/identity.js +1 -1
- package/exports/browser/{index-s61gSKAd.js → index-BD0Anx7_.js} +1 -1
- package/exports/browser/{messages-CZ-3jxiD.js → messages-Dr5w-bq6.js} +2 -2
- package/exports/browser/{peernet-Coi40mR_.js → peernet-DHQj_MFb.js} +4 -4
- package/exports/browser/peernet.js +2 -2
- package/exports/identity.js +6 -2
- package/exports/peernet.js +1 -1
- package/exports/types/identity.d.ts +1 -1
- package/exports/types/peernet.d.ts +1 -0
- package/package.json +1 -1
- package/src/identity.ts +6 -2
- package/src/peernet.ts +5 -2
- package/test/peernet.test.js +10 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { L as LittlePubSub, d as deflate_1, i as inflate_1, c as createDebugger } from './peernet-
|
|
2
|
-
import './identity-
|
|
1
|
+
import { L as LittlePubSub, d as deflate_1, i as inflate_1, c as createDebugger } from './peernet-DHQj_MFb.js';
|
|
2
|
+
import './identity-ChyyZSve.js';
|
|
3
3
|
import 'crypto';
|
|
4
4
|
import './value-C3vAp-wb.js';
|
|
5
5
|
|
|
@@ -232,7 +232,7 @@ class SocketRequestClient {
|
|
|
232
232
|
const init = async () => {
|
|
233
233
|
// @ts-ignore
|
|
234
234
|
if (!globalThis.WebSocket && !this.#experimentalWebsocket)
|
|
235
|
-
globalThis.WebSocket = (await import('./browser-
|
|
235
|
+
globalThis.WebSocket = (await import('./browser-_hiyXwPp.js').then(function (n) { return n.b; })).default.w3cwebsocket;
|
|
236
236
|
const client = new WebSocket(this.#url, this.#protocol);
|
|
237
237
|
if (this.#experimentalWebsocket) {
|
|
238
238
|
client.addEventListener('error', this.onerror);
|
|
@@ -1303,7 +1303,7 @@ class Client {
|
|
|
1303
1303
|
}
|
|
1304
1304
|
}
|
|
1305
1305
|
async #loadNodeWebrtcImplementation() {
|
|
1306
|
-
const koushWrtcModule = await import('./browser-
|
|
1306
|
+
const koushWrtcModule = await import('./browser-D-r0O9Qn.js').then(function (n) { return n.b; });
|
|
1307
1307
|
const koushWrtc = koushWrtcModule.default;
|
|
1308
1308
|
if (!isWrtcImplementation(koushWrtc)) {
|
|
1309
1309
|
throw new Error('@koush/wrtc does not match required wrtc contract');
|
|
@@ -8308,7 +8308,7 @@ class Identity {
|
|
|
8308
8308
|
accounts = new TextDecoder().decode(accounts);
|
|
8309
8309
|
return JSON.parse(accounts);
|
|
8310
8310
|
}
|
|
8311
|
-
async load(password) {
|
|
8311
|
+
async load(password, fresh = false) {
|
|
8312
8312
|
if (password && password.includes('.txt')) {
|
|
8313
8313
|
const { readFile } = await import('fs/promises');
|
|
8314
8314
|
try {
|
|
@@ -8324,15 +8324,19 @@ class Identity {
|
|
|
8324
8324
|
password = await importee.default();
|
|
8325
8325
|
}
|
|
8326
8326
|
const accountExists = await globalThis.accountStore.has('public');
|
|
8327
|
-
if (accountExists) {
|
|
8327
|
+
if (accountExists && !fresh) {
|
|
8328
8328
|
const pub = await globalThis.accountStore.get('public');
|
|
8329
8329
|
this.id = JSON.parse(new TextDecoder().decode(pub)).walletId;
|
|
8330
8330
|
const selected = await globalThis.walletStore.get('selected-account');
|
|
8331
8331
|
this.selectedAccount = new TextDecoder().decode(selected);
|
|
8332
8332
|
}
|
|
8333
8333
|
else {
|
|
8334
|
-
const importee = await import(/* webpackChunkName: "generate-account" */ './index-
|
|
8334
|
+
const importee = await import(/* webpackChunkName: "generate-account" */ './index-BD0Anx7_.js');
|
|
8335
8335
|
const { identity, accounts } = await importee.default(password, this.network);
|
|
8336
|
+
if (fresh) {
|
|
8337
|
+
await globalThis.accountStore.clear();
|
|
8338
|
+
await globalThis.walletStore.clear();
|
|
8339
|
+
}
|
|
8336
8340
|
await globalThis.accountStore.put('public', JSON.stringify({ walletId: identity.walletId }));
|
|
8337
8341
|
await globalThis.walletStore.put('version', String(1));
|
|
8338
8342
|
await globalThis.walletStore.put('accounts', JSON.stringify(accounts));
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { I as default, r as resolveAccountWallets } from './identity-
|
|
1
|
+
export { I as default, r as resolveAccountWallets } from './identity-ChyyZSve.js';
|
|
2
2
|
import 'crypto';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as index$2, b as base, a as base58$1, c as index$3, d as index$4, e as index$5, f as createSHA512, g as createSHA384, h as createSHA256, j as createSHA224, k as createSHA1, I as Identity } from './identity-
|
|
1
|
+
import { i as index$2, b as base, a as base58$1, c as index$3, d as index$4, e as index$5, f as createSHA512, g as createSHA384, h as createSHA256, j as createSHA224, k as createSHA1, I as Identity } from './identity-ChyyZSve.js';
|
|
2
2
|
import { K as KeyPath, a as KeyValue } from './value-C3vAp-wb.js';
|
|
3
3
|
|
|
4
4
|
const getTargets = () => Array.from([]);
|
|
@@ -8615,7 +8615,7 @@ class Peernet {
|
|
|
8615
8615
|
await getAddress();
|
|
8616
8616
|
this.storePrefix = options.storePrefix;
|
|
8617
8617
|
this.root = options.root;
|
|
8618
|
-
const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile } = await import(/* webpackChunkName: "messages" */ './messages-
|
|
8618
|
+
const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile } = await import(/* webpackChunkName: "messages" */ './messages-Dr5w-bq6.js');
|
|
8619
8619
|
/**
|
|
8620
8620
|
* proto Object containing protos
|
|
8621
8621
|
* @type {Object}
|
|
@@ -8646,7 +8646,7 @@ class Peernet {
|
|
|
8646
8646
|
await this.addStore(store, options.storePrefix, options.root);
|
|
8647
8647
|
}
|
|
8648
8648
|
this.identity = new Identity(this.network);
|
|
8649
|
-
await this.identity.load(password);
|
|
8649
|
+
await this.identity.load(password, options.freshIdentity === true);
|
|
8650
8650
|
this._peerHandler = new PeerDiscovery(this.id);
|
|
8651
8651
|
this.peerId = this.id;
|
|
8652
8652
|
/**
|
|
@@ -8662,7 +8662,7 @@ class Peernet {
|
|
|
8662
8662
|
if (this.#starting || this.#started)
|
|
8663
8663
|
return;
|
|
8664
8664
|
this.#starting = true;
|
|
8665
|
-
const importee = await import('./client-
|
|
8665
|
+
const importee = await import('./client-U5AYtQje.js');
|
|
8666
8666
|
/**
|
|
8667
8667
|
* @access public
|
|
8668
8668
|
* @type {PeernetClient}
|
package/exports/identity.js
CHANGED
|
@@ -53,7 +53,7 @@ class Identity {
|
|
|
53
53
|
accounts = new TextDecoder().decode(accounts);
|
|
54
54
|
return JSON.parse(accounts);
|
|
55
55
|
}
|
|
56
|
-
async load(password) {
|
|
56
|
+
async load(password, fresh = false) {
|
|
57
57
|
if (password && password.includes('.txt')) {
|
|
58
58
|
const { readFile } = await import('fs/promises');
|
|
59
59
|
try {
|
|
@@ -69,7 +69,7 @@ class Identity {
|
|
|
69
69
|
password = await importee.default();
|
|
70
70
|
}
|
|
71
71
|
const accountExists = await globalThis.accountStore.has('public');
|
|
72
|
-
if (accountExists) {
|
|
72
|
+
if (accountExists && !fresh) {
|
|
73
73
|
const pub = await globalThis.accountStore.get('public');
|
|
74
74
|
this.id = JSON.parse(new TextDecoder().decode(pub)).walletId;
|
|
75
75
|
const selected = await globalThis.walletStore.get('selected-account');
|
|
@@ -78,6 +78,10 @@ class Identity {
|
|
|
78
78
|
else {
|
|
79
79
|
const importee = await import(/* webpackChunkName: "generate-account" */ '@leofcoin/generate-account');
|
|
80
80
|
const { identity, accounts } = await importee.default(password, this.network);
|
|
81
|
+
if (fresh) {
|
|
82
|
+
await globalThis.accountStore.clear();
|
|
83
|
+
await globalThis.walletStore.clear();
|
|
84
|
+
}
|
|
81
85
|
await globalThis.accountStore.put('public', JSON.stringify({ walletId: identity.walletId }));
|
|
82
86
|
await globalThis.walletStore.put('version', String(1));
|
|
83
87
|
await globalThis.walletStore.put('accounts', JSON.stringify(accounts));
|
package/exports/peernet.js
CHANGED
|
@@ -487,7 +487,7 @@ class Peernet {
|
|
|
487
487
|
await this.addStore(store, options.storePrefix, options.root);
|
|
488
488
|
}
|
|
489
489
|
this.identity = new Identity(this.network);
|
|
490
|
-
await this.identity.load(password);
|
|
490
|
+
await this.identity.load(password, options.freshIdentity === true);
|
|
491
491
|
this._peerHandler = new PeerDiscovery(this.id);
|
|
492
492
|
this.peerId = this.id;
|
|
493
493
|
/**
|
|
@@ -14,7 +14,7 @@ export default class Identity {
|
|
|
14
14
|
constructor(network: string);
|
|
15
15
|
get accounts(): Promise<[[name: string, externalAddress: string, internalAddress: string]]>;
|
|
16
16
|
getAccounts(): Promise<[[name: string, externalAddress: string, internalAddress: string]]>;
|
|
17
|
-
load(password?: string): Promise<void>;
|
|
17
|
+
load(password?: string, fresh?: boolean): Promise<void>;
|
|
18
18
|
selectAccount(account: string): Promise<unknown>;
|
|
19
19
|
sign(hash: Uint8Array): Promise<Uint8Array<ArrayBufferLike>>;
|
|
20
20
|
lock(password: string): void;
|
package/package.json
CHANGED
package/src/identity.ts
CHANGED
|
@@ -72,7 +72,7 @@ export default class Identity {
|
|
|
72
72
|
return JSON.parse(accounts)
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
async load(password?: string): Promise<void> {
|
|
75
|
+
async load(password?: string, fresh = false): Promise<void> {
|
|
76
76
|
if (password && password.includes('.txt')) {
|
|
77
77
|
const { readFile } = await import('fs/promises')
|
|
78
78
|
try {
|
|
@@ -88,7 +88,7 @@ export default class Identity {
|
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
const accountExists = await globalThis.accountStore.has('public')
|
|
91
|
-
if (accountExists) {
|
|
91
|
+
if (accountExists && !fresh) {
|
|
92
92
|
const pub = await globalThis.accountStore.get('public')
|
|
93
93
|
this.id = JSON.parse(new TextDecoder().decode(pub)).walletId
|
|
94
94
|
const selected = await globalThis.walletStore.get('selected-account')
|
|
@@ -96,6 +96,10 @@ export default class Identity {
|
|
|
96
96
|
} else {
|
|
97
97
|
const importee = await import(/* webpackChunkName: "generate-account" */ '@leofcoin/generate-account')
|
|
98
98
|
const { identity, accounts } = await importee.default(password, this.network)
|
|
99
|
+
if (fresh) {
|
|
100
|
+
await globalThis.accountStore.clear()
|
|
101
|
+
await globalThis.walletStore.clear()
|
|
102
|
+
}
|
|
99
103
|
await globalThis.accountStore.put('public', JSON.stringify({ walletId: identity.walletId }))
|
|
100
104
|
|
|
101
105
|
await globalThis.walletStore.put('version', String(1))
|
package/src/peernet.ts
CHANGED
|
@@ -199,7 +199,10 @@ export default class Peernet {
|
|
|
199
199
|
*
|
|
200
200
|
* @return {Promise} instance of Peernet
|
|
201
201
|
*/
|
|
202
|
-
async _init(
|
|
202
|
+
async _init(
|
|
203
|
+
options: { storePrefix?: string; root?: string; freshIdentity?: boolean },
|
|
204
|
+
password: string
|
|
205
|
+
): Promise<Peernet> {
|
|
203
206
|
await getAddress()
|
|
204
207
|
this.storePrefix = options.storePrefix
|
|
205
208
|
this.root = options.root
|
|
@@ -254,7 +257,7 @@ export default class Peernet {
|
|
|
254
257
|
}
|
|
255
258
|
|
|
256
259
|
this.identity = new Identity(this.network)
|
|
257
|
-
await this.identity.load(password)
|
|
260
|
+
await this.identity.load(password, options.freshIdentity === true)
|
|
258
261
|
|
|
259
262
|
this._peerHandler = new PeerDiscovery(this.id)
|
|
260
263
|
this.peerId = this.id
|
package/test/peernet.test.js
CHANGED
|
@@ -35,6 +35,16 @@ test('exposes identity instance', () => {
|
|
|
35
35
|
assert.ok(peernet.identity instanceof Identity)
|
|
36
36
|
})
|
|
37
37
|
|
|
38
|
+
test('freshIdentity replaces a persisted identity and signer', async () => {
|
|
39
|
+
const originalId = peernet.id
|
|
40
|
+
const originalAccount = peernet.selectedAccount
|
|
41
|
+
const replacement = await new Peernet({ ...options, freshIdentity: true }, password)
|
|
42
|
+
|
|
43
|
+
assert.notEqual(replacement.id, originalId)
|
|
44
|
+
assert.notEqual(replacement.selectedAccount, originalAccount)
|
|
45
|
+
assert.equal(new TextDecoder().decode(await globalThis.walletStore.get('selected-account')), replacement.selectedAccount)
|
|
46
|
+
})
|
|
47
|
+
|
|
38
48
|
test('has a DHT instance', () => {
|
|
39
49
|
assert.ok(peernet.dht)
|
|
40
50
|
})
|