Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
timonson committed Nov 5, 2023
1 parent a1b836c commit d968853
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 20 deletions.
2 changes: 1 addition & 1 deletion deps.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * as base64url from "https://deno.land/std@0.204.0/encoding/base64url.ts";
export * as base64url from "https://deno.land/std@0.205.0/encoding/base64url.ts";
14 changes: 9 additions & 5 deletions dist/mod.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,12 +396,16 @@ function createSigningInput(header, payload) {
return `${mod.encode(encoder1.encode(JSON.stringify(header)))}.${mod.encode(encoder1.encode(JSON.stringify(payload)))}`;
}
async function create1(header, payload, key) {
if (verify(header.alg, key)) {
const signingInput = createSigningInput(header, payload);
const signature = await create(header.alg, key, signingInput);
return `${signingInput}.${signature}`;
if (isObject(payload)) {
if (verify(header.alg, key)) {
const signingInput = createSigningInput(header, payload);
const signature = await create(header.alg, key, signingInput);
return `${signingInput}.${signature}`;
} else {
throw new Error(`The jwt's alg '${header.alg}' does not match the key's algorithm.`);
}
} else {
throw new Error(`The jwt's alg '${header.alg}' does not match the key's algorithm.`);
throw new Error(`The jwt claims set is not a JSON object.`);
}
}
function getNumericDate(exp) {
Expand Down
3 changes: 1 addition & 2 deletions examples/deps.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export { serve } from "https://deno.land/[email protected]/http/server.ts";
export * as base64 from "https://deno.land/[email protected]/encoding/base64.ts";
export * as base64 from "https://deno.land/[email protected]/encoding/base64.ts";
13 changes: 8 additions & 5 deletions examples/hs512.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { create, getNumericDate, verify } from "../mod.ts";
import { serve } from "./deps.ts";

import type { Header, Payload } from "../mod.ts";
import {
create,
getNumericDate,
type Header,
type Payload,
verify,
} from "../mod.ts";

const key = await crypto.subtle.generateKey(
{ name: "HMAC", hash: "SHA-512" },
Expand Down Expand Up @@ -31,4 +34,4 @@ async function handleRequest(request: Request) {
}
}

await serve(handleRequest);
Deno.serve(handleRequest);
7 changes: 2 additions & 5 deletions examples/rs384.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import { create, verify } from "../mod.ts";
import { serve } from "./deps.ts";

import type { Header, Payload } from "../mod.ts";
import { create, type Header, type Payload, verify } from "../mod.ts";

const { privateKey, publicKey } = await window.crypto.subtle.generateKey(
{
Expand Down Expand Up @@ -39,4 +36,4 @@ async function handleRequest(request: Request) {
}
}

await serve(handleRequest);
Deno.serve(handleRequest);
4 changes: 2 additions & 2 deletions tests/test_deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ export {
assertEquals,
assertRejects,
assertThrows,
} from "https://deno.land/std@0.204.0/testing/asserts.ts";
} from "https://deno.land/std@0.205.0/testing/asserts.ts";

export {
decode as decodeHex,
} from "https://deno.land/std@0.204.0/encoding/hex.ts";
} from "https://deno.land/std@0.205.0/encoding/hex.ts";

0 comments on commit d968853

Please sign in to comment.