@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.
Files changed (116) hide show
  1. package/dist/browser.mjs +1 -1
  2. package/dist/browser.mjs.map +4 -4
  3. package/dist/esm/algorithms/aes-ctr.js +1 -1
  4. package/dist/esm/algorithms/aes-gcm.js +34 -1
  5. package/dist/esm/algorithms/aes-gcm.js.map +1 -1
  6. package/dist/esm/algorithms/aes-kw.js +154 -0
  7. package/dist/esm/algorithms/aes-kw.js.map +1 -0
  8. package/dist/esm/algorithms/ecdsa.js +110 -1
  9. package/dist/esm/algorithms/ecdsa.js.map +1 -1
  10. package/dist/esm/algorithms/eddsa.js +90 -1
  11. package/dist/esm/algorithms/eddsa.js.map +1 -1
  12. package/dist/esm/algorithms/hkdf.js +53 -0
  13. package/dist/esm/algorithms/hkdf.js.map +1 -0
  14. package/dist/esm/algorithms/pbkdf2.js +55 -0
  15. package/dist/esm/algorithms/pbkdf2.js.map +1 -0
  16. package/dist/esm/algorithms/sha-2.js +1 -1
  17. package/dist/esm/algorithms/x25519.js +125 -0
  18. package/dist/esm/algorithms/x25519.js.map +1 -0
  19. package/dist/esm/cose/cbor.js +35 -0
  20. package/dist/esm/cose/cbor.js.map +1 -0
  21. package/dist/esm/cose/cose-key.js +312 -0
  22. package/dist/esm/cose/cose-key.js.map +1 -0
  23. package/dist/esm/cose/cose-sign1.js +283 -0
  24. package/dist/esm/cose/cose-sign1.js.map +1 -0
  25. package/dist/esm/cose/eat.js +254 -0
  26. package/dist/esm/cose/eat.js.map +1 -0
  27. package/dist/esm/crypto-error.js +4 -0
  28. package/dist/esm/crypto-error.js.map +1 -1
  29. package/dist/esm/index.js +9 -0
  30. package/dist/esm/index.js.map +1 -1
  31. package/dist/esm/local-key-manager.js +6 -1
  32. package/dist/esm/local-key-manager.js.map +1 -1
  33. package/dist/esm/primitives/ecies-secp256k1.js +79 -0
  34. package/dist/esm/primitives/ecies-secp256k1.js.map +1 -0
  35. package/dist/esm/primitives/x25519.js +9 -16
  36. package/dist/esm/primitives/x25519.js.map +1 -1
  37. package/dist/esm/utils.js +30 -0
  38. package/dist/esm/utils.js.map +1 -1
  39. package/dist/types/algorithms/aes-ctr.d.ts +1 -1
  40. package/dist/types/algorithms/aes-gcm.d.ts +23 -3
  41. package/dist/types/algorithms/aes-gcm.d.ts.map +1 -1
  42. package/dist/types/algorithms/aes-kw.d.ts +129 -0
  43. package/dist/types/algorithms/aes-kw.d.ts.map +1 -0
  44. package/dist/types/algorithms/ecdsa.d.ts +48 -3
  45. package/dist/types/algorithms/ecdsa.d.ts.map +1 -1
  46. package/dist/types/algorithms/eddsa.d.ts +48 -3
  47. package/dist/types/algorithms/eddsa.d.ts.map +1 -1
  48. package/dist/types/algorithms/hkdf.d.ts +35 -0
  49. package/dist/types/algorithms/hkdf.d.ts.map +1 -0
  50. package/dist/types/algorithms/pbkdf2.d.ts +35 -0
  51. package/dist/types/algorithms/pbkdf2.d.ts.map +1 -0
  52. package/dist/types/algorithms/sha-2.d.ts +1 -1
  53. package/dist/types/algorithms/x25519.d.ts +76 -0
  54. package/dist/types/algorithms/x25519.d.ts.map +1 -0
  55. package/dist/types/cose/cbor.d.ts +30 -0
  56. package/dist/types/cose/cbor.d.ts.map +1 -0
  57. package/dist/types/cose/cose-key.d.ts +106 -0
  58. package/dist/types/cose/cose-key.d.ts.map +1 -0
  59. package/dist/types/cose/cose-sign1.d.ts +195 -0
  60. package/dist/types/cose/cose-sign1.d.ts.map +1 -0
  61. package/dist/types/cose/eat.d.ts +203 -0
  62. package/dist/types/cose/eat.d.ts.map +1 -0
  63. package/dist/types/crypto-error.d.ts +4 -0
  64. package/dist/types/crypto-error.d.ts.map +1 -1
  65. package/dist/types/index.d.ts +9 -0
  66. package/dist/types/index.d.ts.map +1 -1
  67. package/dist/types/local-key-manager.d.ts +4 -4
  68. package/dist/types/local-key-manager.d.ts.map +1 -1
  69. package/dist/types/primitives/ecies-secp256k1.d.ts +53 -0
  70. package/dist/types/primitives/ecies-secp256k1.d.ts.map +1 -0
  71. package/dist/types/primitives/x25519.d.ts +9 -16
  72. package/dist/types/primitives/x25519.d.ts.map +1 -1
  73. package/dist/types/types/crypto-api.d.ts +52 -4
  74. package/dist/types/types/crypto-api.d.ts.map +1 -1
  75. package/dist/types/types/key-converter.d.ts +37 -15
  76. package/dist/types/types/key-converter.d.ts.map +1 -1
  77. package/dist/types/types/key-deriver.d.ts +41 -0
  78. package/dist/types/types/key-deriver.d.ts.map +1 -1
  79. package/dist/types/types/key-io.d.ts +37 -0
  80. package/dist/types/types/key-io.d.ts.map +1 -1
  81. package/dist/types/types/params-direct.d.ts +17 -0
  82. package/dist/types/types/params-direct.d.ts.map +1 -1
  83. package/dist/types/types/params-kms.d.ts +55 -0
  84. package/dist/types/types/params-kms.d.ts.map +1 -1
  85. package/dist/types/utils.d.ts +19 -0
  86. package/dist/types/utils.d.ts.map +1 -1
  87. package/dist/utils.js +1 -1
  88. package/dist/utils.js.map +3 -3
  89. package/package.json +12 -14
  90. package/src/algorithms/aes-ctr.ts +1 -1
  91. package/src/algorithms/aes-gcm.ts +38 -2
  92. package/src/algorithms/aes-kw.ts +182 -0
  93. package/src/algorithms/ecdsa.ts +132 -1
  94. package/src/algorithms/eddsa.ts +108 -1
  95. package/src/algorithms/hkdf.ts +54 -0
  96. package/src/algorithms/pbkdf2.ts +57 -0
  97. package/src/algorithms/sha-2.ts +1 -1
  98. package/src/algorithms/x25519.ts +153 -0
  99. package/src/cose/cbor.ts +36 -0
  100. package/src/cose/cose-key.ts +344 -0
  101. package/src/cose/cose-sign1.ts +473 -0
  102. package/src/cose/eat.ts +368 -0
  103. package/src/crypto-error.ts +6 -0
  104. package/src/index.ts +10 -0
  105. package/src/local-key-manager.ts +9 -4
  106. package/src/primitives/ecies-secp256k1.ts +113 -0
  107. package/src/primitives/x25519.ts +9 -16
  108. package/src/types/crypto-api.ts +124 -6
  109. package/src/types/key-converter.ts +33 -7
  110. package/src/types/key-deriver.ts +49 -0
  111. package/src/types/key-io.ts +40 -0
  112. package/src/types/params-direct.ts +21 -0
  113. package/src/types/params-kms.ts +67 -0
  114. package/src/utils.ts +53 -0
  115. package/dist/browser.js +0 -60
  116. package/dist/browser.js.map +0 -7
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hkdf.d.ts","sourceRoot":"","sources":["../../../src/algorithms/hkdf.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE/D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAGxD;;;GAGG;AACH,MAAM,WAAW,wBAAyB,SAAQ,oBAAoB;IACpE;;;;;OAKG;IACH,SAAS,EAAE,UAAU,GAAG,UAAU,GAAG,UAAU,CAAC;CACjD;AAED;;;GAGG;AACH,qBAAa,aAAc,SAAQ,eACjC,YAAW,eAAe,CAAC,wBAAwB,EAAE,UAAU,CAAC;IAEhE;;;;;;;;;OASG;IACU,cAAc,CAAC,EAAE,SAAS,EAAE,GAAG,MAAM,EAAE,EAClD,wBAAwB,GAAG,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,GAClD,OAAO,CAAC,UAAU,CAAC;CAavB"}
@@ -0,0 +1,35 @@
1
+ import type { DeriveKeyBytesParams } from '../types/params-direct.js';
2
+ import type { KeyBytesDeriver } from '../types/key-deriver.js';
3
+ import type { Pbkdf2Params } from '../primitives/pbkdf2.js';
4
+ import { CryptoAlgorithm } from './crypto-algorithm.js';
5
+ /**
6
+ * The `Pbkdf2DeriveKeyBytesParams` interface defines the algorithm-specific parameters that
7
+ * should be passed into the `deriveKeyBytes()` method when using the PBKDF2 algorithm.
8
+ */
9
+ export interface Pbkdf2DeriveKeyBytesParams extends DeriveKeyBytesParams {
10
+ /** Specifies the algorithm variant for PBKDF2 key derivation.
11
+ * The value determines the hash function that will be used and must be one of the following:
12
+ * - `"PBES2-HS256+A128KW"`: PBKDF2 with HMAC SHA-256 and A128KW key wrapping.
13
+ * - `"PBES2-HS384+A192KW"`: PBKDF2 with HMAC SHA-384 and A192KW key wrapping.
14
+ * - `"PBES2-HS512+A256KW"`: PBKDF2 with HMAC SHA-512 and A256KW key wrapping.
15
+ */
16
+ algorithm: 'PBES2-HS256+A128KW' | 'PBES2-HS384+A192KW' | 'PBES2-HS512+A256KW';
17
+ }
18
+ /**
19
+ * The `Pbkdf2Algorithm` class provides a concrete implementation for PBKDF2 key derivation. It
20
+ * wraps the {@link Pbkdf2} primitive and maps PBES2 JOSE algorithm names to hash functions.
21
+ */
22
+ export declare class Pbkdf2Algorithm extends CryptoAlgorithm implements KeyBytesDeriver<Pbkdf2DeriveKeyBytesParams, Uint8Array> {
23
+ /**
24
+ * Derives a cryptographic byte array using PBKDF2.
25
+ *
26
+ * @param params - The parameters for the key derivation operation.
27
+ * @param params.algorithm - The PBES2 algorithm variant (e.g., `'PBES2-HS512+A256KW'`).
28
+ * @param params.baseKeyBytes - The password or passphrase as bytes.
29
+ * @param params.length - The desired length of the output in bits.
30
+ *
31
+ * @returns A Promise that resolves to the derived key bytes.
32
+ */
33
+ deriveKeyBytes({ algorithm, ...params }: Pbkdf2DeriveKeyBytesParams & Omit<Pbkdf2Params, 'hash'>): Promise<Uint8Array>;
34
+ }
35
+ //# sourceMappingURL=pbkdf2.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pbkdf2.d.ts","sourceRoot":"","sources":["../../../src/algorithms/pbkdf2.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAE5D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAGxD;;;GAGG;AACH,MAAM,WAAW,0BAA2B,SAAQ,oBAAoB;IACtE;;;;;OAKG;IACH,SAAS,EAAE,oBAAoB,GAAG,oBAAoB,GAAG,oBAAoB,CAAC;CAC/E;AAED;;;GAGG;AACH,qBAAa,eAAgB,SAAQ,eACnC,YAAW,eAAe,CAAC,0BAA0B,EAAE,UAAU,CAAC;IAElE;;;;;;;;;OASG;IACU,cAAc,CAAC,EAAE,SAAS,EAAE,GAAG,MAAM,EAAE,EAClD,0BAA0B,GAAG,IAAI,CAAC,YAAY,EAAE,MAAM,CAAC,GACtD,OAAO,CAAC,UAAU,CAAC;CAgBvB"}
@@ -18,7 +18,7 @@ export interface Sha2DigestParams extends DigestParams {
18
18
  * of the hash function and arbitrary data as input and returns the hash digest of the data.
19
19
  *
20
20
  * This class is typically accessed through implementations that extend the
21
- * {@link CryptoApi | `CryptoApi`} interface.
21
+ * {@link DsaApi | `DsaApi`} interface.
22
22
  */
23
23
  export declare class Sha2Algorithm extends CryptoAlgorithm implements Hasher<Sha2DigestParams> {
24
24
  /**
@@ -0,0 +1,76 @@
1
+ import type { AsymmetricKeyGenerator } from '../types/key-generator.js';
2
+ import type { Jwk } from '../jose/jwk.js';
3
+ import type { KeyConverter } from '../types/key-converter.js';
4
+ import type { BytesToPrivateKeyParams, ComputePublicKeyParams, GenerateKeyParams, GetPublicKeyParams, PrivateKeyToBytesParams } from '../types/params-direct.js';
5
+ import { CryptoAlgorithm } from './crypto-algorithm.js';
6
+ /**
7
+ * The `X25519GenerateKeyParams` interface defines the algorithm-specific parameters that should be
8
+ * passed into the `generateKey()` method when using the X25519 key agreement algorithm.
9
+ */
10
+ export interface X25519GenerateKeyParams extends GenerateKeyParams {
11
+ /**
12
+ * A string defining the type of key to generate. The value must be:
13
+ * - `"X25519"`: Elliptic-curve Diffie-Hellman (ECDH) using Curve25519.
14
+ */
15
+ algorithm: 'X25519';
16
+ }
17
+ /**
18
+ * The `X25519Algorithm` class provides a concrete implementation for key generation,
19
+ * public key derivation, and key conversion using the X25519 elliptic curve. X25519 is a
20
+ * key agreement curve (not a signature curve) used for ECDH key exchange in JWE encryption.
21
+ *
22
+ * This class implements the {@link AsymmetricKeyGenerator | `AsymmetricKeyGenerator`} and
23
+ * {@link KeyConverter | `KeyConverter`} interfaces, providing private key generation,
24
+ * public key derivation, and byte/JWK conversion.
25
+ */
26
+ export declare class X25519Algorithm extends CryptoAlgorithm implements AsymmetricKeyGenerator<X25519GenerateKeyParams, Jwk, GetPublicKeyParams>, KeyConverter {
27
+ /**
28
+ * Converts a raw private key in bytes to its corresponding JWK format.
29
+ *
30
+ * @param params - The parameters for the private key conversion.
31
+ * @param params.algorithm - Must be `'X25519'`.
32
+ * @param params.privateKeyBytes - The raw private key as a Uint8Array.
33
+ *
34
+ * @returns A Promise that resolves to the private key in JWK format.
35
+ */
36
+ bytesToPrivateKey({ algorithm, privateKeyBytes }: BytesToPrivateKeyParams & {
37
+ algorithm: 'X25519';
38
+ }): Promise<Jwk>;
39
+ /**
40
+ * Derives the public key in JWK format from a given X25519 private key.
41
+ *
42
+ * @param params - The parameters for the public key derivation.
43
+ * @param params.key - The private key in JWK format from which to derive the public key.
44
+ *
45
+ * @returns A Promise that resolves to the derived public key in JWK format.
46
+ */
47
+ computePublicKey({ key }: ComputePublicKeyParams): Promise<Jwk>;
48
+ /**
49
+ * Generates a new X25519 private key in JWK format.
50
+ *
51
+ * @param params - The parameters for key generation.
52
+ * @param params.algorithm - Must be `'X25519'`.
53
+ *
54
+ * @returns A Promise that resolves to the generated private key in JWK format.
55
+ */
56
+ generateKey({ algorithm }: X25519GenerateKeyParams): Promise<Jwk>;
57
+ /**
58
+ * Retrieves the public key properties from a given X25519 private key in JWK format.
59
+ *
60
+ * @param params - The parameters for retrieving the public key properties.
61
+ * @param params.key - The private key in JWK format.
62
+ *
63
+ * @returns A Promise that resolves to the public key in JWK format.
64
+ */
65
+ getPublicKey({ key }: GetPublicKeyParams): Promise<Jwk>;
66
+ /**
67
+ * Converts a private key from JWK format to a byte array.
68
+ *
69
+ * @param params - The parameters for the private key conversion.
70
+ * @param params.privateKey - The private key in JWK format.
71
+ *
72
+ * @returns A Promise that resolves to the private key as a Uint8Array.
73
+ */
74
+ privateKeyToBytes({ privateKey }: PrivateKeyToBytesParams): Promise<Uint8Array>;
75
+ }
76
+ //# sourceMappingURL=x25519.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"x25519.d.ts","sourceRoot":"","sources":["../../../src/algorithms/x25519.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACxE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,EACV,uBAAuB,EACvB,sBAAsB,EACtB,iBAAiB,EACjB,kBAAkB,EAClB,uBAAuB,EACxB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAMxD;;;GAGG;AACH,MAAM,WAAW,uBAAwB,SAAQ,iBAAiB;IAChE;;;OAGG;IACH,SAAS,EAAE,QAAQ,CAAC;CACrB;AAED;;;;;;;;GAQG;AACH,qBAAa,eAAgB,SAAQ,eACnC,YAAW,sBAAsB,CAAC,uBAAuB,EAAE,GAAG,EAAE,kBAAkB,CAAC,EACxE,YAAY;IAEvB;;;;;;;;OAQG;IACU,iBAAiB,CAAC,EAAE,SAAS,EAAE,eAAe,EAAE,EAC3D,uBAAuB,GAAG;QAAE,SAAS,EAAE,QAAQ,CAAA;KAAE,GAChD,OAAO,CAAC,GAAG,CAAC;IAaf;;;;;;;OAOG;IACU,gBAAgB,CAAC,EAAE,GAAG,EAAE,EACnC,sBAAsB,GACrB,OAAO,CAAC,GAAG,CAAC;IAef;;;;;;;OAOG;IACG,WAAW,CAAC,EAAE,SAAS,EAAE,EAC7B,uBAAuB,GACtB,OAAO,CAAC,GAAG,CAAC;IAaf;;;;;;;OAOG;IACU,YAAY,CAAC,EAAE,GAAG,EAAE,EAC/B,kBAAkB,GACjB,OAAO,CAAC,GAAG,CAAC;IAef;;;;;;;OAOG;IACU,iBAAiB,CAAC,EAAE,UAAU,EAAE,EAC3C,uBAAuB,GACtB,OAAO,CAAC,UAAU,CAAC;CAGvB"}
@@ -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,0BAA0B,CAAC;IAE/C;;;;OAIG;IACH,WAAW,CAAC,EAAE,UAAU,CAAC;IAEzB;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,qDAAqD;IACrD,SAAS,EAAE,UAAU,CAAC;IAEtB,qDAAqD;IACrD,GAAG,EAAE,GAAG,CAAC;IAET;;;;OAIG;IACH,WAAW,CAAC,EAAE,UAAU,CAAC;IAEzB;;OAEG;IACH,OAAO,CAAC,EAAE,UAAU,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,2DAA2D;IAC3D,eAAe,EAAE,wBAAwB,CAAC;IAE1C,0EAA0E;IAC1E,oBAAoB,EAAE,UAAU,CAAC;IAEjC,yCAAyC;IACzC,iBAAiB,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAExC,sCAAsC;IACtC,OAAO,EAAE,UAAU,GAAG,IAAI,CAAC;IAE3B,qBAAqB;IACrB,SAAS,EAAE,UAAU,CAAC;CACvB;AAgBD;;GAEG;AAGH;;;;;;;;;;;;GAYG;AACH,qBAAa,SAAS;IACpB;;;;;;;;;;;;;;;;;;;;;OAqBG;WACiB,MAAM,CAAC,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAAC,UAAU,CAAC;IAwC9E;;;;;;;;;;;OAWG;WACiB,MAAM,CAAC,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAAC,OAAO,CAAC;IAgC3E;;;;;;;;;;;;;OAaG;WACW,MAAM,CAAC,SAAS,EAAE,UAAU,GAAG,gBAAgB;IA6F7D;;;;;;;;;;;;;OAaG;IACH,OAAO,CAAC,MAAM,CAAC,kBAAkB;IAajC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,uBAAuB;IAgBtC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,yBAAyB;IAUxC;;OAEG;mBACkB,SAAS;IAoB9B;;OAEG;mBACkB,WAAW;CAoBjC"}