title: Convert Node.JS code snippet to Javascript (Google Apps Script)
body: <p>I would like to convert the following <code>Node.JS</code> code snippet to <code>JavaScript</code> in order to run it in Google Apps Script:</p>
  
  <p><strong>From: Node.JS</strong></p>
  
  <pre><code>function getMessageSignature(path, request, nonce) {
    var message   = querystring.stringify(request);
    var secret    = new Buffer(config.secret, 'base64');
    var hash  = new crypto.createHash('sha256');
    var hmac  = new crypto.createHmac('sha512', secret);
    var hash_digest   = hash.update(nonce + message).digest('binary');
    var hmac_digest   = hmac.update(path + hash_digest, 'binary').digest('base64');
    return hmac_digest;
  }
  </code></pre>
  
  <p>This is the code I have tried so far (and many variations of it):</p>
  
  <p><strong>To: JavaScript / Google Apps Script</strong></p>
  
  <pre><code>function getMessageSignature(url, request, nonce) {
  
    // Message signature using HMAC-SHA512 of (URI path + SHA256(nonce + POST data)) 
    //and base64 decoded secret API key
  
    const secretApiKey = 'wdwdKswdKKewe23edeYIvL/GsltsGWbuBXnarcxZfu/9PjFbXl5npg==';
    var secretApiKeyBytes = Utilities.base64Decode(secretApiKey);
    var blob = Utilities.newBlob(secretApiKeyBytes); 
    var secretApiKeyString = blob.getDataAsString(); // POTENTIAL ERROR HERE?
  
    var json = Utilities.jsonStringify(request); 
  
    var hash_digest = Utilities.computeDigest(Utilities.DigestAlgorithm.SHA_256, 
        nonce + json);
  
    var hmac_digest = Utilities.computeHmacSignature(Utilities.MacAlgorithm.HMAC_SHA_512, 
        url + hash_digest, secretApiKeyString); // POTENTIAL ERROR HERE?
  
    var base64 = Utilities.base64Encode(hmac_digest);
  
    return base64;
  }
  </code></pre>
  
  <p>When sending the signature as part of my request to the server, I always get the error message from the server: <code>Invalid Key</code>.</p>
  
  <p>BTW: This is the API which I would like to use in JavaScript: <a href="https://www.kraken.com/help/api#general-usage" rel="noreferrer">Kraken API</a></p>
  
  <p>I would appreciate any hint or suggestions very much!!</p>