UNPKG

@yeepay/yop-typescript-sdk

Version:

TypeScript SDK for interacting with YOP (YeePay Open Platform)

51 lines (50 loc) 2.39 kB
import crypto from 'crypto'; interface VerifyParams { data: string; sign: string; publicKey: string | Buffer | crypto.KeyObject; } interface DigitalEnvelopeResult { status: 'success' | 'failed'; result: string; message: string; } export declare class VerifyUtils { /** * Creates a KeyObject from various public key/certificate inputs. * Handles PEM Public Key blocks that actually contain certificates. * @param certOrKey - Certificate content (PEM), PEM public key (potentially containing a cert), or raw public key string/Buffer. * @returns The public key as a KeyObject. * @throws Error if input is invalid or public key cannot be extracted/created. */ static getPublicKeyObject(certOrKey: string | Buffer): crypto.KeyObject; /** * Validates RSA signature for YOP API responses. * Assumes the signature should be verified against the string representation of the 'result' field in the JSON response. * @param params - Parameters containing the full response body string (data), the signature (sign), and the public key. * @returns Whether the signature is valid. */ static isValidRsaResult(params: VerifyParams): boolean; /** * Handles digital envelope decryption * @param content - Digital envelope content * @param isv_private_key - Merchant private key * @param yop_public_key - YOP platform public key (string, Buffer, or KeyObject) * @returns Processing result */ static digital_envelope_handler(content: string, isv_private_key: string, yop_public_key: string | Buffer | crypto.KeyObject): DigitalEnvelopeResult; /** * Validates merchant notification signature (or similar signed data) * @param result - Result data string to verify * @param sign - Signature * @param public_key - Public key (string, Buffer, or KeyObject) * @returns Whether the signature is valid */ static isValidNotifyResult(result: string, sign: string, public_key: string | Buffer | crypto.KeyObject): boolean; static base64_safe_handler(data: string): string; static key_format(key: string): string; static rsaDecrypt(content: string, privateKey: string): Buffer; static aesDecrypt(encrypted: string, key: Buffer): string; static getBizResult(content: string, format?: string): string; } export default VerifyUtils;