@sphereon/ssi-sdk-ext.did-resolver-key 0.28.1-feature.esm.cjs.8 → 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 CHANGED
@@ -37,11 +37,11 @@ __export(index_exports, {
37
37
  getResolver: () => getResolver
38
38
  });
39
39
  module.exports = __toCommonJS(index_exports);
40
- var import_varint = require("varint");
40
+ var import_varint = __toESM(require("varint"), 1);
41
41
  var import_base58 = require("multiformats/bases/base58");
42
42
 
43
43
  // src/drivers/ed25519.ts
44
- var import_to_string = require("uint8arrays/to-string");
44
+ var u8a = __toESM(require("uint8arrays"), 1);
45
45
  var import_ed25519 = require("@stablelib/ed25519");
46
46
 
47
47
  // src/types.ts
@@ -49,12 +49,13 @@ var DID_LD_JSON = "application/did+ld+json";
49
49
  var DID_JSON = "application/did+json";
50
50
 
51
51
  // src/drivers/ed25519.ts
52
+ var { toString } = u8a;
52
53
  function encodeKey(key, encodeKey2) {
53
54
  const bytes = new Uint8Array(key.length + 2);
54
55
  bytes[0] = encodeKey2 ?? 236;
55
56
  bytes[1] = 1;
56
57
  bytes.set(key, 2);
57
- return `z${(0, import_to_string.toString)(bytes, "base58btc")}`;
58
+ return `z${toString(bytes, "base58btc")}`;
58
59
  }
59
60
  __name(encodeKey, "encodeKey");
60
61
  var keyToDidDoc = /* @__PURE__ */ __name((args) => {
@@ -93,13 +94,13 @@ var keyToDidDoc2018_2019 = /* @__PURE__ */ __name(({ pubKeyBytes, fingerprint, c
93
94
  id: keyId,
94
95
  type: "Ed25519VerificationKey2018",
95
96
  controller: did,
96
- publicKeyBase58: (0, import_to_string.toString)(pubKeyBytes, "base58btc")
97
+ publicKeyBase58: toString(pubKeyBytes, "base58btc")
97
98
  },
98
99
  {
99
100
  id: x25519KeyId,
100
101
  type: "X25519KeyAgreementKey2019",
101
102
  controller: did,
102
- publicKeyBase58: (0, import_to_string.toString)(x25519PubBytes, "base58btc")
103
+ publicKeyBase58: toString(x25519PubBytes, "base58btc")
103
104
  }
104
105
  ],
105
106
  authentication: [
@@ -168,7 +169,8 @@ var ed25519_default = {
168
169
  };
169
170
 
170
171
  // src/drivers/bls12381g2.ts
171
- var import_to_string2 = require("uint8arrays/to-string");
172
+ var u8a2 = __toESM(require("uint8arrays"), 1);
173
+ var { toString: toString2 } = u8a2;
172
174
  var keyToDidDoc2 = /* @__PURE__ */ __name(({ pubKeyBytes, fingerprint }) => {
173
175
  const did = `did:key:${fingerprint}`;
174
176
  const keyId = `${did}#${fingerprint}`;
@@ -179,7 +181,7 @@ var keyToDidDoc2 = /* @__PURE__ */ __name(({ pubKeyBytes, fingerprint }) => {
179
181
  id: keyId,
180
182
  type: "Bls12381G2Key2020",
181
183
  controller: did,
182
- publicKeyBase58: (0, import_to_string2.toString)(pubKeyBytes, "base58btc")
184
+ publicKeyBase58: toString2(pubKeyBytes, "base58btc")
183
185
  }
184
186
  ],
185
187
  authentication: [
@@ -201,7 +203,8 @@ var bls12381g2_default = {
201
203
  };
202
204
 
203
205
  // src/drivers/secp256k1.ts
204
- var import_to_string3 = require("uint8arrays/to-string");
206
+ var u8a3 = __toESM(require("uint8arrays"), 1);
207
+ var { toString: toString3 } = u8a3;
205
208
  var keyToDidDoc3 = /* @__PURE__ */ __name(({ pubKeyBytes, fingerprint }) => {
206
209
  const did = `did:key:${fingerprint}`;
207
210
  const keyId = `${did}#${fingerprint}`;
@@ -212,7 +215,7 @@ var keyToDidDoc3 = /* @__PURE__ */ __name(({ pubKeyBytes, fingerprint }) => {
212
215
  id: keyId,
213
216
  type: "Secp256k1VerificationKey2018",
214
217
  controller: did,
215
- publicKeyBase58: (0, import_to_string3.toString)(pubKeyBytes, "base58btc")
218
+ publicKeyBase58: toString3(pubKeyBytes, "base58btc")
216
219
  }
217
220
  ],
218
221
  authentication: [
@@ -235,7 +238,8 @@ var secp256k1_default = {
235
238
 
236
239
  // src/drivers/secp256r1.ts
237
240
  var nist_weierstrauss = __toESM(require("nist-weierstrauss"), 1);
238
- var import_from_string = require("uint8arrays/from-string");
241
+ var u8a4 = __toESM(require("uint8arrays"), 1);
242
+ var { fromString } = u8a4;
239
243
  function keyToDidDoc4({ pubKeyBytes, fingerprint }) {
240
244
  const did = `did:key:${fingerprint}`;
241
245
  const keyId = `${did}#${fingerprint}`;
@@ -287,7 +291,7 @@ function pubKeyBytesToXY(pubKeyBytes) {
287
291
  }
288
292
  if (bytesCount == 33) {
289
293
  if (publicKeyHex.slice(0, 2) == "03" || publicKeyHex.slice(0, 2) == "02") {
290
- const publicKey = (0, import_from_string.fromString)(publicKeyHex, "base16");
294
+ const publicKey = fromString(publicKeyHex, "base16");
291
295
  const point = nist_weierstrauss.secp256r1.ECPointDecompress(publicKey);
292
296
  return nist_weierstrauss.nist_weierstrauss_common.publicKeyIntToXY(point);
293
297
  }
@@ -300,8 +304,9 @@ var secp256r1_default = {
300
304
  };
301
305
 
302
306
  // src/drivers/secp384r1.ts
303
- var import_from_string2 = require("uint8arrays/from-string");
307
+ var u8a5 = __toESM(require("uint8arrays"), 1);
304
308
  var nist_weierstrauss2 = __toESM(require("nist-weierstrauss"), 1);
309
+ var { fromString: fromString2 } = u8a5;
305
310
  function keyToDidDoc5({ pubKeyBytes, fingerprint }) {
306
311
  const did = `did:key:${fingerprint}`;
307
312
  const keyId = `${did}#${fingerprint}`;
@@ -353,7 +358,7 @@ function pubKeyBytesToXY2(pubKeyBytes) {
353
358
  }
354
359
  if (bytesCount == 49) {
355
360
  if (publicKeyHex.slice(0, 2) == "03" || publicKeyHex.slice(0, 2) == "02") {
356
- const publicKey = (0, import_from_string2.fromString)(publicKeyHex, "base16");
361
+ const publicKey = fromString2(publicKeyHex, "base16");
357
362
  const point = nist_weierstrauss2.secp384r1.ECPointDecompress(publicKey);
358
363
  return nist_weierstrauss2.nist_weierstrauss_common.publicKeyIntToXY(point);
359
364
  }
@@ -366,8 +371,9 @@ var secp384r1_default = {
366
371
  };
367
372
 
368
373
  // src/drivers/secp521r1.ts
369
- var import_from_string3 = require("uint8arrays/from-string");
374
+ var u8a6 = __toESM(require("uint8arrays"), 1);
370
375
  var nist_weierstrauss3 = __toESM(require("nist-weierstrauss"), 1);
376
+ var { fromString: fromString3 } = u8a6;
371
377
  function keyToDidDoc6({ pubKeyBytes, fingerprint }) {
372
378
  const did = `did:key:${fingerprint}`;
373
379
  const keyId = `${did}#${fingerprint}`;
@@ -409,7 +415,7 @@ function pubKeyBytesToXY3(pubKeyBytes) {
409
415
  const publicKeyHex = nist_weierstrauss3.nist_weierstrauss_common.pubKeyBytesToHex(pubKeyBytes);
410
416
  if (132 <= publicKeyHex.length && publicKeyHex.length <= 134) {
411
417
  if (publicKeyHex.slice(0, 2) == "03" || publicKeyHex.slice(0, 2) == "02") {
412
- const publicKey = (0, import_from_string3.fromString)(publicKeyHex, "base16");
418
+ const publicKey = fromString3(publicKeyHex, "base16");
413
419
  const point = nist_weierstrauss3.secp521r1.ECPointDecompress(publicKey);
414
420
  return nist_weierstrauss3.nist_weierstrauss_common.publicKeyIntToXY(point);
415
421
  }
@@ -462,6 +468,7 @@ var jwk_jcs_default = {
462
468
  };
463
469
 
464
470
  // src/index.ts
471
+ var { decode } = import_varint.default;
465
472
  var prefixToDriverMap = {
466
473
  231: secp256k1_default,
467
474
  237: ed25519_default,
@@ -484,8 +491,8 @@ var getResolver = /* @__PURE__ */ __name(() => {
484
491
  };
485
492
  try {
486
493
  const multicodecPubKey = import_base58.base58btc.decode(parsed.id);
487
- const keyType = (0, import_varint.decode)(multicodecPubKey);
488
- const pubKeyBytes = multicodecPubKey.slice(import_varint.decode.bytes);
494
+ const keyType = decode(multicodecPubKey);
495
+ const pubKeyBytes = multicodecPubKey.slice(decode.bytes);
489
496
  const args = {
490
497
  pubKeyBytes,
491
498
  fingerprint: parsed.id,
@@ -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 { decode } from '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],\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KAAMC;EACN,OAAQC;AACV;AAEO,IAAMC,cAAc,6BAAA;AACzB,SAAO;IACLC,KAAK,8BAAOC,KAAaC,QAAmBC,GAAeC,YAAAA;AACzD,YAAMC,cAAcD,QAAQE,UAAUC;AACtC,YAAMC,WAAgC;QACpCC,uBAAuB;UAAEJ;QAAY;QACrCK,aAAa;QACbC,qBAAqB,CAAC;MACxB;AACA,UAAI;AACF,cAAMC,mBAAmBC,wBAAUC,OAAOZ,OAAOa,EAAE;AACnD,cAAMC,cAAUF,sBAAOF,gBAAAA;AACvB,cAAMK,cAAcL,iBAAiBM,MAAMJ,qBAAOK,KAAK;AACvD,cAAMC,OAAwB;UAAEH;UAAaI,aAAanB,OAAOa;UAAIV;UAAaD;QAAQ;AAC1F,cAAMkB,MAAM,MAAM/B,kBAAkByB,OAAAA,EAASO,YAAYH,IAAAA;AACzD,YAAIf,gBAAgBE,aAAa;AAC/B,cAAI,CAACe,IAAI,UAAA,GAAa;AACpBA,gBAAI,UAAA,IAAc;UACpB,WACEE,MAAMC,QAAQH,IAAI,UAAA,CAAW,KAC7B,CAACA,IAAI,UAAA,EAAYI,SAAS,yBAAA,KAC1B,CAACJ,IAAI,UAAA,EAAYI,SAAS,8BAAA,GAC1B;AACAJ,gBAAI,UAAA,EAAYK,KAAK,yBAAA;UACvB;AACAnB,mBAASE,cAAcY;QACzB,WAAWjB,gBAAgBuB,UAAU;AACnCpB,mBAASE,cAAcY;QACzB,OAAO;AACL,iBAAOd,SAASC,sBAAsBJ;AACtCG,mBAASC,sBAAsBoB,QAAQ;QACzC;MACF,SAASC,GAAQ;AACftB,iBAASC,sBAAsBoB,QAAQ;AACvCrB,iBAASC,sBAAsBsB,UAAUD,EAAEE,SAAQ;MACrD;AACA,aAAOxB;IACT,GAnCK;EAoCP;AACF,GAvC2B;AAwC3B,IAAA,gBAAe;EAAET;AAAY;","names":["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","import_to_string","keyToDidDoc","pubKeyBytes","fingerprint","did","keyId","id","verificationMethod","type","controller","publicKeyBase58","toString","authentication","assertionMethod","capabilityDelegation","capabilityInvocation","import_to_string","keyToDidDoc","pubKeyBytes","fingerprint","did","keyId","id","verificationMethod","type","controller","publicKeyBase58","toString","authentication","assertionMethod","capabilityDelegation","capabilityInvocation","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","import_from_string","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","import_from_string","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","keyToDidDoc","pubKeyBytes","fingerprint","contentType","did","keyId","publicKeyJwk","jwkJcsDecode","DID_LD_JSON","id","verificationMethod","type","controller","authentication","assertionMethod","capabilityDelegation","capabilityInvocation","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","decode","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;;;;;;;;AAAA,oBAAmB;AAGnB,oBAA0B;;;ACF1B,UAAqB;AAIrB,qBAAyC;;;ACHlC,IAAMA,cAAc;AACpB,IAAMC,WAAW;;;ADDxB,IAAM,EAAEC,SAAQ,IAAKC;AAMrB,SAASC,UAAUC,KAAiBD,YAAkB;AACpD,QAAME,QAAQ,IAAIC,WAAWF,IAAIG,SAAS,CAAA;AAC1CF,QAAM,CAAA,IAAKF,cAAa;AAGxBE,QAAM,CAAA,IAAK;AACXA,QAAMG,IAAIJ,KAAK,CAAA;AACf,SAAO,IAAIH,SAASI,OAAO,WAAA,CAAA;AAC7B;AARSF;AAUF,IAAMM,cAAc,wBAACC,SAAAA;AAC1B,QAAM,EAAEC,QAAO,IAAKD;AACpB,MAAI,CAACC,SAASC,iBAAiB;AAC7B,WAAOC,gBAAgBH,IAAAA;EACzB;AACA,UAAQC,QAAQC,iBAAe;IAC7B,KAAK;IACL,KAAK;AACH,aAAOE,qBAAqBJ,IAAAA;IAC9B,KAAK;IAC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1F,cAAMiB,MAAM,MAAM9B,kBAAkBwB,OAAAA,EAASO,YAAYH,IAAAA;AACzD,YAAId,gBAAgBE,aAAa;AAC/B,cAAI,CAACc,IAAI,UAAA,GAAa;AACpBA,gBAAI,UAAA,IAAc;UACpB,WACEE,MAAMC,QAAQH,IAAI,UAAA,CAAW,KAC7B,CAACA,IAAI,UAAA,EAAYI,SAAS,yBAAA,KAC1B,CAACJ,IAAI,UAAA,EAAYI,SAAS,8BAAA,GAC1B;AACAJ,gBAAI,UAAA,EAAYK,KAAK,yBAAA;UACvB;AACAlB,mBAASE,cAAcW;QACzB,WAAWhB,gBAAgBsB,UAAU;AACnCnB,mBAASE,cAAcW;QACzB,OAAO;AACL,iBAAOb,SAASC,sBAAsBJ;AACtCG,mBAASC,sBAAsBmB,QAAQ;QACzC;MACF,SAASC,GAAQ;AACfrB,iBAASC,sBAAsBmB,QAAQ;AACvCpB,iBAASC,sBAAsBqB,UAAUD,EAAEE,SAAQ;MACrD;AACA,aAAOvB;IACT,GAnCK;EAoCP;AACF,GAvC2B;AAwC3B,IAAA,gBAAe;EAAET;AAAY;","names":["DID_LD_JSON","DID_JSON","toString","u8a","encodeKey","key","bytes","Uint8Array","length","set","keyToDidDoc","args","options","publicKeyFormat","keyToDidDoc2020","keyToDidDoc2018_2019","Error","pubKeyBytes","fingerprint","contentType","did","keyId","x25519PubBytes","convertPublicKeyToX25519","x25519KeyId","DID_LD_JSON","id","verificationMethod","type","controller","publicKeyBase58","authentication","assertionMethod","capabilityDelegation","capabilityInvocation","keyAgreement","publicKeyMultibase","u8a","toString","u8a","keyToDidDoc","pubKeyBytes","fingerprint","did","keyId","id","verificationMethod","type","controller","publicKeyBase58","authentication","assertionMethod","capabilityDelegation","capabilityInvocation","u8a","toString","u8a","keyToDidDoc","pubKeyBytes","fingerprint","did","keyId","id","verificationMethod","type","controller","publicKeyBase58","authentication","assertionMethod","capabilityDelegation","capabilityInvocation","u8a","fromString","u8a","keyToDidDoc","pubKeyBytes","fingerprint","did","keyId","key","pubKeyBytesToXY","id","verificationMethod","type","controller","publicKeyJwk","kty","crv","x","xm","y","ym","authentication","assertionMethod","capabilityDelegation","capabilityInvocation","nist_weierstrauss_common","testUint8Array","TypeError","publicKeyHex","pubKeyBytesToHex","bytesCount","length","publicKeyToXY","slice","publicKey","point","secp256r1","ECPointDecompress","publicKeyIntToXY","Error","u8a","nist_weierstrauss","fromString","u8a","keyToDidDoc","pubKeyBytes","fingerprint","did","keyId","key","pubKeyBytesToXY","id","verificationMethod","type","controller","publicKeyJwk","kty","crv","x","xm","y","ym","authentication","assertionMethod","capabilityDelegation","capabilityInvocation","nist_weierstrauss_common","testUint8Array","TypeError","publicKeyHex","pubKeyBytesToHex","bytesCount","length","publicKeyToXY","slice","publicKey","point","secp384r1","ECPointDecompress","publicKeyIntToXY","Error","u8a","nist_weierstrauss","fromString","u8a","keyToDidDoc","pubKeyBytes","fingerprint","did","keyId","key","pubKeyBytesToXY","id","verificationMethod","type","controller","publicKeyJwk","kty","crv","x","xm","y","ym","authentication","assertionMethod","capabilityDelegation","capabilityInvocation","nist_weierstrauss_common","testUint8Array","TypeError","publicKeyHex","pubKeyBytesToHex","length","slice","publicKey","point","secp521r1","ECPointDecompress","publicKeyIntToXY","Error","keyToDidDoc","pubKeyBytes","fingerprint","contentType","did","keyId","publicKeyJwk","jwkJcsDecode","DID_LD_JSON","id","verificationMethod","type","controller","authentication","assertionMethod","capabilityDelegation","capabilityInvocation","decode","varint","prefixToDriverMap","secp256k1","ed25519","secp256r1","secp384r1","secp521r1","bls12381g2","jwkJcs","getResolver","key","did","parsed","r","options","contentType","accept","DID_LD_JSON","response","didResolutionMetadata","didDocument","didDocumentMetadata","multicodecPubKey","base58btc","id","keyType","pubKeyBytes","slice","bytes","args","fingerprint","doc","keyToDidDoc","Array","isArray","includes","push","DID_JSON","error","e","message","toString"]}
package/dist/index.js CHANGED
@@ -2,11 +2,11 @@ var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
3
 
4
4
  // src/index.ts
5
- import { decode } from "varint";
5
+ import varint from "varint";
6
6
  import { base58btc } from "multiformats/bases/base58";
7
7
 
8
8
  // src/drivers/ed25519.ts
9
- import { toString } from "uint8arrays/to-string";
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 { toString as toString2 } from "uint8arrays/to-string";
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 { toString as toString3 } from "uint8arrays/to-string";
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 { fromString } from "uint8arrays/from-string";
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 { fromString as fromString2 } from "uint8arrays/from-string";
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 { fromString as fromString3 } from "uint8arrays/from-string";
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}`;
@@ -427,6 +433,7 @@ var jwk_jcs_default = {
427
433
  };
428
434
 
429
435
  // src/index.ts
436
+ var { decode } = varint;
430
437
  var prefixToDriverMap = {
431
438
  231: secp256k1_default,
432
439
  237: ed25519_default,
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 { decode } from '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,SAASA,cAAc;AAEvB,SAASC,iBAAiB;;;ACA1B,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;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AAMC,UAAUF,OAAOF,gBAAAA;AACvB,cAAMK,cAAcL,iBAAiBM,MAAMJ,OAAOK,KAAK;AACvD,cAAMC,OAAwB;UAAEH;UAAaI,aAAanB,OAAOa;UAAIV;UAAaD;QAAQ;AAC1F,cAAMkB,MAAM,MAAM/B,kBAAkByB,OAAAA,EAASO,YAAYH,IAAAA;AACzD,YAAIf,gBAAgBE,aAAa;AAC/B,cAAI,CAACe,IAAI,UAAA,GAAa;AACpBA,gBAAI,UAAA,IAAc;UACpB,WACEE,MAAMC,QAAQH,IAAI,UAAA,CAAW,KAC7B,CAACA,IAAI,UAAA,EAAYI,SAAS,yBAAA,KAC1B,CAACJ,IAAI,UAAA,EAAYI,SAAS,8BAAA,GAC1B;AACAJ,gBAAI,UAAA,EAAYK,KAAK,yBAAA;UACvB;AACAnB,mBAASE,cAAcY;QACzB,WAAWjB,gBAAgBuB,UAAU;AACnCpB,mBAASE,cAAcY;QACzB,OAAO;AACL,iBAAOd,SAASC,sBAAsBJ;AACtCG,mBAASC,sBAAsBoB,QAAQ;QACzC;MACF,SAASC,GAAQ;AACftB,iBAASC,sBAAsBoB,QAAQ;AACvCrB,iBAASC,sBAAsBsB,UAAUD,EAAEE,SAAQ;MACrD;AACA,aAAOxB;IACT,GAnCK;EAoCP;AACF,GAvC2B;AAwC3B,IAAA,gBAAe;EAAET;AAAY;","names":["decode","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","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","decode","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,EAAEC,SAAQ,IAAKC;AAMrB,SAASC,UAAUC,KAAiBD,YAAkB;AACpD,QAAME,QAAQ,IAAIC,WAAWF,IAAIG,SAAS,CAAA;AAC1CF,QAAM,CAAA,IAAKF,cAAa;AAGxBE,QAAM,CAAA,IAAK;AACXA,QAAMG,IAAIJ,KAAK,CAAA;AACf,SAAO,IAAIH,SAASI,OAAO,WAAA,CAAA;AAC7B;AARSF;AAUF,IAAMM,cAAc,wBAACC,SAAAA;AAC1B,QAAM,EAAEC,QAAO,IAAKD;AACpB,MAAI,CAACC,SAASC,iBAAiB;AAC7B,WAAOC,gBAAgBH,IAAAA;EACzB;AACA,UAAQC,QAAQC,iBAAe;IAC7B,KAAK;IACL,KAAK;AACH,aAAOE,qBAAqBJ,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,EAAEE,aAAaC,aAAaC,YAAW,MAAmB;AACtF,QAAMC,MAAM,WAAWF,WAAAA;AACvB,QAAMG,QAAQ,GAAGD,GAAAA,IAAOF,WAAAA;AAKxB,QAAMI,iBAA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,GAC1B;AACAJ,gBAAI,UAAA,EAAYK,KAAK,yBAAA;UACvB;AACAlB,mBAASE,cAAcW;QACzB,WAAWhB,gBAAgBsB,UAAU;AACnCnB,mBAASE,cAAcW;QACzB,OAAO;AACL,iBAAOb,SAASC,sBAAsBJ;AACtCG,mBAASC,sBAAsBmB,QAAQ;QACzC;MACF,SAASC,GAAQ;AACfrB,iBAASC,sBAAsBmB,QAAQ;AACvCpB,iBAASC,sBAAsBqB,UAAUD,EAAEE,SAAQ;MACrD;AACA,aAAOvB;IACT,GAnCK;EAoCP;AACF,GAvC2B;AAwC3B,IAAA,gBAAe;EAAET;AAAY;","names":["varint","base58btc","u8a","convertPublicKeyToX25519","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","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.esm.cjs.8+4c162d1",
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": "^0.28.1-feature.esm.cjs.8+4c162d1",
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": "4c162d14577f462070adeea3e7ec5a443c324ee7"
67
+ "gitHead": "2c2024461b7732a2b9c6e6940cc399d5ca4626ac"
67
68
  }
@@ -1,6 +1,7 @@
1
1
  import { DIDDocument } from 'did-resolver'
2
2
  // @ts-ignore
3
- import { toString } from 'uint8arrays/to-string'
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 => {
@@ -1,6 +1,6 @@
1
-
2
1
  // @ts-ignore
3
- import { toString } from 'uint8arrays/to-string'
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'
@@ -1,5 +1,6 @@
1
1
  // @ts-ignore
2
- import { toString } from 'uint8arrays/to-string'
2
+ import * as u8a from 'uint8arrays'
3
+ const { toString } = u8a
3
4
  import { DIDDocument } from 'did-resolver'
4
5
  import { KeyToDidDocArgs } from '../types'
5
6
 
@@ -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 {fromString} from 'uint8arrays/from-string'
7
- import {KeyToDidDocArgs} from '../types'
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
@@ -1,7 +1,8 @@
1
1
  // Brent Shambaugh <brent.shambaugh@gmail.com>. 2021.
2
2
 
3
3
  // @ts-ignore
4
- import { fromString } from 'uint8arrays/from-string'
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'
@@ -1,7 +1,8 @@
1
1
  // Brent Shambaugh <brent.shambaugh@gmail.com>. 2021.
2
2
 
3
3
  // @ts-ignore
4
- import { fromString } from 'uint8arrays/from-string'
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
@@ -1,4 +1,5 @@
1
- import { decode } from 'varint'
1
+ import varint from 'varint'
2
+ const { decode } = varint
2
3
  // @ts-ignore
3
4
  import { base58btc } from 'multiformats/bases/base58'
4
5
  import ed25519 from './drivers/ed25519'