Problems with Signing in Javascript or Verifying in Python

in steemhelp •  3 months ago

I sign transactions and then I am attempting to verify them in Python. When doing the signing and verifcation both on Python, things work fine. However, when signing in javascript, verification fails.

The first solution that fixes this gets 10 SBD (expires in one month).

The following is a string which describes the transaction "{"ref_block_num":2054,"ref_block_prefix":1350126288,"expiration":"2018-06-26T12:54:06","operations":[["custom_json",{"required_auths":[],"required_posting_auths":["leprechaun"],"id":"authenticate","json":"{\"session_id\":\"d87e868697b269d86d5fddf27f881868\",\"site\":\"www.steemfiles.com\",\"username\":\"leprechaun\"}"}]],"signatures":["1f01be836a7542fba7b842d3c35f0aed052452a5b0eccd22397a9a1099932a1e642dc60cb805665b9c45e6d02717ecf42b7936907fa2d6ba64c9e47d3973815224"],"extensions":[]}"

The key used to sign this was "STX7SwVD2TqJ5yRL49HvLgwq6tTTAVAKzqXSv7SWxk7Gh7GrurRmm"

The python is a CGI script. Maybe there is something wrong with the signature conversion code. It's all strange to me because I used this code before in my massfollow script.

       steem.api.getDynamicGlobalProperties(function(err, globals) {
               if (err) {
                   console.log("Error: could not get global properties");
                   set_error("Could not contact RPC node", 5000);
                   //console.log("Signed transaction for login not actually working yet");
                   $scope._loginInProgress = false;
               } else {
                   let head_block_number = globals["head_block_number"] & 0xFFFF;
                   let ref_block_prefix  = parseInt(globals["head_block_id"].substring(8,16), 16);
                   let now               = new Date();
                   let expiration        = new Date(now.getTime() + 10000);
                   let custom_account_association_transaction = {
                   'ref_block_num': head_block_number, 
                   'ref_block_prefix': ref_block_prefix, 
                   'expiration': expiration.toISOString().split('.')[0], 
                   'operations': [
                       ['custom_json', 
                               {   
                                   'required_auths': [], 
                                   'required_posting_auths': [$scope.username], 
                                   'id': 'authenticate',
                                   'json': JSON.stringify({
                                           session_id: getCookie('session'),
                                           site: 'www.steemfiles.com',
                                           username: $scope.username                      
                                   })
                               }
                           ]
                   ],
                   'signatures': [],
                   'extensions': [], 
                   };
                   
                   steem.auth.signTransaction(custom_account_association_transaction,  [private_signing_key]);
                   var signatures = custom_account_association_transaction['signatures'];
                   // Convert signature into a format that pysteem uses.
                   for (i = 0; i < signatures.length; ++i) {
                       let signature = signatures[i];
                       let s = '';
                       let h;
                       for (j = 0; j < signature.length; ++j) {
                           h = signature[j].toString(16);
                           if (h.length < 2) {
                               h = '0' + h;
                           }
                           s += h;
                       }
                       signatures[i] = s;
                   }
                   
                   custom_account_association_transaction['signatures'] = signatures;
                   console.log(custom_account_association_transaction); 
                   $http({
                           url: 'http://localhost/cgi-bin/loginajax.cgi',
                           method: 'POST',
                           headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
                           data: 'username=' + encodeURIComponent($scope.username) +  '&session=' + encodeURIComponent(getCookie('session')) +
                           '&public_key=' + encodeURIComponent(public_signing_key) +
                           '&association_transaction=' + encodeURIComponent(JSON.stringify(custom_account_association_transaction))
                   }).success(login_succeeded).error(function (data, status, headers, config) {
                       failure_routine("connection error: could not contact steemfiles server");
                   });
                   
               } // if err or !err
                
               
       });
Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

I've never tried the steem.auth.signTransaction() method but I saw in some other article that the private key you pass as a parameter should be an object in the form of {posting: wif} maybe you were simply passing a string?

·

Yes, I was passing a string.

·
·
·
·
·

Thanks for your help in this matter. You went out of your way.

·
·

and apparently dsteem is faster than steem.js at signing