@fedify/fedify 1.5.0-dev.653 → 1.5.0-dev.654

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/CHANGES.md CHANGED
@@ -8,6 +8,16 @@ Version 1.5.0
8
8
 
9
9
  To be released.
10
10
 
11
+ - Fedify now accepts PEM-PKCS#1 besides PEM-SPKI for RSA public keys.
12
+ [[#209]]
13
+
14
+ - `CryptographicKey` now can contain a `publicKey` with a PEM-PKCS#1
15
+ format (in addition to PEM-SPKI).
16
+ - Added `importPkcs1()` function.
17
+ - Added `importPem()` function.
18
+
19
+ [#209]: https://github.com/fedify-dev/fedify/issues/209
20
+
11
21
 
12
22
  Version 1.4.1
13
23
  -------------
package/esm/deno.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export default {
2
2
  "name": "@fedify/fedify",
3
- "version": "1.5.0-dev.653+1d000223",
3
+ "version": "1.5.0-dev.654+b5166915",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": "./mod.ts",
@@ -1,5 +1,4 @@
1
1
  import * as dntShim from "../_dnt.shims.js";
2
- import { createPublicKey } from "node:crypto";
3
2
  import { concat } from "../deps/jsr.io/@std/bytes/1.0.5/concat.js";
4
3
  import { decodeBase64, encodeBase64 } from "../deps/jsr.io/@std/encoding/1.0.7/base64.js";
5
4
  import { decodeBase64Url } from "../deps/jsr.io/@std/encoding/1.0.7/base64url.js";
@@ -7,6 +6,7 @@ import { decodeHex } from "../deps/jsr.io/@std/encoding/1.0.7/hex.js";
7
6
  import { Integer, Sequence } from "asn1js";
8
7
  import { decode, encode } from "multibase";
9
8
  import { addPrefix, getCodeFromData, rmPrefix } from "multicodec";
9
+ import { createPublicKey } from "node:crypto";
10
10
  import { PublicKeyInfo } from "pkijs";
11
11
  import { validateCryptoKey } from "../sig/key.js";
12
12
  const algorithms = {
@@ -51,6 +51,29 @@ export async function exportSpki(key) {
51
51
  pem = (pem.match(/.{1,64}/g) || []).join("\n");
52
52
  return `-----BEGIN PUBLIC KEY-----\n${pem}\n-----END PUBLIC KEY-----\n`;
53
53
  }
54
+ /**
55
+ * Imports a PEM-PKCS#1 formatted public key.
56
+ * @param pem The PEM-PKCS#1 formatted public key.
57
+ * @returns The imported public key.
58
+ * @throws {TypeError} If the key is invalid or unsupported.
59
+ * @since 1.5.0
60
+ */
61
+ export function importPkcs1(pem) {
62
+ const key = createPublicKey({ key: pem, format: "pem", type: "pkcs1" });
63
+ const spki = key.export({ type: "spki", format: "pem" });
64
+ return importSpki(spki);
65
+ }
66
+ const PKCS1_HEADER = /^\s*-----BEGIN\s+RSA\s+PUBLIC\s+KEY-----\s*\n/;
67
+ /**
68
+ * Imports a PEM formatted public key (SPKI or PKCS#1).
69
+ * @param pem The PEM formatted public key to import (SPKI or PKCS#1).
70
+ * @returns The imported public key.
71
+ * @throws {TypeError} If the key is invalid or unsupported.
72
+ * @since 1.5.0
73
+ */
74
+ export function importPem(pem) {
75
+ return PKCS1_HEADER.test(pem) ? importPkcs1(pem) : importSpki(pem);
76
+ }
54
77
  /**
55
78
  * Imports a [Multibase]-encoded public key.
56
79
  *
@@ -126,3 +149,4 @@ export async function exportMultibaseKey(key) {
126
149
  const encoded = encode("base58btc", prefixed);
127
150
  return new TextDecoder().decode(encoded);
128
151
  }
152
+ // cSpell: ignore multicodec pkijs