Skip to content

Commit

Permalink
Use importKey/exportKey under the hood
Browse files Browse the repository at this point in the history
  • Loading branch information
dahlia committed Mar 12, 2024
1 parent ac63f73 commit a021cee
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions federation/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Temporal } from "npm:@js-temporal/polyfill@^0.4.4";
import { validateCryptoKey } from "../httpsig/key.ts";
import { exportJwk, importJwk, validateCryptoKey } from "../httpsig/key.ts";
import { handleNodeInfo, handleNodeInfoJrd } from "../nodeinfo/handler.ts";
import {
DocumentLoader,
Expand Down Expand Up @@ -164,13 +164,7 @@ export class Federation<TContextData> {
async #listenQueue(message: OutboxMessage): Promise<void> {
await sendActivity({
keyId: new URL(message.keyId),
privateKey: await crypto.subtle.importKey(
"jwk",
message.privateKey,
{ name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" },
true,
["sign"],
),
privateKey: await importJwk(message.privateKey, "private"),
activity: await Activity.fromJsonLd(message.activity, {
documentLoader: this.#documentLoader,
}),
Expand Down Expand Up @@ -652,7 +646,7 @@ export class Federation<TContextData> {
const message: OutboxMessage = {
type: "outbox",
keyId: keyId.href,
privateKey: await crypto.subtle.exportKey("jwk", privateKey),
privateKey: await exportJwk(privateKey),
activity: await activity.toJsonLd({ expand: true }),
inbox: inbox.href,
};
Expand Down

0 comments on commit a021cee

Please sign in to comment.