-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from viapip/master
proxy, mongodb
- Loading branch information
Showing
20 changed files
with
307 additions
and
77 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import path from 'node:path' | ||
|
||
export const alg = 'ES256' | ||
const keysDir = path.join(__dirname, './keys') | ||
|
||
export const publicKeyPath = path.join(keysDir, 'public') | ||
export const privateKeyPath = path.join(keysDir, 'private') | ||
export function loadKeys() { | ||
|
||
} | ||
|
||
// export async function writeKeys(obj: { | ||
// name: string | ||
// privateKey: jose.KeyLike | ||
// publicKey: jose.KeyLike | ||
// }) { | ||
|
||
// } | ||
|
||
// export async function generateKeyPair(name: string) { | ||
// const { privateKey, publicKey } = await jose.generateKeyPair(alg, { extractable: true }) | ||
|
||
// // writeKeys({ | ||
// // name, | ||
// // privateKey, | ||
// // publicKey, | ||
// // }) | ||
// } |
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,7 @@ | ||
import * as jose from 'jose' | ||
|
||
export const alg = 'ES256' | ||
|
||
export const serverKeys = await jose.generateKeyPair(alg, { extractable: true }) | ||
export const userKeys1 = await jose.generateKeyPair(alg, { extractable: true }) | ||
export const userKeys3 = await jose.generateKeyPair(alg, { extractable: true }) |
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,28 @@ | ||
import * as jose from 'jose' | ||
|
||
const alg = 'ES256' | ||
|
||
const keys = await jose.generateKeyPair(alg, { extractable: true }) | ||
const keys2 = await jose.generateKeyPair(alg, { extractable: true }) | ||
|
||
console.log('keys\n', await jose.exportPKCS8(keys.privateKey)) | ||
console.log('keys2\n', await jose.exportPKCS8(keys2.privateKey)) | ||
|
||
const jwt = await new jose.GeneralSign( | ||
new TextEncoder().encode('Hello, World!'), | ||
) | ||
.addSignature(keys.privateKey) | ||
.setProtectedHeader({ alg, b64: true }) | ||
.addSignature(keys2.privateKey) | ||
.setProtectedHeader({ alg, b64: true }) | ||
.sign() | ||
|
||
console.log('jwt', jwt) | ||
|
||
const { payload, protectedHeader } = await jose.generalVerify( | ||
jwt, | ||
keys2.publicKey, | ||
) | ||
|
||
console.log(protectedHeader) | ||
console.log(new TextDecoder().decode(payload)) |
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,51 @@ | ||
import * as jose from 'jose' | ||
|
||
const alg = 'ES256' | ||
const options = { | ||
issuer: 'urn:example:issuer', | ||
audience: 'urn:example:audience', | ||
} | ||
|
||
const keys = await jose.generateKeyPair(alg, { extractable: true }) | ||
const keys2 = await jose.generateKeyPair(alg, { extractable: true }) | ||
// const keys3 = await jose.generateKeyPair(alg, { extractable: true }); | ||
|
||
const jwk1 = await jose.exportJWK(keys.publicKey).then((jwk) => { | ||
jwk.kid = 'key1' | ||
|
||
return jwk | ||
}) | ||
|
||
const jwk2 = await jose.exportJWK(keys2.publicKey).then((jwk) => { | ||
jwk.kid = 'key2' | ||
|
||
return jwk | ||
}) | ||
|
||
// const jwk3 = await jose.exportJWK(keys3.publicKey).then((jwk) => { | ||
// jwk.kid = "key3"; | ||
// return jwk; | ||
// }); | ||
|
||
const jwks = jose.createLocalJWKSet({ keys: [jwk1, jwk2] }) | ||
|
||
console.log('keys\n', await jose.exportPKCS8(keys.privateKey)) | ||
console.log('keys2\n', await jose.exportPKCS8(keys2.privateKey)) | ||
|
||
const jwt = await new jose.SignJWT({ | ||
foo: 'bar', | ||
}) | ||
.setIssuer(options.issuer) | ||
.setAudience(options.audience) | ||
.setProtectedHeader({ alg, kid: 'key1' }) | ||
.setExpirationTime('10m') | ||
.setIssuedAt() | ||
.sign(keys.privateKey) | ||
|
||
console.log('jwt', jwt) | ||
|
||
const { payload, protectedHeader } = await jose | ||
.jwtVerify(jwt, jwks, options) | ||
|
||
console.log(protectedHeader) | ||
console.log(payload) |
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,22 @@ | ||
function generateCombinations(test: { [key: string]: string[] }): string[][] { | ||
let combinations: string[][] = [[]] | ||
Object.keys(test).forEach((key) => { | ||
const newCombinations: string[][] = [] | ||
test[key].forEach((value) => { | ||
combinations.forEach((combination) => { | ||
newCombinations.push([...combination, `${key}-${value}`]) | ||
}) | ||
}) | ||
combinations = newCombinations | ||
}) | ||
|
||
return combinations | ||
} | ||
|
||
const test = { | ||
size: ['xs', 's', 'm', 'l', 'xl'], | ||
color: ['red', 'green', 'blue'], | ||
material: ['wood', 'plastic', 'metal'], | ||
} | ||
|
||
console.log(generateCombinations(test)) |
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,16 @@ | ||
import consola from 'consola' | ||
import { MongoClient } from 'mongodb' | ||
|
||
const logger = consola.withTag('mongodb') | ||
export async function createMongoDBStore() { | ||
const client = new MongoClient('mongodb://root:example@mongodb:27017') | ||
|
||
await client.connect() | ||
|
||
const db = client.db('testSozdev') | ||
logger.debug('Connected to MongoDB', db.databaseName) | ||
|
||
return { | ||
data: db.collection('data'), | ||
} | ||
} |
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
Oops, something went wrong.