@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,203 @@
1
+ import type { CoseSign1ProtectedHeader } from './cose-sign1.js';
2
+ import type { Jwk } from '../jose/jwk.js';
3
+ /**
4
+ * EAT (Entity Attestation Token) claim key constants.
5
+ *
6
+ * EAT reuses CWT registered claim keys and adds attestation-specific claims.
7
+ *
8
+ * @see {@link https://www.rfc-editor.org/rfc/rfc9711 | RFC 9711 — Entity Attestation Token (EAT)}
9
+ * @see {@link https://www.rfc-editor.org/rfc/rfc8392 | RFC 8392 — CWT (CBOR Web Token)}
10
+ */
11
+ export declare enum EatClaimKey {
12
+ /** Issuer (iss) — RFC 8392 */
13
+ Iss = 1,
14
+ /** Subject (sub) — RFC 8392 */
15
+ Sub = 2,
16
+ /** Audience (aud) — RFC 8392 */
17
+ Aud = 3,
18
+ /** Expiration Time (exp) — RFC 8392 */
19
+ Exp = 4,
20
+ /** Not Before (nbf) — RFC 8392 */
21
+ Nbf = 5,
22
+ /** Issued At (iat) — RFC 8392 */
23
+ Iat = 6,
24
+ /** CWT ID (cti) — RFC 8392 */
25
+ Cti = 7,
26
+ /** Nonce (eat_nonce) — RFC 9711, Section 4.1 */
27
+ Nonce = 10,
28
+ /** UEID (Universal Entity ID) — RFC 9711, Section 4.2.1 */
29
+ Ueid = 256,
30
+ /** SUEIDs (Semi-permanent UEIDs) — RFC 9711, Section 4.2.2 */
31
+ Sueids = 257,
32
+ /** OEM ID (Hardware OEM Identification) — RFC 9711, Section 4.2.3 */
33
+ Oemid = 258,
34
+ /** Hardware Model — RFC 9711, Section 4.2.4 */
35
+ Hwmodel = 259,
36
+ /** Hardware Version — RFC 9711, Section 4.2.5 */
37
+ Hwversion = 260,
38
+ /** Secure Boot — RFC 9711, Section 4.2.7 */
39
+ Secboot = 262,
40
+ /** Debug Status — RFC 9711, Section 4.2.8 */
41
+ Dbgstat = 263,
42
+ /** Location — RFC 9711, Section 4.2.9 */
43
+ Location = 264,
44
+ /** Profile — RFC 9711, Section 4.2.10 */
45
+ Profile = 265,
46
+ /** Submods (Submodules) — RFC 9711, Section 4.2.18 */
47
+ Submods = 266,
48
+ /** Measurement Results — RFC 9711, Section 4.2.15 */
49
+ Measres = 272,
50
+ /** Intended Use — RFC 9711, Section 4.2.14 */
51
+ Intuse = 268
52
+ }
53
+ /**
54
+ * Debug status values for the `dbgstat` claim.
55
+ *
56
+ * @see {@link https://www.rfc-editor.org/rfc/rfc9711#section-4.2.8 | RFC 9711, Section 4.2.8}
57
+ */
58
+ export declare enum EatDebugStatus {
59
+ /** Debug is enabled */
60
+ Enabled = 0,
61
+ /** Debug is disabled */
62
+ Disabled = 1,
63
+ /** Debug is disabled since manufacture */
64
+ DisabledSinceBoot = 2,
65
+ /** Debug is disabled permanently */
66
+ DisabledPermanently = 3,
67
+ /** Debug is disabled fully and permanently */
68
+ DisabledFullyAndPermanently = 4
69
+ }
70
+ /**
71
+ * Security level for the `seclevel` claim.
72
+ *
73
+ * @see {@link https://www.rfc-editor.org/rfc/rfc9711#section-4.2.6 | RFC 9711, Section 4.2.6}
74
+ */
75
+ export declare enum EatSecurityLevel {
76
+ /** Unrestricted — no security guarantees */
77
+ Unrestricted = 1,
78
+ /** Restricted — some restrictions on environment */
79
+ Restricted = 2,
80
+ /** Secure Restricted — hardware-enforced restrictions */
81
+ SecureRestricted = 3,
82
+ /** Hardware — hardware-isolated execution environment */
83
+ Hardware = 4
84
+ }
85
+ /**
86
+ * Parsed EAT claims, providing typed access to standard and attestation-specific claims.
87
+ *
88
+ * All fields are optional because EAT does not mandate any specific claims; the
89
+ * required set depends on the attestation profile.
90
+ *
91
+ * @see {@link https://www.rfc-editor.org/rfc/rfc9711 | RFC 9711}
92
+ */
93
+ export interface EatClaims {
94
+ /** Issuer — identifies the entity that issued the token. */
95
+ iss?: string;
96
+ /** Subject — identifies the entity that is the subject of the token. */
97
+ sub?: string;
98
+ /** Audience — identifies the intended recipient(s). */
99
+ aud?: string;
100
+ /** Expiration time (seconds since epoch). */
101
+ exp?: number;
102
+ /** Not Before (seconds since epoch). */
103
+ nbf?: number;
104
+ /** Issued At (seconds since epoch). */
105
+ iat?: number;
106
+ /** CWT ID — unique token identifier (byte string). */
107
+ cti?: Uint8Array;
108
+ /** Nonce — challenge value binding the token to a request. */
109
+ nonce?: Uint8Array | Uint8Array[];
110
+ /** Universal Entity ID. */
111
+ ueid?: Uint8Array;
112
+ /** Hardware model identifier. */
113
+ hwmodel?: Uint8Array;
114
+ /** Hardware version. */
115
+ hwversion?: unknown;
116
+ /** Debug status. */
117
+ dbgstat?: EatDebugStatus;
118
+ /** Measurement results — software component measurements. */
119
+ measres?: unknown;
120
+ /** Submodules — nested EAT tokens or claims from sub-components. */
121
+ submods?: Map<string, unknown>;
122
+ /**
123
+ * All raw claims as a Map for access to non-standard or profile-specific claims.
124
+ * Integer keys correspond to {@link EatClaimKey} values.
125
+ */
126
+ rawClaims: Map<number | string, unknown>;
127
+ }
128
+ /**
129
+ * Parameters for decoding an EAT token.
130
+ */
131
+ export interface EatDecodeParams {
132
+ /** The CBOR-encoded EAT token (COSE_Sign1 envelope). */
133
+ token: Uint8Array;
134
+ }
135
+ /**
136
+ * Parameters for verifying and decoding an EAT token.
137
+ */
138
+ export interface EatVerifyParams {
139
+ /** The CBOR-encoded EAT token (COSE_Sign1 envelope). */
140
+ token: Uint8Array;
141
+ /** The public key for signature verification, in JWK format. */
142
+ key: Jwk;
143
+ /** External additional authenticated data. Defaults to empty bytes. */
144
+ externalAad?: Uint8Array;
145
+ }
146
+ /**
147
+ * Result of decoding an EAT token.
148
+ */
149
+ export interface EatDecodeResult {
150
+ /** The parsed protected header from the COSE_Sign1 envelope. */
151
+ protectedHeader: CoseSign1ProtectedHeader;
152
+ /** The parsed EAT claims from the payload. */
153
+ claims: EatClaims;
154
+ }
155
+ /**
156
+ * Entity Attestation Token (EAT) implementation per RFC 9711.
157
+ *
158
+ * EATs are CBOR-based attestation tokens carried in COSE_Sign1 envelopes.
159
+ * They are used by TEE platforms (ARM CCA, Intel TDX, AMD SEV-SNP, Nitro Enclaves)
160
+ * to provide hardware-rooted attestation evidence.
161
+ *
162
+ * This implementation focuses on decoding and verification of EAT tokens — the
163
+ * primary use case for a DWN node that needs to verify TEE attestation from
164
+ * compute modules.
165
+ *
166
+ * @see {@link https://www.rfc-editor.org/rfc/rfc9711 | RFC 9711 — Entity Attestation Token (EAT)}
167
+ */
168
+ export declare class Eat {
169
+ /**
170
+ * Decodes an EAT token without verifying its signature.
171
+ *
172
+ * Use this method only when signature verification is performed separately
173
+ * (e.g., by a TEE attestation service) or for debugging/inspection.
174
+ *
175
+ * @param params - The parameters for decoding.
176
+ * @returns The decoded protected header and claims.
177
+ * @throws {CryptoError} If the token is not valid COSE_Sign1 or the payload is not valid CBOR.
178
+ */
179
+ static decode({ token }: EatDecodeParams): EatDecodeResult;
180
+ /**
181
+ * Verifies the signature of an EAT token and decodes its claims.
182
+ *
183
+ * This is the primary method for processing EAT tokens from TEE attestation.
184
+ * It verifies the COSE_Sign1 signature using the provided public key, then
185
+ * parses the EAT claims from the payload.
186
+ *
187
+ * @param params - The parameters for verification and decoding.
188
+ * @returns The decoded protected header and claims if verification succeeds.
189
+ * @throws {CryptoError} If verification fails or the token is malformed.
190
+ */
191
+ static verifyAndDecode(params: EatVerifyParams): Promise<EatDecodeResult>;
192
+ /**
193
+ * Parses CBOR-encoded EAT claims into a typed {@link EatClaims} object.
194
+ *
195
+ * Handles both integer-keyed (CBOR standard) and string-keyed claims.
196
+ *
197
+ * @param payload - The CBOR-encoded claims byte string.
198
+ * @returns The parsed EAT claims.
199
+ * @throws {CryptoError} If the payload is not valid CBOR or not a map.
200
+ */
201
+ private static parseClaims;
202
+ }
203
+ //# sourceMappingURL=eat.d.ts.map
@@ -0,0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AAe;IAC9B,gEAAgE;IAChE,eAAe,EAAE,wBAAwB,CAAC;IAE1C,8CAA8C;IAC9C,MAAM,EAAE,SAAS,CAAC;CACnB;AAED;;;;;;;;;;;;GAYG;AACH,qBAAa,GAAG;IACd;;;;;;;;;OASG;WACW,MAAM,CAAC,EAAE,KAAK,EAAE,EAAE,eAAe,GAAG,eAAe;IAoBjE;;;;;;;;;;OAUG;WACiB,eAAe,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC;IAqBtF;;;;;;;;OAQG;IACH,OAAO,CAAC,MAAM,CAAC,WAAW;CAmG3B"}
@@ -19,6 +19,10 @@ export declare enum CryptoErrorCode {
19
19
  AlgorithmNotSupported = "algorithmNotSupported",
20
20
  /** The encoding operation (either encoding or decoding) failed. */
21
21
  EncodingError = "encodingError",
22
+ /** The COSE_Sign1 message does not conform to valid structure. */
23
+ InvalidCoseSign1 = "invalidCoseSign1",
24
+ /** The EAT (Entity Attestation Token) is malformed or failed verification. */
25
+ InvalidEat = "invalidEat",
22
26
  /** The JWE supplied does not conform to valid syntax. */
23
27
  InvalidJwe = "invalidJwe",
24
28
  /** The JWK supplied does not conform to valid syntax. */
@@ -1 +1 @@
1
- {"version":3,"file":"crypto-error.d.ts","sourceRoot":"","sources":["../../src/crypto-error.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,WAAY,SAAQ,KAAK;IAOjB,IAAI,EAAE,eAAe;IANxC;;;;;OAKG;gBACgB,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM;CAc1D;AAED;;GAEG;AACH,oBAAY,eAAe;IACzB,gFAAgF;IAChF,qBAAqB,0BAA0B;IAE/C,mEAAmE;IACnE,aAAa,kBAAkB;IAE/B,yDAAyD;IACzD,UAAU,eAAe;IAEzB,yDAAyD;IACzD,UAAU,eAAe;IAEzB,sEAAsE;IACtE,qBAAqB,0BAA0B;CAChD"}
1
+ {"version":3,"file":"crypto-error.d.ts","sourceRoot":"","sources":["../../src/crypto-error.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,WAAY,SAAQ,KAAK;IAOjB,IAAI,EAAE,eAAe;IANxC;;;;;OAKG;gBACgB,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM;CAc1D;AAED;;GAEG;AACH,oBAAY,eAAe;IACzB,gFAAgF;IAChF,qBAAqB,0BAA0B;IAE/C,mEAAmE;IACnE,aAAa,kBAAkB;IAE/B,kEAAkE;IAClE,gBAAgB,qBAAqB;IAErC,8EAA8E;IAC9E,UAAU,eAAe;IAEzB,yDAAyD;IACzD,UAAU,eAAe;IAEzB,yDAAyD;IACzD,UAAU,eAAe;IAEzB,sEAAsE;IACtE,qBAAqB,0BAA0B;CAChD"}
@@ -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';
@@ -1 +1 @@
1
- {"version":3,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BAAmB,CAAC;AACvC,mBAAmB,wBAAwB,CAAC;AAC5C,mBAAmB,0BAA0B,CAAC;AAC9C,mBAAmB,4BAA4B,CAAC;AAChD,mBAAmB,uBAAuB,CAAC;AAC3C,mBAAmB,mBAAmB,CAAC"}
@@ -1,8 +1,8 @@
1
1
  import type { KeyValueStore } from '@enbox/common';
2
- import type { CryptoApi } from './types/crypto-api.js';
3
2
  import type { Jwk } from './jose/jwk.js';
4
3
  import type { KeyIdentifier } from './types/identifier.js';
5
4
  import type { KeyImporterExporter } from './types/key-io.js';
5
+ import type { KeyManager } from './types/crypto-api.js';
6
6
  import type { KmsDigestParams, KmsExportKeyParams, KmsGenerateKeyParams, KmsGetKeyUriParams, KmsGetPublicKeyParams, KmsImportKeyParams, KmsSignParams, KmsVerifyParams } from './types/params-kms.js';
7
7
  /**
8
8
  * The `LocalKeyManagerParams` interface specifies the parameters for initializing an instance of
@@ -42,9 +42,9 @@ export interface LocalKeyManagerGenerateKeyParams extends KmsGenerateKeyParams {
42
42
  * - `"Ed25519"`
43
43
  * - `"secp256k1"`
44
44
  */
45
- algorithm: 'Ed25519' | 'secp256k1' | 'secp256r1';
45
+ algorithm: 'Ed25519' | 'secp256k1' | 'secp256r1' | 'X25519';
46
46
  }
47
- export declare class LocalKeyManager implements CryptoApi, KeyImporterExporter<KmsImportKeyParams, KeyIdentifier, KmsExportKeyParams> {
47
+ export declare class LocalKeyManager implements KeyManager, KeyImporterExporter<KmsImportKeyParams, KeyIdentifier, KmsExportKeyParams> {
48
48
  /**
49
49
  * A private map that stores instances of cryptographic algorithm implementations. Each key in
50
50
  * this map is an `AlgorithmConstructor`, and its corresponding value is an instance of a class
@@ -131,7 +131,7 @@ export declare class LocalKeyManager implements CryptoApi, KeyImporterExporter<K
131
131
  * @remarks
132
132
  * This method generates a {@link https://datatracker.ietf.org/doc/html/rfc3986 | URI}
133
133
  * (Uniform Resource Identifier) for the given JWK, which uniquely identifies the key across all
134
- * `CryptoApi` implementations. The key URI is constructed by appending the
134
+ * `KeyManager` implementations. The key URI is constructed by appending the
135
135
  * {@link https://datatracker.ietf.org/doc/html/rfc7638 | JWK thumbprint} to the prefix
136
136
  * `urn:jwk:`. The JWK thumbprint is deterministically computed from the JWK and is consistent
137
137
  * regardless of property order or optional property inclusion in the JWK. This ensures that the
@@ -1 +1 @@
1
- {"version":3,"file":"local-key-manager.d.ts","sourceRoot":"","sources":["../../src/local-key-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAInD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAI7D,OAAO,KAAK,EACV,eAAe,EACf,kBAAkB,EAClB,oBAAoB,EACpB,kBAAkB,EAClB,qBAAqB,EACrB,kBAAkB,EAClB,aAAa,EACb,eAAe,EAChB,MAAM,uBAAuB,CAAC;AA6C/B;;;;;;GAMG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,aAAa,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC;CAC9C,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,2BAA4B,SAAQ,eAAe;IAClE;;;OAGG;IACH,SAAS,EAAE,SAAS,CAAC;CACtB;AAED;;;;GAIG;AACH,MAAM,WAAW,gCAAiC,SAAQ,oBAAoB;IAC5E;;;;OAIG;IACH,SAAS,EAAE,SAAS,GAAG,WAAW,GAAG,WAAW,CAAC;CAClD;AAED,qBAAa,eAAgB,YACzB,SAAS,EACT,mBAAmB,CAAC,kBAAkB,EAAE,aAAa,EAAE,kBAAkB,CAAC;IAE5E;;;;;OAKG;IACH,OAAO,CAAC,mBAAmB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AAE,IAAI,EAAE,EACrC,2BAA2B,GAC1B,OAAO,CAAC,UAAU,CAAC;IAUtB;;;;;;;;;;;;;;;;;;OAkBG;IACU,SAAS,CAAC,EAAE,MAAM,EAAE,EAC/B,kBAAkB,GACjB,OAAO,CAAC,GAAG,CAAC;IAOf;;;;;;;;;;;;;;;OAeG;IACU,WAAW,CAAC,EAAE,SAAS,EAAE,EACpC,gCAAgC,GAC/B,OAAO,CAAC,aAAa,CAAC;IAoBzB;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACU,SAAS,CAAC,EAAE,GAAG,EAAE,EAC5B,kBAAkB,GACjB,OAAO,CAAC,aAAa,CAAC;IAUzB;;;;;;;;;;;;;;;OAeG;IACU,YAAY,CAAC,EAAE,MAAM,EAAE,EAClC,qBAAqB,GACpB,OAAO,CAAC,GAAG,CAAC;IAgBf;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACU,SAAS,CAAC,EAAE,GAAG,EAAE,EAC5B,kBAAkB,GACjB,OAAO,CAAC,aAAa,CAAC;IAkBzB;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACU,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,EAChC,aAAa,GACZ,OAAO,CAAC,UAAU,CAAC;IAgBtB;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACU,MAAM,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,EAC1C,eAAe,GACd,OAAO,CAAC,OAAO,CAAC;IAanB;;;;;;;;;;;;;;;;;;;OAmBG;IACH,OAAO,CAAC,YAAY;IAmBpB;;;;;;;;;;;;;;;;;;;OAmBG;IACH,OAAO,CAAC,gBAAgB;IAkBxB;;;;;;;;;;;;;;OAcG;YACW,aAAa;CAY5B"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Output of an ECIES-SECP256K1 encryption operation.
3
+ */
4
+ export type EciesSecp256k1EncryptionOutput = {
5
+ /** The AES-GCM initialization vector. */
6
+ initializationVector: Uint8Array;
7
+ /** The ephemeral secp256k1 public key (compressed, 33 bytes). */
8
+ ephemeralPublicKey: Uint8Array;
9
+ /** The encrypted data. */
10
+ ciphertext: Uint8Array;
11
+ /** The AES-GCM authentication tag (16 bytes). */
12
+ messageAuthenticationCode: Uint8Array;
13
+ };
14
+ /**
15
+ * Input required for ECIES-SECP256K1 decryption.
16
+ */
17
+ export type EciesSecp256k1EncryptionInput = EciesSecp256k1EncryptionOutput & {
18
+ /** The recipient's secp256k1 private key (raw 32 bytes). */
19
+ privateKey: Uint8Array;
20
+ };
21
+ /**
22
+ * Browser-compatible ECIES (Elliptic Curve Integrated Encryption Scheme) using secp256k1.
23
+ *
24
+ * Wire-format compatible with `eciesjs` v0.4.x configured with
25
+ * `isEphemeralKeyCompressed: true, isHkdfKeyCompressed: false` (the default).
26
+ *
27
+ * Protocol:
28
+ * 1. Generate an ephemeral secp256k1 key pair.
29
+ * 2. ECDH shared secret (uncompressed point).
30
+ * 3. HKDF-SHA-256 key derivation: `hkdf(sha256, ephemeralPubUncompressed || sharedPointUncompressed)`.
31
+ * 4. AES-256-GCM encryption with random 16-byte nonce.
32
+ *
33
+ * All underlying primitives (`@noble/ciphers`, `@noble/curves`, `@noble/hashes`)
34
+ * are pure JavaScript and work in Node, Bun, and browsers.
35
+ */
36
+ export declare class EciesSecp256k1 {
37
+ /**
38
+ * Encrypt plaintext for a given secp256k1 public key.
39
+ * @param publicKeyBytes - Recipient's public key (compressed 33 bytes or uncompressed 65 bytes).
40
+ * @param plaintext - The data to encrypt.
41
+ */
42
+ static encrypt(publicKeyBytes: Uint8Array, plaintext: Uint8Array): EciesSecp256k1EncryptionOutput;
43
+ /**
44
+ * Decrypt ciphertext produced by {@link EciesSecp256k1.encrypt}.
45
+ * @param input - The encryption output plus the recipient's private key.
46
+ */
47
+ static decrypt(input: EciesSecp256k1EncryptionInput): Uint8Array;
48
+ /**
49
+ * Whether the ephemeral public key is compressed (always true for this implementation).
50
+ */
51
+ static get isEphemeralKeyCompressed(): boolean;
52
+ }
53
+ //# sourceMappingURL=ecies-secp256k1.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ecies-secp256k1.d.ts","sourceRoot":"","sources":["../../../src/primitives/ecies-secp256k1.ts"],"names":[],"mappings":"AAiBA;;GAEG;AACH,MAAM,MAAM,8BAA8B,GAAG;IAC3C,yCAAyC;IACzC,oBAAoB,EAAE,UAAU,CAAC;IACjC,iEAAiE;IACjE,kBAAkB,EAAE,UAAU,CAAC;IAC/B,0BAA0B;IAC1B,UAAU,EAAE,UAAU,CAAC;IACvB,iDAAiD;IACjD,yBAAyB,EAAE,UAAU,CAAC;CACvC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,6BAA6B,GAAG,8BAA8B,GAAG;IAC3E,4DAA4D;IAC5D,UAAU,EAAE,UAAU,CAAC;CACxB,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,qBAAa,cAAc;IACzB;;;;OAIG;WACW,OAAO,CAAC,cAAc,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,GAAG,8BAA8B;IAyBxG;;;OAGG;WACW,OAAO,CAAC,KAAK,EAAE,6BAA6B,GAAG,UAAU;IAiBvE;;OAEG;IACH,WAAkB,wBAAwB,IAAI,OAAO,CAEpD;CACF"}
@@ -238,32 +238,25 @@ export declare class X25519 {
238
238
  publicKey: Jwk;
239
239
  }): Promise<Uint8Array>;
240
240
  /**
241
- * Computes an RFC6090-compliant Elliptic Curve Diffie-Hellman (ECDH) shared secret
242
- * using secp256k1 private and public keys in JSON Web Key (JWK) format.
241
+ * Computes an X25519 Elliptic Curve Diffie-Hellman (ECDH) shared secret
242
+ * using X25519 private and public keys in JSON Web Key (JWK) format.
243
243
  *
244
244
  * @remarks
245
245
  * This method facilitates the ECDH key agreement protocol, which is a method of securely
246
246
  * deriving a shared secret between two parties based on their private and public keys.
247
247
  * It takes the private key of one party (privateKeyA) and the public key of another
248
- * party (publicKeyB) to compute a shared secret. The shared secret is derived from the
249
- * x-coordinate of the elliptic curve point resulting from the multiplication of the
250
- * public key with the private key.
251
- *
252
- * Note: When performing Elliptic Curve Diffie-Hellman (ECDH) key agreement,
253
- * the resulting shared secret is a point on the elliptic curve, which
254
- * consists of an x-coordinate and a y-coordinate. With a 256-bit curve like
255
- * secp256k1, each of these coordinates is 32 bytes (256 bits) long. However,
256
- * in the ECDH process, it's standard practice to use only the x-coordinate
257
- * of the shared secret point as the resulting shared key. This is because
258
- * the y-coordinate does not add to the entropy of the key, and both parties
259
- * can independently compute the x-coordinate. Consquently, this implementation
260
- * omits the y-coordinate for simplicity and standard compliance.
248
+ * party (publicKeyB) to compute a shared secret. The shared secret is the raw output
249
+ * of the X25519 function as defined in RFC 7748.
250
+ *
251
+ * Note: Unlike Weierstrass curves (e.g., secp256k1), X25519 is a Montgomery curve
252
+ * where the ECDH output is a single 32-byte scalar value, not an (x, y) point.
253
+ * The result is used directly as the shared secret.
261
254
  *
262
255
  * @example
263
256
  * ```ts
264
257
  * const privateKeyA = { ... }; // A Jwk object for party A
265
258
  * const publicKeyB = { ... }; // A PublicKeyJwk object for party B
266
- * const sharedSecret = await Secp256k1.sharedSecret({
259
+ * const sharedSecret = await X25519.sharedSecret({
267
260
  * privateKeyA,
268
261
  * publicKeyB
269
262
  * });
@@ -1 +1 @@
1
- {"version":3,"file":"x25519.d.ts","sourceRoot":"","sources":["../../../src/primitives/x25519.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAI5F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,qBAAa,MAAM;IACjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;WACiB,iBAAiB,CAAC,EAAE,eAAe,EAAE,EAAE;QACzD,eAAe,EAAE,UAAU,CAAC;KAC7B,GAAG,OAAO,CAAC,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exB"}
@@ -1,10 +1,16 @@
1
+ import type { AsymmetricKeyConverter } from './key-converter.js';
1
2
  import type { AsymmetricKeyGenerator } from './key-generator.js';
3
+ import type { Cipher } from './cipher.js';
2
4
  import type { Hasher } from './hasher.js';
5
+ import type { Jwk } from '../jose/jwk.js';
3
6
  import type { KeyIdentifier } from './identifier.js';
7
+ import type { KeyWrapper } from './key-wrapper.js';
4
8
  import type { Signer } from './signer.js';
5
- import type { KmsDigestParams, KmsGenerateKeyParams, KmsGetKeyUriParams, KmsGetPublicKeyParams, KmsSignParams, KmsVerifyParams } from './params-kms.js';
9
+ import type { BytesToPrivateKeyParams, BytesToPublicKeyParams, CipherParams, DeriveKeyBytesParams, DeriveKeyFromBytesParams, DigestParams, GenerateKeyParams, GetPublicKeyParams, PrivateKeyToBytesParams, PublicKeyToBytesParams, SignParams, UnwrapKeyParams, VerifyParams, WrapKeyParams } from './params-direct.js';
10
+ import type { KeyBytesDeriver, SimpleKeyDeriver } from './key-deriver.js';
11
+ import type { KmsCipherParams, KmsDigestParams, KmsGenerateKeyParams, KmsGetKeyUriParams, KmsGetPublicKeyParams, KmsSignParams, KmsVerifyParams } from './params-kms.js';
6
12
  /**
7
- * The `CryptoApi` interface integrates key generation, hashing, and signing functionalities,
13
+ * The `DsaApi` interface integrates key generation, hashing, and signing functionalities,
8
14
  * designed for use with a Key Management System (KMS). It extends `AsymmetricKeyGenerator` for
9
15
  * generating asymmetric keys, `Hasher` for hash digest computations, and `Signer` for signing and
10
16
  * verifying operations.
@@ -24,12 +30,54 @@ import type { KmsDigestParams, KmsGenerateKeyParams, KmsGetKeyUriParams, KmsGetP
24
30
  * identifier (e.g. JWK thumbprint, UUID generated by hosted KMS, etc.).
25
31
  * - Must support key generation, hashing, signing, and verifying operations.
26
32
  * - May be extended to support other cryptographic operations.
27
- * - Implementations of the `CryptoApi` interface can be passed as an argument to the public API
33
+ * - Implementations of the `DsaApi` interface can be passed as an argument to the public API
28
34
  * methods of Web5 libraries that involve key material (e.g., DID creation, VC signing, arbitrary
29
35
  * data signing/verification, etc.).
30
36
  */
31
- export interface CryptoApi<GenerateKeyInput = KmsGenerateKeyParams, GenerateKeyOutput = KeyIdentifier, GetPublicKeyInput = KmsGetPublicKeyParams, DigestInput = KmsDigestParams, SignInput = KmsSignParams, VerifyInput = KmsVerifyParams> extends AsymmetricKeyGenerator<GenerateKeyInput, GenerateKeyOutput, GetPublicKeyInput>, Hasher<DigestInput>, Signer<SignInput, VerifyInput> {
37
+ export interface DsaApi<GenerateKeyInput = KmsGenerateKeyParams, GenerateKeyOutput = KeyIdentifier, GetPublicKeyInput = KmsGetPublicKeyParams, DigestInput = KmsDigestParams, SignInput = KmsSignParams, VerifyInput = KmsVerifyParams> extends AsymmetricKeyGenerator<GenerateKeyInput, GenerateKeyOutput, GetPublicKeyInput>, Hasher<DigestInput>, Signer<SignInput, VerifyInput> {
38
+ }
39
+ /**
40
+ * The `CryptoApi` interface extends {@link DsaApi} with encryption, key conversion,
41
+ * key derivation, and key wrapping capabilities.
42
+ *
43
+ * This is the full-featured cryptographic API used by agent-level code that needs direct-key
44
+ * cipher, key conversion, and key derivation operations beyond what the base `DsaApi` provides.
45
+ */
46
+ export interface CryptoApi<GenerateKeyInput = GenerateKeyParams, GenerateKeyOutput = Jwk, GetPublicKeyInput = GetPublicKeyParams, DigestInput = DigestParams, SignInput = SignParams, VerifyInput = VerifyParams, EncryptInput = CipherParams, DecryptInput = CipherParams, BytesToPublicKeyInput = BytesToPublicKeyParams, PublicKeyToBytesInput = PublicKeyToBytesParams, BytesToPrivateKeyInput = BytesToPrivateKeyParams, PrivateKeyToBytesInput = PrivateKeyToBytesParams, DeriveKeyInput = DeriveKeyFromBytesParams, DeriveKeyOutput = Jwk, DeriveKeyBytesInput = DeriveKeyBytesParams, DeriveKeyBytesOutput = Uint8Array, WrapKeyInput = WrapKeyParams, UnwrapKeyInput = UnwrapKeyParams> extends DsaApi<GenerateKeyInput, GenerateKeyOutput, GetPublicKeyInput, DigestInput, SignInput, VerifyInput>, Cipher<EncryptInput, DecryptInput>, AsymmetricKeyConverter<BytesToPublicKeyInput, PublicKeyToBytesInput, BytesToPrivateKeyInput, PrivateKeyToBytesInput>, SimpleKeyDeriver<DeriveKeyInput, DeriveKeyOutput>, KeyBytesDeriver<DeriveKeyBytesInput, DeriveKeyBytesOutput>, KeyWrapper<WrapKeyInput, UnwrapKeyInput> {
47
+ }
48
+ /** @deprecated Use {@link CryptoApi} instead. */
49
+ export type ExtendedCryptoApi<GenerateKeyInput = GenerateKeyParams, GenerateKeyOutput = Jwk, GetPublicKeyInput = GetPublicKeyParams, DigestInput = DigestParams, SignInput = SignParams, VerifyInput = VerifyParams, EncryptInput = CipherParams, DecryptInput = CipherParams, BytesToPublicKeyInput = BytesToPublicKeyParams, PublicKeyToBytesInput = PublicKeyToBytesParams, BytesToPrivateKeyInput = BytesToPrivateKeyParams, PrivateKeyToBytesInput = PrivateKeyToBytesParams, DeriveKeyInput = DeriveKeyFromBytesParams, DeriveKeyOutput = Jwk, DeriveKeyBytesInput = DeriveKeyBytesParams, DeriveKeyBytesOutput = Uint8Array, WrapKeyInput = WrapKeyParams, UnwrapKeyInput = UnwrapKeyParams> = CryptoApi<GenerateKeyInput, GenerateKeyOutput, GetPublicKeyInput, DigestInput, SignInput, VerifyInput, EncryptInput, DecryptInput, BytesToPublicKeyInput, PublicKeyToBytesInput, BytesToPrivateKeyInput, PrivateKeyToBytesInput, DeriveKeyInput, DeriveKeyOutput, DeriveKeyBytesInput, DeriveKeyBytesOutput, WrapKeyInput, UnwrapKeyInput>;
50
+ /**
51
+ * Parameters for configuring a {@link KeyManager} implementation.
52
+ */
53
+ export interface KeyManagerParams {
54
+ CipherInput?: unknown;
55
+ GenerateKeyInput?: unknown;
56
+ GenerateKeyOutput?: unknown;
57
+ GetPublicKeyInput?: unknown;
58
+ SignInput?: unknown;
59
+ VerifyInput?: unknown;
60
+ }
61
+ /**
62
+ * Default parameter types for {@link KeyManager}, using KMS-oriented types.
63
+ */
64
+ export interface DefaultKeyManagerParams {
65
+ CipherInput: KmsCipherParams;
66
+ GenerateKeyInput: KmsGenerateKeyParams;
67
+ GenerateKeyOutput: KeyIdentifier;
68
+ GetPublicKeyInput: KmsGetPublicKeyParams;
69
+ SignInput: KmsSignParams;
70
+ VerifyInput: KmsVerifyParams;
71
+ }
72
+ /**
73
+ * The `KeyManager` interface integrates key generation and signing capabilities.
74
+ *
75
+ * Concrete implementations of this interface are intended to be used as a Key Management System
76
+ * (KMS), which is responsible for generating and storing cryptographic keys.
77
+ */
78
+ export interface KeyManager<T extends KeyManagerParams = DefaultKeyManagerParams> extends DsaApi<T['GenerateKeyInput'], T['GenerateKeyOutput'], T['GetPublicKeyInput'], KmsDigestParams, T['SignInput'], T['VerifyInput']> {
32
79
  /**
80
+ * Returns the Key URI for a given JWK.
33
81
  *
34
82
  * @param params - The parameters for getting the key URI.
35
83
  * @param params.key - The key to get the URI for.
@@ -1 +1 @@
1
- {"version":3,"file":"crypto-api.d.ts","sourceRoot":"","sources":["../../../src/types/crypto-api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EACV,eAAe,EACf,oBAAoB,EACpB,kBAAkB,EAClB,qBAAqB,EACrB,aAAa,EACb,eAAe,EAChB,MAAM,iBAAiB,CAAC;AAEzB;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,WAAW,SAAS,CACxB,gBAAgB,GAAG,oBAAoB,EACvC,iBAAiB,GAAG,aAAa,EACjC,iBAAiB,GAAG,qBAAqB,EACzC,WAAW,GAAG,eAAe,EAC7B,SAAS,GAAG,aAAa,EACzB,WAAW,GA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iB,EAAE,qBAAqB,CAAC;IACzC,SAAS,EAAE,aAAa,CAAC;IACzB,WAAW,EAAE,eAAe,CAAC;CAC9B;AAED;;;;;GAKG;AACH,MAAM,WAAW,UAAU,CAAC,CAAC,SAAS,gBAAgB,GAAG,uBAAuB,CAC9E,SAAQ,MAAM,CAAC,CAAC,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAC,mBAAmB,CAAC,EAAE,CAAC,CAAC,mBAAmB,CAAC,EAAE,eAAe,EAAE,CAAC,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,aAAa,CAAC,CAAC;IAExI;;;;;;OAMG;IACH,SAAS,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;CAC/D"}
@@ -1,8 +1,17 @@
1
1
  import type { Jwk } from '../jose/jwk.js';
2
2
  /**
3
3
  * `KeyConverter` interface for converting private keys between byte array and JWK formats.
4
+ *
5
+ * @typeParam BytesToPrivateKeyInput - The input type for `bytesToPrivateKey`. Defaults to
6
+ * `{ privateKeyBytes: Uint8Array }`.
7
+ * @typeParam PrivateKeyToBytesInput - The input type for `privateKeyToBytes`. Defaults to
8
+ * `{ privateKey: Jwk }`.
4
9
  */
5
- export interface KeyConverter {
10
+ export interface KeyConverter<BytesToPrivateKeyInput = {
11
+ privateKeyBytes: Uint8Array;
12
+ }, PrivateKeyToBytesInput = {
13
+ privateKey: Jwk;
14
+ }> {
6
15
  /**
7
16
  * Converts a private key from a byte array to JWK format.
8
17
  *
@@ -11,9 +20,7 @@ export interface KeyConverter {
11
20
  *
12
21
  * @returns A Promise that resolves to the private key in JWK format.
13
22
  */
14
- bytesToPrivateKey(params: {
15
- privateKeyBytes: Uint8Array;
16
- }): Promise<Jwk>;
23
+ bytesToPrivateKey(params: BytesToPrivateKeyInput): Promise<Jwk>;
17
24
  /**
18
25
  * Converts a private key from JWK format to a byte array.
19
26
  *
@@ -22,15 +29,34 @@ export interface KeyConverter {
22
29
  *
23
30
  * @returns A Promise that resolves to the private key as a Uint8Array.
24
31
  */
25
- privateKeyToBytes(params: {
26
- privateKey: Jwk;
27
- }): Promise<Uint8Array>;
32
+ privateKeyToBytes(params: PrivateKeyToBytesInput): Promise<Uint8Array>;
28
33
  }
29
34
  /**
30
- * `AsymmetricKeyConverter` interface extends {@link KeyConverter |`KeyConverter`}, adding support
35
+ * `AsymmetricKeyConverter` interface extends {@link KeyConverter | `KeyConverter`}, adding support
31
36
  * for public key conversions.
37
+ *
38
+ * When used with default type parameters, this interface includes all four conversion methods
39
+ * (bytes-to/from private key AND bytes-to/from public key). When used with explicit type
40
+ * parameters, both the private and public key conversion types can be customized.
41
+ *
42
+ * @typeParam BytesToPublicKeyInput - The input type for `bytesToPublicKey`. Defaults to
43
+ * `{ publicKeyBytes: Uint8Array }`.
44
+ * @typeParam PublicKeyToBytesInput - The input type for `publicKeyToBytes`. Defaults to
45
+ * `{ publicKey: Jwk }`.
46
+ * @typeParam BytesToPrivateKeyInput - The input type for `bytesToPrivateKey`. Defaults to
47
+ * `{ privateKeyBytes: Uint8Array }`.
48
+ * @typeParam PrivateKeyToBytesInput - The input type for `privateKeyToBytes`. Defaults to
49
+ * `{ privateKey: Jwk }`.
32
50
  */
33
- export interface AsymmetricKeyConverter extends KeyConverter {
51
+ export interface AsymmetricKeyConverter<BytesToPublicKeyInput = {
52
+ publicKeyBytes: Uint8Array;
53
+ }, PublicKeyToBytesInput = {
54
+ publicKey: Jwk;
55
+ }, BytesToPrivateKeyInput = {
56
+ privateKeyBytes: Uint8Array;
57
+ }, PrivateKeyToBytesInput = {
58
+ privateKey: Jwk;
59
+ }> extends KeyConverter<BytesToPrivateKeyInput, PrivateKeyToBytesInput> {
34
60
  /**
35
61
  * Converts a public key from a byte array to JWK format.
36
62
  *
@@ -39,9 +65,7 @@ export interface AsymmetricKeyConverter extends KeyConverter {
39
65
  *
40
66
  * @returns A Promise that resolves to the public key in JWK format.
41
67
  */
42
- bytesToPublicKey(params: {
43
- publicKeyBytes: Uint8Array;
44
- }): Promise<Jwk>;
68
+ bytesToPublicKey(params: BytesToPublicKeyInput): Promise<Jwk>;
45
69
  /**
46
70
  * Converts a public key from JWK format to a byte array.
47
71
  *
@@ -50,8 +74,6 @@ export interface AsymmetricKeyConverter extends KeyConverter {
50
74
  *
51
75
  * @returns A Promise that resolves to the public key as a Uint8Array.
52
76
  */
53
- publicKeyToBytes(params: {
54
- publicKey: Jwk;
55
- }): Promise<Uint8Array>;
77
+ publicKeyToBytes(params: PublicKeyToBytesInput): Promise<Uint8Array>;
56
78
  }
57
79
  //# sourceMappingURL=key-converter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"key-converter.d.ts","sourceRoot":"","sources":["../../../src/types/key-converter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAE1C;;GAEG;AACH,MAAM,WAAW,YAAY;IAE3B;;;;;;;OAOG;IACH,iBAAiB,CAAC,MAAM,EAAE;QAAE,eAAe,EAAE,UAAU,CAAA;KAAE,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IAEzE;;;;;;;OAOG;IACH,iBAAiB,CAAC,MAAM,EAAE;QAAE,UAAU,EAAE,GAAG,CAAA;KAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CACrE;AAED;;;GAGG;AACH,MAAM,WAAW,sBAAuB,SAAQ,YAAY;IAC1D;;;;;;;OAOG;IACH,gBAAgB,CAAC,MAAM,EAAE;QAAE,cAAc,EAAE,UAAU,CAAA;KAAE,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IAEvE;;;;;;;OAOG;IACH,gBAAgB,CAAC,MAAM,EAAE;QAAE,SAAS,EAAE,GAAG,CAAA;KAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CACnE"}
1
+ {"version":3,"file":"key-converter.d.ts","sourceRoot":"","sources":["../../../src/types/key-converter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,E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