Skip to content
This repository has been archived by the owner on Jul 27, 2018. It is now read-only.

Commit

Permalink
update readme & bump version to 0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
qianbin committed Jul 10, 2018
1 parent aa91c1b commit 0dd6bad
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 16 deletions.
70 changes: 57 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,40 @@
## Thor Model Kit
# Thor Model Kit

Typescript library defines VeChain Thor data models, to aid DApp development.

[![Gitter](https://badges.gitter.im/vechain/thor.svg)](https://gitter.im/vechain/thor?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)

[![NPM Version](https://badge.fury.io/js/thor-model-kit.svg)](https://www.npmjs.com/package/thor-model-kit)
[![Build Status](https://travis-ci.org/vechain/thor-model-kit.svg)](https://travis-ci.org/vechain/thor-model-kit)
[![Coverage Status](https://coveralls.io/repos/github/vechain/thor-model-kit/badge.svg?branch=master)](https://coveralls.io/github/vechain/thor-model-kit?branch=master)

Typescript library defines VeChainThor data models.

## Install

## Installation

```bash
npm i --save thor-model-kit
```

## Usage

import all widgets
All widgets are as below:

```javascript
import { Address, Bytes32, BigInt, blake2b256, keccak256, Secp256k1, Transaction } from 'thor-model-kit'
import {
Address,
Bytes32,
BigInt,
blake2b256,
keccak256,
Secp256k1,
Mnemonic,
Keystore,
Transaction
} from 'thor-model-kit'
```

basic types
### Basic types

```javascript
let addr = Address.fromHex('0x7567d83b7b8d80addcb281a71d54fc7b3364ffed', '0x' /* defaults to '0x' */)
Expand All @@ -38,7 +52,7 @@ console.log(bi.toString(10))
// 123
```

crypto methods
### Crypto methods

```javascript
let hash = blake2b256('hello world')
Expand All @@ -57,18 +71,48 @@ let signature = Secp256k1.sign(keccak256('hello world'), privKey)
let recoveredPubKey = Secp256k1.recover(keccak256('hello world'), signature)
```

transaction
### Mnemonic & Keystore

```javascript
// generate BIP39 mnemonic words, default to 12 words(128bit strength)
let words = Mnemonic.generate()

// derive private key from mnemonic words according to BIP32, using the path `m/44'/818'/0'/0/0`.
// defined for VET at https://github.com/satoshilabs/slips/blob/master/slip-0044.md
let privateKey = Mnemonic.derivePrivateKey(words)

// in recovery process, validation is recommended
let ok = Mnemonic.validate(words)

// encrypt/decrypt private key using Ethereum's keystore scheme
let keystore = await Keystore.encrypt(privateKey, 'your password')

// throw for wrong password
let recoveredPrivateKey = await Keystore.decrypt(keystore, 'your password')

// roughly check keystore format
let ok = Keystore.wellFormed(keystore)
```

### Transaction codec

```javascript
let clauses = clauses: [{
to: Address.fromHex('7567d83b7b8d80addcb281a71d54fc7b3364ffed', ''),
value: BigInt.from(10000),
data: Buffer.alloc(0)
}]

// calc intrinsic gas
let gas = Transaction.intrinsicGas(clauses)
console.log(gas)
// 21000

let body: Transaction.Body = {
chainTag: 0x9a,
blockRef: Buffer.from('0000000000000000', 'hex'),
expiration: 32,
clauses: [{
to: Address.fromHex('7567d83b7b8d80addcb281a71d54fc7b3364ffed', ''),
value: BigInt.from(10000),
data: Buffer.alloc(0)
}],
clauses: clauses,
gasPriceCoef: 128,
gas: BigInt.from(21000),
dependsOn: null,
Expand Down
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "thor-model-kit",
"version": "0.2.2",
"description": "Typescript library defines VeChainThor data models",
"version": "0.3.0",
"description": "Typescript library defines VeChain Thor data models, to aid DApp development",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"scripts": {
Expand Down Expand Up @@ -38,8 +38,13 @@
},
"keywords": [
"vechain",
"thor",
"blockchain",
"model"
"models",
"dapp",
"crypto",
"mnemonic",
"keystore"
],
"author": "vechain.org",
"license": "LGPL-3.0",
Expand Down

0 comments on commit 0dd6bad

Please sign in to comment.