@enbox/crypto 0.0.4 → 0.0.6

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.
@@ -0,0 +1,254 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { Cbor } from './cbor.js';
11
+ import { CoseSign1 } from './cose-sign1.js';
12
+ import { CryptoError, CryptoErrorCode } from '../crypto-error.js';
13
+ /**
14
+ * EAT (Entity Attestation Token) claim key constants.
15
+ *
16
+ * EAT reuses CWT registered claim keys and adds attestation-specific claims.
17
+ *
18
+ * @see {@link https://www.rfc-editor.org/rfc/rfc9711 | RFC 9711 — Entity Attestation Token (EAT)}
19
+ * @see {@link https://www.rfc-editor.org/rfc/rfc8392 | RFC 8392 — CWT (CBOR Web Token)}
20
+ */
21
+ export var EatClaimKey;
22
+ (function (EatClaimKey) {
23
+ /** Issuer (iss) — RFC 8392 */
24
+ EatClaimKey[EatClaimKey["Iss"] = 1] = "Iss";
25
+ /** Subject (sub) — RFC 8392 */
26
+ EatClaimKey[EatClaimKey["Sub"] = 2] = "Sub";
27
+ /** Audience (aud) — RFC 8392 */
28
+ EatClaimKey[EatClaimKey["Aud"] = 3] = "Aud";
29
+ /** Expiration Time (exp) — RFC 8392 */
30
+ EatClaimKey[EatClaimKey["Exp"] = 4] = "Exp";
31
+ /** Not Before (nbf) — RFC 8392 */
32
+ EatClaimKey[EatClaimKey["Nbf"] = 5] = "Nbf";
33
+ /** Issued At (iat) — RFC 8392 */
34
+ EatClaimKey[EatClaimKey["Iat"] = 6] = "Iat";
35
+ /** CWT ID (cti) — RFC 8392 */
36
+ EatClaimKey[EatClaimKey["Cti"] = 7] = "Cti";
37
+ /** Nonce (eat_nonce) — RFC 9711, Section 4.1 */
38
+ EatClaimKey[EatClaimKey["Nonce"] = 10] = "Nonce";
39
+ /** UEID (Universal Entity ID) — RFC 9711, Section 4.2.1 */
40
+ EatClaimKey[EatClaimKey["Ueid"] = 256] = "Ueid";
41
+ /** SUEIDs (Semi-permanent UEIDs) — RFC 9711, Section 4.2.2 */
42
+ EatClaimKey[EatClaimKey["Sueids"] = 257] = "Sueids";
43
+ /** OEM ID (Hardware OEM Identification) — RFC 9711, Section 4.2.3 */
44
+ EatClaimKey[EatClaimKey["Oemid"] = 258] = "Oemid";
45
+ /** Hardware Model — RFC 9711, Section 4.2.4 */
46
+ EatClaimKey[EatClaimKey["Hwmodel"] = 259] = "Hwmodel";
47
+ /** Hardware Version — RFC 9711, Section 4.2.5 */
48
+ EatClaimKey[EatClaimKey["Hwversion"] = 260] = "Hwversion";
49
+ /** Secure Boot — RFC 9711, Section 4.2.7 */
50
+ EatClaimKey[EatClaimKey["Secboot"] = 262] = "Secboot";
51
+ /** Debug Status — RFC 9711, Section 4.2.8 */
52
+ EatClaimKey[EatClaimKey["Dbgstat"] = 263] = "Dbgstat";
53
+ /** Location — RFC 9711, Section 4.2.9 */
54
+ EatClaimKey[EatClaimKey["Location"] = 264] = "Location";
55
+ /** Profile — RFC 9711, Section 4.2.10 */
56
+ EatClaimKey[EatClaimKey["Profile"] = 265] = "Profile";
57
+ /** Submods (Submodules) — RFC 9711, Section 4.2.18 */
58
+ EatClaimKey[EatClaimKey["Submods"] = 266] = "Submods";
59
+ /** Measurement Results — RFC 9711, Section 4.2.15 */
60
+ EatClaimKey[EatClaimKey["Measres"] = 272] = "Measres";
61
+ /** Intended Use — RFC 9711, Section 4.2.14 */
62
+ EatClaimKey[EatClaimKey["Intuse"] = 268] = "Intuse";
63
+ })(EatClaimKey || (EatClaimKey = {}));
64
+ /**
65
+ * Debug status values for the `dbgstat` claim.
66
+ *
67
+ * @see {@link https://www.rfc-editor.org/rfc/rfc9711#section-4.2.8 | RFC 9711, Section 4.2.8}
68
+ */
69
+ export var EatDebugStatus;
70
+ (function (EatDebugStatus) {
71
+ /** Debug is enabled */
72
+ EatDebugStatus[EatDebugStatus["Enabled"] = 0] = "Enabled";
73
+ /** Debug is disabled */
74
+ EatDebugStatus[EatDebugStatus["Disabled"] = 1] = "Disabled";
75
+ /** Debug is disabled since manufacture */
76
+ EatDebugStatus[EatDebugStatus["DisabledSinceBoot"] = 2] = "DisabledSinceBoot";
77
+ /** Debug is disabled permanently */
78
+ EatDebugStatus[EatDebugStatus["DisabledPermanently"] = 3] = "DisabledPermanently";
79
+ /** Debug is disabled fully and permanently */
80
+ EatDebugStatus[EatDebugStatus["DisabledFullyAndPermanently"] = 4] = "DisabledFullyAndPermanently";
81
+ })(EatDebugStatus || (EatDebugStatus = {}));
82
+ /**
83
+ * Security level for the `seclevel` claim.
84
+ *
85
+ * @see {@link https://www.rfc-editor.org/rfc/rfc9711#section-4.2.6 | RFC 9711, Section 4.2.6}
86
+ */
87
+ export var EatSecurityLevel;
88
+ (function (EatSecurityLevel) {
89
+ /** Unrestricted — no security guarantees */
90
+ EatSecurityLevel[EatSecurityLevel["Unrestricted"] = 1] = "Unrestricted";
91
+ /** Restricted — some restrictions on environment */
92
+ EatSecurityLevel[EatSecurityLevel["Restricted"] = 2] = "Restricted";
93
+ /** Secure Restricted — hardware-enforced restrictions */
94
+ EatSecurityLevel[EatSecurityLevel["SecureRestricted"] = 3] = "SecureRestricted";
95
+ /** Hardware — hardware-isolated execution environment */
96
+ EatSecurityLevel[EatSecurityLevel["Hardware"] = 4] = "Hardware";
97
+ })(EatSecurityLevel || (EatSecurityLevel = {}));
98
+ /**
99
+ * Entity Attestation Token (EAT) implementation per RFC 9711.
100
+ *
101
+ * EATs are CBOR-based attestation tokens carried in COSE_Sign1 envelopes.
102
+ * They are used by TEE platforms (ARM CCA, Intel TDX, AMD SEV-SNP, Nitro Enclaves)
103
+ * to provide hardware-rooted attestation evidence.
104
+ *
105
+ * This implementation focuses on decoding and verification of EAT tokens — the
106
+ * primary use case for a DWN node that needs to verify TEE attestation from
107
+ * compute modules.
108
+ *
109
+ * @see {@link https://www.rfc-editor.org/rfc/rfc9711 | RFC 9711 — Entity Attestation Token (EAT)}
110
+ */
111
+ export class Eat {
112
+ /**
113
+ * Decodes an EAT token without verifying its signature.
114
+ *
115
+ * Use this method only when signature verification is performed separately
116
+ * (e.g., by a TEE attestation service) or for debugging/inspection.
117
+ *
118
+ * @param params - The parameters for decoding.
119
+ * @returns The decoded protected header and claims.
120
+ * @throws {CryptoError} If the token is not valid COSE_Sign1 or the payload is not valid CBOR.
121
+ */
122
+ static decode({ token }) {
123
+ // Decode the COSE_Sign1 envelope.
124
+ const coseSign1 = CoseSign1.decode(token);
125
+ if (coseSign1.payload === null) {
126
+ throw new CryptoError(CryptoErrorCode.InvalidEat, 'Eat: token has detached payload; use verifyAndDecode with the payload provided separately');
127
+ }
128
+ // Decode the CBOR payload into claims.
129
+ const claims = Eat.parseClaims(coseSign1.payload);
130
+ return {
131
+ protectedHeader: coseSign1.protectedHeader,
132
+ claims,
133
+ };
134
+ }
135
+ /**
136
+ * Verifies the signature of an EAT token and decodes its claims.
137
+ *
138
+ * This is the primary method for processing EAT tokens from TEE attestation.
139
+ * It verifies the COSE_Sign1 signature using the provided public key, then
140
+ * parses the EAT claims from the payload.
141
+ *
142
+ * @param params - The parameters for verification and decoding.
143
+ * @returns The decoded protected header and claims if verification succeeds.
144
+ * @throws {CryptoError} If verification fails or the token is malformed.
145
+ */
146
+ static verifyAndDecode(params) {
147
+ return __awaiter(this, void 0, void 0, function* () {
148
+ const { token, key, externalAad } = params;
149
+ // Verify the COSE_Sign1 signature.
150
+ const isValid = yield CoseSign1.verify({
151
+ coseSign1: token,
152
+ key,
153
+ externalAad,
154
+ });
155
+ if (!isValid) {
156
+ throw new CryptoError(CryptoErrorCode.InvalidEat, 'Eat: signature verification failed');
157
+ }
158
+ // Decode and return claims (signature is already verified).
159
+ return Eat.decode({ token });
160
+ });
161
+ }
162
+ /**
163
+ * Parses CBOR-encoded EAT claims into a typed {@link EatClaims} object.
164
+ *
165
+ * Handles both integer-keyed (CBOR standard) and string-keyed claims.
166
+ *
167
+ * @param payload - The CBOR-encoded claims byte string.
168
+ * @returns The parsed EAT claims.
169
+ * @throws {CryptoError} If the payload is not valid CBOR or not a map.
170
+ */
171
+ static parseClaims(payload) {
172
+ let rawClaims;
173
+ try {
174
+ const decoded = Cbor.decode(payload);
175
+ if (decoded instanceof Map) {
176
+ rawClaims = decoded;
177
+ }
178
+ else if (typeof decoded === 'object' && decoded !== null) {
179
+ // Some encoders produce plain objects instead of Maps for maps with string keys.
180
+ rawClaims = new Map(Object.entries(decoded));
181
+ }
182
+ else {
183
+ throw new Error('not a map');
184
+ }
185
+ }
186
+ catch (error) {
187
+ if (error instanceof CryptoError) {
188
+ throw error;
189
+ }
190
+ throw new CryptoError(CryptoErrorCode.InvalidEat, 'Eat: payload is not a valid CBOR map');
191
+ }
192
+ const claims = { rawClaims };
193
+ // Extract standard CWT claims.
194
+ const iss = rawClaims.get(EatClaimKey.Iss);
195
+ if (iss !== undefined) {
196
+ claims.iss = iss;
197
+ }
198
+ const sub = rawClaims.get(EatClaimKey.Sub);
199
+ if (sub !== undefined) {
200
+ claims.sub = sub;
201
+ }
202
+ const aud = rawClaims.get(EatClaimKey.Aud);
203
+ if (aud !== undefined) {
204
+ claims.aud = aud;
205
+ }
206
+ const exp = rawClaims.get(EatClaimKey.Exp);
207
+ if (exp !== undefined) {
208
+ claims.exp = exp;
209
+ }
210
+ const nbf = rawClaims.get(EatClaimKey.Nbf);
211
+ if (nbf !== undefined) {
212
+ claims.nbf = nbf;
213
+ }
214
+ const iat = rawClaims.get(EatClaimKey.Iat);
215
+ if (iat !== undefined) {
216
+ claims.iat = iat;
217
+ }
218
+ const cti = rawClaims.get(EatClaimKey.Cti);
219
+ if (cti !== undefined) {
220
+ claims.cti = cti;
221
+ }
222
+ // Extract EAT-specific claims.
223
+ const nonce = rawClaims.get(EatClaimKey.Nonce);
224
+ if (nonce !== undefined) {
225
+ claims.nonce = nonce;
226
+ }
227
+ const ueid = rawClaims.get(EatClaimKey.Ueid);
228
+ if (ueid !== undefined) {
229
+ claims.ueid = ueid;
230
+ }
231
+ const hwmodel = rawClaims.get(EatClaimKey.Hwmodel);
232
+ if (hwmodel !== undefined) {
233
+ claims.hwmodel = hwmodel;
234
+ }
235
+ const hwversion = rawClaims.get(EatClaimKey.Hwversion);
236
+ if (hwversion !== undefined) {
237
+ claims.hwversion = hwversion;
238
+ }
239
+ const dbgstat = rawClaims.get(EatClaimKey.Dbgstat);
240
+ if (dbgstat !== undefined) {
241
+ claims.dbgstat = dbgstat;
242
+ }
243
+ const measres = rawClaims.get(EatClaimKey.Measres);
244
+ if (measres !== undefined) {
245
+ claims.measres = measres;
246
+ }
247
+ const submods = rawClaims.get(EatClaimKey.Submods);
248
+ if (submods !== undefined) {
249
+ claims.submods = submods;
250
+ }
251
+ return claims;
252
+ }
253
+ }
254
+ //# sourceMappingURL=eat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eat.js","sourceRoot":"","sources":["../../../src/cose/eat.ts"],"names":[],"mappings":";;;;;;;;;AAGA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAElE;;;;;;;GAOG;AACH,MAAM,CAAN,IAAY,WAyCX;AAzCD,WAAY,WAAW;IACrB,8BAA8B;IAC9B,2CAAO,CAAA;IACP,+BAA+B;IAC/B,2CAAO,CAAA;IACP,gCAAgC;IAChC,2CAAO,CAAA;IACP,uCAAuC;IACvC,2C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,CAAC;QACnD,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC1B,MAAM,CAAC,OAAO,GAAG,OAAyB,CAAC;QAC7C,CAAC;QAED,MAAM,OAAO,GAAG,SAAS,CAAC,GAAG,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QACnD,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC1B,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC;QAC3B,CAAC;QAED,MAAM,OAAO,GAAG,SAAS,CAAC,GAAG,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QACnD,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC1B,MAAM,CAAC,OAAO,GAAG,OAA+B,CAAC;QACnD,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
@@ -31,6 +31,10 @@ export var CryptoErrorCode;
31
31
  CryptoErrorCode["AlgorithmNotSupported"] = "algorithmNotSupported";
32
32
  /** The encoding operation (either encoding or decoding) failed. */
33
33
  CryptoErrorCode["EncodingError"] = "encodingError";
34
+ /** The COSE_Sign1 message does not conform to valid structure. */
35
+ CryptoErrorCode["InvalidCoseSign1"] = "invalidCoseSign1";
36
+ /** The EAT (Entity Attestation Token) is malformed or failed verification. */
37
+ CryptoErrorCode["InvalidEat"] = "invalidEat";
34
38
  /** The JWE supplied does not conform to valid syntax. */
35
39
  CryptoErrorCode["InvalidJwe"] = "invalidJwe";
36
40
  /** The JWK supplied does not conform to valid syntax. */
@@ -1 +1 @@
1
- {"version":3,"file":"crypto-error.js","sourceRoot":"","sources":["../../src/crypto-error.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,OAAO,WAAY,SAAQ,KAAK;IACpC;;;;;OAKG;IACH,YAAmB,IAAqB,EAAE,OAAe;QACvD,KAAK,CAAC,OAAO,CAAC,CAAC;QADE,SAAI,GAAJ,IAAI,CAAiB;QAEtC,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;QAE1B,8FAA8F;QAC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AA+B,CAAA;IAE/B,kEAAkE;IAClE,wDAAqC,CAAA;IAErC,8EAA8E;IAC9E,4CAAyB,CAAA;IAEzB,yDAAyD;IACzD,4CAAyB,CAAA;IAEzB,yDAAyD;IACzD,4CAAyB,CAAA;IAEzB,sEAAsE;IACtE,kEAA+C,CAAA;AACjD,CAAC,EArBW,eAAe,KAAf,eAAe,QAqB1B"}
package/dist/esm/index.js CHANGED
@@ -1,6 +1,10 @@
1
1
  export * from './crypto-error.js';
2
2
  export * from './local-key-manager.js';
3
3
  export * from './utils.js';
4
+ export * from './cose/cbor.js';
5
+ export * from './cose/cose-key.js';
6
+ export * from './cose/cose-sign1.js';
7
+ export * from './cose/eat.js';
4
8
  export * from './algorithms/aes-ctr.js';
5
9
  export * from './algorithms/aes-gcm.js';
6
10
  export * from './algorithms/aes-kw.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,YAAY,CAAC;AAE3B,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,kCAAkC,CAAC;AACjD,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AAEvC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAEhC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,iCAAiC,CAAC;AAChD,cAAc,yBAAyB,CAAC;AACxC,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@ -0,0 +1,30 @@
1
+ /**
2
+ * CBOR (Concise Binary Object Representation) encoding and decoding utilities.
3
+ *
4
+ * Provides a thin wrapper around the `cborg` library, exposing `encode` and `decode`
5
+ * operations for use by COSE and EAT implementations.
6
+ *
7
+ * @see {@link https://www.rfc-editor.org/rfc/rfc8949 | RFC 8949 — CBOR}
8
+ */
9
+ export declare class Cbor {
10
+ /**
11
+ * Encodes a JavaScript value to a CBOR byte string.
12
+ *
13
+ * @param value - The value to encode. Supports objects, arrays, strings, numbers,
14
+ * booleans, null, undefined, Uint8Array (encoded as CBOR byte string), and Map.
15
+ * @returns The CBOR-encoded bytes.
16
+ */
17
+ static encode(value: unknown): Uint8Array;
18
+ /**
19
+ * Decodes a CBOR byte string to a JavaScript value.
20
+ *
21
+ * CBOR maps are decoded as JavaScript `Map` instances to support integer keys,
22
+ * which is required by COSE (RFC 9052) and EAT (RFC 9711).
23
+ *
24
+ * @param data - The CBOR-encoded bytes to decode.
25
+ * @returns The decoded JavaScript value.
26
+ * @throws If the input is not valid CBOR.
27
+ */
28
+ static decode<T = unknown>(data: Uint8Array): T;
29
+ }
30
+ //# sourceMappingURL=cbor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cbor.d.ts","sourceRoot":"","sources":["../../../src/cose/cbor.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,qBAAa,IAAI;IACf;;;;;;OAMG;WACW,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU;IAIhD;;;;;;;;;OASG;WACW,MAAM,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,UAAU,GAAG,CAAC;CAGvD"}
@@ -0,0 +1,106 @@
1
+ import type { Jwk } from '../jose/jwk.js';
2
+ /**
3
+ * COSE Key Type values (RFC 9052, Section 7).
4
+ *
5
+ * @see {@link https://www.iana.org/assignments/cose/cose.xhtml#key-type | IANA COSE Key Types}
6
+ */
7
+ export declare enum CoseKeyType {
8
+ /** Octet Key Pair (e.g., Ed25519, X25519) */
9
+ OKP = 1,
10
+ /** Elliptic Curve (e.g., P-256, P-384, P-521) */
11
+ EC2 = 2,
12
+ /** Symmetric key */
13
+ Symmetric = 4
14
+ }
15
+ /**
16
+ * COSE Elliptic Curve identifiers (RFC 9053, Section 7.1).
17
+ *
18
+ * @see {@link https://www.iana.org/assignments/cose/cose.xhtml#elliptic-curves | IANA COSE Elliptic Curves}
19
+ */
20
+ export declare enum CoseEllipticCurve {
21
+ /** NIST P-256 (secp256r1) */
22
+ P256 = 1,
23
+ /** NIST P-384 (secp384r1) */
24
+ P384 = 2,
25
+ /** NIST P-521 (secp521r1) */
26
+ P521 = 3,
27
+ /** X25519 for ECDH */
28
+ X25519 = 4,
29
+ /** X448 for ECDH */
30
+ X448 = 5,
31
+ /** Ed25519 for EdDSA */
32
+ Ed25519 = 6,
33
+ /** Ed448 for EdDSA */
34
+ Ed448 = 7,
35
+ /** secp256k1 */
36
+ Secp256k1 = 8
37
+ }
38
+ /**
39
+ * COSE Algorithm identifiers (RFC 9053).
40
+ *
41
+ * Only includes algorithms relevant to Enbox confidential compute.
42
+ *
43
+ * @see {@link https://www.iana.org/assignments/cose/cose.xhtml#algorithms | IANA COSE Algorithms}
44
+ */
45
+ export declare enum CoseAlgorithm {
46
+ /** EdDSA (Ed25519 or Ed448) */
47
+ EdDSA = -8,
48
+ /** ECDSA with SHA-256 (P-256) */
49
+ ES256 = -7,
50
+ /** ECDSA with SHA-384 (P-384) */
51
+ ES384 = -35,
52
+ /** ECDSA with SHA-512 (P-521) */
53
+ ES512 = -36,
54
+ /** ECDSA with SHA-256 (secp256k1) */
55
+ ES256K = -47
56
+ }
57
+ /**
58
+ * Utilities for converting between JWK and COSE key representations.
59
+ *
60
+ * COSE keys use integer labels and CBOR encoding, while JWK uses string
61
+ * property names and JSON. This class provides bidirectional conversion.
62
+ *
63
+ * @see {@link https://www.rfc-editor.org/rfc/rfc9052#section-7 | RFC 9052, Section 7}
64
+ */
65
+ export declare class CoseKey {
66
+ /**
67
+ * Converts a JWK to a COSE key represented as a Map.
68
+ *
69
+ * @param jwk - The JWK to convert.
70
+ * @returns A Map with integer labels as keys, suitable for CBOR encoding.
71
+ * @throws {CryptoError} If the JWK key type or curve is not supported.
72
+ */
73
+ static fromJwk(jwk: Jwk): Map<number, unknown>;
74
+ /**
75
+ * Converts a COSE key Map to a JWK.
76
+ *
77
+ * @param coseKey - A Map with integer labels as keys (from CBOR decoding).
78
+ * @returns The equivalent JWK.
79
+ * @throws {CryptoError} If the COSE key type or curve is not supported.
80
+ */
81
+ static toJwk(coseKey: Map<number, unknown>): Jwk;
82
+ /**
83
+ * Infers the COSE algorithm identifier from a JWK.
84
+ *
85
+ * If the JWK has an `alg` field, it is used directly. Otherwise, the algorithm
86
+ * is inferred from the key type and curve.
87
+ *
88
+ * @param jwk - The JWK to infer the algorithm from.
89
+ * @returns The COSE algorithm identifier.
90
+ * @throws {CryptoError} If the algorithm cannot be determined.
91
+ */
92
+ static algorithmFromJwk(jwk: Jwk): CoseAlgorithm;
93
+ /**
94
+ * Maps a COSE algorithm identifier to a JWK algorithm name.
95
+ *
96
+ * @param alg - The COSE algorithm identifier.
97
+ * @returns The JWK algorithm name.
98
+ * @throws {CryptoError} If the algorithm is not supported.
99
+ */
100
+ static algorithmToJwk(alg: CoseAlgorithm): string;
101
+ /**
102
+ * Applies common COSE key fields (kid, alg) to a JWK.
103
+ */
104
+ private static applyCommonFields;
105
+ }
106
+ //# sourceMappingURL=cose-key.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cose-key.d.ts","sourceRoot":"","sources":["../../../src/cose/cose-key.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAM1C;;;;GAIG;AACH,oBAAY,WAAW;IACrB,6CAA6C;IAC7C,GAAG,IAAI;IACP,iDAAiD;IACjD,GAAG,IAAI;IACP,oBAAoB;IACpB,SAAS,IAAI;CACd;AAED;;;;GAIG;AACH,oBAAY,iBAAiB;IAC3B,6BAA6B;IAC7B,IAAI,IAAI;IACR,6BAA6B;IAC7B,IAAI,IAAI;IACR,6BAA6B;IAC7B,IAAI,IAAI;IACR,sBAAsB;IACtB,MAAM,IAAI;IACV,oBAAoB;IACpB,IAAI,IAAI;IACR,wBAAwB;IACxB,OAAO,IAAI;IACX,sBAAsB;IACtB,KAAK,IAAI;IACT,gBAAgB;IAChB,SAAS,IAAI;CACd;AAED;;;;;;GAMG;AACH,oBAAY,aAAa;IACvB,+BAA+B;IAC/B,KAAK,KAAK;IACV,iCAAiC;IACjC,KAAK,KAAK;IACV,iCAAiC;IACjC,KAAK,MAAM;IACX,iCAAiC;IACjC,KAAK,MAAM;IACX,qCAAqC;IACrC,MAAM,MAAM;CACb;AAmFD;;;;;;;GAOG;AACH,qBAAa,OAAO;IAClB;;;;;;OAMG;WACW,OAAO,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC;IAmDrD;;;;;;OAMG;WACW,KAAK,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,GAAG;IA6DvD;;;;;;;;;OASG;WACW,gBAAgB,CAAC,GAAG,EAAE,GAAG,GAAG,aAAa;IAyBvD;;;;;;OAMG;WACW,cAAc,CAAC,GAAG,EAAE,aAAa,GAAG,MAAM;IAOxD;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,iBAAiB;CAWjC"}
@@ -0,0 +1,195 @@
1
+ import type { Jwk } from '../jose/jwk.js';
2
+ import { CoseAlgorithm } from './cose-key.js';
3
+ /**
4
+ * COSE_Sign1 protected header parameters.
5
+ *
6
+ * The protected header is integrity-protected by inclusion in the Sig_structure.
7
+ * At minimum, it MUST contain the algorithm identifier.
8
+ *
9
+ * @see {@link https://www.rfc-editor.org/rfc/rfc9052#section-4 | RFC 9052, Section 4}
10
+ */
11
+ export interface CoseSign1ProtectedHeader {
12
+ /** Algorithm identifier (label 1). Required. */
13
+ alg: CoseAlgorithm;
14
+ /** Content type (label 3). */
15
+ contentType?: string | number;
16
+ /** Key ID (label 4). */
17
+ kid?: Uint8Array;
18
+ /** Additional header parameters. */
19
+ [key: string]: unknown;
20
+ }
21
+ /**
22
+ * COSE_Sign1 unprotected header parameters.
23
+ *
24
+ * These parameters are NOT integrity-protected.
25
+ *
26
+ * @see {@link https://www.rfc-editor.org/rfc/rfc9052#section-4 | RFC 9052, Section 4}
27
+ */
28
+ export interface CoseSign1UnprotectedHeader {
29
+ /** Key ID (label 4). */
30
+ kid?: Uint8Array;
31
+ /** Additional header parameters. */
32
+ [key: string]: unknown;
33
+ }
34
+ /**
35
+ * Parameters for creating a COSE_Sign1 structure.
36
+ */
37
+ export interface CoseSign1CreateParams {
38
+ /** The signing key in JWK format. Must contain the private key (`d`). */
39
+ key: Jwk;
40
+ /** The payload to sign. */
41
+ payload: Uint8Array;
42
+ /**
43
+ * Protected header parameters. If omitted, the algorithm is inferred from the key
44
+ * and a minimal protected header `{ alg }` is used.
45
+ */
46
+ protectedHeader?: CoseSign1ProtectedHeader;
47
+ /** Unprotected header parameters. */
48
+ unprotectedHeader?: CoseSign1UnprotectedHeader;
49
+ /**
50
+ * External additional authenticated data (external_aad).
51
+ * Included in the Sig_structure but not in the COSE_Sign1 message itself.
52
+ * Defaults to empty bytes.
53
+ */
54
+ externalAad?: Uint8Array;
55
+ /**
56
+ * If true, the payload is detached (not included in the COSE_Sign1 serialization).
57
+ * The payload field in the CBOR array will be `null`.
58
+ */
59
+ detachedPayload?: boolean;
60
+ }
61
+ /**
62
+ * Parameters for verifying a COSE_Sign1 structure.
63
+ */
64
+ export interface CoseSign1VerifyParams {
65
+ /** The COSE_Sign1 CBOR-encoded message to verify. */
66
+ coseSign1: Uint8Array;
67
+ /** The public key in JWK format for verification. */
68
+ key: Jwk;
69
+ /**
70
+ * External additional authenticated data (external_aad).
71
+ * Must match the value used during signing.
72
+ * Defaults to empty bytes.
73
+ */
74
+ externalAad?: Uint8Array;
75
+ /**
76
+ * Detached payload. Required if the COSE_Sign1 was created with `detachedPayload: true`.
77
+ */
78
+ payload?: Uint8Array;
79
+ }
80
+ /**
81
+ * Decoded COSE_Sign1 structure.
82
+ */
83
+ export interface CoseSign1Decoded {
84
+ /** The protected header parameters (decoded from CBOR). */
85
+ protectedHeader: CoseSign1ProtectedHeader;
86
+ /** The raw protected header bytes (needed for signature verification). */
87
+ protectedHeaderBytes: Uint8Array;
88
+ /** The unprotected header parameters. */
89
+ unprotectedHeader: Map<number, unknown>;
90
+ /** The payload (null if detached). */
91
+ payload: Uint8Array | null;
92
+ /** The signature. */
93
+ signature: Uint8Array;
94
+ }
95
+ /**
96
+ * CBOR tag for COSE_Sign1 (RFC 9052, Section 4.2).
97
+ */
98
+ /**
99
+ * COSE_Sign1 implementation per RFC 9052.
100
+ *
101
+ * Provides creation, verification, and decoding of COSE_Sign1 (single-signer)
102
+ * signed messages. This is the CBOR-based counterpart to JOSE/JWS and is used
103
+ * in TEE attestation (EAT tokens), CWT, and other COSE-based protocols.
104
+ *
105
+ * Supported algorithms:
106
+ * - EdDSA (Ed25519) — CoseAlgorithm.EdDSA (-8)
107
+ * - ES256 (P-256 / secp256r1 with SHA-256) — CoseAlgorithm.ES256 (-7)
108
+ *
109
+ * @see {@link https://www.rfc-editor.org/rfc/rfc9052#section-4.3 | RFC 9052, Section 4.3}
110
+ */
111
+ export declare class CoseSign1 {
112
+ /**
113
+ * Creates a COSE_Sign1 message.
114
+ *
115
+ * Constructs the `Sig_structure1` to-be-signed bytes per RFC 9052 Section 4.4,
116
+ * signs them with the provided key, and returns the CBOR-encoded COSE_Sign1 array:
117
+ *
118
+ * ```
119
+ * COSE_Sign1 = [
120
+ * protected : bstr, ; CBOR-encoded protected header
121
+ * unprotected : map, ; unprotected header parameters
122
+ * payload : bstr / nil, ; payload (nil if detached)
123
+ * signature : bstr ; signature
124
+ * ]
125
+ * ```
126
+ *
127
+ * @param params - The parameters for creating the COSE_Sign1 message.
128
+ * @returns The CBOR-encoded COSE_Sign1 message.
129
+ * @throws {CryptoError} If the algorithm is not supported or signing fails.
130
+ *
131
+ * @see {@link https://www.rfc-editor.org/rfc/rfc9052#section-4.3 | RFC 9052, Section 4.3}
132
+ * @see {@link https://www.rfc-editor.org/rfc/rfc9052#section-4.4 | RFC 9052, Section 4.4}
133
+ */
134
+ static create(params: CoseSign1CreateParams): Promise<Uint8Array>;
135
+ /**
136
+ * Verifies a COSE_Sign1 message.
137
+ *
138
+ * Decodes the CBOR-encoded message, reconstructs the `Sig_structure1`, and verifies
139
+ * the signature using the provided public key.
140
+ *
141
+ * @param params - The parameters for verifying the COSE_Sign1 message.
142
+ * @returns `true` if the signature is valid, `false` otherwise.
143
+ * @throws {CryptoError} If the message is malformed or the algorithm is not supported.
144
+ *
145
+ * @see {@link https://www.rfc-editor.org/rfc/rfc9052#section-4.4 | RFC 9052, Section 4.4}
146
+ */
147
+ static verify(params: CoseSign1VerifyParams): Promise<boolean>;
148
+ /**
149
+ * Decodes a CBOR-encoded COSE_Sign1 message into its constituent parts.
150
+ *
151
+ * The COSE_Sign1 structure is a CBOR array of four elements:
152
+ * ```
153
+ * [protected, unprotected, payload, signature]
154
+ * ```
155
+ *
156
+ * The message may optionally be wrapped in CBOR tag 18.
157
+ *
158
+ * @param coseSign1 - The CBOR-encoded COSE_Sign1 message.
159
+ * @returns The decoded COSE_Sign1 components.
160
+ * @throws {CryptoError} If the message does not conform to COSE_Sign1 structure.
161
+ */
162
+ static decode(coseSign1: Uint8Array): CoseSign1Decoded;
163
+ /**
164
+ * Builds the Sig_structure1 array for COSE_Sign1 signing and verification.
165
+ *
166
+ * ```
167
+ * Sig_structure1 = [
168
+ * context : "Signature1",
169
+ * body_protected : bstr,
170
+ * external_aad : bstr,
171
+ * payload : bstr
172
+ * ]
173
+ * ```
174
+ *
175
+ * @see {@link https://www.rfc-editor.org/rfc/rfc9052#section-4.4 | RFC 9052, Section 4.4}
176
+ */
177
+ private static buildSigStructure1;
178
+ /**
179
+ * Converts a {@link CoseSign1ProtectedHeader} to a CBOR Map with integer labels.
180
+ */
181
+ private static buildProtectedHeaderMap;
182
+ /**
183
+ * Converts a {@link CoseSign1UnprotectedHeader} to a CBOR Map with integer labels.
184
+ */
185
+ private static buildUnprotectedHeaderMap;
186
+ /**
187
+ * Signs the to-be-signed bytes with the appropriate algorithm.
188
+ */
189
+ private static signBytes;
190
+ /**
191
+ * Verifies a signature over the to-be-signed bytes with the appropriate algorithm.
192
+ */
193
+ private static verifyBytes;
194
+ }
195
+ //# sourceMappingURL=cose-sign1.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cose-sign1.d.ts","sourceRoot":"","sources":["../../../src/cose/cose-sign1.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAK1C,OAAO,EAAE,aAAa,EAAW,MAAM,eAAe,CAAC;AAGvD;;;;;;;GAOG;AACH,MAAM,WAAW,wBAAwB;IACvC,gDAAgD;IAChD,GAAG,EAAE,aAAa,CAAC;IAEnB,8BAA8B;IAC9B,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAE9B,wBAAwB;IACxB,GAAG,CAAC,EAAE,UAAU,CAAC;IAEjB,oCAAoC;IACpC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,0BAA0B;IACzC,wBAAwB;IACxB,GAAG,CAAC,EAAE,UAAU,CAAC;IAEjB,oCAAoC;IACpC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,yEAAyE;IACzE,GAAG,EAAE,GAAG,CAAC;IAET,2BAA2B;IAC3B,OAAO,EAAE,UAAU,CAAC;IAEpB;;;OAGG;IACH,eAAe,CAAC,EAAE,wBAAwB,CAAC;IAE3C,qCAAqC;IACrC,iBAAiB,CAAC,EAAE,0BAA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