Signatures

Two signatures protect your integration:

  • Widget URL signature — the signature parameter you add to the widget URL. See Widget URL Signature.
  • Callback signature — the X-Signature header Mercuryo adds to callbacks sent to your server. See Callback Signature.

Widget URL Signature

The signature parameter protects On-Ramp widget URLs from forgery. It must be included in every On-Ramp request. It is not required for Off-Ramp operations.

The signature is validated when the user selects a payment method. If the signature is missing or invalid, the user sees the Invalid or missing request signature error and cannot proceed with the payment.

Signature Versions

Two signature versions are available. Both bind the widget URL to the IP address of the user: your backend includes the user's IP in the signature when generating the URL, and Mercuryo compares it with the IP the user has when opening the widget.

These two IPs can differ even for the same user — for example, when the mobile operator assigns a new IP or the device switches from Wi-Fi to mobile data.

  • Signature v2 — the IPs must match exactly. If the user's IP has changed, the user cannot proceed with the payment.
  • Signature v3 — the user's IP is passed in encrypted form. Mercuryo first checks for an exact match; if the IPs differ, validation still passes when both IPs belong to the same network or region.

Signature v2

Step 1 — Get the User's IP

Take the IP address of the user opening the widget (IPv4 or IPv6), as seen by your backend.

Step 2 — Generate the Signature

Concatenate the values without spaces, compute a SHA-512 hash of that string and prefix it with v2:.

With merchant_transaction_id:

address + secret + ip + merchant_transaction_id

Without merchant_transaction_id:

address + secret + ip

Parameters:

  • address — the user's cryptocurrency wallet address
  • secret — your widget's Secret key from the Dashboard (Widgets → select widget → Secret)
  • ip — the user's IP from Step 1
  • merchant_transaction_id — your internal transaction ID (optional)

Note: If you pass merchant_transaction_id in the widget URL, it must be included in the signature, and vice versa.

Step 3 — Build the Widget URL

Add signature to the widget URL:

https://exchange.mercuryo.io/?widget_id=YOUR_WIDGET_ID
  &address=0x742d35Cc6634C0532925a3b844Bc454e4438f44e
  &merchant_transaction_id=tx_123456
  &signature=v2:83a6473f7b0aade8cd794c38f435d8db621149f206e8488ec99ab12edefc5d55d605384dc0b3cc947a93fd3bd4d0d210c6972fcf39fbb4dce893729ddf8ea825

Note: address and merchant_transaction_id (if used) in the URL must have exactly the same values used for the signature. If any of them is missing or differs, signature validation will fail. The IP itself is not passed in the URL — it is only part of the signature.

Code Examples

The examples use the formula with merchant_transaction_id. If you don't use it, pass an empty string.

JavaScript (Node.js)

const crypto = require('crypto');

function generateSignature(address, secret, ip, merchantTransactionId) {
  const data = `${address}${secret}${ip}${merchantTransactionId}`;
  const hash = crypto.createHash('sha512').update(data).digest('hex');
  return `v2:${hash}`;
}

// Example
const signature = generateSignature(
  '0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
  'your_secret_key_123',
  '192.168.1.1',
  'tx_123456'
);
// Result: "v2:83a6473f7b0aade8cd794c38f435d8db..."

Python

import hashlib

def generate_signature(address: str, secret: str, ip: str, merchant_transaction_id: str) -> str:
    data = f"{address}{secret}{ip}{merchant_transaction_id}"
    hash_value = hashlib.sha512(data.encode()).hexdigest()
    return f"v2:{hash_value}"

# Example
signature = generate_signature(
    '0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
    'your_secret_key_123',
    '192.168.1.1',
    'tx_123456'
)
# Result: "v2:83a6473f7b0aade8cd794c38f435d8db..."

Go

package main

import (
    "crypto/sha512"
    "encoding/hex"
    "fmt"
)

func generateSignature(address, secret, ip, merchantTransactionID string) string {
    data := address + secret + ip + merchantTransactionID
    hash := sha512.Sum512([]byte(data))
    return fmt.Sprintf("v2:%s", hex.EncodeToString(hash[:]))
}

Signature v3

Step 1 — Get the Encryption Key

Request the v3 encryption public key from your integration manager. This key is separate from your widget's Secret key.

Step 2 — Encrypt the User's IP

  1. Take the IP address of the user opening the widget (IPv4 or IPv6), as seen by your backend.
  2. Encrypt the IP as a text string (for example, 203.0.113.45) with the public key using a sealed box (crypto_box_seal from libsodium).
  3. Encode the result as base64url without padding (- and _ instead of + and /, no trailing =), so the value can be added to the URL without extra encoding.

The result is the sealed_ip value.

Libraries:

  • Node.js — libsodium-wrappers
  • PHP — sodium extension (built-in)
  • Python — PyNaCl
  • Go — golang.org/x/crypto/nacl/box
  • Java — lazysodium-java

Note: Encryption produces a different value every time, even for the same IP. Generate sealed_ip once per widget URL and use the same string both in the signature and in the URL.

Step 3 — Generate the Signature

Concatenate the values without spaces, compute a SHA-512 hash of that string and prefix it with v3:.

With merchant_transaction_id:

address + secret + sealed_ip + merchant_transaction_id

Without merchant_transaction_id:

address + secret + sealed_ip

Parameters:

  • address — the user's cryptocurrency wallet address
  • secret — your widget's Secret key from the Dashboard (Widgets → select widget → Secret)
  • sealed_ip — the encrypted IP from Step 2 (not the raw IP)
  • merchant_transaction_id — your internal transaction ID (optional)

Note: If you pass merchant_transaction_id in the widget URL, it must be included in the signature, and vice versa.

Step 4 — Build the Widget URL

Add sealed_ip and signature to the widget URL:

https://exchange.mercuryo.io/?widget_id=YOUR_WIDGET_ID
  &address=0x742d35Cc6634C0532925a3b844Bc454e4438f44e
  &merchant_transaction_id=tx_123456
  &sealed_ip=SEALED_IP
  &signature=v3:GENERATED_SIGNATURE

Note: address, sealed_ip and merchant_transaction_id (if used) in the URL must have exactly the same values used for the signature. If any of them is missing or differs, signature validation will fail.

Code Examples

The examples use the formula with merchant_transaction_id. If you don't use it, pass an empty string.

JavaScript (Node.js)

const crypto = require('crypto');
const sodium = require('libsodium-wrappers');

async function generateSealedIp(ip, publicKey) {
  await sodium.ready;
  const key = sodium.from_base64(publicKey, sodium.base64_variants.ORIGINAL);
  const sealed = sodium.crypto_box_seal(ip, key);
  return sodium.to_base64(sealed, sodium.base64_variants.URLSAFE_NO_PADDING);
}

function generateSignature(address, secret, sealedIp, merchantTransactionId) {
  const data = `${address}${secret}${sealedIp}${merchantTransactionId}`;
  const hash = crypto.createHash('sha512').update(data).digest('hex');
  return `v3:${hash}`;
}

// Example (inside an async function)
const sealedIp = await generateSealedIp('192.168.1.1', 'your_encryption_public_key');
const signature = generateSignature(
  '0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
  'your_secret_key_123',
  sealedIp,
  'tx_123456'
);
// Result: "v3:..."

Python

import base64
import hashlib
from nacl.public import PublicKey, SealedBox

def generate_sealed_ip(ip: str, public_key: str) -> str:
    box = SealedBox(PublicKey(base64.b64decode(public_key)))
    sealed = box.encrypt(ip.encode())
    return base64.urlsafe_b64encode(sealed).rstrip(b"=").decode()

def generate_signature(address: str, secret: str, sealed_ip: str, merchant_transaction_id: str) -> str:
    data = f"{address}{secret}{sealed_ip}{merchant_transaction_id}"
    hash_value = hashlib.sha512(data.encode()).hexdigest()
    return f"v3:{hash_value}"

# Example
sealed_ip = generate_sealed_ip('192.168.1.1', 'your_encryption_public_key')
signature = generate_signature(
    '0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
    'your_secret_key_123',
    sealed_ip,
    'tx_123456'
)
# Result: "v3:..."

Go

package main

import (
    "crypto/rand"
    "crypto/sha512"
    "encoding/base64"
    "encoding/hex"
    "fmt"

    "golang.org/x/crypto/nacl/box"
)

func generateSealedIP(ip, publicKey string) (string, error) {
    keyBytes, err := base64.StdEncoding.DecodeString(publicKey)
    if err != nil || len(keyBytes) != 32 {
        return "", fmt.Errorf("invalid public key")
    }
    var key [32]byte
    copy(key[:], keyBytes)
    sealed, err := box.SealAnonymous(nil, []byte(ip), &key, rand.Reader)
    if err != nil {
        return "", err
    }
    return base64.RawURLEncoding.EncodeToString(sealed), nil
}

func generateSignature(address, secret, sealedIP, merchantTransactionID string) string {
    data := address + secret + sealedIP + merchantTransactionID
    hash := sha512.Sum512([]byte(data))
    return fmt.Sprintf("v3:%s", hex.EncodeToString(hash[:]))
}

Try It: Signature Calculator

To verify your implementation, use the calculator below to generate a signature and compare it against the one your server produces.

Note: The hash is computed locally using your browser. For v3, paste the sealed_ip value generated by your backend — the calculator does not encrypt the IP. Merchant Transaction ID is optional.

Callback Signature

Each callback includes an X-Signature header containing an HMAC SHA-256 hash of the raw JSON body, generated using your widget's Sign Key from the Dashboard (Widgets → select widget → Sign Key).

Important: Use the complete raw JSON body exactly as received — do not parse, reformat, or extract fields from it. Any modification will produce a different hash and cause verification to fail.

Code Examples

JavaScript

const crypto = require('crypto');

function verifyCallbackSignature(rawBody, signature, signKey) {
  const hmac = crypto.createHmac('sha256', signKey);
  const calculated = hmac.update(rawBody).digest('hex');
  return calculated === signature;
}

Python

import hmac
import hashlib

def verify_callback_signature(raw_body: str, signature: str, sign_key: str) -> bool:
    calculated = hmac.new(sign_key.encode(), raw_body.encode(), hashlib.sha256).hexdigest()
    return calculated == signature

Go

import (
    "crypto/hmac"
    "crypto/sha256"
    "encoding/hex"
)

func verifyCallbackSignature(rawBody, signature, signKey string) bool {
    h := hmac.New(sha256.New, []byte(signKey))
    h.Write([]byte(rawBody))
    return hex.EncodeToString(h.Sum(nil)) == signature
}

Try It: Callback Signature Calculator

Paste your raw callback body and Sign Key to verify your implementation.

Note: The hash is computed locally using your browser.