diff --git a/Cargo.lock b/Cargo.lock index aa2e974..578c9e0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -304,6 +304,12 @@ dependencies = [ "tracing", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "atty" version = "0.2.14" @@ -461,6 +467,16 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base58ck" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c8d66485a3a2ea485c1913c4572ce0256067a5377ac8c75c4960e1cda98605f" +dependencies = [ + "bitcoin-internals 0.3.0", + "bitcoin_hashes 0.14.0", +] + [[package]] name = "base64" version = "0.13.1" @@ -506,6 +522,12 @@ version = "0.10.0-beta" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "98f7eed2b2781a6f0b5c903471d48e15f56fb4e1165df8a9a2337fd1a59d45ea" +[[package]] +name = "bech32" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d965446196e3b7decd44aa7ee49e31d630118f90ef12f97900f262eb915c951d" + [[package]] name = "beef" version = "0.5.2" @@ -596,14 +618,31 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c85783c2fe40083ea54a33aa2f0ba58831d90fcd190f5bdc47e74e84d2a96ae" dependencies = [ "bech32 0.10.0-beta", - "bitcoin-internals", + "bitcoin-internals 0.2.0", "bitcoin_hashes 0.13.0", - "hex-conservative", + "hex-conservative 0.1.1", "hex_lit", "secp256k1 0.28.2", "serde", ] +[[package]] +name = "bitcoin" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea507acc1cd80fc084ace38544bbcf7ced7c2aa65b653b102de0ce718df668f6" +dependencies = [ + "base58ck", + "bech32 0.11.0", + "bitcoin-internals 0.3.0", + "bitcoin-io", + "bitcoin-units", + "bitcoin_hashes 0.14.0", + "hex-conservative 0.2.1", + "hex_lit", + "secp256k1 0.29.0", +] + [[package]] name = "bitcoin-internals" version = "0.2.0" @@ -613,12 +652,33 @@ dependencies = [ "serde", ] +[[package]] +name = "bitcoin-internals" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30bdbe14aa07b06e6cfeffc529a1f099e5fbe249524f8125358604df99a4bed2" + +[[package]] +name = "bitcoin-io" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "340e09e8399c7bd8912f495af6aa58bea0c9214773417ffaa8f6460f93aaee56" + [[package]] name = "bitcoin-private" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73290177011694f38ec25e165d0387ab7ea749a4b81cd4c80dae5988229f7a57" +[[package]] +name = "bitcoin-units" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb54da0b28892f3c52203a7191534033e051b6f4b52bc15480681b57b7e036f5" +dependencies = [ + "bitcoin-internals 0.3.0", +] + [[package]] name = "bitcoin_hashes" version = "0.11.0" @@ -645,11 +705,21 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1930a4dabfebb8d7d9992db18ebe3ae2876f0a305fab206fd168df931ede293b" dependencies = [ - "bitcoin-internals", - "hex-conservative", + "bitcoin-internals 0.2.0", + "hex-conservative 0.1.1", "serde", ] +[[package]] +name = "bitcoin_hashes" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb18c03d0db0247e147a21a6faafd5a7eb851c743db062de72018b6b7e8e4d16" +dependencies = [ + "bitcoin-io", + "hex-conservative 0.2.1", +] + [[package]] name = "bitcoincore-rpc" version = "0.16.0" @@ -1242,6 +1312,16 @@ dependencies = [ "serde", ] +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + [[package]] name = "esplora-client" version = "0.5.0" @@ -1788,6 +1868,18 @@ dependencies = [ "validator", ] +[[package]] +name = "fedimint_clientd_rs" +version = "0.0.6" +dependencies = [ + "bitcoin 0.32.2", + "reqwest 0.12.4", + "serde", + "serde_json", + "tokio", + "tracing", +] + [[package]] name = "ff" version = "0.12.1" @@ -1824,6 +1916,21 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + [[package]] name = "form_urlencoded" version = "1.2.1" @@ -2071,6 +2178,25 @@ dependencies = [ "tracing", ] +[[package]] +name = "h2" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa82e28a107a8cc405f0839610bdc9b15f1e25ec7d696aa5cf173edbcb1486ab" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http 1.1.0", + "indexmap 2.2.6", + "slab", + "tokio", + "tokio-util", + "tracing", +] + [[package]] name = "half" version = "2.4.1" @@ -2149,6 +2275,15 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "30ed443af458ccb6d81c1e7e661545f94d3176752fb1df2f543b902a1e0f51e2" +[[package]] +name = "hex-conservative" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5313b072ce3c597065a808dbf612c4c8e8590bdbf8b579508bf7a762c5eae6cd" +dependencies = [ + "arrayvec", +] + [[package]] name = "hex_fmt" version = "0.3.0" @@ -2254,7 +2389,7 @@ dependencies = [ "futures-channel", "futures-core", "futures-util", - "h2", + "h2 0.3.26", "http 0.2.12", "http-body 0.4.6", "httparse", @@ -2277,6 +2412,7 @@ dependencies = [ "bytes", "futures-channel", "futures-util", + "h2 0.4.5", "http 1.1.0", "http-body 1.0.0", "httparse", @@ -2319,6 +2455,22 @@ dependencies = [ "tower-service", ] +[[package]] +name = "hyper-tls" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper 1.3.1", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] + [[package]] name = "hyper-util" version = "0.1.3" @@ -2816,6 +2968,12 @@ dependencies = [ "serde", ] +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + [[package]] name = "lnurl-pay" version = "0.5.0" @@ -3044,6 +3202,23 @@ dependencies = [ "tracing", ] +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + [[package]] name = "negentropy" version = "0.3.1" @@ -3287,6 +3462,50 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" +[[package]] +name = "openssl" +version = "0.10.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95a0481286a310808298130d22dd1fef0fa571e05a8f44ec801801e84b216b1f" +dependencies = [ + "bitflags 2.5.0", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.60", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.102" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c597637d56fbc83893a35eb0dd04b2b8e7a50c91e64e9493e398b5df4fb45fa2" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "opentelemetry" version = "0.22.0" @@ -3831,7 +4050,7 @@ dependencies = [ "encoding_rs", "futures-core", "futures-util", - "h2", + "h2 0.3.26", "http 0.2.12", "http-body 0.4.6", "hyper 0.14.28", @@ -3870,18 +4089,22 @@ checksum = "566cafdd92868e0939d3fb961bd0dc25fcfaaed179291093b3d43e6b3150ea10" dependencies = [ "base64 0.22.0", "bytes", + "encoding_rs", "futures-core", "futures-util", + "h2 0.4.5", "http 1.1.0", "http-body 1.0.0", "http-body-util", "hyper 1.3.1", "hyper-rustls 0.26.0", + "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", + "native-tls", "once_cell", "percent-encoding", "pin-project-lite", @@ -3892,7 +4115,9 @@ dependencies = [ "serde_json", "serde_urlencoded", "sync_wrapper 0.1.2", + "system-configuration", "tokio", + "tokio-native-tls", "tokio-rustls 0.25.0", "tokio-socks", "tower-service", @@ -3996,6 +4221,19 @@ dependencies = [ "semver", ] +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags 2.5.0", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + [[package]] name = "rustls" version = "0.20.9" @@ -4101,6 +4339,15 @@ dependencies = [ "cipher", ] +[[package]] +name = "schannel" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbc91545643bcf3a0bbb6569265615222618bdf33ce4ffbbd13c4bbd4c093534" +dependencies = [ + "windows-sys 0.52.0", +] + [[package]] name = "scopeguard" version = "1.2.0" @@ -4165,6 +4412,16 @@ dependencies = [ "serde", ] +[[package]] +name = "secp256k1" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e0cc0f1cf93f4969faf3ea1c7d8a9faed25918d96affa959720823dfe86d4f3" +dependencies = [ + "bitcoin_hashes 0.13.0", + "secp256k1-sys 0.10.0", +] + [[package]] name = "secp256k1-sys" version = "0.6.1" @@ -4192,6 +4449,15 @@ dependencies = [ "cc", ] +[[package]] +name = "secp256k1-sys" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1433bd67156263443f14d603720b082dd3121779323fce20cba2aa07b874bc1b" +dependencies = [ + "cc", +] + [[package]] name = "secp256k1-zkp" version = "0.7.0" @@ -4214,6 +4480,29 @@ dependencies = [ "secp256k1-sys 0.6.1", ] +[[package]] +name = "security-framework" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c627723fd09706bacdb5cf41499e95098555af3c3c29d014dc3c458ef6be11c0" +dependencies = [ + "bitflags 2.5.0", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "317936bbbd05227752583946b9e66d7ce3b489f84e11a94a510b4437fef407d7" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "semver" version = "1.0.23" @@ -4266,9 +4555,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.116" +version = "1.0.117" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e17db7126d17feb94eb3fad46bf1a96b034e8aacbc2e775fe81505f8b0b2813" +checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" dependencies = [ "indexmap 2.2.6", "itoa", @@ -4563,6 +4852,18 @@ version = "0.12.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1fc403891a21bcfb7c37834ba66a547a8f402146eba7265b5a6d88059c9ff2f" +[[package]] +name = "tempfile" +version = "3.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" +dependencies = [ + "cfg-if", + "fastrand", + "rustix", + "windows-sys 0.52.0", +] + [[package]] name = "termcolor" version = "1.4.1" @@ -4676,9 +4977,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.37.0" +version = "1.38.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" dependencies = [ "backtrace", "bytes", @@ -4696,15 +4997,25 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "2.2.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +checksum = "5f5ae998a069d4b5aba8ee9dad856af7d520c3699e6159b185c2acd48155d39a" dependencies = [ "proc-macro2", "quote", "syn 2.0.60", ] +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + [[package]] name = "tokio-rustls" version = "0.23.4" diff --git a/Cargo.toml b/Cargo.toml index 3b8de8b..4751375 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = ["multimint", "fedimint-clientd", "fedimint-nwc"] +members = ["multimint", "fedimint-clientd", "fedimint-nwc", "wrappers/fedimint_clientd_rs"] resolver = "2" [workspace.package] diff --git a/wrappers/fedimint-ts/src/FedimintClient.ts b/wrappers/fedimint-ts/src/FedimintClient.ts index 7a9606d..259d538 100644 --- a/wrappers/fedimint-ts/src/FedimintClient.ts +++ b/wrappers/fedimint-ts/src/FedimintClient.ts @@ -97,7 +97,7 @@ export class FedimintClientBuilder { this.baseUrl, this.password, this.activeFederationId, - this.activeGatewayId + this.activeGatewayId, ); return client; @@ -121,14 +121,14 @@ export class FedimintClient { baseUrl: string, password: string, activeFederationId: string, - activeGatewayId: string = "" + activeGatewayId: string = "", ) { this.baseUrl = baseUrl + "/v2"; this.password = password; this.activeFederationId = activeFederationId; this.activeGatewayId = activeGatewayId; console.log( - "Fedimint Client initialized, must set activeGatewayId after intitalization to use lightning module methods or manually pass in gateways" + "Fedimint Client initialized, must set activeGatewayId after intitalization to use lightning module methods or manually pass in gateways", ); } @@ -153,7 +153,7 @@ export class FedimintClient { }); } else { console.log( - "Clearing active gateway id, must be set manually on lightning calls or setDefaultGatewayId to true" + "Clearing active gateway id, must be set manually on lightning calls or setDefaultGatewayId to true", ); this.activeGatewayId = ""; } @@ -196,7 +196,7 @@ export class FedimintClient { if (!res.ok) { throw new Error( - `GET request failed. Status: ${res.status}, Body: ${await res.text()}` + `GET request failed. Status: ${res.status}, Body: ${await res.text()}`, ); } @@ -222,7 +222,7 @@ export class FedimintClient { if (!res.ok) { throw new Error( - `POST request failed. Status: ${res.status}, Body: ${await res.text()}` + `POST request failed. Status: ${res.status}, Body: ${await res.text()}`, ); } @@ -241,7 +241,7 @@ export class FedimintClient { private async postWithFederationId( endpoint: string, body: any, - federationId?: string + federationId?: string, ): Promise { const effectiveFederationId = federationId || this.activeFederationId; @@ -265,7 +265,7 @@ export class FedimintClient { endpoint: string, body: any, gatewayId?: string, - federationId?: string + federationId?: string, ): Promise { try { const effectiveGatewayId = gatewayId || this.activeGatewayId; @@ -273,7 +273,7 @@ export class FedimintClient { if (effectiveFederationId === "" || effectiveGatewayId === "") { throw new Error( - "Must set active federation and gateway id before posting with them" + "Must set active federation and gateway id before posting with them", ); } @@ -323,13 +323,13 @@ export class FedimintClient { * Returns the common API version to use to communicate with the federation and modules */ public async discoverVersion( - threshold?: number + threshold?: number, ): Promise { const request: DiscoverVersionRequest = threshold ? { threshold } : {}; return this.post( "/admin/discover-version", - request + request, ); } @@ -340,14 +340,14 @@ export class FedimintClient { */ public async listOperations( limit: number, - federationId?: string + federationId?: string, ): Promise { const request: ListOperationsRequest = { limit }; return await this.postWithFederationId( "/admin/list-operations", request, - federationId + federationId, ); } @@ -372,7 +372,7 @@ export class FedimintClient { inviteCode: string, setActiveFederationId: boolean, useDefaultGateway: boolean, - useManualSecret: boolean = false + useManualSecret: boolean = false, ): Promise { const request: JoinRequest = { inviteCode, useManualSecret }; @@ -395,13 +395,13 @@ export class FedimintClient { createInvoice: async ( request: LightningInvoiceRequest, gatewayId?: string, - federationId?: string + federationId?: string, ): Promise => { return await this.postWithGatewayIdAndFederationId( "/ln/invoice", request, gatewayId, - federationId + federationId, ); }, @@ -420,13 +420,13 @@ export class FedimintClient { createInvoiceForPubkeyTweak: async ( request: LightningInvoiceExternalPubkeyTweakedRequest, gatewayId?: string, - federationId?: string + federationId?: string, ): Promise => { return await this.postWithGatewayIdAndFederationId( "/ln/invoice-external-pubkey-tweaked", request, gatewayId, - federationId + federationId, ); }, @@ -439,12 +439,12 @@ export class FedimintClient { */ claimPubkeyTweakReceives: async ( request: LightningClaimPubkeyTweakReceivesRequest, - federationId: string + federationId: string, ): Promise => { return await this.postWithFederationId( "/ln/claim-external-receive-tweaked", request, - federationId + federationId, ); }, @@ -455,14 +455,14 @@ export class FedimintClient { */ awaitInvoice: async ( operationId: string, - federationId?: string + federationId?: string, ): Promise => { const request: LightningAwaitInvoiceRequest = { operationId }; return await this.postWithFederationId( "/ln/await-invoice", request, - federationId + federationId, ); }, @@ -472,13 +472,13 @@ export class FedimintClient { pay: async ( request: LightningPayRequest, gatewayId?: string, - federationId?: string + federationId?: string, ): Promise => { return await this.postWithGatewayIdAndFederationId( "/ln/pay", request, gatewayId, - federationId + federationId, ); }, @@ -503,7 +503,7 @@ export class FedimintClient { return await this.post( "/mint/decode-notes", - request + request, ); }, @@ -511,7 +511,7 @@ export class FedimintClient { * Encodes json notes to hex encoded binary notes */ encodeNotes: async ( - notesJson: NotesJson + notesJson: NotesJson, ): Promise => { const request: MintEncodeNotesRequest = { notesJsonStr: JSON.stringify(notesJson), @@ -519,7 +519,7 @@ export class FedimintClient { return await this.post( "/mint/encode-notes", - request + request, ); }, @@ -530,14 +530,14 @@ export class FedimintClient { */ reissue: async ( notes: string, - federationId?: string + federationId?: string, ): Promise => { const request: MintReissueRequest = { notes }; return await this.postWithFederationId( "/mint/reissue", request, - federationId + federationId, ); }, @@ -553,12 +553,12 @@ export class FedimintClient { */ spend: async ( request: MintSpendRequest, - federationId?: string + federationId?: string, ): Promise => { return await this.postWithFederationId( "/mint/spend", request, - federationId + federationId, ); }, @@ -567,14 +567,14 @@ export class FedimintClient { */ validate: async ( notes: string, - federationId?: string + federationId?: string, ): Promise => { const request: MintValidateRequest = { notes }; return await this.postWithFederationId( "/mint/validate", request, - federationId + federationId, ); }, @@ -616,14 +616,14 @@ export class FedimintClient { */ createDepositAddress: async ( timeout: number, - federationId?: string + federationId?: string, ): Promise => { const request: OnchainDepositAddressRequest = { timeout }; return await this.postWithFederationId( "/onchain/deposit-address", request, - federationId + federationId, ); }, @@ -635,14 +635,14 @@ export class FedimintClient { */ awaitDeposit: async ( operationId: string, - federationId?: string + federationId?: string, ): Promise => { const request: OnchainAwaitDepositRequest = { operationId }; return await this.postWithFederationId( "/onchain/await-deposit", request, - federationId + federationId, ); }, @@ -659,14 +659,14 @@ export class FedimintClient { withdraw: async ( address: string, amountSat: number | "all", - federationId?: string + federationId?: string, ): Promise => { const request: OnchainWithdrawRequest = { address, amountSat }; return await this.postWithFederationId( "/onchain/withdraw", request, - federationId + federationId, ); }, }; diff --git a/wrappers/fedimint_clientd_rs/.gitignore b/wrappers/fedimint_clientd_rs/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/wrappers/fedimint_clientd_rs/.gitignore @@ -0,0 +1 @@ +/target diff --git a/wrappers/fedimint_clientd_rs/Cargo.lock b/wrappers/fedimint_clientd_rs/Cargo.lock new file mode 100644 index 0000000..60168d7 --- /dev/null +++ b/wrappers/fedimint_clientd_rs/Cargo.lock @@ -0,0 +1,1391 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "arrayvec" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" + +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17c6a35df3749d2e8bb1b7b21a976d82b15548788d2735b9d82f329268f71a11" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "base58ck" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c8d66485a3a2ea485c1913c4572ce0256067a5377ac8c75c4960e1cda98605f" +dependencies = [ + "bitcoin-internals", + "bitcoin_hashes", +] + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bech32" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d965446196e3b7decd44aa7ee49e31d630118f90ef12f97900f262eb915c951d" + +[[package]] +name = "bitcoin" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea507acc1cd80fc084ace38544bbcf7ced7c2aa65b653b102de0ce718df668f6" +dependencies = [ + "base58ck", + "bech32", + "bitcoin-internals", + "bitcoin-io", + "bitcoin-units", + "bitcoin_hashes", + "hex-conservative", + "hex_lit", + "secp256k1", +] + +[[package]] +name = "bitcoin-internals" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30bdbe14aa07b06e6cfeffc529a1f099e5fbe249524f8125358604df99a4bed2" + +[[package]] +name = "bitcoin-io" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "340e09e8399c7bd8912f495af6aa58bea0c9214773417ffaa8f6460f93aaee56" + +[[package]] +name = "bitcoin-units" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb54da0b28892f3c52203a7191534033e051b6f4b52bc15480681b57b7e036f5" +dependencies = [ + "bitcoin-internals", +] + +[[package]] +name = "bitcoin_hashes" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb18c03d0db0247e147a21a6faafd5a7eb851c743db062de72018b6b7e8e4d16" +dependencies = [ + "bitcoin-io", + "hex-conservative", +] + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + +[[package]] +name = "cc" +version = "1.0.98" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41c270e7540d725e65ac7f1b212ac8ce349719624d7bcff99f8e2e488e8cf03f" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" + +[[package]] +name = "fedimint_clientd_rs" +version = "0.0.1" +dependencies = [ + "bitcoin", + "reqwest", + "serde", + "serde_json", + "tokio", + "tracing", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-core", + "futures-task", + "pin-project-lite", + "pin-utils", +] + +[[package]] +name = "gimli" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" + +[[package]] +name = "h2" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa82e28a107a8cc405f0839610bdc9b15f1e25ec7d696aa5cf173edbcb1486ab" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "hex-conservative" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5313b072ce3c597065a808dbf612c4c8e8590bdbf8b579508bf7a762c5eae6cd" +dependencies = [ + "arrayvec", +] + +[[package]] +name = "hex_lit" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3011d1213f159867b13cfd6ac92d2cd5f1345762c63be3554e84092d85a50bbd" + +[[package]] +name = "http" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0475f8b2ac86659c21b64320d5d653f9efe42acd2a4e560073ec61a155a34f1d" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" + +[[package]] +name = "hyper" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe575dd17d0862a9a33781c8c4696a55c320909004a67a00fb286ba8b1bc496d" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-tls" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] + +[[package]] +name = "hyper-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b875924a60b96e5d7b9ae7b066540b1dd1cbd90d1828f54c92e02a283351c56" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower", + "tower-service", + "tracing", +] + +[[package]] +name = "idna" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "indexmap" +version = "2.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "ipnet" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87dfd01fe195c66b572b37921ad8803d010623c0aca821bea2302239d155cdae" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.35.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8ec7ab813848ba4522158d5517a6093db1ded27575b070f4177b8d12b41db5e" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "openssl" +version = "0.10.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95a0481286a310808298130d22dd1fef0fa571e05a8f44ec801801e84b216b1f" +dependencies = [ + "bitflags 2.5.0", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.102" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c597637d56fbc83893a35eb0dd04b2b8e7a50c91e64e9493e398b5df4fb45fa2" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.5", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "pin-project" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" + +[[package]] +name = "proc-macro2" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +dependencies = [ + "bitflags 2.5.0", +] + +[[package]] +name = "reqwest" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "566cafdd92868e0939d3fb961bd0dc25fcfaaed179291093b3d43e6b3150ea10" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "winreg", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags 2.5.0", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls-pemfile" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29993a25686778eb88d4189742cd713c9bce943bc54251a33509dc63cbacf73d" +dependencies = [ + "base64", + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "976295e77ce332211c0d24d92c0e83e50f5c5f046d11082cea19f3df13a3562d" + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "schannel" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbc91545643bcf3a0bbb6569265615222618bdf33ce4ffbbd13c4bbd4c093534" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "secp256k1" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e0cc0f1cf93f4969faf3ea1c7d8a9faed25918d96affa959720823dfe86d4f3" +dependencies = [ + "bitcoin_hashes", + "secp256k1-sys", +] + +[[package]] +name = "secp256k1-sys" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1433bd67156263443f14d603720b082dd3121779323fce20cba2aa07b874bc1b" +dependencies = [ + "cc", +] + +[[package]] +name = "security-framework" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c627723fd09706bacdb5cf41499e95098555af3c3c29d014dc3c458ef6be11c0" +dependencies = [ + "bitflags 2.5.0", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "317936bbbd05227752583946b9e66d7ce3b489f84e11a94a510b4437fef407d7" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "serde" +version = "1.0.203" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.203" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.117" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "syn" +version = "2.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" + +[[package]] +name = "system-configuration" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" +dependencies = [ + "cfg-if", + "fastrand", + "rustix", + "windows-sys 0.52.0", +] + +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-macros" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f5ae998a069d4b5aba8ee9dad856af7d520c3699e6159b185c2acd48155d39a" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" +dependencies = [ + "futures-core", + "futures-util", + "pin-project", + "pin-project-lite", + "tokio", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-layer" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" + +[[package]] +name = "tower-service" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "url" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76bc14366121efc8dbb487ab05bcc9d346b3b5ec0eaa76e46594cabbe51762c0" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" + +[[package]] +name = "web-sys" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" + +[[package]] +name = "winreg" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a277a57398d4bfa075df44f501a17cfdf8542d224f0d36095a2adc7aee4ef0a5" +dependencies = [ + "cfg-if", + "windows-sys 0.48.0", +] diff --git a/wrappers/fedimint_clientd_rs/Cargo.toml b/wrappers/fedimint_clientd_rs/Cargo.toml new file mode 100644 index 0000000..3d2d433 --- /dev/null +++ b/wrappers/fedimint_clientd_rs/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "fedimint_clientd_rs" +version = "0.0.6" +edition = "2021" +description = "Rust client for hitting the REST endpoints on a fedimint clientd" +repository = "https://github.com/fedimint/fedimint-clientd" +license = "MIT" +readme = "README.md" +homepage = "https://github.com/fedimint/fedimint-clientd" + +[dependencies] +reqwest = { version = "0.12.4", features = ["json"] } +serde = { version = "1.0.197", features = ["derive"] } +serde_json = "1.0.117" +tracing = "0.1.40" +tokio = { version = "1.38.0", features = ["full"] } +bitcoin = "0.32.2" diff --git a/wrappers/fedimint_clientd_rs/README.md b/wrappers/fedimint_clientd_rs/README.md new file mode 100644 index 0000000..3b101ba --- /dev/null +++ b/wrappers/fedimint_clientd_rs/README.md @@ -0,0 +1,3 @@ +# Fedimint Clientd Rust Client + +Rust client for hitting the REST endpoints on a fedimint clientd. diff --git a/wrappers/fedimint_clientd_rs/src/client/admin/mod.rs b/wrappers/fedimint_clientd_rs/src/client/admin/mod.rs new file mode 100644 index 0000000..8c93949 --- /dev/null +++ b/wrappers/fedimint_clientd_rs/src/client/admin/mod.rs @@ -0,0 +1,81 @@ +pub mod types; + +use crate::FedimintClient; +use serde_json::Value; +pub use types::*; + +impl FedimintClient { + /// Returns info about each joined federation + pub async fn info(&self) -> Result { + self.get::("/admin/info").await + } + + /// Returns the client configuration + pub async fn config(&self) -> Result { + self.get::("/admin/config").await + } + + /// Returns the current set of connected federation IDs + pub async fn federation_ids(&self) -> Result { + self.get::("/admin/federation-ids") + .await + } + + /// Returns the common API version to use to communicate with the federation and modules + pub async fn discover_version( + &self, + threshold: usize, + ) -> Result { + self.post::( + "/admin/discover-version", + DiscoverVersionRequest { threshold }, + ) + .await + } + + /// Output a list of the most recent operations performed by this client on the currently-active federation + pub async fn list_operations(&self, limit: u64) -> Result { + let federation_id = self.active_federation_id.clone(); + + if federation_id.is_empty() { + return Err("Federation ID Required".to_string()); + } + + self.post::( + "/admin/list-operations", + ListOperationsRequest { + limit, + federationId: federation_id, + }, + ) + .await + } + + pub async fn join(&mut self, options: JoinOptions) -> Result { + let response = self + .post::( + "/admin/join", + JoinRequest { + inviteCode: options.invite_code, + useManualSecret: options.use_manual_secret, + }, + ) + .await; + + match response { + Ok(res) => { + if options.set_active_federation_id { + let _ = self + .switch_federation_id( + res.clone().this_federation_id, + options.use_default_gateway, + ) + .await; + } + + Ok(res) + } + Err(err) => Err(err), + } + } +} diff --git a/wrappers/fedimint_clientd_rs/src/client/admin/types.rs b/wrappers/fedimint_clientd_rs/src/client/admin/types.rs new file mode 100644 index 0000000..fe9b0a3 --- /dev/null +++ b/wrappers/fedimint_clientd_rs/src/client/admin/types.rs @@ -0,0 +1,80 @@ +#![allow(non_snake_case)] + +use serde::{Deserialize, Serialize}; +use serde_json::Value; +use std::collections::HashMap; + +use crate::client::types::{FederationInfo, OperationOutput}; + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +pub struct ListOperationsRequest { + pub limit: u64, + pub federationId: String, +} + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +pub struct JoinRequest { + pub inviteCode: String, + pub useManualSecret: bool, +} + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +pub struct DiscoverVersionRequest { + pub threshold: usize, +} + +pub type InfoResponse = HashMap; + +pub type DiscoverVersionResponse = HashMap; + +#[derive(Debug, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct ListOperationsResponse { + pub operations: Vec, +} + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct FederationIdsResponse { + pub federation_ids: Vec, +} + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct JoinResponse { + pub this_federation_id: String, + pub federation_ids: Vec, +} + +pub struct JoinOptions { + pub invite_code: String, + pub use_default_gateway: bool, + pub set_active_federation_id: bool, + pub use_manual_secret: bool, +} + +impl JoinOptions { + pub fn new(invite_code: String) -> Self { + JoinOptions { + invite_code, + set_active_federation_id: false, + use_default_gateway: false, + use_manual_secret: false, + } + } + + pub fn set_active_federation_id(mut self) -> Self { + self.set_active_federation_id = true; + self + } + + pub fn use_default_gateway(mut self) -> Self { + self.use_default_gateway = true; + self + } + + pub fn use_manual_secret(mut self) -> Self { + self.use_manual_secret = true; + self + } +} diff --git a/wrappers/fedimint_clientd_rs/src/client/lightning/mod.rs b/wrappers/fedimint_clientd_rs/src/client/lightning/mod.rs new file mode 100644 index 0000000..9444dea --- /dev/null +++ b/wrappers/fedimint_clientd_rs/src/client/lightning/mod.rs @@ -0,0 +1,127 @@ +pub mod types; + +use super::types::Gateway; +use crate::FedimintClient; +pub use types::*; + +impl FedimintClient { + pub async fn create_invoice( + &self, + opts: InvoiceOptions, + ) -> Result { + let federation_id = self.active_federation_id.clone(); + + if federation_id.is_empty() { + return Err("Federation ID Required".to_string()); + } + + self.post::( + "/ln/invoice", + CreateInvoiceRequest { + federationId: federation_id, + gatewayId: self.active_gateway_id.to_owned(), + amountMsat: opts.amount_msat, + description: opts.description, + expiryTime: opts.expiry_time, + }, + ) + .await + } + + pub async fn create_invoice_for_pubkey_tweak( + &self, + opts: TweakedInvoiceOptions, + ) -> Result { + let federation_id = self.active_federation_id.clone(); + + if federation_id.is_empty() { + return Err("Federation ID Required".to_string()); + } + + self.post::( + "/ln/invoice-external-pubkey-tweaked", + CreateTweakedInvoiceRequest { + federationId: federation_id, + gatewayId: self.active_gateway_id.to_owned(), + amountMsat: opts.amount_msat, + description: opts.description, + externalPubkey: opts.external_pubkey, + tweak: opts.tweak, + expiryTime: opts.expiry_time, + }, + ) + .await + } + + pub async fn claim_pubkey_tweak_receives( + &self, + private_key: String, + tweaks: Vec, + ) -> Result { + let federation_id = self.active_federation_id.clone(); + + if federation_id.is_empty() { + return Err("Federation ID Required".to_string()); + } + + self.post::( + "/ln/claim-external-receive-tweaked", + ClaimPubkeyTweakRequest { + federationId: federation_id, + privateKey: private_key, + tweaks, + }, + ) + .await + } + + pub async fn await_invoice( + &self, + operation_id: String, + ) -> Result { + let federation_id = self.active_federation_id.clone(); + + if federation_id.is_empty() { + return Err("Federation ID Required".to_string()); + } + + self.post::( + "/ln/await-invoice", + AwaitInvoiceRequest { + federationId: federation_id, + operationId: operation_id, + }, + ) + .await + } + + pub async fn pay(&self, args: PayOptions) -> Result { + let federation_id = self.active_federation_id.clone(); + + if federation_id.is_empty() { + return Err("Federation ID Required".to_string()); + } + + self.post::( + "/ln/pay", + LightningPayRequest { + federationId: federation_id, + gatewayId: self.active_gateway_id.to_owned(), + paymentInfo: args.payment_info, + amountMsat: args.amount_msat, + LightningurlComment: args.lightningurl_comment, + }, + ) + .await + } + + pub async fn list_gateways(&self) -> Result, String> { + self.post::>( + "/ln/list-gateways", + ListGatewaysRequest { + federationId: self.active_federation_id.to_owned(), + }, + ) + .await + } +} diff --git a/wrappers/fedimint_clientd_rs/src/client/lightning/types.rs b/wrappers/fedimint_clientd_rs/src/client/lightning/types.rs new file mode 100644 index 0000000..28e7237 --- /dev/null +++ b/wrappers/fedimint_clientd_rs/src/client/lightning/types.rs @@ -0,0 +1,231 @@ +#![allow(non_snake_case)] + +use serde::{Deserialize, Serialize}; + +use crate::client::types::LnReceiveState; + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct CreateInvoiceResponse { + pub operation_id: String, + pub invoice: String, +} + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct LightningPaymentResponse { + pub status: LnReceiveState, +} + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct AwaitInvoiceResponse { + pub status: LnReceiveState, +} + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct LightningPayResponse { + pub operation_id: String, + pub payment_type: PayType, + pub contract_id: String, + pub fee: u64, + pub preimage: String, +} + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "snake_case")] +pub enum PayType { + // Payment from this client to another user within the federation + Internal(String), + // Payment from this client to another user, facilitated by a gateway + Lightning(String), +} + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +pub struct CreateInvoiceRequest { + pub gatewayId: String, + pub federationId: String, + pub amountMsat: u64, + pub description: String, + pub expiryTime: Option, +} + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +pub struct CreateTweakedInvoiceRequest { + pub gatewayId: String, + pub federationId: String, + pub amountMsat: u64, + pub tweak: u64, + pub description: String, + pub expiryTime: Option, + pub externalPubkey: String, +} + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +pub struct ClaimPubkeyTweakRequest { + pub federationId: String, + pub privateKey: String, + pub tweaks: Vec, +} + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +pub struct AwaitInvoiceRequest { + pub federationId: String, + pub operationId: String, +} + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +pub struct LightningPayRequest { + pub federationId: String, + pub gatewayId: String, + pub paymentInfo: String, + pub amountMsat: Option, + pub LightningurlComment: Option, +} + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +pub struct ListGatewaysRequest { + pub federationId: String, +} + +pub struct InvoiceOptions { + pub amount_msat: u64, + pub description: String, + pub expiry_time: Option, +} + +impl InvoiceOptions { + pub fn new() -> Self { + InvoiceOptions { + amount_msat: 0, + description: "".to_string(), + expiry_time: None, + } + } + + pub fn msats(mut self, msats: u64) -> Self { + self.amount_msat = msats; + self + } + + pub fn sats(mut self, sats: u64) -> Self { + self.amount_msat = sats * 1000; + self + } + + pub fn description(mut self, description: String) -> Self { + self.description = description; + self + } + + pub fn expiry_time(mut self, expiry_time: u64) -> Self { + self.expiry_time = Some(expiry_time); + self + } +} + +impl Default for InvoiceOptions { + fn default() -> Self { + Self::new() + } +} + +#[derive(Debug)] +pub struct TweakedInvoiceOptions { + pub amount_msat: u64, + pub tweak: u64, + pub description: String, + pub external_pubkey: String, + pub expiry_time: Option, +} + +impl TweakedInvoiceOptions { + pub fn new() -> Self { + TweakedInvoiceOptions { + amount_msat: 0, + tweak: 0, + external_pubkey: "".to_string(), + description: "".to_string(), + expiry_time: None, + } + } + + pub fn msats(mut self, msats: u64) -> Self { + self.amount_msat = msats; + self + } + + pub fn sats(mut self, sats: u64) -> Self { + self.amount_msat = sats * 1000; + self + } + + pub fn tweak(mut self, tweak: u64) -> Self { + self.tweak = tweak; + self + } + + pub fn external_pubkey(mut self, external_pubkey: String) -> Self { + self.external_pubkey = external_pubkey; + self + } + + pub fn description(mut self, description: String) -> Self { + self.description = description; + self + } + + pub fn expiry_time(mut self, expiry_time: u64) -> Self { + self.expiry_time = Some(expiry_time); + self + } +} + +impl Default for TweakedInvoiceOptions { + fn default() -> Self { + Self::new() + } +} + +pub struct PayOptions { + pub payment_info: String, + pub amount_msat: Option, + pub lightningurl_comment: Option, +} + +impl PayOptions { + pub fn new() -> Self { + PayOptions { + amount_msat: None, + payment_info: "".to_string(), + lightningurl_comment: None, + } + } + + pub fn msats(mut self, msats: u64) -> Self { + self.amount_msat = Some(msats); + self + } + + pub fn sats(mut self, sats: u64) -> Self { + self.amount_msat = Some(sats * 1000); + self + } + + pub fn payment_info(mut self, payment_info: String) -> Self { + self.payment_info = payment_info; + self + } + + pub fn comment(mut self, comment: String) -> Self { + self.lightningurl_comment = Some(comment); + self + } +} + +impl Default for PayOptions { + fn default() -> Self { + Self::new() + } +} diff --git a/wrappers/fedimint_clientd_rs/src/client/mint/mod.rs b/wrappers/fedimint_clientd_rs/src/client/mint/mod.rs new file mode 100644 index 0000000..e5a66f2 --- /dev/null +++ b/wrappers/fedimint_clientd_rs/src/client/mint/mod.rs @@ -0,0 +1,99 @@ +pub mod types; + +use crate::FedimintClient; +pub use types::*; + +use super::types::NotesJson; + +impl FedimintClient { + pub async fn decode_notes(&self, notes: String) -> Result { + self.post::( + "/mint/decode-notes", + DecodeNotesRequest { notes }, + ) + .await + } + + pub async fn encode_notes(&self, notes_json: NotesJson) -> Result { + let json_notes = serde_json::to_string(¬es_json); + + match json_notes { + Ok(json) => { + self.post::( + "/mint/encode-notes", + EncodeNotesRequest { notesJsonStr: json }, + ) + .await + } + Err(_) => Err("Failed to stringify JSON Notes".to_string()), + } + } + + pub async fn reissue(&self, notes: String) -> Result { + let federation_id = self.active_federation_id.clone(); + + if federation_id.is_empty() { + return Err("Federation ID Required".to_string()); + } + + self.post::( + "/mint/reissue", + ReissueRequest { + federationId: federation_id, + notes, + }, + ) + .await + } + + pub async fn spend(&self, request: SpendOptions) -> Result { + let federation_id = self.active_federation_id.clone(); + + if federation_id.is_empty() { + return Err("Federation ID Required".to_string()); + } + + self.post::( + "/mint/spend", + SpendRequest { + federationId: federation_id, + allowOverpay: request.allow_overpay, + amountMsat: request.amount_msat, + includeInvite: request.include_invite, + timeout: request.timeout, + }, + ) + .await + } + + pub async fn validate(&self, notes: String) -> Result { + let federation_id = self.active_federation_id.clone(); + + if federation_id.is_empty() { + return Err("Federation ID Required".to_string()); + } + + self.post::("/mint/validate", { + ValidateRequest { + federationId: federation_id, + notes, + } + }) + .await + } + + pub async fn split(&self, notes: String) -> Result { + self.post::("/mint/split", SplitRequest { notes }) + .await + } + + pub async fn combine(&self, notes_vec: Vec) -> Result { + self.post::( + "/mint/combine", + CombineRequest { + notesVec: notes_vec, + }, + ) + .await + } +} diff --git a/wrappers/fedimint_clientd_rs/src/client/mint/types.rs b/wrappers/fedimint_clientd_rs/src/client/mint/types.rs new file mode 100644 index 0000000..878cc3d --- /dev/null +++ b/wrappers/fedimint_clientd_rs/src/client/mint/types.rs @@ -0,0 +1,147 @@ +#![allow(non_snake_case)] + +use serde::{Deserialize, Serialize}; +use std::collections::HashMap; + +use crate::client::types::NotesJson; + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +pub struct DecodeNotesRequest { + pub notes: String, +} + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +pub struct EncodeNotesRequest { + pub notesJsonStr: String, +} + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +pub struct ReissueRequest { + pub federationId: String, + pub notes: String, +} + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +pub struct SpendRequest { + pub federationId: String, + pub amountMsat: u64, + pub allowOverpay: bool, + pub timeout: u64, + pub includeInvite: bool, +} + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +pub struct SpendArgs { + pub amountMsat: u64, + pub allowOverpay: bool, + pub timeout: u64, + pub includeInvite: bool, +} + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +pub struct ValidateRequest { + pub federationId: String, + pub notes: String, +} + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +pub struct SplitRequest { + pub notes: String, +} + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +pub struct CombineRequest { + pub notesVec: Vec, +} + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct DecodeNotesResponse { + pub notes_json: NotesJson, +} + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct EncodeNotesResponse { + pub notes: String, +} + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct ReissueResponse { + pub amount_msat: u64, +} + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct SpendResponse { + pub operation: String, + pub notes: String, +} + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct ValidateResponse { + pub amount_msat: u64, +} + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct SplitResponse { + pub notes: HashMap, +} + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct CombineResponse { + pub notes: String, +} + +pub struct SpendOptions { + pub amount_msat: u64, + pub allow_overpay: bool, + pub timeout: u64, + pub include_invite: bool, +} + +impl SpendOptions { + pub fn new() -> Self { + SpendOptions { + amount_msat: 0, + allow_overpay: false, + timeout: 0, + include_invite: false, + } + } + + pub fn msats(mut self, msats: u64) -> Self { + self.amount_msat = msats; + self + } + + pub fn sats(mut self, sats: u64) -> Self { + self.amount_msat = sats * 1000; + self + } + + pub fn allow_overpay(mut self, allow_overpay: bool) -> Self { + self.allow_overpay = allow_overpay; + self + } + + pub fn include_invite(mut self, include_invite: bool) -> Self { + self.include_invite = include_invite; + self + } + + pub fn timeout(mut self, timeout: u64) -> Self { + self.timeout = timeout; + self + } +} + +impl Default for SpendOptions { + fn default() -> Self { + Self::new() + } +} diff --git a/wrappers/fedimint_clientd_rs/src/client/mod.rs b/wrappers/fedimint_clientd_rs/src/client/mod.rs new file mode 100644 index 0000000..e8c37cd --- /dev/null +++ b/wrappers/fedimint_clientd_rs/src/client/mod.rs @@ -0,0 +1,181 @@ +pub mod admin; +pub mod lightning; +pub mod mint; +pub mod onchain; +pub mod types; + +use serde::{de::DeserializeOwned, Serialize}; +use tracing::info; + +pub struct FedimintClient { + pub base_url: String, + pub password: String, + pub active_federation_id: String, + pub active_gateway_id: String, + pub built: bool, +} + +impl FedimintClient { + /// Creates a new FedimintClient + pub fn new() -> Self { + Self { + base_url: "".to_string(), + password: "".to_string(), + active_federation_id: "".to_string(), + active_gateway_id: "".to_string(), + built: false, + } + } + + /// Sets the Base URL + pub fn base_url(mut self, base_url: String) -> Self { + self.base_url = format!("{}/v2", base_url); + self + } + + /// Sets the Password + pub fn password(mut self, password: String) -> Self { + self.password = password; + self + } + + /// Sets the default active federation ID + pub fn active_federation_id(mut self, active_federation_id: String) -> Self { + self.active_federation_id = active_federation_id; + self + } + + /// Sets the default active lightning gateway ID + pub fn active_gateway_id(mut self, active_gateway_id: String) -> Self { + self.active_gateway_id = active_gateway_id; + self + } + + /// Builds the client. If `base_url`, `password`, and `active_federation_id` are set, returns + /// Ok(FedimintClient). Errors if any are empty + pub fn build(mut self) -> Result { + if self.base_url.is_empty() || self.password.is_empty() { + return Err("base_url and password must be set".to_string()); + } + + self.built = true; + + Ok(self) + } + + /// Switches to use a new Federation ID. If `use_default_gateway` is specified, automatically + /// switches to use the first available lightnig gateway. + pub async fn switch_federation_id( + &mut self, + federation_id: String, + use_default_gateway: bool, + ) -> Result<(), String> { + self.active_federation_id.clone_from(&federation_id); + info!("Changed active federation id to: {}", federation_id); + + if use_default_gateway { + match self.use_default_gateway().await { + Ok(_) => Ok(()), + Err(e) => Err(e), + } + } else { + info!("Clearing active gateway id, must be set manually on lightning calls or setDefaultGatewayId to true"); + self.active_gateway_id = "".to_string(); + Ok(()) + } + } + + /// Uses the first available lightning gateway + pub async fn use_default_gateway(&mut self) -> Result<(), String> { + let gateways = self.list_gateways().await; + + match gateways { + Ok(gws) => { + gws[0] + .info + .gateway_id + .clone_into(&mut self.active_gateway_id); + Ok(()) + } + Err(e) => Err(e), + } + } + + /// Makes a GET request to the specified `endpoint`. + /// Returns a deserialized struct of type `T` + pub(crate) async fn get(&self, endpoint: &str) -> Result + where + T: DeserializeOwned, + { + if !self.built { + return Err( + "Fedimint Client not built. Call `.build()` after initializing.".to_string(), + ); + } + + let client = reqwest::Client::new(); + + let response = client + .get(format!("{}{}", self.base_url, endpoint)) + .header("Authorization", format!("Bearer {}", self.password)) + .header("accept", "application/json") + .send() + .await + .map_err(|e| e.to_string())?; + + if !response.status().is_success() { + let status = response.status(); + let body = response + .text() + .await + .unwrap_or_else(|_| "Failed to read body".to_string()); + + return Err(format!( + "GET request failed. Status: {}, Body: {}", + status, body + )); + } + // Deserialize the response JSON into the desired type. + let json = response.json::().await.map_err(|e| e.to_string())?; + Ok(json) + } + + /// Makes a POST request to the specified `endpoint` with a payload/body of type `Req` + /// Returns a deserialized struct of type `Res` + pub(crate) async fn post(&self, endpoint: &str, payload: Req) -> Result + where + Req: Serialize, + Res: DeserializeOwned, + { + let client = reqwest::Client::new(); + let response = client + .post(format!("{}{}", self.base_url, endpoint)) + .header("Authorization", format!("Bearer {}", self.password)) + .json(&payload) + .send() + .await + .map_err(|e| e.to_string())?; + + if !response.status().is_success() { + let status = response.status(); + let body = response + .text() + .await + .unwrap_or_else(|_| "Failed to read body".to_string()); + + return Err(format!( + "POST request failed. Status: {}, Body: {}", + status, body + )); + } + + let json = response.json::().await.map_err(|e| e.to_string())?; + Ok(json) + } +} + +impl Default for FedimintClient { + fn default() -> Self { + Self::new() + } +} diff --git a/wrappers/fedimint_clientd_rs/src/client/onchain/mod.rs b/wrappers/fedimint_clientd_rs/src/client/onchain/mod.rs new file mode 100644 index 0000000..73aad67 --- /dev/null +++ b/wrappers/fedimint_clientd_rs/src/client/onchain/mod.rs @@ -0,0 +1,46 @@ +pub mod types; + +use crate::FedimintClient; +pub use types::*; + +impl FedimintClient { + pub async fn create_deposit_address( + &self, + timeout: u64, + ) -> Result { + let federation_id = self.active_federation_id.clone(); + + if federation_id.is_empty() { + return Err("Federation ID Required".to_string()); + } + + self.post::( + "/onchain/deposit-address", + CreateDepositAddressRequest { + federationId: federation_id, + timeout, + }, + ) + .await + } + + pub async fn await_deposit( + &self, + operation_id: String, + ) -> Result { + let federation_id = self.active_federation_id.clone(); + + if federation_id.is_empty() { + return Err("Federation ID Required".to_string()); + } + + self.post::( + "/onchain/await-deposit", + AwaitDepositRequest { + federationId: federation_id, + operationId: operation_id, + }, + ) + .await + } +} diff --git a/wrappers/fedimint_clientd_rs/src/client/onchain/types.rs b/wrappers/fedimint_clientd_rs/src/client/onchain/types.rs new file mode 100644 index 0000000..bd7fc11 --- /dev/null +++ b/wrappers/fedimint_clientd_rs/src/client/onchain/types.rs @@ -0,0 +1,84 @@ +#![allow(non_snake_case)] + +use serde::{Deserialize, Serialize}; +use serde_json::Value; + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +pub struct CreateDepositAddressRequest { + pub federationId: String, + pub timeout: u64, +} + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +pub struct AwaitDepositRequest { + pub federationId: String, + pub operationId: String, +} + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct CreateDepositAddressResponse { + pub operationId: String, + pub address: String, +} + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +pub struct AwaitDepositResponseConfirmed { + pub btc_transaction: BTCTransaction, + pub out_idx: String, +} + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +pub struct BTCInput { + pub previous_output: String, + pub script_sig: String, + pub sequence: u64, + pub witness: Vec, +} + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +pub struct BTCOutput { + pub value: u64, + pub script_pubkey: String, +} + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +pub struct BTCTransaction { + pub version: usize, + pub lock_time: usize, + pub input: Vec, + pub output: Vec, +} + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +pub struct AwaitedDepositConfirmed { + pub Confirmed: AwaitDepositResponseConfirmed, +} + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +pub struct AwaitedDepositFailed { + pub Failed: String, +} + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +pub struct BitcoinTransactionData { + /// The bitcoin transaction is saved as soon as we see it so the transaction + /// can be re-transmitted if it's evicted from the mempool. + pub btc_transaction: Value, + /// Index of the deposit output + pub out_idx: u32, +} + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +pub enum DepositState { + WaitingForTransaction, + WaitingForConfirmation(BitcoinTransactionData), + Confirmed(BitcoinTransactionData), + Claimed(BitcoinTransactionData), + Failed(String), +} + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +pub struct AwaitDepositResponse { + pub status: DepositState, +} diff --git a/wrappers/fedimint_clientd_rs/src/client/types/mod.rs b/wrappers/fedimint_clientd_rs/src/client/types/mod.rs new file mode 100644 index 0000000..bf459ea --- /dev/null +++ b/wrappers/fedimint_clientd_rs/src/client/types/mod.rs @@ -0,0 +1,82 @@ +#![allow(non_snake_case)] + +use serde::{Deserialize, Serialize}; +use serde_json::Value; +use std::collections::HashMap; + +#[derive(Deserialize, Serialize, Debug, Clone)] +#[serde(rename_all = "camelCase")] +pub struct FederationInfo { + pub network: String, + pub meta: HashMap, + pub total_amount_msat: u64, + pub total_num_notes: usize, + pub denominations_msat: HashMap, +} + +#[derive(Deserialize, Serialize, Debug, Clone)] +#[serde(rename_all = "camelCase")] +pub struct OperationOutput { + pub id: Value, + pub creation_time: Value, + pub operation_kind: Value, + pub operation_meta: Value, + #[serde(skip_serializing_if = "Option::is_none")] + pub outcome: Option, +} + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "snake_case")] +pub enum LnReceiveState { + Created, + WaitingForPayment { invoice: String, timeout: usize }, + Canceled { reason: String }, + Funded, + AwaitingFunds, + Claimed, +} + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +pub struct Gateway { + pub federation_id: String, + pub info: GatewayInfo, + pub vetted: bool, + pub ttl: GatewayTTL, +} + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +pub struct GatewayInfo { + pub api: String, + pub fees: GatewayFees, + pub gateway_id: String, + pub gateway_redeem_key: String, + pub lightning_alias: String, + pub mint_channel_id: u64, + pub node_pub_key: String, + pub route_hints: Vec, + pub supports_private_payments: bool, +} + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +pub struct GatewayTTL { + pub nanos: u32, + pub secs: u64, +} + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +pub struct GatewayFees { + pub base_msat: u32, + pub proportional_millionths: u32, +} + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +pub struct NotesJson { + pub federation_id_prefix: String, + pub notes: HashMap>, +} + +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +pub struct Note { + pub signature: String, + pub spend_key: String, +} diff --git a/wrappers/fedimint_clientd_rs/src/lib.rs b/wrappers/fedimint_clientd_rs/src/lib.rs new file mode 100644 index 0000000..4f72e22 --- /dev/null +++ b/wrappers/fedimint_clientd_rs/src/lib.rs @@ -0,0 +1,2 @@ +mod client; +pub use client::*;