@enbox/dids 0.0.2 → 0.0.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 (78) hide show
  1. package/README.md +41 -1
  2. package/dist/browser.mjs +6 -10
  3. package/dist/browser.mjs.map +4 -4
  4. package/dist/esm/bearer-did.js +5 -5
  5. package/dist/esm/bearer-did.js.map +1 -1
  6. package/dist/esm/did.js +13 -6
  7. package/dist/esm/did.js.map +1 -1
  8. package/dist/esm/index.js +2 -0
  9. package/dist/esm/index.js.map +1 -1
  10. package/dist/esm/methods/did-dht.js +34 -25
  11. package/dist/esm/methods/did-dht.js.map +1 -1
  12. package/dist/esm/methods/did-ion.js +9 -7
  13. package/dist/esm/methods/did-ion.js.map +1 -1
  14. package/dist/esm/methods/did-jwk.js +3 -3
  15. package/dist/esm/methods/did-jwk.js.map +1 -1
  16. package/dist/esm/methods/did-key.js +12 -240
  17. package/dist/esm/methods/did-key.js.map +1 -1
  18. package/dist/esm/methods/did-web.js +3 -2
  19. package/dist/esm/methods/did-web.js.map +1 -1
  20. package/dist/esm/resolver/resolver-cache-level.js +1 -1
  21. package/dist/esm/resolver/resolver-cache-level.js.map +1 -1
  22. package/dist/esm/resolver/resolver-cache-memory.js +77 -0
  23. package/dist/esm/resolver/resolver-cache-memory.js.map +1 -0
  24. package/dist/esm/resolver/resolver-cache-noop.js +10 -10
  25. package/dist/esm/resolver/resolver-cache-noop.js.map +1 -1
  26. package/dist/esm/resolver/universal-resolver.js +3 -3
  27. package/dist/esm/resolver/universal-resolver.js.map +1 -1
  28. package/dist/esm/utils.js +62 -21
  29. package/dist/esm/utils.js.map +1 -1
  30. package/dist/types/bearer-did.d.ts +6 -5
  31. package/dist/types/bearer-did.d.ts.map +1 -1
  32. package/dist/types/did.d.ts.map +1 -1
  33. package/dist/types/index.d.ts +2 -0
  34. package/dist/types/index.d.ts.map +1 -1
  35. package/dist/types/methods/did-dht.d.ts +6 -6
  36. package/dist/types/methods/did-dht.d.ts.map +1 -1
  37. package/dist/types/methods/did-ion.d.ts +6 -5
  38. package/dist/types/methods/did-ion.d.ts.map +1 -1
  39. package/dist/types/methods/did-jwk.d.ts +5 -5
  40. package/dist/types/methods/did-jwk.d.ts.map +1 -1
  41. package/dist/types/methods/did-key.d.ts +6 -55
  42. package/dist/types/methods/did-key.d.ts.map +1 -1
  43. package/dist/types/methods/did-method.d.ts +5 -5
  44. package/dist/types/methods/did-method.d.ts.map +1 -1
  45. package/dist/types/resolver/resolver-cache-level.d.ts.map +1 -1
  46. package/dist/types/resolver/resolver-cache-memory.d.ts +58 -0
  47. package/dist/types/resolver/resolver-cache-memory.d.ts.map +1 -0
  48. package/dist/types/resolver/universal-resolver.d.ts +2 -2
  49. package/dist/types/resolver/universal-resolver.d.ts.map +1 -1
  50. package/dist/types/types/did-core.d.ts +1 -1
  51. package/dist/types/types/did-core.d.ts.map +1 -1
  52. package/dist/types/utils.d.ts +27 -5
  53. package/dist/types/utils.d.ts.map +1 -1
  54. package/dist/utils.js +1 -5
  55. package/dist/utils.js.map +4 -4
  56. package/package.json +35 -47
  57. package/src/bearer-did.ts +15 -14
  58. package/src/did.ts +8 -6
  59. package/src/index.ts +2 -0
  60. package/src/methods/did-dht.ts +37 -37
  61. package/src/methods/did-ion.ts +23 -15
  62. package/src/methods/did-jwk.ts +9 -9
  63. package/src/methods/did-key.ts +29 -310
  64. package/src/methods/did-method.ts +6 -6
  65. package/src/methods/did-web.ts +2 -2
  66. package/src/resolver/resolver-cache-level.ts +4 -4
  67. package/src/resolver/resolver-cache-memory.ts +84 -0
  68. package/src/resolver/resolver-cache-noop.ts +10 -10
  69. package/src/resolver/universal-resolver.ts +5 -5
  70. package/src/types/did-core.ts +3 -3
  71. package/src/utils.ts +55 -26
  72. package/dist/browser.js +0 -77
  73. package/dist/browser.js.map +0 -7
  74. package/dist/cjs/index.js +0 -6303
  75. package/dist/cjs/index.js.map +0 -7
  76. package/dist/cjs/package.json +0 -1
  77. package/dist/cjs/utils.js +0 -245
  78. package/dist/cjs/utils.js.map +0 -7
package/package.json CHANGED
@@ -1,11 +1,23 @@
1
1
  {
2
2
  "name": "@enbox/dids",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "TBD DIDs library",
5
5
  "type": "module",
6
- "main": "./dist/cjs/index.js",
6
+ "main": "./dist/esm/index.js",
7
7
  "module": "./dist/esm/index.js",
8
8
  "types": "./dist/types/index.d.ts",
9
+ "scripts": {
10
+ "clean": "rimraf dist",
11
+ "build:esm": "rimraf dist/esm dist/types && bun tsc -p tsconfig.json",
12
+ "build:browser": "rimraf dist/browser.mjs && bun ../../build/browser-bundle.js --extra-entry src/utils.ts:dist/utils.js",
13
+ "build": "bun run clean && bun run build:esm && bun run build:browser",
14
+ "lint": "eslint . --max-warnings 0",
15
+ "lint:fix": "eslint . --fix",
16
+ "test:node": "bun test tests/",
17
+ "test:node:coverage": "bun test --coverage --coverage-reporter=text --coverage-reporter=lcov --coverage-dir=coverage tests/",
18
+ "test:browser": "bunx --bun vitest --config vitest.browser.config.ts --run",
19
+ "test:browser:coverage": "bunx --bun vitest --config vitest.browser.config.ts --run --coverage --coverage.provider=istanbul --coverage.reportsDirectory=./coverage-browser"
20
+ },
9
21
  "homepage": "https://github.com/enboxorg/enbox/tree/main/packages/dids#readme",
10
22
  "bugs": "https://github.com/enboxorg/enbox/issues",
11
23
  "repository": {
@@ -15,6 +27,10 @@
15
27
  },
16
28
  "license": "Apache-2.0",
17
29
  "contributors": [
30
+ {
31
+ "name": "Liran Cohen",
32
+ "url": "https://github.com/LiranCohen"
33
+ },
18
34
  {
19
35
  "name": "Daniel Buchner",
20
36
  "url": "https://github.com/csuwildcat"
@@ -34,14 +50,14 @@
34
50
  ],
35
51
  "exports": {
36
52
  ".": {
53
+ "browser": "./dist/browser.mjs",
37
54
  "types": "./dist/types/index.d.ts",
38
- "import": "./dist/esm/index.js",
39
- "require": "./dist/cjs/index.js"
55
+ "import": "./dist/esm/index.js"
40
56
  },
41
57
  "./utils": {
58
+ "browser": "./dist/utils.js",
42
59
  "types": "./dist/types/utils.d.ts",
43
- "import": "./dist/esm/utils.js",
44
- "require": "./dist/cjs/utils.js"
60
+ "import": "./dist/esm/utils.js"
45
61
  }
46
62
  },
47
63
  "react-native": "./dist/esm/index.js",
@@ -59,58 +75,30 @@
59
75
  "access": "public"
60
76
  },
61
77
  "engines": {
62
- "node": ">=18.0.0"
78
+ "bun": ">=1.0.0"
63
79
  },
64
80
  "dependencies": {
65
81
  "@decentralized-identity/ion-sdk": "1.0.4",
66
82
  "@dnsquery/dns-packet": "6.1.1",
83
+ "@enbox/common": "0.0.3",
84
+ "@enbox/crypto": "0.0.4",
67
85
  "abstract-level": "1.0.4",
68
86
  "bencode": "4.0.0",
69
- "buffer": "6.0.3",
70
87
  "level": "8.0.1",
71
- "ms": "2.1.3",
72
- "@enbox/common": "0.0.2",
73
- "@enbox/crypto": "0.0.2"
88
+ "ms": "2.1.3"
74
89
  },
75
90
  "devDependencies": {
76
- "@playwright/test": "1.45.3",
77
91
  "@types/bencode": "2.0.4",
78
- "@types/chai": "4.3.16",
79
- "@types/chai-as-promised": "7.1.8",
80
- "@types/eslint": "8.56.10",
81
- "@types/mocha": "10.0.7",
82
92
  "@types/ms": "0.7.34",
83
93
  "@types/node": "20.14.8",
84
- "@types/sinon": "17.0.3",
85
- "@typescript-eslint/eslint-plugin": "7.9.0",
86
- "@typescript-eslint/parser": "7.14.1",
87
- "@web/test-runner": "0.18.2",
88
- "@web/test-runner-playwright": "0.11.0",
89
- "c8": "9.1.0",
90
- "chai": "5.1.1",
91
- "chai-as-promised": "7.1.2",
92
- "esbuild": "0.23.0",
93
- "eslint": "9.5.0",
94
- "eslint-plugin-mocha": "10.4.3",
95
- "mocha": "10.7.0",
96
- "mocha-junit-reporter": "2.2.1",
97
- "playwright": "1.45.3",
94
+ "@typescript-eslint/eslint-plugin": "8.32.1",
95
+ "@typescript-eslint/parser": "8.32.1",
96
+ "@vitest/browser-playwright": "4.0.18",
97
+ "@vitest/coverage-istanbul": "4.0.18",
98
+ "bun-types": "latest",
99
+ "eslint": "9.7.0",
98
100
  "rimraf": "5.0.7",
99
- "sinon": "18.0.0",
100
- "source-map-loader": "5.0.0",
101
- "typescript": "5.5.4"
102
- },
103
- "scripts": {
104
- "clean": "rimraf dist coverage tests/compiled",
105
- "build:esm": "rimraf dist/esm dist/types && pnpm tsc -p tsconfig.json",
106
- "build:cjs": "rimraf dist/cjs && node build/cjs-bundle.js && echo '{\"type\": \"commonjs\"}' > ./dist/cjs/package.json",
107
- "build:browser": "rimraf dist/browser.mjs dist/browser.js && node build/bundles.js",
108
- "build:tests:node": "rimraf tests/compiled && pnpm tsc -p tests/tsconfig.json",
109
- "build:tests:browser": "rimraf tests/compiled && node build/esbuild-tests.cjs",
110
- "build": "pnpm clean && pnpm build:esm && pnpm build:cjs && pnpm build:browser",
111
- "lint": "eslint . --max-warnings 0",
112
- "lint:fix": "eslint . --fix",
113
- "test:node": "pnpm build:tests:node && pnpm c8 mocha",
114
- "test:browser": "pnpm build:tests:browser && web-test-runner"
101
+ "typescript": "5.5.4",
102
+ "vitest": "4.0.18"
115
103
  }
116
- }
104
+ }
package/src/bearer-did.ts CHANGED
@@ -1,16 +1,16 @@
1
1
  import type {
2
+ EnclosedSignParams,
3
+ EnclosedVerifyParams,
2
4
  Jwk,
3
- Signer,
4
- CryptoApi,
5
5
  KeyIdentifier,
6
- EnclosedSignParams,
6
+ KeyImporterExporter,
7
+ KeyManager,
7
8
  KmsExportKeyParams,
8
9
  KmsImportKeyParams,
9
- KeyImporterExporter,
10
- EnclosedVerifyParams,
10
+ Signer,
11
11
  } from '@enbox/crypto';
12
12
 
13
- import { LocalKeyManager, CryptoUtils } from '@enbox/crypto';
13
+ import { CryptoUtils, LocalKeyManager } from '@enbox/crypto';
14
14
 
15
15
  import type { DidDocument } from './types/did-core.js';
16
16
  import type { DidMetadata, PortableDid } from './types/portable-did.js';
@@ -32,7 +32,8 @@ export interface BearerDidSigner extends Signer {
32
32
  *
33
33
  * Typically, this value is used to populate the `alg` field of a JWT or JWS header. The
34
34
  * registered algorithm names are defined in the
35
- * {@link https://www.iana.org/assignments/jose/jose.xhtml#web-signature-encryption-algorithms | IANA JSON Web Signature and Encryption Algorithms registry}.
35
+ * {@link https://www.iana.org/assignments/jose/jose.xhtml#web-signature-encryption-algorithms |
36
+ * IANA JSON Web Signature and Encryption Algorithms registry}.
36
37
  *
37
38
  * @example
38
39
  * "ES256" // ECDSA using P-256 and SHA-256
@@ -76,13 +77,13 @@ export class BearerDid {
76
77
  *
77
78
  * Each DID method requires at least one key be present in the provided `keyManager`.
78
79
  */
79
- keyManager: CryptoApi;
80
+ keyManager: KeyManager;
80
81
 
81
82
  constructor({ uri, document, metadata, keyManager }: {
82
83
  uri: string,
83
84
  document: DidDocument,
84
85
  metadata: DidMetadata,
85
- keyManager: CryptoApi
86
+ keyManager: KeyManager
86
87
  }) {
87
88
  this.uri = uri;
88
89
  this.document = document;
@@ -129,7 +130,7 @@ export class BearerDid {
129
130
  }
130
131
 
131
132
  // Create a new `PortableDid` copy object to store the exported data.
132
- let portableDid: PortableDid = JSON.parse(JSON.stringify({
133
+ const portableDid: PortableDid = JSON.parse(JSON.stringify({
133
134
  uri : this.uri,
134
135
  document : this.document,
135
136
  metadata : this.metadata
@@ -138,7 +139,7 @@ export class BearerDid {
138
139
  // If the BearerDid's key manager supports exporting private keys, add them to the portable DID.
139
140
  if ('exportKey' in this.keyManager && typeof this.keyManager.exportKey === 'function') {
140
141
  const privateKeys: Jwk[] = [];
141
- for (let vm of this.document.verificationMethod) {
142
+ for (const vm of this.document.verificationMethod) {
142
143
  if (!vm.publicKeyJwk) {
143
144
  throw new Error(`Verification method '${vm.id}' does not contain a public key in JWK format`);
144
145
  }
@@ -237,7 +238,7 @@ export class BearerDid {
237
238
  * keys for any verification method are missing in the key manager.
238
239
  */
239
240
  public static async import({ portableDid, keyManager = new LocalKeyManager() }: {
240
- keyManager?: CryptoApi & KeyImporterExporter<KmsImportKeyParams, KeyIdentifier, KmsExportKeyParams>;
241
+ keyManager?: KeyManager & KeyImporterExporter<KmsImportKeyParams, KeyIdentifier, KmsExportKeyParams>;
241
242
  portableDid: PortableDid;
242
243
  }): Promise<BearerDid> {
243
244
 
@@ -250,7 +251,7 @@ export class BearerDid {
250
251
  }
251
252
 
252
253
  // If given, import the private key material into the key manager.
253
- for (let key of portableDid.privateKeys ?? []) {
254
+ for (const key of portableDid.privateKeys ?? []) {
254
255
 
255
256
  // confirm th key does not already exist before importing it to avoid failures from the key manager
256
257
  const keyUri = await keyManager.getKeyUri({ key });
@@ -262,7 +263,7 @@ export class BearerDid {
262
263
 
263
264
  // Validate that the key material for every verification method in the DID document is present
264
265
  // in the key manager.
265
- for (let vm of verificationMethods) {
266
+ for (const vm of verificationMethods) {
266
267
  if (!vm.publicKeyJwk) {
267
268
  throw new Error(`Verification method '${vm.id}' does not contain a public key in JWK format`);
268
269
  }
package/src/did.ts CHANGED
@@ -32,7 +32,9 @@ export class Did {
32
32
  static readonly FRAGMENT_PATTERN = `(#.*)?`;
33
33
  /** Regular expression pattern for matching all of the components of a DID URI. */
34
34
  static readonly DID_URI_PATTERN = new RegExp(
35
- `^did:(?<method>${Did.METHOD_PATTERN}):(?<id>${Did.METHOD_ID_PATTERN})(?<path>${Did.PATH_PATTERN})(?<query>${Did.QUERY_PATTERN})(?<fragment>${Did.FRAGMENT_PATTERN})$`
35
+ '^did:(?<method>' + Did.METHOD_PATTERN + '):(?<id>' + Did.METHOD_ID_PATTERN + ')' +
36
+ '(?<path>' + Did.PATH_PATTERN + ')(?<query>' + Did.QUERY_PATTERN + ')' +
37
+ '(?<fragment>' + Did.FRAGMENT_PATTERN + ')$'
36
38
  );
37
39
 
38
40
  /**
@@ -141,13 +143,13 @@ export class Did {
141
143
  */
142
144
  static parse(didUri: string): Did | null {
143
145
  // Return null if the input string is empty or not provided.
144
- if (!didUri) return null;
146
+ if (!didUri) {return null;}
145
147
 
146
148
  // Execute the regex pattern on the input string to extract URI components.
147
149
  const match = Did.DID_URI_PATTERN.exec(didUri);
148
150
 
149
151
  // If the pattern does not match, or if the required groups are not found, return null.
150
- if (!match || !match.groups) return null;
152
+ if (!match || !match.groups) {return null;}
151
153
 
152
154
  // Extract the method, id, params, path, query, and fragment from the regex match groups.
153
155
  const { method, id, path, query, fragment } = match.groups;
@@ -160,13 +162,13 @@ export class Did {
160
162
  };
161
163
 
162
164
  // If path is present, add it to the Did object.
163
- if (path) did.path = path;
165
+ if (path) {did.path = path;}
164
166
 
165
167
  // If query is present, add it to the Did object, removing the leading '?'.
166
- if (query) did.query = query.slice(1);
168
+ if (query) {did.query = query.slice(1);}
167
169
 
168
170
  // If fragment is present, add it to the Did object, removing the leading '#'.
169
- if (fragment) did.fragment = fragment.slice(1);
171
+ if (fragment) {did.fragment = fragment.slice(1);}
170
172
 
171
173
  // If query params are present, parse them into a key-value object and add to the Did object.
172
174
  if (query) {
package/src/index.ts CHANGED
@@ -15,7 +15,9 @@ export * from './methods/did-method.js';
15
15
  export * from './methods/did-web.js';
16
16
 
17
17
  export * from './resolver/resolver-cache-level.js';
18
+ export * from './resolver/resolver-cache-memory.js';
18
19
  export * from './resolver/resolver-cache-noop.js';
19
20
  export * from './resolver/universal-resolver.js';
20
21
 
22
+ export { isPortableDid } from './utils.js';
21
23
  export * as utils from './utils.js';
@@ -1,37 +1,37 @@
1
- import type { Packet, StringAnswer, TxtAnswer, TxtData } from '@dnsquery/dns-packet';
2
1
  import type {
2
+ AsymmetricKeyConverter,
3
3
  Jwk,
4
- Signer,
5
- CryptoApi,
6
4
  KeyIdentifier,
5
+ KeyImporterExporter,
6
+ KeyManager,
7
7
  KmsExportKeyParams,
8
8
  KmsImportKeyParams,
9
- KeyImporterExporter,
10
- AsymmetricKeyConverter,
9
+ Signer,
11
10
  } from '@enbox/crypto';
11
+ import type { Packet, StringAnswer, TxtAnswer, TxtData } from '@dnsquery/dns-packet';
12
12
 
13
13
  import bencode from 'bencode';
14
14
  import { Convert } from '@enbox/common';
15
- import { computeJwkThumbprint, Ed25519, LocalKeyManager, Secp256k1, Secp256r1, X25519 } from '@enbox/crypto';
16
15
  import { AUTHORITATIVE_ANSWER, decode as dnsPacketDecode, encode as dnsPacketEncode } from '@dnsquery/dns-packet';
16
+ import { computeJwkThumbprint, Ed25519, LocalKeyManager, Secp256k1, Secp256r1, X25519 } from '@enbox/crypto';
17
17
 
18
- import type { DidMetadata, PortableDid } from '../types/portable-did.js';
19
18
  import type { DidCreateOptions, DidCreateVerificationMethod, DidRegistrationResult } from './did-method.js';
20
19
  import type {
21
- DidService,
22
20
  DidDocument,
23
- DidResolutionResult,
24
21
  DidResolutionOptions,
22
+ DidResolutionResult,
23
+ DidService,
25
24
  DidVerificationMethod,
26
25
  } from '../types/did-core.js';
26
+ import type { DidMetadata, PortableDid } from '../types/portable-did.js';
27
27
 
28
+ import { BearerDid } from '../bearer-did.js';
28
29
  import { Did } from '../did.js';
29
30
  import { DidMethod } from './did-method.js';
30
- import { BearerDid } from '../bearer-did.js';
31
- import { extractDidFragment } from '../utils.js';
32
- import { DidError, DidErrorCode } from '../did-error.js';
33
31
  import { DidVerificationRelationship } from '../types/did-core.js';
34
32
  import { EMPTY_DID_RESOLUTION_RESULT } from '../types/did-resolution.js';
33
+ import { extractDidFragment } from '../utils.js';
34
+ import { DidError, DidErrorCode } from '../did-error.js';
35
35
 
36
36
  /**
37
37
  * Represents a BEP44 message, which is used for storing and retrieving data in the Mainline DHT
@@ -221,7 +221,7 @@ export type PreviousDidProof = {
221
221
  * The default DID DHT Gateway or Pkarr Relay server to use when publishing and resolving DID
222
222
  * documents.
223
223
  */
224
- const DEFAULT_GATEWAY_URI = 'https://did-dht-production.up.railway.app';
224
+ const DEFAULT_GATEWAY_URI = process.env.DID_DHT_GATEWAY_URI || 'https://enbox-did-dht.fly.dev';
225
225
 
226
226
  /**
227
227
  * The version of the DID DHT specification that is implemented by this library.
@@ -506,7 +506,7 @@ export class DidDht extends DidMethod {
506
506
  * @param params.options - Optional parameters that can be specified when creating a new DID.
507
507
  * @returns A Promise resolving to a {@link BearerDid} object representing the new DID.
508
508
  */
509
- public static async create<TKms extends CryptoApi | undefined = undefined>({
509
+ public static async create<TKms extends KeyManager | undefined = undefined>({
510
510
  keyManager = new LocalKeyManager(),
511
511
  options = {}
512
512
  }: {
@@ -552,7 +552,7 @@ export class DidDht extends DidMethod {
552
552
  if (!verificationMethodsToAdd?.some(vm => vm.id?.split('#').pop() === '0')) {
553
553
  // Add the Identity Key to the beginning of the key set.
554
554
  verificationMethodsToAdd.unshift({
555
- algorithm : 'Ed25519' as any,
555
+ algorithm : 'Ed25519' as DidCreateVerificationMethod<TKms>['algorithm'],
556
556
  id : '0',
557
557
  purposes : ['authentication', 'assertionMethod', 'capabilityDelegation', 'capabilityInvocation']
558
558
  });
@@ -587,7 +587,7 @@ export class DidDht extends DidMethod {
587
587
  // Add the verification method to the specified purpose properties of the DID document.
588
588
  for (const purpose of verificationMethod.purposes ?? []) {
589
589
  // Initialize the purpose property if it does not already exist.
590
- if (!document[purpose]) document[purpose] = [];
590
+ document[purpose] ??= [];
591
591
  // Add the verification method to the purpose property.
592
592
  document[purpose]!.push(methodId);
593
593
  }
@@ -648,7 +648,7 @@ export class DidDht extends DidMethod {
648
648
  * manager.
649
649
  */
650
650
  public static async import({ portableDid, keyManager = new LocalKeyManager() }: {
651
- keyManager?: CryptoApi & KeyImporterExporter<KmsImportKeyParams, KeyIdentifier, KmsExportKeyParams>;
651
+ keyManager?: KeyManager & KeyImporterExporter<KmsImportKeyParams, KeyIdentifier, KmsExportKeyParams>;
652
652
  portableDid: PortableDid;
653
653
  }): Promise<BearerDid> {
654
654
  // Verify the DID method is supported.
@@ -784,7 +784,7 @@ export class DidDht extends DidMethod {
784
784
 
785
785
  } catch (error: any) {
786
786
  // Rethrow any unexpected errors that are not a `DidError`.
787
- if (!(error instanceof DidError)) throw new Error(error);
787
+ if (!(error instanceof DidError)) {throw new Error(error);}
788
788
 
789
789
  // Return a DID Resolution Result with the appropriate error code.
790
790
  return {
@@ -910,14 +910,14 @@ export class DidDhtDocument {
910
910
  }
911
911
 
912
912
  } catch (error: any) {
913
- if (error instanceof DidError) throw error;
913
+ if (error instanceof DidError) {throw error;}
914
914
  throw new DidError(DidErrorCode.InternalError, `Failed to fetch Pkarr record: ${error.message}`);
915
915
  }
916
916
 
917
917
  // Read the Fetch Response stream into a byte array.
918
918
  const messageBytes = await response.arrayBuffer();
919
919
 
920
- if(!messageBytes) {
920
+ if (!messageBytes) {
921
921
  throw new DidError(DidErrorCode.NotFound, `Pkarr record not found for: ${identifier}`);
922
922
  }
923
923
 
@@ -1010,7 +1010,7 @@ export class DidDhtDocument {
1010
1010
 
1011
1011
  for (const answer of dnsPacket?.answers ?? []) {
1012
1012
  // DID DHT properties are ONLY present in DNS TXT records.
1013
- if (answer.type !== 'TXT') continue;
1013
+ if (answer.type !== 'TXT') {continue;}
1014
1014
 
1015
1015
  // Get the DID DHT record identifier (e.g., k0, aka, did, etc.) from the DNS resource name.
1016
1016
  const dnsRecordId = answer.name.split('.')[0].substring(1);
@@ -1051,11 +1051,11 @@ export class DidDhtDocument {
1051
1051
  const namedCurve = DidDhtRegisteredKeyType[Number(t)];
1052
1052
 
1053
1053
  // Convert the public key from a byte array to JWK format.
1054
- let publicKey = await DidDhtUtils.keyConverter(namedCurve).bytesToPublicKey({ publicKeyBytes });
1054
+ const publicKey = await DidDhtUtils.keyConverter(namedCurve).bytesToPublicKey({ publicKeyBytes });
1055
1055
 
1056
1056
  publicKey.alg = parsedAlg || KeyTypeToDefaultAlgorithmMap[Number(t) as DidDhtRegisteredKeyType];
1057
1057
 
1058
- // TOOD: when this is complete https://github.com/TBD54566975/web5-js/issues/638 then we can add this back and
1058
+ // TODO: when this is complete https://github.com/enboxorg/enbox/issues/638 then we can add this back and
1059
1059
  // update the test vectors kid back to '0'
1060
1060
  // if(dnsRecordId === 'k0') {
1061
1061
  // publicKey.kid = '0';
@@ -1138,11 +1138,11 @@ export class DidDhtDocument {
1138
1138
  const { auth, asm, del, inv, agm } = DidDhtUtils.parseTxtDataToObject(answer.data);
1139
1139
 
1140
1140
  // Add the verification relationships, if any, to the DID document.
1141
- if (auth) didDocument.authentication = recordIdsToMethodIds(auth);
1142
- if (asm) didDocument.assertionMethod = recordIdsToMethodIds(asm);
1143
- if (del) didDocument.capabilityDelegation = recordIdsToMethodIds(del);
1144
- if (inv) didDocument.capabilityInvocation = recordIdsToMethodIds(inv);
1145
- if (agm) didDocument.keyAgreement = recordIdsToMethodIds(agm);
1141
+ if (auth) {didDocument.authentication = recordIdsToMethodIds(auth);}
1142
+ if (asm) {didDocument.assertionMethod = recordIdsToMethodIds(asm);}
1143
+ if (del) {didDocument.capabilityDelegation = recordIdsToMethodIds(del);}
1144
+ if (inv) {didDocument.capabilityInvocation = recordIdsToMethodIds(inv);}
1145
+ if (agm) {didDocument.keyAgreement = recordIdsToMethodIds(agm);}
1146
1146
 
1147
1147
  break;
1148
1148
  }
@@ -1220,7 +1220,7 @@ export class DidDhtDocument {
1220
1220
  for (const [index, verificationMethod] of didDocument.verificationMethod?.entries() ?? []) {
1221
1221
  const dnsRecordId = `k${index}`;
1222
1222
  verificationMethodIds.push(dnsRecordId);
1223
- let methodId = verificationMethod.id.split('#').pop()!; // Remove fragment prefix, if any.
1223
+ const methodId = verificationMethod.id.split('#').pop()!; // Remove fragment prefix, if any.
1224
1224
  idLookup.set(methodId, dnsRecordId);
1225
1225
 
1226
1226
  const publicKey = verificationMethod.publicKeyJwk;
@@ -1242,16 +1242,16 @@ export class DidDhtDocument {
1242
1242
  const txtData = [`t=${keyType}`, `k=${publicKeyBase64Url}`];
1243
1243
  // if the methodId is not the identity key or a thumbprint, explicity define the id within the DNS TXT record.
1244
1244
  // otherwise the id can be inferred from the thumbprint.
1245
- if (methodId !== '0' && await computeJwkThumbprint({ jwk: publicKey }) !== methodId) {
1245
+ if (methodId !== '0' && await computeJwkThumbprint({ jwk: publicKey }) !== methodId) {
1246
1246
  txtData.unshift(`id=${methodId}`);
1247
1247
  }
1248
1248
  // Only set the algorithm property (`a`) if it differs from the default algorithm for the key type.
1249
- if(publicKey.alg !== KeyTypeToDefaultAlgorithmMap[keyType]) {
1249
+ if (publicKey.alg !== KeyTypeToDefaultAlgorithmMap[keyType]) {
1250
1250
  txtData.push(`a=${publicKey.alg}`);
1251
1251
  }
1252
1252
 
1253
1253
  // Add the controller property, if set to a value other than the Identity Key (DID Subject).
1254
- if (verificationMethod.controller !== didDocument.id) txtData.push(`c=${verificationMethod.controller}`);
1254
+ if (verificationMethod.controller !== didDocument.id) {txtData.push(`c=${verificationMethod.controller}`);}
1255
1255
 
1256
1256
  // Add a TXT record for the verification method.
1257
1257
  txtRecords.push({
@@ -1298,8 +1298,8 @@ export class DidDhtDocument {
1298
1298
  // Add verification relationships to the root record.
1299
1299
  Object.keys(DidVerificationRelationship).forEach(relationship => {
1300
1300
  // Collect the verification method IDs for the given relationship.
1301
- const dnsRecordIds = (didDocument[relationship as keyof DidDocument] as any[])
1302
- ?.map(id => idLookup.get(id.split('#').pop()));
1301
+ const dnsRecordIds = (didDocument[relationship as keyof DidDocument] as string[] | undefined)
1302
+ ?.map((id: string): string | undefined => idLookup.get(id.split('#').pop()!));
1303
1303
 
1304
1304
  // If the relationship includes verification methods, add them to the root record.
1305
1305
  if (dnsRecordIds) {
@@ -1422,7 +1422,7 @@ export class DidDhtUtils {
1422
1422
  didUri: string
1423
1423
  }): Promise<Jwk> {
1424
1424
  // Decode the method-specific identifier from z-base-32 to a byte array.
1425
- let identityKeyBytes = DidDhtUtils.identifierToIdentityKeyBytes({ didUri });
1425
+ const identityKeyBytes = DidDhtUtils.identifierToIdentityKeyBytes({ didUri });
1426
1426
 
1427
1427
  // Convert the byte array to a JWK.
1428
1428
  const identityKey = await Ed25519.bytesToPublicKey({ publicKeyBytes: identityKeyBytes });
@@ -1528,7 +1528,7 @@ export class DidDhtUtils {
1528
1528
 
1529
1529
  const converter = converters[curve];
1530
1530
 
1531
- if (!converter) throw new DidError(DidErrorCode.InvalidPublicKeyType, `Unsupported curve: ${curve}`);
1531
+ if (!converter) {throw new DidError(DidErrorCode.InvalidPublicKeyType, `Unsupported curve: ${curve}`);}
1532
1532
 
1533
1533
  return converter;
1534
1534
  }
@@ -1609,7 +1609,7 @@ export class DidDhtUtils {
1609
1609
  const key = await DidDhtUtils.identifierToIdentityKey({ didUri: previousDidProof.previousDid });
1610
1610
  const data = DidDhtUtils.identifierToIdentityKeyBytes({ didUri: newDid });
1611
1611
  const signature = Convert.base64Url(previousDidProof.signature).toUint8Array();
1612
- const isValid = await Ed25519.verify({ key, data, signature });
1612
+ const isValid = await Ed25519.verify({ key, data, signature });
1613
1613
 
1614
1614
  if (!isValid) {
1615
1615
  throw new DidError(DidErrorCode.InvalidPreviousDidProof, 'The previous DID proof is invalid.');
@@ -1,31 +1,38 @@
1
- import type { CryptoApi, Jwk, KeyIdentifier, KeyImporterExporter, KmsExportKeyParams, KmsImportKeyParams } from '@enbox/crypto';
2
1
  import type {
3
- JwkEs256k,
4
2
  IonDocumentModel,
5
3
  IonPublicKeyModel,
6
4
  IonPublicKeyPurpose,
5
+ JwkEs256k,
7
6
  } from '@decentralized-identity/ion-sdk';
8
-
7
+ import type {
8
+ Jwk,
9
+ KeyIdentifier,
10
+ KeyImporterExporter,
11
+ KeyManager,
12
+ KmsExportKeyParams,
13
+ KmsImportKeyParams,
14
+ } from '@enbox/crypto';
15
+
16
+ import { computeJwkThumbprint, LocalKeyManager } from '@enbox/crypto';
9
17
  import { IonDid, IonRequest } from '@decentralized-identity/ion-sdk';
10
- import { LocalKeyManager, computeJwkThumbprint } from '@enbox/crypto';
11
18
 
12
19
  import type { PortableDid } from '../types/portable-did.js';
13
20
  import type { DidCreateOptions, DidCreateVerificationMethod, DidRegistrationResult } from '../methods/did-method.js';
14
21
  import type {
15
- DidService,
16
22
  DidDocument,
17
- DidResolutionResult,
18
23
  DidResolutionOptions,
24
+ DidResolutionResult,
25
+ DidService,
19
26
  DidVerificationMethod,
20
27
  DidVerificationRelationship,
21
28
  } from '../types/did-core.js';
22
29
 
23
- import { Did } from '../did.js';
24
30
  import { BearerDid } from '../bearer-did.js';
31
+ import { Did } from '../did.js';
25
32
  import { DidMethod } from '../methods/did-method.js';
26
- import { DidError, DidErrorCode } from '../did-error.js';
27
- import { getVerificationRelationshipsById } from '../utils.js';
28
33
  import { EMPTY_DID_RESOLUTION_RESULT } from '../types/did-resolution.js';
34
+ import { getVerificationRelationshipsById } from '../utils.js';
35
+ import { DidError, DidErrorCode } from '../did-error.js';
29
36
 
30
37
  /**
31
38
  * Options for creating a Decentralized Identifier (DID) using the DID ION method.
@@ -364,7 +371,7 @@ export class DidIon extends DidMethod {
364
371
  * @param params.options - Optional parameters that can be specified when creating a new DID.
365
372
  * @returns A Promise resolving to a {@link BearerDid} object representing the new DID.
366
373
  */
367
- public static async create<TKms extends CryptoApi | undefined = undefined>({
374
+ public static async create<TKms extends KeyManager | undefined = undefined>({
368
375
  keyManager = new LocalKeyManager(),
369
376
  options = {}
370
377
  }: {
@@ -393,7 +400,7 @@ export class DidIon extends DidMethod {
393
400
 
394
401
  // If no verification methods were specified, generate a default Ed25519 verification method.
395
402
  const defaultVerificationMethod: DidCreateVerificationMethod<TKms> = {
396
- algorithm : 'Ed25519' as any,
403
+ algorithm : 'Ed25519' as DidCreateVerificationMethod<TKms>['algorithm'],
397
404
  purposes : ['authentication', 'assertionMethod', 'capabilityDelegation', 'capabilityInvocation']
398
405
  };
399
406
 
@@ -517,7 +524,7 @@ export class DidIon extends DidMethod {
517
524
  * any verification method are missing in the key manager.
518
525
  */
519
526
  public static async import({ portableDid, keyManager = new LocalKeyManager() }: {
520
- keyManager?: CryptoApi & KeyImporterExporter<KmsImportKeyParams, KeyIdentifier, KmsExportKeyParams>;
527
+ keyManager?: KeyManager & KeyImporterExporter<KmsImportKeyParams, KeyIdentifier, KmsExportKeyParams>;
521
528
  portableDid: PortableDid;
522
529
  }): Promise<BearerDid> {
523
530
  // Verify the DID method is supported.
@@ -613,7 +620,7 @@ export class DidIon extends DidMethod {
613
620
  didRegistrationMetadata: {}
614
621
  };
615
622
 
616
- } catch (error: any) {
623
+ } catch {
617
624
  return {
618
625
  didDocument : null,
619
626
  didDocumentMetadata : {
@@ -700,7 +707,7 @@ export class DidIon extends DidMethod {
700
707
 
701
708
  } catch (error: any) {
702
709
  // Rethrow any unexpected errors that are not a `DidError`.
703
- if (!(error instanceof DidError)) throw new Error(error);
710
+ if (!(error instanceof DidError)) {throw new Error(error);}
704
711
 
705
712
  // Return a DID Resolution Result with the appropriate error code.
706
713
  return {
@@ -813,7 +820,8 @@ export class DidIonUtils {
813
820
  *
814
821
  * @param params - The parameters containing the services and verification methods to include in the ION document.
815
822
  * @param params.services - A list of service endpoints to be included in the DID document, specifying ways to interact with the DID subject.
816
- * @param params.verificationMethods - A list of verification methods to be included, detailing the cryptographic keys and their intended uses within the DID document.
823
+ * @param params.verificationMethods - A list of verification methods to be included, detailing the
824
+ * cryptographic keys and their intended uses within the DID document.
817
825
  * @returns A Promise resolving to an `IonDocumentModel`, ready for use in Sidetree operations like DID creation and updates.
818
826
  */
819
827
  public static async createIonDocument({ services, verificationMethods }: {
@@ -1,11 +1,11 @@
1
1
  import type {
2
+ InferKeyGeneratorAlgorithm,
2
3
  Jwk,
3
- CryptoApi,
4
4
  KeyIdentifier,
5
+ KeyImporterExporter,
6
+ KeyManager,
5
7
  KmsExportKeyParams,
6
8
  KmsImportKeyParams,
7
- KeyImporterExporter,
8
- InferKeyGeneratorAlgorithm,
9
9
  } from '@enbox/crypto';
10
10
 
11
11
  import { Convert } from '@enbox/common';
@@ -15,11 +15,11 @@ import type { PortableDid } from '../types/portable-did.js';
15
15
  import type { DidCreateOptions, DidCreateVerificationMethod } from './did-method.js';
16
16
  import type { DidDocument, DidResolutionOptions, DidResolutionResult, DidVerificationMethod } from '../types/did-core.js';
17
17
 
18
+ import { BearerDid } from '../bearer-did.js';
18
19
  import { Did } from '../did.js';
19
20
  import { DidMethod } from './did-method.js';
20
- import { BearerDid } from '../bearer-did.js';
21
- import { DidError, DidErrorCode } from '../did-error.js';
22
21
  import { EMPTY_DID_RESOLUTION_RESULT } from '../types/did-resolution.js';
22
+ import { DidError, DidErrorCode } from '../did-error.js';
23
23
 
24
24
  /**
25
25
  * Defines the set of options available when creating a new Decentralized Identifier (DID) with the
@@ -76,7 +76,7 @@ export interface DidJwkCreateOptions<TKms> extends DidCreateOptions<TKms> {
76
76
  /**
77
77
  * Optionally specify the algorithm to be used for key generation.
78
78
  */
79
- algorithm?: TKms extends CryptoApi
79
+ algorithm?: TKms extends KeyManager
80
80
  ? InferKeyGeneratorAlgorithm<TKms>
81
81
  : InferKeyGeneratorAlgorithm<LocalKeyManager>;
82
82
 
@@ -193,7 +193,7 @@ export class DidJwk extends DidMethod {
193
193
  * @param params.options - Optional parameters that can be specified when creating a new DID.
194
194
  * @returns A Promise resolving to a {@link BearerDid} object representing the new DID.
195
195
  */
196
- public static async create<TKms extends CryptoApi | undefined = undefined>({
196
+ public static async create<TKms extends KeyManager | undefined = undefined>({
197
197
  keyManager = new LocalKeyManager(),
198
198
  options = {}
199
199
  }: {
@@ -305,7 +305,7 @@ export class DidJwk extends DidMethod {
305
305
  * @throws An error if the DID document does not contain exactly one verification method.
306
306
  */
307
307
  public static async import({ portableDid, keyManager = new LocalKeyManager() }: {
308
- keyManager?: CryptoApi & KeyImporterExporter<KmsImportKeyParams, KeyIdentifier, KmsExportKeyParams>;
308
+ keyManager?: KeyManager & KeyImporterExporter<KmsImportKeyParams, KeyIdentifier, KmsExportKeyParams>;
309
309
  portableDid: PortableDid;
310
310
  }): Promise<BearerDid> {
311
311
  // Verify the DID method is supported.
@@ -341,7 +341,7 @@ export class DidJwk extends DidMethod {
341
341
  // Attempt to decode the Base64URL-encoded JWK.
342
342
  let publicKey: Jwk | undefined;
343
343
  try {
344
- publicKey = Convert.base64Url(parsedDid!.id).toObject() as Jwk;
344
+ publicKey = parsedDid ? Convert.base64Url(parsedDid.id).toObject() as Jwk : undefined;
345
345
  } catch { /* Consume the error so that a DID resolution error can be returned later. */ }
346
346
 
347
347
  // If parsing or decoding failed, the DID is invalid.