@circle-fin/daa-react-native-sdk 0.0.0-stage → 0.5.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 +69 -0
- package/LICENSE +176 -0
- package/README.md +691 -2
- package/android/build.gradle +102 -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 +104 -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 +107 -0
- package/android/src/main/java/com/circle/daa/reactnative/DaaSecureKeyModule.kt +318 -0
- package/android/src/main/java/com/circle/daa/reactnative/InstallationIdentityStore.kt +122 -0
- package/android/src/main/java/com/circle/daa/reactnative/UnpaddedBase64Url.kt +45 -0
- package/build/DaaClient.d.ts +237 -0
- package/build/DaaClient.js +442 -0
- package/build/api/AccountLimitsClient.d.ts +79 -0
- package/build/api/AccountLimitsClient.js +142 -0
- package/build/api/AccountsClient.d.ts +98 -0
- package/build/api/AccountsClient.js +279 -0
- package/build/api/AchFiatAccountsClient.d.ts +92 -0
- package/build/api/AchFiatAccountsClient.js +142 -0
- package/build/api/AuthClient.d.ts +95 -0
- package/build/api/AuthClient.js +221 -0
- package/build/api/ContractExecutionsClient.d.ts +114 -0
- package/build/api/ContractExecutionsClient.js +462 -0
- package/build/api/DaaUserClient.d.ts +187 -0
- package/build/api/DaaUserClient.js +312 -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 +121 -0
- package/build/api/TransfersClient.d.ts +107 -0
- package/build/api/TransfersClient.js +324 -0
- package/build/api/WireFiatAccountsClient.d.ts +99 -0
- package/build/api/WireFiatAccountsClient.js +156 -0
- package/build/api/WithdrawalsClient.d.ts +97 -0
- package/build/api/WithdrawalsClient.js +308 -0
- package/build/api/deviceApproval.d.ts +48 -0
- package/build/api/deviceApproval.js +247 -0
- package/build/api/deviceStatus.d.ts +61 -0
- package/build/api/deviceStatus.js +216 -0
- package/build/api/loginFailure.d.ts +51 -0
- package/build/api/loginFailure.js +95 -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 +124 -0
- package/build/api/signedResource.js +267 -0
- package/build/auth/RegistrationFlowKey.d.ts +93 -0
- package/build/auth/RegistrationFlowKey.js +203 -0
- package/build/auth/daaRegistrationNative.d.ts +58 -0
- package/build/auth/daaRegistrationNative.js +158 -0
- package/build/auth/deviceAuthorization.d.ts +87 -0
- package/build/auth/deviceAuthorization.js +295 -0
- package/build/auth/ownerGrant.d.ts +29 -0
- package/build/auth/ownerGrant.js +90 -0
- package/build/auth/registrationAuthorization.d.ts +48 -0
- package/build/auth/registrationAuthorization.js +246 -0
- package/build/auth/registrationCodeVerifier.d.ts +31 -0
- package/build/auth/registrationCodeVerifier.js +75 -0
- package/build/config.d.ts +106 -0
- package/build/config.js +131 -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/jwkThumbprint.d.ts +32 -0
- package/build/crypto/jwkThumbprint.js +49 -0
- package/build/crypto/matchingCode.d.ts +47 -0
- package/build/crypto/matchingCode.js +93 -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 +307 -0
- package/build/errors.js +413 -0
- package/build/index.d.ts +69 -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/ContractExecution.d.ts +197 -0
- package/build/models/ContractExecution.js +130 -0
- package/build/models/CreateAccountRequest.d.ts +74 -0
- package/build/models/CreateAccountRequest.js +19 -0
- package/build/models/CreateContractExecutionRequest.d.ts +81 -0
- package/build/models/CreateContractExecutionRequest.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 +146 -0
- package/build/models/DaaUserContext.js +164 -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/DeviceStatus.d.ts +69 -0
- package/build/models/DeviceStatus.js +19 -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/PendingDeviceApproval.d.ts +121 -0
- package/build/models/PendingDeviceApproval.js +208 -0
- package/build/models/PendingDeviceRegistration.d.ts +229 -0
- package/build/models/PendingDeviceRegistration.js +636 -0
- package/build/models/PreparedContractExecution.d.ts +70 -0
- package/build/models/PreparedContractExecution.js +77 -0
- package/build/models/PreparedSocialLogin.d.ts +148 -0
- package/build/models/PreparedSocialLogin.js +252 -0
- package/build/models/Transaction.d.ts +233 -0
- package/build/models/Transaction.js +182 -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/codeSecrets.d.ts +100 -0
- package/build/models/codeSecrets.js +321 -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 +25 -0
- package/build/securekey/InMemorySecureKey.js +168 -0
- package/build/securekey/NativeSecureKey.d.ts +26 -0
- package/build/securekey/NativeSecureKey.js +355 -0
- package/build/securekey/NativeSecureKeyBridge.d.ts +151 -0
- package/build/securekey/NativeSecureKeyBridge.js +19 -0
- package/build/securekey/SecureKey.d.ts +257 -0
- package/build/securekey/SecureKey.js +19 -0
- package/build/securekey/alias.d.ts +97 -0
- package/build/securekey/alias.js +184 -0
- package/build/securekey/ownerAuthKeyResolver.d.ts +73 -0
- package/build/securekey/ownerAuthKeyResolver.js +78 -0
- package/build/securekey/registration.d.ts +19 -0
- package/build/securekey/registration.js +38 -0
- package/build/securekey/resolveNativeBridge.d.ts +33 -0
- package/build/securekey/resolveNativeBridge.js +201 -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 +41 -0
- package/build/transport/headers.js +81 -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/contractExecutionPayload.d.ts +24 -0
- package/build/wire/contractExecutionPayload.js +130 -0
- package/build/wire/daaStatusCodes.d.ts +81 -0
- package/build/wire/daaStatusCodes.js +86 -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 +35 -0
- package/build/wire/deviceContextPayload.js +59 -0
- package/build/wire/deviceRegistrationResultPayload.d.ts +77 -0
- package/build/wire/deviceRegistrationResultPayload.js +162 -0
- package/build/wire/deviceStatusPayload.d.ts +20 -0
- package/build/wire/deviceStatusPayload.js +66 -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 +94 -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 +48 -0
- package/build/wire/pendingRegistrationPayload.js +72 -0
- package/build/wire/socialLoginRequestPayload.d.ts +26 -0
- package/build/wire/socialLoginRequestPayload.js +55 -0
- package/build/wire/transactionPayload.d.ts +31 -0
- package/build/wire/transactionPayload.js +149 -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 +125 -0
- package/ios/DaaScaExceptions.swift +96 -0
- package/ios/DaaScaModule.swift +125 -0
- package/ios/DaaSecureKeyExceptions.swift +125 -0
- package/ios/DaaSecureKeyModule.swift +306 -0
- package/ios/InstallationIdentityStore.swift +162 -0
- package/ios/UnpaddedBase64URL.swift +42 -0
- package/package.json +114 -4
- package/src/DaaClient.ts +509 -0
- package/src/api/AccountLimitsClient.ts +146 -0
- package/src/api/AccountsClient.ts +308 -0
- package/src/api/AchFiatAccountsClient.ts +147 -0
- package/src/api/AuthClient.ts +266 -0
- package/src/api/ContractExecutionsClient.ts +527 -0
- package/src/api/DaaUserClient.ts +345 -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 +138 -0
- package/src/api/TransfersClient.ts +364 -0
- package/src/api/WireFiatAccountsClient.ts +172 -0
- package/src/api/WithdrawalsClient.ts +342 -0
- package/src/api/deviceApproval.ts +306 -0
- package/src/api/deviceStatus.ts +238 -0
- package/src/api/loginFailure.ts +112 -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 +427 -0
- package/src/auth/RegistrationFlowKey.ts +274 -0
- package/src/auth/daaRegistrationNative.ts +191 -0
- package/src/auth/deviceAuthorization.ts +365 -0
- package/src/auth/ownerGrant.ts +102 -0
- package/src/auth/registrationAuthorization.ts +309 -0
- package/src/auth/registrationCodeVerifier.ts +76 -0
- package/src/config.ts +192 -0
- package/src/crypto/base64url.ts +88 -0
- package/src/crypto/bytes.ts +30 -0
- package/src/crypto/jwkThumbprint.ts +65 -0
- package/src/crypto/matchingCode.ts +100 -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 +576 -0
- package/src/index.ts +258 -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/ContractExecution.ts +250 -0
- package/src/models/CreateAccountRequest.ts +109 -0
- package/src/models/CreateContractExecutionRequest.ts +100 -0
- package/src/models/CreateTransferRequest.ts +114 -0
- package/src/models/CreateWithdrawalRequest.ts +120 -0
- package/src/models/DaaUserContext.ts +228 -0
- package/src/models/Deposit.ts +307 -0
- package/src/models/DepositSummary.ts +142 -0
- package/src/models/DeviceStatus.ts +50 -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/PendingDeviceApproval.ts +229 -0
- package/src/models/PendingDeviceRegistration.ts +791 -0
- package/src/models/PreparedContractExecution.ts +128 -0
- package/src/models/PreparedSocialLogin.ts +297 -0
- package/src/models/Transaction.ts +322 -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/codeSecrets.ts +360 -0
- package/src/models/redaction.ts +22 -0
- package/src/sca/ScaClient.ts +289 -0
- package/src/securekey/InMemorySecureKey.ts +192 -0
- package/src/securekey/NativeSecureKey.ts +388 -0
- package/src/securekey/NativeSecureKeyBridge.ts +189 -0
- package/src/securekey/SecureKey.ts +279 -0
- package/src/securekey/alias.ts +212 -0
- package/src/securekey/ownerAuthKeyResolver.ts +135 -0
- package/src/securekey/registration.ts +40 -0
- package/src/securekey/resolveNativeBridge.ts +343 -0
- package/src/testing.ts +32 -0
- package/src/transport/DaaTransport.ts +42 -0
- package/src/transport/headers.ts +93 -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/contractExecutionPayload.ts +152 -0
- package/src/wire/daaStatusCodes.ts +86 -0
- package/src/wire/dataEnvelope.ts +80 -0
- package/src/wire/depositPayload.ts +186 -0
- package/src/wire/deviceContextPayload.ts +60 -0
- package/src/wire/deviceRegistrationResultPayload.ts +211 -0
- package/src/wire/deviceStatusPayload.ts +68 -0
- package/src/wire/errorEnvelope.ts +87 -0
- package/src/wire/fiatAccountPayload.ts +112 -0
- package/src/wire/instant.ts +96 -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 +118 -0
- package/src/wire/socialLoginRequestPayload.ts +66 -0
- package/src/wire/transactionPayload.ts +181 -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,442 @@
|
|
|
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_instances, _DaaClient_config, _DaaClient_publicApiOrigin, _DaaClient_auth, _DaaClient_authKeys, _DaaClient_ownerKeys, _DaaClient_restores, _DaaClient_restoreOnce, _DaaClient_confirmRegistration;
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
exports.DaaClient = void 0;
|
|
33
|
+
const AuthClient_1 = require("./api/AuthClient");
|
|
34
|
+
const deviceStatus_1 = require("./api/deviceStatus");
|
|
35
|
+
const DaaUserClient_1 = require("./api/DaaUserClient");
|
|
36
|
+
const signedResource_1 = require("./api/signedResource");
|
|
37
|
+
const config_1 = require("./config");
|
|
38
|
+
const errors_1 = require("./errors");
|
|
39
|
+
const DaaUserContext_1 = require("./models/DaaUserContext");
|
|
40
|
+
const ownerAuthKeyResolver_1 = require("./securekey/ownerAuthKeyResolver");
|
|
41
|
+
const alias_1 = require("./securekey/alias");
|
|
42
|
+
const resolveNativeBridge_1 = require("./securekey/resolveNativeBridge");
|
|
43
|
+
const deviceContextPayload_1 = require("./wire/deviceContextPayload");
|
|
44
|
+
const NO_LOCAL_KEY = Object.freeze({ status: 'no_local_key' });
|
|
45
|
+
/**
|
|
46
|
+
* Root DAA client.
|
|
47
|
+
*
|
|
48
|
+
* `auth.prepareSocialLogin` starts the three-call login. Social Session and
|
|
49
|
+
* Device Registration Complete live on the values that returns. `forUser`
|
|
50
|
+
* opens the authenticated operations surface only for an `ACTIVE`
|
|
51
|
+
* `DaaUserContext`.
|
|
52
|
+
*/
|
|
53
|
+
class DaaClient {
|
|
54
|
+
constructor(config) {
|
|
55
|
+
_DaaClient_instances.add(this);
|
|
56
|
+
_DaaClient_config.set(this, void 0);
|
|
57
|
+
/** The validated `publicApiOrigin`, or `undefined` for the environment's origin. */
|
|
58
|
+
_DaaClient_publicApiOrigin.set(this, void 0);
|
|
59
|
+
_DaaClient_auth.set(this, void 0);
|
|
60
|
+
/**
|
|
61
|
+
* One resolver for the installation AuthKey, shared by login and `forUser`.
|
|
62
|
+
* Takes the Owner's `clientEntityId` per call rather than baking
|
|
63
|
+
* one in, since this `DaaClient` may serve more than one Owner over its
|
|
64
|
+
* lifetime.
|
|
65
|
+
*
|
|
66
|
+
* Held here rather than inside `AuthClient` because both need it and neither
|
|
67
|
+
* may hand it to a consumer: `AuthClient` is reachable as `client.auth`, so an
|
|
68
|
+
* `OwnerAuthKey` returned from a method on it would be a generic signing
|
|
69
|
+
* surface. This field is `#`-private, so it is reachable from `forUser` and
|
|
70
|
+
* from nowhere else.
|
|
71
|
+
*/
|
|
72
|
+
_DaaClient_authKeys.set(this, void 0);
|
|
73
|
+
/**
|
|
74
|
+
* The same store as {@link #authKeys}, with the read-only and forget
|
|
75
|
+
* operations session restore needs. `#`-private for the same reason.
|
|
76
|
+
*/
|
|
77
|
+
_DaaClient_ownerKeys.set(this, void 0);
|
|
78
|
+
/**
|
|
79
|
+
* One in-flight restore per `clientEntityId`. Concurrent callers share the
|
|
80
|
+
* promise — one user-authentication prompt, one signed request — and the
|
|
81
|
+
* entry is removed once it settles, so a later call starts afresh.
|
|
82
|
+
*/
|
|
83
|
+
_DaaClient_restores.set(this, new Map());
|
|
84
|
+
if (!config.appId) {
|
|
85
|
+
throw new Error('DAA: appId is required');
|
|
86
|
+
}
|
|
87
|
+
if (!config.transport) {
|
|
88
|
+
throw new Error('DAA: transport is required');
|
|
89
|
+
}
|
|
90
|
+
if (!config_1.DAA_ENVIRONMENTS.includes(config.environment)) {
|
|
91
|
+
throw new Error(`DAA: unknown environment "${config.environment}"; expected one of ${config_1.DAA_ENVIRONMENTS.join(', ')}`);
|
|
92
|
+
}
|
|
93
|
+
// The key-namespace limits, checked here rather than first on key
|
|
94
|
+
// resolution: that runs after Social Session, so a bad appId would fail
|
|
95
|
+
// only once the service had bound the end user. After the presence checks,
|
|
96
|
+
// so a missing field is reported first.
|
|
97
|
+
(0, alias_1.assertAppId)(config.appId);
|
|
98
|
+
const publicApiOrigin = (0, config_1.assertPublicApiOrigin)(config.environment, config.publicApiOrigin);
|
|
99
|
+
const keyPolicy = (0, config_1.assertDeviceKeyPolicy)(config.keyPolicy);
|
|
100
|
+
const addDeviceApproval = (0, config_1.assertAddDeviceApproval)(config.addDeviceApproval);
|
|
101
|
+
// When DaaSecureKey is present, fail closed if it declares a weaker policy
|
|
102
|
+
// than the configured closed set. Absent (Node / Jest) is not a pass —
|
|
103
|
+
// resolveNativeBridge() still checks on first AuthKey use.
|
|
104
|
+
(0, resolveNativeBridge_1.assertNativeModuleKeyPolicyIfPresent)(keyPolicy);
|
|
105
|
+
__classPrivateFieldSet(this, _DaaClient_config, Object.freeze({ ...config, keyPolicy }), "f");
|
|
106
|
+
__classPrivateFieldSet(this, _DaaClient_publicApiOrigin, publicApiOrigin, "f");
|
|
107
|
+
// Built eagerly, but it resolves nothing until something asks: the Expo
|
|
108
|
+
// DaaSecureKey module is reached on first resolution, so constructing a
|
|
109
|
+
// DaaClient still does not require it.
|
|
110
|
+
__classPrivateFieldSet(this, _DaaClient_ownerKeys, (0, ownerAuthKeyResolver_1.createAppOwnerKeys)({ appId: config.appId, environment: config.environment }, null), "f");
|
|
111
|
+
__classPrivateFieldSet(this, _DaaClient_authKeys, __classPrivateFieldGet(this, _DaaClient_ownerKeys, "f").resolveOrCreate, "f");
|
|
112
|
+
// Constructed eagerly. Prepare needs no AuthKey and no DaaSecureKey. The
|
|
113
|
+
// Expo DaaRegistration module (CSPRNG, flow key) is resolved on first
|
|
114
|
+
// prepare, not here — matching randomBytes / randomUuidV4. A host missing
|
|
115
|
+
// that module fails closed at login. Jest injects a fake. AuthKey selection
|
|
116
|
+
// is lazy on Social Session.
|
|
117
|
+
__classPrivateFieldSet(this, _DaaClient_auth, new AuthClient_1.AuthClient({
|
|
118
|
+
transport: config.transport,
|
|
119
|
+
ownerKeys: __classPrivateFieldGet(this, _DaaClient_ownerKeys, "f"),
|
|
120
|
+
addDeviceApproval,
|
|
121
|
+
}), "f");
|
|
122
|
+
}
|
|
123
|
+
get appId() {
|
|
124
|
+
return __classPrivateFieldGet(this, _DaaClient_config, "f").appId;
|
|
125
|
+
}
|
|
126
|
+
get environment() {
|
|
127
|
+
return __classPrivateFieldGet(this, _DaaClient_config, "f").environment;
|
|
128
|
+
}
|
|
129
|
+
get transport() {
|
|
130
|
+
return __classPrivateFieldGet(this, _DaaClient_config, "f").transport;
|
|
131
|
+
}
|
|
132
|
+
get keyPolicy() {
|
|
133
|
+
return __classPrivateFieldGet(this, _DaaClient_config, "f").keyPolicy;
|
|
134
|
+
}
|
|
135
|
+
/** Starts one social-login attempt (Prepare). */
|
|
136
|
+
get auth() {
|
|
137
|
+
return __classPrivateFieldGet(this, _DaaClient_auth, "f");
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* The authenticated operations surface for one user.
|
|
141
|
+
*
|
|
142
|
+
* Opens only for an `ACTIVE` `DaaUserContext` this SDK minted: one decoded
|
|
143
|
+
* from Device Registration Complete, or one returned by {@link restore} after
|
|
144
|
+
* the service confirmed the stored registration. Both are bound to the local
|
|
145
|
+
* AuthKey's thumbprint, which every signed operation re-checks. A fabricated
|
|
146
|
+
* object, a `RECOVERY_PENDING` result, or a missing context fail closed —
|
|
147
|
+
* they are not an Owner-bound credential.
|
|
148
|
+
*
|
|
149
|
+
* The context is carried into the surface rather than only checked at the
|
|
150
|
+
* door. `deviceContext.authKeyId` is the `kid` every signed write's
|
|
151
|
+
* `X-Device-Authorization` announces, and the AuthKey it names is re-resolved
|
|
152
|
+
* by the `{appId, environment}` alias login already used, together with
|
|
153
|
+
* THIS context's own `clientEntityId` — the key itself is
|
|
154
|
+
* enclave-held and is not a field on a decoded server result. Validating the
|
|
155
|
+
* context and then dropping it would leave this surface with no credential
|
|
156
|
+
* to sign with at all.
|
|
157
|
+
*/
|
|
158
|
+
forUser(context) {
|
|
159
|
+
if (!(0, DaaUserContext_1.isActiveDaaUserContext)(context)) {
|
|
160
|
+
throw (0, errors_1.contractViolation)('forUser requires an ACTIVE DaaUserContext from Device Registration Complete');
|
|
161
|
+
}
|
|
162
|
+
// Bound to this context's clientEntityId now, once, rather than passed
|
|
163
|
+
// through: `DaaUserSigning.resolveAuthKey` is a zero-arg
|
|
164
|
+
// `OwnerAuthKeyResolver` (api/signedResource.ts) because a resource client
|
|
165
|
+
// has no Owner concept of its own — it only ever signs for the user this
|
|
166
|
+
// `forUser` call already validated.
|
|
167
|
+
const clientEntityId = context.clientEntityId;
|
|
168
|
+
return (0, DaaUserClient_1.createDaaUserClient)(__classPrivateFieldGet(this, _DaaClient_config, "f").transport, __classPrivateFieldGet(this, _DaaClient_config, "f").environment, {
|
|
169
|
+
resolveAuthKey: async () => {
|
|
170
|
+
const authKey = await __classPrivateFieldGet(this, _DaaClient_authKeys, "f").call(this, clientEntityId);
|
|
171
|
+
await (0, DaaUserContext_1.assertAuthKeyMatchesContext)(context, authKey);
|
|
172
|
+
return authKey;
|
|
173
|
+
},
|
|
174
|
+
authKeyId: context.deviceContext.authKeyId,
|
|
175
|
+
clientEntityId,
|
|
176
|
+
}, __classPrivateFieldGet(this, _DaaClient_publicApiOrigin, "f"));
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Restore a signed-in user after an app restart with the AuthKey this device
|
|
180
|
+
* already registered, instead of a new social login.
|
|
181
|
+
*
|
|
182
|
+
* `clientEntityId` is the value the app stored, keyed by its own user id,
|
|
183
|
+
* when that user last completed login (`DaaUserContext.clientEntityId`). It
|
|
184
|
+
* only selects which local key to look for; it grants nothing by itself — see
|
|
185
|
+
* the `OwnerKeyIdentity` note in `securekey/SecureKey.ts`.
|
|
186
|
+
*
|
|
187
|
+
* Steps:
|
|
188
|
+
*
|
|
189
|
+
* 1. Look up the registered AuthKey and the `authKeyId` recorded when Circle
|
|
190
|
+
* registered it. This never creates a key and never prompts. None found
|
|
191
|
+
* resolves `{ status: 'no_local_key' }`.
|
|
192
|
+
* 2. Sign `GET /v1/accounts/auth/context` (`get_device_context`) with that
|
|
193
|
+
* key, `kid` = the stored `authKeyId`. This is the one user-authentication
|
|
194
|
+
* prompt (biometrics or device credential).
|
|
195
|
+
* 3. Require the returned `authKeyId` and `ownerBindingId` to equal the
|
|
196
|
+
* stored ones, then return an `ACTIVE` context bound to the key, for
|
|
197
|
+
* {@link forUser}.
|
|
198
|
+
*
|
|
199
|
+
* Call it while the app is in the foreground: iOS cannot show the
|
|
200
|
+
* authentication prompt during a background launch.
|
|
201
|
+
*
|
|
202
|
+
* Concurrent calls for the same `clientEntityId` share one restore.
|
|
203
|
+
*
|
|
204
|
+
* On failure this deletes nothing and starts no login. An application must
|
|
205
|
+
* not do either automatically: keep the key, report the error, and let the
|
|
206
|
+
* user decide (retry, or sign in again). A throw is never "no key" — that is
|
|
207
|
+
* only ever the `no_local_key` result. In particular a native failure while
|
|
208
|
+
* reading the key (for example its local protection metadata is
|
|
209
|
+
* unreadable) throws through the usual native error mapping; it is not
|
|
210
|
+
* turned into `no_local_key`, so it must not start enrollment either.
|
|
211
|
+
*
|
|
212
|
+
* `clientEntityId` must be the lowercase UUID exactly as
|
|
213
|
+
* `DaaUserContext.clientEntityId` returned it. The key slot is derived from
|
|
214
|
+
* those exact characters, so an uppercase copy (for example after a round
|
|
215
|
+
* trip through Swift's `UUID.uuidString`) would find no key; it is rejected
|
|
216
|
+
* instead of being reported as `no_local_key`.
|
|
217
|
+
*
|
|
218
|
+
* @throws DaaError with `detail.kind === 'contract_violation'` for a
|
|
219
|
+
* `clientEntityId` that is not a lowercase UUID, for a returned `authKeyId`
|
|
220
|
+
* or `ownerBindingId` that does not match the stored one, for a key
|
|
221
|
+
* forgotten while the restore was reading it, for a response the SDK
|
|
222
|
+
* cannot read, and when the service rejects the device
|
|
223
|
+
* authorization (the credential is no longer accepted — the same mapping
|
|
224
|
+
* as every signed write; on a revoked or unknown AuthKey the service
|
|
225
|
+
* answers `403` with DAA status `420036`). The application's response is
|
|
226
|
+
* the same for all of them: keep the key and offer sign-in. One exception:
|
|
227
|
+
* on iOS a prompt the system or the app interrupted also arrives as
|
|
228
|
+
* `contract_violation` today, so retry `restore` in the foreground first
|
|
229
|
+
* if the app left it during the prompt (see the README);
|
|
230
|
+
* `user_cancelled` when the user dismisses the authentication prompt:
|
|
231
|
+
* nothing was sent and the key is untouched, so calling `restore` again
|
|
232
|
+
* prompts again; `local_user_authentication_required` when user
|
|
233
|
+
* authentication failed or is unavailable; `clock_skew` when the service
|
|
234
|
+
* rejected the authorization because the device clock is off, the same as
|
|
235
|
+
* `refreshContext`; `api` for any other status besides `200`; `transport` if
|
|
236
|
+
* the consumer's transport throws, with the thrown value as `err.cause`.
|
|
237
|
+
*/
|
|
238
|
+
async restore(args) {
|
|
239
|
+
const clientEntityId = requireClientEntityId(args);
|
|
240
|
+
let inFlight = __classPrivateFieldGet(this, _DaaClient_restores, "f").get(clientEntityId);
|
|
241
|
+
if (inFlight === undefined) {
|
|
242
|
+
inFlight = __classPrivateFieldGet(this, _DaaClient_instances, "m", _DaaClient_restoreOnce).call(this, clientEntityId).finally(() => {
|
|
243
|
+
__classPrivateFieldGet(this, _DaaClient_restores, "f").delete(clientEntityId);
|
|
244
|
+
});
|
|
245
|
+
__classPrivateFieldGet(this, _DaaClient_restores, "f").set(clientEntityId, inFlight);
|
|
246
|
+
}
|
|
247
|
+
return inFlight;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Delete this device's AuthKey for `clientEntityId`, and its local
|
|
251
|
+
* registration record.
|
|
252
|
+
*
|
|
253
|
+
* Call it only on an explicit user action, such as "remove this device",
|
|
254
|
+
* confirming the removal of a key Circle has revoked, or confirming that the
|
|
255
|
+
* user starts over after this new device was declined (status `denied` from
|
|
256
|
+
* {@link getDeviceStatus}, or a registration refused with `device_denied`) —
|
|
257
|
+
* never as an
|
|
258
|
+
* automatic reaction to a failed {@link restore}, a rejected write, or any
|
|
259
|
+
* other status or error. The SDK never deletes the key by itself.
|
|
260
|
+
*
|
|
261
|
+
* It is local only and does NOT revoke the key with Circle, which keeps the
|
|
262
|
+
* registered public key. It cannot be undone: the next login on this device registers a new
|
|
263
|
+
* AuthKey. Succeeds when no key exists.
|
|
264
|
+
*
|
|
265
|
+
* Contexts and `DaaUserClient`s already handed out are not invalidated by
|
|
266
|
+
* this call. Operations that need a new signature fail once the key is gone,
|
|
267
|
+
* but an authorization signed before the delete stays valid, because Circle
|
|
268
|
+
* still accepts the key: a contract execution prepared earlier can still be
|
|
269
|
+
* sent with `contractExecutions.submit`. Close those clients and drop any
|
|
270
|
+
* prepared value you do not intend to send as part of the same action.
|
|
271
|
+
*
|
|
272
|
+
* Do not call it while a login or a {@link restore} for the same
|
|
273
|
+
* `clientEntityId` is still in flight; finish or abandon that first. A
|
|
274
|
+
* restore that is reading the key when the delete starts fails closed with
|
|
275
|
+
* `contract_violation`. A login ceremony that already holds the key is not
|
|
276
|
+
* cancelled: whether its key survives depends on the order the native SDK
|
|
277
|
+
* runs the two calls in, so the outcome is not defined.
|
|
278
|
+
*
|
|
279
|
+
* @throws DaaError with `detail.kind === 'contract_violation'` for a
|
|
280
|
+
* `clientEntityId` that is not a lowercase UUID, and for a native failure
|
|
281
|
+
* that has no more specific mapping. Native failures go through the same
|
|
282
|
+
* mapping as every other AuthKey operation, so the delete can also report
|
|
283
|
+
* `local_user_authentication_required` or `device_not_initialized` if the
|
|
284
|
+
* platform raises one of those.
|
|
285
|
+
*/
|
|
286
|
+
async forgetLocalKey(args) {
|
|
287
|
+
const clientEntityId = requireClientEntityId(args);
|
|
288
|
+
await __classPrivateFieldGet(this, _DaaClient_ownerKeys, "f").forget(clientEntityId);
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* The add-a-device status of this device's new AuthKey:
|
|
292
|
+
* `GET /v1/accounts/auth/devices/{authKeyId}`, with the `authKeyId` DAA
|
|
293
|
+
* returned when it added the key as waiting. One read, for example when the app is reopened
|
|
294
|
+
* while a request was waiting (the app must have saved `authKeyId`); use
|
|
295
|
+
* {@link watchDeviceStatus} to wait for the outcome.
|
|
296
|
+
*
|
|
297
|
+
* `denied` means the user declined this device on another one. The key
|
|
298
|
+
* can't ask again: after the user confirms, the app may delete it with
|
|
299
|
+
* {@link forgetLocalKey} and sign in again with a new key. The SDK never
|
|
300
|
+
* deletes it by itself.
|
|
301
|
+
*
|
|
302
|
+
* `authKeyId` may be in either case.
|
|
303
|
+
*
|
|
304
|
+
* @throws DaaError with `detail.kind === 'contract_violation'` for an
|
|
305
|
+
* `authKeyId` that is not a UUID string and for a response the SDK cannot read;
|
|
306
|
+
* `transport` (retryable) when the transport throws; `api` for any status
|
|
307
|
+
* but `200`, including `404` when DAA doesn't know the key.
|
|
308
|
+
*/
|
|
309
|
+
async getDeviceStatus(args) {
|
|
310
|
+
return await (0, deviceStatus_1.readDeviceStatus)(withTransportFailure(__classPrivateFieldGet(this, _DaaClient_config, "f").transport), requireAuthKeyId(args));
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Wait for the add-a-device outcome: read {@link getDeviceStatus} until it is
|
|
314
|
+
* no longer `pending_approval` or `pending_activation` (so `active`,
|
|
315
|
+
* `denied`, `expired`, `cancelled`, or `unrecognized`), and resolve with it.
|
|
316
|
+
*
|
|
317
|
+
* Reads every 5 s while `pending_approval`, and during the cool-down
|
|
318
|
+
* (`pending_activation`) at `readyAt` or every 30 s, whichever is sooner.
|
|
319
|
+
* DAA reports `expired` once `expiresAt` passes on its clock, so this
|
|
320
|
+
* device's clock never ends the watch. After a retryable failure the wait
|
|
321
|
+
* doubles, up to 30 s, with a random part so that watches that failed
|
|
322
|
+
* together don't retry together. `onStatus` gets the first status and every
|
|
323
|
+
* change; if it throws, the watch rejects with that error. Aborting `signal`
|
|
324
|
+
* stops the watch at once, even during a read, and rejects with the
|
|
325
|
+
* signal's reason; a late response is ignored.
|
|
326
|
+
*
|
|
327
|
+
* Every call runs its own loop. Run one watch per `authKeyId` and abort it
|
|
328
|
+
* when the screen that started it goes away: each extra watch is another
|
|
329
|
+
* read every 5 s against the partner's rate limit for this route.
|
|
330
|
+
*
|
|
331
|
+
* @throws the same errors as {@link getDeviceStatus}, and
|
|
332
|
+
* `contract_violation` for an `onStatus` that is not a function or a
|
|
333
|
+
* `signal` that is not an `AbortSignal`, before anything is sent.
|
|
334
|
+
* Ones marked `retryable` (`transport`, or `api` with `429`/`5xx`) are
|
|
335
|
+
* retried, and the watch rejects with the last one after 10 in a row; any
|
|
336
|
+
* other, such as a transport's own `DaaError` with `retryable: false`,
|
|
337
|
+
* rejects at once.
|
|
338
|
+
*/
|
|
339
|
+
async watchDeviceStatus(args) {
|
|
340
|
+
return await (0, deviceStatus_1.watchDeviceStatus)(withTransportFailure(__classPrivateFieldGet(this, _DaaClient_config, "f").transport), requireWatchArgs(args));
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
exports.DaaClient = DaaClient;
|
|
344
|
+
_DaaClient_config = new WeakMap(), _DaaClient_publicApiOrigin = new WeakMap(), _DaaClient_auth = new WeakMap(), _DaaClient_authKeys = new WeakMap(), _DaaClient_ownerKeys = new WeakMap(), _DaaClient_restores = new WeakMap(), _DaaClient_instances = new WeakSet(), _DaaClient_restoreOnce = async function _DaaClient_restoreOnce(clientEntityId) {
|
|
345
|
+
const registered = await __classPrivateFieldGet(this, _DaaClient_ownerKeys, "f").resolveExisting(clientEntityId);
|
|
346
|
+
if (registered === null) {
|
|
347
|
+
return NO_LOCAL_KEY;
|
|
348
|
+
}
|
|
349
|
+
// Read before any prompt: the thumbprint comes from the public key.
|
|
350
|
+
const authKeyThumbprint = await registered.authKey.thumbprint();
|
|
351
|
+
const deviceContext = await __classPrivateFieldGet(this, _DaaClient_instances, "m", _DaaClient_confirmRegistration).call(this, registered);
|
|
352
|
+
return Object.freeze({
|
|
353
|
+
status: 'ACTIVE',
|
|
354
|
+
context: (0, DaaUserContext_1.restoreDaaUserContext)(clientEntityId, deviceContext, authKeyThumbprint),
|
|
355
|
+
});
|
|
356
|
+
}, _DaaClient_confirmRegistration =
|
|
357
|
+
/**
|
|
358
|
+
* Ask the service for the device context with a registered-device
|
|
359
|
+
* authorization signed by the stored key, through the same
|
|
360
|
+
* `getSignedResource` path as `DaaUserClient.refreshContext`, and require
|
|
361
|
+
* that it names the same `authKeyId` and `ownerBindingId` that were stored
|
|
362
|
+
* when the key was acknowledged.
|
|
363
|
+
*
|
|
364
|
+
* A different `ownerBindingId` fails closed rather than being adopted: the
|
|
365
|
+
* stored record and the service disagree about which Owner binding this key
|
|
366
|
+
* belongs to, and the SDK has no basis to pick one. Re-registration through
|
|
367
|
+
* login is the path that legitimately records new identifiers.
|
|
368
|
+
*/
|
|
369
|
+
async function _DaaClient_confirmRegistration(registered) {
|
|
370
|
+
const deviceContext = await (0, signedResource_1.getSignedResource)({
|
|
371
|
+
transport: withTransportFailure(__classPrivateFieldGet(this, _DaaClient_config, "f").transport),
|
|
372
|
+
operation: 'get_device_context',
|
|
373
|
+
authKey: registered.authKey,
|
|
374
|
+
authKeyId: registered.authKeyId,
|
|
375
|
+
expectedStatus: 200,
|
|
376
|
+
decode: deviceContextPayload_1.toDeviceContext,
|
|
377
|
+
});
|
|
378
|
+
if (deviceContext.authKeyId !== registered.authKeyId) {
|
|
379
|
+
throw (0, errors_1.contractViolation)('the restored device context names a different AuthKey');
|
|
380
|
+
}
|
|
381
|
+
if (deviceContext.ownerBindingId !== registered.ownerBindingId) {
|
|
382
|
+
throw (0, errors_1.contractViolation)('the restored device context names a different Owner binding');
|
|
383
|
+
}
|
|
384
|
+
return deviceContext;
|
|
385
|
+
};
|
|
386
|
+
function requireClientEntityId(args) {
|
|
387
|
+
const clientEntityId = (0, config_1.isRecord)(args) ? args['clientEntityId'] : undefined;
|
|
388
|
+
if (typeof clientEntityId !== 'string') {
|
|
389
|
+
throw (0, errors_1.contractViolation)('clientEntityId must be a UUID');
|
|
390
|
+
}
|
|
391
|
+
// The same rule enrollment applies when it derives the key alias (lowercase
|
|
392
|
+
// UUID), checked up front so a bad value never reaches the key store.
|
|
393
|
+
(0, alias_1.assertClientEntityId)(clientEntityId);
|
|
394
|
+
return clientEntityId;
|
|
395
|
+
}
|
|
396
|
+
/** The `authKeyId` of a status call; the UUID check itself is `readDeviceStatus`'s. */
|
|
397
|
+
function requireAuthKeyId(args) {
|
|
398
|
+
const authKeyId = (0, config_1.isRecord)(args) ? args['authKeyId'] : undefined;
|
|
399
|
+
if (typeof authKeyId !== 'string') {
|
|
400
|
+
throw (0, errors_1.contractViolation)('authKeyId must be a UUID');
|
|
401
|
+
}
|
|
402
|
+
return authKeyId;
|
|
403
|
+
}
|
|
404
|
+
/** `watchDeviceStatus`'s arguments, checked before the first read. */
|
|
405
|
+
function requireWatchArgs(args) {
|
|
406
|
+
const authKeyId = requireAuthKeyId(args);
|
|
407
|
+
const { onStatus, signal } = args;
|
|
408
|
+
if (onStatus !== undefined && typeof onStatus !== 'function') {
|
|
409
|
+
throw (0, errors_1.contractViolation)('onStatus must be a function');
|
|
410
|
+
}
|
|
411
|
+
// Everything the watch uses, so a partial object fails here, before the
|
|
412
|
+
// first read, not in a cleanup that would leave the watch never settling.
|
|
413
|
+
if (signal !== undefined &&
|
|
414
|
+
!((0, config_1.isRecord)(signal) &&
|
|
415
|
+
typeof signal['aborted'] === 'boolean' &&
|
|
416
|
+
typeof signal['addEventListener'] === 'function' &&
|
|
417
|
+
typeof signal['removeEventListener'] === 'function')) {
|
|
418
|
+
throw (0, errors_1.contractViolation)('signal must be an AbortSignal');
|
|
419
|
+
}
|
|
420
|
+
return {
|
|
421
|
+
authKeyId,
|
|
422
|
+
...(onStatus === undefined ? {} : { onStatus: onStatus }),
|
|
423
|
+
...(signal === undefined ? {} : { signal: signal }),
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* The consumer's transport, with a throw reported as the spec's `transport`
|
|
428
|
+
* error through the same `asTransportFailure` every `DaaUserClient` operation
|
|
429
|
+
* uses.
|
|
430
|
+
*/
|
|
431
|
+
function withTransportFailure(transport) {
|
|
432
|
+
return Object.freeze({
|
|
433
|
+
send: async (request) => {
|
|
434
|
+
try {
|
|
435
|
+
return await transport.send(request);
|
|
436
|
+
}
|
|
437
|
+
catch (err) {
|
|
438
|
+
throw (0, DaaUserClient_1.asTransportFailure)(err, request);
|
|
439
|
+
}
|
|
440
|
+
},
|
|
441
|
+
});
|
|
442
|
+
}
|
|
@@ -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
|
+
}
|