@buildonspark/issuer-sdk 0.0.22 → 0.0.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (385) hide show
  1. package/dist/chunk-GB7N6I5O.js +48 -0
  2. package/dist/index.cjs +518 -0
  3. package/dist/index.d.cts +110 -0
  4. package/dist/index.d.ts +110 -0
  5. package/dist/index.js +497 -0
  6. package/dist/types.cjs +77 -0
  7. package/dist/types.d.cts +99 -0
  8. package/dist/{issuer-sdk/src/types.d.ts → types.d.ts} +14 -12
  9. package/dist/types.js +12 -0
  10. package/package.json +31 -32
  11. package/src/examples/example.ts +1 -1
  12. package/src/index.ts +1 -0
  13. package/src/interface/wallet-interface.ts +7 -6
  14. package/src/{issuer-sdk.ts → issuer-spark-wallet.ts} +5 -5
  15. package/src/tests/integration/spark.test.ts +3 -12
  16. package/src/types.ts +1 -2
  17. package/src/utils/constants.ts +2 -2
  18. package/dist/issuer-sdk/src/interface/wallet-interface.d.ts +0 -67
  19. package/dist/issuer-sdk/src/interface/wallet-interface.js +0 -2
  20. package/dist/issuer-sdk/src/interface/wallet-interface.js.map +0 -1
  21. package/dist/issuer-sdk/src/issuer-sdk.d.ts +0 -43
  22. package/dist/issuer-sdk/src/issuer-sdk.js +0 -153
  23. package/dist/issuer-sdk/src/issuer-sdk.js.map +0 -1
  24. package/dist/issuer-sdk/src/proto/common.d.ts +0 -58
  25. package/dist/issuer-sdk/src/proto/common.js +0 -350
  26. package/dist/issuer-sdk/src/proto/common.js.map +0 -1
  27. package/dist/issuer-sdk/src/proto/google/protobuf/descriptor.d.ts +0 -1228
  28. package/dist/issuer-sdk/src/proto/google/protobuf/descriptor.js +0 -5070
  29. package/dist/issuer-sdk/src/proto/google/protobuf/descriptor.js.map +0 -1
  30. package/dist/issuer-sdk/src/proto/google/protobuf/duration.d.ts +0 -99
  31. package/dist/issuer-sdk/src/proto/google/protobuf/duration.js +0 -90
  32. package/dist/issuer-sdk/src/proto/google/protobuf/duration.js.map +0 -1
  33. package/dist/issuer-sdk/src/proto/google/protobuf/empty.d.ts +0 -33
  34. package/dist/issuer-sdk/src/proto/google/protobuf/empty.js +0 -46
  35. package/dist/issuer-sdk/src/proto/google/protobuf/empty.js.map +0 -1
  36. package/dist/issuer-sdk/src/proto/google/protobuf/timestamp.d.ts +0 -128
  37. package/dist/issuer-sdk/src/proto/google/protobuf/timestamp.js +0 -90
  38. package/dist/issuer-sdk/src/proto/google/protobuf/timestamp.js.map +0 -1
  39. package/dist/issuer-sdk/src/proto/mock.d.ts +0 -48
  40. package/dist/issuer-sdk/src/proto/mock.js +0 -103
  41. package/dist/issuer-sdk/src/proto/mock.js.map +0 -1
  42. package/dist/issuer-sdk/src/proto/spark.d.ts +0 -1101
  43. package/dist/issuer-sdk/src/proto/spark.js +0 -9565
  44. package/dist/issuer-sdk/src/proto/spark.js.map +0 -1
  45. package/dist/issuer-sdk/src/proto/spark_authn.d.ts +0 -111
  46. package/dist/issuer-sdk/src/proto/spark_authn.js +0 -517
  47. package/dist/issuer-sdk/src/proto/spark_authn.js.map +0 -1
  48. package/dist/issuer-sdk/src/proto/validate/validate.d.ts +0 -1087
  49. package/dist/issuer-sdk/src/proto/validate/validate.js +0 -4437
  50. package/dist/issuer-sdk/src/proto/validate/validate.js.map +0 -1
  51. package/dist/issuer-sdk/src/services/freeze.d.ts +0 -11
  52. package/dist/issuer-sdk/src/services/freeze.js +0 -44
  53. package/dist/issuer-sdk/src/services/freeze.js.map +0 -1
  54. package/dist/issuer-sdk/src/services/token-transactions.d.ts +0 -8
  55. package/dist/issuer-sdk/src/services/token-transactions.js +0 -27
  56. package/dist/issuer-sdk/src/services/token-transactions.js.map +0 -1
  57. package/dist/issuer-sdk/src/tests/integration/spark.test.d.ts +0 -1
  58. package/dist/issuer-sdk/src/tests/integration/spark.test.js +0 -373
  59. package/dist/issuer-sdk/src/tests/integration/spark.test.js.map +0 -1
  60. package/dist/issuer-sdk/src/types.js +0 -33
  61. package/dist/issuer-sdk/src/types.js.map +0 -1
  62. package/dist/issuer-sdk/src/utils/constants.d.ts +0 -16
  63. package/dist/issuer-sdk/src/utils/constants.js +0 -18
  64. package/dist/issuer-sdk/src/utils/constants.js.map +0 -1
  65. package/dist/issuer-sdk/src/utils/enum-mappers.d.ts +0 -6
  66. package/dist/issuer-sdk/src/utils/enum-mappers.js +0 -66
  67. package/dist/issuer-sdk/src/utils/enum-mappers.js.map +0 -1
  68. package/dist/issuer-sdk/src/utils/token-hashing.d.ts +0 -2
  69. package/dist/issuer-sdk/src/utils/token-hashing.js +0 -45
  70. package/dist/issuer-sdk/src/utils/token-hashing.js.map +0 -1
  71. package/dist/issuer-sdk/src/utils/type-mappers.d.ts +0 -4
  72. package/dist/issuer-sdk/src/utils/type-mappers.js +0 -106
  73. package/dist/issuer-sdk/src/utils/type-mappers.js.map +0 -1
  74. package/dist/spark-sdk/src/graphql/client.d.ts +0 -29
  75. package/dist/spark-sdk/src/graphql/client.js +0 -246
  76. package/dist/spark-sdk/src/graphql/client.js.map +0 -1
  77. package/dist/spark-sdk/src/graphql/mutations/CompleteCoopExit.d.ts +0 -1
  78. package/dist/spark-sdk/src/graphql/mutations/CompleteCoopExit.js +0 -19
  79. package/dist/spark-sdk/src/graphql/mutations/CompleteCoopExit.js.map +0 -1
  80. package/dist/spark-sdk/src/graphql/mutations/CompleteLeavesSwap.d.ts +0 -1
  81. package/dist/spark-sdk/src/graphql/mutations/CompleteLeavesSwap.js +0 -17
  82. package/dist/spark-sdk/src/graphql/mutations/CompleteLeavesSwap.js.map +0 -1
  83. package/dist/spark-sdk/src/graphql/mutations/RequestCoopExit.d.ts +0 -1
  84. package/dist/spark-sdk/src/graphql/mutations/RequestCoopExit.js +0 -20
  85. package/dist/spark-sdk/src/graphql/mutations/RequestCoopExit.js.map +0 -1
  86. package/dist/spark-sdk/src/graphql/mutations/RequestLightningReceive.d.ts +0 -1
  87. package/dist/spark-sdk/src/graphql/mutations/RequestLightningReceive.js +0 -26
  88. package/dist/spark-sdk/src/graphql/mutations/RequestLightningReceive.js.map +0 -1
  89. package/dist/spark-sdk/src/graphql/mutations/RequestLightningSend.d.ts +0 -1
  90. package/dist/spark-sdk/src/graphql/mutations/RequestLightningSend.js +0 -18
  91. package/dist/spark-sdk/src/graphql/mutations/RequestLightningSend.js.map +0 -1
  92. package/dist/spark-sdk/src/graphql/mutations/RequestSwapLeaves.d.ts +0 -1
  93. package/dist/spark-sdk/src/graphql/mutations/RequestSwapLeaves.js +0 -24
  94. package/dist/spark-sdk/src/graphql/mutations/RequestSwapLeaves.js.map +0 -1
  95. package/dist/spark-sdk/src/graphql/objects/BitcoinNetwork.d.ts +0 -17
  96. package/dist/spark-sdk/src/graphql/objects/BitcoinNetwork.js +0 -20
  97. package/dist/spark-sdk/src/graphql/objects/BitcoinNetwork.js.map +0 -1
  98. package/dist/spark-sdk/src/graphql/objects/CompleteCoopExitInput.d.ts +0 -7
  99. package/dist/spark-sdk/src/graphql/objects/CompleteCoopExitInput.js +0 -14
  100. package/dist/spark-sdk/src/graphql/objects/CompleteCoopExitInput.js.map +0 -1
  101. package/dist/spark-sdk/src/graphql/objects/CompleteCoopExitOutput.d.ts +0 -7
  102. package/dist/spark-sdk/src/graphql/objects/CompleteCoopExitOutput.js +0 -19
  103. package/dist/spark-sdk/src/graphql/objects/CompleteCoopExitOutput.js.map +0 -1
  104. package/dist/spark-sdk/src/graphql/objects/CompleteLeavesSwapInput.d.ts +0 -8
  105. package/dist/spark-sdk/src/graphql/objects/CompleteLeavesSwapInput.js +0 -16
  106. package/dist/spark-sdk/src/graphql/objects/CompleteLeavesSwapInput.js.map +0 -1
  107. package/dist/spark-sdk/src/graphql/objects/CompleteLeavesSwapOutput.d.ts +0 -7
  108. package/dist/spark-sdk/src/graphql/objects/CompleteLeavesSwapOutput.js +0 -19
  109. package/dist/spark-sdk/src/graphql/objects/CompleteLeavesSwapOutput.js.map +0 -1
  110. package/dist/spark-sdk/src/graphql/objects/CompleteSeedReleaseInput.d.ts +0 -7
  111. package/dist/spark-sdk/src/graphql/objects/CompleteSeedReleaseInput.js +0 -14
  112. package/dist/spark-sdk/src/graphql/objects/CompleteSeedReleaseInput.js.map +0 -1
  113. package/dist/spark-sdk/src/graphql/objects/CompleteSeedReleaseOutput.d.ts +0 -7
  114. package/dist/spark-sdk/src/graphql/objects/CompleteSeedReleaseOutput.js +0 -17
  115. package/dist/spark-sdk/src/graphql/objects/CompleteSeedReleaseOutput.js.map +0 -1
  116. package/dist/spark-sdk/src/graphql/objects/Connection.d.ts +0 -16
  117. package/dist/spark-sdk/src/graphql/objects/Connection.js +0 -56
  118. package/dist/spark-sdk/src/graphql/objects/Connection.js.map +0 -1
  119. package/dist/spark-sdk/src/graphql/objects/CoopExitFeeEstimateInput.d.ts +0 -7
  120. package/dist/spark-sdk/src/graphql/objects/CoopExitFeeEstimateInput.js +0 -14
  121. package/dist/spark-sdk/src/graphql/objects/CoopExitFeeEstimateInput.js.map +0 -1
  122. package/dist/spark-sdk/src/graphql/objects/CoopExitFeeEstimateOutput.d.ts +0 -8
  123. package/dist/spark-sdk/src/graphql/objects/CoopExitFeeEstimateOutput.js +0 -26
  124. package/dist/spark-sdk/src/graphql/objects/CoopExitFeeEstimateOutput.js.map +0 -1
  125. package/dist/spark-sdk/src/graphql/objects/CoopExitRequest.d.ts +0 -35
  126. package/dist/spark-sdk/src/graphql/objects/CoopExitRequest.js +0 -68
  127. package/dist/spark-sdk/src/graphql/objects/CoopExitRequest.js.map +0 -1
  128. package/dist/spark-sdk/src/graphql/objects/CurrencyAmount.d.ts +0 -24
  129. package/dist/spark-sdk/src/graphql/objects/CurrencyAmount.js +0 -30
  130. package/dist/spark-sdk/src/graphql/objects/CurrencyAmount.js.map +0 -1
  131. package/dist/spark-sdk/src/graphql/objects/CurrencyUnit.d.ts +0 -29
  132. package/dist/spark-sdk/src/graphql/objects/CurrencyUnit.js +0 -32
  133. package/dist/spark-sdk/src/graphql/objects/CurrencyUnit.js.map +0 -1
  134. package/dist/spark-sdk/src/graphql/objects/Entity.d.ts +0 -16
  135. package/dist/spark-sdk/src/graphql/objects/Entity.js +0 -169
  136. package/dist/spark-sdk/src/graphql/objects/Entity.js.map +0 -1
  137. package/dist/spark-sdk/src/graphql/objects/GetChallengeInput.d.ts +0 -6
  138. package/dist/spark-sdk/src/graphql/objects/GetChallengeInput.js +0 -12
  139. package/dist/spark-sdk/src/graphql/objects/GetChallengeInput.js.map +0 -1
  140. package/dist/spark-sdk/src/graphql/objects/GetChallengeOutput.d.ts +0 -7
  141. package/dist/spark-sdk/src/graphql/objects/GetChallengeOutput.js +0 -17
  142. package/dist/spark-sdk/src/graphql/objects/GetChallengeOutput.js.map +0 -1
  143. package/dist/spark-sdk/src/graphql/objects/Invoice.d.ts +0 -15
  144. package/dist/spark-sdk/src/graphql/objects/Invoice.js +0 -45
  145. package/dist/spark-sdk/src/graphql/objects/Invoice.js.map +0 -1
  146. package/dist/spark-sdk/src/graphql/objects/Leaf.d.ts +0 -11
  147. package/dist/spark-sdk/src/graphql/objects/Leaf.js +0 -29
  148. package/dist/spark-sdk/src/graphql/objects/Leaf.js.map +0 -1
  149. package/dist/spark-sdk/src/graphql/objects/LeavesSwapFeeEstimateInput.d.ts +0 -6
  150. package/dist/spark-sdk/src/graphql/objects/LeavesSwapFeeEstimateInput.js +0 -12
  151. package/dist/spark-sdk/src/graphql/objects/LeavesSwapFeeEstimateInput.js.map +0 -1
  152. package/dist/spark-sdk/src/graphql/objects/LeavesSwapFeeEstimateOutput.d.ts +0 -8
  153. package/dist/spark-sdk/src/graphql/objects/LeavesSwapFeeEstimateOutput.js +0 -26
  154. package/dist/spark-sdk/src/graphql/objects/LeavesSwapFeeEstimateOutput.js.map +0 -1
  155. package/dist/spark-sdk/src/graphql/objects/LeavesSwapRequest.d.ts +0 -42
  156. package/dist/spark-sdk/src/graphql/objects/LeavesSwapRequest.js +0 -123
  157. package/dist/spark-sdk/src/graphql/objects/LeavesSwapRequest.js.map +0 -1
  158. package/dist/spark-sdk/src/graphql/objects/LightningReceiveFeeEstimateInput.d.ts +0 -8
  159. package/dist/spark-sdk/src/graphql/objects/LightningReceiveFeeEstimateInput.js +0 -15
  160. package/dist/spark-sdk/src/graphql/objects/LightningReceiveFeeEstimateInput.js.map +0 -1
  161. package/dist/spark-sdk/src/graphql/objects/LightningReceiveFeeEstimateOutput.d.ts +0 -8
  162. package/dist/spark-sdk/src/graphql/objects/LightningReceiveFeeEstimateOutput.js +0 -26
  163. package/dist/spark-sdk/src/graphql/objects/LightningReceiveFeeEstimateOutput.js.map +0 -1
  164. package/dist/spark-sdk/src/graphql/objects/LightningReceiveRequest.d.ts +0 -34
  165. package/dist/spark-sdk/src/graphql/objects/LightningReceiveRequest.js +0 -97
  166. package/dist/spark-sdk/src/graphql/objects/LightningReceiveRequest.js.map +0 -1
  167. package/dist/spark-sdk/src/graphql/objects/LightningReceiveRequestStatus.d.ts +0 -18
  168. package/dist/spark-sdk/src/graphql/objects/LightningReceiveRequestStatus.js +0 -21
  169. package/dist/spark-sdk/src/graphql/objects/LightningReceiveRequestStatus.js.map +0 -1
  170. package/dist/spark-sdk/src/graphql/objects/LightningSendFeeEstimateInput.d.ts +0 -6
  171. package/dist/spark-sdk/src/graphql/objects/LightningSendFeeEstimateInput.js +0 -12
  172. package/dist/spark-sdk/src/graphql/objects/LightningSendFeeEstimateInput.js.map +0 -1
  173. package/dist/spark-sdk/src/graphql/objects/LightningSendFeeEstimateOutput.d.ts +0 -8
  174. package/dist/spark-sdk/src/graphql/objects/LightningSendFeeEstimateOutput.js +0 -26
  175. package/dist/spark-sdk/src/graphql/objects/LightningSendFeeEstimateOutput.js.map +0 -1
  176. package/dist/spark-sdk/src/graphql/objects/LightningSendRequest.d.ts +0 -35
  177. package/dist/spark-sdk/src/graphql/objects/LightningSendRequest.js +0 -82
  178. package/dist/spark-sdk/src/graphql/objects/LightningSendRequest.js.map +0 -1
  179. package/dist/spark-sdk/src/graphql/objects/LightningSendRequestStatus.d.ts +0 -15
  180. package/dist/spark-sdk/src/graphql/objects/LightningSendRequestStatus.js +0 -18
  181. package/dist/spark-sdk/src/graphql/objects/LightningSendRequestStatus.js.map +0 -1
  182. package/dist/spark-sdk/src/graphql/objects/NotifyReceiverTransferInput.d.ts +0 -7
  183. package/dist/spark-sdk/src/graphql/objects/NotifyReceiverTransferInput.js +0 -14
  184. package/dist/spark-sdk/src/graphql/objects/NotifyReceiverTransferInput.js.map +0 -1
  185. package/dist/spark-sdk/src/graphql/objects/PageInfo.d.ts +0 -11
  186. package/dist/spark-sdk/src/graphql/objects/PageInfo.js +0 -26
  187. package/dist/spark-sdk/src/graphql/objects/PageInfo.js.map +0 -1
  188. package/dist/spark-sdk/src/graphql/objects/Provider.d.ts +0 -7
  189. package/dist/spark-sdk/src/graphql/objects/Provider.js +0 -14
  190. package/dist/spark-sdk/src/graphql/objects/Provider.js.map +0 -1
  191. package/dist/spark-sdk/src/graphql/objects/RequestCoopExitInput.d.ts +0 -7
  192. package/dist/spark-sdk/src/graphql/objects/RequestCoopExitInput.js +0 -14
  193. package/dist/spark-sdk/src/graphql/objects/RequestCoopExitInput.js.map +0 -1
  194. package/dist/spark-sdk/src/graphql/objects/RequestCoopExitOutput.d.ts +0 -7
  195. package/dist/spark-sdk/src/graphql/objects/RequestCoopExitOutput.js +0 -19
  196. package/dist/spark-sdk/src/graphql/objects/RequestCoopExitOutput.js.map +0 -1
  197. package/dist/spark-sdk/src/graphql/objects/RequestLeavesSwapInput.d.ts +0 -11
  198. package/dist/spark-sdk/src/graphql/objects/RequestLeavesSwapInput.js +0 -22
  199. package/dist/spark-sdk/src/graphql/objects/RequestLeavesSwapInput.js.map +0 -1
  200. package/dist/spark-sdk/src/graphql/objects/RequestLeavesSwapOutput.d.ts +0 -7
  201. package/dist/spark-sdk/src/graphql/objects/RequestLeavesSwapOutput.js +0 -19
  202. package/dist/spark-sdk/src/graphql/objects/RequestLeavesSwapOutput.js.map +0 -1
  203. package/dist/spark-sdk/src/graphql/objects/RequestLightningReceiveInput.d.ts +0 -16
  204. package/dist/spark-sdk/src/graphql/objects/RequestLightningReceiveInput.js +0 -21
  205. package/dist/spark-sdk/src/graphql/objects/RequestLightningReceiveInput.js.map +0 -1
  206. package/dist/spark-sdk/src/graphql/objects/RequestLightningReceiveOutput.d.ts +0 -7
  207. package/dist/spark-sdk/src/graphql/objects/RequestLightningReceiveOutput.js +0 -19
  208. package/dist/spark-sdk/src/graphql/objects/RequestLightningReceiveOutput.js.map +0 -1
  209. package/dist/spark-sdk/src/graphql/objects/RequestLightningSendInput.d.ts +0 -7
  210. package/dist/spark-sdk/src/graphql/objects/RequestLightningSendInput.js +0 -14
  211. package/dist/spark-sdk/src/graphql/objects/RequestLightningSendInput.js.map +0 -1
  212. package/dist/spark-sdk/src/graphql/objects/RequestLightningSendOutput.d.ts +0 -7
  213. package/dist/spark-sdk/src/graphql/objects/RequestLightningSendOutput.js +0 -19
  214. package/dist/spark-sdk/src/graphql/objects/RequestLightningSendOutput.js.map +0 -1
  215. package/dist/spark-sdk/src/graphql/objects/SparkCoopExitRequestStatus.d.ts +0 -14
  216. package/dist/spark-sdk/src/graphql/objects/SparkCoopExitRequestStatus.js +0 -17
  217. package/dist/spark-sdk/src/graphql/objects/SparkCoopExitRequestStatus.js.map +0 -1
  218. package/dist/spark-sdk/src/graphql/objects/SparkLeavesSwapRequestStatus.d.ts +0 -14
  219. package/dist/spark-sdk/src/graphql/objects/SparkLeavesSwapRequestStatus.js +0 -17
  220. package/dist/spark-sdk/src/graphql/objects/SparkLeavesSwapRequestStatus.js.map +0 -1
  221. package/dist/spark-sdk/src/graphql/objects/SparkTransferToLeavesConnection.d.ts +0 -19
  222. package/dist/spark-sdk/src/graphql/objects/SparkTransferToLeavesConnection.js +0 -45
  223. package/dist/spark-sdk/src/graphql/objects/SparkTransferToLeavesConnection.js.map +0 -1
  224. package/dist/spark-sdk/src/graphql/objects/SparkWalletUser.d.ts +0 -21
  225. package/dist/spark-sdk/src/graphql/objects/SparkWalletUser.js +0 -45
  226. package/dist/spark-sdk/src/graphql/objects/SparkWalletUser.js.map +0 -1
  227. package/dist/spark-sdk/src/graphql/objects/StartSeedReleaseInput.d.ts +0 -6
  228. package/dist/spark-sdk/src/graphql/objects/StartSeedReleaseInput.js +0 -12
  229. package/dist/spark-sdk/src/graphql/objects/StartSeedReleaseInput.js.map +0 -1
  230. package/dist/spark-sdk/src/graphql/objects/SwapLeaf.d.ts +0 -9
  231. package/dist/spark-sdk/src/graphql/objects/SwapLeaf.js +0 -23
  232. package/dist/spark-sdk/src/graphql/objects/SwapLeaf.js.map +0 -1
  233. package/dist/spark-sdk/src/graphql/objects/Transfer.d.ts +0 -24
  234. package/dist/spark-sdk/src/graphql/objects/Transfer.js +0 -82
  235. package/dist/spark-sdk/src/graphql/objects/Transfer.js.map +0 -1
  236. package/dist/spark-sdk/src/graphql/objects/UserLeafInput.d.ts +0 -8
  237. package/dist/spark-sdk/src/graphql/objects/UserLeafInput.js +0 -16
  238. package/dist/spark-sdk/src/graphql/objects/UserLeafInput.js.map +0 -1
  239. package/dist/spark-sdk/src/graphql/objects/UserRequest.d.ts +0 -22
  240. package/dist/spark-sdk/src/graphql/objects/UserRequest.js +0 -310
  241. package/dist/spark-sdk/src/graphql/objects/UserRequest.js.map +0 -1
  242. package/dist/spark-sdk/src/graphql/objects/VerifyChallengeInput.d.ts +0 -10
  243. package/dist/spark-sdk/src/graphql/objects/VerifyChallengeInput.js +0 -20
  244. package/dist/spark-sdk/src/graphql/objects/VerifyChallengeInput.js.map +0 -1
  245. package/dist/spark-sdk/src/graphql/objects/VerifyChallengeOutput.d.ts +0 -7
  246. package/dist/spark-sdk/src/graphql/objects/VerifyChallengeOutput.js +0 -17
  247. package/dist/spark-sdk/src/graphql/objects/VerifyChallengeOutput.js.map +0 -1
  248. package/dist/spark-sdk/src/graphql/objects/WalletUserIdentityPublicKeyInput.d.ts +0 -6
  249. package/dist/spark-sdk/src/graphql/objects/WalletUserIdentityPublicKeyInput.js +0 -12
  250. package/dist/spark-sdk/src/graphql/objects/WalletUserIdentityPublicKeyInput.js.map +0 -1
  251. package/dist/spark-sdk/src/graphql/objects/WalletUserIdentityPublicKeyOutput.d.ts +0 -7
  252. package/dist/spark-sdk/src/graphql/objects/WalletUserIdentityPublicKeyOutput.js +0 -17
  253. package/dist/spark-sdk/src/graphql/objects/WalletUserIdentityPublicKeyOutput.js.map +0 -1
  254. package/dist/spark-sdk/src/graphql/objects/index.d.ts +0 -53
  255. package/dist/spark-sdk/src/graphql/objects/index.js +0 -14
  256. package/dist/spark-sdk/src/graphql/objects/index.js.map +0 -1
  257. package/dist/spark-sdk/src/graphql/queries/CoopExitFeeEstimate.d.ts +0 -1
  258. package/dist/spark-sdk/src/graphql/queries/CoopExitFeeEstimate.js +0 -18
  259. package/dist/spark-sdk/src/graphql/queries/CoopExitFeeEstimate.js.map +0 -1
  260. package/dist/spark-sdk/src/graphql/queries/LeavesSwapFeeEstimate.d.ts +0 -1
  261. package/dist/spark-sdk/src/graphql/queries/LeavesSwapFeeEstimate.js +0 -16
  262. package/dist/spark-sdk/src/graphql/queries/LeavesSwapFeeEstimate.js.map +0 -1
  263. package/dist/spark-sdk/src/graphql/queries/LightningReceiveFeeEstimate.d.ts +0 -1
  264. package/dist/spark-sdk/src/graphql/queries/LightningReceiveFeeEstimate.js +0 -18
  265. package/dist/spark-sdk/src/graphql/queries/LightningReceiveFeeEstimate.js.map +0 -1
  266. package/dist/spark-sdk/src/graphql/queries/LightningSendFeeEstimate.d.ts +0 -1
  267. package/dist/spark-sdk/src/graphql/queries/LightningSendFeeEstimate.js +0 -16
  268. package/dist/spark-sdk/src/graphql/queries/LightningSendFeeEstimate.js.map +0 -1
  269. package/dist/spark-sdk/src/graphql/queries/UserRequest.d.ts +0 -1
  270. package/dist/spark-sdk/src/graphql/queries/UserRequest.js +0 -10
  271. package/dist/spark-sdk/src/graphql/queries/UserRequest.js.map +0 -1
  272. package/dist/spark-sdk/src/proto/common.d.ts +0 -58
  273. package/dist/spark-sdk/src/proto/common.js +0 -350
  274. package/dist/spark-sdk/src/proto/common.js.map +0 -1
  275. package/dist/spark-sdk/src/proto/google/protobuf/empty.d.ts +0 -33
  276. package/dist/spark-sdk/src/proto/google/protobuf/empty.js +0 -46
  277. package/dist/spark-sdk/src/proto/google/protobuf/empty.js.map +0 -1
  278. package/dist/spark-sdk/src/proto/google/protobuf/timestamp.d.ts +0 -128
  279. package/dist/spark-sdk/src/proto/google/protobuf/timestamp.js +0 -90
  280. package/dist/spark-sdk/src/proto/google/protobuf/timestamp.js.map +0 -1
  281. package/dist/spark-sdk/src/proto/mock.d.ts +0 -48
  282. package/dist/spark-sdk/src/proto/mock.js +0 -103
  283. package/dist/spark-sdk/src/proto/mock.js.map +0 -1
  284. package/dist/spark-sdk/src/proto/spark.d.ts +0 -1209
  285. package/dist/spark-sdk/src/proto/spark.js +0 -10516
  286. package/dist/spark-sdk/src/proto/spark.js.map +0 -1
  287. package/dist/spark-sdk/src/proto/spark_authn.d.ts +0 -111
  288. package/dist/spark-sdk/src/proto/spark_authn.js +0 -517
  289. package/dist/spark-sdk/src/proto/spark_authn.js.map +0 -1
  290. package/dist/spark-sdk/src/services/config.d.ts +0 -17
  291. package/dist/spark-sdk/src/services/config.js +0 -54
  292. package/dist/spark-sdk/src/services/config.js.map +0 -1
  293. package/dist/spark-sdk/src/services/connection.d.ts +0 -22
  294. package/dist/spark-sdk/src/services/connection.js +0 -180
  295. package/dist/spark-sdk/src/services/connection.js.map +0 -1
  296. package/dist/spark-sdk/src/services/coop-exit.d.ts +0 -20
  297. package/dist/spark-sdk/src/services/coop-exit.js +0 -101
  298. package/dist/spark-sdk/src/services/coop-exit.js.map +0 -1
  299. package/dist/spark-sdk/src/services/deposit.d.ts +0 -21
  300. package/dist/spark-sdk/src/services/deposit.js +0 -214
  301. package/dist/spark-sdk/src/services/deposit.js.map +0 -1
  302. package/dist/spark-sdk/src/services/lightning.d.ts +0 -32
  303. package/dist/spark-sdk/src/services/lightning.js +0 -210
  304. package/dist/spark-sdk/src/services/lightning.js.map +0 -1
  305. package/dist/spark-sdk/src/services/lrc20.d.ts +0 -5
  306. package/dist/spark-sdk/src/services/lrc20.js +0 -27
  307. package/dist/spark-sdk/src/services/lrc20.js.map +0 -1
  308. package/dist/spark-sdk/src/services/token-transactions.d.ts +0 -16
  309. package/dist/spark-sdk/src/services/token-transactions.js +0 -299
  310. package/dist/spark-sdk/src/services/token-transactions.js.map +0 -1
  311. package/dist/spark-sdk/src/services/transfer.d.ts +0 -66
  312. package/dist/spark-sdk/src/services/transfer.js +0 -791
  313. package/dist/spark-sdk/src/services/transfer.js.map +0 -1
  314. package/dist/spark-sdk/src/services/tree-creation.d.ts +0 -29
  315. package/dist/spark-sdk/src/services/tree-creation.js +0 -399
  316. package/dist/spark-sdk/src/services/tree-creation.js.map +0 -1
  317. package/dist/spark-sdk/src/services/wallet-config.d.ts +0 -23
  318. package/dist/spark-sdk/src/services/wallet-config.js +0 -107
  319. package/dist/spark-sdk/src/services/wallet-config.js.map +0 -1
  320. package/dist/spark-sdk/src/signer/signer.d.ts +0 -106
  321. package/dist/spark-sdk/src/signer/signer.js +0 -275
  322. package/dist/spark-sdk/src/signer/signer.js.map +0 -1
  323. package/dist/spark-sdk/src/spark-sdk.d.ts +0 -414
  324. package/dist/spark-sdk/src/spark-sdk.js +0 -1285
  325. package/dist/spark-sdk/src/spark-sdk.js.map +0 -1
  326. package/dist/spark-sdk/src/tests/utils/test-faucet.d.ts +0 -24
  327. package/dist/spark-sdk/src/tests/utils/test-faucet.js +0 -182
  328. package/dist/spark-sdk/src/tests/utils/test-faucet.js.map +0 -1
  329. package/dist/spark-sdk/src/types/grpc.d.ts +0 -6
  330. package/dist/spark-sdk/src/types/grpc.js +0 -2
  331. package/dist/spark-sdk/src/types/grpc.js.map +0 -1
  332. package/dist/spark-sdk/src/types/index.d.ts +0 -3
  333. package/dist/spark-sdk/src/types/index.js +0 -4
  334. package/dist/spark-sdk/src/types/index.js.map +0 -1
  335. package/dist/spark-sdk/src/utils/adaptor-signature.d.ts +0 -7
  336. package/dist/spark-sdk/src/utils/adaptor-signature.js +0 -114
  337. package/dist/spark-sdk/src/utils/adaptor-signature.js.map +0 -1
  338. package/dist/spark-sdk/src/utils/bitcoin.d.ts +0 -12
  339. package/dist/spark-sdk/src/utils/bitcoin.js +0 -87
  340. package/dist/spark-sdk/src/utils/bitcoin.js.map +0 -1
  341. package/dist/spark-sdk/src/utils/crypto.d.ts +0 -1
  342. package/dist/spark-sdk/src/utils/crypto.js +0 -14
  343. package/dist/spark-sdk/src/utils/crypto.js.map +0 -1
  344. package/dist/spark-sdk/src/utils/index.d.ts +0 -12
  345. package/dist/spark-sdk/src/utils/index.js +0 -13
  346. package/dist/spark-sdk/src/utils/index.js.map +0 -1
  347. package/dist/spark-sdk/src/utils/keys.d.ts +0 -9
  348. package/dist/spark-sdk/src/utils/keys.js +0 -73
  349. package/dist/spark-sdk/src/utils/keys.js.map +0 -1
  350. package/dist/spark-sdk/src/utils/mempool.d.ts +0 -1
  351. package/dist/spark-sdk/src/utils/mempool.js +0 -29
  352. package/dist/spark-sdk/src/utils/mempool.js.map +0 -1
  353. package/dist/spark-sdk/src/utils/network.d.ts +0 -36
  354. package/dist/spark-sdk/src/utils/network.js +0 -65
  355. package/dist/spark-sdk/src/utils/network.js.map +0 -1
  356. package/dist/spark-sdk/src/utils/proof.d.ts +0 -1
  357. package/dist/spark-sdk/src/utils/proof.js +0 -12
  358. package/dist/spark-sdk/src/utils/proof.js.map +0 -1
  359. package/dist/spark-sdk/src/utils/response-validation.d.ts +0 -1
  360. package/dist/spark-sdk/src/utils/response-validation.js +0 -16
  361. package/dist/spark-sdk/src/utils/response-validation.js.map +0 -1
  362. package/dist/spark-sdk/src/utils/secret-sharing.d.ts +0 -26
  363. package/dist/spark-sdk/src/utils/secret-sharing.js +0 -174
  364. package/dist/spark-sdk/src/utils/secret-sharing.js.map +0 -1
  365. package/dist/spark-sdk/src/utils/signing.d.ts +0 -12
  366. package/dist/spark-sdk/src/utils/signing.js +0 -67
  367. package/dist/spark-sdk/src/utils/signing.js.map +0 -1
  368. package/dist/spark-sdk/src/utils/token-hashing.d.ts +0 -3
  369. package/dist/spark-sdk/src/utils/token-hashing.js +0 -116
  370. package/dist/spark-sdk/src/utils/token-hashing.js.map +0 -1
  371. package/dist/spark-sdk/src/utils/token-keyshares.d.ts +0 -5
  372. package/dist/spark-sdk/src/utils/token-keyshares.js +0 -17
  373. package/dist/spark-sdk/src/utils/token-keyshares.js.map +0 -1
  374. package/dist/spark-sdk/src/utils/token-transactions.d.ts +0 -5
  375. package/dist/spark-sdk/src/utils/token-transactions.js +0 -40
  376. package/dist/spark-sdk/src/utils/token-transactions.js.map +0 -1
  377. package/dist/spark-sdk/src/utils/transaction.d.ts +0 -9
  378. package/dist/spark-sdk/src/utils/transaction.js +0 -35
  379. package/dist/spark-sdk/src/utils/transaction.js.map +0 -1
  380. package/dist/spark-sdk/src/utils/wasm-wrapper.d.ts +0 -2
  381. package/dist/spark-sdk/src/utils/wasm-wrapper.js +0 -46
  382. package/dist/spark-sdk/src/utils/wasm-wrapper.js.map +0 -1
  383. package/dist/spark-sdk/src/utils/wasm.d.ts +0 -54
  384. package/dist/spark-sdk/src/utils/wasm.js +0 -26
  385. package/dist/spark-sdk/src/utils/wasm.js.map +0 -1
@@ -1,791 +0,0 @@
1
- import { bytesToHex, equalBytes, hexToBytes, numberToBytesBE, } from "@noble/curves/abstract/utils";
2
- import { secp256k1 } from "@noble/curves/secp256k1";
3
- import { Transaction } from "@scure/btc-signer";
4
- import { sha256 } from "@scure/btc-signer/utils";
5
- import * as ecies from "eciesjs";
6
- import { SignatureIntent } from "../proto/common.js";
7
- import { TransferStatus, } from "../proto/spark.js";
8
- import { getSigHashFromTx, getTxFromRawTxBytes, getTxId, } from "../utils/bitcoin.js";
9
- import { getCrypto } from "../utils/crypto.js";
10
- import { createRefundTx, getEphemeralAnchorOutput, getNextTransactionSequence, } from "../utils/transaction.js";
11
- const INITIAL_TIME_LOCK = 2000;
12
- function initialSequence() {
13
- return (1 << 30) | INITIAL_TIME_LOCK;
14
- }
15
- const crypto = getCrypto();
16
- export class BaseTransferService {
17
- config;
18
- connectionManager;
19
- constructor(config, connectionManager) {
20
- this.config = config;
21
- this.connectionManager = connectionManager;
22
- }
23
- async sendTransferTweakKey(transfer, leaves, refundSignatureMap) {
24
- const keyTweakInputMap = await this.prepareSendTransferKeyTweaks(transfer, leaves, refundSignatureMap);
25
- let updatedTransfer;
26
- const errors = [];
27
- const promises = Object.entries(this.config.getSigningOperators()).map(async ([identifier, operator]) => {
28
- const sparkClient = await this.connectionManager.createSparkClient(operator.address);
29
- const leavesToSend = keyTweakInputMap.get(identifier);
30
- if (!leavesToSend) {
31
- errors.push(new Error(`No leaves to send for operator ${identifier}`));
32
- return;
33
- }
34
- let transferResp;
35
- try {
36
- transferResp = await sparkClient.complete_send_transfer({
37
- transferId: transfer.id,
38
- ownerIdentityPublicKey: await this.config.signer.getIdentityPublicKey(),
39
- leavesToSend,
40
- });
41
- }
42
- catch (error) {
43
- errors.push(new Error(`Error completing send transfer: ${error}`));
44
- return;
45
- }
46
- if (!updatedTransfer) {
47
- updatedTransfer = transferResp.transfer;
48
- }
49
- else {
50
- if (!transferResp.transfer) {
51
- errors.push(new Error(`No transfer response from operator ${identifier}`));
52
- return;
53
- }
54
- if (!this.compareTransfers(updatedTransfer, transferResp.transfer)) {
55
- errors.push(new Error(`Inconsistent transfer response from operators`));
56
- }
57
- }
58
- });
59
- await Promise.all(promises);
60
- if (errors.length > 0) {
61
- throw new Error(`Error completing send transfer: ${errors[0]}`);
62
- }
63
- if (!updatedTransfer) {
64
- throw new Error("No updated transfer found");
65
- }
66
- return updatedTransfer;
67
- }
68
- async signRefunds(leafDataMap, operatorSigningResults, adaptorPubKey) {
69
- const nodeSignatures = [];
70
- for (const operatorSigningResult of operatorSigningResults) {
71
- const leafData = leafDataMap.get(operatorSigningResult.leafId);
72
- if (!leafData ||
73
- !leafData.tx ||
74
- leafData.vout === undefined ||
75
- !leafData.refundTx) {
76
- throw new Error(`Leaf data not found for leaf ${operatorSigningResult.leafId}`);
77
- }
78
- const txOutput = leafData.tx?.getOutput(0);
79
- if (!txOutput) {
80
- throw new Error(`Output not found for leaf ${operatorSigningResult.leafId}`);
81
- }
82
- const refundTxSighash = getSigHashFromTx(leafData.refundTx, 0, txOutput);
83
- const userSignature = await this.config.signer.signFrost({
84
- message: refundTxSighash,
85
- publicKey: leafData.signingPubKey,
86
- privateAsPubKey: leafData.signingPubKey,
87
- selfCommitment: leafData.signingNonceCommitment,
88
- statechainCommitments: operatorSigningResult.refundTxSigningResult?.signingNonceCommitments,
89
- adaptorPubKey: adaptorPubKey,
90
- verifyingKey: operatorSigningResult.verifyingKey,
91
- });
92
- const refundAggregate = await this.config.signer.aggregateFrost({
93
- message: refundTxSighash,
94
- statechainSignatures: operatorSigningResult.refundTxSigningResult?.signatureShares,
95
- statechainPublicKeys: operatorSigningResult.refundTxSigningResult?.publicKeys,
96
- verifyingKey: operatorSigningResult.verifyingKey,
97
- statechainCommitments: operatorSigningResult.refundTxSigningResult?.signingNonceCommitments,
98
- selfCommitment: leafData.signingNonceCommitment,
99
- publicKey: leafData.signingPubKey,
100
- selfSignature: userSignature,
101
- adaptorPubKey: adaptorPubKey,
102
- });
103
- nodeSignatures.push({
104
- nodeId: operatorSigningResult.leafId,
105
- refundTxSignature: refundAggregate,
106
- nodeTxSignature: new Uint8Array(),
107
- });
108
- }
109
- return nodeSignatures;
110
- }
111
- async prepareSendTransferKeyTweaks(transfer, leaves, refundSignatureMap) {
112
- const receiverEciesPubKey = ecies.PublicKey.fromHex(bytesToHex(transfer.receiverIdentityPublicKey));
113
- const leavesTweaksMap = new Map();
114
- for (const leaf of leaves) {
115
- const refundSignature = refundSignatureMap.get(leaf.leaf.id);
116
- const leafTweaksMap = await this.prepareSingleSendTransferKeyTweak(transfer.id, leaf, receiverEciesPubKey, refundSignature);
117
- for (const [identifier, leafTweak] of leafTweaksMap) {
118
- leavesTweaksMap.set(identifier, [
119
- ...(leavesTweaksMap.get(identifier) || []),
120
- leafTweak,
121
- ]);
122
- }
123
- }
124
- return leavesTweaksMap;
125
- }
126
- async prepareSingleSendTransferKeyTweak(transferID, leaf, receiverEciesPubKey, refundSignature) {
127
- const signingOperators = this.config.getSigningOperators();
128
- const pubKeyTweak = await this.config.signer.subtractPrivateKeysGivenPublicKeys(leaf.signingPubKey, leaf.newSigningPubKey);
129
- const shares = await this.config.signer.splitSecretWithProofs({
130
- secret: pubKeyTweak,
131
- curveOrder: secp256k1.CURVE.n,
132
- threshold: this.config.getThreshold(),
133
- numShares: Object.keys(signingOperators).length,
134
- isSecretPubkey: true,
135
- });
136
- const pubkeySharesTweak = new Map();
137
- for (const [identifier, operator] of Object.entries(signingOperators)) {
138
- const share = this.findShare(shares, operator.id);
139
- if (!share) {
140
- throw new Error(`Share not found for operator ${operator.id}`);
141
- }
142
- const pubkeyTweak = secp256k1.getPublicKey(numberToBytesBE(share.share, 32), true);
143
- pubkeySharesTweak.set(identifier, pubkeyTweak);
144
- }
145
- const secretCipher = await this.config.signer.encryptLeafPrivateKeyEcies(receiverEciesPubKey.toBytes(), leaf.newSigningPubKey);
146
- const encoder = new TextEncoder();
147
- const payload = new Uint8Array([
148
- ...encoder.encode(leaf.leaf.id),
149
- ...encoder.encode(transferID),
150
- ...secretCipher,
151
- ]);
152
- const payloadHash = sha256(payload);
153
- const signature = await this.config.signer.signMessageWithIdentityKey(payloadHash, true);
154
- const leafTweaksMap = new Map();
155
- for (const [identifier, operator] of Object.entries(signingOperators)) {
156
- const share = this.findShare(shares, operator.id);
157
- if (!share) {
158
- throw new Error(`Share not found for operator ${operator.id}`);
159
- }
160
- leafTweaksMap.set(identifier, {
161
- leafId: leaf.leaf.id,
162
- secretShareTweak: {
163
- secretShare: numberToBytesBE(share.share, 32),
164
- proofs: share.proofs,
165
- },
166
- pubkeySharesTweak: Object.fromEntries(pubkeySharesTweak),
167
- secretCipher,
168
- signature,
169
- refundSignature: refundSignature ?? new Uint8Array(),
170
- });
171
- }
172
- return leafTweaksMap;
173
- }
174
- findShare(shares, operatorID) {
175
- const targetShareIndex = BigInt(operatorID + 1);
176
- for (const s of shares) {
177
- if (s.index === targetShareIndex) {
178
- return s;
179
- }
180
- }
181
- return undefined;
182
- }
183
- compareTransfers(transfer1, transfer2) {
184
- return (transfer1.id === transfer2.id &&
185
- equalBytes(transfer1.senderIdentityPublicKey, transfer2.senderIdentityPublicKey) &&
186
- transfer1.status === transfer2.status &&
187
- transfer1.totalValue === transfer2.totalValue &&
188
- transfer1.expiryTime?.getTime() === transfer2.expiryTime?.getTime() &&
189
- transfer1.leaves.length === transfer2.leaves.length);
190
- }
191
- }
192
- export class TransferService extends BaseTransferService {
193
- constructor(config, connectionManager) {
194
- super(config, connectionManager);
195
- }
196
- async sendTransfer(leaves, receiverIdentityPubkey) {
197
- const { transfer, signatureMap } = await this.sendTransferSignRefund(leaves, receiverIdentityPubkey);
198
- const transferWithTweakedKeys = await this.sendTransferTweakKey(transfer, leaves, signatureMap);
199
- return transferWithTweakedKeys;
200
- }
201
- async claimTransfer(transfer, leaves) {
202
- if (transfer.status === TransferStatus.TRANSFER_STATUS_SENDER_KEY_TWEAKED) {
203
- await this.claimTransferTweakKeys(transfer, leaves);
204
- }
205
- const signatures = await this.claimTransferSignRefunds(transfer, leaves);
206
- return await this.finalizeTransfer(signatures);
207
- }
208
- async queryPendingTransfers() {
209
- const sparkClient = await this.connectionManager.createSparkClient(this.config.getCoordinatorAddress());
210
- let pendingTransfersResp;
211
- try {
212
- pendingTransfersResp = await sparkClient.query_pending_transfers({
213
- participant: {
214
- $case: "receiverIdentityPublicKey",
215
- receiverIdentityPublicKey: await this.config.signer.getIdentityPublicKey(),
216
- },
217
- network: this.config.getNetworkProto(),
218
- });
219
- }
220
- catch (error) {
221
- throw new Error(`Error querying pending transfers: ${error}`);
222
- }
223
- return pendingTransfersResp;
224
- }
225
- async queryAllTransfers(limit, offset) {
226
- const sparkClient = await this.connectionManager.createSparkClient(this.config.getCoordinatorAddress());
227
- let allTransfersResp;
228
- try {
229
- allTransfersResp = await sparkClient.query_all_transfers({
230
- identityPublicKey: await this.config.signer.getIdentityPublicKey(),
231
- limit,
232
- offset,
233
- });
234
- }
235
- catch (error) {
236
- throw new Error(`Error querying all transfers: ${error}`);
237
- }
238
- return allTransfersResp;
239
- }
240
- async verifyPendingTransfer(transfer) {
241
- const leafPubKeyMap = new Map();
242
- for (const leaf of transfer.leaves) {
243
- if (!leaf.leaf) {
244
- throw new Error("Leaf is undefined");
245
- }
246
- const encoder = new TextEncoder();
247
- const leafIdBytes = encoder.encode(leaf.leaf.id);
248
- const transferIdBytes = encoder.encode(transfer.id);
249
- const payload = new Uint8Array([
250
- ...leafIdBytes,
251
- ...transferIdBytes,
252
- ...leaf.secretCipher,
253
- ]);
254
- const payloadHash = sha256(payload);
255
- if (!secp256k1.verify(leaf.signature, payloadHash, transfer.senderIdentityPublicKey)) {
256
- throw new Error("Signature verification failed");
257
- }
258
- const leafSecret = await this.config.signer.decryptEcies(leaf.secretCipher);
259
- leafPubKeyMap.set(leaf.leaf.id, leafSecret);
260
- }
261
- return leafPubKeyMap;
262
- }
263
- async sendSwapSignRefund(leaves, receiverIdentityPubkey, expiryTime, adaptorPubKey) {
264
- const transferId = crypto.randomUUID();
265
- const leafDataMap = new Map();
266
- for (const leaf of leaves) {
267
- const signingNonceCommitment = await this.config.signer.getRandomSigningCommitment();
268
- const tx = getTxFromRawTxBytes(leaf.leaf.nodeTx);
269
- const refundTx = getTxFromRawTxBytes(leaf.leaf.refundTx);
270
- leafDataMap.set(leaf.leaf.id, {
271
- signingPubKey: leaf.signingPubKey,
272
- receivingPubkey: receiverIdentityPubkey,
273
- signingNonceCommitment,
274
- tx,
275
- refundTx,
276
- vout: leaf.leaf.vout,
277
- });
278
- }
279
- const signingJobs = this.prepareRefundSoSigningJobs(leaves, leafDataMap);
280
- const sparkClient = await this.connectionManager.createSparkClient(this.config.getCoordinatorAddress());
281
- let response;
282
- try {
283
- response = await sparkClient.leaf_swap({
284
- transfer: {
285
- transferId,
286
- leavesToSend: signingJobs,
287
- ownerIdentityPublicKey: await this.config.signer.getIdentityPublicKey(),
288
- receiverIdentityPublicKey: receiverIdentityPubkey,
289
- expiryTime: expiryTime,
290
- },
291
- swapId: crypto.randomUUID(),
292
- adaptorPublicKey: adaptorPubKey || new Uint8Array(),
293
- });
294
- }
295
- catch (error) {
296
- throw new Error(`Error initiating leaf swap: ${error}`);
297
- }
298
- if (!response.transfer) {
299
- throw new Error("No transfer response from coordinator");
300
- }
301
- const signatures = await this.signRefunds(leafDataMap, response.signingResults, adaptorPubKey);
302
- const signatureMap = new Map();
303
- for (const signature of signatures) {
304
- signatureMap.set(signature.nodeId, signature.refundTxSignature);
305
- }
306
- return {
307
- transfer: response.transfer,
308
- signatureMap,
309
- leafDataMap,
310
- signingResults: response.signingResults,
311
- };
312
- }
313
- async sendTransferSignRefund(leaves, receiverIdentityPubkey, expiryTime) {
314
- const transferID = crypto.randomUUID();
315
- const leafDataMap = new Map();
316
- for (const leaf of leaves) {
317
- const signingNonceCommitment = await this.config.signer.getRandomSigningCommitment();
318
- const tx = getTxFromRawTxBytes(leaf.leaf.nodeTx);
319
- const refundTx = getTxFromRawTxBytes(leaf.leaf.refundTx);
320
- leafDataMap.set(leaf.leaf.id, {
321
- signingPubKey: leaf.signingPubKey,
322
- receivingPubkey: receiverIdentityPubkey,
323
- signingNonceCommitment,
324
- tx,
325
- refundTx,
326
- vout: leaf.leaf.vout,
327
- });
328
- }
329
- const signingJobs = this.prepareRefundSoSigningJobs(leaves, leafDataMap);
330
- const sparkClient = await this.connectionManager.createSparkClient(this.config.getCoordinatorAddress());
331
- let response;
332
- try {
333
- response = await sparkClient.start_send_transfer({
334
- transferId: transferID,
335
- leavesToSend: signingJobs,
336
- ownerIdentityPublicKey: await this.config.signer.getIdentityPublicKey(),
337
- receiverIdentityPublicKey: receiverIdentityPubkey,
338
- expiryTime: expiryTime,
339
- });
340
- }
341
- catch (error) {
342
- throw new Error(`Error starting send transfer: ${error}`);
343
- }
344
- const signatures = await this.signRefunds(leafDataMap, response.signingResults);
345
- const signatureMap = new Map();
346
- for (const signature of signatures) {
347
- signatureMap.set(signature.nodeId, signature.refundTxSignature);
348
- }
349
- if (!response.transfer) {
350
- throw new Error("No transfer response from coordinator");
351
- }
352
- return {
353
- transfer: response.transfer,
354
- signatureMap,
355
- leafDataMap,
356
- };
357
- }
358
- prepareRefundSoSigningJobs(leaves, leafDataMap) {
359
- const signingJobs = [];
360
- for (const leaf of leaves) {
361
- const refundSigningData = leafDataMap.get(leaf.leaf.id);
362
- if (!refundSigningData) {
363
- throw new Error(`Leaf data not found for leaf ${leaf.leaf.id}`);
364
- }
365
- const nodeTx = getTxFromRawTxBytes(leaf.leaf.nodeTx);
366
- const nodeOutPoint = {
367
- txid: hexToBytes(getTxId(nodeTx)),
368
- index: 0,
369
- };
370
- const currRefundTx = getTxFromRawTxBytes(leaf.leaf.refundTx);
371
- const { nextSequence } = getNextTransactionSequence(currRefundTx.getInput(0).sequence);
372
- const amountSats = currRefundTx.getOutput(0).amount;
373
- if (amountSats === undefined) {
374
- throw new Error("Amount not found in signRefunds");
375
- }
376
- const refundTx = createRefundTx(nextSequence, nodeOutPoint, amountSats, refundSigningData.receivingPubkey, this.config.getNetwork());
377
- refundSigningData.refundTx = refundTx;
378
- const refundNonceCommitmentProto = refundSigningData.signingNonceCommitment;
379
- signingJobs.push({
380
- leafId: leaf.leaf.id,
381
- refundTxSigningJob: {
382
- signingPublicKey: refundSigningData.signingPubKey,
383
- rawTx: refundTx.toBytes(),
384
- signingNonceCommitment: refundNonceCommitmentProto,
385
- },
386
- });
387
- }
388
- return signingJobs;
389
- }
390
- async claimTransferTweakKeys(transfer, leaves) {
391
- const leavesTweaksMap = await this.prepareClaimLeavesKeyTweaks(leaves);
392
- const errors = [];
393
- const promises = Object.entries(this.config.getSigningOperators()).map(async ([identifier, operator]) => {
394
- const sparkClient = await this.connectionManager.createSparkClient(operator.address);
395
- const leavesToReceive = leavesTweaksMap.get(identifier);
396
- if (!leavesToReceive) {
397
- errors.push(new Error(`No leaves to receive for operator ${identifier}`));
398
- return;
399
- }
400
- try {
401
- await sparkClient.claim_transfer_tweak_keys({
402
- transferId: transfer.id,
403
- ownerIdentityPublicKey: await this.config.signer.getIdentityPublicKey(),
404
- leavesToReceive,
405
- });
406
- }
407
- catch (error) {
408
- errors.push(new Error(`Error claiming transfer tweak keys: ${error}`));
409
- return;
410
- }
411
- });
412
- await Promise.all(promises);
413
- if (errors.length > 0) {
414
- throw new Error(`Error claiming transfer tweak keys: ${errors[0]}`);
415
- }
416
- }
417
- async prepareClaimLeavesKeyTweaks(leaves) {
418
- const leafDataMap = new Map();
419
- for (const leaf of leaves) {
420
- const leafData = await this.prepareClaimLeafKeyTweaks(leaf);
421
- for (const [identifier, leafTweak] of leafData) {
422
- leafDataMap.set(identifier, [
423
- ...(leafDataMap.get(identifier) || []),
424
- leafTweak,
425
- ]);
426
- }
427
- }
428
- return leafDataMap;
429
- }
430
- async prepareClaimLeafKeyTweaks(leaf) {
431
- const signingOperators = this.config.getSigningOperators();
432
- const pubKeyTweak = await this.config.signer.subtractPrivateKeysGivenPublicKeys(leaf.signingPubKey, leaf.newSigningPubKey);
433
- const shares = await this.config.signer.splitSecretWithProofs({
434
- secret: pubKeyTweak,
435
- curveOrder: secp256k1.CURVE.n,
436
- threshold: this.config.getThreshold(),
437
- numShares: Object.keys(signingOperators).length,
438
- isSecretPubkey: true,
439
- });
440
- const pubkeySharesTweak = new Map();
441
- for (const [identifier, operator] of Object.entries(signingOperators)) {
442
- const share = this.findShare(shares, operator.id);
443
- if (!share) {
444
- throw new Error(`Share not found for operator ${operator.id}`);
445
- }
446
- const pubkeyTweak = secp256k1.getPublicKey(numberToBytesBE(share.share, 32));
447
- pubkeySharesTweak.set(identifier, pubkeyTweak);
448
- }
449
- const leafTweaksMap = new Map();
450
- for (const [identifier, operator] of Object.entries(signingOperators)) {
451
- const share = this.findShare(shares, operator.id);
452
- if (!share) {
453
- throw new Error(`Share not found for operator ${operator.id}`);
454
- }
455
- leafTweaksMap.set(identifier, {
456
- leafId: leaf.leaf.id,
457
- secretShareTweak: {
458
- secretShare: numberToBytesBE(share.share, 32),
459
- proofs: share.proofs,
460
- },
461
- pubkeySharesTweak: Object.fromEntries(pubkeySharesTweak),
462
- });
463
- }
464
- return leafTweaksMap;
465
- }
466
- async claimTransferSignRefunds(transfer, leafKeys) {
467
- const leafDataMap = new Map();
468
- for (const leafKey of leafKeys) {
469
- const tx = getTxFromRawTxBytes(leafKey.leaf.nodeTx);
470
- leafDataMap.set(leafKey.leaf.id, {
471
- signingPubKey: leafKey.newSigningPubKey,
472
- receivingPubkey: leafKey.newSigningPubKey,
473
- signingNonceCommitment: await this.config.signer.getRandomSigningCommitment(),
474
- tx,
475
- vout: leafKey.leaf.vout,
476
- });
477
- }
478
- const signingJobs = this.prepareRefundSoSigningJobs(leafKeys, leafDataMap);
479
- const sparkClient = await this.connectionManager.createSparkClient(this.config.getCoordinatorAddress());
480
- let resp;
481
- try {
482
- resp = await sparkClient.claim_transfer_sign_refunds({
483
- transferId: transfer.id,
484
- ownerIdentityPublicKey: await this.config.signer.getIdentityPublicKey(),
485
- signingJobs,
486
- });
487
- }
488
- catch (error) {
489
- throw new Error(`Error claiming transfer sign refunds: ${error}`);
490
- }
491
- return this.signRefunds(leafDataMap, resp.signingResults);
492
- }
493
- async finalizeTransfer(nodeSignatures) {
494
- const sparkClient = await this.connectionManager.createSparkClient(this.config.getCoordinatorAddress());
495
- try {
496
- return await sparkClient.finalize_node_signatures({
497
- intent: SignatureIntent.TRANSFER,
498
- nodeSignatures,
499
- });
500
- }
501
- catch (error) {
502
- throw new Error(`Error finalizing node signatures in transfer: ${error}`);
503
- }
504
- }
505
- async cancelSendTransfer(transfer, operatorAddress) {
506
- const sparkClient = await this.connectionManager.createSparkClient(operatorAddress);
507
- try {
508
- const response = await sparkClient.cancel_send_transfer({
509
- transferId: transfer.id,
510
- senderIdentityPublicKey: await this.config.signer.getIdentityPublicKey(),
511
- });
512
- return response.transfer;
513
- }
514
- catch (error) {
515
- throw new Error(`Error canceling send transfer: ${error}`);
516
- }
517
- }
518
- async queryPendingTransfersBySender(operatorAddress) {
519
- const sparkClient = await this.connectionManager.createSparkClient(operatorAddress);
520
- try {
521
- return await sparkClient.query_pending_transfers({
522
- participant: {
523
- $case: "senderIdentityPublicKey",
524
- senderIdentityPublicKey: await this.config.signer.getIdentityPublicKey(),
525
- },
526
- network: this.config.getNetworkProto(),
527
- });
528
- }
529
- catch (error) {
530
- throw new Error(`Error querying pending transfers by sender: ${error}`);
531
- }
532
- }
533
- async refreshTimelockNodes(nodes, parentNode, signingPubKey) {
534
- if (nodes.length === 0) {
535
- throw Error("no nodes to refresh");
536
- }
537
- const signingJobs = [];
538
- const newNodeTxs = [];
539
- for (let i = 0; i < nodes.length; i++) {
540
- const node = nodes[i];
541
- if (!node) {
542
- throw Error("could not get node");
543
- }
544
- const nodeTx = getTxFromRawTxBytes(node?.nodeTx);
545
- const input = nodeTx.getInput(0);
546
- if (!input) {
547
- throw Error("Could not fetch tx input");
548
- }
549
- const newTx = new Transaction({ allowUnknownOutputs: true });
550
- for (let j = 0; j < nodeTx.outputsLength; j++) {
551
- newTx.addOutput(nodeTx.getOutput(j));
552
- }
553
- if (i === 0) {
554
- const currSequence = input.sequence;
555
- newTx.addInput({
556
- ...input,
557
- sequence: getNextTransactionSequence(currSequence).nextSequence,
558
- });
559
- }
560
- else {
561
- newTx.addInput({
562
- ...input,
563
- sequence: initialSequence(),
564
- txid: newNodeTxs[i - 1]?.id,
565
- });
566
- }
567
- signingJobs.push({
568
- signingPublicKey: signingPubKey,
569
- rawTx: newTx.toBytes(),
570
- signingNonceCommitment: await this.config.signer.getRandomSigningCommitment(),
571
- });
572
- newNodeTxs[i] = newTx;
573
- }
574
- const leaf = nodes[nodes.length - 1];
575
- if (!leaf?.refundTx) {
576
- throw Error("leaf does not have refund tx");
577
- }
578
- const refundTx = getTxFromRawTxBytes(leaf?.refundTx);
579
- const newRefundTx = new Transaction({ allowUnknownOutputs: true });
580
- for (let j = 0; j < refundTx.outputsLength; j++) {
581
- newRefundTx.addOutput(refundTx.getOutput(j));
582
- }
583
- const refundTxInput = refundTx.getInput(0);
584
- if (!refundTxInput) {
585
- throw Error("refund tx doesn't have input");
586
- }
587
- if (!newNodeTxs[newNodeTxs.length - 1]) {
588
- throw Error("Could not get last node tx");
589
- }
590
- newRefundTx.addInput({
591
- ...refundTxInput,
592
- sequence: initialSequence(),
593
- txid: getTxId(newNodeTxs[newNodeTxs.length - 1]),
594
- });
595
- const refundSigningJob = {
596
- signingPublicKey: signingPubKey,
597
- rawTx: newRefundTx.toBytes(),
598
- signingNonceCommitment: await this.config.signer.getRandomSigningCommitment(),
599
- };
600
- signingJobs.push(refundSigningJob);
601
- const sparkClient = await this.connectionManager.createSparkClient(this.config.getCoordinatorAddress());
602
- const response = await sparkClient.refresh_timelock({
603
- leafId: leaf.id,
604
- ownerIdentityPublicKey: await this.config.signer.getIdentityPublicKey(),
605
- signingJobs,
606
- });
607
- if (signingJobs.length !== response.signingResults.length) {
608
- throw Error(`number of signing jobs and signing results do not match: ${signingJobs.length} !== ${response.signingResults.length}`);
609
- }
610
- let nodeSignatures = [];
611
- let leafSignature;
612
- let refundSignature;
613
- let leafNodeId;
614
- for (let i = 0; i < response.signingResults.length; i++) {
615
- const signingResult = response.signingResults[i];
616
- const signingJob = signingJobs[i];
617
- if (!signingJob || !signingResult) {
618
- throw Error("Signing job does not exist");
619
- }
620
- if (!signingJob.signingNonceCommitment) {
621
- throw Error("nonce commitment does not exist");
622
- }
623
- const rawTx = getTxFromRawTxBytes(signingJob.rawTx);
624
- let parentTx;
625
- let nodeId;
626
- let vout;
627
- if (i === nodes.length) {
628
- nodeId = nodes[i - 1]?.id;
629
- parentTx = newNodeTxs[i - 1];
630
- vout = 0;
631
- }
632
- else if (i === 0) {
633
- nodeId = nodes[i]?.id;
634
- parentTx = getTxFromRawTxBytes(parentNode.nodeTx);
635
- vout = nodes[i]?.vout;
636
- }
637
- else {
638
- nodeId = nodes[i]?.id;
639
- parentTx = newNodeTxs[i - 1];
640
- vout = nodes[i]?.vout;
641
- }
642
- if (!parentTx || !nodeId || vout === undefined) {
643
- throw Error("Could not parse signing results");
644
- }
645
- const txOut = parentTx.getOutput(vout);
646
- const rawTxSighash = getSigHashFromTx(rawTx, 0, txOut);
647
- const userSignature = await this.config.signer.signFrost({
648
- message: rawTxSighash,
649
- privateAsPubKey: signingPubKey,
650
- publicKey: signingPubKey,
651
- verifyingKey: signingResult.verifyingKey,
652
- selfCommitment: signingJob.signingNonceCommitment,
653
- statechainCommitments: signingResult.signingResult?.signingNonceCommitments,
654
- adaptorPubKey: new Uint8Array(),
655
- });
656
- const signature = await this.config.signer.aggregateFrost({
657
- message: rawTxSighash,
658
- statechainSignatures: signingResult.signingResult?.signatureShares,
659
- statechainPublicKeys: signingResult.signingResult?.publicKeys,
660
- verifyingKey: signingResult.verifyingKey,
661
- statechainCommitments: signingResult.signingResult?.signingNonceCommitments,
662
- selfCommitment: signingJob.signingNonceCommitment,
663
- publicKey: signingPubKey,
664
- selfSignature: userSignature,
665
- adaptorPubKey: new Uint8Array(),
666
- });
667
- if (i !== nodes.length && i !== nodes.length - 1) {
668
- nodeSignatures.push({
669
- nodeId: nodeId,
670
- nodeTxSignature: signature,
671
- refundTxSignature: new Uint8Array(),
672
- });
673
- }
674
- else if (i === nodes.length) {
675
- refundSignature = signature;
676
- }
677
- else if (i === nodes.length - 1) {
678
- leafNodeId = nodeId;
679
- leafSignature = signature;
680
- }
681
- }
682
- if (!leafSignature || !refundSignature || !leafNodeId) {
683
- throw Error("leaf or refund signature does not exist");
684
- }
685
- nodeSignatures.push({
686
- nodeId: leafNodeId,
687
- nodeTxSignature: leafSignature,
688
- refundTxSignature: refundSignature,
689
- });
690
- return await sparkClient.finalize_node_signatures({
691
- intent: SignatureIntent.REFRESH,
692
- nodeSignatures,
693
- });
694
- }
695
- async extendTimelock(node, signingPubKey) {
696
- const nodeTx = getTxFromRawTxBytes(node.nodeTx);
697
- const refundTx = getTxFromRawTxBytes(node.refundTx);
698
- const refundSequence = refundTx.getInput(0).sequence || 0;
699
- const newNodeOutPoint = {
700
- txid: hexToBytes(nodeTx.id),
701
- index: 0,
702
- };
703
- const { nextSequence: newNodeSequence } = getNextTransactionSequence(refundSequence);
704
- const newNodeTx = new Transaction({ allowUnknownOutputs: true });
705
- newNodeTx.addInput({ ...newNodeOutPoint, sequence: newNodeSequence });
706
- newNodeTx.addOutput(nodeTx.getOutput(0));
707
- newNodeTx.addOutput(getEphemeralAnchorOutput());
708
- const newRefundOutPoint = {
709
- txid: hexToBytes(getTxId(newNodeTx)),
710
- index: 0,
711
- };
712
- const amountSats = refundTx.getOutput(0).amount;
713
- if (amountSats === undefined) {
714
- throw new Error("Amount not found in extendTimelock");
715
- }
716
- const newRefundTx = createRefundTx(initialSequence(), newRefundOutPoint, amountSats, signingPubKey, this.config.getNetwork());
717
- const nodeSighash = getSigHashFromTx(newNodeTx, 0, nodeTx.getOutput(0));
718
- const refundSighash = getSigHashFromTx(newRefundTx, 0, nodeTx.getOutput(0));
719
- const newNodeSigningJob = {
720
- signingPublicKey: signingPubKey,
721
- rawTx: newNodeTx.toBytes(),
722
- signingNonceCommitment: await this.config.signer.getRandomSigningCommitment(),
723
- };
724
- const newRefundSigningJob = {
725
- signingPublicKey: signingPubKey,
726
- rawTx: newRefundTx.toBytes(),
727
- signingNonceCommitment: await this.config.signer.getRandomSigningCommitment(),
728
- };
729
- const sparkClient = await this.connectionManager.createSparkClient(this.config.getCoordinatorAddress());
730
- const response = await sparkClient.extend_leaf({
731
- leafId: node.id,
732
- ownerIdentityPublicKey: await this.config.signer.getIdentityPublicKey(),
733
- nodeTxSigningJob: newNodeSigningJob,
734
- refundTxSigningJob: newRefundSigningJob,
735
- });
736
- if (!response.nodeTxSigningResult || !response.refundTxSigningResult) {
737
- throw new Error("Signing result does not exist");
738
- }
739
- const nodeUserSig = await this.config.signer.signFrost({
740
- message: nodeSighash,
741
- privateAsPubKey: signingPubKey,
742
- publicKey: signingPubKey,
743
- verifyingKey: response.nodeTxSigningResult.verifyingKey,
744
- selfCommitment: newNodeSigningJob.signingNonceCommitment,
745
- statechainCommitments: response.nodeTxSigningResult.signingResult?.signingNonceCommitments,
746
- adaptorPubKey: new Uint8Array(),
747
- });
748
- const refundUserSig = await this.config.signer.signFrost({
749
- message: refundSighash,
750
- privateAsPubKey: signingPubKey,
751
- publicKey: signingPubKey,
752
- verifyingKey: response.refundTxSigningResult.verifyingKey,
753
- selfCommitment: newRefundSigningJob.signingNonceCommitment,
754
- statechainCommitments: response.refundTxSigningResult.signingResult?.signingNonceCommitments,
755
- adaptorPubKey: new Uint8Array(),
756
- });
757
- const nodeSig = await this.config.signer.aggregateFrost({
758
- message: nodeSighash,
759
- statechainSignatures: response.nodeTxSigningResult.signingResult?.signatureShares,
760
- statechainPublicKeys: response.nodeTxSigningResult.signingResult?.publicKeys,
761
- verifyingKey: response.nodeTxSigningResult.verifyingKey,
762
- statechainCommitments: response.nodeTxSigningResult.signingResult?.signingNonceCommitments,
763
- selfCommitment: newNodeSigningJob.signingNonceCommitment,
764
- publicKey: signingPubKey,
765
- selfSignature: nodeUserSig,
766
- adaptorPubKey: new Uint8Array(),
767
- });
768
- const refundSig = await this.config.signer.aggregateFrost({
769
- message: refundSighash,
770
- statechainSignatures: response.refundTxSigningResult.signingResult?.signatureShares,
771
- statechainPublicKeys: response.refundTxSigningResult.signingResult?.publicKeys,
772
- verifyingKey: response.refundTxSigningResult.verifyingKey,
773
- statechainCommitments: response.refundTxSigningResult.signingResult?.signingNonceCommitments,
774
- selfCommitment: newRefundSigningJob.signingNonceCommitment,
775
- publicKey: signingPubKey,
776
- selfSignature: refundUserSig,
777
- adaptorPubKey: new Uint8Array(),
778
- });
779
- return await sparkClient.finalize_node_signatures({
780
- intent: SignatureIntent.EXTEND,
781
- nodeSignatures: [
782
- {
783
- nodeId: response.leafId,
784
- nodeTxSignature: nodeSig,
785
- refundTxSignature: refundSig,
786
- },
787
- ],
788
- });
789
- }
790
- }
791
- //# sourceMappingURL=transfer.js.map