Skip to content

Commit b05365a

Browse files
authored
Add javascript language bindings (payjoin#1190)
2 parents 9597e91 + cf265f8 commit b05365a

34 files changed

+1958
-23
lines changed

.codespellrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[codespell]
2-
skip = .git,target,Cargo.toml,Cargo.lock,Cargo-minimal.lock,Cargo-recent.lock
2+
skip = .git,target,Cargo.toml,Cargo.lock,Cargo-minimal.lock,Cargo-recent.lock,package-lock.json
33
ignore-words-list = crate,ser,ot

.github/workflows/javascript.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Build and Test JavaScript
2+
on:
3+
pull_request:
4+
paths:
5+
- payjoin-ffi/**
6+
env:
7+
# Override the value from the rust-toolchain file
8+
# This is necessary because even though the correct toolchain
9+
# is explicitly specified for the rust-toolchain action,
10+
# rustup honors the rust-toolchain file over the default
11+
RUSTUP_TOOLCHAIN: 1.85
12+
13+
jobs:
14+
build-js-and-test:
15+
name: "Build and test javascript"
16+
runs-on: ${{ matrix.os }}
17+
defaults:
18+
run:
19+
working-directory: payjoin-ffi/javascript
20+
strategy:
21+
matrix:
22+
os: [ubuntu-latest, macos-latest]
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v4
26+
27+
- name: Install Rust 1.85.0
28+
uses: dtolnay/[email protected]
29+
30+
- name: "Use cache"
31+
uses: Swatinem/rust-cache@v2
32+
33+
- name: Install Node
34+
uses: actions/setup-node@v6
35+
36+
- name: Install llvm
37+
if: matrix.os == 'macos-latest'
38+
run: brew install llvm
39+
40+
- name: Install wasm-bindgen
41+
run: cargo install wasm-bindgen-cli
42+
43+
- name: "Install dependencies"
44+
run: npm ci
45+
46+
- name: Generate bindings and binaries
47+
run: bash ./scripts/generate_bindings.sh
48+
49+
- name: Run tests
50+
run: npm test

Cargo-minimal.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2397,6 +2397,7 @@ dependencies = [
23972397
"tokio",
23982398
"tracing",
23992399
"url",
2400+
"web-time",
24002401
]
24012402

24022403
[[package]]
@@ -2469,6 +2470,7 @@ dependencies = [
24692470
"bdk",
24702471
"bitcoin-ffi",
24712472
"bitcoin-ohttp",
2473+
"getrandom 0.2.15",
24722474
"hex",
24732475
"lazy_static",
24742476
"payjoin",

Cargo-recent.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2397,6 +2397,7 @@ dependencies = [
23972397
"tokio",
23982398
"tracing",
23992399
"url",
2400+
"web-time",
24002401
]
24012402

24022403
[[package]]
@@ -2469,6 +2470,7 @@ dependencies = [
24692470
"bdk",
24702471
"bitcoin-ffi",
24712472
"bitcoin-ohttp",
2473+
"getrandom 0.2.15",
24722474
"hex",
24732475
"lazy_static",
24742476
"payjoin",

payjoin-ffi/Cargo.toml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ license = "MIT OR Apache-2.0"
66
exclude = ["tests"]
77

88
[features]
9-
_test-utils = ["payjoin-test-utils", "tokio"]
9+
default = ["io"]
10+
dart = ["dep:uniffi-dart"]
11+
io = ["payjoin/io"]
12+
_test-utils = ["payjoin-test-utils", "tokio", "io"]
1013
_manual-tls = ["payjoin/_manual-tls"]
14+
wasm_js = ["getrandom/js"]
1115

1216
[lib]
1317
name = "payjoin_ffi"
@@ -19,22 +23,23 @@ path = "uniffi-bindgen.rs"
1923

2024
[build-dependencies]
2125
uniffi = { version = "0.29.4", features = ["build", "cli"] }
22-
uniffi-dart = { git = "https://github.com/Uniffi-Dart/uniffi-dart.git", rev = "04f0007", features = ["build"] }
26+
uniffi-dart = { git = "https://github.com/Uniffi-Dart/uniffi-dart.git", rev = "04f0007", features = ["build"], optional = true }
2327

2428
[dependencies]
2529
base64 = "0.22.1"
2630
bitcoin-ffi = { git = "https://github.com/benalleng/bitcoin-ffi.git", rev = "8e3a23b" }
31+
getrandom = "0.2"
2732
hex = "0.4.3"
2833
lazy_static = "1.5.0"
2934
ohttp = { package = "bitcoin-ohttp", version = "0.6.0" }
30-
payjoin = { version = "1.0.0-rc.1", features = ["v1", "v2", "io"] }
35+
payjoin = { version = "1.0.0-rc.1", features = ["v1", "v2"] }
3136
payjoin-test-utils = { version = "0.0.1", optional = true }
3237
serde = { version = "1.0.219", features = ["derive"] }
3338
serde_json = "1.0.142"
3439
thiserror = "2.0.14"
3540
tokio = { version = "1.47.1", features = ["full"], optional = true }
3641
uniffi = { version = "0.29.4" }
37-
uniffi-dart = { git = "https://github.com/Uniffi-Dart/uniffi-dart.git", rev = "04f0007" }
42+
uniffi-dart = { git = "https://github.com/Uniffi-Dart/uniffi-dart.git", rev = "04f0007", optional = true }
3843
url = "2.5.4"
3944

4045
[dev-dependencies]

payjoin-ffi/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ The directories below include instructions for using, building, and publishing t
1414
|----------|-----------------------|-------------------|------------------------------------|
1515
| Python | linux, macOS | [payjoin-ffi/python](python) | [payjoin](https://pypi.org/project/payjoin/) |
1616
| Dart | linux, macOS | [payjoin-ffi/dart](dart) | N/A |
17+
| JavaScript | linux, macOS | [payjoin-ffi/javascript](javascript) | N/A |
1718

1819
## Minimum Supported Rust Version (MSRV)
1920

20-
This library should compile with any combination of features with Rust 1.78.0.
21+
This library should compile with any combination of features with Rust 1.85.0.
2122

2223
## References
2324

payjoin-ffi/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
fn main() {
22
uniffi::generate_scaffolding("src/payjoin_ffi.udl").unwrap();
3+
#[cfg(feature = "dart")]
34
uniffi_dart::generate_scaffolding("src/payjoin_ffi.udl".into()).unwrap();
45
}

payjoin-ffi/dart/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ Follow these steps to clone the repository and run the tests.
1111
git clone https://github.com/payjoin/rust-payjoin.git
1212
cd rust-payjoin/payjoin-ffi/dart
1313

14-
# Generate the bindings (use the script appropriate for your platform)
15-
bash ./scripts/generate_<platform>.sh
14+
# Generate the bindings
15+
bash ./scripts/generate_bindings.sh
1616

1717
# Run all tests
1818
dart test

payjoin-ffi/dart/scripts/generate_bindings.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ fi
1919

2020
cd ../
2121
echo "Generating payjoin dart..."
22-
cargo build --features _test-utils --profile dev
23-
cargo run --features _test-utils --profile dev --bin uniffi-bindgen -- --library ../target/debug/$LIBNAME --language dart --out-dir dart/lib/
22+
cargo build --features dart,_test-utils --profile dev
23+
cargo run --features dart,_test-utils --profile dev --bin uniffi-bindgen -- --library ../target/debug/$LIBNAME --language dart --out-dir dart/lib/
2424

2525
if [[ "$OS" == "Darwin" ]]; then
2626
echo "Generating native binaries..."
2727
rustup target add aarch64-apple-darwin x86_64-apple-darwin
2828
# This is a test script the actual release should not include the test utils feature
29-
cargo build --profile dev --target aarch64-apple-darwin --features _test-utils &
30-
cargo build --profile dev --target x86_64-apple-darwin --features _test-utils &
29+
cargo build --profile dev --target aarch64-apple-darwin --features dart,_test-utils &
30+
cargo build --profile dev --target x86_64-apple-darwin --features dart,_test-utils &
3131
wait
3232

3333
echo "Building macos fat library"
@@ -38,7 +38,7 @@ else
3838
echo "Generating native binaries..."
3939
rustup target add x86_64-unknown-linux-gnu
4040
# This is a test script the actual release should not include the test utils feature
41-
cargo build --profile dev --target x86_64-unknown-linux-gnu --features _test-utils
41+
cargo build --profile dev --target x86_64-unknown-linux-gnu --features dart,_test-utils
4242

4343
echo "Copying payjoin_ffi binary"
4444
cp ../target/x86_64-unknown-linux-gnu/debug/$LIBNAME dart/$LIBNAME

payjoin-ffi/javascript/.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Build outputs
2+
dist/
3+
node_modules/
4+
5+
# Generated by uniffi-bindgen-react-native
6+
rust_modules/
7+
src/generated/
8+
9+
# Generated by napi-rs (test-utils)
10+
test-utils/*.node
11+
test-utils/index.d.ts

0 commit comments

Comments
 (0)