@continuonai/rcan-ts 1.1.0 → 1.2.0
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/dist/browser.d.mts +90 -3
- package/dist/browser.mjs +169 -4
- package/dist/browser.mjs.map +1 -1
- package/dist/index.d.mts +90 -3
- package/dist/index.d.ts +90 -3
- package/dist/index.js +173 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +169 -4
- package/dist/index.mjs.map +1 -1
- package/dist/rcan-validate.js +7 -2
- package/dist/rcan.iife.js +16 -3
- package/package.json +28 -5
package/dist/browser.d.mts
CHANGED
|
@@ -114,6 +114,12 @@ interface SignatureBlock {
|
|
|
114
114
|
kid: string;
|
|
115
115
|
sig: string;
|
|
116
116
|
}
|
|
117
|
+
/** v2.2: Post-quantum (ML-DSA-65) signature block */
|
|
118
|
+
interface PQSignatureBlock {
|
|
119
|
+
alg: "ml-dsa-65";
|
|
120
|
+
kid: string;
|
|
121
|
+
sig: string;
|
|
122
|
+
}
|
|
117
123
|
interface RCANMessageData {
|
|
118
124
|
rcan?: string;
|
|
119
125
|
/** v1.5: explicit protocol version field (defaults to SPEC_VERSION) */
|
|
@@ -152,6 +158,8 @@ interface RCANMessageData {
|
|
|
152
158
|
firmwareHash?: string;
|
|
153
159
|
/** v2.1: URI to sender's SBOM attestation endpoint (envelope field 14). Required at L2+. */
|
|
154
160
|
attestationRef?: string;
|
|
161
|
+
/** v2.2: ML-DSA-65 post-quantum signature block (field 16, FIPS 204). Hybrid mode alongside Ed25519. */
|
|
162
|
+
pqSig?: PQSignatureBlock | undefined;
|
|
155
163
|
[key: string]: unknown;
|
|
156
164
|
}
|
|
157
165
|
declare class RCANMessageError extends Error {
|
|
@@ -188,6 +196,8 @@ declare class RCANMessage {
|
|
|
188
196
|
readonly firmwareHash: string | undefined;
|
|
189
197
|
/** v2.1: URI to sender's SBOM attestation endpoint */
|
|
190
198
|
readonly attestationRef: string | undefined;
|
|
199
|
+
/** v2.2: ML-DSA-65 post-quantum signature (field 16, FIPS 204). Hybrid alongside Ed25519. */
|
|
200
|
+
readonly pqSig: PQSignatureBlock | undefined;
|
|
191
201
|
constructor(data: RCANMessageData);
|
|
192
202
|
/** Whether this message has a signature block */
|
|
193
203
|
get isSigned(): boolean;
|
|
@@ -755,9 +765,9 @@ declare function makeTransparencyMessage(ruri: string, disclosure: string, deleg
|
|
|
755
765
|
* §3.5 — Protocol Version Compatibility
|
|
756
766
|
*/
|
|
757
767
|
/** The RCAN spec version this SDK implements. */
|
|
758
|
-
declare const SPEC_VERSION = "2.
|
|
768
|
+
declare const SPEC_VERSION = "2.2.0";
|
|
759
769
|
/** The SDK release version. */
|
|
760
|
-
declare const SDK_VERSION = "1.
|
|
770
|
+
declare const SDK_VERSION = "1.2.0";
|
|
761
771
|
/**
|
|
762
772
|
* Validate version compatibility.
|
|
763
773
|
*
|
|
@@ -1852,6 +1862,83 @@ declare function verifyM2mTrustedToken(token: string, targetRrn: string, options
|
|
|
1852
1862
|
skipRevocationCheck?: boolean;
|
|
1853
1863
|
}): Promise<M2MTrustedClaims>;
|
|
1854
1864
|
|
|
1865
|
+
/**
|
|
1866
|
+
* RCAN v2.2 Post-Quantum Hybrid Signing — ML-DSA-65 (NIST FIPS 204)
|
|
1867
|
+
*
|
|
1868
|
+
* Provides MLDSAKeyPair for post-quantum signing alongside the existing
|
|
1869
|
+
* Ed25519 SignatureBlock. In hybrid mode a message carries both:
|
|
1870
|
+
* - `signature` — Ed25519 SignatureBlock (backward-compat with v2.1)
|
|
1871
|
+
* - `pqSig` — MLDSASignatureBlock (new in v2.2)
|
|
1872
|
+
*
|
|
1873
|
+
* Key sizes (ML-DSA-65, NIST security level 3):
|
|
1874
|
+
* Public key: 1952 bytes
|
|
1875
|
+
* Private key: 4032 bytes
|
|
1876
|
+
* Signature: 3309 bytes
|
|
1877
|
+
*
|
|
1878
|
+
* Requires: @noble/post-quantum (npm install @noble/post-quantum)
|
|
1879
|
+
*
|
|
1880
|
+
* Spec: https://rcan.dev/spec#section-7-2
|
|
1881
|
+
*/
|
|
1882
|
+
|
|
1883
|
+
/** @deprecated use PQSignatureBlock */
|
|
1884
|
+
type MLDSASignatureBlock = PQSignatureBlock;
|
|
1885
|
+
interface MLDSAKeyPairData {
|
|
1886
|
+
/** Public key bytes (1952 bytes) */
|
|
1887
|
+
publicKey: Uint8Array;
|
|
1888
|
+
/** Private key bytes (4032 bytes). Absent for verify-only key pairs. */
|
|
1889
|
+
secretKey?: Uint8Array;
|
|
1890
|
+
/** 8-char hex key ID */
|
|
1891
|
+
keyId: string;
|
|
1892
|
+
}
|
|
1893
|
+
/**
|
|
1894
|
+
* An ML-DSA-65 (CRYSTALS-Dilithium, NIST FIPS 204) key pair.
|
|
1895
|
+
*
|
|
1896
|
+
* Immutable value object. Build via {@link MLDSAKeyPair.generate} or
|
|
1897
|
+
* {@link MLDSAKeyPair.fromPublicKey}.
|
|
1898
|
+
*/
|
|
1899
|
+
declare class MLDSAKeyPair {
|
|
1900
|
+
readonly keyId: string;
|
|
1901
|
+
readonly publicKey: Uint8Array;
|
|
1902
|
+
readonly secretKey: Uint8Array | undefined;
|
|
1903
|
+
private constructor();
|
|
1904
|
+
/** Generate a new ML-DSA-65 key pair. */
|
|
1905
|
+
static generate(): Promise<MLDSAKeyPair>;
|
|
1906
|
+
/** Build a verify-only key pair from raw public key bytes. */
|
|
1907
|
+
static fromPublicKey(publicKey: Uint8Array): Promise<MLDSAKeyPair>;
|
|
1908
|
+
/** Build a full key pair from saved bytes (public + secret). */
|
|
1909
|
+
static fromKeyMaterial(publicKey: Uint8Array, secretKey: Uint8Array): Promise<MLDSAKeyPair>;
|
|
1910
|
+
get hasPrivateKey(): boolean;
|
|
1911
|
+
/** Sign raw bytes; returns ML-DSA-65 signature (3309 bytes). */
|
|
1912
|
+
signBytes(data: Uint8Array): Promise<Uint8Array>;
|
|
1913
|
+
/**
|
|
1914
|
+
* Verify an ML-DSA-65 signature.
|
|
1915
|
+
* @returns true if valid
|
|
1916
|
+
* @throws {Error} on invalid signature
|
|
1917
|
+
*/
|
|
1918
|
+
verifyBytes(data: Uint8Array, signature: Uint8Array): Promise<void>;
|
|
1919
|
+
toString(): string;
|
|
1920
|
+
}
|
|
1921
|
+
/**
|
|
1922
|
+
* Add an ML-DSA-65 signature (`pqSig`) to an RCAN message.
|
|
1923
|
+
*
|
|
1924
|
+
* This is the v2.2 hybrid complement to the existing Ed25519 signature.
|
|
1925
|
+
* Call {@link signMessageEd25519} (or the existing signing path) first to set
|
|
1926
|
+
* `signature`, then call this to append `pqSig`.
|
|
1927
|
+
*
|
|
1928
|
+
* @param msg RCAN message (mutated in place — sets `pqSig`)
|
|
1929
|
+
* @param keypair ML-DSA-65 key pair with private key
|
|
1930
|
+
* @returns The same message cast to include `pqSig`
|
|
1931
|
+
*/
|
|
1932
|
+
declare function addPQSignature(msg: RCANMessage, keypair: MLDSAKeyPair): Promise<RCANMessage>;
|
|
1933
|
+
/**
|
|
1934
|
+
* Verify the ML-DSA-65 signature (`pqSig`) on an RCAN message.
|
|
1935
|
+
*
|
|
1936
|
+
* @param msg Message with a `pqSig` field
|
|
1937
|
+
* @param trustedKeys Trusted ML-DSA public key pairs
|
|
1938
|
+
* @param requirePQ If true, raise when `pqSig` is absent (for post-2028 hard mode)
|
|
1939
|
+
*/
|
|
1940
|
+
declare function verifyPQSignature(msg: RCANMessage, trustedKeys: MLDSAKeyPair[], requirePQ?: boolean): Promise<void>;
|
|
1941
|
+
|
|
1855
1942
|
/**
|
|
1856
1943
|
* rcan-ts — Official TypeScript SDK for RCAN v1.6
|
|
1857
1944
|
* Robot Communication and Accountability Network
|
|
@@ -1864,4 +1951,4 @@ declare const VERSION = "0.6.0";
|
|
|
1864
1951
|
/** @deprecated Use SPEC_VERSION from ./version instead */
|
|
1865
1952
|
declare const RCAN_VERSION = "1.6";
|
|
1866
1953
|
|
|
1867
|
-
export { AUTHORITY_ERROR_CODES, type ApprovalStatus, AuditChain, AuditError, type AuditExportRequest, type AuthorityAccessPayload, type AuthorityAccessPayloadWire, type AuthorityDataCategory, type AuthorityResponseData, type AuthorityResponsePayload, COMPETITION_SCOPE_LEVEL, CONTRIBUTE_SCOPE_LEVEL, type CachedKey, type ChainVerifyResult, ClockDriftError, type ClockSyncStatus, CommitmentRecord, type CommitmentRecordData, type CommitmentRecordJSON, type CompetitionBadge, type CompetitionEnter, type CompetitionFormat, type CompetitionScore, type ComputeResource, ConfidenceGate, type ConsentRequestParams, type ConsentResponseParams, type ConsentType, type ContributeCancel, type ContributeRequest, type ContributeResult, DEFAULT_LOA_POLICY, DataCategory, type DelegationHop, FIRMWARE_MANIFEST_PATH, FaultCode, type FaultReportParams, type FaultSeverity, type FederationSyncPayload, FederationSyncType, type FirmwareComponent, FirmwareIntegrityError, type FirmwareManifest, type FirmwareManifestWire, GateError, HiTLGate, type IdentityRecord, type JWKEntry, type JWKSDocument, KeyStore, LevelOfAssurance, type ListResult, type LoaPolicy, M2MAuthError, type M2MPeerClaims, type M2MTrustedClaims, M2M_TRUSTED_ISSUER, type MediaChunk, MediaEncoding, MessageType, NodeClient, type OfflineCommandResult, OfflineModeManager, type OfflineState, PRODUCTION_LOA_POLICY, type PendingApproval, type PersonalResearchResult, QoSAckTimeoutError, QoSLevel, QoSManager, type QoSResult, type QoSSendOptions, RCANAddressError, type RCANAgentConfig, type RCANConfig, RCANConfigAuthorizationError, RCANDelegationChainError, RCANError, RCANGateError, RCANMessage, type RCANMessageData, type RCANMessageEnvelope, RCANMessageError, type RCANMetadata, RCANNodeError, RCANNodeNotFoundError, RCANNodeSyncError, RCANNodeTrustError, RCANRegistryError, type RCANRegistryNode, RCANReplayAttackError, type RCANResolveResult, RCANSignatureError, RCANValidationError, RCANVersionIncompatibleError, RCAN_VERSION, ROLE_JWT_LEVEL, RRF_REVOCATION_CACHE_TTL_MS, RRF_REVOCATION_URL, type RegistrationResult, RegistryClient, type RegistryIdentity, RegistryTier, ReplayCache, type ReplayCheckResult, type ReplayableMessage, type ResearchMetrics, RevocationCache$1 as RevocationCache, type RevocationStatus, type RevocationStatusValue, type Robot, type RobotRegistration, RobotURI, RobotURIError, type RobotURIOptions, Role, type RunType, SAFETY_MESSAGE_TYPE, SCOPE_MIN_ROLE, SDK_VERSION, SPEC_VERSION, type SafetyEvent, type SafetyMessage, type ScopeValidationResult, type SeasonStanding, type SenderType, type SignatureBlock, type StandingEntry, type StreamChunk, type TrainingConsentRequestParams, type TransparencyMessage, TransportEncoding, TransportError, TrustAnchorCache, VERSION, type ValidationResult, type WorkUnitStatus, addDelegationHop, addMediaInline, addMediaRef, assertClockSynced, authorityAccessFromWire, authorityAccessToWire, canonicalManifestJson, checkClockSync, checkRevocation, decodeBleFrames, decodeCompact, decodeMinimal, encodeBleFrames, encodeCompact, encodeMinimal, extractIdentityFromJwt, extractLoaFromJwt, extractRoleFromJwt, fetchCanonicalSchema, fetchRRFRevocations, isAuthorityRequestValid, isM2mTrustedRevoked, isPreemptedBy, isSafetyMessage, makeCloudRelayMessage, makeCompetitionEnter, makeCompetitionScore, makeConfigUpdate, makeConsentDeny, makeConsentGrant, makeConsentRequest, makeContributeCancel, makeContributeRequest, makeContributeResult, makeEstopMessage, makeEstopWithQoS, makeFaultReport, makeFederationSync, makeKeyRotationMessage, makePersonalResearchResult, makeResumeMessage, makeRevocationBroadcast, makeSeasonStanding, makeStopMessage, makeStreamChunk, makeTrainingConsentDeny, makeTrainingConsentGrant, makeTrainingConsentRequest, makeTrainingDataMessage, makeTransparencyMessage, manifestFromWire, manifestToWire, parseM2mPeerToken, parseM2mTrustedToken, roleFromJwtLevel, selectTransport, validateAuthorityAccess, validateCompetitionScope, validateConfig, validateConfigAgainstSchema, validateConfigUpdate, validateConsentMessage, validateContributeScope, validateCrossRegistryCommand, validateDelegationChain, validateLoaForScope, validateManifest, validateMediaChunks, validateMessage, validateNodeAgainstSchema, validateReplay, validateRoleForScope, validateSafetyMessage, validateTrainingDataMessage, validateURI, validateVersionCompat, verifyM2mTrustedToken, verifyM2mTrustedTokenClaims };
|
|
1954
|
+
export { AUTHORITY_ERROR_CODES, type ApprovalStatus, AuditChain, AuditError, type AuditExportRequest, type AuthorityAccessPayload, type AuthorityAccessPayloadWire, type AuthorityDataCategory, type AuthorityResponseData, type AuthorityResponsePayload, COMPETITION_SCOPE_LEVEL, CONTRIBUTE_SCOPE_LEVEL, type CachedKey, type ChainVerifyResult, ClockDriftError, type ClockSyncStatus, CommitmentRecord, type CommitmentRecordData, type CommitmentRecordJSON, type CompetitionBadge, type CompetitionEnter, type CompetitionFormat, type CompetitionScore, type ComputeResource, ConfidenceGate, type ConsentRequestParams, type ConsentResponseParams, type ConsentType, type ContributeCancel, type ContributeRequest, type ContributeResult, DEFAULT_LOA_POLICY, DataCategory, type DelegationHop, FIRMWARE_MANIFEST_PATH, FaultCode, type FaultReportParams, type FaultSeverity, type FederationSyncPayload, FederationSyncType, type FirmwareComponent, FirmwareIntegrityError, type FirmwareManifest, type FirmwareManifestWire, GateError, HiTLGate, type IdentityRecord, type JWKEntry, type JWKSDocument, KeyStore, LevelOfAssurance, type ListResult, type LoaPolicy, M2MAuthError, type M2MPeerClaims, type M2MTrustedClaims, M2M_TRUSTED_ISSUER, MLDSAKeyPair, type MLDSAKeyPairData, type MLDSASignatureBlock, type MediaChunk, MediaEncoding, MessageType, NodeClient, type OfflineCommandResult, OfflineModeManager, type OfflineState, PRODUCTION_LOA_POLICY, type PendingApproval, type PersonalResearchResult, QoSAckTimeoutError, QoSLevel, QoSManager, type QoSResult, type QoSSendOptions, RCANAddressError, type RCANAgentConfig, type RCANConfig, RCANConfigAuthorizationError, RCANDelegationChainError, RCANError, RCANGateError, RCANMessage, type RCANMessageData, type RCANMessageEnvelope, RCANMessageError, type RCANMetadata, RCANNodeError, RCANNodeNotFoundError, RCANNodeSyncError, RCANNodeTrustError, RCANRegistryError, type RCANRegistryNode, RCANReplayAttackError, type RCANResolveResult, RCANSignatureError, RCANValidationError, RCANVersionIncompatibleError, RCAN_VERSION, ROLE_JWT_LEVEL, RRF_REVOCATION_CACHE_TTL_MS, RRF_REVOCATION_URL, type RegistrationResult, RegistryClient, type RegistryIdentity, RegistryTier, ReplayCache, type ReplayCheckResult, type ReplayableMessage, type ResearchMetrics, RevocationCache$1 as RevocationCache, type RevocationStatus, type RevocationStatusValue, type Robot, type RobotRegistration, RobotURI, RobotURIError, type RobotURIOptions, Role, type RunType, SAFETY_MESSAGE_TYPE, SCOPE_MIN_ROLE, SDK_VERSION, SPEC_VERSION, type SafetyEvent, type SafetyMessage, type ScopeValidationResult, type SeasonStanding, type SenderType, type SignatureBlock, type StandingEntry, type StreamChunk, type TrainingConsentRequestParams, type TransparencyMessage, TransportEncoding, TransportError, TrustAnchorCache, VERSION, type ValidationResult, type WorkUnitStatus, addDelegationHop, addMediaInline, addMediaRef, addPQSignature, assertClockSynced, authorityAccessFromWire, authorityAccessToWire, canonicalManifestJson, checkClockSync, checkRevocation, decodeBleFrames, decodeCompact, decodeMinimal, encodeBleFrames, encodeCompact, encodeMinimal, extractIdentityFromJwt, extractLoaFromJwt, extractRoleFromJwt, fetchCanonicalSchema, fetchRRFRevocations, isAuthorityRequestValid, isM2mTrustedRevoked, isPreemptedBy, isSafetyMessage, makeCloudRelayMessage, makeCompetitionEnter, makeCompetitionScore, makeConfigUpdate, makeConsentDeny, makeConsentGrant, makeConsentRequest, makeContributeCancel, makeContributeRequest, makeContributeResult, makeEstopMessage, makeEstopWithQoS, makeFaultReport, makeFederationSync, makeKeyRotationMessage, makePersonalResearchResult, makeResumeMessage, makeRevocationBroadcast, makeSeasonStanding, makeStopMessage, makeStreamChunk, makeTrainingConsentDeny, makeTrainingConsentGrant, makeTrainingConsentRequest, makeTrainingDataMessage, makeTransparencyMessage, manifestFromWire, manifestToWire, parseM2mPeerToken, parseM2mTrustedToken, roleFromJwtLevel, selectTransport, validateAuthorityAccess, validateCompetitionScope, validateConfig, validateConfigAgainstSchema, validateConfigUpdate, validateConsentMessage, validateContributeScope, validateCrossRegistryCommand, validateDelegationChain, validateLoaForScope, validateManifest, validateMediaChunks, validateMessage, validateNodeAgainstSchema, validateReplay, validateRoleForScope, validateSafetyMessage, validateTrainingDataMessage, validateURI, validateVersionCompat, verifyM2mTrustedToken, verifyM2mTrustedTokenClaims, verifyPQSignature };
|
package/dist/browser.mjs
CHANGED
|
@@ -99,8 +99,8 @@ var RobotURI = class _RobotURI {
|
|
|
99
99
|
};
|
|
100
100
|
|
|
101
101
|
// src/version.ts
|
|
102
|
-
var SPEC_VERSION = "2.
|
|
103
|
-
var SDK_VERSION = "1.
|
|
102
|
+
var SPEC_VERSION = "2.2.0";
|
|
103
|
+
var SDK_VERSION = "1.2.0";
|
|
104
104
|
function validateVersionCompat(incomingVersion, localVersion = SPEC_VERSION) {
|
|
105
105
|
const parseParts = (v) => {
|
|
106
106
|
const parts = v.split(".");
|
|
@@ -199,6 +199,8 @@ var RCANMessage = class _RCANMessage {
|
|
|
199
199
|
__publicField(this, "firmwareHash");
|
|
200
200
|
/** v2.1: URI to sender's SBOM attestation endpoint */
|
|
201
201
|
__publicField(this, "attestationRef");
|
|
202
|
+
/** v2.2: ML-DSA-65 post-quantum signature (field 16, FIPS 204). Hybrid alongside Ed25519. */
|
|
203
|
+
__publicField(this, "pqSig");
|
|
202
204
|
if (!data.cmd || data.cmd.trim() === "") {
|
|
203
205
|
throw new RCANMessageError("'cmd' is required");
|
|
204
206
|
}
|
|
@@ -228,6 +230,7 @@ var RCANMessage = class _RCANMessage {
|
|
|
228
230
|
this.mediaChunks = data.mediaChunks;
|
|
229
231
|
this.firmwareHash = data.firmwareHash;
|
|
230
232
|
this.attestationRef = data.attestationRef;
|
|
233
|
+
this.pqSig = data.pqSig;
|
|
231
234
|
if (this.signature !== void 0 && this.signature["sig"] === "pending") {
|
|
232
235
|
throw new RCANMessageError(
|
|
233
236
|
"signature.sig:'pending' is not valid in RCAN v2.1. Sign the message before sending."
|
|
@@ -276,6 +279,7 @@ var RCANMessage = class _RCANMessage {
|
|
|
276
279
|
if (this.mediaChunks !== void 0) obj.mediaChunks = this.mediaChunks;
|
|
277
280
|
if (this.firmwareHash !== void 0) obj.firmwareHash = this.firmwareHash;
|
|
278
281
|
if (this.attestationRef !== void 0) obj.attestationRef = this.attestationRef;
|
|
282
|
+
if (this.pqSig !== void 0) obj.pqSig = this.pqSig;
|
|
279
283
|
return obj;
|
|
280
284
|
}
|
|
281
285
|
/** Serialize to JSON string */
|
|
@@ -320,7 +324,8 @@ var RCANMessage = class _RCANMessage {
|
|
|
320
324
|
transportEncoding: obj.transportEncoding,
|
|
321
325
|
mediaChunks: obj.mediaChunks,
|
|
322
326
|
firmwareHash: obj.firmwareHash,
|
|
323
|
-
attestationRef: obj.attestationRef
|
|
327
|
+
attestationRef: obj.attestationRef,
|
|
328
|
+
pqSig: obj.pqSig
|
|
324
329
|
});
|
|
325
330
|
}
|
|
326
331
|
};
|
|
@@ -3095,6 +3100,163 @@ async function verifyM2mTrustedToken(token, targetRrn, options) {
|
|
|
3095
3100
|
return claims;
|
|
3096
3101
|
}
|
|
3097
3102
|
|
|
3103
|
+
// src/pqSigning.ts
|
|
3104
|
+
function toBase64url(bytes) {
|
|
3105
|
+
let binary = "";
|
|
3106
|
+
for (let i = 0; i < bytes.length; i++) binary += String.fromCharCode(bytes[i]);
|
|
3107
|
+
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
3108
|
+
}
|
|
3109
|
+
function fromBase64url(b64) {
|
|
3110
|
+
const padded = b64.replace(/-/g, "+").replace(/_/g, "/");
|
|
3111
|
+
const binary = atob(padded);
|
|
3112
|
+
const bytes = new Uint8Array(binary.length);
|
|
3113
|
+
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
|
|
3114
|
+
return bytes;
|
|
3115
|
+
}
|
|
3116
|
+
async function sha256hex(data) {
|
|
3117
|
+
const g = typeof globalThis !== "undefined" ? globalThis : {};
|
|
3118
|
+
const webcrypto = g.crypto;
|
|
3119
|
+
const subtle = webcrypto?.subtle;
|
|
3120
|
+
if (subtle) {
|
|
3121
|
+
const buf = await subtle.digest("SHA-256", data);
|
|
3122
|
+
return Array.from(new Uint8Array(buf)).map((b) => b.toString(16).padStart(2, "0")).join("").slice(0, 8);
|
|
3123
|
+
}
|
|
3124
|
+
const nodeCrypto = await import("crypto").catch(() => null);
|
|
3125
|
+
if (nodeCrypto) {
|
|
3126
|
+
return nodeCrypto.createHash("sha256").update(data).digest("hex").slice(0, 8);
|
|
3127
|
+
}
|
|
3128
|
+
throw new Error("No SHA-256 implementation available");
|
|
3129
|
+
}
|
|
3130
|
+
var _mlDsaModule;
|
|
3131
|
+
async function requireNoblePostQuantum() {
|
|
3132
|
+
if (_mlDsaModule) return _mlDsaModule;
|
|
3133
|
+
if (typeof __require !== "undefined") {
|
|
3134
|
+
try {
|
|
3135
|
+
_mlDsaModule = __require("@noble/post-quantum/ml-dsa.js");
|
|
3136
|
+
return _mlDsaModule;
|
|
3137
|
+
} catch {
|
|
3138
|
+
}
|
|
3139
|
+
}
|
|
3140
|
+
try {
|
|
3141
|
+
_mlDsaModule = await import("@noble/post-quantum/ml-dsa.js");
|
|
3142
|
+
return _mlDsaModule;
|
|
3143
|
+
} catch {
|
|
3144
|
+
throw new Error(
|
|
3145
|
+
"ML-DSA signing requires @noble/post-quantum. Install with: npm install @noble/post-quantum"
|
|
3146
|
+
);
|
|
3147
|
+
}
|
|
3148
|
+
}
|
|
3149
|
+
var MLDSAKeyPair = class _MLDSAKeyPair {
|
|
3150
|
+
constructor(data) {
|
|
3151
|
+
__publicField(this, "keyId");
|
|
3152
|
+
__publicField(this, "publicKey");
|
|
3153
|
+
__publicField(this, "secretKey");
|
|
3154
|
+
this.keyId = data.keyId;
|
|
3155
|
+
this.publicKey = data.publicKey;
|
|
3156
|
+
this.secretKey = data.secretKey;
|
|
3157
|
+
}
|
|
3158
|
+
/** Generate a new ML-DSA-65 key pair. */
|
|
3159
|
+
static async generate() {
|
|
3160
|
+
const { ml_dsa65 } = await requireNoblePostQuantum();
|
|
3161
|
+
const kp = ml_dsa65.keygen();
|
|
3162
|
+
const keyId = await sha256hex(kp.publicKey);
|
|
3163
|
+
return new _MLDSAKeyPair({
|
|
3164
|
+
publicKey: kp.publicKey,
|
|
3165
|
+
secretKey: kp.secretKey,
|
|
3166
|
+
keyId
|
|
3167
|
+
});
|
|
3168
|
+
}
|
|
3169
|
+
/** Build a verify-only key pair from raw public key bytes. */
|
|
3170
|
+
static async fromPublicKey(publicKey) {
|
|
3171
|
+
const keyId = await sha256hex(publicKey);
|
|
3172
|
+
return new _MLDSAKeyPair({ publicKey, keyId });
|
|
3173
|
+
}
|
|
3174
|
+
/** Build a full key pair from saved bytes (public + secret). */
|
|
3175
|
+
static async fromKeyMaterial(publicKey, secretKey) {
|
|
3176
|
+
const keyId = await sha256hex(publicKey);
|
|
3177
|
+
return new _MLDSAKeyPair({ publicKey, secretKey, keyId });
|
|
3178
|
+
}
|
|
3179
|
+
get hasPrivateKey() {
|
|
3180
|
+
return this.secretKey !== void 0;
|
|
3181
|
+
}
|
|
3182
|
+
/** Sign raw bytes; returns ML-DSA-65 signature (3309 bytes). */
|
|
3183
|
+
async signBytes(data) {
|
|
3184
|
+
if (!this.secretKey) {
|
|
3185
|
+
throw new Error("Cannot sign: MLDSAKeyPair has no private key (verify-only)");
|
|
3186
|
+
}
|
|
3187
|
+
const { ml_dsa65 } = await requireNoblePostQuantum();
|
|
3188
|
+
return ml_dsa65.sign(data, this.secretKey);
|
|
3189
|
+
}
|
|
3190
|
+
/**
|
|
3191
|
+
* Verify an ML-DSA-65 signature.
|
|
3192
|
+
* @returns true if valid
|
|
3193
|
+
* @throws {Error} on invalid signature
|
|
3194
|
+
*/
|
|
3195
|
+
async verifyBytes(data, signature) {
|
|
3196
|
+
const { ml_dsa65 } = await requireNoblePostQuantum();
|
|
3197
|
+
const ok = ml_dsa65.verify(signature, data, this.publicKey);
|
|
3198
|
+
if (!ok) throw new Error("ML-DSA signature verification failed");
|
|
3199
|
+
}
|
|
3200
|
+
toString() {
|
|
3201
|
+
const mode = this.hasPrivateKey ? "private+public" : "public-only";
|
|
3202
|
+
return `MLDSAKeyPair(keyId=${this.keyId}, alg=ML-DSA-65, ${mode})`;
|
|
3203
|
+
}
|
|
3204
|
+
};
|
|
3205
|
+
function canonicalMessageBytes(msg) {
|
|
3206
|
+
const m = msg;
|
|
3207
|
+
const payload = {
|
|
3208
|
+
rcan: msg.rcan,
|
|
3209
|
+
msg_id: m["msgId"] ?? m["msg_id"] ?? "",
|
|
3210
|
+
timestamp: msg.timestamp,
|
|
3211
|
+
cmd: msg.cmd,
|
|
3212
|
+
target: msg.target,
|
|
3213
|
+
params: msg.params
|
|
3214
|
+
};
|
|
3215
|
+
const sorted = JSON.stringify(
|
|
3216
|
+
Object.fromEntries(Object.entries(payload).sort()),
|
|
3217
|
+
null,
|
|
3218
|
+
void 0
|
|
3219
|
+
);
|
|
3220
|
+
return new TextEncoder().encode(sorted);
|
|
3221
|
+
}
|
|
3222
|
+
async function addPQSignature(msg, keypair) {
|
|
3223
|
+
const payload = canonicalMessageBytes(msg);
|
|
3224
|
+
const rawSig = await keypair.signBytes(payload);
|
|
3225
|
+
const block = {
|
|
3226
|
+
alg: "ml-dsa-65",
|
|
3227
|
+
kid: keypair.keyId,
|
|
3228
|
+
sig: toBase64url(rawSig)
|
|
3229
|
+
};
|
|
3230
|
+
msg["pqSig"] = block;
|
|
3231
|
+
return msg;
|
|
3232
|
+
}
|
|
3233
|
+
async function verifyPQSignature(msg, trustedKeys, requirePQ = false) {
|
|
3234
|
+
const pqSig = msg["pqSig"];
|
|
3235
|
+
if (!pqSig) {
|
|
3236
|
+
if (requirePQ) {
|
|
3237
|
+
throw new Error("ML-DSA signature (pqSig) required but missing from message");
|
|
3238
|
+
}
|
|
3239
|
+
return;
|
|
3240
|
+
}
|
|
3241
|
+
if (pqSig.alg !== "ml-dsa-65") {
|
|
3242
|
+
throw new Error(`Unsupported PQ signature algorithm: ${pqSig.alg}`);
|
|
3243
|
+
}
|
|
3244
|
+
const matched = trustedKeys.find((k) => k.keyId === pqSig.kid);
|
|
3245
|
+
if (!matched) {
|
|
3246
|
+
throw new Error(
|
|
3247
|
+
`No trusted ML-DSA key with kid=${pqSig.kid}. Known kids: [${trustedKeys.map((k) => k.keyId).join(", ")}]`
|
|
3248
|
+
);
|
|
3249
|
+
}
|
|
3250
|
+
let rawSig;
|
|
3251
|
+
try {
|
|
3252
|
+
rawSig = fromBase64url(pqSig.sig);
|
|
3253
|
+
} catch (e) {
|
|
3254
|
+
throw new Error(`Invalid base64url ML-DSA signature: ${e}`);
|
|
3255
|
+
}
|
|
3256
|
+
const payload = canonicalMessageBytes(msg);
|
|
3257
|
+
await matched.verifyBytes(payload, rawSig);
|
|
3258
|
+
}
|
|
3259
|
+
|
|
3098
3260
|
// src/index.ts
|
|
3099
3261
|
var VERSION = "0.6.0";
|
|
3100
3262
|
var RCAN_VERSION = "1.6";
|
|
@@ -3119,6 +3281,7 @@ export {
|
|
|
3119
3281
|
LevelOfAssurance,
|
|
3120
3282
|
M2MAuthError,
|
|
3121
3283
|
M2M_TRUSTED_ISSUER,
|
|
3284
|
+
MLDSAKeyPair,
|
|
3122
3285
|
MediaEncoding,
|
|
3123
3286
|
MessageType,
|
|
3124
3287
|
NodeClient,
|
|
@@ -3165,6 +3328,7 @@ export {
|
|
|
3165
3328
|
addDelegationHop,
|
|
3166
3329
|
addMediaInline,
|
|
3167
3330
|
addMediaRef,
|
|
3331
|
+
addPQSignature,
|
|
3168
3332
|
assertClockSynced,
|
|
3169
3333
|
authorityAccessFromWire,
|
|
3170
3334
|
authorityAccessToWire,
|
|
@@ -3239,6 +3403,7 @@ export {
|
|
|
3239
3403
|
validateURI,
|
|
3240
3404
|
validateVersionCompat,
|
|
3241
3405
|
verifyM2mTrustedToken,
|
|
3242
|
-
verifyM2mTrustedTokenClaims
|
|
3406
|
+
verifyM2mTrustedTokenClaims,
|
|
3407
|
+
verifyPQSignature
|
|
3243
3408
|
};
|
|
3244
3409
|
//# sourceMappingURL=browser.mjs.map
|