Skip to content
DEVELOPER REFERENCE

API Reference

Complete technical specifications for the Morpheus smart contracts and the Enclave Javascript SDK.

1. Smart Contract Interface (Neo N3 C#)

The active on-chain interface is the Neo N3 C# call pattern below.

Oracle Call Pattern
// Neo N3 Mainnet Oracle: 0xf54d8584ef82315c1800373272ab08ae0db2d5ef

string payloadJson = "{"symbol":"TWELVEDATA:NEO-USD","json_path":"price","target_chain":"neo_n3"}";

Contract.Call(
 MorpheusOracleHash,
 "request",
 CallFlags.All,
 "privacy_oracle",
 (ByteString)payloadJson,
 Runtime.ExecutingScriptHash,
 "onOracleResult"
);

To interact with the Morpheus Oracle on Neo N3 Mainnet, use Contract.Call against 0xf54d8584ef82315c1800373272ab08ae0db2d5ef or NeoNS oracle.morpheus.neo.

2. NeoDID Resolution

NeoDID now also exposes a W3C DID resolution route for public service discovery and subject namespaces:

GET /api/neodid/resolve
GET /api/neodid/resolve?did=did:morpheus:neo_n3:service:neodid
Accept: application/ld+json;profile="https://w3id.org/did-resolution"

GET /api/neodid/resolve?did=did:morpheus:neo_n3:vault:6d0656f6dd91469db1c90cc1e574380613f43738&format=document
Accept: application/did+ld+json

The resolver exposes the public service DID document, TEE verifier JWK, registry anchors, and subject namespaces without leaking provider UIDs or nullifiers.

3. Enclave SDK (Javascript)

When using built-in compute, Morpheus exposes a fixed catalog of functions. Custom JS compute receives input and helpers; Oracle custom JS receives data, context, and helpers.

hash.sha256Hash

Hashes any JSON-serializable payload with SHA-256.

// PARAMETERS
input: any
// EXAMPLE
const digest = await morpheus.hash.sha256({ data: '...' });
hash.keccak256Hash

Hashes any JSON-serializable payload with Keccak-256.

// PARAMETERS
input: any
// EXAMPLE
const digest = await morpheus.hash.keccak256({ data: '...' });
crypto.rsa_verifyCrypto

Verifies an RSA-SHA256 signature (computationally efficient in TEE).

// PARAMETERS
public_key: string, signature: string, payload: string
// EXAMPLE
const isValid = await morpheus.crypto.rsa_verify(input);
math.modexpMath

Performs big integer modular exponentiation.

// PARAMETERS
base: string, exponent: string, modulus: string
// EXAMPLE
const result = await morpheus.math.modexp({ base: '2', exponent: '10', modulus: '100' });
math.polynomialMath

Evaluates a polynomial of arbitrary degree.

// PARAMETERS
coefficients: string[], x: string, modulus?: string
// EXAMPLE
const y = await morpheus.math.polynomial({ coefficients: ['1', '0', '1'], x: '2' });
matrix.multiplyLinear Algebra

Multiplies two dense matrices.

// PARAMETERS
left: number[][], right: number[][]
// EXAMPLE
const matrix = await morpheus.matrix.multiply({ left: [[1,2]], right: [[3],[4]] });
vector.cosine_similarityLinear Algebra

Computes cosine similarity between two vectors.

// PARAMETERS
left: number[], right: number[]
// EXAMPLE
const sim = await morpheus.vector.cosine_similarity({ left: [1,0], right: [0,1] });
merkle.rootMerkle

Builds a SHA-256 Merkle root from a list of leaves.

// PARAMETERS
leaves: string[]
// EXAMPLE
const root = await morpheus.merkle.root({ leaves: ['a', 'b', 'c'] });
zkp.public_signal_hashZKP

Computes a deterministic digest over public signals.

// PARAMETERS
circuit_id: string, signals: any[]
// EXAMPLE
const hash = await morpheus.zkp.public_signal_hash({ circuit_id: '...', signals: [] });
zkp.proof_digestZKP

Computes a deterministic digest over a proof object and optional verifying key.

// PARAMETERS
proof: any, verifying_key?: any
// EXAMPLE
const digest = await morpheus.zkp.proof_digest({ proof, verifying_key });
zkp.witness_digestZKP

Computes a digest over witness material before proving.

// PARAMETERS
witness: any, circuit_id?: string
// EXAMPLE
const digest = await morpheus.zkp.witness_digest({ witness, circuit_id: '<circuit-id>' });
zkp.groth16.verifyZKP

Verifies a Groth16 proof against a verifying key and public signals.

// PARAMETERS
verifying_key: any, public_signals: any[], proof: any
// EXAMPLE
const verdict = await morpheus.zkp.groth16.verify({ verifying_key, public_signals, proof });
zkp.groth16.prove.planZKP

Returns a planning estimate for Groth16 proving workloads.

// PARAMETERS
constraints: number, witness_count: number
// EXAMPLE
const plan = await morpheus.zkp.groth16.prove.plan({ constraints: 120000, witness_count: 4096 });
zkp.plonk.prove.planZKP

Returns a planning estimate for PLONK proving workloads.

// PARAMETERS
gates: number
// EXAMPLE
const plan = await morpheus.zkp.plonk.prove.plan({ gates: 90000 });
zkp.zerc20.single_withdraw.verifyZKP

Checks zERC20 single-withdraw public inputs and can optionally run Groth16 verification.

// PARAMETERS
public_inputs: object, verifying_key: any, proof: any
// EXAMPLE
const verdict = await morpheus.zkp.zerc20.single_withdraw.verify({ public_inputs, proof, verifying_key });
fhe.batch_planFHE

Builds a ciphertext batching plan.

// PARAMETERS
slot_count: number, ciphertext_count: number
// EXAMPLE
const plan = await morpheus.fhe.batch_plan({ slot_count: 4096, ciphertext_count: 8 });
fhe.noise_budget_estimateFHE

Estimates a rough FHE noise budget.

// PARAMETERS
multiplicative_depth: number, scale_bits: number, modulus_bits: number
// EXAMPLE
const estimate = await morpheus.fhe.noise_budget_estimate({ multiplicative_depth: 4, scale_bits: 40, modulus_bits: 218 });
fhe.rotation_planFHE

Returns a rotation and key-switch planning summary.

// PARAMETERS
indices: number[]
// EXAMPLE
const plan = await morpheus.fhe.rotation_plan({ indices: [1, 3, -2] });
privacy.maskPrivacy

Masks a sensitive string, leaving edges visible.

// PARAMETERS
value: string, unmasked_left: number, unmasked_right: number
// EXAMPLE
const masked = await morpheus.privacy.mask({ value: 'secret_key', unmasked_left: 2, unmasked_right: 2 });
privacy.add_noisePrivacy

Adds simulated Laplace noise for differential privacy.

// PARAMETERS
value: number, scale: number
// EXAMPLE
const noisy = await morpheus.privacy.add_noise({ value: 100, scale: 1.0 });

4. Public HTTP API

The Vercel edge app exposes a small set of public JSON endpoints in front of the enclave. All bodies are JSON. POST routes are IP rate-limited; on overflow they return 429 with { error: "Too many requests", retryAfter }. Every rate-limited response carries X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset (ISO-8601), and Retry-After (seconds) headers.

MethodPathRate limitDescription
POST/api/oracle/query30 / minute / IPOff-chain provider fetch + TEE-signed result preview (provider-aware payload resolution).
POST/api/oracle/smart-fetch20 / minute / IPHeuristic provider selection variant of /api/oracle/query.
POST/api/compute/execute20 / minute / IPRun a builtin or custom-JS compute function inside the enclave. Requires target_chain to be neo_n3 when supplied.
GET/api/feeds/[symbol]unmetered (read)Latest price quote for a symbol. Accepts ?provider, ?project_slug, ?provider_params (URL-encoded JSON).

Degraded / fallback shapes

When an upstream provider is unavailable, GET /api/feeds/[symbol] responds with HTTP 200 and a degraded envelope (so callers can distinguish "no quote" from a request error). The upstream status is also surfaced in the x-morpheus-upstream-status header. Invalid input returns HTTP 400 with { error: "..." }.

jsonGET /api/feeds/NEO-USD (degraded)
{
  "status": "unavailable",
  "degraded": true,
  "symbol": "NEO-USD",
  "provider": "twelvedata",
  "error": "feed_quote_unavailable",
  "upstream_status": 503
}
CURRENT DESIGNUPDATED FOR DUAL-CVM ARCHITECTURE