@continuonai/rcan-ts 1.1.0 → 1.2.1
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 +66 -4
- package/dist/browser.mjs +143 -4
- package/dist/browser.mjs.map +1 -1
- package/dist/index.d.mts +66 -4
- package/dist/index.d.ts +66 -4
- package/dist/index.js +149 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +143 -4
- package/dist/index.mjs.map +1 -1
- package/dist/rcan-validate.js +6 -2
- package/dist/rcan.iife.js +16 -3
- package/package.json +30 -4
package/dist/browser.d.mts
CHANGED
|
@@ -109,8 +109,15 @@ interface DelegationHop {
|
|
|
109
109
|
scope: string;
|
|
110
110
|
signature: string;
|
|
111
111
|
}
|
|
112
|
+
/** RCAN v2.2: ML-DSA-65 is the only valid alg ("ml-dsa-65"). Ed25519 is deprecated. */
|
|
112
113
|
interface SignatureBlock {
|
|
113
|
-
alg:
|
|
114
|
+
alg: "ml-dsa-65";
|
|
115
|
+
kid: string;
|
|
116
|
+
sig: string;
|
|
117
|
+
}
|
|
118
|
+
/** v2.2: Post-quantum (ML-DSA-65) signature block */
|
|
119
|
+
interface PQSignatureBlock {
|
|
120
|
+
alg: "ml-dsa-65";
|
|
114
121
|
kid: string;
|
|
115
122
|
sig: string;
|
|
116
123
|
}
|
|
@@ -152,6 +159,8 @@ interface RCANMessageData {
|
|
|
152
159
|
firmwareHash?: string;
|
|
153
160
|
/** v2.1: URI to sender's SBOM attestation endpoint (envelope field 14). Required at L2+. */
|
|
154
161
|
attestationRef?: string;
|
|
162
|
+
/** v2.2: ML-DSA-65 post-quantum signature block (field 16, FIPS 204). Hybrid mode alongside Ed25519. */
|
|
163
|
+
pqSig?: PQSignatureBlock | undefined;
|
|
155
164
|
[key: string]: unknown;
|
|
156
165
|
}
|
|
157
166
|
declare class RCANMessageError extends Error {
|
|
@@ -188,6 +197,8 @@ declare class RCANMessage {
|
|
|
188
197
|
readonly firmwareHash: string | undefined;
|
|
189
198
|
/** v2.1: URI to sender's SBOM attestation endpoint */
|
|
190
199
|
readonly attestationRef: string | undefined;
|
|
200
|
+
/** v2.2: ML-DSA-65 post-quantum signature (field 16, FIPS 204). Hybrid alongside Ed25519. */
|
|
201
|
+
readonly pqSig: PQSignatureBlock | undefined;
|
|
191
202
|
constructor(data: RCANMessageData);
|
|
192
203
|
/** Whether this message has a signature block */
|
|
193
204
|
get isSigned(): boolean;
|
|
@@ -755,9 +766,9 @@ declare function makeTransparencyMessage(ruri: string, disclosure: string, deleg
|
|
|
755
766
|
* §3.5 — Protocol Version Compatibility
|
|
756
767
|
*/
|
|
757
768
|
/** The RCAN spec version this SDK implements. */
|
|
758
|
-
declare const SPEC_VERSION = "2.
|
|
769
|
+
declare const SPEC_VERSION = "2.2.0";
|
|
759
770
|
/** The SDK release version. */
|
|
760
|
-
declare const SDK_VERSION = "1.1
|
|
771
|
+
declare const SDK_VERSION = "1.2.1";
|
|
761
772
|
/**
|
|
762
773
|
* Validate version compatibility.
|
|
763
774
|
*
|
|
@@ -1852,6 +1863,57 @@ declare function verifyM2mTrustedToken(token: string, targetRrn: string, options
|
|
|
1852
1863
|
skipRevocationCheck?: boolean;
|
|
1853
1864
|
}): Promise<M2MTrustedClaims>;
|
|
1854
1865
|
|
|
1866
|
+
/**
|
|
1867
|
+
* RCAN v2.2 ML-DSA-65 Signing (NIST FIPS 204)
|
|
1868
|
+
*
|
|
1869
|
+
* Ed25519 is deprecated. ML-DSA-65 is the ONLY signing algorithm.
|
|
1870
|
+
* All signed messages carry a ``signature`` block with ``alg: "ml-dsa-65"``.
|
|
1871
|
+
*
|
|
1872
|
+
* Requires: @noble/post-quantum (npm install @noble/post-quantum)
|
|
1873
|
+
*
|
|
1874
|
+
* Spec: https://rcan.dev/spec/v2.2#section-7-2
|
|
1875
|
+
*/
|
|
1876
|
+
|
|
1877
|
+
interface MLDSAKeyPairData {
|
|
1878
|
+
publicKey: Uint8Array;
|
|
1879
|
+
secretKey?: Uint8Array;
|
|
1880
|
+
keyId: string;
|
|
1881
|
+
}
|
|
1882
|
+
/**
|
|
1883
|
+
* An ML-DSA-65 (CRYSTALS-Dilithium, NIST FIPS 204) key pair.
|
|
1884
|
+
*
|
|
1885
|
+
* This is the ONLY signing key type in RCAN v2.2+. Ed25519 is deprecated.
|
|
1886
|
+
*/
|
|
1887
|
+
declare class MLDSAKeyPair {
|
|
1888
|
+
readonly keyId: string;
|
|
1889
|
+
readonly publicKey: Uint8Array;
|
|
1890
|
+
readonly secretKey: Uint8Array | undefined;
|
|
1891
|
+
private constructor();
|
|
1892
|
+
static generate(): Promise<MLDSAKeyPair>;
|
|
1893
|
+
static fromPublicKey(publicKey: Uint8Array): Promise<MLDSAKeyPair>;
|
|
1894
|
+
static fromKeyMaterial(publicKey: Uint8Array, secretKey: Uint8Array): Promise<MLDSAKeyPair>;
|
|
1895
|
+
get hasPrivateKey(): boolean;
|
|
1896
|
+
signBytes(data: Uint8Array): Promise<Uint8Array>;
|
|
1897
|
+
verifyBytes(data: Uint8Array, signature: Uint8Array): Promise<void>;
|
|
1898
|
+
toString(): string;
|
|
1899
|
+
}
|
|
1900
|
+
/**
|
|
1901
|
+
* Sign an RCANMessage with ML-DSA-65 (the only signing algorithm in RCAN v2.2).
|
|
1902
|
+
*
|
|
1903
|
+
* Sets msg.signature = { alg: "ml-dsa-65", kid, sig }.
|
|
1904
|
+
*/
|
|
1905
|
+
declare function signMessage(msg: RCANMessage, keypair: MLDSAKeyPair): Promise<RCANMessage>;
|
|
1906
|
+
/**
|
|
1907
|
+
* Verify the ML-DSA-65 signature on an RCANMessage.
|
|
1908
|
+
*
|
|
1909
|
+
* @throws {Error} if signature is missing, alg is not ml-dsa-65, key not found, or invalid.
|
|
1910
|
+
*/
|
|
1911
|
+
declare function verifyMessage(msg: RCANMessage, trustedKeys: MLDSAKeyPair[]): Promise<void>;
|
|
1912
|
+
/** @deprecated Use signMessage() — Ed25519 is removed in RCAN v2.2 */
|
|
1913
|
+
declare const addPQSignature: typeof signMessage;
|
|
1914
|
+
/** @deprecated Use verifyMessage() — Ed25519 is removed in RCAN v2.2 */
|
|
1915
|
+
declare function verifyPQSignature(msg: RCANMessage, trustedKeys: MLDSAKeyPair[], _requirePQ?: boolean): Promise<void>;
|
|
1916
|
+
|
|
1855
1917
|
/**
|
|
1856
1918
|
* rcan-ts — Official TypeScript SDK for RCAN v1.6
|
|
1857
1919
|
* Robot Communication and Accountability Network
|
|
@@ -1864,4 +1926,4 @@ declare const VERSION = "0.6.0";
|
|
|
1864
1926
|
/** @deprecated Use SPEC_VERSION from ./version instead */
|
|
1865
1927
|
declare const RCAN_VERSION = "1.6";
|
|
1866
1928
|
|
|
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 };
|
|
1929
|
+
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 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, signMessage, validateAuthorityAccess, validateCompetitionScope, validateConfig, validateConfigAgainstSchema, validateConfigUpdate, validateConsentMessage, validateContributeScope, validateCrossRegistryCommand, validateDelegationChain, validateLoaForScope, validateManifest, validateMediaChunks, validateMessage, validateNodeAgainstSchema, validateReplay, validateRoleForScope, validateSafetyMessage, validateTrainingDataMessage, validateURI, validateVersionCompat, verifyM2mTrustedToken, verifyM2mTrustedTokenClaims, verifyMessage, 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.1
|
|
102
|
+
var SPEC_VERSION = "2.2.0";
|
|
103
|
+
var SDK_VERSION = "1.2.1";
|
|
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."
|
|
@@ -320,7 +323,8 @@ var RCANMessage = class _RCANMessage {
|
|
|
320
323
|
transportEncoding: obj.transportEncoding,
|
|
321
324
|
mediaChunks: obj.mediaChunks,
|
|
322
325
|
firmwareHash: obj.firmwareHash,
|
|
323
|
-
attestationRef: obj.attestationRef
|
|
326
|
+
attestationRef: obj.attestationRef,
|
|
327
|
+
pqSig: obj.pqSig
|
|
324
328
|
});
|
|
325
329
|
}
|
|
326
330
|
};
|
|
@@ -3095,6 +3099,136 @@ async function verifyM2mTrustedToken(token, targetRrn, options) {
|
|
|
3095
3099
|
return claims;
|
|
3096
3100
|
}
|
|
3097
3101
|
|
|
3102
|
+
// src/pqSigning.ts
|
|
3103
|
+
function toBase64url(bytes) {
|
|
3104
|
+
let binary = "";
|
|
3105
|
+
for (let i = 0; i < bytes.length; i++) binary += String.fromCharCode(bytes[i]);
|
|
3106
|
+
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
3107
|
+
}
|
|
3108
|
+
function fromBase64url(b64) {
|
|
3109
|
+
const padded = b64.replace(/-/g, "+").replace(/_/g, "/");
|
|
3110
|
+
const binary = atob(padded);
|
|
3111
|
+
const bytes = new Uint8Array(binary.length);
|
|
3112
|
+
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
|
|
3113
|
+
return bytes;
|
|
3114
|
+
}
|
|
3115
|
+
async function sha256hex(data) {
|
|
3116
|
+
if (typeof crypto !== "undefined" && crypto.subtle) {
|
|
3117
|
+
const buf = await crypto.subtle.digest("SHA-256", data.buffer);
|
|
3118
|
+
return Array.from(new Uint8Array(buf)).map((b) => b.toString(16).padStart(2, "0")).join("").slice(0, 8);
|
|
3119
|
+
}
|
|
3120
|
+
const { createHash } = __require("crypto");
|
|
3121
|
+
return createHash("sha256").update(data).digest("hex").slice(0, 8);
|
|
3122
|
+
}
|
|
3123
|
+
var _mlDsaModule;
|
|
3124
|
+
async function requireMlDsa() {
|
|
3125
|
+
if (_mlDsaModule) return _mlDsaModule;
|
|
3126
|
+
if (typeof __require !== "undefined") {
|
|
3127
|
+
try {
|
|
3128
|
+
_mlDsaModule = __require("@noble/post-quantum/ml-dsa.js");
|
|
3129
|
+
return _mlDsaModule;
|
|
3130
|
+
} catch {
|
|
3131
|
+
}
|
|
3132
|
+
}
|
|
3133
|
+
try {
|
|
3134
|
+
_mlDsaModule = await import("@noble/post-quantum/ml-dsa.js");
|
|
3135
|
+
return _mlDsaModule;
|
|
3136
|
+
} catch {
|
|
3137
|
+
throw new Error(
|
|
3138
|
+
"ML-DSA-65 signing requires @noble/post-quantum. Install with: npm install @noble/post-quantum"
|
|
3139
|
+
);
|
|
3140
|
+
}
|
|
3141
|
+
}
|
|
3142
|
+
var MLDSAKeyPair = class _MLDSAKeyPair {
|
|
3143
|
+
constructor(data) {
|
|
3144
|
+
__publicField(this, "keyId");
|
|
3145
|
+
__publicField(this, "publicKey");
|
|
3146
|
+
__publicField(this, "secretKey");
|
|
3147
|
+
this.keyId = data.keyId;
|
|
3148
|
+
this.publicKey = data.publicKey;
|
|
3149
|
+
this.secretKey = data.secretKey;
|
|
3150
|
+
}
|
|
3151
|
+
static async generate() {
|
|
3152
|
+
const m = await requireMlDsa();
|
|
3153
|
+
const kp = m.ml_dsa65.keygen();
|
|
3154
|
+
const keyId = await sha256hex(kp.publicKey);
|
|
3155
|
+
return new _MLDSAKeyPair({ publicKey: kp.publicKey, secretKey: kp.secretKey, keyId });
|
|
3156
|
+
}
|
|
3157
|
+
static async fromPublicKey(publicKey) {
|
|
3158
|
+
const keyId = await sha256hex(publicKey);
|
|
3159
|
+
return new _MLDSAKeyPair({ publicKey, keyId });
|
|
3160
|
+
}
|
|
3161
|
+
static async fromKeyMaterial(publicKey, secretKey) {
|
|
3162
|
+
const keyId = await sha256hex(publicKey);
|
|
3163
|
+
return new _MLDSAKeyPair({ publicKey, secretKey, keyId });
|
|
3164
|
+
}
|
|
3165
|
+
get hasPrivateKey() {
|
|
3166
|
+
return this.secretKey !== void 0;
|
|
3167
|
+
}
|
|
3168
|
+
async signBytes(data) {
|
|
3169
|
+
if (!this.secretKey) throw new Error("Cannot sign: MLDSAKeyPair has no private key (verify-only)");
|
|
3170
|
+
const m = await requireMlDsa();
|
|
3171
|
+
return m.ml_dsa65.sign(data, this.secretKey);
|
|
3172
|
+
}
|
|
3173
|
+
async verifyBytes(data, signature) {
|
|
3174
|
+
const m = await requireMlDsa();
|
|
3175
|
+
const ok = m.ml_dsa65.verify(signature, data, this.publicKey);
|
|
3176
|
+
if (!ok) throw new Error("ML-DSA-65 signature verification failed");
|
|
3177
|
+
}
|
|
3178
|
+
toString() {
|
|
3179
|
+
return `MLDSAKeyPair(keyId=${this.keyId}, alg=ML-DSA-65, ${this.hasPrivateKey ? "private+public" : "public-only"})`;
|
|
3180
|
+
}
|
|
3181
|
+
};
|
|
3182
|
+
function canonicalMessageBytes(msg) {
|
|
3183
|
+
const payload = {
|
|
3184
|
+
rcan: msg.rcan,
|
|
3185
|
+
msg_id: msg["msgId"] ?? "",
|
|
3186
|
+
timestamp: msg.timestamp,
|
|
3187
|
+
cmd: msg.cmd,
|
|
3188
|
+
target: msg.target,
|
|
3189
|
+
params: msg.params
|
|
3190
|
+
};
|
|
3191
|
+
return new TextEncoder().encode(
|
|
3192
|
+
JSON.stringify(Object.fromEntries(Object.entries(payload).sort()))
|
|
3193
|
+
);
|
|
3194
|
+
}
|
|
3195
|
+
async function signMessage(msg, keypair) {
|
|
3196
|
+
const payload = canonicalMessageBytes(msg);
|
|
3197
|
+
const rawSig = await keypair.signBytes(payload);
|
|
3198
|
+
msg["signature"] = {
|
|
3199
|
+
alg: "ml-dsa-65",
|
|
3200
|
+
kid: keypair.keyId,
|
|
3201
|
+
sig: toBase64url(rawSig)
|
|
3202
|
+
};
|
|
3203
|
+
return msg;
|
|
3204
|
+
}
|
|
3205
|
+
async function verifyMessage(msg, trustedKeys) {
|
|
3206
|
+
const sig = msg.signature;
|
|
3207
|
+
if (!sig) throw new Error("Message is unsigned \u2014 signature field missing");
|
|
3208
|
+
if (sig.alg !== "ml-dsa-65") {
|
|
3209
|
+
throw new Error(
|
|
3210
|
+
`Unsupported signature algorithm: ${sig.alg}. RCAN v2.2 requires ml-dsa-65 (Ed25519 is deprecated).`
|
|
3211
|
+
);
|
|
3212
|
+
}
|
|
3213
|
+
const matched = trustedKeys.find((k) => k.keyId === sig.kid);
|
|
3214
|
+
if (!matched) {
|
|
3215
|
+
throw new Error(
|
|
3216
|
+
`No trusted ML-DSA-65 key with kid=${sig.kid}. Known kids: [${trustedKeys.map((k) => k.keyId).join(", ")}]`
|
|
3217
|
+
);
|
|
3218
|
+
}
|
|
3219
|
+
let rawSig;
|
|
3220
|
+
try {
|
|
3221
|
+
rawSig = fromBase64url(sig.sig);
|
|
3222
|
+
} catch (e) {
|
|
3223
|
+
throw new Error(`Invalid base64url sig: ${e}`);
|
|
3224
|
+
}
|
|
3225
|
+
await matched.verifyBytes(canonicalMessageBytes(msg), rawSig);
|
|
3226
|
+
}
|
|
3227
|
+
var addPQSignature = signMessage;
|
|
3228
|
+
async function verifyPQSignature(msg, trustedKeys, _requirePQ = true) {
|
|
3229
|
+
return verifyMessage(msg, trustedKeys);
|
|
3230
|
+
}
|
|
3231
|
+
|
|
3098
3232
|
// src/index.ts
|
|
3099
3233
|
var VERSION = "0.6.0";
|
|
3100
3234
|
var RCAN_VERSION = "1.6";
|
|
@@ -3119,6 +3253,7 @@ export {
|
|
|
3119
3253
|
LevelOfAssurance,
|
|
3120
3254
|
M2MAuthError,
|
|
3121
3255
|
M2M_TRUSTED_ISSUER,
|
|
3256
|
+
MLDSAKeyPair,
|
|
3122
3257
|
MediaEncoding,
|
|
3123
3258
|
MessageType,
|
|
3124
3259
|
NodeClient,
|
|
@@ -3165,6 +3300,7 @@ export {
|
|
|
3165
3300
|
addDelegationHop,
|
|
3166
3301
|
addMediaInline,
|
|
3167
3302
|
addMediaRef,
|
|
3303
|
+
addPQSignature,
|
|
3168
3304
|
assertClockSynced,
|
|
3169
3305
|
authorityAccessFromWire,
|
|
3170
3306
|
authorityAccessToWire,
|
|
@@ -3218,6 +3354,7 @@ export {
|
|
|
3218
3354
|
parseM2mTrustedToken,
|
|
3219
3355
|
roleFromJwtLevel,
|
|
3220
3356
|
selectTransport,
|
|
3357
|
+
signMessage,
|
|
3221
3358
|
validateAuthorityAccess,
|
|
3222
3359
|
validateCompetitionScope,
|
|
3223
3360
|
validateConfig,
|
|
@@ -3239,6 +3376,8 @@ export {
|
|
|
3239
3376
|
validateURI,
|
|
3240
3377
|
validateVersionCompat,
|
|
3241
3378
|
verifyM2mTrustedToken,
|
|
3242
|
-
verifyM2mTrustedTokenClaims
|
|
3379
|
+
verifyM2mTrustedTokenClaims,
|
|
3380
|
+
verifyMessage,
|
|
3381
|
+
verifyPQSignature
|
|
3243
3382
|
};
|
|
3244
3383
|
//# sourceMappingURL=browser.mjs.map
|