From 67fbcfe0a3bab916b7bf73d1c17adc509583303e Mon Sep 17 00:00:00 2001 From: Ivan Herman Date: Mon, 26 Aug 2024 11:55:09 +0200 Subject: [PATCH] Got to an equilibrium point --- README.md | 50 +++++++++---------- dist/index.js | 20 ++++---- dist/lib/common.d.ts | 8 +-- dist/lib/common.js | 2 +- dist/lib/convert.js | 18 +++---- dist/lib/ecdsa.js | 4 +- dist/lib/eddsa.js | 4 +- docs/assets/highlight.css | 8 +-- docs/assets/search.js | 2 +- docs/enums/lib_common.CryptoCurves.html | 6 +-- docs/enums/lib_common.CryptoKeyTypes.html | 4 +- docs/functions/index.JWKToMultikey.html | 4 +- docs/functions/index.cryptoToMultikey.html | 4 +- docs/functions/index.multikeyToCrypto.html | 4 +- docs/functions/index.multikeyToJWK.html | 4 +- .../lib_common.preambleToCryptoData.html | 2 +- docs/functions/lib_convert.JWKToMultikey.html | 2 +- docs/functions/lib_convert.multikeyToJWK.html | 2 +- .../lib_ecdsa.JWKToMultikeyBinary.html | 2 +- .../lib_ecdsa.multikeyBinaryToJWK.html | 2 +- .../lib_eddsa.JWKToMultikeyBinary.html | 2 +- .../lib_eddsa.multikeyBinaryToJWK.html | 2 +- docs/index.html | 23 ++++----- docs/interfaces/lib_common.CryptoKeyData.html | 6 +-- docs/interfaces/lib_common.JWKKeyPair.html | 6 +-- docs/interfaces/lib_common.Multikey.html | 4 +- .../interfaces/lib_common.MultikeyBinary.html | 4 +- docs/modules/index.html | 2 +- docs/modules/lib_common.html | 2 +- docs/modules/lib_convert.html | 2 +- docs/modules/lib_ecdsa.html | 2 +- docs/modules/lib_eddsa.html | 2 +- docs/types/lib_common.ClassToDecoder.html | 2 +- docs/types/lib_common.ClassToEncoder.html | 2 +- docs/types/lib_common.ClassToPreamble.html | 2 +- docs/types/lib_common.Multibase.html | 2 +- docs/types/lib_common.Preamble.html | 2 +- docs/variables/lib_common.ECDSACurves.html | 2 +- .../lib_common.Ecdsa256Preambles.html | 2 +- .../lib_common.Ecdsa384Preambles.html | 2 +- docs/variables/lib_common.EddsaPreambles.html | 2 +- .../lib_common.classToDecoder-1.html | 2 +- .../lib_common.classToEncoder-1.html | 2 +- .../lib_common.classToPreamble-1.html | 2 +- index.ts | 20 ++++---- lib/common.ts | 8 +-- lib/convert.ts | 18 +++---- lib/ecdsa.ts | 4 +- lib/eddsa.ts | 4 +- package.json | 6 +-- tests/roundtrip_cry.ts | 11 ++-- tests/roundtrip_jwk.ts | 11 ++-- tests/roundtrip_s_cry.ts | 5 +- tests/roundtrip_s_jwk.ts | 6 +-- 54 files changed, 163 insertions(+), 163 deletions(-) diff --git a/README.md b/README.md index d841f17..e42f86c 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,8 @@ Conversion of cryptographic keys in [Multikey format](https://www.w3.org/TR/cont from [WebCrypto](https://www.w3.org/TR/WebCryptoAPI/) and [JWK](https://datatracker.ietf.org/doc/html/rfc7517). The conversions are available for the three EC curves that are defined for Verifiable Credentials: [ECDSA with P-256 and P-384](https://www.w3.org/TR/vc-di-ecdsa/#multikey) and [EDDSA](https://www.w3.org/TR/vc-di-eddsa/#multikey). -This is really a proof-of-concept implementation. It shows that such conversion _can indeed be done_, -which is an important in proving the practical usability of multikeys. +(This is really a proof-of-concept implementation. It shows that such conversion _can indeed be done_, +which is an important in proving the practical usability of multikeys. It would need extra tests using external Multikeys.) The package has been written in TypeScript+Node.js. (There is also a [Typescript+Deno version](https://github.com/iherman/multikey-webcrypto-d).) @@ -17,24 +17,23 @@ For a more detailed documentation, see the [code documentation](https://iherman. ## Necessary extra types used by the API -The interface makes use of the `JsonWebKey`, `CryptoKeyPair`, and `CryptoKey` types, which are global types in Node.js (or Deno), defined by WebCrypto. +The interface makes use of the `JsonWebKey`, `CryptoKeyPair`, and `CryptoKey` types, which are global types in Node.js (or Deno), defined by WebCrypto. The following types are also exported by the package: ```typescript export interface JWKKeyPair { - public: JsonWebKey; - secret?: JsonWebKey; + publicKey: JsonWebKey; + privateKey?: JsonWebKey; } export type Multibase = string; +// The field names in `Multikey` reflect the Multikey specification. export interface Multikey { publicKeyMultibase: Multibase; secretKeyMultibase?: Multibase; } ``` -The field names in `Multikey` reflect the [Multikey specification](https://www.w3.org/TR/controller-document/#multikey). - ## Usage of the API functions ### Multikey and JWK @@ -42,49 +41,50 @@ The field names in `Multikey` reflect the [Multikey specification](https://www.w ```typescript import * as mkc from "multikey-webcrypto"; -// Convert a JWK Pair to a Multikey Pair: -const jwk_pair: JWKKeyPair = { - public: your_jwk_public_key, - secret: your_jwk_secret_key, +// Get a JWK pair +const jwk_pair: mkc.JWKKeyPair = { + publicKey: your_jwk_public_key, + privateKey: your_jwk_private_key, }; -const mk_pair: MultikeyPair = mkc.JWKToMultikey(jwk_pair); -// mk_pair.publicKeyMultibase and mk_pair.secretKeyMultibase provide the right values +const mk_pair: mkc.Multikey = mkc.JWKToMultikey(jwk_pair); +// mk_pair.publicKeyMultibase and mk_pair.secretKeyMultibase provide the converted values // Convert the multikey back to jwk -const generated_jwk_pair: JWKKeyPair = mkc.multikeyToJWK(mk_pair); +const generated_jwk_pair: mkc.JWKKeyPair = mkc.multikeyToJWK(mk_pair); ``` -In all cases the secret key may be missing or set to `undefined`, so that only the public key is converted. The same can be achieved if the functions are uses with an overloaded signature: +In all cases the secret key may be missing or set to `undefined`, so that only the public key is converted. The same can be achieved if the functions are used with an overloaded signature: ```typescript import * as mkc from "multikey-webcrypto"; -const mk: Multikey = mkc.JWKToMultikey(your_jwk_public_key); +const mk: mkc.Multibase = mkc.JWKToMultikey(your_jwk_public_key); // mk the encoded value // Convert the multikey back to jwk -const generated_jwk_public_key: JWKKeyPair = mkc.multikeyToJWK(mk); +const generated_jwk_public_key: mkc.JWKKeyPair = mkc.multikeyToJWK(mk); ``` ### Multikey and WebCrypto keys -The interface is similar to the JWK case. The only major difference is that functions are asynchronous (the reason is that WebCrypto implementations are using asynchronous functions). -The simplest is to use the `await` constructs in the code: +The interface is similar to the JWK case. The only major difference is that functions are asynchronous (the reason is that WebCrypto implementations are asynchronous). +The simplest approach is to use the `await` constructs in the code: ```typescript import * as mkc from "multikey-webcrypto"; -// Convert a JWK Pair to a Multikey Pair: +// Convert a JWK Pair to a Multikey. +// Note: the `CryptoKeyPair` interface is defined by the WebCrypto implementations, not by this package const crypto_pair: CryptoKeyPair = { - public: your_web_crypto_public_key, - secret: your_web_crypto_secret_key, + publicKey: your_web_crypto_public_key, + privateKey: your_web_crypto_secret_key, }; -const mk_pair: MultikeyPair = await mkc.cryptoToMultikey(crypto_pair); +const mk_pair: Multikey = await mkc.cryptoToMultikey(crypto_pair); // mk_pair.publicKeyMultibase and mk_pair.secretKeyMultibase provide the right values // Convert the multikey back to jwk -const generated_crypto_pair: JWKKeyPair = await mkc.multikeyToCrypto(mk_pair); +const generated_crypto_pair: mkc.JWKKeyPair = await mkc.multikeyToCrypto(mk_pair); ``` Similarly to the JWK case, handling public keys only can be done with the aliased versions of the same functions: @@ -92,7 +92,7 @@ Similarly to the JWK case, handling public keys only can be done with the aliase ```typescript import * as mkc from "multikey-webcrypto"; -const mk: Multikey = mkc.cryptoToMultikey(your_web_crypto_public_key); +const mk: Multibase = mkc.cryptoToMultikey(your_web_crypto_public_key); // mk the encoded value // Convert the multikey back to jwk diff --git a/dist/index.js b/dist/index.js index f847c2d..237dcc7 100644 --- a/dist/index.js +++ b/dist/index.js @@ -23,7 +23,7 @@ function multikeyToJWK(keys) { return jwk_keys; } else { - return jwk_keys.public; + return jwk_keys.publicKey; } } // Implementation of the overloaded functions @@ -32,10 +32,10 @@ async function multikeyToCrypto(keys) { const jwkPair = multikeyToJWK(input); const algorithm = { name: "" }; // We have to establish what the algorithm type is from the public jwk - switch (jwkPair.public.kty) { + switch (jwkPair.publicKey.kty) { case 'EC': algorithm.name = "ECDSA"; - algorithm.namedCurve = jwkPair.public.crv; + algorithm.namedCurve = jwkPair.publicKey.crv; break; case 'OKP': algorithm.name = "Ed25519"; @@ -47,11 +47,11 @@ async function multikeyToCrypto(keys) { throw new Error("Unknown kty value for the JWK key"); } const output = { - publicKey: await crypto.subtle.importKey("jwk", jwkPair.public, algorithm, true, ["verify"]), + publicKey: await crypto.subtle.importKey("jwk", jwkPair.publicKey, algorithm, true, ["verify"]), privateKey: undefined, }; - if (jwkPair.secret != undefined) { - output.privateKey = await crypto.subtle.importKey("jwk", jwkPair.secret, algorithm, true, ["sign"]); + if (jwkPair.privateKey != undefined) { + output.privateKey = await crypto.subtle.importKey("jwk", jwkPair.privateKey, algorithm, true, ["sign"]); } // Got the return, the type depends on the overloaded input type if (isMultikeyPair(keys)) { @@ -64,9 +64,9 @@ async function multikeyToCrypto(keys) { // Implementation of the overloaded functions function JWKToMultikey(keys) { function isJWKKeyPair(obj) { - return obj.public !== undefined; + return obj.publicKey !== undefined; } - const input = isJWKKeyPair(keys) ? keys : { public: keys }; + const input = isJWKKeyPair(keys) ? keys : { publicKey: keys }; const m_keys = convert.JWKToMultikey(input); if (isJWKKeyPair(keys)) { return m_keys; @@ -84,10 +84,10 @@ async function cryptoToMultikey(keys) { const input = isPair ? keys : { publicKey: keys, privateKey: undefined }; // Generate the JWK version of the cryptokeys: const jwkKeyPair = { - public: await crypto.subtle.exportKey("jwk", input.publicKey), + publicKey: await crypto.subtle.exportKey("jwk", input.publicKey), }; if (isPair && input.privateKey !== undefined) { - jwkKeyPair.secret = await crypto.subtle.exportKey("jwk", input.privateKey); + jwkKeyPair.privateKey = await crypto.subtle.exportKey("jwk", input.privateKey); } // Ready for conversion const output = JWKToMultikey(jwkKeyPair); diff --git a/dist/lib/common.d.ts b/dist/lib/common.d.ts index 10f254a..2141cd8 100644 --- a/dist/lib/common.d.ts +++ b/dist/lib/common.d.ts @@ -6,8 +6,8 @@ * Public/secret pair of JWK instances */ export interface JWKKeyPair { - public: JsonWebKey; - secret?: JsonWebKey; + publicKey: JsonWebKey; + privateKey?: JsonWebKey; } /** * Type for a Multibase @@ -33,7 +33,7 @@ export interface MultikeyBinary { /************************************************************************* */ /************************************************************************* */ /** - * Names for the various crypto curve + * Names for the various crypto curves */ export declare enum CryptoCurves { ECDSA_384 = "secp384r1", @@ -108,7 +108,7 @@ export declare const classToEncoder: ClassToEncoder; */ export declare const ECDSACurves: CryptoCurves[]; /** - * This is an internal type, used for the implementation: return the crypto curve and type from a preamble. + * This is an internal type, used for the implementation: return the crypto curve and type from a multikey preamble. * * So far, I have not yet found a way to encode that in a simple table, hence the separate function. */ diff --git a/dist/lib/common.js b/dist/lib/common.js index d37165c..004bf40 100644 --- a/dist/lib/common.js +++ b/dist/lib/common.js @@ -12,7 +12,7 @@ const ecdsa = require("./ecdsa"); /* Values to handle the various preamble bytes for the different key types */ /************************************************************************* */ /** - * Names for the various crypto curve + * Names for the various crypto curves */ var CryptoCurves; (function (CryptoCurves) { diff --git a/dist/lib/convert.js b/dist/lib/convert.js index b9dc856..acae13a 100644 --- a/dist/lib/convert.js +++ b/dist/lib/convert.js @@ -121,10 +121,10 @@ function JWKToMultikey(keys) { throw new Error(`No kty value for the key (${JSON.stringify(key)})`); } }; - const publicKeyCurve = keyCurve(keys.public); + const publicKeyCurve = keyCurve(keys.publicKey); // The secret key class is calculated, but this is just for checking; the two must be identical... - if (keys.secret !== undefined) { - const secretKeyCurve = keyCurve(keys.secret); + if (keys.privateKey !== undefined) { + const secretKeyCurve = keyCurve(keys.privateKey); if (publicKeyCurve !== secretKeyCurve) { throw new Error(`Public and private keys refer to different EC curves (${JSON.stringify(keys)})`); } @@ -132,16 +132,16 @@ function JWKToMultikey(keys) { // The cryptokey values are x, y (for ecdsa), and d (for the secret key). // Each of these are base 64 encoded strings; what we need is the // binary versions thereof. - const x = decodeJWKField(keys.public.x); + const x = decodeJWKField(keys.publicKey.x); if (x === undefined) { - throw new Error(`x value is missing from public key (${JSON.stringify(keys.public)})`); + throw new Error(`x value is missing from public key (${JSON.stringify(keys.publicKey)})`); } - const y = decodeJWKField(keys.public.y); + const y = decodeJWKField(keys.publicKey.y); if (common_1.ECDSACurves.includes(publicKeyCurve) && y === undefined) { - throw new Error(`y value is missing from the ECDSA public key (${JSON.stringify(keys.public)})`); + throw new Error(`y value is missing from the ECDSA public key (${JSON.stringify(keys.publicKey)})`); } - const d = (keys.secret) ? decodeJWKField(keys.secret.d) : undefined; - if (keys.secret && d === undefined) { + const d = (keys.privateKey) ? decodeJWKField(keys.privateKey.d) : undefined; + if (keys.privateKey && d === undefined) { throw new Error(`d value is missing from private key (${JSON.stringify(keys)})`); } const converter = common_1.classToEncoder[publicKeyCurve]; diff --git a/dist/lib/ecdsa.js b/dist/lib/ecdsa.js index a71e5a9..75b4b3a 100644 --- a/dist/lib/ecdsa.js +++ b/dist/lib/ecdsa.js @@ -58,7 +58,7 @@ function multikeyBinaryToJWK(curve, xb, db) { const x = base64.encode(uncompressed.x); const y = base64.encode(uncompressed.y); const output = { - public: { + publicKey: { kty: "EC", crv: (curve === common_1.CryptoCurves.ECDSA_256) ? "P-256" : "P-384", x, @@ -70,7 +70,7 @@ function multikeyBinaryToJWK(curve, xb, db) { } }; if (db !== undefined) { - output.secret = { + output.privateKey = { kty: "EC", crv: (curve === common_1.CryptoCurves.ECDSA_256) ? "P-256" : "P-384", x, diff --git a/dist/lib/eddsa.js b/dist/lib/eddsa.js index 8c07846..8e5f23d 100644 --- a/dist/lib/eddsa.js +++ b/dist/lib/eddsa.js @@ -38,7 +38,7 @@ function JWKToMultikeyBinary(_curve, x, d, _y) { function multikeyBinaryToJWK(_curve, xb, db) { const x = base64.encode(xb); const output = { - public: { + publicKey: { kty: "OKP", crv: "Ed25519", x, @@ -49,7 +49,7 @@ function multikeyBinaryToJWK(_curve, xb, db) { } }; if (db !== undefined) { - output.secret = { + output.privateKey = { kty: "OKP", crv: "Ed25519", x, diff --git a/docs/assets/highlight.css b/docs/assets/highlight.css index c5ab1a3..20ad2d5 100644 --- a/docs/assets/highlight.css +++ b/docs/assets/highlight.css @@ -9,10 +9,10 @@ --dark-hl-3: #4EC9B0; --light-hl-4: #001080; --dark-hl-4: #9CDCFE; - --light-hl-5: #A31515; - --dark-hl-5: #CE9178; - --light-hl-6: #008000; - --dark-hl-6: #6A9955; + --light-hl-5: #008000; + --dark-hl-5: #6A9955; + --light-hl-6: #A31515; + --dark-hl-6: #CE9178; --light-hl-7: #0070C1; --dark-hl-7: #4FC1FF; --light-hl-8: #795E26; diff --git a/docs/assets/search.js b/docs/assets/search.js index fa42585..36e15b4 100644 --- a/docs/assets/search.js +++ b/docs/assets/search.js @@ -1 +1 @@ -window.searchData = "data:application/octet-stream;base64,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"; \ No newline at end of file +window.searchData = "data:application/octet-stream;base64,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"; \ No newline at end of file diff --git a/docs/enums/lib_common.CryptoCurves.html b/docs/enums/lib_common.CryptoCurves.html index c204c9a..d84cfa4 100644 --- a/docs/enums/lib_common.CryptoCurves.html +++ b/docs/enums/lib_common.CryptoCurves.html @@ -1,5 +1,5 @@ -CryptoCurves | Conversions to and from multikeys and WebCrypto - v0.0.1

Names for the various crypto curve

-

Enumeration Members

ECDSA_384 +CryptoCurves | Conversions to and from multikeys and WebCrypto - v0.0.1
+

Enumeration Members

ECDSA_384: "secp384r1"
ECDSA_256: "secp256r1"
EDDSA: "ed25519"
diff --git a/docs/enums/lib_common.CryptoKeyTypes.html b/docs/enums/lib_common.CryptoKeyTypes.html index 9341828..4edf4ff 100644 --- a/docs/enums/lib_common.CryptoKeyTypes.html +++ b/docs/enums/lib_common.CryptoKeyTypes.html @@ -1,4 +1,4 @@ CryptoKeyTypes | Conversions to and from multikeys and WebCrypto - v0.0.1
+

Enumeration Members

PUBLIC: "public"
SECRET: "secret"
diff --git a/docs/functions/index.JWKToMultikey.html b/docs/functions/index.JWKToMultikey.html index 4587f93..a85b385 100644 --- a/docs/functions/index.JWKToMultikey.html +++ b/docs/functions/index.JWKToMultikey.html @@ -7,8 +7,8 @@

Parameters

Returns Multikey

-
  • Overloaded version of the conversion function for a single (public) key in JWK, returning the generated Multikey.

    +
  • Overloaded version of the conversion function for a single (public) key in JWK, returning the generated Multikey.

    Parameters

    • keys: JsonWebKey

    Returns Multibase

    • exceptions if something is incorrect in the incoming data
    -
  • +
    diff --git a/docs/functions/index.cryptoToMultikey.html b/docs/functions/index.cryptoToMultikey.html index c3d16c6..b428409 100644 --- a/docs/functions/index.cryptoToMultikey.html +++ b/docs/functions/index.cryptoToMultikey.html @@ -5,8 +5,8 @@

    Parameters

    Returns Promise<Multikey>

    -
  • Overloaded version of the conversion function for a single (public) key in JWK, returning the generated Multikey.

    +
  • Overloaded version of the conversion function for a single (public) key in JWK, returning the generated Multikey.

    Parameters

    • keys: CryptoKey

    Returns Promise<Multibase>

    • exceptions if something is incorrect in the incoming data
    -
  • +
    diff --git a/docs/functions/index.multikeyToCrypto.html b/docs/functions/index.multikeyToCrypto.html index 1a0062d..9ded4e9 100644 --- a/docs/functions/index.multikeyToCrypto.html +++ b/docs/functions/index.multikeyToCrypto.html @@ -5,8 +5,8 @@

    Parameters

    Returns Promise<CryptoKeyPair>

    -
  • Overloaded version of the conversion function for a single (public) key in Multikey, returning the generated Crypto Key.

    +
  • Overloaded version of the conversion function for a single (public) key in Multikey, returning the generated Crypto Key.

    Parameters

    • keys: string

    Returns Promise<CryptoKey>

    • exceptions if something is incorrect in the incoming data
    -
  • +
    diff --git a/docs/functions/index.multikeyToJWK.html b/docs/functions/index.multikeyToJWK.html index fae2570..ef49dfa 100644 --- a/docs/functions/index.multikeyToJWK.html +++ b/docs/functions/index.multikeyToJWK.html @@ -5,8 +5,8 @@

    Parameters

    Returns JWKKeyPair

    -
  • Overloaded version of the conversion function for a single (public) key in Multikey, returning the generated JWK.

    +
  • Overloaded version of the conversion function for a single (public) key in Multikey, returning the generated JWK.

    Parameters

    • keys: string

    Returns JsonWebKey

    • exceptions if something is incorrect in the incoming data
    -
  • +
    diff --git a/docs/functions/lib_common.preambleToCryptoData.html b/docs/functions/lib_common.preambleToCryptoData.html index 7ed9b9c..00e8019 100644 --- a/docs/functions/lib_common.preambleToCryptoData.html +++ b/docs/functions/lib_common.preambleToCryptoData.html @@ -1,4 +1,4 @@ preambleToCryptoData | Conversions to and from multikeys and WebCrypto - v0.0.1
    • Classify the crypto key based on the multikey preamble characters that are at the start of the code. These are two binary numbers, signalling the crypto category (ecdsa or eddsa) and, in the former case, the additional reference to the exact curve.

      -

      Parameters

      Returns CryptoKeyData

    +

    Parameters

    Returns CryptoKeyData

    diff --git a/docs/functions/lib_convert.JWKToMultikey.html b/docs/functions/lib_convert.JWKToMultikey.html index ec0d050..120dabf 100644 --- a/docs/functions/lib_convert.JWKToMultikey.html +++ b/docs/functions/lib_convert.JWKToMultikey.html @@ -4,4 +4,4 @@ those that would lead to error in this cose. E.g., it does not check whether the x (and possibly y) values are identical in the secret and private JWK keys.

    Works for ecdsa (both P-384 and P-256), and eddsa.

    -

    Parameters

    Returns Multikey

    +

    Parameters

    Returns Multikey

    diff --git a/docs/functions/lib_convert.multikeyToJWK.html b/docs/functions/lib_convert.multikeyToJWK.html index a586e5a..de95617 100644 --- a/docs/functions/lib_convert.multikeyToJWK.html +++ b/docs/functions/lib_convert.multikeyToJWK.html @@ -5,4 +5,4 @@

    Parameters

    Returns JWKKeyPair

    -
    +
    diff --git a/docs/functions/lib_ecdsa.JWKToMultikeyBinary.html b/docs/functions/lib_ecdsa.JWKToMultikeyBinary.html index 6e3a594..41c6fb0 100644 --- a/docs/functions/lib_ecdsa.JWKToMultikeyBinary.html +++ b/docs/functions/lib_ecdsa.JWKToMultikeyBinary.html @@ -8,4 +8,4 @@
  • x: Uint8Array

    x value for the elliptical curve

  • d: Uint8Array

    d (private) value for the elliptical curve

  • Optionaly: Uint8Array

    y value for the elliptical curve

    -
  • Returns MultikeyBinary

    +

    Returns MultikeyBinary

    diff --git a/docs/functions/lib_ecdsa.multikeyBinaryToJWK.html b/docs/functions/lib_ecdsa.multikeyBinaryToJWK.html index 370d6e5..8108f9d 100644 --- a/docs/functions/lib_ecdsa.multikeyBinaryToJWK.html +++ b/docs/functions/lib_ecdsa.multikeyBinaryToJWK.html @@ -6,4 +6,4 @@

    Parameters

    Returns JWKKeyPair

    +

    Returns JWKKeyPair

    diff --git a/docs/functions/lib_eddsa.JWKToMultikeyBinary.html b/docs/functions/lib_eddsa.JWKToMultikeyBinary.html index 1cbd267..e060c30 100644 --- a/docs/functions/lib_eddsa.JWKToMultikeyBinary.html +++ b/docs/functions/lib_eddsa.JWKToMultikeyBinary.html @@ -6,4 +6,4 @@
  • x: Uint8Array

    x value for the elliptical curve, as extracted from JWK

  • d: Uint8Array

    d (private) value for the elliptical curve, as extracted from JWK

  • Optional_y: Uint8Array

    unused in this function, just a placeholder

    -
  • Returns MultikeyBinary

    +

    Returns MultikeyBinary

    diff --git a/docs/functions/lib_eddsa.multikeyBinaryToJWK.html b/docs/functions/lib_eddsa.multikeyBinaryToJWK.html index 2ef0cb6..f990870 100644 --- a/docs/functions/lib_eddsa.multikeyBinaryToJWK.html +++ b/docs/functions/lib_eddsa.multikeyBinaryToJWK.html @@ -6,4 +6,4 @@

    Parameters

    Returns JWKKeyPair

    +

    Returns JWKKeyPair

    diff --git a/docs/index.html b/docs/index.html index 0de504e..cbfcc9e 100644 --- a/docs/index.html +++ b/docs/index.html @@ -2,29 +2,28 @@

    Multikey ↔︎ WebCrypto and JWK conversions (Node.js version)

    Conversion of cryptographic keys in Multikey format to and from WebCrypto and JWK. The conversions are available for the three EC curves that are defined for Verifiable Credentials: ECDSA with P-256 and P-384 and EDDSA.

    -

    This is really a proof-of-concept implementation. It shows that such conversion can indeed be done, -which is an important in proving the practical usability of multikeys.

    +

    (This is really a proof-of-concept implementation. It shows that such conversion can indeed be done, +which is an important in proving the practical usability of multikeys. It would need extra tests using external Multikeys.)

    The package has been written in TypeScript+Node.js. (There is also a Typescript+Deno version.)

    For a more detailed documentation, see the code documentation, generated by typedoc. A short set of examples may help.

    -

    The interface makes use of the JsonWebKey, CryptoKeyPair, and CryptoKey types, which are global types in Node.js (or Deno), defined by WebCrypto.

    -
    export interface JWKKeyPair {
    public: JsonWebKey;
    secret?: JsonWebKey;
    }

    export type Multibase = string;

    export interface Multikey {
    publicKeyMultibase: Multibase;
    secretKeyMultibase?: Multibase;
    } +

    The interface makes use of the JsonWebKey, CryptoKeyPair, and CryptoKey types, which are global types in Node.js (or Deno), defined by WebCrypto. The following types are also exported by the package:

    +
    export interface JWKKeyPair {
    publicKey: JsonWebKey;
    privateKey?: JsonWebKey;
    }

    export type Multibase = string;

    // The field names in `Multikey` reflect the Multikey specification.
    export interface Multikey {
    publicKeyMultibase: Multibase;
    secretKeyMultibase?: Multibase;
    }
    -

    The field names in Multikey reflect the Multikey specification.

    -
    import * as mkc from "multikey-webcrypto";

    // Convert a JWK Pair to a Multikey Pair:
    const jwk_pair: JWKKeyPair = {
    public: your_jwk_public_key,
    secret: your_jwk_secret_key,
    };
    const mk_pair: MultikeyPair = mkc.JWKToMultikey(jwk_pair);
    // mk_pair.publicKeyMultibase and mk_pair.secretKeyMultibase provide the right values

    // Convert the multikey back to jwk
    const generated_jwk_pair: JWKKeyPair = mkc.multikeyToJWK(mk_pair);
    +
    import * as mkc from "multikey-webcrypto";

    // Get a JWK pair
    const jwk_pair: mkc.JWKKeyPair = {
    publicKey: your_jwk_public_key,
    privateKey: your_jwk_private_key,
    };
    const mk_pair: mkc.Multikey = mkc.JWKToMultikey(jwk_pair);
    // mk_pair.publicKeyMultibase and mk_pair.secretKeyMultibase provide the converted values

    // Convert the multikey back to jwk
    const generated_jwk_pair: mkc.JWKKeyPair = mkc.multikeyToJWK(mk_pair);
    -

    In all cases the secret key may be missing or set to undefined, so that only the public key is converted. The same can be achieved if the functions are uses with an overloaded signature:

    -
    import * as mkc from "multikey-webcrypto";

    const mk: Multikey = mkc.JWKToMultikey(your_jwk_public_key);
    // mk the encoded value

    // Convert the multikey back to jwk
    const generated_jwk_public_key: JWKKeyPair = mkc.multikeyToJWK(mk); +

    In all cases the secret key may be missing or set to undefined, so that only the public key is converted. The same can be achieved if the functions are used with an overloaded signature:

    +
    import * as mkc from "multikey-webcrypto";

    const mk: mkc.Multibase = mkc.JWKToMultikey(your_jwk_public_key);
    // mk the encoded value

    // Convert the multikey back to jwk
    const generated_jwk_public_key: mkc.JWKKeyPair = mkc.multikeyToJWK(mk);
    -

    The interface is similar to the JWK case. The only major difference is that functions are asynchronous (the reason is that WebCrypto implementations are using asynchronous functions). -The simplest is to use the await constructs in the code:

    -
    import * as mkc from "multikey-webcrypto";

    // Convert a JWK Pair to a Multikey Pair:
    const crypto_pair: CryptoKeyPair = {
    public: your_web_crypto_public_key,
    secret: your_web_crypto_secret_key,
    };
    const mk_pair: MultikeyPair = await mkc.cryptoToMultikey(crypto_pair);
    // mk_pair.publicKeyMultibase and mk_pair.secretKeyMultibase provide the right values

    // Convert the multikey back to jwk
    const generated_crypto_pair: JWKKeyPair = await mkc.multikeyToCrypto(mk_pair); +

    The interface is similar to the JWK case. The only major difference is that functions are asynchronous (the reason is that WebCrypto implementations are asynchronous). +The simplest approach is to use the await constructs in the code:

    +
    import * as mkc from "multikey-webcrypto";

    // Convert a JWK Pair to a Multikey.
    // Note: the `CryptoKeyPair` interface is defined by the WebCrypto implementations, not by this package
    const crypto_pair: CryptoKeyPair = {
    publicKey: your_web_crypto_public_key,
    privateKey: your_web_crypto_secret_key,
    };
    const mk_pair: Multikey = await mkc.cryptoToMultikey(crypto_pair);
    // mk_pair.publicKeyMultibase and mk_pair.secretKeyMultibase provide the right values

    // Convert the multikey back to jwk
    const generated_crypto_pair: mkc.JWKKeyPair = await mkc.multikeyToCrypto(mk_pair);

    Similarly to the JWK case, handling public keys only can be done with the aliased versions of the same functions:

    -
    import * as mkc from "multikey-webcrypto";

    const mk: Multikey = mkc.cryptoToMultikey(your_web_crypto_public_key);
    // mk the encoded value

    // Convert the multikey back to jwk
    const generated_crypto_key: JWKKeyPair = mkc.multikeyToJWK(mk); +
    import * as mkc from "multikey-webcrypto";

    const mk: Multibase = mkc.cryptoToMultikey(your_web_crypto_public_key);
    // mk the encoded value

    // Convert the multikey back to jwk
    const generated_crypto_key: JWKKeyPair = mkc.multikeyToJWK(mk);
    diff --git a/docs/interfaces/lib_common.CryptoKeyData.html b/docs/interfaces/lib_common.CryptoKeyData.html index 3a976ea..32abe76 100644 --- a/docs/interfaces/lib_common.CryptoKeyData.html +++ b/docs/interfaces/lib_common.CryptoKeyData.html @@ -1,5 +1,5 @@ -CryptoKeyData | Conversions to and from multikeys and WebCrypto - v0.0.1

    This is an internal type, used for the implementation: return the crypto curve and type from a preamble.

    +CryptoKeyData | Conversions to and from multikeys and WebCrypto - v0.0.1

    This is an internal type, used for the implementation: return the crypto curve and type from a multikey preamble.

    So far, I have not yet found a way to encode that in a simple table, hence the separate function.

    -
    interface CryptoKeyData {
        crCurve: CryptoCurves;
        crType: CryptoKeyTypes;
    }

    Properties

    interface CryptoKeyData {
        crCurve: CryptoCurves;
        crType: CryptoKeyTypes;
    }

    Properties

    Properties

    crCurve: CryptoCurves
    +

    Properties

    crCurve: CryptoCurves
    diff --git a/docs/interfaces/lib_common.JWKKeyPair.html b/docs/interfaces/lib_common.JWKKeyPair.html index 7fa02c2..8320882 100644 --- a/docs/interfaces/lib_common.JWKKeyPair.html +++ b/docs/interfaces/lib_common.JWKKeyPair.html @@ -1,4 +1,4 @@ JWKKeyPair | Conversions to and from multikeys and WebCrypto - v0.0.1
    +
    interface JWKKeyPair {
        publicKey: JsonWebKey;
        privateKey?: JsonWebKey;
    }

    Properties

    Properties

    publicKey: JsonWebKey
    privateKey?: JsonWebKey
    diff --git a/docs/interfaces/lib_common.Multikey.html b/docs/interfaces/lib_common.Multikey.html index a12201a..5cbfd60 100644 --- a/docs/interfaces/lib_common.Multikey.html +++ b/docs/interfaces/lib_common.Multikey.html @@ -1,5 +1,5 @@ Multikey | Conversions to and from multikeys and WebCrypto - v0.0.1

    Properties

    publicKeyMultibase: string
    secretKeyMultibase?: string
    diff --git a/docs/interfaces/lib_common.MultikeyBinary.html b/docs/interfaces/lib_common.MultikeyBinary.html index db9d036..0b8825c 100644 --- a/docs/interfaces/lib_common.MultikeyBinary.html +++ b/docs/interfaces/lib_common.MultikeyBinary.html @@ -1,4 +1,4 @@ MultikeyBinary | Conversions to and from multikeys and WebCrypto - v0.0.1

    Same as the Multikey, but decoded and without the preambles. I.e., just the bare key values.

    -
    interface MultikeyBinary {
        public: Uint8Array;
        secret?: Uint8Array;
    }

    Properties

    interface MultikeyBinary {
        public: Uint8Array;
        secret?: Uint8Array;
    }

    Properties

    Properties

    public: Uint8Array
    secret?: Uint8Array
    +

    Properties

    public: Uint8Array
    secret?: Uint8Array
    diff --git a/docs/modules/index.html b/docs/modules/index.html index ef93799..8d8330b 100644 --- a/docs/modules/index.html +++ b/docs/modules/index.html @@ -1,4 +1,4 @@ -index | Conversions to and from multikeys and WebCrypto - v0.0.1

    References

    JWKKeyPair +index | Conversions to and from multikeys and WebCrypto - v0.0.1

    References

    Functions

    multikeyToJWK diff --git a/docs/modules/lib_common.html b/docs/modules/lib_common.html index 64916a5..a16e9d3 100644 --- a/docs/modules/lib_common.html +++ b/docs/modules/lib_common.html @@ -1,5 +1,5 @@ lib/common | Conversions to and from multikeys and WebCrypto - v0.0.1

    Common types, conversion functions and Multikey conversion utilities for the rest of the code.

    -

    Index

    Enumerations

    Index

    Enumerations

    Interfaces

    JWKKeyPair Multikey diff --git a/docs/modules/lib_convert.html b/docs/modules/lib_convert.html index b06c35b..ddda66c 100644 --- a/docs/modules/lib_convert.html +++ b/docs/modules/lib_convert.html @@ -1,4 +1,4 @@ lib/convert | Conversions to and from multikeys and WebCrypto - v0.0.1
    diff --git a/docs/modules/lib_ecdsa.html b/docs/modules/lib_ecdsa.html index 3791c66..5fbe43a 100644 --- a/docs/modules/lib_ecdsa.html +++ b/docs/modules/lib_ecdsa.html @@ -2,6 +2,6 @@ which must be compressed when creating the Multikey representation, and decompressed for the JWK conversion.

    The two exported functions, used by the rest of the package, just branch out to the internal functions that do the key (de)compression itself.

    -

    Index

    Functions

    Index

    Functions

    diff --git a/docs/modules/lib_eddsa.html b/docs/modules/lib_eddsa.html index 27a0f98..1bba7c1 100644 --- a/docs/modules/lib_eddsa.html +++ b/docs/modules/lib_eddsa.html @@ -1,5 +1,5 @@ lib/eddsa | Conversions to and from multikeys and WebCrypto - v0.0.1
    diff --git a/docs/types/lib_common.ClassToDecoder.html b/docs/types/lib_common.ClassToDecoder.html index e8c4c01..5b4bc12 100644 --- a/docs/types/lib_common.ClassToDecoder.html +++ b/docs/types/lib_common.ClassToDecoder.html @@ -1,2 +1,2 @@ ClassToDecoder | Conversions to and from multikeys and WebCrypto - v0.0.1
    +
    diff --git a/docs/types/lib_common.ClassToEncoder.html b/docs/types/lib_common.ClassToEncoder.html index 37e08b6..a67d2e0 100644 --- a/docs/types/lib_common.ClassToEncoder.html +++ b/docs/types/lib_common.ClassToEncoder.html @@ -1,2 +1,2 @@ ClassToEncoder | Conversions to and from multikeys and WebCrypto - v0.0.1
    +
    diff --git a/docs/types/lib_common.ClassToPreamble.html b/docs/types/lib_common.ClassToPreamble.html index 82a8348..705e959 100644 --- a/docs/types/lib_common.ClassToPreamble.html +++ b/docs/types/lib_common.ClassToPreamble.html @@ -1,2 +1,2 @@ ClassToPreamble | Conversions to and from multikeys and WebCrypto - v0.0.1
    +
    diff --git a/docs/types/lib_common.Multibase.html b/docs/types/lib_common.Multibase.html index a8233a0..4eff55f 100644 --- a/docs/types/lib_common.Multibase.html +++ b/docs/types/lib_common.Multibase.html @@ -1,3 +1,3 @@ Multibase | Conversions to and from multikeys and WebCrypto - v0.0.1
    +
    diff --git a/docs/types/lib_common.Preamble.html b/docs/types/lib_common.Preamble.html index 325c25b..f7ff88b 100644 --- a/docs/types/lib_common.Preamble.html +++ b/docs/types/lib_common.Preamble.html @@ -1,2 +1,2 @@ Preamble | Conversions to and from multikeys and WebCrypto - v0.0.1
    +

    Type Parameters

    • T
    diff --git a/docs/variables/lib_common.ECDSACurves.html b/docs/variables/lib_common.ECDSACurves.html index b8c443e..90c69bf 100644 --- a/docs/variables/lib_common.ECDSACurves.html +++ b/docs/variables/lib_common.ECDSACurves.html @@ -1,3 +1,3 @@ ECDSACurves | Conversions to and from multikeys and WebCrypto - v0.0.1
    +
    diff --git a/docs/variables/lib_common.Ecdsa256Preambles.html b/docs/variables/lib_common.Ecdsa256Preambles.html index dd90ef5..e673f76 100644 --- a/docs/variables/lib_common.Ecdsa256Preambles.html +++ b/docs/variables/lib_common.Ecdsa256Preambles.html @@ -1,2 +1,2 @@ Ecdsa256Preambles | Conversions to and from multikeys and WebCrypto - v0.0.1
    +
    diff --git a/docs/variables/lib_common.Ecdsa384Preambles.html b/docs/variables/lib_common.Ecdsa384Preambles.html index 883292e..4b62fa8 100644 --- a/docs/variables/lib_common.Ecdsa384Preambles.html +++ b/docs/variables/lib_common.Ecdsa384Preambles.html @@ -1,2 +1,2 @@ Ecdsa384Preambles | Conversions to and from multikeys and WebCrypto - v0.0.1
    +
    diff --git a/docs/variables/lib_common.EddsaPreambles.html b/docs/variables/lib_common.EddsaPreambles.html index b9cd56b..516d8a5 100644 --- a/docs/variables/lib_common.EddsaPreambles.html +++ b/docs/variables/lib_common.EddsaPreambles.html @@ -1,2 +1,2 @@ EddsaPreambles | Conversions to and from multikeys and WebCrypto - v0.0.1
    +
    diff --git a/docs/variables/lib_common.classToDecoder-1.html b/docs/variables/lib_common.classToDecoder-1.html index 405c6d7..6b6b8b3 100644 --- a/docs/variables/lib_common.classToDecoder-1.html +++ b/docs/variables/lib_common.classToDecoder-1.html @@ -1,2 +1,2 @@ classToDecoder | Conversions to and from multikeys and WebCrypto - v0.0.1
    +
    diff --git a/docs/variables/lib_common.classToEncoder-1.html b/docs/variables/lib_common.classToEncoder-1.html index 1db48f3..57d1882 100644 --- a/docs/variables/lib_common.classToEncoder-1.html +++ b/docs/variables/lib_common.classToEncoder-1.html @@ -1,2 +1,2 @@ classToEncoder | Conversions to and from multikeys and WebCrypto - v0.0.1
    +
    diff --git a/docs/variables/lib_common.classToPreamble-1.html b/docs/variables/lib_common.classToPreamble-1.html index c696508..fa07096 100644 --- a/docs/variables/lib_common.classToPreamble-1.html +++ b/docs/variables/lib_common.classToPreamble-1.html @@ -1,2 +1,2 @@ classToPreamble | Conversions to and from multikeys and WebCrypto - v0.0.1
    +
    diff --git a/index.ts b/index.ts index 0a3791c..b47e6a4 100644 --- a/index.ts +++ b/index.ts @@ -44,7 +44,7 @@ export function multikeyToJWK(keys: Multikey | Multibase): JWKKeyPair | JsonWebK if (isMultikeyPair(keys)) { return jwk_keys; } else { - return jwk_keys.public; + return jwk_keys.publicKey; } } @@ -81,10 +81,10 @@ export async function multikeyToCrypto(keys: Multikey | Multibase): Promise { const publicKey: JsonWebKey = await crypto.subtle.exportKey("jwk", newPair.publicKey); const privateKey: JsonWebKey = await crypto.subtle.exportKey("jwk", newPair.privateKey); - return { public: publicKey, secret: privateKey }; + return { publicKey: publicKey, privateKey: privateKey }; } +/** + * Test: Convert fresh CryptoKeys pairs into Multikey pairs and back; the crypto values should be identical. + */ async function main(): Promise { const onePair = async (label: string, pair: CryptoKeyPair): Promise => { // Do a round-trip @@ -40,9 +43,9 @@ async function main(): Promise { str(mkPair); if (label === "EDDSA") { - console.log(`Values are equal? ${keyPair.secret?.x === mkPair.secret?.x && keyPair?.secret?.d === keyPair?.secret?.d}`) + console.log(`Values are equal? ${keyPair.privateKey?.x === mkPair.privateKey?.x && keyPair?.privateKey?.d === keyPair?.privateKey?.d}`) } else { - console.log(`Values are equal? ${keyPair.secret?.x === mkPair.secret?.x && keyPair.secret?.y === mkPair.secret?.y && keyPair?.secret?.d === keyPair?.secret?.d}`) + console.log(`Values are equal? ${keyPair.privateKey?.x === mkPair.privateKey?.x && keyPair.privateKey?.y === mkPair.privateKey?.y && keyPair?.privateKey?.d === keyPair?.privateKey?.d}`) } } diff --git a/tests/roundtrip_jwk.ts b/tests/roundtrip_jwk.ts index 6419c85..2271935 100644 --- a/tests/roundtrip_jwk.ts +++ b/tests/roundtrip_jwk.ts @@ -9,7 +9,7 @@ export function str(inp: any): void { } /** - * Convert a CryptoKey Pair into a JWK Pair. Not really used by these tools, but handy to have it to help debugging. + * Convert a CryptoKey Pair into a JWK Pair. * @param newPair * @returns */ @@ -17,9 +17,12 @@ export function str(inp: any): void { async function toJWK(newPair: CryptoKeyPair): Promise { const publicKey: JsonWebKey = await crypto.subtle.exportKey("jwk", newPair.publicKey); const privateKey: JsonWebKey = await crypto.subtle.exportKey("jwk", newPair.privateKey); - return { public: publicKey, secret: privateKey }; + return { publicKey: publicKey, privateKey: privateKey }; } +/** + * Test: Convert fresh JWK key pairs into Multikey pairs and back; the crypto values should be identical. + */ async function main(): Promise { const onePair = async (label: string, pair: CryptoKeyPair): Promise => { const keyPair: JWKKeyPair = await toJWK(pair); @@ -33,9 +36,9 @@ async function main(): Promise { str(mkPair); if (label === "EDDSA") { - console.log(`Values are equal? ${keyPair.secret?.x === mkPair.secret?.x && keyPair?.secret?.d === keyPair?.secret?.d}`) + console.log(`Values are equal? ${keyPair.privateKey?.x === mkPair.privateKey?.x && keyPair?.privateKey?.d === keyPair?.privateKey?.d}`) } else { - console.log(`Values are equal? ${keyPair.secret?.x === mkPair.secret?.x && keyPair.secret?.y === mkPair.secret?.y && keyPair?.secret?.d === keyPair?.secret?.d}`) + console.log(`Values are equal? ${keyPair.privateKey?.x === mkPair.privateKey?.x && keyPair.privateKey?.y === mkPair.privateKey?.y && keyPair?.privateKey?.d === keyPair?.privateKey?.d}`) } } diff --git a/tests/roundtrip_s_cry.ts b/tests/roundtrip_s_cry.ts index ca44019..611f25e 100644 --- a/tests/roundtrip_s_cry.ts +++ b/tests/roundtrip_s_cry.ts @@ -11,11 +11,8 @@ export function str(inp: any): void { } /** - * Convert a CryptoKey Pair into a JWK Pair. Not really used by these tools, but handy to have it to help debugging. - * @param newPair - * @returns + * Test: Convert fresh public CryptoKeys into Multikey and back; the crypto values should be identical. */ - async function main(): Promise { const onePair = async (label: string, key: CryptoKey): Promise => { // Do a round-trip diff --git a/tests/roundtrip_s_jwk.ts b/tests/roundtrip_s_jwk.ts index 2e5f404..7edb151 100644 --- a/tests/roundtrip_s_jwk.ts +++ b/tests/roundtrip_s_jwk.ts @@ -8,12 +8,10 @@ export function str(inp: any): void { console.log(JSON.stringify(inp, null, 4)); } + /** - * Convert a CryptoKey Pair into a JWK Pair. Not really used by these tools, but handy to have it to help debugging. - * @param newPair - * @returns + * Test: Convert fresh JWK public key into Multikey and back; the crypto values should be identical. */ - async function main(): Promise { const onePair = async (label: string, key: CryptoKey): Promise => { const key_jwk: JsonWebKey = await crypto.subtle.exportKey("jwk", key);