diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index c5a8a7d..997e7c2 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -8,6 +8,7 @@ Please see the development guides for each crate/package: ### Packages * [React Native](packages/react-native/DEVELOPMENT.md) +* [Wasm](packages/wasm/DEVELOPMENT.md) ## Automatic format & syntax checking To configure automatic code formatting and syntax checking for this repository, you can run the following command once: diff --git a/cli/Cargo.lock b/cli/Cargo.lock index 7b6a4f2..41f6215 100644 --- a/cli/Cargo.lock +++ b/cli/Cargo.lock @@ -4167,7 +4167,7 @@ dependencies = [ [[package]] name = "sdk-common" version = "0.6.2" -source = "git+https://github.com/breez/breez-sdk?rev=cc331f34102abda3a39a51524307688a74458050#cc331f34102abda3a39a51524307688a74458050" +source = "git+https://github.com/breez/breez-sdk?rev=f3746d42f972208824a5a03075098d4dafc27215#f3746d42f972208824a5a03075098d4dafc27215" dependencies = [ "aes", "anyhow", @@ -4212,7 +4212,7 @@ dependencies = [ [[package]] name = "sdk-macros" version = "0.6.2" -source = "git+https://github.com/breez/breez-sdk?rev=cc331f34102abda3a39a51524307688a74458050#cc331f34102abda3a39a51524307688a74458050" +source = "git+https://github.com/breez/breez-sdk?rev=f3746d42f972208824a5a03075098d4dafc27215#f3746d42f972208824a5a03075098d4dafc27215" dependencies = [ "proc-macro2", "quote", diff --git a/lib/Cargo.lock b/lib/Cargo.lock index a4e0a14..74b9189 100644 --- a/lib/Cargo.lock +++ b/lib/Cargo.lock @@ -4498,7 +4498,7 @@ dependencies = [ [[package]] name = "sdk-common" version = "0.6.2" -source = "git+https://github.com/breez/breez-sdk?rev=cc331f34102abda3a39a51524307688a74458050#cc331f34102abda3a39a51524307688a74458050" +source = "git+https://github.com/breez/breez-sdk?rev=f3746d42f972208824a5a03075098d4dafc27215#f3746d42f972208824a5a03075098d4dafc27215" dependencies = [ "aes", "anyhow", @@ -4543,7 +4543,7 @@ dependencies = [ [[package]] name = "sdk-macros" version = "0.6.2" -source = "git+https://github.com/breez/breez-sdk?rev=cc331f34102abda3a39a51524307688a74458050#cc331f34102abda3a39a51524307688a74458050" +source = "git+https://github.com/breez/breez-sdk?rev=f3746d42f972208824a5a03075098d4dafc27215#f3746d42f972208824a5a03075098d4dafc27215" dependencies = [ "proc-macro2", "quote", diff --git a/lib/Cargo.toml b/lib/Cargo.toml index bcaf40f..daf1685 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -37,8 +37,8 @@ anyhow = "1.0" log = "0.4.20" once_cell = "1.19" serde = { version = "1.0", features = ["derive"] } -sdk-common = { git = "https://github.com/breez/breez-sdk", rev = "cc331f34102abda3a39a51524307688a74458050", features = ["liquid"] } -sdk-macros = { git = "https://github.com/breez/breez-sdk", rev = "cc331f34102abda3a39a51524307688a74458050" } +sdk-common = { git = "https://github.com/breez/breez-sdk", rev = "f3746d42f972208824a5a03075098d4dafc27215", features = ["liquid"] } +sdk-macros = { git = "https://github.com/breez/breez-sdk", rev = "f3746d42f972208824a5a03075098d4dafc27215" } thiserror = "1.0" [patch.crates-io] diff --git a/lib/wasm/DEVELOPMENT.md b/lib/wasm/DEVELOPMENT.md index 09f5164..4073b0b 100644 --- a/lib/wasm/DEVELOPMENT.md +++ b/lib/wasm/DEVELOPMENT.md @@ -18,16 +18,36 @@ make init ## Building ```bash -make pack +make build ``` This will generate the following artifacts: +* Bundle - suitable for use with bundlers like Webpack + - `bundle/package.json` + - `bundle/breez_sdk_liquid_wasm.d.ts` + - `bundle/breez_sdk_liquid_wasm.js` + - `bundle/breez_sdk_liquid_wasm_bg.js` + - `bundle/breez_sdk_liquid_wasm_bg.wasm` + - `bundle/breez_sdk_liquid_wasm_bg.wasm.d.ts` +* Deno - ES module for use with Deno + - `deno/breez_sdk_liquid_wasm.d.ts` + - `deno/breez_sdk_liquid_wasm.js` + - `deno/breez_sdk_liquid_wasm_bg.wasm` + - `deno/breez_sdk_liquid_wasm_bg.wasm.d.ts` +* Node - CommonJS module for use with Node.js + - `node/package.json` + - `node/breez_sdk_liquid_wasm.d.ts` + - `node/breez_sdk_liquid_wasm.js` + - `node/breez_sdk_liquid_wasm_bg.wasm` + - `node/breez_sdk_liquid_wasm_bg.wasm.d.ts` +* Web - ES module for use in browsers + - `web/package.json` + - `web/breez_sdk_liquid_wasm.d.ts` + - `web/breez_sdk_liquid_wasm.js` + - `web/breez_sdk_liquid_wasm_bg.wasm` + - `web/breez_sdk_liquid_wasm_bg.wasm.d.ts` -- `pkg/package.json` -- `pkg/breez_sdk_liquid_wasm_bg.wasm` -- `pkg/breez_sdk_liquid_wasm_bg.d.wasm` -- `pkg/breez_sdk_liquid_wasm.d.ts` -- `pkg/breez_sdk_liquid_wasm.js` + Each can be build separately with `make build-bundle`, `make build-deno`, `make build-node` or `make build-web`. ## Testing ```bash diff --git a/lib/wasm/Makefile b/lib/wasm/Makefile index b68158c..9841747 100644 --- a/lib/wasm/Makefile +++ b/lib/wasm/Makefile @@ -11,8 +11,19 @@ init: clippy: $(CLANG_PREFIX) cargo clippy --target=wasm32-unknown-unknown -- -D warnings -pack: - $(CLANG_PREFIX) wasm-pack build --weak-refs --target web --scope @breeztech +build: build-bundle build-deno build-node build-web + +build-bundle: + $(CLANG_PREFIX) wasm-pack build --target bundler --release --out-dir pkg/bundle + +build-deno: + $(CLANG_PREFIX) wasm-pack build --target deno --release --out-dir pkg/deno + +build-node: + $(CLANG_PREFIX) wasm-pack build --target nodejs --release --out-dir pkg/node + +build-web: + $(CLANG_PREFIX) wasm-pack build --target web --release --out-dir pkg/web test: $(CLANG_PREFIX) wasm-pack test --headless --firefox diff --git a/lib/wasm/src/model.rs b/lib/wasm/src/model.rs index e4cec0e..6577ff6 100644 --- a/lib/wasm/src/model.rs +++ b/lib/wasm/src/model.rs @@ -210,7 +210,6 @@ pub struct LnUrlWithdrawRequestData { #[sdk_macros::extern_wasm_bindgen(breez_sdk_liquid::prelude::LnUrlCallbackStatus)] pub enum LnUrlCallbackStatus { Ok, - #[serde(rename = "ERROR")] ErrorStatus { #[serde(flatten)] data: LnUrlErrorData, diff --git a/packages/react-native/LICENSE b/packages/react-native/LICENSE index f4117bb..5c004f2 100644 --- a/packages/react-native/LICENSE +++ b/packages/react-native/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 Breez +Copyright (c) 2025 Breez Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/packages/react-native/README.md b/packages/react-native/README.md new file mode 100644 index 0000000..c758944 --- /dev/null +++ b/packages/react-native/README.md @@ -0,0 +1,130 @@ +# React Native Breez SDK - Nodeless *(Liquid Implementation)* + +The Breez SDK provides developers with a end-to-end solution for integrating self-custodial Lightning payments into their apps and services. It eliminates the need for third parties, simplifies the complexities of Bitcoin and Lightning, and enables seamless onboarding for billions of users to the future of peer-to-peer payments. + +## **What Is the Breez SDK - Nodeless *(Liquid Implementation)*?** + +It’s a nodeless integration that offers a self-custodial, end-to-end solution for integrating Lightning payments, utilizing the Liquid Network with on-chain interoperability and third-party fiat on-ramps. Using the SDK you'll able to: + +- **Send payments** via various protocols such as: Bolt11, Bolt12, BIP353, LNURL-Pay, Lightning address, BTC address +- **Receive payments** via various protocols such as: Bolt11, LNURL-Withdraw, LNURL-Pay, Lightning address, BTC address + +**Key Features** + +- [x] Send and receive Lightning payments +- [x] On-chain interoperability +- [x] Complete LNURL functionality +- [x] Multi-app support +- [x] Multi-device support +- [x] Real-time state backup +- [x] Keys are only held by users +- [x] USDT and multi-asset support on Liquid +- [x] Built-in fiat on-ramp +- [x] Free open-source solution + +## Getting Started +```bash +npm install @breeztech/react-native-breez-sdk-liquid +``` +or + +```bash +yarn add @breeztech/react-native-breez-sdk-liquid +``` + +## Usage +Head over to the [Breez SDK - Nodeless *(Liquid Implementation)* documentation](https://sdk-doc-liquid.breez.technology/) to start implementing Lightning in your app. + +You'll need an API key to use the Breez SDK - Nodeless *(Liquid Implementation)*. To request an API key is free — you just need to [complete this simple form.](https://breez.technology/request-api-key/#contact-us-form-sdk) + +```ts +import React, { useEffect } from "react" +import { + addEventListener, + connect, + defaultConfig, + LiquidNetwork, + NodeConfigVariant, + prepareSendPayment, + SdkEvent, + sendPayment +} from "@breeztech/react-native-breez-sdk-liquid"; +import BuildConfig from "react-native-build-config" + +const App = () => ( + ... + + const eventHandler = (sdkEvent: SdkEvent) => { + console.log(`${JSON.stringify(sdkEvent)}`) + } + + const payInvoice = async (bolt11: string) => { + // Pay invoice + let prepareSendRes = await prepareSendPayment({ destination: bolt11 }) + let sendPaymentRes = await sendPayment({ prepareResponse: prepareSendRes }) + } + + useEffect(() => { + const asyncFn = async () => { + // Construct the sdk default config + const config = await defaultConfig(LiquidNetwork.MAINNET, BuildConfig.BREEZ_API_KEY) + + // Connect to the Breez SDK make it ready to use + await connect({ config, mnemonic }) + + // Add event handler + await addEventListener(eventHandler) + } + + asyncFn() + }, []) + + ... +) + +export default App +``` + +## Example + +In the `example` folder of the [Breez SDK repository](https://github.com/breez/breez-sdk-liquid/tree/main/packages/react-native/example) you will find a basic application for using Breez SDK. Change directory into the folder and install the dependencies: +```bash +yarn +``` +Then to run on android: +```bash +yarn android +``` +or for iOS: +```bash +yarn pods && yarn ios +``` + +## Troubleshooting +### Important fix for React Native versions below 0.71.0 + +If your project uses a React Native version less < 0.71.0, and you want to build your app for Android, you might run into an error like this: + +``` + 2 files found with path 'lib/arm64-v8a/libc++_shared.so' from inputs: + - /(...)/.gradle/caches/transforms-3/c476ede63d070b991438fe0d1c323931/transformed/jetified-react-native-0.68.6/jni/arm64-v8a/libc++_shared.so + - /(...)/.gradle/caches/transforms-3/7c318ac8dd87c1f0c7540616d6d47bd8/transformed/jetified-breez-sdk-0.1.3/jni/arm64-v8a/libc++_shared.so +``` + +To fix this you need to disambiguate which file to use by adding the following snippet to your app's `android/app/build.gradle`: + +```gradle +android { + // ... + packagingOptions { + pickFirst 'lib/x86/libc++_shared.so' + pickFirst 'lib/x86_64/libc++_shared.so' + pickFirst 'lib/armeabi-v7a/libc++_shared.so' + pickFirst 'lib/arm64-v8a/libc++_shared.so' + } +} +``` + +Both the Breez SDK as well as React Native package the `libc++_shared.so` native library. +React Native versions below 0.71.0 have a [bug](https://github.com/facebook/react-native/issues/30297) where they cannot automatically handle multiple versions of this file. +This has been [fixed](https://github.com/facebook/react-native/pull/35093) in React Native 0.71.0 and thus the above snippet only needs to be added to projects using React Native < 0.71.0. diff --git a/packages/wasm/.gitignore b/packages/wasm/.gitignore new file mode 100644 index 0000000..28d4145 --- /dev/null +++ b/packages/wasm/.gitignore @@ -0,0 +1,6 @@ +# node.js +# +node_modules/ +npm-debug.log +yarn-debug.log +yarn-error.log diff --git a/packages/wasm/DEVELOPMENT.md b/packages/wasm/DEVELOPMENT.md new file mode 100644 index 0000000..781690c --- /dev/null +++ b/packages/wasm/DEVELOPMENT.md @@ -0,0 +1,61 @@ +# Development guide - Wasm package + +When developing, it can be useful to work with a locally built version of the Breez Liquid SDK instead of relying on what is published already. +To do this, you first need to build the Breez Liquid SDK bindings locally and then point the examples to make use of the locally built Breez Liquid SDK Wasm package. + +All the following commands can be run in the `packages/wasm` directory. + +## Prerequisites +To build some dependencies you need to first install +- [Protobuf](https://protobuf.dev/installation/) +- [Emscripten](https://emscripten.org/docs/getting_started/downloads.html) for compiling to Wasm +- [Firefox](https://mozilla.org/firefox/download/) for testing Wasm + +```bash +brew install protobuf emscripten +``` + +On first usage you will need to run: +```bash +make init +``` + +## Build +To build the Wasm code run: +```bash +make build +``` + +This will generate the following artifacts: + +* Bundle - suitable for use with bundlers like Webpack + - `bundle/package.json` + - `bundle/breez_sdk_liquid_wasm.d.ts` + - `bundle/breez_sdk_liquid_wasm.js` + - `bundle/breez_sdk_liquid_wasm_bg.js` + - `bundle/breez_sdk_liquid_wasm_bg.wasm` + - `bundle/breez_sdk_liquid_wasm_bg.wasm.d.ts` +* Deno - ES module for use with Deno + - `deno/breez_sdk_liquid_wasm.d.ts` + - `deno/breez_sdk_liquid_wasm.js` + - `deno/breez_sdk_liquid_wasm_bg.wasm` + - `deno/breez_sdk_liquid_wasm_bg.wasm.d.ts` +* Node - CommonJS module for use with Node.js + - `node/package.json` + - `node/breez_sdk_liquid_wasm.d.ts` + - `node/breez_sdk_liquid_wasm.js` + - `node/breez_sdk_liquid_wasm_bg.wasm` + - `node/breez_sdk_liquid_wasm_bg.wasm.d.ts` +* Web - ES module for use in browsers + - `web/package.json` + - `web/breez_sdk_liquid_wasm.d.ts` + - `web/breez_sdk_liquid_wasm.js` + - `web/breez_sdk_liquid_wasm_bg.wasm` + - `web/breez_sdk_liquid_wasm_bg.wasm.d.ts` + +## Testing with the examples + +To test locally built bindings in the examples, the npm dependencies need to be updated to use the local package. +```json + "@breeztech/breez-sdk-liquid": "file:../../", +``` diff --git a/packages/wasm/LICENSE b/packages/wasm/LICENSE new file mode 100644 index 0000000..5c004f2 --- /dev/null +++ b/packages/wasm/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 Breez + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packages/wasm/PUBLISHING.md b/packages/wasm/PUBLISHING.md new file mode 100644 index 0000000..8dd6685 --- /dev/null +++ b/packages/wasm/PUBLISHING.md @@ -0,0 +1,52 @@ +## Publishing + +### Build +On first usage you will need to run: +``` +make init +``` + +Then to build the Wasm code: +``` +make build +``` + +#### Generated artifacts +* Bundle - suitable for use with bundlers like Webpack + >* bundle/package.json + >* bundle/breez_sdk_liquid_wasm.d.ts + >* bundle/breez_sdk_liquid_wasm.js + >* bundle/breez_sdk_liquid_wasm_bg.js + >* bundle/breez_sdk_liquid_wasm_bg.wasm + >* bundle/breez_sdk_liquid_wasm_bg.wasm.d.ts +* Deno - ES module for use with Deno + >* deno/breez_sdk_liquid_wasm.d.ts + >* deno/breez_sdk_liquid_wasm.js + >* deno/breez_sdk_liquid_wasm_bg.wasm + >* deno/breez_sdk_liquid_wasm_bg.wasm.d.ts +* Node - CommonJS module for use with Node.js + >* node/package.json + >* node/breez_sdk_liquid_wasm.d.ts + >* node/breez_sdk_liquid_wasm.js + >* node/breez_sdk_liquid_wasm_bg.wasm + >* node/breez_sdk_liquid_wasm_bg.wasm.d.ts +* Web - ES module for use in browsers + >* web/package.json + >* web/breez_sdk_liquid_wasm.d.ts + >* web/breez_sdk_liquid_wasm.js + >* web/breez_sdk_liquid_wasm_bg.wasm + >* web/breez_sdk_liquid_wasm_bg.wasm.d.ts + +### Publish +When publishing, make sure the following are updated: +- Update the version number in `package.json`. +- Set the published version of `@breeztech/breez-sdk-liquid` in the each example's `package.json` file. + +Then login to npm: +``` +npm login --@scope=@breeztech +``` +Then publish: +``` +npm publish --access public +``` \ No newline at end of file diff --git a/packages/wasm/README.md b/packages/wasm/README.md new file mode 100644 index 0000000..08e3f71 --- /dev/null +++ b/packages/wasm/README.md @@ -0,0 +1,108 @@ +# Breez SDK - Nodeless *(Liquid Implementation)* + +The Breez SDK provides developers with a end-to-end solution for integrating self-custodial Lightning payments into their apps and services. It eliminates the need for third parties, simplifies the complexities of Bitcoin and Lightning, and enables seamless onboarding for billions of users to the future of peer-to-peer payments. + +## **What Is the Breez SDK - Nodeless *(Liquid Implementation)*?** + +It’s a nodeless integration that offers a self-custodial, end-to-end solution for integrating Lightning payments, utilizing the Liquid Network with on-chain interoperability and third-party fiat on-ramps. Using the SDK you'll able to: + +- **Send payments** via various protocols such as: Bolt11, Bolt12, BIP353, LNURL-Pay, Lightning address, BTC address +- **Receive payments** via various protocols such as: Bolt11, LNURL-Withdraw, LNURL-Pay, Lightning address, BTC address + +**Key Features** + +- [x] Send and receive Lightning payments +- [x] On-chain interoperability +- [x] Complete LNURL functionality +- [x] Multi-app support +- [x] Multi-device support +- [x] Real-time state backup +- [x] Keys are only held by users +- [x] USDT and multi-asset support on Liquid +- [x] Built-in fiat on-ramp +- [x] Free open-source solution + +## Getting Started +```bash +npm install @breeztech/breez-sdk-liquid +``` +or + +```bash +yarn add @breeztech/breez-sdk-liquid +``` + +## Usage +Head over to the [Breez SDK - Nodeless *(Liquid Implementation)* documentation](https://sdk-doc-liquid.breez.technology/) to start implementing Lightning in your app. + +You'll need an API key to use the Breez SDK - Nodeless *(Liquid Implementation)*. To request an API key is free — you just need to [complete this simple form.](https://breez.technology/request-api-key/#contact-us-form-sdk) + +### Web +When developing a browser application you should import `@breeztech/breez-sdk-liquid` (or the explicit `@breeztech/breez-sdk-liquid/web` submodule). + +It's important to first initialise the WebAssembly module by using `await init()` before making any other calls to the module. + +```ts +import init, { + connect, + defaultConfig, + SdkEvent +} from '@breeztech/breez-sdk-liquid/web' + +// Initialise the WebAssembly module +await init() +``` + +### Node.js +When developing a node.js application you should require `@breeztech/breez-sdk-liquid` (or the explicit `@breeztech/breez-sdk-liquid/node` submodule). +```js +const { connect, defaultConfig, initLogger } = require('@breeztech/breez-sdk-liquid/node') +const { Command } = require('commander') +require('dotenv').config() + +class JsEventListener { + onEvent = (event) => { + console.log(`EVENT RECEIVED: ${JSON.stringify(event)}`) + } +} + +const program = new Command() +const eventListener = new JsEventListener() + +const initSdk = async () => { + // Set the logger to trace + initLogger('trace') + + // Get the mnemonic + const breezApiKey = process.env.BREEZ_API_KEY + const mnemonic = process.env.MNEMONIC + + // Connect using the config + const config = await defaultConfig('mainnet', breezApiKey) + console.log(`defaultConfig: ${JSON.stringify(config)}`) + + const sdk = await connect({ config, mnemonic }) + console.log(`connect`) + + const listenerId = await sdk.addEventListener(eventListener) + console.log(`addEventListener: ${listenerId}`) + return sdk +} + +program.name('nodeless-wasm-cli').description('CLI for Breez SDK - Nodeless Wasm') + +program.command('get-info').action(async () => { + let sdk = await initSdk() + let getInfoRes = await sdk.getInfo() + console.log(`getInfo: ${JSON.stringify(getInfoRes)}`) +}) + +program.parse() +``` + +### Deno +When developing a Deno application you should import `@breeztech/breez-sdk-liquid` (or the explicit `@breeztech/breez-sdk-liquid/deno` submodule). + +## Troubleshooting + +- Node.js version 19 is the first version to add `global.crypto`. When using less than version 19 this has to be polyfilled. diff --git a/packages/wasm/examples/node/.gitignore b/packages/wasm/examples/node/.gitignore new file mode 100644 index 0000000..a7c3b57 --- /dev/null +++ b/packages/wasm/examples/node/.gitignore @@ -0,0 +1,28 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +node_modules +package-lock.json +yarn.lock +dist +dist-ssr +*.local + +# Editor directories and files +.vscode/* +!.vscode/extensions.json +.idea +.DS_Store +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? + +.env \ No newline at end of file diff --git a/packages/wasm/examples/node/README.md b/packages/wasm/examples/node/README.md new file mode 100644 index 0000000..3384ce4 --- /dev/null +++ b/packages/wasm/examples/node/README.md @@ -0,0 +1,21 @@ +# Breez SDK Nodeless - Wasm NodeJs Example + +## Prerequisites +Copy the `example.env` file to `.env` and set the BREEZ_API_KEY and MNEMONIC environment variables. + +## Build +If you are running from a local Wasm package, build the Wasm package first in the [Wasm package](../../) directory. +```bash +cd .. +make build +``` + +Install the dependencies +```bash +npm i +``` + +## Run +```bash +node cli.js get-info +``` \ No newline at end of file diff --git a/packages/wasm/examples/node/cli.js b/packages/wasm/examples/node/cli.js new file mode 100644 index 0000000..a548239 --- /dev/null +++ b/packages/wasm/examples/node/cli.js @@ -0,0 +1,42 @@ +const { connect, defaultConfig, initLogger } = require('@breeztech/breez-sdk-liquid/node') +const { Command } = require('commander') +require('dotenv').config() + +class JsEventListener { + onEvent = (event) => { + console.log(`EVENT RECEIVED: ${JSON.stringify(event)}`) + } +} + +const program = new Command() +const eventListener = new JsEventListener() + +const initSdk = async () => { + // Set the logger to trace + initLogger('trace') + + // Get the mnemonic + const breezApiKey = process.env.BREEZ_API_KEY + const mnemonic = process.env.MNEMONIC + + // Connect using the config + const config = await defaultConfig('mainnet', breezApiKey) + console.log(`defaultConfig: ${JSON.stringify(config)}`) + + const sdk = await connect({ config, mnemonic }) + console.log(`connect`) + + const listenerId = await sdk.addEventListener(eventListener) + console.log(`addEventListener: ${listenerId}`) + return sdk +} + +program.name('nodeless-wasm-cli').description('CLI for Breez SDK - Nodeless Wasm') + +program.command('get-info').action(async () => { + let sdk = await initSdk() + let getInfoRes = await sdk.getInfo() + console.log(`getInfo: ${JSON.stringify(getInfoRes)}`) +}) + +program.parse() diff --git a/packages/wasm/examples/node/example.env b/packages/wasm/examples/node/example.env new file mode 100644 index 0000000..37cd253 --- /dev/null +++ b/packages/wasm/examples/node/example.env @@ -0,0 +1,2 @@ +BREEZ_API_KEY = "" +MNEMONIC = "" diff --git a/packages/wasm/examples/node/package.json b/packages/wasm/examples/node/package.json new file mode 100644 index 0000000..2607b1b --- /dev/null +++ b/packages/wasm/examples/node/package.json @@ -0,0 +1,19 @@ +{ + "name": "example", + "private": true, + "version": "0.0.0", + "main": "cli.js", + "dependencies": { + "@breeztech/breez-sdk-liquid": "file:../../", + "commander": "^13.1.0", + "dotenv": "^16.4.7" + }, + "prettier": { + "endOfLine": "lf", + "printWidth": 150, + "semi": false, + "singleQuote": true, + "tabWidth": 4, + "trailingComma": "none" + } +} diff --git a/packages/wasm/examples/web-vite/.gitignore b/packages/wasm/examples/web-vite/.gitignore new file mode 100644 index 0000000..a7c3b57 --- /dev/null +++ b/packages/wasm/examples/web-vite/.gitignore @@ -0,0 +1,28 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +node_modules +package-lock.json +yarn.lock +dist +dist-ssr +*.local + +# Editor directories and files +.vscode/* +!.vscode/extensions.json +.idea +.DS_Store +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? + +.env \ No newline at end of file diff --git a/packages/wasm/examples/web-vite/README.md b/packages/wasm/examples/web-vite/README.md new file mode 100644 index 0000000..6bb1237 --- /dev/null +++ b/packages/wasm/examples/web-vite/README.md @@ -0,0 +1,26 @@ +# Breez SDK Nodeless - Wasm Vite Example + +## Prerequisites +Copy the `example.env` file to `.env` and set the VITE_BREEZ_API_KEY and VITE_MNEMONIC environment variables. + +## Build +If you are running from a local Wasm package, build the Wasm package first in the [Wasm package](../../) directory. +```bash +cd .. +make build +``` + +Install the dependencies +```bash +yarn +``` + +Run vite build +```bash +yarn build +``` + +## Run +```bash +yarn preview +``` \ No newline at end of file diff --git a/packages/wasm/examples/web-vite/eslint.config.js b/packages/wasm/examples/web-vite/eslint.config.js new file mode 100644 index 0000000..092408a --- /dev/null +++ b/packages/wasm/examples/web-vite/eslint.config.js @@ -0,0 +1,28 @@ +import js from '@eslint/js' +import globals from 'globals' +import reactHooks from 'eslint-plugin-react-hooks' +import reactRefresh from 'eslint-plugin-react-refresh' +import tseslint from 'typescript-eslint' + +export default tseslint.config( + { ignores: ['dist'] }, + { + extends: [js.configs.recommended, ...tseslint.configs.recommended], + files: ['**/*.{ts,tsx}'], + languageOptions: { + ecmaVersion: 2020, + globals: globals.browser, + }, + plugins: { + 'react-hooks': reactHooks, + 'react-refresh': reactRefresh, + }, + rules: { + ...reactHooks.configs.recommended.rules, + 'react-refresh/only-export-components': [ + 'warn', + { allowConstantExport: true }, + ], + }, + }, +) diff --git a/packages/wasm/examples/web-vite/example.env b/packages/wasm/examples/web-vite/example.env new file mode 100644 index 0000000..0cee449 --- /dev/null +++ b/packages/wasm/examples/web-vite/example.env @@ -0,0 +1,2 @@ +VITE_BREEZ_API_KEY = "" +VITE_MNEMONIC = "" diff --git a/packages/wasm/examples/web-vite/index.html b/packages/wasm/examples/web-vite/index.html new file mode 100644 index 0000000..7b02e30 --- /dev/null +++ b/packages/wasm/examples/web-vite/index.html @@ -0,0 +1,13 @@ + + +
+ + + +