@mblaney/holster 0.1.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.
- package/.github/workflows/node.js.yml +31 -0
- package/LICENSE.md +55 -0
- package/README.md +24 -0
- package/build/holster.js +4 -0
- package/build/holster.js.map +7 -0
- package/examples/index.html +33 -0
- package/examples/index.js +49 -0
- package/examples/user.html +31 -0
- package/examples/user.js +88 -0
- package/examples/wire.html +27 -0
- package/examples/wire.js +55 -0
- package/package.json +44 -0
- package/src/array.js +34 -0
- package/src/buffer.js +83 -0
- package/src/dup.js +23 -0
- package/src/get.js +19 -0
- package/src/ham.js +151 -0
- package/src/holster.js +502 -0
- package/src/index.js +21 -0
- package/src/radisk.js +438 -0
- package/src/radix.js +106 -0
- package/src/sea-utils.js +65 -0
- package/src/sea.js +224 -0
- package/src/store.js +225 -0
- package/src/user.js +330 -0
- package/src/utils.js +124 -0
- package/src/wire.js +290 -0
- package/test/holster.get.test.js +60 -0
- package/test/holster.lex.test.js +196 -0
- package/test/holster.off.test.js +53 -0
- package/test/holster.on.test.js +168 -0
- package/test/holster.put.test.js +278 -0
- package/test/holster.secure.test.js +210 -0
- package/test/holster.user.get.test.js +86 -0
- package/test/holster.user.lex.test.js +148 -0
- package/test/holster.user.off.test.js +72 -0
- package/test/holster.user.on.test.js +185 -0
- package/test/holster.user.put.test.js +381 -0
- package/test/kitty/! +9 -0
- package/test/names.js +225 -0
- package/test/radisk.test.js +191 -0
- package/test/radix.test.js +117 -0
- package/test/sea.test.js +284 -0
- package/test/store.test.js +316 -0
- package/test/user.test.js +173 -0
- package/test/wire.test.js +159 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import {describe, test} from "node:test"
|
|
2
|
+
import assert from "node:assert/strict"
|
|
3
|
+
import Radisk from "../src/radisk.js"
|
|
4
|
+
import Names from "./names.js"
|
|
5
|
+
const names = Names()
|
|
6
|
+
|
|
7
|
+
describe("radisk", () => {
|
|
8
|
+
const puts = {}
|
|
9
|
+
const opt = {
|
|
10
|
+
write: 1,
|
|
11
|
+
batch: 2,
|
|
12
|
+
size: 100,
|
|
13
|
+
store: {
|
|
14
|
+
get: (file, cb) => {
|
|
15
|
+
cb(null, puts[file])
|
|
16
|
+
},
|
|
17
|
+
put: (file, data, cb) => {
|
|
18
|
+
puts[file] = data
|
|
19
|
+
cb(null)
|
|
20
|
+
},
|
|
21
|
+
list: cb => {
|
|
22
|
+
Object.keys(puts).sort().forEach(cb)
|
|
23
|
+
cb(null)
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
}
|
|
27
|
+
const radisk = Radisk(opt)
|
|
28
|
+
|
|
29
|
+
test("write and read from memory", (t, done) => {
|
|
30
|
+
radisk("key", "value", () => {
|
|
31
|
+
assert.deepEqual(puts, {"!": '\x1F+0\x1F#\x1F"key\x1F=\x1F"value\x1F\n'})
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
// Reading after write means radisk.batch is still available.
|
|
35
|
+
radisk("key", (err, value) => {
|
|
36
|
+
assert.equal(value, "value")
|
|
37
|
+
done()
|
|
38
|
+
})
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
test("read from store", (t, done) => {
|
|
42
|
+
// Waiting until after opt.write means radisk.batch has been reset, so a
|
|
43
|
+
// call to radisk.read is required which means the file needs to be parsed.
|
|
44
|
+
setTimeout(() => {
|
|
45
|
+
radisk("key", (err, value) => {
|
|
46
|
+
assert.equal(value, "value")
|
|
47
|
+
done()
|
|
48
|
+
})
|
|
49
|
+
}, opt.write + 1)
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
test("write and read value with state", (t, done) => {
|
|
53
|
+
radisk("key", ["value", 1234])
|
|
54
|
+
setTimeout(() => {
|
|
55
|
+
assert.deepEqual(puts, {
|
|
56
|
+
"!": '\x1F+0\x1F#\x1F"key\x1F=\x1F"value\x031234\x1F\n',
|
|
57
|
+
})
|
|
58
|
+
radisk("key", (err, value) => {
|
|
59
|
+
assert.deepEqual(value, ["value", 1234])
|
|
60
|
+
done()
|
|
61
|
+
})
|
|
62
|
+
}, 10)
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
test("write and read a plain object is undefined", (t, done) => {
|
|
66
|
+
radisk("key", {object: true})
|
|
67
|
+
setTimeout(() => {
|
|
68
|
+
assert.deepEqual(puts, {
|
|
69
|
+
"!": '\x1F+0\x1F#\x1F"key\x1F=undefined\n',
|
|
70
|
+
})
|
|
71
|
+
radisk("key", (err, value) => {
|
|
72
|
+
assert.deepEqual(value, undefined)
|
|
73
|
+
done()
|
|
74
|
+
})
|
|
75
|
+
}, 10)
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
test("write a plain object with state is also undefined", (t, done) => {
|
|
79
|
+
radisk("key", [{object: true}, 1234])
|
|
80
|
+
setTimeout(() => {
|
|
81
|
+
assert.deepEqual(puts, {
|
|
82
|
+
"!": '\x1F+0\x1F#\x1F"key\x1F=undefined\n',
|
|
83
|
+
})
|
|
84
|
+
radisk("key", (err, value) => {
|
|
85
|
+
assert.deepEqual(value, undefined)
|
|
86
|
+
done()
|
|
87
|
+
})
|
|
88
|
+
}, 10)
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
test("write and read a soul relation is ok", (t, done) => {
|
|
92
|
+
const rel = {"#": "soul"}
|
|
93
|
+
radisk("key", rel)
|
|
94
|
+
setTimeout(() => {
|
|
95
|
+
assert.deepEqual(puts, {
|
|
96
|
+
"!": '\x1F+0\x1F#\x1F"key\x1F=\x1F#soul\x1F\n',
|
|
97
|
+
})
|
|
98
|
+
radisk("key", (err, value) => {
|
|
99
|
+
assert.deepEqual(value, rel)
|
|
100
|
+
done()
|
|
101
|
+
})
|
|
102
|
+
}, 10)
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
test("write and read a soul relation with state is ok", (t, done) => {
|
|
106
|
+
const rel = [{"#": "soul"}, 1234]
|
|
107
|
+
radisk("key", rel)
|
|
108
|
+
setTimeout(() => {
|
|
109
|
+
assert.deepEqual(puts, {
|
|
110
|
+
"!": '\x1F+0\x1F#\x1F"key\x1F=\x1F#soul\x031234\x1F\n',
|
|
111
|
+
})
|
|
112
|
+
radisk("key", (err, value) => {
|
|
113
|
+
assert.deepEqual(value, rel)
|
|
114
|
+
done()
|
|
115
|
+
})
|
|
116
|
+
}, 10)
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
test("write and read value with newline", (t, done) => {
|
|
120
|
+
radisk("key", "value\ncontinued")
|
|
121
|
+
setTimeout(() => {
|
|
122
|
+
assert.deepEqual(puts, {
|
|
123
|
+
"!": '\x1F+0\x1F#\x1F"key\x1F=\x1F"value\ncontinued\x1F\n',
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
radisk("key", (err, value) => {
|
|
127
|
+
assert.equal(value, "value\ncontinued")
|
|
128
|
+
done()
|
|
129
|
+
})
|
|
130
|
+
}, 10)
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
test("write and read value with newline and state", (t, done) => {
|
|
134
|
+
radisk("key", ["value\ncontinued", 12345])
|
|
135
|
+
setTimeout(() => {
|
|
136
|
+
assert.deepEqual(puts, {
|
|
137
|
+
"!": '\x1F+0\x1F#\x1F"key\x1F=\x1F"value\ncontinued\x0312345\x1F\n',
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
radisk("key", (err, value) => {
|
|
141
|
+
assert.deepEqual(value, ["value\ncontinued", 12345])
|
|
142
|
+
done()
|
|
143
|
+
})
|
|
144
|
+
}, 10)
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
test("write more than batch size", (t, done) => {
|
|
148
|
+
radisk("keyA", "valueA")
|
|
149
|
+
radisk("keyB", "valueB")
|
|
150
|
+
radisk("keyC", "valueC")
|
|
151
|
+
setTimeout(() => {
|
|
152
|
+
assert.deepEqual(puts, {
|
|
153
|
+
"!":
|
|
154
|
+
'\x1F+0\x1F#\x1F"key\x1F=\x1F"value\ncontinued\x0312345\x1F\n' +
|
|
155
|
+
'\x1F+1\x1F#\x1F"A\x1F=\x1F"valueA\x1F\n' +
|
|
156
|
+
'\x1F+1\x1F#\x1F"B\x1F=\x1F"valueB\x1F\n' +
|
|
157
|
+
'\x1F+1\x1F#\x1F"C\x1F=\x1F"valueC\x1F\n',
|
|
158
|
+
})
|
|
159
|
+
radisk("keyA", (err, value) => {
|
|
160
|
+
assert.equal(value, "valueA")
|
|
161
|
+
done()
|
|
162
|
+
})
|
|
163
|
+
}, 10)
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
test("write and read value bigger than file size", (t, done) => {
|
|
167
|
+
const big =
|
|
168
|
+
"file size is only 100 bytes so writing this value requires calling slice"
|
|
169
|
+
radisk("newFile", big)
|
|
170
|
+
radisk("newFile", (err, value) => {
|
|
171
|
+
assert.equal(value, big)
|
|
172
|
+
})
|
|
173
|
+
setTimeout(() => {
|
|
174
|
+
assert.deepEqual(puts, {
|
|
175
|
+
"!":
|
|
176
|
+
'\x1F+0\x1F#\x1F"key\x1F=\x1F"value\ncontinued\x0312345\x1F\n' +
|
|
177
|
+
'\x1F+1\x1F#\x1F"A\x1F=\x1F"valueA\x1F\n' +
|
|
178
|
+
'\x1F+1\x1F#\x1F"B\x1F=\x1F"valueB\x1F\n' +
|
|
179
|
+
'\x1F+1\x1F#\x1F"C\x1F=\x1F \x1F\n',
|
|
180
|
+
keyC:
|
|
181
|
+
'\x1F+0\x1F#\x1F"keyC\x1F=\x1F"valueC\x1F\n' +
|
|
182
|
+
'\x1F+0\x1F#\x1F"newFile\x1F=\x1F \x1F\n',
|
|
183
|
+
newFile: '\x1F+0\x1F#\x1F"newFile\x1F=\x1F"' + big + "\x1F\n",
|
|
184
|
+
})
|
|
185
|
+
radisk("newFile", (err, value) => {
|
|
186
|
+
assert.equal(value, big)
|
|
187
|
+
done()
|
|
188
|
+
})
|
|
189
|
+
}, 10)
|
|
190
|
+
})
|
|
191
|
+
})
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import {describe, test} from "node:test"
|
|
2
|
+
import assert from "node:assert/strict"
|
|
3
|
+
import Radix from "../src/radix.js"
|
|
4
|
+
import Names from "./names.js"
|
|
5
|
+
const names = Names()
|
|
6
|
+
|
|
7
|
+
// ASCII character for group separator.
|
|
8
|
+
const group = String.fromCharCode(29)
|
|
9
|
+
// ASCII character for record separator.
|
|
10
|
+
const record = String.fromCharCode(30)
|
|
11
|
+
|
|
12
|
+
describe("radix", () => {
|
|
13
|
+
const radix = Radix()
|
|
14
|
+
|
|
15
|
+
test("unit", () => {
|
|
16
|
+
radix("asdf.pub", "yum")
|
|
17
|
+
radix("ablah", "cool")
|
|
18
|
+
radix("abc", {yes: 1})
|
|
19
|
+
radix("node/circle.bob", "awesome")
|
|
20
|
+
|
|
21
|
+
assert.deepEqual(radix("asdf."), {pub: {[record]: "yum"}})
|
|
22
|
+
assert.equal(radix("nv/foo.bar"), undefined)
|
|
23
|
+
assert.equal(radix("ablah"), "cool")
|
|
24
|
+
assert.deepEqual(radix("abc"), {yes: 1})
|
|
25
|
+
assert.equal(radix("abcd"), undefined)
|
|
26
|
+
assert.deepEqual(radix(), {
|
|
27
|
+
a: {
|
|
28
|
+
[group]: {
|
|
29
|
+
"sdf.pub": {[record]: "yum"},
|
|
30
|
+
b: {
|
|
31
|
+
[group]: {
|
|
32
|
+
c: {
|
|
33
|
+
[record]: {
|
|
34
|
+
yes: 1,
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
lah: {
|
|
38
|
+
[record]: "cool",
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
"node/circle.bob": {[record]: "awesome"},
|
|
45
|
+
})
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
test("replace", () => {
|
|
49
|
+
radix("asdf.pub", "yuck")
|
|
50
|
+
radix("ablah", "cool!")
|
|
51
|
+
radix("abc", {yes: 2})
|
|
52
|
+
radix("node/circle.bob", "awe")
|
|
53
|
+
radix("abcd", true)
|
|
54
|
+
|
|
55
|
+
assert.deepEqual(radix("asdf."), {pub: {[record]: "yuck"}})
|
|
56
|
+
assert.equal(radix("ablah"), "cool!")
|
|
57
|
+
assert.equal(radix("nv/foo.bar"), undefined)
|
|
58
|
+
assert.deepEqual(radix("abc"), {yes: 2})
|
|
59
|
+
assert.equal(radix("abcd"), true)
|
|
60
|
+
assert.deepEqual(radix(), {
|
|
61
|
+
a: {
|
|
62
|
+
[group]: {
|
|
63
|
+
"sdf.pub": {[record]: "yuck"},
|
|
64
|
+
b: {
|
|
65
|
+
[group]: {
|
|
66
|
+
c: {
|
|
67
|
+
[group]: {
|
|
68
|
+
d: {
|
|
69
|
+
[record]: true,
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
[record]: {
|
|
73
|
+
yes: 2,
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
lah: {
|
|
77
|
+
[record]: "cool!",
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
"node/circle.bob": {[record]: "awe"},
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
test("radix write read", () => {
|
|
88
|
+
// Add some shorter values to also force group matching in Radix.map.
|
|
89
|
+
radix("A", 1)
|
|
90
|
+
radix("Be", 2)
|
|
91
|
+
radix("Bo", 3)
|
|
92
|
+
radix("L", 4)
|
|
93
|
+
radix("Mi", 5)
|
|
94
|
+
var all = {}
|
|
95
|
+
names.forEach((value, index) => {
|
|
96
|
+
all[value] = index
|
|
97
|
+
radix(value, index)
|
|
98
|
+
})
|
|
99
|
+
assert.equal(Object.keys(all).length, names.length)
|
|
100
|
+
Radix.map(radix, (value, key) => {
|
|
101
|
+
delete all[key]
|
|
102
|
+
})
|
|
103
|
+
assert.equal(Object.keys(all).length, 0)
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
test("radix read again", () => {
|
|
107
|
+
var all = {}
|
|
108
|
+
names.forEach((value, index) => {
|
|
109
|
+
all[value] = index
|
|
110
|
+
})
|
|
111
|
+
assert.equal(Object.keys(all).length, names.length)
|
|
112
|
+
Radix.map(radix, (value, key) => {
|
|
113
|
+
delete all[key]
|
|
114
|
+
})
|
|
115
|
+
assert.equal(Object.keys(all).length, 0)
|
|
116
|
+
})
|
|
117
|
+
})
|
package/test/sea.test.js
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import {describe, test} from "node:test"
|
|
2
|
+
import assert from "node:assert/strict"
|
|
3
|
+
import SEA from "../src/sea.js"
|
|
4
|
+
|
|
5
|
+
// The JWK format uses "base64url" encoding, which means "+" replaced with "-"
|
|
6
|
+
// and "/" with "_" and removing "=" padding. So public and private keys here
|
|
7
|
+
// are strings of alphanumeric characters and underscores (regex: \w), as well
|
|
8
|
+
// as dashes. The x and y values of public keys are joined by a full stop, so
|
|
9
|
+
// these conditions match the following two regular expressions:
|
|
10
|
+
const pubRegex = /^(\w|\-)+\.(\w|\-)+$/
|
|
11
|
+
const privRegex = /^(\w|\-)+$/
|
|
12
|
+
|
|
13
|
+
describe("SEA", () => {
|
|
14
|
+
test("pair await", (t, done) => {
|
|
15
|
+
;(async () => {
|
|
16
|
+
const pair = await SEA.pair()
|
|
17
|
+
assert.match(pair.pub, pubRegex)
|
|
18
|
+
assert.match(pair.priv, privRegex)
|
|
19
|
+
assert.match(pair.epub, pubRegex)
|
|
20
|
+
assert.match(pair.epriv, privRegex)
|
|
21
|
+
done()
|
|
22
|
+
})()
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
test("pair callback", (t, done) => {
|
|
26
|
+
SEA.pair(pair => {
|
|
27
|
+
assert.match(pair.pub, pubRegex)
|
|
28
|
+
assert.match(pair.priv, privRegex)
|
|
29
|
+
assert.match(pair.epub, pubRegex)
|
|
30
|
+
assert.match(pair.epriv, privRegex)
|
|
31
|
+
done()
|
|
32
|
+
})
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
test("encrypt and decrypt string await", (t, done) => {
|
|
36
|
+
;(async () => {
|
|
37
|
+
const pair = await SEA.pair()
|
|
38
|
+
const enc = await SEA.encrypt("hello self", pair)
|
|
39
|
+
const dec = await SEA.decrypt(enc, pair)
|
|
40
|
+
assert.equal(dec, "hello self")
|
|
41
|
+
done()
|
|
42
|
+
})()
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
test("encrypt and decrypt with wrong key", (t, done) => {
|
|
46
|
+
;(async () => {
|
|
47
|
+
const alice = await SEA.pair()
|
|
48
|
+
const bob = await SEA.pair()
|
|
49
|
+
const enc = await SEA.encrypt("alice secret", alice)
|
|
50
|
+
const dec = await SEA.decrypt(enc, bob)
|
|
51
|
+
assert.equal(dec, null)
|
|
52
|
+
done()
|
|
53
|
+
})()
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
test("encrypt and decrypt string callback", (t, done) => {
|
|
57
|
+
SEA.pair(pair => {
|
|
58
|
+
SEA.encrypt("hello self", pair, enc => {
|
|
59
|
+
SEA.decrypt(enc, pair, dec => {
|
|
60
|
+
assert.equal(dec, "hello self")
|
|
61
|
+
done()
|
|
62
|
+
})
|
|
63
|
+
})
|
|
64
|
+
})
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
test("encrypt and decrypt object await", (t, done) => {
|
|
68
|
+
;(async () => {
|
|
69
|
+
const pair = await SEA.pair()
|
|
70
|
+
const enc = await SEA.encrypt({test: "hello self"}, pair)
|
|
71
|
+
const dec = await SEA.decrypt(enc, pair)
|
|
72
|
+
assert.deepEqual(dec, {test: "hello self"})
|
|
73
|
+
done()
|
|
74
|
+
})()
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
test("encrypt and decrypt object callback", (t, done) => {
|
|
78
|
+
SEA.pair(pair => {
|
|
79
|
+
SEA.encrypt({test: "hello self"}, pair, enc => {
|
|
80
|
+
SEA.decrypt(enc, pair, dec => {
|
|
81
|
+
assert.deepEqual(dec, {test: "hello self"})
|
|
82
|
+
done()
|
|
83
|
+
})
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
test("sign and verify string await", (t, done) => {
|
|
89
|
+
;(async () => {
|
|
90
|
+
const pair = await SEA.pair()
|
|
91
|
+
const signed = await SEA.sign("hello self", pair)
|
|
92
|
+
const verified = await SEA.verify(signed, pair)
|
|
93
|
+
assert.equal(verified, "hello self")
|
|
94
|
+
done()
|
|
95
|
+
})()
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
test("sign and verify with wrong key", (t, done) => {
|
|
99
|
+
;(async () => {
|
|
100
|
+
const alice = await SEA.pair()
|
|
101
|
+
const bob = await SEA.pair()
|
|
102
|
+
const signed = await SEA.sign("signed by alice", alice)
|
|
103
|
+
const verified = await SEA.verify(signed, bob)
|
|
104
|
+
assert.equal(verified, null)
|
|
105
|
+
done()
|
|
106
|
+
})()
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
test("sign and verify string callback", (t, done) => {
|
|
110
|
+
SEA.pair(pair => {
|
|
111
|
+
SEA.sign("hello self", pair, signed => {
|
|
112
|
+
SEA.verify(signed, pair, verified => {
|
|
113
|
+
assert.equal(verified, "hello self")
|
|
114
|
+
done()
|
|
115
|
+
})
|
|
116
|
+
})
|
|
117
|
+
})
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
test("sign and verify object await", (t, done) => {
|
|
121
|
+
;(async () => {
|
|
122
|
+
const pair = await SEA.pair()
|
|
123
|
+
const signed = await SEA.sign({test: "hello self"}, pair)
|
|
124
|
+
const verified = await SEA.verify(signed, pair)
|
|
125
|
+
assert.deepEqual(verified, {test: "hello self"})
|
|
126
|
+
done()
|
|
127
|
+
})()
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
test("sign and verify object callback", (t, done) => {
|
|
131
|
+
SEA.pair(pair => {
|
|
132
|
+
SEA.sign({test: "hello self"}, pair, signed => {
|
|
133
|
+
SEA.verify(signed, pair, verified => {
|
|
134
|
+
assert.deepEqual(verified, {test: "hello self"})
|
|
135
|
+
done()
|
|
136
|
+
})
|
|
137
|
+
})
|
|
138
|
+
})
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
test("work with salt encrypt string callback", (t, done) => {
|
|
142
|
+
SEA.work("hello", "salt", work => {
|
|
143
|
+
SEA.encrypt("hello work", work, enc => {
|
|
144
|
+
SEA.decrypt(enc, work, dec => {
|
|
145
|
+
assert.equal(dec, "hello work")
|
|
146
|
+
done()
|
|
147
|
+
})
|
|
148
|
+
})
|
|
149
|
+
})
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
test("work with salt encrypt string await", (t, done) => {
|
|
153
|
+
;(async () => {
|
|
154
|
+
const work = await SEA.work("hello", "salt")
|
|
155
|
+
const enc = await SEA.encrypt("hello work", work)
|
|
156
|
+
const dec = await SEA.decrypt(enc, work)
|
|
157
|
+
assert.equal(dec, "hello work")
|
|
158
|
+
done()
|
|
159
|
+
})()
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
test("work with salt encrypt object callback", (t, done) => {
|
|
163
|
+
SEA.work("hello", "salt", work => {
|
|
164
|
+
SEA.encrypt({test: "hello work"}, work, enc => {
|
|
165
|
+
SEA.decrypt(enc, work, dec => {
|
|
166
|
+
assert.deepEqual(dec, {test: "hello work"})
|
|
167
|
+
done()
|
|
168
|
+
})
|
|
169
|
+
})
|
|
170
|
+
})
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
test("work with salt encrypt object await", (t, done) => {
|
|
174
|
+
;(async () => {
|
|
175
|
+
const work = await SEA.work("hello", "salt")
|
|
176
|
+
const enc = await SEA.encrypt({test: "hello work"}, work)
|
|
177
|
+
const dec = await SEA.decrypt(enc, work)
|
|
178
|
+
assert.deepEqual(dec, {test: "hello work"})
|
|
179
|
+
done()
|
|
180
|
+
})()
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
test("work no salt encrypt string callback", (t, done) => {
|
|
184
|
+
SEA.work("hello", work => {
|
|
185
|
+
SEA.encrypt("hello work", work, enc => {
|
|
186
|
+
SEA.decrypt(enc, work, dec => {
|
|
187
|
+
assert.equal(dec, "hello work")
|
|
188
|
+
done()
|
|
189
|
+
})
|
|
190
|
+
})
|
|
191
|
+
})
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
test("work no salt encrypt string await", (t, done) => {
|
|
195
|
+
;(async () => {
|
|
196
|
+
const work = await SEA.work("hello")
|
|
197
|
+
const enc = await SEA.encrypt("hello work", work)
|
|
198
|
+
const dec = await SEA.decrypt(enc, work)
|
|
199
|
+
assert.equal(dec, "hello work")
|
|
200
|
+
done()
|
|
201
|
+
})()
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
test("work no salt encrypt object callback", (t, done) => {
|
|
205
|
+
SEA.work("hello", work => {
|
|
206
|
+
SEA.encrypt({test: "hello work"}, work, enc => {
|
|
207
|
+
SEA.decrypt(enc, work, dec => {
|
|
208
|
+
assert.deepEqual(dec, {test: "hello work"})
|
|
209
|
+
done()
|
|
210
|
+
})
|
|
211
|
+
})
|
|
212
|
+
})
|
|
213
|
+
})
|
|
214
|
+
|
|
215
|
+
test("work no salt encrypt object await", (t, done) => {
|
|
216
|
+
;(async () => {
|
|
217
|
+
const work = await SEA.work("hello")
|
|
218
|
+
const enc = await SEA.encrypt({test: "hello work"}, work)
|
|
219
|
+
const dec = await SEA.decrypt(enc, work)
|
|
220
|
+
assert.deepEqual(dec, {test: "hello work"})
|
|
221
|
+
done()
|
|
222
|
+
})()
|
|
223
|
+
})
|
|
224
|
+
|
|
225
|
+
test("secret string callback", (t, done) => {
|
|
226
|
+
SEA.pair(alice => {
|
|
227
|
+
SEA.pair(bob => {
|
|
228
|
+
SEA.secret(bob, alice, to => {
|
|
229
|
+
SEA.encrypt("shared data", to, enc => {
|
|
230
|
+
SEA.secret(alice, bob, from => {
|
|
231
|
+
SEA.decrypt(enc, from, dec => {
|
|
232
|
+
assert.equal(dec, "shared data")
|
|
233
|
+
done()
|
|
234
|
+
})
|
|
235
|
+
})
|
|
236
|
+
})
|
|
237
|
+
})
|
|
238
|
+
})
|
|
239
|
+
})
|
|
240
|
+
})
|
|
241
|
+
|
|
242
|
+
test("secret string await", (t, done) => {
|
|
243
|
+
;(async () => {
|
|
244
|
+
const alice = await SEA.pair()
|
|
245
|
+
const bob = await SEA.pair()
|
|
246
|
+
const to = await SEA.secret(bob, alice)
|
|
247
|
+
const enc = await SEA.encrypt("shared data", to)
|
|
248
|
+
const from = await SEA.secret(alice, bob)
|
|
249
|
+
const dec = await SEA.decrypt(enc, from)
|
|
250
|
+
assert.equal(dec, "shared data")
|
|
251
|
+
done()
|
|
252
|
+
})()
|
|
253
|
+
})
|
|
254
|
+
|
|
255
|
+
test("secret object callback", (t, done) => {
|
|
256
|
+
SEA.pair(alice => {
|
|
257
|
+
SEA.pair(bob => {
|
|
258
|
+
SEA.secret(bob, alice, to => {
|
|
259
|
+
SEA.encrypt({test: "shared data"}, to, enc => {
|
|
260
|
+
SEA.secret(alice, bob, from => {
|
|
261
|
+
SEA.decrypt(enc, from, dec => {
|
|
262
|
+
assert.deepEqual(dec, {test: "shared data"})
|
|
263
|
+
done()
|
|
264
|
+
})
|
|
265
|
+
})
|
|
266
|
+
})
|
|
267
|
+
})
|
|
268
|
+
})
|
|
269
|
+
})
|
|
270
|
+
})
|
|
271
|
+
|
|
272
|
+
test("secret object await", (t, done) => {
|
|
273
|
+
;(async () => {
|
|
274
|
+
const alice = await SEA.pair()
|
|
275
|
+
const bob = await SEA.pair()
|
|
276
|
+
const to = await SEA.secret(bob, alice)
|
|
277
|
+
const enc = await SEA.encrypt({test: "shared data"}, to)
|
|
278
|
+
const from = await SEA.secret(alice, bob)
|
|
279
|
+
const dec = await SEA.decrypt(enc, from)
|
|
280
|
+
assert.deepEqual(dec, {test: "shared data"})
|
|
281
|
+
done()
|
|
282
|
+
})()
|
|
283
|
+
})
|
|
284
|
+
})
|