@enbox/dids 0.0.1 → 0.0.3
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.js +6 -10
- package/dist/browser.js.map +4 -4
- 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/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-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 +37 -21
- package/dist/esm/utils.js.map +1 -1
- package/dist/types/bearer-did.d.ts +3 -2
- package/dist/types/bearer-did.d.ts.map +1 -1
- package/dist/types/did.d.ts.map +1 -1
- package/dist/types/methods/did-dht.d.ts +4 -4
- package/dist/types/methods/did-dht.d.ts.map +1 -1
- package/dist/types/methods/did-ion.d.ts +3 -2
- package/dist/types/methods/did-ion.d.ts.map +1 -1
- package/dist/types/methods/did-jwk.d.ts +2 -2
- package/dist/types/methods/did-jwk.d.ts.map +1 -1
- package/dist/types/methods/did-key.d.ts +3 -52
- package/dist/types/methods/did-key.d.ts.map +1 -1
- package/dist/types/methods/did-method.d.ts +3 -3
- 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/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 +8 -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 +24 -34
- package/src/bearer-did.ts +12 -11
- package/src/did.ts +8 -6
- package/src/methods/did-dht.ts +35 -35
- package/src/methods/did-ion.ts +12 -11
- package/src/methods/did-jwk.ts +6 -6
- package/src/methods/did-key.ts +24 -305
- package/src/methods/did-method.ts +3 -3
- package/src/methods/did-web.ts +2 -2
- package/src/resolver/resolver-cache-level.ts +4 -4
- 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 +28 -26
- 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
package/src/utils.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
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 { DidError, DidErrorCode } from './did-error.js';
|
|
10
|
-
import {
|
|
11
|
-
DidService,
|
|
8
|
+
import type {
|
|
12
9
|
DidDocument,
|
|
10
|
+
DidService,
|
|
13
11
|
DidVerificationMethod,
|
|
14
|
-
DidVerificationRelationship,
|
|
15
12
|
} from './types/did-core.js';
|
|
16
13
|
|
|
14
|
+
import { DidVerificationRelationship } from './types/did-core.js';
|
|
15
|
+
import { DidError, DidErrorCode } from './did-error.js';
|
|
16
|
+
|
|
17
17
|
/**
|
|
18
18
|
* Represents a Decentralized Web Node (DWN) service in a DID Document.
|
|
19
19
|
*
|
|
@@ -30,7 +30,7 @@ import {
|
|
|
30
30
|
* const service: DwnDidService = {
|
|
31
31
|
* id: 'did:example:123#dwn',
|
|
32
32
|
* type: 'DecentralizedWebNode',
|
|
33
|
-
* serviceEndpoint: 'https://enbox-
|
|
33
|
+
* serviceEndpoint: 'https://enbox-dwn.fly.dev',
|
|
34
34
|
* enc: 'did:example:123#key-1',
|
|
35
35
|
* sig: 'did:example:123#key-2'
|
|
36
36
|
* }
|
|
@@ -76,8 +76,8 @@ export interface DwnDidService extends DidService {
|
|
|
76
76
|
* without a '#', and complex data structures.
|
|
77
77
|
*/
|
|
78
78
|
export function extractDidFragment(input: unknown): string | undefined {
|
|
79
|
-
if (typeof input !== 'string') return undefined;
|
|
80
|
-
if (input.length === 0) return undefined;
|
|
79
|
+
if (typeof input !== 'string') {return undefined;}
|
|
80
|
+
if (input.length === 0) {return undefined;}
|
|
81
81
|
return input.split('#').pop();
|
|
82
82
|
}
|
|
83
83
|
|
|
@@ -97,8 +97,10 @@ export function extractDidFragment(input: unknown): string | undefined {
|
|
|
97
97
|
*
|
|
98
98
|
* @param params - An object containing input parameters for retrieving services.
|
|
99
99
|
* @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
|
-
*
|
|
100
|
+
* @param params.id - Optional. A string representing the specific service ID to match. If provided,
|
|
101
|
+
* only the service with this ID will be returned.
|
|
102
|
+
* @param params.type - Optional. A string representing the specific service type to match.
|
|
103
|
+
* If provided, only the service(s) of this type will be returned.
|
|
102
104
|
* @returns An array of services. If no matching service is found, an empty array is returned.
|
|
103
105
|
*/
|
|
104
106
|
export function getServices({ didDocument, id, type }: {
|
|
@@ -107,8 +109,8 @@ export function getServices({ didDocument, id, type }: {
|
|
|
107
109
|
type?: string;
|
|
108
110
|
}): DidService[] {
|
|
109
111
|
return didDocument?.service?.filter(service => {
|
|
110
|
-
if (id && service.id !== id) return false;
|
|
111
|
-
if (type && service.type !== type) return false;
|
|
112
|
+
if (id && service.id !== id) {return false;}
|
|
113
|
+
if (type && service.type !== type) {return false;}
|
|
112
114
|
return true;
|
|
113
115
|
}) ?? [];
|
|
114
116
|
}
|
|
@@ -150,7 +152,7 @@ export async function getVerificationMethodByKey({ didDocument, publicKeyJwk, pu
|
|
|
150
152
|
// Collect all verification methods from the DID document.
|
|
151
153
|
const verificationMethods = getVerificationMethods({ didDocument });
|
|
152
154
|
|
|
153
|
-
for (
|
|
155
|
+
for (const method of verificationMethods) {
|
|
154
156
|
if (publicKeyJwk && method.publicKeyJwk) {
|
|
155
157
|
const publicKeyThumbprint = await computeJwkThumbprint({ jwk: publicKeyJwk });
|
|
156
158
|
if (publicKeyThumbprint === await computeJwkThumbprint({ jwk: method.publicKeyJwk })) {
|
|
@@ -191,7 +193,7 @@ export async function getVerificationMethodByKey({ didDocument, publicKeyJwk, pu
|
|
|
191
193
|
export function getVerificationMethods({ didDocument }: {
|
|
192
194
|
didDocument: DidDocument;
|
|
193
195
|
}): DidVerificationMethod[] {
|
|
194
|
-
if (!didDocument) throw new TypeError(`Required parameter missing: 'didDocument'`);
|
|
196
|
+
if (!didDocument) {throw new TypeError(`Required parameter missing: 'didDocument'`);}
|
|
195
197
|
|
|
196
198
|
const verificationMethods: DidVerificationMethod[] = [];
|
|
197
199
|
|
|
@@ -356,7 +358,7 @@ export function getVerificationRelationshipsById({ didDocument, methodId }: {
|
|
|
356
358
|
*/
|
|
357
359
|
export function isDidService(obj: unknown): obj is DidService {
|
|
358
360
|
// Validate that the given value is an object.
|
|
359
|
-
if (!obj || typeof obj !== 'object' || obj === null) return false;
|
|
361
|
+
if (!obj || typeof obj !== 'object' || obj === null) {return false;}
|
|
360
362
|
|
|
361
363
|
// Validate that the object has the necessary properties of DidService.
|
|
362
364
|
return 'id' in obj && 'type' in obj && 'serviceEndpoint' in obj;
|
|
@@ -391,7 +393,7 @@ export function isDidService(obj: unknown): obj is DidService {
|
|
|
391
393
|
* {
|
|
392
394
|
* id: 'did:example:123#dwn',
|
|
393
395
|
* type: 'DecentralizedWebNode',
|
|
394
|
-
* serviceEndpoint: 'https://enbox-
|
|
396
|
+
* serviceEndpoint: 'https://enbox-dwn.fly.dev',
|
|
395
397
|
* enc: 'did:example:123#key-1',
|
|
396
398
|
* sig: 'did:example:123#key-2'
|
|
397
399
|
* }
|
|
@@ -412,13 +414,13 @@ export function isDidService(obj: unknown): obj is DidService {
|
|
|
412
414
|
*/
|
|
413
415
|
export function isDwnDidService(obj: unknown): obj is DwnDidService {
|
|
414
416
|
// Validate that the given value is a {@link DidService}.
|
|
415
|
-
if (!isDidService(obj)) return false;
|
|
417
|
+
if (!isDidService(obj)) {return false;}
|
|
416
418
|
|
|
417
419
|
// Validate that the `type` property is `DecentralizedWebNode`.
|
|
418
|
-
if (obj.type !== 'DecentralizedWebNode') return false;
|
|
420
|
+
if (obj.type !== 'DecentralizedWebNode') {return false;}
|
|
419
421
|
|
|
420
422
|
// Validate that the given object has the `enc` and `sig` properties.
|
|
421
|
-
if (!('enc' in obj && 'sig' in obj)) return false;
|
|
423
|
+
if (!('enc' in obj && 'sig' in obj)) {return false;}
|
|
422
424
|
|
|
423
425
|
// Validate that the `enc` and `sig` properties are either strings or arrays of strings.
|
|
424
426
|
const isStringOrStringArray = (prop: any): boolean =>
|
|
@@ -453,14 +455,14 @@ export function isDwnDidService(obj: unknown): obj is DwnDidService {
|
|
|
453
455
|
*/
|
|
454
456
|
export function isDidVerificationMethod(obj: unknown): obj is DidVerificationMethod {
|
|
455
457
|
// Validate that the given value is an object.
|
|
456
|
-
if (!obj || typeof obj !== 'object' || obj === null) return false;
|
|
458
|
+
if (!obj || typeof obj !== 'object' || obj === null) {return false;}
|
|
457
459
|
|
|
458
460
|
// Validate that the object has the necessary properties of a DidVerificationMethod.
|
|
459
|
-
if (!('id' in obj && 'type' in obj && 'controller' in obj)) return false;
|
|
461
|
+
if (!('id' in obj && 'type' in obj && 'controller' in obj)) {return false;}
|
|
460
462
|
|
|
461
|
-
if (typeof obj.id !== 'string') return false;
|
|
462
|
-
if (typeof obj.type !== 'string') return false;
|
|
463
|
-
if (typeof obj.controller !== 'string') return false;
|
|
463
|
+
if (typeof obj.id !== 'string') {return false;}
|
|
464
|
+
if (typeof obj.type !== 'string') {return false;}
|
|
465
|
+
if (typeof obj.controller !== 'string') {return false;}
|
|
464
466
|
|
|
465
467
|
return true;
|
|
466
468
|
}
|
|
@@ -526,7 +528,7 @@ export function multibaseIdToKeyBytes({ multibaseKeyId }: {
|
|
|
526
528
|
const { code, data, name } = Multicodec.removePrefix({ prefixedData: prefixedKey });
|
|
527
529
|
|
|
528
530
|
return { keyBytes: data, multicodecCode: code, multicodecName: name };
|
|
529
|
-
} catch
|
|
531
|
+
} catch {
|
|
530
532
|
throw new DidError(DidErrorCode.InvalidDid, `Invalid multibase identifier: ${multibaseKeyId}`);
|
|
531
533
|
}
|
|
532
534
|
}
|