@interop/did-web-resolver 5.0.0 → 6.1.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/README.md +38 -12
- package/dist/DidWebResolver.d.ts +263 -0
- package/dist/DidWebResolver.d.ts.map +1 -0
- package/dist/DidWebResolver.js +565 -0
- package/dist/DidWebResolver.js.map +1 -0
- package/dist/assertions.d.ts +47 -0
- package/dist/assertions.d.ts.map +1 -0
- package/dist/assertions.js +90 -0
- package/dist/assertions.js.map +1 -0
- package/dist/constants.d.ts +23 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +45 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +36 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +66 -73
- package/dist/esm/DidWebResolver.d.ts +0 -147
- package/dist/esm/DidWebResolver.d.ts.map +0 -1
- package/dist/esm/DidWebResolver.js +0 -322
- package/dist/esm/DidWebResolver.js.map +0 -1
- package/dist/esm/index.d.ts +0 -8
- package/dist/esm/index.d.ts.map +0 -1
- package/dist/esm/index.js +0 -6
- package/dist/esm/index.js.map +0 -1
- package/dist/src/DidWebResolver.d.ts +0 -146
- package/dist/src/DidWebResolver.js +0 -329
- package/dist/src/DidWebResolver.js.map +0 -1
- package/dist/src/index.d.ts +0 -7
- package/dist/src/index.js +0 -12
- package/dist/src/index.js.map +0 -1
- package/dist/test/DidWebResolver.spec.d.ts +0 -1
- package/dist/test/DidWebResolver.spec.js +0 -183
- package/dist/test/DidWebResolver.spec.js.map +0 -1
- package/src/DidWebResolver.ts +0 -366
- package/src/declarations.d.ts +0 -11
- package/src/index.ts +0 -8
- /package/{LICENSE → LICENSE.md} +0 -0
|
@@ -1,329 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DidWebResolver = exports.initKeys = exports.urlFromDid = exports.didFromUrl = void 0;
|
|
4
|
-
/* eslint-disable @typescript-eslint/strict-boolean-expressions */
|
|
5
|
-
const http_client_1 = require("@digitalcredentials/http-client");
|
|
6
|
-
const didIo = require("@digitalcredentials/did-io");
|
|
7
|
-
const ed25519Context = require("ed25519-signature-2020-context");
|
|
8
|
-
const x25519Context = require("x25519-key-agreement-2020-context");
|
|
9
|
-
const didContext = require("did-context");
|
|
10
|
-
const bnid_1 = require("@digitalcredentials/bnid");
|
|
11
|
-
const whatwg_url_1 = require("whatwg-url");
|
|
12
|
-
const { VERIFICATION_RELATIONSHIPS } = didIo;
|
|
13
|
-
const DEFAULT_KEY_MAP = {
|
|
14
|
-
capabilityInvocation: 'Ed25519VerificationKey2020',
|
|
15
|
-
authentication: 'Ed25519VerificationKey2020',
|
|
16
|
-
assertionMethod: 'Ed25519VerificationKey2020',
|
|
17
|
-
capabilityDelegation: 'Ed25519VerificationKey2020',
|
|
18
|
-
keyAgreement: 'X25519KeyAgreementKey2020'
|
|
19
|
-
};
|
|
20
|
-
function didFromUrl({ url } = {}) {
|
|
21
|
-
if (!url) {
|
|
22
|
-
throw new TypeError('Cannot convert url to did, missing url.');
|
|
23
|
-
}
|
|
24
|
-
if (url.startsWith('http:')) {
|
|
25
|
-
throw new TypeError('did:web does not support non-HTTPS URLs.');
|
|
26
|
-
}
|
|
27
|
-
let parsedUrl;
|
|
28
|
-
try {
|
|
29
|
-
parsedUrl = new whatwg_url_1.URL(url);
|
|
30
|
-
}
|
|
31
|
-
catch (error) {
|
|
32
|
-
throw new TypeError(`Invalid url: "${url}".`);
|
|
33
|
-
}
|
|
34
|
-
let { host, pathname } = parsedUrl;
|
|
35
|
-
let pathComponent = '';
|
|
36
|
-
const didJsonSuffix = '/did.json';
|
|
37
|
-
const wellKnownSuffix = '/.well-known';
|
|
38
|
-
if (pathname?.endsWith(didJsonSuffix)) {
|
|
39
|
-
pathname = pathname.substring(0, pathname.length - didJsonSuffix.length);
|
|
40
|
-
}
|
|
41
|
-
if (pathname?.endsWith(wellKnownSuffix)) {
|
|
42
|
-
pathname = pathname.substring(0, pathname.length - wellKnownSuffix.length);
|
|
43
|
-
}
|
|
44
|
-
if (pathname && pathname !== '/') {
|
|
45
|
-
pathComponent = pathname.split('/').map(encodeURIComponent).join(':');
|
|
46
|
-
}
|
|
47
|
-
return 'did:web:' + encodeURIComponent(host) + pathComponent;
|
|
48
|
-
}
|
|
49
|
-
exports.didFromUrl = didFromUrl;
|
|
50
|
-
function urlFromDid({ did }) {
|
|
51
|
-
if (!did?.startsWith('did:web:')) {
|
|
52
|
-
throw new TypeError(`DID Method not supported: "${did ?? ''}".`);
|
|
53
|
-
}
|
|
54
|
-
const [didUrl, hashFragment] = did.split('#');
|
|
55
|
-
// eslint-disable-next-line no-unused-vars
|
|
56
|
-
// const [didResource, query] = didUrl.split('?')
|
|
57
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
58
|
-
const [_did, _web, urlNoProtocol, ...pathFragments] = didUrl.split(':');
|
|
59
|
-
if (urlNoProtocol.includes('/')) {
|
|
60
|
-
throw new TypeError(`Cannot construct url from did: "${did}". domain-name cannot contain a path.`);
|
|
61
|
-
}
|
|
62
|
-
let parsedUrl;
|
|
63
|
-
try {
|
|
64
|
-
// URI-decode the url (in case it contained a port number,
|
|
65
|
-
// for example, `did:web:localhost%3A8080`
|
|
66
|
-
parsedUrl = new whatwg_url_1.URL('https://' + decodeURIComponent(urlNoProtocol));
|
|
67
|
-
}
|
|
68
|
-
catch (error) {
|
|
69
|
-
throw new TypeError(`Cannot construct url from did: "${did}".`);
|
|
70
|
-
}
|
|
71
|
-
if (pathFragments.length === 0) {
|
|
72
|
-
parsedUrl.pathname = '/.well-known/did.json';
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
parsedUrl.pathname = pathFragments.map(decodeURIComponent).join('/') + '/did.json';
|
|
76
|
-
}
|
|
77
|
-
if (hashFragment) {
|
|
78
|
-
parsedUrl.hash = hashFragment;
|
|
79
|
-
}
|
|
80
|
-
return parsedUrl.toString();
|
|
81
|
-
}
|
|
82
|
-
exports.urlFromDid = urlFromDid;
|
|
83
|
-
/**
|
|
84
|
-
* Initializes the DID Document's keys/proof methods.
|
|
85
|
-
*
|
|
86
|
-
* @example
|
|
87
|
-
* didDocument.id = 'did:ex:123';
|
|
88
|
-
* const {didDocument, keyPairs} = await initKeys({
|
|
89
|
-
* didDocument,
|
|
90
|
-
* cryptoLd,
|
|
91
|
-
* keyMap: {
|
|
92
|
-
* capabilityInvocation: someExistingKey,
|
|
93
|
-
* authentication: 'Ed25519VerificationKey2020',
|
|
94
|
-
* assertionMethod: 'Ed25519VerificationKey2020',
|
|
95
|
-
* keyAgreement: 'X25519KeyAgreementKey2019'
|
|
96
|
-
* }
|
|
97
|
-
* });.
|
|
98
|
-
*
|
|
99
|
-
* @param {object} options - Options hashmap.
|
|
100
|
-
* @param {object} options.didDocument - DID Document.
|
|
101
|
-
* @typedef {object} CryptoLD
|
|
102
|
-
* @param {CryptoLD} [options.cryptoLd] - CryptoLD driver instance,
|
|
103
|
-
* initialized with the key types this DID Document intends to support.
|
|
104
|
-
* @param {object} [options.keyMap] - Map of keys (or key types) by purpose.
|
|
105
|
-
*
|
|
106
|
-
* @returns {Promise<{didDocument: object, keyPairs: Map}>} Resolves with the
|
|
107
|
-
* DID Document initialized with keys, as well as the map of the corresponding
|
|
108
|
-
* key pairs (by key id).
|
|
109
|
-
*/
|
|
110
|
-
async function initKeys({ didDocument, cryptoLd, keyMap } = {}) {
|
|
111
|
-
const doc = { ...didDocument };
|
|
112
|
-
if (!doc.id) {
|
|
113
|
-
throw new TypeError('DID Document "id" property is required to initialize keys.');
|
|
114
|
-
}
|
|
115
|
-
const keyPairs = new Map();
|
|
116
|
-
// Set the defaults for the created keys (if needed)
|
|
117
|
-
const options = { controller: doc.id };
|
|
118
|
-
for (const purpose in keyMap) {
|
|
119
|
-
if (!VERIFICATION_RELATIONSHIPS.has(purpose)) {
|
|
120
|
-
throw new Error(`Unsupported key purpose: "${purpose}".`);
|
|
121
|
-
}
|
|
122
|
-
let key;
|
|
123
|
-
if (typeof keyMap[purpose] === 'string') {
|
|
124
|
-
if (!cryptoLd) {
|
|
125
|
-
throw new Error('Please provide an initialized CryptoLD instance.');
|
|
126
|
-
}
|
|
127
|
-
key = await cryptoLd.generate({ type: keyMap[purpose], ...options });
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
// An existing key has been provided
|
|
131
|
-
key = keyMap[purpose];
|
|
132
|
-
}
|
|
133
|
-
doc[purpose] = [key.export({ publicKey: true })];
|
|
134
|
-
keyPairs.set(key.id, key);
|
|
135
|
-
}
|
|
136
|
-
return { didDocument: doc, keyPairs };
|
|
137
|
-
}
|
|
138
|
-
exports.initKeys = initKeys;
|
|
139
|
-
class DidWebResolver {
|
|
140
|
-
cryptoLd;
|
|
141
|
-
keyMap;
|
|
142
|
-
method;
|
|
143
|
-
logger;
|
|
144
|
-
/**
|
|
145
|
-
* @param cryptoLd {CryptoLD}
|
|
146
|
-
* @param keyMap {object}
|
|
147
|
-
* @param [logger] {object} Logger object (with .log, .error, .warn,
|
|
148
|
-
* etc methods).
|
|
149
|
-
*/
|
|
150
|
-
constructor({ cryptoLd, keyMap = DEFAULT_KEY_MAP, logger = console } = {}) {
|
|
151
|
-
this.method = 'web'; // did:web:... (used for didIo resolver harness)
|
|
152
|
-
this.cryptoLd = cryptoLd;
|
|
153
|
-
this.keyMap = keyMap;
|
|
154
|
-
this.logger = logger;
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* Generates a new DID Document and initializes various authentication
|
|
158
|
-
* and authorization proof purpose keys.
|
|
159
|
-
*
|
|
160
|
-
* @example
|
|
161
|
-
* const url = 'https://example.com'
|
|
162
|
-
* const { didDocument, didKeys } = await didWeb.generate({url})
|
|
163
|
-
* didDocument.id
|
|
164
|
-
* // -> 'did:web:example.com'
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
* Either an `id` or a `url` is required:
|
|
168
|
-
* @param [id] {string} - A did:web DID. If absent, will be converted from url
|
|
169
|
-
* @param [url] {string}
|
|
170
|
-
* @param [seed] {string|Uint8Array}
|
|
171
|
-
*
|
|
172
|
-
* @param [keyMap] {object} A hashmap of key types by purpose.
|
|
173
|
-
*
|
|
174
|
-
* @param cryptoLd
|
|
175
|
-
* @parma [cryptoLd] {object} CryptoLD instance with support for supported
|
|
176
|
-
* crypto suites installed.
|
|
177
|
-
*
|
|
178
|
-
* @returns {Promise<{didDocument: object, keyPairs: object,
|
|
179
|
-
* methodFor: Function}>} Resolves with the generated DID Document, along
|
|
180
|
-
* with the corresponding key pairs used to generate it (for storage in a
|
|
181
|
-
* KMS).
|
|
182
|
-
*/
|
|
183
|
-
async generate({ id, url, seed, keyMap, cryptoLd = this.cryptoLd } = {}) {
|
|
184
|
-
if (!id && !url) {
|
|
185
|
-
throw new TypeError('A "url" or an "id" parameter is required.');
|
|
186
|
-
}
|
|
187
|
-
if (seed && keyMap) {
|
|
188
|
-
throw new TypeError('Either a "seed" or a "keyMap" param must be provided, but not both.');
|
|
189
|
-
}
|
|
190
|
-
const did = id ?? didFromUrl({ url });
|
|
191
|
-
if (seed) {
|
|
192
|
-
const keyPair = await _keyPairFromSecretSeed({
|
|
193
|
-
seed, controller: did, cryptoLd
|
|
194
|
-
});
|
|
195
|
-
keyMap = { assertionMethod: keyPair };
|
|
196
|
-
}
|
|
197
|
-
else {
|
|
198
|
-
keyMap = keyMap || this.keyMap;
|
|
199
|
-
}
|
|
200
|
-
// Compose the DID Document
|
|
201
|
-
let didDocument = {
|
|
202
|
-
'@context': [
|
|
203
|
-
didContext.constants.DID_CONTEXT_URL,
|
|
204
|
-
ed25519Context.constants.CONTEXT_URL,
|
|
205
|
-
x25519Context.constants.CONTEXT_URL
|
|
206
|
-
],
|
|
207
|
-
id: did
|
|
208
|
-
};
|
|
209
|
-
const result = await initKeys({ didDocument, cryptoLd, keyMap });
|
|
210
|
-
const keyPairs = result.keyPairs;
|
|
211
|
-
didDocument = result.didDocument;
|
|
212
|
-
// Convenience function that returns the public/private key pair instance
|
|
213
|
-
// for a given purpose (authentication, assertionMethod, keyAgreement, etc).
|
|
214
|
-
const methodFor = ({ purpose }) => {
|
|
215
|
-
const { id: methodId } = didIo.findVerificationMethod({
|
|
216
|
-
doc: didDocument, purpose
|
|
217
|
-
});
|
|
218
|
-
return keyPairs.get(methodId);
|
|
219
|
-
};
|
|
220
|
-
return { didDocument, keyPairs, methodFor };
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* Fetches a DID Document for a given DID.
|
|
224
|
-
*
|
|
225
|
-
* @example
|
|
226
|
-
* // In Node.js tests, use an agent to avoid self-signed certificate errors
|
|
227
|
-
* const agent = new https.agent({rejectUnauthorized: false});
|
|
228
|
-
*
|
|
229
|
-
* @param {string} [did] For example, 'did:web:example.com'
|
|
230
|
-
* @param {string} [url]
|
|
231
|
-
* @param {https.Agent} [agent] Optional agent used to customize network
|
|
232
|
-
* behavior in Node.js (such as `rejectUnauthorized: false`).
|
|
233
|
-
* @param {object} [logger] Logger object (with .log, .error, .warn,
|
|
234
|
-
* etc methods).
|
|
235
|
-
*
|
|
236
|
-
* @throws {Error}
|
|
237
|
-
*
|
|
238
|
-
* @returns {Promise<object>} Plain parsed JSON object of the DID Document.
|
|
239
|
-
*/
|
|
240
|
-
async get({ did, url, agent, logger = this.logger }) {
|
|
241
|
-
const didUrl = url ?? urlFromDid({ did });
|
|
242
|
-
if (!didUrl) {
|
|
243
|
-
throw new TypeError('A DID or a URL is required.');
|
|
244
|
-
}
|
|
245
|
-
const [urlAuthority, keyIdFragment] = didUrl.split('#');
|
|
246
|
-
let didDocument;
|
|
247
|
-
try {
|
|
248
|
-
logger.info(`Fetching "${urlAuthority}" via http client.`);
|
|
249
|
-
const result = await http_client_1.httpClient.get(urlAuthority, { agent });
|
|
250
|
-
didDocument = result.data;
|
|
251
|
-
}
|
|
252
|
-
catch (e) {
|
|
253
|
-
// status is HTTP status code
|
|
254
|
-
// data is JSON error from the server if available
|
|
255
|
-
const { data, status } = e;
|
|
256
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
257
|
-
logger.error(`Http ${status ?? ''} error:`, data);
|
|
258
|
-
throw e;
|
|
259
|
-
}
|
|
260
|
-
if (didDocument && keyIdFragment) {
|
|
261
|
-
// resolve an individual key
|
|
262
|
-
// Keys are expected to have format: <did:web:...>#<keyIdFragment>
|
|
263
|
-
const didAuthority = didFromUrl({ url: urlAuthority });
|
|
264
|
-
const methodId = `${didAuthority}#${keyIdFragment}`;
|
|
265
|
-
const key = didIo.findVerificationMethod({ doc: didDocument, methodId });
|
|
266
|
-
if (!key) {
|
|
267
|
-
throw new Error(`Key id ${methodId} not found.`);
|
|
268
|
-
}
|
|
269
|
-
const keyPair = await this.cryptoLd.from(key);
|
|
270
|
-
return keyPair.export({ publicKey: true, includeContext: true });
|
|
271
|
-
}
|
|
272
|
-
return didDocument;
|
|
273
|
-
}
|
|
274
|
-
/**
|
|
275
|
-
* Returns the public key (verification method) object for a given DID
|
|
276
|
-
* Document and purpose. Useful in conjunction with a `.get()` call.
|
|
277
|
-
*
|
|
278
|
-
* @example
|
|
279
|
-
* const didDocument = await didKeyDriver.get({did});
|
|
280
|
-
* const authKeyData = didDriver.publicMethodFor({
|
|
281
|
-
* didDocument, purpose: 'authentication'
|
|
282
|
-
* });
|
|
283
|
-
* // You can then create a suite instance object to verify signatures etc.
|
|
284
|
-
* const authPublicKey = await cryptoLd.from(authKeyData);
|
|
285
|
-
* const {verify} = authPublicKey.verifier();
|
|
286
|
-
*
|
|
287
|
-
* @param {object} options - Options hashmap.
|
|
288
|
-
* @param {object} options.didDocument - DID Document (retrieved via a
|
|
289
|
-
* `.get()` or from some other source).
|
|
290
|
-
* @param {string} options.purpose - Verification method purpose, such as
|
|
291
|
-
* 'authentication', 'assertionMethod', 'keyAgreement' and so on.
|
|
292
|
-
*
|
|
293
|
-
* @returns {object} Returns the public key object (obtained from the DID
|
|
294
|
-
* Document), without a `@context`.
|
|
295
|
-
*/
|
|
296
|
-
publicMethodFor({ didDocument, purpose }) {
|
|
297
|
-
const method = didIo.findVerificationMethod({ doc: didDocument, purpose });
|
|
298
|
-
if (!method) {
|
|
299
|
-
throw new Error(`No verification method found for purpose "${purpose}"`);
|
|
300
|
-
}
|
|
301
|
-
return method;
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
exports.DidWebResolver = DidWebResolver;
|
|
305
|
-
/**
|
|
306
|
-
* @param options {object}
|
|
307
|
-
* @param options.seed {string|Uint8Array}
|
|
308
|
-
* @param controller {string}
|
|
309
|
-
* @param cryptoLd {object}
|
|
310
|
-
*
|
|
311
|
-
* @return {Promise<LDKeyPair>}
|
|
312
|
-
*/
|
|
313
|
-
async function _keyPairFromSecretSeed({ seed, controller, cryptoLd }) {
|
|
314
|
-
let seedBytes;
|
|
315
|
-
if (typeof seed === 'string') {
|
|
316
|
-
// Currently only supports base58 multibase / identity multihash encoding.
|
|
317
|
-
if (!seed.startsWith('z1A')) {
|
|
318
|
-
throw new TypeError('"seed" parameter must be a multibase/multihash encoded string, or a Uint8Array.');
|
|
319
|
-
}
|
|
320
|
-
seedBytes = (0, bnid_1.decodeSecretKeySeed)({ secretKeySeed: seed });
|
|
321
|
-
}
|
|
322
|
-
else {
|
|
323
|
-
seedBytes = new Uint8Array(seed);
|
|
324
|
-
}
|
|
325
|
-
return cryptoLd.generate({
|
|
326
|
-
controller, seed: seedBytes, type: 'Ed25519VerificationKey2020'
|
|
327
|
-
});
|
|
328
|
-
}
|
|
329
|
-
//# sourceMappingURL=DidWebResolver.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DidWebResolver.js","sourceRoot":"","sources":["../../src/DidWebResolver.ts"],"names":[],"mappings":";;;AAAA,kEAAkE;AAClE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;;;;;;;;;;;;;;;;;;OAqBG;IACH,eAAe,CAAE,EAAE,WAAW,EAAE,OAAO,EAAyC;QAC9E,MAAM,MAAM,GAAG,KAAK,CAAC,sBAAsB,CAAC,EAAE,GAAG,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC,CAAA;QAC1E,IAAI,CAAC,MAAM,EAAE;YACX,MAAM,IAAI,KAAK,CAAC,6CAA6C,OAAO,GAAG,CAAC,CAAA;SACzE;QACD,OAAO,MAAM,CAAA;IACf,CAAC;CACF;AAxLD,wCAwLC;AAED;;;;;;;GAOG;AACH,KAAK,UAAU,sBAAsB,CAAE,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAsE;IACvI,IAAI,SAAS,CAAA;IACb,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QAC5B,0EAA0E;QAC1E,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE;YAC3B,MAAM,IAAI,SAAS,CAAC,iFAAiF,CAAC,CAAA;SACvG;QACD,SAAS,GAAG,IAAA,0BAAmB,EAAC,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"}
|
package/dist/src/index.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
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 };
|
package/dist/src/index.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.urlFromDid = exports.didFromUrl = exports.DidWebResolver = exports.driver = void 0;
|
|
4
|
-
const DidWebResolver_1 = require("./DidWebResolver");
|
|
5
|
-
Object.defineProperty(exports, "DidWebResolver", { enumerable: true, get: function () { return DidWebResolver_1.DidWebResolver; } });
|
|
6
|
-
Object.defineProperty(exports, "didFromUrl", { enumerable: true, get: function () { return DidWebResolver_1.didFromUrl; } });
|
|
7
|
-
Object.defineProperty(exports, "urlFromDid", { enumerable: true, get: function () { return DidWebResolver_1.urlFromDid; } });
|
|
8
|
-
const driver = (options) => {
|
|
9
|
-
return new DidWebResolver_1.DidWebResolver(options);
|
|
10
|
-
};
|
|
11
|
-
exports.driver = driver;
|
|
12
|
-
//# sourceMappingURL=index.js.map
|
package/dist/src/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AACA,qDAAyE;AAMxD,+FANR,+BAAc,OAMQ;AAAE,2FANR,2BAAU,OAMQ;AAAE,2FANR,2BAAU,OAMQ;AAJvD,MAAM,MAAM,GAAG,CAAC,OAAkF,EAAkB,EAAE;IACpH,OAAO,IAAI,+BAAc,CAAC,OAAO,CAAC,CAAA;AACpC,CAAC,CAAA;AAEQ,wBAAM"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
/* eslint-disable @typescript-eslint/strict-boolean-expressions */
|
|
4
|
-
const chai_1 = require("chai");
|
|
5
|
-
const src_1 = require("../src");
|
|
6
|
-
const ed25519_verification_key_2020_1 = require("@digitalcredentials/ed25519-verification-key-2020");
|
|
7
|
-
const x25519_key_agreement_key_2020_1 = require("@digitalcredentials/x25519-key-agreement-key-2020");
|
|
8
|
-
const crypto_ld_1 = require("crypto-ld");
|
|
9
|
-
const cryptoLd = new crypto_ld_1.CryptoLD();
|
|
10
|
-
cryptoLd.use(ed25519_verification_key_2020_1.Ed25519VerificationKey2020);
|
|
11
|
-
cryptoLd.use(x25519_key_agreement_key_2020_1.X25519KeyAgreementKey2020);
|
|
12
|
-
describe('DidWebDriver', () => {
|
|
13
|
-
describe('constructor', () => {
|
|
14
|
-
it('should exist', () => {
|
|
15
|
-
(0, chai_1.assert)(new src_1.DidWebResolver());
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
describe('publicMethodFor()', () => {
|
|
19
|
-
it('should fetch a public key object for a given purpose', async () => {
|
|
20
|
-
const didWeb = new src_1.DidWebResolver({ cryptoLd });
|
|
21
|
-
const url = 'https://example.com';
|
|
22
|
-
const { didDocument } = await didWeb.generate({ url });
|
|
23
|
-
const keyAgreementKey = didWeb.publicMethodFor({
|
|
24
|
-
didDocument, purpose: 'keyAgreement'
|
|
25
|
-
});
|
|
26
|
-
chai_1.assert.equal(keyAgreementKey.type, 'X25519KeyAgreementKey2020');
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
describe('generate()', () => {
|
|
30
|
-
let didWeb;
|
|
31
|
-
beforeEach(async () => {
|
|
32
|
-
didWeb = new src_1.DidWebResolver({ cryptoLd });
|
|
33
|
-
});
|
|
34
|
-
it('should generate using default key map', async () => {
|
|
35
|
-
const url = 'https://example.com';
|
|
36
|
-
const { didDocument, keyPairs } = await didWeb.generate({ url });
|
|
37
|
-
chai_1.assert.property(didDocument, '@context');
|
|
38
|
-
chai_1.assert.equal(didDocument.id, 'did:web:example.com');
|
|
39
|
-
chai_1.assert.equal(didDocument.capabilityInvocation[0].type, 'Ed25519VerificationKey2020');
|
|
40
|
-
chai_1.assert.equal(didDocument.authentication[0].type, 'Ed25519VerificationKey2020');
|
|
41
|
-
chai_1.assert.equal(didDocument.assertionMethod[0].type, 'Ed25519VerificationKey2020');
|
|
42
|
-
chai_1.assert.equal(didDocument.capabilityDelegation[0].type, 'Ed25519VerificationKey2020');
|
|
43
|
-
(0, chai_1.assert)(keyPairs);
|
|
44
|
-
});
|
|
45
|
-
it('should return methodFor convenience function', async () => {
|
|
46
|
-
const url = 'https://example.com';
|
|
47
|
-
const { methodFor } = await didWeb.generate({ url });
|
|
48
|
-
const keyAgreementKey = methodFor({ purpose: 'keyAgreement' });
|
|
49
|
-
chai_1.assert.property(keyAgreementKey, 'type', 'X25519KeyAgreementKey2020');
|
|
50
|
-
chai_1.assert.property(keyAgreementKey, 'controller', 'did:web:example.com');
|
|
51
|
-
chai_1.assert.property(keyAgreementKey, 'publicKeyMultibase');
|
|
52
|
-
chai_1.assert.property(keyAgreementKey, 'privateKeyMultibase');
|
|
53
|
-
});
|
|
54
|
-
it('should generate from seed', async () => {
|
|
55
|
-
const seed = 'z1AhV1bADy7RepJ64mvH7Kk7htFNGc7EA1WA5nGzLSTWc6o';
|
|
56
|
-
const url = 'https://example.com';
|
|
57
|
-
const { didDocument, methodFor } = await didWeb.generate({ url, seed });
|
|
58
|
-
chai_1.assert.property(didDocument, 'id', 'did:web:example.com');
|
|
59
|
-
const assertionKey = methodFor({ purpose: 'assertionMethod' });
|
|
60
|
-
chai_1.assert.property(assertionKey, 'id', 'did:web:example.com#z6MkmDMjfkjs9XPCN1LfoQQRHz1mJ8PEdiVYC66XKhj3wGyB');
|
|
61
|
-
chai_1.assert.property(assertionKey, 'type', 'Ed25519VerificationKey2020');
|
|
62
|
-
chai_1.assert.property(assertionKey, 'controller', 'did:web:example.com');
|
|
63
|
-
chai_1.assert.property(assertionKey, 'publicKeyMultibase', 'z6MkmDMjfkjs9XPCN1LfoQQRHz1mJ8PEdiVYC66XKhj3wGyB');
|
|
64
|
-
chai_1.assert.property(assertionKey, 'privateKeyMultibase');
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
describe('urlFromDid()', () => {
|
|
68
|
-
it('should error on non-did:web dids', () => {
|
|
69
|
-
let error;
|
|
70
|
-
try {
|
|
71
|
-
(0, src_1.urlFromDid)({ did: 'did:example:1234' });
|
|
72
|
-
}
|
|
73
|
-
catch (e) {
|
|
74
|
-
error = e;
|
|
75
|
-
}
|
|
76
|
-
chai_1.assert.equal(error.message, 'DID Method not supported: "did:example:1234".');
|
|
77
|
-
});
|
|
78
|
-
it('should error on pattern did:web:domain/path/subpath', () => {
|
|
79
|
-
const invalidDids = [
|
|
80
|
-
'did:web:example.com/path',
|
|
81
|
-
'did:web:example.com/path/subpath',
|
|
82
|
-
'did:web:example.com/path/subpath?query=string',
|
|
83
|
-
'did:web:example.com/path/subpath#fragment',
|
|
84
|
-
'did:web:example.com/:user:alice'
|
|
85
|
-
];
|
|
86
|
-
invalidDids.forEach((did) => {
|
|
87
|
-
let error;
|
|
88
|
-
try {
|
|
89
|
-
(0, src_1.urlFromDid)({ did });
|
|
90
|
-
}
|
|
91
|
-
catch (e) {
|
|
92
|
-
error = e;
|
|
93
|
-
}
|
|
94
|
-
if (error) {
|
|
95
|
-
chai_1.assert.include(error.message, 'domain-name cannot contain a path.');
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
chai_1.assert.fail('should have thrown error for did: ' + did);
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
it('should convert first id fragment to pathname plus default path', () => {
|
|
103
|
-
chai_1.assert.equal((0, src_1.urlFromDid)({ did: 'did:web:example.com' }), 'https://example.com/.well-known/did.json');
|
|
104
|
-
});
|
|
105
|
-
it('should url-decode host', () => {
|
|
106
|
-
chai_1.assert.equal((0, src_1.urlFromDid)({ did: 'did:web:localhost%3A8080' }), 'https://localhost:8080/.well-known/did.json');
|
|
107
|
-
});
|
|
108
|
-
it('should preserve hash fragments for dids without paths', () => {
|
|
109
|
-
const url = (0, src_1.urlFromDid)({ did: 'did:web:localhost%3A8080#keyId' });
|
|
110
|
-
chai_1.assert.equal(url, 'https://localhost:8080/.well-known/did.json#keyId');
|
|
111
|
-
});
|
|
112
|
-
// See: https://w3c-ccg.github.io/did-method-web/#example-creating-the-did-with-optional-path
|
|
113
|
-
it('should work with optional path', () => {
|
|
114
|
-
const url = (0, src_1.urlFromDid)({ did: 'did:web:w3c-ccg.github.io:user:alice' });
|
|
115
|
-
chai_1.assert.equal(url, 'https://w3c-ccg.github.io/user/alice/did.json');
|
|
116
|
-
});
|
|
117
|
-
// See: https://w3c-ccg.github.io/did-method-web/#example-creating-the-did-with-optional-path-and-port
|
|
118
|
-
it('should work with optional path and port', () => {
|
|
119
|
-
const url = (0, src_1.urlFromDid)({ did: 'did:web:example.com%3A3000:user:alice' });
|
|
120
|
-
chai_1.assert.equal(url, 'https://example.com:3000/user/alice/did.json');
|
|
121
|
-
});
|
|
122
|
-
it('should preserve hash fragments for dids with optional path', () => {
|
|
123
|
-
const url = (0, src_1.urlFromDid)({ did: 'did:web:w3c-ccg.github.io:user:alice#keyId' });
|
|
124
|
-
chai_1.assert.equal(url, 'https://w3c-ccg.github.io/user/alice/did.json#keyId');
|
|
125
|
-
});
|
|
126
|
-
it('should preserve hash fragments for dids with optional path and port', () => {
|
|
127
|
-
const url = (0, src_1.urlFromDid)({ did: 'did:web:example.com%3A3000:user:alice#keyId' });
|
|
128
|
-
chai_1.assert.equal(url, 'https://example.com:3000/user/alice/did.json#keyId');
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
describe('didFromUrl', () => {
|
|
132
|
-
it('should error on missing url', () => {
|
|
133
|
-
let error;
|
|
134
|
-
try {
|
|
135
|
-
(0, src_1.didFromUrl)();
|
|
136
|
-
}
|
|
137
|
-
catch (e) {
|
|
138
|
-
error = e;
|
|
139
|
-
}
|
|
140
|
-
chai_1.assert.equal(error.message, 'Cannot convert url to did, missing url.');
|
|
141
|
-
});
|
|
142
|
-
it('should error on http URLs', () => {
|
|
143
|
-
let error;
|
|
144
|
-
try {
|
|
145
|
-
(0, src_1.didFromUrl)({ url: 'http://example.com' });
|
|
146
|
-
}
|
|
147
|
-
catch (e) {
|
|
148
|
-
error = e;
|
|
149
|
-
}
|
|
150
|
-
chai_1.assert.equal(error.message, 'did:web does not support non-HTTPS URLs.');
|
|
151
|
-
});
|
|
152
|
-
it('should error on invalid URLs', () => {
|
|
153
|
-
let error;
|
|
154
|
-
try {
|
|
155
|
-
(0, src_1.didFromUrl)({ url: 'non-url' });
|
|
156
|
-
}
|
|
157
|
-
catch (e) {
|
|
158
|
-
error = e;
|
|
159
|
-
}
|
|
160
|
-
chai_1.assert.equal(error.message, 'Invalid url: "non-url".');
|
|
161
|
-
});
|
|
162
|
-
it('should convert host to did identifier', () => {
|
|
163
|
-
chai_1.assert.equal((0, src_1.didFromUrl)({ url: 'https://localhost' }), 'did:web:localhost');
|
|
164
|
-
chai_1.assert.equal((0, src_1.didFromUrl)({ url: 'https://example.com' }), 'did:web:example.com');
|
|
165
|
-
});
|
|
166
|
-
it('should url-encode host', () => {
|
|
167
|
-
chai_1.assert.equal((0, src_1.didFromUrl)({ url: 'https://localhost:8080' }), 'did:web:localhost%3A8080');
|
|
168
|
-
});
|
|
169
|
-
it('should leave off the default / path', () => {
|
|
170
|
-
chai_1.assert.equal((0, src_1.didFromUrl)({ url: 'https://example.com/' }), 'did:web:example.com');
|
|
171
|
-
});
|
|
172
|
-
it('should encode path / separators as :', () => {
|
|
173
|
-
chai_1.assert.equal((0, src_1.didFromUrl)({ url: 'https://example.com/path/subpath/did.json' }), 'did:web:example.com:path:subpath');
|
|
174
|
-
});
|
|
175
|
-
it('should drop the default /.well-known/did.json pathname', () => {
|
|
176
|
-
chai_1.assert.equal((0, src_1.didFromUrl)({ url: 'https://example.com/.well-known/did.json' }), 'did:web:example.com');
|
|
177
|
-
});
|
|
178
|
-
it('should url-encode path fragments', () => {
|
|
179
|
-
chai_1.assert.equal((0, src_1.didFromUrl)({ url: 'https://example.com/path/some+subpath' }), 'did:web:example.com:path:some%2Bsubpath');
|
|
180
|
-
});
|
|
181
|
-
});
|
|
182
|
-
});
|
|
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