@sphereon/ssi-sdk-ext.did-resolver-key 0.28.1-feature.esm.cjs.9 → 0.28.1-feature.jose.vcdm.19
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/index.cjs +70 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +12 -6
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
- package/src/drivers/bls12381g2.ts +2 -1
- package/src/drivers/ed25519.ts +2 -2
- package/src/drivers/secp256k1.ts +2 -1
- package/src/drivers/secp256r1.ts +4 -3
- package/src/drivers/secp384r1.ts +2 -1
- package/src/drivers/secp521r1.ts +2 -1
- package/src/index.ts +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,30 +1,66 @@
|
|
|
1
|
-
"use strict";
|
|
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;
|
|
2
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);
|
|
3
30
|
|
|
4
31
|
// src/index.ts
|
|
5
|
-
var
|
|
6
|
-
|
|
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");
|
|
7
42
|
|
|
8
43
|
// src/drivers/ed25519.ts
|
|
9
|
-
var
|
|
10
|
-
var
|
|
44
|
+
var u8a = __toESM(require("uint8arrays"), 1);
|
|
45
|
+
var import_ed25519 = require("@stablelib/ed25519");
|
|
11
46
|
|
|
12
47
|
// src/types.ts
|
|
13
48
|
var DID_LD_JSON = "application/did+ld+json";
|
|
14
49
|
var DID_JSON = "application/did+json";
|
|
15
50
|
|
|
16
51
|
// src/drivers/ed25519.ts
|
|
52
|
+
var { toString } = u8a;
|
|
17
53
|
function encodeKey(key, encodeKey2) {
|
|
18
54
|
const bytes = new Uint8Array(key.length + 2);
|
|
19
|
-
bytes[0] =
|
|
55
|
+
bytes[0] = encodeKey2 ?? 236;
|
|
20
56
|
bytes[1] = 1;
|
|
21
57
|
bytes.set(key, 2);
|
|
22
|
-
return `z${
|
|
58
|
+
return `z${toString(bytes, "base58btc")}`;
|
|
23
59
|
}
|
|
24
60
|
__name(encodeKey, "encodeKey");
|
|
25
61
|
var keyToDidDoc = /* @__PURE__ */ __name((args) => {
|
|
26
62
|
const { options } = args;
|
|
27
|
-
if (!
|
|
63
|
+
if (!options?.publicKeyFormat) {
|
|
28
64
|
return keyToDidDoc2020(args);
|
|
29
65
|
}
|
|
30
66
|
switch (options.publicKeyFormat) {
|
|
@@ -42,7 +78,7 @@ var keyToDidDoc = /* @__PURE__ */ __name((args) => {
|
|
|
42
78
|
var keyToDidDoc2018_2019 = /* @__PURE__ */ __name(({ pubKeyBytes, fingerprint, contentType }) => {
|
|
43
79
|
const did = `did:key:${fingerprint}`;
|
|
44
80
|
const keyId = `${did}#${fingerprint}`;
|
|
45
|
-
const x25519PubBytes =
|
|
81
|
+
const x25519PubBytes = (0, import_ed25519.convertPublicKeyToX25519)(pubKeyBytes);
|
|
46
82
|
const x25519KeyId = `${did}#${encodeKey(x25519PubBytes)}`;
|
|
47
83
|
return {
|
|
48
84
|
...contentType === DID_LD_JSON && {
|
|
@@ -58,13 +94,13 @@ var keyToDidDoc2018_2019 = /* @__PURE__ */ __name(({ pubKeyBytes, fingerprint, c
|
|
|
58
94
|
id: keyId,
|
|
59
95
|
type: "Ed25519VerificationKey2018",
|
|
60
96
|
controller: did,
|
|
61
|
-
publicKeyBase58:
|
|
97
|
+
publicKeyBase58: toString(pubKeyBytes, "base58btc")
|
|
62
98
|
},
|
|
63
99
|
{
|
|
64
100
|
id: x25519KeyId,
|
|
65
101
|
type: "X25519KeyAgreementKey2019",
|
|
66
102
|
controller: did,
|
|
67
|
-
publicKeyBase58:
|
|
103
|
+
publicKeyBase58: toString(x25519PubBytes, "base58btc")
|
|
68
104
|
}
|
|
69
105
|
],
|
|
70
106
|
authentication: [
|
|
@@ -87,7 +123,7 @@ var keyToDidDoc2018_2019 = /* @__PURE__ */ __name(({ pubKeyBytes, fingerprint, c
|
|
|
87
123
|
var keyToDidDoc2020 = /* @__PURE__ */ __name(({ pubKeyBytes, fingerprint, contentType }) => {
|
|
88
124
|
const did = `did:key:${fingerprint}`;
|
|
89
125
|
const keyId = `${did}#${fingerprint}`;
|
|
90
|
-
const x25519PubBytes =
|
|
126
|
+
const x25519PubBytes = (0, import_ed25519.convertPublicKeyToX25519)(pubKeyBytes);
|
|
91
127
|
const x25519KeyId = `${did}#${encodeKey(x25519PubBytes)}`;
|
|
92
128
|
return {
|
|
93
129
|
...contentType === DID_LD_JSON && {
|
|
@@ -133,7 +169,8 @@ var ed25519_default = {
|
|
|
133
169
|
};
|
|
134
170
|
|
|
135
171
|
// src/drivers/bls12381g2.ts
|
|
136
|
-
|
|
172
|
+
var u8a2 = __toESM(require("uint8arrays"), 1);
|
|
173
|
+
var { toString: toString2 } = u8a2;
|
|
137
174
|
var keyToDidDoc2 = /* @__PURE__ */ __name(({ pubKeyBytes, fingerprint }) => {
|
|
138
175
|
const did = `did:key:${fingerprint}`;
|
|
139
176
|
const keyId = `${did}#${fingerprint}`;
|
|
@@ -144,7 +181,7 @@ var keyToDidDoc2 = /* @__PURE__ */ __name(({ pubKeyBytes, fingerprint }) => {
|
|
|
144
181
|
id: keyId,
|
|
145
182
|
type: "Bls12381G2Key2020",
|
|
146
183
|
controller: did,
|
|
147
|
-
publicKeyBase58:
|
|
184
|
+
publicKeyBase58: toString2(pubKeyBytes, "base58btc")
|
|
148
185
|
}
|
|
149
186
|
],
|
|
150
187
|
authentication: [
|
|
@@ -166,7 +203,8 @@ var bls12381g2_default = {
|
|
|
166
203
|
};
|
|
167
204
|
|
|
168
205
|
// src/drivers/secp256k1.ts
|
|
169
|
-
|
|
206
|
+
var u8a3 = __toESM(require("uint8arrays"), 1);
|
|
207
|
+
var { toString: toString3 } = u8a3;
|
|
170
208
|
var keyToDidDoc3 = /* @__PURE__ */ __name(({ pubKeyBytes, fingerprint }) => {
|
|
171
209
|
const did = `did:key:${fingerprint}`;
|
|
172
210
|
const keyId = `${did}#${fingerprint}`;
|
|
@@ -177,7 +215,7 @@ var keyToDidDoc3 = /* @__PURE__ */ __name(({ pubKeyBytes, fingerprint }) => {
|
|
|
177
215
|
id: keyId,
|
|
178
216
|
type: "Secp256k1VerificationKey2018",
|
|
179
217
|
controller: did,
|
|
180
|
-
publicKeyBase58:
|
|
218
|
+
publicKeyBase58: toString3(pubKeyBytes, "base58btc")
|
|
181
219
|
}
|
|
182
220
|
],
|
|
183
221
|
authentication: [
|
|
@@ -199,8 +237,9 @@ var secp256k1_default = {
|
|
|
199
237
|
};
|
|
200
238
|
|
|
201
239
|
// src/drivers/secp256r1.ts
|
|
202
|
-
var
|
|
203
|
-
var
|
|
240
|
+
var nist_weierstrauss = __toESM(require("nist-weierstrauss"), 1);
|
|
241
|
+
var u8a4 = __toESM(require("uint8arrays"), 1);
|
|
242
|
+
var { fromString } = u8a4;
|
|
204
243
|
function keyToDidDoc4({ pubKeyBytes, fingerprint }) {
|
|
205
244
|
const did = `did:key:${fingerprint}`;
|
|
206
245
|
const keyId = `${did}#${fingerprint}`;
|
|
@@ -252,7 +291,7 @@ function pubKeyBytesToXY(pubKeyBytes) {
|
|
|
252
291
|
}
|
|
253
292
|
if (bytesCount == 33) {
|
|
254
293
|
if (publicKeyHex.slice(0, 2) == "03" || publicKeyHex.slice(0, 2) == "02") {
|
|
255
|
-
const publicKey =
|
|
294
|
+
const publicKey = fromString(publicKeyHex, "base16");
|
|
256
295
|
const point = nist_weierstrauss.secp256r1.ECPointDecompress(publicKey);
|
|
257
296
|
return nist_weierstrauss.nist_weierstrauss_common.publicKeyIntToXY(point);
|
|
258
297
|
}
|
|
@@ -265,8 +304,9 @@ var secp256r1_default = {
|
|
|
265
304
|
};
|
|
266
305
|
|
|
267
306
|
// src/drivers/secp384r1.ts
|
|
268
|
-
|
|
269
|
-
|
|
307
|
+
var u8a5 = __toESM(require("uint8arrays"), 1);
|
|
308
|
+
var nist_weierstrauss2 = __toESM(require("nist-weierstrauss"), 1);
|
|
309
|
+
var { fromString: fromString2 } = u8a5;
|
|
270
310
|
function keyToDidDoc5({ pubKeyBytes, fingerprint }) {
|
|
271
311
|
const did = `did:key:${fingerprint}`;
|
|
272
312
|
const keyId = `${did}#${fingerprint}`;
|
|
@@ -318,7 +358,7 @@ function pubKeyBytesToXY2(pubKeyBytes) {
|
|
|
318
358
|
}
|
|
319
359
|
if (bytesCount == 49) {
|
|
320
360
|
if (publicKeyHex.slice(0, 2) == "03" || publicKeyHex.slice(0, 2) == "02") {
|
|
321
|
-
const publicKey =
|
|
361
|
+
const publicKey = fromString2(publicKeyHex, "base16");
|
|
322
362
|
const point = nist_weierstrauss2.secp384r1.ECPointDecompress(publicKey);
|
|
323
363
|
return nist_weierstrauss2.nist_weierstrauss_common.publicKeyIntToXY(point);
|
|
324
364
|
}
|
|
@@ -331,8 +371,9 @@ var secp384r1_default = {
|
|
|
331
371
|
};
|
|
332
372
|
|
|
333
373
|
// src/drivers/secp521r1.ts
|
|
334
|
-
|
|
335
|
-
|
|
374
|
+
var u8a6 = __toESM(require("uint8arrays"), 1);
|
|
375
|
+
var nist_weierstrauss3 = __toESM(require("nist-weierstrauss"), 1);
|
|
376
|
+
var { fromString: fromString3 } = u8a6;
|
|
336
377
|
function keyToDidDoc6({ pubKeyBytes, fingerprint }) {
|
|
337
378
|
const did = `did:key:${fingerprint}`;
|
|
338
379
|
const keyId = `${did}#${fingerprint}`;
|
|
@@ -374,7 +415,7 @@ function pubKeyBytesToXY3(pubKeyBytes) {
|
|
|
374
415
|
const publicKeyHex = nist_weierstrauss3.nist_weierstrauss_common.pubKeyBytesToHex(pubKeyBytes);
|
|
375
416
|
if (132 <= publicKeyHex.length && publicKeyHex.length <= 134) {
|
|
376
417
|
if (publicKeyHex.slice(0, 2) == "03" || publicKeyHex.slice(0, 2) == "02") {
|
|
377
|
-
const publicKey =
|
|
418
|
+
const publicKey = fromString3(publicKeyHex, "base16");
|
|
378
419
|
const point = nist_weierstrauss3.secp521r1.ECPointDecompress(publicKey);
|
|
379
420
|
return nist_weierstrauss3.nist_weierstrauss_common.publicKeyIntToXY(point);
|
|
380
421
|
}
|
|
@@ -387,11 +428,11 @@ var secp521r1_default = {
|
|
|
387
428
|
};
|
|
388
429
|
|
|
389
430
|
// src/drivers/jwk.jcs.ts
|
|
390
|
-
var
|
|
431
|
+
var import_ssi_sdk_ext = require("@sphereon/ssi-sdk-ext.key-utils");
|
|
391
432
|
var keyToDidDoc7 = /* @__PURE__ */ __name(({ pubKeyBytes, fingerprint, contentType }) => {
|
|
392
433
|
const did = `did:key:${fingerprint}`;
|
|
393
434
|
const keyId = `${did}#${fingerprint}`;
|
|
394
|
-
const publicKeyJwk =
|
|
435
|
+
const publicKeyJwk = (0, import_ssi_sdk_ext.jwkJcsDecode)(pubKeyBytes);
|
|
395
436
|
return {
|
|
396
437
|
...contentType === DID_LD_JSON && {
|
|
397
438
|
"@context": [
|
|
@@ -427,7 +468,7 @@ var jwk_jcs_default = {
|
|
|
427
468
|
};
|
|
428
469
|
|
|
429
470
|
// src/index.ts
|
|
430
|
-
var { decode } =
|
|
471
|
+
var { decode } = import_varint.default;
|
|
431
472
|
var prefixToDriverMap = {
|
|
432
473
|
231: secp256k1_default,
|
|
433
474
|
237: ed25519_default,
|
|
@@ -449,7 +490,7 @@ var getResolver = /* @__PURE__ */ __name(() => {
|
|
|
449
490
|
didDocumentMetadata: {}
|
|
450
491
|
};
|
|
451
492
|
try {
|
|
452
|
-
const multicodecPubKey =
|
|
493
|
+
const multicodecPubKey = import_base58.base58btc.decode(parsed.id);
|
|
453
494
|
const keyType = decode(multicodecPubKey);
|
|
454
495
|
const pubKeyBytes = multicodecPubKey.slice(decode.bytes);
|
|
455
496
|
const args = {
|
|
@@ -483,10 +524,4 @@ var getResolver = /* @__PURE__ */ __name(() => {
|
|
|
483
524
|
var index_default = {
|
|
484
525
|
getResolver
|
|
485
526
|
};
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
exports.DID_JSON = DID_JSON; exports.DID_LD_JSON = DID_LD_JSON; exports.default = index_default; exports.getResolver = getResolver;
|
|
492
527
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/SSI-SDK-crypto-extensions/SSI-SDK-crypto-extensions/packages/did-resolver-key/dist/index.cjs","../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"],"names":["DID_LD_JSON","DID_JSON","encodeKey","key","bytes","Uint8Array","length","set","toString","args","publicKeyFormat","fingerprint","convertPublicKeyToX25519","x25519PubBytes","did","keyId","pubKeyBytes","x25519KeyId","keyToDidDoc","xm","ym","nist_weierstrauss_common","slice","publicKeyHex","secp256r1","pubKeyBytesToXY","secp384r1","secp521r1","publicKeyJwk","varint","secp256k1","ed25519","bls12381g2","jwkJcs","accept","contentType","base58btc","multicodecPubKey","id","options","prefixToDriverMap","doc","didResolutionMetadata","error","message","response","getResolver"],"mappings":"AAAA,uiCAAI,UAAU,EAAE,MAAM,CAAC,cAAc;AACrC,IAAI,OAAO,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,CAAC,CAAC;AACxF;AACA;ACHA,gFAAmB;AAGnB,mDAA0B;ADG1B;AACA;AELA,iDAAyB;AAGzB,6CAAyC;AFKzC;AACA;AGTO,IAAMA,YAAAA,EAAc,yBAAA;AACpB,IAAMC,SAAAA,EAAW,sBAAA;AHWxB;AACA;AEPA,SAASC,SAAAA,CAAUC,GAAAA,EAAiBD,UAAAA,EAAkB;AACpD,EAAA,MAAME,MAAAA,EAAQ,IAAIC,UAAAA,CAAWF,GAAAA,CAAIG,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;ATsYoC,IAAA;ASpYtB,IAAA;AAACb,MAAAA;ATuYqB,IAAA;AStYrB,IAAA;AAACA,MAAAA;ATyYoB,IAAA;ASxYhB,IAAA;AAACA,MAAAA;AT2Ye,IAAA;AS1YhB,IAAA;AAACA,MAAAA;AT6Ye,IAAA;AS5YxC,EAAA;AArByB;AAuBZ;AAAEG,EAAAA;AAAY;ATgZa;AACA;AC3avBW;AAeY;AACvBC,EAAAA;AACAC,EAAAA;AACEP,EAAAA;AACAE,EAAAA;AACAC,EAAAA;AACFK,EAAAA;AACEC,EAAAA;AACV;AAE2B;AAClB,EAAA;AACOnB,IAAAA;AACkBoB,MAAAA;AACU,MAAA;AACb,QAAA;AAAEC,UAAAA;AAAY,QAAA;AACxB,QAAA;AACS,QAAA;AACxB,MAAA;AACI,MAAA;AACuBC,QAAAA;AACFC,QAAAA;AACHA,QAAAA;AACU,QAAA;AAAErB,UAAAA;AAAiCsB,UAAAA;AAAIH,UAAAA;AAAaI,UAAAA;AAAQ,QAAA;AACxEC,QAAAA;AACe,QAAA;AACT,UAAA;AACF,YAAA;AAEA,UAAA;AAIG,YAAA;AACvB,UAAA;AACuBC,UAAAA;AACExC,QAAAA;AACFwC,UAAAA;AAClB,QAAA;AACWC,UAAAA;AACeC,UAAAA;AACjC,QAAA;AACe,MAAA;AACgBA,QAAAA;AACAC,QAAAA;AACjC,MAAA;AACOC,MAAAA;AAlCJ,IAAA;AAoCP,EAAA;AAtCyB;AAwCZ;AAAEC,EAAAA;AAAY;ADmaa;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/SSI-SDK-crypto-extensions/SSI-SDK-crypto-extensions/packages/did-resolver-key/dist/index.cjs","sourcesContent":[null,"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","\n// @ts-ignore\nimport { toString } from 'uint8arrays/to-string'\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 { toString } from 'uint8arrays/to-string'\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 { toString } from 'uint8arrays/to-string'\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 {fromString} from 'uint8arrays/from-string'\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 { fromString } from 'uint8arrays/from-string'\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 { fromString } from 'uint8arrays/from-string'\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"]}
|
|
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":";;;;;;;;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BqB,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"]}
|
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import varint from "varint";
|
|
|
6
6
|
import { base58btc } from "multiformats/bases/base58";
|
|
7
7
|
|
|
8
8
|
// src/drivers/ed25519.ts
|
|
9
|
-
import
|
|
9
|
+
import * as u8a from "uint8arrays";
|
|
10
10
|
import { convertPublicKeyToX25519 } from "@stablelib/ed25519";
|
|
11
11
|
|
|
12
12
|
// src/types.ts
|
|
@@ -14,6 +14,7 @@ var DID_LD_JSON = "application/did+ld+json";
|
|
|
14
14
|
var DID_JSON = "application/did+json";
|
|
15
15
|
|
|
16
16
|
// src/drivers/ed25519.ts
|
|
17
|
+
var { toString } = u8a;
|
|
17
18
|
function encodeKey(key, encodeKey2) {
|
|
18
19
|
const bytes = new Uint8Array(key.length + 2);
|
|
19
20
|
bytes[0] = encodeKey2 ?? 236;
|
|
@@ -133,7 +134,8 @@ var ed25519_default = {
|
|
|
133
134
|
};
|
|
134
135
|
|
|
135
136
|
// src/drivers/bls12381g2.ts
|
|
136
|
-
import
|
|
137
|
+
import * as u8a2 from "uint8arrays";
|
|
138
|
+
var { toString: toString2 } = u8a2;
|
|
137
139
|
var keyToDidDoc2 = /* @__PURE__ */ __name(({ pubKeyBytes, fingerprint }) => {
|
|
138
140
|
const did = `did:key:${fingerprint}`;
|
|
139
141
|
const keyId = `${did}#${fingerprint}`;
|
|
@@ -166,7 +168,8 @@ var bls12381g2_default = {
|
|
|
166
168
|
};
|
|
167
169
|
|
|
168
170
|
// src/drivers/secp256k1.ts
|
|
169
|
-
import
|
|
171
|
+
import * as u8a3 from "uint8arrays";
|
|
172
|
+
var { toString: toString3 } = u8a3;
|
|
170
173
|
var keyToDidDoc3 = /* @__PURE__ */ __name(({ pubKeyBytes, fingerprint }) => {
|
|
171
174
|
const did = `did:key:${fingerprint}`;
|
|
172
175
|
const keyId = `${did}#${fingerprint}`;
|
|
@@ -200,7 +203,8 @@ var secp256k1_default = {
|
|
|
200
203
|
|
|
201
204
|
// src/drivers/secp256r1.ts
|
|
202
205
|
import * as nist_weierstrauss from "nist-weierstrauss";
|
|
203
|
-
import
|
|
206
|
+
import * as u8a4 from "uint8arrays";
|
|
207
|
+
var { fromString } = u8a4;
|
|
204
208
|
function keyToDidDoc4({ pubKeyBytes, fingerprint }) {
|
|
205
209
|
const did = `did:key:${fingerprint}`;
|
|
206
210
|
const keyId = `${did}#${fingerprint}`;
|
|
@@ -265,8 +269,9 @@ var secp256r1_default = {
|
|
|
265
269
|
};
|
|
266
270
|
|
|
267
271
|
// src/drivers/secp384r1.ts
|
|
268
|
-
import
|
|
272
|
+
import * as u8a5 from "uint8arrays";
|
|
269
273
|
import * as nist_weierstrauss2 from "nist-weierstrauss";
|
|
274
|
+
var { fromString: fromString2 } = u8a5;
|
|
270
275
|
function keyToDidDoc5({ pubKeyBytes, fingerprint }) {
|
|
271
276
|
const did = `did:key:${fingerprint}`;
|
|
272
277
|
const keyId = `${did}#${fingerprint}`;
|
|
@@ -331,8 +336,9 @@ var secp384r1_default = {
|
|
|
331
336
|
};
|
|
332
337
|
|
|
333
338
|
// src/drivers/secp521r1.ts
|
|
334
|
-
import
|
|
339
|
+
import * as u8a6 from "uint8arrays";
|
|
335
340
|
import * as nist_weierstrauss3 from "nist-weierstrauss";
|
|
341
|
+
var { fromString: fromString3 } = u8a6;
|
|
336
342
|
function keyToDidDoc6({ pubKeyBytes, fingerprint }) {
|
|
337
343
|
const did = `did:key:${fingerprint}`;
|
|
338
344
|
const keyId = `${did}#${fingerprint}`;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +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","\n// @ts-ignore\nimport { toString } from 'uint8arrays/to-string'\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 { toString } from 'uint8arrays/to-string'\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 { toString } from 'uint8arrays/to-string'\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 {fromString} from 'uint8arrays/from-string'\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 { fromString } from 'uint8arrays/from-string'\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 { fromString } from 'uint8arrays/from-string'\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,OAAOA,YAAY;AAGnB,SAASC,iBAAiB;;;ACD1B,SAASC,gBAAgB;AAGzB,SAASC,gCAAgC;;;ACHlC,IAAMC,cAAc;AACpB,IAAMC,WAAW;;;ADKxB,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,IAAIK,SAASJ,OAAO,WAAA,CAAA;AAC7B;AARSF;AAUF,IAAMO,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,IAAAA;IAC9B,KAAK;IACL,KAAK;IACL,KAAK;AACH,aAAOG,gBAAgBH,IAAAA;IACzB;AACE,YAAMK,MAAM,GAAGJ,QAAQC,eAAe,2CAA2C;EACrF;AACF,GAhB2B;AAiB3B,IAAME,uBAAuB,wBAAC,E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AAI,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":["varint","base58btc","toString","convertPublicKeyToX25519","DID_LD_JSON","DID_JSON","encodeKey","key","bytes","Uint8Array","length","set","toString","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","toString","keyToDidDoc","pubKeyBytes","fingerprint","did","keyId","id","verificationMethod","type","controller","publicKeyBase58","toString","authentication","assertionMethod","capabilityDelegation","capabilityInvocation","toString","keyToDidDoc","pubKeyBytes","fingerprint","did","keyId","id","verificationMethod","type","controller","publicKeyBase58","toString","authentication","assertionMethod","capabilityDelegation","capabilityInvocation","nist_weierstrauss","fromString","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","fromString","point","secp256r1","ECPointDecompress","publicKeyIntToXY","Error","fromString","nist_weierstrauss","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","fromString","point","secp384r1","ECPointDecompress","publicKeyIntToXY","Error","fromString","nist_weierstrauss","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","fromString","point","secp521r1","ECPointDecompress","publicKeyIntToXY","Error","jwkJcsDecode","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"]}
|
|
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,OAAOA,YAAY;AAGnB,SAASC,iBAAiB;;;ACF1B,YAAYC,SAAS;AAIrB,SAASC,gCAAgC;;;ACHlC,IAAMC,cAAc;AACpB,IAAMC,WAAW;;;ADDxB,IAAM,EAA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","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","nist_weierstrauss","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","jwkJcsDecode","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"]}
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sphereon/ssi-sdk-ext.did-resolver-key",
|
|
3
3
|
"description": "Sphereon did:key resolver with BBS+/BLS and EBSI support.",
|
|
4
|
-
"version": "0.28.1-feature.
|
|
4
|
+
"version": "0.28.1-feature.jose.vcdm.19+2c20244",
|
|
5
5
|
"source": "./src/index.ts",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/index.cjs",
|
|
8
8
|
"module": "./dist/index.js",
|
|
9
9
|
"types": "./dist/index.d.ts",
|
|
10
10
|
"exports": {
|
|
11
|
+
"react-native": "./dist/index.js",
|
|
11
12
|
"import": {
|
|
12
13
|
"types": "./dist/index.d.ts",
|
|
13
14
|
"import": "./dist/index.js"
|
|
@@ -21,7 +22,7 @@
|
|
|
21
22
|
"build": "tsup --config ../../tsup.config.ts --tsconfig ../../tsconfig.tsup.json"
|
|
22
23
|
},
|
|
23
24
|
"dependencies": {
|
|
24
|
-
"@sphereon/ssi-sdk-ext.key-utils": "
|
|
25
|
+
"@sphereon/ssi-sdk-ext.key-utils": "0.28.1-feature.jose.vcdm.19+2c20244",
|
|
25
26
|
"@stablelib/ed25519": "^1.0.3",
|
|
26
27
|
"bigint-mod-arith": "^3.3.1",
|
|
27
28
|
"did-resolver": "^4.1.0",
|
|
@@ -63,5 +64,5 @@
|
|
|
63
64
|
"secp256r1",
|
|
64
65
|
"RSA"
|
|
65
66
|
],
|
|
66
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "2c2024461b7732a2b9c6e6940cc399d5ca4626ac"
|
|
67
68
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { DIDDocument } from 'did-resolver'
|
|
2
2
|
// @ts-ignore
|
|
3
|
-
import
|
|
3
|
+
import * as u8a from 'uint8arrays'
|
|
4
|
+
const { toString } = u8a
|
|
4
5
|
import { KeyToDidDocArgs } from '../index'
|
|
5
6
|
|
|
6
7
|
export const keyToDidDoc = ({ pubKeyBytes, fingerprint }: KeyToDidDocArgs): DIDDocument => {
|
package/src/drivers/ed25519.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
1
|
// @ts-ignore
|
|
3
|
-
import
|
|
2
|
+
import * as u8a from 'uint8arrays'
|
|
3
|
+
const { toString } = u8a
|
|
4
4
|
import { DIDDocument } from 'did-resolver'
|
|
5
5
|
// import { edwardsToMontgomery } from '@noble/curves/ed25519'
|
|
6
6
|
import { convertPublicKeyToX25519 } from '@stablelib/ed25519'
|
package/src/drivers/secp256k1.ts
CHANGED
package/src/drivers/secp256r1.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
// Brent Shambaugh <brent.shambaugh@gmail.com>. 2021.
|
|
2
2
|
|
|
3
3
|
import * as nist_weierstrauss from 'nist-weierstrauss'
|
|
4
|
-
import {base64urlPoint} from 'nist-weierstrauss'
|
|
4
|
+
import { base64urlPoint } from 'nist-weierstrauss'
|
|
5
5
|
// @ts-ignore
|
|
6
|
-
import
|
|
7
|
-
|
|
6
|
+
import * as u8a from 'uint8arrays'
|
|
7
|
+
const { fromString } = u8a
|
|
8
|
+
import { KeyToDidDocArgs } from '../types'
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Constructs the document based on the method key
|
package/src/drivers/secp384r1.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// Brent Shambaugh <brent.shambaugh@gmail.com>. 2021.
|
|
2
2
|
|
|
3
3
|
// @ts-ignore
|
|
4
|
-
import
|
|
4
|
+
import * as u8a from 'uint8arrays'
|
|
5
|
+
const { fromString } = u8a
|
|
5
6
|
|
|
6
7
|
import * as nist_weierstrauss from 'nist-weierstrauss'
|
|
7
8
|
import { base64urlPoint } from 'nist-weierstrauss'
|
package/src/drivers/secp521r1.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// Brent Shambaugh <brent.shambaugh@gmail.com>. 2021.
|
|
2
2
|
|
|
3
3
|
// @ts-ignore
|
|
4
|
-
import
|
|
4
|
+
import * as u8a from 'uint8arrays'
|
|
5
|
+
const { fromString } = u8a
|
|
5
6
|
|
|
6
7
|
import * as nist_weierstrauss from 'nist-weierstrauss'
|
|
7
8
|
import { base64urlPoint } from 'nist-weierstrauss'
|
package/src/index.ts
CHANGED