signer.d.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /// <reference types="node" />
  2. export declare const signedParamsSeparator = ";";
  3. interface IKV {
  4. [key: string]: any;
  5. }
  6. interface ICredential {
  7. secretId: string;
  8. secretKey: string;
  9. }
  10. interface ISignerOptions {
  11. allowSignBuffer?: boolean;
  12. }
  13. export declare class Signer {
  14. private credential;
  15. private service;
  16. private algorithm;
  17. private options;
  18. constructor(credential: ICredential, service: string, options?: ISignerOptions);
  19. static camSafeUrlEncode(str: any): string;
  20. /**
  21. * 将一个对象处理成 KeyValue 形式,嵌套的对象将会被处理成字符串,Key转换成小写字母
  22. * @param {Object} obj - 待处理的对象
  23. * @param {Object} options
  24. * @param {Boolean} options.enableBuffer
  25. */
  26. static formatKeyAndValue(obj: any, options?: {
  27. multipart?: boolean;
  28. enableValueToLowerCase?: boolean;
  29. selectedKeys?: string[];
  30. filter?: Function;
  31. }): any;
  32. static calcParamsHash(params: any, keys?: null | string[], options?: any): string;
  33. /**
  34. * 计算签名信息
  35. * @param {string} method - Http Verb:GET/get POST/post 区分大小写
  36. * @param {string} url - 地址:http://abc.org/api/v1?a=1&b=2
  37. * @param {Object} headers - 需要签名的头部字段
  38. * @param {string} params - 请求参数
  39. * @param {number} [timestamp] - 签名时间戳
  40. * @param {object} [options] - 可选参数
  41. */
  42. tc3sign(method: string, url: string, headers: IKV, params: IKV | string, timestamp: number, options?: {
  43. enableHostCheck?: boolean;
  44. enableContentTypeCheck?: boolean;
  45. withSignedParams?: boolean;
  46. }): {
  47. authorization: string;
  48. signedParams: string[];
  49. signedHeaders: string[];
  50. signature: string | Buffer;
  51. timestamp: number;
  52. multipart: any;
  53. };
  54. }
  55. export {};