- Add GETTING_STARTED.md with quick start guide and development modes - Add INSTALL.sh automated installation script - Add INSTALLATION_CHECKLIST.md, INSTALLATION_SUCCESS.md, and INSTALLATION_SUMMARY.md - Add QUICK_REFERENCE.md for common commands - Add SETUP_GUIDE.md with detailed setup instructions - Update README.md with improved project overview - Add did-wallet app dependencies and node_modules
34 lines
1.0 KiB
JavaScript
34 lines
1.0 KiB
JavaScript
import { createHash, randomBytes as rand } from 'node:crypto'
|
|
|
|
const decoder = new TextDecoder()
|
|
export const arr2text = (data, enc) => {
|
|
if (data.byteLength > 1024) {
|
|
if (!enc) return decoder.decode(data)
|
|
const dec = new TextDecoder(enc)
|
|
return dec.decode(data)
|
|
}
|
|
return Buffer.from(data).toString(enc || 'utf8')
|
|
}
|
|
|
|
export const text2arr = str => new Uint8Array(Buffer.from(str, 'utf8'))
|
|
|
|
export const arr2base = data => Buffer.from(data).toString('base64')
|
|
|
|
export const base2arr = str => new Uint8Array(Buffer.from(str, 'base64'))
|
|
|
|
export const hex2bin = hex => Buffer.from(hex, 'hex').toString('binary')
|
|
|
|
export const bin2hex = bin => Buffer.from(bin, 'binary').toString('hex')
|
|
|
|
export const hash = async (data, format, algo = 'sha1') => {
|
|
algo = algo.replace('sha-', 'sha')
|
|
const out = createHash(algo).update(data)
|
|
return format ? out.digest(format) : new Uint8Array(out.digest().buffer)
|
|
}
|
|
|
|
export const randomBytes = size => {
|
|
return new Uint8Array(rand(size))
|
|
}
|
|
|
|
export * from './util.js'
|