0.0.1 • Published 2 years ago

signed-fetch v0.0.1

Weekly downloads
-
License
ISC
Repository
gitlab
Last release
2 years ago

Signed Fetch

A fetch wrapper that sends signed requests, according to the Signing HTTP Messages draft 08.

This has not been tested in production or with other servers yet. If you decide to try it and find any bugs please let me know.

import SignedFetch from 'signed-fetch';
import * as nodeFetch from 'node-fetch';

// You should make the public key available at this URL
const publicKeyId = 'http://my-site.example/@paul#main-key';
const privateKey = `-----BEGIN RSA PRIVATE KEY-----
${process.env.PRIVATE_KEY}
-----END RSA PRIVATE KEY-----`;

const fetch = new SignedFetch(
	{
		keyId: publicKeyId,
		privateKey: privateKey
	},
	{
		...nodeFetch,
		fetch: nodeFetch.default
	}
);

const res = await fetch('https://mastodon.social/user/gargron')

Dependencies

  • activitypub-http-signatures: ^1.0.0
  • custom-fetch: ^1.0.0

signed-fetch

Signed Fetch

module.exports ⏏

Creates a fetch-like function that sends signed messages

Kind: Exported class

new module.exports(keyOptions, fetchOptions, Request, Response, fetch)

Create a SignedFetch function

ParamTypeDescription
keyOptionsobjectKey options
keyOptions.keyIdstringURI of the public key for verifying the signature
keyOptions.privateKeystringThe private key to use to sign requests
fetchOptionsobjectFetch implementation
RequestclassConstructor for the fetch request object
ResponseclassConstructor for the fetch response object
fetchfunctionThe actual fetch function to call