(uuid: string)
| 38 | } |
| 39 | |
| 40 | function parseUuid(uuid: string): Uint8Array { |
| 41 | const hex = uuid.replace(/-/g, '') |
| 42 | |
| 43 | if (!/^[0-9a-fA-F]{32}$/.test(hex)) { |
| 44 | throw new Error(`Invalid UUID: ${uuid}`) |
| 45 | } |
| 46 | |
| 47 | return Uint8Array.from( |
| 48 | Array.from({ length: 16 }, (_, index) => |
| 49 | Number.parseInt(hex.slice(index * 2, index * 2 + 2), 16), |
| 50 | ), |
| 51 | ) |
| 52 | } |
| 53 | |
| 54 | function stringifyUuid(bytes: Uint8Array): string { |
| 55 | if (bytes.length !== 16) { |