Socket
Book a DemoInstallSign in
Socket

hmac-scheme-plain

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hmac-scheme-plain

Sign a request with an HMAC signature

0.1.1
latest
Source
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

hmac-scheme-plain

Build Status Coverage Status

Plain scheme plugin for axios-adapter-hmac. Follows the "plain" scheme spec from cmawhorter/hmmac.

Config

This scheme requires two values in the schemeConfig object:

{
    publicKey: "<publicKey>",
    privateKey: "<privateKey>",
}

Usage

See the readme for axios-adapter-hmac for adapter-specific usage instructions.

This module is not inherently coupled to the axios adapter — its purpose is simply to transform a request-ish object.

To use this module outside of the axios request adapter, simply require it and pass options to the sign function:

const hmacSchemePlain = require("hmac-scheme-plain");

function hash(data) {
    // generate a hash digest
}

function hmac(data) {
    // generate an hmac digest
}

const signedHeaders = ["content-type", "date", "host"];
const schemeConfig = {
    publicKey: "publicKey",
    privateKey: "privateKey",
};
const request = {
    method: "get",
    url: "https://google.com",
    headers: {
        "content-type": "application/json",
        date: "2017-10-11T20:00:00.000Z",
        host: "google.com",
    },
    data: {
        key: "value",
    }
    // ...other request keys
}

hmacSchemePlain.sign({ request, signedHeaders, schemeConfig, hash, hmac });

console.log(request)
/* {
    method: "get",
    url: "https://google.com",
    headers: {
        "content-type": "application/json",
        date: "2017-10-11T20:00:00.000Z",
        host: "google.com",
        // new headers
        "x-auth-signedheaders": "content-type;date;host",
        authorization: "HMAC <publicKey>:<hash>",
    },
    data: {
        key: "value",
    }
    ...other request keys
} */

The request object is required to have the following properties:

method: string,
url: string,
headers: {
    [string]: string
},
data?: {
    [string]: string
},

The hash and hmac functions must generate digests as strings. An example using the crypto module:

const crypto = require("crypto");

function hash(data) {
    return crypto
        .generateHash("sha256")
        .update(data)
        .digest("hex");
}

signedHeaders must be an array, though it can be empty.

FAQs

Package last updated on 12 Oct 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.