-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d90c21f
commit 7bbddcc
Showing
19 changed files
with
201 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 7 additions & 3 deletions
10
src/components/jwt/signSha256.mjs → src/components/jwt/signSha256.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,22 @@ | ||
import signer from "./src/sign/sha256.mjs"; | ||
import signer from "./src/sign/sha256.ts"; | ||
import nodeCrypto from "node:crypto"; | ||
import BufferProto from "node:buffer"; | ||
import name from "../runtime/name.mjs"; | ||
import args from "../runtime/name.ts"; | ||
|
||
type HashFunction = (data: Uint8Array) => nodeCrypto.Hash; | ||
|
||
export default () => | ||
( | ||
(rt) => | ||
signer( | ||
//@ts-ignore | ||
rt === "Bun" ? Buffer : BufferProto.Buffer, | ||
)( | ||
rt === "Bun" | ||
//@ts-ignore | ||
? (d) => new Bun.CryptoHasher("sha256").update(d) | ||
: (d) => nodeCrypto.createHash("sha256").update(d), | ||
) | ||
)( | ||
name(), | ||
args(), | ||
)(); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import type BufferProto from "node:buffer"; | ||
import type nodeCrypto from "node:crypto"; | ||
|
||
type HashFunction = (data: Uint8Array) => nodeCrypto.Hash; | ||
|
||
export default (Buffer: typeof BufferProto.Buffer) => | ||
(sha256: HashFunction) => | ||
( | ||
header = Buffer.from(JSON.stringify({ | ||
alg: "HS256", | ||
typ: "JWT", | ||
})).toString("base64url") + ".", | ||
) => | ||
(key: Uint8Array) => | ||
( | ||
(hmac) => | ||
((lf) => (rg: Uint8Array) => (message: Object) => | ||
( | ||
(json) => | ||
header + json + "." + | ||
sha256( | ||
Buffer.concat([ | ||
lf, | ||
sha256( | ||
Buffer.concat([ | ||
rg, | ||
Buffer.from(header + json), | ||
]), | ||
).digest(), | ||
]), | ||
) | ||
.digest().toString("base64url") | ||
)( | ||
Buffer.from(JSON.stringify(message)).toString("base64url"), | ||
))(new Uint8Array(64).map((_x, i) => hmac[i] ^ 0x5c))( | ||
new Uint8Array(64).map((_x, i) => hmac[i] ^ 0x36), | ||
) | ||
)( | ||
key.length > 64 | ||
? sha256(key).digest() | ||
: key.length < 64 | ||
? Buffer.concat([key, Buffer.alloc(64 - key.length)]) | ||
: key, | ||
); |
11 changes: 9 additions & 2 deletions
11
src/components/jwt/src/verify/sha256.mjs → src/components/jwt/src/verify/sha256.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 9 additions & 7 deletions
16
src/components/jwt/verifySha256.mjs → src/components/jwt/verifySha256.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,23 @@ | ||
import verify from "./src/verify/sha256.mjs"; | ||
import verify from "./src/verify/sha256.ts"; | ||
import args from "../runtime/name.ts"; | ||
import nodeCrypto from "node:crypto"; | ||
import BufferProto from "node:buffer"; | ||
|
||
args(); | ||
|
||
export default () => | ||
( | ||
(rt) => | ||
verify( | ||
//@ts-ignore | ||
rt === "Bun" ? Buffer : BufferProto.Buffer, | ||
)( | ||
rt === "Bun" | ||
//@ts-ignore | ||
? (d) => new Bun.CryptoHasher("sha256").update(d) | ||
: (d) => nodeCrypto.createHash("sha256").update(d), | ||
: (d: nodeCrypto.BinaryLike) => | ||
nodeCrypto.createHash("sha256").update(d), | ||
) | ||
)( | ||
typeof Bun !== "undefined" | ||
? "Bun" | ||
: typeof Bun !== "undefined" | ||
? "Deno" | ||
: "Node", | ||
args(), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.