-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: generate keys when extension is installed #93
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(/=+$/, '') | ||
raducristianpopa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is no reason for this method to be here, it's independent of the background class. Maybe a better place would be the storage wrapper to access different variables in there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, there isn't a storage wrapper available. Once the storage wrapper is implemented, transferring it there will be straightforward. I'll add a comment.