@enbox/dids 0.0.2 → 0.0.4
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 +41 -1
- package/dist/browser.mjs +6 -10
- package/dist/browser.mjs.map +4 -4
- package/dist/esm/bearer-did.js +5 -5
- package/dist/esm/bearer-did.js.map +1 -1
- package/dist/esm/did.js +13 -6
- package/dist/esm/did.js.map +1 -1
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/methods/did-dht.js +34 -25
- package/dist/esm/methods/did-dht.js.map +1 -1
- package/dist/esm/methods/did-ion.js +9 -7
- package/dist/esm/methods/did-ion.js.map +1 -1
- package/dist/esm/methods/did-jwk.js +3 -3
- package/dist/esm/methods/did-jwk.js.map +1 -1
- package/dist/esm/methods/did-key.js +12 -240
- package/dist/esm/methods/did-key.js.map +1 -1
- package/dist/esm/methods/did-web.js +3 -2
- package/dist/esm/methods/did-web.js.map +1 -1
- package/dist/esm/resolver/resolver-cache-level.js +1 -1
- package/dist/esm/resolver/resolver-cache-level.js.map +1 -1
- package/dist/esm/resolver/resolver-cache-memory.js +77 -0
- package/dist/esm/resolver/resolver-cache-memory.js.map +1 -0
- package/dist/esm/resolver/resolver-cache-noop.js +10 -10
- package/dist/esm/resolver/resolver-cache-noop.js.map +1 -1
- package/dist/esm/resolver/universal-resolver.js +3 -3
- package/dist/esm/resolver/universal-resolver.js.map +1 -1
- package/dist/esm/utils.js +62 -21
- package/dist/esm/utils.js.map +1 -1
- package/dist/types/bearer-did.d.ts +6 -5
- package/dist/types/bearer-did.d.ts.map +1 -1
- package/dist/types/did.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/methods/did-dht.d.ts +6 -6
- package/dist/types/methods/did-dht.d.ts.map +1 -1
- package/dist/types/methods/did-ion.d.ts +6 -5
- package/dist/types/methods/did-ion.d.ts.map +1 -1
- package/dist/types/methods/did-jwk.d.ts +5 -5
- package/dist/types/methods/did-jwk.d.ts.map +1 -1
- package/dist/types/methods/did-key.d.ts +6 -55
- package/dist/types/methods/did-key.d.ts.map +1 -1
- package/dist/types/methods/did-method.d.ts +5 -5
- package/dist/types/methods/did-method.d.ts.map +1 -1
- package/dist/types/resolver/resolver-cache-level.d.ts.map +1 -1
- package/dist/types/resolver/resolver-cache-memory.d.ts +58 -0
- package/dist/types/resolver/resolver-cache-memory.d.ts.map +1 -0
- package/dist/types/resolver/universal-resolver.d.ts +2 -2
- package/dist/types/resolver/universal-resolver.d.ts.map +1 -1
- package/dist/types/types/did-core.d.ts +1 -1
- package/dist/types/types/did-core.d.ts.map +1 -1
- package/dist/types/utils.d.ts +27 -5
- package/dist/types/utils.d.ts.map +1 -1
- package/dist/utils.js +1 -5
- package/dist/utils.js.map +4 -4
- package/package.json +35 -47
- package/src/bearer-did.ts +15 -14
- package/src/did.ts +8 -6
- package/src/index.ts +2 -0
- package/src/methods/did-dht.ts +37 -37
- package/src/methods/did-ion.ts +23 -15
- package/src/methods/did-jwk.ts +9 -9
- package/src/methods/did-key.ts +29 -310
- package/src/methods/did-method.ts +6 -6
- package/src/methods/did-web.ts +2 -2
- package/src/resolver/resolver-cache-level.ts +4 -4
- package/src/resolver/resolver-cache-memory.ts +84 -0
- package/src/resolver/resolver-cache-noop.ts +10 -10
- package/src/resolver/universal-resolver.ts +5 -5
- package/src/types/did-core.ts +3 -3
- package/src/utils.ts +55 -26
- package/dist/browser.js +0 -77
- package/dist/browser.js.map +0 -7
- package/dist/cjs/index.js +0 -6303
- package/dist/cjs/index.js.map +0 -7
- package/dist/cjs/package.json +0 -1
- package/dist/cjs/utils.js +0 -245
- package/dist/cjs/utils.js.map +0 -7
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import ms from 'ms';
|
|
2
|
+
import { TtlCache } from '@enbox/common';
|
|
3
|
+
|
|
4
|
+
import type { DidResolutionResult } from '../types/did-core.js';
|
|
5
|
+
import type { DidResolverCache } from '../types/did-resolution.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Configuration parameters for creating an in-memory cache for DID resolution results.
|
|
9
|
+
*
|
|
10
|
+
* Allows customization of the cache time-to-live (TTL) setting.
|
|
11
|
+
*/
|
|
12
|
+
export type DidResolverCacheMemoryParams = {
|
|
13
|
+
/**
|
|
14
|
+
* Optional. The time-to-live for cache entries, expressed as a string (e.g., '1h', '15m').
|
|
15
|
+
* Determines how long a cache entry should remain valid before being considered expired.
|
|
16
|
+
*
|
|
17
|
+
* Defaults to '15m' if not specified.
|
|
18
|
+
*/
|
|
19
|
+
ttl?: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export class DidResolverCacheMemory implements DidResolverCache {
|
|
23
|
+
private cache: TtlCache<string, DidResolutionResult>;
|
|
24
|
+
|
|
25
|
+
constructor({ ttl = '15m' }: DidResolverCacheMemoryParams = {}) {
|
|
26
|
+
this.cache = new TtlCache({ ttl: ms(ttl) });
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Retrieves a DID resolution result from the cache.
|
|
31
|
+
*
|
|
32
|
+
* If the cached item has exceeded its TTL, it's scheduled for deletion and undefined is returned.
|
|
33
|
+
*
|
|
34
|
+
* @param didUri - The DID string used as the key for retrieving the cached result.
|
|
35
|
+
* @returns The cached DID resolution result or undefined if not found or expired.
|
|
36
|
+
*/
|
|
37
|
+
public async get(didUri: string): Promise<DidResolutionResult | void> {
|
|
38
|
+
if (!didUri) {
|
|
39
|
+
throw new Error('Key cannot be null or undefined');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return this.cache.get(didUri);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Stores a DID resolution result in the cache with a TTL.
|
|
47
|
+
*
|
|
48
|
+
* @param didUri - The DID string used as the key for storing the result.
|
|
49
|
+
* @param resolutionResult - The DID resolution result to be cached.
|
|
50
|
+
* @returns A promise that resolves when the operation is complete.
|
|
51
|
+
*/
|
|
52
|
+
public async set(didUri: string, resolutionResult: DidResolutionResult): Promise<void> {
|
|
53
|
+
this.cache.set(didUri, resolutionResult);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Deletes a DID resolution result from the cache.
|
|
58
|
+
*
|
|
59
|
+
* @param didUri - The DID string used as the key for deletion.
|
|
60
|
+
* @returns A promise that resolves when the operation is complete.
|
|
61
|
+
*/
|
|
62
|
+
public async delete(didUri: string): Promise<void> {
|
|
63
|
+
this.cache.delete(didUri);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Clears all entries from the cache.
|
|
68
|
+
*
|
|
69
|
+
* @returns A promise that resolves when the operation is complete.
|
|
70
|
+
*/
|
|
71
|
+
public async clear(): Promise<void> {
|
|
72
|
+
this.cache.clear();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* This method is a no-op but exists to be consistent with other DID Resolver Cache
|
|
77
|
+
* implementations.
|
|
78
|
+
*
|
|
79
|
+
* @returns A promise that resolves immediately.
|
|
80
|
+
*/
|
|
81
|
+
public async close(): Promise<void> {
|
|
82
|
+
// No-op since there is no underlying store to close.
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -8,19 +8,19 @@ import type { DidResolverCache } from '../types/did-resolution.js';
|
|
|
8
8
|
* potential for this library to be used in as many JS runtimes as possible.
|
|
9
9
|
*/
|
|
10
10
|
export const DidResolverCacheNoop: DidResolverCache = {
|
|
11
|
-
get
|
|
12
|
-
return
|
|
11
|
+
get(_key: string): Promise<DidResolutionResult | void> {
|
|
12
|
+
return Promise.resolve(undefined);
|
|
13
13
|
},
|
|
14
|
-
set
|
|
15
|
-
return
|
|
14
|
+
set(_key: string, _value: DidResolutionResult): Promise<void> {
|
|
15
|
+
return Promise.resolve();
|
|
16
16
|
},
|
|
17
|
-
delete
|
|
18
|
-
return
|
|
17
|
+
delete(_key: string): Promise<boolean | void> {
|
|
18
|
+
return Promise.resolve();
|
|
19
19
|
},
|
|
20
|
-
clear
|
|
21
|
-
return
|
|
20
|
+
clear(): Promise<void> {
|
|
21
|
+
return Promise.resolve();
|
|
22
22
|
},
|
|
23
|
-
close
|
|
24
|
-
return
|
|
23
|
+
close(): Promise<void> {
|
|
24
|
+
return Promise.resolve();
|
|
25
25
|
}
|
|
26
26
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { DidMethodResolver } from '../methods/did-method.js';
|
|
2
|
-
import type { DidResolver, DidResolverCache, DidUrlDereferencer } from '../types/did-resolution.js';
|
|
3
2
|
import type { DidDereferencingOptions, DidDereferencingResult, DidResolutionOptions, DidResolutionResult, DidResource } from '../types/did-core.js';
|
|
3
|
+
import type { DidResolver, DidResolverCache, DidUrlDereferencer } from '../types/did-resolution.js';
|
|
4
4
|
|
|
5
5
|
import { Did } from '../did.js';
|
|
6
6
|
import { DidErrorCode } from '../did-error.js';
|
|
@@ -33,7 +33,7 @@ export type UniversalResolverParams = {
|
|
|
33
33
|
* which effectively disables caching.
|
|
34
34
|
*/
|
|
35
35
|
cache?: DidResolverCache;
|
|
36
|
-
}
|
|
36
|
+
};
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
39
|
* The `DidResolver` class provides mechanisms for resolving Decentralized Identifiers (DIDs) to
|
|
@@ -153,7 +153,7 @@ export class UniversalResolver implements DidResolver, DidUrlDereferencer {
|
|
|
153
153
|
* More information on DID URL dereferencing can be found in the
|
|
154
154
|
* {@link https://www.w3.org/TR/did-core/#did-url-dereferencing | DID Core specification}.
|
|
155
155
|
*
|
|
156
|
-
* TODO: This is a partial implementation and does not fully implement DID URL dereferencing. (https://github.com/
|
|
156
|
+
* TODO: This is a partial implementation and does not fully implement DID URL dereferencing. (https://github.com/enboxorg/enbox/issues/387)
|
|
157
157
|
*
|
|
158
158
|
* @param didUrl - The DID URL string to dereference.
|
|
159
159
|
* @param [_options] - Input options to the dereference function. Optional.
|
|
@@ -206,7 +206,7 @@ export class UniversalResolver implements DidResolver, DidUrlDereferencer {
|
|
|
206
206
|
let didResource: DidResource | undefined;
|
|
207
207
|
|
|
208
208
|
// Find the first matching verification method in the DID document.
|
|
209
|
-
for (
|
|
209
|
+
for (const vm of verificationMethod) {
|
|
210
210
|
if (idSet.has(vm.id)) {
|
|
211
211
|
didResource = vm;
|
|
212
212
|
break;
|
|
@@ -214,7 +214,7 @@ export class UniversalResolver implements DidResolver, DidUrlDereferencer {
|
|
|
214
214
|
}
|
|
215
215
|
|
|
216
216
|
// Find the first matching service in the DID document.
|
|
217
|
-
for (
|
|
217
|
+
for (const svc of service) {
|
|
218
218
|
if (idSet.has(svc.id)) {
|
|
219
219
|
didResource = svc;
|
|
220
220
|
break;
|
package/src/types/did-core.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Jwk } from '@enbox/crypto';
|
|
1
|
+
import type { Jwk } from '@enbox/crypto';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Represents metadata related to the process of DID dereferencing.
|
|
@@ -33,7 +33,7 @@ export type DidDereferencingMetadata = {
|
|
|
33
33
|
|
|
34
34
|
// Additional output metadata generated during DID Resolution.
|
|
35
35
|
[key: string]: any;
|
|
36
|
-
}
|
|
36
|
+
};
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
39
|
* Represents the options that can be used during the process of DID dereferencing.
|
|
@@ -90,7 +90,7 @@ export type DidDereferencingResult = {
|
|
|
90
90
|
* dereferencing is unsuccessful, this output MUST be an empty metadata structure.
|
|
91
91
|
*/
|
|
92
92
|
contentMetadata: DidDocumentMetadata;
|
|
93
|
-
}
|
|
93
|
+
};
|
|
94
94
|
|
|
95
95
|
/**
|
|
96
96
|
* A set of data describing the Decentralized Identifierr (DID) subject.
|
package/src/utils.ts
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import type { Jwk } from '@enbox/crypto';
|
|
2
2
|
import type { RequireOnly } from '@enbox/common';
|
|
3
3
|
|
|
4
|
-
import { Convert, Multicodec } from '@enbox/common';
|
|
5
4
|
import { computeJwkThumbprint } from '@enbox/crypto';
|
|
5
|
+
import { Convert, Multicodec } from '@enbox/common';
|
|
6
6
|
|
|
7
7
|
import type { KeyWithMulticodec } from './types/multibase.js';
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
DidService,
|
|
8
|
+
import type { PortableDid } from './types/portable-did.js';
|
|
9
|
+
import type {
|
|
12
10
|
DidDocument,
|
|
11
|
+
DidService,
|
|
13
12
|
DidVerificationMethod,
|
|
14
|
-
DidVerificationRelationship,
|
|
15
13
|
} from './types/did-core.js';
|
|
16
14
|
|
|
15
|
+
import { DidVerificationRelationship } from './types/did-core.js';
|
|
16
|
+
import { DidError, DidErrorCode } from './did-error.js';
|
|
17
|
+
|
|
17
18
|
/**
|
|
18
19
|
* Represents a Decentralized Web Node (DWN) service in a DID Document.
|
|
19
20
|
*
|
|
@@ -30,7 +31,7 @@ import {
|
|
|
30
31
|
* const service: DwnDidService = {
|
|
31
32
|
* id: 'did:example:123#dwn',
|
|
32
33
|
* type: 'DecentralizedWebNode',
|
|
33
|
-
* serviceEndpoint: 'https://enbox-
|
|
34
|
+
* serviceEndpoint: 'https://enbox-dwn.fly.dev',
|
|
34
35
|
* enc: 'did:example:123#key-1',
|
|
35
36
|
* sig: 'did:example:123#key-2'
|
|
36
37
|
* }
|
|
@@ -76,8 +77,8 @@ export interface DwnDidService extends DidService {
|
|
|
76
77
|
* without a '#', and complex data structures.
|
|
77
78
|
*/
|
|
78
79
|
export function extractDidFragment(input: unknown): string | undefined {
|
|
79
|
-
if (typeof input !== 'string') return undefined;
|
|
80
|
-
if (input.length === 0) return undefined;
|
|
80
|
+
if (typeof input !== 'string') {return undefined;}
|
|
81
|
+
if (input.length === 0) {return undefined;}
|
|
81
82
|
return input.split('#').pop();
|
|
82
83
|
}
|
|
83
84
|
|
|
@@ -97,8 +98,10 @@ export function extractDidFragment(input: unknown): string | undefined {
|
|
|
97
98
|
*
|
|
98
99
|
* @param params - An object containing input parameters for retrieving services.
|
|
99
100
|
* @param params.didDocument - The DID document from which services are retrieved.
|
|
100
|
-
* @param params.id - Optional. A string representing the specific service ID to match. If provided,
|
|
101
|
-
*
|
|
101
|
+
* @param params.id - Optional. A string representing the specific service ID to match. If provided,
|
|
102
|
+
* only the service with this ID will be returned.
|
|
103
|
+
* @param params.type - Optional. A string representing the specific service type to match.
|
|
104
|
+
* If provided, only the service(s) of this type will be returned.
|
|
102
105
|
* @returns An array of services. If no matching service is found, an empty array is returned.
|
|
103
106
|
*/
|
|
104
107
|
export function getServices({ didDocument, id, type }: {
|
|
@@ -107,8 +110,8 @@ export function getServices({ didDocument, id, type }: {
|
|
|
107
110
|
type?: string;
|
|
108
111
|
}): DidService[] {
|
|
109
112
|
return didDocument?.service?.filter(service => {
|
|
110
|
-
if (id && service.id !== id) return false;
|
|
111
|
-
if (type && service.type !== type) return false;
|
|
113
|
+
if (id && service.id !== id) {return false;}
|
|
114
|
+
if (type && service.type !== type) {return false;}
|
|
112
115
|
return true;
|
|
113
116
|
}) ?? [];
|
|
114
117
|
}
|
|
@@ -150,7 +153,7 @@ export async function getVerificationMethodByKey({ didDocument, publicKeyJwk, pu
|
|
|
150
153
|
// Collect all verification methods from the DID document.
|
|
151
154
|
const verificationMethods = getVerificationMethods({ didDocument });
|
|
152
155
|
|
|
153
|
-
for (
|
|
156
|
+
for (const method of verificationMethods) {
|
|
154
157
|
if (publicKeyJwk && method.publicKeyJwk) {
|
|
155
158
|
const publicKeyThumbprint = await computeJwkThumbprint({ jwk: publicKeyJwk });
|
|
156
159
|
if (publicKeyThumbprint === await computeJwkThumbprint({ jwk: method.publicKeyJwk })) {
|
|
@@ -191,7 +194,7 @@ export async function getVerificationMethodByKey({ didDocument, publicKeyJwk, pu
|
|
|
191
194
|
export function getVerificationMethods({ didDocument }: {
|
|
192
195
|
didDocument: DidDocument;
|
|
193
196
|
}): DidVerificationMethod[] {
|
|
194
|
-
if (!didDocument) throw new TypeError(`Required parameter missing: 'didDocument'`);
|
|
197
|
+
if (!didDocument) {throw new TypeError(`Required parameter missing: 'didDocument'`);}
|
|
195
198
|
|
|
196
199
|
const verificationMethods: DidVerificationMethod[] = [];
|
|
197
200
|
|
|
@@ -356,7 +359,7 @@ export function getVerificationRelationshipsById({ didDocument, methodId }: {
|
|
|
356
359
|
*/
|
|
357
360
|
export function isDidService(obj: unknown): obj is DidService {
|
|
358
361
|
// Validate that the given value is an object.
|
|
359
|
-
if (!obj || typeof obj !== 'object' || obj === null) return false;
|
|
362
|
+
if (!obj || typeof obj !== 'object' || obj === null) {return false;}
|
|
360
363
|
|
|
361
364
|
// Validate that the object has the necessary properties of DidService.
|
|
362
365
|
return 'id' in obj && 'type' in obj && 'serviceEndpoint' in obj;
|
|
@@ -391,7 +394,7 @@ export function isDidService(obj: unknown): obj is DidService {
|
|
|
391
394
|
* {
|
|
392
395
|
* id: 'did:example:123#dwn',
|
|
393
396
|
* type: 'DecentralizedWebNode',
|
|
394
|
-
* serviceEndpoint: 'https://enbox-
|
|
397
|
+
* serviceEndpoint: 'https://enbox-dwn.fly.dev',
|
|
395
398
|
* enc: 'did:example:123#key-1',
|
|
396
399
|
* sig: 'did:example:123#key-2'
|
|
397
400
|
* }
|
|
@@ -412,13 +415,13 @@ export function isDidService(obj: unknown): obj is DidService {
|
|
|
412
415
|
*/
|
|
413
416
|
export function isDwnDidService(obj: unknown): obj is DwnDidService {
|
|
414
417
|
// Validate that the given value is a {@link DidService}.
|
|
415
|
-
if (!isDidService(obj)) return false;
|
|
418
|
+
if (!isDidService(obj)) {return false;}
|
|
416
419
|
|
|
417
420
|
// Validate that the `type` property is `DecentralizedWebNode`.
|
|
418
|
-
if (obj.type !== 'DecentralizedWebNode') return false;
|
|
421
|
+
if (obj.type !== 'DecentralizedWebNode') {return false;}
|
|
419
422
|
|
|
420
423
|
// Validate that the given object has the `enc` and `sig` properties.
|
|
421
|
-
if (!('enc' in obj && 'sig' in obj)) return false;
|
|
424
|
+
if (!('enc' in obj && 'sig' in obj)) {return false;}
|
|
422
425
|
|
|
423
426
|
// Validate that the `enc` and `sig` properties are either strings or arrays of strings.
|
|
424
427
|
const isStringOrStringArray = (prop: any): boolean =>
|
|
@@ -453,18 +456,44 @@ export function isDwnDidService(obj: unknown): obj is DwnDidService {
|
|
|
453
456
|
*/
|
|
454
457
|
export function isDidVerificationMethod(obj: unknown): obj is DidVerificationMethod {
|
|
455
458
|
// Validate that the given value is an object.
|
|
456
|
-
if (!obj || typeof obj !== 'object' || obj === null) return false;
|
|
459
|
+
if (!obj || typeof obj !== 'object' || obj === null) {return false;}
|
|
457
460
|
|
|
458
461
|
// Validate that the object has the necessary properties of a DidVerificationMethod.
|
|
459
|
-
if (!('id' in obj && 'type' in obj && 'controller' in obj)) return false;
|
|
462
|
+
if (!('id' in obj && 'type' in obj && 'controller' in obj)) {return false;}
|
|
460
463
|
|
|
461
|
-
if (typeof obj.id !== 'string') return false;
|
|
462
|
-
if (typeof obj.type !== 'string') return false;
|
|
463
|
-
if (typeof obj.controller !== 'string') return false;
|
|
464
|
+
if (typeof obj.id !== 'string') {return false;}
|
|
465
|
+
if (typeof obj.type !== 'string') {return false;}
|
|
466
|
+
if (typeof obj.controller !== 'string') {return false;}
|
|
464
467
|
|
|
465
468
|
return true;
|
|
466
469
|
}
|
|
467
470
|
|
|
471
|
+
/**
|
|
472
|
+
* Checks if a given object conforms to the {@link PortableDid} interface.
|
|
473
|
+
*
|
|
474
|
+
* A `PortableDid` is an object with `uri`, `document`, and `metadata` properties that does not
|
|
475
|
+
* have a `keyManager` property (or has it set to `undefined`). This distinguishes it from a
|
|
476
|
+
* {@link BearerDid}, which includes a `keyManager`.
|
|
477
|
+
*
|
|
478
|
+
* @example
|
|
479
|
+
* ```ts
|
|
480
|
+
* if (isPortableDid(obj)) {
|
|
481
|
+
* console.log('The object is a PortableDid');
|
|
482
|
+
* }
|
|
483
|
+
* ```
|
|
484
|
+
*
|
|
485
|
+
* @param obj - The object to be checked.
|
|
486
|
+
* @returns `true` if `obj` is a `PortableDid`; otherwise, `false`.
|
|
487
|
+
*/
|
|
488
|
+
export function isPortableDid(obj: unknown): obj is PortableDid {
|
|
489
|
+
// Validate that the given value is an object that has the necessary properties of PortableDid.
|
|
490
|
+
return !(!obj || typeof obj !== 'object' || obj === null)
|
|
491
|
+
&& 'uri' in obj
|
|
492
|
+
&& 'document' in obj
|
|
493
|
+
&& 'metadata' in obj
|
|
494
|
+
&& (!('keyManager' in obj) || obj.keyManager === undefined);
|
|
495
|
+
}
|
|
496
|
+
|
|
468
497
|
/**
|
|
469
498
|
* Converts a cryptographic key to a multibase identifier.
|
|
470
499
|
*
|
|
@@ -526,7 +555,7 @@ export function multibaseIdToKeyBytes({ multibaseKeyId }: {
|
|
|
526
555
|
const { code, data, name } = Multicodec.removePrefix({ prefixedData: prefixedKey });
|
|
527
556
|
|
|
528
557
|
return { keyBytes: data, multicodecCode: code, multicodecName: name };
|
|
529
|
-
} catch
|
|
558
|
+
} catch {
|
|
530
559
|
throw new DidError(DidErrorCode.InvalidDid, `Invalid multibase identifier: ${multibaseKeyId}`);
|
|
531
560
|
}
|
|
532
561
|
}
|