cashu_sdk.udl 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. namespace cashu_sdk {};
  2. // Cashu
  3. [Error]
  4. interface CashuError {
  5. Generic(string err);
  6. };
  7. // Types
  8. [Enum]
  9. interface CurrencyUnit {
  10. Sat();
  11. Usd();
  12. Custom(string unit);
  13. };
  14. interface Bolt11Invoice {
  15. [Throws=CashuError]
  16. constructor(string bolt11);
  17. string as_string();
  18. Amount? amount();
  19. };
  20. interface Amount {
  21. constructor(u64 amount);
  22. sequence<Amount> split();
  23. };
  24. interface Secret {
  25. constructor();
  26. sequence<u8> as_bytes();
  27. };
  28. interface MintQuote {
  29. constructor(string id, Amount amount, string unit, Bolt11Invoice request, boolean paid, u64 boolean);
  30. };
  31. interface MeltQuote {
  32. constructor(string id, Amount amount, string unit, Bolt11Invoice request, Amount fee_reserve, boolean paid, u64 boolean);
  33. };
  34. // NUT00
  35. interface PublicKey {
  36. [Throws=CashuError, Name=from_hex]
  37. constructor(string hex);
  38. [Throws=CashuError]
  39. string to_hex();
  40. };
  41. interface SecretKey {
  42. [Throws=CashuError]
  43. string to_hex();
  44. };
  45. interface BlindedMessage {
  46. constructor(Id keyset_id, Amount amount, PublicKey b);
  47. Amount amount();
  48. Id keyset_id();
  49. PublicKey b();
  50. };
  51. interface Proof {
  52. constructor(Amount amount, Secret secret, PublicKey c, Id id);
  53. Amount amount();
  54. Secret secret();
  55. PublicKey c();
  56. Id keyset_id();
  57. };
  58. interface BlindedSignature {
  59. constructor(Id keyset_id, Amount amount, PublicKey c);
  60. Id keyset_id();
  61. Amount amount();
  62. PublicKey c();
  63. };
  64. interface MintProof {
  65. constructor(Amount? amount, Secret secret, PublicKey? c, Id? id);
  66. Amount? amount();
  67. Secret secret();
  68. PublicKey? c();
  69. Id? keyset_id();
  70. };
  71. interface MintProofs {
  72. [Throws=CashuError]
  73. constructor(string mint, sequence<Proof> proofs);
  74. string url();
  75. sequence<Proof> proofs();
  76. };
  77. interface Token {
  78. [Throws=CashuError]
  79. constructor(string mint, sequence<Proof> token, string? memo, string? unit);
  80. sequence<MintProofs> token();
  81. string? memo();
  82. string? unit();
  83. string to_string();
  84. [Throws=CashuError, Name=from_string]
  85. constructor(string token);
  86. };
  87. interface PreMintSecrets {
  88. [Throws=CashuError, Name=random]
  89. constructor(Id keyset_id, Amount amount);
  90. [Throws=CashuError, Name=blank]
  91. constructor(Id keyset_id, Amount amount);
  92. sequence<BlindedMessage> blinded_messages();
  93. sequence<Secret> secrets();
  94. sequence<SecretKey> rs();
  95. sequence<Amount> amounts();
  96. };
  97. // NUT-02
  98. interface Id {
  99. [Throws=CashuError]
  100. constructor(string id);
  101. };
  102. interface KeyPair {
  103. [Name=from_secret_key]
  104. constructor(SecretKey secret_key);
  105. SecretKey secret_key();
  106. PublicKey public_key();
  107. };
  108. interface Keys {
  109. constructor(record<string, PublicKey> keys);
  110. record<string, PublicKey> keys();
  111. record<string, string> as_hashmap();
  112. PublicKey? amount_key(Amount amount);
  113. };
  114. interface KeySet {
  115. constructor(Id id, string unit, Keys keys);
  116. Id id();
  117. Keys keys();
  118. };
  119. interface MintKeySet {
  120. [Name=generate]
  121. constructor(string secret, string unit, string derivation_path, u8 max_order);
  122. };
  123. interface KeysResponse {
  124. constructor(sequence<KeySet> keysets);
  125. };
  126. interface KeySetResponse {
  127. constructor(sequence<KeySetInfo> keysets);
  128. sequence<KeySetInfo> keysets();
  129. };
  130. // NUT-03
  131. interface SwapRequest {
  132. constructor(sequence<Proof> proofs, sequence<BlindedMessage> outputs);
  133. sequence<Proof> proofs();
  134. sequence<BlindedMessage> outputs();
  135. Amount proofs_amount();
  136. Amount output_amount();
  137. };
  138. interface SwapResponse {
  139. constructor(sequence<BlindedSignature> promises);
  140. sequence<BlindedSignature> signatures();
  141. };
  142. // NUT-04
  143. interface MintQuoteBolt11Request {
  144. constructor(Amount amount, string unit);
  145. Amount amount();
  146. };
  147. interface MintQuoteBolt11Response {
  148. constructor(string quote, string request, boolean paid, u64 expiry);
  149. string quote();
  150. string request();
  151. boolean paid();
  152. u64 expiry();
  153. };
  154. interface MintBolt11Request {
  155. constructor(string quote, sequence<BlindedMessage> outputs);
  156. string quote();
  157. sequence<BlindedMessage> outputs();
  158. };
  159. interface MintBolt11Response {
  160. constructor(sequence<BlindedSignature> signatures);
  161. sequence<BlindedSignature> signatures();
  162. };
  163. // NUT-05
  164. interface MeltQuoteBolt11Response {
  165. [Throws=CashuError]
  166. constructor(string quote, u64 amount, u64 fee_reserve, boolean paid, u64 expiry);
  167. string quote();
  168. u64 amount();
  169. u64 fee_reserve();
  170. boolean paid();
  171. u64 expiry();
  172. };
  173. interface MeltQuoteBolt11Request {
  174. [Throws=CashuError]
  175. constructor(string request, string unit);
  176. string request();
  177. };
  178. interface MeltBolt11Request {
  179. [Throws=CashuError]
  180. constructor(string quote, sequence<Proof> inputs, sequence<BlindedMessage>? outputs);
  181. sequence<Proof> inputs();
  182. string quote();
  183. };
  184. interface MeltBolt11Response {
  185. constructor(boolean paid, string? payment_preimage, sequence<BlindedSignature>? change);
  186. string? payment_preimage();
  187. boolean paid();
  188. };
  189. // NUT-06
  190. interface MintInfo {
  191. constructor(string? name, PublicKey? pubkey, MintVersion? version, string? description, string? description_long, sequence<sequence<string>>? contact, string nuts, string? motd);
  192. string? name();
  193. PublicKey? pubkey();
  194. MintVersion? version();
  195. string? description();
  196. string? description_long();
  197. sequence<sequence<string>>? contact();
  198. string? motd();
  199. };
  200. // NUT-07
  201. interface CheckSpendableRequest {
  202. constructor(sequence<MintProof> proofs);
  203. sequence<MintProof> proofs();
  204. };
  205. interface CheckSpendableResponse {
  206. constructor(sequence<boolean> spendable, sequence<boolean> pending);
  207. sequence<boolean> spendable();
  208. sequence<boolean> pending();
  209. };
  210. interface MintVersion {
  211. constructor(string name, string version);
  212. string name();
  213. string version();
  214. };
  215. interface KeySetInfo {
  216. constructor(Id id, string unit);
  217. };
  218. enum InvoiceStatus {
  219. "Unpaid",
  220. "Paid",
  221. "Expired",
  222. "InFlight"
  223. };
  224. // Cashu Sdk
  225. interface MintKeySetInfo {
  226. constructor(Id id, boolean active, string unit, u64 valid_from, u64? valid_to, string derivation_path, u8 max_order);
  227. };
  228. [Error]
  229. interface CashuSdkError {
  230. Generic(string err);
  231. };
  232. interface SendProofs {
  233. constructor(sequence<Proof> change_proofs, sequence<Proof> send_proofs);
  234. sequence<Proof> send_proofs();
  235. sequence<Proof> change_proofs();
  236. };
  237. interface Melted {
  238. constructor(boolean paid, string? preimage, sequence<Proof>? change);
  239. string? preimage();
  240. boolean paid();
  241. sequence<Proof>? change();
  242. };
  243. interface Wallet {
  244. constructor(string mint_url, Keys mint_keys, sequence<MintQuote> mint_quotes, sequence<MeltQuote> melt_quotes);
  245. // [Throws=CashuSdkError]
  246. // ProofsStatus check_proofs_spent(sequence<Proof> proofs);
  247. [Throws=CashuSdkError]
  248. Token mint_token(Amount amount, CurrencyUnit? unit, string? memo);
  249. [Throws=CashuSdkError]
  250. MintQuote mint_quote(Amount amount, CurrencyUnit unit);
  251. [Throws=CashuSdkError]
  252. sequence<Proof> mint(string quote);
  253. [Throws=CashuSdkError]
  254. sequence<Proof> receive(string encoded_token);
  255. [Throws=CashuSdkError]
  256. sequence<Proof> process_swap_response(PreMintSecrets blinded_messages, sequence<BlindedSignature> promises);
  257. [Throws=CashuSdkError]
  258. SendProofs send(Amount amount, sequence<Proof> proofs);
  259. [Throws=CashuSdkError]
  260. MeltQuote melt_quote(CurrencyUnit unit, Bolt11Invoice request);
  261. [Throws=CashuSdkError]
  262. Melted melt(string quote_id, sequence<Proof> proofs);
  263. [Throws=CashuSdkError]
  264. string proofs_to_token(sequence<Proof> proof, CurrencyUnit? unit, string? memo);
  265. };
  266. interface Mint {
  267. [Throws=CashuSdkError]
  268. constructor(string secret, sequence<MintKeySetInfo> keysets_info, sequence<Secret> spent_secrets, Amount min_fee_reserve, f32 percent_fee_reserve);
  269. KeysResponse? keyset_pubkeys(Id keyset_id);
  270. KeySetResponse keysets();
  271. KeySet? keyset(Id id);
  272. [Throws=CashuSdkError]
  273. SwapResponse process_swap_request(SwapRequest swap_request);
  274. };