npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

js-signature

v0.1.9

Published

js-signature, laravel-signature

Downloads

5

Readme

Node JSSignature

说明

本 js 库为 laravel-signature 的客户端 js 版本。

安装

$ npm install js-signature

使用

# 1、设置 key,secret,[uri, method, params, ...]  参数;
# 2、通过 sign() 方法签名;
# 3、通过 getHeaders() 获取头部需要携带的参数,通过 http 请求头传递。
<script>
import JSSignature from 'js-signature'

JSSignature.init({
    key: 'accessKeyId',
    secret: 'accessKeySecret'
})
// uri,method, params, 也可直接通过 init 设置
const headers = JSSignature.setUri('/index').setMethod('GET')
        .setParams({ perPage: 20, page: 1, a: { aa: '1', bb: '2' }}).sign().getHeaders()
console.log(headers)
/**
* 因传递的时间为浏览器端的时间,可能错误;可提示时间错误或通过不签名接口获取服务器时间再使用设置时间戳方法
const headers = JSSignature.setUri('/index').setMethod('GET').setTimesamp(1600246526)
        .setParams({ perPage: 20, page: 1, a: { aa: '1', bb: '2' }}).sign().getHeaders()
*/
// {Access-Key-Id: "accessKeyId", Timestamp: "1600246526", Signature: "Signature B7vSXHICVTYYuGC5w3vBVdCwgjQ=", Version: ""}
</script>

init参数

| 参数 | 类型 | 默认 | 说明 | | ------------------ | ------ | ------------- | -------------------------------------------------- | | key | string | '' | 必须,accessKeyId | | secret | string | '' | 必须,accessKeySecret | | method | string | GET | [GET, POST, PUT, DELETE, ...] | | uri | string | '/' | 请求URI,域名后/开始 | | params | object | {} | 参数, | | version | string | '' | 接口版本 | | algo | string | sha1 | 加密方式[md5, sha1, sha256, ...] | | prefix | string | '' | 签名字符串前面拼接的字符 | | connector | string | & | 签名字符串之间拼接的字符 | | suffix | string | '' | 签名字符串最后拼接的字符 | | headerAccessKey | string | Access-Key-Id | 请求头参数名,headers['Access-Key-Id'] | | headerTimestamp | string | Timestamp | 请求头参数名,headers['Timestamp] | | headerSignature | string | Signature | 请求头参数名,headers['Signature'] | | headerSignatureTag | string | Signature | 签名标识 headers['Signature'] = Signature sign | | headerVersion | string | Version | 请求头参数名,headers['Version'] |

方法(主要使用init, sign, getHeaders)

| 方法 | 可通过init()方法设置 | 说明 | | ----------------------------- | ---------------------- | ----------------------- | | init(object) | - | 设置参数值 | | setMethod(string) | 是 | 设置 method | | setUri(string) | 是 | 设置 uri | | setParams(object) | 是 | 设置 params | | sign() | - | 签名 | | getHeaders() | - | 获取头部数据 | | setTimesamp(number) | - | 设置时间戳 | | setKey(string) | 是 | 设置 accessKeyId | | setSecret(string) | 是 | 设置 accessKeySecret | | setVersion(string) | 是 | 设置 version | | setAlgo(string) | 是 | 设置 algo | | setPrefix(string) | 是 | 设置 prefix | | setConnector(string) | 是 | 设置 connector | | setSuffix(string) | 是 | 设置 suffix | | setHeaderAccessKey(string) | 是 | 设置 headerAccessKey | | setHeaderTimestamp(string) | 是 | 设置 headerTimestamp | | setHeaderSignature(string) | 是 | 设置 headerSignature | | setHeaderSignatureTag(string) | 是 | 设置 headerSignatureTag | | setHeaderVersion(string) | 是 | 设置 headerVersion |

注意

# 注意:
# 1、因传递的时间为浏览器端的时间,可能错误;可提示时间错误或通过不签名接口获取服务器时间再使用设置时间戳方法