@credo-ts/node 0.8.0-alpha-20260915104201 → 0.8.0-alpha-20260928074804

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 (49) hide show
  1. package/build/NodeFileSystem.d.mts +1 -3
  2. package/build/NodeFileSystem.d.mts.map +1 -1
  3. package/build/NodeFileSystem.mjs +1 -2
  4. package/build/NodeFileSystem.mjs.map +1 -1
  5. package/build/_virtual/{_@oxc-project_runtime@0.112.0/helpers → _@oxc-project_runtime@0.151.0/helpers/esm}/assertClassBrand.mjs +2 -3
  6. package/build/_virtual/{_@oxc-project_runtime@0.112.0/helpers → _@oxc-project_runtime@0.151.0/helpers/esm}/checkPrivateRedeclaration.mjs +2 -3
  7. package/build/_virtual/_@oxc-project_runtime@0.151.0/helpers/esm/classPrivateFieldGet2.mjs +7 -0
  8. package/build/_virtual/_@oxc-project_runtime@0.151.0/helpers/esm/classPrivateFieldInitSpec.mjs +7 -0
  9. package/build/_virtual/_@oxc-project_runtime@0.151.0/helpers/esm/classPrivateFieldSet2.mjs +7 -0
  10. package/build/index.d.mts +0 -1
  11. package/build/index.d.mts.map +1 -1
  12. package/build/index.mjs +3 -4
  13. package/build/index.mjs.map +1 -1
  14. package/build/kms/NodeInMemoryKeyManagementStorage.d.mts +1 -3
  15. package/build/kms/NodeInMemoryKeyManagementStorage.d.mts.map +1 -1
  16. package/build/kms/NodeInMemoryKeyManagementStorage.mjs +3 -4
  17. package/build/kms/NodeInMemoryKeyManagementStorage.mjs.map +1 -1
  18. package/build/kms/NodeKeyManagementService.d.mts +1 -3
  19. package/build/kms/NodeKeyManagementService.d.mts.map +1 -1
  20. package/build/kms/NodeKeyManagementService.mjs +61 -13
  21. package/build/kms/NodeKeyManagementService.mjs.map +1 -1
  22. package/build/kms/NodeKeyManagementStorage.d.mts +1 -3
  23. package/build/kms/NodeKeyManagementStorage.d.mts.map +1 -1
  24. package/build/kms/crypto/createKey.mjs +1 -2
  25. package/build/kms/crypto/createKey.mjs.map +1 -1
  26. package/build/kms/crypto/decrypt.mjs +8 -6
  27. package/build/kms/crypto/decrypt.mjs.map +1 -1
  28. package/build/kms/crypto/deriveKey.mjs +1 -2
  29. package/build/kms/crypto/deriveKey.mjs.map +1 -1
  30. package/build/kms/crypto/encrypt.mjs +1 -2
  31. package/build/kms/crypto/encrypt.mjs.map +1 -1
  32. package/build/kms/crypto/hpke.mjs +82 -0
  33. package/build/kms/crypto/hpke.mjs.map +1 -0
  34. package/build/kms/crypto/sign.mjs +9 -7
  35. package/build/kms/crypto/sign.mjs.map +1 -1
  36. package/build/kms/crypto/verify.mjs +13 -8
  37. package/build/kms/crypto/verify.mjs.map +1 -1
  38. package/build/transport/DidCommHttpInboundTransport.d.mts +11 -13
  39. package/build/transport/DidCommHttpInboundTransport.d.mts.map +1 -1
  40. package/build/transport/DidCommHttpInboundTransport.mjs +28 -12
  41. package/build/transport/DidCommHttpInboundTransport.mjs.map +1 -1
  42. package/build/transport/DidCommWsInboundTransport.d.mts +3 -8
  43. package/build/transport/DidCommWsInboundTransport.d.mts.map +1 -1
  44. package/build/transport/DidCommWsInboundTransport.mjs +7 -6
  45. package/build/transport/DidCommWsInboundTransport.mjs.map +1 -1
  46. package/package.json +5 -4
  47. package/build/_virtual/_@oxc-project_runtime@0.112.0/helpers/classPrivateFieldGet2.mjs +0 -9
  48. package/build/_virtual/_@oxc-project_runtime@0.112.0/helpers/classPrivateFieldInitSpec.mjs +0 -9
  49. package/build/_virtual/_@oxc-project_runtime@0.112.0/helpers/classPrivateFieldSet2.mjs +0 -9
@@ -1,7 +1,6 @@
1
1
  import { DownloadToFileOptions, FileSystem } from "@credo-ts/core";
2
-
3
2
  //#region src/NodeFileSystem.d.ts
4
- declare class NodeFileSystem implements FileSystem {
3
+ export declare class NodeFileSystem implements FileSystem {
5
4
  readonly dataPath: string;
6
5
  readonly cachePath: string;
7
6
  readonly tempPath: string;
@@ -29,5 +28,4 @@ declare class NodeFileSystem implements FileSystem {
29
28
  downloadToFile(url: string, path: string, options: DownloadToFileOptions): Promise<void>;
30
29
  }
31
30
  //#endregion
32
- export { NodeFileSystem };
33
31
  //# sourceMappingURL=NodeFileSystem.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"NodeFileSystem.d.mts","names":[],"sources":["../src/NodeFileSystem.ts"],"mappings":";;;cAWa,cAAA,YAA0B,UAAA;EAAA,SACrB,QAAA;EAAA,SACA,SAAA;EAAA,SACA,QAAA;;;;;;;;;;;cAYG,OAAA;IAAY,YAAA;IAAuB,aAAA;IAAwB,YAAA;EAAA;EAMjE,MAAA,CAAO,IAAA,WAAY,OAAA;EASnB,eAAA,CAAgB,IAAA,WAAe,OAAA;EAI/B,QAAA,CAAS,UAAA,UAAoB,eAAA,WAA0B,OAAA;EAIvD,KAAA,CAAM,IAAA,UAAc,IAAA,WAAe,OAAA;EAOnC,IAAA,CAAK,IAAA,WAAe,OAAA;EAIpB,MAAA,CAAO,IAAA,WAAe,OAAA;EAItB,cAAA,CAAe,GAAA,UAAa,IAAA,UAAc,OAAA,EAAS,qBAAA,GAAqB,OAAA;AAAA"}
1
+ {"version":3,"file":"NodeFileSystem.d.mts","names":[],"sources":["../src/NodeFileSystem.ts"],"mappings":";;qBAWa,0BAA0B;WACrB;WACA;WACA;;;;;;;;;;;EAYG,YAAA;IAAY;IAAuB;IAAwB;;EAMjE,OAAO,eAAY;EASnB,gBAAgB,eAAe;EAI/B,SAAS,oBAAoB,0BAA0B;EAIvD,MAAM,cAAc,eAAe;EAOnC,KAAK,eAAe;EAIpB,OAAO,eAAe;EAItB,eAAe,aAAa,cAAc,SAAS,wBAAqB"}
@@ -5,7 +5,6 @@ import http from "http";
5
5
  import https from "https";
6
6
  import { homedir, tmpdir } from "os";
7
7
  import { dirname } from "path";
8
-
9
8
  //#region src/NodeFileSystem.ts
10
9
  const { access, readFile, writeFile, mkdir, rm, unlink, copyFile } = promises;
11
10
  var NodeFileSystem = class {
@@ -80,7 +79,7 @@ var NodeFileSystem = class {
80
79
  });
81
80
  }
82
81
  };
83
-
84
82
  //#endregion
85
83
  export { NodeFileSystem };
84
+
86
85
  //# sourceMappingURL=NodeFileSystem.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"NodeFileSystem.mjs","names":[],"sources":["../src/NodeFileSystem.ts"],"sourcesContent":["import type { DownloadToFileOptions, FileSystem } from '@credo-ts/core'\nimport { CredoError, TypedArrayEncoder } from '@credo-ts/core'\nimport { createHash } from 'crypto'\nimport fs, { promises } from 'fs'\nimport http from 'http'\nimport https from 'https'\nimport { homedir, tmpdir } from 'os'\nimport { dirname } from 'path'\n\nconst { access, readFile, writeFile, mkdir, rm, unlink, copyFile } = promises\n\nexport class NodeFileSystem implements FileSystem {\n public readonly dataPath\n public readonly cachePath\n public readonly tempPath\n\n /**\n * Create new NodeFileSystem class instance.\n *\n * @param baseDataPath The base path to use for reading and writing data files used within the framework.\n * Files will be created under baseDataPath/.afj directory. If not specified, it will be set to homedir()\n * @param baseCachePath The base path to use for reading and writing cache files used within the framework.\n * Files will be created under baseCachePath/.afj directory. If not specified, it will be set to homedir()\n * @param baseTempPath The base path to use for reading and writing temporary files within the framework.\n * Files will be created under baseTempPath/.afj directory. If not specified, it will be set to tmpdir()\n */\n public constructor(options?: { baseDataPath?: string; baseCachePath?: string; baseTempPath?: string }) {\n this.dataPath = options?.baseDataPath ? `${options?.baseDataPath}/.afj` : `${homedir()}/.afj/data`\n this.cachePath = options?.baseCachePath ? `${options?.baseCachePath}/.afj` : `${homedir()}/.afj/cache`\n this.tempPath = `${options?.baseTempPath ?? tmpdir()}/.afj`\n }\n\n public async exists(path: string) {\n try {\n await access(path)\n return true\n } catch {\n return false\n }\n }\n\n public async createDirectory(path: string): Promise<void> {\n await mkdir(dirname(path), { recursive: true })\n }\n\n public async copyFile(sourcePath: string, destinationPath: string): Promise<void> {\n await copyFile(sourcePath, destinationPath)\n }\n\n public async write(path: string, data: string): Promise<void> {\n // Make sure parent directories exist\n await mkdir(dirname(path), { recursive: true })\n\n return writeFile(path, data, { encoding: 'utf-8' })\n }\n\n public async read(path: string): Promise<string> {\n return readFile(path, { encoding: 'utf-8' })\n }\n\n public async delete(path: string): Promise<void> {\n await rm(path, { recursive: true, force: true })\n }\n\n public async downloadToFile(url: string, path: string, options: DownloadToFileOptions) {\n const httpMethod = url.startsWith('https') ? https : http\n\n // Make sure parent directories exist\n await mkdir(dirname(path), { recursive: true })\n\n const file = fs.createWriteStream(path)\n const hash = options.verifyHash ? createHash('sha256') : undefined\n\n return new Promise<void>((resolve, reject) => {\n httpMethod\n .get(url, (response) => {\n // check if response is success\n if (response.statusCode !== 200) {\n reject(`Unable to download file from url: ${url}. Response status was ${response.statusCode}`)\n }\n\n hash && response.pipe(hash)\n response.pipe(file)\n file.on('finish', async () => {\n file.close()\n\n if (hash && options.verifyHash?.hash) {\n hash.end()\n const digest = hash.digest()\n if (digest.compare(options.verifyHash.hash) !== 0) {\n await fs.promises.unlink(path)\n\n reject(\n new CredoError(\n `Hash of downloaded file does not match expected hash. Expected: ${\n options.verifyHash.hash\n }, Actual: ${TypedArrayEncoder.toUtf8String(digest)})}`\n )\n )\n }\n }\n resolve()\n })\n })\n .on('error', async (error) => {\n // Handle errors\n await unlink(path) // Delete the file async. (But we don't check the result)\n reject(`Unable to download file from url: ${url}. ${error.message}`)\n })\n })\n }\n}\n"],"mappings":";;;;;;;;;AASA,MAAM,EAAE,QAAQ,UAAU,WAAW,OAAO,IAAI,QAAQ,aAAa;AAErE,IAAa,iBAAb,MAAkD;;;;;;;;;;;CAehD,AAAO,YAAY,SAAoF;AACrG,OAAK,WAAW,SAAS,eAAe,GAAG,SAAS,aAAa,SAAS,GAAG,SAAS,CAAC;AACvF,OAAK,YAAY,SAAS,gBAAgB,GAAG,SAAS,cAAc,SAAS,GAAG,SAAS,CAAC;AAC1F,OAAK,WAAW,GAAG,SAAS,gBAAgB,QAAQ,CAAC;;CAGvD,MAAa,OAAO,MAAc;AAChC,MAAI;AACF,SA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W,KACpB,YAAY,kBAAkB,aAAa,OAAO,CAAC,IACrD,CACF;;;AAGL,cAAS;MACT;KACF,CACD,GAAG,SAAS,OAAO,UAAU;AAE5B,UAAM,OAAO,KAAK;AAClB,WAAO,qCAAqC,IAAI,IAAI,MAAM,UAAU;KACpE;IACJ"}
1
+ {"version":3,"file":"NodeFileSystem.mjs","names":[],"sources":["../src/NodeFileSystem.ts"],"sourcesContent":["import type { DownloadToFileOptions, FileSystem } from '@credo-ts/core'\nimport { CredoError, TypedArrayEncoder } from '@credo-ts/core'\nimport { createHash } from 'crypto'\nimport fs, { promises } from 'fs'\nimport http from 'http'\nimport https from 'https'\nimport { homedir, tmpdir } from 'os'\nimport { dirname } from 'path'\n\nconst { access, readFile, writeFile, mkdir, rm, unlink, copyFile } = promises\n\nexport class NodeFileSystem implements FileSystem {\n public readonly dataPath\n public readonly cachePath\n public readonly tempPath\n\n /**\n * Create new NodeFileSystem class instance.\n *\n * @param baseDataPath The base path to use for reading and writing data files used within the framework.\n * Files will be created under baseDataPath/.afj directory. If not specified, it will be set to homedir()\n * @param baseCachePath The base path to use for reading and writing cache files used within the framework.\n * Files will be created under baseCachePath/.afj directory. If not specified, it will be set to homedir()\n * @param baseTempPath The base path to use for reading and writing temporary files within the framework.\n * Files will be created under baseTempPath/.afj directory. If not specified, it will be set to tmpdir()\n */\n public constructor(options?: { baseDataPath?: string; baseCachePath?: string; baseTempPath?: string }) {\n this.dataPath = options?.baseDataPath ? `${options?.baseDataPath}/.afj` : `${homedir()}/.afj/data`\n this.cachePath = options?.baseCachePath ? `${options?.baseCachePath}/.afj` : `${homedir()}/.afj/cache`\n this.tempPath = `${options?.baseTempPath ?? tmpdir()}/.afj`\n }\n\n public async exists(path: string) {\n try {\n await access(path)\n return true\n } catch {\n return false\n }\n }\n\n public async createDirectory(path: string): Promise<void> {\n await mkdir(dirname(path), { recursive: true })\n }\n\n public async copyFile(sourcePath: string, destinationPath: string): Promise<void> {\n await copyFile(sourcePath, destinationPath)\n }\n\n public async write(path: string, data: string): Promise<void> {\n // Make sure parent directories exist\n await mkdir(dirname(path), { recursive: true })\n\n return writeFile(path, data, { encoding: 'utf-8' })\n }\n\n public async read(path: string): Promise<string> {\n return readFile(path, { encoding: 'utf-8' })\n }\n\n public async delete(path: string): Promise<void> {\n await rm(path, { recursive: true, force: true })\n }\n\n public async downloadToFile(url: string, path: string, options: DownloadToFileOptions) {\n const httpMethod = url.startsWith('https') ? https : http\n\n // Make sure parent directories exist\n await mkdir(dirname(path), { recursive: true })\n\n const file = fs.createWriteStream(path)\n const hash = options.verifyHash ? createHash('sha256') : undefined\n\n return new Promise<void>((resolve, reject) => {\n httpMethod\n .get(url, (response) => {\n // check if response is success\n if (response.statusCode !== 200) {\n reject(`Unable to download file from url: ${url}. Response status was ${response.statusCode}`)\n }\n\n hash && response.pipe(hash)\n response.pipe(file)\n file.on('finish', async () => {\n file.close()\n\n if (hash && options.verifyHash?.hash) {\n hash.end()\n const digest = hash.digest()\n if (digest.compare(options.verifyHash.hash) !== 0) {\n await fs.promises.unlink(path)\n\n reject(\n new CredoError(\n `Hash of downloaded file does not match expected hash. Expected: ${\n options.verifyHash.hash\n }, Actual: ${TypedArrayEncoder.toUtf8String(digest)})}`\n )\n )\n }\n }\n resolve()\n })\n })\n .on('error', async (error) => {\n // Handle errors\n await unlink(path) // Delete the file async. (But we don't check the result)\n reject(`Unable to download file from url: ${url}. ${error.message}`)\n })\n })\n }\n}\n"],"mappings":";;;;;;;;AASA,MAAM,EAAE,QAAQ,UAAU,WAAW,OAAO,IAAI,QAAQ,aAAa;AAErE,IAAa,iBAAb,MAAkD;;;;;;;;;;;CAehD,YAAmB,SAAoF;EACrG,KAAK,WAAW,SAAS,eAAe,GAAG,SAAS,aAAa,SAAS,GAAG,QAAQ,EAAE;EACvF,KAAK,YAAY,SAAS,gBAAgB,GAAG,SAAS,cAAc,SAAS,GAAG,QAAQ,EAAE;EAC1F,KAAK,WAAW,GAAG,SAAS,gBAAgB,OAAO,E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AAI,MAAM,GAAG;OACjD,MAAM,GAAG,SAAS,OAAO,IAAI;OAE7B,OACE,IAAI,WACF,mEACE,QAAQ,WAAW,KACpB,YAAY,kBAAkB,aAAa,MAAM,EAAE,GACtD,CACF;MACF;KACF;KACA,QAAQ;IACV,CAAC;GACH,CAAC,CAAC,CACD,GAAG,SAAS,OAAO,UAAU;IAE5B,MAAM,OAAO,IAAI;IACjB,OAAO,qCAAqC,IAAI,IAAI,MAAM,SAAS;GACrE,CAAC;EACL,CAAC;CACH;AACF"}
@@ -1,8 +1,7 @@
1
- //#region \0@oxc-project+runtime@0.112.0/helpers/assertClassBrand.js
1
+ //#region \0@oxc-project+runtime@0.151.0/helpers/esm/assertClassBrand.js
2
2
  function _assertClassBrand(e, t, n) {
3
3
  if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n;
4
4
  throw new TypeError("Private element is not present on this object");
5
5
  }
6
-
7
6
  //#endregion
8
- export { _assertClassBrand };
7
+ export { _assertClassBrand as default };
@@ -1,7 +1,6 @@
1
- //#region \0@oxc-project+runtime@0.112.0/helpers/checkPrivateRedeclaration.js
1
+ //#region \0@oxc-project+runtime@0.151.0/helpers/esm/checkPrivateRedeclaration.js
2
2
  function _checkPrivateRedeclaration(e, t) {
3
3
  if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object");
4
4
  }
5
-
6
5
  //#endregion
7
- export { _checkPrivateRedeclaration };
6
+ export { _checkPrivateRedeclaration as default };
@@ -0,0 +1,7 @@
1
+ import _assertClassBrand from "./assertClassBrand.mjs";
2
+ //#region \0@oxc-project+runtime@0.151.0/helpers/esm/classPrivateFieldGet2.js
3
+ function _classPrivateFieldGet2(s, a) {
4
+ return s.get(_assertClassBrand(s, a));
5
+ }
6
+ //#endregion
7
+ export { _classPrivateFieldGet2 as default };
@@ -0,0 +1,7 @@
1
+ import _checkPrivateRedeclaration from "./checkPrivateRedeclaration.mjs";
2
+ //#region \0@oxc-project+runtime@0.151.0/helpers/esm/classPrivateFieldInitSpec.js
3
+ function _classPrivateFieldInitSpec(e, t, a) {
4
+ _checkPrivateRedeclaration(e, t), t.set(e, a);
5
+ }
6
+ //#endregion
7
+ export { _classPrivateFieldInitSpec as default };
@@ -0,0 +1,7 @@
1
+ import _assertClassBrand from "./assertClassBrand.mjs";
2
+ //#region \0@oxc-project+runtime@0.151.0/helpers/esm/classPrivateFieldSet2.js
3
+ function _classPrivateFieldSet2(s, a, r) {
4
+ return s.set(_assertClassBrand(s, a), r), r;
5
+ }
6
+ //#endregion
7
+ export { _classPrivateFieldSet2 as default };
package/build/index.d.mts CHANGED
@@ -5,7 +5,6 @@ import { NodeKeyManagementStorage } from "./kms/NodeKeyManagementStorage.mjs";
5
5
  import { NodeInMemoryKeyManagementStorage } from "./kms/NodeInMemoryKeyManagementStorage.mjs";
6
6
  import { NodeKeyManagementService } from "./kms/NodeKeyManagementService.mjs";
7
7
  import { AgentDependencies } from "@credo-ts/core";
8
-
9
8
  //#region src/index.d.ts
10
9
  declare const agentDependencies: AgentDependencies;
11
10
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;;;;cAaM,iBAAA,EAAmB,iBAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;;;cAaM,mBAAmB"}
package/build/index.mjs CHANGED
@@ -4,16 +4,15 @@ import { DidCommWsInboundTransport } from "./transport/DidCommWsInboundTransport
4
4
  import { NodeInMemoryKeyManagementStorage } from "./kms/NodeInMemoryKeyManagementStorage.mjs";
5
5
  import { NodeKeyManagementService } from "./kms/NodeKeyManagementService.mjs";
6
6
  import { EventEmitter } from "events";
7
- import { WebSocket as WebSocket$1 } from "ws";
8
-
7
+ import { WebSocket } from "ws";
9
8
  //#region src/index.ts
10
9
  const agentDependencies = {
11
10
  FileSystem: NodeFileSystem,
12
11
  fetch,
13
12
  EventEmitterClass: EventEmitter,
14
- WebSocketClass: WebSocket$1
13
+ WebSocketClass: WebSocket
15
14
  };
16
-
17
15
  //#endregion
18
16
  export { DidCommHttpInboundTransport, DidCommWsInboundTransport, NodeFileSystem, NodeInMemoryKeyManagementStorage, NodeKeyManagementService, agentDependencies };
17
+
19
18
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["WebSocket"],"sources":["../src/index.ts"],"sourcesContent":["import type { AgentDependencies } from '@credo-ts/core'\n\nimport { EventEmitter } from 'events'\nimport { WebSocket } from 'ws'\n\nimport { NodeFileSystem } from './NodeFileSystem'\nimport { DidCommHttpInboundTransport } from './transport/DidCommHttpInboundTransport'\nimport { DidCommWsInboundTransport } from './transport/DidCommWsInboundTransport'\n\nexport { NodeInMemoryKeyManagementStorage } from './kms/NodeInMemoryKeyManagementStorage'\nexport { NodeKeyManagementService } from './kms/NodeKeyManagementService'\nexport type { NodeKeyManagementStorage } from './kms/NodeKeyManagementStorage'\n\nconst agentDependencies: AgentDependencies = {\n FileSystem: NodeFileSystem,\n fetch,\n EventEmitterClass: EventEmitter,\n WebSocketClass: WebSocket,\n}\n\nexport { agentDependencies, DidCommHttpInboundTransport, DidCommWsInboundTransport, NodeFileSystem }\n"],"mappings":";;;;;;;;;AAaA,MAAM,oBAAuC;CAC3C,YAAY;CACZ;CACA,mBAAmB;CACnB,gBAAgBA;CACjB"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { AgentDependencies } from '@credo-ts/core'\n\nimport { EventEmitter } from 'events'\nimport { WebSocket } from 'ws'\n\nimport { NodeFileSystem } from './NodeFileSystem'\nimport { DidCommHttpInboundTransport } from './transport/DidCommHttpInboundTransport'\nimport { DidCommWsInboundTransport } from './transport/DidCommWsInboundTransport'\n\nexport { NodeInMemoryKeyManagementStorage } from './kms/NodeInMemoryKeyManagementStorage'\nexport { NodeKeyManagementService } from './kms/NodeKeyManagementService'\nexport type { NodeKeyManagementStorage } from './kms/NodeKeyManagementStorage'\n\nconst agentDependencies: AgentDependencies = {\n FileSystem: NodeFileSystem,\n fetch,\n EventEmitterClass: EventEmitter,\n WebSocketClass: WebSocket,\n}\n\nexport { agentDependencies, DidCommHttpInboundTransport, DidCommWsInboundTransport, NodeFileSystem }\n"],"mappings":";;;;;;;;AAaA,MAAM,oBAAuC;CAC3C,YAAY;CACZ;CACA,mBAAmB;CACnB,gBAAgB;AAClB"}
@@ -1,8 +1,7 @@
1
1
  import { NodeKeyManagementStorage } from "./NodeKeyManagementStorage.mjs";
2
2
  import { AgentContext, Kms } from "@credo-ts/core";
3
-
4
3
  //#region src/kms/NodeInMemoryKeyManagementStorage.d.ts
5
- declare class NodeInMemoryKeyManagementStorage implements NodeKeyManagementStorage {
4
+ export declare class NodeInMemoryKeyManagementStorage implements NodeKeyManagementStorage {
6
5
  #private;
7
6
  get(agentContext: AgentContext, keyId: string): Promise<{
8
7
  d: string;
@@ -77,5 +76,4 @@ declare class NodeInMemoryKeyManagementStorage implements NodeKeyManagementStora
77
76
  private storageForContext;
78
77
  }
79
78
  //#endregion
80
- export { NodeInMemoryKeyManagementStorage };
81
79
  //# sourceMappingURL=NodeInMemoryKeyManagementStorage.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"NodeInMemoryKeyManagementStorage.d.mts","names":[],"sources":["../../src/kms/NodeInMemoryKeyManagementStorage.ts"],"mappings":";;;;cAGa,gCAAA,YAA4C,wBAAA;EAAA;EAG1C,GAAA,CAAI,YAAA,EAAc,YAAA,EAAc,KAAA,WAAa,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAInD,GAAA,CAAI,YAAA,EAAc,YAAA,EAAc,KAAA;EAIhC,GAAA,CAAI,YAAA,EAAc,YAAA,EAAc,KAAA,UAAe,GAAA,EAAK,GAAA,CAAI,aAAA;EAIxD,MAAA,CAAO,YAAA,EAAc,YAAA,EAAc,KAAA;EAAA,QAIlC,iBAAA;AAAA"}
1
+ {"version":3,"file":"NodeInMemoryKeyManagementStorage.d.mts","names":[],"sources":["../../src/kms/NodeInMemoryKeyManagementStorage.ts"],"mappings":";;;qBAGa,4CAA4C;;EAG1C,IAAI,cAAc,cAAc,gBAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAInD,IAAI,cAAc,cAAc;EAIhC,IAAI,cAAc,cAAc,eAAe,KAAK,IAAI;EAIxD,OAAO,cAAc,cAAc;UAIlC"}
@@ -1,6 +1,5 @@
1
- import { _classPrivateFieldInitSpec } from "../_virtual/_@oxc-project_runtime@0.112.0/helpers/classPrivateFieldInitSpec.mjs";
2
- import { _classPrivateFieldGet2 } from "../_virtual/_@oxc-project_runtime@0.112.0/helpers/classPrivateFieldGet2.mjs";
3
-
1
+ import _classPrivateFieldInitSpec from "../_virtual/_@oxc-project_runtime@0.151.0/helpers/esm/classPrivateFieldInitSpec.mjs";
2
+ import _classPrivateFieldGet2 from "../_virtual/_@oxc-project_runtime@0.151.0/helpers/esm/classPrivateFieldGet2.mjs";
4
3
  //#region src/kms/NodeInMemoryKeyManagementStorage.ts
5
4
  var _storage = /* @__PURE__ */ new WeakMap();
6
5
  var NodeInMemoryKeyManagementStorage = class {
@@ -28,7 +27,7 @@ var NodeInMemoryKeyManagementStorage = class {
28
27
  return storage;
29
28
  }
30
29
  };
31
-
32
30
  //#endregion
33
31
  export { NodeInMemoryKeyManagementStorage };
32
+
34
33
  //# sourceMappingURL=NodeInMemoryKeyManagementStorage.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"NodeInMemoryKeyManagementStorage.mjs","names":[],"sources":["../../src/kms/NodeInMemoryKeyManagementStorage.ts"],"sourcesContent":["import type { AgentContext, Kms } from '@credo-ts/core'\nimport type { NodeKeyManagementStorage } from './NodeKeyManagementStorage'\n\nexport class NodeInMemoryKeyManagementStorage implements NodeKeyManagementStorage {\n #storage = new Map<string, Map<string, Kms.KmsJwkPrivate>>()\n\n public async get(agentContext: AgentContext, keyId: string) {\n return this.storageForContext(agentContext).get(keyId) ?? null\n }\n\n public has(agentContext: AgentContext, keyId: string) {\n return this.storageForContext(agentContext).has(keyId)\n }\n\n public set(agentContext: AgentContext, keyId: string, jwk: Kms.KmsJwkPrivate) {\n this.storageForContext(agentContext).set(keyId, jwk)\n }\n\n public delete(agentContext: AgentContext, keyId: string) {\n return this.storageForContext(agentContext).delete(keyId)\n }\n\n private storageForContext(agentContext: AgentContext) {\n let storage = this.#storage.get(agentContext.contextCorrelationId)\n\n if (!storage) {\n storage = new Map()\n this.#storage.set(agentContext.contextCorrelationId, storage)\n }\n\n return storage\n }\n}\n"],"mappings":";;;;;AAGA,IAAa,mCAAb,MAAkF;;6DACrE,IAAI,KAA6C;;CAE5D,MAAa,IAAI,cAA4B,OAAe;AAC1D,SAAO,KAAK,kBAAkB,aAAa,CAAC,IAAI,MAAM,IAAI;;CAG5D,AAAO,IAAI,cAA4B,OAAe;AACpD,SAAO,KAAK,kBAAkB,aAAa,CAAC,IAAI,MAAM;;CAGxD,AAAO,IAAI,cAA4B,OAAe,KAAwB;AAC5E,OAAK,kBAAkB,aAAa,CAAC,IAAI,OAAO,IAAI;;CAGtD,AAAO,OAAO,cAA4B,OAAe;AACvD,SAAO,KAAK,kBAAkB,aAAa,CAAC,OAAO,MAAM;;CAG3D,AAAQ,kBAAkB,cAA4B;EACpD,IAAI,2CAAU,KAAa,CAAC,IAAI,aAAa,qBAAqB;AAElE,MAAI,CAAC,SAAS;AACZ,6BAAU,IAAI,KAAK;AACnB,yCAAa,CAAC,IAAI,aAAa,sBAAsB,QAAQ;;AAG/D,SAAO"}
1
+ {"version":3,"file":"NodeInMemoryKeyManagementStorage.mjs","names":[],"sources":["../../src/kms/NodeInMemoryKeyManagementStorage.ts"],"sourcesContent":["import type { AgentContext, Kms } from '@credo-ts/core'\nimport type { NodeKeyManagementStorage } from './NodeKeyManagementStorage'\n\nexport class NodeInMemoryKeyManagementStorage implements NodeKeyManagementStorage {\n #storage = new Map<string, Map<string, Kms.KmsJwkPrivate>>()\n\n public async get(agentContext: AgentContext, keyId: string) {\n return this.storageForContext(agentContext).get(keyId) ?? null\n }\n\n public has(agentContext: AgentContext, keyId: string) {\n return this.storageForContext(agentContext).has(keyId)\n }\n\n public set(agentContext: AgentContext, keyId: string, jwk: Kms.KmsJwkPrivate) {\n this.storageForContext(agentContext).set(keyId, jwk)\n }\n\n public delete(agentContext: AgentContext, keyId: string) {\n return this.storageForContext(agentContext).delete(keyId)\n }\n\n private storageForContext(agentContext: AgentContext) {\n let storage = this.#storage.get(agentContext.contextCorrelationId)\n\n if (!storage) {\n storage = new Map()\n this.#storage.set(agentContext.contextCorrelationId, storage)\n }\n\n return storage\n }\n}\n"],"mappings":";;;;AAGA,IAAa,mCAAb,MAAkF;;EACrE,2BAAA,MAAA,0BAAA,IAAI,IAA4C,CAAA;;CAE3D,MAAa,IAAI,cAA4B,OAAe;EAC1D,OAAO,KAAK,kBAAkB,YAAY,CAAC,CAAC,IAAI,KAAK,KAAK;CAC5D;CAEA,IAAW,cAA4B,OAAe;EACpD,OAAO,KAAK,kBAAkB,YAAY,CAAC,CAAC,IAAI,KAAK;CACvD;CAEA,IAAW,cAA4B,OAAe,KAAwB;EAC5E,KAAK,kBAAkB,YAAY,CAAC,CAAC,IAAI,OAAO,GAAG;CACrD;CAEA,OAAc,cAA4B,OAAe;EACvD,OAAO,KAAK,kBAAkB,YAAY,CAAC,CAAC,OAAO,KAAK;CAC1D;CAEA,kBAA0B,cAA4B;EACpD,IAAI,UAAA,uBAAA,UAAU,IAAA,CAAA,CAAc,IAAI,aAAa,oBAAoB;EAEjE,IAAI,CAAC,SAAS;GACZ,0BAAU,IAAI,IAAI;GAClB,uBAAA,UAAA,IAAA,CAAA,CAAc,IAAI,aAAa,sBAAsB,OAAO;EAC9D;EAEA,OAAO;CACT;AACF"}
@@ -1,8 +1,7 @@
1
1
  import { NodeKeyManagementStorage } from "./NodeKeyManagementStorage.mjs";
2
2
  import { AgentContext, Kms } from "@credo-ts/core";
3
-
4
3
  //#region src/kms/NodeKeyManagementService.d.ts
5
- declare class NodeKeyManagementService implements Kms.KeyManagementService {
4
+ export declare class NodeKeyManagementService implements Kms.KeyManagementService {
6
5
  #private;
7
6
  readonly backend = "node";
8
7
  constructor(storage: NodeKeyManagementStorage);
@@ -20,5 +19,4 @@ declare class NodeKeyManagementService implements Kms.KeyManagementService {
20
19
  private assertKeyNotExists;
21
20
  }
22
21
  //#endregion
23
- export { NodeKeyManagementService };
24
22
  //# sourceMappingURL=NodeKeyManagementService.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"NodeKeyManagementService.d.mts","names":[],"sources":["../../src/kms/NodeKeyManagementService.ts"],"mappings":";;;;cAmBa,wBAAA,YAAoC,GAAA,CAAI,oBAAA;EAAA;WACnC,OAAA;cAIG,OAAA,EAAS,wBAAA;EAIrB,oBAAA,CAAqB,aAAA,EAAe,YAAA,EAAc,SAAA,EAAW,GAAA,CAAI,YAAA;EAmFjE,WAAA,CAAY,aAAA,EAAe,YAAA,EAAc,OAAA,EAAS,GAAA,CAAI,qBAAA,GAAwB,GAAA,CAAI,oBAAA;EAI5E,YAAA,CAAa,YAAA,EAAc,YAAA,EAAc,KAAA,WAAgB,OAAA,CAAQ,GAAA,CAAI,YAAA;EAOrE,SAAA,aAAsB,GAAA,CAAI,aAAA,CAAA,CACrC,YAAA,EAAc,YAAA,EACd,OAAA,EAAS,GAAA,CAAI,mBAAA,CAAoB,GAAA,IAChC,OAAA,CAAQ,GAAA,CAAI,kBAAA,CAAmB,GAAA;EAyDrB,SAAA,CAAU,YAAA,EAAc,YAAA,EAAc,OAAA,EAAS,GAAA,CAAI,mBAAA,GAAsB,OAAA;EAIzE,SAAA,cAAuB,GAAA,CAAI,gBAAA,CAAA,CACtC,YAAA,EAAc,YAAA,EACd,OAAA,EAAS,GAAA,CAAI,mBAAA,CAAoB,IAAA,IAChC,OAAA,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FjF,QAAQ,cAAc,cAAc,SAAS,IAAI,oBAAoB,QAAQ,IAAI;UAoFhF;UASA"}
@@ -1,15 +1,15 @@
1
- import { _classPrivateFieldInitSpec } from "../_virtual/_@oxc-project_runtime@0.112.0/helpers/classPrivateFieldInitSpec.mjs";
2
- import { _classPrivateFieldGet2 } from "../_virtual/_@oxc-project_runtime@0.112.0/helpers/classPrivateFieldGet2.mjs";
1
+ import _classPrivateFieldInitSpec from "../_virtual/_@oxc-project_runtime@0.151.0/helpers/esm/classPrivateFieldInitSpec.mjs";
2
+ import _classPrivateFieldGet2 from "../_virtual/_@oxc-project_runtime@0.151.0/helpers/esm/classPrivateFieldGet2.mjs";
3
3
  import { assertNodeSupportedEcCrv, assertNodeSupportedOctAlgorithm, assertNodeSupportedOkpCrv, createEcKey, createOctKey, createOkpKey, createRsaKey } from "./crypto/createKey.mjs";
4
4
  import { nodeSupportedJwaAlgorithm, performSign } from "./crypto/sign.mjs";
5
5
  import { performDecrypt } from "./crypto/decrypt.mjs";
6
6
  import { deriveDecryptionKey, deriveEncryptionKey, nodeSupportedKeyAgreementAlgorithms } from "./crypto/deriveKey.mjs";
7
7
  import { nodeSupportedEncryptionAlgorithms, performEncrypt } from "./crypto/encrypt.mjs";
8
+ import { hpkeOpen, hpkeSeal, nodeSupportedHpkeAlgorithms } from "./crypto/hpke.mjs";
8
9
  import { performVerify } from "./crypto/verify.mjs";
9
- import { _classPrivateFieldSet2 } from "../_virtual/_@oxc-project_runtime@0.112.0/helpers/classPrivateFieldSet2.mjs";
10
+ import _classPrivateFieldSet2 from "../_virtual/_@oxc-project_runtime@0.151.0/helpers/esm/classPrivateFieldSet2.mjs";
10
11
  import { Kms, TypedArrayEncoder } from "@credo-ts/core";
11
12
  import { createPrivateKey, createSecretKey, randomBytes, randomUUID } from "node:crypto";
12
-
13
13
  //#region src/kms/NodeKeyManagementService.ts
14
14
  var _storage = /* @__PURE__ */ new WeakMap();
15
15
  var NodeKeyManagementService = class {
@@ -61,13 +61,22 @@ var NodeKeyManagementService = class {
61
61
  return false;
62
62
  }
63
63
  if (operation.operation === "sign" || operation.operation === "verify") return nodeSupportedJwaAlgorithm.includes(operation.algorithm);
64
- if (operation.operation === "encrypt") {
65
- if (!nodeSupportedEncryptionAlgorithms.includes(operation.encryption.algorithm)) return false;
66
- if (!operation.keyAgreement) return true;
67
- return nodeSupportedKeyAgreementAlgorithms.includes(operation.keyAgreement.algorithm);
68
- }
69
- if (operation.operation === "decrypt") {
70
- if (!nodeSupportedEncryptionAlgorithms.includes(operation.decryption.algorithm)) return false;
64
+ if (operation.operation === "encrypt" || operation.operation === "decrypt") {
65
+ const encryption = operation.operation === "encrypt" ? operation.encryption : operation.decryption;
66
+ if (operation.keyAgreement && "externalPublicJwk" in operation.keyAgreement && operation.keyAgreement.externalPublicJwk) {
67
+ const externalPublicJwk = operation.keyAgreement.externalPublicJwk;
68
+ try {
69
+ if (externalPublicJwk.kty === "EC") assertNodeSupportedEcCrv(externalPublicJwk);
70
+ else assertNodeSupportedOkpCrv(externalPublicJwk);
71
+ } catch {
72
+ return false;
73
+ }
74
+ }
75
+ if (encryption.algorithm === "HPKE") {
76
+ if (!operation.keyAgreement || !Kms.isJwaHpkeAlgorithm(operation.keyAgreement.algorithm)) return false;
77
+ return nodeSupportedHpkeAlgorithms.includes(operation.keyAgreement.algorithm);
78
+ }
79
+ if (!nodeSupportedEncryptionAlgorithms.includes(encryption.algorithm)) return false;
71
80
  if (!operation.keyAgreement) return true;
72
81
  return nodeSupportedKeyAgreementAlgorithms.includes(operation.keyAgreement.algorithm);
73
82
  }
@@ -197,6 +206,24 @@ var NodeKeyManagementService = class {
197
206
  }
198
207
  async encrypt(agentContext, options) {
199
208
  const { data, encryption, key } = options;
209
+ if (encryption.algorithm === "HPKE") {
210
+ if (!key.keyAgreement || !Kms.isKmsKeyAgreementEncryptHpke(key.keyAgreement)) throw new Kms.KeyManagementError(`Encryption algorithm 'HPKE' can only be used with an integrated-encryption HPKE key agreement algorithm`);
211
+ const { keyAgreement } = key;
212
+ Kms.assertAllowedKeyDerivationAlgForKey(keyAgreement.externalPublicJwk, keyAgreement.algorithm);
213
+ Kms.assertKeyAllowsDerive(keyAgreement.externalPublicJwk);
214
+ try {
215
+ return await hpkeSeal({
216
+ algorithm: keyAgreement.algorithm,
217
+ recipientPublicJwk: keyAgreement.externalPublicJwk,
218
+ data,
219
+ info: keyAgreement.info,
220
+ aad: encryption.aad
221
+ });
222
+ } catch (error) {
223
+ if (error instanceof Kms.KeyManagementError) throw error;
224
+ throw new Kms.KeyManagementError("Error encrypting", { cause: error });
225
+ }
226
+ }
200
227
  Kms.assertSupportedEncryptionAlgorithm(encryption, nodeSupportedEncryptionAlgorithms, this.backend);
201
228
  let encryptionKey;
202
229
  let encryptedKey;
@@ -224,7 +251,7 @@ var NodeKeyManagementService = class {
224
251
  Kms.assertAllowedEncryptionAlgForKey(encryptionKey, encryption.algorithm);
225
252
  Kms.assertKeyAllowsEncrypt(encryptionKey);
226
253
  return {
227
- ...await performEncrypt(encryptionKey, options.encryption, data),
254
+ ...await performEncrypt(encryptionKey, encryption, data),
228
255
  encryptedKey
229
256
  };
230
257
  } catch (error) {
@@ -234,6 +261,27 @@ var NodeKeyManagementService = class {
234
261
  }
235
262
  async decrypt(agentContext, options) {
236
263
  const { decryption, encrypted, key } = options;
264
+ if (decryption.algorithm === "HPKE") {
265
+ if (!key.keyAgreement || !Kms.isKmsKeyAgreementDecryptHpke(key.keyAgreement)) throw new Kms.KeyManagementError(`Decryption algorithm 'HPKE' can only be used with an integrated-encryption HPKE key agreement algorithm`);
266
+ const { keyAgreement } = key;
267
+ const recipientPrivateJwk = await this.getKeyAsserted(agentContext, keyAgreement.keyId);
268
+ Kms.assertJwkAsymmetric(recipientPrivateJwk, keyAgreement.keyId);
269
+ Kms.assertAllowedKeyDerivationAlgForKey(recipientPrivateJwk, keyAgreement.algorithm);
270
+ Kms.assertKeyAllowsDerive(recipientPrivateJwk);
271
+ try {
272
+ return { data: await hpkeOpen({
273
+ algorithm: keyAgreement.algorithm,
274
+ recipientPrivateJwk,
275
+ encapsulatedKey: keyAgreement.encapsulatedKey,
276
+ encrypted,
277
+ info: keyAgreement.info,
278
+ aad: decryption.aad
279
+ }) };
280
+ } catch (error) {
281
+ if (error instanceof Kms.KeyManagementError) throw error;
282
+ throw new Kms.KeyManagementError("Error decrypting", { cause: error });
283
+ }
284
+ }
237
285
  Kms.assertSupportedEncryptionAlgorithm(decryption, nodeSupportedEncryptionAlgorithms, this.backend);
238
286
  let decryptionKey;
239
287
  if (key.keyId) decryptionKey = await this.getKeyAsserted(agentContext, key.keyId);
@@ -273,7 +321,7 @@ var NodeKeyManagementService = class {
273
321
  if (await _classPrivateFieldGet2(_storage, this).get(agentContext, keyId)) throw new Kms.KeyManagementKeyExistsError(keyId, this.backend);
274
322
  }
275
323
  };
276
-
277
324
  //#endregion
278
325
  export { NodeKeyManagementService };
326
+
279
327
  //# sourceMappingURL=NodeKeyManagementService.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"NodeKeyManagementService.mjs","names":[],"sources":["../../src/kms/NodeKeyManagementService.ts"],"sourcesContent":["import { createPrivateKey, createSecretKey, randomBytes, randomUUID } from 'node:crypto'\nimport type { AgentContext } from '@credo-ts/core'\nimport { Kms, TypedArrayEncoder } from '@credo-ts/core'\nimport {\n assertNodeSupportedEcCrv,\n assertNodeSupportedOctAlgorithm,\n assertNodeSupportedOkpCrv,\n createEcKey,\n createOctKey,\n createOkpKey,\n createRsaKey,\n} from './crypto/createKey'\nimport { performDecrypt } from './crypto/decrypt'\nimport { deriveDecryptionKey, deriveEncryptionKey, nodeSupportedKeyAgreementAlgorithms } from './crypto/deriveKey'\nimport { nodeSupportedEncryptionAlgorithms, performEncrypt } from './crypto/encrypt'\nimport { nodeSupportedJwaAlgorithm, performSign } from './crypto/sign'\nimport { performVerify } from './crypto/verify'\nimport type { NodeKeyManagementStorage } from './NodeKeyManagementStorage'\n\nexport class NodeKeyManagementService implements Kms.KeyManagementService {\n public readonly backend = 'node'\n\n #storage: NodeKeyManagementStorage\n\n public constructor(storage: NodeKeyManagementStorage) {\n this.#storage = storage\n }\n\n public isOperationSupported(_agentContext: AgentContext, operation: Kms.KmsOperation): boolean {\n if (operation.operation === 'deleteKey') return true\n if (operation.operation === 'randomBytes') return true\n\n if (operation.operation === 'createKey') {\n // TODO: probably clean to split the assert methods so we don't need try/catch here\n try {\n if (operation.type.kty === 'RSA') {\n return true\n }\n\n if (operation.type.kty === 'EC') {\n assertNodeSupportedEcCrv(operation.type)\n return true\n }\n\n if (operation.type.kty === 'OKP') {\n assertNodeSupportedOkpCrv(operation.type)\n return true\n }\n\n if (operation.type.kty === 'oct') {\n assertNodeSupportedOctAlgorithm(operation.type)\n return true\n }\n } catch {\n return false\n }\n\n return false\n }\n\n if (operation.operation === 'importKey') {\n try {\n if (operation.privateJwk.kty === 'RSA' || operation.privateJwk.kty === 'oct') {\n return true\n }\n\n if (operation.privateJwk.kty === 'EC') {\n assertNodeSupportedEcCrv({ kty: operation.privateJwk.kty, crv: operation.privateJwk.crv })\n return true\n }\n\n if (operation.privateJwk.kty === 'OKP') {\n assertNodeSupportedOkpCrv({ kty: operation.privateJwk.kty, crv: operation.privateJwk.crv })\n return true\n }\n } catch {\n return false\n }\n }\n\n if (operation.operation === 'sign' || operation.operation === 'verify') {\n return nodeSupportedJwaAlgorithm.includes(operation.algorithm)\n }\n\n if (operation.operation === 'encrypt') {\n const isSupportedEncryptionAlgorithm = nodeSupportedEncryptionAlgorithms.includes(\n operation.encryption.algorithm as (typeof nodeSupportedEncryptionAlgorithms)[number]\n )\n if (!isSupportedEncryptionAlgorithm) return false\n if (!operation.keyAgreement) return true\n\n return nodeSupportedKeyAgreementAlgorithms.includes(\n operation.keyAgreement.algorithm as (typeof nodeSupportedKeyAgreementAlgorithms)[number]\n )\n }\n\n if (operation.operation === 'decrypt') {\n const isSupportedEncryptionAlgorithm = nodeSupportedEncryptionAlgorithms.includes(\n operation.decryption.algorithm as (typeof nodeSupportedEncryptionAlgorithms)[number]\n )\n if (!isSupportedEncryptionAlgorithm) return false\n if (!operation.keyAgreement) return true\n\n return nodeSupportedKeyAgreementAlgorithms.includes(\n operation.keyAgreement.algorithm as (typeof nodeSupportedKeyAgreementAlgorithms)[number]\n )\n }\n\n return false\n }\n\n public randomBytes(_agentContext: AgentContext, options: Kms.KmsRandomBytesOptions): Kms.KmsRandomBytesReturn {\n return randomBytes(options.length)\n }\n\n public async getPublicKey(agentContext: AgentContext, keyId: string): Promise<Kms.KmsJwkPublic | null> {\n const privateJwk = await this.#storage.get(agentContext, keyId)\n if (!privateJwk) return null\n\n return Kms.publicJwkFromPrivateJwk(privateJwk)\n }\n\n public async importKey<Jwk extends Kms.KmsJwkPrivate>(\n agentContext: AgentContext,\n options: Kms.KmsImportKeyOptions<Jwk>\n ): Promise<Kms.KmsImportKeyReturn<Jwk>> {\n const { kid } = options.privateJwk\n\n if (kid) await this.assertKeyNotExists(agentContext, kid)\n\n const privateJwk = {\n ...options.privateJwk,\n kid: kid ?? randomUUID(),\n }\n\n try {\n if (privateJwk.kty === 'oct') {\n // Just check if we can create a secret key instance\n createSecretKey(TypedArrayEncoder.fromBase64Url(privateJwk.k)).export({ format: 'jwk' })\n } else if (privateJwk.kty === 'EC') {\n assertNodeSupportedEcCrv({ kty: privateJwk.kty, crv: privateJwk.crv })\n // This validates the JWK\n createPrivateKey({\n format: 'jwk',\n key: privateJwk,\n })\n } else if (privateJwk.kty === 'OKP') {\n assertNodeSupportedOkpCrv({ kty: privateJwk.kty, crv: privateJwk.crv })\n // This validates the JWK\n createPrivateKey({\n format: 'jwk',\n key: privateJwk,\n })\n } else if (privateJwk.kty === 'RSA') {\n // This validates the JWK\n createPrivateKey({\n format: 'jwk',\n key: privateJwk,\n })\n } else {\n // All kty values supported for now, but can change in the future\n // @ts-expect-error\n throw new Kms.KeyManagementAlgorithmNotSupportedError(`kty '${privateJwk.kty}'`, this.backend)\n }\n\n await this.#storage.set(agentContext, privateJwk.kid, privateJwk)\n const publicJwk = Kms.publicJwkFromPrivateJwk(privateJwk)\n\n return {\n keyId: privateJwk.kid,\n publicJwk: {\n ...publicJwk,\n kid: privateJwk.kid,\n },\n } as Kms.KmsImportKeyReturn<Jwk>\n } catch (error) {\n if (error instanceof Kms.KeyManagementError) throw error\n\n throw new Kms.KeyManagementError('Error importing key', { cause: error })\n }\n }\n\n public async deleteKey(agentContext: AgentContext, options: Kms.KmsDeleteKeyOptions): Promise<boolean> {\n return await this.#storage.delete(agentContext, options.keyId)\n }\n\n public async createKey<Type extends Kms.KmsCreateKeyType>(\n agentContext: AgentContext,\n options: Kms.KmsCreateKeyOptions<Type>\n ): Promise<Kms.KmsCreateKeyReturn<Type>> {\n const { type, keyId } = options\n\n if (keyId) await this.assertKeyNotExists(agentContext, keyId)\n\n try {\n let jwks: { publicJwk: Kms.KmsJwkPublic; privateJwk: Kms.KmsJwkPrivate }\n if (type.kty === 'EC') {\n assertNodeSupportedEcCrv(type)\n jwks = await createEcKey(type)\n } else if (type.kty === 'OKP') {\n assertNodeSupportedOkpCrv(type)\n jwks = await createOkpKey(type)\n } else if (type.kty === 'RSA') {\n jwks = await createRsaKey(type)\n } else if (type.kty === 'oct') {\n assertNodeSupportedOctAlgorithm(type)\n jwks = await createOctKey(type)\n } else {\n // @ts-expect-error\n throw new Kms.KeyManagementAlgorithmNotSupportedError(`kty '${type.kty}'`, this.backend)\n }\n\n jwks.privateJwk.kid = keyId ?? randomUUID()\n jwks.publicJwk.kid = jwks.privateJwk.kid\n\n await this.#storage.set(agentContext, jwks.privateJwk.kid, jwks.privateJwk)\n\n return {\n publicJwk: jwks.publicJwk as Kms.KmsCreateKeyReturn<Type>['publicJwk'],\n keyId: jwks.publicJwk.kid,\n }\n } catch (error) {\n if (error instanceof Kms.KeyManagementError) throw error\n\n throw new Kms.KeyManagementError('Error creating key', { cause: error })\n }\n }\n\n public async sign(agentContext: AgentContext, options: Kms.KmsSignOptions): Promise<Kms.KmsSignReturn> {\n const { keyId, algorithm, data } = options\n\n // 1. Retrieve the key\n const key = await this.getKeyAsserted(agentContext, keyId)\n\n try {\n // 2. Validate alg and use for key\n Kms.assertAllowedSigningAlgForKey(key, algorithm)\n Kms.assertKeyAllowsSign(key)\n\n // 3. Perform the signing operation\n const signature = await performSign(key, algorithm, data)\n\n return {\n signature,\n }\n } catch (error) {\n if (error instanceof Kms.KeyManagementError) throw error\n\n throw new Kms.KeyManagementError('Error signing with key', { cause: error })\n }\n }\n\n public async verify(agentContext: AgentContext, options: Kms.KmsVerifyOptions): Promise<Kms.KmsVerifyReturn> {\n const { algorithm, data, signature } = options\n\n try {\n let key: Exclude<Kms.KmsJwkPublic, Kms.KmsJwkPublicOct> | Kms.KmsJwkPrivate\n if (options.key.keyId) {\n key = await this.getKeyAsserted(agentContext, options.key.keyId)\n } else if (options.key.publicJwk?.kty === 'EC') {\n assertNodeSupportedEcCrv(options.key.publicJwk)\n key = options.key.publicJwk\n } else if (options.key.publicJwk?.kty === 'OKP') {\n assertNodeSupportedOkpCrv(options.key.publicJwk)\n key = options.key.publicJwk\n } else if (options.key.publicJwk?.kty === 'RSA') {\n key = options.key.publicJwk\n } else {\n // @ts-expect-error\n throw new Kms.KeyManagementAlgorithmNotSupportedError(`kty ${options.key.kty}`, this.backend)\n }\n\n // 2. Validate alg and use for key\n Kms.assertAllowedSigningAlgForKey(key, algorithm)\n Kms.assertKeyAllowsVerify(key)\n\n // 3. Perform the verify operation\n const verified = await performVerify(key, algorithm, data, signature)\n if (verified) {\n return {\n verified: true,\n publicJwk: Kms.publicJwkFromPrivateJwk(key),\n }\n }\n\n return {\n verified: false,\n }\n } catch (error) {\n if (error instanceof Kms.KeyManagementError) throw error\n\n throw new Kms.KeyManagementError('Error verifying with key', { cause: error })\n }\n }\n\n public async encrypt(agentContext: AgentContext, options: Kms.KmsEncryptOptions): Promise<Kms.KmsEncryptReturn> {\n const { data, encryption, key } = options\n\n Kms.assertSupportedEncryptionAlgorithm(encryption, nodeSupportedEncryptionAlgorithms, this.backend)\n\n let encryptionKey: Kms.KmsJwkPrivate\n let encryptedKey: Kms.KmsEncryptedKey | undefined\n\n if (key.keyId) {\n encryptionKey = await this.getKeyAsserted(agentContext, key.keyId)\n } else if (key.privateJwk) {\n encryptionKey = key.privateJwk\n } else if (key.keyAgreement) {\n Kms.assertAllowedKeyDerivationAlgForKey(key.keyAgreement.externalPublicJwk, key.keyAgreement.algorithm)\n Kms.assertKeyAllowsDerive(key.keyAgreement.externalPublicJwk)\n Kms.assertSupportedKeyAgreementAlgorithm(key.keyAgreement, nodeSupportedKeyAgreementAlgorithms, this.backend)\n\n const privateJwk = await this.getKeyAsserted(agentContext, key.keyAgreement.keyId)\n Kms.assertJwkAsymmetric(privateJwk, key.keyAgreement.keyId)\n Kms.assertAllowedKeyDerivationAlgForKey(privateJwk, key.keyAgreement.algorithm)\n Kms.assertKeyAllowsDerive(privateJwk)\n Kms.assertAsymmetricJwkKeyTypeMatches(privateJwk, key.keyAgreement.externalPublicJwk)\n\n const { contentEncryptionKey, encryptedContentEncryptionKey } = await deriveEncryptionKey({\n keyAgreement: key.keyAgreement,\n encryption,\n privateJwk,\n })\n\n encryptionKey = contentEncryptionKey\n encryptedKey = encryptedContentEncryptionKey\n } else {\n throw new Kms.KeyManagementError('Unexpected key parameter for encrypt')\n }\n\n if (encryptionKey.kty !== 'oct') {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(\n `kty '${encryptionKey.kty} for content encryption'`,\n this.backend\n )\n }\n\n try {\n // 2. Validate alg and use for key\n Kms.assertAllowedEncryptionAlgForKey(encryptionKey, encryption.algorithm)\n Kms.assertKeyAllowsEncrypt(encryptionKey)\n\n // 3. Perform the encryption operation\n const encrypted = await performEncrypt(encryptionKey, options.encryption, data)\n return {\n ...encrypted,\n encryptedKey,\n }\n } catch (error) {\n if (error instanceof Kms.KeyManagementError) throw error\n\n throw new Kms.KeyManagementError('Error encrypting', { cause: error })\n }\n }\n\n public async decrypt(agentContext: AgentContext, options: Kms.KmsDecryptOptions): Promise<Kms.KmsDecryptReturn> {\n const { decryption, encrypted, key } = options\n\n Kms.assertSupportedEncryptionAlgorithm(decryption, nodeSupportedEncryptionAlgorithms, this.backend)\n\n let decryptionKey: Kms.KmsJwkPrivate\n if (key.keyId) {\n decryptionKey = await this.getKeyAsserted(agentContext, key.keyId)\n } else if (key.privateJwk) {\n decryptionKey = key.privateJwk\n } else if (key.keyAgreement) {\n Kms.assertSupportedKeyAgreementAlgorithm(key.keyAgreement, nodeSupportedKeyAgreementAlgorithms, this.backend)\n Kms.assertAllowedKeyDerivationAlgForKey(key.keyAgreement.externalPublicJwk, key.keyAgreement.algorithm)\n Kms.assertKeyAllowsDerive(key.keyAgreement.externalPublicJwk)\n\n const privateJwk = await this.getKeyAsserted(agentContext, key.keyAgreement.keyId)\n Kms.assertJwkAsymmetric(privateJwk, key.keyAgreement.keyId)\n Kms.assertAllowedKeyDerivationAlgForKey(privateJwk, key.keyAgreement.algorithm)\n Kms.assertKeyAllowsDerive(privateJwk)\n Kms.assertAsymmetricJwkKeyTypeMatches(privateJwk, key.keyAgreement.externalPublicJwk)\n\n const { contentEncryptionKey } = await deriveDecryptionKey({\n keyAgreement: key.keyAgreement,\n decryption,\n privateJwk,\n })\n\n decryptionKey = contentEncryptionKey\n } else {\n throw new Kms.KeyManagementError('Unexpected key parameter for decrypt')\n }\n\n if (decryptionKey.kty !== 'oct') {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(\n `kty '${decryptionKey.kty}' for content encryption`,\n this.backend\n )\n }\n\n try {\n // 2. Validate alg and use for key\n Kms.assertAllowedEncryptionAlgForKey(decryptionKey, decryption.algorithm)\n Kms.assertKeyAllowsEncrypt(decryptionKey)\n\n // 3. Perform the decryption operation\n return await performDecrypt(decryptionKey, decryption, encrypted)\n } catch (error) {\n if (error instanceof Kms.KeyManagementError) throw error\n\n throw new Kms.KeyManagementError('Error decrypting', { cause: error })\n }\n }\n\n private async getKeyAsserted(agentContext: AgentContext, keyId: string) {\n const storageKey = await this.#storage.get(agentContext, keyId)\n if (!storageKey) {\n throw new Kms.KeyManagementKeyNotFoundError(keyId, [this.backend])\n }\n\n return storageKey\n }\n\n private async assertKeyNotExists(agentContext: AgentContext, keyId: string) {\n const storageKey = await this.#storage.get(agentContext, keyId)\n\n if (storageKey) {\n throw new Kms.KeyManagementKeyExistsError(keyId, this.backend)\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAmBA,IAAa,2BAAb,MAA0E;CAKxE,AAAO,YAAY,SAAmC;OAJtC,UAAU;;AAKxB,yCAAgB,QAAO;;CAGzB,AAAO,qBAAqB,eAA6B,WAAsC;AAC7F,MAAI,UAAU,cAAc,YAAa,QAAO;AAChD,MAAI,UAAU,cAAc,cAAe,QAAO;AAElD,MAAI,UAAU,cAAc,aAAa;AAEvC,OAAI;AACF,QAAI,UAAU,KAAK,QAAQ,MACzB,QAAO;AAGT,QAAI,UAAU,KAAK,QAAQ,MAAM;AAC/B,8BAAyB,UAAU,KAAK;AACxC,YAAO;;AAGT,QAAI,UAAU,KAAK,QAAQ,OAAO;AAChC,+BAA0B,UAAU,KAAK;AACzC,YAAO;;AAGT,QAAI,UAAU,KAAK,QAAQ,OAAO;AAChC,qCAAgC,UAAU,KAAK;AAC/C,YAAO;;WAEH;AACN,WAAO;;AAGT,UAAO;;AAGT,MAAI,UAAU,cAAc,YAC1B,KAAI;AACF,OAAI,UAAU,WAAW,QAAQ,SAAS,UAAU,WAAW,QAAQ,MACrE,QAAO;AAGT,OAAI,UAAU,WAAW,QAAQ,MAAM;AACrC,6BAAyB;KAAE,KAAK,UAAU,WAAW;KAAK,KAAK,UAAU,WAAW;KAAK,CAAC;AAC1F,WAAO;;AAGT,OAAI,UAAU,WAAW,QAAQ,OAAO;AACtC,8BAA0B;KAAE,KAAK,UAAU,WAAW;KAAK,KAAK,UAAU,WAAW;KAAK,CAAC;AAC3F,WAAO;;UAEH;AACN,UAAO;;AAIX,MAAI,UAAU,cAAc,U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AI,8BAA8B,OAAO,CAAC,KAAK,QAAQ,CAAC;AAGpE,SAAO;;CAGT,MAAc,mBAAmB,cAA4B,OAAe;AAG1E,MAFmB,uCAAM,KAAa,CAAC,IAAI,cAAc,MAAM,CAG7D,OAAM,IAAI,IAAI,4BAA4B,OAAO,KAAK,QAAQ"}
1
+ {"version":3,"file":"NodeKeyManagementService.mjs","names":[],"sources":["../../src/kms/NodeKeyManagementService.ts"],"sourcesContent":["import { createPrivateKey, createSecretKey, randomBytes, randomUUID } from 'node:crypto'\nimport type { AgentContext } from '@credo-ts/core'\nimport { Kms, TypedArrayEncoder } from '@credo-ts/core'\nimport {\n assertNodeSupportedEcCrv,\n assertNodeSupportedOctAlgorithm,\n assertNodeSupportedOkpCrv,\n createEcKey,\n createOctKey,\n createOkpKey,\n createRsaKey,\n} from './crypto/createKey'\nimport { performDecrypt } from './crypto/decrypt'\nimport { deriveDecryptionKey, deriveEncryptionKey, nodeSupportedKeyAgreementAlgorithms } from './crypto/deriveKey'\nimport { nodeSupportedEncryptionAlgorithms, performEncrypt } from './crypto/encrypt'\nimport { hpkeOpen, hpkeSeal, nodeSupportedHpkeAlgorithms } from './crypto/hpke'\nimport { nodeSupportedJwaAlgorithm, performSign } from './crypto/sign'\nimport { performVerify } from './crypto/verify'\nimport type { NodeKeyManagementStorage } from './NodeKeyManagementStorage'\n\nexport class NodeKeyManagementService implements Kms.KeyManagementService {\n public readonly backend = 'node'\n\n #storage: NodeKeyManagementStorage\n\n public constructor(storage: NodeKeyManagementStorage) {\n this.#storage = storage\n }\n\n public isOperationSupported(_agentContext: AgentContext, operation: Kms.KmsOperation): boolean {\n if (operation.operation === 'deleteKey') return true\n if (operation.operation === 'randomBytes') return true\n\n if (operation.operation === 'createKey') {\n // TODO: probably clean to split the assert methods so we don't need try/catch here\n try {\n if (operation.type.kty === 'RSA') {\n return true\n }\n\n if (operation.type.kty === 'EC') {\n assertNodeSupportedEcCrv(operation.type)\n return true\n }\n\n if (operation.type.kty === 'OKP') {\n assertNodeSupportedOkpCrv(operation.type)\n return true\n }\n\n if (operation.type.kty === 'oct') {\n assertNodeSupportedOctAlgorithm(operation.type)\n return true\n }\n } catch {\n return false\n }\n\n return false\n }\n\n if (operation.operation === 'importKey') {\n try {\n if (operation.privateJwk.kty === 'RSA' || operation.privateJwk.kty === 'oct') {\n return true\n }\n\n if (operation.privateJwk.kty === 'EC') {\n assertNodeSupportedEcCrv({ kty: operation.privateJwk.kty, crv: operation.privateJwk.crv })\n return true\n }\n\n if (operation.privateJwk.kty === 'OKP') {\n assertNodeSupportedOkpCrv({ kty: operation.privateJwk.kty, crv: operation.privateJwk.crv })\n return true\n }\n } catch {\n return false\n }\n }\n\n if (operation.operation === 'sign' || operation.operation === 'verify') {\n return nodeSupportedJwaAlgorithm.includes(operation.algorithm)\n }\n\n if (operation.operation === 'encrypt' || operation.operation === 'decrypt') {\n const encryption = operation.operation === 'encrypt' ? operation.encryption : operation.decryption\n\n // We can only perform key agreement with curves we support. We also can't create the\n // ephemeral key for e.g. ECDH-ES if the curve is not supported.\n if (\n operation.keyAgreement &&\n 'externalPublicJwk' in operation.keyAgreement &&\n operation.keyAgreement.externalPublicJwk\n ) {\n const externalPublicJwk = operation.keyAgreement.externalPublicJwk\n try {\n if (externalPublicJwk.kty === 'EC') assertNodeSupportedEcCrv(externalPublicJwk)\n else assertNodeSupportedOkpCrv(externalPublicJwk)\n } catch {\n return false\n }\n }\n\n // HPKE is an integrated encryption mode: the suite fixes the AEAD, so the HPKE key agreement\n // algorithm is all there is to check.\n if (encryption.algorithm === 'HPKE') {\n if (!operation.keyAgreement || !Kms.isJwaHpkeAlgorithm(operation.keyAgreement.algorithm)) return false\n\n return nodeSupportedHpkeAlgorithms.includes(\n operation.keyAgreement.algorithm as (typeof nodeSupportedHpkeAlgorithms)[number]\n )\n }\n\n const isSupportedEncryptionAlgorithm = nodeSupportedEncryptionAlgorithms.includes(\n encryption.algorithm as (typeof nodeSupportedEncryptionAlgorithms)[number]\n )\n if (!isSupportedEncryptionAlgorithm) return false\n if (!operation.keyAgreement) return true\n\n return nodeSupportedKeyAgreementAlgorithms.includes(\n operation.keyAgreement.algorithm as (typeof nodeSupportedKeyAgreementAlgorithms)[number]\n )\n }\n\n return false\n }\n\n public randomBytes(_agentContext: AgentContext, options: Kms.KmsRandomBytesOptions): Kms.KmsRandomBytesReturn {\n return randomBytes(options.length)\n }\n\n public async getPublicKey(agentContext: AgentContext, keyId: string): Promise<Kms.KmsJwkPublic | null> {\n const privateJwk = await this.#storage.get(agentContext, keyId)\n if (!privateJwk) return null\n\n return Kms.publicJwkFromPrivateJwk(privateJwk)\n }\n\n public async importKey<Jwk extends Kms.KmsJwkPrivate>(\n agentContext: AgentContext,\n options: Kms.KmsImportKeyOptions<Jwk>\n ): Promise<Kms.KmsImportKeyReturn<Jwk>> {\n const { kid } = options.privateJwk\n\n if (kid) await this.assertKeyNotExists(agentContext, kid)\n\n const privateJwk = {\n ...options.privateJwk,\n kid: kid ?? randomUUID(),\n }\n\n try {\n if (privateJwk.kty === 'oct') {\n // Just check if we can create a secret key instance\n createSecretKey(TypedArrayEncoder.fromBase64Url(privateJwk.k)).export({ format: 'jwk' })\n } else if (privateJwk.kty === 'EC') {\n assertNodeSupportedEcCrv({ kty: privateJwk.kty, crv: privateJwk.crv })\n // This validates the JWK\n createPrivateKey({\n format: 'jwk',\n key: privateJwk,\n })\n } else if (privateJwk.kty === 'OKP') {\n assertNodeSupportedOkpCrv({ kty: privateJwk.kty, crv: privateJwk.crv })\n // This validates the JWK\n createPrivateKey({\n format: 'jwk',\n key: privateJwk,\n })\n } else if (privateJwk.kty === 'RSA') {\n // This validates the JWK\n createPrivateKey({\n format: 'jwk',\n key: privateJwk,\n })\n } else {\n // All kty values supported for now, but can change in the future\n // @ts-expect-error\n throw new Kms.KeyManagementAlgorithmNotSupportedError(`kty '${privateJwk.kty}'`, this.backend)\n }\n\n await this.#storage.set(agentContext, privateJwk.kid, privateJwk)\n const publicJwk = Kms.publicJwkFromPrivateJwk(privateJwk)\n\n return {\n keyId: privateJwk.kid,\n publicJwk: {\n ...publicJwk,\n kid: privateJwk.kid,\n },\n } as Kms.KmsImportKeyReturn<Jwk>\n } catch (error) {\n if (error instanceof Kms.KeyManagementError) throw error\n\n throw new Kms.KeyManagementError('Error importing key', { cause: error })\n }\n }\n\n public async deleteKey(agentContext: AgentContext, options: Kms.KmsDeleteKeyOptions): Promise<boolean> {\n return await this.#storage.delete(agentContext, options.keyId)\n }\n\n public async createKey<Type extends Kms.KmsCreateKeyType>(\n agentContext: AgentContext,\n options: Kms.KmsCreateKeyOptions<Type>\n ): Promise<Kms.KmsCreateKeyReturn<Type>> {\n const { type, keyId } = options\n\n if (keyId) await this.assertKeyNotExists(agentContext, keyId)\n\n try {\n let jwks: { publicJwk: Kms.KmsJwkPublic; privateJwk: Kms.KmsJwkPrivate }\n if (type.kty === 'EC') {\n assertNodeSupportedEcCrv(type)\n jwks = await createEcKey(type)\n } else if (type.kty === 'OKP') {\n assertNodeSupportedOkpCrv(type)\n jwks = await createOkpKey(type)\n } else if (type.kty === 'RSA') {\n jwks = await createRsaKey(type)\n } else if (type.kty === 'oct') {\n assertNodeSupportedOctAlgorithm(type)\n jwks = await createOctKey(type)\n } else {\n // @ts-expect-error\n throw new Kms.KeyManagementAlgorithmNotSupportedError(`kty '${type.kty}'`, this.backend)\n }\n\n jwks.privateJwk.kid = keyId ?? randomUUID()\n jwks.publicJwk.kid = jwks.privateJwk.kid\n\n await this.#storage.set(agentContext, jwks.privateJwk.kid, jwks.privateJwk)\n\n return {\n publicJwk: jwks.publicJwk as Kms.KmsCreateKeyReturn<Type>['publicJwk'],\n keyId: jwks.publicJwk.kid,\n }\n } catch (error) {\n if (error instanceof Kms.KeyManagementError) throw error\n\n throw new Kms.KeyManagementError('Error creating key', { cause: error })\n }\n }\n\n public async sign(agentContext: AgentContext, options: Kms.KmsSignOptions): Promise<Kms.KmsSignReturn> {\n const { keyId, algorithm, data } = options\n\n // 1. Retrieve the key\n const key = await this.getKeyAsserted(agentContext, keyId)\n\n try {\n // 2. Validate alg and use for key\n Kms.assertAllowedSigningAlgForKey(key, algorithm)\n Kms.assertKeyAllowsSign(key)\n\n // 3. Perform the signing operation\n const signature = await performSign(key, algorithm, data)\n\n return {\n signature,\n }\n } catch (error) {\n if (error instanceof Kms.KeyManagementError) throw error\n\n throw new Kms.KeyManagementError('Error signing with key', { cause: error })\n }\n }\n\n public async verify(agentContext: AgentContext, options: Kms.KmsVerifyOptions): Promise<Kms.KmsVerifyReturn> {\n const { algorithm, data, signature } = options\n\n try {\n let key: Exclude<Kms.KmsJwkPublic, Kms.KmsJwkPublicOct> | Kms.KmsJwkPrivate\n if (options.key.keyId) {\n key = await this.getKeyAsserted(agentContext, options.key.keyId)\n } else if (options.key.publicJwk?.kty === 'EC') {\n assertNodeSupportedEcCrv(options.key.publicJwk)\n key = options.key.publicJwk\n } else if (options.key.publicJwk?.kty === 'OKP') {\n assertNodeSupportedOkpCrv(options.key.publicJwk)\n key = options.key.publicJwk\n } else if (options.key.publicJwk?.kty === 'RSA') {\n key = options.key.publicJwk\n } else {\n // @ts-expect-error\n throw new Kms.KeyManagementAlgorithmNotSupportedError(`kty ${options.key.kty}`, this.backend)\n }\n\n // 2. Validate alg and use for key\n Kms.assertAllowedSigningAlgForKey(key, algorithm)\n Kms.assertKeyAllowsVerify(key)\n\n // 3. Perform the verify operation\n const verified = await performVerify(key, algorithm, data, signature)\n if (verified) {\n return {\n verified: true,\n publicJwk: Kms.publicJwkFromPrivateJwk(key),\n }\n }\n\n return {\n verified: false,\n }\n } catch (error) {\n if (error instanceof Kms.KeyManagementError) throw error\n\n throw new Kms.KeyManagementError('Error verifying with key', { cause: error })\n }\n }\n\n public async encrypt(agentContext: AgentContext, options: Kms.KmsEncryptOptions): Promise<Kms.KmsEncryptReturn> {\n const { data, encryption, key } = options\n\n if (encryption.algorithm === 'HPKE') {\n if (!key.keyAgreement || !Kms.isKmsKeyAgreementEncryptHpke(key.keyAgreement)) {\n throw new Kms.KeyManagementError(\n `Encryption algorithm 'HPKE' can only be used with an integrated-encryption HPKE key agreement algorithm`\n )\n }\n\n const { keyAgreement } = key\n Kms.assertAllowedKeyDerivationAlgForKey(keyAgreement.externalPublicJwk, keyAgreement.algorithm)\n Kms.assertKeyAllowsDerive(keyAgreement.externalPublicJwk)\n\n try {\n return await hpkeSeal({\n algorithm: keyAgreement.algorithm,\n recipientPublicJwk: keyAgreement.externalPublicJwk,\n data,\n info: keyAgreement.info,\n aad: encryption.aad,\n })\n } catch (error) {\n if (error instanceof Kms.KeyManagementError) throw error\n throw new Kms.KeyManagementError('Error encrypting', { cause: error })\n }\n }\n\n Kms.assertSupportedEncryptionAlgorithm(encryption, nodeSupportedEncryptionAlgorithms, this.backend)\n\n let encryptionKey: Kms.KmsJwkPrivate\n let encryptedKey: Kms.KmsEncryptedKey | undefined\n\n if (key.keyId) {\n encryptionKey = await this.getKeyAsserted(agentContext, key.keyId)\n } else if (key.privateJwk) {\n encryptionKey = key.privateJwk\n } else if (key.keyAgreement) {\n Kms.assertAllowedKeyDerivationAlgForKey(key.keyAgreement.externalPublicJwk, key.keyAgreement.algorithm)\n Kms.assertKeyAllowsDerive(key.keyAgreement.externalPublicJwk)\n Kms.assertSupportedKeyAgreementAlgorithm(key.keyAgreement, nodeSupportedKeyAgreementAlgorithms, this.backend)\n\n const privateJwk = await this.getKeyAsserted(agentContext, key.keyAgreement.keyId)\n Kms.assertJwkAsymmetric(privateJwk, key.keyAgreement.keyId)\n Kms.assertAllowedKeyDerivationAlgForKey(privateJwk, key.keyAgreement.algorithm)\n Kms.assertKeyAllowsDerive(privateJwk)\n Kms.assertAsymmetricJwkKeyTypeMatches(privateJwk, key.keyAgreement.externalPublicJwk)\n\n const { contentEncryptionKey, encryptedContentEncryptionKey } = await deriveEncryptionKey({\n keyAgreement: key.keyAgreement,\n encryption,\n privateJwk,\n })\n\n encryptionKey = contentEncryptionKey\n encryptedKey = encryptedContentEncryptionKey\n } else {\n throw new Kms.KeyManagementError('Unexpected key parameter for encrypt')\n }\n\n if (encryptionKey.kty !== 'oct') {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(\n `kty '${encryptionKey.kty} for content encryption'`,\n this.backend\n )\n }\n\n try {\n // 2. Validate alg and use for key\n Kms.assertAllowedEncryptionAlgForKey(encryptionKey, encryption.algorithm)\n Kms.assertKeyAllowsEncrypt(encryptionKey)\n\n // 3. Perform the encryption operation\n const encrypted = await performEncrypt(encryptionKey, encryption, data)\n return {\n ...encrypted,\n encryptedKey,\n }\n } catch (error) {\n if (error instanceof Kms.KeyManagementError) throw error\n\n throw new Kms.KeyManagementError('Error encrypting', { cause: error })\n }\n }\n\n public async decrypt(agentContext: AgentContext, options: Kms.KmsDecryptOptions): Promise<Kms.KmsDecryptReturn> {\n const { decryption, encrypted, key } = options\n\n if (decryption.algorithm === 'HPKE') {\n if (!key.keyAgreement || !Kms.isKmsKeyAgreementDecryptHpke(key.keyAgreement)) {\n throw new Kms.KeyManagementError(\n `Decryption algorithm 'HPKE' can only be used with an integrated-encryption HPKE key agreement algorithm`\n )\n }\n\n const { keyAgreement } = key\n const recipientPrivateJwk = await this.getKeyAsserted(agentContext, keyAgreement.keyId)\n\n Kms.assertJwkAsymmetric(recipientPrivateJwk, keyAgreement.keyId)\n Kms.assertAllowedKeyDerivationAlgForKey(recipientPrivateJwk, keyAgreement.algorithm)\n Kms.assertKeyAllowsDerive(recipientPrivateJwk)\n\n try {\n return {\n data: await hpkeOpen({\n algorithm: keyAgreement.algorithm,\n recipientPrivateJwk,\n encapsulatedKey: keyAgreement.encapsulatedKey,\n encrypted,\n info: keyAgreement.info,\n aad: decryption.aad,\n }),\n }\n } catch (error) {\n if (error instanceof Kms.KeyManagementError) throw error\n throw new Kms.KeyManagementError('Error decrypting', { cause: error })\n }\n }\n\n Kms.assertSupportedEncryptionAlgorithm(decryption, nodeSupportedEncryptionAlgorithms, this.backend)\n\n let decryptionKey: Kms.KmsJwkPrivate\n if (key.keyId) {\n decryptionKey = await this.getKeyAsserted(agentContext, key.keyId)\n } else if (key.privateJwk) {\n decryptionKey = key.privateJwk\n } else if (key.keyAgreement) {\n Kms.assertSupportedKeyAgreementAlgorithm(key.keyAgreement, nodeSupportedKeyAgreementAlgorithms, this.backend)\n Kms.assertAllowedKeyDerivationAlgForKey(key.keyAgreement.externalPublicJwk, key.keyAgreement.algorithm)\n Kms.assertKeyAllowsDerive(key.keyAgreement.externalPublicJwk)\n\n const privateJwk = await this.getKeyAsserted(agentContext, key.keyAgreement.keyId)\n Kms.assertJwkAsymmetric(privateJwk, key.keyAgreement.keyId)\n Kms.assertAllowedKeyDerivationAlgForKey(privateJwk, key.keyAgreement.algorithm)\n Kms.assertKeyAllowsDerive(privateJwk)\n Kms.assertAsymmetricJwkKeyTypeMatches(privateJwk, key.keyAgreement.externalPublicJwk)\n\n const { contentEncryptionKey } = await deriveDecryptionKey({\n keyAgreement: key.keyAgreement,\n decryption,\n privateJwk,\n })\n\n decryptionKey = contentEncryptionKey\n } else {\n throw new Kms.KeyManagementError('Unexpected key parameter for decrypt')\n }\n\n if (decryptionKey.kty !== 'oct') {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(\n `kty '${decryptionKey.kty}' for content encryption`,\n this.backend\n )\n }\n\n try {\n // 2. Validate alg and use for key\n Kms.assertAllowedEncryptionAlgForKey(decryptionKey, decryption.algorithm)\n Kms.assertKeyAllowsEncrypt(decryptionKey)\n\n // 3. Perform the decryption operation\n return await performDecrypt(decryptionKey, decryption, encrypted)\n } catch (error) {\n if (error instanceof Kms.KeyManagementError) throw error\n\n throw new Kms.KeyManagementError('Error decrypting', { cause: error })\n }\n }\n\n private async getKeyAsserted(agentContext: AgentContext, keyId: string) {\n const storageKey = await this.#storage.get(agentContext, keyId)\n if (!storageKey) {\n throw new Kms.KeyManagementKeyNotFoundError(keyId, [this.backend])\n }\n\n return storageKey\n }\n\n private async assertKeyNotExists(agentContext: AgentContext, keyId: string) {\n const storageKey = await this.#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AAuB,aAAa;GAGxC,OAAO,MAAM,eAAe,eAAe,YAAY,SAAS;EAClE,SAAS,OAAO;GACd,IAAI,iBAAiB,IAAI,oBAAoB,MAAM;GAEnD,MAAM,IAAI,IAAI,mBAAmB,oBAAoB,EAAE,OAAO,MAAM,CAAC;EACvE;CACF;CAEA,MAAc,eAAe,cAA4B,OAAe;EACtE,MAAM,aAAa,MAAA,uBAAA,UAAM,IAAA,CAAA,CAAc,IAAI,cAAc,KAAK;EAC9D,IAAI,CAAC,YACH,MAAM,IAAI,IAAI,8BAA8B,OAAO,CAAC,KAAK,OAAO,CAAC;EAGnE,OAAO;CACT;CAEA,MAAc,mBAAmB,cAA4B,OAAe;EAG1E,IAAI,MAAA,uBAAA,UAFqB,IAAA,CAAA,CAAc,IAAI,cAAc,KAAK,GAG5D,MAAM,IAAI,IAAI,4BAA4B,OAAO,KAAK,OAAO;CAEjE;AACF"}
@@ -1,7 +1,6 @@
1
1
  import { AgentContext, CanBePromise, Kms } from "@credo-ts/core";
2
-
3
2
  //#region src/kms/NodeKeyManagementStorage.d.ts
4
- interface NodeKeyManagementStorage {
3
+ export interface NodeKeyManagementStorage {
5
4
  get(agentContext: AgentContext, keyId: string): CanBePromise<Kms.KmsJwkPrivate | null>;
6
5
  has(agentContext: AgentContext, keyId: string): CanBePromise<boolean>;
7
6
  set(agentContext: AgentContext, keyId: string, jwk: Kms.KmsJwkPrivate): CanBePromise<void>;
@@ -11,5 +10,4 @@ interface NodeKeyManagementStorage {
11
10
  delete(agentContext: AgentContext, keyId: string): CanBePromise<boolean>;
12
11
  }
13
12
  //#endregion
14
- export { NodeKeyManagementStorage };
15
13
  //# sourceMappingURL=NodeKeyManagementStorage.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"NodeKeyManagementStorage.d.mts","names":[],"sources":["../../src/kms/NodeKeyManagementStorage.ts"],"mappings":";;;UAEiB,wBAAA;EACf,GAAA,CAAI,YAAA,EAAc,YAAA,EAAc,KAAA,WAAgB,YAAA,CAAa,GAAA,CAAI,aAAA;EACjE,GAAA,CAAI,YAAA,EAAc,YAAA,EAAc,KAAA,WAAgB,YAAA;EAGhD,GAAA,CAAI,YAAA,EAAc,YAAA,EAAc,KAAA,UAAe,GAAA,EAAK,GAAA,CAAI,aAAA,GAAgB,YAAA;;;;EAKxE,MAAA,CAAO,YAAA,EAAc,YAAA,EAAc,KAAA,WAAgB,YAAA;AAAA"}
1
+ {"version":3,"file":"NodeKeyManagementStorage.d.mts","names":[],"sources":["../../src/kms/NodeKeyManagementStorage.ts"],"mappings":";;iBAEiB;EACf,IAAI,cAAc,cAAc,gBAAgB,aAAa,IAAI;EACjE,IAAI,cAAc,cAAc,gBAAgB;EAGhD,IAAI,cAAc,cAAc,eAAe,KAAK,IAAI,gBAAgB;;;;EAKxE,OAAO,cAAc,cAAc,gBAAgB"}
@@ -1,7 +1,6 @@
1
1
  import { Kms } from "@credo-ts/core";
2
2
  import { generateKeyPair, randomBytes } from "node:crypto";
3
3
  import { promisify } from "node:util";
4
-
5
4
  //#region src/kms/crypto/createKey.ts
6
5
  const generateKeyPair$1 = promisify(generateKeyPair);
7
6
  const nodeSupportedEcCrvs = [
@@ -53,7 +52,7 @@ async function createOctKey(options) {
53
52
  publicJwk
54
53
  };
55
54
  }
56
-
57
55
  //#endregion
58
56
  export { assertNodeSupportedEcCrv, assertNodeSupportedOctAlgorithm, assertNodeSupportedOkpCrv, createEcKey, createOctKey, createOkpKey, createRsaKey };
57
+
59
58
  //# sourceMappingURL=createKey.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"createKey.mjs","names":["generateKeyPair","_generateKeyPair"],"sources":["../../../src/kms/crypto/createKey.ts"],"sourcesContent":["import { generateKeyPair as _generateKeyPair, randomBytes } from 'node:crypto'\nimport { promisify } from 'node:util'\nimport { Kms } from '@credo-ts/core'\n\nconst generateKeyPair = promisify(_generateKeyPair)\n\nconst nodeSupportedEcCrvs = ['P-256', 'P-384', 'P-521', 'secp256k1'] satisfies Kms.KmsJwkPublicEc['crv'][]\nexport type NodeKmsSupportedEcCrvs = (typeof nodeSupportedEcCrvs)[number]\nexport function assertNodeSupportedEcCrv(\n options: Kms.KmsCreateKeyTypeEc\n): asserts options is Kms.KmsCreateKeyTypeEc & { crv: NodeKmsSupportedEcCrvs } {\n if (!nodeSupportedEcCrvs.includes(options.crv as NodeKmsSupportedEcCrvs)) {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(`crv '${options.crv}' for kty '${options.kty}'`, 'node')\n }\n}\n\nexport async function createEcKey({ crv }: Kms.KmsCreateKeyTypeEc & { crv: NodeKmsSupportedEcCrvs }) {\n const { publicKey, privateKey } = await generateKeyPair('ec', {\n namedCurve: crv,\n })\n\n const privateJwk = privateKey.export({\n format: 'jwk',\n })\n\n const publicJwk = publicKey.export({\n format: 'jwk',\n })\n\n return {\n privateJwk: privateJwk as Kms.KmsJwkPrivateEc,\n publicJwk: publicJwk as Kms.KmsJwkPublicEc,\n }\n}\n\nexport async function createRsaKey({ modulusLength }: Kms.KmsCreateKeyTypeRsa) {\n const { publicKey, privateKey } = await generateKeyPair('rsa', {\n modulusLength,\n })\n\n const privateJwk = privateKey.export({\n format: 'jwk',\n })\n\n const publicJwk = publicKey.export({\n format: 'jwk',\n })\n\n return {\n privateJwk: privateJwk as Kms.KmsJwkPrivateRsa,\n publicJwk: publicJwk as Kms.KmsJwkPublicRsa,\n }\n}\n\nconst nodeSupportedOkpCrvs = ['Ed25519', 'X25519'] satisfies Kms.KmsJwkPublicOkp['crv'][]\ntype NodeKmsSupportedOkpCrvs = (typeof nodeSupportedOkpCrvs)[number]\nexport function assertNodeSupportedOkpCrv(\n options: Kms.KmsCreateKeyTypeOkp\n): asserts options is Kms.KmsCreateKeyTypeOkp & { crv: NodeKmsSupportedOkpCrvs } {\n if (!nodeSupportedOkpCrvs.includes(options.crv as NodeKmsSupportedOkpCrvs)) {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(`crv '${options.crv}' for kty '${options.kty}'`, 'node')\n }\n}\n\nexport async function createOkpKey({ crv }: Kms.KmsCreateKeyTypeOkp & { crv: NodeKmsSupportedOkpCrvs }) {\n const { publicKey, privateKey } =\n crv === 'Ed25519' ? await generateKeyPair('ed25519') : await generateKeyPair('x25519')\n\n const privateJwk = privateKey.export({\n format: 'jwk',\n })\n\n const publicJwk = publicKey.export({\n format: 'jwk',\n })\n\n return {\n privateJwk: privateJwk as Kms.KmsJwkPrivateOkp,\n publicJwk: publicJwk as Kms.KmsJwkPublicOkp,\n }\n}\n\nconst nodeSupportedOctAlgorithms = ['aes', 'hmac'] satisfies Kms.KmsCreateKeyTypeOct['algorithm'][]\ntype NodeSupportedOctAlgorithms = (typeof nodeSupportedOctAlgorithms)[number]\nexport function assertNodeSupportedOctAlgorithm(\n options: Kms.KmsCreateKeyTypeOct\n): asserts options is Kms.KmsCreateKeyTypeOct & { algorithm: NodeSupportedOctAlgorithms } {\n if (!nodeSupportedOctAlgorithms.includes(options.algorithm as NodeSupportedOctAlgorithms)) {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(\n `algorithm '${options.algorithm}' for kty '${options.kty}'`,\n 'node'\n )\n }\n}\n\nexport async function createOctKey(options: Kms.KmsCreateKeyTypeOct & { algorithm: NodeSupportedOctAlgorithms }) {\n const secretBytes = randomBytes(options.length >> 3)\n\n const privateJwk = {\n kty: 'oct',\n k: secretBytes.toString('base64url'),\n }\n\n const { k, ...publicJwk } = privateJwk\n\n return {\n privateJwk: privateJwk as Kms.KmsJwkPrivateOct,\n publicJwk: publicJwk as Kms.KmsJwkPublicOct,\n }\n}\n"],"mappings":";;;;;AAIA,MAAMA,oBAAkB,UAAUC,gBAAiB;AAEnD,MAAM,sBAAsB;CAAC;CAAS;CAAS;CAAS;CAAY;AAEpE,SAAgB,yBACd,SAC6E;AAC7E,KAAI,CAAC,oBAAoB,SAAS,QAAQ,IAA8B,CACtE,OAAM,IAAI,IAAI,wCAAwC,QAAQ,QAAQ,IAAI,aAAa,QAAQ,IAAI,IAAI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cAAc;AAE5B,QAAO;EACO;EACD;EACZ"}
1
+ {"version":3,"file":"createKey.mjs","names":["generateKeyPair","_generateKeyPair"],"sources":["../../../src/kms/crypto/createKey.ts"],"sourcesContent":["import { generateKeyPair as _generateKeyPair, randomBytes } from 'node:crypto'\nimport { promisify } from 'node:util'\nimport { Kms } from '@credo-ts/core'\n\nconst generateKeyPair = promisify(_generateKeyPair)\n\nconst nodeSupportedEcCrvs = ['P-256', 'P-384', 'P-521', 'secp256k1'] satisfies Kms.KmsJwkPublicEc['crv'][]\nexport type NodeKmsSupportedEcCrvs = (typeof nodeSupportedEcCrvs)[number]\nexport function assertNodeSupportedEcCrv(\n options: Kms.KmsCreateKeyTypeEc\n): asserts options is Kms.KmsCreateKeyTypeEc & { crv: NodeKmsSupportedEcCrvs } {\n if (!nodeSupportedEcCrvs.includes(options.crv as NodeKmsSupportedEcCrvs)) {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(`crv '${options.crv}' for kty '${options.kty}'`, 'node')\n }\n}\n\nexport async function createEcKey({ crv }: Kms.KmsCreateKeyTypeEc & { crv: NodeKmsSupportedEcCrvs }) {\n const { publicKey, privateKey } = await generateKeyPair('ec', {\n namedCurve: crv,\n })\n\n const privateJwk = privateKey.export({\n format: 'jwk',\n })\n\n const publicJwk = publicKey.export({\n format: 'jwk',\n })\n\n return {\n privateJwk: privateJwk as Kms.KmsJwkPrivateEc,\n publicJwk: publicJwk as Kms.KmsJwkPublicEc,\n }\n}\n\nexport async function createRsaKey({ modulusLength }: Kms.KmsCreateKeyTypeRsa) {\n const { publicKey, privateKey } = await generateKeyPair('rsa', {\n modulusLength,\n })\n\n const privateJwk = privateKey.export({\n format: 'jwk',\n })\n\n const publicJwk = publicKey.export({\n format: 'jwk',\n })\n\n return {\n privateJwk: privateJwk as Kms.KmsJwkPrivateRsa,\n publicJwk: publicJwk as Kms.KmsJwkPublicRsa,\n }\n}\n\nconst nodeSupportedOkpCrvs = ['Ed25519', 'X25519'] satisfies Kms.KmsJwkPublicOkp['crv'][]\ntype NodeKmsSupportedOkpCrvs = (typeof nodeSupportedOkpCrvs)[number]\nexport function assertNodeSupportedOkpCrv(\n options: Kms.KmsCreateKeyTypeOkp\n): asserts options is Kms.KmsCreateKeyTypeOkp & { crv: NodeKmsSupportedOkpCrvs } {\n if (!nodeSupportedOkpCrvs.includes(options.crv as NodeKmsSupportedOkpCrvs)) {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(`crv '${options.crv}' for kty '${options.kty}'`, 'node')\n }\n}\n\nexport async function createOkpKey({ crv }: Kms.KmsCreateKeyTypeOkp & { crv: NodeKmsSupportedOkpCrvs }) {\n const { publicKey, privateKey } =\n crv === 'Ed25519' ? await generateKeyPair('ed25519') : await generateKeyPair('x25519')\n\n const privateJwk = privateKey.export({\n format: 'jwk',\n })\n\n const publicJwk = publicKey.export({\n format: 'jwk',\n })\n\n return {\n privateJwk: privateJwk as Kms.KmsJwkPrivateOkp,\n publicJwk: publicJwk as Kms.KmsJwkPublicOkp,\n }\n}\n\nconst nodeSupportedOctAlgorithms = ['aes', 'hmac'] satisfies Kms.KmsCreateKeyTypeOct['algorithm'][]\ntype NodeSupportedOctAlgorithms = (typeof nodeSupportedOctAlgorithms)[number]\nexport function assertNodeSupportedOctAlgorithm(\n options: Kms.KmsCreateKeyTypeOct\n): asserts options is Kms.KmsCreateKeyTypeOct & { algorithm: NodeSupportedOctAlgorithms } {\n if (!nodeSupportedOctAlgorithms.includes(options.algorithm as NodeSupportedOctAlgorithms)) {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(\n `algorithm '${options.algorithm}' for kty '${options.kty}'`,\n 'node'\n )\n }\n}\n\nexport async function createOctKey(options: Kms.KmsCreateKeyTypeOct & { algorithm: NodeSupportedOctAlgorithms }) {\n const secretBytes = randomBytes(options.length >> 3)\n\n const privateJwk = {\n kty: 'oct',\n k: secretBytes.toString('base64url'),\n }\n\n const { k, ...publicJwk } = privateJwk\n\n return {\n privateJwk: privateJwk as Kms.Km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