Skip to content

Commit

Permalink
refactor(remix-deno): implement crypto-dependent interface functions
Browse files Browse the repository at this point in the history
  • Loading branch information
pcattori committed Mar 19, 2022
1 parent e83ae52 commit be83e02
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { SignFunction, UnsignFunction } from "./deps/@remix-run/server-runtime.ts"

const encoder = new TextEncoder();

export async function sign(value: string, secret: string): Promise<string> {
export const sign: SignFunction = async (value, secret) => {
const key = await crypto.subtle.importKey(
"raw",
encoder.encode(secret),
Expand All @@ -19,10 +21,7 @@ export async function sign(value: string, secret: string): Promise<string> {
return value + "." + hash;
}

export async function unsign(
cookie: string,
secret: string
): Promise<string | false> {
export const unsign: UnsignFunction = async (cookie, secret) => {
const key = await crypto.subtle.importKey(
"raw",
encoder.encode(secret),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ export type {
ServerBuild,
SessionIdStorageStrategy,
SessionStorage,
Sign,
Unsign,
} from "https://esm.sh/@remix-run/server-runtime?pin=v68";
export {
createCookieFactory,
createCookieSessionStorageFactory,
createMemorySessionStorageFactory,
createSessionStorageFactory,
createRequestHandler,
createSessionStorage,
} from "https://esm.sh/@remix-run/server-runtime?pin=v68";
20 changes: 0 additions & 20 deletions templates/deno-ts/remix-deno/globals.ts

This file was deleted.

13 changes: 13 additions & 0 deletions templates/deno-ts/remix-deno/implementations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {
createCookieFactory,
createCookieSessionStorageFactory,
createMemorySessionStorageFactory,
createSessionStorageFactory,
} from "./deps/@remix-run/server-runtime.ts";

import { sign, unsign } from "./crypto.ts";

export const createCookie = createCookieFactory({ sign, unsign });
export const createCookieSessionStorage = createCookieSessionStorageFactory(createCookie);
export const createSessionStorage = createSessionStorageFactory(createCookie);
export const createMemorySessionStorage = createMemorySessionStorageFactory(createSessionStorage);
6 changes: 4 additions & 2 deletions templates/deno-ts/remix-deno/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
export { installGlobals } from './globals.ts'
export { createFileSessionStorage } from './sessions/fileStorage.ts'
export { createRequestHandler, createRequestHandlerWithStaticFiles, serveStaticFiles } from './server.ts'

export {
createCookie,
createCookieSessionStorage,
createMemorySessionStorage,
createSession,
createSessionStorage,
} from './implementations.ts';

export {
createSession,
isCookie,
isSession,
json,
Expand Down
2 changes: 1 addition & 1 deletion templates/deno-ts/remix-deno/sessions/fileStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {
SessionStorage,
SessionIdStorageStrategy,
} from "../deps/@remix-run/server-runtime.ts";
import { createSessionStorage } from "../deps/@remix-run/server-runtime.ts";
import { createSessionStorage } from "../implementations.ts";

interface FileSessionStorageOptions {
/**
Expand Down

0 comments on commit be83e02

Please sign in to comment.