@enbox/dids 0.0.2 → 0.0.3

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 (68) hide show
  1. package/README.md +41 -1
  2. package/dist/browser.js +6 -10
  3. package/dist/browser.js.map +4 -4
  4. package/dist/browser.mjs +6 -10
  5. package/dist/browser.mjs.map +4 -4
  6. package/dist/esm/bearer-did.js +5 -5
  7. package/dist/esm/bearer-did.js.map +1 -1
  8. package/dist/esm/did.js +13 -6
  9. package/dist/esm/did.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-noop.js +10 -10
  23. package/dist/esm/resolver/resolver-cache-noop.js.map +1 -1
  24. package/dist/esm/resolver/universal-resolver.js +3 -3
  25. package/dist/esm/resolver/universal-resolver.js.map +1 -1
  26. package/dist/esm/utils.js +37 -21
  27. package/dist/esm/utils.js.map +1 -1
  28. package/dist/types/bearer-did.d.ts +3 -2
  29. package/dist/types/bearer-did.d.ts.map +1 -1
  30. package/dist/types/did.d.ts.map +1 -1
  31. package/dist/types/methods/did-dht.d.ts +4 -4
  32. package/dist/types/methods/did-dht.d.ts.map +1 -1
  33. package/dist/types/methods/did-ion.d.ts +3 -2
  34. package/dist/types/methods/did-ion.d.ts.map +1 -1
  35. package/dist/types/methods/did-jwk.d.ts +2 -2
  36. package/dist/types/methods/did-jwk.d.ts.map +1 -1
  37. package/dist/types/methods/did-key.d.ts +3 -52
  38. package/dist/types/methods/did-key.d.ts.map +1 -1
  39. package/dist/types/methods/did-method.d.ts +3 -3
  40. package/dist/types/methods/did-method.d.ts.map +1 -1
  41. package/dist/types/resolver/resolver-cache-level.d.ts.map +1 -1
  42. package/dist/types/resolver/universal-resolver.d.ts +2 -2
  43. package/dist/types/resolver/universal-resolver.d.ts.map +1 -1
  44. package/dist/types/types/did-core.d.ts +1 -1
  45. package/dist/types/types/did-core.d.ts.map +1 -1
  46. package/dist/types/utils.d.ts +8 -5
  47. package/dist/types/utils.d.ts.map +1 -1
  48. package/dist/utils.js +1 -5
  49. package/dist/utils.js.map +4 -4
  50. package/package.json +30 -40
  51. package/src/bearer-did.ts +12 -11
  52. package/src/did.ts +8 -6
  53. package/src/methods/did-dht.ts +35 -35
  54. package/src/methods/did-ion.ts +12 -11
  55. package/src/methods/did-jwk.ts +6 -6
  56. package/src/methods/did-key.ts +24 -305
  57. package/src/methods/did-method.ts +3 -3
  58. package/src/methods/did-web.ts +2 -2
  59. package/src/resolver/resolver-cache-level.ts +4 -4
  60. package/src/resolver/resolver-cache-noop.ts +10 -10
  61. package/src/resolver/universal-resolver.ts +5 -5
  62. package/src/types/did-core.ts +3 -3
  63. package/src/utils.ts +28 -26
  64. package/dist/cjs/index.js +0 -6303
  65. package/dist/cjs/index.js.map +0 -7
  66. package/dist/cjs/package.json +0 -1
  67. package/dist/cjs/utils.js +0 -245
  68. 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.3",
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 dist/browser.js && bun build/bundles.js",
13
+ "build:tests:browser": "rimraf tests/compiled && bun build/esbuild-tests.cjs",
14
+ "build": "bun run clean && bun run build:esm && bun run build:browser",
15
+ "lint": "eslint . --max-warnings 0",
16
+ "lint:fix": "eslint . --fix",
17
+ "test:node": "bun test tests/",
18
+ "test:node:coverage": "bun test --coverage --coverage-reporter=text --coverage-reporter=lcov --coverage-dir=coverage tests/",
19
+ "test:browser": "bun run build:tests:browser && bunx web-test-runner"
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"
@@ -35,13 +51,11 @@
35
51
  "exports": {
36
52
  ".": {
37
53
  "types": "./dist/types/index.d.ts",
38
- "import": "./dist/esm/index.js",
39
- "require": "./dist/cjs/index.js"
54
+ "import": "./dist/esm/index.js"
40
55
  },
41
56
  "./utils": {
42
57
  "types": "./dist/types/utils.d.ts",
43
- "import": "./dist/esm/utils.js",
44
- "require": "./dist/cjs/utils.js"
58
+ "import": "./dist/esm/utils.js"
45
59
  }
46
60
  },
47
61
  "react-native": "./dist/esm/index.js",
@@ -59,58 +73,34 @@
59
73
  "access": "public"
60
74
  },
61
75
  "engines": {
62
- "node": ">=18.0.0"
76
+ "bun": ">=1.0.0"
63
77
  },
64
78
  "dependencies": {
65
79
  "@decentralized-identity/ion-sdk": "1.0.4",
66
80
  "@dnsquery/dns-packet": "6.1.1",
81
+ "@enbox/common": "0.0.3",
82
+ "@enbox/crypto": "0.0.3",
67
83
  "abstract-level": "1.0.4",
68
84
  "bencode": "4.0.0",
69
- "buffer": "6.0.3",
70
85
  "level": "8.0.1",
71
- "ms": "2.1.3",
72
- "@enbox/common": "0.0.2",
73
- "@enbox/crypto": "0.0.2"
86
+ "ms": "2.1.3"
74
87
  },
75
88
  "devDependencies": {
89
+ "buffer": "6.0.3",
76
90
  "@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",
94
+ "@typescript-eslint/eslint-plugin": "8.32.1",
95
+ "@typescript-eslint/parser": "8.32.1",
87
96
  "@web/test-runner": "0.18.2",
88
97
  "@web/test-runner-playwright": "0.11.0",
89
- "c8": "9.1.0",
90
- "chai": "5.1.1",
91
- "chai-as-promised": "7.1.2",
98
+ "bun-types": "latest",
92
99
  "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",
100
+ "eslint": "9.7.0",
97
101
  "playwright": "1.45.3",
98
102
  "rimraf": "5.0.7",
99
- "sinon": "18.0.0",
100
103
  "source-map-loader": "5.0.0",
101
104
  "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"
115
105
  }
116
- }
106
+ }
package/src/bearer-did.ts CHANGED
@@ -1,16 +1,16 @@
1
1
  import type {
2
- Jwk,
3
- Signer,
4
2
  CryptoApi,
5
- KeyIdentifier,
6
3
  EnclosedSignParams,
4
+ EnclosedVerifyParams,
5
+ Jwk,
6
+ KeyIdentifier,
7
+ KeyImporterExporter,
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
@@ -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
  }
@@ -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) {
@@ -1,37 +1,37 @@
1
- import type { Packet, StringAnswer, TxtAnswer, TxtData } from '@dnsquery/dns-packet';
2
1
  import type {
3
- Jwk,
4
- Signer,
2
+ AsymmetricKeyConverter,
5
3
  CryptoApi,
4
+ Jwk,
6
5
  KeyIdentifier,
6
+ KeyImporterExporter,
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.
@@ -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
  }
@@ -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,31 @@
1
1
  import type { CryptoApi, Jwk, KeyIdentifier, KeyImporterExporter, KmsExportKeyParams, KmsImportKeyParams } from '@enbox/crypto';
2
2
  import type {
3
- JwkEs256k,
4
3
  IonDocumentModel,
5
4
  IonPublicKeyModel,
6
5
  IonPublicKeyPurpose,
6
+ JwkEs256k,
7
7
  } from '@decentralized-identity/ion-sdk';
8
8
 
9
+ import { computeJwkThumbprint, LocalKeyManager } from '@enbox/crypto';
9
10
  import { IonDid, IonRequest } from '@decentralized-identity/ion-sdk';
10
- import { LocalKeyManager, computeJwkThumbprint } from '@enbox/crypto';
11
11
 
12
12
  import type { PortableDid } from '../types/portable-did.js';
13
13
  import type { DidCreateOptions, DidCreateVerificationMethod, DidRegistrationResult } from '../methods/did-method.js';
14
14
  import type {
15
- DidService,
16
15
  DidDocument,
17
- DidResolutionResult,
18
16
  DidResolutionOptions,
17
+ DidResolutionResult,
18
+ DidService,
19
19
  DidVerificationMethod,
20
20
  DidVerificationRelationship,
21
21
  } from '../types/did-core.js';
22
22
 
23
- import { Did } from '../did.js';
24
23
  import { BearerDid } from '../bearer-did.js';
24
+ import { Did } from '../did.js';
25
25
  import { DidMethod } from '../methods/did-method.js';
26
- import { DidError, DidErrorCode } from '../did-error.js';
27
- import { getVerificationRelationshipsById } from '../utils.js';
28
26
  import { EMPTY_DID_RESOLUTION_RESULT } from '../types/did-resolution.js';
27
+ import { getVerificationRelationshipsById } from '../utils.js';
28
+ import { DidError, DidErrorCode } from '../did-error.js';
29
29
 
30
30
  /**
31
31
  * Options for creating a Decentralized Identifier (DID) using the DID ION method.
@@ -393,7 +393,7 @@ export class DidIon extends DidMethod {
393
393
 
394
394
  // If no verification methods were specified, generate a default Ed25519 verification method.
395
395
  const defaultVerificationMethod: DidCreateVerificationMethod<TKms> = {
396
- algorithm : 'Ed25519' as any,
396
+ algorithm : 'Ed25519' as DidCreateVerificationMethod<TKms>['algorithm'],
397
397
  purposes : ['authentication', 'assertionMethod', 'capabilityDelegation', 'capabilityInvocation']
398
398
  };
399
399
 
@@ -613,7 +613,7 @@ export class DidIon extends DidMethod {
613
613
  didRegistrationMetadata: {}
614
614
  };
615
615
 
616
- } catch (error: any) {
616
+ } catch {
617
617
  return {
618
618
  didDocument : null,
619
619
  didDocumentMetadata : {
@@ -700,7 +700,7 @@ export class DidIon extends DidMethod {
700
700
 
701
701
  } catch (error: any) {
702
702
  // Rethrow any unexpected errors that are not a `DidError`.
703
- if (!(error instanceof DidError)) throw new Error(error);
703
+ if (!(error instanceof DidError)) {throw new Error(error);}
704
704
 
705
705
  // Return a DID Resolution Result with the appropriate error code.
706
706
  return {
@@ -813,7 +813,8 @@ export class DidIonUtils {
813
813
  *
814
814
  * @param params - The parameters containing the services and verification methods to include in the ION document.
815
815
  * @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.
816
+ * @param params.verificationMethods - A list of verification methods to be included, detailing the
817
+ * cryptographic keys and their intended uses within the DID document.
817
818
  * @returns A Promise resolving to an `IonDocumentModel`, ready for use in Sidetree operations like DID creation and updates.
818
819
  */
819
820
  public static async createIonDocument({ services, verificationMethods }: {
@@ -1,11 +1,11 @@
1
1
  import type {
2
- Jwk,
3
2
  CryptoApi,
3
+ InferKeyGeneratorAlgorithm,
4
+ Jwk,
4
5
  KeyIdentifier,
6
+ KeyImporterExporter,
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
@@ -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.