Skip to content

Commit

Permalink
feat 整合个人后台测试工具包
Browse files Browse the repository at this point in the history
  • Loading branch information
webkubor committed Oct 31, 2023
1 parent 4478f37 commit 55fe04a
Show file tree
Hide file tree
Showing 25 changed files with 238 additions and 197 deletions.
27 changes: 0 additions & 27 deletions aes.js

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
110 changes: 110 additions & 0 deletions api/signer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import {ec as EC} from 'elliptic';
var sha256 = require("sha256");

export abstract class Signer {
abstract sign(message: string): string;

abstract getPublicKey(): string;
}



export class LocalSigner implements Signer {
private readonly privKey: string;

constructor(privKey: string) {
this.privKey = privKey;
}

/**
* sign message
* @param message
*/
public sign = (message: string) => {
let privateKey = Buffer.from(this.privKey, 'hex');
const secp256k1 = new EC('secp256k1');
console.log('sha256加密前', message)
const Msg = sha256.x2(message);
console.log('sha256x2加密后', Msg)
let sig = secp256k1.sign(Buffer.from(Msg, 'hex'), privateKey);
console.log(sig, "sig")
return sig.toDER("hex")
};

public sign1 = (message: string) => {
const privateKey = Buffer.from(this.privKey, 'hex');
const secp256k1 = new EC('secp256k1');
const messageBytes = Buffer.from(message, 'utf-8');
const Msg = sha256.x2(messageBytes);
let sig = secp256k1.sign(Buffer.from(Msg, 'hex'), privateKey);
return sig.toDER("hex");
};

public verifySignature = (content: string, sig: string, pub: string): boolean => {
const secp256k1 = new EC('secp256k1');

// 将签名解析为r和s值
const signature = secp256k1.signatureFromDER(Buffer.from(sig, 'hex'));

// 将消息哈希和公钥转换为Buffer
const messageHash = sha256.x2(content);
const publicKey = Buffer.from(pub, 'hex');

// 使用公钥验证签名
return secp256k1.verify(Buffer.from(messageHash, 'hex'), signature, publicKey);
};

/***
* verify signature
* @param content
* @param sig
* @param pub
*/
public static verifyEccSignature = (content: string, sig: string, pub: string): boolean => {
const secp256k1 = new EC('secp256k1');
return secp256k1.verify(
Buffer.from(sha256.x2(content), 'hex'),
Buffer.from(sig, "hex"),
Buffer.from(pub, 'hex'));
};

/***
* generate new secp256k1 key pair
*/
public static newKeyPair = () => {
const ec = new EC('secp256k1');
let key = ec.genKeyPair();

return {
privKey: key.getPrivate('hex'),
pubKey: key.getPublic(true, 'hex'),
}
};

public getPublicKey = () => {
const secp256k1 = new EC('secp256k1');
let privateKey = Buffer.from(this.privKey, 'hex');
let keyPair = secp256k1.keyFromPrivate(privateKey);
return keyPair.getPublic().encodeCompressed('hex')
}
}




const signer = new LocalSigner("515eadf3e4b56219c8eed116ea3a3ec9f8645c7504c4edb1bc67bc2000f4425c");
// const message0 = "POST|/api/payOut/unifiedOrder|1694074594933|accountTax=112233445566778&amount=10&bankName=PIX_EMAIL&currency=BRA&customerAccountNumber=cvsggsasasjahsjjashc783137913139@gmail.com&customerContact=41988789227&customerEmail=tar0987321@gmail.com&customerName=OODS12&mchNo=M1693644864&mchOrderNo=SA169338446718010310001703608150&notifyUrl=http://b.aabbcc22.xyz:8010/org/org_notify/65&wayCode=PIX";
// const message1 = "POST|/api/payOut/unifiedOrder|1694074594933|accountTax=112233445566778&amount=10&bankName=PIX_EMAIL&currency=BRA&customerAccountNumber=cvsggsasasjahsjjashc783137913139@gmail.com&customerContact=41988789227&customerEmail=tar0987321@gmail.com&customerName=SÉRNHG OODS12&mchNo=M1693644864&mchOrderNo=SA169338446718010310001703608150&notifyUrl=http://b.aabbcc22.xyz:8010/org/org_notify/65&wayCode=PIX";
// const signedMessage = signer.sign(message0);
const customerName = 'customerName=SÉRNHG OODS12'
const signedMessage = signer.sign1(customerName);
// const isValid = signer.verifySignature(customerName, signedMessage, '0353bff99033789d833fe369748e27831b142568b3d879263276290b961c93957c');

// if (isValid) {
// console.log("Signature is valid.");
// } else {
// console.log("Signature is invalid.");
// }


console.log("Signed message:", signedMessage);
File renamed without changes.
34 changes: 0 additions & 34 deletions api/webhook.js

This file was deleted.

42 changes: 42 additions & 0 deletions color/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@


export enum Color {
BrightRed = "\x1b[31m",
DarkRed = "\x1b[91m",
RedBackground = "\x1b[41m",
BrightGreen = "\x1b[32m",
DarkGreen = "\x1b[92m",
GreenBackground = "\x1b[42m",
BrightYellow = "\x1b[33m",
DarkYellow = "\x1b[93m",
YellowBackground = "\x1b[43m",
BrightBlue = "\x1b[34m",
DarkBlue = "\x1b[94m",
BlueBackground = "\x1b[44m",
BrightPurple = "\x1b[35m",
DarkPurple = "\x1b[95m",
PurpleBackground = "\x1b[45m",
BrightCyan = "\x1b[36m",
DarkCyan = "\x1b[96m",
CyanBackground = "\x1b[46m",
BrightWhite = "\x1b[37m",
DarkWhite = "\x1b[97m",
WhiteBackground = "\x1b[47m",
Reset = "\x1b[0m",
BrightMagenta = "\x1b[95m", // 亮品红色
DarkMagenta = "\x1b[35m", // 深品红色
MagentaBackground = "\x1b[45m", // 品红色背景
BrightYellowGreen = "\x1b[93m", // 亮黄绿色
DarkYellowGreen = "\x1b[33m", // 深黄绿色
YellowGreenBackground = "\x1b[43m" // 黄绿色背景
}

export function coloredLog(message: string, color: string): void {
const colorCode = color;
if (colorCode) {
console.log(colorCode + message + Color.Reset);
} else {
console.error("Unsupported color:", color);
}
}

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"main": "index.js",
"scripts": {
"index": "node index",
"short": "node shortPicture",
"webhook": "node ./api/webhook"
"short": "node ./short/index.ts",
"webhook": "ts-node ./webhooks/yuque"
},
"keywords": [
"screenshot",
Expand All @@ -24,9 +24,11 @@
"flyio": "^0.6.14",
"nodemon": "^2.0.4",
"puppeteer": "^19.7.1",
"typescript": "^5.2.2",
"xlsx": "^0.16.6"
},
"devDependencies": {
"@types/node": "^20.8.9",
"axios": "^1.3.3",
"cheerio": "^1.0.0-rc.12"
}
Expand Down
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
98 changes: 0 additions & 98 deletions test/fileSteam.js

This file was deleted.

36 changes: 0 additions & 36 deletions test/time.js

This file was deleted.

Loading

0 comments on commit 55fe04a

Please sign in to comment.