Skip to content

CashuSwift is a native library for building Cashu Ecash wallets on all of Apple's platforms

Notifications You must be signed in to change notification settings

zeugmaster/CashuSwift

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CashuSwift library for Cashu Ecash

This library provides basic functionality and model representation for using the Cashu protocol via its V1 API.

⚠️ This package is not production ready and its APIs will change. Please use it only for experimenting and with a test mint offering FakeWallet ecash.

Implemented NUTs:

Mandatory

# Description
00 Cryptography and Models
01 Mint public keys
02 Keysets and fees
03 Swapping tokens
04 Minting tokens
05 Melting tokens
06 Mint info

Optional

# Description Status
07 Token state check ✔️
08 Overpaid Lightning fees ✔️
09 Signature restore ✔️
10 Spending conditions 🚧
11 Pay-To-Pubkey (P2PK) 🚧
12 DLEQ proofs 🚧
13 Deterministic secrets ✔️
14 Hashed Timelock Contracts (HTLCs) 🚧
15 Partial multi-path payments (MPP) 🚧
16 Animated QR codes N/A
17 WebSocket subscriptions 🚧

Basic Usage

Most methods on Mint have additional parameters for customizing their behaviour (e.g. preferredDistribution, seed for deterministic secret generation). The library defines basic types like Mint, Proof etc., that conform to corresponding protocols. This allows a library user to either reuse these types or define their own in accordance with these protocols.

Initializing a mint

let mintURL = URL(string: "https://testmint.macadamia.cash")!
let mint = try await Mint(with: mintURL)

Minting ecash

let amount = 511
let quote = try await CashuSwift.getQuote(mint: mint,
                                          quoteRequest: CashuSwift.Bolt11.RequestMintQuote(unit: "sat",
                                                                                           amount: amount))
let proofs = try await CashuSwift.issue(for: quote, on: mint) as! [CashuSwift.Proof]

Sending ecash

let (token, change) = try await CashuSwift.send(mint: mint, proofs: proofs, amount: 15)

// The token object can be serialized to a string (currently only V3 format supported)
let tokenString = try token.serialize(.V3)

Receiving ecash

let token = try "cashuAey...".deserializeToken()
// This will swap the ecash contained in the token and return your new proofs
let proofs = try await CashuSwift.receive(mint: mint, token: token)

Melting ecash

let quoteRequest = CashuSwift.Bolt11.RequestMeltQuote(unit: "sat", request: q2.request, options: nil)
let quote = try await CashuSwift.getQuote(mint:mint, quoteRequest: quoteRequest)

let result = try await CashuSwift.melt(mint: mint, quote: quote, proofs: proofs)
// result.paid == true if the Bolt11 lightning payment successful

About

CashuSwift is a native library for building Cashu Ecash wallets on all of Apple's platforms

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages