Enable CORS, fix nsec1 keys

This commit is contained in:
Alex Gleason 2023-03-04 22:49:08 -06:00
parent 825fed7d21
commit 48f04e48de
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
4 changed files with 11 additions and 2 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.env

View File

@ -1,3 +1,5 @@
import converter from 'npm:bech32-converting';
import { validator, z } from '@/deps.ts';
const createTokenSchema = z.object({
@ -8,8 +10,11 @@ const createTokenController = validator('json', (value, c) => {
const result = createTokenSchema.safeParse(value);
if (result.success) {
const password = result.data.password;
const token = password.startsWith('nsec1') ? converter('nsec').toHex(password).slice(2) : password;
return c.json({
access_token: result.data.password,
access_token: token,
token_type: 'Bearer',
scope: 'read write follow push',
created_at: Math.floor(new Date().getTime() / 1000),

View File

@ -1,4 +1,4 @@
import { Hono } from '@/deps.ts';
import { cors, Hono } from '@/deps.ts';
import { credentialsController } from './api/accounts.ts';
import { appCredentialsController, createAppController } from './api/apps.ts';
@ -8,6 +8,8 @@ import { createTokenController } from './api/oauth.ts';
const app = new Hono();
app.use('/*', cors());
app.get('/api/v1/instance', instanceController);
app.get('/api/v1/apps/verify_credentials', appCredentialsController);

View File

@ -1,5 +1,6 @@
import { Context, Hono, validator } from 'https://deno.land/x/hono@v3.0.2/mod.ts';
export { Hono, validator };
export { cors } from 'https://deno.land/x/hono@v3.0.2/middleware.ts';
export { z } from 'https://deno.land/x/zod@v3.20.5/mod.ts';
export { Author, RelayPool } from 'https://dev.jspm.io/nostr-relaypool@0.5.3';
export { getPublicKey } from 'https://dev.jspm.io/nostr-tools@1.6.0';