{"id":44340331,"url":"https://github.com/ali-master/uuidv47","last_synced_at":"2026-02-11T12:56:20.015Z","repository":{"id":315461788,"uuid":"1059600246","full_name":"ali-master/uuidv47","owner":"ali-master","description":"Reversible UUID v4/v7 transformation using SipHash-2-4 cryptography. Hide time-ordering from external APIs while maintaining internal chronological benefits.","archived":false,"fork":false,"pushed_at":"2025-10-07T20:19:29.000Z","size":1727,"stargazers_count":116,"open_issues_count":2,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-07T22:07:00.624Z","etag":null,"topics":["nodejs","siphash","siphash-2-4","typescript","usex","uuid","uuidv4","uuidv47","uuidv7"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ali-master.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-18T17:02:55.000Z","updated_at":"2025-10-07T20:19:33.000Z","dependencies_parsed_at":"2025-09-18T20:23:36.421Z","dependency_job_id":null,"html_url":"https://github.com/ali-master/uuidv47","commit_stats":null,"previous_names":["ali-master/uuidv47"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/ali-master/uuidv47","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ali-master%2Fuuidv47","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ali-master%2Fuuidv47/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ali-master%2Fuuidv47/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ali-master%2Fuuidv47/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ali-master","download_url":"https://codeload.github.com/ali-master/uuidv47/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ali-master%2Fuuidv47/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29333140,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-11T12:42:24.625Z","status":"ssl_error","status_checked_at":"2026-02-11T12:41:23.344Z","response_time":97,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nodejs","siphash","siphash-2-4","typescript","usex","uuid","uuidv4","uuidv47","uuidv7"],"created_at":"2026-02-11T12:56:19.311Z","updated_at":"2026-02-11T12:56:20.006Z","avatar_url":"https://github.com/ali-master.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n    \u003cimg src=\"assets/logo.svg\" alt=\"UUIDv47 TypeScript Logo\" width=\"120\" height=\"120\" /\u003e\n    \u003ch1\u003eUUIDv47\u003c/h1\u003e\n    \u003cp\u003e\u003cstrong\u003eReversible UUID v4/v7 transformation using SipHash-2-4\u003c/strong\u003e\u003c/p\u003e\n    \n[![NPM Version](https://img.shields.io/npm/v/@usex/uuidv47?style=flat-square\u0026color=blue)](https://www.npmjs.com/package/@usex/uuidv47)\n[![License](https://img.shields.io/badge/license-MIT-green?style=flat-square)](LICENSE)\n[![TypeScript](https://img.shields.io/badge/TypeScript-5.9+-blue?style=flat-square\u0026logo=typescript)](https://www.typescriptlang.org/)\n[![Test Coverage](https://img.shields.io/badge/coverage-100-brightgreen?style=flat-square)](https://github.com/ali-master/uuidv47)\n[![Bundle Size](https://img.shields.io/badge/bundle-5.71KB-brightgreen?style=flat-square)](https://bundlephobia.com/package/@usex/uuidv47)\n[![Minified + Gzipped](https://img.shields.io/badge/gzipped-2.25KB-success?style=flat-square)](https://bundlephobia.com/package/@usex/uuidv47)\n\n\u003cp\u003e\u003cem\u003e⚡ Ultra-lightweight • 🚀 Zero dependencies • 📦 Just 2.25KB gzipped\u003c/em\u003e\u003c/p\u003e\n\u003c/div\u003e\n\n## 🚀 What is UUIDv47?\n\n**UUIDv47** is a revolutionary approach to UUID management that allows you to **reversibly transform** UUIDs between v7 (time-ordered) and v4 (random-appearing) formats. This enables you to:\n\n- 🔒 **Hide time-ordering** from external APIs while maintaining internal chronological benefits\n- 🎭 **Present v4 facades** to clients while storing efficient v7 UUIDs internally  \n- 🔐 **Cryptographically secure** transformations using SipHash-2-4 algorithm\n- ⚡ **High performance** with \u003e10,000 operations per second\n- 🔄 **Perfect reversibility** - no data loss in transformations\n- 📦 **Tiny footprint** - only 2.25KB gzipped with zero dependencies\n\n## 🎯 Why Choose UUIDv47?\n\nUUIDv47 is a lightweight library at just 5.71KB (2.25KB gzipped) that provides enterprise-grade UUID transformation capabilities with zero dependencies.\n\n## 📋 Table of Contents\n\n- [Installation](#-installation)\n- [Quick Start](#-quick-start)\n- [Core Concepts](#-core-concepts)\n- [Usage Examples](#-usage-examples)\n- [API Reference](#-api-reference)\n- [Performance](#-performance)\n- [Security](#-se)\n- [Contributing](#-contributing)\n\n## 📦 Installation\n\n```bash\n# Using Bun (recommended)\nbun add @usex/uuidv47\n\n# Using npm\nnpm install @usex/uuidv47\n\n# Using yarn\nyarn add @usex/uuidv47\n\n# Using pnpm\npnpm add @usex/uuidv47\n```\n\n### Requirements\n\n- **Node.js**: 16.0.0+\n- **TypeScript**: 5.0+ (for TypeScript projects)\n- **Runtime**: Works with Node.js, Bun, Deno, and modern browsers\n\n## ⚡ Quick Start\n\n```typescript\nimport { generateRandomKey, parseUUID, formatUUID, encodeV4Facade, decodeV4Facade } from '@usex/uuidv47';\n\n// 1. Generate a secure transformation key\nconst key = generateRandomKey();\n\n// 2. Parse your UUIDv7 (from your UUID generator)\nconst originalV7 = parseUUID('018f4e7c-3c4a-7000-8000-123456789abc');\n\n// 3. Transform to v4 facade (for external APIs)\nconst v4Facade = encodeV4Facade(originalV7, key);\nconsole.log(formatUUID(v4Facade));\n// Output: \"a1b2c3d4-e5f6-4789-9abc-def012345678\" (appears random)\n\n// 4. Transform back to original v7 (for internal use)\nconst decodedV7 = decodeV4Facade(v4Facade, key);\nconsole.log(formatUUID(decodedV7));\n// Output: \"018f4e7c-3c4a-7000-8000-123456789abc\" (original restored)\n```\n\n## 🧠 Core Concepts\n\n### The Problem UUIDv47 Solves\n\n**UUIDv7** provides excellent time-ordering properties but reveals creation timestamps to anyone who can parse them. **UUIDv4** appears random but lacks useful ordering. **UUIDv47** gives you both:\n\n```typescript\n// Internal storage: UUIDv7 (time-ordered, efficient)\nconst internalId = \"018f4e7c-3c4a-7000-8000-123456789abc\";  // Created at specific timestamp\n\n// External API: UUIDv4 facade (random-appearing, private)\nconst publicId = \"a1b2c3d4-e5f6-4789-9abc-def012345678\";   // Hides creation time\n\n// They're the SAME identifier, just different representations!\n```\n\n### How It Works\n\n1. **Timestamp Encryption**: The 48-bit timestamp in UUIDv7 is XORed with a SipHash-2-4 derived mask\n2. **Random Bits Preserved**: The random portion remains unchanged, maintaining uniqueness\n3. **Version Swap**: Version bits are changed between 4 and 7 during transformation\n4. **Perfect Reversibility**: Using the same key, transformations are completely reversible\n\n### Key Components\n\n- **SipHash-2-4**: Cryptographically secure hash function for generating encryption masks\n- **48-bit Timestamp**: The time component that gets encrypted/decrypted\n- **Transformation Key**: 128-bit key (two 64-bit values) for secure transformations\n- **UUID128**: Buffer representation of 16-byte UUIDs for efficient processing\n\n## 💡 Usage Examples\n\n### 1. Basic Encode/Decode Operations\n\n```typescript\nimport { generateRandomKey, parseUUID, formatUUID, getUUIDVersion, encodeV4Facade, decodeV4Facade } from '@usex/uuidv47';\n\nconst key = generateRandomKey();\nconst v7UUID = parseUUID(\"018f4e7c-3c4a-7000-8000-123456789abc\");\n\nconsole.log(`Original UUIDv7: ${formatUUID(v7UUID)}`);\nconsole.log(`Version: ${getUUIDVersion(v7UUID)}`); // 7\n\nconst v4Facade = encodeV4Facade(v7UUID, key);\nconsole.log(`UUIDv4 Facade: ${formatUUID(v4Facade)}`);\nconsole.log(`Version: ${getUUIDVersion(v4Facade)}`); // 4\n\nconst decodedV7 = decodeV4Facade(v4Facade, key);\nconsole.log(`Decoded UUIDv7: ${formatUUID(decodedV7)}`);\nconsole.log(`Matches original: ${decodedV7.equals(v7UUID)}`); // true\n```\n\n### 2. Service Integration Pattern\n\n```typescript\nclass UUIDTransformationService {\n  private readonly key: UUIDv47Key;\n\n  constructor(keyMaterial?: Buffer) {\n    this.key = keyMaterial \n      ? createKeyFromBuffer(keyMaterial)\n      : generateRandomKey();\n  }\n\n  // For external APIs - hide time ordering\n  toPublicId(internalV7: string): string {\n    const uuid = parseUUID(internalV7);\n    const facade = encodeV4Facade(uuid, this.key);\n    return formatUUID(facade);\n  }\n\n  // For internal processing - restore time ordering\n  toInternalId(publicV4: string): string {\n    const uuid = parseUUID(publicV4);\n    const original = decodeV4Facade(uuid, this.key);\n    return formatUUID(original);\n  }\n}\n\n// Usage\nconst service = new UUIDTransformationService();\nconst internalId = \"018f4e7c-3c4a-7000-8000-123456789abc\";\nconst publicId = service.toPublicId(internalId);\nconst recoveredId = service.toInternalId(publicId);\n\nconsole.log({ internalId, publicId, recoveredId });\n// { \n//   internalId: \"018f4e7c-3c4a-7000-8000-123456789abc\",\n//   publicId: \"a1b2c3d4-e5f6-4789-9abc-def012345678\", \n//   recoveredId: \"018f4e7c-3c4a-7000-8000-123456789abc\"\n// }\n```\n\n### 3. Multi-Tenant Key Management\n\n```typescript\nclass MultiTenantUUIDService {\n  private readonly tenantKeys = new Map\u003cstring, UUIDv47Key\u003e();\n\n  setTenantKey(tenantId: string, keyMaterial: Buffer): void {\n    this.tenantKeys.set(tenantId, createKeyFromBuffer(keyMaterial));\n  }\n\n  encodeForTenant(tenantId: string, v7UUID: string): string {\n    const key = this.tenantKeys.get(tenantId);\n    if (!key) throw new Error(`No key found for tenant: ${tenantId}`);\n    \n    const uuid = parseUUID(v7UUID);\n    const facade = encodeV4Facade(uuid, key);\n    return formatUUID(facade);\n  }\n\n  decodeForTenant(tenantId: string, v4Facade: string): string {\n    const key = this.tenantKeys.get(tenantId);\n    if (!key) throw new Error(`No key found for tenant: ${tenantId}`);\n    \n    const uuid = parseUUID(v4Facade);\n    const original = decodeV4Facade(uuid, key);\n    return formatUUID(original);\n  }\n}\n```\n\n### 4. Batch Processing\n\n```typescript\n// Process 1000 UUIDs efficiently\nconst key = generateRandomKey();\nconst v7UUIDs = generateV7UUIDs(1000); // Your UUID generation\n\nconsole.time('Batch Encode');\nconst facades = v7UUIDs.map(uuid =\u003e encodeV4Facade(uuid, key));\nconsole.timeEnd('Batch Encode'); // ~10ms for 1000 UUIDs\n\nconsole.time('Batch Decode');\nconst decoded = facades.map(facade =\u003e decodeV4Facade(facade, key));\nconsole.timeEnd('Batch Decode'); // ~10ms for 1000 UUIDs\n\n// Verify all transformations are perfect\nconst allMatch = decoded.every((uuid, i) =\u003e uuid.equals(v7UUIDs[i]));\nconsole.log(`All roundtrips successful: ${allMatch}`); // true\n```\n\n### 5. Error Handling\n\n```typescript\nconst key = generateRandomKey();\n\ntry {\n  // This will throw - can only encode v7 UUIDs\n  const v4UUID = parseUUID(\"a1b2c3d4-e5f6-4000-8000-123456789abc\");\n  encodeV4Facade(v4UUID, key);\n} catch (error) {\n  console.log(error.message); // \"Input UUID must be version 7\"\n}\n\ntry {\n  // This will throw - can only decode v4 UUIDs\n  const v7UUID = parseUUID(\"018f4e7c-3c4a-7000-8000-123456789abc\");\n  decodeV4Facade(v7UUID, key);\n} catch (error) {\n  console.log(error.message); // \"Input UUID must be version 4\"\n}\n\ntry {\n  // This will throw - invalid UUID format\n  parseUUID(\"invalid-uuid-string\");\n} catch (error) {\n  console.log(error.message); // \"Invalid UUID string length: expected 36, got 19\"\n}\n```\n\n### 6. UUID v7 Timestamp Extraction\n\n```typescript\nimport { parseUUID, extractTimestampFromV7, formatUUID } from '@usex/uuidv47';\n\n// Extract timestamp from a UUID v7\nconst v7UUID = parseUUID(\"018f4e7c-3c4a-7000-8000-123456789abc\");\nconst timestamp = extractTimestampFromV7(v7UUID);\n\nconsole.log(`UUID v7: ${formatUUID(v7UUID)}`);\nconsole.log(`Timestamp: ${timestamp.getTime()} ms`);\nconsole.log(`Date: ${timestamp.toISOString()}`); // \"2024-10-07T23:15:45.610Z\"\nconsole.log(`Local: ${timestamp.toLocaleString()}`);\n\n// Compare creation times of multiple UUIDs\nconst uuid1 = parseUUID(\"018f4e7c-3c4a-7000-8000-111111111111\");\nconst uuid2 = parseUUID(\"018f4e7c-4000-7000-8000-222222222222\");\nconst uuid3 = parseUUID(\"018f4e7c-5000-7000-8000-333333333333\");\n\nconst date1 = extractTimestampFromV7(uuid1);\nconst date2 = extractTimestampFromV7(uuid2);\nconst date3 = extractTimestampFromV7(uuid3);\n\nconsole.log(\"UUIDs in chronological order:\");\nconsole.log(`  ${formatUUID(uuid1)}: ${date1.toISOString()}`);\nconsole.log(`  ${formatUUID(uuid2)}: ${date2.toISOString()}`);\nconsole.log(`  ${formatUUID(uuid3)}: ${date3.toISOString()}`);\n\n// Use for sorting, filtering by date, etc.\nconst uuids = [uuid3, uuid1, uuid2];\nconst sortedByTime = uuids.sort((a, b) =\u003e {\n  const timeA = extractTimestampFromV7(a).getTime();\n  const timeB = extractTimestampFromV7(b).getTime();\n  return timeA - timeB;\n});\n\n// Error handling - only works with v7 UUIDs\ntry {\n  const v4UUID = parseUUID(\"a1b2c3d4-e5f6-4000-8000-123456789abc\");\n  extractTimestampFromV7(v4UUID);\n} catch (error) {\n  console.log(error.message); // \"Cannot extract timestamp: UUID is version 4, expected version 7\"\n}\n```\n\n## 📚 API Reference\n\n### Core Transformation Functions\n\n#### `encodeV4Facade(uuidV7: UUID128, key: UUIDv47Key): UUID128`\nTransform a UUIDv7 into a UUIDv4 facade that appears random but can be reversed.\n\n```typescript\nimport { encodeV4Facade, parseUUID, generateRandomKey } from '@usex/uuidv47';\n\nconst key = generateRandomKey();\nconst v7 = parseUUID(\"018f4e7c-3c4a-7000-8000-123456789abc\");\nconst v4Facade = encodeV4Facade(v7, key);\n```\n\n#### `decodeV4Facade(uuidV4Facade: UUID128, key: UUIDv47Key): UUID128`\nTransform a UUIDv4 facade back to its original UUIDv7 format.\n\n```typescript\nimport { decodeV4Facade } from '@usex/uuidv47';\n\nconst originalV7 = decodeV4Facade(v4Facade, key);\n```\n\n#### Enhanced Core Functions with Options\n\n#### `encodeV4FacadeWithOptions(uuidV7: UUID128, key: UUIDv47Key, options?: UUIDOperationOptions): UUID128`\nEncode with performance optimization options.\n\n```typescript\nimport { encodeV4FacadeWithOptions } from '@usex/uuidv47';\n\n// Skip validation for trusted input (faster)\nconst encoded = encodeV4FacadeWithOptions(v7, key, { skipValidation: true });\n```\n\n#### `decodeV4FacadeWithOptions(uuidV4Facade: UUID128, key: UUIDv47Key, options?: UUIDOperationOptions): UUID128`\nDecode with performance optimization options.\n\n```typescript\nimport { decodeV4FacadeWithOptions } from '@usex/uuidv47';\n\n// Skip validation for maximum performance\nconst decoded = decodeV4FacadeWithOptions(v4Facade, key, { skipValidation: true });\n```\n\n### Batch Processing Functions\n\n#### `batchEncodeV4Facade(uuids: UUID128[], key: UUIDv47Key): UUID128[]`\nProcess multiple UUIDs efficiently in a single operation.\n\n```typescript\nimport { batchEncodeV4Facade } from '@usex/uuidv47';\n\nconst v7UUIDs = [uuid1, uuid2, uuid3]; // Array of v7 UUIDs\nconst v4Facades = batchEncodeV4Facade(v7UUIDs, key);\n```\n\n#### `batchDecodeV4Facade(uuids: UUID128[], key: UUIDv47Key): UUID128[]`\nDecode multiple UUIDs efficiently in a single operation.\n\n```typescript\nimport { batchDecodeV4Facade } from '@usex/uuidv47';\n\nconst originalUUIDs = batchDecodeV4Facade(v4Facades, key);\n```\n\n#### `batchEncodeV4FacadeWithOptions(uuids: UUID128[], key: UUIDv47Key, options?: UUIDOperationOptions): UUID128[]`\nBatch encoding with performance options.\n\n```typescript\nimport { batchEncodeV4FacadeWithOptions } from '@usex/uuidv47';\n\n// Use individual processing instead of batch optimization\nconst encoded = batchEncodeV4FacadeWithOptions(uuids, key, { \n  useBatchProcessing: false,\n  skipValidation: true \n});\n```\n\n#### `batchDecodeV4FacadeWithOptions(uuids: UUID128[], key: UUIDv47Key, options?: UUIDOperationOptions): UUID128[]`\nBatch decoding with performance options.\n\n```typescript\nimport { batchDecodeV4FacadeWithOptions } from '@usex/uuidv47';\n\nconst decoded = batchDecodeV4FacadeWithOptions(facades, key, {\n  useBatchProcessing: false,\n  skipValidation: true\n});\n```\n\n### UUID Parsing and Formatting Functions\n\n#### `parseUUID(uuidString: string): UUID128`\nConvert a UUID string to internal Buffer representation.\n\n```typescript\nimport { parseUUID } from '@usex/uuidv47';\n\nconst uuid = parseUUID(\"018f4e7c-3c4a-7000-8000-123456789abc\");\n```\n\n#### `formatUUID(uuid: UUID128): string`\nConvert a UUID Buffer to standard string format.\n\n```typescript\nimport { formatUUID } from '@usex/uuidv47';\n\nconst uuidString = formatUUID(uuid); // \"018f4e7c-3c4a-7000-8000-123456789abc\"\n```\n\n#### `parseUUIDWithOptions(uuidString: string, options?: UUIDOperationOptions): UUIDParseResult`\nParse UUID with enhanced result information and performance options.\n\n```typescript\nimport { parseUUIDWithOptions } from '@usex/uuidv47';\n\nconst result = parseUUIDWithOptions(\"018f4e7c-3c4a-7000-8000-123456789abc\");\nconsole.log(result);\n// {\n//   uuid: Buffer,\n//   version: 7,\n//   isValid: true\n// }\n\n// Skip validation for performance\nconst fastResult = parseUUIDWithOptions(uuidString, { skipValidation: true });\n```\n\n#### `isValidUUIDString(uuidString: string): boolean`\nFast validation of UUID string format without full parsing.\n\n```typescript\nimport { isValidUUIDString } from '@usex/uuidv47';\n\nconst isValid = isValidUUIDString(\"018f4e7c-3c4a-7000-8000-123456789abc\"); // true\nconst isInvalid = isValidUUIDString(\"invalid-uuid\"); // false\n```\n\n#### `extractTimestampFromV7(uuid: UUID128): Date`\nExtract the timestamp from a UUID v7 and convert it to a JavaScript Date object.\n\nUUID v7 stores a 48-bit Unix timestamp (milliseconds since epoch) in the first 6 bytes. This function extracts that timestamp and returns it as a Date object.\n\n```typescript\nimport { extractTimestampFromV7, parseUUID } from '@usex/uuidv47';\n\n// Parse a UUID v7\nconst uuid = parseUUID(\"018f4e7c-3c4a-7000-8000-123456789abc\");\n\n// Extract the timestamp\nconst date = extractTimestampFromV7(uuid);\nconsole.log(date.toISOString()); // \"2024-10-07T23:15:45.610Z\"\nconsole.log(date.getTime());     // 1728340545610\n\n// Compare timestamps from multiple UUIDs\nconst uuid1 = parseUUID(\"018f4e7c-3c4a-7000-8000-123456789abc\");\nconst uuid2 = parseUUID(\"018f4e7c-4000-7000-8000-123456789abc\");\nconst date1 = extractTimestampFromV7(uuid1);\nconst date2 = extractTimestampFromV7(uuid2);\nconsole.log(date1 \u003c date2); // true (uuid1 was created before uuid2)\n```\n\n**Note:** This function will throw an error if the UUID is not version 7.\n\n```typescript\n// This will throw an error\nconst v4UUID = parseUUID(\"01234567-89ab-4000-8000-123456789abc\");\nextractTimestampFromV7(v4UUID); // Error: Cannot extract timestamp: UUID is version 4, expected version 7\n```\n\n### UUID Version and Variant Functions\n\n#### `getUUIDVersion(uuid: UUID128): UUIDVersion`\nExtract the version number from a UUID.\n\n```typescript\nimport { getUUIDVersion } from '@usex/uuidv47';\n\nconst version = getUUIDVersion(uuid); // 7 for UUIDv7, 4 for UUIDv4\n```\n\n#### `setUUIDVersion(uuid: UUID128, version: UUIDVersion): void`\nSet the version bits in a UUID (modifies the UUID in place).\n\n```typescript\nimport { setUUIDVersion, UUIDVersion } from '@usex/uuidv47';\n\nsetUUIDVersion(uuid, UUIDVersion.V4); // Sets version to 4\n```\n\n#### `setVariantRFC4122(uuid: UUID128): void`\nSet the RFC4122 variant bits in a UUID (modifies the UUID in place).\n\n```typescript\nimport { setVariantRFC4122 } from '@usex/uuidv47';\n\nsetVariantRFC4122(uuid); // Sets proper variant bits\n```\n\n### Key Management Functions\n\n#### `generateRandomKey(): UUIDv47Key`\nGenerate a cryptographically secure random transformation key.\n\n```typescript\nimport { generateRandomKey } from '@usex/uuidv47';\n\nconst key = generateRandomKey();\n```\n\n#### `createKey(k0: bigint, k1: bigint): UUIDv47Key`\nCreate a transformation key from two 64-bit values.\n\n```typescript\nimport { createKey } from '@usex/uuidv47';\n\nconst key = createKey(0x0123456789abcdefn, 0xfedcba9876543210n);\n```\n\n#### `createKeyFromBuffer(keyBuffer: Buffer): UUIDv47Key`\nCreate a transformation key from a 16-byte buffer.\n\n```typescript\nimport { createKeyFromBuffer } from '@usex/uuidv47';\n\nconst keyBuffer = Buffer.from('0123456789abcdeffedcba9876543210', 'hex');\nconst key = createKeyFromBuffer(keyBuffer);\n```\n\n#### `keyToBuffer(key: UUIDv47Key): Buffer`\nConvert a transformation key to a 16-byte buffer for serialization.\n\n```typescript\nimport { keyToBuffer } from '@usex/uuidv47';\n\nconst buffer = keyToBuffer(key); // 16-byte Buffer\n```\n\n#### `isValidKey(key: any): key is UUIDv47Key`\nType guard to validate if an object is a valid UUIDv47Key.\n\n```typescript\nimport { isValidKey } from '@usex/uuidv47';\n\nif (isValidKey(someObject)) {\n  // TypeScript now knows someObject is UUIDv47Key\n  const encoded = encodeV4Facade(uuid, someObject);\n}\n```\n\n#### `generateRandomKeys(count: number): UUIDv47Key[]`\nGenerate multiple random keys efficiently in a single operation.\n\n```typescript\nimport { generateRandomKeys } from '@usex/uuidv47';\n\nconst keys = generateRandomKeys(10); // Array of 10 random keys\n```\n\n## 🙏 Acknowledgments\n- **SipHash Algorithm**: Jean-Philippe Aumasson and Daniel J. Bernstein\n- **UUID Standards**: RFC 4122 and RFC 9562\n\n## Star History\n\n\u003ca href=\"https://www.star-history.com/#ali-master/uuidv47\u0026Date\u0026LogScale\"\u003e\n \u003cpicture\u003e\n   \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"https://api.star-history.com/svg?repos=ali-master/uuidv47\u0026type=Date\u0026theme=dark\" /\u003e\n   \u003csource media=\"(prefers-color-scheme: light)\" srcset=\"https://api.star-history.com/svg?repos=ali-master/uuidv47\u0026type=Date\" /\u003e\n   \u003cimg alt=\"Star History Chart\" src=\"https://api.star-history.com/svg?repos=ali-master/uuidv47\u0026type=Date\" /\u003e\n \u003c/picture\u003e\n\u003c/a\u003e\n\n---\n\n\u003cdiv align=\"center\"\u003e\n  \u003cp\u003e\n    \u003csub\u003eBuilt with ❤️ by \u003ca href=\"https://github.com/ali-master\" target=\"_blank\"\u003eAli Torki\u003c/a\u003e and contributors\u003c/sub\u003e\n  \u003c/p\u003e\n  \u003cp\u003e\n    \u003ca href=\"https://github.com/ali-master/uuidv47\"\u003e⭐ Star us on GitHub\u003c/a\u003e •\n    \u003ca href=\"https://linkedin.com/in/alitorki\"\u003e🐦 Follow on LinkedIn\u003c/a\u003e •\n    \u003ca href=\"https://www.npmjs.com/package/@usex/uuidv47\"\u003e📦 View on NPM\u003c/a\u003e\n  \u003c/p\u003e\n\u003c/div\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fali-master%2Fuuidv47","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fali-master%2Fuuidv47","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fali-master%2Fuuidv47/lists"}