diff --git a/README.md b/README.md index e71f0ef..a4fd2ba 100644 --- a/README.md +++ b/README.md @@ -13,16 +13,18 @@ You can install the cli app with `cargo install fedimint-clientd` or by cloning ``` CLI USAGE: fedimint-clientd \ - --fm_db_path=/absolute/path/to/dir/to/store/database \ + --db-path=/absolute/path/to/dir/to/store/database \ --password="some-secure-password-that-becomes-the-bearer-token" \ --addr="127.0.0.1:8080" - --mode="default" + --mode="rest" + --invite-code="fed1-fedimint-invite-code" ENV USAGE: FEDIMINT_CLIENTD_DB_PATH=/absolute/path/to/dir/to/store/database FEDIMINT_CLIENTD_PASSWORD="some-secure-password-that-becomes-the-bearer-token" FEDIMINT_CLIENTD_ADDR="127.0.0.1:8080" -FEDIMINT_CLIENTD_MODE="default" +FEDIMINT_CLIENTD_MODE="rest" +FEDIMINT_CLIENTD_INVITE_CODE="fed1-fedimint-invite-code" ``` ## Fedimint Clientd Endpoints diff --git a/justfile.local.just b/justfile.local.just index 178441d..68c4057 100644 --- a/justfile.local.just +++ b/justfile.local.just @@ -5,7 +5,7 @@ mprocs: ./scripts/mprocs-nix.sh dev-fed mprocs-new.yaml test-ts: - bun run wrappers/fedimint-ts/test.ts + bun run wrappers/fedimint-ts/tests/test.ts test-py: python3.11 wrappers/fedimint-py/test.py diff --git a/wrappers/fedimint-ts/README.md b/wrappers/fedimint-ts/README.md index b1992db..6b5f20d 100644 --- a/wrappers/fedimint-ts/README.md +++ b/wrappers/fedimint-ts/README.md @@ -3,9 +3,10 @@ This is a TypeScript client that consumes the [Fedimint Http Client](https://github.com/kodylow/fedimint-http), communicating with it via HTTP and a password. It's a hacky prototype, but it works until we can get a proper TS client for Fedimint. All of the federation handling code happens in the fedimint-http-client, this just exposes a simple API for interacting with the client from TypeScript (will be mirrored in Python and Go). ## Usage + ```typescript -import {FedimintClientBuilder} from "./FedimintClient"; import dotenv from "dotenv"; +import { FedimintClientBuilder } from "fedimint-ts"; dotenv.config(); @@ -51,41 +52,20 @@ fedimintClient.ln.awaitInvoice({ operation_id }).then((response) => { }); ``` -# Setup - -Set the following in the fedimint-http .env environment variables: - -```bash -FEDERATION_INVITE_CODE = 'fed1-some-invite-code' -SECRET_KEY = 'some-secret-key' # generate this with `openssl rand -base64 32` -FM_DB_PATH = '/absolute/path/to/fm.db' # just make this a new dir called `fm_db` in the root of the fedimint-http-client and use the absolute path to thatm it'll create the db file for you on startup -PASSWORD = 'password' -DOMAIN = 'localhost' -PORT = 5000 -BASE_URL = 'http://localhost:5000' -``` - -Then start the fedimint-http-client server: +## Development -```bash -cargo run -``` +Install dependencies with `bun install` or `npm install`. -Then you're ready to run the typescript client, which will use the same base url and password as the fedimint-http-client: +Follow these [steps to setup a `fedimint-clientd` server](https://github.com/fedimint/fedimint-clientd?tab=readme-ov-file#getting-started) and then you're ready to run the typescript client. + `fedimint-ts` will use the same base url and password as the `fedimint-clientd`: ```bash BASE_URL = 'http://localhost:5000' PASSWORD = 'password' ``` -To install dependencies: - -```bash -bun install -``` - -To run (this just runs an example that creates FedimintClient in typescript and creates an invoice): +Then run your code that follows the pattern of `tests/info-example.ts`. ```bash -bun run example.ts +bun run tests/info-example.ts ``` diff --git a/wrappers/fedimint-ts/bun.lockb b/wrappers/fedimint-ts/bun.lockb deleted file mode 100755 index fab43d7..0000000 Binary files a/wrappers/fedimint-ts/bun.lockb and /dev/null differ diff --git a/wrappers/fedimint-ts/index.ts b/wrappers/fedimint-ts/index.ts deleted file mode 100644 index 7964808..0000000 --- a/wrappers/fedimint-ts/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { FedimintClient, FedimintClientBuilder } from "./FedimintClient"; -import * as types from "./types"; - -export { FedimintClient, FedimintClientBuilder, types }; diff --git a/wrappers/fedimint-ts/package-lock.json b/wrappers/fedimint-ts/package-lock.json new file mode 100644 index 0000000..0939032 --- /dev/null +++ b/wrappers/fedimint-ts/package-lock.json @@ -0,0 +1,1581 @@ +{ + "name": "fedimint-ts", + "version": "0.2.23", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "fedimint-ts", + "version": "0.2.23", + "license": "MIT", + "dependencies": { + "crypto": "^1.0.1", + "dotenv": "^16.3.1", + "fedimint-ts": "^0.2.7", + "secp256k1": "^5.0.0" + }, + "devDependencies": { + "@types/secp256k1": "^4.0.6", + "@typescript-eslint/eslint-plugin": "^6.13.1", + "@typescript-eslint/parser": "^6.13.1", + "eslint": "^8", + "typescript": "^5.0.0" + } + }, + "node_modules/@aashutoshrathi/word-wrap": { + "version": "1.2.6", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/@eslint-community/eslint-utils": { + "version": "4.4.0", + "dev": true, + "license": "MIT", + "dependencies": { + "eslint-visitor-keys": "^3.3.0" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "peerDependencies": { + "eslint": "^6.0.0 || ^7.0.0 || >=8.0.0" + } + }, + "node_modules/@eslint-community/regexpp": { + "version": "4.10.0", + "dev": true, + "license": "MIT", + "engines": { + "node": "^12.0.0 || ^14.0.0 || >=16.0.0" + } + }, + "node_modules/@eslint/eslintrc": { + "version": "2.1.4", + "dev": true, + "license": "MIT", + "dependencies": { + "ajv": "^6.12.4", + "debug": "^4.3.2", + "espree": "^9.6.0", + "globals": "^13.19.0", + "ignore": "^5.2.0", + "import-fresh": "^3.2.1", + "js-yaml": "^4.1.0", + "minimatch": "^3.1.2", + "strip-json-comments": "^3.1.1" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/@eslint/js": { + "version": "8.57.0", + "dev": true, + "license": "MIT", + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + } + }, + "node_modules/@humanwhocodes/config-array": { + "version": "0.11.14", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@humanwhocodes/object-schema": "^2.0.2", + "debug": "^4.3.1", + "minimatch": "^3.0.5" + }, + "engines": { + "node": ">=10.10.0" + } + }, + "node_modules/@humanwhocodes/module-importer": { + "version": "1.0.1", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=12.22" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/nzakas" + } + }, + "node_modules/@humanwhocodes/object-schema": { + "version": "2.0.3", + "dev": true, + "license": "BSD-3-Clause" + }, + "node_modules/@nodelib/fs.scandir": { + "version": "2.1.5", + "dev": true, + "license": "MIT", + "dependencies": { + "@nodelib/fs.stat": "2.0.5", + "run-parallel": "^1.1.9" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/@nodelib/fs.stat": { + "version": "2.0.5", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 8" + } + }, + "node_modules/@nodelib/fs.walk": { + "version": "1.2.8", + "dev": true, + "license": "MIT", + "dependencies": { + "@nodelib/fs.scandir": "2.1.5", + "fastq": "^1.6.0" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/@types/json-schema": { + "version": "7.0.15", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/node": { + "version": "20.12.7", + "dev": true, + "license": "MIT", + "dependencies": { + "undici-types": "~5.26.4" + } + }, + "node_modules/@types/secp256k1": { + "version": "4.0.6", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/node": "*" + } + }, + "node_modules/@types/semver": { + "version": "7.5.8", + "dev": true, + "license": "MIT" + }, + "node_modules/@typescript-eslint/eslint-plugin": { + "version": "6.21.0", + "dev": true, + "license": "MIT", + "dependencies": { + "@eslint-community/regexpp": "^4.5.1", + "@typescript-eslint/scope-manager": "6.21.0", + "@typescript-eslint/type-utils": "6.21.0", + "@typescript-eslint/utils": "6.21.0", + "@typescript-eslint/visitor-keys": "6.21.0", + "debug": "^4.3.4", + "graphemer": "^1.4.0", + "ignore": "^5.2.4", + "natural-compare": "^1.4.0", + "semver": "^7.5.4", + "ts-api-utils": "^1.0.1" + }, + "engines": { + "node": "^16.0.0 || >=18.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "@typescript-eslint/parser": "^6.0.0 || ^6.0.0-alpha", + "eslint": "^7.0.0 || ^8.0.0" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/@typescript-eslint/parser": { + "version": "6.21.0", + "dev": true, + "license": "BSD-2-Clause", + "dependencies": { + "@typescript-eslint/scope-manager": "6.21.0", + "@typescript-eslint/types": "6.21.0", + "@typescript-eslint/typescript-estree": "6.21.0", + "@typescript-eslint/visitor-keys": "6.21.0", + "debug": "^4.3.4" + }, + "engines": { + "node": "^16.0.0 || >=18.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^7.0.0 || ^8.0.0" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/@typescript-eslint/scope-manager": { + "version": "6.21.0", + "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/types": "6.21.0", + "@typescript-eslint/visitor-keys": "6.21.0" + }, + "engines": { + "node": "^16.0.0 || >=18.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/@typescript-eslint/type-utils": { + "version": "6.21.0", + "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/typescript-estree": "6.21.0", + "@typescript-eslint/utils": "6.21.0", + "debug": "^4.3.4", + "ts-api-utils": "^1.0.1" + }, + "engines": { + "node": "^16.0.0 || >=18.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^7.0.0 || ^8.0.0" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/@typescript-eslint/types": { + "version": "6.21.0", + "dev": true, + "license": "MIT", + "engines": { + "node": "^16.0.0 || >=18.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/@typescript-eslint/typescript-estree": { + "version": "6.21.0", + "dev": true, + "license": "BSD-2-Clause", + "dependencies": { + "@typescript-eslint/types": "6.21.0", + "@typescript-eslint/visitor-keys": "6.21.0", + "debug": "^4.3.4", + "globby": "^11.1.0", + "is-glob": "^4.0.3", + "minimatch": "9.0.3", + "semver": "^7.5.4", + "ts-api-utils": "^1.0.1" + }, + "engines": { + "node": "^16.0.0 || >=18.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/@typescript-eslint/typescript-estree/node_modules/brace-expansion": { + "version": "2.0.1", + "dev": true, + "license": "MIT", + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "node_modules/@typescript-eslint/typescript-estree/node_modules/minimatch": { + "version": "9.0.3", + "dev": true, + "license": "ISC", + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/@typescript-eslint/utils": { + "version": "6.21.0", + "dev": true, + "license": "MIT", + "dependencies": { + "@eslint-community/eslint-utils": "^4.4.0", + "@types/json-schema": "^7.0.12", + "@types/semver": "^7.5.0", + "@typescript-eslint/scope-manager": "6.21.0", + "@typescript-eslint/types": "6.21.0", + "@typescript-eslint/typescript-estree": "6.21.0", + "semver": "^7.5.4" + }, + "engines": { + "node": "^16.0.0 || >=18.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^7.0.0 || ^8.0.0" + } + }, + "node_modules/@typescript-eslint/visitor-keys": { + "version": "6.21.0", + "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/types": "6.21.0", + "eslint-visitor-keys": "^3.4.1" + }, + "engines": { + "node": "^16.0.0 || >=18.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/@ungap/structured-clone": { + "version": "1.2.0", + "dev": true, + "license": "ISC" + }, + "node_modules/acorn": { + "version": "8.11.3", + "dev": true, + "license": "MIT", + "bin": { + "acorn": "bin/acorn" + }, + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/acorn-jsx": { + "version": "5.3.2", + "dev": true, + "license": "MIT", + "peerDependencies": { + "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" + } + }, + "node_modules/ajv": { + "version": "6.12.6", + "dev": true, + "license": "MIT", + "dependencies": { + "fast-deep-equal": "^3.1.1", + "fast-json-stable-stringify": "^2.0.0", + "json-schema-traverse": "^0.4.1", + "uri-js": "^4.2.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, + "node_modules/ansi-regex": { + "version": "5.0.1", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/ansi-styles": { + "version": "4.3.0", + "dev": true, + "license": "MIT", + "dependencies": { + "color-convert": "^2.0.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/argparse": { + "version": "2.0.1", + "dev": true, + "license": "Python-2.0" + }, + "node_modules/array-union": { + "version": "2.1.0", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/balanced-match": { + "version": "1.0.2", + "dev": true, + "license": "MIT" + }, + "node_modules/bn.js": { + "version": "4.12.0", + "license": "MIT" + }, + "node_modules/brace-expansion": { + "version": "1.1.11", + "dev": true, + "license": "MIT", + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "node_modules/braces": { + "version": "3.0.2", + "dev": true, + "license": "MIT", + "dependencies": { + "fill-range": "^7.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/brorand": { + "version": "1.1.0", + "license": "MIT" + }, + "node_modules/callsites": { + "version": "3.1.0", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + } + }, + "node_modules/chalk": { + "version": "4.1.2", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, + "node_modules/color-convert": { + "version": "2.0.1", + "dev": true, + "license": "MIT", + "dependencies": { + "color-name": "~1.1.4" + }, + "engines": { + "node": ">=7.0.0" + } + }, + "node_modules/color-name": { + "version": "1.1.4", + "dev": true, + "license": "MIT" + }, + "node_modules/concat-map": { + "version": "0.0.1", + "dev": true, + "license": "MIT" + }, + "node_modules/cross-spawn": { + "version": "7.0.3", + "dev": true, + "license": "MIT", + "dependencies": { + "path-key": "^3.1.0", + "shebang-command": "^2.0.0", + "which": "^2.0.1" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/crypto": { + "version": "1.0.1", + "license": "ISC" + }, + "node_modules/debug": { + "version": "4.3.4", + "dev": true, + "license": "MIT", + "dependencies": { + "ms": "2.1.2" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/deep-is": { + "version": "0.1.4", + "dev": true, + "license": "MIT" + }, + "node_modules/dir-glob": { + "version": "3.0.1", + "dev": true, + "license": "MIT", + "dependencies": { + "path-type": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/doctrine": { + "version": "3.0.0", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "esutils": "^2.0.2" + }, + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/dotenv": { + "version": "16.4.5", + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, + "node_modules/elliptic": { + "version": "6.5.5", + "license": "MIT", + "dependencies": { + "bn.js": "^4.11.9", + "brorand": "^1.1.0", + "hash.js": "^1.0.0", + "hmac-drbg": "^1.0.1", + "inherits": "^2.0.4", + "minimalistic-assert": "^1.0.1", + "minimalistic-crypto-utils": "^1.0.1" + } + }, + "node_modules/escape-string-regexp": { + "version": "4.0.0", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/eslint": { + "version": "8.57.0", + "dev": true, + "license": "MIT", + "dependencies": { + "@eslint-community/eslint-utils": "^4.2.0", + "@eslint-community/regexpp": "^4.6.1", + "@eslint/eslintrc": "^2.1.4", + "@eslint/js": "8.57.0", + "@humanwhocodes/config-array": "^0.11.14", + "@humanwhocodes/module-importer": "^1.0.1", + "@nodelib/fs.walk": "^1.2.8", + "@ungap/structured-clone": "^1.2.0", + "ajv": "^6.12.4", + "chalk": "^4.0.0", + "cross-spawn": "^7.0.2", + "debug": "^4.3.2", + "doctrine": "^3.0.0", + "escape-string-regexp": "^4.0.0", + "eslint-scope": "^7.2.2", + "eslint-visitor-keys": "^3.4.3", + "espree": "^9.6.1", + "esquery": "^1.4.2", + "esutils": "^2.0.2", + "fast-deep-equal": "^3.1.3", + "file-entry-cache": "^6.0.1", + "find-up": "^5.0.0", + "glob-parent": "^6.0.2", + "globals": "^13.19.0", + "graphemer": "^1.4.0", + "ignore": "^5.2.0", + "imurmurhash": "^0.1.4", + "is-glob": "^4.0.0", + "is-path-inside": "^3.0.3", + "js-yaml": "^4.1.0", + "json-stable-stringify-without-jsonify": "^1.0.1", + "levn": "^0.4.1", + "lodash.merge": "^4.6.2", + "minimatch": "^3.1.2", + "natural-compare": "^1.4.0", + "optionator": "^0.9.3", + "strip-ansi": "^6.0.1", + "text-table": "^0.2.0" + }, + "bin": { + "eslint": "bin/eslint.js" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/eslint-scope": { + "version": "7.2.2", + "dev": true, + "license": "BSD-2-Clause", + "dependencies": { + "esrecurse": "^4.3.0", + "estraverse": "^5.2.0" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/eslint-visitor-keys": { + "version": "3.4.3", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/espree": { + "version": "9.6.1", + "dev": true, + "license": "BSD-2-Clause", + "dependencies": { + "acorn": "^8.9.0", + "acorn-jsx": "^5.3.2", + "eslint-visitor-keys": "^3.4.1" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/esquery": { + "version": "1.5.0", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "estraverse": "^5.1.0" + }, + "engines": { + "node": ">=0.10" + } + }, + "node_modules/esrecurse": { + "version": "4.3.0", + "dev": true, + "license": "BSD-2-Clause", + "dependencies": { + "estraverse": "^5.2.0" + }, + "engines": { + "node": ">=4.0" + } + }, + "node_modules/estraverse": { + "version": "5.3.0", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=4.0" + } + }, + "node_modules/esutils": { + "version": "2.0.3", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/fast-deep-equal": { + "version": "3.1.3", + "dev": true, + "license": "MIT" + }, + "node_modules/fast-glob": { + "version": "3.3.2", + "dev": true, + "license": "MIT", + "dependencies": { + "@nodelib/fs.stat": "^2.0.2", + "@nodelib/fs.walk": "^1.2.3", + "glob-parent": "^5.1.2", + "merge2": "^1.3.0", + "micromatch": "^4.0.4" + }, + "engines": { + "node": ">=8.6.0" + } + }, + "node_modules/fast-glob/node_modules/glob-parent": { + "version": "5.1.2", + "dev": true, + "license": "ISC", + "dependencies": { + "is-glob": "^4.0.1" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/fast-json-stable-stringify": { + "version": "2.1.0", + "dev": true, + "license": "MIT" + }, + "node_modules/fast-levenshtein": { + "version": "2.0.6", + "dev": true, + "license": "MIT" + }, + "node_modules/fastq": { + "version": "1.17.1", + "dev": true, + "license": "ISC", + "dependencies": { + "reusify": "^1.0.4" + } + }, + "node_modules/fedimint-ts": { + "version": "0.2.23", + "license": "MIT", + "dependencies": { + "crypto": "^1.0.1", + "dotenv": "^16.3.1", + "fedimint-ts": "^0.2.7", + "secp256k1": "^5.0.0" + } + }, + "node_modules/file-entry-cache": { + "version": "6.0.1", + "dev": true, + "license": "MIT", + "dependencies": { + "flat-cache": "^3.0.4" + }, + "engines": { + "node": "^10.12.0 || >=12.0.0" + } + }, + "node_modules/fill-range": { + "version": "7.0.1", + "dev": true, + "license": "MIT", + "dependencies": { + "to-regex-range": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/find-up": { + "version": "5.0.0", + "dev": true, + "license": "MIT", + "dependencies": { + "locate-path": "^6.0.0", + "path-exists": "^4.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/flat-cache": { + "version": "3.2.0", + "dev": true, + "license": "MIT", + "dependencies": { + "flatted": "^3.2.9", + "keyv": "^4.5.3", + "rimraf": "^3.0.2" + }, + "engines": { + "node": "^10.12.0 || >=12.0.0" + } + }, + "node_modules/flatted": { + "version": "3.3.1", + "dev": true, + "license": "ISC" + }, + "node_modules/fs.realpath": { + "version": "1.0.0", + "dev": true, + "license": "ISC" + }, + "node_modules/glob": { + "version": "7.2.3", + "dev": true, + "license": "ISC", + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.1.1", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + }, + "engines": { + "node": "*" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/glob-parent": { + "version": "6.0.2", + "dev": true, + "license": "ISC", + "dependencies": { + "is-glob": "^4.0.3" + }, + "engines": { + "node": ">=10.13.0" + } + }, + "node_modules/globals": { + "version": "13.24.0", + "dev": true, + "license": "MIT", + "dependencies": { + "type-fest": "^0.20.2" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/globby": { + "version": "11.1.0", + "dev": true, + "license": "MIT", + "dependencies": { + "array-union": "^2.1.0", + "dir-glob": "^3.0.1", + "fast-glob": "^3.2.9", + "ignore": "^5.2.0", + "merge2": "^1.4.1", + "slash": "^3.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/graphemer": { + "version": "1.4.0", + "dev": true, + "license": "MIT" + }, + "node_modules/has-flag": { + "version": "4.0.0", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/hash.js": { + "version": "1.1.7", + "license": "MIT", + "dependencies": { + "inherits": "^2.0.3", + "minimalistic-assert": "^1.0.1" + } + }, + "node_modules/hmac-drbg": { + "version": "1.0.1", + "license": "MIT", + "dependencies": { + "hash.js": "^1.0.3", + "minimalistic-assert": "^1.0.0", + "minimalistic-crypto-utils": "^1.0.1" + } + }, + "node_modules/ignore": { + "version": "5.3.1", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 4" + } + }, + "node_modules/import-fresh": { + "version": "3.3.0", + "dev": true, + "license": "MIT", + "dependencies": { + "parent-module": "^1.0.0", + "resolve-from": "^4.0.0" + }, + "engines": { + "node": ">=6" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/imurmurhash": { + "version": "0.1.4", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.8.19" + } + }, + "node_modules/inflight": { + "version": "1.0.6", + "dev": true, + "license": "ISC", + "dependencies": { + "once": "^1.3.0", + "wrappy": "1" + } + }, + "node_modules/inherits": { + "version": "2.0.4", + "license": "ISC" + }, + "node_modules/is-extglob": { + "version": "2.1.1", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-glob": { + "version": "4.0.3", + "dev": true, + "license": "MIT", + "dependencies": { + "is-extglob": "^2.1.1" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-number": { + "version": "7.0.0", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.12.0" + } + }, + "node_modules/is-path-inside": { + "version": "3.0.3", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/isexe": { + "version": "2.0.0", + "dev": true, + "license": "ISC" + }, + "node_modules/js-yaml": { + "version": "4.1.0", + "dev": true, + "license": "MIT", + "dependencies": { + "argparse": "^2.0.1" + }, + "bin": { + "js-yaml": "bin/js-yaml.js" + } + }, + "node_modules/json-buffer": { + "version": "3.0.1", + "dev": true, + "license": "MIT" + }, + "node_modules/json-schema-traverse": { + "version": "0.4.1", + "dev": true, + "license": "MIT" + }, + "node_modules/json-stable-stringify-without-jsonify": { + "version": "1.0.1", + "dev": true, + "license": "MIT" + }, + "node_modules/keyv": { + "version": "4.5.4", + "dev": true, + "license": "MIT", + "dependencies": { + "json-buffer": "3.0.1" + } + }, + "node_modules/levn": { + "version": "0.4.1", + "dev": true, + "license": "MIT", + "dependencies": { + "prelude-ls": "^1.2.1", + "type-check": "~0.4.0" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/locate-path": { + "version": "6.0.0", + "dev": true, + "license": "MIT", + "dependencies": { + "p-locate": "^5.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/lodash.merge": { + "version": "4.6.2", + "dev": true, + "license": "MIT" + }, + "node_modules/lru-cache": { + "version": "6.0.0", + "dev": true, + "license": "ISC", + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/merge2": { + "version": "1.4.1", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 8" + } + }, + "node_modules/micromatch": { + "version": "4.0.5", + "dev": true, + "license": "MIT", + "dependencies": { + "braces": "^3.0.2", + "picomatch": "^2.3.1" + }, + "engines": { + "node": ">=8.6" + } + }, + "node_modules/minimalistic-assert": { + "version": "1.0.1", + "license": "ISC" + }, + "node_modules/minimalistic-crypto-utils": { + "version": "1.0.1", + "license": "MIT" + }, + "node_modules/minimatch": { + "version": "3.1.2", + "dev": true, + "license": "ISC", + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, + "node_modules/ms": { + "version": "2.1.2", + "dev": true, + "license": "MIT" + }, + "node_modules/natural-compare": { + "version": "1.4.0", + "dev": true, + "license": "MIT" + }, + "node_modules/node-addon-api": { + "version": "5.1.0", + "license": "MIT" + }, + "node_modules/node-gyp-build": { + "version": "4.8.0", + "license": "MIT", + "bin": { + "node-gyp-build": "bin.js", + "node-gyp-build-optional": "optional.js", + "node-gyp-build-test": "build-test.js" + } + }, + "node_modules/once": { + "version": "1.4.0", + "dev": true, + "license": "ISC", + "dependencies": { + "wrappy": "1" + } + }, + "node_modules/optionator": { + "version": "0.9.3", + "dev": true, + "license": "MIT", + "dependencies": { + "@aashutoshrathi/word-wrap": "^1.2.3", + "deep-is": "^0.1.3", + "fast-levenshtein": "^2.0.6", + "levn": "^0.4.1", + "prelude-ls": "^1.2.1", + "type-check": "^0.4.0" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/p-limit": { + "version": "3.1.0", + "dev": true, + "license": "MIT", + "dependencies": { + "yocto-queue": "^0.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/p-locate": { + "version": "5.0.0", + "dev": true, + "license": "MIT", + "dependencies": { + "p-limit": "^3.0.2" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/parent-module": { + "version": "1.0.1", + "dev": true, + "license": "MIT", + "dependencies": { + "callsites": "^3.0.0" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/path-exists": { + "version": "4.0.0", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/path-is-absolute": { + "version": "1.0.1", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/path-key": { + "version": "3.1.1", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/path-type": { + "version": "4.0.0", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/picomatch": { + "version": "2.3.1", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8.6" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, + "node_modules/prelude-ls": { + "version": "1.2.1", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/punycode": { + "version": "2.3.1", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + } + }, + "node_modules/queue-microtask": { + "version": "1.2.3", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT" + }, + "node_modules/resolve-from": { + "version": "4.0.0", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=4" + } + }, + "node_modules/reusify": { + "version": "1.0.4", + "dev": true, + "license": "MIT", + "engines": { + "iojs": ">=1.0.0", + "node": ">=0.10.0" + } + }, + "node_modules/rimraf": { + "version": "3.0.2", + "dev": true, + "license": "ISC", + "dependencies": { + "glob": "^7.1.3" + }, + "bin": { + "rimraf": "bin.js" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/run-parallel": { + "version": "1.2.0", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT", + "dependencies": { + "queue-microtask": "^1.2.2" + } + }, + "node_modules/secp256k1": { + "version": "5.0.0", + "hasInstallScript": true, + "license": "MIT", + "dependencies": { + "elliptic": "^6.5.4", + "node-addon-api": "^5.0.0", + "node-gyp-build": "^4.2.0" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/semver": { + "version": "7.6.0", + "dev": true, + "license": "ISC", + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/shebang-command": { + "version": "2.0.0", + "dev": true, + "license": "MIT", + "dependencies": { + "shebang-regex": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/shebang-regex": { + "version": "3.0.0", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/slash": { + "version": "3.0.0", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/strip-ansi": { + "version": "6.0.1", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/strip-json-comments": { + "version": "3.1.1", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/supports-color": { + "version": "7.2.0", + "dev": true, + "license": "MIT", + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/text-table": { + "version": "0.2.0", + "dev": true, + "license": "MIT" + }, + "node_modules/to-regex-range": { + "version": "5.0.1", + "dev": true, + "license": "MIT", + "dependencies": { + "is-number": "^7.0.0" + }, + "engines": { + "node": ">=8.0" + } + }, + "node_modules/ts-api-utils": { + "version": "1.3.0", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=16" + }, + "peerDependencies": { + "typescript": ">=4.2.0" + } + }, + "node_modules/type-check": { + "version": "0.4.0", + "dev": true, + "license": "MIT", + "dependencies": { + "prelude-ls": "^1.2.1" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/type-fest": { + "version": "0.20.2", + "dev": true, + "license": "(MIT OR CC0-1.0)", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/typescript": { + "version": "5.4.5", + "dev": true, + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, + "node_modules/undici-types": { + "version": "5.26.5", + "dev": true, + "license": "MIT" + }, + "node_modules/uri-js": { + "version": "4.4.1", + "dev": true, + "license": "BSD-2-Clause", + "dependencies": { + "punycode": "^2.1.0" + } + }, + "node_modules/which": { + "version": "2.0.2", + "dev": true, + "license": "ISC", + "dependencies": { + "isexe": "^2.0.0" + }, + "bin": { + "node-which": "bin/node-which" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/wrappy": { + "version": "1.0.2", + "dev": true, + "license": "ISC" + }, + "node_modules/yallist": { + "version": "4.0.0", + "dev": true, + "license": "ISC" + }, + "node_modules/yocto-queue": { + "version": "0.1.0", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + } + } +} diff --git a/wrappers/fedimint-ts/package.json b/wrappers/fedimint-ts/package.json index 6b83e69..5b897dd 100644 --- a/wrappers/fedimint-ts/package.json +++ b/wrappers/fedimint-ts/package.json @@ -1,26 +1,28 @@ { "name": "fedimint-ts", - "module": "index.ts", - "type": "module", "author": "The Fedimint Developers", - "license": "MIT", - "version": "0.2.23", "description": "A TypeScript Wrapper for the Fedimint HTTP Client", + "version": "0.2.24", + "license": "MIT", + "files": [ + "dist" + ], "scripts": { "build": "tsc" }, + "type": "module", + "module": "index.ts", + "dependencies": { + "crypto": "^1.0.1", + "dotenv": "^16.3.1", + "fedimint-ts": "^0.2.7", + "secp256k1": "^5.0.0" + }, "devDependencies": { "@types/secp256k1": "^4.0.6", "@typescript-eslint/eslint-plugin": "^6.13.1", "@typescript-eslint/parser": "^6.13.1", - "bun-types": "latest", "eslint": "^8", "typescript": "^5.0.0" - }, - "dependencies": { - "crypto": "^1.0.1", - "dotenv": "^16.3.1", - "fedimint-ts": "^0.2.7", - "secp256k1": "^5.0.0" } } diff --git a/wrappers/fedimint-ts/FedimintClient.ts b/wrappers/fedimint-ts/src/FedimintClient.ts similarity index 92% rename from wrappers/fedimint-ts/FedimintClient.ts rename to wrappers/fedimint-ts/src/FedimintClient.ts index fda8926..ec82560 100644 --- a/wrappers/fedimint-ts/FedimintClient.ts +++ b/wrappers/fedimint-ts/src/FedimintClient.ts @@ -1,4 +1,4 @@ -import type { +import { // BackupRequest, InfoResponse, ListOperationsRequest, @@ -40,20 +40,13 @@ import type { LightningPayResponse, } from "./types"; -/** - * All the methods calling to fedimint clientd are asynchronous and return a Promise that resolves to the data returned by the API. - * @param T - The type of data that the API returns - * @returns - The data returned by the API - */ -type FedimintResponse = Promise; - /** * Builder pattern for creating a FedimintClient. * @param baseUrl - The base URL of the Fedimint API * @param password - The password of the Fedimint client * @param activeFederationId - The ID of the active federation */ -class FedimintClientBuilder { +export class FedimintClientBuilder { private baseUrl: string; private password: string; private activeFederationId: string; @@ -117,7 +110,7 @@ class FedimintClientBuilder { * @param activeFederationId - The ID of the active federation to use for module methods * @param activeGatewayId - Optional, the ID of the active gateway, if not provided, the first gateway in the active federation will be used */ -class FedimintClient { +export class FedimintClient { private baseUrl: string; private password: string; private activeFederationId: string; @@ -194,7 +187,7 @@ class FedimintClient { * Automatically ensures a default federation ID is set if needed. * @param endpoint - The endpoint to make the request to. */ - private async get(endpoint: string): FedimintResponse { + private async get(endpoint: string): Promise { const res = await fetch(`${this.baseUrl}${endpoint}`, { method: "GET", headers: { Authorization: `Bearer ${this.password}` }, @@ -216,7 +209,7 @@ class FedimintClient { * @param endpoint - The endpoint to make the request to. * @param body - The body of the request. */ - private async post(endpoint: string, body: any): FedimintResponse { + private async post(endpoint: string, body: any): Promise { const res = await fetch(`${this.baseUrl}${endpoint}`, { method: "POST", headers: { @@ -248,7 +241,7 @@ class FedimintClient { endpoint: string, body: any, federationId?: string - ): FedimintResponse { + ): Promise { const effectiveFederationId = federationId || this.activeFederationId; return this.post(endpoint, { @@ -272,7 +265,7 @@ class FedimintClient { body: any, gatewayId?: string, federationId?: string - ): FedimintResponse { + ): Promise { try { const effectiveGatewayId = gatewayId || this.activeGatewayId; const effectiveFederationId = federationId || this.activeFederationId; @@ -296,14 +289,14 @@ class FedimintClient { /** * Fetches wallet information including holdings, tiers, and federation metadata. */ - public async info(): FedimintResponse { + public async info(): Promise { return await this.get("/admin/info"); } /** * Returns the client configurations by federationId */ - public async config(): FedimintResponse { + public async config(): Promise { return await this.get("/admin/config"); } @@ -317,7 +310,7 @@ class FedimintClient { // public async backup( // metadata: BackupRequest, // federationId?: string - // ): FedimintResponse { + // ): Promise { // await this.postWithFederationId( // "/admin/backup", // metadata, @@ -330,7 +323,7 @@ class FedimintClient { */ public async discoverVersion( threshold?: number - ): FedimintResponse { + ): Promise { const request: DiscoverVersionRequest = threshold ? { threshold } : {}; return this.post( @@ -347,7 +340,7 @@ class FedimintClient { public async listOperations( limit: number, federationId?: string - ): FedimintResponse { + ): Promise { const request: ListOperationsRequest = { limit }; return await this.postWithFederationId( @@ -360,7 +353,7 @@ class FedimintClient { /** * Returns the current set of connected federation IDs */ - public async federationIds(): FedimintResponse { + public async federationIds(): Promise { return await this.get("/admin/federation-ids"); } @@ -379,7 +372,7 @@ class FedimintClient { setActiveFederationId: boolean, useDefaultGateway: boolean, useManualSecret: boolean = false - ): FedimintResponse { + ): Promise { const request: JoinRequest = { inviteCode, useManualSecret }; const response = await this.post("/admin/join", request); @@ -404,7 +397,7 @@ class FedimintClient { expiryTime?: number, gatewayId?: string, federationId?: string - ): FedimintResponse => { + ): Promise => { const request: LightningInvoiceRequest = { amountMsat, description, @@ -439,7 +432,7 @@ class FedimintClient { expiryTime?: number, gatewayId?: string, federationId?: string - ): FedimintResponse => { + ): Promise => { const request: LightningInvoiceExternalPubkeyTweakedRequest = { externalPubkey: pubkey, tweak, @@ -467,7 +460,7 @@ class FedimintClient { privateKey: string, tweaks: number[], federationId: string - ): FedimintResponse => { + ): Promise => { const request: LightningClaimPubkeyTweakReceivesRequest = { privateKey, tweaks, @@ -488,7 +481,7 @@ class FedimintClient { awaitInvoice: async ( operationId: string, federationId?: string - ): FedimintResponse => { + ): Promise => { const request: LightningAwaitInvoiceRequest = { operationId }; return await this.postWithFederationId( @@ -507,7 +500,7 @@ class FedimintClient { LightningurlComment?: string, gatewayId?: string, federationId?: string - ): FedimintResponse => { + ): Promise => { const request: LightningPayRequest = { paymentInfo, amountMsat, @@ -525,7 +518,7 @@ class FedimintClient { /** * Outputs a list of registered lighting lightning gateways */ - listGateways: async (): FedimintResponse => + listGateways: async (): Promise => await this.postWithFederationId("/ln/list-gateways", {}), }; @@ -538,7 +531,7 @@ class FedimintClient { */ decodeNotes: async ( notes: string - ): FedimintResponse => { + ): Promise => { const request: MintDecodeNotesRequest = { notes, }; @@ -554,7 +547,7 @@ class FedimintClient { */ encodeNotes: async ( notesJson: NotesJson - ): FedimintResponse => { + ): Promise => { const request: MintEncodeNotesRequest = { notesJsonStr: JSON.stringify(notesJson), }; @@ -573,7 +566,7 @@ class FedimintClient { reissue: async ( notes: string, federationId?: string - ): FedimintResponse => { + ): Promise => { const request: MintReissueRequest = { notes }; return await this.postWithFederationId( @@ -599,7 +592,7 @@ class FedimintClient { timeout: number, includeInvite: boolean, federationId?: string - ): FedimintResponse => { + ): Promise => { const request: MintSpendRequest = { amountMsat, allowOverpay, @@ -620,7 +613,7 @@ class FedimintClient { validate: async ( notes: string, federationId?: string - ): FedimintResponse => { + ): Promise => { const request: MintValidateRequest = { notes }; return await this.postWithFederationId( @@ -634,7 +627,7 @@ class FedimintClient { * Splits an ecash note string into its individual notes. * @param notes - The notes to split */ - split: async (notes: string): FedimintResponse => { + split: async (notes: string): Promise => { const request: MintSplitRequest = { notes }; return await this.post("/mint/split", request); @@ -646,7 +639,7 @@ class FedimintClient { */ combine: async ( notesVec: string[] - ): FedimintResponse => { + ): Promise => { const request: MintCombineRequest = { notesVec }; return await this.post("/mint/combine", request); @@ -671,7 +664,7 @@ class FedimintClient { createDepositAddress: async ( timeout: number, federationId?: string - ): FedimintResponse => { + ): Promise => { const request: OnchainDepositAddressRequest = { timeout }; return await this.postWithFederationId( @@ -690,7 +683,7 @@ class FedimintClient { awaitDeposit: async ( operationId: string, federationId?: string - ): FedimintResponse => { + ): Promise => { const request: OnchainAwaitDepositRequest = { operationId }; return await this.postWithFederationId( @@ -714,7 +707,7 @@ class FedimintClient { address: string, amountSat: number | "all", federationId?: string - ): FedimintResponse => { + ): Promise => { const request: OnchainWithdrawRequest = { address, amountSat }; return await this.postWithFederationId( @@ -725,5 +718,3 @@ class FedimintClient { }, }; } - -export { FedimintClientBuilder, FedimintClient }; diff --git a/wrappers/fedimint-ts/src/index.ts b/wrappers/fedimint-ts/src/index.ts new file mode 100644 index 0000000..4dba17d --- /dev/null +++ b/wrappers/fedimint-ts/src/index.ts @@ -0,0 +1,2 @@ +export * from "./types"; +export * from './FedimintClient'; diff --git a/wrappers/fedimint-ts/src/types.ts b/wrappers/fedimint-ts/src/types.ts new file mode 100644 index 0000000..2b1fa2c --- /dev/null +++ b/wrappers/fedimint-ts/src/types.ts @@ -0,0 +1,273 @@ +export interface Tiered { + [amount: number]: T; +} + +export interface TieredSummary { + tiered: Tiered; +} + +export interface InfoResponse { + [federationId: string]: { + network: string; + meta: { [key: string]: string }; + totalAmountMsat: number; + totalNumNotes: number; + denominationsMsat: TieredSummary; + }; +} + +export interface FederationIdsResponse { + federationIds: string[]; +} + +export interface DiscoverVersionRequest { + threshold?: number; +} + +export interface DiscoverVersionResponse { + [federationId: string]: any; +} + +export interface JoinRequest { + inviteCode: string; + useManualSecret: boolean; +} + +export interface JoinResponse { + thisFederationId: string; + federationIds: string[]; +} + +export interface BackupRequest { + metadata: { [key: string]: string }; +} + +export interface ListOperationsRequest { + limit: number; +} + +export interface OperationOutput { + id: string; + creationTime: string; + operationKind: string; + operationMeta: any; + outcome?: any; +} + +export interface OnchainDepositAddressRequest { + timeout: number; +} + +export interface OnchainDepositAddressResponse { + operationId: string; + address: string; +} + +export interface OnchainAwaitDepositRequest { + operationId: string; +} + +export interface BTCInput { + previous_output: string; + script_sig: string; + sequence: number; + witness: string[]; +} + +export interface BTCOutput { + value: number; + script_pubkey: string; +} + +export interface BTCTransaction { + version: number; + lock_time: number; + input: BTCInput[]; + output: BTCOutput[]; +} + +export interface AwaitDepositResponseConfirmed { + btc_transaction: BTCTransaction; + out_idx: number; +} + +export interface OnchainAwaitDepositResponse { + status: { Confirmed: AwaitDepositResponseConfirmed } | { Failed: string }; +} + +export interface OnchainWithdrawRequest { + address: string; + amountSat: number | "all"; +} + +export interface OnchainWithdrawResponse { + txid: string; + feesSat: number; +} + +export interface LightningInvoiceRequest { + amountMsat: number; + description: string; + expiryTime?: number; +} + +export interface LightningInvoiceResponse { + operationId: string; + invoice: string; +} + +export interface LightningInvoiceExternalPubkeyRequest { + amountMsat: number; + description: string; + externalPubkey: string; + expiryTime?: number; +} + +export interface LightningInvoiceExternalPubkeyResponse { + operationId: string; + invoice: string; +} + +export interface LightningInvoiceExternalPubkeyTweakedRequest { + amountMsat: number; + description: string; + externalPubkey: string; + tweak: number; + expiryTime?: number; +} + +export interface LightningInvoiceExternalPubkeyTweakedResponse { + operationId: string; + invoice: string; +} + +export interface LightningClaimPubkeyReceiveRequest { + privateKey: string; +} + +export interface LightningClaimPubkeyReceiveTweakedRequest { + privateKey: string; + tweaks: number[]; +} + +export interface LightningAwaitInvoiceRequest { + operationId: string; +} + +export interface LightningPayRequest { + paymentInfo: string; + amountMsat?: number; + LightningurlComment?: string; +} + +export interface LightningPayResponse { + operationId: string; + paymentType: string; + contractId: string; + fee: number; +} + +export interface LightningAwaitPayRequest { + operationId: string; +} + +export interface GatewayInfo { + api: string; + fees: GatewayFees; + gateway_id: string; + gateway_redeem_key: string; + lightning_alias: string; + mint_channel_id: number; + node_pub_key: string; + route_hints: any[]; // Adjust the type according to the actual structure of route hints + supports_private_payments: boolean; +} + +export interface GatewayFees { + baseMsat: number; + proportionalMillionths: number; +} + +export interface GatewayTTL { + nanos: number; + secs: number; +} + +export interface Gateway { + federation_id: string; + info: GatewayInfo; + ttl: GatewayTTL; + vetted: boolean; +} + +export interface MintDecodeNotesRequest { + notes: string; +} + +export interface MintDecodeNotesResponse { + notesJson: NotesJson; +} + +export interface MintEncodeNotesRequest { + notesJsonStr: string; +} + +export interface MintEncodeNotesResponse { + notes: string; +} + +export interface MintReissueRequest { + notes: string; +} + +export interface MintReissueResponse { + amountMsat: number; +} + +export interface MintSpendRequest { + amountMsat: number; + allowOverpay: boolean; + timeout: number; + includeInvite: boolean; +} + +export interface MintSpendResponse { + operation: string; + notes: string; +} + +export interface MintValidateRequest { + notes: string; +} + +export interface MintValidateResponse { + amountMsat: number; +} + +export interface MintSplitRequest { + notes: string; +} + +export interface MintSplitResponse { + notes: Record; +} + +export interface MintCombineRequest { + notesVec: string[]; +} + +export interface MintCombineResponse { + notes: string; +} + +export interface Note { + signature: string; + spend_key: string; +} + +export interface NotesJson { + federation_id_prefix: string; + notes: { + [denomination: string]: Note[]; + }; +} diff --git a/wrappers/fedimint-ts/example.ts b/wrappers/fedimint-ts/tests/info-example.ts similarity index 83% rename from wrappers/fedimint-ts/example.ts rename to wrappers/fedimint-ts/tests/info-example.ts index dd74461..b31fcb7 100644 --- a/wrappers/fedimint-ts/example.ts +++ b/wrappers/fedimint-ts/tests/info-example.ts @@ -1,10 +1,15 @@ -import { FedimintClientBuilder } from "./FedimintClient"; +/** + * Example that builds a `FedimintClient` connected to a `fedimint-clientd` + * and then uses it to get information about the active Fedimint. + */ + import dotenv from "dotenv"; +import { FedimintClientBuilder } from "../src"; dotenv.config(); async function main() { - const baseUrl = process.env.BASE_URL || "http://localhost:3333"; + const baseUrl = process.env.BASE_URL || "http://127.0.0.1:3333"; const password = process.env.PASSWORD || "password"; const builder = new FedimintClientBuilder(); builder diff --git a/wrappers/fedimint-ts/test.ts b/wrappers/fedimint-ts/tests/test.ts similarity index 99% rename from wrappers/fedimint-ts/test.ts rename to wrappers/fedimint-ts/tests/test.ts index a85aaff..26a5e5a 100644 --- a/wrappers/fedimint-ts/test.ts +++ b/wrappers/fedimint-ts/tests/test.ts @@ -1,7 +1,7 @@ -import { randomBytes } from "crypto"; -import { FedimintClientBuilder } from "./FedimintClient"; import dotenv from "dotenv"; +import { randomBytes } from "crypto"; import * as secp256k1 from "secp256k1"; +import { FedimintClientBuilder } from "../src"; dotenv.config(); diff --git a/wrappers/fedimint-ts/tsconfig.json b/wrappers/fedimint-ts/tsconfig.json index a3944af..412deb0 100644 --- a/wrappers/fedimint-ts/tsconfig.json +++ b/wrappers/fedimint-ts/tsconfig.json @@ -1,23 +1,9 @@ { + "include": ["src/**/*"], "compilerOptions": { - "lib": ["ESNext"], - "module": "esnext", - "target": "esnext", - "moduleResolution": "bundler", - "moduleDetection": "force", - "allowImportingTsExtensions": true, - "noEmit": true, - "composite": true, - "strict": true, - "downlevelIteration": true, - "skipLibCheck": true, - "jsx": "react-jsx", - "allowSyntheticDefaultImports": true, - "forceConsistentCasingInFileNames": true, "allowJs": true, "declaration": true, - "types": [ - "bun-types" // add Bun global - ] + "outDir": "dist", + "declarationMap": true } } diff --git a/wrappers/fedimint-ts/types.ts b/wrappers/fedimint-ts/types.ts deleted file mode 100644 index 09cc701..0000000 --- a/wrappers/fedimint-ts/types.ts +++ /dev/null @@ -1,321 +0,0 @@ -interface Tiered { - [amount: number]: T; -} - -interface TieredSummary { - tiered: Tiered; -} - -interface InfoResponse { - [federationId: string]: { - network: string; - meta: { [key: string]: string }; - totalAmountMsat: number; - totalNumNotes: number; - denominationsMsat: TieredSummary; - }; -} - -interface FederationIdsResponse { - federationIds: string[]; -} - -interface DiscoverVersionRequest { - threshold?: number; -} - -interface DiscoverVersionResponse { - [federationId: string]: any; -} - -interface JoinRequest { - inviteCode: string; - useManualSecret: boolean; -} - -interface JoinResponse { - thisFederationId: string; - federationIds: string[]; -} - -interface BackupRequest { - metadata: { [key: string]: string }; -} - -interface ListOperationsRequest { - limit: number; -} - -interface OperationOutput { - id: string; - creationTime: string; - operationKind: string; - operationMeta: any; - outcome?: any; -} - -interface OnchainDepositAddressRequest { - timeout: number; -} - -interface OnchainDepositAddressResponse { - operationId: string; - address: string; -} - -interface OnchainAwaitDepositRequest { - operationId: string; -} - -interface BTCInput { - previous_output: string; - script_sig: string; - sequence: number; - witness: string[]; -} - -interface BTCOutput { - value: number; - script_pubkey: string; -} - -interface BTCTransaction { - version: number; - lock_time: number; - input: BTCInput[]; - output: BTCOutput[]; -} - -interface AwaitDepositResponseConfirmed { - btc_transaction: BTCTransaction; - out_idx: number; -} - -interface OnchainAwaitDepositResponse { - status: { Confirmed: AwaitDepositResponseConfirmed } | { Failed: string }; -} - -interface OnchainWithdrawRequest { - address: string; - amountSat: number | "all"; -} - -interface OnchainWithdrawResponse { - txid: string; - feesSat: number; -} - -interface LightningInvoiceRequest { - amountMsat: number; - description: string; - expiryTime?: number; -} - -interface LightningInvoiceResponse { - operationId: string; - invoice: string; -} - -interface LightningInvoiceExternalPubkeyRequest { - amountMsat: number; - description: string; - externalPubkey: string; - expiryTime?: number; -} - -interface LightningInvoiceExternalPubkeyResponse { - operationId: string; - invoice: string; -} - -interface LightningInvoiceExternalPubkeyTweakedRequest { - amountMsat: number; - description: string; - externalPubkey: string; - tweak: number; - expiryTime?: number; -} - -interface LightningInvoiceExternalPubkeyTweakedResponse { - operationId: string; - invoice: string; -} - -interface LightningClaimPubkeyReceiveRequest { - privateKey: string; -} - -interface LightningClaimPubkeyReceiveTweakedRequest { - privateKey: string; - tweaks: number[]; -} - -interface LightningAwaitInvoiceRequest { - operationId: string; -} - -interface LightningPayRequest { - paymentInfo: string; - amountMsat?: number; - LightningurlComment?: string; -} - -interface LightningPayResponse { - operationId: string; - paymentType: string; - contractId: string; - fee: number; -} - -interface LightningAwaitPayRequest { - operationId: string; -} - -interface GatewayInfo { - api: string; - fees: GatewayFees; - gateway_id: string; - gateway_redeem_key: string; - lightning_alias: string; - mint_channel_id: number; - node_pub_key: string; - route_hints: any[]; // Adjust the type according to the actual structure of route hints - supports_private_payments: boolean; -} - -interface GatewayFees { - baseMsat: number; - proportionalMillionths: number; -} - -interface GatewayTTL { - nanos: number; - secs: number; -} - -interface Gateway { - federation_id: string; - info: GatewayInfo; - ttl: GatewayTTL; - vetted: boolean; -} - -interface MintDecodeNotesRequest { - notes: string; -} - -interface MintDecodeNotesResponse { - notesJson: NotesJson; -} - -interface MintEncodeNotesRequest { - notesJsonStr: string; -} - -interface MintEncodeNotesResponse { - notes: string; -} - -interface MintReissueRequest { - notes: string; -} - -interface MintReissueResponse { - amountMsat: number; -} - -interface MintSpendRequest { - amountMsat: number; - allowOverpay: boolean; - timeout: number; - includeInvite: boolean; -} - -interface MintSpendResponse { - operation: string; - notes: string; -} - -interface MintValidateRequest { - notes: string; -} - -interface MintValidateResponse { - amountMsat: number; -} - -interface MintSplitRequest { - notes: string; -} - -interface MintSplitResponse { - notes: Record; -} - -interface MintCombineRequest { - notesVec: string[]; -} - -interface MintCombineResponse { - notes: string; -} - -interface Note { - signature: string; - spend_key: string; -} - -interface NotesJson { - federation_id_prefix: string; - notes: { - [denomination: string]: Note[]; - }; -} - -export type { - Tiered, - TieredSummary, - InfoResponse, - FederationIdsResponse, - DiscoverVersionRequest, - DiscoverVersionResponse, - JoinRequest, - JoinResponse, - BackupRequest, - ListOperationsRequest, - OperationOutput, - OnchainDepositAddressRequest, - OnchainDepositAddressResponse, - OnchainAwaitDepositRequest, - OnchainAwaitDepositResponse, - OnchainWithdrawRequest, - OnchainWithdrawResponse, - LightningInvoiceRequest, - LightningInvoiceResponse, - LightningInvoiceExternalPubkeyRequest, - LightningInvoiceExternalPubkeyResponse, - LightningInvoiceExternalPubkeyTweakedRequest, - LightningInvoiceExternalPubkeyTweakedResponse, - LightningClaimPubkeyReceiveRequest, - LightningClaimPubkeyReceiveTweakedRequest, - LightningAwaitInvoiceRequest, - LightningPayRequest, - LightningPayResponse, - LightningAwaitPayRequest, - Gateway, - NotesJson, - MintDecodeNotesRequest, - MintDecodeNotesResponse, - MintEncodeNotesRequest, - MintEncodeNotesResponse, - MintReissueRequest, - MintReissueResponse, - MintSpendRequest, - MintSpendResponse, - MintValidateRequest, - MintValidateResponse, - MintSplitRequest, - MintSplitResponse, - MintCombineRequest, - MintCombineResponse, -};