Skip to content

Conversation

@netoneko
Copy link
Contributor

@netoneko netoneko commented Sep 11, 2019

Before:

const sender = Orbs.createAccount();
const receiver = Orbs.createAccount();
const orbsClient = new Orbs.Client(endpoint, virtualChainId, "TEST_NET");

const [tx, txId] = orbsClient.createTransaction(
  sender.publicKey, sender.privateKey, // removed in 2.0
  "BenchmarkToken", "transfer", 
  [Orbs.argUint64(10), Orbs.argAddress(receiver.address)]);

const query = orbsClient.createQuery(sender.publicKey, 
"BenchmarkToken", "getBalance", 
[Orbs.argAddress(receiver.address)]);

After:

const sender = Orbs.createAccount();
const receiver = Orbs.createAccount();
const senderClient = new Orbs.Client(endpoint, virtualChainId, "TEST_NET", 
  new Orbs.DefaultSigner(sender)); // added in 2.0

const [tx, txId] = await senderClient.createTransaction("BenchmarkToken", "transfer", 
  [Orbs.argUint64(10), Orbs.argAddress(receiver.address)]); // became async in 2.0

const query = await senderClient.createQuery("BenchmarkToken", "getBalance", 
  [Orbs.argAddress(receiver.address)]); // became async in 2.0

Notice that references to publicKey and privateKey were removed and instead you have to pass new DefaultSigner({publicKey, privateKey}) which encapsulates signing.

The purpose of this change is to be able to inject the signer from the outside without exposing the keys, a step forward to implementing a wallet like Metamask.

@netoneko netoneko changed the title Introduce Signer interface for key management [WIP] Introduce Signer interface for key management Sep 11, 2019
@netoneko netoneko force-pushed the feature/introduce-providers branch from 91fdb64 to ffc1246 Compare September 11, 2019 12:11
@netoneko netoneko force-pushed the feature/introduce-providers branch from eed874e to 0a823c1 Compare September 19, 2019 09:59
@netoneko netoneko force-pushed the feature/introduce-providers branch from 0a823c1 to d0fc0e0 Compare September 19, 2019 10:02
@netoneko netoneko changed the title [WIP] Introduce Signer interface for key management Introduce Signer interface for key management (breaking changes, moving to SDK 2.0) Sep 24, 2019
@electricmonk
Copy link
Contributor

My only qualm is around the DefaultSigner name - can we name it LocalSigner instead? or a different name that reflects what distinguishes it from other future signers?

@netoneko netoneko requested a review from gilamran September 25, 2019 07:44
@gilamran
Copy link
Contributor

I agree with Shay, DefaultSigner is too general. I also like the LocalSigner.

@gilamran
Copy link
Contributor

The file Signature can be better described by calling it Signer instead.

@gilamran
Copy link
Contributor

I don't understand the why you erased the contracts clone, and used a local versions of it (input.json and output.json). Without the clone you might miss changes

expect(accountIdLength).toEqual(32);
});

it("should create Orbs.Client instance", async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines were just moved, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. I just moved to async/await syntax.

@netoneko
Copy link
Contributor Author

I have removed the contracts clone because it's not really compatible with the old format anymore (because keys moved to a different place in the config as they are not parameters of the calls anymore).

We won't miss the changes because we run this e2e against gamma, so there is no difference if the input jsons come from outside or are stored here and can be refactored.

@netoneko
Copy link
Contributor Author

I believe I have resolved all the issues.

@gilamran
Copy link
Contributor

Great job!!

@gilamran gilamran merged commit 940aab8 into master Sep 25, 2019
@netoneko netoneko deleted the feature/introduce-providers branch September 25, 2019 14:19
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

Successfully merging this pull request may close these issues.

4 participants