Skip to content

Commit 1cfa5fe

Browse files
committed
feat: finish decodePrivate
1 parent 17f2650 commit 1cfa5fe

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/decodePrivate.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
11
export default (sbot) => (data, cb) => {
2-
cb(null, data)
2+
if (typeof data.content === 'string') {
3+
sbot.unbox(data.content, (err, unboxed) => {
4+
cb(
5+
err,
6+
{
7+
...data,
8+
content: unboxed
9+
}
10+
)
11+
})
12+
} else {
13+
cb(null, data)
14+
}
315
}

src/decodePrivate.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import test from "ava"
22
import decodePrivate from './decodePrivate.js'
33

4-
function unecrypt(data) {
4+
function uncrypt(data) {
55
return data.replace(/\*/g, '')
66
}
77

@@ -28,15 +28,15 @@ test('decode encrypted msgs', (t) => {
2828
const sbot = {
2929
unbox(cypher, cb) {
3030
t.is(cypher, data.content)
31-
cb(null, unecrypt(cypher))
31+
cb(null, { text: uncrypt(cypher) })
3232
}
3333
}
3434
return new Promise((resolve) => {
3535
const done = (err, d) => {
3636
t.is(err, null)
3737
t.is(
3838
d.content.text,
39-
unecrypt(data.content)
39+
uncrypt(data.content)
4040
)
4141
resolve()
4242
}

0 commit comments

Comments
 (0)