From 39ec43533d2f8387c8e827fe448453cbcac7a0cd Mon Sep 17 00:00:00 2001 From: Paul Chonpimai Date: Thu, 11 Jul 2019 00:22:29 +0700 Subject: [PATCH] v0.1.2 --- package.json | 2 +- packages/libra-web-account/Wallet.ts | 13 ++++++------- packages/libra-web-core/index.ts | 26 +++++++++++++------------ packages/libra-web-transaction/index.ts | 2 +- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index 8e44696..0e99a71 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "libra-web", - "version": "0.1.0", + "version": "0.1.2", "description": "A library for connecting with libra from browser and Node.js", "main": "build/libra-web/index.js", "types": "build/libra-web/index.d.ts", diff --git a/packages/libra-web-account/Wallet.ts b/packages/libra-web-account/Wallet.ts index 54adf21..96cda13 100644 --- a/packages/libra-web-account/Wallet.ts +++ b/packages/libra-web-account/Wallet.ts @@ -3,21 +3,20 @@ import { KeyFactory, Seed } from './KeyFactory' import { Mnemonic } from './Mnemonic' export class LibraWallet { - private readonly mnemonic: string[] - private keyFactory: KeyFactory - - static create(): LibraWallet { + public static create(): LibraWallet { return new LibraWallet(new Mnemonic().toString()) } + private readonly mnemonic: string[] + private keyFactory: KeyFactory - constructor(_mnemonic: string) { - if (!_mnemonic) { + constructor(mnemonic: string) { + if (!mnemonic) { throw new Error( 'Mnemonic is required for initialing LibraWallet. Use LibraWallet.create() for creating a new one.', ) } - this.mnemonic = _mnemonic.trim().split(' ') + this.mnemonic = mnemonic.trim().split(' ') const seed = Seed.fromMnemonic(this.mnemonic, 'LIBRA') this.keyFactory = new KeyFactory(seed) } diff --git a/packages/libra-web-core/index.ts b/packages/libra-web-core/index.ts index 0ed93cc..2c09960 100644 --- a/packages/libra-web-core/index.ts +++ b/packages/libra-web-core/index.ts @@ -2,24 +2,24 @@ import axios from 'axios' import BigNumber from 'bignumber.js' import { SHA3 } from 'sha3' +import { Account, AccountAddress, AccountState, AccountStates } from '../libra-web-account' +import { CursorBuffer } from '../libra-web-core-utils/common/CursorBuffer' +import PathValues from '../libra-web-core-utils/constants/PathValues' import { AccountStateBlob, AccountStateWithProof, AdmissionControlClient, - SubmitTransactionRequest, - SubmitTransactionResponse, GetAccountStateRequest, GetAccountStateResponse, + RawTransaction, RequestItem, ResponseItem, - UpdateToLatestLedgerRequest, - RawTransaction, SignedTransaction, + SubmitTransactionRequest, + SubmitTransactionResponse, + UpdateToLatestLedgerRequest, } from '../libra-web-net' -import { CursorBuffer } from '../libra-web-core-utils/common/CursorBuffer' -import PathValues from '../libra-web-core-utils/constants/PathValues' import { LibraTransaction, LibraTransactionFactory } from '../libra-web-transaction' -import { Account, AccountAddress, AccountState, AccountStates } from '../libra-web-account' export enum LibraNetwork { Testnet = 'testnet', @@ -41,16 +41,16 @@ const DefaultFaucetServerHost = 'faucet.testnet.libra.org' const DefaultProxyServer: LibralLibConfig = process.env.NODE_ENV === 'test' ? { - protocol: 'http', host: 'localhost', - port: '8080', network: LibraNetwork.Local, + port: '8080', + protocol: 'http', } : { - protocol: 'http', host: 'ac.testnet.trylibra.org', - port: '80', network: LibraNetwork.Testnet, + port: '80', + protocol: 'http', } export class LibraClient { @@ -199,7 +199,9 @@ export class LibraClient { receipientAddress: AccountAddress | string, numCoins: number | string | BigNumber, ): Promise { - if (typeof receipientAddress === 'string') receipientAddress = AccountAddress.fromHex(receipientAddress) + if (typeof receipientAddress === 'string') { + receipientAddress = AccountAddress.fromHex(receipientAddress) + } const response = await this.execute( LibraTransactionFactory.createTransfer( sender.getAddress().toBytes(), diff --git a/packages/libra-web-transaction/index.ts b/packages/libra-web-transaction/index.ts index 371f711..3c603a2 100644 --- a/packages/libra-web-transaction/index.ts +++ b/packages/libra-web-transaction/index.ts @@ -45,8 +45,8 @@ export class LibraTransactionFactory { receipientAddress: Uint8Array, numCoins: BigNumber, gasConstraint: LibraGasConstraint = { - maxGasAmount: new BigNumber('10000'), gasUnitPrice: new BigNumber('0'), + maxGasAmount: new BigNumber('10000'), }, expirationTime: string | BigNumber = '1661898073', sequenceNumber: string | BigNumber = '-1',