@sphereon/ssi-sdk-ext.did-resolver-key 0.28.1-feature.oyd.cmsm.improv.21 → 0.28.1-next.54

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.
Files changed (54) hide show
  1. package/dist/index.cjs +527 -0
  2. package/dist/index.cjs.map +1 -0
  3. package/dist/index.d.cts +21 -0
  4. package/dist/index.d.ts +18 -5
  5. package/dist/index.js +491 -87
  6. package/dist/index.js.map +1 -1
  7. package/package.json +23 -10
  8. package/src/__tests__/__snapshots__/secp256r1.test.ts.snap +249 -1
  9. package/src/__tests__/__snapshots__/secp384r1.test.ts.snap +249 -1
  10. package/src/__tests__/__snapshots__/secp521r1.test.ts.snap +280 -1
  11. package/src/__tests__/key_resolver.test.ts +2 -1
  12. package/src/__tests__/secp256r1.test.ts +4 -4
  13. package/src/__tests__/secp384r1.test.ts +3 -3
  14. package/src/__tests__/secp521r1.test.ts +3 -2
  15. package/src/drivers/bls12381g2.ts +3 -1
  16. package/src/drivers/ed25519.ts +6 -4
  17. package/src/drivers/secp256k1.ts +3 -1
  18. package/src/drivers/secp256r1.ts +4 -3
  19. package/src/drivers/secp384r1.ts +3 -1
  20. package/src/drivers/secp521r1.ts +3 -1
  21. package/src/index.ts +3 -1
  22. package/dist/drivers/bls12381g2.d.ts +0 -8
  23. package/dist/drivers/bls12381g2.d.ts.map +0 -1
  24. package/dist/drivers/bls12381g2.js +0 -49
  25. package/dist/drivers/bls12381g2.js.map +0 -1
  26. package/dist/drivers/ed25519.d.ts +0 -8
  27. package/dist/drivers/ed25519.d.ts.map +0 -1
  28. package/dist/drivers/ed25519.js +0 -118
  29. package/dist/drivers/ed25519.js.map +0 -1
  30. package/dist/drivers/jwk.jcs.d.ts +0 -8
  31. package/dist/drivers/jwk.jcs.d.ts.map +0 -1
  32. package/dist/drivers/jwk.jcs.js +0 -23
  33. package/dist/drivers/jwk.jcs.js.map +0 -1
  34. package/dist/drivers/secp256k1.d.ts +0 -8
  35. package/dist/drivers/secp256k1.d.ts.map +0 -1
  36. package/dist/drivers/secp256k1.js +0 -49
  37. package/dist/drivers/secp256k1.js.map +0 -1
  38. package/dist/drivers/secp256r1.d.ts +0 -24
  39. package/dist/drivers/secp256r1.d.ts.map +0 -1
  40. package/dist/drivers/secp256r1.js +0 -99
  41. package/dist/drivers/secp256r1.js.map +0 -1
  42. package/dist/drivers/secp384r1.d.ts +0 -24
  43. package/dist/drivers/secp384r1.d.ts.map +0 -1
  44. package/dist/drivers/secp384r1.js +0 -99
  45. package/dist/drivers/secp384r1.js.map +0 -1
  46. package/dist/drivers/secp521r1.d.ts +0 -23
  47. package/dist/drivers/secp521r1.d.ts.map +0 -1
  48. package/dist/drivers/secp521r1.js +0 -87
  49. package/dist/drivers/secp521r1.js.map +0 -1
  50. package/dist/index.d.ts.map +0 -1
  51. package/dist/types.d.ts +0 -14
  52. package/dist/types.d.ts.map +0 -1
  53. package/dist/types.js +0 -6
  54. package/dist/types.js.map +0 -1
package/dist/index.cjs ADDED
@@ -0,0 +1,527 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // src/index.ts
32
+ var index_exports = {};
33
+ __export(index_exports, {
34
+ DID_JSON: () => DID_JSON,
35
+ DID_LD_JSON: () => DID_LD_JSON,
36
+ default: () => index_default,
37
+ getResolver: () => getResolver
38
+ });
39
+ module.exports = __toCommonJS(index_exports);
40
+ var import_varint = __toESM(require("varint"), 1);
41
+ var import_base58 = require("multiformats/bases/base58");
42
+
43
+ // src/drivers/ed25519.ts
44
+ var u8a = __toESM(require("uint8arrays"), 1);
45
+ var import_ed25519 = require("@stablelib/ed25519");
46
+
47
+ // src/types.ts
48
+ var DID_LD_JSON = "application/did+ld+json";
49
+ var DID_JSON = "application/did+json";
50
+
51
+ // src/drivers/ed25519.ts
52
+ var { toString } = u8a;
53
+ function encodeKey(key, encodeKey2) {
54
+ const bytes = new Uint8Array(key.length + 2);
55
+ bytes[0] = encodeKey2 ?? 236;
56
+ bytes[1] = 1;
57
+ bytes.set(key, 2);
58
+ return `z${toString(bytes, "base58btc")}`;
59
+ }
60
+ __name(encodeKey, "encodeKey");
61
+ var keyToDidDoc = /* @__PURE__ */ __name((args) => {
62
+ const { options } = args;
63
+ if (!options?.publicKeyFormat) {
64
+ return keyToDidDoc2020(args);
65
+ }
66
+ switch (options.publicKeyFormat) {
67
+ case "Ed25519VerificationKey2018":
68
+ case "X25519KeyAgreementKey2019":
69
+ return keyToDidDoc2018_2019(args);
70
+ case "Ed25519VerificationKey2020":
71
+ case "X25519KeyAgreementKey2020":
72
+ case "Multikey":
73
+ return keyToDidDoc2020(args);
74
+ default:
75
+ throw Error(`${options.publicKeyFormat} not supported yet for the ed25519 driver`);
76
+ }
77
+ }, "keyToDidDoc");
78
+ var keyToDidDoc2018_2019 = /* @__PURE__ */ __name(({ pubKeyBytes, fingerprint, contentType }) => {
79
+ const did = `did:key:${fingerprint}`;
80
+ const keyId = `${did}#${fingerprint}`;
81
+ const x25519PubBytes = (0, import_ed25519.convertPublicKeyToX25519)(pubKeyBytes);
82
+ const x25519KeyId = `${did}#${encodeKey(x25519PubBytes)}`;
83
+ return {
84
+ ...contentType === DID_LD_JSON && {
85
+ "@context": [
86
+ "https://www.w3.org/ns/did/v1",
87
+ "https://w3id.org/security/suites/ed25519-2018/v1",
88
+ "https://w3id.org/security/suites/x25519-2019/v1"
89
+ ]
90
+ },
91
+ id: did,
92
+ verificationMethod: [
93
+ {
94
+ id: keyId,
95
+ type: "Ed25519VerificationKey2018",
96
+ controller: did,
97
+ publicKeyBase58: toString(pubKeyBytes, "base58btc")
98
+ },
99
+ {
100
+ id: x25519KeyId,
101
+ type: "X25519KeyAgreementKey2019",
102
+ controller: did,
103
+ publicKeyBase58: toString(x25519PubBytes, "base58btc")
104
+ }
105
+ ],
106
+ authentication: [
107
+ keyId
108
+ ],
109
+ assertionMethod: [
110
+ keyId
111
+ ],
112
+ capabilityDelegation: [
113
+ keyId
114
+ ],
115
+ capabilityInvocation: [
116
+ keyId
117
+ ],
118
+ keyAgreement: [
119
+ x25519KeyId
120
+ ]
121
+ };
122
+ }, "keyToDidDoc2018_2019");
123
+ var keyToDidDoc2020 = /* @__PURE__ */ __name(({ pubKeyBytes, fingerprint, contentType }) => {
124
+ const did = `did:key:${fingerprint}`;
125
+ const keyId = `${did}#${fingerprint}`;
126
+ const x25519PubBytes = (0, import_ed25519.convertPublicKeyToX25519)(pubKeyBytes);
127
+ const x25519KeyId = `${did}#${encodeKey(x25519PubBytes)}`;
128
+ return {
129
+ ...contentType === DID_LD_JSON && {
130
+ "@context": [
131
+ "https://www.w3.org/ns/did/v1",
132
+ "https://w3id.org/security/suites/ed25519-2020/v1",
133
+ "https://w3id.org/security/suites/x25519-2020/v1"
134
+ ]
135
+ },
136
+ id: did,
137
+ verificationMethod: [
138
+ {
139
+ id: keyId,
140
+ type: "Ed25519VerificationKey2020",
141
+ controller: did,
142
+ publicKeyMultibase: encodeKey(pubKeyBytes, 237)
143
+ }
144
+ ],
145
+ authentication: [
146
+ keyId
147
+ ],
148
+ assertionMethod: [
149
+ keyId
150
+ ],
151
+ capabilityDelegation: [
152
+ keyId
153
+ ],
154
+ capabilityInvocation: [
155
+ keyId
156
+ ],
157
+ keyAgreement: [
158
+ {
159
+ id: x25519KeyId,
160
+ type: "X25519KeyAgreementKey2020",
161
+ controller: did,
162
+ publicKeyMultibase: encodeKey(x25519PubBytes, 236)
163
+ }
164
+ ]
165
+ };
166
+ }, "keyToDidDoc2020");
167
+ var ed25519_default = {
168
+ keyToDidDoc
169
+ };
170
+
171
+ // src/drivers/bls12381g2.ts
172
+ var u8a2 = __toESM(require("uint8arrays"), 1);
173
+ var { toString: toString2 } = u8a2;
174
+ var keyToDidDoc2 = /* @__PURE__ */ __name(({ pubKeyBytes, fingerprint }) => {
175
+ const did = `did:key:${fingerprint}`;
176
+ const keyId = `${did}#${fingerprint}`;
177
+ return {
178
+ id: did,
179
+ verificationMethod: [
180
+ {
181
+ id: keyId,
182
+ type: "Bls12381G2Key2020",
183
+ controller: did,
184
+ publicKeyBase58: toString2(pubKeyBytes, "base58btc")
185
+ }
186
+ ],
187
+ authentication: [
188
+ keyId
189
+ ],
190
+ assertionMethod: [
191
+ keyId
192
+ ],
193
+ capabilityDelegation: [
194
+ keyId
195
+ ],
196
+ capabilityInvocation: [
197
+ keyId
198
+ ]
199
+ };
200
+ }, "keyToDidDoc");
201
+ var bls12381g2_default = {
202
+ keyToDidDoc: keyToDidDoc2
203
+ };
204
+
205
+ // src/drivers/secp256k1.ts
206
+ var u8a3 = __toESM(require("uint8arrays"), 1);
207
+ var { toString: toString3 } = u8a3;
208
+ var keyToDidDoc3 = /* @__PURE__ */ __name(({ pubKeyBytes, fingerprint }) => {
209
+ const did = `did:key:${fingerprint}`;
210
+ const keyId = `${did}#${fingerprint}`;
211
+ return {
212
+ id: did,
213
+ verificationMethod: [
214
+ {
215
+ id: keyId,
216
+ type: "Secp256k1VerificationKey2018",
217
+ controller: did,
218
+ publicKeyBase58: toString3(pubKeyBytes, "base58btc")
219
+ }
220
+ ],
221
+ authentication: [
222
+ keyId
223
+ ],
224
+ assertionMethod: [
225
+ keyId
226
+ ],
227
+ capabilityDelegation: [
228
+ keyId
229
+ ],
230
+ capabilityInvocation: [
231
+ keyId
232
+ ]
233
+ };
234
+ }, "keyToDidDoc");
235
+ var secp256k1_default = {
236
+ keyToDidDoc: keyToDidDoc3
237
+ };
238
+
239
+ // src/drivers/secp256r1.ts
240
+ var nist_weierstrauss = __toESM(require("nist-weierstrauss"), 1);
241
+ var u8a4 = __toESM(require("uint8arrays"), 1);
242
+ var { fromString } = u8a4;
243
+ function keyToDidDoc4({ pubKeyBytes, fingerprint }) {
244
+ const did = `did:key:${fingerprint}`;
245
+ const keyId = `${did}#${fingerprint}`;
246
+ const key = pubKeyBytesToXY(pubKeyBytes);
247
+ return {
248
+ id: did,
249
+ verificationMethod: [
250
+ {
251
+ id: keyId,
252
+ type: "JsonWebKey2020",
253
+ controller: did,
254
+ publicKeyJwk: {
255
+ kty: "EC",
256
+ crv: "P-256",
257
+ x: key.xm,
258
+ y: key.ym
259
+ }
260
+ }
261
+ ],
262
+ authentication: [
263
+ keyId
264
+ ],
265
+ assertionMethod: [
266
+ keyId
267
+ ],
268
+ capabilityDelegation: [
269
+ keyId
270
+ ],
271
+ capabilityInvocation: [
272
+ keyId
273
+ ]
274
+ };
275
+ }
276
+ __name(keyToDidDoc4, "keyToDidDoc");
277
+ function pubKeyBytesToXY(pubKeyBytes) {
278
+ if (!nist_weierstrauss.nist_weierstrauss_common.testUint8Array(pubKeyBytes)) {
279
+ throw new TypeError("input must be a Uint8Array");
280
+ }
281
+ const publicKeyHex = nist_weierstrauss.nist_weierstrauss_common.pubKeyBytesToHex(pubKeyBytes);
282
+ const bytesCount = publicKeyHex.length / 2;
283
+ if (bytesCount == 64) {
284
+ return nist_weierstrauss.nist_weierstrauss_common.publicKeyToXY(publicKeyHex);
285
+ }
286
+ if (bytesCount == 65) {
287
+ if (publicKeyHex.slice(0, 2) == "04") {
288
+ const publicKey = publicKeyHex.slice(2);
289
+ return nist_weierstrauss.nist_weierstrauss_common.publicKeyToXY(publicKey);
290
+ }
291
+ }
292
+ if (bytesCount == 33) {
293
+ if (publicKeyHex.slice(0, 2) == "03" || publicKeyHex.slice(0, 2) == "02") {
294
+ const publicKey = fromString(publicKeyHex, "base16");
295
+ const point = nist_weierstrauss.secp256r1.ECPointDecompress(publicKey);
296
+ return nist_weierstrauss.nist_weierstrauss_common.publicKeyIntToXY(point);
297
+ }
298
+ }
299
+ throw new Error("Unexpected pubKeyBytes");
300
+ }
301
+ __name(pubKeyBytesToXY, "pubKeyBytesToXY");
302
+ var secp256r1_default = {
303
+ keyToDidDoc: keyToDidDoc4
304
+ };
305
+
306
+ // src/drivers/secp384r1.ts
307
+ var u8a5 = __toESM(require("uint8arrays"), 1);
308
+ var nist_weierstrauss2 = __toESM(require("nist-weierstrauss"), 1);
309
+ var { fromString: fromString2 } = u8a5;
310
+ function keyToDidDoc5({ pubKeyBytes, fingerprint }) {
311
+ const did = `did:key:${fingerprint}`;
312
+ const keyId = `${did}#${fingerprint}`;
313
+ const key = pubKeyBytesToXY2(pubKeyBytes);
314
+ return {
315
+ id: did,
316
+ verificationMethod: [
317
+ {
318
+ id: keyId,
319
+ type: "JsonWebKey2020",
320
+ controller: did,
321
+ publicKeyJwk: {
322
+ kty: "EC",
323
+ crv: "P-384",
324
+ x: key.xm,
325
+ y: key.ym
326
+ }
327
+ }
328
+ ],
329
+ authentication: [
330
+ keyId
331
+ ],
332
+ assertionMethod: [
333
+ keyId
334
+ ],
335
+ capabilityDelegation: [
336
+ keyId
337
+ ],
338
+ capabilityInvocation: [
339
+ keyId
340
+ ]
341
+ };
342
+ }
343
+ __name(keyToDidDoc5, "keyToDidDoc");
344
+ function pubKeyBytesToXY2(pubKeyBytes) {
345
+ if (!nist_weierstrauss2.nist_weierstrauss_common.testUint8Array(pubKeyBytes)) {
346
+ throw new TypeError("input must be a Uint8Array");
347
+ }
348
+ const publicKeyHex = nist_weierstrauss2.nist_weierstrauss_common.pubKeyBytesToHex(pubKeyBytes);
349
+ const bytesCount = publicKeyHex.length / 2;
350
+ if (bytesCount == 96) {
351
+ return nist_weierstrauss2.nist_weierstrauss_common.publicKeyToXY(publicKeyHex);
352
+ }
353
+ if (bytesCount == 97) {
354
+ if (publicKeyHex.slice(0, 2) == "04") {
355
+ const publicKey = publicKeyHex.slice(2);
356
+ return nist_weierstrauss2.nist_weierstrauss_common.publicKeyToXY(publicKey);
357
+ }
358
+ }
359
+ if (bytesCount == 49) {
360
+ if (publicKeyHex.slice(0, 2) == "03" || publicKeyHex.slice(0, 2) == "02") {
361
+ const publicKey = fromString2(publicKeyHex, "base16");
362
+ const point = nist_weierstrauss2.secp384r1.ECPointDecompress(publicKey);
363
+ return nist_weierstrauss2.nist_weierstrauss_common.publicKeyIntToXY(point);
364
+ }
365
+ }
366
+ throw new Error("Unexpected pubKeyBytes");
367
+ }
368
+ __name(pubKeyBytesToXY2, "pubKeyBytesToXY");
369
+ var secp384r1_default = {
370
+ keyToDidDoc: keyToDidDoc5
371
+ };
372
+
373
+ // src/drivers/secp521r1.ts
374
+ var u8a6 = __toESM(require("uint8arrays"), 1);
375
+ var nist_weierstrauss3 = __toESM(require("nist-weierstrauss"), 1);
376
+ var { fromString: fromString3 } = u8a6;
377
+ function keyToDidDoc6({ pubKeyBytes, fingerprint }) {
378
+ const did = `did:key:${fingerprint}`;
379
+ const keyId = `${did}#${fingerprint}`;
380
+ const key = pubKeyBytesToXY3(pubKeyBytes);
381
+ return {
382
+ id: did,
383
+ verificationMethod: [
384
+ {
385
+ id: keyId,
386
+ type: "JsonWebKey2020",
387
+ controller: did,
388
+ publicKeyJwk: {
389
+ kty: "EC",
390
+ crv: "P-521",
391
+ x: key.xm,
392
+ y: key.ym
393
+ }
394
+ }
395
+ ],
396
+ authentication: [
397
+ keyId
398
+ ],
399
+ assertionMethod: [
400
+ keyId
401
+ ],
402
+ capabilityDelegation: [
403
+ keyId
404
+ ],
405
+ capabilityInvocation: [
406
+ keyId
407
+ ]
408
+ };
409
+ }
410
+ __name(keyToDidDoc6, "keyToDidDoc");
411
+ function pubKeyBytesToXY3(pubKeyBytes) {
412
+ if (!nist_weierstrauss3.nist_weierstrauss_common.testUint8Array(pubKeyBytes)) {
413
+ throw new TypeError("input must be a Uint8Array");
414
+ }
415
+ const publicKeyHex = nist_weierstrauss3.nist_weierstrauss_common.pubKeyBytesToHex(pubKeyBytes);
416
+ if (132 <= publicKeyHex.length && publicKeyHex.length <= 134) {
417
+ if (publicKeyHex.slice(0, 2) == "03" || publicKeyHex.slice(0, 2) == "02") {
418
+ const publicKey = fromString3(publicKeyHex, "base16");
419
+ const point = nist_weierstrauss3.secp521r1.ECPointDecompress(publicKey);
420
+ return nist_weierstrauss3.nist_weierstrauss_common.publicKeyIntToXY(point);
421
+ }
422
+ }
423
+ throw new Error("Unexpected pubKeyBytes");
424
+ }
425
+ __name(pubKeyBytesToXY3, "pubKeyBytesToXY");
426
+ var secp521r1_default = {
427
+ keyToDidDoc: keyToDidDoc6
428
+ };
429
+
430
+ // src/drivers/jwk.jcs.ts
431
+ var import_ssi_sdk_ext = require("@sphereon/ssi-sdk-ext.key-utils");
432
+ var keyToDidDoc7 = /* @__PURE__ */ __name(({ pubKeyBytes, fingerprint, contentType }) => {
433
+ const did = `did:key:${fingerprint}`;
434
+ const keyId = `${did}#${fingerprint}`;
435
+ const publicKeyJwk = (0, import_ssi_sdk_ext.jwkJcsDecode)(pubKeyBytes);
436
+ return {
437
+ ...contentType === DID_LD_JSON && {
438
+ "@context": [
439
+ "https://www.w3.org/ns/did/v1",
440
+ "https://w3id.org/security/suites/jws-2020/v1"
441
+ ]
442
+ },
443
+ id: did,
444
+ verificationMethod: [
445
+ {
446
+ id: keyId,
447
+ type: "JsonWebKey2020",
448
+ controller: did,
449
+ publicKeyJwk
450
+ }
451
+ ],
452
+ authentication: [
453
+ keyId
454
+ ],
455
+ assertionMethod: [
456
+ keyId
457
+ ],
458
+ capabilityDelegation: [
459
+ keyId
460
+ ],
461
+ capabilityInvocation: [
462
+ keyId
463
+ ]
464
+ };
465
+ }, "keyToDidDoc");
466
+ var jwk_jcs_default = {
467
+ keyToDidDoc: keyToDidDoc7
468
+ };
469
+
470
+ // src/index.ts
471
+ var { decode } = import_varint.default;
472
+ var prefixToDriverMap = {
473
+ 231: secp256k1_default,
474
+ 237: ed25519_default,
475
+ 4608: secp256r1_default,
476
+ 4609: secp384r1_default,
477
+ 4610: secp521r1_default,
478
+ 235: bls12381g2_default,
479
+ 60241: jwk_jcs_default
480
+ };
481
+ var getResolver = /* @__PURE__ */ __name(() => {
482
+ return {
483
+ key: /* @__PURE__ */ __name(async (did, parsed, r, options) => {
484
+ const contentType = options.accept || DID_LD_JSON;
485
+ const response = {
486
+ didResolutionMetadata: {
487
+ contentType
488
+ },
489
+ didDocument: null,
490
+ didDocumentMetadata: {}
491
+ };
492
+ try {
493
+ const multicodecPubKey = import_base58.base58btc.decode(parsed.id);
494
+ const keyType = decode(multicodecPubKey);
495
+ const pubKeyBytes = multicodecPubKey.slice(decode.bytes);
496
+ const args = {
497
+ pubKeyBytes,
498
+ fingerprint: parsed.id,
499
+ contentType,
500
+ options
501
+ };
502
+ const doc = await prefixToDriverMap[keyType].keyToDidDoc(args);
503
+ if (contentType === DID_LD_JSON) {
504
+ if (!doc["@context"]) {
505
+ doc["@context"] = "https://w3id.org/did/v1";
506
+ } else if (Array.isArray(doc["@context"]) && !doc["@context"].includes("https://w3id.org/did/v1") && !doc["@context"].includes("https://www.w3.org/ns/did/v1")) {
507
+ doc["@context"].push("https://w3id.org/did/v1");
508
+ }
509
+ response.didDocument = doc;
510
+ } else if (contentType === DID_JSON) {
511
+ response.didDocument = doc;
512
+ } else {
513
+ delete response.didResolutionMetadata.contentType;
514
+ response.didResolutionMetadata.error = "representationNotSupported";
515
+ }
516
+ } catch (e) {
517
+ response.didResolutionMetadata.error = "invalidDid";
518
+ response.didResolutionMetadata.message = e.toString();
519
+ }
520
+ return response;
521
+ }, "key")
522
+ };
523
+ }, "getResolver");
524
+ var index_default = {
525
+ getResolver
526
+ };
527
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/drivers/ed25519.ts","../src/types.ts","../src/drivers/bls12381g2.ts","../src/drivers/secp256k1.ts","../src/drivers/secp256r1.ts","../src/drivers/secp384r1.ts","../src/drivers/secp521r1.ts","../src/drivers/jwk.jcs.ts"],"sourcesContent":["import varint from 'varint'\nconst { decode } = varint\n// @ts-ignore\nimport { base58btc } from 'multiformats/bases/base58'\nimport ed25519 from './drivers/ed25519'\nimport bls12381g2 from './drivers/bls12381g2'\nimport secp256k1 from './drivers/secp256k1'\nimport secp256r1 from './drivers/secp256r1'\nimport secp384r1 from './drivers/secp384r1'\nimport secp521r1 from './drivers/secp521r1'\nimport { DIDResolutionResult, ParsedDID, Resolvable, ResolverRegistry } from 'did-resolver'\nimport jwkJcs from './drivers/jwk.jcs'\nimport { DID_JSON, DID_LD_JSON, DIDKeyResolutionOptions, KeyToDidDocArgs } from './types'\n\nexport * from './types'\n\nconst prefixToDriverMap: any = {\n 0xe7: secp256k1,\n 0xed: ed25519,\n 0x1200: secp256r1,\n 0x1201: secp384r1,\n 0x1202: secp521r1,\n 0xeb: bls12381g2,\n 0xeb51: jwkJcs,\n}\n\nexport const getResolver = (): ResolverRegistry => {\n return {\n key: async (did: string, parsed: ParsedDID, r: Resolvable, options: DIDKeyResolutionOptions) => {\n const contentType = options.accept || DID_LD_JSON\n const response: DIDResolutionResult = {\n didResolutionMetadata: { contentType },\n didDocument: null,\n didDocumentMetadata: {},\n }\n try {\n const multicodecPubKey = base58btc.decode(parsed.id)\n const keyType = decode(multicodecPubKey)\n const pubKeyBytes = multicodecPubKey.slice(decode.bytes)\n const args: KeyToDidDocArgs = { pubKeyBytes, fingerprint: parsed.id, contentType, options }\n const doc = await prefixToDriverMap[keyType].keyToDidDoc(args)\n if (contentType === DID_LD_JSON) {\n if (!doc['@context']) {\n doc['@context'] = 'https://w3id.org/did/v1'\n } else if (\n Array.isArray(doc['@context']) &&\n !doc['@context'].includes('https://w3id.org/did/v1') &&\n !doc['@context'].includes('https://www.w3.org/ns/did/v1')\n ) {\n doc['@context'].push('https://w3id.org/did/v1')\n }\n response.didDocument = doc\n } else if (contentType === DID_JSON) {\n response.didDocument = doc\n } else {\n delete response.didResolutionMetadata.contentType\n response.didResolutionMetadata.error = 'representationNotSupported'\n }\n } catch (e: any) {\n response.didResolutionMetadata.error = 'invalidDid'\n response.didResolutionMetadata.message = e.toString()\n }\n return response\n },\n }\n}\nexport default { getResolver }\n","// @ts-ignore\nimport * as u8a from 'uint8arrays'\nconst { toString } = u8a\nimport { DIDDocument } from 'did-resolver'\n// import { edwardsToMontgomery } from '@noble/curves/ed25519'\nimport { convertPublicKeyToX25519 } from '@stablelib/ed25519'\nimport { DID_LD_JSON, KeyToDidDocArgs } from '../types'\n\nfunction encodeKey(key: Uint8Array, encodeKey?: number) {\n const bytes = new Uint8Array(key.length + 2)\n bytes[0] = encodeKey ?? 0xec\n // The multicodec is encoded as a varint so we need to add this.\n // See js-multicodec for a general implementation\n bytes[1] = 0x01\n bytes.set(key, 2)\n return `z${toString(bytes, 'base58btc')}`\n}\n\nexport const keyToDidDoc = (args: KeyToDidDocArgs) => {\n const { options } = args\n if (!options?.publicKeyFormat) {\n return keyToDidDoc2020(args)\n }\n switch (options.publicKeyFormat) {\n case 'Ed25519VerificationKey2018':\n case 'X25519KeyAgreementKey2019':\n return keyToDidDoc2018_2019(args)\n case 'Ed25519VerificationKey2020':\n case 'X25519KeyAgreementKey2020':\n case 'Multikey':\n return keyToDidDoc2020(args)\n default:\n throw Error(`${options.publicKeyFormat} not supported yet for the ed25519 driver`)\n }\n}\nconst keyToDidDoc2018_2019 = ({ pubKeyBytes, fingerprint, contentType }: KeyToDidDocArgs): DIDDocument => {\n const did = `did:key:${fingerprint}`\n const keyId = `${did}#${fingerprint}`\n\n //todo: Move to noble lib. x25519 values differ between below methods. Current implementation is correct according to DID:key spec\n // const pubKeyHex = toString(pubKeyBytes, 'base16')\n // const x25519PubBytes = edwardsToMontgomery(pubKeyHex)\n const x25519PubBytes = convertPublicKeyToX25519(pubKeyBytes)\n\n const x25519KeyId = `${did}#${encodeKey(x25519PubBytes)}`\n return {\n ...(contentType === DID_LD_JSON && {\n '@context': [\n 'https://www.w3.org/ns/did/v1',\n 'https://w3id.org/security/suites/ed25519-2018/v1',\n 'https://w3id.org/security/suites/x25519-2019/v1',\n ],\n }),\n id: did,\n verificationMethod: [\n {\n id: keyId,\n type: 'Ed25519VerificationKey2018',\n controller: did,\n publicKeyBase58: toString(pubKeyBytes, 'base58btc'),\n },\n {\n id: x25519KeyId,\n type: 'X25519KeyAgreementKey2019',\n controller: did,\n publicKeyBase58: toString(x25519PubBytes, 'base58btc'),\n },\n ],\n authentication: [keyId],\n assertionMethod: [keyId],\n capabilityDelegation: [keyId],\n capabilityInvocation: [keyId],\n keyAgreement: [x25519KeyId],\n }\n}\n\nconst keyToDidDoc2020 = ({ pubKeyBytes, fingerprint, contentType }: KeyToDidDocArgs): DIDDocument => {\n const did = `did:key:${fingerprint}`\n const keyId = `${did}#${fingerprint}`\n //todo: Move to noble lib. x25519 values differ between below methods. Current implementation is correct according to DID:key spec\n // const pubKeyHex = u8a.toString(pubKeyBytes, 'base16')\n // const x25519PubBytes = edwardsToMontgomery(pubKeyBytes)\n const x25519PubBytes = convertPublicKeyToX25519(pubKeyBytes)\n\n const x25519KeyId = `${did}#${encodeKey(x25519PubBytes)}`\n return {\n ...(contentType === DID_LD_JSON && {\n '@context': [\n 'https://www.w3.org/ns/did/v1',\n 'https://w3id.org/security/suites/ed25519-2020/v1',\n 'https://w3id.org/security/suites/x25519-2020/v1',\n ],\n }),\n id: did,\n verificationMethod: [\n {\n id: keyId,\n type: 'Ed25519VerificationKey2020',\n controller: did,\n publicKeyMultibase: encodeKey(pubKeyBytes, 0xed),\n },\n ],\n authentication: [keyId],\n assertionMethod: [keyId],\n capabilityDelegation: [keyId],\n capabilityInvocation: [keyId],\n keyAgreement: [\n {\n id: x25519KeyId,\n type: 'X25519KeyAgreementKey2020',\n controller: did,\n publicKeyMultibase: encodeKey(x25519PubBytes, 0xec),\n },\n ],\n }\n}\nexport default { keyToDidDoc }\n","import { DIDResolutionOptions } from 'did-resolver'\n\nexport const DID_LD_JSON = 'application/did+ld+json'\nexport const DID_JSON = 'application/did+json'\n\nexport type PublicKeyFormat =\n | 'JsonWebKey2020'\n | 'Ed25519VerificationKey2018'\n | 'X25519KeyAgreementKey2019'\n | 'Ed25519VerificationKey2020'\n | 'X25519KeyAgreementKey2020'\n | 'Multikey'\nexport interface KeyToDidDocArgs {\n pubKeyBytes: Uint8Array\n fingerprint: string\n contentType?: string\n options?: DIDKeyResolutionOptions\n}\n\nexport interface DIDKeyResolutionOptions extends DIDResolutionOptions {\n publicKeyFormat?: PublicKeyFormat\n}\n","import { DIDDocument } from 'did-resolver'\n// @ts-ignore\nimport * as u8a from 'uint8arrays'\nconst { toString } = u8a\nimport { KeyToDidDocArgs } from '../index'\n\nexport const keyToDidDoc = ({ pubKeyBytes, fingerprint }: KeyToDidDocArgs): DIDDocument => {\n const did = `did:key:${fingerprint}`\n const keyId = `${did}#${fingerprint}`\n return {\n id: did,\n verificationMethod: [\n {\n id: keyId,\n type: 'Bls12381G2Key2020',\n controller: did,\n publicKeyBase58: toString(pubKeyBytes, 'base58btc'),\n },\n ],\n authentication: [keyId],\n assertionMethod: [keyId],\n capabilityDelegation: [keyId],\n capabilityInvocation: [keyId],\n }\n}\nexport default { keyToDidDoc }\n","// @ts-ignore\nimport * as u8a from 'uint8arrays'\nconst { toString } = u8a\nimport { DIDDocument } from 'did-resolver'\nimport { KeyToDidDocArgs } from '../types'\n\nexport const keyToDidDoc = ({ pubKeyBytes, fingerprint }: KeyToDidDocArgs): DIDDocument => {\n const did = `did:key:${fingerprint}`\n const keyId = `${did}#${fingerprint}`\n return {\n id: did,\n verificationMethod: [\n {\n id: keyId,\n type: 'Secp256k1VerificationKey2018',\n controller: did,\n publicKeyBase58: toString(pubKeyBytes, 'base58btc'),\n },\n ],\n authentication: [keyId],\n assertionMethod: [keyId],\n capabilityDelegation: [keyId],\n capabilityInvocation: [keyId],\n }\n}\n\nexport default { keyToDidDoc }\n","// Brent Shambaugh <brent.shambaugh@gmail.com>. 2021.\n\nimport * as nist_weierstrauss from 'nist-weierstrauss'\nimport { base64urlPoint } from 'nist-weierstrauss'\n// @ts-ignore\nimport * as u8a from 'uint8arrays'\nconst { fromString } = u8a\nimport { KeyToDidDocArgs } from '../types'\n\n/**\n * Constructs the document based on the method key\n */\nexport function keyToDidDoc({ pubKeyBytes, fingerprint }: KeyToDidDocArgs): any {\n const did = `did:key:${fingerprint}`\n const keyId = `${did}#${fingerprint}`\n const key = pubKeyBytesToXY(pubKeyBytes)\n return {\n id: did,\n verificationMethod: [\n {\n id: keyId,\n type: 'JsonWebKey2020',\n controller: did,\n publicKeyJwk: {\n kty: 'EC',\n crv: 'P-256',\n x: key.xm,\n y: key.ym,\n },\n },\n ],\n authentication: [keyId],\n assertionMethod: [keyId],\n capabilityDelegation: [keyId],\n capabilityInvocation: [keyId],\n }\n}\n\n/**\n *\n * @param pubKeyBytes - public key as uncompressed byte array with no prefix (raw key),\n * uncompressed with 0x04 prefix, or compressed with 0x02 prefix if even and 0x03 prefix if odd.\n * @returns point x,y with coordinates as multibase encoded base64urls\n *\n * See the the did:key specification: https://w3c-ccg.github.io/did-method-key/#p-256.\n * At present only raw p-256 keys are covered in the specification.\n * @throws TypeError: input cannot be null or undefined.\n * @throws Error: Unexpected pubKeyBytes\n * @internal\n */\nexport function pubKeyBytesToXY(pubKeyBytes: Uint8Array): base64urlPoint {\n if (!nist_weierstrauss.nist_weierstrauss_common.testUint8Array(pubKeyBytes)) {\n throw new TypeError('input must be a Uint8Array')\n }\n const publicKeyHex = nist_weierstrauss.nist_weierstrauss_common.pubKeyBytesToHex(pubKeyBytes)\n const bytesCount = publicKeyHex.length / 2\n\n // raw p-256 key\n if (bytesCount == 64) {\n return nist_weierstrauss.nist_weierstrauss_common.publicKeyToXY(publicKeyHex)\n }\n\n // uncompressed p-256 key, SEC format\n if (bytesCount == 65) {\n if (publicKeyHex.slice(0, 2) == '04') {\n const publicKey = publicKeyHex.slice(2)\n return nist_weierstrauss.nist_weierstrauss_common.publicKeyToXY(publicKey)\n }\n }\n\n // compressed p-256 key, SEC format\n if (bytesCount == 33) {\n if (publicKeyHex.slice(0, 2) == '03' || publicKeyHex.slice(0, 2) == '02') {\n const publicKey = fromString(publicKeyHex, 'base16')\n const point = nist_weierstrauss.secp256r1.ECPointDecompress(publicKey)\n return nist_weierstrauss.nist_weierstrauss_common.publicKeyIntToXY(point)\n }\n }\n\n throw new Error('Unexpected pubKeyBytes')\n}\n\nexport default { keyToDidDoc }\n","// Brent Shambaugh <brent.shambaugh@gmail.com>. 2021.\n\n// @ts-ignore\nimport * as u8a from 'uint8arrays'\nconst { fromString } = u8a\n\nimport * as nist_weierstrauss from 'nist-weierstrauss'\nimport { base64urlPoint } from 'nist-weierstrauss'\nimport { KeyToDidDocArgs } from '../types'\n\n/**\n * Constructs the document based on the method key\n */\nexport function keyToDidDoc({ pubKeyBytes, fingerprint }: KeyToDidDocArgs): any {\n const did = `did:key:${fingerprint}`\n const keyId = `${did}#${fingerprint}`\n const key = pubKeyBytesToXY(pubKeyBytes)\n return {\n id: did,\n verificationMethod: [\n {\n id: keyId,\n type: 'JsonWebKey2020',\n controller: did,\n publicKeyJwk: {\n kty: 'EC',\n crv: 'P-384',\n x: key.xm,\n y: key.ym,\n },\n },\n ],\n authentication: [keyId],\n assertionMethod: [keyId],\n capabilityDelegation: [keyId],\n capabilityInvocation: [keyId],\n }\n}\n\n/**\n *\n * @param pubKeyBytes - public key as uncompressed byte array with no prefix (raw key),\n * uncompressed with 0x04 prefix, or compressed with 0x02 prefix if even and 0x03 prefix if odd.\n * @returns point x,y with coordinates as multibase encoded base64urls\n *\n * See the the did:key specification: https://w3c-ccg.github.io/did-method-key/#p-384.\n * At present only raw p-384 keys are covered in the specification.\n * @throws TypeError: input cannot be null or undefined.\n * @throws Error: Unexpected pubKeyBytes\n * @internal\n */\nexport function pubKeyBytesToXY(pubKeyBytes: Uint8Array): base64urlPoint {\n if (!nist_weierstrauss.nist_weierstrauss_common.testUint8Array(pubKeyBytes)) {\n throw new TypeError('input must be a Uint8Array')\n }\n const publicKeyHex = nist_weierstrauss.nist_weierstrauss_common.pubKeyBytesToHex(pubKeyBytes)\n const bytesCount = publicKeyHex.length / 2\n\n // raw p-384 key\n if (bytesCount == 96) {\n return nist_weierstrauss.nist_weierstrauss_common.publicKeyToXY(publicKeyHex)\n }\n\n // uncompressed p-384 key, SEC format\n if (bytesCount == 97) {\n if (publicKeyHex.slice(0, 2) == '04') {\n const publicKey = publicKeyHex.slice(2)\n return nist_weierstrauss.nist_weierstrauss_common.publicKeyToXY(publicKey)\n }\n }\n\n // compressed p-384 key, SEC format\n if (bytesCount == 49) {\n if (publicKeyHex.slice(0, 2) == '03' || publicKeyHex.slice(0, 2) == '02') {\n const publicKey = fromString(publicKeyHex, 'base16')\n const point = nist_weierstrauss.secp384r1.ECPointDecompress(publicKey)\n return nist_weierstrauss.nist_weierstrauss_common.publicKeyIntToXY(point)\n }\n }\n\n throw new Error('Unexpected pubKeyBytes')\n}\n\nexport default { keyToDidDoc }\n","// Brent Shambaugh <brent.shambaugh@gmail.com>. 2021.\n\n// @ts-ignore\nimport * as u8a from 'uint8arrays'\nconst { fromString } = u8a\n\nimport * as nist_weierstrauss from 'nist-weierstrauss'\nimport { base64urlPoint } from 'nist-weierstrauss'\nimport { KeyToDidDocArgs } from '../types'\n\n/**\n * Constructs the document based on the method key\n */\nexport function keyToDidDoc({ pubKeyBytes, fingerprint }: KeyToDidDocArgs): any {\n const did = `did:key:${fingerprint}`\n const keyId = `${did}#${fingerprint}`\n const key = pubKeyBytesToXY(pubKeyBytes)\n return {\n id: did,\n verificationMethod: [\n {\n id: keyId,\n type: 'JsonWebKey2020',\n controller: did,\n publicKeyJwk: {\n kty: 'EC',\n crv: 'P-521',\n x: key.xm,\n y: key.ym,\n },\n },\n ],\n authentication: [keyId],\n assertionMethod: [keyId],\n capabilityDelegation: [keyId],\n capabilityInvocation: [keyId],\n }\n}\n\n/**\n *\n * @param pubKeyBytes - public key as compressed with 0x02 prefix if even and 0x03 prefix if odd.\n * @returns point x,y with coordinates as multibase encoded base64urls\n *\n * See the the did:key specification: https://w3c-ccg.github.io/did-method-key/#p-521.\n * For compression see: https://tools.ietf.org/id/draft-jivsov-ecc-compact-05.html#rfc.section.3\n * @throws TypeError: input cannot be null or undefined.\n * @throws Error: Unexpected pubKeyBytes\n * @internal\n */\nexport function pubKeyBytesToXY(pubKeyBytes: Uint8Array): base64urlPoint {\n if (!nist_weierstrauss.nist_weierstrauss_common.testUint8Array(pubKeyBytes)) {\n throw new TypeError('input must be a Uint8Array')\n }\n const publicKeyHex = nist_weierstrauss.nist_weierstrauss_common.pubKeyBytesToHex(pubKeyBytes)\n\n // compressed p-521 key, SEC format\n // publicKeyHex.length / 2.0 = 67.0 bytes\n if (132 <= publicKeyHex.length && publicKeyHex.length <= 134) {\n if (publicKeyHex.slice(0, 2) == '03' || publicKeyHex.slice(0, 2) == '02') {\n const publicKey = fromString(publicKeyHex, 'base16')\n const point = nist_weierstrauss.secp521r1.ECPointDecompress(publicKey)\n return nist_weierstrauss.nist_weierstrauss_common.publicKeyIntToXY(point)\n }\n }\n\n throw new Error('Unexpected pubKeyBytes')\n}\n\nexport default { keyToDidDoc }\n","import { DIDDocument, JsonWebKey as DIFJWK } from 'did-resolver'\nimport { DID_LD_JSON, KeyToDidDocArgs } from '../index'\nimport { jwkJcsDecode } from '@sphereon/ssi-sdk-ext.key-utils'\n\nexport const keyToDidDoc = ({ pubKeyBytes, fingerprint, contentType }: KeyToDidDocArgs): DIDDocument => {\n const did = `did:key:${fingerprint}`\n const keyId = `${did}#${fingerprint}`\n const publicKeyJwk = jwkJcsDecode(pubKeyBytes) as DIFJWK\n return {\n ...(contentType === DID_LD_JSON && {\n '@context': ['https://www.w3.org/ns/did/v1', 'https://w3id.org/security/suites/jws-2020/v1'],\n }),\n id: did,\n verificationMethod: [\n {\n id: keyId,\n type: 'JsonWebKey2020',\n controller: did,\n publicKeyJwk,\n },\n ],\n authentication: [keyId],\n assertionMethod: [keyId],\n capabilityDelegation: [keyId],\n capabilityInvocation: [keyId],\n }\n}\nexport default { keyToDidDoc }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;AAAA,oBAAmB;AAGnB,oBAA0B;;;ACF1B,UAAqB;AAIrB,qBAAyC;;;ACHlC,IAAMA,cAAc;AACpB,IAAMC,WAAW;;;ADDxB,IAAM,EAAEC,SAAQ,IAAKC;AAMrB,SAASC,UAAUC,KAAiBD,YAAkB;AACpD,QAAME,QAAQ,IAAIC,WAAWF,IAAIG,SAAS,CAAA;AAC1CF,QAAM,CAAA,IAAKF,cAAa;AAGxBE,QAAM,CAAA,IAAK;AACXA,QAAMG,IAAIJ,KAAK,CAAA;AACf,SAAO,IAAIH,SAASI,OAAO,WAAA,CAAA;AAC7B;AARSF;AAUF,IAAMM,cAAc,wBAACC,SAAAA;AAC1B,QAAM,EAAEC,QAAO,IAAKD;AACpB,MAAI,CAACC,SAASC,iBAAiB;AAC7B,WAAOC,gBAAgBH,IAAAA;EACzB;AACA,UAAQC,QAAQC,iBAAe;IAC7B,KAAK;IACL,KAAK;AACH,aAAOE,qBAAqBJ,I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IT;UAAaD;QAAQ;AAC1F,cAAMiB,MAAM,MAAM9B,kBAAkBwB,OAAAA,EAASO,YAAYH,IAAAA;AACzD,YAAId,gBAAgBE,aAAa;AAC/B,cAAI,CAACc,IAAI,UAAA,GAAa;AACpBA,gBAAI,UAAA,IAAc;UACpB,WACEE,MAAMC,QAAQH,IAAI,UAAA,CAAW,KAC7B,CAACA,IAAI,UAAA,EAAYI,SAAS,yBAAA,KAC1B,CAACJ,IAAI,UAAA,EAAYI,SAAS,8BAAA,GAC1B;AACAJ,gBAAI,UAAA,EAAYK,KAAK,yBAAA;UACvB;AACAlB,mBAASE,cAAcW;QACzB,WAAWhB,gBAAgBsB,UAAU;AACnCnB,mBAASE,cAAcW;QACzB,OAAO;AACL,iBAAOb,SAASC,sBAAsBJ;AACtCG,mBAASC,sBAAsBmB,QAAQ;QACzC;MACF,SAASC,GAAQ;AACfrB,iBAASC,sBAAsBmB,QAAQ;AACvCpB,iBAASC,sBAAsBqB,UAAUD,EAAEE,SAAQ;MACrD;AACA,aAAOvB;IACT,GAnCK;EAoCP;AACF,GAvC2B;AAwC3B,IAAA,gBAAe;EAAET;AAAY;","names":["DID_LD_JSON","DID_JSON","toString","u8a","encodeKey","key","bytes","Uint8Array","length","set","keyToDidDoc","args","options","publicKeyFormat","keyToDidDoc2020","keyToDidDoc2018_2019","Error","pubKeyBytes","fingerprint","contentType","did","keyId","x25519PubBytes","convertPublicKeyToX25519","x25519KeyId","DID_LD_JSON","id","verificationMethod","type","controller","publicKeyBase58","authentication","assertionMethod","capabilityDelegation","capabilityInvocation","keyAgreement","publicKeyMultibase","u8a","toString","u8a","keyToDidDoc","pubKeyBytes","fingerprint","did","keyId","id","verificationMethod","type","controller","publicKeyBase58","authentication","assertionMethod","capabilityDelegation","capabilityInvocation","u8a","toString","u8a","keyToDidDoc","pubKeyBytes","fingerprint","did","keyId","id","verificationMethod","type","controller","publicKeyBase58","authentication","assertionMethod","capabilityDelegation","capabilityInvocation","u8a","fromString","u8a","keyToDidDoc","pubKeyBytes","fingerprint","did","keyId","key","pubKeyBytesToXY","id","verificationMethod","type","controller","publicKeyJwk","kty","crv","x","xm","y","ym","authentication","assertionMethod","capabilityDelegation","capabilityInvocation","nist_weierstrauss_common","testUint8Array","TypeError","publicKeyHex","pubKeyBytesToHex","bytesCount","length","publicKeyToXY","slice","publicKey","point","secp256r1","ECPointDecompress","publicKeyIntToXY","Error","u8a","nist_weierstrauss","fromString","u8a","keyToDidDoc","pubKeyBytes","fingerprint","did","keyId","key","pubKeyBytesToXY","id","verificationMethod","type","controller","publicKeyJwk","kty","crv","x","xm","y","ym","authentication","assertionMethod","capabilityDelegation","capabilityInvocation","nist_weierstrauss_common","testUint8Array","TypeError","publicKeyHex","pubKeyBytesToHex","bytesCount","length","publicKeyToXY","slice","publicKey","point","secp384r1","ECPointDecompress","publicKeyIntToXY","Error","u8a","nist_weierstrauss","fromString","u8a","keyToDidDoc","pubKeyBytes","fingerprint","did","keyId","key","pubKeyBytesToXY","id","verificationMethod","type","controller","publicKeyJwk","kty","crv","x","xm","y","ym","authentication","assertionMethod","capabilityDelegation","capabilityInvocation","nist_weierstrauss_common","testUint8Array","TypeError","publicKeyHex","pubKeyBytesToHex","length","slice","publicKey","point","secp521r1","ECPointDecompress","publicKeyIntToXY","Error","keyToDidDoc","pubKeyBytes","fingerprint","contentType","did","keyId","publicKeyJwk","jwkJcsDecode","DID_LD_JSON","id","verificationMethod","type","controller","authentication","assertionMethod","capabilityDelegation","capabilityInvocation","decode","varint","prefixToDriverMap","secp256k1","ed25519","secp256r1","secp384r1","secp521r1","bls12381g2","jwkJcs","getResolver","key","did","parsed","r","options","contentType","accept","DID_LD_JSON","response","didResolutionMetadata","didDocument","didDocumentMetadata","multicodecPubKey","base58btc","id","keyType","pubKeyBytes","slice","bytes","args","fingerprint","doc","keyToDidDoc","Array","isArray","includes","push","DID_JSON","error","e","message","toString"]}
@@ -0,0 +1,21 @@
1
+ import { DIDResolutionOptions, ResolverRegistry } from 'did-resolver';
2
+
3
+ declare const DID_LD_JSON = "application/did+ld+json";
4
+ declare const DID_JSON = "application/did+json";
5
+ type PublicKeyFormat = 'JsonWebKey2020' | 'Ed25519VerificationKey2018' | 'X25519KeyAgreementKey2019' | 'Ed25519VerificationKey2020' | 'X25519KeyAgreementKey2020' | 'Multikey';
6
+ interface KeyToDidDocArgs {
7
+ pubKeyBytes: Uint8Array;
8
+ fingerprint: string;
9
+ contentType?: string;
10
+ options?: DIDKeyResolutionOptions;
11
+ }
12
+ interface DIDKeyResolutionOptions extends DIDResolutionOptions {
13
+ publicKeyFormat?: PublicKeyFormat;
14
+ }
15
+
16
+ declare const getResolver: () => ResolverRegistry;
17
+ declare const _default: {
18
+ getResolver: () => ResolverRegistry;
19
+ };
20
+
21
+ export { type DIDKeyResolutionOptions, DID_JSON, DID_LD_JSON, type KeyToDidDocArgs, type PublicKeyFormat, _default as default, getResolver };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,21 @@
1
- import { ResolverRegistry } from 'did-resolver';
2
- export * from './types';
3
- export declare const getResolver: () => ResolverRegistry;
1
+ import { DIDResolutionOptions, ResolverRegistry } from 'did-resolver';
2
+
3
+ declare const DID_LD_JSON = "application/did+ld+json";
4
+ declare const DID_JSON = "application/did+json";
5
+ type PublicKeyFormat = 'JsonWebKey2020' | 'Ed25519VerificationKey2018' | 'X25519KeyAgreementKey2019' | 'Ed25519VerificationKey2020' | 'X25519KeyAgreementKey2020' | 'Multikey';
6
+ interface KeyToDidDocArgs {
7
+ pubKeyBytes: Uint8Array;
8
+ fingerprint: string;
9
+ contentType?: string;
10
+ options?: DIDKeyResolutionOptions;
11
+ }
12
+ interface DIDKeyResolutionOptions extends DIDResolutionOptions {
13
+ publicKeyFormat?: PublicKeyFormat;
14
+ }
15
+
16
+ declare const getResolver: () => ResolverRegistry;
4
17
  declare const _default: {
5
18
  getResolver: () => ResolverRegistry;
6
19
  };
7
- export default _default;
8
- //# sourceMappingURL=index.d.ts.map
20
+
21
+ export { type DIDKeyResolutionOptions, DID_JSON, DID_LD_JSON, type KeyToDidDocArgs, type PublicKeyFormat, _default as default, getResolver };