@enbox/crypto 0.0.3 → 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/algorithms/aes-ctr.js +1 -1
- package/dist/esm/algorithms/aes-gcm.js +34 -1
- package/dist/esm/algorithms/aes-gcm.js.map +1 -1
- package/dist/esm/algorithms/aes-kw.js +154 -0
- package/dist/esm/algorithms/aes-kw.js.map +1 -0
- package/dist/esm/algorithms/ecdsa.js +110 -1
- package/dist/esm/algorithms/ecdsa.js.map +1 -1
- package/dist/esm/algorithms/eddsa.js +90 -1
- package/dist/esm/algorithms/eddsa.js.map +1 -1
- package/dist/esm/algorithms/hkdf.js +53 -0
- package/dist/esm/algorithms/hkdf.js.map +1 -0
- package/dist/esm/algorithms/pbkdf2.js +55 -0
- package/dist/esm/algorithms/pbkdf2.js.map +1 -0
- package/dist/esm/algorithms/sha-2.js +1 -1
- package/dist/esm/algorithms/x25519.js +125 -0
- package/dist/esm/algorithms/x25519.js.map +1 -0
- 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 +9 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/local-key-manager.js +6 -1
- package/dist/esm/local-key-manager.js.map +1 -1
- package/dist/esm/primitives/ecies-secp256k1.js +79 -0
- package/dist/esm/primitives/ecies-secp256k1.js.map +1 -0
- package/dist/esm/primitives/x25519.js +9 -16
- package/dist/esm/primitives/x25519.js.map +1 -1
- package/dist/esm/utils.js +30 -0
- package/dist/esm/utils.js.map +1 -1
- package/dist/types/algorithms/aes-ctr.d.ts +1 -1
- package/dist/types/algorithms/aes-gcm.d.ts +23 -3
- package/dist/types/algorithms/aes-gcm.d.ts.map +1 -1
- package/dist/types/algorithms/aes-kw.d.ts +129 -0
- package/dist/types/algorithms/aes-kw.d.ts.map +1 -0
- package/dist/types/algorithms/ecdsa.d.ts +48 -3
- package/dist/types/algorithms/ecdsa.d.ts.map +1 -1
- package/dist/types/algorithms/eddsa.d.ts +48 -3
- package/dist/types/algorithms/eddsa.d.ts.map +1 -1
- package/dist/types/algorithms/hkdf.d.ts +35 -0
- package/dist/types/algorithms/hkdf.d.ts.map +1 -0
- package/dist/types/algorithms/pbkdf2.d.ts +35 -0
- package/dist/types/algorithms/pbkdf2.d.ts.map +1 -0
- package/dist/types/algorithms/sha-2.d.ts +1 -1
- package/dist/types/algorithms/x25519.d.ts +76 -0
- package/dist/types/algorithms/x25519.d.ts.map +1 -0
- 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 +9 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/local-key-manager.d.ts +4 -4
- package/dist/types/local-key-manager.d.ts.map +1 -1
- package/dist/types/primitives/ecies-secp256k1.d.ts +53 -0
- package/dist/types/primitives/ecies-secp256k1.d.ts.map +1 -0
- package/dist/types/primitives/x25519.d.ts +9 -16
- package/dist/types/primitives/x25519.d.ts.map +1 -1
- package/dist/types/types/crypto-api.d.ts +52 -4
- package/dist/types/types/crypto-api.d.ts.map +1 -1
- package/dist/types/types/key-converter.d.ts +37 -15
- package/dist/types/types/key-converter.d.ts.map +1 -1
- package/dist/types/types/key-deriver.d.ts +41 -0
- package/dist/types/types/key-deriver.d.ts.map +1 -1
- package/dist/types/types/key-io.d.ts +37 -0
- package/dist/types/types/key-io.d.ts.map +1 -1
- package/dist/types/types/params-direct.d.ts +17 -0
- package/dist/types/types/params-direct.d.ts.map +1 -1
- package/dist/types/types/params-kms.d.ts +55 -0
- package/dist/types/types/params-kms.d.ts.map +1 -1
- package/dist/types/utils.d.ts +19 -0
- package/dist/types/utils.d.ts.map +1 -1
- package/dist/utils.js +1 -1
- package/dist/utils.js.map +3 -3
- package/package.json +12 -14
- package/src/algorithms/aes-ctr.ts +1 -1
- package/src/algorithms/aes-gcm.ts +38 -2
- package/src/algorithms/aes-kw.ts +182 -0
- package/src/algorithms/ecdsa.ts +132 -1
- package/src/algorithms/eddsa.ts +108 -1
- package/src/algorithms/hkdf.ts +54 -0
- package/src/algorithms/pbkdf2.ts +57 -0
- package/src/algorithms/sha-2.ts +1 -1
- package/src/algorithms/x25519.ts +153 -0
- 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 +10 -0
- package/src/local-key-manager.ts +9 -4
- package/src/primitives/ecies-secp256k1.ts +113 -0
- package/src/primitives/x25519.ts +9 -16
- package/src/types/crypto-api.ts +124 -6
- package/src/types/key-converter.ts +33 -7
- package/src/types/key-deriver.ts +49 -0
- package/src/types/key-io.ts +40 -0
- package/src/types/params-direct.ts +21 -0
- package/src/types/params-kms.ts +67 -0
- package/src/utils.ts +53 -0
- package/dist/browser.js +0 -60
- package/dist/browser.js.map +0 -7
|
@@ -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;;;;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,CAAC;QACH,CAAC;KAAA;IAED;;OAEG;IACK,MAAM,CAAO,WAAW,CAC9B,GAAkB,EAClB,GAAQ,EACR,IAAgB,EAChB,SAAqB;;YAErB,QAAQ,GAAG,EAAE,CAAC;gBACZ,KAAK,aAAa,CAAC,KAAK;oBACtB,OAAO,OAAO,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;gBAElD,KAAK,aAAa,CAAC,KAAK;oBACtB,OAAO,SAAS,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;gBAEpD;oBACE,MAAM,IAAI,WAAW,CACnB,eAAe,CAAC,qBAAqB,EACrC,qCAAqC,GAAG,mBAAmB,CAC5D,CAAC;YACN,CAAC;QACH,CAAC;KAAA;CACF"}
|
|
@@ -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,2CAAO,CAAA;IACP,kCAAkC;IAClC,2CAAO,CAAA;IACP,iCAAiC;IACjC,2CAAO,CAAA;IACP,8BAA8B;IAC9B,2CAAO,CAAA;IACP,gDAAgD;IAChD,gDAAU,CAAA;IACV,2DAA2D;IAC3D,+CAAU,CAAA;IACV,8DAA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ACnD,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"}
|
package/dist/esm/crypto-error.js
CHANGED
|
@@ -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;QAC9F,4FAA4F;QAC5F,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAElD,2EAA2E;QAC3E,kEAAkE;QAClE,IAAI,KAAK,CAAC,iBAAiB,EAAE,CAAC;YAC5B,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;QAC7C,CAAC;IACH,CAAC;CACF;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,
|
|
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;QAC9F,4FAA4F;QAC5F,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAElD,2EAA2E;QAC3E,kEAAkE;QAClE,IAAI,KAAK,CAAC,iBAAiB,EAAE,CAAC;YAC5B,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;QAC7C,CAAC;IACH,CAAC;CACF;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,eAqBX;AArBD,WAAY,eAAe;IACzB,gFAAgF;IAChF,kEAA+C,CAAA;IAE/C,mEAAmE;IACnE,kDAA+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,12 +1,20 @@
|
|
|
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';
|
|
10
|
+
export * from './algorithms/aes-kw.js';
|
|
6
11
|
export * from './algorithms/crypto-algorithm.js';
|
|
7
12
|
export * from './algorithms/ecdsa.js';
|
|
8
13
|
export * from './algorithms/eddsa.js';
|
|
14
|
+
export * from './algorithms/hkdf.js';
|
|
15
|
+
export * from './algorithms/pbkdf2.js';
|
|
9
16
|
export * from './algorithms/sha-2.js';
|
|
17
|
+
export * from './algorithms/x25519.js';
|
|
10
18
|
export * from './jose/jwe.js';
|
|
11
19
|
export * from './jose/jwk.js';
|
|
12
20
|
export * from './jose/jws.js';
|
|
@@ -16,6 +24,7 @@ export * from './primitives/aes-ctr.js';
|
|
|
16
24
|
export * from './primitives/aes-gcm.js';
|
|
17
25
|
export * from './primitives/aes-kw.js';
|
|
18
26
|
export * from './primitives/concat-kdf.js';
|
|
27
|
+
export * from './primitives/ecies-secp256k1.js';
|
|
19
28
|
export * from './primitives/ed25519.js';
|
|
20
29
|
export * from './primitives/hkdf.js';
|
|
21
30
|
export * from './primitives/secp256r1.js';
|
package/dist/esm/index.js.map
CHANGED
|
@@ -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,kCAAkC,CAAC;AACjD,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;
|
|
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,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAE9B,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,cAAc,sBAAsB,CAAC;AACrC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oCAAoC,CAAC"}
|
|
@@ -11,6 +11,7 @@ import { MemoryStore } from '@enbox/common';
|
|
|
11
11
|
import { EcdsaAlgorithm } from './algorithms/ecdsa.js';
|
|
12
12
|
import { EdDsaAlgorithm } from './algorithms/eddsa.js';
|
|
13
13
|
import { Sha2Algorithm } from './algorithms/sha-2.js';
|
|
14
|
+
import { X25519Algorithm } from './algorithms/x25519.js';
|
|
14
15
|
import { computeJwkThumbprint, isPrivateJwk, KEY_URI_PREFIX_JWK } from './jose/jwk.js';
|
|
15
16
|
/**
|
|
16
17
|
* `supportedAlgorithms` is an object mapping algorithm names to their respective implementations
|
|
@@ -36,6 +37,10 @@ const supportedAlgorithms = {
|
|
|
36
37
|
'SHA-256': {
|
|
37
38
|
implementation: Sha2Algorithm,
|
|
38
39
|
names: ['SHA-256']
|
|
40
|
+
},
|
|
41
|
+
'X25519': {
|
|
42
|
+
implementation: X25519Algorithm,
|
|
43
|
+
names: ['X25519']
|
|
39
44
|
}
|
|
40
45
|
};
|
|
41
46
|
export class LocalKeyManager {
|
|
@@ -148,7 +153,7 @@ export class LocalKeyManager {
|
|
|
148
153
|
* @remarks
|
|
149
154
|
* This method generates a {@link https://datatracker.ietf.org/doc/html/rfc3986 | URI}
|
|
150
155
|
* (Uniform Resource Identifier) for the given JWK, which uniquely identifies the key across all
|
|
151
|
-
* `
|
|
156
|
+
* `KeyManager` implementations. The key URI is constructed by appending the
|
|
152
157
|
* {@link https://datatracker.ietf.org/doc/html/rfc7638 | JWK thumbprint} to the prefix
|
|
153
158
|
* `urn:jwk:`. The JWK thumbprint is deterministically computed from the JWK and is consistent
|
|
154
159
|
* regardless of property order or optional property inclusion in the JWK. This ensures that the
|