CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-polkadot--util-crypto

A collection of useful crypto utilities for Polkadot ecosystem projects

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

base-encoding.mddocs/

Base Encoding

Encoding and decoding utilities for Base32, Base58, and Base64 formats with validation and IPFS compatibility options.

Capabilities

Base58 Encoding

Base58 encoding commonly used in blockchain addresses and identifiers.

/**
 * Encode bytes to Base58 string
 * @param value - Bytes to encode
 * @param ipfsCompat - Use IPFS-compatible alphabet
 * @returns Base58 encoded string
 */
function base58Encode(value: Uint8Array, ipfsCompat?: boolean): string;

/**
 * Decode Base58 string to bytes
 * @param value - Base58 string to decode
 * @param ipfsCompat - Use IPFS-compatible alphabet
 * @returns Decoded bytes
 */
function base58Decode(value: string, ipfsCompat?: boolean): Uint8Array;

/**
 * Validate Base58 string format
 * @param value - String to validate
 * @returns true if valid Base58
 */
function base58Validate(value: string): boolean;

/**
 * Check if string is Base58 encoded
 * @param value - String to check
 * @returns true if Base58 format
 */
function isBase58(value: string): boolean;

Base64 Encoding

Standard Base64 encoding with padding utilities.

/**
 * Encode bytes to Base64 string
 * @param value - Bytes to encode
 * @returns Base64 encoded string
 */
function base64Encode(value: Uint8Array): string;

/**
 * Decode Base64 string to bytes
 * @param value - Base64 string to decode
 * @returns Decoded bytes
 */
function base64Decode(value: string): Uint8Array;

/**
 * Validate Base64 string format
 * @param value - String to validate
 * @returns true if valid Base64
 */
function base64Validate(value: string): boolean;

/**
 * Check if string is Base64 encoded
 * @param value - String to check
 * @returns true if Base64 format
 */
function isBase64(value: string): boolean;

/**
 * Add padding to Base64 string
 * @param value - Base64 string
 * @returns Padded Base64 string
 */
function base64Pad(value: string): string;

/**
 * Remove padding from Base64 string
 * @param value - Padded Base64 string
 * @returns Trimmed Base64 string
 */
function base64Trim(value: string): string;

Base32 Encoding

Base32 encoding with IPFS compatibility.

/**
 * Encode bytes to Base32 string
 * @param value - Bytes to encode  
 * @param ipfsCompat - Use IPFS-compatible alphabet
 * @returns Base32 encoded string
 */
function base32Encode(value: Uint8Array, ipfsCompat?: boolean): string;

/**
 * Decode Base32 string to bytes
 * @param value - Base32 string to decode
 * @param ipfsCompat - Use IPFS-compatible alphabet
 * @returns Decoded bytes
 */
function base32Decode(value: string, ipfsCompat?: boolean): Uint8Array;

/**
 * Validate Base32 string format
 * @param value - String to validate
 * @returns true if valid Base32
 */
function base32Validate(value: string): boolean;

/**
 * Check if string is Base32 encoded
 * @param value - String to check
 * @returns true if Base32 format
 */
function isBase32(value: string): boolean;

Usage Examples

import { 
  base58Encode, 
  base58Decode,
  base64Encode,
  base64Decode,
  base32Encode,
  base32Decode
} from "@polkadot/util-crypto";

const data = new TextEncoder().encode("Hello World");

// Base58
const base58 = base58Encode(data);
const decoded58 = base58Decode(base58);

// Base64
const base64 = base64Encode(data);
const decoded64 = base64Decode(base64);

// Base32
const base32 = base32Encode(data);
const decoded32 = base32Decode(base32);

Install with Tessl CLI

npx tessl i tessl/npm-polkadot--util-crypto

docs

address.md

base-encoding.md

crypto-init.md

ethereum.md

hashing.md

index.md

json-encryption.md

key-derivation-pbkdf.md

key-derivation.md

keypairs.md

mnemonic.md

random.md

signatures.md

tile.json