npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nxapi-znca-api

v1.5.0

Published

Nintendo Switch app APIs

Downloads

7

Readme

nxapi znca API server

This repository contains a server for generating f parameters required to authenticate to the Nintendo Switch Online app API. This was previously part of nxapi (GitHub), a library and command line and Electron app for using Nintendo's smart device app APIs.

This uses Frida to call the token generation functions in the Nintendo Switch Online app on a rooted Android device.

This server can be self hosted to avoid sending access tokens to third party APIs.

Public API

A server running this API is available at https://nxapi-znca-api.fancy.org.uk/api/znca. If you would like to use this set a User-Agent header including your project's name and version number (and contact information if your project is not easily discoverable, e.g. on GitHub), and send me a message in the nxapi Discord server. If your project authenticates as the user's Nintendo Account you must explain that their id_token will be sent to a third-party API, and include a link to here.

Status is available at https://nxapi-status.fancy.org.uk. Usage stats are available at https://ubuntu-2204-vm-test.fancy.org.uk/grafana/public-dashboards/57854670274a4ddf98b12332a6c47cf4.

The API is mostly compatible with the imink API, however:

  • If the timestamp and/or request_id options are included in the request body they will not be included in the response.
  • The X-znca-Platform and X-znca-Version headers should be used to indicate which version of the Nintendo Switch Online app should be used.
    • This makes it easier to migrate to newer versions of the app and prevents using invalid f parameters when the client version (the X-ProductVersion header sent to Nintendo's API) does not match the version used to generate f.
    • If these headers are not sent, any version available on the server will be used.
    • /api/znca/config can be used to get the latest supported app version. This is compatible with the imink API's /config endpoint.

See docs/api.md for API usage details.

Requirements

  • adb is installed on the computer running the server
  • The Android device is running adbd as root or a su-like command can be used to escalate to root
  • The frida-server executable is located at /data/local/tmp/frida-server on the Android device (a different path can be provided using the --frida-server-path option)
  • The Nintendo Switch Online app is installed on the Android device

No other software (e.g. frida-tools) needs to be installed on the computer running nxapi. The Android device must be constantly reachable using ADB. The server will attempt to reconnect to the Android device and will automatically retry any requests that would fail due to the device disconnecting. The server will exit if it fails to reconnect to the device. A service manager should be used to restart the server if it exits.

The service can also run in a container. The Android device can also run in a container using redroid. See Docker.

Install

Install with npm

Node.js and npm must already be installed.

# From registry.npmjs.com
npm install --global nxapi-znca-api

# From gitlab.fancy.org.uk
npm install --global --registry https://gitlab.fancy.org.uk/api/v4/packages/npm/ @samuel/nxapi-znca-api

# From npm.pkg.github.com
npm install --global --registry https://npm.pkg.github.com @samuelthomas2774/nxapi-znca-api

# From gitlab.com
npm install --global --registry https://gitlab.com/api/v4/packages/npm/ @samuelthomas2774/nxapi-znca-api

Install from source

Node.js and npm must already be installed.

# Don't download an archive, as nxapi detects the current git revision
git clone https://gitlab.fancy.org.uk/samuel/nxapi-znca-api.git
cd nxapi-znca-api

npm install
npx tsc
npm link

# Build Docker image
docker build . --tag registry.fancy.org.uk/samuel/nxapi-znca-api
# # Run in Docker
# docker run -it --rm -v ./data:/data registry.fancy.org.uk/samuel/nxapi-znca-api ...

Docker

A docker-compose project using a redroid container is included.

# Don't download an archive, as nxapi detects the current git revision
git clone https://gitlab.fancy.org.uk/samuel/nxapi-znca-api.git
cd nxapi-znca-api

# Optionally build Docker image (by default docker-compose will pull the latest version from Docker Hub)
# docker build . --tag registry.fancy.org.uk/samuel/nxapi-znca-api --tag samuelthomas2774/nxapi-znca-api

# Load kernel modules for redroid
modprobe binder_linux devices="binder,hwbinder,vndbinder"
modprobe ashmem_linux

# The URL to download the Nintendo Switch Online app from must be provided (a .env file can also be used)
CORAL_APK_URL="https://example.com/com.nintendo.znca-2.4.0.apk" docker compose up -d

Usage

The server can be run using the nxapi-znca-api android-frida-server command.

# Start the server using the ADB server "android.local:5555" listening on all interfaces on a random port
nxapi-znca-api android-frida-server android.local:5555

# Start the server listening on a specific address/port
# The `--listen` option can be used multiple times
nxapi-znca-api android-frida-server android.local:5555 --listen "[::1]:12345"

# Use a command to escalate to root to start frida-server and the Nintendo Switch Online app
# "{cmd}" will be replaced with the path to a temporary script in double quotes
nxapi-znca-api android-frida-server android.local:5555 --exec-command "/system/bin/su -c {cmd}"

# Specify a different location for the adb executable if it is not in the search path
nxapi-znca-api android-frida-server android.local:5555 --adb-path "/usr/local/bin/adb"

# Run `adb root` when connecting to the device to restart adbd as root
nxapi-znca-api android-frida-server android.local:5555 --adb-root

# Specify a different location for the frida-server executable on the device
nxapi-znca-api android-frida-server android.local:5555 --frida-server-path "/data/local/tmp/frida-server-15.1.17-android-arm"

# Use Frida to start the app on the device (even if it is already running) (recommended)
nxapi-znca-api android-frida-server android.local:5555 --start-method spawn
# Use `am start-activity` to ensure the app process is running
nxapi-znca-api android-frida-server android.local:5555 --start-method activity
# Use `am start-service` to ensure the app process is running, without causing Android to show the app (default)
nxapi-znca-api android-frida-server android.local:5555 --start-method service
# Do not attempt to start the app on the device automatically - this will cause the server to fail if the app is not already running
nxapi-znca-api android-frida-server android.local:5555 --start-method none

# Strictly validate the timestamp and request_id parameters sent by the client are likely to be accepted by Nintendo's API
nxapi-znca-api android-frida-server android.local:5555 --strict-validate

# Don't validate the token sent by the client
nxapi-znca-api android-frida-server android.local:5555 --no-validate-tokens

# Docker
# From docker.io
docker run -it --rm -v ./data:/data samuelthomas2774/nxapi-znca-api ...
# From gitlab.fancy.org.uk
docker run -it --rm -v ./data:/data registry.fancy.org.uk/samuel/nxapi-znca-api ...

See docs/api.md for API usage details.