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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@chain1/stok-utils

v1.0.1

Published

Utility functions for StoChain blockchain applications - date formatting, number formatting, crypto operations, storage, and blockchain utilities

Readme

@chain1/stok-utils

Comprehensive utility library for StoChain blockchain applications providing utilities for date formatting, number formatting, crypto operations, storage management, and blockchain interactions.

Installation

npm install @chain1/stok-utils

or

yarn add @chain1/stok-utils

Features

📅 Date Utilities

  • Date formatting with multiple format options
  • Korean date formatting support
  • Today/date range helpers
  • Zero dependencies

🔢 Number Utilities

  • Thousands separator formatting
  • Decimal precision control
  • Compact number notation (K, M, B)
  • Zero dependencies

💰 Currency Formatting

  • Multi-currency support (KRW, USD, CNY, etc.)
  • Automatic precision handling
  • Locale-aware formatting
  • Zero dependencies

🔐 Crypto & Security

  • PIN-based encryption/decryption
  • Private key management
  • Secure storage integration
  • Recovery phrase generation

⛓️ Blockchain Utilities

  • Multi-chain support (ETH, BSC, STO, KAIA)
  • Wallet management
  • Token balance queries
  • Transaction sending
  • Gas price estimation
  • ERC-20 token operations

Usage

Core Utilities (No Dependencies)

import {
  formatDate,
  numberWithCommas,
  formatDisplayAmount
} from '@chain1/stok-utils';

// Date formatting
const date = formatDate(new Date().toISOString(), 'korean');
// "2025년 11월 08일 10:00"

// Number formatting
const amount = numberWithCommas(1000000);
// "1,000,000"

// Currency formatting
const price = formatDisplayAmount(1234.56, 'usd');
// "1,234.56"

Blockchain Operations

Note: Requires ethers peer dependency

import {
  getWalletInfoFromPrivateKey,
  getChainBalance,
  sendToken
} from '@chain1/stok-utils';

// Get wallet info from private key
const walletInfo = await getWalletInfoFromPrivateKey(
  privateKey,
  'ETH'
);
// { address, balance, chain, chainSymbol, privateKey }

// Get balance for specific chain
const balance = await getChainBalance(address, 'BSC');

// Send tokens
const result = await sendToken(
  privateKey,
  recipientAddress,
  amount,
  'STO'
);

Crypto Operations

Note: Requires React Native dependencies

import {
  encryptPrivateKey,
  decryptPrivateKey,
  generateRecoveryPhrase
} from '@chain1/stok-utils';

// Encrypt private key with user ID and PIN
const encrypted = await encryptPrivateKey(privateKey, userId);

// Decrypt private key
const decrypted = await decryptPrivateKey(encrypted, userId);

// Generate recovery phrase
const phrase = generateRecoveryPhrase();
// "word1 word2 word3 ... word12"

Storage Operations

Note: Requires React Native dependencies

import {
  saveUserId,
  getUserId,
  saveMbId,
  clearUserData
} from '@chain1/stok-utils';

// Save user ID securely
await saveUserId('user-uuid');

// Retrieve user ID
const userId = await getUserId();

// Clear all user data
await clearUserData();

Peer Dependencies

Core Utilities

No dependencies required for date, number, and format utilities.

Blockchain Utilities

{
  "ethers": "^5.7.0"
}

Crypto & Storage (React Native)

{
  "react-native": ">=0.60.0",
  "@react-native-async-storage/async-storage": "^1.15.0",
  "react-native-crypto-js": "^1.0.0",
  "expo-crypto": "^14.0.0",
  "expo-secure-store": "^14.0.0",
  "react-native-aes-crypto": "^3.2.0",
  "@supabase/supabase-js": "^2.38.0"
}

All React Native dependencies are optional. Install only what you need based on the features you use.

API Reference

Date Utilities

formatDate(isoDateString, format)

Formats an ISO date string to a readable format.

Parameters:

  • isoDateString (string): ISO format date string
  • format (string): Format type - 'default', 'korean', 'short', 'time', 'date', 'korean-date'

Returns: Formatted date string

getTodayTimeRange()

Returns today's start and end time in ISO format.

Returns: { startTime, endTime }

isToday(date)

Checks if a date is today.

Parameters:

  • date (string|Date): Date to check

Returns: boolean

Number Utilities

numberWithCommas(number)

Adds thousands separator to a number.

Parameters:

  • number (number|string): Number to format

Returns: Formatted string with commas

formatDecimal(number, decimals)

Limits decimal places of a number.

Parameters:

  • number (number|string): Number to format
  • decimals (number): Decimal places (default: 2)

Returns: Formatted decimal string

formatCompactNumber(number)

Converts numbers to compact notation (K, M, B).

Parameters:

  • number (number|string): Number to format

Returns: Compact notation string

Currency Utilities

formatDisplayAmount(amount, currency)

Formats amount according to currency standards.

Parameters:

  • amount (number|string): Amount to format
  • currency (string): Currency code ('krw', 'usd', 'cny', etc.)

Returns: Formatted amount string

Blockchain Utilities

getWalletInfoFromPrivateKey(privateKey, chain)

Gets wallet information from a private key.

Parameters:

  • privateKey (string): Ethereum format private key
  • chain (string): Chain type ('STO', 'ETH', 'BSC', 'KAIA')

Returns: Promise<{ address, balance, chain, chainSymbol, privateKey }>

getChainBalance(address, chain)

Queries balance for a specific chain.

Parameters:

  • address (string): Wallet address
  • chain (string): Chain type (default: 'STO')

Returns: Promise - Balance in wei

sendToken(privateKey, recipientAddress, amount, chain)

Sends native tokens.

Parameters:

  • privateKey (string): Sender's private key
  • recipientAddress (string): Recipient address
  • amount (number|string): Amount to send
  • chain (string): Chain type (default: 'STO')

Returns: Promise<{ success, txHash, receipt }>

transferERC20Token(tokenAddress, recipientAddress, amount, privateKey, chain)

Transfers ERC-20 tokens.

Parameters:

  • tokenAddress (string): Token contract address
  • recipientAddress (string): Recipient address
  • amount (string): Amount to transfer
  • privateKey (string): Sender's private key
  • chain (string): Chain type (default: 'STO')

Returns: Promise<{ success, txHash, receipt, amount, token }>

Crypto Utilities

encryptPrivateKey(privateKey, userId)

Encrypts a private key with user ID and optional PIN.

Parameters:

  • privateKey (string): Private key to encrypt
  • userId (string): User identifier

Returns: Promise - Encrypted data

decryptPrivateKey(encryptedData, userId)

Decrypts an encrypted private key.

Parameters:

  • encryptedData (string): Encrypted private key
  • userId (string): User identifier

Returns: Promise - Decrypted private key

generateRecoveryPhrase()

Generates a 12-word recovery phrase.

Returns: string - 12-word mnemonic phrase

Storage Utilities

saveUserId(userId)

Saves user ID to secure storage.

Parameters:

  • userId (string): User UUID

getUserId()

Retrieves saved user ID.

Returns: Promise<string|null>

clearUserData()

Clears all stored user data.

Returns: Promise

Supported Chains

  • ETH: Ethereum Mainnet
  • BSC: Binance Smart Chain (Testnet & Mainnet)
  • STO: StoChain
  • KAIA: KAIA Network (Baobab Testnet)

License

MIT License

Author

chain1

Repository

https://github.com/chain1/stok-utils

Issues

https://github.com/chain1/stok-utils/issues

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.