-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add local signature server & update scripts (#64)
* Add local signature server & update scripts * Specify bash shell in GH Action Also updates the build command for the sanity workflow. * Update signatures URL for production build * Remove comments
- Loading branch information
1 parent
073278f
commit 4456519
Showing
17 changed files
with
922 additions
and
107 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,8 @@ jobs: | |
uses: ./.github/actions/setup | ||
|
||
- name: Build | ||
run: pnpm build:${{ matrix.browser }} | ||
shell: bash | ||
run: pnpm build ${{ matrix.browser }} | ||
|
||
- name: Upload artifacts | ||
uses: actions/[email protected] | ||
|
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 |
---|---|---|
|
@@ -38,6 +38,7 @@ jobs: | |
uses: ./.github/actions/setup | ||
|
||
- name: Build | ||
shell: bash | ||
run: pnpm build | ||
|
||
- name: Release | ||
|
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,81 @@ | ||
import { | ||
createHeaders, | ||
Headers, | ||
loadBase64Key, | ||
RequestLike, | ||
} from '@interledger/http-signature-utils' | ||
import Koa from 'koa' | ||
import bodyParser from 'koa-bodyparser' | ||
|
||
interface Context<TResponseBody = unknown> | ||
extends Koa.ParameterizedContext<Koa.DefaultState, Koa.DefaultContext, TResponseBody> {} | ||
|
||
interface GenerateSignatureRequestBody extends RequestLike {} | ||
|
||
function validateBody(body: any): body is GenerateSignatureRequestBody { | ||
return !!body.headers && !!body.method && !!body.url | ||
} | ||
|
||
async function validatePath(ctx: Context, next: Koa.Next): Promise<void> { | ||
if (ctx.path !== '/') { | ||
ctx.status = 404 | ||
} else { | ||
await next() | ||
} | ||
} | ||
|
||
async function validateMethod(ctx: Context, next: Koa.Next): Promise<void> { | ||
if (ctx.method !== 'POST') { | ||
ctx.status = 405 | ||
} else { | ||
await next() | ||
} | ||
} | ||
|
||
async function createHeadersHandler(ctx: Context<Headers>): Promise<void> { | ||
const { body } = ctx.request | ||
|
||
if (!validateBody(body)) { | ||
ctx.throw('Invalid request body', 400) | ||
} | ||
|
||
let privateKey: ReturnType<typeof loadBase64Key> | ||
|
||
try { | ||
privateKey = loadBase64Key(BASE64_PRIVATE_KEY) | ||
} catch { | ||
ctx.throw('Not a valid private key', 400) | ||
} | ||
|
||
if (privateKey === undefined) { | ||
ctx.throw('Not an Ed25519 private key', 400) | ||
} | ||
|
||
const headers = await createHeaders({ | ||
request: body, | ||
privateKey, | ||
keyId: KEY_ID, | ||
}) | ||
|
||
delete headers['Content-Length'] | ||
delete headers['Content-Type'] | ||
|
||
ctx.body = headers | ||
} | ||
|
||
const PORT = 3000 | ||
const BASE64_PRIVATE_KEY = | ||
'LS0tLS1CRUdJTiBQUklWQVRFIEtFWS0tLS0tCk1DNENBUUF3QlFZREsyVndCQ0lFSUUvVlJTRVUzYS9CTUE2cmhUQnZmKzcxMG10YWlmbkF6SzFsWGpDK0QrSTkKLS0tLS1FTkQgUFJJVkFURSBLRVktLS0tLQ==' | ||
const KEY_ID = 'f0ac2190-54d5-47c8-b061-221e7068d823' | ||
|
||
const app = new Koa<Koa.DefaultState, Context>() | ||
|
||
app.use(bodyParser()) | ||
app.use(validatePath) | ||
app.use(validateMethod) | ||
app.use(createHeadersHandler) | ||
|
||
app.listen(3000, () => { | ||
// eslint-disable-next-line no-console | ||
console.log(`Local signatures server started on port ${PORT}`) | ||
}) |
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.