autopass 3.1.4 → 3.2.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.
@@ -0,0 +1,34 @@
1
+ import BlindEncryptionSodium from 'blind-encryption-sodium'
2
+ import Autopass from './index.js'
3
+ import Corestore from 'corestore'
4
+ import process from 'process'
5
+ import b4a from 'b4a'
6
+ const store = new Corestore('example/' + process.argv[2])
7
+
8
+ let pass = null
9
+
10
+ const password = b4a.alloc(32, 'password')
11
+
12
+ if (process.argv[3]) {
13
+ const pair = Autopass.pair(store, process.argv[3], {
14
+ blindEncryption: new BlindEncryptionSodium(password)
15
+ })
16
+ pass = await pair.finished()
17
+ } else {
18
+ pass = new Autopass(store, {
19
+ blindEncryption: new BlindEncryptionSodium(password)
20
+ })
21
+ await pass.ready()
22
+ }
23
+
24
+ if (pass.base.writable) {
25
+ const inv = await pass.createInvite()
26
+ console.log('invite', inv)
27
+ }
28
+ onupdate()
29
+ pass.on('update', onupdate)
30
+
31
+ function onupdate() {
32
+ console.log('db changed, all entries:')
33
+ pass.list().on('data', console.log)
34
+ }
package/index.js CHANGED
@@ -28,6 +28,7 @@ class AutopassPairer extends ReadyResource {
28
28
  this.onreject = null
29
29
  this.pass = null
30
30
  this.relayThrough = opts.relayThrough || null
31
+ this.blindEncryption = opts.blindEncryption || null
31
32
 
32
33
  this.ready().catch(noop)
33
34
  }
@@ -63,7 +64,8 @@ class AutopassPairer extends ReadyResource {
63
64
  key: result.key,
64
65
  wakeup: this.wakeup,
65
66
  encryptionKey: result.encryptionKey,
66
- bootstrap: this.bootstrap
67
+ bootstrap: this.bootstrap,
68
+ blindEncryption: this.blindEncryption
67
69
  })
68
70
 
69
71
  await this.pass.deleteInvite()
@@ -171,12 +173,13 @@ class Autopass extends ReadyResource {
171
173
 
172
174
  // Initialize autobase
173
175
  _boot(opts = {}) {
174
- const { encryptionKey, key, wakeup } = opts
176
+ const { encryptionKey, key, wakeup, blindEncryption } = opts
175
177
 
176
178
  this.base = new Autobase(this.store, key, {
177
179
  wakeup,
178
180
  encrypt: true,
179
181
  encryptionKey,
182
+ blindEncryption,
180
183
  open(store) {
181
184
  return HyperDB.bee(store.get('view'), db, {
182
185
  extension: false,
@@ -237,11 +240,10 @@ class Autopass extends ReadyResource {
237
240
  if (this.opened === false) await this.ready()
238
241
  const existing = await this.base.view.findOne('@autopass/invite', {})
239
242
  if (existing) {
243
+ if (this.member) await this.member.flushed()
240
244
  return z32.encode(existing.invite)
241
245
  }
242
- const { id, invite, publicKey, expires } = BlindPairing.createInvite(
243
- this.base.key
244
- )
246
+ const { id, invite, publicKey, expires } = BlindPairing.createInvite(this.base.key)
245
247
 
246
248
  const record = { id, invite, publicKey, expires }
247
249
  await this.base.append(encode('@autopass/add-invite', record))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autopass",
3
- "version": "3.1.4",
3
+ "version": "3.2.0",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "brittle": "npx brittle test.js",
@@ -26,12 +26,13 @@
26
26
  "brittle": "^3.19.0",
27
27
  "hyperdht": "^6.23.0",
28
28
  "prettier": "^3.6.2",
29
- "prettier-config-holepunch": "^1.0.0",
29
+ "prettier-config-holepunch": "^2.0.0",
30
30
  "test-tmp": "^1.4.0"
31
31
  },
32
32
  "dependencies": {
33
33
  "autobase": "^7.19.4",
34
34
  "b4a": "^1.7.1",
35
+ "blind-encryption-sodium": "^1.0.2",
35
36
  "blind-pairing": "^2.3.1",
36
37
  "blind-peering": "^1.13.0",
37
38
  "corestore": "^7.4.7",
package/schema.js CHANGED
@@ -159,10 +159,7 @@ blobs.collections.register({
159
159
  })
160
160
  HyperdbBuilder.toDisk(dbTemplate)
161
161
 
162
- const hyperdispatch = Hyperdispatch.from(
163
- './spec/schema',
164
- './spec/hyperdispatch'
165
- )
162
+ const hyperdispatch = Hyperdispatch.from('./spec/schema', './spec/hyperdispatch')
166
163
  const namespace = hyperdispatch.namespace('autopass')
167
164
  namespace.register({
168
165
  name: 'remove-writer',
@@ -47,40 +47,20 @@ class Router {
47
47
  this._handler7 = handler
48
48
  break
49
49
  default:
50
- throw new Error(
51
- 'Cannot register a handler for a nonexistent route: ' + name
52
- )
50
+ throw new Error('Cannot register a handler for a nonexistent route: ' + name)
53
51
  }
54
52
  this._missing--
55
53
  }
56
54
 
57
55
  _checkAll() {
58
- assert(
59
- this._handler0 !== null,
60
- 'Missing handler for "@autopass/remove-writer"'
61
- )
62
- assert(
63
- this._handler1 !== null,
64
- 'Missing handler for "@autopass/add-writer"'
65
- )
56
+ assert(this._handler0 !== null, 'Missing handler for "@autopass/remove-writer"')
57
+ assert(this._handler1 !== null, 'Missing handler for "@autopass/add-writer"')
66
58
  assert(this._handler2 !== null, 'Missing handler for "@autopass/put"')
67
- assert(
68
- this._handler3 !== null,
69
- 'Missing handler for "@autopass/add-mirror"'
70
- )
71
- assert(
72
- this._handler4 !== null,
73
- 'Missing handler for "@autopass/del-mirror"'
74
- )
59
+ assert(this._handler3 !== null, 'Missing handler for "@autopass/add-mirror"')
60
+ assert(this._handler4 !== null, 'Missing handler for "@autopass/del-mirror"')
75
61
  assert(this._handler5 !== null, 'Missing handler for "@autopass/del"')
76
- assert(
77
- this._handler6 !== null,
78
- 'Missing handler for "@autopass/add-invite"'
79
- )
80
- assert(
81
- this._handler7 !== null,
82
- 'Missing handler for "@autopass/del-invite"'
83
- )
62
+ assert(this._handler6 !== null, 'Missing handler for "@autopass/add-invite"')
63
+ assert(this._handler7 !== null, 'Missing handler for "@autopass/del-invite"')
84
64
  }
85
65
 
86
66
  async dispatch(message, context) {
package/test.js CHANGED
@@ -3,6 +3,8 @@ const Autopass = require('./')
3
3
  const Corestore = require('corestore')
4
4
  const testnet = require('hyperdht/testnet')
5
5
  const tmp = require('test-tmp')
6
+ const b4a = require('b4a')
7
+ const BlindEncryptionSodium = require('blind-encryption-sodium')
6
8
 
7
9
  test('basic', async function (t) {
8
10
  const a = await create(t, { replicate: false })
@@ -79,6 +81,53 @@ test('invites', async function (t) {
79
81
  })
80
82
  })
81
83
 
84
+ test('blind encryption', async function (t) {
85
+ t.plan(4)
86
+
87
+ const password = b4a.alloc(32, 'password')
88
+ const tn = await testnet(10, t)
89
+
90
+ const a = await create(t, {
91
+ bootstrap: tn.bootstrap,
92
+ blindEncryption: new BlindEncryptionSodium(password)
93
+ })
94
+ t.teardown(() => {
95
+ a.close()
96
+ })
97
+
98
+ const updateListener = function () {
99
+ if (a.base.system.members === 2) {
100
+ t.pass('a has two members')
101
+ a.removeListener('update', updateListener) // Remove the listener in teardown
102
+ }
103
+ }
104
+
105
+ a.on('update', updateListener)
106
+
107
+ const inv = await a.createInvite()
108
+
109
+ const p = await pair(t, inv, {
110
+ bootstrap: tn.bootstrap,
111
+ blindEncryption: new BlindEncryptionSodium(password)
112
+ })
113
+
114
+ const b = await p.finished()
115
+ await b.ready()
116
+
117
+ const [encryptionKeyBuffer, encryptionKeyEncryptedBuffer] = await Promise.all([
118
+ b.base.local.getUserData('autobase/encryption'),
119
+ b.base.local.getUserData('autobase/blind-encryption')
120
+ ])
121
+
122
+ t.absent(encryptionKeyBuffer)
123
+ t.ok(encryptionKeyEncryptedBuffer)
124
+
125
+ t.teardown(() => b.close())
126
+ b.on('update', function () {
127
+ if (b.base.system.members === 2) t.pass('b has two members')
128
+ })
129
+ })
130
+
82
131
  test('suspend and resume', async function (t) {
83
132
  t.plan(3)
84
133