-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:
verifyRequestByKeyId()
, verifyRequest()
, `fetchVerification…
…Keys()` (#8) BREAKING CHANGE: `verify()` method has been replaced by `verifyRequestByKeyId()` for clarity Before: ```js import { verify } from "@copilot-extensions/preview-sdk"; const payloadIsVerified = await verify(request.body, signature, keyId, { token }); ``` After ```js import { verifyRequestByKeyId } from "@copilot-extensions/preview-sdk"; const payloadIsVerified = await verifyRequestByKeyId(request.body, signature, key, { token }); ```
- Loading branch information
Showing
5 changed files
with
260 additions
and
56 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
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 |
---|---|---|
@@ -1,32 +1,66 @@ | ||
import { expectType } from "tsd"; | ||
import { request } from "@octokit/request"; | ||
|
||
import { verify } from "./index.js"; | ||
import { | ||
fetchVerificationKeys, | ||
verifyRequest, | ||
verifyRequestByKeyId, | ||
type VerificationPublicKey, | ||
} from "./index.js"; | ||
|
||
const rawBody = ""; | ||
const signature = ""; | ||
const keyId = ""; | ||
const key = "" | ||
const token = ""; | ||
|
||
export async function verifyTest() { | ||
const result = await verify(rawBody, signature, keyId); | ||
export async function verifyRequestByKeyIdTest() { | ||
const result = await verifyRequestByKeyId(rawBody, signature, keyId); | ||
expectType<boolean>(result); | ||
|
||
// @ts-expect-error - first 3 arguments are required | ||
verify(rawBody, signature); | ||
verifyRequestByKeyId(rawBody, signature); | ||
|
||
// @ts-expect-error - rawBody must be a string | ||
await verify(1, signature, keyId); | ||
await verifyRequestByKeyId(1, signature, keyId); | ||
|
||
// @ts-expect-error - signature must be a string | ||
await verify(rawBody, 1, keyId); | ||
await verifyRequestByKeyId(rawBody, 1, keyId); | ||
|
||
// @ts-expect-error - keyId must be a string | ||
await verify(rawBody, signature, 1); | ||
await verifyRequestByKeyId(rawBody, signature, 1); | ||
|
||
// accepts a token argument | ||
await verify(rawBody, signature, keyId, { token }); | ||
await verifyRequestByKeyId(rawBody, signature, keyId, { token }); | ||
|
||
// accepts a request argument | ||
await verify(rawBody, signature, keyId, { request }); | ||
await verifyRequestByKeyId(rawBody, signature, keyId, { request }); | ||
} | ||
|
||
export async function verifyRequestTest() { | ||
const result = await verifyRequest(rawBody, signature, key); | ||
expectType<boolean>(result); | ||
|
||
// @ts-expect-error - first 3 arguments are required | ||
verifyRequest(rawBody, signature); | ||
|
||
// @ts-expect-error - rawBody must be a string | ||
await verifyRequest(1, signature, key); | ||
|
||
// @ts-expect-error - signature must be a string | ||
await verifyRequest(rawBody, 1, key); | ||
|
||
// @ts-expect-error - key must be a string | ||
await verifyRequest(rawBody, signature, 1); | ||
} | ||
|
||
export async function fetchVerificationKeysTest() { | ||
const result = await fetchVerificationKeys(); | ||
expectType<VerificationPublicKey[]>(result); | ||
|
||
// accepts a token argument | ||
await fetchVerificationKeys({ token }); | ||
|
||
// accepts a request argument | ||
await fetchVerificationKeys({ request }); | ||
} |
Oops, something went wrong.