@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,103 @@
1
+ # API keys
2
+
3
+ An API key belongs to your organization: it is valid until it expires or is revoked, and every call made with it is journaled. `client.apikeys` reads the keys of your organization and the journal of their calls — it is read-only: a key cannot be created through the API, and the SDK does not revoke.
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
+ | `list(params?)` | Lists the keys of your organization | `Page<Apikey>` |
12
+ | `get(apikey)` | Reads one key | `Apikey` |
13
+ | `logs(apikey, params?)` | Lists the calls made with a key | `Page<ApikeyLog>` |
14
+
15
+ TypeScript types of this resource, exported by the package: `Apikey`, `ApikeyLog`, `ApikeyListParams` — the constant `ApikeyState` (also a type) — plus the shared `PageParams`.
16
+
17
+ ## list
18
+
19
+ ```
20
+ client.apikeys.list(params?: ApikeyListParams): Promise<Page<Apikey>>
21
+ ```
22
+
23
+ | Parameter | Type | Description |
24
+ |---|---|---|
25
+ | `params.offset`, `params.limit` | `number` | [Pagination](../concepts.md#pagination) |
26
+ | `params.includeRevoked` | `boolean` | Also returns the `ApikeyState.REVOKED` keys — default `false` ([Query booleans](../concepts.md#query-booleans)) |
27
+
28
+ ```ts
29
+ import { ApikeyState } from '@bitgen/sdk'
30
+
31
+ const { count, items } = await client.apikeys.list({ includeRevoked: true })
32
+
33
+ for (const key of items) {
34
+ console.log(key.name, key.state === ApikeyState.ENABLED, key.expireAt) // 'backend' true 1735689600
35
+ }
36
+ ```
37
+
38
+ Returns a page of `Apikey` ([get](#get)).
39
+
40
+ ## get
41
+
42
+ ```
43
+ client.apikeys.get(apikey: string | Apikey): Promise<Apikey>
44
+ ```
45
+
46
+ `apikey` is the uuid of the key, or an `Apikey` of `list()`.
47
+
48
+ ```ts
49
+ import { ApikeyState } from '@bitgen/sdk'
50
+
51
+ const key = await client.apikeys.get('APIKEY_UUID')
52
+
53
+ console.log(key.state === ApikeyState.ENABLED, new Date(key.expireAt * 1000)) // true 2025-01-01T00:00:00.000Z
54
+ ```
55
+
56
+ Returns an `Apikey`:
57
+
58
+ | Field | Description |
59
+ |---|---|
60
+ | `uuid` | The key |
61
+ | `state` | `ApikeyState.ENABLED` or `ApikeyState.REVOKED` |
62
+ | `name` | Label given at creation |
63
+ | `permissions` | What the key is allowed to do, as set by BITGEN |
64
+ | `expireAt`, `createdAt` | Epoch seconds |
65
+ | `organization` | `{ uuid, state, name, hub, owner }` — `hub` is `{ uuid, state, name, options }` or `null` (`options`: internal), `owner` is the owner of the organization, `{ uuid, login, firstname, lastname }` or `null` |
66
+
67
+ An unknown uuid answers `404 unknown_apikey`. The raw key itself is never returned: it is shown once, when the key is created.
68
+
69
+ ## logs
70
+
71
+ ```
72
+ client.apikeys.logs(apikey: string | Apikey, params?: PageParams): Promise<Page<ApikeyLog>>
73
+ ```
74
+
75
+ `apikey` is the uuid of the key, or an `Apikey` of `list()`.
76
+
77
+ | Parameter | Type | Description |
78
+ |---|---|---|
79
+ | `params.offset`, `params.limit` | `number` | [Pagination](../concepts.md#pagination) |
80
+
81
+ ```ts
82
+ const { count, items } = await client.apikeys.logs('APIKEY_UUID', { offset: 0, limit: 50 })
83
+
84
+ for (const call of items) {
85
+ console.log(call.date, call.path, call.status, call.error) // 1701000000 'GET /custody/…' 200 null
86
+ }
87
+ ```
88
+
89
+ Returns a page of `ApikeyLog`, one entry per call made with the key: `date` (epoch seconds), `path` (`"GET /custody/…"`), `payload` (the inputs of the call as a JSON string, personal data masked), `status` (the HTTP status answered), `error` (response body of the failed call, `null` when the call succeeded).
90
+
91
+ ## Errors
92
+
93
+ In addition to the [common errors](../errors.md#common-errors):
94
+
95
+ | Status | `code` | Meaning |
96
+ |---|---|---|
97
+ | `404` | `unknown_apikey` | Unknown key |
98
+ | `422` | `invalid_include_revoked` | `includeRevoked` is not a boolean value |
99
+
100
+ ## Related
101
+
102
+ - [Configuration](../configuration.md#credentials) — `scope` and `apiKey`
103
+ - [Errors](../errors.md#common-errors) — a missing, unknown, revoked or expired key
@@ -0,0 +1,121 @@
1
+ # Assets
2
+
3
+ The assets are the crypto currencies and tokens of the BITGEN platform, each on its network, with its decimals, its fees, a live ticker and its EUR price history. `client.asset` reads this catalogue: which assets exist and are `AssetState.AVAILABLE`, how many decimals an amount may carry, and the prices.
4
+
5
+ Examples use `client`, a configured `BitgenClient` ([Configuration](../configuration.md)). An asset is designated by its uuid or its ISO code, in any case, or by a model carrying its uuid ([Assets](../concepts.md#assets)).
6
+
7
+ ## Methods
8
+
9
+ | Method | What it does | Returns |
10
+ |---|---|---|
11
+ | `list()` | Lists the assets of the platform | `Page<Asset>` |
12
+ | `get(asset)` | Reads one asset | `Asset` |
13
+ | `tickers()` | Reads the ticker of every asset | `Page<{ iso, ticker }>` |
14
+ | `ticker(iso)` | Reads the ticker and the EUR price history of one asset | `{ iso, ticker, history }` |
15
+
16
+ TypeScript types of this resource, exported by the package: `AssetTicker`, `AssetFees`, `AssetNetworkType`, `AssetNetwork`, `Asset` — the constants `AssetState` (also a type) and `Asset` (the ISO codes, a value only: the `Asset` type is the model) — plus the shared `AssetRef`, `AssetInput`, `History`.
17
+
18
+ ## list
19
+
20
+ ```
21
+ client.asset.list(): Promise<Page<Asset>>
22
+ ```
23
+
24
+ ```ts
25
+ import { AssetState } from '@bitgen/sdk'
26
+
27
+ const { count, items } = await client.asset.list()
28
+
29
+ const available = items.filter((asset) => asset.state === AssetState.AVAILABLE)
30
+ for (const asset of available) {
31
+ console.log(asset.iso, asset.label, asset.baseUnit) // 'ETH' 'Ethereum' 18
32
+ }
33
+ ```
34
+
35
+ Returns a page of `Asset` ([get](#get)).
36
+
37
+ ## get
38
+
39
+ ```
40
+ client.asset.get(asset: AssetInput): Promise<Asset>
41
+ ```
42
+
43
+ `asset` is the uuid or the ISO code of the asset (`Asset.ETH`), or a model carrying its uuid — an `AssetRef` such as `wallet.asset`.
44
+
45
+ ```ts
46
+ import { Asset, AssetState } from '@bitgen/sdk'
47
+
48
+ const eth = await client.asset.get(Asset.ETH)
49
+
50
+ console.log(eth.state === AssetState.AVAILABLE, eth.baseUnit, eth.ticker.price) // true 18 2031.5
51
+ ```
52
+
53
+ Returns an `Asset`:
54
+
55
+ | Field | Description |
56
+ |---|---|
57
+ | `uuid` | The asset |
58
+ | `state` | `AssetState.AVAILABLE`, `UNAVAILABLE`, `ARCHIVED` or `HIDDEN` |
59
+ | `iso` | The ISO code, with the case it is stored with (`ETH`) — compare it case-insensitively |
60
+ | `label` | Display name (`Bitcoin`) |
61
+ | `contractAddress` | The contract address of a token — `''` for a native asset, never `null` |
62
+ | `baseUnit` | The decimals of the asset (18 by default, 24 at most): the precision amounts may carry |
63
+ | `gasUnit` | Gas units consumed by a transfer of this asset on its network; with the network's `gasBase`, it sizes the network fee |
64
+ | `logo` | The logo as a data URI (SVG), or `null` |
65
+ | `data` | Internal connector mapping, raw JSON string — not needed for an integration |
66
+ | `fees` | `low`, `medium`, `high` — the raw fee schedule of the gas provider, opaque — and `computed`: `gas` (gas cost of a transfer, in the smallest unit of the native coin), `native` (the same, in native coin units) |
67
+ | `ticker` | `price` and `marketcap` (in EUR), `rank` (market cap rank), `percentChange24h` (24-hour change, in %) |
68
+ | `history` | The EUR price curve, a `History` ([Timestamps and histories](../concepts.md#timestamps-and-histories)) |
69
+ | `network` | `uuid`, `state` (state of the network record), `caip2` (chain identifier, CAIP-2 — `eip155:1`), `label`, `gasBase`, `data`, `type` (`{ uuid, code, label, data }` — `code` is the network family: `UTXO`, `EVM`, `COMPUTE_UNIT` or `DROPS`; `label` its name) — both `data` are internal connector mappings, raw JSON strings, not needed for an integration |
70
+
71
+ An unknown uuid or ISO code answers `404 unknown_asset`.
72
+
73
+ ## tickers
74
+
75
+ ```
76
+ client.asset.tickers(): Promise<Page<{ iso: string, ticker: AssetTicker }>>
77
+ ```
78
+
79
+ ```ts
80
+ const { items } = await client.asset.tickers()
81
+
82
+ for (const { iso, ticker } of items) {
83
+ console.log(iso, ticker.price, ticker.percentChange24h) // 'BTC' 61230.4 -1.2
84
+ }
85
+ ```
86
+
87
+ Returns, for every asset, its `iso` and its `ticker` (`AssetTicker`): `price` and `marketcap` (in EUR), `rank` (market cap rank), `percentChange24h` (24-hour change, in %).
88
+
89
+ ## ticker
90
+
91
+ ```
92
+ client.asset.ticker(iso: string): Promise<{ iso: string, ticker: AssetTicker, history: History }>
93
+ ```
94
+
95
+ `iso` is the ISO code of the asset (`Asset.BTC`) — this read takes no uuid and no model.
96
+
97
+ ```ts
98
+ import { Asset } from '@bitgen/sdk'
99
+
100
+ const btc = await client.asset.ticker(Asset.BTC)
101
+
102
+ console.log(btc.ticker.price) // 61230.4
103
+ console.log(btc.history.d) // EUR price over the last 24 hours, one point per hour
104
+ ```
105
+
106
+ Returns the `iso`, the `ticker` and the EUR price `history` of the asset.
107
+
108
+ ## Errors
109
+
110
+ In addition to the [common errors](../errors.md#common-errors):
111
+
112
+ | Status | `code` | Meaning |
113
+ |---|---|---|
114
+ | `404` | `unknown_asset` | Unknown uuid or ISO code |
115
+
116
+ ## Related
117
+
118
+ - [Assets](../concepts.md#assets) — the `Asset` constants, uuid or ISO code, case
119
+ - [Amounts](../concepts.md#amounts) — crypto amounts as strings, up to the decimals of the asset
120
+ - [Custody wallets](custody.md) — one wallet per customer and per asset
121
+ - [Trading](trading.md) — orders take an `AssetState.AVAILABLE` asset
@@ -0,0 +1,156 @@
1
+ # Bank accounts
2
+
3
+ Every customer has an EUR account on the BITGEN platform: a ledger that receives their bank transfers, holds the EUR balance their purchases are paid from, is credited by their sales, and pays their withdrawals to their IBAN. `client.bank` reads the account and its operations, withdraws EUR, and credits deposits.
4
+
5
+ Examples use `client`, a configured `BitgenClient` ([Configuration](../configuration.md)). A customer is designated by a `UserRef`: their uuid, or a model carrying it, such as the `Created` returned by `client.customer.create` ([User references](../concepts.md#user-references)). The customer must belong to your organization and be activated, otherwise the API answers `404 unknown_bank` ([Activation and identity](../concepts.md#activation-and-identity)).
6
+
7
+ ## Methods
8
+
9
+ | Method | What it does | Returns |
10
+ |---|---|---|
11
+ | `get(user)` | Reads the EUR account of a customer — creates it on first read | `BankAccount` |
12
+ | `operations(user, params?)` | Lists the EUR operations of a customer | `Page<BankOperation>` |
13
+ | `withdraw(user, params)` | Withdraws EUR to the customer's IBAN | `{ transaction }` |
14
+ | `credit(params)` | Credits an EUR deposit to a customer's account | `Created` (the deposit) |
15
+
16
+ TypeScript types of this resource, exported by the package: `BankAccount`, `BankOperation`, `BankOperationsParams`, `BankWithdrawParams`, `BankCreditParams` — the constant `BankDirection` (also a type) — plus the shared `UserRef`, `Created`, `Amount`.
17
+
18
+ ## get
19
+
20
+ ```
21
+ client.bank.get(user: UserRef): Promise<BankAccount>
22
+ ```
23
+
24
+ The account is created on first read — if your organization uses BITGEN's identity verification, the customer's identity must be validated first ([Activation and identity](../concepts.md#activation-and-identity)). The `message` of the account is the reference the customer must indicate on their bank transfers.
25
+
26
+ ```ts
27
+ const account = await client.bank.get('CUSTOMER_UUID')
28
+
29
+ // 1. Give the customer the reference to put on their wire transfer
30
+ console.log(account.message) // 'BTGN…'
31
+
32
+ // 2. Once the transfer is received, the balance is credited
33
+ console.log(account.balance) // 150
34
+ console.log(account.pending) // { in: 0, out: 0 }
35
+ ```
36
+
37
+ Returns a `BankAccount`:
38
+
39
+ | Field | Description |
40
+ |---|---|
41
+ | `uuid` | The account |
42
+ | `message` | The wire transfer reference the customer must indicate (`BTGN` prefix) |
43
+ | `iban`, `bank`, `bic` | The customer's bank details, `null` until set — `withdraw` can set them |
44
+ | `balance` | EUR balance (number) |
45
+ | `pending` | `{ in, out }` — EUR incoming not credited yet, and outgoing not confirmed yet |
46
+ | `history` | EUR balance curve, a `History` ([Timestamps and histories](../concepts.md#timestamps-and-histories)); `{}` until the hourly computation has run for this account |
47
+
48
+ ## operations
49
+
50
+ ```
51
+ client.bank.operations(user: UserRef, params?: BankOperationsParams): Promise<Page<BankOperation>>
52
+ ```
53
+
54
+ | Parameter | Type | Description |
55
+ |---|---|---|
56
+ | `params.direction` | `BankDirection` | `BankDirection.ALL` (default), `DEPOSIT`, `WITHDRAWAL`, `PURCHASE` or `SELL` — an unknown value means `ALL` |
57
+ | `params.from`, `params.to` | `number` | Epoch seconds; both together, otherwise ignored |
58
+ | `params.offset`, `params.limit` | `number` | [Pagination](../concepts.md#pagination) |
59
+
60
+ ```ts
61
+ import { BankDirection } from '@bitgen/sdk'
62
+
63
+ const { count, items } = await client.bank.operations('CUSTOMER_UUID', {
64
+ direction: BankDirection.DEPOSIT,
65
+ from: 1700000000,
66
+ to: 1702592000,
67
+ offset: 0,
68
+ limit: 50,
69
+ })
70
+
71
+ for (const operation of items) {
72
+ console.log(operation.date, operation.direction === BankDirection.DEPOSIT, operation.amount) // 1701000000 true 150
73
+ }
74
+ ```
75
+
76
+ Returns a page of `BankOperation`: `txId` (identifier of the ledger entry), `amount` (EUR, number), `direction` (`BankDirection.DEPOSIT`, `WITHDRAWAL`, `PURCHASE` or `SELL` — never `ALL`), `date` (epoch seconds), `info` (free label of the operation — for instance the asset bought or sold — or `null`).
77
+
78
+ ## withdraw
79
+
80
+ ```
81
+ client.bank.withdraw(user: UserRef, params: BankWithdrawParams): Promise<{ transaction: string }>
82
+ ```
83
+
84
+ | Parameter | Type | Description |
85
+ |---|---|---|
86
+ | `params.amount` | `Amount` | EUR, rounded to 2 decimals ([Amounts](../concepts.md#amounts)) |
87
+ | `params.iban`, `params.bank`, `params.bic` | `string` | Optional: update the customer's bank details before the withdrawal |
88
+
89
+ ```ts
90
+ const { transaction } = await client.bank.withdraw('CUSTOMER_UUID', {
91
+ amount: '50.00',
92
+ iban: 'FR76…', // optional, sets or replaces the customer's bank details
93
+ bic: 'BNPAFRPP',
94
+ })
95
+
96
+ const movement = await client.transaction.get(transaction) // follow the withdrawal in the transaction journal
97
+ ```
98
+
99
+ The withdrawal goes to the customer's IBAN: the account must have bank details (`412 bank_rib_required`), a sufficient balance (`416 requested_amount_error`) and an amount above the fee (`416 amount_below_fee`). `transaction` is the uuid of the `Transaction` created for the withdrawal ([Transactions](transaction.md)).
100
+
101
+ ## credit
102
+
103
+ ```
104
+ client.bank.credit(params: BankCreditParams): Promise<Created>
105
+ ```
106
+
107
+ `credit` only applies when your organization's bank provider is **manual** — deposits are not reported to BITGEN automatically: you tell BITGEN a wire has arrived, and the customer's account is credited. With an automated provider, deposits are detected and credited automatically and you are notified by the `bank.credited` webhook ([Webhooks](webhooks.md)) — do not call `credit`: the API refuses it (`412 deposit_reported_by_provider`). The account is designated either by the customer (`user`) or by the wire transfer reference of the account (`message`).
108
+
109
+ | Parameter | Type | Description |
110
+ |---|---|---|
111
+ | `params.amount` | `Amount` | EUR ([Amounts](../concepts.md#amounts)) |
112
+ | `params.currency` | `'EUR'` | Optional |
113
+ | `params.user` | `UserRef` | The customer — or `message` |
114
+ | `params.message` | `string` | The wire transfer reference of the account (`BTGN…`) — or `user` |
115
+ | `params.reference` | `string` | The bank's transfer reference — it makes the call idempotent: calling twice with the same reference credits once (and returns the same `uuid`) |
116
+
117
+ ```ts
118
+ const { uuid } = await client.bank.credit({
119
+ amount: '100.00',
120
+ user: 'CUSTOMER_UUID',
121
+ reference: 'BANK-TRANSFER-REF-42', // the bank's transfer reference: credited once, however many times it is sent
122
+ })
123
+ ```
124
+
125
+ Returns a `Created` — the `uuid` identifying the deposit. Without `user` nor `message`, the API answers `400 bank_target_required`.
126
+
127
+ ## Errors
128
+
129
+ In addition to the [common errors](../errors.md#common-errors):
130
+
131
+ | Status | `code` | Meaning |
132
+ |---|---|---|
133
+ | `400` | `invalid_amount` | The amount is not valid |
134
+ | `400` | `bank_target_required` | `credit` without `user` nor `message` |
135
+ | `400` | `invalid_currency` | `credit` with a currency other than `EUR` |
136
+ | `403` | `user_actions_disabled` | Customer actions are disabled for your organization (`user_can_actions` flag) |
137
+ | `404` | `unknown_bank` | The customer is not an activated member of your organization, or the account was not found |
138
+ | `404` | `unknown_organization` | `credit`: the organization is unknown |
139
+ | `412` | `owner_identity_not_validated` | Your organization uses BITGEN's identity verification and the customer's identity is not validated: the account cannot be created |
140
+ | `412` | `bank_rib_required` | `withdraw` without an IBAN or a bank on the account |
141
+ | `412` | `ramp_not_enabled` | The `CoreType.RAMP` (bank) connector of your organization is not enabled |
142
+ | `412` | `deposit_reported_by_provider` | `credit` on an automated bank provider: deposits are reported by the provider itself |
143
+ | `412` | `trading_not_enabled` | The `CoreType.TRADING` connector of your organization is not enabled |
144
+ | `416` | `requested_amount_error` | Insufficient balance |
145
+ | `416` | `amount_below_fee` | The amount does not cover the fee |
146
+ | `422` | `invalid_iban` | The IBAN is not valid |
147
+ | `423` | `account_frozen` | The customer's account is frozen |
148
+ | `423` | `blocked_by_alert` | An active compliance alert blocks the customer |
149
+ | `423` | `bank_lock_unavailable` | The account is locked by a concurrent operation (creation, withdrawal) |
150
+
151
+ ## Related
152
+
153
+ - [Amounts](../concepts.md#amounts) — EUR amounts as strings, 2 decimals
154
+ - [Trading](trading.md) — purchases paid from the EUR balance, sales credited to it
155
+ - [Transactions](transaction.md) — the journal where withdrawals appear
156
+ - [Webhooks](webhooks.md) — `bank.credited`, `bank.debited`, `bank.transaction`
@@ -0,0 +1,91 @@
1
+ # Connectors
2
+
3
+ A connector — a *core* — is a service the BITGEN platform is plugged into: a bank (`CoreType.RAMP`), an exchange (`CoreType.TRADING`), a custodian (`CoreType.CUSTODY`), a staking provider (`CoreType.STAKING`), an identity verification service (`CoreType.IDENTITY`) or an anti-money-laundering service (`CoreType.AML`). `client.core` reads this catalogue: which connectors exist, their state, and — for staking providers — the asset and the offer they carry. Its main use for an integration is to pick a staking provider ([Staking](staking.md)).
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 connectors of the platform, optionally filtered by type, asset and state | `Page<Core>` |
12
+ | `get(core)` | Reads one connector | `Core` |
13
+
14
+ TypeScript types of this resource, exported by the package: `CoreConfigField`, `Core`, `CoreListParams` — the constants `CoreType`, `CoreState` (also types) — plus the shared `CoreRef`, `AssetRef`, `AssetInput`, `Page`.
15
+
16
+ The catalogue is managed by BITGEN. Which connectors your organization uses, and their configuration, are set in the BITGEN interface — not through the API.
17
+
18
+ ## list
19
+
20
+ ```
21
+ client.core.list(params?: CoreListParams): Promise<Page<Core>>
22
+ ```
23
+
24
+ Not paginated: `count` is everything that matches. All the filters are optional and combine.
25
+
26
+ | Parameter | Type | Description |
27
+ |---|---|---|
28
+ | `params.type` | `CoreType` | `CoreType.IDENTITY`, `AML`, `TRADING`, `CUSTODY`, `STAKING` or `RAMP` — anything else → `424 unknown_core_type` |
29
+ | `params.asset` | `AssetInput` | Only the connectors attached to this asset (the `CoreType.STAKING` ones), by uuid or ISO code (`Asset.ETH`) or by model ([Assets](../concepts.md#assets)) — unknown → `404 unknown_asset` |
30
+ | `params.state` | `CoreState` | `CoreState.ENABLED` or `CoreState.DISABLED` — anything else → `400 invalid_core_status` |
31
+
32
+ ```ts
33
+ import { Asset, CoreState, CoreType } from '@bitgen/sdk'
34
+
35
+ const banks = await client.core.list({ type: CoreType.RAMP })
36
+ const exchanges = await client.core.list({ type: CoreType.TRADING })
37
+ const custodians = await client.core.list({ type: CoreType.CUSTODY })
38
+ const providers = await client.core.list({ type: CoreType.STAKING, asset: Asset.ETH }) // the staking providers of ETH
39
+
40
+ for (const provider of providers.items) {
41
+ console.log(provider.name, provider.asset?.iso, provider.state === CoreState.ENABLED) // 'bitgen_eth' 'ETH' true
42
+ }
43
+ ```
44
+
45
+ Returns the matching `Core` connectors ([get](#get)).
46
+
47
+ ## get
48
+
49
+ ```
50
+ client.core.get(core: string | Core): Promise<Core>
51
+ ```
52
+
53
+ `core` is the uuid of the connector, or a `Core` of `list()`.
54
+
55
+ ```ts
56
+ const core = await client.core.get('CORE_UUID')
57
+
58
+ for (const field of core.config) {
59
+ console.log(field.name, field.data.value) // 'min_deposit' …
60
+ }
61
+ ```
62
+
63
+ Returns a `Core`:
64
+
65
+ | Field | Description |
66
+ |---|---|
67
+ | `uuid` | The connector |
68
+ | `state` | `CoreState.ENABLED` or `CoreState.DISABLED` |
69
+ | `name` | The identifier of the connector — for a `CoreType.STAKING` connector, `<provider>_<iso>` (`figment_sol`, `bitgen_eth`) |
70
+ | `label` | Display name |
71
+ | `type` | `CoreType.IDENTITY`, `AML`, `TRADING`, `CUSTODY`, `STAKING` or `RAMP` |
72
+ | `asset` | `AssetRef`: `{ uuid, iso, label }` for a `CoreType.STAKING` connector (derived from its `name`), `null` for the other types |
73
+ | `config` | The configuration schema of the connector, a list of `CoreConfigField`: `name` (key), `label` (display names `{ fr, en }`), `data.type` (`string`, `int`, `bool`, `password` or `webhook`), `data.value` (the value — empty for secrets). The secrets of your organization's configuration never appear here. |
74
+
75
+ An unknown uuid answers `404 unknown_core`.
76
+
77
+ ## Errors
78
+
79
+ In addition to the [common errors](../errors.md#common-errors):
80
+
81
+ | Status | `code` | Meaning |
82
+ |---|---|---|
83
+ | `400` | `invalid_core_status` | `state` is neither `CoreState.ENABLED` nor `CoreState.DISABLED` |
84
+ | `404` | `unknown_asset` | `list`: unknown `asset` |
85
+ | `404` | `unknown_core` | `get`: unknown connector |
86
+ | `424` | `unknown_core_type` | `type` is not one of the connector types |
87
+
88
+ ## Related
89
+
90
+ - [Staking](staking.md) — `client.staking.providers` is `list` filtered on `CoreType.STAKING`; a `StakingPosition` carries its provider as a `CoreRef`
91
+ - [Assets](../concepts.md#assets) — uuid or ISO code, case
@@ -0,0 +1,166 @@
1
+ # Custody wallets
2
+
3
+ A custody wallet holds the crypto of a customer for one asset, at the custodian of the platform: a deposit address the customer sends funds to, an exact balance, and on-chain withdrawals to external addresses. `client.custody` lists and reads the wallets of a customer, provisions them, reads the EUR value of their custody, and withdraws.
4
+
5
+ Examples use `client`, a configured `BitgenClient` ([Configuration](../configuration.md)). A customer is designated by a `UserRef`: their uuid, or a model carrying it, such as the `Created` returned by `client.customer.create` ([User references](../concepts.md#user-references)). `wallets` and `wallet` also take the uuid of your organization (your `scope`) to read its treasury wallets (`type` `WalletType.TREASURY`, read-only); `portfolio` and `withdraw` are for customers only. A customer who is not an activated member of your organization is refused with `403 org_forbidden` ([Activation and identity](../concepts.md#activation-and-identity)); another organization, with `403 cross_org_forbidden`.
6
+
7
+ ## Methods
8
+
9
+ | Method | What it does | Returns |
10
+ |---|---|---|
11
+ | `wallets(user)` | Lists the wallets of a customer, or of your organization | `Wallet[]` |
12
+ | `wallet(user, asset)` | Reads one wallet with its EUR value curve — provisions it on first read | `Wallet` |
13
+ | `portfolio(user)` | Reads the EUR value curve of the whole custody of a customer | `CustodyPortfolio` |
14
+ | `withdraw(user, params)` | Sends crypto from a wallet to an external address | `{ transaction }` |
15
+
16
+ TypeScript types of this resource, exported by the package: `Wallet`, `CustodyPortfolio`, `TravelRule`, `CustodyWithdrawParams` — the constants `WalletState`, `WalletType` (also types) — plus the shared `UserRef`, `AssetRef`, `AssetInput`, `Amount`.
17
+
18
+ ## wallets
19
+
20
+ ```
21
+ client.custody.wallets(user: UserRef): Promise<Wallet[]>
22
+ ```
23
+
24
+ ```ts
25
+ const wallets = await client.custody.wallets('CUSTOMER_UUID')
26
+
27
+ for (const wallet of wallets) {
28
+ console.log(wallet.asset.iso, wallet.balance, wallet.address) // 'ETH' '0.5' '0xabc…'
29
+ }
30
+
31
+ const treasury = await client.custody.wallets('YOUR_SCOPE_UUID') // the treasury wallets of your organization
32
+ ```
33
+
34
+ Returns the wallets without their `history`:
35
+
36
+ | Field | Description |
37
+ |---|---|
38
+ | `uuid` | The wallet |
39
+ | `state` | `WalletState.CREATED` or `WalletState.FROZEN` |
40
+ | `type` | `WalletType.USER` for a customer, `WalletType.TREASURY` for your organization |
41
+ | `address` | The deposit address (or `null`) |
42
+ | `addressLegacy` | The same deposit address in the legacy format of the chain, for networks that have two address formats; `null` otherwise |
43
+ | `tag` | The memo / tag of the address, for the assets that use one (XRP, XLM…) — or `null` |
44
+ | `balance` | The exact quantity, as a string |
45
+ | `asset` | `AssetRef`: `{ uuid, iso, label }` ([Assets](../concepts.md#assets) — compare `iso` case-insensitively) |
46
+ | `history` | Only on `wallet`: the EUR value curve, a `History` ([Timestamps and histories](../concepts.md#timestamps-and-histories)) — `{}` on a new wallet until the curve has been computed |
47
+
48
+ ## wallet
49
+
50
+ ```
51
+ client.custody.wallet(user: UserRef, asset: AssetInput): Promise<Wallet>
52
+ ```
53
+
54
+ | Parameter | Type | Description |
55
+ |---|---|---|
56
+ | `asset` | `AssetInput` | The asset, by uuid or ISO code (`Asset.ETH`) or by model ([Assets](../concepts.md#assets)) — never the uuid of the wallet |
57
+
58
+ ```ts
59
+ import { Asset } from '@bitgen/sdk'
60
+
61
+ const wallet = await client.custody.wallet('CUSTOMER_UUID', Asset.ETH)
62
+
63
+ // Show the customer where to send their ETH
64
+ console.log(wallet.address) // '0xabc…'
65
+ console.log(wallet.tag) // null — a memo / tag only for assets that need one
66
+ console.log(wallet.balance) // '0.5'
67
+ console.log(wallet.history?.d) // EUR value over the last 24 hours — only on this unit read
68
+ ```
69
+
70
+ When the customer has no wallet for this asset yet, the API **provisions** it: a deposit address is created at the custodian. The customer must be activated, not frozen (`403 account_frozen`), with a validated identity if your organization uses BITGEN's identity verification (`403 kyc_not_validated` — [Activation and identity](../concepts.md#activation-and-identity)) and no active compliance alert (`423 blocked_by_alert`). Returns the `Wallet` with its `history`.
71
+
72
+ ## portfolio
73
+
74
+ ```
75
+ client.custody.portfolio(user: UserRef): Promise<CustodyPortfolio>
76
+ ```
77
+
78
+ ```ts
79
+ const portfolio = await client.custody.portfolio('CUSTOMER_UUID')
80
+
81
+ console.log(portfolio.history.m) // EUR value of the custody, one point per day over the last month
82
+ ```
83
+
84
+ Returns `{ uuid, type, history }` — `uuid` is the custody account of the customer, `type` is `WalletType.USER` (a customer) or `WalletType.TREASURY` (the organization) — or a flat `{ history }` at zero while the customer has no custody. Customers only: your organization's uuid is refused with `415 custody_portfolio_treasury_unsupported`.
85
+
86
+ ## withdraw
87
+
88
+ ```
89
+ client.custody.withdraw(user: UserRef, params: CustodyWithdrawParams): Promise<{ transaction: string | null }>
90
+ ```
91
+
92
+ | Parameter | Type | Description |
93
+ |---|---|---|
94
+ | `params.asset` | `AssetInput` | The asset, by uuid or ISO code (`Asset.ETH`) or by model |
95
+ | `params.amount` | `Amount` | The quantity to send, as a string: more than 0, at most the decimals of the asset (`baseUnit`) — sent untouched; the EUR value of the quantity must reach a minimum — `416 withdraw_below_minimum` below it ([Amounts](../concepts.md#amounts)) |
96
+ | `params.targetAddress` | `string` | The destination address |
97
+ | `params.targetTag` | `string` | The destination memo / tag, for the assets that need one |
98
+ | `params.idempotencyKey` | `string` | Optional, 64 characters max, unique per customer: replaying the same key returns the same transaction |
99
+ | `params.travelRule` | `TravelRule` | Optional travel rule information on the destination: a person `{ firstname?, lastname?, address? }` **or** a platform `{ platform }` — one form or the other, 255 characters max per field |
100
+
101
+ ```ts
102
+ import { Asset } from '@bitgen/sdk'
103
+
104
+ const { transaction } = await client.custody.withdraw('CUSTOMER_UUID', {
105
+ asset: Asset.ETH,
106
+ amount: '0.05', // string: up to 18 decimals, sent as is — above the asset's minimum (see Errors)
107
+ targetAddress: '0xabc…',
108
+ idempotencyKey: 'withdraw-42',
109
+ travelRule: { platform: 'Kraken' }, // or { firstname: 'Jean', lastname: 'Valjean', address: '…' }
110
+ })
111
+
112
+ if (transaction !== null) {
113
+ const movement = await client.transaction.get(transaction) // follow it in the transaction journal
114
+ }
115
+ ```
116
+
117
+ Customers only: your organization's uuid is refused with `415 custody_treasury_withdraw_unsupported`. The EUR value of the withdrawal must reach the minimum (`416 withdraw_below_minimum` — [Amounts](../concepts.md#amounts)). Returns the uuid of the `Transaction` created for the withdrawal ([Transactions](transaction.md)) — `null` while the analysis has not created it yet.
118
+
119
+ ## Errors
120
+
121
+ In addition to the [common errors](../errors.md#common-errors):
122
+
123
+ | Status | `code` | Meaning |
124
+ |---|---|---|
125
+ | `400` | `invalid_amount` | The amount is not valid |
126
+ | `400` | `invalid_travel_rule` | `travelRule` mixes the two forms, or a field is too long |
127
+ | `403` | `org_forbidden` | The customer is not an activated member of your organization |
128
+ | `403` | `cross_org_forbidden` | The uuid belongs to another organization |
129
+ | `403` | `account_frozen` | The customer's account is frozen |
130
+ | `403` | `kyc_not_validated` | Your organization uses BITGEN's identity verification and the customer's identity is not validated ([Activation and identity](../concepts.md#activation-and-identity)) |
131
+ | `403` | `wallet_frozen` | The wallet is frozen |
132
+ | `403` | `user_actions_disabled` | Customer actions are disabled for your organization (`user_can_actions` flag) |
133
+ | `404` | `unknown_asset` | Unknown asset — the wallet uuid is not accepted |
134
+ | `404` | `unknown_organization` | The organization is unknown |
135
+ | `404` | `withdraw_organization_unresolved` | The organization of the withdrawal is unresolved |
136
+ | `409` | `duplicate_withdraw` | Duplicate withdrawal |
137
+ | `412` | `custody_not_enabled` | The `CUSTODY` connector of your organization is not enabled |
138
+ | `415` | `custody_portfolio_treasury_unsupported` | `portfolio` on your organization |
139
+ | `415` | `custody_treasury_withdraw_unsupported` | `withdraw` on your organization |
140
+ | `416` | `amount_precision_exceeded` | More decimals than the asset allows |
141
+ | `416` | `withdraw_below_minimum` | The EUR value of the quantity is below the minimum |
142
+ | `416` | `withdraw_price_unavailable` | No price is available to value the withdrawal |
143
+ | `416` | `requested_amount_error` | Insufficient balance |
144
+ | `416` | `custody_vault_insufficient` | The custody vault is insufficient |
145
+ | `416` | `withdraw_target_too_long` | `targetAddress` is too long |
146
+ | `422` | `withdraw_target_invalid` | `targetAddress` is not valid |
147
+ | `422` | `withdraw_target_tag_required` | The asset needs a `targetTag` |
148
+ | `422` | `withdraw_target_address_required` | `targetAddress` is missing |
149
+ | `422` | `invalid_idempotency_key` | `idempotencyKey` is not valid (64 characters max) |
150
+ | `422` | `asset_not_supported` | The custodian does not support this asset |
151
+ | `422` | `asset_address_unavailable` | No deposit address is available for this asset |
152
+ | `423` | `blocked_by_alert` | An active compliance alert blocks the customer |
153
+ | `423` | `custody_lock_unavailable` | The custody is locked by a concurrent operation |
154
+ | `503` | `custody_vault_unavailable` | The custodian's vault is unavailable |
155
+ | `503` | `custody_gas_unavailable` | Gas is unavailable at the custodian |
156
+ | `503` | `custody_address_unverifiable` | The destination address could not be verified |
157
+
158
+ ## Related
159
+
160
+ - [Assets](../concepts.md#assets) — uuid or ISO code, case
161
+ - [Amounts](../concepts.md#amounts) — crypto amounts as strings, minimums
162
+ - [Assets catalogue](asset.md) — the decimals (`baseUnit`) and state of each asset
163
+ - [Trading](trading.md) — sales take crypto from custody
164
+ - [Staking](staking.md) — staking moves crypto from custody to the provider
165
+ - [Transactions](transaction.md) — the journal where deposits and withdrawals appear
166
+ - [Webhooks](webhooks.md) — `custody.wallet.created`, `custody.received`, `custody.sent`, `custody.transaction`