New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@ysfe/signature

Package Overview
Dependencies
Maintainers
4
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ysfe/signature

前端通用参数签名工具

latest
npmnpm
Version
1.0.2
Version published
Maintainers
4
Created
Source

@ysfe/signature

前端签名生成工具

前置依赖

开发指引

传送门

使用方式

  • 安装: 执行 yarn add @ysfe/signature

  • 使用:

    • 详细请参考测试用例: 传送门
    • 简单使用
     const res = signature({
         data: {
           // your params
         }
     }).toString()
    

参数说明

参数及用法, 请看 ./src 或 单测用例

| 参数 | 描述 | 类型 | 默认值 | 其他说明 | | ----------- | ------------------------------ | ----------------------------------------------------- | ------ | -------- | -------------------- | --- | --- | | data | 请求参数 | {[key:string]:any} | {} | | | suffix | 自定义后缀 (参数盐值) | string | 无 | | | sort | 是否启用排序 or 自定义排序方法 | boolean / (key1:string, key2:string)=> number / false | | | hashFactory | 签名 hash 计算方法 | 'MD5' | 'SHA1' | 'SHA256' | (str:string)=>string | MD5 | |

导出事件

参数及用法, 请看 ./src 或 单测用例

方法描述
serialize参数序列化, 生成 query 字符串
toString输出签名字符串
addToUrl将参数携带签名附加给 url

二次抽象方法 | signByStr

  • 描述: 解析 url 串, 并生成签名
  • 参数/示例:
const res = signByStr(
    'http://test.com/',
    { a: '123', c: '234' },
    { sort: true }
)

实现方案

注意事项

  • 注意参数序列化方式里面, 数组参数序列化方式为 arrayFormat: 'brackets', 如果出现问题, 变更这里或提前进行 stringify 即可

[其他说明事项]

版本说明

  • 2021-06-08 | 完成工具抽象

Keywords

signature

FAQs

Package last updated on 08 Jun 2021

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