@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
package/src/errors.ts ADDED
@@ -0,0 +1,319 @@
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
+ // Stable SDK error model. Unknown DAA codes remain observable as
20
+ // `api` and are never guessed retryable. Errors never expose Owner grants, JWS
21
+ // values, raw key material, native key handles, or sealed server state.
22
+ //
23
+ // `device_revoked` and `owner_binding_invalid` are reserved: DAA returns no
24
+ // code that produces them, so the SDK never throws them. They stay in the type
25
+ // so that a later DAA code does not change the public type.
26
+
27
+ export type DaaSdkError =
28
+ | { kind: 'transport'; retryable: boolean; idempotencyKey?: string }
29
+ | { kind: 'api'; httpStatus: number; daaStatusCode?: string | number; retryable: boolean }
30
+ | { kind: 'local_user_authentication_required' }
31
+ | { kind: 'login_request_expired' }
32
+ | { kind: 'owner_grant_invalid' }
33
+ | { kind: 'owner_grant_expired' }
34
+ | { kind: 'prepare_receipt_invalid' }
35
+ | { kind: 'owner_binding_invalid' }
36
+ | { kind: 'device_not_initialized' }
37
+ | { kind: 'device_revoked' }
38
+ | { kind: 'idempotency_conflict'; idempotencyKey: string; correlationId?: string }
39
+ | { kind: 'contract_violation'; correlationId?: string }
40
+
41
+ /**
42
+ * An Error carrying a structured `DaaSdkError`. The SDK throws this so callers
43
+ * get the stable model (`err.detail.kind`) instead of raw platform text.
44
+ */
45
+ export class DaaError extends Error {
46
+ readonly detail: DaaSdkError
47
+ // The originating error. Kept off `message` (so it never lands in logs by
48
+ // default) but available to a host that deliberately inspects `err.cause`.
49
+ readonly cause: unknown
50
+
51
+ constructor(detail: DaaSdkError, message: string, cause: unknown = undefined) {
52
+ super(message)
53
+ this.name = 'DaaError'
54
+ this.detail = detail
55
+ this.cause = cause
56
+ // Keep `cause` non-enumerable so JSON.stringify and crash reporters that
57
+ // walk own enumerable properties do not export the raw native error (its
58
+ // code / userInfo / native stack). It stays readable via `err.cause`.
59
+ Object.defineProperty(this, 'cause', { enumerable: false })
60
+ }
61
+ }
62
+
63
+ /** Narrow an unknown caught value to `DaaError` (so callers can read `.detail`). */
64
+ export function isDaaError(err: unknown): err is DaaError {
65
+ return err instanceof DaaError
66
+ }
67
+
68
+ /** A local boundary/contract check failed (no request was sent). */
69
+ export function contractViolation(message: string, correlationId?: string | null): DaaError {
70
+ if (correlationId === undefined || correlationId === null) {
71
+ return new DaaError({ kind: 'contract_violation' }, `DAA: ${message}`)
72
+ }
73
+ return new DaaError(
74
+ { kind: 'contract_violation', correlationId },
75
+ `DAA: ${message}${requestIdSuffix(correlationId)}`,
76
+ )
77
+ }
78
+
79
+ /**
80
+ * A correlation id is a server-supplied header value, and it reaches
81
+ * `DaaError.message` — which a consuming app is likely to log verbatim. A header
82
+ * carrying CR, LF, or other control characters could therefore forge log lines,
83
+ * so only printable ASCII is interpolated.
84
+ *
85
+ * This does not cost the value: a correlation id is printable, so the message
86
+ * carries the exact header. Only one already carrying control characters comes
87
+ * through altered, and the missing characters are the ones that made it unsafe.
88
+ * Where the error model carries the field — `contract_violation` — the detail
89
+ * still holds it exactly, for a caller reading it deliberately rather than
90
+ * logging it.
91
+ */
92
+ function messageSafe(correlationId: string): string {
93
+ return correlationId.replace(/[^\x20-\x7e]/g, '')
94
+ }
95
+
96
+ /** The ` (requestId=…)` message suffix, or nothing when there is no correlation id. */
97
+ function requestIdSuffix(correlationId: string | null): string {
98
+ return correlationId === null ? '' : ` (requestId=${messageSafe(correlationId)})`
99
+ }
100
+
101
+ /**
102
+ * A successful response could not be read as the contract's shape.
103
+ *
104
+ * The same `contract_violation` kind as a local check: the model describes a
105
+ * broken contract, not which side broke it, and a caller's recovery is the same
106
+ * either way — the call cannot be made to succeed by retrying it. What
107
+ * distinguishes this one is `correlationId`, the provider's `X-Request-Id`, which
108
+ * is what makes it diagnosable server-side.
109
+ *
110
+ * Nothing derived from the response *body* is carried. The body is the thing the
111
+ * SDK could not vouch for; a misrouted or intercepted response must not be able
112
+ * to put its own text into a consumer's logs. Not even the name of the field that
113
+ * was missing goes in.
114
+ */
115
+ export function malformedResponse(correlationId: string | null): DaaError {
116
+ const detail: DaaSdkError =
117
+ correlationId === null
118
+ ? { kind: 'contract_violation' }
119
+ : { kind: 'contract_violation', correlationId }
120
+ return new DaaError(
121
+ detail,
122
+ `DAA: the response did not match the DAA API contract${requestIdSuffix(correlationId)}`,
123
+ )
124
+ }
125
+
126
+ /**
127
+ * A DAA API call returned an unexpected status.
128
+ *
129
+ * `retryable` is decided by the HTTP status alone. A caller may safely retry
130
+ * `429` and `5xx` responses; write retries must reuse the original body and
131
+ * idempotency key. Other `4xx` responses will not become successes on a second
132
+ * attempt. The DAA status code is carried for logging and support but is
133
+ * deliberately **not** consulted — an unknown DAA code stays observable and is
134
+ * never guessed retryable.
135
+ *
136
+ * `correlationId` goes in the message and **not** on the detail, because the
137
+ * `api` variant does not model one — the error model puts the field on
138
+ * `contract_violation` only, and the SDK does not widen the `api` type to carry
139
+ * it. Sanitising costs nothing here: a correlation id is printable, so the
140
+ * message copy is the exact header. Only a header already carrying control
141
+ * characters differs, and that value is not one to hand back untouched.
142
+ */
143
+ export function apiFailure(args: {
144
+ httpStatus: number
145
+ daaStatusCode: string | number | null
146
+ correlationId: string | null
147
+ }): DaaError {
148
+ const retryable = args.httpStatus === 429 || args.httpStatus >= 500
149
+ const detail: DaaSdkError = {
150
+ kind: 'api',
151
+ httpStatus: args.httpStatus,
152
+ retryable,
153
+ ...(args.daaStatusCode === null ? {} : { daaStatusCode: args.daaStatusCode }),
154
+ }
155
+ return new DaaError(
156
+ detail,
157
+ `DAA: API call failed (status=${args.httpStatus})${requestIdSuffix(args.correlationId)}`,
158
+ )
159
+ }
160
+
161
+ /**
162
+ * The consumer's transport threw instead of returning a response.
163
+ *
164
+ * The error model calls this `transport`. A throw from `DaaTransport.send` does
165
+ * not say whether the request reached DAA. Cancellation after transport
166
+ * submission remains an ambiguous result and follows the retry rules; a throw
167
+ * from the transport leaves the same unknown outcome. The retry rule is to
168
+ * retry with the same body bytes and the same idempotency key. That is why
169
+ * `retryable` is `true`, and why the idempotency key of the request handed to
170
+ * the transport, when its body has one, goes on the detail: it is the key the
171
+ * retry must reuse.
172
+ *
173
+ * The thrown value is the consumer's own error. It is kept as `cause`, not
174
+ * copied into `message`: the SDK cannot vouch for its text, and `message` is
175
+ * what crash reporters log by default.
176
+ *
177
+ * Every `DaaUserClient` operation reports a transport throw this way. The three
178
+ * login calls (Prepare, Social Session, and Device Registration Complete) do
179
+ * not: they rethrow the consumer's error unchanged, because the SDK mints their
180
+ * idempotency keys itself and does not let a caller resend the same bytes, so
181
+ * `retryable: true` would not be true for them.
182
+ */
183
+ export function transportFailure(cause: unknown, idempotencyKey?: string): DaaError {
184
+ const detail: DaaSdkError =
185
+ idempotencyKey === undefined
186
+ ? { kind: 'transport', retryable: true }
187
+ : { kind: 'transport', retryable: true, idempotencyKey }
188
+ return new DaaError(detail, 'DAA: the transport failed before a response was received', cause)
189
+ }
190
+
191
+ /**
192
+ * The pending login request expired (`410`).
193
+ *
194
+ * The contract's rule for the Prepare and Social Session calls: "An exact retry
195
+ * after expiry returns `410`; the SDK starts a new logical attempt with a fresh,
196
+ * permanently unused key." So the caller's recovery is a new `prepareSocialLogin`,
197
+ * not a retry, and the expired key is never reused.
198
+ *
199
+ * `correlationId`, the response's `X-Request-Id`, goes in the message only, as
200
+ * on `api`. The error model puts a correlation id on `contract_violation`;
201
+ * `idempotency_conflict` also carries it, as an optional field (see
202
+ * {@link idempotencyConflict}), and this variant does not.
203
+ */
204
+ export function loginRequestExpired(correlationId: string | null): DaaError {
205
+ return new DaaError(
206
+ { kind: 'login_request_expired' },
207
+ `DAA: the login request has expired${requestIdSuffix(correlationId)}`,
208
+ )
209
+ }
210
+
211
+ /**
212
+ * The Prepare receipt could not be verified: it is missing where one is
213
+ * required, malformed, signed by no pinned key, bound to values other than this
214
+ * attempt's, outside its validity window, or the platform verifier is missing
215
+ * or failed.
216
+ *
217
+ * On the login path this is raised only when a trust anchor is pinned for the
218
+ * environment: the SDK then verifies the receipt and fails closed on any
219
+ * mismatch, and nothing from that Prepare response reaches the application.
220
+ * With no anchor pinned, the receipt is ignored. Not retryable in place: the
221
+ * caller's recovery is a new `prepareSocialLogin`, which sends a fresh
222
+ * challenge and flow key. A failure that persists across fresh attempts points
223
+ * at the relay or at trust material that does not match the service's signer,
224
+ * not at the user.
225
+ *
226
+ * The receipt is unverified server-supplied text and never goes into the
227
+ * message; `message` here is one of the SDK's own literals.
228
+ */
229
+ export function prepareReceiptInvalid(message: string, cause: unknown = undefined): DaaError {
230
+ return new DaaError({ kind: 'prepare_receipt_invalid' }, `DAA: ${message}`, cause)
231
+ }
232
+
233
+ /**
234
+ * The same error with the response's `X-Request-Id` named in its message.
235
+ *
236
+ * For a check that runs on a decoded response without seeing the response
237
+ * itself — the Prepare receipt's verification has many throw sites and none of
238
+ * them holds the headers — so the caller that does hold the response adds the
239
+ * id once. The detail, the cause, and the stack of the check that threw are
240
+ * unchanged.
241
+ */
242
+ export function withRequestId(err: DaaError, correlationId: string | null): DaaError {
243
+ if (correlationId === null) {
244
+ return err
245
+ }
246
+ const correlated = new DaaError(
247
+ err.detail,
248
+ `${err.message}${requestIdSuffix(correlationId)}`,
249
+ err.cause,
250
+ )
251
+ if (err.stack !== undefined) {
252
+ // Keep the frame that names which receipt check failed, with the new message.
253
+ // A function replacer, so a `$` in the server's id is not a replace pattern.
254
+ correlated.stack = err.stack.replace(err.message, () => correlated.message)
255
+ }
256
+ return correlated
257
+ }
258
+
259
+ /**
260
+ * An idempotency key was reused with different request bytes: a `409` with
261
+ * `IDEMPOTENCY_KEY_REUSED` (`420034`). Another `409` is not this error.
262
+ *
263
+ * The key goes on the detail so a caller can correlate the conflict; it stays
264
+ * out of `message` because that string is what crash reporters log by default.
265
+ * The response's `X-Request-Id` is the server's id, not the caller's, so it goes
266
+ * in both, in the shape `contract_violation` uses: a host that reports
267
+ * `err.detail` rather than the message can still trace the conflict
268
+ * server-side. The error model puts a correlation id on `contract_violation`;
269
+ * `idempotency_conflict` also carries it, as an optional field.
270
+ */
271
+ export function idempotencyConflict(
272
+ idempotencyKey: string,
273
+ correlationId: string | null,
274
+ ): DaaError {
275
+ const detail: DaaSdkError =
276
+ correlationId === null
277
+ ? { kind: 'idempotency_conflict', idempotencyKey }
278
+ : { kind: 'idempotency_conflict', idempotencyKey, correlationId }
279
+ return new DaaError(
280
+ detail,
281
+ `DAA: idempotency key was reused with a different request${requestIdSuffix(correlationId)}`,
282
+ )
283
+ }
284
+
285
+ /**
286
+ * Map an error thrown by the native secure-key module onto `DaaSdkError`. The
287
+ * raw native message is never propagated into `.message` — it can contain
288
+ * keystore/enclave internals that must not reach host-app logs — but is retained
289
+ * as `.cause` for deliberate inspection.
290
+ *
291
+ * An already-structured `DaaError` passes through unchanged. Otherwise a stable
292
+ * `code` on the native error maps the known custody states; anything else
293
+ * collapses to `contract_violation`.
294
+ */
295
+ export function mapNativeError(err: unknown): DaaError {
296
+ if (err instanceof DaaError) {
297
+ return err
298
+ }
299
+ const code = (err as { code?: unknown } | null | undefined)?.code
300
+ if (code === 'USER_AUTH_REQUIRED') {
301
+ return new DaaError(
302
+ { kind: 'local_user_authentication_required' },
303
+ 'DAA: user authentication is required',
304
+ err,
305
+ )
306
+ }
307
+ if (code === 'NOT_INITIALIZED') {
308
+ return new DaaError(
309
+ { kind: 'device_not_initialized' },
310
+ 'DAA: secure key is not initialized',
311
+ err,
312
+ )
313
+ }
314
+ return new DaaError(
315
+ { kind: 'contract_violation' },
316
+ 'DAA: native secure-key operation failed',
317
+ err,
318
+ )
319
+ }
package/src/index.ts ADDED
@@ -0,0 +1,223 @@
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
+ // Public surface of this package.
20
+ //
21
+ // The transport boundary, exact-byte serialization, the typed read/write clients
22
+ // (types only), and the login ceremony: Prepare, Social Session, Device
23
+ // Registration Complete, then `DaaClient.forUser` for an ACTIVE context.
24
+ // No generic signing API. Registered-device `signDeviceAuthorization` is
25
+ // bridged to native on both platforms. Device Registration Complete sends the
26
+ // two-JWS registration proof — `X-Device-Authorization` over the proposed
27
+ // AuthKey, plus `X-Registration-Flow-Authorization` over the ephemeral flow
28
+ // key committed at Prepare — and both signatures reach native, each through
29
+ // its OWN typed seam: the AuthKey signs the device proof through
30
+ // `signRegistrationDeviceAuthorization` (a different native function and
31
+ // validator from post-activation `signDeviceAuthorization` — see
32
+ // `securekey/SecureKey.ts`), and the flow key signs through
33
+ // `DaaRegistrationFlowKey.signRegistrationAuthorization`. Tests can also
34
+ // finish the ceremony with the WebCrypto flow-key provider and `./testing`
35
+ // InMemory AuthKeys.
36
+ //
37
+ // The Owner-key *interfaces* are exported (they carry no runtime capability and
38
+ // are the contract that native/production key stores implement). The concrete
39
+ // WebCrypto test double is NOT exported here — it lives behind the `./testing`
40
+ // subpath and fails closed in production builds. So raw-byte signing is
41
+ // unreachable from `.` on exports-aware resolvers, and gated by a runtime guard
42
+ // elsewhere (see SECURITY.md and the `exports` map in package.json).
43
+
44
+ export { DaaClient } from './DaaClient'
45
+
46
+ // Passkey SCA (native ceremony through Circle's hosted page). A runtime value
47
+ // on purpose: it is the only way to reach the DaaSca native module.
48
+ export { createScaClient, isScaError, ScaError } from './sca/ScaClient'
49
+ export type {
50
+ ScaCapabilities,
51
+ ScaClient,
52
+ ScaConfig,
53
+ ScaEnvironment,
54
+ ScaErrorCode,
55
+ } from './sca/ScaClient'
56
+
57
+ // The typed API surface and its models are exported as **types only**. That is
58
+ // what keeps a consumer from fabricating server-attributed data: there is no
59
+ // runtime constructor for `Account`, `Money`, `BusinessPii`, or `Address`
60
+ // anywhere on this entry, and the factory that builds them
61
+ // (`api/DaaUserClient.createDaaUserClient`) is not exported either. Every
62
+ // instance a caller can hold came from a response this SDK decoded. The models
63
+ // also carry `#` private fields, so an object literal cannot be *typed* as one
64
+ // of them either.
65
+ //
66
+ // The mixed prefixing is deliberate. The SDK contract states this surface in
67
+ // TypeScript, so for this SDK those are the names rather than an idiomatic
68
+ // rendering of them: `DaaClient`, `DaaUserClient`, `DaaTransport`,
69
+ // `DaaSdkConfiguration`, `DaaUserContext`, and `DaaSdkError` carry the prefix;
70
+ // the resources and sub-clients — `Account`, `AccountsClient`, `Page` — do not.
71
+ // Names the contract does not mention (`Money`, `BusinessPii`, `Address`)
72
+ // follow its convention for resources.
73
+ //
74
+ // TypeScript has no namespace to lean on the way the natives do, so a consumer
75
+ // imports into a flat scope; every unprefixed name here is type-only, and a
76
+ // collision with an app's own `Account` is resolved at the import site with `as`.
77
+ export type { AuthClient } from './api/AuthClient'
78
+ export type { AccountListQuery, AccountsClient } from './api/AccountsClient'
79
+ export type { AccountLimitsClient, AccountLimitsUsageQuery } from './api/AccountLimitsClient'
80
+ export type { DepositAddressListQuery, DepositAddressesClient } from './api/DepositAddressesClient'
81
+ export type { DepositListQuery, DepositsClient } from './api/DepositsClient'
82
+ export type { TransactionListQuery, TransactionsClient } from './api/TransactionsClient'
83
+ export type { TransferListQuery, TransfersClient } from './api/TransfersClient'
84
+ export type { WithdrawalListQuery, WithdrawalsClient } from './api/WithdrawalsClient'
85
+ export type { FiatAccountsClient } from './api/FiatAccountsClient'
86
+ export type {
87
+ PublicAccountId,
88
+ WireFiatAccountListQuery,
89
+ WireFiatAccountsClient,
90
+ WireInstructionQuery,
91
+ } from './api/WireFiatAccountsClient'
92
+ export type { AchFiatAccountListQuery, AchFiatAccountsClient } from './api/AchFiatAccountsClient'
93
+ export type { DaaUserClient } from './api/DaaUserClient'
94
+ export type {
95
+ DaaUserContext,
96
+ DeviceContext,
97
+ DeviceRegistrationResult,
98
+ } from './models/DaaUserContext'
99
+ export type { PendingDeviceRegistration } from './models/PendingDeviceRegistration'
100
+ export type {
101
+ Account,
102
+ AccountPurpose,
103
+ AccountRendering,
104
+ AccountStatus,
105
+ AccountType,
106
+ CustodyType,
107
+ } from './models/Account'
108
+ export type { CreateAccountRequest } from './models/CreateAccountRequest'
109
+ export type {
110
+ AccountLimitsUsage,
111
+ AccountLimitsUsageItem,
112
+ AccountLimitsUsageRendering,
113
+ AccountLimitsUsageResourceType,
114
+ LimitsUsageAssetType,
115
+ LimitsUsageComparisonType,
116
+ LimitsUsageOperation,
117
+ LimitsUsageUnit,
118
+ LimitsUsageWindow,
119
+ } from './models/AccountLimitsUsage'
120
+ export type {
121
+ CreateTransferAmount,
122
+ CreateTransferDestination,
123
+ CreateTransferRequest,
124
+ CreateTransferRiskSignals,
125
+ CreateTransferSource,
126
+ } from './models/CreateTransferRequest'
127
+ export type { Address, BusinessPii } from './models/BusinessPii'
128
+ export type { AddressObject, AddressObjectRendering } from './models/AddressObject'
129
+ export type { DepositAddressChain, GenerateAddressRequest } from './models/GenerateAddressRequest'
130
+ export type {
131
+ Deposit,
132
+ DepositAccountLocation,
133
+ DepositRendering,
134
+ DepositRiskEvaluation,
135
+ DepositSourceLocation,
136
+ DepositStatus,
137
+ DepositType,
138
+ } from './models/Deposit'
139
+ export type { DepositSummary, DepositSummaryRendering } from './models/DepositSummary'
140
+ export type { Money } from './models/Money'
141
+ export type { Page } from './models/Page'
142
+ export type { PreparedSocialLogin } from './models/PreparedSocialLogin'
143
+ export type {
144
+ Transaction,
145
+ TransactionAccountLocation,
146
+ TransactionBlockchainLocation,
147
+ TransactionBlockchainLocationRendering,
148
+ TransactionFiatLocation,
149
+ TransactionLocation,
150
+ TransactionRendering,
151
+ TransactionStatus,
152
+ TransactionType,
153
+ } from './models/Transaction'
154
+ export type {
155
+ Fee,
156
+ Transfer,
157
+ TransferDestinationAccountLocation,
158
+ TransferDestinationAccountLocationRendering,
159
+ TransferDestinationBlockchainLocation,
160
+ TransferDestinationBlockchainLocationRendering,
161
+ TransferDestinationLocation,
162
+ TransferErrorCode,
163
+ TransferPolicyEvaluation,
164
+ TransferRendering,
165
+ TransferSourceLocation,
166
+ TransferStatus,
167
+ } from './models/Transfer'
168
+ export type {
169
+ WithdrawalAdjustments,
170
+ WithdrawalDestination,
171
+ WithdrawalDestinationType,
172
+ WithdrawalDetail,
173
+ WithdrawalDetailRendering,
174
+ WithdrawalErrorCode,
175
+ WithdrawalPolicyEvaluation,
176
+ WithdrawalReturn,
177
+ WithdrawalRiskEvaluation,
178
+ WithdrawalStatus,
179
+ WithdrawalSubAccountSweep,
180
+ WithdrawalSweepStatus,
181
+ WithdrawalToAmount,
182
+ } from './models/Withdrawal'
183
+ export type {
184
+ CreateWithdrawalAmount,
185
+ CreateWithdrawalDestination,
186
+ CreateWithdrawalRequest,
187
+ CreateWithdrawalRiskSignals,
188
+ CreateWithdrawalSource,
189
+ CreateWithdrawalToAmount,
190
+ } from './models/CreateWithdrawalRequest'
191
+ export type { BankAddress, BillingDetails, FiatAccountStatus } from './models/FiatAccount'
192
+ export type {
193
+ TransferTypeInfo,
194
+ Wire,
195
+ WireInstruction,
196
+ WireInstructionBeneficiary,
197
+ WireInstructionBeneficiaryBank,
198
+ WireSummary,
199
+ } from './models/Wire'
200
+ export type {
201
+ ACH,
202
+ ACHInstruction,
203
+ ACHInstructionBeneficiary,
204
+ ACHInstructionBeneficiaryBank,
205
+ } from './models/Ach'
206
+
207
+ export { DAA_ENVIRONMENTS, DEVICE_KEY_POLICY } from './config'
208
+ export type { DaaEnvironment, DaaSdkConfiguration, DeviceKeyPolicy } from './config'
209
+ export type { DaaHttpRequest, DaaHttpResponse, DaaTransport } from './transport/DaaTransport'
210
+ export type { DaaSdkError } from './errors'
211
+ // Structured error thrown by the SDK; callers narrow with `isDaaError` and read
212
+ // `err.detail.kind`.
213
+ export { DaaError, isDaaError } from './errors'
214
+ export type {
215
+ AuthKeyResolution,
216
+ OwnerAuthKey,
217
+ OwnerKeyIdentity,
218
+ SecureKeyStore,
219
+ } from './securekey/SecureKey'
220
+
221
+ // Exact-byte serialization utilities.
222
+ export { serializeBody, serializeEmptyBody } from './crypto/serialization'
223
+ export { toBase64Url, fromBase64Url } from './crypto/base64url'