Utilities
UUID, random string, hash, passphrase, and SSH keypair generators for the Node.js SDK.
The Node.js SDK includes utility generators under the generate export.
import { generate } from '@stashbase/node-sdk'UUID
Generate UUID values with v4 or v7 format.
generate.uuid.v4()
Returns UUID v4.
const id = generate.uuid.v4()generate.uuid.v7()
Returns UUID v7 based on current Unix epoch milliseconds and random bits.
const id = generate.uuid.v7()Random
Generate random strings with these methods:
generate.random.alphanumeric(options?)generate.random.hex(options?)generate.random.base32(options?)generate.random.base64(options?)generate.random.base64url(options?)generate.random.base64Url(options?)
Options
All random methods accept GenerateRandomStringOptions.
Prop
Type
Examples
const alphanumeric = generate.random.alphanumeric()
const hex = generate.random.hex({ length: 64 })
const base32 = generate.random.base32({ bytes: 20 })
const base64 = generate.random.base64({ length: 32 })
const base64url = generate.random.base64url({ uppercase: true })Hash
Use generate.hash(value, options?) to generate a hash digest for a string.
Signature
generate.hash(value: string, options?: GenerateHashOptions): stringOptions
Prop
Type
Supported algorithms:
sha224sha256sha384sha512
Examples
const hash1 = generate.hash('hello')
const hash2 = generate.hash('hello', { algorithm: 'sha512' })
const hash3 = generate.hash('hello', { uppercase: true })Passphrase
Use generate.passphrase(options?) to generate a random passphrase from the built-in word list.
Signature
generate.passphrase(options?: GeneratePassphraseOptions): stringConstants
PASSPHRASE_MIN_WORDS = 3PASSPHRASE_MAX_WORDS = 24
Options
Prop
Type
Built-in word list
generate.passphrase uses a built-in dictionary that includes words such as:
anchor, apple, arch, arrow, atom, ... , winter, zephyr, zinc.
Examples
const p1 = generate.passphrase()
const p2 = generate.passphrase({ words: 4 })
const p3 = generate.passphrase({ separator: '.' })
const p4 = generate.passphrase({ uppercase: true })SSH Keypair
Use generate.sshKeypair(options?) to generate SSH key material and SHA256 fingerprint.
Signature
generate.sshKeypair(options?: GenerateSshKeypairOptions): GenerateSshKeypairResultOptions
Prop
Type
Result
GenerateSshKeypairResult contains:
keyTypeprivateKey(PEM)publicKey(OpenSSH format)fingerprint(SHA256:...)
Notes
rsageneration usesmodulusLength: 4096.- Public key is returned in OpenSSH format (
ssh-ed25519orssh-rsa). - Fingerprint is SHA256 over the OpenSSH key blob.
Examples
const keypair1 = generate.sshKeypair()
const keypair2 = generate.sshKeypair({
keyType: 'rsa',
comment: 'dev@stashbase',
})
const keypair3 = generate.sshKeypair({
passphrase: 'my-secret-passphrase',
})