@octopusdeploy/step-packages-public-feed-encryption
TypeScript icon, indicating that this package has built-in type declarations

0.2.3 • Public • Published

STEP PACKAGE PUBLIC FEED ENCRYPTION

A package that facilitates the generation of an encrypted signature for step package public feed. The encryption method follows the convention of AWS Signature Version 4.

Install

npm i @octopusdeploy/step-packages-public-feed-encryption
pnpm i @octopusdeploy/step-packages-public-feed-encryption

Usage

Create Hash

import { createHash } from "@octopusdeploy/step-packages-public-feed-encryption";

const stringToEncrypt = "";
const hash = createHash("sha256", stringToEncrypt);

Create HMAC

import { createHmac } from "@octopusdeploy/step-packages-public-feed-encryption";

const stringToEncrypt = "";
const secretKey = process.env["SECRET_KEY"];
const hmac = createHmac("sha256", stringToEncrypt, secretKey);

Create Signature

import { createSignature, KeyValuePair } from "@octopusdeploy/step-packages-public-feed-encryption";

The createSignature will generate the encrypted request signature. The signature will then be attached to the request's header before the request is sent to the step package public feed server. The function requires these parameters:

  • algorithm (string): the algorithm used to encrypt the signature. ex: "sha265"
  • secretKey (string): the secret key which is associated with the Azure Function's API key.
  • httpMethod (string): the HTTP method of the request. ex: "POST"
  • headers (KeyValuePair[]): the KeyValuePair list of the HTTP request's header.
  • payloads (KeyValuePair[]): the KeyValuePair list of the HTTP request's content.
  • requestTimestamp (string): the ISO string of the request's timestamp. ex: "1975-08-19T23:15:30.000Z"
// Create request signature
const requestMethod = "POST";
const requestTimestamp = new Date().toJSON();
const requestHeader: Record<string, string> = {
    "x-functions-key": apiKey,
    "content-length": contentLength.toString(),
    timestamp: requestTimestamp,
};
const packageFile = readFileSync(packageToPublish, { encoding: "base64" });
const payloads: KeyValuePair[] = [
    {
        key: "package",
        value: packageFile,
    },
    {
        key: "manifest",
        value: JSON.stringify(manifest),
    },
];

requestHeader["signature"] = createSignature(
    "sha256",
    secretKey,
    requestMethod,
    Object.entries(requestHeader).map(([key, value]) => ({ key, value })),
    payloads,
    requestTimestamp
);

Package Sidebar

Install

npm i @octopusdeploy/step-packages-public-feed-encryption

Weekly Downloads

178

Version

0.2.3

License

none

Unpacked Size

18.2 kB

Total Files

16

Last publish

Collaborators

  • shaunmarx
  • octobob
  • octokartik
  • jbristowe