cashu_sdk.udl 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. namespace cashu_sdk {};
  2. // Cashu
  3. [Error]
  4. interface CashuError {
  5. Generic(string err);
  6. };
  7. interface Bolt11Invoice {
  8. [Throws=CashuError]
  9. constructor(string bolt11);
  10. string as_string();
  11. Amount? amount();
  12. };
  13. interface Amount {
  14. u64 to_sat();
  15. u64 to_msat();
  16. [Name = from_sat]
  17. constructor(u64 sat);
  18. [Name = from_msat]
  19. constructor(u64 msat);
  20. sequence<Amount> split();
  21. };
  22. interface PublicKey {
  23. [Throws=CashuError, Name=from_hex]
  24. constructor(string hex);
  25. [Throws=CashuError]
  26. string to_hex();
  27. };
  28. interface SecretKey {
  29. [Throws=CashuError, Name=from_hex]
  30. constructor(string hex);
  31. [Throws=CashuError]
  32. string to_hex();
  33. };
  34. interface BlindedMessage {
  35. constructor(Amount amount, PublicKey b);
  36. Amount amount();
  37. PublicKey b();
  38. };
  39. interface Proof {
  40. constructor(Amount amount, string secret, PublicKey c, string? id);
  41. Amount amount();
  42. string secret();
  43. PublicKey c();
  44. string? id();
  45. };
  46. interface BlindedSignature {
  47. constructor(string id, Amount amount, PublicKey c);
  48. string id();
  49. Amount amount();
  50. PublicKey c();
  51. };
  52. interface MintProof {
  53. constructor(Amount? amount, string secret, PublicKey? c, string? id);
  54. Amount? amount();
  55. string secret();
  56. PublicKey? c();
  57. string? id();
  58. };
  59. interface MintProofs {
  60. [Throws=CashuError]
  61. constructor(string mint, sequence<Proof> proofs);
  62. string url();
  63. sequence<Proof> proofs();
  64. };
  65. interface Token {
  66. [Throws=CashuError]
  67. constructor(string mint, sequence<Proof> token, string? memo);
  68. sequence<MintProofs> token();
  69. string? memo();
  70. [Throws=CashuError]
  71. string as_string();
  72. [Throws=CashuError, Name=from_string]
  73. constructor(string token);
  74. };
  75. interface BlindedMessages {
  76. [Throws=CashuError, Name=random]
  77. constructor(Amount amount);
  78. [Throws=CashuError, Name=blank]
  79. constructor(Amount fee_reserve);
  80. sequence<BlindedMessage> blinded_messages();
  81. sequence<string> secrets();
  82. sequence<SecretKey> rs();
  83. sequence<Amount> amounts();
  84. };
  85. interface KeyPair {
  86. [Name=from_secret_key]
  87. constructor(SecretKey secret_key);
  88. SecretKey secret_key();
  89. PublicKey public_key();
  90. };
  91. interface Keys {
  92. constructor(record<string, PublicKey> keys);
  93. record<string, PublicKey> keys();
  94. record<string, string> as_hashmap();
  95. PublicKey? amount_key(Amount amount);
  96. };
  97. interface KeySet {
  98. constructor(string id, Keys keys);
  99. string id();
  100. Keys keys();
  101. };
  102. interface KeySetResponse {
  103. constructor(sequence<string> keyset_ids);
  104. sequence<string> keyset_ids();
  105. };
  106. interface RequestMintResponse {
  107. [Throws=CashuError]
  108. constructor(string invoice, string hash);
  109. string invoice();
  110. string hash();
  111. };
  112. interface MintRequest {
  113. constructor(sequence<BlindedMessage> outputs);
  114. sequence<BlindedMessage> outputs();
  115. Amount total_amount();
  116. };
  117. interface PostMintResponse {
  118. constructor(sequence<BlindedSignature> promises);
  119. sequence<BlindedSignature> promises();
  120. };
  121. interface CheckFeesRequest {
  122. [Throws=CashuError]
  123. constructor(string invoice);
  124. string invoice();
  125. };
  126. interface CheckFeesResponse {
  127. constructor(Amount amount);
  128. Amount amount();
  129. };
  130. interface Nut05MeltRequest {
  131. [Throws=CashuError]
  132. constructor(sequence<Proof> proofs, string Invoice);
  133. sequence<Proof> proofs();
  134. string invoice();
  135. };
  136. interface Nut05MeltResponse {
  137. constructor(boolean paid, string? preimage);
  138. boolean paid();
  139. string? preimage();
  140. };
  141. interface SplitRequest {
  142. constructor(sequence<Proof> proofs, sequence<BlindedMessage> outputs);
  143. sequence<Proof> proofs();
  144. sequence<BlindedMessage> outputs();
  145. Amount proofs_amount();
  146. Amount output_amount();
  147. };
  148. interface SplitResponse {
  149. constructor(sequence<BlindedSignature> promises);
  150. sequence<BlindedSignature> promises();
  151. Amount? promises_amount();
  152. };
  153. interface CheckSpendableRequest {
  154. constructor(sequence<MintProof> proofs);
  155. sequence<MintProof> proofs();
  156. };
  157. interface CheckSpendableResponse {
  158. constructor(sequence<boolean> spendable, sequence<boolean> pending);
  159. sequence<boolean> spendable();
  160. sequence<boolean> pending();
  161. };
  162. interface MeltRequest {
  163. [Throws=CashuError]
  164. constructor(sequence<Proof> proofs, string Invoice, sequence<BlindedMessage>? outputs);
  165. sequence<Proof> proofs();
  166. string invoice();
  167. sequence<BlindedMessage>? outputs();
  168. };
  169. interface MeltResponse {
  170. constructor(boolean paid, string? preimage, sequence<BlindedSignature>? change);
  171. boolean paid();
  172. string? preimage();
  173. sequence<BlindedSignature>? change();
  174. };
  175. interface MintVersion {
  176. constructor(string name, string version);
  177. string name();
  178. string version();
  179. };
  180. interface MintInfo {
  181. constructor(string? name, PublicKey? pubkey, MintVersion? version, string? description, string? description_long, sequence<sequence<string>>? contact, sequence<string> nuts, string? motd);
  182. };
  183. enum InvoiceStatus {
  184. "Unpaid",
  185. "Paid",
  186. "Expired",
  187. "InFlight"
  188. };
  189. interface ProofsStatus {
  190. constructor(sequence<MintProof> spendable, sequence<MintProof> spent);
  191. sequence<MintProof> spendable();
  192. sequence<MintProof> spent();
  193. };
  194. // Cashu Sdk
  195. [Error]
  196. interface CashuSdkError {
  197. Generic(string err);
  198. };
  199. interface SendProofs {
  200. constructor(sequence<Proof> change_proofs, sequence<Proof> send_proofs);
  201. sequence<Proof> send_proofs();
  202. sequence<Proof> change_proofs();
  203. };
  204. interface Melted {
  205. constructor(boolean paid, string? preimage, sequence<Proof>? change);
  206. string? preimage();
  207. boolean paid();
  208. sequence<Proof>? change();
  209. };
  210. interface Client {
  211. [Throws=CashuSdkError]
  212. constructor(string mint_url);
  213. [Throws=CashuSdkError]
  214. Keys get_keys();
  215. [Throws=CashuSdkError]
  216. KeySetResponse get_keysets();
  217. [Throws=CashuSdkError]
  218. RequestMintResponse request_mint(Amount amount);
  219. [Throws=CashuSdkError]
  220. PostMintResponse mint(BlindedMessages blinded_messages, string hash);
  221. [Throws=CashuSdkError]
  222. CheckFeesResponse check_fees(Bolt11Invoice invoice);
  223. [Throws=CashuSdkError]
  224. MeltResponse melt(sequence<Proof> proofs, Bolt11Invoice invoice, sequence<BlindedMessage>? outputs);
  225. [Throws=CashuSdkError]
  226. SplitResponse split(SplitRequest split_request);
  227. [Throws=CashuSdkError]
  228. CheckSpendableResponse check_spendable(sequence<MintProof> proofs);
  229. [Throws=CashuSdkError]
  230. MintInfo get_info();
  231. };
  232. interface Wallet {
  233. constructor(Client client, Keys mint_keys);
  234. // [Throws=CashuSdkError]
  235. // ProofsStatus check_proofs_spent(sequence<MintProof> proofs);
  236. [Throws=CashuSdkError]
  237. RequestMintResponse request_mint(Amount amount);
  238. [Throws=CashuSdkError]
  239. Token mint_token(Amount amount, string hash);
  240. [Throws=CashuSdkError]
  241. sequence<Proof> mint(Amount amount, string hash);
  242. [Throws=CashuSdkError]
  243. Amount check_fee(Bolt11Invoice invoice);
  244. [Throws=CashuSdkError]
  245. sequence<Proof> receive(string encoded_token);
  246. [Throws=CashuSdkError]
  247. sequence<Proof> process_split_response(BlindedMessages blinded_messages, sequence<BlindedSignature> promises);
  248. [Throws=CashuSdkError]
  249. SendProofs send(Amount amount, sequence<Proof> proofs);
  250. [Throws=CashuSdkError]
  251. Melted melt(Bolt11Invoice invoice, sequence<Proof> proofs, Amount fee_reserve);
  252. [Throws=CashuSdkError]
  253. string proof_to_token(sequence<Proof> proof, string? memo);
  254. };