open-index/open-npm huggingface dataset:
npm package: @posh/ast
Description: Generate JS modules from ASTs
Author: Paul Sherman
Latest version: 0.6.1

# @posh/ast

Generate JavaScript modules from AST nodes.

Uses Babel's `@babel/types` and `@babel/generator` packages.

**Note:** Not all node types are wrapped by `@posh/ast`. For the ones that are not, the types from `@babel/types` should be used.

```bash
npm install @posh/ast
```

## Usage

```js
import { stringify, types } from "@posh/ast";

function createModule() {
  const myVar = types.CONST("myVar", types.STRING("hi!"));
  const exportVar = types.EXPORT_DEFAULT(types.ID("myVar"));

  const code = stringify`
${myVar}
${exportVar}
`;
  /*
   * const myVar = "hi!";
   * export default myVar;
   */
}

function createComponent() {
  const importReact = types.IMPORT_DEFAULT("React", "react");
  const MyComponent = types.FUNCTION(
    "MyComponent",
    [types.ID("props")],
    [
      types.RETURN(types.STRING("test"))
    ]
  );
  const exportComponent = types.EXPORT_DEFAULT("MyComponent");
  const code = stringify`
${importReact}

${MyComponent}

${exportComponent}
`;
  /*
   * import React from "react"
   *
   * function MyComponent(props) {
   *   return "test";
   * }
   *
   * export default MyComponent;
   */
}
```
npm package: @posichain-js/crypto
Description: crypto libraries for posichain
Author: musket.gun@position.exchange
Latest version: 0.0.5

# @posichain-js/crypto

This package provides a collection of apis related to address management, kestore, encoding, and encrypt/decrypt.

## Installation

```
npm install @posichain-js/crypto
```

## Usage

```javascript
const {
  encode,
  decode,
  randomBytes,
  toBech32,
  fromBech32,
  PosiChainAddress,
  generatePrivateKey,
  getPubkeyFromPrivateKey,
  getAddressFromPublicKey,
  getAddressFromPrivateKey,
  encryptPhrase,
  decryptPhrase
} = require('@posichain-js/crypto');
const { isPrivateKey, isAddress, isPublicKey } = require('@posichain-js/utils');
```

Address apis
```javascript
const bytes = randomBytes(20);
const addr = new PosiChainAddress(bytes);

console.log(addr.checksum);
console.log(addr.bech32);

console.log(PosiChainAddress.isValidBech32(addr.bech32));
```

RLP apis
```javascript
const encoded = '0x89010101010101010101';
const decoded = '0x010101010101010101';
console.log(encode(decoded));
console.log(decode(encoded));
```

Keystore apis
```javascript
const prv = generatePrivateKey();
const pub = getPubkeyFromPrivateKey(prv);
const addr = getAddressFromPublicKey(pub);
const addrPrv = getAddressFromPrivateKey(prv);
console.log(isPrivateKey(prv));
console.log(isPublicKey(pub));
console.log(isAddress(addr));
console.log(isAddress(addrPrv));
```

Encrypt/decrypt apis
```javascript
const { Wallet } = require('@posichain-js/account');

const myPhrase = new Wallet().newMnemonic();
console.log(myPhrase);
const pwd = '1234';
encryptPhrase(myPhrase, pwd).then((value) => {
  console.log(value);
  decryptPhrase(JSON.parse(value), pwd).then(value => {
    console.log(value);
  });
});
```
npm package: @posichain-js/network
Description: network suites for posichain
Author: musket.gun@position.exchange
Latest version: 0.0.5

# @posichain-js/network

This package provides a collection of apis to create messengers (HTTP, WebSocket) to connect to blockchain networks.

## Installation

```
npm install @posichain-js/network
```

## Usage

```javascript
const { Messenger, HttpProvider, WSProvider } = require('@posichain-js/network');
const { ChainID, ChainType } = require('@posichain-js/utils');
const testnetHTTP = 'https://s0.posichain.org/';
const testnetWS = 'wss://ws.s0.posichain.org/';
const localHTTP = 'http://localhost:9500/';
const localWS = 'http://localhost:9800/';
const http = new HttpProvider(testnetHTTP); // for local use localHTTP
const ws = new WSProvider(testnetWS); // for local use testnetWS
const customHTTPMessenger = new Messenger(http, ChainType.PosiChain, ChainID.HmyTestnet); // for local ChainID.HmyLocal
const customWSMessenger = new Messenger(ws, ChainType.PosiChain, ChainID.HmyTestnet); // for local ChainID.HmyLocal
```
npm package: @posichain-js/staking
Description: staking transaction package for posichain
Latest version: 0.0.5

# @posichain-js/staking

This package provides a collection of apis to create, sign/send staking transaction, and receive confirm/receipt.

## Installation

```
npm install @posichain-js/staking
```

## Usage

Create a PosiChain instance connecting to testnet

```javascript
const { PosiChain } = require('@posichain-js/core');
const {
  ChainID,
  ChainType,
  hexToNumber,
  numberToHex,
  fromWei,
  Units,
  Unit,
} = require('@posichain-js/utils');

const posi = new PosiChain(
    'https://s0.posichain.org//',
    {
        chainType: ChainType.PosiChain,
        chainId: ChainID.PosiTestnet,
    },
);
```
Below, examples show how to send delegate, undelegate, and collect rewards staking transactions. First, set the chainId, gasLimit, gasPrice for all subsequent staking transactions
```javascript
posi.stakings.setTxParams({
  gasLimit: 25000,
  gasPrice: numberToHex(new posi.utils.Unit('1').asGwei().toWei()),
  chainId: 2
});
```
<span style="color:red">Note: create and edit validator transactions are not fully supported in the sdk</span>

Create delegate staking transaction
```javascript
const delegate = posi.stakings.delegate({
  delegatorAddress: 'one103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7',
  validatorAddress: 'one1vfqqagdzz352mtvdl69v0hw953hm993n6v26yl',
  amount: numberToHex(new Unit(1000).asOne().toWei())
});
const delegateStakingTx = delegate.build();
```

Sign and send the delegate transaction and receive confirmation
```javascript
// key corresponds to one103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7, only has testnet balance
posi.wallet.addByPrivateKey('45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e');

posi.wallet.signStaking(delegateStakingTx).then(signedTxn => {
  signedTxn.sendTransaction().then(([tx, hash]) => {
    console.log(hash);
    signedTxn.confirm(hash).then(response => {
      console.log(response.receipt);
    });
  });
});
```

Similarily, undelegate and collect reward transactions can be composed, signed and sent
Create undelegate staking transaction
```javascript
const undelegate = posi.stakings.undelegate({
  delegatorAddress: 'one103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7',
  validatorAddress: 'one1vfqqagdzz352mtvdl69v0hw953hm993n6v26yl',
  amount: numberToHex(new Unit(1000).asOne().toWei())
});
const undelegateStakingTx = undelegate.build();
```

Create collect rewards staking transaction
```javascript
const collectRewards = posi.stakings.collectRewards({
  delegatorAddress: 'one103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7'
});
const collectRewardsStakingTx = collectRewards.build();
```

Also, similar to normal transaction, signing and sending can be performed asynchronously.
npm package: @posichain-js/utils
Description: utils for posichain
Author: shin@position.exchange
Latest version: 0.0.5

# @posichain-js/utils

This package provides a collection of utility apis for unit conversions like `fromWei`, `toWei`, `hexToNumber`, `numberToHex`, `isAddress`, etc.

## Installation

```
npm install @posichain-js/utils
```

## Usage

Available units
```
const { Units } = require('@posichain-js/utils');

[Units.wei, '1'], // 1 wei
[Units.Kwei, '1000'], // 1e3 wei
[Units.Mwei, '1000000'], // 1e6 wei
[Units.Gwei, '1000000000'], // 1e9 wei
[Units.szabo, '1000000000000'], // 1e12 wei
[Units.finney, '1000000000000000'], // 1e15 wei
[Units.ether, '1000000000000000000'], // 1e18 wei
[Units.one, '1000000000000000000'], // 1e18 wei
[Units.Kether, '1000000000000000000000'], // 1e21 wei
[Units.Mether, '1000000000000000000000000'], // 1e24 wei
[Units.Gether, '1000000000000000000000000000'], // 1e27 wei
[Units.Tether, '1000000000000000000000000000000'], // 1e30 wei
```

Converting between different units
```javascript
const { Units, Unit, numberToString, add0xToString, fromWei, toWei, numToStr} = require('@posichain-js/utils');
const { BN } = require('@posichain-js/crypto');

const one = new Unit('1').asOne();
const oneToGwei = one.toGwei();
console.log(oneToGwei);

// numberToString
const num = 123;
const str = numberToString(num)
console.log(str);

// add0xToString
const str = '12345';
const expected = add0xToString(str)
console.log(expected);

// fromWei
const Wei = new BN('1000000000000000000');
const expected = fromWei(Wei, Units.one);
console.log(expected);

// toWei
const one = new BN('1');
const expected = toWei(one, posi.utils.Units.one);
const num = numToStr(expected);
console.log(num);
```