From bba6c87ced82b27e4d670c7cf878c38ca3a9ded7 Mon Sep 17 00:00:00 2001 From: Cotton Hou Date: Thu, 21 Nov 2024 12:08:44 +0800 Subject: [PATCH] apply wasm encoder --- app.tsx | 12 ++++++++---- deploy/deno.ts | 16 ++++++++-------- specs/smoking.test.ts | 21 ++++++++++++--------- 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/app.tsx b/app.tsx index 0329959..145e4c5 100644 --- a/app.tsx +++ b/app.tsx @@ -8,6 +8,7 @@ import { bodyLimit } from 'hono/body-limit'; import { validator } from 'hono/validator'; import { HTTPException } from 'hono/http-exception'; +import type { Encoder } from './encoder/index.ts'; import type { AdapterGen } from './adapter/index.ts'; import { layout, Create, SigningPane, Go } from './components/index.tsx'; @@ -15,7 +16,7 @@ import { Show, scriptSrc } from './components/show.tsx'; import { collection } from './assets.ts'; -import { noop, csp, cached, register, gen_fnv1a_hash, +import { noop, csp, cached, register, parser, v_create, v_id_slugify, v_optional_signing_back, read_var, UUIDv4, UUIDv5_URL, compose_signing_url, calc_fingerprint, nmap, nothing, slugify, exception, challenge_, duration, @@ -25,10 +26,14 @@ import { noop, csp, cached, register, gen_fnv1a_hash, -export async function create_app (storage: AdapterGen, { +export async function create_app ( + + hash: Encoder, + storage: AdapterGen, + +{ auth = noop, - encoding = gen_fnv1a_hash(), cache_name = 'assets-v1', ttl_in_ms = nothing(), signing_nav = false, @@ -38,7 +43,6 @@ export async function create_app (storage: AdapterGen, { } = {}) { const db = await storage(); - const hash = await encoding(); const extend = register(collection); diff --git a/deploy/deno.ts b/deploy/deno.ts index fe9fdc4..9143407 100644 --- a/deploy/deno.ts +++ b/deploy/deno.ts @@ -2,7 +2,7 @@ import type { MiddlewareHandler } from 'hono/types'; import { create_app } from '../app.tsx'; import { gen_deno_kv } from '../adapter/deno-kv.ts'; -import { gen_fnv1a_hash } from '../utils.ts'; +import { gen_fnv1a_hash } from '../encoder/jsr-std-wasm.ts'; @@ -26,19 +26,19 @@ export function make ({ } = {}): Promise { - return create_app(gen_deno_kv(kv_path), { + const hash = gen_fnv1a_hash({ + key: hash_seed, + large: hash_enlarge, + }); + + const storage = gen_deno_kv(kv_path); + return create_app(hash, storage, { auth, cache_name, ttl_in_ms, signing_nav, signing_site, - - encoding: gen_fnv1a_hash({ - key: hash_seed, - large: hash_enlarge, - }), - }); } diff --git a/specs/smoking.test.ts b/specs/smoking.test.ts index a8ef70c..44e324e 100644 --- a/specs/smoking.test.ts +++ b/specs/smoking.test.ts @@ -8,18 +8,20 @@ import { Hono } from 'hono'; import { testClient } from 'hono/testing'; import { create_app } from '../app.tsx'; +import { gen_fnv1a_hash } from '../encoder/jsr-std-wasm.ts'; import { gen_deno_kv } from '../adapter/deno-kv.ts'; import { make_ttl_cache } from '../adapter/ttl-cache.ts'; import { make_map_object } from '../adapter/map-object.ts'; -import { calc_fingerprint, gen_fnv1a_hash, +import { calc_fingerprint, HMAC_SHA256, signingAuth, UUIDv4, webcrypto, challenge_, duration, } from '../utils.ts'; +const hashing = gen_fnv1a_hash(); -const app = await create_app(gen_deno_kv(':memory:'), { +const app = await create_app(hashing, gen_deno_kv(':memory:'), { insecure: true, signing_nav: true, }); @@ -137,8 +139,9 @@ Deno.test('throw on same code twice', async function () { Deno.test('advanced config', async function () { - const other = await create_app(make_map_object, { - encoding: gen_fnv1a_hash({ large: true, key: 'ayb' }), + const hashing_local = gen_fnv1a_hash({ large: true, key: 'ayb' }); + + const other = await create_app(hashing_local, make_map_object, { insecure: true, }); @@ -194,7 +197,7 @@ Deno.test('advanced config', async function () { Deno.test('default app', async function () { - await create_app(make_map_object); + await create_app(hashing, make_map_object); }); @@ -305,7 +308,7 @@ Deno.test('signingAuth', async function () { { // ok on show page - const client = testClient(await create_app(make_map_object, { + const client = testClient(await create_app(hashing, make_map_object, { auth: signingAuth([ fingerprint ]), insecure: true, })); @@ -324,7 +327,7 @@ Deno.test('signingAuth', async function () { const fingerprint_lookup = spy(() => true); - const client = testClient(await create_app(make_map_object, { + const client = testClient(await create_app(hashing, make_map_object, { auth: signingAuth(fingerprint_lookup), insecure: true, })); @@ -443,7 +446,7 @@ Deno.test('cache with TTL', async function () { const url = 'https://example.com'; const code = 'foobar'; - const app = await create_app(make_ttl_cache, { + const app = await create_app(hashing, make_ttl_cache, { ttl_in_ms, insecure: true, }); @@ -502,7 +505,7 @@ Deno.test('take TTL from ctx.var', async function () { using time = new FakeTime(); - const app_local = await create_app(make_ttl_cache, { + const app_local = await create_app(hashing, make_ttl_cache, { insecure: true, ttl_in_ms: 500, async auth (ctx, next) {