diff --git a/mod.ts b/mod.ts index 6fd6402..c26c215 100644 --- a/mod.ts +++ b/mod.ts @@ -42,6 +42,15 @@ function codecFromCode(code: bigint): Codec { throw new TypeError("Unknown algorithm and/or key type"); } +/** + * + * @param key The [`CryptoKey`](https://developer.mozilla.org/en-US/docs/Web/API/CryptoKey) to export. + * @returns A [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that fulfills with a string containing the key in a Multikey-compatible format. + * + * To export a key, the key must have [`CryptoKey.extractable`](https://developer.mozilla.org/en-US/docs/Web/API/CryptoKey/extractable) set to `true`. + * + * Check the library page for a list of supported algorithms. + */ export async function exportMultikey(key: CryptoKey): Promise { const codec = codecFromKey(key); const keyData = await codec.encode(key); @@ -55,6 +64,15 @@ export async function exportMultikey(key: CryptoKey): Promise { return "z" + multikeyb58; } +/** + * + * @param input A `string` containing the key in Multikey format. + * @returns A [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that fulfills with a [`CryptoKey`](https://developer.mozilla.org/en-US/docs/Web/API/CryptoKey). + * + * Imported keys have [`CryptoKey.extractable`](https://developer.mozilla.org/en-US/docs/Web/API/CryptoKey/extractable) set to `true`. + * + * Check the library page for a list of supported algorithms. + */ export async function importMultikey(input: string): Promise { if (input[0] !== "z") { throw new TypeError("Invalid multibase, expected base58btc string");