default
--- NOT PRODUCTION READY. WOULD NEED INTEROPERABILITY TESTS---
Convert a Crypto Key pair to Multikeys. This function exports the cryptokeys into a JWK Key pair,
and uses the JWKToMultikey
function.
Convert a JWK Key pair to Multikeys. This function decodes the JWK keys, finds out which binary key it encodes and, converts the key to the multikey versions depending on the exact curve.
Type for a Multibase
Pair of keys in Multibase encoding. Using the field names as defined in the Multikey specification.
Convert a multikey pair to Web Crypto. This function decodes the multikey data into JWK using the
multikeyToJWK
function, and imports the resulting keys into Web Crypto.
Convert a multikey pair to JWK. This function decodes the multikey data into a binary buffer, checks the preambles and invokes the crypto specific converter functions (depending on the preamble values) that do the final conversion from the binary data to JWK.
lib/common.ts
Common types, conversion functions and Multikey conversion utilities for the rest of the code.
Type definition for the table mapping curves to their decoder functions (i.e., mapping the Multikey to JWK).
What coder function must be used to convert from Multikey to JWK (data)?
Type definition for the table mapping curves to their encoder functions (i.e., mapping the JWK to Multikey).
What coder function must be used to convert from JWK to Multikey?
Type definition for the table mapping preambles to a specific curve.
What preambles must be used for a Curve?
Names for the various crypto curves
This is an internal type, used for the implementation: return the crypto curve and type from a multikey preamble.
Names for the key types
Preamble for ECDSA P-256
, a.k.a. secp256r1
curve
Preamble for ECDSA P-384
, a.k.a. secp384r1
curve
List of possible ECDSA Curves. Having this here declaratively may make it easier if in the future, a new curve is added to the family (P-512)?
Preamble value for EDDSA, a.k.a. ed25519
curve
Type for a Multibase
Pair of keys in Multibase encoding. Using the field names as defined in the Multikey specification.
Same as the Multikey, but decoded and without the preambles. I.e., just the bare key values.
Type used for preambles, which are, so far, a single pair of numbers.
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.
lib/convert.ts
The real work for the whole library are done in the main functions in this module.
Convert JWK Key pair to Multikeys. This function decodes the JWK keys, finds out which binary key it encodes and converts the key to the multikey versions depending on the exact curve.
Generic function to convert a multikey pair to JWK. This function decodes the multikey data into a binary buffer, checks the preambles and invokes the crypto curve specific converter functions (depending on the preamble values) that do the final conversion from the binary data to JWK.
lib/ecdsa.ts
Base conversion functions for ECDSA. The Multikey definition requires the usage of a compressed public key which must be compressed when creating the Multikey representation, and decompressed for the JWK conversion.
Convert the Crypto values from JWK to the equivalent Multikey Pairs' binary data. The final encoding, with preambles, are done in the general level.
Convert the multikey values to their JWK equivalents. The final x
and d
values are encoded
in base64 and then the relevant JWK structure are created
lib/eddsa.ts
Base conversion functions for EDDSA. The functions are straightforward, but the interfaces are made so that they coincide with the companion functions in ECDSA.
Convert the Crypto values from JWK to the equivalent Multikey Pairs' binary data. The final encoding, with preambles, are done in the general level.
Convert the multikey values to their JWK equivalents. The final x
and d
values are encoded
in base64 and then the relevant JWK structure are created