"use strict";
/**
 * Deterministic canonical JSON serializer for Ed25519 signing/verification.
 *
 * Why purpose-built and not RFC 8785 (JCS) or a vendored canonicalize lib:
 * the entitlement payload schema is tightly controlled — flat object, primitives
 * plus one string array (purchasedPlugins). A 30-line implementation covers it
 * exactly and stays zero-dep, which matters because the create-maxy bundle
 * has a hardcoded externalDeps surface that any new runtime dep must thread.
 *
 * Rules:
 *   - object keys sorted lexicographically (Array.prototype.sort default)
 *   - no whitespace
 *   - strings JSON.stringify-escaped (handles unicode, quotes, backslashes)
 *   - numbers in finite IEEE 754; reject NaN / Infinity / -0
 *   - booleans + null verbatim
 *   - arrays preserve element order (signing party owns array semantics)
 *   - throws on unsupported value types (functions, undefined, symbols, bigint)
 *
 * Both sides (Rubytech signer + customer verifier) call canonicalize() before
 * signing/verifying. Canonical bytes are UTF-8 of the returned string.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.canonicalize = canonicalize;
function canonicalize(value) {
    if (value === null)
        return "null";
    if (typeof value === "boolean")
        return value ? "true" : "false";
    if (typeof value === "string")
        return JSON.stringify(value);
    if (typeof value === "number") {
        if (!Number.isFinite(value)) {
            throw new Error(`canonicalize: non-finite number rejected (${value})`);
        }
        if (Object.is(value, -0)) {
            throw new Error("canonicalize: negative zero rejected");
        }
        return JSON.stringify(value);
    }
    if (Array.isArray(value)) {
        return "[" + value.map(canonicalize).join(",") + "]";
    }
    if (typeof value === "object") {
        const keys = Object.keys(value).sort();
        const parts = [];
        for (const k of keys) {
            parts.push(JSON.stringify(k) + ":" + canonicalize(value[k]));
        }
        return "{" + parts.join(",") + "}";
    }
    throw new Error(`canonicalize: unsupported value type ${typeof value}`);
}
//# sourceMappingURL=canonicalize.js.map