starknet 11.8.0 → 11.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/falcon/index.d.ts +194 -2
- package/dist/falcon/index.js +833 -154
- package/dist/falcon/index.js.map +1 -1
- package/dist/falcon/index.mjs +828 -150
- package/dist/falcon/index.mjs.map +1 -1
- package/dist/index.d.ts +102 -47
- package/dist/index.global.js +130 -67
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +130 -67
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +130 -67
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/falcon/Falcon512Signer.ts","../../src/falcon/accountType.ts","../../src/falcon/oz/ownership.ts","../../src/falcon/s2morrow/constants.ts","../../src/falcon/s2morrow/felt.ts","../../src/falcon/oz/signature.ts","../../src/falcon/engine/noble/falcon.ts","../../src/falcon/engine/noble/_crystals.ts","../../src/falcon/engine/noble/utils.ts","../../src/falcon/engine/engine.ts","../../src/falcon/s2morrow/nttRoots.ts","../../src/falcon/s2morrow/ntt.ts","../../src/falcon/s2morrow/packing.ts","../../src/falcon/s2morrow/signature.ts","../../src/falcon/s2morrow/hashToPoint.ts","../../src/falcon/oz/hashToPoint.ts","../../src/falcon/s2morrow/keys.ts","../../src/falcon/falcon512.ts","../../src/falcon/verify.ts"],"sourcesContent":["import * as starknet from 'starknet';\nimport {\n parseFalconOptions,\n type Falcon512AccountType,\n type Falcon512Options,\n} from './accountType';\nimport { ownershipAcceptanceHash } from './oz/ownership';\nimport { signHashOz } from './oz/signature';\nimport {\n getPublicKey,\n getPackedPublicKey,\n importFalconRsSecretKey,\n publicKeyToNtt,\n SECRET_KEY_LENGTH,\n toBytes,\n} from './s2morrow/keys';\nimport { signHash } from './s2morrow/signature';\n\n/**\n * Throws a clear error unless the transaction is V3: the hash functions of starknet.js compute V3\n * hashes only.\n * @param {InvocationsDetailsWithNonce} details the details of the transaction\n * @throws {Error} when the version is not V3\n * @example\n * ```typescript\n * assertV3({ nonce: 1, version: '0x3' });\n * // passes\n * assertV3({ nonce: 1, version: '0x1' });\n * // throws Error(\"Falcon512: only V3 transactions are supported\")\n * ```\n */\nfunction assertV3(details: starknet.InvocationsDetailsWithNonce): void {\n if (!starknet.isV3Tx(details)) throw new Error('Falcon512: only V3 transactions are supported');\n}\n\n/**\n * Signer for the Falcon-512 accounts (post-quantum signature), in pure TypeScript.\n *\n * Falcon-512 is a signature scheme built on lattices, designed to resist attacks by quantum\n * computers. Three account contracts verify it on-chain, each with its own signature layout: the\n * `accountType` option of the constructor selects it (see `Falcon512AccountType`).\n * - `'s2morrow'` (default): the S2morrow account (https://github.com/feltroidprime/s2morrow), which\n * hashes the transaction with Poseidon. A signature is 61 felts.\n * - `'oz-hint'` and `'oz-direct'`: the two Falcon-512 accounts of OpenZeppelin Contracts for Cairo\n * (pre-release v4.1.0-rc.0), which hash it with SHAKE-256. A signature is 60 felts with the hint\n * s1·h, which makes the on-chain check cheaper, or 31 felts without it.\n *\n * Fees: the on-chain verification costs much more L2 gas than an ECDSA one. By default, the fee\n * estimates of `Account` skip the validation of the signature (`skipValidate: true`), so they leave\n * out this cost: pass `{ skipValidate: false }` to `execute`, `deployAccount` and `declare`.\n *\n * Status:\n * - This is Falcon as submitted to Round 3 of the NIST post-quantum standardization, not FN-DSA\n * (FIPS 206). FN-DSA is not final yet, and will most likely be incompatible with it.\n * - The Falcon code is a patched copy of `@noble/post-quantum` 0.7.1, kept until noble publishes\n * the API this signer needs. noble has no independent audit: its author audited version 0.6.1\n * (April 2026).\n * - Signing is not constant-time: do not sign where an attacker can measure its timing closely.\n * - Only V3 transactions are supported.\n */\nexport class Falcon512Signer implements starknet.SignerInterface {\n readonly #secretKey: Uint8Array;\n\n readonly #publicKey: Uint8Array;\n\n readonly #pkNtt: Uint16Array;\n\n readonly #packedPublicKey: string[];\n\n readonly #accountType: Falcon512AccountType;\n\n /**\n * Builds a signer from a NIST Falcon-512 secret key. The key is fully checked, then copied: the\n * signer keeps its own copy, in a private field.\n * @param {Uint8Array | string} secretKey NIST Falcon-512 secret key (1281 bytes), Uint8Array or\n * hex string. Prefer a Uint8Array: a string cannot be wiped from memory.\n * @param {Falcon512Options} [options] `accountType`: the type of the account that checks the\n * signatures, `'s2morrow'` (default), `'oz-hint'` or `'oz-direct'`\n * @throws {Error} when the secret key or an option is invalid\n * @example\n * ```typescript\n * const { secretKey } = falcon512.generateKeyPair();\n * const mySigner = new Falcon512Signer(secretKey); // for an S2morrow account\n * const myOzSigner = new Falcon512Signer(secretKey, { accountType: 'oz-hint' });\n * new Falcon512Signer(new Uint8Array(1281));\n * // throws Error(\"Falcon512: invalid secret key header\")\n * ```\n */\n constructor(secretKey: Uint8Array | string, options?: Falcon512Options) {\n const accountType = parseFalconOptions(options); // read before the key is copied\n const bytes = toBytes(secretKey, SECRET_KEY_LENGTH, 'secret key');\n let publicKey: Uint8Array;\n try {\n publicKey = getPublicKey(bytes); // fully validates the key\n } catch (error) {\n bytes.fill(0); // the copy of an invalid key is not kept\n throw error;\n }\n this.#accountType = accountType;\n this.#publicKey = publicKey;\n this.#secretKey = bytes;\n this.#pkNtt = publicKeyToNtt(this.#publicKey);\n this.#packedPublicKey = getPackedPublicKey(this.#publicKey);\n }\n\n /**\n * Builds a signer from a falcon-rs secret key (3584 bytes), converted to the NIST format.\n *\n * Warning: falcon-rs derives the seed of its sampler from the public salt of each signature, so\n * the signatures it produced may leak information about the secret key. Use this for continuity\n * only; for real funds, generate a new key with `falcon512.generateKeyPair`. The S2morrow account\n * cannot change its key: a new key means a new account. An OpenZeppelin account can change its\n * key (see `signOwnershipAcceptance`).\n * @param {Uint8Array | string} secretKey the falcon-rs secret key (3584 bytes), or its hex string\n * @param {Falcon512Options} [options] `accountType`, as for the constructor\n * @returns {Falcon512Signer} a signer that holds the same key, in the NIST format\n * @throws {Error} when the falcon-rs secret key or an option is invalid\n * @example\n * ```typescript\n * const mySigner = Falcon512Signer.fromFalconRs(falconRsSecretKey); // 3584 bytes, from falcon-rs\n * const result = mySigner.getPackedPublicKey();\n * // result = ['0xb2cf4f8b3c6f60cc662f438970ad34017e260c52d7911297a42811ce3cea2b', …] (29 felts)\n * ```\n */\n static fromFalconRs(secretKey: Uint8Array | string, options?: Falcon512Options): Falcon512Signer {\n const nist = importFalconRsSecretKey(secretKey);\n try {\n return new Falcon512Signer(nist, options);\n } finally {\n nist.fill(0);\n }\n }\n\n /**\n * NIST Falcon-512 public key (897 bytes), as a hex string.\n * @returns {Promise<string>} the public key: 0x, then 1794 hex digits\n * @example\n * ```typescript\n * const { secretKey } = falcon512.generateKeyPair();\n * const mySigner = new Falcon512Signer(secretKey);\n * const result = await mySigner.getPubKey();\n * // result = '0x09…' (1796 characters; 09 is the header of the format)\n * ```\n */\n public async getPubKey(): Promise<string> {\n return starknet.encode.addHexPrefix(starknet.encode.buf2hex(this.#publicKey));\n }\n\n /**\n * The 29 felts of the public key, in the form the accounts store it: the constructor argument\n * `pk_packed` of S2morrow, or the `public_key` array of an OpenZeppelin account (whose\n * constructor calldata is `29`, then these 29 felts). The same for the three account types.\n * @returns {string[]} the 29 felts, as hex strings (a new array at each call)\n * @example\n * ```typescript\n * const { secretKey } = falcon512.generateKeyPair();\n * const mySigner = new Falcon512Signer(secretKey);\n * const result = mySigner.getPackedPublicKey();\n * // result = ['0x…', …] (29 felts)\n * ```\n */\n public getPackedPublicKey(): string[] {\n return [...this.#packedPublicKey];\n }\n\n /**\n * Signs a SNIP-12 message (TypedData) for off-chain use.\n * @param {TypedData} typedData the message to sign\n * @param {string} accountAddress address of the account that signs the message\n * @returns {Promise<Signature>} the signature, as hex strings: 61 felts (S2morrow), 60\n * (OpenZeppelin, hint) or 31 (OpenZeppelin, direct)\n * @example\n * ```typescript\n * const result = await mySigner.signMessage(myTypedData, accountAddress);\n * // result = ['0x…', …] (S2morrow: 61 felts, random salt); result[29] = '0x2' (salt length)\n * ```\n */\n public async signMessage(\n typedData: starknet.TypedData,\n accountAddress: string\n ): Promise<starknet.Signature> {\n return this.signRaw(starknet.typedData.getMessageHash(typedData, accountAddress));\n }\n\n /**\n * Signs an INVOKE transaction (V3 only).\n * @param {Call[]} transactions the calls of the transaction\n * @param {InvocationsSignerDetails} details the details needed to hash the transaction\n * @returns {Promise<Signature>} the signature, as hex strings: 61, 60 or 31 felts, according to\n * the account type\n * @throws {Error} when the transaction is not V3\n * @example\n * ```typescript\n * const calls: Call[] = [\n * {\n * contractAddress: '0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d',\n * entrypoint: 'transfer',\n * calldata: ['0x123', '1000', '0'],\n * },\n * ];\n * const details: InvocationsSignerDetails = {\n * walletAddress: accountAddress,\n * chainId: constants.StarknetChainId.SN_SEPOLIA,\n * cairoVersion: '1',\n * version: '0x3',\n * nonce: 1,\n * resourceBounds: {\n * l1_gas: { max_amount: 0n, max_price_per_unit: 50000000000000n },\n * l2_gas: { max_amount: 40000000n, max_price_per_unit: 20000000000n },\n * l1_data_gas: { max_amount: 1000n, max_price_per_unit: 100000n },\n * },\n * tip: 0,\n * paymasterData: [],\n * accountDeploymentData: [],\n * nonceDataAvailabilityMode: RPC.EDataAvailabilityMode.L1,\n * feeDataAvailabilityMode: RPC.EDataAvailabilityMode.L1,\n * };\n * const result = await mySigner.signTransaction(calls, details);\n * // result = ['0x…', …] (S2morrow: 61 felts)\n * ```\n */\n public async signTransaction(\n transactions: starknet.Call[],\n details: starknet.InvocationsSignerDetails\n ): Promise<starknet.Signature> {\n assertV3(details);\n const compiledCalldata = starknet.transaction.getExecuteCalldata(\n transactions,\n details.cairoVersion\n );\n const msgHash = starknet.hash.calculateInvokeTransactionHash({\n ...details,\n senderAddress: details.walletAddress,\n compiledCalldata,\n version: details.version,\n nonceDataAvailabilityMode: starknet.stark.intDAM(details.nonceDataAvailabilityMode),\n feeDataAvailabilityMode: starknet.stark.intDAM(details.feeDataAvailabilityMode),\n });\n return this.signRaw(msgHash);\n }\n\n /**\n * Signs the DEPLOY_ACCOUNT transaction of a Falcon-512 account (V3 only).\n * @param {DeployAccountSignerDetails} details the details needed to hash the transaction\n * @returns {Promise<Signature>} the signature, as hex strings: 61, 60 or 31 felts, according to\n * the account type\n * @throws {Error} when the transaction is not V3\n * @example\n * ```typescript\n * const packedPublicKey = mySigner.getPackedPublicKey();\n * const classHash = '0x37c7626b50ba517835c9556b53bce57cb6633704bb702f8c2f13a44cf151d5';\n * const salt = packedPublicKey[0];\n * const details: DeployAccountSignerDetails = {\n * classHash,\n * constructorCalldata: packedPublicKey,\n * addressSalt: salt,\n * contractAddress: hash.calculateContractAddressFromHash(salt, classHash, packedPublicKey, 0),\n * chainId: constants.StarknetChainId.SN_SEPOLIA,\n * version: '0x3',\n * nonce: 0,\n * resourceBounds: {\n * l1_gas: { max_amount: 0n, max_price_per_unit: 50000000000000n },\n * l2_gas: { max_amount: 60000000n, max_price_per_unit: 20000000000n },\n * l1_data_gas: { max_amount: 1000n, max_price_per_unit: 100000n },\n * },\n * tip: 0,\n * paymasterData: [],\n * accountDeploymentData: [],\n * nonceDataAvailabilityMode: RPC.EDataAvailabilityMode.L1,\n * feeDataAvailabilityMode: RPC.EDataAvailabilityMode.L1,\n * };\n * const result = await mySigner.signDeployAccountTransaction(details);\n * // result = ['0x…', …] (S2morrow: 61 felts)\n * ```\n */\n public async signDeployAccountTransaction(\n details: starknet.DeployAccountSignerDetails\n ): Promise<starknet.Signature> {\n assertV3(details);\n const compiledConstructorCalldata = starknet.CallData.compile(details.constructorCalldata);\n const msgHash = starknet.hash.calculateDeployAccountTransactionHash({\n ...details,\n salt: details.addressSalt,\n compiledConstructorCalldata,\n version: details.version,\n nonceDataAvailabilityMode: starknet.stark.intDAM(details.nonceDataAvailabilityMode),\n feeDataAvailabilityMode: starknet.stark.intDAM(details.feeDataAvailabilityMode),\n });\n return this.signRaw(msgHash);\n }\n\n /**\n * Signs a DECLARE transaction (V3 only).\n * @param {DeclareSignerDetails} details the details needed to hash the transaction\n * @returns {Promise<Signature>} the signature, as hex strings: 61, 60 or 31 felts, according to\n * the account type\n * @throws {Error} when the transaction is not V3\n * @example\n * ```typescript\n * const details: DeclareSignerDetails = {\n * senderAddress: accountAddress,\n * classHash: '0x37c7626b50ba517835c9556b53bce57cb6633704bb702f8c2f13a44cf151d5',\n * compiledClassHash: '0x1f2afb8ae690b84f4b7acfde52fbd2e5a1dc0c910ed898a778dc1ad3339e5c5',\n * chainId: constants.StarknetChainId.SN_SEPOLIA,\n * version: '0x3',\n * nonce: 2,\n * resourceBounds: {\n * l1_gas: { max_amount: 0n, max_price_per_unit: 50000000000000n },\n * l2_gas: { max_amount: 80000000n, max_price_per_unit: 20000000000n },\n * l1_data_gas: { max_amount: 1000n, max_price_per_unit: 100000n },\n * },\n * tip: 0,\n * paymasterData: [],\n * accountDeploymentData: [],\n * nonceDataAvailabilityMode: RPC.EDataAvailabilityMode.L1,\n * feeDataAvailabilityMode: RPC.EDataAvailabilityMode.L1,\n * };\n * const result = await mySigner.signDeclareTransaction(details);\n * // result = ['0x…', …] (S2morrow: 61 felts)\n * ```\n */\n public async signDeclareTransaction(\n details: starknet.DeclareSignerDetails\n ): Promise<starknet.Signature> {\n assertV3(details);\n const msgHash = starknet.hash.calculateDeclareTransactionHash({\n ...details,\n version: details.version,\n nonceDataAvailabilityMode: starknet.stark.intDAM(details.nonceDataAvailabilityMode),\n feeDataAvailabilityMode: starknet.stark.intDAM(details.feeDataAvailabilityMode),\n });\n return this.signRaw(msgHash);\n }\n\n /**\n * Signs the acceptance of a key change of an OpenZeppelin Falcon-512 account.\n *\n * The account changes its key when it calls its own `set_public_key(new_public_key, signature)`:\n * the current key signs that transaction, as any other, and the new key must sign an acceptance.\n * Call this method on the signer of the new key, with the key that the account holds now. The\n * signed hash is Poseidon('StarkNet Message', 'accept_ownership', account address,\n * Poseidon(current key)). It holds no chain id, nonce or expiry: an acceptance is not single-use,\n * and the current key must still sign each key change.\n * @param {BigNumberish} accountAddress the address of the account\n * @param {BigNumberish[]} currentPublicKey the 29 felts of the key that the account holds now\n * (`getPackedPublicKey()` of its current signer, or its `get_public_key`)\n * @returns {Promise<string[]>} the acceptance, as hex strings, in the layout of this signer: 60\n * felts (`'oz-hint'`) or 31 (`'oz-direct'`)\n * @throws {Error} for an S2morrow signer (that account cannot change its key), or when the\n * current key has neither 29 felts nor none, or a value is not a felt252. Also when a subclass\n * makes `signRaw` return something else than an array of felts\n * @example\n * ```typescript\n * const newSigner = new Falcon512Signer(newSecretKey, { accountType: 'oz-hint' });\n * const acceptance = await newSigner.signOwnershipAcceptance(\n * falconAccount.address,\n * currentSigner.getPackedPublicKey()\n * );\n * const { transaction_hash } = await falconAccount.execute(\n * {\n * contractAddress: falconAccount.address,\n * entrypoint: 'set_public_key',\n * calldata: CallData.compile({\n * new_public_key: newSigner.getPackedPublicKey(),\n * signature: acceptance,\n * }),\n * },\n * { skipValidate: false }\n * );\n * await myProvider.waitForTransaction(transaction_hash);\n * // From now on, the account checks the signatures of newSigner.\n * ```\n */\n public async signOwnershipAcceptance(\n accountAddress: starknet.BigNumberish,\n currentPublicKey: readonly starknet.BigNumberish[]\n ): Promise<string[]> {\n if (this.#accountType === 's2morrow') {\n throw new Error('Falcon512: an S2morrow account cannot change its key');\n }\n const signature = await this.signRaw(ownershipAcceptanceHash(accountAddress, currentPublicKey));\n if (!Array.isArray(signature)) {\n throw new Error('Falcon512: signRaw must return an array of felts');\n }\n return signature;\n }\n\n /**\n * Signs a hash: the last step of all the methods above, in the layout of the account type. It\n * stays protected, so that no public method signs an arbitrary hash. A subclass can override it,\n * as for every starknet.js signer.\n * @param {string} msgHash the hash to sign, a felt252\n * @returns {Promise<Signature>} the signature, as hex strings: 61, 60 or 31 felts, according to\n * the account type\n * @example\n * ```typescript\n * class LoggedFalconSigner extends Falcon512Signer {\n * protected async signRaw(msgHash: string): Promise<Signature> {\n * console.log('Falcon-512 signs', msgHash);\n * return super.signRaw(msgHash);\n * }\n * }\n * const result = await new LoggedFalconSigner(secretKey).signMessage(myTypedData, accountAddress);\n * // logs the hash of the message; result = ['0x…', …] (61 felts)\n * ```\n */\n protected async signRaw(msgHash: string): Promise<starknet.Signature> {\n const value = starknet.num.toBigInt(msgHash);\n switch (this.#accountType) {\n case 'oz-hint':\n return signHashOz(value, this.#secretKey, this.#pkNtt, 'hint');\n case 'oz-direct':\n return signHashOz(value, this.#secretKey, this.#pkNtt, 'direct');\n default: // 's2morrow'\n return signHash(value, this.#secretKey, this.#pkNtt);\n }\n }\n}\n","/**\n * The Falcon-512 accounts that `starknet/falcon` signs for. Each one has its own signature layout:\n * the signer must use the type of the account class, or the account rejects the signatures.\n *\n * - `'s2morrow'`: the S2morrow account (https://github.com/feltroidprime/s2morrow), class\n * `0x37c7626b50ba517835c9556b53bce57cb6633704bb702f8c2f13a44cf151d5`. Signatures of 61 felts,\n * hashed with Poseidon. The default.\n * - `'oz-hint'`: `Falcon512ShakeAccountUpgradeable` of OpenZeppelin Contracts for Cairo\n * (v4.1.0-rc.0), class `0x014660ce3739fbde6e33d994cebd6a9fb20e800516b2e1b6c253d4d09baa9ae0`\n * (compiled with Cairo 2.21.0). Signatures of 60 felts, with the product s1·h (the hint), which\n * makes the on-chain check cheaper.\n * - `'oz-direct'`: `Falcon512ShakeDirectAccountUpgradeable` of OpenZeppelin Contracts for Cairo\n * (v4.1.0-rc.0), class `0x016111958d61eedfa5a950b608997abb4981b548f1862d620cc9247461ddeeb1`\n * (compiled with Cairo 2.21.0). Signatures of 31 felts, without the hint.\n *\n * The two OpenZeppelin accounts store the same key and have the same ABI. A class upgrade from one\n * to the other keeps the address and the key, but changes the signature layout.\n */\nexport type Falcon512AccountType = 's2morrow' | 'oz-hint' | 'oz-direct';\n\n/** Options of `Falcon512Signer`, `falcon512.verify` and `falcon512.verifyMessage`. */\nexport type Falcon512Options = {\n /** The type of the account that checks the signatures. Default: `'s2morrow'`. */\n accountType?: Falcon512AccountType;\n};\n\nconst ACCOUNT_TYPES: readonly Falcon512AccountType[] = Object.freeze([\n 's2morrow',\n 'oz-hint',\n 'oz-direct',\n]);\n\n/**\n * Reads the options of `starknet/falcon` strictly: an unknown option or value is an error, never a\n * silent fallback to the default type.\n * @param {unknown} options the options given by the caller, or undefined\n * @returns {Falcon512AccountType} the account type; `'s2morrow'` when none is given\n * @throws {Error} when the options are not an object, have an unknown key, or an unknown\n * accountType\n * @example\n * ```typescript\n * const result = parseFalconOptions({ accountType: 'oz-hint' });\n * // result = 'oz-hint'\n * const result2 = parseFalconOptions(undefined);\n * // result2 = 's2morrow'\n * parseFalconOptions({ acountType: 'oz-hint' });\n * // throws Error('Falcon512: unknown option \"acountType\"')\n * ```\n */\nexport function parseFalconOptions(options: unknown): Falcon512AccountType {\n if (options === undefined) return 's2morrow';\n if (typeof options !== 'object' || options === null || Array.isArray(options)) {\n throw new Error('Falcon512: options must be an object');\n }\n Object.keys(options).forEach((key) => {\n if (key !== 'accountType') throw new Error(`Falcon512: unknown option \"${key}\"`);\n });\n const { accountType } = options as Falcon512Options;\n if (accountType === undefined) return 's2morrow';\n if (!ACCOUNT_TYPES.includes(accountType)) {\n throw new Error(\n `Falcon512: unknown accountType \"${String(accountType)}\" (expected 's2morrow', 'oz-hint' or 'oz-direct')`\n );\n }\n return accountType;\n}\n","// Key change of the OpenZeppelin Falcon-512 accounts (OpenZeppelin Contracts for Cairo\n// v4.1.0-rc.0, `set_public_key`): the hash that the new key signs to accept the account.\nimport * as starknet from 'starknet';\nimport { PACKED_SLOTS } from '../s2morrow/constants';\nimport { parseFelt } from '../s2morrow/felt';\n\n/**\n * Hash that the new key signs to accept a key change of an OpenZeppelin Falcon-512 account:\n * Poseidon('StarkNet Message', 'accept_ownership', account address, Poseidon(current key)).\n * It holds no chain id, nonce or expiry (as in OpenZeppelin): an acceptance is not single-use.\n * @param {BigNumberish} accountAddress the address of the account\n * @param {BigNumberish[]} currentPublicKey the 29 felts of the key that the account holds now, or\n * none\n * @returns {string} the hash to sign, as a hex string\n * @throws {Error} when the current key has neither 29 felts nor none, or a value is not a felt252\n * @example\n * ```typescript\n * const result = ownershipAcceptanceHash(CairoBytes31.fromText('FALCON_MIGRATION').toBigInt(), []);\n * // result = '0x4cd1d8e37687d438b941364f25ae8c1d3198903239a23dd49add4f3c250a61b'\n * // (the value of the OpenZeppelin reference data, migration_fixture.cairo)\n * ```\n */\nexport function ownershipAcceptanceHash(\n accountAddress: starknet.BigNumberish,\n currentPublicKey: readonly starknet.BigNumberish[]\n): string {\n if (\n !Array.isArray(currentPublicKey) ||\n (currentPublicKey.length !== PACKED_SLOTS && currentPublicKey.length !== 0)\n ) {\n throw new Error('Falcon512: current public key must have 29 felts, or none');\n }\n const address = parseFelt(accountAddress, 'account address');\n const key = currentPublicKey.map((x, i) => parseFelt(x, `current public key[${i}]`));\n const { computePoseidonHashOnElements } = starknet.hash;\n return computePoseidonHashOnElements([\n starknet.CairoBytes31.fromText('StarkNet Message').toBigInt(),\n starknet.CairoBytes31.fromText('accept_ownership').toBigInt(),\n address,\n computePoseidonHashOnElements(key),\n ]);\n}\n","// Falcon-512 / S2morrow constants shared by the pure-TypeScript implementation.\n\n/** Falcon modulus q. */\nexport const Q = 12289;\n/** q as a bigint. */\nexport const QB = 12289n;\n/** Degree of the polynomials (Falcon-512). */\nexport const N = 512;\n/** Squared-norm bound of a Falcon-512 signature; identical to SIG_BOUND_512 in falcon.cairo. */\nexport const SIG_BOUND_512 = 34034726;\n/** Number of felt252 of a packed 512-coefficient polynomial. */\nexport const PACKED_SLOTS = 29;\n/** Zq values packed in each u128 half of a felt252 (base-Q Horner encoding). */\nexport const VALUES_PER_HALF = 9;\n/** Number of salt felts produced by this signer. */\nexport const SALT_FELTS = 2;\n/** Signature length: s1 (29) + salt length (1) + salt (2) + mul_hint (29). */\nexport const SIGNATURE_FELTS = 61;\n","import * as starknet from 'starknet';\n\n/**\n * Throws if x is not a felt252: a bigint with 0 <= x < P. The range check is the one of\n * `CairoFelt252`.\n * @param {bigint} x the value to check\n * @param {string} label the name of the value, used in the error message\n * @throws {Error} when x is not a bigint, or is outside [0, P)\n * @example\n * ```typescript\n * assertFelt(5n, 'salt');\n * // passes\n * assertFelt(-1n, 'salt');\n * // throws Error(\"Value -1 is out of felt252 range [0, 3618502788666131213697322783095070105623107215331596699973092056135872020481)\")\n * ```\n */\nexport function assertFelt(x: bigint, label: string): void {\n if (typeof x !== 'bigint') throw new Error(`Falcon512: ${label} is not a felt252`);\n starknet.CairoFelt252.assertRange(x);\n}\n\n/**\n * Spellings accepted for a felt252: \"0x\" and 1 to 64 hex digits, or 1 to 76 decimal digits (P has\n * 76). The caps keep an untrusted signature cheap to reject: 61 huge strings would cost seconds.\n */\nconst FELT_STRING = /^(0[xX][0-9a-fA-F]{1,64}|[0-9]{1,76})$/;\n\n/**\n * Parses a felt252 given as a bigint, a safe integer, a hex string (\"0x…\") or a decimal string.\n * The check comes first and refuses what starknet.js would convert without a word (\"\", \" \",\n * \"0x\", a text, a boolean, an unsafe integer), and a negative number; `CairoFelt252` then converts\n * and checks the range.\n * @param {unknown} value the value to parse\n * @param {string} label the name of the value, used in the error message\n * @returns {bigint} the felt252\n * @throws {Error} when the value is not one of the accepted spellings, or is outside [0, P)\n * @example\n * ```typescript\n * const result = parseFelt('0x1F', 'x');\n * // result = 31n\n * const result2 = parseFelt('31', 'x');\n * // result2 = 31n\n * parseFelt('', 'x');\n * // throws Error(\"Falcon512: x is not a felt252\")\n * ```\n */\nexport function parseFelt(value: unknown, label: string): bigint {\n const accepted =\n (typeof value === 'bigint' && value >= 0n) ||\n (typeof value === 'number' && Number.isSafeInteger(value) && value >= 0) ||\n (typeof value === 'string' && FELT_STRING.test(value));\n if (!accepted) throw new Error(`Falcon512: ${label} is not a felt252`);\n return new starknet.CairoFelt252(value).toBigInt();\n}\n","// Signature layouts of the OpenZeppelin Falcon-512 accounts (OpenZeppelin Contracts for Cairo\n// v4.1.0-rc.0): direct = s1 (29 felts) ‖ salt_a ‖ salt_b; hint = direct ‖ s1·h (29 felts).\nimport { randomBytes as cryptoRandomBytes } from '@noble/hashes/utils.js';\nimport * as starknet from 'starknet';\nimport { nobleEngine } from '../engine/engine';\nimport { PACKED_SLOTS } from '../s2morrow/constants';\nimport { assertFelt, parseFelt } from '../s2morrow/felt';\nimport { modQ } from '../s2morrow/ntt';\nimport { packPoly, unpackPoly } from '../s2morrow/packing';\nimport { checkSignatureEquation, computeMulHint, type SignDeps } from '../s2morrow/signature';\nimport { hashToPointShake, SALT_BYTES, saltFeltsToBytes } from './hashToPoint';\n\n/** The two signature layouts of the OpenZeppelin Falcon-512 accounts. */\nexport type OzVariant = 'hint' | 'direct';\n\n/** Signature length: s1 (29) and the salt (2), plus the hint s1·h (29) in the hint layout. */\nexport const OZ_SIGNATURE_FELTS: Readonly<Record<OzVariant, number>> = Object.freeze({\n hint: 2 * PACKED_SLOTS + 2,\n direct: PACKED_SLOTS + 2,\n});\n\n/** Decoded OpenZeppelin signature. `mulHint` is present in the hint layout only. */\nexport type OzSignature = { s1: Uint16Array; saltA: bigint; saltB: bigint; mulHint?: Uint16Array };\n\nconst defaultDeps: SignDeps = { engine: nobleEngine, randomBytes: cryptoRandomBytes };\n\n/**\n * Reads bytes as a number, least significant byte first.\n * @param {Uint8Array} bytes the bytes to read\n * @returns {bigint} the number\n * @example\n * ```typescript\n * const result = readLittleEndian(Uint8Array.from([2, 1]));\n * // result = 258n (0x0102)\n * ```\n */\nconst readLittleEndian = (bytes: Uint8Array): bigint =>\n bytes.reduceRight((acc, byte) => acc * 256n + BigInt(byte), 0n);\n\n/**\n * Encodes a signature in an OpenZeppelin layout: s1 packed (29 felts), salt_a, salt_b, then the\n * hint s1·h packed (29 felts) in the hint layout.\n * @param {OzSignature} sig the decoded signature\n * @param {OzVariant} variant the layout: 'hint' (60 felts) or 'direct' (31 felts)\n * @returns {string[]} the felts, as hex strings\n * @throws {Error} when the hint layout is asked without the hint polynomial\n * @example\n * ```typescript\n * const signature = signHashOz(0x1234n, secretKey, pkNtt, 'hint');\n * const result = formatOzSignature(parseOzSignature(signature, 'hint'), 'hint');\n * // result = signature (the same 60 felts)\n * ```\n */\nexport function formatOzSignature(sig: OzSignature, variant: OzVariant): string[] {\n const felts = [...packPoly(sig.s1), sig.saltA, sig.saltB];\n if (variant === 'hint') {\n if (!sig.mulHint) throw new Error('Falcon512: the hint layout needs the hint polynomial');\n felts.push(...packPoly(sig.mulHint));\n }\n return felts.map((x) => starknet.num.toHex(x));\n}\n\n/**\n * Strict parsing of a signature in an OpenZeppelin layout (hex or decimal strings, numbers,\n * bigints).\n * @param {unknown[]} signature the felts of the signature\n * @param {OzVariant} variant the expected layout: 'hint' (60 felts) or 'direct' (31 felts)\n * @returns {OzSignature} s1, the two salt felts and, in the hint layout, the hint\n * @throws {Error} when the signature does not have the length of the layout, a felt is invalid, a\n * polynomial is not canonical, or a salt felt is not below 2^160\n * @example\n * ```typescript\n * const result = parseOzSignature(signHashOz(0x1234n, secretKey, pkNtt, 'direct'), 'direct');\n * // result = { s1: Uint16Array(512) […], saltA: …n, saltB: …n, mulHint: undefined }\n * parseOzSignature(['0x1'], 'hint');\n * // throws Error(\"Falcon512: signature must have 60 felts\")\n * ```\n */\nexport function parseOzSignature(signature: readonly unknown[], variant: OzVariant): OzSignature {\n const length = OZ_SIGNATURE_FELTS[variant];\n if (!Array.isArray(signature) || signature.length !== length) {\n throw new Error(`Falcon512: signature must have ${length} felts`);\n }\n const felts = signature.map((x, i) => parseFelt(x, `signature[${i}]`));\n const saltA = felts[PACKED_SLOTS];\n const saltB = felts[PACKED_SLOTS + 1];\n saltFeltsToBytes(saltA, saltB); // throws when a salt felt is not below 2^160\n return {\n s1: unpackPoly(felts.slice(0, PACKED_SLOTS)),\n saltA,\n saltB,\n mulHint: variant === 'hint' ? unpackPoly(felts.slice(PACKED_SLOTS + 2)) : undefined,\n };\n}\n\n/**\n * Signs a message hash for an OpenZeppelin account (internal: never exported by index.ts, to avoid\n * blind signing). The salt is 40 random bytes; the engine draws its own sampler seed, independent\n * from the public salt. The encoded signature is checked again before being returned.\n * @param {bigint} msgHash the hash to sign, a felt252\n * @param {Uint8Array} secretKey the NIST Falcon-512 secret key (1281 bytes)\n * @param {Uint16Array} pkNtt the NTT of the public polynomial h\n * @param {OzVariant} variant the layout: 'hint' (60 felts) or 'direct' (31 felts)\n * @param {SignDeps} [deps] the engine and the random source (tests only)\n * @returns {string[]} the felts of the signature, as hex strings\n * @throws {Error} when msgHash is not a felt252, or the self-verification fails\n * @example\n * ```typescript\n * const { secretKey, publicKey } = generateKeyPair();\n * const result = signHashOz(0x1234n, secretKey, publicKeyToNtt(publicKey), 'hint');\n * // result = ['0x…', …] (60 felts, random salt)\n * ```\n */\nexport function signHashOz(\n msgHash: bigint,\n secretKey: Uint8Array,\n pkNtt: Uint16Array,\n variant: OzVariant,\n deps: SignDeps = defaultDeps\n): string[] {\n assertFelt(msgHash, 'message hash');\n const salt = deps.randomBytes(2 * SALT_BYTES);\n const saltA = readLittleEndian(salt.subarray(0, SALT_BYTES));\n const saltB = readLittleEndian(salt.subarray(SALT_BYTES));\n const hashPoint = hashToPointShake(msgHash, saltA, saltB);\n const s1 = Uint16Array.from(deps.engine.signHashPoint(hashPoint, secretKey), modQ);\n const mulHint = variant === 'hint' ? Uint16Array.from(computeMulHint(s1, pkNtt)) : undefined;\n const signature = formatOzSignature({ s1, saltA, saltB, mulHint }, variant);\n const decoded = parseOzSignature(signature, variant);\n const decodedHint = decoded.mulHint ?? computeMulHint(decoded.s1, pkNtt);\n if (!checkSignatureEquation(hashPoint, decoded.s1, decodedHint, pkNtt)) {\n throw new Error('Falcon512: self-verification failed, signature discarded');\n }\n return signature;\n}\n\n/**\n * Verifies a signature of msgHash in an OpenZeppelin layout; false for any malformed input. In the\n * direct layout, the product s1·h is computed here, as the direct account does on-chain.\n * @param {bigint} msgHash the signed hash\n * @param {unknown[]} signature the felts of the signature\n * @param {ArrayLike<number>} pkNtt the NTT of the public polynomial h\n * @param {OzVariant} variant the expected layout: 'hint' (60 felts) or 'direct' (31 felts)\n * @returns {boolean} true for a valid signature of msgHash in this layout, false otherwise\n * @example\n * ```typescript\n * const signature = signHashOz(0x1234n, secretKey, pkNtt, 'direct');\n * const result = verifyHashOz(0x1234n, signature, pkNtt, 'direct');\n * // result = true\n * const result2 = verifyHashOz(0x1234n, signature, pkNtt, 'hint');\n * // result2 = false (31 felts, not 60)\n * ```\n */\nexport function verifyHashOz(\n msgHash: bigint,\n signature: readonly unknown[],\n pkNtt: ArrayLike<number>,\n variant: OzVariant\n): boolean {\n let decoded: OzSignature;\n try {\n assertFelt(msgHash, 'message hash');\n decoded = parseOzSignature(signature, variant);\n } catch {\n return false;\n }\n const mulHint = decoded.mulHint ?? computeMulHint(decoded.s1, pkNtt);\n return checkSignatureEquation(\n hashToPointShake(msgHash, decoded.saltA, decoded.saltB),\n decoded.s1,\n mulHint,\n pkNtt\n );\n}\n","/* eslint-disable -- vendored copy of @noble/post-quantum 0.7.1, kept as is: see PATCH.md */\n/**\n * Falcon pq-friendly signature algorithm.\n * Will change in backwards-incompatible way once FIPS-206 gets finalized.\n * @module\n */\n/*! noble-post-quantum - MIT License (c) 2024 Paul Miller (paulmillr.com) */\nimport { rngAesCtrDrbg256 } from '@noble/ciphers/aes.js';\nimport { chacha20 } from '@noble/ciphers/chacha.js';\nimport { FFTCore } from '@noble/curves/abstract/fft.js';\nimport type { IField } from '@noble/curves/abstract/modular.js';\nimport { invert } from '@noble/curves/abstract/modular.js';\nimport { bytesToNumberLE, numberToHexUnpadded } from '@noble/curves/utils.js';\nimport { shake256 } from '@noble/hashes/sha3.js';\nimport {\n abytes,\n bytesToHex,\n createView,\n hexToBytes,\n randomBytes,\n swap32IfBE,\n type TypedArray,\n u32,\n u8,\n} from '@noble/hashes/utils.js';\nimport { genCrystals, type TypedCons } from './_crystals';\nimport {\n baswap64If,\n type BytesCoderLen,\n cleanBytes,\n copyBytes,\n type Coder,\n type CryptoKeys,\n getMask,\n type Signer,\n type SigOpts,\n splitCoder,\n type TArg,\n type TRet,\n validateSigOpts,\n validateVerOpts,\n SIG_OPT_KEYS,\n type VerOpts,\n} from './utils';\n/*\nFIPS-206 would likely improve the situation with spec.\n\nFalcon (non-FIPS) spec is terrible. Two main issues: non-deterministic keys & floats.\n\n## Summary\n\n- NIST round3 KATs pass\n- No interop with other JS libraries, because they are incorrect\n- No recoverPublicKey: it requires s1, which is calculated from public+s2. Sig only has s2.\n- Code has verify_recover, but it's unused\n- Mediocre code quality, primarily because it follows implementation-specific (C lib) tidbits\n- Samplers are fragile\n\n## Non-deterministic keys\n\nFalcon spec doesn't provide enough data to re-create keys from KAT vectors. Spec mentions:\n> This process reduces the maximum sizes of coefficients of F and G\n> by about 30 bits at each iteration\nWhile actual implementation reduces them by 25 bits (scale_k), which is very important detail.\n\nThere are also various implementation checks not mentioned in spec, like\n> let's skip this perfectly valid key, because it doesn't fit into our bigint implementation\n\nWithout these, it's hard to produce correct keys. This means that,\nunless NIST specifies full process with all operations,\n**all keys are implementation-specific**.\n\nWhich means, we cannot use any key derivation schemes here: same seed will return\ndifferent keys in different implementations.\n\nThis also complicates testing a lot. If a key succesfully signs a message and other implementations\nconfirm it, there is still zero assurance with regards to quality / entropy of the key.\nOne can create a valid key, which nevertheless doesn't have enough entropy.\n\n## Floats\n\nPartially fixed by \"fixed point\" primitive. Falcon basically impelements floats on top of u64.\n\nIt's more constant-time, but in JS there is no **fast** u64:\n\n- Using bigint backend would drop const-timeness\n- Using u32 {hi, low} tuples means unnecessary allocations / jit deopt,\n and is still 4 times slower than Floats\n\nThen, there are rounding issues. This is implementation specific.\nThis matters more for C, since 'double' is not neccesarily binary64.\nIn js, floats guaranteed to be IEEE-754 binary64.\n\nIn theory floats are nice, but since fixed point format is not specified in spec\n(other that \"it is binary64\"), this is even more fragile, since it doesn't implement exact\nfull spec of binary64 (two zeros/subnomarls/nans/etc). Those parts should not be used inside falcon,\nbut may cause some differences.\n\nLack of specification is also hard to debug, brings precision loss (a+b+c !== a+c+b):\nthere are no serialized floats, all float arithmetic happens inside of an algorithm, so\nwe can produce same results (small differences rounded at the end).\n\nFor byte-to-byte result in falcon, one needs to copy implementation-specific details, unspecced.\n\n## CSPRNG\n\nNIST KATs randomness situation is bad:\n\n1. aes-drbg generates seed\n2. The seed passes CSPRNG into sign, which uses shake256 to produce another seed and nonce\n3. Then a separate rejection sampling chacha20 CSPRNG is created, based on that seed.\n\n## Detached vs non-detached\n\nThe API is different between detached / non-detached signatures,\nhowever only non-detached (sm) is included in KAT, so we implement them\n(crypto_sign_open instead of crypto_sign_verify).\n*/\n\n// Utils\n// MSB first. Current Falcon uses are byte-aligned only, and outer wrappers must still enforce\n// exact body lengths / canonical padding because this helper neither flushes nor rejects a final\n// partial field on its own.\nconst bitsCoderMSB = <T extends TypedArray>(\n newPoly: TypedCons<T>,\n N: number,\n d: number,\n c: Coder<number, number>\n): TRet<BytesCoderLen<T>> => {\n const mask = getMask(d);\n const bytesLen = d * (N / 8);\n return {\n bytesLen,\n encode: (poly: TArg<T>): TRet<Uint8Array> => {\n if (poly.length !== N) throw new Error(`wrong length: expected ${N}, got ${poly.length}`);\n const r = new Uint8Array(bytesLen);\n for (let i = 0, buf = 0, bufLen = 0, pos = 0; i < poly.length; i++) {\n buf = (buf << d) | (c.encode(poly[i]) & mask);\n bufLen += d;\n for (; bufLen >= 8; bufLen -= 8) r[pos++] = (buf >>> (bufLen - 8)) & 0xff;\n }\n return r as TRet<Uint8Array>;\n },\n decode: (bytes: TArg<Uint8Array>): TRet<T> => {\n const r = newPoly(N);\n for (let i = 0, buf = 0, bufLen = 0, pos = 0; i < bytes.length; i++) {\n buf = (buf << 8) | bytes[i];\n bufLen += 8;\n for (; bufLen >= d; bufLen -= d) r[pos++] = c.decode((buf >>> (bufLen - d)) & mask);\n }\n return r as TRet<T>;\n },\n } as TRet<BytesCoderLen<T>>;\n};\n// Adds a single leading tag byte. Exact body validation is delegated to `restCoder.decode()`.\n// encode() zeroizes the temporary encoded body after copying, so wrapped encoders must return\n// owned scratch bytes rather than caller-owned buffers.\nconst headerCoder = <T>(tag: number, restCoder: TArg<BytesCoderLen<T>>): TRet<BytesCoderLen<T>> => {\n const coder = restCoder as BytesCoderLen<T>;\n return {\n bytesLen: 1 + coder.bytesLen,\n encode(value: TArg<T>): TRet<Uint8Array> {\n const body = coder.encode(value as T);\n const out = new Uint8Array(1 + body.length);\n out[0] = tag;\n out.set(body, 1);\n cleanBytes(body);\n return out as TRet<Uint8Array>;\n },\n decode(data: TArg<Uint8Array>): TRet<T> {\n if (data[0] !== tag) throw new Error(`wrong tag: expected ${tag}, got 0x${data[0]}`);\n return coder.decode(data.subarray(1)) as TRet<T>;\n },\n } as TRet<BytesCoderLen<T>>;\n};\n\n// Fun, but overengineered. Hoping FIPS would fix this.\n// Falcon-specific Golomb-Rice compressed format:\n// Vec<[1bit sign, 7 bit low, array(1 terminated).length==high <<7]>.\n// decode() returns only coefficients, so callers must still enforce exact consumed length /\n// canonical framing around the payload.\nconst compCoder = (n: number) => {\n const LIMIT = 2047;\n return {\n encode(data: TArg<Int16Array>): TRet<Uint8Array> {\n // Algorithm 17: Compress(s, slen) (Page 47)\n // Require: A polynomial s = Σ sᵢxⁱ ∈ Z[x] of degree < n, a string bitlength slen\n // Ensure: A compressed representation str of s of slen bits, or ⊥\n // 1: str ← {} ▷ str is the empty string\n // 2: for i from 0 to n-1 do ▷ At each step, str ← (str||strᵢ), where strᵢ encodes sᵢ\n // 3: str ← (str||b), where b = 1 if sᵢ < 0, b = 0 otherwise ▷ Encode the sign of sᵢ\n // 4: str ← (str||b₆b₅...b₀), where bⱼ = (|sᵢ| >> j) & 0x1\n // ▷ Encode in binary the low bits of |sᵢ|\n // 5: k ← |sᵢ| >> 7\n // 6: str ← (str||0ᵏ1) ▷ Encode in unary the high bits of |sᵢ|\n // 7: if |str| > slen then\n // 8: str ← ⊥ ▷ Abort if str is too long\n // 9: else\n // 10: str ← (str||0^{slen-|str|}) ▷ Pad str to slen bits\n // 11: return str\n if (data.length !== n) throw new Error('wrong length');\n const res: number[] = [];\n let buf = 0;\n let bufLen = 0;\n const writeBits = (n: number, v: number) => {\n bufLen += n;\n buf = (buf << n) | v;\n // flush buffer if bigger than byte\n for (; bufLen >= 8; buf &= getMask(bufLen)) {\n bufLen -= 8;\n res.push((buf >>> bufLen) & 0xff);\n }\n };\n for (let i = 0; i < n; i++) {\n let v = data[i];\n if (!Number.isInteger(v) || v < -LIMIT || v > LIMIT)\n throw new Error(`data[${i}]=${v} out of range`);\n const sign = v < 0 ? 1 : 0;\n v = Math.abs(v);\n writeBits(1, sign);\n writeBits(7, v & 0b0111_1111); // low\n writeBits((v >>> 7) + 1, 1); // high (unary)\n }\n if (bufLen > 0) res.push((buf << (8 - bufLen)) & 0xff);\n return new Uint8Array(res) as TRet<Uint8Array>;\n },\n decode(data: TArg<Uint8Array>): TRet<Int16Array> {\n // Algorithm 18: Decompress(str, slen), (Page 48)\n // Require: A bitstring str = (str[i])_{i=0,...,slen-1}, a bitlength slen\n // Ensure: A polynomial s = Σ sᵢxⁱ ∈ Z[x], or ⊥\n // 1: if |str| ≠ slen then ▷ Enforce fixed bitlength\n // 2: return ⊥\n // 3: for i from 0 to (n-1) do\n // 4: s'ᵢ ← Σ_{j=0 to 6} 2⁶⁻ʲ · str[1 + j] ▷ We recover the lowest bits of |sᵢ|.\n // 5: k ← 0\n // 6: while str[8 + k] = 0 do ▷ We recover the highest bits of |sᵢ|.\n // 7: k ← k + 1\n // 8: sᵢ ← (-1)^{str[0]} · (s'ᵢ + 2⁷k) ▷ We recompute sᵢ.\n // 9: if (sᵢ = 0) and (str[0] = 1) then ▷ Enforce unique encoding if sᵢ = 0\n // 10: return ⊥\n // 11: str ← str with first 9 + k bits removed ▷ We remove the bits of str that encode sᵢ.\n // 12: if str contains any non-zero bits then ▷ Enforce trailing bits at 0\n // 13: return ⊥\n // 14: return s = Σ_{i=0}^{n-1} sᵢxⁱ\n const res = new Int16Array(n);\n let buf = 0;\n let bufLen = 0;\n let pos = 0;\n const readBits = (n: number) => {\n for (; bufLen < n && pos < data.length; bufLen += 8) buf = (buf << 8) | data[pos++];\n if (bufLen < n)\n throw new Error(`end of buffer: len=${bufLen} buf=${buf} lastByte=${data[pos]}`);\n bufLen -= n;\n const val = buf >>> bufLen;\n buf &= getMask(bufLen);\n return val;\n };\n for (let resPos = 0; resPos < n; resPos++) {\n const sign = readBits(1);\n const low = readBits(7);\n let high = 0;\n // Reference comp_decode adds 128 for each unary zero and rejects immediately above 2047.\n // Waiting for the terminating one first lets an invalid coefficient scan the entire input.\n while (!readBits(1)) {\n high++;\n if (high > LIMIT >>> 7) throw new Error(`limit: ${low | (high << 7)} > ${LIMIT}`);\n }\n const v = low | (high << 7);\n if (sign && v === 0) throw new Error('negative zero encoding');\n if (v > LIMIT) throw new Error(`limit: ${v} > ${LIMIT}`);\n res[resPos] = sign ? -v : v;\n }\n if (buf) throw new Error('non-empty accumulator');\n return res as TRet<Int16Array>;\n },\n };\n};\n\n// Falcon padded-signature helper. encode() assumes `data.length <= len`; decode() strips trailing\n// zero padding and returns a subarray view, so it is not a generic byte-string codec.\nconst pad = (len: number) => ({\n encode(data: TArg<Uint8Array>) {\n const res = new Uint8Array(len);\n res.set(data);\n return res;\n },\n decode(data: TArg<Uint8Array>) {\n let end = data.length;\n while (end > 0 && data[end - 1] === 0) end--;\n return data.subarray(0, end);\n },\n});\n// TODO: merge with noble-curves bls?\ntype ComplexElm<T> = { re: T; im: T };\n// Zero complex-polynomial temporaries in place. Requires fully initialized `{ re, im }` entries.\nconst cleanCPoly = (...list: CPoly[]): void => {\n for (const p of list) {\n for (let i = 0; i < p.length; i++) {\n p[i].re = 0;\n p[i].im = 0;\n }\n }\n};\n// Generic complex helper used by Falcon's FFT code. Current audited use relies on\n// add/sub/mul/conj/scale/magSqSum/neg; inv() is intentionally unimplemented.\nfunction getComplex<T>(field: IField<T>) {\n const F = field;\n return {\n lift: (x: ComplexElm<T> | T): ComplexElm<T> => {\n // Reuse existing complex objects verbatim; callers that need isolation must clone first.\n if ((x as any).re !== undefined && (x as any).im !== undefined) return x as ComplexElm<T>;\n return { re: x as T, im: F.ZERO };\n },\n add: (a: ComplexElm<T>, b: ComplexElm<T>): ComplexElm<T> => ({\n re: F.add(a.re, b.re),\n im: F.add(a.im, b.im),\n }),\n sub: (a: ComplexElm<T>, b: ComplexElm<T>): ComplexElm<T> => ({\n re: F.sub(a.re, b.re),\n im: F.sub(a.im, b.im),\n }),\n mul: (a: ComplexElm<T>, b: ComplexElm<T>): ComplexElm<T> => ({\n re: F.sub(F.mul(a.re, b.re), F.mul(a.im, b.im)),\n im: F.add(F.mul(a.re, b.im), F.mul(a.im, b.re)),\n }),\n div: (a: ComplexElm<T>, b: ComplexElm<T>): ComplexElm<T> => {\n const denom = F.add(F.mul(b.re, b.re), F.mul(b.im, b.im));\n return {\n re: F.div(F.add(F.mul(a.re, b.re), F.mul(a.im, b.im)), denom),\n im: F.div(F.sub(F.mul(a.im, b.re), F.mul(a.re, b.im)), denom),\n };\n },\n neg: (a: ComplexElm<T>): ComplexElm<T> => ({ re: F.neg(a.re), im: F.neg(a.im) }),\n conj: (a: ComplexElm<T>): ComplexElm<T> => ({ re: a.re, im: F.neg(a.im) }),\n scale: (a: ComplexElm<T>, x: T | bigint): ComplexElm<T> => ({\n re: F.mul(a.re, x),\n im: F.mul(a.im, x),\n }),\n // a.re * a.re + a.im * a.im + b.re * b.re + b.im * b.im;\n magSqSum: (a: ComplexElm<T>, b: ComplexElm<T>): T =>\n F.add(\n F.add(F.add(F.mul(a.re, a.re), F.mul(a.im, a.im)), F.mul(b.re, b.re)),\n F.mul(b.im, b.im)\n ),\n eql: (a: ComplexElm<T>, b: ComplexElm<T>): boolean => F.eql(a.re, b.re) && F.eql(a.im, b.im),\n clone: (a: ComplexElm<T>): ComplexElm<T> => ({ re: a.re, im: a.im }),\n inv: () => {\n throw new Error('not implemented');\n },\n };\n}\n// Falcon real-polynomial FFT layout: [...re, ...im]. Requires an even-length flat array and\n// copies into fresh JS objects / arrays instead of creating views.\nconst ComplexArr = {\n decode(lst: number[]): ComplexElm<number>[] {\n const N = lst.length;\n const hn = N >> 1;\n const len = lst.length;\n if (len === 0) return [];\n if (len % 2 !== 0)\n throw new Error('Array length must be even to pair real and imaginary parts.');\n const res = [];\n for (let i = 0; i < hn; i++) {\n res.push({ re: lst[i], im: lst[i + hn] });\n }\n return res;\n },\n encode(lst: ComplexElm<number>[]): number[] {\n const re = [];\n const im = [];\n for (const i of lst) {\n re.push(i.re);\n im.push(i.im);\n }\n return [...re, ...im];\n },\n};\n// Precomputed root-table layout [re[0], im[0], re[1], im[1], ...]. Used for `COMPLEX_ROOTS`,\n// not Falcon's packed polynomial FFT layout; encode() is currently unused.\n// decode() / encode() copy between the flat root table\n// and detached `{ re, im }` objects; they never create aliasing views.\nconst ComplexArrInterleaved = {\n decode(lst: ArrayLike<number>): ComplexElm<number>[] {\n const len = lst.length;\n if (len === 0) return [];\n if (len % 2 !== 0)\n throw new Error('Array length must be even to pair real and imaginary parts.');\n const res: ComplexElm<number>[] = [];\n // Iterate through the list, taking two elements at a time\n for (let i = 0; i < len; i += 2) {\n res.push({ re: lst[i], im: lst[i + 1] });\n }\n return res;\n },\n encode(lst: ComplexElm<number>[]): number[] {\n const res: number[] = [];\n for (const complexNum of lst) {\n res.push(complexNum.re);\n res.push(complexNum.im);\n }\n return res;\n },\n};\n// Alias a Float64Array as bytes for the root-table hash pin; not a portable serialization.\nconst u8f = (arr: TArg<Float64Array>): TRet<Uint8Array> =>\n new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength) as TRet<Uint8Array>;\n\n// Alias bytes as Float64Array lanes. Falcon's exact binary64 tables are stored as little-endian\n// payload bytes, so BE runtimes must decode lane-by-lane instead of aliasing host-endian floats.\n// Copy/truncate to whole 8-byte lanes first\n// so BE byte swaps cannot mutate caller-owned bytes\n// or read a partial float.\nconst f64a = (arr: TArg<Uint8Array>): TRet<Float64Array> =>\n new Float64Array(\n baswap64If(Uint8Array.from(arr.subarray(0, Math.floor(arr.byteLength / 8) * 8))).buffer\n ) as TRet<Float64Array>;\n\n// Exact big-endian binary64 hex helper for constants. Only decode() is currently used; malformed\n// inputs fail through lower-level hex / DataView checks instead of an explicit wrapper guard.\nconst Float = /* @__PURE__ */ Object.freeze({\n encode(n: number): string {\n const bytes = new Uint8Array(8);\n const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);\n view.setFloat64(0, n, false);\n return bytesToHex(bytes);\n },\n decode(s: string): number {\n const bytes = hexToBytes(s);\n const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);\n return view.getFloat64(0, false);\n },\n});\n// Decode a 64-bit bigint bit pattern into the exact binary64 value.\nconst f64b = (n: bigint): number => Float.decode(numberToHexUnpadded(n));\n\n// Types\ntype SignatureRaw = { msg: Uint8Array; nonce: Uint8Array; s2: Uint8Array };\ntype BPoly = bigint[];\ntype FPoly = Float64Array;\ntype SPoly = Int8Array; // Small poly (f/g/F/G)\ntype IPoly = Uint16Array; // Integer poly mod Q\n\n// Constants\nconst EMPTY_CHACHA20_BLOCK = /** @__PURE__ */ new Uint8Array(64);\n// Falcon's randomized hashing salt r is always 320 bits / 40 bytes, and the same width\n// also drives the detached and attached signature wire formats.\nconst NONCELEN = 40;\n\n// Falcon's public modulus q = 12289 is also the NTT parameter chosen in round 3.\nconst Q: number = 12289; // 12 * 1024 + 1\n// Falcon's midpoint floor(q/2); the only live use is the mirrored G-reconstruction reduction below.\nconst Qhalf: number = Q >> 1;\nconst QBig = BigInt(Q);\nconst _0n = /* @__PURE__ */ BigInt(0);\nconst _1n = /* @__PURE__ */ BigInt(1);\nconst _10n = /* @__PURE__ */ BigInt(10);\nconst _25n = /* @__PURE__ */ BigInt(25);\nconst _31n = /* @__PURE__ */ BigInt(31);\nconst _32n = /* @__PURE__ */ BigInt(32);\nconst _63n = /* @__PURE__ */ BigInt(63);\nconst _64n = /* @__PURE__ */ BigInt(64);\n// Low 32 bits and low 63 bits of a bigint, used by the chacha20 counter and gaussian sampler.\nconst MASK_32n = /* @__PURE__ */ BigInt('0xffffffff');\nconst MASK_63n = /* @__PURE__ */ BigInt('0x7fffffffffffffff');\n//const R = 4091; // 2^16 mod q\n// This 16-bit Montgomery kernel uses R = 2^16, so mul(x, R2) converts x into Montgomery form.\nconst R2 = 10952; // 2^32 mod q\n// falcon.pdf page 55 says \"1/q mod 2^16\",\n// but the reduction formula and the round-3 Falcon code both require -1/q.\nconst Q0I = 12287; // -1/q mod 2^16\nconst F_INV_Q = 1.0 / Q;\nconst F_MINUS_INV_Q = -F_INV_Q;\n// Round-3 bigint keygen keeps these tables coupled: MAX_BL_SMALL and MAX_BL_LARGE are measured\n// 31-bit word bounds, and BITLENGTH is the measured avg/stddev heuristic. Edits must recheck the\n// next-depth relation and the current 31 * wordCount headroom used by reduce().\nconst MAX_BL_SMALL = [1, 1, 2, 2, 4, 7, 14, 27, 53, 106, 209];\n// Unreduced F/G word bounds for reduce(); the same round-3 source also couples this table to the\n// top-10-word floating approximation there,\n// so it must stay in sync with MAX_BL_SMALL and BITLENGTH.\nconst MAX_BL_LARGE = [2, 2, 5, 7, 12, 21, 40, 78, 157, 308];\n// Exact binary64 encoding of Falcon's Gram-Schmidt keygen bound (1.17^2) * q = 16822.4121.\nconst BNORM_MAX = f64b(BigInt('4670353323383631276'));\n// Measured round-3 bigint-keygen heuristic, not a normative Falcon parameter table or proof bound.\nconst BITLENGTH = [\n { avg: 4, std: 0 },\n { avg: 11, std: 1 },\n { avg: 24, std: 1 },\n { avg: 50, std: 1 },\n { avg: 102, std: 1 },\n { avg: 202, std: 2 },\n { avg: 401, std: 4 },\n { avg: 794, std: 5 },\n { avg: 1577, std: 8 },\n { avg: 3138, std: 13 },\n { avg: 6308, std: 25 },\n];\n// First entry is P(x = 0); the remaining entries are conditional tail thresholds scaled by 2^63.\n// Smaller Falcon dimensions reuse the N = 1024, q = 12289 table by summing 2^(10-logn) draws.\n// The trailing 0 sentinel guarantees gaussSingle()\n// always selects a tail bucket when x = 0 is missed.\nconst gauss_1024_12289 = /* @__PURE__ */ [\n '1283868770400643928',\n '6416574995475331444',\n '4078260278032692663',\n '2353523259288686585',\n '1227179971273316331',\n '575931623374121527',\n '242543240509105209',\n '91437049221049666',\n '30799446349977173',\n '9255276791179340',\n '2478152334826140',\n '590642893610164',\n '125206034929641',\n '23590435911403',\n '3948334035941',\n '586753615614',\n '77391054539',\n '9056793210',\n '940121950',\n '86539696',\n '7062824',\n '510971',\n '32764',\n '1862',\n '94',\n '4',\n '0',\n].map(BigInt);\n\n// Exact binary64 1/sigma payloads from round-3 fpr.h. Nearby decimal spellings round 1 ULP low in\n// JS, so keep these as decoded bit patterns and recheck the raw payloads after edits.\nconst INV_SIGMA = /* @__PURE__ */ Object.freeze([\n 0.0, // unused\n f64b(BigInt('4574611497772390042')),\n f64b(BigInt('4574501679055810265')),\n f64b(BigInt('4574396282908341804')),\n f64b(BigInt('4574245855758572086')),\n f64b(BigInt('4574103865040221165')),\n f64b(BigInt('4573969550563515544')),\n f64b(BigInt('4573842244705920822')),\n f64b(BigInt('4573721358406441454')),\n f64b(BigInt('4573606369665796042')),\n f64b(BigInt('4573496814039276259')),\n]);\n\n// Exact binary64 sigma_min constants from round-3 fpr.h indexed by logn; despite one PQClean\n// summary comment, these are sigma_min itself, not 1/sigma_min, which is why this table stays\n// separate from INV_SIGMA.\nconst SIGMA_MIN = /* @__PURE__ */ Object.freeze([\n 0.0, // unused\n f64b(BigInt('4607707126469777035')),\n f64b(BigInt('4607777455861499430')),\n f64b(BigInt('4607846828256951418')),\n f64b(BigInt('4607949175006100261')),\n f64b(BigInt('4608049571757433526')),\n f64b(BigInt('4608148125896792003')),\n f64b(BigInt('4608244935301382692')),\n f64b(BigInt('4608340089478362016')),\n f64b(BigInt('4608433670533905013')),\n f64b(BigInt('4608525754002622308')),\n]);\n// Upper end of the SamplerZ proof interval from Falcon section 3.9.1. The per-leaf sigma is\n// derived from the reconstructed private basis, so imported keys must be checked against it.\nconst SIGMA_MAX = 1.8205;\n\n// Falcon Table 3.1 RCDT values for chi, split into 24-bit limbs; storage is [high, mid, low],\n// so gaussian0() intentionally compares them against v0, v1, v2 in reverse order. The final\n// RCDT[18] = 0 row is omitted because the algorithm iterates only over i = 0..17.\nconst GAUSS0 = new Uint32Array([\n 10745844, 3068844, 3741698, 5559083, 1580863, 8248194, 2260429, 13669192, 2736639, 708981,\n 4421575, 10046180, 169348, 7122675, 4136815, 30538, 13063405, 7650655, 4132, 14505003, 7826148,\n 417, 16768101, 11363290, 31, 8444042, 8086568, 1, 12844466, 265321, 0, 1232676, 13644283, 0,\n 38047, 9111839, 0, 870, 6138264, 0, 14, 12545723, 0, 0, 3104126, 0, 0, 28824, 0, 0, 198, 0, 0, 1,\n]);\n\n// Inclusive floor(beta^2) signature-acceptance bounds indexed by logn; the Falcon PDF publishes\n// only Falcon-512 and Falcon-1024 directly, while the smaller rows are mirrored from the round-3\n// NIST submission package.\nconst L2BOUND = [\n 0, // unused\n 101498,\n 208714,\n 428865,\n 892039,\n 1852696,\n 3842630,\n 7959734,\n 16468416,\n 34034726,\n 70265242,\n];\n\n// 32kb in hex.\n// Could be 4x smaller by using 2 bytes per root. However, that would mean using sin/cos.\n// Different JS engines give different sin / cos result, which means the result would be unreliable.\n// See \"COMPLEX ROOT GENERATION FOR FALCON\" in tests.\n// Those exact roots are taken from the round-3 Falcon submission, preserving its original\n// bit-reversed order here and remapping it only later for FFTCore.\nconst COMPLEX_ROOTS = /** @__PURE__ */ (() => {\n const roots = f64a(\n hexToBytes(\n '000000000000000000000000000000000000000000000080000000000000f03fcd3b7f669ea0e63fcd3b7f66' +\n '9ea0e63fcd3b7f669ea0e6bfcd3b7f669ea0e63f468d32cf6b90ed3f63a9aea6e27dd83f63a9aea6e27dd8bf' +\n '468d32cf6b90ed3f63a9aea6e27dd83f468d32cf6b90ed3f468d32cf6b90edbf63a9aea6e27dd83fb05cf7cf' +\n '9762ef3f0ba6693cb8f8c83f0ba6693cb8f8c8bfb05cf7cf9762ef3fc868ae393bc7e13fa3a10e29669bea3f' +\n 'a3a10e29669beabfc868ae393bc7e13fa3a10e29669bea3fc868ae393bc7e13fc868ae393bc7e1bfa3a10e29' +\n '669bea3f0ba6693cb8f8c83fb05cf7cf9762ef3fb05cf7cf9762efbf0ba6693cb8f8c83f2625d1a38dd8ef3f' +\n '2cb429bca617b93f2cb429bca617b9bf2625d1a38dd8ef3fd61d0925f34ce43f4117156b80bce83f4117156b' +\n '80bce8bfd61d0925f34ce43fb1bd80f1b238ec3f3bf606385d2bde3f3bf606385d2bdebfb1bd80f1b238ec3f' +\n '069fd52e0694d23fda2dc656419fee3fda2dc656419feebf069fd52e0694d23fda2dc656419fee3f069fd52e' +\n '0694d23f069fd52e0694d2bfda2dc656419fee3f3bf606385d2bde3fb1bd80f1b238ec3fb1bd80f1b238ecbf' +\n '3bf606385d2bde3f4117156b80bce83fd61d0925f34ce43fd61d0925f34ce4bf4117156b80bce83f2cb429bc' +\n 'a617b93f2625d1a38dd8ef3f2625d1a38dd8efbf2cb429bca617b93f7e6d79e321f6ef3f14d80df1651fa93f' +\n '14d80df1651fa9bf7e6d79e321f6ef3fa0ec8c34697de53fafaf6a22dfb5e73fafaf6a22dfb5e7bfa0ec8c34' +\n '697de53f73c73cf47aedec3fc05ce109105ddb3fc05ce109105ddbbf73c73cf47aedec3fdd1fab759a8fd53f' +\n 'e586f6042121ee3fe586f6042121eebfdd1fab759a8fd53fd73092fb7e0aef3f1b5f217bf919cf3f1b5f217b' +\n 'f919cfbfd73092fb7e0aef3feeff22998773e03f3e6e19458372eb3f3e6e19458372ebbfeeff22998773e03f' +\n '4187f347e0b3e93f3570e1fcf70fe33f3570e1fcf70fe3bf4187f347e0b3e93f3a618e6e10c8c23f17a5087f' +\n '55a7ef3f17a5087f55a7efbf3a618e6e10c8c23f17a5087f55a7ef3f3a618e6e10c8c23f3a618e6e10c8c2bf' +\n '17a5087f55a7ef3f3570e1fcf70fe33f4187f347e0b3e93f4187f347e0b3e9bf3570e1fcf70fe33f3e6e1945' +\n '8372eb3feeff22998773e03feeff22998773e0bf3e6e19458372eb3f1b5f217bf919cf3fd73092fb7e0aef3f' +\n 'd73092fb7e0aefbf1b5f217bf919cf3fe586f6042121ee3fdd1fab759a8fd53fdd1fab759a8fd5bfe586f604' +\n '2121ee3fc05ce109105ddb3f73c73cf47aedec3f73c73cf47aedecbfc05ce109105ddb3fafaf6a22dfb5e73f' +\n 'a0ec8c34697de53fa0ec8c34697de5bfafaf6a22dfb5e73f14d80df1651fa93f7e6d79e321f6ef3f7e6d79e3' +\n '21f6efbf14d80df1651fa93f0dcd846088fdef3f7e66a3f75521993f7e66a3f7552199bf0dcd846088fdef3f' +\n 'df2c1d55b710e63f96ffef37082de73f96ffef37082de7bfdf2c1d55b710e63f3ac94dd13441ed3f8aeda843' +\n '79efd93f8aeda84379efd9bf3ac94dd13441ed3f9f45fa308508d73f3cc2ccb613dbed3f3cc2ccb613dbedbf' +\n '9f45fa308508d73f89e564acf338ef3f634f7e6a820bcc3f634f7e6a820bccbf89e564acf338ef3f234b1b54' +\n 'b31ee13f000215580a09eb3f000215580a09ebbf234b1b54b31ee13f822746a0a729ea3fdf12dd4c056de23f' +\n 'df12dd4c056de2bf822746a0a729ea3fc63f8b4414e2c53fa94b71fa6487ef3fa94b71fa6487efbfc63f8b44' +\n '14e2c53fd39fe17064c2ef3f0e73a9564e56bf3f0e73a9564e56bfbfd39fe17064c2ef3fb9502029faafe33f' +\n 'fb639249223ae93ffb639249223ae9bfb9502029faafe33f2a956facc0d7eb3fba9af8dba48bdf3fba9af8db' +\n 'a48bdfbf2a956facc0d7eb3f77f6b162d211d13f634968e740d7ee3f634968e740d7eebf77f6b162d211d13f' +\n '12e148ec8862ee3f016617945c13d43f016617945c13d4bf12e148ec8862ee3f5ec431996ec6dc3ff5113421' +\n '4b95ec3ff51134214b95ecbf5ec431996ec6dc3f6e97ff0b0e3be83fe9e5e3bbcae6e43fe9e5e3bbcae6e4bf' +\n '6e97ff0b0e3be83ff619ce9220d5b23f3a8801adcde9ef3f3a8801adcde9efbff619ce9220d5b23f3a8801ad' +\n 'cde9ef3ff619ce9220d5b23ff619ce9220d5b2bf3a8801adcde9ef3fe9e5e3bbcae6e43f6e97ff0b0e3be83f' +\n '6e97ff0b0e3be8bfe9e5e3bbcae6e43ff51134214b95ec3f5ec431996ec6dc3f5ec431996ec6dcbff5113421' +\n '4b95ec3f016617945c13d43f12e148ec8862ee3f12e148ec8862eebf016617945c13d43f634968e740d7ee3f' +\n '77f6b162d211d13f77f6b162d211d1bf634968e740d7ee3fba9af8dba48bdf3f2a956facc0d7eb3f2a956fac' +\n 'c0d7ebbfba9af8dba48bdf3ffb639249223ae93fb9502029faafe33fb9502029faafe3bffb639249223ae93f' +\n '0e73a9564e56bf3fd39fe17064c2ef3fd39fe17064c2efbf0e73a9564e56bf3fa94b71fa6487ef3fc63f8b44' +\n '14e2c53fc63f8b4414e2c5bfa94b71fa6487ef3fdf12dd4c056de23f822746a0a729ea3f822746a0a729eabf' +\n 'df12dd4c056de23f000215580a09eb3f234b1b54b31ee13f234b1b54b31ee1bf000215580a09eb3f634f7e6a' +\n '820bcc3f89e564acf338ef3f89e564acf338efbf634f7e6a820bcc3f3cc2ccb613dbed3f9f45fa308508d73f' +\n '9f45fa308508d7bf3cc2ccb613dbed3f8aeda84379efd93f3ac94dd13441ed3f3ac94dd13441edbf8aeda843' +\n '79efd93f96ffef37082de73fdf2c1d55b710e63fdf2c1d55b710e6bf96ffef37082de73f7e66a3f75521993f' +\n '0dcd846088fdef3f0dcd846088fdefbf7e66a3f75521993fdb929b1662ffef3f84c7defcd121893f84c7defc' +\n 'd12189bfdb929b1662ffef3f3d78f0251959e63fafa8ea5444e7e63fafa8ea5444e7e6bf3d78f0251959e63f' +\n '8be6c9736169ed3fd793bc632a37d93fd793bc632a37d9bf8be6c9736169ed3fe7cc1d31a9c3d73f9ba03862' +\n '52b6ed3f9ba0386252b6edbfe7cc1d31a9c3d73f2d2f0b3b604eef3f5104b025a082ca3f5104b025a082cabf' +\n '2d2f0b3b604eef3f49dbde634d73e13f11d5219ebcd2ea3f11d5219ebcd2eabf49dbde634d73e13fe2fa021b' +\n '0963ea3f59eb3399791ae23f59eb3399791ae2bfe2fa021b0963ea3f31bf50ded96dc73f7720a1a39975ef3f' +\n '7720a1a39975efbf31bf50ded96dc73f7ba66dfd15ceef3fd5c29ec78537bc3fd5c29ec78537bcbf7ba66dfd' +\n '15ceef3fd4564553d9fee33f0d94efa3ccfbe83f0d94efa3ccfbe8bfd4564553d9fee33f49557226c408ec3f' +\n 'd678ef5219dcde3fd678ef5219dcdebf49557226c408ec3f3edb4c3f44d3d13f740bdfc8d8bbee3f740bdfc8' +\n 'd8bbeebf3edb4c3f44d3d13f0dd14cab7b81ee3f5281e1c21054d33f5281e1c21054d3bf0dd14cab7b81ee3f' +\n '89e3865b7779dd3f9b7388348b67ec3f9b7388348b67ecbf89e3865b7779dd3fbf2eba0f407ce83f39099b9b' +\n '449ae43f39099b9b449ae4bfbf2eba0f407ce83f19a49a0ad0f6b53f095bbdfccae1ef3f095bbdfccae1efbf' +\n '19a49a0ad0f6b53fad718e6595f0ef3fe020f8796e65af3fe020f8796e65afbfad718e6595f0ef3f9655a392' +\n '8232e53f711757e3ecf8e73f711757e3ecf8e7bf9655a3928232e53f5cfcfcf3f0c1ec3fe71e01d84912dc3f' +\n 'e71e01d84912dcbf5cfcfcf3f0c1ec3f6ae77842e2d1d43f7ec12b4b6a42ee3f7ec12b4b6a42eebf6ae77842' +\n 'e2d1d43fc273e4a378f1ee3faefd370eb84fd03faefd370eb84fd0bfc273e4a378f1ee3fb73e4c87fc1ce03f' +\n 'd2903567aaa5eb3fd2903567aaa5ebbfb73e4c87fc1ce03f42d7c7f47e77e93ff35906b15860e33ff35906b1' +\n '5860e3bf42d7c7f47e77e93f77f5dacef039c13f41d7957179b5ef3f41d7957179b5efbf77f5dacef039c13f' +\n '9b09c924f997ef3f5a3e29b17655c43f5a3e29b17655c4bf9b09c924f997ef3feaf3fa25dbbee23f94af29ef' +\n '43efe93f94af29ef43efe9bfeaf3fa25dbbee23f1257f53e4d3eeb3f8f895d4d70c9e03f8f895d4d70c9e0bf' +\n '1257f53e4d3eeb3f114345e54f93cd3fda3a76f75222ef3fda3a76f75222efbf114345e54f93cd3f2bbe2d62' +\n 'aefeed3fc6273fdd7d4cd63fc6273fdd7d4cd6bf2bbe2d62aefeed3fca3f6d2bc8a6da3fdc353e74e717ed3f' +\n 'dc353e74e717edbfca3f6d2bc8a6da3f6172035fe771e73f8c0165be7bc7e53f8c0165be7bc7e5bf6172035f' +\n 'e771e73fcd55947565d8a23f5df7feef72faef3f5df7feef72faefbfcd55947565d8a23f5df7feef72faef3f' +\n 'cd55947565d8a23fcd55947565d8a2bf5df7feef72faef3f8c0165be7bc7e53f6172035fe771e73f6172035f' +\n 'e771e7bf8c0165be7bc7e53fdc353e74e717ed3fca3f6d2bc8a6da3fca3f6d2bc8a6dabfdc353e74e717ed3f' +\n 'c6273fdd7d4cd63f2bbe2d62aefeed3f2bbe2d62aefeedbfc6273fdd7d4cd63fda3a76f75222ef3f114345e5' +\n '4f93cd3f114345e54f93cdbfda3a76f75222ef3f8f895d4d70c9e03f1257f53e4d3eeb3f1257f53e4d3eebbf' +\n '8f895d4d70c9e03f94af29ef43efe93feaf3fa25dbbee23feaf3fa25dbbee2bf94af29ef43efe93f5a3e29b1' +\n '7655c43f9b09c924f997ef3f9b09c924f997efbf5a3e29b17655c43f41d7957179b5ef3f77f5dacef039c13f' +\n '77f5dacef039c1bf41d7957179b5ef3ff35906b15860e33f42d7c7f47e77e93f42d7c7f47e77e9bff35906b1' +\n '5860e33fd2903567aaa5eb3fb73e4c87fc1ce03fb73e4c87fc1ce0bfd2903567aaa5eb3faefd370eb84fd03f' +\n 'c273e4a378f1ee3fc273e4a378f1eebfaefd370eb84fd03f7ec12b4b6a42ee3f6ae77842e2d1d43f6ae77842' +\n 'e2d1d4bf7ec12b4b6a42ee3fe71e01d84912dc3f5cfcfcf3f0c1ec3f5cfcfcf3f0c1ecbfe71e01d84912dc3f' +\n '711757e3ecf8e73f9655a3928232e53f9655a3928232e5bf711757e3ecf8e73fe020f8796e65af3fad718e65' +\n '95f0ef3fad718e6595f0efbfe020f8796e65af3f095bbdfccae1ef3f19a49a0ad0f6b53f19a49a0ad0f6b5bf' +\n '095bbdfccae1ef3f39099b9b449ae43fbf2eba0f407ce83fbf2eba0f407ce8bf39099b9b449ae43f9b738834' +\n '8b67ec3f89e3865b7779dd3f89e3865b7779ddbf9b7388348b67ec3f5281e1c21054d33f0dd14cab7b81ee3f' +\n '0dd14cab7b81eebf5281e1c21054d33f740bdfc8d8bbee3f3edb4c3f44d3d13f3edb4c3f44d3d1bf740bdfc8' +\n 'd8bbee3fd678ef5219dcde3f49557226c408ec3f49557226c408ecbfd678ef5219dcde3f0d94efa3ccfbe83f' +\n 'd4564553d9fee33fd4564553d9fee3bf0d94efa3ccfbe83fd5c29ec78537bc3f7ba66dfd15ceef3f7ba66dfd' +\n '15ceefbfd5c29ec78537bc3f7720a1a39975ef3f31bf50ded96dc73f31bf50ded96dc7bf7720a1a39975ef3f' +\n '59eb3399791ae23fe2fa021b0963ea3fe2fa021b0963eabf59eb3399791ae23f11d5219ebcd2ea3f49dbde63' +\n '4d73e13f49dbde634d73e1bf11d5219ebcd2ea3f5104b025a082ca3f2d2f0b3b604eef3f2d2f0b3b604eefbf' +\n '5104b025a082ca3f9ba0386252b6ed3fe7cc1d31a9c3d73fe7cc1d31a9c3d7bf9ba0386252b6ed3fd793bc63' +\n '2a37d93f8be6c9736169ed3f8be6c9736169edbfd793bc632a37d93fafa8ea5444e7e63f3d78f0251959e63f' +\n '3d78f0251959e6bfafa8ea5444e7e63f84c7defcd121893fdb929b1662ffef3fdb929b1662ffefbf84c7defc' +\n 'd121893f928a8e85d8ffef3f710067fef021793f710067fef02179bf928a8e85d8ffef3f10af9184f77ce63f' +\n '7582c1730dc4e63f7582c1730dc4e6bf10af9184f77ce63ff9ecb8020b7ded3fb0a4c82ea5dad83fb0a4c82e' +\n 'a5dad8bff9ecb8020b7ded3fc4aa4eb0e320d83f888966a983a3ed3f888966a983a3edbfc4aa4eb0e320d83f' +\n '849e78b1a258ef3f6643dcf2cbbdc93f6643dcf2cbbdc9bf849e78b1a258ef3fb8b9f2095a9de13fd4c01659' +\n '32b7ea3fd4c0165932b7eabfb8b9f2095a9de13f9de69f52587fea3f1b86bc8bf0f0e13f1b86bc8bf0f0e1bf' +\n '9de69f52587fea3fc6649ce86633c83fb7bbf57d3f6cef3fb7bbf57d3f6cefbfc6649ce86633c83f840b2214' +\n '79d3ef3f035c4924b7a7ba3f035c4924b7a7babf840b221479d3ef3fb16b8e17ff25e43fcc98163345dce83f' +\n 'cc98163345dce8bfb16b8e17ff25e43fb071a93fde20ec3f1451f8eae083de3f1451f8eae083debfb071a93f' +\n 'de20ec3f71bbc3abbb33d23f8ea8e7e8b2adee3f8ea8e7e8b2adeebf71bbc3abbb33d23ff2f71d368490ee3f' +\n '8703ecda22f4d23f8703ecda22f4d2bff2f71d368490ee3f58cc81148fd2dd3f07692b014250ec3f07692b01' +\n '4250ecbf58cc81148fd2dd3faad44d9a7e9ce83f4773981bb573e43f4773981bb573e4bfaad44d9a7e9ce83f' +\n '215b5d6a5887b73f56f4f19f53ddef3f56f4f19f53ddefbf215b5d6a5887b73f5c578d0f83f3ef3fe3d7c012' +\n '8d42ac3fe3d7c0128d42acbf5c578d0f83f3ef3f375197381058e53fb23dc36c83d7e73fb23dc36c83d7e7bf' +\n '375197381058e53ff6328b89d9d7ec3f01bd0423cfb7db3f01bd0423cfb7dbbff6328b89d9d7ec3f243caf80' +\n 'd830d53f25ce70e8ea31ee3f25ce70e8ea31eebf243caf80d830d53fec950b0c22feee3ff9eddf1adcdccf3f' +\n 'f9eddf1adcdccfbfec950b0c22feee3f1a22ae265648e03fe90475d2388ceb3fe90475d2388cebbf1a22ae26' +\n '5648e03f220dd82ecf95e93f578e0c0d4038e33f578e0c0d4038e3bf220dd82ecf95e93fcf7becd41601c23f' +\n 'bbcf468e8eaeef3fbbcf468e8eaeefbfcf7becd41601c23fc8b2ad55ce9fef3f148dcdb0db8ec33f148dcdb0' +\n 'db8ec3bfc8b2ad55ce9fef3f17eae8e380e7e23fd580eaf5b1d1e93fd580eaf5b1d1e9bf17eae8e380e7e23f' +\n '051492fe8958eb3fe1c51774909ee03fe1c51774909ee0bf051492fe8958eb3f1b1a101eca56ce3f5d20f753' +\n '8f16ef3f5d20f7538f16efbf1b1a101eca56ce3fac8029ca0c10ee3f93a69e3727eed53f93a69e3727eed5bf' +\n 'ac8029ca0c10ee3f09407f6c0d02db3f92bdb2fed402ed3f92bdb2fed402edbf09407f6c0d02db3fe5554f57' +\n '0094e73f50725d2a8da2e53f50725d2a8da2e5bfe5554f570094e73f43cd90d200fca53fdf81dbda71f8ef3f' +\n 'df81dbda71f8efbf43cd90d200fca53ff8d3f11d25fcef3f01cfd13137699f3f01cfd13137699fbff8d3f11d' +\n '25fcef3f7470839534ece53f8dd2a88d944fe73f8dd2a88d944fe7bf7470839534ece53f9fefe020b22ced3f' +\n 'e5a1de27414bda3fe5a1de27414bdabf9fefe020b22ced3f177ec77d9daad63fda47def705eded3fda47def7' +\n '05ededbf177ec77d9daad63f9d9a08c9c92def3f86b212b38ccfcc3f86b212b38ccfccbf9d9a08c9c92def3f' +\n '7e8e2abb26f4e03fb4130047cd23eb3fb4130047cd23ebbf7e8e2abb26f4e03f37f9baea950cea3fa89c6227' +\n '0796e23fa89c62270796e2bf37f9baea950cea3ff2c59785df1bc53fdb41aeffd58fef3fdb41aeffd58fefbf' +\n 'f2c59785df1bc53f8641e41716bcef3f1d83ba47a072c03f1d83ba47a072c0bf8641e41716bcef3f22ebdf85' +\n '4188e33fd76d8ee4ef58e93fd76d8ee4ef58e9bf22ebdf854188e33fea8093c4d7beeb3f1012e74bf6e2df3f' +\n '1012e74bf6e2dfbfea8093c4d7beeb3f90dbdbcfd9b0d03fbc9d5ae282e4ee3fbc9d5ae282e4eebf90dbdbcf' +\n 'd9b0d03ffc9f72049f52ee3f541057a5b872d43f541057a5b872d4bffc9f72049f52ee3f0b0097497f6cdc3f' +\n '00b9a069c1abec3f00b9a069c1abecbf0b0097497f6cdc3fcc7ab5331b1ae83f9ba0599fc00ce53f9ba0599f' +\n 'c00ce5bfcc7ab5331b1ae83fb309d7340144b13fc473b6ec58edef3fc473b6ec58edefbfb309d7340144b13f' +\n '40392eaff3e5ef3f962027791166b43f962027791166b4bf40392eaff3e5ef3f0400ec45a1c0e43fcc58e91a' +\n 'c55be83fcc58e91ac55be8bf0400ec45a1c0e43ff33c23528e7eec3f5bdbe9e81620dd3f5bdbe9e81620ddbf' +\n 'f33c23528e7eec3fb71404faceb3d33f44976adb2772ee3f44976adb2772eebfb71404faceb3d33f84bfc3d3' +\n 'b2c9ee3f775176d7a072d13f775176d7a072d1bf84bfc3d3b2c9ee3f67d03f960534df3fdd7753e164f0eb3f' +\n 'dd7753e164f0ebbf67d03f960534df3fa29dd46f161be93f4483c53882d7e33f4483c53882d7e3bfa29dd46f' +\n '161be93fc99faecb0ec7bd3f21b7fe6c64c8ef3f21b7fe6c64c8efbfc99faecb0ec7bd3f6e3de629a67eef3f' +\n 'b24af60413a8c63fb24af60413a8c6bf6e3de629a67eef3f1fac98fbd543e23fc89a11c87846ea3fc89a11c8' +\n '7846eabf1fac98fbd543e23f74143cb404eeea3feb6c33af1549e13feb6c33af1549e1bf74143cb404eeea3f' +\n '22673def3247cb3fdd92ff85d043ef3fdd92ff85d043efbf22673def3247cb3f600241cbd7c8ed3ff618240f' +\n '3466d73ff618240f3466d7bf600241cbd7c8ed3fffbd41617193d93fb13ee9526f55ed3fb13ee9526f55edbf' +\n 'ffbd41617193d93f7a6d17b3420ae73fe91b1ca30335e63fe91b1ca30335e6bf7a6d17b3420ae73ffd0ee3bb' +\n '36d9923fa1514bb49cfeef3fa1514bb49cfeefbffd0ee3bb36d9923fa1514bb49cfeef3ffd0ee3bb36d9923f' +\n 'fd0ee3bb36d992bfa1514bb49cfeef3fe91b1ca30335e63f7a6d17b3420ae73f7a6d17b3420ae7bfe91b1ca3' +\n '0335e63fb13ee9526f55ed3fffbd41617193d93fffbd41617193d9bfb13ee9526f55ed3ff618240f3466d73f' +\n '600241cbd7c8ed3f600241cbd7c8edbff618240f3466d73fdd92ff85d043ef3f22673def3247cb3f22673def' +\n '3247cbbfdd92ff85d043ef3feb6c33af1549e13f74143cb404eeea3f74143cb404eeeabfeb6c33af1549e13f' +\n 'c89a11c87846ea3f1fac98fbd543e23f1fac98fbd543e2bfc89a11c87846ea3fb24af60413a8c63f6e3de629' +\n 'a67eef3f6e3de629a67eefbfb24af60413a8c63f21b7fe6c64c8ef3fc99faecb0ec7bd3fc99faecb0ec7bdbf' +\n '21b7fe6c64c8ef3f4483c53882d7e33fa29dd46f161be93fa29dd46f161be9bf4483c53882d7e33fdd7753e1' +\n '64f0eb3f67d03f960534df3f67d03f960534dfbfdd7753e164f0eb3f775176d7a072d13f84bfc3d3b2c9ee3f' +\n '84bfc3d3b2c9eebf775176d7a072d13f44976adb2772ee3fb71404faceb3d33fb71404faceb3d3bf44976adb' +\n '2772ee3f5bdbe9e81620dd3ff33c23528e7eec3ff33c23528e7eecbf5bdbe9e81620dd3fcc58e91ac55be83f' +\n '0400ec45a1c0e43f0400ec45a1c0e4bfcc58e91ac55be83f962027791166b43f40392eaff3e5ef3f40392eaf' +\n 'f3e5efbf962027791166b43fc473b6ec58edef3fb309d7340144b13fb309d7340144b1bfc473b6ec58edef3f' +\n '9ba0599fc00ce53fcc7ab5331b1ae83fcc7ab5331b1ae8bf9ba0599fc00ce53f00b9a069c1abec3f0b009749' +\n '7f6cdc3f0b0097497f6cdcbf00b9a069c1abec3f541057a5b872d43ffc9f72049f52ee3ffc9f72049f52eebf' +\n '541057a5b872d43fbc9d5ae282e4ee3f90dbdbcfd9b0d03f90dbdbcfd9b0d0bfbc9d5ae282e4ee3f1012e74b' +\n 'f6e2df3fea8093c4d7beeb3fea8093c4d7beebbf1012e74bf6e2df3fd76d8ee4ef58e93f22ebdf854188e33f' +\n '22ebdf854188e3bfd76d8ee4ef58e93f1d83ba47a072c03f8641e41716bcef3f8641e41716bcefbf1d83ba47' +\n 'a072c03fdb41aeffd58fef3ff2c59785df1bc53ff2c59785df1bc5bfdb41aeffd58fef3fa89c62270796e23f' +\n '37f9baea950cea3f37f9baea950ceabfa89c62270796e23fb4130047cd23eb3f7e8e2abb26f4e03f7e8e2abb' +\n '26f4e0bfb4130047cd23eb3f86b212b38ccfcc3f9d9a08c9c92def3f9d9a08c9c92defbf86b212b38ccfcc3f' +\n 'da47def705eded3f177ec77d9daad63f177ec77d9daad6bfda47def705eded3fe5a1de27414bda3f9fefe020' +\n 'b22ced3f9fefe020b22cedbfe5a1de27414bda3f8dd2a88d944fe73f7470839534ece53f7470839534ece5bf' +\n '8dd2a88d944fe73f01cfd13137699f3ff8d3f11d25fcef3ff8d3f11d25fcefbf01cfd13137699f3fdf81dbda' +\n '71f8ef3f43cd90d200fca53f43cd90d200fca5bfdf81dbda71f8ef3f50725d2a8da2e53fe5554f570094e73f' +\n 'e5554f570094e7bf50725d2a8da2e53f92bdb2fed402ed3f09407f6c0d02db3f09407f6c0d02dbbf92bdb2fe' +\n 'd402ed3f93a69e3727eed53fac8029ca0c10ee3fac8029ca0c10eebf93a69e3727eed53f5d20f7538f16ef3f' +\n '1b1a101eca56ce3f1b1a101eca56cebf5d20f7538f16ef3fe1c51774909ee03f051492fe8958eb3f051492fe' +\n '8958ebbfe1c51774909ee03fd580eaf5b1d1e93f17eae8e380e7e23f17eae8e380e7e2bfd580eaf5b1d1e93f' +\n '148dcdb0db8ec33fc8b2ad55ce9fef3fc8b2ad55ce9fefbf148dcdb0db8ec33fbbcf468e8eaeef3fcf7becd4' +\n '1601c23fcf7becd41601c2bfbbcf468e8eaeef3f578e0c0d4038e33f220dd82ecf95e93f220dd82ecf95e9bf' +\n '578e0c0d4038e33fe90475d2388ceb3f1a22ae265648e03f1a22ae265648e0bfe90475d2388ceb3ff9eddf1a' +\n 'dcdccf3fec950b0c22feee3fec950b0c22feeebff9eddf1adcdccf3f25ce70e8ea31ee3f243caf80d830d53f' +\n '243caf80d830d5bf25ce70e8ea31ee3f01bd0423cfb7db3ff6328b89d9d7ec3ff6328b89d9d7ecbf01bd0423' +\n 'cfb7db3fb23dc36c83d7e73f375197381058e53f375197381058e5bfb23dc36c83d7e73fe3d7c0128d42ac3f' +\n '5c578d0f83f3ef3f5c578d0f83f3efbfe3d7c0128d42ac3f56f4f19f53ddef3f215b5d6a5887b73f215b5d6a' +\n '5887b7bf56f4f19f53ddef3f4773981bb573e43faad44d9a7e9ce83faad44d9a7e9ce8bf4773981bb573e43f' +\n '07692b014250ec3f58cc81148fd2dd3f58cc81148fd2ddbf07692b014250ec3f8703ecda22f4d23ff2f71d36' +\n '8490ee3ff2f71d368490eebf8703ecda22f4d23f8ea8e7e8b2adee3f71bbc3abbb33d23f71bbc3abbb33d2bf' +\n '8ea8e7e8b2adee3f1451f8eae083de3fb071a93fde20ec3fb071a93fde20ecbf1451f8eae083de3fcc981633' +\n '45dce83fb16b8e17ff25e43fb16b8e17ff25e4bfcc98163345dce83f035c4924b7a7ba3f840b221479d3ef3f' +\n '840b221479d3efbf035c4924b7a7ba3fb7bbf57d3f6cef3fc6649ce86633c83fc6649ce86633c8bfb7bbf57d' +\n '3f6cef3f1b86bc8bf0f0e13f9de69f52587fea3f9de69f52587feabf1b86bc8bf0f0e13fd4c0165932b7ea3f' +\n 'b8b9f2095a9de13fb8b9f2095a9de1bfd4c0165932b7ea3f6643dcf2cbbdc93f849e78b1a258ef3f849e78b1' +\n 'a258efbf6643dcf2cbbdc93f888966a983a3ed3fc4aa4eb0e320d83fc4aa4eb0e320d8bf888966a983a3ed3f' +\n 'b0a4c82ea5dad83ff9ecb8020b7ded3ff9ecb8020b7dedbfb0a4c82ea5dad83f7582c1730dc4e63f10af9184' +\n 'f77ce63f10af9184f77ce6bf7582c1730dc4e63f710067fef021793f928a8e85d8ffef3f928a8e85d8ffefbf' +\n '710067fef021793f021d6221f6ffef3fbaa4ccbef821693fbaa4ccbef82169bf021d6221f6ffef3f719ca1ea' +\n 'd18ee63f9ce22fed5cb2e63f9ce22fed5cb2e6bf719ca1ead18ee63f4fa44584c486ed3f44edd5864bacd83f' +\n '44edd5864bacd8bf4fa44584c486ed3f3f90f3aa6a4fd83f463d8bdd009aed3f463d8bdd009aedbf3f90f3aa' +\n '6a4fd83f5d6843eda65def3ffa2ab6e9495bc93ffa2ab6e9495bc9bf5d6843eda65def3fbf73131750b2e13f' +\n '8eb92c7a54a9ea3f8eb92c7a54a9eabfbf73131750b2e13fd25a546e678dea3f7248dc641bdce13f7248dc64' +\n '1bdce1bfd25a546e678dea3f0418c4271796c83fee3c88567567ef3fee3c88567567efbf0418c4271796c83f' +\n '9e5ca72d0dd6ef3f5ca824ebb6dfb93f5ca824ebb6dfb9bf9e5ca72d0dd6ef3f80432a5b7f39e43f55461875' +\n '6acce83f554618756acce8bf80432a5b7f39e43ff1e33149d12cec3f25d83c6da857de3f25d83c6da857debf' +\n 'f1e33149d12cec3fba545599e663d23f0058e69383a6ee3f0058e69383a6eebfba545599e663d23f306b0136' +\n 'ec97ee3f2045954e1ac4d23f2045954e1ac4d2bf306b0136ec97ee3fde41a966fffedd3f04c041318344ec3f' +\n '04c041318344ecbfde41a966fffedd3f881dde1e87ace83fa2322b695a60e43fa2322b695a60e4bf881dde1e' +\n '87ace83fa130c112874fb83f8c531475fadaef3f8c531475fadaefbfa130c112874fb83fd3beb154dcf4ef3f' +\n '17835fbd01b1aa3f17835fbd01b1aabfd3beb154dcf4ef3f9f649751c36ae53f33d3e29cb8c6e73f33d3e29c' +\n 'b8c6e7bf9f649751c36ae53f60a09927b3e2ec3f9356fd14788adb3f9356fd14788adbbf60a09927b3e2ec3f' +\n 'b467f4124060d53f7a1939448f29ee3f7a1939448f29eebfb467f4124060d53f8c73cf145a04ef3f0238bd80' +\n '747bcf3f0238bd80747bcfbf8c73cf145a04ef3fb7b831ecf35de03fe992e786667feb3fe992e786667febbf' +\n 'b7b831ecf35de03fb2062ba4dfa4e93f1fa649ec2124e33f1fa649ec2124e3bfb2062ba4dfa4e93f0934fd4d' +\n '9964c23fdcfd0ccbfbaaef3fdcfd0ccbfbaaefbf0934fd4d9964c23f91177aac9ba3ef3fa71645f97b2bc33f' +\n 'a71645f97b2bc3bf91177aac9ba3ef3f1510444bc2fbe23fc275f010d1c2e93fc275f010d1c2e9bf1510444b' +\n 'c2fbe23f47bcfd148f65eb3f8cb032201189e03f8cb032201189e0bf47bcfd148f65eb3f48e32d466bb8ce3f' +\n '5f8f89bc9010ef3f5f8f89bc9010efbf48e32d466bb8ce3fd966dc2fa018ee3fb6b39d8be7bed53fb6b39d8b' +\n 'e7bed5bfd966dc2fa018ee3f7219b31d972fdb3f7b46cee830f8ec3f7b46cee830f8ecbf7219b31d972fdb3f' +\n 'd297bf07f7a4e73fdf23f7d50190e53fdf23f7d50190e5bfd297bf07f7a4e73f864687a5ba8da73f64911bbb' +\n '53f7ef3f64911bbb53f7efbf864687a5ba8da73f79a6e29ce0fcef3f1d3be54c4f459c3f1d3be54c4f459cbf' +\n '79a6e29ce0fcef3f106ae5bd7cfee53f4299078e553ee73f4299078e553ee7bf106ae5bd7cfee53fdcfbcb7b' +\n 'fc36ed3fc00ab543651dda3fc00ab543651ddabfdcfbcb7bfc36ed3fb60c8a6398d9d63f818d6d0f16e4ed3f' +\n '818d6d0f16e4edbfb60c8a6398d9d63ff0ae3a5a6833ef3fdd745d53906dcc3fdd745d53906dccbff0ae3a5a' +\n '6833ef3f57a9d0487209e13ff5a24c2a7416eb3ff5a24c2a7416ebbf57a9d0487209e13f5ea7c0d2261bea3f' +\n 'ba3c4def8b81e23fba3c4def8b81e2bf5ea7c0d2261bea3fdecb5486007fc53f784bcb37a78bef3f784bcb37' +\n 'a78befbfdecb5486007fc53f888d0a0f47bfef3f5bb86fade80ec03f5bb86fade80ec0bf888d0a0f47bfef3f' +\n '2930d6e3239ce33f6c4aace39049e93f6c4aace39049e9bf2930d6e3239ce33f27230dcb54cbeb3fded2245c' +\n '57b7df3fded2245c57b7dfbf27230dcb54cbeb3fce49174e5be1d03f5186076aebddee3f5186076aebddeebf' +\n 'ce49174e5be1d03fd36704559d5aee3ff03689dc1043d43ff03689dc1043d4bfd36704559d5aee3f895386c3' +\n '7f99dc3f49c4b9198fa0ec3f49c4b9198fa0ecbf895386c37f99dc3fff45f5139c2ae83f86a4cc25ccf9e43f' +\n '86a4cc25ccf9e4bfff45f5139c2ae83f4d44ed74960cb23f0f4130259debef3f0f4130259debefbf4d44ed74' +\n '960cb23f602d4885eae7ef3f99a2c5129f9db33f99a2c5129f9db3bf602d4885eae7ef3f7f9f586dbcd3e43f' +\n 'fa83af11714be83ffa83af11714be8bf7f9f586dbcd3e43f139c0287f589ec3f21cde1ae4bf3dc3f21cde1ae' +\n '4bf3dcbf139c0287f589ec3f71c26ee99be3d33fa7535dc5616aee3fa7535dc5616aeebf71c26ee99be3d33f' +\n '0990995e83d0ee3f7893c6ef3e42d13f7893c6ef3e42d1bf0990995e83d0ee3fa3cd56e6de5fdf3fc1541161' +\n '1be4eb3fc15411611be4ebbfa3cd56e6de5fdf3f15a8c51fa42ae93f18c58149c4c3e33f18c58149c4c3e3bf' +\n '15a8c51fa42ae93f3faae4fdb78ebe3ff69a7d3b6ec5ef3ff69a7d3b6ec5efbf3faae4fdb78ebe3f0cc6404a' +\n '0f83ef3f0d831d831a45c63f0d831d831a45c6bf0cc6404a0f83ef3f1071bb4c7358e23fc63b594a1838ea3f' +\n 'c63b594a1838eabf1071bb4c7358e23fb6579fd88ffbea3f4f25eecfe933e13f4f25eecfe933e1bfb6579fd8' +\n '8ffbea3fad5df13463a9cb3f65bc1bbc6b3eef3f65bc1bbc6b3eefbfad5df13463a9cb3f5a918af3fed1ed3f' +\n '921026c96337d73f921026c96337d7bf5a918af3fed1ed3ff2f90d447dc1d93f2475181b5b4bed3f2475181b' +\n '5b4bedbff2f90d447dc1d93fbf410e96ac1be73fff22ec4fe422e63fff22ec4fe422e6bfbf410e96ac1be73f' +\n '26b2fa214dfd953f77cb70681cfeef3f77cb70681cfeefbf26b2fa214dfd953fd13bc54309ffef3fcb97b96a' +\n '296a8f3fcb97b96a296a8fbfd13bc54309ffef3f5b537f431547e63f755bc999caf8e63f755bc999caf8e6bf' +\n '5b537f431547e63f7f8a8872715fed3f8f94abb75565d93f8f94abb75565d9bf7f8a8872715fed3faedf13e6' +\n 'f594d73f9a7595439ebfed3f9a7595439ebfedbfaedf13e6f594d73fb4abbc062249ef3fabb9f3d5f1e4ca3f' +\n 'abb9f3d5f1e4cabfb4abbc062249ef3fbce2dbe4365ee13fefec45f368e0ea3fefec45f368e0eabfbce2dbe4' +\n '365ee13f23f59010c954ea3fe2132c662d2fe23fe2132c662d2fe2bf23f59010c954ea3fffc4088dfd0ac73f' +\n '2a321a9c297aef3f2a321a9c297aefbfffc4088dfd0ac73f5443910347cbef3fc17d303b53ffbc3fc17d303b' +\n '53ffbcbf5443910347cbef3f8006beea33ebe33ffe5e5743790be93ffe5e5743790be9bf8006beea33ebe33f' +\n '47b1a1259dfceb3ffef7bf061908df3ffef7bf061908dfbf47b1a1259dfceb3f43f2e8fbf7a2d13fb2f61a4b' +\n 'cfc2ee3fb2f61a4bcfc2eebf43f2e8fbf7a2d13f5a16a529db79ee3fabb653e3f583d33fabb653e3f583d3bf' +\n '5a16a529db79ee3f9d60a82bd04cdd3fd7aa9e891573ec3fd7aa9e891573ecbf9d60a82bd04cdd3f95a19a1d' +\n '0a6ce83ff122675179ade43ff122675179ade4bf95a19a1d0a6ce83f0a4d4d4a772eb53f86d8e92be9e3ef3f' +\n '86d8e92be9e3efbf0a4d4d4a772eb53f9161820201efef3f6430464e617bb03f6430464e617bb0bf91618202' +\n '01efef3fa69ad91ca81fe53ffa526e758b09e83ffa526e758b09e8bfa69ad91ca81fe53f99da000ae2b6ec3f' +\n '293126476d3fdc3f293126476d3fdcbf99da000ae2b6ec3ff3821bd153a2d43f5ece81ff8d4aee3f5ece81ff' +\n '8d4aeebff3821bd153a2d43f44a5504c07ebee3f1e66eb054e80d03f1e66eb054e80d0bf44a5504c07ebee3f' +\n 'e1822bc84007e03f0dc4b6a049b2eb3f0dc4b6a049b2ebbfe1822bc84007e03fe17fbd423f68e93f8d7f811b' +\n '5374e33f8d7f811b5374e3bfe17fbd423f68e93f8667b2bc4dd6c03fb7ad668dd1b8ef3fb7ad668dd1b8efbf' +\n '8667b2bc4dd6c03f08ac854ff193ef3f88fa797fb1b8c43f88fa797fb1b8c4bf08ac854ff193ef3f58eb7ae8' +\n '76aae23fde4931f1f4fde93fde4931f1f4fde9bf58eb7ae876aae23ff37bf3a51531eb3fb6c44bb8d0dee03f' +\n 'b6c44bb8d0dee0bff37bf3a51531eb3feebd2c4d7731cd3fce0946fc1728ef3fce0946fc1728efbfeebd2c4d' +\n '7731cd3f9ca59b6ae3f5ed3fcb63ad9c947bd63fcb63ad9c947bd6bf9ca59b6ae3f5ed3f1bf3dbd30c79da3f' +\n 'e1a4e5c65522ed3fe1a4e5c65522edbf1bf3dbd30c79da3f6447302cc560e73f5c343ee7ded9e53f5c343ee7' +\n 'ded9e5bf6447302cc560e73f7fc142db8546a13faefd25e455fbef3faefd25e455fbefbf7fc142db8546a13f' +\n '14c008427cf9ef3f7961f86f396aa43f7961f86f396aa4bf14c008427cf9ef3f48744f260bb5e53f5bb3901b' +\n 'fb82e73f5bb3901bfb82e7bf48744f260bb5e53fb9d2592f670ded3f09dc5c1273d4da3f09dc5c1273d4dabf' +\n 'b9d2592f670ded3f02c2885c591dd63f540f28d96607ee3f540f28d96607eebf02c2885c591dd63f084728be' +\n '7a1cef3f9a09013f16f5cd3f9a09013f16f5cdbf084728be7a1cef3fec858f8705b4e03f2579de09744beb3f' +\n '2579de09744bebbfec858f8705b4e03f7224b4ed82e0e93fb89b4ed333d3e23fb89b4ed333d3e2bf7224b4ed' +\n '82e0e93f9348db572ff2c33f29defb7ced9bef3f29defb7ced9befbf9348db572ff2c33f4dd581c60db2ef3f' +\n 'e724be40899dc13fe724be40899dc1bf4dd581c60db2ef3fe14dc152524ce33f947545f1ae86e93f947545f1' +\n 'ae86e9bfe14dc152524ce33f5e15d91ffa98eb3f96bded55ae32e03f96bded55ae32e0bf5e15d91ffa98eb3f' +\n 'd2fdb906181fd03fc0a31ce5d6f7ee3fc0a31ce5d6f7eebfd2fdb906181fd03f85ce75ec333aee3f487019dc' +\n '6301d53f487019dc6301d5bf85ce75ec333aee3fd9c0ff1715e5db3fa0dec220eeccec3fa0dec220eeccecbf' +\n 'd9c0ff1715e5db3f8636b0873fe8e73ffc9d15f54f45e53ffc9d15f54f45e5bf8636b0873fe8e73fc98e80f9' +\n '06d4ad3fed31e11416f2ef3fed31e11416f2efbfc98e80f906d4ad3f0733f72299dfef3f29b1793e1bbfb63f' +\n '29b1793e1bbfb6bf0733f72299dfef3fff9160300387e43fa11b48e7668ce83fa11b48e7668ce8bfff916030' +\n '0387e43f5af8fe59ef5bec3fd910fa5c0ca6dd3fd910fa5c0ca6ddbf5af8fe59ef5bec3fafba38b61f24d33f' +\n '2560ad5b0989ee3f2560ad5b0989eebfafba38b61f24d33f11885b51cfb4ee3fbe27d7838503d23fbe27d783' +\n '8503d2bf11885b51cfb4ee3f2056f29506b0de3f575e46dcd914ec3f575e46dcd914ecbf2056f29506b0de3f' +\n '496c489b10ece83f8c103d667212e43f8c103d667212e4bf496c489b10ece83f4cf638eca66fbb3f8760d858' +\n 'd1d0ef3f8760d858d1d0efbf4cf638eca66fbb3fb77e4b43f670ef3f1ccbd2bba7d0c73f1ccbd2bba7d0c7bf' +\n 'b77e4b43f670ef3fd66075a1ba05e23ff5609dde3871ea3ff5609dde3871eabfd66075a1ba05e23fc8fa3ebd' +\n 'ffc4ea3fe5463a1f5988e13fe5463a1f5988e1bfc8fa3ebdffc4ea3fda31181b3e20ca3f072daf1f8b53ef3f' +\n '072daf1f8b53efbfda31181b3e20ca3fb98ae62cf4aced3fe44173d34df2d73fe44173d34df2d7bfb98ae62c' +\n 'f4aced3fd17bef81ef08d93fff0d8c503f73ed3fff0d8c503f73edbfd17bef81ef08d93fcdaf4aefafd5e63f' +\n '86b3523f0f6be63f86b3523f0f6be6bfcdaf4aefafd5e63f0397500e6bd9823f4f8c972ca7ffef3f4f8c972c' +\n 'a7ffefbf0397500e6bd9823f4f8c972ca7ffef3f0397500e6bd9823f0397500e6bd982bf4f8c972ca7ffef3f' +\n '86b3523f0f6be63fcdaf4aefafd5e63fcdaf4aefafd5e6bf86b3523f0f6be63fff0d8c503f73ed3fd17bef81' +\n 'ef08d93fd17bef81ef08d9bfff0d8c503f73ed3fe44173d34df2d73fb98ae62cf4aced3fb98ae62cf4acedbf' +\n 'e44173d34df2d73f072daf1f8b53ef3fda31181b3e20ca3fda31181b3e20cabf072daf1f8b53ef3fe5463a1f' +\n '5988e13fc8fa3ebdffc4ea3fc8fa3ebdffc4eabfe5463a1f5988e13ff5609dde3871ea3fd66075a1ba05e23f' +\n 'd66075a1ba05e2bff5609dde3871ea3f1ccbd2bba7d0c73fb77e4b43f670ef3fb77e4b43f670efbf1ccbd2bb' +\n 'a7d0c73f8760d858d1d0ef3f4cf638eca66fbb3f4cf638eca66fbbbf8760d858d1d0ef3f8c103d667212e43f' +\n '496c489b10ece83f496c489b10ece8bf8c103d667212e43f575e46dcd914ec3f2056f29506b0de3f2056f295' +\n '06b0debf575e46dcd914ec3fbe27d7838503d23f11885b51cfb4ee3f11885b51cfb4eebfbe27d7838503d23f' +\n '2560ad5b0989ee3fafba38b61f24d33fafba38b61f24d3bf2560ad5b0989ee3fd910fa5c0ca6dd3f5af8fe59' +\n 'ef5bec3f5af8fe59ef5becbfd910fa5c0ca6dd3fa11b48e7668ce83fff9160300387e43fff9160300387e4bf' +\n 'a11b48e7668ce83f29b1793e1bbfb63f0733f72299dfef3f0733f72299dfefbf29b1793e1bbfb63fed31e114' +\n '16f2ef3fc98e80f906d4ad3fc98e80f906d4adbfed31e11416f2ef3ffc9d15f54f45e53f8636b0873fe8e73f' +\n '8636b0873fe8e7bffc9d15f54f45e53fa0dec220eeccec3fd9c0ff1715e5db3fd9c0ff1715e5dbbfa0dec220' +\n 'eeccec3f487019dc6301d53f85ce75ec333aee3f85ce75ec333aeebf487019dc6301d53fc0a31ce5d6f7ee3f' +\n 'd2fdb906181fd03fd2fdb906181fd0bfc0a31ce5d6f7ee3f96bded55ae32e03f5e15d91ffa98eb3f5e15d91f' +\n 'fa98ebbf96bded55ae32e03f947545f1ae86e93fe14dc152524ce33fe14dc152524ce3bf947545f1ae86e93f' +\n 'e724be40899dc13f4dd581c60db2ef3f4dd581c60db2efbfe724be40899dc13f29defb7ced9bef3f9348db57' +\n '2ff2c33f9348db572ff2c3bf29defb7ced9bef3fb89b4ed333d3e23f7224b4ed82e0e93f7224b4ed82e0e9bf' +\n 'b89b4ed333d3e23f2579de09744beb3fec858f8705b4e03fec858f8705b4e0bf2579de09744beb3f9a09013f' +\n '16f5cd3f084728be7a1cef3f084728be7a1cefbf9a09013f16f5cd3f540f28d96607ee3f02c2885c591dd63f' +\n '02c2885c591dd6bf540f28d96607ee3f09dc5c1273d4da3fb9d2592f670ded3fb9d2592f670dedbf09dc5c12' +\n '73d4da3f5bb3901bfb82e73f48744f260bb5e53f48744f260bb5e5bf5bb3901bfb82e73f7961f86f396aa43f' +\n '14c008427cf9ef3f14c008427cf9efbf7961f86f396aa43faefd25e455fbef3f7fc142db8546a13f7fc142db' +\n '8546a1bfaefd25e455fbef3f5c343ee7ded9e53f6447302cc560e73f6447302cc560e7bf5c343ee7ded9e53f' +\n 'e1a4e5c65522ed3f1bf3dbd30c79da3f1bf3dbd30c79dabfe1a4e5c65522ed3fcb63ad9c947bd63f9ca59b6a' +\n 'e3f5ed3f9ca59b6ae3f5edbfcb63ad9c947bd63fce0946fc1728ef3feebd2c4d7731cd3feebd2c4d7731cdbf' +\n 'ce0946fc1728ef3fb6c44bb8d0dee03ff37bf3a51531eb3ff37bf3a51531ebbfb6c44bb8d0dee03fde4931f1' +\n 'f4fde93f58eb7ae876aae23f58eb7ae876aae2bfde4931f1f4fde93f88fa797fb1b8c43f08ac854ff193ef3f' +\n '08ac854ff193efbf88fa797fb1b8c43fb7ad668dd1b8ef3f8667b2bc4dd6c03f8667b2bc4dd6c0bfb7ad668d' +\n 'd1b8ef3f8d7f811b5374e33fe17fbd423f68e93fe17fbd423f68e9bf8d7f811b5374e33f0dc4b6a049b2eb3f' +\n 'e1822bc84007e03fe1822bc84007e0bf0dc4b6a049b2eb3f1e66eb054e80d03f44a5504c07ebee3f44a5504c' +\n '07ebeebf1e66eb054e80d03f5ece81ff8d4aee3ff3821bd153a2d43ff3821bd153a2d4bf5ece81ff8d4aee3f' +\n '293126476d3fdc3f99da000ae2b6ec3f99da000ae2b6ecbf293126476d3fdc3ffa526e758b09e83fa69ad91c' +\n 'a81fe53fa69ad91ca81fe5bffa526e758b09e83f6430464e617bb03f9161820201efef3f9161820201efefbf' +\n '6430464e617bb03f86d8e92be9e3ef3f0a4d4d4a772eb53f0a4d4d4a772eb5bf86d8e92be9e3ef3ff1226751' +\n '79ade43f95a19a1d0a6ce83f95a19a1d0a6ce8bff122675179ade43fd7aa9e891573ec3f9d60a82bd04cdd3f' +\n '9d60a82bd04cddbfd7aa9e891573ec3fabb653e3f583d33f5a16a529db79ee3f5a16a529db79eebfabb653e3' +\n 'f583d33fb2f61a4bcfc2ee3f43f2e8fbf7a2d13f43f2e8fbf7a2d1bfb2f61a4bcfc2ee3ffef7bf061908df3f' +\n '47b1a1259dfceb3f47b1a1259dfcebbffef7bf061908df3ffe5e5743790be93f8006beea33ebe33f8006beea' +\n '33ebe3bffe5e5743790be93fc17d303b53ffbc3f5443910347cbef3f5443910347cbefbfc17d303b53ffbc3f' +\n '2a321a9c297aef3fffc4088dfd0ac73fffc4088dfd0ac7bf2a321a9c297aef3fe2132c662d2fe23f23f59010' +\n 'c954ea3f23f59010c954eabfe2132c662d2fe23fefec45f368e0ea3fbce2dbe4365ee13fbce2dbe4365ee1bf' +\n 'efec45f368e0ea3fabb9f3d5f1e4ca3fb4abbc062249ef3fb4abbc062249efbfabb9f3d5f1e4ca3f9a759543' +\n '9ebfed3faedf13e6f594d73faedf13e6f594d7bf9a7595439ebfed3f8f94abb75565d93f7f8a8872715fed3f' +\n '7f8a8872715fedbf8f94abb75565d93f755bc999caf8e63f5b537f431547e63f5b537f431547e6bf755bc999' +\n 'caf8e63fcb97b96a296a8f3fd13bc54309ffef3fd13bc54309ffefbfcb97b96a296a8f3f77cb70681cfeef3f' +\n '26b2fa214dfd953f26b2fa214dfd95bf77cb70681cfeef3fff22ec4fe422e63fbf410e96ac1be73fbf410e96' +\n 'ac1be7bfff22ec4fe422e63f2475181b5b4bed3ff2f90d447dc1d93ff2f90d447dc1d9bf2475181b5b4bed3f' +\n '921026c96337d73f5a918af3fed1ed3f5a918af3fed1edbf921026c96337d73f65bc1bbc6b3eef3fad5df134' +\n '63a9cb3fad5df13463a9cbbf65bc1bbc6b3eef3f4f25eecfe933e13fb6579fd88ffbea3fb6579fd88ffbeabf' +\n '4f25eecfe933e13fc63b594a1838ea3f1071bb4c7358e23f1071bb4c7358e2bfc63b594a1838ea3f0d831d83' +\n '1a45c63f0cc6404a0f83ef3f0cc6404a0f83efbf0d831d831a45c63ff69a7d3b6ec5ef3f3faae4fdb78ebe3f' +\n '3faae4fdb78ebebff69a7d3b6ec5ef3f18c58149c4c3e33f15a8c51fa42ae93f15a8c51fa42ae9bf18c58149' +\n 'c4c3e33fc15411611be4eb3fa3cd56e6de5fdf3fa3cd56e6de5fdfbfc15411611be4eb3f7893c6ef3e42d13f' +\n '0990995e83d0ee3f0990995e83d0eebf7893c6ef3e42d13fa7535dc5616aee3f71c26ee99be3d33f71c26ee9' +\n '9be3d3bfa7535dc5616aee3f21cde1ae4bf3dc3f139c0287f589ec3f139c0287f589ecbf21cde1ae4bf3dc3f' +\n 'fa83af11714be83f7f9f586dbcd3e43f7f9f586dbcd3e4bffa83af11714be83f99a2c5129f9db33f602d4885' +\n 'eae7ef3f602d4885eae7efbf99a2c5129f9db33f0f4130259debef3f4d44ed74960cb23f4d44ed74960cb2bf' +\n '0f4130259debef3f86a4cc25ccf9e43fff45f5139c2ae83fff45f5139c2ae8bf86a4cc25ccf9e43f49c4b919' +\n '8fa0ec3f895386c37f99dc3f895386c37f99dcbf49c4b9198fa0ec3ff03689dc1043d43fd36704559d5aee3f' +\n 'd36704559d5aeebff03689dc1043d43f5186076aebddee3fce49174e5be1d03fce49174e5be1d0bf5186076a' +\n 'ebddee3fded2245c57b7df3f27230dcb54cbeb3f27230dcb54cbebbfded2245c57b7df3f6c4aace39049e93f' +\n '2930d6e3239ce33f2930d6e3239ce3bf6c4aace39049e93f5bb86fade80ec03f888d0a0f47bfef3f888d0a0f' +\n '47bfefbf5bb86fade80ec03f784bcb37a78bef3fdecb5486007fc53fdecb5486007fc5bf784bcb37a78bef3f' +\n 'ba3c4def8b81e23f5ea7c0d2261bea3f5ea7c0d2261beabfba3c4def8b81e23ff5a24c2a7416eb3f57a9d048' +\n '7209e13f57a9d0487209e1bff5a24c2a7416eb3fdd745d53906dcc3ff0ae3a5a6833ef3ff0ae3a5a6833efbf' +\n 'dd745d53906dcc3f818d6d0f16e4ed3fb60c8a6398d9d63fb60c8a6398d9d6bf818d6d0f16e4ed3fc00ab543' +\n '651dda3fdcfbcb7bfc36ed3fdcfbcb7bfc36edbfc00ab543651dda3f4299078e553ee73f106ae5bd7cfee53f' +\n '106ae5bd7cfee5bf4299078e553ee73f1d3be54c4f459c3f79a6e29ce0fcef3f79a6e29ce0fcefbf1d3be54c' +\n '4f459c3f64911bbb53f7ef3f864687a5ba8da73f864687a5ba8da7bf64911bbb53f7ef3fdf23f7d50190e53f' +\n 'd297bf07f7a4e73fd297bf07f7a4e7bfdf23f7d50190e53f7b46cee830f8ec3f7219b31d972fdb3f7219b31d' +\n '972fdbbf7b46cee830f8ec3fb6b39d8be7bed53fd966dc2fa018ee3fd966dc2fa018eebfb6b39d8be7bed53f' +\n '5f8f89bc9010ef3f48e32d466bb8ce3f48e32d466bb8cebf5f8f89bc9010ef3f8cb032201189e03f47bcfd14' +\n '8f65eb3f47bcfd148f65ebbf8cb032201189e03fc275f010d1c2e93f1510444bc2fbe23f1510444bc2fbe2bf' +\n 'c275f010d1c2e93fa71645f97b2bc33f91177aac9ba3ef3f91177aac9ba3efbfa71645f97b2bc33fdcfd0ccb' +\n 'fbaaef3f0934fd4d9964c23f0934fd4d9964c2bfdcfd0ccbfbaaef3f1fa649ec2124e33fb2062ba4dfa4e93f' +\n 'b2062ba4dfa4e9bf1fa649ec2124e33fe992e786667feb3fb7b831ecf35de03fb7b831ecf35de0bfe992e786' +\n '667feb3f0238bd80747bcf3f8c73cf145a04ef3f8c73cf145a04efbf0238bd80747bcf3f7a1939448f29ee3f' +\n 'b467f4124060d53fb467f4124060d5bf7a1939448f29ee3f9356fd14788adb3f60a09927b3e2ec3f60a09927' +\n 'b3e2ecbf9356fd14788adb3f33d3e29cb8c6e73f9f649751c36ae53f9f649751c36ae5bf33d3e29cb8c6e73f' +\n '17835fbd01b1aa3fd3beb154dcf4ef3fd3beb154dcf4efbf17835fbd01b1aa3f8c531475fadaef3fa130c112' +\n '874fb83fa130c112874fb8bf8c531475fadaef3fa2322b695a60e43f881dde1e87ace83f881dde1e87ace8bf' +\n 'a2322b695a60e43f04c041318344ec3fde41a966fffedd3fde41a966fffeddbf04c041318344ec3f2045954e' +\n '1ac4d23f306b0136ec97ee3f306b0136ec97eebf2045954e1ac4d23f0058e69383a6ee3fba545599e663d23f' +\n 'ba545599e663d2bf0058e69383a6ee3f25d83c6da857de3ff1e33149d12cec3ff1e33149d12cecbf25d83c6d' +\n 'a857de3f554618756acce83f80432a5b7f39e43f80432a5b7f39e4bf554618756acce83f5ca824ebb6dfb93f' +\n '9e5ca72d0dd6ef3f9e5ca72d0dd6efbf5ca824ebb6dfb93fee3c88567567ef3f0418c4271796c83f0418c427' +\n '1796c8bfee3c88567567ef3f7248dc641bdce13fd25a546e678dea3fd25a546e678deabf7248dc641bdce13f' +\n '8eb92c7a54a9ea3fbf73131750b2e13fbf73131750b2e1bf8eb92c7a54a9ea3ffa2ab6e9495bc93f5d6843ed' +\n 'a65def3f5d6843eda65defbffa2ab6e9495bc93f463d8bdd009aed3f3f90f3aa6a4fd83f3f90f3aa6a4fd8bf' +\n '463d8bdd009aed3f44edd5864bacd83f4fa44584c486ed3f4fa44584c486edbf44edd5864bacd83f9ce22fed' +\n '5cb2e63f719ca1ead18ee63f719ca1ead18ee6bf9ce22fed5cb2e63fbaa4ccbef821693f021d6221f6ffef3f' +\n '021d6221f6ffefbfbaa4ccbef821693f'\n )\n );\n\n // Sanity check (shake256 because used already): catch byte-level corruption, endianness/layout\n // mistakes, or accidental regeneration through engine-dependent sin/cos results.\n const rootBytes = u8f(baswap64If(Float64Array.from(roots)));\n if (\n bytesToHex(shake256(rootBytes)) !==\n 'f45a496cf56ccc6e3e3395a20209206d81d71a7905a661447bd5bc0e24e0af1e'\n ) {\n throw new Error('COMPLEX_ROOTS mismatch');\n }\n return roots;\n})();\n\n// Falcon's q-field Montgomery kernel: mul() operates on Montgomery residues and returns one.\n// inv() accepts a normal residue but returns its inverse in Montgomery form, so div(x, y) can stay\n// `mul(x, inv(y))`; callers like toMontgomery() manage the representation boundaries.\nconst intField = {\n mul(x: number, y: number) {\n let z = Math.imul(x, y);\n let w = Math.imul(Q, Math.imul(z, Q0I) & 0xffff);\n z = ((z + w) >>> 16) - Q;\n z += Q & (z >> 31);\n return z >>> 0;\n },\n inv(y: number): number {\n // y^(q-2) mod q\n if (y === 0) throw new Error('divison by zero');\n const e00 = this.mul(y, R2); // e0 = 1\n const e01 = this.mul(e00, e00); // 2 * e0 = 2\n const e02 = this.mul(e01, e00); // e1 + e0 = 3\n const e03 = this.mul(e02, e01); // e3 = e2 + e1 = 5\n const e04 = this.mul(e03, e03); // e4 = 2 * e3 = 10\n const e05 = this.mul(e04, e04); // e5 = 2 * e4 = 20\n const e06 = this.mul(e05, e05); // e6 = 2 * e5 = 40\n const e07 = this.mul(e06, e06); // e7 = 2 * e6 = 80\n const e08 = this.mul(e07, e07); // e8 = 2 * e7 = 160\n const e09 = this.mul(e08, e02); // e9 = e8 + e2 = 163\n const e10 = this.mul(e09, e08); // e10 = e9 + e8 = 323\n const e11 = this.mul(e10, e10); // e11 = 2 * e10 = 646\n const e12 = this.mul(e11, e11); // e12 = 2 * e11 = 1292\n const e13 = this.mul(e12, e09); // e13 = e12 + e9 = 1455\n const e14 = this.mul(e13, e13); // e14 = 2 * e13 = 2910\n const e15 = this.mul(e14, e14); // e15 = 2 * e14 = 5820\n const e16 = this.mul(e15, e10); // e16 = e15 + e10 = 6143\n const e17 = this.mul(e16, e16); // e17 = 2 * e16 = 12286\n const e18 = this.mul(e17, e00); // e18 = e17 + e0 = 12287\n return e18;\n },\n div: (x: number, y: number): number => intField.mul(x, intField.inv(y)),\n};\n\nfunction getIntPoly(logn: number) {\n const n = 1 << logn;\n const newPoly = (n: number) => new Uint16Array(n);\n const F = Number(invert(BigInt(n), QBig));\n const { mod, smod, NTT } = genCrystals({\n N: n,\n Q,\n F: F,\n ROOT_OF_UNITY: 7,\n newPoly,\n isKyber: false,\n brvBits: 10,\n });\n // Keep Falcon source compatible with older TS parsers: avoid spelling newer\n // `Uint16Array<ArrayBuffer>` syntax directly and cast the callee side at the boundary.\n const ntt = (r: TArg<IPoly>): TRet<IPoly> => (NTT.encode as any)(r);\n const intt = (r: TArg<IPoly>): TRet<IPoly> => (NTT.decode as any)(r);\n // Falcon integer helpers mutate their first argument in place; div() also performs intt()\n // before returning, so callers must treat these as owned-temporary transforms, not pure helpers.\n // Centered representatives are in [-6144, 6144] for odd q = 12289,\n // not a generic [-q/2, q/2] range.\n const signedCoder = {\n encode: (p: TArg<IPoly>) => Int16Array.from(p, (x) => smod(x)),\n decode: (p: TArg<SPoly | Int16Array>) => Uint16Array.from(p, (x) => mod(x)),\n };\n const intPoly = {\n create: newPoly,\n smallSqnorm(f: TArg<SPoly>) {\n let s = 0;\n let ng = 0;\n for (let u = 0; u < n; u++) {\n const z = f[u];\n s = (s + z * z) >>> 0;\n ng |= s;\n }\n return (s | -(ng >>> 31)) >>> 0;\n },\n isShort(s1: TArg<Int16Array>, s2: TArg<Int16Array>) {\n let s = 0 >>> 0;\n let ng = 0 >>> 0;\n for (let u = 0; u < n; u++) {\n let z1 = (s1[u] << 16) >> 16;\n s = (s + ((z1 * z1) >>> 0)) >>> 0;\n ng |= s;\n let z2 = (s2[u] << 16) >> 16;\n s = (s + ((z2 * z2) >>> 0)) >>> 0;\n ng |= s;\n }\n if (ng & 0x80000000) s = 0xffffffff;\n return s <= L2BOUND[logn];\n },\n sub(a: TArg<IPoly>, b: TArg<IPoly>): TRet<IPoly> {\n for (let i = 0; i < n; i++) a[i] = mod(a[i] - b[i]);\n return a as TRet<IPoly>;\n },\n ntt,\n intt,\n toMontgomery(d: TArg<IPoly>): TRet<IPoly> {\n for (let i = 0; i < n; i++) d[i] = intField.mul(d[i], R2);\n return d as TRet<IPoly>;\n },\n mul(f: TArg<IPoly>, d: TArg<IPoly>): TRet<IPoly> {\n for (let i = 0; i < n; i++) f[i] = intField.mul(f[i], d[i]);\n return f as TRet<IPoly>;\n },\n div(f: TArg<IPoly>, d: TArg<IPoly>): TRet<IPoly> {\n for (let i = 0; i < n; i++) f[i] = intField.div(f[i], d[i]);\n this.intt(f);\n return f as TRet<IPoly>;\n },\n };\n return { newPoly, intPoly, signedCoder };\n}\n\n// Falcon's JS binary64 complex field wrapper for FFT/sampler paths. Current uses are the\n// ordinary finite-number operations add/sub/neg/mul/conj/scale/magSqSum; the inherited wider API\n// exists because getComplex() exposes it, not because all methods are relied on by Falcon today.\nconst fComplex = getComplex({\n ZERO: 0,\n ONE: 1,\n add: (x: number, y: number) => x + y,\n sub: (x: number, y: number) => x - y,\n mul: (x: number, y: number) => x * y,\n div: (x: number, y: number) => x / y,\n eql: (x: number, y: number) => x === y,\n inv: (x: number) => 1 / x,\n neg: (x: number) => -x,\n} as any as IField<number>);\n\n// Detached object copy of the exact round-3 / PQClean fpr_gm_tab payload in its original order.\nconst COMPLEX_ROOTS_O = ComplexArrInterleaved.decode(COMPLEX_ROOTS);\n// Re-map roots into the local forward FFTCore schedule\n// `{ dit: false, invertButterflies: true, brp: false }`.\n// Index 0 stays intentionally unused because FFTCore's forward group counter starts at 1.\nconst FFTCoreRoots: Record<number, ComplexElm<number>[]> = {};\n// Inverse FFTCore reads roots as `N - grp`, so fill this table from the end and store `-conj(root)`\n// rather than plain conjugates\n// to match Falcon's split/iFFT sign convention under the local butterfly.\nconst FFTCoreRootsConj: Record<number, ComplexElm<number>[]> = {};\nfor (let logn = 0; logn < 10; logn++) {\n const out = new Array(1 << logn);\n const outC = new Array(1 << logn);\n for (let i = 0, g1 = 1, g2 = 1; i < logn; i++) {\n const ng = 1 << i;\n for (let k = 0; k < ng; k++) out[g1++] = COMPLEX_ROOTS_O[(ng << 1) + k];\n const ng2 = 1 << (logn - i);\n for (let k = 0; k < ng2 >> 1; k++)\n outC[out.length - g2++] = fComplex.neg(fComplex.conj(COMPLEX_ROOTS_O[ng2 + k]));\n }\n FFTCoreRoots[logn] = out;\n FFTCoreRootsConj[logn] = outC;\n}\n\ntype CPoly = ComplexElm<number>[];\n// Mixed float-poly helper surface: most methods allocate / return fresh values,\n// but FFT() and iFFT() mutate their CPoly input in place.\n// Flat Float64Array buffers use ComplexArr's [...re, ...im] layout.\nfunction getFloatPoly(logn: number) {\n const n = 1 << logn;\n const N_COMPLEX = n >> 1;\n const hn = Math.log2(N_COMPLEX);\n const fftOpts = { N: N_COMPLEX, invertButterflies: true, skipStages: 0, brp: false };\n const inv = 1.0 / N_COMPLEX;\n return {\n to: (f: TArg<FPoly>) => ComplexArr.decode(Array.from(f)),\n from: (f: CPoly): TRet<FPoly> => new Float64Array(ComplexArr.encode(f)) as TRet<FPoly>,\n // Runtime callers also pass HashToPoint's Uint16Array output here;\n // the implementation only needs a numeric typed-array shape,\n // even though the local type is narrower.\n convSmall: (f: TArg<SPoly>): CPoly => ComplexArr.decode(Array.from(f)),\n add: (a: CPoly, b: CPoly): CPoly => a.map((i, j) => fComplex.add(i, b[j])),\n sub: (a: CPoly, b: CPoly): CPoly => a.map((i, j) => fComplex.sub(i, b[j])),\n neg: (a: CPoly): CPoly => a.map((i) => fComplex.neg(i)),\n mul: (a: CPoly, b: CPoly): CPoly => a.map((i, j) => fComplex.mul(i, b[j])),\n conj: (a: CPoly): CPoly => a.map((i) => fComplex.conj(i)),\n mulConst: (a: CPoly, x: number): CPoly => a.map((i) => fComplex.scale(i, x)),\n scaleNorm: (a: CPoly, b: TArg<FPoly>): CPoly => a.map((i, j) => fComplex.scale(i, b[j])),\n invNorm: (a: CPoly, b: CPoly) =>\n new Float64Array(a.map((i, j) => 1.0 / fComplex.magSqSum(i, b[j]))),\n FFT: (f: CPoly): CPoly =>\n FFTCore(fComplex, { ...fftOpts, dit: false, roots: FFTCoreRoots[hn] })(f),\n iFFT(f: CPoly): CPoly {\n FFTCore(fComplex, { ...fftOpts, dit: true, roots: FFTCoreRootsConj[hn] })(f);\n for (let i = 0; i < f.length; i++) f[i] = fComplex.scale(f[i], inv);\n return f;\n },\n };\n}\n\nfunction ldlFFT(logn: number, g00t: CPoly, g01t: CPoly, g11t: CPoly) {\n // Algorithm 8: LDL*(G)\n // (Page 37)\n // Require: A full-rank self-adjoint matrix G = (Gᵢⱼ) ∈ FFT(Q[x]/(φ))²ˣ²\n // Ensure: The LDL* decomposition G = LDL* over FFT(Q[x]/(φ))\n // Format: All polynomials are in FFT representation.\n // 1: D₀₀ ← G₀₀\n // 2: L₁₀ ← G₁₀/G₀₀\n // 3: D₁₁ ← G₁₁ - L₁₀ ⊙ L₁₀* ⊙ G₀₀\n // 4: L ← [ 1 0 ; L₁₀ 1 ], D ← [ D₀₀ 0 ; 0 D₁₁ ]\n // 5: return (L, D)\n\n // Algorithm 9: ffLDL*(G)\n // (Page 37)\n // Require: A full-rank Gram matrix G ∈ FFT(Q[x]/(xⁿ + 1))²ˣ²\n // Ensure: A binary tree T\n // Format: All polynomials are in FFT representation.\n // 1: (L, D) ← LDL*(G) ▷ L = [ 1 0 ; L₁₀ 1 ], D = [ D₀₀ 0 ; 0 D₁₁ ]\n // 2: T.value ← L₁₀\n // 3: if (n = 2) then\n // 4: T.leftchild ← D₀₀\n // 5: T.rightchild ← D₁₁\n // 6: return T\n // 7: else\n // 8: d₀₀, d₀₁ ← splitfft(D₀₀) ▷ dᵢⱼ ∈ FFT(Q[x]/(x^{n/2} + 1))\n // 9: d₁₀, d₁₁ ← splitfft(D₁₁)\n // 10: G₀ ← [ d₀₀ d₀₁ ; d₀₁* d₀₀ ], G₁ ← [ d₁₀ d₁₁ ; d₁₁* d₁₀ ]\n // ▷ Since D₀₀, D₁₁ are self-adjoint, (3.30) applies\n // 11: T.leftchild ← ffLDL*(G₀) ▷ Recursive calls\n // 12: T.rightchild ← ffLDL*(G₁)\n // 13: return T\n\n // Recursive calls may alias g00t and g11t, and the top-level arrays persist across signing\n // retries. LDL replaces array entries, so shallow copies keep both kinds of caller state intact.\n g00t = g00t.slice();\n g01t = g01t.slice();\n g11t = g11t.slice();\n const hn = 1 << (logn - 1);\n for (let i = 0; i < hn; i++) {\n const g01 = g01t[i];\n const g11 = g11t[i];\n const mu = fComplex.scale(g01, 1.0 / g00t[i].re);\n g11t[i] = { re: g11.re - (mu.re * g01.re + mu.im * g01.im), im: g11.im };\n g01t[i] = fComplex.conj(mu);\n }\n return { g00: g00t, g01: g01t, g11: g11t };\n}\n\nfunction ApproxExp(x: number, ccs: number): number {\n // Algorithm 13: ApproxExp(x, ccs), (Page 42)\n // Require: Floating-point values x ∈ [0, ln(2)] and ccs ∈ [0, 1]\n // Ensure: A floating approximation of ccs · exp(-x); berExp() applies the later 2^63 scaling.\n // 1: C = [0x00000004741183A3, ...]\n // 2: y ← C[0] ▷ y and z remain in {0, ..., 2⁶³ - 1} the whole algorithm.\n // 3: z ← ⌊2⁶³ · x⌋\n // 4: for i = 1, ..., 12 do\n // 5: y ← C[i] - (z · y) >> 63 ▷ (z · y) fits in 126 bits, but we only need the top 63 bits\n // 6: z ← ⌊2⁶³ · ccs⌋\n // 7: y ← (z · y) >> 63\n // 8: return y\n // FACCT / round-3 Falcon's leading 1.0 coefficient is implicit in `return ccs * (1.0 + z * y)`,\n // so the decimal list below stores the remaining 12 polynomial coefficients only.\n const ev = [\n 0.99999999999999489297408672428, 0.500000000000019206858326015208,\n 0.166666666666984014666397229121, 0.041666666666110491190622155955,\n 0.008333333327800835146903501993, 0.001388888894063186997887560103,\n 0.000198412739277311890541063977, 0.000024801566833585381209939524,\n 0.000002755586350219122514855659, 0.000000275607356160477811864927,\n 0.000000025299506379442070029551, 0.000000002073772366009083061987,\n ];\n const y = -x;\n let z = ev[ev.length - 1];\n for (let i = ev.length - 2; i >= 0; i--) z = z * y + ev[i];\n return ccs * (1.0 + z * y);\n}\n\n// Actual api\ntype FalconOpts = {\n N: number;\n // Table 3.3 total padded detached bytes. In padded mode it drives `.lengths.signature` and the\n // payload width `sigLen - 1 - NONCELEN`.\n sigLen: number;\n padded: boolean;\n fgBits: number;\n FGBits: number;\n // Compressed-s payload bytes only, excluding the detached header byte and 40-byte nonce.\n paddedLen: number;\n // Maximum compressed-s payload emitted by sign(). Unpadded detached verification enforces the\n // same Round-3 ceiling before decoding.\n maxS2Len: number;\n};\n\ntype FalconRandom = (bytesLength?: number) => TRet<Uint8Array>;\ntype FalconSigOpts = SigOpts & { random?: FalconRandom };\n/** Falcon attached-signature API. */\nexport type FalconAttached = CryptoKeys & {\n /** Key lengths plus the 48-byte sampler-seed hook for signing. */\n lengths: CryptoKeys['lengths'] & { signRand?: number };\n /**\n * Signs a message and appends it to the returned attached signature.\n * @param msg Message bytes to sign.\n * @param secretKey Falcon secret key bytes.\n * @param opts Optional Falcon signing options.\n * @returns Attached signature containing both the message and signature.\n */\n seal(msg: Uint8Array, secretKey: Uint8Array, opts?: FalconSigOpts): Uint8Array;\n /**\n * Verifies an attached signature and returns the embedded message.\n * @param sig Attached Falcon signature bytes.\n * @param publicKey Falcon public key bytes.\n * @param opts Optional verification options.\n * @returns Fresh message bytes that do not alias either input when the signature is valid.\n */\n open(sig: Uint8Array, publicKey: Uint8Array, opts?: VerOpts): Uint8Array;\n};\n/** PATCH: options of `internal.sign` (tests only). */\nexport type FalconInternalSignOpts = {\n /** Sampler-seed source (48 bytes). Default: crypto.getRandomValues. */\n random?: (bytesLength?: number) => Uint8Array;\n /** Maximum sampling attempts before throwing. Default: 1000. */\n maxIterations?: number;\n};\n/** PATCH: signing / verification of an externally computed hash point (like ml-dsa `internal`). */\nexport type FalconInternal = {\n /** Signs a hash point (N coefficients mod q); returns the raw signed s2 polynomial. */\n sign(hashPoint: Uint16Array, secretKey: Uint8Array, opts?: FalconInternalSignOpts): Int16Array;\n /** Checks that s2 is a valid signature of the hash point for the public key. */\n verify(s2: Int16Array, hashPoint: Uint16Array, publicKey: Uint8Array): boolean;\n};\n/** Falcon detached-signature API with an attached-signature helper. */\nexport type Falcon = Signer & {\n /** Attached-signature helper for the same Falcon parameter set. */\n attached: FalconAttached;\n /** PATCH: external hash-point API. */\n internal: FalconInternal;\n};\n\nfunction genFalcon(opts: FalconOpts): TRet<Falcon> {\n const { N } = opts;\n const logn = Math.log2(N);\n const id = <T>(n: T): T => n;\n const { newPoly, intPoly, signedCoder } = getIntPoly(logn);\n const floatPoly = getFloatPoly(logn);\n // Kinda like FFT Sampler: single function, but a lot of private deps and internal rng stake\n class NTRU {\n private logn: number;\n private shake: ReturnType<typeof shake256.create>;\n constructor(logn: number, seed: Uint8Array) {\n this.logn = logn;\n this.shake = shake256.create().update(seed);\n }\n private gaussSingle() {\n const g = 1 << (10 - this.logn);\n let val = 0;\n for (let i = 0; i < g; i++) {\n const r128 = bytesToNumberLE(this.shake.xof(16));\n const r1 = r128 & MASK_63n;\n const r2 = (r128 >> _64n) & MASK_63n;\n const sign = Number((r128 >> _63n) & _1n);\n let f = r1 < gauss_1024_12289[0] ? 1 : 0;\n let v = 0;\n for (let k = 1; k < gauss_1024_12289.length; k++) {\n const tBit = r2 >= gauss_1024_12289[k] ? 1 : 0;\n v |= k & -(tBit & (f ^ 1));\n f |= tBit;\n }\n val += sign === 1 ? -v : v;\n }\n return val;\n }\n private polyGauss(): SPoly {\n const n = 1 << this.logn;\n let mod2 = 0; // xor sum of previous elements\n const f = new Int8Array(n);\n for (let u = 0; u < n; u++) {\n let s;\n while (true) {\n s = this.gaussSingle();\n if (s < -127 || s > 127) continue;\n if (u === n - 1) if ((mod2 ^ (s & 1)) === 0) continue;\n break;\n }\n if (u < n - 1) mod2 ^= s & 1;\n f[u] = s;\n }\n return f;\n }\n private galoisNorm(logn: number, a: BPoly): BPoly {\n const n = 1 << logn;\n const d = new Array(n >> 1);\n for (let k = 0; k < n; k += 2) {\n let s: bigint = _0n;\n for (let i = 0; i <= k; i += 2) s += a[i] * a[k - i];\n for (let i = k + 2; i < n; i += 2) s -= a[i] * a[k + n - i];\n d[k >>> 1] = s;\n }\n for (let k = 0; k < n; k += 2) {\n let s: bigint = _0n;\n for (let i = 1; i < k; i += 2) s += a[i] * a[k - i];\n for (let i = k + 1; i < n; i += 2) s -= a[i] * a[k + n - i];\n d[k >>> 1] -= s;\n }\n return d;\n }\n private mulConjD(logn: number, d: BPoly, a: BPoly, b: BPoly): BPoly {\n const n = 1 << logn;\n for (let k = 0; k < n; k++) {\n let s: bigint = _0n;\n for (let i = 0; i <= k; i += 2) s += b[i >>> 1] * a[k - i];\n for (let i = k + 2 - (k & 1); i < n; i += 2) s -= b[i >>> 1] * a[k + n - i];\n if ((k & 1) === 0) d[k] = s;\n else d[k] = -s;\n }\n return d;\n }\n private subMul(logn: number, a: BPoly, b: BPoly, c: BPoly, e: bigint): BPoly {\n const n = 1 << logn;\n for (let k = 0; k < n; k++) {\n let s: bigint = _0n;\n for (let i = 0; i <= k; i++) s += b[i] * c[k - i];\n for (let i = k + 1; i < n; i++) s -= b[i] * c[k + n - i];\n a[k] -= s << e;\n }\n return a;\n }\n private reduce(logn: number, f: BPoly, g: BPoly, F: BPoly, G: BPoly, logn_top: number) {\n // Algorithm 7: Reduce(f, g, F, G)\n // (Page 35)\n // Require: Polynomials f, g, F, G ∈ Z[x]/(φ)\n // Ensure: (F, G) is reduced with respect to (f, g)\n // 1: do\n // 2: k ← ⌊(Ff*+Gg*)/(ff*+gg*)⌋ ▷ (Ff*+Gg*)/(ff*+gg*) ∈ Q[x]/(φ) and k ∈ Z[x]/(φ)\n // 3: F ← F - kf\n // 4: G ← G - kg\n // 5: while k ≠ 0\n // ▷ Multiple iterations may be needed, e.g. if k is computed in small precision.\n const n = 1 << logn;\n const depth = logn_top - logn;\n const floatPoly = getFloatPoly(logn);\n const slen = MAX_BL_SMALL[depth];\n const llen = MAX_BL_LARGE[depth];\n let maxFGBits = BigInt(31 * llen);\n let FGlen = BigInt(llen);\n const scalefg = BigInt(31 * (slen - 10));\n const fgMaxBits = BITLENGTH[depth].avg + 6 * BITLENGTH[depth].std;\n const fgMinBits = BITLENGTH[depth].avg - 6 * BITLENGTH[depth].std;\n let scaleK = BigInt(Math.round(31 * llen - fgMinBits));\n let fx = new Float64Array(n);\n let gx = new Float64Array(n);\n for (let i = 0; i < n; i++) {\n fx[i] = Number(f[i] >> scalefg);\n gx[i] = Number(g[i] >> scalefg);\n }\n const rt3 = floatPoly.conj(floatPoly.FFT(floatPoly.to(fx)));\n const rt4 = floatPoly.conj(floatPoly.FFT(floatPoly.to(gx)));\n const rt5 = floatPoly.invNorm(rt3, rt4);\n\n const Fx = new Float64Array(n);\n const Gx = new Float64Array(n);\n const k = new Array(n);\n while (true) {\n let scaleFG = _31n * (FGlen - _10n);\n for (let i = 0; i < n; i++) {\n Fx[i] = Number(F[i] >> scaleFG);\n Gx[i] = Number(G[i] >> scaleFG);\n }\n const rt2 = floatPoly.mul(floatPoly.FFT(floatPoly.to(Gx)), rt4);\n const rt1 = floatPoly.mul(floatPoly.FFT(floatPoly.to(Fx)), rt3);\n // convert to float64array\n const rt2f = floatPoly.from(\n floatPoly.iFFT(floatPoly.scaleNorm(floatPoly.add(rt2, rt1), rt5))\n );\n const pdc = 2 ** Number(scaleFG - scalefg - scaleK);\n for (let i = 0; i < n; i++) {\n const BOUND = 2147483647.0;\n const val = rt2f[i] * pdc;\n if (val <= -BOUND || val >= BOUND) return false;\n k[i] = BigInt(Math.round(val));\n }\n F = this.subMul(logn, F, f, k, scaleK); // 3: F ← F - kf\n G = this.subMul(logn, G, g, k, scaleK); // 4: G ← G - kg\n const maxfgNew = scaleK + BigInt(Math.round(fgMaxBits)) + _10n;\n if (maxfgNew < maxFGBits) maxFGBits = maxfgNew;\n if (FGlen > _1n && FGlen * _31n >= maxFGBits + _31n) FGlen--;\n if (scaleK <= _0n) break;\n scaleK -= _25n;\n if (scaleK < _0n) scaleK = _0n;\n }\n return true;\n }\n // This is recursive thing that goes from logn to 0\n private solveBranch(logn: number, f: BPoly, g: BPoly, F: BPoly, G: BPoly, logn_top?: number) {\n // Algorithm 6: NTRUSolve_{n,q}(f, g), (Page 35)\n // Require: f, g ∈ Z[x]/(xⁿ + 1) with n a power of two\n // Ensure: Polynomials F, G such that (3.15) is verified\n // 1: if n = 1 then\n // 2: Compute u, v ∈ Z such that uf - vg = gcd(f, g) ▷ Using the extended GCD\n // 3: if gcd(f, g) ≠ 1 then\n // 4: abort and return ⊥\n // 5: (F, G) ← (vq, uq)\n // 6: return (F, G)\n // 7: else\n // 8: f' ← N(f) ▷ f', g', F', G' ∈ Z[x]/(x^{n/2} + 1)\n // 9: g' ← N(g) ▷ N as defined in either (3.25) or (3.26)\n // 10: (F', G') ← NTRUSolve_{n/2,q}(f', g') ▷ Recursive call\n // 11: F ← F'(x²)g(-x) ▷ F, G ∈ Z[x]/(xⁿ + 1)\n // 12: G ← G'(x²)f(-x)\n // 13: Reduce(f, g, F, G) ▷ (F, G) is reduced with respect to (f, g)\n // 14: return (F, G)\n if (logn === 0) {\n // // 1: if n = 1 then\n const xf = f[0];\n const xg = g[0];\n // We can rely on 'invert' to throw if they are not coprime.\n if (xf <= _0n || xg <= _0n) return false;\n try {\n const u1 = invert(xf, xg); // if gcd(f, g) ≠ 1 then\n const v1 = (_1n - u1 * xf) / xg;\n F[0] = -v1 * QBig; // 5: (F, G) ← (vq, uq)\n G[0] = u1 * QBig;\n return true;\n } catch (e) {\n return false;\n }\n }\n if (logn_top === undefined) logn_top = logn;\n const n = 1 << logn;\n const hn = n >>> 1;\n if (!f || f.length < n || !g || g.length < n) return false;\n const fp = this.galoisNorm(logn, f); // 8: f' ← N(f)\n const gp = this.galoisNorm(logn, g); // 9: g' ← N(g)\n const Fp = new Array(hn); // 10: (F', G') ← NTRUSolve_{n/2,q}(f', g')\n const Gp = new Array(hn);\n // 10: (F', G') ← NTRUSolve_{n/2,q}(f', g')\n // ▷ Recursive call\n if (!this.solveBranch(logn - 1, fp, gp, Fp, Gp, logn_top)) return false;\n F = this.mulConjD(logn, F, g, Fp); // 11: F ← F'(x²)g(-x)\n G = this.mulConjD(logn, G, f, Gp); // 12: G ← G'(x²)f(-x)\n // 13: Reduce(f, g, F, G)\n // ▷ (F, G) is reduced with respect to (f, g)\n return this.reduce(logn, f, g, F, G, logn_top);\n }\n private solve(f: SPoly, g: SPoly) {\n // Algorithm 5: NTRUGen(φ, q)\n // (Page 34)\n // Require: A monic polynomial φ ∈ Z[x] of degree n, a modulus q\n // Ensure: Polynomials f, g, F, G\n // 1: σ{f,g} ← 1.17√q/2n ▷ σ{f,g} is chosen so that E[||(f, g)||] = 1.17√q\n // 2: for i from 0 to n-1 do\n // 3: fᵢ ← DZ,σ{f,g},0 ▷ See also (3.29)\n // 4: gᵢ ← DZ,σ{f,g},0\n // 5: f ← Σᵢ fᵢxⁱ ▷ f ∈ Z[x]/(φ)\n // 6: g ← Σᵢ gᵢxⁱ ▷ g ∈ Z[x]/(φ)\n // 7: if NTT(f) contains 0 as a coefficient then ▷ Check that f is invertible mod q\n // 8: restart\n // 9: γ ← max{||(g, -f)||, ||( (qf*)/(ff*+gg*), (qg*)/(ff*+gg*) )||}\n // ▷ Using (3.9) with (3.8) or (3.10)\n // 10: if γ > 1.17√q then ▷ Check that γ = ||B||_GS is short\n // 11: restart\n // 12: F, G ← NTRUSolve_{n,q}(f, g) ▷ Computing F, G such that fG - gF = q mod φ\n // 13: if (F, G) = ⊥ then\n // 14: restart\n // 15: return f, g, F, G\n const n = 1 << logn;\n const bf = Array.from(f).map(BigInt);\n const bg = Array.from(g).map(BigInt);\n const bF = new Array(n);\n const bG = new Array(n);\n // 12: F, G ← NTRUSolve_{n,q}(f, g)\n // ▷ Computing F, G such that fG - gF = q mod φ\n if (!this.solveBranch(logn, bf, bg, bF, bG)) return false;\n const F = new Int8Array(n);\n const G = new Int8Array(n);\n for (let i = 0; i < n; i++) {\n const x = bF[i];\n const y = bG[i];\n if (x < -127 || x > +127 || y < -127 || y > +127) return false;\n F[i] = Number(x);\n G[i] = Number(y);\n }\n return [F, G];\n }\n generate(): [SPoly, SPoly, SPoly, SPoly, IPoly] {\n // Algorithm 4: Keygen(φ, q)\n // (Page 33)\n // Require: A monic polynomial φ ∈ Z[x], a modulus q\n // Ensure: A secret key sk, a public key pk\n // 1: f, g, F, G ← NTRUGen(φ, q) ▷ Solving the NTRU equation\n // 2: B ← [ g -f ; G -F ]\n // 3: B̂ ← FFT(B) ▷ Compute the FFT for each of the 4 components {g, -f, G, -F}\n // 4: G ← B̂ × B̂*\n // 5: T ← ffLDL*(G) ▷ Computing the LDL* tree\n // 6: for each leaf leaf of T do\n // 7: leaf.value ← σ/√leaf.value ▷ Normalization step\n // 8: sk ← (B̂, T)\n // 9: h ← gf⁻¹ mod q\n // 10: pk ← h\n // 11: return sk, pk\n let max = 1_000_000;\n let curr = 0;\n while (true) {\n if (curr++ === max) throw new Error(\"can't generate key\");\n const f = this.polyGauss();\n const g = this.polyGauss();\n let lim = 1 << (opts.fgBits - 1);\n for (let u = 0; u < N; u++) {\n if (f[u] >= lim || f[u] <= -lim || g[u] >= lim || g[u] <= -lim) {\n lim = -1;\n break;\n }\n }\n if (lim < 0) continue;\n const normf = intPoly.smallSqnorm(f);\n const normg = intPoly.smallSqnorm(g);\n const norm = (normf + normg) | -((normf | normg) >>> 31);\n // Cheap integer prefilter for the same 1.17^2*q Gram-Schmidt bound;\n // ceil(BNORM_MAX) = 16823.\n if (norm >= 16823) continue;\n let rt1 = floatPoly.FFT(floatPoly.convSmall(f));\n let rt2 = floatPoly.FFT(floatPoly.convSmall(g));\n const rt3 = floatPoly.invNorm(rt1, rt2);\n rt1 = floatPoly.iFFT(floatPoly.scaleNorm(floatPoly.mulConst(floatPoly.conj(rt1), Q), rt3));\n rt2 = floatPoly.iFFT(floatPoly.scaleNorm(floatPoly.mulConst(floatPoly.conj(rt2), Q), rt3));\n // Separate reals and then imaginary to enforce numerical stability\n let bnorm = 0;\n for (let u = 0; u < rt1.length; u++) {\n bnorm += rt1[u].re * rt1[u].re;\n bnorm += rt2[u].re * rt2[u].re;\n }\n for (let u = 0; u < rt1.length; u++) {\n bnorm += rt1[u].im * rt1[u].im;\n bnorm += rt2[u].im * rt2[u].im;\n }\n if (!(bnorm < BNORM_MAX)) continue;\n let pub;\n try {\n pub = computePublic(f, g);\n } catch (_) {\n continue;\n }\n const solved = this.solve(f, g);\n if (solved === false) continue;\n return [f, g, solved[0], solved[1], pub]; // f g F G h\n }\n }\n }\n // same as ml-dsa id, but MSB bits :(\n const modqCoder = () => {\n const coder = bitsCoderMSB(newPoly, N, 14, {\n encode: id,\n decode: id,\n }) as BytesCoderLen<IPoly>;\n return {\n bytesLen: coder.bytesLen,\n encode(poly: TArg<Uint16Array>) {\n // Keep these raw checks in sync with Q:\n // Falcon public-key coefficients must stay in [0, q - 1].\n for (let i = 0; i < poly.length; i++)\n if (poly[i] >= 12289) throw new Error('public key coeff out of range');\n return coder.encode(poly);\n },\n decode(bytes: TArg<Uint8Array>) {\n // Round-3 Falcon requires exact body length here;\n // otherwise truncated keys decode as zero-padded\n // and overlong keys silently ignore the tail in this generic bit decoder.\n if (bytes.length !== coder.bytesLen) throw new Error('wrong public key length');\n const poly = coder.decode(bytes);\n // Keep these raw checks in sync with Q:\n // Falcon public-key coefficients must stay in [0, q - 1].\n for (let i = 0; i < poly.length; i++)\n if (poly[i] >= 12289) throw new Error('public key coeff out of range');\n const normalized = coder.encode(poly);\n if (normalized.length !== bytes.length) throw new Error('wrong public key length');\n for (let i = 0; i < bytes.length; i++)\n if (bytes[i] !== normalized[i]) throw new Error('wrong public key encoding');\n return poly;\n },\n };\n };\n const trimI8Coder = (bits: number) => {\n const shift = 32 - bits;\n const coder = bitsCoderMSB((len) => new Int8Array(len), N, bits, {\n encode: (v) => v & ((1 << bits) - 1),\n decode: (w) => ((w & getMask(bits)) << shift) >> shift,\n }) as BytesCoderLen<SPoly>;\n return {\n bytesLen: coder.bytesLen,\n encode(poly: TArg<Int8Array>) {\n // Secret-key trim encodings keep a symmetric signed range and reserve the most-negative\n // value as a non-canonical sentinel,\n // so encode() and decode() intentionally use different bounds.\n const max = (1 << (bits - 1)) - 1;\n const min = -max;\n for (let i = 0; i < poly.length; i++)\n if (poly[i] < min || poly[i] > max) throw new Error('private key coeff out of range');\n return coder.encode(poly);\n },\n decode(bytes: TArg<Uint8Array>) {\n const poly = coder.decode(bytes);\n const min = -(1 << (bits - 1));\n for (let i = 0; i < poly.length; i++)\n if (poly[i] === min) throw new Error('forbidden private key coeff');\n return poly;\n },\n };\n };\n const fgCoder = trimI8Coder(opts.fgBits);\n const FGCoder = trimI8Coder(opts.FGBits);\n // Current utils.splitCoder requires a label first;\n // without it Falcon key/sig encodings drift and KATs fail.\n // 0x50 + logn || f || g || F\n const secretKeyCoder = headerCoder(\n 0x50 + logn,\n splitCoder('falcon.secretKey', fgCoder, fgCoder, FGCoder)\n ) as BytesCoderLen<[Int8Array, Int8Array, Int8Array]>;\n const publicKeyCoder = headerCoder(0x00 + logn, modqCoder()) as BytesCoderLen<Uint16Array>;\n const decodePaddedSig = (s2: TArg<Uint8Array>) => {\n // The fixed padded form accepts only a canonical compressed payload\n // followed by an all-zero tail.\n const normalized = compCoder(N).encode(compCoder(N).decode(s2));\n for (let i = normalized.length; i < s2.length; i++)\n if (s2[i] !== 0) throw new Error('non-zero padding');\n return normalized;\n };\n const decodeUnpaddedSig = (s2: TArg<Uint8Array>) => {\n // Unpadded attached and detached signatures require the compressed payload to use its exact\n // canonical bitlength. Appending a zero tail and adjusting the outer container length must\n // still be rejected.\n const normalized = compCoder(N).encode(compCoder(N).decode(s2));\n if (normalized.length !== s2.length) throw new Error('wrong signature length');\n return s2;\n };\n const decodeSig = opts.padded ? decodePaddedSig : decodeUnpaddedSig;\n // Unpadded: [ 2B sig_len ] [ 40B nonce ] [ message ] [ 1B header ] [ compressed_sig ]\n // Padded [ 1B header ] [ 40B nonce ] [ compressed_sig ] [ padding ] | [ message ]\n const SignatureCoderBasic = (logn: number) => {\n const TYPE_BYTE = 0x20 + logn;\n return {\n encode({ msg, nonce, s2 }: TArg<SignatureRaw>): TRet<Uint8Array> {\n let compressed: Uint8Array = s2;\n const payloadLen = 1 + compressed.length;\n const totalLen = 2 + NONCELEN + msg.length + payloadLen;\n const out = new Uint8Array(totalLen);\n let i = 0;\n out[i++] = (payloadLen >> 8) & 0xff;\n out[i++] = payloadLen & 0xff;\n out.set(nonce, i);\n i += NONCELEN;\n out.set(msg, i);\n i += msg.length;\n out[i++] = TYPE_BYTE;\n out.set(compressed, i);\n return out as TRet<Uint8Array>;\n },\n decode(data: TArg<Uint8Array>): TRet<SignatureRaw> {\n if (!data || data.length < NONCELEN + 3) throw new Error('signature coder: wrong length');\n const len = (data[0] << 8) | data[1];\n const s2Len = len - 1;\n const msgLen = data.length - NONCELEN - 3 - s2Len;\n if (msgLen < 0) throw new Error('signature coder: wrong msg length');\n const typeByte = data[2 + NONCELEN + msgLen];\n if (typeByte !== TYPE_BYTE) throw new Error('signature coder: wrong type byte');\n const nonce = data.subarray(2, 2 + NONCELEN);\n const msg = data.subarray(2 + NONCELEN, 2 + NONCELEN + msgLen);\n const s2 = decodeUnpaddedSig(data.subarray(2 + NONCELEN + msgLen + 1));\n if (s2.length !== s2Len) throw new Error('signature coder: wrong s2 length');\n return { msg, nonce, s2 } as TRet<SignatureRaw>;\n },\n };\n };\n const SignatureCoderPadded = (logn: number) => {\n const sigLen = opts.paddedLen;\n return {\n encode({ msg, nonce, s2 }: TArg<SignatureRaw>): TRet<Uint8Array> {\n return headerCoder(\n 0x30 + logn,\n splitCoder('falcon.signature', NONCELEN, sigLen, msg.length)\n ).encode([nonce, pad(sigLen).encode(s2), msg]);\n },\n decode(data: TArg<Uint8Array>): TRet<SignatureRaw> {\n // Keep API misuse on the coder's TypeError path before reading the container length.\n abytes(data, undefined, 'signature');\n // The compressed-signature field is fixed-width here; only the message is variable. A\n // container shorter than the fixed part would make the s2 field borrow bytes from nowhere\n // and let a truncated encoding open to the same message.\n const msgLen = data.length - NONCELEN - sigLen - 1;\n if (msgLen < 0) throw new Error('signature coder: wrong length');\n const [nonce, s2, msg] = headerCoder(\n 0x30 + logn,\n splitCoder('falcon.signature', NONCELEN, sigLen, msgLen)\n ).decode(data);\n return { nonce, s2: decodeSig(s2), msg } as TRet<SignatureRaw>;\n },\n };\n };\n // [ 1B header ] [ 40B nonce ] [ compressed_sig ]\n const SignatureCoderDetached = (logn: number) => {\n const paddedSigLen = opts.sigLen - 1 - NONCELEN;\n const getSigLen = (s2: TArg<Uint8Array>) => (opts.padded ? paddedSigLen : s2.length);\n return {\n encode({ nonce, s2 }: TArg<{ nonce: Uint8Array; s2: Uint8Array }>): TRet<Uint8Array> {\n return headerCoder(\n 0x30 + logn,\n splitCoder('falcon.detachedSignature', NONCELEN, getSigLen(s2))\n ).encode([nonce, opts.padded ? pad(paddedSigLen).encode(s2) : s2]);\n },\n decode(data: TArg<Uint8Array>): TRet<{\n nonce: Uint8Array;\n s2: Uint8Array;\n }> {\n // Unpadded Round-3 signatures have parameter-set maxima (header + nonce + s2):\n // 752 bytes for Falcon-512 and 1462 for Falcon-1024. Reject before creating views or\n // entering the bit decoder so attacker-sized inputs cannot cause proportional work.\n if (!opts.padded && data.length > 1 + NONCELEN + opts.maxS2Len)\n throw new Error('detached signature too long');\n // Padded detached signatures are fixed-length (`lengths.signature`), so the payload width\n // must come from the parameter set, not from the input: deriving it would accept appended\n // zero bytes and truncated padding as extra valid encodings of the same signature.\n // Unpadded signatures are variable-length; decodeUnpaddedSig() enforces the exact canonical\n // bitlength of whatever remains.\n const payloadLen = opts.padded ? paddedSigLen : data.length - NONCELEN - 1;\n const [nonce, raw] = headerCoder(\n 0x30 + logn,\n splitCoder('falcon.detachedSignature', NONCELEN, payloadLen)\n ).decode(data);\n const s2 = decodeSig(raw);\n return { nonce, s2 } as TRet<{ nonce: Uint8Array; s2: Uint8Array }>;\n },\n };\n };\n const SignatureCoder = (opts.padded ? SignatureCoderPadded : SignatureCoderBasic)(logn);\n // Round-3 Falcon rejects non-invertible f before division;\n // otherwise malformed secret keys leak a raw arithmetic error.\n // Returns NTT(f) after the nonzero-lane check;\n // callers still apply f^{-1} via coefficient-wise division.\n const invertF = (f: TArg<SPoly>) => {\n const tt = intPoly.ntt(signedCoder.decode(f));\n for (let u = 0; u < N; u++)\n if (tt[u] === 0) throw new Error('invalid secretKey: non-invertible f');\n return tt;\n };\n function computePublic(f: TArg<SPoly>, g: TArg<SPoly>) {\n const tt = invertF(f);\n const h = intPoly.ntt(signedCoder.decode(g));\n // intPoly.div() returns to coefficient form via intt(), so public keys are encoded from the\n // canonical polynomial h = g/f and verifyRaw() re-enters the NTT domain later.\n const res = intPoly.div(h, tt); // h = g/f\n cleanBytes(tt);\n return res;\n }\n // Reconstruct the omitted secret-key limb G as g*F/f mod q, then mirror round-3 Falcon's centered\n // reduction and small-coefficient check before using the completed basis for signing.\n function completePrivate(f: TArg<SPoly>, g: TArg<SPoly>, F: TArg<SPoly>) {\n let t1 = intPoly.toMontgomery(intPoly.ntt(signedCoder.decode(g)));\n const t2 = intPoly.ntt(signedCoder.decode(F));\n const tt = invertF(f);\n t1 = intPoly.div(intPoly.mul(t1, t2), tt);\n const G = new Int8Array(N);\n for (let u = 0; u < N; u++) {\n let w = t1[u];\n // This mirrors round-3 Falcon's secret-key G reconstruction, not a generic centered reduction\n // helper:\n // the threshold is floor(q/2), and w = Qhalf maps to -Qhalf - 1 here on purpose.\n w -= Q & ~-((w - Qhalf) >>> 31);\n const gi = w | 0;\n if (gi < -127 || gi > 127) {\n cleanBytes(t1, t2, tt, G);\n throw new Error('Coefficient out of bounds');\n }\n G[u] = gi;\n }\n cleanBytes(t1, t2, tt);\n return G;\n }\n function HashToPoint(nonce: TArg<Uint8Array>, msg: TArg<Uint8Array>): TRet<IPoly> {\n // Algorithm 3: HashToPoint(str, q, n)\n // (Page 31)\n // Require: A string str, a modulus q ≤ 2¹⁶, a degree n ∈ N*\n // Ensure: An polynomial c = Σᵢ cᵢxⁱ in Zq[x]\n // 1: k ← ⌈2¹⁶/q⌉\n // 2: ctx ← SHAKE-256-Init()\n // 3: SHAKE-256-Inject(ctx, str)\n // 4: i ← 0\n // 5: while i < n do\n // 6: t ← SHAKE-256-Extract(ctx, 16)\n // 7: if t < kq then\n // 8: cᵢ ← t mod q\n // 9: i ← i + 1\n // 10: return c\n const h = shake256.create().update(nonce).update(msg); // 3: SHAKE-256-Inject(ctx, str)\n const c = new Uint16Array(N);\n // Round-3 Falcon keeps 16-bit draws only in 0..61444, i.e. below 61445 = 5*q, the largest\n // 16-bit multiple of q below 2^16; a literal ceil(2^16/q)*q would accept every sample.\n const kQ = 5 * Q;\n for (let i = 0; i < N;) {\n const tmp = h.xof(2); // 6: t ← SHAKE-256-Extract(ctx, 16)\n let w = (tmp[0] << 8) | tmp[1];\n if (w < kQ) c[i++] = w % Q; // 8: cᵢ ← t mod q\n }\n return c as TRet<IPoly>;\n }\n // This is basically one sampling routine,\n // but it carries a lot of internal state and gets complex quickly.\n class FFSampler {\n private logn: number;\n // Shake\n private shake: ReturnType<typeof shake256.create>;\n private shakeBuf: Uint8Array;\n private ctrView: DataView;\n // ChaCha\n private ctr: bigint = _0n;\n private buf: Uint8Array;\n private buf32: Uint32Array;\n private pos: number;\n private key: Uint8Array;\n private nonce32: Uint32Array;\n private curBlock: Uint8Array;\n private curBlock32: Uint32Array;\n private view: DataView;\n // Sampler\n private b01: CPoly;\n private b11: CPoly;\n private g00: CPoly;\n private g01: CPoly;\n private g11: CPoly;\n\n constructor(logn: number, seed: Uint8Array, b00: CPoly, b01: CPoly, b10: CPoly, b11: CPoly) {\n this.logn = logn;\n // Shake\n this.shake = shake256.create().update(seed);\n this.shakeBuf = new Uint8Array(56);\n this.key = this.shakeBuf.subarray(0, 32);\n this.nonce32 = u32(this.shakeBuf.subarray(32, 48)); // 4 u32s\n this.ctrView = createView(this.shakeBuf.subarray(48, 56));\n // Signle chacha20 instance buffer\n this.curBlock = new Uint8Array(64);\n this.curBlock32 = u32(this.curBlock);\n // whole rng buffer\n this.buf = new Uint8Array(8 * this.curBlock.length);\n this.buf32 = u32(this.buf);\n this.pos = this.buf.length; // not filled yet!\n this.view = createView(this.buf);\n // Sampler\n this.b01 = b01;\n this.b11 = b11;\n const { g00, g01, g11 } = this.gramFFT(b00, b10);\n this.g00 = g00;\n this.g01 = g01;\n this.g11 = g11;\n }\n destroy() {\n this.shake.destroy();\n cleanBytes(this.shakeBuf, this.curBlock, this.buf);\n cleanCPoly(this.b01, this.b11, this.g00, this.g01, this.g11);\n }\n private refill(minBytes: number): void {\n if (this.buf.length - this.pos >= minBytes) return;\n const out32 = swap32IfBE(this.buf32);\n for (let i = 0; i < 8; i++, this.ctr++) {\n const n = swap32IfBE(this.nonce32.slice()); // [n0, n1, n2, n3]\n n[2] ^= Number(this.ctr & MASK_32n);\n n[3] ^= Number(this.ctr >> _32n);\n // chacha20() takes raw nonce bytes; on BE the word-normalized temp must be swapped back.\n swap32IfBE(n.subarray(1));\n chacha20(this.key, u8(n.subarray(1)), EMPTY_CHACHA20_BLOCK, this.curBlock, n[0]);\n // Interleave like Falcon's AVX2 layout (by u32 chunks from 8 parallel chacha20)\n const block32 = swap32IfBE(this.curBlock32);\n for (let j = 0; j < 16; j++) out32[i + j * 8] = block32[j];\n swap32IfBE(block32);\n }\n swap32IfBE(out32);\n this.pos = 0;\n }\n // Sampler\n private gaussian0(): number {\n // Algorithm 12: BaseSampler()\n // (Page 41)\n // Require: -\n // Ensure: An integer z₀ ∈ {0, ..., 18} such that z ~ χ ▷ χ is uniquely defined by (3.33)\n // 1: u ← UniformBits(72) ▷ See (3.32)\n // 2: z₀ ← 0\n // 3: for i = 0, ..., 17 do\n // 4: z₀ ← z₀ + [u < RCDT[i]] ▷ Note that one should use RCDT, not pdt or cdt\n // 5: return z₀\n this.refill(9);\n const t0 = this.view.getUint32(this.pos, true);\n const t1 = this.view.getUint32(this.pos + 4, true);\n const t2 = this.buf[this.pos + 8];\n this.pos += 9;\n const v0 = t0 & 0xffffff;\n const v1 = ((t0 >>> 24) & 0xff) | ((t1 & 0xffff) << 8);\n const v2 = ((t1 >>> 16) & 0xffff) | (t2 << 16);\n let z = 0;\n for (let i = 0; i < GAUSS0.length; i += 3) {\n let cc = (v0 - GAUSS0[i + 2]) >>> 31;\n cc = (((v1 - GAUSS0[i + 1]) | 0) - cc) >>> 31;\n cc = (((v2 - GAUSS0[i + 0]) | 0) - cc) >>> 31;\n z += cc;\n }\n return z;\n }\n private berExp(x: number, ccs: any) {\n // Algorithm 14: BerExp(x, ccs) (Page 43)\n // Require: Floating point values x, ccs ≥ 0\n // Ensure: A single bit, equal to 1 with probability ≈ ccs · exp(-x)\n // 1: s ← ⌊x/ln(2)⌋\n // ▷ Compute the unique decomposition x = s · ln(2) + r,\n // with (r, s) ∈ [0, ln 2) × Z⁺\n // 2: r ← x - s · ln(2)\n // 3: s ← min(s, 63)\n // 4: z ← (2 · ApproxExp(r, ccs) - 1) >> s ▷ z ≈ 2⁶⁴⁻ˢ · ccs · exp(-r) = 2⁶⁴ · ccs · exp(-x)\n // 5: i ← 64\n // 6: do\n // 7: i ← i - 8\n // 8: w ← UniformBits(8) - ((z >> i) & 0xFF)\n // ▷ This loop does not need to be done in constant-time\n // 9: while ((w = 0) and (i > 0))\n // 10: return [w < 0] ▷ Return 1 with probability 2⁻⁶⁴ · z ≈ ccs · exp(-x)\n let s = Math.trunc(x * 1.4426950408889633870046509401);\n const r = x - s * 0.69314718055994530941723212146;\n let e = ApproxExp(r, ccs);\n e *= 2147483648.0;\n let z1 = e | 0;\n e = (e - z1) * 4294967296.0;\n let z0 = e | 0;\n z1 = (z1 << 1) | (z0 >>> 31);\n z0 <<= 1;\n s = (s | ((63 - s) >>> 26)) & 63;\n const sm = -(s >>> 5) | 0;\n z0 ^= sm & (z0 ^ z1);\n z1 &= ~sm;\n s &= 31;\n z0 = (z0 >>> s) | ((z1 << (31 - s)) << 1);\n z1 >>>= s;\n for (let j = 0; j < 2; j++) {\n for (let i = 24; i >= 0; i -= 8) {\n this.refill(1);\n const w = this.buf[this.pos++];\n const bz = (z1 >>> i) & 0xff;\n if (w !== bz) return w < bz;\n }\n z1 = z0;\n }\n return false;\n }\n private samplerZ(mu: number, isigma: number) {\n // Algorithm 15: SamplerZ(μ, σ'), (Page 43)\n // Require: Floating-point values μ, σ' ∈ R such that σ' ∈ [σ_{min}, σ_{max}]\n // Ensure: An integer z ∈ Z sampled from a distribution very close to DZ,μ,σ'\n // 1: r ← μ - ⌊μ⌋ ▷ r must be in [0, 1)\n // 2: ccs ← σ_{min}/σ' ▷ ccs helps to make the algorithm running time independent of σ'\n // 3: while (1) do\n // 4: z₀ ← BaseSampler()\n // 5: b ← UniformBits(8) & 0x1\n // 6: z ← b + (2 · b - 1)z₀\n // 7: x ← ((z-r)²)/(2σ'²)\n // 8: if (BerExp(x, ccs) = 1) then\n // 9: return z + ⌊μ⌋\n const s = Math.floor(mu);\n const r = mu - s;\n const dss = isigma * isigma * 0.5;\n const ccs = isigma * SIGMA_MIN[this.logn];\n for (;;) {\n const z0 = this.gaussian0();\n this.refill(1);\n const b = this.buf[this.pos++] & 1;\n const z = (((z0 << 1) + 1) & -b) - z0;\n let x = z - r;\n x = x * x * dss - z0 * z0 * 0.1508650488753727203494747755;\n if (this.berExp(x, ccs)) return s + z;\n }\n }\n private splitFFT(logn: number, f: CPoly) {\n // Algorithm 1: splitfft(FFT(f))\n // (Page 29)\n // Require: FFT(f) = (f(ζ))ζ for some f ∈ Q[x]/(φ)\n // Ensure: FFT(f₀) = (f₀(ζ'))ζ' and FFT(f₁) = (f₁(ζ'))ζ' for some f₀, f₁ ∈ Q[x]/(φ')\n // Format: All polynomials are in FFT representation.\n // 1: for ζ such that φ(ζ) = 0 and Im(ζ) > 0 do ▷ See eq. (3.19) with 0 ≤ k < n/2\n // 2: ζ' ← ζ²\n // 3: f₀(ζ') ← ½ [f(ζ) + f(−ζ)]\n // 4: f₁(ζ') ← (1/(2ζ)) [f(ζ) − f(−ζ)]\n // 5: return (FFT(f₀), FFT(f₁))\n const hn = 1 << (logn - 1);\n const qn = hn >> 1;\n if (logn === 1) return { f0: [{ re: f[0].re, im: 0.0 }], f1: [{ re: f[0].im, im: 0.0 }] };\n const f0t = new Array(qn);\n const f1t = new Array(qn);\n const ft = f;\n for (let i = 0; i < qn; i++) {\n const a = ft[(i << 1) + 0];\n const b = ft[(i << 1) + 1];\n f0t[i] = fComplex.scale(fComplex.add(a, b), 0.5);\n f1t[i] = fComplex.scale(\n fComplex.mul(fComplex.sub(a, b), fComplex.conj(COMPLEX_ROOTS_O[i + hn])),\n 0.5\n );\n }\n return { f0: f0t, f1: f1t };\n }\n private splitSelfAdjFFT(logn: number, f: CPoly) {\n const hn = 1 << (logn - 1);\n const qn = hn >> 1;\n if (logn === 1) return { f0: [{ re: f[0].re, im: 0.0 }], f1: [{ re: 0.0, im: 0.0 }] };\n const f0t = new Array(qn);\n const f1t = new Array(qn);\n const ft = f;\n for (let i = 0; i < qn; i++) {\n const a = ft[(i << 1) + 0];\n const b = ft[(i << 1) + 1];\n f0t[i] = fComplex.scale(fComplex.add(a, b), 0.5);\n f1t[i] = fComplex.scale(\n fComplex.scale(fComplex.conj(COMPLEX_ROOTS_O[i + hn]), fComplex.sub(a, b).re),\n 0.5\n );\n }\n return { f0: f0t, f1: f1t };\n }\n private mergeFFT(logn: number, f0: CPoly, f1: CPoly): CPoly {\n // Algorithm 2: mergefft(f₀, f₁)\n // (Page 29)\n // Require: FFT(f₀) = (f₀(ζ'))ζ' and FFT(f₁) = (f₁(ζ'))ζ' for some f₀, f₁ ∈ Q[x]/(φ')\n // Ensure: FFT(f) = (f(ζ))ζ for some f ∈ Q[x]/(φ)\n // Format: All polynomials are in FFT representation.\n // 1: for ζ such that φ(ζ) = 0 do ▷ See eq. (3.19)\n // 2: ζ' ← ζ²\n // 3: f(ζ) ← f₀(ζ') + ζf₁(ζ')\n // 4: return FFT(f)\n const hn = 1 << (logn - 1);\n const qn = hn >> 1;\n if (logn === 1) return [{ re: f0[0].re, im: f1[0].re }];\n const ft = new Array(2 * qn);\n for (let i = 0; i < qn; i++) {\n const a = f0[i];\n const c = fComplex.mul(f1[i], COMPLEX_ROOTS_O[i + hn]);\n ft[(i << 1) + 0] = fComplex.add(a, c);\n ft[(i << 1) + 1] = fComplex.sub(a, c);\n }\n return ft;\n }\n private gramFFT(b00: CPoly, b10: CPoly) {\n const { b01, b11 } = this;\n const hn = (1 << this.logn) >> 1;\n const g00: CPoly = new Array(hn);\n const g01: CPoly = new Array(hn);\n const g11: CPoly = new Array(hn);\n for (let i = 0; i < hn; i++) {\n const b00t = b00[i];\n const b01t = b01[i];\n const b10t = b10[i];\n const b11t = b11[i];\n const u = fComplex.mul(b00t, fComplex.conj(b10t));\n const v = fComplex.mul(b01t, fComplex.conj(b11t));\n g00[i] = { re: fComplex.magSqSum(b00t, b01t), im: 0.0 };\n g01[i] = fComplex.add(u, v);\n g11[i] = { re: fComplex.magSqSum(b10t, b11t), im: 0.0 };\n }\n return { g00, g01, g11 };\n }\n private ffsampRec(\n logn: number,\n t0: CPoly,\n t1: CPoly,\n g00i: CPoly,\n g01i: CPoly,\n g11i: CPoly\n ): { t0: CPoly; t1: CPoly } {\n // Algorithm 11: ffSamplingₙ(t, T)\n // (Page 40)\n // Require: t = (t₀, t₁) ∈ FFT(Q[x]/(xⁿ + 1))², a FALCON tree T\n // Ensure: z = (z₀, z₁) ∈ FFT(Z[x]/(xⁿ + 1))²\n // Format: All polynomials are in FFT representation.\n // 1: if n = 1 then\n // 2: σ' ← T.value ▷ It is always the case that σ' ∈ [σ_{min}, σ_{max}]\n // 3: z₀ ← SamplerZ(t₀, σ') ▷ Since n=1, tᵢ = invFFT(tᵢ) ∈ Q and zᵢ = invFFT(zᵢ) ∈ Z\n // 4: z₁ ← SamplerZ(t₁, σ')\n // 5: return z = (z₀, z₁)\n // 6: (l, T₀, T₁) ← (T.value, T.leftchild, T.rightchild)\n // 7: t'₁ ← splitfft(t₁) ▷ t₀, t'₁ ∈ FFT(Q[x]/(x^{n/2} + 1))²\n // 8: z'₁ ← ffSampling_{n/2}(t'₁, T₁) ▷ First recursive call to ffSampling_{n/2}\n // 9: z₁ ← mergefft(z'₁) ▷ z₀, z₁ ∈ FFT(Z[x]/(x^{n/2} + 1))²\n // 10: t'₀ ← t₀ + (t₁ - z₁) ⊙ l\n // 11: t''₀ ← splitfft(t'₀)\n // 12: z'₀ ← ffSampling_{n/2}(t''₀, T₀) ▷ Second recursive call to ffSampling_{n/2}\n // 13: z₀ ← mergefft(z'₀)\n // 14: return z = (z₀, z₁)\n if (logn === 0) {\n // The dynamic sampler stores 1/σ' instead of σ'. Keygen guarantees this interval,\n // but an imported compact key may reconstruct an invalid basis. Check the actual LDL*\n // leaf before it can drive SamplerZ; the negated comparison also rejects NaN/infinity.\n const leaf = Math.sqrt(g00i[0].re) * INV_SIGMA[this.logn];\n const sigmaPrime = 1 / leaf;\n if (!(sigmaPrime >= SIGMA_MIN[this.logn] && sigmaPrime <= SIGMA_MAX))\n throw new Error('invalid secretKey: sampler sigma out of range');\n // 3: z₀ ← SamplerZ(t₀, σ')\n // ▷ Since n=1, tᵢ = invFFT(tᵢ) ∈ Q and zᵢ = invFFT(zᵢ) ∈ Z\n const t0re = this.samplerZ(t0[0].re, leaf);\n const t1re = this.samplerZ(t1[0].re, leaf); // 4: z₁ ← SamplerZ(t₁, σ')\n return { t0: [{ re: t0re, im: 0.0 }], t1: [{ re: t1re, im: 0.0 }] };\n }\n // 6: (l, T₀, T₁) ← (T.value, T.leftchild, T.rightchild)\n const { g00, g01, g11 } = ldlFFT(logn, g00i, g01i, g11i);\n const { f0: g00f0, f1: g00f1 } = this.splitSelfAdjFFT(logn, g00);\n const { f0: g11f0, f1: g11f1 } = this.splitSelfAdjFFT(logn, g11);\n // 7: t'₁ ← splitfft(t₁)\n // ▷ t₀, t'₁ ∈ FFT(Q[x]/(x^{n/2} + 1))²\n const { f0: t1f0in, f1: t1f1in } = this.splitFFT(logn, t1);\n const { t0: t1f0out, t1: t1f1out } = this.ffsampRec(\n logn - 1,\n t1f0in,\n t1f1in,\n g11f0,\n g11f1,\n g11f0\n ); // 8: z'₁ ← ffSampling_{n/2}(t'₁, T₁) ▷ First recursive call to ffSampling_{n/2}\n // 9: z₁ ← mergefft(z'₁)\n // ▷ z₀, z₁ ∈ FFT(Z[x]/(x^{n/2} + 1))²\n const t1new = this.mergeFFT(logn, t1f0out, t1f1out);\n // 10: t'₀ ← t₀ + (t₁ - z₁) ⊙ l\n const t0tmp = floatPoly.add(t0, floatPoly.mul(g01, floatPoly.sub(t1, t1new)));\n const { f0: t0f0in, f1: t0f1in } = this.splitFFT(logn, t0tmp); // 11: t''₀ ← splitfft(t'₀)\n const { t0: t0f0out, t1: t0f1out } = this.ffsampRec(\n logn - 1,\n t0f0in,\n t0f1in,\n g00f0,\n g00f1,\n g00f0\n ); // 12: z'₀ ← ffSampling_{n/2}(t''₀, T₀) ▷ Second recursive call to ffSampling_{n/2}\n const z1 = this.mergeFFT(logn, t0f0out, t0f1out); // 13: z₀ ← mergefft(z'₀)\n return { t0: z1, t1: t1new };\n }\n // sampling a preimage in FFT domain\n sample(hm: Uint16Array) {\n const t0t = floatPoly.FFT(floatPoly.convSmall(hm as any));\n const t0f = floatPoly.mulConst(floatPoly.mul(t0t, this.b11), F_INV_Q);\n const t1f = floatPoly.mulConst(floatPoly.mul(t0t, this.b01), F_MINUS_INV_Q);\n // Set seed\n this.shake.xofInto(this.shakeBuf);\n this.ctr = this.ctrView.getBigUint64(0, true);\n // Actual sampling\n return this.ffsampRec(this.logn, t0f, t1f, this.g00, this.g01, this.g11);\n }\n }\n\n const signRaw = (\n sk: TArg<Uint8Array>,\n msg: TArg<Uint8Array>,\n maxLen: number,\n rnd: TArg<FalconRandom> = randomBytes\n ): TRet<SignatureRaw> => {\n // Algorithm 10: Sign(m, sk, [β²]), (Page 39)\n // Require: A message m, a secret key sk, a bound [β²]\n // Ensure: A signature sig of m\n // 1: r ← {0, 1}³²⁰ uniformly\n // 2: c ← HashToPoint(r||m, q, n)\n // 3: t ← ( (1/q)FFT(c) ⊙ FFT(F), (1/q)FFT(c) ⊙ FFT(f) ) ▷ t = (FFT(c), FFT(0)) · B̂⁻¹\n // 4: do\n // 5: do\n // 6: z ← ffSamplingₙ(t, T)\n // 7: s = (t - z)B̂\n // ▷ At this point, s follows a Gaussian distribution:\n // s ~ D_{(c,0)+Λ(B),σ,0}\n // 8: while ||s||² > [β²]\n // ▷ Since s is in FFT representation, one may use (3.8) to compute ||s||²\n // 9: (s₁, s₂) ← invFFT(s) ▷ s₁ + s₂h = c mod (φ, q)\n // 10: s ← Compress(s₂, 8 · sbytelen - 328)\n // ▷ Remove 1 byte for the header, and 40 bytes for r\n // 11: while (s = ⊥)\n // 12: return sig = (r, s)\n abytes(msg, undefined, 'msg');\n abytes(sk, secretKeyCoder.bytesLen, 'secretKey');\n // One RNG stream drives both the public 40-byte nonce and the 48-byte sampler seed, so\n // deterministic rnd hooks make signatures deterministic for fixed secretKey/message inputs.\n const nonce = rnd(40);\n // Keep these raw 40-byte checks in sync with NONCELEN: Falcon's r <- {0,1}^320 nonce\n // feeds HashToPoint(r || m) and the public signature framing, so callback bugs must fail fast.\n abytes(nonce, 40, 'nonce');\n const hm = HashToPoint(nonce, msg); // 2: c ← HashToPoint(r||m, q, n)\n const seed = rnd(48);\n // Falcon implementations here use a fixed 48-byte sampler seed; reject callback bugs up front.\n abytes(seed, 48, 'seed');\n try {\n const [f, g, F] = secretKeyCoder.decode(sk);\n try {\n const G = completePrivate(f, g, F);\n const b00 = floatPoly.FFT(floatPoly.convSmall(g));\n const b01 = floatPoly.FFT(floatPoly.neg(floatPoly.convSmall(f)));\n const b10 = floatPoly.FFT(floatPoly.convSmall(G));\n const b11 = floatPoly.FFT(floatPoly.neg(floatPoly.convSmall(F)));\n const sampler = new FFSampler(logn, seed, b00, b01, b10, b11);\n const s2 = new Int16Array(N);\n try {\n while (true) {\n const { t0, t1 } = sampler.sample(hm);\n // t2 = b00*t0 + b10*t1\n const t2 = floatPoly.add(floatPoly.mul(t0, b00), floatPoly.mul(t1, b10));\n const t3 = floatPoly.mul(t0, b01); // t3 = b01*t0\n const t4 = floatPoly.iFFT(t2); // t4 = iFFT(tx)\n // t5 = iFFT(b11*t1 + ty)\n const t5 = floatPoly.iFFT(floatPoly.add(floatPoly.mul(t1, b11), t3));\n // Traverse imaginary in exact same order to avoid numerical instability\n const hn = N >> 1;\n let sqn = 0;\n for (let i = 0; i < hn; i++) {\n sqn += (hm[i] - (Math.round(t4[i].re) | 0)) ** 2;\n sqn += (hm[hn + i] - (Math.round(t4[i].im) | 0)) ** 2;\n const z = -Math.round(t5[i].re);\n sqn += z * z;\n s2[i] = z & 0xffff;\n const z2 = -Math.round(t5[i].im);\n sqn += z2 * z2;\n s2[i + hn] = z2 & 0xffff;\n }\n cleanCPoly(t0, t1, t2, t3, t4, t5);\n if (!(sqn <= L2BOUND[logn])) continue;\n // 10: s ← Compress(s₂, 8 · sbytelen - 328)\n // ▷ Remove 1 byte for the header, and 40 bytes for r\n const s2comp = compCoder(N).encode(s2);\n if (s2comp.length > maxLen) {\n cleanBytes(s2comp);\n continue;\n }\n return { s2: s2comp, nonce, msg } as TRet<SignatureRaw>;\n }\n } finally {\n cleanBytes(s2);\n sampler.destroy();\n cleanCPoly(b00, b01, b10, b11);\n cleanBytes(G);\n }\n } finally {\n cleanBytes(f, g, F);\n }\n } finally {\n cleanBytes(seed);\n }\n };\n\n // Raw helper: malformed encodings or wrong lengths still throw here; the public verify()/open()\n // wrappers decide whether to translate those failures into false or an exception.\n const verifyRaw = (\n pk: TArg<Uint8Array>,\n s2comp: TArg<Uint8Array>,\n nonce: TArg<Uint8Array>,\n msg: TArg<Uint8Array>\n ) => {\n // Algorithm 16: Verify(m, sig, pk, [β²])\n // (Page 45)\n // Require: A message m, a signature sig = (r, s), a public key pk = h ∈ Zq[x]/(φ), a bound [β²]\n // Ensure: Accept or reject\n // 1: c ← HashToPoint(r||m, q, n)\n // 2: s₂ ← Decompress(s, 8 · sbytelen - 328)\n // 3: if (s₂ = ⊥) then\n // 4: reject ▷ Reject invalid encodings\n // 5: s₁ ← c - s₂h mod q ▷ s₁ should be normalized between -q/2 and q/2\n // 6: if ||(s₁, s₂)||² < [β²] then\n // 7: accept\n // 8: else\n // 9: reject ▷ Reject signatures that are too long\n const s2 = compCoder(N).decode(s2comp); // 2: s₂ ← Decompress(s, 8 · sbytelen - 328)\n const c0 = HashToPoint(nonce, msg); // 1: c ← HashToPoint(r||m, q, n)\n const h = intPoly.toMontgomery(intPoly.ntt(publicKeyCoder.decode(pk)));\n const s1 = intPoly.intt(intPoly.mul(intPoly.ntt(signedCoder.decode(s2)), h));\n intPoly.sub(s1, c0); // 5: s₁ ← c - s₂h mod q ▷ s₁ should be normalized between -q/2 and q/2\n return intPoly.isShort(signedCoder.encode(s1), s2); // 6: if ||(s₁, s₂)||² < [β²] then\n };\n\n const info = Object.freeze({ type: 'falcon' });\n const keyLengths = Object.freeze({\n seed: 48,\n publicKey: publicKeyCoder.bytesLen,\n secretKey: secretKeyCoder.bytesLen,\n });\n // Falcon takes a sampler callback the other schemes do not, and rejects `context`\n // with its own message; both stay in the accepted set so the specific errors fire.\n const FALCON_SIG_OPT_KEYS = [...SIG_OPT_KEYS, 'random'] as const;\n // Noble exposes a 48-byte sampler-seed hook,\n // but Falcon still samples/encodes a separate 40-byte nonce per signature.\n const getRnd = (opts: TArg<FalconSigOpts> = {}): TRet<FalconRandom> => {\n // `context` stays in the accepted set so the specific \"not supported\" error below\n // still fires, rather than the generic unexpected-option one.\n opts = validateSigOpts(opts, FALCON_SIG_OPT_KEYS);\n if (opts.context !== undefined) throw new Error('context is not supported');\n if (opts.random !== undefined && typeof opts.random !== 'function')\n throw new TypeError('\"opts.random\" expected function, got type=' + typeof opts.random);\n if (opts.random !== undefined) return opts.random as TRet<FalconRandom>;\n if (opts.extraEntropy === undefined) return randomBytes;\n const seed = opts.extraEntropy === false ? new Uint8Array(48) : opts.extraEntropy;\n abytes(seed, 48, 'opts.extraEntropy');\n const drbg = rngAesCtrDrbg256(seed);\n return (len = 0) => drbg.randomBytes(len) as TRet<Uint8Array>;\n };\n const checkVerOpts = (opts: TArg<VerOpts> = {}) => {\n const normalized = validateVerOpts(opts);\n if (normalized.context !== undefined) throw new Error('context is not supported');\n };\n const tests = Object.freeze({\n publicKeyCoder: Object.freeze(publicKeyCoder),\n privateKeyCoder: Object.freeze(secretKeyCoder),\n maxS2Len: opts.maxS2Len,\n });\n // `signRand` documents only the sampler-seed input length;\n // detached/attached signatures still include their own 40-byte nonce.\n const attachedLengths = Object.freeze({ ...keyLengths, signRand: 48 });\n const lengths = opts.padded\n ? Object.freeze({ ...attachedLengths, signature: opts.sigLen })\n : attachedLengths;\n const keygen = (\n seed?: TArg<Uint8Array>\n ): TRet<{ publicKey: Uint8Array; secretKey: Uint8Array }> => {\n const randSeed = seed === undefined;\n if (randSeed) seed = randomBytes(48);\n abytes(seed!, 48, 'seed');\n const [f, g, F, _G, pub] = new NTRU(logn, seed!).generate();\n const sk = secretKeyCoder.encode([f, g, F]);\n const pk = publicKeyCoder.encode(pub);\n if (randSeed) cleanBytes(seed!);\n cleanBytes(f, g, F, _G);\n return { publicKey: pk, secretKey: sk } as TRet<{\n publicKey: Uint8Array;\n secretKey: Uint8Array;\n }>;\n };\n const getPublicKey = (sk: TArg<Uint8Array>): TRet<Uint8Array> => {\n abytes(sk, secretKeyCoder.bytesLen, 'secretKey');\n const [f, g, F] = secretKeyCoder.decode(sk);\n try {\n const h = computePublic(f, g);\n cleanBytes(f, g, F);\n return publicKeyCoder.encode(h) as TRet<Uint8Array>;\n } catch (e) {\n cleanBytes(f, g, F);\n throw e;\n }\n };\n const sign = (\n msg: TArg<Uint8Array>,\n sk: TArg<Uint8Array>,\n sigOpts: TArg<FalconSigOpts> = {}\n ): TRet<Uint8Array> => {\n const { s2, nonce } = signRaw(sk, msg, opts.maxS2Len, getRnd(sigOpts));\n return SignatureCoderDetached(logn).encode({ nonce, s2 });\n };\n /** Verify one detached Falcon signature.\n * Returns `false` for malformed detached signature encodings, non-canonical detached signatures,\n * and well-formed signatures that do not validate. Throws on malformed API argument types or\n * unsupported verification options.\n */\n const verify = (\n sig: TArg<Uint8Array>,\n msg: TArg<Uint8Array>,\n pk: TArg<Uint8Array>,\n verOpts: TArg<VerOpts> = {}\n ) => {\n checkVerOpts(verOpts);\n abytes(sig, undefined, 'signature');\n abytes(msg, undefined, 'msg');\n // Length/canonical public-key failures are decoded below and return false; only type is fatal.\n abytes(pk, undefined, 'publicKey');\n try {\n const { s2, nonce } = SignatureCoderDetached(logn).decode(sig);\n return verifyRaw(pk, s2, nonce, msg);\n } catch {\n return false;\n }\n };\n const attached: TRet<FalconAttached> = Object.freeze({\n info,\n lengths: attachedLengths,\n keygen,\n getPublicKey,\n seal(msg: TArg<Uint8Array>, sk: TArg<Uint8Array>, sigOpts: TArg<FalconSigOpts> = {}) {\n const { s2, nonce } = signRaw(sk, msg, opts.maxS2Len, getRnd(sigOpts));\n return SignatureCoder.encode({ msg, nonce, s2 });\n },\n open(sig: TArg<Uint8Array>, pk: TArg<Uint8Array>, verOpts: TArg<VerOpts> = {}) {\n checkVerOpts(verOpts);\n // Wrong argument types are caller bugs and must stay TypeErrors; only what happens\n // after this is untrusted input. Detached verify() type-checks the public key the same\n // way, so open() does too: a wrong type is fatal, and a malformed (wrong-length or\n // non-canonical) key folds into the single rejection below rather than leaking a raw\n // codec error, exactly as detached verify() folds it into `false`.\n abytes(sig, undefined, 'signature');\n abytes(pk, undefined, 'publicKey');\n // Decode and verify owned snapshots. Apart from keeping the authenticated result stable\n // after open() returns, this ensures every verification step observes the same bytes when\n // an input is backed by SharedArrayBuffer or has subclass-overridden view methods.\n const ownedSig = copyBytes(sig);\n const ownedPk = copyBytes(pk);\n // Decode failures and malformed-key failures are rejected signatures, not internal\n // faults. Letting the codec's own errors out gave a caller handling untrusted input\n // several different messages for one corrupt byte, including \"end of buffer: len=2\n // buf=0 lastByte=undefined\", which reads as a library bug. Detached verify already\n // treats every such failure uniformly; open() collapses them into one Error (the\n // original preserved as `cause`). A well-formed signature that simply does not\n // validate falls through to the same message with no cause.\n try {\n let verifiedMsg: Uint8Array | undefined;\n try {\n const { s2, nonce, msg } = SignatureCoder.decode(ownedSig);\n if (verifyRaw(ownedPk, s2, nonce, msg)) verifiedMsg = msg;\n } catch (cause) {\n throw new Error('invalid signature', { cause });\n }\n if (verifiedMsg === undefined) throw new Error('invalid signature');\n // Do not retain or expose the full attached-signature allocation through `.buffer`.\n return copyBytes(verifiedMsg);\n } finally {\n cleanBytes(ownedSig, ownedPk);\n }\n },\n });\n // PATCH (starknet.js-workshop pureTS): signing / verification of an externally computed hash\n // point, mirroring ml-dsa `internal` + `externalMu`. See PATCH.md.\n const INTERNAL_MAX_ITERATIONS = 1000;\n const checkHashPoint = (hashPoint: TArg<Uint16Array>): void => {\n if (!(hashPoint instanceof Uint16Array) || hashPoint.length !== N)\n throw new Error(`hashPoint: expected Uint16Array(${N})`);\n for (let i = 0; i < N; i++)\n if (hashPoint[i] >= Q) throw new Error('hashPoint: coefficient out of range');\n };\n const internal: TRet<FalconInternal> = Object.freeze({\n sign(\n hashPoint: TArg<Uint16Array>,\n sk: TArg<Uint8Array>,\n internalOpts: TArg<FalconInternalSignOpts> = {}\n ): TRet<Int16Array> {\n checkHashPoint(hashPoint);\n abytes(sk, secretKeyCoder.bytesLen, 'secretKey');\n const rnd = (internalOpts.random ?? randomBytes) as FalconRandom;\n const maxIterations = internalOpts.maxIterations ?? INTERNAL_MAX_ITERATIONS;\n const hm = Uint16Array.from(hashPoint) as IPoly;\n const seed = rnd(48);\n abytes(seed, 48, 'seed');\n try {\n const [f, g, F] = secretKeyCoder.decode(sk);\n try {\n const G = completePrivate(f, g, F);\n const b00 = floatPoly.FFT(floatPoly.convSmall(g));\n const b01 = floatPoly.FFT(floatPoly.neg(floatPoly.convSmall(f)));\n const b10 = floatPoly.FFT(floatPoly.convSmall(G));\n const b11 = floatPoly.FFT(floatPoly.neg(floatPoly.convSmall(F)));\n const sampler = new FFSampler(logn, seed, b00, b01, b10, b11);\n const s2 = new Int16Array(N);\n try {\n for (let iteration = 0; iteration < maxIterations; iteration++) {\n const { t0, t1 } = sampler.sample(hm);\n const t2 = floatPoly.add(floatPoly.mul(t0, b00), floatPoly.mul(t1, b10));\n const t3 = floatPoly.mul(t0, b01);\n const t4 = floatPoly.iFFT(t2);\n const t5 = floatPoly.iFFT(floatPoly.add(floatPoly.mul(t1, b11), t3));\n const hn = N >> 1;\n let sqn = 0;\n for (let i = 0; i < hn; i++) {\n sqn += (hm[i] - (Math.round(t4[i].re) | 0)) ** 2;\n sqn += (hm[hn + i] - (Math.round(t4[i].im) | 0)) ** 2;\n const z = -Math.round(t5[i].re);\n sqn += z * z;\n s2[i] = z & 0xffff;\n const z2 = -Math.round(t5[i].im);\n sqn += z2 * z2;\n s2[i + hn] = z2 & 0xffff;\n }\n cleanCPoly(t0, t1, t2, t3, t4, t5);\n if (sqn <= L2BOUND[logn]) return s2.slice() as TRet<Int16Array>;\n }\n throw new Error('internal.sign: no short signature found within the iteration cap');\n } finally {\n cleanBytes(s2);\n sampler.destroy();\n cleanCPoly(b00, b01, b10, b11);\n cleanBytes(G);\n }\n } finally {\n cleanBytes(f, g, F);\n }\n } finally {\n cleanBytes(seed);\n }\n },\n verify(\n s2: TArg<Int16Array>,\n hashPoint: TArg<Uint16Array>,\n pk: TArg<Uint8Array>\n ): boolean {\n checkHashPoint(hashPoint);\n if (!(s2 instanceof Int16Array) || s2.length !== N)\n throw new Error(`s2: expected Int16Array(${N})`);\n abytes(pk, publicKeyCoder.bytesLen, 'publicKey');\n const h = intPoly.toMontgomery(intPoly.ntt(publicKeyCoder.decode(pk)));\n const s1 = intPoly.intt(intPoly.mul(intPoly.ntt(signedCoder.decode(s2 as Int16Array)), h));\n intPoly.sub(s1, hashPoint as IPoly);\n return intPoly.isShort(signedCoder.encode(s1), s2 as Int16Array);\n },\n });\n const res = {\n info,\n lengths,\n attached,\n keygen,\n getPublicKey,\n sign,\n verify,\n internal,\n };\n (res as any).__test = tests;\n return Object.freeze(res);\n}\n\nconst falcon512opts = {\n N: 512,\n // Keep the mode an own property: omitted config fields must not inherit from Object.prototype.\n padded: false,\n // Table 3.3 fixed padded detached bytes, including the detached header byte and 40-byte nonce.\n sigLen: 666,\n fgBits: 6,\n FGBits: 8,\n // Compressed-s payload bytes only, excluding the detached header byte and 40-byte nonce.\n paddedLen: 625,\n};\n/**\n * Falcon-512 detached-signature API with the attached helper exposed as `.attached`.\n * @example\n * Generate a Falcon-512 keypair and verify one detached signature.\n * ```ts\n * const { secretKey, publicKey } = falcon512.keygen();\n * const msg = new Uint8Array([1, 2, 3]);\n * const sig = falcon512.sign(msg, secretKey);\n * falcon512.verify(sig, msg, publicKey);\n * ```\n */\nexport const falcon512: TRet<Falcon> = /* @__PURE__ */ (() =>\n genFalcon({ ...falcon512opts, maxS2Len: 711 }))();\n/**\n * Falcon-512 padded detached-signature API with the attached helper exposed as `.attached`.\n * @example\n * Generate a Falcon-512 padded keypair and verify one detached signature.\n * ```ts\n * const { secretKey, publicKey } = falcon512padded.keygen();\n * const msg = new Uint8Array([1, 2, 3]);\n * const sig = falcon512padded.sign(msg, secretKey);\n * falcon512padded.verify(sig, msg, publicKey);\n * ```\n */\nexport const falcon512padded: TRet<Falcon> = /* @__PURE__ */ (() =>\n genFalcon({\n ...falcon512opts,\n padded: true,\n maxS2Len: 625,\n }))();\n\nconst falcon1024opts = {\n N: 1024,\n padded: false,\n // Table 3.3 fixed padded detached bytes, including the detached header byte and 40-byte nonce.\n sigLen: 1280,\n fgBits: 5,\n FGBits: 8,\n // Compressed-s payload bytes only, excluding the detached header byte and 40-byte nonce.\n paddedLen: 1239,\n};\n/**\n * Falcon-1024 detached-signature API with the attached helper exposed as `.attached`.\n * @example\n * Generate a Falcon-1024 keypair and verify one detached signature.\n * ```ts\n * const { secretKey, publicKey } = falcon1024.keygen();\n * const msg = new Uint8Array([1, 2, 3]);\n * const sig = falcon1024.sign(msg, secretKey);\n * falcon1024.verify(sig, msg, publicKey);\n * ```\n */\nexport const falcon1024: TRet<Falcon> = /* @__PURE__ */ (() =>\n genFalcon({\n ...falcon1024opts,\n maxS2Len: 1421,\n }))();\n/**\n * Falcon-1024 padded detached-signature API with the attached helper exposed as `.attached`.\n * @example\n * Generate a Falcon-1024 padded keypair and verify one detached signature.\n * ```ts\n * const { secretKey, publicKey } = falcon1024padded.keygen();\n * const msg = new Uint8Array([1, 2, 3]);\n * const sig = falcon1024padded.sign(msg, secretKey);\n * falcon1024padded.verify(sig, msg, publicKey);\n * ```\n */\nexport const falcon1024padded: TRet<Falcon> = /* @__PURE__ */ (() =>\n genFalcon({\n ...falcon1024opts,\n padded: true,\n maxS2Len: 1239,\n }))();\n\n// NOTE: for tests only, don't use\nexport const __tests: any = /* @__PURE__ */ (() =>\n Object.freeze({\n BNORM_MAX,\n COMPLEX_ROOTS,\n Float,\n INV_SIGMA,\n SIGMA_MIN,\n getFloatPoly,\n ldlFFT,\n cleanCPoly,\n falcon512: (falcon512 as any).__test,\n falcon512padded: (falcon512padded as any).__test,\n falcon1024: (falcon1024 as any).__test,\n falcon1024padded: (falcon1024padded as any).__test,\n }))();\n","/* eslint-disable -- vendored copy of @noble/post-quantum 0.7.1, kept as is: see PATCH.md */\n/**\n * Internal methods for lattice-based ML-KEM and ML-DSA.\n * @module\n */\n/*! noble-post-quantum - MIT License (c) 2024 Paul Miller (paulmillr.com) */\nimport { FFTCore, reverseBits } from '@noble/curves/abstract/fft.js';\nimport { shake128, shake256 } from '@noble/hashes/sha3.js';\nimport type { TypedArray } from '@noble/hashes/utils.js';\nimport {\n type BytesCoderLen,\n cleanBytes,\n type Coder,\n getMask,\n type TArg,\n type TRet,\n} from './utils';\n\n/** Extendable-output reader used by the CRYSTALS implementations. */\nexport type XOF = (\n seed: Uint8Array,\n blockLen?: number\n) => {\n /**\n * Read diagnostic counters for the current XOF session.\n * @returns Current call and XOF block counters.\n */\n stats: () => { calls: number; xofs: number };\n /**\n * Select one `(x, y)` coordinate pair and get a block reader for it.\n * Only one coordinate stream is live at a time: a later `get(...)` call rebinds the shared\n * SHAKE state and invalidates older readers.\n * Each squeeze aliases one mutable internal output buffer, so callers must copy blocks they\n * want to retain before the next read.\n * @param x - First matrix coordinate.\n * @param y - Second matrix coordinate.\n * @returns Lazy block reader for that coordinate pair.\n */\n get: (x: number, y: number) => () => Uint8Array; // return block aligned to blockLen and 3\n /** Wipe any buffered state once the reader is no longer needed. */\n clean: () => void;\n};\n\n/** CRYSTALS (ml-kem, ml-dsa) options */\n/** Shared polynomial and NTT parameters for CRYSTALS algorithms. */\nexport type CrystalOpts<T extends TypedArray> = {\n /**\n * Allocate one zeroed polynomial/vector container.\n * @param n - Number of coefficients to allocate.\n * @returns Fresh typed container.\n */\n newPoly: TypedCons<T>;\n /** Polynomial size, typically `256`. */\n N: number;\n /** Prime modulus used for all coefficient arithmetic. */\n Q: number;\n /** Inverse transform normalization factor:\n * `256**-1 mod q` for Dilithium, `128**-1 mod q` for Kyber.\n */\n F: number;\n /** Principal root of unity for the transform domain. */\n ROOT_OF_UNITY: number;\n /** Number of bits used for bit-reversal ordering. */\n brvBits: number;\n /** `true` for Kyber/ML-KEM mode, `false` for Dilithium/ML-DSA mode. */\n isKyber: boolean;\n};\n\n/** Constructor function for typed polynomial containers. */\nexport type TypedCons<T extends TypedArray> = (n: number) => T;\n\ntype Crystals<T extends TypedArray> = {\n mod: (a: number, modulo?: number) => number;\n smod: (a: number, modulo?: number) => number;\n nttZetas: T;\n NTT: {\n /**\n * Forward transform in place. Mutates and returns `r`.\n * Kyber-mode input coefficients must already use canonical representatives in `[0, Q)`.\n */\n encode: (r: T) => T;\n /**\n * Inverse transform in place. Mutates and returns `r`.\n * Kyber-mode input coefficients must already use canonical representatives in `[0, Q)`.\n */\n decode: (r: T) => T;\n };\n bitsCoder: (d: number, c: Coder<number, number>) => BytesCoderLen<T>;\n};\n\n/**\n * Creates shared modular arithmetic, NTT, and packing helpers for CRYSTALS schemes.\n * @param opts - Polynomial and transform parameters. See {@link CrystalOpts}.\n * @returns CRYSTALS arithmetic and encoding helpers.\n * @example\n * Create shared modular arithmetic and NTT helpers for a CRYSTALS parameter set.\n * ```ts\n * const crystals = genCrystals({\n * newPoly: (n) => new Uint16Array(n),\n * N: 256,\n * Q: 3329,\n * F: 3303,\n * ROOT_OF_UNITY: 17,\n * brvBits: 7,\n * isKyber: true,\n * });\n * const reduced = crystals.mod(-1);\n * ```\n */\nexport const genCrystals = <T extends TypedArray>(opts: CrystalOpts<T>): TRet<Crystals<T>> => {\n // isKyber: true means Kyber, false means Dilithium\n const { newPoly, N, Q, F, ROOT_OF_UNITY, brvBits, isKyber } = opts;\n // Normalize JS `%` into the canonical Z_m representative `[0, modulo-1]` expected by\n // FIPS 203 §2.3 / FIPS 204 §2.3 before downstream mod-q arithmetic.\n const mod = (a: number, modulo = Q): number => {\n const result = (a % modulo) | 0;\n return (result >= 0 ? result | 0 : (modulo + result) | 0) | 0;\n };\n // FIPS 204 §7.4 uses the centered `mod ±` representative for low bits, keeping the\n // positive midpoint when `modulo` is even.\n // Center to `[-floor((modulo-1)/2), floor(modulo/2)]`.\n const smod = (a: number, modulo = Q): number => {\n const r = mod(a, modulo) | 0;\n return (r > modulo >> 1 ? (r - modulo) | 0 : r) | 0;\n };\n // Kyber uses the FIPS 203 Appendix A `BitRev_7` table here via the first 128 entries, while\n // Dilithium uses the FIPS 204 §7.5 / Appendix B `BitRev_8` zetas table over all 256 entries.\n function getZettas() {\n const out = newPoly(N);\n for (let i = 0; i < N; i++) {\n const b = reverseBits(i, brvBits);\n const p = BigInt(ROOT_OF_UNITY) ** BigInt(b) % BigInt(Q);\n out[i] = Number(p) | 0;\n }\n return out;\n }\n const nttZetas = getZettas();\n\n // Number-Theoretic Transform\n // Explained: https://electricdusk.com/ntt.html\n\n // Kyber has slightly different params, since there is no 512th primitive root of unity mod q,\n // only 256th primitive root of unity mod. Which also complicates MultiplyNTT.\n\n const inv = (_a: number) => {\n throw new Error('not implemented');\n };\n // ML-KEM (Kyber) polynomials always enter the transform reduced to [0, Q), so add/sub only\n // need one conditional correction instead of `%`; measured ~20% faster NTT there.\n // ML-DSA keeps the generic mod() path on purpose: its first forward stage sees centered\n // (negative) coefficients, and `sub(a, t)` can drop below -Q (t is a mul output in [0, Q)),\n // so a single correction is not enough. A guarded fast path with mod() fallback was measured\n // slower than plain `%` for the 23-bit Q (V8 int32 modulo is one div; the branches lose).\n const field = isKyber\n ? {\n add: (a: number, b: number) => {\n const r = (a + b) | 0;\n return r >= Q ? (r - Q) | 0 : r;\n },\n sub: (a: number, b: number) => {\n const r = (a - b) | 0;\n return r < 0 ? (r + Q) | 0 : r;\n },\n mul: (a: number, b: number) => mod((a | 0) * (b | 0)) | 0,\n inv,\n }\n : {\n add: (a: number, b: number) => mod((a | 0) + (b | 0)) | 0,\n sub: (a: number, b: number) => mod((a | 0) - (b | 0)) | 0,\n mul: (a: number, b: number) => mod((a | 0) * (b | 0)) | 0,\n inv,\n };\n const nttOpts = {\n N,\n roots: nttZetas as any,\n invertButterflies: true,\n skipStages: isKyber ? 1 : 0,\n brp: false,\n };\n const dif = FFTCore(field, { dit: false, ...nttOpts });\n const dit = FFTCore(field, { dit: true, ...nttOpts });\n const NTT = {\n encode: (r: T): T => {\n return dif(r) as any;\n },\n decode: (r: T): T => {\n dit(r as any);\n // The inverse-NTT normalization factor is family-specific: FIPS 203 Algorithm 10 line 14\n // uses `128^-1 mod q` for Kyber, while FIPS 204 Algorithm 42 lines 21-23 use `256^-1 mod q`.\n // kyber uses 128 here, because brv && stuff\n for (let i = 0; i < r.length; i++) r[i] = mod(F * r[i]);\n return r;\n },\n };\n // Pack one little-endian `d`-bit word per coefficient, matching FIPS 203 ByteEncode /\n // ByteDecode and the FIPS 204 BitsToBytes-based polynomial packing helpers.\n const bitsCoder = (d: number, c: Coder<number, number>): TRet<BytesCoderLen<T>> => {\n // Validate the carry shape once: JS bitwise operations silently truncate wider accumulators.\n for (let i = 0, bufLen = 0; i < N; i++) {\n bufLen += d;\n if (bufLen > 32) getMask(bufLen);\n bufLen %= 8;\n }\n const mask = getMask(d);\n const bytesLen = d * (N / 8);\n return {\n bytesLen,\n encode: (poly_: TArg<T>): TRet<Uint8Array> => {\n const poly = poly_ as T;\n const r = new Uint8Array(bytesLen);\n for (let i = 0, buf = 0, bufLen = 0, pos = 0; i < poly.length; i++) {\n buf |= (c.encode(poly[i]) & mask) << bufLen;\n bufLen += d;\n // Take the low byte directly: `& 0xff` matches the previous getMask(bufLen) result\n // after Uint8Array truncation, without a validated function call per output byte.\n for (; bufLen >= 8; bufLen -= 8, buf >>= 8) r[pos++] = buf & 0xff;\n }\n return r as TRet<Uint8Array>;\n },\n decode: (bytes: TArg<Uint8Array>): TRet<T> => {\n const r = newPoly(N);\n for (let i = 0, buf = 0, bufLen = 0, pos = 0; i < bytes.length; i++) {\n buf |= bytes[i] << bufLen;\n bufLen += 8;\n for (; bufLen >= d; bufLen -= d, buf >>= d) r[pos++] = c.decode(buf & mask);\n }\n return r as TRet<T>;\n },\n } as TRet<BytesCoderLen<T>>;\n };\n\n return {\n mod,\n smod,\n nttZetas: nttZetas as TRet<T>,\n NTT: {\n encode: (r: TArg<T>): TRet<T> => NTT.encode(r as T) as TRet<T>,\n decode: (r: TArg<T>): TRet<T> => NTT.decode(r as T) as TRet<T>,\n },\n bitsCoder: bitsCoder as TRet<Crystals<T>>['bitsCoder'],\n };\n};\n\nconst createXofShake =\n (shake: typeof shake128): TRet<XOF> =>\n (seed: TArg<Uint8Array>, blockLen?: number) => {\n if (!blockLen) blockLen = shake.blockLen;\n // Optimizations that won't mater:\n // - cached seed update (two .update(), on start and on the end)\n // - another cache which cloned into working copy\n\n // Faster than multiple updates, since seed less than blockLen\n const _seed = new Uint8Array(seed.length + 2);\n _seed.set(seed);\n const seedLen = seed.length;\n const buf = new Uint8Array(blockLen); // == shake128.blockLen\n let h = shake.create({});\n let calls = 0;\n let xofs = 0;\n return {\n stats: () => ({ calls, xofs }),\n get: (x: number, y: number) => {\n // Rebind to `seed || x || y` so callers can implement the spec's per-coordinate\n // SHAKE inputs like `rho || j || i` and `rho || IntegerToBytes(counter, 2)`.\n _seed[seedLen + 0] = x;\n _seed[seedLen + 1] = y;\n h.destroy();\n h = shake.create({}).update(_seed);\n calls++;\n return () => {\n xofs++;\n return h.xofInto(buf) as TRet<Uint8Array>;\n };\n },\n clean: () => {\n h.destroy();\n cleanBytes(buf, _seed);\n },\n };\n };\n\n/**\n * SHAKE128-based extendable-output reader factory used by ML-KEM.\n * `get(x, y)` selects one coordinate pair at a time; calling it again invalidates previously\n * returned readers, and each squeeze reuses one mutable internal output buffer.\n * @param seed - Seed bytes for the reader.\n * @param blockLen - Optional output block length.\n * @returns Stateful XOF reader.\n * @example\n * Build the ML-KEM SHAKE128 matrix expander and read one block.\n * ```ts\n * import { randomBytes } from '@noble/post-quantum/utils.js';\n * import { XOF128 } from '@noble/post-quantum/_crystals.js';\n * const reader = XOF128(randomBytes(32));\n * const block = reader.get(0, 0)();\n * ```\n */\nexport const XOF128: TRet<XOF> = /* @__PURE__ */ createXofShake(shake128);\n/**\n * SHAKE256-based extendable-output reader factory used by ML-DSA.\n * `get(x, y)` appends raw one-byte coordinates to the seed, invalidates previously returned\n * readers, and reuses one mutable internal output buffer for each squeeze.\n * @param seed - Seed bytes for the reader.\n * @param blockLen - Optional output block length.\n * @returns Stateful XOF reader.\n * @example\n * Build the ML-DSA SHAKE256 coefficient expander and read one block.\n * ```ts\n * import { randomBytes } from '@noble/post-quantum/utils.js';\n * import { XOF256 } from '@noble/post-quantum/_crystals.js';\n * const reader = XOF256(randomBytes(32));\n * const block = reader.get(0, 0)();\n * ```\n */\nexport const XOF256: TRet<XOF> = /* @__PURE__ */ createXofShake(shake256);\n","/* eslint-disable -- vendored copy of @noble/post-quantum 0.7.1, kept as is: see PATCH.md */\n/**\n * Utilities for hex, bytearray and number handling.\n * @module\n */\n/*! noble-post-quantum - MIT License (c) 2024 Paul Miller (paulmillr.com) */\nimport {\n type CHash,\n type TypedArray,\n abytes,\n abytes as abytes_,\n ahash as ahash_,\n anumber,\n bytesToHex,\n concatBytes,\n isBytes,\n isLE,\n randomBytes as randb,\n} from '@noble/hashes/utils.js';\n/**\n * Bytes API type helpers for old + new TypeScript.\n *\n * TS 5.6 has `Uint8Array`, while TS 5.9+ made it generic `Uint8Array<ArrayBuffer>`.\n * We can't use specific return type, because TS 5.6 will error.\n * We can't use generic return type, because most TS 5.9 software will expect specific type.\n *\n * Maps typed-array input leaves to broad forms.\n * These are compatibility adapters, not ownership guarantees.\n *\n * - `TArg` keeps byte inputs broad.\n * - `TRet` marks byte outputs for TS 5.6 and TS 5.9+ compatibility.\n */\nexport type TypedArg<T> = T extends BigInt64Array\n ? BigInt64Array\n : T extends BigUint64Array\n ? BigUint64Array\n : T extends Float32Array\n ? Float32Array\n : T extends Float64Array\n ? Float64Array\n : T extends Int16Array\n ? Int16Array\n : T extends Int32Array\n ? Int32Array\n : T extends Int8Array\n ? Int8Array\n : T extends Uint16Array\n ? Uint16Array\n : T extends Uint32Array\n ? Uint32Array\n : T extends Uint8ClampedArray\n ? Uint8ClampedArray\n : T extends Uint8Array\n ? Uint8Array\n : never;\n/** Maps typed-array output leaves to narrow TS-compatible forms. */\nexport type TypedRet<T> = T extends BigInt64Array\n ? ReturnType<typeof BigInt64Array.of>\n : T extends BigUint64Array\n ? ReturnType<typeof BigUint64Array.of>\n : T extends Float32Array\n ? ReturnType<typeof Float32Array.of>\n : T extends Float64Array\n ? ReturnType<typeof Float64Array.of>\n : T extends Int16Array\n ? ReturnType<typeof Int16Array.of>\n : T extends Int32Array\n ? ReturnType<typeof Int32Array.of>\n : T extends Int8Array\n ? ReturnType<typeof Int8Array.of>\n : T extends Uint16Array\n ? ReturnType<typeof Uint16Array.of>\n : T extends Uint32Array\n ? ReturnType<typeof Uint32Array.of>\n : T extends Uint8ClampedArray\n ? ReturnType<typeof Uint8ClampedArray.of>\n : T extends Uint8Array\n ? ReturnType<typeof Uint8Array.of>\n : never;\n/** Recursively adapts byte-carrying API input types. See {@link TypedArg}. */\nexport type TArg<T> =\n | T\n | ([TypedArg<T>] extends [never]\n ? T extends (...args: infer A) => infer R\n ? ((...args: { [K in keyof A]: TRet<A[K]> }) => TArg<R>) & {\n [K in keyof T]: T[K] extends (...args: any) => any ? T[K] : TArg<T[K]>;\n }\n : T extends [infer A, ...infer R]\n ? [TArg<A>, ...{ [K in keyof R]: TArg<R[K]> }]\n : T extends readonly [infer A, ...infer R]\n ? readonly [TArg<A>, ...{ [K in keyof R]: TArg<R[K]> }]\n : T extends (infer A)[]\n ? TArg<A>[]\n : T extends readonly (infer A)[]\n ? readonly TArg<A>[]\n : T extends Promise<infer A>\n ? Promise<TArg<A>>\n : T extends object\n ? { [K in keyof T]: TArg<T[K]> }\n : T\n : TypedArg<T>);\n/** Recursively adapts byte-carrying API output types. See {@link TypedArg}. */\nexport type TRet<T> = T extends unknown\n ? T &\n ([TypedRet<T>] extends [never]\n ? T extends (...args: infer A) => infer R\n ? ((...args: { [K in keyof A]: TArg<A[K]> }) => TRet<R>) & {\n [K in keyof T]: T[K] extends (...args: any) => any ? T[K] : TRet<T[K]>;\n }\n : T extends [infer A, ...infer R]\n ? [TRet<A>, ...{ [K in keyof R]: TRet<R[K]> }]\n : T extends readonly [infer A, ...infer R]\n ? readonly [TRet<A>, ...{ [K in keyof R]: TRet<R[K]> }]\n : T extends (infer A)[]\n ? TRet<A>[]\n : T extends readonly (infer A)[]\n ? readonly TRet<A>[]\n : T extends Promise<infer A>\n ? Promise<TRet<A>>\n : T extends object\n ? { [K in keyof T]: TRet<T[K]> }\n : T\n : TypedRet<T>)\n : never;\n/**\n * Asserts that a value is a byte array and optionally checks its length.\n * Returns the original reference unchanged on success, and currently also accepts Node `Buffer`\n * values through the upstream validator.\n * This helper throws on malformed input, so APIs that must return `false` need to guard lengths\n * before decoding or before calling it.\n * @example\n * Validate that a value is a byte array with the expected length.\n * ```ts\n * abytes(new Uint8Array([1]), 1);\n * ```\n */\nconst abytesDoc: typeof abytes = abytes;\nexport { abytesDoc as abytes };\n/**\n * Concatenates byte arrays into a new `Uint8Array`.\n * Zero arguments return an empty `Uint8Array`.\n * Invalid segments throw before allocation because each argument is validated first.\n * @example\n * Concatenate two byte arrays into one result.\n * ```ts\n * concatBytes(new Uint8Array([1]), new Uint8Array([2]));\n * ```\n */\nconst concatBytesDoc: typeof concatBytes = concatBytes;\nexport { concatBytesDoc as concatBytes };\n/**\n * Returns cryptographically secure random bytes.\n * Requires `globalThis.crypto.getRandomValues` and throws if that API is unavailable.\n * `bytesLength` is validated by the upstream helper as a non-negative integer before allocation,\n * so negative and fractional values both throw instead of truncating through JS `ToIndex`.\n * @param bytesLength - Number of random bytes to generate.\n * @returns Fresh random bytes.\n * @example\n * Generate a fresh random seed.\n * ```ts\n * const seed = randomBytes(4);\n * ```\n */\nexport const randomBytes: typeof randb = randb;\n\nexport function aarray<T>(\n item: unknown,\n title: string,\n inner: (elm: T, title: string) => void = () => {}\n): T[] {\n if (!Array.isArray(item))\n throw new TypeError(`\"${title}\" expected array, got type=${typeof item}`);\n for (let i = 0; i < item.length; i++) inner(item[i], `${title}[${i}]`);\n return item;\n}\n\nexport function aobject<T extends object>(value: unknown, title = 'object'): T {\n if (value === null || typeof value !== 'object' || Array.isArray(value))\n throw new TypeError(\n title === 'object'\n ? 'expected valid options object'\n : `\"${title}\" expected object, got type=${typeof value}`\n );\n return value as T;\n}\n\n/**\n * Compares two byte arrays in a length-constant way for equal lengths.\n * Inputs are validated as byte arrays; unequal lengths return `false` immediately.\n * @param a - First byte array.\n * @param b - Second byte array.\n * @returns Whether both arrays contain the same bytes.\n * @example\n * Compare two byte arrays for equality.\n * ```ts\n * equalBytes(new Uint8Array([1]), new Uint8Array([1]));\n * ```\n */\nexport function equalBytes(a: TArg<Uint8Array>, b: TArg<Uint8Array>): boolean {\n a = abytes(a);\n b = abytes(b);\n if (a.length !== b.length) return false;\n let diff = 0;\n for (let i = 0; i < a.length; i++) diff |= a[i] ^ b[i];\n return diff === 0;\n}\n\n/**\n * Copies bytes into a fresh `Uint8Array`.\n * Returns a detached plain `Uint8Array` after validating that the input is real bytes.\n * @param bytes - Source bytes.\n * @returns Copy of the input bytes.\n * @example\n * Copy bytes into a fresh array.\n * ```ts\n * copyBytes(new Uint8Array([1, 2]));\n * ```\n */\nexport function copyBytes(bytes: TArg<Uint8Array>): TRet<Uint8Array> {\n // The typed-array constructor copies a typed-array source through its internal byte storage.\n // Unlike `Uint8Array.from`, it does not invoke a subclass-overridden iterator. Keep the explicit\n // validation because the constructor itself would also accept arrays and other typed arrays.\n return new Uint8Array(abytes(bytes)) as TRet<Uint8Array>;\n}\n\n/**\n * Byte-swaps each 64-bit lane in place.\n * Falcon's exact binary64 tables are stored as little-endian byte payloads, so BE runtimes need\n * this boundary helper before aliasing them as host `Float64Array` lanes.\n * @param arr - Byte buffer whose length is a multiple of 8.\n * @returns The same buffer after in-place 64-bit lane byte swaps.\n * @example\n * Byte-swap one 64-bit lane in place.\n * ```ts\n * byteSwap64(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]));\n * ```\n */\nexport function byteSwap64<T extends ArrayBufferView>(arr: T): T {\n const bytes = new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength);\n for (let i = 0; i < bytes.length; i += 8) {\n const a0 = bytes[i + 0];\n const a1 = bytes[i + 1];\n const a2 = bytes[i + 2];\n const a3 = bytes[i + 3];\n bytes[i + 0] = bytes[i + 7];\n bytes[i + 1] = bytes[i + 6];\n bytes[i + 2] = bytes[i + 5];\n bytes[i + 3] = bytes[i + 4];\n bytes[i + 4] = a3;\n bytes[i + 5] = a2;\n bytes[i + 6] = a1;\n bytes[i + 7] = a0;\n }\n return arr;\n}\n/**\n * Byte-swaps 64-bit lanes on big-endian runtimes and returns the input unchanged on little-endian.\n * This keeps Falcon's binary64 tables in canonical little-endian order before aliasing them as\n * `Float64Array` lanes on the current host.\n * @param arr - Buffer to pass through or swap in place.\n * @returns The same buffer, normalized for Falcon's little-endian table layout.\n * @example\n * Normalize one host-endian buffer for Falcon's float tables.\n * ```ts\n * baswap64If(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]));\n * ```\n */\nexport const baswap64If: <T extends ArrayBufferView>(arr: T) => T = isLE\n ? (arr) => arr\n : byteSwap64;\n\n/** Shared key-generation surface for signers and KEMs. */\nexport type CryptoKeys = {\n /** Optional metadata about the algorithm family or variant. */\n info?: { type?: string };\n /** Public byte lengths for the exported key material. */\n lengths: { seed?: number; publicKey?: number; secretKey?: number };\n /**\n * Generate one secret/public keypair.\n * @param seed - Optional seed bytes for deterministic key generation.\n * @returns Fresh secret/public keypair.\n */\n keygen: (seed?: TArg<Uint8Array>) => {\n secretKey: TRet<Uint8Array>;\n publicKey: TRet<Uint8Array>;\n };\n /**\n * Derive one public key from a secret key.\n * @param secretKey - Secret key bytes.\n * @returns Public key bytes.\n */\n getPublicKey: (secretKey: TArg<Uint8Array>) => TRet<Uint8Array>;\n};\n\n/** Verification options shared by the signature APIs. */\nexport type VerOpts = {\n /** Optional application-defined context string. */\n context?: Uint8Array;\n};\n/** Signing options shared by the signature APIs. */\nexport type SigOpts = VerOpts & {\n // Compatibility with @noble/curves: false to disable, enabled by default, user can pass U8A\n /** Optional extra entropy or `false` to disable randomized signing. */\n extraEntropy?: Uint8Array | false;\n};\n\n/**\n * Validates that an options bag is a plain object.\n * @param opts - Options object to validate.\n * @throws On wrong argument types. {@link TypeError}\n * @example\n * Validate that an options bag is a plain object.\n * ```ts\n * validateOpts({});\n * ```\n */\nexport function validateOpts(opts: object): void {\n // Arrays silently passed here before, but these call sites expect named option-bag fields.\n if (isBytes(opts)) throw new TypeError('\"opts\" expected object, got Uint8Array');\n aobject(opts, 'opts');\n const proto = Object.getPrototypeOf(opts);\n // Options are security parameters, not general class instances. Restricting the bag to own\n // properties prevents values injected through Object.prototype (or a custom shared prototype)\n // from silently changing signing behavior. Null-prototype records remain supported.\n if (proto !== null && proto !== Object.prototype)\n throw new TypeError('\"opts\" expected a plain object');\n}\n\n// Frozen because they are exported: an unfrozen array export lets anything in the\n// process push a key onto the accepted set and silently re-open exactly the hole this\n// validation closes.\n/** Keys accepted by `verify`. */\nexport const VER_OPT_KEYS: readonly ['context'] = /* @__PURE__ */ Object.freeze([\n 'context',\n] as const);\n/** Keys accepted by `sign`. */\nexport const SIG_OPT_KEYS: readonly ['context', 'extraEntropy'] = /* @__PURE__ */ Object.freeze([\n 'context',\n 'extraEntropy',\n] as const);\n\n/**\n * Rejects option keys the caller did not mean to set.\n *\n * Validating the types of known keys while ignoring unknown ones makes a typo\n * indistinguishable from an omission, and for these options an omission is a\n * security downgrade rather than a no-op: `{ ctx }` instead of `{ context }` signs\n * with no domain separation, succeeds, and verifies for anyone who also supplies\n * none. Nothing at any layer reports it. TypeScript catches this through excess\n * property checks, so the exposure is JavaScript callers specifically.\n *\n * @param opts - Options object to check.\n * @param allowed - The keys this call site accepts.\n * Returns a frozen null-prototype snapshot so later reads cannot fall through to a polluted\n * prototype. Like `checkOpts()` in noble-hashes, only enumerable own properties are copied.\n * @throws If any other copied key is present or the bag has a custom prototype. {@link TypeError}\n * @returns Sanitized snapshot of the enumerable own options.\n * @example\n * Accept a known option key. A key the list does not name, such as `ctx`, throws instead.\n * ```ts\n * import { checkOptKeys } from '@noble/post-quantum/utils.js';\n * checkOptKeys({ context: new Uint8Array() }, ['context']);\n * ```\n */\nexport function checkOptKeys<T extends object>(opts: T, allowed: readonly string[]): T {\n validateOpts(opts);\n // Snapshot once before validation: Object.assign follows the same own-enumerable option-bag\n // semantics as noble-hashes, while the null prototype keeps omitted fields immune to pollution.\n const normalized = Object.assign(Object.create(null), opts) as Record<string, unknown>;\n for (const [k, v] of Object.entries(normalized)) {\n // `undefined` means unset everywhere else in these validators, and building an options bag by\n // spread is a normal way to reach these calls, so present-but-undefined stays equivalent to\n // omission.\n if (v === undefined) continue;\n if (!allowed.includes(k))\n throw new TypeError(\n 'unexpected option \"' + String(k) + '\"; expected one of: ' + allowed.join(', ')\n );\n }\n return Object.freeze(normalized) as T;\n}\n\n/**\n * Validates common verification options.\n * `context` itself is validated with `abytes(...)`, and individual algorithms may narrow support\n * further after this shared plain-object gate.\n * @param opts - Verification options. See {@link VerOpts}.\n * @param allowed - Keys this call site accepts. Defaults to {@link VER_OPT_KEYS}; surfaces that\n * take extra keys, or take fewer, pass their own list.\n * @throws On wrong argument types. {@link TypeError}\n * @returns Frozen null-prototype snapshot of the validated options.\n * @example\n * Validate common verification options.\n * ```ts\n * validateVerOpts({ context: new Uint8Array([1]) });\n * ```\n */\nexport function validateVerOpts<T extends TArg<VerOpts>>(\n opts: T,\n allowed: readonly string[] = VER_OPT_KEYS\n): T {\n const normalized = checkOptKeys(opts, allowed);\n if (normalized.context !== undefined) abytes(normalized.context, undefined, 'opts.context');\n return normalized;\n}\n\n/**\n * Validates common signing options.\n * `extraEntropy` is validated with `abytes(...)`; exact lengths and extra algorithm-specific\n * restrictions are enforced later by callers.\n * @param opts - Signing options. See {@link SigOpts}.\n * @param allowed - Keys this call site accepts. Defaults to {@link SIG_OPT_KEYS}; surfaces that\n * take extra keys, or take fewer, pass their own list.\n * @throws On wrong argument types. {@link TypeError}\n * @returns Frozen null-prototype snapshot of the validated options.\n * @example\n * Validate common signing options.\n * ```ts\n * validateSigOpts({ extraEntropy: new Uint8Array([1]) });\n * ```\n */\nexport function validateSigOpts<T extends TArg<SigOpts>>(\n opts: T,\n allowed: readonly string[] = SIG_OPT_KEYS\n): T {\n const normalized = checkOptKeys(opts, allowed);\n if (normalized.context !== undefined) abytes(normalized.context, undefined, 'opts.context');\n if (normalized.extraEntropy !== false && normalized.extraEntropy !== undefined)\n abytes(normalized.extraEntropy, undefined, 'opts.extraEntropy');\n return normalized;\n}\n\n/** Generic signature interface with key generation, signing, and verification. */\nexport type Signer = CryptoKeys & {\n /** Public byte lengths for signatures and signing randomness. */\n lengths: { signRand?: number; signature?: number };\n /**\n * Sign one message.\n * @param msg - Message bytes to sign.\n * @param secretKey - Secret key bytes.\n * @param opts - Optional signing options.\n * @returns Signature bytes.\n */\n sign: (\n msg: TArg<Uint8Array>,\n secretKey: TArg<Uint8Array>,\n opts?: TArg<SigOpts>\n ) => TRet<Uint8Array>;\n /**\n * Verify one signature.\n * @param sig - Signature bytes.\n * @param msg - Signed message bytes.\n * @param publicKey - Public key bytes.\n * @param opts - Optional verification options.\n * @returns `true` when the signature is valid, `false` when all inputs are well-formed but the\n * signature check does not pass. Some implementations also treat malformed signature encodings as\n * a verification failure and return `false`.\n * @throws On malformed API arguments or unsupported verification options.\n */\n verify: (\n sig: TArg<Uint8Array>,\n msg: TArg<Uint8Array>,\n publicKey: TArg<Uint8Array>,\n opts?: TArg<VerOpts>\n ) => boolean;\n};\n\n/** Generic key encapsulation mechanism interface. */\nexport type KEM = CryptoKeys & {\n /** Public byte lengths for ciphertexts and optional message randomness. */\n lengths: { cipherText?: number; msg?: number; msgRand?: number };\n /**\n * Encapsulate one shared secret to a recipient public key.\n * @param publicKey - Recipient public key bytes.\n * @param msg - Optional caller-provided randomness/message seed.\n * @returns Ciphertext plus shared secret.\n */\n encapsulate: (\n publicKey: TArg<Uint8Array>,\n msg?: TArg<Uint8Array>\n ) => {\n cipherText: TRet<Uint8Array>;\n sharedSecret: TRet<Uint8Array>;\n };\n /**\n * Recover the shared secret from a ciphertext and recipient secret key.\n * @param cipherText - Ciphertext bytes.\n * @param secretKey - Recipient secret key bytes.\n * @returns Decapsulated shared secret.\n */\n decapsulate: (cipherText: TArg<Uint8Array>, secretKey: TArg<Uint8Array>) => TRet<Uint8Array>;\n};\n\n/** Bidirectional encoder/decoder interface. */\nexport interface Coder<F, T> {\n /**\n * Serialize one value.\n * @param from - Value to encode.\n * @returns Encoded representation.\n */\n encode(from: F): T;\n /**\n * Parse one serialized value.\n * @param to - Encoded representation.\n * @returns Decoded value.\n */\n decode(to: T): F;\n}\n\n/** Encoder/decoder interface specialized for byte arrays. */\nexport interface BytesCoder<T> extends Coder<T, Uint8Array> {\n /**\n * Serialize one value into bytes.\n * @param data - Value to encode.\n * @returns Encoded bytes.\n */\n encode: (data: T) => Uint8Array;\n /**\n * Parse one byte array into a value.\n * @param bytes - Encoded bytes.\n * @returns Decoded value.\n */\n decode: (bytes: Uint8Array) => T;\n}\n\n/** Fixed-length byte encoder/decoder. */\nexport type BytesCoderLen<T> = BytesCoder<T> & { bytesLen: number };\n\n// nano-packed, because struct encoding is hard.\ntype UnCoder<T> = T extends BytesCoder<infer U> ? U : never;\ntype SplitOut<T extends (number | BytesCoderLen<any>)[]> = {\n [K in keyof T]: T[K] extends number ? Uint8Array : UnCoder<T[K]>;\n};\n/**\n * Builds a fixed-layout coder from byte lengths and nested coders.\n * Raw-length fields decode as zero-copy `subarray(...)` views, and nested coders may preserve that\n * aliasing too. Nested coder `encode(...)` results are treated as owned scratch: `splitCoder`\n * copies them into the output and then zeroizes them with `fill(0)`. If a nested encoder forwards\n * caller-owned bytes, it must do so only after detaching them into a disposable copy.\n * @param label - Label used in validation errors.\n * @param lengths - Field lengths or nested coders.\n * @returns Composite fixed-length coder.\n * @example\n * Build a fixed-layout coder from byte lengths and nested coders.\n * ```ts\n * splitCoder('demo', 1, 2).encode([new Uint8Array([1]), new Uint8Array([2, 3])]);\n * ```\n */\nexport function splitCoder<T extends (number | BytesCoderLen<any>)[]>(\n label: string,\n ...lengths: T\n): TRet<BytesCoder<SplitOut<T>> & { bytesLen: number }> {\n const getLength = (c: TArg<number | BytesCoderLen<any>>) =>\n typeof c === 'number' ? c : (c as BytesCoderLen<any>).bytesLen;\n const bytesLen: number = lengths.reduce((sum: number, a) => sum + getLength(a), 0);\n return {\n bytesLen,\n encode: (bufs: T) => {\n const res = new Uint8Array(bytesLen);\n for (let i = 0, pos = 0; i < lengths.length; i++) {\n const c = lengths[i];\n const l = getLength(c);\n const b: Uint8Array = typeof c === 'number' ? (bufs[i] as any) : c.encode(bufs[i]);\n abytes_(b, l, label);\n res.set(b, pos);\n if (typeof c !== 'number') b.fill(0); // clean\n pos += l;\n }\n return res;\n },\n decode: (buf: TArg<Uint8Array>) => {\n abytes_(buf, bytesLen, label);\n const res = [];\n for (const c of lengths) {\n const l = getLength(c);\n const b = buf.subarray(0, l);\n res.push(typeof c === 'number' ? b : c.decode(b));\n buf = buf.subarray(l);\n }\n return res as SplitOut<T>;\n },\n } as any;\n}\n// nano-packed.array (fixed size)\n/**\n * Builds a fixed-length vector coder from another fixed-length coder.\n * Element decoding receives `subarray(...)` views, so aliasing depends on the element coder.\n * Element coder `encode(...)` results are treated as owned scratch: `vecCoder` copies them into\n * the output and then zeroizes them with `fill(0)`. If an element encoder forwards caller-owned\n * bytes, it must do so only after detaching them into a disposable copy. `vecCoder` also trusts\n * the `BytesCoderLen` contract: each encoded element must already be exactly `c.bytesLen` bytes.\n * @param c - Element coder.\n * @param vecLen - Number of elements in the vector.\n * @returns Fixed-length vector coder.\n * @example\n * Build a fixed-length vector coder from another fixed-length coder.\n * ```ts\n * vecCoder(\n * { bytesLen: 1, encode: (n: number) => Uint8Array.of(n), decode: (b: Uint8Array) => b[0] || 0 },\n * 2\n * ).encode([1, 2]);\n * ```\n */\nexport function vecCoder<T>(c: TArg<BytesCoderLen<T>>, vecLen: number): TRet<BytesCoderLen<T[]>> {\n const coder = c as BytesCoderLen<T>;\n const bytesLen = vecLen * coder.bytesLen;\n return {\n bytesLen,\n encode: (u: TArg<T[]>): TRet<Uint8Array> => {\n const uArr = aarray<T>(u, 'u');\n if (uArr.length !== vecLen)\n throw new RangeError(`vecCoder.encode: wrong length=${uArr.length}. Expected: ${vecLen}`);\n const res = new Uint8Array(bytesLen);\n for (let i = 0, pos = 0; i < uArr.length; i++) {\n const b = coder.encode(uArr[i] as T);\n res.set(b, pos);\n b.fill(0); // clean\n pos += b.length;\n }\n return res as TRet<Uint8Array>;\n },\n decode: (a: TArg<Uint8Array>): TRet<T[]> => {\n abytes_(a, bytesLen);\n const r: T[] = [];\n for (let i = 0; i < a.length; i += coder.bytesLen)\n r.push(coder.decode(a.subarray(i, i + coder.bytesLen)));\n return r as TRet<T[]>;\n },\n } as any;\n}\n\n/**\n * Overwrites supported typed-array inputs with zeroes in place.\n * Accepts direct typed arrays and one-level arrays of them.\n * @param list - Typed arrays or one-level lists of typed arrays to clear.\n * @example\n * Overwrite typed arrays with zeroes.\n * ```ts\n * const buf = Uint8Array.of(1, 2, 3);\n * cleanBytes(buf);\n * ```\n */\nexport function cleanBytes(...list: (TypedArray | TypedArray[])[]): void {\n for (const t of list) {\n if (Array.isArray(t)) for (const b of t) b.fill(0);\n else t.fill(0);\n }\n}\n\n/**\n * Creates a 32-bit mask with the lowest `bits` bits set.\n * @param bits - Number of low bits to keep.\n * @returns Bit mask with `bits` ones.\n * @throws On wrong argument types. {@link TypeError}\n * @throws On wrong argument ranges or values. {@link RangeError}\n * @example\n * Create a low-bit mask for packed-field operations.\n * ```ts\n * const mask = getMask(4);\n * ```\n */\nexport function getMask(bits: number): number {\n anumber(bits, 'bits');\n if (bits > 32) throw new RangeError('\"bits\" expected <= 32, got ' + bits);\n // JS shifts are modulo 32, so bit 32 needs an explicit full-width mask.\n return bits === 32 ? 0xffffffff : ~(-1 << bits) >>> 0;\n}\n\n/** Shared empty byte array used as the default context. */\nexport const EMPTY: TRet<Uint8Array> = /* @__PURE__ */ Uint8Array.of();\n\n/**\n * Builds the domain-separated message payload for the pure sign/verify paths.\n * Context length `255` is valid; only `ctx.length > 255` is rejected.\n * @param msg - Message bytes.\n * @param ctx - Optional context bytes.\n * @returns Domain-separated message payload.\n * @throws On wrong argument ranges or values. {@link RangeError}\n * @example\n * Build the domain-separated payload before direct signing.\n * ```ts\n * const payload = getMessage(new Uint8Array([1, 2]));\n * ```\n */\nexport function getMessage(msg: TArg<Uint8Array>, ctx: TArg<Uint8Array> = EMPTY): TRet<Uint8Array> {\n abytes_(msg, undefined, 'msg');\n abytes_(ctx, undefined, 'ctx');\n if (ctx.length > 255) throw new RangeError('context should be 255 bytes or less');\n return concatBytes(new Uint8Array([0, ctx.length]), ctx, msg);\n}\n\n// DER tag+length plus the shared NIST hash OID arc 2.16.840.1.101.3.4.2.* used by the\n// FIPS 204 / FIPS 205 pre-hash wrappers; the final byte selects SHA-256, SHA-512, SHAKE128,\n// SHAKE256, or another approved hash/XOF under that subtree.\n// 06 09 60 86 48 01 65 03 04 02\nconst oidNistP = /* @__PURE__ */ Uint8Array.from([6, 9, 0x60, 0x86, 0x48, 1, 0x65, 3, 4, 2]);\n\n/**\n * Output length, in bytes, that each XOF OID under this arc denotes.\n *\n * Unlike a fixed hash, an XOF's OID is a promise about the digest length: RFC 8702\n * defines id-shake128 as SHAKE128 with 256-bit output and id-shake256 as SHAKE256 with\n * 512-bit output, and FIPS 204 / FIPS 205 use exactly those pairings for pre-hash. Both\n * bare noble-hashes defaults are half these values, so neither can be signed under its\n * own OID.\n */\nconst XOF_OID_OUTPUT_LEN: Record<string, number> = /* @__PURE__ */ (() => ({\n '060960864801650304020b': 32, // id-shake128, SHAKE128(M, 256)\n '060960864801650304020c': 64, // id-shake256, SHAKE256(M, 512)\n}))();\n\n/**\n * Validates that a hash exposes a NIST hash OID and enough collision resistance.\n * Current accepted surface is broader than the FIPS algorithm tables: any hash/XOF under the NIST\n * `2.16.840.1.101.3.4.2.*` subtree is accepted if its effective `outputLen` is strong enough.\n * XOF callers must pass a callable whose `outputLen` matches the digest length they actually intend\n * to sign; bare `shake128` / `shake256` defaults are too short for the stronger prehash modes.\n * @param hash - Hash function to validate.\n * @param requiredStrength - Minimum required collision-resistance strength in bits.\n * @throws If the hash metadata or collision resistance is insufficient. {@link Error}\n * @example\n * Validate that a hash exposes a NIST hash OID and enough collision resistance.\n * ```ts\n * import { sha256 } from '@noble/hashes/sha2.js';\n * import { checkHash } from '@noble/post-quantum/utils.js';\n * checkHash(sha256, 128);\n * ```\n */\nexport function checkHash(hash: CHash, requiredStrength: number = 0): void {\n if (typeof hash !== 'function' || typeof (hash as any).create !== 'function')\n throw new TypeError('\"hash\" expected hash function, got type=' + typeof hash);\n ahash_(hash);\n anumber(requiredStrength, 'requiredStrength');\n const oid = hash.oid as unknown as TArg<Uint8Array>;\n abytes_(oid, undefined, 'hash.oid');\n if (!equalBytes(oid.subarray(0, 10), oidNistP))\n throw new Error('\"hash.oid\" is invalid: expected NIST hash');\n // FIPS 204 / FIPS 205 require both collision and second-preimage strength; for approved NIST\n // hashes/XOFs under this OID subtree, the collision bound from the configured digest length is\n // the tighter runtime check, so enforce that lower bound here.\n // XOFs under this arc are identified by an OID that fixes their output length:\n // FIPS 204 §5.4.1 (SHAKE128) and FIPS 205 §10.2.2 (both SHAKEs), matching RFC 8702, pair\n // id-shake128 with SHAKE128(M, 256) and id-shake256 with SHAKE256(M, 512). getMessagePrehash embeds\n // hash.oid beside hash(msg), so a shorter digest signs an M' that claims a length\n // it does not have: noble-hashes' bare shake256 defaults to 32 bytes and cleared\n // the collision bound at the 128-bit level, producing signatures a conformant\n // verifier rejects because it recomputes 512 bits. Check the length the OID\n // denotes rather than the generic bound.\n const xofLen = XOF_OID_OUTPUT_LEN[bytesToHex(oid as Uint8Array)];\n if (xofLen !== undefined && hash.outputLen !== xofLen) {\n throw new Error(\n 'Pre-hash XOF output length must be ' + xofLen + ' bytes for this OID, got: ' + hash.outputLen\n );\n }\n const collisionResistance = (hash.outputLen * 8) / 2;\n if (requiredStrength > collisionResistance) {\n throw new Error(\n 'Pre-hash security strength too low: ' +\n collisionResistance +\n ', required: ' +\n requiredStrength\n );\n }\n}\n\n/**\n * Builds the domain-separated prehash payload for the prehash sign/verify paths.\n * Callers are expected to vet `hash.oid` first, e.g. via `checkHash(...)`; calling this helper\n * directly with a hash object that lacks `oid` currently throws later inside `concatBytes(...)`.\n * Context length `255` is valid; only `ctx.length > 255` is rejected.\n * @param hash - Prehash function.\n * @param msg - Message bytes.\n * @param ctx - Optional context bytes.\n * @returns Domain-separated prehash payload.\n * @throws On wrong argument ranges or values. {@link RangeError}\n * @example\n * Build the domain-separated prehash payload for external hashing.\n * ```ts\n * import { sha256 } from '@noble/hashes/sha2.js';\n * import { getMessagePrehash } from '@noble/post-quantum/utils.js';\n * getMessagePrehash(sha256, new Uint8Array([1, 2]));\n * ```\n */\nexport function getMessagePrehash(\n hash: CHash,\n msg: TArg<Uint8Array>,\n ctx: TArg<Uint8Array> = EMPTY\n): TRet<Uint8Array> {\n checkHash(hash);\n abytes_(msg, undefined, 'msg');\n abytes_(ctx, undefined, 'ctx');\n if (ctx.length > 255) throw new RangeError('context should be 255 bytes or less');\n const hashed = hash(msg);\n return concatBytes(new Uint8Array([1, ctx.length]), ctx, hash.oid!, hashed);\n}\n\n/**\n * Asserts something is a string.\n * @param value - Value to validate.\n * @param title - Label included in thrown errors.\n * @returns The validated string.\n * @throws On wrong argument types. {@link TypeError}\n * @example\n * Validate a label string.\n *\n * ```ts\n * astring('example', 'label');\n * ```\n */\nexport function astring(value: unknown, title: string = ''): string {\n if (typeof value !== 'string') {\n const prefix = title && `\"${title}\" `;\n throw new TypeError(prefix + 'expected string, got type=' + typeof value);\n }\n return value;\n}\n","import { falcon512 } from './noble/falcon';\n\n/**\n * Falcon-512 primitives used by the S2morrow layer (NIST key formats). `nobleEngine` is the only\n * implementation: this interface keeps the rest of `starknet/falcon` independent from the place the\n * Falcon code comes from.\n */\nexport interface FalconEngine {\n /**\n * New key pair.\n * @param {Uint8Array} [seed] 48 random bytes; by default, drawn by noble\n * @returns {{ secretKey: Uint8Array; publicKey: Uint8Array }} the NIST secret key (1281 bytes)\n * and the NIST public key (897 bytes)\n * @example\n * ```typescript\n * const result = nobleEngine.keygen(new Uint8Array(48).fill(1));\n * // result = { secretKey: Uint8Array(1281) [89, 0, 31, 1, 255, 255, …],\n * // publicKey: Uint8Array(897) [9, 100, 145, 86, 69, 182, …] }\n * ```\n */\n keygen(seed?: Uint8Array): { secretKey: Uint8Array; publicKey: Uint8Array };\n /**\n * Public key of a NIST secret key. Not used by the signer, which computes h = g / f itself: kept\n * to cross-check that code in the tests.\n * @param {Uint8Array} secretKey the NIST secret key (1281 bytes)\n * @returns {Uint8Array} the NIST public key (897 bytes)\n * @example\n * ```typescript\n * const { secretKey } = nobleEngine.keygen(new Uint8Array(48).fill(1));\n * const result = nobleEngine.getPublicKey(secretKey);\n * // result = Uint8Array(897) [9, 100, 145, 86, 69, 182, …]\n * ```\n */\n getPublicKey(secretKey: Uint8Array): Uint8Array;\n /**\n * Signs a hash point. Draws a new sampler seed at each call.\n * @param {Uint16Array} hashPoint the 512 coefficients of the hash point, in [0, q)\n * @param {Uint8Array} secretKey the NIST secret key (1281 bytes)\n * @returns {Int16Array} s2, the 512 coefficients that the signature carries (the S2morrow\n * account names this polynomial s1)\n * @example\n * ```typescript\n * const hashPoint = hashToPoint([42n], [1n, 2n]);\n * const result = nobleEngine.signHashPoint(hashPoint, secretKey);\n * // result = Int16Array(512) [-248, -33, -9, -221, …] (random: a new sampler seed at each call)\n * ```\n */\n signHashPoint(hashPoint: Uint16Array, secretKey: Uint8Array): Int16Array;\n /**\n * Checks s2 against a hash point, with the norm check of noble. Not used by the signer, which\n * checks the equation of the S2morrow account instead: kept for the tests.\n * @param {Int16Array} s2 the 512 coefficients returned by `signHashPoint`\n * @param {Uint16Array} hashPoint the 512 coefficients of the hash point, in [0, q)\n * @param {Uint8Array} publicKey the NIST public key (897 bytes)\n * @returns {boolean} true when s2 is a valid signature of the hash point\n * @example\n * ```typescript\n * const s2 = nobleEngine.signHashPoint(hashPoint, secretKey);\n * const result = nobleEngine.verifyHashPoint(s2, hashPoint, publicKey);\n * // result = true\n * ```\n */\n verifyHashPoint(s2: Int16Array, hashPoint: Uint16Array, publicKey: Uint8Array): boolean;\n}\n\n/**\n * The engine of `starknet/falcon`, backed by a copy of `@noble/post-quantum` 0.7.1. This file is\n * the only one of `src/falcon/` that imports the copy.\n *\n * What is copied: `noble/falcon.ts`, `noble/_crystals.ts`, `noble/utils.ts` and `noble/LICENSE`\n * (MIT, Paul Miller), from the npm package `@noble/post-quantum@0.7.1`. The copy adds one thing:\n * `falcon512.internal`, with `sign(hashPoint, secretKey)` and `verify(s2, hashPoint, publicKey)`.\n * noble 0.7.1 computes the hash point itself, with SHAKE256, inside `genFalcon`; the S2morrow\n * account needs a Poseidon hash point, computed by `s2morrow/hashToPoint.ts`. `noble/PATCH.md`\n * lists the changes, the exact diff and the SHA-256 of each copied file, checked by\n * `__tests__/utils/falcon/vendor.test.ts`. ESLint and Prettier skip the copy.\n *\n * Why a copy: this API is proposed to noble in\n * https://github.com/paulmillr/noble-post-quantum/pull/55, not merged yet (2026-10-16).\n *\n * The switch, once noble publishes this API:\n * 1. `package.json`: add `@noble/post-quantum` to the dependencies, and remove `@noble/ciphers`\n * (only the copy imports it; noble brings its own).\n * 2. Here: import `falcon512` from `@noble/post-quantum/falcon.js`, and adapt the four functions\n * below if the published names differ.\n * 3. Delete the folder `noble/`, its line in `.prettierignore` (and the file, if no other line is\n * left), the test `__tests__/utils/falcon/vendor.test.ts`, and the point \"Traceable vendored\n * code\" of `src/falcon/SECURITY.md`.\n * 4. Tests: in `engine.test.ts`, `keys.test.ts` and `signature.test.ts`, import `falcon512` from\n * `@noble/post-quantum/falcon.js`; `engine.test.ts` checks the patched API: adapt it to the\n * published one. In `boundaries.test.ts`, replace `@noble/ciphers` with `@noble/post-quantum`.\n * 5. Docs: remove the mention of the copy from the JSDoc of `Falcon512Signer` and from the module\n * comment of `src/falcon/index.ts`.\n *\n * The public API of `starknet/falcon` does not change, and the other tests pass unchanged.\n */\nexport const nobleEngine: FalconEngine = Object.freeze({\n keygen: (seed?: Uint8Array) => falcon512.keygen(seed),\n getPublicKey: (secretKey: Uint8Array) => falcon512.getPublicKey(secretKey),\n signHashPoint: (hashPoint: Uint16Array, secretKey: Uint8Array) =>\n falcon512.internal.sign(hashPoint, secretKey),\n verifyHashPoint: (s2: Int16Array, hashPoint: Uint16Array, publicKey: Uint8Array) =>\n falcon512.internal.verify(s2, hashPoint, publicKey),\n});\n","// NTT roots of x^n + 1 mod q, falcon.py convention, for n = 2, 4, ..., 512 (offset n - 2).\n// Copied from falcon-rs src/constants.rs (NTT_ROOTS_ALL, commit fbf38fe);\n// checked by __tests__/utils/falcon/ntt.test.ts.\nexport const NTT_ROOTS_ALL: readonly number[] = Object.freeze([\n 1479, 10810, 4043, 8246, 5146, 7143, 5736, 6553, 4134, 8155, 722, 11567, 1305, 10984, 1646, 10643,\n 1212, 11077, 5860, 6429, 3195, 9094, 2545, 9744, 3621, 8668, 3504, 8785, 3542, 8747, 4591, 7698,\n 5728, 6561, 5023, 7266, 5828, 6461, 4978, 7311, 1351, 10938, 3328, 8961, 5777, 6512, 2975, 9314,\n 563, 11726, 3006, 9283, 2744, 9545, 949, 11340, 2625, 9664, 4821, 7468, 2639, 9650, 1000, 11289,\n 4320, 7969, 3091, 9198, 81, 12208, 2963, 9326, 4896, 7393, 3051, 9238, 2366, 9923, 1853, 10436,\n 140, 12149, 4611, 7678, 726, 11563, 4255, 8034, 1177, 11112, 2768, 9521, 1635, 10654, 3712, 8577,\n 3135, 9154, 2747, 9542, 4846, 7443, 3553, 8736, 4805, 7484, 2294, 9995, 1062, 11227, 1326, 10963,\n 5086, 7203, 3014, 9275, 3201, 9088, 1170, 11119, 2319, 9970, 955, 11334, 790, 11499, 544, 11745,\n 5791, 6498, 339, 11950, 2468, 9821, 2842, 9447, 480, 11809, 9, 12280, 1022, 11267, 4278, 8011,\n 1673, 10616, 4989, 7300, 5331, 6958, 3584, 8705, 4177, 8112, 1381, 10908, 2525, 9764, 2396, 9893,\n 4452, 7837, 3296, 8993, 3949, 8340, 130, 12159, 4354, 7935, 5374, 6915, 2837, 9452, 5767, 6522,\n 827, 11462, 3748, 8541, 953, 11336, 5067, 7222, 2197, 10092, 118, 12171, 2476, 9813, 2548, 9741,\n 4231, 8058, 355, 11934, 3382, 8907, 3707, 8582, 1759, 10530, 3694, 8595, 5179, 7110, 5542, 6747,\n 145, 12144, 3637, 8652, 3459, 8830, 5911, 6378, 4890, 7399, 3932, 8357, 2731, 9558, 2089, 10200,\n 5092, 7197, 2881, 9408, 3284, 9005, 729, 11560, 3241, 9048, 3289, 9000, 2013, 10276, 5755, 6534,\n 4632, 7657, 1260, 11029, 4388, 7901, 334, 11955, 2426, 9863, 1696, 10593, 1428, 10861, 1663,\n 10626, 1777, 10512, 1426, 10863, 4654, 7635, 5291, 6998, 2704, 9585, 4938, 7351, 3636, 8653, 3915,\n 8374, 2166, 10123, 113, 12176, 4919, 7370, 3, 12286, 4437, 7852, 160, 12129, 3149, 9140, 4057,\n 8232, 3271, 9018, 1689, 10600, 3364, 8925, 4372, 7917, 2174, 10115, 4414, 7875, 2847, 9442, 2645,\n 9644, 4053, 8236, 2305, 9984, 5042, 7247, 5195, 7094, 2780, 9509, 1484, 10805, 4895, 7394, 3016,\n 9273, 243, 12046, 3000, 9289, 671, 11618, 3136, 9153, 5191, 7098, 2399, 9890, 3400, 8889, 2178,\n 10111, 1544, 10745, 420, 11869, 5559, 6730, 476, 11813, 3531, 8758, 3985, 8304, 4905, 7384, 5332,\n 6957, 3510, 8779, 2370, 9919, 2865, 9424, 2969, 9320, 3978, 8311, 2686, 9603, 3247, 9042, 4048,\n 8241, 2249, 10040, 1153, 11136, 2884, 9405, 5407, 6882, 3186, 9103, 1630, 10659, 2126, 10163,\n 2187, 10102, 2566, 9723, 2422, 9867, 6039, 6250, 2987, 9302, 6022, 6267, 2437, 9852, 3646, 8643,\n 875, 11414, 3780, 8509, 1607, 10682, 4976, 7313, 5011, 7278, 1002, 11287, 4284, 8005, 5088, 7201,\n 3248, 9041, 1207, 11082, 1168, 11121, 5277, 7012, 1065, 11224, 2143, 10146, 404, 11885, 4645,\n 7644, 1912, 10377, 1378, 10911, 435, 11854, 4337, 7952, 2381, 9908, 5444, 6845, 4096, 8193, 493,\n 11796, 545, 11744, 5019, 7270, 3704, 8585, 2678, 9611, 1537, 10752, 242, 12047, 4714, 7575, 4143,\n 8146, 27, 12262, 3066, 9223, 3763, 8526, 1440, 10849, 5084, 7205, 1632, 10657, 1017, 11272, 4885,\n 7404, 3778, 8511, 3833, 8456, 390, 11899, 773, 11516, 2401, 9888, 442, 11847, 5101, 7188, 1067,\n 11222, 2912, 9377, 5698, 6591, 354, 11935, 4861, 7428, 2859, 9430, 1045, 11244, 5012, 7277, 2481,\n 9808, 3957, 8332, 2839, 9450, 2127, 10162, 151, 12138, 431, 11858, 1579, 10710, 5906, 6383, 2505,\n 9784, 1323, 10966, 2766, 9523, 52, 12237, 3174, 9115, 6055, 6234, 3336, 8953, 677, 11612, 5874,\n 6415, 4169, 8120, 3127, 9162, 5241, 7048, 2920, 9369, 1010, 11279, 5468, 6821, 787, 11502, 3482,\n 8807, 1321, 10968, 192, 12097, 4912, 7377, 2049, 10240, 4698, 7591, 5057, 7232, 4780, 7509, 3445,\n 8844, 1956, 10333, 5009, 7280, 6008, 6281, 885, 11404, 3532, 8757, 1003, 11286, 58, 12231, 241,\n 12048, 975, 11314, 4212, 8077, 2844, 9445, 3438, 8851, 1105, 11184, 142, 12147, 5681, 6608, 3477,\n 8812, 2302, 9987, 605, 11684, 4213, 8076, 504, 11785, 5886, 6403, 4782, 7507, 5594, 6695, 3029,\n 9260, 421, 11868, 4080, 8209, 6068, 6221, 3602, 8687, 6077, 6212, 4624, 7665, 3263, 9026, 3600,\n 8689, 4948, 7341, 6137, 6152, 400, 11889, 1728, 10561, 5862, 6427, 6136, 6153, 5415, 6874, 3643,\n 8646, 56, 12233, 3199, 9090, 5206, 7083, 5529, 6760, 3565, 8724, 654, 11635, 1987, 10302, 1702,\n 10587, 3988, 8301, 468, 11821, 316, 11973, 382, 11907, 3710, 8579, 6093, 6196, 5446, 6843, 5339,\n 6950, 973, 11316, 1254, 11035, 1359, 10930, 5435, 6854, 2033, 10256, 3998, 8291, 3879, 8410, 1922,\n 10367, 3860, 8429, 5445, 6844, 4536, 7753, 1050, 11239, 3818, 8471, 6118, 6171, 1190, 11099, 2683,\n 9606, 3789, 8500, 147, 12142, 5456, 6833, 4449, 7840, 4749, 7540, 5537, 6752, 4789, 7500, 4467,\n 7822, 1018, 11271, 5925, 6364, 1041, 11248, 3514, 8775, 2344, 9945, 1278, 11011, 5574, 6715, 1973,\n 10316, 4324, 7965, 4916, 7373, 4075, 8214, 5315, 6974, 5079, 7210, 3262, 9027, 522, 11767, 2169,\n 10120, 1200, 11089, 5184, 7105, 2555, 9734, 6122, 6167, 5297, 6992, 6119, 6170, 3956, 8333, 1360,\n 10929, 1962, 10327, 1594, 10695, 5961, 6328, 5106, 7183, 4298, 7991, 3329, 8960, 168, 12121, 2692,\n 9597, 4049, 8240, 3728, 8561, 1159, 11130, 5990, 6299, 948, 11341, 1146, 11143, 1404, 10885, 325,\n 11964, 5766, 6523, 652, 11637, 295, 11994, 6099, 6190, 2919, 9370, 3762, 8527, 4016, 8273, 4077,\n 8212, 6065, 6224, 835, 11454, 3570, 8719, 4240, 8049, 4046, 8243, 709, 11580, 3150, 9139, 1319,\n 10970, 1058, 11231, 4079, 8210, 922, 11367, 441, 11848, 4322, 7967, 1958, 10331, 2078, 10211,\n 1112, 11177, 3834, 8455, 5257, 7032, 4433, 7856, 5919, 6370, 5486, 6803, 3054, 9235, 1747, 10542,\n 3123, 9166, 2948, 9341, 2503, 9786, 5782, 6507, 1566, 10723, 64, 12225, 3656, 8633, 2459, 9830,\n 683, 11606, 1293, 10996, 4737, 7552, 5429, 6860, 4774, 7515, 5908, 6381, 453, 11836, 418, 11871,\n 3772, 8517, 3991, 8298, 3969, 8320, 2767, 9522, 156, 12133, 2281, 10008, 5876, 6413, 5333, 6956,\n 2031, 10258, 3963, 8326, 576, 11713, 2447, 9842, 6142, 6147, 2051, 10238, 1954, 10335, 1805,\n 10484, 2882, 9407, 3529, 8760, 3434, 8855, 2908, 9381, 218, 12071, 3030, 9259, 4115, 8174, 1843,\n 10446, 2361, 9928, 3202, 9087, 4493, 7796, 2057, 10232, 5369, 6920, 1512, 10777, 350, 11939, 1815,\n 10474, 5383, 6906, 49, 12240, 1263, 11026, 5915, 6374, 1483, 10806, 1489, 10800, 2500, 9789, 5942,\n 6347, 1583, 10706, 1693, 10596, 3009, 9280, 174, 12115, 723, 11566, 2738, 9551, 5868, 6421, 5735,\n 6554, 2655, 9634, 3315, 8974, 426, 11863, 4754, 7535, 1858, 10431, 1975, 10314, 3757, 8532, 2925,\n 9364, 347, 11942,\n]);\n","/* eslint-disable no-bitwise */\n/* eslint-disable no-plusplus */\nimport { N, Q } from './constants';\nimport { NTT_ROOTS_ALL } from './nttRoots';\n\n/** Inverse of 2 mod q. */\nconst I2 = 6145;\n/** Square root of -1 mod q (NTT root for n = 2). */\nconst SQR1 = 1479;\n\n/**\n * Reduces an integer to [0, q).\n * @param {number} a an integer, possibly negative\n * @returns {number} a mod q, in [0, q)\n * @example\n * ```typescript\n * const result = modQ(-1);\n * // result = 12288\n * const result2 = modQ(12290);\n * // result2 = 1\n * ```\n */\nexport const modQ = (a: number): number => ((a % Q) + Q) % Q;\n\n/**\n * base^exponent mod q, by square and multiply.\n * @param {number} base the base\n * @param {number} exponent a non-negative integer\n * @returns {number} the power, in [0, q)\n * @example\n * ```typescript\n * const result = powMod(2, 10);\n * // result = 1024\n * const result2 = powMod(1479, 2);\n * // result2 = 12288 (1479 is a square root of -1 mod q)\n * ```\n */\nfunction powMod(base: number, exponent: number): number {\n let result = 1;\n let b = modQ(base);\n for (let e = exponent; e > 0; e >>= 1) {\n if (e & 1) result = (result * b) % Q;\n b = (b * b) % Q;\n }\n return result;\n}\n\n/**\n * Inverse mod q (Fermat); throws for 0. No cache: inputs may be derived from secret keys.\n * @param {number} x an integer that is not a multiple of q\n * @returns {number} the inverse of x mod q, in [1, q)\n * @throws {Error} when x is a multiple of q\n * @example\n * ```typescript\n * const result = invMod(1479);\n * // result = 10810\n * invMod(0);\n * // throws Error(\"Falcon512: 0 has no inverse mod q\")\n * ```\n */\nexport function invMod(x: number): number {\n const r = modQ(x);\n if (r === 0) throw new Error('Falcon512: 0 has no inverse mod q');\n return powMod(r, Q - 2);\n}\n\n/**\n * Roots used at size n (falcon.py `roots_dict_Zq[n]`).\n * @param {number} n a power of 2, from 2 to 512\n * @returns {number[]} the n roots of x^n + 1 mod q, in (r, -r) pairs\n * @example\n * ```typescript\n * const result = nttRoots(4);\n * // result = [4043, 8246, 5146, 7143]\n * ```\n */\nexport const nttRoots = (n: number): readonly number[] => NTT_ROOTS_ALL.slice(n - 2, 2 * n - 2);\n\n/**\n * Throws unless n is a power of 2 from 2 to 512 (the sizes of the NTT).\n * @param {number} n the size to check\n * @throws {Error} when n is not a power of 2 in [2, 512]\n * @example\n * ```typescript\n * checkSize(4);\n * // passes\n * checkSize(3);\n * // throws Error(\"Falcon512: NTT size must be a power of 2 in [2, 512], got 3\")\n * ```\n */\nfunction checkSize(n: number): void {\n if (n < 2 || n > N || (n & (n - 1)) !== 0) {\n throw new Error(`Falcon512: NTT size must be a power of 2 in [2, ${N}], got ${n}`);\n }\n}\n\n/**\n * Recursive NTT of coefficients already in [0, q); `ntt` checks and reduces its input first.\n * @param {number[]} f the coefficients, in [0, q), of size a power of 2\n * @returns {number[]} the NTT of f\n * @example\n * ```typescript\n * const result = nttRec([1, 2]);\n * // result = [2959, 9332]\n * ```\n */\nfunction nttRec(f: number[]): number[] {\n const n = f.length;\n if (n === 2) {\n const t = (SQR1 * f[1]) % Q;\n return [modQ(f[0] + t), modQ(f[0] - t)];\n }\n const half = n / 2;\n const even: number[] = new Array(half);\n const odd: number[] = new Array(half);\n for (let i = 0; i < half; i++) {\n even[i] = f[2 * i];\n odd[i] = f[2 * i + 1];\n }\n const a = nttRec(even);\n const b = nttRec(odd);\n const w = nttRoots(n);\n const out: number[] = new Array(n);\n for (let i = 0; i < half; i++) {\n const wb = (w[2 * i] * b[i]) % Q;\n out[2 * i] = modQ(a[i] + wb);\n out[2 * i + 1] = modQ(a[i] - wb);\n }\n return out;\n}\n\n/**\n * Recursive inverse NTT of values already in [0, q); `intt` checks and reduces its input first.\n * @param {number[]} fNtt the NTT values, in [0, q), of size a power of 2\n * @returns {number[]} the coefficients, in [0, q)\n * @example\n * ```typescript\n * const result = inttRec([2959, 9332]);\n * // result = [1, 2]\n * ```\n */\nfunction inttRec(fNtt: number[]): number[] {\n const n = fNtt.length;\n if (n === 2) {\n const s = modQ(fNtt[0] + fNtt[1]);\n const d = modQ(fNtt[0] - fNtt[1]);\n return [(I2 * s) % Q, (((I2 * invMod(SQR1)) % Q) * d) % Q];\n }\n const half = n / 2;\n const w = nttRoots(n);\n const f0: number[] = new Array(half);\n const f1: number[] = new Array(half);\n for (let i = 0; i < half; i++) {\n const s = modQ(fNtt[2 * i] + fNtt[2 * i + 1]);\n const d = modQ(fNtt[2 * i] - fNtt[2 * i + 1]);\n f0[i] = (I2 * s) % Q;\n f1[i] = (((I2 * d) % Q) * invMod(w[2 * i])) % Q;\n }\n const a = inttRec(f0);\n const b = inttRec(f1);\n const out: number[] = new Array(n);\n for (let i = 0; i < half; i++) {\n out[2 * i] = a[i];\n out[2 * i + 1] = b[i];\n }\n return out;\n}\n\n/**\n * NTT in the falcon.py convention (same as falcon-rs and falcon.cairo). Coefficients may be negative.\n * @param {ArrayLike<number>} f the coefficients, of size a power of 2 from 2 to 512\n * @returns {number[]} the NTT of f, in [0, q)\n * @throws {Error} when the size of f is not a power of 2 in [2, 512]\n * @example\n * ```typescript\n * const result = ntt([1, 2]);\n * // result = [2959, 9332]\n * ntt([1, 2, 3]);\n * // throws Error(\"Falcon512: NTT size must be a power of 2 in [2, 512], got 3\")\n * ```\n */\nexport function ntt(f: ArrayLike<number>): number[] {\n checkSize(f.length);\n return nttRec(Array.from(f, modQ));\n}\n\n/**\n * Inverse NTT; output in [0, q).\n * @param {ArrayLike<number>} fNtt the NTT values, of size a power of 2 from 2 to 512\n * @returns {number[]} the coefficients, in [0, q)\n * @throws {Error} when the size of fNtt is not a power of 2 in [2, 512]\n * @example\n * ```typescript\n * const result = intt([2959, 9332]);\n * // result = [1, 2]\n * ```\n */\nexport function intt(fNtt: ArrayLike<number>): number[] {\n checkSize(fNtt.length);\n return inttRec(Array.from(fNtt, modQ));\n}\n\n/**\n * Product in Zq[x]/(x^n + 1).\n * @param {ArrayLike<number>} a the first polynomial\n * @param {ArrayLike<number>} b the second polynomial, of the same size\n * @returns {number[]} a·b mod (x^n + 1, q), in [0, q)\n * @throws {Error} when the sizes differ, or are not a power of 2 in [2, 512]\n * @example\n * ```typescript\n * const result = mulZq([1, 1], [1, 1]);\n * // result = [0, 2] ((1 + x)² = 2x, since x² = -1)\n * ```\n */\nexport function mulZq(a: ArrayLike<number>, b: ArrayLike<number>): number[] {\n if (a.length !== b.length) throw new Error('Falcon512: polynomial sizes differ');\n const an = ntt(a);\n const bn = ntt(b);\n return intt(an.map((v, i) => (v * bn[i]) % Q));\n}\n\n/**\n * Quotient a / b in Zq[x]/(x^n + 1); throws if b is not invertible.\n * @param {ArrayLike<number>} a the dividend\n * @param {ArrayLike<number>} b the divisor, of the same size\n * @returns {number[]} a / b mod (x^n + 1, q), in [0, q)\n * @throws {Error} when the sizes differ, or b is not invertible mod q\n * @example\n * ```typescript\n * const result = divZq([0, 2], [1, 1]);\n * // result = [1, 1]\n * divZq([1, 2], [0, 0]);\n * // throws Error(\"Falcon512: polynomial is not invertible mod q\")\n * ```\n */\nexport function divZq(a: ArrayLike<number>, b: ArrayLike<number>): number[] {\n if (a.length !== b.length) throw new Error('Falcon512: polynomial sizes differ');\n const an = ntt(a);\n const bn = ntt(b);\n if (bn.some((v) => v === 0)) throw new Error('Falcon512: polynomial is not invertible mod q');\n return intt(an.map((v, i) => (v * invMod(bn[i])) % Q));\n}\n\n/**\n * Exact integer product in Z[x]/(x^n + 1). Only for small coefficients (NTRU equation check,\n * test reference): every partial sum must stay below 2^53.\n * @param {ArrayLike<number>} a the first polynomial\n * @param {ArrayLike<number>} b the second polynomial, of the same size\n * @returns {number[]} the exact product, not reduced mod q\n * @throws {Error} when the sizes differ\n * @example\n * ```typescript\n * const result = mulNegacyclicInt([1, 1, 0, 0], [1, 1, 0, 0]);\n * // result = [1, 2, 1, 0]\n * const result2 = mulNegacyclicInt([1, 0, 0, 1], [1, 0, 0, 1]);\n * // result2 = [1, 0, -1, 2] (x^3 · x^3 = x^6 = -x^2)\n * ```\n */\nexport function mulNegacyclicInt(a: ArrayLike<number>, b: ArrayLike<number>): number[] {\n const n = a.length;\n if (b.length !== n) throw new Error('Falcon512: polynomial sizes differ');\n const r: number[] = new Array(n).fill(0);\n for (let i = 0; i < n; i++) {\n const ai = a[i];\n if (ai !== 0) {\n for (let j = 0; j < n; j++) {\n const k = i + j;\n if (k < n) r[k] += ai * b[j];\n else r[k - n] -= ai * b[j];\n }\n }\n }\n return r;\n}\n","/* eslint-disable no-bitwise */\n/* eslint-disable no-plusplus */\nimport * as starknet from 'starknet';\nimport { N, PACKED_SLOTS, Q, QB, VALUES_PER_HALF } from './constants';\nimport { assertFelt } from './felt';\n\n/**\n * Horner evaluation in base q of values[start..end): values[start] + values[start + 1]·q + …\n * @param {ArrayLike<number>} values the Zq values\n * @param {number} start index of the first value (lowest power of q)\n * @param {number} end index after the last value\n * @returns {bigint} the packed number\n * @example\n * ```typescript\n * const result = horner([1, 2], 0, 2);\n * // result = 24579n (1 + 2 × 12289)\n * ```\n */\nconst horner = (values: ArrayLike<number>, start: number, end: number): bigint => {\n let acc = 0n;\n for (let i = end - 1; i >= start; i--) acc = acc * QB + BigInt(values[i]);\n return acc;\n};\n\n/**\n * Packs 512 Zq values into 29 felt252 (falcon-rs packing.rs / Cairo packing.cairo):\n * felt = horner(v0..v8) + horner(v9..v17) * 2^128; the last felt holds 8 values in its low half.\n * @param {ArrayLike<number>} poly 512 integers in [0, q)\n * @returns {bigint[]} the 29 packed felts\n * @throws {Error} when poly does not have 512 coefficients, or one of them is not in [0, q)\n * @example\n * ```typescript\n * const result = packPoly(Array.from({ length: 512 }, (_, i) => i));\n * // result = [3009220298763626926401032896359925372832289177998513310902944456849637412n, …] (29 felts)\n * ```\n */\nexport function packPoly(poly: ArrayLike<number>): bigint[] {\n if (poly.length !== N) throw new Error(`Falcon512: polynomial must have ${N} coefficients`);\n for (let i = 0; i < N; i++) {\n const v = poly[i];\n if (!Number.isInteger(v) || v < 0 || v >= Q) {\n throw new Error('Falcon512: polynomial coefficient out of range');\n }\n }\n const out: bigint[] = [];\n for (let start = 0; start < N; start += 2 * VALUES_PER_HALF) {\n const mid = Math.min(start + VALUES_PER_HALF, N);\n const end = Math.min(start + 2 * VALUES_PER_HALF, N);\n out.push(horner(poly, start, mid) + (horner(poly, mid, end) << 128n));\n }\n return out;\n}\n\n/**\n * Unpacks 29 felt252 into 512 Zq values; only the canonical encoding is accepted.\n * @param {bigint[]} felts the 29 packed felts\n * @returns {Uint16Array} the 512 values, in [0, q)\n * @throws {Error} when there are not 29 felts, a felt is out of range, or the encoding is not\n * canonical\n * @example\n * ```typescript\n * const result = unpackPoly(packPoly(Array.from({ length: 512 }, (_, i) => i)));\n * // result = Uint16Array(512) [0, 1, 2, 3, …]\n * unpackPoly(new Array(28).fill(0n));\n * // throws Error(\"Falcon512: packed polynomial must have 29 felts\")\n * ```\n */\nexport function unpackPoly(felts: readonly bigint[]): Uint16Array {\n if (felts.length !== PACKED_SLOTS) {\n throw new Error(`Falcon512: packed polynomial must have ${PACKED_SLOTS} felts`);\n }\n const out = new Uint16Array(N);\n let idx = 0;\n // eslint-disable-next-line no-restricted-syntax\n for (const felt of felts) {\n assertFelt(felt, 'packed polynomial slot');\n // eslint-disable-next-line no-restricted-syntax\n for (const half of [felt & starknet.UINT_128_MAX, felt >> 128n]) {\n const count = Math.min(VALUES_PER_HALF, N - idx);\n if (half >= QB ** BigInt(count)) {\n throw new Error('Falcon512: non-canonical packed polynomial');\n }\n let v = half;\n for (let i = 0; i < count; i++) {\n out[idx++] = Number(v % QB);\n v /= QB;\n }\n }\n }\n return out;\n}\n","import { randomBytes as cryptoRandomBytes } from '@noble/hashes/utils.js';\nimport * as starknet from 'starknet';\nimport { nobleEngine, type FalconEngine } from '../engine/engine';\nimport { N, PACKED_SLOTS, Q, SALT_FELTS, SIG_BOUND_512, SIGNATURE_FELTS } from './constants';\nimport { assertFelt, parseFelt } from './felt';\nimport { hashToPoint } from './hashToPoint';\nimport { intt, modQ, ntt } from './ntt';\nimport { packPoly, unpackPoly } from './packing';\n\n/** Decoded S2morrow signature (Serde of PackedFalconSignatureWithHint). */\nexport type FalconStarknetSignature = { s1: Uint16Array; salt: bigint[]; mulHint: Uint16Array };\n/** Injectable dependencies of signHash (tests only). */\nexport type SignDeps = { engine: FalconEngine; randomBytes: (length: number) => Uint8Array };\n\nconst defaultDeps: SignDeps = { engine: nobleEngine, randomBytes: cryptoRandomBytes };\n\n/**\n * mul_hint = INTT(NTT(s1) ⊙ pkNtt) = s1·h mod (x^512 + 1, q).\n * @param {ArrayLike<number>} s1 the 512 coefficients of s1, in [0, q)\n * @param {ArrayLike<number>} pkNtt the NTT of the public polynomial h\n * @returns {number[]} the 512 coefficients of s1·h, in [0, q)\n * @example\n * ```typescript\n * const { publicKey } = generateKeyPair(new Uint8Array(48).fill(1));\n * const s1 = [1, ...new Array(511).fill(0)];\n * const result = computeMulHint(s1, publicKeyToNtt(publicKey));\n * // result = [6436, 5476, 5849, 5158, …] (512 values): h itself, since s1 = 1\n * ```\n */\nexport function computeMulHint(s1: ArrayLike<number>, pkNtt: ArrayLike<number>): number[] {\n const s1Ntt = ntt(s1);\n return intt(s1Ntt.map((v, i) => (v * pkNtt[i]) % Q));\n}\n\n/**\n * Square of x after centering it in (-q/2, q/2]: the norm used by falcon.cairo.\n * @param {number} x a value in [0, q)\n * @returns {number} the square of the centered value\n * @example\n * ```typescript\n * const result = centeredSquare(12288);\n * // result = 1 (12288 is -1 once centered)\n * const result2 = centeredSquare(3);\n * // result2 = 9\n * ```\n */\nconst centeredSquare = (x: number): number => {\n const c = x <= (Q - 1) / 2 ? x : Q - x;\n return c * c;\n};\n\n/**\n * Mirror of falcon.cairo `verify_with_msg_point`: NTT(s1) ⊙ pkNtt = NTT(mulHint), and\n * ‖hashPoint − mulHint‖² + ‖s1‖² ≤ SIG_BOUND_512 (centered norms). Inputs in [0, q).\n * @param {ArrayLike<number>} hashPoint the 512 coefficients of the hash point\n * @param {ArrayLike<number>} s1 the 512 coefficients of s1\n * @param {ArrayLike<number>} mulHint the 512 coefficients of the hint s1·h\n * @param {ArrayLike<number>} pkNtt the NTT of the public polynomial h\n * @returns {boolean} true when the hint is right and the signature is short enough\n * @example\n * ```typescript\n * const signature = signHash(0x1234n, secretKey, pkNtt);\n * const { s1, salt, mulHint } = parseSignature(signature);\n * const result = checkSignatureEquation(hashToPoint([0x1234n], salt), s1, mulHint, pkNtt);\n * // result = true\n * ```\n */\nexport function checkSignatureEquation(\n hashPoint: ArrayLike<number>,\n s1: ArrayLike<number>,\n mulHint: ArrayLike<number>,\n pkNtt: ArrayLike<number>\n): boolean {\n if (hashPoint.length !== N || s1.length !== N || mulHint.length !== N || pkNtt.length !== N) {\n return false;\n }\n const s1Ntt = ntt(s1);\n const hintNtt = ntt(mulHint);\n for (let i = 0; i < N; i += 1) {\n if ((s1Ntt[i] * pkNtt[i]) % Q !== hintNtt[i]) return false;\n }\n let norm = 0;\n for (let i = 0; i < N; i += 1) {\n norm += centeredSquare(modQ(hashPoint[i] - mulHint[i])) + centeredSquare(s1[i]);\n }\n return norm <= SIG_BOUND_512;\n}\n\n/**\n * 61 felts: [s1 packed (29)] [salt length] [salt…] [mul_hint packed (29)].\n * @param {FalconStarknetSignature} sig the decoded signature\n * @returns {string[]} the 61 felts, as hex strings\n * @example\n * ```typescript\n * const signature = signHash(0x1234n, secretKey, pkNtt);\n * const result = formatSignature(parseSignature(signature));\n * // result = signature (the same 61 felts); result[29] = '0x2' (salt length)\n * ```\n */\nexport function formatSignature(sig: FalconStarknetSignature): string[] {\n const felts = [\n ...packPoly(sig.s1),\n BigInt(sig.salt.length),\n ...sig.salt,\n ...packPoly(sig.mulHint),\n ];\n return felts.map((x) => starknet.num.toHex(x));\n}\n\n/**\n * Strict parsing of a 61-felt signature (hex or decimal strings, numbers, bigints).\n * @param {unknown[]} signature the 61 felts\n * @returns {FalconStarknetSignature} s1, the salt (2 felts) and mul_hint\n * @throws {Error} when the signature does not have 61 felts, a felt is invalid, or the salt\n * length is not 2\n * @example\n * ```typescript\n * const result = parseSignature(signHash(0x1234n, secretKey, pkNtt));\n * // result = { s1: Uint16Array(512) [12275, 53, 11941, 226, …], salt: [two felts], mulHint: Uint16Array(512) […] }\n * parseSignature(['0x1']);\n * // throws Error(\"Falcon512: signature must have 61 felts\")\n * ```\n */\nexport function parseSignature(signature: readonly unknown[]): FalconStarknetSignature {\n if (!Array.isArray(signature) || signature.length !== SIGNATURE_FELTS) {\n throw new Error(`Falcon512: signature must have ${SIGNATURE_FELTS} felts`);\n }\n const felts = signature.map((x, i) => parseFelt(x, `signature[${i}]`));\n if (felts[PACKED_SLOTS] !== BigInt(SALT_FELTS)) {\n throw new Error('Falcon512: unexpected salt length');\n }\n const saltStart = PACKED_SLOTS + 1;\n return {\n s1: unpackPoly(felts.slice(0, PACKED_SLOTS)),\n salt: felts.slice(saltStart, saltStart + SALT_FELTS),\n mulHint: unpackPoly(felts.slice(saltStart + SALT_FELTS)),\n };\n}\n\n/**\n * A salt felt of 248 random bits (31 bytes), always below P.\n * @param {(length: number) => Uint8Array} randomBytes the source of random bytes\n * @returns {bigint} the salt felt\n * @example\n * ```typescript\n * const result = randomSaltFelt((n) => new Uint8Array(n).fill(1));\n * // result = 1773775876797123091660094745843871137458179912157484130506396813846708481n (0x0101…01)\n * ```\n */\nconst randomSaltFelt = (randomBytes: SignDeps['randomBytes']): bigint =>\n BigInt(`0x${starknet.encode.buf2hex(randomBytes(31))}`); // 248 bits < P\n\n/**\n * Signs a message hash for the S2morrow account (internal: never exported by index.ts, to avoid\n * blind signing). The engine draws its own sampler seed, independent from the public salt. The\n * encoded signature is re-checked (reusing the hash point) before being returned.\n * @param {bigint} msgHash the hash to sign, a felt252\n * @param {Uint8Array} secretKey the NIST Falcon-512 secret key (1281 bytes)\n * @param {Uint16Array} pkNtt the NTT of the public polynomial h\n * @param {SignDeps} [deps] the engine and the random source (tests only)\n * @returns {string[]} the 61 felts of the signature\n * @throws {Error} when msgHash is not a felt252, or the self-verification fails\n * @example\n * ```typescript\n * const { secretKey, publicKey } = generateKeyPair(new Uint8Array(48).fill(1));\n * const result = signHash(0x1234n, secretKey, publicKeyToNtt(publicKey));\n * // result = ['0x…', …] (61 felts, random salt); result[29] = '0x2'\n * ```\n */\nexport function signHash(\n msgHash: bigint,\n secretKey: Uint8Array,\n pkNtt: Uint16Array,\n deps: SignDeps = defaultDeps\n): string[] {\n assertFelt(msgHash, 'message hash');\n const salt = [randomSaltFelt(deps.randomBytes), randomSaltFelt(deps.randomBytes)];\n const hashPoint = hashToPoint([msgHash], salt);\n const s2 = deps.engine.signHashPoint(hashPoint, secretKey);\n const s1 = Uint16Array.from(s2, modQ);\n const mulHint = Uint16Array.from(computeMulHint(s1, pkNtt));\n const signature = formatSignature({ s1, salt, mulHint });\n const decoded = parseSignature(signature);\n if (!checkSignatureEquation(hashPoint, decoded.s1, decoded.mulHint, pkNtt)) {\n throw new Error('Falcon512: self-verification failed, signature discarded');\n }\n return signature;\n}\n\n/**\n * Verifies a 61-felt signature of msgHash; false for any malformed input.\n * @param {bigint} msgHash the signed hash\n * @param {unknown[]} signature the 61 felts\n * @param {ArrayLike<number>} pkNtt the NTT of the public polynomial h\n * @returns {boolean} true for a valid signature of msgHash, false otherwise\n * @example\n * ```typescript\n * const signature = signHash(0x1234n, secretKey, pkNtt);\n * const result = verifyHash(0x1234n, signature, pkNtt);\n * // result = true\n * const result2 = verifyHash(0x1235n, signature, pkNtt);\n * // result2 = false\n * ```\n */\nexport function verifyHash(\n msgHash: bigint,\n signature: readonly unknown[],\n pkNtt: ArrayLike<number>\n): boolean {\n let decoded: FalconStarknetSignature;\n try {\n assertFelt(msgHash, 'message hash');\n decoded = parseSignature(signature);\n } catch {\n return false;\n }\n return checkSignatureEquation(\n hashToPoint([msgHash], decoded.salt),\n decoded.s1,\n decoded.mulHint,\n pkNtt\n );\n}\n","/* eslint-disable no-bitwise */\n/* eslint-disable no-plusplus */\nimport { poseidonHashMany, poseidonSmall } from '@scure/starknet';\nimport * as starknet from 'starknet';\nimport { N, QB } from './constants';\nimport { assertFelt } from './felt';\n\n/**\n * S2morrow Poseidon hash-to-point (same as falcon-rs poseidon_hash.rs and the Cairo contract):\n * seed = poseidon_hash_span(message ‖ salt); state = [seed, 0, 0]; 21 Hades permutations each give\n * 12 base-Q digits from state[0] and 12 from state[1], a 22nd gives the last 8 from state[0].\n * Each felt yields 6 digits from its low u128, then 6 from its high u128.\n * @param {bigint[]} message the felts of the message (here, one felt: the hash to sign)\n * @param {bigint[]} salt the felts of the salt (two felts for this signer)\n * @returns {Uint16Array} the hash point: 512 coefficients in [0, q)\n * @throws {Error} when an element is not a felt252\n * @example\n * ```typescript\n * const result = hashToPoint([42n], [1n, 2n]);\n * // result = Uint16Array(512) [3798, 10958, 659, 9391, …]\n * ```\n */\nexport function hashToPoint(message: readonly bigint[], salt: readonly bigint[]): Uint16Array {\n message.forEach((m) => assertFelt(m, 'message element'));\n salt.forEach((s) => assertFelt(s, 'salt element'));\n const out = new Uint16Array(N);\n let idx = 0;\n const extract6 = (value: bigint): void => {\n let v = value;\n for (let i = 0; i < 6 && idx < N; i++) {\n out[idx++] = Number(v % QB);\n v /= QB;\n }\n };\n const extract12 = (felt: bigint): void => {\n extract6(felt & starknet.UINT_128_MAX);\n extract6(felt >> 128n);\n };\n let state: bigint[] = [poseidonHashMany([...message, ...salt]), 0n, 0n];\n for (let round = 0; round < 21; round++) {\n state = poseidonSmall(state);\n extract12(state[0]);\n extract12(state[1]);\n }\n state = poseidonSmall(state);\n extract12(state[0]);\n return out;\n}\n","/* eslint-disable no-bitwise */\n// Hash-to-point of the OpenZeppelin Falcon-512 accounts (OpenZeppelin Contracts for Cairo\n// v4.1.0-rc.0, README of packages/account, \"Key and signature encoding\").\nimport { shake256 } from '@noble/hashes/sha3.js';\nimport { N, Q } from '../s2morrow/constants';\nimport { assertFelt } from '../s2morrow/felt';\n\n/** Number of bytes that one salt felt of an OpenZeppelin signature encodes. */\nexport const SALT_BYTES = 20;\n\n/** A salt felt must be below 2^160 (20 bytes). */\nconst SALT_LIMIT = 1n << BigInt(8 * SALT_BYTES);\n\n/** Words of 5q or more are skipped: 61445 is the largest multiple of q below 2^16. */\nconst KQ = 5 * Q;\n\n/**\n * Writes x into out[offset … offset + length - 1], least significant byte first.\n * @param {bigint} x the value to write; it must fit in `length` bytes\n * @param {Uint8Array} out the array that receives the bytes\n * @param {number} offset index of the first byte to write\n * @param {number} length number of bytes to write\n * @example\n * ```typescript\n * const out = new Uint8Array(4);\n * writeLittleEndian(0x0102n, out, 0, 4);\n * // out = Uint8Array(4) [2, 1, 0, 0]\n * ```\n */\nconst writeLittleEndian = (x: bigint, out: Uint8Array, offset: number, length: number): void => {\n let v = x;\n for (let i = 0; i < length; i += 1) {\n // eslint-disable-next-line no-param-reassign\n out[offset + i] = Number(v & 0xffn);\n v >>= 8n;\n }\n};\n\n/**\n * The 40 bytes of the salt of an OpenZeppelin signature: salt_a, then salt_b, each on 20 bytes,\n * least significant byte first.\n * @param {bigint} saltA the first salt felt\n * @param {bigint} saltB the second salt felt\n * @returns {Uint8Array} the 40 bytes of the salt\n * @throws {Error} when a salt felt is negative, or not below 2^160\n * @example\n * ```typescript\n * const result = saltFeltsToBytes(1n, 2n);\n * // result = Uint8Array(40) [1, 0, 0, …, 2, 0, 0, …] (1 at index 0, 2 at index 20)\n * ```\n */\nexport function saltFeltsToBytes(saltA: bigint, saltB: bigint): Uint8Array {\n [saltA, saltB].forEach((salt) => {\n if (typeof salt !== 'bigint' || salt < 0n || salt >= SALT_LIMIT) {\n throw new Error('Falcon512: salt felt must be non-negative and below 2^160');\n }\n });\n const out = new Uint8Array(2 * SALT_BYTES);\n writeLittleEndian(saltA, out, 0, SALT_BYTES);\n writeLittleEndian(saltB, out, SALT_BYTES, SALT_BYTES);\n return out;\n}\n\n/**\n * OpenZeppelin hash-to-point: SHAKE-256 over salt_a (20 bytes) ‖ salt_b (20 bytes) ‖ the message\n * hash (32 bytes), all little-endian. The output is read as big-endian 16-bit words; words of 5q\n * (61445) or more are skipped, the others are reduced modulo q, until there are 512 coefficients.\n * This is the HashToPoint of the Falcon submission, with the 40 salt bytes as its nonce.\n * @param {bigint} msgHash the hash to sign, a felt252\n * @param {bigint} saltA the first salt felt, below 2^160\n * @param {bigint} saltB the second salt felt, below 2^160\n * @returns {Uint16Array} the hash point: 512 coefficients in [0, q)\n * @throws {Error} when msgHash is not a felt252, or a salt felt is not below 2^160\n * @example\n * ```typescript\n * const result = hashToPointShake(42n, 1n, 2n);\n * // result = Uint16Array(512) [5836, 973, 11428, 8040, …]\n * ```\n */\nexport function hashToPointShake(msgHash: bigint, saltA: bigint, saltB: bigint): Uint16Array {\n assertFelt(msgHash, 'message hash');\n const message = new Uint8Array(32);\n writeLittleEndian(msgHash, message, 0, 32);\n const xof = shake256.create().update(saltFeltsToBytes(saltA, saltB)).update(message);\n const out = new Uint16Array(N);\n for (let i = 0; i < N;) {\n const [high, low] = xof.xof(2);\n const word = (high << 8) | low;\n if (word < KQ) {\n out[i] = word % Q;\n i += 1;\n }\n }\n return out;\n}\n","/* eslint-disable no-bitwise */\n/* eslint-disable no-plusplus */\nimport { isBytes } from '@noble/hashes/utils.js';\nimport * as starknet from 'starknet';\nimport { nobleEngine } from '../engine/engine';\nimport { N, Q } from './constants';\nimport { divZq, modQ, mulNegacyclicInt, mulZq, ntt } from './ntt';\nimport { packPoly } from './packing';\n\nexport const SECRET_KEY_LENGTH = 1281;\nexport const PUBLIC_KEY_LENGTH = 897;\nexport const SEED_LENGTH = 48;\nexport const FALCON_RS_SECRET_KEY_LENGTH = 3584;\nconst FALCON_RS_POLY_LENGTH = 896;\nconst SECRET_KEY_HEADER = 0x59; // 0x50 + log2(512)\nconst PUBLIC_KEY_HEADER = 0x09; // 0x00 + log2(512)\nconst FG_BITS = 6;\nconst CAPITAL_FG_BITS = 8;\nconst FG_MAX = 31; // 2^(6-1) - 1\nconst CAPITAL_FG_MAX = 127; // 2^(8-1) - 1\nconst FG_BYTES = (N * FG_BITS) / 8; // 384\n\nexport type Falcon512KeyPair = { secretKey: Uint8Array; publicKey: Uint8Array };\n/** NTRU secret polynomials, with f·G − g·F = q. */\nexport type SecretPolys = { f: Int8Array; g: Int8Array; F: Int8Array; G: Int8Array };\n\n/** An array that `wipe` can overwrite with zeros. */\ntype Wipeable = { fill(value: number): unknown };\n\n/**\n * Copies a Uint8Array, or reads a hex string (with or without 0x), of exactly `expectedLength`\n * bytes. The length is checked first, so `num.hexToBytes` never pads an odd-length string.\n * @param {Uint8Array | string} input the bytes, or their hex string\n * @param {number} expectedLength the number of bytes expected\n * @param {string} label the name of the value, used in the error messages\n * @returns {Uint8Array} a copy of the bytes\n * @throws {Error} when the input is neither bytes nor a hex string, or has another length\n * @example\n * ```typescript\n * const result = toBytes('0x0102', 2, 'key');\n * // result = Uint8Array(2) [1, 2]\n * toBytes('0x010', 2, 'key');\n * // throws Error(\"Falcon512: key must have 4 hex digits, got 3\")\n * ```\n */\nexport function toBytes(\n input: Uint8Array | string,\n expectedLength: number,\n label: string\n): Uint8Array {\n if (isBytes(input)) {\n if (input.length !== expectedLength) {\n throw new Error(`Falcon512: ${label} must be ${expectedLength} bytes, got ${input.length}`);\n }\n return Uint8Array.from(input);\n }\n if (typeof input !== 'string') {\n throw new Error(`Falcon512: ${label} must be a Uint8Array or a hex string`);\n }\n const hex = starknet.encode.removeHexPrefix(input);\n if (!/^[0-9a-fA-F]*$/.test(hex)) {\n throw new Error(`Falcon512: ${label} is not a valid hex string`);\n }\n if (hex.length !== 2 * expectedLength) {\n throw new Error(\n `Falcon512: ${label} must have ${2 * expectedLength} hex digits, got ${hex.length}`\n );\n }\n return starknet.num.hexToBytes(starknet.encode.addHexPrefix(hex));\n}\n\n/**\n * Overwrites arrays with zeros (best-effort wiping of secret values).\n * @param {...Wipeable} arrays the arrays to wipe\n * @example\n * ```typescript\n * const secret = Uint8Array.from([1, 2]);\n * wipe(secret);\n * // secret = Uint8Array(2) [0, 0]\n * ```\n */\nconst wipe = (...arrays: Wipeable[]): void => {\n arrays.forEach((a) => a.fill(0));\n};\n\n/**\n * Centers a value of [0, q) in (-q/2, q/2].\n * @param {number} x a value in [0, q)\n * @returns {number} the centered value\n * @example\n * ```typescript\n * const result = center(12288);\n * // result = -1\n * const result2 = center(6144);\n * // result2 = 6144\n * const result3 = center(6145);\n * // result3 = -6144\n * ```\n */\nconst center = (x: number): number => (x > Q >> 1 ? x - Q : x);\n\n/**\n * Reads the low `bits` bits of raw as a two's complement number.\n * @param {number} raw the unsigned value\n * @param {number} bits the width of the value\n * @returns {number} the signed value\n * @example\n * ```typescript\n * const result = toSigned(0x3f, 6);\n * // result = -1\n * const result2 = toSigned(0x1f, 6);\n * // result2 = 31\n * ```\n */\nconst toSigned = (raw: number, bits: number): number => (raw << (32 - bits)) >> (32 - bits);\n\n/**\n * NIST encoding: packs values of `bits` bits each, most significant bit first.\n * @param {ArrayLike<number>} values the values (only their low `bits` bits are kept)\n * @param {number} bits the width of each value\n * @returns {Uint8Array} the packed bytes\n * @example\n * ```typescript\n * const result = encodeBitsMSB([1, 2, 3, 4], 6);\n * // result = Uint8Array(3) [4, 32, 196]\n * ```\n */\nfunction encodeBitsMSB(values: ArrayLike<number>, bits: number): Uint8Array {\n const out = new Uint8Array((values.length * bits) / 8);\n const mask = (1 << bits) - 1;\n let acc = 0;\n let accBits = 0;\n let pos = 0;\n for (let i = 0; i < values.length; i++) {\n acc = (acc << bits) | (values[i] & mask);\n accBits += bits;\n while (accBits >= 8) {\n accBits -= 8;\n out[pos++] = (acc >>> accBits) & 0xff;\n }\n acc &= (1 << accBits) - 1;\n }\n return out;\n}\n\n/**\n * NIST decoding: reads `count` values of `bits` bits each, most significant bit first.\n * @param {Uint8Array} bytes the packed bytes\n * @param {number} count the number of values\n * @param {number} bits the width of each value\n * @returns {number[]} the unsigned values\n * @throws {Error} when the number of bytes does not match count × bits\n * @example\n * ```typescript\n * const result = decodeBitsMSB(Uint8Array.from([4, 32, 196]), 4, 6);\n * // result = [1, 2, 3, 4]\n * ```\n */\nfunction decodeBitsMSB(bytes: Uint8Array, count: number, bits: number): number[] {\n if (bytes.length * 8 !== count * bits) throw new Error('Falcon512: invalid encoding length');\n const out: number[] = [];\n const mask = (1 << bits) - 1;\n let acc = 0;\n let accBits = 0;\n for (let i = 0; i < bytes.length; i++) {\n acc = (acc << 8) | bytes[i];\n accBits += 8;\n while (accBits >= bits) {\n accBits -= bits;\n out.push((acc >>> accBits) & mask);\n }\n acc &= (1 << accBits) - 1;\n }\n return out;\n}\n\n/**\n * falcon-rs encoding: packs values mod q on 14 bits each, least significant bit first, into 896\n * bytes.\n * @param {ArrayLike<number>} values the values, in [0, q)\n * @returns {Uint8Array} the 896 bytes\n * @example\n * ```typescript\n * const result = encode14LSB([1, 2]);\n * // result = Uint8Array(896) [1, 128, 0, 0, …]\n * ```\n */\nfunction encode14LSB(values: ArrayLike<number>): Uint8Array {\n const out = new Uint8Array(FALCON_RS_POLY_LENGTH);\n let acc = 0;\n let accBits = 0;\n let pos = 0;\n for (let i = 0; i < values.length; i++) {\n acc |= values[i] << accBits;\n accBits += 14;\n while (accBits >= 8) {\n out[pos++] = acc & 0xff;\n acc >>>= 8;\n accBits -= 8;\n }\n }\n return out;\n}\n\n/**\n * falcon-rs decoding: reads 512 values of 14 bits, least significant bit first. A partial result\n * is wiped when a value is refused.\n * @param {Uint8Array} bytes the 896 bytes of one polynomial\n * @returns {number[]} the 512 values, in [0, q)\n * @throws {Error} when a value is not below q\n * @example\n * ```typescript\n * const result = decode14LSB(encode14LSB(new Array(512).fill(5)));\n * // result = [5, 5, 5, …] (512 values)\n * ```\n */\nfunction decode14LSB(bytes: Uint8Array): number[] {\n const out: number[] = [];\n let acc = 0;\n let accBits = 0;\n let pos = 0;\n try {\n for (let i = 0; i < N; i++) {\n while (accBits < 14) {\n acc |= bytes[pos++] << accBits;\n accBits += 8;\n }\n const v = acc & 0x3fff;\n acc >>>= 14;\n accBits -= 14;\n if (v >= Q) {\n throw new Error('Falcon512: invalid falcon-rs secret key (coefficient out of range)');\n }\n out.push(v);\n }\n return out;\n } catch (error) {\n wipe(out);\n throw error;\n }\n}\n\n/**\n * Throws if a coefficient is outside [-max, max].\n * @param {ArrayLike<number>} poly the coefficients\n * @param {number} max the largest absolute value allowed\n * @param {string} label the name of the polynomial, used in the error message\n * @throws {Error} when a coefficient is out of range\n * @example\n * ```typescript\n * checkRange([1, -2, 31], 31, 'f');\n * // passes\n * checkRange([32], 31, 'f');\n * // throws Error(\"Falcon512: invalid secret key (f coefficient out of range)\")\n * ```\n */\nfunction checkRange(poly: ArrayLike<number>, max: number, label: string): void {\n for (let i = 0; i < poly.length; i++) {\n if (poly[i] < -max || poly[i] > max) {\n throw new Error(`Falcon512: invalid secret key (${label} coefficient out of range)`);\n }\n }\n}\n\n/**\n * G = g·F / f mod q, centered; throws if f is not invertible or G is not small.\n * @param {Int8Array} f the secret polynomial f\n * @param {Int8Array} g the secret polynomial g\n * @param {Int8Array} F the secret polynomial F\n * @returns {Int8Array} the secret polynomial G\n * @throws {Error} when f is not invertible mod q, or G has a coefficient out of range\n * @example\n * ```typescript\n * const { f, g, F } = decodeSecretKey(generateKeyPair(new Uint8Array(48).fill(1)).secretKey);\n * const result = completeG(f, g, F);\n * // result = Int8Array(512) [37, 8, 43, -40, …]\n * ```\n */\nfunction completeG(f: Int8Array, g: Int8Array, F: Int8Array): Int8Array {\n const gF = mulZq(g, F);\n let quotient: number[] = [];\n let G: number[] = [];\n try {\n quotient = divZq(gF, f);\n G = quotient.map(center);\n checkRange(G, CAPITAL_FG_MAX, 'G');\n return Int8Array.from(G);\n } finally {\n wipe(gF, quotient, G);\n }\n}\n\n/**\n * Checks the NTRU equation f·G − g·F = q over Z[x]/(x^512 + 1).\n * @param {SecretPolys} polys the four secret polynomials\n * @throws {Error} when the equation does not hold\n * @example\n * ```typescript\n * const { f, g, F, G } = decodeSecretKey(secretKey);\n * checkNtruEquation({ f, g, F, G });\n * // passes\n * checkNtruEquation({ f, g, F: Int8Array.from(F, (v) => -v), G });\n * // throws Error(\"Falcon512: invalid secret key (NTRU equation not satisfied)\")\n * ```\n */\nfunction checkNtruEquation({ f, g, F, G }: SecretPolys): void {\n const fG = mulNegacyclicInt(f, G);\n const gF = mulNegacyclicInt(g, F);\n try {\n for (let i = 0; i < N; i++) {\n if (fG[i] - gF[i] !== (i === 0 ? Q : 0)) {\n throw new Error('Falcon512: invalid secret key (NTRU equation not satisfied)');\n }\n }\n } finally {\n wipe(fG, gF);\n }\n}\n\n/**\n * Decodes one signed polynomial of a NIST secret key; the smallest value of the width is refused.\n * @param {Uint8Array} bytes the encoded polynomial\n * @param {number} bits the width of each coefficient (6 for f and g, 8 for F)\n * @param {string} label the name of the polynomial, used in the error message\n * @returns {Int8Array} the 512 coefficients\n * @throws {Error} when a coefficient has the forbidden value -2^(bits-1)\n * @example\n * ```typescript\n * const { secretKey } = generateKeyPair(new Uint8Array(48).fill(1));\n * const result = decodeSigned(secretKey.subarray(1, 385), 6, 'f');\n * // result = Int8Array(512) [0, 1, -4, 1, …]\n * ```\n */\nfunction decodeSigned(bytes: Uint8Array, bits: number, label: string): Int8Array {\n const min = -(1 << (bits - 1));\n const raw = decodeBitsMSB(bytes, N, bits);\n try {\n return Int8Array.from(raw, (value) => {\n const v = toSigned(value, bits);\n if (v === min) {\n throw new Error(`Falcon512: invalid secret key (forbidden ${label} coefficient)`);\n }\n return v;\n });\n } finally {\n wipe(raw);\n }\n}\n\n/**\n * Decodes and fully validates a NIST Falcon-512 secret key. The caller must wipe the result.\n * @param {Uint8Array | string} secretKey the NIST secret key (1281 bytes), or its hex string\n * @returns {SecretPolys} the four NTRU polynomials f, g, F, G\n * @throws {Error} when the key has a wrong length or header, a coefficient out of range, or does\n * not satisfy the NTRU equation\n * @example\n * ```typescript\n * const result = decodeSecretKey(generateKeyPair(new Uint8Array(48).fill(1)).secretKey);\n * // result = { f: Int8Array(512) [0, 1, -4, 1, …], g: Int8Array(512) [1, 3, -1, -2, …],\n * // F: Int8Array(512) [-32, 20, -61, -5, …], G: Int8Array(512) [37, 8, 43, -40, …] }\n * ```\n */\nexport function decodeSecretKey(secretKey: Uint8Array | string): SecretPolys {\n const bytes = toBytes(secretKey, SECRET_KEY_LENGTH, 'secret key');\n const parts: Int8Array[] = [];\n try {\n if (bytes[0] !== SECRET_KEY_HEADER) throw new Error('Falcon512: invalid secret key header');\n const f = decodeSigned(bytes.subarray(1, 1 + FG_BYTES), FG_BITS, 'f');\n parts.push(f);\n const g = decodeSigned(bytes.subarray(1 + FG_BYTES, 1 + 2 * FG_BYTES), FG_BITS, 'g');\n parts.push(g);\n const F = decodeSigned(bytes.subarray(1 + 2 * FG_BYTES), CAPITAL_FG_BITS, 'F');\n parts.push(F);\n const G = completeG(f, g, F);\n parts.push(G);\n const polys = { f, g, F, G };\n checkNtruEquation(polys);\n return polys;\n } catch (error) {\n wipe(...parts);\n throw error;\n } finally {\n wipe(bytes);\n }\n}\n\n/**\n * Encodes f, g, F into a NIST Falcon-512 secret key.\n * @param {Pick<SecretPolys, 'f' | 'g' | 'F'>} polys the secret polynomials f, g and F\n * @returns {Uint8Array} the NIST secret key (1281 bytes)\n * @throws {Error} when a coefficient is out of range\n * @example\n * ```typescript\n * const { secretKey } = generateKeyPair(new Uint8Array(48).fill(1));\n * const result = encodeSecretKey(decodeSecretKey(secretKey));\n * // result = Uint8Array(1281) [89, 0, 31, 1, 255, 255, …] (the same bytes as secretKey)\n * ```\n */\nexport function encodeSecretKey({ f, g, F }: Pick<SecretPolys, 'f' | 'g' | 'F'>): Uint8Array {\n checkRange(f, FG_MAX, 'f');\n checkRange(g, FG_MAX, 'g');\n checkRange(F, CAPITAL_FG_MAX, 'F');\n const fBits = Array.from(f, (v) => v & 0x3f);\n const gBits = Array.from(g, (v) => v & 0x3f);\n const capitalFBits = Array.from(F, (v) => v & 0xff);\n const encoded = [\n encodeBitsMSB(fBits, FG_BITS),\n encodeBitsMSB(gBits, FG_BITS),\n encodeBitsMSB(capitalFBits, CAPITAL_FG_BITS),\n ];\n try {\n const out = new Uint8Array(SECRET_KEY_LENGTH);\n out[0] = SECRET_KEY_HEADER;\n out.set(encoded[0], 1);\n out.set(encoded[1], 1 + FG_BYTES);\n out.set(encoded[2], 1 + 2 * FG_BYTES);\n return out;\n } finally {\n wipe(fBits, gBits, capitalFBits, ...encoded);\n }\n}\n\n/**\n * Decodes a NIST Falcon-512 public key into h (coefficients in [0, q)).\n * @param {Uint8Array | string} publicKey the NIST public key (897 bytes), or its hex string\n * @returns {Uint16Array} the 512 coefficients of h\n * @throws {Error} when the key has a wrong length or header, or a coefficient is not below q\n * @example\n * ```typescript\n * const result = decodePublicKey(generateKeyPair(new Uint8Array(48).fill(1)).publicKey);\n * // result = Uint16Array(512) [6436, 5476, 5849, 5158, …]\n * ```\n */\nexport function decodePublicKey(publicKey: Uint8Array | string): Uint16Array {\n const bytes = toBytes(publicKey, PUBLIC_KEY_LENGTH, 'public key');\n if (bytes[0] !== PUBLIC_KEY_HEADER) throw new Error('Falcon512: invalid public key header');\n const h = decodeBitsMSB(bytes.subarray(1), N, 14);\n if (h.some((v) => v >= Q)) {\n throw new Error('Falcon512: invalid public key (coefficient out of range)');\n }\n return Uint16Array.from(h);\n}\n\n/**\n * Encodes h into a NIST Falcon-512 public key.\n * @param {ArrayLike<number>} h the 512 coefficients of h, in [0, q)\n * @returns {Uint8Array} the NIST public key (897 bytes)\n * @throws {Error} when h does not have 512 coefficients, or one of them is not in [0, q)\n * @example\n * ```typescript\n * const { publicKey } = generateKeyPair(new Uint8Array(48).fill(1));\n * const result = encodePublicKey(decodePublicKey(publicKey));\n * // result = Uint8Array(897) [9, 100, 145, 86, 69, 182, …] (the same bytes as publicKey)\n * ```\n */\nexport function encodePublicKey(h: ArrayLike<number>): Uint8Array {\n if (h.length !== N) {\n throw new Error(`Falcon512: public key polynomial must have ${N} coefficients`);\n }\n for (let i = 0; i < N; i++) {\n if (!Number.isInteger(h[i]) || h[i] < 0 || h[i] >= Q) {\n throw new Error('Falcon512: invalid public key (coefficient out of range)');\n }\n }\n const out = new Uint8Array(PUBLIC_KEY_LENGTH);\n out[0] = PUBLIC_KEY_HEADER;\n out.set(encodeBitsMSB(h, 14), 1);\n return out;\n}\n\n/**\n * New key pair (NIST formats). The optional seed must be 48 bytes from a CSPRNG.\n * @param {Uint8Array} [seed] 48 random bytes; by default, drawn by the engine\n * @returns {Falcon512KeyPair} the secret key (1281 bytes) and the public key (897 bytes)\n * @throws {Error} when the seed is not 48 bytes\n * @example\n * ```typescript\n * const result = falcon512.generateKeyPair();\n * // result = { secretKey: Uint8Array(1281) [89, …], publicKey: Uint8Array(897) [9, …] }\n * // A new random key at each call; 89 (0x59) and 9 (0x09) are the headers of the two formats.\n * ```\n */\nexport function generateKeyPair(seed?: Uint8Array): Falcon512KeyPair {\n if (seed !== undefined && (!isBytes(seed) || seed.length !== SEED_LENGTH)) {\n throw new Error(`Falcon512: seed must be a Uint8Array of ${SEED_LENGTH} bytes`);\n }\n return nobleEngine.keygen(seed);\n}\n\n/**\n * Public key h = g / f mod q of a validated secret key (NIST format).\n * @param {Uint8Array | string} secretKey the NIST secret key (1281 bytes), or its hex string\n * @returns {Uint8Array} the NIST public key (897 bytes)\n * @throws {Error} when the secret key is invalid\n * @example\n * ```typescript\n * const { secretKey, publicKey } = falcon512.generateKeyPair();\n * const result = falcon512.getPublicKey(secretKey);\n * // result = Uint8Array(897) [9, …] (the same bytes as publicKey)\n * ```\n */\nexport function getPublicKey(secretKey: Uint8Array | string): Uint8Array {\n const polys = decodeSecretKey(secretKey);\n try {\n return encodePublicKey(divZq(polys.g, polys.f));\n } finally {\n wipe(polys.f, polys.g, polys.F, polys.G);\n }\n}\n\n/**\n * NTT of h, as stored by the S2morrow account.\n * @param {Uint8Array | string} publicKey the NIST public key (897 bytes), or its hex string\n * @returns {Uint16Array} the 512 values of NTT(h)\n * @throws {Error} when the public key is invalid\n * @example\n * ```typescript\n * const result = publicKeyToNtt(generateKeyPair(new Uint8Array(48).fill(1)).publicKey);\n * // result = Uint16Array(512) [11282, 2302, 6547, 2550, …]\n * ```\n */\nexport function publicKeyToNtt(publicKey: Uint8Array | string): Uint16Array {\n return Uint16Array.from(ntt(decodePublicKey(publicKey)));\n}\n\n/**\n * The 29 felts of the account constructor argument `pk_packed`.\n * @param {Uint8Array | string} publicKey the NIST public key (897 bytes), or its hex string\n * @returns {string[]} the 29 felts, as hex strings\n * @throws {Error} when the public key is invalid\n * @example\n * ```typescript\n * const { publicKey } = falcon512.generateKeyPair();\n * const result = falcon512.getPackedPublicKey(publicKey);\n * // result = ['0x…', …] (29 felts)\n * ```\n */\nexport function getPackedPublicKey(publicKey: Uint8Array | string): string[] {\n return packPoly(publicKeyToNtt(publicKey)).map((x) => starknet.num.toHex(x));\n}\n\n/**\n * Converts a falcon-rs secret key (f‖g‖F‖G, 4 × 896 bytes) into a NIST secret key.\n *\n * Warning: falcon-rs derives the seed of its sampler from the public salt of each signature, so the\n * signatures it produced may leak information about the secret key. Import such a key for\n * continuity only; for real funds, generate a new key with `generateKeyPair`.\n * @param {Uint8Array | string} secretKey the falcon-rs secret key (3584 bytes), or its hex string\n * @returns {Uint8Array} the NIST secret key (1281 bytes)\n * @throws {Error} when the key has a wrong length, a coefficient out of range, a G that does not\n * match f, g, F, or does not satisfy the NTRU equation\n * @example\n * ```typescript\n * const result = falcon512.importFalconRsSecretKey(falconRsSecretKey);\n * // result = Uint8Array(1281) [89, …] (NIST header 0x59)\n * ```\n */\nexport function importFalconRsSecretKey(secretKey: Uint8Array | string): Uint8Array {\n const bytes = toBytes(secretKey, FALCON_RS_SECRET_KEY_LENGTH, 'falcon-rs secret key');\n const parts: Wipeable[] = [];\n try {\n const names = ['f', 'g', 'F', 'G'];\n const [f, g, F, G] = names.map((name, k) => {\n const chunk = bytes.subarray(k * FALCON_RS_POLY_LENGTH, (k + 1) * FALCON_RS_POLY_LENGTH);\n const decoded = decode14LSB(chunk);\n parts.push(decoded);\n const poly = decoded.map(center);\n parts.push(poly);\n checkRange(poly, k < 2 ? FG_MAX : CAPITAL_FG_MAX, name);\n const p = Int8Array.from(poly);\n parts.push(p);\n return p;\n });\n const recomputed = completeG(f, g, F);\n parts.push(recomputed);\n if (recomputed.some((v, i) => v !== G[i])) {\n throw new Error('Falcon512: invalid falcon-rs secret key (G does not match f, g, F)');\n }\n checkNtruEquation({ f, g, F, G });\n return encodeSecretKey({ f, g, F });\n } finally {\n wipe(bytes, ...parts);\n }\n}\n\n/**\n * Converts a NIST secret key into the falcon-rs format (f‖g‖F‖G, 4 × 896 bytes).\n *\n * Warning: falcon-rs derives the seed of its sampler from the public salt of each signature, so\n * signing with falcon-rs exposes the key: keep signing with this library.\n * @param {Uint8Array | string} secretKey the NIST secret key (1281 bytes), or its hex string\n * @returns {Uint8Array} the falcon-rs secret key (3584 bytes)\n * @throws {Error} when the secret key is invalid\n * @example\n * ```typescript\n * const { secretKey } = falcon512.generateKeyPair();\n * const result = falcon512.exportFalconRsSecretKey(secretKey);\n * // result = Uint8Array(3584) […]\n * ```\n */\nexport function exportFalconRsSecretKey(secretKey: Uint8Array | string): Uint8Array {\n const polys = decodeSecretKey(secretKey);\n const parts: Wipeable[] = [];\n try {\n const out = new Uint8Array(FALCON_RS_SECRET_KEY_LENGTH);\n [polys.f, polys.g, polys.F, polys.G].forEach((p, k) => {\n const values = Array.from(p, modQ);\n const encoded = encode14LSB(values);\n parts.push(values, encoded);\n out.set(encoded, k * FALCON_RS_POLY_LENGTH);\n });\n return out;\n } finally {\n wipe(polys.f, polys.g, polys.F, polys.G, ...parts);\n }\n}\n","// Falcon-512 helpers, exposed by index.ts as the `falcon512` namespace\n// (same style as `ec.starkCurve` or `typedData` in starknet.js).\nexport { verify, verifyMessage } from './verify';\nexport {\n exportFalconRsSecretKey,\n generateKeyPair,\n getPackedPublicKey,\n getPublicKey,\n importFalconRsSecretKey,\n} from './s2morrow/keys';\n","import * as starknet from 'starknet';\nimport { parseFalconOptions, type Falcon512Options } from './accountType';\nimport { verifyHashOz } from './oz/signature';\nimport { PACKED_SLOTS } from './s2morrow/constants';\nimport { parseFelt } from './s2morrow/felt';\nimport { publicKeyToNtt } from './s2morrow/keys';\nimport { unpackPoly } from './s2morrow/packing';\nimport { verifyHash } from './s2morrow/signature';\n\n/**\n * Strict parsing (see `parseFelt`): \"\", \" \", \"0x\", a text or a boolean is not a message hash.\n * @param {BigNumberish} value the message hash\n * @returns {bigint | undefined} the hash as a bigint, or undefined when it is not a valid felt252\n * @example\n * ```typescript\n * const result = toMessageHash('0x1234');\n * // result = 4660n\n * const result2 = toMessageHash('0x');\n * // result2 = undefined\n * ```\n */\nfunction toMessageHash(value: starknet.BigNumberish): bigint | undefined {\n try {\n return parseFelt(value, 'message hash');\n } catch {\n return undefined;\n }\n}\n\n/**\n * NTT of the public polynomial h, from a NIST public key or from the 29 felts of a packed key.\n * @param {Uint8Array | string | BigNumberish[]} fullPublicKey the NIST key (897 bytes, or its hex\n * string), or the 29 felts of the packed key\n * @returns {Uint16Array} the 512 values of NTT(h)\n * @throws {Error} when the NIST key is invalid, or the packed key does not have 29 felts, has an\n * invalid felt, or is not canonical\n * @example\n * ```typescript\n * const { publicKey } = falcon512.generateKeyPair();\n * const result = toPkNtt(falcon512.getPackedPublicKey(publicKey));\n * // result = toPkNtt(publicKey) = Uint16Array(512) […]\n * ```\n */\nfunction toPkNtt(\n fullPublicKey: Uint8Array | string | readonly starknet.BigNumberish[]\n): Uint16Array {\n if (Array.isArray(fullPublicKey)) {\n if (fullPublicKey.length !== PACKED_SLOTS) {\n throw new Error(`Falcon512: packed public key must have ${PACKED_SLOTS} felts`);\n }\n return unpackPoly(fullPublicKey.map((x, i) => parseFelt(x, `public key[${i}]`)));\n }\n return publicKeyToNtt(fullPublicKey as Uint8Array | string);\n}\n\n/**\n * Low-level verification, same shape as `ec.starkCurve.verify(signature, msgHash, fullPublicKey)`.\n * @param {Signature} signature the felts of a Falcon-512 signature: 61 (S2morrow), 60\n * (OpenZeppelin, hint) or 31 (OpenZeppelin, direct)\n * @param {BigNumberish} msgHash the signed hash (a transaction hash, or the hash of a SNIP-12\n * message)\n * @param {Uint8Array | string | BigNumberish[]} fullPublicKey the public key: the NIST Falcon-512\n * key (897 bytes, as returned by `getPubKey()`), or the 29 felts of the packed key (as returned by\n * `getPackedPublicKey()`, or by `get_public_key` of an OpenZeppelin account)\n * @param {Falcon512Options} [options] `accountType`: the signature layout to check, `'s2morrow'`\n * (default), `'oz-hint'` or `'oz-direct'`\n * @returns {boolean} true for a valid signature of msgHash in this layout; false for an invalid or\n * malformed signature, a signature in another layout, or a malformed hash\n * @throws {Error} when the public key or an option is invalid\n * @example\n * ```typescript\n * const { secretKey, publicKey } = falcon512.generateKeyPair();\n * const mySigner = new Falcon512Signer(secretKey);\n * const signature = await mySigner.signMessage(myTypedData, accountAddress);\n * const msgHash = typedData.getMessageHash(myTypedData, accountAddress);\n * const result = falcon512.verify(signature, msgHash, publicKey);\n * // result = true\n * const result2 = falcon512.verify(signature, '0x1234', publicKey);\n * // result2 = false\n * const myOzSigner = new Falcon512Signer(secretKey, { accountType: 'oz-hint' });\n * const ozSignature = await myOzSigner.signMessage(myTypedData, accountAddress);\n * const result3 = falcon512.verify(ozSignature, msgHash, myOzSigner.getPackedPublicKey(), {\n * accountType: 'oz-hint',\n * });\n * // result3 = true\n * falcon512.verify(signature, msgHash, '0x1234');\n * // throws Error(\"Falcon512: public key must have 1794 hex digits, got 4\")\n * ```\n */\nexport function verify(\n signature: starknet.Signature,\n msgHash: starknet.BigNumberish,\n fullPublicKey: Uint8Array | string | readonly starknet.BigNumberish[],\n options?: Falcon512Options\n): boolean {\n const accountType = parseFalconOptions(options);\n const pkNtt = toPkNtt(fullPublicKey);\n const h = toMessageHash(msgHash);\n if (h === undefined || !Array.isArray(signature)) return false;\n switch (accountType) {\n case 'oz-hint':\n return verifyHashOz(h, signature, pkNtt, 'hint');\n case 'oz-direct':\n return verifyHashOz(h, signature, pkNtt, 'direct');\n default: // 's2morrow'\n return verifyHash(h, signature, pkNtt);\n }\n}\n\n/**\n * Checks a SNIP-12 message signed by a Falcon-512 account. Same shapes as\n * `typedData.verifyMessage`, with the options of `falcon512.verify` at the end.\n * @param {BigNumberish | TypedData} message a TypedData message, or its hash (SNIP-12)\n * @param {Signature} signature the felts of a Falcon-512 signature: 61 (S2morrow), 60\n * (OpenZeppelin, hint) or 31 (OpenZeppelin, direct)\n * @param {Uint8Array | string | BigNumberish[]} fullPublicKey the NIST Falcon-512 key (897 bytes,\n * as returned by `getPubKey()`), or the 29 felts of the packed key\n * @param {BigNumberish} accountAddress address of the account that signed the message, required\n * when `message` is a TypedData. With a hash, there is no address: the options come in its place\n * @param {Falcon512Options} [options] `accountType`, as for `falcon512.verify`\n * @returns {boolean} true if the message is verified\n * @throws {Error} when `message` is a TypedData and the account address is missing, or when the\n * public key or an option is invalid\n * @example\n * ```typescript\n * const signature = await mySigner.signMessage(myTypedData, accountAddress);\n * const msgHash = typedData.getMessageHash(myTypedData, accountAddress);\n * const result1 = falcon512.verifyMessage(myTypedData, signature, publicKey, accountAddress);\n * const result2 = falcon512.verifyMessage(msgHash, signature, publicKey);\n * // result1 = result2 = true\n * const ozSignature = await myOzSigner.signMessage(myTypedData, accountAddress);\n * const options = { accountType: 'oz-direct' } as const;\n * const result3 = falcon512.verifyMessage(myTypedData, ozSignature, publicKey, accountAddress, options);\n * const result4 = falcon512.verifyMessage(msgHash, ozSignature, publicKey, options);\n * // result3 = result4 = true (myOzSigner built with { accountType: 'oz-direct' })\n * ```\n */\nexport function verifyMessage(\n message: starknet.TypedData,\n signature: starknet.Signature,\n fullPublicKey: Uint8Array | string | readonly starknet.BigNumberish[],\n accountAddress: starknet.BigNumberish,\n options?: Falcon512Options\n): boolean;\nexport function verifyMessage(\n message: starknet.BigNumberish,\n signature: starknet.Signature,\n fullPublicKey: Uint8Array | string | readonly starknet.BigNumberish[],\n options?: Falcon512Options\n): boolean;\nexport function verifyMessage(\n message: starknet.BigNumberish | starknet.TypedData,\n signature: starknet.Signature,\n fullPublicKey: Uint8Array | string | readonly starknet.BigNumberish[],\n accountAddressOrOptions?: starknet.BigNumberish | Falcon512Options,\n options?: Falcon512Options\n): boolean {\n if (typeof message === 'object' && message !== null) {\n if (accountAddressOrOptions === undefined) {\n throw new Error('Falcon512: accountAddress is required to verify a TypedData message');\n }\n const accountAddress = accountAddressOrOptions as starknet.BigNumberish;\n return verify(\n signature,\n starknet.typedData.getMessageHash(message, accountAddress),\n fullPublicKey,\n options\n );\n }\n // With a hash, a 4th argument that is not an options object is ignored, as before.\n const hashOptions =\n typeof accountAddressOrOptions === 'object' &&\n accountAddressOrOptions !== null &&\n !Array.isArray(accountAddressOrOptions)\n ? accountAddressOrOptions\n : undefined;\n return verify(signature, message, fullPublicKey, hashOptions);\n}\n"],"mappings":";;;;;;;AAAA,YAAYA,eAAc;;;AC0B1B,IAAM,gBAAiD,OAAO,OAAO;AAAA,EACnE;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAmBM,SAAS,mBAAmB,SAAwC;AACzE,MAAI,YAAY,OAAW,QAAO;AAClC,MAAI,OAAO,YAAY,YAAY,YAAY,QAAQ,MAAM,QAAQ,OAAO,GAAG;AAC7E,UAAM,IAAI,MAAM,sCAAsC;AAAA,EACxD;AACA,SAAO,KAAK,OAAO,EAAE,QAAQ,CAAC,QAAQ;AACpC,QAAI,QAAQ,cAAe,OAAM,IAAI,MAAM,8BAA8B,GAAG,GAAG;AAAA,EACjF,CAAC;AACD,QAAM,EAAE,YAAY,IAAI;AACxB,MAAI,gBAAgB,OAAW,QAAO;AACtC,MAAI,CAAC,cAAc,SAAS,WAAW,GAAG;AACxC,UAAM,IAAI;AAAA,MACR,mCAAmC,OAAO,WAAW,CAAC;AAAA,IACxD;AAAA,EACF;AACA,SAAO;AACT;;;AC/DA,YAAYC,eAAc;;;ACCnB,IAAM,IAAI;AAEV,IAAM,KAAK;AAEX,IAAM,IAAI;AAEV,IAAM,gBAAgB;AAEtB,IAAM,eAAe;AAErB,IAAM,kBAAkB;AAExB,IAAM,aAAa;AAEnB,IAAM,kBAAkB;;;ACjB/B,YAAY,cAAc;AAgBnB,SAAS,WAAW,GAAW,OAAqB;AACzD,MAAI,OAAO,MAAM,SAAU,OAAM,IAAI,MAAM,cAAc,KAAK,mBAAmB;AACjF,EAAS,sBAAa,YAAY,CAAC;AACrC;AAMA,IAAM,cAAc;AAqBb,SAAS,UAAU,OAAgB,OAAuB;AAC/D,QAAM,WACH,OAAO,UAAU,YAAY,SAAS,MACtC,OAAO,UAAU,YAAY,OAAO,cAAc,KAAK,KAAK,SAAS,KACrE,OAAO,UAAU,YAAY,YAAY,KAAK,KA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AoC;AAC5D;AAoCO,SAAS,OACd,WACA,SACA,eACA,SACS;AACT,QAAM,cAAc,mBAAmB,OAAO;AAC9C,QAAM,QAAQ,QAAQ,aAAa;AACnC,QAAM,IAAI,cAAc,OAAO;AAC/B,MAAI,MAAM,UAAa,CAAC,MAAM,QAAQ,SAAS,EAAG,QAAO;AACzD,UAAQ,aAAa;AAAA,IACnB,KAAK;AACH,aAAO,aAAa,GAAG,WAAW,OAAO,MAAM;AAAA,IACjD,KAAK;AACH,aAAO,aAAa,GAAG,WAAW,OAAO,QAAQ;AAAA,IACnD;AACE,aAAO,WAAW,GAAG,WAAW,KAAK;AAAA,EACzC;AACF;AA2CO,SAAS,cACd,SACA,WACA,eACA,yBACA,SACS;AACT,MAAI,OAAO,YAAY,YAAY,YAAY,MAAM;AACnD,QAAI,4BAA4B,QAAW;AACzC,YAAM,IAAI,MAAM,qEAAqE;AAAA,IACvF;AACA,UAAM,iBAAiB;AACvB,WAAO;AAAA,MACL;AAAA,MACS,oBAAU,eAAe,SAAS,cAAc;AAAA,MACzD;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,QAAM,cACJ,OAAO,4BAA4B,YACnC,4BAA4B,QAC5B,CAAC,MAAM,QAAQ,uBAAuB,IAClC,0BACA;AACN,SAAO,OAAO,WAAW,SAAS,eAAe,WAAW;AAC9D;","names":["starknet","starknet","cryptoRandomBytes","starknet","FFTCore","shake256","abytes","bytesToHex","N","Q","N","n","bytesToHex","Q","shake256","ntt","intt","FFTCore","logn","sign","floatPoly","abytes","res","opts","getPublicKey","verify","starknet","starknet","starknet","randomBytes","shake256","shake256","defaultDeps","cryptoRandomBytes","isBytes","starknet","isBytes","typedData","starknet"]}
|
|
1
|
+
{"version":3,"sources":["../../src/falcon/Falcon512Signer.ts","../../src/falcon/accountType.ts","../../src/falcon/oz/ownership.ts","../../src/falcon/s2morrow/constants.ts","../../src/falcon/s2morrow/felt.ts","../../src/falcon/oz/signature.ts","../../src/falcon/engine/noble/falcon.ts","../../src/falcon/engine/noble/_crystals.ts","../../src/falcon/engine/noble/utils.ts","../../src/falcon/engine/noble/ml-kem.ts","../../src/falcon/engine/engine.ts","../../src/falcon/s2morrow/nttRoots.ts","../../src/falcon/s2morrow/ntt.ts","../../src/falcon/s2morrow/packing.ts","../../src/falcon/s2morrow/signature.ts","../../src/falcon/s2morrow/hashToPoint.ts","../../src/falcon/oz/hashToPoint.ts","../../src/falcon/s2morrow/keys.ts","../../src/falcon/falcon512.ts","../../src/falcon/verify.ts","../../src/falcon/mlkem/index.ts","../../src/falcon/mlkem/exchange.ts","../../src/falcon/mlkem/messages.ts","../../src/falcon/mlkem/signatures.ts","../../src/falcon/mlkem/utils/bytes.ts","../../src/falcon/mlkem/utils/time.ts"],"sourcesContent":["import * as starknet from 'starknet';\nimport {\n parseFalconOptions,\n type Falcon512AccountType,\n type Falcon512Options,\n} from './accountType';\nimport { ownershipAcceptanceHash } from './oz/ownership';\nimport { signHashOz } from './oz/signature';\nimport {\n getPublicKey,\n getPackedPublicKey,\n importFalconRsSecretKey,\n publicKeyToNtt,\n SECRET_KEY_LENGTH,\n toBytes,\n} from './s2morrow/keys';\nimport { signHash } from './s2morrow/signature';\n\n/**\n * Throws a clear error unless the transaction is V3: the hash functions of starknet.js compute V3\n * hashes only.\n * @param {InvocationsDetailsWithNonce} details the details of the transaction\n * @throws {Error} when the version is not V3\n * @example\n * ```typescript\n * assertV3({ nonce: 1, version: '0x3' });\n * // passes\n * assertV3({ nonce: 1, version: '0x1' });\n * // throws Error(\"Falcon512: only V3 transactions are supported\")\n * ```\n */\nfunction assertV3(details: starknet.InvocationsDetailsWithNonce): void {\n if (!starknet.isV3Tx(details)) throw new Error('Falcon512: only V3 transactions are supported');\n}\n\n/**\n * Signer for the Falcon-512 accounts (post-quantum signature), in pure TypeScript.\n *\n * Falcon-512 is a signature scheme built on lattices, designed to resist attacks by quantum\n * computers. Three account contracts verify it on-chain, each with its own signature layout: the\n * `accountType` option of the constructor selects it (see `Falcon512AccountType`).\n * - `'s2morrow'` (default): the S2morrow account (https://github.com/feltroidprime/s2morrow), which\n * hashes the transaction with Poseidon. A signature is 61 felts.\n * - `'oz-hint'` and `'oz-direct'`: the two Falcon-512 accounts of OpenZeppelin Contracts for Cairo\n * (pre-release v4.1.0-rc.0), which hash it with SHAKE-256. A signature is 60 felts with the hint\n * s1·h, which makes the on-chain check cheaper, or 31 felts without it.\n *\n * Fees: the on-chain verification costs much more L2 gas than an ECDSA one. By default, the fee\n * estimates of `Account` skip the validation of the signature (`skipValidate: true`), so they leave\n * out this cost: pass `{ skipValidate: false }` to `execute`, `deployAccount` and `declare`.\n *\n * Status:\n * - This is Falcon as submitted to Round 3 of the NIST post-quantum standardization, not FN-DSA\n * (FIPS 206). FN-DSA is not final yet, and will most likely be incompatible with it.\n * - The Falcon code is a patched copy of `@noble/post-quantum` 0.7.1, kept until noble publishes\n * the API this signer needs. noble has no independent audit: its author audited version 0.6.1\n * (April 2026).\n * - Signing is not constant-time: do not sign where an attacker can measure its timing closely.\n * - Only V3 transactions are supported.\n */\nexport class Falcon512Signer implements starknet.SignerInterface {\n readonly #secretKey: Uint8Array;\n\n readonly #publicKey: Uint8Array;\n\n readonly #pkNtt: Uint16Array;\n\n readonly #packedPublicKey: string[];\n\n readonly #accountType: Falcon512AccountType;\n\n /**\n * Builds a signer from a NIST Falcon-512 secret key. The key is fully checked, then copied: the\n * signer keeps its own copy, in a private field.\n * @param {Uint8Array | string} secretKey NIST Falcon-512 secret key (1281 bytes), Uint8Array or\n * hex string. Prefer a Uint8Array: a string cannot be wiped from memory.\n * @param {Falcon512Options} [options] `accountType`: the type of the account that checks the\n * signatures, `'s2morrow'` (default), `'oz-hint'` or `'oz-direct'`\n * @throws {Error} when the secret key or an option is invalid\n * @example\n * ```typescript\n * const { secretKey } = falcon512.generateKeyPair();\n * const mySigner = new Falcon512Signer(secretKey); // for an S2morrow account\n * const myOzSigner = new Falcon512Signer(secretKey, { accountType: 'oz-hint' });\n * new Falcon512Signer(new Uint8Array(1281));\n * // throws Error(\"Falcon512: invalid secret key header\")\n * ```\n */\n constructor(secretKey: Uint8Array | string, options?: Falcon512Options) {\n const accountType = parseFalconOptions(options); // read before the key is copied\n const bytes = toBytes(secretKey, SECRET_KEY_LENGTH, 'secret key');\n let publicKey: Uint8Array;\n try {\n publicKey = getPublicKey(bytes); // fully validates the key\n } catch (error) {\n bytes.fill(0); // the copy of an invalid key is not kept\n throw error;\n }\n this.#accountType = accountType;\n this.#publicKey = publicKey;\n this.#secretKey = bytes;\n this.#pkNtt = publicKeyToNtt(this.#publicKey);\n this.#packedPublicKey = getPackedPublicKey(this.#publicKey);\n }\n\n /**\n * Builds a signer from a falcon-rs secret key (3584 bytes), converted to the NIST format.\n *\n * Warning: falcon-rs derives the seed of its sampler from the public salt of each signature, so\n * the signatures it produced may leak information about the secret key. Use this for continuity\n * only; for real funds, generate a new key with `falcon512.generateKeyPair`. The S2morrow account\n * cannot change its key: a new key means a new account. An OpenZeppelin account can change its\n * key (see `signOwnershipAcceptance`).\n * @param {Uint8Array | string} secretKey the falcon-rs secret key (3584 bytes), or its hex string\n * @param {Falcon512Options} [options] `accountType`, as for the constructor\n * @returns {Falcon512Signer} a signer that holds the same key, in the NIST format\n * @throws {Error} when the falcon-rs secret key or an option is invalid\n * @example\n * ```typescript\n * const mySigner = Falcon512Signer.fromFalconRs(falconRsSecretKey); // 3584 bytes, from falcon-rs\n * const result = mySigner.getPackedPublicKey();\n * // result = ['0xb2cf4f8b3c6f60cc662f438970ad34017e260c52d7911297a42811ce3cea2b', …] (29 felts)\n * ```\n */\n static fromFalconRs(secretKey: Uint8Array | string, options?: Falcon512Options): Falcon512Signer {\n const nist = importFalconRsSecretKey(secretKey);\n try {\n return new Falcon512Signer(nist, options);\n } finally {\n nist.fill(0);\n }\n }\n\n /**\n * NIST Falcon-512 public key (897 bytes), as a hex string.\n * @returns {Promise<string>} the public key: 0x, then 1794 hex digits\n * @example\n * ```typescript\n * const { secretKey } = falcon512.generateKeyPair();\n * const mySigner = new Falcon512Signer(secretKey);\n * const result = await mySigner.getPubKey();\n * // result = '0x09…' (1796 characters; 09 is the header of the format)\n * ```\n */\n public async getPubKey(): Promise<string> {\n return starknet.encode.addHexPrefix(starknet.encode.buf2hex(this.#publicKey));\n }\n\n /**\n * The 29 felts of the public key, in the form the accounts store it: the constructor argument\n * `pk_packed` of S2morrow, or the `public_key` array of an OpenZeppelin account (whose\n * constructor calldata is `29`, then these 29 felts). The same for the three account types.\n * @returns {string[]} the 29 felts, as hex strings (a new array at each call)\n * @example\n * ```typescript\n * const { secretKey } = falcon512.generateKeyPair();\n * const mySigner = new Falcon512Signer(secretKey);\n * const result = mySigner.getPackedPublicKey();\n * // result = ['0x…', …] (29 felts)\n * ```\n */\n public getPackedPublicKey(): string[] {\n return [...this.#packedPublicKey];\n }\n\n /**\n * Signs a SNIP-12 message (TypedData) for off-chain use.\n * @param {TypedData} typedData the message to sign\n * @param {string} accountAddress address of the account that signs the message\n * @returns {Promise<Signature>} the signature, as hex strings: 61 felts (S2morrow), 60\n * (OpenZeppelin, hint) or 31 (OpenZeppelin, direct)\n * @example\n * ```typescript\n * const result = await mySigner.signMessage(myTypedData, accountAddress);\n * // result = ['0x…', …] (S2morrow: 61 felts, random salt); result[29] = '0x2' (salt length)\n * ```\n */\n public async signMessage(\n typedData: starknet.TypedData,\n accountAddress: string\n ): Promise<starknet.Signature> {\n return this.signRaw(starknet.typedData.getMessageHash(typedData, accountAddress));\n }\n\n /**\n * Signs an INVOKE transaction (V3 only).\n * @param {Call[]} transactions the calls of the transaction\n * @param {InvocationsSignerDetails} details the details needed to hash the transaction\n * @returns {Promise<Signature>} the signature, as hex strings: 61, 60 or 31 felts, according to\n * the account type\n * @throws {Error} when the transaction is not V3\n * @example\n * ```typescript\n * const calls: Call[] = [\n * {\n * contractAddress: '0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d',\n * entrypoint: 'transfer',\n * calldata: ['0x123', '1000', '0'],\n * },\n * ];\n * const details: InvocationsSignerDetails = {\n * walletAddress: accountAddress,\n * chainId: constants.StarknetChainId.SN_SEPOLIA,\n * cairoVersion: '1',\n * version: '0x3',\n * nonce: 1,\n * resourceBounds: {\n * l1_gas: { max_amount: 0n, max_price_per_unit: 50000000000000n },\n * l2_gas: { max_amount: 40000000n, max_price_per_unit: 20000000000n },\n * l1_data_gas: { max_amount: 1000n, max_price_per_unit: 100000n },\n * },\n * tip: 0,\n * paymasterData: [],\n * accountDeploymentData: [],\n * nonceDataAvailabilityMode: RPC.EDataAvailabilityMode.L1,\n * feeDataAvailabilityMode: RPC.EDataAvailabilityMode.L1,\n * };\n * const result = await mySigner.signTransaction(calls, details);\n * // result = ['0x…', …] (S2morrow: 61 felts)\n * ```\n */\n public async signTransaction(\n transactions: starknet.Call[],\n details: starknet.InvocationsSignerDetails\n ): Promise<starknet.Signature> {\n assertV3(details);\n const compiledCalldata = starknet.transaction.getExecuteCalldata(\n transactions,\n details.cairoVersion\n );\n const msgHash = starknet.hash.calculateInvokeTransactionHash({\n ...details,\n senderAddress: details.walletAddress,\n compiledCalldata,\n version: details.version,\n nonceDataAvailabilityMode: starknet.stark.intDAM(details.nonceDataAvailabilityMode),\n feeDataAvailabilityMode: starknet.stark.intDAM(details.feeDataAvailabilityMode),\n });\n return this.signRaw(msgHash);\n }\n\n /**\n * Signs the DEPLOY_ACCOUNT transaction of a Falcon-512 account (V3 only).\n * @param {DeployAccountSignerDetails} details the details needed to hash the transaction\n * @returns {Promise<Signature>} the signature, as hex strings: 61, 60 or 31 felts, according to\n * the account type\n * @throws {Error} when the transaction is not V3\n * @example\n * ```typescript\n * const packedPublicKey = mySigner.getPackedPublicKey();\n * const classHash = '0x37c7626b50ba517835c9556b53bce57cb6633704bb702f8c2f13a44cf151d5';\n * const salt = packedPublicKey[0];\n * const details: DeployAccountSignerDetails = {\n * classHash,\n * constructorCalldata: packedPublicKey,\n * addressSalt: salt,\n * contractAddress: hash.calculateContractAddressFromHash(salt, classHash, packedPublicKey, 0),\n * chainId: constants.StarknetChainId.SN_SEPOLIA,\n * version: '0x3',\n * nonce: 0,\n * resourceBounds: {\n * l1_gas: { max_amount: 0n, max_price_per_unit: 50000000000000n },\n * l2_gas: { max_amount: 60000000n, max_price_per_unit: 20000000000n },\n * l1_data_gas: { max_amount: 1000n, max_price_per_unit: 100000n },\n * },\n * tip: 0,\n * paymasterData: [],\n * accountDeploymentData: [],\n * nonceDataAvailabilityMode: RPC.EDataAvailabilityMode.L1,\n * feeDataAvailabilityMode: RPC.EDataAvailabilityMode.L1,\n * };\n * const result = await mySigner.signDeployAccountTransaction(details);\n * // result = ['0x…', …] (S2morrow: 61 felts)\n * ```\n */\n public async signDeployAccountTransaction(\n details: starknet.DeployAccountSignerDetails\n ): Promise<starknet.Signature> {\n assertV3(details);\n const compiledConstructorCalldata = starknet.CallData.compile(details.constructorCalldata);\n const msgHash = starknet.hash.calculateDeployAccountTransactionHash({\n ...details,\n salt: details.addressSalt,\n compiledConstructorCalldata,\n version: details.version,\n nonceDataAvailabilityMode: starknet.stark.intDAM(details.nonceDataAvailabilityMode),\n feeDataAvailabilityMode: starknet.stark.intDAM(details.feeDataAvailabilityMode),\n });\n return this.signRaw(msgHash);\n }\n\n /**\n * Signs a DECLARE transaction (V3 only).\n * @param {DeclareSignerDetails} details the details needed to hash the transaction\n * @returns {Promise<Signature>} the signature, as hex strings: 61, 60 or 31 felts, according to\n * the account type\n * @throws {Error} when the transaction is not V3\n * @example\n * ```typescript\n * const details: DeclareSignerDetails = {\n * senderAddress: accountAddress,\n * classHash: '0x37c7626b50ba517835c9556b53bce57cb6633704bb702f8c2f13a44cf151d5',\n * compiledClassHash: '0x1f2afb8ae690b84f4b7acfde52fbd2e5a1dc0c910ed898a778dc1ad3339e5c5',\n * chainId: constants.StarknetChainId.SN_SEPOLIA,\n * version: '0x3',\n * nonce: 2,\n * resourceBounds: {\n * l1_gas: { max_amount: 0n, max_price_per_unit: 50000000000000n },\n * l2_gas: { max_amount: 80000000n, max_price_per_unit: 20000000000n },\n * l1_data_gas: { max_amount: 1000n, max_price_per_unit: 100000n },\n * },\n * tip: 0,\n * paymasterData: [],\n * accountDeploymentData: [],\n * nonceDataAvailabilityMode: RPC.EDataAvailabilityMode.L1,\n * feeDataAvailabilityMode: RPC.EDataAvailabilityMode.L1,\n * };\n * const result = await mySigner.signDeclareTransaction(details);\n * // result = ['0x…', …] (S2morrow: 61 felts)\n * ```\n */\n public async signDeclareTransaction(\n details: starknet.DeclareSignerDetails\n ): Promise<starknet.Signature> {\n assertV3(details);\n const msgHash = starknet.hash.calculateDeclareTransactionHash({\n ...details,\n version: details.version,\n nonceDataAvailabilityMode: starknet.stark.intDAM(details.nonceDataAvailabilityMode),\n feeDataAvailabilityMode: starknet.stark.intDAM(details.feeDataAvailabilityMode),\n });\n return this.signRaw(msgHash);\n }\n\n /**\n * Signs the acceptance of a key change of an OpenZeppelin Falcon-512 account.\n *\n * The account changes its key when it calls its own `set_public_key(new_public_key, signature)`:\n * the current key signs that transaction, as any other, and the new key must sign an acceptance.\n * Call this method on the signer of the new key, with the key that the account holds now. The\n * signed hash is Poseidon('StarkNet Message', 'accept_ownership', account address,\n * Poseidon(current key)). It holds no chain id, nonce or expiry: an acceptance is not single-use,\n * and the current key must still sign each key change.\n * @param {BigNumberish} accountAddress the address of the account\n * @param {BigNumberish[]} currentPublicKey the 29 felts of the key that the account holds now\n * (`getPackedPublicKey()` of its current signer, or its `get_public_key`)\n * @returns {Promise<string[]>} the acceptance, as hex strings, in the layout of this signer: 60\n * felts (`'oz-hint'`) or 31 (`'oz-direct'`)\n * @throws {Error} for an S2morrow signer (that account cannot change its key), or when the\n * current key has neither 29 felts nor none, or a value is not a felt252. Also when a subclass\n * makes `signRaw` return something else than an array of felts\n * @example\n * ```typescript\n * const newSigner = new Falcon512Signer(newSecretKey, { accountType: 'oz-hint' });\n * const acceptance = await newSigner.signOwnershipAcceptance(\n * falconAccount.address,\n * currentSigner.getPackedPublicKey()\n * );\n * const { transaction_hash } = await falconAccount.execute(\n * {\n * contractAddress: falconAccount.address,\n * entrypoint: 'set_public_key',\n * calldata: CallData.compile({\n * new_public_key: newSigner.getPackedPublicKey(),\n * signature: acceptance,\n * }),\n * },\n * { skipValidate: false }\n * );\n * await myProvider.waitForTransaction(transaction_hash);\n * // From now on, the account checks the signatures of newSigner.\n * ```\n */\n public async signOwnershipAcceptance(\n accountAddress: starknet.BigNumberish,\n currentPublicKey: readonly starknet.BigNumberish[]\n ): Promise<string[]> {\n if (this.#accountType === 's2morrow') {\n throw new Error('Falcon512: an S2morrow account cannot change its key');\n }\n const signature = await this.signRaw(ownershipAcceptanceHash(accountAddress, currentPublicKey));\n if (!Array.isArray(signature)) {\n throw new Error('Falcon512: signRaw must return an array of felts');\n }\n return signature;\n }\n\n /**\n * Signs a hash: the last step of all the methods above, in the layout of the account type. It\n * stays protected, so that no public method signs an arbitrary hash. A subclass can override it,\n * as for every starknet.js signer.\n * @param {string} msgHash the hash to sign, a felt252\n * @returns {Promise<Signature>} the signature, as hex strings: 61, 60 or 31 felts, according to\n * the account type\n * @example\n * ```typescript\n * class LoggedFalconSigner extends Falcon512Signer {\n * protected async signRaw(msgHash: string): Promise<Signature> {\n * console.log('Falcon-512 signs', msgHash);\n * return super.signRaw(msgHash);\n * }\n * }\n * const result = await new LoggedFalconSigner(secretKey).signMessage(myTypedData, accountAddress);\n * // logs the hash of the message; result = ['0x…', …] (61 felts)\n * ```\n */\n protected async signRaw(msgHash: string): Promise<starknet.Signature> {\n const value = starknet.num.toBigInt(msgHash);\n switch (this.#accountType) {\n case 'oz-hint':\n return signHashOz(value, this.#secretKey, this.#pkNtt, 'hint');\n case 'oz-direct':\n return signHashOz(value, this.#secretKey, this.#pkNtt, 'direct');\n default: // 's2morrow'\n return signHash(value, this.#secretKey, this.#pkNtt);\n }\n }\n}\n","/**\n * The Falcon-512 accounts that `starknet/falcon` signs for. Each one has its own signature layout:\n * the signer must use the type of the account class, or the account rejects the signatures.\n *\n * - `'s2morrow'`: the S2morrow account (https://github.com/feltroidprime/s2morrow), class\n * `0x37c7626b50ba517835c9556b53bce57cb6633704bb702f8c2f13a44cf151d5`. Signatures of 61 felts,\n * hashed with Poseidon. The default.\n * - `'oz-hint'`: `Falcon512ShakeAccountUpgradeable` of OpenZeppelin Contracts for Cairo\n * (v4.1.0-rc.0), class `0x014660ce3739fbde6e33d994cebd6a9fb20e800516b2e1b6c253d4d09baa9ae0`\n * (compiled with Cairo 2.21.0). Signatures of 60 felts, with the product s1·h (the hint), which\n * makes the on-chain check cheaper.\n * - `'oz-direct'`: `Falcon512ShakeDirectAccountUpgradeable` of OpenZeppelin Contracts for Cairo\n * (v4.1.0-rc.0), class `0x016111958d61eedfa5a950b608997abb4981b548f1862d620cc9247461ddeeb1`\n * (compiled with Cairo 2.21.0). Signatures of 31 felts, without the hint.\n *\n * The two OpenZeppelin accounts store the same key and have the same ABI. A class upgrade from one\n * to the other keeps the address and the key, but changes the signature layout.\n */\nexport type Falcon512AccountType = 's2morrow' | 'oz-hint' | 'oz-direct';\n\n/** Options of `Falcon512Signer`, `falcon512.verify` and `falcon512.verifyMessage`. */\nexport type Falcon512Options = {\n /** The type of the account that checks the signatures. Default: `'s2morrow'`. */\n accountType?: Falcon512AccountType;\n};\n\nconst ACCOUNT_TYPES: readonly Falcon512AccountType[] = Object.freeze([\n 's2morrow',\n 'oz-hint',\n 'oz-direct',\n]);\n\n/**\n * Reads the options of `starknet/falcon` strictly: an unknown option or value is an error, never a\n * silent fallback to the default type.\n * @param {unknown} options the options given by the caller, or undefined\n * @returns {Falcon512AccountType} the account type; `'s2morrow'` when none is given\n * @throws {Error} when the options are not an object, have an unknown key, or an unknown\n * accountType\n * @example\n * ```typescript\n * const result = parseFalconOptions({ accountType: 'oz-hint' });\n * // result = 'oz-hint'\n * const result2 = parseFalconOptions(undefined);\n * // result2 = 's2morrow'\n * parseFalconOptions({ acountType: 'oz-hint' });\n * // throws Error('Falcon512: unknown option \"acountType\"')\n * ```\n */\nexport function parseFalconOptions(options: unknown): Falcon512AccountType {\n if (options === undefined) return 's2morrow';\n if (typeof options !== 'object' || options === null || Array.isArray(options)) {\n throw new Error('Falcon512: options must be an object');\n }\n Object.keys(options).forEach((key) => {\n if (key !== 'accountType') throw new Error(`Falcon512: unknown option \"${key}\"`);\n });\n const { accountType } = options as Falcon512Options;\n if (accountType === undefined) return 's2morrow';\n if (!ACCOUNT_TYPES.includes(accountType)) {\n throw new Error(\n `Falcon512: unknown accountType \"${String(accountType)}\" (expected 's2morrow', 'oz-hint' or 'oz-direct')`\n );\n }\n return accountType;\n}\n","// Key change of the OpenZeppelin Falcon-512 accounts (OpenZeppelin Contracts for Cairo\n// v4.1.0-rc.0, `set_public_key`): the hash that the new key signs to accept the account.\nimport * as starknet from 'starknet';\nimport { PACKED_SLOTS } from '../s2morrow/constants';\nimport { parseFelt } from '../s2morrow/felt';\n\n/**\n * Hash that the new key signs to accept a key change of an OpenZeppelin Falcon-512 account:\n * Poseidon('StarkNet Message', 'accept_ownership', account address, Poseidon(current key)).\n * It holds no chain id, nonce or expiry (as in OpenZeppelin): an acceptance is not single-use.\n * @param {BigNumberish} accountAddress the address of the account\n * @param {BigNumberish[]} currentPublicKey the 29 felts of the key that the account holds now, or\n * none\n * @returns {string} the hash to sign, as a hex string\n * @throws {Error} when the current key has neither 29 felts nor none, or a value is not a felt252\n * @example\n * ```typescript\n * const result = ownershipAcceptanceHash(CairoBytes31.fromText('FALCON_MIGRATION').toBigInt(), []);\n * // result = '0x4cd1d8e37687d438b941364f25ae8c1d3198903239a23dd49add4f3c250a61b'\n * // (the value of the OpenZeppelin reference data, migration_fixture.cairo)\n * ```\n */\nexport function ownershipAcceptanceHash(\n accountAddress: starknet.BigNumberish,\n currentPublicKey: readonly starknet.BigNumberish[]\n): string {\n if (\n !Array.isArray(currentPublicKey) ||\n (currentPublicKey.length !== PACKED_SLOTS && currentPublicKey.length !== 0)\n ) {\n throw new Error('Falcon512: current public key must have 29 felts, or none');\n }\n const address = parseFelt(accountAddress, 'account address');\n const key = currentPublicKey.map((x, i) => parseFelt(x, `current public key[${i}]`));\n const { computePoseidonHashOnElements } = starknet.hash;\n return computePoseidonHashOnElements([\n starknet.CairoBytes31.fromText('StarkNet Message').toBigInt(),\n starknet.CairoBytes31.fromText('accept_ownership').toBigInt(),\n address,\n computePoseidonHashOnElements(key),\n ]);\n}\n","// Falcon-512 / S2morrow constants shared by the pure-TypeScript implementation.\n\n/** Falcon modulus q. */\nexport const Q = 12289;\n/** q as a bigint. */\nexport const QB = 12289n;\n/** Degree of the polynomials (Falcon-512). */\nexport const N = 512;\n/** Squared-norm bound of a Falcon-512 signature; identical to SIG_BOUND_512 in falcon.cairo. */\nexport const SIG_BOUND_512 = 34034726;\n/** Number of felt252 of a packed 512-coefficient polynomial. */\nexport const PACKED_SLOTS = 29;\n/** Zq values packed in each u128 half of a felt252 (base-Q Horner encoding). */\nexport const VALUES_PER_HALF = 9;\n/** Number of salt felts produced by this signer. */\nexport const SALT_FELTS = 2;\n/** Signature length: s1 (29) + salt length (1) + salt (2) + mul_hint (29). */\nexport const SIGNATURE_FELTS = 61;\n","import * as starknet from 'starknet';\n\n/**\n * Throws if x is not a felt252: a bigint with 0 <= x < P. The range check is the one of\n * `CairoFelt252`.\n * @param {bigint} x the value to check\n * @param {string} label the name of the value, used in the error message\n * @throws {Error} when x is not a bigint, or is outside [0, P)\n * @example\n * ```typescript\n * assertFelt(5n, 'salt');\n * // passes\n * assertFelt(-1n, 'salt');\n * // throws Error(\"Value -1 is out of felt252 range [0, 3618502788666131213697322783095070105623107215331596699973092056135872020481)\")\n * ```\n */\nexport function assertFelt(x: bigint, label: string): void {\n if (typeof x !== 'bigint') throw new Error(`Falcon512: ${label} is not a felt252`);\n starknet.CairoFelt252.assertRange(x);\n}\n\n/**\n * Spellings accepted for a felt252: \"0x\" and 1 to 64 hex digits, or 1 to 76 decimal digits (P has\n * 76). The caps keep an untrusted signature cheap to reject: 61 huge strings would cost seconds.\n */\nconst FELT_STRING = /^(0[xX][0-9a-fA-F]{1,64}|[0-9]{1,76})$/;\n\n/**\n * Parses a felt252 given as a bigint, a safe integer, a hex string (\"0x…\") or a decimal string.\n * The check comes first and refuses what starknet.js would convert without a word (\"\", \" \",\n * \"0x\", a text, a boolean, an unsafe integer), and a negative number; `CairoFelt252` then converts\n * and checks the range.\n * @param {unknown} value the value to parse\n * @param {string} label the name of the value, used in the error message\n * @returns {bigint} the felt252\n * @throws {Error} when the value is not one of the accepted spellings, or is outside [0, P)\n * @example\n * ```typescript\n * const result = parseFelt('0x1F', 'x');\n * // result = 31n\n * const result2 = parseFelt('31', 'x');\n * // result2 = 31n\n * parseFelt('', 'x');\n * // throws Error(\"Falcon512: x is not a felt252\")\n * ```\n */\nexport function parseFelt(value: unknown, label: string): bigint {\n const accepted =\n (typeof value === 'bigint' && value >= 0n) ||\n (typeof value === 'number' && Number.isSafeInteger(value) && value >= 0) ||\n (typeof value === 'string' && FELT_STRING.test(value));\n if (!accepted) throw new Error(`Falcon512: ${label} is not a felt252`);\n return new starknet.CairoFelt252(value).toBigInt();\n}\n","// Signature layouts of the OpenZeppelin Falcon-512 accounts (OpenZeppelin Contracts for Cairo\n// v4.1.0-rc.0): direct = s1 (29 felts) ‖ salt_a ‖ salt_b; hint = direct ‖ s1·h (29 felts).\nimport { randomBytes as cryptoRandomBytes } from '@noble/hashes/utils.js';\nimport * as starknet from 'starknet';\nimport { nobleEngine } from '../engine/engine';\nimport { PACKED_SLOTS } from '../s2morrow/constants';\nimport { assertFelt, parseFelt } from '../s2morrow/felt';\nimport { modQ } from '../s2morrow/ntt';\nimport { packPoly, unpackPoly } from '../s2morrow/packing';\nimport { checkSignatureEquation, computeMulHint, type SignDeps } from '../s2morrow/signature';\nimport { hashToPointShake, SALT_BYTES, saltFeltsToBytes } from './hashToPoint';\n\n/** The two signature layouts of the OpenZeppelin Falcon-512 accounts. */\nexport type OzVariant = 'hint' | 'direct';\n\n/** Signature length: s1 (29) and the salt (2), plus the hint s1·h (29) in the hint layout. */\nexport const OZ_SIGNATURE_FELTS: Readonly<Record<OzVariant, number>> = Object.freeze({\n hint: 2 * PACKED_SLOTS + 2,\n direct: PACKED_SLOTS + 2,\n});\n\n/** Decoded OpenZeppelin signature. `mulHint` is present in the hint layout only. */\nexport type OzSignature = { s1: Uint16Array; saltA: bigint; saltB: bigint; mulHint?: Uint16Array };\n\nconst defaultDeps: SignDeps = { engine: nobleEngine, randomBytes: cryptoRandomBytes };\n\n/**\n * Reads bytes as a number, least significant byte first.\n * @param {Uint8Array} bytes the bytes to read\n * @returns {bigint} the number\n * @example\n * ```typescript\n * const result = readLittleEndian(Uint8Array.from([2, 1]));\n * // result = 258n (0x0102)\n * ```\n */\nconst readLittleEndian = (bytes: Uint8Array): bigint =>\n bytes.reduceRight((acc, byte) => acc * 256n + BigInt(byte), 0n);\n\n/**\n * Encodes a signature in an OpenZeppelin layout: s1 packed (29 felts), salt_a, salt_b, then the\n * hint s1·h packed (29 felts) in the hint layout.\n * @param {OzSignature} sig the decoded signature\n * @param {OzVariant} variant the layout: 'hint' (60 felts) or 'direct' (31 felts)\n * @returns {string[]} the felts, as hex strings\n * @throws {Error} when the hint layout is asked without the hint polynomial\n * @example\n * ```typescript\n * const signature = signHashOz(0x1234n, secretKey, pkNtt, 'hint');\n * const result = formatOzSignature(parseOzSignature(signature, 'hint'), 'hint');\n * // result = signature (the same 60 felts)\n * ```\n */\nexport function formatOzSignature(sig: OzSignature, variant: OzVariant): string[] {\n const felts = [...packPoly(sig.s1), sig.saltA, sig.saltB];\n if (variant === 'hint') {\n if (!sig.mulHint) throw new Error('Falcon512: the hint layout needs the hint polynomial');\n felts.push(...packPoly(sig.mulHint));\n }\n return felts.map((x) => starknet.num.toHex(x));\n}\n\n/**\n * Strict parsing of a signature in an OpenZeppelin layout (hex or decimal strings, numbers,\n * bigints).\n * @param {unknown[]} signature the felts of the signature\n * @param {OzVariant} variant the expected layout: 'hint' (60 felts) or 'direct' (31 felts)\n * @returns {OzSignature} s1, the two salt felts and, in the hint layout, the hint\n * @throws {Error} when the signature does not have the length of the layout, a felt is invalid, a\n * polynomial is not canonical, or a salt felt is not below 2^160\n * @example\n * ```typescript\n * const result = parseOzSignature(signHashOz(0x1234n, secretKey, pkNtt, 'direct'), 'direct');\n * // result = { s1: Uint16Array(512) […], saltA: …n, saltB: …n, mulHint: undefined }\n * parseOzSignature(['0x1'], 'hint');\n * // throws Error(\"Falcon512: signature must have 60 felts\")\n * ```\n */\nexport function parseOzSignature(signature: readonly unknown[], variant: OzVariant): OzSignature {\n const length = OZ_SIGNATURE_FELTS[variant];\n if (!Array.isArray(signature) || signature.length !== length) {\n throw new Error(`Falcon512: signature must have ${length} felts`);\n }\n const felts = signature.map((x, i) => parseFelt(x, `signature[${i}]`));\n const saltA = felts[PACKED_SLOTS];\n const saltB = felts[PACKED_SLOTS + 1];\n saltFeltsToBytes(saltA, saltB); // throws when a salt felt is not below 2^160\n return {\n s1: unpackPoly(felts.slice(0, PACKED_SLOTS)),\n saltA,\n saltB,\n mulHint: variant === 'hint' ? unpackPoly(felts.slice(PACKED_SLOTS + 2)) : undefined,\n };\n}\n\n/**\n * Signs a message hash for an OpenZeppelin account (internal: never exported by index.ts, to avoid\n * blind signing). The salt is 40 random bytes; the engine draws its own sampler seed, independent\n * from the public salt. The encoded signature is checked again before being returned.\n * @param {bigint} msgHash the hash to sign, a felt252\n * @param {Uint8Array} secretKey the NIST Falcon-512 secret key (1281 bytes)\n * @param {Uint16Array} pkNtt the NTT of the public polynomial h\n * @param {OzVariant} variant the layout: 'hint' (60 felts) or 'direct' (31 felts)\n * @param {SignDeps} [deps] the engine and the random source (tests only)\n * @returns {string[]} the felts of the signature, as hex strings\n * @throws {Error} when msgHash is not a felt252, or the self-verification fails\n * @example\n * ```typescript\n * const { secretKey, publicKey } = generateKeyPair();\n * const result = signHashOz(0x1234n, secretKey, publicKeyToNtt(publicKey), 'hint');\n * // result = ['0x…', …] (60 felts, random salt)\n * ```\n */\nexport function signHashOz(\n msgHash: bigint,\n secretKey: Uint8Array,\n pkNtt: Uint16Array,\n variant: OzVariant,\n deps: SignDeps = defaultDeps\n): string[] {\n assertFelt(msgHash, 'message hash');\n const salt = deps.randomBytes(2 * SALT_BYTES);\n const saltA = readLittleEndian(salt.subarray(0, SALT_BYTES));\n const saltB = readLittleEndian(salt.subarray(SALT_BYTES));\n const hashPoint = hashToPointShake(msgHash, saltA, saltB);\n const s1 = Uint16Array.from(deps.engine.signHashPoint(hashPoint, secretKey), modQ);\n const mulHint = variant === 'hint' ? Uint16Array.from(computeMulHint(s1, pkNtt)) : undefined;\n const signature = formatOzSignature({ s1, saltA, saltB, mulHint }, variant);\n const decoded = parseOzSignature(signature, variant);\n const decodedHint = decoded.mulHint ?? computeMulHint(decoded.s1, pkNtt);\n if (!checkSignatureEquation(hashPoint, decoded.s1, decodedHint, pkNtt)) {\n throw new Error('Falcon512: self-verification failed, signature discarded');\n }\n return signature;\n}\n\n/**\n * Verifies a signature of msgHash in an OpenZeppelin layout; false for any malformed input. In the\n * direct layout, the product s1·h is computed here, as the direct account does on-chain.\n * @param {bigint} msgHash the signed hash\n * @param {unknown[]} signature the felts of the signature\n * @param {ArrayLike<number>} pkNtt the NTT of the public polynomial h\n * @param {OzVariant} variant the expected layout: 'hint' (60 felts) or 'direct' (31 felts)\n * @returns {boolean} true for a valid signature of msgHash in this layout, false otherwise\n * @example\n * ```typescript\n * const signature = signHashOz(0x1234n, secretKey, pkNtt, 'direct');\n * const result = verifyHashOz(0x1234n, signature, pkNtt, 'direct');\n * // result = true\n * const result2 = verifyHashOz(0x1234n, signature, pkNtt, 'hint');\n * // result2 = false (31 felts, not 60)\n * ```\n */\nexport function verifyHashOz(\n msgHash: bigint,\n signature: readonly unknown[],\n pkNtt: ArrayLike<number>,\n variant: OzVariant\n): boolean {\n let decoded: OzSignature;\n try {\n assertFelt(msgHash, 'message hash');\n decoded = parseOzSignature(signature, variant);\n } catch {\n return false;\n }\n const mulHint = decoded.mulHint ?? computeMulHint(decoded.s1, pkNtt);\n return checkSignatureEquation(\n hashToPointShake(msgHash, decoded.saltA, decoded.saltB),\n decoded.s1,\n mulHint,\n pkNtt\n );\n}\n","/* eslint-disable -- vendored copy of @noble/post-quantum 0.7.1, kept as is: see PATCH.md */\n/**\n * Falcon pq-friendly signature algorithm.\n * Will change in backwards-incompatible way once FIPS-206 gets finalized.\n * @module\n */\n/*! noble-post-quantum - MIT License (c) 2024 Paul Miller (paulmillr.com) */\nimport { rngAesCtrDrbg256 } from '@noble/ciphers/aes.js';\nimport { chacha20 } from '@noble/ciphers/chacha.js';\nimport { FFTCore } from '@noble/curves/abstract/fft.js';\nimport type { IField } from '@noble/curves/abstract/modular.js';\nimport { invert } from '@noble/curves/abstract/modular.js';\nimport { bytesToNumberLE, numberToHexUnpadded } from '@noble/curves/utils.js';\nimport { shake256 } from '@noble/hashes/sha3.js';\nimport {\n abytes,\n bytesToHex,\n createView,\n hexToBytes,\n randomBytes,\n swap32IfBE,\n type TypedArray,\n u32,\n u8,\n} from '@noble/hashes/utils.js';\nimport { genCrystals, type TypedCons } from './_crystals';\nimport {\n baswap64If,\n type BytesCoderLen,\n cleanBytes,\n copyBytes,\n type Coder,\n type CryptoKeys,\n getMask,\n type Signer,\n type SigOpts,\n splitCoder,\n type TArg,\n type TRet,\n validateSigOpts,\n validateVerOpts,\n SIG_OPT_KEYS,\n type VerOpts,\n} from './utils';\n/*\nFIPS-206 would likely improve the situation with spec.\n\nFalcon (non-FIPS) spec is terrible. Two main issues: non-deterministic keys & floats.\n\n## Summary\n\n- NIST round3 KATs pass\n- No interop with other JS libraries, because they are incorrect\n- No recoverPublicKey: it requires s1, which is calculated from public+s2. Sig only has s2.\n- Code has verify_recover, but it's unused\n- Mediocre code quality, primarily because it follows implementation-specific (C lib) tidbits\n- Samplers are fragile\n\n## Non-deterministic keys\n\nFalcon spec doesn't provide enough data to re-create keys from KAT vectors. Spec mentions:\n> This process reduces the maximum sizes of coefficients of F and G\n> by about 30 bits at each iteration\nWhile actual implementation reduces them by 25 bits (scale_k), which is very important detail.\n\nThere are also various implementation checks not mentioned in spec, like\n> let's skip this perfectly valid key, because it doesn't fit into our bigint implementation\n\nWithout these, it's hard to produce correct keys. This means that,\nunless NIST specifies full process with all operations,\n**all keys are implementation-specific**.\n\nWhich means, we cannot use any key derivation schemes here: same seed will return\ndifferent keys in different implementations.\n\nThis also complicates testing a lot. If a key succesfully signs a message and other implementations\nconfirm it, there is still zero assurance with regards to quality / entropy of the key.\nOne can create a valid key, which nevertheless doesn't have enough entropy.\n\n## Floats\n\nPartially fixed by \"fixed point\" primitive. Falcon basically impelements floats on top of u64.\n\nIt's more constant-time, but in JS there is no **fast** u64:\n\n- Using bigint backend would drop const-timeness\n- Using u32 {hi, low} tuples means unnecessary allocations / jit deopt,\n and is still 4 times slower than Floats\n\nThen, there are rounding issues. This is implementation specific.\nThis matters more for C, since 'double' is not neccesarily binary64.\nIn js, floats guaranteed to be IEEE-754 binary64.\n\nIn theory floats are nice, but since fixed point format is not specified in spec\n(other that \"it is binary64\"), this is even more fragile, since it doesn't implement exact\nfull spec of binary64 (two zeros/subnomarls/nans/etc). Those parts should not be used inside falcon,\nbut may cause some differences.\n\nLack of specification is also hard to debug, brings precision loss (a+b+c !== a+c+b):\nthere are no serialized floats, all float arithmetic happens inside of an algorithm, so\nwe can produce same results (small differences rounded at the end).\n\nFor byte-to-byte result in falcon, one needs to copy implementation-specific details, unspecced.\n\n## CSPRNG\n\nNIST KATs randomness situation is bad:\n\n1. aes-drbg generates seed\n2. The seed passes CSPRNG into sign, which uses shake256 to produce another seed and nonce\n3. Then a separate rejection sampling chacha20 CSPRNG is created, based on that seed.\n\n## Detached vs non-detached\n\nThe API is different between detached / non-detached signatures,\nhowever only non-detached (sm) is included in KAT, so we implement them\n(crypto_sign_open instead of crypto_sign_verify).\n*/\n\n// Utils\n// MSB first. Current Falcon uses are byte-aligned only, and outer wrappers must still enforce\n// exact body lengths / canonical padding because this helper neither flushes nor rejects a final\n// partial field on its own.\nconst bitsCoderMSB = <T extends TypedArray>(\n newPoly: TypedCons<T>,\n N: number,\n d: number,\n c: Coder<number, number>\n): TRet<BytesCoderLen<T>> => {\n const mask = getMask(d);\n const bytesLen = d * (N / 8);\n return {\n bytesLen,\n encode: (poly: TArg<T>): TRet<Uint8Array> => {\n if (poly.length !== N) throw new Error(`wrong length: expected ${N}, got ${poly.length}`);\n const r = new Uint8Array(bytesLen);\n for (let i = 0, buf = 0, bufLen = 0, pos = 0; i < poly.length; i++) {\n buf = (buf << d) | (c.encode(poly[i]) & mask);\n bufLen += d;\n for (; bufLen >= 8; bufLen -= 8) r[pos++] = (buf >>> (bufLen - 8)) & 0xff;\n }\n return r as TRet<Uint8Array>;\n },\n decode: (bytes: TArg<Uint8Array>): TRet<T> => {\n const r = newPoly(N);\n for (let i = 0, buf = 0, bufLen = 0, pos = 0; i < bytes.length; i++) {\n buf = (buf << 8) | bytes[i];\n bufLen += 8;\n for (; bufLen >= d; bufLen -= d) r[pos++] = c.decode((buf >>> (bufLen - d)) & mask);\n }\n return r as TRet<T>;\n },\n } as TRet<BytesCoderLen<T>>;\n};\n// Adds a single leading tag byte. Exact body validation is delegated to `restCoder.decode()`.\n// encode() zeroizes the temporary encoded body after copying, so wrapped encoders must return\n// owned scratch bytes rather than caller-owned buffers.\nconst headerCoder = <T>(tag: number, restCoder: TArg<BytesCoderLen<T>>): TRet<BytesCoderLen<T>> => {\n const coder = restCoder as BytesCoderLen<T>;\n return {\n bytesLen: 1 + coder.bytesLen,\n encode(value: TArg<T>): TRet<Uint8Array> {\n const body = coder.encode(value as T);\n const out = new Uint8Array(1 + body.length);\n out[0] = tag;\n out.set(body, 1);\n cleanBytes(body);\n return out as TRet<Uint8Array>;\n },\n decode(data: TArg<Uint8Array>): TRet<T> {\n if (data[0] !== tag) throw new Error(`wrong tag: expected ${tag}, got 0x${data[0]}`);\n return coder.decode(data.subarray(1)) as TRet<T>;\n },\n } as TRet<BytesCoderLen<T>>;\n};\n\n// Fun, but overengineered. Hoping FIPS would fix this.\n// Falcon-specific Golomb-Rice compressed format:\n// Vec<[1bit sign, 7 bit low, array(1 terminated).length==high <<7]>.\n// decode() returns only coefficients, so callers must still enforce exact consumed length /\n// canonical framing around the payload.\nconst compCoder = (n: number) => {\n const LIMIT = 2047;\n return {\n encode(data: TArg<Int16Array>): TRet<Uint8Array> {\n // Algorithm 17: Compress(s, slen) (Page 47)\n // Require: A polynomial s = Σ sᵢxⁱ ∈ Z[x] of degree < n, a string bitlength slen\n // Ensure: A compressed representation str of s of slen bits, or ⊥\n // 1: str ← {} ▷ str is the empty string\n // 2: for i from 0 to n-1 do ▷ At each step, str ← (str||strᵢ), where strᵢ encodes sᵢ\n // 3: str ← (str||b), where b = 1 if sᵢ < 0, b = 0 otherwise ▷ Encode the sign of sᵢ\n // 4: str ← (str||b₆b₅...b₀), where bⱼ = (|sᵢ| >> j) & 0x1\n // ▷ Encode in binary the low bits of |sᵢ|\n // 5: k ← |sᵢ| >> 7\n // 6: str ← (str||0ᵏ1) ▷ Encode in unary the high bits of |sᵢ|\n // 7: if |str| > slen then\n // 8: str ← ⊥ ▷ Abort if str is too long\n // 9: else\n // 10: str ← (str||0^{slen-|str|}) ▷ Pad str to slen bits\n // 11: return str\n if (data.length !== n) throw new Error('wrong length');\n const res: number[] = [];\n let buf = 0;\n let bufLen = 0;\n const writeBits = (n: number, v: number) => {\n bufLen += n;\n buf = (buf << n) | v;\n // flush buffer if bigger than byte\n for (; bufLen >= 8; buf &= getMask(bufLen)) {\n bufLen -= 8;\n res.push((buf >>> bufLen) & 0xff);\n }\n };\n for (let i = 0; i < n; i++) {\n let v = data[i];\n if (!Number.isInteger(v) || v < -LIMIT || v > LIMIT)\n throw new Error(`data[${i}]=${v} out of range`);\n const sign = v < 0 ? 1 : 0;\n v = Math.abs(v);\n writeBits(1, sign);\n writeBits(7, v & 0b0111_1111); // low\n writeBits((v >>> 7) + 1, 1); // high (unary)\n }\n if (bufLen > 0) res.push((buf << (8 - bufLen)) & 0xff);\n return new Uint8Array(res) as TRet<Uint8Array>;\n },\n decode(data: TArg<Uint8Array>): TRet<Int16Array> {\n // Algorithm 18: Decompress(str, slen), (Page 48)\n // Require: A bitstring str = (str[i])_{i=0,...,slen-1}, a bitlength slen\n // Ensure: A polynomial s = Σ sᵢxⁱ ∈ Z[x], or ⊥\n // 1: if |str| ≠ slen then ▷ Enforce fixed bitlength\n // 2: return ⊥\n // 3: for i from 0 to (n-1) do\n // 4: s'ᵢ ← Σ_{j=0 to 6} 2⁶⁻ʲ · str[1 + j] ▷ We recover the lowest bits of |sᵢ|.\n // 5: k ← 0\n // 6: while str[8 + k] = 0 do ▷ We recover the highest bits of |sᵢ|.\n // 7: k ← k + 1\n // 8: sᵢ ← (-1)^{str[0]} · (s'ᵢ + 2⁷k) ▷ We recompute sᵢ.\n // 9: if (sᵢ = 0) and (str[0] = 1) then ▷ Enforce unique encoding if sᵢ = 0\n // 10: return ⊥\n // 11: str ← str with first 9 + k bits removed ▷ We remove the bits of str that encode sᵢ.\n // 12: if str contains any non-zero bits then ▷ Enforce trailing bits at 0\n // 13: return ⊥\n // 14: return s = Σ_{i=0}^{n-1} sᵢxⁱ\n const res = new Int16Array(n);\n let buf = 0;\n let bufLen = 0;\n let pos = 0;\n const readBits = (n: number) => {\n for (; bufLen < n && pos < data.length; bufLen += 8) buf = (buf << 8) | data[pos++];\n if (bufLen < n)\n throw new Error(`end of buffer: len=${bufLen} buf=${buf} lastByte=${data[pos]}`);\n bufLen -= n;\n const val = buf >>> bufLen;\n buf &= getMask(bufLen);\n return val;\n };\n for (let resPos = 0; resPos < n; resPos++) {\n const sign = readBits(1);\n const low = readBits(7);\n let high = 0;\n // Reference comp_decode adds 128 for each unary zero and rejects immediately above 2047.\n // Waiting for the terminating one first lets an invalid coefficient scan the entire input.\n while (!readBits(1)) {\n high++;\n if (high > LIMIT >>> 7) throw new Error(`limit: ${low | (high << 7)} > ${LIMIT}`);\n }\n const v = low | (high << 7);\n if (sign && v === 0) throw new Error('negative zero encoding');\n if (v > LIMIT) throw new Error(`limit: ${v} > ${LIMIT}`);\n res[resPos] = sign ? -v : v;\n }\n if (buf) throw new Error('non-empty accumulator');\n return res as TRet<Int16Array>;\n },\n };\n};\n\n// Falcon padded-signature helper. encode() assumes `data.length <= len`; decode() strips trailing\n// zero padding and returns a subarray view, so it is not a generic byte-string codec.\nconst pad = (len: number) => ({\n encode(data: TArg<Uint8Array>) {\n const res = new Uint8Array(len);\n res.set(data);\n return res;\n },\n decode(data: TArg<Uint8Array>) {\n let end = data.length;\n while (end > 0 && data[end - 1] === 0) end--;\n return data.subarray(0, end);\n },\n});\n// TODO: merge with noble-curves bls?\ntype ComplexElm<T> = { re: T; im: T };\n// Zero complex-polynomial temporaries in place. Requires fully initialized `{ re, im }` entries.\nconst cleanCPoly = (...list: CPoly[]): void => {\n for (const p of list) {\n for (let i = 0; i < p.length; i++) {\n p[i].re = 0;\n p[i].im = 0;\n }\n }\n};\n// Generic complex helper used by Falcon's FFT code. Current audited use relies on\n// add/sub/mul/conj/scale/magSqSum/neg; inv() is intentionally unimplemented.\nfunction getComplex<T>(field: IField<T>) {\n const F = field;\n return {\n lift: (x: ComplexElm<T> | T): ComplexElm<T> => {\n // Reuse existing complex objects verbatim; callers that need isolation must clone first.\n if ((x as any).re !== undefined && (x as any).im !== undefined) return x as ComplexElm<T>;\n return { re: x as T, im: F.ZERO };\n },\n add: (a: ComplexElm<T>, b: ComplexElm<T>): ComplexElm<T> => ({\n re: F.add(a.re, b.re),\n im: F.add(a.im, b.im),\n }),\n sub: (a: ComplexElm<T>, b: ComplexElm<T>): ComplexElm<T> => ({\n re: F.sub(a.re, b.re),\n im: F.sub(a.im, b.im),\n }),\n mul: (a: ComplexElm<T>, b: ComplexElm<T>): ComplexElm<T> => ({\n re: F.sub(F.mul(a.re, b.re), F.mul(a.im, b.im)),\n im: F.add(F.mul(a.re, b.im), F.mul(a.im, b.re)),\n }),\n div: (a: ComplexElm<T>, b: ComplexElm<T>): ComplexElm<T> => {\n const denom = F.add(F.mul(b.re, b.re), F.mul(b.im, b.im));\n return {\n re: F.div(F.add(F.mul(a.re, b.re), F.mul(a.im, b.im)), denom),\n im: F.div(F.sub(F.mul(a.im, b.re), F.mul(a.re, b.im)), denom),\n };\n },\n neg: (a: ComplexElm<T>): ComplexElm<T> => ({ re: F.neg(a.re), im: F.neg(a.im) }),\n conj: (a: ComplexElm<T>): ComplexElm<T> => ({ re: a.re, im: F.neg(a.im) }),\n scale: (a: ComplexElm<T>, x: T | bigint): ComplexElm<T> => ({\n re: F.mul(a.re, x),\n im: F.mul(a.im, x),\n }),\n // a.re * a.re + a.im * a.im + b.re * b.re + b.im * b.im;\n magSqSum: (a: ComplexElm<T>, b: ComplexElm<T>): T =>\n F.add(\n F.add(F.add(F.mul(a.re, a.re), F.mul(a.im, a.im)), F.mul(b.re, b.re)),\n F.mul(b.im, b.im)\n ),\n eql: (a: ComplexElm<T>, b: ComplexElm<T>): boolean => F.eql(a.re, b.re) && F.eql(a.im, b.im),\n clone: (a: ComplexElm<T>): ComplexElm<T> => ({ re: a.re, im: a.im }),\n inv: () => {\n throw new Error('not implemented');\n },\n };\n}\n// Falcon real-polynomial FFT layout: [...re, ...im]. Requires an even-length flat array and\n// copies into fresh JS objects / arrays instead of creating views.\nconst ComplexArr = {\n decode(lst: number[]): ComplexElm<number>[] {\n const N = lst.length;\n const hn = N >> 1;\n const len = lst.length;\n if (len === 0) return [];\n if (len % 2 !== 0)\n throw new Error('Array length must be even to pair real and imaginary parts.');\n const res = [];\n for (let i = 0; i < hn; i++) {\n res.push({ re: lst[i], im: lst[i + hn] });\n }\n return res;\n },\n encode(lst: ComplexElm<number>[]): number[] {\n const re = [];\n const im = [];\n for (const i of lst) {\n re.push(i.re);\n im.push(i.im);\n }\n return [...re, ...im];\n },\n};\n// Precomputed root-table layout [re[0], im[0], re[1], im[1], ...]. Used for `COMPLEX_ROOTS`,\n// not Falcon's packed polynomial FFT layout; encode() is currently unused.\n// decode() / encode() copy between the flat root table\n// and detached `{ re, im }` objects; they never create aliasing views.\nconst ComplexArrInterleaved = {\n decode(lst: ArrayLike<number>): ComplexElm<number>[] {\n const len = lst.length;\n if (len === 0) return [];\n if (len % 2 !== 0)\n throw new Error('Array length must be even to pair real and imaginary parts.');\n const res: ComplexElm<number>[] = [];\n // Iterate through the list, taking two elements at a time\n for (let i = 0; i < len; i += 2) {\n res.push({ re: lst[i], im: lst[i + 1] });\n }\n return res;\n },\n encode(lst: ComplexElm<number>[]): number[] {\n const res: number[] = [];\n for (const complexNum of lst) {\n res.push(complexNum.re);\n res.push(complexNum.im);\n }\n return res;\n },\n};\n// Alias a Float64Array as bytes for the root-table hash pin; not a portable serialization.\nconst u8f = (arr: TArg<Float64Array>): TRet<Uint8Array> =>\n new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength) as TRet<Uint8Array>;\n\n// Alias bytes as Float64Array lanes. Falcon's exact binary64 tables are stored as little-endian\n// payload bytes, so BE runtimes must decode lane-by-lane instead of aliasing host-endian floats.\n// Copy/truncate to whole 8-byte lanes first\n// so BE byte swaps cannot mutate caller-owned bytes\n// or read a partial float.\nconst f64a = (arr: TArg<Uint8Array>): TRet<Float64Array> =>\n new Float64Array(\n baswap64If(Uint8Array.from(arr.subarray(0, Math.floor(arr.byteLength / 8) * 8))).buffer\n ) as TRet<Float64Array>;\n\n// Exact big-endian binary64 hex helper for constants. Only decode() is currently used; malformed\n// inputs fail through lower-level hex / DataView checks instead of an explicit wrapper guard.\nconst Float = /* @__PURE__ */ Object.freeze({\n encode(n: number): string {\n const bytes = new Uint8Array(8);\n const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);\n view.setFloat64(0, n, false);\n return bytesToHex(bytes);\n },\n decode(s: string): number {\n const bytes = hexToBytes(s);\n const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);\n return view.getFloat64(0, false);\n },\n});\n// Decode a 64-bit bigint bit pattern into the exact binary64 value.\nconst f64b = (n: bigint): number => Float.decode(numberToHexUnpadded(n));\n\n// Types\ntype SignatureRaw = { msg: Uint8Array; nonce: Uint8Array; s2: Uint8Array };\ntype BPoly = bigint[];\ntype FPoly = Float64Array;\ntype SPoly = Int8Array; // Small poly (f/g/F/G)\ntype IPoly = Uint16Array; // Integer poly mod Q\n\n// Constants\nconst EMPTY_CHACHA20_BLOCK = /** @__PURE__ */ new Uint8Array(64);\n// Falcon's randomized hashing salt r is always 320 bits / 40 bytes, and the same width\n// also drives the detached and attached signature wire formats.\nconst NONCELEN = 40;\n\n// Falcon's public modulus q = 12289 is also the NTT parameter chosen in round 3.\nconst Q: number = 12289; // 12 * 1024 + 1\n// Falcon's midpoint floor(q/2); the only live use is the mirrored G-reconstruction reduction below.\nconst Qhalf: number = Q >> 1;\nconst QBig = BigInt(Q);\nconst _0n = /* @__PURE__ */ BigInt(0);\nconst _1n = /* @__PURE__ */ BigInt(1);\nconst _10n = /* @__PURE__ */ BigInt(10);\nconst _25n = /* @__PURE__ */ BigInt(25);\nconst _31n = /* @__PURE__ */ BigInt(31);\nconst _32n = /* @__PURE__ */ BigInt(32);\nconst _63n = /* @__PURE__ */ BigInt(63);\nconst _64n = /* @__PURE__ */ BigInt(64);\n// Low 32 bits and low 63 bits of a bigint, used by the chacha20 counter and gaussian sampler.\nconst MASK_32n = /* @__PURE__ */ BigInt('0xffffffff');\nconst MASK_63n = /* @__PURE__ */ BigInt('0x7fffffffffffffff');\n//const R = 4091; // 2^16 mod q\n// This 16-bit Montgomery kernel uses R = 2^16, so mul(x, R2) converts x into Montgomery form.\nconst R2 = 10952; // 2^32 mod q\n// falcon.pdf page 55 says \"1/q mod 2^16\",\n// but the reduction formula and the round-3 Falcon code both require -1/q.\nconst Q0I = 12287; // -1/q mod 2^16\nconst F_INV_Q = 1.0 / Q;\nconst F_MINUS_INV_Q = -F_INV_Q;\n// Round-3 bigint keygen keeps these tables coupled: MAX_BL_SMALL and MAX_BL_LARGE are measured\n// 31-bit word bounds, and BITLENGTH is the measured avg/stddev heuristic. Edits must recheck the\n// next-depth relation and the current 31 * wordCount headroom used by reduce().\nconst MAX_BL_SMALL = [1, 1, 2, 2, 4, 7, 14, 27, 53, 106, 209];\n// Unreduced F/G word bounds for reduce(); the same round-3 source also couples this table to the\n// top-10-word floating approximation there,\n// so it must stay in sync with MAX_BL_SMALL and BITLENGTH.\nconst MAX_BL_LARGE = [2, 2, 5, 7, 12, 21, 40, 78, 157, 308];\n// Exact binary64 encoding of Falcon's Gram-Schmidt keygen bound (1.17^2) * q = 16822.4121.\nconst BNORM_MAX = f64b(BigInt('4670353323383631276'));\n// Measured round-3 bigint-keygen heuristic, not a normative Falcon parameter table or proof bound.\nconst BITLENGTH = [\n { avg: 4, std: 0 },\n { avg: 11, std: 1 },\n { avg: 24, std: 1 },\n { avg: 50, std: 1 },\n { avg: 102, std: 1 },\n { avg: 202, std: 2 },\n { avg: 401, std: 4 },\n { avg: 794, std: 5 },\n { avg: 1577, std: 8 },\n { avg: 3138, std: 13 },\n { avg: 6308, std: 25 },\n];\n// First entry is P(x = 0); the remaining entries are conditional tail thresholds scaled by 2^63.\n// Smaller Falcon dimensions reuse the N = 1024, q = 12289 table by summing 2^(10-logn) draws.\n// The trailing 0 sentinel guarantees gaussSingle()\n// always selects a tail bucket when x = 0 is missed.\nconst gauss_1024_12289 = /* @__PURE__ */ [\n '1283868770400643928',\n '6416574995475331444',\n '4078260278032692663',\n '2353523259288686585',\n '1227179971273316331',\n '575931623374121527',\n '242543240509105209',\n '91437049221049666',\n '30799446349977173',\n '9255276791179340',\n '2478152334826140',\n '590642893610164',\n '125206034929641',\n '23590435911403',\n '3948334035941',\n '586753615614',\n '77391054539',\n '9056793210',\n '940121950',\n '86539696',\n '7062824',\n '510971',\n '32764',\n '1862',\n '94',\n '4',\n '0',\n].map(BigInt);\n\n// Exact binary64 1/sigma payloads from round-3 fpr.h. Nearby decimal spellings round 1 ULP low in\n// JS, so keep these as decoded bit patterns and recheck the raw payloads after edits.\nconst INV_SIGMA = /* @__PURE__ */ Object.freeze([\n 0.0, // unused\n f64b(BigInt('4574611497772390042')),\n f64b(BigInt('4574501679055810265')),\n f64b(BigInt('4574396282908341804')),\n f64b(BigInt('4574245855758572086')),\n f64b(BigInt('4574103865040221165')),\n f64b(BigInt('4573969550563515544')),\n f64b(BigInt('4573842244705920822')),\n f64b(BigInt('4573721358406441454')),\n f64b(BigInt('4573606369665796042')),\n f64b(BigInt('4573496814039276259')),\n]);\n\n// Exact binary64 sigma_min constants from round-3 fpr.h indexed by logn; despite one PQClean\n// summary comment, these are sigma_min itself, not 1/sigma_min, which is why this table stays\n// separate from INV_SIGMA.\nconst SIGMA_MIN = /* @__PURE__ */ Object.freeze([\n 0.0, // unused\n f64b(BigInt('4607707126469777035')),\n f64b(BigInt('4607777455861499430')),\n f64b(BigInt('4607846828256951418')),\n f64b(BigInt('4607949175006100261')),\n f64b(BigInt('4608049571757433526')),\n f64b(BigInt('4608148125896792003')),\n f64b(BigInt('4608244935301382692')),\n f64b(BigInt('4608340089478362016')),\n f64b(BigInt('4608433670533905013')),\n f64b(BigInt('4608525754002622308')),\n]);\n// Upper end of the SamplerZ proof interval from Falcon section 3.9.1. The per-leaf sigma is\n// derived from the reconstructed private basis, so imported keys must be checked against it.\nconst SIGMA_MAX = 1.8205;\n\n// Falcon Table 3.1 RCDT values for chi, split into 24-bit limbs; storage is [high, mid, low],\n// so gaussian0() intentionally compares them against v0, v1, v2 in reverse order. The final\n// RCDT[18] = 0 row is omitted because the algorithm iterates only over i = 0..17.\nconst GAUSS0 = new Uint32Array([\n 10745844, 3068844, 3741698, 5559083, 1580863, 8248194, 2260429, 13669192, 2736639, 708981,\n 4421575, 10046180, 169348, 7122675, 4136815, 30538, 13063405, 7650655, 4132, 14505003, 7826148,\n 417, 16768101, 11363290, 31, 8444042, 8086568, 1, 12844466, 265321, 0, 1232676, 13644283, 0,\n 38047, 9111839, 0, 870, 6138264, 0, 14, 12545723, 0, 0, 3104126, 0, 0, 28824, 0, 0, 198, 0, 0, 1,\n]);\n\n// Inclusive floor(beta^2) signature-acceptance bounds indexed by logn; the Falcon PDF publishes\n// only Falcon-512 and Falcon-1024 directly, while the smaller rows are mirrored from the round-3\n// NIST submission package.\nconst L2BOUND = [\n 0, // unused\n 101498,\n 208714,\n 428865,\n 892039,\n 1852696,\n 3842630,\n 7959734,\n 16468416,\n 34034726,\n 70265242,\n];\n\n// 32kb in hex.\n// Could be 4x smaller by using 2 bytes per root. However, that would mean using sin/cos.\n// Different JS engines give different sin / cos result, which means the result would be unreliable.\n// See \"COMPLEX ROOT GENERATION FOR FALCON\" in tests.\n// Those exact roots are taken from the round-3 Falcon submission, preserving its original\n// bit-reversed order here and remapping it only later for FFTCore.\nconst COMPLEX_ROOTS = /** @__PURE__ */ (() => {\n const roots = f64a(\n hexToBytes(\n '000000000000000000000000000000000000000000000080000000000000f03fcd3b7f669ea0e63fcd3b7f66' +\n '9ea0e63fcd3b7f669ea0e6bfcd3b7f669ea0e63f468d32cf6b90ed3f63a9aea6e27dd83f63a9aea6e27dd8bf' +\n '468d32cf6b90ed3f63a9aea6e27dd83f468d32cf6b90ed3f468d32cf6b90edbf63a9aea6e27dd83fb05cf7cf' +\n '9762ef3f0ba6693cb8f8c83f0ba6693cb8f8c8bfb05cf7cf9762ef3fc868ae393bc7e13fa3a10e29669bea3f' +\n 'a3a10e29669beabfc868ae393bc7e13fa3a10e29669bea3fc868ae393bc7e13fc868ae393bc7e1bfa3a10e29' +\n '669bea3f0ba6693cb8f8c83fb05cf7cf9762ef3fb05cf7cf9762efbf0ba6693cb8f8c83f2625d1a38dd8ef3f' +\n '2cb429bca617b93f2cb429bca617b9bf2625d1a38dd8ef3fd61d0925f34ce43f4117156b80bce83f4117156b' +\n '80bce8bfd61d0925f34ce43fb1bd80f1b238ec3f3bf606385d2bde3f3bf606385d2bdebfb1bd80f1b238ec3f' +\n '069fd52e0694d23fda2dc656419fee3fda2dc656419feebf069fd52e0694d23fda2dc656419fee3f069fd52e' +\n '0694d23f069fd52e0694d2bfda2dc656419fee3f3bf606385d2bde3fb1bd80f1b238ec3fb1bd80f1b238ecbf' +\n '3bf606385d2bde3f4117156b80bce83fd61d0925f34ce43fd61d0925f34ce4bf4117156b80bce83f2cb429bc' +\n 'a617b93f2625d1a38dd8ef3f2625d1a38dd8efbf2cb429bca617b93f7e6d79e321f6ef3f14d80df1651fa93f' +\n '14d80df1651fa9bf7e6d79e321f6ef3fa0ec8c34697de53fafaf6a22dfb5e73fafaf6a22dfb5e7bfa0ec8c34' +\n '697de53f73c73cf47aedec3fc05ce109105ddb3fc05ce109105ddbbf73c73cf47aedec3fdd1fab759a8fd53f' +\n 'e586f6042121ee3fe586f6042121eebfdd1fab759a8fd53fd73092fb7e0aef3f1b5f217bf919cf3f1b5f217b' +\n 'f919cfbfd73092fb7e0aef3feeff22998773e03f3e6e19458372eb3f3e6e19458372ebbfeeff22998773e03f' +\n '4187f347e0b3e93f3570e1fcf70fe33f3570e1fcf70fe3bf4187f347e0b3e93f3a618e6e10c8c23f17a5087f' +\n '55a7ef3f17a5087f55a7efbf3a618e6e10c8c23f17a5087f55a7ef3f3a618e6e10c8c23f3a618e6e10c8c2bf' +\n '17a5087f55a7ef3f3570e1fcf70fe33f4187f347e0b3e93f4187f347e0b3e9bf3570e1fcf70fe33f3e6e1945' +\n '8372eb3feeff22998773e03feeff22998773e0bf3e6e19458372eb3f1b5f217bf919cf3fd73092fb7e0aef3f' +\n 'd73092fb7e0aefbf1b5f217bf919cf3fe586f6042121ee3fdd1fab759a8fd53fdd1fab759a8fd5bfe586f604' +\n '2121ee3fc05ce109105ddb3f73c73cf47aedec3f73c73cf47aedecbfc05ce109105ddb3fafaf6a22dfb5e73f' +\n 'a0ec8c34697de53fa0ec8c34697de5bfafaf6a22dfb5e73f14d80df1651fa93f7e6d79e321f6ef3f7e6d79e3' +\n '21f6efbf14d80df1651fa93f0dcd846088fdef3f7e66a3f75521993f7e66a3f7552199bf0dcd846088fdef3f' +\n 'df2c1d55b710e63f96ffef37082de73f96ffef37082de7bfdf2c1d55b710e63f3ac94dd13441ed3f8aeda843' +\n '79efd93f8aeda84379efd9bf3ac94dd13441ed3f9f45fa308508d73f3cc2ccb613dbed3f3cc2ccb613dbedbf' +\n '9f45fa308508d73f89e564acf338ef3f634f7e6a820bcc3f634f7e6a820bccbf89e564acf338ef3f234b1b54' +\n 'b31ee13f000215580a09eb3f000215580a09ebbf234b1b54b31ee13f822746a0a729ea3fdf12dd4c056de23f' +\n 'df12dd4c056de2bf822746a0a729ea3fc63f8b4414e2c53fa94b71fa6487ef3fa94b71fa6487efbfc63f8b44' +\n '14e2c53fd39fe17064c2ef3f0e73a9564e56bf3f0e73a9564e56bfbfd39fe17064c2ef3fb9502029faafe33f' +\n 'fb639249223ae93ffb639249223ae9bfb9502029faafe33f2a956facc0d7eb3fba9af8dba48bdf3fba9af8db' +\n 'a48bdfbf2a956facc0d7eb3f77f6b162d211d13f634968e740d7ee3f634968e740d7eebf77f6b162d211d13f' +\n '12e148ec8862ee3f016617945c13d43f016617945c13d4bf12e148ec8862ee3f5ec431996ec6dc3ff5113421' +\n '4b95ec3ff51134214b95ecbf5ec431996ec6dc3f6e97ff0b0e3be83fe9e5e3bbcae6e43fe9e5e3bbcae6e4bf' +\n '6e97ff0b0e3be83ff619ce9220d5b23f3a8801adcde9ef3f3a8801adcde9efbff619ce9220d5b23f3a8801ad' +\n 'cde9ef3ff619ce9220d5b23ff619ce9220d5b2bf3a8801adcde9ef3fe9e5e3bbcae6e43f6e97ff0b0e3be83f' +\n '6e97ff0b0e3be8bfe9e5e3bbcae6e43ff51134214b95ec3f5ec431996ec6dc3f5ec431996ec6dcbff5113421' +\n '4b95ec3f016617945c13d43f12e148ec8862ee3f12e148ec8862eebf016617945c13d43f634968e740d7ee3f' +\n '77f6b162d211d13f77f6b162d211d1bf634968e740d7ee3fba9af8dba48bdf3f2a956facc0d7eb3f2a956fac' +\n 'c0d7ebbfba9af8dba48bdf3ffb639249223ae93fb9502029faafe33fb9502029faafe3bffb639249223ae93f' +\n '0e73a9564e56bf3fd39fe17064c2ef3fd39fe17064c2efbf0e73a9564e56bf3fa94b71fa6487ef3fc63f8b44' +\n '14e2c53fc63f8b4414e2c5bfa94b71fa6487ef3fdf12dd4c056de23f822746a0a729ea3f822746a0a729eabf' +\n 'df12dd4c056de23f000215580a09eb3f234b1b54b31ee13f234b1b54b31ee1bf000215580a09eb3f634f7e6a' +\n '820bcc3f89e564acf338ef3f89e564acf338efbf634f7e6a820bcc3f3cc2ccb613dbed3f9f45fa308508d73f' +\n '9f45fa308508d7bf3cc2ccb613dbed3f8aeda84379efd93f3ac94dd13441ed3f3ac94dd13441edbf8aeda843' +\n '79efd93f96ffef37082de73fdf2c1d55b710e63fdf2c1d55b710e6bf96ffef37082de73f7e66a3f75521993f' +\n '0dcd846088fdef3f0dcd846088fdefbf7e66a3f75521993fdb929b1662ffef3f84c7defcd121893f84c7defc' +\n 'd12189bfdb929b1662ffef3f3d78f0251959e63fafa8ea5444e7e63fafa8ea5444e7e6bf3d78f0251959e63f' +\n '8be6c9736169ed3fd793bc632a37d93fd793bc632a37d9bf8be6c9736169ed3fe7cc1d31a9c3d73f9ba03862' +\n '52b6ed3f9ba0386252b6edbfe7cc1d31a9c3d73f2d2f0b3b604eef3f5104b025a082ca3f5104b025a082cabf' +\n '2d2f0b3b604eef3f49dbde634d73e13f11d5219ebcd2ea3f11d5219ebcd2eabf49dbde634d73e13fe2fa021b' +\n '0963ea3f59eb3399791ae23f59eb3399791ae2bfe2fa021b0963ea3f31bf50ded96dc73f7720a1a39975ef3f' +\n '7720a1a39975efbf31bf50ded96dc73f7ba66dfd15ceef3fd5c29ec78537bc3fd5c29ec78537bcbf7ba66dfd' +\n '15ceef3fd4564553d9fee33f0d94efa3ccfbe83f0d94efa3ccfbe8bfd4564553d9fee33f49557226c408ec3f' +\n 'd678ef5219dcde3fd678ef5219dcdebf49557226c408ec3f3edb4c3f44d3d13f740bdfc8d8bbee3f740bdfc8' +\n 'd8bbeebf3edb4c3f44d3d13f0dd14cab7b81ee3f5281e1c21054d33f5281e1c21054d3bf0dd14cab7b81ee3f' +\n '89e3865b7779dd3f9b7388348b67ec3f9b7388348b67ecbf89e3865b7779dd3fbf2eba0f407ce83f39099b9b' +\n '449ae43f39099b9b449ae4bfbf2eba0f407ce83f19a49a0ad0f6b53f095bbdfccae1ef3f095bbdfccae1efbf' +\n '19a49a0ad0f6b53fad718e6595f0ef3fe020f8796e65af3fe020f8796e65afbfad718e6595f0ef3f9655a392' +\n '8232e53f711757e3ecf8e73f711757e3ecf8e7bf9655a3928232e53f5cfcfcf3f0c1ec3fe71e01d84912dc3f' +\n 'e71e01d84912dcbf5cfcfcf3f0c1ec3f6ae77842e2d1d43f7ec12b4b6a42ee3f7ec12b4b6a42eebf6ae77842' +\n 'e2d1d43fc273e4a378f1ee3faefd370eb84fd03faefd370eb84fd0bfc273e4a378f1ee3fb73e4c87fc1ce03f' +\n 'd2903567aaa5eb3fd2903567aaa5ebbfb73e4c87fc1ce03f42d7c7f47e77e93ff35906b15860e33ff35906b1' +\n '5860e3bf42d7c7f47e77e93f77f5dacef039c13f41d7957179b5ef3f41d7957179b5efbf77f5dacef039c13f' +\n '9b09c924f997ef3f5a3e29b17655c43f5a3e29b17655c4bf9b09c924f997ef3feaf3fa25dbbee23f94af29ef' +\n '43efe93f94af29ef43efe9bfeaf3fa25dbbee23f1257f53e4d3eeb3f8f895d4d70c9e03f8f895d4d70c9e0bf' +\n '1257f53e4d3eeb3f114345e54f93cd3fda3a76f75222ef3fda3a76f75222efbf114345e54f93cd3f2bbe2d62' +\n 'aefeed3fc6273fdd7d4cd63fc6273fdd7d4cd6bf2bbe2d62aefeed3fca3f6d2bc8a6da3fdc353e74e717ed3f' +\n 'dc353e74e717edbfca3f6d2bc8a6da3f6172035fe771e73f8c0165be7bc7e53f8c0165be7bc7e5bf6172035f' +\n 'e771e73fcd55947565d8a23f5df7feef72faef3f5df7feef72faefbfcd55947565d8a23f5df7feef72faef3f' +\n 'cd55947565d8a23fcd55947565d8a2bf5df7feef72faef3f8c0165be7bc7e53f6172035fe771e73f6172035f' +\n 'e771e7bf8c0165be7bc7e53fdc353e74e717ed3fca3f6d2bc8a6da3fca3f6d2bc8a6dabfdc353e74e717ed3f' +\n 'c6273fdd7d4cd63f2bbe2d62aefeed3f2bbe2d62aefeedbfc6273fdd7d4cd63fda3a76f75222ef3f114345e5' +\n '4f93cd3f114345e54f93cdbfda3a76f75222ef3f8f895d4d70c9e03f1257f53e4d3eeb3f1257f53e4d3eebbf' +\n '8f895d4d70c9e03f94af29ef43efe93feaf3fa25dbbee23feaf3fa25dbbee2bf94af29ef43efe93f5a3e29b1' +\n '7655c43f9b09c924f997ef3f9b09c924f997efbf5a3e29b17655c43f41d7957179b5ef3f77f5dacef039c13f' +\n '77f5dacef039c1bf41d7957179b5ef3ff35906b15860e33f42d7c7f47e77e93f42d7c7f47e77e9bff35906b1' +\n '5860e33fd2903567aaa5eb3fb73e4c87fc1ce03fb73e4c87fc1ce0bfd2903567aaa5eb3faefd370eb84fd03f' +\n 'c273e4a378f1ee3fc273e4a378f1eebfaefd370eb84fd03f7ec12b4b6a42ee3f6ae77842e2d1d43f6ae77842' +\n 'e2d1d4bf7ec12b4b6a42ee3fe71e01d84912dc3f5cfcfcf3f0c1ec3f5cfcfcf3f0c1ecbfe71e01d84912dc3f' +\n '711757e3ecf8e73f9655a3928232e53f9655a3928232e5bf711757e3ecf8e73fe020f8796e65af3fad718e65' +\n '95f0ef3fad718e6595f0efbfe020f8796e65af3f095bbdfccae1ef3f19a49a0ad0f6b53f19a49a0ad0f6b5bf' +\n '095bbdfccae1ef3f39099b9b449ae43fbf2eba0f407ce83fbf2eba0f407ce8bf39099b9b449ae43f9b738834' +\n '8b67ec3f89e3865b7779dd3f89e3865b7779ddbf9b7388348b67ec3f5281e1c21054d33f0dd14cab7b81ee3f' +\n '0dd14cab7b81eebf5281e1c21054d33f740bdfc8d8bbee3f3edb4c3f44d3d13f3edb4c3f44d3d1bf740bdfc8' +\n 'd8bbee3fd678ef5219dcde3f49557226c408ec3f49557226c408ecbfd678ef5219dcde3f0d94efa3ccfbe83f' +\n 'd4564553d9fee33fd4564553d9fee3bf0d94efa3ccfbe83fd5c29ec78537bc3f7ba66dfd15ceef3f7ba66dfd' +\n '15ceefbfd5c29ec78537bc3f7720a1a39975ef3f31bf50ded96dc73f31bf50ded96dc7bf7720a1a39975ef3f' +\n '59eb3399791ae23fe2fa021b0963ea3fe2fa021b0963eabf59eb3399791ae23f11d5219ebcd2ea3f49dbde63' +\n '4d73e13f49dbde634d73e1bf11d5219ebcd2ea3f5104b025a082ca3f2d2f0b3b604eef3f2d2f0b3b604eefbf' +\n '5104b025a082ca3f9ba0386252b6ed3fe7cc1d31a9c3d73fe7cc1d31a9c3d7bf9ba0386252b6ed3fd793bc63' +\n '2a37d93f8be6c9736169ed3f8be6c9736169edbfd793bc632a37d93fafa8ea5444e7e63f3d78f0251959e63f' +\n '3d78f0251959e6bfafa8ea5444e7e63f84c7defcd121893fdb929b1662ffef3fdb929b1662ffefbf84c7defc' +\n 'd121893f928a8e85d8ffef3f710067fef021793f710067fef02179bf928a8e85d8ffef3f10af9184f77ce63f' +\n '7582c1730dc4e63f7582c1730dc4e6bf10af9184f77ce63ff9ecb8020b7ded3fb0a4c82ea5dad83fb0a4c82e' +\n 'a5dad8bff9ecb8020b7ded3fc4aa4eb0e320d83f888966a983a3ed3f888966a983a3edbfc4aa4eb0e320d83f' +\n '849e78b1a258ef3f6643dcf2cbbdc93f6643dcf2cbbdc9bf849e78b1a258ef3fb8b9f2095a9de13fd4c01659' +\n '32b7ea3fd4c0165932b7eabfb8b9f2095a9de13f9de69f52587fea3f1b86bc8bf0f0e13f1b86bc8bf0f0e1bf' +\n '9de69f52587fea3fc6649ce86633c83fb7bbf57d3f6cef3fb7bbf57d3f6cefbfc6649ce86633c83f840b2214' +\n '79d3ef3f035c4924b7a7ba3f035c4924b7a7babf840b221479d3ef3fb16b8e17ff25e43fcc98163345dce83f' +\n 'cc98163345dce8bfb16b8e17ff25e43fb071a93fde20ec3f1451f8eae083de3f1451f8eae083debfb071a93f' +\n 'de20ec3f71bbc3abbb33d23f8ea8e7e8b2adee3f8ea8e7e8b2adeebf71bbc3abbb33d23ff2f71d368490ee3f' +\n '8703ecda22f4d23f8703ecda22f4d2bff2f71d368490ee3f58cc81148fd2dd3f07692b014250ec3f07692b01' +\n '4250ecbf58cc81148fd2dd3faad44d9a7e9ce83f4773981bb573e43f4773981bb573e4bfaad44d9a7e9ce83f' +\n '215b5d6a5887b73f56f4f19f53ddef3f56f4f19f53ddefbf215b5d6a5887b73f5c578d0f83f3ef3fe3d7c012' +\n '8d42ac3fe3d7c0128d42acbf5c578d0f83f3ef3f375197381058e53fb23dc36c83d7e73fb23dc36c83d7e7bf' +\n '375197381058e53ff6328b89d9d7ec3f01bd0423cfb7db3f01bd0423cfb7dbbff6328b89d9d7ec3f243caf80' +\n 'd830d53f25ce70e8ea31ee3f25ce70e8ea31eebf243caf80d830d53fec950b0c22feee3ff9eddf1adcdccf3f' +\n 'f9eddf1adcdccfbfec950b0c22feee3f1a22ae265648e03fe90475d2388ceb3fe90475d2388cebbf1a22ae26' +\n '5648e03f220dd82ecf95e93f578e0c0d4038e33f578e0c0d4038e3bf220dd82ecf95e93fcf7becd41601c23f' +\n 'bbcf468e8eaeef3fbbcf468e8eaeefbfcf7becd41601c23fc8b2ad55ce9fef3f148dcdb0db8ec33f148dcdb0' +\n 'db8ec3bfc8b2ad55ce9fef3f17eae8e380e7e23fd580eaf5b1d1e93fd580eaf5b1d1e9bf17eae8e380e7e23f' +\n '051492fe8958eb3fe1c51774909ee03fe1c51774909ee0bf051492fe8958eb3f1b1a101eca56ce3f5d20f753' +\n '8f16ef3f5d20f7538f16efbf1b1a101eca56ce3fac8029ca0c10ee3f93a69e3727eed53f93a69e3727eed5bf' +\n 'ac8029ca0c10ee3f09407f6c0d02db3f92bdb2fed402ed3f92bdb2fed402edbf09407f6c0d02db3fe5554f57' +\n '0094e73f50725d2a8da2e53f50725d2a8da2e5bfe5554f570094e73f43cd90d200fca53fdf81dbda71f8ef3f' +\n 'df81dbda71f8efbf43cd90d200fca53ff8d3f11d25fcef3f01cfd13137699f3f01cfd13137699fbff8d3f11d' +\n '25fcef3f7470839534ece53f8dd2a88d944fe73f8dd2a88d944fe7bf7470839534ece53f9fefe020b22ced3f' +\n 'e5a1de27414bda3fe5a1de27414bdabf9fefe020b22ced3f177ec77d9daad63fda47def705eded3fda47def7' +\n '05ededbf177ec77d9daad63f9d9a08c9c92def3f86b212b38ccfcc3f86b212b38ccfccbf9d9a08c9c92def3f' +\n '7e8e2abb26f4e03fb4130047cd23eb3fb4130047cd23ebbf7e8e2abb26f4e03f37f9baea950cea3fa89c6227' +\n '0796e23fa89c62270796e2bf37f9baea950cea3ff2c59785df1bc53fdb41aeffd58fef3fdb41aeffd58fefbf' +\n 'f2c59785df1bc53f8641e41716bcef3f1d83ba47a072c03f1d83ba47a072c0bf8641e41716bcef3f22ebdf85' +\n '4188e33fd76d8ee4ef58e93fd76d8ee4ef58e9bf22ebdf854188e33fea8093c4d7beeb3f1012e74bf6e2df3f' +\n '1012e74bf6e2dfbfea8093c4d7beeb3f90dbdbcfd9b0d03fbc9d5ae282e4ee3fbc9d5ae282e4eebf90dbdbcf' +\n 'd9b0d03ffc9f72049f52ee3f541057a5b872d43f541057a5b872d4bffc9f72049f52ee3f0b0097497f6cdc3f' +\n '00b9a069c1abec3f00b9a069c1abecbf0b0097497f6cdc3fcc7ab5331b1ae83f9ba0599fc00ce53f9ba0599f' +\n 'c00ce5bfcc7ab5331b1ae83fb309d7340144b13fc473b6ec58edef3fc473b6ec58edefbfb309d7340144b13f' +\n '40392eaff3e5ef3f962027791166b43f962027791166b4bf40392eaff3e5ef3f0400ec45a1c0e43fcc58e91a' +\n 'c55be83fcc58e91ac55be8bf0400ec45a1c0e43ff33c23528e7eec3f5bdbe9e81620dd3f5bdbe9e81620ddbf' +\n 'f33c23528e7eec3fb71404faceb3d33f44976adb2772ee3f44976adb2772eebfb71404faceb3d33f84bfc3d3' +\n 'b2c9ee3f775176d7a072d13f775176d7a072d1bf84bfc3d3b2c9ee3f67d03f960534df3fdd7753e164f0eb3f' +\n 'dd7753e164f0ebbf67d03f960534df3fa29dd46f161be93f4483c53882d7e33f4483c53882d7e3bfa29dd46f' +\n '161be93fc99faecb0ec7bd3f21b7fe6c64c8ef3f21b7fe6c64c8efbfc99faecb0ec7bd3f6e3de629a67eef3f' +\n 'b24af60413a8c63fb24af60413a8c6bf6e3de629a67eef3f1fac98fbd543e23fc89a11c87846ea3fc89a11c8' +\n '7846eabf1fac98fbd543e23f74143cb404eeea3feb6c33af1549e13feb6c33af1549e1bf74143cb404eeea3f' +\n '22673def3247cb3fdd92ff85d043ef3fdd92ff85d043efbf22673def3247cb3f600241cbd7c8ed3ff618240f' +\n '3466d73ff618240f3466d7bf600241cbd7c8ed3fffbd41617193d93fb13ee9526f55ed3fb13ee9526f55edbf' +\n 'ffbd41617193d93f7a6d17b3420ae73fe91b1ca30335e63fe91b1ca30335e6bf7a6d17b3420ae73ffd0ee3bb' +\n '36d9923fa1514bb49cfeef3fa1514bb49cfeefbffd0ee3bb36d9923fa1514bb49cfeef3ffd0ee3bb36d9923f' +\n 'fd0ee3bb36d992bfa1514bb49cfeef3fe91b1ca30335e63f7a6d17b3420ae73f7a6d17b3420ae7bfe91b1ca3' +\n '0335e63fb13ee9526f55ed3fffbd41617193d93fffbd41617193d9bfb13ee9526f55ed3ff618240f3466d73f' +\n '600241cbd7c8ed3f600241cbd7c8edbff618240f3466d73fdd92ff85d043ef3f22673def3247cb3f22673def' +\n '3247cbbfdd92ff85d043ef3feb6c33af1549e13f74143cb404eeea3f74143cb404eeeabfeb6c33af1549e13f' +\n 'c89a11c87846ea3f1fac98fbd543e23f1fac98fbd543e2bfc89a11c87846ea3fb24af60413a8c63f6e3de629' +\n 'a67eef3f6e3de629a67eefbfb24af60413a8c63f21b7fe6c64c8ef3fc99faecb0ec7bd3fc99faecb0ec7bdbf' +\n '21b7fe6c64c8ef3f4483c53882d7e33fa29dd46f161be93fa29dd46f161be9bf4483c53882d7e33fdd7753e1' +\n '64f0eb3f67d03f960534df3f67d03f960534dfbfdd7753e164f0eb3f775176d7a072d13f84bfc3d3b2c9ee3f' +\n '84bfc3d3b2c9eebf775176d7a072d13f44976adb2772ee3fb71404faceb3d33fb71404faceb3d3bf44976adb' +\n '2772ee3f5bdbe9e81620dd3ff33c23528e7eec3ff33c23528e7eecbf5bdbe9e81620dd3fcc58e91ac55be83f' +\n '0400ec45a1c0e43f0400ec45a1c0e4bfcc58e91ac55be83f962027791166b43f40392eaff3e5ef3f40392eaf' +\n 'f3e5efbf962027791166b43fc473b6ec58edef3fb309d7340144b13fb309d7340144b1bfc473b6ec58edef3f' +\n '9ba0599fc00ce53fcc7ab5331b1ae83fcc7ab5331b1ae8bf9ba0599fc00ce53f00b9a069c1abec3f0b009749' +\n '7f6cdc3f0b0097497f6cdcbf00b9a069c1abec3f541057a5b872d43ffc9f72049f52ee3ffc9f72049f52eebf' +\n '541057a5b872d43fbc9d5ae282e4ee3f90dbdbcfd9b0d03f90dbdbcfd9b0d0bfbc9d5ae282e4ee3f1012e74b' +\n 'f6e2df3fea8093c4d7beeb3fea8093c4d7beebbf1012e74bf6e2df3fd76d8ee4ef58e93f22ebdf854188e33f' +\n '22ebdf854188e3bfd76d8ee4ef58e93f1d83ba47a072c03f8641e41716bcef3f8641e41716bcefbf1d83ba47' +\n 'a072c03fdb41aeffd58fef3ff2c59785df1bc53ff2c59785df1bc5bfdb41aeffd58fef3fa89c62270796e23f' +\n '37f9baea950cea3f37f9baea950ceabfa89c62270796e23fb4130047cd23eb3f7e8e2abb26f4e03f7e8e2abb' +\n '26f4e0bfb4130047cd23eb3f86b212b38ccfcc3f9d9a08c9c92def3f9d9a08c9c92defbf86b212b38ccfcc3f' +\n 'da47def705eded3f177ec77d9daad63f177ec77d9daad6bfda47def705eded3fe5a1de27414bda3f9fefe020' +\n 'b22ced3f9fefe020b22cedbfe5a1de27414bda3f8dd2a88d944fe73f7470839534ece53f7470839534ece5bf' +\n '8dd2a88d944fe73f01cfd13137699f3ff8d3f11d25fcef3ff8d3f11d25fcefbf01cfd13137699f3fdf81dbda' +\n '71f8ef3f43cd90d200fca53f43cd90d200fca5bfdf81dbda71f8ef3f50725d2a8da2e53fe5554f570094e73f' +\n 'e5554f570094e7bf50725d2a8da2e53f92bdb2fed402ed3f09407f6c0d02db3f09407f6c0d02dbbf92bdb2fe' +\n 'd402ed3f93a69e3727eed53fac8029ca0c10ee3fac8029ca0c10eebf93a69e3727eed53f5d20f7538f16ef3f' +\n '1b1a101eca56ce3f1b1a101eca56cebf5d20f7538f16ef3fe1c51774909ee03f051492fe8958eb3f051492fe' +\n '8958ebbfe1c51774909ee03fd580eaf5b1d1e93f17eae8e380e7e23f17eae8e380e7e2bfd580eaf5b1d1e93f' +\n '148dcdb0db8ec33fc8b2ad55ce9fef3fc8b2ad55ce9fefbf148dcdb0db8ec33fbbcf468e8eaeef3fcf7becd4' +\n '1601c23fcf7becd41601c2bfbbcf468e8eaeef3f578e0c0d4038e33f220dd82ecf95e93f220dd82ecf95e9bf' +\n '578e0c0d4038e33fe90475d2388ceb3f1a22ae265648e03f1a22ae265648e0bfe90475d2388ceb3ff9eddf1a' +\n 'dcdccf3fec950b0c22feee3fec950b0c22feeebff9eddf1adcdccf3f25ce70e8ea31ee3f243caf80d830d53f' +\n '243caf80d830d5bf25ce70e8ea31ee3f01bd0423cfb7db3ff6328b89d9d7ec3ff6328b89d9d7ecbf01bd0423' +\n 'cfb7db3fb23dc36c83d7e73f375197381058e53f375197381058e5bfb23dc36c83d7e73fe3d7c0128d42ac3f' +\n '5c578d0f83f3ef3f5c578d0f83f3efbfe3d7c0128d42ac3f56f4f19f53ddef3f215b5d6a5887b73f215b5d6a' +\n '5887b7bf56f4f19f53ddef3f4773981bb573e43faad44d9a7e9ce83faad44d9a7e9ce8bf4773981bb573e43f' +\n '07692b014250ec3f58cc81148fd2dd3f58cc81148fd2ddbf07692b014250ec3f8703ecda22f4d23ff2f71d36' +\n '8490ee3ff2f71d368490eebf8703ecda22f4d23f8ea8e7e8b2adee3f71bbc3abbb33d23f71bbc3abbb33d2bf' +\n '8ea8e7e8b2adee3f1451f8eae083de3fb071a93fde20ec3fb071a93fde20ecbf1451f8eae083de3fcc981633' +\n '45dce83fb16b8e17ff25e43fb16b8e17ff25e4bfcc98163345dce83f035c4924b7a7ba3f840b221479d3ef3f' +\n '840b221479d3efbf035c4924b7a7ba3fb7bbf57d3f6cef3fc6649ce86633c83fc6649ce86633c8bfb7bbf57d' +\n '3f6cef3f1b86bc8bf0f0e13f9de69f52587fea3f9de69f52587feabf1b86bc8bf0f0e13fd4c0165932b7ea3f' +\n 'b8b9f2095a9de13fb8b9f2095a9de1bfd4c0165932b7ea3f6643dcf2cbbdc93f849e78b1a258ef3f849e78b1' +\n 'a258efbf6643dcf2cbbdc93f888966a983a3ed3fc4aa4eb0e320d83fc4aa4eb0e320d8bf888966a983a3ed3f' +\n 'b0a4c82ea5dad83ff9ecb8020b7ded3ff9ecb8020b7dedbfb0a4c82ea5dad83f7582c1730dc4e63f10af9184' +\n 'f77ce63f10af9184f77ce6bf7582c1730dc4e63f710067fef021793f928a8e85d8ffef3f928a8e85d8ffefbf' +\n '710067fef021793f021d6221f6ffef3fbaa4ccbef821693fbaa4ccbef82169bf021d6221f6ffef3f719ca1ea' +\n 'd18ee63f9ce22fed5cb2e63f9ce22fed5cb2e6bf719ca1ead18ee63f4fa44584c486ed3f44edd5864bacd83f' +\n '44edd5864bacd8bf4fa44584c486ed3f3f90f3aa6a4fd83f463d8bdd009aed3f463d8bdd009aedbf3f90f3aa' +\n '6a4fd83f5d6843eda65def3ffa2ab6e9495bc93ffa2ab6e9495bc9bf5d6843eda65def3fbf73131750b2e13f' +\n '8eb92c7a54a9ea3f8eb92c7a54a9eabfbf73131750b2e13fd25a546e678dea3f7248dc641bdce13f7248dc64' +\n '1bdce1bfd25a546e678dea3f0418c4271796c83fee3c88567567ef3fee3c88567567efbf0418c4271796c83f' +\n '9e5ca72d0dd6ef3f5ca824ebb6dfb93f5ca824ebb6dfb9bf9e5ca72d0dd6ef3f80432a5b7f39e43f55461875' +\n '6acce83f554618756acce8bf80432a5b7f39e43ff1e33149d12cec3f25d83c6da857de3f25d83c6da857debf' +\n 'f1e33149d12cec3fba545599e663d23f0058e69383a6ee3f0058e69383a6eebfba545599e663d23f306b0136' +\n 'ec97ee3f2045954e1ac4d23f2045954e1ac4d2bf306b0136ec97ee3fde41a966fffedd3f04c041318344ec3f' +\n '04c041318344ecbfde41a966fffedd3f881dde1e87ace83fa2322b695a60e43fa2322b695a60e4bf881dde1e' +\n '87ace83fa130c112874fb83f8c531475fadaef3f8c531475fadaefbfa130c112874fb83fd3beb154dcf4ef3f' +\n '17835fbd01b1aa3f17835fbd01b1aabfd3beb154dcf4ef3f9f649751c36ae53f33d3e29cb8c6e73f33d3e29c' +\n 'b8c6e7bf9f649751c36ae53f60a09927b3e2ec3f9356fd14788adb3f9356fd14788adbbf60a09927b3e2ec3f' +\n 'b467f4124060d53f7a1939448f29ee3f7a1939448f29eebfb467f4124060d53f8c73cf145a04ef3f0238bd80' +\n '747bcf3f0238bd80747bcfbf8c73cf145a04ef3fb7b831ecf35de03fe992e786667feb3fe992e786667febbf' +\n 'b7b831ecf35de03fb2062ba4dfa4e93f1fa649ec2124e33f1fa649ec2124e3bfb2062ba4dfa4e93f0934fd4d' +\n '9964c23fdcfd0ccbfbaaef3fdcfd0ccbfbaaefbf0934fd4d9964c23f91177aac9ba3ef3fa71645f97b2bc33f' +\n 'a71645f97b2bc3bf91177aac9ba3ef3f1510444bc2fbe23fc275f010d1c2e93fc275f010d1c2e9bf1510444b' +\n 'c2fbe23f47bcfd148f65eb3f8cb032201189e03f8cb032201189e0bf47bcfd148f65eb3f48e32d466bb8ce3f' +\n '5f8f89bc9010ef3f5f8f89bc9010efbf48e32d466bb8ce3fd966dc2fa018ee3fb6b39d8be7bed53fb6b39d8b' +\n 'e7bed5bfd966dc2fa018ee3f7219b31d972fdb3f7b46cee830f8ec3f7b46cee830f8ecbf7219b31d972fdb3f' +\n 'd297bf07f7a4e73fdf23f7d50190e53fdf23f7d50190e5bfd297bf07f7a4e73f864687a5ba8da73f64911bbb' +\n '53f7ef3f64911bbb53f7efbf864687a5ba8da73f79a6e29ce0fcef3f1d3be54c4f459c3f1d3be54c4f459cbf' +\n '79a6e29ce0fcef3f106ae5bd7cfee53f4299078e553ee73f4299078e553ee7bf106ae5bd7cfee53fdcfbcb7b' +\n 'fc36ed3fc00ab543651dda3fc00ab543651ddabfdcfbcb7bfc36ed3fb60c8a6398d9d63f818d6d0f16e4ed3f' +\n '818d6d0f16e4edbfb60c8a6398d9d63ff0ae3a5a6833ef3fdd745d53906dcc3fdd745d53906dccbff0ae3a5a' +\n '6833ef3f57a9d0487209e13ff5a24c2a7416eb3ff5a24c2a7416ebbf57a9d0487209e13f5ea7c0d2261bea3f' +\n 'ba3c4def8b81e23fba3c4def8b81e2bf5ea7c0d2261bea3fdecb5486007fc53f784bcb37a78bef3f784bcb37' +\n 'a78befbfdecb5486007fc53f888d0a0f47bfef3f5bb86fade80ec03f5bb86fade80ec0bf888d0a0f47bfef3f' +\n '2930d6e3239ce33f6c4aace39049e93f6c4aace39049e9bf2930d6e3239ce33f27230dcb54cbeb3fded2245c' +\n '57b7df3fded2245c57b7dfbf27230dcb54cbeb3fce49174e5be1d03f5186076aebddee3f5186076aebddeebf' +\n 'ce49174e5be1d03fd36704559d5aee3ff03689dc1043d43ff03689dc1043d4bfd36704559d5aee3f895386c3' +\n '7f99dc3f49c4b9198fa0ec3f49c4b9198fa0ecbf895386c37f99dc3fff45f5139c2ae83f86a4cc25ccf9e43f' +\n '86a4cc25ccf9e4bfff45f5139c2ae83f4d44ed74960cb23f0f4130259debef3f0f4130259debefbf4d44ed74' +\n '960cb23f602d4885eae7ef3f99a2c5129f9db33f99a2c5129f9db3bf602d4885eae7ef3f7f9f586dbcd3e43f' +\n 'fa83af11714be83ffa83af11714be8bf7f9f586dbcd3e43f139c0287f589ec3f21cde1ae4bf3dc3f21cde1ae' +\n '4bf3dcbf139c0287f589ec3f71c26ee99be3d33fa7535dc5616aee3fa7535dc5616aeebf71c26ee99be3d33f' +\n '0990995e83d0ee3f7893c6ef3e42d13f7893c6ef3e42d1bf0990995e83d0ee3fa3cd56e6de5fdf3fc1541161' +\n '1be4eb3fc15411611be4ebbfa3cd56e6de5fdf3f15a8c51fa42ae93f18c58149c4c3e33f18c58149c4c3e3bf' +\n '15a8c51fa42ae93f3faae4fdb78ebe3ff69a7d3b6ec5ef3ff69a7d3b6ec5efbf3faae4fdb78ebe3f0cc6404a' +\n '0f83ef3f0d831d831a45c63f0d831d831a45c6bf0cc6404a0f83ef3f1071bb4c7358e23fc63b594a1838ea3f' +\n 'c63b594a1838eabf1071bb4c7358e23fb6579fd88ffbea3f4f25eecfe933e13f4f25eecfe933e1bfb6579fd8' +\n '8ffbea3fad5df13463a9cb3f65bc1bbc6b3eef3f65bc1bbc6b3eefbfad5df13463a9cb3f5a918af3fed1ed3f' +\n '921026c96337d73f921026c96337d7bf5a918af3fed1ed3ff2f90d447dc1d93f2475181b5b4bed3f2475181b' +\n '5b4bedbff2f90d447dc1d93fbf410e96ac1be73fff22ec4fe422e63fff22ec4fe422e6bfbf410e96ac1be73f' +\n '26b2fa214dfd953f77cb70681cfeef3f77cb70681cfeefbf26b2fa214dfd953fd13bc54309ffef3fcb97b96a' +\n '296a8f3fcb97b96a296a8fbfd13bc54309ffef3f5b537f431547e63f755bc999caf8e63f755bc999caf8e6bf' +\n '5b537f431547e63f7f8a8872715fed3f8f94abb75565d93f8f94abb75565d9bf7f8a8872715fed3faedf13e6' +\n 'f594d73f9a7595439ebfed3f9a7595439ebfedbfaedf13e6f594d73fb4abbc062249ef3fabb9f3d5f1e4ca3f' +\n 'abb9f3d5f1e4cabfb4abbc062249ef3fbce2dbe4365ee13fefec45f368e0ea3fefec45f368e0eabfbce2dbe4' +\n '365ee13f23f59010c954ea3fe2132c662d2fe23fe2132c662d2fe2bf23f59010c954ea3fffc4088dfd0ac73f' +\n '2a321a9c297aef3f2a321a9c297aefbfffc4088dfd0ac73f5443910347cbef3fc17d303b53ffbc3fc17d303b' +\n '53ffbcbf5443910347cbef3f8006beea33ebe33ffe5e5743790be93ffe5e5743790be9bf8006beea33ebe33f' +\n '47b1a1259dfceb3ffef7bf061908df3ffef7bf061908dfbf47b1a1259dfceb3f43f2e8fbf7a2d13fb2f61a4b' +\n 'cfc2ee3fb2f61a4bcfc2eebf43f2e8fbf7a2d13f5a16a529db79ee3fabb653e3f583d33fabb653e3f583d3bf' +\n '5a16a529db79ee3f9d60a82bd04cdd3fd7aa9e891573ec3fd7aa9e891573ecbf9d60a82bd04cdd3f95a19a1d' +\n '0a6ce83ff122675179ade43ff122675179ade4bf95a19a1d0a6ce83f0a4d4d4a772eb53f86d8e92be9e3ef3f' +\n '86d8e92be9e3efbf0a4d4d4a772eb53f9161820201efef3f6430464e617bb03f6430464e617bb0bf91618202' +\n '01efef3fa69ad91ca81fe53ffa526e758b09e83ffa526e758b09e8bfa69ad91ca81fe53f99da000ae2b6ec3f' +\n '293126476d3fdc3f293126476d3fdcbf99da000ae2b6ec3ff3821bd153a2d43f5ece81ff8d4aee3f5ece81ff' +\n '8d4aeebff3821bd153a2d43f44a5504c07ebee3f1e66eb054e80d03f1e66eb054e80d0bf44a5504c07ebee3f' +\n 'e1822bc84007e03f0dc4b6a049b2eb3f0dc4b6a049b2ebbfe1822bc84007e03fe17fbd423f68e93f8d7f811b' +\n '5374e33f8d7f811b5374e3bfe17fbd423f68e93f8667b2bc4dd6c03fb7ad668dd1b8ef3fb7ad668dd1b8efbf' +\n '8667b2bc4dd6c03f08ac854ff193ef3f88fa797fb1b8c43f88fa797fb1b8c4bf08ac854ff193ef3f58eb7ae8' +\n '76aae23fde4931f1f4fde93fde4931f1f4fde9bf58eb7ae876aae23ff37bf3a51531eb3fb6c44bb8d0dee03f' +\n 'b6c44bb8d0dee0bff37bf3a51531eb3feebd2c4d7731cd3fce0946fc1728ef3fce0946fc1728efbfeebd2c4d' +\n '7731cd3f9ca59b6ae3f5ed3fcb63ad9c947bd63fcb63ad9c947bd6bf9ca59b6ae3f5ed3f1bf3dbd30c79da3f' +\n 'e1a4e5c65522ed3fe1a4e5c65522edbf1bf3dbd30c79da3f6447302cc560e73f5c343ee7ded9e53f5c343ee7' +\n 'ded9e5bf6447302cc560e73f7fc142db8546a13faefd25e455fbef3faefd25e455fbefbf7fc142db8546a13f' +\n '14c008427cf9ef3f7961f86f396aa43f7961f86f396aa4bf14c008427cf9ef3f48744f260bb5e53f5bb3901b' +\n 'fb82e73f5bb3901bfb82e7bf48744f260bb5e53fb9d2592f670ded3f09dc5c1273d4da3f09dc5c1273d4dabf' +\n 'b9d2592f670ded3f02c2885c591dd63f540f28d96607ee3f540f28d96607eebf02c2885c591dd63f084728be' +\n '7a1cef3f9a09013f16f5cd3f9a09013f16f5cdbf084728be7a1cef3fec858f8705b4e03f2579de09744beb3f' +\n '2579de09744bebbfec858f8705b4e03f7224b4ed82e0e93fb89b4ed333d3e23fb89b4ed333d3e2bf7224b4ed' +\n '82e0e93f9348db572ff2c33f29defb7ced9bef3f29defb7ced9befbf9348db572ff2c33f4dd581c60db2ef3f' +\n 'e724be40899dc13fe724be40899dc1bf4dd581c60db2ef3fe14dc152524ce33f947545f1ae86e93f947545f1' +\n 'ae86e9bfe14dc152524ce33f5e15d91ffa98eb3f96bded55ae32e03f96bded55ae32e0bf5e15d91ffa98eb3f' +\n 'd2fdb906181fd03fc0a31ce5d6f7ee3fc0a31ce5d6f7eebfd2fdb906181fd03f85ce75ec333aee3f487019dc' +\n '6301d53f487019dc6301d5bf85ce75ec333aee3fd9c0ff1715e5db3fa0dec220eeccec3fa0dec220eeccecbf' +\n 'd9c0ff1715e5db3f8636b0873fe8e73ffc9d15f54f45e53ffc9d15f54f45e5bf8636b0873fe8e73fc98e80f9' +\n '06d4ad3fed31e11416f2ef3fed31e11416f2efbfc98e80f906d4ad3f0733f72299dfef3f29b1793e1bbfb63f' +\n '29b1793e1bbfb6bf0733f72299dfef3fff9160300387e43fa11b48e7668ce83fa11b48e7668ce8bfff916030' +\n '0387e43f5af8fe59ef5bec3fd910fa5c0ca6dd3fd910fa5c0ca6ddbf5af8fe59ef5bec3fafba38b61f24d33f' +\n '2560ad5b0989ee3f2560ad5b0989eebfafba38b61f24d33f11885b51cfb4ee3fbe27d7838503d23fbe27d783' +\n '8503d2bf11885b51cfb4ee3f2056f29506b0de3f575e46dcd914ec3f575e46dcd914ecbf2056f29506b0de3f' +\n '496c489b10ece83f8c103d667212e43f8c103d667212e4bf496c489b10ece83f4cf638eca66fbb3f8760d858' +\n 'd1d0ef3f8760d858d1d0efbf4cf638eca66fbb3fb77e4b43f670ef3f1ccbd2bba7d0c73f1ccbd2bba7d0c7bf' +\n 'b77e4b43f670ef3fd66075a1ba05e23ff5609dde3871ea3ff5609dde3871eabfd66075a1ba05e23fc8fa3ebd' +\n 'ffc4ea3fe5463a1f5988e13fe5463a1f5988e1bfc8fa3ebdffc4ea3fda31181b3e20ca3f072daf1f8b53ef3f' +\n '072daf1f8b53efbfda31181b3e20ca3fb98ae62cf4aced3fe44173d34df2d73fe44173d34df2d7bfb98ae62c' +\n 'f4aced3fd17bef81ef08d93fff0d8c503f73ed3fff0d8c503f73edbfd17bef81ef08d93fcdaf4aefafd5e63f' +\n '86b3523f0f6be63f86b3523f0f6be6bfcdaf4aefafd5e63f0397500e6bd9823f4f8c972ca7ffef3f4f8c972c' +\n 'a7ffefbf0397500e6bd9823f4f8c972ca7ffef3f0397500e6bd9823f0397500e6bd982bf4f8c972ca7ffef3f' +\n '86b3523f0f6be63fcdaf4aefafd5e63fcdaf4aefafd5e6bf86b3523f0f6be63fff0d8c503f73ed3fd17bef81' +\n 'ef08d93fd17bef81ef08d9bfff0d8c503f73ed3fe44173d34df2d73fb98ae62cf4aced3fb98ae62cf4acedbf' +\n 'e44173d34df2d73f072daf1f8b53ef3fda31181b3e20ca3fda31181b3e20cabf072daf1f8b53ef3fe5463a1f' +\n '5988e13fc8fa3ebdffc4ea3fc8fa3ebdffc4eabfe5463a1f5988e13ff5609dde3871ea3fd66075a1ba05e23f' +\n 'd66075a1ba05e2bff5609dde3871ea3f1ccbd2bba7d0c73fb77e4b43f670ef3fb77e4b43f670efbf1ccbd2bb' +\n 'a7d0c73f8760d858d1d0ef3f4cf638eca66fbb3f4cf638eca66fbbbf8760d858d1d0ef3f8c103d667212e43f' +\n '496c489b10ece83f496c489b10ece8bf8c103d667212e43f575e46dcd914ec3f2056f29506b0de3f2056f295' +\n '06b0debf575e46dcd914ec3fbe27d7838503d23f11885b51cfb4ee3f11885b51cfb4eebfbe27d7838503d23f' +\n '2560ad5b0989ee3fafba38b61f24d33fafba38b61f24d3bf2560ad5b0989ee3fd910fa5c0ca6dd3f5af8fe59' +\n 'ef5bec3f5af8fe59ef5becbfd910fa5c0ca6dd3fa11b48e7668ce83fff9160300387e43fff9160300387e4bf' +\n 'a11b48e7668ce83f29b1793e1bbfb63f0733f72299dfef3f0733f72299dfefbf29b1793e1bbfb63fed31e114' +\n '16f2ef3fc98e80f906d4ad3fc98e80f906d4adbfed31e11416f2ef3ffc9d15f54f45e53f8636b0873fe8e73f' +\n '8636b0873fe8e7bffc9d15f54f45e53fa0dec220eeccec3fd9c0ff1715e5db3fd9c0ff1715e5dbbfa0dec220' +\n 'eeccec3f487019dc6301d53f85ce75ec333aee3f85ce75ec333aeebf487019dc6301d53fc0a31ce5d6f7ee3f' +\n 'd2fdb906181fd03fd2fdb906181fd0bfc0a31ce5d6f7ee3f96bded55ae32e03f5e15d91ffa98eb3f5e15d91f' +\n 'fa98ebbf96bded55ae32e03f947545f1ae86e93fe14dc152524ce33fe14dc152524ce3bf947545f1ae86e93f' +\n 'e724be40899dc13f4dd581c60db2ef3f4dd581c60db2efbfe724be40899dc13f29defb7ced9bef3f9348db57' +\n '2ff2c33f9348db572ff2c3bf29defb7ced9bef3fb89b4ed333d3e23f7224b4ed82e0e93f7224b4ed82e0e9bf' +\n 'b89b4ed333d3e23f2579de09744beb3fec858f8705b4e03fec858f8705b4e0bf2579de09744beb3f9a09013f' +\n '16f5cd3f084728be7a1cef3f084728be7a1cefbf9a09013f16f5cd3f540f28d96607ee3f02c2885c591dd63f' +\n '02c2885c591dd6bf540f28d96607ee3f09dc5c1273d4da3fb9d2592f670ded3fb9d2592f670dedbf09dc5c12' +\n '73d4da3f5bb3901bfb82e73f48744f260bb5e53f48744f260bb5e5bf5bb3901bfb82e73f7961f86f396aa43f' +\n '14c008427cf9ef3f14c008427cf9efbf7961f86f396aa43faefd25e455fbef3f7fc142db8546a13f7fc142db' +\n '8546a1bfaefd25e455fbef3f5c343ee7ded9e53f6447302cc560e73f6447302cc560e7bf5c343ee7ded9e53f' +\n 'e1a4e5c65522ed3f1bf3dbd30c79da3f1bf3dbd30c79dabfe1a4e5c65522ed3fcb63ad9c947bd63f9ca59b6a' +\n 'e3f5ed3f9ca59b6ae3f5edbfcb63ad9c947bd63fce0946fc1728ef3feebd2c4d7731cd3feebd2c4d7731cdbf' +\n 'ce0946fc1728ef3fb6c44bb8d0dee03ff37bf3a51531eb3ff37bf3a51531ebbfb6c44bb8d0dee03fde4931f1' +\n 'f4fde93f58eb7ae876aae23f58eb7ae876aae2bfde4931f1f4fde93f88fa797fb1b8c43f08ac854ff193ef3f' +\n '08ac854ff193efbf88fa797fb1b8c43fb7ad668dd1b8ef3f8667b2bc4dd6c03f8667b2bc4dd6c0bfb7ad668d' +\n 'd1b8ef3f8d7f811b5374e33fe17fbd423f68e93fe17fbd423f68e9bf8d7f811b5374e33f0dc4b6a049b2eb3f' +\n 'e1822bc84007e03fe1822bc84007e0bf0dc4b6a049b2eb3f1e66eb054e80d03f44a5504c07ebee3f44a5504c' +\n '07ebeebf1e66eb054e80d03f5ece81ff8d4aee3ff3821bd153a2d43ff3821bd153a2d4bf5ece81ff8d4aee3f' +\n '293126476d3fdc3f99da000ae2b6ec3f99da000ae2b6ecbf293126476d3fdc3ffa526e758b09e83fa69ad91c' +\n 'a81fe53fa69ad91ca81fe5bffa526e758b09e83f6430464e617bb03f9161820201efef3f9161820201efefbf' +\n '6430464e617bb03f86d8e92be9e3ef3f0a4d4d4a772eb53f0a4d4d4a772eb5bf86d8e92be9e3ef3ff1226751' +\n '79ade43f95a19a1d0a6ce83f95a19a1d0a6ce8bff122675179ade43fd7aa9e891573ec3f9d60a82bd04cdd3f' +\n '9d60a82bd04cddbfd7aa9e891573ec3fabb653e3f583d33f5a16a529db79ee3f5a16a529db79eebfabb653e3' +\n 'f583d33fb2f61a4bcfc2ee3f43f2e8fbf7a2d13f43f2e8fbf7a2d1bfb2f61a4bcfc2ee3ffef7bf061908df3f' +\n '47b1a1259dfceb3f47b1a1259dfcebbffef7bf061908df3ffe5e5743790be93f8006beea33ebe33f8006beea' +\n '33ebe3bffe5e5743790be93fc17d303b53ffbc3f5443910347cbef3f5443910347cbefbfc17d303b53ffbc3f' +\n '2a321a9c297aef3fffc4088dfd0ac73fffc4088dfd0ac7bf2a321a9c297aef3fe2132c662d2fe23f23f59010' +\n 'c954ea3f23f59010c954eabfe2132c662d2fe23fefec45f368e0ea3fbce2dbe4365ee13fbce2dbe4365ee1bf' +\n 'efec45f368e0ea3fabb9f3d5f1e4ca3fb4abbc062249ef3fb4abbc062249efbfabb9f3d5f1e4ca3f9a759543' +\n '9ebfed3faedf13e6f594d73faedf13e6f594d7bf9a7595439ebfed3f8f94abb75565d93f7f8a8872715fed3f' +\n '7f8a8872715fedbf8f94abb75565d93f755bc999caf8e63f5b537f431547e63f5b537f431547e6bf755bc999' +\n 'caf8e63fcb97b96a296a8f3fd13bc54309ffef3fd13bc54309ffefbfcb97b96a296a8f3f77cb70681cfeef3f' +\n '26b2fa214dfd953f26b2fa214dfd95bf77cb70681cfeef3fff22ec4fe422e63fbf410e96ac1be73fbf410e96' +\n 'ac1be7bfff22ec4fe422e63f2475181b5b4bed3ff2f90d447dc1d93ff2f90d447dc1d9bf2475181b5b4bed3f' +\n '921026c96337d73f5a918af3fed1ed3f5a918af3fed1edbf921026c96337d73f65bc1bbc6b3eef3fad5df134' +\n '63a9cb3fad5df13463a9cbbf65bc1bbc6b3eef3f4f25eecfe933e13fb6579fd88ffbea3fb6579fd88ffbeabf' +\n '4f25eecfe933e13fc63b594a1838ea3f1071bb4c7358e23f1071bb4c7358e2bfc63b594a1838ea3f0d831d83' +\n '1a45c63f0cc6404a0f83ef3f0cc6404a0f83efbf0d831d831a45c63ff69a7d3b6ec5ef3f3faae4fdb78ebe3f' +\n '3faae4fdb78ebebff69a7d3b6ec5ef3f18c58149c4c3e33f15a8c51fa42ae93f15a8c51fa42ae9bf18c58149' +\n 'c4c3e33fc15411611be4eb3fa3cd56e6de5fdf3fa3cd56e6de5fdfbfc15411611be4eb3f7893c6ef3e42d13f' +\n '0990995e83d0ee3f0990995e83d0eebf7893c6ef3e42d13fa7535dc5616aee3f71c26ee99be3d33f71c26ee9' +\n '9be3d3bfa7535dc5616aee3f21cde1ae4bf3dc3f139c0287f589ec3f139c0287f589ecbf21cde1ae4bf3dc3f' +\n 'fa83af11714be83f7f9f586dbcd3e43f7f9f586dbcd3e4bffa83af11714be83f99a2c5129f9db33f602d4885' +\n 'eae7ef3f602d4885eae7efbf99a2c5129f9db33f0f4130259debef3f4d44ed74960cb23f4d44ed74960cb2bf' +\n '0f4130259debef3f86a4cc25ccf9e43fff45f5139c2ae83fff45f5139c2ae8bf86a4cc25ccf9e43f49c4b919' +\n '8fa0ec3f895386c37f99dc3f895386c37f99dcbf49c4b9198fa0ec3ff03689dc1043d43fd36704559d5aee3f' +\n 'd36704559d5aeebff03689dc1043d43f5186076aebddee3fce49174e5be1d03fce49174e5be1d0bf5186076a' +\n 'ebddee3fded2245c57b7df3f27230dcb54cbeb3f27230dcb54cbebbfded2245c57b7df3f6c4aace39049e93f' +\n '2930d6e3239ce33f2930d6e3239ce3bf6c4aace39049e93f5bb86fade80ec03f888d0a0f47bfef3f888d0a0f' +\n '47bfefbf5bb86fade80ec03f784bcb37a78bef3fdecb5486007fc53fdecb5486007fc5bf784bcb37a78bef3f' +\n 'ba3c4def8b81e23f5ea7c0d2261bea3f5ea7c0d2261beabfba3c4def8b81e23ff5a24c2a7416eb3f57a9d048' +\n '7209e13f57a9d0487209e1bff5a24c2a7416eb3fdd745d53906dcc3ff0ae3a5a6833ef3ff0ae3a5a6833efbf' +\n 'dd745d53906dcc3f818d6d0f16e4ed3fb60c8a6398d9d63fb60c8a6398d9d6bf818d6d0f16e4ed3fc00ab543' +\n '651dda3fdcfbcb7bfc36ed3fdcfbcb7bfc36edbfc00ab543651dda3f4299078e553ee73f106ae5bd7cfee53f' +\n '106ae5bd7cfee5bf4299078e553ee73f1d3be54c4f459c3f79a6e29ce0fcef3f79a6e29ce0fcefbf1d3be54c' +\n '4f459c3f64911bbb53f7ef3f864687a5ba8da73f864687a5ba8da7bf64911bbb53f7ef3fdf23f7d50190e53f' +\n 'd297bf07f7a4e73fd297bf07f7a4e7bfdf23f7d50190e53f7b46cee830f8ec3f7219b31d972fdb3f7219b31d' +\n '972fdbbf7b46cee830f8ec3fb6b39d8be7bed53fd966dc2fa018ee3fd966dc2fa018eebfb6b39d8be7bed53f' +\n '5f8f89bc9010ef3f48e32d466bb8ce3f48e32d466bb8cebf5f8f89bc9010ef3f8cb032201189e03f47bcfd14' +\n '8f65eb3f47bcfd148f65ebbf8cb032201189e03fc275f010d1c2e93f1510444bc2fbe23f1510444bc2fbe2bf' +\n 'c275f010d1c2e93fa71645f97b2bc33f91177aac9ba3ef3f91177aac9ba3efbfa71645f97b2bc33fdcfd0ccb' +\n 'fbaaef3f0934fd4d9964c23f0934fd4d9964c2bfdcfd0ccbfbaaef3f1fa649ec2124e33fb2062ba4dfa4e93f' +\n 'b2062ba4dfa4e9bf1fa649ec2124e33fe992e786667feb3fb7b831ecf35de03fb7b831ecf35de0bfe992e786' +\n '667feb3f0238bd80747bcf3f8c73cf145a04ef3f8c73cf145a04efbf0238bd80747bcf3f7a1939448f29ee3f' +\n 'b467f4124060d53fb467f4124060d5bf7a1939448f29ee3f9356fd14788adb3f60a09927b3e2ec3f60a09927' +\n 'b3e2ecbf9356fd14788adb3f33d3e29cb8c6e73f9f649751c36ae53f9f649751c36ae5bf33d3e29cb8c6e73f' +\n '17835fbd01b1aa3fd3beb154dcf4ef3fd3beb154dcf4efbf17835fbd01b1aa3f8c531475fadaef3fa130c112' +\n '874fb83fa130c112874fb8bf8c531475fadaef3fa2322b695a60e43f881dde1e87ace83f881dde1e87ace8bf' +\n 'a2322b695a60e43f04c041318344ec3fde41a966fffedd3fde41a966fffeddbf04c041318344ec3f2045954e' +\n '1ac4d23f306b0136ec97ee3f306b0136ec97eebf2045954e1ac4d23f0058e69383a6ee3fba545599e663d23f' +\n 'ba545599e663d2bf0058e69383a6ee3f25d83c6da857de3ff1e33149d12cec3ff1e33149d12cecbf25d83c6d' +\n 'a857de3f554618756acce83f80432a5b7f39e43f80432a5b7f39e4bf554618756acce83f5ca824ebb6dfb93f' +\n '9e5ca72d0dd6ef3f9e5ca72d0dd6efbf5ca824ebb6dfb93fee3c88567567ef3f0418c4271796c83f0418c427' +\n '1796c8bfee3c88567567ef3f7248dc641bdce13fd25a546e678dea3fd25a546e678deabf7248dc641bdce13f' +\n '8eb92c7a54a9ea3fbf73131750b2e13fbf73131750b2e1bf8eb92c7a54a9ea3ffa2ab6e9495bc93f5d6843ed' +\n 'a65def3f5d6843eda65defbffa2ab6e9495bc93f463d8bdd009aed3f3f90f3aa6a4fd83f3f90f3aa6a4fd8bf' +\n '463d8bdd009aed3f44edd5864bacd83f4fa44584c486ed3f4fa44584c486edbf44edd5864bacd83f9ce22fed' +\n '5cb2e63f719ca1ead18ee63f719ca1ead18ee6bf9ce22fed5cb2e63fbaa4ccbef821693f021d6221f6ffef3f' +\n '021d6221f6ffefbfbaa4ccbef821693f'\n )\n );\n\n // Sanity check (shake256 because used already): catch byte-level corruption, endianness/layout\n // mistakes, or accidental regeneration through engine-dependent sin/cos results.\n const rootBytes = u8f(baswap64If(Float64Array.from(roots)));\n if (\n bytesToHex(shake256(rootBytes)) !==\n 'f45a496cf56ccc6e3e3395a20209206d81d71a7905a661447bd5bc0e24e0af1e'\n ) {\n throw new Error('COMPLEX_ROOTS mismatch');\n }\n return roots;\n})();\n\n// Falcon's q-field Montgomery kernel: mul() operates on Montgomery residues and returns one.\n// inv() accepts a normal residue but returns its inverse in Montgomery form, so div(x, y) can stay\n// `mul(x, inv(y))`; callers like toMontgomery() manage the representation boundaries.\nconst intField = {\n mul(x: number, y: number) {\n let z = Math.imul(x, y);\n let w = Math.imul(Q, Math.imul(z, Q0I) & 0xffff);\n z = ((z + w) >>> 16) - Q;\n z += Q & (z >> 31);\n return z >>> 0;\n },\n inv(y: number): number {\n // y^(q-2) mod q\n if (y === 0) throw new Error('divison by zero');\n const e00 = this.mul(y, R2); // e0 = 1\n const e01 = this.mul(e00, e00); // 2 * e0 = 2\n const e02 = this.mul(e01, e00); // e1 + e0 = 3\n const e03 = this.mul(e02, e01); // e3 = e2 + e1 = 5\n const e04 = this.mul(e03, e03); // e4 = 2 * e3 = 10\n const e05 = this.mul(e04, e04); // e5 = 2 * e4 = 20\n const e06 = this.mul(e05, e05); // e6 = 2 * e5 = 40\n const e07 = this.mul(e06, e06); // e7 = 2 * e6 = 80\n const e08 = this.mul(e07, e07); // e8 = 2 * e7 = 160\n const e09 = this.mul(e08, e02); // e9 = e8 + e2 = 163\n const e10 = this.mul(e09, e08); // e10 = e9 + e8 = 323\n const e11 = this.mul(e10, e10); // e11 = 2 * e10 = 646\n const e12 = this.mul(e11, e11); // e12 = 2 * e11 = 1292\n const e13 = this.mul(e12, e09); // e13 = e12 + e9 = 1455\n const e14 = this.mul(e13, e13); // e14 = 2 * e13 = 2910\n const e15 = this.mul(e14, e14); // e15 = 2 * e14 = 5820\n const e16 = this.mul(e15, e10); // e16 = e15 + e10 = 6143\n const e17 = this.mul(e16, e16); // e17 = 2 * e16 = 12286\n const e18 = this.mul(e17, e00); // e18 = e17 + e0 = 12287\n return e18;\n },\n div: (x: number, y: number): number => intField.mul(x, intField.inv(y)),\n};\n\nfunction getIntPoly(logn: number) {\n const n = 1 << logn;\n const newPoly = (n: number) => new Uint16Array(n);\n const F = Number(invert(BigInt(n), QBig));\n const { mod, smod, NTT } = genCrystals({\n N: n,\n Q,\n F: F,\n ROOT_OF_UNITY: 7,\n newPoly,\n isKyber: false,\n brvBits: 10,\n });\n // Keep Falcon source compatible with older TS parsers: avoid spelling newer\n // `Uint16Array<ArrayBuffer>` syntax directly and cast the callee side at the boundary.\n const ntt = (r: TArg<IPoly>): TRet<IPoly> => (NTT.encode as any)(r);\n const intt = (r: TArg<IPoly>): TRet<IPoly> => (NTT.decode as any)(r);\n // Falcon integer helpers mutate their first argument in place; div() also performs intt()\n // before returning, so callers must treat these as owned-temporary transforms, not pure helpers.\n // Centered representatives are in [-6144, 6144] for odd q = 12289,\n // not a generic [-q/2, q/2] range.\n const signedCoder = {\n encode: (p: TArg<IPoly>) => Int16Array.from(p, (x) => smod(x)),\n decode: (p: TArg<SPoly | Int16Array>) => Uint16Array.from(p, (x) => mod(x)),\n };\n const intPoly = {\n create: newPoly,\n smallSqnorm(f: TArg<SPoly>) {\n let s = 0;\n let ng = 0;\n for (let u = 0; u < n; u++) {\n const z = f[u];\n s = (s + z * z) >>> 0;\n ng |= s;\n }\n return (s | -(ng >>> 31)) >>> 0;\n },\n isShort(s1: TArg<Int16Array>, s2: TArg<Int16Array>) {\n let s = 0 >>> 0;\n let ng = 0 >>> 0;\n for (let u = 0; u < n; u++) {\n let z1 = (s1[u] << 16) >> 16;\n s = (s + ((z1 * z1) >>> 0)) >>> 0;\n ng |= s;\n let z2 = (s2[u] << 16) >> 16;\n s = (s + ((z2 * z2) >>> 0)) >>> 0;\n ng |= s;\n }\n if (ng & 0x80000000) s = 0xffffffff;\n return s <= L2BOUND[logn];\n },\n sub(a: TArg<IPoly>, b: TArg<IPoly>): TRet<IPoly> {\n for (let i = 0; i < n; i++) a[i] = mod(a[i] - b[i]);\n return a as TRet<IPoly>;\n },\n ntt,\n intt,\n toMontgomery(d: TArg<IPoly>): TRet<IPoly> {\n for (let i = 0; i < n; i++) d[i] = intField.mul(d[i], R2);\n return d as TRet<IPoly>;\n },\n mul(f: TArg<IPoly>, d: TArg<IPoly>): TRet<IPoly> {\n for (let i = 0; i < n; i++) f[i] = intField.mul(f[i], d[i]);\n return f as TRet<IPoly>;\n },\n div(f: TArg<IPoly>, d: TArg<IPoly>): TRet<IPoly> {\n for (let i = 0; i < n; i++) f[i] = intField.div(f[i], d[i]);\n this.intt(f);\n return f as TRet<IPoly>;\n },\n };\n return { newPoly, intPoly, signedCoder };\n}\n\n// Falcon's JS binary64 complex field wrapper for FFT/sampler paths. Current uses are the\n// ordinary finite-number operations add/sub/neg/mul/conj/scale/magSqSum; the inherited wider API\n// exists because getComplex() exposes it, not because all methods are relied on by Falcon today.\nconst fComplex = getComplex({\n ZERO: 0,\n ONE: 1,\n add: (x: number, y: number) => x + y,\n sub: (x: number, y: number) => x - y,\n mul: (x: number, y: number) => x * y,\n div: (x: number, y: number) => x / y,\n eql: (x: number, y: number) => x === y,\n inv: (x: number) => 1 / x,\n neg: (x: number) => -x,\n} as any as IField<number>);\n\n// Detached object copy of the exact round-3 / PQClean fpr_gm_tab payload in its original order.\nconst COMPLEX_ROOTS_O = ComplexArrInterleaved.decode(COMPLEX_ROOTS);\n// Re-map roots into the local forward FFTCore schedule\n// `{ dit: false, invertButterflies: true, brp: false }`.\n// Index 0 stays intentionally unused because FFTCore's forward group counter starts at 1.\nconst FFTCoreRoots: Record<number, ComplexElm<number>[]> = {};\n// Inverse FFTCore reads roots as `N - grp`, so fill this table from the end and store `-conj(root)`\n// rather than plain conjugates\n// to match Falcon's split/iFFT sign convention under the local butterfly.\nconst FFTCoreRootsConj: Record<number, ComplexElm<number>[]> = {};\nfor (let logn = 0; logn < 10; logn++) {\n const out = new Array(1 << logn);\n const outC = new Array(1 << logn);\n for (let i = 0, g1 = 1, g2 = 1; i < logn; i++) {\n const ng = 1 << i;\n for (let k = 0; k < ng; k++) out[g1++] = COMPLEX_ROOTS_O[(ng << 1) + k];\n const ng2 = 1 << (logn - i);\n for (let k = 0; k < ng2 >> 1; k++)\n outC[out.length - g2++] = fComplex.neg(fComplex.conj(COMPLEX_ROOTS_O[ng2 + k]));\n }\n FFTCoreRoots[logn] = out;\n FFTCoreRootsConj[logn] = outC;\n}\n\ntype CPoly = ComplexElm<number>[];\n// Mixed float-poly helper surface: most methods allocate / return fresh values,\n// but FFT() and iFFT() mutate their CPoly input in place.\n// Flat Float64Array buffers use ComplexArr's [...re, ...im] layout.\nfunction getFloatPoly(logn: number) {\n const n = 1 << logn;\n const N_COMPLEX = n >> 1;\n const hn = Math.log2(N_COMPLEX);\n const fftOpts = { N: N_COMPLEX, invertButterflies: true, skipStages: 0, brp: false };\n const inv = 1.0 / N_COMPLEX;\n return {\n to: (f: TArg<FPoly>) => ComplexArr.decode(Array.from(f)),\n from: (f: CPoly): TRet<FPoly> => new Float64Array(ComplexArr.encode(f)) as TRet<FPoly>,\n // Runtime callers also pass HashToPoint's Uint16Array output here;\n // the implementation only needs a numeric typed-array shape,\n // even though the local type is narrower.\n convSmall: (f: TArg<SPoly>): CPoly => ComplexArr.decode(Array.from(f)),\n add: (a: CPoly, b: CPoly): CPoly => a.map((i, j) => fComplex.add(i, b[j])),\n sub: (a: CPoly, b: CPoly): CPoly => a.map((i, j) => fComplex.sub(i, b[j])),\n neg: (a: CPoly): CPoly => a.map((i) => fComplex.neg(i)),\n mul: (a: CPoly, b: CPoly): CPoly => a.map((i, j) => fComplex.mul(i, b[j])),\n conj: (a: CPoly): CPoly => a.map((i) => fComplex.conj(i)),\n mulConst: (a: CPoly, x: number): CPoly => a.map((i) => fComplex.scale(i, x)),\n scaleNorm: (a: CPoly, b: TArg<FPoly>): CPoly => a.map((i, j) => fComplex.scale(i, b[j])),\n invNorm: (a: CPoly, b: CPoly) =>\n new Float64Array(a.map((i, j) => 1.0 / fComplex.magSqSum(i, b[j]))),\n FFT: (f: CPoly): CPoly =>\n FFTCore(fComplex, { ...fftOpts, dit: false, roots: FFTCoreRoots[hn] })(f),\n iFFT(f: CPoly): CPoly {\n FFTCore(fComplex, { ...fftOpts, dit: true, roots: FFTCoreRootsConj[hn] })(f);\n for (let i = 0; i < f.length; i++) f[i] = fComplex.scale(f[i], inv);\n return f;\n },\n };\n}\n\nfunction ldlFFT(logn: number, g00t: CPoly, g01t: CPoly, g11t: CPoly) {\n // Algorithm 8: LDL*(G)\n // (Page 37)\n // Require: A full-rank self-adjoint matrix G = (Gᵢⱼ) ∈ FFT(Q[x]/(φ))²ˣ²\n // Ensure: The LDL* decomposition G = LDL* over FFT(Q[x]/(φ))\n // Format: All polynomials are in FFT representation.\n // 1: D₀₀ ← G₀₀\n // 2: L₁₀ ← G₁₀/G₀₀\n // 3: D₁₁ ← G₁₁ - L₁₀ ⊙ L₁₀* ⊙ G₀₀\n // 4: L ← [ 1 0 ; L₁₀ 1 ], D ← [ D₀₀ 0 ; 0 D₁₁ ]\n // 5: return (L, D)\n\n // Algorithm 9: ffLDL*(G)\n // (Page 37)\n // Require: A full-rank Gram matrix G ∈ FFT(Q[x]/(xⁿ + 1))²ˣ²\n // Ensure: A binary tree T\n // Format: All polynomials are in FFT representation.\n // 1: (L, D) ← LDL*(G) ▷ L = [ 1 0 ; L₁₀ 1 ], D = [ D₀₀ 0 ; 0 D₁₁ ]\n // 2: T.value ← L₁₀\n // 3: if (n = 2) then\n // 4: T.leftchild ← D₀₀\n // 5: T.rightchild ← D₁₁\n // 6: return T\n // 7: else\n // 8: d₀₀, d₀₁ ← splitfft(D₀₀) ▷ dᵢⱼ ∈ FFT(Q[x]/(x^{n/2} + 1))\n // 9: d₁₀, d₁₁ ← splitfft(D₁₁)\n // 10: G₀ ← [ d₀₀ d₀₁ ; d₀₁* d₀₀ ], G₁ ← [ d₁₀ d₁₁ ; d₁₁* d₁₀ ]\n // ▷ Since D₀₀, D₁₁ are self-adjoint, (3.30) applies\n // 11: T.leftchild ← ffLDL*(G₀) ▷ Recursive calls\n // 12: T.rightchild ← ffLDL*(G₁)\n // 13: return T\n\n // Recursive calls may alias g00t and g11t, and the top-level arrays persist across signing\n // retries. LDL replaces array entries, so shallow copies keep both kinds of caller state intact.\n g00t = g00t.slice();\n g01t = g01t.slice();\n g11t = g11t.slice();\n const hn = 1 << (logn - 1);\n for (let i = 0; i < hn; i++) {\n const g01 = g01t[i];\n const g11 = g11t[i];\n const mu = fComplex.scale(g01, 1.0 / g00t[i].re);\n g11t[i] = { re: g11.re - (mu.re * g01.re + mu.im * g01.im), im: g11.im };\n g01t[i] = fComplex.conj(mu);\n }\n return { g00: g00t, g01: g01t, g11: g11t };\n}\n\nfunction ApproxExp(x: number, ccs: number): number {\n // Algorithm 13: ApproxExp(x, ccs), (Page 42)\n // Require: Floating-point values x ∈ [0, ln(2)] and ccs ∈ [0, 1]\n // Ensure: A floating approximation of ccs · exp(-x); berExp() applies the later 2^63 scaling.\n // 1: C = [0x00000004741183A3, ...]\n // 2: y ← C[0] ▷ y and z remain in {0, ..., 2⁶³ - 1} the whole algorithm.\n // 3: z ← ⌊2⁶³ · x⌋\n // 4: for i = 1, ..., 12 do\n // 5: y ← C[i] - (z · y) >> 63 ▷ (z · y) fits in 126 bits, but we only need the top 63 bits\n // 6: z ← ⌊2⁶³ · ccs⌋\n // 7: y ← (z · y) >> 63\n // 8: return y\n // FACCT / round-3 Falcon's leading 1.0 coefficient is implicit in `return ccs * (1.0 + z * y)`,\n // so the decimal list below stores the remaining 12 polynomial coefficients only.\n const ev = [\n 0.99999999999999489297408672428, 0.500000000000019206858326015208,\n 0.166666666666984014666397229121, 0.041666666666110491190622155955,\n 0.008333333327800835146903501993, 0.001388888894063186997887560103,\n 0.000198412739277311890541063977, 0.000024801566833585381209939524,\n 0.000002755586350219122514855659, 0.000000275607356160477811864927,\n 0.000000025299506379442070029551, 0.000000002073772366009083061987,\n ];\n const y = -x;\n let z = ev[ev.length - 1];\n for (let i = ev.length - 2; i >= 0; i--) z = z * y + ev[i];\n return ccs * (1.0 + z * y);\n}\n\n// Actual api\ntype FalconOpts = {\n N: number;\n // Table 3.3 total padded detached bytes. In padded mode it drives `.lengths.signature` and the\n // payload width `sigLen - 1 - NONCELEN`.\n sigLen: number;\n padded: boolean;\n fgBits: number;\n FGBits: number;\n // Compressed-s payload bytes only, excluding the detached header byte and 40-byte nonce.\n paddedLen: number;\n // Maximum compressed-s payload emitted by sign(). Unpadded detached verification enforces the\n // same Round-3 ceiling before decoding.\n maxS2Len: number;\n};\n\ntype FalconRandom = (bytesLength?: number) => TRet<Uint8Array>;\ntype FalconSigOpts = SigOpts & { random?: FalconRandom };\n/** Falcon attached-signature API. */\nexport type FalconAttached = CryptoKeys & {\n /** Key lengths plus the 48-byte sampler-seed hook for signing. */\n lengths: CryptoKeys['lengths'] & { signRand?: number };\n /**\n * Signs a message and appends it to the returned attached signature.\n * @param msg Message bytes to sign.\n * @param secretKey Falcon secret key bytes.\n * @param opts Optional Falcon signing options.\n * @returns Attached signature containing both the message and signature.\n */\n seal(msg: Uint8Array, secretKey: Uint8Array, opts?: FalconSigOpts): Uint8Array;\n /**\n * Verifies an attached signature and returns the embedded message.\n * @param sig Attached Falcon signature bytes.\n * @param publicKey Falcon public key bytes.\n * @param opts Optional verification options.\n * @returns Fresh message bytes that do not alias either input when the signature is valid.\n */\n open(sig: Uint8Array, publicKey: Uint8Array, opts?: VerOpts): Uint8Array;\n};\n/** PATCH: options of `internal.sign` (tests only). */\nexport type FalconInternalSignOpts = {\n /** Sampler-seed source (48 bytes). Default: crypto.getRandomValues. */\n random?: (bytesLength?: number) => Uint8Array;\n /** Maximum sampling attempts before throwing. Default: 1000. */\n maxIterations?: number;\n};\n/** PATCH: signing / verification of an externally computed hash point (like ml-dsa `internal`). */\nexport type FalconInternal = {\n /** Signs a hash point (N coefficients mod q); returns the raw signed s2 polynomial. */\n sign(hashPoint: Uint16Array, secretKey: Uint8Array, opts?: FalconInternalSignOpts): Int16Array;\n /** Checks that s2 is a valid signature of the hash point for the public key. */\n verify(s2: Int16Array, hashPoint: Uint16Array, publicKey: Uint8Array): boolean;\n};\n/** Falcon detached-signature API with an attached-signature helper. */\nexport type Falcon = Signer & {\n /** Attached-signature helper for the same Falcon parameter set. */\n attached: FalconAttached;\n /** PATCH: external hash-point API. */\n internal: FalconInternal;\n};\n\nfunction genFalcon(opts: FalconOpts): TRet<Falcon> {\n const { N } = opts;\n const logn = Math.log2(N);\n const id = <T>(n: T): T => n;\n const { newPoly, intPoly, signedCoder } = getIntPoly(logn);\n const floatPoly = getFloatPoly(logn);\n // Kinda like FFT Sampler: single function, but a lot of private deps and internal rng stake\n class NTRU {\n private logn: number;\n private shake: ReturnType<typeof shake256.create>;\n constructor(logn: number, seed: Uint8Array) {\n this.logn = logn;\n this.shake = shake256.create().update(seed);\n }\n private gaussSingle() {\n const g = 1 << (10 - this.logn);\n let val = 0;\n for (let i = 0; i < g; i++) {\n const r128 = bytesToNumberLE(this.shake.xof(16));\n const r1 = r128 & MASK_63n;\n const r2 = (r128 >> _64n) & MASK_63n;\n const sign = Number((r128 >> _63n) & _1n);\n let f = r1 < gauss_1024_12289[0] ? 1 : 0;\n let v = 0;\n for (let k = 1; k < gauss_1024_12289.length; k++) {\n const tBit = r2 >= gauss_1024_12289[k] ? 1 : 0;\n v |= k & -(tBit & (f ^ 1));\n f |= tBit;\n }\n val += sign === 1 ? -v : v;\n }\n return val;\n }\n private polyGauss(): SPoly {\n const n = 1 << this.logn;\n let mod2 = 0; // xor sum of previous elements\n const f = new Int8Array(n);\n for (let u = 0; u < n; u++) {\n let s;\n while (true) {\n s = this.gaussSingle();\n if (s < -127 || s > 127) continue;\n if (u === n - 1) if ((mod2 ^ (s & 1)) === 0) continue;\n break;\n }\n if (u < n - 1) mod2 ^= s & 1;\n f[u] = s;\n }\n return f;\n }\n private galoisNorm(logn: number, a: BPoly): BPoly {\n const n = 1 << logn;\n const d = new Array(n >> 1);\n for (let k = 0; k < n; k += 2) {\n let s: bigint = _0n;\n for (let i = 0; i <= k; i += 2) s += a[i] * a[k - i];\n for (let i = k + 2; i < n; i += 2) s -= a[i] * a[k + n - i];\n d[k >>> 1] = s;\n }\n for (let k = 0; k < n; k += 2) {\n let s: bigint = _0n;\n for (let i = 1; i < k; i += 2) s += a[i] * a[k - i];\n for (let i = k + 1; i < n; i += 2) s -= a[i] * a[k + n - i];\n d[k >>> 1] -= s;\n }\n return d;\n }\n private mulConjD(logn: number, d: BPoly, a: BPoly, b: BPoly): BPoly {\n const n = 1 << logn;\n for (let k = 0; k < n; k++) {\n let s: bigint = _0n;\n for (let i = 0; i <= k; i += 2) s += b[i >>> 1] * a[k - i];\n for (let i = k + 2 - (k & 1); i < n; i += 2) s -= b[i >>> 1] * a[k + n - i];\n if ((k & 1) === 0) d[k] = s;\n else d[k] = -s;\n }\n return d;\n }\n private subMul(logn: number, a: BPoly, b: BPoly, c: BPoly, e: bigint): BPoly {\n const n = 1 << logn;\n for (let k = 0; k < n; k++) {\n let s: bigint = _0n;\n for (let i = 0; i <= k; i++) s += b[i] * c[k - i];\n for (let i = k + 1; i < n; i++) s -= b[i] * c[k + n - i];\n a[k] -= s << e;\n }\n return a;\n }\n private reduce(logn: number, f: BPoly, g: BPoly, F: BPoly, G: BPoly, logn_top: number) {\n // Algorithm 7: Reduce(f, g, F, G)\n // (Page 35)\n // Require: Polynomials f, g, F, G ∈ Z[x]/(φ)\n // Ensure: (F, G) is reduced with respect to (f, g)\n // 1: do\n // 2: k ← ⌊(Ff*+Gg*)/(ff*+gg*)⌋ ▷ (Ff*+Gg*)/(ff*+gg*) ∈ Q[x]/(φ) and k ∈ Z[x]/(φ)\n // 3: F ← F - kf\n // 4: G ← G - kg\n // 5: while k ≠ 0\n // ▷ Multiple iterations may be needed, e.g. if k is computed in small precision.\n const n = 1 << logn;\n const depth = logn_top - logn;\n const floatPoly = getFloatPoly(logn);\n const slen = MAX_BL_SMALL[depth];\n const llen = MAX_BL_LARGE[depth];\n let maxFGBits = BigInt(31 * llen);\n let FGlen = BigInt(llen);\n const scalefg = BigInt(31 * (slen - 10));\n const fgMaxBits = BITLENGTH[depth].avg + 6 * BITLENGTH[depth].std;\n const fgMinBits = BITLENGTH[depth].avg - 6 * BITLENGTH[depth].std;\n let scaleK = BigInt(Math.round(31 * llen - fgMinBits));\n let fx = new Float64Array(n);\n let gx = new Float64Array(n);\n for (let i = 0; i < n; i++) {\n fx[i] = Number(f[i] >> scalefg);\n gx[i] = Number(g[i] >> scalefg);\n }\n const rt3 = floatPoly.conj(floatPoly.FFT(floatPoly.to(fx)));\n const rt4 = floatPoly.conj(floatPoly.FFT(floatPoly.to(gx)));\n const rt5 = floatPoly.invNorm(rt3, rt4);\n\n const Fx = new Float64Array(n);\n const Gx = new Float64Array(n);\n const k = new Array(n);\n while (true) {\n let scaleFG = _31n * (FGlen - _10n);\n for (let i = 0; i < n; i++) {\n Fx[i] = Number(F[i] >> scaleFG);\n Gx[i] = Number(G[i] >> scaleFG);\n }\n const rt2 = floatPoly.mul(floatPoly.FFT(floatPoly.to(Gx)), rt4);\n const rt1 = floatPoly.mul(floatPoly.FFT(floatPoly.to(Fx)), rt3);\n // convert to float64array\n const rt2f = floatPoly.from(\n floatPoly.iFFT(floatPoly.scaleNorm(floatPoly.add(rt2, rt1), rt5))\n );\n const pdc = 2 ** Number(scaleFG - scalefg - scaleK);\n for (let i = 0; i < n; i++) {\n const BOUND = 2147483647.0;\n const val = rt2f[i] * pdc;\n if (val <= -BOUND || val >= BOUND) return false;\n k[i] = BigInt(Math.round(val));\n }\n F = this.subMul(logn, F, f, k, scaleK); // 3: F ← F - kf\n G = this.subMul(logn, G, g, k, scaleK); // 4: G ← G - kg\n const maxfgNew = scaleK + BigInt(Math.round(fgMaxBits)) + _10n;\n if (maxfgNew < maxFGBits) maxFGBits = maxfgNew;\n if (FGlen > _1n && FGlen * _31n >= maxFGBits + _31n) FGlen--;\n if (scaleK <= _0n) break;\n scaleK -= _25n;\n if (scaleK < _0n) scaleK = _0n;\n }\n return true;\n }\n // This is recursive thing that goes from logn to 0\n private solveBranch(logn: number, f: BPoly, g: BPoly, F: BPoly, G: BPoly, logn_top?: number) {\n // Algorithm 6: NTRUSolve_{n,q}(f, g), (Page 35)\n // Require: f, g ∈ Z[x]/(xⁿ + 1) with n a power of two\n // Ensure: Polynomials F, G such that (3.15) is verified\n // 1: if n = 1 then\n // 2: Compute u, v ∈ Z such that uf - vg = gcd(f, g) ▷ Using the extended GCD\n // 3: if gcd(f, g) ≠ 1 then\n // 4: abort and return ⊥\n // 5: (F, G) ← (vq, uq)\n // 6: return (F, G)\n // 7: else\n // 8: f' ← N(f) ▷ f', g', F', G' ∈ Z[x]/(x^{n/2} + 1)\n // 9: g' ← N(g) ▷ N as defined in either (3.25) or (3.26)\n // 10: (F', G') ← NTRUSolve_{n/2,q}(f', g') ▷ Recursive call\n // 11: F ← F'(x²)g(-x) ▷ F, G ∈ Z[x]/(xⁿ + 1)\n // 12: G ← G'(x²)f(-x)\n // 13: Reduce(f, g, F, G) ▷ (F, G) is reduced with respect to (f, g)\n // 14: return (F, G)\n if (logn === 0) {\n // // 1: if n = 1 then\n const xf = f[0];\n const xg = g[0];\n // We can rely on 'invert' to throw if they are not coprime.\n if (xf <= _0n || xg <= _0n) return false;\n try {\n const u1 = invert(xf, xg); // if gcd(f, g) ≠ 1 then\n const v1 = (_1n - u1 * xf) / xg;\n F[0] = -v1 * QBig; // 5: (F, G) ← (vq, uq)\n G[0] = u1 * QBig;\n return true;\n } catch (e) {\n return false;\n }\n }\n if (logn_top === undefined) logn_top = logn;\n const n = 1 << logn;\n const hn = n >>> 1;\n if (!f || f.length < n || !g || g.length < n) return false;\n const fp = this.galoisNorm(logn, f); // 8: f' ← N(f)\n const gp = this.galoisNorm(logn, g); // 9: g' ← N(g)\n const Fp = new Array(hn); // 10: (F', G') ← NTRUSolve_{n/2,q}(f', g')\n const Gp = new Array(hn);\n // 10: (F', G') ← NTRUSolve_{n/2,q}(f', g')\n // ▷ Recursive call\n if (!this.solveBranch(logn - 1, fp, gp, Fp, Gp, logn_top)) return false;\n F = this.mulConjD(logn, F, g, Fp); // 11: F ← F'(x²)g(-x)\n G = this.mulConjD(logn, G, f, Gp); // 12: G ← G'(x²)f(-x)\n // 13: Reduce(f, g, F, G)\n // ▷ (F, G) is reduced with respect to (f, g)\n return this.reduce(logn, f, g, F, G, logn_top);\n }\n private solve(f: SPoly, g: SPoly) {\n // Algorithm 5: NTRUGen(φ, q)\n // (Page 34)\n // Require: A monic polynomial φ ∈ Z[x] of degree n, a modulus q\n // Ensure: Polynomials f, g, F, G\n // 1: σ{f,g} ← 1.17√q/2n ▷ σ{f,g} is chosen so that E[||(f, g)||] = 1.17√q\n // 2: for i from 0 to n-1 do\n // 3: fᵢ ← DZ,σ{f,g},0 ▷ See also (3.29)\n // 4: gᵢ ← DZ,σ{f,g},0\n // 5: f ← Σᵢ fᵢxⁱ ▷ f ∈ Z[x]/(φ)\n // 6: g ← Σᵢ gᵢxⁱ ▷ g ∈ Z[x]/(φ)\n // 7: if NTT(f) contains 0 as a coefficient then ▷ Check that f is invertible mod q\n // 8: restart\n // 9: γ ← max{||(g, -f)||, ||( (qf*)/(ff*+gg*), (qg*)/(ff*+gg*) )||}\n // ▷ Using (3.9) with (3.8) or (3.10)\n // 10: if γ > 1.17√q then ▷ Check that γ = ||B||_GS is short\n // 11: restart\n // 12: F, G ← NTRUSolve_{n,q}(f, g) ▷ Computing F, G such that fG - gF = q mod φ\n // 13: if (F, G) = ⊥ then\n // 14: restart\n // 15: return f, g, F, G\n const n = 1 << logn;\n const bf = Array.from(f).map(BigInt);\n const bg = Array.from(g).map(BigInt);\n const bF = new Array(n);\n const bG = new Array(n);\n // 12: F, G ← NTRUSolve_{n,q}(f, g)\n // ▷ Computing F, G such that fG - gF = q mod φ\n if (!this.solveBranch(logn, bf, bg, bF, bG)) return false;\n const F = new Int8Array(n);\n const G = new Int8Array(n);\n for (let i = 0; i < n; i++) {\n const x = bF[i];\n const y = bG[i];\n if (x < -127 || x > +127 || y < -127 || y > +127) return false;\n F[i] = Number(x);\n G[i] = Number(y);\n }\n return [F, G];\n }\n generate(): [SPoly, SPoly, SPoly, SPoly, IPoly] {\n // Algorithm 4: Keygen(φ, q)\n // (Page 33)\n // Require: A monic polynomial φ ∈ Z[x], a modulus q\n // Ensure: A secret key sk, a public key pk\n // 1: f, g, F, G ← NTRUGen(φ, q) ▷ Solving the NTRU equation\n // 2: B ← [ g -f ; G -F ]\n // 3: B̂ ← FFT(B) ▷ Compute the FFT for each of the 4 components {g, -f, G, -F}\n // 4: G ← B̂ × B̂*\n // 5: T ← ffLDL*(G) ▷ Computing the LDL* tree\n // 6: for each leaf leaf of T do\n // 7: leaf.value ← σ/√leaf.value ▷ Normalization step\n // 8: sk ← (B̂, T)\n // 9: h ← gf⁻¹ mod q\n // 10: pk ← h\n // 11: return sk, pk\n let max = 1_000_000;\n let curr = 0;\n while (true) {\n if (curr++ === max) throw new Error(\"can't generate key\");\n const f = this.polyGauss();\n const g = this.polyGauss();\n let lim = 1 << (opts.fgBits - 1);\n for (let u = 0; u < N; u++) {\n if (f[u] >= lim || f[u] <= -lim || g[u] >= lim || g[u] <= -lim) {\n lim = -1;\n break;\n }\n }\n if (lim < 0) continue;\n const normf = intPoly.smallSqnorm(f);\n const normg = intPoly.smallSqnorm(g);\n const norm = (normf + normg) | -((normf | normg) >>> 31);\n // Cheap integer prefilter for the same 1.17^2*q Gram-Schmidt bound;\n // ceil(BNORM_MAX) = 16823.\n if (norm >= 16823) continue;\n let rt1 = floatPoly.FFT(floatPoly.convSmall(f));\n let rt2 = floatPoly.FFT(floatPoly.convSmall(g));\n const rt3 = floatPoly.invNorm(rt1, rt2);\n rt1 = floatPoly.iFFT(floatPoly.scaleNorm(floatPoly.mulConst(floatPoly.conj(rt1), Q), rt3));\n rt2 = floatPoly.iFFT(floatPoly.scaleNorm(floatPoly.mulConst(floatPoly.conj(rt2), Q), rt3));\n // Separate reals and then imaginary to enforce numerical stability\n let bnorm = 0;\n for (let u = 0; u < rt1.length; u++) {\n bnorm += rt1[u].re * rt1[u].re;\n bnorm += rt2[u].re * rt2[u].re;\n }\n for (let u = 0; u < rt1.length; u++) {\n bnorm += rt1[u].im * rt1[u].im;\n bnorm += rt2[u].im * rt2[u].im;\n }\n if (!(bnorm < BNORM_MAX)) continue;\n let pub;\n try {\n pub = computePublic(f, g);\n } catch (_) {\n continue;\n }\n const solved = this.solve(f, g);\n if (solved === false) continue;\n return [f, g, solved[0], solved[1], pub]; // f g F G h\n }\n }\n }\n // same as ml-dsa id, but MSB bits :(\n const modqCoder = () => {\n const coder = bitsCoderMSB(newPoly, N, 14, {\n encode: id,\n decode: id,\n }) as BytesCoderLen<IPoly>;\n return {\n bytesLen: coder.bytesLen,\n encode(poly: TArg<Uint16Array>) {\n // Keep these raw checks in sync with Q:\n // Falcon public-key coefficients must stay in [0, q - 1].\n for (let i = 0; i < poly.length; i++)\n if (poly[i] >= 12289) throw new Error('public key coeff out of range');\n return coder.encode(poly);\n },\n decode(bytes: TArg<Uint8Array>) {\n // Round-3 Falcon requires exact body length here;\n // otherwise truncated keys decode as zero-padded\n // and overlong keys silently ignore the tail in this generic bit decoder.\n if (bytes.length !== coder.bytesLen) throw new Error('wrong public key length');\n const poly = coder.decode(bytes);\n // Keep these raw checks in sync with Q:\n // Falcon public-key coefficients must stay in [0, q - 1].\n for (let i = 0; i < poly.length; i++)\n if (poly[i] >= 12289) throw new Error('public key coeff out of range');\n const normalized = coder.encode(poly);\n if (normalized.length !== bytes.length) throw new Error('wrong public key length');\n for (let i = 0; i < bytes.length; i++)\n if (bytes[i] !== normalized[i]) throw new Error('wrong public key encoding');\n return poly;\n },\n };\n };\n const trimI8Coder = (bits: number) => {\n const shift = 32 - bits;\n const coder = bitsCoderMSB((len) => new Int8Array(len), N, bits, {\n encode: (v) => v & ((1 << bits) - 1),\n decode: (w) => ((w & getMask(bits)) << shift) >> shift,\n }) as BytesCoderLen<SPoly>;\n return {\n bytesLen: coder.bytesLen,\n encode(poly: TArg<Int8Array>) {\n // Secret-key trim encodings keep a symmetric signed range and reserve the most-negative\n // value as a non-canonical sentinel,\n // so encode() and decode() intentionally use different bounds.\n const max = (1 << (bits - 1)) - 1;\n const min = -max;\n for (let i = 0; i < poly.length; i++)\n if (poly[i] < min || poly[i] > max) throw new Error('private key coeff out of range');\n return coder.encode(poly);\n },\n decode(bytes: TArg<Uint8Array>) {\n const poly = coder.decode(bytes);\n const min = -(1 << (bits - 1));\n for (let i = 0; i < poly.length; i++)\n if (poly[i] === min) throw new Error('forbidden private key coeff');\n return poly;\n },\n };\n };\n const fgCoder = trimI8Coder(opts.fgBits);\n const FGCoder = trimI8Coder(opts.FGBits);\n // Current utils.splitCoder requires a label first;\n // without it Falcon key/sig encodings drift and KATs fail.\n // 0x50 + logn || f || g || F\n const secretKeyCoder = headerCoder(\n 0x50 + logn,\n splitCoder('falcon.secretKey', fgCoder, fgCoder, FGCoder)\n ) as BytesCoderLen<[Int8Array, Int8Array, Int8Array]>;\n const publicKeyCoder = headerCoder(0x00 + logn, modqCoder()) as BytesCoderLen<Uint16Array>;\n const decodePaddedSig = (s2: TArg<Uint8Array>) => {\n // The fixed padded form accepts only a canonical compressed payload\n // followed by an all-zero tail.\n const normalized = compCoder(N).encode(compCoder(N).decode(s2));\n for (let i = normalized.length; i < s2.length; i++)\n if (s2[i] !== 0) throw new Error('non-zero padding');\n return normalized;\n };\n const decodeUnpaddedSig = (s2: TArg<Uint8Array>) => {\n // Unpadded attached and detached signatures require the compressed payload to use its exact\n // canonical bitlength. Appending a zero tail and adjusting the outer container length must\n // still be rejected.\n const normalized = compCoder(N).encode(compCoder(N).decode(s2));\n if (normalized.length !== s2.length) throw new Error('wrong signature length');\n return s2;\n };\n const decodeSig = opts.padded ? decodePaddedSig : decodeUnpaddedSig;\n // Unpadded: [ 2B sig_len ] [ 40B nonce ] [ message ] [ 1B header ] [ compressed_sig ]\n // Padded [ 1B header ] [ 40B nonce ] [ compressed_sig ] [ padding ] | [ message ]\n const SignatureCoderBasic = (logn: number) => {\n const TYPE_BYTE = 0x20 + logn;\n return {\n encode({ msg, nonce, s2 }: TArg<SignatureRaw>): TRet<Uint8Array> {\n let compressed: Uint8Array = s2;\n const payloadLen = 1 + compressed.length;\n const totalLen = 2 + NONCELEN + msg.length + payloadLen;\n const out = new Uint8Array(totalLen);\n let i = 0;\n out[i++] = (payloadLen >> 8) & 0xff;\n out[i++] = payloadLen & 0xff;\n out.set(nonce, i);\n i += NONCELEN;\n out.set(msg, i);\n i += msg.length;\n out[i++] = TYPE_BYTE;\n out.set(compressed, i);\n return out as TRet<Uint8Array>;\n },\n decode(data: TArg<Uint8Array>): TRet<SignatureRaw> {\n if (!data || data.length < NONCELEN + 3) throw new Error('signature coder: wrong length');\n const len = (data[0] << 8) | data[1];\n const s2Len = len - 1;\n const msgLen = data.length - NONCELEN - 3 - s2Len;\n if (msgLen < 0) throw new Error('signature coder: wrong msg length');\n const typeByte = data[2 + NONCELEN + msgLen];\n if (typeByte !== TYPE_BYTE) throw new Error('signature coder: wrong type byte');\n const nonce = data.subarray(2, 2 + NONCELEN);\n const msg = data.subarray(2 + NONCELEN, 2 + NONCELEN + msgLen);\n const s2 = decodeUnpaddedSig(data.subarray(2 + NONCELEN + msgLen + 1));\n if (s2.length !== s2Len) throw new Error('signature coder: wrong s2 length');\n return { msg, nonce, s2 } as TRet<SignatureRaw>;\n },\n };\n };\n const SignatureCoderPadded = (logn: number) => {\n const sigLen = opts.paddedLen;\n return {\n encode({ msg, nonce, s2 }: TArg<SignatureRaw>): TRet<Uint8Array> {\n return headerCoder(\n 0x30 + logn,\n splitCoder('falcon.signature', NONCELEN, sigLen, msg.length)\n ).encode([nonce, pad(sigLen).encode(s2), msg]);\n },\n decode(data: TArg<Uint8Array>): TRet<SignatureRaw> {\n // Keep API misuse on the coder's TypeError path before reading the container length.\n abytes(data, undefined, 'signature');\n // The compressed-signature field is fixed-width here; only the message is variable. A\n // container shorter than the fixed part would make the s2 field borrow bytes from nowhere\n // and let a truncated encoding open to the same message.\n const msgLen = data.length - NONCELEN - sigLen - 1;\n if (msgLen < 0) throw new Error('signature coder: wrong length');\n const [nonce, s2, msg] = headerCoder(\n 0x30 + logn,\n splitCoder('falcon.signature', NONCELEN, sigLen, msgLen)\n ).decode(data);\n return { nonce, s2: decodeSig(s2), msg } as TRet<SignatureRaw>;\n },\n };\n };\n // [ 1B header ] [ 40B nonce ] [ compressed_sig ]\n const SignatureCoderDetached = (logn: number) => {\n const paddedSigLen = opts.sigLen - 1 - NONCELEN;\n const getSigLen = (s2: TArg<Uint8Array>) => (opts.padded ? paddedSigLen : s2.length);\n return {\n encode({ nonce, s2 }: TArg<{ nonce: Uint8Array; s2: Uint8Array }>): TRet<Uint8Array> {\n return headerCoder(\n 0x30 + logn,\n splitCoder('falcon.detachedSignature', NONCELEN, getSigLen(s2))\n ).encode([nonce, opts.padded ? pad(paddedSigLen).encode(s2) : s2]);\n },\n decode(data: TArg<Uint8Array>): TRet<{\n nonce: Uint8Array;\n s2: Uint8Array;\n }> {\n // Unpadded Round-3 signatures have parameter-set maxima (header + nonce + s2):\n // 752 bytes for Falcon-512 and 1462 for Falcon-1024. Reject before creating views or\n // entering the bit decoder so attacker-sized inputs cannot cause proportional work.\n if (!opts.padded && data.length > 1 + NONCELEN + opts.maxS2Len)\n throw new Error('detached signature too long');\n // Padded detached signatures are fixed-length (`lengths.signature`), so the payload width\n // must come from the parameter set, not from the input: deriving it would accept appended\n // zero bytes and truncated padding as extra valid encodings of the same signature.\n // Unpadded signatures are variable-length; decodeUnpaddedSig() enforces the exact canonical\n // bitlength of whatever remains.\n const payloadLen = opts.padded ? paddedSigLen : data.length - NONCELEN - 1;\n const [nonce, raw] = headerCoder(\n 0x30 + logn,\n splitCoder('falcon.detachedSignature', NONCELEN, payloadLen)\n ).decode(data);\n const s2 = decodeSig(raw);\n return { nonce, s2 } as TRet<{ nonce: Uint8Array; s2: Uint8Array }>;\n },\n };\n };\n const SignatureCoder = (opts.padded ? SignatureCoderPadded : SignatureCoderBasic)(logn);\n // Round-3 Falcon rejects non-invertible f before division;\n // otherwise malformed secret keys leak a raw arithmetic error.\n // Returns NTT(f) after the nonzero-lane check;\n // callers still apply f^{-1} via coefficient-wise division.\n const invertF = (f: TArg<SPoly>) => {\n const tt = intPoly.ntt(signedCoder.decode(f));\n for (let u = 0; u < N; u++)\n if (tt[u] === 0) throw new Error('invalid secretKey: non-invertible f');\n return tt;\n };\n function computePublic(f: TArg<SPoly>, g: TArg<SPoly>) {\n const tt = invertF(f);\n const h = intPoly.ntt(signedCoder.decode(g));\n // intPoly.div() returns to coefficient form via intt(), so public keys are encoded from the\n // canonical polynomial h = g/f and verifyRaw() re-enters the NTT domain later.\n const res = intPoly.div(h, tt); // h = g/f\n cleanBytes(tt);\n return res;\n }\n // Reconstruct the omitted secret-key limb G as g*F/f mod q, then mirror round-3 Falcon's centered\n // reduction and small-coefficient check before using the completed basis for signing.\n function completePrivate(f: TArg<SPoly>, g: TArg<SPoly>, F: TArg<SPoly>) {\n let t1 = intPoly.toMontgomery(intPoly.ntt(signedCoder.decode(g)));\n const t2 = intPoly.ntt(signedCoder.decode(F));\n const tt = invertF(f);\n t1 = intPoly.div(intPoly.mul(t1, t2), tt);\n const G = new Int8Array(N);\n for (let u = 0; u < N; u++) {\n let w = t1[u];\n // This mirrors round-3 Falcon's secret-key G reconstruction, not a generic centered reduction\n // helper:\n // the threshold is floor(q/2), and w = Qhalf maps to -Qhalf - 1 here on purpose.\n w -= Q & ~-((w - Qhalf) >>> 31);\n const gi = w | 0;\n if (gi < -127 || gi > 127) {\n cleanBytes(t1, t2, tt, G);\n throw new Error('Coefficient out of bounds');\n }\n G[u] = gi;\n }\n cleanBytes(t1, t2, tt);\n return G;\n }\n function HashToPoint(nonce: TArg<Uint8Array>, msg: TArg<Uint8Array>): TRet<IPoly> {\n // Algorithm 3: HashToPoint(str, q, n)\n // (Page 31)\n // Require: A string str, a modulus q ≤ 2¹⁶, a degree n ∈ N*\n // Ensure: An polynomial c = Σᵢ cᵢxⁱ in Zq[x]\n // 1: k ← ⌈2¹⁶/q⌉\n // 2: ctx ← SHAKE-256-Init()\n // 3: SHAKE-256-Inject(ctx, str)\n // 4: i ← 0\n // 5: while i < n do\n // 6: t ← SHAKE-256-Extract(ctx, 16)\n // 7: if t < kq then\n // 8: cᵢ ← t mod q\n // 9: i ← i + 1\n // 10: return c\n const h = shake256.create().update(nonce).update(msg); // 3: SHAKE-256-Inject(ctx, str)\n const c = new Uint16Array(N);\n // Round-3 Falcon keeps 16-bit draws only in 0..61444, i.e. below 61445 = 5*q, the largest\n // 16-bit multiple of q below 2^16; a literal ceil(2^16/q)*q would accept every sample.\n const kQ = 5 * Q;\n for (let i = 0; i < N;) {\n const tmp = h.xof(2); // 6: t ← SHAKE-256-Extract(ctx, 16)\n let w = (tmp[0] << 8) | tmp[1];\n if (w < kQ) c[i++] = w % Q; // 8: cᵢ ← t mod q\n }\n return c as TRet<IPoly>;\n }\n // This is basically one sampling routine,\n // but it carries a lot of internal state and gets complex quickly.\n class FFSampler {\n private logn: number;\n // Shake\n private shake: ReturnType<typeof shake256.create>;\n private shakeBuf: Uint8Array;\n private ctrView: DataView;\n // ChaCha\n private ctr: bigint = _0n;\n private buf: Uint8Array;\n private buf32: Uint32Array;\n private pos: number;\n private key: Uint8Array;\n private nonce32: Uint32Array;\n private curBlock: Uint8Array;\n private curBlock32: Uint32Array;\n private view: DataView;\n // Sampler\n private b01: CPoly;\n private b11: CPoly;\n private g00: CPoly;\n private g01: CPoly;\n private g11: CPoly;\n\n constructor(logn: number, seed: Uint8Array, b00: CPoly, b01: CPoly, b10: CPoly, b11: CPoly) {\n this.logn = logn;\n // Shake\n this.shake = shake256.create().update(seed);\n this.shakeBuf = new Uint8Array(56);\n this.key = this.shakeBuf.subarray(0, 32);\n this.nonce32 = u32(this.shakeBuf.subarray(32, 48)); // 4 u32s\n this.ctrView = createView(this.shakeBuf.subarray(48, 56));\n // Signle chacha20 instance buffer\n this.curBlock = new Uint8Array(64);\n this.curBlock32 = u32(this.curBlock);\n // whole rng buffer\n this.buf = new Uint8Array(8 * this.curBlock.length);\n this.buf32 = u32(this.buf);\n this.pos = this.buf.length; // not filled yet!\n this.view = createView(this.buf);\n // Sampler\n this.b01 = b01;\n this.b11 = b11;\n const { g00, g01, g11 } = this.gramFFT(b00, b10);\n this.g00 = g00;\n this.g01 = g01;\n this.g11 = g11;\n }\n destroy() {\n this.shake.destroy();\n cleanBytes(this.shakeBuf, this.curBlock, this.buf);\n cleanCPoly(this.b01, this.b11, this.g00, this.g01, this.g11);\n }\n private refill(minBytes: number): void {\n if (this.buf.length - this.pos >= minBytes) return;\n const out32 = swap32IfBE(this.buf32);\n for (let i = 0; i < 8; i++, this.ctr++) {\n const n = swap32IfBE(this.nonce32.slice()); // [n0, n1, n2, n3]\n n[2] ^= Number(this.ctr & MASK_32n);\n n[3] ^= Number(this.ctr >> _32n);\n // chacha20() takes raw nonce bytes; on BE the word-normalized temp must be swapped back.\n swap32IfBE(n.subarray(1));\n chacha20(this.key, u8(n.subarray(1)), EMPTY_CHACHA20_BLOCK, this.curBlock, n[0]);\n // Interleave like Falcon's AVX2 layout (by u32 chunks from 8 parallel chacha20)\n const block32 = swap32IfBE(this.curBlock32);\n for (let j = 0; j < 16; j++) out32[i + j * 8] = block32[j];\n swap32IfBE(block32);\n }\n swap32IfBE(out32);\n this.pos = 0;\n }\n // Sampler\n private gaussian0(): number {\n // Algorithm 12: BaseSampler()\n // (Page 41)\n // Require: -\n // Ensure: An integer z₀ ∈ {0, ..., 18} such that z ~ χ ▷ χ is uniquely defined by (3.33)\n // 1: u ← UniformBits(72) ▷ See (3.32)\n // 2: z₀ ← 0\n // 3: for i = 0, ..., 17 do\n // 4: z₀ ← z₀ + [u < RCDT[i]] ▷ Note that one should use RCDT, not pdt or cdt\n // 5: return z₀\n this.refill(9);\n const t0 = this.view.getUint32(this.pos, true);\n const t1 = this.view.getUint32(this.pos + 4, true);\n const t2 = this.buf[this.pos + 8];\n this.pos += 9;\n const v0 = t0 & 0xffffff;\n const v1 = ((t0 >>> 24) & 0xff) | ((t1 & 0xffff) << 8);\n const v2 = ((t1 >>> 16) & 0xffff) | (t2 << 16);\n let z = 0;\n for (let i = 0; i < GAUSS0.length; i += 3) {\n let cc = (v0 - GAUSS0[i + 2]) >>> 31;\n cc = (((v1 - GAUSS0[i + 1]) | 0) - cc) >>> 31;\n cc = (((v2 - GAUSS0[i + 0]) | 0) - cc) >>> 31;\n z += cc;\n }\n return z;\n }\n private berExp(x: number, ccs: any) {\n // Algorithm 14: BerExp(x, ccs) (Page 43)\n // Require: Floating point values x, ccs ≥ 0\n // Ensure: A single bit, equal to 1 with probability ≈ ccs · exp(-x)\n // 1: s ← ⌊x/ln(2)⌋\n // ▷ Compute the unique decomposition x = s · ln(2) + r,\n // with (r, s) ∈ [0, ln 2) × Z⁺\n // 2: r ← x - s · ln(2)\n // 3: s ← min(s, 63)\n // 4: z ← (2 · ApproxExp(r, ccs) - 1) >> s ▷ z ≈ 2⁶⁴⁻ˢ · ccs · exp(-r) = 2⁶⁴ · ccs · exp(-x)\n // 5: i ← 64\n // 6: do\n // 7: i ← i - 8\n // 8: w ← UniformBits(8) - ((z >> i) & 0xFF)\n // ▷ This loop does not need to be done in constant-time\n // 9: while ((w = 0) and (i > 0))\n // 10: return [w < 0] ▷ Return 1 with probability 2⁻⁶⁴ · z ≈ ccs · exp(-x)\n let s = Math.trunc(x * 1.4426950408889633870046509401);\n const r = x - s * 0.69314718055994530941723212146;\n let e = ApproxExp(r, ccs);\n e *= 2147483648.0;\n let z1 = e | 0;\n e = (e - z1) * 4294967296.0;\n let z0 = e | 0;\n z1 = (z1 << 1) | (z0 >>> 31);\n z0 <<= 1;\n s = (s | ((63 - s) >>> 26)) & 63;\n const sm = -(s >>> 5) | 0;\n z0 ^= sm & (z0 ^ z1);\n z1 &= ~sm;\n s &= 31;\n z0 = (z0 >>> s) | ((z1 << (31 - s)) << 1);\n z1 >>>= s;\n for (let j = 0; j < 2; j++) {\n for (let i = 24; i >= 0; i -= 8) {\n this.refill(1);\n const w = this.buf[this.pos++];\n const bz = (z1 >>> i) & 0xff;\n if (w !== bz) return w < bz;\n }\n z1 = z0;\n }\n return false;\n }\n private samplerZ(mu: number, isigma: number) {\n // Algorithm 15: SamplerZ(μ, σ'), (Page 43)\n // Require: Floating-point values μ, σ' ∈ R such that σ' ∈ [σ_{min}, σ_{max}]\n // Ensure: An integer z ∈ Z sampled from a distribution very close to DZ,μ,σ'\n // 1: r ← μ - ⌊μ⌋ ▷ r must be in [0, 1)\n // 2: ccs ← σ_{min}/σ' ▷ ccs helps to make the algorithm running time independent of σ'\n // 3: while (1) do\n // 4: z₀ ← BaseSampler()\n // 5: b ← UniformBits(8) & 0x1\n // 6: z ← b + (2 · b - 1)z₀\n // 7: x ← ((z-r)²)/(2σ'²)\n // 8: if (BerExp(x, ccs) = 1) then\n // 9: return z + ⌊μ⌋\n const s = Math.floor(mu);\n const r = mu - s;\n const dss = isigma * isigma * 0.5;\n const ccs = isigma * SIGMA_MIN[this.logn];\n for (;;) {\n const z0 = this.gaussian0();\n this.refill(1);\n const b = this.buf[this.pos++] & 1;\n const z = (((z0 << 1) + 1) & -b) - z0;\n let x = z - r;\n x = x * x * dss - z0 * z0 * 0.1508650488753727203494747755;\n if (this.berExp(x, ccs)) return s + z;\n }\n }\n private splitFFT(logn: number, f: CPoly) {\n // Algorithm 1: splitfft(FFT(f))\n // (Page 29)\n // Require: FFT(f) = (f(ζ))ζ for some f ∈ Q[x]/(φ)\n // Ensure: FFT(f₀) = (f₀(ζ'))ζ' and FFT(f₁) = (f₁(ζ'))ζ' for some f₀, f₁ ∈ Q[x]/(φ')\n // Format: All polynomials are in FFT representation.\n // 1: for ζ such that φ(ζ) = 0 and Im(ζ) > 0 do ▷ See eq. (3.19) with 0 ≤ k < n/2\n // 2: ζ' ← ζ²\n // 3: f₀(ζ') ← ½ [f(ζ) + f(−ζ)]\n // 4: f₁(ζ') ← (1/(2ζ)) [f(ζ) − f(−ζ)]\n // 5: return (FFT(f₀), FFT(f₁))\n const hn = 1 << (logn - 1);\n const qn = hn >> 1;\n if (logn === 1) return { f0: [{ re: f[0].re, im: 0.0 }], f1: [{ re: f[0].im, im: 0.0 }] };\n const f0t = new Array(qn);\n const f1t = new Array(qn);\n const ft = f;\n for (let i = 0; i < qn; i++) {\n const a = ft[(i << 1) + 0];\n const b = ft[(i << 1) + 1];\n f0t[i] = fComplex.scale(fComplex.add(a, b), 0.5);\n f1t[i] = fComplex.scale(\n fComplex.mul(fComplex.sub(a, b), fComplex.conj(COMPLEX_ROOTS_O[i + hn])),\n 0.5\n );\n }\n return { f0: f0t, f1: f1t };\n }\n private splitSelfAdjFFT(logn: number, f: CPoly) {\n const hn = 1 << (logn - 1);\n const qn = hn >> 1;\n if (logn === 1) return { f0: [{ re: f[0].re, im: 0.0 }], f1: [{ re: 0.0, im: 0.0 }] };\n const f0t = new Array(qn);\n const f1t = new Array(qn);\n const ft = f;\n for (let i = 0; i < qn; i++) {\n const a = ft[(i << 1) + 0];\n const b = ft[(i << 1) + 1];\n f0t[i] = fComplex.scale(fComplex.add(a, b), 0.5);\n f1t[i] = fComplex.scale(\n fComplex.scale(fComplex.conj(COMPLEX_ROOTS_O[i + hn]), fComplex.sub(a, b).re),\n 0.5\n );\n }\n return { f0: f0t, f1: f1t };\n }\n private mergeFFT(logn: number, f0: CPoly, f1: CPoly): CPoly {\n // Algorithm 2: mergefft(f₀, f₁)\n // (Page 29)\n // Require: FFT(f₀) = (f₀(ζ'))ζ' and FFT(f₁) = (f₁(ζ'))ζ' for some f₀, f₁ ∈ Q[x]/(φ')\n // Ensure: FFT(f) = (f(ζ))ζ for some f ∈ Q[x]/(φ)\n // Format: All polynomials are in FFT representation.\n // 1: for ζ such that φ(ζ) = 0 do ▷ See eq. (3.19)\n // 2: ζ' ← ζ²\n // 3: f(ζ) ← f₀(ζ') + ζf₁(ζ')\n // 4: return FFT(f)\n const hn = 1 << (logn - 1);\n const qn = hn >> 1;\n if (logn === 1) return [{ re: f0[0].re, im: f1[0].re }];\n const ft = new Array(2 * qn);\n for (let i = 0; i < qn; i++) {\n const a = f0[i];\n const c = fComplex.mul(f1[i], COMPLEX_ROOTS_O[i + hn]);\n ft[(i << 1) + 0] = fComplex.add(a, c);\n ft[(i << 1) + 1] = fComplex.sub(a, c);\n }\n return ft;\n }\n private gramFFT(b00: CPoly, b10: CPoly) {\n const { b01, b11 } = this;\n const hn = (1 << this.logn) >> 1;\n const g00: CPoly = new Array(hn);\n const g01: CPoly = new Array(hn);\n const g11: CPoly = new Array(hn);\n for (let i = 0; i < hn; i++) {\n const b00t = b00[i];\n const b01t = b01[i];\n const b10t = b10[i];\n const b11t = b11[i];\n const u = fComplex.mul(b00t, fComplex.conj(b10t));\n const v = fComplex.mul(b01t, fComplex.conj(b11t));\n g00[i] = { re: fComplex.magSqSum(b00t, b01t), im: 0.0 };\n g01[i] = fComplex.add(u, v);\n g11[i] = { re: fComplex.magSqSum(b10t, b11t), im: 0.0 };\n }\n return { g00, g01, g11 };\n }\n private ffsampRec(\n logn: number,\n t0: CPoly,\n t1: CPoly,\n g00i: CPoly,\n g01i: CPoly,\n g11i: CPoly\n ): { t0: CPoly; t1: CPoly } {\n // Algorithm 11: ffSamplingₙ(t, T)\n // (Page 40)\n // Require: t = (t₀, t₁) ∈ FFT(Q[x]/(xⁿ + 1))², a FALCON tree T\n // Ensure: z = (z₀, z₁) ∈ FFT(Z[x]/(xⁿ + 1))²\n // Format: All polynomials are in FFT representation.\n // 1: if n = 1 then\n // 2: σ' ← T.value ▷ It is always the case that σ' ∈ [σ_{min}, σ_{max}]\n // 3: z₀ ← SamplerZ(t₀, σ') ▷ Since n=1, tᵢ = invFFT(tᵢ) ∈ Q and zᵢ = invFFT(zᵢ) ∈ Z\n // 4: z₁ ← SamplerZ(t₁, σ')\n // 5: return z = (z₀, z₁)\n // 6: (l, T₀, T₁) ← (T.value, T.leftchild, T.rightchild)\n // 7: t'₁ ← splitfft(t₁) ▷ t₀, t'₁ ∈ FFT(Q[x]/(x^{n/2} + 1))²\n // 8: z'₁ ← ffSampling_{n/2}(t'₁, T₁) ▷ First recursive call to ffSampling_{n/2}\n // 9: z₁ ← mergefft(z'₁) ▷ z₀, z₁ ∈ FFT(Z[x]/(x^{n/2} + 1))²\n // 10: t'₀ ← t₀ + (t₁ - z₁) ⊙ l\n // 11: t''₀ ← splitfft(t'₀)\n // 12: z'₀ ← ffSampling_{n/2}(t''₀, T₀) ▷ Second recursive call to ffSampling_{n/2}\n // 13: z₀ ← mergefft(z'₀)\n // 14: return z = (z₀, z₁)\n if (logn === 0) {\n // The dynamic sampler stores 1/σ' instead of σ'. Keygen guarantees this interval,\n // but an imported compact key may reconstruct an invalid basis. Check the actual LDL*\n // leaf before it can drive SamplerZ; the negated comparison also rejects NaN/infinity.\n const leaf = Math.sqrt(g00i[0].re) * INV_SIGMA[this.logn];\n const sigmaPrime = 1 / leaf;\n if (!(sigmaPrime >= SIGMA_MIN[this.logn] && sigmaPrime <= SIGMA_MAX))\n throw new Error('invalid secretKey: sampler sigma out of range');\n // 3: z₀ ← SamplerZ(t₀, σ')\n // ▷ Since n=1, tᵢ = invFFT(tᵢ) ∈ Q and zᵢ = invFFT(zᵢ) ∈ Z\n const t0re = this.samplerZ(t0[0].re, leaf);\n const t1re = this.samplerZ(t1[0].re, leaf); // 4: z₁ ← SamplerZ(t₁, σ')\n return { t0: [{ re: t0re, im: 0.0 }], t1: [{ re: t1re, im: 0.0 }] };\n }\n // 6: (l, T₀, T₁) ← (T.value, T.leftchild, T.rightchild)\n const { g00, g01, g11 } = ldlFFT(logn, g00i, g01i, g11i);\n const { f0: g00f0, f1: g00f1 } = this.splitSelfAdjFFT(logn, g00);\n const { f0: g11f0, f1: g11f1 } = this.splitSelfAdjFFT(logn, g11);\n // 7: t'₁ ← splitfft(t₁)\n // ▷ t₀, t'₁ ∈ FFT(Q[x]/(x^{n/2} + 1))²\n const { f0: t1f0in, f1: t1f1in } = this.splitFFT(logn, t1);\n const { t0: t1f0out, t1: t1f1out } = this.ffsampRec(\n logn - 1,\n t1f0in,\n t1f1in,\n g11f0,\n g11f1,\n g11f0\n ); // 8: z'₁ ← ffSampling_{n/2}(t'₁, T₁) ▷ First recursive call to ffSampling_{n/2}\n // 9: z₁ ← mergefft(z'₁)\n // ▷ z₀, z₁ ∈ FFT(Z[x]/(x^{n/2} + 1))²\n const t1new = this.mergeFFT(logn, t1f0out, t1f1out);\n // 10: t'₀ ← t₀ + (t₁ - z₁) ⊙ l\n const t0tmp = floatPoly.add(t0, floatPoly.mul(g01, floatPoly.sub(t1, t1new)));\n const { f0: t0f0in, f1: t0f1in } = this.splitFFT(logn, t0tmp); // 11: t''₀ ← splitfft(t'₀)\n const { t0: t0f0out, t1: t0f1out } = this.ffsampRec(\n logn - 1,\n t0f0in,\n t0f1in,\n g00f0,\n g00f1,\n g00f0\n ); // 12: z'₀ ← ffSampling_{n/2}(t''₀, T₀) ▷ Second recursive call to ffSampling_{n/2}\n const z1 = this.mergeFFT(logn, t0f0out, t0f1out); // 13: z₀ ← mergefft(z'₀)\n return { t0: z1, t1: t1new };\n }\n // sampling a preimage in FFT domain\n sample(hm: Uint16Array) {\n const t0t = floatPoly.FFT(floatPoly.convSmall(hm as any));\n const t0f = floatPoly.mulConst(floatPoly.mul(t0t, this.b11), F_INV_Q);\n const t1f = floatPoly.mulConst(floatPoly.mul(t0t, this.b01), F_MINUS_INV_Q);\n // Set seed\n this.shake.xofInto(this.shakeBuf);\n this.ctr = this.ctrView.getBigUint64(0, true);\n // Actual sampling\n return this.ffsampRec(this.logn, t0f, t1f, this.g00, this.g01, this.g11);\n }\n }\n\n const signRaw = (\n sk: TArg<Uint8Array>,\n msg: TArg<Uint8Array>,\n maxLen: number,\n rnd: TArg<FalconRandom> = randomBytes\n ): TRet<SignatureRaw> => {\n // Algorithm 10: Sign(m, sk, [β²]), (Page 39)\n // Require: A message m, a secret key sk, a bound [β²]\n // Ensure: A signature sig of m\n // 1: r ← {0, 1}³²⁰ uniformly\n // 2: c ← HashToPoint(r||m, q, n)\n // 3: t ← ( (1/q)FFT(c) ⊙ FFT(F), (1/q)FFT(c) ⊙ FFT(f) ) ▷ t = (FFT(c), FFT(0)) · B̂⁻¹\n // 4: do\n // 5: do\n // 6: z ← ffSamplingₙ(t, T)\n // 7: s = (t - z)B̂\n // ▷ At this point, s follows a Gaussian distribution:\n // s ~ D_{(c,0)+Λ(B),σ,0}\n // 8: while ||s||² > [β²]\n // ▷ Since s is in FFT representation, one may use (3.8) to compute ||s||²\n // 9: (s₁, s₂) ← invFFT(s) ▷ s₁ + s₂h = c mod (φ, q)\n // 10: s ← Compress(s₂, 8 · sbytelen - 328)\n // ▷ Remove 1 byte for the header, and 40 bytes for r\n // 11: while (s = ⊥)\n // 12: return sig = (r, s)\n abytes(msg, undefined, 'msg');\n abytes(sk, secretKeyCoder.bytesLen, 'secretKey');\n // One RNG stream drives both the public 40-byte nonce and the 48-byte sampler seed, so\n // deterministic rnd hooks make signatures deterministic for fixed secretKey/message inputs.\n const nonce = rnd(40);\n // Keep these raw 40-byte checks in sync with NONCELEN: Falcon's r <- {0,1}^320 nonce\n // feeds HashToPoint(r || m) and the public signature framing, so callback bugs must fail fast.\n abytes(nonce, 40, 'nonce');\n const hm = HashToPoint(nonce, msg); // 2: c ← HashToPoint(r||m, q, n)\n const seed = rnd(48);\n // Falcon implementations here use a fixed 48-byte sampler seed; reject callback bugs up front.\n abytes(seed, 48, 'seed');\n try {\n const [f, g, F] = secretKeyCoder.decode(sk);\n try {\n const G = completePrivate(f, g, F);\n const b00 = floatPoly.FFT(floatPoly.convSmall(g));\n const b01 = floatPoly.FFT(floatPoly.neg(floatPoly.convSmall(f)));\n const b10 = floatPoly.FFT(floatPoly.convSmall(G));\n const b11 = floatPoly.FFT(floatPoly.neg(floatPoly.convSmall(F)));\n const sampler = new FFSampler(logn, seed, b00, b01, b10, b11);\n const s2 = new Int16Array(N);\n try {\n while (true) {\n const { t0, t1 } = sampler.sample(hm);\n // t2 = b00*t0 + b10*t1\n const t2 = floatPoly.add(floatPoly.mul(t0, b00), floatPoly.mul(t1, b10));\n const t3 = floatPoly.mul(t0, b01); // t3 = b01*t0\n const t4 = floatPoly.iFFT(t2); // t4 = iFFT(tx)\n // t5 = iFFT(b11*t1 + ty)\n const t5 = floatPoly.iFFT(floatPoly.add(floatPoly.mul(t1, b11), t3));\n // Traverse imaginary in exact same order to avoid numerical instability\n const hn = N >> 1;\n let sqn = 0;\n for (let i = 0; i < hn; i++) {\n sqn += (hm[i] - (Math.round(t4[i].re) | 0)) ** 2;\n sqn += (hm[hn + i] - (Math.round(t4[i].im) | 0)) ** 2;\n const z = -Math.round(t5[i].re);\n sqn += z * z;\n s2[i] = z & 0xffff;\n const z2 = -Math.round(t5[i].im);\n sqn += z2 * z2;\n s2[i + hn] = z2 & 0xffff;\n }\n cleanCPoly(t0, t1, t2, t3, t4, t5);\n if (!(sqn <= L2BOUND[logn])) continue;\n // 10: s ← Compress(s₂, 8 · sbytelen - 328)\n // ▷ Remove 1 byte for the header, and 40 bytes for r\n const s2comp = compCoder(N).encode(s2);\n if (s2comp.length > maxLen) {\n cleanBytes(s2comp);\n continue;\n }\n return { s2: s2comp, nonce, msg } as TRet<SignatureRaw>;\n }\n } finally {\n cleanBytes(s2);\n sampler.destroy();\n cleanCPoly(b00, b01, b10, b11);\n cleanBytes(G);\n }\n } finally {\n cleanBytes(f, g, F);\n }\n } finally {\n cleanBytes(seed);\n }\n };\n\n // Raw helper: malformed encodings or wrong lengths still throw here; the public verify()/open()\n // wrappers decide whether to translate those failures into false or an exception.\n const verifyRaw = (\n pk: TArg<Uint8Array>,\n s2comp: TArg<Uint8Array>,\n nonce: TArg<Uint8Array>,\n msg: TArg<Uint8Array>\n ) => {\n // Algorithm 16: Verify(m, sig, pk, [β²])\n // (Page 45)\n // Require: A message m, a signature sig = (r, s), a public key pk = h ∈ Zq[x]/(φ), a bound [β²]\n // Ensure: Accept or reject\n // 1: c ← HashToPoint(r||m, q, n)\n // 2: s₂ ← Decompress(s, 8 · sbytelen - 328)\n // 3: if (s₂ = ⊥) then\n // 4: reject ▷ Reject invalid encodings\n // 5: s₁ ← c - s₂h mod q ▷ s₁ should be normalized between -q/2 and q/2\n // 6: if ||(s₁, s₂)||² < [β²] then\n // 7: accept\n // 8: else\n // 9: reject ▷ Reject signatures that are too long\n const s2 = compCoder(N).decode(s2comp); // 2: s₂ ← Decompress(s, 8 · sbytelen - 328)\n const c0 = HashToPoint(nonce, msg); // 1: c ← HashToPoint(r||m, q, n)\n const h = intPoly.toMontgomery(intPoly.ntt(publicKeyCoder.decode(pk)));\n const s1 = intPoly.intt(intPoly.mul(intPoly.ntt(signedCoder.decode(s2)), h));\n intPoly.sub(s1, c0); // 5: s₁ ← c - s₂h mod q ▷ s₁ should be normalized between -q/2 and q/2\n return intPoly.isShort(signedCoder.encode(s1), s2); // 6: if ||(s₁, s₂)||² < [β²] then\n };\n\n const info = Object.freeze({ type: 'falcon' });\n const keyLengths = Object.freeze({\n seed: 48,\n publicKey: publicKeyCoder.bytesLen,\n secretKey: secretKeyCoder.bytesLen,\n });\n // Falcon takes a sampler callback the other schemes do not, and rejects `context`\n // with its own message; both stay in the accepted set so the specific errors fire.\n const FALCON_SIG_OPT_KEYS = [...SIG_OPT_KEYS, 'random'] as const;\n // Noble exposes a 48-byte sampler-seed hook,\n // but Falcon still samples/encodes a separate 40-byte nonce per signature.\n const getRnd = (opts: TArg<FalconSigOpts> = {}): TRet<FalconRandom> => {\n // `context` stays in the accepted set so the specific \"not supported\" error below\n // still fires, rather than the generic unexpected-option one.\n opts = validateSigOpts(opts, FALCON_SIG_OPT_KEYS);\n if (opts.context !== undefined) throw new Error('context is not supported');\n if (opts.random !== undefined && typeof opts.random !== 'function')\n throw new TypeError('\"opts.random\" expected function, got type=' + typeof opts.random);\n if (opts.random !== undefined) return opts.random as TRet<FalconRandom>;\n if (opts.extraEntropy === undefined) return randomBytes;\n const seed = opts.extraEntropy === false ? new Uint8Array(48) : opts.extraEntropy;\n abytes(seed, 48, 'opts.extraEntropy');\n const drbg = rngAesCtrDrbg256(seed);\n return (len = 0) => drbg.randomBytes(len) as TRet<Uint8Array>;\n };\n const checkVerOpts = (opts: TArg<VerOpts> = {}) => {\n const normalized = validateVerOpts(opts);\n if (normalized.context !== undefined) throw new Error('context is not supported');\n };\n const tests = Object.freeze({\n publicKeyCoder: Object.freeze(publicKeyCoder),\n privateKeyCoder: Object.freeze(secretKeyCoder),\n maxS2Len: opts.maxS2Len,\n });\n // `signRand` documents only the sampler-seed input length;\n // detached/attached signatures still include their own 40-byte nonce.\n const attachedLengths = Object.freeze({ ...keyLengths, signRand: 48 });\n const lengths = opts.padded\n ? Object.freeze({ ...attachedLengths, signature: opts.sigLen })\n : attachedLengths;\n const keygen = (\n seed?: TArg<Uint8Array>\n ): TRet<{ publicKey: Uint8Array; secretKey: Uint8Array }> => {\n const randSeed = seed === undefined;\n if (randSeed) seed = randomBytes(48);\n abytes(seed!, 48, 'seed');\n const [f, g, F, _G, pub] = new NTRU(logn, seed!).generate();\n const sk = secretKeyCoder.encode([f, g, F]);\n const pk = publicKeyCoder.encode(pub);\n if (randSeed) cleanBytes(seed!);\n cleanBytes(f, g, F, _G);\n return { publicKey: pk, secretKey: sk } as TRet<{\n publicKey: Uint8Array;\n secretKey: Uint8Array;\n }>;\n };\n const getPublicKey = (sk: TArg<Uint8Array>): TRet<Uint8Array> => {\n abytes(sk, secretKeyCoder.bytesLen, 'secretKey');\n const [f, g, F] = secretKeyCoder.decode(sk);\n try {\n const h = computePublic(f, g);\n cleanBytes(f, g, F);\n return publicKeyCoder.encode(h) as TRet<Uint8Array>;\n } catch (e) {\n cleanBytes(f, g, F);\n throw e;\n }\n };\n const sign = (\n msg: TArg<Uint8Array>,\n sk: TArg<Uint8Array>,\n sigOpts: TArg<FalconSigOpts> = {}\n ): TRet<Uint8Array> => {\n const { s2, nonce } = signRaw(sk, msg, opts.maxS2Len, getRnd(sigOpts));\n return SignatureCoderDetached(logn).encode({ nonce, s2 });\n };\n /** Verify one detached Falcon signature.\n * Returns `false` for malformed detached signature encodings, non-canonical detached signatures,\n * and well-formed signatures that do not validate. Throws on malformed API argument types or\n * unsupported verification options.\n */\n const verify = (\n sig: TArg<Uint8Array>,\n msg: TArg<Uint8Array>,\n pk: TArg<Uint8Array>,\n verOpts: TArg<VerOpts> = {}\n ) => {\n checkVerOpts(verOpts);\n abytes(sig, undefined, 'signature');\n abytes(msg, undefined, 'msg');\n // Length/canonical public-key failures are decoded below and return false; only type is fatal.\n abytes(pk, undefined, 'publicKey');\n try {\n const { s2, nonce } = SignatureCoderDetached(logn).decode(sig);\n return verifyRaw(pk, s2, nonce, msg);\n } catch {\n return false;\n }\n };\n const attached: TRet<FalconAttached> = Object.freeze({\n info,\n lengths: attachedLengths,\n keygen,\n getPublicKey,\n seal(msg: TArg<Uint8Array>, sk: TArg<Uint8Array>, sigOpts: TArg<FalconSigOpts> = {}) {\n const { s2, nonce } = signRaw(sk, msg, opts.maxS2Len, getRnd(sigOpts));\n return SignatureCoder.encode({ msg, nonce, s2 });\n },\n open(sig: TArg<Uint8Array>, pk: TArg<Uint8Array>, verOpts: TArg<VerOpts> = {}) {\n checkVerOpts(verOpts);\n // Wrong argument types are caller bugs and must stay TypeErrors; only what happens\n // after this is untrusted input. Detached verify() type-checks the public key the same\n // way, so open() does too: a wrong type is fatal, and a malformed (wrong-length or\n // non-canonical) key folds into the single rejection below rather than leaking a raw\n // codec error, exactly as detached verify() folds it into `false`.\n abytes(sig, undefined, 'signature');\n abytes(pk, undefined, 'publicKey');\n // Decode and verify owned snapshots. Apart from keeping the authenticated result stable\n // after open() returns, this ensures every verification step observes the same bytes when\n // an input is backed by SharedArrayBuffer or has subclass-overridden view methods.\n const ownedSig = copyBytes(sig);\n const ownedPk = copyBytes(pk);\n // Decode failures and malformed-key failures are rejected signatures, not internal\n // faults. Letting the codec's own errors out gave a caller handling untrusted input\n // several different messages for one corrupt byte, including \"end of buffer: len=2\n // buf=0 lastByte=undefined\", which reads as a library bug. Detached verify already\n // treats every such failure uniformly; open() collapses them into one Error (the\n // original preserved as `cause`). A well-formed signature that simply does not\n // validate falls through to the same message with no cause.\n try {\n let verifiedMsg: Uint8Array | undefined;\n try {\n const { s2, nonce, msg } = SignatureCoder.decode(ownedSig);\n if (verifyRaw(ownedPk, s2, nonce, msg)) verifiedMsg = msg;\n } catch (cause) {\n throw new Error('invalid signature', { cause });\n }\n if (verifiedMsg === undefined) throw new Error('invalid signature');\n // Do not retain or expose the full attached-signature allocation through `.buffer`.\n return copyBytes(verifiedMsg);\n } finally {\n cleanBytes(ownedSig, ownedPk);\n }\n },\n });\n // PATCH (starknet.js-workshop pureTS): signing / verification of an externally computed hash\n // point, mirroring ml-dsa `internal` + `externalMu`. See PATCH.md.\n const INTERNAL_MAX_ITERATIONS = 1000;\n const checkHashPoint = (hashPoint: TArg<Uint16Array>): void => {\n if (!(hashPoint instanceof Uint16Array) || hashPoint.length !== N)\n throw new Error(`hashPoint: expected Uint16Array(${N})`);\n for (let i = 0; i < N; i++)\n if (hashPoint[i] >= Q) throw new Error('hashPoint: coefficient out of range');\n };\n const internal: TRet<FalconInternal> = Object.freeze({\n sign(\n hashPoint: TArg<Uint16Array>,\n sk: TArg<Uint8Array>,\n internalOpts: TArg<FalconInternalSignOpts> = {}\n ): TRet<Int16Array> {\n checkHashPoint(hashPoint);\n abytes(sk, secretKeyCoder.bytesLen, 'secretKey');\n const rnd = (internalOpts.random ?? randomBytes) as FalconRandom;\n const maxIterations = internalOpts.maxIterations ?? INTERNAL_MAX_ITERATIONS;\n const hm = Uint16Array.from(hashPoint) as IPoly;\n const seed = rnd(48);\n abytes(seed, 48, 'seed');\n try {\n const [f, g, F] = secretKeyCoder.decode(sk);\n try {\n const G = completePrivate(f, g, F);\n const b00 = floatPoly.FFT(floatPoly.convSmall(g));\n const b01 = floatPoly.FFT(floatPoly.neg(floatPoly.convSmall(f)));\n const b10 = floatPoly.FFT(floatPoly.convSmall(G));\n const b11 = floatPoly.FFT(floatPoly.neg(floatPoly.convSmall(F)));\n const sampler = new FFSampler(logn, seed, b00, b01, b10, b11);\n const s2 = new Int16Array(N);\n try {\n for (let iteration = 0; iteration < maxIterations; iteration++) {\n const { t0, t1 } = sampler.sample(hm);\n const t2 = floatPoly.add(floatPoly.mul(t0, b00), floatPoly.mul(t1, b10));\n const t3 = floatPoly.mul(t0, b01);\n const t4 = floatPoly.iFFT(t2);\n const t5 = floatPoly.iFFT(floatPoly.add(floatPoly.mul(t1, b11), t3));\n const hn = N >> 1;\n let sqn = 0;\n for (let i = 0; i < hn; i++) {\n sqn += (hm[i] - (Math.round(t4[i].re) | 0)) ** 2;\n sqn += (hm[hn + i] - (Math.round(t4[i].im) | 0)) ** 2;\n const z = -Math.round(t5[i].re);\n sqn += z * z;\n s2[i] = z & 0xffff;\n const z2 = -Math.round(t5[i].im);\n sqn += z2 * z2;\n s2[i + hn] = z2 & 0xffff;\n }\n cleanCPoly(t0, t1, t2, t3, t4, t5);\n if (sqn <= L2BOUND[logn]) return s2.slice() as TRet<Int16Array>;\n }\n throw new Error('internal.sign: no short signature found within the iteration cap');\n } finally {\n cleanBytes(s2);\n sampler.destroy();\n cleanCPoly(b00, b01, b10, b11);\n cleanBytes(G);\n }\n } finally {\n cleanBytes(f, g, F);\n }\n } finally {\n cleanBytes(seed);\n }\n },\n verify(\n s2: TArg<Int16Array>,\n hashPoint: TArg<Uint16Array>,\n pk: TArg<Uint8Array>\n ): boolean {\n checkHashPoint(hashPoint);\n if (!(s2 instanceof Int16Array) || s2.length !== N)\n throw new Error(`s2: expected Int16Array(${N})`);\n abytes(pk, publicKeyCoder.bytesLen, 'publicKey');\n const h = intPoly.toMontgomery(intPoly.ntt(publicKeyCoder.decode(pk)));\n const s1 = intPoly.intt(intPoly.mul(intPoly.ntt(signedCoder.decode(s2 as Int16Array)), h));\n intPoly.sub(s1, hashPoint as IPoly);\n return intPoly.isShort(signedCoder.encode(s1), s2 as Int16Array);\n },\n });\n const res = {\n info,\n lengths,\n attached,\n keygen,\n getPublicKey,\n sign,\n verify,\n internal,\n };\n (res as any).__test = tests;\n return Object.freeze(res);\n}\n\nconst falcon512opts = {\n N: 512,\n // Keep the mode an own property: omitted config fields must not inherit from Object.prototype.\n padded: false,\n // Table 3.3 fixed padded detached bytes, including the detached header byte and 40-byte nonce.\n sigLen: 666,\n fgBits: 6,\n FGBits: 8,\n // Compressed-s payload bytes only, excluding the detached header byte and 40-byte nonce.\n paddedLen: 625,\n};\n/**\n * Falcon-512 detached-signature API with the attached helper exposed as `.attached`.\n * @example\n * Generate a Falcon-512 keypair and verify one detached signature.\n * ```ts\n * const { secretKey, publicKey } = falcon512.keygen();\n * const msg = new Uint8Array([1, 2, 3]);\n * const sig = falcon512.sign(msg, secretKey);\n * falcon512.verify(sig, msg, publicKey);\n * ```\n */\nexport const falcon512: TRet<Falcon> = /* @__PURE__ */ (() =>\n genFalcon({ ...falcon512opts, maxS2Len: 711 }))();\n/**\n * Falcon-512 padded detached-signature API with the attached helper exposed as `.attached`.\n * @example\n * Generate a Falcon-512 padded keypair and verify one detached signature.\n * ```ts\n * const { secretKey, publicKey } = falcon512padded.keygen();\n * const msg = new Uint8Array([1, 2, 3]);\n * const sig = falcon512padded.sign(msg, secretKey);\n * falcon512padded.verify(sig, msg, publicKey);\n * ```\n */\nexport const falcon512padded: TRet<Falcon> = /* @__PURE__ */ (() =>\n genFalcon({\n ...falcon512opts,\n padded: true,\n maxS2Len: 625,\n }))();\n\nconst falcon1024opts = {\n N: 1024,\n padded: false,\n // Table 3.3 fixed padded detached bytes, including the detached header byte and 40-byte nonce.\n sigLen: 1280,\n fgBits: 5,\n FGBits: 8,\n // Compressed-s payload bytes only, excluding the detached header byte and 40-byte nonce.\n paddedLen: 1239,\n};\n/**\n * Falcon-1024 detached-signature API with the attached helper exposed as `.attached`.\n * @example\n * Generate a Falcon-1024 keypair and verify one detached signature.\n * ```ts\n * const { secretKey, publicKey } = falcon1024.keygen();\n * const msg = new Uint8Array([1, 2, 3]);\n * const sig = falcon1024.sign(msg, secretKey);\n * falcon1024.verify(sig, msg, publicKey);\n * ```\n */\nexport const falcon1024: TRet<Falcon> = /* @__PURE__ */ (() =>\n genFalcon({\n ...falcon1024opts,\n maxS2Len: 1421,\n }))();\n/**\n * Falcon-1024 padded detached-signature API with the attached helper exposed as `.attached`.\n * @example\n * Generate a Falcon-1024 padded keypair and verify one detached signature.\n * ```ts\n * const { secretKey, publicKey } = falcon1024padded.keygen();\n * const msg = new Uint8Array([1, 2, 3]);\n * const sig = falcon1024padded.sign(msg, secretKey);\n * falcon1024padded.verify(sig, msg, publicKey);\n * ```\n */\nexport const falcon1024padded: TRet<Falcon> = /* @__PURE__ */ (() =>\n genFalcon({\n ...falcon1024opts,\n padded: true,\n maxS2Len: 1239,\n }))();\n\n// NOTE: for tests only, don't use\nexport const __tests: any = /* @__PURE__ */ (() =>\n Object.freeze({\n BNORM_MAX,\n COMPLEX_ROOTS,\n Float,\n INV_SIGMA,\n SIGMA_MIN,\n getFloatPoly,\n ldlFFT,\n cleanCPoly,\n falcon512: (falcon512 as any).__test,\n falcon512padded: (falcon512padded as any).__test,\n falcon1024: (falcon1024 as any).__test,\n falcon1024padded: (falcon1024padded as any).__test,\n }))();\n","/* eslint-disable -- vendored copy of @noble/post-quantum 0.7.1, kept as is: see PATCH.md */\n/**\n * Internal methods for lattice-based ML-KEM and ML-DSA.\n * @module\n */\n/*! noble-post-quantum - MIT License (c) 2024 Paul Miller (paulmillr.com) */\nimport { FFTCore, reverseBits } from '@noble/curves/abstract/fft.js';\nimport { shake128, shake256 } from '@noble/hashes/sha3.js';\nimport type { TypedArray } from '@noble/hashes/utils.js';\nimport {\n type BytesCoderLen,\n cleanBytes,\n type Coder,\n getMask,\n type TArg,\n type TRet,\n} from './utils';\n\n/** Extendable-output reader used by the CRYSTALS implementations. */\nexport type XOF = (\n seed: Uint8Array,\n blockLen?: number\n) => {\n /**\n * Read diagnostic counters for the current XOF session.\n * @returns Current call and XOF block counters.\n */\n stats: () => { calls: number; xofs: number };\n /**\n * Select one `(x, y)` coordinate pair and get a block reader for it.\n * Only one coordinate stream is live at a time: a later `get(...)` call rebinds the shared\n * SHAKE state and invalidates older readers.\n * Each squeeze aliases one mutable internal output buffer, so callers must copy blocks they\n * want to retain before the next read.\n * @param x - First matrix coordinate.\n * @param y - Second matrix coordinate.\n * @returns Lazy block reader for that coordinate pair.\n */\n get: (x: number, y: number) => () => Uint8Array; // return block aligned to blockLen and 3\n /** Wipe any buffered state once the reader is no longer needed. */\n clean: () => void;\n};\n\n/** CRYSTALS (ml-kem, ml-dsa) options */\n/** Shared polynomial and NTT parameters for CRYSTALS algorithms. */\nexport type CrystalOpts<T extends TypedArray> = {\n /**\n * Allocate one zeroed polynomial/vector container.\n * @param n - Number of coefficients to allocate.\n * @returns Fresh typed container.\n */\n newPoly: TypedCons<T>;\n /** Polynomial size, typically `256`. */\n N: number;\n /** Prime modulus used for all coefficient arithmetic. */\n Q: number;\n /** Inverse transform normalization factor:\n * `256**-1 mod q` for Dilithium, `128**-1 mod q` for Kyber.\n */\n F: number;\n /** Principal root of unity for the transform domain. */\n ROOT_OF_UNITY: number;\n /** Number of bits used for bit-reversal ordering. */\n brvBits: number;\n /** `true` for Kyber/ML-KEM mode, `false` for Dilithium/ML-DSA mode. */\n isKyber: boolean;\n};\n\n/** Constructor function for typed polynomial containers. */\nexport type TypedCons<T extends TypedArray> = (n: number) => T;\n\ntype Crystals<T extends TypedArray> = {\n mod: (a: number, modulo?: number) => number;\n smod: (a: number, modulo?: number) => number;\n nttZetas: T;\n NTT: {\n /**\n * Forward transform in place. Mutates and returns `r`.\n * Kyber-mode input coefficients must already use canonical representatives in `[0, Q)`.\n */\n encode: (r: T) => T;\n /**\n * Inverse transform in place. Mutates and returns `r`.\n * Kyber-mode input coefficients must already use canonical representatives in `[0, Q)`.\n */\n decode: (r: T) => T;\n };\n bitsCoder: (d: number, c: Coder<number, number>) => BytesCoderLen<T>;\n};\n\n/**\n * Creates shared modular arithmetic, NTT, and packing helpers for CRYSTALS schemes.\n * @param opts - Polynomial and transform parameters. See {@link CrystalOpts}.\n * @returns CRYSTALS arithmetic and encoding helpers.\n * @example\n * Create shared modular arithmetic and NTT helpers for a CRYSTALS parameter set.\n * ```ts\n * const crystals = genCrystals({\n * newPoly: (n) => new Uint16Array(n),\n * N: 256,\n * Q: 3329,\n * F: 3303,\n * ROOT_OF_UNITY: 17,\n * brvBits: 7,\n * isKyber: true,\n * });\n * const reduced = crystals.mod(-1);\n * ```\n */\nexport const genCrystals = <T extends TypedArray>(opts: CrystalOpts<T>): TRet<Crystals<T>> => {\n // isKyber: true means Kyber, false means Dilithium\n const { newPoly, N, Q, F, ROOT_OF_UNITY, brvBits, isKyber } = opts;\n // Normalize JS `%` into the canonical Z_m representative `[0, modulo-1]` expected by\n // FIPS 203 §2.3 / FIPS 204 §2.3 before downstream mod-q arithmetic.\n const mod = (a: number, modulo = Q): number => {\n const result = (a % modulo) | 0;\n return (result >= 0 ? result | 0 : (modulo + result) | 0) | 0;\n };\n // FIPS 204 §7.4 uses the centered `mod ±` representative for low bits, keeping the\n // positive midpoint when `modulo` is even.\n // Center to `[-floor((modulo-1)/2), floor(modulo/2)]`.\n const smod = (a: number, modulo = Q): number => {\n const r = mod(a, modulo) | 0;\n return (r > modulo >> 1 ? (r - modulo) | 0 : r) | 0;\n };\n // Kyber uses the FIPS 203 Appendix A `BitRev_7` table here via the first 128 entries, while\n // Dilithium uses the FIPS 204 §7.5 / Appendix B `BitRev_8` zetas table over all 256 entries.\n function getZettas() {\n const out = newPoly(N);\n for (let i = 0; i < N; i++) {\n const b = reverseBits(i, brvBits);\n const p = BigInt(ROOT_OF_UNITY) ** BigInt(b) % BigInt(Q);\n out[i] = Number(p) | 0;\n }\n return out;\n }\n const nttZetas = getZettas();\n\n // Number-Theoretic Transform\n // Explained: https://electricdusk.com/ntt.html\n\n // Kyber has slightly different params, since there is no 512th primitive root of unity mod q,\n // only 256th primitive root of unity mod. Which also complicates MultiplyNTT.\n\n const inv = (_a: number) => {\n throw new Error('not implemented');\n };\n // ML-KEM (Kyber) polynomials always enter the transform reduced to [0, Q), so add/sub only\n // need one conditional correction instead of `%`; measured ~20% faster NTT there.\n // ML-DSA keeps the generic mod() path on purpose: its first forward stage sees centered\n // (negative) coefficients, and `sub(a, t)` can drop below -Q (t is a mul output in [0, Q)),\n // so a single correction is not enough. A guarded fast path with mod() fallback was measured\n // slower than plain `%` for the 23-bit Q (V8 int32 modulo is one div; the branches lose).\n const field = isKyber\n ? {\n add: (a: number, b: number) => {\n const r = (a + b) | 0;\n return r >= Q ? (r - Q) | 0 : r;\n },\n sub: (a: number, b: number) => {\n const r = (a - b) | 0;\n return r < 0 ? (r + Q) | 0 : r;\n },\n mul: (a: number, b: number) => mod((a | 0) * (b | 0)) | 0,\n inv,\n }\n : {\n add: (a: number, b: number) => mod((a | 0) + (b | 0)) | 0,\n sub: (a: number, b: number) => mod((a | 0) - (b | 0)) | 0,\n mul: (a: number, b: number) => mod((a | 0) * (b | 0)) | 0,\n inv,\n };\n const nttOpts = {\n N,\n roots: nttZetas as any,\n invertButterflies: true,\n skipStages: isKyber ? 1 : 0,\n brp: false,\n };\n const dif = FFTCore(field, { dit: false, ...nttOpts });\n const dit = FFTCore(field, { dit: true, ...nttOpts });\n const NTT = {\n encode: (r: T): T => {\n return dif(r) as any;\n },\n decode: (r: T): T => {\n dit(r as any);\n // The inverse-NTT normalization factor is family-specific: FIPS 203 Algorithm 10 line 14\n // uses `128^-1 mod q` for Kyber, while FIPS 204 Algorithm 42 lines 21-23 use `256^-1 mod q`.\n // kyber uses 128 here, because brv && stuff\n for (let i = 0; i < r.length; i++) r[i] = mod(F * r[i]);\n return r;\n },\n };\n // Pack one little-endian `d`-bit word per coefficient, matching FIPS 203 ByteEncode /\n // ByteDecode and the FIPS 204 BitsToBytes-based polynomial packing helpers.\n const bitsCoder = (d: number, c: Coder<number, number>): TRet<BytesCoderLen<T>> => {\n // Validate the carry shape once: JS bitwise operations silently truncate wider accumulators.\n for (let i = 0, bufLen = 0; i < N; i++) {\n bufLen += d;\n if (bufLen > 32) getMask(bufLen);\n bufLen %= 8;\n }\n const mask = getMask(d);\n const bytesLen = d * (N / 8);\n return {\n bytesLen,\n encode: (poly_: TArg<T>): TRet<Uint8Array> => {\n const poly = poly_ as T;\n const r = new Uint8Array(bytesLen);\n for (let i = 0, buf = 0, bufLen = 0, pos = 0; i < poly.length; i++) {\n buf |= (c.encode(poly[i]) & mask) << bufLen;\n bufLen += d;\n // Take the low byte directly: `& 0xff` matches the previous getMask(bufLen) result\n // after Uint8Array truncation, without a validated function call per output byte.\n for (; bufLen >= 8; bufLen -= 8, buf >>= 8) r[pos++] = buf & 0xff;\n }\n return r as TRet<Uint8Array>;\n },\n decode: (bytes: TArg<Uint8Array>): TRet<T> => {\n const r = newPoly(N);\n for (let i = 0, buf = 0, bufLen = 0, pos = 0; i < bytes.length; i++) {\n buf |= bytes[i] << bufLen;\n bufLen += 8;\n for (; bufLen >= d; bufLen -= d, buf >>= d) r[pos++] = c.decode(buf & mask);\n }\n return r as TRet<T>;\n },\n } as TRet<BytesCoderLen<T>>;\n };\n\n return {\n mod,\n smod,\n nttZetas: nttZetas as TRet<T>,\n NTT: {\n encode: (r: TArg<T>): TRet<T> => NTT.encode(r as T) as TRet<T>,\n decode: (r: TArg<T>): TRet<T> => NTT.decode(r as T) as TRet<T>,\n },\n bitsCoder: bitsCoder as TRet<Crystals<T>>['bitsCoder'],\n };\n};\n\nconst createXofShake =\n (shake: typeof shake128): TRet<XOF> =>\n (seed: TArg<Uint8Array>, blockLen?: number) => {\n if (!blockLen) blockLen = shake.blockLen;\n // Optimizations that won't mater:\n // - cached seed update (two .update(), on start and on the end)\n // - another cache which cloned into working copy\n\n // Faster than multiple updates, since seed less than blockLen\n const _seed = new Uint8Array(seed.length + 2);\n _seed.set(seed);\n const seedLen = seed.length;\n const buf = new Uint8Array(blockLen); // == shake128.blockLen\n let h = shake.create({});\n let calls = 0;\n let xofs = 0;\n return {\n stats: () => ({ calls, xofs }),\n get: (x: number, y: number) => {\n // Rebind to `seed || x || y` so callers can implement the spec's per-coordinate\n // SHAKE inputs like `rho || j || i` and `rho || IntegerToBytes(counter, 2)`.\n _seed[seedLen + 0] = x;\n _seed[seedLen + 1] = y;\n h.destroy();\n h = shake.create({}).update(_seed);\n calls++;\n return () => {\n xofs++;\n return h.xofInto(buf) as TRet<Uint8Array>;\n };\n },\n clean: () => {\n h.destroy();\n cleanBytes(buf, _seed);\n },\n };\n };\n\n/**\n * SHAKE128-based extendable-output reader factory used by ML-KEM.\n * `get(x, y)` selects one coordinate pair at a time; calling it again invalidates previously\n * returned readers, and each squeeze reuses one mutable internal output buffer.\n * @param seed - Seed bytes for the reader.\n * @param blockLen - Optional output block length.\n * @returns Stateful XOF reader.\n * @example\n * Build the ML-KEM SHAKE128 matrix expander and read one block.\n * ```ts\n * import { randomBytes } from '@noble/post-quantum/utils.js';\n * import { XOF128 } from '@noble/post-quantum/_crystals.js';\n * const reader = XOF128(randomBytes(32));\n * const block = reader.get(0, 0)();\n * ```\n */\nexport const XOF128: TRet<XOF> = /* @__PURE__ */ createXofShake(shake128);\n/**\n * SHAKE256-based extendable-output reader factory used by ML-DSA.\n * `get(x, y)` appends raw one-byte coordinates to the seed, invalidates previously returned\n * readers, and reuses one mutable internal output buffer for each squeeze.\n * @param seed - Seed bytes for the reader.\n * @param blockLen - Optional output block length.\n * @returns Stateful XOF reader.\n * @example\n * Build the ML-DSA SHAKE256 coefficient expander and read one block.\n * ```ts\n * import { randomBytes } from '@noble/post-quantum/utils.js';\n * import { XOF256 } from '@noble/post-quantum/_crystals.js';\n * const reader = XOF256(randomBytes(32));\n * const block = reader.get(0, 0)();\n * ```\n */\nexport const XOF256: TRet<XOF> = /* @__PURE__ */ createXofShake(shake256);\n","/* eslint-disable -- vendored copy of @noble/post-quantum 0.7.1, kept as is: see PATCH.md */\n/**\n * Utilities for hex, bytearray and number handling.\n * @module\n */\n/*! noble-post-quantum - MIT License (c) 2024 Paul Miller (paulmillr.com) */\nimport {\n type CHash,\n type TypedArray,\n abytes,\n abytes as abytes_,\n ahash as ahash_,\n anumber,\n bytesToHex,\n concatBytes,\n isBytes,\n isLE,\n randomBytes as randb,\n} from '@noble/hashes/utils.js';\n/**\n * Bytes API type helpers for old + new TypeScript.\n *\n * TS 5.6 has `Uint8Array`, while TS 5.9+ made it generic `Uint8Array<ArrayBuffer>`.\n * We can't use specific return type, because TS 5.6 will error.\n * We can't use generic return type, because most TS 5.9 software will expect specific type.\n *\n * Maps typed-array input leaves to broad forms.\n * These are compatibility adapters, not ownership guarantees.\n *\n * - `TArg` keeps byte inputs broad.\n * - `TRet` marks byte outputs for TS 5.6 and TS 5.9+ compatibility.\n */\nexport type TypedArg<T> = T extends BigInt64Array\n ? BigInt64Array\n : T extends BigUint64Array\n ? BigUint64Array\n : T extends Float32Array\n ? Float32Array\n : T extends Float64Array\n ? Float64Array\n : T extends Int16Array\n ? Int16Array\n : T extends Int32Array\n ? Int32Array\n : T extends Int8Array\n ? Int8Array\n : T extends Uint16Array\n ? Uint16Array\n : T extends Uint32Array\n ? Uint32Array\n : T extends Uint8ClampedArray\n ? Uint8ClampedArray\n : T extends Uint8Array\n ? Uint8Array\n : never;\n/** Maps typed-array output leaves to narrow TS-compatible forms. */\nexport type TypedRet<T> = T extends BigInt64Array\n ? ReturnType<typeof BigInt64Array.of>\n : T extends BigUint64Array\n ? ReturnType<typeof BigUint64Array.of>\n : T extends Float32Array\n ? ReturnType<typeof Float32Array.of>\n : T extends Float64Array\n ? ReturnType<typeof Float64Array.of>\n : T extends Int16Array\n ? ReturnType<typeof Int16Array.of>\n : T extends Int32Array\n ? ReturnType<typeof Int32Array.of>\n : T extends Int8Array\n ? ReturnType<typeof Int8Array.of>\n : T extends Uint16Array\n ? ReturnType<typeof Uint16Array.of>\n : T extends Uint32Array\n ? ReturnType<typeof Uint32Array.of>\n : T extends Uint8ClampedArray\n ? ReturnType<typeof Uint8ClampedArray.of>\n : T extends Uint8Array\n ? ReturnType<typeof Uint8Array.of>\n : never;\n/** Recursively adapts byte-carrying API input types. See {@link TypedArg}. */\nexport type TArg<T> =\n | T\n | ([TypedArg<T>] extends [never]\n ? T extends (...args: infer A) => infer R\n ? ((...args: { [K in keyof A]: TRet<A[K]> }) => TArg<R>) & {\n [K in keyof T]: T[K] extends (...args: any) => any ? T[K] : TArg<T[K]>;\n }\n : T extends [infer A, ...infer R]\n ? [TArg<A>, ...{ [K in keyof R]: TArg<R[K]> }]\n : T extends readonly [infer A, ...infer R]\n ? readonly [TArg<A>, ...{ [K in keyof R]: TArg<R[K]> }]\n : T extends (infer A)[]\n ? TArg<A>[]\n : T extends readonly (infer A)[]\n ? readonly TArg<A>[]\n : T extends Promise<infer A>\n ? Promise<TArg<A>>\n : T extends object\n ? { [K in keyof T]: TArg<T[K]> }\n : T\n : TypedArg<T>);\n/** Recursively adapts byte-carrying API output types. See {@link TypedArg}. */\nexport type TRet<T> = T extends unknown\n ? T &\n ([TypedRet<T>] extends [never]\n ? T extends (...args: infer A) => infer R\n ? ((...args: { [K in keyof A]: TArg<A[K]> }) => TRet<R>) & {\n [K in keyof T]: T[K] extends (...args: any) => any ? T[K] : TRet<T[K]>;\n }\n : T extends [infer A, ...infer R]\n ? [TRet<A>, ...{ [K in keyof R]: TRet<R[K]> }]\n : T extends readonly [infer A, ...infer R]\n ? readonly [TRet<A>, ...{ [K in keyof R]: TRet<R[K]> }]\n : T extends (infer A)[]\n ? TRet<A>[]\n : T extends readonly (infer A)[]\n ? readonly TRet<A>[]\n : T extends Promise<infer A>\n ? Promise<TRet<A>>\n : T extends object\n ? { [K in keyof T]: TRet<T[K]> }\n : T\n : TypedRet<T>)\n : never;\n/**\n * Asserts that a value is a byte array and optionally checks its length.\n * Returns the original reference unchanged on success, and currently also accepts Node `Buffer`\n * values through the upstream validator.\n * This helper throws on malformed input, so APIs that must return `false` need to guard lengths\n * before decoding or before calling it.\n * @example\n * Validate that a value is a byte array with the expected length.\n * ```ts\n * abytes(new Uint8Array([1]), 1);\n * ```\n */\nconst abytesDoc: typeof abytes = abytes;\nexport { abytesDoc as abytes };\n/**\n * Concatenates byte arrays into a new `Uint8Array`.\n * Zero arguments return an empty `Uint8Array`.\n * Invalid segments throw before allocation because each argument is validated first.\n * @example\n * Concatenate two byte arrays into one result.\n * ```ts\n * concatBytes(new Uint8Array([1]), new Uint8Array([2]));\n * ```\n */\nconst concatBytesDoc: typeof concatBytes = concatBytes;\nexport { concatBytesDoc as concatBytes };\n/**\n * Returns cryptographically secure random bytes.\n * Requires `globalThis.crypto.getRandomValues` and throws if that API is unavailable.\n * `bytesLength` is validated by the upstream helper as a non-negative integer before allocation,\n * so negative and fractional values both throw instead of truncating through JS `ToIndex`.\n * @param bytesLength - Number of random bytes to generate.\n * @returns Fresh random bytes.\n * @example\n * Generate a fresh random seed.\n * ```ts\n * const seed = randomBytes(4);\n * ```\n */\nexport const randomBytes: typeof randb = randb;\n\nexport function aarray<T>(\n item: unknown,\n title: string,\n inner: (elm: T, title: string) => void = () => {}\n): T[] {\n if (!Array.isArray(item))\n throw new TypeError(`\"${title}\" expected array, got type=${typeof item}`);\n for (let i = 0; i < item.length; i++) inner(item[i], `${title}[${i}]`);\n return item;\n}\n\nexport function aobject<T extends object>(value: unknown, title = 'object'): T {\n if (value === null || typeof value !== 'object' || Array.isArray(value))\n throw new TypeError(\n title === 'object'\n ? 'expected valid options object'\n : `\"${title}\" expected object, got type=${typeof value}`\n );\n return value as T;\n}\n\n/**\n * Compares two byte arrays in a length-constant way for equal lengths.\n * Inputs are validated as byte arrays; unequal lengths return `false` immediately.\n * @param a - First byte array.\n * @param b - Second byte array.\n * @returns Whether both arrays contain the same bytes.\n * @example\n * Compare two byte arrays for equality.\n * ```ts\n * equalBytes(new Uint8Array([1]), new Uint8Array([1]));\n * ```\n */\nexport function equalBytes(a: TArg<Uint8Array>, b: TArg<Uint8Array>): boolean {\n a = abytes(a);\n b = abytes(b);\n if (a.length !== b.length) return false;\n let diff = 0;\n for (let i = 0; i < a.length; i++) diff |= a[i] ^ b[i];\n return diff === 0;\n}\n\n/**\n * Copies bytes into a fresh `Uint8Array`.\n * Returns a detached plain `Uint8Array` after validating that the input is real bytes.\n * @param bytes - Source bytes.\n * @returns Copy of the input bytes.\n * @example\n * Copy bytes into a fresh array.\n * ```ts\n * copyBytes(new Uint8Array([1, 2]));\n * ```\n */\nexport function copyBytes(bytes: TArg<Uint8Array>): TRet<Uint8Array> {\n // The typed-array constructor copies a typed-array source through its internal byte storage.\n // Unlike `Uint8Array.from`, it does not invoke a subclass-overridden iterator. Keep the explicit\n // validation because the constructor itself would also accept arrays and other typed arrays.\n return new Uint8Array(abytes(bytes)) as TRet<Uint8Array>;\n}\n\n/**\n * Byte-swaps each 64-bit lane in place.\n * Falcon's exact binary64 tables are stored as little-endian byte payloads, so BE runtimes need\n * this boundary helper before aliasing them as host `Float64Array` lanes.\n * @param arr - Byte buffer whose length is a multiple of 8.\n * @returns The same buffer after in-place 64-bit lane byte swaps.\n * @example\n * Byte-swap one 64-bit lane in place.\n * ```ts\n * byteSwap64(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]));\n * ```\n */\nexport function byteSwap64<T extends ArrayBufferView>(arr: T): T {\n const bytes = new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength);\n for (let i = 0; i < bytes.length; i += 8) {\n const a0 = bytes[i + 0];\n const a1 = bytes[i + 1];\n const a2 = bytes[i + 2];\n const a3 = bytes[i + 3];\n bytes[i + 0] = bytes[i + 7];\n bytes[i + 1] = bytes[i + 6];\n bytes[i + 2] = bytes[i + 5];\n bytes[i + 3] = bytes[i + 4];\n bytes[i + 4] = a3;\n bytes[i + 5] = a2;\n bytes[i + 6] = a1;\n bytes[i + 7] = a0;\n }\n return arr;\n}\n/**\n * Byte-swaps 64-bit lanes on big-endian runtimes and returns the input unchanged on little-endian.\n * This keeps Falcon's binary64 tables in canonical little-endian order before aliasing them as\n * `Float64Array` lanes on the current host.\n * @param arr - Buffer to pass through or swap in place.\n * @returns The same buffer, normalized for Falcon's little-endian table layout.\n * @example\n * Normalize one host-endian buffer for Falcon's float tables.\n * ```ts\n * baswap64If(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]));\n * ```\n */\nexport const baswap64If: <T extends ArrayBufferView>(arr: T) => T = isLE\n ? (arr) => arr\n : byteSwap64;\n\n/** Shared key-generation surface for signers and KEMs. */\nexport type CryptoKeys = {\n /** Optional metadata about the algorithm family or variant. */\n info?: { type?: string };\n /** Public byte lengths for the exported key material. */\n lengths: { seed?: number; publicKey?: number; secretKey?: number };\n /**\n * Generate one secret/public keypair.\n * @param seed - Optional seed bytes for deterministic key generation.\n * @returns Fresh secret/public keypair.\n */\n keygen: (seed?: TArg<Uint8Array>) => {\n secretKey: TRet<Uint8Array>;\n publicKey: TRet<Uint8Array>;\n };\n /**\n * Derive one public key from a secret key.\n * @param secretKey - Secret key bytes.\n * @returns Public key bytes.\n */\n getPublicKey: (secretKey: TArg<Uint8Array>) => TRet<Uint8Array>;\n};\n\n/** Verification options shared by the signature APIs. */\nexport type VerOpts = {\n /** Optional application-defined context string. */\n context?: Uint8Array;\n};\n/** Signing options shared by the signature APIs. */\nexport type SigOpts = VerOpts & {\n // Compatibility with @noble/curves: false to disable, enabled by default, user can pass U8A\n /** Optional extra entropy or `false` to disable randomized signing. */\n extraEntropy?: Uint8Array | false;\n};\n\n/**\n * Validates that an options bag is a plain object.\n * @param opts - Options object to validate.\n * @throws On wrong argument types. {@link TypeError}\n * @example\n * Validate that an options bag is a plain object.\n * ```ts\n * validateOpts({});\n * ```\n */\nexport function validateOpts(opts: object): void {\n // Arrays silently passed here before, but these call sites expect named option-bag fields.\n if (isBytes(opts)) throw new TypeError('\"opts\" expected object, got Uint8Array');\n aobject(opts, 'opts');\n const proto = Object.getPrototypeOf(opts);\n // Options are security parameters, not general class instances. Restricting the bag to own\n // properties prevents values injected through Object.prototype (or a custom shared prototype)\n // from silently changing signing behavior. Null-prototype records remain supported.\n if (proto !== null && proto !== Object.prototype)\n throw new TypeError('\"opts\" expected a plain object');\n}\n\n// Frozen because they are exported: an unfrozen array export lets anything in the\n// process push a key onto the accepted set and silently re-open exactly the hole this\n// validation closes.\n/** Keys accepted by `verify`. */\nexport const VER_OPT_KEYS: readonly ['context'] = /* @__PURE__ */ Object.freeze([\n 'context',\n] as const);\n/** Keys accepted by `sign`. */\nexport const SIG_OPT_KEYS: readonly ['context', 'extraEntropy'] = /* @__PURE__ */ Object.freeze([\n 'context',\n 'extraEntropy',\n] as const);\n\n/**\n * Rejects option keys the caller did not mean to set.\n *\n * Validating the types of known keys while ignoring unknown ones makes a typo\n * indistinguishable from an omission, and for these options an omission is a\n * security downgrade rather than a no-op: `{ ctx }` instead of `{ context }` signs\n * with no domain separation, succeeds, and verifies for anyone who also supplies\n * none. Nothing at any layer reports it. TypeScript catches this through excess\n * property checks, so the exposure is JavaScript callers specifically.\n *\n * @param opts - Options object to check.\n * @param allowed - The keys this call site accepts.\n * Returns a frozen null-prototype snapshot so later reads cannot fall through to a polluted\n * prototype. Like `checkOpts()` in noble-hashes, only enumerable own properties are copied.\n * @throws If any other copied key is present or the bag has a custom prototype. {@link TypeError}\n * @returns Sanitized snapshot of the enumerable own options.\n * @example\n * Accept a known option key. A key the list does not name, such as `ctx`, throws instead.\n * ```ts\n * import { checkOptKeys } from '@noble/post-quantum/utils.js';\n * checkOptKeys({ context: new Uint8Array() }, ['context']);\n * ```\n */\nexport function checkOptKeys<T extends object>(opts: T, allowed: readonly string[]): T {\n validateOpts(opts);\n // Snapshot once before validation: Object.assign follows the same own-enumerable option-bag\n // semantics as noble-hashes, while the null prototype keeps omitted fields immune to pollution.\n const normalized = Object.assign(Object.create(null), opts) as Record<string, unknown>;\n for (const [k, v] of Object.entries(normalized)) {\n // `undefined` means unset everywhere else in these validators, and building an options bag by\n // spread is a normal way to reach these calls, so present-but-undefined stays equivalent to\n // omission.\n if (v === undefined) continue;\n if (!allowed.includes(k))\n throw new TypeError(\n 'unexpected option \"' + String(k) + '\"; expected one of: ' + allowed.join(', ')\n );\n }\n return Object.freeze(normalized) as T;\n}\n\n/**\n * Validates common verification options.\n * `context` itself is validated with `abytes(...)`, and individual algorithms may narrow support\n * further after this shared plain-object gate.\n * @param opts - Verification options. See {@link VerOpts}.\n * @param allowed - Keys this call site accepts. Defaults to {@link VER_OPT_KEYS}; surfaces that\n * take extra keys, or take fewer, pass their own list.\n * @throws On wrong argument types. {@link TypeError}\n * @returns Frozen null-prototype snapshot of the validated options.\n * @example\n * Validate common verification options.\n * ```ts\n * validateVerOpts({ context: new Uint8Array([1]) });\n * ```\n */\nexport function validateVerOpts<T extends TArg<VerOpts>>(\n opts: T,\n allowed: readonly string[] = VER_OPT_KEYS\n): T {\n const normalized = checkOptKeys(opts, allowed);\n if (normalized.context !== undefined) abytes(normalized.context, undefined, 'opts.context');\n return normalized;\n}\n\n/**\n * Validates common signing options.\n * `extraEntropy` is validated with `abytes(...)`; exact lengths and extra algorithm-specific\n * restrictions are enforced later by callers.\n * @param opts - Signing options. See {@link SigOpts}.\n * @param allowed - Keys this call site accepts. Defaults to {@link SIG_OPT_KEYS}; surfaces that\n * take extra keys, or take fewer, pass their own list.\n * @throws On wrong argument types. {@link TypeError}\n * @returns Frozen null-prototype snapshot of the validated options.\n * @example\n * Validate common signing options.\n * ```ts\n * validateSigOpts({ extraEntropy: new Uint8Array([1]) });\n * ```\n */\nexport function validateSigOpts<T extends TArg<SigOpts>>(\n opts: T,\n allowed: readonly string[] = SIG_OPT_KEYS\n): T {\n const normalized = checkOptKeys(opts, allowed);\n if (normalized.context !== undefined) abytes(normalized.context, undefined, 'opts.context');\n if (normalized.extraEntropy !== false && normalized.extraEntropy !== undefined)\n abytes(normalized.extraEntropy, undefined, 'opts.extraEntropy');\n return normalized;\n}\n\n/** Generic signature interface with key generation, signing, and verification. */\nexport type Signer = CryptoKeys & {\n /** Public byte lengths for signatures and signing randomness. */\n lengths: { signRand?: number; signature?: number };\n /**\n * Sign one message.\n * @param msg - Message bytes to sign.\n * @param secretKey - Secret key bytes.\n * @param opts - Optional signing options.\n * @returns Signature bytes.\n */\n sign: (\n msg: TArg<Uint8Array>,\n secretKey: TArg<Uint8Array>,\n opts?: TArg<SigOpts>\n ) => TRet<Uint8Array>;\n /**\n * Verify one signature.\n * @param sig - Signature bytes.\n * @param msg - Signed message bytes.\n * @param publicKey - Public key bytes.\n * @param opts - Optional verification options.\n * @returns `true` when the signature is valid, `false` when all inputs are well-formed but the\n * signature check does not pass. Some implementations also treat malformed signature encodings as\n * a verification failure and return `false`.\n * @throws On malformed API arguments or unsupported verification options.\n */\n verify: (\n sig: TArg<Uint8Array>,\n msg: TArg<Uint8Array>,\n publicKey: TArg<Uint8Array>,\n opts?: TArg<VerOpts>\n ) => boolean;\n};\n\n/** Generic key encapsulation mechanism interface. */\nexport type KEM = CryptoKeys & {\n /** Public byte lengths for ciphertexts and optional message randomness. */\n lengths: { cipherText?: number; msg?: number; msgRand?: number };\n /**\n * Encapsulate one shared secret to a recipient public key.\n * @param publicKey - Recipient public key bytes.\n * @param msg - Optional caller-provided randomness/message seed.\n * @returns Ciphertext plus shared secret.\n */\n encapsulate: (\n publicKey: TArg<Uint8Array>,\n msg?: TArg<Uint8Array>\n ) => {\n cipherText: TRet<Uint8Array>;\n sharedSecret: TRet<Uint8Array>;\n };\n /**\n * Recover the shared secret from a ciphertext and recipient secret key.\n * @param cipherText - Ciphertext bytes.\n * @param secretKey - Recipient secret key bytes.\n * @returns Decapsulated shared secret.\n */\n decapsulate: (cipherText: TArg<Uint8Array>, secretKey: TArg<Uint8Array>) => TRet<Uint8Array>;\n};\n\n/** Bidirectional encoder/decoder interface. */\nexport interface Coder<F, T> {\n /**\n * Serialize one value.\n * @param from - Value to encode.\n * @returns Encoded representation.\n */\n encode(from: F): T;\n /**\n * Parse one serialized value.\n * @param to - Encoded representation.\n * @returns Decoded value.\n */\n decode(to: T): F;\n}\n\n/** Encoder/decoder interface specialized for byte arrays. */\nexport interface BytesCoder<T> extends Coder<T, Uint8Array> {\n /**\n * Serialize one value into bytes.\n * @param data - Value to encode.\n * @returns Encoded bytes.\n */\n encode: (data: T) => Uint8Array;\n /**\n * Parse one byte array into a value.\n * @param bytes - Encoded bytes.\n * @returns Decoded value.\n */\n decode: (bytes: Uint8Array) => T;\n}\n\n/** Fixed-length byte encoder/decoder. */\nexport type BytesCoderLen<T> = BytesCoder<T> & { bytesLen: number };\n\n// nano-packed, because struct encoding is hard.\ntype UnCoder<T> = T extends BytesCoder<infer U> ? U : never;\ntype SplitOut<T extends (number | BytesCoderLen<any>)[]> = {\n [K in keyof T]: T[K] extends number ? Uint8Array : UnCoder<T[K]>;\n};\n/**\n * Builds a fixed-layout coder from byte lengths and nested coders.\n * Raw-length fields decode as zero-copy `subarray(...)` views, and nested coders may preserve that\n * aliasing too. Nested coder `encode(...)` results are treated as owned scratch: `splitCoder`\n * copies them into the output and then zeroizes them with `fill(0)`. If a nested encoder forwards\n * caller-owned bytes, it must do so only after detaching them into a disposable copy.\n * @param label - Label used in validation errors.\n * @param lengths - Field lengths or nested coders.\n * @returns Composite fixed-length coder.\n * @example\n * Build a fixed-layout coder from byte lengths and nested coders.\n * ```ts\n * splitCoder('demo', 1, 2).encode([new Uint8Array([1]), new Uint8Array([2, 3])]);\n * ```\n */\nexport function splitCoder<T extends (number | BytesCoderLen<any>)[]>(\n label: string,\n ...lengths: T\n): TRet<BytesCoder<SplitOut<T>> & { bytesLen: number }> {\n const getLength = (c: TArg<number | BytesCoderLen<any>>) =>\n typeof c === 'number' ? c : (c as BytesCoderLen<any>).bytesLen;\n const bytesLen: number = lengths.reduce((sum: number, a) => sum + getLength(a), 0);\n return {\n bytesLen,\n encode: (bufs: T) => {\n const res = new Uint8Array(bytesLen);\n for (let i = 0, pos = 0; i < lengths.length; i++) {\n const c = lengths[i];\n const l = getLength(c);\n const b: Uint8Array = typeof c === 'number' ? (bufs[i] as any) : c.encode(bufs[i]);\n abytes_(b, l, label);\n res.set(b, pos);\n if (typeof c !== 'number') b.fill(0); // clean\n pos += l;\n }\n return res;\n },\n decode: (buf: TArg<Uint8Array>) => {\n abytes_(buf, bytesLen, label);\n const res = [];\n for (const c of lengths) {\n const l = getLength(c);\n const b = buf.subarray(0, l);\n res.push(typeof c === 'number' ? b : c.decode(b));\n buf = buf.subarray(l);\n }\n return res as SplitOut<T>;\n },\n } as any;\n}\n// nano-packed.array (fixed size)\n/**\n * Builds a fixed-length vector coder from another fixed-length coder.\n * Element decoding receives `subarray(...)` views, so aliasing depends on the element coder.\n * Element coder `encode(...)` results are treated as owned scratch: `vecCoder` copies them into\n * the output and then zeroizes them with `fill(0)`. If an element encoder forwards caller-owned\n * bytes, it must do so only after detaching them into a disposable copy. `vecCoder` also trusts\n * the `BytesCoderLen` contract: each encoded element must already be exactly `c.bytesLen` bytes.\n * @param c - Element coder.\n * @param vecLen - Number of elements in the vector.\n * @returns Fixed-length vector coder.\n * @example\n * Build a fixed-length vector coder from another fixed-length coder.\n * ```ts\n * vecCoder(\n * { bytesLen: 1, encode: (n: number) => Uint8Array.of(n), decode: (b: Uint8Array) => b[0] || 0 },\n * 2\n * ).encode([1, 2]);\n * ```\n */\nexport function vecCoder<T>(c: TArg<BytesCoderLen<T>>, vecLen: number): TRet<BytesCoderLen<T[]>> {\n const coder = c as BytesCoderLen<T>;\n const bytesLen = vecLen * coder.bytesLen;\n return {\n bytesLen,\n encode: (u: TArg<T[]>): TRet<Uint8Array> => {\n const uArr = aarray<T>(u, 'u');\n if (uArr.length !== vecLen)\n throw new RangeError(`vecCoder.encode: wrong length=${uArr.length}. Expected: ${vecLen}`);\n const res = new Uint8Array(bytesLen);\n for (let i = 0, pos = 0; i < uArr.length; i++) {\n const b = coder.encode(uArr[i] as T);\n res.set(b, pos);\n b.fill(0); // clean\n pos += b.length;\n }\n return res as TRet<Uint8Array>;\n },\n decode: (a: TArg<Uint8Array>): TRet<T[]> => {\n abytes_(a, bytesLen);\n const r: T[] = [];\n for (let i = 0; i < a.length; i += coder.bytesLen)\n r.push(coder.decode(a.subarray(i, i + coder.bytesLen)));\n return r as TRet<T[]>;\n },\n } as any;\n}\n\n/**\n * Overwrites supported typed-array inputs with zeroes in place.\n * Accepts direct typed arrays and one-level arrays of them.\n * @param list - Typed arrays or one-level lists of typed arrays to clear.\n * @example\n * Overwrite typed arrays with zeroes.\n * ```ts\n * const buf = Uint8Array.of(1, 2, 3);\n * cleanBytes(buf);\n * ```\n */\nexport function cleanBytes(...list: (TypedArray | TypedArray[])[]): void {\n for (const t of list) {\n if (Array.isArray(t)) for (const b of t) b.fill(0);\n else t.fill(0);\n }\n}\n\n/**\n * Creates a 32-bit mask with the lowest `bits` bits set.\n * @param bits - Number of low bits to keep.\n * @returns Bit mask with `bits` ones.\n * @throws On wrong argument types. {@link TypeError}\n * @throws On wrong argument ranges or values. {@link RangeError}\n * @example\n * Create a low-bit mask for packed-field operations.\n * ```ts\n * const mask = getMask(4);\n * ```\n */\nexport function getMask(bits: number): number {\n anumber(bits, 'bits');\n if (bits > 32) throw new RangeError('\"bits\" expected <= 32, got ' + bits);\n // JS shifts are modulo 32, so bit 32 needs an explicit full-width mask.\n return bits === 32 ? 0xffffffff : ~(-1 << bits) >>> 0;\n}\n\n/** Shared empty byte array used as the default context. */\nexport const EMPTY: TRet<Uint8Array> = /* @__PURE__ */ Uint8Array.of();\n\n/**\n * Builds the domain-separated message payload for the pure sign/verify paths.\n * Context length `255` is valid; only `ctx.length > 255` is rejected.\n * @param msg - Message bytes.\n * @param ctx - Optional context bytes.\n * @returns Domain-separated message payload.\n * @throws On wrong argument ranges or values. {@link RangeError}\n * @example\n * Build the domain-separated payload before direct signing.\n * ```ts\n * const payload = getMessage(new Uint8Array([1, 2]));\n * ```\n */\nexport function getMessage(msg: TArg<Uint8Array>, ctx: TArg<Uint8Array> = EMPTY): TRet<Uint8Array> {\n abytes_(msg, undefined, 'msg');\n abytes_(ctx, undefined, 'ctx');\n if (ctx.length > 255) throw new RangeError('context should be 255 bytes or less');\n return concatBytes(new Uint8Array([0, ctx.length]), ctx, msg);\n}\n\n// DER tag+length plus the shared NIST hash OID arc 2.16.840.1.101.3.4.2.* used by the\n// FIPS 204 / FIPS 205 pre-hash wrappers; the final byte selects SHA-256, SHA-512, SHAKE128,\n// SHAKE256, or another approved hash/XOF under that subtree.\n// 06 09 60 86 48 01 65 03 04 02\nconst oidNistP = /* @__PURE__ */ Uint8Array.from([6, 9, 0x60, 0x86, 0x48, 1, 0x65, 3, 4, 2]);\n\n/**\n * Output length, in bytes, that each XOF OID under this arc denotes.\n *\n * Unlike a fixed hash, an XOF's OID is a promise about the digest length: RFC 8702\n * defines id-shake128 as SHAKE128 with 256-bit output and id-shake256 as SHAKE256 with\n * 512-bit output, and FIPS 204 / FIPS 205 use exactly those pairings for pre-hash. Both\n * bare noble-hashes defaults are half these values, so neither can be signed under its\n * own OID.\n */\nconst XOF_OID_OUTPUT_LEN: Record<string, number> = /* @__PURE__ */ (() => ({\n '060960864801650304020b': 32, // id-shake128, SHAKE128(M, 256)\n '060960864801650304020c': 64, // id-shake256, SHAKE256(M, 512)\n}))();\n\n/**\n * Validates that a hash exposes a NIST hash OID and enough collision resistance.\n * Current accepted surface is broader than the FIPS algorithm tables: any hash/XOF under the NIST\n * `2.16.840.1.101.3.4.2.*` subtree is accepted if its effective `outputLen` is strong enough.\n * XOF callers must pass a callable whose `outputLen` matches the digest length they actually intend\n * to sign; bare `shake128` / `shake256` defaults are too short for the stronger prehash modes.\n * @param hash - Hash function to validate.\n * @param requiredStrength - Minimum required collision-resistance strength in bits.\n * @throws If the hash metadata or collision resistance is insufficient. {@link Error}\n * @example\n * Validate that a hash exposes a NIST hash OID and enough collision resistance.\n * ```ts\n * import { sha256 } from '@noble/hashes/sha2.js';\n * import { checkHash } from '@noble/post-quantum/utils.js';\n * checkHash(sha256, 128);\n * ```\n */\nexport function checkHash(hash: CHash, requiredStrength: number = 0): void {\n if (typeof hash !== 'function' || typeof (hash as any).create !== 'function')\n throw new TypeError('\"hash\" expected hash function, got type=' + typeof hash);\n ahash_(hash);\n anumber(requiredStrength, 'requiredStrength');\n const oid = hash.oid as unknown as TArg<Uint8Array>;\n abytes_(oid, undefined, 'hash.oid');\n if (!equalBytes(oid.subarray(0, 10), oidNistP))\n throw new Error('\"hash.oid\" is invalid: expected NIST hash');\n // FIPS 204 / FIPS 205 require both collision and second-preimage strength; for approved NIST\n // hashes/XOFs under this OID subtree, the collision bound from the configured digest length is\n // the tighter runtime check, so enforce that lower bound here.\n // XOFs under this arc are identified by an OID that fixes their output length:\n // FIPS 204 §5.4.1 (SHAKE128) and FIPS 205 §10.2.2 (both SHAKEs), matching RFC 8702, pair\n // id-shake128 with SHAKE128(M, 256) and id-shake256 with SHAKE256(M, 512). getMessagePrehash embeds\n // hash.oid beside hash(msg), so a shorter digest signs an M' that claims a length\n // it does not have: noble-hashes' bare shake256 defaults to 32 bytes and cleared\n // the collision bound at the 128-bit level, producing signatures a conformant\n // verifier rejects because it recomputes 512 bits. Check the length the OID\n // denotes rather than the generic bound.\n const xofLen = XOF_OID_OUTPUT_LEN[bytesToHex(oid as Uint8Array)];\n if (xofLen !== undefined && hash.outputLen !== xofLen) {\n throw new Error(\n 'Pre-hash XOF output length must be ' + xofLen + ' bytes for this OID, got: ' + hash.outputLen\n );\n }\n const collisionResistance = (hash.outputLen * 8) / 2;\n if (requiredStrength > collisionResistance) {\n throw new Error(\n 'Pre-hash security strength too low: ' +\n collisionResistance +\n ', required: ' +\n requiredStrength\n );\n }\n}\n\n/**\n * Builds the domain-separated prehash payload for the prehash sign/verify paths.\n * Callers are expected to vet `hash.oid` first, e.g. via `checkHash(...)`; calling this helper\n * directly with a hash object that lacks `oid` currently throws later inside `concatBytes(...)`.\n * Context length `255` is valid; only `ctx.length > 255` is rejected.\n * @param hash - Prehash function.\n * @param msg - Message bytes.\n * @param ctx - Optional context bytes.\n * @returns Domain-separated prehash payload.\n * @throws On wrong argument ranges or values. {@link RangeError}\n * @example\n * Build the domain-separated prehash payload for external hashing.\n * ```ts\n * import { sha256 } from '@noble/hashes/sha2.js';\n * import { getMessagePrehash } from '@noble/post-quantum/utils.js';\n * getMessagePrehash(sha256, new Uint8Array([1, 2]));\n * ```\n */\nexport function getMessagePrehash(\n hash: CHash,\n msg: TArg<Uint8Array>,\n ctx: TArg<Uint8Array> = EMPTY\n): TRet<Uint8Array> {\n checkHash(hash);\n abytes_(msg, undefined, 'msg');\n abytes_(ctx, undefined, 'ctx');\n if (ctx.length > 255) throw new RangeError('context should be 255 bytes or less');\n const hashed = hash(msg);\n return concatBytes(new Uint8Array([1, ctx.length]), ctx, hash.oid!, hashed);\n}\n\n/**\n * Asserts something is a string.\n * @param value - Value to validate.\n * @param title - Label included in thrown errors.\n * @returns The validated string.\n * @throws On wrong argument types. {@link TypeError}\n * @example\n * Validate a label string.\n *\n * ```ts\n * astring('example', 'label');\n * ```\n */\nexport function astring(value: unknown, title: string = ''): string {\n if (typeof value !== 'string') {\n const prefix = title && `\"${title}\" `;\n throw new TypeError(prefix + 'expected string, got type=' + typeof value);\n }\n return value;\n}\n","/* eslint-disable -- vendored copy of @noble/post-quantum 0.7.1, kept as is: see PATCH.md */\n/**\n * ML-KEM: Module Lattice-based Key Encapsulation Mechanism from\n * [FIPS-203](https://csrc.nist.gov/pubs/fips/203/ipd). A.k.a. CRYSTALS-Kyber.\n *\n * Key encapsulation is similar to DH / ECDH (think X25519), with important differences:\n * * Unlike in ECDH, we can't verify if it was \"Bob\" who've sent the shared secret\n * * Unlike ECDH, it is probabalistic and relies on quality of randomness (CSPRNG).\n * * Decapsulation never throws an error, even when shared secret was\n * encrypted by a different public key. It will just return a different shared secret.\n *\n * There are some concerns with regards to security: see\n * [djb blog](https://blog.cr.yp.to/20231003-countcorrectly.html) and\n * [mailing list](https://groups.google.com/a/list.nist.gov/g/pqc-forum/c/W2VOzy0wz_E).\n *\n * Has similar internals to ML-DSA, but their keys and params are different.\n *\n * Check out [official site](https://www.pq-crystals.org/kyber/resources.shtml),\n * [repo](https://github.com/pq-crystals/kyber),\n * [spec](https://datatracker.ietf.org/doc/draft-cfrg-schwabe-kyber/).\n * @module\n */\n/*! noble-post-quantum - MIT License (c) 2024 Paul Miller (paulmillr.com) */\nimport { sha3_256, sha3_512, shake256 } from '@noble/hashes/sha3.js';\nimport { type CHash, swap32IfBE, u32 } from '@noble/hashes/utils.js';\nimport { genCrystals, type XOF, XOF128 } from './_crystals';\nimport {\n abytes,\n cleanBytes,\n type Coder,\n copyBytes,\n equalBytes,\n getMask,\n type KEM,\n randomBytes,\n splitCoder,\n type TArg,\n type TRet,\n vecCoder,\n} from './utils';\n\n/** Key encapsulation mechanism interface */\n\nconst N = 256; // Kyber (not FIPS-203) supports different lengths, but all std modes were using 256\nconst Q = 3329; // 13*(2**8)+1, modulo prime\nconst F = 3303; // 3303 ≡ 128**(−1) mod q (FIPS-203)\nconst ROOT_OF_UNITY = 17; // ζ = 17 ∈ Zq is a primitive 256-th root of unity modulo Q. ζ**128 ≡−1\n// treeshake: keep genCrystals behind the object so PARAMS-only bundles can drop it entirely.\n// Shared CRYSTALS helper in the ML-KEM branch: Kyber mode, 7-bit bit-reversal,\n// and Uint16Array polys because current coefficients stay reduced modulo q.\nconst crystals = /* @__PURE__ */ genCrystals({\n N,\n Q,\n F,\n ROOT_OF_UNITY,\n newPoly: (n: number): TRet<Uint16Array> => new Uint16Array(n) as TRet<Uint16Array>,\n brvBits: 7,\n isKyber: true,\n});\n\n/** FIPS 203: 7. Parameter Sets */\n/** Public ML-KEM parameter-set description. */\nexport type KEMParam = {\n /** Polynomial size. */\n N: number;\n /** Module rank. */\n K: number;\n /** Prime modulus. */\n Q: number;\n /** CBD parameter used for secret-key noise. */\n ETA1: number;\n /** CBD parameter used for error noise. */\n ETA2: number;\n /** Compression width for the `u` vector. */\n du: number;\n /** Compression width for the `v` polynomial. */\n dv: number;\n /** Required strength of the randomness source in bits. */\n RBGstrength: number;\n};\n/** Internal params of ML-KEM versions */\n// prettier-ignore\n/** Built-in ML-KEM parameter presets keyed by the public export names\n * `ml_kem512` / `ml_kem768` / `ml_kem1024`.\n * `RBGstrength` is Table 2's required randomness-source strength in bits,\n * not a generic security label.\n */\nexport const PARAMS: Record<string, KEMParam> = /* @__PURE__ */ (() =>\n Object.freeze({\n 512: Object.freeze({ N, Q, K: 2, ETA1: 3, ETA2: 2, du: 10, dv: 4, RBGstrength: 128 }),\n 768: Object.freeze({ N, Q, K: 3, ETA1: 2, ETA2: 2, du: 10, dv: 4, RBGstrength: 192 }),\n 1024: Object.freeze({ N, Q, K: 4, ETA1: 2, ETA2: 2, du: 11, dv: 5, RBGstrength: 256 }),\n } as const))();\n\n// FIPS-203: compress/decompress\nconst compress = (d: number): Coder<number, number> => {\n // d=12 is the ByteEncode12/ByteDecode12 path, not lossy compression.\n // ByteDecode12 interprets each 12-bit word modulo q; without that reduction the public-key\n // modulus check in encapsulate() becomes a no-op for malformed coefficients like 4095.\n if (d >= 12) return { encode: (i: number) => i, decode: (i: number) => (i >= Q ? i - Q : i) };\n // Comments map to python implementation in RFC (draft-cfrg-schwabe-kyber)\n // const round = (i: number) => Math.floor(i + 0.5) | 0;\n const a = 2 ** (d - 1);\n return {\n // This only matches standalone Compress_d after bitsCoder masks the result into Z_(2^d).\n encode: (i: number) => ((i << d) + Q / 2) / Q,\n // const decompress = (i: number) => round((Q / 2 ** d) * i);\n decode: (i: number) => (i * Q + a) >>> d,\n };\n};\n\n// Raw ByteEncode_d / ByteDecode_d from FIPS 203 operate on d-bit words directly.\n// That differs from `polyCoder(d)` for d<12, where noble folds packing together with the lossy\n// ciphertext compression step used by u/v. Tests that exercise the spec's raw packing surface need\n// this exact non-lossy variant instead.\nconst byteCoder = (d: number) =>\n crystals.bitsCoder(\n d,\n d === 12\n ? { encode: (i: number) => i, decode: (i: number) => (i >= Q ? i - Q : i) }\n : { encode: (i: number) => i, decode: (i: number) => i }\n );\n\n// NOTE: we merge encoding and compress because it is faster, also both require same d param\n// d=12 is the ByteEncode12/ByteDecode12 path rather than compression, and caller-side\n// public-key modulus checks route through this helper's decode/encode roundtrip.\n// Converts between bytes and d-bits compressed representation.\n// Kinda like convertRadix2 from @scure/base.\n// decode(encode(t)) == t, but there is loss of information on encode(decode(t))\nconst polyCoder = (d: number) => (d === 12 ? byteCoder(12) : crystals.bitsCoder(d, compress(d)));\n\n// Poly is mod Q, so 12 bits\ntype Poly = Uint16Array;\n\n// Coefficients always stay reduced in [0, Q) here (samplers, NTT and coders all reduce),\n// so one conditional correction replaces the generic mod().\nfunction polyAdd(a_: TArg<Poly>, b_: TArg<Poly>) {\n const a = a_ as Poly;\n const b = b_ as Poly;\n // Mutates `a` in place; callers must pass two N=256 polynomials.\n for (let i = 0; i < N; i++) {\n const r = a[i] + b[i]; // a += b\n a[i] = r >= Q ? r - Q : r;\n }\n}\nfunction polySub(a_: TArg<Poly>, b_: TArg<Poly>) {\n const a = a_ as Poly;\n const b = b_ as Poly;\n // Mutates `a` in place; callers must pass two N=256 polynomials.\n for (let i = 0; i < N; i++) {\n const r = a[i] - b[i]; // a -= b\n a[i] = r < 0 ? r + Q : r;\n }\n}\n\n// FIPS-203: Computes the product of two degree-one polynomials with respect to a quadratic modulus\nfunction BaseCaseMultiply(a0: number, a1: number, b0: number, b1: number, zeta: number) {\n // `zeta` here is Algorithm 11's γ = ζ^(2BitRev_7(i)+1).\n // Reduce a1*b1 before multiplying by zeta: a1*b1*zeta would reach ~2^35, forcing JS engines\n // into slow float fmod; with the extra reduction every intermediate fits int32.\n const c0 = crystals.mod(crystals.mod(a1 * b1) * zeta + a0 * b0);\n const c1 = crystals.mod(a0 * b1 + a1 * b0);\n return { c0, c1 };\n}\n\n// FIPS-203: Computes the product (in the ring Tq) of two NTT representations.\n// Works in place on `f`; `g` is read-only and both inputs must already be in NTT form.\nfunction MultiplyNTTs(f_: TArg<Poly>, g_: TArg<Poly>): TRet<Poly> {\n const f = f_ as Poly;\n const g = g_ as Poly;\n for (let i = 0; i < N / 2; i++) {\n let z = crystals.nttZetas[64 + (i >> 1)];\n if (i & 1) z = -z;\n const { c0, c1 } = BaseCaseMultiply(f[2 * i + 0], f[2 * i + 1], g[2 * i + 0], g[2 * i + 1], z);\n f[2 * i + 0] = c0;\n f[2 * i + 1] = c1;\n }\n return f as TRet<Poly>;\n}\n\ntype PRF = (l: number, key: Uint8Array, nonce: number) => Uint8Array;\n\n/**\n * Prepared (pre-expanded) ML-KEM public key. Experimental prototype.\n * Caches only public data: packed ek, the expanded matrix Â, decoded t̂ and H(ek). No secret\n * material is retained between calls; secret keys passed to `decapsulate` are decoded and wiped\n * per call, exactly like the one-shot API. `clean()` wipes the expanded Â/t̂ cache; the packed\n * public key and H(ek) are public and are not wiped. The object must not be used afterwards.\n */\nexport type KEMPrepared = {\n /**\n * Detached copy of the source public key. Treat as read-only while the prepared object is in use.\n * Callers may wipe it after final use; any mutation invalidates subsequent operations.\n */\n publicKey: Uint8Array;\n /** Same as `KEM.encapsulate`, minus per-call ek re-validation and  re-expansion. */\n encapsulate: (msg?: Uint8Array) => { cipherText: Uint8Array; sharedSecret: Uint8Array };\n /**\n * Same as `KEM.decapsulate`; throws if `secretKey` does not embed this public key.\n * The embedded-ek byte comparison plus stored-hash comparison is equivalent to the\n * FIPS 203 §7.3 hash input check.\n */\n decapsulate: (cipherText: Uint8Array, secretKey: Uint8Array) => Uint8Array;\n /** Wipe cached (public) data. */\n clean: () => void;\n};\n/** KEM with prepared-key support. */\nexport type MLKEM = KEM & { prepare: (publicKey: Uint8Array) => KEMPrepared };\n\ntype XofGet = ReturnType<ReturnType<XOF>['get']>;\n\ntype KyberOpts = KEMParam & {\n HASH256: CHash;\n HASH512: CHash;\n KDF: CHash<any, { dkLen?: number }>;\n XOF: XOF; // (seed: Uint8Array, len: number, x: number, y: number) => Uint8Array;\n PRF: PRF;\n};\n\n// Return poly in NTT representation\nfunction SampleNTT(xof_: TArg<XofGet>): TRet<Poly> {\n const xof = xof_ as XofGet;\n // The reader must already bind the Algorithm 7 seed||j||i bytes\n // and return block lengths divisible by 3.\n const r: Poly = new Uint16Array(N);\n for (let j = 0; j < N;) {\n const b = xof();\n if (b.length % 3) throw new Error('SampleNTT: unaligned block');\n for (let i = 0; j < N && i + 3 <= b.length; i += 3) {\n const d1 = ((b[i + 0] >> 0) | (b[i + 1] << 8)) & 0xfff;\n const d2 = ((b[i + 1] >> 4) | (b[i + 2] << 4)) & 0xfff;\n if (d1 < Q) r[j++] = d1;\n if (j < N && d2 < Q) r[j++] = d2;\n }\n }\n return r as TRet<Poly>;\n}\n\n// Sampling from the centered binomial distribution\n// Returns poly with small coefficients (noise/errors) stored modulo q in ordinary coefficient form.\n// Current callers only use Table 2 eta values {2,3} and PRF outputs of exactly 64*eta bytes.\nconst sampleCBDBytes = (buf: TArg<Uint8Array>, eta: number): TRet<Poly> => {\n const r: Poly = new Uint16Array(N);\n // CBD consumes the PRF bitstream in little-endian byte order; normalize the word view on BE,\n // then swap it back so callers still observe `buf` as read-only.\n const b32 = u32(buf);\n swap32IfBE(b32);\n let len = 0;\n for (let i = 0, p = 0, bb = 0, t0 = 0; i < b32.length; i++) {\n let b = b32[i];\n for (let j = 0; j < 32; j++) {\n bb += b & 1;\n b >>= 1;\n len += 1;\n if (len === eta) {\n t0 = bb;\n bb = 0;\n } else if (len === 2 * eta) {\n r[p++] = crystals.mod(t0 - bb);\n bb = 0;\n len = 0;\n }\n }\n }\n swap32IfBE(b32);\n if (len) throw new Error(`sampleCBD: leftover bits: ${len}`);\n return r as TRet<Poly>;\n};\n\nfunction sampleCBD(\n PRF_: TArg<PRF>,\n seed: TArg<Uint8Array>,\n nonce: number,\n eta: number\n): TRet<Poly> {\n const PRF = PRF_ as PRF;\n return sampleCBDBytes(PRF((eta * N) / 4, seed, nonce), eta);\n}\n\n// K-PKE\n// Internal ML-KEM subroutine only: exact 32-byte `seed` / `msg` inputs\n// come from Algorithms 13-15, and the helper mutates decoded temporary\n// polynomials in place while leaving caller byte arrays unchanged.\nconst genKPKE = (opts_: TArg<KyberOpts>) => {\n const opts = opts_ as KyberOpts;\n const { K, PRF, XOF, HASH512, ETA1, ETA2, du, dv } = opts;\n const poly1 = polyCoder(1);\n const polyV = polyCoder(dv);\n const polyU = polyCoder(du);\n const publicCoder = splitCoder('publicKey', vecCoder(polyCoder(12), K), 32);\n const secretCoder = vecCoder(polyCoder(12), K);\n const cipherCoder = splitCoder('ciphertext', vecCoder(polyU, K), polyV);\n const seedCoder = splitCoder('seed', 32, 32);\n // Algorithm 14 (K-PKE.Encrypt) core, after ek parsing. `tHat` and every poly returned by\n // `getA(i, j)` are treated as disposable scratch: they are mutated in place and wiped/dropped,\n // so callers holding cached copies must pass fresh copies.\n const encryptCore = (\n tHat: TArg<Poly[]>,\n getA: TArg<(i: number, j: number) => Poly>,\n msg: TArg<Uint8Array>,\n seed: TArg<Uint8Array>\n ): TRet<Uint8Array> => {\n const rHat = [];\n for (let i = 0; i < K; i++) rHat.push(crystals.NTT.encode(sampleCBD(PRF, seed, i, ETA1)));\n const tmp2 = new Uint16Array(N);\n const u = [];\n for (let i = 0; i < K; i++) {\n const e1 = sampleCBD(PRF, seed, K + i, ETA2);\n const tmp = new Uint16Array(N);\n for (let j = 0; j < K; j++) {\n const aij = getA(i, j); // A[j][i], inplace transpose access\n polyAdd(tmp, MultiplyNTTs(aij, rHat[j])); // t += aij * rHat[j]\n }\n polyAdd(e1, crystals.NTT.decode(tmp)); // e1 += tmp\n u.push(e1);\n polyAdd(tmp2, MultiplyNTTs(tHat[i], rHat[i])); // t2 += tHat[i] * rHat[i]\n cleanBytes(tmp);\n }\n const e2 = sampleCBD(PRF, seed, 2 * K, ETA2);\n polyAdd(e2, crystals.NTT.decode(tmp2)); // e2 += tmp2\n const v = poly1.decode(msg); // encode plaintext m into polynomial v\n polyAdd(v, e2); // v += e2\n cleanBytes(tHat, rHat, tmp2, e2);\n return cipherCoder.encode([u, v]) as TRet<Uint8Array>;\n };\n return {\n secretCoder,\n lengths: {\n secretKey: secretCoder.bytesLen,\n publicKey: publicCoder.bytesLen,\n cipherText: cipherCoder.bytesLen,\n },\n keygen: (seed: TArg<Uint8Array>) => {\n abytes(seed, 32, 'seed');\n const seedDst = new Uint8Array(33);\n seedDst.set(seed);\n // FIPS 203 Algorithm 13 appends the parameter-set byte `k`\n // before `G(d || k)`, so expanding the same 32-byte seed\n // under a different ML-KEM parameter set yields unrelated keys.\n seedDst[32] = K;\n const seedHash = HASH512(seedDst);\n\n const [rho, sigma] = seedCoder.decode(seedHash);\n const sHat: Poly[] = [];\n const tHat: Poly[] = [];\n for (let i = 0; i < K; i++) sHat.push(crystals.NTT.encode(sampleCBD(PRF, sigma, i, ETA1)));\n const x = XOF(rho);\n for (let i = 0; i < K; i++) {\n const e = crystals.NTT.encode(sampleCBD(PRF, sigma, K + i, ETA1));\n for (let j = 0; j < K; j++) {\n const aji = SampleNTT(x.get(j, i)); // A[i][j], inplace\n polyAdd(e, MultiplyNTTs(aji, sHat[j]));\n }\n tHat.push(e); // t ← A ◦ s + e\n }\n x.clean();\n const res = {\n publicKey: publicCoder.encode([tHat, rho]),\n secretKey: secretCoder.encode(sHat),\n };\n cleanBytes(rho, sigma, sHat, tHat, seedDst, seedHash);\n return res;\n },\n encrypt: (\n publicKey: TArg<Uint8Array>,\n msg: TArg<Uint8Array>,\n seed: TArg<Uint8Array>\n ): TRet<Uint8Array> => {\n const [tHat, rho] = publicCoder.decode(publicKey);\n const x = XOF(rho);\n const res = encryptCore(tHat as Poly[], (i, j) => SampleNTT(x.get(i, j)) as Poly, msg, seed);\n x.clean();\n return res;\n },\n // Expands the full  matrix (public data derived from rho) once, so repeated encryptions\n // against the same ek skip the K² SampleNTT XOF expansions. Cached polys are copied per\n // call because encryptCore mutates its inputs in place.\n prepare: (publicKey: TArg<Uint8Array>) => {\n const [tHat, rho] = publicCoder.decode(publicKey);\n const x = XOF(rho);\n const A: Poly[] = [];\n for (let i = 0; i < K; i++)\n for (let j = 0; j < K; j++) A.push(SampleNTT(x.get(i, j)) as Poly);\n x.clean();\n return {\n encrypt: (msg: TArg<Uint8Array>, seed: TArg<Uint8Array>): TRet<Uint8Array> =>\n encryptCore(\n (tHat as Poly[]).map((p) => p.slice() as Poly),\n (i, j) => A[i * K + j].slice() as Poly,\n msg,\n seed\n ),\n clean: () => cleanBytes(tHat as Poly[], A),\n };\n },\n decrypt: (cipherText: TArg<Uint8Array>, privateKey: TArg<Uint8Array>): TRet<Uint8Array> => {\n const [u, v] = cipherCoder.decode(cipherText);\n const sk = secretCoder.decode(privateKey); // s ← ByteDecode_12(dkPKE)\n const tmp = new Uint16Array(N);\n // tmp += sk[i] * u[i]\n for (let i = 0; i < K; i++) polyAdd(tmp, MultiplyNTTs(sk[i], crystals.NTT.encode(u[i])));\n polySub(v, crystals.NTT.decode(tmp)); // w = v' - tmp\n // `v` now holds w, from which the plaintext is just a 1-bit threshold away, so wipe it too.\n // encode() allocates its own buffer, so the returned bytes do not alias `v`.\n const res = poly1.encode(v) as TRet<Uint8Array>;\n cleanBytes(tmp, sk, u, v);\n return res;\n },\n };\n};\n\n/**\n * Public ML-KEM wrapper over the internal K-PKE subroutine.\n * `keygen(seed)` and `encapsulate(publicKey, msg)` are deterministic/test-oriented hooks that map\n * more directly to Algorithms 16-17 than to the pure no-input / random-internal Algorithms 19-20.\n * `encapsulate`'s optional `msg` is the 32-byte message randomness `m` of Algorithm 17, the\n * pre-image the shared secret is derived from, NOT a plaintext to encrypt: ML-KEM is a key\n * encapsulation mechanism, not a cipher. Omit it to draw fresh randomness; pass it only to\n * reproduce a known-answer vector, and only as 32 uniformly random bytes, since a low-entropy or\n * reused value makes the shared secret predictable. The same holds for `keygen`'s optional `seed`.\n * decapsulate() tries to follow the Algorithms 18/21 implicit-reject structure as closely as\n * practical here by re-encrypting, comparing ciphertexts, returning `Khat` on match or `Kbar` on\n * mismatch, and zeroizing the non-returned shared-secret candidate; JS/JIT still provides no\n * constant-time guarantees for that path.\n */\nfunction createKyber(opts: TArg<KyberOpts>): TRet<MLKEM> {\n const rawOpts = opts as KyberOpts;\n const KPKE = genKPKE(rawOpts);\n const { HASH256, HASH512, KDF } = rawOpts;\n const { secretCoder: KPKESecretCoder, lengths } = KPKE;\n const secretCoder = splitCoder('secretKey', lengths.secretKey, lengths.publicKey, 32, 32);\n const msgLen = 32;\n const seedLen = 64;\n // FIPS-203 includes additional verification check for modulus\n const validateModulus = (publicKey: TArg<Uint8Array>, fn: string) => {\n const eke = (publicKey as Uint8Array).subarray(0, 384 * rawOpts.K);\n // Copy because of inplace encoding\n const ek = KPKESecretCoder.encode(KPKESecretCoder.decode(copyBytes(eke)));\n // (Modulus check.) Perform the computation ek ← ByteEncode12(ByteDecode12(eke)).\n // If ek = ̸ eke, the input is invalid. (See Section 4.2.1.)\n const ok = equalBytes(ek, eke);\n cleanBytes(ek);\n if (!ok) throw new Error(`ML-KEM.${fn}: wrong publicKey modulus`);\n };\n const kemLengths = Object.freeze({\n ...lengths,\n seed: 64,\n msg: msgLen,\n msgRand: msgLen,\n secretKey: secretCoder.bytesLen,\n });\n return Object.freeze({\n info: Object.freeze({ type: 'ml-kem' }),\n lengths: kemLengths,\n keygen: (seed?: TArg<Uint8Array>) => {\n // A generated seed carries z (the implicit-rejection secret) and must be wiped once the\n // secret key holds a copy, matching ml-dsa / slh-dsa / falcon keygen. A caller-supplied\n // seed is the caller's to manage (and the immutability test requires it stay untouched).\n const ownSeed = seed === undefined;\n const s = ownSeed ? randomBytes(seedLen) : (seed as TArg<Uint8Array>);\n let sk: Uint8Array | undefined;\n let publicKeyHash: Uint8Array | undefined;\n try {\n abytes(s, seedLen, 'seed');\n const keys = KPKE.keygen(s.subarray(0, 32));\n const publicKey = keys.publicKey;\n sk = keys.secretKey as Uint8Array;\n publicKeyHash = HASH256(publicKey);\n // (dkPKE||ek||H(ek)||z)\n const secretKey = secretCoder.encode([sk, publicKey, publicKeyHash, s.subarray(32)]);\n return {\n publicKey: publicKey as TRet<Uint8Array>,\n secretKey: secretKey as TRet<Uint8Array>,\n };\n } finally {\n if (sk !== undefined) cleanBytes(sk);\n if (publicKeyHash !== undefined) cleanBytes(publicKeyHash);\n if (ownSeed) cleanBytes(s);\n }\n },\n getPublicKey: (secretKey: TArg<Uint8Array>): TRet<Uint8Array> => {\n const [_sk, publicKey, _publicKeyHash, _z] = secretCoder.decode(secretKey);\n return Uint8Array.from(publicKey) as TRet<Uint8Array>;\n },\n encapsulate: (publicKey: TArg<Uint8Array>, msg?: TArg<Uint8Array>) => {\n // A generated message is the preimage of the shared secret (K = G(m || H(ek))[0:32]) and\n // must be wiped. A caller-supplied message is the deterministic-randomness hook and the\n // caller's to manage (the immutability test requires it stay untouched).\n const ownMsg = msg === undefined;\n const m = ownMsg ? randomBytes(msgLen) : (msg as TArg<Uint8Array>);\n let kr: Uint8Array | undefined;\n try {\n abytes(publicKey, lengths.publicKey, 'publicKey');\n abytes(m, msgLen, 'message');\n validateModulus(publicKey, 'encapsulate');\n // derive randomness\n kr = HASH512.create().update(m).update(HASH256(publicKey)).digest();\n const cipherText = KPKE.encrypt(publicKey, m, kr.subarray(32, 64));\n return {\n cipherText: cipherText as TRet<Uint8Array>,\n sharedSecret: kr.subarray(0, 32) as TRet<Uint8Array>,\n };\n } finally {\n if (kr !== undefined) cleanBytes(kr.subarray(32));\n if (ownMsg) cleanBytes(m);\n }\n },\n decapsulate: (cipherText: TArg<Uint8Array>, secretKey: TArg<Uint8Array>): TRet<Uint8Array> => {\n abytes(secretKey, secretCoder.bytesLen, 'secretKey'); // 768*k + 96\n abytes(cipherText, lengths.cipherText, 'cipherText'); // 32(du*k + dv)\n // test ← H(dk[384𝑘 ∶ 768𝑘 + 32])) .\n const k768 = secretCoder.bytesLen - 96;\n const start = k768 + 32;\n const test = HASH256(secretKey.subarray(k768 / 2, start));\n // If test ≠ dk[768𝑘 + 32 ∶ 768𝑘 + 64], then input checking has failed.\n if (!equalBytes(test, secretKey.subarray(start, start + 32)))\n throw new Error('invalid secretKey: hash check failed');\n const [sk, publicKey, publicKeyHash, z] = secretCoder.decode(secretKey);\n const msg = KPKE.decrypt(cipherText, sk);\n // derive randomness, Khat, rHat = G(mHat || h)\n const kr = HASH512.create().update(msg).update(publicKeyHash).digest();\n const Khat = kr.subarray(0, 32);\n // re-encrypt using the derived randomness\n const cipherText2 = KPKE.encrypt(publicKey, msg, kr.subarray(32, 64));\n // if ciphertexts do not match, “implicitly reject”\n const isValid = equalBytes(cipherText, cipherText2);\n const Kbar = KDF.create({ dkLen: 32 }).update(z).update(cipherText).digest();\n // kr[32:64] is the derived K-PKE encryption randomness: wipe it like encapsulate() does.\n cleanBytes(msg, cipherText2, kr.subarray(32), !isValid ? Khat : Kbar);\n return (isValid ? Khat : Kbar) as TRet<Uint8Array>;\n },\n /**\n * Experimental prototype: pre-expand a public key so repeated encapsulate/decapsulate\n * against the same key skip re-validation, H(ek), t̂ decoding and the K² SampleNTT\n * XOF expansions of Â. Only public data is cached; see {@link KEMPrepared}.\n */\n prepare: (publicKey: TArg<Uint8Array>): TRet<KEMPrepared> => {\n abytes(publicKey, lengths.publicKey, 'publicKey');\n validateModulus(publicKey, 'prepare');\n const ek = copyBytes(publicKey); // detach from the caller before caching\n const publicKeyHash = HASH256(ek);\n const cached = KPKE.prepare(ek);\n return Object.freeze({\n publicKey: ek as TRet<Uint8Array>,\n encapsulate: (msg?: TArg<Uint8Array>) => {\n // As in the non-prepared encapsulate: a generated message is the shared-secret\n // preimage and is wiped; a caller-supplied one is left untouched.\n const ownMsg = msg === undefined;\n const m = ownMsg ? randomBytes(msgLen) : (msg as TArg<Uint8Array>);\n let kr: Uint8Array | undefined;\n try {\n abytes(m, msgLen, 'message');\n kr = HASH512.create().update(m).update(publicKeyHash).digest();\n const cipherText = cached.encrypt(m, kr.subarray(32, 64));\n return {\n cipherText: cipherText as TRet<Uint8Array>,\n sharedSecret: kr.subarray(0, 32) as TRet<Uint8Array>,\n };\n } finally {\n if (kr !== undefined) cleanBytes(kr.subarray(32));\n if (ownMsg) cleanBytes(m);\n }\n },\n decapsulate: (\n cipherText: TArg<Uint8Array>,\n secretKey: TArg<Uint8Array>\n ): TRet<Uint8Array> => {\n abytes(secretKey, secretCoder.bytesLen, 'secretKey');\n abytes(cipherText, lengths.cipherText, 'cipherText');\n const [sk, ekEmbedded, storedHash, z] = secretCoder.decode(secretKey);\n // Under KEMPrepared's read-only publicKey contract, bind dk to the prepared key.\n // Together with publicKeyHash = H(ek) computed in prepare(), this is equivalent to (and\n // stronger than) FIPS 203 §7.3's `H(dk[384k : 768k+32]) == dk[768k+32 : 768k+64]`.\n if (!equalBytes(ekEmbedded, ek) || !equalBytes(storedHash, publicKeyHash))\n throw new Error('ML-KEM.decapsulate: secretKey does not match prepared publicKey');\n const msg = KPKE.decrypt(cipherText, sk);\n // derive randomness, Khat, rHat = G(mHat || h)\n const kr = HASH512.create().update(msg).update(publicKeyHash).digest();\n const Khat = kr.subarray(0, 32);\n // re-encrypt using the derived randomness and cached Â/t̂\n const cipherText2 = cached.encrypt(msg, kr.subarray(32, 64));\n // if ciphertexts do not match, “implicitly reject”\n const isValid = equalBytes(cipherText, cipherText2);\n const Kbar = KDF.create({ dkLen: 32 }).update(z).update(cipherText).digest();\n cleanBytes(msg, cipherText2, kr.subarray(32), !isValid ? Khat : Kbar);\n return (isValid ? Khat : Kbar) as TRet<Uint8Array>;\n },\n clean: cached.clean,\n }) as TRet<KEMPrepared>;\n },\n });\n}\n\n// FIPS 203's PRF_eta binding: current callers use only 32-byte keys, one-byte nonces,\n// and dkLen values {128, 192}; out-of-range nonce numbers still wrap modulo 256 here.\nfunction shakePRF(dkLen: number, key: TArg<Uint8Array>, nonce: number): TRet<Uint8Array> {\n return shake256\n .create({ dkLen })\n .update(key)\n .update(new Uint8Array([nonce]))\n .digest() as TRet<Uint8Array>;\n}\n\n// Fixed ML-KEM hash/XOF bindings. `KDF` here is the spec's fixed 32-byte `J` call,\n// and swapping any field changes the scheme rather than tuning an internal dependency.\nconst opts = /* @__PURE__ */ (() => ({\n HASH256: sha3_256,\n HASH512: sha3_512,\n KDF: shake256,\n XOF: XOF128,\n PRF: shakePRF,\n}))();\n// Parameter-set instantiation step for the spec's \"ML-KEM-x\" names; current correctness relies\n// on the internal PARAMS rows rather than local validation of arbitrary KEMParam objects.\nconst mk = (params: KEMParam) =>\n createKyber({\n ...opts,\n ...params,\n });\n\n/**\n * ML-KEM-512: Table 2 row `k=2, η1=3, η2=2, du=10, dv=4`; Table 3 sizes `800/1632/768/32`.\n * The ASD lifecycle note here is external policy guidance, not a FIPS 203 requirement.\n * @example\n * Generate deterministic ML-KEM-512 keys, encapsulate a shared secret, and decapsulate it.\n * ```ts\n * import { ml_kem512 } from '@noble/post-quantum/ml-kem.js';\n * const seed = new Uint8Array(ml_kem512.lengths.seed!);\n * const { secretKey, publicKey } = ml_kem512.keygen(seed);\n * const msg = new Uint8Array(ml_kem512.lengths.msgRand!);\n * const { cipherText, sharedSecret } = ml_kem512.encapsulate(publicKey, msg);\n * const recovered = ml_kem512.decapsulate(cipherText, secretKey);\n * const publicKey2 = ml_kem512.getPublicKey(secretKey);\n * ```\n */\nexport const ml_kem512: TRet<MLKEM> = /* @__PURE__ */ (() => mk(PARAMS[512]))();\n/**\n * ML-KEM-768: Table 2 row `k=3, η1=2, η2=2, du=10, dv=4`; Table 3 sizes `1184/2400/1088/32`.\n * The ASD lifecycle note here is external policy guidance, not a FIPS 203 requirement.\n */\nexport const ml_kem768: TRet<MLKEM> = /* @__PURE__ */ (() => mk(PARAMS[768]))();\n/**\n * ML-KEM-1024: Table 2 row `k=4, η1=2, η2=2, du=11, dv=5`; Table 3 sizes `1568/3168/1568/32`.\n * The ASD lifecycle note here is external policy guidance, not a FIPS 203 requirement.\n */\nexport const ml_kem1024: TRet<MLKEM> = /* @__PURE__ */ (() => mk(PARAMS[1024]))();\n\n// NOTE: for tests only, don't use. This keeps the exact internal ML-KEM math surfaces available\n// without re-implementing them in separate test code.\nexport const __tests: any = /* @__PURE__ */ (() =>\n Object.freeze({\n Compress_d: (x: number, d: number) => {\n if (d < 1 || d > 11) throw new Error(`Compress_d: expected d in [1..11], got ${d}`);\n return compress(d).encode(x) & getMask(d);\n },\n Decompress_d: (y: number, d: number) => {\n if (d < 1 || d > 11) throw new Error(`Decompress_d: expected d in [1..11], got ${d}`);\n return compress(d).decode(y);\n },\n ByteEncode_d: (F: TArg<Uint16Array>, d: number) => {\n if (d < 1 || d > 12) throw new Error(`ByteEncode_d: expected d in [1..12], got ${d}`);\n return byteCoder(d).encode(F as TRet<Uint16Array>);\n },\n ByteDecode_d: (B: TArg<Uint8Array>, d: number) => {\n if (d < 1 || d > 12) throw new Error(`ByteDecode_d: expected d in [1..12], got ${d}`);\n return byteCoder(d).decode(B);\n },\n NTT: (f: TArg<Uint16Array>) => crystals.NTT.encode(Uint16Array.from(f)),\n NTT_inv: (fHat: TArg<Uint16Array>) => crystals.NTT.decode(Uint16Array.from(fHat)),\n MultiplyNTTs: (fHat: TArg<Uint16Array>, gHat: TArg<Uint16Array>) =>\n MultiplyNTTs(Uint16Array.from(fHat), Uint16Array.from(gHat)),\n SamplePolyCBD: (B: TArg<Uint8Array>, eta: number) => {\n abytes(B, 64 * eta, 'B');\n return sampleCBDBytes(B, eta);\n },\n SampleNTT: (B: TArg<Uint8Array>) => {\n abytes(B, 34, 'B');\n const xof = XOF128(B.subarray(0, 32));\n try {\n return SampleNTT(xof.get(B[32], B[33]));\n } finally {\n xof.clean();\n }\n },\n }))();\n","import { falcon512 } from './noble/falcon';\n\n/**\n * Falcon-512 primitives used by the S2morrow layer (NIST key formats). `nobleEngine` is the only\n * implementation: this interface keeps the rest of `starknet/falcon` independent from the place the\n * Falcon code comes from.\n */\nexport interface FalconEngine {\n /**\n * New key pair.\n * @param {Uint8Array} [seed] 48 random bytes; by default, drawn by noble\n * @returns {{ secretKey: Uint8Array; publicKey: Uint8Array }} the NIST secret key (1281 bytes)\n * and the NIST public key (897 bytes)\n * @example\n * ```typescript\n * const result = nobleEngine.keygen(new Uint8Array(48).fill(1));\n * // result = { secretKey: Uint8Array(1281) [89, 0, 31, 1, 255, 255, …],\n * // publicKey: Uint8Array(897) [9, 100, 145, 86, 69, 182, …] }\n * ```\n */\n keygen(seed?: Uint8Array): { secretKey: Uint8Array; publicKey: Uint8Array };\n /**\n * Public key of a NIST secret key. Not used by the signer, which computes h = g / f itself: kept\n * to cross-check that code in the tests.\n * @param {Uint8Array} secretKey the NIST secret key (1281 bytes)\n * @returns {Uint8Array} the NIST public key (897 bytes)\n * @example\n * ```typescript\n * const { secretKey } = nobleEngine.keygen(new Uint8Array(48).fill(1));\n * const result = nobleEngine.getPublicKey(secretKey);\n * // result = Uint8Array(897) [9, 100, 145, 86, 69, 182, …]\n * ```\n */\n getPublicKey(secretKey: Uint8Array): Uint8Array;\n /**\n * Signs a hash point. Draws a new sampler seed at each call.\n * @param {Uint16Array} hashPoint the 512 coefficients of the hash point, in [0, q)\n * @param {Uint8Array} secretKey the NIST secret key (1281 bytes)\n * @returns {Int16Array} s2, the 512 coefficients that the signature carries (the S2morrow\n * account names this polynomial s1)\n * @example\n * ```typescript\n * const hashPoint = hashToPoint([42n], [1n, 2n]);\n * const result = nobleEngine.signHashPoint(hashPoint, secretKey);\n * // result = Int16Array(512) [-248, -33, -9, -221, …] (random: a new sampler seed at each call)\n * ```\n */\n signHashPoint(hashPoint: Uint16Array, secretKey: Uint8Array): Int16Array;\n /**\n * Checks s2 against a hash point, with the norm check of noble. Not used by the signer, which\n * checks the equation of the S2morrow account instead: kept for the tests.\n * @param {Int16Array} s2 the 512 coefficients returned by `signHashPoint`\n * @param {Uint16Array} hashPoint the 512 coefficients of the hash point, in [0, q)\n * @param {Uint8Array} publicKey the NIST public key (897 bytes)\n * @returns {boolean} true when s2 is a valid signature of the hash point\n * @example\n * ```typescript\n * const s2 = nobleEngine.signHashPoint(hashPoint, secretKey);\n * const result = nobleEngine.verifyHashPoint(s2, hashPoint, publicKey);\n * // result = true\n * ```\n */\n verifyHashPoint(s2: Int16Array, hashPoint: Uint16Array, publicKey: Uint8Array): boolean;\n}\n\n/**\n * The engine of `starknet/falcon`, backed by a copy of `@noble/post-quantum` 0.7.1. This file is\n * the only one of `src/falcon/` that imports the copy.\n *\n * What is copied: `noble/falcon.ts`, `noble/ml-kem.ts`, `noble/_crystals.ts`, `noble/utils.ts` and\n * `noble/LICENSE` (MIT, Paul Miller), from the npm package `@noble/post-quantum@0.7.1`. The copy\n * adds one thing: `falcon512.internal`, with `sign(hashPoint, secretKey)` and\n * `verify(s2, hashPoint, publicKey)`.\n * noble 0.7.1 computes the hash point itself, with SHAKE256, inside `genFalcon`; the S2morrow\n * account needs a Poseidon hash point, computed by `s2morrow/hashToPoint.ts`. `noble/PATCH.md`\n * lists the changes, the exact diff and the SHA-256 of each copied file, checked by\n * `__tests__/utils/falcon/vendor.test.ts`. ESLint and Prettier skip the copy.\n *\n * Why a copy: this API is proposed to noble in\n * https://github.com/paulmillr/noble-post-quantum/pull/55, not merged yet (2026-10-16).\n *\n * The switch, once noble publishes this API:\n * 1. `package.json`: add `@noble/post-quantum` to the dependencies, and remove `@noble/ciphers`\n * (only the copy imports it; noble brings its own).\n * 2. Here: import `falcon512` from `@noble/post-quantum/falcon.js`, and adapt the four functions\n * below if the published names differ. Import `ml_kem768` from `@noble/post-quantum/ml-kem.js`.\n * 3. Delete the folder `noble/`, its line in `.prettierignore` (and the file, if no other line is\n * left), the test `__tests__/utils/falcon/vendor.test.ts`, and the point \"Traceable vendored\n * code\" of `src/falcon/SECURITY.md`.\n * 4. Tests: in `engine.test.ts`, `keys.test.ts` and `signature.test.ts`, import `falcon512` from\n * `@noble/post-quantum/falcon.js`; `engine.test.ts` checks the patched API: adapt it to the\n * published one. In `boundaries.test.ts`, replace `@noble/ciphers` with `@noble/post-quantum`.\n * 5. Docs: remove the mention of the copy from the JSDoc of `Falcon512Signer` and from the module\n * comment of `src/falcon/index.ts`.\n *\n * The public API of `starknet/falcon` does not change, and the other tests pass unchanged.\n */\nexport const nobleEngine: FalconEngine = Object.freeze({\n keygen: (seed?: Uint8Array) => falcon512.keygen(seed),\n getPublicKey: (secretKey: Uint8Array) => falcon512.getPublicKey(secretKey),\n signHashPoint: (hashPoint: Uint16Array, secretKey: Uint8Array) =>\n falcon512.internal.sign(hashPoint, secretKey),\n verifyHashPoint: (s2: Int16Array, hashPoint: Uint16Array, publicKey: Uint8Array) =>\n falcon512.internal.verify(s2, hashPoint, publicKey),\n});\n\n// ML-KEM-768 (FIPS 203), for the `mlkem` key exchange. Same copy of noble 0.7.1, with no change to\n// its code: its API is the one of the npm package.\nexport { ml_kem768 } from './noble/ml-kem';\n","// NTT roots of x^n + 1 mod q, falcon.py convention, for n = 2, 4, ..., 512 (offset n - 2).\n// Copied from falcon-rs src/constants.rs (NTT_ROOTS_ALL, commit fbf38fe);\n// checked by __tests__/utils/falcon/ntt.test.ts.\nexport const NTT_ROOTS_ALL: readonly number[] = Object.freeze([\n 1479, 10810, 4043, 8246, 5146, 7143, 5736, 6553, 4134, 8155, 722, 11567, 1305, 10984, 1646, 10643,\n 1212, 11077, 5860, 6429, 3195, 9094, 2545, 9744, 3621, 8668, 3504, 8785, 3542, 8747, 4591, 7698,\n 5728, 6561, 5023, 7266, 5828, 6461, 4978, 7311, 1351, 10938, 3328, 8961, 5777, 6512, 2975, 9314,\n 563, 11726, 3006, 9283, 2744, 9545, 949, 11340, 2625, 9664, 4821, 7468, 2639, 9650, 1000, 11289,\n 4320, 7969, 3091, 9198, 81, 12208, 2963, 9326, 4896, 7393, 3051, 9238, 2366, 9923, 1853, 10436,\n 140, 12149, 4611, 7678, 726, 11563, 4255, 8034, 1177, 11112, 2768, 9521, 1635, 10654, 3712, 8577,\n 3135, 9154, 2747, 9542, 4846, 7443, 3553, 8736, 4805, 7484, 2294, 9995, 1062, 11227, 1326, 10963,\n 5086, 7203, 3014, 9275, 3201, 9088, 1170, 11119, 2319, 9970, 955, 11334, 790, 11499, 544, 11745,\n 5791, 6498, 339, 11950, 2468, 9821, 2842, 9447, 480, 11809, 9, 12280, 1022, 11267, 4278, 8011,\n 1673, 10616, 4989, 7300, 5331, 6958, 3584, 8705, 4177, 8112, 1381, 10908, 2525, 9764, 2396, 9893,\n 4452, 7837, 3296, 8993, 3949, 8340, 130, 12159, 4354, 7935, 5374, 6915, 2837, 9452, 5767, 6522,\n 827, 11462, 3748, 8541, 953, 11336, 5067, 7222, 2197, 10092, 118, 12171, 2476, 9813, 2548, 9741,\n 4231, 8058, 355, 11934, 3382, 8907, 3707, 8582, 1759, 10530, 3694, 8595, 5179, 7110, 5542, 6747,\n 145, 12144, 3637, 8652, 3459, 8830, 5911, 6378, 4890, 7399, 3932, 8357, 2731, 9558, 2089, 10200,\n 5092, 7197, 2881, 9408, 3284, 9005, 729, 11560, 3241, 9048, 3289, 9000, 2013, 10276, 5755, 6534,\n 4632, 7657, 1260, 11029, 4388, 7901, 334, 11955, 2426, 9863, 1696, 10593, 1428, 10861, 1663,\n 10626, 1777, 10512, 1426, 10863, 4654, 7635, 5291, 6998, 2704, 9585, 4938, 7351, 3636, 8653, 3915,\n 8374, 2166, 10123, 113, 12176, 4919, 7370, 3, 12286, 4437, 7852, 160, 12129, 3149, 9140, 4057,\n 8232, 3271, 9018, 1689, 10600, 3364, 8925, 4372, 7917, 2174, 10115, 4414, 7875, 2847, 9442, 2645,\n 9644, 4053, 8236, 2305, 9984, 5042, 7247, 5195, 7094, 2780, 9509, 1484, 10805, 4895, 7394, 3016,\n 9273, 243, 12046, 3000, 9289, 671, 11618, 3136, 9153, 5191, 7098, 2399, 9890, 3400, 8889, 2178,\n 10111, 1544, 10745, 420, 11869, 5559, 6730, 476, 11813, 3531, 8758, 3985, 8304, 4905, 7384, 5332,\n 6957, 3510, 8779, 2370, 9919, 2865, 9424, 2969, 9320, 3978, 8311, 2686, 9603, 3247, 9042, 4048,\n 8241, 2249, 10040, 1153, 11136, 2884, 9405, 5407, 6882, 3186, 9103, 1630, 10659, 2126, 10163,\n 2187, 10102, 2566, 9723, 2422, 9867, 6039, 6250, 2987, 9302, 6022, 6267, 2437, 9852, 3646, 8643,\n 875, 11414, 3780, 8509, 1607, 10682, 4976, 7313, 5011, 7278, 1002, 11287, 4284, 8005, 5088, 7201,\n 3248, 9041, 1207, 11082, 1168, 11121, 5277, 7012, 1065, 11224, 2143, 10146, 404, 11885, 4645,\n 7644, 1912, 10377, 1378, 10911, 435, 11854, 4337, 7952, 2381, 9908, 5444, 6845, 4096, 8193, 493,\n 11796, 545, 11744, 5019, 7270, 3704, 8585, 2678, 9611, 1537, 10752, 242, 12047, 4714, 7575, 4143,\n 8146, 27, 12262, 3066, 9223, 3763, 8526, 1440, 10849, 5084, 7205, 1632, 10657, 1017, 11272, 4885,\n 7404, 3778, 8511, 3833, 8456, 390, 11899, 773, 11516, 2401, 9888, 442, 11847, 5101, 7188, 1067,\n 11222, 2912, 9377, 5698, 6591, 354, 11935, 4861, 7428, 2859, 9430, 1045, 11244, 5012, 7277, 2481,\n 9808, 3957, 8332, 2839, 9450, 2127, 10162, 151, 12138, 431, 11858, 1579, 10710, 5906, 6383, 2505,\n 9784, 1323, 10966, 2766, 9523, 52, 12237, 3174, 9115, 6055, 6234, 3336, 8953, 677, 11612, 5874,\n 6415, 4169, 8120, 3127, 9162, 5241, 7048, 2920, 9369, 1010, 11279, 5468, 6821, 787, 11502, 3482,\n 8807, 1321, 10968, 192, 12097, 4912, 7377, 2049, 10240, 4698, 7591, 5057, 7232, 4780, 7509, 3445,\n 8844, 1956, 10333, 5009, 7280, 6008, 6281, 885, 11404, 3532, 8757, 1003, 11286, 58, 12231, 241,\n 12048, 975, 11314, 4212, 8077, 2844, 9445, 3438, 8851, 1105, 11184, 142, 12147, 5681, 6608, 3477,\n 8812, 2302, 9987, 605, 11684, 4213, 8076, 504, 11785, 5886, 6403, 4782, 7507, 5594, 6695, 3029,\n 9260, 421, 11868, 4080, 8209, 6068, 6221, 3602, 8687, 6077, 6212, 4624, 7665, 3263, 9026, 3600,\n 8689, 4948, 7341, 6137, 6152, 400, 11889, 1728, 10561, 5862, 6427, 6136, 6153, 5415, 6874, 3643,\n 8646, 56, 12233, 3199, 9090, 5206, 7083, 5529, 6760, 3565, 8724, 654, 11635, 1987, 10302, 1702,\n 10587, 3988, 8301, 468, 11821, 316, 11973, 382, 11907, 3710, 8579, 6093, 6196, 5446, 6843, 5339,\n 6950, 973, 11316, 1254, 11035, 1359, 10930, 5435, 6854, 2033, 10256, 3998, 8291, 3879, 8410, 1922,\n 10367, 3860, 8429, 5445, 6844, 4536, 7753, 1050, 11239, 3818, 8471, 6118, 6171, 1190, 11099, 2683,\n 9606, 3789, 8500, 147, 12142, 5456, 6833, 4449, 7840, 4749, 7540, 5537, 6752, 4789, 7500, 4467,\n 7822, 1018, 11271, 5925, 6364, 1041, 11248, 3514, 8775, 2344, 9945, 1278, 11011, 5574, 6715, 1973,\n 10316, 4324, 7965, 4916, 7373, 4075, 8214, 5315, 6974, 5079, 7210, 3262, 9027, 522, 11767, 2169,\n 10120, 1200, 11089, 5184, 7105, 2555, 9734, 6122, 6167, 5297, 6992, 6119, 6170, 3956, 8333, 1360,\n 10929, 1962, 10327, 1594, 10695, 5961, 6328, 5106, 7183, 4298, 7991, 3329, 8960, 168, 12121, 2692,\n 9597, 4049, 8240, 3728, 8561, 1159, 11130, 5990, 6299, 948, 11341, 1146, 11143, 1404, 10885, 325,\n 11964, 5766, 6523, 652, 11637, 295, 11994, 6099, 6190, 2919, 9370, 3762, 8527, 4016, 8273, 4077,\n 8212, 6065, 6224, 835, 11454, 3570, 8719, 4240, 8049, 4046, 8243, 709, 11580, 3150, 9139, 1319,\n 10970, 1058, 11231, 4079, 8210, 922, 11367, 441, 11848, 4322, 7967, 1958, 10331, 2078, 10211,\n 1112, 11177, 3834, 8455, 5257, 7032, 4433, 7856, 5919, 6370, 5486, 6803, 3054, 9235, 1747, 10542,\n 3123, 9166, 2948, 9341, 2503, 9786, 5782, 6507, 1566, 10723, 64, 12225, 3656, 8633, 2459, 9830,\n 683, 11606, 1293, 10996, 4737, 7552, 5429, 6860, 4774, 7515, 5908, 6381, 453, 11836, 418, 11871,\n 3772, 8517, 3991, 8298, 3969, 8320, 2767, 9522, 156, 12133, 2281, 10008, 5876, 6413, 5333, 6956,\n 2031, 10258, 3963, 8326, 576, 11713, 2447, 9842, 6142, 6147, 2051, 10238, 1954, 10335, 1805,\n 10484, 2882, 9407, 3529, 8760, 3434, 8855, 2908, 9381, 218, 12071, 3030, 9259, 4115, 8174, 1843,\n 10446, 2361, 9928, 3202, 9087, 4493, 7796, 2057, 10232, 5369, 6920, 1512, 10777, 350, 11939, 1815,\n 10474, 5383, 6906, 49, 12240, 1263, 11026, 5915, 6374, 1483, 10806, 1489, 10800, 2500, 9789, 5942,\n 6347, 1583, 10706, 1693, 10596, 3009, 9280, 174, 12115, 723, 11566, 2738, 9551, 5868, 6421, 5735,\n 6554, 2655, 9634, 3315, 8974, 426, 11863, 4754, 7535, 1858, 10431, 1975, 10314, 3757, 8532, 2925,\n 9364, 347, 11942,\n]);\n","/* eslint-disable no-bitwise */\n/* eslint-disable no-plusplus */\nimport { N, Q } from './constants';\nimport { NTT_ROOTS_ALL } from './nttRoots';\n\n/** Inverse of 2 mod q. */\nconst I2 = 6145;\n/** Square root of -1 mod q (NTT root for n = 2). */\nconst SQR1 = 1479;\n\n/**\n * Reduces an integer to [0, q).\n * @param {number} a an integer, possibly negative\n * @returns {number} a mod q, in [0, q)\n * @example\n * ```typescript\n * const result = modQ(-1);\n * // result = 12288\n * const result2 = modQ(12290);\n * // result2 = 1\n * ```\n */\nexport const modQ = (a: number): number => ((a % Q) + Q) % Q;\n\n/**\n * base^exponent mod q, by square and multiply.\n * @param {number} base the base\n * @param {number} exponent a non-negative integer\n * @returns {number} the power, in [0, q)\n * @example\n * ```typescript\n * const result = powMod(2, 10);\n * // result = 1024\n * const result2 = powMod(1479, 2);\n * // result2 = 12288 (1479 is a square root of -1 mod q)\n * ```\n */\nfunction powMod(base: number, exponent: number): number {\n let result = 1;\n let b = modQ(base);\n for (let e = exponent; e > 0; e >>= 1) {\n if (e & 1) result = (result * b) % Q;\n b = (b * b) % Q;\n }\n return result;\n}\n\n/**\n * Inverse mod q (Fermat); throws for 0. No cache: inputs may be derived from secret keys.\n * @param {number} x an integer that is not a multiple of q\n * @returns {number} the inverse of x mod q, in [1, q)\n * @throws {Error} when x is a multiple of q\n * @example\n * ```typescript\n * const result = invMod(1479);\n * // result = 10810\n * invMod(0);\n * // throws Error(\"Falcon512: 0 has no inverse mod q\")\n * ```\n */\nexport function invMod(x: number): number {\n const r = modQ(x);\n if (r === 0) throw new Error('Falcon512: 0 has no inverse mod q');\n return powMod(r, Q - 2);\n}\n\n/**\n * Roots used at size n (falcon.py `roots_dict_Zq[n]`).\n * @param {number} n a power of 2, from 2 to 512\n * @returns {number[]} the n roots of x^n + 1 mod q, in (r, -r) pairs\n * @example\n * ```typescript\n * const result = nttRoots(4);\n * // result = [4043, 8246, 5146, 7143]\n * ```\n */\nexport const nttRoots = (n: number): readonly number[] => NTT_ROOTS_ALL.slice(n - 2, 2 * n - 2);\n\n/**\n * Throws unless n is a power of 2 from 2 to 512 (the sizes of the NTT).\n * @param {number} n the size to check\n * @throws {Error} when n is not a power of 2 in [2, 512]\n * @example\n * ```typescript\n * checkSize(4);\n * // passes\n * checkSize(3);\n * // throws Error(\"Falcon512: NTT size must be a power of 2 in [2, 512], got 3\")\n * ```\n */\nfunction checkSize(n: number): void {\n if (n < 2 || n > N || (n & (n - 1)) !== 0) {\n throw new Error(`Falcon512: NTT size must be a power of 2 in [2, ${N}], got ${n}`);\n }\n}\n\n/**\n * Recursive NTT of coefficients already in [0, q); `ntt` checks and reduces its input first.\n * @param {number[]} f the coefficients, in [0, q), of size a power of 2\n * @returns {number[]} the NTT of f\n * @example\n * ```typescript\n * const result = nttRec([1, 2]);\n * // result = [2959, 9332]\n * ```\n */\nfunction nttRec(f: number[]): number[] {\n const n = f.length;\n if (n === 2) {\n const t = (SQR1 * f[1]) % Q;\n return [modQ(f[0] + t), modQ(f[0] - t)];\n }\n const half = n / 2;\n const even: number[] = new Array(half);\n const odd: number[] = new Array(half);\n for (let i = 0; i < half; i++) {\n even[i] = f[2 * i];\n odd[i] = f[2 * i + 1];\n }\n const a = nttRec(even);\n const b = nttRec(odd);\n const w = nttRoots(n);\n const out: number[] = new Array(n);\n for (let i = 0; i < half; i++) {\n const wb = (w[2 * i] * b[i]) % Q;\n out[2 * i] = modQ(a[i] + wb);\n out[2 * i + 1] = modQ(a[i] - wb);\n }\n return out;\n}\n\n/**\n * Recursive inverse NTT of values already in [0, q); `intt` checks and reduces its input first.\n * @param {number[]} fNtt the NTT values, in [0, q), of size a power of 2\n * @returns {number[]} the coefficients, in [0, q)\n * @example\n * ```typescript\n * const result = inttRec([2959, 9332]);\n * // result = [1, 2]\n * ```\n */\nfunction inttRec(fNtt: number[]): number[] {\n const n = fNtt.length;\n if (n === 2) {\n const s = modQ(fNtt[0] + fNtt[1]);\n const d = modQ(fNtt[0] - fNtt[1]);\n return [(I2 * s) % Q, (((I2 * invMod(SQR1)) % Q) * d) % Q];\n }\n const half = n / 2;\n const w = nttRoots(n);\n const f0: number[] = new Array(half);\n const f1: number[] = new Array(half);\n for (let i = 0; i < half; i++) {\n const s = modQ(fNtt[2 * i] + fNtt[2 * i + 1]);\n const d = modQ(fNtt[2 * i] - fNtt[2 * i + 1]);\n f0[i] = (I2 * s) % Q;\n f1[i] = (((I2 * d) % Q) * invMod(w[2 * i])) % Q;\n }\n const a = inttRec(f0);\n const b = inttRec(f1);\n const out: number[] = new Array(n);\n for (let i = 0; i < half; i++) {\n out[2 * i] = a[i];\n out[2 * i + 1] = b[i];\n }\n return out;\n}\n\n/**\n * NTT in the falcon.py convention (same as falcon-rs and falcon.cairo). Coefficients may be negative.\n * @param {ArrayLike<number>} f the coefficients, of size a power of 2 from 2 to 512\n * @returns {number[]} the NTT of f, in [0, q)\n * @throws {Error} when the size of f is not a power of 2 in [2, 512]\n * @example\n * ```typescript\n * const result = ntt([1, 2]);\n * // result = [2959, 9332]\n * ntt([1, 2, 3]);\n * // throws Error(\"Falcon512: NTT size must be a power of 2 in [2, 512], got 3\")\n * ```\n */\nexport function ntt(f: ArrayLike<number>): number[] {\n checkSize(f.length);\n return nttRec(Array.from(f, modQ));\n}\n\n/**\n * Inverse NTT; output in [0, q).\n * @param {ArrayLike<number>} fNtt the NTT values, of size a power of 2 from 2 to 512\n * @returns {number[]} the coefficients, in [0, q)\n * @throws {Error} when the size of fNtt is not a power of 2 in [2, 512]\n * @example\n * ```typescript\n * const result = intt([2959, 9332]);\n * // result = [1, 2]\n * ```\n */\nexport function intt(fNtt: ArrayLike<number>): number[] {\n checkSize(fNtt.length);\n return inttRec(Array.from(fNtt, modQ));\n}\n\n/**\n * Product in Zq[x]/(x^n + 1).\n * @param {ArrayLike<number>} a the first polynomial\n * @param {ArrayLike<number>} b the second polynomial, of the same size\n * @returns {number[]} a·b mod (x^n + 1, q), in [0, q)\n * @throws {Error} when the sizes differ, or are not a power of 2 in [2, 512]\n * @example\n * ```typescript\n * const result = mulZq([1, 1], [1, 1]);\n * // result = [0, 2] ((1 + x)² = 2x, since x² = -1)\n * ```\n */\nexport function mulZq(a: ArrayLike<number>, b: ArrayLike<number>): number[] {\n if (a.length !== b.length) throw new Error('Falcon512: polynomial sizes differ');\n const an = ntt(a);\n const bn = ntt(b);\n return intt(an.map((v, i) => (v * bn[i]) % Q));\n}\n\n/**\n * Quotient a / b in Zq[x]/(x^n + 1); throws if b is not invertible.\n * @param {ArrayLike<number>} a the dividend\n * @param {ArrayLike<number>} b the divisor, of the same size\n * @returns {number[]} a / b mod (x^n + 1, q), in [0, q)\n * @throws {Error} when the sizes differ, or b is not invertible mod q\n * @example\n * ```typescript\n * const result = divZq([0, 2], [1, 1]);\n * // result = [1, 1]\n * divZq([1, 2], [0, 0]);\n * // throws Error(\"Falcon512: polynomial is not invertible mod q\")\n * ```\n */\nexport function divZq(a: ArrayLike<number>, b: ArrayLike<number>): number[] {\n if (a.length !== b.length) throw new Error('Falcon512: polynomial sizes differ');\n const an = ntt(a);\n const bn = ntt(b);\n if (bn.some((v) => v === 0)) throw new Error('Falcon512: polynomial is not invertible mod q');\n return intt(an.map((v, i) => (v * invMod(bn[i])) % Q));\n}\n\n/**\n * Exact integer product in Z[x]/(x^n + 1). Only for small coefficients (NTRU equation check,\n * test reference): every partial sum must stay below 2^53.\n * @param {ArrayLike<number>} a the first polynomial\n * @param {ArrayLike<number>} b the second polynomial, of the same size\n * @returns {number[]} the exact product, not reduced mod q\n * @throws {Error} when the sizes differ\n * @example\n * ```typescript\n * const result = mulNegacyclicInt([1, 1, 0, 0], [1, 1, 0, 0]);\n * // result = [1, 2, 1, 0]\n * const result2 = mulNegacyclicInt([1, 0, 0, 1], [1, 0, 0, 1]);\n * // result2 = [1, 0, -1, 2] (x^3 · x^3 = x^6 = -x^2)\n * ```\n */\nexport function mulNegacyclicInt(a: ArrayLike<number>, b: ArrayLike<number>): number[] {\n const n = a.length;\n if (b.length !== n) throw new Error('Falcon512: polynomial sizes differ');\n const r: number[] = new Array(n).fill(0);\n for (let i = 0; i < n; i++) {\n const ai = a[i];\n if (ai !== 0) {\n for (let j = 0; j < n; j++) {\n const k = i + j;\n if (k < n) r[k] += ai * b[j];\n else r[k - n] -= ai * b[j];\n }\n }\n }\n return r;\n}\n","/* eslint-disable no-bitwise */\n/* eslint-disable no-plusplus */\nimport * as starknet from 'starknet';\nimport { N, PACKED_SLOTS, Q, QB, VALUES_PER_HALF } from './constants';\nimport { assertFelt } from './felt';\n\n/**\n * Horner evaluation in base q of values[start..end): values[start] + values[start + 1]·q + …\n * @param {ArrayLike<number>} values the Zq values\n * @param {number} start index of the first value (lowest power of q)\n * @param {number} end index after the last value\n * @returns {bigint} the packed number\n * @example\n * ```typescript\n * const result = horner([1, 2], 0, 2);\n * // result = 24579n (1 + 2 × 12289)\n * ```\n */\nconst horner = (values: ArrayLike<number>, start: number, end: number): bigint => {\n let acc = 0n;\n for (let i = end - 1; i >= start; i--) acc = acc * QB + BigInt(values[i]);\n return acc;\n};\n\n/**\n * Packs 512 Zq values into 29 felt252 (falcon-rs packing.rs / Cairo packing.cairo):\n * felt = horner(v0..v8) + horner(v9..v17) * 2^128; the last felt holds 8 values in its low half.\n * @param {ArrayLike<number>} poly 512 integers in [0, q)\n * @returns {bigint[]} the 29 packed felts\n * @throws {Error} when poly does not have 512 coefficients, or one of them is not in [0, q)\n * @example\n * ```typescript\n * const result = packPoly(Array.from({ length: 512 }, (_, i) => i));\n * // result = [3009220298763626926401032896359925372832289177998513310902944456849637412n, …] (29 felts)\n * ```\n */\nexport function packPoly(poly: ArrayLike<number>): bigint[] {\n if (poly.length !== N) throw new Error(`Falcon512: polynomial must have ${N} coefficients`);\n for (let i = 0; i < N; i++) {\n const v = poly[i];\n if (!Number.isInteger(v) || v < 0 || v >= Q) {\n throw new Error('Falcon512: polynomial coefficient out of range');\n }\n }\n const out: bigint[] = [];\n for (let start = 0; start < N; start += 2 * VALUES_PER_HALF) {\n const mid = Math.min(start + VALUES_PER_HALF, N);\n const end = Math.min(start + 2 * VALUES_PER_HALF, N);\n out.push(horner(poly, start, mid) + (horner(poly, mid, end) << 128n));\n }\n return out;\n}\n\n/**\n * Unpacks 29 felt252 into 512 Zq values; only the canonical encoding is accepted.\n * @param {bigint[]} felts the 29 packed felts\n * @returns {Uint16Array} the 512 values, in [0, q)\n * @throws {Error} when there are not 29 felts, a felt is out of range, or the encoding is not\n * canonical\n * @example\n * ```typescript\n * const result = unpackPoly(packPoly(Array.from({ length: 512 }, (_, i) => i)));\n * // result = Uint16Array(512) [0, 1, 2, 3, …]\n * unpackPoly(new Array(28).fill(0n));\n * // throws Error(\"Falcon512: packed polynomial must have 29 felts\")\n * ```\n */\nexport function unpackPoly(felts: readonly bigint[]): Uint16Array {\n if (felts.length !== PACKED_SLOTS) {\n throw new Error(`Falcon512: packed polynomial must have ${PACKED_SLOTS} felts`);\n }\n const out = new Uint16Array(N);\n let idx = 0;\n // eslint-disable-next-line no-restricted-syntax\n for (const felt of felts) {\n assertFelt(felt, 'packed polynomial slot');\n // eslint-disable-next-line no-restricted-syntax\n for (const half of [felt & starknet.UINT_128_MAX, felt >> 128n]) {\n const count = Math.min(VALUES_PER_HALF, N - idx);\n if (half >= QB ** BigInt(count)) {\n throw new Error('Falcon512: non-canonical packed polynomial');\n }\n let v = half;\n for (let i = 0; i < count; i++) {\n out[idx++] = Number(v % QB);\n v /= QB;\n }\n }\n }\n return out;\n}\n","import { randomBytes as cryptoRandomBytes } from '@noble/hashes/utils.js';\nimport * as starknet from 'starknet';\nimport { nobleEngine, type FalconEngine } from '../engine/engine';\nimport { N, PACKED_SLOTS, Q, SALT_FELTS, SIG_BOUND_512, SIGNATURE_FELTS } from './constants';\nimport { assertFelt, parseFelt } from './felt';\nimport { hashToPoint } from './hashToPoint';\nimport { intt, modQ, ntt } from './ntt';\nimport { packPoly, unpackPoly } from './packing';\n\n/** Decoded S2morrow signature (Serde of PackedFalconSignatureWithHint). */\nexport type FalconStarknetSignature = { s1: Uint16Array; salt: bigint[]; mulHint: Uint16Array };\n/** Injectable dependencies of signHash (tests only). */\nexport type SignDeps = { engine: FalconEngine; randomBytes: (length: number) => Uint8Array };\n\nconst defaultDeps: SignDeps = { engine: nobleEngine, randomBytes: cryptoRandomBytes };\n\n/**\n * mul_hint = INTT(NTT(s1) ⊙ pkNtt) = s1·h mod (x^512 + 1, q).\n * @param {ArrayLike<number>} s1 the 512 coefficients of s1, in [0, q)\n * @param {ArrayLike<number>} pkNtt the NTT of the public polynomial h\n * @returns {number[]} the 512 coefficients of s1·h, in [0, q)\n * @example\n * ```typescript\n * const { publicKey } = generateKeyPair(new Uint8Array(48).fill(1));\n * const s1 = [1, ...new Array(511).fill(0)];\n * const result = computeMulHint(s1, publicKeyToNtt(publicKey));\n * // result = [6436, 5476, 5849, 5158, …] (512 values): h itself, since s1 = 1\n * ```\n */\nexport function computeMulHint(s1: ArrayLike<number>, pkNtt: ArrayLike<number>): number[] {\n const s1Ntt = ntt(s1);\n return intt(s1Ntt.map((v, i) => (v * pkNtt[i]) % Q));\n}\n\n/**\n * Square of x after centering it in (-q/2, q/2]: the norm used by falcon.cairo.\n * @param {number} x a value in [0, q)\n * @returns {number} the square of the centered value\n * @example\n * ```typescript\n * const result = centeredSquare(12288);\n * // result = 1 (12288 is -1 once centered)\n * const result2 = centeredSquare(3);\n * // result2 = 9\n * ```\n */\nconst centeredSquare = (x: number): number => {\n const c = x <= (Q - 1) / 2 ? x : Q - x;\n return c * c;\n};\n\n/**\n * Mirror of falcon.cairo `verify_with_msg_point`: NTT(s1) ⊙ pkNtt = NTT(mulHint), and\n * ‖hashPoint − mulHint‖² + ‖s1‖² ≤ SIG_BOUND_512 (centered norms). Inputs in [0, q).\n * @param {ArrayLike<number>} hashPoint the 512 coefficients of the hash point\n * @param {ArrayLike<number>} s1 the 512 coefficients of s1\n * @param {ArrayLike<number>} mulHint the 512 coefficients of the hint s1·h\n * @param {ArrayLike<number>} pkNtt the NTT of the public polynomial h\n * @returns {boolean} true when the hint is right and the signature is short enough\n * @example\n * ```typescript\n * const signature = signHash(0x1234n, secretKey, pkNtt);\n * const { s1, salt, mulHint } = parseSignature(signature);\n * const result = checkSignatureEquation(hashToPoint([0x1234n], salt), s1, mulHint, pkNtt);\n * // result = true\n * ```\n */\nexport function checkSignatureEquation(\n hashPoint: ArrayLike<number>,\n s1: ArrayLike<number>,\n mulHint: ArrayLike<number>,\n pkNtt: ArrayLike<number>\n): boolean {\n if (hashPoint.length !== N || s1.length !== N || mulHint.length !== N || pkNtt.length !== N) {\n return false;\n }\n const s1Ntt = ntt(s1);\n const hintNtt = ntt(mulHint);\n for (let i = 0; i < N; i += 1) {\n if ((s1Ntt[i] * pkNtt[i]) % Q !== hintNtt[i]) return false;\n }\n let norm = 0;\n for (let i = 0; i < N; i += 1) {\n norm += centeredSquare(modQ(hashPoint[i] - mulHint[i])) + centeredSquare(s1[i]);\n }\n return norm <= SIG_BOUND_512;\n}\n\n/**\n * 61 felts: [s1 packed (29)] [salt length] [salt…] [mul_hint packed (29)].\n * @param {FalconStarknetSignature} sig the decoded signature\n * @returns {string[]} the 61 felts, as hex strings\n * @example\n * ```typescript\n * const signature = signHash(0x1234n, secretKey, pkNtt);\n * const result = formatSignature(parseSignature(signature));\n * // result = signature (the same 61 felts); result[29] = '0x2' (salt length)\n * ```\n */\nexport function formatSignature(sig: FalconStarknetSignature): string[] {\n const felts = [\n ...packPoly(sig.s1),\n BigInt(sig.salt.length),\n ...sig.salt,\n ...packPoly(sig.mulHint),\n ];\n return felts.map((x) => starknet.num.toHex(x));\n}\n\n/**\n * Strict parsing of a 61-felt signature (hex or decimal strings, numbers, bigints).\n * @param {unknown[]} signature the 61 felts\n * @returns {FalconStarknetSignature} s1, the salt (2 felts) and mul_hint\n * @throws {Error} when the signature does not have 61 felts, a felt is invalid, or the salt\n * length is not 2\n * @example\n * ```typescript\n * const result = parseSignature(signHash(0x1234n, secretKey, pkNtt));\n * // result = { s1: Uint16Array(512) [12275, 53, 11941, 226, …], salt: [two felts], mulHint: Uint16Array(512) […] }\n * parseSignature(['0x1']);\n * // throws Error(\"Falcon512: signature must have 61 felts\")\n * ```\n */\nexport function parseSignature(signature: readonly unknown[]): FalconStarknetSignature {\n if (!Array.isArray(signature) || signature.length !== SIGNATURE_FELTS) {\n throw new Error(`Falcon512: signature must have ${SIGNATURE_FELTS} felts`);\n }\n const felts = signature.map((x, i) => parseFelt(x, `signature[${i}]`));\n if (felts[PACKED_SLOTS] !== BigInt(SALT_FELTS)) {\n throw new Error('Falcon512: unexpected salt length');\n }\n const saltStart = PACKED_SLOTS + 1;\n return {\n s1: unpackPoly(felts.slice(0, PACKED_SLOTS)),\n salt: felts.slice(saltStart, saltStart + SALT_FELTS),\n mulHint: unpackPoly(felts.slice(saltStart + SALT_FELTS)),\n };\n}\n\n/**\n * A salt felt of 248 random bits (31 bytes), always below P.\n * @param {(length: number) => Uint8Array} randomBytes the source of random bytes\n * @returns {bigint} the salt felt\n * @example\n * ```typescript\n * const result = randomSaltFelt((n) => new Uint8Array(n).fill(1));\n * // result = 1773775876797123091660094745843871137458179912157484130506396813846708481n (0x0101…01)\n * ```\n */\nconst randomSaltFelt = (randomBytes: SignDeps['randomBytes']): bigint =>\n BigInt(`0x${starknet.encode.buf2hex(randomBytes(31))}`); // 248 bits < P\n\n/**\n * Signs a message hash for the S2morrow account (internal: never exported by index.ts, to avoid\n * blind signing). The engine draws its own sampler seed, independent from the public salt. The\n * encoded signature is re-checked (reusing the hash point) before being returned.\n * @param {bigint} msgHash the hash to sign, a felt252\n * @param {Uint8Array} secretKey the NIST Falcon-512 secret key (1281 bytes)\n * @param {Uint16Array} pkNtt the NTT of the public polynomial h\n * @param {SignDeps} [deps] the engine and the random source (tests only)\n * @returns {string[]} the 61 felts of the signature\n * @throws {Error} when msgHash is not a felt252, or the self-verification fails\n * @example\n * ```typescript\n * const { secretKey, publicKey } = generateKeyPair(new Uint8Array(48).fill(1));\n * const result = signHash(0x1234n, secretKey, publicKeyToNtt(publicKey));\n * // result = ['0x…', …] (61 felts, random salt); result[29] = '0x2'\n * ```\n */\nexport function signHash(\n msgHash: bigint,\n secretKey: Uint8Array,\n pkNtt: Uint16Array,\n deps: SignDeps = defaultDeps\n): string[] {\n assertFelt(msgHash, 'message hash');\n const salt = [randomSaltFelt(deps.randomBytes), randomSaltFelt(deps.randomBytes)];\n const hashPoint = hashToPoint([msgHash], salt);\n const s2 = deps.engine.signHashPoint(hashPoint, secretKey);\n const s1 = Uint16Array.from(s2, modQ);\n const mulHint = Uint16Array.from(computeMulHint(s1, pkNtt));\n const signature = formatSignature({ s1, salt, mulHint });\n const decoded = parseSignature(signature);\n if (!checkSignatureEquation(hashPoint, decoded.s1, decoded.mulHint, pkNtt)) {\n throw new Error('Falcon512: self-verification failed, signature discarded');\n }\n return signature;\n}\n\n/**\n * Verifies a 61-felt signature of msgHash; false for any malformed input.\n * @param {bigint} msgHash the signed hash\n * @param {unknown[]} signature the 61 felts\n * @param {ArrayLike<number>} pkNtt the NTT of the public polynomial h\n * @returns {boolean} true for a valid signature of msgHash, false otherwise\n * @example\n * ```typescript\n * const signature = signHash(0x1234n, secretKey, pkNtt);\n * const result = verifyHash(0x1234n, signature, pkNtt);\n * // result = true\n * const result2 = verifyHash(0x1235n, signature, pkNtt);\n * // result2 = false\n * ```\n */\nexport function verifyHash(\n msgHash: bigint,\n signature: readonly unknown[],\n pkNtt: ArrayLike<number>\n): boolean {\n let decoded: FalconStarknetSignature;\n try {\n assertFelt(msgHash, 'message hash');\n decoded = parseSignature(signature);\n } catch {\n return false;\n }\n return checkSignatureEquation(\n hashToPoint([msgHash], decoded.salt),\n decoded.s1,\n decoded.mulHint,\n pkNtt\n );\n}\n","/* eslint-disable no-bitwise */\n/* eslint-disable no-plusplus */\nimport { poseidonHashMany, poseidonSmall } from '@scure/starknet';\nimport * as starknet from 'starknet';\nimport { N, QB } from './constants';\nimport { assertFelt } from './felt';\n\n/**\n * S2morrow Poseidon hash-to-point (same as falcon-rs poseidon_hash.rs and the Cairo contract):\n * seed = poseidon_hash_span(message ‖ salt); state = [seed, 0, 0]; 21 Hades permutations each give\n * 12 base-Q digits from state[0] and 12 from state[1], a 22nd gives the last 8 from state[0].\n * Each felt yields 6 digits from its low u128, then 6 from its high u128.\n * @param {bigint[]} message the felts of the message (here, one felt: the hash to sign)\n * @param {bigint[]} salt the felts of the salt (two felts for this signer)\n * @returns {Uint16Array} the hash point: 512 coefficients in [0, q)\n * @throws {Error} when an element is not a felt252\n * @example\n * ```typescript\n * const result = hashToPoint([42n], [1n, 2n]);\n * // result = Uint16Array(512) [3798, 10958, 659, 9391, …]\n * ```\n */\nexport function hashToPoint(message: readonly bigint[], salt: readonly bigint[]): Uint16Array {\n message.forEach((m) => assertFelt(m, 'message element'));\n salt.forEach((s) => assertFelt(s, 'salt element'));\n const out = new Uint16Array(N);\n let idx = 0;\n const extract6 = (value: bigint): void => {\n let v = value;\n for (let i = 0; i < 6 && idx < N; i++) {\n out[idx++] = Number(v % QB);\n v /= QB;\n }\n };\n const extract12 = (felt: bigint): void => {\n extract6(felt & starknet.UINT_128_MAX);\n extract6(felt >> 128n);\n };\n let state: bigint[] = [poseidonHashMany([...message, ...salt]), 0n, 0n];\n for (let round = 0; round < 21; round++) {\n state = poseidonSmall(state);\n extract12(state[0]);\n extract12(state[1]);\n }\n state = poseidonSmall(state);\n extract12(state[0]);\n return out;\n}\n","/* eslint-disable no-bitwise */\n// Hash-to-point of the OpenZeppelin Falcon-512 accounts (OpenZeppelin Contracts for Cairo\n// v4.1.0-rc.0, README of packages/account, \"Key and signature encoding\").\nimport { shake256 } from '@noble/hashes/sha3.js';\nimport { N, Q } from '../s2morrow/constants';\nimport { assertFelt } from '../s2morrow/felt';\n\n/** Number of bytes that one salt felt of an OpenZeppelin signature encodes. */\nexport const SALT_BYTES = 20;\n\n/** A salt felt must be below 2^160 (20 bytes). */\nconst SALT_LIMIT = 1n << BigInt(8 * SALT_BYTES);\n\n/** Words of 5q or more are skipped: 61445 is the largest multiple of q below 2^16. */\nconst KQ = 5 * Q;\n\n/**\n * Writes x into out[offset … offset + length - 1], least significant byte first.\n * @param {bigint} x the value to write; it must fit in `length` bytes\n * @param {Uint8Array} out the array that receives the bytes\n * @param {number} offset index of the first byte to write\n * @param {number} length number of bytes to write\n * @example\n * ```typescript\n * const out = new Uint8Array(4);\n * writeLittleEndian(0x0102n, out, 0, 4);\n * // out = Uint8Array(4) [2, 1, 0, 0]\n * ```\n */\nconst writeLittleEndian = (x: bigint, out: Uint8Array, offset: number, length: number): void => {\n let v = x;\n for (let i = 0; i < length; i += 1) {\n // eslint-disable-next-line no-param-reassign\n out[offset + i] = Number(v & 0xffn);\n v >>= 8n;\n }\n};\n\n/**\n * The 40 bytes of the salt of an OpenZeppelin signature: salt_a, then salt_b, each on 20 bytes,\n * least significant byte first.\n * @param {bigint} saltA the first salt felt\n * @param {bigint} saltB the second salt felt\n * @returns {Uint8Array} the 40 bytes of the salt\n * @throws {Error} when a salt felt is negative, or not below 2^160\n * @example\n * ```typescript\n * const result = saltFeltsToBytes(1n, 2n);\n * // result = Uint8Array(40) [1, 0, 0, …, 2, 0, 0, …] (1 at index 0, 2 at index 20)\n * ```\n */\nexport function saltFeltsToBytes(saltA: bigint, saltB: bigint): Uint8Array {\n [saltA, saltB].forEach((salt) => {\n if (typeof salt !== 'bigint' || salt < 0n || salt >= SALT_LIMIT) {\n throw new Error('Falcon512: salt felt must be non-negative and below 2^160');\n }\n });\n const out = new Uint8Array(2 * SALT_BYTES);\n writeLittleEndian(saltA, out, 0, SALT_BYTES);\n writeLittleEndian(saltB, out, SALT_BYTES, SALT_BYTES);\n return out;\n}\n\n/**\n * OpenZeppelin hash-to-point: SHAKE-256 over salt_a (20 bytes) ‖ salt_b (20 bytes) ‖ the message\n * hash (32 bytes), all little-endian. The output is read as big-endian 16-bit words; words of 5q\n * (61445) or more are skipped, the others are reduced modulo q, until there are 512 coefficients.\n * This is the HashToPoint of the Falcon submission, with the 40 salt bytes as its nonce.\n * @param {bigint} msgHash the hash to sign, a felt252\n * @param {bigint} saltA the first salt felt, below 2^160\n * @param {bigint} saltB the second salt felt, below 2^160\n * @returns {Uint16Array} the hash point: 512 coefficients in [0, q)\n * @throws {Error} when msgHash is not a felt252, or a salt felt is not below 2^160\n * @example\n * ```typescript\n * const result = hashToPointShake(42n, 1n, 2n);\n * // result = Uint16Array(512) [5836, 973, 11428, 8040, …]\n * ```\n */\nexport function hashToPointShake(msgHash: bigint, saltA: bigint, saltB: bigint): Uint16Array {\n assertFelt(msgHash, 'message hash');\n const message = new Uint8Array(32);\n writeLittleEndian(msgHash, message, 0, 32);\n const xof = shake256.create().update(saltFeltsToBytes(saltA, saltB)).update(message);\n const out = new Uint16Array(N);\n for (let i = 0; i < N;) {\n const [high, low] = xof.xof(2);\n const word = (high << 8) | low;\n if (word < KQ) {\n out[i] = word % Q;\n i += 1;\n }\n }\n return out;\n}\n","/* eslint-disable no-bitwise */\n/* eslint-disable no-plusplus */\nimport { isBytes } from '@noble/hashes/utils.js';\nimport * as starknet from 'starknet';\nimport { nobleEngine } from '../engine/engine';\nimport { N, Q } from './constants';\nimport { divZq, modQ, mulNegacyclicInt, mulZq, ntt } from './ntt';\nimport { packPoly } from './packing';\n\nexport const SECRET_KEY_LENGTH = 1281;\nexport const PUBLIC_KEY_LENGTH = 897;\nexport const SEED_LENGTH = 48;\nexport const FALCON_RS_SECRET_KEY_LENGTH = 3584;\nconst FALCON_RS_POLY_LENGTH = 896;\nconst SECRET_KEY_HEADER = 0x59; // 0x50 + log2(512)\nconst PUBLIC_KEY_HEADER = 0x09; // 0x00 + log2(512)\nconst FG_BITS = 6;\nconst CAPITAL_FG_BITS = 8;\nconst FG_MAX = 31; // 2^(6-1) - 1\nconst CAPITAL_FG_MAX = 127; // 2^(8-1) - 1\nconst FG_BYTES = (N * FG_BITS) / 8; // 384\n\nexport type Falcon512KeyPair = { secretKey: Uint8Array; publicKey: Uint8Array };\n/** NTRU secret polynomials, with f·G − g·F = q. */\nexport type SecretPolys = { f: Int8Array; g: Int8Array; F: Int8Array; G: Int8Array };\n\n/** An array that `wipe` can overwrite with zeros. */\ntype Wipeable = { fill(value: number): unknown };\n\n/**\n * Copies a Uint8Array, or reads a hex string (with or without 0x), of exactly `expectedLength`\n * bytes. The length is checked first, so `num.hexToBytes` never pads an odd-length string.\n * @param {Uint8Array | string} input the bytes, or their hex string\n * @param {number} expectedLength the number of bytes expected\n * @param {string} label the name of the value, used in the error messages\n * @returns {Uint8Array} a copy of the bytes\n * @throws {Error} when the input is neither bytes nor a hex string, or has another length\n * @example\n * ```typescript\n * const result = toBytes('0x0102', 2, 'key');\n * // result = Uint8Array(2) [1, 2]\n * toBytes('0x010', 2, 'key');\n * // throws Error(\"Falcon512: key must have 4 hex digits, got 3\")\n * ```\n */\nexport function toBytes(\n input: Uint8Array | string,\n expectedLength: number,\n label: string\n): Uint8Array {\n if (isBytes(input)) {\n if (input.length !== expectedLength) {\n throw new Error(`Falcon512: ${label} must be ${expectedLength} bytes, got ${input.length}`);\n }\n return Uint8Array.from(input);\n }\n if (typeof input !== 'string') {\n throw new Error(`Falcon512: ${label} must be a Uint8Array or a hex string`);\n }\n const hex = starknet.encode.removeHexPrefix(input);\n if (!/^[0-9a-fA-F]*$/.test(hex)) {\n throw new Error(`Falcon512: ${label} is not a valid hex string`);\n }\n if (hex.length !== 2 * expectedLength) {\n throw new Error(\n `Falcon512: ${label} must have ${2 * expectedLength} hex digits, got ${hex.length}`\n );\n }\n return starknet.num.hexToBytes(starknet.encode.addHexPrefix(hex));\n}\n\n/**\n * Overwrites arrays with zeros (best-effort wiping of secret values).\n * @param {...Wipeable} arrays the arrays to wipe\n * @example\n * ```typescript\n * const secret = Uint8Array.from([1, 2]);\n * wipe(secret);\n * // secret = Uint8Array(2) [0, 0]\n * ```\n */\nconst wipe = (...arrays: Wipeable[]): void => {\n arrays.forEach((a) => a.fill(0));\n};\n\n/**\n * Centers a value of [0, q) in (-q/2, q/2].\n * @param {number} x a value in [0, q)\n * @returns {number} the centered value\n * @example\n * ```typescript\n * const result = center(12288);\n * // result = -1\n * const result2 = center(6144);\n * // result2 = 6144\n * const result3 = center(6145);\n * // result3 = -6144\n * ```\n */\nconst center = (x: number): number => (x > Q >> 1 ? x - Q : x);\n\n/**\n * Reads the low `bits` bits of raw as a two's complement number.\n * @param {number} raw the unsigned value\n * @param {number} bits the width of the value\n * @returns {number} the signed value\n * @example\n * ```typescript\n * const result = toSigned(0x3f, 6);\n * // result = -1\n * const result2 = toSigned(0x1f, 6);\n * // result2 = 31\n * ```\n */\nconst toSigned = (raw: number, bits: number): number => (raw << (32 - bits)) >> (32 - bits);\n\n/**\n * NIST encoding: packs values of `bits` bits each, most significant bit first.\n * @param {ArrayLike<number>} values the values (only their low `bits` bits are kept)\n * @param {number} bits the width of each value\n * @returns {Uint8Array} the packed bytes\n * @example\n * ```typescript\n * const result = encodeBitsMSB([1, 2, 3, 4], 6);\n * // result = Uint8Array(3) [4, 32, 196]\n * ```\n */\nfunction encodeBitsMSB(values: ArrayLike<number>, bits: number): Uint8Array {\n const out = new Uint8Array((values.length * bits) / 8);\n const mask = (1 << bits) - 1;\n let acc = 0;\n let accBits = 0;\n let pos = 0;\n for (let i = 0; i < values.length; i++) {\n acc = (acc << bits) | (values[i] & mask);\n accBits += bits;\n while (accBits >= 8) {\n accBits -= 8;\n out[pos++] = (acc >>> accBits) & 0xff;\n }\n acc &= (1 << accBits) - 1;\n }\n return out;\n}\n\n/**\n * NIST decoding: reads `count` values of `bits` bits each, most significant bit first.\n * @param {Uint8Array} bytes the packed bytes\n * @param {number} count the number of values\n * @param {number} bits the width of each value\n * @returns {number[]} the unsigned values\n * @throws {Error} when the number of bytes does not match count × bits\n * @example\n * ```typescript\n * const result = decodeBitsMSB(Uint8Array.from([4, 32, 196]), 4, 6);\n * // result = [1, 2, 3, 4]\n * ```\n */\nfunction decodeBitsMSB(bytes: Uint8Array, count: number, bits: number): number[] {\n if (bytes.length * 8 !== count * bits) throw new Error('Falcon512: invalid encoding length');\n const out: number[] = [];\n const mask = (1 << bits) - 1;\n let acc = 0;\n let accBits = 0;\n for (let i = 0; i < bytes.length; i++) {\n acc = (acc << 8) | bytes[i];\n accBits += 8;\n while (accBits >= bits) {\n accBits -= bits;\n out.push((acc >>> accBits) & mask);\n }\n acc &= (1 << accBits) - 1;\n }\n return out;\n}\n\n/**\n * falcon-rs encoding: packs values mod q on 14 bits each, least significant bit first, into 896\n * bytes.\n * @param {ArrayLike<number>} values the values, in [0, q)\n * @returns {Uint8Array} the 896 bytes\n * @example\n * ```typescript\n * const result = encode14LSB([1, 2]);\n * // result = Uint8Array(896) [1, 128, 0, 0, …]\n * ```\n */\nfunction encode14LSB(values: ArrayLike<number>): Uint8Array {\n const out = new Uint8Array(FALCON_RS_POLY_LENGTH);\n let acc = 0;\n let accBits = 0;\n let pos = 0;\n for (let i = 0; i < values.length; i++) {\n acc |= values[i] << accBits;\n accBits += 14;\n while (accBits >= 8) {\n out[pos++] = acc & 0xff;\n acc >>>= 8;\n accBits -= 8;\n }\n }\n return out;\n}\n\n/**\n * falcon-rs decoding: reads 512 values of 14 bits, least significant bit first. A partial result\n * is wiped when a value is refused.\n * @param {Uint8Array} bytes the 896 bytes of one polynomial\n * @returns {number[]} the 512 values, in [0, q)\n * @throws {Error} when a value is not below q\n * @example\n * ```typescript\n * const result = decode14LSB(encode14LSB(new Array(512).fill(5)));\n * // result = [5, 5, 5, …] (512 values)\n * ```\n */\nfunction decode14LSB(bytes: Uint8Array): number[] {\n const out: number[] = [];\n let acc = 0;\n let accBits = 0;\n let pos = 0;\n try {\n for (let i = 0; i < N; i++) {\n while (accBits < 14) {\n acc |= bytes[pos++] << accBits;\n accBits += 8;\n }\n const v = acc & 0x3fff;\n acc >>>= 14;\n accBits -= 14;\n if (v >= Q) {\n throw new Error('Falcon512: invalid falcon-rs secret key (coefficient out of range)');\n }\n out.push(v);\n }\n return out;\n } catch (error) {\n wipe(out);\n throw error;\n }\n}\n\n/**\n * Throws if a coefficient is outside [-max, max].\n * @param {ArrayLike<number>} poly the coefficients\n * @param {number} max the largest absolute value allowed\n * @param {string} label the name of the polynomial, used in the error message\n * @throws {Error} when a coefficient is out of range\n * @example\n * ```typescript\n * checkRange([1, -2, 31], 31, 'f');\n * // passes\n * checkRange([32], 31, 'f');\n * // throws Error(\"Falcon512: invalid secret key (f coefficient out of range)\")\n * ```\n */\nfunction checkRange(poly: ArrayLike<number>, max: number, label: string): void {\n for (let i = 0; i < poly.length; i++) {\n if (poly[i] < -max || poly[i] > max) {\n throw new Error(`Falcon512: invalid secret key (${label} coefficient out of range)`);\n }\n }\n}\n\n/**\n * G = g·F / f mod q, centered; throws if f is not invertible or G is not small.\n * @param {Int8Array} f the secret polynomial f\n * @param {Int8Array} g the secret polynomial g\n * @param {Int8Array} F the secret polynomial F\n * @returns {Int8Array} the secret polynomial G\n * @throws {Error} when f is not invertible mod q, or G has a coefficient out of range\n * @example\n * ```typescript\n * const { f, g, F } = decodeSecretKey(generateKeyPair(new Uint8Array(48).fill(1)).secretKey);\n * const result = completeG(f, g, F);\n * // result = Int8Array(512) [37, 8, 43, -40, …]\n * ```\n */\nfunction completeG(f: Int8Array, g: Int8Array, F: Int8Array): Int8Array {\n const gF = mulZq(g, F);\n let quotient: number[] = [];\n let G: number[] = [];\n try {\n quotient = divZq(gF, f);\n G = quotient.map(center);\n checkRange(G, CAPITAL_FG_MAX, 'G');\n return Int8Array.from(G);\n } finally {\n wipe(gF, quotient, G);\n }\n}\n\n/**\n * Checks the NTRU equation f·G − g·F = q over Z[x]/(x^512 + 1).\n * @param {SecretPolys} polys the four secret polynomials\n * @throws {Error} when the equation does not hold\n * @example\n * ```typescript\n * const { f, g, F, G } = decodeSecretKey(secretKey);\n * checkNtruEquation({ f, g, F, G });\n * // passes\n * checkNtruEquation({ f, g, F: Int8Array.from(F, (v) => -v), G });\n * // throws Error(\"Falcon512: invalid secret key (NTRU equation not satisfied)\")\n * ```\n */\nfunction checkNtruEquation({ f, g, F, G }: SecretPolys): void {\n const fG = mulNegacyclicInt(f, G);\n const gF = mulNegacyclicInt(g, F);\n try {\n for (let i = 0; i < N; i++) {\n if (fG[i] - gF[i] !== (i === 0 ? Q : 0)) {\n throw new Error('Falcon512: invalid secret key (NTRU equation not satisfied)');\n }\n }\n } finally {\n wipe(fG, gF);\n }\n}\n\n/**\n * Decodes one signed polynomial of a NIST secret key; the smallest value of the width is refused.\n * @param {Uint8Array} bytes the encoded polynomial\n * @param {number} bits the width of each coefficient (6 for f and g, 8 for F)\n * @param {string} label the name of the polynomial, used in the error message\n * @returns {Int8Array} the 512 coefficients\n * @throws {Error} when a coefficient has the forbidden value -2^(bits-1)\n * @example\n * ```typescript\n * const { secretKey } = generateKeyPair(new Uint8Array(48).fill(1));\n * const result = decodeSigned(secretKey.subarray(1, 385), 6, 'f');\n * // result = Int8Array(512) [0, 1, -4, 1, …]\n * ```\n */\nfunction decodeSigned(bytes: Uint8Array, bits: number, label: string): Int8Array {\n const min = -(1 << (bits - 1));\n const raw = decodeBitsMSB(bytes, N, bits);\n try {\n return Int8Array.from(raw, (value) => {\n const v = toSigned(value, bits);\n if (v === min) {\n throw new Error(`Falcon512: invalid secret key (forbidden ${label} coefficient)`);\n }\n return v;\n });\n } finally {\n wipe(raw);\n }\n}\n\n/**\n * Decodes and fully validates a NIST Falcon-512 secret key. The caller must wipe the result.\n * @param {Uint8Array | string} secretKey the NIST secret key (1281 bytes), or its hex string\n * @returns {SecretPolys} the four NTRU polynomials f, g, F, G\n * @throws {Error} when the key has a wrong length or header, a coefficient out of range, or does\n * not satisfy the NTRU equation\n * @example\n * ```typescript\n * const result = decodeSecretKey(generateKeyPair(new Uint8Array(48).fill(1)).secretKey);\n * // result = { f: Int8Array(512) [0, 1, -4, 1, …], g: Int8Array(512) [1, 3, -1, -2, …],\n * // F: Int8Array(512) [-32, 20, -61, -5, …], G: Int8Array(512) [37, 8, 43, -40, …] }\n * ```\n */\nexport function decodeSecretKey(secretKey: Uint8Array | string): SecretPolys {\n const bytes = toBytes(secretKey, SECRET_KEY_LENGTH, 'secret key');\n const parts: Int8Array[] = [];\n try {\n if (bytes[0] !== SECRET_KEY_HEADER) throw new Error('Falcon512: invalid secret key header');\n const f = decodeSigned(bytes.subarray(1, 1 + FG_BYTES), FG_BITS, 'f');\n parts.push(f);\n const g = decodeSigned(bytes.subarray(1 + FG_BYTES, 1 + 2 * FG_BYTES), FG_BITS, 'g');\n parts.push(g);\n const F = decodeSigned(bytes.subarray(1 + 2 * FG_BYTES), CAPITAL_FG_BITS, 'F');\n parts.push(F);\n const G = completeG(f, g, F);\n parts.push(G);\n const polys = { f, g, F, G };\n checkNtruEquation(polys);\n return polys;\n } catch (error) {\n wipe(...parts);\n throw error;\n } finally {\n wipe(bytes);\n }\n}\n\n/**\n * Encodes f, g, F into a NIST Falcon-512 secret key.\n * @param {Pick<SecretPolys, 'f' | 'g' | 'F'>} polys the secret polynomials f, g and F\n * @returns {Uint8Array} the NIST secret key (1281 bytes)\n * @throws {Error} when a coefficient is out of range\n * @example\n * ```typescript\n * const { secretKey } = generateKeyPair(new Uint8Array(48).fill(1));\n * const result = encodeSecretKey(decodeSecretKey(secretKey));\n * // result = Uint8Array(1281) [89, 0, 31, 1, 255, 255, …] (the same bytes as secretKey)\n * ```\n */\nexport function encodeSecretKey({ f, g, F }: Pick<SecretPolys, 'f' | 'g' | 'F'>): Uint8Array {\n checkRange(f, FG_MAX, 'f');\n checkRange(g, FG_MAX, 'g');\n checkRange(F, CAPITAL_FG_MAX, 'F');\n const fBits = Array.from(f, (v) => v & 0x3f);\n const gBits = Array.from(g, (v) => v & 0x3f);\n const capitalFBits = Array.from(F, (v) => v & 0xff);\n const encoded = [\n encodeBitsMSB(fBits, FG_BITS),\n encodeBitsMSB(gBits, FG_BITS),\n encodeBitsMSB(capitalFBits, CAPITAL_FG_BITS),\n ];\n try {\n const out = new Uint8Array(SECRET_KEY_LENGTH);\n out[0] = SECRET_KEY_HEADER;\n out.set(encoded[0], 1);\n out.set(encoded[1], 1 + FG_BYTES);\n out.set(encoded[2], 1 + 2 * FG_BYTES);\n return out;\n } finally {\n wipe(fBits, gBits, capitalFBits, ...encoded);\n }\n}\n\n/**\n * Decodes a NIST Falcon-512 public key into h (coefficients in [0, q)).\n * @param {Uint8Array | string} publicKey the NIST public key (897 bytes), or its hex string\n * @returns {Uint16Array} the 512 coefficients of h\n * @throws {Error} when the key has a wrong length or header, or a coefficient is not below q\n * @example\n * ```typescript\n * const result = decodePublicKey(generateKeyPair(new Uint8Array(48).fill(1)).publicKey);\n * // result = Uint16Array(512) [6436, 5476, 5849, 5158, …]\n * ```\n */\nexport function decodePublicKey(publicKey: Uint8Array | string): Uint16Array {\n const bytes = toBytes(publicKey, PUBLIC_KEY_LENGTH, 'public key');\n if (bytes[0] !== PUBLIC_KEY_HEADER) throw new Error('Falcon512: invalid public key header');\n const h = decodeBitsMSB(bytes.subarray(1), N, 14);\n if (h.some((v) => v >= Q)) {\n throw new Error('Falcon512: invalid public key (coefficient out of range)');\n }\n return Uint16Array.from(h);\n}\n\n/**\n * Encodes h into a NIST Falcon-512 public key.\n * @param {ArrayLike<number>} h the 512 coefficients of h, in [0, q)\n * @returns {Uint8Array} the NIST public key (897 bytes)\n * @throws {Error} when h does not have 512 coefficients, or one of them is not in [0, q)\n * @example\n * ```typescript\n * const { publicKey } = generateKeyPair(new Uint8Array(48).fill(1));\n * const result = encodePublicKey(decodePublicKey(publicKey));\n * // result = Uint8Array(897) [9, 100, 145, 86, 69, 182, …] (the same bytes as publicKey)\n * ```\n */\nexport function encodePublicKey(h: ArrayLike<number>): Uint8Array {\n if (h.length !== N) {\n throw new Error(`Falcon512: public key polynomial must have ${N} coefficients`);\n }\n for (let i = 0; i < N; i++) {\n if (!Number.isInteger(h[i]) || h[i] < 0 || h[i] >= Q) {\n throw new Error('Falcon512: invalid public key (coefficient out of range)');\n }\n }\n const out = new Uint8Array(PUBLIC_KEY_LENGTH);\n out[0] = PUBLIC_KEY_HEADER;\n out.set(encodeBitsMSB(h, 14), 1);\n return out;\n}\n\n/**\n * New key pair (NIST formats). The optional seed must be 48 bytes from a CSPRNG.\n * @param {Uint8Array} [seed] 48 random bytes; by default, drawn by the engine\n * @returns {Falcon512KeyPair} the secret key (1281 bytes) and the public key (897 bytes)\n * @throws {Error} when the seed is not 48 bytes\n * @example\n * ```typescript\n * const result = falcon512.generateKeyPair();\n * // result = { secretKey: Uint8Array(1281) [89, …], publicKey: Uint8Array(897) [9, …] }\n * // A new random key at each call; 89 (0x59) and 9 (0x09) are the headers of the two formats.\n * ```\n */\nexport function generateKeyPair(seed?: Uint8Array): Falcon512KeyPair {\n if (seed !== undefined && (!isBytes(seed) || seed.length !== SEED_LENGTH)) {\n throw new Error(`Falcon512: seed must be a Uint8Array of ${SEED_LENGTH} bytes`);\n }\n return nobleEngine.keygen(seed);\n}\n\n/**\n * Public key h = g / f mod q of a validated secret key (NIST format).\n * @param {Uint8Array | string} secretKey the NIST secret key (1281 bytes), or its hex string\n * @returns {Uint8Array} the NIST public key (897 bytes)\n * @throws {Error} when the secret key is invalid\n * @example\n * ```typescript\n * const { secretKey, publicKey } = falcon512.generateKeyPair();\n * const result = falcon512.getPublicKey(secretKey);\n * // result = Uint8Array(897) [9, …] (the same bytes as publicKey)\n * ```\n */\nexport function getPublicKey(secretKey: Uint8Array | string): Uint8Array {\n const polys = decodeSecretKey(secretKey);\n try {\n return encodePublicKey(divZq(polys.g, polys.f));\n } finally {\n wipe(polys.f, polys.g, polys.F, polys.G);\n }\n}\n\n/**\n * NTT of h, as stored by the S2morrow account.\n * @param {Uint8Array | string} publicKey the NIST public key (897 bytes), or its hex string\n * @returns {Uint16Array} the 512 values of NTT(h)\n * @throws {Error} when the public key is invalid\n * @example\n * ```typescript\n * const result = publicKeyToNtt(generateKeyPair(new Uint8Array(48).fill(1)).publicKey);\n * // result = Uint16Array(512) [11282, 2302, 6547, 2550, …]\n * ```\n */\nexport function publicKeyToNtt(publicKey: Uint8Array | string): Uint16Array {\n return Uint16Array.from(ntt(decodePublicKey(publicKey)));\n}\n\n/**\n * The 29 felts of the account constructor argument `pk_packed`.\n * @param {Uint8Array | string} publicKey the NIST public key (897 bytes), or its hex string\n * @returns {string[]} the 29 felts, as hex strings\n * @throws {Error} when the public key is invalid\n * @example\n * ```typescript\n * const { publicKey } = falcon512.generateKeyPair();\n * const result = falcon512.getPackedPublicKey(publicKey);\n * // result = ['0x…', …] (29 felts)\n * ```\n */\nexport function getPackedPublicKey(publicKey: Uint8Array | string): string[] {\n return packPoly(publicKeyToNtt(publicKey)).map((x) => starknet.num.toHex(x));\n}\n\n/**\n * Converts a falcon-rs secret key (f‖g‖F‖G, 4 × 896 bytes) into a NIST secret key.\n *\n * Warning: falcon-rs derives the seed of its sampler from the public salt of each signature, so the\n * signatures it produced may leak information about the secret key. Import such a key for\n * continuity only; for real funds, generate a new key with `generateKeyPair`.\n * @param {Uint8Array | string} secretKey the falcon-rs secret key (3584 bytes), or its hex string\n * @returns {Uint8Array} the NIST secret key (1281 bytes)\n * @throws {Error} when the key has a wrong length, a coefficient out of range, a G that does not\n * match f, g, F, or does not satisfy the NTRU equation\n * @example\n * ```typescript\n * const result = falcon512.importFalconRsSecretKey(falconRsSecretKey);\n * // result = Uint8Array(1281) [89, …] (NIST header 0x59)\n * ```\n */\nexport function importFalconRsSecretKey(secretKey: Uint8Array | string): Uint8Array {\n const bytes = toBytes(secretKey, FALCON_RS_SECRET_KEY_LENGTH, 'falcon-rs secret key');\n const parts: Wipeable[] = [];\n try {\n const names = ['f', 'g', 'F', 'G'];\n const [f, g, F, G] = names.map((name, k) => {\n const chunk = bytes.subarray(k * FALCON_RS_POLY_LENGTH, (k + 1) * FALCON_RS_POLY_LENGTH);\n const decoded = decode14LSB(chunk);\n parts.push(decoded);\n const poly = decoded.map(center);\n parts.push(poly);\n checkRange(poly, k < 2 ? FG_MAX : CAPITAL_FG_MAX, name);\n const p = Int8Array.from(poly);\n parts.push(p);\n return p;\n });\n const recomputed = completeG(f, g, F);\n parts.push(recomputed);\n if (recomputed.some((v, i) => v !== G[i])) {\n throw new Error('Falcon512: invalid falcon-rs secret key (G does not match f, g, F)');\n }\n checkNtruEquation({ f, g, F, G });\n return encodeSecretKey({ f, g, F });\n } finally {\n wipe(bytes, ...parts);\n }\n}\n\n/**\n * Converts a NIST secret key into the falcon-rs format (f‖g‖F‖G, 4 × 896 bytes).\n *\n * Warning: falcon-rs derives the seed of its sampler from the public salt of each signature, so\n * signing with falcon-rs exposes the key: keep signing with this library.\n * @param {Uint8Array | string} secretKey the NIST secret key (1281 bytes), or its hex string\n * @returns {Uint8Array} the falcon-rs secret key (3584 bytes)\n * @throws {Error} when the secret key is invalid\n * @example\n * ```typescript\n * const { secretKey } = falcon512.generateKeyPair();\n * const result = falcon512.exportFalconRsSecretKey(secretKey);\n * // result = Uint8Array(3584) […]\n * ```\n */\nexport function exportFalconRsSecretKey(secretKey: Uint8Array | string): Uint8Array {\n const polys = decodeSecretKey(secretKey);\n const parts: Wipeable[] = [];\n try {\n const out = new Uint8Array(FALCON_RS_SECRET_KEY_LENGTH);\n [polys.f, polys.g, polys.F, polys.G].forEach((p, k) => {\n const values = Array.from(p, modQ);\n const encoded = encode14LSB(values);\n parts.push(values, encoded);\n out.set(encoded, k * FALCON_RS_POLY_LENGTH);\n });\n return out;\n } finally {\n wipe(polys.f, polys.g, polys.F, polys.G, ...parts);\n }\n}\n","/**\n * Functions for the keys and the signatures of Falcon-512: create a key pair, get its public key\n * (NIST format, or packed in 29 felts), import or export a falcon-rs key, and verify a signature or\n * a SNIP-12 message off-chain. To sign, use `Falcon512Signer`.\n *\n * ```typescript\n * const { secretKey, publicKey } = falcon512.generateKeyPair();\n * const signer = new Falcon512Signer(secretKey, { accountType: 'oz-hint' });\n * const signature = await signer.signMessage(myTypedData, accountAddress);\n * const options = { accountType: 'oz-hint' } as const;\n * const isValid = falcon512.verifyMessage(myTypedData, signature, publicKey, accountAddress, options);\n * // isValid = true\n * ```\n *\n * Choice of the account, deployment and key change are in the\n * [guide](https://starknet-js.com/docs/guides/account/postQuantum).\n * @module\n */\nexport { verify, verifyMessage } from './verify';\nexport {\n exportFalconRsSecretKey,\n generateKeyPair,\n getPackedPublicKey,\n getPublicKey,\n importFalconRsSecretKey,\n} from './s2morrow/keys';\n","import * as starknet from 'starknet';\nimport { parseFalconOptions, type Falcon512Options } from './accountType';\nimport { verifyHashOz } from './oz/signature';\nimport { PACKED_SLOTS } from './s2morrow/constants';\nimport { parseFelt } from './s2morrow/felt';\nimport { publicKeyToNtt } from './s2morrow/keys';\nimport { unpackPoly } from './s2morrow/packing';\nimport { verifyHash } from './s2morrow/signature';\n\n/**\n * Strict parsing (see `parseFelt`): \"\", \" \", \"0x\", a text or a boolean is not a message hash.\n * @param {BigNumberish} value the message hash\n * @returns {bigint | undefined} the hash as a bigint, or undefined when it is not a valid felt252\n * @example\n * ```typescript\n * const result = toMessageHash('0x1234');\n * // result = 4660n\n * const result2 = toMessageHash('0x');\n * // result2 = undefined\n * ```\n */\nfunction toMessageHash(value: starknet.BigNumberish): bigint | undefined {\n try {\n return parseFelt(value, 'message hash');\n } catch {\n return undefined;\n }\n}\n\n/**\n * NTT of the public polynomial h, from a NIST public key or from the 29 felts of a packed key.\n * @param {Uint8Array | string | BigNumberish[]} fullPublicKey the NIST key (897 bytes, or its hex\n * string), or the 29 felts of the packed key\n * @returns {Uint16Array} the 512 values of NTT(h)\n * @throws {Error} when the NIST key is invalid, or the packed key does not have 29 felts, has an\n * invalid felt, or is not canonical\n * @example\n * ```typescript\n * const { publicKey } = falcon512.generateKeyPair();\n * const result = toPkNtt(falcon512.getPackedPublicKey(publicKey));\n * // result = toPkNtt(publicKey) = Uint16Array(512) […]\n * ```\n */\nfunction toPkNtt(\n fullPublicKey: Uint8Array | string | readonly starknet.BigNumberish[]\n): Uint16Array {\n if (Array.isArray(fullPublicKey)) {\n if (fullPublicKey.length !== PACKED_SLOTS) {\n throw new Error(`Falcon512: packed public key must have ${PACKED_SLOTS} felts`);\n }\n return unpackPoly(fullPublicKey.map((x, i) => parseFelt(x, `public key[${i}]`)));\n }\n return publicKeyToNtt(fullPublicKey as Uint8Array | string);\n}\n\n/**\n * Low-level verification, same shape as `ec.starkCurve.verify(signature, msgHash, fullPublicKey)`.\n * @param {Signature} signature the felts of a Falcon-512 signature: 61 (S2morrow), 60\n * (OpenZeppelin, hint) or 31 (OpenZeppelin, direct)\n * @param {BigNumberish} msgHash the signed hash (a transaction hash, or the hash of a SNIP-12\n * message)\n * @param {Uint8Array | string | BigNumberish[]} fullPublicKey the public key: the NIST Falcon-512\n * key (897 bytes, as returned by `getPubKey()`), or the 29 felts of the packed key (as returned by\n * `getPackedPublicKey()`, or by `get_public_key` of an OpenZeppelin account)\n * @param {Falcon512Options} [options] `accountType`: the signature layout to check, `'s2morrow'`\n * (default), `'oz-hint'` or `'oz-direct'`\n * @returns {boolean} true for a valid signature of msgHash in this layout; false for an invalid or\n * malformed signature, a signature in another layout, or a malformed hash\n * @throws {Error} when the public key or an option is invalid\n * @example\n * ```typescript\n * const { secretKey, publicKey } = falcon512.generateKeyPair();\n * const mySigner = new Falcon512Signer(secretKey);\n * const signature = await mySigner.signMessage(myTypedData, accountAddress);\n * const msgHash = typedData.getMessageHash(myTypedData, accountAddress);\n * const result = falcon512.verify(signature, msgHash, publicKey);\n * // result = true\n * const result2 = falcon512.verify(signature, '0x1234', publicKey);\n * // result2 = false\n * const myOzSigner = new Falcon512Signer(secretKey, { accountType: 'oz-hint' });\n * const ozSignature = await myOzSigner.signMessage(myTypedData, accountAddress);\n * const result3 = falcon512.verify(ozSignature, msgHash, myOzSigner.getPackedPublicKey(), {\n * accountType: 'oz-hint',\n * });\n * // result3 = true\n * falcon512.verify(signature, msgHash, '0x1234');\n * // throws Error(\"Falcon512: public key must have 1794 hex digits, got 4\")\n * ```\n */\nexport function verify(\n signature: starknet.Signature,\n msgHash: starknet.BigNumberish,\n fullPublicKey: Uint8Array | string | readonly starknet.BigNumberish[],\n options?: Falcon512Options\n): boolean {\n const accountType = parseFalconOptions(options);\n const pkNtt = toPkNtt(fullPublicKey);\n const h = toMessageHash(msgHash);\n if (h === undefined || !Array.isArray(signature)) return false;\n switch (accountType) {\n case 'oz-hint':\n return verifyHashOz(h, signature, pkNtt, 'hint');\n case 'oz-direct':\n return verifyHashOz(h, signature, pkNtt, 'direct');\n default: // 's2morrow'\n return verifyHash(h, signature, pkNtt);\n }\n}\n\n/**\n * Checks a SNIP-12 message signed by a Falcon-512 account. Same shapes as\n * `typedData.verifyMessage`, with the options of `falcon512.verify` at the end.\n * @param {BigNumberish | TypedData} message a TypedData message, or its hash (SNIP-12)\n * @param {Signature} signature the felts of a Falcon-512 signature: 61 (S2morrow), 60\n * (OpenZeppelin, hint) or 31 (OpenZeppelin, direct)\n * @param {Uint8Array | string | BigNumberish[]} fullPublicKey the NIST Falcon-512 key (897 bytes,\n * as returned by `getPubKey()`), or the 29 felts of the packed key\n * @param {BigNumberish} accountAddress address of the account that signed the message, required\n * when `message` is a TypedData. With a hash, there is no address: the options come in its place\n * @param {Falcon512Options} [options] `accountType`, as for `falcon512.verify`\n * @returns {boolean} true if the message is verified\n * @throws {Error} when `message` is a TypedData and the account address is missing, or when the\n * public key or an option is invalid\n * @example\n * ```typescript\n * const signature = await mySigner.signMessage(myTypedData, accountAddress);\n * const msgHash = typedData.getMessageHash(myTypedData, accountAddress);\n * const result1 = falcon512.verifyMessage(myTypedData, signature, publicKey, accountAddress);\n * const result2 = falcon512.verifyMessage(msgHash, signature, publicKey);\n * // result1 = result2 = true\n * const ozSignature = await myOzSigner.signMessage(myTypedData, accountAddress);\n * const options = { accountType: 'oz-direct' } as const;\n * const result3 = falcon512.verifyMessage(myTypedData, ozSignature, publicKey, accountAddress, options);\n * const result4 = falcon512.verifyMessage(msgHash, ozSignature, publicKey, options);\n * // result3 = result4 = true (myOzSigner built with { accountType: 'oz-direct' })\n * ```\n */\nexport function verifyMessage(\n message: starknet.TypedData,\n signature: starknet.Signature,\n fullPublicKey: Uint8Array | string | readonly starknet.BigNumberish[],\n accountAddress: starknet.BigNumberish,\n options?: Falcon512Options\n): boolean;\nexport function verifyMessage(\n message: starknet.BigNumberish,\n signature: starknet.Signature,\n fullPublicKey: Uint8Array | string | readonly starknet.BigNumberish[],\n options?: Falcon512Options\n): boolean;\nexport function verifyMessage(\n message: starknet.BigNumberish | starknet.TypedData,\n signature: starknet.Signature,\n fullPublicKey: Uint8Array | string | readonly starknet.BigNumberish[],\n accountAddressOrOptions?: starknet.BigNumberish | Falcon512Options,\n options?: Falcon512Options\n): boolean {\n if (typeof message === 'object' && message !== null) {\n if (accountAddressOrOptions === undefined) {\n throw new Error('Falcon512: accountAddress is required to verify a TypedData message');\n }\n const accountAddress = accountAddressOrOptions as starknet.BigNumberish;\n return verify(\n signature,\n starknet.typedData.getMessageHash(message, accountAddress),\n fullPublicKey,\n options\n );\n }\n // With a hash, a 4th argument that is not an options object is ignored, as before.\n const hashOptions =\n typeof accountAddressOrOptions === 'object' &&\n accountAddressOrOptions !== null &&\n !Array.isArray(accountAddressOrOptions)\n ? accountAddressOrOptions\n : undefined;\n return verify(signature, message, fullPublicKey, hashOptions);\n}\n","/**\n * A post-quantum key exchange between two Falcon-512 accounts of OpenZeppelin, with ML-KEM-768\n * (FIPS 203). Alice and Bob get the same secret of 32 bytes, for example the key of an encrypted\n * message. The secret itself is never sent.\n *\n * 1. Alice calls `createKey`. She keeps the seed secret, signs the message with her account, and\n * sends her public key with the signature (`MlKemSignedKey`).\n * 2. Bob calls `encapsulate`. It first checks the signature of Alice, then gives Bob the secret and\n * a capsule. Bob signs the message with his account, and sends the capsule with the signature\n * (`MlKemSignedCapsule`).\n * 3. Alice calls `decapsulate`. It first checks the signature of Bob, then opens the capsule: Alice\n * gets the same secret.\n *\n * Each signature is checked with the Falcon key that the account stores (`get_public_key`): any\n * other account is refused. A wallet only signs the two messages, with `signMessage`.\n *\n * ```typescript\n * // 1. Alice\n * const aliceKey = mlkem.createKey(await myProvider.getChainId(), validUntil);\n * // 2. Bob, with the key signed by Alice\n * const bobSide = await mlkem.encapsulate(myProvider, signedKey, bobAccount.address);\n * // 3. Alice, with the capsule signed by Bob\n * const secret = await mlkem.decapsulate(myProvider, signedCapsule, aliceAccount.address, aliceKey.seed);\n * // secret = bobSide.sharedSecret\n * ```\n *\n * The diagram of the exchange, a complete example and the limits are in the\n * [guide](https://starknet-js.com/docs/guides/account/postQuantum#share-a-secret-between-two-falcon-accounts).\n * @module\n */\nexport { createKey, decapsulate, encapsulate } from './exchange';\n","import { hkdf } from '@noble/hashes/hkdf.js';\nimport { sha256 } from '@noble/hashes/sha2.js';\nimport { randomBytes } from '@noble/hashes/utils.js';\nimport * as starknet from 'starknet';\nimport { ml_kem768 } from '../engine/engine';\nimport { parseFelt } from '../s2morrow/felt';\nimport { capsuleMessage, DOMAIN_NAME, DOMAIN_VERSION, publicKeyMessage } from './messages';\nimport type {\n MlKemEncapsulation,\n MlKemKey,\n MlKemSignedCapsule,\n MlKemSignedKey,\n} from './mlkem.type';\nimport { checkSignature } from './signatures';\nimport { checkBytes, hashBytes } from './utils/bytes';\nimport { checkTime, nowInSeconds } from './utils/time';\n\n// The ML-KEM key exchange, in three steps:\n// 1. Alice calls `createKey`. She keeps the seed secret. She signs the message with her account,\n// then she publishes her public key with the signature.\n// 2. Bob calls `encapsulate`. It checks the signature of Alice. Then it gives Bob the shared\n// secret and a capsule. Bob signs the message with his account, then he sends the capsule to\n// Alice with the signature.\n// 3. Alice calls `decapsulate`. It checks the signature of Bob. Then it opens the capsule, and it\n// gives Alice the same shared secret as Bob.\n// A wallet only signs the two messages, with `signMessage`: it needs nothing new.\n\n// Sizes of ML-KEM-768, in bytes (FIPS 203).\nconst PUBLIC_KEY_SIZE = 1184;\nconst CAPSULE_SIZE = 1088;\nconst SEED_SIZE = 64;\nconst SHARED_SECRET_SIZE = 32;\n\n/**\n * The final shared secret. ML-KEM gives Alice and Bob a secret of 32 bytes. HKDF (with SHA-256)\n * mixes this secret with the context of the exchange: the chain, the two accounts, the key and the\n * capsule. So Alice and Bob get the same final secret only when they agree on all of them.\n * For example, if Mallory signs the capsule of Bob in her own name, Alice and Bob get two\n * different secrets. So Bob cannot read what Alice sends to Mallory, and Alice cannot take a\n * message of Bob for a message of Mallory.\n * @param {Uint8Array} mlKemSecret the secret that ML-KEM gives (32 bytes)\n * @param {object} context the context of the exchange: the chain id, the address of the account\n * of Alice (`keyOwnerAddress`), the address of the account of Bob (`senderAddress`), the hash of\n * the key and the hash of the capsule\n * @returns {Uint8Array} the final shared secret (32 bytes)\n * @example\n * ```typescript\n * const result = finalSecret(mlKemSecret, {\n * chainId,\n * keyOwnerAddress: aliceAddress,\n * senderAddress: bobAddress,\n * keyHash,\n * capsuleHash,\n * });\n * // result = Uint8Array(32) [ … ]\n * ```\n */\nfunction finalSecret(\n mlKemSecret: Uint8Array,\n context: {\n chainId: string;\n keyOwnerAddress: bigint;\n senderAddress: bigint;\n keyHash: string;\n capsuleHash: string;\n }\n): Uint8Array {\n const contextHash = starknet.hash.computePoseidonHashOnElements([\n starknet.CairoBytes31.fromText(DOMAIN_NAME).toBigInt(),\n starknet.CairoBytes31.fromText(DOMAIN_VERSION).toBigInt(),\n context.chainId,\n context.keyOwnerAddress,\n context.senderAddress,\n context.keyHash,\n context.capsuleHash,\n ]);\n // HKDF takes the context as bytes: the 32 bytes of the hash of the context.\n const info = starknet.num.hexToBytes(starknet.num.toHex64(contextHash));\n return hkdf(sha256, mlKemSecret, undefined, info, SHARED_SECRET_SIZE);\n}\n\n/**\n * Step 1, for Alice: creates a new ML-KEM-768 key, and the message that links it to her account.\n * Alice keeps the seed secret. She signs the message with her account (`signMessage`). Then she\n * publishes her public key, its end of validity and the signature (see `MlKemSignedKey`).\n * A wallet can sign the message: it needs nothing new. The seed stays in the dapp.\n * @param {string} chainId the chain id, as `provider.getChainId()` returns it\n * @param {number} validUntil the end of validity of the key, in seconds since 1970-01-01 (UTC).\n * It must be in the future\n * @returns {MlKemKey} the seed, the public key and the message to sign\n * @throws {Error} when the chain id is empty, or when validUntil is not a time in seconds in the\n * future\n * @example\n * ```typescript\n * const chainId = await myProvider.getChainId();\n * const validUntil = Math.floor(Date.now() / 1000) + 30 * 24 * 3600; // in 30 days\n * const aliceKey = mlkem.createKey(chainId, validUntil);\n * const signature = await aliceAccount.signMessage(aliceKey.typedData);\n * const signedKey = {\n * keyOwnerAddress: aliceAccount.address,\n * publicKey: aliceKey.publicKey,\n * validUntil,\n * signature,\n * };\n * // Alice keeps aliceKey.seed (64 bytes) secret, and publishes signedKey.\n * ```\n */\nexport function createKey(chainId: string, validUntil: number): MlKemKey {\n if (typeof chainId !== 'string' || chainId === '') {\n throw new Error('ML-KEM: chainId must be the chain id, as provider.getChainId() returns it.');\n }\n checkTime(validUntil, 'validUntil');\n if (validUntil <= nowInSeconds()) throw new Error('ML-KEM: validUntil must be in the future.');\n const seed = randomBytes(SEED_SIZE);\n const { publicKey, secretKey } = ml_kem768.keygen(seed);\n // Alice does not need the secret key now: `decapsulate` builds it again from the seed.\n // Erase the secret key: write 0 in each byte, so that it does not stay in memory.\n secretKey.fill(0);\n const typedData = publicKeyMessage(chainId, hashBytes(publicKey), validUntil);\n return { seed, publicKey, typedData };\n}\n\n/**\n * Step 2, for Bob: checks the signed key of Alice, then creates the shared secret and a capsule.\n * Bob keeps the shared secret. He signs the message with his account (`signMessage`). Then he\n * sends the capsule, the timestamp and the signature to Alice (see `MlKemSignedCapsule`).\n * The function refuses the key when it has expired, or when the account of Alice did not sign it\n * with a post-quantum signature (see `checkSignature`).\n * @param {ProviderInterface} provider the provider of the chain of the exchange\n * @param {MlKemSignedKey} signedKey what Alice published\n * @param {BigNumberish} senderAddress the address of the account of Bob, who makes the capsule\n * and sends it\n * @returns {Promise<MlKemEncapsulation>} the shared secret, the capsule, the timestamp and the\n * message to sign\n * @throws {Error} when the key has a wrong size or has expired, or when the signature of Alice is\n * not valid\n * @example\n * ```typescript\n * const bobSide = await mlkem.encapsulate(myProvider, signedKey, bobAccount.address);\n * const signature = await bobAccount.signMessage(bobSide.typedData);\n * const signedCapsule = {\n * senderAddress: bobAccount.address,\n * capsule: bobSide.capsule,\n * timestamp: bobSide.timestamp,\n * signature,\n * };\n * // Bob keeps bobSide.sharedSecret (32 bytes) secret, and sends signedCapsule to Alice.\n * ```\n */\nexport async function encapsulate(\n provider: starknet.ProviderInterface,\n signedKey: MlKemSignedKey,\n senderAddress: starknet.BigNumberish\n): Promise<MlKemEncapsulation> {\n checkBytes(signedKey.publicKey, PUBLIC_KEY_SIZE, 'public key');\n checkTime(signedKey.validUntil, 'validUntil');\n // Alice owns the key. Bob calls this function: he makes the capsule and sends it.\n const aliceAddress = parseFelt(signedKey.keyOwnerAddress, 'ML-KEM key owner address');\n const bobAddress = parseFelt(senderAddress, 'ML-KEM sender address');\n if (signedKey.validUntil <= nowInSeconds()) {\n const owner = starknet.num.toHex(aliceAddress);\n throw new Error(`ML-KEM: the key of the account ${owner} has expired.`);\n }\n const chainId = await provider.getChainId();\n const keyHash = hashBytes(signedKey.publicKey);\n const keyMessage = publicKeyMessage(chainId, keyHash, signedKey.validUntil);\n await checkSignature(provider, keyMessage, signedKey.signature, aliceAddress);\n\n // noble calls the capsule `cipherText`.\n const { cipherText: capsule, sharedSecret: mlKemSecret } = ml_kem768.encapsulate(\n signedKey.publicKey\n );\n const capsuleHash = hashBytes(capsule);\n const timestamp = nowInSeconds();\n const sharedSecret = finalSecret(mlKemSecret, {\n chainId,\n keyOwnerAddress: aliceAddress,\n senderAddress: bobAddress,\n keyHash,\n capsuleHash,\n });\n // Erase the ML-KEM secret: write 0 in each byte, so that it does not stay in memory.\n mlKemSecret.fill(0);\n const typedData = capsuleMessage(chainId, aliceAddress, keyHash, capsuleHash, timestamp);\n return { sharedSecret, capsule, timestamp, typedData };\n}\n\n/**\n * Step 3, for Alice: checks the signed capsule of Bob, then opens the capsule. Alice gets the same\n * shared secret as Bob.\n * The function refuses the capsule when the account of Bob did not sign it with a post-quantum\n * signature (see `checkSignature`). A capsule made for another key or for another account is\n * refused too: the signature of Bob does not match.\n * Bob signed the timestamp, so it is the time that Bob gave. To refuse an old capsule, or a\n * capsule received twice, is the job of the application.\n * @param {ProviderInterface} provider the provider of the chain of the exchange\n * @param {MlKemSignedCapsule} signedCapsule what Bob sent\n * @param {BigNumberish} keyOwnerAddress the address of the account of Alice, who owns the key\n * @param {Uint8Array} seed the seed that `createKey` gave to Alice (64 bytes)\n * @returns {Promise<Uint8Array>} the shared secret (32 bytes), the same as the one of Bob\n * @throws {Error} when the capsule or the seed has a wrong size, or when the signature of Bob is\n * not valid\n * @example\n * ```typescript\n * const sharedSecret = await mlkem.decapsulate(\n * myProvider,\n * signedCapsule,\n * aliceAccount.address,\n * aliceKey.seed\n * );\n * // sharedSecret = bobSide.sharedSecret (32 bytes)\n * ```\n */\nexport async function decapsulate(\n provider: starknet.ProviderInterface,\n signedCapsule: MlKemSignedCapsule,\n keyOwnerAddress: starknet.BigNumberish,\n seed: Uint8Array\n): Promise<Uint8Array> {\n checkBytes(signedCapsule.capsule, CAPSULE_SIZE, 'capsule');\n checkTime(signedCapsule.timestamp, 'timestamp');\n checkBytes(seed, SEED_SIZE, 'seed');\n // Alice calls this function: she owns the key. Bob made the capsule and sent it.\n const aliceAddress = parseFelt(keyOwnerAddress, 'ML-KEM key owner address');\n const bobAddress = parseFelt(signedCapsule.senderAddress, 'ML-KEM sender address');\n const { publicKey, secretKey } = ml_kem768.keygen(seed);\n try {\n const chainId = await provider.getChainId();\n const keyHash = hashBytes(publicKey);\n const capsuleHash = hashBytes(signedCapsule.capsule);\n const { timestamp } = signedCapsule;\n const typedData = capsuleMessage(chainId, aliceAddress, keyHash, capsuleHash, timestamp);\n await checkSignature(provider, typedData, signedCapsule.signature, bobAddress);\n\n const mlKemSecret = ml_kem768.decapsulate(signedCapsule.capsule, secretKey);\n const sharedSecret = finalSecret(mlKemSecret, {\n chainId,\n keyOwnerAddress: aliceAddress,\n senderAddress: bobAddress,\n keyHash,\n capsuleHash,\n });\n // Erase the ML-KEM secret: write 0 in each byte, so that it does not stay in memory.\n mlKemSecret.fill(0);\n return sharedSecret;\n } finally {\n // This part runs in all cases, also after an error.\n // Erase the secret key: write 0 in each byte, so that it does not stay in memory.\n secretKey.fill(0);\n }\n}\n","import * as starknet from 'starknet';\n\n// The two SNIP-12 messages of the ML-KEM key exchange:\n// - Alice signs the first one, to link her ML-KEM public key to her account.\n// - Bob signs the second one, to sign the capsule that he sends to Alice. The capsule is what\n// FIPS 203 and noble call the \"cipher text\": 1088 bytes that hold the shared secret. Only the\n// ML-KEM secret key of Alice can open it.\n// The side that checks a signature builds the message again, from the data that it receives and\n// with the same function. So both sides get the same message, and the same hash.\n\n/** Name of the SNIP-12 domain of the two messages. */\nexport const DOMAIN_NAME = 'ML-KEM key exchange';\n\n/** Version of the SNIP-12 domain. If the two messages change, this version must change too. */\nexport const DOMAIN_VERSION = '1';\n\n/** The ML-KEM variant. The message of Alice shows it. */\nconst ALGORITHM = 'ML-KEM-768';\n\n/**\n * The domain of the two messages: its type and its values, as SNIP-12 revision 1 defines them.\n * The function builds new objects at each call. So if a caller changes one message, the other\n * message does not change.\n * @param {string} chainId the chain id, as `provider.getChainId()` returns it\n * @returns {{ type: StarknetType[]; domain: StarknetDomain }} the type and the values of the domain\n * @example\n * ```typescript\n * const result = messageDomain(constants.StarknetChainId.SN_SEPOLIA);\n * // result = { type: [{ name: 'name', type: 'shortstring' }, …],\n * // domain: { name: 'ML-KEM key exchange', version: '1', chainId: '0x534e5f5345504f4c4941',\n * // revision: '1' } }\n * ```\n */\nfunction messageDomain(chainId: string): {\n type: starknet.StarknetType[];\n domain: starknet.StarknetDomain;\n} {\n return {\n type: [\n { name: 'name', type: 'shortstring' },\n { name: 'version', type: 'shortstring' },\n { name: 'chainId', type: 'shortstring' },\n { name: 'revision', type: 'shortstring' },\n ],\n domain: {\n name: DOMAIN_NAME,\n version: DOMAIN_VERSION,\n chainId,\n revision: starknet.TypedDataRevision.ACTIVE,\n },\n };\n}\n\n/**\n * The message that Alice signs after `createKey`. It tells Bob that this ML-KEM key belongs to the\n * account of Alice. Alice signs it with `signMessage(typedData, aliceAddress)`: her address is part\n * of what she signs, so the message does not repeat it.\n * @param {string} chainId the chain id, as `provider.getChainId()` returns it\n * @param {string} keyHash the hash of the ML-KEM public key of Alice, from `hashBytes`\n * @param {number} validUntil the end of validity of the key, in seconds since 1970-01-01 (UTC)\n * @returns {TypedData} the SNIP-12 message (revision 1)\n * @example\n * ```typescript\n * const result = publicKeyMessage(constants.StarknetChainId.SN_SEPOLIA, keyHash, 1798761600);\n * // result = {\n * // types: { StarknetDomain: […], MlKemPublicKey: […] },\n * // primaryType: 'MlKemPublicKey',\n * // domain: { name: 'ML-KEM key exchange', version: '1', chainId: '0x534e…', revision: '1' },\n * // message: { Algorithm: 'ML-KEM-768', 'Key hash': keyHash, 'Valid until': 1798761600 },\n * // }\n * ```\n */\nexport function publicKeyMessage(\n chainId: string,\n keyHash: string,\n validUntil: number\n): starknet.TypedData {\n const { type, domain } = messageDomain(chainId);\n return {\n types: {\n StarknetDomain: type,\n MlKemPublicKey: [\n { name: 'Algorithm', type: 'shortstring' },\n { name: 'Key hash', type: 'felt' },\n { name: 'Valid until', type: 'timestamp' },\n ],\n },\n primaryType: 'MlKemPublicKey',\n domain,\n message: { Algorithm: ALGORITHM, 'Key hash': keyHash, 'Valid until': validUntil },\n };\n}\n\n/**\n * The message that Bob signs after `encapsulate`. It tells Alice that the capsule comes from Bob.\n * Bob signs it with `signMessage(typedData, bobAddress)`: his address is part of what he signs, so\n * the message does not repeat it.\n * @param {string} chainId the chain id, as `provider.getChainId()` returns it\n * @param {BigNumberish} keyOwnerAddress the address of the account of Alice, which owns the ML-KEM\n * key\n * @param {string} keyHash the hash of the ML-KEM public key of Alice, from `hashBytes`\n * @param {string} capsuleHash the hash of the capsule, from `hashBytes`\n * @param {number} timestamp the time of `encapsulate`, in seconds since 1970-01-01 (UTC)\n * @returns {TypedData} the SNIP-12 message (revision 1)\n * @example\n * ```typescript\n * const result = capsuleMessage(chainId, aliceAddress, keyHash, capsuleHash, 1795000000);\n * // result = {\n * // types: { StarknetDomain: […], MlKemCapsule: […] },\n * // primaryType: 'MlKemCapsule',\n * // domain: { name: 'ML-KEM key exchange', version: '1', chainId, revision: '1' },\n * // message: { 'Key owner': '0x…', 'Key hash': keyHash, 'Capsule hash': capsuleHash,\n * // Timestamp: 1795000000 },\n * // }\n * ```\n */\nexport function capsuleMessage(\n chainId: string,\n keyOwnerAddress: starknet.BigNumberish,\n keyHash: string,\n capsuleHash: string,\n timestamp: number\n): starknet.TypedData {\n const { type, domain } = messageDomain(chainId);\n return {\n types: {\n StarknetDomain: type,\n MlKemCapsule: [\n { name: 'Key owner', type: 'ContractAddress' },\n { name: 'Key hash', type: 'felt' },\n { name: 'Capsule hash', type: 'felt' },\n { name: 'Timestamp', type: 'timestamp' },\n ],\n },\n primaryType: 'MlKemCapsule',\n domain,\n message: {\n 'Key owner': starknet.num.toHex(keyOwnerAddress),\n 'Key hash': keyHash,\n 'Capsule hash': capsuleHash,\n Timestamp: timestamp,\n },\n };\n}\n","import * as starknet from 'starknet';\nimport type { Falcon512AccountType } from '../accountType';\nimport { PACKED_SLOTS } from '../s2morrow/constants';\nimport { parseFelt } from '../s2morrow/felt';\nimport { verifyMessage } from '../verify';\n\n/**\n * Checks that an account signed a message of the key exchange, with a post-quantum signature.\n * The function reads the public key that the account stores (`get_public_key`). Then it checks\n * the signature with this key, off-chain.\n *\n * Today, it accepts only the Falcon-512 accounts of OpenZeppelin. It refuses a Stark (ECDSA)\n * account, an S2morrow account (it has no `get_public_key`), and an account that is not deployed.\n * To accept another post-quantum signature later, change this function only.\n * @param {ProviderInterface} provider the provider that reads the public key of the account\n * @param {TypedData} typedData the message\n * @param {Signature} signature the signature of the message\n * @param {BigNumberish} accountAddress the address of the account that signed the message\n * @returns {Promise<void>} nothing: the function returns only when the signature is valid\n * @throws {Error} when the account is not a deployed Falcon-512 account of OpenZeppelin, or when\n * the signature is not valid\n * @example\n * ```typescript\n * const signature = await aliceFalconAccount.signMessage(typedData);\n * await checkSignature(myProvider, typedData, signature, aliceFalconAccount.address);\n * // returns: the signature is valid\n * await checkSignature(myProvider, typedData, signature, myStarkAccount.address);\n * // throws Error('ML-KEM: the account 0x… is not a Falcon-512 account of OpenZeppelin.')\n * ```\n */\nexport async function checkSignature(\n provider: starknet.ProviderInterface,\n typedData: starknet.TypedData,\n signature: starknet.Signature,\n accountAddress: starknet.BigNumberish\n): Promise<void> {\n const address = starknet.num.toHex(parseFelt(accountAddress, 'ML-KEM account address'));\n let answer: string[];\n try {\n answer = await provider.callContract({\n contractAddress: address,\n entrypoint: 'get_public_key',\n });\n } catch (error) {\n throw new Error(\n `ML-KEM: cannot read the public key of the account ${address}. The account must be ` +\n 'deployed, and must be a Falcon-512 account of OpenZeppelin.',\n { cause: error }\n );\n }\n // A Falcon-512 account of OpenZeppelin answers 29, then the 29 felts of its key.\n // A Stark account answers one felt.\n if (answer.length !== PACKED_SLOTS + 1 || BigInt(answer[0]) !== BigInt(PACKED_SLOTS)) {\n throw new Error(`ML-KEM: the account ${address} is not a Falcon-512 account of OpenZeppelin.`);\n }\n // The number of felts tells how to read the signature. 60 felts: the signature carries a hint,\n // which makes the on-chain check cheaper. 31 felts: no hint.\n const length = Array.isArray(signature) ? signature.length : 0;\n let accountType: Falcon512AccountType;\n if (length === 60) {\n accountType = 'oz-hint';\n } else if (length === 31) {\n accountType = 'oz-direct';\n } else {\n throw new Error(\n `ML-KEM: the signature of the account ${address} is not a Falcon-512 signature.`\n );\n }\n if (!verifyMessage(typedData, signature, answer.slice(1), address, { accountType })) {\n throw new Error(`ML-KEM: the signature of the account ${address} is not valid.`);\n }\n}\n","import { isBytes } from '@noble/hashes/utils.js';\nimport * as starknet from 'starknet';\n\n/**\n * Checks that a value is a Uint8Array of the expected size.\n * @param {unknown} value the value to check\n * @param {number} size the expected number of bytes\n * @param {string} name the name of the value, for the error message\n * @returns {Uint8Array} the value\n * @throws {Error} when the value is not a Uint8Array of this size\n * @example\n * ```typescript\n * const result = checkBytes(new Uint8Array(64), 64, 'seed');\n * // result = the same Uint8Array\n * checkBytes('0x1234', 64, 'seed');\n * // throws Error('ML-KEM: the seed must be a Uint8Array of 64 bytes.')\n * ```\n */\nexport function checkBytes(value: unknown, size: number, name: string): Uint8Array {\n if (!isBytes(value) || value.length !== size) {\n throw new Error(`ML-KEM: the ${name} must be a Uint8Array of ${size} bytes.`);\n }\n return value;\n}\n\n/**\n * Hash of bytes, with Poseidon. The bytes are cut into groups of 31 bytes, in order. Each group\n * becomes one felt, with its first byte as the highest byte (big-endian). The last group holds the\n * bytes that are left.\n *\n * Use it only for bytes of a fixed size: an ML-KEM-768 public key (1184 bytes, so 39 felts) or a\n * capsule (1088 bytes, so 36 felts). With a fixed size, two different series of bytes always give\n * different felts.\n * @param {Uint8Array} bytes the bytes to hash\n * @returns {string} the hash: one felt, in hex\n * @example\n * ```typescript\n * const result = hashBytes(new Uint8Array(32).fill(1));\n * // The felts are 0x0101…01 (31 bytes) and 0x01 (1 byte).\n * // result = '0x56657fe3500667466b4fc95fff44a7e6799c982fff4c85fbd18a5641b51f70d'\n * ```\n */\nexport function hashBytes(bytes: Uint8Array): string {\n // 31 bytes always fit in a felt. It is also the maximum length of a short string.\n const groupSize = starknet.constants.TEXT_TO_FELT_MAX_LEN;\n const felts: string[] = [];\n for (let start = 0; start < bytes.length; start += groupSize) {\n const group = bytes.subarray(start, start + groupSize);\n felts.push(starknet.encode.addHexPrefix(starknet.encode.buf2hex(group)));\n }\n return starknet.hash.computePoseidonHashOnElements(felts);\n}\n","// Times of the key exchange: in seconds since 1970-01-01 (UTC), like the timestamps of Starknet.\n\n/**\n * The biggest time accepted, in seconds: 4294967295, in the year 2106. A bigger value is probably\n * in milliseconds, like the result of `Date.now()`.\n */\nconst MAX_TIME = 0xffffffff;\n\n/**\n * The current time, in seconds since 1970-01-01 (UTC).\n * @returns {number} the current time, in seconds\n * @example\n * ```typescript\n * const result = nowInSeconds();\n * // result = 1795000000 (for example)\n * ```\n */\nexport function nowInSeconds(): number {\n return Math.floor(Date.now() / 1000);\n}\n\n/**\n * Checks that a value is a time in seconds since 1970-01-01 (UTC): a whole number from 0 to\n * 4294967295 (the year 2106).\n * @param {unknown} value the value to check\n * @param {string} name the name of the value, for the error message\n * @returns {number} the value\n * @throws {Error} when the value is not such a whole number. For example, a `Date`, or a time in\n * milliseconds like the result of `Date.now()`\n * @example\n * ```typescript\n * const result = checkTime(1798761600, 'validUntil');\n * // result = 1798761600\n * checkTime(Date.now(), 'validUntil');\n * // throws Error('ML-KEM: validUntil must be a time in seconds, from 0 to 4294967295. …')\n * ```\n */\nexport function checkTime(value: unknown, name: string): number {\n if (typeof value !== 'number' || !Number.isSafeInteger(value) || value < 0 || value > MAX_TIME) {\n throw new Error(\n `ML-KEM: ${name} must be a time in seconds, from 0 to ${MAX_TIME}. ` +\n 'Note: Date.now() gives milliseconds, so divide it by 1000.'\n );\n }\n return value;\n}\n"],"mappings":";;;;;;;AAAA,YAAYA,eAAc;;;AC0B1B,IAAM,gBAAiD,OAAO,OAAO;AAAA,EACnE;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAmBM,SAAS,mBAAmB,SAAwC;AACzE,MAAI,YAAY,OAAW,QAAO;AAClC,MAAI,OAAO,YAAY,YAAY,YAAY,QAAQ,MAAM,QAAQ,OAAO,GAAG;AAC7E,UAAM,IAAI,MAAM,sCAAsC;AAAA,EACxD;AACA,SAAO,KAAK,OAAO,EAAE,QAAQ,CAAC,QAAQ;AACpC,QAAI,QAAQ,cAAe,OAAM,IAAI,MAAM,8BAA8B,GAAG,GAAG;AAAA,EACjF,CAAC;AACD,QAAM,EAAE,YAAY,IAAI;AACxB,MAAI,gBAAgB,OAAW,QAAO;AACtC,MAAI,CAAC,cAAc,SAAS,WAAW,GAAG;AACxC,UAAM,IAAI;AAAA,MACR,mCAAmC,OAAO,WAAW,CAAC;AAAA,IACxD;AAAA,EACF;AACA,SAAO;AACT;;;AC/DA,YAAYC,eAAc;;;ACCnB,IAAM,IAAI;AAEV,IAAM,KAAK;AAEX,IAAM,IAAI;AAEV,IAAM,gBAAgB;AAEtB,IAAM,eAAe;AAErB,IAAM,kBAAkB;AAExB,IAAM,aAAa;AAEnB,IAAM,kBAAkB;;;ACjB/B,YAAY,cAAc;AAgBnB,SAAS,WAAW,GAAW,OAAqB;AACzD,MAAI,OAAO,MAAM,SAAU,OAAM,IAAI,MAAM,cAAc,KAAK,mBAAmB;AACjF,EAAS,sBAAa,YAAY,CAAC;AACrC;AAM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ACf;AAAA,IACA;AAAA,EACF,CAAC;AAED,cAAY,KAAK,CAAC;AAClB,QAAMA,aAAY,eAAe,SAAS,cAAc,SAAS,aAAa,SAAS;AACvF,SAAO,EAAE,cAAc,SAAS,WAAW,WAAAA,WAAU;AACvD;AA4BA,eAAsB,YACpB,UACA,eACA,iBACA,MACqB;AACrB,aAAW,cAAc,SAAS,cAAc,SAAS;AACzD,YAAU,cAAc,WAAW,WAAW;AAC9C,aAAW,MAAM,WAAW,MAAM;AAElC,QAAM,eAAe,UAAU,iBAAiB,0BAA0B;AAC1E,QAAM,aAAa,UAAU,cAAc,eAAe,uBAAuB;AACjF,QAAM,EAAE,WAAW,UAAU,IAAI,UAAU,OAAO,IAAI;AACtD,MAAI;AACF,UAAM,UAAU,MAAM,SAAS,WAAW;AAC1C,UAAM,UAAU,UAAU,SAAS;AACnC,UAAM,cAAc,UAAU,cAAc,OAAO;AACnD,UAAM,EAAE,UAAU,IAAI;AACtB,UAAMA,aAAY,eAAe,SAAS,cAAc,SAAS,aAAa,SAAS;AACvF,UAAM,eAAe,UAAUA,YAAW,cAAc,WAAW,UAAU;AAE7E,UAAM,cAAc,UAAU,YAAY,cAAc,SAAS,SAAS;AAC1E,UAAM,eAAe,YAAY,aAAa;AAAA,MAC5C;AAAA,MACA,iBAAiB;AAAA,MACjB,eAAe;AAAA,MACf;AAAA,MACA;AAAA,IACF,CAAC;AAED,gBAAY,KAAK,CAAC;AAClB,WAAO;AAAA,EACT,UAAE;AAGA,cAAU,KAAK,CAAC;AAAA,EAClB;AACF;","names":["starknet","starknet","cryptoRandomBytes","starknet","FFTCore","shake256","abytes","bytesToHex","randomBytes","opts","opts","N","Q","F","ROOT_OF_UNITY","N","n","F","bytesToHex","Q","shake256","ntt","intt","FFTCore","opts","logn","sign","floatPoly","abytes","res","randomBytes","getPublicKey","verify","shake256","swap32IfBE","u32","N","Q","u32","swap32IfBE","opts","shake256","starknet","starknet","starknet","randomBytes","shake256","shake256","defaultDeps","cryptoRandomBytes","isBytes","starknet","isBytes","F","typedData","starknet","randomBytes","starknet","starknet","starknet","typedData","isBytes","starknet","randomBytes","typedData"]}
|