Keyboard shortcuts

Press ← or → to navigate between chapters

Press ? to show this help

Press Esc to hide this help

JS/WASM の型宣言

初期化関数、返されるインスタンス、各方式のメソッドの引数と戻り値を型定義から掲載しています。初期化と利用例 · 型定義を取得

export type BytesLike = Uint8Array | string;

export class QuantAegisWasmError extends Error {
  readonly code: number;
  constructor(code: number, message: string);
}

export interface KemKeyPair {
  readonly ek: Uint8Array;
  readonly dk: Uint8Array;
}

export interface KemEncapsResult {
  readonly ct: Uint8Array;
  readonly sharedSecret: Uint8Array;
}

export interface KemApi {
  readonly EK_LEN: number;
  readonly DK_LEN: number;
  readonly CT_LEN: number;
  readonly SHARED_SECRET_LEN: 32;
  keygen(): KemKeyPair;
  encaps(ek: Uint8Array): KemEncapsResult;
  /** An invalid capsule of the correct length also produces a secret. Authenticate the payload separately. */
  decaps(dk: Uint8Array, ct: Uint8Array): Uint8Array;
}

export interface XWingHazmatApi {
  /** Length in bytes of the `eseed` accepted by {@link XWingHazmatApi.encapsDerand}. */
  readonly ENCAPS_SEED_LEN: 64;
  /**
   * Deterministic X-Wing `GenerateKeyPairDerand(skSeed)`.
   *
   * **Hazardous: intended for known-answer testing (KAT) only.** The 32-byte `skSeed` is the
   * decapsulation key itself: it must come from a CSPRNG, be kept secret and never be reused for
   * another key pair. Anyone who knows or can guess the seed recovers `dk`. Use
   * {@link KemApi.keygen} for normal key generation.
   */
  keygenDerand(skSeed: Uint8Array): KemKeyPair;
  /**
   * Deterministic X-Wing `EncapsulateDerand(ek, eseed)`.
   *
   * **Hazardous: intended for known-answer testing (KAT) only.** The 64-byte `eseed` replaces the
   * encapsulation randomness. Reusing it, or using a predictable value, produces the same
   * ciphertext and shared secret again and lets anyone who knows `eseed` compute the shared
   * secret, which breaks security. Use {@link KemApi.encaps} in production.
   */
  encapsDerand(ek: Uint8Array, eseed: Uint8Array): KemEncapsResult;
}

export interface QuantAegisWasmHazmat {
  readonly XWing: XWingHazmatApi;
}

export interface SigKeyPair {
  readonly pk: Uint8Array;
  readonly sk: Uint8Array;
}

export interface SignatureApi {
  readonly PK_LEN: number;
  readonly SK_LEN: number;
  readonly SIG_LEN: number;
  readonly MAX_CTX_LEN: 255;
  keygen(): SigKeyPair;
  sign(sk: Uint8Array, msg: BytesLike, ctx?: BytesLike): Uint8Array;
  /**
   * Signs without fresh per-signature randomness (ML-DSA: `rnd = 0`; SLH-DSA:
   * `opt_rand = PK.seed`), so the same `(sk, msg, ctx)` always yields the same signature.
   *
   * **Intended for known-answer testing (KAT) and reproducibility.** The deterministic variant is
   * permitted by FIPS 204 / FIPS 205, but it drops the hedging randomness that mitigates
   * fault-injection and side-channel attacks on the signing key. Prefer {@link SignatureApi.sign}
   * (hedged) in production.
   */
  signDeterministic(sk: Uint8Array, msg: BytesLike, ctx?: BytesLike): Uint8Array;
  verify(pk: Uint8Array, msg: BytesLike, sig: Uint8Array, ctx?: BytesLike): void;
}

export interface SeededSignatureApi extends SignatureApi {
  /** Length in bytes of the seed accepted by {@link SeededSignatureApi.fromSeed}. */
  readonly SEED_LEN: number;
  /**
   * Derives a key pair deterministically from a `SEED_LEN`-byte seed (ML-DSA: the FIPS 204 `xi`
   * seed; MLDSA65-Ed25519: the 64-byte composite seed).
   *
   * **Hazardous: intended for known-answer testing (KAT).** The seed is equivalent to the signing
   * key: it must come from a CSPRNG, be kept secret and never be reused for another key pair.
   * Anyone who knows or can guess the seed recovers `sk`. Use {@link SignatureApi.keygen} to
   * generate new keys.
   */
  fromSeed(seed: Uint8Array): SigKeyPair;
}

export interface QuantAegisWasmInstance {
  readonly abiVersion: number;
  sha3_256(data: BytesLike): Uint8Array;
  shake256(data: BytesLike, outLen: number): Uint8Array;
  readonly MlKem512: KemApi;
  readonly MlKem768: KemApi;
  readonly MlKem1024: KemApi;
  readonly XWing: KemApi;
  readonly MlDsa44: SeededSignatureApi;
  readonly MlDsa65: SeededSignatureApi;
  readonly MlDsa87: SeededSignatureApi;
  readonly MlDsa65Ed25519: SeededSignatureApi;
  readonly SlhDsaShake128f: SignatureApi;
  readonly SlhDsaShake192f: SignatureApi;
  readonly SlhDsaShake256f: SignatureApi;
  readonly hazmat: QuantAegisWasmHazmat;
}

export function initQuantAegisWasm(
  wasmSource: BufferSource | WebAssembly.Module,
): Promise<QuantAegisWasmInstance>;