Skip to content
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

Update libraries to accept raw webhook secret #555

Merged
merged 29 commits into from
Jul 13, 2022
Merged
Changes from 2 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f748dbd
implement raw token option in js lib
svix-dylan Jul 12, 2022
979926e
account for base64 string
svix-dylan Jul 12, 2022
6d3a732
generalize and patch ui8a bug
svix-dylan Jul 12, 2022
ceaec95
feedback
svix-dylan Jul 12, 2022
5282289
reformat conditions check
svix-dylan Jul 12, 2022
b34dacb
go implementation
svix-dylan Jul 12, 2022
35b451c
patch go linter errors
svix-dylan Jul 12, 2022
153d865
god i hate java. attempt java impl.
svix-dylan Jul 12, 2022
79f7ac0
java remove trailing spaces for linter
svix-dylan Jul 12, 2022
64e426d
iterate per feedback
svix-dylan Jul 12, 2022
f7504df
kotlin impl
svix-dylan Jul 12, 2022
273f071
php impl
svix-dylan Jul 12, 2022
5e7776c
php linter patch
svix-dylan Jul 12, 2022
7dc40a7
python attempt
svix-dylan Jul 12, 2022
b989735
single overloaded “from raw” function Go
svix-dylan Jul 12, 2022
2c3eecf
use Union to solve python init (and remove stale enc_key)
svix-dylan Jul 12, 2022
ca47c1f
lint patch
svix-dylan Jul 12, 2022
b546141
python lint
svix-dylan Jul 12, 2022
1abff99
ruby attempt
svix-dylan Jul 12, 2022
0f02a78
rust impl
svix-dylan Jul 12, 2022
ad4eb57
patch rust
svix-dylan Jul 12, 2022
eeb4e56
patch rust
svix-dylan Jul 12, 2022
19f1f7f
csharp, a la java approach
svix-dylan Jul 12, 2022
579033b
patch Go
svix-dylan Jul 12, 2022
cd53be5
string->String->bytes
svix-dylan Jul 12, 2022
1efb72e
fml ok
svix-dylan Jul 12, 2022
1a12edf
ruby lint patch
svix-dylan Jul 12, 2022
e6d41d1
remove rawString construction, all libs except js
svix-dylan Jul 12, 2022
47f98f7
Update rust/src/webhooks.rs
tasn Jul 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions javascript/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -590,18 +590,28 @@ export interface WebhookUnbrandedRequiredHeaders {
"webhook-signature": string;
}

export interface WebhookOptions {
raw?: boolean;
svix-dylan marked this conversation as resolved.
Show resolved Hide resolved
}

export class Webhook {
private static prefix = "whsec_";
private readonly key: Uint8Array;

constructor(secret: string) {
constructor(secret: string | Uint8Array, options?: WebhookOptions) {
if (!secret) {
throw new Error("Secret can't be empty.");
}
if (secret.startsWith(Webhook.prefix)) {
if (!options?.raw && secret instanceof String && secret.startsWith(Webhook.prefix)) {
secret = secret.substring(Webhook.prefix.length);
}
this.key = base64.decode(secret);
if (options?.raw && secret instanceof Uint8Array) {
this.key = secret;
} else if (options?.raw && secret instanceof String) {
this.key = Uint8Array.from(atob(secret.toString()), (c) => c.charCodeAt(0));
svix-dylan marked this conversation as resolved.
Show resolved Hide resolved
} else {
this.key = base64.decode(secret.toString());
svix-dylan marked this conversation as resolved.
Show resolved Hide resolved
}
}

public verify(
Expand Down