git ssb

0+

dangerousbeans / web-bootloader



forked from Dominic / web-bootloader

Tree: ef1a2eaa163709173d29cc9f3fc446695e466fe7

Files: ef1a2eaa163709173d29cc9f3fc446695e466fe7 / _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