Sign and verify
Gives access to the respective functions in the CTX.
It needs
cryptoin thepetition.
Specifications
- HS256
Sign
Example of signing param.
import { wrap } from "vixeny";
const handler = await wrap()()
.get({
path: "/sign/:user",
crypto: {
globalKey: "secret!",
},
f: ({ sign, param }) => sign(param),
})
// Creating a server element
.testPetitions();
// Checking token
await handler(new Request("http://localhost/sign/pluie"))
.then((x) => x.text())
.then(console.log); Verify
Example of signing param and verifying the validity of it.
import { wrap } from "vixeny";
// Generic
const cryptoOptions = {
crypto: {
globalKey: "secret!",
},
};
const handler = await wrap()()
.get({
path: "/sign/:user",
// Manually adding crypto options,
crypto: {
globalKey: "secret!",
},
f: ({ sign, param }) => sign(param),
})
.post({
path: "/isItValid",
// Append options
...cryptoOptions,
f: async ({ verify, req }) => {
// Verifies the body
const token = verify(await req.text());
// Check validity of the token
if (token) {
// If the token is not null returns status 200
return new Response(null, { status: 200 });
} else {
// If the token is null returns status 403
return new Response(null, { status: 403 });
}
},
})
.testPetitions();
// Getting the token of { user : "pluie" }
const token = await handler(new Request("http://localhost/sign/pluie"))
.then((x) => x.text());
// Checking validity
await handler(
new Request("http://localhost/isItValid", {
method: "POST",
body: token,
}),
)
.then(console.log); List
- Branch : Gets access to the functions in branch.
- Cookie : Manages HTTP cookies.
- Query : Facilitates easy access to URL query parameters.
- Param : Extracts URL path parameters.
- Headers : Provides access to HTTP request headers.
- Resolve : Gets the values of the resolved functions.
- IO : Handles file operations.
- Sign & Verify : Gives access to a sign and verify function.
- Token : Verifies the cookies with the current key.
