@sphereon/ssi-sdk-ext.did-resolver-ebsi 0.15.0 → 0.15.1-next.13
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/drivers/ebsi-v1.d.ts +11 -2
- package/dist/drivers/ebsi-v1.d.ts.map +1 -1
- package/dist/drivers/ebsi-v1.js +51 -16
- package/dist/drivers/ebsi-v1.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/ebsi_resolver.test.ts +12 -2
- package/src/drivers/ebsi-v1.ts +59 -15
- package/src/index.ts +2 -1
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
import { DIDDocument, DIDResolutionOptions } from 'did-resolver';
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const EBSI_TEST_REGISTRY = "https://api-test.ebsi.eu/did-registry/v4/identifiers";
|
|
3
|
+
export declare const EBSI_PILOT_REGISTRY = "https://api-pilot.ebsi.eu/did-registry/v4";
|
|
4
|
+
export declare const EBSI_CONFORMANCE_REGISTRY = "https://api-conformance.ebsi.eu/did-registry/v4/identifiers";
|
|
5
|
+
type EBSIResolutionOptions = DIDResolutionOptions & {
|
|
6
|
+
noFallbackRegistries?: boolean;
|
|
7
|
+
noEnvVarRegistry?: boolean;
|
|
8
|
+
registries?: string[];
|
|
9
|
+
registry?: string;
|
|
10
|
+
};
|
|
11
|
+
export declare const keyToDidDoc: (did: string, contentType: string, options: EBSIResolutionOptions) => Promise<DIDDocument>;
|
|
3
12
|
declare const _default: {
|
|
4
|
-
keyToDidDoc: (did: string, contentType: string, options:
|
|
13
|
+
keyToDidDoc: (did: string, contentType: string, options: EBSIResolutionOptions) => Promise<DIDDocument>;
|
|
5
14
|
};
|
|
6
15
|
export default _default;
|
|
7
16
|
//# sourceMappingURL=ebsi-v1.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ebsi-v1.d.ts","sourceRoot":"","sources":["../../src/drivers/ebsi-v1.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAGhE,eAAO,MAAM,WAAW,QAAe,MAAM,eAAe,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"ebsi-v1.d.ts","sourceRoot":"","sources":["../../src/drivers/ebsi-v1.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAGhE,eAAO,MAAM,kBAAkB,yDAAyD,CAAA;AACxF,eAAO,MAAM,mBAAmB,8CAA8C,CAAA;AAC9E,eAAO,MAAM,yBAAyB,gEAAgE,CAAA;AAEtG,KAAK,qBAAqB,GAAG,oBAAoB,GAAG;IAClD,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAC9B,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,CAAA;AACD,eAAO,MAAM,WAAW,QAAe,MAAM,eAAe,MAAM,WAAW,qBAAqB,KAAG,QAAQ,WAAW,CAavH,CAAA;;;;AA4CD,wBAA8B"}
|
package/dist/drivers/ebsi-v1.js
CHANGED
|
@@ -9,30 +9,65 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.keyToDidDoc = void 0;
|
|
12
|
+
exports.keyToDidDoc = exports.EBSI_CONFORMANCE_REGISTRY = exports.EBSI_PILOT_REGISTRY = exports.EBSI_TEST_REGISTRY = void 0;
|
|
13
13
|
const cross_fetch_1 = require("cross-fetch");
|
|
14
|
+
exports.EBSI_TEST_REGISTRY = 'https://api-test.ebsi.eu/did-registry/v4/identifiers';
|
|
15
|
+
exports.EBSI_PILOT_REGISTRY = 'https://api-pilot.ebsi.eu/did-registry/v4';
|
|
16
|
+
exports.EBSI_CONFORMANCE_REGISTRY = 'https://api-conformance.ebsi.eu/did-registry/v4/identifiers';
|
|
14
17
|
const keyToDidDoc = (did, contentType, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
+
const registries = determineRegistries(options);
|
|
19
|
+
for (const registry of registries) {
|
|
20
|
+
try {
|
|
21
|
+
const didDocument = yield keyToDidDocImpl(did, contentType, registry, options);
|
|
22
|
+
if (didDocument && !('error' in didDocument)) {
|
|
23
|
+
return didDocument;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
console.log(error);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return Promise.reject(new Error(`Could not resolve DID ${did} using registries: ${JSON.stringify(registries)}`));
|
|
18
31
|
});
|
|
19
32
|
exports.keyToDidDoc = keyToDidDoc;
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
33
|
+
const keyToDidDocImpl = (did, contentType, registry, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
+
const uri = didURI(did, registry);
|
|
35
|
+
const response = yield (0, cross_fetch_1.fetch)(uri);
|
|
36
|
+
if (response.status >= 400) {
|
|
37
|
+
throw Error(yield response.json());
|
|
38
|
+
}
|
|
39
|
+
return (yield response.json());
|
|
40
|
+
});
|
|
41
|
+
const didURI = (did, registry) => {
|
|
42
|
+
let uri = registry;
|
|
43
|
+
if (uri.endsWith('/')) {
|
|
44
|
+
uri = uri.substring(0, uri.length - 1);
|
|
24
45
|
}
|
|
25
|
-
if (!
|
|
26
|
-
|
|
46
|
+
if (!uri.includes('identifiers')) {
|
|
47
|
+
uri += '/identifiers';
|
|
27
48
|
}
|
|
28
|
-
return `${
|
|
49
|
+
return `${uri}/${did}`;
|
|
29
50
|
};
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
if (options.
|
|
33
|
-
|
|
51
|
+
const determineRegistries = (options) => {
|
|
52
|
+
let registries = new Set();
|
|
53
|
+
if (options.registries && Array.isArray(options.registries) && options.registries.length > 0) {
|
|
54
|
+
options.registries.forEach(registries.add);
|
|
55
|
+
}
|
|
56
|
+
if (options.registry) {
|
|
57
|
+
registries.add(options.registry);
|
|
58
|
+
}
|
|
59
|
+
if (options.noEnvVarRegistry !== true && process.env.EBSI_DEFAULT_REGISTRY) {
|
|
60
|
+
registries.add(process.env.EBSI_DEFAULT_REGISTRY);
|
|
61
|
+
}
|
|
62
|
+
if (options.noFallbackRegistries !== true) {
|
|
63
|
+
registries.add(exports.EBSI_PILOT_REGISTRY);
|
|
64
|
+
registries.add(exports.EBSI_CONFORMANCE_REGISTRY);
|
|
65
|
+
registries.add(exports.EBSI_TEST_REGISTRY);
|
|
66
|
+
}
|
|
67
|
+
if (registries.size === 0) {
|
|
68
|
+
throw Error('Please provide a registry as an option, a fallback registry or use an environment variable (EBSI_DEFAULT_REGISTRY)');
|
|
34
69
|
}
|
|
35
|
-
return (
|
|
70
|
+
return Array.from(registries);
|
|
36
71
|
};
|
|
37
72
|
exports.default = { keyToDidDoc: exports.keyToDidDoc };
|
|
38
73
|
//# sourceMappingURL=ebsi-v1.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ebsi-v1.js","sourceRoot":"","sources":["../../src/drivers/ebsi-v1.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,6CAAmC;
|
|
1
|
+
{"version":3,"file":"ebsi-v1.js","sourceRoot":"","sources":["../../src/drivers/ebsi-v1.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,6CAAmC;AAEtB,QAAA,kBAAkB,GAAG,sDAAsD,CAAA;AAC3E,QAAA,mBAAmB,GAAG,2CAA2C,CAAA;AACjE,QAAA,yBAAyB,GAAG,6DAA6D,CAAA;AAQ/F,MAAM,WAAW,GAAG,CAAO,GAAW,E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EAAX,mBAAW,EAAE,CAAA"}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAoE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAKjH,eAAO,MAAM,WAAW,4BAA4B,CAAA;AACpD,eAAO,MAAM,QAAQ,yBAAyB,CAAA;AAK9C,eAAO,MAAM,WAAW,QAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAoE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAKjH,eAAO,MAAM,WAAW,4BAA4B,CAAA;AACpD,eAAO,MAAM,QAAQ,yBAAyB,CAAA;AAK9C,eAAO,MAAM,WAAW,QAAO,gBA0C9B,CAAA;;;;AASD,wBAA8B"}
|
package/dist/index.js
CHANGED
|
@@ -52,7 +52,8 @@ const getResolver = () => {
|
|
|
52
52
|
try {
|
|
53
53
|
const contentType = determineContentType(options);
|
|
54
54
|
response.didResolutionMetadata.contentType = contentType;
|
|
55
|
-
const
|
|
55
|
+
const driver = methodToDriverMap[parsed.method];
|
|
56
|
+
const doc = yield driver.keyToDidDoc(did, contentType, options);
|
|
56
57
|
switch (contentType) {
|
|
57
58
|
case exports.DID_LD_JSON:
|
|
58
59
|
if (!doc['@context']) {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAA2C;AAG3C,mCAA+B;AAE/B,IAAA,eAAM,GAAE,CAAA;AACK,QAAA,WAAW,GAAG,yBAAyB,CAAA;AACvC,QAAA,QAAQ,GAAG,sBAAsB,CAAA;AAC9C,MAAM,iBAAiB,GAAQ;IAC7B,IAAI,EAAE,MAAM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Q,QAAQ,mBAAW,6BAA6B,WAAW,EAAE,CAAC,CAAA;KAC3F;IACD,OAAO,WAAW,CAAA;AACpB,CAAC,CAAA;AACD,kBAAe,EAAE,WAAW,EAAX,mBAAW,EAAE,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sphereon/ssi-sdk-ext.did-resolver-ebsi",
|
|
3
3
|
"description": "Sphereon did:ebsi resolver for Legal Entities.",
|
|
4
|
-
"version": "0.15.
|
|
4
|
+
"version": "0.15.1-next.13+6d1359c",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"secp256r1",
|
|
44
44
|
"RSA"
|
|
45
45
|
],
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "6d1359c17ffff07e66252c65af729505d533777b"
|
|
47
47
|
}
|
|
@@ -18,6 +18,15 @@ describe('@sphereon/ssi-sdk-ext.did-resolver-ebsi', () => {
|
|
|
18
18
|
})
|
|
19
19
|
expect(resolutionResult.didDocument).toEqual(JSON.parse(fs.readFileSync(`${__dirname}/fixtures/ebsiv1_did_doc.json`, { encoding: 'utf-8' })))
|
|
20
20
|
})
|
|
21
|
+
it('should resolve conformance DID did:ebsi trying all registries', async () => {
|
|
22
|
+
const resolver = new Resolver({ ...getResolver() })
|
|
23
|
+
const resolutionResult = await resolver.resolve('did:ebsi:zhJARjPN69cEtgPxHen1Mid', {
|
|
24
|
+
accept: DID_LD_JSON,
|
|
25
|
+
})
|
|
26
|
+
expect(resolutionResult.didDocument).toMatchObject({
|
|
27
|
+
'@context': ['https://www.w3.org/ns/did/v1', 'https://w3id.org/security/suites/jws-2020/v1'],
|
|
28
|
+
})
|
|
29
|
+
})
|
|
21
30
|
|
|
22
31
|
it('should not resolve a v1 did:ebsi against a non-existing registry', async () => {
|
|
23
32
|
const resolver = new Resolver({ ...getResolver() })
|
|
@@ -25,6 +34,8 @@ describe('@sphereon/ssi-sdk-ext.did-resolver-ebsi', () => {
|
|
|
25
34
|
resolver.resolve('did:ebsi:z25gUx2D5Ujb6eZcmQEnertx#5jOg2ai976NEo_UKDCDHqDzO1vBx2RQJ_9ZuyZLqSCs', {
|
|
26
35
|
accept: DID_LD_JSON,
|
|
27
36
|
registry: 'http://127.0.0.1:9993',
|
|
37
|
+
noFallbackRegistries: true,
|
|
38
|
+
noEnvVarRegistry: true,
|
|
28
39
|
})
|
|
29
40
|
).resolves.toEqual({
|
|
30
41
|
didDocument: null,
|
|
@@ -32,8 +43,7 @@ describe('@sphereon/ssi-sdk-ext.did-resolver-ebsi', () => {
|
|
|
32
43
|
didResolutionMetadata: {
|
|
33
44
|
contentType: 'application/did+ld+json',
|
|
34
45
|
error: 'invalidDid',
|
|
35
|
-
message:
|
|
36
|
-
'FetchError: request to http://127.0.0.1:9993/identifiers/did:ebsi:z25gUx2D5Ujb6eZcmQEnertx failed, reason: connect ECONNREFUSED 127.0.0.1:9993',
|
|
46
|
+
message: 'Error: Could not resolve DID did:ebsi:z25gUx2D5Ujb6eZcmQEnertx using registries: ["http://127.0.0.1:9993"]',
|
|
37
47
|
},
|
|
38
48
|
})
|
|
39
49
|
})
|
package/src/drivers/ebsi-v1.ts
CHANGED
|
@@ -1,27 +1,71 @@
|
|
|
1
1
|
import { DIDDocument, DIDResolutionOptions } from 'did-resolver'
|
|
2
2
|
import { fetch } from 'cross-fetch'
|
|
3
3
|
|
|
4
|
-
export const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
export const EBSI_TEST_REGISTRY = 'https://api-test.ebsi.eu/did-registry/v4/identifiers'
|
|
5
|
+
export const EBSI_PILOT_REGISTRY = 'https://api-pilot.ebsi.eu/did-registry/v4'
|
|
6
|
+
export const EBSI_CONFORMANCE_REGISTRY = 'https://api-conformance.ebsi.eu/did-registry/v4/identifiers'
|
|
7
|
+
|
|
8
|
+
type EBSIResolutionOptions = DIDResolutionOptions & {
|
|
9
|
+
noFallbackRegistries?: boolean
|
|
10
|
+
noEnvVarRegistry?: boolean
|
|
11
|
+
registries?: string[]
|
|
12
|
+
registry?: string
|
|
13
|
+
}
|
|
14
|
+
export const keyToDidDoc = async (did: string, contentType: string, options: EBSIResolutionOptions): Promise<DIDDocument> => {
|
|
15
|
+
const registries = determineRegistries(options)
|
|
16
|
+
for (const registry of registries) {
|
|
17
|
+
try {
|
|
18
|
+
const didDocument = await keyToDidDocImpl(did, contentType, registry, options)
|
|
19
|
+
if (didDocument && !('error' in didDocument)) {
|
|
20
|
+
return didDocument
|
|
21
|
+
}
|
|
22
|
+
} catch (error: unknown) {
|
|
23
|
+
console.log(error)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return Promise.reject(new Error(`Could not resolve DID ${did} using registries: ${JSON.stringify(registries)}`))
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const keyToDidDocImpl = async (did: string, contentType: string, registry: string, options: DIDResolutionOptions): Promise<DIDDocument> => {
|
|
30
|
+
const uri = didURI(did, registry)
|
|
31
|
+
const response = await fetch(uri)
|
|
32
|
+
if (response.status >= 400) {
|
|
33
|
+
throw Error(await response.json())
|
|
34
|
+
}
|
|
35
|
+
return (await response.json()) as DIDDocument
|
|
8
36
|
}
|
|
9
37
|
|
|
10
|
-
const didURI = (did: string,
|
|
11
|
-
let
|
|
12
|
-
if (
|
|
13
|
-
|
|
38
|
+
const didURI = (did: string, registry: string) => {
|
|
39
|
+
let uri = registry
|
|
40
|
+
if (uri.endsWith('/')) {
|
|
41
|
+
uri = uri.substring(0, uri.length - 1)
|
|
14
42
|
}
|
|
15
|
-
if (!
|
|
16
|
-
|
|
43
|
+
if (!uri.includes('identifiers')) {
|
|
44
|
+
uri += '/identifiers'
|
|
17
45
|
}
|
|
18
|
-
return `${
|
|
46
|
+
return `${uri}/${did}`
|
|
19
47
|
}
|
|
20
48
|
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
49
|
+
const determineRegistries = (options: EBSIResolutionOptions): string[] => {
|
|
50
|
+
let registries = new Set<string>()
|
|
51
|
+
if (options.registries && Array.isArray(options.registries) && options.registries.length > 0) {
|
|
52
|
+
options.registries.forEach(registries.add)
|
|
24
53
|
}
|
|
25
|
-
|
|
54
|
+
if (options.registry) {
|
|
55
|
+
registries.add(options.registry)
|
|
56
|
+
}
|
|
57
|
+
if (options.noEnvVarRegistry !== true && process.env.EBSI_DEFAULT_REGISTRY) {
|
|
58
|
+
registries.add(process.env.EBSI_DEFAULT_REGISTRY)
|
|
59
|
+
}
|
|
60
|
+
if (options.noFallbackRegistries !== true) {
|
|
61
|
+
registries.add(EBSI_PILOT_REGISTRY)
|
|
62
|
+
registries.add(EBSI_CONFORMANCE_REGISTRY)
|
|
63
|
+
registries.add(EBSI_TEST_REGISTRY)
|
|
64
|
+
}
|
|
65
|
+
if (registries.size === 0) {
|
|
66
|
+
throw Error('Please provide a registry as an option, a fallback registry or use an environment variable (EBSI_DEFAULT_REGISTRY)')
|
|
67
|
+
}
|
|
68
|
+
return Array.from(registries)
|
|
26
69
|
}
|
|
70
|
+
|
|
27
71
|
export default { keyToDidDoc }
|
package/src/index.ts
CHANGED
|
@@ -22,7 +22,8 @@ export const getResolver = (): ResolverRegistry => {
|
|
|
22
22
|
try {
|
|
23
23
|
const contentType = determineContentType(options)
|
|
24
24
|
response.didResolutionMetadata.contentType = contentType
|
|
25
|
-
const
|
|
25
|
+
const driver = methodToDriverMap[parsed.method]
|
|
26
|
+
const doc = await driver.keyToDidDoc(did, contentType, options)
|
|
26
27
|
switch (contentType) {
|
|
27
28
|
case DID_LD_JSON:
|
|
28
29
|
if (!doc['@context']) {
|