-
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: generate keys when extension is installed (#93)
* Generate keys when extension is installed * Add comments
- Loading branch information
1 parent
b944898
commit 4025f6b
Showing
8 changed files
with
100 additions
and
15 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
This file was deleted.
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,14 @@ | ||
import { asClass, createContainer } from 'awilix' | ||
|
||
import Background from './Background' | ||
|
||
interface Cradle { | ||
background: Background | ||
} | ||
|
||
export const container = createContainer<Cradle>() | ||
|
||
container.register({ | ||
background: asClass(Background).singleton(), | ||
// TODO - add injectable services | ||
}) |
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,35 @@ | ||
import * as ed from '@noble/ed25519' | ||
import { sha512 } from '@noble/hashes/sha512' | ||
|
||
ed.etc.sha512Sync = (...m) => sha512(ed.etc.concatBytes(...m)) | ||
|
||
export function generateEd25519KeyPair() { | ||
const rawPrivateKey = ed.utils.randomPrivateKey() | ||
// PKCS#8 format (version + algorithm) | ||
// Adding these values upfront solves the future import of the key using | ||
// `crypto.subtle.importKey` once the WebCrypto API supports the Ed25519 algorithm. | ||
// prettier-ignore | ||
const privateKey = new Uint8Array([ | ||
48, 46, 2, 1, 0, 48, 5, 6, 3, 43, 101, 112, 4, 34, 4, 32, | ||
...rawPrivateKey, | ||
]) | ||
const publicKey = ed.getPublicKey(rawPrivateKey) | ||
|
||
return { privateKey, publicKey } | ||
} | ||
|
||
export function exportJWK(key: Uint8Array, kid: string) { | ||
const string = String.fromCharCode.apply(null, key) | ||
|
||
const base64 = btoa(string) | ||
// Based on the JWK Spec - base64url encoded. | ||
// https://datatracker.ietf.org/doc/html/rfc7517#section-3 | ||
const base64Url = base64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '') | ||
|
||
return { | ||
kty: 'OKP', | ||
crv: 'Ed25519', | ||
x: base64Url, | ||
kid, | ||
} | ||
} |
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