@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,257 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) 2026, Circle Internet Group, Inc. All rights reserved.
4
+ *
5
+ * SPDX-License-Identifier: Apache-2.0
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
20
+ if (kind === "m") throw new TypeError("Private method is not writable");
21
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
22
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
23
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
24
+ };
25
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
26
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
27
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
28
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
29
+ };
30
+ var _AuthClient_instances, _AuthClient_transport, _AuthClient_registrationFlowKeys, _AuthClient_authKeys, _AuthClient_environment, _AuthClient_prepareReceiptTrustAnchor, _AuthClient_resolveAuthKey, _AuthClient_requireEnvironmentForReceipt;
31
+ Object.defineProperty(exports, "__esModule", { value: true });
32
+ exports.AuthClient = void 0;
33
+ const registrationCodeVerifier_1 = require("../auth/registrationCodeVerifier");
34
+ const prepareReceipt_1 = require("../auth/prepareReceipt");
35
+ const RegistrationFlowKey_1 = require("../auth/RegistrationFlowKey");
36
+ const base64url_1 = require("../crypto/base64url");
37
+ const jwkThumbprint_1 = require("../crypto/jwkThumbprint");
38
+ const random_1 = require("../crypto/random");
39
+ const serialization_1 = require("../crypto/serialization");
40
+ const errors_1 = require("../errors");
41
+ const PreparedSocialLogin_1 = require("../models/PreparedSocialLogin");
42
+ const ownerAuthKeyResolver_1 = require("../securekey/ownerAuthKeyResolver");
43
+ const headers_1 = require("../transport/headers");
44
+ const socialLoginRequestPayload_1 = require("../wire/socialLoginRequestPayload");
45
+ const loginFailure_1 = require("./loginFailure");
46
+ const resourceRequest_1 = require("./resourceRequest");
47
+ /**
48
+ * `POST /v1/accounts/auth/loginRequests` — the contract's `prepareSocialLogin`
49
+ * operation, on the **public** path — the form a consumer's transport is
50
+ * handed, as for every other client here.
51
+ *
52
+ * There is no `/social/` segment. The contract path is
53
+ * `/v1/accounts/auth/loginRequests` (camelCase), and its sibling
54
+ * Social Session call is `/v1/accounts/auth/sessions`.
55
+ */
56
+ const PREPARE_SOCIAL_LOGIN_PATH = '/v1/accounts/auth/loginRequests';
57
+ /**
58
+ * Uppercase provider key, matching `PrepareSocialLoginRequest.provider`
59
+ * (`^[A-Z][A-Z0-9_]*$`, `maxLength: 64`). Providers are application-registry
60
+ * keys such as `GOOGLE` or `APPLE`, not raw issuer URLs.
61
+ */
62
+ const PROVIDER = /^[A-Z][A-Z0-9_]{0,63}$/;
63
+ /**
64
+ * Unpadded Base64URL of a 91-byte P-256 SPKI is always 122 characters, and the
65
+ * contract pins `registrationFlowPublicKey` to exactly that length. The charset
66
+ * is the one this SDK's Base64URL codec emits.
67
+ */
68
+ const FLOW_PUBLIC_KEY = /^[A-Za-z0-9_-]{122}$/;
69
+ /** `registrationCodeChallenge` is an unpadded Base64URL SHA-256 digest: 43 characters. */
70
+ const CODE_CHALLENGE = /^[A-Za-z0-9_-]{43}$/;
71
+ /**
72
+ * The social-login entry point: `AuthClient`.
73
+ *
74
+ * Login is split into three calls — Prepare, Social Session, Device
75
+ * Registration Complete. Prepare lives here; Session and Complete live on the
76
+ * values Prepare returns (`PreparedSocialLogin.completeSocialSession`,
77
+ * `PendingDeviceRegistration.complete`).
78
+ *
79
+ * Prepare does not touch an AuthKey. AuthKey selection happens only after
80
+ * the Social Session response, via the injected store (tests) or the native
81
+ * store (production). Prepare does check the DAA-signed Prepare receipt, before
82
+ * it returns anything to the application — see `prepareSocialLogin`.
83
+ *
84
+ * Not constructible by a consumer: exported from `index.ts` as a type only, and
85
+ * the `#transport` field makes the type nominal.
86
+ */
87
+ class AuthClient {
88
+ /** @internal Constructed only through `DaaClient`. */
89
+ constructor(args) {
90
+ _AuthClient_instances.add(this);
91
+ _AuthClient_transport.set(this, void 0);
92
+ _AuthClient_registrationFlowKeys.set(this, void 0);
93
+ _AuthClient_authKeys.set(this, void 0);
94
+ _AuthClient_environment.set(this, void 0);
95
+ _AuthClient_prepareReceiptTrustAnchor.set(this, void 0);
96
+ __classPrivateFieldSet(this, _AuthClient_transport, args.transport, "f");
97
+ __classPrivateFieldSet(this, _AuthClient_registrationFlowKeys, args.registrationFlowKeys ?? (0, RegistrationFlowKey_1.defaultRegistrationFlowKeyProvider)(), "f");
98
+ __classPrivateFieldSet(this, _AuthClient_authKeys, args.authKeys ?? (0, ownerAuthKeyResolver_1.createOwnerAuthKeyResolver)(args.identity ?? null, args.secureKeys ?? null), "f");
99
+ __classPrivateFieldSet(this, _AuthClient_environment, args.environment ?? args.identity?.environment ?? null, "f");
100
+ __classPrivateFieldSet(this, _AuthClient_prepareReceiptTrustAnchor, args.prepareReceiptTrustAnchor !== undefined
101
+ ? args.prepareReceiptTrustAnchor
102
+ : __classPrivateFieldGet(this, _AuthClient_environment, "f") === null
103
+ ? null
104
+ : (0, prepareReceipt_1.pinnedPrepareReceiptTrustAnchor)(__classPrivateFieldGet(this, _AuthClient_environment, "f")), "f");
105
+ Object.freeze(this);
106
+ }
107
+ /**
108
+ * Start one social-login attempt.
109
+ *
110
+ * The SDK owns the body `idempotencyKey`. Each call mints a new one and
111
+ * serializes the body once for that request; the key is kept on the returned
112
+ * `PreparedSocialLogin` so an ambiguous in-process retry can resend identical
113
+ * bytes. Durable persistence across a restart is not implemented — see
114
+ * `models/PreparedSocialLogin.ts`.
115
+ *
116
+ * The Prepare receipt is checked before this resolves, so an application
117
+ * never holds a nonce from a response that failed that check. With no trust
118
+ * anchor pinned for the environment — every environment in this release —
119
+ * the SDK does no receipt work: a receipt the service sends is ignored, login
120
+ * proceeds as if none arrived, and `prepareReceiptJws` is null. With an
121
+ * anchor pinned, the receipt is required and must verify. See
122
+ * `checkPrepareReceipt` in
123
+ * `auth/prepareReceipt.ts`.
124
+ *
125
+ * @throws DaaError with `detail.kind === 'prepare_receipt_invalid'` when an
126
+ * anchor is pinned and the receipt is missing, malformed, fails its
127
+ * signature or claim checks, has expired, or the platform verifier is
128
+ * missing or fails; `contract_violation` for a rejected provider, unusable
129
+ * local key material, a missing native DaaRegistration module, or a
130
+ * response the SDK cannot read;
131
+ * `login_request_expired` for `410`; `idempotency_conflict` for a `409`
132
+ * with `IDEMPOTENCY_KEY_REUSED` (`420034`); `contract_violation` with the
133
+ * correlation id for `LOGIN_REQUEST_CONSUMED` (`420039`); and `api` for any
134
+ * other status besides the documented `201`, including any other `409`.
135
+ * Whatever the consumer's transport throws is rethrown unchanged.
136
+ */
137
+ async prepareSocialLogin(input) {
138
+ if (typeof input !== 'object' || input === null || Array.isArray(input)) {
139
+ throw (0, errors_1.contractViolation)('prepareSocialLogin input must be an object');
140
+ }
141
+ if (typeof input.provider !== 'string' || !PROVIDER.test(input.provider)) {
142
+ throw (0, errors_1.contractViolation)('provider must be an uppercase identity-provider key of at most 64 characters');
143
+ }
144
+ const provider = input.provider;
145
+ // Ordering: verifier and flow key exist BEFORE Prepare is sent.
146
+ const registrationCodeVerifier = (0, registrationCodeVerifier_1.newRegistrationCodeVerifier)();
147
+ const registrationCodeChallenge = (0, registrationCodeVerifier_1.registrationCodeChallengeS256)(registrationCodeVerifier);
148
+ if (!CODE_CHALLENGE.test(registrationCodeChallenge)) {
149
+ throw (0, errors_1.contractViolation)('registration code challenge must be a 43-character unpadded Base64URL SHA-256 digest');
150
+ }
151
+ const registrationFlowKey = await __classPrivateFieldGet(this, _AuthClient_registrationFlowKeys, "f").generate();
152
+ try {
153
+ const registrationFlowPublicKey = await registrationFlowKey.publicKeySpkiBase64Url();
154
+ if (!FLOW_PUBLIC_KEY.test(registrationFlowPublicKey)) {
155
+ throw (0, errors_1.contractViolation)('registration-flow public key must be a 122-character unpadded Base64URL P-256 SPKI');
156
+ }
157
+ const idempotencyKey = newIdempotencyKey();
158
+ // Serialized once. These are the bytes that go on the wire, and the bytes an
159
+ // exact retry has to reproduce; nothing downstream re-serializes them.
160
+ //
161
+ // idempotencyKey + provider are required; challenge and flow key are
162
+ // optional. The service rejects unknown members with `400`, so
163
+ // `registrationCodeChallengeMethod` is not sent. Always send challenge +
164
+ // flow key; hold the verifier for Complete.
165
+ const bodyBytes = (0, serialization_1.serializeBody)({
166
+ idempotencyKey,
167
+ provider,
168
+ registrationCodeChallenge,
169
+ registrationFlowPublicKey,
170
+ });
171
+ const response = await __classPrivateFieldGet(this, _AuthClient_transport, "f").send({
172
+ method: 'POST',
173
+ path: PREPARE_SOCIAL_LOGIN_PATH,
174
+ query: null,
175
+ headers: { 'Content-Type': 'application/json' },
176
+ bodyBytes,
177
+ });
178
+ const failure = (0, loginFailure_1.loginStepFailure)(response, idempotencyKey);
179
+ if (failure !== null) {
180
+ throw failure;
181
+ }
182
+ const prepared = (0, resourceRequest_1.decodeResourceResponse)({
183
+ response,
184
+ expectedStatus: 201,
185
+ decode: socialLoginRequestPayload_1.toSocialLoginRequest,
186
+ });
187
+ const verifiedReceipt = await (0, prepareReceipt_1.checkPrepareReceipt)(prepared.prepareReceiptJws, __classPrivateFieldGet(this, _AuthClient_prepareReceiptTrustAnchor, "f"), () => ({
188
+ loginRequestId: prepared.loginRequestId,
189
+ nonce: prepared.oidcNonce,
190
+ provider,
191
+ environment: __classPrivateFieldGet(this, _AuthClient_instances, "m", _AuthClient_requireEnvironmentForReceipt).call(this),
192
+ // The SDK's own values, generated before Prepare was sent: the two a
193
+ // relay substituting another attempt cannot make match.
194
+ registrationCodeChallenge,
195
+ registrationFlowKeyThumbprint: (0, jwkThumbprint_1.p256JwkThumbprint)((0, base64url_1.fromBase64Url)(registrationFlowPublicKey)),
196
+ })).catch((err) => {
197
+ // A rejected receipt came from this response, so it names the
198
+ // response's request id. A `contract_violation` from the check is this
199
+ // SDK's own configuration fault and is left as it is.
200
+ throw (0, errors_1.isDaaError)(err) && err.detail.kind === 'prepare_receipt_invalid'
201
+ ? (0, errors_1.withRequestId)(err, (0, headers_1.headerValueIgnoringCase)(response.headers, 'X-Request-Id'))
202
+ : err;
203
+ });
204
+ return new PreparedSocialLogin_1.PreparedSocialLogin({
205
+ loginRequestId: prepared.loginRequestId,
206
+ oidcNonce: prepared.oidcNonce,
207
+ oidcState: prepared.oidcState,
208
+ // Only a receipt that verified; an ignored one is not handed on.
209
+ prepareReceiptJws: verifiedReceipt === null ? null : verifiedReceipt.compactJws,
210
+ expiresAt: prepared.expiresAt,
211
+ registrationCodeVerifier,
212
+ registrationFlowKey,
213
+ idempotencyKey,
214
+ transport: __classPrivateFieldGet(this, _AuthClient_transport, "f"),
215
+ resolveAuthKey: (clientEntityId) => __classPrivateFieldGet(this, _AuthClient_instances, "m", _AuthClient_resolveAuthKey).call(this, clientEntityId),
216
+ });
217
+ }
218
+ catch (error) {
219
+ // Keep the key on a successful PreparedSocialLogin — Complete still needs
220
+ // the private half. A failed attempt has no holder, so drop the native
221
+ // cache entry rather than leaking it for the process lifetime.
222
+ await (0, RegistrationFlowKey_1.releaseQuietly)(registrationFlowKey);
223
+ throw error;
224
+ }
225
+ }
226
+ }
227
+ exports.AuthClient = AuthClient;
228
+ _AuthClient_transport = new WeakMap(), _AuthClient_registrationFlowKeys = new WeakMap(), _AuthClient_authKeys = new WeakMap(), _AuthClient_environment = new WeakMap(), _AuthClient_prepareReceiptTrustAnchor = new WeakMap(), _AuthClient_instances = new WeakSet(), _AuthClient_resolveAuthKey =
229
+ /**
230
+ * Select or create the installation AuthKey only after Social Session.
231
+ * Prepare never calls this.
232
+ *
233
+ * `clientEntityId` namespaces the key per Owner. The caller —
234
+ * `PreparedSocialLogin.completeSocialSession` — passes the Social Session
235
+ * response's OWN echo of `clientEntityId`, not the value the application
236
+ * supplied to that call, because the response is the server-confirmed one.
237
+ *
238
+ * Private, and it stays private — with an ECMAScript `#` private field, not
239
+ * TypeScript's `private` keyword, which is erased at build time and would
240
+ * leave an ordinary callable method on the prototype. `AuthClient` is
241
+ * reachable from a consumer as `DaaClient.auth`, so a merely
242
+ * compile-time-private method here would hand out an `OwnerAuthKey` — and
243
+ * with it `signExactBytes` — which is the generic signing surface this SDK
244
+ * does not have. `forUser` reaches the same key through the resolver
245
+ * `DaaClient` owns, not through this client.
246
+ */
247
+ async function _AuthClient_resolveAuthKey(clientEntityId) {
248
+ return __classPrivateFieldGet(this, _AuthClient_authKeys, "f").call(this, clientEntityId);
249
+ }, _AuthClient_requireEnvironmentForReceipt = function _AuthClient_requireEnvironmentForReceipt() {
250
+ if (__classPrivateFieldGet(this, _AuthClient_environment, "f") === null) {
251
+ throw (0, errors_1.contractViolation)('verifying a Prepare receipt requires the configured environment');
252
+ }
253
+ return __classPrivateFieldGet(this, _AuthClient_environment, "f");
254
+ };
255
+ function newIdempotencyKey() {
256
+ return (0, random_1.randomUuidV4)();
257
+ }
@@ -0,0 +1,124 @@
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
+ import type { DaaEnvironment } from '../config';
19
+ import type { DeviceContext } from '../models/DaaUserContext';
20
+ import type { DaaTransport } from '../transport/DaaTransport';
21
+ import { AccountLimitsClient } from './AccountLimitsClient';
22
+ import { AccountsClient } from './AccountsClient';
23
+ import { DepositAddressesClient } from './DepositAddressesClient';
24
+ import { DepositsClient } from './DepositsClient';
25
+ import { FiatAccountsClient } from './FiatAccountsClient';
26
+ import { type DaaUserSigning } from './signedResource';
27
+ import { TransactionsClient } from './TransactionsClient';
28
+ import { TransfersClient } from './TransfersClient';
29
+ import { WithdrawalsClient } from './WithdrawalsClient';
30
+ /**
31
+ * The authenticated operations surface, as the SDK contract's `DaaUserClient`.
32
+ *
33
+ * The contract reaches this through the root client's `forUser(context)`, and every
34
+ * operation lives here rather than on the root client — the root client has only
35
+ * `auth` and `forUser`.
36
+ *
37
+ * Every resource client here has at least one operation; the surface never
38
+ * exposes a client with none.
39
+ *
40
+ * Signing material reaches only the clients that have a signed operation.
41
+ * Account limits, deposits, deposit addresses, transactions, and fiat
42
+ * accounts read (and, for deposit addresses, write unsigned) and so are
43
+ * handed none — a client that cannot sign cannot be made to sign by a later
44
+ * edit that forgets which calls are authorized. Fiat-account reads and
45
+ * get-instructions are both unsigned operations; for account limits/usage,
46
+ * see `AccountLimitsClient`'s class note for why it is unsigned.
47
+ */
48
+ export declare class DaaUserClient {
49
+ #private;
50
+ /** Reads over DAA accounts, and the signed account create. */
51
+ readonly accounts: AccountsClient;
52
+ /** Reads over an account's limits and current usage. */
53
+ readonly accountLimits: AccountLimitsClient;
54
+ /** Reads over DAA deposit addresses. */
55
+ readonly depositAddresses: DepositAddressesClient;
56
+ /** Reads over DAA deposits, and the paged deposit list. */
57
+ readonly deposits: DepositsClient;
58
+ /** Reads over DAA unified account activity. */
59
+ readonly transactions: TransactionsClient;
60
+ /** Reads over DAA transfers, and the signed transfer create. */
61
+ readonly transfers: TransfersClient;
62
+ /** Reads over DAA withdrawals, and the signed withdrawal create. */
63
+ readonly withdrawals: WithdrawalsClient;
64
+ /** Reads over wire and ACH fiat accounts, and their receiving instructions. */
65
+ readonly fiatAccounts: FiatAccountsClient;
66
+ /** @internal Constructed only through {@link createDaaUserClient}. */
67
+ constructor(transport: DaaTransport, environment: DaaEnvironment, signing: DaaUserSigning, publicApiOriginOverride?: string);
68
+ /**
69
+ * Signed context refresh (`refreshContext`).
70
+ *
71
+ * `get_device_context` (`GET /v1/accounts/auth/context`) is a registered-device
72
+ * authorization operation, not an ordinary unsigned read: the device
73
+ * authorization payload applies to registered-device authorization for
74
+ * protected writes and signed context refresh, alongside `transfer` and
75
+ * `withdrawal`, and `securekey/SecureKey.ts` names "signed context refresh"
76
+ * alongside "protected writes" as one of the defined DAA operations signing is
77
+ * reachable for. There is no request body: `getSignedResource` signs over the
78
+ * empty byte array per the bodyless-request rule and sends nothing as
79
+ * the request entity.
80
+ *
81
+ * @throws DaaError with `detail.kind === 'contract_violation'` for an AuthKey
82
+ * that is not yet registered, for a rejected or replayed authorization
83
+ * (including a key that is no longer active: DAA has no revoked-credential
84
+ * code, so this never throws `device_revoked`), for a response the SDK
85
+ * cannot read, and once this client is {@link close}d;
86
+ * `detail.kind === 'api'` for a status other than the documented `200`; and
87
+ * `detail.kind === 'transport'` if the consumer's transport throws, with
88
+ * the thrown value as `err.cause`.
89
+ */
90
+ refreshContext(): Promise<DeviceContext>;
91
+ /**
92
+ * `DaaUserClient.close()` clears active context from memory and cancels
93
+ * unsent work. It preserves an active profile-scoped AuthKey and credential;
94
+ * application logout is not device revocation.
95
+ *
96
+ * This class holds no `DaaUserContext` object and no cancellable in-flight
97
+ * work of its own to release — the context a caller passed to `forUser` is
98
+ * never retained here, only the plain `authKeyId` string and a resolver
99
+ * closure, and every call this SDK makes is a single `transport.send` awaited
100
+ * to completion with no cancellation token in the transport contract to
101
+ * cancel. Concretely, close() revokes this instance's own capability to
102
+ * produce a fresh `X-Device-Authorization` at all, so `refreshContext` and
103
+ * every signed `create` on `accounts` / `transfers` / `withdrawals` fail
104
+ * closed with `contract_violation` from this point on instead of silently
105
+ * continuing to sign. The guarded transport also refuses unsigned reads, writes, and
106
+ * retained Page navigation closures after close, so unsent work cannot
107
+ * outlive the user surface that created it. The registered AuthKey and
108
+ * Circle's registration acknowledgement are untouched — nothing here calls
109
+ * the native store, so there is nothing here that could revoke either.
110
+ * Idempotent: closing an already-closed client is a no-op.
111
+ */
112
+ close(): void;
113
+ }
114
+ /**
115
+ * Build the operations surface over a transport.
116
+ *
117
+ * Deliberately **not** exported from `index.ts`, and deliberately not a member of
118
+ * `DaaClient`: a consumer must not reach this without the user context that
119
+ * `forUser` requires, decoded from an `ACTIVE` Device Registration Complete.
120
+ *
121
+ * `publicApiOrigin` is the override `DaaClient` has already validated. Without
122
+ * it, the environment's public API origin is the pagination trust anchor.
123
+ */
124
+ export declare function createDaaUserClient(transport: DaaTransport, environment: DaaEnvironment, signing: DaaUserSigning, publicApiOrigin?: string): DaaUserClient;
@@ -0,0 +1,245 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) 2026, Circle Internet Group, Inc. All rights reserved.
4
+ *
5
+ * SPDX-License-Identifier: Apache-2.0
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
20
+ if (kind === "m") throw new TypeError("Private method is not writable");
21
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
22
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
23
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
24
+ };
25
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
26
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
27
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
28
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
29
+ };
30
+ var _DaaUserClient_transport, _DaaUserClient_signing, _DaaUserClient_markClosed;
31
+ Object.defineProperty(exports, "__esModule", { value: true });
32
+ exports.DaaUserClient = void 0;
33
+ exports.createDaaUserClient = createDaaUserClient;
34
+ const config_1 = require("../config");
35
+ const deviceAuthorization_1 = require("../auth/deviceAuthorization");
36
+ const errors_1 = require("../errors");
37
+ const deviceContextPayload_1 = require("../wire/deviceContextPayload");
38
+ const AccountLimitsClient_1 = require("./AccountLimitsClient");
39
+ const AccountsClient_1 = require("./AccountsClient");
40
+ const DepositAddressesClient_1 = require("./DepositAddressesClient");
41
+ const DepositsClient_1 = require("./DepositsClient");
42
+ const FiatAccountsClient_1 = require("./FiatAccountsClient");
43
+ const signedResource_1 = require("./signedResource");
44
+ const TransactionsClient_1 = require("./TransactionsClient");
45
+ const TransfersClient_1 = require("./TransfersClient");
46
+ const WithdrawalsClient_1 = require("./WithdrawalsClient");
47
+ /**
48
+ * The authenticated operations surface, as the SDK contract's `DaaUserClient`.
49
+ *
50
+ * The contract reaches this through the root client's `forUser(context)`, and every
51
+ * operation lives here rather than on the root client — the root client has only
52
+ * `auth` and `forUser`.
53
+ *
54
+ * Every resource client here has at least one operation; the surface never
55
+ * exposes a client with none.
56
+ *
57
+ * Signing material reaches only the clients that have a signed operation.
58
+ * Account limits, deposits, deposit addresses, transactions, and fiat
59
+ * accounts read (and, for deposit addresses, write unsigned) and so are
60
+ * handed none — a client that cannot sign cannot be made to sign by a later
61
+ * edit that forgets which calls are authorized. Fiat-account reads and
62
+ * get-instructions are both unsigned operations; for account limits/usage,
63
+ * see `AccountLimitsClient`'s class note for why it is unsigned.
64
+ */
65
+ class DaaUserClient {
66
+ /** @internal Constructed only through {@link createDaaUserClient}. */
67
+ constructor(transport, environment, signing, publicApiOriginOverride) {
68
+ _DaaUserClient_transport.set(this, void 0);
69
+ _DaaUserClient_signing.set(this, void 0);
70
+ _DaaUserClient_markClosed.set(this, void 0);
71
+ const publicApiOrigin = publicApiOriginOverride ?? (0, config_1.publicApiOriginFor)(environment);
72
+ // `close()` has to reach every signed operation this surface
73
+ // exposes, not just `refreshContext` — an accounts/transfers/withdrawals
74
+ // `create` reached through a "closed" client is exactly the further use
75
+ // `close()` exists to refuse. Every signed client below is handed this one
76
+ // wrapper rather than the caller's `signing` directly, so flipping `closed`
77
+ // here closes all of them at once without editing any resource client.
78
+ let closed = false;
79
+ const assertOpen = () => {
80
+ if (closed) {
81
+ throw (0, errors_1.contractViolation)('DaaUserClient is closed; call DaaClient.forUser again to resume operations');
82
+ }
83
+ };
84
+ const guardedSigning = Object.freeze({
85
+ authKeyId: signing.authKeyId,
86
+ resolveAuthKey: async () => {
87
+ assertOpen();
88
+ return guardAuthKey(await signing.resolveAuthKey(), assertOpen);
89
+ },
90
+ });
91
+ // The transport guard closes unsent unsigned work too: a retained Page's
92
+ // next()/previous() closure still holds the client it was created from,
93
+ // so handing every resource client this wrapper makes close() reach those
94
+ // later sends without editing each pagination client.
95
+ //
96
+ // It is also the one place every operation on this surface reaches the
97
+ // consumer's transport, so it is where a throw from that transport becomes
98
+ // the SDK's `transport` error (see `transportFailure`). Only the send is
99
+ // wrapped: a closed client's `contract_violation` is the SDK's own refusal,
100
+ // not a transport failure, and is thrown before anything is sent.
101
+ const guardedTransport = Object.freeze({
102
+ send: async (request) => {
103
+ assertOpen();
104
+ try {
105
+ return await transport.send(request);
106
+ }
107
+ catch (err) {
108
+ throw asTransportFailure(err, request);
109
+ }
110
+ },
111
+ });
112
+ this.accounts = new AccountsClient_1.AccountsClient(guardedTransport, publicApiOrigin, guardedSigning);
113
+ this.accountLimits = new AccountLimitsClient_1.AccountLimitsClient(guardedTransport);
114
+ this.depositAddresses = new DepositAddressesClient_1.DepositAddressesClient(guardedTransport, publicApiOrigin);
115
+ this.deposits = new DepositsClient_1.DepositsClient(guardedTransport, publicApiOrigin);
116
+ this.transactions = new TransactionsClient_1.TransactionsClient(guardedTransport, publicApiOrigin);
117
+ this.transfers = new TransfersClient_1.TransfersClient(guardedTransport, publicApiOrigin, guardedSigning);
118
+ this.withdrawals = new WithdrawalsClient_1.WithdrawalsClient(guardedTransport, publicApiOrigin, guardedSigning);
119
+ this.fiatAccounts = new FiatAccountsClient_1.FiatAccountsClient(guardedTransport);
120
+ __classPrivateFieldSet(this, _DaaUserClient_transport, guardedTransport, "f");
121
+ __classPrivateFieldSet(this, _DaaUserClient_signing, guardedSigning, "f");
122
+ __classPrivateFieldSet(this, _DaaUserClient_markClosed, () => {
123
+ closed = true;
124
+ }, "f");
125
+ Object.freeze(this);
126
+ }
127
+ /**
128
+ * Signed context refresh (`refreshContext`).
129
+ *
130
+ * `get_device_context` (`GET /v1/accounts/auth/context`) is a registered-device
131
+ * authorization operation, not an ordinary unsigned read: the device
132
+ * authorization payload applies to registered-device authorization for
133
+ * protected writes and signed context refresh, alongside `transfer` and
134
+ * `withdrawal`, and `securekey/SecureKey.ts` names "signed context refresh"
135
+ * alongside "protected writes" as one of the defined DAA operations signing is
136
+ * reachable for. There is no request body: `getSignedResource` signs over the
137
+ * empty byte array per the bodyless-request rule and sends nothing as
138
+ * the request entity.
139
+ *
140
+ * @throws DaaError with `detail.kind === 'contract_violation'` for an AuthKey
141
+ * that is not yet registered, for a rejected or replayed authorization
142
+ * (including a key that is no longer active: DAA has no revoked-credential
143
+ * code, so this never throws `device_revoked`), for a response the SDK
144
+ * cannot read, and once this client is {@link close}d;
145
+ * `detail.kind === 'api'` for a status other than the documented `200`; and
146
+ * `detail.kind === 'transport'` if the consumer's transport throws, with
147
+ * the thrown value as `err.cause`.
148
+ */
149
+ async refreshContext() {
150
+ return (0, signedResource_1.getSignedResource)({
151
+ transport: __classPrivateFieldGet(this, _DaaUserClient_transport, "f"),
152
+ operation: 'get_device_context',
153
+ authKey: await __classPrivateFieldGet(this, _DaaUserClient_signing, "f").resolveAuthKey(),
154
+ authKeyId: __classPrivateFieldGet(this, _DaaUserClient_signing, "f").authKeyId,
155
+ expectedStatus: 200,
156
+ decode: deviceContextPayload_1.toDeviceContext,
157
+ });
158
+ }
159
+ /**
160
+ * `DaaUserClient.close()` clears active context from memory and cancels
161
+ * unsent work. It preserves an active profile-scoped AuthKey and credential;
162
+ * application logout is not device revocation.
163
+ *
164
+ * This class holds no `DaaUserContext` object and no cancellable in-flight
165
+ * work of its own to release — the context a caller passed to `forUser` is
166
+ * never retained here, only the plain `authKeyId` string and a resolver
167
+ * closure, and every call this SDK makes is a single `transport.send` awaited
168
+ * to completion with no cancellation token in the transport contract to
169
+ * cancel. Concretely, close() revokes this instance's own capability to
170
+ * produce a fresh `X-Device-Authorization` at all, so `refreshContext` and
171
+ * every signed `create` on `accounts` / `transfers` / `withdrawals` fail
172
+ * closed with `contract_violation` from this point on instead of silently
173
+ * continuing to sign. The guarded transport also refuses unsigned reads, writes, and
174
+ * retained Page navigation closures after close, so unsent work cannot
175
+ * outlive the user surface that created it. The registered AuthKey and
176
+ * Circle's registration acknowledgement are untouched — nothing here calls
177
+ * the native store, so there is nothing here that could revoke either.
178
+ * Idempotent: closing an already-closed client is a no-op.
179
+ */
180
+ close() {
181
+ __classPrivateFieldGet(this, _DaaUserClient_markClosed, "f").call(this);
182
+ }
183
+ }
184
+ exports.DaaUserClient = DaaUserClient;
185
+ _DaaUserClient_transport = new WeakMap(), _DaaUserClient_signing = new WeakMap(), _DaaUserClient_markClosed = new WeakMap();
186
+ /**
187
+ * Keep an in-flight signed operation tied to this user's lifecycle. The
188
+ * resolver guard prevents new operations after `close()`, while the signing
189
+ * guard also covers an operation that started before `close()` and would
190
+ * otherwise sign with the already-resolved AuthKey.
191
+ */
192
+ function guardAuthKey(authKey, assertOpen) {
193
+ return Object.freeze({
194
+ publicKeySpkiBase64Url: () => authKey.publicKeySpkiBase64Url(),
195
+ thumbprint: () => authKey.thumbprint(),
196
+ resolution: () => authKey.resolution(),
197
+ acknowledgeRegistration: () => authKey.acknowledgeRegistration(),
198
+ signExactBytes: async (message) => {
199
+ assertOpen();
200
+ return authKey.signExactBytes(message);
201
+ },
202
+ signRegistrationDeviceAuthorization: async (message) => {
203
+ assertOpen();
204
+ return authKey.signRegistrationDeviceAuthorization(message);
205
+ },
206
+ });
207
+ }
208
+ /**
209
+ * Build the operations surface over a transport.
210
+ *
211
+ * Deliberately **not** exported from `index.ts`, and deliberately not a member of
212
+ * `DaaClient`: a consumer must not reach this without the user context that
213
+ * `forUser` requires, decoded from an `ACTIVE` Device Registration Complete.
214
+ *
215
+ * `publicApiOrigin` is the override `DaaClient` has already validated. Without
216
+ * it, the environment's public API origin is the pagination trust anchor.
217
+ */
218
+ function createDaaUserClient(transport, environment, signing, publicApiOrigin) {
219
+ return new DaaUserClient(transport, environment, signing, publicApiOrigin);
220
+ }
221
+ /**
222
+ * Wrap a throw from the consumer's transport as a `transport` error. An error
223
+ * that is already a `DaaError` passes through unchanged, as in
224
+ * `mapNativeError`.
225
+ *
226
+ * The idempotency key is read from the exact bytes that were handed to the
227
+ * transport, with the same reader the signed `409` mapping uses. A body the
228
+ * reader cannot parse leaves the key off rather than replacing the transport
229
+ * failure with a different error.
230
+ */
231
+ function asTransportFailure(err, request) {
232
+ if (err instanceof errors_1.DaaError) {
233
+ return err;
234
+ }
235
+ let idempotencyKey;
236
+ if (request.bodyBytes !== null) {
237
+ try {
238
+ idempotencyKey = (0, deviceAuthorization_1.idempotencyKeyFromExactBody)(request.bodyBytes);
239
+ }
240
+ catch {
241
+ idempotencyKey = undefined;
242
+ }
243
+ }
244
+ return (0, errors_1.transportFailure)(err, idempotencyKey);
245
+ }