git ssb

0+

dangerousbeans / web-bootloader



forked from Dominic / web-bootloader

Tree: d67c2ef5cf3682981ede79ed8a64b2b1cfdd31a5

Files: d67c2ef5cf3682981ede79ed8a64b2b1cfdd31a5 / _util.js

639 bytesRaw
1
2var u = exports
3
4u.toUtf8 = function (data) {
5 return 'string' == typeof data ? data : new Buffer(data).toString('utf8')
6}
7
8u.toBuffer = function (data) {
9 return 'string' !== typeof data
10 ? data
11 : new Buffer(data)
12}
13
14u.toBase64 = require('arraybuffer-base64')
15
16var crypto = require('crypto')
17
18u.hash = function (data, cb) {
19 setImmediate(function () {
20 cb(null,
21 crypto.createHash('sha256').update(data).digest('base64')
22 )
23 })
24}
25
26u.parse = function (str) {
27 try {
28 return JSON.parse(str)
29 } catch (_) { }
30}
31
32u.HashError = function (_id, id) {
33 return new Error('incorrect hash:'+_id+'\n expected:'+id)
34}
35
36
37
38
39

Built with git-ssb-web