@leofcoin/peernet 0.18.8 → 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-ae251a9c.js → client-94d84d27.js} +2 -2
- package/exports/browser/{index-72471f52.js → index-5a93c9c3.js} +7 -9
- package/exports/browser/{messages-1f20bad9.js → messages-c820f513.js} +2 -2
- package/exports/browser/{index-769b10c7.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 +90 -31
- 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 +17 -34
- package/src/prompts/password/browser.js +1 -0
- package/src/prompts/password/node.js +6 -0
- package/exports/browser/peernet-34ea081d.js +0 -2999
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { K as KeyValue } from './value-
|
|
1
|
+
import { K as KeyValue } from './value-157ab062.js';
|
|
2
2
|
|
|
3
3
|
const instanceOfAny = (object, constructors) => constructors.some((c) => object instanceof c);
|
|
4
4
|
|
|
@@ -315,149 +315,149 @@ replaceTraps((oldTraps) => ({
|
|
|
315
315
|
},
|
|
316
316
|
}));
|
|
317
317
|
|
|
318
|
-
// import base32 from '@vandeurenglenn/base32'
|
|
319
|
-
// import base58 from '@vandeurenglenn/base58'
|
|
320
|
-
|
|
321
|
-
// export const encodings = {
|
|
322
|
-
// base58,
|
|
323
|
-
// base32
|
|
324
|
-
// }
|
|
325
|
-
|
|
326
|
-
const encode = (string, encoding = 'utf-8') => {
|
|
327
|
-
if (typeof string === 'string') {
|
|
328
|
-
let encoded;
|
|
329
|
-
|
|
330
|
-
// if (encodings[encoding]) encoded = encodings[encoding].encode(encoded)
|
|
331
|
-
encoded = new TextEncoder().encode(string);
|
|
332
|
-
return encoded
|
|
333
|
-
}
|
|
334
|
-
throw Error(`expected typeof String instead got ${string}`)
|
|
335
|
-
};
|
|
336
|
-
|
|
337
|
-
const decode = (uint8Array, encoding) => {
|
|
338
|
-
if (uint8Array instanceof Uint8Array) {
|
|
339
|
-
let decoded;
|
|
340
|
-
// if (encodings[encoding]) decoded = encodings[encoding].decode(decoded)
|
|
341
|
-
decoded = new TextDecoder().decode(uint8Array);
|
|
342
|
-
|
|
343
|
-
return decoded
|
|
344
|
-
}
|
|
345
|
-
throw Error(`expected typeof uint8Array instead got ${uint8Array}`)
|
|
318
|
+
// import base32 from '@vandeurenglenn/base32'
|
|
319
|
+
// import base58 from '@vandeurenglenn/base58'
|
|
320
|
+
|
|
321
|
+
// export const encodings = {
|
|
322
|
+
// base58,
|
|
323
|
+
// base32
|
|
324
|
+
// }
|
|
325
|
+
|
|
326
|
+
const encode = (string, encoding = 'utf-8') => {
|
|
327
|
+
if (typeof string === 'string') {
|
|
328
|
+
let encoded;
|
|
329
|
+
|
|
330
|
+
// if (encodings[encoding]) encoded = encodings[encoding].encode(encoded)
|
|
331
|
+
encoded = new TextEncoder().encode(string);
|
|
332
|
+
return encoded
|
|
333
|
+
}
|
|
334
|
+
throw Error(`expected typeof String instead got ${string}`)
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
const decode = (uint8Array, encoding) => {
|
|
338
|
+
if (uint8Array instanceof Uint8Array) {
|
|
339
|
+
let decoded;
|
|
340
|
+
// if (encodings[encoding]) decoded = encodings[encoding].decode(decoded)
|
|
341
|
+
decoded = new TextDecoder().decode(uint8Array);
|
|
342
|
+
|
|
343
|
+
return decoded
|
|
344
|
+
}
|
|
345
|
+
throw Error(`expected typeof uint8Array instead got ${uint8Array}`)
|
|
346
346
|
};
|
|
347
347
|
|
|
348
|
-
const pathSepS = '/';
|
|
349
|
-
class KeyPath {
|
|
350
|
-
|
|
351
|
-
/**
|
|
352
|
-
* @param {string | Uint8Array} input
|
|
353
|
-
*/
|
|
354
|
-
constructor(input) {
|
|
355
|
-
if (typeof input === 'string') {
|
|
356
|
-
this.uint8Array = encode(input);
|
|
357
|
-
} else if (input instanceof Uint8Array) {
|
|
358
|
-
this.uint8Array = input;
|
|
359
|
-
} else if (input instanceof KeyPath) {
|
|
360
|
-
this.uint8Array = input.uint8Array;
|
|
361
|
-
} else {
|
|
362
|
-
throw new Error('Invalid keyPath, should be a String, Uint8Array or KeyPath')
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
isKeyPath() {
|
|
367
|
-
return true
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
/**
|
|
371
|
-
* Convert to the string representation
|
|
372
|
-
*
|
|
373
|
-
* @param {import('uint8arrays/to-string').SupportedEncodings} [encoding='utf8'] - The encoding to use.
|
|
374
|
-
* @returns {string}
|
|
375
|
-
*/
|
|
376
|
-
toString(encoding = 'hex') {
|
|
377
|
-
return decode(this.uint8Array)
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
/**
|
|
381
|
-
* Returns the `list` representation of this path.
|
|
382
|
-
*
|
|
383
|
-
* @returns string[]
|
|
384
|
-
*
|
|
385
|
-
* @example
|
|
386
|
-
* ```js
|
|
387
|
-
* new Key('/Comedy/MontyPython/Actor:JohnCleese').list()
|
|
388
|
-
* // => ['Comedy', 'MontyPythong', 'Actor:JohnCleese']
|
|
389
|
-
* ```
|
|
390
|
-
*/
|
|
391
|
-
list() {
|
|
392
|
-
return this.toString().split(pathSepS).slice(1)
|
|
393
|
-
}
|
|
394
|
-
|
|
348
|
+
const pathSepS = '/';
|
|
349
|
+
class KeyPath {
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* @param {string | Uint8Array} input
|
|
353
|
+
*/
|
|
354
|
+
constructor(input) {
|
|
355
|
+
if (typeof input === 'string') {
|
|
356
|
+
this.uint8Array = encode(input);
|
|
357
|
+
} else if (input instanceof Uint8Array) {
|
|
358
|
+
this.uint8Array = input;
|
|
359
|
+
} else if (input instanceof KeyPath) {
|
|
360
|
+
this.uint8Array = input.uint8Array;
|
|
361
|
+
} else {
|
|
362
|
+
throw new Error('Invalid keyPath, should be a String, Uint8Array or KeyPath')
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
isKeyPath() {
|
|
367
|
+
return true
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Convert to the string representation
|
|
372
|
+
*
|
|
373
|
+
* @param {import('uint8arrays/to-string').SupportedEncodings} [encoding='utf8'] - The encoding to use.
|
|
374
|
+
* @returns {string}
|
|
375
|
+
*/
|
|
376
|
+
toString(encoding = 'hex') {
|
|
377
|
+
return decode(this.uint8Array)
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Returns the `list` representation of this path.
|
|
382
|
+
*
|
|
383
|
+
* @returns string[]
|
|
384
|
+
*
|
|
385
|
+
* @example
|
|
386
|
+
* ```js
|
|
387
|
+
* new Key('/Comedy/MontyPython/Actor:JohnCleese').list()
|
|
388
|
+
* // => ['Comedy', 'MontyPythong', 'Actor:JohnCleese']
|
|
389
|
+
* ```
|
|
390
|
+
*/
|
|
391
|
+
list() {
|
|
392
|
+
return this.toString().split(pathSepS).slice(1)
|
|
393
|
+
}
|
|
394
|
+
|
|
395
395
|
}
|
|
396
396
|
|
|
397
|
-
class
|
|
398
|
-
constructor(name = 'storage', root = '.leofcoin', version = 1) {
|
|
399
|
-
this.version = version;
|
|
400
|
-
this.name = name;
|
|
401
|
-
this.root = root;
|
|
402
|
-
this.db = openDB(`${root}/${name}`, version, {
|
|
403
|
-
upgrade(db) {
|
|
404
|
-
db.createObjectStore(name);
|
|
405
|
-
}
|
|
406
|
-
});
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
toKeyPath(key) {
|
|
410
|
-
if (!key.isKeyPath()) key = new KeyPath(key);
|
|
411
|
-
return key.toString('base32')
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
toKeyValue(value) {
|
|
415
|
-
if (!value.isKeyValue()) value = new KeyValue(value);
|
|
416
|
-
return value.uint8Array
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
async get(key) {
|
|
420
|
-
return (await this.db).get(this.name, this.toKeyPath(key))
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
async put(key, value) {
|
|
424
|
-
return (await this.db).put(this.name, this.toKeyValue(value), this.toKeyPath(key))
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
async delete(key) {
|
|
428
|
-
return (await this.db).delete(this.name, this.toKeyPath(key))
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
async clear() {
|
|
432
|
-
return (await this.db).clear(this.name)
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
async values(limit = -1) {
|
|
436
|
-
const values = [];
|
|
437
|
-
const tx = (await this.db).transaction(this.name);
|
|
438
|
-
|
|
439
|
-
for await (const cursor of tx.store) {
|
|
440
|
-
values.push(cursor.value);
|
|
441
|
-
if (limit && values.length === limit) return values
|
|
442
|
-
}
|
|
443
|
-
return values
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
async keys(limit = -1) {
|
|
447
|
-
const keys = [];
|
|
448
|
-
const tx = (await this.db).transaction(this.name);
|
|
449
|
-
|
|
450
|
-
for await (const cursor of tx.store) {
|
|
451
|
-
keys.push(cursor.key);
|
|
452
|
-
if (limit && keys.length === limit) return keys
|
|
453
|
-
}
|
|
454
|
-
return keys
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
async iterate() {
|
|
458
|
-
return (await this.db).transaction(this.name).store
|
|
459
|
-
}
|
|
460
|
-
|
|
397
|
+
class BrowerStore {
|
|
398
|
+
constructor(name = 'storage', root = '.leofcoin', version = 1) {
|
|
399
|
+
this.version = version;
|
|
400
|
+
this.name = name;
|
|
401
|
+
this.root = root;
|
|
402
|
+
this.db = openDB(`${root}/${name}`, version, {
|
|
403
|
+
upgrade(db) {
|
|
404
|
+
db.createObjectStore(name);
|
|
405
|
+
}
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
toKeyPath(key) {
|
|
410
|
+
if (!key.isKeyPath()) key = new KeyPath(key);
|
|
411
|
+
return key.toString('base32')
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
toKeyValue(value) {
|
|
415
|
+
if (!value.isKeyValue()) value = new KeyValue(value);
|
|
416
|
+
return value.uint8Array
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
async get(key) {
|
|
420
|
+
return (await this.db).get(this.name, this.toKeyPath(key))
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
async put(key, value) {
|
|
424
|
+
return (await this.db).put(this.name, this.toKeyValue(value), this.toKeyPath(key))
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
async delete(key) {
|
|
428
|
+
return (await this.db).delete(this.name, this.toKeyPath(key))
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
async clear() {
|
|
432
|
+
return (await this.db).clear(this.name)
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
async values(limit = -1) {
|
|
436
|
+
const values = [];
|
|
437
|
+
const tx = (await this.db).transaction(this.name);
|
|
438
|
+
|
|
439
|
+
for await (const cursor of tx.store) {
|
|
440
|
+
values.push(cursor.value);
|
|
441
|
+
if (limit && values.length === limit) return values
|
|
442
|
+
}
|
|
443
|
+
return values
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
async keys(limit = -1) {
|
|
447
|
+
const keys = [];
|
|
448
|
+
const tx = (await this.db).transaction(this.name);
|
|
449
|
+
|
|
450
|
+
for await (const cursor of tx.store) {
|
|
451
|
+
keys.push(cursor.key);
|
|
452
|
+
if (limit && keys.length === limit) return keys
|
|
453
|
+
}
|
|
454
|
+
return keys
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
async iterate() {
|
|
458
|
+
return (await this.db).transaction(this.name).store
|
|
459
|
+
}
|
|
460
|
+
|
|
461
461
|
}
|
|
462
462
|
|
|
463
|
-
export {
|
|
463
|
+
export { BrowerStore as default };
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import MultiWallet from './
|
|
2
|
-
import './
|
|
3
|
-
import './value-40634404.js';
|
|
1
|
+
import { M as MultiWallet } from './peernet-1908438f.js';
|
|
2
|
+
import './value-157ab062.js';
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* @params {String} network
|
|
7
6
|
* @return {object} { identity, accounts, config }
|
|
8
7
|
*/
|
|
9
|
-
var index = async (network) => {
|
|
8
|
+
var index = async (password, network) => {
|
|
9
|
+
if (!password)
|
|
10
|
+
throw new Error('wallets need to be password protected.');
|
|
10
11
|
let wallet = new MultiWallet(network);
|
|
11
12
|
/**
|
|
12
13
|
* @type {string}
|
|
13
14
|
*/
|
|
14
|
-
const mnemonic = await wallet.generate();
|
|
15
|
+
const mnemonic = await wallet.generate(password);
|
|
15
16
|
wallet = new MultiWallet(network);
|
|
16
|
-
await wallet.recover(mnemonic, network);
|
|
17
|
-
console.log(await wallet.address);
|
|
17
|
+
await wallet.recover(mnemonic, password, network);
|
|
18
18
|
/**
|
|
19
19
|
* @type {object}
|
|
20
20
|
*/
|
|
@@ -28,8 +28,6 @@ var index = async (network) => {
|
|
|
28
28
|
walletId: await external.id
|
|
29
29
|
},
|
|
30
30
|
accounts: [['main account', externalAddress, internalAddress]]
|
|
31
|
-
// config: {
|
|
32
|
-
// }
|
|
33
31
|
};
|
|
34
32
|
};
|
|
35
33
|
|