@atcute/identity 1.1.4 → 2.0.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/README.md +6 -5
- package/dist/did.d.ts +4 -3
- package/dist/did.d.ts.map +1 -1
- package/dist/did.js +1 -1
- package/dist/did.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/methods/key.d.ts +2 -1
- package/dist/methods/key.d.ts.map +1 -1
- package/dist/methods/key.js +1 -1
- package/dist/methods/key.js.map +1 -1
- package/dist/methods/plc.d.ts +2 -3
- package/dist/methods/plc.d.ts.map +1 -1
- package/dist/methods/plc.js +2 -3
- package/dist/methods/plc.js.map +1 -1
- package/dist/methods/web.d.ts +5 -8
- package/dist/methods/web.d.ts.map +1 -1
- package/dist/methods/web.js +4 -6
- package/dist/methods/web.js.map +1 -1
- package/dist/typedefs.d.ts +185 -13
- package/dist/typedefs.d.ts.map +1 -1
- package/dist/typedefs.js +49 -108
- package/dist/typedefs.js.map +1 -1
- package/dist/utils.d.ts +4 -3
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +0 -1
- package/dist/utils.js.map +1 -1
- package/lib/did.ts +3 -3
- package/lib/index.ts +1 -1
- package/lib/methods/key.ts +2 -2
- package/lib/methods/plc.ts +3 -4
- package/lib/methods/web.ts +6 -8
- package/lib/typedefs.ts +82 -131
- package/lib/utils.ts +1 -1
- package/package.json +11 -7
- package/dist/types.d.ts +0 -23
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- package/lib/types.ts +0 -25
package/README.md
CHANGED
|
@@ -154,14 +154,15 @@ use the validation schemas to check if a DID document is well-formed:
|
|
|
154
154
|
|
|
155
155
|
```ts
|
|
156
156
|
import { defs } from '@atcute/identity';
|
|
157
|
+
import * as v from 'valibot';
|
|
157
158
|
|
|
158
|
-
const result = defs.didDocument
|
|
159
|
-
if (result.
|
|
160
|
-
// result.
|
|
161
|
-
console.log(result.
|
|
159
|
+
const result = v.safeParse(defs.didDocument, unknownData);
|
|
160
|
+
if (result.success) {
|
|
161
|
+
// result.output is a validated DidDocument
|
|
162
|
+
console.log(result.output.id);
|
|
162
163
|
} else {
|
|
163
164
|
// validation failed
|
|
164
|
-
console.error('invalid DID document');
|
|
165
|
+
console.error('invalid DID document', result.issues);
|
|
165
166
|
}
|
|
166
167
|
```
|
|
167
168
|
|
package/dist/did.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import type { AtprotoAudience, AtprotoDid, Did } from '@atcute/lexicons/syntax';
|
|
1
2
|
/**
|
|
2
3
|
* checks if it's a DID identifier that is supported by atproto
|
|
3
4
|
*/
|
|
4
|
-
export declare const isAtprotoDid: (input:
|
|
5
|
-
export declare const isAtprotoAudience: (input:
|
|
5
|
+
export declare const isAtprotoDid: (input: unknown) => input is AtprotoDid;
|
|
6
|
+
export declare const isAtprotoAudience: (input: unknown) => input is AtprotoAudience;
|
|
6
7
|
/**
|
|
7
8
|
* returns the DID's method
|
|
8
9
|
*/
|
|
9
|
-
export declare const extractDidMethod: <M extends string>(did:
|
|
10
|
+
export declare const extractDidMethod: <M extends string>(did: Did<M>) => M;
|
|
10
11
|
//# sourceMappingURL=did.d.ts.map
|
package/dist/did.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"did.d.ts","sourceRoot":"","sources":["../lib/did.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"did.d.ts","sourceRoot":"","sources":["../lib/did.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,yBAAyB,CAAC;AAOhF;;GAEG;AACH,eAAO,MAAM,YAAY,UAAW,OAAO,KAAG,KAAK,IAAI,UAEtD,CAAC;AAEF,eAAO,MAAM,iBAAiB,UAAW,OAAO,KAAG,KAAK,IAAI,eAY3D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,MAAM,OAAO,GAAG,CAAC,CAAC,CAAC,KAAG,CAIhE,CAAC"}
|
package/dist/did.js
CHANGED
|
@@ -9,7 +9,7 @@ export const isAtprotoDid = (input) => {
|
|
|
9
9
|
};
|
|
10
10
|
export const isAtprotoAudience = (input) => {
|
|
11
11
|
// 'did:web:a.co#f'
|
|
12
|
-
if (input.length < 14) {
|
|
12
|
+
if (typeof input !== 'string' || input.length < 14) {
|
|
13
13
|
return false;
|
|
14
14
|
}
|
|
15
15
|
const isep = input.indexOf('#', 12);
|
package/dist/did.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"did.js","sourceRoot":"","sources":["../lib/did.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEnD,MAAM,WAAW,GAAG,wDAAwD,CAAC;AAE7E;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"did.js","sourceRoot":"","sources":["../lib/did.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEnD,MAAM,WAAW,GAAG,wDAAwD,CAAC;AAE7E;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAAc,EAAuB,EAAE;IACnE,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,eAAe,CAAC,KAAK,CAAC,CAAC;AAClD,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,KAAc,EAA4B,EAAE;IAC7E,mBAAmB;IACnB,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,GAAG,EAAE,EAAE,CAAC;QACpD,OAAO,KAAK,CAAC;IACd,CAAC;IAED,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IACpC,IAAI,IAAI,KAAK,CAAC,CAAC,EAAE,CAAC;QACjB,OAAO,KAAK,CAAC;IACd,CAAC;IAED,OAAO,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,IAAI,YAAY,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;AACtF,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAmB,GAAW,EAAK,EAAE;IACpE,MAAM,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IACjC,MAAM,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;IAClC,OAAO,MAAW,CAAC;AACpB,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,eAAe,CAAC;AACtC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,eAAe,CAAC;AACtC,YAAY,EAAE,WAAW,EAAE,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAE9E,cAAc,YAAY,CAAC;AAE3B,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,eAAe,CAAC;AAGtC,cAAc,YAAY,CAAC;AAE3B,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC"}
|
package/dist/methods/key.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { Did } from '@atcute/lexicons';
|
|
1
2
|
/**
|
|
2
3
|
* checks if input is a did:key identifier
|
|
3
4
|
*/
|
|
4
|
-
export declare const isKeyDid: (input:
|
|
5
|
+
export declare const isKeyDid: (input: unknown) => input is Did<'key'>;
|
|
5
6
|
//# sourceMappingURL=key.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"key.d.ts","sourceRoot":"","sources":["../../lib/methods/key.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"key.d.ts","sourceRoot":"","sources":["../../lib/methods/key.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAI5C;;GAEG;AACH,eAAO,MAAM,QAAQ,UAAW,OAAO,KAAG,KAAK,IAAI,GAAG,CAAC,KAAK,CAE3D,CAAC"}
|
package/dist/methods/key.js
CHANGED
|
@@ -3,6 +3,6 @@ const KEY_DID_RE = /^did:key:z[a-km-zA-HJ-NP-Z1-9]+$/;
|
|
|
3
3
|
* checks if input is a did:key identifier
|
|
4
4
|
*/
|
|
5
5
|
export const isKeyDid = (input) => {
|
|
6
|
-
return input.length >= 10 && KEY_DID_RE.test(input);
|
|
6
|
+
return typeof input === 'string' && input.length >= 10 && KEY_DID_RE.test(input);
|
|
7
7
|
};
|
|
8
8
|
//# sourceMappingURL=key.js.map
|
package/dist/methods/key.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"key.js","sourceRoot":"","sources":["../../lib/methods/key.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,GAAG,kCAAkC,CAAC;AAEtD;;GAEG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"key.js","sourceRoot":"","sources":["../../lib/methods/key.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,GAAG,kCAAkC,CAAC;AAEtD;;GAEG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAuB,EAAE;IAC/D,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,IAAI,EAAE,IAAI,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAClF,CAAC,CAAC"}
|
package/dist/methods/plc.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const PLC_DID_RE: RegExp;
|
|
1
|
+
import type { Did } from '@atcute/lexicons/syntax';
|
|
3
2
|
/**
|
|
4
3
|
* checks if input is a did:plc identifier
|
|
5
4
|
*/
|
|
6
|
-
export declare const isPlcDid: (input:
|
|
5
|
+
export declare const isPlcDid: (input: unknown) => input is Did<'plc'>;
|
|
7
6
|
//# sourceMappingURL=plc.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plc.d.ts","sourceRoot":"","sources":["../../lib/methods/plc.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"plc.d.ts","sourceRoot":"","sources":["../../lib/methods/plc.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,yBAAyB,CAAC;AAInD;;GAEG;AACH,eAAO,MAAM,QAAQ,UAAW,OAAO,KAAG,KAAK,IAAI,GAAG,CAAC,KAAK,CAE3D,CAAC"}
|
package/dist/methods/plc.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
export const PLC_DID_RE = /^did:plc:([a-z2-7]{24})$/;
|
|
1
|
+
const PLC_DID_RE = /^did:plc:([a-z2-7]{24})$/;
|
|
3
2
|
/**
|
|
4
3
|
* checks if input is a did:plc identifier
|
|
5
4
|
*/
|
|
6
5
|
export const isPlcDid = (input) => {
|
|
7
|
-
return input.length === 32 && PLC_DID_RE.test(input);
|
|
6
|
+
return typeof input === 'string' && input.length === 32 && PLC_DID_RE.test(input);
|
|
8
7
|
};
|
|
9
8
|
//# sourceMappingURL=plc.js.map
|
package/dist/methods/plc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plc.js","sourceRoot":"","sources":["../../lib/methods/plc.ts"],"names":[],"mappings":"AAEA,
|
|
1
|
+
{"version":3,"file":"plc.js","sourceRoot":"","sources":["../../lib/methods/plc.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,GAAG,0BAA0B,CAAC;AAE9C;;GAEG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAuB,EAAE;IAC/D,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,KAAK,EAAE,IAAI,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACnF,CAAC,CAAC"}
|
package/dist/methods/web.d.ts
CHANGED
|
@@ -1,23 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const WEB_DID_RE: RegExp;
|
|
3
|
-
/** @deprecated use `isAtprotoWebDid` instead */
|
|
4
|
-
export declare const ATPROTO_WEB_DID_RE: RegExp;
|
|
1
|
+
import type { Did } from '@atcute/lexicons/syntax';
|
|
5
2
|
/**
|
|
6
3
|
* checks if input is a did:web identifier, note that you should probably use
|
|
7
4
|
* `isAtprotoWebDid` for atproto-related cases as atproto only supports a subset
|
|
8
5
|
* of the did:web specification (namely, no custom paths)
|
|
9
6
|
*/
|
|
10
|
-
export declare const isWebDid: (input:
|
|
7
|
+
export declare const isWebDid: (input: unknown) => input is Did<'web'>;
|
|
11
8
|
/**
|
|
12
9
|
* checks if input is a did:web identifier that is supported by atproto
|
|
13
10
|
*/
|
|
14
|
-
export declare const isAtprotoWebDid: (input:
|
|
11
|
+
export declare const isAtprotoWebDid: (input: unknown) => input is Did<'web'>;
|
|
15
12
|
/**
|
|
16
13
|
* normalize a did:web identifier
|
|
17
14
|
*/
|
|
18
|
-
export declare const normalizeWebDid: (did:
|
|
15
|
+
export declare const normalizeWebDid: (did: Did<'web'>) => Did<'web'>;
|
|
19
16
|
/**
|
|
20
17
|
* converts did:web identifier into the DID document's URL
|
|
21
18
|
*/
|
|
22
|
-
export declare const webDidToDocumentUrl: (did:
|
|
19
|
+
export declare const webDidToDocumentUrl: (did: Did<'web'>) => URL;
|
|
23
20
|
//# sourceMappingURL=web.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../../lib/methods/web.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../../lib/methods/web.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,yBAAyB,CAAC;AAQnD;;;;GAIG;AACH,eAAO,MAAM,QAAQ,UAAW,OAAO,KAAG,KAAK,IAAI,GAAG,CAAC,KAAK,CAE3D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,eAAe,UAAW,OAAO,KAAG,KAAK,IAAI,GAAG,CAAC,KAAK,CAElE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,eAAe,QAAS,GAAG,CAAC,KAAK,CAAC,KAAG,GAAG,CAAC,KAAK,CAS1D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mBAAmB,QAAS,GAAG,CAAC,KAAK,CAAC,KAAG,GAgBrD,CAAC"}
|
package/dist/methods/web.js
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/** @deprecated use `isAtprotoWebDid` instead */
|
|
4
|
-
export const ATPROTO_WEB_DID_RE = /^did:web:([a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*(?:\.[a-zA-Z]{2,})|localhost(?:%3[aA]\d+)?)$/;
|
|
1
|
+
const WEB_DID_RE = /^did:web:([a-zA-Z0-9%-]+(?:(?:\.[a-zA-Z0-9%-]+)*(?:\.[a-zA-Z]{2,}))?)?((?::[a-zA-Z0-9\-%.]+)+)?$/;
|
|
2
|
+
const ATPROTO_WEB_DID_RE = /^did:web:([a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*(?:\.[a-zA-Z]{2,})|localhost(?:%3[aA]\d+)?)$/;
|
|
5
3
|
/**
|
|
6
4
|
* checks if input is a did:web identifier, note that you should probably use
|
|
7
5
|
* `isAtprotoWebDid` for atproto-related cases as atproto only supports a subset
|
|
8
6
|
* of the did:web specification (namely, no custom paths)
|
|
9
7
|
*/
|
|
10
8
|
export const isWebDid = (input) => {
|
|
11
|
-
return input.length >= 9 && WEB_DID_RE.test(input);
|
|
9
|
+
return typeof input === 'string' && input.length >= 9 && WEB_DID_RE.test(input);
|
|
12
10
|
};
|
|
13
11
|
/**
|
|
14
12
|
* checks if input is a did:web identifier that is supported by atproto
|
|
15
13
|
*/
|
|
16
14
|
export const isAtprotoWebDid = (input) => {
|
|
17
|
-
return input.length >= 12 && ATPROTO_WEB_DID_RE.test(input);
|
|
15
|
+
return typeof input === 'string' && input.length >= 12 && ATPROTO_WEB_DID_RE.test(input);
|
|
18
16
|
};
|
|
19
17
|
/**
|
|
20
18
|
* normalize a did:web identifier
|
package/dist/methods/web.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../lib/methods/web.ts"],"names":[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AG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;IAEzE,IAAI,QAAQ,GAAG,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACrC,IAAI,QAAQ,KAAK,GAAG,EAAE,CAAC;QACtB,QAAQ,GAAG,uBAAuB,CAAC;IACpC,CAAC;SAAM,CAAC;QACP,QAAQ,IAAI,WAAW,CAAC;IACzB,CAAC;IAED,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,WAAW,IAAI,GAAG,QAAQ,EAAE,CAAC,CAAC;IAClD,IAAI,GAAG,CAAC,QAAQ,KAAK,WAAW,EAAE,CAAC;QAClC,GAAG,CAAC,QAAQ,GAAG,OAAO,CAAC;IACxB,CAAC;IAED,OAAO,GAAG,CAAC;AACZ,CAAC,CAAC"}
|
package/dist/typedefs.d.ts
CHANGED
|
@@ -1,14 +1,186 @@
|
|
|
1
|
-
import * as v from '
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export declare const
|
|
5
|
-
|
|
6
|
-
export declare const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import * as v from 'valibot';
|
|
2
|
+
export declare const rfc3968UriSchema: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "must be a url">]>;
|
|
3
|
+
export declare const didRelativeUri: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "must be a did relative uri">]>;
|
|
4
|
+
export declare const multibaseString: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "must be a base58 multibase">]>;
|
|
5
|
+
export declare const didString: v.CustomSchema<`did:${string}:${string}`, v.ErrorMessage<v.CustomIssue> | undefined>;
|
|
6
|
+
export declare const verificationMethod: v.SchemaWithPipe<readonly [v.LooseObjectSchema<{
|
|
7
|
+
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "must be a did relative uri">]>;
|
|
8
|
+
readonly type: v.StringSchema<undefined>;
|
|
9
|
+
readonly controller: v.CustomSchema<`did:${string}:${string}`, v.ErrorMessage<v.CustomIssue> | undefined>;
|
|
10
|
+
readonly publicKeyMultibase: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "must be a base58 multibase">]>, undefined>;
|
|
11
|
+
readonly publicKeyJwk: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.UnknownSchema, undefined>, undefined>;
|
|
12
|
+
}, undefined>, v.BaseValidation<{
|
|
13
|
+
id: string;
|
|
14
|
+
type: string;
|
|
15
|
+
controller: `did:${string}:${string}`;
|
|
16
|
+
publicKeyMultibase?: string | undefined;
|
|
17
|
+
publicKeyJwk?: {
|
|
18
|
+
[x: string]: unknown;
|
|
19
|
+
} | undefined;
|
|
20
|
+
} & {
|
|
21
|
+
[key: string]: unknown;
|
|
22
|
+
}, {
|
|
23
|
+
id: string;
|
|
24
|
+
type: string;
|
|
25
|
+
controller: `did:${string}:${string}`;
|
|
26
|
+
publicKeyMultibase?: string | undefined;
|
|
27
|
+
publicKeyJwk?: {
|
|
28
|
+
[x: string]: unknown;
|
|
29
|
+
} | undefined;
|
|
30
|
+
} & {
|
|
31
|
+
[key: string]: unknown;
|
|
32
|
+
}, v.CheckIssue<{
|
|
33
|
+
id: string;
|
|
34
|
+
type: string;
|
|
35
|
+
controller: `did:${string}:${string}`;
|
|
36
|
+
publicKeyMultibase?: string | undefined;
|
|
37
|
+
publicKeyJwk?: {
|
|
38
|
+
[x: string]: unknown;
|
|
39
|
+
} | undefined;
|
|
40
|
+
} & {
|
|
41
|
+
[key: string]: unknown;
|
|
42
|
+
}>>]>;
|
|
43
|
+
export declare const service: v.LooseObjectSchema<{
|
|
44
|
+
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "must be a did relative uri">]>;
|
|
45
|
+
readonly type: v.UnionSchema<[v.StringSchema<undefined>, v.ArraySchema<v.StringSchema<undefined>, undefined>], undefined>;
|
|
46
|
+
readonly serviceEndpoint: v.UnionSchema<[v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "must be a url">]>, v.RecordSchema<v.StringSchema<undefined>, v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "must be a url">]>, undefined>, v.ArraySchema<v.UnionSchema<[v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "must be a url">]>, v.RecordSchema<v.StringSchema<undefined>, v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "must be a url">]>, undefined>], undefined>, undefined>], undefined>;
|
|
47
|
+
}, undefined>;
|
|
48
|
+
export declare const didDocument: v.SchemaWithPipe<readonly [v.LooseObjectSchema<{
|
|
49
|
+
readonly '@context': v.OptionalSchema<v.ArraySchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "must be a url">]>, undefined>, undefined>;
|
|
50
|
+
readonly id: v.CustomSchema<`did:${string}:${string}`, v.ErrorMessage<v.CustomIssue> | undefined>;
|
|
51
|
+
readonly alsoKnownAs: v.OptionalSchema<v.SchemaWithPipe<readonly [v.ArraySchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "must be a url">]>, undefined>, v.CheckAction<string[], "duplicate aka entries">]>, undefined>;
|
|
52
|
+
readonly verificationMethod: v.OptionalSchema<v.SchemaWithPipe<readonly [v.ArraySchema<v.SchemaWithPipe<readonly [v.LooseObjectSchema<{
|
|
53
|
+
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "must be a did relative uri">]>;
|
|
54
|
+
readonly type: v.StringSchema<undefined>;
|
|
55
|
+
readonly controller: v.CustomSchema<`did:${string}:${string}`, v.ErrorMessage<v.CustomIssue> | undefined>;
|
|
56
|
+
readonly publicKeyMultibase: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "must be a base58 multibase">]>, undefined>;
|
|
57
|
+
readonly publicKeyJwk: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.UnknownSchema, undefined>, undefined>;
|
|
58
|
+
}, undefined>, v.BaseValidation<{
|
|
59
|
+
id: string;
|
|
60
|
+
type: string;
|
|
61
|
+
controller: `did:${string}:${string}`;
|
|
62
|
+
publicKeyMultibase?: string | undefined;
|
|
63
|
+
publicKeyJwk?: {
|
|
64
|
+
[x: string]: unknown;
|
|
65
|
+
} | undefined;
|
|
66
|
+
} & {
|
|
67
|
+
[key: string]: unknown;
|
|
68
|
+
}, {
|
|
69
|
+
id: string;
|
|
70
|
+
type: string;
|
|
71
|
+
controller: `did:${string}:${string}`;
|
|
72
|
+
publicKeyMultibase?: string | undefined;
|
|
73
|
+
publicKeyJwk?: {
|
|
74
|
+
[x: string]: unknown;
|
|
75
|
+
} | undefined;
|
|
76
|
+
} & {
|
|
77
|
+
[key: string]: unknown;
|
|
78
|
+
}, v.CheckIssue<{
|
|
79
|
+
id: string;
|
|
80
|
+
type: string;
|
|
81
|
+
controller: `did:${string}:${string}`;
|
|
82
|
+
publicKeyMultibase?: string | undefined;
|
|
83
|
+
publicKeyJwk?: {
|
|
84
|
+
[x: string]: unknown;
|
|
85
|
+
} | undefined;
|
|
86
|
+
} & {
|
|
87
|
+
[key: string]: unknown;
|
|
88
|
+
}>>]>, undefined>, v.CheckAction<({
|
|
89
|
+
id: string;
|
|
90
|
+
type: string;
|
|
91
|
+
controller: `did:${string}:${string}`;
|
|
92
|
+
publicKeyMultibase?: string | undefined;
|
|
93
|
+
publicKeyJwk?: {
|
|
94
|
+
[x: string]: unknown;
|
|
95
|
+
} | undefined;
|
|
96
|
+
} & {
|
|
97
|
+
[key: string]: unknown;
|
|
98
|
+
})[], "duplicate verification method ids">]>, undefined>;
|
|
99
|
+
readonly service: v.OptionalSchema<v.ArraySchema<v.LooseObjectSchema<{
|
|
100
|
+
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "must be a did relative uri">]>;
|
|
101
|
+
readonly type: v.UnionSchema<[v.StringSchema<undefined>, v.ArraySchema<v.StringSchema<undefined>, undefined>], undefined>;
|
|
102
|
+
readonly serviceEndpoint: v.UnionSchema<[v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "must be a url">]>, v.RecordSchema<v.StringSchema<undefined>, v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "must be a url">]>, undefined>, v.ArraySchema<v.UnionSchema<[v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "must be a url">]>, v.RecordSchema<v.StringSchema<undefined>, v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "must be a url">]>, undefined>], undefined>, undefined>], undefined>;
|
|
103
|
+
}, undefined>, undefined>, undefined>;
|
|
104
|
+
readonly controller: v.OptionalSchema<v.UnionSchema<[v.CustomSchema<`did:${string}:${string}`, v.ErrorMessage<v.CustomIssue> | undefined>, v.ArraySchema<v.CustomSchema<`did:${string}:${string}`, v.ErrorMessage<v.CustomIssue> | undefined>, undefined>], undefined>, undefined>;
|
|
105
|
+
readonly authentication: v.OptionalSchema<v.ArraySchema<v.UnionSchema<[v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "must be a did relative uri">]>, v.SchemaWithPipe<readonly [v.LooseObjectSchema<{
|
|
106
|
+
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "must be a did relative uri">]>;
|
|
107
|
+
readonly type: v.StringSchema<undefined>;
|
|
108
|
+
readonly controller: v.CustomSchema<`did:${string}:${string}`, v.ErrorMessage<v.CustomIssue> | undefined>;
|
|
109
|
+
readonly publicKeyMultibase: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "must be a base58 multibase">]>, undefined>;
|
|
110
|
+
readonly publicKeyJwk: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.UnknownSchema, undefined>, undefined>;
|
|
111
|
+
}, undefined>, v.BaseValidation<{
|
|
112
|
+
id: string;
|
|
113
|
+
type: string;
|
|
114
|
+
controller: `did:${string}:${string}`;
|
|
115
|
+
publicKeyMultibase?: string | undefined;
|
|
116
|
+
publicKeyJwk?: {
|
|
117
|
+
[x: string]: unknown;
|
|
118
|
+
} | undefined;
|
|
119
|
+
} & {
|
|
120
|
+
[key: string]: unknown;
|
|
121
|
+
}, {
|
|
122
|
+
id: string;
|
|
123
|
+
type: string;
|
|
124
|
+
controller: `did:${string}:${string}`;
|
|
125
|
+
publicKeyMultibase?: string | undefined;
|
|
126
|
+
publicKeyJwk?: {
|
|
127
|
+
[x: string]: unknown;
|
|
128
|
+
} | undefined;
|
|
129
|
+
} & {
|
|
130
|
+
[key: string]: unknown;
|
|
131
|
+
}, v.CheckIssue<{
|
|
132
|
+
id: string;
|
|
133
|
+
type: string;
|
|
134
|
+
controller: `did:${string}:${string}`;
|
|
135
|
+
publicKeyMultibase?: string | undefined;
|
|
136
|
+
publicKeyJwk?: {
|
|
137
|
+
[x: string]: unknown;
|
|
138
|
+
} | undefined;
|
|
139
|
+
} & {
|
|
140
|
+
[key: string]: unknown;
|
|
141
|
+
}>>]>], undefined>, undefined>, undefined>;
|
|
142
|
+
}, undefined>, v.CheckAction<{
|
|
143
|
+
'@context'?: string[] | undefined;
|
|
144
|
+
id: `did:${string}:${string}`;
|
|
145
|
+
alsoKnownAs?: string[] | undefined;
|
|
146
|
+
verificationMethod?: ({
|
|
147
|
+
id: string;
|
|
148
|
+
type: string;
|
|
149
|
+
controller: `did:${string}:${string}`;
|
|
150
|
+
publicKeyMultibase?: string | undefined;
|
|
151
|
+
publicKeyJwk?: {
|
|
152
|
+
[x: string]: unknown;
|
|
153
|
+
} | undefined;
|
|
154
|
+
} & {
|
|
155
|
+
[key: string]: unknown;
|
|
156
|
+
})[] | undefined;
|
|
157
|
+
service?: ({
|
|
158
|
+
id: string;
|
|
159
|
+
type: string | string[];
|
|
160
|
+
serviceEndpoint: string | (string | {
|
|
161
|
+
[x: string]: string;
|
|
162
|
+
})[] | {
|
|
163
|
+
[x: string]: string;
|
|
164
|
+
};
|
|
165
|
+
} & {
|
|
166
|
+
[key: string]: unknown;
|
|
167
|
+
})[] | undefined;
|
|
168
|
+
controller?: `did:${string}:${string}`[] | `did:${string}:${string}` | undefined;
|
|
169
|
+
authentication?: (string | ({
|
|
170
|
+
id: string;
|
|
171
|
+
type: string;
|
|
172
|
+
controller: `did:${string}:${string}`;
|
|
173
|
+
publicKeyMultibase?: string | undefined;
|
|
174
|
+
publicKeyJwk?: {
|
|
175
|
+
[x: string]: unknown;
|
|
176
|
+
} | undefined;
|
|
177
|
+
} & {
|
|
178
|
+
[key: string]: unknown;
|
|
179
|
+
}))[] | undefined;
|
|
180
|
+
} & {
|
|
181
|
+
[key: string]: unknown;
|
|
182
|
+
}, "duplicate service ids">]>;
|
|
183
|
+
export type VerificationMethod = v.InferOutput<typeof verificationMethod>;
|
|
184
|
+
export type Service = v.InferOutput<typeof service>;
|
|
185
|
+
export type DidDocument = v.InferOutput<typeof didDocument>;
|
|
14
186
|
//# sourceMappingURL=typedefs.d.ts.map
|
package/dist/typedefs.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typedefs.d.ts","sourceRoot":"","sources":["../lib/typedefs.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"typedefs.d.ts","sourceRoot":"","sources":["../lib/typedefs.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAK7B,eAAO,MAAM,gBAAgB,gGAG5B,CAAC;AAEF,eAAO,MAAM,cAAc,6GAG1B,CAAC;AAEF,eAAO,MAAM,eAAe,6GAA0E,CAAC;AAEvG,eAAO,MAAM,SAAS,sFAAwC,CAAC;AAE/D,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAoB9B,CAAC;AAEF,eAAO,MAAM,OAAO;;;;aASlB,CAAC;AAcH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6BAgCvB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAC1E,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,OAAO,CAAC,CAAC;AACpD,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,WAAW,CAAC,CAAC"}
|
package/dist/typedefs.js
CHANGED
|
@@ -1,121 +1,62 @@
|
|
|
1
1
|
import { isDid } from '@atcute/lexicons/syntax';
|
|
2
|
-
import * as v from '
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export const
|
|
6
|
-
|
|
7
|
-
export const
|
|
8
|
-
export const
|
|
9
|
-
|
|
10
|
-
}, `must be a url`);
|
|
11
|
-
export const didRelativeUri = v.string().assert((input) => {
|
|
12
|
-
return FRAGMENT_RE.test(input) || URL.canParse(input);
|
|
13
|
-
}, `must be a did relative uri`);
|
|
14
|
-
export const multibaseString = v.string().assert((input) => {
|
|
15
|
-
return MULTIBASE_RE.test(input);
|
|
16
|
-
}, `must be a base58 multibase`);
|
|
17
|
-
export const didString = v.string().assert(isDid, `must be a did`);
|
|
18
|
-
export const verificationMethod = v
|
|
19
|
-
.object({
|
|
2
|
+
import * as v from 'valibot';
|
|
3
|
+
const FRAGMENT_RE = /^#[^#]+$/;
|
|
4
|
+
const MULTIBASE_RE = /^z[a-km-zA-HJ-NP-Z1-9]+$/;
|
|
5
|
+
export const rfc3968UriSchema = v.pipe(v.string(), v.check((input) => URL.canParse(input), `must be a url`));
|
|
6
|
+
export const didRelativeUri = v.pipe(v.string(), v.check((input) => FRAGMENT_RE.test(input) || URL.canParse(input), `must be a did relative uri`));
|
|
7
|
+
export const multibaseString = v.pipe(v.string(), v.regex(MULTIBASE_RE, `must be a base58 multibase`));
|
|
8
|
+
export const didString = v.custom(isDid, `must be a did`);
|
|
9
|
+
export const verificationMethod = v.pipe(v.looseObject({
|
|
20
10
|
id: didRelativeUri,
|
|
21
11
|
type: v.string(),
|
|
22
12
|
controller: didString,
|
|
23
|
-
publicKeyMultibase:
|
|
24
|
-
publicKeyJwk: v.record().
|
|
25
|
-
})
|
|
26
|
-
.chain((input) => {
|
|
13
|
+
publicKeyMultibase: v.optional(multibaseString),
|
|
14
|
+
publicKeyJwk: v.optional(v.record(v.string(), v.unknown())),
|
|
15
|
+
}), v.forward(v.check((input) => {
|
|
27
16
|
switch (input.type) {
|
|
28
|
-
case 'Multikey':
|
|
29
|
-
if (input.publicKeyMultibase === undefined) {
|
|
30
|
-
return v.err({ message: `missing multikey`, path: ['publicKeyMultibase'] });
|
|
31
|
-
}
|
|
32
|
-
break;
|
|
33
|
-
}
|
|
17
|
+
case 'Multikey':
|
|
34
18
|
case 'EcdsaSecp256k1VerificationKey2019':
|
|
35
|
-
case 'EcdsaSecp256r1VerificationKey2019':
|
|
36
|
-
|
|
37
|
-
return v.err({ message: `missing multibase key`, path: ['publicKeyMultibase'] });
|
|
38
|
-
}
|
|
39
|
-
break;
|
|
40
|
-
}
|
|
19
|
+
case 'EcdsaSecp256r1VerificationKey2019':
|
|
20
|
+
return input.publicKeyMultibase !== undefined;
|
|
41
21
|
}
|
|
42
|
-
return
|
|
43
|
-
});
|
|
44
|
-
export const service = v.
|
|
22
|
+
return true;
|
|
23
|
+
}, `missing public key multibase`), ['publicKeyMultibase']));
|
|
24
|
+
export const service = v.looseObject({
|
|
45
25
|
// should've only been RFC3968, but did:plc uses relative URIs.
|
|
46
26
|
id: didRelativeUri,
|
|
47
|
-
type: v.union(v.string(), v.array(v.string())),
|
|
48
|
-
serviceEndpoint: v.union(
|
|
27
|
+
type: v.union([v.string(), v.array(v.string())]),
|
|
28
|
+
serviceEndpoint: v.union([
|
|
29
|
+
rfc3968UriSchema,
|
|
30
|
+
v.record(v.string(), rfc3968UriSchema),
|
|
31
|
+
v.array(v.union([rfc3968UriSchema, v.record(v.string(), rfc3968UriSchema)])),
|
|
32
|
+
]),
|
|
49
33
|
});
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
.chain((input) => {
|
|
57
|
-
for (let i = 0, len = input.length; i < len; i++) {
|
|
58
|
-
const aka = input[i];
|
|
59
|
-
for (let j = 0; j < i; j++) {
|
|
60
|
-
if (aka === input[j]) {
|
|
61
|
-
return v.err({
|
|
62
|
-
message: `duplicate "${aka}" aka entry`,
|
|
63
|
-
path: [i],
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return v.ok(input);
|
|
69
|
-
})
|
|
70
|
-
.optional(),
|
|
71
|
-
verificationMethod: v
|
|
72
|
-
.array(verificationMethod)
|
|
73
|
-
.chain((input) => {
|
|
74
|
-
for (let i = 0, len = input.length; i < len; i++) {
|
|
75
|
-
const method = input[i];
|
|
76
|
-
const methodId = method.id;
|
|
77
|
-
for (let j = 0; j < i; j++) {
|
|
78
|
-
if (methodId === input[j].id) {
|
|
79
|
-
return v.err({
|
|
80
|
-
message: `duplicate "${methodId}" verification method`,
|
|
81
|
-
path: [i, 'id'],
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return v.ok(input);
|
|
87
|
-
})
|
|
88
|
-
.optional(),
|
|
89
|
-
service: v.array(service).optional(),
|
|
90
|
-
controller: v.union(didString, v.array(didString)).optional(),
|
|
91
|
-
authentication: v.array(v.union(didRelativeUri, verificationMethod)).optional(),
|
|
92
|
-
})
|
|
93
|
-
.chain((input) => {
|
|
94
|
-
const { id: did, service: services } = input;
|
|
95
|
-
if (services?.length) {
|
|
96
|
-
const len = services.length;
|
|
97
|
-
// oxlint-disable-next-line no-new-array
|
|
98
|
-
const identifiers = new Array(len);
|
|
99
|
-
for (let i = 0; i < len; i++) {
|
|
100
|
-
const service = services[i];
|
|
101
|
-
let id = service.id;
|
|
102
|
-
if (id[0] === '#') {
|
|
103
|
-
id = did + id;
|
|
104
|
-
}
|
|
105
|
-
identifiers[i] = id;
|
|
106
|
-
}
|
|
107
|
-
for (let i = 0; i < len; i++) {
|
|
108
|
-
const id = identifiers[i];
|
|
109
|
-
for (let j = 0; j < i; j++) {
|
|
110
|
-
if (id === identifiers[j]) {
|
|
111
|
-
return v.err({
|
|
112
|
-
message: `duplicate "${id}" service`,
|
|
113
|
-
path: ['service', i, 'id'],
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
}
|
|
34
|
+
const hasDuplicates = (arr, key = (x) => x) => {
|
|
35
|
+
const seen = new Set();
|
|
36
|
+
for (const item of arr) {
|
|
37
|
+
const k = key(item);
|
|
38
|
+
if (seen.has(k)) {
|
|
39
|
+
return true;
|
|
117
40
|
}
|
|
41
|
+
seen.add(k);
|
|
118
42
|
}
|
|
119
|
-
return
|
|
120
|
-
}
|
|
43
|
+
return false;
|
|
44
|
+
};
|
|
45
|
+
export const didDocument = v.pipe(v.looseObject({
|
|
46
|
+
'@context': v.optional(v.array(rfc3968UriSchema)),
|
|
47
|
+
id: didString,
|
|
48
|
+
alsoKnownAs: v.optional(v.pipe(v.array(rfc3968UriSchema), v.check((input) => !hasDuplicates(input), `duplicate aka entries`))),
|
|
49
|
+
verificationMethod: v.optional(v.pipe(v.array(verificationMethod), v.check((input) => !hasDuplicates(input, (m) => m.id), `duplicate verification method ids`))),
|
|
50
|
+
service: v.optional(v.array(service)),
|
|
51
|
+
controller: v.optional(v.union([didString, v.array(didString)])),
|
|
52
|
+
authentication: v.optional(v.array(v.union([didRelativeUri, verificationMethod]))),
|
|
53
|
+
}), v.check((input) => {
|
|
54
|
+
const services = input.service;
|
|
55
|
+
if (!services?.length) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
const did = input.id;
|
|
59
|
+
const identifiers = services.map((s) => (s.id[0] === '#' ? did + s.id : s.id));
|
|
60
|
+
return !hasDuplicates(identifiers);
|
|
61
|
+
}, `duplicate service ids`));
|
|
121
62
|
//# sourceMappingURL=typedefs.js.map
|
package/dist/typedefs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typedefs.js","sourceRoot":"","sources":["../lib/typedefs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"typedefs.js","sourceRoot":"","sources":["../lib/typedefs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAY,MAAM,yBAAyB,CAAC;AAE1D,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAE7B,MAAM,WAAW,GAAG,UAAU,CAAC;AAC/B,MAAM,YAAY,GAAG,0BAA0B,CAAC;AAEhD,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,IAAI,CACrC,CAAC,CAAC,MAAM,EAAE,EACV,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,eAAe,CAAC,CACxD,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC,IAAI,CACnC,CAAC,CAAC,MAAM,EAAE,EACV,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,4BAA4B,CAAC,CAChG,CAAC;AAEF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
|
-
import
|
|
1
|
+
import type { Handle } from '@atcute/lexicons';
|
|
2
|
+
import type * as t from './typedefs.ts';
|
|
2
3
|
export interface VerificationMaterial {
|
|
3
4
|
type: string;
|
|
4
5
|
publicKeyMultibase: string;
|
|
@@ -7,10 +8,10 @@ export declare const isAtprotoServiceEndpoint: (input: string) => boolean;
|
|
|
7
8
|
export declare const getVerificationMaterial: (doc: t.DidDocument, id: `#${string}`) => VerificationMaterial | undefined;
|
|
8
9
|
export declare const getAtprotoVerificationMaterial: (doc: t.DidDocument) => VerificationMaterial | undefined;
|
|
9
10
|
export declare const getAtprotoLabelerVerificationMaterial: (doc: t.DidDocument) => VerificationMaterial | undefined;
|
|
10
|
-
export declare const getAtprotoHandle: (doc: t.DidDocument) =>
|
|
11
|
+
export declare const getAtprotoHandle: (doc: t.DidDocument) => Handle | null | undefined;
|
|
11
12
|
export declare const getAtprotoServiceEndpoint: (doc: t.DidDocument, predicate: {
|
|
12
13
|
id: `#${string}`;
|
|
13
|
-
type?: string
|
|
14
|
+
type?: string;
|
|
14
15
|
}) => string | undefined;
|
|
15
16
|
export declare const getPdsEndpoint: (doc: t.DidDocument) => string | undefined;
|
|
16
17
|
export declare const getLabelerEndpoint: (doc: t.DidDocument) => string | undefined;
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../lib/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../lib/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAG/C,OAAO,KAAK,KAAK,CAAC,MAAM,eAAe,CAAC;AAExC,MAAM,WAAW,oBAAoB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,kBAAkB,EAAE,MAAM,CAAC;CAC3B;AAID,eAAO,MAAM,wBAAwB,UAAW,MAAM,KAAG,OAiBxD,CAAC;AAEF,eAAO,MAAM,uBAAuB,QAC9B,CAAC,CAAC,WAAW,MACd,IAAI,MAAM,EAAE,KACd,oBAAoB,GAAG,SAqBzB,CAAC;AAEF,eAAO,MAAM,8BAA8B,QAAS,CAAC,CAAC,WAAW,KAAG,oBAAoB,GAAG,SAE1F,CAAC;AAEF,eAAO,MAAM,qCAAqC,QAC5C,CAAC,CAAC,WAAW,KAChB,oBAAoB,GAAG,SAEzB,CAAC;AAEF,eAAO,MAAM,gBAAgB,QAAS,CAAC,CAAC,WAAW,KAAG,MAAM,GAAG,IAAI,GAAG,SAyBrE,CAAC;AAEF,eAAO,MAAM,yBAAyB,QAChC,CAAC,CAAC,WAAW,aACP;IAAE,EAAE,EAAE,IAAI,MAAM,EAAE,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,KAC5C,MAAM,GAAG,SA+BX,CAAC;AAEF,eAAO,MAAM,cAAc,QAAS,CAAC,CAAC,WAAW,KAAG,MAAM,GAAG,SAK5D,CAAC;AAEF,eAAO,MAAM,kBAAkB,QAAS,CAAC,CAAC,WAAW,KAAG,MAAM,GAAG,SAKhE,CAAC;AAEF,eAAO,MAAM,sBAAsB,QAAS,CAAC,CAAC,WAAW,KAAG,MAAM,GAAG,SAKpE,CAAC;AAEF,eAAO,MAAM,yBAAyB,QAAS,CAAC,CAAC,WAAW,KAAG,MAAM,GAAG,SAKvE,CAAC;AAEF,eAAO,MAAM,8BAA8B,QAAS,CAAC,CAAC,WAAW,KAAG,MAAM,GAAG,SAK5E,CAAC"}
|
package/dist/utils.js
CHANGED
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../lib/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../lib/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE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,EAAE;IAC5E,OAAO,yBAAyB,CAAC,GAAG,EAAE;QACrC,EAAE,EAAE,kBAAkB;QACtB,IAAI,EAAE,gBAAgB;KACtB,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,GAAkB,EAAsB,EAAE;IAChF,OAAO,yBAAyB,CAAC,GAAG,EAAE;QACrC,EAAE,EAAE,YAAY;QAChB,IAAI,EAAE,iBAAiB;KACvB,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,GAAkB,EAAsB,EAAE;IACnF,OAAO,yBAAyB,CAAC,GAAG,EAAE;QACrC,EAAE,EAAE,UAAU;QACd,IAAI,EAAE,mBAAmB;KACzB,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAAC,GAAkB,EAAsB,EAAE;IACxF,OAAO,yBAAyB,CAAC,GAAG,EAAE;QACrC,EAAE,EAAE,aAAa;QACjB,IAAI,EAAE,yBAAyB;KAC/B,CAAC,CAAC;AACJ,CAAC,CAAC"}
|
package/lib/did.ts
CHANGED
|
@@ -8,13 +8,13 @@ const FRAGMENT_RE = /^(?:[A-Za-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9A-Fa-f]{2})*$/;
|
|
|
8
8
|
/**
|
|
9
9
|
* checks if it's a DID identifier that is supported by atproto
|
|
10
10
|
*/
|
|
11
|
-
export const isAtprotoDid = (input:
|
|
11
|
+
export const isAtprotoDid = (input: unknown): input is AtprotoDid => {
|
|
12
12
|
return isPlcDid(input) || isAtprotoWebDid(input);
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
-
export const isAtprotoAudience = (input:
|
|
15
|
+
export const isAtprotoAudience = (input: unknown): input is AtprotoAudience => {
|
|
16
16
|
// 'did:web:a.co#f'
|
|
17
|
-
if (input.length < 14) {
|
|
17
|
+
if (typeof input !== 'string' || input.length < 14) {
|
|
18
18
|
return false;
|
|
19
19
|
}
|
|
20
20
|
|
package/lib/index.ts
CHANGED
package/lib/methods/key.ts
CHANGED
|
@@ -5,6 +5,6 @@ const KEY_DID_RE = /^did:key:z[a-km-zA-HJ-NP-Z1-9]+$/;
|
|
|
5
5
|
/**
|
|
6
6
|
* checks if input is a did:key identifier
|
|
7
7
|
*/
|
|
8
|
-
export const isKeyDid = (input:
|
|
9
|
-
return input.length >= 10 && KEY_DID_RE.test(input);
|
|
8
|
+
export const isKeyDid = (input: unknown): input is Did<'key'> => {
|
|
9
|
+
return typeof input === 'string' && input.length >= 10 && KEY_DID_RE.test(input);
|
|
10
10
|
};
|
package/lib/methods/plc.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import type { Did } from '@atcute/lexicons/syntax';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
export const PLC_DID_RE = /^did:plc:([a-z2-7]{24})$/;
|
|
3
|
+
const PLC_DID_RE = /^did:plc:([a-z2-7]{24})$/;
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* checks if input is a did:plc identifier
|
|
8
7
|
*/
|
|
9
|
-
export const isPlcDid = (input:
|
|
10
|
-
return input.length === 32 && PLC_DID_RE.test(input);
|
|
8
|
+
export const isPlcDid = (input: unknown): input is Did<'plc'> => {
|
|
9
|
+
return typeof input === 'string' && input.length === 32 && PLC_DID_RE.test(input);
|
|
11
10
|
};
|
package/lib/methods/web.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import type { Did } from '@atcute/lexicons/syntax';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
export const WEB_DID_RE =
|
|
3
|
+
const WEB_DID_RE =
|
|
5
4
|
/^did:web:([a-zA-Z0-9%-]+(?:(?:\.[a-zA-Z0-9%-]+)*(?:\.[a-zA-Z]{2,}))?)?((?::[a-zA-Z0-9\-%.]+)+)?$/;
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
export const ATPROTO_WEB_DID_RE =
|
|
6
|
+
const ATPROTO_WEB_DID_RE =
|
|
9
7
|
/^did:web:([a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*(?:\.[a-zA-Z]{2,})|localhost(?:%3[aA]\d+)?)$/;
|
|
10
8
|
|
|
11
9
|
/**
|
|
@@ -13,15 +11,15 @@ export const ATPROTO_WEB_DID_RE =
|
|
|
13
11
|
* `isAtprotoWebDid` for atproto-related cases as atproto only supports a subset
|
|
14
12
|
* of the did:web specification (namely, no custom paths)
|
|
15
13
|
*/
|
|
16
|
-
export const isWebDid = (input:
|
|
17
|
-
return input.length >= 9 && WEB_DID_RE.test(input);
|
|
14
|
+
export const isWebDid = (input: unknown): input is Did<'web'> => {
|
|
15
|
+
return typeof input === 'string' && input.length >= 9 && WEB_DID_RE.test(input);
|
|
18
16
|
};
|
|
19
17
|
|
|
20
18
|
/**
|
|
21
19
|
* checks if input is a did:web identifier that is supported by atproto
|
|
22
20
|
*/
|
|
23
|
-
export const isAtprotoWebDid = (input:
|
|
24
|
-
return input.length >= 12 && ATPROTO_WEB_DID_RE.test(input);
|
|
21
|
+
export const isAtprotoWebDid = (input: unknown): input is Did<'web'> => {
|
|
22
|
+
return typeof input === 'string' && input.length >= 12 && ATPROTO_WEB_DID_RE.test(input);
|
|
25
23
|
};
|
|
26
24
|
|
|
27
25
|
/**
|
package/lib/typedefs.ts
CHANGED
|
@@ -1,152 +1,103 @@
|
|
|
1
|
-
import { isDid } from '@atcute/lexicons/syntax';
|
|
1
|
+
import { isDid, type Did } from '@atcute/lexicons/syntax';
|
|
2
2
|
|
|
3
|
-
import * as v from '
|
|
3
|
+
import * as v from 'valibot';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
const FRAGMENT_RE = /^#[^#]+$/;
|
|
6
|
+
const MULTIBASE_RE = /^z[a-km-zA-HJ-NP-Z1-9]+$/;
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
export const rfc3968UriSchema = v.pipe(
|
|
9
|
+
v.string(),
|
|
10
|
+
v.check((input) => URL.canParse(input), `must be a url`),
|
|
11
|
+
);
|
|
11
12
|
|
|
12
|
-
export const
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
export const didRelativeUri = v.pipe(
|
|
14
|
+
v.string(),
|
|
15
|
+
v.check((input) => FRAGMENT_RE.test(input) || URL.canParse(input), `must be a did relative uri`),
|
|
16
|
+
);
|
|
15
17
|
|
|
16
|
-
export const
|
|
17
|
-
return FRAGMENT_RE.test(input) || URL.canParse(input);
|
|
18
|
-
}, `must be a did relative uri`);
|
|
18
|
+
export const multibaseString = v.pipe(v.string(), v.regex(MULTIBASE_RE, `must be a base58 multibase`));
|
|
19
19
|
|
|
20
|
-
export const
|
|
21
|
-
return MULTIBASE_RE.test(input);
|
|
22
|
-
}, `must be a base58 multibase`);
|
|
20
|
+
export const didString = v.custom<Did>(isDid, `must be a did`);
|
|
23
21
|
|
|
24
|
-
export const
|
|
25
|
-
|
|
26
|
-
export const verificationMethod: v.Type<t.VerificationMethod> = v
|
|
27
|
-
.object({
|
|
22
|
+
export const verificationMethod = v.pipe(
|
|
23
|
+
v.looseObject({
|
|
28
24
|
id: didRelativeUri,
|
|
29
25
|
type: v.string(),
|
|
30
26
|
controller: didString,
|
|
31
|
-
publicKeyMultibase:
|
|
32
|
-
publicKeyJwk: v.record().
|
|
33
|
-
})
|
|
34
|
-
.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
break;
|
|
42
|
-
}
|
|
43
|
-
case 'EcdsaSecp256k1VerificationKey2019':
|
|
44
|
-
case 'EcdsaSecp256r1VerificationKey2019': {
|
|
45
|
-
if (input.publicKeyMultibase === undefined) {
|
|
46
|
-
return v.err({ message: `missing multibase key`, path: ['publicKeyMultibase'] });
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
break;
|
|
27
|
+
publicKeyMultibase: v.optional(multibaseString),
|
|
28
|
+
publicKeyJwk: v.optional(v.record(v.string(), v.unknown())),
|
|
29
|
+
}),
|
|
30
|
+
v.forward(
|
|
31
|
+
v.check((input) => {
|
|
32
|
+
switch (input.type) {
|
|
33
|
+
case 'Multikey':
|
|
34
|
+
case 'EcdsaSecp256k1VerificationKey2019':
|
|
35
|
+
case 'EcdsaSecp256r1VerificationKey2019':
|
|
36
|
+
return input.publicKeyMultibase !== undefined;
|
|
50
37
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
38
|
+
return true;
|
|
39
|
+
}, `missing public key multibase`),
|
|
40
|
+
['publicKeyMultibase'],
|
|
41
|
+
),
|
|
42
|
+
);
|
|
55
43
|
|
|
56
|
-
export const service
|
|
44
|
+
export const service = v.looseObject({
|
|
57
45
|
// should've only been RFC3968, but did:plc uses relative URIs.
|
|
58
46
|
id: didRelativeUri,
|
|
59
|
-
type: v.union(v.string(), v.array(v.string())),
|
|
60
|
-
serviceEndpoint: v.union(
|
|
47
|
+
type: v.union([v.string(), v.array(v.string())]),
|
|
48
|
+
serviceEndpoint: v.union([
|
|
61
49
|
rfc3968UriSchema,
|
|
62
|
-
v.record(rfc3968UriSchema),
|
|
63
|
-
v.array(v.union(rfc3968UriSchema, v.record(rfc3968UriSchema))),
|
|
64
|
-
),
|
|
50
|
+
v.record(v.string(), rfc3968UriSchema),
|
|
51
|
+
v.array(v.union([rfc3968UriSchema, v.record(v.string(), rfc3968UriSchema)])),
|
|
52
|
+
]),
|
|
65
53
|
});
|
|
66
54
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
for (let j = 0; j < i; j++) {
|
|
80
|
-
if (aka === input[j]) {
|
|
81
|
-
return v.err({
|
|
82
|
-
message: `duplicate "${aka}" aka entry`,
|
|
83
|
-
path: [i],
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return v.ok(input);
|
|
90
|
-
})
|
|
91
|
-
.optional(),
|
|
92
|
-
verificationMethod: v
|
|
93
|
-
.array(verificationMethod)
|
|
94
|
-
.chain((input) => {
|
|
95
|
-
for (let i = 0, len = input.length; i < len; i++) {
|
|
96
|
-
const method = input[i];
|
|
97
|
-
const methodId = method.id;
|
|
98
|
-
|
|
99
|
-
for (let j = 0; j < i; j++) {
|
|
100
|
-
if (methodId === input[j].id) {
|
|
101
|
-
return v.err({
|
|
102
|
-
message: `duplicate "${methodId}" verification method`,
|
|
103
|
-
path: [i, 'id'],
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return v.ok(input);
|
|
110
|
-
})
|
|
111
|
-
.optional(),
|
|
112
|
-
service: v.array(service).optional(),
|
|
113
|
-
|
|
114
|
-
controller: v.union(didString, v.array(didString)).optional(),
|
|
115
|
-
authentication: v.array(v.union(didRelativeUri, verificationMethod)).optional(),
|
|
116
|
-
})
|
|
117
|
-
.chain((input) => {
|
|
118
|
-
const { id: did, service: services } = input;
|
|
119
|
-
|
|
120
|
-
if (services?.length) {
|
|
121
|
-
const len = services.length;
|
|
122
|
-
|
|
123
|
-
// oxlint-disable-next-line no-new-array
|
|
124
|
-
const identifiers = new Array(len);
|
|
125
|
-
|
|
126
|
-
for (let i = 0; i < len; i++) {
|
|
127
|
-
const service = services[i];
|
|
128
|
-
|
|
129
|
-
let id = service.id;
|
|
130
|
-
if (id[0] === '#') {
|
|
131
|
-
id = did + id;
|
|
132
|
-
}
|
|
55
|
+
const hasDuplicates = <T>(arr: readonly T[], key: (item: T) => unknown = (x) => x): boolean => {
|
|
56
|
+
const seen = new Set<unknown>();
|
|
57
|
+
for (const item of arr) {
|
|
58
|
+
const k = key(item);
|
|
59
|
+
if (seen.has(k)) {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
seen.add(k);
|
|
63
|
+
}
|
|
64
|
+
return false;
|
|
65
|
+
};
|
|
133
66
|
|
|
134
|
-
|
|
135
|
-
|
|
67
|
+
export const didDocument = v.pipe(
|
|
68
|
+
v.looseObject({
|
|
69
|
+
'@context': v.optional(v.array(rfc3968UriSchema)),
|
|
136
70
|
|
|
137
|
-
|
|
138
|
-
const id = identifiers[i];
|
|
71
|
+
id: didString,
|
|
139
72
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
73
|
+
alsoKnownAs: v.optional(
|
|
74
|
+
v.pipe(
|
|
75
|
+
v.array(rfc3968UriSchema),
|
|
76
|
+
v.check((input) => !hasDuplicates(input), `duplicate aka entries`),
|
|
77
|
+
),
|
|
78
|
+
),
|
|
79
|
+
verificationMethod: v.optional(
|
|
80
|
+
v.pipe(
|
|
81
|
+
v.array(verificationMethod),
|
|
82
|
+
v.check((input) => !hasDuplicates(input, (m) => m.id), `duplicate verification method ids`),
|
|
83
|
+
),
|
|
84
|
+
),
|
|
85
|
+
service: v.optional(v.array(service)),
|
|
86
|
+
|
|
87
|
+
controller: v.optional(v.union([didString, v.array(didString)])),
|
|
88
|
+
authentication: v.optional(v.array(v.union([didRelativeUri, verificationMethod]))),
|
|
89
|
+
}),
|
|
90
|
+
v.check((input) => {
|
|
91
|
+
const services = input.service;
|
|
92
|
+
if (!services?.length) {
|
|
93
|
+
return true;
|
|
149
94
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
95
|
+
const did = input.id;
|
|
96
|
+
const identifiers = services.map((s) => (s.id[0] === '#' ? did + s.id : s.id));
|
|
97
|
+
return !hasDuplicates(identifiers);
|
|
98
|
+
}, `duplicate service ids`),
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
export type VerificationMethod = v.InferOutput<typeof verificationMethod>;
|
|
102
|
+
export type Service = v.InferOutput<typeof service>;
|
|
103
|
+
export type DidDocument = v.InferOutput<typeof didDocument>;
|
package/lib/utils.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atcute/identity",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "syntax, type definitions and schemas for atproto handles, DIDs and DID documents",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"atproto",
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
"dist/",
|
|
16
16
|
"lib/",
|
|
17
17
|
"!lib/**/*.bench.ts",
|
|
18
|
-
"!lib/**/*.test.ts"
|
|
18
|
+
"!lib/**/*.test.ts",
|
|
19
|
+
"!dist/**/*.{test,bench}.*"
|
|
19
20
|
],
|
|
20
21
|
"type": "module",
|
|
21
22
|
"sideEffects": false,
|
|
@@ -26,15 +27,18 @@
|
|
|
26
27
|
"access": "public"
|
|
27
28
|
},
|
|
28
29
|
"dependencies": {
|
|
29
|
-
"
|
|
30
|
-
"@atcute/lexicons": "^
|
|
30
|
+
"valibot": "^1.4.0",
|
|
31
|
+
"@atcute/lexicons": "^2.0.0"
|
|
31
32
|
},
|
|
32
33
|
"devDependencies": {
|
|
33
|
-
"@vitest/coverage-v8": "^4.1.
|
|
34
|
-
"vitest": "^4.1.
|
|
34
|
+
"@vitest/coverage-v8": "^4.1.5",
|
|
35
|
+
"vitest": "^4.1.5"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"@atcute/lexicons": "^2.0.0"
|
|
35
39
|
},
|
|
36
40
|
"scripts": {
|
|
37
|
-
"build": "tsgo
|
|
41
|
+
"build": "tsgo",
|
|
38
42
|
"test": "vitest",
|
|
39
43
|
"prepublish": "rm -rf dist; pnpm run build"
|
|
40
44
|
}
|
package/dist/types.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { Did } from '@atcute/lexicons';
|
|
2
|
-
export interface VerificationMethod {
|
|
3
|
-
id: string;
|
|
4
|
-
type: string;
|
|
5
|
-
controller: Did;
|
|
6
|
-
publicKeyMultibase?: string;
|
|
7
|
-
publicKeyJwk?: Record<string, unknown>;
|
|
8
|
-
}
|
|
9
|
-
export interface Service {
|
|
10
|
-
id: string;
|
|
11
|
-
type: string | string[];
|
|
12
|
-
serviceEndpoint: string | Record<string, string> | (string | Record<string, string>)[];
|
|
13
|
-
}
|
|
14
|
-
export interface DidDocument {
|
|
15
|
-
'@context'?: string[];
|
|
16
|
-
id: Did;
|
|
17
|
-
controller?: Did | Did[];
|
|
18
|
-
alsoKnownAs?: string[];
|
|
19
|
-
verificationMethod?: VerificationMethod[];
|
|
20
|
-
authentication?: (string | VerificationMethod)[];
|
|
21
|
-
service?: Service[];
|
|
22
|
-
}
|
|
23
|
-
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAE5C,MAAM,WAAW,kBAAkB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,GAAG,CAAC;IAChB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACvC;AAED,MAAM,WAAW,OAAO;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACxB,eAAe,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC;CACvF;AAED,MAAM,WAAW,WAAW;IAC3B,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,EAAE,EAAE,GAAG,CAAC;IACR,UAAU,CAAC,EAAE,GAAG,GAAG,GAAG,EAAE,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,kBAAkB,CAAC,EAAE,kBAAkB,EAAE,CAAC;IAC1C,cAAc,CAAC,EAAE,CAAC,MAAM,GAAG,kBAAkB,CAAC,EAAE,CAAC;IACjD,OAAO,CAAC,EAAE,OAAO,EAAE,CAAC;CACpB"}
|
package/dist/types.js
DELETED
package/dist/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../lib/types.ts"],"names":[],"mappings":""}
|
package/lib/types.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { Did } from '@atcute/lexicons';
|
|
2
|
-
|
|
3
|
-
export interface VerificationMethod {
|
|
4
|
-
id: string;
|
|
5
|
-
type: string;
|
|
6
|
-
controller: Did;
|
|
7
|
-
publicKeyMultibase?: string;
|
|
8
|
-
publicKeyJwk?: Record<string, unknown>;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface Service {
|
|
12
|
-
id: string;
|
|
13
|
-
type: string | string[];
|
|
14
|
-
serviceEndpoint: string | Record<string, string> | (string | Record<string, string>)[];
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface DidDocument {
|
|
18
|
-
'@context'?: string[];
|
|
19
|
-
id: Did;
|
|
20
|
-
controller?: Did | Did[];
|
|
21
|
-
alsoKnownAs?: string[];
|
|
22
|
-
verificationMethod?: VerificationMethod[];
|
|
23
|
-
authentication?: (string | VerificationMethod)[];
|
|
24
|
-
service?: Service[];
|
|
25
|
-
}
|