UNPKG

fastcomments-sdk

Version:

FastComments API Client - A SDK for interacting with the FastComments API

46 lines 1.62 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SecureSSOPayloadBuilder = void 0; const crypto_1 = __importDefault(require("crypto")); /** * Handles secure SSO payload creation with HMAC-SHA256 verification */ class SecureSSOPayloadBuilder { constructor(apiKey, userData) { this.timestamp = Date.now(); // Create JSON and base64 encode it const userDataJSON = JSON.stringify(userData); this.userDataJSONBase64 = Buffer.from(userDataJSON, 'utf8').toString('base64'); // Create HMAC-SHA256 verification hash this.verificationHash = this.createVerificationHash(apiKey, this.timestamp, this.userDataJSONBase64); } /** * Creates HMAC-SHA256 verification hash */ createVerificationHash(apiKey, timestamp, userDataJSONBase64) { const hmac = crypto_1.default.createHmac('sha256', apiKey); hmac.update(timestamp + userDataJSONBase64); return hmac.digest('hex'); } /** * Gets the secure SSO payload */ getPayload() { return { userDataJSONBase64: this.userDataJSONBase64, verificationHash: this.verificationHash, timestamp: this.timestamp }; } /** * Gets the payload as a JSON string */ toJSON() { return JSON.stringify(this.getPayload()); } } exports.SecureSSOPayloadBuilder = SecureSSOPayloadBuilder; //# sourceMappingURL=SecureSSOPayload.js.map