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 CHANGED
@@ -52,7 +52,7 @@ blind.register({
52
52
  },
53
53
  {
54
54
  name: 'message',
55
- type: 'string'
55
+ type: 'buffer'
56
56
  }
57
57
  ]
58
58
  })
@@ -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
- if (node.value.add) await base.addWriter(Buffer.from(node.value.key, 'hex'), { indexer: false })
17
- view.append(node.value)
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
- await base.append({ add: true, key: info.writer.toString('hex') })
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 message = process.argv[4]
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({ mailbox: true, text: message })
124
+ await w.append(message)
127
125
  const length = w.local.length
128
126
  await w.close()
129
127
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blind-peer",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "WIP - nothing to see here",
5
5
  "main": "index.js",
6
6
  "dependencies": {
@@ -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.string.preencode(state, m.message)
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.string.encode(state, m.message)
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.string.decode(state)
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.string.preencode(state, m.message)
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.string.encode(state, m.message)
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.string.decode(state)
108
+ if ((flags & 1) !== 0) res.message = c.buffer.decode(state)
109
109
 
110
110
  return res
111
111
  }
@@ -59,7 +59,7 @@
59
59
  },
60
60
  {
61
61
  "name": "message",
62
- "type": "string",
62
+ "type": "buffer",
63
63
  "version": 1
64
64
  }
65
65
  ]