Bearle/django-scatter-auth

Can it support desktop versions?

yzhsuper opened this issue · 8 comments

thank you for the example.
i use it on chrome app is work.
but scatter desktop(10.1.0) did not work.
how do i change it to apply to scatter desktop?

English is not my native language; please excuse typing errors.

Hello,
It seems like the API has been changed.
I'll get to it in a month or two but if you need it right now - you can check out the docs at https://get-scatter.com/docs/setting-up-for-web-apps and try to convert the js, it shouldn't be too hard, and do a pull request.

thank you so much.
I saw some source code for scatter, the desktop version just hash the data.
It has been verified to be successful.

Hi @yzhsuper, could you perform a pull request? I would love to use your fix

Hi @yzhsuper, could you perform a pull request? I would love to use your fix

before you call the 'validate_signature' function
you just need hash the data
note:

  1. the desktop version must greater 10.0.3.
  2. this way is incompatible with chrome app
    `try:
    msg = sign_data_for_desktop(random_12str, to_sign)
    is_valid = validate_signature(msg=msg, sig=signature, pubkey=pubkey)
    except InvalidSignatureException as e:
    return None

import hashlib
def sha256(encrypt_str):
sh = hashlib.sha256(encrypt_str.encode('utf-8'))
return sh.hexdigest()

def sign_data_for_desktop(data, to_sign):
"""
scatter desktop
:param to_sign:
:param data:
:return:
"""
a = sha256(to_sign)
b = sha256(data)
return '%s%s' % (a, b)`

Hi @yzhsuper, could you perform a pull request? I would love to use your fix

before you call the 'validate_signature' function
you just need hash the data
note:

1. the desktop version must greater 10.0.3.

2. this way is incompatible with chrome app
   `try:
   msg = sign_data_for_desktop(random_12str, to_sign)
   is_valid = validate_signature(msg=msg, sig=signature, pubkey=pubkey)
   except InvalidSignatureException as e:
   return None

import hashlib
def sha256(encrypt_str):
sh = hashlib.sha256(encrypt_str.encode('utf-8'))
return sh.hexdigest()

def sign_data_for_desktop(data, to_sign):
"""
scatter desktop
:param to_sign:
:param data:
:return:
"""
a = sha256(to_sign)
b = sha256(data)
return '%s%s' % (a, b)`

I tried this, but it isn't working

def validate_signature(msg, sig, pubkey):
    random_12str = str(randint(10**(12-1), (10**12)-1))
    msg = sign_data_for_desktop('5'*12, sig)

    key_type, key_string = signature_from_string(sig)
    key = check_decode(key_string, key_type)
    r, s, i = signature_from_buffer(key)
    pub_key_point = point_decode_from(ecdsa_curve.secp256k1, check_decode(pubkey[3:]))

    res = ecdsa.verify((r, s), msg, pub_key_point, ecdsa_curve.secp256k1)
    print(res)
    if res is None:
        raise InvalidSignatureException

    return res

res is False, and not even None

Note that I have a randomiser for the 12 digits, I am using '5'*12 to make debugging easier.

The random_12str is Generated by page

<script src="https://cdn.scattercdn.com/file/scatter-cdn/js/latest/scatterjs-core.min.js"></script>
function random12() {

        var arr = [];
        for (var i = 0; i < 12; i++) {
            var num = Math.random() * 9;
            num = parseInt(num, 10);
            arr.push(num);
        }
        return arr.join('');
    }

function web_login() {
        // if (window.is_login) return true;
        var sign_data = random12();
        console.log(sign_data);
        var toSign = 'xxxxxx';
        toSign = scatter_core.identity.accounts[0].name;
        console.log(toSign);
        console.log(scatter_core.identity.publicKey);

        scatter_core.authenticate(sign_data, toSign)
            .then(res => {
                $.post('xxxx', {
                    'sign': res,
                    'public_key': scatter_core.identity.publicKey,
                    'name': scatter_core.identity.accounts[0].name,
                    'sign_data': sign_data,
                    'to_sign': toSign
                 }, function (data) {
                    console.log(data);
                 });
            }).catch(err => {
            	console.log('err', err);
        });
    }

then you try

Can you share your project with us? Pull request maybe?

What is the purpose of var toSign = 'xxxxxx'; and the string inside $.post('xxxx', ...)

Can you share your project with us? Pull request maybe?

What is the purpose of var toSign = 'xxxxxx'; and the string inside $.post('xxxx', ...)

i create a new demo
https://github.com/yzhsuper/django-scatter
you can see the whole process