Scan your whole stack
Are you using @midnightntwrk/midnight-js?
Find out what’s in your code.
Scan your apps free in minutes (opens in a new tab)Latest version: v5.0.3-0-pre.607399e7
@midnightntwrk/midnight-js was last scanned on 24 Nov 2026 at version 5.0.3-0-pre.607399e7. Risk score 0 of 100. No malicious behavior was detected.
| Version | Published | Status |
|---|---|---|
| 5.0.3-0-pre.607399e7 LATEST | 24 Nov 2026 | No rules fired |
| 5.0.3-0-pre.325b875e | 24 Nov 2026 | No rules fired |
| 5.0.3-0-pre.3373fadc | 24 Nov 2026 | No rules fired |
| 5.0.3-0-pre.a94adcc4 | 23 Nov 2026 | Not shown |
| 5.0.3-0-pre.63208040 | 23 Nov 2026 | Not shown |
Findings for v5.0.3-0-pre.607399e7. The score is a capped sum of the weights of the rules that fired — not CVSS, not exploitability, and not a probability. It is not comparable across packages with different scan coverage.
The score describes 5.0.3-0-pre.607399e7; other versions have their own rules, not their own score.
The publisher’s own README, as collected from the registry.
Barrel package that provides a single entry point to the core components of Midnight.js. Import all core modules from one package instead of installing them individually.
yarn add @midnightntwrk/midnight-js
import { contracts, types, utils } from '@midnightntwrk/midnight-js';
// providers.config carries the network id: { networkId: 'preview', ttlSeconds: 3600 }
const deployed = await contracts.deployContract(providers, {
compiledContract: myContract,
privateStateId: 'my-state',
initialPrivateState: { counter: 0n }
});
| Module | Package | Description |
|---|---|---|
contracts |
@midnightntwrk/midnight-js-contracts |
Contract deployment and interaction utilities |
types |
@midnightntwrk/midnight-js-types |
Shared types, interfaces, and provider contracts |
utils |
@midnightntwrk/midnight-js-utils |
Hex encoding, address validation, and utilities |
The network runs one of two ledger eras, v8 or v9. The names for saying
which era produced a payload or a record are re-exported from the barrel
directly, alongside the namespaces above:
import {
LEDGER_ERAS, // the closed, frozen set: ['v8', 'v9']
CURRENT_LEDGER_ERA, // the current era, 'v9': the `era` of every current-era result
type LedgerEra, // 'v8' | 'v9'
versionOfRecord, // a record carrying protocolVersion -> LedgerEra
latestNetworkLedgerVersion // asks a source for the network's current ledger era -> LedgerEra
} from '@midnightntwrk/midnight-js';
Use versionOfRecord for a protocolVersion read off an existing record, and
latestNetworkLedgerVersion for the era a transaction built now would land in. Each
tags its failures with the path it was called on, so a handler can tell the two
apart.
Both refuse rather than guess. They raise UnknownProtocolVersionError when a
protocolVersion is malformed (not a non-negative integer) or is well-formed
but maps to no era this build knows. versionOfRecord throws;
latestNetworkLedgerVersion is async, so it rejects instead, and a rejection from
the source itself propagates unchanged.
import {
type ProtocolVersionUnknownReason,
UnknownProtocolVersionError,
versionOfRecord,
type VersionResolutionPath
} from '@midnightntwrk/midnight-js';
// Any record carrying a raw protocolVersion -- e.g. a transaction or block
// already read from the indexer. Node major 9 is one this build has no era
// for, so this record takes the failure path.
const record = { protocolVersion: 9_000_000 };
try {
const era = versionOfRecord(record);
console.log(`this record was written under ledger ${era}`);
} catch (error) {
// Anything that is not ours is not ours to interpret. Never swallow it.
if (!(error instanceof UnknownProtocolVersionError)) {
throw error;
}
const path: VersionResolutionPath = error.path; // 'read' | 'construct'
const reason: ProtocolVersionUnknownReason = error.reason; // 'unknown' | 'malformed'
throw new Error(
reason === 'unknown'
? `This record is from a ledger era this build does not know (${path} path). Upgrade midnight-js.`
: `The protocolVersion handed to versionOfRecord was malformed (${path} path). Check the source record.`,
{ cause: error }
);
}
Both eras are worth handling explicitly, because the two reasons need different
responses: 'unknown' means this framework build predates the network, and
'malformed' means the wrong field was wired into the resolver.
If you would rather discriminate on a stable string than on a class, every
error here also carries a code. PROTOCOL_ERROR_CODES names them and
utils.hasErrorCode is the guard:
import { PROTOCOL_ERROR_CODES, utils } from '@midnightntwrk/midnight-js';
if (utils.hasErrorCode(error, PROTOCOL_ERROR_CODES.UNKNOWN_PROTOCOL_VERSION_READ)) {
// the era of an existing record could not be resolved
}
Deploying to or calling a v8 contract runs through the retained pre-fork
pipeline, which raises errors of its own. The barrel publishes those classes
too, so you can catch them and read their payload without a cast:
| Class | Payload | Means |
|---|---|---|
Ledger8RuntimeMissingError |
subpath |
the retained runtime chunk could not be loaded at all |
ComposeFailedError |
version, stage, circuitId |
a circuit operation is missing or under-registered |
ComposeOptionError |
version, option |
one composition option cannot be used |
StateDecodeFailedError |
version |
contract-state bytes could not be read as that era |
StateInconsistentError |
version |
contract-state bytes were read as that era, but the state is internally inconsistent |
UnknownLedgerEraError |
requestedVersion |
the value names an era outside LEDGER_ERAS, or carries no era (requestedVersion is undefined: a pre-5.0.0 provider) |
PayloadNotATransactionError |
none | a v8 payload sent for proving was not a transaction |
The retained pre-fork (v8) ledger runtime is not re-exported here, and it
is absent from the barrel's static import graph. It is loaded on demand, only
once you actually touch a v8 contract.
Importing the barrel is not otherwise free: it pulls the v9 ledger and
onchain-runtime, because contracts needs them. The sub-path imports below let
you take one module without the rest.
Each module is also available as a sub-path import for tree-shaking:
import { deployContract, findDeployedContract } from '@midnightntwrk/midnight-js/contracts';
import { type ProofProvider, type WalletProvider } from '@midnightntwrk/midnight-js/types';
import { toHex, fromHex } from '@midnightntwrk/midnight-js/utils';
// Namespace imports (all modules)
import { contracts, types, utils } from '@midnightntwrk/midnight-js';
// Ledger era vocabulary (named, not namespaced)
import { LEDGER_ERAS, type LedgerEra } from '@midnightntwrk/midnight-js';
// Sub-path imports (individual modules)
import { ... } from '@midnightntwrk/midnight-js/contracts';
import { ... } from '@midnightntwrk/midnight-js/types';
import { ... } from '@midnightntwrk/midnight-js/utils';
By using this package, you agree to Midnight's Terms and Conditions and Privacy Policy.
Licensed under Apache License 2.0.
Find threats in your stack.
OX Radar can check high-priority threats, like critical package CVEs, against your context.
Each incident is marked Detected or Not Detected with a remediation plan and proof all tracked in the Response Center.
The probe returned only these fields for this server — auth requirement, protocol and tool list weren’t observed, so they’re not shown (never guessed).
The publisher’s own links, as the registry reports them. These are not sources for the assessment on this page.