@interop/did-web-resolver 2.2.1 → 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.
- package/dist/DidWebResolver.js +21 -7
- package/package.json +1 -1
- package/src/DidWebResolver.js +21 -7
package/dist/DidWebResolver.js
CHANGED
|
@@ -60,10 +60,21 @@ function didFromUrl ({ url } = {}) {
|
|
|
60
60
|
throw new TypeError(`Invalid url: "${url}".`)
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
let { host, pathname } = parsedUrl;
|
|
65
64
|
let pathComponent = '';
|
|
66
|
-
|
|
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
|
|
|
@@ -83,7 +94,11 @@ function urlFromDid ({ did } = {}) {
|
|
|
83
94
|
// const [didResource, query] = didUrl.split('?')
|
|
84
95
|
|
|
85
96
|
// eslint-disable-next-line no-unused-vars
|
|
86
|
-
const [_did, _web, urlNoProtocol] = didUrl.split(':');
|
|
97
|
+
const [_did, _web, urlNoProtocol, ...pathFragments] = didUrl.split(':');
|
|
98
|
+
|
|
99
|
+
if (urlNoProtocol.includes('/')) {
|
|
100
|
+
throw new TypeError(`Cannot construct url from did: "${did}". domain-name cannot contain a path.`)
|
|
101
|
+
}
|
|
87
102
|
|
|
88
103
|
let parsedUrl;
|
|
89
104
|
try {
|
|
@@ -94,11 +109,10 @@ function urlFromDid ({ did } = {}) {
|
|
|
94
109
|
throw new TypeError(`Cannot construct url from did: "${did}".`)
|
|
95
110
|
}
|
|
96
111
|
|
|
97
|
-
if (
|
|
112
|
+
if (pathFragments.length === 0) {
|
|
98
113
|
parsedUrl.pathname = '/.well-known/did.json';
|
|
99
114
|
} else {
|
|
100
|
-
|
|
101
|
-
parsedUrl.pathname = pathFragments.map(decodeURIComponent).join('/');
|
|
115
|
+
parsedUrl.pathname = pathFragments.map(decodeURIComponent).join('/') + '/did.json';
|
|
102
116
|
}
|
|
103
117
|
|
|
104
118
|
if (hashFragment) {
|
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": "
|
|
4
|
+
"version": "3.0.1",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Dmitri Zagidulin",
|
|
7
7
|
"url": "https://github.com/dmitrizagidulin/"
|
package/src/DidWebResolver.js
CHANGED
|
@@ -31,10 +31,21 @@ export function didFromUrl ({ url } = {}) {
|
|
|
31
31
|
throw new TypeError(`Invalid url: "${url}".`)
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
let { host, pathname } = parsedUrl
|
|
36
35
|
let pathComponent = ''
|
|
37
|
-
|
|
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
|
|
|
@@ -54,7 +65,11 @@ export function urlFromDid ({ did } = {}) {
|
|
|
54
65
|
// const [didResource, query] = didUrl.split('?')
|
|
55
66
|
|
|
56
67
|
// eslint-disable-next-line no-unused-vars
|
|
57
|
-
const [_did, _web, urlNoProtocol] = didUrl.split(':')
|
|
68
|
+
const [_did, _web, urlNoProtocol, ...pathFragments] = didUrl.split(':')
|
|
69
|
+
|
|
70
|
+
if (urlNoProtocol.includes('/')) {
|
|
71
|
+
throw new TypeError(`Cannot construct url from did: "${did}". domain-name cannot contain a path.`)
|
|
72
|
+
}
|
|
58
73
|
|
|
59
74
|
let parsedUrl
|
|
60
75
|
try {
|
|
@@ -65,11 +80,10 @@ export function urlFromDid ({ did } = {}) {
|
|
|
65
80
|
throw new TypeError(`Cannot construct url from did: "${did}".`)
|
|
66
81
|
}
|
|
67
82
|
|
|
68
|
-
if (
|
|
83
|
+
if (pathFragments.length === 0) {
|
|
69
84
|
parsedUrl.pathname = '/.well-known/did.json'
|
|
70
85
|
} else {
|
|
71
|
-
|
|
72
|
-
parsedUrl.pathname = pathFragments.map(decodeURIComponent).join('/')
|
|
86
|
+
parsedUrl.pathname = pathFragments.map(decodeURIComponent).join('/') + '/did.json'
|
|
73
87
|
}
|
|
74
88
|
|
|
75
89
|
if (hashFragment) {
|