GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — phi.network/dist/verifierCanon.ts at main · Phinetwork/phi.network Expand file tree/ Copy pathverifierCanon.tsMore file actions 94 lines (82 loc) · 3.05 KB / Copy pathverifierCanon.tsFile metadata and controls94 lines (82 loc) · 3.05 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 // src/pages/SigilPage/verifierCanon.ts import { sha256 as nobleSha256 } from "@noble/hashes/sha256"; const B58_ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; export const bytesToHexCanon = (u8: Uint8Array) => Array.from(u8).map((b) => b.toString(16).padStart(2, "0")).join(""); // SHA-256 with secure-context fallback (works on file:// via @noble/hashes) export async function sha256HexCanon(msg: string | Uint8Array): Promise<string> { const data = typeof msg === "string" ? new TextEncoder().encode(msg) : msg; const subtle = globalThis.crypto?.subtle; if (subtle) { const buf = await subtle.digest("SHA-256", data); return bytesToHexCanon(new Uint8Array(buf)); } const hash = nobleSha256(data); return bytesToHexCanon(hash); } function base58EncodeCanon(bytes: Uint8Array): string { let n = 0n; for (const b of bytes) n = (n << 8n) + BigInt(b); let out = ""; while (n > 0n) { const mod = Number(n % 58n); out = B58_ALPHABET[mod] + out; n /= 58n; } for (let i = 0; i < bytes.length && bytes[i] === 0; i++) out = "1" + out; return out; } export async function base58CheckCanon(payload: Uint8Array, version = 0x00): Promise<string> { const v = new Uint8Array(1 + payload.length); v[0] = version; v.set(payload, 1); const subtle = globalThis.crypto?.subtle; let c2: Uint8Array; if (subtle) { const d1 = await subtle.digest("SHA-256", v); const d2 = await subtle.digest("SHA-256", d1); c2 = new Uint8Array(d2); } else { const h1 = nobleSha256(v); c2 = nobleSha256(h1); } const checksum = c2.slice(0, 4); const full = new Uint8Array(v.length + 4); full.set(v); full.set(checksum, v.length); return base58EncodeCanon(full); } export async function derivePhiKeyFromSigCanon(sigHex: string): Promise<string> { const s = await sha256HexCanon(sigHex + "φ"); const raw = new Uint8Array(20); for (let i = 0; i < 20; i++) raw[i] = parseInt(s.slice(i * 2, i * 2 + 2), 16); return base58CheckCanon(raw, 0x00); } /* Ensure canonical <metadata> first for Verifier */ export function ensureCanonicalMetadataFirst(svgEl: SVGSVGElement) { try { const metas = Array.from(svgEl.querySelectorAll("metadata")); if (!metas.length) return; const canon = metas.find((m) => m.getAttribute("data-noncanonical") !== "1") || metas[0]; if (canon && svgEl.firstChild !== canon) svgEl.insertBefore(canon, svgEl.firstChild); } catch { /* noop: non-fatal */ } } /* Σ builder — intention is explicitly string|null for API compatibility */ export function verifierSigmaString( pulse: number, beat: number, stepIndex: number, chakraDay: string, intention: string | null ): string { return `${pulse}|${beat}|${stepIndex}|${chakraDay}|${intention ?? ""}`; } /* Read optional intentionSigil as string|null (not undefined) */ export function readIntentionSigil(obj: unknown): string | null { if (typeof obj !== "object" || obj === null) return null; const rec = obj as Record<string, unknown>; const v = rec["intentionSigil"]; return typeof v === "string" ? v : null; } |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |