cashu_sdk.udl 7.5 KB

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