GithubHelp home page GithubHelp logo

interledger / http-message-signatures Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dhensby/node-http-message-signatures

0.0 2.0 0.0 211 KB

A package for signing HTTP messages as per the http-message-signing draft specification

License: ISC License

TypeScript 100.00%

http-message-signatures's Introduction

HTTP Message Signatures

Node.js CI

Based on the draft specifications for HTTP Message Signatures, this library facilitates the signing of HTTP messages before being sent.

Specifications

Two specifications are supported by this library:

  1. HTTPBIS
  2. Cavage

Approach

As the cavage specification is now expired and superseded by the HTTPBIS one, this library takes a "HTTPBIS-first" approach. This means that most support and maintenance will go into the HTTPBIS implementation and syntax. The syntax is then back-ported to the Cavage implementation as much as possible.

Examples

Signing a request

const { sign, createSigner } = require('http-message-signing');

(async () => {
    const signedRequest = await sign({
        method: 'POST',
        url: 'https://example.com',
        headers: {
            'content-type': 'text/plain',
        },
        body: 'test',
    }, {
        components: [
            '@method',
            '@authority',
            'content-type',
        ],
        parameters: {
            created: Math.floor(Date.now() / 1000),
        },
        keyId: 'my-hmac-secret',
        signer: createSigner('hmac-sha256'),
    });
    // signedRequest now has the `Signature` and `Signature-Input` headers
})().catch(console.error);

Signing with your own signer

It's possible to provide your own signer (this is useful if you're using a secure enclave or key management service). To do so, you must implement a callable that has the alg prop set to a valid algorithm value. It's possible to use proprietary algorithm values if you have some internal signing logic you need to support.

const mySigner = async (data) => {
    return Buffer.from('my sig');
}
mySigner.alg = 'custom-123';

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.