Create a Deribit signature string & hashCreate GUID / UUID in JavaScript?How to check empty/undefined/null string in JavaScript?How can I convert a string to boolean in JavaScript?Creating multiline strings in JavaScriptHow can I get query string values in JavaScript?How do I make the first letter of a string uppercase in JavaScript?Sort array of objects by string property valueHow to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?What is JSONP, and why was it created?
Indicating multiple different modes of speech (fantasy language or telepathy)
Has Darkwing Duck ever met Scrooge McDuck?
Some numbers are more equivalent than others
Can the Supreme Court overturn an impeachment?
Why does Async/Await work properly when the loop is inside the async function and not the other way around?
How to align and center standalone amsmath equations?
How do ground effect vehicles perform turns?
Proving a function is onto where f(x)=|x|.
Is possible to search in vim history?
Should I install hardwood flooring or cabinets first?
Is it possible to have a strip of cold climate in the middle of a planet?
Journal losing indexing services
Divine apple island
What is this type of notehead called?
Is there a conventional notation or name for the slip angle?
Could the E-bike drivetrain wear down till needing replacement after 400 km?
How must one send away the mother bird?
Could solar power be utilized and substitute coal in the 19th Century
Flux received by a negative charge
Gibbs free energy in standard state vs. equilibrium
How much character growth crosses the line into breaking the character
How can "mimic phobia" be cured or prevented?
Greco-Roman egalitarianism
MAXDOP Settings for SQL Server 2014
Create a Deribit signature string & hash
Create GUID / UUID in JavaScript?How to check empty/undefined/null string in JavaScript?How can I convert a string to boolean in JavaScript?Creating multiline strings in JavaScriptHow can I get query string values in JavaScript?How do I make the first letter of a string uppercase in JavaScript?Sort array of objects by string property valueHow to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?What is JSONP, and why was it created?
I have been trying to connect to my account with the Deribit testnet API and I can't figure out why my code is not working.
My Apps Script test function:
function callderibit()
var key = '2YZn85siaUf5A'
var secret = 'BTMSIAJ8IYQTAV4MLN88UAHLIUNYZ3HN'
var nonce = '1452237485895' ;
var baseUrl = 'https://test.deribit.com';
var action = '/api/v1/private/account'
var string =
'_=' + nonce
+ '&_ackey=' + key
+ '&_acsec=' + secret
+ '&_action='+ action;
var hash = Utilities.computeDigest(Utilities.DigestAlgorithm.SHA_256,
string);
var hash_encoded = Utilities.base64Encode(hash);
var signature = key + '.' + nonce + '.' + hash_encoded ;
var options = 'headers': 'X-Deribit-Sig': signature
// Call the API
var response = UrlFetchApp.fetch(baseUrl + action , options )
//Parse the JSON reply
var json = response.getContentText();
var data = JSON.parse(json);
Logger.log(data);
This is the signature I am producing:
2YZn85siaUf5A.1452237485895.KOlc7ELGnz8cjYp614ONxZlngo/z2AHMEjVdlHlW9Oo=
The signature I sould be getting is this one:
2YZn85siaUf5A.1452237485895.LQctRklxPiJDHJj9ZYp78Epilx7N78crGghzr1pvNlI=
Bellow is the JS version of what I am trying to do, maybe someone can help me to translate it to gas.
Reference
let access_key = '2YZn85siaUf5A';
let secret_key = 'BTMSIAJ8IYQTAV4MLN88UAHLIUNYZ3HN';
function get_signature(action, arguments)
let nonce = (new Date()).getTime().toString();
let signatureString =
'_=' + nonce
+ '&_ackey=' + access_key
+ '&_acsec=' + secret_key
+ '&_action=' + action;
Object.keys(arguments).sort().forEach((key) =>
signatureString += "&";
signatureString += key;
signatureString += "=";
let value = arguments[key];
if (Array.isArray(value))
value = value.join('');
signatureString += value.toString();
);
let signatureStringEncoded = new TextEncoder("utf-8").encode(signatureString
);
let binaryHash = crypto.subtle.digest("SHA-256", signatureStringEncoded);
return (
access_key + "." +
nonce.toString() + "." +
btoa(binaryHash)
)
javascript google-apps-script authorization
New contributor
|
show 5 more comments
I have been trying to connect to my account with the Deribit testnet API and I can't figure out why my code is not working.
My Apps Script test function:
function callderibit()
var key = '2YZn85siaUf5A'
var secret = 'BTMSIAJ8IYQTAV4MLN88UAHLIUNYZ3HN'
var nonce = '1452237485895' ;
var baseUrl = 'https://test.deribit.com';
var action = '/api/v1/private/account'
var string =
'_=' + nonce
+ '&_ackey=' + key
+ '&_acsec=' + secret
+ '&_action='+ action;
var hash = Utilities.computeDigest(Utilities.DigestAlgorithm.SHA_256,
string);
var hash_encoded = Utilities.base64Encode(hash);
var signature = key + '.' + nonce + '.' + hash_encoded ;
var options = 'headers': 'X-Deribit-Sig': signature
// Call the API
var response = UrlFetchApp.fetch(baseUrl + action , options )
//Parse the JSON reply
var json = response.getContentText();
var data = JSON.parse(json);
Logger.log(data);
This is the signature I am producing:
2YZn85siaUf5A.1452237485895.KOlc7ELGnz8cjYp614ONxZlngo/z2AHMEjVdlHlW9Oo=
The signature I sould be getting is this one:
2YZn85siaUf5A.1452237485895.LQctRklxPiJDHJj9ZYp78Epilx7N78crGghzr1pvNlI=
Bellow is the JS version of what I am trying to do, maybe someone can help me to translate it to gas.
Reference
let access_key = '2YZn85siaUf5A';
let secret_key = 'BTMSIAJ8IYQTAV4MLN88UAHLIUNYZ3HN';
function get_signature(action, arguments)
let nonce = (new Date()).getTime().toString();
let signatureString =
'_=' + nonce
+ '&_ackey=' + access_key
+ '&_acsec=' + secret_key
+ '&_action=' + action;
Object.keys(arguments).sort().forEach((key) =>
signatureString += "&";
signatureString += key;
signatureString += "=";
let value = arguments[key];
if (Array.isArray(value))
value = value.join('');
signatureString += value.toString();
);
let signatureStringEncoded = new TextEncoder("utf-8").encode(signatureString
);
let binaryHash = crypto.subtle.digest("SHA-256", signatureStringEncoded);
return (
access_key + "." +
nonce.toString() + "." +
btoa(binaryHash)
)
javascript google-apps-script authorization
New contributor
Should'_=' + 'nonce'
be'_=' + nonce
?
– tehhowch
Mar 21 at 13:51
you are right, I changed it! but the authorization is still not successful
– Saoma
Mar 21 at 13:56
When you use the example values provided in the API docs, does your code here produce the stated signature2YZn85siaUf5A.1452237485895.LQctRklxPiJDHJj9ZYp78Epilx7N78crGghzr1pvNlI=
? If not, then you are not constructing and hashing properly.
– tehhowch
Mar 21 at 14:06
The hash dose look different, I just tried out the apiconsole and produced a bunch of signatures. I am producing a hash of a lenght of 64 instead of 58 (excluding key and nonce). Also the correct hash always has an '=' at the end.
– Saoma
Mar 21 at 14:13
I have amended the code as I saw that the hash needed to be encoded (base64). The signature I am now producing matches the ones I can get from the console, however I still dont have assess.
– Saoma
Mar 21 at 14:43
|
show 5 more comments
I have been trying to connect to my account with the Deribit testnet API and I can't figure out why my code is not working.
My Apps Script test function:
function callderibit()
var key = '2YZn85siaUf5A'
var secret = 'BTMSIAJ8IYQTAV4MLN88UAHLIUNYZ3HN'
var nonce = '1452237485895' ;
var baseUrl = 'https://test.deribit.com';
var action = '/api/v1/private/account'
var string =
'_=' + nonce
+ '&_ackey=' + key
+ '&_acsec=' + secret
+ '&_action='+ action;
var hash = Utilities.computeDigest(Utilities.DigestAlgorithm.SHA_256,
string);
var hash_encoded = Utilities.base64Encode(hash);
var signature = key + '.' + nonce + '.' + hash_encoded ;
var options = 'headers': 'X-Deribit-Sig': signature
// Call the API
var response = UrlFetchApp.fetch(baseUrl + action , options )
//Parse the JSON reply
var json = response.getContentText();
var data = JSON.parse(json);
Logger.log(data);
This is the signature I am producing:
2YZn85siaUf5A.1452237485895.KOlc7ELGnz8cjYp614ONxZlngo/z2AHMEjVdlHlW9Oo=
The signature I sould be getting is this one:
2YZn85siaUf5A.1452237485895.LQctRklxPiJDHJj9ZYp78Epilx7N78crGghzr1pvNlI=
Bellow is the JS version of what I am trying to do, maybe someone can help me to translate it to gas.
Reference
let access_key = '2YZn85siaUf5A';
let secret_key = 'BTMSIAJ8IYQTAV4MLN88UAHLIUNYZ3HN';
function get_signature(action, arguments)
let nonce = (new Date()).getTime().toString();
let signatureString =
'_=' + nonce
+ '&_ackey=' + access_key
+ '&_acsec=' + secret_key
+ '&_action=' + action;
Object.keys(arguments).sort().forEach((key) =>
signatureString += "&";
signatureString += key;
signatureString += "=";
let value = arguments[key];
if (Array.isArray(value))
value = value.join('');
signatureString += value.toString();
);
let signatureStringEncoded = new TextEncoder("utf-8").encode(signatureString
);
let binaryHash = crypto.subtle.digest("SHA-256", signatureStringEncoded);
return (
access_key + "." +
nonce.toString() + "." +
btoa(binaryHash)
)
javascript google-apps-script authorization
New contributor
I have been trying to connect to my account with the Deribit testnet API and I can't figure out why my code is not working.
My Apps Script test function:
function callderibit()
var key = '2YZn85siaUf5A'
var secret = 'BTMSIAJ8IYQTAV4MLN88UAHLIUNYZ3HN'
var nonce = '1452237485895' ;
var baseUrl = 'https://test.deribit.com';
var action = '/api/v1/private/account'
var string =
'_=' + nonce
+ '&_ackey=' + key
+ '&_acsec=' + secret
+ '&_action='+ action;
var hash = Utilities.computeDigest(Utilities.DigestAlgorithm.SHA_256,
string);
var hash_encoded = Utilities.base64Encode(hash);
var signature = key + '.' + nonce + '.' + hash_encoded ;
var options = 'headers': 'X-Deribit-Sig': signature
// Call the API
var response = UrlFetchApp.fetch(baseUrl + action , options )
//Parse the JSON reply
var json = response.getContentText();
var data = JSON.parse(json);
Logger.log(data);
This is the signature I am producing:
2YZn85siaUf5A.1452237485895.KOlc7ELGnz8cjYp614ONxZlngo/z2AHMEjVdlHlW9Oo=
The signature I sould be getting is this one:
2YZn85siaUf5A.1452237485895.LQctRklxPiJDHJj9ZYp78Epilx7N78crGghzr1pvNlI=
Bellow is the JS version of what I am trying to do, maybe someone can help me to translate it to gas.
Reference
let access_key = '2YZn85siaUf5A';
let secret_key = 'BTMSIAJ8IYQTAV4MLN88UAHLIUNYZ3HN';
function get_signature(action, arguments)
let nonce = (new Date()).getTime().toString();
let signatureString =
'_=' + nonce
+ '&_ackey=' + access_key
+ '&_acsec=' + secret_key
+ '&_action=' + action;
Object.keys(arguments).sort().forEach((key) =>
signatureString += "&";
signatureString += key;
signatureString += "=";
let value = arguments[key];
if (Array.isArray(value))
value = value.join('');
signatureString += value.toString();
);
let signatureStringEncoded = new TextEncoder("utf-8").encode(signatureString
);
let binaryHash = crypto.subtle.digest("SHA-256", signatureStringEncoded);
return (
access_key + "." +
nonce.toString() + "." +
btoa(binaryHash)
)
javascript google-apps-script authorization
javascript google-apps-script authorization
New contributor
New contributor
edited 2 days ago
Saoma
New contributor
asked Mar 21 at 13:47
SaomaSaoma
11
11
New contributor
New contributor
Should'_=' + 'nonce'
be'_=' + nonce
?
– tehhowch
Mar 21 at 13:51
you are right, I changed it! but the authorization is still not successful
– Saoma
Mar 21 at 13:56
When you use the example values provided in the API docs, does your code here produce the stated signature2YZn85siaUf5A.1452237485895.LQctRklxPiJDHJj9ZYp78Epilx7N78crGghzr1pvNlI=
? If not, then you are not constructing and hashing properly.
– tehhowch
Mar 21 at 14:06
The hash dose look different, I just tried out the apiconsole and produced a bunch of signatures. I am producing a hash of a lenght of 64 instead of 58 (excluding key and nonce). Also the correct hash always has an '=' at the end.
– Saoma
Mar 21 at 14:13
I have amended the code as I saw that the hash needed to be encoded (base64). The signature I am now producing matches the ones I can get from the console, however I still dont have assess.
– Saoma
Mar 21 at 14:43
|
show 5 more comments
Should'_=' + 'nonce'
be'_=' + nonce
?
– tehhowch
Mar 21 at 13:51
you are right, I changed it! but the authorization is still not successful
– Saoma
Mar 21 at 13:56
When you use the example values provided in the API docs, does your code here produce the stated signature2YZn85siaUf5A.1452237485895.LQctRklxPiJDHJj9ZYp78Epilx7N78crGghzr1pvNlI=
? If not, then you are not constructing and hashing properly.
– tehhowch
Mar 21 at 14:06
The hash dose look different, I just tried out the apiconsole and produced a bunch of signatures. I am producing a hash of a lenght of 64 instead of 58 (excluding key and nonce). Also the correct hash always has an '=' at the end.
– Saoma
Mar 21 at 14:13
I have amended the code as I saw that the hash needed to be encoded (base64). The signature I am now producing matches the ones I can get from the console, however I still dont have assess.
– Saoma
Mar 21 at 14:43
Should
'_=' + 'nonce'
be '_=' + nonce
?– tehhowch
Mar 21 at 13:51
Should
'_=' + 'nonce'
be '_=' + nonce
?– tehhowch
Mar 21 at 13:51
you are right, I changed it! but the authorization is still not successful
– Saoma
Mar 21 at 13:56
you are right, I changed it! but the authorization is still not successful
– Saoma
Mar 21 at 13:56
When you use the example values provided in the API docs, does your code here produce the stated signature
2YZn85siaUf5A.1452237485895.LQctRklxPiJDHJj9ZYp78Epilx7N78crGghzr1pvNlI=
? If not, then you are not constructing and hashing properly.– tehhowch
Mar 21 at 14:06
When you use the example values provided in the API docs, does your code here produce the stated signature
2YZn85siaUf5A.1452237485895.LQctRklxPiJDHJj9ZYp78Epilx7N78crGghzr1pvNlI=
? If not, then you are not constructing and hashing properly.– tehhowch
Mar 21 at 14:06
The hash dose look different, I just tried out the apiconsole and produced a bunch of signatures. I am producing a hash of a lenght of 64 instead of 58 (excluding key and nonce). Also the correct hash always has an '=' at the end.
– Saoma
Mar 21 at 14:13
The hash dose look different, I just tried out the apiconsole and produced a bunch of signatures. I am producing a hash of a lenght of 64 instead of 58 (excluding key and nonce). Also the correct hash always has an '=' at the end.
– Saoma
Mar 21 at 14:13
I have amended the code as I saw that the hash needed to be encoded (base64). The signature I am now producing matches the ones I can get from the console, however I still dont have assess.
– Saoma
Mar 21 at 14:43
I have amended the code as I saw that the hash needed to be encoded (base64). The signature I am now producing matches the ones I can get from the console, however I still dont have assess.
– Saoma
Mar 21 at 14:43
|
show 5 more comments
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Saoma is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55281911%2fcreate-a-deribit-signature-string-hash%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Saoma is a new contributor. Be nice, and check out our Code of Conduct.
Saoma is a new contributor. Be nice, and check out our Code of Conduct.
Saoma is a new contributor. Be nice, and check out our Code of Conduct.
Saoma is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55281911%2fcreate-a-deribit-signature-string-hash%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Should
'_=' + 'nonce'
be'_=' + nonce
?– tehhowch
Mar 21 at 13:51
you are right, I changed it! but the authorization is still not successful
– Saoma
Mar 21 at 13:56
When you use the example values provided in the API docs, does your code here produce the stated signature
2YZn85siaUf5A.1452237485895.LQctRklxPiJDHJj9ZYp78Epilx7N78crGghzr1pvNlI=
? If not, then you are not constructing and hashing properly.– tehhowch
Mar 21 at 14:06
The hash dose look different, I just tried out the apiconsole and produced a bunch of signatures. I am producing a hash of a lenght of 64 instead of 58 (excluding key and nonce). Also the correct hash always has an '=' at the end.
– Saoma
Mar 21 at 14:13
I have amended the code as I saw that the hash needed to be encoded (base64). The signature I am now producing matches the ones I can get from the console, however I still dont have assess.
– Saoma
Mar 21 at 14:43