@coinbase/cdp-sdk 1.1.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (311) hide show
  1. package/CHANGELOG.md +79 -0
  2. package/LICENSE +21 -0
  3. package/{dist → _cjs}/accounts/evm/toEvmServerAccount.js +1 -0
  4. package/_cjs/accounts/evm/toEvmServerAccount.js.map +1 -0
  5. package/{dist → _cjs}/accounts/evm/toEvmSmartAccount.js +1 -0
  6. package/_cjs/accounts/evm/toEvmSmartAccount.js.map +1 -0
  7. package/{dist → _cjs}/accounts/types.js +1 -0
  8. package/_cjs/accounts/types.js.map +1 -0
  9. package/{dist → _cjs}/actions/evm/sendUserOperation.js +1 -0
  10. package/_cjs/actions/evm/sendUserOperation.js.map +1 -0
  11. package/{dist → _cjs}/actions/evm/waitForUserOperation.js +10 -9
  12. package/_cjs/actions/evm/waitForUserOperation.js.map +1 -0
  13. package/{dist → _cjs}/analytics.js +7 -6
  14. package/_cjs/analytics.js.map +1 -0
  15. package/{dist → _cjs}/auth/errors.js +1 -0
  16. package/_cjs/auth/errors.js.map +1 -0
  17. package/{dist → _cjs}/auth/hooks/axios/index.js +2 -1
  18. package/_cjs/auth/hooks/axios/index.js.map +1 -0
  19. package/{dist → _cjs}/auth/hooks/axios/withAuth.js +3 -2
  20. package/_cjs/auth/hooks/axios/withAuth.js.map +1 -0
  21. package/{dist → _cjs}/auth/index.js +4 -3
  22. package/_cjs/auth/index.js.map +1 -0
  23. package/{dist → _cjs}/auth/utils/http.js +6 -5
  24. package/_cjs/auth/utils/http.js.map +1 -0
  25. package/{dist → _cjs}/auth/utils/index.js +3 -2
  26. package/_cjs/auth/utils/index.js.map +1 -0
  27. package/{dist → _cjs}/auth/utils/jwt.js +4 -3
  28. package/_cjs/auth/utils/jwt.js.map +1 -0
  29. package/{dist → _cjs}/client/cdp.js +13 -8
  30. package/_cjs/client/cdp.js.map +1 -0
  31. package/{dist → _cjs}/client/evm/evm.js +30 -28
  32. package/_cjs/client/evm/evm.js.map +1 -0
  33. package/{dist → _cjs}/client/evm/evm.types.js +1 -0
  34. package/_cjs/client/evm/evm.types.js.map +1 -0
  35. package/{dist → _cjs}/client/solana/index.js +3 -2
  36. package/_cjs/client/solana/index.js.map +1 -0
  37. package/{dist → _cjs}/client/solana/solana.js +9 -8
  38. package/_cjs/client/solana/solana.js.map +1 -0
  39. package/{dist → _cjs}/client/solana/solana.types.js +1 -0
  40. package/_cjs/client/solana/solana.types.js.map +1 -0
  41. package/{dist → _cjs}/constants.js +1 -0
  42. package/_cjs/constants.js.map +1 -0
  43. package/{dist → _cjs}/errors.js +1 -0
  44. package/_cjs/errors.js.map +1 -0
  45. package/{dist → _cjs}/index.js +4 -3
  46. package/_cjs/index.js.map +1 -0
  47. package/{dist → _cjs}/openapi-client/cdpApiClient.js +18 -14
  48. package/_cjs/openapi-client/cdpApiClient.js.map +1 -0
  49. package/{dist → _cjs}/openapi-client/errors.js +6 -0
  50. package/_cjs/openapi-client/errors.js.map +1 -0
  51. package/{dist → _cjs}/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +31 -30
  52. package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -0
  53. package/{dist → _cjs}/openapi-client/generated/evm-accounts/evm-accounts.js +46 -41
  54. package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.js.map +1 -0
  55. package/{dist → _cjs}/openapi-client/generated/evm-accounts/evm-accounts.msw.js +73 -40
  56. package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.msw.js.map +1 -0
  57. package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js +69 -0
  58. package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js.map +1 -0
  59. package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js +188 -0
  60. package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js.map +1 -0
  61. package/{dist → _cjs}/openapi-client/generated/faucets/faucets.js +18 -13
  62. package/_cjs/openapi-client/generated/faucets/faucets.js.map +1 -0
  63. package/{dist → _cjs}/openapi-client/generated/faucets/faucets.msw.js +16 -12
  64. package/_cjs/openapi-client/generated/faucets/faucets.msw.js.map +1 -0
  65. package/{dist → _cjs}/openapi-client/generated/index.msw.js +5 -4
  66. package/_cjs/openapi-client/generated/index.msw.js.map +1 -0
  67. package/{dist → _cjs}/openapi-client/generated/solana-accounts/solana-accounts.js +38 -35
  68. package/_cjs/openapi-client/generated/solana-accounts/solana-accounts.js.map +1 -0
  69. package/{dist → _cjs}/openapi-client/generated/solana-accounts/solana-accounts.msw.js +68 -35
  70. package/_cjs/openapi-client/generated/solana-accounts/solana-accounts.msw.js.map +1 -0
  71. package/{dist → _cjs}/openapi-client/index.js +12 -11
  72. package/_cjs/openapi-client/index.js.map +1 -0
  73. package/_cjs/package.json +1 -0
  74. package/{dist → _cjs}/types/calls.js +1 -0
  75. package/_cjs/types/calls.js.map +1 -0
  76. package/{dist → _cjs}/types/contract.js +1 -0
  77. package/_cjs/types/contract.js.map +1 -0
  78. package/{dist → _cjs}/types/misc.js +1 -0
  79. package/_cjs/types/misc.js.map +1 -0
  80. package/{dist → _cjs}/types/multicall.js +1 -0
  81. package/_cjs/types/multicall.js.map +1 -0
  82. package/{dist → _cjs}/types/utils.js +1 -0
  83. package/_cjs/types/utils.js.map +1 -0
  84. package/{dist → _cjs}/utils/wait.js +3 -2
  85. package/_cjs/utils/wait.js.map +1 -0
  86. package/_cjs/version.js +5 -0
  87. package/_cjs/version.js.map +1 -0
  88. package/_esm/accounts/evm/toEvmServerAccount.js +40 -0
  89. package/_esm/accounts/evm/toEvmServerAccount.js.map +1 -0
  90. package/_esm/accounts/evm/toEvmSmartAccount.js +22 -0
  91. package/_esm/accounts/evm/toEvmSmartAccount.js.map +1 -0
  92. package/_esm/accounts/types.js +2 -0
  93. package/_esm/accounts/types.js.map +1 -0
  94. package/_esm/actions/evm/sendUserOperation.js +85 -0
  95. package/_esm/actions/evm/sendUserOperation.js.map +1 -0
  96. package/_esm/actions/evm/waitForUserOperation.js +58 -0
  97. package/_esm/actions/evm/waitForUserOperation.js.map +1 -0
  98. package/_esm/analytics.js +84 -0
  99. package/_esm/analytics.js.map +1 -0
  100. package/_esm/auth/errors.js +57 -0
  101. package/_esm/auth/errors.js.map +1 -0
  102. package/_esm/auth/hooks/axios/index.js +2 -0
  103. package/_esm/auth/hooks/axios/index.js.map +1 -0
  104. package/_esm/auth/hooks/axios/withAuth.js +71 -0
  105. package/_esm/auth/hooks/axios/withAuth.js.map +1 -0
  106. package/_esm/auth/index.js +5 -0
  107. package/_esm/auth/index.js.map +1 -0
  108. package/_esm/auth/utils/http.js +70 -0
  109. package/_esm/auth/utils/http.js.map +1 -0
  110. package/_esm/auth/utils/index.js +3 -0
  111. package/_esm/auth/utils/index.js.map +1 -0
  112. package/_esm/auth/utils/jwt.js +199 -0
  113. package/_esm/auth/utils/jwt.js.map +1 -0
  114. package/_esm/client/cdp.js +95 -0
  115. package/_esm/client/cdp.js.map +1 -0
  116. package/_esm/client/evm/evm.js +518 -0
  117. package/_esm/client/evm/evm.js.map +1 -0
  118. package/_esm/client/evm/evm.types.js +2 -0
  119. package/_esm/client/evm/evm.types.js.map +1 -0
  120. package/_esm/client/solana/index.js +2 -0
  121. package/_esm/client/solana/index.js.map +1 -0
  122. package/_esm/client/solana/solana.js +204 -0
  123. package/_esm/client/solana/solana.js.map +1 -0
  124. package/_esm/client/solana/solana.types.js +2 -0
  125. package/_esm/client/solana/solana.types.js.map +1 -0
  126. package/_esm/constants.js +5 -0
  127. package/_esm/constants.js.map +1 -0
  128. package/_esm/errors.js +18 -0
  129. package/_esm/errors.js.map +1 -0
  130. package/_esm/index.js +3 -0
  131. package/_esm/index.js.map +1 -0
  132. package/_esm/openapi-client/cdpApiClient.js +112 -0
  133. package/_esm/openapi-client/cdpApiClient.js.map +1 -0
  134. package/_esm/openapi-client/errors.js +71 -0
  135. package/_esm/openapi-client/errors.js.map +1 -0
  136. package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +52 -0
  137. package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -0
  138. package/_esm/openapi-client/generated/evm-accounts/evm-accounts.js +80 -0
  139. package/_esm/openapi-client/generated/evm-accounts/evm-accounts.js.map +1 -0
  140. package/_esm/openapi-client/generated/evm-accounts/evm-accounts.msw.js +128 -0
  141. package/_esm/openapi-client/generated/evm-accounts/evm-accounts.msw.js.map +1 -0
  142. package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js +60 -0
  143. package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js.map +1 -0
  144. package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js +172 -0
  145. package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js.map +1 -0
  146. package/_esm/openapi-client/generated/faucets/faucets.js +51 -0
  147. package/_esm/openapi-client/generated/faucets/faucets.js.map +1 -0
  148. package/_esm/openapi-client/generated/faucets/faucets.msw.js +39 -0
  149. package/_esm/openapi-client/generated/faucets/faucets.msw.js.map +1 -0
  150. package/_esm/openapi-client/generated/index.msw.js +5 -0
  151. package/_esm/openapi-client/generated/index.msw.js.map +1 -0
  152. package/_esm/openapi-client/generated/solana-accounts/solana-accounts.js +73 -0
  153. package/_esm/openapi-client/generated/solana-accounts/solana-accounts.js.map +1 -0
  154. package/_esm/openapi-client/generated/solana-accounts/solana-accounts.msw.js +116 -0
  155. package/_esm/openapi-client/generated/solana-accounts/solana-accounts.msw.js.map +1 -0
  156. package/_esm/openapi-client/index.js +27 -0
  157. package/_esm/openapi-client/index.js.map +1 -0
  158. package/_esm/package.json +1 -0
  159. package/_esm/types/calls.js +4 -0
  160. package/_esm/types/calls.js.map +1 -0
  161. package/_esm/types/contract.js +4 -0
  162. package/_esm/types/contract.js.map +1 -0
  163. package/_esm/types/misc.js +3 -0
  164. package/_esm/types/misc.js.map +1 -0
  165. package/_esm/types/multicall.js +2 -0
  166. package/_esm/types/multicall.js.map +1 -0
  167. package/_esm/types/utils.js +4 -0
  168. package/_esm/types/utils.js.map +1 -0
  169. package/_esm/utils/wait.js +32 -0
  170. package/_esm/utils/wait.js.map +1 -0
  171. package/_esm/version.js +2 -0
  172. package/_esm/version.js.map +1 -0
  173. package/{dist → _types}/accounts/evm/toEvmServerAccount.d.ts +3 -2
  174. package/_types/accounts/evm/toEvmServerAccount.d.ts.map +1 -0
  175. package/{dist → _types}/accounts/evm/toEvmSmartAccount.d.ts +3 -2
  176. package/_types/accounts/evm/toEvmSmartAccount.d.ts.map +1 -0
  177. package/{dist → _types}/accounts/types.d.ts +3 -2
  178. package/_types/accounts/types.d.ts.map +1 -0
  179. package/{dist → _types}/actions/evm/sendUserOperation.d.ts +5 -5
  180. package/_types/actions/evm/sendUserOperation.d.ts.map +1 -0
  181. package/{dist → _types}/actions/evm/waitForUserOperation.d.ts +4 -3
  182. package/_types/actions/evm/waitForUserOperation.d.ts.map +1 -0
  183. package/{dist → _types}/analytics.d.ts +1 -0
  184. package/_types/analytics.d.ts.map +1 -0
  185. package/{dist → _types}/auth/errors.d.ts +1 -0
  186. package/_types/auth/errors.d.ts.map +1 -0
  187. package/_types/auth/hooks/axios/index.d.ts +2 -0
  188. package/_types/auth/hooks/axios/index.d.ts.map +1 -0
  189. package/{dist → _types}/auth/hooks/axios/withAuth.d.ts +1 -0
  190. package/_types/auth/hooks/axios/withAuth.d.ts.map +1 -0
  191. package/_types/auth/index.d.ts +5 -0
  192. package/_types/auth/index.d.ts.map +1 -0
  193. package/{dist → _types}/auth/utils/http.d.ts +1 -0
  194. package/_types/auth/utils/http.d.ts.map +1 -0
  195. package/_types/auth/utils/index.d.ts +3 -0
  196. package/_types/auth/utils/index.d.ts.map +1 -0
  197. package/{dist → _types}/auth/utils/jwt.d.ts +1 -0
  198. package/_types/auth/utils/jwt.d.ts.map +1 -0
  199. package/{dist → _types}/client/cdp.d.ts +3 -2
  200. package/_types/client/cdp.d.ts.map +1 -0
  201. package/{dist → _types}/client/evm/evm.d.ts +4 -3
  202. package/_types/client/evm/evm.d.ts.map +1 -0
  203. package/{dist → _types}/client/evm/evm.types.d.ts +7 -6
  204. package/_types/client/evm/evm.types.d.ts.map +1 -0
  205. package/_types/client/solana/index.d.ts +2 -0
  206. package/_types/client/solana/index.d.ts.map +1 -0
  207. package/{dist → _types}/client/solana/solana.d.ts +2 -1
  208. package/_types/client/solana/solana.d.ts.map +1 -0
  209. package/{dist → _types}/client/solana/solana.types.d.ts +2 -1
  210. package/_types/client/solana/solana.types.d.ts.map +1 -0
  211. package/{dist → _types}/constants.d.ts +1 -0
  212. package/_types/constants.d.ts.map +1 -0
  213. package/{dist → _types}/errors.d.ts +1 -0
  214. package/_types/errors.d.ts.map +1 -0
  215. package/_types/index.d.ts +4 -0
  216. package/_types/index.d.ts.map +1 -0
  217. package/{dist → _types}/openapi-client/cdpApiClient.d.ts +1 -0
  218. package/_types/openapi-client/cdpApiClient.d.ts.map +1 -0
  219. package/{dist → _types}/openapi-client/errors.d.ts +2 -1
  220. package/_types/openapi-client/errors.d.ts.map +1 -0
  221. package/{dist → _types}/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts +13 -12
  222. package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts.map +1 -0
  223. package/{dist → _types}/openapi-client/generated/evm-accounts/evm-accounts.d.ts +24 -23
  224. package/_types/openapi-client/generated/evm-accounts/evm-accounts.d.ts.map +1 -0
  225. package/{dist → _types}/openapi-client/generated/evm-accounts/evm-accounts.msw.d.ts +3 -2
  226. package/_types/openapi-client/generated/evm-accounts/evm-accounts.msw.d.ts.map +1 -0
  227. package/{dist → _types}/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.d.ts +21 -20
  228. package/_types/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.d.ts.map +1 -0
  229. package/{dist → _types}/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.d.ts +3 -2
  230. package/_types/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.d.ts.map +1 -0
  231. package/{dist → _types}/openapi-client/generated/faucets/faucets.d.ts +9 -8
  232. package/_types/openapi-client/generated/faucets/faucets.d.ts.map +1 -0
  233. package/{dist → _types}/openapi-client/generated/faucets/faucets.msw.d.ts +3 -2
  234. package/_types/openapi-client/generated/faucets/faucets.msw.d.ts.map +1 -0
  235. package/_types/openapi-client/generated/index.msw.d.ts +5 -0
  236. package/_types/openapi-client/generated/index.msw.d.ts.map +1 -0
  237. package/{dist → _types}/openapi-client/generated/solana-accounts/solana-accounts.d.ts +21 -20
  238. package/_types/openapi-client/generated/solana-accounts/solana-accounts.d.ts.map +1 -0
  239. package/{dist → _types}/openapi-client/generated/solana-accounts/solana-accounts.msw.d.ts +3 -2
  240. package/_types/openapi-client/generated/solana-accounts/solana-accounts.msw.d.ts.map +1 -0
  241. package/_types/openapi-client/index.d.ts +56 -0
  242. package/_types/openapi-client/index.d.ts.map +1 -0
  243. package/{dist → _types}/types/calls.d.ts +4 -3
  244. package/_types/types/calls.d.ts.map +1 -0
  245. package/{dist → _types}/types/contract.d.ts +3 -2
  246. package/_types/types/contract.d.ts.map +1 -0
  247. package/{dist → _types}/types/misc.d.ts +1 -0
  248. package/_types/types/misc.d.ts.map +1 -0
  249. package/{dist → _types}/types/multicall.d.ts +2 -1
  250. package/_types/types/multicall.d.ts.map +1 -0
  251. package/{dist → _types}/types/utils.d.ts +1 -0
  252. package/_types/types/utils.d.ts.map +1 -0
  253. package/{dist → _types}/utils/wait.d.ts +1 -0
  254. package/_types/utils/wait.d.ts.map +1 -0
  255. package/_types/version.d.ts +2 -0
  256. package/_types/version.d.ts.map +1 -0
  257. package/accounts/evm/toEvmServerAccount.ts +60 -0
  258. package/accounts/evm/toEvmSmartAccount.ts +37 -0
  259. package/accounts/types.ts +53 -0
  260. package/actions/evm/sendUserOperation.ts +163 -0
  261. package/actions/evm/waitForUserOperation.ts +115 -0
  262. package/analytics.ts +123 -0
  263. package/auth/README.md +145 -0
  264. package/auth/errors.ts +59 -0
  265. package/auth/hooks/axios/index.ts +1 -0
  266. package/auth/hooks/axios/withAuth.ts +120 -0
  267. package/auth/index.ts +5 -0
  268. package/auth/utils/http.ts +146 -0
  269. package/auth/utils/index.ts +2 -0
  270. package/auth/utils/jwt.ts +324 -0
  271. package/client/cdp.ts +113 -0
  272. package/client/evm/evm.ts +606 -0
  273. package/client/evm/evm.types.ts +303 -0
  274. package/client/solana/index.ts +1 -0
  275. package/client/solana/solana.ts +237 -0
  276. package/client/solana/solana.types.ts +114 -0
  277. package/constants.ts +4 -0
  278. package/errors.ts +17 -0
  279. package/index.ts +4 -0
  280. package/openapi-client/cdpApiClient.ts +214 -0
  281. package/openapi-client/errors.ts +96 -0
  282. package/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.ts +411 -0
  283. package/openapi-client/generated/evm-accounts/evm-accounts.msw.ts +242 -0
  284. package/openapi-client/generated/evm-accounts/evm-accounts.ts +150 -0
  285. package/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.ts +283 -0
  286. package/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.ts +131 -0
  287. package/openapi-client/generated/faucets/faucets.msw.ts +76 -0
  288. package/openapi-client/generated/faucets/faucets.ts +83 -0
  289. package/openapi-client/generated/index.msw.ts +4 -0
  290. package/openapi-client/generated/solana-accounts/solana-accounts.msw.ts +219 -0
  291. package/openapi-client/generated/solana-accounts/solana-accounts.ts +143 -0
  292. package/openapi-client/index.ts +32 -0
  293. package/package.json +31 -66
  294. package/types/calls.ts +40 -0
  295. package/types/contract.ts +126 -0
  296. package/types/misc.ts +5 -0
  297. package/types/multicall.ts +29 -0
  298. package/types/utils.ts +288 -0
  299. package/utils/wait.ts +52 -0
  300. package/version.ts +1 -0
  301. package/dist/auth/hooks/axios/index.d.ts +0 -1
  302. package/dist/auth/index.d.ts +0 -4
  303. package/dist/auth/utils/index.d.ts +0 -2
  304. package/dist/client/evm/index.d.ts +0 -1
  305. package/dist/client/evm/index.js +0 -5
  306. package/dist/client/solana/index.d.ts +0 -1
  307. package/dist/index.d.ts +0 -3
  308. package/dist/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js +0 -66
  309. package/dist/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js +0 -99
  310. package/dist/openapi-client/generated/index.msw.d.ts +0 -4
  311. package/dist/openapi-client/index.d.ts +0 -55
package/auth/README.md ADDED
@@ -0,0 +1,145 @@
1
+ ### Overview
2
+
3
+ The following methods can be used to authenticate your requests to the [Coinbase Developer Platform (CDP)](https://docs.cdp.coinbase.com/). Choose the method that best suits your needs:
4
+
5
+ | Method | Difficulty | Description |
6
+ | :-- | :-- | :-- |
7
+ | [Use an Axios request client](#use-an-axios-request-interceptor) | Easy | Use an [Axios](https://axios-http.com/docs/intro) client with a pre-configured interceptor that automatically handles authentication for all requests. |
8
+ | [Generate your authorization headers](#generate-your-authorization-headers) | Intermediate | Generate authentication headers and apply them to your preferred HTTP client. |
9
+ | [Generate a JWT](#generate-a-jwt) | Advanced | Generate a JWT token, manually create your authentication headers, and apply them to your preferred HTTP client. |
10
+
11
+ Visit the [CDP Authentication docs](https://docs.cdp.coinbase.com/api-v2/docs/authentication) for more details.
12
+
13
+ ### Generate a JWT
14
+
15
+ The following example shows how to generate a JWT token, which can then be injected manually into your `Authorization` header to authenticate REST API requests to the [CDP APIs](https://docs.cdp.coinbase.com/api-v2/docs/welcome) using the HTTP request library of your choice.
16
+
17
+ **Step 1**: Install the required package:
18
+
19
+ ```bash
20
+ npm install @coinbase/cdp-sdk
21
+ ```
22
+
23
+ **Step 2**: Generate a JWT:
24
+
25
+ ```typescript
26
+ import { generateJwt } from "@coinbase/cdp-sdk/auth";
27
+
28
+ const jwt = await generateJwt({
29
+ apiKeyId: "YOUR_API_KEY_ID",
30
+ apiKeySecret: "YOUR_API_KEY_SECRET",
31
+ requestMethod: "GET",
32
+ requestHost: "api.cdp.coinbase.com",
33
+ requestPath: "/platform/v2/evm/accounts",
34
+ expiresIn: 120, // optional (defaults to 120 seconds)
35
+ });
36
+
37
+ console.log(jwt);
38
+ ```
39
+
40
+ For information about the above parameters, please refer to the [Authentication parameters](#authentication-parameters) section.
41
+
42
+ **Step 3**: Use your JWT (Bearer token) in the `Authorization` header of your HTTP request:
43
+
44
+ ```bash
45
+ curl -L 'https://api.cdp.coinbase.com/platform/v2/evm/accounts' \
46
+ -H 'Content-Type: application/json' \
47
+ -H 'Accept: application/json' \
48
+ -H 'Authorization: Bearer $jwt'
49
+ ```
50
+
51
+ ### Generate your authorization headers
52
+
53
+ The following example shows how to generate the required authentication headers for authenticating a request to the [CDP REST APIs](https://docs.cdp.coinbase.com/api-v2/docs/welcome), using the HTTP request library of your choice.
54
+
55
+ **Step 1**: Install the required package:
56
+
57
+ ```bash
58
+ npm install @coinbase/cdp-sdk
59
+ ```
60
+
61
+ **Step 2**: Generate authorization headers:
62
+
63
+ ```typescript
64
+ import { getAuthHeaders } from "@coinbase/cdp-sdk/auth";
65
+
66
+ const headers = await getAuthHeaders({
67
+ apiKeyId: "YOUR_API_KEY_ID",
68
+ apiKeySecret: "YOUR_API_KEY_SECRET",
69
+ walletSecret: "YOUR_WALLET_SECRET",
70
+ requestMethod: "POST",
71
+ requestHost: "api.cdp.coinbase.com",
72
+ requestPath: "/platform/v2/evm/accounts",
73
+ requestBody: {
74
+ name: "MyAccount",
75
+ },
76
+ expiresIn: 120, // optional (defaults to 120 seconds)
77
+ });
78
+
79
+ console.log(headers);
80
+ ```
81
+
82
+ For information about the above parameters, please refer to the [Authentication parameters](#authentication-parameters) section.
83
+
84
+ ### Use an Axios request interceptor
85
+
86
+ **Step 1**: Install the required packages:
87
+
88
+ ```bash
89
+ npm install @coinbase/cdp-sdk axios
90
+ ```
91
+
92
+ **Step 2**: Create an authenticated Axios client:
93
+
94
+ The following example shows how to use an [Axios](https://axios-http.com/docs/intro) HTTP client with a pre-configured interceptor to authenticate your requests to the CDP REST APIs. This client will automatically add the appropriate authentication headers to each request.
95
+
96
+ ```typescript
97
+ import axios from "axios";
98
+ import { axiosHooks } from "@coinbase/cdp-sdk/auth";
99
+
100
+ // Create an Axios instance
101
+ const axiosClient = axios.create({
102
+ baseURL: "https://api.cdp.coinbase.com",
103
+ });
104
+
105
+ // Add authentication to the client
106
+ axiosHooks.withAuth(axiosClient, {
107
+ apiKeyId: "YOUR_API_KEY_ID",
108
+ apiKeySecret: "YOUR_API_KEY_SECRET",
109
+ walletSecret: "YOUR_WALLET_SECRET",
110
+ });
111
+
112
+ // Make authenticated requests (example)
113
+ // The appropriate authentication headers will be automatically added to the request
114
+ try {
115
+ const response = await axiosClient.post("/platform/v2/evm/accounts", {
116
+ name: "MyAccount",
117
+ });
118
+ console.log(response.data);
119
+ } catch (error) {
120
+ console.error("Request failed:", error);
121
+ }
122
+ ```
123
+
124
+ The Axios interceptor will automatically:
125
+
126
+ - Generate a JWT for each request
127
+ - Add the JWT to the `Authorization` header
128
+ - Set the appropriate `Content-Type` header
129
+ - Add wallet authentication when required
130
+
131
+ For information about the above parameters, please refer to the [Authentication parameters](#authentication-parameters) section.
132
+
133
+ ### Authentication parameters
134
+
135
+ The following table provides more context of many of the authentication parameters used in the examples above:
136
+
137
+ | Parameter | Required | Description |
138
+ | :-- | :-- | :-- |
139
+ | `apiKeyId` | true | The unique identifier for your API key. Supported formats are:<br/>- `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`<br/>- `organizations/{orgId}/apiKeys/{keyId}` |
140
+ | `apiKeySecret` | true | Your API key secret. Supported formats are:<br/>- Edwards key (Ed25519): `xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx==`<br/>- Elliptic Curve key (ES256): `-----BEGIN EC PRIVATE KEY-----\n...\n...\n...==\n-----END EC PRIVATE KEY-----\n` |
141
+ | `requestMethod` | true | The HTTP method for the API request you're authenticating (ie, `GET`, `POST`, `PUT`, `DELETE`). |
142
+ | `requestHost` | true | The API host you're calling (ie, `api.cdp.coinbase.com`). |
143
+ | `requestPath` | true | The path of the specific API endpoint you're calling (ie, `/platform/v1/wallets`). |
144
+ | `requestBody` | false | Optional request body data. |
145
+ | `expiresIn` | false | The JWT expiration time in seconds. After this time, the JWT will no longer be valid, and a new one must be generated. Defaults to `120` (ie, 2 minutes) if not specified. |
package/auth/errors.ts ADDED
@@ -0,0 +1,59 @@
1
+ /**
2
+ * A class of errors for capturing stack traces.
3
+ */
4
+ class BaseError extends Error {
5
+ /**
6
+ * Base error constructor.
7
+ *
8
+ * @param message - The message to display.
9
+ */
10
+ constructor(message: string) {
11
+ super(message);
12
+ this.name = this.constructor.name;
13
+ if (Error.captureStackTrace) {
14
+ Error.captureStackTrace(this, this.constructor);
15
+ }
16
+ }
17
+ }
18
+
19
+ /**
20
+ * An error for invalid API key format.
21
+ */
22
+ export class InvalidAPIKeyFormatError extends BaseError {
23
+ /**
24
+ * Invalid API key format error constructor.
25
+ *
26
+ * @param message - The message to display.
27
+ */
28
+ constructor(message: string) {
29
+ super("Invalid API key format: " + message);
30
+ }
31
+ }
32
+
33
+ /**
34
+ * An error for invalid Wallet Secret format.
35
+ */
36
+ export class InvalidWalletSecretFormatError extends BaseError {
37
+ /**
38
+ * Invalid Wallet Secret format error constructor.
39
+ *
40
+ * @param message - The message to display.
41
+ */
42
+ constructor(message: string) {
43
+ super("Invalid Wallet Secret format: " + message);
44
+ }
45
+ }
46
+
47
+ /**
48
+ * An error for an undefined Wallet Secret.
49
+ */
50
+ export class UndefinedWalletSecretError extends BaseError {
51
+ /**
52
+ * Undefined Wallet Secret error constructor.
53
+ *
54
+ * @param message - The message to display.
55
+ */
56
+ constructor(message: string) {
57
+ super("Undefined Wallet Secret: " + message);
58
+ }
59
+ }
@@ -0,0 +1 @@
1
+ export * from "./withAuth.js";
@@ -0,0 +1,120 @@
1
+ import { AxiosInstance, AxiosHeaders } from "axios";
2
+
3
+ import { getAuthHeaders } from "../../utils/http.js";
4
+
5
+ export interface AuthInterceptorOptions {
6
+ /**
7
+ * The API key ID
8
+ *
9
+ * Examples:
10
+ * 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
11
+ * 'organizations/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/apiKeys/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
12
+ */
13
+ apiKeyId: string;
14
+
15
+ /**
16
+ * The API key secret
17
+ *
18
+ * Examples:
19
+ * 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx==' (Edwards key (Ed25519))
20
+ * '-----BEGIN EC PRIVATE KEY-----\n...\n...\n...==\n-----END EC PRIVATE KEY-----\n' (EC key (ES256))
21
+ */
22
+ apiKeySecret: string;
23
+
24
+ /** The Wallet Secret */
25
+ walletSecret?: string;
26
+
27
+ /** The source of the request */
28
+ source?: string;
29
+
30
+ /** The version of the source of the request */
31
+ sourceVersion?: string;
32
+
33
+ /** Optional expiration time in seconds (defaults to 120) */
34
+ expiresIn?: number;
35
+
36
+ /** Whether to log request/response details */
37
+ debug?: boolean;
38
+ }
39
+
40
+ /**
41
+ * Axios interceptor for adding the JWT to the Authorization header.
42
+ *
43
+ * @param axiosClient - The Axios client instance to add the interceptor to
44
+ * @param options - Options for the request including API keys and debug flag
45
+ * @returns The modified request configuration with the Authorization header added
46
+ */
47
+ export function withAuth(axiosClient: AxiosInstance, options: AuthInterceptorOptions) {
48
+ axiosClient.interceptors.request.use(async axiosConfig => {
49
+ const method = axiosConfig.method?.toString().toUpperCase() || "GET";
50
+
51
+ if (!axiosConfig.url) {
52
+ throw new Error("URL is required for authentication");
53
+ }
54
+
55
+ const fullyQualifiedURL = axiosClient.getUri() + axiosConfig.url;
56
+
57
+ // Parse URL to get host and path
58
+ const url = new URL(fullyQualifiedURL);
59
+
60
+ // Get authentication headers
61
+ const headers = await getAuthHeaders({
62
+ apiKeyId: options.apiKeyId,
63
+ apiKeySecret: options.apiKeySecret,
64
+ requestMethod: method,
65
+ requestHost: url.host,
66
+ requestPath: url.pathname,
67
+ requestBody: axiosConfig.data,
68
+ walletSecret: options.walletSecret,
69
+ source: options.source,
70
+ sourceVersion: options.sourceVersion,
71
+ expiresIn: options.expiresIn,
72
+ });
73
+
74
+ // Add headers to request config
75
+ axiosConfig.headers = new AxiosHeaders({
76
+ ...axiosConfig.headers,
77
+ ...headers,
78
+ });
79
+
80
+ if (options.debug) {
81
+ console.log("Request:", {
82
+ method,
83
+ url: fullyQualifiedURL,
84
+ headers: axiosConfig.headers,
85
+ data: axiosConfig.data,
86
+ });
87
+ }
88
+
89
+ return axiosConfig;
90
+ });
91
+
92
+ if (options.debug) {
93
+ axiosClient.interceptors.response.use(
94
+ response => {
95
+ console.log("Response:", {
96
+ status: response.status,
97
+ statusText: response.statusText,
98
+ headers: response.headers,
99
+ data: response.data,
100
+ });
101
+ return response;
102
+ },
103
+ error => {
104
+ // Ensure we have access to the error response details
105
+ const errorDetails = {
106
+ status: error.response?.status,
107
+ statusText: error.response?.statusText,
108
+ headers: error.response?.headers,
109
+ data: error.response?.data,
110
+ message: error.message,
111
+ };
112
+
113
+ console.error("Response Error:", errorDetails);
114
+ return Promise.reject(error);
115
+ },
116
+ );
117
+ }
118
+
119
+ return axiosClient;
120
+ }
package/auth/index.ts ADDED
@@ -0,0 +1,5 @@
1
+ import * as axiosHooks from "./hooks/axios/index.js";
2
+
3
+ export * from "./utils/http.js";
4
+ export * from "./utils/jwt.js";
5
+ export { axiosHooks };
@@ -0,0 +1,146 @@
1
+ import { generateWalletJwt, generateJwt } from "./jwt.js";
2
+ import { version } from "../../version.js";
3
+
4
+ /**
5
+ * Options for generating authentication headers for API requests.
6
+ */
7
+ export interface GetAuthHeadersOptions {
8
+ /**
9
+ * The API key ID
10
+ *
11
+ * Examples:
12
+ * 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
13
+ * 'organizations/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/apiKeys/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
14
+ */
15
+ apiKeyId: string;
16
+
17
+ /**
18
+ * The API key secret
19
+ *
20
+ * Examples:
21
+ * 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx==' (Edwards key (Ed25519))
22
+ * '-----BEGIN EC PRIVATE KEY-----\n...\n...\n...==\n-----END EC PRIVATE KEY-----\n' (EC key (ES256))
23
+ */
24
+ apiKeySecret: string;
25
+
26
+ /**
27
+ * The HTTP method for the request (e.g. 'GET', 'POST')
28
+ */
29
+ requestMethod: string;
30
+
31
+ /**
32
+ * The host for the request (e.g. 'api.cdp.coinbase.com')
33
+ */
34
+ requestHost: string;
35
+
36
+ /**
37
+ * The path for the request (e.g. '/platform/v1/wallets')
38
+ */
39
+ requestPath: string;
40
+
41
+ /**
42
+ * Optional request body data
43
+ */
44
+ requestBody?: unknown;
45
+
46
+ /**
47
+ * The Wallet Secret for wallet authentication
48
+ */
49
+ walletSecret?: string;
50
+
51
+ /**
52
+ * The source identifier for the request
53
+ */
54
+ source?: string;
55
+
56
+ /**
57
+ * The version of the source making the request
58
+ */
59
+ sourceVersion?: string;
60
+
61
+ /**
62
+ * Optional expiration time in seconds (defaults to 120)
63
+ */
64
+ expiresIn?: number;
65
+ }
66
+
67
+ /**
68
+ * Gets authentication headers for a request.
69
+ *
70
+ * @param options - The configuration options for generating auth headers
71
+ * @returns Object containing the authentication headers
72
+ */
73
+ export async function getAuthHeaders(
74
+ options: GetAuthHeadersOptions,
75
+ ): Promise<Record<string, string>> {
76
+ const headers: Record<string, string> = {};
77
+
78
+ // Generate and add JWT token
79
+ const jwt = await generateJwt({
80
+ apiKeyId: options.apiKeyId,
81
+ apiKeySecret: options.apiKeySecret,
82
+ requestMethod: options.requestMethod,
83
+ requestHost: options.requestHost,
84
+ requestPath: options.requestPath,
85
+ expiresIn: options.expiresIn,
86
+ });
87
+ headers["Authorization"] = `Bearer ${jwt}`;
88
+ headers["Content-Type"] = "application/json";
89
+
90
+ // Add wallet auth if needed
91
+ if (requiresWalletAuth(options.requestMethod, options.requestPath)) {
92
+ if (!options.walletSecret) {
93
+ throw new Error(
94
+ "Wallet Secret not configured. Please set the CDP_WALLET_SECRET environment variable, or pass it as an option to the CdpClient constructor.",
95
+ );
96
+ }
97
+
98
+ const walletAuthToken = await generateWalletJwt({
99
+ walletSecret: options.walletSecret,
100
+ requestMethod: options.requestMethod,
101
+ requestHost: options.requestHost,
102
+ requestPath: options.requestPath,
103
+ requestData: options.requestBody || {},
104
+ });
105
+ headers["X-Wallet-Auth"] = walletAuthToken;
106
+ }
107
+
108
+ // Add correlation data
109
+ headers["Correlation-Context"] = getCorrelationData(options.source, options.sourceVersion);
110
+
111
+ return headers;
112
+ }
113
+
114
+ /**
115
+ * Returns true if the request indicated by the method and URL requires wallet authentication.
116
+ *
117
+ * @param requestMethod - The HTTP method of the request
118
+ * @param requestPath - The URL path of the request
119
+ * @returns True if the request requires wallet authentication, false otherwise
120
+ */
121
+ function requiresWalletAuth(requestMethod: string, requestPath: string): boolean {
122
+ return (
123
+ requestPath?.includes("/accounts") && (requestMethod === "POST" || requestMethod === "DELETE")
124
+ );
125
+ }
126
+
127
+ /**
128
+ * Returns encoded correlation data including the SDK version and language.
129
+ *
130
+ * @param source - The source identifier for the request
131
+ * @param sourceVersion - The version of the source making the request
132
+ * @returns Encoded correlation data as a query string
133
+ */
134
+ function getCorrelationData(source?: string, sourceVersion?: string): string {
135
+ const data = {
136
+ sdk_version: version,
137
+ sdk_language: "typescript",
138
+ source: source || "sdk-auth",
139
+ };
140
+ if (sourceVersion) {
141
+ data["source_version"] = sourceVersion;
142
+ }
143
+ return Object.keys(data)
144
+ .map(key => `${key}=${encodeURIComponent(data[key])}`)
145
+ .join(",");
146
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./http.js";
2
+ export * from "./jwt.js";