generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add generate key response and basic key generation tests
- Loading branch information
Showing
9 changed files
with
1,145 additions
and
3 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,44 @@ | ||
import { Request, Response } from "express"; | ||
import { LocalKms, KeyManager, Web5ManagedAgent } from "@web5/agent"; | ||
import { paths } from "./openapi.js"; | ||
import { Convert } from "@web5/common"; | ||
|
||
// @ts-ignore | ||
const mockAgent: Web5ManagedAgent = {}; | ||
const localKms = new LocalKms({ kmsName: "memory", agent: mockAgent }); | ||
const keyManager = new KeyManager({ | ||
kms: { memory: localKms }, | ||
agent: mockAgent, | ||
}); | ||
|
||
export async function cryptoSecp256k1Generate(req: Request, res: Response) { | ||
const key = await keyManager.generateKey({ | ||
kms: "memory", | ||
algorithm: { name: "ECDSA", namedCurve: "secp256k1" }, | ||
keyUsages: ["sign", "verify"], | ||
}); | ||
|
||
const resp: paths["/crypto/generate-key/secp256k1"]["post"]["responses"]["200"]["content"]["application/json"] = | ||
{ | ||
public: Convert.uint8Array(key.publicKey.material!).toBase64Url(), | ||
private: null, //Convert.uint8Array(key.privateKey.material!).toBase64Url(), // private key material here is null? | ||
}; | ||
|
||
res.json(resp); | ||
} | ||
|
||
export async function cryptoEd25519Generate(req: Request, res: Response) { | ||
const keyPair = await keyManager.generateKey({ | ||
kms: "memory", | ||
algorithm: { name: "EdDSA", namedCurve: "Ed25519" }, | ||
keyUsages: ["sign", "verify"], | ||
}); | ||
|
||
const resp: paths["/crypto/generate-key/ed25519"]["post"]["responses"]["200"]["content"]["application/json"] = | ||
{ | ||
public: Convert.uint8Array(keyPair.publicKey.material!).toBase64Url(), | ||
private: null, //Convert.uint8Array(keyPair.privateKey.material!).toBase64Url(), | ||
}; | ||
|
||
res.json(resp); | ||
} |
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.