Code Monkey home page Code Monkey logo

aleph-sdk-docs-python's People

Contributors

geraldinefiser avatar gitbook-bot avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

aliel mhhukiewitz

aleph-sdk-docs-python's Issues

[dApp] Connecting wallet and avoid having to authorize every transaction

Amrik in the Dev TG chat: (https://t.me/c/1599881637/1044)
Is it possible to connect to the network using metmask wallet?
Currently we need user's private key to sign the transaction however, I want a user to able to connect to the dapp using metmask and they can send messages to the network (a decentralized chat app) without always approving the transaction with pop up.

Hugo:
We are aware of this issue. In the future, we will add a "delegation" method so you'll be able to use multiple (sub)keys on behalf of your master key (the one holding aleph tokens).

Moshe:
In the meantime you can do this by yourself:

  • Generate a private key in the browser, use it to sign all the messenging stuff. Encrypt this private key for the user metamask decryption key
  • Write the address linked to this private key as well as the encrypted private key in the metamask address key-value store (AGGREGATE, signing a message using metamask)
  • Write the owner address on the browser-local address key-value store (AGGREGATE again, signing with the browser-local private key, no need for a popup)
  • Then do all the messenging using that browser-local address

If the users needs to reconnect:

  • Decrypt the browser-local private key using metamask (will show a popup)
  • continue as before

You can also not encrypt and store the private key if you support multiple browser-local keys (then just generate a new one on every new browser that doesn't have it in storage... even though having it encrypted neds to allow to decrypt it on every opening so no risk linked to local storage)

How to migrate a private key from aleph-client to Metamask

Article written by Gabriel:

How to use Metamask with aleph-vm

Upload your script

The first step is to generate a private key to import it on Metamask. If you already have a private key, you can jump to the next step.

So firstly you will need to upload your script, in this way a new private key will be generated in device.key at root of your repository.

This key is encrypted with the PrivateKey class of coincurve.

Retrieve private key

To recover this private key you will have to transform its content into hexadecimal.

Here is the code for achieving this

from coincurve import PrivateKey

# In case we don't want to bother with handling private key ourselves
# do an ugly and insecure write and read from disk to this file.
PRIVATE_KEY_FILE = "device.key"

def get_fallback_private_key() -> bytes:
    private_key: bytes
    try:
        with open(PRIVATE_KEY_FILE, "rb") as prvfile:
            private_key = prvfile.read()
    except OSError:
        private_key = generate_key()
        with open(PRIVATE_KEY_FILE, "wb") as prvfile:
            prvfile.write(private_key)

    return private_key

k = get_fallback_private_key()

print('your private key is', PrivateKey(k).to_hex())

You will get a printed message like your private key is b3bxxxxxxxxxxxxxxxxxx

Metamask: import private key

Get started

If you do not have Metamask, you should install the extension here , then create an account.

Import private key

Open Metamask browser extension

Capture d’écran 2021-12-03 à 13 01 25

Click on profile and import account

Capture d’écran 2021-12-03 à 13 02 51

Then copy and paste your private key from device.key

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.