@blockcerts/hashlink-verifier
Version:
Handling hashlinks in Blockcerts
11 lines (10 loc) • 314 B
text/typescript
export function stringToUint8Array (data: string | Uint8Array): Uint8Array {
if (typeof data === 'string') {
// convert data to Uint8Array
return new TextEncoder().encode(data);
}
if (!(data instanceof Uint8Array)) {
throw new TypeError('"data" be a string or Uint8Array.');
}
return data;
}