Convert python script to javascript
<pre><code>    #!/usr/bin/env python

# by carlcarl

import getopt
import sys
import hmac
import hashlib
import base64
import urllib


def formattedCmd(api, cmd):
    s = 'apiKey=' + api + '&amp;' + cmd
    return s


def encypt(string, key):
    h = hmac.new(key, string, hashlib.sha1)
  #  print '\n' + h.digest()
    return base64.b64encode(h.digest())


def formattedUrl(baseUrl, api, cmd, signature):
    url = baseUrl + '?' + formattedCmd(api, cmd) + '&amp;' + urllib.urlencode({'signature': signature})
    return url


def main():
    print 'ffffffffffffffffffffffffff'
    try:
        print getopt.getopt(sys.argv[1:], 'u:a:s:', ['help', 'output='])
        opts, args = getopt.getopt(sys.argv[1:], 'u:a:s:', ['help', 'output='])
        print opts, args,'print'
    except getopt.GetoptError, err:
        print str(err)
        sys.exit(2)

    baseUrl = 'http://10.176.14.26:8080/client/api'
    cmd = 'command=listZones'
    api = 'Qo9Qwfatwz9ARB328Btn9PftzL2Cf5LOWd8OFyJmiM513tpTIm-zKxJoWkWqf353Df397xcLdKXGk8_JO8nM3Q'
    secret = '-kgkBuBUrGFeIC4gUvngSK_3Ypmi7fuF8XdVXIusnyyiEP2YUcG3FnPUGJGy3rp3Bw5ZNnqgS-9tIfyV1QnK1g'

    for o, a in opts:
        if o == '-u':
            cmd = a
        elif o == '-a':
            api = a
        elif o == '-s':
            secret = a
        else:
            assert False, 'unhandled option'

    newCmd = formattedCmd(api, cmd).lower()
    signature = encypt(newCmd, secret)
    url = formattedUrl(baseUrl, api, cmd, signature)

    print '\n' + url

if __name__ == '__main__':
    main()
</code></pre>

<p>This is a script which is creating sample signature, i need to use the same script in javascript.</p>

<p>I have done my project in javascript, and this is one of the major part to generate an authentication signature. I tried many script in javascript but not getting the desired output.</p>

<p>Please help me to solve the issue.</p>

<p>Thanks in advance :)</p>
