@atproto/did 0.2.4 → 0.4.0-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/methods.js CHANGED
@@ -1,19 +1,3 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./methods/plc.js"), exports);
18
- __exportStar(require("./methods/web.js"), exports);
1
+ export * from './methods/plc.js';
2
+ export * from './methods/web.js';
19
3
  //# sourceMappingURL=methods.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"methods.js","sourceRoot":"","sources":["../src/methods.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAgC;AAChC,mDAAgC","sourcesContent":["export * from './methods/plc.js'\nexport * from './methods/web.js'\n"]}
1
+ {"version":3,"file":"methods.js","sourceRoot":"","sources":["../src/methods.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,kBAAkB,CAAA","sourcesContent":["export * from './methods/plc.js'\nexport * from './methods/web.js'\n"]}
package/dist/utils.js CHANGED
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.matchesIdentifier = matchesIdentifier;
4
- function matchesIdentifier(did, id, candidate) {
1
+ export function matchesIdentifier(did, id, candidate) {
5
2
  // optimized implementation of:
6
3
  // return candidate === `#${id}` || candidate === `${did}#${id}`
7
4
  return candidate.charCodeAt(0) === 35 // '#'
package/dist/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;AAGA,8CAcC;AAdD,SAAgB,iBAAiB,CAC/B,GAAM,EACN,EAAK,EACL,SAAiB;IAEjB,+BAA+B;IAC/B,gEAAgE;IAEhE,OAAO,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,MAAM;QAC1C,CAAC,CAAC,SAAS,CAAC,MAAM,KAAK,EAAE,CAAC,MAAM,GAAG,CAAC,IAAI,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC9D,CAAC,CAAC,SAAS,CAAC,MAAM,KAAK,EAAE,CAAC,MAAM,GAAG,CAAC,GAAG,GAAG,CAAC,MAAM;YAC7C,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,MAAM;YACjD,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC;YACzB,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;AAC9B,CAAC","sourcesContent":["export type Identifier<D extends string, I extends string> =\n | `#${I}`\n | `${D}#${I}`\nexport function matchesIdentifier<D extends string, I extends string>(\n did: D,\n id: I,\n candidate: string,\n): candidate is Identifier<D, I> {\n // optimized implementation of:\n // return candidate === `#${id}` || candidate === `${did}#${id}`\n\n return candidate.charCodeAt(0) === 35 // '#'\n ? candidate.length === id.length + 1 && candidate.endsWith(id)\n : candidate.length === id.length + 1 + did.length &&\n candidate.charCodeAt(did.length) === 35 && // '#'\n candidate.startsWith(did) &&\n candidate.endsWith(id)\n}\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,iBAAiB,CAC/B,GAAM,EACN,EAAK,EACL,SAAiB;IAEjB,+BAA+B;IAC/B,gEAAgE;IAEhE,OAAO,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,MAAM;QAC1C,CAAC,CAAC,SAAS,CAAC,MAAM,KAAK,EAAE,CAAC,MAAM,GAAG,CAAC,IAAI,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC9D,CAAC,CAAC,SAAS,CAAC,MAAM,KAAK,EAAE,CAAC,MAAM,GAAG,CAAC,GAAG,GAAG,CAAC,MAAM;YAC7C,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,MAAM;YACjD,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC;YACzB,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;AAC9B,CAAC","sourcesContent":["export type Identifier<D extends string, I extends string> =\n | `#${I}`\n | `${D}#${I}`\nexport function matchesIdentifier<D extends string, I extends string>(\n did: D,\n id: I,\n candidate: string,\n): candidate is Identifier<D, I> {\n // optimized implementation of:\n // return candidate === `#${id}` || candidate === `${did}#${id}`\n\n return candidate.charCodeAt(0) === 35 // '#'\n ? candidate.length === id.length + 1 && candidate.endsWith(id)\n : candidate.length === id.length + 1 + did.length &&\n candidate.charCodeAt(did.length) === 35 && // '#'\n candidate.startsWith(did) &&\n candidate.endsWith(id)\n}\n"]}
@@ -0,0 +1,15 @@
1
+ /** @type {import('jest').Config} */
2
+ module.exports = {
3
+ displayName: 'DID',
4
+ transform: {
5
+ '^.+\\.(t|j)s$': [
6
+ '@swc/jest',
7
+ { jsc: { transform: {} }, module: { type: 'es6' } },
8
+ ],
9
+ },
10
+ extensionsToTreatAsEsm: ['.ts'],
11
+ transformIgnorePatterns: [],
12
+ testTimeout: 60000,
13
+ setupFiles: ['<rootDir>/../../jest.setup.ts'],
14
+ moduleNameMapper: { '^(\\.\\.?\\/.+)\\.js$': ['$1.ts', '$1.js'] },
15
+ }
package/package.json CHANGED
@@ -1,6 +1,9 @@
1
1
  {
2
2
  "name": "@atproto/did",
3
- "version": "0.2.4",
3
+ "version": "0.4.0-next.0",
4
+ "engines": {
5
+ "node": ">=22"
6
+ },
4
7
  "license": "MIT",
5
8
  "description": "DID resolution and verification library",
6
9
  "keywords": [
@@ -15,9 +18,7 @@
15
18
  "url": "https://github.com/bluesky-social/atproto",
16
19
  "directory": "packages/did"
17
20
  },
18
- "type": "commonjs",
19
- "main": "dist/index.js",
20
- "types": "dist/index.d.ts",
21
+ "type": "module",
21
22
  "exports": {
22
23
  ".": {
23
24
  "types": "./dist/index.d.ts",
@@ -29,11 +30,11 @@
29
30
  },
30
31
  "devDependencies": {
31
32
  "@swc/jest": "^0.2.24",
32
- "jest": "^28.1.2",
33
- "typescript": "^5.6.3"
33
+ "jest": "^30.0.0",
34
+ "typescript": "^6.0.3"
34
35
  },
35
36
  "scripts": {
36
37
  "build": "tsc --build tsconfig.build.json",
37
- "test": "jest"
38
+ "test": "NODE_OPTIONS=--experimental-vm-modules jest"
38
39
  }
39
40
  }
@@ -35,6 +35,9 @@ const didRelativeUriSchema = z.union([
35
35
  }),
36
36
  ])
37
37
 
38
+ /**
39
+ * @see {@link https://www.w3.org/TR/did-1.0/#verification-material Verification Material}
40
+ */
38
41
  const didVerificationMethodSchema = z.object({
39
42
  id: didRelativeUriSchema,
40
43
  type: z.string().min(1),
@@ -90,7 +93,10 @@ const didServiceSchema = z.object({
90
93
 
91
94
  export type DidService = z.infer<typeof didServiceSchema>
92
95
 
93
- const didAuthenticationSchema = z.union([
96
+ /**
97
+ * @see {@link https://www.w3.org/TR/did-1.0/#referring-to-verification-methods Referring to Verification Methods}
98
+ */
99
+ const verificationMethodReference = z.union([
94
100
  //
95
101
  didRelativeUriSchema,
96
102
  didVerificationMethodSchema,
@@ -101,23 +107,24 @@ const didAuthenticationSchema = z.union([
101
107
  * @see {@link https://www.w3.org/TR/did-core/#production-0}
102
108
  */
103
109
  export const didDocumentSchema = z.object({
104
- '@context': z.union([
105
- z.literal('https://www.w3.org/ns/did/v1'),
106
- z
107
- .array(z.string().url())
108
- .nonempty()
109
- .refine((data) => data[0] === 'https://www.w3.org/ns/did/v1', {
110
- message: 'First @context must be https://www.w3.org/ns/did/v1',
111
- }),
112
- ]),
110
+ '@context': z
111
+ .union([
112
+ z.literal('https://www.w3.org/ns/did/v1'),
113
+ z
114
+ .array(z.string().url())
115
+ .nonempty()
116
+ .refine((data) => data[0] === 'https://www.w3.org/ns/did/v1', {
117
+ message: 'First @context must be https://www.w3.org/ns/did/v1',
118
+ }),
119
+ ])
120
+ // @NOTE @context is required by producers, but optional for consumers.
121
+ .optional(),
113
122
  id: didSchema,
114
123
  controller: didControllerSchema.optional(),
115
124
  alsoKnownAs: z.array(rfc3968UriSchema).optional(),
116
125
  service: z.array(didServiceSchema).optional(),
117
- authentication: z.array(didAuthenticationSchema).optional(),
118
- verificationMethod: z
119
- .array(z.union([didVerificationMethodSchema, didRelativeUriSchema]))
120
- .optional(),
126
+ authentication: z.array(verificationMethodReference).optional(),
127
+ verificationMethod: z.array(didVerificationMethodSchema).optional(),
121
128
  })
122
129
 
123
130
  export type DidDocument<Method extends string = string> = z.infer<
@@ -47,7 +47,7 @@ describe('assertDidPlc', () => {
47
47
 
48
48
  it('throws if called with non string argument', () => {
49
49
  for (const [val, message] of INVALID) {
50
- expect(() => assertDidPlc(val)).toThrowError(
50
+ expect(() => assertDidPlc(val)).toThrow(
51
51
  new InvalidDidError(
52
52
  typeof val === 'string' ? val : typeof val,
53
53
  message,
@@ -66,7 +66,7 @@ describe('asDidPlc', () => {
66
66
 
67
67
  it('throws if called with invalid dids', () => {
68
68
  for (const [val] of INVALID) {
69
- expect(() => asDidPlc(val)).toThrowError(InvalidDidError)
69
+ expect(() => asDidPlc(val)).toThrow(InvalidDidError)
70
70
  }
71
71
  })
72
72
  })
@@ -63,7 +63,7 @@ describe('assertDidWeb', () => {
63
63
 
64
64
  it('throws if called with non string argument', () => {
65
65
  for (const [val, message] of INVALID) {
66
- expect(() => assertDidWeb(val)).toThrowError(
66
+ expect(() => assertDidWeb(val)).toThrow(
67
67
  new InvalidDidError(
68
68
  typeof val === 'string' ? val : typeof val,
69
69
  message,
@@ -98,7 +98,7 @@ describe('asDidWeb', () => {
98
98
 
99
99
  it('throws if called with invalid dids', () => {
100
100
  for (const [val, message] of INVALID) {
101
- expect(() => asDidWeb(val)).toThrowError(
101
+ expect(() => asDidWeb(val)).toThrow(
102
102
  new InvalidDidError(
103
103
  typeof val === 'string' ? val : typeof val,
104
104
  message,
@@ -1 +1 @@
1
- {"root":["./src/atproto.ts","./src/did-document.ts","./src/did-error.ts","./src/did.ts","./src/index.ts","./src/methods.ts","./src/utils.ts","./src/lib/uri.ts","./src/methods/plc.ts","./src/methods/web.ts"],"version":"5.8.2"}
1
+ {"root":["./src/atproto.ts","./src/did-document.ts","./src/did-error.ts","./src/did.ts","./src/index.ts","./src/methods.ts","./src/utils.ts","./src/lib/uri.ts","./src/methods/plc.ts","./src/methods/web.ts"],"version":"6.0.3"}
package/jest.config.js DELETED
@@ -1,13 +0,0 @@
1
- /** @type {import('jest').Config} */
2
- module.exports = {
3
- displayName: 'PDS',
4
- transform: { '^.+\\.(t|j)s$': '@swc/jest' },
5
- // Jest requires all ESM dependencies to be transpiled (even if they are
6
- // dynamically import()ed).
7
- transformIgnorePatterns: [
8
- `/node_modules/.pnpm/(?!(get-port|lande|toygrad)@)`,
9
- ],
10
- testTimeout: 60000,
11
- setupFiles: ['<rootDir>/../../jest.setup.ts'],
12
- moduleNameMapper: { '^(\\.\\.?\\/.+)\\.js$': ['$1.ts', '$1.js'] },
13
- }