Skip to content

Commit aef927c

Browse files
committed
finish decodePrivate
1 parent bf50162 commit aef927c

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

lib/decodePrivate.mjs

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
}

lib/decodePrivate.test.mjs

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'
33

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

@@ -27,14 +27,14 @@ test.cb('decode encrypted msgs', (t) => {
2727
t.is(err, null)
2828
t.is(
2929
d.content.text,
30-
unecrypt(data.content)
30+
uncrypt(data.content)
3131
)
3232
t.end()
3333
}
3434
const sbot = {
3535
unbox(cypher, cb) {
3636
t.is(cypher, data.content)
37-
cb(null, unecrypt(cypher))
37+
cb(null, {text: uncrypt(cypher)})
3838
}
3939
}
4040
decodePrivate(sbot)(data, done)

0 commit comments

Comments
 (0)