Utils
Helper functions exported by the @4thtech-sdk/utils package.
Utility functions and helpers used by the other SDK packages. Version 0.0.2.
Installation
npm install @4thtech-sdk/utilsUsage
import { stringToArrayBuffer, arrayBufferToString } from '@4thtech-sdk/utils';
const buffer = stringToArrayBuffer('hello');
const text = arrayBufferToString(buffer);Exports
The package index exports the buffer helpers, the Node crypto helpers and the error class.
Buffer helpers
stringToArrayBuffer(str)
Converts a string to an ArrayBuffer
arrayBufferToString(buffer)
Converts an ArrayBuffer to a string
hexStringToArrayBuffer(hex)
Converts a hex string to an ArrayBuffer
arrayBufferToHexString(buffer)
Converts an ArrayBuffer to a hex string
concatenateArrayBuffers(...buffers)
Joins several ArrayBuffers into one
Crypto helpers
calculateChecksum(data)
Returns the SHA-256 checksum of an ArrayBuffer as a hex string
calculateChecksumFromStream(filePath)
Returns the SHA-256 checksum of a file, read as a stream (Node)
createSha256Hash(data)
Returns the SHA-256 hash of a string
getRandomValues(typedArray)
Fills a Uint8Array with random values
subtle
The Web Crypto SubtleCrypto object
Errors
ContractRevertedError is thrown by the clients in @4thtech-sdk/ethereum when a contract call reverts.
See also
AES Encryption, which uses these helpers in its examples.
Last updated
