docs
evals
scenario-1
scenario-10
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
Build a utility that constructs signing keys for OAuth 1.0 authentication using different cryptographic methods.
Your task is to implement a key builder utility that creates properly formatted signing keys for OAuth 1.0 signature generation. The utility should support multiple signature methods and handle various edge cases related to secret encoding and key construction.
Implement a module that constructs signing keys for OAuth 1.0 signatures:
For HMAC-based signatures (HMAC-SHA1, HMAC-SHA256):
For RSA-based signatures:
Create a module with the following capabilities:
/**
* Constructs an HMAC signing key from consumer and token secrets.
* Both secrets are RFC 3986 encoded and concatenated with '&'.
*
* @param {string} consumerSecret - The OAuth consumer secret (empty string if undefined)
* @param {string} tokenSecret - The OAuth token secret (empty string if undefined)
* @returns {string} The constructed HMAC signing key
*/
function buildHmacKey(consumerSecret, tokenSecret) {
// IMPLEMENTATION HERE
}
/**
* Validates and prepares an RSA private key for signing.
*
* @param {string} privateKey - The RSA private key in PEM format
* @returns {string} The validated private key
* @throws {Error} If the key is not in valid PEM format
*/
function prepareRsaKey(privateKey) {
// IMPLEMENTATION HERE
}
/**
* Applies RFC 3986 percent-encoding to a string.
* This extends standard URI encoding to encode additional characters: !, *, ', (, )
*
* @param {string} str - The string to encode
* @returns {string} The RFC 3986 encoded string
*/
function encodeRfc3986(str) {
// IMPLEMENTATION HERE
}
module.exports = {
buildHmacKey,
prepareRsaKey,
encodeRfc3986
};Provides OAuth 1.0 signature generation capabilities for reference implementation patterns.