@leofcoin/peernet 1.2.24 → 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.
@@ -1,4 +1,4 @@
1
- import { m as getDefaultExportFromCjs } from './identity-DWchlbmt.js';
1
+ import { m as getDefaultExportFromCjs } from './identity-ChyyZSve.js';
2
2
 
3
3
  function _mergeNamespaces(n, m) {
4
4
  m.forEach(function (e) {
@@ -1,4 +1,4 @@
1
- import { m as getDefaultExportFromCjs } from './identity-DWchlbmt.js';
1
+ import { m as getDefaultExportFromCjs } from './identity-ChyyZSve.js';
2
2
 
3
3
  function _mergeNamespaces(n, m) {
4
4
  m.forEach(function (e) {
@@ -1,5 +1,5 @@
1
- import { L as LittlePubSub, d as deflate_1, i as inflate_1, c as createDebugger } from './peernet-Coi40mR_.js';
2
- import './identity-DWchlbmt.js';
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-BuaFyOQj.js').then(function (n) { return n.b; })).default.w3cwebsocket;
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-BOiH47em.js').then(function (n) { return n.b; });
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-s61gSKAd.js');
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-DWchlbmt.js';
1
+ export { I as default, r as resolveAccountWallets } from './identity-ChyyZSve.js';
2
2
  import 'crypto';
@@ -1,4 +1,4 @@
1
- import { M as MultiWallet, l as encrypt, a as base58$1 } from './identity-DWchlbmt.js';
1
+ import { M as MultiWallet, l as encrypt, a as base58$1 } from './identity-ChyyZSve.js';
2
2
  import 'crypto';
3
3
 
4
4
  /**
@@ -1,5 +1,5 @@
1
- import { F as FormatInterface } from './peernet-Coi40mR_.js';
2
- import './identity-DWchlbmt.js';
1
+ import { F as FormatInterface } from './peernet-DHQj_MFb.js';
2
+ import './identity-ChyyZSve.js';
3
3
  import 'crypto';
4
4
  import './value-C3vAp-wb.js';
5
5
 
@@ -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-DWchlbmt.js';
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-CZ-3jxiD.js');
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-B2wkkpij.js');
8665
+ const importee = await import('./client-U5AYtQje.js');
8666
8666
  /**
8667
8667
  * @access public
8668
8668
  * @type {PeernetClient}
@@ -1,4 +1,4 @@
1
- export { P as default } from './peernet-Coi40mR_.js';
2
- import './identity-DWchlbmt.js';
1
+ export { P as default } from './peernet-DHQj_MFb.js';
2
+ import './identity-ChyyZSve.js';
3
3
  import './value-C3vAp-wb.js';
4
4
  import 'crypto';
@@ -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 {
@@ -65,11 +65,11 @@ class Identity {
65
65
  }
66
66
  if (!password) {
67
67
  // @ts-ignore
68
- const importee = await import('./home/runner/work/peernet/peernet/src/prompts/password.js');
68
+ const importee = await import('./prompts/password.js');
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));
@@ -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;
@@ -105,6 +105,7 @@ export default class Peernet {
105
105
  _init(options: {
106
106
  storePrefix?: string;
107
107
  root?: string;
108
+ freshIdentity?: boolean;
108
109
  }, password: string): Promise<Peernet>;
109
110
  start(): Promise<void>;
110
111
  addRequestHandler(name: any, method: any): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/peernet",
3
- "version": "1.2.24",
3
+ "version": "1.2.26",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",
package/rollup.config.js CHANGED
@@ -27,20 +27,10 @@ const walk = async (dir) => {
27
27
 
28
28
  const isHashedChunk = (runtimePath) => /-[A-Za-z0-9_-]{8,}\.js$/.test(runtimePath)
29
29
 
30
- const normalizeNodePromptImport = () => ({
31
- name: 'normalize-node-prompt-import',
32
- writeBundle: async () => {
33
- const filePath = 'exports/identity.js'
34
- const code = await readFile(filePath, 'utf8')
35
- const normalized = code
36
- .replaceAll("'./src/prompts/password.js'", "'./prompts/password.js'")
37
- .replace(/(["'])\.\/Users\/[^"']*\/src\/prompts\/password\.js\1/g, '$1./prompts/password.js$1')
38
-
39
- if (normalized !== code) {
40
- await writeFile(filePath, normalized)
41
- }
42
- }
43
- })
30
+ const isPromptImport = (id) =>
31
+ id === './prompts/password.js' ||
32
+ id === './src/prompts/password.js' ||
33
+ id.endsWith('/src/prompts/password.js')
44
34
 
45
35
  const runtimeFirstExports = ({ exportsDir = 'exports', declarationsDir = 'exports/types' } = {}) => ({
46
36
  name: 'runtime-first-exports',
@@ -124,7 +114,7 @@ export default [
124
114
  output: {
125
115
  format: 'es',
126
116
  dir: 'exports',
127
- paths: (id) => (id === './src/prompts/password.js' ? './prompts/password.js' : id)
117
+ paths: (id) => (isPromptImport(id) ? './prompts/password.js' : id)
128
118
  },
129
119
  plugins: [
130
120
  typescript({
@@ -132,15 +122,12 @@ export default [
132
122
  outDir: 'exports',
133
123
  declarationDir: 'exports/types'
134
124
  }
135
- }),
136
- normalizeNodePromptImport()
125
+ })
137
126
  ],
138
- external: [
139
- './prompts/password.js',
140
- './src/prompts/password.js',
141
- './prompts/password/browser.js',
142
- './prompts/password/node.js'
143
- ]
127
+ external: (id) =>
128
+ isPromptImport(id) ||
129
+ id === './prompts/password/browser.js' ||
130
+ id === './prompts/password/node.js'
144
131
  },
145
132
  {
146
133
  input: ['./src/prompts/password/browser.js'],
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(options: { storePrefix?: string; root?: string }, password: string): Promise<Peernet> {
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
@@ -1,5 +1,6 @@
1
1
  import test from 'node:test'
2
2
  import assert from 'node:assert/strict'
3
+ import { readFile } from 'node:fs/promises'
3
4
 
4
5
  import Peernet from '../exports/peernet.js'
5
6
  import Identity, { resolveAccountWallets } from '../exports/identity.js'
@@ -18,6 +19,12 @@ const options = {
18
19
  const password = 'password'
19
20
  const peernet = await new Peernet(options, password)
20
21
 
22
+ test('node bundle uses a portable password prompt import', async () => {
23
+ const identityBundle = await readFile(new URL('../exports/identity.js', import.meta.url), 'utf8')
24
+ assert.match(identityBundle, /import\(['"]\.\/prompts\/password\.js['"]\)/)
25
+ assert.doesNotMatch(identityBundle, /(?:\/home\/|\/Users\/|[A-Za-z]:\\)/)
26
+ })
27
+
21
28
  test('initializes with provided options', () => {
22
29
  assert.equal(peernet.network, options.network)
23
30
  assert.equal(peernet.version, options.version)
@@ -28,6 +35,16 @@ test('exposes identity instance', () => {
28
35
  assert.ok(peernet.identity instanceof Identity)
29
36
  })
30
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
+
31
48
  test('has a DHT instance', () => {
32
49
  assert.ok(peernet.dht)
33
50
  })