@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,59 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.toDeviceContext = toDeviceContext;
|
|
21
|
+
const uuid_1 = require("../validation/uuid");
|
|
22
|
+
const instant_1 = require("./instant");
|
|
23
|
+
const payload_1 = require("./payload");
|
|
24
|
+
function requiredUuidField(payload, name) {
|
|
25
|
+
const value = (0, payload_1.requiredString)(payload, name);
|
|
26
|
+
if (!(0, uuid_1.isUuid)(value)) {
|
|
27
|
+
throw new payload_1.MalformedPayloadError(name);
|
|
28
|
+
}
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Decode the wire `DeviceContext`: the shape `get_device_context`
|
|
33
|
+
* (`GET /v1/accounts/auth/context`, `DaaUserClient.refreshContext`) returns,
|
|
34
|
+
* and the shape Device Registration Complete's `KeyCredential` is renamed to
|
|
35
|
+
* (`wire/deviceRegistrationResultPayload.ts`).
|
|
36
|
+
*
|
|
37
|
+
* One decoder for both, rather than two copies: DAA builds the
|
|
38
|
+
* `KeyCredential` from the same `DeviceContext`, so a divergence between "the
|
|
39
|
+
* shape Complete returns" and "the shape refresh returns" would be a service
|
|
40
|
+
* defect, not something two independent decoders should each get to
|
|
41
|
+
* interpret.
|
|
42
|
+
*
|
|
43
|
+
* `DeviceContext.resolvedAt` is one of the timestamps the service sends in its
|
|
44
|
+
* default number form, the same as `PreparedSocialLogin.expiresAt`, so the
|
|
45
|
+
* epoch-millisecond form is accepted here. See `wire/instant.ts`.
|
|
46
|
+
*/
|
|
47
|
+
function toDeviceContext(value) {
|
|
48
|
+
const payload = (0, payload_1.asObject)(value, 'deviceContext');
|
|
49
|
+
const status = (0, payload_1.requiredString)(payload, 'deviceCredentialStatus');
|
|
50
|
+
if (status !== 'active') {
|
|
51
|
+
throw new payload_1.MalformedPayloadError('deviceCredentialStatus');
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
deviceCredentialStatus: 'active',
|
|
55
|
+
ownerBindingId: requiredUuidField(payload, 'ownerBindingId'),
|
|
56
|
+
authKeyId: requiredUuidField(payload, 'authKeyId'),
|
|
57
|
+
resolvedAt: (0, instant_1.requiredDateTime)(payload, 'resolvedAt'),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
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 DeviceRegistrationResult } from '../models/DaaUserContext';
|
|
19
|
+
/**
|
|
20
|
+
* A `pending_approval` registration as DAA sends it. `PendingDeviceRegistration`
|
|
21
|
+
* adds the local code secret and AuthKey thumbprint to make the public
|
|
22
|
+
* `PendingDeviceApproval`.
|
|
23
|
+
*/
|
|
24
|
+
export type PendingApprovalPayload = Readonly<{
|
|
25
|
+
status: 'PENDING_APPROVAL';
|
|
26
|
+
requestId: string;
|
|
27
|
+
authKeyId: string;
|
|
28
|
+
expiresAt: string;
|
|
29
|
+
codeNonce: string;
|
|
30
|
+
/** The request's stored seal, or `null` from a DAA that doesn't send it. */
|
|
31
|
+
codeSeal: string | null;
|
|
32
|
+
}>;
|
|
33
|
+
/**
|
|
34
|
+
* A `pending_activation` registration as DAA sends it: a device approved from
|
|
35
|
+
* another device, signing in again during the account's cool-down.
|
|
36
|
+
* `PendingDeviceRegistration` acknowledges the key with `ownerBindingId`,
|
|
37
|
+
* which the public result leaves out.
|
|
38
|
+
*/
|
|
39
|
+
export type PendingActivationPayload = Readonly<{
|
|
40
|
+
status: 'PENDING_ACTIVATION';
|
|
41
|
+
authKeyId: string;
|
|
42
|
+
ownerBindingId: string;
|
|
43
|
+
readyAt: string;
|
|
44
|
+
}>;
|
|
45
|
+
/**
|
|
46
|
+
* Complete's decoded payload, before the pending variants get their local state.
|
|
47
|
+
* `/v1/accounts/auth/keys` never returns `RECOVERY_PENDING`, so this decoder
|
|
48
|
+
* never produces it, although the public `DeviceRegistrationResult` keeps it.
|
|
49
|
+
*/
|
|
50
|
+
export type DecodedDeviceRegistration = Extract<DeviceRegistrationResult, {
|
|
51
|
+
status: 'ACTIVE';
|
|
52
|
+
}> | PendingApprovalPayload | PendingActivationPayload;
|
|
53
|
+
/**
|
|
54
|
+
* Map Complete's `data` payload: the `KeyCredential` that
|
|
55
|
+
* `POST /v1/accounts/auth/keys` returns for `"type": "deviceKey"`.
|
|
56
|
+
*
|
|
57
|
+
* DAA builds a `KeyCredential` from the same `DeviceContext` that
|
|
58
|
+
* `get_device_context` returns, with names that fit both key types. For a
|
|
59
|
+
* device key, `credentialStatus` is the `deviceCredentialStatus` and
|
|
60
|
+
* `credentialId` is the `authKeyId` (the `kid` that later
|
|
61
|
+
* `X-Device-Authorization` requests sign with). Every other member keeps its
|
|
62
|
+
* name. So the payload is checked for `type: "deviceKey"`, those two members
|
|
63
|
+
* are renamed, and the result is decoded as a `DeviceContext`:
|
|
64
|
+
*
|
|
65
|
+
* - `active` is `ACTIVE` (`toDeviceContext`), a first device or a key the
|
|
66
|
+
* account already holds;
|
|
67
|
+
* - `pending_approval` is a new device on an account that already has one (see
|
|
68
|
+
* `toPendingApproval`);
|
|
69
|
+
* - `pending_activation` is an approved device signing in again during its
|
|
70
|
+
* cool-down (see `toPendingActivation`);
|
|
71
|
+
* - any other status, or a missing one, fails closed, as does a malformed
|
|
72
|
+
* UUID or timestamp.
|
|
73
|
+
*
|
|
74
|
+
* Any other `type` is refused. Extra members are otherwise ignored.
|
|
75
|
+
* `clientEntityId` comes from Social Session, not this payload.
|
|
76
|
+
*/
|
|
77
|
+
export declare function toDeviceRegistrationResult(value: unknown, sessionClientEntityId: string): DecodedDeviceRegistration;
|
|
@@ -0,0 +1,162 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.toDeviceRegistrationResult = toDeviceRegistrationResult;
|
|
21
|
+
const DaaUserContext_1 = require("../models/DaaUserContext");
|
|
22
|
+
const matchingCode_1 = require("../crypto/matchingCode");
|
|
23
|
+
const uuid_1 = require("../validation/uuid");
|
|
24
|
+
const deviceContextPayload_1 = require("./deviceContextPayload");
|
|
25
|
+
const instant_1 = require("./instant");
|
|
26
|
+
const payload_1 = require("./payload");
|
|
27
|
+
/** The only `type` a device key registration may echo. */
|
|
28
|
+
const DEVICE_KEY_TYPE = 'deviceKey';
|
|
29
|
+
/**
|
|
30
|
+
* The `KeyCredential` members that `DeviceContext` names differently, by their
|
|
31
|
+
* `DeviceContext` name. A decoder error names the `KeyCredential` member.
|
|
32
|
+
*/
|
|
33
|
+
const KEY_CREDENTIAL_NAMES = Object.freeze({
|
|
34
|
+
deviceCredentialStatus: 'credentialStatus',
|
|
35
|
+
authKeyId: 'credentialId',
|
|
36
|
+
});
|
|
37
|
+
/**
|
|
38
|
+
* Map Complete's `data` payload: the `KeyCredential` that
|
|
39
|
+
* `POST /v1/accounts/auth/keys` returns for `"type": "deviceKey"`.
|
|
40
|
+
*
|
|
41
|
+
* DAA builds a `KeyCredential` from the same `DeviceContext` that
|
|
42
|
+
* `get_device_context` returns, with names that fit both key types. For a
|
|
43
|
+
* device key, `credentialStatus` is the `deviceCredentialStatus` and
|
|
44
|
+
* `credentialId` is the `authKeyId` (the `kid` that later
|
|
45
|
+
* `X-Device-Authorization` requests sign with). Every other member keeps its
|
|
46
|
+
* name. So the payload is checked for `type: "deviceKey"`, those two members
|
|
47
|
+
* are renamed, and the result is decoded as a `DeviceContext`:
|
|
48
|
+
*
|
|
49
|
+
* - `active` is `ACTIVE` (`toDeviceContext`), a first device or a key the
|
|
50
|
+
* account already holds;
|
|
51
|
+
* - `pending_approval` is a new device on an account that already has one (see
|
|
52
|
+
* `toPendingApproval`);
|
|
53
|
+
* - `pending_activation` is an approved device signing in again during its
|
|
54
|
+
* cool-down (see `toPendingActivation`);
|
|
55
|
+
* - any other status, or a missing one, fails closed, as does a malformed
|
|
56
|
+
* UUID or timestamp.
|
|
57
|
+
*
|
|
58
|
+
* Any other `type` is refused. Extra members are otherwise ignored.
|
|
59
|
+
* `clientEntityId` comes from Social Session, not this payload.
|
|
60
|
+
*/
|
|
61
|
+
function toDeviceRegistrationResult(value, sessionClientEntityId) {
|
|
62
|
+
const payload = deviceContextFromKeyCredential((0, payload_1.asObject)(value, 'payload'));
|
|
63
|
+
try {
|
|
64
|
+
const credentialStatus = (0, payload_1.optionalString)(payload, 'deviceCredentialStatus');
|
|
65
|
+
if (credentialStatus === 'pending_approval') {
|
|
66
|
+
return toPendingApproval(payload);
|
|
67
|
+
}
|
|
68
|
+
if (credentialStatus === 'pending_activation') {
|
|
69
|
+
return toPendingActivation(payload);
|
|
70
|
+
}
|
|
71
|
+
const result = Object.freeze({
|
|
72
|
+
status: 'ACTIVE',
|
|
73
|
+
context: new DaaUserContext_1.DaaUserContext(DaaUserContext_1.DECODER_TOKEN, {
|
|
74
|
+
clientEntityId: sessionClientEntityId,
|
|
75
|
+
deviceContext: (0, deviceContextPayload_1.toDeviceContext)(payload),
|
|
76
|
+
}),
|
|
77
|
+
});
|
|
78
|
+
return result;
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
if (error instanceof payload_1.MalformedPayloadError) {
|
|
82
|
+
throw new payload_1.MalformedPayloadError(KEY_CREDENTIAL_NAMES[error.fieldName] ?? error.fieldName);
|
|
83
|
+
}
|
|
84
|
+
throw error;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The `KeyCredential` as a flat `DeviceContext`: `credentialStatus` becomes
|
|
89
|
+
* `deviceCredentialStatus` and `credentialId` becomes `authKeyId`; every other
|
|
90
|
+
* member is kept as it is.
|
|
91
|
+
*/
|
|
92
|
+
function deviceContextFromKeyCredential(payload) {
|
|
93
|
+
if ((0, payload_1.requiredString)(payload, 'type') !== DEVICE_KEY_TYPE) {
|
|
94
|
+
throw new payload_1.MalformedPayloadError('type');
|
|
95
|
+
}
|
|
96
|
+
const deviceContext = { ...payload };
|
|
97
|
+
delete deviceContext.type;
|
|
98
|
+
delete deviceContext.credentialStatus;
|
|
99
|
+
delete deviceContext.credentialId;
|
|
100
|
+
deviceContext.deviceCredentialStatus = payload.credentialStatus;
|
|
101
|
+
deviceContext.authKeyId = payload.credentialId;
|
|
102
|
+
return deviceContext;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* The `DeviceContext` DAA returns for a new device on an account that
|
|
106
|
+
* already has one: `deviceCredentialStatus: "pending_approval"` with the
|
|
107
|
+
* request's `requestId`, `expiresAt` and the enclave's `codeNonce` (32 bytes,
|
|
108
|
+
* canonical unpadded Base64URL, so `PendingDeviceApproval` can decode it).
|
|
109
|
+
* `codeSeal`, when present, is the seal the request was created with (32
|
|
110
|
+
* bytes, the same encoding): for a key that was already waiting it is the one
|
|
111
|
+
* from its first registration, not this body's. A DAA that doesn't send it
|
|
112
|
+
* yet decodes as `null`. `ownerBindingId` and `resolvedAt` are not read:
|
|
113
|
+
* nothing here signs until the request is approved.
|
|
114
|
+
*/
|
|
115
|
+
function toPendingApproval(payload) {
|
|
116
|
+
const codeNonce = (0, payload_1.requiredString)(payload, 'codeNonce');
|
|
117
|
+
if ((0, matchingCode_1.canonicalBytes32)(codeNonce) === null) {
|
|
118
|
+
throw new payload_1.MalformedPayloadError('codeNonce');
|
|
119
|
+
}
|
|
120
|
+
const codeSeal = (0, payload_1.optionalString)(payload, 'codeSeal');
|
|
121
|
+
if (codeSeal !== null && (0, matchingCode_1.canonicalBytes32)(codeSeal) === null) {
|
|
122
|
+
throw new payload_1.MalformedPayloadError('codeSeal');
|
|
123
|
+
}
|
|
124
|
+
return Object.freeze({
|
|
125
|
+
status: 'PENDING_APPROVAL',
|
|
126
|
+
requestId: requiredUuid(payload, 'requestId'),
|
|
127
|
+
authKeyId: requiredUuid(payload, 'authKeyId'),
|
|
128
|
+
expiresAt: (0, instant_1.requiredDateTime)(payload, 'expiresAt'),
|
|
129
|
+
codeNonce,
|
|
130
|
+
codeSeal,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* The `DeviceContext` DAA returns for a device an existing device already
|
|
135
|
+
* approved, signing in again before the account's cool-down ends:
|
|
136
|
+
* `deviceCredentialStatus: "pending_activation"` with `readyAt`, when the key
|
|
137
|
+
* may sign. The key is the account's, so `ownerBindingId` and `authKeyId` are
|
|
138
|
+
* final. The `pending_approval` fields (`requestId`, `expiresAt`, `codeNonce`,
|
|
139
|
+
* `codeSeal`) make the payload ambiguous, so a payload carrying any of them is
|
|
140
|
+
* refused. `resolvedAt` is not read.
|
|
141
|
+
*/
|
|
142
|
+
function toPendingActivation(payload) {
|
|
143
|
+
for (const name of ['requestId', 'expiresAt', 'codeNonce', 'codeSeal']) {
|
|
144
|
+
const value = payload[name];
|
|
145
|
+
if (value !== undefined && value !== null) {
|
|
146
|
+
throw new payload_1.MalformedPayloadError(name);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return Object.freeze({
|
|
150
|
+
status: 'PENDING_ACTIVATION',
|
|
151
|
+
authKeyId: requiredUuid(payload, 'authKeyId'),
|
|
152
|
+
ownerBindingId: requiredUuid(payload, 'ownerBindingId'),
|
|
153
|
+
readyAt: (0, instant_1.requiredDateTime)(payload, 'readyAt'),
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
function requiredUuid(payload, name) {
|
|
157
|
+
const value = (0, payload_1.requiredString)(payload, name);
|
|
158
|
+
if (!(0, uuid_1.isUuid)(value)) {
|
|
159
|
+
throw new payload_1.MalformedPayloadError(name);
|
|
160
|
+
}
|
|
161
|
+
return value;
|
|
162
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
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 { DeviceStatus } from '../models/DeviceStatus';
|
|
19
|
+
/** Decode the status route's `data`. An unknown `status` is kept as `unrecognized`. */
|
|
20
|
+
export declare function toDeviceStatus(value: unknown): DeviceStatus;
|
|
@@ -0,0 +1,66 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.toDeviceStatus = toDeviceStatus;
|
|
21
|
+
const uuid_1 = require("../validation/uuid");
|
|
22
|
+
const instant_1 = require("./instant");
|
|
23
|
+
const payload_1 = require("./payload");
|
|
24
|
+
/** Decode the status route's `data`. An unknown `status` is kept as `unrecognized`. */
|
|
25
|
+
function toDeviceStatus(value) {
|
|
26
|
+
const payload = (0, payload_1.asObject)(value, 'payload');
|
|
27
|
+
const authKeyId = requiredUuid(payload, 'authKeyId');
|
|
28
|
+
const status = (0, payload_1.requiredString)(payload, 'status');
|
|
29
|
+
switch (status) {
|
|
30
|
+
case 'pending_approval':
|
|
31
|
+
case 'expired':
|
|
32
|
+
return Object.freeze({
|
|
33
|
+
status,
|
|
34
|
+
authKeyId,
|
|
35
|
+
requestId: requiredUuid(payload, 'requestId'),
|
|
36
|
+
expiresAt: (0, instant_1.requiredDateTime)(payload, 'expiresAt'),
|
|
37
|
+
});
|
|
38
|
+
case 'denied':
|
|
39
|
+
case 'cancelled':
|
|
40
|
+
return Object.freeze({ status, authKeyId, requestId: requiredUuid(payload, 'requestId') });
|
|
41
|
+
case 'pending_activation':
|
|
42
|
+
return Object.freeze({
|
|
43
|
+
status,
|
|
44
|
+
authKeyId,
|
|
45
|
+
...optionalRequestId(payload),
|
|
46
|
+
readyAt: (0, instant_1.requiredDateTime)(payload, 'readyAt'),
|
|
47
|
+
});
|
|
48
|
+
case 'active':
|
|
49
|
+
return Object.freeze({ status, authKeyId, ...optionalRequestId(payload) });
|
|
50
|
+
default:
|
|
51
|
+
// Preserved, not refused: DAA may add a status before this SDK knows it.
|
|
52
|
+
return Object.freeze({ status: 'unrecognized', authKeyId, rawValue: status });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function optionalRequestId(payload) {
|
|
56
|
+
return (0, payload_1.optionalString)(payload, 'requestId') === null
|
|
57
|
+
? {}
|
|
58
|
+
: { requestId: requiredUuid(payload, 'requestId') };
|
|
59
|
+
}
|
|
60
|
+
function requiredUuid(payload, name) {
|
|
61
|
+
const value = (0, payload_1.requiredString)(payload, name);
|
|
62
|
+
if (!(0, uuid_1.isUuid)(value)) {
|
|
63
|
+
throw new payload_1.MalformedPayloadError(name);
|
|
64
|
+
}
|
|
65
|
+
return value;
|
|
66
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Circle Internet Group, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* The DAA status code from an error body, when the body carries a readable one.
|
|
20
|
+
*
|
|
21
|
+
* Best-effort by design: a failed call must still surface its HTTP status and
|
|
22
|
+
* correlation id when the provider returned an empty body, a proxy's HTML error
|
|
23
|
+
* page, or a shape the contract does not describe. Losing the whole error because
|
|
24
|
+
* its detail did not parse would be worse than losing the detail, so every failure
|
|
25
|
+
* here is `null`.
|
|
26
|
+
*
|
|
27
|
+
* Only the code is lifted. The envelope's `message` and `externalMessage` are
|
|
28
|
+
* provider-authored text from a response the SDK cannot vouch for, and the SDK
|
|
29
|
+
* error model has nowhere to put them that is not a log line.
|
|
30
|
+
*
|
|
31
|
+
* DAA sends the flat platform error body, with the code at the **root**:
|
|
32
|
+
* `{"code":420034,"message":"…","externalMessage":"…"}`. The SDK also
|
|
33
|
+
* accepts the code at `status.code`, but only when the root `code` is absent.
|
|
34
|
+
* A root `code` that is present decides alone, even when it is unreadable or
|
|
35
|
+
* unknown and `status.code` is a known code. Present means the key exists with
|
|
36
|
+
* a value other than `null`. Neither is under `data`: the `data` success
|
|
37
|
+
* wrapper is never applied to an error response.
|
|
38
|
+
*
|
|
39
|
+
* A decimal-string code comes back as the number. Any other string comes back
|
|
40
|
+
* unchanged so that an `api` error can still show it, but it classifies
|
|
41
|
+
* nothing: `isDaaStatus` matches numbers only.
|
|
42
|
+
*/
|
|
43
|
+
export declare function readDaaStatusCode(bytes: Uint8Array | null): string | number | null;
|
|
@@ -0,0 +1,85 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.readDaaStatusCode = readDaaStatusCode;
|
|
21
|
+
const jsonNumber_1 = require("./jsonNumber");
|
|
22
|
+
/**
|
|
23
|
+
* The DAA status code from an error body, when the body carries a readable one.
|
|
24
|
+
*
|
|
25
|
+
* Best-effort by design: a failed call must still surface its HTTP status and
|
|
26
|
+
* correlation id when the provider returned an empty body, a proxy's HTML error
|
|
27
|
+
* page, or a shape the contract does not describe. Losing the whole error because
|
|
28
|
+
* its detail did not parse would be worse than losing the detail, so every failure
|
|
29
|
+
* here is `null`.
|
|
30
|
+
*
|
|
31
|
+
* Only the code is lifted. The envelope's `message` and `externalMessage` are
|
|
32
|
+
* provider-authored text from a response the SDK cannot vouch for, and the SDK
|
|
33
|
+
* error model has nowhere to put them that is not a log line.
|
|
34
|
+
*
|
|
35
|
+
* DAA sends the flat platform error body, with the code at the **root**:
|
|
36
|
+
* `{"code":420034,"message":"…","externalMessage":"…"}`. The SDK also
|
|
37
|
+
* accepts the code at `status.code`, but only when the root `code` is absent.
|
|
38
|
+
* A root `code` that is present decides alone, even when it is unreadable or
|
|
39
|
+
* unknown and `status.code` is a known code. Present means the key exists with
|
|
40
|
+
* a value other than `null`. Neither is under `data`: the `data` success
|
|
41
|
+
* wrapper is never applied to an error response.
|
|
42
|
+
*
|
|
43
|
+
* A decimal-string code comes back as the number. Any other string comes back
|
|
44
|
+
* unchanged so that an `api` error can still show it, but it classifies
|
|
45
|
+
* nothing: `isDaaStatus` matches numbers only.
|
|
46
|
+
*/
|
|
47
|
+
function readDaaStatusCode(bytes) {
|
|
48
|
+
if (bytes === null || bytes.length === 0) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
let root;
|
|
52
|
+
try {
|
|
53
|
+
root = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(bytes));
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
if (!isObject(root)) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
const flat = root['code'];
|
|
62
|
+
if (flat !== undefined && flat !== null) {
|
|
63
|
+
return codeValue(flat);
|
|
64
|
+
}
|
|
65
|
+
const status = root['status'];
|
|
66
|
+
return isObject(status) ? codeValue(status['code']) : null;
|
|
67
|
+
}
|
|
68
|
+
function isObject(value) {
|
|
69
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
70
|
+
}
|
|
71
|
+
function codeValue(code) {
|
|
72
|
+
// A numeric code arrives as a number from `JSON.parse`. A status code is
|
|
73
|
+
// small enough that no rounding question arises, so it is handed back as it
|
|
74
|
+
// came.
|
|
75
|
+
if (typeof code === 'number') {
|
|
76
|
+
return Number.isFinite(code) ? code : null;
|
|
77
|
+
}
|
|
78
|
+
if (typeof code !== 'string' || code.length === 0) {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
// A code the service quoted is handed back as a number when it is one, so a
|
|
82
|
+
// consumer can compare it without knowing which shape arrived. A string that
|
|
83
|
+
// is not a number is kept only for diagnostics on the `api` error.
|
|
84
|
+
return jsonNumber_1.JSON_NUMBER.test(code) ? Number(code) : code;
|
|
85
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
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 { FiatAccountStatus } from '../models/FiatAccount';
|
|
19
|
+
import { BankAddress, BillingDetails } from '../models/FiatAccount';
|
|
20
|
+
export declare function toFiatAccountStatus(raw: string): FiatAccountStatus;
|
|
21
|
+
export declare function optionalBoolean(payload: Record<string, unknown>, name: string, label?: string): boolean | null;
|
|
22
|
+
/**
|
|
23
|
+
* Decode the guaranteed `BillingDetails` shape.
|
|
24
|
+
*
|
|
25
|
+
* The service requires `name`, `city`, `country`, `line1`, and `postalCode` on
|
|
26
|
+
* every wire/ACH fiat account, unlike `Account`'s optional `BusinessPii`
|
|
27
|
+
* enrichment — so a fiat account missing one of these is a broken contract,
|
|
28
|
+
* not a partially-enriched record.
|
|
29
|
+
*/
|
|
30
|
+
export declare function toBillingDetails(value: unknown, label: string): BillingDetails;
|
|
31
|
+
export declare function requiredBillingDetails(payload: Record<string, unknown>, name: string): BillingDetails;
|
|
32
|
+
/**
|
|
33
|
+
* Decode the optional `BankAddress` shape. Only `country` is guaranteed when
|
|
34
|
+
* the object is present at all.
|
|
35
|
+
*/
|
|
36
|
+
export declare function toBankAddress(value: unknown, label: string): BankAddress;
|
|
37
|
+
export declare function optionalBankAddress(payload: Record<string, unknown>, name: string): BankAddress | null;
|
|
@@ -0,0 +1,93 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.toFiatAccountStatus = toFiatAccountStatus;
|
|
21
|
+
exports.optionalBoolean = optionalBoolean;
|
|
22
|
+
exports.toBillingDetails = toBillingDetails;
|
|
23
|
+
exports.requiredBillingDetails = requiredBillingDetails;
|
|
24
|
+
exports.toBankAddress = toBankAddress;
|
|
25
|
+
exports.optionalBankAddress = optionalBankAddress;
|
|
26
|
+
const FiatAccount_1 = require("../models/FiatAccount");
|
|
27
|
+
const payload_1 = require("./payload");
|
|
28
|
+
/** Decoders shared by the wire and ACH fiat-account payloads (`wirePayload.ts`, `achPayload.ts`). */
|
|
29
|
+
const STATUSES = new Map([
|
|
30
|
+
['pending', Object.freeze({ kind: 'pending' })],
|
|
31
|
+
['complete', Object.freeze({ kind: 'complete' })],
|
|
32
|
+
['failed', Object.freeze({ kind: 'failed' })],
|
|
33
|
+
]);
|
|
34
|
+
function toFiatAccountStatus(raw) {
|
|
35
|
+
return STATUSES.get(raw) ?? (0, payload_1.unrecognized)(raw);
|
|
36
|
+
}
|
|
37
|
+
function optionalBoolean(payload, name, label = name) {
|
|
38
|
+
const value = payload[name];
|
|
39
|
+
if (value === undefined || value === null) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
if (typeof value !== 'boolean') {
|
|
43
|
+
throw new payload_1.MalformedPayloadError(label);
|
|
44
|
+
}
|
|
45
|
+
return value;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Decode the guaranteed `BillingDetails` shape.
|
|
49
|
+
*
|
|
50
|
+
* The service requires `name`, `city`, `country`, `line1`, and `postalCode` on
|
|
51
|
+
* every wire/ACH fiat account, unlike `Account`'s optional `BusinessPii`
|
|
52
|
+
* enrichment — so a fiat account missing one of these is a broken contract,
|
|
53
|
+
* not a partially-enriched record.
|
|
54
|
+
*/
|
|
55
|
+
function toBillingDetails(value, label) {
|
|
56
|
+
const payload = (0, payload_1.asObject)(value, label);
|
|
57
|
+
return new FiatAccount_1.BillingDetails({
|
|
58
|
+
name: (0, payload_1.requiredString)(payload, 'name', `${label}.name`),
|
|
59
|
+
city: (0, payload_1.requiredString)(payload, 'city', `${label}.city`),
|
|
60
|
+
country: (0, payload_1.requiredString)(payload, 'country', `${label}.country`),
|
|
61
|
+
line1: (0, payload_1.requiredString)(payload, 'line1', `${label}.line1`),
|
|
62
|
+
line2: (0, payload_1.optionalString)(payload, 'line2', `${label}.line2`),
|
|
63
|
+
district: (0, payload_1.optionalString)(payload, 'district', `${label}.district`),
|
|
64
|
+
postalCode: (0, payload_1.requiredString)(payload, 'postalCode', `${label}.postalCode`),
|
|
65
|
+
valid: optionalBoolean(payload, 'valid', `${label}.valid`),
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
function requiredBillingDetails(payload, name) {
|
|
69
|
+
const value = payload[name];
|
|
70
|
+
if (value === undefined || value === null) {
|
|
71
|
+
throw new payload_1.MalformedPayloadError(name);
|
|
72
|
+
}
|
|
73
|
+
return toBillingDetails(value, name);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Decode the optional `BankAddress` shape. Only `country` is guaranteed when
|
|
77
|
+
* the object is present at all.
|
|
78
|
+
*/
|
|
79
|
+
function toBankAddress(value, label) {
|
|
80
|
+
const payload = (0, payload_1.asObject)(value, label);
|
|
81
|
+
return new FiatAccount_1.BankAddress({
|
|
82
|
+
bankName: (0, payload_1.optionalString)(payload, 'bankName', `${label}.bankName`),
|
|
83
|
+
city: (0, payload_1.optionalString)(payload, 'city', `${label}.city`),
|
|
84
|
+
country: (0, payload_1.requiredString)(payload, 'country', `${label}.country`),
|
|
85
|
+
line1: (0, payload_1.optionalString)(payload, 'line1', `${label}.line1`),
|
|
86
|
+
line2: (0, payload_1.optionalString)(payload, 'line2', `${label}.line2`),
|
|
87
|
+
district: (0, payload_1.optionalString)(payload, 'district', `${label}.district`),
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
function optionalBankAddress(payload, name) {
|
|
91
|
+
const value = (0, payload_1.optionalObject)(payload, name);
|
|
92
|
+
return value === null ? null : toBankAddress(value, name);
|
|
93
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Circle Internet Group, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* A login-flow timestamp the service guarantees, in either form it sends.
|
|
20
|
+
*
|
|
21
|
+
* The contract OpenAPI declares an ISO-8601 string and the running service
|
|
22
|
+
* sends a JSON number of epoch milliseconds, so the SDK accepts both. A number
|
|
23
|
+
* is normalised to the string form at this boundary, so every public timestamp
|
|
24
|
+
* stays one stable type no matter which form arrived. Anything that is neither
|
|
25
|
+
* form still fails closed.
|
|
26
|
+
*/
|
|
27
|
+
export declare function requiredDateTime(payload: Record<string, unknown>, name: string): string;
|