@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.
- package/DaaReactNativeSdk.podspec +63 -0
- package/LICENSE +176 -0
- package/README.md +217 -2
- package/android/build.gradle +97 -0
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/java/com/circle/daa/reactnative/DaaRegistrationExceptions.kt +47 -0
- package/android/src/main/java/com/circle/daa/reactnative/DaaRegistrationModule.kt +121 -0
- package/android/src/main/java/com/circle/daa/reactnative/DaaScaExceptions.kt +60 -0
- package/android/src/main/java/com/circle/daa/reactnative/DaaScaModule.kt +179 -0
- package/android/src/main/java/com/circle/daa/reactnative/DaaSecureKeyExceptions.kt +73 -0
- package/android/src/main/java/com/circle/daa/reactnative/DaaSecureKeyModule.kt +185 -0
- package/android/src/main/java/com/circle/daa/reactnative/InstallationIdentityStore.kt +73 -0
- package/android/src/main/java/com/circle/daa/reactnative/UnpaddedBase64Url.kt +45 -0
- package/build/DaaClient.d.ts +57 -0
- package/build/DaaClient.js +158 -0
- package/build/api/AccountLimitsClient.d.ts +79 -0
- package/build/api/AccountLimitsClient.js +142 -0
- package/build/api/AccountsClient.d.ts +95 -0
- package/build/api/AccountsClient.js +276 -0
- package/build/api/AchFiatAccountsClient.d.ts +92 -0
- package/build/api/AchFiatAccountsClient.js +142 -0
- package/build/api/AuthClient.d.ts +120 -0
- package/build/api/AuthClient.js +257 -0
- package/build/api/DaaUserClient.d.ts +124 -0
- package/build/api/DaaUserClient.js +245 -0
- package/build/api/DepositAddressesClient.d.ts +112 -0
- package/build/api/DepositAddressesClient.js +222 -0
- package/build/api/DepositsClient.d.ts +106 -0
- package/build/api/DepositsClient.js +183 -0
- package/build/api/FiatAccountsClient.d.ts +43 -0
- package/build/api/FiatAccountsClient.js +46 -0
- package/build/api/TransactionsClient.d.ts +64 -0
- package/build/api/TransactionsClient.js +120 -0
- package/build/api/TransfersClient.d.ts +104 -0
- package/build/api/TransfersClient.js +321 -0
- package/build/api/WireFiatAccountsClient.d.ts +99 -0
- package/build/api/WireFiatAccountsClient.js +156 -0
- package/build/api/WithdrawalsClient.d.ts +94 -0
- package/build/api/WithdrawalsClient.js +305 -0
- package/build/api/loginFailure.d.ts +43 -0
- package/build/api/loginFailure.js +64 -0
- package/build/api/pagination.d.ts +29 -0
- package/build/api/pagination.js +50 -0
- package/build/api/queryParameters.d.ts +23 -0
- package/build/api/queryParameters.js +77 -0
- package/build/api/resourceRequest.d.ts +60 -0
- package/build/api/resourceRequest.js +79 -0
- package/build/api/signedResource.d.ts +77 -0
- package/build/api/signedResource.js +168 -0
- package/build/auth/RegistrationFlowKey.d.ts +93 -0
- package/build/auth/RegistrationFlowKey.js +203 -0
- package/build/auth/daaRegistrationNative.d.ts +80 -0
- package/build/auth/daaRegistrationNative.js +184 -0
- package/build/auth/deviceAuthorization.d.ts +73 -0
- package/build/auth/deviceAuthorization.js +243 -0
- package/build/auth/ownerGrant.d.ts +29 -0
- package/build/auth/ownerGrant.js +90 -0
- package/build/auth/prepareReceipt.d.ts +150 -0
- package/build/auth/prepareReceipt.js +357 -0
- package/build/auth/registrationAuthorization.d.ts +48 -0
- package/build/auth/registrationAuthorization.js +243 -0
- package/build/auth/registrationCodeVerifier.d.ts +31 -0
- package/build/auth/registrationCodeVerifier.js +75 -0
- package/build/config.d.ts +79 -0
- package/build/config.js +116 -0
- package/build/crypto/base64url.d.ts +26 -0
- package/build/crypto/base64url.js +87 -0
- package/build/crypto/bytes.d.ts +27 -0
- package/build/crypto/bytes.js +32 -0
- package/build/crypto/es256Jws.d.ts +56 -0
- package/build/crypto/es256Jws.js +196 -0
- package/build/crypto/jwkThumbprint.d.ts +32 -0
- package/build/crypto/jwkThumbprint.js +49 -0
- package/build/crypto/random.d.ts +35 -0
- package/build/crypto/random.js +106 -0
- package/build/crypto/serialization.d.ts +26 -0
- package/build/crypto/serialization.js +43 -0
- package/build/crypto/sha256.d.ts +18 -0
- package/build/crypto/sha256.js +100 -0
- package/build/errors.d.ts +190 -0
- package/build/errors.js +252 -0
- package/build/index.d.ts +61 -0
- package/build/index.js +67 -0
- package/build/models/Account.d.ts +201 -0
- package/build/models/Account.js +147 -0
- package/build/models/AccountLimitsUsage.d.ts +169 -0
- package/build/models/AccountLimitsUsage.js +86 -0
- package/build/models/Ach.d.ts +135 -0
- package/build/models/Ach.js +184 -0
- package/build/models/AddressObject.d.ts +128 -0
- package/build/models/AddressObject.js +141 -0
- package/build/models/BusinessPii.d.ts +84 -0
- package/build/models/BusinessPii.js +142 -0
- package/build/models/CreateAccountRequest.d.ts +74 -0
- package/build/models/CreateAccountRequest.js +19 -0
- package/build/models/CreateTransferRequest.d.ts +91 -0
- package/build/models/CreateTransferRequest.js +19 -0
- package/build/models/CreateWithdrawalRequest.d.ts +99 -0
- package/build/models/CreateWithdrawalRequest.js +19 -0
- package/build/models/DaaUserContext.d.ts +96 -0
- package/build/models/DaaUserContext.js +133 -0
- package/build/models/Deposit.d.ts +241 -0
- package/build/models/Deposit.js +149 -0
- package/build/models/DepositSummary.d.ts +91 -0
- package/build/models/DepositSummary.js +114 -0
- package/build/models/FiatAccount.d.ts +99 -0
- package/build/models/FiatAccount.js +151 -0
- package/build/models/GenerateAddressRequest.d.ts +67 -0
- package/build/models/GenerateAddressRequest.js +68 -0
- package/build/models/Money.d.ts +76 -0
- package/build/models/Money.js +99 -0
- package/build/models/Page.d.ts +33 -0
- package/build/models/Page.js +57 -0
- package/build/models/PendingDeviceRegistration.d.ts +90 -0
- package/build/models/PendingDeviceRegistration.js +180 -0
- package/build/models/PreparedSocialLogin.d.ts +155 -0
- package/build/models/PreparedSocialLogin.js +235 -0
- package/build/models/Transaction.d.ts +187 -0
- package/build/models/Transaction.js +134 -0
- package/build/models/Transfer.d.ts +335 -0
- package/build/models/Transfer.js +240 -0
- package/build/models/Wire.d.ts +213 -0
- package/build/models/Wire.js +264 -0
- package/build/models/Withdrawal.d.ts +201 -0
- package/build/models/Withdrawal.js +156 -0
- package/build/models/redaction.d.ts +18 -0
- package/build/models/redaction.js +23 -0
- package/build/sca/ScaClient.d.ts +105 -0
- package/build/sca/ScaClient.js +193 -0
- package/build/securekey/InMemorySecureKey.d.ts +23 -0
- package/build/securekey/InMemorySecureKey.js +127 -0
- package/build/securekey/NativeSecureKey.d.ts +24 -0
- package/build/securekey/NativeSecureKey.js +178 -0
- package/build/securekey/NativeSecureKeyBridge.d.ts +83 -0
- package/build/securekey/NativeSecureKeyBridge.js +19 -0
- package/build/securekey/SecureKey.d.ts +137 -0
- package/build/securekey/SecureKey.js +19 -0
- package/build/securekey/alias.d.ts +88 -0
- package/build/securekey/alias.js +175 -0
- package/build/securekey/ownerAuthKeyResolver.d.ts +56 -0
- package/build/securekey/ownerAuthKeyResolver.js +63 -0
- package/build/securekey/resolveNativeBridge.d.ts +30 -0
- package/build/securekey/resolveNativeBridge.js +120 -0
- package/build/testing.d.ts +18 -0
- package/build/testing.js +34 -0
- package/build/transport/DaaTransport.d.ts +35 -0
- package/build/transport/DaaTransport.js +19 -0
- package/build/transport/headers.d.ts +30 -0
- package/build/transport/headers.js +45 -0
- package/build/validation/requestBody.d.ts +27 -0
- package/build/validation/requestBody.js +56 -0
- package/build/validation/uuid.d.ts +25 -0
- package/build/validation/uuid.js +33 -0
- package/build/wire/accountLimitsUsagePayload.d.ts +30 -0
- package/build/wire/accountLimitsUsagePayload.js +130 -0
- package/build/wire/accountPayload.d.ts +36 -0
- package/build/wire/accountPayload.js +100 -0
- package/build/wire/achPayload.d.ts +24 -0
- package/build/wire/achPayload.js +82 -0
- package/build/wire/addressObjectPayload.d.ts +44 -0
- package/build/wire/addressObjectPayload.js +64 -0
- package/build/wire/daaStatusCodes.d.ts +64 -0
- package/build/wire/daaStatusCodes.js +69 -0
- package/build/wire/dataEnvelope.d.ts +40 -0
- package/build/wire/dataEnvelope.js +79 -0
- package/build/wire/depositPayload.d.ts +42 -0
- package/build/wire/depositPayload.js +159 -0
- package/build/wire/deviceContextPayload.d.ts +33 -0
- package/build/wire/deviceContextPayload.js +57 -0
- package/build/wire/deviceRegistrationResultPayload.d.ts +32 -0
- package/build/wire/deviceRegistrationResultPayload.js +128 -0
- package/build/wire/errorEnvelope.d.ts +43 -0
- package/build/wire/errorEnvelope.js +85 -0
- package/build/wire/fiatAccountPayload.d.ts +37 -0
- package/build/wire/fiatAccountPayload.js +93 -0
- package/build/wire/instant.d.ts +27 -0
- package/build/wire/instant.js +91 -0
- package/build/wire/jsonNumber.d.ts +30 -0
- package/build/wire/jsonNumber.js +34 -0
- package/build/wire/moneyPayload.d.ts +30 -0
- package/build/wire/moneyPayload.js +56 -0
- package/build/wire/paginationLinks.d.ts +28 -0
- package/build/wire/paginationLinks.js +167 -0
- package/build/wire/payload.d.ts +60 -0
- package/build/wire/payload.js +121 -0
- package/build/wire/pendingRegistrationPayload.d.ts +32 -0
- package/build/wire/pendingRegistrationPayload.js +54 -0
- package/build/wire/socialLoginRequestPayload.d.ts +31 -0
- package/build/wire/socialLoginRequestPayload.js +72 -0
- package/build/wire/transactionPayload.d.ts +31 -0
- package/build/wire/transactionPayload.js +126 -0
- package/build/wire/transferPayload.d.ts +43 -0
- package/build/wire/transferPayload.js +218 -0
- package/build/wire/wireEnums.d.ts +22 -0
- package/build/wire/wireEnums.js +69 -0
- package/build/wire/wirePayload.d.ts +29 -0
- package/build/wire/wirePayload.js +138 -0
- package/build/wire/withdrawalPayload.d.ts +27 -0
- package/build/wire/withdrawalPayload.js +179 -0
- package/expo-module.config.json +14 -0
- package/ios/DaaRegistrationExceptions.swift +58 -0
- package/ios/DaaRegistrationModule.swift +143 -0
- package/ios/DaaScaExceptions.swift +96 -0
- package/ios/DaaScaModule.swift +125 -0
- package/ios/DaaSecureKeyExceptions.swift +77 -0
- package/ios/DaaSecureKeyModule.swift +162 -0
- package/ios/InstallationIdentityStore.swift +126 -0
- package/ios/UnpaddedBase64URL.swift +42 -0
- package/package.json +114 -4
- package/src/DaaClient.ts +171 -0
- package/src/api/AccountLimitsClient.ts +146 -0
- package/src/api/AccountsClient.ts +305 -0
- package/src/api/AchFiatAccountsClient.ts +147 -0
- package/src/api/AuthClient.ts +331 -0
- package/src/api/DaaUserClient.ts +270 -0
- package/src/api/DepositAddressesClient.ts +239 -0
- package/src/api/DepositsClient.ts +208 -0
- package/src/api/FiatAccountsClient.ts +50 -0
- package/src/api/TransactionsClient.ts +137 -0
- package/src/api/TransfersClient.ts +361 -0
- package/src/api/WireFiatAccountsClient.ts +172 -0
- package/src/api/WithdrawalsClient.ts +339 -0
- package/src/api/loginFailure.ts +75 -0
- package/src/api/pagination.ts +63 -0
- package/src/api/queryParameters.ts +82 -0
- package/src/api/resourceRequest.ts +135 -0
- package/src/api/signedResource.ts +267 -0
- package/src/auth/RegistrationFlowKey.ts +274 -0
- package/src/auth/daaRegistrationNative.ts +236 -0
- package/src/auth/deviceAuthorization.ts +302 -0
- package/src/auth/ownerGrant.ts +102 -0
- package/src/auth/prepareReceipt.ts +522 -0
- package/src/auth/registrationAuthorization.ts +306 -0
- package/src/auth/registrationCodeVerifier.ts +76 -0
- package/src/config.ts +156 -0
- package/src/crypto/base64url.ts +88 -0
- package/src/crypto/bytes.ts +30 -0
- package/src/crypto/es256Jws.ts +240 -0
- package/src/crypto/jwkThumbprint.ts +65 -0
- package/src/crypto/random.ts +113 -0
- package/src/crypto/serialization.ts +42 -0
- package/src/crypto/sha256.ts +105 -0
- package/src/errors.ts +319 -0
- package/src/index.ts +223 -0
- package/src/models/Account.ts +264 -0
- package/src/models/AccountLimitsUsage.ts +192 -0
- package/src/models/Ach.ts +269 -0
- package/src/models/AddressObject.ts +169 -0
- package/src/models/BusinessPii.ts +154 -0
- package/src/models/CreateAccountRequest.ts +109 -0
- package/src/models/CreateTransferRequest.ts +114 -0
- package/src/models/CreateWithdrawalRequest.ts +120 -0
- package/src/models/DaaUserContext.ts +172 -0
- package/src/models/Deposit.ts +307 -0
- package/src/models/DepositSummary.ts +142 -0
- package/src/models/FiatAccount.ts +195 -0
- package/src/models/GenerateAddressRequest.ts +101 -0
- package/src/models/Money.ts +91 -0
- package/src/models/Page.ts +48 -0
- package/src/models/PendingDeviceRegistration.ts +197 -0
- package/src/models/PreparedSocialLogin.ts +287 -0
- package/src/models/Transaction.ts +247 -0
- package/src/models/Transfer.ts +459 -0
- package/src/models/Wire.ts +405 -0
- package/src/models/Withdrawal.ts +283 -0
- package/src/models/redaction.ts +22 -0
- package/src/sca/ScaClient.ts +289 -0
- package/src/securekey/InMemorySecureKey.ts +138 -0
- package/src/securekey/NativeSecureKey.ts +179 -0
- package/src/securekey/NativeSecureKeyBridge.ts +109 -0
- package/src/securekey/SecureKey.ts +149 -0
- package/src/securekey/alias.ts +204 -0
- package/src/securekey/ownerAuthKeyResolver.ts +96 -0
- package/src/securekey/resolveNativeBridge.ts +185 -0
- package/src/testing.ts +32 -0
- package/src/transport/DaaTransport.ts +42 -0
- package/src/transport/headers.ts +46 -0
- package/src/validation/requestBody.ts +60 -0
- package/src/validation/uuid.ts +31 -0
- package/src/wire/accountLimitsUsagePayload.ts +182 -0
- package/src/wire/accountPayload.ts +108 -0
- package/src/wire/achPayload.ts +98 -0
- package/src/wire/addressObjectPayload.ts +64 -0
- package/src/wire/daaStatusCodes.ts +69 -0
- package/src/wire/dataEnvelope.ts +80 -0
- package/src/wire/depositPayload.ts +186 -0
- package/src/wire/deviceContextPayload.ts +58 -0
- package/src/wire/deviceRegistrationResultPayload.ts +153 -0
- package/src/wire/errorEnvelope.ts +87 -0
- package/src/wire/fiatAccountPayload.ts +112 -0
- package/src/wire/instant.ts +93 -0
- package/src/wire/jsonNumber.ts +33 -0
- package/src/wire/moneyPayload.ts +55 -0
- package/src/wire/paginationLinks.ts +204 -0
- package/src/wire/payload.ts +146 -0
- package/src/wire/pendingRegistrationPayload.ts +75 -0
- package/src/wire/socialLoginRequestPayload.ts +89 -0
- package/src/wire/transactionPayload.ts +145 -0
- package/src/wire/transferPayload.ts +249 -0
- package/src/wire/wireEnums.ts +74 -0
- package/src/wire/wirePayload.ts +160 -0
- package/src/wire/withdrawalPayload.ts +219 -0
- package/testing.d.ts +19 -0
- package/testing.js +25 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// Copyright (c) 2026, Circle Internet Group, Inc. All rights reserved.
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
//
|
|
5
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
// you may not use this file except in compliance with the License.
|
|
7
|
+
// You may obtain a copy of the License at
|
|
8
|
+
//
|
|
9
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
//
|
|
11
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
// See the License for the specific language governing permissions and
|
|
15
|
+
// limitations under the License.
|
|
16
|
+
|
|
17
|
+
package com.circle.daa.reactnative
|
|
18
|
+
|
|
19
|
+
import android.content.Context
|
|
20
|
+
import java.io.File
|
|
21
|
+
import java.util.UUID
|
|
22
|
+
|
|
23
|
+
// Durable per-install UUID for DaaAuthKeyIdentity.installationId.
|
|
24
|
+
// Native docs: the caller persists the UUID; a new install gets a new UUID.
|
|
25
|
+
// App-private no-backup storage is wiped on uninstall, so a reinstall mints a
|
|
26
|
+
// new UUID and therefore a new Keystore AuthKey.
|
|
27
|
+
|
|
28
|
+
internal object InstallationIdentityStore {
|
|
29
|
+
private const val FILE_NAME = "daa-installation-id"
|
|
30
|
+
private val lock = Any()
|
|
31
|
+
|
|
32
|
+
fun loadOrCreate(context: Context): UUID {
|
|
33
|
+
// One tmp path for all writers. Serialize so a first-run race cannot
|
|
34
|
+
// persist id_B after a caller already returned id_A (two Keystore
|
|
35
|
+
// aliases). iOS gets the same exclusivity from its actor / SecItemAdd.
|
|
36
|
+
synchronized(lock) {
|
|
37
|
+
val dir = context.noBackupFilesDir
|
|
38
|
+
val file = File(dir, FILE_NAME)
|
|
39
|
+
readUuid(file)?.let {
|
|
40
|
+
return it
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
val id = UUID.randomUUID()
|
|
44
|
+
val tmp = File(dir, "$FILE_NAME.tmp")
|
|
45
|
+
tmp.writeText(id.toString().lowercase())
|
|
46
|
+
if (!tmp.renameTo(file)) {
|
|
47
|
+
tmp.delete()
|
|
48
|
+
readUuid(file)?.let {
|
|
49
|
+
return it
|
|
50
|
+
}
|
|
51
|
+
throw ContractViolationException()
|
|
52
|
+
}
|
|
53
|
+
return readUuid(file) ?: id
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Truncated or garbage files are wiped so the next mint is a new UUID.
|
|
58
|
+
// That does NOT uninstall: the previous Keystore key remains under the
|
|
59
|
+
// old alias, still registered with Circle if enrollment happened, never
|
|
60
|
+
// revoked. The SDK silently creates a new AuthKey. This keeps
|
|
61
|
+
// resolveOrCreate usable; it is not equivalent to wiping app data.
|
|
62
|
+
private fun readUuid(file: File): UUID? {
|
|
63
|
+
if (!file.exists()) {
|
|
64
|
+
return null
|
|
65
|
+
}
|
|
66
|
+
val parsed = runCatching { UUID.fromString(file.readText().trim()) }.getOrNull()
|
|
67
|
+
if (parsed == null) {
|
|
68
|
+
file.delete()
|
|
69
|
+
return null
|
|
70
|
+
}
|
|
71
|
+
return parsed
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Copyright (c) 2026, Circle Internet Group, Inc. All rights reserved.
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
//
|
|
5
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
// you may not use this file except in compliance with the License.
|
|
7
|
+
// You may obtain a copy of the License at
|
|
8
|
+
//
|
|
9
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
//
|
|
11
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
// See the License for the specific language governing permissions and
|
|
15
|
+
// limitations under the License.
|
|
16
|
+
|
|
17
|
+
package com.circle.daa.reactnative
|
|
18
|
+
|
|
19
|
+
import android.util.Base64
|
|
20
|
+
|
|
21
|
+
// Shared by DaaSecureKey and DaaRegistration. One canonicalization so a
|
|
22
|
+
// round-trip check on the signing-input decoder cannot drift from encode.
|
|
23
|
+
|
|
24
|
+
internal fun unpaddedBase64Url(bytes: ByteArray): String {
|
|
25
|
+
return Base64.encodeToString(
|
|
26
|
+
bytes,
|
|
27
|
+
Base64.NO_WRAP or Base64.URL_SAFE or Base64.NO_PADDING,
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
internal fun decodeUnpaddedBase64Url(encoded: String): ByteArray {
|
|
32
|
+
if (encoded.length % 4 == 1) {
|
|
33
|
+
throw ContractViolationException()
|
|
34
|
+
}
|
|
35
|
+
val decoded =
|
|
36
|
+
try {
|
|
37
|
+
Base64.decode(encoded, Base64.URL_SAFE or Base64.NO_WRAP or Base64.NO_PADDING)
|
|
38
|
+
} catch (_: IllegalArgumentException) {
|
|
39
|
+
throw ContractViolationException()
|
|
40
|
+
}
|
|
41
|
+
if (unpaddedBase64Url(decoded) != encoded) {
|
|
42
|
+
throw ContractViolationException()
|
|
43
|
+
}
|
|
44
|
+
return decoded
|
|
45
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
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 { AuthClient } from './api/AuthClient';
|
|
19
|
+
import { type DaaUserClient } from './api/DaaUserClient';
|
|
20
|
+
import type { DaaEnvironment, DaaSdkConfiguration, DeviceKeyPolicy } from './config';
|
|
21
|
+
import { type DaaUserContext } from './models/DaaUserContext';
|
|
22
|
+
import type { DaaTransport } from './transport/DaaTransport';
|
|
23
|
+
/**
|
|
24
|
+
* Root DAA client.
|
|
25
|
+
*
|
|
26
|
+
* `auth.prepareSocialLogin` starts the three-call login. Social Session and
|
|
27
|
+
* Device Registration Complete live on the values that returns. `forUser`
|
|
28
|
+
* opens the authenticated operations surface only for an `ACTIVE`
|
|
29
|
+
* `DaaUserContext`.
|
|
30
|
+
*/
|
|
31
|
+
export declare class DaaClient {
|
|
32
|
+
#private;
|
|
33
|
+
constructor(config: DaaSdkConfiguration);
|
|
34
|
+
get appId(): string;
|
|
35
|
+
get environment(): DaaEnvironment;
|
|
36
|
+
get transport(): DaaTransport;
|
|
37
|
+
get keyPolicy(): DeviceKeyPolicy;
|
|
38
|
+
/** Starts one social-login attempt (Prepare). */
|
|
39
|
+
get auth(): AuthClient;
|
|
40
|
+
/**
|
|
41
|
+
* The authenticated operations surface for one user.
|
|
42
|
+
*
|
|
43
|
+
* Opens only for an `ACTIVE` `DaaUserContext` decoded from Device Registration
|
|
44
|
+
* Complete. A fabricated object, a `RECOVERY_PENDING` result, or a missing
|
|
45
|
+
* context fail closed — they are not an Owner-bound credential.
|
|
46
|
+
*
|
|
47
|
+
* The context is carried into the surface rather than only checked at the
|
|
48
|
+
* door. `deviceContext.authKeyId` is the `kid` every signed write's
|
|
49
|
+
* `X-Device-Authorization` announces, and the AuthKey it names is re-resolved
|
|
50
|
+
* by the `{appId, environment}` alias login already used, together with
|
|
51
|
+
* THIS context's own `clientEntityId` — the key itself is
|
|
52
|
+
* enclave-held and is not a field on a decoded server result. Validating the
|
|
53
|
+
* context and then dropping it would leave this surface with no credential
|
|
54
|
+
* to sign with at all.
|
|
55
|
+
*/
|
|
56
|
+
forUser(context: DaaUserContext): DaaUserClient;
|
|
57
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
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 _DaaClient_config, _DaaClient_publicApiOrigin, _DaaClient_auth, _DaaClient_authKeys;
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
exports.DaaClient = void 0;
|
|
33
|
+
const AuthClient_1 = require("./api/AuthClient");
|
|
34
|
+
const DaaUserClient_1 = require("./api/DaaUserClient");
|
|
35
|
+
const config_1 = require("./config");
|
|
36
|
+
const errors_1 = require("./errors");
|
|
37
|
+
const DaaUserContext_1 = require("./models/DaaUserContext");
|
|
38
|
+
const ownerAuthKeyResolver_1 = require("./securekey/ownerAuthKeyResolver");
|
|
39
|
+
const alias_1 = require("./securekey/alias");
|
|
40
|
+
const resolveNativeBridge_1 = require("./securekey/resolveNativeBridge");
|
|
41
|
+
/**
|
|
42
|
+
* Root DAA client.
|
|
43
|
+
*
|
|
44
|
+
* `auth.prepareSocialLogin` starts the three-call login. Social Session and
|
|
45
|
+
* Device Registration Complete live on the values that returns. `forUser`
|
|
46
|
+
* opens the authenticated operations surface only for an `ACTIVE`
|
|
47
|
+
* `DaaUserContext`.
|
|
48
|
+
*/
|
|
49
|
+
class DaaClient {
|
|
50
|
+
constructor(config) {
|
|
51
|
+
_DaaClient_config.set(this, void 0);
|
|
52
|
+
/** The validated `publicApiOrigin`, or `undefined` for the environment's origin. */
|
|
53
|
+
_DaaClient_publicApiOrigin.set(this, void 0);
|
|
54
|
+
_DaaClient_auth.set(this, void 0);
|
|
55
|
+
/**
|
|
56
|
+
* One resolver for the installation AuthKey, shared by login and `forUser`.
|
|
57
|
+
* Takes the Owner's `clientEntityId` per call rather than baking
|
|
58
|
+
* one in, since this `DaaClient` may serve more than one Owner over its
|
|
59
|
+
* lifetime.
|
|
60
|
+
*
|
|
61
|
+
* Held here rather than inside `AuthClient` because both need it and neither
|
|
62
|
+
* may hand it to a consumer: `AuthClient` is reachable as `client.auth`, so an
|
|
63
|
+
* `OwnerAuthKey` returned from a method on it would be a generic signing
|
|
64
|
+
* surface. This field is `#`-private, so it is reachable from `forUser` and
|
|
65
|
+
* from nowhere else.
|
|
66
|
+
*/
|
|
67
|
+
_DaaClient_authKeys.set(this, void 0);
|
|
68
|
+
if (!config.appId) {
|
|
69
|
+
throw new Error('DAA: appId is required');
|
|
70
|
+
}
|
|
71
|
+
if (!config.transport) {
|
|
72
|
+
throw new Error('DAA: transport is required');
|
|
73
|
+
}
|
|
74
|
+
if (!config_1.DAA_ENVIRONMENTS.includes(config.environment)) {
|
|
75
|
+
throw new Error(`DAA: unknown environment "${config.environment}"; expected one of ${config_1.DAA_ENVIRONMENTS.join(', ')}`);
|
|
76
|
+
}
|
|
77
|
+
// The key-namespace limits, checked here rather than first on key
|
|
78
|
+
// resolution: that runs after Social Session, so a bad appId would fail
|
|
79
|
+
// only once the service had bound the end user. After the presence checks,
|
|
80
|
+
// so a missing field is reported first.
|
|
81
|
+
(0, alias_1.assertAppId)(config.appId);
|
|
82
|
+
const publicApiOrigin = (0, config_1.assertPublicApiOrigin)(config.environment, config.publicApiOrigin);
|
|
83
|
+
const keyPolicy = (0, config_1.assertDeviceKeyPolicy)(config.keyPolicy);
|
|
84
|
+
// When DaaSecureKey is present, fail closed if it declares a weaker policy
|
|
85
|
+
// than the configured closed set. Absent (Node / Jest) is not a pass —
|
|
86
|
+
// resolveNativeBridge() still checks on first AuthKey use.
|
|
87
|
+
(0, resolveNativeBridge_1.assertNativeModuleKeyPolicyIfPresent)(keyPolicy);
|
|
88
|
+
__classPrivateFieldSet(this, _DaaClient_config, Object.freeze({ ...config, keyPolicy }), "f");
|
|
89
|
+
__classPrivateFieldSet(this, _DaaClient_publicApiOrigin, publicApiOrigin, "f");
|
|
90
|
+
// Built eagerly, but it resolves nothing until something asks: the Expo
|
|
91
|
+
// DaaSecureKey module is reached on first resolution, so constructing a
|
|
92
|
+
// DaaClient still does not require it.
|
|
93
|
+
__classPrivateFieldSet(this, _DaaClient_authKeys, (0, ownerAuthKeyResolver_1.createOwnerAuthKeyResolver)({ appId: config.appId, environment: config.environment }, null), "f");
|
|
94
|
+
// Constructed eagerly. Prepare needs no AuthKey and no DaaSecureKey. The
|
|
95
|
+
// Expo DaaRegistration module (CSPRNG, flow key, receipt signature
|
|
96
|
+
// verification) is resolved on first prepare, not here — matching
|
|
97
|
+
// randomBytes / randomUuidV4. A host missing that module fails closed at
|
|
98
|
+
// login. Jest injects a fake. AuthKey selection is lazy on Social Session.
|
|
99
|
+
__classPrivateFieldSet(this, _DaaClient_auth, new AuthClient_1.AuthClient({
|
|
100
|
+
transport: config.transport,
|
|
101
|
+
authKeys: __classPrivateFieldGet(this, _DaaClient_authKeys, "f"),
|
|
102
|
+
environment: config.environment,
|
|
103
|
+
}), "f");
|
|
104
|
+
}
|
|
105
|
+
get appId() {
|
|
106
|
+
return __classPrivateFieldGet(this, _DaaClient_config, "f").appId;
|
|
107
|
+
}
|
|
108
|
+
get environment() {
|
|
109
|
+
return __classPrivateFieldGet(this, _DaaClient_config, "f").environment;
|
|
110
|
+
}
|
|
111
|
+
get transport() {
|
|
112
|
+
return __classPrivateFieldGet(this, _DaaClient_config, "f").transport;
|
|
113
|
+
}
|
|
114
|
+
get keyPolicy() {
|
|
115
|
+
return __classPrivateFieldGet(this, _DaaClient_config, "f").keyPolicy;
|
|
116
|
+
}
|
|
117
|
+
/** Starts one social-login attempt (Prepare). */
|
|
118
|
+
get auth() {
|
|
119
|
+
return __classPrivateFieldGet(this, _DaaClient_auth, "f");
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* The authenticated operations surface for one user.
|
|
123
|
+
*
|
|
124
|
+
* Opens only for an `ACTIVE` `DaaUserContext` decoded from Device Registration
|
|
125
|
+
* Complete. A fabricated object, a `RECOVERY_PENDING` result, or a missing
|
|
126
|
+
* context fail closed — they are not an Owner-bound credential.
|
|
127
|
+
*
|
|
128
|
+
* The context is carried into the surface rather than only checked at the
|
|
129
|
+
* door. `deviceContext.authKeyId` is the `kid` every signed write's
|
|
130
|
+
* `X-Device-Authorization` announces, and the AuthKey it names is re-resolved
|
|
131
|
+
* by the `{appId, environment}` alias login already used, together with
|
|
132
|
+
* THIS context's own `clientEntityId` — the key itself is
|
|
133
|
+
* enclave-held and is not a field on a decoded server result. Validating the
|
|
134
|
+
* context and then dropping it would leave this surface with no credential
|
|
135
|
+
* to sign with at all.
|
|
136
|
+
*/
|
|
137
|
+
forUser(context) {
|
|
138
|
+
if (!(0, DaaUserContext_1.isActiveDaaUserContext)(context)) {
|
|
139
|
+
throw (0, errors_1.contractViolation)('forUser requires an ACTIVE DaaUserContext from Device Registration Complete');
|
|
140
|
+
}
|
|
141
|
+
// Bound to this context's clientEntityId now, once, rather than passed
|
|
142
|
+
// through: `DaaUserSigning.resolveAuthKey` is a zero-arg
|
|
143
|
+
// `OwnerAuthKeyResolver` (api/signedResource.ts) because a resource client
|
|
144
|
+
// has no Owner concept of its own — it only ever signs for the user this
|
|
145
|
+
// `forUser` call already validated.
|
|
146
|
+
const clientEntityId = context.clientEntityId;
|
|
147
|
+
return (0, DaaUserClient_1.createDaaUserClient)(__classPrivateFieldGet(this, _DaaClient_config, "f").transport, __classPrivateFieldGet(this, _DaaClient_config, "f").environment, {
|
|
148
|
+
resolveAuthKey: async () => {
|
|
149
|
+
const authKey = await __classPrivateFieldGet(this, _DaaClient_authKeys, "f").call(this, clientEntityId);
|
|
150
|
+
await (0, DaaUserContext_1.assertAuthKeyMatchesContext)(context, authKey);
|
|
151
|
+
return authKey;
|
|
152
|
+
},
|
|
153
|
+
authKeyId: context.deviceContext.authKeyId,
|
|
154
|
+
}, __classPrivateFieldGet(this, _DaaClient_publicApiOrigin, "f"));
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
exports.DaaClient = DaaClient;
|
|
158
|
+
_DaaClient_config = new WeakMap(), _DaaClient_publicApiOrigin = new WeakMap(), _DaaClient_auth = new WeakMap(), _DaaClient_authKeys = new WeakMap();
|
|
@@ -0,0 +1,79 @@
|
|
|
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 { AccountLimitsUsage } from '../models/AccountLimitsUsage';
|
|
19
|
+
import type { DaaTransport } from '../transport/DaaTransport';
|
|
20
|
+
declare const OPERATIONS: readonly ["deposit", "withdrawal", "receive", "send", "send_count", "address_linking", "fiat_linking", "deposit_return_count", "balance_cap"];
|
|
21
|
+
declare const ASSET_TYPES: readonly ["fiat", "crypto"];
|
|
22
|
+
declare const WINDOWS: readonly ["PT24H", "P30D"];
|
|
23
|
+
/** Filters accepted by the account limits/usage read, all optional. */
|
|
24
|
+
export type AccountLimitsUsageQuery = Readonly<{
|
|
25
|
+
operation?: (typeof OPERATIONS)[number];
|
|
26
|
+
assetType?: (typeof ASSET_TYPES)[number];
|
|
27
|
+
/** ISO 8601 rolling-window duration. */
|
|
28
|
+
window?: (typeof WINDOWS)[number];
|
|
29
|
+
}>;
|
|
30
|
+
/**
|
|
31
|
+
* Reads over an account's limits and current usage, as the SDK contract's
|
|
32
|
+
* `AccountLimitsClient`.
|
|
33
|
+
*
|
|
34
|
+
* A dedicated client rather than a method on `AccountsClient`, matching this
|
|
35
|
+
* SDK's pattern: every distinct resource type — accounts, deposits, deposit
|
|
36
|
+
* addresses, transactions, transfers, withdrawals, fiat accounts — gets its
|
|
37
|
+
* own client class rather than being folded into a sibling's. `limitsUsage` is its own resource with its own
|
|
38
|
+
* wire shape, so it gets its own class too.
|
|
39
|
+
*
|
|
40
|
+
* {@link get} is an **ordinary typed read** (the classification for every
|
|
41
|
+
* by-id read in this SDK): it needs no device signature. Neither the public
|
|
42
|
+
* reference nor the Owner-authorization registry names a signed "limits"
|
|
43
|
+
* operation.
|
|
44
|
+
*
|
|
45
|
+
* The API additionally rejects `window=PT24H` combined with
|
|
46
|
+
* `operation=fiat_linking` or `operation=deposit_return_count`. That
|
|
47
|
+
* constraint is not pre-validated here: it is a business rule about which
|
|
48
|
+
* *values* of two independent query parameters may combine, not a structural
|
|
49
|
+
* rule about the request shape, and this SDK's existing cross-field query
|
|
50
|
+
* checks (`pageAfter`/`pageBefore` mutual exclusion on every paged list) are
|
|
51
|
+
* all of the latter kind. Rejecting it locally would mean this SDK
|
|
52
|
+
* hard-codes a business rule that can change on the service side without a
|
|
53
|
+
* client release to match; the service's own `400` is the source of truth.
|
|
54
|
+
*
|
|
55
|
+
* Not constructible by a consumer: exported from `index.ts` as a type only,
|
|
56
|
+
* and the `#transport` field makes the type nominal.
|
|
57
|
+
*/
|
|
58
|
+
export declare class AccountLimitsClient {
|
|
59
|
+
#private;
|
|
60
|
+
/** @internal Constructed only through the internal user-client factory. */
|
|
61
|
+
constructor(transport: DaaTransport);
|
|
62
|
+
/**
|
|
63
|
+
* Read one account's limits and current usage.
|
|
64
|
+
*
|
|
65
|
+
* @param accountId The service-assigned identifier. The public reference
|
|
66
|
+
* types this path parameter `^\d{1,10}$`; anything else is rejected
|
|
67
|
+
* locally rather than sent, because it cannot resolve on the service side.
|
|
68
|
+
* @param query Optional `operation`/`assetType`/`window` filters.
|
|
69
|
+
* @throws DaaError with `detail.kind === 'contract_violation'` for a
|
|
70
|
+
* rejected `accountId` or query, or a response the SDK cannot read, and
|
|
71
|
+
* `detail.kind === 'api'` for a status other than the documented `200`
|
|
72
|
+
* (including the `400` the API returns for `window=PT24H` combined
|
|
73
|
+
* with `operation=fiat_linking`/`deposit_return_count`);
|
|
74
|
+
* `detail.kind === 'transport'` if the consumer's transport throws, with the
|
|
75
|
+
* thrown value as `err.cause`.
|
|
76
|
+
*/
|
|
77
|
+
get(accountId: string, query?: AccountLimitsUsageQuery): Promise<AccountLimitsUsage>;
|
|
78
|
+
}
|
|
79
|
+
export {};
|
|
@@ -0,0 +1,142 @@
|
|
|
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 _AccountLimitsClient_transport;
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
exports.AccountLimitsClient = void 0;
|
|
33
|
+
const errors_1 = require("../errors");
|
|
34
|
+
const accountLimitsUsagePayload_1 = require("../wire/accountLimitsUsagePayload");
|
|
35
|
+
const queryParameters_1 = require("./queryParameters");
|
|
36
|
+
const resourceRequest_1 = require("./resourceRequest");
|
|
37
|
+
/**
|
|
38
|
+
* `GET /v1/accounts/{accountId}/limits/usage` — the public path documented at
|
|
39
|
+
* https://developers.circle.com/api-reference/digital-asset-accounts/all/list-account-limits-usage.
|
|
40
|
+
*
|
|
41
|
+
* The public API reference above is this client's contract.
|
|
42
|
+
*/
|
|
43
|
+
const ACCOUNT_LIMITS_USAGE_PATH_PREFIX = '/v1/accounts/';
|
|
44
|
+
const ACCOUNT_LIMITS_USAGE_PATH_SUFFIX = '/limits/usage';
|
|
45
|
+
/**
|
|
46
|
+
* The public reference's documented pattern for this path parameter:
|
|
47
|
+
* `^\d{1,10}$`. This is stricter than `AccountsClient.get`'s `accountId`
|
|
48
|
+
* guard: account ids are strings in general, but this endpoint's reference
|
|
49
|
+
* constrains the parameter to a numeric shape, so the guard follows the
|
|
50
|
+
* documented contract for *this* endpoint. The same reasoning distinguishes `DepositsClient.get`'s UUID
|
|
51
|
+
* guard from `AccountsClient.get`'s path-segment one.
|
|
52
|
+
*/
|
|
53
|
+
const ACCOUNT_ID_PATTERN = /^\d{1,10}$/;
|
|
54
|
+
const OPERATIONS = Object.freeze([
|
|
55
|
+
'deposit',
|
|
56
|
+
'withdrawal',
|
|
57
|
+
'receive',
|
|
58
|
+
'send',
|
|
59
|
+
'send_count',
|
|
60
|
+
'address_linking',
|
|
61
|
+
'fiat_linking',
|
|
62
|
+
'deposit_return_count',
|
|
63
|
+
'balance_cap',
|
|
64
|
+
]);
|
|
65
|
+
const ASSET_TYPES = Object.freeze(['fiat', 'crypto']);
|
|
66
|
+
const WINDOWS = Object.freeze(['PT24H', 'P30D']);
|
|
67
|
+
/**
|
|
68
|
+
* Reads over an account's limits and current usage, as the SDK contract's
|
|
69
|
+
* `AccountLimitsClient`.
|
|
70
|
+
*
|
|
71
|
+
* A dedicated client rather than a method on `AccountsClient`, matching this
|
|
72
|
+
* SDK's pattern: every distinct resource type — accounts, deposits, deposit
|
|
73
|
+
* addresses, transactions, transfers, withdrawals, fiat accounts — gets its
|
|
74
|
+
* own client class rather than being folded into a sibling's. `limitsUsage` is its own resource with its own
|
|
75
|
+
* wire shape, so it gets its own class too.
|
|
76
|
+
*
|
|
77
|
+
* {@link get} is an **ordinary typed read** (the classification for every
|
|
78
|
+
* by-id read in this SDK): it needs no device signature. Neither the public
|
|
79
|
+
* reference nor the Owner-authorization registry names a signed "limits"
|
|
80
|
+
* operation.
|
|
81
|
+
*
|
|
82
|
+
* The API additionally rejects `window=PT24H` combined with
|
|
83
|
+
* `operation=fiat_linking` or `operation=deposit_return_count`. That
|
|
84
|
+
* constraint is not pre-validated here: it is a business rule about which
|
|
85
|
+
* *values* of two independent query parameters may combine, not a structural
|
|
86
|
+
* rule about the request shape, and this SDK's existing cross-field query
|
|
87
|
+
* checks (`pageAfter`/`pageBefore` mutual exclusion on every paged list) are
|
|
88
|
+
* all of the latter kind. Rejecting it locally would mean this SDK
|
|
89
|
+
* hard-codes a business rule that can change on the service side without a
|
|
90
|
+
* client release to match; the service's own `400` is the source of truth.
|
|
91
|
+
*
|
|
92
|
+
* Not constructible by a consumer: exported from `index.ts` as a type only,
|
|
93
|
+
* and the `#transport` field makes the type nominal.
|
|
94
|
+
*/
|
|
95
|
+
class AccountLimitsClient {
|
|
96
|
+
/** @internal Constructed only through the internal user-client factory. */
|
|
97
|
+
constructor(transport) {
|
|
98
|
+
_AccountLimitsClient_transport.set(this, void 0);
|
|
99
|
+
__classPrivateFieldSet(this, _AccountLimitsClient_transport, transport, "f");
|
|
100
|
+
Object.freeze(this);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Read one account's limits and current usage.
|
|
104
|
+
*
|
|
105
|
+
* @param accountId The service-assigned identifier. The public reference
|
|
106
|
+
* types this path parameter `^\d{1,10}$`; anything else is rejected
|
|
107
|
+
* locally rather than sent, because it cannot resolve on the service side.
|
|
108
|
+
* @param query Optional `operation`/`assetType`/`window` filters.
|
|
109
|
+
* @throws DaaError with `detail.kind === 'contract_violation'` for a
|
|
110
|
+
* rejected `accountId` or query, or a response the SDK cannot read, and
|
|
111
|
+
* `detail.kind === 'api'` for a status other than the documented `200`
|
|
112
|
+
* (including the `400` the API returns for `window=PT24H` combined
|
|
113
|
+
* with `operation=fiat_linking`/`deposit_return_count`);
|
|
114
|
+
* `detail.kind === 'transport'` if the consumer's transport throws, with the
|
|
115
|
+
* thrown value as `err.cause`.
|
|
116
|
+
*/
|
|
117
|
+
async get(accountId, query) {
|
|
118
|
+
if (!ACCOUNT_ID_PATTERN.test(accountId)) {
|
|
119
|
+
throw (0, errors_1.contractViolation)('accountId must match ^\\d{1,10}$');
|
|
120
|
+
}
|
|
121
|
+
return (0, resourceRequest_1.readResource)({
|
|
122
|
+
transport: __classPrivateFieldGet(this, _AccountLimitsClient_transport, "f"),
|
|
123
|
+
path: ACCOUNT_LIMITS_USAGE_PATH_PREFIX + accountId + ACCOUNT_LIMITS_USAGE_PATH_SUFFIX,
|
|
124
|
+
query: accountLimitsUsageQuery(query),
|
|
125
|
+
decode: accountLimitsUsagePayload_1.toAccountLimitsUsage,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
exports.AccountLimitsClient = AccountLimitsClient;
|
|
130
|
+
_AccountLimitsClient_transport = new WeakMap();
|
|
131
|
+
function accountLimitsUsageQuery(query) {
|
|
132
|
+
if (query === undefined)
|
|
133
|
+
return null;
|
|
134
|
+
if (typeof query !== 'object' || query === null || Array.isArray(query)) {
|
|
135
|
+
throw (0, errors_1.contractViolation)('account limits usage query must be an object');
|
|
136
|
+
}
|
|
137
|
+
const parts = [];
|
|
138
|
+
(0, queryParameters_1.appendEnum)(parts, 'operation', query.operation, OPERATIONS);
|
|
139
|
+
(0, queryParameters_1.appendEnum)(parts, 'assetType', query.assetType, ASSET_TYPES);
|
|
140
|
+
(0, queryParameters_1.appendEnum)(parts, 'window', query.window, WINDOWS);
|
|
141
|
+
return parts.length === 0 ? null : parts.join('&');
|
|
142
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
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 { Account } from '../models/Account';
|
|
19
|
+
import type { CreateAccountRequest } from '../models/CreateAccountRequest';
|
|
20
|
+
import type { Page } from '../models/Page';
|
|
21
|
+
import type { DaaTransport } from '../transport/DaaTransport';
|
|
22
|
+
import { type DaaUserSigning } from './signedResource';
|
|
23
|
+
export type AccountListQuery = Readonly<{
|
|
24
|
+
custodyType?: 'omnibus' | 'segregated' | 'self';
|
|
25
|
+
clientEntityId?: string;
|
|
26
|
+
type?: 'first_party' | 'third_party';
|
|
27
|
+
isAttributed?: boolean;
|
|
28
|
+
purpose?: 'custody' | 'payments';
|
|
29
|
+
status?: readonly ('active' | 'pending' | 'rejected' | 'archived')[];
|
|
30
|
+
description?: string;
|
|
31
|
+
currencies?: readonly string[];
|
|
32
|
+
groupId?: string;
|
|
33
|
+
from?: string;
|
|
34
|
+
to?: string;
|
|
35
|
+
pageAfter?: string;
|
|
36
|
+
pageBefore?: string;
|
|
37
|
+
pageSize?: number;
|
|
38
|
+
}>;
|
|
39
|
+
/**
|
|
40
|
+
* Reads over DAA accounts, plus the signed account create, as the SDK
|
|
41
|
+
* contract's `AccountsClient`.
|
|
42
|
+
*
|
|
43
|
+
* {@link list} returns a page whose navigation is derived only from same-origin
|
|
44
|
+
* RFC 8288 links bound to this collection.
|
|
45
|
+
*
|
|
46
|
+
* An account read is an **ordinary typed read**: it needs no device signature.
|
|
47
|
+
* {@link create} is the opposite: it is an Owner-authorized write, so it
|
|
48
|
+
* carries an `X-Device-Authorization` bound to the exact bytes it sends and
|
|
49
|
+
* cannot happen without the registered AuthKey `forUser` supplies.
|
|
50
|
+
*
|
|
51
|
+
* Not constructible by a consumer: exported from `index.ts` as a type only, and
|
|
52
|
+
* the `#transport` field makes the type nominal.
|
|
53
|
+
*/
|
|
54
|
+
export declare class AccountsClient {
|
|
55
|
+
#private;
|
|
56
|
+
/** @internal Constructed only through `createDaaUserClient`. */
|
|
57
|
+
constructor(transport: DaaTransport, publicApiOrigin: string, signing: DaaUserSigning);
|
|
58
|
+
/** List accounts and retain the API's opaque navigation queries unchanged. */
|
|
59
|
+
list(query?: AccountListQuery): Promise<Page<Account>>;
|
|
60
|
+
/**
|
|
61
|
+
* Read one account.
|
|
62
|
+
*
|
|
63
|
+
* @param accountId The service-assigned identifier.
|
|
64
|
+
* @throws DaaError with `detail.kind === 'contract_violation'` for a rejected
|
|
65
|
+
* `accountId` or a response the SDK cannot read, and `detail.kind === 'api'`
|
|
66
|
+
* for a status other than the documented `200`; `detail.kind === 'transport'`
|
|
67
|
+
* if the consumer's transport throws, with the thrown value as `err.cause`.
|
|
68
|
+
*/
|
|
69
|
+
get(accountId: string): Promise<Account>;
|
|
70
|
+
/**
|
|
71
|
+
* Create a self-custody account, authorized by the registered device key.
|
|
72
|
+
*
|
|
73
|
+
* The body is validated, serialized **once**, and that exact byte slice is
|
|
74
|
+
* both hashed into the authorization's `body_sha256` claim and sent as the
|
|
75
|
+
* request entity. Nothing between here and the transport re-serializes it,
|
|
76
|
+
* which is the whole point: a re-encoding that changed so much as a space
|
|
77
|
+
* would produce a signature over bytes the service never receives.
|
|
78
|
+
*
|
|
79
|
+
* Neither the method nor the path is chosen here. `postSignedResource`
|
|
80
|
+
* resolves both from the registry entry for `create_account`, so a signed
|
|
81
|
+
* write cannot be aimed somewhere the operation does not name.
|
|
82
|
+
*
|
|
83
|
+
* @throws DaaError with `detail.kind === 'contract_violation'` for a request
|
|
84
|
+
* the registry schema would reject, for an AuthKey that is not yet
|
|
85
|
+
* registered — the create is refused locally, before anything is signed or
|
|
86
|
+
* sent — for a rejected or replayed authorization (including a key that is
|
|
87
|
+
* no longer active: DAA has no revoked-credential code, so this never
|
|
88
|
+
* throws `device_revoked`), and for a response the SDK cannot read;
|
|
89
|
+
* `detail.kind === 'api'` for a status other than the documented `201`; and
|
|
90
|
+
* `detail.kind === 'transport'` if the consumer's transport throws, with the
|
|
91
|
+
* thrown value as `err.cause` and the request's `idempotencyKey` on the
|
|
92
|
+
* detail.
|
|
93
|
+
*/
|
|
94
|
+
create(request: CreateAccountRequest): Promise<Account>;
|
|
95
|
+
}
|