@yeepay/yop-typescript-sdk
Version:
TypeScript SDK for interacting with YOP (YeePay Open Platform)
81 lines (80 loc) • 3 kB
TypeScript
import { AuthHeaderOptions } from './types.js';
export declare class RsaV3Util {
static formatDate(date: Date, fmt: string): string;
/**
* Gets authentication headers for API requests
* @param options - Options for generating auth headers
* @returns Authentication headers
*/
static getAuthHeaders(options: AuthHeaderOptions): Record<string, string>;
/**
* Builds the canonical header string and the list of signed header names.
* Includes 'content-type' (if present) and all 'x-yop-*' headers.
* @param headersToSign - Headers potentially included in the signature.
* @returns An object containing the canonical header string and the signed headers string.
*/
static buildCanonicalHeaders(headersToSign: Record<string, string>): {
canonicalHeaderString: string;
signedHeadersString: string;
};
/**
* Gets canonical query string for API requests
* @param params - Request parameters
* @param method - HTTP method
* @returns Canonical query string
*/
static getCanonicalQueryString(params: Record<string, unknown>, method: string): string;
/**
* Gets canonical headers for API requests
* @param headers - Request headers
* @returns Canonical headers string
*/
/**
* Generates a UUID
* @returns UUID string
*/
static uuid(): string;
/**
* Gets canonical parameters string
* @param params - Request parameters
* @returns Canonical parameters string
*/
static getCanonicalParams(params?: Record<string, unknown>): string;
/**
* Calculates SHA256 hash and returns hex string
* @param params - Request parameters
* @param config - Configuration options
* @param method - HTTP method
* @returns SHA256 hash as hex string
*/
/**
* 对对象的键进行排序,以确保生成一致的 JSON 字符串
* @param obj - 要排序的对象
* @returns 排序后的对象
*/
private static sortObjectKeys;
/**
* Calculates SHA256 hash and returns hex string
* @param params - Request parameters
* @param config - Configuration options
* @param method - HTTP method
* @returns SHA256 hash as hex string
*/
static getSha256AndHexStr(params: Record<string, unknown>, config: {
contentType: string;
}, method: string): string;
/**
* Signs a canonical request string using RSA-SHA256
* @param canonicalRequest - The canonical request string to sign
* @param appPrivateKey - The private key to sign with (PEM format or raw)
* @returns Base64 URL-safe signature with $SHA256 suffix
*/
static sign(canonicalRequest: string, appPrivateKey: string): string;
/**
* Formats a raw private key string into PEM format
* @param rawKey - The raw private key string
* @returns Formatted PEM private key
*/
private static formatPrivateKey;
}
export default RsaV3Util;