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

 

History

77 Commits
 
 
 
 
 
 
 
 
 
 

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)

Initializing a mint

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

Minting ecash

let quote = try await mint.getQuote(quoteRequest: Bolt11.RequestMintQuote(unit: "sat",
                                                                          amount: 21))
let proofs = try await mint.issue(for: quote)

Sending ecash

let (token, change) = try await mint.send(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 mint.receive(token: token)

Melting ecash

let meltQuoteRequest = Bolt11.RequestMeltQuote(unit: "sat", request: q2.request, options: nil)
let meltQ = try await mint.getQuote(quoteRequest: meltQuoteRequest)
let result = try await mint.melt(quote: meltQ, 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