Skip to content

Commit

Permalink
feat: add support for passing in your own storage to session key sign…
Browse files Browse the repository at this point in the history
  • Loading branch information
moldy530 authored May 29, 2024
1 parent e275f5f commit 67474c0
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/accounts/src/msca/plugins/session-key/signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { z } from "zod";
export const SessionKeySignerSchema = z.object({
storageType: z
.union([z.literal("local-storage"), z.literal("session-storage")])
.or(z.custom<Storage>())
.default("local-storage"),
storageKey: z.string().default("session-key-signer:session-key"),
});
Expand All @@ -30,7 +31,7 @@ export class SessionKeySigner
{
signerType: string;
inner: LocalAccountSigner<PrivateKeyAccount>;
private storageType: "local-storage" | "session-storage";
private storageType: "local-storage" | "session-storage" | Storage;
private storageKey: string;

constructor(config_: SessionKeySignerConfig = {}) {
Expand All @@ -41,7 +42,9 @@ export class SessionKeySigner

const sessionKey = (() => {
const storage =
config.storageType === "session-storage"
typeof this.storageType !== "string"
? this.storageType
: this.storageType === "session-storage"
? sessionStorage
: localStorage;
const key = storage.getItem(this.storageKey);
Expand Down

0 comments on commit 67474c0

Please sign in to comment.