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

Verify Signature #1

Open
4 tasks
tripott opened this issue Jun 8, 2022 · 0 comments
Open
4 tasks

Verify Signature #1

tripott opened this issue Jun 8, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@tripott
Copy link
Contributor

tripott commented Jun 8, 2022

hyper Queue allows you to create a target webhook endpoint to receive jobs, in order to secure that endpoint to only receive jobs from hyper, you can implement a secret, this secret using sha256 to encode a nounce timestamp and a signature of the job payload. We created a function on hyper_connect to make it easier to implement your own middleware to validate these incoming jobs in a secure way.

  • Create and export create_hyper_verify fn
  • Types
  • Document within readme
  • Example within readme

JS hyper-connect SDK version: https://github.com/hyper63/hyper/blob/main/packages/connect/deno/utils/hyper-verify.ts

/**
 * Verify a job received from a hyper queue.
 * See https://docs.hyper.io/post-a-jobtask#sz-verifying-jobs-from-hyper-queue
 *
 * @param {string} secret - the secret you provided when creating the queue.
 * your hyper queue adds a signature to all job requests, using this secret.
 * @param {string} ttl - the maximum age of a job, in the case of your worker having a constraint
 * where it should only process jobs if the job was sent within the last 5 minutes
 * @returns - a function that, given the X-HYPER-SIGNATURE and job payload,
 * will verify the signature and payload and return a hyper OK response
 */

export function createHyperVerify(secret: string, ttl?: string) {
  return function (signature: string, payload: unknown): Result {
    return of({ input: { signature, payload }, secret, ttl })
      .map(splitHyperSignature)
      .chain(createHmacSignature)
      .chain(compareSignatures)
      .chain(verifyTimeGap(ttl as string))
      .either(identity, handleSuccess);
  };
}
@tripott tripott added the enhancement New feature or request label Jun 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant