npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

thor-model-kit

v0.3.1

Published

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

Downloads

68

Readme

~~Thor Model Kit~~

Deprecated, use thor-devkit instead.

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

Gitter

NPM Version Build Status Coverage Status

Installation

npm i --save thor-model-kit

Usage

All widgets are as below:

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

Basic types

let addr = Address.fromHex('0x7567d83b7b8d80addcb281a71d54fc7b3364ffed', '0x' /* defaults to '0x' */)
console.log(addr.toString('0x' /* defaults to '0x' */))
// 0x7567d83b7b8d80addcb281a71d54fc7b3364ffed
console.log(addr.toString('vx:'))
// vx:7567d83b7b8d80addcb281a71d54fc7b3364ffed

let b32 = Bytes32.fromHex('0xda90eaea52980bc4bb8d40cb2ff84d78433b3b4a6e7d50b75736c5e3e77b71ec', '0x' /* defaults to '0x' */)
console.log(b32.toString('0x' /* defaults to '0x' */))
// 0xda90eaea52980bc4bb8d40cb2ff84d78433b3b4a6e7d50b75736c5e3e77b71ec

let bi = BigInt.from(123)
console.log(bi.toString(10))
// 123

Crypto methods

let hash = blake2b256('hello world')
console.log(hash.toString())
// 0x256c83b297114d201b30179f3f0ef0cace9783622da5974326b436178aeef610

hash = keccak256('hello world')
console.log(hash.toString())
// 0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad

// Secp256k1
let privKey = Secp256k1.generatePrivateKey()
let pubKey = Secp256k1.derivePublicKey(privKey)
let addr = Secp256k1.deriveAddress(pubKey)
let signature = Secp256k1.sign(keccak256('hello world'), privKey)
let recoveredPubKey = Secp256k1.recover(keccak256('hello world'), signature)

Mnemonic & Keystore

// 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

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: clauses,
    gasPriceCoef: 128,
    gas: BigInt.from(21000),
    dependsOn: null,
    nonce: BigInt.from(12345678),
    reserved: []
}

let tx = new Transaction(body)
tx.signature = Secp256k1.sign(tx.signingHash, /* your private key */)

let raw = tx.encode()
let decoded = Transaction.decode(raw)

License

thor-model-kit is licensed under the GNU Lesser General Public License v3.0, also included in LICENSE file in repository.