@bitgen/sdk 0.1.5 → 1.0.3

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 (328) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/README.md +27 -106
  3. package/dist/cjs/client.d.ts +20 -8
  4. package/dist/cjs/client.d.ts.map +1 -1
  5. package/dist/cjs/client.js +33 -12
  6. package/dist/cjs/client.js.map +1 -1
  7. package/dist/cjs/constants.d.ts +256 -0
  8. package/dist/cjs/constants.d.ts.map +1 -0
  9. package/dist/cjs/constants.js +214 -0
  10. package/dist/cjs/constants.js.map +1 -0
  11. package/dist/cjs/error.d.ts +17 -10
  12. package/dist/cjs/error.d.ts.map +1 -1
  13. package/dist/cjs/error.js +25 -7
  14. package/dist/cjs/error.js.map +1 -1
  15. package/dist/cjs/http.d.ts +13 -8
  16. package/dist/cjs/http.d.ts.map +1 -1
  17. package/dist/cjs/http.js +135 -43
  18. package/dist/cjs/http.js.map +1 -1
  19. package/dist/cjs/index.d.ts +14 -1
  20. package/dist/cjs/index.d.ts.map +1 -1
  21. package/dist/cjs/index.js +30 -1
  22. package/dist/cjs/index.js.map +1 -1
  23. package/dist/cjs/resources/apikeys.d.ts +18 -0
  24. package/dist/cjs/resources/apikeys.d.ts.map +1 -0
  25. package/dist/cjs/resources/apikeys.js +31 -0
  26. package/dist/cjs/resources/apikeys.js.map +1 -0
  27. package/dist/cjs/resources/asset.d.ts +17 -5
  28. package/dist/cjs/resources/asset.d.ts.map +1 -1
  29. package/dist/cjs/resources/asset.js +17 -6
  30. package/dist/cjs/resources/asset.js.map +1 -1
  31. package/dist/cjs/resources/bank.d.ts +11 -6
  32. package/dist/cjs/resources/bank.d.ts.map +1 -1
  33. package/dist/cjs/resources/bank.js +17 -9
  34. package/dist/cjs/resources/bank.js.map +1 -1
  35. package/dist/cjs/resources/core.d.ts +12 -0
  36. package/dist/cjs/resources/core.d.ts.map +1 -0
  37. package/dist/cjs/resources/core.js +22 -0
  38. package/dist/cjs/resources/core.js.map +1 -0
  39. package/dist/cjs/resources/custody.d.ts +27 -0
  40. package/dist/cjs/resources/custody.d.ts.map +1 -0
  41. package/dist/cjs/resources/custody.js +38 -0
  42. package/dist/cjs/resources/custody.js.map +1 -0
  43. package/dist/cjs/resources/customer.d.ts +20 -0
  44. package/dist/cjs/resources/customer.d.ts.map +1 -0
  45. package/dist/cjs/resources/customer.js +38 -0
  46. package/dist/cjs/resources/customer.js.map +1 -0
  47. package/dist/cjs/resources/staking.d.ts +32 -0
  48. package/dist/cjs/resources/staking.d.ts.map +1 -0
  49. package/dist/cjs/resources/staking.js +69 -0
  50. package/dist/cjs/resources/staking.js.map +1 -0
  51. package/dist/cjs/resources/trading.d.ts +24 -0
  52. package/dist/cjs/resources/trading.d.ts.map +1 -0
  53. package/dist/cjs/resources/trading.js +41 -0
  54. package/dist/cjs/resources/trading.js.map +1 -0
  55. package/dist/cjs/resources/transaction.d.ts +6 -9
  56. package/dist/cjs/resources/transaction.d.ts.map +1 -1
  57. package/dist/cjs/resources/transaction.js +10 -15
  58. package/dist/cjs/resources/transaction.js.map +1 -1
  59. package/dist/cjs/resources/webhooks.d.ts +46 -0
  60. package/dist/cjs/resources/webhooks.d.ts.map +1 -0
  61. package/dist/cjs/resources/webhooks.js +142 -0
  62. package/dist/cjs/resources/webhooks.js.map +1 -0
  63. package/dist/cjs/types/apikeys.d.ts +43 -0
  64. package/dist/cjs/types/apikeys.d.ts.map +1 -0
  65. package/dist/cjs/types/apikeys.js +3 -0
  66. package/dist/cjs/types/apikeys.js.map +1 -0
  67. package/dist/cjs/types/asset.d.ts +57 -0
  68. package/dist/cjs/types/asset.d.ts.map +1 -0
  69. package/dist/cjs/types/asset.js +3 -0
  70. package/dist/cjs/types/asset.js.map +1 -0
  71. package/dist/cjs/types/bank.d.ts +58 -0
  72. package/dist/cjs/types/bank.d.ts.map +1 -0
  73. package/dist/cjs/types/bank.js +3 -0
  74. package/dist/cjs/types/bank.js.map +1 -0
  75. package/dist/cjs/types/core.d.ts +32 -0
  76. package/dist/cjs/types/core.d.ts.map +1 -0
  77. package/dist/cjs/types/core.js +3 -0
  78. package/dist/cjs/types/core.js.map +1 -0
  79. package/dist/cjs/types/custody.d.ts +50 -0
  80. package/dist/cjs/types/custody.d.ts.map +1 -0
  81. package/dist/cjs/types/custody.js +3 -0
  82. package/dist/cjs/types/custody.js.map +1 -0
  83. package/dist/cjs/types/customer.d.ts +190 -0
  84. package/dist/cjs/types/customer.d.ts.map +1 -0
  85. package/dist/cjs/types/customer.js +3 -0
  86. package/dist/cjs/types/customer.js.map +1 -0
  87. package/dist/cjs/types/index.d.ts +79 -194
  88. package/dist/cjs/types/index.d.ts.map +1 -1
  89. package/dist/cjs/types/index.js +0 -1
  90. package/dist/cjs/types/index.js.map +1 -1
  91. package/dist/cjs/types/staking.d.ts +88 -0
  92. package/dist/cjs/types/staking.d.ts.map +1 -0
  93. package/dist/cjs/types/staking.js +3 -0
  94. package/dist/cjs/types/staking.js.map +1 -0
  95. package/dist/cjs/types/trading.d.ts +51 -0
  96. package/dist/cjs/types/trading.d.ts.map +1 -0
  97. package/dist/cjs/types/trading.js +3 -0
  98. package/dist/cjs/types/trading.js.map +1 -0
  99. package/dist/cjs/types/transaction.d.ts +61 -0
  100. package/dist/cjs/types/transaction.d.ts.map +1 -0
  101. package/dist/cjs/types/transaction.js +3 -0
  102. package/dist/cjs/types/transaction.js.map +1 -0
  103. package/dist/cjs/types/webhooks.d.ts +55 -0
  104. package/dist/cjs/types/webhooks.d.ts.map +1 -0
  105. package/dist/cjs/types/webhooks.js +3 -0
  106. package/dist/cjs/types/webhooks.js.map +1 -0
  107. package/dist/cjs/utils.d.ts +21 -2
  108. package/dist/cjs/utils.d.ts.map +1 -1
  109. package/dist/cjs/utils.js +67 -4
  110. package/dist/cjs/utils.js.map +1 -1
  111. package/dist/cjs/version.d.ts +2 -0
  112. package/dist/cjs/version.d.ts.map +1 -0
  113. package/dist/cjs/version.js +6 -0
  114. package/dist/cjs/version.js.map +1 -0
  115. package/dist/esm/client.d.ts +20 -8
  116. package/dist/esm/client.d.ts.map +1 -1
  117. package/dist/esm/client.js +33 -12
  118. package/dist/esm/client.js.map +1 -1
  119. package/dist/esm/constants.d.ts +256 -0
  120. package/dist/esm/constants.d.ts.map +1 -0
  121. package/dist/esm/constants.js +211 -0
  122. package/dist/esm/constants.js.map +1 -0
  123. package/dist/esm/error.d.ts +17 -10
  124. package/dist/esm/error.d.ts.map +1 -1
  125. package/dist/esm/error.js +24 -6
  126. package/dist/esm/error.js.map +1 -1
  127. package/dist/esm/http.d.ts +13 -8
  128. package/dist/esm/http.d.ts.map +1 -1
  129. package/dist/esm/http.js +136 -44
  130. package/dist/esm/http.js.map +1 -1
  131. package/dist/esm/index.d.ts +14 -1
  132. package/dist/esm/index.d.ts.map +1 -1
  133. package/dist/esm/index.js +6 -0
  134. package/dist/esm/index.js.map +1 -1
  135. package/dist/esm/resources/apikeys.d.ts +18 -0
  136. package/dist/esm/resources/apikeys.d.ts.map +1 -0
  137. package/dist/esm/resources/apikeys.js +27 -0
  138. package/dist/esm/resources/apikeys.js.map +1 -0
  139. package/dist/esm/resources/asset.d.ts +17 -5
  140. package/dist/esm/resources/asset.d.ts.map +1 -1
  141. package/dist/esm/resources/asset.js +17 -6
  142. package/dist/esm/resources/asset.js.map +1 -1
  143. package/dist/esm/resources/bank.d.ts +11 -6
  144. package/dist/esm/resources/bank.d.ts.map +1 -1
  145. package/dist/esm/resources/bank.js +18 -10
  146. package/dist/esm/resources/bank.js.map +1 -1
  147. package/dist/esm/resources/core.d.ts +12 -0
  148. package/dist/esm/resources/core.d.ts.map +1 -0
  149. package/dist/esm/resources/core.js +18 -0
  150. package/dist/esm/resources/core.js.map +1 -0
  151. package/dist/esm/resources/custody.d.ts +27 -0
  152. package/dist/esm/resources/custody.d.ts.map +1 -0
  153. package/dist/esm/resources/custody.js +34 -0
  154. package/dist/esm/resources/custody.js.map +1 -0
  155. package/dist/esm/resources/customer.d.ts +20 -0
  156. package/dist/esm/resources/customer.d.ts.map +1 -0
  157. package/dist/esm/resources/customer.js +34 -0
  158. package/dist/esm/resources/customer.js.map +1 -0
  159. package/dist/esm/resources/staking.d.ts +32 -0
  160. package/dist/esm/resources/staking.d.ts.map +1 -0
  161. package/dist/esm/resources/staking.js +65 -0
  162. package/dist/esm/resources/staking.js.map +1 -0
  163. package/dist/esm/resources/trading.d.ts +24 -0
  164. package/dist/esm/resources/trading.d.ts.map +1 -0
  165. package/dist/esm/resources/trading.js +37 -0
  166. package/dist/esm/resources/trading.js.map +1 -0
  167. package/dist/esm/resources/transaction.d.ts +6 -9
  168. package/dist/esm/resources/transaction.d.ts.map +1 -1
  169. package/dist/esm/resources/transaction.js +11 -16
  170. package/dist/esm/resources/transaction.js.map +1 -1
  171. package/dist/esm/resources/webhooks.d.ts +46 -0
  172. package/dist/esm/resources/webhooks.d.ts.map +1 -0
  173. package/dist/esm/resources/webhooks.js +138 -0
  174. package/dist/esm/resources/webhooks.js.map +1 -0
  175. package/dist/esm/types/apikeys.d.ts +43 -0
  176. package/dist/esm/types/apikeys.d.ts.map +1 -0
  177. package/dist/esm/types/apikeys.js +2 -0
  178. package/dist/esm/types/apikeys.js.map +1 -0
  179. package/dist/esm/types/asset.d.ts +57 -0
  180. package/dist/esm/types/asset.d.ts.map +1 -0
  181. package/dist/esm/types/asset.js +2 -0
  182. package/dist/esm/types/asset.js.map +1 -0
  183. package/dist/esm/types/bank.d.ts +58 -0
  184. package/dist/esm/types/bank.d.ts.map +1 -0
  185. package/dist/esm/types/bank.js +2 -0
  186. package/dist/esm/types/bank.js.map +1 -0
  187. package/dist/esm/types/core.d.ts +32 -0
  188. package/dist/esm/types/core.d.ts.map +1 -0
  189. package/dist/esm/types/core.js +2 -0
  190. package/dist/esm/types/core.js.map +1 -0
  191. package/dist/esm/types/custody.d.ts +50 -0
  192. package/dist/esm/types/custody.d.ts.map +1 -0
  193. package/dist/esm/types/custody.js +2 -0
  194. package/dist/esm/types/custody.js.map +1 -0
  195. package/dist/esm/types/customer.d.ts +190 -0
  196. package/dist/esm/types/customer.d.ts.map +1 -0
  197. package/dist/esm/types/customer.js +2 -0
  198. package/dist/esm/types/customer.js.map +1 -0
  199. package/dist/esm/types/index.d.ts +79 -194
  200. package/dist/esm/types/index.d.ts.map +1 -1
  201. package/dist/esm/types/index.js +0 -1
  202. package/dist/esm/types/index.js.map +1 -1
  203. package/dist/esm/types/staking.d.ts +88 -0
  204. package/dist/esm/types/staking.d.ts.map +1 -0
  205. package/dist/esm/types/staking.js +2 -0
  206. package/dist/esm/types/staking.js.map +1 -0
  207. package/dist/esm/types/trading.d.ts +51 -0
  208. package/dist/esm/types/trading.d.ts.map +1 -0
  209. package/dist/esm/types/trading.js +2 -0
  210. package/dist/esm/types/trading.js.map +1 -0
  211. package/dist/esm/types/transaction.d.ts +61 -0
  212. package/dist/esm/types/transaction.d.ts.map +1 -0
  213. package/dist/esm/types/transaction.js +2 -0
  214. package/dist/esm/types/transaction.js.map +1 -0
  215. package/dist/esm/types/webhooks.d.ts +55 -0
  216. package/dist/esm/types/webhooks.d.ts.map +1 -0
  217. package/dist/esm/types/webhooks.js +2 -0
  218. package/dist/esm/types/webhooks.js.map +1 -0
  219. package/dist/esm/utils.d.ts +21 -2
  220. package/dist/esm/utils.d.ts.map +1 -1
  221. package/dist/esm/utils.js +62 -4
  222. package/dist/esm/utils.js.map +1 -1
  223. package/dist/esm/version.d.ts +2 -0
  224. package/dist/esm/version.d.ts.map +1 -0
  225. package/dist/esm/version.js +3 -0
  226. package/dist/esm/version.js.map +1 -0
  227. package/package.json +29 -12
  228. package/readme/concepts.md +104 -0
  229. package/readme/configuration.md +72 -0
  230. package/readme/errors.md +67 -0
  231. package/readme/installation.md +43 -0
  232. package/readme/quick-start.md +87 -0
  233. package/readme/resource/apikeys.md +103 -0
  234. package/readme/resource/asset.md +121 -0
  235. package/readme/resource/bank.md +156 -0
  236. package/readme/resource/core.md +91 -0
  237. package/readme/resource/custody.md +166 -0
  238. package/readme/resource/customer.md +208 -0
  239. package/readme/resource/staking.md +277 -0
  240. package/readme/resource/trading.md +166 -0
  241. package/readme/resource/transaction.md +106 -0
  242. package/readme/resource/webhooks.md +307 -0
  243. package/src/client.ts +46 -0
  244. package/src/constants.ts +281 -0
  245. package/src/error.ts +36 -0
  246. package/src/http.ts +201 -0
  247. package/src/index.ts +111 -0
  248. package/src/resources/apikeys.ts +30 -0
  249. package/src/resources/asset.ts +28 -0
  250. package/src/resources/bank.ts +39 -0
  251. package/src/resources/core.ts +19 -0
  252. package/src/resources/custody.ts +37 -0
  253. package/src/resources/customer.ts +46 -0
  254. package/src/resources/staking.ts +88 -0
  255. package/src/resources/trading.ts +41 -0
  256. package/src/resources/transaction.ts +20 -0
  257. package/src/resources/webhooks.ts +169 -0
  258. package/src/types/apikeys.ts +35 -0
  259. package/src/types/asset.ts +59 -0
  260. package/src/types/bank.ts +60 -0
  261. package/src/types/core.ts +32 -0
  262. package/src/types/custody.ts +40 -0
  263. package/src/types/customer.ts +189 -0
  264. package/src/types/index.ts +215 -0
  265. package/src/types/staking.ts +87 -0
  266. package/src/types/trading.ts +56 -0
  267. package/src/types/transaction.ts +62 -0
  268. package/src/types/webhooks.ts +60 -0
  269. package/src/utils.ts +74 -0
  270. package/src/version.ts +2 -0
  271. package/dist/cjs/resources/order.d.ts +0 -17
  272. package/dist/cjs/resources/order.d.ts.map +0 -1
  273. package/dist/cjs/resources/order.js +0 -30
  274. package/dist/cjs/resources/order.js.map +0 -1
  275. package/dist/cjs/resources/stats.d.ts +0 -11
  276. package/dist/cjs/resources/stats.d.ts.map +0 -1
  277. package/dist/cjs/resources/stats.js +0 -18
  278. package/dist/cjs/resources/stats.js.map +0 -1
  279. package/dist/cjs/resources/user.d.ts +0 -22
  280. package/dist/cjs/resources/user.d.ts.map +0 -1
  281. package/dist/cjs/resources/user.js +0 -37
  282. package/dist/cjs/resources/user.js.map +0 -1
  283. package/dist/cjs/resources/wallet.d.ts +0 -11
  284. package/dist/cjs/resources/wallet.d.ts.map +0 -1
  285. package/dist/cjs/resources/wallet.js +0 -19
  286. package/dist/cjs/resources/wallet.js.map +0 -1
  287. package/dist/esm/resources/order.d.ts +0 -17
  288. package/dist/esm/resources/order.d.ts.map +0 -1
  289. package/dist/esm/resources/order.js +0 -26
  290. package/dist/esm/resources/order.js.map +0 -1
  291. package/dist/esm/resources/stats.d.ts +0 -11
  292. package/dist/esm/resources/stats.d.ts.map +0 -1
  293. package/dist/esm/resources/stats.js +0 -14
  294. package/dist/esm/resources/stats.js.map +0 -1
  295. package/dist/esm/resources/user.d.ts +0 -22
  296. package/dist/esm/resources/user.d.ts.map +0 -1
  297. package/dist/esm/resources/user.js +0 -33
  298. package/dist/esm/resources/user.js.map +0 -1
  299. package/dist/esm/resources/wallet.d.ts +0 -11
  300. package/dist/esm/resources/wallet.d.ts.map +0 -1
  301. package/dist/esm/resources/wallet.js +0 -15
  302. package/dist/esm/resources/wallet.js.map +0 -1
  303. package/dist/types/client.d.ts +0 -19
  304. package/dist/types/client.d.ts.map +0 -1
  305. package/dist/types/error.d.ts +0 -15
  306. package/dist/types/error.d.ts.map +0 -1
  307. package/dist/types/http.d.ts +0 -21
  308. package/dist/types/http.d.ts.map +0 -1
  309. package/dist/types/index.d.ts +0 -4
  310. package/dist/types/index.d.ts.map +0 -1
  311. package/dist/types/resources/asset.d.ts +0 -11
  312. package/dist/types/resources/asset.d.ts.map +0 -1
  313. package/dist/types/resources/bank.d.ts +0 -13
  314. package/dist/types/resources/bank.d.ts.map +0 -1
  315. package/dist/types/resources/order.d.ts +0 -17
  316. package/dist/types/resources/order.d.ts.map +0 -1
  317. package/dist/types/resources/stats.d.ts +0 -11
  318. package/dist/types/resources/stats.d.ts.map +0 -1
  319. package/dist/types/resources/transaction.d.ts +0 -15
  320. package/dist/types/resources/transaction.d.ts.map +0 -1
  321. package/dist/types/resources/user.d.ts +0 -22
  322. package/dist/types/resources/user.d.ts.map +0 -1
  323. package/dist/types/resources/wallet.d.ts +0 -11
  324. package/dist/types/resources/wallet.d.ts.map +0 -1
  325. package/dist/types/types/index.d.ts +0 -212
  326. package/dist/types/types/index.d.ts.map +0 -1
  327. package/dist/types/utils.d.ts +0 -7
  328. package/dist/types/utils.d.ts.map +0 -1
@@ -0,0 +1,106 @@
1
+ # Transactions
2
+
3
+ The transaction journal is the unified, read-only record of the fiat and crypto movements of your organization: bank deposits and withdrawals, custody deposits and withdrawals, and the internal legs of sales and staking. Transactions are created by the platform — never through the API — and referenced by the other resources: `bank.withdraw` and `custody.withdraw` return the uuid of the transaction they create. `client.transaction` lists and reads them.
4
+
5
+ Examples use `client`, a configured `BitgenClient` ([Configuration](../configuration.md)).
6
+
7
+ ## Methods
8
+
9
+ | Method | What it does | Returns |
10
+ |---|---|---|
11
+ | `list(params?)` | Lists the transactions of your organization | `Page<Transaction>` |
12
+ | `get(transaction)` | Reads one transaction, by uuid or reference | `Transaction` |
13
+
14
+ TypeScript types of this resource, exported by the package: `TransactionAlert`, `Transaction`, `TransactionListParams` — the constants `TransactionState`, `TransactionSource`, `TransactionDirection` (also types) — plus the shared `UserRef`, `UserSummary`, `OrganizationSummary`, `OrganizationHub`, `AssetInput`, `Page`.
15
+
16
+ ## list
17
+
18
+ ```
19
+ client.transaction.list(params?: TransactionListParams): Promise<Page<Transaction>>
20
+ ```
21
+
22
+ | Parameter | Type | Description |
23
+ |---|---|---|
24
+ | `params.user` | `UserRef` | Only the transactions of this customer (uuid or model; unknown → `404 unknown_user`) |
25
+ | `params.status` | `TransactionState` | Only this state: `TransactionState.ANALYZING`, `PENDING`, `COMPLETED`, `FROZEN`, `FAILED`, `TRANSFERING` or `SEIZED` — anything else → `400 invalid_transaction_state` |
26
+ | `params.source` | `TransactionSource` | `TransactionSource.BANK` or `TransactionSource.CUSTODY` |
27
+ | `params.direction` | `TransactionDirection` | `TransactionDirection.IN` or `TransactionDirection.OUT` |
28
+ | `params.asset` | `AssetInput` | Only this asset, by ISO code (`Asset.ETH`), uuid or model |
29
+ | `params.offset`, `params.limit` | `number` | [Pagination](../concepts.md#pagination) — `limit` up to 100 on this list |
30
+
31
+ ```ts
32
+ import { Asset, TransactionDirection, TransactionSource, TransactionState } from '@bitgen/sdk'
33
+
34
+ const { count, items } = await client.transaction.list({
35
+ user: 'CUSTOMER_UUID',
36
+ status: TransactionState.PENDING,
37
+ source: TransactionSource.CUSTODY,
38
+ direction: TransactionDirection.IN,
39
+ asset: Asset.ETH,
40
+ offset: 0,
41
+ limit: 100,
42
+ })
43
+
44
+ for (const transaction of items) {
45
+ console.log(transaction.direction, transaction.asset, transaction.amount, transaction.state)
46
+ }
47
+ ```
48
+
49
+ Returns a page of `Transaction`.
50
+
51
+ ## get
52
+
53
+ ```
54
+ client.transaction.get(transaction: string | Transaction): Promise<Transaction>
55
+ ```
56
+
57
+ `transaction` is the uuid of the transaction, its `reference`, or a `Transaction` of `list()`.
58
+
59
+ ```ts
60
+ import { TransactionState } from '@bitgen/sdk'
61
+
62
+ const { transaction } = await client.bank.withdraw('CUSTOMER_UUID', { amount: '50.00' })
63
+
64
+ const withdrawal = await client.transaction.get(transaction)
65
+ console.log(withdrawal.state === TransactionState.PENDING) // true
66
+ ```
67
+
68
+ Returns a `Transaction`:
69
+
70
+ | Field | Description |
71
+ |---|---|
72
+ | `uuid` | The transaction |
73
+ | `state` | `TransactionState.ANALYZING`, `PENDING`, `COMPLETED`, `FROZEN`, `FAILED`, `TRANSFERING` or `SEIZED` |
74
+ | `source` | `TransactionSource.BANK` (EUR) or `TransactionSource.CUSTODY` (crypto) |
75
+ | `direction` | `TransactionDirection.IN` or `TransactionDirection.OUT` |
76
+ | `asset` | The asset iso — `EUR` for bank transactions |
77
+ | `amount` | The amount, in that asset (a number — for crypto, the exact amount is the string held by the custody wallet) |
78
+ | `eurValue` | EUR value when recorded, or `null` |
79
+ | `reference` | The reference, or `null` |
80
+ | `credited` | Whether the customer's balance (EUR account or wallet) has been credited |
81
+ | `silent` | `true` for an internal leg (staking, sale) that is not an operation of the customer |
82
+ | `data` | Additional context set by the platform (compliance details, internal flags) — varies with the transaction, not needed for an integration |
83
+ | `createdAt`, `updatedAt` | Epoch seconds |
84
+ | `owner` | The customer, a `UserSummary`: `{ uuid, state, login, account: { firstname, lastname, fin } }` — a `UserRef` — or `null` |
85
+ | `assignee` | The compliance officer assigned while the transaction is on hold (`PENDING`, `FROZEN`), same shape as `owner`; `null` otherwise |
86
+ | `organization` | `OrganizationSummary` with its `hub`: `{ uuid, state, name, hub }` — `hub` is the hub the organization belongs to (`OrganizationHub`, `{ uuid, name }`, or `null`) — or `null` |
87
+ | `alert` | The compliance alert attached to the transaction (`TransactionAlert`), or `null`: `uuid`, `state` (`OPEN`, `RESOLVED`, `DISMISSED`, `DECLARATED`, `CONFIRMED`), `severity` (`SUCCESS`, `WARNING`, `CRITICAL`), `type` (`KYT`, `KYC_EXPIRE`, `SUSPICIOUS_ACTIVITY`, `AML`, `SANCTIONS`), `description`, `confidence` (confidence of the analysis, 0–100), `recommendation` (suggested action), `factors` (elements that weighed in the analysis), `sources` (the observations analysed), `history` (state changes of the alert), `incidentKey` (groups the alerts of a same incident), `createdAt`, `updatedAt`, `user` (the customer), `assignee` (the compliance officer), `organization` |
88
+
89
+ An unknown uuid or reference, or a transaction outside your organization, answers `404 unknown_transaction`.
90
+
91
+ ## Errors
92
+
93
+ In addition to the [common errors](../errors.md#common-errors):
94
+
95
+ | Status | `code` | Meaning |
96
+ |---|---|---|
97
+ | `400` | `invalid_transaction_state` | `status` is not one of the transaction states |
98
+ | `404` | `unknown_user` | `list`: unknown `user` |
99
+ | `404` | `unknown_transaction` | Unknown uuid or reference, or outside your organization |
100
+
101
+ ## Related
102
+
103
+ - [Bank accounts](bank.md) — EUR withdrawals return a transaction uuid
104
+ - [Custody wallets](custody.md) — on-chain withdrawals return a transaction uuid
105
+ - [Pagination](../concepts.md#pagination) — `limit` up to 100 on this list
106
+ - [Webhooks](webhooks.md) — `bank.transaction`, `custody.transaction`, `alert.opened`, `alert.status`
@@ -0,0 +1,307 @@
1
+ # Webhooks
2
+
3
+ BITGEN pushes the events of your organization — a customer created, an identity validated, a deposit credited, a withdrawal sent, an order executed, a compliance alert… — to an HTTPS endpoint of yours, each delivery signed with a secret shared with you. `client.webhooks` sets up that endpoint and its secret, subscribes your organization to the events of the catalogue, reads the delivery logs, and verifies the deliveries your endpoint receives with `verify`.
4
+
5
+ Examples use `client`, a configured `BitgenClient` ([Configuration](../configuration.md)). Wherever the API expects your organization, the SDK sends the `scope` of the client.
6
+
7
+ ## Methods
8
+
9
+ | Method | What it does | Returns |
10
+ |---|---|---|
11
+ | `activate(params)` | Activates the webhooks of your organization: sets the endpoint, generates the secret | `void` |
12
+ | `updateEndpoint(params)` | Changes the endpoint | `void` |
13
+ | `regenerate()` | Generates a new secret | `void` |
14
+ | `list(params?)` | Reads the secret, the endpoint and the subscriptions of your organization | `WebhookSubscriptions` |
15
+ | `subscribe(event)` | Subscribes your organization to an event of the catalogue | `Created` (the subscription) |
16
+ | `archive(subscriber)` | Archives a subscription: the event is no longer delivered | `void` |
17
+ | `reactivate(subscriber)` | Reactivates an archived subscription | `void` |
18
+ | `logs(subscriber, params?)` | Lists the delivery attempts of a subscription | `Page<DeliveryLog>` |
19
+ | `catalog()` | Lists the events of the catalogue | `Page<WebhookType>` |
20
+ | `catalogItem(webhook)` | Reads one event of the catalogue | `WebhookType` |
21
+ | `verify(input)` | Verifies a delivery received by your endpoint and returns its envelope | `WebhookEvent` |
22
+
23
+ TypeScript types of this resource, exported by the package: `WebhookType`, `Subscriber`, `WebhookSubscriptions`, `DeliveryLog`, `WebhookEvent`, `VerifyInput` — the constants `WebhookEventName`, `SubscriberState` (also types) — plus the shared `Created`, `PageParams`.
24
+
25
+ ## activate
26
+
27
+ ```
28
+ client.webhooks.activate(params: { endpoint: string }): Promise<void>
29
+ ```
30
+
31
+ | Parameter | Type | Description |
32
+ |---|---|---|
33
+ | `params.endpoint` | `string` | The URL BITGEN will deliver the events to — `https://` is added when the scheme is missing; `http://` is refused outside a local environment |
34
+
35
+ ```ts
36
+ await client.webhooks.activate({ endpoint: 'https://example.com/bitgen' })
37
+
38
+ const { secret } = await client.webhooks.list() // the initial secret is read with list(): keep it server-side for `verify`
39
+ ```
40
+
41
+ Activation generates the secret of your organization. `activate` does not return it: the API returns the current secret in `list()` (`secret` field, next to `endpoint` and the subscriptions). Once active, a second activation answers `429 webhook_security_already_enabled`. The API answers with an empty body: the promise resolves with `undefined`.
42
+
43
+ ## updateEndpoint
44
+
45
+ ```
46
+ client.webhooks.updateEndpoint(params: { endpoint: string }): Promise<void>
47
+ ```
48
+
49
+ | Parameter | Type | Description |
50
+ |---|---|---|
51
+ | `params.endpoint` | `string` | The new URL — same rules as `activate` |
52
+
53
+ ```ts
54
+ await client.webhooks.updateEndpoint({ endpoint: 'https://example.com/bitgen/v2' })
55
+ ```
56
+
57
+ Before activation, the API answers `404 unknown_webhook_security`. The promise resolves with `undefined`.
58
+
59
+ ## regenerate
60
+
61
+ ```
62
+ client.webhooks.regenerate(): Promise<void>
63
+ ```
64
+
65
+ ```ts
66
+ await client.webhooks.regenerate() // 1. a new secret is created — it is not returned
67
+
68
+ const { secret } = await client.webhooks.list() // 2. the new secret — configure your receiving endpoint with it, the previous one stops validating immediately
69
+ ```
70
+
71
+ `regenerate()` creates a new secret but does not return it: the API returns the current secret in `list()` (`secret` field, next to `endpoint` and the subscriptions). The deliveries are signed with the new one from then on, the previous one stops validating immediately. Before activation, the API answers `404 unknown_webhook_security`. The promise resolves with `undefined`.
72
+
73
+ ## list
74
+
75
+ ```
76
+ client.webhooks.list(params?: { includeArchived?: boolean }): Promise<WebhookSubscriptions>
77
+ ```
78
+
79
+ | Parameter | Type | Description |
80
+ |---|---|---|
81
+ | `params.includeArchived` | `boolean` | Also returns the `SubscriberState.ARCHIVED` subscriptions — default `false` ([Query booleans](../concepts.md#query-booleans)) |
82
+
83
+ ```ts
84
+ import { SubscriberState } from '@bitgen/sdk'
85
+
86
+ const { secret, endpoint, items } = await client.webhooks.list({ includeArchived: true })
87
+
88
+ for (const subscription of items) {
89
+ console.log(subscription.webhook.name, subscription.state === SubscriberState.ENABLED) // 'custody.sent' true
90
+ }
91
+ ```
92
+
93
+ Returns a `WebhookSubscriptions`:
94
+
95
+ | Field | Description |
96
+ |---|---|
97
+ | `secret` | The secret of your organization, for `verify` |
98
+ | `endpoint` | The URL the events are delivered to |
99
+ | `items` | The subscriptions (`Subscriber`): `uuid`, `state` (`SubscriberState.ENABLED` or `SubscriberState.ARCHIVED`), `updatedAt` (epoch seconds), `webhook` (the event of the catalogue: `uuid`, `state` (a `SubscriberState` too), `name`, `label` — its display names, a raw JSON string `{"fr": "…", "en": "…"}` — and `data`, internal) |
100
+
101
+ Before activation, the API answers `404 unknown_webhook_security`.
102
+
103
+ ## subscribe
104
+
105
+ ```
106
+ client.webhooks.subscribe(event: string | WebhookType): Promise<Created>
107
+ ```
108
+
109
+ | Parameter | Type | Description |
110
+ |---|---|---|
111
+ | `event` | `string` or `WebhookType` | The event, by name (`WebhookEventName.CUSTODY_SENT`), by uuid of the catalogue, or by the `WebhookType` of `catalog()` |
112
+
113
+ ```ts
114
+ import { WebhookEventName } from '@bitgen/sdk'
115
+
116
+ const { uuid } = await client.webhooks.subscribe(WebhookEventName.CUSTODY_SENT)
117
+ ```
118
+
119
+ Returns a `Created` — the uuid of the subscription, for `archive`, `reactivate` and `logs`. A subscription that already exists answers `409 webhook_subscription_already_exists`; an unknown event, `404 unknown_webhook`. The events of the catalogue:
120
+
121
+ | Family | Events |
122
+ |---|---|
123
+ | Customers | `user.created`, `user.identity.started`, `user.identity.pending`, `user.identity.step.validated`, `user.identity.step.rejected`, `user.identity.step.requested`, `user.identity.validated`, `user.identity.renew`, `user.identity.request` |
124
+ | Organizations | `organization.created`, `organization.identity.started`, `organization.identity.pending`, `organization.identity.step.validated`, `organization.identity.step.rejected`, `organization.identity.step.requested`, `organization.identity.validated`, `organization.identity.renew`, `organization.identity.request` |
125
+ | Bank | `bank.credited`, `bank.debited`, `bank.transaction` |
126
+ | Custody | `custody.transaction`, `custody.wallet.created`, `custody.sent`, `custody.received` |
127
+ | Trading | `trading.buy`, `trading.sell` |
128
+ | Staking | `staking.requested`, `staking.status`, `staking.rewards`, `staking.claimed` |
129
+ | Compliance | `alert.opened`, `alert.status` |
130
+
131
+ The `WebhookEventName` constant carries these names — `WebhookEventName.CUSTODY_SENT` for `custody.sent`, `USER_IDENTITY_STEP_VALIDATED` for `user.identity.step.validated`… — and as a type it also accepts any other string, since the catalogue may grow ([Constants](../concepts.md#constants)).
132
+
133
+ ## archive
134
+
135
+ ```
136
+ client.webhooks.archive(subscriber: string | Subscriber): Promise<void>
137
+ ```
138
+
139
+ `subscriber` is the uuid returned by `subscribe`, or a `Subscriber` of `list()`.
140
+
141
+ ```ts
142
+ await client.webhooks.archive('SUBSCRIBER_UUID')
143
+ ```
144
+
145
+ The subscription becomes `SubscriberState.ARCHIVED`: the event is no longer delivered. An unknown subscription answers `404 unknown_webhook_subscriber`. The promise resolves with `undefined`.
146
+
147
+ ## reactivate
148
+
149
+ ```
150
+ client.webhooks.reactivate(subscriber: string | Subscriber): Promise<void>
151
+ ```
152
+
153
+ `subscriber` is the uuid returned by `subscribe`, or a `Subscriber` of `list({ includeArchived: true })`.
154
+
155
+ ```ts
156
+ await client.webhooks.reactivate('SUBSCRIBER_UUID')
157
+ ```
158
+
159
+ The subscription becomes `SubscriberState.ENABLED` again. An unknown subscription answers `404 unknown_webhook_subscriber`. The promise resolves with `undefined`.
160
+
161
+ ## logs
162
+
163
+ ```
164
+ client.webhooks.logs(subscriber: string | Subscriber, params?: PageParams): Promise<Page<DeliveryLog>>
165
+ ```
166
+
167
+ `subscriber` is the uuid returned by `subscribe`, or a `Subscriber` of `list()`.
168
+
169
+ | Parameter | Type | Description |
170
+ |---|---|---|
171
+ | `params.offset`, `params.limit` | `number` | [Pagination](../concepts.md#pagination) |
172
+
173
+ ```ts
174
+ const { count, items } = await client.webhooks.logs('SUBSCRIBER_UUID', { offset: 0, limit: 50 })
175
+
176
+ for (const delivery of items) {
177
+ console.log(delivery.date, delivery.http_code, delivery.attempts) // 1701000000 204 1
178
+ }
179
+ ```
180
+
181
+ Returns a page of `DeliveryLog`: `date` (epoch seconds), `webhook` (the event name), `url` (the endpoint called), `status` (`SENT` or `FAILED` for that attempt), `http_code` (the status your endpoint answered, or `null`), `duration_ms` (or `null`), `attempts` (attempt number), `payload` (the delivered body), `error` (failure reason, `null` on success).
182
+
183
+ ## catalog
184
+
185
+ ```
186
+ client.webhooks.catalog(): Promise<Page<WebhookType>>
187
+ ```
188
+
189
+ ```ts
190
+ import { SubscriberState } from '@bitgen/sdk'
191
+
192
+ const { items } = await client.webhooks.catalog()
193
+
194
+ for (const type of items) {
195
+ console.log(type.name, type.state === SubscriberState.ENABLED) // 'custody.sent' true
196
+ }
197
+ ```
198
+
199
+ Returns every event of the catalogue, `SubscriberState.ARCHIVED` ones included, as `WebhookType`: `uuid`, `state` (`SubscriberState.ENABLED` or `SubscriberState.ARCHIVED`), `name`, `label` (its display names, a raw JSON string `{"fr": "…", "en": "…"}`), `data` (internal, a raw JSON string).
200
+
201
+ ## catalogItem
202
+
203
+ ```
204
+ client.webhooks.catalogItem(webhook: string | WebhookType): Promise<WebhookType>
205
+ ```
206
+
207
+ `webhook` is the uuid of the event, or a `WebhookType` of `catalog()`.
208
+
209
+ ```ts
210
+ const type = await client.webhooks.catalogItem('WEBHOOK_UUID')
211
+ ```
212
+
213
+ Returns one `WebhookType`; an unknown uuid answers `404 unknown_webhook`.
214
+
215
+ ## verify
216
+
217
+ ```
218
+ client.webhooks.verify(input: VerifyInput): Promise<WebhookEvent>
219
+ ```
220
+
221
+ No request: the verification runs locally, with the secret of your organization.
222
+
223
+ Each delivery is a `POST` to your endpoint, with `Content-Type: application/json`, a JSON body `{ delivery_id, timestamp, event, data }` and two headers:
224
+
225
+ | Header | Content |
226
+ |---|---|
227
+ | `X-BITGEN-Timestamp` | The time of the delivery, epoch seconds |
228
+ | `X-BITGEN-Signature` | `sha256=<hex>`, where `hex = HMAC_SHA256(secret, "<timestamp>.<rawBody>")` |
229
+
230
+ Answer with a 2xx status: a delivery that does not get one is retried 4 times (after 60 s, 5 min, 15 min and 1 h).
231
+
232
+ | Parameter | Type | Description |
233
+ |---|---|---|
234
+ | `input.rawBody` | `string` or `Uint8Array` | The body exactly as received — the bytes, never a re-serialized JSON |
235
+ | `input.headers` | `Record<string, string \| string[] \| undefined>` | The headers as received (Node's `IncomingHttpHeaders`); names are matched case-insensitively |
236
+ | `input.secret` | `string` | The secret of your organization (`list().secret`) |
237
+ | `input.tolerance` | `number` | Optional: the maximum distance, in seconds, between now and the timestamp of the delivery — `300` by default, `0` disables the check |
238
+
239
+ ```ts
240
+ import { createServer } from 'node:http'
241
+ import { BitgenClient, BitgenError, WebhookEventName } from '@bitgen/sdk'
242
+
243
+ const client = new BitgenClient({ scope: 'YOUR_SCOPE_UUID', apiKey: 'YOUR_API_KEY' })
244
+ const { secret } = await client.webhooks.list()
245
+
246
+ createServer((req, res) => {
247
+ const chunks: Buffer[] = []
248
+ req.on('data', (chunk: Buffer) => chunks.push(chunk))
249
+ req.on('end', async () => {
250
+ try {
251
+ const event = await client.webhooks.verify({ rawBody: Buffer.concat(chunks), headers: req.headers, secret })
252
+ if (event.event === WebhookEventName.CUSTODY_SENT) {
253
+ // event.data is `unknown`: its shape depends on the event
254
+ }
255
+ res.writeHead(204).end()
256
+ } catch (err) {
257
+ res.writeHead(err instanceof BitgenError ? 400 : 500).end()
258
+ }
259
+ })
260
+ }).listen(8080)
261
+ ```
262
+
263
+ `verify` recomputes the signature on the raw bytes, compares it with `X-BITGEN-Signature` in constant time, checks `X-BITGEN-Timestamp` against `tolerance`, and only then parses the body. The SDK is stateless: a delivery may be replayed within the freshness window and verify again — an endpoint that wants to ignore a replay deduplicates on `delivery_id` on its side. It returns the envelope, a `WebhookEvent`:
264
+
265
+ | Field | Description |
266
+ |---|---|
267
+ | `delivery_id` | The delivery |
268
+ | `timestamp` | The time of the delivery, epoch seconds |
269
+ | `event` | The event name (`WebhookEventName`) — compare it with the constant |
270
+ | `data` | The payload of the event — typed `unknown`: its shape depends on the event |
271
+
272
+ A delivery that fails the verification rejects the promise with a `BitgenError` whose `status` is `0` and whose `code` is one of:
273
+
274
+ | `code` | Meaning |
275
+ |---|---|
276
+ | `missing_signature` | No `X-BITGEN-Signature` header |
277
+ | `invalid_signature` | The signature does not match the body and the secret |
278
+ | `missing_timestamp` | No `X-BITGEN-Timestamp` header, or not a number |
279
+ | `timestamp_expired` | The timestamp of the delivery is more than `tolerance` seconds away from now |
280
+ | `invalid_payload` | The body is not the JSON envelope |
281
+
282
+ An `input` that is not usable — a `rawBody` that is neither a string nor bytes, `headers` that are not an object, an empty `secret`, a `tolerance` that is not a number of seconds — rejects with a `TypeError` ([Rejected promises](../errors.md#rejected-promises)).
283
+
284
+ ## Errors
285
+
286
+ In addition to the [common errors](../errors.md#common-errors):
287
+
288
+ | Status | `code` | Meaning |
289
+ |---|---|---|
290
+ | `0` | `missing_signature`, `invalid_signature`, `missing_timestamp`, `timestamp_expired`, `invalid_payload` | `verify`: the delivery fails the verification ([verify](#verify)) |
291
+ | `400` | `webhook_security_https_required` | `activate`, `updateEndpoint`: an `http://` endpoint outside a local environment |
292
+ | `404` | `unknown_webhook_security` | The webhooks of your organization are not activated |
293
+ | `404` | `unknown_webhook` | Unknown event |
294
+ | `404` | `unknown_webhook_subscriber` | Unknown subscription |
295
+ | `409` | `webhook_subscription_already_exists` | `subscribe`: your organization is already subscribed to this event |
296
+ | `412` | `organization_not_enabled` | Your organization is closed |
297
+ | `422` | `invalid_include_archived` | `includeArchived` is not a boolean value |
298
+ | `429` | `webhook_security_already_enabled` | `activate`: the webhooks are already active |
299
+
300
+ ## Related
301
+
302
+ - [Errors](../errors.md) — `BitgenError`, `status: 0`
303
+ - [Customers](customer.md) — `user.created`, `user.identity.*`
304
+ - [Bank accounts](bank.md) — `bank.credited`, `bank.debited`, `bank.transaction`
305
+ - [Custody wallets](custody.md) — `custody.wallet.created`, `custody.received`, `custody.sent`, `custody.transaction`
306
+ - [Trading](trading.md) — `trading.buy`, `trading.sell`
307
+ - [Staking](staking.md) — `staking.requested`, `staking.status`, `staking.rewards`, `staking.claimed`
package/src/client.ts ADDED
@@ -0,0 +1,46 @@
1
+ import { HttpClient } from './http.js'
2
+ import { ApikeysResource } from './resources/apikeys.js'
3
+ import { AssetResource } from './resources/asset.js'
4
+ import { BankResource } from './resources/bank.js'
5
+ import { CoreResource } from './resources/core.js'
6
+ import { CustodyResource } from './resources/custody.js'
7
+ import { CustomerResource } from './resources/customer.js'
8
+ import { StakingResource } from './resources/staking.js'
9
+ import { TradingResource } from './resources/trading.js'
10
+ import { TransactionResource } from './resources/transaction.js'
11
+ import { WebhooksResource } from './resources/webhooks.js'
12
+ import type { BitgenConfig } from './types/index.js'
13
+
14
+ /**
15
+ * Entry point of the SDK: one instance per API key, resources hang off it (`client.asset`…).
16
+ * Invalid config throws a `TypeError` here, before any request is sent.
17
+ */
18
+ export class BitgenClient {
19
+ protected readonly http: HttpClient
20
+
21
+ readonly asset: AssetResource
22
+ readonly customer: CustomerResource
23
+ readonly bank: BankResource
24
+ readonly custody: CustodyResource
25
+ readonly trading: TradingResource
26
+ readonly transaction: TransactionResource
27
+ readonly core: CoreResource
28
+ readonly staking: StakingResource
29
+ readonly webhooks: WebhooksResource
30
+ readonly apikeys: ApikeysResource
31
+
32
+ constructor(config: BitgenConfig) {
33
+ this.http = new HttpClient(config)
34
+
35
+ this.asset = new AssetResource(this.http)
36
+ this.customer = new CustomerResource(this.http)
37
+ this.bank = new BankResource(this.http)
38
+ this.custody = new CustodyResource(this.http)
39
+ this.trading = new TradingResource(this.http)
40
+ this.transaction = new TransactionResource(this.http)
41
+ this.core = new CoreResource(this.http)
42
+ this.staking = new StakingResource(this.http, this.core)
43
+ this.webhooks = new WebhooksResource(this.http)
44
+ this.apikeys = new ApikeysResource(this.http)
45
+ }
46
+ }