-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·41 lines (33 loc) · 1.06 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
var crypto = require('crypto');
var _voxrtc = {
username: '',
secret: '',
expires: ''
};
var Voxbone = function(opts) {
_voxrtc.username = opts.voxrtcUsername;
_voxrtc.secret = opts.voxrtcSecret;
_voxrtc.expires = opts.voxrtcExpiresInSeconds;
};
Voxbone.prototype = {
//Delivery Report constructor that passes parameters to the http sendSMSRequest request
generate: function(){
var cleanHmacDigest = function (hmac) {
while ((hmac.length % 4 != 0)) {
hmac += '=';
}
hmac = hmac.replace('/ /g', '+');
return hmac;
};
var username = _voxrtc.username;
var secret = _voxrtc.secret;
var hmac = crypto.createHmac('sha1', secret);
var expires_in_seconds = _voxrtc.expires || 300;
var expires = Math.round(Date.now()/1000) + expires_in_seconds;
var text = expires + ':' + username;
hmac.update(text);
var key = cleanHmacDigest(hmac.digest('base64'));
return '{ key: \'' + key + '\', expires: ' + expires + ', username: \'' + username + '\'}';
}
};
module.exports = Voxbone;