lib/WixConnect.js
function(instance, secret, validator) {
        // spilt the instance into signature and data

        if (instance === null || typeof secret !== 'string' || instance.split('.').length !== 2) {
            throw {
                name: "WixSignatureException",
                message: "Missing instance or secret key"
            }
        }
        var pair = instance.split('.');
        var signature = new Buffer(pair[0], 'base64');
        // sign the data using hmac-sha1-256
        var data = pair[1];
        var newSignature = signData(secret, data);

        if (toBase64Safe(signature) !== newSignature.toString()) {
            throw {
                name: "WixSignatureException",
                message: "Signatures do not match, requester is most likely not Wix"
            };
        }
        var jsonData = JSON.parse(new Buffer(fromBase64Safe(data), 'base64').toString('utf8'));

        if (typeof validator !== 'function') {
            validator = function (date) {
                return (Date.now() - date.getTime()) <= (1000 * 60 * 60 * 24 * 2); // 2 days
            };
        }
        if (validator(new Date(jsonData.signDate))) {
            return jsonData;
        }
        throw {
            name: "WixSignatureException",
            message: "Signatures date has expired"
        };
    }
function(instance, secret, validator) {
        // spilt the instance into signature and data

        if (instance === null || typeof secret !== 'string' || instance.split('.').length !== 2) {
            throw {
                name: "WixSignatureException",
                message: "Missing instance or secret key"
            }
        }
        var pair = instance.split('.');
        var signature = new Buffer(pair[0], 'base64');
        // sign the data using hmac-sha1-256
        var data = pair[1];
        var newSignature = signData(secret, data);

        if (toBase64Safe(signature) !== newSignature.toString()) {
            throw {
                name: "WixSignatureException",
                message: "Signatures do not match, requester is most likely not Wix"
            };
        }
        var jsonData = JSON.parse(new Buffer(fromBase64Safe(data), 'base64').toString('utf8'));

        if (typeof validator !== 'function') {
            validator = function (date) {
                return (Date.now() - date.getTime()) <= (1000 * 60 * 60 * 24 * 2); // 2 days
            };
        }
        if (validator(new Date(jsonData.signDate))) {
            return jsonData;
        }
        throw {
            name: "WixSignatureException",
            message: "Signatures date has expired"
        };
    }
function ( instance , secret , validator ) { // spilt the instance into signature and data if ( instance === null || typeof secret !== 'string' || instance . split ( '.' ) . length !== 2 ) { throw { name : "WixSignatureException" , message : "Missing instance or secret key" } } var pair = instance . split ( '.' ) ; var signature = new Buffer ( pair [ 0 ] , 'base64' ) ; // sign the data using hmac-sha1-256 var data = pair [ 1 ] ; var newSignature = signData ( secret , data ) ; if ( toBase64Safe ( signature ) !== newSignature . toString ( ) ) { throw { name : "WixSignatureException" , message : "Signatures do not match, requester is most likely not Wix" } ; } var jsonData = JSON . parse ( new Buffer ( fromBase64Safe ( data ) , 'base64' ) . toString ( 'utf8' ) ) ; if ( typeof validator !== 'function' ) { validator = function ( date ) { return ( Date . now ( ) - date . getTime ( ) ) <= ( 1000 * 60 * 60 * 24 * 2 ) ; // 2 days } ; } if ( validator ( new Date ( jsonData . signDate ) ) ) { return jsonData ; } throw { name : "WixSignatureException" , message : "Signatures date has expired" } ; }
Parses a Wix instance and verifies the data.  Either returns an object or throws an exception
@static
@param {string} instance - the instance parameter sent by Wix
@param {string} secret - your application's secret key
@param {?module:Wix/Connect~WixDateValidator} validator - an optional data validator
@returns {module:Wix/Connect.WixInstanceData} - a JSON object containing information from Wix about the requester
@throws an exception if signatures don't match
Parses a Wix instance and verifies the data . Either returns an object or throws an exception