autopass 3.3.0 → 3.4.1
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/README.md +19 -2
- package/index.js +33 -20
- package/package.json +4 -3
- package/schema.js +31 -10
- package/spec/db/db.json +22 -8
- package/spec/db/index.js +76 -70
- package/spec/db/messages.js +121 -30
- package/spec/hyperdispatch/dispatch.json +1 -1
- package/spec/hyperdispatch/index.js +8 -8
- package/spec/hyperdispatch/messages.js +67 -6
- package/spec/schema/index.js +67 -6
- package/spec/schema/schema.json +44 -2
- package/test.js +50 -8
package/README.md
CHANGED
|
@@ -71,13 +71,30 @@ Add new entry
|
|
|
71
71
|
|
|
72
72
|
Remove an entry.
|
|
73
73
|
|
|
74
|
+
#### `stream = pass.listWriters(query)`
|
|
75
|
+
|
|
76
|
+
List all writers, optionally takes a hyperdb query
|
|
77
|
+
|
|
78
|
+
#### `writer = await pass.getWriter(key)
|
|
79
|
+
|
|
80
|
+
Get a writer, object similar to the addWriter input.
|
|
81
|
+
|
|
74
82
|
#### `await pass.removeWriter(writerKey)`
|
|
75
83
|
|
|
76
84
|
Remove a writer explictly.
|
|
77
85
|
|
|
78
|
-
#### `await pass.addWriter(
|
|
86
|
+
#### `await pass.addWriter(writer)`
|
|
79
87
|
|
|
80
88
|
Add a writer explictly.
|
|
89
|
+
Writer should look like this
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
{
|
|
93
|
+
key: otherSidesLocalWriterKey,
|
|
94
|
+
name: 'optional name for the writer',
|
|
95
|
+
readOnly: false // weather the person can write or only read
|
|
96
|
+
}
|
|
97
|
+
```
|
|
81
98
|
|
|
82
99
|
#### `pass.writerKey`
|
|
83
100
|
|
|
@@ -127,7 +144,7 @@ Fully close the pass instance.
|
|
|
127
144
|
|
|
128
145
|
Suspend the swarm and discovery
|
|
129
146
|
|
|
130
|
-
#### `await pass.resume`
|
|
147
|
+
#### `await pass.resume()`
|
|
131
148
|
|
|
132
149
|
Resume the swarm is suspended
|
|
133
150
|
|
package/index.js
CHANGED
|
@@ -12,6 +12,12 @@ const { Router, encode, decode } = require('./spec/hyperdispatch')
|
|
|
12
12
|
const BlindPeering = require('blind-peering')
|
|
13
13
|
const db = require('./spec/db/index.js')
|
|
14
14
|
const enc = require('hypercore-id-encoding')
|
|
15
|
+
const c = require('compact-encoding')
|
|
16
|
+
|
|
17
|
+
const { getEncoding } = require('./spec/schema/index.js')
|
|
18
|
+
|
|
19
|
+
const PUBLIC_INVITE_METADATA = getEncoding('@autopass/public-invite-metadata')
|
|
20
|
+
const INVITEE = getEncoding('@autopass/invitee')
|
|
15
21
|
|
|
16
22
|
class AutopassPairer extends ReadyResource {
|
|
17
23
|
constructor(store, invite, opts = {}) {
|
|
@@ -29,6 +35,7 @@ class AutopassPairer extends ReadyResource {
|
|
|
29
35
|
this.pass = null
|
|
30
36
|
this.relayThrough = opts.relayThrough || null
|
|
31
37
|
this.blindEncryption = opts.blindEncryption || null
|
|
38
|
+
this.name = opts.name || null
|
|
32
39
|
|
|
33
40
|
this.ready().catch(noop)
|
|
34
41
|
}
|
|
@@ -54,9 +61,10 @@ class AutopassPairer extends ReadyResource {
|
|
|
54
61
|
await core.ready()
|
|
55
62
|
const key = core.key
|
|
56
63
|
await core.close()
|
|
64
|
+
|
|
57
65
|
this.candidate = this.pairing.addCandidate({
|
|
58
66
|
invite: z32.decode(this.invite),
|
|
59
|
-
userData: key,
|
|
67
|
+
userData: c.encode(INVITEE, { key, name: this.name }),
|
|
60
68
|
onadd: async (result) => {
|
|
61
69
|
if (this.pass === null) {
|
|
62
70
|
this.pass = new Autopass(this.store, {
|
|
@@ -70,10 +78,12 @@ class AutopassPairer extends ReadyResource {
|
|
|
70
78
|
|
|
71
79
|
await this.pass.deleteInvite()
|
|
72
80
|
}
|
|
73
|
-
|
|
81
|
+
|
|
82
|
+
const metadata = result.data ? c.decode(PUBLIC_INVITE_METADATA, result.data) : null
|
|
83
|
+
|
|
74
84
|
this.swarm = null
|
|
75
85
|
this.store = null
|
|
76
|
-
if (this.onresolve && readOnly) {
|
|
86
|
+
if (this.onresolve && metadata && metadata.readOnly) {
|
|
77
87
|
this._whenReadable()
|
|
78
88
|
} else if (this.onresolve) {
|
|
79
89
|
this._whenWritable()
|
|
@@ -84,11 +94,7 @@ class AutopassPairer extends ReadyResource {
|
|
|
84
94
|
}
|
|
85
95
|
|
|
86
96
|
_whenReadable() {
|
|
87
|
-
|
|
88
|
-
this.pass.base.off('update', check)
|
|
89
|
-
this.onresolve(this.pass)
|
|
90
|
-
}
|
|
91
|
-
this.pass.base.on('update', check)
|
|
97
|
+
this.onresolve(this.pass)
|
|
92
98
|
}
|
|
93
99
|
|
|
94
100
|
_whenWritable() {
|
|
@@ -149,11 +155,13 @@ class Autopass extends ReadyResource {
|
|
|
149
155
|
this.debug = !!opts.key
|
|
150
156
|
// Register handlers for commands
|
|
151
157
|
this.router.add('@autopass/remove-writer', async (data, context) => {
|
|
158
|
+
await context.view.delete('@autopass/writer', data)
|
|
152
159
|
await context.base.removeWriter(data.key)
|
|
153
160
|
})
|
|
154
161
|
|
|
155
162
|
this.router.add('@autopass/add-writer', async (data, context) => {
|
|
156
|
-
await context.
|
|
163
|
+
await context.view.insert('@autopass/writer', data)
|
|
164
|
+
if (!data.readOnly) await context.base.addWriter(data.key)
|
|
157
165
|
})
|
|
158
166
|
|
|
159
167
|
this.router.add('@autopass/put', async (data, context) => {
|
|
@@ -263,7 +271,7 @@ class Autopass extends ReadyResource {
|
|
|
263
271
|
const { id, invite, publicKey, expires, additional } = BlindPairing.createInvite(
|
|
264
272
|
this.base.key,
|
|
265
273
|
{
|
|
266
|
-
data:
|
|
274
|
+
data: c.encode(PUBLIC_INVITE_METADATA, { readOnly })
|
|
267
275
|
}
|
|
268
276
|
)
|
|
269
277
|
|
|
@@ -293,19 +301,25 @@ class Autopass extends ReadyResource {
|
|
|
293
301
|
return { value: data.value, file: data.file }
|
|
294
302
|
}
|
|
295
303
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
)
|
|
304
|
+
listWriters(query) {
|
|
305
|
+
return this.base.view.find('@autopass/writer', query)
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
async getWriter(key) {
|
|
309
|
+
return this.base.view.get('@autopass/writer', { key })
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
async addWriter(data) {
|
|
313
|
+
if (typeof data === 'string') data = b4a.from(data, 'hex')
|
|
314
|
+
if (b4a.isBuffer(data)) data = { key: data, name: null, readOnly: false }
|
|
315
|
+
await this.base.append(encode('@autopass/add-writer', data))
|
|
302
316
|
return true
|
|
303
317
|
}
|
|
304
318
|
|
|
305
319
|
async removeWriter(key) {
|
|
306
320
|
await this.base.append(
|
|
307
321
|
encode('@autopass/remove-writer', {
|
|
308
|
-
key: b4a.isBuffer(key) ? key : b4a.from(key)
|
|
322
|
+
key: b4a.isBuffer(key) ? key : b4a.from(key, 'hex')
|
|
309
323
|
})
|
|
310
324
|
)
|
|
311
325
|
}
|
|
@@ -337,9 +351,8 @@ class Autopass extends ReadyResource {
|
|
|
337
351
|
}
|
|
338
352
|
const readOnly = inv.readOnly
|
|
339
353
|
candidate.open(inv.publicKey)
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
}
|
|
354
|
+
const { key, name } = c.decode(INVITEE, candidate.userData)
|
|
355
|
+
await this.addWriter({ key, name, readOnly })
|
|
343
356
|
candidate.confirm({
|
|
344
357
|
key: this.base.key,
|
|
345
358
|
encryptionKey: this.base.encryptionKey,
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "autopass",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.1",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"scripts": {
|
|
6
|
-
"brittle": "
|
|
7
|
-
"lint": "
|
|
6
|
+
"brittle": "brittle test.js",
|
|
7
|
+
"lint": "prettier . --check",
|
|
8
|
+
"format": "prettier . --write",
|
|
8
9
|
"test": "npm run lint && npm run brittle"
|
|
9
10
|
},
|
|
10
11
|
"author": "Holepunch Inc",
|
package/schema.js
CHANGED
|
@@ -4,9 +4,9 @@ const Hyperdispatch = require('hyperdispatch')
|
|
|
4
4
|
|
|
5
5
|
// SCHEMA CREATION START //
|
|
6
6
|
const autopass = Hyperschema.from('./spec/schema')
|
|
7
|
-
const
|
|
7
|
+
const pass = autopass.namespace('autopass')
|
|
8
8
|
// You can find a list of supported data types here: https://github.com/holepunchto/compact-encoding
|
|
9
|
-
|
|
9
|
+
pass.register({
|
|
10
10
|
name: 'records',
|
|
11
11
|
compact: false,
|
|
12
12
|
fields: [
|
|
@@ -27,7 +27,7 @@ template.register({
|
|
|
27
27
|
}
|
|
28
28
|
]
|
|
29
29
|
})
|
|
30
|
-
|
|
30
|
+
pass.register({
|
|
31
31
|
name: 'mirrors',
|
|
32
32
|
compact: false,
|
|
33
33
|
fields: [
|
|
@@ -38,7 +38,7 @@ template.register({
|
|
|
38
38
|
}
|
|
39
39
|
]
|
|
40
40
|
})
|
|
41
|
-
|
|
41
|
+
pass.register({
|
|
42
42
|
name: 'writer',
|
|
43
43
|
compact: false,
|
|
44
44
|
fields: [
|
|
@@ -46,11 +46,19 @@ template.register({
|
|
|
46
46
|
name: 'key',
|
|
47
47
|
type: 'buffer',
|
|
48
48
|
required: true
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: 'name',
|
|
52
|
+
type: 'string'
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: 'readOnly',
|
|
56
|
+
type: 'bool'
|
|
49
57
|
}
|
|
50
58
|
]
|
|
51
59
|
})
|
|
52
60
|
|
|
53
|
-
|
|
61
|
+
pass.register({
|
|
54
62
|
name: 'delete',
|
|
55
63
|
compact: false,
|
|
56
64
|
fields: [
|
|
@@ -62,7 +70,20 @@ template.register({
|
|
|
62
70
|
]
|
|
63
71
|
})
|
|
64
72
|
|
|
65
|
-
|
|
73
|
+
pass.register({
|
|
74
|
+
name: 'invitee',
|
|
75
|
+
fields: [
|
|
76
|
+
{ name: 'key', type: 'fixed32', required: true },
|
|
77
|
+
{ name: 'name', type: 'string' }
|
|
78
|
+
]
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
pass.register({
|
|
82
|
+
name: 'public-invite-metadata',
|
|
83
|
+
fields: [{ name: 'readOnly', type: 'bool' }]
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
pass.register({
|
|
66
87
|
name: 'additional-invite-data',
|
|
67
88
|
fields: [
|
|
68
89
|
{ name: 'data', type: 'buffer', required: true },
|
|
@@ -70,7 +91,7 @@ template.register({
|
|
|
70
91
|
]
|
|
71
92
|
})
|
|
72
93
|
|
|
73
|
-
|
|
94
|
+
pass.register({
|
|
74
95
|
name: 'invite',
|
|
75
96
|
compact: false,
|
|
76
97
|
fields: [
|
|
@@ -97,7 +118,7 @@ template.register({
|
|
|
97
118
|
{
|
|
98
119
|
name: 'readOnly',
|
|
99
120
|
type: 'bool',
|
|
100
|
-
required:
|
|
121
|
+
required: false
|
|
101
122
|
},
|
|
102
123
|
{
|
|
103
124
|
name: 'additional',
|
|
@@ -107,7 +128,7 @@ template.register({
|
|
|
107
128
|
]
|
|
108
129
|
})
|
|
109
130
|
|
|
110
|
-
|
|
131
|
+
pass.register({
|
|
111
132
|
name: 'del-invite',
|
|
112
133
|
compact: false,
|
|
113
134
|
fields: [
|
|
@@ -118,7 +139,7 @@ template.register({
|
|
|
118
139
|
}
|
|
119
140
|
]
|
|
120
141
|
})
|
|
121
|
-
|
|
142
|
+
pass.register({
|
|
122
143
|
name: 'del-mirror',
|
|
123
144
|
compact: false,
|
|
124
145
|
fields: [
|
package/spec/db/db.json
CHANGED
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
"indexes": [],
|
|
13
13
|
"schema": "@autopass/records",
|
|
14
14
|
"derived": false,
|
|
15
|
-
"key": [
|
|
15
|
+
"key": [
|
|
16
|
+
"key"
|
|
17
|
+
],
|
|
16
18
|
"trigger": null
|
|
17
19
|
},
|
|
18
20
|
{
|
|
@@ -25,7 +27,9 @@
|
|
|
25
27
|
"indexes": [],
|
|
26
28
|
"schema": "@autopass/invite",
|
|
27
29
|
"derived": false,
|
|
28
|
-
"key": [
|
|
30
|
+
"key": [
|
|
31
|
+
"id"
|
|
32
|
+
],
|
|
29
33
|
"trigger": null
|
|
30
34
|
},
|
|
31
35
|
{
|
|
@@ -38,7 +42,9 @@
|
|
|
38
42
|
"indexes": [],
|
|
39
43
|
"schema": "@autopass/mirrors",
|
|
40
44
|
"derived": false,
|
|
41
|
-
"key": [
|
|
45
|
+
"key": [
|
|
46
|
+
"key"
|
|
47
|
+
],
|
|
42
48
|
"trigger": null
|
|
43
49
|
},
|
|
44
50
|
{
|
|
@@ -51,7 +57,9 @@
|
|
|
51
57
|
"indexes": [],
|
|
52
58
|
"schema": "@autopass/writer",
|
|
53
59
|
"derived": false,
|
|
54
|
-
"key": [
|
|
60
|
+
"key": [
|
|
61
|
+
"key"
|
|
62
|
+
],
|
|
55
63
|
"trigger": null
|
|
56
64
|
},
|
|
57
65
|
{
|
|
@@ -64,7 +72,9 @@
|
|
|
64
72
|
"indexes": [],
|
|
65
73
|
"schema": "@autopass/delete",
|
|
66
74
|
"derived": false,
|
|
67
|
-
"key": [
|
|
75
|
+
"key": [
|
|
76
|
+
"key"
|
|
77
|
+
],
|
|
68
78
|
"trigger": null
|
|
69
79
|
},
|
|
70
80
|
{
|
|
@@ -77,7 +87,9 @@
|
|
|
77
87
|
"indexes": [],
|
|
78
88
|
"schema": "@autopass/del-invite",
|
|
79
89
|
"derived": false,
|
|
80
|
-
"key": [
|
|
90
|
+
"key": [
|
|
91
|
+
"id"
|
|
92
|
+
],
|
|
81
93
|
"trigger": null
|
|
82
94
|
},
|
|
83
95
|
{
|
|
@@ -90,8 +102,10 @@
|
|
|
90
102
|
"indexes": [],
|
|
91
103
|
"schema": "@autopass/del-mirror",
|
|
92
104
|
"derived": false,
|
|
93
|
-
"key": [
|
|
105
|
+
"key": [
|
|
106
|
+
"key"
|
|
107
|
+
],
|
|
94
108
|
"trigger": null
|
|
95
109
|
}
|
|
96
110
|
]
|
|
97
|
-
}
|
|
111
|
+
}
|