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

27 lines
930 B
TypeScript

import { asUint8Array } from './util/as-uint8array.js'
import bases, { type SupportedEncodings } from './util/bases.js'
export type { SupportedEncodings }
/**
* Create a `Uint8Array` from the passed string
*
* Supports `utf8`, `utf-8`, `hex`, and any encoding supported by the multiformats module.
*
* Also `ascii` which is similar to node's 'binary' encoding.
*/
export function fromString (string: string, encoding: SupportedEncodings = 'utf8'): Uint8Array {
const base = bases[encoding]
if (base == null) {
throw new Error(`Unsupported encoding "${encoding}"`)
}
if ((encoding === 'utf8' || encoding === 'utf-8') && globalThis.Buffer != null && globalThis.Buffer.from != null) {
return asUint8Array(globalThis.Buffer.from(string, 'utf-8'))
}
// add multibase prefix
return base.decoder.decode(`${base.prefix}${string}`) // eslint-disable-line @typescript-eslint/restrict-template-expressions
}