-
-
Save WyohKnott/151edcc3e6c53679aacf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function signatureMethod (consumerSecret, tokenSecret, signatureBaseString) { | |
var encoder = new TextEncoder('utf-8'); | |
var passphrase; | |
consumerSecret = consumerSecret; | |
tokenSecret = tokenSecret || ''; | |
passphrase = consumerSecret + '&' + tokenSecret; | |
return crypto.subtle.importKey( | |
"raw", | |
encoder.encode(passphrase), | |
{ | |
name: "HMAC", | |
hash: { | |
name: "SHA-1" | |
} | |
}, | |
false, | |
["sign", "verify"] | |
).then(function (key) { | |
return crypto.subtle.sign( | |
{ | |
name: "HMAC" | |
}, | |
key, | |
encoder.encode(signatureBaseString) | |
); | |
}).then(function (signature) { | |
var result = []; | |
(new Uint8Array(signature)).forEach(function (char) { | |
result.push(String.fromCharCode(char)); | |
}); | |
return result.join(''); | |
}).catch(function (err) { | |
console.error('Could not sign: ', err); | |
}); | |
} | |
signatureMethod("blah blah blah", "something", "long signature string to") | |
.then((response) => console.log("sign", response)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment