Dorian 0d073fa89e Add comprehensive installation and setup documentation
- 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
2026-01-27 17:18:21 +00:00

67 lines
1.5 KiB
JavaScript

/* Common package for dealing with hex/string/uint8 conversions (and sha1 hashing)
*
* @author Jimmy Wärting <jimmy@warting.se> (https://jimmy.warting.se/opensource)
* @license MIT
*/
export const alphabet = '0123456789abcdef'
const encodeLookup = []
const decodeLookup = []
for (let i = 0; i < 256; i++) {
encodeLookup[i] = alphabet[i >> 4 & 0xf] + alphabet[i & 0xf]
if (i < 16) {
if (i < 10) {
decodeLookup[0x30 + i] = i
} else {
decodeLookup[0x61 - 10 + i] = i
}
}
}
export const arr2hex = data => {
const length = data.length
let string = ''
let i = 0
while (i < length) {
string += encodeLookup[data[i++]]
}
return string
}
export const hex2arr = str => {
const sizeof = str.length >> 1
const length = sizeof << 1
const array = new Uint8Array(sizeof)
let n = 0
let i = 0
while (i < length) {
array[n++] = decodeLookup[str.charCodeAt(i++)] << 4 | decodeLookup[str.charCodeAt(i++)]
}
return array
}
export const concat = (chunks, size = 0) => {
const length = chunks.length || 0
if (!size) {
let i = length
while (i--) size += chunks[i].length
}
const b = new Uint8Array(size)
let offset = size
let i = length
while (i--) {
offset -= chunks[i].length
b.set(chunks[i], offset)
}
return b
}
export const equal = (a, b) => {
if (a.length !== b.length) return false
for (let i = a.length; i > -1; i -= 1) {
if ((a[i] !== b[i])) return false
}
return true
}