@atproto/did 0.1.1-rc.1 → 0.1.2
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 +16 -0
- package/dist/atproto.d.ts +2 -1
- package/dist/atproto.d.ts.map +1 -1
- package/dist/atproto.js +21 -17
- package/dist/atproto.js.map +1 -1
- package/dist/did-document.d.ts +1 -49
- package/dist/did-document.d.ts.map +1 -1
- package/dist/did-document.js +14 -21
- package/dist/did-document.js.map +1 -1
- package/dist/did.d.ts +3 -3
- package/dist/did.d.ts.map +1 -1
- package/dist/did.js +12 -12
- package/dist/did.js.map +1 -1
- package/dist/methods/plc.d.ts +1 -1
- package/dist/methods/plc.d.ts.map +1 -1
- package/dist/methods/plc.js +16 -14
- package/dist/methods/plc.js.map +1 -1
- package/dist/methods/web.d.ts +1 -1
- package/dist/methods/web.d.ts.map +1 -1
- package/dist/methods/web.js +11 -7
- package/dist/methods/web.js.map +1 -1
- package/package.json +1 -1
- package/src/atproto.ts +29 -20
- package/src/did-document.ts +16 -24
- package/src/did.ts +8 -8
- package/src/methods/plc.ts +16 -13
- package/src/methods/web.ts +10 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @atproto/did
|
|
2
2
|
|
|
3
|
+
## 0.1.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#2776](https://github.com/bluesky-social/atproto/pull/2776) [`cb4abbb67`](https://github.com/bluesky-social/atproto/commit/cb4abbb673c69a8a89b49dca5c038f3da2153c6c) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Disallow path component in Web DID's (as per spec)
|
|
8
|
+
|
|
9
|
+
- [#2776](https://github.com/bluesky-social/atproto/pull/2776) [`cb4abbb67`](https://github.com/bluesky-social/atproto/commit/cb4abbb673c69a8a89b49dca5c038f3da2153c6c) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Properly parse localhost did:web
|
|
10
|
+
|
|
11
|
+
- [#2776](https://github.com/bluesky-social/atproto/pull/2776) [`cb4abbb67`](https://github.com/bluesky-social/atproto/commit/cb4abbb673c69a8a89b49dca5c038f3da2153c6c) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Code optimizations and documentation. Rename `check*` utility function to `assert*`.
|
|
12
|
+
|
|
13
|
+
## 0.1.1
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- [#2483](https://github.com/bluesky-social/atproto/pull/2483) [`b934b396b`](https://github.com/bluesky-social/atproto/commit/b934b396b13ba32bf2bf7e75ecdf6871e5f310dd) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Expose atproto specific types and utilities
|
|
18
|
+
|
|
3
19
|
## 0.1.0
|
|
4
20
|
|
|
5
21
|
### Minor Changes
|
package/dist/atproto.d.ts
CHANGED
|
@@ -3,7 +3,8 @@ export type AtprotoIdentityDidMethods = 'plc' | 'web';
|
|
|
3
3
|
export type AtprotoDid = Did<AtprotoIdentityDidMethods>;
|
|
4
4
|
export declare function isAtprotoDid(input: unknown): input is AtprotoDid;
|
|
5
5
|
export declare function asAtprotoDid(input: unknown): AtprotoDid;
|
|
6
|
-
export declare function
|
|
6
|
+
export declare function assertAtprotoDid(input: unknown): asserts input is AtprotoDid;
|
|
7
|
+
export declare function assertAtprotoDidWeb(input: unknown): asserts input is Did<'web'>;
|
|
7
8
|
/**
|
|
8
9
|
* @see {@link https://atproto.com/specs/did#blessed-did-methods}
|
|
9
10
|
*/
|
package/dist/atproto.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"atproto.d.ts","sourceRoot":"","sources":["../src/atproto.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"atproto.d.ts","sourceRoot":"","sources":["../src/atproto.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAW9B,MAAM,MAAM,yBAAyB,GAAG,KAAK,GAAG,KAAK,CAAA;AACrD,MAAM,MAAM,UAAU,GAAG,GAAG,CAAC,yBAAyB,CAAC,CAAA;AAEvD,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU,CAahE;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,CAGvD;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,KAAK,IAAI,UAAU,CAa5E;AAED,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,KAAK,IAAI,GAAG,CAAC,KAAK,CAAC,CAmB7B;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,GAAG,CAAC,KAAK,CAAC,CAOnE"}
|
package/dist/atproto.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isAtprotoDidWeb = exports.
|
|
3
|
+
exports.isAtprotoDidWeb = exports.assertAtprotoDidWeb = exports.assertAtprotoDid = exports.asAtprotoDid = exports.isAtprotoDid = void 0;
|
|
4
4
|
const did_error_js_1 = require("./did-error.js");
|
|
5
5
|
const methods_js_1 = require("./methods.js");
|
|
6
6
|
function isAtprotoDid(input) {
|
|
@@ -21,43 +21,47 @@ function isAtprotoDid(input) {
|
|
|
21
21
|
}
|
|
22
22
|
exports.isAtprotoDid = isAtprotoDid;
|
|
23
23
|
function asAtprotoDid(input) {
|
|
24
|
-
|
|
24
|
+
assertAtprotoDid(input);
|
|
25
25
|
return input;
|
|
26
26
|
}
|
|
27
27
|
exports.asAtprotoDid = asAtprotoDid;
|
|
28
|
-
function
|
|
28
|
+
function assertAtprotoDid(input) {
|
|
29
29
|
if (typeof input !== 'string') {
|
|
30
30
|
throw new did_error_js_1.InvalidDidError(typeof input, `DID must be a string`);
|
|
31
31
|
}
|
|
32
32
|
else if (input.startsWith(methods_js_1.DID_PLC_PREFIX)) {
|
|
33
|
-
(0, methods_js_1.
|
|
33
|
+
(0, methods_js_1.assertDidPlc)(input);
|
|
34
34
|
}
|
|
35
35
|
else if (input.startsWith(methods_js_1.DID_WEB_PREFIX)) {
|
|
36
|
-
(
|
|
36
|
+
assertAtprotoDidWeb(input);
|
|
37
37
|
}
|
|
38
38
|
else {
|
|
39
39
|
throw new did_error_js_1.InvalidDidError(input, `Atproto only allows "plc" and "web" DID methods`);
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
-
exports.
|
|
42
|
+
exports.assertAtprotoDid = assertAtprotoDid;
|
|
43
|
+
function assertAtprotoDidWeb(input) {
|
|
44
|
+
(0, methods_js_1.assertDidWeb)(input);
|
|
45
|
+
if (input.includes(':', methods_js_1.DID_WEB_PREFIX.length)) {
|
|
46
|
+
throw new did_error_js_1.InvalidDidError(input, `Atproto does not allow path components in Web DIDs`);
|
|
47
|
+
}
|
|
48
|
+
if (input.includes('%3A', methods_js_1.DID_WEB_PREFIX.length) &&
|
|
49
|
+
!input.startsWith('did:web:localhost%3A')) {
|
|
50
|
+
throw new did_error_js_1.InvalidDidError(input, `Atproto does not allow port numbers in Web DIDs, except for localhost`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.assertAtprotoDidWeb = assertAtprotoDidWeb;
|
|
43
54
|
/**
|
|
44
55
|
* @see {@link https://atproto.com/specs/did#blessed-did-methods}
|
|
45
56
|
*/
|
|
46
57
|
function isAtprotoDidWeb(input) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return
|
|
50
|
-
}
|
|
51
|
-
// Path are not allowed
|
|
52
|
-
if (input.includes(':', methods_js_1.DID_WEB_PREFIX.length)) {
|
|
53
|
-
return false;
|
|
58
|
+
try {
|
|
59
|
+
assertAtprotoDidWeb(input);
|
|
60
|
+
return true;
|
|
54
61
|
}
|
|
55
|
-
|
|
56
|
-
if (input.includes('%3A', methods_js_1.DID_WEB_PREFIX.length) &&
|
|
57
|
-
!input.startsWith('did:web:localhost%3A')) {
|
|
62
|
+
catch {
|
|
58
63
|
return false;
|
|
59
64
|
}
|
|
60
|
-
return (0, methods_js_1.isDidWeb)(input);
|
|
61
65
|
}
|
|
62
66
|
exports.isAtprotoDidWeb = isAtprotoDidWeb;
|
|
63
67
|
//# sourceMappingURL=atproto.js.map
|
package/dist/atproto.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"atproto.js","sourceRoot":"","sources":["../src/atproto.ts"],"names":[],"mappings":";;;AAAA,iDAAgD;AAEhD,
|
|
1
|
+
{"version":3,"file":"atproto.js","sourceRoot":"","sources":["../src/atproto.ts"],"names":[],"mappings":";;;AAAA,iDAAgD;AAEhD,6CAMqB;AAOrB,SAAgB,YAAY,CAAC,KAAc;IACzC,2BAA2B;IAC3B,mDAAmD;IAEnD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAA;IACd,CAAC;SAAM,IAAI,KAAK,CAAC,UAAU,CAAC,2BAAc,CAAC,EAAE,CAAC;QAC5C,OAAO,IAAA,qBAAQ,EAAC,KAAK,CAAC,CAAA;IACxB,CAAC;SAAM,IAAI,KAAK,CAAC,UAAU,CAAC,2BAAc,CAAC,EAAE,CAAC;QAC5C,OAAO,eAAe,CAAC,KAAK,CAAC,CAAA;IAC/B,CAAC;SAAM,CAAC;QACN,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC;AAbD,oCAaC;AAED,SAAgB,YAAY,CAAC,KAAc;IACzC,gBAAgB,CAAC,KAAK,CAAC,CAAA;IACvB,OAAO,KAAK,CAAA;AACd,CAAC;AAHD,oCAGC;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,EAAC,KAAK,CAAC,CAAA;IACrB,CAAC;SAAM,IAAI,KAAK,CAAC,UAAU,CAAC,2BAAc,CAAC,EAAE,CAAC;QAC5C,mBAAmB,CAAC,KAAK,CAAC,CAAA;IAC5B,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,8BAAe,CACvB,KAAK,EACL,iDAAiD,CAClD,CAAA;IACH,CAAC;AACH,CAAC;AAbD,4CAaC;AAED,SAAgB,mBAAmB,CACjC,KAAc;IAEd,IAAA,yBAAY,EAAC,KAAK,CAAC,CAAA;IAEnB,IAAI,KAAK,CAAC,QAAQ,CAAC,GAAG,EAAE,2BAAc,CAAC,MAAM,CAAC,EAAE,CAAC;QAC/C,MAAM,IAAI,8BAAe,CACvB,KAAK,EACL,oDAAoD,CACrD,CAAA;IACH,CAAC;IAED,IACE,KAAK,CAAC,QAAQ,CAAC,KAAK,EAAE,2BAAc,CAAC,MAAM,CAAC;QAC5C,CAAC,KAAK,CAAC,UAAU,CAAC,sBAAsB,CAAC,EACzC,CAAC;QACD,MAAM,IAAI,8BAAe,CACvB,KAAK,EACL,uEAAuE,CACxE,CAAA;IACH,CAAC;AACH,CAAC;AArBD,kDAqBC;AAED;;GAEG;AACH,SAAgB,eAAe,CAAC,KAAc;IAC5C,IAAI,CAAC;QACH,mBAAmB,CAAC,KAAK,CAAC,CAAA;QAC1B,OAAO,IAAI,CAAA;IACb,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC;AAPD,0CAOC"}
|
package/dist/did-document.d.ts
CHANGED
|
@@ -130,7 +130,7 @@ export declare const didDocumentSchema: z.ZodObject<{
|
|
|
130
130
|
export type DidDocument<Method extends string = string> = z.infer<typeof didDocumentSchema> & {
|
|
131
131
|
id: Did<Method>;
|
|
132
132
|
};
|
|
133
|
-
export declare const didDocumentValidator: z.ZodEffects<z.
|
|
133
|
+
export declare const didDocumentValidator: z.ZodEffects<z.ZodObject<{
|
|
134
134
|
'@context': 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">]>>;
|
|
@@ -282,54 +282,6 @@ export declare const didDocumentValidator: z.ZodEffects<z.ZodEffects<z.ZodObject
|
|
|
282
282
|
publicKeyJwk?: Record<string, unknown> | undefined;
|
|
283
283
|
publicKeyMultibase?: string | undefined;
|
|
284
284
|
})[] | undefined;
|
|
285
|
-
}>, {
|
|
286
|
-
id: `did:${string}:${string}`;
|
|
287
|
-
'@context': "https://www.w3.org/ns/did/v1" | [string, ...string[]];
|
|
288
|
-
controller?: `did:${string}:${string}` | `did:${string}:${string}`[] | undefined;
|
|
289
|
-
alsoKnownAs?: string[] | undefined;
|
|
290
|
-
service?: {
|
|
291
|
-
type: string | string[];
|
|
292
|
-
id: string;
|
|
293
|
-
serviceEndpoint: string | Record<string, string> | [string | Record<string, string>, ...(string | Record<string, string>)[]];
|
|
294
|
-
}[] | undefined;
|
|
295
|
-
authentication?: (string | {
|
|
296
|
-
type: string;
|
|
297
|
-
id: string;
|
|
298
|
-
controller: `did:${string}:${string}` | `did:${string}:${string}`[];
|
|
299
|
-
publicKeyJwk?: Record<string, unknown> | undefined;
|
|
300
|
-
publicKeyMultibase?: string | undefined;
|
|
301
|
-
})[] | undefined;
|
|
302
|
-
verificationMethod?: (string | {
|
|
303
|
-
type: string;
|
|
304
|
-
id: string;
|
|
305
|
-
controller: `did:${string}:${string}` | `did:${string}:${string}`[];
|
|
306
|
-
publicKeyJwk?: Record<string, unknown> | undefined;
|
|
307
|
-
publicKeyMultibase?: string | undefined;
|
|
308
|
-
})[] | undefined;
|
|
309
|
-
}, {
|
|
310
|
-
id: string;
|
|
311
|
-
'@context': "https://www.w3.org/ns/did/v1" | [string, ...string[]];
|
|
312
|
-
controller?: string | string[] | undefined;
|
|
313
|
-
alsoKnownAs?: string[] | undefined;
|
|
314
|
-
service?: {
|
|
315
|
-
type: string | string[];
|
|
316
|
-
id: string;
|
|
317
|
-
serviceEndpoint: string | Record<string, string> | [string | Record<string, string>, ...(string | Record<string, string>)[]];
|
|
318
|
-
}[] | undefined;
|
|
319
|
-
authentication?: (string | {
|
|
320
|
-
type: string;
|
|
321
|
-
id: string;
|
|
322
|
-
controller: string | string[];
|
|
323
|
-
publicKeyJwk?: Record<string, unknown> | undefined;
|
|
324
|
-
publicKeyMultibase?: string | undefined;
|
|
325
|
-
})[] | undefined;
|
|
326
|
-
verificationMethod?: (string | {
|
|
327
|
-
type: string;
|
|
328
|
-
id: string;
|
|
329
|
-
controller: string | string[];
|
|
330
|
-
publicKeyJwk?: Record<string, unknown> | undefined;
|
|
331
|
-
publicKeyMultibase?: string | undefined;
|
|
332
|
-
})[] | undefined;
|
|
333
285
|
}>;
|
|
334
286
|
export {};
|
|
335
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;AAEvB,OAAO,EAAE,GAAG,EAAa,MAAM,UAAU,CAAA;AAqEzC;;;GAGG;AACH,QAAA,MAAM,gBAAgB;;;;;;;;;;;;EAIpB,CAAA;AAEF,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAA;AAQzD;;;GAGG;AACH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;;;;;;;;;;;;;;;;;;;;EAwB7B,CAAA"}
|
package/dist/did-document.js
CHANGED
|
@@ -103,33 +103,26 @@ exports.didDocumentSchema = zod_1.z.object({
|
|
|
103
103
|
});
|
|
104
104
|
// @TODO: add other refinements ?
|
|
105
105
|
exports.didDocumentValidator = exports.didDocumentSchema
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
106
|
+
// Ensure that every service id is unique
|
|
107
|
+
.superRefine(({ id: did, service }, ctx) => {
|
|
108
|
+
if (service) {
|
|
109
|
+
const visited = new Set();
|
|
110
|
+
for (let i = 0; i < service.length; i++) {
|
|
111
|
+
const current = service[i];
|
|
112
|
+
const serviceId = current.id.startsWith('#')
|
|
113
|
+
? `${did}${current.id}`
|
|
114
|
+
: current.id;
|
|
115
|
+
if (!visited.has(serviceId)) {
|
|
116
|
+
visited.add(serviceId);
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
110
119
|
ctx.addIssue({
|
|
111
120
|
code: zod_1.z.ZodIssueCode.custom,
|
|
112
|
-
message: `
|
|
121
|
+
message: `Duplicate service id (${current.id}) found in the document`,
|
|
113
122
|
path: ['service', i, 'id'],
|
|
114
123
|
});
|
|
115
124
|
}
|
|
116
125
|
}
|
|
117
126
|
}
|
|
118
|
-
})
|
|
119
|
-
.superRefine((data, ctx) => {
|
|
120
|
-
if (data.service) {
|
|
121
|
-
const normalizedIds = data.service.map((s) => s.id?.startsWith('#') ? `${data.id}${s.id}` : s.id);
|
|
122
|
-
for (let i = 0; i < normalizedIds.length; i++) {
|
|
123
|
-
for (let j = i + 1; j < normalizedIds.length; j++) {
|
|
124
|
-
if (normalizedIds[i] === normalizedIds[j]) {
|
|
125
|
-
ctx.addIssue({
|
|
126
|
-
code: zod_1.z.ZodIssueCode.custom,
|
|
127
|
-
message: `Duplicate service id (${normalizedIds[j]}) found in the document`,
|
|
128
|
-
path: ['service', j, 'id'],
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
127
|
});
|
|
135
128
|
//# sourceMappingURL=did-document.js.map
|
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;AAEvB,qCAAyC;AAEzC;;;;GAIG;AACH,MAAM,gBAAgB,GAAG,OAAC,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE;IAClD,IAAI,CAAC;QACH,IAAI,GAAG,CAAC,IAAI,CAAC,CAAA;QACb,OAAO,IAAI,CAAA;IACb,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC,EAAE,uBAAuB,CAAC,CAAA;AAE3B,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;IAChB,OAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC;CAC7B,CAAC,CAAA;AAEF,MAAM,2BAA2B,GAAG,OAAC,CAAC,MAAM,CAAC;IAC3C,EAAE,EAAE,oBAAoB;IACxB,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACvB,UAAU,EAAE,mBAAmB;IAC/B,YAAY,EAAE,OAAC,CAAC,MAAM,CAAC,OAAC,CAAC,MAAM,EAAE,EAAE,OAAC,CAAC,OAAO,EAAE,CAAC,CAAC,QAAQ,EAAE;IAC1D,kBAAkB,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC1C,CAAC,CAAA;AAEF;;;;;;;;;GASG;AACH,MAAM,kBAAkB,GAAG,oB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AAG,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"}
|
package/dist/did.d.ts
CHANGED
|
@@ -38,7 +38,7 @@ type AsDidMethodInternal<S, Acc extends string> = S extends `${infer H}${infer T
|
|
|
38
38
|
* Check if the input is a valid DID method name, at the position between
|
|
39
39
|
* `start` (inclusive) and `end` (exclusive).
|
|
40
40
|
*/
|
|
41
|
-
export declare function
|
|
41
|
+
export declare function assertDidMethod(input: string, start?: number, end?: number): void;
|
|
42
42
|
/**
|
|
43
43
|
* This method assumes the input is a valid Did
|
|
44
44
|
*/
|
|
@@ -49,8 +49,8 @@ export declare function extractDidMethod<D extends Did>(did: D): D extends `did:
|
|
|
49
49
|
* Check if the input is a valid DID method-specific identifier, at the position
|
|
50
50
|
* between `start` (inclusive) and `end` (exclusive).
|
|
51
51
|
*/
|
|
52
|
-
export declare function
|
|
53
|
-
export declare function
|
|
52
|
+
export declare function assertDidMsid(input: string, start?: number, end?: number): void;
|
|
53
|
+
export declare function assertDid(input: unknown): asserts input is Did;
|
|
54
54
|
export declare function isDid(input: unknown): input is Did;
|
|
55
55
|
export declare function asDid(input: unknown): Did;
|
|
56
56
|
export declare const didSchema: z.ZodEffects<z.ZodString, `did:${string}:${string}`, string>;
|
package/dist/did.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"did.d.ts","sourceRoot":"","sources":["../src/did.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAGvB,QAAA,MAAM,UAAU,SAAS,CAAA;AAEzB,OAAO,EAAE,UAAU,EAAE,CAAA;AAErB;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,MAAM,GAAG,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,IAAI,OAAO,WAAW,CAAC,CAAC,CAAC,IAAI,MAAM,EAAE,CAAA;AAE9E;;GAEG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,MAAM,SAAS,CAAC,GACzC,MAAM,GACN,mBAAmB,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;AAE9B,KAAK,gBAAgB,GAAG,SAAS,GAAG,cAAc,CAAA;AAClD,KAAK,SAAS,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAA;AAC1E,KAAK,cAAc,GACf,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,CAAA;AAEP,KAAK,mBAAmB,CACtB,CAAC,EACD,GAAG,SAAS,MAAM,IAChB,CAAC,SAAS,GAAG,MAAM,CAAC,GAAG,MAAM,CAAC,EAAE,GAChC,CAAC,SAAS,gBAAgB,GACxB,mBAAmB,CAAC,CAAC,EAAE,G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,GAChC,CAAC,SAAS,gBAAgB,GACxB,mBAAmB,CAAC,CAAC,EAAE,GAAG,GAAG,GAAG,CAAC,EAAE,CAAC,GACpC,KAAK,GACP,GAAG,SAAS,EAAE,GACZ,KAAK,GACL,GAAG,CAAA;AAET;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,MAAM,EACb,KAAK,SAAI,EACT,GAAG,SAAe,GACjB,IAAI,CA0BN;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,GAAG,EAAE,GAAG,EAAE,CAAC,iFAIrD;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,MAAM,EACb,KAAK,SAAI,EACT,GAAG,SAAe,GACjB,IAAI,CAuEN;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,KAAK,IAAI,GAAG,CAqB9D;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,GAAG,CAYlD;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,OAAO,GAAG,GAAG,CAGzC;AAED,eAAO,MAAM,SAAS,8DAalB,CAAA"}
|
package/dist/did.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.didSchema = exports.asDid = exports.isDid = exports.
|
|
3
|
+
exports.didSchema = exports.asDid = exports.isDid = exports.assertDid = exports.assertDidMsid = exports.extractDidMethod = exports.assertDidMethod = exports.DID_PREFIX = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const did_error_js_1 = require("./did-error.js");
|
|
6
6
|
const DID_PREFIX = 'did:';
|
|
@@ -12,7 +12,7 @@ const DID_PREFIX_LENGTH = DID_PREFIX.length;
|
|
|
12
12
|
* Check if the input is a valid DID method name, at the position between
|
|
13
13
|
* `start` (inclusive) and `end` (exclusive).
|
|
14
14
|
*/
|
|
15
|
-
function
|
|
15
|
+
function assertDidMethod(input, start = 0, end = input.length) {
|
|
16
16
|
if (!Number.isFinite(end) ||
|
|
17
17
|
!Number.isFinite(start) ||
|
|
18
18
|
end < start ||
|
|
@@ -32,7 +32,7 @@ function checkDidMethod(input, start = 0, end = input.length) {
|
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
exports.
|
|
35
|
+
exports.assertDidMethod = assertDidMethod;
|
|
36
36
|
/**
|
|
37
37
|
* This method assumes the input is a valid Did
|
|
38
38
|
*/
|
|
@@ -48,7 +48,7 @@ exports.extractDidMethod = extractDidMethod;
|
|
|
48
48
|
* Check if the input is a valid DID method-specific identifier, at the position
|
|
49
49
|
* between `start` (inclusive) and `end` (exclusive).
|
|
50
50
|
*/
|
|
51
|
-
function
|
|
51
|
+
function assertDidMsid(input, start = 0, end = input.length) {
|
|
52
52
|
if (!Number.isFinite(end) ||
|
|
53
53
|
!Number.isFinite(start) ||
|
|
54
54
|
end < start ||
|
|
@@ -97,8 +97,8 @@ function checkDidMsid(input, start = 0, end = input.length) {
|
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
|
-
exports.
|
|
101
|
-
function
|
|
100
|
+
exports.assertDidMsid = assertDidMsid;
|
|
101
|
+
function assertDid(input) {
|
|
102
102
|
if (typeof input !== 'string') {
|
|
103
103
|
throw new did_error_js_1.InvalidDidError(typeof input, `DID must be a string`);
|
|
104
104
|
}
|
|
@@ -113,13 +113,13 @@ function checkDid(input) {
|
|
|
113
113
|
if (idSep === -1) {
|
|
114
114
|
throw new did_error_js_1.InvalidDidError(input, `Missing colon after method name`);
|
|
115
115
|
}
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
assertDidMethod(input, DID_PREFIX_LENGTH, idSep);
|
|
117
|
+
assertDidMsid(input, idSep + 1, length);
|
|
118
118
|
}
|
|
119
|
-
exports.
|
|
119
|
+
exports.assertDid = assertDid;
|
|
120
120
|
function isDid(input) {
|
|
121
121
|
try {
|
|
122
|
-
|
|
122
|
+
assertDid(input);
|
|
123
123
|
return true;
|
|
124
124
|
}
|
|
125
125
|
catch (err) {
|
|
@@ -132,7 +132,7 @@ function isDid(input) {
|
|
|
132
132
|
}
|
|
133
133
|
exports.isDid = isDid;
|
|
134
134
|
function asDid(input) {
|
|
135
|
-
|
|
135
|
+
assertDid(input);
|
|
136
136
|
return input;
|
|
137
137
|
}
|
|
138
138
|
exports.asDid = asDid;
|
|
@@ -140,7 +140,7 @@ exports.didSchema = zod_1.z
|
|
|
140
140
|
.string()
|
|
141
141
|
.superRefine((value, ctx) => {
|
|
142
142
|
try {
|
|
143
|
-
|
|
143
|
+
assertDid(value);
|
|
144
144
|
return true;
|
|
145
145
|
}
|
|
146
146
|
catch (err) {
|
package/dist/did.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"did.js","sourceRoot":"","sources":["../src/did.ts"],"names":[],"mappings":";;;AAAA,6BAAuB;AACvB,iDAA0D;AAE1D,MAAM,UAAU,GAAG,MAAM,CAAA;AAEhB,gCAAU;AADnB,MAAM,iBAAiB,GAAG,UAAU,CAAC,MAAM,CAAA;AA2E3C;;;;;GAKG;AACH,SAAgB,
|
|
1
|
+
{"version":3,"file":"did.js","sourceRoot":"","sources":["../src/did.ts"],"names":[],"mappings":";;;AAAA,6BAAuB;AACvB,iDAA0D;AAE1D,MAAM,UAAU,GAAG,MAAM,CAAA;AAEhB,gCAAU;AADnB,MAAM,iBAAiB,GAAG,UAAU,CAAC,MAAM,CAAA;AA2E3C;;;;;GAKG;AACH,SAAgB,eAAe,CAC7B,KAAa,EACb,KAAK,GAAG,CAAC,EACT,GAAG,GAAG,KAAK,CAAC,MAAM;IAElB,IACE,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC;QACrB,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;QACvB,GAAG,GAAG,KAAK;QACX,GAAG,GAAG,KA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4
4
|
export declare function isDidPlc(input: unknown): input is Did<'plc'>;
|
|
5
5
|
export declare function asDidPlc(input: unknown): Did<'plc'>;
|
|
6
|
-
export declare function
|
|
6
|
+
export declare function assertDidPlc(input: unknown): asserts input is Did<'plc'>;
|
|
7
7
|
//# sourceMappingURL=plc.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plc.d.ts","sourceRoot":"","sources":["../../src/methods/plc.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AAE/B,QAAA,MAAM,cAAc,aAAa,CAAA;AAIjC,OAAO,EAAE,cAAc,EAAE,CAAA;AAEzB,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,GAAG,CAAC,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"plc.d.ts","sourceRoot":"","sources":["../../src/methods/plc.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AAE/B,QAAA,MAAM,cAAc,aAAa,CAAA;AAIjC,OAAO,EAAE,cAAc,EAAE,CAAA;AAEzB,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,GAAG,CAAC,KAAK,CAAC,CAS5D;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,GAAG,CAAC,KAAK,CAAC,CAGnD;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,KAAK,IAAI,GAAG,CAAC,KAAK,CAAC,CAyBxE"}
|
package/dist/methods/plc.js
CHANGED
|
@@ -1,30 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.assertDidPlc = exports.asDidPlc = exports.isDidPlc = exports.DID_PLC_PREFIX = void 0;
|
|
4
4
|
const did_error_js_1 = require("../did-error.js");
|
|
5
5
|
const DID_PLC_PREFIX = `did:plc:`;
|
|
6
6
|
exports.DID_PLC_PREFIX = DID_PLC_PREFIX;
|
|
7
7
|
const DID_PLC_PREFIX_LENGTH = DID_PLC_PREFIX.length;
|
|
8
8
|
const DID_PLC_LENGTH = 32;
|
|
9
9
|
function isDidPlc(input) {
|
|
10
|
-
// Optimization:
|
|
10
|
+
// Optimization: equivalent to try/catch around "assertDidPlc"
|
|
11
11
|
if (typeof input !== 'string')
|
|
12
12
|
return false;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
catch {
|
|
13
|
+
if (input.length !== DID_PLC_LENGTH)
|
|
14
|
+
return false;
|
|
15
|
+
if (!input.startsWith(DID_PLC_PREFIX))
|
|
18
16
|
return false;
|
|
17
|
+
for (let i = DID_PLC_PREFIX_LENGTH; i < DID_PLC_LENGTH; i++) {
|
|
18
|
+
if (!isBase32Char(input.charCodeAt(i)))
|
|
19
|
+
return false;
|
|
19
20
|
}
|
|
21
|
+
return true;
|
|
20
22
|
}
|
|
21
23
|
exports.isDidPlc = isDidPlc;
|
|
22
24
|
function asDidPlc(input) {
|
|
23
|
-
|
|
25
|
+
assertDidPlc(input);
|
|
24
26
|
return input;
|
|
25
27
|
}
|
|
26
28
|
exports.asDidPlc = asDidPlc;
|
|
27
|
-
function
|
|
29
|
+
function assertDidPlc(input) {
|
|
28
30
|
if (typeof input !== 'string') {
|
|
29
31
|
throw new did_error_js_1.InvalidDidError(typeof input, `DID must be a string`);
|
|
30
32
|
}
|
|
@@ -34,14 +36,14 @@ function checkDidPlc(input) {
|
|
|
34
36
|
if (!input.startsWith(DID_PLC_PREFIX)) {
|
|
35
37
|
throw new did_error_js_1.InvalidDidError(input, `Invalid did:plc prefix`);
|
|
36
38
|
}
|
|
37
|
-
|
|
39
|
+
// The following check is not necessary, as the check below is more strict:
|
|
40
|
+
// assertDidMsid(input, DID_PLC_PREFIX.length)
|
|
38
41
|
for (let i = DID_PLC_PREFIX_LENGTH; i < DID_PLC_LENGTH; i++) {
|
|
39
|
-
|
|
40
|
-
// Base32 encoding ([a-z2-7])
|
|
41
|
-
if ((c < 0x61 || c > 0x7a) && (c < 0x32 || c > 0x37)) {
|
|
42
|
+
if (!isBase32Char(input.charCodeAt(i))) {
|
|
42
43
|
throw new did_error_js_1.InvalidDidError(input, `Invalid character at position ${i}`);
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
46
|
}
|
|
46
|
-
exports.
|
|
47
|
+
exports.assertDidPlc = assertDidPlc;
|
|
48
|
+
const isBase32Char = (c) => (c >= 0x61 && c <= 0x7a) || (c >= 0x32 && c <= 0x37); // [a-z2-7]
|
|
47
49
|
//# sourceMappingURL=plc.js.map
|
package/dist/methods/plc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plc.js","sourceRoot":"","sources":["../../src/methods/plc.ts"],"names":[],"mappings":";;;AAAA,kDAAiD;AAGjD,MAAM,cAAc,GAAG,UAAU,CAAA;AAIxB,wCAAc;AAHvB,MAAM,qBAAqB,GAAG,cAAc,CAAC,MAAM,CAAA;AACnD,MAAM,cAAc,GAAG,EAAE,CAAA;AAIzB,SAAgB,QAAQ,CAAC,KAAc;IACrC,
|
|
1
|
+
{"version":3,"file":"plc.js","sourceRoot":"","sources":["../../src/methods/plc.ts"],"names":[],"mappings":";;;AAAA,kDAAiD;AAGjD,MAAM,cAAc,GAAG,UAAU,CAAA;AAIxB,wCAAc;AAHvB,MAAM,qBAAqB,GAAG,cAAc,CAAC,MAAM,CAAA;AACnD,MAAM,cAAc,GAAG,EAAE,CAAA;AAIzB,SAAgB,QAAQ,CAAC,KAAc;IACrC,8DAA8D;IAC9D,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAA;IAC3C,IAAI,KAAK,CAAC,MAAM,KAAK,cAAc;QAAE,OAAO,KAAK,CAAA;IACjD,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,cAAc,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AAC,IAAI,IAAI,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,IAAI,CAAC,CAAA,CAAC,WAAW"}
|
package/dist/methods/web.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare const DID_WEB_PREFIX = "did:web:";
|
|
|
5
5
|
*/
|
|
6
6
|
export declare function isDidWeb(input: unknown): input is Did<'web'>;
|
|
7
7
|
export declare function asDidWeb(input: unknown): Did<'web'>;
|
|
8
|
-
export declare function
|
|
8
|
+
export declare function assertDidWeb(input: unknown): asserts input is Did<'web'>;
|
|
9
9
|
export declare function didWebToUrl(did: string): URL;
|
|
10
10
|
export declare function urlToDidWeb(url: URL): Did<'web'>;
|
|
11
11
|
//# sourceMappingURL=web.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../../src/methods/web.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,
|
|
1
|
+
{"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../../src/methods/web.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAiB,MAAM,WAAW,CAAA;AAE9C,eAAO,MAAM,cAAc,aAAkC,CAAA;AAE7D;;GAEG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,GAAG,CAAC,KAAK,CAAC,CAU5D;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,GAAG,CAAC,KAAK,CAAC,CAGnD;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,KAAK,IAAI,GAAG,CAAC,KAAK,CAAC,CAMxE;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAuB5C;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,CAOhD"}
|
package/dist/methods/web.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.urlToDidWeb = exports.didWebToUrl = exports.
|
|
3
|
+
exports.urlToDidWeb = exports.didWebToUrl = exports.assertDidWeb = exports.asDidWeb = exports.isDidWeb = exports.DID_WEB_PREFIX = void 0;
|
|
4
4
|
const did_error_js_1 = require("../did-error.js");
|
|
5
5
|
const did_js_1 = require("../did.js");
|
|
6
6
|
exports.DID_WEB_PREFIX = `did:web:`;
|
|
@@ -12,7 +12,7 @@ function isDidWeb(input) {
|
|
|
12
12
|
if (typeof input !== 'string')
|
|
13
13
|
return false;
|
|
14
14
|
try {
|
|
15
|
-
|
|
15
|
+
assertDidWeb(input);
|
|
16
16
|
return true;
|
|
17
17
|
}
|
|
18
18
|
catch {
|
|
@@ -21,17 +21,17 @@ function isDidWeb(input) {
|
|
|
21
21
|
}
|
|
22
22
|
exports.isDidWeb = isDidWeb;
|
|
23
23
|
function asDidWeb(input) {
|
|
24
|
-
|
|
24
|
+
assertDidWeb(input);
|
|
25
25
|
return input;
|
|
26
26
|
}
|
|
27
27
|
exports.asDidWeb = asDidWeb;
|
|
28
|
-
function
|
|
28
|
+
function assertDidWeb(input) {
|
|
29
29
|
if (typeof input !== 'string') {
|
|
30
30
|
throw new did_error_js_1.InvalidDidError(typeof input, `DID must be a string`);
|
|
31
31
|
}
|
|
32
32
|
void didWebToUrl(input);
|
|
33
33
|
}
|
|
34
|
-
exports.
|
|
34
|
+
exports.assertDidWeb = assertDidWeb;
|
|
35
35
|
function didWebToUrl(did) {
|
|
36
36
|
if (!did.startsWith(exports.DID_WEB_PREFIX)) {
|
|
37
37
|
throw new did_error_js_1.InvalidDidError(did, `did:web must start with ${exports.DID_WEB_PREFIX}`);
|
|
@@ -40,11 +40,15 @@ function didWebToUrl(did) {
|
|
|
40
40
|
throw new did_error_js_1.InvalidDidError(did, 'did:web MSID must not start with a colon');
|
|
41
41
|
}
|
|
42
42
|
// Make sure every char is valid (per DID spec)
|
|
43
|
-
(0, did_js_1.
|
|
43
|
+
(0, did_js_1.assertDidMsid)(did, exports.DID_WEB_PREFIX.length);
|
|
44
44
|
try {
|
|
45
45
|
const msid = did.slice(exports.DID_WEB_PREFIX.length);
|
|
46
46
|
const parts = msid.split(':').map(decodeURIComponent);
|
|
47
|
-
|
|
47
|
+
const url = new URL(`https://${parts.join('/')}`);
|
|
48
|
+
if (url.hostname === 'localhost') {
|
|
49
|
+
url.protocol = 'http:';
|
|
50
|
+
}
|
|
51
|
+
return url;
|
|
48
52
|
}
|
|
49
53
|
catch (cause) {
|
|
50
54
|
throw new did_error_js_1.InvalidDidError(did, 'Invalid Web DID', cause);
|
package/dist/methods/web.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/methods/web.ts"],"names":[],"mappings":";;;AAAA,kDAAiD;AACjD,
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/methods/web.ts"],"names":[],"mappings":";;;AAAA,kDAAiD;AACjD,sCAA8C;AAEjC,QAAA,cAAc,GAAG,UAA+B,CAAA;AAE7D;;GAEG;AACH,SAAgB,QAAQ,CAAC,KAAc;IACrC,wCAAwC;IACxC,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAA;IAE3C,IAAI,CAAC;QACH,YAAY,CAAC,KAAK,CAAC,CAAA;QACnB,OAAO,IAAI,CAAA;IACb,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC;AAVD,4BAUC;AAED,SAAgB,QAAQ,CAAC,KAAc;IACrC,YAAY,CAAC,KAAK,CAAC,CAAA;IACnB,OAAO,KAAK,CAAA;AACd,CAAC;AAHD,4BAGC;AAED,SAAgB,YAAY,CAAC,KAAc;IACzC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,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AAG,CAAC,QAAQ,KAAK,GAAG;QAClB,CAAC,CAAC,EAAE;QACJ,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAExE,OAAO,WAAW,kBAAkB,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAA;AAC3E,CAAC;AAPD,kCAOC"}
|
package/package.json
CHANGED
package/src/atproto.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { InvalidDidError } from './did-error.js'
|
|
2
2
|
import { Did } from './did.js'
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
assertDidPlc,
|
|
5
|
+
assertDidWeb,
|
|
6
6
|
DID_PLC_PREFIX,
|
|
7
7
|
DID_WEB_PREFIX,
|
|
8
8
|
isDidPlc,
|
|
9
|
-
isDidWeb,
|
|
10
9
|
} from './methods.js'
|
|
11
10
|
|
|
12
11
|
// This file contains atproto-specific DID validation utilities.
|
|
@@ -30,17 +29,17 @@ export function isAtprotoDid(input: unknown): input is AtprotoDid {
|
|
|
30
29
|
}
|
|
31
30
|
|
|
32
31
|
export function asAtprotoDid(input: unknown): AtprotoDid {
|
|
33
|
-
|
|
32
|
+
assertAtprotoDid(input)
|
|
34
33
|
return input
|
|
35
34
|
}
|
|
36
35
|
|
|
37
|
-
export function
|
|
36
|
+
export function assertAtprotoDid(input: unknown): asserts input is AtprotoDid {
|
|
38
37
|
if (typeof input !== 'string') {
|
|
39
38
|
throw new InvalidDidError(typeof input, `DID must be a string`)
|
|
40
39
|
} else if (input.startsWith(DID_PLC_PREFIX)) {
|
|
41
|
-
|
|
40
|
+
assertDidPlc(input)
|
|
42
41
|
} else if (input.startsWith(DID_WEB_PREFIX)) {
|
|
43
|
-
|
|
42
|
+
assertAtprotoDidWeb(input)
|
|
44
43
|
} else {
|
|
45
44
|
throw new InvalidDidError(
|
|
46
45
|
input,
|
|
@@ -49,27 +48,37 @@ export function checkAtprotoDid(input: unknown): asserts input is AtprotoDid {
|
|
|
49
48
|
}
|
|
50
49
|
}
|
|
51
50
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
// Optimization: make cheap checks first
|
|
57
|
-
if (typeof input !== 'string') {
|
|
58
|
-
return false
|
|
59
|
-
}
|
|
51
|
+
export function assertAtprotoDidWeb(
|
|
52
|
+
input: unknown,
|
|
53
|
+
): asserts input is Did<'web'> {
|
|
54
|
+
assertDidWeb(input)
|
|
60
55
|
|
|
61
|
-
// Path are not allowed
|
|
62
56
|
if (input.includes(':', DID_WEB_PREFIX.length)) {
|
|
63
|
-
|
|
57
|
+
throw new InvalidDidError(
|
|
58
|
+
input,
|
|
59
|
+
`Atproto does not allow path components in Web DIDs`,
|
|
60
|
+
)
|
|
64
61
|
}
|
|
65
62
|
|
|
66
|
-
// Port numbers are not allowed, except for localhost
|
|
67
63
|
if (
|
|
68
64
|
input.includes('%3A', DID_WEB_PREFIX.length) &&
|
|
69
65
|
!input.startsWith('did:web:localhost%3A')
|
|
70
66
|
) {
|
|
71
|
-
|
|
67
|
+
throw new InvalidDidError(
|
|
68
|
+
input,
|
|
69
|
+
`Atproto does not allow port numbers in Web DIDs, except for localhost`,
|
|
70
|
+
)
|
|
72
71
|
}
|
|
72
|
+
}
|
|
73
73
|
|
|
74
|
-
|
|
74
|
+
/**
|
|
75
|
+
* @see {@link https://atproto.com/specs/did#blessed-did-methods}
|
|
76
|
+
*/
|
|
77
|
+
export function isAtprotoDidWeb(input: unknown): input is Did<'web'> {
|
|
78
|
+
try {
|
|
79
|
+
assertAtprotoDidWeb(input)
|
|
80
|
+
return true
|
|
81
|
+
} catch {
|
|
82
|
+
return false
|
|
83
|
+
}
|
|
75
84
|
}
|
package/src/did-document.ts
CHANGED
|
@@ -117,35 +117,27 @@ export type DidDocument<Method extends string = string> = z.infer<
|
|
|
117
117
|
|
|
118
118
|
// @TODO: add other refinements ?
|
|
119
119
|
export const didDocumentValidator = didDocumentSchema
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
120
|
+
// Ensure that every service id is unique
|
|
121
|
+
.superRefine(({ id: did, service }, ctx) => {
|
|
122
|
+
if (service) {
|
|
123
|
+
const visited = new Set()
|
|
124
|
+
|
|
125
|
+
for (let i = 0; i < service.length; i++) {
|
|
126
|
+
const current = service[i]
|
|
127
|
+
|
|
128
|
+
const serviceId = current.id.startsWith('#')
|
|
129
|
+
? `${did}${current.id}`
|
|
130
|
+
: current.id
|
|
131
|
+
|
|
132
|
+
if (!visited.has(serviceId)) {
|
|
133
|
+
visited.add(serviceId)
|
|
134
|
+
} else {
|
|
124
135
|
ctx.addIssue({
|
|
125
136
|
code: z.ZodIssueCode.custom,
|
|
126
|
-
message: `
|
|
137
|
+
message: `Duplicate service id (${current.id}) found in the document`,
|
|
127
138
|
path: ['service', i, 'id'],
|
|
128
139
|
})
|
|
129
140
|
}
|
|
130
141
|
}
|
|
131
142
|
}
|
|
132
143
|
})
|
|
133
|
-
.superRefine((data, ctx) => {
|
|
134
|
-
if (data.service) {
|
|
135
|
-
const normalizedIds = data.service.map((s) =>
|
|
136
|
-
s.id?.startsWith('#') ? `${data.id}${s.id}` : s.id,
|
|
137
|
-
)
|
|
138
|
-
|
|
139
|
-
for (let i = 0; i < normalizedIds.length; i++) {
|
|
140
|
-
for (let j = i + 1; j < normalizedIds.length; j++) {
|
|
141
|
-
if (normalizedIds[i] === normalizedIds[j]) {
|
|
142
|
-
ctx.addIssue({
|
|
143
|
-
code: z.ZodIssueCode.custom,
|
|
144
|
-
message: `Duplicate service id (${normalizedIds[j]}) found in the document`,
|
|
145
|
-
path: ['service', j, 'id'],
|
|
146
|
-
})
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
})
|
package/src/did.ts
CHANGED
|
@@ -83,7 +83,7 @@ type AsDidMethodInternal<
|
|
|
83
83
|
* Check if the input is a valid DID method name, at the position between
|
|
84
84
|
* `start` (inclusive) and `end` (exclusive).
|
|
85
85
|
*/
|
|
86
|
-
export function
|
|
86
|
+
export function assertDidMethod(
|
|
87
87
|
input: string,
|
|
88
88
|
start = 0,
|
|
89
89
|
end = input.length,
|
|
@@ -130,7 +130,7 @@ export function extractDidMethod<D extends Did>(did: D) {
|
|
|
130
130
|
* Check if the input is a valid DID method-specific identifier, at the position
|
|
131
131
|
* between `start` (inclusive) and `end` (exclusive).
|
|
132
132
|
*/
|
|
133
|
-
export function
|
|
133
|
+
export function assertDidMsid(
|
|
134
134
|
input: string,
|
|
135
135
|
start = 0,
|
|
136
136
|
end = input.length,
|
|
@@ -207,7 +207,7 @@ export function checkDidMsid(
|
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
209
|
|
|
210
|
-
export function
|
|
210
|
+
export function assertDid(input: unknown): asserts input is Did {
|
|
211
211
|
if (typeof input !== 'string') {
|
|
212
212
|
throw new InvalidDidError(typeof input, `DID must be a string`)
|
|
213
213
|
}
|
|
@@ -226,13 +226,13 @@ export function checkDid(input: unknown): asserts input is Did {
|
|
|
226
226
|
throw new InvalidDidError(input, `Missing colon after method name`)
|
|
227
227
|
}
|
|
228
228
|
|
|
229
|
-
|
|
230
|
-
|
|
229
|
+
assertDidMethod(input, DID_PREFIX_LENGTH, idSep)
|
|
230
|
+
assertDidMsid(input, idSep + 1, length)
|
|
231
231
|
}
|
|
232
232
|
|
|
233
233
|
export function isDid(input: unknown): input is Did {
|
|
234
234
|
try {
|
|
235
|
-
|
|
235
|
+
assertDid(input)
|
|
236
236
|
return true
|
|
237
237
|
} catch (err) {
|
|
238
238
|
if (err instanceof DidError) {
|
|
@@ -245,7 +245,7 @@ export function isDid(input: unknown): input is Did {
|
|
|
245
245
|
}
|
|
246
246
|
|
|
247
247
|
export function asDid(input: unknown): Did {
|
|
248
|
-
|
|
248
|
+
assertDid(input)
|
|
249
249
|
return input
|
|
250
250
|
}
|
|
251
251
|
|
|
@@ -253,7 +253,7 @@ export const didSchema = z
|
|
|
253
253
|
.string()
|
|
254
254
|
.superRefine((value: string, ctx: z.RefinementCtx): value is Did => {
|
|
255
255
|
try {
|
|
256
|
-
|
|
256
|
+
assertDid(value)
|
|
257
257
|
return true
|
|
258
258
|
} catch (err) {
|
|
259
259
|
ctx.addIssue({
|
package/src/methods/plc.ts
CHANGED
|
@@ -8,23 +8,22 @@ const DID_PLC_LENGTH = 32
|
|
|
8
8
|
export { DID_PLC_PREFIX }
|
|
9
9
|
|
|
10
10
|
export function isDidPlc(input: unknown): input is Did<'plc'> {
|
|
11
|
-
// Optimization:
|
|
11
|
+
// Optimization: equivalent to try/catch around "assertDidPlc"
|
|
12
12
|
if (typeof input !== 'string') return false
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return
|
|
17
|
-
} catch {
|
|
18
|
-
return false
|
|
13
|
+
if (input.length !== DID_PLC_LENGTH) return false
|
|
14
|
+
if (!input.startsWith(DID_PLC_PREFIX)) return false
|
|
15
|
+
for (let i = DID_PLC_PREFIX_LENGTH; i < DID_PLC_LENGTH; i++) {
|
|
16
|
+
if (!isBase32Char(input.charCodeAt(i))) return false
|
|
19
17
|
}
|
|
18
|
+
return true
|
|
20
19
|
}
|
|
21
20
|
|
|
22
21
|
export function asDidPlc(input: unknown): Did<'plc'> {
|
|
23
|
-
|
|
22
|
+
assertDidPlc(input)
|
|
24
23
|
return input
|
|
25
24
|
}
|
|
26
25
|
|
|
27
|
-
export function
|
|
26
|
+
export function assertDidPlc(input: unknown): asserts input is Did<'plc'> {
|
|
28
27
|
if (typeof input !== 'string') {
|
|
29
28
|
throw new InvalidDidError(typeof input, `DID must be a string`)
|
|
30
29
|
}
|
|
@@ -40,12 +39,16 @@ export function checkDidPlc(input: unknown): asserts input is Did<'plc'> {
|
|
|
40
39
|
throw new InvalidDidError(input, `Invalid did:plc prefix`)
|
|
41
40
|
}
|
|
42
41
|
|
|
43
|
-
|
|
42
|
+
// The following check is not necessary, as the check below is more strict:
|
|
43
|
+
|
|
44
|
+
// assertDidMsid(input, DID_PLC_PREFIX.length)
|
|
45
|
+
|
|
44
46
|
for (let i = DID_PLC_PREFIX_LENGTH; i < DID_PLC_LENGTH; i++) {
|
|
45
|
-
|
|
46
|
-
// Base32 encoding ([a-z2-7])
|
|
47
|
-
if ((c < 0x61 || c > 0x7a) && (c < 0x32 || c > 0x37)) {
|
|
47
|
+
if (!isBase32Char(input.charCodeAt(i))) {
|
|
48
48
|
throw new InvalidDidError(input, `Invalid character at position ${i}`)
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
+
|
|
53
|
+
const isBase32Char = (c: number): boolean =>
|
|
54
|
+
(c >= 0x61 && c <= 0x7a) || (c >= 0x32 && c <= 0x37) // [a-z2-7]
|
package/src/methods/web.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { InvalidDidError } from '../did-error.js'
|
|
2
|
-
import { Did,
|
|
2
|
+
import { Did, assertDidMsid } from '../did.js'
|
|
3
3
|
|
|
4
4
|
export const DID_WEB_PREFIX = `did:web:` satisfies Did<'web'>
|
|
5
5
|
|
|
@@ -11,7 +11,7 @@ export function isDidWeb(input: unknown): input is Did<'web'> {
|
|
|
11
11
|
if (typeof input !== 'string') return false
|
|
12
12
|
|
|
13
13
|
try {
|
|
14
|
-
|
|
14
|
+
assertDidWeb(input)
|
|
15
15
|
return true
|
|
16
16
|
} catch {
|
|
17
17
|
return false
|
|
@@ -19,11 +19,11 @@ export function isDidWeb(input: unknown): input is Did<'web'> {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export function asDidWeb(input: unknown): Did<'web'> {
|
|
22
|
-
|
|
22
|
+
assertDidWeb(input)
|
|
23
23
|
return input
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
export function
|
|
26
|
+
export function assertDidWeb(input: unknown): asserts input is Did<'web'> {
|
|
27
27
|
if (typeof input !== 'string') {
|
|
28
28
|
throw new InvalidDidError(typeof input, `DID must be a string`)
|
|
29
29
|
}
|
|
@@ -41,12 +41,16 @@ export function didWebToUrl(did: string): URL {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
// Make sure every char is valid (per DID spec)
|
|
44
|
-
|
|
44
|
+
assertDidMsid(did, DID_WEB_PREFIX.length)
|
|
45
45
|
|
|
46
46
|
try {
|
|
47
47
|
const msid = did.slice(DID_WEB_PREFIX.length)
|
|
48
48
|
const parts = msid.split(':').map(decodeURIComponent)
|
|
49
|
-
|
|
49
|
+
const url = new URL(`https://${parts.join('/')}`)
|
|
50
|
+
if (url.hostname === 'localhost') {
|
|
51
|
+
url.protocol = 'http:'
|
|
52
|
+
}
|
|
53
|
+
return url
|
|
50
54
|
} catch (cause) {
|
|
51
55
|
throw new InvalidDidError(did, 'Invalid Web DID', cause)
|
|
52
56
|
}
|