blind-peer 0.0.1 → 0.0.2
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/build.js +1 -1
- package/example/autobase.mjs +7 -4
- package/example/post.mjs +4 -1
- package/index.js +3 -5
- package/package.json +1 -1
- package/spec/hyperdb/messages.js +3 -3
- package/spec/hyperschema/index.js +3 -3
- package/spec/hyperschema/schema.json +1 -1
package/build.js
CHANGED
package/example/autobase.mjs
CHANGED
|
@@ -7,14 +7,14 @@ import debounce from 'debounceify'
|
|
|
7
7
|
|
|
8
8
|
const base = new Autobase(new Corestore('/tmp/my-corestore'), {
|
|
9
9
|
encryptionKey: Buffer.alloc(30).fill('secret'),
|
|
10
|
-
valueEncoding: c.json,
|
|
11
10
|
open (store) {
|
|
12
11
|
return store.get('view', { valueEncoding: c.json })
|
|
13
12
|
},
|
|
14
13
|
async apply (nodes, view, base) {
|
|
15
14
|
for (const node of nodes) {
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
const jsonValue = JSON.parse(node.value.toString())
|
|
16
|
+
if (jsonValue.add) await base.addWriter(Buffer.from(jsonValue.key, 'hex'), { indexer: false })
|
|
17
|
+
view.append(jsonValue)
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
})
|
|
@@ -45,7 +45,10 @@ s.on('connection', async c => {
|
|
|
45
45
|
const info = await peer.addMailbox({ autobase: base.key })
|
|
46
46
|
|
|
47
47
|
if (info.open === false) {
|
|
48
|
-
|
|
48
|
+
const message = Buffer.from(
|
|
49
|
+
JSON.stringify({ add: true, key: info.writer.toString('hex') })
|
|
50
|
+
)
|
|
51
|
+
await base.append(message)
|
|
49
52
|
await base.update()
|
|
50
53
|
|
|
51
54
|
const core = base.store.get({ key: info.writer, active: false })
|
package/example/post.mjs
CHANGED
|
@@ -3,7 +3,10 @@ import Hyperswarm from 'hyperswarm'
|
|
|
3
3
|
|
|
4
4
|
const publicKey = Buffer.from(process.argv[2], 'hex')
|
|
5
5
|
const autobase = Buffer.from(process.argv[3], 'hex')
|
|
6
|
-
const
|
|
6
|
+
const rawMessage = process.argv[4]
|
|
7
|
+
const message = Buffer.from(
|
|
8
|
+
JSON.stringify({ mailbox: true, message: rawMessage })
|
|
9
|
+
)
|
|
7
10
|
|
|
8
11
|
const s = new Hyperswarm()
|
|
9
12
|
|
package/index.js
CHANGED
|
@@ -56,8 +56,7 @@ module.exports = class BlindPeer {
|
|
|
56
56
|
|
|
57
57
|
const w = new AutobaseLightWriter(this.store.namespace(entry.autobase), entry.autobase, {
|
|
58
58
|
active: false,
|
|
59
|
-
blockEncryptionKey: entry.blockEncryptionKey
|
|
60
|
-
valueEncoding: c.json
|
|
59
|
+
blockEncryptionKey: entry.blockEncryptionKey
|
|
61
60
|
})
|
|
62
61
|
|
|
63
62
|
for (const peer of core.peers) {
|
|
@@ -120,10 +119,9 @@ module.exports = class BlindPeer {
|
|
|
120
119
|
|
|
121
120
|
const w = new AutobaseLightWriter(this.store.namespace(autobase), autobase, {
|
|
122
121
|
active: false,
|
|
123
|
-
blockEncryptionKey: entry.blockEncryptionKey
|
|
124
|
-
valueEncoding: c.json
|
|
122
|
+
blockEncryptionKey: entry.blockEncryptionKey
|
|
125
123
|
})
|
|
126
|
-
await w.append(
|
|
124
|
+
await w.append(message)
|
|
127
125
|
const length = w.local.length
|
|
128
126
|
await w.close()
|
|
129
127
|
|
package/package.json
CHANGED
package/spec/hyperdb/messages.js
CHANGED
|
@@ -86,7 +86,7 @@ const encoding2 = {
|
|
|
86
86
|
c.fixed32.preencode(state, m.autobase)
|
|
87
87
|
c.uint.preencode(state, flags)
|
|
88
88
|
|
|
89
|
-
if (m.message) c.
|
|
89
|
+
if (m.message) c.buffer.preencode(state, m.message)
|
|
90
90
|
},
|
|
91
91
|
encode (state, m) {
|
|
92
92
|
let flags = 0
|
|
@@ -95,7 +95,7 @@ const encoding2 = {
|
|
|
95
95
|
c.fixed32.encode(state, m.autobase)
|
|
96
96
|
c.uint.encode(state, flags)
|
|
97
97
|
|
|
98
|
-
if (m.message) c.
|
|
98
|
+
if (m.message) c.buffer.encode(state, m.message)
|
|
99
99
|
},
|
|
100
100
|
decode (state) {
|
|
101
101
|
const res = {}
|
|
@@ -105,7 +105,7 @@ const encoding2 = {
|
|
|
105
105
|
res.autobase = c.fixed32.decode(state)
|
|
106
106
|
|
|
107
107
|
const flags = state.start < state.end ? c.uint.decode(state) : 0
|
|
108
|
-
if ((flags & 1) !== 0) res.message = c.
|
|
108
|
+
if ((flags & 1) !== 0) res.message = c.buffer.decode(state)
|
|
109
109
|
|
|
110
110
|
return res
|
|
111
111
|
}
|
|
@@ -86,7 +86,7 @@ const encoding2 = {
|
|
|
86
86
|
c.fixed32.preencode(state, m.autobase)
|
|
87
87
|
c.uint.preencode(state, flags)
|
|
88
88
|
|
|
89
|
-
if (m.message) c.
|
|
89
|
+
if (m.message) c.buffer.preencode(state, m.message)
|
|
90
90
|
},
|
|
91
91
|
encode (state, m) {
|
|
92
92
|
let flags = 0
|
|
@@ -95,7 +95,7 @@ const encoding2 = {
|
|
|
95
95
|
c.fixed32.encode(state, m.autobase)
|
|
96
96
|
c.uint.encode(state, flags)
|
|
97
97
|
|
|
98
|
-
if (m.message) c.
|
|
98
|
+
if (m.message) c.buffer.encode(state, m.message)
|
|
99
99
|
},
|
|
100
100
|
decode (state) {
|
|
101
101
|
const res = {}
|
|
@@ -105,7 +105,7 @@ const encoding2 = {
|
|
|
105
105
|
res.autobase = c.fixed32.decode(state)
|
|
106
106
|
|
|
107
107
|
const flags = state.start < state.end ? c.uint.decode(state) : 0
|
|
108
|
-
if ((flags & 1) !== 0) res.message = c.
|
|
108
|
+
if ((flags & 1) !== 0) res.message = c.buffer.decode(state)
|
|
109
109
|
|
|
110
110
|
return res
|
|
111
111
|
}
|