p2party 0.8.0 → 0.14.2
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/LICENSE.md +202 -661
- package/README.md +736 -404
- package/THIRD_PARTY_NOTICES.md +458 -0
- package/docs/assets/p2party-cat.svg +1 -0
- package/docs/getting-started.md +203 -0
- package/docs/protocol-v4-security.md +158 -0
- package/docs/references.md +157 -0
- package/docs/session-api.md +457 -0
- package/docs/wire-format.md +103 -0
- package/examples/standalone-e2ee.ts +194 -0
- package/lib/api/signalingServerApi.d.ts +6 -7
- package/lib/api/webrtc/baseQuery.d.ts +1 -2
- package/lib/api/webrtc/disconnectFromAllRoomsQuery.d.ts +1 -2
- package/lib/api/webrtc/disconnectFromChannelLabelQuery.d.ts +1 -2
- package/lib/api/webrtc/disconnectFromPeerChannelLabelQuery.d.ts +1 -2
- package/lib/api/webrtc/disconnectFromPeerQuery.d.ts +3 -3
- package/lib/api/webrtc/disconnectFromRoomQuery.d.ts +1 -2
- package/lib/api/webrtc/disconnectQuery.d.ts +1 -2
- package/lib/api/webrtc/iceGeneration.d.ts +17 -0
- package/lib/api/webrtc/iceRepair.d.ts +10 -0
- package/lib/api/webrtc/index.d.ts +13 -13
- package/lib/api/webrtc/interfaces.d.ts +67 -11
- package/lib/api/webrtc/negotiationLock.d.ts +12 -0
- package/lib/api/webrtc/openChannelQuery.d.ts +1 -2
- package/lib/api/webrtc/pendingIceCandidates.d.ts +14 -0
- package/lib/api/webrtc/roomPeer.d.ts +11 -0
- package/lib/api/webrtc/sendMessageQuery.d.ts +7 -4
- package/lib/api/webrtc/setCandidateQuery.d.ts +1 -2
- package/lib/api/webrtc/setDescriptionQuery.d.ts +1 -2
- package/lib/cryptography/coverCell.d.ts +65 -0
- package/lib/cryptography/cpace.d.ts +41 -0
- package/lib/cryptography/ed25519.d.ts +0 -1
- package/lib/cryptography/hashStream.d.ts +15 -0
- package/lib/cryptography/hkdf.d.ts +3 -0
- package/lib/cryptography/identityCrossSig.d.ts +7 -0
- package/lib/cryptography/interfaces.d.ts +28 -13
- package/lib/cryptography/memory.d.ts +2 -4
- package/lib/cryptography/merkle.d.ts +0 -1
- package/lib/cryptography/mlkem.d.ts +117 -0
- package/lib/cryptography/mnemonic.d.ts +0 -1
- package/lib/cryptography/pqHealing.d.ts +268 -0
- package/lib/cryptography/pqHealingFrame.d.ts +39 -0
- package/lib/cryptography/pqMessageKey.d.ts +30 -0
- package/lib/cryptography/random.d.ts +22 -0
- package/lib/cryptography/ratchet.d.ts +146 -0
- package/lib/cryptography/testModule.d.ts +7 -0
- package/lib/cryptography/utils.d.ts +0 -1
- package/lib/cryptography/wasmLoader.d.ts +6 -1
- package/lib/cryptography/x25519.d.ts +15 -0
- package/lib/cryptography/x3dh.d.ts +9 -0
- package/lib/db/api.d.ts +54 -22
- package/lib/db/db.worker.d.ts +0 -1
- package/lib/db/ratchetWrap.d.ts +36 -0
- package/lib/db/src/getDB.d.ts +17 -4
- package/lib/db/types.d.ts +274 -32
- package/lib/db.worker.js +1 -2
- package/lib/handlers/chunkFrame.d.ts +13 -0
- package/lib/handlers/connectionSignal.d.ts +26 -0
- package/lib/handlers/coverEdge.d.ts +42 -0
- package/lib/handlers/coverRuntime.d.ts +91 -0
- package/lib/handlers/coverScheduler.d.ts +184 -0
- package/lib/handlers/coverTransfer.d.ts +46 -0
- package/lib/handlers/frameType.d.ts +10 -0
- package/lib/handlers/handleChallenge.d.ts +0 -1
- package/lib/handlers/handleConnectToPeer.d.ts +0 -1
- package/lib/handlers/handleHandshake.d.ts +74 -0
- package/lib/handlers/handleMessageQueueing.d.ts +53 -4
- package/lib/handlers/handleOpenChannel.d.ts +4 -2
- package/lib/handlers/handleQueuedIceCandidates.d.ts +0 -1
- package/lib/handlers/handleReadReceipt.d.ts +17 -4
- package/lib/handlers/handleReceiveMessage.d.ts +21 -3
- package/lib/handlers/handleSendMessage.d.ts +110 -2
- package/lib/handlers/handleWebSocketMessage.d.ts +1 -3
- package/lib/handlers/handshakeCore.d.ts +95 -0
- package/lib/handlers/messageChunkCrypto.d.ts +70 -0
- package/lib/handlers/peerRosterDelta.d.ts +12 -0
- package/lib/handlers/pqHealingOrchestrator.d.ts +46 -0
- package/lib/handlers/pqHealingRuntime.d.ts +82 -0
- package/lib/handlers/ratchetGate.d.ts +18 -0
- package/lib/handlers/ratchetPersist.d.ts +53 -0
- package/lib/handlers/receiptFrame.d.ts +18 -0
- package/lib/handlers/receiveMessageKeyLifetime.d.ts +24 -0
- package/lib/handlers/reconcile.d.ts +16 -0
- package/lib/handlers/transferAbort.d.ts +42 -0
- package/lib/index.d.ts +203 -46
- package/lib/index.js +1 -2
- package/lib/index.min.js +1 -2
- package/lib/index.mjs +1 -2
- package/lib/libcrypto.provenance.json +45 -0
- package/lib/libcrypto.wasm +0 -0
- package/lib/middleware/keyPairListenerMiddleware.d.ts +0 -1
- package/lib/middleware/roomListenerMiddleware.d.ts +0 -1
- package/lib/reducers/commonSlice.d.ts +0 -1
- package/lib/reducers/keyPairSlice.d.ts +0 -1
- package/lib/reducers/roomSlice.d.ts +65 -3
- package/lib/reducers/signalingServerSlice.d.ts +25 -4
- package/lib/roomInvite.d.ts +18 -0
- package/lib/roomPinAttempts.d.ts +12 -0
- package/lib/roomPinVault.d.ts +26 -0
- package/lib/roomPolicy.d.ts +60 -0
- package/lib/session.d.ts +110 -0
- package/lib/session.js +1 -0
- package/lib/session.mjs +1 -0
- package/lib/store.d.ts +40 -41
- package/lib/utils/channelLabel.d.ts +0 -1
- package/lib/utils/chunkBounds.d.ts +9 -0
- package/lib/utils/constants.d.ts +50 -6
- package/lib/utils/debug.d.ts +25 -0
- package/lib/utils/drainAndClose.d.ts +5 -0
- package/lib/utils/identityRole.d.ts +19 -0
- package/lib/utils/interfaces.d.ts +31 -43
- package/lib/utils/leafHash.d.ts +13 -0
- package/lib/utils/messageTypes.d.ts +0 -1
- package/lib/utils/metadata.d.ts +6 -1
- package/lib/utils/mutex.d.ts +24 -0
- package/lib/utils/protocolVersion.d.ts +5 -0
- package/lib/utils/receiptToken.d.ts +7 -0
- package/lib/utils/sendQueueKey.d.ts +2 -0
- package/lib/utils/signalingAuth.d.ts +8 -0
- package/lib/utils/signalingBounds.d.ts +9 -0
- package/lib/utils/splitToChunks.d.ts +7 -4
- package/lib/utils/uint8array.d.ts +1 -2
- package/lib/utils/waitForOpen.d.ts +3 -0
- package/lib/utils/zeroFree.d.ts +10 -0
- package/package.json +109 -49
- package/lib/api/signalingServerApi.d.ts.map +0 -1
- package/lib/api/webrtc/baseQuery.d.ts.map +0 -1
- package/lib/api/webrtc/disconnectFromAllRoomsQuery.d.ts.map +0 -1
- package/lib/api/webrtc/disconnectFromChannelLabelQuery.d.ts.map +0 -1
- package/lib/api/webrtc/disconnectFromPeerChannelLabelQuery.d.ts.map +0 -1
- package/lib/api/webrtc/disconnectFromPeerQuery.d.ts.map +0 -1
- package/lib/api/webrtc/disconnectFromRoomQuery.d.ts.map +0 -1
- package/lib/api/webrtc/disconnectQuery.d.ts.map +0 -1
- package/lib/api/webrtc/index.d.ts.map +0 -1
- package/lib/api/webrtc/interfaces.d.ts.map +0 -1
- package/lib/api/webrtc/openChannelQuery.d.ts.map +0 -1
- package/lib/api/webrtc/sendMessageQuery.d.ts.map +0 -1
- package/lib/api/webrtc/setCandidateQuery.d.ts.map +0 -1
- package/lib/api/webrtc/setDescriptionQuery.d.ts.map +0 -1
- package/lib/cryptography/chacha20poly1305.d.ts +0 -116
- package/lib/cryptography/chacha20poly1305.d.ts.map +0 -1
- package/lib/cryptography/ed25519.d.ts.map +0 -1
- package/lib/cryptography/interfaces.d.ts.map +0 -1
- package/lib/cryptography/memory.d.ts.map +0 -1
- package/lib/cryptography/merkle.d.ts.map +0 -1
- package/lib/cryptography/mnemonic.d.ts.map +0 -1
- package/lib/cryptography/utils.d.ts.map +0 -1
- package/lib/cryptography/wasmLoader.d.ts.map +0 -1
- package/lib/db/api.d.ts.map +0 -1
- package/lib/db/db.worker.d.ts.map +0 -1
- package/lib/db/src/getDB.d.ts.map +0 -1
- package/lib/db/types.d.ts.map +0 -1
- package/lib/db.worker.js.map +0 -1
- package/lib/handlers/handleChallenge.d.ts.map +0 -1
- package/lib/handlers/handleConnectToPeer.d.ts.map +0 -1
- package/lib/handlers/handleMessageQueueing.d.ts.map +0 -1
- package/lib/handlers/handleOpenChannel.d.ts.map +0 -1
- package/lib/handlers/handleQueuedIceCandidates.d.ts.map +0 -1
- package/lib/handlers/handleReadReceipt.d.ts.map +0 -1
- package/lib/handlers/handleReceiveMessage.d.ts.map +0 -1
- package/lib/handlers/handleSendMessage.d.ts.map +0 -1
- package/lib/handlers/handleWebSocketMessage.d.ts.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/index.min.js.map +0 -1
- package/lib/index.mjs.map +0 -1
- package/lib/middleware/keyPairListenerMiddleware.d.ts.map +0 -1
- package/lib/middleware/roomListenerMiddleware.d.ts.map +0 -1
- package/lib/reducers/commonSlice.d.ts.map +0 -1
- package/lib/reducers/keyPairSlice.d.ts.map +0 -1
- package/lib/reducers/roomSlice.d.ts.map +0 -1
- package/lib/reducers/signalingServerSlice.d.ts.map +0 -1
- package/lib/store.d.ts.map +0 -1
- package/lib/utils/allocators.d.ts +0 -22
- package/lib/utils/allocators.d.ts.map +0 -1
- package/lib/utils/channelLabel.d.ts.map +0 -1
- package/lib/utils/constants.d.ts.map +0 -1
- package/lib/utils/interfaces.d.ts.map +0 -1
- package/lib/utils/messageTypes.d.ts.map +0 -1
- package/lib/utils/metadata.d.ts.map +0 -1
- package/lib/utils/splitToChunks.d.ts.map +0 -1
- package/lib/utils/uint8array.d.ts.map +0 -1
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { type RatchetRootSuite } from "../utils/constants";
|
|
2
|
+
import type { LibCrypto } from "./libcrypto";
|
|
3
|
+
export declare const COVER_CELL_HEADER_BYTES: number;
|
|
4
|
+
export declare const COVER_CELL_PLAINTEXT_BYTES: number;
|
|
5
|
+
export declare const COVER_CELL_BINDING_BYTES = 32;
|
|
6
|
+
export declare const COVER_CELL_ROOT_BYTES = 32;
|
|
7
|
+
export declare const COVER_CELL_TOKEN_BYTES: number;
|
|
8
|
+
export declare const COVER_CELL_MAX_PAYLOAD_BYTES: number;
|
|
9
|
+
export type CoverCellDirection = "initiator-to-responder" | "responder-to-initiator";
|
|
10
|
+
export type CoverCellContent = {
|
|
11
|
+
readonly subtype: "dummy";
|
|
12
|
+
} | {
|
|
13
|
+
/** Explicit encrypted CANCEL for exactly one admitted transfer. */
|
|
14
|
+
readonly subtype: "cancel";
|
|
15
|
+
readonly merkleRoot: Uint8Array;
|
|
16
|
+
} | {
|
|
17
|
+
/**
|
|
18
|
+
* Scheduled receipt (per-cell ack or terminal completion token), scoped
|
|
19
|
+
* to its transfer root. Never the 65-byte immediate receipt frame.
|
|
20
|
+
*/
|
|
21
|
+
readonly subtype: "receipt";
|
|
22
|
+
readonly merkleRoot: Uint8Array;
|
|
23
|
+
readonly token: Uint8Array;
|
|
24
|
+
};
|
|
25
|
+
export type CoverCellErrorCode = "authentication-failed" | "binding-mismatch" | "epoch-mismatch" | "invalid-cell" | "invalid-direction" | "invalid-padding" | "replayed-counter";
|
|
26
|
+
export declare class CoverCellError extends Error {
|
|
27
|
+
readonly code: CoverCellErrorCode;
|
|
28
|
+
constructor(code: CoverCellErrorCode, message: string);
|
|
29
|
+
}
|
|
30
|
+
export interface SealCoverCellOptions {
|
|
31
|
+
readonly module: LibCrypto;
|
|
32
|
+
readonly rootSuite: RatchetRootSuite;
|
|
33
|
+
/** Current epoch's PQ message root (borrowed; never wiped here). */
|
|
34
|
+
readonly rootKey: Uint8Array;
|
|
35
|
+
readonly binding: Uint8Array;
|
|
36
|
+
readonly direction: CoverCellDirection;
|
|
37
|
+
readonly keyEpoch: bigint;
|
|
38
|
+
/** Strictly increasing per-direction cover counter (replay ordering). */
|
|
39
|
+
readonly counter: bigint;
|
|
40
|
+
readonly content: CoverCellContent;
|
|
41
|
+
}
|
|
42
|
+
export interface OpenCoverCellOptions {
|
|
43
|
+
readonly module: LibCrypto;
|
|
44
|
+
readonly rootSuite: RatchetRootSuite;
|
|
45
|
+
readonly rootKey: Uint8Array;
|
|
46
|
+
readonly binding: Uint8Array;
|
|
47
|
+
/** Expected inbound direction; the opposite direction derives another key. */
|
|
48
|
+
readonly direction: CoverCellDirection;
|
|
49
|
+
readonly keyEpoch: bigint;
|
|
50
|
+
/** Highest already-accepted counter; the cell must be strictly newer. */
|
|
51
|
+
readonly counterAbove?: bigint;
|
|
52
|
+
readonly frame: Uint8Array;
|
|
53
|
+
}
|
|
54
|
+
export interface OpenedCoverCell {
|
|
55
|
+
readonly content: CoverCellContent;
|
|
56
|
+
readonly counter: bigint;
|
|
57
|
+
}
|
|
58
|
+
/** Seal one authenticated fixed-size cover cell (dummy, CANCEL, or receipt). */
|
|
59
|
+
export declare const sealCoverCell: (options: SealCoverCellOptions) => Uint8Array;
|
|
60
|
+
/**
|
|
61
|
+
* Authenticate one fixed-size cover cell and return its content. The subtype
|
|
62
|
+
* is knowable only after this authentication succeeds; an unauthentic cell
|
|
63
|
+
* reveals nothing and terminates nothing.
|
|
64
|
+
*/
|
|
65
|
+
export declare const openCoverCell: (options: OpenCoverCellOptions) => OpenedCoverCell;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { LibCrypto } from "./libcrypto";
|
|
2
|
+
/**
|
|
3
|
+
* CPace draft-21 prepend_len(): unsigned LEB128 byte length followed by value.
|
|
4
|
+
* Exported so the standards KAT can freeze the transcript encoding independently
|
|
5
|
+
* of the group operation.
|
|
6
|
+
*/
|
|
7
|
+
export declare const encodeCpaceLength: (length: number) => Uint8Array;
|
|
8
|
+
/**
|
|
9
|
+
* CPACE-RISTR255-SHA512 generator from draft-irtf-cfrg-cpace-21:
|
|
10
|
+
*
|
|
11
|
+
* generator_string =
|
|
12
|
+
* lv_cat(DSI, PRS, zero_bytes(len_zpad), CI, sid)
|
|
13
|
+
*
|
|
14
|
+
* where len_zpad fills the first SHA-512 input block after DSI and PRS.
|
|
15
|
+
*/
|
|
16
|
+
export declare const deriveGenerator: (pin: Uint8Array, sid: Uint8Array, channelInput: Uint8Array, module: LibCrypto) => Uint8Array;
|
|
17
|
+
/** y <- uniform non-zero ristretto255 scalar; Y = y*G. */
|
|
18
|
+
export declare const cpaceStart: (generator: Uint8Array, module: LibCrypto) => {
|
|
19
|
+
y: Uint8Array;
|
|
20
|
+
Y: Uint8Array;
|
|
21
|
+
};
|
|
22
|
+
export interface CpaceFinishParams {
|
|
23
|
+
/** Caller's one-use private scalar. */
|
|
24
|
+
y: Uint8Array;
|
|
25
|
+
/** Remote party's encoded Ristretto255 share. */
|
|
26
|
+
peerShare: Uint8Array;
|
|
27
|
+
/** Shared CPace session identifier. */
|
|
28
|
+
sid: Uint8Array;
|
|
29
|
+
/** Initiator and responder shares in protocol order. */
|
|
30
|
+
initiatorShare: Uint8Array;
|
|
31
|
+
responderShare: Uint8Array;
|
|
32
|
+
/** Optional associated data; identities are already role-bound in CI here. */
|
|
33
|
+
initiatorAssociatedData?: Uint8Array;
|
|
34
|
+
responderAssociatedData?: Uint8Array;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Finish draft-21 CPace and return only ISK. The intermediate shared point K
|
|
38
|
+
* never enters JavaScript and is wiped in WASM before return, as required by
|
|
39
|
+
* draft §10.3.
|
|
40
|
+
*/
|
|
41
|
+
export declare const cpaceFinish: (params: CpaceFinishParams, module: LibCrypto) => Uint8Array;
|
|
@@ -9,4 +9,3 @@ export declare const keyPairFromSecretKey: (secretKey: Uint8Array, module?: LibC
|
|
|
9
9
|
*/
|
|
10
10
|
export declare const sign: (message: Uint8Array, secretKey: Uint8Array, module?: LibCrypto) => Promise<Uint8Array>;
|
|
11
11
|
export declare const verify: (message: Uint8Array, signature: Uint8Array, publicKey: Uint8Array, module?: LibCrypto) => Promise<boolean>;
|
|
12
|
-
//# sourceMappingURL=ed25519.d.ts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { LibCrypto } from "./libcrypto";
|
|
2
|
+
/**
|
|
3
|
+
* Compute the plain SHA-512 of a File incrementally: read it one
|
|
4
|
+
* HASH_WINDOW_BYTES slice at a time (O(1) memory — the whole file is never
|
|
5
|
+
* resident) and feed each slice to the WASM streaming hash in
|
|
6
|
+
* HASH_WASM_CHUNK_BYTES sub-chunks (the WASM heap buffer is tiny and fixed,
|
|
7
|
+
* since the merkle module's memory cannot grow). The result is byte-identical
|
|
8
|
+
* to `crypto.subtle.digest("SHA-512", <whole file>)` (plain SHA-512, no domain
|
|
9
|
+
* separation), so it drops in for the previous whole-file-in-RAM digest.
|
|
10
|
+
*
|
|
11
|
+
* @param file - the File to hash (disk-backed; slices load lazily).
|
|
12
|
+
* @param module - a LibCrypto exposing _sha512_init/update/final + _malloc/_free.
|
|
13
|
+
* @returns the 64-byte SHA-512 digest.
|
|
14
|
+
*/
|
|
15
|
+
export declare const hashFileStreaming: (file: File, module: LibCrypto, signal?: AbortSignal) => Promise<Uint8Array>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { LibCrypto } from "./libcrypto";
|
|
2
|
+
/** The signed/verified transcript: IDENTITY_CROSS_SIGN_DOMAIN ‖ X25519_pub. */
|
|
3
|
+
export declare const identityCrossSignMessage: (x25519Pub: Uint8Array) => Uint8Array;
|
|
4
|
+
/** Produce the cross-signature over (DOMAIN ‖ x25519Pub) with the Ed25519 secret. */
|
|
5
|
+
export declare const crossSignIdentityX25519: (x25519Pub: Uint8Array, ed25519Secret: Uint8Array, module?: LibCrypto) => Promise<Uint8Array>;
|
|
6
|
+
/** Verify a cross-signature against the peer's pinned Ed25519 identity pub. */
|
|
7
|
+
export declare const verifyIdentityCrossSig: (x25519Pub: Uint8Array, crossSig: Uint8Array, ed25519Pub: Uint8Array, module?: LibCrypto) => Promise<boolean>;
|
|
@@ -1,25 +1,33 @@
|
|
|
1
1
|
export declare const crypto_auth_hmacsha512_BYTES: number;
|
|
2
2
|
export declare const crypto_auth_hmacsha512_KEYBYTES: number;
|
|
3
3
|
export declare const crypto_hash_sha512_BYTES: number;
|
|
4
|
+
export declare const crypto_hash_sha512_STATEBYTES = 208;
|
|
4
5
|
export declare const crypto_sign_ed25519_BYTES: number;
|
|
5
6
|
export declare const crypto_sign_ed25519_SEEDBYTES: number;
|
|
6
7
|
export declare const crypto_sign_ed25519_PUBLICKEYBYTES: number;
|
|
7
8
|
export declare const crypto_sign_ed25519_SECRETKEYBYTES: number;
|
|
8
9
|
export declare const crypto_secretbox_KEYBYTES: number;
|
|
9
10
|
export declare const crypto_secretbox_NONCEBYTES: number;
|
|
10
|
-
export declare const crypto_box_poly1305_AUTHTAGBYTES: number;
|
|
11
|
-
export declare const crypto_box_x25519_PUBLICKEYBYTES: number;
|
|
12
|
-
export declare const crypto_box_x25519_SECRETKEYBYTES: number;
|
|
13
|
-
export declare const crypto_box_x25519_NONCEBYTES: number;
|
|
14
11
|
export declare const crypto_aead_chacha20poly1305_ietf_KEYBYTES: number;
|
|
15
12
|
export declare const crypto_aead_chacha20poly1305_ietf_NPUBBYTES: number;
|
|
13
|
+
export declare const crypto_aead_chacha20poly1305_ietf_ABYTES: number;
|
|
16
14
|
export declare const crypto_pwhash_argon2id_SALTBYTES: number;
|
|
15
|
+
export declare const crypto_core_ristretto255_BYTES: number;
|
|
16
|
+
export declare const crypto_core_ristretto255_HASHBYTES: number;
|
|
17
|
+
export declare const crypto_core_ristretto255_SCALARBYTES: number;
|
|
18
|
+
export declare const crypto_scalarmult_ristretto255_BYTES: number;
|
|
19
|
+
export declare const crypto_scalarmult_curve25519_BYTES: number;
|
|
20
|
+
export declare const crypto_scalarmult_curve25519_SCALARBYTES: number;
|
|
21
|
+
export declare const mlkem768_PUBLICKEYBYTES: number;
|
|
22
|
+
export declare const mlkem768_SECRETKEYBYTES: number;
|
|
23
|
+
export declare const mlkem768_CIPHERTEXTBYTES: number;
|
|
24
|
+
export declare const mlkem768_BYTES: number;
|
|
25
|
+
export declare const mlkem768_KEYPAIRCOINBYTES: number;
|
|
26
|
+
export declare const mlkem768_ENCAPSCOINBYTES: number;
|
|
17
27
|
export interface SignKeyPair {
|
|
18
28
|
publicKey: Uint8Array;
|
|
19
29
|
secretKey: Uint8Array;
|
|
20
30
|
}
|
|
21
|
-
export declare const getEncryptedLen: (dataLen: number) => number;
|
|
22
|
-
export declare const getDecryptedLen: (encryptedLen: number) => number;
|
|
23
31
|
declare const _default: {
|
|
24
32
|
crypto_hash_sha512_BYTES: number;
|
|
25
33
|
crypto_sign_ed25519_BYTES: number;
|
|
@@ -28,13 +36,20 @@ declare const _default: {
|
|
|
28
36
|
crypto_sign_ed25519_SECRETKEYBYTES: number;
|
|
29
37
|
crypto_secretbox_KEYBYTES: number;
|
|
30
38
|
crypto_secretbox_NONCEBYTES: number;
|
|
31
|
-
crypto_box_poly1305_AUTHTAGBYTES: number;
|
|
32
|
-
crypto_box_x25519_PUBLICKEYBYTES: number;
|
|
33
|
-
crypto_box_x25519_SECRETKEYBYTES: number;
|
|
34
|
-
crypto_box_x25519_NONCEBYTES: number;
|
|
35
39
|
crypto_aead_chacha20poly1305_ietf_KEYBYTES: number;
|
|
36
|
-
|
|
37
|
-
|
|
40
|
+
crypto_aead_chacha20poly1305_ietf_NPUBBYTES: number;
|
|
41
|
+
crypto_aead_chacha20poly1305_ietf_ABYTES: number;
|
|
42
|
+
crypto_core_ristretto255_BYTES: number;
|
|
43
|
+
crypto_core_ristretto255_HASHBYTES: number;
|
|
44
|
+
crypto_core_ristretto255_SCALARBYTES: number;
|
|
45
|
+
crypto_scalarmult_ristretto255_BYTES: number;
|
|
46
|
+
crypto_scalarmult_curve25519_BYTES: number;
|
|
47
|
+
crypto_scalarmult_curve25519_SCALARBYTES: number;
|
|
48
|
+
mlkem768_PUBLICKEYBYTES: number;
|
|
49
|
+
mlkem768_SECRETKEYBYTES: number;
|
|
50
|
+
mlkem768_CIPHERTEXTBYTES: number;
|
|
51
|
+
mlkem768_BYTES: number;
|
|
52
|
+
mlkem768_KEYPAIRCOINBYTES: number;
|
|
53
|
+
mlkem768_ENCAPSCOINBYTES: number;
|
|
38
54
|
};
|
|
39
55
|
export default _default;
|
|
40
|
-
//# sourceMappingURL=interfaces.d.ts.map
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
declare const _default: {
|
|
2
2
|
newKeyPairMemory: () => WebAssembly.Memory;
|
|
3
|
+
identityX25519KeypairMemory: () => WebAssembly.Memory;
|
|
3
4
|
keyPairFromSeedMemory: () => WebAssembly.Memory;
|
|
4
5
|
keyPairFromSecretKeyMemory: () => WebAssembly.Memory;
|
|
5
6
|
signMemory: (messageLen: number) => WebAssembly.Memory;
|
|
6
7
|
verifyMemory: (messageLen: number) => WebAssembly.Memory;
|
|
7
|
-
|
|
8
|
-
decryptAsymmetricMemory: (encryptedLen: number, additionalDataLen: number) => WebAssembly.Memory;
|
|
8
|
+
protocolV3Memory: () => WebAssembly.Memory;
|
|
9
9
|
getMerkleRootMemory: (leavesLen: number) => WebAssembly.Memory;
|
|
10
10
|
getMerkleProofMemory: (leavesLen: number) => WebAssembly.Memory;
|
|
11
11
|
verifyMerkleProofMemory: (proofLen: number) => WebAssembly.Memory;
|
|
12
12
|
argon2Memory: (mnemonicLen: number) => WebAssembly.Memory;
|
|
13
|
-
getReceiveMessageMemory: () => WebAssembly.Memory;
|
|
14
13
|
};
|
|
15
14
|
export default _default;
|
|
16
|
-
//# sourceMappingURL=memory.d.ts.map
|
|
@@ -40,4 +40,3 @@ export declare const getMerkleRootFromProof: (item: Uint8Array, proof: Uint8Arra
|
|
|
40
40
|
* byte is either 0 or 1, indicating whether it is to the left or to the right in the tree.
|
|
41
41
|
*/
|
|
42
42
|
export declare const verifyMerkleProof: (item: Uint8Array, root: Uint8Array, proof: Uint8Array, module?: LibCrypto) => Promise<boolean>;
|
|
43
|
-
//# sourceMappingURL=merkle.d.ts.map
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { LibCrypto } from "./libcrypto";
|
|
2
|
+
export type MlKemParameterSet = 512 | 768 | 1024;
|
|
3
|
+
export declare const ML_KEM_512_PUBLIC_KEY_BYTES = 800;
|
|
4
|
+
export declare const ML_KEM_512_SECRET_KEY_BYTES = 1632;
|
|
5
|
+
export declare const ML_KEM_512_CIPHERTEXT_BYTES = 768;
|
|
6
|
+
export declare const ML_KEM_768_PUBLIC_KEY_BYTES = 1184;
|
|
7
|
+
export declare const ML_KEM_768_SECRET_KEY_BYTES = 2400;
|
|
8
|
+
export declare const ML_KEM_768_CIPHERTEXT_BYTES = 1088;
|
|
9
|
+
export declare const ML_KEM_1024_PUBLIC_KEY_BYTES = 1568;
|
|
10
|
+
export declare const ML_KEM_1024_SECRET_KEY_BYTES = 3168;
|
|
11
|
+
export declare const ML_KEM_1024_CIPHERTEXT_BYTES = 1568;
|
|
12
|
+
export declare const ML_KEM_SHARED_SECRET_BYTES = 32;
|
|
13
|
+
export declare const ML_KEM_KEYPAIR_RANDOM_BYTES = 64;
|
|
14
|
+
export declare const ML_KEM_ENCAPS_RANDOM_BYTES = 32;
|
|
15
|
+
type MlKemKeyPairExport<P extends MlKemParameterSet> = `_mlkem${P}_keypair`;
|
|
16
|
+
type MlKemEncapsExport<P extends MlKemParameterSet> = `_mlkem${P}_encaps`;
|
|
17
|
+
type MlKemDecapsExport<P extends MlKemParameterSet> = `_mlkem${P}_decaps`;
|
|
18
|
+
/**
|
|
19
|
+
* Complete runtime description of one FIPS 203 parameter set.
|
|
20
|
+
*
|
|
21
|
+
* The sizes are carried with the selected suite so callers cannot
|
|
22
|
+
* accidentally validate an ML-KEM-512 key with ML-KEM-768 constants.
|
|
23
|
+
*/
|
|
24
|
+
export interface MlKemSuiteDescriptor<P extends MlKemParameterSet = MlKemParameterSet> {
|
|
25
|
+
readonly parameterSet: P;
|
|
26
|
+
readonly standardName: `ML-KEM-${P}`;
|
|
27
|
+
readonly publicKeyBytes: number;
|
|
28
|
+
readonly secretKeyBytes: number;
|
|
29
|
+
readonly ciphertextBytes: number;
|
|
30
|
+
readonly sharedSecretBytes: typeof ML_KEM_SHARED_SECRET_BYTES;
|
|
31
|
+
readonly keyPairRandomBytes: typeof ML_KEM_KEYPAIR_RANDOM_BYTES;
|
|
32
|
+
readonly encapsRandomBytes: typeof ML_KEM_ENCAPS_RANDOM_BYTES;
|
|
33
|
+
readonly wasmExports: {
|
|
34
|
+
readonly keypair: MlKemKeyPairExport<P>;
|
|
35
|
+
readonly encaps: MlKemEncapsExport<P>;
|
|
36
|
+
readonly decaps: MlKemDecapsExport<P>;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export declare const ML_KEM_512_SUITE: Readonly<MlKemSuiteDescriptor<512>>;
|
|
40
|
+
export declare const ML_KEM_768_SUITE: Readonly<MlKemSuiteDescriptor<768>>;
|
|
41
|
+
export declare const ML_KEM_1024_SUITE: Readonly<MlKemSuiteDescriptor<1024>>;
|
|
42
|
+
export declare const ML_KEM_SUITES: Readonly<{
|
|
43
|
+
512: Readonly<MlKemSuiteDescriptor<512>>;
|
|
44
|
+
768: Readonly<MlKemSuiteDescriptor<768>>;
|
|
45
|
+
1024: Readonly<MlKemSuiteDescriptor<1024>>;
|
|
46
|
+
}>;
|
|
47
|
+
export declare const getMlKemSuite: <P extends MlKemParameterSet>(parameterSet: P) => Readonly<MlKemSuiteDescriptor<P>>;
|
|
48
|
+
type MlKemKeyPairFunction = (publicKey: number, secretKey: number, coins64: number) => number;
|
|
49
|
+
type MlKemEncapsFunction = (ciphertext: number, sharedSecret: number, publicKey: number, coins32: number) => number;
|
|
50
|
+
type MlKemDecapsFunction = (sharedSecret: number, ciphertext: number, secretKey: number) => number;
|
|
51
|
+
/**
|
|
52
|
+
* The deterministic ABI exported by the pinned, portable mlkem-native build.
|
|
53
|
+
* JavaScript supplies all entropy; the WASM has no second RNG path.
|
|
54
|
+
*/
|
|
55
|
+
export interface MlKemModule extends LibCrypto {
|
|
56
|
+
_mlkem512_keypair: MlKemKeyPairFunction;
|
|
57
|
+
_mlkem512_encaps: MlKemEncapsFunction;
|
|
58
|
+
_mlkem512_decaps: MlKemDecapsFunction;
|
|
59
|
+
_mlkem768_keypair: MlKemKeyPairFunction;
|
|
60
|
+
_mlkem768_encaps: MlKemEncapsFunction;
|
|
61
|
+
_mlkem768_decaps: MlKemDecapsFunction;
|
|
62
|
+
_mlkem1024_keypair: MlKemKeyPairFunction;
|
|
63
|
+
_mlkem1024_encaps: MlKemEncapsFunction;
|
|
64
|
+
_mlkem1024_decaps: MlKemDecapsFunction;
|
|
65
|
+
}
|
|
66
|
+
/** Compatibility type for protocol-v3 code while suite negotiation lands. */
|
|
67
|
+
export type MlKem768Module = LibCrypto & Pick<MlKemModule, "_mlkem768_keypair" | "_mlkem768_encaps" | "_mlkem768_decaps">;
|
|
68
|
+
export interface MlKemKeyPair {
|
|
69
|
+
/** A copy suitable for transport or serialization. This is not secret. */
|
|
70
|
+
readonly publicKey: Uint8Array;
|
|
71
|
+
/**
|
|
72
|
+
* Plaintext secret key bytes suitable for encrypted serialization.
|
|
73
|
+
* Call destroy() as soon as the key is no longer needed.
|
|
74
|
+
*/
|
|
75
|
+
readonly secretKey: Uint8Array;
|
|
76
|
+
readonly destroyed: boolean;
|
|
77
|
+
/** Idempotently wipes this object's secretKey bytes. */
|
|
78
|
+
destroy(): void;
|
|
79
|
+
}
|
|
80
|
+
export interface MlKemEncapsulation {
|
|
81
|
+
/** A copy suitable for transport or serialization. This is not secret. */
|
|
82
|
+
readonly ciphertext: Uint8Array;
|
|
83
|
+
/** Plaintext shared-secret bytes. Mix into a KDF, then call destroy(). */
|
|
84
|
+
readonly sharedSecret: Uint8Array;
|
|
85
|
+
readonly destroyed: boolean;
|
|
86
|
+
/** Idempotently wipes this object's sharedSecret bytes. */
|
|
87
|
+
destroy(): void;
|
|
88
|
+
}
|
|
89
|
+
export interface MlKemDecapsulation {
|
|
90
|
+
/** Plaintext shared-secret bytes. Mix into a KDF, then call destroy(). */
|
|
91
|
+
readonly sharedSecret: Uint8Array;
|
|
92
|
+
readonly destroyed: boolean;
|
|
93
|
+
/** Idempotently wipes this object's sharedSecret bytes. */
|
|
94
|
+
destroy(): void;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Async-compatible ML-KEM API. The WASM calls are synchronous, but promises
|
|
98
|
+
* allow a worker-backed implementation without changing protocol state
|
|
99
|
+
* machines.
|
|
100
|
+
*/
|
|
101
|
+
export interface MlKemBackend<P extends MlKemParameterSet = MlKemParameterSet> {
|
|
102
|
+
readonly suite: Readonly<MlKemSuiteDescriptor<P>>;
|
|
103
|
+
generateKeyPair(): Promise<MlKemKeyPair>;
|
|
104
|
+
encapsulate(publicKey: Uint8Array): Promise<MlKemEncapsulation>;
|
|
105
|
+
decapsulate(ciphertext: Uint8Array, secretKey: Uint8Array): Promise<MlKemDecapsulation>;
|
|
106
|
+
}
|
|
107
|
+
/** Compatibility aliases for the currently shipped ML-KEM-768 handshake. */
|
|
108
|
+
export type MlKem768KeyPair = MlKemKeyPair;
|
|
109
|
+
export type MlKem768Encapsulation = MlKemEncapsulation;
|
|
110
|
+
export type MlKem768Decapsulation = MlKemDecapsulation;
|
|
111
|
+
export type MlKem768Backend = MlKemBackend<768>;
|
|
112
|
+
export declare const createMlKemBackend: <P extends MlKemParameterSet>(module: LibCrypto, suite: Readonly<MlKemSuiteDescriptor<P>>) => MlKemBackend<P>;
|
|
113
|
+
/**
|
|
114
|
+
* Temporary compatibility factory for the protocol-v3 ML-KEM-768 wire suite.
|
|
115
|
+
*/
|
|
116
|
+
export declare const createMlKem768Backend: (module: LibCrypto) => MlKem768Backend;
|
|
117
|
+
export {};
|
|
@@ -27,4 +27,3 @@ export declare const validateMnemonic: (mnemonic: string) => Promise<boolean>;
|
|
|
27
27
|
* @returns An Ed25519 key pair
|
|
28
28
|
*/
|
|
29
29
|
export declare const keyPairFromMnemonic: (mnemonic: string, password?: string) => Promise<import("./interfaces").SignKeyPair>;
|
|
30
|
-
//# sourceMappingURL=mnemonic.d.ts.map
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import { type MlKemBackend, type MlKemParameterSet, type MlKemSuiteDescriptor } from "./mlkem";
|
|
2
|
+
import type { LibCrypto } from "./libcrypto";
|
|
3
|
+
/**
|
|
4
|
+
* Sparse post-quantum healing state machine.
|
|
5
|
+
*
|
|
6
|
+
* This module deliberately does not own transport or persistence. Callers must:
|
|
7
|
+
*
|
|
8
|
+
* 1. authenticate/decrypt every inbound record with the current outer channel
|
|
9
|
+
* before calling an `acceptAuthenticated*` method;
|
|
10
|
+
* 2. persist prepared state before putting its record on the network;
|
|
11
|
+
* 3. encrypt an ADVANCE under its `fromEpoch` key before committing it; and
|
|
12
|
+
* 4. gate application traffic while `trafficBlocked` is true.
|
|
13
|
+
*
|
|
14
|
+
* There is no classical or lower-parameter fallback. The room-selected suite
|
|
15
|
+
* supplied to the constructor is checked against both FIPS 203 sizes and the
|
|
16
|
+
* backend. Every ADVANCE embeds the complete OFFER it answers. That makes the
|
|
17
|
+
* exact suite, channel binding, epochs, counters, public key, and ciphertext a
|
|
18
|
+
* single deterministic KDF transcript and gives the state machine an exact
|
|
19
|
+
* byte string with which to reject replays and forks.
|
|
20
|
+
*/
|
|
21
|
+
export declare const PQ_HEALING_BINDING_BYTES = 32;
|
|
22
|
+
export declare const PQ_HEALING_ROOT_BYTES = 32;
|
|
23
|
+
export declare const PQ_HEALING_RECORD_HEADER_BYTES = 64;
|
|
24
|
+
export declare const PQ_HEALING_ACK_BYTES = 64;
|
|
25
|
+
export declare const PQ_HEALING_SNAPSHOT_FORMAT_VERSION = 1;
|
|
26
|
+
export type PqHealingTurn = "local" | "remote";
|
|
27
|
+
export type PqHealingPhase = "idle" | "outbound-offer-prepared" | "outbound-offer-dispatched" | "inbound-offer" | "outbound-advance-prepared" | "outbound-advance-awaiting-ack" | "inbound-advance-prepared" | "inbound-advance-awaiting-ack-dispatch" | "destroyed";
|
|
28
|
+
export type PqHealingErrorCode = "binding-mismatch" | "counter-gap" | "destroyed" | "epoch-gap" | "fork" | "invalid-record" | "invalid-state" | "overflow" | "replay" | "suite-mismatch" | "wrong-turn";
|
|
29
|
+
export declare class PqHealingError extends Error {
|
|
30
|
+
readonly code: PqHealingErrorCode;
|
|
31
|
+
constructor(code: PqHealingErrorCode, message: string);
|
|
32
|
+
}
|
|
33
|
+
export interface PqHealingAdvanceAcknowledgement {
|
|
34
|
+
/**
|
|
35
|
+
* The newly committed epoch. The transport acknowledgement must be
|
|
36
|
+
* authenticated under this epoch, proving that the offerer decapsulated.
|
|
37
|
+
*/
|
|
38
|
+
readonly epoch: bigint;
|
|
39
|
+
/** Sender counter of the ADVANCE being acknowledged. */
|
|
40
|
+
readonly advanceCounter: bigint;
|
|
41
|
+
}
|
|
42
|
+
export interface PqHealingOfferRecord {
|
|
43
|
+
readonly type: "offer";
|
|
44
|
+
readonly parameterSet: MlKemParameterSet;
|
|
45
|
+
readonly binding: Uint8Array;
|
|
46
|
+
readonly senderCounter: bigint;
|
|
47
|
+
readonly fromEpoch: bigint;
|
|
48
|
+
readonly toEpoch: bigint;
|
|
49
|
+
readonly publicKey: Uint8Array;
|
|
50
|
+
}
|
|
51
|
+
export interface PqHealingAdvanceRecord {
|
|
52
|
+
readonly type: "advance";
|
|
53
|
+
readonly parameterSet: MlKemParameterSet;
|
|
54
|
+
readonly binding: Uint8Array;
|
|
55
|
+
readonly senderCounter: bigint;
|
|
56
|
+
readonly fromEpoch: bigint;
|
|
57
|
+
readonly toEpoch: bigint;
|
|
58
|
+
/** The complete, canonical OFFER answered by this record. */
|
|
59
|
+
readonly offerBytes: Uint8Array;
|
|
60
|
+
readonly offer: PqHealingOfferRecord;
|
|
61
|
+
readonly ciphertext: Uint8Array;
|
|
62
|
+
}
|
|
63
|
+
export type PqHealingRecord = PqHealingOfferRecord | PqHealingAdvanceRecord;
|
|
64
|
+
export interface PqHealingMachineOptions<P extends MlKemParameterSet> {
|
|
65
|
+
readonly module: LibCrypto;
|
|
66
|
+
readonly backend: MlKemBackend<P>;
|
|
67
|
+
/**
|
|
68
|
+
* Authenticated room-selected suite. This is an input, never a negotiated
|
|
69
|
+
* result. It must exactly match the backend's parameter set and FIPS sizes.
|
|
70
|
+
*/
|
|
71
|
+
readonly suite: Readonly<MlKemSuiteDescriptor<P>>;
|
|
72
|
+
/**
|
|
73
|
+
* Non-secret, transcript-derived edge binding (for example a truncation of
|
|
74
|
+
* the authenticated handshake/channel-input hash).
|
|
75
|
+
*/
|
|
76
|
+
readonly binding: Uint8Array;
|
|
77
|
+
/** Current, separate PQ root. The constructor takes an owned copy. */
|
|
78
|
+
readonly rootKey: Uint8Array;
|
|
79
|
+
/** Which side is allowed to emit the first/next OFFER. */
|
|
80
|
+
readonly nextOfferer: PqHealingTurn;
|
|
81
|
+
readonly epoch?: bigint;
|
|
82
|
+
readonly localCounter?: bigint;
|
|
83
|
+
readonly remoteCounter?: bigint;
|
|
84
|
+
}
|
|
85
|
+
export interface PqHealingRestoreOptions<P extends MlKemParameterSet> {
|
|
86
|
+
readonly module: LibCrypto;
|
|
87
|
+
readonly backend: MlKemBackend<P>;
|
|
88
|
+
readonly suite: Readonly<MlKemSuiteDescriptor<P>>;
|
|
89
|
+
/** Authenticated expected edge binding; snapshots from another edge fail. */
|
|
90
|
+
readonly binding: Uint8Array;
|
|
91
|
+
}
|
|
92
|
+
export type PqHealingSnapshotPhase = {
|
|
93
|
+
readonly kind: "idle";
|
|
94
|
+
} | {
|
|
95
|
+
readonly kind: "outbound-offer-prepared" | "outbound-offer-dispatched";
|
|
96
|
+
readonly offer: Uint8Array;
|
|
97
|
+
readonly secretKey: Uint8Array;
|
|
98
|
+
} | {
|
|
99
|
+
readonly kind: "inbound-offer";
|
|
100
|
+
readonly offer: Uint8Array;
|
|
101
|
+
} | {
|
|
102
|
+
readonly kind: "outbound-advance-prepared";
|
|
103
|
+
readonly advance: Uint8Array;
|
|
104
|
+
readonly nextRoot: Uint8Array;
|
|
105
|
+
} | {
|
|
106
|
+
readonly kind: "outbound-advance-awaiting-ack";
|
|
107
|
+
readonly advance: Uint8Array;
|
|
108
|
+
} | {
|
|
109
|
+
readonly kind: "inbound-advance-prepared";
|
|
110
|
+
readonly advance: Uint8Array;
|
|
111
|
+
readonly secretKey: Uint8Array;
|
|
112
|
+
readonly nextRoot: Uint8Array;
|
|
113
|
+
} | {
|
|
114
|
+
readonly kind: "inbound-advance-awaiting-ack-dispatch";
|
|
115
|
+
readonly advance: Uint8Array;
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Owned, plaintext checkpoint of the complete store-free PQ machine.
|
|
119
|
+
*
|
|
120
|
+
* Durable integration normally checkpoints only phases whose corresponding
|
|
121
|
+
* sealed outbox frame is committed in the same transaction. The two
|
|
122
|
+
* `*-prepared` phases are intentionally representable for clone/rollback and
|
|
123
|
+
* fault-injection tests, but are transaction-local and must never be persisted
|
|
124
|
+
* alone or dispatched after restoration without the exact sealed frame.
|
|
125
|
+
*/
|
|
126
|
+
export interface PqHealingSnapshot<P extends MlKemParameterSet = MlKemParameterSet> {
|
|
127
|
+
readonly formatVersion: typeof PQ_HEALING_SNAPSHOT_FORMAT_VERSION;
|
|
128
|
+
readonly parameterSet: P;
|
|
129
|
+
readonly binding: Uint8Array;
|
|
130
|
+
readonly rootKey: Uint8Array;
|
|
131
|
+
readonly epoch: bigint;
|
|
132
|
+
readonly localCounter: bigint;
|
|
133
|
+
readonly remoteCounter: bigint;
|
|
134
|
+
readonly nextOfferer: PqHealingTurn;
|
|
135
|
+
readonly phase: PqHealingSnapshotPhase;
|
|
136
|
+
readonly lastInboundOffer: Uint8Array | null;
|
|
137
|
+
readonly lastInboundAdvance: Uint8Array | null;
|
|
138
|
+
}
|
|
139
|
+
export declare const getPqHealingRecordLengths: (suite: Readonly<MlKemSuiteDescriptor>) => {
|
|
140
|
+
readonly offer: number;
|
|
141
|
+
readonly advance: number;
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* Encode the sole canonical PQ acknowledgement representation:
|
|
145
|
+
*
|
|
146
|
+
* `magic(4) | version(1) | type(1) | suite(1) | flags(1) | binding(32) |
|
|
147
|
+
* advanceCounter(u64 BE) | epoch(u64 BE) | reserved(u64=0)`.
|
|
148
|
+
*/
|
|
149
|
+
export declare const encodePqHealingAck: (acknowledgement: unknown, suite: Readonly<MlKemSuiteDescriptor>, binding: Uint8Array) => Uint8Array;
|
|
150
|
+
/** Decode and validate an exact, edge- and suite-bound 64-byte ACK. */
|
|
151
|
+
export declare const decodePqHealingAck: (record: Uint8Array, suite: Readonly<MlKemSuiteDescriptor>, binding: Uint8Array) => PqHealingAdvanceAcknowledgement;
|
|
152
|
+
/**
|
|
153
|
+
* Parse a canonical record without changing state. Integration code can use
|
|
154
|
+
* this for routing and audit logs, but MUST still call the stateful
|
|
155
|
+
* `acceptAuthenticated*` method only after outer authentication.
|
|
156
|
+
*/
|
|
157
|
+
export declare const inspectPqHealingRecord: (record: Uint8Array, suite: Readonly<MlKemSuiteDescriptor>) => PqHealingRecord;
|
|
158
|
+
/**
|
|
159
|
+
* One directional-turn PQ healing machine for a single authenticated peer
|
|
160
|
+
* edge. A room mesh owns one instance per edge; a room-wide policy supplies
|
|
161
|
+
* the same exact ML-KEM parameter set to every instance.
|
|
162
|
+
*/
|
|
163
|
+
export declare class PqHealingMachine<P extends MlKemParameterSet> {
|
|
164
|
+
#private;
|
|
165
|
+
constructor(options: PqHealingMachineOptions<P>);
|
|
166
|
+
static restore<Q extends MlKemParameterSet>(snapshot: unknown, options: PqHealingRestoreOptions<Q>): PqHealingMachine<Q>;
|
|
167
|
+
get suite(): Readonly<MlKemSuiteDescriptor<P>>;
|
|
168
|
+
get phase(): PqHealingPhase;
|
|
169
|
+
get epoch(): bigint;
|
|
170
|
+
get localCounter(): bigint;
|
|
171
|
+
get remoteCounter(): bigint;
|
|
172
|
+
get nextOfferer(): PqHealingTurn;
|
|
173
|
+
/**
|
|
174
|
+
* New-epoch messages must not race the control exchange across independent
|
|
175
|
+
* WebRTC data channels. The integration must hold application traffic while
|
|
176
|
+
* this is true.
|
|
177
|
+
*/
|
|
178
|
+
get trafficBlocked(): boolean;
|
|
179
|
+
/** Explicit owned copy for the message-key combiner or encrypted checkpoint. */
|
|
180
|
+
copyRootKey(): Uint8Array;
|
|
181
|
+
/**
|
|
182
|
+
* Deep-copy the complete checkpoint, including pending ML-KEM secret keys.
|
|
183
|
+
* See `PqHealingSnapshot`: prepared phases are transaction-local snapshots.
|
|
184
|
+
*/
|
|
185
|
+
snapshot(): PqHealingSnapshot<P>;
|
|
186
|
+
/** Deep-clone this machine into independently owned secret buffers. */
|
|
187
|
+
clone(): PqHealingMachine<P>;
|
|
188
|
+
/**
|
|
189
|
+
* Consume an independently authenticated successor. Superseded live secrets
|
|
190
|
+
* are wiped and `next` becomes destroyed without wiping the moved secrets.
|
|
191
|
+
*/
|
|
192
|
+
adopt(next: PqHealingMachine<P>): void;
|
|
193
|
+
/**
|
|
194
|
+
* Return the exact public record that should be sent/retransmitted. A caller
|
|
195
|
+
* must never reconstruct a replacement after the original may have escaped.
|
|
196
|
+
*/
|
|
197
|
+
copyPendingOutboundRecord(): Uint8Array;
|
|
198
|
+
prepareOffer(): Promise<Uint8Array>;
|
|
199
|
+
/**
|
|
200
|
+
* Mark the persisted OFFER as having possibly escaped to the network. After
|
|
201
|
+
* this point it cannot be aborted or replaced; only its exact bytes may be
|
|
202
|
+
* retransmitted.
|
|
203
|
+
*/
|
|
204
|
+
markOfferDispatched(): void;
|
|
205
|
+
/**
|
|
206
|
+
* Safe only while the caller can prove the OFFER has never been sent.
|
|
207
|
+
* The pending ML-KEM secret key is wiped.
|
|
208
|
+
*/
|
|
209
|
+
abortUnsentOffer(): void;
|
|
210
|
+
/**
|
|
211
|
+
* Accept a full OFFER only after the outer AEAD has authenticated it.
|
|
212
|
+
*/
|
|
213
|
+
acceptAuthenticatedOffer(record: Uint8Array): void;
|
|
214
|
+
/**
|
|
215
|
+
* Prepare an ADVANCE and its candidate root. The caller must outer-encrypt
|
|
216
|
+
* this exact record under `fromEpoch` before committing, then persist the
|
|
217
|
+
* committed state and sealed record before sending.
|
|
218
|
+
*/
|
|
219
|
+
prepareAdvance(): Promise<Uint8Array>;
|
|
220
|
+
/**
|
|
221
|
+
* Commit the prepared root after the exact ADVANCE has already been sealed
|
|
222
|
+
* under the old epoch. The returned record is the only record that may be
|
|
223
|
+
* sent. Application traffic remains blocked until a new-epoch authenticated
|
|
224
|
+
* acknowledgement is accepted.
|
|
225
|
+
*/
|
|
226
|
+
commitPreparedAdvance(): Uint8Array;
|
|
227
|
+
/**
|
|
228
|
+
* Close the responder side only after an acknowledgement authenticated under
|
|
229
|
+
* the new epoch has been received. Exact epoch/counter binding prevents an
|
|
230
|
+
* unrelated transport receipt from unlocking the next OFFER.
|
|
231
|
+
*/
|
|
232
|
+
acceptAuthenticatedAdvanceAcknowledgement(acknowledgement: unknown): void;
|
|
233
|
+
/**
|
|
234
|
+
* Accept a full ADVANCE only after its outer AEAD has authenticated it under
|
|
235
|
+
* the old epoch.
|
|
236
|
+
*/
|
|
237
|
+
acceptAuthenticatedAdvance(record: Uint8Array): Promise<void>;
|
|
238
|
+
/**
|
|
239
|
+
* Commit a successfully decapsulated ADVANCE. The returned binding must be
|
|
240
|
+
* carried by an acknowledgement authenticated under the new epoch. Traffic
|
|
241
|
+
* remains blocked until `markAdvanceAcknowledgementDispatched` is called.
|
|
242
|
+
*/
|
|
243
|
+
commitAcceptedAdvance(): PqHealingAdvanceAcknowledgement;
|
|
244
|
+
/**
|
|
245
|
+
* Mark the new-epoch acknowledgement as having escaped to the network.
|
|
246
|
+
* Integration should persist that fact or retain a transport receipt cache
|
|
247
|
+
* so an exact ADVANCE replay can be answered without rolling state back.
|
|
248
|
+
*/
|
|
249
|
+
markAdvanceAcknowledgementDispatched(acknowledgement: unknown): void;
|
|
250
|
+
/**
|
|
251
|
+
* Idempotent terminal cleanup. All live roots, candidate roots, and pending
|
|
252
|
+
* ML-KEM secret keys are wiped. Public record copies may remain with callers.
|
|
253
|
+
*/
|
|
254
|
+
destroy(): void;
|
|
255
|
+
}
|
|
256
|
+
/** Store-free checkpoint helper with an owned result. */
|
|
257
|
+
export declare const snapshotPqHealing: <P extends MlKemParameterSet>(machine: PqHealingMachine<P>) => PqHealingSnapshot<P>;
|
|
258
|
+
/** Restore only after validating suite, binding, records, and phase invariants. */
|
|
259
|
+
export declare const restorePqHealing: <P extends MlKemParameterSet>(snapshot: unknown, options: PqHealingRestoreOptions<P>) => PqHealingMachine<P>;
|
|
260
|
+
/** Deep-clone for mutate/persist/adopt transaction flows. */
|
|
261
|
+
export declare const clonePqHealing: <P extends MlKemParameterSet>(machine: PqHealingMachine<P>) => PqHealingMachine<P>;
|
|
262
|
+
/** Consume `next` as the independently authenticated successor of `live`. */
|
|
263
|
+
export declare const adoptPqHealing: <P extends MlKemParameterSet>(live: PqHealingMachine<P>, next: PqHealingMachine<P>) => void;
|
|
264
|
+
/**
|
|
265
|
+
* Wipe every byte buffer owned by a plaintext checkpoint, including the PQ
|
|
266
|
+
* root, pending KEM secret key/candidate root, binding, and public records.
|
|
267
|
+
*/
|
|
268
|
+
export declare const wipePqHealingSnapshot: (snapshot: PqHealingSnapshot) => void;
|