npm-package-near-encoding-sdk
v1.0.3617
Published
npm Package - near-encoding
Readme
near-encoding
Utility functions for Base64 encoding, JSON buffer encoding, and NEAR account state fetching.
Installation
npm install near-encoding
Usage
Base64 Encoding
import { encodeBase64, decodeBase64 } from 'near-encoding';
const encoded = encodeBase64('hello world'); // => 'aGVsbG8gd29ybGQ='
const decoded = decodeBase64('aGVsbG8gd29ybGQ='); // => 'hello world'
JSON Buffer Encoding
import { encodeJson, decodeJson } from 'near-encoding';
const buffer = encodeJson({ foo: 'bar', count: 42 }); // => Buffer
const obj = decodeJson(buffer); // => { foo: 'bar', count: 42 }
Fetch and Encode Account State
import { fetchAndEncodeAccountState } from 'near-encoding';
const result = await fetchAndEncodeAccountState('alice.near'); // => { raw: AccountState, encoded: string }
Generate Key Pair
import { generateKeyPair } from 'near-encoding';
const keyPair = generateKeyPair('alice.near'); // => GeneratedKeyPair
API
| Function | Signature |
|---|---|
| encodeBase64 | (input: string): string |
| decodeBase64 | (input: string): string |
| encodeJson | (input: Record<string, unknown>): Buffer |
| decodeJson | (input: Buffer \| Uint8Array): Record<string, unknown> |
| fetchAndEncodeAccountState | (accountId: string): Promise<{ raw: AccountState; encoded: string }> |
| generateKeyPair | (accountId: string): GeneratedKeyPair |
License
MIT
