Beispiel #1
0
    async def post(self):
        key_or_wif = self.get_secure_cookie("key_or_wif")
        if not key_or_wif and self.jwt.get('key_or_wif') != 'true':
            return self.render_as_json({'error': 'not authorized'})
        args = json.loads(self.request.body)
        if not args.get('uid'):
            return self.render_as_json({
                "error": True,
                "message": "no user account provided"
            })
        keyhash = hashlib.sha256(
            TU.generate_deterministic_signature(
                self.config, 'child_wallet').encode()).hexdigest()
        exkey = BIP32Key.fromExtendedKey(self.config.xprv)
        last_child_key = self.config.mongo.db.child_keys.find(
            {'signature': keyhash}, sort=[('inc', -1)])
        inc = last_child_key.count() + 1
        key = exkey.ChildKey(inc)
        child_key = BIP32Key.fromExtendedKey(key.ExtendedKey())
        child_key = child_key.ChildKey(inc)
        public_key = child_key.PublicKey().hex()
        address = str(
            P2PKHBitcoinAddress.from_pubkey(bytes.fromhex(public_key)))
        private_key = child_key.PrivateKey().hex()
        wif = self.to_wif(private_key)

        await self.config.mongo.async_db.child_keys.insert_one({
            'account':
            args.get('uid'),
            'inc':
            inc,
            'extended':
            child_key.ExtendedKey(),
            'public_key':
            public_key,
            'address':
            address,
            'private_key':
            private_key,
            'wif':
            wif,
            'signature':
            keyhash
        })
        return self.render_as_json({"address": address})
Beispiel #2
0
 def get_username_signature(self):
     from yadacoin.core.transactionutils import TU
     return TU.generate_deterministic_signature(self, self.username,
                                                self.private_key)