//#region ../../src/types/bsv-auth.ts
/**
* Canonicalize a signed prompt envelope for signature verification.
* Uses stable key ordering for deterministic hashing.
*/
function canonicalizeSignedPrompt(envelope) {
	return JSON.stringify(stableSort(envelope));
}
function stableSort(value) {
	if (Array.isArray(value)) return value.map((item) => stableSort(item));
	if (value && typeof value === "object") {
		const entries = Object.entries(value).filter(([, v]) => v !== void 0).toSorted(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([k, v]) => [k, stableSort(v)]);
		return Object.fromEntries(entries);
	}
	return value;
}
/**
* Canonicalize a signed request for signature verification
* Order: method + path + timestamp + nonce + body_hash
*/
function canonicalizeRequest(req) {
	const bodyHash = req.body ? typeof req.body === "string" ? req.body : JSON.stringify(req.body) : "";
	return `${req.method.toUpperCase()}\n${req.path}\n${req.timestamp}\n${req.nonce}\n${bodyHash}`;
}

//#endregion
export { canonicalizeSignedPrompt as n, canonicalizeRequest as t };