cashu_sdk.udl 8.0 KB

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