-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR setups the backend API skeleton and changes the front-end to interact with that API.
- Loading branch information
Frederik Rothenberger
committed
Dec 14, 2023
1 parent
5d79761
commit 394f34f
Showing
6 changed files
with
138 additions
and
16 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 |
---|---|---|
@@ -1,4 +1,13 @@ | ||
import { defineConfig } from "astro/config"; | ||
|
||
// https://astro.build/config | ||
export default defineConfig({}); | ||
export default defineConfig({ | ||
output: "server", | ||
vite: { | ||
server: { | ||
watch: { | ||
ignored: [".idea"], // don't hot reload on IDE file changes | ||
}, | ||
}, | ||
}, | ||
}); |
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,49 @@ | ||
import { AuthClient, IdbStorage } from "@dfinity/auth-client"; | ||
import { AnonymousIdentity, SignIdentity } from "@dfinity/agent"; | ||
import type { | ||
DerEncodedPublicKey, | ||
PublicKey, | ||
Signature, | ||
} from "@dfinity/agent/lib/esm/auth"; | ||
|
||
export class ChallengeAuthClient extends AuthClient { | ||
public constructor(challenge: string) { | ||
super( | ||
new AnonymousIdentity(), | ||
new ChallengeIdentity(challenge), | ||
null, | ||
new IdbStorage(), | ||
undefined, | ||
undefined, | ||
); | ||
} | ||
} | ||
|
||
export class ChallengeIdentity extends SignIdentity { | ||
private readonly challenge: ArrayBuffer; | ||
public constructor(challenge: string) { | ||
super(); | ||
this.challenge = base64ToBytes(challenge); | ||
} | ||
|
||
getPublicKey(): PublicKey { | ||
return new Challenge(this.challenge); | ||
} | ||
|
||
sign(_blob: ArrayBuffer): Promise<Signature> { | ||
throw new Error("not implemented"); | ||
} | ||
} | ||
|
||
export class Challenge { | ||
constructor(public challenge: ArrayBuffer) {} | ||
|
||
public toDer(): DerEncodedPublicKey { | ||
return this.challenge; | ||
} | ||
} | ||
|
||
function base64ToBytes(base64: string): Uint8Array { | ||
const binString = atob(base64); | ||
return Uint8Array.from(binString, (m) => m.codePointAt(0)!); | ||
} |
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,12 @@ | ||
import type { APIRoute } from "astro"; | ||
|
||
export const POST: APIRoute = async ({ request }) => { | ||
if (request.headers.get("Content-Type") === "application/json") { | ||
const body = await request.json(); | ||
console.log(`submitted verifiable presentation: ${JSON.stringify(body)}`); | ||
return new Response(undefined, { | ||
status: 200, | ||
}); | ||
} | ||
return new Response(null, { status: 400 }); | ||
}; |
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,14 @@ | ||
import type { APIRoute } from "astro"; | ||
import crypto from "crypto"; | ||
|
||
export const GET: APIRoute = () => { | ||
console.log("challenge requested"); | ||
return new Response( | ||
JSON.stringify({ | ||
challenge: crypto.randomBytes(20).toString("base64"), | ||
}), | ||
{ | ||
status: 200, | ||
}, | ||
); | ||
}; |
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,12 @@ | ||
import type { APIRoute } from "astro"; | ||
|
||
export const POST: APIRoute = async ({ request }) => { | ||
if (request.headers.get("Content-Type") === "application/json") { | ||
const body = await request.json(); | ||
console.log(`submitted delegation chain: ${JSON.stringify(body)}`); | ||
return new Response(undefined, { | ||
status: 200, | ||
}); | ||
} | ||
return new Response(null, { status: 400 }); | ||
}; |
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