@metamask/ramps-controller 20.3.0 → 22.0.0

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 (290) hide show
  1. package/CHANGELOG.md +42 -1
  2. package/dist/{NeoBankService-method-action-types.d.mts → NeoBankService-method-action-types.d.ts} +2 -2
  3. package/dist/NeoBankService-method-action-types.d.ts.map +1 -0
  4. package/dist/{NeoBankService-method-action-types.mjs → NeoBankService-method-action-types.js} +1 -1
  5. package/dist/NeoBankService-method-action-types.js.map +1 -0
  6. package/dist/{NeoBankService.d.cts → NeoBankService.d.ts} +8 -8
  7. package/dist/NeoBankService.d.ts.map +1 -0
  8. package/dist/NeoBankService.js +380 -0
  9. package/dist/NeoBankService.js.map +1 -0
  10. package/dist/{RampsController-method-action-types.d.mts → RampsController-method-action-types.d.ts} +18 -3
  11. package/dist/RampsController-method-action-types.d.ts.map +1 -0
  12. package/dist/{TransakService-method-action-types.mjs → RampsController-method-action-types.js} +1 -1
  13. package/dist/RampsController-method-action-types.js.map +1 -0
  14. package/dist/{RampsController.d.mts → RampsController.d.ts} +86 -23
  15. package/dist/RampsController.d.ts.map +1 -0
  16. package/dist/{RampsController.mjs → RampsController.js} +976 -634
  17. package/dist/RampsController.js.map +1 -0
  18. package/dist/{RampsService-method-action-types.d.cts → RampsService-method-action-types.d.ts} +2 -2
  19. package/dist/RampsService-method-action-types.d.ts.map +1 -0
  20. package/dist/{RampsService-method-action-types.mjs → RampsService-method-action-types.js} +1 -1
  21. package/dist/RampsService-method-action-types.js.map +1 -0
  22. package/dist/{RampsService.d.mts → RampsService.d.ts} +11 -5
  23. package/dist/RampsService.d.ts.map +1 -0
  24. package/dist/{RampsService.mjs → RampsService.js} +159 -147
  25. package/dist/RampsService.js.map +1 -0
  26. package/dist/{RequestCache.d.mts → RequestCache.d.ts} +3 -3
  27. package/dist/RequestCache.d.ts.map +1 -0
  28. package/dist/{RequestCache.mjs → RequestCache.js} +1 -1
  29. package/dist/RequestCache.js.map +1 -0
  30. package/dist/{TransakService-method-action-types.d.cts → TransakService-method-action-types.d.ts} +2 -2
  31. package/dist/TransakService-method-action-types.d.ts.map +1 -0
  32. package/dist/{RampsController-method-action-types.mjs → TransakService-method-action-types.js} +1 -1
  33. package/dist/TransakService-method-action-types.js.map +1 -0
  34. package/dist/{TransakService.d.cts → TransakService.d.ts} +6 -6
  35. package/dist/TransakService.d.ts.map +1 -0
  36. package/dist/TransakService.js +746 -0
  37. package/dist/TransakService.js.map +1 -0
  38. package/dist/{autoramp-types.d.cts → autoramp-types.d.ts} +1 -1
  39. package/dist/autoramp-types.d.ts.map +1 -0
  40. package/dist/autoramp-types.js +2 -0
  41. package/dist/autoramp-types.js.map +1 -0
  42. package/dist/{autorampAccount.d.mts → autorampAccount.d.ts} +3 -3
  43. package/dist/autorampAccount.d.ts.map +1 -0
  44. package/dist/{autorampAccount.mjs → autorampAccount.js} +1 -1
  45. package/dist/autorampAccount.js.map +1 -0
  46. package/dist/{client-identity.d.mts → client-identity.d.ts} +1 -1
  47. package/dist/client-identity.d.ts.map +1 -0
  48. package/dist/{client-identity.mjs → client-identity.js} +1 -1
  49. package/dist/client-identity.js.map +1 -0
  50. package/dist/{errorNormalization.d.mts → errorNormalization.d.ts} +1 -1
  51. package/dist/errorNormalization.d.ts.map +1 -0
  52. package/dist/{errorNormalization.mjs → errorNormalization.js} +1 -1
  53. package/dist/errorNormalization.js.map +1 -0
  54. package/dist/{featureFlags.d.mts → featureFlags.d.ts} +2 -2
  55. package/dist/featureFlags.d.ts.map +1 -0
  56. package/dist/{featureFlags.mjs → featureFlags.js} +1 -1
  57. package/dist/featureFlags.js.map +1 -0
  58. package/dist/{index.d.mts → index.d.ts} +37 -35
  59. package/dist/index.d.ts.map +1 -0
  60. package/dist/index.js +19 -0
  61. package/dist/index.js.map +1 -0
  62. package/dist/order-syncing/constants.d.ts +23 -0
  63. package/dist/order-syncing/constants.d.ts.map +1 -0
  64. package/dist/order-syncing/constants.js +23 -0
  65. package/dist/order-syncing/constants.js.map +1 -0
  66. package/dist/order-syncing/controller-integration.d.ts +91 -0
  67. package/dist/order-syncing/controller-integration.d.ts.map +1 -0
  68. package/dist/order-syncing/controller-integration.js +364 -0
  69. package/dist/order-syncing/controller-integration.js.map +1 -0
  70. package/dist/order-syncing/index.d.ts +7 -0
  71. package/dist/order-syncing/index.d.ts.map +1 -0
  72. package/dist/order-syncing/index.js +5 -0
  73. package/dist/order-syncing/index.js.map +1 -0
  74. package/dist/order-syncing/sync-utils.d.ts +9 -0
  75. package/dist/order-syncing/sync-utils.d.ts.map +1 -0
  76. package/dist/order-syncing/sync-utils.js +27 -0
  77. package/dist/order-syncing/sync-utils.js.map +1 -0
  78. package/dist/order-syncing/types.d.ts +66 -0
  79. package/dist/order-syncing/types.d.ts.map +1 -0
  80. package/dist/order-syncing/types.js +2 -0
  81. package/dist/order-syncing/types.js.map +1 -0
  82. package/dist/order-syncing/utils.d.ts +83 -0
  83. package/dist/order-syncing/utils.d.ts.map +1 -0
  84. package/dist/order-syncing/utils.js +144 -0
  85. package/dist/order-syncing/utils.js.map +1 -0
  86. package/dist/{orderStatus.d.mts → orderStatus.d.ts} +2 -2
  87. package/dist/orderStatus.d.ts.map +1 -0
  88. package/dist/{orderStatus.mjs → orderStatus.js} +2 -2
  89. package/dist/orderStatus.js.map +1 -0
  90. package/dist/{ownership-message.d.cts → ownership-message.d.ts} +1 -1
  91. package/dist/ownership-message.d.ts.map +1 -0
  92. package/dist/{ownership-message.mjs → ownership-message.js} +1 -1
  93. package/dist/ownership-message.js.map +1 -0
  94. package/dist/{paymentMethodMerge.d.cts → paymentMethodMerge.d.ts} +2 -2
  95. package/dist/paymentMethodMerge.d.ts.map +1 -0
  96. package/dist/{paymentMethodMerge.mjs → paymentMethodMerge.js} +1 -1
  97. package/dist/paymentMethodMerge.js.map +1 -0
  98. package/dist/{providerAvailability.d.cts → providerAvailability.d.ts} +2 -2
  99. package/dist/providerAvailability.d.ts.map +1 -0
  100. package/dist/{providerAvailability.mjs → providerAvailability.js} +1 -1
  101. package/dist/providerAvailability.js.map +1 -0
  102. package/dist/{quoteClassification.d.cts → quoteClassification.d.ts} +2 -2
  103. package/dist/quoteClassification.d.ts.map +1 -0
  104. package/dist/{quoteClassification.mjs → quoteClassification.js} +1 -1
  105. package/dist/quoteClassification.js.map +1 -0
  106. package/dist/{rampsErrorCodes.d.cts → rampsErrorCodes.d.ts} +2 -2
  107. package/dist/rampsErrorCodes.d.ts.map +1 -0
  108. package/dist/{rampsErrorCodes.mjs → rampsErrorCodes.js} +1 -1
  109. package/dist/rampsErrorCodes.js.map +1 -0
  110. package/dist/{selectors.d.mts → selectors.d.ts} +3 -3
  111. package/dist/selectors.d.ts.map +1 -0
  112. package/dist/{selectors.mjs → selectors.js} +2 -2
  113. package/dist/selectors.js.map +1 -0
  114. package/dist/{transakApiErrorUtils.d.cts → transakApiErrorUtils.d.ts} +1 -1
  115. package/dist/transakApiErrorUtils.d.ts.map +1 -0
  116. package/dist/{transakApiErrorUtils.mjs → transakApiErrorUtils.js} +3 -3
  117. package/dist/transakApiErrorUtils.js.map +1 -0
  118. package/dist/{transakErrorCodes.d.cts → transakErrorCodes.d.ts} +3 -3
  119. package/dist/transakErrorCodes.d.ts.map +1 -0
  120. package/dist/{transakErrorCodes.mjs → transakErrorCodes.js} +1 -1
  121. package/dist/transakErrorCodes.js.map +1 -0
  122. package/dist/{wallet-registration-machine.d.cts → wallet-registration-machine.d.ts} +1 -1
  123. package/dist/wallet-registration-machine.d.ts.map +1 -0
  124. package/dist/{wallet-registration-machine.mjs → wallet-registration-machine.js} +1 -1
  125. package/dist/wallet-registration-machine.js.map +1 -0
  126. package/dist/{wallet-registration-service.d.cts → wallet-registration-service.d.ts} +1 -1
  127. package/dist/wallet-registration-service.d.ts.map +1 -0
  128. package/dist/{wallet-registration-service.mjs → wallet-registration-service.js} +60 -69
  129. package/dist/wallet-registration-service.js.map +1 -0
  130. package/package.json +18 -21
  131. package/dist/NeoBankService-method-action-types.cjs +0 -7
  132. package/dist/NeoBankService-method-action-types.cjs.map +0 -1
  133. package/dist/NeoBankService-method-action-types.d.cts +0 -126
  134. package/dist/NeoBankService-method-action-types.d.cts.map +0 -1
  135. package/dist/NeoBankService-method-action-types.d.mts.map +0 -1
  136. package/dist/NeoBankService-method-action-types.mjs.map +0 -1
  137. package/dist/NeoBankService.cjs +0 -387
  138. package/dist/NeoBankService.cjs.map +0 -1
  139. package/dist/NeoBankService.d.cts.map +0 -1
  140. package/dist/NeoBankService.d.mts +0 -191
  141. package/dist/NeoBankService.d.mts.map +0 -1
  142. package/dist/NeoBankService.mjs +0 -379
  143. package/dist/NeoBankService.mjs.map +0 -1
  144. package/dist/RampsController-method-action-types.cjs +0 -7
  145. package/dist/RampsController-method-action-types.cjs.map +0 -1
  146. package/dist/RampsController-method-action-types.d.cts +0 -758
  147. package/dist/RampsController-method-action-types.d.cts.map +0 -1
  148. package/dist/RampsController-method-action-types.d.mts.map +0 -1
  149. package/dist/RampsController-method-action-types.mjs.map +0 -1
  150. package/dist/RampsController.cjs +0 -2799
  151. package/dist/RampsController.cjs.map +0 -1
  152. package/dist/RampsController.d.cts +0 -968
  153. package/dist/RampsController.d.cts.map +0 -1
  154. package/dist/RampsController.d.mts.map +0 -1
  155. package/dist/RampsController.mjs.map +0 -1
  156. package/dist/RampsService-method-action-types.cjs +0 -7
  157. package/dist/RampsService-method-action-types.cjs.map +0 -1
  158. package/dist/RampsService-method-action-types.d.cts.map +0 -1
  159. package/dist/RampsService-method-action-types.d.mts +0 -171
  160. package/dist/RampsService-method-action-types.d.mts.map +0 -1
  161. package/dist/RampsService-method-action-types.mjs.map +0 -1
  162. package/dist/RampsService.cjs +0 -708
  163. package/dist/RampsService.cjs.map +0 -1
  164. package/dist/RampsService.d.cts +0 -944
  165. package/dist/RampsService.d.cts.map +0 -1
  166. package/dist/RampsService.d.mts.map +0 -1
  167. package/dist/RampsService.mjs.map +0 -1
  168. package/dist/RequestCache.cjs +0 -103
  169. package/dist/RequestCache.cjs.map +0 -1
  170. package/dist/RequestCache.d.cts +0 -110
  171. package/dist/RequestCache.d.cts.map +0 -1
  172. package/dist/RequestCache.d.mts.map +0 -1
  173. package/dist/RequestCache.mjs.map +0 -1
  174. package/dist/TransakService-method-action-types.cjs +0 -7
  175. package/dist/TransakService-method-action-types.cjs.map +0 -1
  176. package/dist/TransakService-method-action-types.d.cts.map +0 -1
  177. package/dist/TransakService-method-action-types.d.mts +0 -140
  178. package/dist/TransakService-method-action-types.d.mts.map +0 -1
  179. package/dist/TransakService-method-action-types.mjs.map +0 -1
  180. package/dist/TransakService.cjs +0 -743
  181. package/dist/TransakService.cjs.map +0 -1
  182. package/dist/TransakService.d.cts.map +0 -1
  183. package/dist/TransakService.d.mts +0 -370
  184. package/dist/TransakService.d.mts.map +0 -1
  185. package/dist/TransakService.mjs +0 -734
  186. package/dist/TransakService.mjs.map +0 -1
  187. package/dist/autoramp-types.cjs +0 -3
  188. package/dist/autoramp-types.cjs.map +0 -1
  189. package/dist/autoramp-types.d.cts.map +0 -1
  190. package/dist/autoramp-types.d.mts +0 -22
  191. package/dist/autoramp-types.d.mts.map +0 -1
  192. package/dist/autoramp-types.mjs +0 -2
  193. package/dist/autoramp-types.mjs.map +0 -1
  194. package/dist/autorampAccount.cjs +0 -155
  195. package/dist/autorampAccount.cjs.map +0 -1
  196. package/dist/autorampAccount.d.cts +0 -126
  197. package/dist/autorampAccount.d.cts.map +0 -1
  198. package/dist/autorampAccount.d.mts.map +0 -1
  199. package/dist/autorampAccount.mjs.map +0 -1
  200. package/dist/client-identity.cjs +0 -28
  201. package/dist/client-identity.cjs.map +0 -1
  202. package/dist/client-identity.d.cts +0 -24
  203. package/dist/client-identity.d.cts.map +0 -1
  204. package/dist/client-identity.d.mts.map +0 -1
  205. package/dist/client-identity.mjs.map +0 -1
  206. package/dist/errorNormalization.cjs +0 -84
  207. package/dist/errorNormalization.cjs.map +0 -1
  208. package/dist/errorNormalization.d.cts +0 -56
  209. package/dist/errorNormalization.d.cts.map +0 -1
  210. package/dist/errorNormalization.d.mts.map +0 -1
  211. package/dist/errorNormalization.mjs.map +0 -1
  212. package/dist/featureFlags.cjs +0 -144
  213. package/dist/featureFlags.cjs.map +0 -1
  214. package/dist/featureFlags.d.cts +0 -82
  215. package/dist/featureFlags.d.cts.map +0 -1
  216. package/dist/featureFlags.d.mts.map +0 -1
  217. package/dist/featureFlags.mjs.map +0 -1
  218. package/dist/index.cjs +0 -82
  219. package/dist/index.cjs.map +0 -1
  220. package/dist/index.d.cts +0 -35
  221. package/dist/index.d.cts.map +0 -1
  222. package/dist/index.d.mts.map +0 -1
  223. package/dist/index.mjs +0 -18
  224. package/dist/index.mjs.map +0 -1
  225. package/dist/orderStatus.cjs +0 -34
  226. package/dist/orderStatus.cjs.map +0 -1
  227. package/dist/orderStatus.d.cts +0 -18
  228. package/dist/orderStatus.d.cts.map +0 -1
  229. package/dist/orderStatus.d.mts.map +0 -1
  230. package/dist/orderStatus.mjs.map +0 -1
  231. package/dist/ownership-message.cjs +0 -26
  232. package/dist/ownership-message.cjs.map +0 -1
  233. package/dist/ownership-message.d.cts.map +0 -1
  234. package/dist/ownership-message.d.mts +0 -22
  235. package/dist/ownership-message.d.mts.map +0 -1
  236. package/dist/ownership-message.mjs.map +0 -1
  237. package/dist/paymentMethodMerge.cjs +0 -51
  238. package/dist/paymentMethodMerge.cjs.map +0 -1
  239. package/dist/paymentMethodMerge.d.cts.map +0 -1
  240. package/dist/paymentMethodMerge.d.mts +0 -26
  241. package/dist/paymentMethodMerge.d.mts.map +0 -1
  242. package/dist/paymentMethodMerge.mjs.map +0 -1
  243. package/dist/providerAvailability.cjs +0 -134
  244. package/dist/providerAvailability.cjs.map +0 -1
  245. package/dist/providerAvailability.d.cts.map +0 -1
  246. package/dist/providerAvailability.d.mts +0 -101
  247. package/dist/providerAvailability.d.mts.map +0 -1
  248. package/dist/providerAvailability.mjs.map +0 -1
  249. package/dist/quoteClassification.cjs +0 -44
  250. package/dist/quoteClassification.cjs.map +0 -1
  251. package/dist/quoteClassification.d.cts.map +0 -1
  252. package/dist/quoteClassification.d.mts +0 -33
  253. package/dist/quoteClassification.d.mts.map +0 -1
  254. package/dist/quoteClassification.mjs.map +0 -1
  255. package/dist/rampsErrorCodes.cjs +0 -11
  256. package/dist/rampsErrorCodes.cjs.map +0 -1
  257. package/dist/rampsErrorCodes.d.cts.map +0 -1
  258. package/dist/rampsErrorCodes.d.mts +0 -9
  259. package/dist/rampsErrorCodes.d.mts.map +0 -1
  260. package/dist/rampsErrorCodes.mjs.map +0 -1
  261. package/dist/selectors.cjs +0 -85
  262. package/dist/selectors.cjs.map +0 -1
  263. package/dist/selectors.d.cts +0 -78
  264. package/dist/selectors.d.cts.map +0 -1
  265. package/dist/selectors.d.mts.map +0 -1
  266. package/dist/selectors.mjs.map +0 -1
  267. package/dist/transakApiErrorUtils.cjs +0 -15
  268. package/dist/transakApiErrorUtils.cjs.map +0 -1
  269. package/dist/transakApiErrorUtils.d.cts.map +0 -1
  270. package/dist/transakApiErrorUtils.d.mts +0 -3
  271. package/dist/transakApiErrorUtils.d.mts.map +0 -1
  272. package/dist/transakApiErrorUtils.mjs.map +0 -1
  273. package/dist/transakErrorCodes.cjs +0 -14
  274. package/dist/transakErrorCodes.cjs.map +0 -1
  275. package/dist/transakErrorCodes.d.cts.map +0 -1
  276. package/dist/transakErrorCodes.d.mts +0 -12
  277. package/dist/transakErrorCodes.d.mts.map +0 -1
  278. package/dist/transakErrorCodes.mjs.map +0 -1
  279. package/dist/wallet-registration-machine.cjs +0 -144
  280. package/dist/wallet-registration-machine.cjs.map +0 -1
  281. package/dist/wallet-registration-machine.d.cts.map +0 -1
  282. package/dist/wallet-registration-machine.d.mts +0 -81
  283. package/dist/wallet-registration-machine.d.mts.map +0 -1
  284. package/dist/wallet-registration-machine.mjs.map +0 -1
  285. package/dist/wallet-registration-service.cjs +0 -351
  286. package/dist/wallet-registration-service.cjs.map +0 -1
  287. package/dist/wallet-registration-service.d.cts.map +0 -1
  288. package/dist/wallet-registration-service.d.mts +0 -144
  289. package/dist/wallet-registration-service.d.mts.map +0 -1
  290. package/dist/wallet-registration-service.mjs.map +0 -1
@@ -1,144 +0,0 @@
1
- "use strict";
2
- /**
3
- * Pure, hand-rolled finite state machine for the MoonPay Iron self-hosted
4
- * wallet registration signing step. It follows the FSM convention used
5
- * elsewhere in `core` (no XState dependency): a single pure `transition`
6
- * reducer plus a data-driven transition table.
7
- *
8
- * Side effects (server lookups, signing, POSTing) live in the interpreter that
9
- * drives this machine; every effect result is fed back in as an event, so the
10
- * machine itself stays deterministic and trivially testable.
11
- */
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.transition = exports.createInitialState = void 0;
14
- const DEFAULT_MAX_ATTEMPTS = 3;
15
- /**
16
- * Creates the initial idle state.
17
- *
18
- * @param maxAttempts - Optional retry ceiling for sign attempts.
19
- * @returns A fresh idle machine state.
20
- */
21
- function createInitialState(maxAttempts = DEFAULT_MAX_ATTEMPTS) {
22
- return { status: 'idle', context: { attempts: 0, maxAttempts } };
23
- }
24
- exports.createInitialState = createInitialState;
25
- /**
26
- * Builds a handler that moves to a status while preserving context.
27
- *
28
- * @param status - Target status.
29
- * @returns A handler transitioning to `status`.
30
- */
31
- function keep(status) {
32
- return (state) => ({ status, context: state.context });
33
- }
34
- /**
35
- * Builds a handler that moves to a status and resets the retry context. Used
36
- * when the user (or app resume) starts a fresh attempt from scratch.
37
- *
38
- * @param status - Target status.
39
- * @returns A handler transitioning to `status` with reset context.
40
- */
41
- function reset(status) {
42
- return (state) => ({
43
- status,
44
- context: { ...state.context, attempts: 0 },
45
- });
46
- }
47
- /**
48
- * Moves to `signing` and counts this as a new sign attempt.
49
- *
50
- * @param state - Current state.
51
- * @returns The `signing` state with an incremented attempt count.
52
- */
53
- const toSigning = (state) => ({
54
- status: 'signing',
55
- context: { ...state.context, attempts: state.context.attempts + 1 },
56
- });
57
- const toPreparing = reset('preparing');
58
- const toAlreadyRegistered = keep('alreadyRegistered');
59
- const toRegisteredDisabled = keep('registeredDisabled');
60
- const toLookupUnavailable = keep('lookupUnavailable');
61
- const toCancelled = keep('cancelled');
62
- const signFailed = (state, event) => {
63
- const { retryable } = event;
64
- return retryable
65
- ? keep('failedRetryable')(state, event)
66
- : keep('failedTerminal')(state, event);
67
- };
68
- const submitValidation = (state, event) => {
69
- const { utcRollover } = event;
70
- return utcRollover && state.context.attempts < state.context.maxAttempts
71
- ? toSigning(state, event)
72
- : keep('failedTerminal')(state, event);
73
- };
74
- const checkThenRetryAbsent = (state, event) => state.context.attempts < state.context.maxAttempts
75
- ? toSigning(state, event)
76
- : keep('failedRetryable')(state, event);
77
- const TABLE = {
78
- idle: {
79
- START: toPreparing,
80
- },
81
- preparing: {
82
- LOOKUP_ACTIVE: toAlreadyRegistered,
83
- LOOKUP_DISABLED: toRegisteredDisabled,
84
- LOOKUP_ABSENT: toSigning,
85
- LOOKUP_FAILED: toLookupUnavailable,
86
- },
87
- awaitingUnlock: {
88
- WALLET_UNLOCKED: keep('signing'),
89
- },
90
- signing: {
91
- SIGN_OK: keep('submitting'),
92
- SIGN_REJECTED: toCancelled,
93
- SIGN_FAILED: signFailed,
94
- WALLET_LOCKED: keep('awaitingUnlock'),
95
- CANCEL: toCancelled,
96
- },
97
- submitting: {
98
- SUBMIT_OK: keep('registered'),
99
- SUBMIT_CONFLICT: keep('disambiguate409'),
100
- SUBMIT_TRANSIENT: keep('checkThenRetry'),
101
- SUBMIT_VALIDATION: submitValidation,
102
- SUBMIT_TERMINAL: keep('failedTerminal'),
103
- SUBMIT_RATE_LIMITED: keep('failedRetryable'),
104
- CANCEL: toCancelled,
105
- },
106
- disambiguate409: {
107
- LOOKUP_ACTIVE: toAlreadyRegistered,
108
- LOOKUP_DISABLED: toRegisteredDisabled,
109
- LOOKUP_ABSENT: keep('failedRetryable'),
110
- LOOKUP_FAILED: toLookupUnavailable,
111
- CANCEL: toCancelled,
112
- },
113
- checkThenRetry: {
114
- LOOKUP_ACTIVE: toAlreadyRegistered,
115
- LOOKUP_DISABLED: toRegisteredDisabled,
116
- LOOKUP_ABSENT: checkThenRetryAbsent,
117
- LOOKUP_FAILED: toLookupUnavailable,
118
- CANCEL: toCancelled,
119
- },
120
- failedRetryable: {
121
- RETRY: toPreparing,
122
- },
123
- lookupUnavailable: {
124
- RETRY: toPreparing,
125
- },
126
- cancelled: {
127
- RETRY: toPreparing,
128
- },
129
- };
130
- /**
131
- * Pure transition reducer. Unhandled (state, event) pairs are no-ops, which is
132
- * how the machine enforces "one in-flight operation" (a second `START` while
133
- * busy is ignored) and how terminal states stay put.
134
- *
135
- * @param state - Current machine state.
136
- * @param event - Event to apply.
137
- * @returns The next state (or the same state for unhandled events).
138
- */
139
- function transition(state, event) {
140
- const handler = TABLE[state.status]?.[event.type];
141
- return handler ? handler(state, event) : state;
142
- }
143
- exports.transition = transition;
144
- //# sourceMappingURL=wallet-registration-machine.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"wallet-registration-machine.cjs","sourceRoot":"","sources":["../src/wallet-registration-machine.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AA4DH,MAAM,oBAAoB,GAAG,CAAC,CAAC;AAE/B;;;;;GAKG;AACH,SAAgB,kBAAkB,CAChC,cAAsB,oBAAoB;IAE1C,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,WAAW,EAAE,EAAE,CAAC;AACnE,CAAC;AAJD,gDAIC;AAED;;;;;GAKG;AACH,SAAS,IAAI,CAAC,MAAgC;IAC5C,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;AACzD,CAAC;AAED;;;;;;GAMG;AACH,SAAS,KAAK,CAAC,MAAgC;IAC7C,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACjB,MAAM;Q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KACpB;IACD,cAAc,EAAE;QACd,aAAa,EAAE,mBAAmB;QAClC,eAAe,EAAE,oBAAoB;QACrC,aAAa,EAAE,oBAAoB;QACnC,aAAa,EAAE,mBAAmB;QAClC,MAAM,EAAE,WAAW;KACpB;IACD,eAAe,EAAE;QACf,KAAK,EAAE,WAAW;KACnB;IACD,iBAAiB,EAAE;QACjB,KAAK,EAAE,WAAW;KACnB;IACD,SAAS,EAAE;QACT,KAAK,EAAE,WAAW;KACnB;CACF,CAAC;AAEF;;;;;;;;GAQG;AACH,SAAgB,UAAU,CACxB,KAA8B,EAC9B,KAA8B;IAE9B,MAAM,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAClD,OAAO,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AACjD,CAAC;AAND,gCAMC","sourcesContent":["/**\n * Pure, hand-rolled finite state machine for the MoonPay Iron self-hosted\n * wallet registration signing step. It follows the FSM convention used\n * elsewhere in `core` (no XState dependency): a single pure `transition`\n * reducer plus a data-driven transition table.\n *\n * Side effects (server lookups, signing, POSTing) live in the interpreter that\n * drives this machine; every effect result is fed back in as an event, so the\n * machine itself stays deterministic and trivially testable.\n */\n\n/** Every state in the signing step. */\nexport type WalletRegistrationStatus =\n | 'idle'\n | 'preparing'\n | 'awaitingUnlock'\n | 'signing'\n | 'submitting'\n | 'disambiguate409'\n | 'checkThenRetry'\n | 'lookupUnavailable'\n | 'registered'\n | 'alreadyRegistered'\n | 'registeredDisabled'\n | 'failedRetryable'\n | 'failedTerminal'\n | 'cancelled';\n\n/** Machine context carried across transitions. */\nexport type WalletRegistrationContext = {\n /** Number of sign attempts made so far (used for the retry ceiling). */\n attempts: number;\n /** Maximum number of sign attempts before a retryable failure is surfaced. */\n maxAttempts: number;\n};\n\nexport type WalletRegistrationState = {\n status: WalletRegistrationStatus;\n context: WalletRegistrationContext;\n};\n\n/** Events the interpreter dispatches into the machine. */\nexport type WalletRegistrationEvent =\n | { type: 'START' }\n | { type: 'WALLET_LOCKED' }\n | { type: 'WALLET_UNLOCKED' }\n | { type: 'LOOKUP_ACTIVE' }\n | { type: 'LOOKUP_DISABLED' }\n | { type: 'LOOKUP_ABSENT' }\n | { type: 'LOOKUP_FAILED' }\n | { type: 'SIGN_OK' }\n | { type: 'SIGN_REJECTED' }\n | { type: 'SIGN_FAILED'; retryable: boolean }\n | { type: 'SUBMIT_OK' }\n | { type: 'SUBMIT_CONFLICT' }\n | { type: 'SUBMIT_TRANSIENT' }\n | { type: 'SUBMIT_VALIDATION'; utcRollover: boolean }\n | { type: 'SUBMIT_TERMINAL' }\n | { type: 'SUBMIT_RATE_LIMITED' }\n | { type: 'RETRY' }\n | { type: 'CANCEL' };\n\ntype EventType = WalletRegistrationEvent['type'];\n\ntype Handler = (\n state: WalletRegistrationState,\n event: WalletRegistrationEvent,\n) => WalletRegistrationState;\n\nconst DEFAULT_MAX_ATTEMPTS = 3;\n\n/**\n * Creates the initial idle state.\n *\n * @param maxAttempts - Optional retry ceiling for sign attempts.\n * @returns A fresh idle machine state.\n */\nexport function createInitialState(\n maxAttempts: number = DEFAULT_MAX_ATTEMPTS,\n): WalletRegistrationState {\n return { status: 'idle', context: { attempts: 0, maxAttempts } };\n}\n\n/**\n * Builds a handler that moves to a status while preserving context.\n *\n * @param status - Target status.\n * @returns A handler transitioning to `status`.\n */\nfunction keep(status: WalletRegistrationStatus): Handler {\n return (state) => ({ status, context: state.context });\n}\n\n/**\n * Builds a handler that moves to a status and resets the retry context. Used\n * when the user (or app resume) starts a fresh attempt from scratch.\n *\n * @param status - Target status.\n * @returns A handler transitioning to `status` with reset context.\n */\nfunction reset(status: WalletRegistrationStatus): Handler {\n return (state) => ({\n status,\n context: { ...state.context, attempts: 0 },\n });\n}\n\n/**\n * Moves to `signing` and counts this as a new sign attempt.\n *\n * @param state - Current state.\n * @returns The `signing` state with an incremented attempt count.\n */\nconst toSigning: Handler = (state) => ({\n status: 'signing',\n context: { ...state.context, attempts: state.context.attempts + 1 },\n});\n\nconst toPreparing = reset('preparing');\nconst toAlreadyRegistered = keep('alreadyRegistered');\nconst toRegisteredDisabled = keep('registeredDisabled');\nconst toLookupUnavailable = keep('lookupUnavailable');\nconst toCancelled = keep('cancelled');\n\nconst signFailed: Handler = (state, event) => {\n const { retryable } = event as Extract<\n WalletRegistrationEvent,\n { type: 'SIGN_FAILED' }\n >;\n return retryable\n ? keep('failedRetryable')(state, event)\n : keep('failedTerminal')(state, event);\n};\n\nconst submitValidation: Handler = (state, event) => {\n const { utcRollover } = event as Extract<\n WalletRegistrationEvent,\n { type: 'SUBMIT_VALIDATION' }\n >;\n return utcRollover && state.context.attempts < state.context.maxAttempts\n ? toSigning(state, event)\n : keep('failedTerminal')(state, event);\n};\n\nconst checkThenRetryAbsent: Handler = (state, event) =>\n state.context.attempts < state.context.maxAttempts\n ? toSigning(state, event)\n : keep('failedRetryable')(state, event);\n\nconst TABLE: Partial<\n Record<WalletRegistrationStatus, Partial<Record<EventType, Handler>>>\n> = {\n idle: {\n START: toPreparing,\n },\n preparing: {\n LOOKUP_ACTIVE: toAlreadyRegistered,\n LOOKUP_DISABLED: toRegisteredDisabled,\n LOOKUP_ABSENT: toSigning,\n LOOKUP_FAILED: toLookupUnavailable,\n },\n awaitingUnlock: {\n WALLET_UNLOCKED: keep('signing'),\n },\n signing: {\n SIGN_OK: keep('submitting'),\n SIGN_REJECTED: toCancelled,\n SIGN_FAILED: signFailed,\n WALLET_LOCKED: keep('awaitingUnlock'),\n CANCEL: toCancelled,\n },\n submitting: {\n SUBMIT_OK: keep('registered'),\n SUBMIT_CONFLICT: keep('disambiguate409'),\n SUBMIT_TRANSIENT: keep('checkThenRetry'),\n SUBMIT_VALIDATION: submitValidation,\n SUBMIT_TERMINAL: keep('failedTerminal'),\n SUBMIT_RATE_LIMITED: keep('failedRetryable'),\n CANCEL: toCancelled,\n },\n disambiguate409: {\n LOOKUP_ACTIVE: toAlreadyRegistered,\n LOOKUP_DISABLED: toRegisteredDisabled,\n LOOKUP_ABSENT: keep('failedRetryable'),\n LOOKUP_FAILED: toLookupUnavailable,\n CANCEL: toCancelled,\n },\n checkThenRetry: {\n LOOKUP_ACTIVE: toAlreadyRegistered,\n LOOKUP_DISABLED: toRegisteredDisabled,\n LOOKUP_ABSENT: checkThenRetryAbsent,\n LOOKUP_FAILED: toLookupUnavailable,\n CANCEL: toCancelled,\n },\n failedRetryable: {\n RETRY: toPreparing,\n },\n lookupUnavailable: {\n RETRY: toPreparing,\n },\n cancelled: {\n RETRY: toPreparing,\n },\n};\n\n/**\n * Pure transition reducer. Unhandled (state, event) pairs are no-ops, which is\n * how the machine enforces \"one in-flight operation\" (a second `START` while\n * busy is ignored) and how terminal states stay put.\n *\n * @param state - Current machine state.\n * @param event - Event to apply.\n * @returns The next state (or the same state for unhandled events).\n */\nexport function transition(\n state: WalletRegistrationState,\n event: WalletRegistrationEvent,\n): WalletRegistrationState {\n const handler = TABLE[state.status]?.[event.type];\n return handler ? handler(state, event) : state;\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"wallet-registration-machine.d.cts","sourceRoot":"","sources":["../src/wallet-registration-machine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,uCAAuC;AACvC,MAAM,MAAM,wBAAwB,GAChC,MAAM,GACN,WAAW,GACX,gBAAgB,GAChB,SAAS,GACT,YAAY,GACZ,iBAAiB,GACjB,gBAAgB,GAChB,mBAAmB,GACnB,YAAY,GACZ,mBAAmB,GACnB,oBAAoB,GACpB,iBAAiB,GACjB,gBAAgB,GAChB,WAAW,CAAC;AAEhB,kDAAkD;AAClD,MAAM,MAAM,yBAAyB,GAAG;IACtC,wEAAwE;IACxE,QAAQ,EAAE,MAAM,CAAC;IACjB,8EAA8E;IAC9E,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAA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and-rolled finite state machine for the MoonPay Iron self-hosted
3
- * wallet registration signing step. It follows the FSM convention used
4
- * elsewhere in `core` (no XState dependency): a single pure `transition`
5
- * reducer plus a data-driven transition table.
6
- *
7
- * Side effects (server lookups, signing, POSTing) live in the interpreter that
8
- * drives this machine; every effect result is fed back in as an event, so the
9
- * machine itself stays deterministic and trivially testable.
10
- */
11
- /** Every state in the signing step. */
12
- export type WalletRegistrationStatus = 'idle' | 'preparing' | 'awaitingUnlock' | 'signing' | 'submitting' | 'disambiguate409' | 'checkThenRetry' | 'lookupUnavailable' | 'registered' | 'alreadyRegistered' | 'registeredDisabled' | 'failedRetryable' | 'failedTerminal' | 'cancelled';
13
- /** Machine context carried across transitions. */
14
- export type WalletRegistrationContext = {
15
- /** Number of sign attempts made so far (used for the retry ceiling). */
16
- attempts: number;
17
- /** Maximum number of sign attempts before a retryable failure is surfaced. */
18
- maxAttempts: number;
19
- };
20
- export type WalletRegistrationState = {
21
- status: WalletRegistrationStatus;
22
- context: WalletRegistrationContext;
23
- };
24
- /** Events the interpreter dispatches into the machine. */
25
- export type WalletRegistrationEvent = {
26
- type: 'START';
27
- } | {
28
- type: 'WALLET_LOCKED';
29
- } | {
30
- type: 'WALLET_UNLOCKED';
31
- } | {
32
- type: 'LOOKUP_ACTIVE';
33
- } | {
34
- type: 'LOOKUP_DISABLED';
35
- } | {
36
- type: 'LOOKUP_ABSENT';
37
- } | {
38
- type: 'LOOKUP_FAILED';
39
- } | {
40
- type: 'SIGN_OK';
41
- } | {
42
- type: 'SIGN_REJECTED';
43
- } | {
44
- type: 'SIGN_FAILED';
45
- retryable: boolean;
46
- } | {
47
- type: 'SUBMIT_OK';
48
- } | {
49
- type: 'SUBMIT_CONFLICT';
50
- } | {
51
- type: 'SUBMIT_TRANSIENT';
52
- } | {
53
- type: 'SUBMIT_VALIDATION';
54
- utcRollover: boolean;
55
- } | {
56
- type: 'SUBMIT_TERMINAL';
57
- } | {
58
- type: 'SUBMIT_RATE_LIMITED';
59
- } | {
60
- type: 'RETRY';
61
- } | {
62
- type: 'CANCEL';
63
- };
64
- /**
65
- * Creates the initial idle state.
66
- *
67
- * @param maxAttempts - Optional retry ceiling for sign attempts.
68
- * @returns A fresh idle machine state.
69
- */
70
- export declare function createInitialState(maxAttempts?: number): WalletRegistrationState;
71
- /**
72
- * Pure transition reducer. Unhandled (state, event) pairs are no-ops, which is
73
- * how the machine enforces "one in-flight operation" (a second `START` while
74
- * busy is ignored) and how terminal states stay put.
75
- *
76
- * @param state - Current machine state.
77
- * @param event - Event to apply.
78
- * @returns The next state (or the same state for unhandled events).
79
- */
80
- export declare function transition(state: WalletRegistrationState, event: WalletRegistrationEvent): WalletRegistrationState;
81
- //# sourceMappingURL=wallet-registration-machine.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"wallet-registration-machine.d.mts","sourceRoot":"","sources":["../src/wallet-registration-machine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,uCAAuC;AACvC,MAAM,MAAM,wBAAwB,GAChC,MAAM,GACN,WAAW,GACX,gBAAgB,GAChB,SAAS,GACT,YAAY,GACZ,iBAAiB,GACjB,gBAAgB,GAChB,mBAAmB,GACnB,YAAY,GACZ,mBAAmB,GACnB,oBAAoB,GACpB,iBAAiB,GACjB,gBAAgB,GAChB,WAAW,CAAC;AAEhB,kDAAkD;AAClD,MAAM,MAAM,yBAAyB,GAAG;IACtC,wEAAwE;IACxE,QAAQ,EAAE,MAAM,CAAC;IACjB,8EAA8E;IAC9E,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,MAAM,EAAE,wBAAwB,CAAC;IACjC,OAAO,EAAE,yBAAyB,CAAC;CACpC,CAAC;AAEF,0DAA0D;AAC1D,MAAM,MAAM,uBAAuB,GAC/B;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,GACjB;IAAE,IAAI,EAAE,eAAe,CAAA;CAAE,GACzB;IAAE,IAAI,EAAE,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AAE,IAAI,CAAC,gBAAgB,CAAC;QACxC,iBAAiB,EAAE,gBAAgB;QACnC,eAAe,EAAE,IAAI,CAAC,gBAAgB,CAAC;QACvC,mBAAmB,EAAE,IAAI,CAAC,iBAAiB,CAAC;QAC5C,MAAM,EAAE,WAAW;KACpB;IACD,eAAe,EAAE;QACf,aAAa,EAAE,mBAAmB;QAClC,eAAe,EAAE,oBAAoB;QACrC,aAAa,EAAE,IAAI,CAAC,iBAAiB,CAAC;QACtC,aAAa,EAAE,mBAAmB;QAClC,MAAM,EAAE,WAAW;KACpB;IACD,cAAc,EAAE;QACd,aAAa,EAAE,mBAAmB;QAClC,eAAe,EAAE,oBAAoB;QACrC,aAAa,EAAE,oBAAoB;QACnC,aAAa,EAAE,mBAAmB;QAClC,MAAM,EAAE,WAAW;KACpB;IACD,eAAe,EAAE;QACf,KAAK,EAAE,WAAW;KACnB;IACD,iBAAiB,EAAE;QACjB,KAAK,EAAE,WAAW;KACnB;IACD,SAAS,EAAE;QACT,KAAK,EAAE,WAAW;KACnB;CACF,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,UAAU,UAAU,CACxB,KAA8B,EAC9B,KAA8B;IAE9B,MAAM,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAClD,OAAO,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AACjD,CAAC","sourcesContent":["/**\n * Pure, hand-rolled finite state machine for the MoonPay Iron self-hosted\n * wallet registration signing step. It follows the FSM convention used\n * elsewhere in `core` (no XState dependency): a single pure `transition`\n * reducer plus a data-driven transition table.\n *\n * Side effects (server lookups, signing, POSTing) live in the interpreter that\n * drives this machine; every effect result is fed back in as an event, so the\n * machine itself stays deterministic and trivially testable.\n */\n\n/** Every state in the signing step. */\nexport type WalletRegistrationStatus =\n | 'idle'\n | 'preparing'\n | 'awaitingUnlock'\n | 'signing'\n | 'submitting'\n | 'disambiguate409'\n | 'checkThenRetry'\n | 'lookupUnavailable'\n | 'registered'\n | 'alreadyRegistered'\n | 'registeredDisabled'\n | 'failedRetryable'\n | 'failedTerminal'\n | 'cancelled';\n\n/** Machine context carried across transitions. */\nexport type WalletRegistrationContext = {\n /** Number of sign attempts made so far (used for the retry ceiling). */\n attempts: number;\n /** Maximum number of sign attempts before a retryable failure is surfaced. */\n maxAttempts: number;\n};\n\nexport type WalletRegistrationState = {\n status: WalletRegistrationStatus;\n context: WalletRegistrationContext;\n};\n\n/** Events the interpreter dispatches into the machine. */\nexport type WalletRegistrationEvent =\n | { type: 'START' }\n | { type: 'WALLET_LOCKED' }\n | { type: 'WALLET_UNLOCKED' }\n | { type: 'LOOKUP_ACTIVE' }\n | { type: 'LOOKUP_DISABLED' }\n | { type: 'LOOKUP_ABSENT' }\n | { type: 'LOOKUP_FAILED' }\n | { type: 'SIGN_OK' }\n | { type: 'SIGN_REJECTED' }\n | { type: 'SIGN_FAILED'; retryable: boolean }\n | { type: 'SUBMIT_OK' }\n | { type: 'SUBMIT_CONFLICT' }\n | { type: 'SUBMIT_TRANSIENT' }\n | { type: 'SUBMIT_VALIDATION'; utcRollover: boolean }\n | { type: 'SUBMIT_TERMINAL' }\n | { type: 'SUBMIT_RATE_LIMITED' }\n | { type: 'RETRY' }\n | { type: 'CANCEL' };\n\ntype EventType = WalletRegistrationEvent['type'];\n\ntype Handler = (\n state: WalletRegistrationState,\n event: WalletRegistrationEvent,\n) => WalletRegistrationState;\n\nconst DEFAULT_MAX_ATTEMPTS = 3;\n\n/**\n * Creates the initial idle state.\n *\n * @param maxAttempts - Optional retry ceiling for sign attempts.\n * @returns A fresh idle machine state.\n */\nexport function createInitialState(\n maxAttempts: number = DEFAULT_MAX_ATTEMPTS,\n): WalletRegistrationState {\n return { status: 'idle', context: { attempts: 0, maxAttempts } };\n}\n\n/**\n * Builds a handler that moves to a status while preserving context.\n *\n * @param status - Target status.\n * @returns A handler transitioning to `status`.\n */\nfunction keep(status: WalletRegistrationStatus): Handler {\n return (state) => ({ status, context: state.context });\n}\n\n/**\n * Builds a handler that moves to a status and resets the retry context. Used\n * when the user (or app resume) starts a fresh attempt from scratch.\n *\n * @param status - Target status.\n * @returns A handler transitioning to `status` with reset context.\n */\nfunction reset(status: WalletRegistrationStatus): Handler {\n return (state) => ({\n status,\n context: { ...state.context, attempts: 0 },\n });\n}\n\n/**\n * Moves to `signing` and counts this as a new sign attempt.\n *\n * @param state - Current state.\n * @returns The `signing` state with an incremented attempt count.\n */\nconst toSigning: Handler = (state) => ({\n status: 'signing',\n context: { ...state.context, attempts: state.context.attempts + 1 },\n});\n\nconst toPreparing = reset('preparing');\nconst toAlreadyRegistered = keep('alreadyRegistered');\nconst toRegisteredDisabled = keep('registeredDisabled');\nconst toLookupUnavailable = keep('lookupUnavailable');\nconst toCancelled = keep('cancelled');\n\nconst signFailed: Handler = (state, event) => {\n const { retryable } = event as Extract<\n WalletRegistrationEvent,\n { type: 'SIGN_FAILED' }\n >;\n return retryable\n ? keep('failedRetryable')(state, event)\n : keep('failedTerminal')(state, event);\n};\n\nconst submitValidation: Handler = (state, event) => {\n const { utcRollover } = event as Extract<\n WalletRegistrationEvent,\n { type: 'SUBMIT_VALIDATION' }\n >;\n return utcRollover && state.context.attempts < state.context.maxAttempts\n ? toSigning(state, event)\n : keep('failedTerminal')(state, event);\n};\n\nconst checkThenRetryAbsent: Handler = (state, event) =>\n state.context.attempts < state.context.maxAttempts\n ? toSigning(state, event)\n : keep('failedRetryable')(state, event);\n\nconst TABLE: Partial<\n Record<WalletRegistrationStatus, Partial<Record<EventType, Handler>>>\n> = {\n idle: {\n START: toPreparing,\n },\n preparing: {\n LOOKUP_ACTIVE: toAlreadyRegistered,\n LOOKUP_DISABLED: toRegisteredDisabled,\n LOOKUP_ABSENT: toSigning,\n LOOKUP_FAILED: toLookupUnavailable,\n },\n awaitingUnlock: {\n WALLET_UNLOCKED: keep('signing'),\n },\n signing: {\n SIGN_OK: keep('submitting'),\n SIGN_REJECTED: toCancelled,\n SIGN_FAILED: signFailed,\n WALLET_LOCKED: keep('awaitingUnlock'),\n CANCEL: toCancelled,\n },\n submitting: {\n SUBMIT_OK: keep('registered'),\n SUBMIT_CONFLICT: keep('disambiguate409'),\n SUBMIT_TRANSIENT: keep('checkThenRetry'),\n SUBMIT_VALIDATION: submitValidation,\n SUBMIT_TERMINAL: keep('failedTerminal'),\n SUBMIT_RATE_LIMITED: keep('failedRetryable'),\n CANCEL: toCancelled,\n },\n disambiguate409: {\n LOOKUP_ACTIVE: toAlreadyRegistered,\n LOOKUP_DISABLED: toRegisteredDisabled,\n LOOKUP_ABSENT: keep('failedRetryable'),\n LOOKUP_FAILED: toLookupUnavailable,\n CANCEL: toCancelled,\n },\n checkThenRetry: {\n LOOKUP_ACTIVE: toAlreadyRegistered,\n LOOKUP_DISABLED: toRegisteredDisabled,\n LOOKUP_ABSENT: checkThenRetryAbsent,\n LOOKUP_FAILED: toLookupUnavailable,\n CANCEL: toCancelled,\n },\n failedRetryable: {\n RETRY: toPreparing,\n },\n lookupUnavailable: {\n RETRY: toPreparing,\n },\n cancelled: {\n RETRY: toPreparing,\n },\n};\n\n/**\n * Pure transition reducer. Unhandled (state, event) pairs are no-ops, which is\n * how the machine enforces \"one in-flight operation\" (a second `START` while\n * busy is ignored) and how terminal states stay put.\n *\n * @param state - Current machine state.\n * @param event - Event to apply.\n * @returns The next state (or the same state for unhandled events).\n */\nexport function transition(\n state: WalletRegistrationState,\n event: WalletRegistrationEvent,\n): WalletRegistrationState {\n const handler = TABLE[state.status]?.[event.type];\n return handler ? handler(state, event) : state;\n}\n"]}
@@ -1,351 +0,0 @@
1
- "use strict";
2
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
- if (kind === "m") throw new TypeError("Private method is not writable");
4
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
- };
8
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
- };
13
- var _WalletRegistrationService_instances, _WalletRegistrationService_fetch, _WalletRegistrationService_baseUrl, _WalletRegistrationService_getAuthToken, _WalletRegistrationService_getExternalId, _WalletRegistrationService_toHttpError, _WalletRegistrationService_toRegistration;
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.WalletRegistrationService = exports.extractErrorBody = exports.createIdempotencyKey = exports.WalletRegistrationError = void 0;
16
- /** Typed error carrying enough context for state transitions. */
17
- class WalletRegistrationError extends Error {
18
- constructor(kind, options) {
19
- super(options.message ?? `wallet registration failed: ${kind}`);
20
- this.name = 'WalletRegistrationError';
21
- this.kind = kind;
22
- this.httpStatus = options.httpStatus;
23
- this.body = options.body;
24
- }
25
- }
26
- exports.WalletRegistrationError = WalletRegistrationError;
27
- /**
28
- * Normalizes a Monad EVM address for case-insensitive comparison.
29
- *
30
- * @param address - Raw address string.
31
- * @returns The comparison key for the address.
32
- */
33
- function normalizeAddress(address) {
34
- return address.toLowerCase();
35
- }
36
- /**
37
- * Maps an HTTP status to the typed error kind the state machine reacts to.
38
- *
39
- * @param status - HTTP status code from the proxy/Iron response.
40
- * @returns The corresponding error kind.
41
- */
42
- function mapStatusToKind(status) {
43
- switch (status) {
44
- case 400:
45
- return 'validation';
46
- case 401:
47
- return 'unauthorized';
48
- case 403:
49
- return 'forbidden';
50
- case 404:
51
- return 'notFound';
52
- case 409:
53
- return 'conflict';
54
- case 429:
55
- return 'rateLimited';
56
- default:
57
- return status >= 500 ? 'transient' : 'validation';
58
- }
59
- }
60
- /**
61
- * Builds a client-side Idempotency-Key for MoonPay POSTs. Prefer a stable
62
- * caller-supplied key across retries of the same proof.
63
- *
64
- * @returns A random UUID when available, otherwise a timestamped fallback.
65
- */
66
- function createIdempotencyKey() {
67
- const cryptoObj = globalThis.crypto;
68
- if (typeof cryptoObj?.randomUUID === 'function') {
69
- return cryptoObj.randomUUID();
70
- }
71
- return `wallet-reg-${Date.now()}-${Math.random().toString(16).slice(2)}`;
72
- }
73
- exports.createIdempotencyKey = createIdempotencyKey;
74
- /**
75
- * Extracts a human-readable error body from a transparent neobank-proxy
76
- * response. Upstream may return a plain string or a JSON value; both are
77
- * mirrored 1:1 (no `{ code: 'iron_error' }` envelope).
78
- *
79
- * @param raw - Raw response text.
80
- * @returns Normalized body string for {@link WalletRegistrationError}.
81
- */
82
- function extractErrorBody(raw) {
83
- const trimmed = raw.trim();
84
- if (!trimmed) {
85
- return raw;
86
- }
87
- try {
88
- const parsed = JSON.parse(trimmed);
89
- if (typeof parsed === 'string') {
90
- return parsed;
91
- }
92
- if (parsed && typeof parsed === 'object') {
93
- const { message } = parsed;
94
- if (typeof message === 'string') {
95
- return message;
96
- }
97
- }
98
- return trimmed;
99
- }
100
- catch {
101
- return trimmed;
102
- }
103
- }
104
- exports.extractErrorBody = extractErrorBody;
105
- /**
106
- * Data service that talks to the Money Movement neobank-proxy for MoonPay Iron
107
- * self-hosted wallet registration. It never calls Iron directly, so the Iron
108
- * API key never ships in the client.
109
- */
110
- class WalletRegistrationService {
111
- constructor(options) {
112
- _WalletRegistrationService_instances.add(this);
113
- _WalletRegistrationService_fetch.set(this, void 0);
114
- _WalletRegistrationService_baseUrl.set(this, void 0);
115
- _WalletRegistrationService_getAuthToken.set(this, void 0);
116
- _WalletRegistrationService_getExternalId.set(this, void 0);
117
- __classPrivateFieldSet(this, _WalletRegistrationService_fetch, options.fetch, "f");
118
- __classPrivateFieldSet(this, _WalletRegistrationService_baseUrl, options.baseUrl.replace(/\/$/u, ''), "f");
119
- __classPrivateFieldSet(this, _WalletRegistrationService_getAuthToken, options.getAuthToken, "f");
120
- __classPrivateFieldSet(this, _WalletRegistrationService_getExternalId, options.getExternalId, "f");
121
- }
122
- /**
123
- * Resolves Iron's internal customer id via
124
- * `GET /neobank/customers/{external_id}/external`, using the MetaMask
125
- * profile/canonical id as `external_id`.
126
- *
127
- * @returns Iron's internal customer id.
128
- */
129
- async getMoonpayCustomerId() {
130
- const [token, externalId] = await Promise.all([
131
- __classPrivateFieldGet(this, _WalletRegistrationService_getAuthToken, "f").call(this),
132
- __classPrivateFieldGet(this, _WalletRegistrationService_getExternalId, "f").call(this),
133
- ]);
134
- if (!externalId) {
135
- throw new WalletRegistrationError('malformedResponse', {
136
- message: 'MetaMask external id (canonical profile id) is empty',
137
- });
138
- }
139
- const response = await __classPrivateFieldGet(this, _WalletRegistrationService_fetch, "f").call(this, `${__classPrivateFieldGet(this, _WalletRegistrationService_baseUrl, "f")}/neobank/customers/${encodeURIComponent(externalId)}/external`, {
140
- method: 'GET',
141
- headers: {
142
- accept: 'application/json',
143
- authorization: `Bearer ${token}`,
144
- },
145
- });
146
- if (!response.ok) {
147
- throw await __classPrivateFieldGet(this, _WalletRegistrationService_instances, "m", _WalletRegistrationService_toHttpError).call(this, response);
148
- }
149
- let payload;
150
- try {
151
- payload = await response.json();
152
- }
153
- catch {
154
- throw new WalletRegistrationError('malformedResponse', {
155
- message: 'MoonPay customer body was not valid JSON',
156
- });
157
- }
158
- const { id } = payload;
159
- if (typeof id !== 'string' || id.length === 0) {
160
- throw new WalletRegistrationError('malformedResponse', {
161
- message: 'MoonPay customer body missing id',
162
- });
163
- }
164
- return id;
165
- }
166
- /**
167
- * Reconciles a wallet against the customer's registered self-hosted addresses
168
- * via `GET /neobank/addresses/crypto/{customer_id}?filter=SelfHosted`.
169
- * Upstream returns all self-hosted chains; Monad filtering stays client-side
170
- * for the POC. Transport failures are reported as `lookupUnavailable`;
171
- * malformed successful responses are reported as `malformedResponse`.
172
- * Neither is downgraded to `absent`.
173
- *
174
- * @param request - Customer id and Monad address to reconcile.
175
- * @returns The active / disabled / absent status for the address.
176
- */
177
- async getRegistrationStatus(request) {
178
- const { customerId, address, blockchain } = request;
179
- let response;
180
- try {
181
- const token = await __classPrivateFieldGet(this, _WalletRegistrationService_getAuthToken, "f").call(this);
182
- const url = new URL(`${__classPrivateFieldGet(this, _WalletRegistrationService_baseUrl, "f")}/neobank/addresses/crypto/${encodeURIComponent(customerId)}`);
183
- url.searchParams.set('filter', 'SelfHosted');
184
- response = await __classPrivateFieldGet(this, _WalletRegistrationService_fetch, "f").call(this, url.toString(), {
185
- method: 'GET',
186
- headers: {
187
- accept: 'application/json',
188
- authorization: `Bearer ${token}`,
189
- },
190
- });
191
- }
192
- catch (error) {
193
- throw new WalletRegistrationError('lookupUnavailable', {
194
- message: 'self-hosted address lookup failed',
195
- body: error instanceof Error ? error.message : undefined,
196
- });
197
- }
198
- if (!response.ok) {
199
- let body;
200
- try {
201
- body = extractErrorBody(await response.text());
202
- }
203
- catch (error) {
204
- body = error instanceof Error ? error.message : '';
205
- }
206
- throw new WalletRegistrationError('lookupUnavailable', {
207
- httpStatus: response.status,
208
- body,
209
- });
210
- }
211
- let payload;
212
- try {
213
- payload = await response.json();
214
- }
215
- catch {
216
- throw new WalletRegistrationError('malformedResponse', {
217
- message: 'self-hosted address list body was not valid JSON',
218
- });
219
- }
220
- if (!Array.isArray(payload)) {
221
- throw new WalletRegistrationError('malformedResponse', {
222
- message: 'expected an array of registered addresses',
223
- });
224
- }
225
- const target = normalizeAddress(address);
226
- const match = payload.find((entry) => {
227
- const record = entry;
228
- const walletAddress = record.wallet_address;
229
- if (typeof walletAddress !== 'string') {
230
- return false;
231
- }
232
- return (normalizeAddress(walletAddress) === target &&
233
- record.blockchain === blockchain);
234
- });
235
- if (!match) {
236
- return { type: 'absent' };
237
- }
238
- const registration = __classPrivateFieldGet(this, _WalletRegistrationService_instances, "m", _WalletRegistrationService_toRegistration).call(this, match);
239
- return registration.disabled
240
- ? { type: 'disabled', registration }
241
- : { type: 'active', registration };
242
- }
243
- /**
244
- * Registers a self-hosted wallet through neobank-proxy
245
- * `POST /neobank/addresses/crypto/selfhosted`. The client supplies
246
- * `customer_id` and an `Idempotency-Key` (generated when omitted). Every
247
- * non-2xx response is mapped to a typed error; `409` is deliberately
248
- * surfaced as an ambiguous `conflict` that the caller must reconcile with a
249
- * follow-up status lookup.
250
- *
251
- * @param request - Customer id, address, blockchain, message, and signature.
252
- * @returns The registered outcome on success.
253
- */
254
- async registerSelfHostedWallet(request) {
255
- const idempotencyKey = request.idempotencyKey ?? createIdempotencyKey();
256
- let response;
257
- try {
258
- const token = await __classPrivateFieldGet(this, _WalletRegistrationService_getAuthToken, "f").call(this);
259
- response = await __classPrivateFieldGet(this, _WalletRegistrationService_fetch, "f").call(this, `${__classPrivateFieldGet(this, _WalletRegistrationService_baseUrl, "f")}/neobank/addresses/crypto/selfhosted`, {
260
- method: 'POST',
261
- headers: {
262
- accept: 'application/json',
263
- 'content-type': 'application/json',
264
- authorization: `Bearer ${token}`,
265
- 'Idempotency-Key': idempotencyKey,
266
- },
267
- body: JSON.stringify({
268
- customer_id: request.customerId,
269
- address: request.address,
270
- blockchain: request.blockchain,
271
- message: request.message,
272
- signature: request.signature,
273
- }),
274
- });
275
- }
276
- catch (error) {
277
- throw new WalletRegistrationError('transient', {
278
- message: 'self-hosted registration request failed',
279
- body: error instanceof Error ? error.message : undefined,
280
- });
281
- }
282
- if (!response.ok) {
283
- throw await __classPrivateFieldGet(this, _WalletRegistrationService_instances, "m", _WalletRegistrationService_toHttpError).call(this, response);
284
- }
285
- let payload;
286
- try {
287
- payload = await response.json();
288
- }
289
- catch {
290
- throw new WalletRegistrationError('malformedResponse', {
291
- message: 'registration success body was not valid JSON',
292
- });
293
- }
294
- const record = payload;
295
- if (typeof record.id !== 'string' || typeof record.address !== 'string') {
296
- throw new WalletRegistrationError('malformedResponse', {
297
- message: 'registration success body missing id/address',
298
- });
299
- }
300
- return {
301
- type: 'registered',
302
- registration: {
303
- id: record.id,
304
- address: record.address,
305
- blockchain: request.blockchain,
306
- disabled: Boolean(record.disabled),
307
- isSelf: true,
308
- },
309
- };
310
- }
311
- }
312
- exports.WalletRegistrationService = WalletRegistrationService;
313
- _WalletRegistrationService_fetch = new WeakMap(), _WalletRegistrationService_baseUrl = new WeakMap(), _WalletRegistrationService_getAuthToken = new WeakMap(), _WalletRegistrationService_getExternalId = new WeakMap(), _WalletRegistrationService_instances = new WeakSet(), _WalletRegistrationService_toHttpError = async function _WalletRegistrationService_toHttpError(response) {
314
- let raw = '';
315
- try {
316
- raw = await response.text();
317
- }
318
- catch {
319
- return new WalletRegistrationError('malformedResponse', {
320
- httpStatus: response.status,
321
- message: 'error body could not be read',
322
- });
323
- }
324
- const { status } = response;
325
- const kind = mapStatusToKind(status);
326
- const body = extractErrorBody(raw);
327
- return new WalletRegistrationError(kind, {
328
- httpStatus: status,
329
- body,
330
- message: body || undefined,
331
- });
332
- }, _WalletRegistrationService_toRegistration = function _WalletRegistrationService_toRegistration(record) {
333
- if (typeof record.id !== 'string' || record.id.length === 0) {
334
- throw new WalletRegistrationError('malformedResponse', {
335
- message: 'registered address missing id',
336
- });
337
- }
338
- if (typeof record.wallet_address !== 'string') {
339
- throw new WalletRegistrationError('malformedResponse', {
340
- message: 'registered address missing wallet_address',
341
- });
342
- }
343
- return {
344
- id: record.id,
345
- address: record.wallet_address,
346
- blockchain: 'Monad',
347
- disabled: Boolean(record.disabled),
348
- isSelf: Boolean(record.is_self),
349
- };
350
- };
351
- //# sourceMappingURL=wallet-registration-service.cjs.map