// Copyright 2026 @quantus/crypto authors & contributors // SPDX-License-Identifier: Apache-2.0 /** * Which ML-DSA parameter set a call refers to. * * These are the chain's own `DilithiumSignatureScheme` variant indices, not a * private numbering — the value here is the byte a signed extrinsic carries on * the wire. Keeping them identical means the keyring's `TYPE_PREFIX` is the * identity function on a scheme, with no table to get backwards. */ export enum Scheme { /** ML-DSA-87. Legacy: accounts created before the scheme was recorded, and the dev-genesis accounts. */ MlDsa87 = 0, /** ML-DSA-65. What new accounts use. */ MlDsa65 = 1 } /** * The name each scheme is stored under, matching `quantus-cli` and the mobile * wallet so a wallet exported from one tool imports into another. */ export const SCHEME_NAME: Record = { [Scheme.MlDsa87]: 'ml-dsa-87', [Scheme.MlDsa65]: 'ml-dsa-65' }; /** * FIPS 204 context for on-chain extrinsic signatures. * * Only from spec 148 onward — earlier runtimes verify under the empty context, * and a signature made under the wrong one is valid, rejected by the chain, and * indistinguishable locally. Callers pass the spec version and get the right * answer from {@link contextForSpec}; nothing here guesses. */ export const EXTRINSIC_CONTEXT = new TextEncoder().encode('QUANTUS_EXTRINSIC'); /** First spec version that verifies extrinsics under {@link EXTRINSIC_CONTEXT}. */ export const EXTRINSIC_MIN_SPEC = 148; /** The signing context a runtime at `specVersion` expects. */ export function contextForSpec (specVersion: number): Uint8Array { return specVersion >= EXTRINSIC_MIN_SPEC ? EXTRINSIC_CONTEXT : new Uint8Array(); }