Skip to content

EdgeApp/zano-utils-js

 
 

Repository files navigation

zano-utils-js

Set of helpers and tools for JS developers that working with Zano

Blockchain Description

  • Ticker: Zano
  • Network: Zano

Functions

decodeTransaction

Node Method Used:

  • get_tx_details

Example Request:

curl -X POST \
-H "Content-Type: application/json" \
--data '{ "jsonrpc": "2.0", "method": "get_tx_details", "params": {"tx_hash": "77b09d759fefd512642f9a5e4e31ed0fefbaf1a8e602a2be94fc511ff982f7cf" }, "id": 1 }' \
"http://37.27.100.59:10500/json_rpc"
Example response
{
  "id": 1,
  "jsonrpc": "2.0",
  "result": {      
    "status": "OK",
    "tx_info": {
      "amount": 0,
      "blob": "AwIlEBqFoRgAAAAAABp....",
      "blob_size": 2017,
      "extra": [{
        "details_view": "",
        "short_view": "(encrypted)",
        "type": "payer"
      },{
        "details_view": "",
        "short_view": "631a0aa63dd0caa6473f8a136a155f54a05d1f2f8b5b92c5145383be2a696834",
        "type": "pub_key"
      },{
        "details_view": "0000",
        "short_view": "0000",
        "type": "FLAGS16"
      },{
        "details_view": "derivation_hash: 5fd099a9\nencrypted_key_derivation: 2fecfc1742ea69e8b25f76c5014bd2cb9ca249e2b717bbc6376e0196e450eccf",
        "short_view": "derivation_hash: 5fd099a9",
        "type": "crypto_checksum"
      },{
        "details_view": "ef40",
        "short_view": "ef40",
        "type": "derivation_hint"
      },{
        "details_view": "94c3",
        "short_view": "94c3",
        "type": "derivation_hint"
      },{
        "details_view": "fee = 0.01",
        "short_view": "fee = 0.01",
        "type": "zarcanum_tx_data_v1"
      }],
      "fee": 10000000000,
      "id": "fd93234ee26299d9bcd0c7ffd66cfd31f66c16b7cd28776ddb3113f77477a669",
      "ins": [{
        "amount": 0,
        "global_indexes": [1614213,1625091,1701687,1724120,1755061,1852550,1885364,1888520,1890757,1901665,1901797,1902935,1903361,1903474,1903878,1904042],
        "htlc_origin": "",
        "kimage_or_ms_id": "5eb5744c8fa2e2b44413323cc1b9bb6021c18218eb25f4c3a12c8ba5f8ca9e05",
        "multisig_count": 0
      },{
        "amount": 0,
        "global_indexes": [1415271,1478600,1553576,1658538,1872595,1899601,1901346,1901642,1902588,1903284,1903353,1903522,1903584,1903697,1903952,1903954],
        "htlc_origin": "",
        "kimage_or_ms_id": "e2a6d2a56c671fec431fa3025e8143ec2e9c14b1bdfc19936f6377c84abc0672",
        "multisig_count": 0
      }],
      "keeper_block": 3199720,
      "object_in_json": "ewogICJBR0dSRUdBVEVE....AgfQogICAgfQogIF0KfQ==",
      "outs": [{
        "amount": 0,
        "global_index": 1904095,
        "is_spent": false,
        "minimum_sigs": 0,
        "pub_keys": ["a08e213373e34988600db3168be88eff5a9e2da9972dcc12d6e51dc56a7b845b","23b5f778966dc4d8594549670a0335c8f639f18a39063606a9ebf1a826bb6a66","e22c32eb7fd87d8403d1516a5849966a1f8f4053eb56ae3a7048c3e5ffcaa0a2","a23fe6c894dc069ba92a252611027bcaae8c80d0848ce0e3357e05e61aa78914","5df242cb3fb59a87"]
      },{
        "amount": 0,
        "global_index": 1904096,
        "is_spent": false,
        "minimum_sigs": 0,
        "pub_keys": ["492d93dc0fb07d90e5d1ce9210b31fc1155206473d5d3f5136f7031ff6aad31e","6c24323a8e2690482cdd685956904168cb5fc8749f3be2df58f7d0aeb39f5252","bbaa2f259d5f6f5c1e0df43c9cbd7c061ac023f91ebb3fe22a5352115f642cec","d4ec19288fc18a81917c3328d45464bddfb04d5582690bc50062dac9dd963887","8dfdd23882a0a1ae"]
      }],
      "pub_key": "631a0aa63dd0caa6473f8a136a155f54a05d1f2f8b5b92c5145383be2a696834",
      "timestamp": 1749725356
    }
  }
}

decodeTransaction

Decode a transaction object_in_json using the provided secret view key and either address or public spend key. You can prodive integrated address or master address.

Import and usage

import { decodeTransaction } from '@zano-project/zano-utils-js';
import type { DecodeTransactionResult } from '@zano-project/zano-utils-js';

decodeTransaction(objectInJson, secretViewKey, address);
// or provide public spend key
decodeTransaction(objectInJson, secretViewKey, publicSpendKey);

Returned data decodeTransaction

type DecodeTransactionResult =
    | { ok: true; amount: string; paymentId?: string }
    | { ok: false; error: string }

txUtils

Namespace that provides low-level cryptographic and transaction-related helper functions for Zano transactions.
These utilities allow working with transaction outputs, stealth addresses, key images, and encrypted fields.

Import utils:

import { txUtils } from '@zano-project/zano-utils-js';

getConcealingPoint

Calculates a concealing point for a transaction output.

Signature:

getConcealingPoint(viewSecretKey: string, txPubKey: string, pubViewKey: string, outputIndex: number): string

decodeAmount

Decrypts an encrypted (masked) output amount using the recipient’s view key.

Signature:

decodeAmount(viewSecretKey: string, txPubKey: string, encryptedAmount: string | number, outputIndex: number): bigint

getStealthAddress

Generates a one-time stealth address (ephemeral public key) using the Dual-key Stealth Address Protocol.

Signature:

getStealthAddress(txPubKey: string, secViewKey: string, pubSpendKey: string, outIndex: number): string

getNativeBlindedAsset

Computes a blinded version of the native asset ID for output verification.

Signature:

getNativeBlindedAsset(viewSecretKey: string, txPubKey: string, outputIndex: number): string

generateKeyImage

Generates a unique key image for a transaction output — used to prevent double-spending.

Signature:

generateKeyImage(txPubKey: string, secViewKey: string, pubSpendKey: string, outIndex: number, spendSecretKey: string): string

decryptPaymentId

Decrypts an encrypted payment ID using the recipient’s view key and transaction public key.

Signature:

decryptPaymentId(encryptedPaymentId: string, txPubKey: string, secViewKey: string): string

parseObjectInJson

Decodes a base64-encoded transaction JSON string into a TransactionObject or TransactionObjectV3.

Signature:

parseObjectInJson(objectInJson: string): TransactionObject | TransactionObjectV3 | null

generateAccount

import { generateAccount } from '@zano-project/zano-utils-js';
import type { AccountResult } from '@zano-project/zano-utils-js';

const account: AccountResult = generateAccount();

Returned data generateAccount

type AccountResult = AccountKeys & {
  address: string;
}

type AccountKeys = {
  secretSpendKey: string;
  secretViewKey: string;
  publicSpendKey: string;
  publicViewKey: string;
}

validateAccount

import { validateAccount } from '@zano-project/zano-utils-js';

const validatedAccount: boolean = validateAccount(
'ZxC15vh38qHAZbfsUXTpxoiyeLhavbBzsQQk81fEwP4jYxN4qR8SEhMfXkRBpQw6vbbSEGpK2VPVPADnL6h3ZViL29Remh4oH',
'21dcd98fb9dc392aeabe1d5cfb90faf63840685762448bf49a48d58d0c70bf0b',
'2ff9e77456d0e65b50d80392a098cddf9032744bd876371fffe95476a92d8564',
'88609e3bc954fe8b5f1a5f0a7e7e44528835b62890de49000033b28898888d01',
'b35fb46128f7150ecff93e0eeee80a95ad9b13e3bfced7d3ff7a121f6748df0e',
);

validateAccount params

async function validateAccount(
  address: string,
  publicSpendKey: string,
  publicViewKey: string,
  secretSpendKey: string,
  secretViewKey: string,
): Promise<boolean> 

generateAccountKeys

import { generateAccountKeys } from '@zano-project/zano-utils-js';
import type { AccountKeys } from '@zano-project/zano-utils-js';

const accountKeys: AccountKeys = generateAccountKeys();

Returned data generateAccountKeys

type AccountKeys = {
  secretSpendKey: string;
  secretViewKey: string;
  publicSpendKey: string;
  publicViewKey: string;
}

privateKeyToPublicKey

import { privateKeyToPublicKey } from '@zano-project/zano-utils-js';

const publicKey: string = privateKeyToPublicKey('88609e3bc954fe8b5f1a5f0a7e7e44528835b62890de49000033b28898888d01');

getAccountBySecretSpendKey

import { getAccountBySecretSpendKey } from '@zano-project/zano-utils-js';
import type { AccountKeys } from '@zano-project/zano-utils-js';

const accountKeys: AccountKeys = getAccountBySecretSpendKey('88609e3bc954fe8b5f1a5f0a7e7e44528835b62890de49000033b28898888d01');

Returned data getAccountBySecretSpendKey

type AccountKeys = {
  secretSpendKey: string;
  secretViewKey: string;
  publicSpendKey: string;
  publicViewKey: string;
}

getKeyPair

import { getKeyPair } from '@zano-project/zano-utils-js';
import type { KeyPair } from '@zano-project/zano-utils-js';

const keypair: KeyPair = getKeyPair();

Returned data getKeyPair

type KeyPair = {
  rawSecretKey: string;
  secretKey: string;
  publicKey: string;
}

getIntegratedAddress

The function accepts either the main master address or the integrated address as a parameter.

import { getIntegratedAddress } from '@zano-project/zano-utils-js';

const integratedAddress: string = getIntegratedAddress('ZxD5aoLDPTdcaRx4uCpyW4XiLfEXejepAVz8cSY2fwHNEiJNu6NmpBBDLGTJzCsUvn3acCVDVDPMV8yQXdPooAp338Se7AxeH');

createIntegratedAddress

import { createIntegratedAddress } from '@zano-project/zano-utils-js';

const integratedAddress: string = createIntegratedAddress('ZxD5aoLDPTdcaRx4uCpyW4XiLfEXejepAVz8cSY2fwHNEiJNu6NmpBBDLGTJzCsUvn3acCVDVDPMV8yQXdPooAp338Se7AxeH', '49c925855b863a25');

getMasterAddress

params:

  1. spendPublicKey: string,
  2. viewPublicKey: string
import { getMasterAddress } from '@zano-project/zano-utils-js';

const integratedAddress: string = getMasterAddress('9f5e1fa93630d4b281b18bb67a3db79e9622fc703cc3ad4a453a82e0a36d51fa', 'a3f208c8f9ba49bab28eed62b35b0f6be0a297bcd85c2faa1eb1820527bcf7e3');

splitIntegratedAddress

Descr: Extract paymentId and master address from integrated address

params:

  1. integratedAddress: string,
import { splitIntegratedAddress } from '@zano-project/zano-utils-js';
import type { SplitedIntegratedAddress } from '@zano-project/zano-utils-js';

const integratedAddress: SplitedIntegratedAddress = splitIntegratedAddress('iZ2kFmwxRHoaRxm1ni8HnfUTkYuKbni8s4CE2Z4GgFfH99BJ6cnbAtJTgUnZjPj9CTCTKy1qqM9wPCTp92uBC7e47JPoHxGL5UU2D1tpQMg4');

Returned data splitIntegratedAddress

type SplitedIntegratedAddress = {
    masterAddress: string;
    paymentId: string;
}

getKeysFromAddress

Descr: Extract public keys from master or integratedAddress

params:

  1. address: string,
import { getKeysFromAddress } from '@zano-project/zano-utils-js';
import type { ZarcanumAddressKeys } from '@zano-project/zano-utils-js';

const integratedAddress: ZarcanumAddressKeys = getKeysFromAddress('iZ2kFmwxRHoaRxm1ni8HnfUTkYuKbni8s4CE2Z4GgFfH99BJ6cnbAtJTgUnZjPj9CTCTKy1qqM9wPCTp92uBC7e47JPoHxGL5UU2D1tpQMg4');

Returned data getKeysFromAddress

type ZarcanumAddressKeys = {
    spendPublicKey: string;
    viewPublicKey: string;
};

generatePaymentId

Descr: generate payment id for creating integrated address

import { generatePaymentId } from '@zano-project/zano-utils-js';

const paymentId: string = generatePaymentId();

mnemonicToSeed

Converts a mnemonic seed phrase (25 or 26 words) into either a secret spend key or a full seed hex string.

A full seed is the raw 32-byte seed with the mnemonic metadata word indices (timestamp and checksum) appended as big-endian uint16 values. This preserves the original timestamp and checksum so the mnemonic can be reconstructed deterministically later.

Parameters

Parameter Type Default Description
seedPhraseRaw string Raw seed phrase string containing 25 or 26 words.
full boolean false When true, returns a full seed hex instead of deriving the secret spend key.

Limitations

  • No support for password-protected seed phrases: Currently, the library does not handle mnemonic phrases that are encrypted with a password.
  • No audit flag support: The library does not yet support the audit flag feature.

Import and usage

import { mnemonicToSeed } from '@zano-project/zano-utils-js';

// Derive the secret spend key (default behavior):
const secretSpendKey: string = mnemonicToSeed('bridge passion scale vast speak mud murder own birthday flight always hair especially tickle crowd shatter tickle deserve hopefully bomb join plan darling aunt beneath give');

// Get the full seed hex (32-byte seed + encoded timestamp + checksum):
const fullSeedHex: string = mnemonicToSeed('bridge passion scale vast speak mud murder own birthday flight always hair especially tickle crowd shatter tickle deserve hopefully bomb join plan darling aunt beneath give', true);

Returned data mnemonicToSeed

When full is false (default), returns the 64-character secret spend key hex string.

When full is true, returns an expanded hex string: the original 32-byte seed (64 hex chars) followed by the word indices for the timestamp word and, if present, the checksum word (each encoded as 4 hex chars). This is 68 hex chars for a 25-word phrase or 72 hex chars for a 26-word phrase.

type MnemonicToSeedResult = string;

seedToMnemonic

Converts a seed hex string into a mnemonic phrase. The behavior depends on the length of the input:

  • 32 bytes (64 hex chars) — Treated as a raw seed. The 24 core mnemonic words are derived from the seed, and a timestamp word is generated from the current date along with a checksum word, producing a 26-word phrase.
  • 34 bytes (68 hex chars) — Treated as a full seed (v1). The last 2 bytes encode a timestamp word index. The mnemonic is reconstructed deterministically from the embedded index, producing a 25-word phrase.
  • 36 bytes (72 hex chars) — Treated as a full seed (v2). The last 4 bytes encode a timestamp word index and a checksum word index. The mnemonic is reconstructed deterministically from the embedded indices, producing a 26-word phrase.

The full seed format is useful for storing and restoring mnemonics without relying on the current date for timestamp generation. Use mnemonicToSeed(phrase, true) to obtain a full seed, and seedToMnemonic(fullSeedHex) to recover the original mnemonic.

Warning

Do not use the secret spend key to create a mnemonic. You must provide the raw seed key, which is the key used to derive both the secret spend key and the mnemonic.

Limitations

  • No support for password-protected seed phrases: Currently, the library does not handle mnemonic phrases that are encrypted with a password.
  • No audit flag support: The library does not yet support the audit flag feature.

Import and usage

import { seedToMnemonic } from '@zano-project/zano-utils-js';
import type { SeedToMnemonicResult } from '@zano-project/zano-utils-js';

// From a raw 32-byte seed (timestamp generated from current date):
const randomBytes: string = getRandomBytes(64).toString('hex');
const seedPhrase: SeedToMnemonicResult = seedToMnemonic(randomBytes);

// From a full seed (timestamp and checksum restored from embedded indices):
const fullSeedHex: string = mnemonicToSeed(seedPhrase, true);
const recoveredPhrase: SeedToMnemonicResult = seedToMnemonic(fullSeedHex);
// recoveredPhrase === seedPhrase

Returned data seedToMnemonic

type SeedToMnemonicResult = string;


Supporting project/donations


ZANO @dev
BTC bc1qpa8w8eaehlplfepmnzpd7v9j046899nktxnkxp
BCH qqgq078vww5exd9kt3frx6krdyznmp80hcygzlgqzd
ETH 0x206c52b78141498e74FF074301ea90888C40c178
XMR 45gp9WTobeB5Km3kLQgVmPJkvm9rSmg4gdyHheXqXijXYMjUY48kLgL7QEz5Ar8z9vQioQ68WYDKsQsjAEonSeFX4UeLSiX

About

Set of helpers and tools for JS developers that working with Zano

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • TypeScript 100.0%