@atproto/did 0.2.3 → 0.3.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 +14 -0
- package/LICENSE.txt +1 -1
- package/dist/atproto.d.ts +2 -1
- package/dist/atproto.d.ts.map +1 -1
- package/dist/atproto.js.map +1 -1
- package/dist/did-document.d.ts +24 -24
- package/dist/did-document.d.ts.map +1 -1
- package/dist/did-document.js +14 -7
- package/dist/did-document.js.map +1 -1
- package/package.json +1 -1
- package/src/atproto.ts +2 -3
- package/src/did-document.ts +21 -14
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @atproto/did
|
|
2
2
|
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#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
|
|
8
|
+
|
|
9
|
+
- [#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)
|
|
10
|
+
|
|
11
|
+
## 0.2.4
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [#4501](https://github.com/bluesky-social/atproto/pull/4501) [`2f78893`](https://github.com/bluesky-social/atproto/commit/2f78893ace3bbf14d4bac36837820ddb46658c98) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Expose new `AtprotoDidDocument` type
|
|
16
|
+
|
|
3
17
|
## 0.2.3
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/LICENSE.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Dual MIT/Apache-2.0 License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2022-
|
|
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.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { Did } from './did.js';
|
|
|
4
4
|
import { Identifier } from './utils.js';
|
|
5
5
|
export type AtprotoIdentityDidMethods = 'plc' | 'web';
|
|
6
6
|
export type AtprotoDid = Did<AtprotoIdentityDidMethods>;
|
|
7
|
+
export type AtprotoDidDocument = DidDocument<AtprotoIdentityDidMethods>;
|
|
7
8
|
export declare const atprotoDidSchema: z.ZodEffects<z.ZodString, `did:plc:${string}` | `did:web:${string}`, string>;
|
|
8
9
|
export declare function isAtprotoDid(input: unknown): input is AtprotoDid;
|
|
9
10
|
export declare function asAtprotoDid<T>(input: T): (T & `did:plc:${string}`) | (T & `did:web:${string}`);
|
|
@@ -22,7 +23,7 @@ export type AtprotoData<M extends AtprotoIdentityDidMethods = AtprotoIdentityDid
|
|
|
22
23
|
pds?: AtprotoPersonalDataServerService<M>;
|
|
23
24
|
};
|
|
24
25
|
export declare function extractAtprotoData<M extends AtprotoIdentityDidMethods>(document: DidDocument<M>): AtprotoData<M>;
|
|
25
|
-
export declare function extractPdsUrl(document:
|
|
26
|
+
export declare function extractPdsUrl(document: AtprotoDidDocument): URL;
|
|
26
27
|
export type AtprotoAka = `at://${string}`;
|
|
27
28
|
export declare function isAtprotoAka(value: string): value is AtprotoAka;
|
|
28
29
|
export type AtprotoPersonalDataServerService<M extends AtprotoIdentityDidMethods = AtprotoIdentityDidMethods> = DidService & {
|
package/dist/atproto.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"atproto.d.ts","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AO,CACL,OAAO,EAAE,IAAI,KAAK,2BAA2B;QAC7C,OAAO,OAAO,CAAC,eAAe,KAAK,QAAQ;QAC3C,IAAA,iBAAQ,EAAC,OAAO,CAAC,eAAe,CAAC;QACjC,IAAA,4BAAiB,EAAC,IAAI,CAAC,EAAE,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,CAAC,CACtD,CAAA;AACH,CAAC;AAEY,QAAA,iCAAiC,GAAG,MAAM,CAAC,MAAM,CAAC;IAC7D,mCAAmC;IACnC,mCAAmC;IACnC,UAAU;CACF,CAAC,CAAA;AAaX,SAAgB,2BAA2B,CAIzC,MAG6D;IAE7D,OAAO,CACL,OAAO,MAAM,KAAK,QAAQ;QAC1B,OAAO,MAAM,EAAE,kBAAkB,KAAK,QAAQ;QAC7C,yCAAwD,CAAC,QAAQ,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>\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(\n document: DidDocument<AtprotoIdentityDidMethods>,\n): 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":";;;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,CAA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jC,IAAA,4BAAiB,EAAC,IAAI,CAAC,EAAE,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,CAAC,CACtD,CAAA;AACH,CAAC;AAEY,QAAA,iCAAiC,GAAG,MAAM,CAAC,MAAM,CAAC;IAC7D,mCAAmC;IACnC,mCAAmC;IACnC,UAAU;CACF,CAAC,CAAA;AAaX,SAAgB,2BAA2B,CAIzC,MAG6D;IAE7D,OAAO,CACL,OAAO,MAAM,KAAK,QAAQ;QAC1B,OAAO,MAAM,EAAE,kBAAkB,KAAK,QAAQ;QAC7C,yCAAwD,CAAC,QAAQ,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"]}
|
package/dist/did-document.d.ts
CHANGED
|
@@ -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.
|
|
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
|
-
}>,
|
|
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?:
|
|
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
|
-
}
|
|
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?:
|
|
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
|
-
}
|
|
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.
|
|
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
|
-
}>,
|
|
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?:
|
|
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
|
-
}
|
|
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?:
|
|
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
|
-
}
|
|
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?:
|
|
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
|
-
}
|
|
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?:
|
|
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
|
-
}
|
|
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;
|
|
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"}
|
package/dist/did-document.js
CHANGED
|
@@ -32,6 +32,9 @@ const didRelativeUriSchema = zod_1.z.union([
|
|
|
32
32
|
message: 'Invalid char in URI fragment',
|
|
33
33
|
}),
|
|
34
34
|
]);
|
|
35
|
+
/**
|
|
36
|
+
* @see {@link https://www.w3.org/TR/did-1.0/#verification-material Verification Material}
|
|
37
|
+
*/
|
|
35
38
|
const didVerificationMethodSchema = zod_1.z.object({
|
|
36
39
|
id: didRelativeUriSchema,
|
|
37
40
|
type: zod_1.z.string().min(1),
|
|
@@ -80,7 +83,10 @@ const didServiceSchema = zod_1.z.object({
|
|
|
80
83
|
type: didServiceTypeSchema,
|
|
81
84
|
serviceEndpoint: didServiceEndpointSchema,
|
|
82
85
|
});
|
|
83
|
-
|
|
86
|
+
/**
|
|
87
|
+
* @see {@link https://www.w3.org/TR/did-1.0/#referring-to-verification-methods Referring to Verification Methods}
|
|
88
|
+
*/
|
|
89
|
+
const verificationMethodReference = zod_1.z.union([
|
|
84
90
|
//
|
|
85
91
|
didRelativeUriSchema,
|
|
86
92
|
didVerificationMethodSchema,
|
|
@@ -90,7 +96,8 @@ const didAuthenticationSchema = zod_1.z.union([
|
|
|
90
96
|
* @see {@link https://www.w3.org/TR/did-core/#production-0}
|
|
91
97
|
*/
|
|
92
98
|
exports.didDocumentSchema = zod_1.z.object({
|
|
93
|
-
'@context': zod_1.z
|
|
99
|
+
'@context': zod_1.z
|
|
100
|
+
.union([
|
|
94
101
|
zod_1.z.literal('https://www.w3.org/ns/did/v1'),
|
|
95
102
|
zod_1.z
|
|
96
103
|
.array(zod_1.z.string().url())
|
|
@@ -98,15 +105,15 @@ exports.didDocumentSchema = zod_1.z.object({
|
|
|
98
105
|
.refine((data) => data[0] === 'https://www.w3.org/ns/did/v1', {
|
|
99
106
|
message: 'First @context must be https://www.w3.org/ns/did/v1',
|
|
100
107
|
}),
|
|
101
|
-
])
|
|
108
|
+
])
|
|
109
|
+
// @NOTE @context is required by producers, but optional for consumers.
|
|
110
|
+
.optional(),
|
|
102
111
|
id: did_js_1.didSchema,
|
|
103
112
|
controller: didControllerSchema.optional(),
|
|
104
113
|
alsoKnownAs: zod_1.z.array(rfc3968UriSchema).optional(),
|
|
105
114
|
service: zod_1.z.array(didServiceSchema).optional(),
|
|
106
|
-
authentication: zod_1.z.array(
|
|
107
|
-
verificationMethod: zod_1.z
|
|
108
|
-
.array(zod_1.z.union([didVerificationMethodSchema, didRelativeUriSchema]))
|
|
109
|
-
.optional(),
|
|
115
|
+
authentication: zod_1.z.array(verificationMethodReference).optional(),
|
|
116
|
+
verificationMethod: zod_1.z.array(didVerificationMethodSchema).optional(),
|
|
110
117
|
});
|
|
111
118
|
// @TODO: add other refinements ?
|
|
112
119
|
exports.didDocumentValidator = exports.didDocumentSchema
|
package/dist/did-document.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"did-document.js","sourceRoot":"","sources":["../src/did-document.ts"],"names":[],"mappings":";;;AAAA,6BAAuB;AACvB,qCAAyC;AACzC,yCAAyC;AAEzC;;;;GAIG;AACH,MAAM,gBAAgB,GAAG,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAA;AAEhE,MAAM,mBAAmB,GAAG,OAAC,CAAC,KAAK,CAAC,CAAC,kBAAS,EAAE,OAAC,CAAC,KAAK,CAAC,kBAAS,CAAC,CAAC,CAAC,CAAA;AAEpE;;GAEG;AACH,MAAM,oBAAoB,GAAG,OAAC,CAAC,KAAK,CAAC;IACnC,gBAAgB,CAAC,MAAM,CACrB,CAAC,KAAK,EAAE,EAAE;QACR,MAAM,aAAa,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;QACxC,IAAI,aAAa,KAAK,CAAC,CAAC;YAAE,OAAO,KAAK,CAAA;QACtC,OAAO,IAAA,mBAAU,EAAC,KAAK,EAAE,aAAa,GAAG,CAAC,CAAC,CAAA;IAC7C,CAAC,EACD;QACE,OAAO,EAAE,4CAA4C;KACtD,CACF;IACD,OAAC;SACE,MAAM,EAAE;SACR,MAAM,CAAC,CAAC,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GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;YAE1B,MAAM,SAAS,GAAG,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC;gBAC1C,CAAC,CAAC,GAAG,GAAG,GAAG,OAAO,CAAC,EAAE,EAAE;gBACvB,CAAC,CAAC,OAAO,CAAC,EAAE,CAAA;YAEd,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;gBAC5B,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;YACxB,CAAC;iBAAM,CAAC;gBACN,GAAG,CAAC,QAAQ,CAAC;oBACX,IAAI,EAAE,OAAC,CAAC,YAAY,CAAC,MAAM;oBAC3B,OAAO,EAAE,yBAAyB,OAAO,CAAC,EAAE,yBAAyB;oBACrE,IAAI,EAAE,CAAC,SAAS,EAAE,CAAC,EAAE,IAAI,CAAC;iBAC3B,CAAC,CAAA;YACJ,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC,CAAC,CAAA","sourcesContent":["import { z } from 'zod'\nimport { Did, didSchema } from './did.js'\nimport { isFragment } from './lib/uri.js'\n\n/**\n * RFC3968 compliant URI\n *\n * @see {@link https://www.rfc-editor.org/rfc/rfc3986}\n */\nconst rfc3968UriSchema = z.string().url('RFC3968 compliant URI')\n\nconst didControllerSchema = z.union([didSchema, z.array(didSchema)])\n\n/**\n * @note this schema is too permissive\n */\nconst didRelativeUriSchema = z.union([\n rfc3968UriSchema.refine(\n (value) => {\n const fragmentIndex = value.indexOf('#')\n if (fragmentIndex === -1) return false\n return isFragment(value, fragmentIndex + 1)\n },\n {\n message: 'Missing or invalid fragment in RFC3968 URI',\n },\n ),\n z\n .string()\n .refine((value) => value.charCodeAt(0) === 35 /* # */, {\n message: 'Fragment must start with #',\n })\n .refine((value) => isFragment(value, 1), {\n message: 'Invalid char in URI fragment',\n }),\n])\n\n/**\n * @see {@link https://www.w3.org/TR/did-1.0/#verification-material Verification Material}\n */\nconst didVerificationMethodSchema = z.object({\n id: didRelativeUriSchema,\n type: z.string().min(1),\n controller: didControllerSchema,\n publicKeyJwk: z.record(z.string(), z.unknown()).optional(),\n publicKeyMultibase: z.string().optional(),\n})\n\n/**\n * The value of the id property MUST be a URI conforming to [RFC3986]. A\n * conforming producer MUST NOT produce multiple service entries with the same\n * id. A conforming consumer MUST produce an error if it detects multiple\n * service entries with the same id.\n *\n * @note Normally, only rfc3968UriSchema should be allowed here. However, the\n * did:plc uses relative URI. For this reason, we also allow relative URIs\n * here.\n */\nconst didServiceIdSchema = didRelativeUriSchema\n\n/**\n * The value of the type property MUST be a string or a set of strings. In order\n * to maximize interoperability, the service type and its associated properties\n * SHOULD be registered in the DID Specification Registries\n * [DID-SPEC-REGISTRIES].\n */\nconst didServiceTypeSchema = z.union([z.string(), z.array(z.string())])\n\n/**\n * The value of the serviceEndpoint property MUST be a string, a map, or a set\n * composed of one or more strings and/or maps. All string values MUST be valid\n * URIs conforming to [RFC3986] and normalized according to the Normalization\n * and Comparison rules in RFC3986 and to any normalization rules in its\n * applicable URI scheme specification.\n */\nconst didServiceEndpointSchema = z.union([\n rfc3968UriSchema,\n z.record(z.string(), rfc3968UriSchema),\n z\n .array(z.union([rfc3968UriSchema, z.record(z.string(), rfc3968UriSchema)]))\n .nonempty(),\n])\n\n/**\n * Each service map MUST contain id, type, and serviceEndpoint properties.\n * @see {@link https://www.w3.org/TR/did-core/#services}\n */\nconst didServiceSchema = z.object({\n id: didServiceIdSchema,\n type: didServiceTypeSchema,\n serviceEndpoint: didServiceEndpointSchema,\n})\n\nexport type DidService = z.infer<typeof didServiceSchema>\n\n/**\n * @see {@link https://www.w3.org/TR/did-1.0/#referring-to-verification-methods Referring to Verification Methods}\n */\nconst verificationMethodReference = z.union([\n //\n didRelativeUriSchema,\n didVerificationMethodSchema,\n])\n\n/**\n * @note This schema is incomplete\n * @see {@link https://www.w3.org/TR/did-core/#production-0}\n */\nexport const didDocumentSchema = z.object({\n '@context': z\n .union([\n z.literal('https://www.w3.org/ns/did/v1'),\n z\n .array(z.string().url())\n .nonempty()\n .refine((data) => data[0] === 'https://www.w3.org/ns/did/v1', {\n message: 'First @context must be https://www.w3.org/ns/did/v1',\n }),\n ])\n // @NOTE @context is required by producers, but optional for consumers.\n .optional(),\n id: didSchema,\n controller: didControllerSchema.optional(),\n alsoKnownAs: z.array(rfc3968UriSchema).optional(),\n service: z.array(didServiceSchema).optional(),\n authentication: z.array(verificationMethodReference).optional(),\n verificationMethod: z.array(didVerificationMethodSchema).optional(),\n})\n\nexport type DidDocument<Method extends string = string> = z.infer<\n typeof didDocumentSchema\n> & { id: Did<Method> }\n\n// @TODO: add other refinements ?\nexport const didDocumentValidator = didDocumentSchema\n // Ensure that every service id is unique\n .superRefine(({ id: did, service }, ctx) => {\n if (service) {\n const visited = new Set()\n\n for (let i = 0; i < service.length; i++) {\n const current = service[i]\n\n const serviceId = current.id.startsWith('#')\n ? `${did}${current.id}`\n : current.id\n\n if (!visited.has(serviceId)) {\n visited.add(serviceId)\n } else {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: `Duplicate service id (${current.id}) found in the document`,\n path: ['service', i, 'id'],\n })\n }\n }\n }\n })\n"]}
|
package/package.json
CHANGED
package/src/atproto.ts
CHANGED
|
@@ -17,6 +17,7 @@ import { Identifier, matchesIdentifier } from './utils.js'
|
|
|
17
17
|
|
|
18
18
|
export type AtprotoIdentityDidMethods = 'plc' | 'web'
|
|
19
19
|
export type AtprotoDid = Did<AtprotoIdentityDidMethods>
|
|
20
|
+
export type AtprotoDidDocument = DidDocument<AtprotoIdentityDidMethods>
|
|
20
21
|
|
|
21
22
|
export const atprotoDidSchema = z
|
|
22
23
|
.string()
|
|
@@ -151,9 +152,7 @@ export function extractAtprotoData<M extends AtprotoIdentityDidMethods>(
|
|
|
151
152
|
}
|
|
152
153
|
}
|
|
153
154
|
|
|
154
|
-
export function extractPdsUrl(
|
|
155
|
-
document: DidDocument<AtprotoIdentityDidMethods>,
|
|
156
|
-
): URL {
|
|
155
|
+
export function extractPdsUrl(document: AtprotoDidDocument): URL {
|
|
157
156
|
const service = document.service?.find(
|
|
158
157
|
isAtprotoPersonalDataServerService,
|
|
159
158
|
document,
|
package/src/did-document.ts
CHANGED
|
@@ -35,6 +35,9 @@ const didRelativeUriSchema = z.union([
|
|
|
35
35
|
}),
|
|
36
36
|
])
|
|
37
37
|
|
|
38
|
+
/**
|
|
39
|
+
* @see {@link https://www.w3.org/TR/did-1.0/#verification-material Verification Material}
|
|
40
|
+
*/
|
|
38
41
|
const didVerificationMethodSchema = z.object({
|
|
39
42
|
id: didRelativeUriSchema,
|
|
40
43
|
type: z.string().min(1),
|
|
@@ -90,7 +93,10 @@ const didServiceSchema = z.object({
|
|
|
90
93
|
|
|
91
94
|
export type DidService = z.infer<typeof didServiceSchema>
|
|
92
95
|
|
|
93
|
-
|
|
96
|
+
/**
|
|
97
|
+
* @see {@link https://www.w3.org/TR/did-1.0/#referring-to-verification-methods Referring to Verification Methods}
|
|
98
|
+
*/
|
|
99
|
+
const verificationMethodReference = z.union([
|
|
94
100
|
//
|
|
95
101
|
didRelativeUriSchema,
|
|
96
102
|
didVerificationMethodSchema,
|
|
@@ -101,23 +107,24 @@ const didAuthenticationSchema = z.union([
|
|
|
101
107
|
* @see {@link https://www.w3.org/TR/did-core/#production-0}
|
|
102
108
|
*/
|
|
103
109
|
export const didDocumentSchema = z.object({
|
|
104
|
-
'@context': z
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
110
|
+
'@context': z
|
|
111
|
+
.union([
|
|
112
|
+
z.literal('https://www.w3.org/ns/did/v1'),
|
|
113
|
+
z
|
|
114
|
+
.array(z.string().url())
|
|
115
|
+
.nonempty()
|
|
116
|
+
.refine((data) => data[0] === 'https://www.w3.org/ns/did/v1', {
|
|
117
|
+
message: 'First @context must be https://www.w3.org/ns/did/v1',
|
|
118
|
+
}),
|
|
119
|
+
])
|
|
120
|
+
// @NOTE @context is required by producers, but optional for consumers.
|
|
121
|
+
.optional(),
|
|
113
122
|
id: didSchema,
|
|
114
123
|
controller: didControllerSchema.optional(),
|
|
115
124
|
alsoKnownAs: z.array(rfc3968UriSchema).optional(),
|
|
116
125
|
service: z.array(didServiceSchema).optional(),
|
|
117
|
-
authentication: z.array(
|
|
118
|
-
verificationMethod: z
|
|
119
|
-
.array(z.union([didVerificationMethodSchema, didRelativeUriSchema]))
|
|
120
|
-
.optional(),
|
|
126
|
+
authentication: z.array(verificationMethodReference).optional(),
|
|
127
|
+
verificationMethod: z.array(didVerificationMethodSchema).optional(),
|
|
121
128
|
})
|
|
122
129
|
|
|
123
130
|
export type DidDocument<Method extends string = string> = z.infer<
|