-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
54 additions
and
12 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
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,19 @@ | ||
import { bench, describe } from "vitest"; | ||
import { verify as verifyNode } from "../src/index.ts"; | ||
import { verify as verifyWeb } from "../src/web.ts"; | ||
import { toNormalizedJsonString } from "./common.ts"; | ||
|
||
describe("sign", () => { | ||
const eventPayload = toNormalizedJsonString({ | ||
foo: "bar", | ||
}); | ||
const secret = "mysecret"; | ||
|
||
bench("node", async () => { | ||
await signNode(secret, JSON.stringify(eventPayload)); | ||
}); | ||
|
||
bench("web", async () => { | ||
await signWeb(secret, JSON.stringify(eventPayload)); | ||
}); | ||
}); |
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,22 @@ | ||
import { bench, describe } from "vitest"; | ||
import { verify as verifyNode } from "../src/index.ts"; | ||
import { verify as verifyWeb } from "../src/web.ts"; | ||
import { toNormalizedJsonString } from "./common.ts"; | ||
|
||
describe("verify", () => { | ||
const eventPayload = toNormalizedJsonString({ | ||
foo: "bar", | ||
}); | ||
const secret = "mysecret"; | ||
|
||
const signatureSHA256 = | ||
"sha256=e3eccac34c43c7dc1cbb905488b1b81347fcc700a7b025697a9d07862256023f"; | ||
|
||
bench("node", async () => { | ||
await verifyNode(secret, eventPayload, signatureSHA256); | ||
}); | ||
|
||
bench("web", async () => { | ||
await verifyWeb(secret, eventPayload, signatureSHA256); | ||
}); | ||
}); |
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,7 @@ | ||
export function toNormalizedJsonString(payload: object) { | ||
// GitHub sends its JSON with no indentation and no line breaks at the end | ||
const payloadString = JSON.stringify(payload); | ||
return payloadString.replace(/[^\\]\\u[\da-f]{4}/g, (s) => { | ||
return s.substr(0, 3) + s.substr(3).toUpperCase(); | ||
}); | ||
} |
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