Skip to content

feat: updating coordinate examples on js and rust#41

Open
sucildossj wants to merge 1 commit intocryptoquick:p2qrhfrom
sucildossj:p2qrh-coordinate
Open

feat: updating coordinate examples on js and rust#41
sucildossj wants to merge 1 commit intocryptoquick:p2qrhfrom
sucildossj:p2qrh-coordinate

Conversation

@sucildossj
Copy link

-- js example package with test run
-- rust example package with test run

@EthanHeilman EthanHeilman force-pushed the p2qrh branch 9 times, most recently from 90b90a2 to 2a041bf Compare February 10, 2026 17:37
@mufasacubana8-pixel
Copy link

import sha256 from 'crypto-js/sha256';
import hmacSHA512 from 'crypto-js/hmac-sha512';
import Base64 from 'crypto-js/enc-base64';

const message, nonce, path, privateKey; // ...
const hashDigest = sha256(nonce + message);
const hmacDigest = Base64.stringify(hmacSHA512(path + hashDigest, privateKey));
const crypto = require("crypto-js");

var AES = require("crypto-js/aes");
var SHA256 = require("crypto-js/sha256");
...
console.log(SHA256("Message"));

var CryptoJS = require("crypto-js");

// Encrypt
var ciphertext = CryptoJS.AES.encrypt('my message', 'secret key 123').toString();

// Decrypt
var bytes = CryptoJS.AES.decrypt(ciphertext, 'secret key 123');
var originalText = bytes.toString(CryptoJS.enc.Utf8);

console.log(originalText); //

var CryptoJS = require("crypto-js");

var data = [{id: 1}, {id: 2}]

// Encrypt
var ciphertext = CryptoJS.AES.encrypt(JSON.stringify(data), 'secret key 123').toString();

// Decrypt
var bytes = CryptoJS.AES.decrypt(ciphertext, 'secret key 123');
var decryptedData = JSON.parse(bytes.toString(CryptoJS.enc.Utf8));

console.log(decryptedData); //

const signRequest = (request_body, api_key, secret) => {
const { id, method, params, nonce } = request_body;

function isObject(obj) { return obj !== undefined && obj !== null && obj.constructor == Object; }
function isArray(obj) { return obj !== undefined && obj !== null && obj.constructor == Array; }
function arrayToString(obj) { return obj.reduce((a,b) => { return a + (isObject(b) ? objectToString(b) : (isArray(b) ? arrayToString(b) : b)); }, ""); }
function objectToString(obj) { return (obj == null ? "" : Object.keys(obj).sort().reduce((a, b) => { return a + b + (isArray(obj[b]) ? arrayToString(obj[b]) : (isObject(obj[b]) ? objectToString(obj[b]) : obj[b])); }, "")); }

const paramsString = objectToString(params);

console.log(paramsString);

const sigPayload = method + id + api_key + paramsString + nonce;
request_body.sig = crypto.HmacSHA256(sigPayload, secret).toString(crypto.enc.Hex);
};

const apiKey = "token"; /* User API Key /
const apiSecret = "secretKey"; /
User API Secret */

let request = {
id: 11,
method: "private/get-order-detail",
api_key: o46Xt8gLahMJz2HVwRrl3bAVj+urgtJoTvV/Nk2bFdZdJQRtruIqqw, extends 0x47b21c2b883b353ba25c0809b752ebe5ad0e7b84,
params: {
order_id: 53287421324
},
nonce: 1587846358253,
};

const requestBody = JSON.stringify(signRequest(request, apiKey, apiSecret)));
else
const request = {
id: 11,
method: "private/get-order-detail",
api_key: "your_actual_api_key_here", // Removed the 'extends...' text
params: {
order_id: 53287421324
},
nonce: Date.now() // Usually, nonces need to be a current timestamp
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants