export class Sign { xSignature: string; signatureAction: string; verb: string; errorMsj: string; valueToProcess: string; appId: string; apiSecret: string; //no es el api secret, es la credentials guid: string; requestPayload: object; uri: string; constructor(body: object, uri: string,guid:string) { this.xSignature = ""; this.signatureAction = ""; this.verb = "POST"; this.errorMsj = ""; this.valueToProcess = ""; this.appId = "e5708000-45b7-48ea-ac11-98775681e97e"; this.apiSecret = "uScGfdxh5VTLdIOx"; this.guid = guid; this.requestPayload = body; this.uri = uri; } signSHA256(valueToProcess: string) { console.log(valueToProcess) const CryptoJS = require('crypto-js'); var SHA256 = require("crypto-js/sha256"); console.log(SHA256(valueToProcess)); var base64 = CryptoJS.enc.Base64.stringify(SHA256(valueToProcess)); console.log("base64: " + base64); return base64; } tranformValueToProcess(): string { if (this.verb == "POST" || this.verb == "PUT") { var payload = JSON.parse(JSON.stringify(this.requestPayload)); this.valueToProcess = this.appId + '|' + this.guid + '|' + JSON.stringify(payload.data) + '|' + this.apiSecret; return this.valueToProcess; } else { this.valueToProcess = this.uri + this.appId + this.guid; return this.valueToProcess; } } getSignature() { this.valueToProcess = this.tranformValueToProcess(); this.xSignature = this.signSHA256(this.valueToProcess); return this.xSignature; } }