@circle-fin/daa-react-native-sdk 0.0.0-stage → 0.4.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 (304) hide show
  1. package/DaaReactNativeSdk.podspec +63 -0
  2. package/LICENSE +176 -0
  3. package/README.md +217 -2
  4. package/android/build.gradle +97 -0
  5. package/android/src/main/AndroidManifest.xml +1 -0
  6. package/android/src/main/java/com/circle/daa/reactnative/DaaRegistrationExceptions.kt +47 -0
  7. package/android/src/main/java/com/circle/daa/reactnative/DaaRegistrationModule.kt +121 -0
  8. package/android/src/main/java/com/circle/daa/reactnative/DaaScaExceptions.kt +60 -0
  9. package/android/src/main/java/com/circle/daa/reactnative/DaaScaModule.kt +179 -0
  10. package/android/src/main/java/com/circle/daa/reactnative/DaaSecureKeyExceptions.kt +73 -0
  11. package/android/src/main/java/com/circle/daa/reactnative/DaaSecureKeyModule.kt +185 -0
  12. package/android/src/main/java/com/circle/daa/reactnative/InstallationIdentityStore.kt +73 -0
  13. package/android/src/main/java/com/circle/daa/reactnative/UnpaddedBase64Url.kt +45 -0
  14. package/build/DaaClient.d.ts +57 -0
  15. package/build/DaaClient.js +158 -0
  16. package/build/api/AccountLimitsClient.d.ts +79 -0
  17. package/build/api/AccountLimitsClient.js +142 -0
  18. package/build/api/AccountsClient.d.ts +95 -0
  19. package/build/api/AccountsClient.js +276 -0
  20. package/build/api/AchFiatAccountsClient.d.ts +92 -0
  21. package/build/api/AchFiatAccountsClient.js +142 -0
  22. package/build/api/AuthClient.d.ts +120 -0
  23. package/build/api/AuthClient.js +257 -0
  24. package/build/api/DaaUserClient.d.ts +124 -0
  25. package/build/api/DaaUserClient.js +245 -0
  26. package/build/api/DepositAddressesClient.d.ts +112 -0
  27. package/build/api/DepositAddressesClient.js +222 -0
  28. package/build/api/DepositsClient.d.ts +106 -0
  29. package/build/api/DepositsClient.js +183 -0
  30. package/build/api/FiatAccountsClient.d.ts +43 -0
  31. package/build/api/FiatAccountsClient.js +46 -0
  32. package/build/api/TransactionsClient.d.ts +64 -0
  33. package/build/api/TransactionsClient.js +120 -0
  34. package/build/api/TransfersClient.d.ts +104 -0
  35. package/build/api/TransfersClient.js +321 -0
  36. package/build/api/WireFiatAccountsClient.d.ts +99 -0
  37. package/build/api/WireFiatAccountsClient.js +156 -0
  38. package/build/api/WithdrawalsClient.d.ts +94 -0
  39. package/build/api/WithdrawalsClient.js +305 -0
  40. package/build/api/loginFailure.d.ts +43 -0
  41. package/build/api/loginFailure.js +64 -0
  42. package/build/api/pagination.d.ts +29 -0
  43. package/build/api/pagination.js +50 -0
  44. package/build/api/queryParameters.d.ts +23 -0
  45. package/build/api/queryParameters.js +77 -0
  46. package/build/api/resourceRequest.d.ts +60 -0
  47. package/build/api/resourceRequest.js +79 -0
  48. package/build/api/signedResource.d.ts +77 -0
  49. package/build/api/signedResource.js +168 -0
  50. package/build/auth/RegistrationFlowKey.d.ts +93 -0
  51. package/build/auth/RegistrationFlowKey.js +203 -0
  52. package/build/auth/daaRegistrationNative.d.ts +80 -0
  53. package/build/auth/daaRegistrationNative.js +184 -0
  54. package/build/auth/deviceAuthorization.d.ts +73 -0
  55. package/build/auth/deviceAuthorization.js +243 -0
  56. package/build/auth/ownerGrant.d.ts +29 -0
  57. package/build/auth/ownerGrant.js +90 -0
  58. package/build/auth/prepareReceipt.d.ts +150 -0
  59. package/build/auth/prepareReceipt.js +357 -0
  60. package/build/auth/registrationAuthorization.d.ts +48 -0
  61. package/build/auth/registrationAuthorization.js +243 -0
  62. package/build/auth/registrationCodeVerifier.d.ts +31 -0
  63. package/build/auth/registrationCodeVerifier.js +75 -0
  64. package/build/config.d.ts +79 -0
  65. package/build/config.js +116 -0
  66. package/build/crypto/base64url.d.ts +26 -0
  67. package/build/crypto/base64url.js +87 -0
  68. package/build/crypto/bytes.d.ts +27 -0
  69. package/build/crypto/bytes.js +32 -0
  70. package/build/crypto/es256Jws.d.ts +56 -0
  71. package/build/crypto/es256Jws.js +196 -0
  72. package/build/crypto/jwkThumbprint.d.ts +32 -0
  73. package/build/crypto/jwkThumbprint.js +49 -0
  74. package/build/crypto/random.d.ts +35 -0
  75. package/build/crypto/random.js +106 -0
  76. package/build/crypto/serialization.d.ts +26 -0
  77. package/build/crypto/serialization.js +43 -0
  78. package/build/crypto/sha256.d.ts +18 -0
  79. package/build/crypto/sha256.js +100 -0
  80. package/build/errors.d.ts +190 -0
  81. package/build/errors.js +252 -0
  82. package/build/index.d.ts +61 -0
  83. package/build/index.js +67 -0
  84. package/build/models/Account.d.ts +201 -0
  85. package/build/models/Account.js +147 -0
  86. package/build/models/AccountLimitsUsage.d.ts +169 -0
  87. package/build/models/AccountLimitsUsage.js +86 -0
  88. package/build/models/Ach.d.ts +135 -0
  89. package/build/models/Ach.js +184 -0
  90. package/build/models/AddressObject.d.ts +128 -0
  91. package/build/models/AddressObject.js +141 -0
  92. package/build/models/BusinessPii.d.ts +84 -0
  93. package/build/models/BusinessPii.js +142 -0
  94. package/build/models/CreateAccountRequest.d.ts +74 -0
  95. package/build/models/CreateAccountRequest.js +19 -0
  96. package/build/models/CreateTransferRequest.d.ts +91 -0
  97. package/build/models/CreateTransferRequest.js +19 -0
  98. package/build/models/CreateWithdrawalRequest.d.ts +99 -0
  99. package/build/models/CreateWithdrawalRequest.js +19 -0
  100. package/build/models/DaaUserContext.d.ts +96 -0
  101. package/build/models/DaaUserContext.js +133 -0
  102. package/build/models/Deposit.d.ts +241 -0
  103. package/build/models/Deposit.js +149 -0
  104. package/build/models/DepositSummary.d.ts +91 -0
  105. package/build/models/DepositSummary.js +114 -0
  106. package/build/models/FiatAccount.d.ts +99 -0
  107. package/build/models/FiatAccount.js +151 -0
  108. package/build/models/GenerateAddressRequest.d.ts +67 -0
  109. package/build/models/GenerateAddressRequest.js +68 -0
  110. package/build/models/Money.d.ts +76 -0
  111. package/build/models/Money.js +99 -0
  112. package/build/models/Page.d.ts +33 -0
  113. package/build/models/Page.js +57 -0
  114. package/build/models/PendingDeviceRegistration.d.ts +90 -0
  115. package/build/models/PendingDeviceRegistration.js +180 -0
  116. package/build/models/PreparedSocialLogin.d.ts +155 -0
  117. package/build/models/PreparedSocialLogin.js +235 -0
  118. package/build/models/Transaction.d.ts +187 -0
  119. package/build/models/Transaction.js +134 -0
  120. package/build/models/Transfer.d.ts +335 -0
  121. package/build/models/Transfer.js +240 -0
  122. package/build/models/Wire.d.ts +213 -0
  123. package/build/models/Wire.js +264 -0
  124. package/build/models/Withdrawal.d.ts +201 -0
  125. package/build/models/Withdrawal.js +156 -0
  126. package/build/models/redaction.d.ts +18 -0
  127. package/build/models/redaction.js +23 -0
  128. package/build/sca/ScaClient.d.ts +105 -0
  129. package/build/sca/ScaClient.js +193 -0
  130. package/build/securekey/InMemorySecureKey.d.ts +23 -0
  131. package/build/securekey/InMemorySecureKey.js +127 -0
  132. package/build/securekey/NativeSecureKey.d.ts +24 -0
  133. package/build/securekey/NativeSecureKey.js +178 -0
  134. package/build/securekey/NativeSecureKeyBridge.d.ts +83 -0
  135. package/build/securekey/NativeSecureKeyBridge.js +19 -0
  136. package/build/securekey/SecureKey.d.ts +137 -0
  137. package/build/securekey/SecureKey.js +19 -0
  138. package/build/securekey/alias.d.ts +88 -0
  139. package/build/securekey/alias.js +175 -0
  140. package/build/securekey/ownerAuthKeyResolver.d.ts +56 -0
  141. package/build/securekey/ownerAuthKeyResolver.js +63 -0
  142. package/build/securekey/resolveNativeBridge.d.ts +30 -0
  143. package/build/securekey/resolveNativeBridge.js +120 -0
  144. package/build/testing.d.ts +18 -0
  145. package/build/testing.js +34 -0
  146. package/build/transport/DaaTransport.d.ts +35 -0
  147. package/build/transport/DaaTransport.js +19 -0
  148. package/build/transport/headers.d.ts +30 -0
  149. package/build/transport/headers.js +45 -0
  150. package/build/validation/requestBody.d.ts +27 -0
  151. package/build/validation/requestBody.js +56 -0
  152. package/build/validation/uuid.d.ts +25 -0
  153. package/build/validation/uuid.js +33 -0
  154. package/build/wire/accountLimitsUsagePayload.d.ts +30 -0
  155. package/build/wire/accountLimitsUsagePayload.js +130 -0
  156. package/build/wire/accountPayload.d.ts +36 -0
  157. package/build/wire/accountPayload.js +100 -0
  158. package/build/wire/achPayload.d.ts +24 -0
  159. package/build/wire/achPayload.js +82 -0
  160. package/build/wire/addressObjectPayload.d.ts +44 -0
  161. package/build/wire/addressObjectPayload.js +64 -0
  162. package/build/wire/daaStatusCodes.d.ts +64 -0
  163. package/build/wire/daaStatusCodes.js +69 -0
  164. package/build/wire/dataEnvelope.d.ts +40 -0
  165. package/build/wire/dataEnvelope.js +79 -0
  166. package/build/wire/depositPayload.d.ts +42 -0
  167. package/build/wire/depositPayload.js +159 -0
  168. package/build/wire/deviceContextPayload.d.ts +33 -0
  169. package/build/wire/deviceContextPayload.js +57 -0
  170. package/build/wire/deviceRegistrationResultPayload.d.ts +32 -0
  171. package/build/wire/deviceRegistrationResultPayload.js +128 -0
  172. package/build/wire/errorEnvelope.d.ts +43 -0
  173. package/build/wire/errorEnvelope.js +85 -0
  174. package/build/wire/fiatAccountPayload.d.ts +37 -0
  175. package/build/wire/fiatAccountPayload.js +93 -0
  176. package/build/wire/instant.d.ts +27 -0
  177. package/build/wire/instant.js +91 -0
  178. package/build/wire/jsonNumber.d.ts +30 -0
  179. package/build/wire/jsonNumber.js +34 -0
  180. package/build/wire/moneyPayload.d.ts +30 -0
  181. package/build/wire/moneyPayload.js +56 -0
  182. package/build/wire/paginationLinks.d.ts +28 -0
  183. package/build/wire/paginationLinks.js +167 -0
  184. package/build/wire/payload.d.ts +60 -0
  185. package/build/wire/payload.js +121 -0
  186. package/build/wire/pendingRegistrationPayload.d.ts +32 -0
  187. package/build/wire/pendingRegistrationPayload.js +54 -0
  188. package/build/wire/socialLoginRequestPayload.d.ts +31 -0
  189. package/build/wire/socialLoginRequestPayload.js +72 -0
  190. package/build/wire/transactionPayload.d.ts +31 -0
  191. package/build/wire/transactionPayload.js +126 -0
  192. package/build/wire/transferPayload.d.ts +43 -0
  193. package/build/wire/transferPayload.js +218 -0
  194. package/build/wire/wireEnums.d.ts +22 -0
  195. package/build/wire/wireEnums.js +69 -0
  196. package/build/wire/wirePayload.d.ts +29 -0
  197. package/build/wire/wirePayload.js +138 -0
  198. package/build/wire/withdrawalPayload.d.ts +27 -0
  199. package/build/wire/withdrawalPayload.js +179 -0
  200. package/expo-module.config.json +14 -0
  201. package/ios/DaaRegistrationExceptions.swift +58 -0
  202. package/ios/DaaRegistrationModule.swift +143 -0
  203. package/ios/DaaScaExceptions.swift +96 -0
  204. package/ios/DaaScaModule.swift +125 -0
  205. package/ios/DaaSecureKeyExceptions.swift +77 -0
  206. package/ios/DaaSecureKeyModule.swift +162 -0
  207. package/ios/InstallationIdentityStore.swift +126 -0
  208. package/ios/UnpaddedBase64URL.swift +42 -0
  209. package/package.json +114 -4
  210. package/src/DaaClient.ts +171 -0
  211. package/src/api/AccountLimitsClient.ts +146 -0
  212. package/src/api/AccountsClient.ts +305 -0
  213. package/src/api/AchFiatAccountsClient.ts +147 -0
  214. package/src/api/AuthClient.ts +331 -0
  215. package/src/api/DaaUserClient.ts +270 -0
  216. package/src/api/DepositAddressesClient.ts +239 -0
  217. package/src/api/DepositsClient.ts +208 -0
  218. package/src/api/FiatAccountsClient.ts +50 -0
  219. package/src/api/TransactionsClient.ts +137 -0
  220. package/src/api/TransfersClient.ts +361 -0
  221. package/src/api/WireFiatAccountsClient.ts +172 -0
  222. package/src/api/WithdrawalsClient.ts +339 -0
  223. package/src/api/loginFailure.ts +75 -0
  224. package/src/api/pagination.ts +63 -0
  225. package/src/api/queryParameters.ts +82 -0
  226. package/src/api/resourceRequest.ts +135 -0
  227. package/src/api/signedResource.ts +267 -0
  228. package/src/auth/RegistrationFlowKey.ts +274 -0
  229. package/src/auth/daaRegistrationNative.ts +236 -0
  230. package/src/auth/deviceAuthorization.ts +302 -0
  231. package/src/auth/ownerGrant.ts +102 -0
  232. package/src/auth/prepareReceipt.ts +522 -0
  233. package/src/auth/registrationAuthorization.ts +306 -0
  234. package/src/auth/registrationCodeVerifier.ts +76 -0
  235. package/src/config.ts +156 -0
  236. package/src/crypto/base64url.ts +88 -0
  237. package/src/crypto/bytes.ts +30 -0
  238. package/src/crypto/es256Jws.ts +240 -0
  239. package/src/crypto/jwkThumbprint.ts +65 -0
  240. package/src/crypto/random.ts +113 -0
  241. package/src/crypto/serialization.ts +42 -0
  242. package/src/crypto/sha256.ts +105 -0
  243. package/src/errors.ts +319 -0
  244. package/src/index.ts +223 -0
  245. package/src/models/Account.ts +264 -0
  246. package/src/models/AccountLimitsUsage.ts +192 -0
  247. package/src/models/Ach.ts +269 -0
  248. package/src/models/AddressObject.ts +169 -0
  249. package/src/models/BusinessPii.ts +154 -0
  250. package/src/models/CreateAccountRequest.ts +109 -0
  251. package/src/models/CreateTransferRequest.ts +114 -0
  252. package/src/models/CreateWithdrawalRequest.ts +120 -0
  253. package/src/models/DaaUserContext.ts +172 -0
  254. package/src/models/Deposit.ts +307 -0
  255. package/src/models/DepositSummary.ts +142 -0
  256. package/src/models/FiatAccount.ts +195 -0
  257. package/src/models/GenerateAddressRequest.ts +101 -0
  258. package/src/models/Money.ts +91 -0
  259. package/src/models/Page.ts +48 -0
  260. package/src/models/PendingDeviceRegistration.ts +197 -0
  261. package/src/models/PreparedSocialLogin.ts +287 -0
  262. package/src/models/Transaction.ts +247 -0
  263. package/src/models/Transfer.ts +459 -0
  264. package/src/models/Wire.ts +405 -0
  265. package/src/models/Withdrawal.ts +283 -0
  266. package/src/models/redaction.ts +22 -0
  267. package/src/sca/ScaClient.ts +289 -0
  268. package/src/securekey/InMemorySecureKey.ts +138 -0
  269. package/src/securekey/NativeSecureKey.ts +179 -0
  270. package/src/securekey/NativeSecureKeyBridge.ts +109 -0
  271. package/src/securekey/SecureKey.ts +149 -0
  272. package/src/securekey/alias.ts +204 -0
  273. package/src/securekey/ownerAuthKeyResolver.ts +96 -0
  274. package/src/securekey/resolveNativeBridge.ts +185 -0
  275. package/src/testing.ts +32 -0
  276. package/src/transport/DaaTransport.ts +42 -0
  277. package/src/transport/headers.ts +46 -0
  278. package/src/validation/requestBody.ts +60 -0
  279. package/src/validation/uuid.ts +31 -0
  280. package/src/wire/accountLimitsUsagePayload.ts +182 -0
  281. package/src/wire/accountPayload.ts +108 -0
  282. package/src/wire/achPayload.ts +98 -0
  283. package/src/wire/addressObjectPayload.ts +64 -0
  284. package/src/wire/daaStatusCodes.ts +69 -0
  285. package/src/wire/dataEnvelope.ts +80 -0
  286. package/src/wire/depositPayload.ts +186 -0
  287. package/src/wire/deviceContextPayload.ts +58 -0
  288. package/src/wire/deviceRegistrationResultPayload.ts +153 -0
  289. package/src/wire/errorEnvelope.ts +87 -0
  290. package/src/wire/fiatAccountPayload.ts +112 -0
  291. package/src/wire/instant.ts +93 -0
  292. package/src/wire/jsonNumber.ts +33 -0
  293. package/src/wire/moneyPayload.ts +55 -0
  294. package/src/wire/paginationLinks.ts +204 -0
  295. package/src/wire/payload.ts +146 -0
  296. package/src/wire/pendingRegistrationPayload.ts +75 -0
  297. package/src/wire/socialLoginRequestPayload.ts +89 -0
  298. package/src/wire/transactionPayload.ts +145 -0
  299. package/src/wire/transferPayload.ts +249 -0
  300. package/src/wire/wireEnums.ts +74 -0
  301. package/src/wire/wirePayload.ts +160 -0
  302. package/src/wire/withdrawalPayload.ts +219 -0
  303. package/testing.d.ts +19 -0
  304. package/testing.js +25 -0
@@ -0,0 +1,361 @@
1
+ /**
2
+ * Copyright (c) 2026, Circle Internet Group, Inc. All rights reserved.
3
+ *
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ import { serializeBody } from '../crypto/serialization'
20
+ import { contractViolation } from '../errors'
21
+ import type {
22
+ CreateTransferAmount,
23
+ CreateTransferDestination,
24
+ CreateTransferRequest,
25
+ CreateTransferRiskSignals,
26
+ CreateTransferSource,
27
+ } from '../models/CreateTransferRequest'
28
+ import type { Transfer } from '../models/Transfer'
29
+ import type { Page } from '../models/Page'
30
+ import type { DaaTransport } from '../transport/DaaTransport'
31
+ import { requireBodyObject, requireKnownProperties } from '../validation/requestBody'
32
+ import { isUuid } from '../validation/uuid'
33
+ import { JSON_NUMBER } from '../wire/jsonNumber'
34
+ import { toTransfer, toTransfers } from '../wire/transferPayload'
35
+ import { readPage } from './pagination'
36
+ import { append, appendEnum, appendString, appendUuid } from './queryParameters'
37
+ import { readResource } from './resourceRequest'
38
+ import { postSignedResource, type DaaUserSigning } from './signedResource'
39
+
40
+ /**
41
+ * `GET /v1/accounts/transfers/{transferId}` — the **public** path, exactly as
42
+ * for Accounts (`AccountsClient.ts`). The registry's
43
+ * `"canonical_path": "/v1/accounts/transfers"` and the `Location` header of
44
+ * `/v1/accounts/transfers/<id>` on create both use it.
45
+ */
46
+ const TRANSFER_PATH_PREFIX = '/v1/accounts/transfers/'
47
+ const TRANSFER_COLLECTION_PATH = '/v1/accounts/transfers'
48
+
49
+ /**
50
+ * The properties the Owner-authorization registry's `transfer` schema names, in
51
+ * the order it names them, at each level of the body.
52
+ *
53
+ * Order matters because these are the bytes that get signed: the body is
54
+ * serialized once from these shapes and that exact slice is hashed into
55
+ * `body_sha256` and put on the wire. Building it here rather than forwarding
56
+ * the caller's object also means the property order does not vary with how the
57
+ * caller happened to write its literal. Every one of these objects is
58
+ * `additionalProperties: false` in the registry, so each level is checked, not
59
+ * just the top.
60
+ */
61
+ const TRANSFER_PROPERTIES = Object.freeze([
62
+ 'idempotencyKey',
63
+ 'source',
64
+ 'destination',
65
+ 'amount',
66
+ 'riskSignals',
67
+ ])
68
+ const TRANSFER_LOCATION_PROPERTIES = Object.freeze(['type', 'id'])
69
+ const TRANSFER_VERIFIED_BLOCKCHAIN_PROPERTIES = Object.freeze(['type', 'addressId'])
70
+ const TRANSFER_AMOUNT_PROPERTIES = Object.freeze(['amount', 'currency'])
71
+ const TRANSFER_RISK_SIGNAL_PROPERTIES = Object.freeze(['ipAddress', 'sessionId', 'deviceId'])
72
+
73
+ export type TransferListQuery = Readonly<{
74
+ /** Select a backing source explicitly; omitted derives from `accountId` or defaults to omnibus. */
75
+ custodyType?: 'omnibus' | 'segregated' | 'self'
76
+ /** Match transfers where this public account id is either leg. */
77
+ accountId?: string
78
+ /** Match this source leg id. Leg ids are strings and are not necessarily UUIDs. */
79
+ sourceAccountId?: string
80
+ /** Match this destination leg id. Leg ids are strings and are not necessarily UUIDs. */
81
+ destinationAccountId?: string
82
+ /** Match transfers for one end-user sub-entity. */
83
+ clientEntityId?: string
84
+ sourceType?: 'account' | 'blockchain'
85
+ destinationType?: 'account' | 'blockchain'
86
+ /** Inclusive RFC 3339 creation-time lower bound. */
87
+ from?: string
88
+ /** Inclusive RFC 3339 creation-time upper bound. */
89
+ to?: string
90
+ /** Initial forward keyset cursor. Link-derived navigation remains opaque. */
91
+ pageAfter?: string
92
+ /** Initial backward keyset cursor. Link-derived navigation remains opaque. */
93
+ pageBefore?: string
94
+ pageSize?: number
95
+ }>
96
+
97
+ /*
98
+ * A transfer id is a UUID, and is checked as one rather than as a generic path
99
+ * segment.
100
+ *
101
+ * The SDK contract types this parameter `transferId: UUID`. That is
102
+ * deliberately unlike `AccountsClient`, whose signature is
103
+ * `accountId: string`, because public account ids are strings, including
104
+ * numeric IDs. The two guards differ on purpose; applying one rule to
105
+ * both would make one of them wrong.
106
+ *
107
+ * A UUID-formatted identifier contains none of the characters — `/`, `%`, `.`, control
108
+ * bytes — that could redirect the request into a sibling route, so this subsumes
109
+ * the path-segment check rather than merely differing from it.
110
+ */
111
+ /**
112
+ * Reads over DAA transfers, plus the signed transfer create, as the SDK
113
+ * contract's `TransfersClient`.
114
+ *
115
+ * {@link list} retains the API's RFC 8288 navigation queries as opaque text.
116
+ * {@link create} is an Owner-authorized write: it carries an
117
+ * `X-Device-Authorization` bound to the exact bytes it sends and cannot happen
118
+ * without the registered AuthKey `forUser` supplies.
119
+ *
120
+ * Not constructible by a consumer: exported from `index.ts` as a type only, and
121
+ * the `#transport` field makes the type nominal.
122
+ */
123
+ export class TransfersClient {
124
+ readonly #transport: DaaTransport
125
+ readonly #publicApiOrigin: string
126
+ readonly #signing: DaaUserSigning
127
+
128
+ /** @internal Constructed only through the internal user-client factory. */
129
+ constructor(transport: DaaTransport, publicApiOrigin: string, signing: DaaUserSigning) {
130
+ this.#transport = transport
131
+ this.#publicApiOrigin = publicApiOrigin
132
+ this.#signing = signing
133
+ Object.freeze(this)
134
+ }
135
+
136
+ /** List transfers and retain the API's opaque navigation queries unchanged. */
137
+ async list(query?: TransferListQuery): Promise<Page<Transfer>> {
138
+ return readPage({
139
+ transport: this.#transport,
140
+ publicApiOrigin: this.#publicApiOrigin,
141
+ path: TRANSFER_COLLECTION_PATH,
142
+ query: transferListQuery(query),
143
+ decode: toTransfers,
144
+ })
145
+ }
146
+
147
+ /**
148
+ * Read one transfer.
149
+ *
150
+ * @param transferId The service-assigned UUID. Values that are not
151
+ * UUID-formatted are rejected locally because they cannot resolve to a
152
+ * transfer on the service side.
153
+ * @throws DaaError with `detail.kind === 'contract_violation'` for a rejected
154
+ * `transferId` or a response the SDK cannot read, and `detail.kind === 'api'`
155
+ * for a status other than the documented `200`; `detail.kind === 'transport'`
156
+ * if the consumer's transport throws, with the thrown value as `err.cause`.
157
+ */
158
+ async get(transferId: string): Promise<Transfer> {
159
+ if (!isUuid(transferId)) {
160
+ throw contractViolation('transferId must be a UUID')
161
+ }
162
+
163
+ return readResource({
164
+ transport: this.#transport,
165
+ path: TRANSFER_PATH_PREFIX + transferId,
166
+ decode: toTransfer,
167
+ })
168
+ }
169
+
170
+ /**
171
+ * Create a transfer, authorized by the registered device key.
172
+ *
173
+ * The body is validated, serialized **once**, and that exact byte slice is
174
+ * both hashed into the authorization's `body_sha256` claim and sent as the
175
+ * request entity. Nothing between here and the transport re-serializes it,
176
+ * which is the whole point: a re-encoding that changed so much as a space
177
+ * would produce a signature over bytes the service never receives.
178
+ *
179
+ * Neither the method nor the path is chosen here. `postSignedResource`
180
+ * resolves both from the registry entry for `transfer`, so a signed write
181
+ * cannot be aimed somewhere the operation does not name.
182
+ *
183
+ * @throws DaaError with `detail.kind === 'contract_violation'` for a request
184
+ * the registry schema would reject, for an AuthKey that is not yet
185
+ * registered — the create is refused locally, before anything is signed or
186
+ * sent — for a rejected or replayed authorization (including a key that is
187
+ * no longer active: DAA has no revoked-credential code, so this never
188
+ * throws `device_revoked`), and for a response the SDK cannot read;
189
+ * `idempotency_conflict`, with the request's key, for a `409` with
190
+ * `IDEMPOTENCY_KEY_REUSED` (`420034`): reconcile the original transfer with
191
+ * the same key; do not mint a new key for it;
192
+ * `detail.kind === 'api'` for a status other than the documented `201`; and
193
+ * `detail.kind === 'transport'` if the consumer's transport throws, with the
194
+ * thrown value as `err.cause` and the request's `idempotencyKey` on the
195
+ * detail.
196
+ */
197
+ async create(request: CreateTransferRequest): Promise<Transfer> {
198
+ const bodyBytes = serializeBody(createTransferBody(request))
199
+ return postSignedResource({
200
+ transport: this.#transport,
201
+ operation: 'transfer',
202
+ authKey: await this.#signing.resolveAuthKey(),
203
+ authKeyId: this.#signing.authKeyId,
204
+ bodyBytes,
205
+ // The contract documents exactly 201, with a Location header. Another
206
+ // 2xx is an observable API failure rather than a silently accepted
207
+ // variant, the same rule the by-id reads apply to 200.
208
+ expectedStatus: 201,
209
+ decode: toTransfer,
210
+ })
211
+ }
212
+ }
213
+
214
+ /**
215
+ * Project a validated request onto the registry's `transfer` shape.
216
+ *
217
+ * Returned rather than serialized here so the caller can hold the one byte
218
+ * slice this body becomes; see {@link TransfersClient.create}.
219
+ */
220
+ function createTransferBody(request: CreateTransferRequest): object {
221
+ requireBodyObject(request, 'transfer create request')
222
+ requireKnownProperties(request, TRANSFER_PROPERTIES, 'transfer create request')
223
+
224
+ const { idempotencyKey, source, destination, amount, riskSignals } = request
225
+
226
+ // The registry types this `format: uuid`, and nothing in the transfer
227
+ // contract narrows it to v4 — unlike the account create, whose own contract
228
+ // text says v4. Requiring more here would reject a key DAA accepts.
229
+ if (typeof idempotencyKey !== 'string' || !isUuid(idempotencyKey)) {
230
+ throw contractViolation('idempotencyKey must be a UUID')
231
+ }
232
+
233
+ return {
234
+ idempotencyKey,
235
+ ...(source === undefined ? {} : { source: transferSource(source) }),
236
+ destination: transferDestination(destination),
237
+ amount: transferAmount(amount),
238
+ ...(riskSignals === undefined ? {} : { riskSignals: transferRiskSignals(riskSignals) }),
239
+ }
240
+ }
241
+
242
+ function transferSource(source: CreateTransferSource): object {
243
+ requireBodyObject(source, 'transfer source')
244
+ requireKnownProperties(source, TRANSFER_LOCATION_PROPERTIES, 'transfer source')
245
+ const { type, id } = source
246
+ if (type !== 'account') {
247
+ throw contractViolation('transfer source type must be account')
248
+ }
249
+ if (typeof id !== 'string' || id.length === 0) {
250
+ throw contractViolation('transfer source id must be a non-empty string')
251
+ }
252
+ return { type, id }
253
+ }
254
+
255
+ /**
256
+ * Both `oneOf` arms, kept apart by their discriminator.
257
+ *
258
+ * The registry requires a destination to match exactly one arm, and the two are
259
+ * told apart by `type` alone — their required properties are disjoint (`id`
260
+ * against `addressId`) and neither admits additional ones. So an unfamiliar
261
+ * `type` is rejected here rather than guessed at: guessing would mean picking
262
+ * an arm DAA would not have picked, and signing that.
263
+ */
264
+ function transferDestination(destination: CreateTransferDestination): object {
265
+ requireBodyObject(destination, 'transfer destination')
266
+ const { type } = destination
267
+ if (type === 'account') {
268
+ requireKnownProperties(destination, TRANSFER_LOCATION_PROPERTIES, 'transfer destination')
269
+ const { id } = destination
270
+ if (typeof id !== 'string' || id.length === 0) {
271
+ throw contractViolation('transfer destination id must be a non-empty string')
272
+ }
273
+ return { type, id }
274
+ }
275
+ if (type === 'verified_blockchain') {
276
+ requireKnownProperties(
277
+ destination,
278
+ TRANSFER_VERIFIED_BLOCKCHAIN_PROPERTIES,
279
+ 'transfer destination',
280
+ )
281
+ const { addressId } = destination
282
+ if (typeof addressId !== 'string' || !isUuid(addressId)) {
283
+ throw contractViolation('transfer destination addressId must be a UUID')
284
+ }
285
+ return { type, addressId }
286
+ }
287
+ throw contractViolation('transfer destination type must be account or verified_blockchain')
288
+ }
289
+
290
+ function transferAmount(amount: CreateTransferAmount): object {
291
+ requireBodyObject(amount, 'transfer amount')
292
+ requireKnownProperties(amount, TRANSFER_AMOUNT_PROPERTIES, 'transfer amount')
293
+ const { amount: amountValue, currency } = amount
294
+ // The registry's `decimal` accepts a JSON string or a JSON number and then
295
+ // parses it as an arbitrary-precision decimal, so it would also take forms
296
+ // JSON itself does not write — a bare leading `.`, a trailing `.`, a leading
297
+ // `+`. This narrows to the RFC 8259 number grammar the SDK already requires
298
+ // of a `Money` on the way in (`wire/jsonNumber.ts`), so the same literal
299
+ // means the same thing in both directions and the signed bytes are never
300
+ // ambiguous.
301
+ if (typeof amountValue !== 'string' || !JSON_NUMBER.test(amountValue)) {
302
+ throw contractViolation('transfer amount must be a decimal string, e.g. "10.25"')
303
+ }
304
+ if (typeof currency !== 'string' || currency.length === 0) {
305
+ throw contractViolation('transfer amount currency must be a non-empty string')
306
+ }
307
+ return { amount: amountValue, currency }
308
+ }
309
+
310
+ function transferRiskSignals(riskSignals: CreateTransferRiskSignals): object {
311
+ requireBodyObject(riskSignals, 'transfer risk signals')
312
+ requireKnownProperties(riskSignals, TRANSFER_RISK_SIGNAL_PROPERTIES, 'transfer risk signals')
313
+ const { ipAddress, sessionId, deviceId } = riskSignals
314
+ requireOptionalRiskSignal(ipAddress, 'ipAddress')
315
+ requireOptionalRiskSignal(sessionId, 'sessionId')
316
+ requireOptionalRiskSignal(deviceId, 'deviceId')
317
+ // The registry requires none of these, so an object with none of them is a
318
+ // valid `riskSignals` and is sent as the empty object the caller asked for.
319
+ return {
320
+ ...(ipAddress === undefined ? {} : { ipAddress }),
321
+ ...(sessionId === undefined ? {} : { sessionId }),
322
+ ...(deviceId === undefined ? {} : { deviceId }),
323
+ }
324
+ }
325
+
326
+ function requireOptionalRiskSignal(value: string | undefined, name: string): void {
327
+ if (value !== undefined && (typeof value !== 'string' || value.length === 0)) {
328
+ throw contractViolation(`transfer risk signal ${name} must be a non-empty string`)
329
+ }
330
+ }
331
+
332
+ function transferListQuery(query: TransferListQuery | undefined): string | null {
333
+ if (query === undefined) return null
334
+ if (typeof query !== 'object' || query === null || Array.isArray(query)) {
335
+ throw contractViolation('transfer list query must be an object')
336
+ }
337
+ if (query.pageAfter !== undefined && query.pageBefore !== undefined) {
338
+ throw contractViolation('pageAfter and pageBefore cannot be used together')
339
+ }
340
+
341
+ const parts: string[] = []
342
+ appendEnum(parts, 'custodyType', query.custodyType, ['omnibus', 'segregated', 'self'])
343
+ appendString(parts, 'accountId', query.accountId)
344
+ appendString(parts, 'sourceAccountId', query.sourceAccountId)
345
+ appendString(parts, 'destinationAccountId', query.destinationAccountId)
346
+ appendUuid(parts, 'clientEntityId', query.clientEntityId)
347
+ appendEnum(parts, 'sourceType', query.sourceType, ['account', 'blockchain'])
348
+ appendEnum(parts, 'destinationType', query.destinationType, ['account', 'blockchain'])
349
+ appendString(parts, 'from', query.from)
350
+ appendString(parts, 'to', query.to)
351
+ // Unlike account cursors, the service models transfer cursors as UUID transfer ids.
352
+ appendUuid(parts, 'pageAfter', query.pageAfter)
353
+ appendUuid(parts, 'pageBefore', query.pageBefore)
354
+ if (query.pageSize !== undefined) {
355
+ if (!Number.isInteger(query.pageSize) || query.pageSize < 1) {
356
+ throw contractViolation('pageSize must be a positive integer')
357
+ }
358
+ append(parts, 'pageSize', String(query.pageSize))
359
+ }
360
+ return parts.length === 0 ? null : parts.join('&')
361
+ }
@@ -0,0 +1,172 @@
1
+ /**
2
+ * Copyright (c) 2026, Circle Internet Group, Inc. All rights reserved.
3
+ *
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ import { contractViolation } from '../errors'
20
+ import type { Wire, WireInstruction, WireSummary } from '../models/Wire'
21
+ import type { DaaTransport } from '../transport/DaaTransport'
22
+ import { isUuid } from '../validation/uuid'
23
+ import { toWire, toWireInstruction, toWireSummaries } from '../wire/wirePayload'
24
+ import { appendString, appendUuid } from './queryParameters'
25
+ import { readResource } from './resourceRequest'
26
+
27
+ const WIRE_COLLECTION_PATH = '/v1/banks/wires'
28
+ const WIRE_PATH_PREFIX = '/v1/banks/wires/'
29
+
30
+ /** The wire collection's list query: `clientEntityId` is optional. */
31
+ export type WireFiatAccountListQuery = Readonly<{
32
+ clientEntityId?: string
33
+ }>
34
+
35
+ /**
36
+ * A public Accounts API `accountId` query value. These are strings, including
37
+ * numeric IDs — the same reason `AccountsClient.get` types its parameter
38
+ * `string` rather than `UUID`.
39
+ */
40
+ export type PublicAccountId = string
41
+
42
+ /** Optional query accepted by {@link WireFiatAccountsClient.getInstructions}. */
43
+ export type WireInstructionQuery = Readonly<{
44
+ accountId?: PublicAccountId
45
+ }>
46
+
47
+ /**
48
+ * Reads over wire fiat accounts.
49
+ *
50
+ * Every operation here is an **ordinary typed read** — fiat-account list and
51
+ * get and the receiving-instructions read are all unsigned — so, like
52
+ * `AccountsClient.get`, none of it needs a device signature.
53
+ *
54
+ * {@link list} returns the API's **unpaginated list shape**: a plain `data`
55
+ * array, not this SDK's opaque-cursor `Page<T>`. {@link get} and
56
+ * {@link getInstructions} are separate SDK methods and response types by
57
+ * design: {@link get} returns the linked bank account, {@link getInstructions}
58
+ * returns Circle receiving instructions for it. {@link getInstructions} is a
59
+ * plain typed read of the public instruction route: it returns Circle's
60
+ * receiving instructions and does not resolve a self-custody pass-through
61
+ * account.
62
+ *
63
+ * Not constructible by a consumer: exported from `index.ts` as a type only,
64
+ * and the `#transport` field makes the type nominal.
65
+ */
66
+ export class WireFiatAccountsClient {
67
+ readonly #transport: DaaTransport
68
+
69
+ /** @internal Constructed only through `createDaaUserClient`. */
70
+ constructor(transport: DaaTransport) {
71
+ this.#transport = transport
72
+ Object.freeze(this)
73
+ }
74
+
75
+ /**
76
+ * List wire fiat accounts.
77
+ *
78
+ * `clientEntityId` is optional here — unlike `AchFiatAccountsClient.list`,
79
+ * where it is required. This is a deliberate asymmetry, not a typo:
80
+ * `WireFiatAccountListQuery.clientEntityId` is optional and
81
+ * `AchFiatAccountListQuery.clientEntityId` is required, because ACH listing
82
+ * covers third-party accounts only.
83
+ *
84
+ * @throws DaaError with `detail.kind === 'contract_violation'` for an
85
+ * invalid query or a response the SDK cannot read, and
86
+ * `detail.kind === 'api'` for a status other than the documented `200`;
87
+ * `detail.kind === 'transport'` if the consumer's transport throws, with the
88
+ * thrown value as `err.cause`.
89
+ */
90
+ async list(query?: WireFiatAccountListQuery): Promise<ReadonlyArray<WireSummary>> {
91
+ return readResource({
92
+ transport: this.#transport,
93
+ path: WIRE_COLLECTION_PATH,
94
+ query: wireListQuery(query),
95
+ decode: toWireSummaries,
96
+ })
97
+ }
98
+
99
+ /**
100
+ * Read one wire fiat account.
101
+ *
102
+ * @param fiatAccountId The service-assigned UUID.
103
+ * @throws DaaError with `detail.kind === 'contract_violation'` for a
104
+ * rejected `fiatAccountId` or a response the SDK cannot read, and
105
+ * `detail.kind === 'api'` for a status other than the documented `200`;
106
+ * `detail.kind === 'transport'` if the consumer's transport throws, with the
107
+ * thrown value as `err.cause`.
108
+ */
109
+ async get(fiatAccountId: string): Promise<Wire> {
110
+ if (!isUuid(fiatAccountId)) {
111
+ throw contractViolation('fiatAccountId must be a UUID')
112
+ }
113
+
114
+ return readResource({
115
+ transport: this.#transport,
116
+ path: WIRE_PATH_PREFIX + fiatAccountId,
117
+ decode: toWire,
118
+ })
119
+ }
120
+
121
+ /**
122
+ * Read Circle receiving instructions for a wire fiat account.
123
+ *
124
+ * A plain typed read of the public instruction route — see the class doc.
125
+ *
126
+ * @param fiatAccountId The service-assigned UUID.
127
+ * @param query Optional public `accountId`. The wire instruction route
128
+ * accepts this parameter; the ACH route does not.
129
+ * @throws DaaError with `detail.kind === 'contract_violation'` for a
130
+ * rejected `fiatAccountId`/`accountId` or a response the SDK cannot read,
131
+ * and `detail.kind === 'api'` for a status other than the documented
132
+ * `200`; `detail.kind === 'transport'` if the consumer's transport throws,
133
+ * with the thrown value as `err.cause`.
134
+ */
135
+ async getInstructions(
136
+ fiatAccountId: string,
137
+ query?: WireInstructionQuery,
138
+ ): Promise<WireInstruction> {
139
+ if (!isUuid(fiatAccountId)) {
140
+ throw contractViolation('fiatAccountId must be a UUID')
141
+ }
142
+
143
+ return readResource({
144
+ transport: this.#transport,
145
+ path: WIRE_PATH_PREFIX + fiatAccountId + '/instructions',
146
+ query: wireInstructionQuery(query),
147
+ decode: toWireInstruction,
148
+ })
149
+ }
150
+ }
151
+
152
+ function wireListQuery(query: WireFiatAccountListQuery | undefined): string | null {
153
+ if (query === undefined) return null
154
+ if (typeof query !== 'object' || query === null || Array.isArray(query)) {
155
+ throw contractViolation('wire list query must be an object')
156
+ }
157
+
158
+ const parts: string[] = []
159
+ appendUuid(parts, 'clientEntityId', query.clientEntityId)
160
+ return parts.length === 0 ? null : parts.join('&')
161
+ }
162
+
163
+ function wireInstructionQuery(query: WireInstructionQuery | undefined): string | null {
164
+ if (query === undefined) return null
165
+ if (typeof query !== 'object' || query === null || Array.isArray(query)) {
166
+ throw contractViolation('wire instruction query must be an object')
167
+ }
168
+
169
+ const parts: string[] = []
170
+ appendString(parts, 'accountId', query.accountId)
171
+ return parts.length === 0 ? null : parts.join('&')
172
+ }