@enbox/crypto 0.0.4 → 0.0.5
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.mjs +1 -1
- package/dist/browser.mjs.map +4 -4
- package/dist/esm/cose/cbor.js +35 -0
- package/dist/esm/cose/cbor.js.map +1 -0
- package/dist/esm/cose/cose-key.js +312 -0
- package/dist/esm/cose/cose-key.js.map +1 -0
- package/dist/esm/cose/cose-sign1.js +283 -0
- package/dist/esm/cose/cose-sign1.js.map +1 -0
- package/dist/esm/cose/eat.js +254 -0
- package/dist/esm/cose/eat.js.map +1 -0
- package/dist/esm/crypto-error.js +4 -0
- package/dist/esm/crypto-error.js.map +1 -1
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/types/cose/cbor.d.ts +30 -0
- package/dist/types/cose/cbor.d.ts.map +1 -0
- package/dist/types/cose/cose-key.d.ts +106 -0
- package/dist/types/cose/cose-key.d.ts.map +1 -0
- package/dist/types/cose/cose-sign1.d.ts +195 -0
- package/dist/types/cose/cose-sign1.d.ts.map +1 -0
- package/dist/types/cose/eat.d.ts +203 -0
- package/dist/types/cose/eat.d.ts.map +1 -0
- package/dist/types/crypto-error.d.ts +4 -0
- package/dist/types/crypto-error.d.ts.map +1 -1
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +4 -3
- package/src/cose/cbor.ts +36 -0
- package/src/cose/cose-key.ts +344 -0
- package/src/cose/cose-sign1.ts +473 -0
- package/src/cose/eat.ts +368 -0
- package/src/crypto-error.ts +6 -0
- package/src/index.ts +5 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { decode as cborDecode, encode as cborEncode } from 'cborg';
|
|
2
|
+
/**
|
|
3
|
+
* CBOR (Concise Binary Object Representation) encoding and decoding utilities.
|
|
4
|
+
*
|
|
5
|
+
* Provides a thin wrapper around the `cborg` library, exposing `encode` and `decode`
|
|
6
|
+
* operations for use by COSE and EAT implementations.
|
|
7
|
+
*
|
|
8
|
+
* @see {@link https://www.rfc-editor.org/rfc/rfc8949 | RFC 8949 — CBOR}
|
|
9
|
+
*/
|
|
10
|
+
export class Cbor {
|
|
11
|
+
/**
|
|
12
|
+
* Encodes a JavaScript value to a CBOR byte string.
|
|
13
|
+
*
|
|
14
|
+
* @param value - The value to encode. Supports objects, arrays, strings, numbers,
|
|
15
|
+
* booleans, null, undefined, Uint8Array (encoded as CBOR byte string), and Map.
|
|
16
|
+
* @returns The CBOR-encoded bytes.
|
|
17
|
+
*/
|
|
18
|
+
static encode(value) {
|
|
19
|
+
return cborEncode(value);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Decodes a CBOR byte string to a JavaScript value.
|
|
23
|
+
*
|
|
24
|
+
* CBOR maps are decoded as JavaScript `Map` instances to support integer keys,
|
|
25
|
+
* which is required by COSE (RFC 9052) and EAT (RFC 9711).
|
|
26
|
+
*
|
|
27
|
+
* @param data - The CBOR-encoded bytes to decode.
|
|
28
|
+
* @returns The decoded JavaScript value.
|
|
29
|
+
* @throws If the input is not valid CBOR.
|
|
30
|
+
*/
|
|
31
|
+
static decode(data) {
|
|
32
|
+
return cborDecode(data, { useMaps: true });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=cbor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cbor.js","sourceRoot":"","sources":["../../../src/cose/cbor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,OAAO,CAAC;AAEnE;;;;;;;GAOG;AACH,MAAM,OAAO,IAAI;IACf;;;;;;OAMG;IACI,MAAM,CAAC,MAAM,CAAC,KAAc;QACjC,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC;IAC3B,CAAC;IAED;;;;;;;;;OASG;IACI,MAAM,CAAC,MAAM,CAAc,IAAgB;QAChD,OAAO,UAAU,CAAC,IAAI,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAM,CAAC;IAClD,CAAC;CACF"}
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import { Convert } from '@enbox/common';
|
|
2
|
+
import { CryptoError, CryptoErrorCode } from '../crypto-error.js';
|
|
3
|
+
/**
|
|
4
|
+
* COSE Key Type values (RFC 9052, Section 7).
|
|
5
|
+
*
|
|
6
|
+
* @see {@link https://www.iana.org/assignments/cose/cose.xhtml#key-type | IANA COSE Key Types}
|
|
7
|
+
*/
|
|
8
|
+
export var CoseKeyType;
|
|
9
|
+
(function (CoseKeyType) {
|
|
10
|
+
/** Octet Key Pair (e.g., Ed25519, X25519) */
|
|
11
|
+
CoseKeyType[CoseKeyType["OKP"] = 1] = "OKP";
|
|
12
|
+
/** Elliptic Curve (e.g., P-256, P-384, P-521) */
|
|
13
|
+
CoseKeyType[CoseKeyType["EC2"] = 2] = "EC2";
|
|
14
|
+
/** Symmetric key */
|
|
15
|
+
CoseKeyType[CoseKeyType["Symmetric"] = 4] = "Symmetric";
|
|
16
|
+
})(CoseKeyType || (CoseKeyType = {}));
|
|
17
|
+
/**
|
|
18
|
+
* COSE Elliptic Curve identifiers (RFC 9053, Section 7.1).
|
|
19
|
+
*
|
|
20
|
+
* @see {@link https://www.iana.org/assignments/cose/cose.xhtml#elliptic-curves | IANA COSE Elliptic Curves}
|
|
21
|
+
*/
|
|
22
|
+
export var CoseEllipticCurve;
|
|
23
|
+
(function (CoseEllipticCurve) {
|
|
24
|
+
/** NIST P-256 (secp256r1) */
|
|
25
|
+
CoseEllipticCurve[CoseEllipticCurve["P256"] = 1] = "P256";
|
|
26
|
+
/** NIST P-384 (secp384r1) */
|
|
27
|
+
CoseEllipticCurve[CoseEllipticCurve["P384"] = 2] = "P384";
|
|
28
|
+
/** NIST P-521 (secp521r1) */
|
|
29
|
+
CoseEllipticCurve[CoseEllipticCurve["P521"] = 3] = "P521";
|
|
30
|
+
/** X25519 for ECDH */
|
|
31
|
+
CoseEllipticCurve[CoseEllipticCurve["X25519"] = 4] = "X25519";
|
|
32
|
+
/** X448 for ECDH */
|
|
33
|
+
CoseEllipticCurve[CoseEllipticCurve["X448"] = 5] = "X448";
|
|
34
|
+
/** Ed25519 for EdDSA */
|
|
35
|
+
CoseEllipticCurve[CoseEllipticCurve["Ed25519"] = 6] = "Ed25519";
|
|
36
|
+
/** Ed448 for EdDSA */
|
|
37
|
+
CoseEllipticCurve[CoseEllipticCurve["Ed448"] = 7] = "Ed448";
|
|
38
|
+
/** secp256k1 */
|
|
39
|
+
CoseEllipticCurve[CoseEllipticCurve["Secp256k1"] = 8] = "Secp256k1";
|
|
40
|
+
})(CoseEllipticCurve || (CoseEllipticCurve = {}));
|
|
41
|
+
/**
|
|
42
|
+
* COSE Algorithm identifiers (RFC 9053).
|
|
43
|
+
*
|
|
44
|
+
* Only includes algorithms relevant to Enbox confidential compute.
|
|
45
|
+
*
|
|
46
|
+
* @see {@link https://www.iana.org/assignments/cose/cose.xhtml#algorithms | IANA COSE Algorithms}
|
|
47
|
+
*/
|
|
48
|
+
export var CoseAlgorithm;
|
|
49
|
+
(function (CoseAlgorithm) {
|
|
50
|
+
/** EdDSA (Ed25519 or Ed448) */
|
|
51
|
+
CoseAlgorithm[CoseAlgorithm["EdDSA"] = -8] = "EdDSA";
|
|
52
|
+
/** ECDSA with SHA-256 (P-256) */
|
|
53
|
+
CoseAlgorithm[CoseAlgorithm["ES256"] = -7] = "ES256";
|
|
54
|
+
/** ECDSA with SHA-384 (P-384) */
|
|
55
|
+
CoseAlgorithm[CoseAlgorithm["ES384"] = -35] = "ES384";
|
|
56
|
+
/** ECDSA with SHA-512 (P-521) */
|
|
57
|
+
CoseAlgorithm[CoseAlgorithm["ES512"] = -36] = "ES512";
|
|
58
|
+
/** ECDSA with SHA-256 (secp256k1) */
|
|
59
|
+
CoseAlgorithm[CoseAlgorithm["ES256K"] = -47] = "ES256K";
|
|
60
|
+
})(CoseAlgorithm || (CoseAlgorithm = {}));
|
|
61
|
+
/**
|
|
62
|
+
* COSE Key common parameter labels (RFC 9052, Section 7.1).
|
|
63
|
+
*/
|
|
64
|
+
var CoseKeyLabel;
|
|
65
|
+
(function (CoseKeyLabel) {
|
|
66
|
+
/** Key Type (kty) */
|
|
67
|
+
CoseKeyLabel[CoseKeyLabel["Kty"] = 1] = "Kty";
|
|
68
|
+
/** Key ID (kid) */
|
|
69
|
+
CoseKeyLabel[CoseKeyLabel["Kid"] = 2] = "Kid";
|
|
70
|
+
/** Algorithm */
|
|
71
|
+
CoseKeyLabel[CoseKeyLabel["Alg"] = 3] = "Alg";
|
|
72
|
+
/** Key Operations */
|
|
73
|
+
CoseKeyLabel[CoseKeyLabel["KeyOps"] = 4] = "KeyOps";
|
|
74
|
+
/** Base IV */
|
|
75
|
+
CoseKeyLabel[CoseKeyLabel["BaseIv"] = 5] = "BaseIv";
|
|
76
|
+
})(CoseKeyLabel || (CoseKeyLabel = {}));
|
|
77
|
+
/**
|
|
78
|
+
* COSE Key type-specific parameter labels.
|
|
79
|
+
*
|
|
80
|
+
* For OKP and EC2 keys, the curve and coordinate labels share the same
|
|
81
|
+
* negative-integer label space (RFC 9053, Section 7.1-7.2).
|
|
82
|
+
*/
|
|
83
|
+
var CoseKeyParamLabel;
|
|
84
|
+
(function (CoseKeyParamLabel) {
|
|
85
|
+
/** Curve identifier (OKP and EC2) */
|
|
86
|
+
CoseKeyParamLabel[CoseKeyParamLabel["Crv"] = -1] = "Crv";
|
|
87
|
+
/** X coordinate (OKP public key or EC2 x-coordinate) */
|
|
88
|
+
CoseKeyParamLabel[CoseKeyParamLabel["X"] = -2] = "X";
|
|
89
|
+
/** Y coordinate (EC2 only) */
|
|
90
|
+
CoseKeyParamLabel[CoseKeyParamLabel["Y"] = -3] = "Y";
|
|
91
|
+
/** Private key (OKP d value or EC2 d value) */
|
|
92
|
+
CoseKeyParamLabel[CoseKeyParamLabel["D"] = -4] = "D";
|
|
93
|
+
})(CoseKeyParamLabel || (CoseKeyParamLabel = {}));
|
|
94
|
+
/**
|
|
95
|
+
* Maps JWK curve names to COSE elliptic curve identifiers.
|
|
96
|
+
*/
|
|
97
|
+
const jwkCrvToCose = {
|
|
98
|
+
'P-256': CoseEllipticCurve.P256,
|
|
99
|
+
'P-384': CoseEllipticCurve.P384,
|
|
100
|
+
'P-521': CoseEllipticCurve.P521,
|
|
101
|
+
'X25519': CoseEllipticCurve.X25519,
|
|
102
|
+
'Ed25519': CoseEllipticCurve.Ed25519,
|
|
103
|
+
'Ed448': CoseEllipticCurve.Ed448,
|
|
104
|
+
'secp256k1': CoseEllipticCurve.Secp256k1,
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* Maps COSE elliptic curve identifiers to JWK curve names.
|
|
108
|
+
*/
|
|
109
|
+
const coseCrvToJwk = {
|
|
110
|
+
[CoseEllipticCurve.P256]: 'P-256',
|
|
111
|
+
[CoseEllipticCurve.P384]: 'P-384',
|
|
112
|
+
[CoseEllipticCurve.P521]: 'P-521',
|
|
113
|
+
[CoseEllipticCurve.X25519]: 'X25519',
|
|
114
|
+
[CoseEllipticCurve.Ed25519]: 'Ed25519',
|
|
115
|
+
[CoseEllipticCurve.Ed448]: 'Ed448',
|
|
116
|
+
[CoseEllipticCurve.Secp256k1]: 'secp256k1',
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* Maps JWK algorithm names to COSE algorithm identifiers.
|
|
120
|
+
*/
|
|
121
|
+
const jwkAlgToCose = {
|
|
122
|
+
'EdDSA': CoseAlgorithm.EdDSA,
|
|
123
|
+
'ES256': CoseAlgorithm.ES256,
|
|
124
|
+
'ES384': CoseAlgorithm.ES384,
|
|
125
|
+
'ES512': CoseAlgorithm.ES512,
|
|
126
|
+
'ES256K': CoseAlgorithm.ES256K,
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* Maps COSE algorithm identifiers to JWK algorithm names.
|
|
130
|
+
*/
|
|
131
|
+
const coseAlgToJwk = {
|
|
132
|
+
[CoseAlgorithm.EdDSA]: 'EdDSA',
|
|
133
|
+
[CoseAlgorithm.ES256]: 'ES256',
|
|
134
|
+
[CoseAlgorithm.ES384]: 'ES384',
|
|
135
|
+
[CoseAlgorithm.ES512]: 'ES512',
|
|
136
|
+
[CoseAlgorithm.ES256K]: 'ES256K',
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* Utilities for converting between JWK and COSE key representations.
|
|
140
|
+
*
|
|
141
|
+
* COSE keys use integer labels and CBOR encoding, while JWK uses string
|
|
142
|
+
* property names and JSON. This class provides bidirectional conversion.
|
|
143
|
+
*
|
|
144
|
+
* @see {@link https://www.rfc-editor.org/rfc/rfc9052#section-7 | RFC 9052, Section 7}
|
|
145
|
+
*/
|
|
146
|
+
export class CoseKey {
|
|
147
|
+
/**
|
|
148
|
+
* Converts a JWK to a COSE key represented as a Map.
|
|
149
|
+
*
|
|
150
|
+
* @param jwk - The JWK to convert.
|
|
151
|
+
* @returns A Map with integer labels as keys, suitable for CBOR encoding.
|
|
152
|
+
* @throws {CryptoError} If the JWK key type or curve is not supported.
|
|
153
|
+
*/
|
|
154
|
+
static fromJwk(jwk) {
|
|
155
|
+
const coseKey = new Map();
|
|
156
|
+
if (jwk.kty === 'OKP') {
|
|
157
|
+
coseKey.set(CoseKeyLabel.Kty, CoseKeyType.OKP);
|
|
158
|
+
const crv = jwk.crv;
|
|
159
|
+
if (crv === undefined || !(crv in jwkCrvToCose)) {
|
|
160
|
+
throw new CryptoError(CryptoErrorCode.AlgorithmNotSupported, `CoseKey: unsupported OKP curve '${crv}'`);
|
|
161
|
+
}
|
|
162
|
+
coseKey.set(CoseKeyParamLabel.Crv, jwkCrvToCose[crv]);
|
|
163
|
+
if (jwk.x !== undefined) {
|
|
164
|
+
coseKey.set(CoseKeyParamLabel.X, Convert.base64Url(jwk.x).toUint8Array());
|
|
165
|
+
}
|
|
166
|
+
if (jwk.d !== undefined) {
|
|
167
|
+
coseKey.set(CoseKeyParamLabel.D, Convert.base64Url(jwk.d).toUint8Array());
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
else if (jwk.kty === 'EC') {
|
|
171
|
+
coseKey.set(CoseKeyLabel.Kty, CoseKeyType.EC2);
|
|
172
|
+
const crv = jwk.crv;
|
|
173
|
+
if (crv === undefined || !(crv in jwkCrvToCose)) {
|
|
174
|
+
throw new CryptoError(CryptoErrorCode.AlgorithmNotSupported, `CoseKey: unsupported EC curve '${crv}'`);
|
|
175
|
+
}
|
|
176
|
+
coseKey.set(CoseKeyParamLabel.Crv, jwkCrvToCose[crv]);
|
|
177
|
+
if (jwk.x !== undefined) {
|
|
178
|
+
coseKey.set(CoseKeyParamLabel.X, Convert.base64Url(jwk.x).toUint8Array());
|
|
179
|
+
}
|
|
180
|
+
if (jwk.y !== undefined) {
|
|
181
|
+
coseKey.set(CoseKeyParamLabel.Y, Convert.base64Url(jwk.y).toUint8Array());
|
|
182
|
+
}
|
|
183
|
+
if (jwk.d !== undefined) {
|
|
184
|
+
coseKey.set(CoseKeyParamLabel.D, Convert.base64Url(jwk.d).toUint8Array());
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
throw new CryptoError(CryptoErrorCode.AlgorithmNotSupported, `CoseKey: unsupported key type '${jwk.kty}'`);
|
|
189
|
+
}
|
|
190
|
+
if (jwk.kid !== undefined) {
|
|
191
|
+
coseKey.set(CoseKeyLabel.Kid, Convert.string(jwk.kid).toUint8Array());
|
|
192
|
+
}
|
|
193
|
+
if (jwk.alg !== undefined && jwk.alg in jwkAlgToCose) {
|
|
194
|
+
coseKey.set(CoseKeyLabel.Alg, jwkAlgToCose[jwk.alg]);
|
|
195
|
+
}
|
|
196
|
+
return coseKey;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Converts a COSE key Map to a JWK.
|
|
200
|
+
*
|
|
201
|
+
* @param coseKey - A Map with integer labels as keys (from CBOR decoding).
|
|
202
|
+
* @returns The equivalent JWK.
|
|
203
|
+
* @throws {CryptoError} If the COSE key type or curve is not supported.
|
|
204
|
+
*/
|
|
205
|
+
static toJwk(coseKey) {
|
|
206
|
+
const kty = coseKey.get(CoseKeyLabel.Kty);
|
|
207
|
+
if (kty === CoseKeyType.OKP) {
|
|
208
|
+
const crv = coseKey.get(CoseKeyParamLabel.Crv);
|
|
209
|
+
if (!(crv in coseCrvToJwk)) {
|
|
210
|
+
throw new CryptoError(CryptoErrorCode.AlgorithmNotSupported, `CoseKey: unsupported COSE OKP curve ${crv}`);
|
|
211
|
+
}
|
|
212
|
+
const jwk = {
|
|
213
|
+
kty: 'OKP',
|
|
214
|
+
crv: coseCrvToJwk[crv],
|
|
215
|
+
};
|
|
216
|
+
const x = coseKey.get(CoseKeyParamLabel.X);
|
|
217
|
+
if (x !== undefined) {
|
|
218
|
+
jwk.x = Convert.uint8Array(x).toBase64Url();
|
|
219
|
+
}
|
|
220
|
+
const d = coseKey.get(CoseKeyParamLabel.D);
|
|
221
|
+
if (d !== undefined) {
|
|
222
|
+
jwk.d = Convert.uint8Array(d).toBase64Url();
|
|
223
|
+
}
|
|
224
|
+
CoseKey.applyCommonFields(coseKey, jwk);
|
|
225
|
+
return jwk;
|
|
226
|
+
}
|
|
227
|
+
else if (kty === CoseKeyType.EC2) {
|
|
228
|
+
const crv = coseKey.get(CoseKeyParamLabel.Crv);
|
|
229
|
+
if (!(crv in coseCrvToJwk)) {
|
|
230
|
+
throw new CryptoError(CryptoErrorCode.AlgorithmNotSupported, `CoseKey: unsupported COSE EC2 curve ${crv}`);
|
|
231
|
+
}
|
|
232
|
+
const jwk = {
|
|
233
|
+
kty: 'EC',
|
|
234
|
+
crv: coseCrvToJwk[crv],
|
|
235
|
+
};
|
|
236
|
+
const x = coseKey.get(CoseKeyParamLabel.X);
|
|
237
|
+
if (x !== undefined) {
|
|
238
|
+
jwk.x = Convert.uint8Array(x).toBase64Url();
|
|
239
|
+
}
|
|
240
|
+
const y = coseKey.get(CoseKeyParamLabel.Y);
|
|
241
|
+
if (y !== undefined) {
|
|
242
|
+
jwk.y = Convert.uint8Array(y).toBase64Url();
|
|
243
|
+
}
|
|
244
|
+
const d = coseKey.get(CoseKeyParamLabel.D);
|
|
245
|
+
if (d !== undefined) {
|
|
246
|
+
jwk.d = Convert.uint8Array(d).toBase64Url();
|
|
247
|
+
}
|
|
248
|
+
CoseKey.applyCommonFields(coseKey, jwk);
|
|
249
|
+
return jwk;
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
throw new CryptoError(CryptoErrorCode.AlgorithmNotSupported, `CoseKey: unsupported COSE key type ${kty}`);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Infers the COSE algorithm identifier from a JWK.
|
|
257
|
+
*
|
|
258
|
+
* If the JWK has an `alg` field, it is used directly. Otherwise, the algorithm
|
|
259
|
+
* is inferred from the key type and curve.
|
|
260
|
+
*
|
|
261
|
+
* @param jwk - The JWK to infer the algorithm from.
|
|
262
|
+
* @returns The COSE algorithm identifier.
|
|
263
|
+
* @throws {CryptoError} If the algorithm cannot be determined.
|
|
264
|
+
*/
|
|
265
|
+
static algorithmFromJwk(jwk) {
|
|
266
|
+
if (jwk.alg !== undefined && jwk.alg in jwkAlgToCose) {
|
|
267
|
+
return jwkAlgToCose[jwk.alg];
|
|
268
|
+
}
|
|
269
|
+
// Infer from key type and curve.
|
|
270
|
+
if (jwk.kty === 'OKP') {
|
|
271
|
+
if (jwk.crv === 'Ed25519' || jwk.crv === 'Ed448') {
|
|
272
|
+
return CoseAlgorithm.EdDSA;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
else if (jwk.kty === 'EC') {
|
|
276
|
+
switch (jwk.crv) {
|
|
277
|
+
case 'P-256': return CoseAlgorithm.ES256;
|
|
278
|
+
case 'P-384': return CoseAlgorithm.ES384;
|
|
279
|
+
case 'P-521': return CoseAlgorithm.ES512;
|
|
280
|
+
case 'secp256k1': return CoseAlgorithm.ES256K;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
throw new CryptoError(CryptoErrorCode.AlgorithmNotSupported, `CoseKey: cannot determine COSE algorithm for key type '${jwk.kty}' curve '${jwk.crv}'`);
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Maps a COSE algorithm identifier to a JWK algorithm name.
|
|
287
|
+
*
|
|
288
|
+
* @param alg - The COSE algorithm identifier.
|
|
289
|
+
* @returns The JWK algorithm name.
|
|
290
|
+
* @throws {CryptoError} If the algorithm is not supported.
|
|
291
|
+
*/
|
|
292
|
+
static algorithmToJwk(alg) {
|
|
293
|
+
if (alg in coseAlgToJwk) {
|
|
294
|
+
return coseAlgToJwk[alg];
|
|
295
|
+
}
|
|
296
|
+
throw new CryptoError(CryptoErrorCode.AlgorithmNotSupported, `CoseKey: unsupported COSE algorithm ${alg}`);
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Applies common COSE key fields (kid, alg) to a JWK.
|
|
300
|
+
*/
|
|
301
|
+
static applyCommonFields(coseKey, jwk) {
|
|
302
|
+
const kid = coseKey.get(CoseKeyLabel.Kid);
|
|
303
|
+
if (kid !== undefined) {
|
|
304
|
+
jwk.kid = Convert.uint8Array(kid).toString();
|
|
305
|
+
}
|
|
306
|
+
const alg = coseKey.get(CoseKeyLabel.Alg);
|
|
307
|
+
if (alg !== undefined && alg in coseAlgToJwk) {
|
|
308
|
+
jwk.alg = coseAlgToJwk[alg];
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
//# sourceMappingURL=cose-key.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cose-key.js","sourceRoot":"","sources":["../../../src/cose/cose-key.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAElE;;;;GAIG;AACH,MA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C,cAAc,CAAC,GAAkB;QAC7C,IAAI,GAAG,IAAI,YAAY,EAAE,CAAC;YACxB,OAAO,YAAY,CAAC,GAAG,CAAC,CAAC;QAC3B,CAAC;QACD,MAAM,IAAI,WAAW,CAAC,eAAe,CAAC,qBAAqB,EAAE,uCAAuC,GAAG,EAAE,CAAC,CAAC;IAC7G,CAAC;IAED;;OAEG;IACK,MAAM,CAAC,iBAAiB,CAAC,OAA6B,EAAE,GAAQ;QACtE,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAA2B,CAAC;QACpE,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;YACtB,GAAG,CAAC,GAAG,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC;QAC/C,CAAC;QAED,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAuB,CAAC;QAChE,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,IAAI,YAAY,EAAE,CAAC;YAC7C,GAAG,CAAC,GAAG,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,283 @@
|
|
|
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 { Ed25519 } from '../primitives/ed25519.js';
|
|
12
|
+
import { Secp256r1 } from '../primitives/secp256r1.js';
|
|
13
|
+
import { CoseAlgorithm, CoseKey } from './cose-key.js';
|
|
14
|
+
import { CryptoError, CryptoErrorCode } from '../crypto-error.js';
|
|
15
|
+
/**
|
|
16
|
+
* COSE header label constants (RFC 9052, Section 3.1).
|
|
17
|
+
*/
|
|
18
|
+
var CoseHeaderLabel;
|
|
19
|
+
(function (CoseHeaderLabel) {
|
|
20
|
+
/** Algorithm identifier */
|
|
21
|
+
CoseHeaderLabel[CoseHeaderLabel["Alg"] = 1] = "Alg";
|
|
22
|
+
/** Critical headers */
|
|
23
|
+
CoseHeaderLabel[CoseHeaderLabel["Crit"] = 2] = "Crit";
|
|
24
|
+
/** Content type */
|
|
25
|
+
CoseHeaderLabel[CoseHeaderLabel["ContentType"] = 3] = "ContentType";
|
|
26
|
+
/** Key ID */
|
|
27
|
+
CoseHeaderLabel[CoseHeaderLabel["Kid"] = 4] = "Kid";
|
|
28
|
+
})(CoseHeaderLabel || (CoseHeaderLabel = {}));
|
|
29
|
+
/**
|
|
30
|
+
* CBOR tag for COSE_Sign1 (RFC 9052, Section 4.2).
|
|
31
|
+
*/
|
|
32
|
+
// const COSE_SIGN1_TAG = 18;
|
|
33
|
+
/**
|
|
34
|
+
* COSE_Sign1 implementation per RFC 9052.
|
|
35
|
+
*
|
|
36
|
+
* Provides creation, verification, and decoding of COSE_Sign1 (single-signer)
|
|
37
|
+
* signed messages. This is the CBOR-based counterpart to JOSE/JWS and is used
|
|
38
|
+
* in TEE attestation (EAT tokens), CWT, and other COSE-based protocols.
|
|
39
|
+
*
|
|
40
|
+
* Supported algorithms:
|
|
41
|
+
* - EdDSA (Ed25519) — CoseAlgorithm.EdDSA (-8)
|
|
42
|
+
* - ES256 (P-256 / secp256r1 with SHA-256) — CoseAlgorithm.ES256 (-7)
|
|
43
|
+
*
|
|
44
|
+
* @see {@link https://www.rfc-editor.org/rfc/rfc9052#section-4.3 | RFC 9052, Section 4.3}
|
|
45
|
+
*/
|
|
46
|
+
export class CoseSign1 {
|
|
47
|
+
/**
|
|
48
|
+
* Creates a COSE_Sign1 message.
|
|
49
|
+
*
|
|
50
|
+
* Constructs the `Sig_structure1` to-be-signed bytes per RFC 9052 Section 4.4,
|
|
51
|
+
* signs them with the provided key, and returns the CBOR-encoded COSE_Sign1 array:
|
|
52
|
+
*
|
|
53
|
+
* ```
|
|
54
|
+
* COSE_Sign1 = [
|
|
55
|
+
* protected : bstr, ; CBOR-encoded protected header
|
|
56
|
+
* unprotected : map, ; unprotected header parameters
|
|
57
|
+
* payload : bstr / nil, ; payload (nil if detached)
|
|
58
|
+
* signature : bstr ; signature
|
|
59
|
+
* ]
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* @param params - The parameters for creating the COSE_Sign1 message.
|
|
63
|
+
* @returns The CBOR-encoded COSE_Sign1 message.
|
|
64
|
+
* @throws {CryptoError} If the algorithm is not supported or signing fails.
|
|
65
|
+
*
|
|
66
|
+
* @see {@link https://www.rfc-editor.org/rfc/rfc9052#section-4.3 | RFC 9052, Section 4.3}
|
|
67
|
+
* @see {@link https://www.rfc-editor.org/rfc/rfc9052#section-4.4 | RFC 9052, Section 4.4}
|
|
68
|
+
*/
|
|
69
|
+
static create(params) {
|
|
70
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
var _a, _b, _c;
|
|
72
|
+
const { key, payload, externalAad = new Uint8Array(0), detachedPayload = false, } = params;
|
|
73
|
+
// Build the protected header.
|
|
74
|
+
const alg = (_b = (_a = params.protectedHeader) === null || _a === void 0 ? void 0 : _a.alg) !== null && _b !== void 0 ? _b : CoseKey.algorithmFromJwk(key);
|
|
75
|
+
const protectedHeaderMap = CoseSign1.buildProtectedHeaderMap((_c = params.protectedHeader) !== null && _c !== void 0 ? _c : { alg });
|
|
76
|
+
const protectedHeaderBytes = Cbor.encode(protectedHeaderMap);
|
|
77
|
+
// Build the unprotected header.
|
|
78
|
+
const unprotectedHeaderMap = params.unprotectedHeader !== undefined
|
|
79
|
+
? CoseSign1.buildUnprotectedHeaderMap(params.unprotectedHeader)
|
|
80
|
+
: new Map();
|
|
81
|
+
// Construct the Sig_structure1 (to-be-signed bytes).
|
|
82
|
+
const sigStructure = CoseSign1.buildSigStructure1(protectedHeaderBytes, externalAad, payload);
|
|
83
|
+
const toBeSigned = Cbor.encode(sigStructure);
|
|
84
|
+
// Sign the Sig_structure1 bytes.
|
|
85
|
+
const signature = yield CoseSign1.signBytes(alg, key, toBeSigned);
|
|
86
|
+
// Assemble the COSE_Sign1 array.
|
|
87
|
+
const coseSign1Array = [
|
|
88
|
+
protectedHeaderBytes,
|
|
89
|
+
unprotectedHeaderMap,
|
|
90
|
+
detachedPayload ? null : payload,
|
|
91
|
+
signature,
|
|
92
|
+
];
|
|
93
|
+
return Cbor.encode(coseSign1Array);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Verifies a COSE_Sign1 message.
|
|
98
|
+
*
|
|
99
|
+
* Decodes the CBOR-encoded message, reconstructs the `Sig_structure1`, and verifies
|
|
100
|
+
* the signature using the provided public key.
|
|
101
|
+
*
|
|
102
|
+
* @param params - The parameters for verifying the COSE_Sign1 message.
|
|
103
|
+
* @returns `true` if the signature is valid, `false` otherwise.
|
|
104
|
+
* @throws {CryptoError} If the message is malformed or the algorithm is not supported.
|
|
105
|
+
*
|
|
106
|
+
* @see {@link https://www.rfc-editor.org/rfc/rfc9052#section-4.4 | RFC 9052, Section 4.4}
|
|
107
|
+
*/
|
|
108
|
+
static verify(params) {
|
|
109
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
110
|
+
var _a, _b;
|
|
111
|
+
const { coseSign1, key, externalAad = new Uint8Array(0), } = params;
|
|
112
|
+
// Decode the COSE_Sign1 message.
|
|
113
|
+
const decoded = CoseSign1.decode(coseSign1);
|
|
114
|
+
// Resolve the payload (from message or detached parameter).
|
|
115
|
+
const payload = (_b = (_a = decoded.payload) !== null && _a !== void 0 ? _a : params.payload) !== null && _b !== void 0 ? _b : null;
|
|
116
|
+
if (payload === null) {
|
|
117
|
+
throw new CryptoError(CryptoErrorCode.InvalidCoseSign1, 'CoseSign1: payload is detached but no payload was provided for verification');
|
|
118
|
+
}
|
|
119
|
+
// Reconstruct the Sig_structure1.
|
|
120
|
+
const sigStructure = CoseSign1.buildSigStructure1(decoded.protectedHeaderBytes, externalAad, payload);
|
|
121
|
+
const toBeSigned = Cbor.encode(sigStructure);
|
|
122
|
+
// Extract the algorithm from the protected header.
|
|
123
|
+
const alg = decoded.protectedHeader.alg;
|
|
124
|
+
// Verify the signature.
|
|
125
|
+
return CoseSign1.verifyBytes(alg, key, toBeSigned, decoded.signature);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Decodes a CBOR-encoded COSE_Sign1 message into its constituent parts.
|
|
130
|
+
*
|
|
131
|
+
* The COSE_Sign1 structure is a CBOR array of four elements:
|
|
132
|
+
* ```
|
|
133
|
+
* [protected, unprotected, payload, signature]
|
|
134
|
+
* ```
|
|
135
|
+
*
|
|
136
|
+
* The message may optionally be wrapped in CBOR tag 18.
|
|
137
|
+
*
|
|
138
|
+
* @param coseSign1 - The CBOR-encoded COSE_Sign1 message.
|
|
139
|
+
* @returns The decoded COSE_Sign1 components.
|
|
140
|
+
* @throws {CryptoError} If the message does not conform to COSE_Sign1 structure.
|
|
141
|
+
*/
|
|
142
|
+
static decode(coseSign1) {
|
|
143
|
+
let decoded;
|
|
144
|
+
try {
|
|
145
|
+
decoded = Cbor.decode(coseSign1);
|
|
146
|
+
}
|
|
147
|
+
catch (_a) {
|
|
148
|
+
throw new CryptoError(CryptoErrorCode.InvalidCoseSign1, 'CoseSign1: failed to decode CBOR');
|
|
149
|
+
}
|
|
150
|
+
// Handle CBOR Tagged value (tag 18 for COSE_Sign1).
|
|
151
|
+
// The `cborg` library decodes tagged values as `Tagged` objects with `tag` and `value` properties.
|
|
152
|
+
if (decoded !== null && typeof decoded === 'object' && 'tag' in decoded) {
|
|
153
|
+
const tagged = decoded;
|
|
154
|
+
if (tagged.tag === 18) {
|
|
155
|
+
decoded = tagged.value;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
// Validate the COSE_Sign1 array structure.
|
|
159
|
+
if (!Array.isArray(decoded) || decoded.length !== 4) {
|
|
160
|
+
throw new CryptoError(CryptoErrorCode.InvalidCoseSign1, 'CoseSign1: expected a CBOR array of 4 elements [protected, unprotected, payload, signature]');
|
|
161
|
+
}
|
|
162
|
+
const [protectedHeaderBytes, unprotectedHeaderMap, payload, signature] = decoded;
|
|
163
|
+
// Validate element types.
|
|
164
|
+
if (!(protectedHeaderBytes instanceof Uint8Array)) {
|
|
165
|
+
throw new CryptoError(CryptoErrorCode.InvalidCoseSign1, 'CoseSign1: protected header must be a byte string');
|
|
166
|
+
}
|
|
167
|
+
if (!(signature instanceof Uint8Array)) {
|
|
168
|
+
throw new CryptoError(CryptoErrorCode.InvalidCoseSign1, 'CoseSign1: signature must be a byte string');
|
|
169
|
+
}
|
|
170
|
+
// Decode the protected header.
|
|
171
|
+
let protectedHeaderMap;
|
|
172
|
+
if (protectedHeaderBytes.length === 0) {
|
|
173
|
+
protectedHeaderMap = new Map();
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
try {
|
|
177
|
+
protectedHeaderMap = Cbor.decode(protectedHeaderBytes);
|
|
178
|
+
}
|
|
179
|
+
catch (_b) {
|
|
180
|
+
throw new CryptoError(CryptoErrorCode.InvalidCoseSign1, 'CoseSign1: failed to decode protected header CBOR');
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
// Extract the algorithm from the protected header.
|
|
184
|
+
const alg = protectedHeaderMap.get(CoseHeaderLabel.Alg);
|
|
185
|
+
if (alg === undefined || typeof alg !== 'number') {
|
|
186
|
+
throw new CryptoError(CryptoErrorCode.InvalidCoseSign1, 'CoseSign1: protected header must contain an algorithm identifier (label 1)');
|
|
187
|
+
}
|
|
188
|
+
// Build the typed protected header.
|
|
189
|
+
const protectedHeader = { alg: alg };
|
|
190
|
+
const contentType = protectedHeaderMap.get(CoseHeaderLabel.ContentType);
|
|
191
|
+
if (contentType !== undefined) {
|
|
192
|
+
protectedHeader.contentType = contentType;
|
|
193
|
+
}
|
|
194
|
+
const kid = protectedHeaderMap.get(CoseHeaderLabel.Kid);
|
|
195
|
+
if (kid !== undefined) {
|
|
196
|
+
protectedHeader.kid = kid;
|
|
197
|
+
}
|
|
198
|
+
return {
|
|
199
|
+
protectedHeader,
|
|
200
|
+
protectedHeaderBytes,
|
|
201
|
+
unprotectedHeader: unprotectedHeaderMap instanceof Map ? unprotectedHeaderMap : new Map(),
|
|
202
|
+
payload: payload instanceof Uint8Array ? payload : null,
|
|
203
|
+
signature,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Builds the Sig_structure1 array for COSE_Sign1 signing and verification.
|
|
208
|
+
*
|
|
209
|
+
* ```
|
|
210
|
+
* Sig_structure1 = [
|
|
211
|
+
* context : "Signature1",
|
|
212
|
+
* body_protected : bstr,
|
|
213
|
+
* external_aad : bstr,
|
|
214
|
+
* payload : bstr
|
|
215
|
+
* ]
|
|
216
|
+
* ```
|
|
217
|
+
*
|
|
218
|
+
* @see {@link https://www.rfc-editor.org/rfc/rfc9052#section-4.4 | RFC 9052, Section 4.4}
|
|
219
|
+
*/
|
|
220
|
+
static buildSigStructure1(protectedHeaderBytes, externalAad, payload) {
|
|
221
|
+
return [
|
|
222
|
+
'Signature1', // context string
|
|
223
|
+
protectedHeaderBytes, // body_protected
|
|
224
|
+
externalAad, // external_aad
|
|
225
|
+
payload, // payload
|
|
226
|
+
];
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Converts a {@link CoseSign1ProtectedHeader} to a CBOR Map with integer labels.
|
|
230
|
+
*/
|
|
231
|
+
static buildProtectedHeaderMap(header) {
|
|
232
|
+
const map = new Map();
|
|
233
|
+
map.set(CoseHeaderLabel.Alg, header.alg);
|
|
234
|
+
if (header.contentType !== undefined) {
|
|
235
|
+
map.set(CoseHeaderLabel.ContentType, header.contentType);
|
|
236
|
+
}
|
|
237
|
+
if (header.kid !== undefined) {
|
|
238
|
+
map.set(CoseHeaderLabel.Kid, header.kid);
|
|
239
|
+
}
|
|
240
|
+
return map;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Converts a {@link CoseSign1UnprotectedHeader} to a CBOR Map with integer labels.
|
|
244
|
+
*/
|
|
245
|
+
static buildUnprotectedHeaderMap(header) {
|
|
246
|
+
const map = new Map();
|
|
247
|
+
if (header.kid !== undefined) {
|
|
248
|
+
map.set(CoseHeaderLabel.Kid, header.kid);
|
|
249
|
+
}
|
|
250
|
+
return map;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Signs the to-be-signed bytes with the appropriate algorithm.
|
|
254
|
+
*/
|
|
255
|
+
static signBytes(alg, key, data) {
|
|
256
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
257
|
+
switch (alg) {
|
|
258
|
+
case CoseAlgorithm.EdDSA:
|
|
259
|
+
return Ed25519.sign({ key, data });
|
|
260
|
+
case CoseAlgorithm.ES256:
|
|
261
|
+
return Secp256r1.sign({ key, data });
|
|
262
|
+
default:
|
|
263
|
+
throw new CryptoError(CryptoErrorCode.AlgorithmNotSupported, `CoseSign1: signing algorithm ${alg} is not supported`);
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Verifies a signature over the to-be-signed bytes with the appropriate algorithm.
|
|
269
|
+
*/
|
|
270
|
+
static verifyBytes(alg, key, data, signature) {
|
|
271
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
272
|
+
switch (alg) {
|
|
273
|
+
case CoseAlgorithm.EdDSA:
|
|
274
|
+
return Ed25519.verify({ key, signature, data });
|
|
275
|
+
case CoseAlgorithm.ES256:
|
|
276
|
+
return Secp256r1.verify({ key, signature, data });
|
|
277
|
+
default:
|
|
278
|
+
throw new CryptoError(CryptoErrorCode.AlgorithmNotSupported, `CoseSign1: verification algorithm ${alg} is not supported`);
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
//# sourceMappingURL=cose-sign1.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cose-sign1.js","sourceRoot":"","sources":["../../../src/cose/cose-sign1.ts"],"names":[],"mappings":";;;;;;;;;AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAmHlE;;GAEG;AACH,IAAK,eASJ;AATD,WAAK,eAAe;IAClB,2BAA2B;IAC3B,mDAAO,CAAA;IACP,uBAAuB;IACvB,qDAAQ,CAAA;IACR,mBAAmB;IACnB,mEAAe,CAAA;IACf,aAAa;IACb,mDAAO,CAAA;AACT,CAAC,EATI,eAAe,KAAf,eAAe,QASnB;AAED;;GAEG;AACH,6BAA6B;AAE7B;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,SAAS;IACpB;;;;;;;;;;;;;;;;;;;;;OAqBG;IACI,MAAM,CAAO,MAAM,CAAC,MAA6B;;;YACtD,MAAM,EACJ,GAAG,EACH,OAAO,EACP,WAAW,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,EAC/B,eAAe,GAAG,KAAK,GACxB,GAAG,MAAM,CAAC;YAEX,8BAA8B;YAC9B,MAAM,GAAG,GAAG,MAAA,MAAA,MAAM,CAAC,eAAe,0CAAE,GAAG,mCAAI,OAAO,CAAC,gBAAgB,CAAC,GAAG,CA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