-
-
Notifications
You must be signed in to change notification settings - Fork 5
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
Showing
9 changed files
with
124 additions
and
52 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
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,39 @@ | ||
import { exists, readFile, writeFile } from "@cross/fs" | ||
import { encodeBase64 } from "@std/encoding/base64" | ||
|
||
export class Secret { | ||
path: string // Type annotation for clarity | ||
cache: string | undefined // Cached secret | ||
|
||
constructor(secretFilePath: string) { // Type annotation for the parameter | ||
this.path = secretFilePath | ||
} | ||
|
||
async generateSecret(): Promise<string> { | ||
const secretArray = new Uint8Array(32) | ||
crypto.getRandomValues(secretArray) | ||
const secret = encodeBase64(secretArray) | ||
await writeFile(this.path, secret) | ||
return secret | ||
} | ||
|
||
async loadSecret(): Promise<string> { // Specify return type | ||
return await readFile(this.path, "utf-8") | ||
} | ||
|
||
async get(): Promise<string> { // Specify return type | ||
try { | ||
if (!this.cache) { | ||
if (await exists(this.path)) { | ||
this.cache = await this.loadSecret() | ||
} else { | ||
this.cache = await this.generateSecret() | ||
} | ||
} | ||
return this.cache | ||
} catch (err) { | ||
console.error("Error handling secret:", err) | ||
throw err | ||
} | ||
} | ||
} |
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,15 +1,10 @@ | ||
import { createJWT, generateKey } from "@cross/jwt" | ||
|
||
// Dummy secret | ||
const jwtSecret = "GawoWOOWOOFSAFFASOFOFOASOAOFASFwoopieeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" | ||
|
||
const key = await generateKey(jwtSecret, "HS512") | ||
|
||
const payload = { | ||
user: { | ||
name: "Test", | ||
}, | ||
exp: Date.now() + 60 * 60 * 1000, | ||
} | ||
|
||
console.log(await createJWT(payload, key)) |
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 |
---|---|---|
|
@@ -2,6 +2,20 @@ | |
"canary_url": "https://raw.githubusercontent.com/Hexagon/pup/main/pup.ts", | ||
"stable": [], | ||
"prerelease": [ | ||
{ | ||
"version": "1.0.0-rc.26", | ||
"url": "jsr:@pup/[email protected]", | ||
"deno": null, | ||
"deno_unstable": "1.42.0", | ||
"default_permissions": [ | ||
"--allow-env", | ||
"--allow-read", | ||
"--allow-write", | ||
"--allow-sys=loadavg,systemMemoryInfo,osUptime,osRelease,uid,gid", | ||
"--allow-net", | ||
"--allow-run" | ||
] | ||
}, | ||
{ | ||
"version": "1.0.0-rc.25", | ||
"url": "jsr:@pup/[email protected]", | ||
|