Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
1815ec2
typescript sdk
UnArbosSix Jul 10, 2026
dc041b1
fix mnemonics
UnArbosSix Jul 10, 2026
d5bf752
fix formatting
UnArbosSix Jul 10, 2026
ebe31a7
ts e2es use ts sdk
UnArbosSix Jul 11, 2026
69a636a
Update basic.test.cjs
UnArbosSix Jul 11, 2026
9943d40
Merge branch 'bittensor-core-exploration' into bittensor-core-typescr…
UnArbosSix Jul 11, 2026
90e4198
fix review
UnArbosSix Jul 11, 2026
89cd213
clippy
UnArbosSix Jul 11, 2026
d1ef788
fix warnings
UnArbosSix Jul 11, 2026
fa59bcb
Merge branch 'bittensor-core-exploration' into bittensor-core-typescr…
UnArbosSix Jul 11, 2026
8890ace
fix sdk build
UnArbosSix Jul 11, 2026
4b6e0ed
fix build post-merge
UnArbosSix Jul 11, 2026
a630667
Move key derivation into Rust & finish names
UnArbosSix Jul 11, 2026
8b9f190
fix keys
UnArbosSix Jul 11, 2026
4b40b22
add browser support
UnArbosSix Jul 11, 2026
586a460
add features from old bittensor
UnArbosSix Jul 11, 2026
3a38161
fix ts sdk job
UnArbosSix Jul 11, 2026
d80e20e
fix keys
UnArbosSix Jul 11, 2026
8d34eff
try fix typescript sdk again
UnArbosSix Jul 11, 2026
86af620
fix browser gap
UnArbosSix Jul 11, 2026
1979344
Update typescript-e2e.yml
UnArbosSix Jul 11, 2026
f0183d8
fix parity check
UnArbosSix Jul 11, 2026
17fe74e
fix
UnArbosSix Jul 11, 2026
3ce5325
fix ledger
UnArbosSix Jul 11, 2026
437b717
fix ts e2e
UnArbosSix Jul 11, 2026
800a45e
fix runtime metadata
UnArbosSix Jul 11, 2026
d7153bc
fix
UnArbosSix Jul 11, 2026
423b73b
try fix e2e ts again
UnArbosSix Jul 11, 2026
cca254e
fix nonce
UnArbosSix Jul 11, 2026
d5fbc3b
fix e2e
UnArbosSix Jul 11, 2026
0351315
Keep sp-core/std out of the portable WASM
UnArbosSix Jul 11, 2026
a8fa5a7
fix leak
UnArbosSix Jul 12, 2026
e32ad17
fmt
UnArbosSix Jul 12, 2026
3a174b0
fix js version
UnArbosSix Jul 12, 2026
112a89d
Restore parity validation for the browser wrapper
UnArbosSix Jul 12, 2026
6291648
rename to bittensor-ts
UnArbosSix Jul 12, 2026
766dbe0
fix for review
UnArbosSix Jul 12, 2026
8cd9033
fix ci
UnArbosSix Jul 12, 2026
cb54cb3
another round of improvments
UnArbosSix Jul 12, 2026
1b0a474
Update generate-esm.cjs
UnArbosSix Jul 12, 2026
d1c9ae8
another round of fixes
UnArbosSix Jul 12, 2026
f7166e7
use get_subnet_hyperparams_v3
UnArbosSix Jul 12, 2026
7fb7777
finish impl
UnArbosSix Jul 12, 2026
c8bf57c
more fixes
UnArbosSix Jul 12, 2026
8aede23
fixes
UnArbosSix Jul 12, 2026
3f288d6
Merge branch 'bittensor-core-exploration' into bittensor-core-typescr…
UnArbosSix Jul 12, 2026
4eeb1b6
Fix CI
UnArbosSix Jul 12, 2026
0e9679b
fix rpc stuff
UnArbosSix Jul 12, 2026
3557d6b
fix typecheck
UnArbosSix Jul 12, 2026
1ae69cc
cleanup
UnArbosSix Jul 12, 2026
5a285e1
fix CI again
UnArbosSix Jul 12, 2026
d713c32
address auditor review
UnArbosSix Jul 12, 2026
dc718f7
fix inaccurate job names
UnArbosSix Jul 12, 2026
6bfcd61
another round of fixes
UnArbosSix Jul 12, 2026
b430828
fix e2e
UnArbosSix Jul 12, 2026
7ab5ca4
another review round
UnArbosSix Jul 12, 2026
4625c5c
another review round
UnArbosSix Jul 12, 2026
1c55023
clippy
UnArbosSix Jul 12, 2026
3d50eb0
Merge branch 'main' into bittensor-core-typescript-sdk
UnArbosSix Jul 12, 2026
47dceba
use new rust from merge
UnArbosSix Jul 12, 2026
1f4e856
fixes
UnArbosSix Jul 12, 2026
7b21070
fmt
UnArbosSix Jul 12, 2026
e05308f
fixes
UnArbosSix Jul 13, 2026
cb479d5
fis TS checks
UnArbosSix Jul 13, 2026
252c684
try fix ci
UnArbosSix Jul 13, 2026
10c3b09
fix CI
UnArbosSix Jul 13, 2026
ce5f46c
cover all old ts e2e in new
UnArbosSix Jul 13, 2026
46ac117
more fixes
UnArbosSix Jul 13, 2026
d4a5748
Merge main
UnArbosSix Jul 13, 2026
05b51b2
Use bittensor SDK helpers in ts-tests
UnArbosSix Jul 13, 2026
ae80118
Update test-bittensor-ts.ts
UnArbosSix Jul 13, 2026
715d6db
fixes
UnArbosSix Jul 13, 2026
fb8e11c
fix browser smoke
UnArbosSix Jul 13, 2026
4d9633e
use hyperparams v3
UnArbosSix Jul 13, 2026
ca6453e
fix CI
UnArbosSix Jul 13, 2026
d3afb99
Fix TS SDK test and clippy allow
UnArbosSix Jul 13, 2026
547179f
clippy
UnArbosSix Jul 13, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 58 additions & 1 deletion .github/workflows/typescript-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ jobs:
-o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" \
build-essential clang curl git make libssl-dev llvm libudev-dev protobuf-compiler pkg-config

- name: Install TypeScript SDK dependencies
run: npm --prefix sdk/typescript-sdk ci

- name: Type-check TypeScript SDK
run: npm --prefix sdk/typescript-sdk run typecheck

- name: Install e2e dependencies
working-directory: ts-tests
run: pnpm install --frozen-lockfile
Expand All @@ -83,6 +89,51 @@ jobs:
cd ts-tests
pnpm run fmt

build-typescript-sdk:
runs-on: [self-hosted, fireactions-heavy]
needs: [trusted-pr, typescript-formatting]
timeout-minutes: 60
steps:
- name: Check-out repository
uses: actions/checkout@v4

- name: Install system dependencies
run: |
sudo DEBIAN_FRONTEND=noninteractive NEEDRESTART_MODE=a apt-get update
sudo DEBIAN_FRONTEND=noninteractive NEEDRESTART_MODE=a apt-get install -y --no-install-recommends \
-o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" \
build-essential clang curl git make libssl-dev llvm libudev-dev protobuf-compiler pkg-config

- name: Install Rust
uses: dtolnay/rust-toolchain@4be7066ada62dd38de10e7b70166bc74ed198c30 # stable

- name: Utilize Shared Rust Cache
uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32 # v2
with:
key: typescript-sdk
cache-on-failure: true

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: ts-tests/.nvmrc

- name: Build and test TypeScript SDK
run: |
npm --prefix sdk/typescript-sdk ci
npm --prefix sdk/typescript-sdk run check
Comment thread
UnArbosSix marked this conversation as resolved.
Outdated

- name: Upload TypeScript SDK build
uses: actions/upload-artifact@v4
with:
name: bittensor-typescript-sdk
path: |
sdk/typescript-sdk/dist
sdk/typescript-sdk/native.cjs
sdk/typescript-sdk/native.generated.d.ts
sdk/typescript-sdk/*.node
if-no-files-found: error

# Build the node binary in both variants and share as artifacts.
build:
runs-on: [self-hosted, fireactions-heavy]
Expand Down Expand Up @@ -129,7 +180,7 @@ jobs:
if-no-files-found: error

run-e2e-tests:
needs: [trusted-pr, build]
needs: [trusted-pr, build, build-typescript-sdk]
Comment thread
UnArbosSix marked this conversation as resolved.
Outdated
Comment thread
UnArbosSix marked this conversation as resolved.
Outdated
runs-on: [self-hosted, fireactions-heavy]
timeout-minutes: 30

Expand Down Expand Up @@ -165,6 +216,12 @@ jobs:
- name: Make binary executable
run: chmod +x target/release/node-subtensor

- name: Download TypeScript SDK build
uses: actions/download-artifact@v4
with:
name: bittensor-typescript-sdk
path: sdk/typescript-sdk

- name: Setup Node.js
uses: actions/setup-node@v4
with:
Expand Down
102 changes: 100 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ members = [
"primitives/*",
"runtime",
"sdk/bittensor-core",
"sdk/typescript-sdk/native",
"sdk/bittensor-core-py",
"support/*",
"chain-extensions",
Expand Down
7 changes: 7 additions & 0 deletions sdk/typescript-sdk/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules/
dist/
native.cjs
native.generated.d.ts
*.node
*.node.map
npm-debug.log*
71 changes: 71 additions & 0 deletions sdk/typescript-sdk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# `@bittensor/sdk`

The monorepo's TypeScript SDK. It lives in its own `sdk/typescript-sdk`
package and is a deliberately thin Node-API wrapper around the sibling
`bittensor-core` Rust crate.

All chain-defined work runs in Rust:

- sr25519/ed25519 keys, signatures, SS58, and wallet keyfiles;
- SCALE encoding and decoding, runtime metadata, storage keys, calls, and
signed extrinsics;
- RFC-0078 metadata digests and Ledger proofs;
- drand timelock encryption and epoch-schedule simulation;
- ML-KEM/XChaCha20 MEV-shield envelopes; and
- Ledger HID signing.

The TypeScript layer is limited to JavaScript-friendly names and defaults,
lossless `Buffer`/`bigint`/`Map` boundary conversion, error classes, and
compatibility adapters for the signer objects expected by Polkadot.js,
Polkadot API, and Moonwall.

The package exposes both CommonJS and ESM entrypoints. It also exports the
raw generated Node-API module as `@bittensor/sdk/native`, so every native
entry point is callable even when an ergonomic wrapper has not yet been
added.

## Build locally

From the repository root:

```sh
cargo test -p bittensor-typescript-sdk-native --all-features
npm --prefix sdk/typescript-sdk ci
npm --prefix sdk/typescript-sdk run check
```

The native crate is isolated under `sdk/typescript-sdk/native`; it links
`sdk/bittensor-core` directly and contains binding glue only. No chain
algorithm is reimplemented in TypeScript.

Node.js 20.17 or newer is required.

## Example

```ts
import {
Keypair,
Runtime,
createKeyringPairFromUri,
sealMevShieldTransaction,
} from '@bittensor/sdk'

const alice = Keypair.fromUri('//Alice')
const signature = alice.sign(Buffer.from('hello'))
console.log(alice.verify(Buffer.from('hello'), signature))

// Compatible with tx.signAsync(...) and Moonwall helpers, while the secret
// key and signing operation remain in Rust.
const signer = createKeyringPairFromUri('//Alice')

const runtime = new Runtime(metadataBytes, specVersion, transactionVersion)
const call = runtime.composeCall('System', 'remark', {
remark: Buffer.from('hello'),
})

const ciphertext = sealMevShieldTransaction(mlKemPublicKey, call)
```

Large SCALE integers are returned as `bigint`; byte carriers are returned as
`Buffer`. A decoded SCALE dictionary with non-string keys is returned as a
`Map`, so no key information is lost.
29 changes: 29 additions & 0 deletions sdk/typescript-sdk/native/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[package]
name = "bittensor-typescript-sdk-native"
version = "0.1.0"
edition = "2021"
publish = false
description = "Native Node-API bridge used by the Bittensor TypeScript SDK"
license = "Apache-2.0"

[lib]
crate-type = ["cdylib"]

[features]
default = ["ledger"]
ledger = ["bittensor-core/ledger"]

[dependencies]
bittensor-core = { path = "../../bittensor-core" }
codec = { workspace = true }
hex = "0.4.3"
napi = { version = "3.10.3", default-features = false, features = ["napi8", "serde-json", "dyn-symbols"] }
napi-derive = "3.5.9"
scale-info = { workspace = true, features = ["std", "serde"] }
serde_json = { version = "1.0.132", features = ["arbitrary_precision"] }

[build-dependencies]
napi-build = "2.3.2"

[lints]
workspace = true
3 changes: 3 additions & 0 deletions sdk/typescript-sdk/native/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
napi_build::setup();
}
Loading
Loading