Skip to content

Commit

Permalink
Add js files to output
Browse files Browse the repository at this point in the history
  • Loading branch information
perfectmak committed Jun 24, 2019
1 parent 5b6a57e commit 6dc45f7
Show file tree
Hide file tree
Showing 10 changed files with 223 additions and 866 deletions.
25 changes: 21 additions & 4 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Libra Core

Libra Core is a javascript library client that can be used to interact to the libra nodes.
Libra Core [js] is a javascript library client that can be used to interact with libra nodes.

> This is still under heavy development and testing, so not ready yet
The end goal is to make it usable both in node and on browser clients too, but currently it is mostly compatible with node.

## Installation
To install with npm run:

Expand All @@ -24,15 +26,21 @@ import { LibraWallet, LibraClient } from 'libra-core';
In order to create a libra account, you would need to instantiate the `LibraWallet` like:

```javascript
import { LibraWallet } from 'libra-core';
import { LibraWallet, Account as LibraAccount } from 'libra-core';

// please don't use this mnemonic outside of this sample code
const wallet = new LibraWallet({
mnemonic: 'upgrade salt toy stable drop paddle'
});

// generate a new account
const account = wallet.newAccount();

// or if you have your secret key you can create an account from it
// const secretKey = 'pub-hex-secret-key-here'
// const account = LibraAccount.fromSecretKey(secretKey);


// you can see your address by:
console.log(account.getAddress().toHex());
```
Expand All @@ -51,7 +59,7 @@ async function main() {
const account = wallet.newAccount();

// mint 2 libracoins to users accounts
await client.mintWithFaucetService(account.getAddress(), 20e6)
await client.mintWithFaucetService(account.getAddress(), 20e6);
}

await main();
Expand All @@ -68,7 +76,7 @@ async function main() {
const accountState = await client.getAccountState(accountsAddress);

// log account balance
console.log(accountState.balance.toString())
console.log(accountState.balance.toString());

// Account state has other information that you could be interested in such as `sequenceNumber`.
}
Expand All @@ -85,5 +93,14 @@ You are welcome to help contribute to making this work.
You will eventually be able to transfer libra coins from your account to another account using `client.execute()` function, but it is also still a work in progress.
You are welcome to help contribute to making this work as well.

## Development
- Clone the repository
- Run `npm install` to install the dependency
- Test with `npm test`
- You might need to run `npm install -g grpc-tools` if you want to regenerate protobuffer classes

## Contribution
Feel free to contribute by opening issues or PR's to this repository

## License
MIT
2 changes: 1 addition & 1 deletion generate-proto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ grpc_tools_node_protoc \
${FILE_PATHS}

# Generate TypeScript definitions
grpc_tools_node_protoc \
protoc \
--plugin=protoc-gen-ts=./node_modules/.bin/protoc-gen-ts \
--ts_out=${GEN_OUT_DIR} \
-I ${PROTO_IMPORT_DIR} \
Expand Down
1 change: 0 additions & 1 deletion lib/Transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ interface LibraGasConstraint {
}

export class LibraTransaction {

public static createTransfer(receipientAddress: string, numAccount: BigNumber): LibraTransaction {
throw new Error('Method not implemented. Still working on compiling and encoding programs');
}
Expand Down
1 change: 0 additions & 1 deletion lib/crypto/Eddsa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { eddsa as Eddsa } from 'elliptic';
export type Signature = Uint8Array;

export class KeyPair {

public static fromSecretKey(secretKey: Uint8Array): KeyPair {
const eddsa = new Eddsa('ed25519');
const eddsaPair = eddsa.keyFromSecret(Buffer.from(secretKey));
Expand Down
1 change: 0 additions & 1 deletion lib/protobufjs.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion lib/wallet/KeyFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { Mnemonic } from './Mnemonic';
*
*/
export class Seed {

public static fromMnemonic(words: string[] | Mnemonic, salt: string = 'LIBRA'): Seed {
const mnemonic: Mnemonic = Array.isArray(words) ? new Mnemonic(words) : words;
const mnemonicBytes = mnemonic.toBytes();
Expand Down
11 changes: 7 additions & 4 deletions lib/wallet/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export type AccountStates = AccountState[];
*
*/
export class AccountState {

/**
* Returns an empty AccountState
*/
Expand Down Expand Up @@ -61,10 +60,15 @@ export class AccountState {
}

export class Account {
public static fromSecretKeyBytes(secretKeyBytes: Uint8Array): Account {
return new Account(KeyPair.fromSecretKey(secretKeyBytes));
}

public static fromSecretKey(secretKey: Uint8Array): Account {
return new Account(KeyPair.fromSecretKey(secretKey));
public static fromSecretKey(secretKeyHex: string): Account {
const keyBytes = new Uint8Array(Buffer.from(secretKeyHex, 'hex'));
return Account.fromSecretKeyBytes(keyBytes);
}

public readonly keyPair: KeyPair;
private address?: AccountAddress;

Expand All @@ -89,7 +93,6 @@ export class Account {
*
*/
export class AccountAddress {

public static isValidString(addressHex: string): boolean {
const length = String(addressHex).replace(' ', '').length;
return length === Addresses.AddressLength * 2;
Expand Down
Loading

0 comments on commit 6dc45f7

Please sign in to comment.