@interop/did-web-resolver 3.0.0 → 4.0.0
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/esm/DidWebResolver.d.ts +147 -0
- package/dist/esm/DidWebResolver.d.ts.map +1 -0
- package/dist/esm/DidWebResolver.js +322 -0
- package/dist/esm/DidWebResolver.js.map +1 -0
- package/dist/esm/index.d.ts +8 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +6 -5
- package/dist/esm/index.js.map +1 -0
- package/dist/src/DidWebResolver.d.ts +146 -0
- package/dist/src/DidWebResolver.js +329 -0
- package/dist/src/DidWebResolver.js.map +1 -0
- package/dist/src/index.d.ts +7 -0
- package/dist/src/index.js +12 -0
- package/dist/src/index.js.map +1 -0
- package/dist/test/DidWebResolver.spec.d.ts +1 -0
- package/dist/test/DidWebResolver.spec.js +183 -0
- package/dist/test/DidWebResolver.spec.js.map +1 -0
- package/package.json +47 -59
- package/src/{DidWebResolver.js → DidWebResolver.ts} +53 -36
- package/src/declarations.d.ts +11 -0
- package/src/{index.js → index.ts} +2 -2
- package/build-dist.sh +0 -14
- package/dist/DidWebResolver.js +0 -383
- package/dist/esm/package.json +0 -3
- package/dist/index.js +0 -14
- package/rollup.config.js +0 -15
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
export declare function didFromUrl({ url }?: {
|
|
2
|
+
url?: string;
|
|
3
|
+
}): string;
|
|
4
|
+
export declare function urlFromDid({ did }: {
|
|
5
|
+
did: string | undefined;
|
|
6
|
+
}): string;
|
|
7
|
+
/**
|
|
8
|
+
* Initializes the DID Document's keys/proof methods.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* didDocument.id = 'did:ex:123';
|
|
12
|
+
* const {didDocument, keyPairs} = await initKeys({
|
|
13
|
+
* didDocument,
|
|
14
|
+
* cryptoLd,
|
|
15
|
+
* keyMap: {
|
|
16
|
+
* capabilityInvocation: someExistingKey,
|
|
17
|
+
* authentication: 'Ed25519VerificationKey2020',
|
|
18
|
+
* assertionMethod: 'Ed25519VerificationKey2020',
|
|
19
|
+
* keyAgreement: 'X25519KeyAgreementKey2019'
|
|
20
|
+
* }
|
|
21
|
+
* });.
|
|
22
|
+
*
|
|
23
|
+
* @param {object} options - Options hashmap.
|
|
24
|
+
* @param {object} options.didDocument - DID Document.
|
|
25
|
+
* @typedef {object} CryptoLD
|
|
26
|
+
* @param {CryptoLD} [options.cryptoLd] - CryptoLD driver instance,
|
|
27
|
+
* initialized with the key types this DID Document intends to support.
|
|
28
|
+
* @param {object} [options.keyMap] - Map of keys (or key types) by purpose.
|
|
29
|
+
*
|
|
30
|
+
* @returns {Promise<{didDocument: object, keyPairs: Map}>} Resolves with the
|
|
31
|
+
* DID Document initialized with keys, as well as the map of the corresponding
|
|
32
|
+
* key pairs (by key id).
|
|
33
|
+
*/
|
|
34
|
+
export declare function initKeys({ didDocument, cryptoLd, keyMap }?: {
|
|
35
|
+
didDocument?: object;
|
|
36
|
+
cryptoLd?: any;
|
|
37
|
+
keyMap?: any;
|
|
38
|
+
}): Promise<{
|
|
39
|
+
didDocument: object;
|
|
40
|
+
keyPairs: Map<string, any>;
|
|
41
|
+
}>;
|
|
42
|
+
export declare class DidWebResolver {
|
|
43
|
+
cryptoLd: any;
|
|
44
|
+
keyMap: object;
|
|
45
|
+
method: string;
|
|
46
|
+
logger: any;
|
|
47
|
+
/**
|
|
48
|
+
* @param cryptoLd {CryptoLD}
|
|
49
|
+
* @param keyMap {object}
|
|
50
|
+
* @param [logger] {object} Logger object (with .log, .error, .warn,
|
|
51
|
+
* etc methods).
|
|
52
|
+
*/
|
|
53
|
+
constructor({ cryptoLd, keyMap, logger }?: {
|
|
54
|
+
cryptoLd?: any;
|
|
55
|
+
keyMap?: object;
|
|
56
|
+
logger?: any;
|
|
57
|
+
});
|
|
58
|
+
/**
|
|
59
|
+
* Generates a new DID Document and initializes various authentication
|
|
60
|
+
* and authorization proof purpose keys.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* const url = 'https://example.com'
|
|
64
|
+
* const { didDocument, didKeys } = await didWeb.generate({url})
|
|
65
|
+
* didDocument.id
|
|
66
|
+
* // -> 'did:web:example.com'
|
|
67
|
+
*
|
|
68
|
+
*
|
|
69
|
+
* Either an `id` or a `url` is required:
|
|
70
|
+
* @param [id] {string} - A did:web DID. If absent, will be converted from url
|
|
71
|
+
* @param [url] {string}
|
|
72
|
+
* @param [seed] {string|Uint8Array}
|
|
73
|
+
*
|
|
74
|
+
* @param [keyMap] {object} A hashmap of key types by purpose.
|
|
75
|
+
*
|
|
76
|
+
* @param cryptoLd
|
|
77
|
+
* @parma [cryptoLd] {object} CryptoLD instance with support for supported
|
|
78
|
+
* crypto suites installed.
|
|
79
|
+
*
|
|
80
|
+
* @returns {Promise<{didDocument: object, keyPairs: object,
|
|
81
|
+
* methodFor: Function}>} Resolves with the generated DID Document, along
|
|
82
|
+
* with the corresponding key pairs used to generate it (for storage in a
|
|
83
|
+
* KMS).
|
|
84
|
+
*/
|
|
85
|
+
generate({ id, url, seed, keyMap, cryptoLd }?: {
|
|
86
|
+
id?: string;
|
|
87
|
+
url?: string;
|
|
88
|
+
seed?: string | Uint8Array;
|
|
89
|
+
keyMap?: any;
|
|
90
|
+
cryptoLd?: any;
|
|
91
|
+
}): Promise<{
|
|
92
|
+
didDocument: any;
|
|
93
|
+
keyPairs: object;
|
|
94
|
+
methodFor: Function;
|
|
95
|
+
}>;
|
|
96
|
+
/**
|
|
97
|
+
* Fetches a DID Document for a given DID.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* // In Node.js tests, use an agent to avoid self-signed certificate errors
|
|
101
|
+
* const agent = new https.agent({rejectUnauthorized: false});
|
|
102
|
+
*
|
|
103
|
+
* @param {string} [did] For example, 'did:web:example.com'
|
|
104
|
+
* @param {string} [url]
|
|
105
|
+
* @param {https.Agent} [agent] Optional agent used to customize network
|
|
106
|
+
* behavior in Node.js (such as `rejectUnauthorized: false`).
|
|
107
|
+
* @param {object} [logger] Logger object (with .log, .error, .warn,
|
|
108
|
+
* etc methods).
|
|
109
|
+
*
|
|
110
|
+
* @throws {Error}
|
|
111
|
+
*
|
|
112
|
+
* @returns {Promise<object>} Plain parsed JSON object of the DID Document.
|
|
113
|
+
*/
|
|
114
|
+
get({ did, url, agent, logger }: {
|
|
115
|
+
did?: string | undefined;
|
|
116
|
+
url?: string | undefined;
|
|
117
|
+
agent?: any;
|
|
118
|
+
logger?: any;
|
|
119
|
+
}): Promise<object>;
|
|
120
|
+
/**
|
|
121
|
+
* Returns the public key (verification method) object for a given DID
|
|
122
|
+
* Document and purpose. Useful in conjunction with a `.get()` call.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* const didDocument = await didKeyDriver.get({did});
|
|
126
|
+
* const authKeyData = didDriver.publicMethodFor({
|
|
127
|
+
* didDocument, purpose: 'authentication'
|
|
128
|
+
* });
|
|
129
|
+
* // You can then create a suite instance object to verify signatures etc.
|
|
130
|
+
* const authPublicKey = await cryptoLd.from(authKeyData);
|
|
131
|
+
* const {verify} = authPublicKey.verifier();
|
|
132
|
+
*
|
|
133
|
+
* @param {object} options - Options hashmap.
|
|
134
|
+
* @param {object} options.didDocument - DID Document (retrieved via a
|
|
135
|
+
* `.get()` or from some other source).
|
|
136
|
+
* @param {string} options.purpose - Verification method purpose, such as
|
|
137
|
+
* 'authentication', 'assertionMethod', 'keyAgreement' and so on.
|
|
138
|
+
*
|
|
139
|
+
* @returns {object} Returns the public key object (obtained from the DID
|
|
140
|
+
* Document), without a `@context`.
|
|
141
|
+
*/
|
|
142
|
+
publicMethodFor({ didDocument, purpose }: {
|
|
143
|
+
didDocument: any;
|
|
144
|
+
purpose: string;
|
|
145
|
+
}): any;
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=DidWebResolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DidWebResolver.d.ts","sour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AAM,CAAC,EAAE,GAAG,CAAC;QAAC,QAAQ,CAAC,EAAE,GAAG,CAAA;KAAO,GAC5F,OAAO,CAAC;QAAE,WAAW,EAAE,GAAG,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,QAAQ,CAAA;KAAE,CAAC;IA+CtE;;;;;;;;;;;;;;;;;OAiBG;IACG,GAAG,CAAE,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,MAAoB,EAAE,EAAE;QAAE,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QAAC,KAAK,CAAC,EAAE,GAAG,CAAC;QAAC,MAAM,CAAC,EAAE,GAAG,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAwCzJ;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,eAAe,CAAE,EAAE,WAAW,EAAE,OAAO,EAAE,EAAE;QAAE,WAAW,EAAE,GAAG,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,GAAG;CAOvF"}
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/strict-boolean-expressions */
|
|
2
|
+
import { httpClient } from '@digitalbazaar/http-client';
|
|
3
|
+
import * as didIo from '@digitalcredentials/did-io';
|
|
4
|
+
import * as ed25519Context from 'ed25519-signature-2020-context';
|
|
5
|
+
import * as x25519Context from 'x25519-key-agreement-2020-context';
|
|
6
|
+
import * as didContext from 'did-context';
|
|
7
|
+
import { decodeSecretKeySeed } from '@digitalcredentials/bnid';
|
|
8
|
+
import { URL } from 'whatwg-url';
|
|
9
|
+
const { VERIFICATION_RELATIONSHIPS } = didIo;
|
|
10
|
+
const DEFAULT_KEY_MAP = {
|
|
11
|
+
capabilityInvocation: 'Ed25519VerificationKey2020',
|
|
12
|
+
authentication: 'Ed25519VerificationKey2020',
|
|
13
|
+
assertionMethod: 'Ed25519VerificationKey2020',
|
|
14
|
+
capabilityDelegation: 'Ed25519VerificationKey2020',
|
|
15
|
+
keyAgreement: 'X25519KeyAgreementKey2020'
|
|
16
|
+
};
|
|
17
|
+
export function didFromUrl({ url } = {}) {
|
|
18
|
+
if (!url) {
|
|
19
|
+
throw new TypeError('Cannot convert url to did, missing url.');
|
|
20
|
+
}
|
|
21
|
+
if (url.startsWith('http:')) {
|
|
22
|
+
throw new TypeError('did:web does not support non-HTTPS URLs.');
|
|
23
|
+
}
|
|
24
|
+
let parsedUrl;
|
|
25
|
+
try {
|
|
26
|
+
parsedUrl = new URL(url);
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
throw new TypeError(`Invalid url: "${url}".`);
|
|
30
|
+
}
|
|
31
|
+
let { host, pathname } = parsedUrl;
|
|
32
|
+
let pathComponent = '';
|
|
33
|
+
const didJsonSuffix = '/did.json';
|
|
34
|
+
const wellKnownSuffix = '/.well-known';
|
|
35
|
+
if (pathname?.endsWith(didJsonSuffix)) {
|
|
36
|
+
pathname = pathname.substring(0, pathname.length - didJsonSuffix.length);
|
|
37
|
+
}
|
|
38
|
+
if (pathname?.endsWith(wellKnownSuffix)) {
|
|
39
|
+
pathname = pathname.substring(0, pathname.length - wellKnownSuffix.length);
|
|
40
|
+
}
|
|
41
|
+
if (pathname && pathname !== '/') {
|
|
42
|
+
pathComponent = pathname.split('/').map(encodeURIComponent).join(':');
|
|
43
|
+
}
|
|
44
|
+
return 'did:web:' + encodeURIComponent(host) + pathComponent;
|
|
45
|
+
}
|
|
46
|
+
export function urlFromDid({ did }) {
|
|
47
|
+
if (!did?.startsWith('did:web:')) {
|
|
48
|
+
throw new TypeError(`DID Method not supported: "${did ?? ''}".`);
|
|
49
|
+
}
|
|
50
|
+
const [didUrl, hashFragment] = did.split('#');
|
|
51
|
+
// eslint-disable-next-line no-unused-vars
|
|
52
|
+
// const [didResource, query] = didUrl.split('?')
|
|
53
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
54
|
+
const [_did, _web, urlNoProtocol, ...pathFragments] = didUrl.split(':');
|
|
55
|
+
if (urlNoProtocol.includes('/')) {
|
|
56
|
+
throw new TypeError(`Cannot construct url from did: "${did}". domain-name cannot contain a path.`);
|
|
57
|
+
}
|
|
58
|
+
let parsedUrl;
|
|
59
|
+
try {
|
|
60
|
+
// URI-decode the url (in case it contained a port number,
|
|
61
|
+
// for example, `did:web:localhost%3A8080`
|
|
62
|
+
parsedUrl = new URL('https://' + decodeURIComponent(urlNoProtocol));
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
throw new TypeError(`Cannot construct url from did: "${did}".`);
|
|
66
|
+
}
|
|
67
|
+
if (pathFragments.length === 0) {
|
|
68
|
+
parsedUrl.pathname = '/.well-known/did.json';
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
parsedUrl.pathname = pathFragments.map(decodeURIComponent).join('/') + '/did.json';
|
|
72
|
+
}
|
|
73
|
+
if (hashFragment) {
|
|
74
|
+
parsedUrl.hash = hashFragment;
|
|
75
|
+
}
|
|
76
|
+
return parsedUrl.toString();
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Initializes the DID Document's keys/proof methods.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* didDocument.id = 'did:ex:123';
|
|
83
|
+
* const {didDocument, keyPairs} = await initKeys({
|
|
84
|
+
* didDocument,
|
|
85
|
+
* cryptoLd,
|
|
86
|
+
* keyMap: {
|
|
87
|
+
* capabilityInvocation: someExistingKey,
|
|
88
|
+
* authentication: 'Ed25519VerificationKey2020',
|
|
89
|
+
* assertionMethod: 'Ed25519VerificationKey2020',
|
|
90
|
+
* keyAgreement: 'X25519KeyAgreementKey2019'
|
|
91
|
+
* }
|
|
92
|
+
* });.
|
|
93
|
+
*
|
|
94
|
+
* @param {object} options - Options hashmap.
|
|
95
|
+
* @param {object} options.didDocument - DID Document.
|
|
96
|
+
* @typedef {object} CryptoLD
|
|
97
|
+
* @param {CryptoLD} [options.cryptoLd] - CryptoLD driver instance,
|
|
98
|
+
* initialized with the key types this DID Document intends to support.
|
|
99
|
+
* @param {object} [options.keyMap] - Map of keys (or key types) by purpose.
|
|
100
|
+
*
|
|
101
|
+
* @returns {Promise<{didDocument: object, keyPairs: Map}>} Resolves with the
|
|
102
|
+
* DID Document initialized with keys, as well as the map of the corresponding
|
|
103
|
+
* key pairs (by key id).
|
|
104
|
+
*/
|
|
105
|
+
export async function initKeys({ didDocument, cryptoLd, keyMap } = {}) {
|
|
106
|
+
const doc = { ...didDocument };
|
|
107
|
+
if (!doc.id) {
|
|
108
|
+
throw new TypeError('DID Document "id" property is required to initialize keys.');
|
|
109
|
+
}
|
|
110
|
+
const keyPairs = new Map();
|
|
111
|
+
// Set the defaults for the created keys (if needed)
|
|
112
|
+
const options = { controller: doc.id };
|
|
113
|
+
for (const purpose in keyMap) {
|
|
114
|
+
if (!VERIFICATION_RELATIONSHIPS.has(purpose)) {
|
|
115
|
+
throw new Error(`Unsupported key purpose: "${purpose}".`);
|
|
116
|
+
}
|
|
117
|
+
let key;
|
|
118
|
+
if (typeof keyMap[purpose] === 'string') {
|
|
119
|
+
if (!cryptoLd) {
|
|
120
|
+
throw new Error('Please provide an initialized CryptoLD instance.');
|
|
121
|
+
}
|
|
122
|
+
key = await cryptoLd.generate({ type: keyMap[purpose], ...options });
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
// An existing key has been provided
|
|
126
|
+
key = keyMap[purpose];
|
|
127
|
+
}
|
|
128
|
+
doc[purpose] = [key.export({ publicKey: true })];
|
|
129
|
+
keyPairs.set(key.id, key);
|
|
130
|
+
}
|
|
131
|
+
return { didDocument: doc, keyPairs };
|
|
132
|
+
}
|
|
133
|
+
export class DidWebResolver {
|
|
134
|
+
cryptoLd;
|
|
135
|
+
keyMap;
|
|
136
|
+
method;
|
|
137
|
+
logger;
|
|
138
|
+
/**
|
|
139
|
+
* @param cryptoLd {CryptoLD}
|
|
140
|
+
* @param keyMap {object}
|
|
141
|
+
* @param [logger] {object} Logger object (with .log, .error, .warn,
|
|
142
|
+
* etc methods).
|
|
143
|
+
*/
|
|
144
|
+
constructor({ cryptoLd, keyMap = DEFAULT_KEY_MAP, logger = console } = {}) {
|
|
145
|
+
this.method = 'web'; // did:web:... (used for didIo resolver harness)
|
|
146
|
+
this.cryptoLd = cryptoLd;
|
|
147
|
+
this.keyMap = keyMap;
|
|
148
|
+
this.logger = logger;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Generates a new DID Document and initializes various authentication
|
|
152
|
+
* and authorization proof purpose keys.
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* const url = 'https://example.com'
|
|
156
|
+
* const { didDocument, didKeys } = await didWeb.generate({url})
|
|
157
|
+
* didDocument.id
|
|
158
|
+
* // -> 'did:web:example.com'
|
|
159
|
+
*
|
|
160
|
+
*
|
|
161
|
+
* Either an `id` or a `url` is required:
|
|
162
|
+
* @param [id] {string} - A did:web DID. If absent, will be converted from url
|
|
163
|
+
* @param [url] {string}
|
|
164
|
+
* @param [seed] {string|Uint8Array}
|
|
165
|
+
*
|
|
166
|
+
* @param [keyMap] {object} A hashmap of key types by purpose.
|
|
167
|
+
*
|
|
168
|
+
* @param cryptoLd
|
|
169
|
+
* @parma [cryptoLd] {object} CryptoLD instance with support for supported
|
|
170
|
+
* crypto suites installed.
|
|
171
|
+
*
|
|
172
|
+
* @returns {Promise<{didDocument: object, keyPairs: object,
|
|
173
|
+
* methodFor: Function}>} Resolves with the generated DID Document, along
|
|
174
|
+
* with the corresponding key pairs used to generate it (for storage in a
|
|
175
|
+
* KMS).
|
|
176
|
+
*/
|
|
177
|
+
async generate({ id, url, seed, keyMap, cryptoLd = this.cryptoLd } = {}) {
|
|
178
|
+
if (!id && !url) {
|
|
179
|
+
throw new TypeError('A "url" or an "id" parameter is required.');
|
|
180
|
+
}
|
|
181
|
+
if (seed && keyMap) {
|
|
182
|
+
throw new TypeError('Either a "seed" or a "keyMap" param must be provided, but not both.');
|
|
183
|
+
}
|
|
184
|
+
const did = id ?? didFromUrl({ url });
|
|
185
|
+
if (seed) {
|
|
186
|
+
const keyPair = await _keyPairFromSecretSeed({
|
|
187
|
+
seed, controller: did, cryptoLd
|
|
188
|
+
});
|
|
189
|
+
keyMap = { assertionMethod: keyPair };
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
keyMap = keyMap || this.keyMap;
|
|
193
|
+
}
|
|
194
|
+
// Compose the DID Document
|
|
195
|
+
let didDocument = {
|
|
196
|
+
'@context': [
|
|
197
|
+
didContext.constants.DID_CONTEXT_URL,
|
|
198
|
+
ed25519Context.constants.CONTEXT_URL,
|
|
199
|
+
x25519Context.constants.CONTEXT_URL
|
|
200
|
+
],
|
|
201
|
+
id: did
|
|
202
|
+
};
|
|
203
|
+
const result = await initKeys({ didDocument, cryptoLd, keyMap });
|
|
204
|
+
const keyPairs = result.keyPairs;
|
|
205
|
+
didDocument = result.didDocument;
|
|
206
|
+
// Convenience function that returns the public/private key pair instance
|
|
207
|
+
// for a given purpose (authentication, assertionMethod, keyAgreement, etc).
|
|
208
|
+
const methodFor = ({ purpose }) => {
|
|
209
|
+
const { id: methodId } = didIo.findVerificationMethod({
|
|
210
|
+
doc: didDocument, purpose
|
|
211
|
+
});
|
|
212
|
+
return keyPairs.get(methodId);
|
|
213
|
+
};
|
|
214
|
+
return { didDocument, keyPairs, methodFor };
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Fetches a DID Document for a given DID.
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* // In Node.js tests, use an agent to avoid self-signed certificate errors
|
|
221
|
+
* const agent = new https.agent({rejectUnauthorized: false});
|
|
222
|
+
*
|
|
223
|
+
* @param {string} [did] For example, 'did:web:example.com'
|
|
224
|
+
* @param {string} [url]
|
|
225
|
+
* @param {https.Agent} [agent] Optional agent used to customize network
|
|
226
|
+
* behavior in Node.js (such as `rejectUnauthorized: false`).
|
|
227
|
+
* @param {object} [logger] Logger object (with .log, .error, .warn,
|
|
228
|
+
* etc methods).
|
|
229
|
+
*
|
|
230
|
+
* @throws {Error}
|
|
231
|
+
*
|
|
232
|
+
* @returns {Promise<object>} Plain parsed JSON object of the DID Document.
|
|
233
|
+
*/
|
|
234
|
+
async get({ did, url, agent, logger = this.logger }) {
|
|
235
|
+
const didUrl = url ?? urlFromDid({ did });
|
|
236
|
+
if (!didUrl) {
|
|
237
|
+
throw new TypeError('A DID or a URL is required.');
|
|
238
|
+
}
|
|
239
|
+
const [urlAuthority, keyIdFragment] = didUrl.split('#');
|
|
240
|
+
let didDocument;
|
|
241
|
+
try {
|
|
242
|
+
logger.info(`Fetching "${urlAuthority}" via http client.`);
|
|
243
|
+
const result = await httpClient.get(urlAuthority, { agent });
|
|
244
|
+
didDocument = result.data;
|
|
245
|
+
}
|
|
246
|
+
catch (e) {
|
|
247
|
+
// status is HTTP status code
|
|
248
|
+
// data is JSON error from the server if available
|
|
249
|
+
const { data, status } = e;
|
|
250
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
251
|
+
logger.error(`Http ${status ?? ''} error:`, data);
|
|
252
|
+
throw e;
|
|
253
|
+
}
|
|
254
|
+
if (didDocument && keyIdFragment) {
|
|
255
|
+
// resolve an individual key
|
|
256
|
+
// Keys are expected to have format: <did:web:...>#<keyIdFragment>
|
|
257
|
+
const didAuthority = didFromUrl({ url: urlAuthority });
|
|
258
|
+
const methodId = `${didAuthority}#${keyIdFragment}`;
|
|
259
|
+
const key = didIo.findVerificationMethod({ doc: didDocument, methodId });
|
|
260
|
+
if (!key) {
|
|
261
|
+
throw new Error(`Key id ${methodId} not found.`);
|
|
262
|
+
}
|
|
263
|
+
const keyPair = await this.cryptoLd.from(key);
|
|
264
|
+
return keyPair.export({ publicKey: true, includeContext: true });
|
|
265
|
+
}
|
|
266
|
+
return didDocument;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Returns the public key (verification method) object for a given DID
|
|
270
|
+
* Document and purpose. Useful in conjunction with a `.get()` call.
|
|
271
|
+
*
|
|
272
|
+
* @example
|
|
273
|
+
* const didDocument = await didKeyDriver.get({did});
|
|
274
|
+
* const authKeyData = didDriver.publicMethodFor({
|
|
275
|
+
* didDocument, purpose: 'authentication'
|
|
276
|
+
* });
|
|
277
|
+
* // You can then create a suite instance object to verify signatures etc.
|
|
278
|
+
* const authPublicKey = await cryptoLd.from(authKeyData);
|
|
279
|
+
* const {verify} = authPublicKey.verifier();
|
|
280
|
+
*
|
|
281
|
+
* @param {object} options - Options hashmap.
|
|
282
|
+
* @param {object} options.didDocument - DID Document (retrieved via a
|
|
283
|
+
* `.get()` or from some other source).
|
|
284
|
+
* @param {string} options.purpose - Verification method purpose, such as
|
|
285
|
+
* 'authentication', 'assertionMethod', 'keyAgreement' and so on.
|
|
286
|
+
*
|
|
287
|
+
* @returns {object} Returns the public key object (obtained from the DID
|
|
288
|
+
* Document), without a `@context`.
|
|
289
|
+
*/
|
|
290
|
+
publicMethodFor({ didDocument, purpose }) {
|
|
291
|
+
const method = didIo.findVerificationMethod({ doc: didDocument, purpose });
|
|
292
|
+
if (!method) {
|
|
293
|
+
throw new Error(`No verification method found for purpose "${purpose}"`);
|
|
294
|
+
}
|
|
295
|
+
return method;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* @param options {object}
|
|
300
|
+
* @param options.seed {string|Uint8Array}
|
|
301
|
+
* @param controller {string}
|
|
302
|
+
* @param cryptoLd {object}
|
|
303
|
+
*
|
|
304
|
+
* @return {Promise<LDKeyPair>}
|
|
305
|
+
*/
|
|
306
|
+
async function _keyPairFromSecretSeed({ seed, controller, cryptoLd }) {
|
|
307
|
+
let seedBytes;
|
|
308
|
+
if (typeof seed === 'string') {
|
|
309
|
+
// Currently only supports base58 multibase / identity multihash encoding.
|
|
310
|
+
if (!seed.startsWith('z1A')) {
|
|
311
|
+
throw new TypeError('"seed" parameter must be a multibase/multihash encoded string, or a Uint8Array.');
|
|
312
|
+
}
|
|
313
|
+
seedBytes = decodeSecretKeySeed({ secretKeySeed: seed });
|
|
314
|
+
}
|
|
315
|
+
else {
|
|
316
|
+
seedBytes = new Uint8Array(seed);
|
|
317
|
+
}
|
|
318
|
+
return cryptoLd.generate({
|
|
319
|
+
controller, seed: seedBytes, type: 'Ed25519VerificationKey2020'
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
//# sourceMappingURL=DidWebResolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DidWebResolver.js","sourceRoot":"","sources":["../../src/DidWebResolver.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAA;AACvD,OAAO,KAAK,KAAK,MAAM,4BAA4B,CAAA;AACnD,OAAO,KAAK,cAAc,MAAM,gCAAgC,CAAA;AAChE,OAAO,KAAK,aAAa,MAAM,mCAAmC,CAAA;AAClE,OAAO,KAAK,UAAU,MAAM,aAAa,CAAA;AACzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAC9D,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAA;AAEhC,MAAM,EAAE,0BAA0B,EAAE,GAAG,KAAK,CAAA;AAE5C,MAAM,eAAe,GAAG;IACtB,oBAAoB,EAAE,4BAA4B;IAClD,cAAc,EAAE,4BAA4B;IAC5C,eAAe,EAAE,4BAA4B;IAC7C,oBAAoB,EAAE,4BAA4B;IAClD,YAAY,EAAE,2BAA2B;CAC1C,CAAA;AAED,MAAM,UAAU,UAAU,CAAE,EAAE,GAAG,KAAuB,EAAE;IACxD,IAAI,CAAC,GAAG,EAAE;QACR,MAAM,IAAI,SAAS,CAAC,yCAAyC,CAAC,CAAA;KAC/D;IACD,IAAI,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE;QAC3B,MAAM,IAAI,SAAS,CAA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AI,SAAS,CAAC,iFAAiF,CAAC,CAAA;SACvG;QACD,SAAS,GAAG,mBAAmB,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAA;KACzD;SAAM;QACL,SAAS,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,CAAA;KACjC;IACD,OAAO,QAAQ,CAAC,QAAQ,CAAC;QACvB,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,4BAA4B;KAChE,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DidWebResolver, didFromUrl, urlFromDid } from './DidWebResolver';
|
|
2
|
+
declare const driver: (options: {
|
|
3
|
+
cryptoLd?: any;
|
|
4
|
+
keyMap?: object | undefined;
|
|
5
|
+
logger?: any;
|
|
6
|
+
} | undefined) => DidWebResolver;
|
|
7
|
+
export { driver, DidWebResolver, didFromUrl, urlFromDid };
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAEzE,QAAA,MAAM,MAAM,YAAa;IAAE,QAAQ,CAAC,EAAE,GAAG,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,MAAM,CAAC,EAAE,GAAG,CAAA;CAAE,GAAG,SAAS,KAAG,cAEpG,CAAA;AAED,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,UAAU,EAAE,UAAU,EAAE,CAAA"}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export
|
|
1
|
+
import { DidWebResolver, didFromUrl, urlFromDid } from './DidWebResolver';
|
|
2
|
+
const driver = (options) => {
|
|
3
|
+
return new DidWebResolver(options);
|
|
4
|
+
};
|
|
5
|
+
export { driver, DidWebResolver, didFromUrl, urlFromDid };
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAEzE,MAAM,MAAM,GAAG,CAAC,OAAkF,EAAkB,EAAE;IACpH,OAAO,IAAI,cAAc,CAAC,OAAO,CAAC,CAAA;AACpC,CAAC,CAAA;AAED,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,UAAU,EAAE,UAAU,EAAE,CAAA"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
export declare function didFromUrl({ url }?: {
|
|
2
|
+
url?: string;
|
|
3
|
+
}): string;
|
|
4
|
+
export declare function urlFromDid({ did }: {
|
|
5
|
+
did: string | undefined;
|
|
6
|
+
}): string;
|
|
7
|
+
/**
|
|
8
|
+
* Initializes the DID Document's keys/proof methods.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* didDocument.id = 'did:ex:123';
|
|
12
|
+
* const {didDocument, keyPairs} = await initKeys({
|
|
13
|
+
* didDocument,
|
|
14
|
+
* cryptoLd,
|
|
15
|
+
* keyMap: {
|
|
16
|
+
* capabilityInvocation: someExistingKey,
|
|
17
|
+
* authentication: 'Ed25519VerificationKey2020',
|
|
18
|
+
* assertionMethod: 'Ed25519VerificationKey2020',
|
|
19
|
+
* keyAgreement: 'X25519KeyAgreementKey2019'
|
|
20
|
+
* }
|
|
21
|
+
* });.
|
|
22
|
+
*
|
|
23
|
+
* @param {object} options - Options hashmap.
|
|
24
|
+
* @param {object} options.didDocument - DID Document.
|
|
25
|
+
* @typedef {object} CryptoLD
|
|
26
|
+
* @param {CryptoLD} [options.cryptoLd] - CryptoLD driver instance,
|
|
27
|
+
* initialized with the key types this DID Document intends to support.
|
|
28
|
+
* @param {object} [options.keyMap] - Map of keys (or key types) by purpose.
|
|
29
|
+
*
|
|
30
|
+
* @returns {Promise<{didDocument: object, keyPairs: Map}>} Resolves with the
|
|
31
|
+
* DID Document initialized with keys, as well as the map of the corresponding
|
|
32
|
+
* key pairs (by key id).
|
|
33
|
+
*/
|
|
34
|
+
export declare function initKeys({ didDocument, cryptoLd, keyMap }?: {
|
|
35
|
+
didDocument?: object;
|
|
36
|
+
cryptoLd?: any;
|
|
37
|
+
keyMap?: any;
|
|
38
|
+
}): Promise<{
|
|
39
|
+
didDocument: object;
|
|
40
|
+
keyPairs: Map<string, any>;
|
|
41
|
+
}>;
|
|
42
|
+
export declare class DidWebResolver {
|
|
43
|
+
cryptoLd: any;
|
|
44
|
+
keyMap: object;
|
|
45
|
+
method: string;
|
|
46
|
+
logger: any;
|
|
47
|
+
/**
|
|
48
|
+
* @param cryptoLd {CryptoLD}
|
|
49
|
+
* @param keyMap {object}
|
|
50
|
+
* @param [logger] {object} Logger object (with .log, .error, .warn,
|
|
51
|
+
* etc methods).
|
|
52
|
+
*/
|
|
53
|
+
constructor({ cryptoLd, keyMap, logger }?: {
|
|
54
|
+
cryptoLd?: any;
|
|
55
|
+
keyMap?: object;
|
|
56
|
+
logger?: any;
|
|
57
|
+
});
|
|
58
|
+
/**
|
|
59
|
+
* Generates a new DID Document and initializes various authentication
|
|
60
|
+
* and authorization proof purpose keys.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* const url = 'https://example.com'
|
|
64
|
+
* const { didDocument, didKeys } = await didWeb.generate({url})
|
|
65
|
+
* didDocument.id
|
|
66
|
+
* // -> 'did:web:example.com'
|
|
67
|
+
*
|
|
68
|
+
*
|
|
69
|
+
* Either an `id` or a `url` is required:
|
|
70
|
+
* @param [id] {string} - A did:web DID. If absent, will be converted from url
|
|
71
|
+
* @param [url] {string}
|
|
72
|
+
* @param [seed] {string|Uint8Array}
|
|
73
|
+
*
|
|
74
|
+
* @param [keyMap] {object} A hashmap of key types by purpose.
|
|
75
|
+
*
|
|
76
|
+
* @param cryptoLd
|
|
77
|
+
* @parma [cryptoLd] {object} CryptoLD instance with support for supported
|
|
78
|
+
* crypto suites installed.
|
|
79
|
+
*
|
|
80
|
+
* @returns {Promise<{didDocument: object, keyPairs: object,
|
|
81
|
+
* methodFor: Function}>} Resolves with the generated DID Document, along
|
|
82
|
+
* with the corresponding key pairs used to generate it (for storage in a
|
|
83
|
+
* KMS).
|
|
84
|
+
*/
|
|
85
|
+
generate({ id, url, seed, keyMap, cryptoLd }?: {
|
|
86
|
+
id?: string;
|
|
87
|
+
url?: string;
|
|
88
|
+
seed?: string | Uint8Array;
|
|
89
|
+
keyMap?: any;
|
|
90
|
+
cryptoLd?: any;
|
|
91
|
+
}): Promise<{
|
|
92
|
+
didDocument: any;
|
|
93
|
+
keyPairs: object;
|
|
94
|
+
methodFor: Function;
|
|
95
|
+
}>;
|
|
96
|
+
/**
|
|
97
|
+
* Fetches a DID Document for a given DID.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* // In Node.js tests, use an agent to avoid self-signed certificate errors
|
|
101
|
+
* const agent = new https.agent({rejectUnauthorized: false});
|
|
102
|
+
*
|
|
103
|
+
* @param {string} [did] For example, 'did:web:example.com'
|
|
104
|
+
* @param {string} [url]
|
|
105
|
+
* @param {https.Agent} [agent] Optional agent used to customize network
|
|
106
|
+
* behavior in Node.js (such as `rejectUnauthorized: false`).
|
|
107
|
+
* @param {object} [logger] Logger object (with .log, .error, .warn,
|
|
108
|
+
* etc methods).
|
|
109
|
+
*
|
|
110
|
+
* @throws {Error}
|
|
111
|
+
*
|
|
112
|
+
* @returns {Promise<object>} Plain parsed JSON object of the DID Document.
|
|
113
|
+
*/
|
|
114
|
+
get({ did, url, agent, logger }: {
|
|
115
|
+
did?: string | undefined;
|
|
116
|
+
url?: string | undefined;
|
|
117
|
+
agent?: any;
|
|
118
|
+
logger?: any;
|
|
119
|
+
}): Promise<object>;
|
|
120
|
+
/**
|
|
121
|
+
* Returns the public key (verification method) object for a given DID
|
|
122
|
+
* Document and purpose. Useful in conjunction with a `.get()` call.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* const didDocument = await didKeyDriver.get({did});
|
|
126
|
+
* const authKeyData = didDriver.publicMethodFor({
|
|
127
|
+
* didDocument, purpose: 'authentication'
|
|
128
|
+
* });
|
|
129
|
+
* // You can then create a suite instance object to verify signatures etc.
|
|
130
|
+
* const authPublicKey = await cryptoLd.from(authKeyData);
|
|
131
|
+
* const {verify} = authPublicKey.verifier();
|
|
132
|
+
*
|
|
133
|
+
* @param {object} options - Options hashmap.
|
|
134
|
+
* @param {object} options.didDocument - DID Document (retrieved via a
|
|
135
|
+
* `.get()` or from some other source).
|
|
136
|
+
* @param {string} options.purpose - Verification method purpose, such as
|
|
137
|
+
* 'authentication', 'assertionMethod', 'keyAgreement' and so on.
|
|
138
|
+
*
|
|
139
|
+
* @returns {object} Returns the public key object (obtained from the DID
|
|
140
|
+
* Document), without a `@context`.
|
|
141
|
+
*/
|
|
142
|
+
publicMethodFor({ didDocument, purpose }: {
|
|
143
|
+
didDocument: any;
|
|
144
|
+
purpose: string;
|
|
145
|
+
}): any;
|
|
146
|
+
}
|