Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial wallet architecture #20

Open
netoneko opened this issue Sep 9, 2019 · 3 comments
Open

Initial wallet architecture #20

netoneko opened this issue Sep 9, 2019 · 3 comments
Assignees

Comments

@netoneko
Copy link
Contributor

netoneko commented Sep 9, 2019

TODO: outline a wallet architecture, supposedly modeled after Metamask Ethereum Provider.

The whole thing boils down to these signature calls: https://github.com/orbs-network/orbs-client-sdk-javascript/blob/master/src/crypto/Signature.ts

They should be extracted to an adapter, which would make it a 2.0 SDK.

@netoneko netoneko self-assigned this Sep 9, 2019
@netoneko
Copy link
Contributor Author

netoneko commented Sep 15, 2019

interface Signer {
  getPublicKey(): Promise<Uint8Array>;
  signEd25519(data: Uint8Array): Promise<Uint8Array>;
}

interface Account extends Signer {
  getName(): Promise<string>;
  _setName(name: string); // Private method of extension

  getDescription(): Promise<string>;
  _setDescription(name: string); // Private method of extension

  getAddress(): Promise<string>;
  isCompromised(): bool // in case we want to filter out compromised keys

  // Private method of extension
  _lockSigner(); // locks the account, disabling Signer.signEd25519 method
  _unlockSigner(); // unlocks the account, makes all the Signer methods available
}

interface Wallet() {
  async enable(): Account[];
  async addAccount({name: string, description: string, phrase?: string}); // generates a new account and sets name and description, if phrase is available then it is used to restore the private key
}

The sample flow (inspired by Metamask low level flow:

import { Wallet } from "orbs-wallet-javascript";
import { Client, argUint64 } from "orbs-client-javascript";

const wallet = new Wallet({ configOptions });
let accounts;
try {
  accounts = await wallet.enable(); // should open a separate extension window that asks for the password
} catch (e) {
  console.log("Could not initialize wallet: " + e.toString();
  throw e;
}

const account = accounts[0];
const client = new Client("http://localhost:8080", 42, account);

const query = await client.createQuery("ReadOnlyContract", "readInfo");
const queryResult = await client.runQuery(query);

console.log(queryResult.OutputArguments[0]);

const [txid, tx] = client.createTransaction("ModifyStateContract", "add", [argUint64(1)]);
const txResult = await client.SendTransaction(tx);

console.log(txResult.OutputArguments[0]);

I understand that unlocking the singer every time might be a bit of an overkill, so we should discuss if we even need this feature. Metamask does not have it.

I thought we might add it to separate read-only usecase from read-write usecase. I think it's definitely up for discussion, maybe @lbeder could give us a tip if it makes sense.

@netoneko
Copy link
Contributor Author

Updated flow after a meeting with @gilamran

@netoneko
Copy link
Contributor Author

Some basic implementation of the flow here: https://github.com/orbs-network/wallet/blob/master/firefox/test/test.js

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

No branches or pull requests

3 participants