@enbox/agent 0.1.2 → 0.1.4

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 (224) hide show
  1. package/dist/browser.mjs +45 -52
  2. package/dist/browser.mjs.map +4 -4
  3. package/dist/esm/crypto-api.js +6 -13
  4. package/dist/esm/crypto-api.js.map +1 -1
  5. package/dist/esm/dwn-api.js +80 -78
  6. package/dist/esm/dwn-api.js.map +1 -1
  7. package/dist/esm/hd-identity-vault.js +4 -5
  8. package/dist/esm/hd-identity-vault.js.map +1 -1
  9. package/dist/esm/identity-api.js +1 -1
  10. package/dist/esm/identity-api.js.map +1 -1
  11. package/dist/esm/index.js +0 -2
  12. package/dist/esm/index.js.map +1 -1
  13. package/dist/esm/local-key-manager.js +31 -32
  14. package/dist/esm/local-key-manager.js.map +1 -1
  15. package/dist/esm/prototyping/crypto/jose/jwe-compact.js +1 -2
  16. package/dist/esm/prototyping/crypto/jose/jwe-compact.js.map +1 -1
  17. package/dist/esm/prototyping/crypto/jose/jwe-flattened.js +15 -4
  18. package/dist/esm/prototyping/crypto/jose/jwe-flattened.js.map +1 -1
  19. package/dist/esm/prototyping/crypto/jose/jwe.js +1 -1
  20. package/dist/esm/prototyping/crypto/jose/jwe.js.map +1 -1
  21. package/dist/esm/store-data.js +3 -3
  22. package/dist/esm/store-data.js.map +1 -1
  23. package/dist/esm/store-did.js +1 -1
  24. package/dist/esm/store-did.js.map +1 -1
  25. package/dist/esm/sync-engine-level.js +49 -11
  26. package/dist/esm/sync-engine-level.js.map +1 -1
  27. package/dist/esm/test-harness.js +24 -8
  28. package/dist/esm/test-harness.js.map +1 -1
  29. package/dist/esm/types/dwn.js +1 -1
  30. package/dist/esm/types/dwn.js.map +1 -1
  31. package/dist/esm/web5-user-agent.js +1 -1
  32. package/dist/esm/web5-user-agent.js.map +1 -1
  33. package/dist/types/crypto-api.d.ts +8 -12
  34. package/dist/types/crypto-api.d.ts.map +1 -1
  35. package/dist/types/dwn-api.d.ts +10 -10
  36. package/dist/types/dwn-api.d.ts.map +1 -1
  37. package/dist/types/hd-identity-vault.d.ts.map +1 -1
  38. package/dist/types/identity-api.d.ts.map +1 -1
  39. package/dist/types/index.d.ts +0 -2
  40. package/dist/types/index.d.ts.map +1 -1
  41. package/dist/types/local-key-manager.d.ts +15 -18
  42. package/dist/types/local-key-manager.d.ts.map +1 -1
  43. package/dist/types/prototyping/crypto/jose/jwe-compact.d.ts +1 -3
  44. package/dist/types/prototyping/crypto/jose/jwe-compact.d.ts.map +1 -1
  45. package/dist/types/prototyping/crypto/jose/jwe-flattened.d.ts +1 -3
  46. package/dist/types/prototyping/crypto/jose/jwe-flattened.d.ts.map +1 -1
  47. package/dist/types/prototyping/crypto/jose/jwe.d.ts +1 -3
  48. package/dist/types/prototyping/crypto/jose/jwe.d.ts.map +1 -1
  49. package/dist/types/store-data.d.ts +2 -2
  50. package/dist/types/store-did.d.ts.map +1 -1
  51. package/dist/types/sync-engine-level.d.ts +18 -6
  52. package/dist/types/sync-engine-level.d.ts.map +1 -1
  53. package/dist/types/test-harness.d.ts.map +1 -1
  54. package/dist/types/types/agent.d.ts +1 -1
  55. package/dist/types/types/agent.d.ts.map +1 -1
  56. package/dist/types/types/dwn.d.ts +2 -2
  57. package/dist/types/types/dwn.d.ts.map +1 -1
  58. package/dist/types/types/key-manager.d.ts +15 -22
  59. package/dist/types/types/key-manager.d.ts.map +1 -1
  60. package/dist/types/utils-internal.d.ts +1 -1
  61. package/dist/types/utils-internal.d.ts.map +1 -1
  62. package/dist/types/web5-user-agent.d.ts +1 -1
  63. package/dist/types/web5-user-agent.d.ts.map +1 -1
  64. package/package.json +13 -15
  65. package/src/crypto-api.ts +24 -20
  66. package/src/dwn-api.ts +109 -102
  67. package/src/hd-identity-vault.ts +4 -5
  68. package/src/identity-api.ts +2 -1
  69. package/src/index.ts +0 -2
  70. package/src/local-key-manager.ts +43 -44
  71. package/src/prototyping/crypto/jose/jwe-compact.ts +3 -7
  72. package/src/prototyping/crypto/jose/jwe-flattened.ts +20 -9
  73. package/src/prototyping/crypto/jose/jwe.ts +2 -6
  74. package/src/store-data.ts +3 -3
  75. package/src/store-did.ts +1 -1
  76. package/src/sync-engine-level.ts +59 -16
  77. package/src/test-harness.ts +23 -8
  78. package/src/types/agent.ts +1 -1
  79. package/src/types/dwn.ts +2 -2
  80. package/src/types/key-manager.ts +31 -22
  81. package/src/utils-internal.ts +1 -1
  82. package/src/web5-user-agent.ts +2 -2
  83. package/dist/browser.js +0 -2213
  84. package/dist/browser.js.map +0 -7
  85. package/dist/esm/dwn-registrar.js +0 -120
  86. package/dist/esm/dwn-registrar.js.map +0 -1
  87. package/dist/esm/prototyping/clients/dwn-rpc-types.js +0 -2
  88. package/dist/esm/prototyping/clients/dwn-rpc-types.js.map +0 -1
  89. package/dist/esm/prototyping/clients/dwn-server-info-cache-memory.js +0 -74
  90. package/dist/esm/prototyping/clients/dwn-server-info-cache-memory.js.map +0 -1
  91. package/dist/esm/prototyping/clients/http-dwn-rpc-client.js +0 -112
  92. package/dist/esm/prototyping/clients/http-dwn-rpc-client.js.map +0 -1
  93. package/dist/esm/prototyping/clients/json-rpc-socket.js +0 -167
  94. package/dist/esm/prototyping/clients/json-rpc-socket.js.map +0 -1
  95. package/dist/esm/prototyping/clients/json-rpc.js +0 -58
  96. package/dist/esm/prototyping/clients/json-rpc.js.map +0 -1
  97. package/dist/esm/prototyping/clients/server-info-types.js +0 -2
  98. package/dist/esm/prototyping/clients/server-info-types.js.map +0 -1
  99. package/dist/esm/prototyping/clients/web-socket-clients.js +0 -90
  100. package/dist/esm/prototyping/clients/web-socket-clients.js.map +0 -1
  101. package/dist/esm/prototyping/common/object.js +0 -14
  102. package/dist/esm/prototyping/common/object.js.map +0 -1
  103. package/dist/esm/prototyping/common/type-utils.js +0 -2
  104. package/dist/esm/prototyping/common/type-utils.js.map +0 -1
  105. package/dist/esm/prototyping/crypto/algorithms/aes-gcm.js +0 -147
  106. package/dist/esm/prototyping/crypto/algorithms/aes-gcm.js.map +0 -1
  107. package/dist/esm/prototyping/crypto/algorithms/aes-kw.js +0 -136
  108. package/dist/esm/prototyping/crypto/algorithms/aes-kw.js.map +0 -1
  109. package/dist/esm/prototyping/crypto/algorithms/ecdsa.js +0 -311
  110. package/dist/esm/prototyping/crypto/algorithms/ecdsa.js.map +0 -1
  111. package/dist/esm/prototyping/crypto/algorithms/eddsa.js +0 -268
  112. package/dist/esm/prototyping/crypto/algorithms/eddsa.js.map +0 -1
  113. package/dist/esm/prototyping/crypto/algorithms/hkdf.js +0 -38
  114. package/dist/esm/prototyping/crypto/algorithms/hkdf.js.map +0 -1
  115. package/dist/esm/prototyping/crypto/algorithms/pbkdf2.js +0 -40
  116. package/dist/esm/prototyping/crypto/algorithms/pbkdf2.js.map +0 -1
  117. package/dist/esm/prototyping/crypto/crypto-error.js +0 -41
  118. package/dist/esm/prototyping/crypto/crypto-error.js.map +0 -1
  119. package/dist/esm/prototyping/crypto/types/crypto-api.js +0 -2
  120. package/dist/esm/prototyping/crypto/types/crypto-api.js.map +0 -1
  121. package/dist/esm/prototyping/crypto/types/key-converter.js +0 -2
  122. package/dist/esm/prototyping/crypto/types/key-converter.js.map +0 -1
  123. package/dist/esm/prototyping/crypto/types/key-deriver.js +0 -2
  124. package/dist/esm/prototyping/crypto/types/key-deriver.js.map +0 -1
  125. package/dist/esm/prototyping/crypto/types/key-io.js +0 -2
  126. package/dist/esm/prototyping/crypto/types/key-io.js.map +0 -1
  127. package/dist/esm/prototyping/crypto/types/key-manager.js +0 -2
  128. package/dist/esm/prototyping/crypto/types/key-manager.js.map +0 -1
  129. package/dist/esm/prototyping/crypto/types/params-direct.js +0 -2
  130. package/dist/esm/prototyping/crypto/types/params-direct.js.map +0 -1
  131. package/dist/esm/prototyping/crypto/types/params-kms.js +0 -2
  132. package/dist/esm/prototyping/crypto/types/params-kms.js.map +0 -1
  133. package/dist/esm/prototyping/crypto/utils.js +0 -19
  134. package/dist/esm/prototyping/crypto/utils.js.map +0 -1
  135. package/dist/esm/prototyping/dids/resolver-cache-memory.js +0 -77
  136. package/dist/esm/prototyping/dids/resolver-cache-memory.js.map +0 -1
  137. package/dist/esm/prototyping/dids/utils.js +0 -9
  138. package/dist/esm/prototyping/dids/utils.js.map +0 -1
  139. package/dist/esm/rpc-client.js +0 -123
  140. package/dist/esm/rpc-client.js.map +0 -1
  141. package/dist/types/dwn-registrar.d.ts +0 -29
  142. package/dist/types/dwn-registrar.d.ts.map +0 -1
  143. package/dist/types/prototyping/clients/dwn-rpc-types.d.ts +0 -45
  144. package/dist/types/prototyping/clients/dwn-rpc-types.d.ts.map +0 -1
  145. package/dist/types/prototyping/clients/dwn-server-info-cache-memory.d.ts +0 -57
  146. package/dist/types/prototyping/clients/dwn-server-info-cache-memory.d.ts.map +0 -1
  147. package/dist/types/prototyping/clients/http-dwn-rpc-client.d.ts +0 -13
  148. package/dist/types/prototyping/clients/http-dwn-rpc-client.d.ts.map +0 -1
  149. package/dist/types/prototyping/clients/json-rpc-socket.d.ts +0 -43
  150. package/dist/types/prototyping/clients/json-rpc-socket.d.ts.map +0 -1
  151. package/dist/types/prototyping/clients/json-rpc.d.ts +0 -49
  152. package/dist/types/prototyping/clients/json-rpc.d.ts.map +0 -1
  153. package/dist/types/prototyping/clients/server-info-types.d.ts +0 -20
  154. package/dist/types/prototyping/clients/server-info-types.d.ts.map +0 -1
  155. package/dist/types/prototyping/clients/web-socket-clients.d.ts +0 -10
  156. package/dist/types/prototyping/clients/web-socket-clients.d.ts.map +0 -1
  157. package/dist/types/prototyping/common/object.d.ts +0 -2
  158. package/dist/types/prototyping/common/object.d.ts.map +0 -1
  159. package/dist/types/prototyping/common/type-utils.d.ts +0 -7
  160. package/dist/types/prototyping/common/type-utils.d.ts.map +0 -1
  161. package/dist/types/prototyping/crypto/algorithms/aes-gcm.d.ts +0 -151
  162. package/dist/types/prototyping/crypto/algorithms/aes-gcm.d.ts.map +0 -1
  163. package/dist/types/prototyping/crypto/algorithms/aes-kw.d.ts +0 -108
  164. package/dist/types/prototyping/crypto/algorithms/aes-kw.d.ts.map +0 -1
  165. package/dist/types/prototyping/crypto/algorithms/ecdsa.d.ts +0 -160
  166. package/dist/types/prototyping/crypto/algorithms/ecdsa.d.ts.map +0 -1
  167. package/dist/types/prototyping/crypto/algorithms/eddsa.d.ts +0 -157
  168. package/dist/types/prototyping/crypto/algorithms/eddsa.d.ts.map +0 -1
  169. package/dist/types/prototyping/crypto/algorithms/hkdf.d.ts +0 -20
  170. package/dist/types/prototyping/crypto/algorithms/hkdf.d.ts.map +0 -1
  171. package/dist/types/prototyping/crypto/algorithms/pbkdf2.d.ts +0 -20
  172. package/dist/types/prototyping/crypto/algorithms/pbkdf2.d.ts.map +0 -1
  173. package/dist/types/prototyping/crypto/crypto-error.d.ts +0 -29
  174. package/dist/types/prototyping/crypto/crypto-error.d.ts.map +0 -1
  175. package/dist/types/prototyping/crypto/types/crypto-api.d.ts +0 -34
  176. package/dist/types/prototyping/crypto/types/crypto-api.d.ts.map +0 -1
  177. package/dist/types/prototyping/crypto/types/key-converter.d.ts +0 -49
  178. package/dist/types/prototyping/crypto/types/key-converter.d.ts.map +0 -1
  179. package/dist/types/prototyping/crypto/types/key-deriver.d.ts +0 -50
  180. package/dist/types/prototyping/crypto/types/key-deriver.d.ts.map +0 -1
  181. package/dist/types/prototyping/crypto/types/key-io.d.ts +0 -49
  182. package/dist/types/prototyping/crypto/types/key-io.d.ts.map +0 -1
  183. package/dist/types/prototyping/crypto/types/key-manager.d.ts +0 -69
  184. package/dist/types/prototyping/crypto/types/key-manager.d.ts.map +0 -1
  185. package/dist/types/prototyping/crypto/types/params-direct.d.ts +0 -75
  186. package/dist/types/prototyping/crypto/types/params-direct.d.ts.map +0 -1
  187. package/dist/types/prototyping/crypto/types/params-kms.d.ts +0 -63
  188. package/dist/types/prototyping/crypto/types/params-kms.d.ts.map +0 -1
  189. package/dist/types/prototyping/crypto/utils.d.ts +0 -7
  190. package/dist/types/prototyping/crypto/utils.d.ts.map +0 -1
  191. package/dist/types/prototyping/dids/resolver-cache-memory.d.ts +0 -57
  192. package/dist/types/prototyping/dids/resolver-cache-memory.d.ts.map +0 -1
  193. package/dist/types/prototyping/dids/utils.d.ts +0 -3
  194. package/dist/types/prototyping/dids/utils.d.ts.map +0 -1
  195. package/dist/types/rpc-client.d.ts +0 -51
  196. package/dist/types/rpc-client.d.ts.map +0 -1
  197. package/src/dwn-registrar.ts +0 -127
  198. package/src/prototyping/clients/dwn-rpc-types.ts +0 -55
  199. package/src/prototyping/clients/dwn-server-info-cache-memory.ts +0 -79
  200. package/src/prototyping/clients/http-dwn-rpc-client.ts +0 -119
  201. package/src/prototyping/clients/json-rpc-socket.ts +0 -189
  202. package/src/prototyping/clients/json-rpc.ts +0 -113
  203. package/src/prototyping/clients/server-info-types.ts +0 -21
  204. package/src/prototyping/clients/web-socket-clients.ts +0 -103
  205. package/src/prototyping/common/object.ts +0 -15
  206. package/src/prototyping/common/type-utils.ts +0 -6
  207. package/src/prototyping/crypto/algorithms/aes-gcm.ts +0 -211
  208. package/src/prototyping/crypto/algorithms/aes-kw.ts +0 -160
  209. package/src/prototyping/crypto/algorithms/ecdsa.ts +0 -366
  210. package/src/prototyping/crypto/algorithms/eddsa.ts +0 -311
  211. package/src/prototyping/crypto/algorithms/hkdf.ts +0 -38
  212. package/src/prototyping/crypto/algorithms/pbkdf2.ts +0 -41
  213. package/src/prototyping/crypto/crypto-error.ts +0 -45
  214. package/src/prototyping/crypto/types/crypto-api.ts +0 -77
  215. package/src/prototyping/crypto/types/key-converter.ts +0 -53
  216. package/src/prototyping/crypto/types/key-deriver.ts +0 -56
  217. package/src/prototyping/crypto/types/key-io.ts +0 -51
  218. package/src/prototyping/crypto/types/key-manager.ts +0 -83
  219. package/src/prototyping/crypto/types/params-direct.ts +0 -95
  220. package/src/prototyping/crypto/types/params-kms.ts +0 -76
  221. package/src/prototyping/crypto/utils.ts +0 -41
  222. package/src/prototyping/dids/resolver-cache-memory.ts +0 -83
  223. package/src/prototyping/dids/utils.ts +0 -10
  224. package/src/rpc-client.ts +0 -160
@@ -1,311 +0,0 @@
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 { CryptoAlgorithm, isEcPrivateJwk, isEcPublicJwk, Secp256k1, Secp256r1 } from '@enbox/crypto';
11
- import { CryptoError, CryptoErrorCode } from '../crypto-error.js';
12
- /**
13
- * The `EcdsaAlgorithm` class provides a concrete implementation for cryptographic operations using
14
- * the Elliptic Curve Digital Signature Algorithm (ECDSA). This class implements both
15
- * {@link Signer | `Signer`} and { @link AsymmetricKeyGenerator | `AsymmetricKeyGenerator`}
16
- * interfaces, providing private key generation, public key derivation, and creation/verification
17
- * of signatures.
18
- *
19
- * This class is typically accessed through implementations that extend the
20
- * {@link CryptoApi | `CryptoApi`} interface.
21
- */
22
- export class EcdsaAlgorithm extends CryptoAlgorithm {
23
- bytesToPrivateKey(_a) {
24
- return __awaiter(this, arguments, void 0, function* ({ algorithm, privateKeyBytes }) {
25
- switch (algorithm) {
26
- case 'ES256K':
27
- case 'secp256k1': {
28
- const privateKey = yield Secp256k1.bytesToPrivateKey({ privateKeyBytes });
29
- privateKey.alg = 'EdDSA';
30
- return privateKey;
31
- }
32
- case 'ES256':
33
- case 'secp256r1': {
34
- const privateKey = yield Secp256r1.bytesToPrivateKey({ privateKeyBytes });
35
- privateKey.alg = 'EdDSA';
36
- return privateKey;
37
- }
38
- default: {
39
- throw new CryptoError(CryptoErrorCode.AlgorithmNotSupported, `Algorithm not supported: ${algorithm}`);
40
- }
41
- }
42
- });
43
- }
44
- bytesToPublicKey(_a) {
45
- return __awaiter(this, arguments, void 0, function* ({ algorithm, publicKeyBytes }) {
46
- switch (algorithm) {
47
- case 'ES256K':
48
- case 'secp256k1': {
49
- const publicKey = yield Secp256k1.bytesToPublicKey({ publicKeyBytes });
50
- publicKey.alg = 'EdDSA';
51
- return publicKey;
52
- }
53
- case 'ES256':
54
- case 'secp256r1': {
55
- const publicKey = yield Secp256r1.bytesToPublicKey({ publicKeyBytes });
56
- publicKey.alg = 'EdDSA';
57
- return publicKey;
58
- }
59
- default: {
60
- throw new CryptoError(CryptoErrorCode.AlgorithmNotSupported, `Algorithm not supported: ${algorithm}`);
61
- }
62
- }
63
- });
64
- }
65
- /**
66
- * Derives the public key in JWK format from a given private key.
67
- *
68
- * @remarks
69
- * This method takes a private key in JWK format and derives its corresponding public key,
70
- * also in JWK format. The process ensures that the derived public key correctly corresponds to
71
- * the given private key.
72
- *
73
- * @example
74
- * ```ts
75
- * const ecdsa = new EcdsaAlgorithm();
76
- * const privateKey = { ... }; // A Jwk object representing a private key
77
- * const publicKey = await ecdsa.computePublicKey({ key: privateKey });
78
- * ```
79
- *
80
- * @param params - The parameters for the public key derivation.
81
- * @param params.key - The private key in JWK format from which to derive the public key.
82
- *
83
- * @returns A Promise that resolves to the derived public key in JWK format.
84
- */
85
- computePublicKey(_a) {
86
- return __awaiter(this, arguments, void 0, function* ({ key }) {
87
- if (!isEcPrivateJwk(key)) {
88
- throw new TypeError('Invalid key provided. Must be an elliptic curve (EC) private key.');
89
- }
90
- switch (key.crv) {
91
- case 'secp256k1': {
92
- const publicKey = yield Secp256k1.computePublicKey({ key });
93
- publicKey.alg = 'ES256K';
94
- return publicKey;
95
- }
96
- case 'P-256': {
97
- const publicKey = yield Secp256r1.computePublicKey({ key });
98
- publicKey.alg = 'ES256';
99
- return publicKey;
100
- }
101
- default: {
102
- throw new Error(`Unsupported curve: ${key.crv}`);
103
- }
104
- }
105
- });
106
- }
107
- /**
108
- * Generates a new private key with the specified algorithm in JSON Web Key (JWK) format.
109
- *
110
- * @example
111
- * ```ts
112
- * const ecdsa = new EcdsaAlgorithm();
113
- * const privateKey = await ecdsa.generateKey({ algorithm: 'ES256K' });
114
- * ```
115
- *
116
- * @param params - The parameters for key generation.
117
- * @param params.algorithm - The algorithm to use for key generation.
118
- *
119
- * @returns A Promise that resolves to the generated private key in JWK format.
120
- */
121
- generateKey(_a) {
122
- return __awaiter(this, arguments, void 0, function* ({ algorithm }) {
123
- switch (algorithm) {
124
- case 'ES256K':
125
- case 'secp256k1': {
126
- const privateKey = yield Secp256k1.generateKey();
127
- privateKey.alg = 'ES256K';
128
- return privateKey;
129
- }
130
- case 'ES256':
131
- case 'secp256r1': {
132
- const privateKey = yield Secp256r1.generateKey();
133
- privateKey.alg = 'ES256';
134
- return privateKey;
135
- }
136
- }
137
- });
138
- }
139
- /**
140
- * Retrieves the public key properties from a given private key in JWK format.
141
- *
142
- * @remarks
143
- * This method extracts the public key portion from an ECDSA private key in JWK format. It does
144
- * so by removing the private key property 'd' and making a shallow copy, effectively yielding the
145
- * public key.
146
- *
147
- * Note: This method offers a significant performance advantage, being about 200 times faster
148
- * than `computePublicKey()`. However, it does not mathematically validate the private key, nor
149
- * does it derive the public key from the private key. It simply extracts existing public key
150
- * properties from the private key object. This makes it suitable for scenarios where speed is
151
- * critical and the private key's integrity is already assured.
152
- *
153
- * @example
154
- * ```ts
155
- * const ecdsa = new EcdsaAlgorithm();
156
- * const privateKey = { ... }; // A Jwk object representing a private key
157
- * const publicKey = await ecdsa.getPublicKey({ key: privateKey });
158
- * ```
159
- *
160
- * @param params - The parameters for retrieving the public key properties.
161
- * @param params.key - The private key in JWK format.
162
- *
163
- * @returns A Promise that resolves to the public key in JWK format.
164
- */
165
- getPublicKey(_a) {
166
- return __awaiter(this, arguments, void 0, function* ({ key }) {
167
- if (!isEcPrivateJwk(key)) {
168
- throw new TypeError('Invalid key provided. Must be an elliptic curve (EC) private key.');
169
- }
170
- switch (key.crv) {
171
- case 'secp256k1': {
172
- const publicKey = yield Secp256k1.getPublicKey({ key });
173
- publicKey.alg = 'ES256K';
174
- return publicKey;
175
- }
176
- case 'P-256': {
177
- const publicKey = yield Secp256r1.getPublicKey({ key });
178
- publicKey.alg = 'ES256';
179
- return publicKey;
180
- }
181
- default: {
182
- throw new Error(`Unsupported curve: ${key.crv}`);
183
- }
184
- }
185
- });
186
- }
187
- privateKeyToBytes(_a) {
188
- return __awaiter(this, arguments, void 0, function* ({ privateKey }) {
189
- switch (privateKey.crv) {
190
- case 'secp256k1': {
191
- return yield Secp256k1.privateKeyToBytes({ privateKey });
192
- }
193
- case 'P-256': {
194
- return yield Secp256r1.privateKeyToBytes({ privateKey });
195
- }
196
- default: {
197
- throw new CryptoError(CryptoErrorCode.AlgorithmNotSupported, `Curve not supported: ${privateKey.crv}`);
198
- }
199
- }
200
- });
201
- }
202
- publicKeyToBytes(_a) {
203
- return __awaiter(this, arguments, void 0, function* ({ publicKey }) {
204
- switch (publicKey.crv) {
205
- case 'secp256k1': {
206
- return yield Secp256k1.publicKeyToBytes({ publicKey });
207
- }
208
- case 'P-256': {
209
- return yield Secp256r1.publicKeyToBytes({ publicKey });
210
- }
211
- default: {
212
- throw new CryptoError(CryptoErrorCode.AlgorithmNotSupported, `Curve not supported: ${publicKey.crv}`);
213
- }
214
- }
215
- });
216
- }
217
- /**
218
- * Generates an ECDSA signature of given data using a private key.
219
- *
220
- * @remarks
221
- * This method uses the signature algorithm determined by the given `algorithm` to sign the
222
- * provided data.
223
- *
224
- * The signature can later be verified by parties with access to the corresponding
225
- * public key, ensuring that the data has not been tampered with and was indeed signed by the
226
- * holder of the private key.
227
- *
228
- * @example
229
- * ```ts
230
- * const ecdsa = new EcdsaAlgorithm();
231
- * const data = new TextEncoder().encode('Message');
232
- * const privateKey = { ... }; // A Jwk object representing a private key
233
- * const signature = await ecdsa.sign({
234
- * key: privateKey,
235
- * data
236
- * });
237
- * ```
238
- *
239
- * @param params - The parameters for the signing operation.
240
- * @param params.key - The private key to use for signing, represented in JWK format.
241
- * @param params.data - The data to sign.
242
- *
243
- * @returns A Promise resolving to the digital signature as a `Uint8Array`.
244
- */
245
- sign(_a) {
246
- return __awaiter(this, arguments, void 0, function* ({ key, data }) {
247
- if (!isEcPrivateJwk(key)) {
248
- throw new TypeError('Invalid key provided. Must be an elliptic curve (EC) private key.');
249
- }
250
- switch (key.crv) {
251
- case 'secp256k1': {
252
- return yield Secp256k1.sign({ key, data });
253
- }
254
- case 'P-256': {
255
- return yield Secp256r1.sign({ key, data });
256
- }
257
- default: {
258
- throw new Error(`Unsupported curve: ${key.crv}`);
259
- }
260
- }
261
- });
262
- }
263
- /**
264
- * Verifies an ECDSA signature associated with the provided data using the provided key.
265
- *
266
- * @remarks
267
- * This method uses the signature algorithm determined by the `crv` property of the provided key
268
- * to check the validity of a digital signature against the original data. It confirms whether the
269
- * signature was created by the holder of the corresponding private key and that the data has not
270
- * been tampered with.
271
- *s
272
- * @example
273
- * ```ts
274
- * const ecdsa = new EcdsaAlgorithm();
275
- * const publicKey = { ... }; // Public key in JWK format corresponding to the private key that signed the data
276
- * const signature = new Uint8Array([...]); // Signature to verify
277
- * const data = new TextEncoder().encode('Message');
278
- * const isValid = await ecdsa.verify({
279
- * key: publicKey,
280
- * signature,
281
- * data
282
- * });
283
- * ```
284
- *
285
- * @param params - The parameters for the verification operation.
286
- * @param params.key - The key to use for verification.
287
- * @param params.signature - The signature to verify.
288
- * @param params.data - The data to verify.
289
- *
290
- * @returns A Promise resolving to a boolean indicating whether the signature is valid.
291
- */
292
- verify(_a) {
293
- return __awaiter(this, arguments, void 0, function* ({ key, signature, data }) {
294
- if (!isEcPublicJwk(key)) {
295
- throw new TypeError('Invalid key provided. Must be an elliptic curve (EC) public key.');
296
- }
297
- switch (key.crv) {
298
- case 'secp256k1': {
299
- return yield Secp256k1.verify({ key, signature, data });
300
- }
301
- case 'P-256': {
302
- return yield Secp256r1.verify({ key, signature, data });
303
- }
304
- default: {
305
- throw new Error(`Unsupported curve: ${key.crv}`);
306
- }
307
- }
308
- });
309
- }
310
- }
311
- //# sourceMappingURL=ecdsa.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ecdsa.js","sourceRoot":"","sources":["../../../../../src/prototyping/crypto/algorithms/ecdsa.ts"],"names":[],"mappings":";;;;;;;;;AAaA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,aAAa,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAGrG,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAiBlE;;;;;;;;;GASG;AACH,MAAM,OAAO,cAAe,SAAQ,eAAe;IAKpC,iBAAiB;6DAAC,EAAE,SAAS,EAAE,eAAe,EAC8B;YAEvF,QAAQ,SAAS,EAAE,CAAC;gBAElB,KAAK,QAAQ,CAAC;gBACd,KAAK,WAAW,CAAC,CAAC,CAAC;oBACjB,MAAM,UAAU,GAAG,MAAM,SAAS,CAAC,iBAAiB,CAAC,EAAE,eAAe,EAAE,CAAC,CAAC;oBAC1E,UAAU,CAAC,GAAG,GAAG,OAAO,CAAC;oBACzB,OAAO,UAAU,CAAC;gBACpB,CAAC;gBAED,KAAK,OAAO,CAAC;gBACb,KAAK,WAAW,CAAC,CAAC,CAAC;oBACjB,MAAM,UAAU,GAAG,MAAM,SAAS,CAAC,iBAAiB,CAAC,EAAE,eAAe,EAAE,CAAC,CAAC;oBAC1E,UAAU,CAAC,GAAG,GAAG,OAAO,CAAC;oBACzB,OAAO,UAAU,CAAC;gBACpB,CAAC;gBAED,OAAO,CAAC,CAAC,CAAC;oBACR,MAAM,IAAI,WAAW,CAAC,eAAe,CAAC,qBAAqB,EAAE,4BAA4B,SAAS,EAAE,CAAC,CAAC;gBACxG,CAAC;YACH,CAAC;QACH,CAAC;KAAA;IAEY,gBAAgB;6DAAC,EAAE,SAAS,EAAE,cAAc,EAC+B;YAEt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AAM,SAAS,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;gBAC1D,CAAC;gBAED,OAAO,CAAC,CAAC,CAAC;oBACR,MAAM,IAAI,KAAK,CAAC,sBAAsB,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC;gBACnD,CAAC;YACH,CAAC;QACH,CAAC;KAAA;CACF"}
@@ -1,268 +0,0 @@
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 { CryptoAlgorithm, Ed25519, isOkpPrivateJwk, isOkpPublicJwk } from '@enbox/crypto';
11
- import { CryptoError, CryptoErrorCode } from '../crypto-error.js';
12
- /**
13
- * The `EdDsaAlgorithm` class provides a concrete implementation for cryptographic operations using
14
- * the Edwards-curve Digital Signature Algorithm (EdDSA). This class implements both
15
- * {@link Signer | `Signer`} and { @link AsymmetricKeyGenerator | `AsymmetricKeyGenerator`}
16
- * interfaces, providing private key generation, public key derivation, and creation/verification
17
- * of signatures.
18
- *
19
- * This class is typically accessed through implementations that extend the
20
- * {@link CryptoApi | `CryptoApi`} interface.
21
- */
22
- export class EdDsaAlgorithm extends CryptoAlgorithm {
23
- bytesToPrivateKey(_a) {
24
- return __awaiter(this, arguments, void 0, function* ({ algorithm, privateKeyBytes }) {
25
- switch (algorithm) {
26
- case 'Ed25519': {
27
- const privateKey = yield Ed25519.bytesToPrivateKey({ privateKeyBytes });
28
- privateKey.alg = 'EdDSA';
29
- return privateKey;
30
- }
31
- default: {
32
- throw new CryptoError(CryptoErrorCode.AlgorithmNotSupported, `Algorithm not supported: ${algorithm}`);
33
- }
34
- }
35
- });
36
- }
37
- bytesToPublicKey(_a) {
38
- return __awaiter(this, arguments, void 0, function* ({ algorithm, publicKeyBytes }) {
39
- switch (algorithm) {
40
- case 'Ed25519': {
41
- const publicKey = yield Ed25519.bytesToPublicKey({ publicKeyBytes });
42
- publicKey.alg = 'EdDSA';
43
- return publicKey;
44
- }
45
- default: {
46
- throw new CryptoError(CryptoErrorCode.AlgorithmNotSupported, `Algorithm not supported: ${algorithm}`);
47
- }
48
- }
49
- });
50
- }
51
- /**
52
- * Derives the public key in JWK format from a given private key.
53
- *
54
- * @remarks
55
- * This method takes a private key in JWK format and derives its corresponding public key,
56
- * also in JWK format. The process ensures that the derived public key correctly corresponds to
57
- * the given private key.
58
- *
59
- * @example
60
- * ```ts
61
- * const eddsa = new EdDsaAlgorithm();
62
- * const privateKey = { ... }; // A Jwk object representing a private key
63
- * const publicKey = await eddsa.computePublicKey({ key: privateKey });
64
- * ```
65
- *
66
- * @param params - The parameters for the public key derivation.
67
- * @param params.key - The private key in JWK format from which to derive the public key.
68
- *
69
- * @returns A Promise that resolves to the derived public key in JWK format.
70
- */
71
- computePublicKey(_a) {
72
- return __awaiter(this, arguments, void 0, function* ({ key }) {
73
- if (!isOkpPrivateJwk(key)) {
74
- throw new TypeError('Invalid key provided. Must be an octet key pair (OKP) private key.');
75
- }
76
- switch (key.crv) {
77
- case 'Ed25519': {
78
- const publicKey = yield Ed25519.computePublicKey({ key });
79
- publicKey.alg = 'EdDSA';
80
- return publicKey;
81
- }
82
- default: {
83
- throw new CryptoError(CryptoErrorCode.AlgorithmNotSupported, `Curve not supported: ${key.crv}`);
84
- }
85
- }
86
- });
87
- }
88
- /**
89
- * Generates a new private key with the specified algorithm in JSON Web Key (JWK) format.
90
- *
91
- * @example
92
- * ```ts
93
- * const eddsa = new EdDsaAlgorithm();
94
- * const privateKey = await eddsa.generateKey({ algorithm: 'Ed25519' });
95
- * ```
96
- *
97
- * @param params - The parameters for key generation.
98
- * @param params.algorithm - The algorithm to use for key generation.
99
- *
100
- * @returns A Promise that resolves to the generated private key in JWK format.
101
- */
102
- generateKey(_a) {
103
- return __awaiter(this, arguments, void 0, function* ({ algorithm }) {
104
- switch (algorithm) {
105
- case 'Ed25519': {
106
- const privateKey = yield Ed25519.generateKey();
107
- privateKey.alg = 'EdDSA';
108
- return privateKey;
109
- }
110
- }
111
- });
112
- }
113
- /**
114
- * Retrieves the public key properties from a given private key in JWK format.
115
- *
116
- * @remarks
117
- * This method extracts the public key portion from an EdDSA private key in JWK format. It does
118
- * so by removing the private key property 'd' and making a shallow copy, effectively yielding the
119
- * public key.
120
- *
121
- * Note: This method offers a significant performance advantage, being about 100 times faster
122
- * than `computePublicKey()`. However, it does not mathematically validate the private key, nor
123
- * does it derive the public key from the private key. It simply extracts existing public key
124
- * properties from the private key object. This makes it suitable for scenarios where speed is
125
- * critical and the private key's integrity is already assured.
126
- *
127
- * @example
128
- * ```ts
129
- * const eddsa = new EdDsaAlgorithm();
130
- * const privateKey = { ... }; // A Jwk object representing a private key
131
- * const publicKey = await eddsa.getPublicKey({ key: privateKey });
132
- * ```
133
- *
134
- * @param params - The parameters for retrieving the public key properties.
135
- * @param params.key - The private key in JWK format.
136
- *
137
- * @returns A Promise that resolves to the public key in JWK format.
138
- */
139
- getPublicKey(_a) {
140
- return __awaiter(this, arguments, void 0, function* ({ key }) {
141
- if (!isOkpPrivateJwk(key)) {
142
- throw new TypeError('Invalid key provided. Must be an octet key pair (OKP) private key.');
143
- }
144
- switch (key.crv) {
145
- case 'Ed25519': {
146
- const publicKey = yield Ed25519.getPublicKey({ key });
147
- publicKey.alg = 'EdDSA';
148
- return publicKey;
149
- }
150
- default: {
151
- throw new Error(`Unsupported curve: ${key.crv}`);
152
- }
153
- }
154
- });
155
- }
156
- privateKeyToBytes(_a) {
157
- return __awaiter(this, arguments, void 0, function* ({ privateKey }) {
158
- switch (privateKey.crv) {
159
- case 'Ed25519': {
160
- return yield Ed25519.privateKeyToBytes({ privateKey });
161
- }
162
- default: {
163
- throw new CryptoError(CryptoErrorCode.AlgorithmNotSupported, `Curve not supported: ${privateKey.crv}`);
164
- }
165
- }
166
- });
167
- }
168
- publicKeyToBytes(_a) {
169
- return __awaiter(this, arguments, void 0, function* ({ publicKey }) {
170
- switch (publicKey.crv) {
171
- case 'Ed25519': {
172
- return yield Ed25519.publicKeyToBytes({ publicKey });
173
- }
174
- default: {
175
- throw new CryptoError(CryptoErrorCode.AlgorithmNotSupported, `Curve not supported: ${publicKey.crv}`);
176
- }
177
- }
178
- });
179
- }
180
- /**
181
- * Generates an EdDSA signature of given data using a private key.
182
- *
183
- * @remarks
184
- * This method uses the signature algorithm determined by the given `algorithm` to sign the
185
- * provided data.
186
- *
187
- * The signature can later be verified by parties with access to the corresponding
188
- * public key, ensuring that the data has not been tampered with and was indeed signed by the
189
- * holder of the private key.
190
- *
191
- * @example
192
- * ```ts
193
- * const eddsa = new EdDsaAlgorithm();
194
- * const data = new TextEncoder().encode('Message');
195
- * const privateKey = { ... }; // A Jwk object representing a private key
196
- * const signature = await eddsa.sign({
197
- * key: privateKey,
198
- * data
199
- * });
200
- * ```
201
- *
202
- * @param params - The parameters for the signing operation.
203
- * @param params.key - The private key to use for signing, represented in JWK format.
204
- * @param params.data - The data to sign.
205
- *
206
- * @returns A Promise resolving to the digital signature as a `Uint8Array`.
207
- */
208
- sign(_a) {
209
- return __awaiter(this, arguments, void 0, function* ({ key, data }) {
210
- if (!isOkpPrivateJwk(key)) {
211
- throw new TypeError('Invalid key provided. Must be an octet key pair (OKP) private key.');
212
- }
213
- switch (key.crv) {
214
- case 'Ed25519': {
215
- return yield Ed25519.sign({ key, data });
216
- }
217
- default: {
218
- throw new CryptoError(CryptoErrorCode.AlgorithmNotSupported, `Curve not supported: ${key.crv}`);
219
- }
220
- }
221
- });
222
- }
223
- /**
224
- * Verifies an EdDSA signature associated with the provided data using the provided key.
225
- *
226
- * @remarks
227
- * This method uses the signature algorithm determined by the `crv` property of the provided key
228
- * to check the validity of a digital signature against the original data. It confirms whether the
229
- * signature was created by the holder of the corresponding private key and that the data has not
230
- * been tampered with.
231
- *s
232
- * @example
233
- * ```ts
234
- * const eddsa = new EdDsaAlgorithm();
235
- * const publicKey = { ... }; // Public key in JWK format corresponding to the private key that signed the data
236
- * const signature = new Uint8Array([...]); // Signature to verify
237
- * const data = new TextEncoder().encode('Message');
238
- * const isValid = await eddsa.verify({
239
- * key: publicKey,
240
- * signature,
241
- * data
242
- * });
243
- * ```
244
- *
245
- * @param params - The parameters for the verification operation.
246
- * @param params.key - The key to use for verification.
247
- * @param params.signature - The signature to verify.
248
- * @param params.data - The data to verify.
249
- *
250
- * @returns A Promise resolving to a boolean indicating whether the signature is valid.
251
- */
252
- verify(_a) {
253
- return __awaiter(this, arguments, void 0, function* ({ key, signature, data }) {
254
- if (!isOkpPublicJwk(key)) {
255
- throw new TypeError('Invalid key provided. Must be an octet key pair (OKP) public key.');
256
- }
257
- switch (key.crv) {
258
- case 'Ed25519': {
259
- return yield Ed25519.verify({ key, signature, data });
260
- }
261
- default: {
262
- throw new CryptoError(CryptoErrorCode.AlgorithmNotSupported, `Curve not supported: ${key.crv}`);
263
- }
264
- }
265
- });
266
- }
267
- }
268
- //# sourceMappingURL=eddsa.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"eddsa.js","sourceRoot":"","sources":["../../../../../src/prototyping/crypto/algorithms/eddsa.ts"],"names":[],"mappings":";;;;;;;;;AAaA,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAG1F,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAclE;;;;;;;;;GASG;AACH,MAAM,OAAO,cAAe,SAAQ,eAAe;IAKpC,iBAAiB;6DAAC,EAAE,SAAS,EAAE,eAAe,EACP;YAElD,QAAQ,SAAS,EAAE,CAAC;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MAAM;6DAAC,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,EAC5B;YAEZ,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC;gBAAA,MAAM,IAAI,SAAS,CAAC,mEAAmE,CAAC,CAAC;YAAA,CAAC;YAErH,QAAQ,GAAG,CAAC,GAAG,EAAE,CAAC;gBAEhB,KAAK,SAAS,CAAC,CAAC,CAAC;oBACf,OAAO,MAAM,OAAO,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;gBACxD,CAAC;gBAED,OAAO,CAAC,CAAC,CAAC;oBACR,MAAM,IAAI,WAAW,CAAC,eAAe,CAAC,qBAAqB,EAAE,wBAAwB,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC;gBAClG,CAAC;YACH,CAAC;QACH,CAAC;KAAA;CACF"}
@@ -1,38 +0,0 @@
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
- var __rest = (this && this.__rest) || function (s, e) {
11
- var t = {};
12
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
13
- t[p] = s[p];
14
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
15
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
16
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
17
- t[p[i]] = s[p[i]];
18
- }
19
- return t;
20
- };
21
- import { CryptoAlgorithm, Hkdf } from '@enbox/crypto';
22
- export class HkdfAlgorithm extends CryptoAlgorithm {
23
- deriveKeyBytes(_a) {
24
- return __awaiter(this, void 0, void 0, function* () {
25
- var { algorithm } = _a, params = __rest(_a, ["algorithm"]);
26
- // Map algorithm name to hash function.
27
- const hash = {
28
- 'HKDF-256': 'SHA-256',
29
- 'HKDF-384': 'SHA-384',
30
- 'HKDF-512': 'SHA-512'
31
- }[algorithm];
32
- // Derive a cryptographic byte array using HKDF.
33
- const derivedKeyBytes = yield Hkdf.deriveKeyBytes(Object.assign(Object.assign({}, params), { hash }));
34
- return derivedKeyBytes;
35
- });
36
- }
37
- }
38
- //# sourceMappingURL=hkdf.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hkdf.js","sourceRoot":"","sources":["../../../../../src/prototyping/crypto/algorithms/hkdf.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAGA,OAAO,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAgBtD,MAAM,OAAO,aAAc,SAAQ,eAAe;IAGnC,cAAc,CAAC,EACyB;;gBADzB,EAAE,SAAS,OACc,EADT,MAAM,cAAtB,aAAwB,CAAF;YAGhD,uCAAuC;YACvC,MAAM,IAAI,GAAG;gBACX,UAAU,EAAG,SAAkB;gBAC/B,UAAU,EAAG,SAAkB;gBAC/B,UAAU,EAAG,SAAkB;aAChC,CAAC,SAAS,CAAC,CAAC;YAEb,gDAAgD;YAChD,MAAM,eAAe,GAAG,MAAM,IAAI,CAAC,cAAc,iCAAM,MAAM,KAAE,IAAI,IAAG,CAAC;YAEvE,OAAO,eAAe,CAAC;QACzB,CAAC;KAAA;CACF"}