notbank
Version:
The Notbank for Node.js
22 lines (18 loc) • 490 B
text/typescript
import crypto from "crypto";
function getRandomInt(max: number): number {
return Math.floor(Math.random() * max);
}
export function getNonce(): string {
return getRandomInt(1_000_000).toString();
}
export function sign(
apiPublicKey: string,
apiSecretKey: string,
userId: string,
nonce: string
): string {
var message = nonce + userId + apiPublicKey;
const hmac256 = crypto.createHmac("sha256", apiSecretKey);
hmac256.update(message);
return hmac256.digest("hex");
}