@interop/did-web-resolver 3.0.0 → 3.0.1

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.
@@ -60,10 +60,21 @@ function didFromUrl ({ url } = {}) {
60
60
  throw new TypeError(`Invalid url: "${url}".`)
61
61
  }
62
62
 
63
- const { host, pathname } = parsedUrl;
64
-
63
+ let { host, pathname } = parsedUrl;
65
64
  let pathComponent = '';
66
- if (pathname && pathname !== '/' && pathname !== '/.well-known/did.json') {
65
+
66
+ const didJsonSuffix = '/did.json';
67
+ const wellKnownSuffix = '/.well-known';
68
+
69
+ if (pathname && pathname.endsWith(didJsonSuffix)) {
70
+ pathname = pathname.substring(0, pathname.length - didJsonSuffix.length);
71
+ }
72
+
73
+ if (pathname && pathname.endsWith(wellKnownSuffix)) {
74
+ pathname = pathname.substring(0, pathname.length - wellKnownSuffix.length);
75
+ }
76
+
77
+ if (pathname && pathname !== '/') {
67
78
  pathComponent = pathname.split('/').map(encodeURIComponent).join(':');
68
79
  }
69
80
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@interop/did-web-resolver",
3
3
  "description": "A did:web method Decentralized Identifier (DID) resolver for the did-io library.",
4
- "version": "3.0.0",
4
+ "version": "3.0.1",
5
5
  "author": {
6
6
  "name": "Dmitri Zagidulin",
7
7
  "url": "https://github.com/dmitrizagidulin/"
@@ -31,10 +31,21 @@ export function didFromUrl ({ url } = {}) {
31
31
  throw new TypeError(`Invalid url: "${url}".`)
32
32
  }
33
33
 
34
- const { host, pathname } = parsedUrl
35
-
34
+ let { host, pathname } = parsedUrl
36
35
  let pathComponent = ''
37
- if (pathname && pathname !== '/' && pathname !== '/.well-known/did.json') {
36
+
37
+ const didJsonSuffix = '/did.json'
38
+ const wellKnownSuffix = '/.well-known'
39
+
40
+ if (pathname && pathname.endsWith(didJsonSuffix)) {
41
+ pathname = pathname.substring(0, pathname.length - didJsonSuffix.length)
42
+ }
43
+
44
+ if (pathname && pathname.endsWith(wellKnownSuffix)) {
45
+ pathname = pathname.substring(0, pathname.length - wellKnownSuffix.length)
46
+ }
47
+
48
+ if (pathname && pathname !== '/') {
38
49
  pathComponent = pathname.split('/').map(encodeURIComponent).join(':')
39
50
  }
40
51