@leofcoin/peernet 1.2.21 → 1.2.23
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-8BFql6K9.js → browser-BKlRwB0A.js} +1 -1
- package/exports/browser/{browser-FVp_QbaL.js → browser-Dx3X9MHO.js} +1 -1
- package/exports/browser/{client-lPe0SUWx.js → client-eYBPUrVq.js} +19 -14
- package/exports/browser/{identity-BeVZQ2Dp.js → identity-BS_eDrwh.js} +1830 -1806
- package/exports/browser/identity.js +1 -1
- package/exports/browser/{index-D6qd-AUn.js → index-B91mcwxm.js} +1 -1
- package/exports/browser/{messages-BfDvXW-x.js → messages-D0Goitr6.js} +2 -2
- package/exports/browser/{peernet-DFiLLjUD.js → peernet-CgU-ZdIe.js} +154 -82
- package/exports/browser/peernet.js +2 -2
- package/exports/identity.js +25 -1
- package/exports/peernet.js +5 -1
- package/exports/store.js +3 -0
- package/exports/types/identity.d.ts +1 -1
- package/exports/types/peernet.d.ts +2 -0
- package/package.json +4 -3
- package/src/identity.ts +30 -1
- package/src/peernet.ts +5 -1
- package/test/peernet.test.js +11 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leofcoin/peernet",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.23",
|
|
4
4
|
"description": "",
|
|
5
5
|
"browser": "./exports/browser/peernet.js",
|
|
6
6
|
"exports": {
|
|
@@ -107,7 +107,7 @@
|
|
|
107
107
|
"@leofcoin/multi-wallet": "^3.1.8",
|
|
108
108
|
"@leofcoin/storage": "^3.5.38",
|
|
109
109
|
"@mapbox/node-pre-gyp": "^2.0.3",
|
|
110
|
-
"@netpeer/swarm": "^0.9.
|
|
110
|
+
"@netpeer/swarm": "^0.9.9",
|
|
111
111
|
"@vandeurenglenn/base58": "^1.1.9",
|
|
112
112
|
"@vandeurenglenn/debug": "^1.4.0",
|
|
113
113
|
"@vandeurenglenn/little-pubsub": "^1.5.2",
|
|
@@ -125,6 +125,7 @@
|
|
|
125
125
|
"@types/node": "^25.9.1",
|
|
126
126
|
"@types/qrcode": "^1.5.6",
|
|
127
127
|
"rollup": "^4.60.4",
|
|
128
|
-
"tslib": "^2.8.1"
|
|
128
|
+
"tslib": "^2.8.1",
|
|
129
|
+
"typescript": "^6.0.2"
|
|
129
130
|
}
|
|
130
131
|
}
|
package/src/identity.ts
CHANGED
|
@@ -7,6 +7,7 @@ import qrcode from 'qrcode'
|
|
|
7
7
|
|
|
8
8
|
export default class Identity {
|
|
9
9
|
#wallet: MultiWallet
|
|
10
|
+
#accountWallets = new Map<string, { sign: (hash: Uint8Array) => Promise<Uint8Array> }>()
|
|
10
11
|
network
|
|
11
12
|
id: string
|
|
12
13
|
selectedAccount: string
|
|
@@ -63,15 +64,43 @@ export default class Identity {
|
|
|
63
64
|
this.#wallet = new MultiWallet(this.network)
|
|
64
65
|
const multiWIF = await decrypt(password, base58.decode(identity.multiWIF))
|
|
65
66
|
await this.#wallet.fromMultiWif(multiWIF)
|
|
67
|
+
await this.#loadAccountWallets()
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async #loadAccountWallets() {
|
|
71
|
+
this.#accountWallets.clear()
|
|
72
|
+
const accounts = await this.getAccounts()
|
|
73
|
+
for (const [index, [, externalAddress, internalAddress]] of accounts.entries()) {
|
|
74
|
+
const account = this.#wallet.account(index + 1)
|
|
75
|
+
const external = (await account.external(1)) as unknown as {
|
|
76
|
+
address: Promise<string>
|
|
77
|
+
sign: (hash: Uint8Array) => Promise<Uint8Array>
|
|
78
|
+
}
|
|
79
|
+
const internal = (await account.internal(1)) as unknown as {
|
|
80
|
+
address: Promise<string>
|
|
81
|
+
sign: (hash: Uint8Array) => Promise<Uint8Array>
|
|
82
|
+
}
|
|
83
|
+
if ((await external.address) !== externalAddress || (await internal.address) !== internalAddress) {
|
|
84
|
+
throw new Error(`stored account ${index + 1} does not match this identity`)
|
|
85
|
+
}
|
|
86
|
+
this.#accountWallets.set(externalAddress, external)
|
|
87
|
+
this.#accountWallets.set(internalAddress, internal)
|
|
88
|
+
}
|
|
89
|
+
if (!this.#accountWallets.has(this.selectedAccount)) {
|
|
90
|
+
throw new Error(`selected account ${this.selectedAccount} is not part of this identity`)
|
|
91
|
+
}
|
|
66
92
|
}
|
|
67
93
|
|
|
68
94
|
selectAccount(account: string) {
|
|
95
|
+
if (!this.#accountWallets.has(account)) throw new Error(`unknown identity account ${account}`)
|
|
69
96
|
this.selectedAccount = account
|
|
70
97
|
return walletStore.put('selected-account', account)
|
|
71
98
|
}
|
|
72
99
|
|
|
73
100
|
sign(hash: Uint8Array) {
|
|
74
|
-
|
|
101
|
+
const wallet = this.#accountWallets.get(this.selectedAccount)
|
|
102
|
+
if (!wallet) throw new Error(`no signer available for selected account ${this.selectedAccount}`)
|
|
103
|
+
return wallet.sign(hash.subarray(0, 32))
|
|
75
104
|
}
|
|
76
105
|
|
|
77
106
|
lock(password: string) {
|
package/src/peernet.ts
CHANGED
|
@@ -52,6 +52,7 @@ export default class Peernet {
|
|
|
52
52
|
client: swarm
|
|
53
53
|
network: string
|
|
54
54
|
stars: string[]
|
|
55
|
+
transport
|
|
55
56
|
networkVersion: string
|
|
56
57
|
bw: {
|
|
57
58
|
up: number
|
|
@@ -77,6 +78,7 @@ export default class Peernet {
|
|
|
77
78
|
* @param {String} options.root - path to root directory
|
|
78
79
|
* @param {String} options.version - path to root directory
|
|
79
80
|
* @param {String} options.storePrefix - prefix for datatores (lfc)
|
|
81
|
+
* @param {Object} options.transport - transport selection and fallback options passed to @netpeer/swarm
|
|
80
82
|
*
|
|
81
83
|
* @return {Promise} instance of Peernet
|
|
82
84
|
*
|
|
@@ -90,6 +92,7 @@ export default class Peernet {
|
|
|
90
92
|
this.network = options.network || 'leofcoin'
|
|
91
93
|
this.autoStart = options.autoStart === undefined ? true : options.autoStart
|
|
92
94
|
this.stars = options.stars
|
|
95
|
+
this.transport = options.transport
|
|
93
96
|
this.version = options.version
|
|
94
97
|
const parts = this.network.split(':')
|
|
95
98
|
this.networkVersion = options.networkVersion || parts.length > 1 ? parts[1] : 'mainnet'
|
|
@@ -281,7 +284,8 @@ export default class Peernet {
|
|
|
281
284
|
peerId: this.id,
|
|
282
285
|
networkVersion: this.networkVersion,
|
|
283
286
|
version: this.version,
|
|
284
|
-
stars: this.stars
|
|
287
|
+
stars: this.stars,
|
|
288
|
+
transport: this.transport
|
|
285
289
|
})
|
|
286
290
|
this.#started = true
|
|
287
291
|
this.#starting = false
|
package/test/peernet.test.js
CHANGED
|
@@ -3,11 +3,13 @@ import assert from 'node:assert/strict'
|
|
|
3
3
|
|
|
4
4
|
import Peernet from '../exports/peernet.js'
|
|
5
5
|
import Identity from '../exports/identity.js'
|
|
6
|
+
import MultiWallet from '@leofcoin/multi-wallet'
|
|
7
|
+
import { fromBase58, toBase58 } from '@vandeurenglenn/typed-array-utils'
|
|
6
8
|
|
|
7
9
|
const options = {
|
|
8
10
|
network: 'leofcoin:peach',
|
|
9
11
|
stars: [],
|
|
10
|
-
root:
|
|
12
|
+
root: `.testnet-${process.pid}`,
|
|
11
13
|
version: '1.0.0',
|
|
12
14
|
storePrefix: 'test',
|
|
13
15
|
autoStart: false
|
|
@@ -234,6 +236,14 @@ test('selected account is set', () => {
|
|
|
234
236
|
assert.ok(typeof peernet.identity.selectedAccount === 'string')
|
|
235
237
|
})
|
|
236
238
|
|
|
239
|
+
test('identity signatures authenticate the selected account', async () => {
|
|
240
|
+
const payload = new Uint8Array(32).fill(7)
|
|
241
|
+
const signature = toBase58(await peernet.identity.sign(payload))
|
|
242
|
+
const verifier = new MultiWallet(peernet.network)
|
|
243
|
+
await verifier.fromAddress(peernet.selectedAccount, null, peernet.network)
|
|
244
|
+
assert.equal(await verifier.verify(fromBase58(signature), payload), true)
|
|
245
|
+
})
|
|
246
|
+
|
|
237
247
|
test('error handling methods exist', () => {
|
|
238
248
|
assert.equal(typeof peernet.handleDHT, 'function')
|
|
239
249
|
assert.equal(typeof peernet.handleData, 'function')
|