Implementation:0xranx OpenContext IOS UUID Generator
| Knowledge Sources | |
|---|---|
| Domains | UUID, iOS |
| Last Updated | 2026-10-24 00:00 GMT |
Overview
UUID v4 generator for the iOS app, using the Web Crypto API with a Math.random fallback to produce RFC 4122-compliant UUID strings.
Description
The uuid.js module in src-ios/utils/ implements a single generateStableId function that generates a UUID v4 string. It uses globalThis.crypto.getRandomValues when available (secure random), falling back to Math.random for older environments. The variant and version bits are set according to RFC 4122 (version 4, variant 10xx). The bytes are converted to hex and formatted as xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx.
Usage
Import this function wherever a unique stable identifier is needed — document creation, idea entry IDs, and database stable_id backfilling.
Code Reference
Source Location
- Repository: 0xranx_OpenContext
- File: src-ios/utils/uuid.js
- Lines: 1-37
Signature
function generateStableId() // → string (UUID v4)
function randomBytes(length) // → Uint8Array
function bytesToHex(bytes) // → string
Import
const { generateStableId } = require('./utils/uuid');
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| (none) | — | — | No parameters |
Outputs
| Name | Type | Description |
|---|---|---|
| generateStableId | string | RFC 4122 UUID v4 string |
Usage Examples
Generating Stable IDs
const { generateStableId } = require('./utils/uuid');
// Generate a new stable_id for a document
const stableId = generateStableId();
console.log(stableId); // "a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d"
// Used in createDoc
const doc = await createDoc({
title: 'My Note',
content: '# Content',
stable_id: generateStableId()
});