@atproto/did 0.2.4 → 0.4.0-next.0

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # @atproto/did
2
2
 
3
+ ## 0.4.0-next.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#4929](https://github.com/bluesky-social/atproto/pull/4929) [`bb7491c`](https://github.com/bluesky-social/atproto/commit/bb7491c29e06181e1d2f8cf6eb454f9bb8ab961b) Thanks [@devinivy](https://github.com/devinivy)! - **BREAKING:** Drop support for Node.js 18 and 20. Node.js 22 is now the minimum supported version. Docker images now use Node.js 24.
8
+
9
+ - [#4943](https://github.com/bluesky-social/atproto/pull/4943) [`07ae5d4`](https://github.com/bluesky-social/atproto/commit/07ae5d4452df51e045e0239da7a04cf0bc154028) Thanks [@devinivy](https://github.com/devinivy)! - **BREAKING:** Convert to pure ESM. All packages now ship `"type": "module"` with ES module output and Node16 module resolution.
10
+
11
+ Node.js 22's `require()` compatibility layer can still load these packages in CommonJS code.
12
+
13
+ - [#4930](https://github.com/bluesky-social/atproto/pull/4930) [`042df15`](https://github.com/bluesky-social/atproto/commit/042df15087c0e62cd1e715fcbf58852fab875af9) Thanks [@devinivy](https://github.com/devinivy)! - Build with TypeScript 6.0. Emitted `.d.ts` files now use TypeScript 6's stricter `Uint8Array<ArrayBuffer>` typing in places where Web/Node APIs require buffer-backed (not shared-memory) byte arrays. Consumers compiling against these types on older TypeScript should see no runtime impact, but may need to widen or cast in spots that previously relied on `Uint8Array` defaulting to `<ArrayBufferLike>`.
14
+
15
+ Internal: tsconfig `moduleResolution: "node"` is silenced via `ignoreDeprecations: "6.0"` for now; the proper migration to `node16`/`bundler` resolution is deferred.
16
+
17
+ ## 0.3.0
18
+
19
+ ### Minor Changes
20
+
21
+ - [#4580](https://github.com/bluesky-social/atproto/pull/4580) [`d54d707`](https://github.com/bluesky-social/atproto/commit/d54d7077eb32041e1f61c312efa1dd0d768c774e) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Allow DID document to omit the `@context` root property
22
+
23
+ - [#4580](https://github.com/bluesky-social/atproto/pull/4580) [`d54d707`](https://github.com/bluesky-social/atproto/commit/d54d7077eb32041e1f61c312efa1dd0d768c774e) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Disallow string values in `verificationMethod` array (as per spec)
24
+
3
25
  ## 0.2.4
4
26
 
5
27
  ### Patch Changes
package/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  Dual MIT/Apache-2.0 License
2
2
 
3
- Copyright (c) 2022-2025 Bluesky Social PBC, and Contributors
3
+ Copyright (c) 2022-2026 Bluesky Social PBC, and Contributors
4
4
 
5
5
  Except as otherwise noted in individual files, this software is licensed under the MIT license (<http://opensource.org/licenses/MIT>), or the Apache License, Version 2.0 (<http://www.apache.org/licenses/LICENSE-2.0>).
6
6
 
package/dist/atproto.js CHANGED
@@ -1,59 +1,46 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ATPROTO_VERIFICATION_METHOD_TYPES = exports.isAtprotoAudience = exports.atprotoDidSchema = void 0;
4
- exports.isAtprotoDid = isAtprotoDid;
5
- exports.asAtprotoDid = asAtprotoDid;
6
- exports.assertAtprotoDid = assertAtprotoDid;
7
- exports.assertAtprotoDidWeb = assertAtprotoDidWeb;
8
- exports.isAtprotoDidWeb = isAtprotoDidWeb;
9
- exports.extractAtprotoData = extractAtprotoData;
10
- exports.extractPdsUrl = extractPdsUrl;
11
- exports.isAtprotoAka = isAtprotoAka;
12
- exports.isAtprotoPersonalDataServerService = isAtprotoPersonalDataServerService;
13
- exports.isAtprotoVerificationMethod = isAtprotoVerificationMethod;
14
- const zod_1 = require("zod");
15
- const did_error_js_1 = require("./did-error.js");
16
- const uri_js_1 = require("./lib/uri.js");
17
- const methods_js_1 = require("./methods.js");
18
- const utils_js_1 = require("./utils.js");
19
- exports.atprotoDidSchema = zod_1.z
1
+ import { z } from 'zod';
2
+ import { DidError, InvalidDidError } from './did-error.js';
3
+ import { canParse, isFragment } from './lib/uri.js';
4
+ import { DID_PLC_PREFIX, DID_WEB_PREFIX, assertDidPlc, assertDidWeb, isDidPlc, isDidWeb, } from './methods.js';
5
+ import { matchesIdentifier } from './utils.js';
6
+ export const atprotoDidSchema = z
20
7
  .string()
21
8
  .refine(isAtprotoDid, `Atproto only allows "plc" and "web" DID methods`);
22
- function isAtprotoDid(input) {
23
- return (0, methods_js_1.isDidPlc)(input) || isAtprotoDidWeb(input);
9
+ export function isAtprotoDid(input) {
10
+ return isDidPlc(input) || isAtprotoDidWeb(input);
24
11
  }
25
- function asAtprotoDid(input) {
12
+ export function asAtprotoDid(input) {
26
13
  assertAtprotoDid(input);
27
14
  return input;
28
15
  }
29
- function assertAtprotoDid(input) {
16
+ export function assertAtprotoDid(input) {
30
17
  if (typeof input !== 'string') {
31
- throw new did_error_js_1.InvalidDidError(typeof input, `DID must be a string`);
18
+ throw new InvalidDidError(typeof input, `DID must be a string`);
32
19
  }
33
- else if (input.startsWith(methods_js_1.DID_PLC_PREFIX)) {
34
- (0, methods_js_1.assertDidPlc)(input);
20
+ else if (input.startsWith(DID_PLC_PREFIX)) {
21
+ assertDidPlc(input);
35
22
  }
36
- else if (input.startsWith(methods_js_1.DID_WEB_PREFIX)) {
23
+ else if (input.startsWith(DID_WEB_PREFIX)) {
37
24
  assertAtprotoDidWeb(input);
38
25
  }
39
26
  else {
40
- throw new did_error_js_1.InvalidDidError(input, `Atproto only allows "plc" and "web" DID methods`);
27
+ throw new InvalidDidError(input, `Atproto only allows "plc" and "web" DID methods`);
41
28
  }
42
29
  }
43
- function assertAtprotoDidWeb(input) {
44
- (0, methods_js_1.assertDidWeb)(input);
30
+ export function assertAtprotoDidWeb(input) {
31
+ assertDidWeb(input);
45
32
  if (isDidWebWithPath(input)) {
46
- throw new did_error_js_1.InvalidDidError(input, `Atproto does not allow path components in Web DIDs`);
33
+ throw new InvalidDidError(input, `Atproto does not allow path components in Web DIDs`);
47
34
  }
48
35
  if (isDidWebWithHttpsPort(input)) {
49
- throw new did_error_js_1.InvalidDidError(input, `Atproto does not allow port numbers in Web DIDs, except for localhost`);
36
+ throw new InvalidDidError(input, `Atproto does not allow port numbers in Web DIDs, except for localhost`);
50
37
  }
51
38
  }
52
39
  /**
53
40
  * @see {@link https://atproto.com/specs/did#blessed-did-methods}
54
41
  */
55
- function isAtprotoDidWeb(input) {
56
- if (!(0, methods_js_1.isDidWeb)(input)) {
42
+ export function isAtprotoDidWeb(input) {
43
+ if (!isDidWeb(input)) {
57
44
  return false;
58
45
  }
59
46
  if (isDidWebWithPath(input)) {
@@ -65,7 +52,7 @@ function isAtprotoDidWeb(input) {
65
52
  return true;
66
53
  }
67
54
  function isDidWebWithPath(did) {
68
- return did.includes(':', methods_js_1.DID_WEB_PREFIX.length);
55
+ return did.includes(':', DID_WEB_PREFIX.length);
69
56
  }
70
57
  function isLocalhostDid(did) {
71
58
  return (did === 'did:web:localhost' ||
@@ -75,17 +62,17 @@ function isLocalhostDid(did) {
75
62
  function isDidWebWithHttpsPort(did) {
76
63
  if (isLocalhostDid(did))
77
64
  return false;
78
- const pathIdx = did.indexOf(':', methods_js_1.DID_WEB_PREFIX.length);
65
+ const pathIdx = did.indexOf(':', DID_WEB_PREFIX.length);
79
66
  const hasPort = pathIdx === -1
80
67
  ? // No path component, check if there's a port separator anywhere after
81
68
  // the "did:web:" prefix
82
- did.includes('%3A', methods_js_1.DID_WEB_PREFIX.length)
69
+ did.includes('%3A', DID_WEB_PREFIX.length)
83
70
  : // There is a path component; if there is an encoded colon *before* it,
84
71
  // then there is a port number
85
72
  did.lastIndexOf('%3A', pathIdx) !== -1;
86
73
  return hasPort;
87
74
  }
88
- const isAtprotoAudience = (value) => {
75
+ export const isAtprotoAudience = (value) => {
89
76
  if (typeof value !== 'string')
90
77
  return false;
91
78
  const hashIndex = value.indexOf('#');
@@ -93,10 +80,9 @@ const isAtprotoAudience = (value) => {
93
80
  return false;
94
81
  if (value.indexOf('#', hashIndex + 1) !== -1)
95
82
  return false;
96
- return ((0, uri_js_1.isFragment)(value, hashIndex + 1) && isAtprotoDid(value.slice(0, hashIndex)));
83
+ return (isFragment(value, hashIndex + 1) && isAtprotoDid(value.slice(0, hashIndex)));
97
84
  };
98
- exports.isAtprotoAudience = isAtprotoAudience;
99
- function extractAtprotoData(document) {
85
+ export function extractAtprotoData(document) {
100
86
  return {
101
87
  did: document.id,
102
88
  aka: document.alsoKnownAs?.find(isAtprotoAka)?.slice(5),
@@ -104,31 +90,31 @@ function extractAtprotoData(document) {
104
90
  pds: document.service?.find((isAtprotoPersonalDataServerService), document),
105
91
  };
106
92
  }
107
- function extractPdsUrl(document) {
93
+ export function extractPdsUrl(document) {
108
94
  const service = document.service?.find(isAtprotoPersonalDataServerService, document);
109
95
  if (!service) {
110
- throw new did_error_js_1.DidError(document.id, `Document ${document.id} does not contain a (valid) #atproto_pds service URL`, 'did-service-not-found');
96
+ throw new DidError(document.id, `Document ${document.id} does not contain a (valid) #atproto_pds service URL`, 'did-service-not-found');
111
97
  }
112
98
  return new URL(service.serviceEndpoint);
113
99
  }
114
- function isAtprotoAka(value) {
100
+ export function isAtprotoAka(value) {
115
101
  return value.startsWith('at://');
116
102
  }
117
- function isAtprotoPersonalDataServerService(service) {
103
+ export function isAtprotoPersonalDataServerService(service) {
118
104
  return (service?.type === 'AtprotoPersonalDataServer' &&
119
105
  typeof service.serviceEndpoint === 'string' &&
120
- (0, uri_js_1.canParse)(service.serviceEndpoint) &&
121
- (0, utils_js_1.matchesIdentifier)(this.id, 'atproto_pds', service.id));
106
+ canParse(service.serviceEndpoint) &&
107
+ matchesIdentifier(this.id, 'atproto_pds', service.id));
122
108
  }
123
- exports.ATPROTO_VERIFICATION_METHOD_TYPES = Object.freeze([
109
+ export const ATPROTO_VERIFICATION_METHOD_TYPES = Object.freeze([
124
110
  'EcdsaSecp256r1VerificationKey2019',
125
111
  'EcdsaSecp256k1VerificationKey2019',
126
112
  'Multikey',
127
113
  ]);
128
- function isAtprotoVerificationMethod(method) {
114
+ export function isAtprotoVerificationMethod(method) {
129
115
  return (typeof method === 'object' &&
130
116
  typeof method?.publicKeyMultibase === 'string' &&
131
- exports.ATPROTO_VERIFICATION_METHOD_TYPES.includes(method.type) &&
132
- (0, utils_js_1.matchesIdentifier)(this.id, 'atproto', method.id));
117
+ ATPROTO_VERIFICATION_METHOD_TYPES.includes(method.type) &&
118
+ matchesIdentifier(this.id, 'atproto', method.id));
133
119
  }
134
120
  //# sourceMappingURL=atproto.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"atproto.js","sourceRoot":"","sources":["../src/atproto.ts"],"names":[],"mappings":";;;AAyBA,oCAEC;AAED,oCAGC;AAED,4CAaC;AAED,kDAkBC;AAKD,0CAcC;AAmDD,gDAeC;AAED,sCAeC;AAGD,oCAEC;AAUD,gFAYC;AAmBD,kEAiBC;AAxOD,6BAAuB;AAEvB,iDAA0D;AAE1D,yCAAmD;AACnD,6CAOqB;AACrB,yCAA0D;AAQ7C,QAAA,gBAAgB,GAAG,OAAC;KAC9B,MAAM,EAAE;KACR,MAAM,CAAC,YAAY,EAAE,iDAAiD,CAAC,CAAA;AAE1E,SAAgB,YAAY,CAAC,KAAc;IACzC,OAAO,IAAA,qBAAQ,EAAC,KAAK,CAAC,IAAI,eAAe,CAAC,KAAK,CAAC,CAAA;AAClD,CAAC;AAED,SAAgB,YAAY,CAAI,KAAQ;IACtC,gBAAgB,CAAC,KAAK,CAAC,CAAA;IACvB,OAAO,KAAK,CAAA;AACd,CAAC;AAED,SAAgB,gBAAgB,CAAC,KAAc;IAC7C,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,IAAI,8BAAe,CAAC,OAAO,KAAK,EAAE,sBAAsB,CAAC,CAAA;IACjE,CAAC;SAAM,IAAI,KAAK,CAAC,UAAU,CAAC,2BAAc,CAAC,EAAE,CAAC;QAC5C,IAAA,yBAAY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CAChE,MAAM,CAAC,IAAI,CACZ;QACD,IAAA,4BAAiB,EAAC,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE,CAAC,CACjD,CAAA;AACH,CAAC","sourcesContent":["import { z } from 'zod'\nimport { DidDocument, DidService } from './did-document.js'\nimport { DidError, InvalidDidError } from './did-error.js'\nimport { Did } from './did.js'\nimport { canParse, isFragment } from './lib/uri.js'\nimport {\n DID_PLC_PREFIX,\n DID_WEB_PREFIX,\n assertDidPlc,\n assertDidWeb,\n isDidPlc,\n isDidWeb,\n} from './methods.js'\nimport { Identifier, matchesIdentifier } from './utils.js'\n\n// This file contains atproto-specific DID validation utilities.\n\nexport type AtprotoIdentityDidMethods = 'plc' | 'web'\nexport type AtprotoDid = Did<AtprotoIdentityDidMethods>\nexport type AtprotoDidDocument = DidDocument<AtprotoIdentityDidMethods>\n\nexport const atprotoDidSchema = z\n .string()\n .refine(isAtprotoDid, `Atproto only allows \"plc\" and \"web\" DID methods`)\n\nexport function isAtprotoDid(input: unknown): input is AtprotoDid {\n return isDidPlc(input) || isAtprotoDidWeb(input)\n}\n\nexport function asAtprotoDid<T>(input: T) {\n assertAtprotoDid(input)\n return input\n}\n\nexport function assertAtprotoDid(input: unknown): asserts input is AtprotoDid {\n if (typeof input !== 'string') {\n throw new InvalidDidError(typeof input, `DID must be a string`)\n } else if (input.startsWith(DID_PLC_PREFIX)) {\n assertDidPlc(input)\n } else if (input.startsWith(DID_WEB_PREFIX)) {\n assertAtprotoDidWeb(input)\n } else {\n throw new InvalidDidError(\n input,\n `Atproto only allows \"plc\" and \"web\" DID methods`,\n )\n }\n}\n\nexport function assertAtprotoDidWeb(\n input: unknown,\n): asserts input is Did<'web'> {\n assertDidWeb(input)\n\n if (isDidWebWithPath(input)) {\n throw new InvalidDidError(\n input,\n `Atproto does not allow path components in Web DIDs`,\n )\n }\n\n if (isDidWebWithHttpsPort(input)) {\n throw new InvalidDidError(\n input,\n `Atproto does not allow port numbers in Web DIDs, except for localhost`,\n )\n }\n}\n\n/**\n * @see {@link https://atproto.com/specs/did#blessed-did-methods}\n */\nexport function isAtprotoDidWeb(input: unknown): input is Did<'web'> {\n if (!isDidWeb(input)) {\n return false\n }\n\n if (isDidWebWithPath(input)) {\n return false\n }\n\n if (isDidWebWithHttpsPort(input)) {\n return false\n }\n\n return true\n}\n\nfunction isDidWebWithPath(did: Did<'web'>): boolean {\n return did.includes(':', DID_WEB_PREFIX.length)\n}\n\nfunction isLocalhostDid(did: Did<'web'>): boolean {\n return (\n did === 'did:web:localhost' ||\n did.startsWith('did:web:localhost:') ||\n did.startsWith('did:web:localhost%3A')\n )\n}\n\nfunction isDidWebWithHttpsPort(did: Did<'web'>): boolean {\n if (isLocalhostDid(did)) return false\n\n const pathIdx = did.indexOf(':', DID_WEB_PREFIX.length)\n\n const hasPort =\n pathIdx === -1\n ? // No path component, check if there's a port separator anywhere after\n // the \"did:web:\" prefix\n did.includes('%3A', DID_WEB_PREFIX.length)\n : // There is a path component; if there is an encoded colon *before* it,\n // then there is a port number\n did.lastIndexOf('%3A', pathIdx) !== -1\n\n return hasPort\n}\n\nexport type AtprotoAudience = `${AtprotoDid}#${string}`\nexport const isAtprotoAudience = (value: unknown): value is AtprotoAudience => {\n if (typeof value !== 'string') return false\n const hashIndex = value.indexOf('#')\n if (hashIndex === -1) return false\n if (value.indexOf('#', hashIndex + 1) !== -1) return false\n return (\n isFragment(value, hashIndex + 1) && isAtprotoDid(value.slice(0, hashIndex))\n )\n}\n\nexport type AtprotoData<\n M extends AtprotoIdentityDidMethods = AtprotoIdentityDidMethods,\n> = {\n did: Did<M>\n aka?: string\n key?: AtprotoVerificationMethod<M>\n pds?: AtprotoPersonalDataServerService<M>\n}\n\nexport function extractAtprotoData<M extends AtprotoIdentityDidMethods>(\n document: DidDocument<M>,\n): AtprotoData<M> {\n return {\n did: document.id,\n aka: document.alsoKnownAs?.find(isAtprotoAka)?.slice(5),\n key: document.verificationMethod?.find(\n isAtprotoVerificationMethod<M>,\n document,\n ),\n pds: document.service?.find(\n isAtprotoPersonalDataServerService<M>,\n document,\n ),\n }\n}\n\nexport function extractPdsUrl(document: AtprotoDidDocument): URL {\n const service = document.service?.find(\n isAtprotoPersonalDataServerService,\n document,\n )\n\n if (!service) {\n throw new DidError(\n document.id,\n `Document ${document.id} does not contain a (valid) #atproto_pds service URL`,\n 'did-service-not-found',\n )\n }\n\n return new URL(service.serviceEndpoint)\n}\n\nexport type AtprotoAka = `at://${string}`\nexport function isAtprotoAka(value: string): value is AtprotoAka {\n return value.startsWith('at://')\n}\n\nexport type AtprotoPersonalDataServerService<\n M extends AtprotoIdentityDidMethods = AtprotoIdentityDidMethods,\n> = DidService & {\n id: Identifier<Did<M>, 'atproto_pds'>\n type: 'AtprotoPersonalDataServer'\n serviceEndpoint: string\n}\n\nexport function isAtprotoPersonalDataServerService<\n M extends AtprotoIdentityDidMethods = AtprotoIdentityDidMethods,\n>(\n this: DidDocument<M>,\n service: null | undefined | DidService,\n): service is AtprotoPersonalDataServerService<M> {\n return (\n service?.type === 'AtprotoPersonalDataServer' &&\n typeof service.serviceEndpoint === 'string' &&\n canParse(service.serviceEndpoint) &&\n matchesIdentifier(this.id, 'atproto_pds', service.id)\n )\n}\n\nexport const ATPROTO_VERIFICATION_METHOD_TYPES = Object.freeze([\n 'EcdsaSecp256r1VerificationKey2019',\n 'EcdsaSecp256k1VerificationKey2019',\n 'Multikey',\n] as const)\nexport type SupportedAtprotoVerificationMethodType =\n (typeof ATPROTO_VERIFICATION_METHOD_TYPES)[number]\n\ntype VerificationMethod = NonNullable<DidDocument['verificationMethod']>[number]\nexport type AtprotoVerificationMethod<\n M extends AtprotoIdentityDidMethods = AtprotoIdentityDidMethods,\n> = Extract<VerificationMethod, object> & {\n id: Identifier<Did<M>, 'atproto'>\n type: SupportedAtprotoVerificationMethodType\n publicKeyMultibase: string\n}\n\nexport function isAtprotoVerificationMethod<\n M extends AtprotoIdentityDidMethods = AtprotoIdentityDidMethods,\n>(\n this: DidDocument<M>,\n method:\n | null\n | undefined\n | NonNullable<DidDocument<M>['verificationMethod']>[number],\n): method is AtprotoVerificationMethod<M> {\n return (\n typeof method === 'object' &&\n typeof method?.publicKeyMultibase === 'string' &&\n (ATPROTO_VERIFICATION_METHOD_TYPES as readonly unknown[]).includes(\n method.type,\n ) &&\n matchesIdentifier(this.id, 'atproto', method.id)\n )\n}\n"]}
1
+ {"version":3,"file":"atproto.js","sourceRoot":"","sources":["../src/atproto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAE1D,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACnD,OAAO,EACL,cAAc,EACd,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,QAAQ,EACR,QAAQ,GACT,MAAM,cAAc,CAAA;AACrB,OAAO,EAAc,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAQ1D,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC;KAC9B,MAAM,EAAE;KACR,MAAM,CAAC,YAAY,EAAE,iDAAiD,CAAC,CAAA;AAE1E,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,eAAe,CAAC,KAAK,CAAC,CAAA;AAClD,CAAC;AAED,MAAM,UAAU,YAAY,CAAI,KAAQ;IACtC,gBAAgB,CAAC,KAAK,CAAC,CAAA;IACvB,OAAO,KAAK,CAAA;AACd,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,KAAc;IAC7C,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,IAAI,eAAe,CAAC,OAAO,KAAK,EAAE,sBAAsB,CAAC,CAAA;IACjE,CAAC;SAAM,IAAI,KAAK,CAAC,UAAU,CAAC,cAAc,CAAC,EAAE,CAAC;QAC5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M,CAAC,IAAI,CACZ;QACD,iBAAiB,CAAC,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE,CAAC,CACjD,CAAA;AACH,CAAC","sourcesContent":["import { z } from 'zod'\nimport { DidDocument, DidService } from './did-document.js'\nimport { DidError, InvalidDidError } from './did-error.js'\nimport { Did } from './did.js'\nimport { canParse, isFragment } from './lib/uri.js'\nimport {\n DID_PLC_PREFIX,\n DID_WEB_PREFIX,\n assertDidPlc,\n assertDidWeb,\n isDidPlc,\n isDidWeb,\n} from './methods.js'\nimport { Identifier, matchesIdentifier } from './utils.js'\n\n// This file contains atproto-specific DID validation utilities.\n\nexport type AtprotoIdentityDidMethods = 'plc' | 'web'\nexport type AtprotoDid = Did<AtprotoIdentityDidMethods>\nexport type AtprotoDidDocument = DidDocument<AtprotoIdentityDidMethods>\n\nexport const atprotoDidSchema = z\n .string()\n .refine(isAtprotoDid, `Atproto only allows \"plc\" and \"web\" DID methods`)\n\nexport function isAtprotoDid(input: unknown): input is AtprotoDid {\n return isDidPlc(input) || isAtprotoDidWeb(input)\n}\n\nexport function asAtprotoDid<T>(input: T) {\n assertAtprotoDid(input)\n return input\n}\n\nexport function assertAtprotoDid(input: unknown): asserts input is AtprotoDid {\n if (typeof input !== 'string') {\n throw new InvalidDidError(typeof input, `DID must be a string`)\n } else if (input.startsWith(DID_PLC_PREFIX)) {\n assertDidPlc(input)\n } else if (input.startsWith(DID_WEB_PREFIX)) {\n assertAtprotoDidWeb(input)\n } else {\n throw new InvalidDidError(\n input,\n `Atproto only allows \"plc\" and \"web\" DID methods`,\n )\n }\n}\n\nexport function assertAtprotoDidWeb(\n input: unknown,\n): asserts input is Did<'web'> {\n assertDidWeb(input)\n\n if (isDidWebWithPath(input)) {\n throw new InvalidDidError(\n input,\n `Atproto does not allow path components in Web DIDs`,\n )\n }\n\n if (isDidWebWithHttpsPort(input)) {\n throw new InvalidDidError(\n input,\n `Atproto does not allow port numbers in Web DIDs, except for localhost`,\n )\n }\n}\n\n/**\n * @see {@link https://atproto.com/specs/did#blessed-did-methods}\n */\nexport function isAtprotoDidWeb(input: unknown): input is Did<'web'> {\n if (!isDidWeb(input)) {\n return false\n }\n\n if (isDidWebWithPath(input)) {\n return false\n }\n\n if (isDidWebWithHttpsPort(input)) {\n return false\n }\n\n return true\n}\n\nfunction isDidWebWithPath(did: Did<'web'>): boolean {\n return did.includes(':', DID_WEB_PREFIX.length)\n}\n\nfunction isLocalhostDid(did: Did<'web'>): boolean {\n return (\n did === 'did:web:localhost' ||\n did.startsWith('did:web:localhost:') ||\n did.startsWith('did:web:localhost%3A')\n )\n}\n\nfunction isDidWebWithHttpsPort(did: Did<'web'>): boolean {\n if (isLocalhostDid(did)) return false\n\n const pathIdx = did.indexOf(':', DID_WEB_PREFIX.length)\n\n const hasPort =\n pathIdx === -1\n ? // No path component, check if there's a port separator anywhere after\n // the \"did:web:\" prefix\n did.includes('%3A', DID_WEB_PREFIX.length)\n : // There is a path component; if there is an encoded colon *before* it,\n // then there is a port number\n did.lastIndexOf('%3A', pathIdx) !== -1\n\n return hasPort\n}\n\nexport type AtprotoAudience = `${AtprotoDid}#${string}`\nexport const isAtprotoAudience = (value: unknown): value is AtprotoAudience => {\n if (typeof value !== 'string') return false\n const hashIndex = value.indexOf('#')\n if (hashIndex === -1) return false\n if (value.indexOf('#', hashIndex + 1) !== -1) return false\n return (\n isFragment(value, hashIndex + 1) && isAtprotoDid(value.slice(0, hashIndex))\n )\n}\n\nexport type AtprotoData<\n M extends AtprotoIdentityDidMethods = AtprotoIdentityDidMethods,\n> = {\n did: Did<M>\n aka?: string\n key?: AtprotoVerificationMethod<M>\n pds?: AtprotoPersonalDataServerService<M>\n}\n\nexport function extractAtprotoData<M extends AtprotoIdentityDidMethods>(\n document: DidDocument<M>,\n): AtprotoData<M> {\n return {\n did: document.id,\n aka: document.alsoKnownAs?.find(isAtprotoAka)?.slice(5),\n key: document.verificationMethod?.find(\n isAtprotoVerificationMethod<M>,\n document,\n ),\n pds: document.service?.find(\n isAtprotoPersonalDataServerService<M>,\n document,\n ),\n }\n}\n\nexport function extractPdsUrl(document: AtprotoDidDocument): URL {\n const service = document.service?.find(\n isAtprotoPersonalDataServerService,\n document,\n )\n\n if (!service) {\n throw new DidError(\n document.id,\n `Document ${document.id} does not contain a (valid) #atproto_pds service URL`,\n 'did-service-not-found',\n )\n }\n\n return new URL(service.serviceEndpoint)\n}\n\nexport type AtprotoAka = `at://${string}`\nexport function isAtprotoAka(value: string): value is AtprotoAka {\n return value.startsWith('at://')\n}\n\nexport type AtprotoPersonalDataServerService<\n M extends AtprotoIdentityDidMethods = AtprotoIdentityDidMethods,\n> = DidService & {\n id: Identifier<Did<M>, 'atproto_pds'>\n type: 'AtprotoPersonalDataServer'\n serviceEndpoint: string\n}\n\nexport function isAtprotoPersonalDataServerService<\n M extends AtprotoIdentityDidMethods = AtprotoIdentityDidMethods,\n>(\n this: DidDocument<M>,\n service: null | undefined | DidService,\n): service is AtprotoPersonalDataServerService<M> {\n return (\n service?.type === 'AtprotoPersonalDataServer' &&\n typeof service.serviceEndpoint === 'string' &&\n canParse(service.serviceEndpoint) &&\n matchesIdentifier(this.id, 'atproto_pds', service.id)\n )\n}\n\nexport const ATPROTO_VERIFICATION_METHOD_TYPES = Object.freeze([\n 'EcdsaSecp256r1VerificationKey2019',\n 'EcdsaSecp256k1VerificationKey2019',\n 'Multikey',\n] as const)\nexport type SupportedAtprotoVerificationMethodType =\n (typeof ATPROTO_VERIFICATION_METHOD_TYPES)[number]\n\ntype VerificationMethod = NonNullable<DidDocument['verificationMethod']>[number]\nexport type AtprotoVerificationMethod<\n M extends AtprotoIdentityDidMethods = AtprotoIdentityDidMethods,\n> = Extract<VerificationMethod, object> & {\n id: Identifier<Did<M>, 'atproto'>\n type: SupportedAtprotoVerificationMethodType\n publicKeyMultibase: string\n}\n\nexport function isAtprotoVerificationMethod<\n M extends AtprotoIdentityDidMethods = AtprotoIdentityDidMethods,\n>(\n this: DidDocument<M>,\n method:\n | null\n | undefined\n | NonNullable<DidDocument<M>['verificationMethod']>[number],\n): method is AtprotoVerificationMethod<M> {\n return (\n typeof method === 'object' &&\n typeof method?.publicKeyMultibase === 'string' &&\n (ATPROTO_VERIFICATION_METHOD_TYPES as readonly unknown[]).includes(\n method.type,\n ) &&\n matchesIdentifier(this.id, 'atproto', method.id)\n )\n}\n"]}
@@ -23,7 +23,7 @@ export type DidService = z.infer<typeof didServiceSchema>;
23
23
  * @see {@link https://www.w3.org/TR/did-core/#production-0}
24
24
  */
25
25
  export declare const didDocumentSchema: z.ZodObject<{
26
- '@context': z.ZodUnion<[z.ZodLiteral<"https://www.w3.org/ns/did/v1">, z.ZodEffects<z.ZodArray<z.ZodString, "atleastone">, [string, ...string[]], [string, ...string[]]>]>;
26
+ '@context': z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"https://www.w3.org/ns/did/v1">, z.ZodEffects<z.ZodArray<z.ZodString, "atleastone">, [string, ...string[]], [string, ...string[]]>]>>;
27
27
  id: z.ZodEffects<z.ZodString, `did:${string}:${string}`, string>;
28
28
  controller: z.ZodOptional<z.ZodUnion<[z.ZodEffects<z.ZodString, `did:${string}:${string}`, string>, z.ZodArray<z.ZodEffects<z.ZodString, `did:${string}:${string}`, string>, "many">]>>;
29
29
  alsoKnownAs: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
@@ -59,7 +59,7 @@ export declare const didDocumentSchema: z.ZodObject<{
59
59
  publicKeyJwk?: Record<string, unknown> | undefined;
60
60
  publicKeyMultibase?: string | undefined;
61
61
  }>]>, "many">>;
62
- verificationMethod: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodObject<{
62
+ verificationMethod: z.ZodOptional<z.ZodArray<z.ZodObject<{
63
63
  id: z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>]>;
64
64
  type: z.ZodString;
65
65
  controller: z.ZodUnion<[z.ZodEffects<z.ZodString, `did:${string}:${string}`, string>, z.ZodArray<z.ZodEffects<z.ZodString, `did:${string}:${string}`, string>, "many">]>;
@@ -77,11 +77,11 @@ export declare const didDocumentSchema: z.ZodObject<{
77
77
  controller: string | string[];
78
78
  publicKeyJwk?: Record<string, unknown> | undefined;
79
79
  publicKeyMultibase?: string | undefined;
80
- }>, z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>]>]>, "many">>;
80
+ }>, "many">>;
81
81
  }, "strip", z.ZodTypeAny, {
82
82
  id: `did:${string}:${string}`;
83
- '@context': "https://www.w3.org/ns/did/v1" | [string, ...string[]];
84
83
  controller?: `did:${string}:${string}` | `did:${string}:${string}`[] | undefined;
84
+ '@context'?: "https://www.w3.org/ns/did/v1" | [string, ...string[]] | undefined;
85
85
  alsoKnownAs?: string[] | undefined;
86
86
  service?: {
87
87
  type: string | string[];
@@ -95,17 +95,17 @@ export declare const didDocumentSchema: z.ZodObject<{
95
95
  publicKeyJwk?: Record<string, unknown> | undefined;
96
96
  publicKeyMultibase?: string | undefined;
97
97
  })[] | undefined;
98
- verificationMethod?: (string | {
98
+ verificationMethod?: {
99
99
  type: string;
100
100
  id: string;
101
101
  controller: `did:${string}:${string}` | `did:${string}:${string}`[];
102
102
  publicKeyJwk?: Record<string, unknown> | undefined;
103
103
  publicKeyMultibase?: string | undefined;
104
- })[] | undefined;
104
+ }[] | undefined;
105
105
  }, {
106
106
  id: string;
107
- '@context': "https://www.w3.org/ns/did/v1" | [string, ...string[]];
108
107
  controller?: string | string[] | undefined;
108
+ '@context'?: "https://www.w3.org/ns/did/v1" | [string, ...string[]] | undefined;
109
109
  alsoKnownAs?: string[] | undefined;
110
110
  service?: {
111
111
  type: string | string[];
@@ -119,19 +119,19 @@ export declare const didDocumentSchema: z.ZodObject<{
119
119
  publicKeyJwk?: Record<string, unknown> | undefined;
120
120
  publicKeyMultibase?: string | undefined;
121
121
  })[] | undefined;
122
- verificationMethod?: (string | {
122
+ verificationMethod?: {
123
123
  type: string;
124
124
  id: string;
125
125
  controller: string | string[];
126
126
  publicKeyJwk?: Record<string, unknown> | undefined;
127
127
  publicKeyMultibase?: string | undefined;
128
- })[] | undefined;
128
+ }[] | undefined;
129
129
  }>;
130
130
  export type DidDocument<Method extends string = string> = z.infer<typeof didDocumentSchema> & {
131
131
  id: Did<Method>;
132
132
  };
133
133
  export declare const didDocumentValidator: z.ZodEffects<z.ZodObject<{
134
- '@context': z.ZodUnion<[z.ZodLiteral<"https://www.w3.org/ns/did/v1">, z.ZodEffects<z.ZodArray<z.ZodString, "atleastone">, [string, ...string[]], [string, ...string[]]>]>;
134
+ '@context': z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"https://www.w3.org/ns/did/v1">, z.ZodEffects<z.ZodArray<z.ZodString, "atleastone">, [string, ...string[]], [string, ...string[]]>]>>;
135
135
  id: z.ZodEffects<z.ZodString, `did:${string}:${string}`, string>;
136
136
  controller: z.ZodOptional<z.ZodUnion<[z.ZodEffects<z.ZodString, `did:${string}:${string}`, string>, z.ZodArray<z.ZodEffects<z.ZodString, `did:${string}:${string}`, string>, "many">]>>;
137
137
  alsoKnownAs: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
@@ -167,7 +167,7 @@ export declare const didDocumentValidator: z.ZodEffects<z.ZodObject<{
167
167
  publicKeyJwk?: Record<string, unknown> | undefined;
168
168
  publicKeyMultibase?: string | undefined;
169
169
  }>]>, "many">>;
170
- verificationMethod: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodObject<{
170
+ verificationMethod: z.ZodOptional<z.ZodArray<z.ZodObject<{
171
171
  id: z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>]>;
172
172
  type: z.ZodString;
173
173
  controller: z.ZodUnion<[z.ZodEffects<z.ZodString, `did:${string}:${string}`, string>, z.ZodArray<z.ZodEffects<z.ZodString, `did:${string}:${string}`, string>, "many">]>;
@@ -185,11 +185,11 @@ export declare const didDocumentValidator: z.ZodEffects<z.ZodObject<{
185
185
  controller: string | string[];
186
186
  publicKeyJwk?: Record<string, unknown> | undefined;
187
187
  publicKeyMultibase?: string | undefined;
188
- }>, z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>]>]>, "many">>;
188
+ }>, "many">>;
189
189
  }, "strip", z.ZodTypeAny, {
190
190
  id: `did:${string}:${string}`;
191
- '@context': "https://www.w3.org/ns/did/v1" | [string, ...string[]];
192
191
  controller?: `did:${string}:${string}` | `did:${string}:${string}`[] | undefined;
192
+ '@context'?: "https://www.w3.org/ns/did/v1" | [string, ...string[]] | undefined;
193
193
  alsoKnownAs?: string[] | undefined;
194
194
  service?: {
195
195
  type: string | string[];
@@ -203,17 +203,17 @@ export declare const didDocumentValidator: z.ZodEffects<z.ZodObject<{
203
203
  publicKeyJwk?: Record<string, unknown> | undefined;
204
204
  publicKeyMultibase?: string | undefined;
205
205
  })[] | undefined;
206
- verificationMethod?: (string | {
206
+ verificationMethod?: {
207
207
  type: string;
208
208
  id: string;
209
209
  controller: `did:${string}:${string}` | `did:${string}:${string}`[];
210
210
  publicKeyJwk?: Record<string, unknown> | undefined;
211
211
  publicKeyMultibase?: string | undefined;
212
- })[] | undefined;
212
+ }[] | undefined;
213
213
  }, {
214
214
  id: string;
215
- '@context': "https://www.w3.org/ns/did/v1" | [string, ...string[]];
216
215
  controller?: string | string[] | undefined;
216
+ '@context'?: "https://www.w3.org/ns/did/v1" | [string, ...string[]] | undefined;
217
217
  alsoKnownAs?: string[] | undefined;
218
218
  service?: {
219
219
  type: string | string[];
@@ -227,17 +227,17 @@ export declare const didDocumentValidator: z.ZodEffects<z.ZodObject<{
227
227
  publicKeyJwk?: Record<string, unknown> | undefined;
228
228
  publicKeyMultibase?: string | undefined;
229
229
  })[] | undefined;
230
- verificationMethod?: (string | {
230
+ verificationMethod?: {
231
231
  type: string;
232
232
  id: string;
233
233
  controller: string | string[];
234
234
  publicKeyJwk?: Record<string, unknown> | undefined;
235
235
  publicKeyMultibase?: string | undefined;
236
- })[] | undefined;
236
+ }[] | undefined;
237
237
  }>, {
238
238
  id: `did:${string}:${string}`;
239
- '@context': "https://www.w3.org/ns/did/v1" | [string, ...string[]];
240
239
  controller?: `did:${string}:${string}` | `did:${string}:${string}`[] | undefined;
240
+ '@context'?: "https://www.w3.org/ns/did/v1" | [string, ...string[]] | undefined;
241
241
  alsoKnownAs?: string[] | undefined;
242
242
  service?: {
243
243
  type: string | string[];
@@ -251,17 +251,17 @@ export declare const didDocumentValidator: z.ZodEffects<z.ZodObject<{
251
251
  publicKeyJwk?: Record<string, unknown> | undefined;
252
252
  publicKeyMultibase?: string | undefined;
253
253
  })[] | undefined;
254
- verificationMethod?: (string | {
254
+ verificationMethod?: {
255
255
  type: string;
256
256
  id: string;
257
257
  controller: `did:${string}:${string}` | `did:${string}:${string}`[];
258
258
  publicKeyJwk?: Record<string, unknown> | undefined;
259
259
  publicKeyMultibase?: string | undefined;
260
- })[] | undefined;
260
+ }[] | undefined;
261
261
  }, {
262
262
  id: string;
263
- '@context': "https://www.w3.org/ns/did/v1" | [string, ...string[]];
264
263
  controller?: string | string[] | undefined;
264
+ '@context'?: "https://www.w3.org/ns/did/v1" | [string, ...string[]] | undefined;
265
265
  alsoKnownAs?: string[] | undefined;
266
266
  service?: {
267
267
  type: string | string[];
@@ -275,13 +275,13 @@ export declare const didDocumentValidator: z.ZodEffects<z.ZodObject<{
275
275
  publicKeyJwk?: Record<string, unknown> | undefined;
276
276
  publicKeyMultibase?: string | undefined;
277
277
  })[] | undefined;
278
- verificationMethod?: (string | {
278
+ verificationMethod?: {
279
279
  type: string;
280
280
  id: string;
281
281
  controller: string | string[];
282
282
  publicKeyJwk?: Record<string, unknown> | undefined;
283
283
  publicKeyMultibase?: string | undefined;
284
- })[] | undefined;
284
+ }[] | undefined;
285
285
  }>;
286
286
  export {};
287
287
  //# sourceMappingURL=did-document.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"did-document.d.ts","sourceRoot":"","sources":["../src/did-document.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,GAAG,EAAa,MAAM,UAAU,CAAA;AA+EzC;;;GAGG;AACH,QAAA,MAAM,gBAAgB;;;;;;;;;;;;EAIpB,CAAA;AAEF,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAA;AAQzD;;;GAGG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkB5B,CAAA;AAEF,MAAM,MAAM,WAAW,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM,IAAI,CAAC,CAAC,KAAK,CAC/D,OAAO,iBAAiB,CACzB,GAAG;IAAE,EAAE,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;CAAE,CAAA;AAGvB,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAwB7B,CAAA"}
1
+ {"version":3,"file":"did-document.d.ts","sourceRoot":"","sources":["../src/did-document.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,GAAG,EAAa,MAAM,UAAU,CAAA;AAkFzC;;;GAGG;AACH,QAAA,MAAM,gBAAgB;;;;;;;;;;;;EAIpB,CAAA;AAEF,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAA;AAWzD;;;GAGG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmB5B,CAAA;AAEF,MAAM,MAAM,WAAW,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM,IAAI,CAAC,CAAC,KAAK,CAC/D,OAAO,iBAAiB,CACzB,GAAG;IAAE,EAAE,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;CAAE,CAAA;AAGvB,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAwB7B,CAAA"}
@@ -1,43 +1,43 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.didDocumentValidator = exports.didDocumentSchema = void 0;
4
- const zod_1 = require("zod");
5
- const did_js_1 = require("./did.js");
6
- const uri_js_1 = require("./lib/uri.js");
1
+ import { z } from 'zod';
2
+ import { didSchema } from './did.js';
3
+ import { isFragment } from './lib/uri.js';
7
4
  /**
8
5
  * RFC3968 compliant URI
9
6
  *
10
7
  * @see {@link https://www.rfc-editor.org/rfc/rfc3986}
11
8
  */
12
- const rfc3968UriSchema = zod_1.z.string().url('RFC3968 compliant URI');
13
- const didControllerSchema = zod_1.z.union([did_js_1.didSchema, zod_1.z.array(did_js_1.didSchema)]);
9
+ const rfc3968UriSchema = z.string().url('RFC3968 compliant URI');
10
+ const didControllerSchema = z.union([didSchema, z.array(didSchema)]);
14
11
  /**
15
12
  * @note this schema is too permissive
16
13
  */
17
- const didRelativeUriSchema = zod_1.z.union([
14
+ const didRelativeUriSchema = z.union([
18
15
  rfc3968UriSchema.refine((value) => {
19
16
  const fragmentIndex = value.indexOf('#');
20
17
  if (fragmentIndex === -1)
21
18
  return false;
22
- return (0, uri_js_1.isFragment)(value, fragmentIndex + 1);
19
+ return isFragment(value, fragmentIndex + 1);
23
20
  }, {
24
21
  message: 'Missing or invalid fragment in RFC3968 URI',
25
22
  }),
26
- zod_1.z
23
+ z
27
24
  .string()
28
25
  .refine((value) => value.charCodeAt(0) === 35 /* # */, {
29
26
  message: 'Fragment must start with #',
30
27
  })
31
- .refine((value) => (0, uri_js_1.isFragment)(value, 1), {
28
+ .refine((value) => isFragment(value, 1), {
32
29
  message: 'Invalid char in URI fragment',
33
30
  }),
34
31
  ]);
35
- const didVerificationMethodSchema = zod_1.z.object({
32
+ /**
33
+ * @see {@link https://www.w3.org/TR/did-1.0/#verification-material Verification Material}
34
+ */
35
+ const didVerificationMethodSchema = z.object({
36
36
  id: didRelativeUriSchema,
37
- type: zod_1.z.string().min(1),
37
+ type: z.string().min(1),
38
38
  controller: didControllerSchema,
39
- publicKeyJwk: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).optional(),
40
- publicKeyMultibase: zod_1.z.string().optional(),
39
+ publicKeyJwk: z.record(z.string(), z.unknown()).optional(),
40
+ publicKeyMultibase: z.string().optional(),
41
41
  });
42
42
  /**
43
43
  * The value of the id property MUST be a URI conforming to [RFC3986]. A
@@ -56,7 +56,7 @@ const didServiceIdSchema = didRelativeUriSchema;
56
56
  * SHOULD be registered in the DID Specification Registries
57
57
  * [DID-SPEC-REGISTRIES].
58
58
  */
59
- const didServiceTypeSchema = zod_1.z.union([zod_1.z.string(), zod_1.z.array(zod_1.z.string())]);
59
+ const didServiceTypeSchema = z.union([z.string(), z.array(z.string())]);
60
60
  /**
61
61
  * The value of the serviceEndpoint property MUST be a string, a map, or a set
62
62
  * composed of one or more strings and/or maps. All string values MUST be valid
@@ -64,23 +64,26 @@ const didServiceTypeSchema = zod_1.z.union([zod_1.z.string(), zod_1.z.array(zod_
64
64
  * and Comparison rules in RFC3986 and to any normalization rules in its
65
65
  * applicable URI scheme specification.
66
66
  */
67
- const didServiceEndpointSchema = zod_1.z.union([
67
+ const didServiceEndpointSchema = z.union([
68
68
  rfc3968UriSchema,
69
- zod_1.z.record(zod_1.z.string(), rfc3968UriSchema),
70
- zod_1.z
71
- .array(zod_1.z.union([rfc3968UriSchema, zod_1.z.record(zod_1.z.string(), rfc3968UriSchema)]))
69
+ z.record(z.string(), rfc3968UriSchema),
70
+ z
71
+ .array(z.union([rfc3968UriSchema, z.record(z.string(), rfc3968UriSchema)]))
72
72
  .nonempty(),
73
73
  ]);
74
74
  /**
75
75
  * Each service map MUST contain id, type, and serviceEndpoint properties.
76
76
  * @see {@link https://www.w3.org/TR/did-core/#services}
77
77
  */
78
- const didServiceSchema = zod_1.z.object({
78
+ const didServiceSchema = z.object({
79
79
  id: didServiceIdSchema,
80
80
  type: didServiceTypeSchema,
81
81
  serviceEndpoint: didServiceEndpointSchema,
82
82
  });
83
- const didAuthenticationSchema = zod_1.z.union([
83
+ /**
84
+ * @see {@link https://www.w3.org/TR/did-1.0/#referring-to-verification-methods Referring to Verification Methods}
85
+ */
86
+ const verificationMethodReference = z.union([
84
87
  //
85
88
  didRelativeUriSchema,
86
89
  didVerificationMethodSchema,
@@ -89,27 +92,28 @@ const didAuthenticationSchema = zod_1.z.union([
89
92
  * @note This schema is incomplete
90
93
  * @see {@link https://www.w3.org/TR/did-core/#production-0}
91
94
  */
92
- exports.didDocumentSchema = zod_1.z.object({
93
- '@context': zod_1.z.union([
94
- zod_1.z.literal('https://www.w3.org/ns/did/v1'),
95
- zod_1.z
96
- .array(zod_1.z.string().url())
95
+ export const didDocumentSchema = z.object({
96
+ '@context': z
97
+ .union([
98
+ z.literal('https://www.w3.org/ns/did/v1'),
99
+ z
100
+ .array(z.string().url())
97
101
  .nonempty()
98
102
  .refine((data) => data[0] === 'https://www.w3.org/ns/did/v1', {
99
103
  message: 'First @context must be https://www.w3.org/ns/did/v1',
100
104
  }),
101
- ]),
102
- id: did_js_1.didSchema,
103
- controller: didControllerSchema.optional(),
104
- alsoKnownAs: zod_1.z.array(rfc3968UriSchema).optional(),
105
- service: zod_1.z.array(didServiceSchema).optional(),
106
- authentication: zod_1.z.array(didAuthenticationSchema).optional(),
107
- verificationMethod: zod_1.z
108
- .array(zod_1.z.union([didVerificationMethodSchema, didRelativeUriSchema]))
105
+ ])
106
+ // @NOTE @context is required by producers, but optional for consumers.
109
107
  .optional(),
108
+ id: didSchema,
109
+ controller: didControllerSchema.optional(),
110
+ alsoKnownAs: z.array(rfc3968UriSchema).optional(),
111
+ service: z.array(didServiceSchema).optional(),
112
+ authentication: z.array(verificationMethodReference).optional(),
113
+ verificationMethod: z.array(didVerificationMethodSchema).optional(),
110
114
  });
111
115
  // @TODO: add other refinements ?
112
- exports.didDocumentValidator = exports.didDocumentSchema
116
+ export const didDocumentValidator = didDocumentSchema
113
117
  // Ensure that every service id is unique
114
118
  .superRefine(({ id: did, service }, ctx) => {
115
119
  if (service) {
@@ -124,7 +128,7 @@ exports.didDocumentValidator = exports.didDocumentSchema
124
128
  }
125
129
  else {
126
130
  ctx.addIssue({
127
- code: zod_1.z.ZodIssueCode.custom,
131
+ code: z.ZodIssueCode.custom,
128
132
  message: `Duplicate service id (${current.id}) found in the document`,
129
133
  path: ['service', i, 'id'],
130
134
  });