-
Notifications
You must be signed in to change notification settings - Fork 19
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
enforce config.keys in TS and log an error when no keys are provided #67
base: main
Are you sure you want to change the base?
Changes from all commits
345dc97
5458be5
f293838
4e0e1b3
dfbe7af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,21 +24,13 @@ export type Transform = { | |
create: () => unknown; | ||
}; | ||
|
||
export type Config = { | ||
export interface BaseConfig { | ||
// Cryptographic capability key | ||
caps?: { | ||
shs?: Buffer | string; | ||
}; | ||
appKey?: Buffer | string; | ||
|
||
// Cryptographic keys | ||
keys?: { | ||
public?: string; | ||
private?: string; | ||
id?: string; | ||
}; | ||
seed?: unknown; | ||
|
||
// Multiserver | ||
connections?: { | ||
incoming?: { | ||
|
@@ -59,4 +51,21 @@ export type Config = { | |
// Legacy but still supported | ||
host?: string; | ||
port?: number; | ||
}; | ||
}; | ||
|
||
export interface SeedConfig extends BaseConfig { | ||
seed: unknown; | ||
keys: never; | ||
}; | ||
|
||
export interface KeysConfig extends BaseConfig { | ||
seed: never; | ||
// Cryptographic keys | ||
keys: { | ||
public: string; | ||
private: string; | ||
id: string; | ||
}; | ||
}; | ||
|
||
export type Config = KeysConfig | SeedConfig; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @staltz I am attempting to create a |
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.
I like this. I would hazard you should probably throw instead of printing an error.
I'd also like to see a test around this - you may find you never see this log because toSodium could error loudly if things go wrong internally to that? (haven't looked at it)
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.
@mixmix appreciate the review. the change has been made to throw rather than log. trying to think through the testing changes needed and could use some additional feedback.
this is what I've come up with so far to add a test case using the
shs
plugin directly, as catching the error when creating a new server catches the missing keys error but throws again whencore.js
goes to load and theshs
transform is missing. Would the following suffice?Should this PR be enhanced to throw only when both keys and a seed are missing? That would save us from updating all the tests.
cc @staltz
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.
I am not familiar enough with this code but expect that both keys need to be there... Or at least the public key.
Your test looks really scoped and sufficient to me. BTW you have essentially recreated tapes t.throws
You could write it like this
Seconds arg is a regex which will be used to test
error.message
on the error which is thrownThere 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.
This has been updated to include 2 new tests. One which throws an error when neither keys nor a seed are passed into with the config. A second test is included that shows the publicKey is being correctly populated when passing just a seed.
This is usually accomplished in multiserver where it would use the keys and expose the public key. Unfortunately we can't wait for this to make it down to multiserver when throwing for missing keys at this level, since the publicKey is needed right away.
This seems like a good idea to preserve some backward compatibility regarding the use of seeds, but open to being told otherwise :). This also introduces another dependency,
secret-handshake
, to use thetoKeys
method to convert the seed to a keypair but maybe usingchloride
directly would make more sense.