mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-25 07:04:39 +03:00
feat(new tool): Paseto/PASERK Encrypt/Decrypt/Sign/Verify and Generator
Fix #1567
This commit is contained in:
1 parent
e99d7b4755
commit
2037d14cd6
7 files changed
+575
No files matched your search
@@ -219,6 +219,7 @@
|
|||||||
"oui-data": "^1.1.281",
|
"oui-data": "^1.1.281",
|
||||||
"parse-duration": "^2.1.2",
|
"parse-duration": "^2.1.2",
|
||||||
"parse-torrent": "^11.0.18",
|
"parse-torrent": "^11.0.18",
|
||||||
|
"paseto-ts": "^2.0.5",
|
||||||
"path2d-polyfill": "^3.1.3",
|
"path2d-polyfill": "^3.1.3",
|
||||||
"pdf-signature-reader": "^1.4.3",
|
"pdf-signature-reader": "^1.4.3",
|
||||||
"pdfjs-dist": "^4.8.69",
|
"pdfjs-dist": "^4.8.69",
|
||||||
|
|||||||
Generated
+75
@@ -554,6 +554,9 @@ dependencies:
|
|||||||
parse-torrent:
|
parse-torrent:
|
||||||
specifier: ^11.0.18
|
specifier: ^11.0.18
|
||||||
version: 11.0.18
|
version: 11.0.18
|
||||||
|
paseto-ts:
|
||||||
|
specifier: ^2.0.5
|
||||||
|
version: 2.0.5
|
||||||
path2d-polyfill:
|
path2d-polyfill:
|
||||||
specifier: ^3.1.3
|
specifier: ^3.1.3
|
||||||
version: 3.1.3
|
version: 3.1.3
|
||||||
@@ -5595,6 +5598,70 @@ packages:
|
|||||||
resolution: {integrity: sha512-XExJS3cLqgrmNBIP3bBw6+1oQ1ksGjFh0+oClDKFYpCCqx/hlqwWO5KO/S63fzUo67SxI9dMrF0y5T/Ey7h8Zw==}
|
resolution: {integrity: sha512-XExJS3cLqgrmNBIP3bBw6+1oQ1ksGjFh0+oClDKFYpCCqx/hlqwWO5KO/S63fzUo67SxI9dMrF0y5T/Ey7h8Zw==}
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
|
/@stablelib/binary@2.0.1:
|
||||||
|
resolution: {integrity: sha512-U9iAO8lXgEDONsA0zPPSgcf3HUBNAqHiJmSHgZz62OvC3Hi2Bhc5kTnQ3S1/L+sthDTHtCMhcEiklmIly6uQ3w==}
|
||||||
|
dependencies:
|
||||||
|
'@stablelib/int': 2.0.1
|
||||||
|
dev: false
|
||||||
|
|
||||||
|
/@stablelib/blake2b@2.0.1:
|
||||||
|
resolution: {integrity: sha512-kBN4i9FHpkTEVrHwKtb1ZjI6QwyoK8emY9TaLcHHFSZkw2FN9Td8Js9mU2U10q+EZ3Mp6z78QgdPDwJXbc3Dtw==}
|
||||||
|
dependencies:
|
||||||
|
'@stablelib/binary': 2.0.1
|
||||||
|
'@stablelib/hash': 2.0.0
|
||||||
|
'@stablelib/wipe': 2.0.1
|
||||||
|
dev: false
|
||||||
|
|
||||||
|
/@stablelib/chacha@2.0.1:
|
||||||
|
resolution: {integrity: sha512-lS1FqtNqofxe2vLkRsLli2m3x/XanUyAYRphLhdHumKeIsLbjbCXdCq3Pf/eWiO7G3QlSG5ViqnoVjktzfLWMg==}
|
||||||
|
dependencies:
|
||||||
|
'@stablelib/binary': 2.0.1
|
||||||
|
'@stablelib/wipe': 2.0.1
|
||||||
|
dev: false
|
||||||
|
|
||||||
|
/@stablelib/ed25519@2.0.2:
|
||||||
|
resolution: {integrity: sha512-d/lJ5sgzhtmpMIbKFWfev+i6WebBdIzzBpMzXtZdvUijoksjXosYFNqytoMj7cRshNj+/XTLYnnVMdZfd+penw==}
|
||||||
|
dependencies:
|
||||||
|
'@stablelib/random': 2.0.1
|
||||||
|
'@stablelib/sha512': 2.0.1
|
||||||
|
'@stablelib/wipe': 2.0.1
|
||||||
|
dev: false
|
||||||
|
|
||||||
|
/@stablelib/hash@2.0.0:
|
||||||
|
resolution: {integrity: sha512-u3WPSqGido8lwJuMcrBgM5K54LrPGhkWAdtsyccf7dGsLixAZUds77zOAbu7bvKPwQlmoByH0txBi5rTmEKuHg==}
|
||||||
|
dev: false
|
||||||
|
|
||||||
|
/@stablelib/int@2.0.1:
|
||||||
|
resolution: {integrity: sha512-Ht63fQp3wz/F8U4AlXEPb7hfJOIILs8Lq55jgtD7KueWtyjhVuzcsGLSTAWtZs3XJDZYdF1WcSKn+kBtbzupww==}
|
||||||
|
dev: false
|
||||||
|
|
||||||
|
/@stablelib/random@2.0.1:
|
||||||
|
resolution: {integrity: sha512-W6GAtXEEs7r+dSbuBsvoFmlyL3gLxle41tQkjKu17dDWtDdjhVUbtRfRCQcCUeczwkgjQxMPopgwYEvxXtHXGw==}
|
||||||
|
dependencies:
|
||||||
|
'@stablelib/binary': 2.0.1
|
||||||
|
'@stablelib/wipe': 2.0.1
|
||||||
|
dev: false
|
||||||
|
|
||||||
|
/@stablelib/sha512@2.0.1:
|
||||||
|
resolution: {integrity: sha512-DUNe5cbnoH3sSIN+MG04RvTCLXtkbyy/SnQxiNO+GgF/KSXkkUSlF6mUVvCUdZBZ2X3NgogR+tAvaRSn8wxnLw==}
|
||||||
|
dependencies:
|
||||||
|
'@stablelib/binary': 2.0.1
|
||||||
|
'@stablelib/hash': 2.0.0
|
||||||
|
'@stablelib/wipe': 2.0.1
|
||||||
|
dev: false
|
||||||
|
|
||||||
|
/@stablelib/wipe@2.0.1:
|
||||||
|
resolution: {integrity: sha512-1eU2K9EgOcV4qc9jcP6G72xxZxEm5PfeI5H55l08W95b4oRJaqhmlWRc4xZAm6IVSKhVNxMi66V67hCzzuMTAg==}
|
||||||
|
dev: false
|
||||||
|
|
||||||
|
/@stablelib/xchacha20@2.0.1:
|
||||||
|
resolution: {integrity: sha512-k55pNv7gIM4mUPU00+nJYTxKiUVNwAtsgrridC0aIU5cVbw9u6qP99x8ENu5eiwOEhZUNg+p3tTOLooCeAOJQA==}
|
||||||
|
dependencies:
|
||||||
|
'@stablelib/binary': 2.0.1
|
||||||
|
'@stablelib/chacha': 2.0.1
|
||||||
|
'@stablelib/wipe': 2.0.1
|
||||||
|
dev: false
|
||||||
|
|
||||||
/@surma/rollup-plugin-off-main-thread@2.2.3:
|
/@surma/rollup-plugin-off-main-thread@2.2.3:
|
||||||
resolution: {integrity: sha512-lR8q/9W7hZpMWweNiAKU7NQerBnzQQLvi8qnTDU/fxItPhtZVMbPV3lbCwjhIlNBe9Bbr5V+KHshvWmVSG9cxQ==}
|
resolution: {integrity: sha512-lR8q/9W7hZpMWweNiAKU7NQerBnzQQLvi8qnTDU/fxItPhtZVMbPV3lbCwjhIlNBe9Bbr5V+KHshvWmVSG9cxQ==}
|
||||||
dependencies:
|
dependencies:
|
||||||
@@ -14526,6 +14593,14 @@ packages:
|
|||||||
upper-case-first: 1.1.2
|
upper-case-first: 1.1.2
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/paseto-ts@2.0.5:
|
||||||
|
resolution: {integrity: sha512-NKnpbYfu6YGQ5jTv9tRsBZeHUQ97Tu12sH4/NZIJXBE+by9VaKQWF2tuReYb1UPCuznWSaXcyAr9k0gMCfYKIw==}
|
||||||
|
dependencies:
|
||||||
|
'@stablelib/blake2b': 2.0.1
|
||||||
|
'@stablelib/ed25519': 2.0.2
|
||||||
|
'@stablelib/xchacha20': 2.0.1
|
||||||
|
dev: false
|
||||||
|
|
||||||
/path-browserify@1.0.1:
|
/path-browserify@1.0.1:
|
||||||
resolution: {integrity: sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g==}
|
resolution: {integrity: sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g==}
|
||||||
dev: true
|
dev: true
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import { Key } from '@vicons/tabler';
|
||||||
|
import { defineTool } from '../tool';
|
||||||
|
|
||||||
|
export const tool = defineTool({
|
||||||
|
name: 'Paseto/PASERK Encryption',
|
||||||
|
path: '/paseto-encryption',
|
||||||
|
description: 'Generate keys and encrypt/decrypt payloads',
|
||||||
|
keywords: ['paseto', 'encryption', 'paserk', 'payload'],
|
||||||
|
component: () => import('./paseto-encryption.vue'),
|
||||||
|
icon: Key,
|
||||||
|
createdAt: new Date('2025-04-21'),
|
||||||
|
category: 'Crypto',
|
||||||
|
});
|
||||||
@@ -0,0 +1,182 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import JSON5 from 'json5';
|
||||||
|
import { decrypt, encrypt, generateKeys } from 'paseto-ts/v4';
|
||||||
|
import { useValidation } from '@/composable/validation';
|
||||||
|
|
||||||
|
const payload = ref(`{
|
||||||
|
"sub": "1234567890",
|
||||||
|
"name": "John Doe",
|
||||||
|
"iat": "${(new Date()).toISOString()}"
|
||||||
|
}`);
|
||||||
|
const footer = ref('{}');
|
||||||
|
|
||||||
|
const localKey = ref('');
|
||||||
|
const addExp = ref(true);
|
||||||
|
const addIat = ref(true);
|
||||||
|
const validatePayload = ref(true);
|
||||||
|
|
||||||
|
function generateLocalKey() {
|
||||||
|
localKey.value = generateKeys('local');
|
||||||
|
}
|
||||||
|
generateLocalKey();
|
||||||
|
|
||||||
|
const encryptedToken = computedAsync(async () => {
|
||||||
|
const localKeyValue = localKey.value;
|
||||||
|
const payloadValue = payload.value;
|
||||||
|
const addExpValue = addExp.value;
|
||||||
|
const addIatValue = addIat.value;
|
||||||
|
const footerValue = footer.value;
|
||||||
|
const validatePayloadValue = validatePayload.value;
|
||||||
|
try {
|
||||||
|
const token = await encrypt(
|
||||||
|
localKeyValue,
|
||||||
|
payloadValue,
|
||||||
|
{
|
||||||
|
addExp: addExpValue,
|
||||||
|
addIat: addIatValue,
|
||||||
|
footer: footerValue,
|
||||||
|
validatePayload: validatePayloadValue,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return {
|
||||||
|
token,
|
||||||
|
error: '',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
catch (e: any) {
|
||||||
|
return { error: e.toString(), token: '' };
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const jsonInputValidation = useValidation({
|
||||||
|
source: payload,
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
message: 'Invalid JSON string',
|
||||||
|
validator: value => JSON5.parse(value),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
const jsonFooterValidation = useValidation({
|
||||||
|
source: footer,
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
message: 'Invalid JSON string',
|
||||||
|
validator: value => JSON5.parse(value),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
const token = ref('');
|
||||||
|
const decryptedToken = computedAsync(async () => {
|
||||||
|
const localKeyValue = localKey.value;
|
||||||
|
const tokenValue = token.value;
|
||||||
|
const validatePayloadValue = validatePayload.value;
|
||||||
|
try {
|
||||||
|
// generic type parameter is optional but will give you type safety on the payload
|
||||||
|
const { payload, footer } = await decrypt<any>(
|
||||||
|
localKeyValue,
|
||||||
|
tokenValue,
|
||||||
|
{
|
||||||
|
validatePayload: validatePayloadValue,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return {
|
||||||
|
payload,
|
||||||
|
footer,
|
||||||
|
error: '',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
catch (e: any) {
|
||||||
|
return { error: e.toString(), payload: '', footer: '' };
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<c-card title="Local Key" mb-2>
|
||||||
|
<c-input-text
|
||||||
|
v-model:value="localKey"
|
||||||
|
label="Local Key:"
|
||||||
|
label-position="left"
|
||||||
|
placeholder="PASERK local key k4.local.xxxx"
|
||||||
|
mb-2
|
||||||
|
/>
|
||||||
|
<div flex justify-center>
|
||||||
|
<n-button @click="generateLocalKey()">
|
||||||
|
Refresh Key
|
||||||
|
</n-button>
|
||||||
|
</div>
|
||||||
|
</c-card>
|
||||||
|
|
||||||
|
<c-card title="Encryption" mb-2>
|
||||||
|
<c-input-text
|
||||||
|
v-model:value="payload"
|
||||||
|
label="Payload:"
|
||||||
|
multiline
|
||||||
|
rows="5"
|
||||||
|
autosize
|
||||||
|
placeholder="JSON payload"
|
||||||
|
:validation="jsonInputValidation"
|
||||||
|
/>
|
||||||
|
<n-space justify="center">
|
||||||
|
<n-form-item label="Validate Payload" label-placement="left">
|
||||||
|
<n-switch v-model:value="validatePayload" />
|
||||||
|
</n-form-item>
|
||||||
|
<n-form-item label="Add Exp" label-placement="left">
|
||||||
|
<n-switch v-model:value="addExp" />
|
||||||
|
</n-form-item>
|
||||||
|
<n-form-item label="Add IAT" label-placement="left">
|
||||||
|
<n-switch v-model:value="addIat" />
|
||||||
|
</n-form-item>
|
||||||
|
</n-space>
|
||||||
|
|
||||||
|
<c-input-text
|
||||||
|
v-model:value="footer"
|
||||||
|
label="Footer:"
|
||||||
|
multiline
|
||||||
|
rows="2"
|
||||||
|
autosize
|
||||||
|
placeholder="JSON footer"
|
||||||
|
:validation="jsonFooterValidation"
|
||||||
|
mb-2
|
||||||
|
/>
|
||||||
|
|
||||||
|
<c-card v-if="encryptedToken" title="Generated PASERK Token:" mb-2>
|
||||||
|
<textarea-copyable v-if="encryptedToken.token" :value="encryptedToken.token" word-wrap />
|
||||||
|
<c-alert v-if="encryptedToken.error">
|
||||||
|
{{ encryptedToken.error }}
|
||||||
|
</c-alert>
|
||||||
|
</c-card>
|
||||||
|
</c-card>
|
||||||
|
|
||||||
|
<c-card title="Decryption" mb-2>
|
||||||
|
<c-input-text
|
||||||
|
v-model:value="token"
|
||||||
|
label="Token:"
|
||||||
|
multiline
|
||||||
|
rows="5"
|
||||||
|
autosize
|
||||||
|
placeholder="PASERK token"
|
||||||
|
/>
|
||||||
|
<n-space justify="center">
|
||||||
|
<n-form-item label="Validate Payload" label-placement="left">
|
||||||
|
<n-checkbox v-model:value="validatePayload" />
|
||||||
|
</n-form-item>
|
||||||
|
</n-space>
|
||||||
|
|
||||||
|
<c-card v-if="decryptedToken" title="Decoded PASERK:" mb-2>
|
||||||
|
<n-form-item v-if="decryptedToken.payload" label="Payload:">
|
||||||
|
<textarea-copyable :value="JSON.stringify(decryptedToken.payload, null, 2)" word-wrap />
|
||||||
|
</n-form-item>
|
||||||
|
<n-form-item v-if="decryptedToken.footer" label="Footer:">
|
||||||
|
<textarea-copyable :value="JSON.stringify(decryptedToken.footer, null, 2)" word-wrap />
|
||||||
|
</n-form-item>
|
||||||
|
<c-alert v-if="decryptedToken.error">
|
||||||
|
{{ decryptedToken.error }}
|
||||||
|
</c-alert>
|
||||||
|
</c-card>
|
||||||
|
</c-card>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import { Key } from '@vicons/tabler';
|
||||||
|
import { defineTool } from '../tool';
|
||||||
|
|
||||||
|
export const tool = defineTool({
|
||||||
|
name: 'Paseto Signing/Verifier',
|
||||||
|
path: '/paseto-signing',
|
||||||
|
description: 'Generate keys and sign/verify payload',
|
||||||
|
keywords: ['paseto', 'signing', 'verify', 'paserk', 'payload'],
|
||||||
|
component: () => import('./paseto-signing.vue'),
|
||||||
|
icon: Key,
|
||||||
|
createdAt: new Date('2025-04-21'),
|
||||||
|
category: 'Crypto',
|
||||||
|
});
|
||||||
@@ -0,0 +1,191 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import JSON5 from 'json5';
|
||||||
|
import { generateKeys, sign, verify } from 'paseto-ts/v4';
|
||||||
|
import { useValidation } from '@/composable/validation';
|
||||||
|
|
||||||
|
const payload = ref(`{
|
||||||
|
"sub": "1234567890",
|
||||||
|
"name": "John Doe",
|
||||||
|
"iat": "${(new Date()).toISOString()}"
|
||||||
|
}`);
|
||||||
|
const footer = ref('{}');
|
||||||
|
|
||||||
|
const secretKey = ref('');
|
||||||
|
const publicKey = ref('');
|
||||||
|
const addExp = ref(true);
|
||||||
|
const addIat = ref(true);
|
||||||
|
const validatePayload = ref(true);
|
||||||
|
|
||||||
|
function generateKeyPairs() {
|
||||||
|
const keys = generateKeys('public');
|
||||||
|
secretKey.value = keys.secretKey;
|
||||||
|
publicKey.value = keys.publicKey;
|
||||||
|
}
|
||||||
|
generateKeyPairs();
|
||||||
|
|
||||||
|
const signedToken = computedAsync(async () => {
|
||||||
|
const secretKeyValue = secretKey.value;
|
||||||
|
const payloadValue = payload.value;
|
||||||
|
const addExpValue = addExp.value;
|
||||||
|
const addIatValue = addIat.value;
|
||||||
|
const footerValue = footer.value;
|
||||||
|
const validatePayloadValue = validatePayload.value;
|
||||||
|
try {
|
||||||
|
const token = await sign(
|
||||||
|
secretKeyValue,
|
||||||
|
payloadValue,
|
||||||
|
{
|
||||||
|
addExp: addExpValue,
|
||||||
|
addIat: addIatValue,
|
||||||
|
footer: footerValue,
|
||||||
|
validatePayload: validatePayloadValue,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return {
|
||||||
|
token,
|
||||||
|
error: '',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
catch (e: any) {
|
||||||
|
return { error: e.toString(), token: '' };
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const jsonInputValidation = useValidation({
|
||||||
|
source: payload,
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
message: 'Invalid JSON string',
|
||||||
|
validator: value => JSON5.parse(value),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
const jsonFooterValidation = useValidation({
|
||||||
|
source: footer,
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
message: 'Invalid JSON string',
|
||||||
|
validator: value => JSON5.parse(value),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
const token = ref('');
|
||||||
|
const verifiedToken = computedAsync(async () => {
|
||||||
|
const publicKeyValue = publicKey.value;
|
||||||
|
const tokenValue = token.value;
|
||||||
|
const validatePayloadValue = validatePayload.value;
|
||||||
|
try {
|
||||||
|
// generic type parameter is optional but will give you type safety on the payload
|
||||||
|
const { payload, footer } = await verify<any>(
|
||||||
|
publicKeyValue,
|
||||||
|
tokenValue,
|
||||||
|
{
|
||||||
|
validatePayload: validatePayloadValue,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return {
|
||||||
|
payload,
|
||||||
|
footer,
|
||||||
|
error: '',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
catch (e: any) {
|
||||||
|
return { error: e.toString(), payload: '', footer: '' };
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<c-card title="Key Pairs" mb-2>
|
||||||
|
<c-input-text
|
||||||
|
v-model:value="secretKey"
|
||||||
|
label="Secret Key:"
|
||||||
|
label-position="left"
|
||||||
|
placeholder="PASERK secret key k4.secret.xxxx"
|
||||||
|
mb-1
|
||||||
|
/>
|
||||||
|
<c-input-text
|
||||||
|
v-model:value="publicKey"
|
||||||
|
label="Public Key:"
|
||||||
|
label-position="left"
|
||||||
|
placeholder="PASERK public key k4.public.xxxx"
|
||||||
|
mb-1
|
||||||
|
/>
|
||||||
|
<div flex justify-center>
|
||||||
|
<n-button @click="generateKeyPairs()">
|
||||||
|
Refresh Key
|
||||||
|
</n-button>
|
||||||
|
</div>
|
||||||
|
</c-card>
|
||||||
|
|
||||||
|
<c-card title="Signing" mb-2>
|
||||||
|
<c-input-text
|
||||||
|
v-model:value="payload"
|
||||||
|
label="Payload:"
|
||||||
|
multiline
|
||||||
|
rows="5"
|
||||||
|
autosize
|
||||||
|
placeholder="JSON payload"
|
||||||
|
:validation="jsonInputValidation"
|
||||||
|
/>
|
||||||
|
<n-space justify="center">
|
||||||
|
<n-form-item label="Validate Payload" label-placement="left">
|
||||||
|
<n-switch v-model:value="validatePayload" />
|
||||||
|
</n-form-item>
|
||||||
|
<n-form-item label="Add Exp" label-placement="left">
|
||||||
|
<n-switch v-model:value="addExp" />
|
||||||
|
</n-form-item>
|
||||||
|
<n-form-item label="Add IAT" label-placement="left">
|
||||||
|
<n-switch v-model:value="addIat" />
|
||||||
|
</n-form-item>
|
||||||
|
</n-space>
|
||||||
|
|
||||||
|
<c-input-text
|
||||||
|
v-model:value="footer"
|
||||||
|
label="Footer:"
|
||||||
|
multiline
|
||||||
|
rows="2"
|
||||||
|
autosize
|
||||||
|
placeholder="JSON footer"
|
||||||
|
:validation="jsonFooterValidation"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<c-card v-if="signedToken" title="Signed PASERK Token:" mb-2>
|
||||||
|
<textarea-copyable v-if="signedToken.token" :value="signedToken.token" word-wrap />
|
||||||
|
<c-alert v-if="signedToken.error">
|
||||||
|
{{ signedToken.error }}
|
||||||
|
</c-alert>
|
||||||
|
</c-card>
|
||||||
|
</c-card>
|
||||||
|
|
||||||
|
<c-card title="Verifying" mb-2>
|
||||||
|
<c-input-text
|
||||||
|
v-model:value="token"
|
||||||
|
label="Token:"
|
||||||
|
multiline
|
||||||
|
rows="5"
|
||||||
|
autosize
|
||||||
|
placeholder="PASERK token"
|
||||||
|
/>
|
||||||
|
<n-space justify="center">
|
||||||
|
<n-form-item label="Validate Payload" label-placement="left">
|
||||||
|
<n-switch v-model:value="validatePayload" />
|
||||||
|
</n-form-item>
|
||||||
|
</n-space>
|
||||||
|
|
||||||
|
<c-card v-if="verifiedToken" title="Verification result:" mb-2>
|
||||||
|
<n-form-item v-if="verifiedToken.payload" label="Payload:">
|
||||||
|
<textarea-copyable :value="JSON.stringify(verifiedToken.payload, null, 2)" word-wrap />
|
||||||
|
</n-form-item>
|
||||||
|
<n-form-item v-if="verifiedToken.footer" label="Footer:">
|
||||||
|
<textarea-copyable :value="JSON.stringify(verifiedToken.footer, null, 2)" word-wrap />
|
||||||
|
</n-form-item>
|
||||||
|
<c-alert v-if="verifiedToken.error">
|
||||||
|
{{ verifiedToken.error }}
|
||||||
|
</c-alert>
|
||||||
|
</c-card>
|
||||||
|
</c-card>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
Vendored
+100
@@ -0,0 +1,100 @@
|
|||||||
|
declare module "paseto-ts/v4" {
|
||||||
|
export type PasetoPurpose = 'local' | 'public';
|
||||||
|
export type Assertion = {
|
||||||
|
[key: string]: any;
|
||||||
|
} | string | Uint8Array;
|
||||||
|
export type Payload = {
|
||||||
|
[key: string]: any;
|
||||||
|
iss?: string;
|
||||||
|
sub?: string;
|
||||||
|
aud?: string;
|
||||||
|
exp?: string;
|
||||||
|
nbf?: string;
|
||||||
|
jti?: string;
|
||||||
|
iat?: string;
|
||||||
|
};
|
||||||
|
export type Footer = {
|
||||||
|
[key: string]: any;
|
||||||
|
kid?: string;
|
||||||
|
wpk?: string;
|
||||||
|
};
|
||||||
|
export type GetRandomValues = (array: Uint8Array) => Uint8Array;
|
||||||
|
|
||||||
|
export interface PASERKPublicKeyPair {
|
||||||
|
secretKey: string;
|
||||||
|
publicKey: string;
|
||||||
|
}
|
||||||
|
export interface PASERKPublicKeyPairBuffer {
|
||||||
|
secretKey: Uint8Array;
|
||||||
|
publicKey: Uint8Array;
|
||||||
|
}
|
||||||
|
|
||||||
|
export declare function generateKeys(purpose: 'local', opts?: {
|
||||||
|
format?: 'paserk';
|
||||||
|
getRandomValues?: GetRandomValues;
|
||||||
|
}): string;
|
||||||
|
export declare function generateKeys(purpose: 'local', opts?: {
|
||||||
|
format?: 'buffer';
|
||||||
|
getRandomValues?: GetRandomValues;
|
||||||
|
}): Uint8Array;
|
||||||
|
export declare function generateKeys(purpose: 'public', opts?: {
|
||||||
|
format?: 'paserk';
|
||||||
|
getRandomValues?: GetRandomValues;
|
||||||
|
}): PASERKPublicKeyPair;
|
||||||
|
export declare function generateKeys(purpose: 'public', opts?: {
|
||||||
|
format?: 'buffer';
|
||||||
|
getRandomValues?: GetRandomValues;
|
||||||
|
}): PASERKPublicKeyPairBuffer;
|
||||||
|
|
||||||
|
export declare function decrypt<T extends {
|
||||||
|
[key: string]: any;
|
||||||
|
} = {
|
||||||
|
[key: string]: any;
|
||||||
|
}>(key: string | Uint8Array, token: string | Uint8Array, { assertion, maxDepth, maxKeys, validatePayload, }?: {
|
||||||
|
assertion?: Assertion | string | Uint8Array;
|
||||||
|
maxDepth?: number;
|
||||||
|
maxKeys?: number;
|
||||||
|
validatePayload?: boolean;
|
||||||
|
}): {
|
||||||
|
payload: Payload & T;
|
||||||
|
footer: Footer | string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export declare function encrypt(key: string | Uint8Array, payload: Payload | string | Uint8Array, { footer, assertion, addIat, addExp, maxDepth, maxKeys, validatePayload, getRandomValues, }?: {
|
||||||
|
footer?: Footer | string | Uint8Array;
|
||||||
|
assertion?: Assertion | string | Uint8Array;
|
||||||
|
addIat?: boolean;
|
||||||
|
addExp?: boolean;
|
||||||
|
maxDepth?: number;
|
||||||
|
maxKeys?: number;
|
||||||
|
validatePayload?: boolean;
|
||||||
|
getRandomValues?: GetRandomValues;
|
||||||
|
}): string;
|
||||||
|
|
||||||
|
export declare function sign(key: string | Uint8Array, payload: Payload | string | Uint8Array, { footer, assertion, addExp, // Add an exp claim if one is not provided: https://github.com/paseto-standard/paseto-spec/blob/master/docs/02-Implementation-Guide/05-API-UX.md#default-expiration-claims
|
||||||
|
addIat, // Add an iat claim if one is not provided
|
||||||
|
maxDepth, // Maximum depth of nested objects
|
||||||
|
maxKeys, // Maximum number of keys in an object
|
||||||
|
validatePayload, }?: {
|
||||||
|
footer?: Footer | string | Uint8Array;
|
||||||
|
assertion?: Assertion | string | Uint8Array;
|
||||||
|
addExp?: boolean;
|
||||||
|
addIat?: boolean;
|
||||||
|
maxDepth?: number;
|
||||||
|
maxKeys?: number;
|
||||||
|
validatePayload?: boolean;
|
||||||
|
}): string;
|
||||||
|
export declare function verify<T extends {
|
||||||
|
[key: string]: any;
|
||||||
|
} = {
|
||||||
|
[key: string]: any;
|
||||||
|
}>(key: string | Uint8Array, token: string | Uint8Array, { assertion, maxDepth, maxKeys, validatePayload, }?: {
|
||||||
|
assertion?: Assertion | string | Uint8Array;
|
||||||
|
maxDepth?: number;
|
||||||
|
maxKeys?: number;
|
||||||
|
validatePayload?: boolean;
|
||||||
|
}): {
|
||||||
|
payload: Payload & T;
|
||||||
|
footer?: Footer | string;
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in new issue
Block a user