diff --git a/packages/triple-ratchet/api-extractor.json b/packages/triple-ratchet/api-extractor.json new file mode 100644 index 00000000..f8f35c49 --- /dev/null +++ b/packages/triple-ratchet/api-extractor.json @@ -0,0 +1,44 @@ +{ + "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", + "mainEntryPointFilePath": "/dist/index.d.mts", + "bundledPackages": [ + "@bcts/*" + ], + "compiler": { + "tsconfigFilePath": "/tsconfig.json" + }, + "apiReport": { + "enabled": false + }, + "docModel": { + "enabled": false + }, + "dtsRollup": { + "enabled": true, + "untrimmedFilePath": "/dist/bundle.d.mts" + }, + "tsdocMetadata": { + "enabled": false + }, + "messages": { + "compilerMessageReporting": { + "default": { + "logLevel": "warning" + } + }, + "extractorMessageReporting": { + "default": { + "logLevel": "warning" + }, + "ae-forgotten-export": { + "logLevel": "error", + "addToApiReportFile": false + } + }, + "tsdocMessageReporting": { + "default": { + "logLevel": "warning" + } + } + } +} diff --git a/packages/triple-ratchet/package.json b/packages/triple-ratchet/package.json index c94ea8bf..a7ba30d1 100644 --- a/packages/triple-ratchet/package.json +++ b/packages/triple-ratchet/package.json @@ -16,13 +16,17 @@ }, "main": "dist/index.cjs", "module": "dist/index.mjs", - "types": "dist/index.d.mts", + "types": "dist/bundle.d.mts", "exports": { ".": { - "types": "./dist/index.d.mts", - "import": "./dist/index.mjs", - "require": "./dist/index.cjs", - "default": "./dist/index.mjs" + "import": { + "types": "./dist/bundle.d.mts", + "default": "./dist/index.mjs" + }, + "require": { + "types": "./dist/index.d.cts", + "default": "./dist/index.cjs" + } } }, "files": [ @@ -31,7 +35,7 @@ "LICENSE" ], "scripts": { - "build": "tsdown", + "build": "tsc --noEmit -p tsconfig.build.json && tsdown && api-extractor run --local", "test": "vitest run", "test:watch": "vitest", "lint": "eslint 'src/**/*.ts' 'tests/**/*.ts'", @@ -64,6 +68,7 @@ "@bcts/eslint": "workspace:*", "@bcts/tsconfig": "workspace:*", "@eslint/js": "^10.0.1", + "@microsoft/api-extractor": "^7.52.1", "@types/node": "^25.3.2", "eslint": "^10.0.2", "prettier": "^3.8.1", diff --git a/packages/triple-ratchet/src/index.ts b/packages/triple-ratchet/src/index.ts index 70ee9c6b..7ffb8399 100644 --- a/packages/triple-ratchet/src/index.ts +++ b/packages/triple-ratchet/src/index.ts @@ -37,18 +37,8 @@ export { KyberPreKeyRecord, InMemoryKyberPreKeyStore } from "./stores.js"; export type { KyberPreKeyStore, PQXDHPreKeyBundle } from "./stores.js"; // Types -export type { - AlicePQXDHParameters, - BobPQXDHParameters, - KyberKeyPair, - KyberCiphertext, - PQXDHDerivedKeys, - PQRatchetState, - PQRatchetMessage, - InitialPQRKey, - PreKeysUsed, - TripleRatchetChainParams, -} from "./types.js"; +export type * from "./types.js"; +export * from "@bcts/double-ratchet"; // Session cipher (encrypt/decrypt) export { tripleRatchetEncrypt, tripleRatchetDecrypt } from "./session-cipher.js"; diff --git a/packages/triple-ratchet/src/session-init.ts b/packages/triple-ratchet/src/session-init.ts index b17e0580..b093dc22 100644 --- a/packages/triple-ratchet/src/session-init.ts +++ b/packages/triple-ratchet/src/session-init.ts @@ -35,7 +35,7 @@ import { } from "@bcts/double-ratchet"; import type { RandomNumberGenerator } from "@bcts/rand"; import * as spqr from "@bcts/spqr"; -import type { ChainParams } from "@bcts/spqr"; +import type { ChainParams } from "./types.js"; import { ml_kem1024 } from "@noble/post-quantum/ml-kem.js"; import { diff --git a/packages/triple-ratchet/src/session-state.ts b/packages/triple-ratchet/src/session-state.ts index 5ae01325..bcdb442b 100644 --- a/packages/triple-ratchet/src/session-state.ts +++ b/packages/triple-ratchet/src/session-state.ts @@ -21,7 +21,7 @@ import type { } from "@bcts/double-ratchet"; import * as spqr from "@bcts/spqr"; import { TripleRatchetError, TripleRatchetErrorCode } from "./error.js"; -import type { PQRatchetState, PQRatchetMessage } from "./types.js"; +import type { PQRatchetState, PQRatchetMessage, RandomBytes } from "./types.js"; export class TripleRatchetSessionState { private readonly inner: SessionState; @@ -42,7 +42,7 @@ export class TripleRatchetSessionState { * Returns the serialized SPQR message to include in the wire envelope * and an optional 32-byte key that should be mixed into the root key. */ - pqRatchetSend(rng: spqr.RandomBytes): { msg: PQRatchetMessage; key: Uint8Array | null } { + pqRatchetSend(rng: RandomBytes): { msg: PQRatchetMessage; key: Uint8Array | null } { try { const result = spqr.send(this._pqRatchetState, rng); this._pqRatchetState = result.state; diff --git a/packages/triple-ratchet/src/types.ts b/packages/triple-ratchet/src/types.ts index 8c5a8034..c80e61b1 100644 --- a/packages/triple-ratchet/src/types.ts +++ b/packages/triple-ratchet/src/types.ts @@ -8,8 +8,10 @@ import type { KeyPair, IdentityKeyPair, IdentityKey } from "@bcts/double-ratchet"; import type { ChainParams } from "@bcts/spqr"; -// Re-export SPQR types used in our public API -export type { ChainParams } from "@bcts/spqr"; +export type * from "@bcts/double-ratchet"; + +export type { RandomBytes, ChainParams } from "@bcts/spqr"; +export type { RandomNumberGenerator } from "@bcts/rand"; /** Opaque serialized SPQR state (protobuf bytes). */ export type PQRatchetState = Uint8Array; diff --git a/packages/triple-ratchet/tsconfig.build.json b/packages/triple-ratchet/tsconfig.build.json new file mode 100644 index 00000000..16aac285 --- /dev/null +++ b/packages/triple-ratchet/tsconfig.build.json @@ -0,0 +1,10 @@ +{ + "extends": "./tsconfig.json", + "include": [ + "src/**/*.ts" + ], + "exclude": [ + "dist", + "node_modules" + ] +}