@circle-fin/daa-react-native-sdk 0.0.0-stage → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DaaReactNativeSdk.podspec +63 -0
- package/LICENSE +176 -0
- package/README.md +217 -2
- package/android/build.gradle +97 -0
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/java/com/circle/daa/reactnative/DaaRegistrationExceptions.kt +47 -0
- package/android/src/main/java/com/circle/daa/reactnative/DaaRegistrationModule.kt +121 -0
- package/android/src/main/java/com/circle/daa/reactnative/DaaScaExceptions.kt +60 -0
- package/android/src/main/java/com/circle/daa/reactnative/DaaScaModule.kt +179 -0
- package/android/src/main/java/com/circle/daa/reactnative/DaaSecureKeyExceptions.kt +73 -0
- package/android/src/main/java/com/circle/daa/reactnative/DaaSecureKeyModule.kt +185 -0
- package/android/src/main/java/com/circle/daa/reactnative/InstallationIdentityStore.kt +73 -0
- package/android/src/main/java/com/circle/daa/reactnative/UnpaddedBase64Url.kt +45 -0
- package/build/DaaClient.d.ts +57 -0
- package/build/DaaClient.js +158 -0
- package/build/api/AccountLimitsClient.d.ts +79 -0
- package/build/api/AccountLimitsClient.js +142 -0
- package/build/api/AccountsClient.d.ts +95 -0
- package/build/api/AccountsClient.js +276 -0
- package/build/api/AchFiatAccountsClient.d.ts +92 -0
- package/build/api/AchFiatAccountsClient.js +142 -0
- package/build/api/AuthClient.d.ts +120 -0
- package/build/api/AuthClient.js +257 -0
- package/build/api/DaaUserClient.d.ts +124 -0
- package/build/api/DaaUserClient.js +245 -0
- package/build/api/DepositAddressesClient.d.ts +112 -0
- package/build/api/DepositAddressesClient.js +222 -0
- package/build/api/DepositsClient.d.ts +106 -0
- package/build/api/DepositsClient.js +183 -0
- package/build/api/FiatAccountsClient.d.ts +43 -0
- package/build/api/FiatAccountsClient.js +46 -0
- package/build/api/TransactionsClient.d.ts +64 -0
- package/build/api/TransactionsClient.js +120 -0
- package/build/api/TransfersClient.d.ts +104 -0
- package/build/api/TransfersClient.js +321 -0
- package/build/api/WireFiatAccountsClient.d.ts +99 -0
- package/build/api/WireFiatAccountsClient.js +156 -0
- package/build/api/WithdrawalsClient.d.ts +94 -0
- package/build/api/WithdrawalsClient.js +305 -0
- package/build/api/loginFailure.d.ts +43 -0
- package/build/api/loginFailure.js +64 -0
- package/build/api/pagination.d.ts +29 -0
- package/build/api/pagination.js +50 -0
- package/build/api/queryParameters.d.ts +23 -0
- package/build/api/queryParameters.js +77 -0
- package/build/api/resourceRequest.d.ts +60 -0
- package/build/api/resourceRequest.js +79 -0
- package/build/api/signedResource.d.ts +77 -0
- package/build/api/signedResource.js +168 -0
- package/build/auth/RegistrationFlowKey.d.ts +93 -0
- package/build/auth/RegistrationFlowKey.js +203 -0
- package/build/auth/daaRegistrationNative.d.ts +80 -0
- package/build/auth/daaRegistrationNative.js +184 -0
- package/build/auth/deviceAuthorization.d.ts +73 -0
- package/build/auth/deviceAuthorization.js +243 -0
- package/build/auth/ownerGrant.d.ts +29 -0
- package/build/auth/ownerGrant.js +90 -0
- package/build/auth/prepareReceipt.d.ts +150 -0
- package/build/auth/prepareReceipt.js +357 -0
- package/build/auth/registrationAuthorization.d.ts +48 -0
- package/build/auth/registrationAuthorization.js +243 -0
- package/build/auth/registrationCodeVerifier.d.ts +31 -0
- package/build/auth/registrationCodeVerifier.js +75 -0
- package/build/config.d.ts +79 -0
- package/build/config.js +116 -0
- package/build/crypto/base64url.d.ts +26 -0
- package/build/crypto/base64url.js +87 -0
- package/build/crypto/bytes.d.ts +27 -0
- package/build/crypto/bytes.js +32 -0
- package/build/crypto/es256Jws.d.ts +56 -0
- package/build/crypto/es256Jws.js +196 -0
- package/build/crypto/jwkThumbprint.d.ts +32 -0
- package/build/crypto/jwkThumbprint.js +49 -0
- package/build/crypto/random.d.ts +35 -0
- package/build/crypto/random.js +106 -0
- package/build/crypto/serialization.d.ts +26 -0
- package/build/crypto/serialization.js +43 -0
- package/build/crypto/sha256.d.ts +18 -0
- package/build/crypto/sha256.js +100 -0
- package/build/errors.d.ts +190 -0
- package/build/errors.js +252 -0
- package/build/index.d.ts +61 -0
- package/build/index.js +67 -0
- package/build/models/Account.d.ts +201 -0
- package/build/models/Account.js +147 -0
- package/build/models/AccountLimitsUsage.d.ts +169 -0
- package/build/models/AccountLimitsUsage.js +86 -0
- package/build/models/Ach.d.ts +135 -0
- package/build/models/Ach.js +184 -0
- package/build/models/AddressObject.d.ts +128 -0
- package/build/models/AddressObject.js +141 -0
- package/build/models/BusinessPii.d.ts +84 -0
- package/build/models/BusinessPii.js +142 -0
- package/build/models/CreateAccountRequest.d.ts +74 -0
- package/build/models/CreateAccountRequest.js +19 -0
- package/build/models/CreateTransferRequest.d.ts +91 -0
- package/build/models/CreateTransferRequest.js +19 -0
- package/build/models/CreateWithdrawalRequest.d.ts +99 -0
- package/build/models/CreateWithdrawalRequest.js +19 -0
- package/build/models/DaaUserContext.d.ts +96 -0
- package/build/models/DaaUserContext.js +133 -0
- package/build/models/Deposit.d.ts +241 -0
- package/build/models/Deposit.js +149 -0
- package/build/models/DepositSummary.d.ts +91 -0
- package/build/models/DepositSummary.js +114 -0
- package/build/models/FiatAccount.d.ts +99 -0
- package/build/models/FiatAccount.js +151 -0
- package/build/models/GenerateAddressRequest.d.ts +67 -0
- package/build/models/GenerateAddressRequest.js +68 -0
- package/build/models/Money.d.ts +76 -0
- package/build/models/Money.js +99 -0
- package/build/models/Page.d.ts +33 -0
- package/build/models/Page.js +57 -0
- package/build/models/PendingDeviceRegistration.d.ts +90 -0
- package/build/models/PendingDeviceRegistration.js +180 -0
- package/build/models/PreparedSocialLogin.d.ts +155 -0
- package/build/models/PreparedSocialLogin.js +235 -0
- package/build/models/Transaction.d.ts +187 -0
- package/build/models/Transaction.js +134 -0
- package/build/models/Transfer.d.ts +335 -0
- package/build/models/Transfer.js +240 -0
- package/build/models/Wire.d.ts +213 -0
- package/build/models/Wire.js +264 -0
- package/build/models/Withdrawal.d.ts +201 -0
- package/build/models/Withdrawal.js +156 -0
- package/build/models/redaction.d.ts +18 -0
- package/build/models/redaction.js +23 -0
- package/build/sca/ScaClient.d.ts +105 -0
- package/build/sca/ScaClient.js +193 -0
- package/build/securekey/InMemorySecureKey.d.ts +23 -0
- package/build/securekey/InMemorySecureKey.js +127 -0
- package/build/securekey/NativeSecureKey.d.ts +24 -0
- package/build/securekey/NativeSecureKey.js +178 -0
- package/build/securekey/NativeSecureKeyBridge.d.ts +83 -0
- package/build/securekey/NativeSecureKeyBridge.js +19 -0
- package/build/securekey/SecureKey.d.ts +137 -0
- package/build/securekey/SecureKey.js +19 -0
- package/build/securekey/alias.d.ts +88 -0
- package/build/securekey/alias.js +175 -0
- package/build/securekey/ownerAuthKeyResolver.d.ts +56 -0
- package/build/securekey/ownerAuthKeyResolver.js +63 -0
- package/build/securekey/resolveNativeBridge.d.ts +30 -0
- package/build/securekey/resolveNativeBridge.js +120 -0
- package/build/testing.d.ts +18 -0
- package/build/testing.js +34 -0
- package/build/transport/DaaTransport.d.ts +35 -0
- package/build/transport/DaaTransport.js +19 -0
- package/build/transport/headers.d.ts +30 -0
- package/build/transport/headers.js +45 -0
- package/build/validation/requestBody.d.ts +27 -0
- package/build/validation/requestBody.js +56 -0
- package/build/validation/uuid.d.ts +25 -0
- package/build/validation/uuid.js +33 -0
- package/build/wire/accountLimitsUsagePayload.d.ts +30 -0
- package/build/wire/accountLimitsUsagePayload.js +130 -0
- package/build/wire/accountPayload.d.ts +36 -0
- package/build/wire/accountPayload.js +100 -0
- package/build/wire/achPayload.d.ts +24 -0
- package/build/wire/achPayload.js +82 -0
- package/build/wire/addressObjectPayload.d.ts +44 -0
- package/build/wire/addressObjectPayload.js +64 -0
- package/build/wire/daaStatusCodes.d.ts +64 -0
- package/build/wire/daaStatusCodes.js +69 -0
- package/build/wire/dataEnvelope.d.ts +40 -0
- package/build/wire/dataEnvelope.js +79 -0
- package/build/wire/depositPayload.d.ts +42 -0
- package/build/wire/depositPayload.js +159 -0
- package/build/wire/deviceContextPayload.d.ts +33 -0
- package/build/wire/deviceContextPayload.js +57 -0
- package/build/wire/deviceRegistrationResultPayload.d.ts +32 -0
- package/build/wire/deviceRegistrationResultPayload.js +128 -0
- package/build/wire/errorEnvelope.d.ts +43 -0
- package/build/wire/errorEnvelope.js +85 -0
- package/build/wire/fiatAccountPayload.d.ts +37 -0
- package/build/wire/fiatAccountPayload.js +93 -0
- package/build/wire/instant.d.ts +27 -0
- package/build/wire/instant.js +91 -0
- package/build/wire/jsonNumber.d.ts +30 -0
- package/build/wire/jsonNumber.js +34 -0
- package/build/wire/moneyPayload.d.ts +30 -0
- package/build/wire/moneyPayload.js +56 -0
- package/build/wire/paginationLinks.d.ts +28 -0
- package/build/wire/paginationLinks.js +167 -0
- package/build/wire/payload.d.ts +60 -0
- package/build/wire/payload.js +121 -0
- package/build/wire/pendingRegistrationPayload.d.ts +32 -0
- package/build/wire/pendingRegistrationPayload.js +54 -0
- package/build/wire/socialLoginRequestPayload.d.ts +31 -0
- package/build/wire/socialLoginRequestPayload.js +72 -0
- package/build/wire/transactionPayload.d.ts +31 -0
- package/build/wire/transactionPayload.js +126 -0
- package/build/wire/transferPayload.d.ts +43 -0
- package/build/wire/transferPayload.js +218 -0
- package/build/wire/wireEnums.d.ts +22 -0
- package/build/wire/wireEnums.js +69 -0
- package/build/wire/wirePayload.d.ts +29 -0
- package/build/wire/wirePayload.js +138 -0
- package/build/wire/withdrawalPayload.d.ts +27 -0
- package/build/wire/withdrawalPayload.js +179 -0
- package/expo-module.config.json +14 -0
- package/ios/DaaRegistrationExceptions.swift +58 -0
- package/ios/DaaRegistrationModule.swift +143 -0
- package/ios/DaaScaExceptions.swift +96 -0
- package/ios/DaaScaModule.swift +125 -0
- package/ios/DaaSecureKeyExceptions.swift +77 -0
- package/ios/DaaSecureKeyModule.swift +162 -0
- package/ios/InstallationIdentityStore.swift +126 -0
- package/ios/UnpaddedBase64URL.swift +42 -0
- package/package.json +114 -4
- package/src/DaaClient.ts +171 -0
- package/src/api/AccountLimitsClient.ts +146 -0
- package/src/api/AccountsClient.ts +305 -0
- package/src/api/AchFiatAccountsClient.ts +147 -0
- package/src/api/AuthClient.ts +331 -0
- package/src/api/DaaUserClient.ts +270 -0
- package/src/api/DepositAddressesClient.ts +239 -0
- package/src/api/DepositsClient.ts +208 -0
- package/src/api/FiatAccountsClient.ts +50 -0
- package/src/api/TransactionsClient.ts +137 -0
- package/src/api/TransfersClient.ts +361 -0
- package/src/api/WireFiatAccountsClient.ts +172 -0
- package/src/api/WithdrawalsClient.ts +339 -0
- package/src/api/loginFailure.ts +75 -0
- package/src/api/pagination.ts +63 -0
- package/src/api/queryParameters.ts +82 -0
- package/src/api/resourceRequest.ts +135 -0
- package/src/api/signedResource.ts +267 -0
- package/src/auth/RegistrationFlowKey.ts +274 -0
- package/src/auth/daaRegistrationNative.ts +236 -0
- package/src/auth/deviceAuthorization.ts +302 -0
- package/src/auth/ownerGrant.ts +102 -0
- package/src/auth/prepareReceipt.ts +522 -0
- package/src/auth/registrationAuthorization.ts +306 -0
- package/src/auth/registrationCodeVerifier.ts +76 -0
- package/src/config.ts +156 -0
- package/src/crypto/base64url.ts +88 -0
- package/src/crypto/bytes.ts +30 -0
- package/src/crypto/es256Jws.ts +240 -0
- package/src/crypto/jwkThumbprint.ts +65 -0
- package/src/crypto/random.ts +113 -0
- package/src/crypto/serialization.ts +42 -0
- package/src/crypto/sha256.ts +105 -0
- package/src/errors.ts +319 -0
- package/src/index.ts +223 -0
- package/src/models/Account.ts +264 -0
- package/src/models/AccountLimitsUsage.ts +192 -0
- package/src/models/Ach.ts +269 -0
- package/src/models/AddressObject.ts +169 -0
- package/src/models/BusinessPii.ts +154 -0
- package/src/models/CreateAccountRequest.ts +109 -0
- package/src/models/CreateTransferRequest.ts +114 -0
- package/src/models/CreateWithdrawalRequest.ts +120 -0
- package/src/models/DaaUserContext.ts +172 -0
- package/src/models/Deposit.ts +307 -0
- package/src/models/DepositSummary.ts +142 -0
- package/src/models/FiatAccount.ts +195 -0
- package/src/models/GenerateAddressRequest.ts +101 -0
- package/src/models/Money.ts +91 -0
- package/src/models/Page.ts +48 -0
- package/src/models/PendingDeviceRegistration.ts +197 -0
- package/src/models/PreparedSocialLogin.ts +287 -0
- package/src/models/Transaction.ts +247 -0
- package/src/models/Transfer.ts +459 -0
- package/src/models/Wire.ts +405 -0
- package/src/models/Withdrawal.ts +283 -0
- package/src/models/redaction.ts +22 -0
- package/src/sca/ScaClient.ts +289 -0
- package/src/securekey/InMemorySecureKey.ts +138 -0
- package/src/securekey/NativeSecureKey.ts +179 -0
- package/src/securekey/NativeSecureKeyBridge.ts +109 -0
- package/src/securekey/SecureKey.ts +149 -0
- package/src/securekey/alias.ts +204 -0
- package/src/securekey/ownerAuthKeyResolver.ts +96 -0
- package/src/securekey/resolveNativeBridge.ts +185 -0
- package/src/testing.ts +32 -0
- package/src/transport/DaaTransport.ts +42 -0
- package/src/transport/headers.ts +46 -0
- package/src/validation/requestBody.ts +60 -0
- package/src/validation/uuid.ts +31 -0
- package/src/wire/accountLimitsUsagePayload.ts +182 -0
- package/src/wire/accountPayload.ts +108 -0
- package/src/wire/achPayload.ts +98 -0
- package/src/wire/addressObjectPayload.ts +64 -0
- package/src/wire/daaStatusCodes.ts +69 -0
- package/src/wire/dataEnvelope.ts +80 -0
- package/src/wire/depositPayload.ts +186 -0
- package/src/wire/deviceContextPayload.ts +58 -0
- package/src/wire/deviceRegistrationResultPayload.ts +153 -0
- package/src/wire/errorEnvelope.ts +87 -0
- package/src/wire/fiatAccountPayload.ts +112 -0
- package/src/wire/instant.ts +93 -0
- package/src/wire/jsonNumber.ts +33 -0
- package/src/wire/moneyPayload.ts +55 -0
- package/src/wire/paginationLinks.ts +204 -0
- package/src/wire/payload.ts +146 -0
- package/src/wire/pendingRegistrationPayload.ts +75 -0
- package/src/wire/socialLoginRequestPayload.ts +89 -0
- package/src/wire/transactionPayload.ts +145 -0
- package/src/wire/transferPayload.ts +249 -0
- package/src/wire/wireEnums.ts +74 -0
- package/src/wire/wirePayload.ts +160 -0
- package/src/wire/withdrawalPayload.ts +219 -0
- package/testing.d.ts +19 -0
- package/testing.js +25 -0
|
@@ -0,0 +1,153 @@
|
|
|
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
|
+
import {
|
|
20
|
+
DaaUserContext,
|
|
21
|
+
DECODER_TOKEN,
|
|
22
|
+
type DeviceRegistrationResult,
|
|
23
|
+
} from '../models/DaaUserContext'
|
|
24
|
+
import { toDeviceContext } from './deviceContextPayload'
|
|
25
|
+
import { requiredDateTime } from './instant'
|
|
26
|
+
import {
|
|
27
|
+
asObject,
|
|
28
|
+
MalformedPayloadError,
|
|
29
|
+
optionalObject,
|
|
30
|
+
optionalString,
|
|
31
|
+
requiredString,
|
|
32
|
+
} from './payload'
|
|
33
|
+
|
|
34
|
+
const RECOVERY_REF_MIN = 16
|
|
35
|
+
const RECOVERY_REF_MAX = 512
|
|
36
|
+
|
|
37
|
+
function toActiveContext(
|
|
38
|
+
payload: Record<string, unknown>,
|
|
39
|
+
sessionClientEntityId: string,
|
|
40
|
+
): DaaUserContext {
|
|
41
|
+
return new DaaUserContext(DECODER_TOKEN, {
|
|
42
|
+
clientEntityId: sessionClientEntityId,
|
|
43
|
+
deviceContext: toDeviceContext(payload),
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The DeviceContext-shaped object Complete returns: a flat payload, or
|
|
49
|
+
* nested `context.deviceContext` / `context` when `status: "ACTIVE"`.
|
|
50
|
+
*/
|
|
51
|
+
function deviceContextPayloadFromComplete(
|
|
52
|
+
payload: Record<string, unknown>,
|
|
53
|
+
): Record<string, unknown> {
|
|
54
|
+
if (optionalString(payload, 'status') !== 'ACTIVE') {
|
|
55
|
+
return payload
|
|
56
|
+
}
|
|
57
|
+
const contextPayload = optionalObject(payload, 'context')
|
|
58
|
+
if (contextPayload === null) {
|
|
59
|
+
throw new MalformedPayloadError('context')
|
|
60
|
+
}
|
|
61
|
+
return optionalObject(contextPayload, 'deviceContext') ?? contextPayload
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Map Complete's `data` payload.
|
|
66
|
+
*
|
|
67
|
+
* The service returns a flat `DeviceContext`. The wrapped `{ status, context }`
|
|
68
|
+
* shape and `RECOVERY_PENDING` are also decoded when present. An absent
|
|
69
|
+
* `status` is read as that flat shape only on a positive signal: it still needs
|
|
70
|
+
* `deviceCredentialStatus === 'active'` (enforced by `toDeviceContext`), and
|
|
71
|
+
* it must carry neither `recoveryReference` nor `expiresAt` — the fields that
|
|
72
|
+
* belong to the `RECOVERY_PENDING` shape. A payload carrying either alongside
|
|
73
|
+
* an absent `status` is ambiguous and is rejected rather than resolved toward
|
|
74
|
+
* the more privileged `ACTIVE` outcome. Extra members are otherwise ignored.
|
|
75
|
+
* `clientEntityId` comes from Social Session, not this payload.
|
|
76
|
+
*/
|
|
77
|
+
export function toDeviceRegistrationResult(
|
|
78
|
+
value: unknown,
|
|
79
|
+
sessionClientEntityId: string,
|
|
80
|
+
): DeviceRegistrationResult {
|
|
81
|
+
const payload = asObject(value, 'payload')
|
|
82
|
+
const status = optionalString(payload, 'status')
|
|
83
|
+
if (status === 'RECOVERY_PENDING') {
|
|
84
|
+
if (optionalObject(payload, 'context') !== null) {
|
|
85
|
+
throw new MalformedPayloadError('context')
|
|
86
|
+
}
|
|
87
|
+
const recoveryReference = requiredString(payload, 'recoveryReference')
|
|
88
|
+
if (
|
|
89
|
+
recoveryReference.length < RECOVERY_REF_MIN ||
|
|
90
|
+
recoveryReference.length > RECOVERY_REF_MAX
|
|
91
|
+
) {
|
|
92
|
+
throw new MalformedPayloadError('recoveryReference')
|
|
93
|
+
}
|
|
94
|
+
const result: DeviceRegistrationResult = Object.freeze({
|
|
95
|
+
status: 'RECOVERY_PENDING',
|
|
96
|
+
recoveryReference,
|
|
97
|
+
// `expiresAt` accepts both timestamp forms, like the other login-flow
|
|
98
|
+
// timestamps on this response.
|
|
99
|
+
expiresAt: requiredDateTime(payload, 'expiresAt'),
|
|
100
|
+
})
|
|
101
|
+
return result
|
|
102
|
+
}
|
|
103
|
+
if (status === 'ACTIVE') {
|
|
104
|
+
const contextPayload = optionalObject(payload, 'context')
|
|
105
|
+
if (contextPayload === null) {
|
|
106
|
+
throw new MalformedPayloadError('context')
|
|
107
|
+
}
|
|
108
|
+
const nestedClient = optionalString(contextPayload, 'clientEntityId')
|
|
109
|
+
if (nestedClient !== null && nestedClient !== sessionClientEntityId) {
|
|
110
|
+
throw new MalformedPayloadError('clientEntityId')
|
|
111
|
+
}
|
|
112
|
+
const devicePayload = deviceContextPayloadFromComplete(payload)
|
|
113
|
+
const result: DeviceRegistrationResult = Object.freeze({
|
|
114
|
+
status: 'ACTIVE',
|
|
115
|
+
context: new DaaUserContext(DECODER_TOKEN, {
|
|
116
|
+
clientEntityId: sessionClientEntityId,
|
|
117
|
+
deviceContext: toDeviceContext(devicePayload),
|
|
118
|
+
}),
|
|
119
|
+
})
|
|
120
|
+
return result
|
|
121
|
+
}
|
|
122
|
+
if (status !== null) {
|
|
123
|
+
throw new MalformedPayloadError('status')
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Flat shape: only decodable on a positive ACTIVE signal, never on
|
|
127
|
+
// the mere absence of `status`. `toActiveContext` still requires
|
|
128
|
+
// `deviceCredentialStatus === 'active'`; this additionally refuses a
|
|
129
|
+
// payload that also carries a `RECOVERY_PENDING` field, rather than
|
|
130
|
+
// silently preferring the more privileged outcome. The error names
|
|
131
|
+
// whichever `RECOVERY_PENDING` field is actually present — `status` itself
|
|
132
|
+
// is absent here, not malformed.
|
|
133
|
+
const conflictingRecoveryField = hasPresentField(payload, 'recoveryReference')
|
|
134
|
+
? 'recoveryReference'
|
|
135
|
+
: hasPresentField(payload, 'expiresAt')
|
|
136
|
+
? 'expiresAt'
|
|
137
|
+
: null
|
|
138
|
+
if (conflictingRecoveryField !== null) {
|
|
139
|
+
throw new MalformedPayloadError(conflictingRecoveryField)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const result: DeviceRegistrationResult = Object.freeze({
|
|
143
|
+
status: 'ACTIVE',
|
|
144
|
+
context: toActiveContext(payload, sessionClientEntityId),
|
|
145
|
+
})
|
|
146
|
+
return result
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** JSON `null` is treated as absence, matching `optionalString`/`optionalObject`. */
|
|
150
|
+
function hasPresentField(payload: Record<string, unknown>, name: string): boolean {
|
|
151
|
+
const value = payload[name]
|
|
152
|
+
return value !== undefined && value !== null
|
|
153
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
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
|
+
import { JSON_NUMBER } from './jsonNumber'
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The DAA status code from an error body, when the body carries a readable one.
|
|
23
|
+
*
|
|
24
|
+
* Best-effort by design: a failed call must still surface its HTTP status and
|
|
25
|
+
* correlation id when the provider returned an empty body, a proxy's HTML error
|
|
26
|
+
* page, or a shape the contract does not describe. Losing the whole error because
|
|
27
|
+
* its detail did not parse would be worse than losing the detail, so every failure
|
|
28
|
+
* here is `null`.
|
|
29
|
+
*
|
|
30
|
+
* Only the code is lifted. The envelope's `message` and `externalMessage` are
|
|
31
|
+
* provider-authored text from a response the SDK cannot vouch for, and the SDK
|
|
32
|
+
* error model has nowhere to put them that is not a log line.
|
|
33
|
+
*
|
|
34
|
+
* DAA sends the flat platform error body, with the code at the **root**:
|
|
35
|
+
* `{"code":420034,"message":"…","externalMessage":"…"}`. The SDK also
|
|
36
|
+
* accepts the code at `status.code`, but only when the root `code` is absent.
|
|
37
|
+
* A root `code` that is present decides alone, even when it is unreadable or
|
|
38
|
+
* unknown and `status.code` is a known code. Present means the key exists with
|
|
39
|
+
* a value other than `null`. Neither is under `data`: the `data` success
|
|
40
|
+
* wrapper is never applied to an error response.
|
|
41
|
+
*
|
|
42
|
+
* A decimal-string code comes back as the number. Any other string comes back
|
|
43
|
+
* unchanged so that an `api` error can still show it, but it classifies
|
|
44
|
+
* nothing: `isDaaStatus` matches numbers only.
|
|
45
|
+
*/
|
|
46
|
+
export function readDaaStatusCode(bytes: Uint8Array | null): string | number | null {
|
|
47
|
+
if (bytes === null || bytes.length === 0) {
|
|
48
|
+
return null
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
let root: unknown
|
|
52
|
+
try {
|
|
53
|
+
root = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(bytes)) as unknown
|
|
54
|
+
} catch {
|
|
55
|
+
return null
|
|
56
|
+
}
|
|
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
|
+
|
|
69
|
+
function isObject(value: unknown): value is Record<string, unknown> {
|
|
70
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function codeValue(code: unknown): string | number | null {
|
|
74
|
+
// A numeric code arrives as a number from `JSON.parse`. A status code is
|
|
75
|
+
// small enough that no rounding question arises, so it is handed back as it
|
|
76
|
+
// came.
|
|
77
|
+
if (typeof code === 'number') {
|
|
78
|
+
return Number.isFinite(code) ? code : null
|
|
79
|
+
}
|
|
80
|
+
if (typeof code !== 'string' || code.length === 0) {
|
|
81
|
+
return null
|
|
82
|
+
}
|
|
83
|
+
// A code the service quoted is handed back as a number when it is one, so a
|
|
84
|
+
// consumer can compare it without knowing which shape arrived. A string that
|
|
85
|
+
// is not a number is kept only for diagnostics on the `api` error.
|
|
86
|
+
return JSON_NUMBER.test(code) ? Number(code) : code
|
|
87
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
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
|
+
import type { FiatAccountStatus } from '../models/FiatAccount'
|
|
20
|
+
import { BankAddress, BillingDetails } from '../models/FiatAccount'
|
|
21
|
+
import {
|
|
22
|
+
MalformedPayloadError,
|
|
23
|
+
asObject,
|
|
24
|
+
optionalObject,
|
|
25
|
+
optionalString,
|
|
26
|
+
requiredString,
|
|
27
|
+
unrecognized,
|
|
28
|
+
} from './payload'
|
|
29
|
+
|
|
30
|
+
/** Decoders shared by the wire and ACH fiat-account payloads (`wirePayload.ts`, `achPayload.ts`). */
|
|
31
|
+
|
|
32
|
+
const STATUSES = new Map<string, FiatAccountStatus>([
|
|
33
|
+
['pending', Object.freeze({ kind: 'pending' as const })],
|
|
34
|
+
['complete', Object.freeze({ kind: 'complete' as const })],
|
|
35
|
+
['failed', Object.freeze({ kind: 'failed' as const })],
|
|
36
|
+
])
|
|
37
|
+
|
|
38
|
+
export function toFiatAccountStatus(raw: string): FiatAccountStatus {
|
|
39
|
+
return STATUSES.get(raw) ?? unrecognized(raw)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function optionalBoolean(
|
|
43
|
+
payload: Record<string, unknown>,
|
|
44
|
+
name: string,
|
|
45
|
+
label = name,
|
|
46
|
+
): boolean | null {
|
|
47
|
+
const value = payload[name]
|
|
48
|
+
if (value === undefined || value === null) {
|
|
49
|
+
return null
|
|
50
|
+
}
|
|
51
|
+
if (typeof value !== 'boolean') {
|
|
52
|
+
throw new MalformedPayloadError(label)
|
|
53
|
+
}
|
|
54
|
+
return value
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Decode the guaranteed `BillingDetails` shape.
|
|
59
|
+
*
|
|
60
|
+
* The service requires `name`, `city`, `country`, `line1`, and `postalCode` on
|
|
61
|
+
* every wire/ACH fiat account, unlike `Account`'s optional `BusinessPii`
|
|
62
|
+
* enrichment — so a fiat account missing one of these is a broken contract,
|
|
63
|
+
* not a partially-enriched record.
|
|
64
|
+
*/
|
|
65
|
+
export function toBillingDetails(value: unknown, label: string): BillingDetails {
|
|
66
|
+
const payload = asObject(value, label)
|
|
67
|
+
return new BillingDetails({
|
|
68
|
+
name: requiredString(payload, 'name', `${label}.name`),
|
|
69
|
+
city: requiredString(payload, 'city', `${label}.city`),
|
|
70
|
+
country: requiredString(payload, 'country', `${label}.country`),
|
|
71
|
+
line1: requiredString(payload, 'line1', `${label}.line1`),
|
|
72
|
+
line2: optionalString(payload, 'line2', `${label}.line2`),
|
|
73
|
+
district: optionalString(payload, 'district', `${label}.district`),
|
|
74
|
+
postalCode: requiredString(payload, 'postalCode', `${label}.postalCode`),
|
|
75
|
+
valid: optionalBoolean(payload, 'valid', `${label}.valid`),
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function requiredBillingDetails(
|
|
80
|
+
payload: Record<string, unknown>,
|
|
81
|
+
name: string,
|
|
82
|
+
): BillingDetails {
|
|
83
|
+
const value = payload[name]
|
|
84
|
+
if (value === undefined || value === null) {
|
|
85
|
+
throw new MalformedPayloadError(name)
|
|
86
|
+
}
|
|
87
|
+
return toBillingDetails(value, name)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Decode the optional `BankAddress` shape. Only `country` is guaranteed when
|
|
92
|
+
* the object is present at all.
|
|
93
|
+
*/
|
|
94
|
+
export function toBankAddress(value: unknown, label: string): BankAddress {
|
|
95
|
+
const payload = asObject(value, label)
|
|
96
|
+
return new BankAddress({
|
|
97
|
+
bankName: optionalString(payload, 'bankName', `${label}.bankName`),
|
|
98
|
+
city: optionalString(payload, 'city', `${label}.city`),
|
|
99
|
+
country: requiredString(payload, 'country', `${label}.country`),
|
|
100
|
+
line1: optionalString(payload, 'line1', `${label}.line1`),
|
|
101
|
+
line2: optionalString(payload, 'line2', `${label}.line2`),
|
|
102
|
+
district: optionalString(payload, 'district', `${label}.district`),
|
|
103
|
+
})
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function optionalBankAddress(
|
|
107
|
+
payload: Record<string, unknown>,
|
|
108
|
+
name: string,
|
|
109
|
+
): BankAddress | null {
|
|
110
|
+
const value = optionalObject(payload, name)
|
|
111
|
+
return value === null ? null : toBankAddress(value, name)
|
|
112
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
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
|
+
import { MalformedPayloadError, requiredString } from './payload'
|
|
20
|
+
|
|
21
|
+
// The two wire forms a login-flow timestamp arrives in, and the single form
|
|
22
|
+
// the login decoders hand on.
|
|
23
|
+
//
|
|
24
|
+
// By default the service serialises a timestamp as a JSON number: an integral
|
|
25
|
+
// count of epoch milliseconds, not fractional seconds. Most timestamps opt out
|
|
26
|
+
// and are sent as ISO-8601 strings: every response carrying a `createDate` /
|
|
27
|
+
// `updateDate` does. Exactly three responses do not — Prepare
|
|
28
|
+
// (`PreparedSocialLogin`), Session and the device context — and those three are
|
|
29
|
+
// the login flow's three responses. The number form is therefore not a
|
|
30
|
+
// service-wide habit but a property of precisely the fields these decoders
|
|
31
|
+
// read, which is why this lives on its own rather than in `payload.ts` beside
|
|
32
|
+
// `requiredString`: a resource `createDate` arriving as a number would be a real
|
|
33
|
+
// contract violation, and `deposit`/`transfer`/`withdrawal` must keep rejecting
|
|
34
|
+
// it.
|
|
35
|
+
//
|
|
36
|
+
// The three fields are `PreparedSocialLogin.expiresAt`,
|
|
37
|
+
// `SocialSession.expiresAt` and `DeviceContext.resolvedAt`. They are the same
|
|
38
|
+
// kind of field, serialised the same way, so all three accept both forms.
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The ISO-8601 form the contract declares for an `Instant`, with a `T`
|
|
42
|
+
* separator. The service does not always send this form — see `requiredDateTime`
|
|
43
|
+
* — but it is the single form these decoders hand on.
|
|
44
|
+
*/
|
|
45
|
+
const DATE_TIME = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})$/
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Render epoch milliseconds as the same ISO-8601 text the string form carries.
|
|
49
|
+
*
|
|
50
|
+
* Three checks, no coercions. A fractional, non-finite, or beyond-safe-integer
|
|
51
|
+
* value is not a count of milliseconds, and zero or below is a field that
|
|
52
|
+
* arrived as a number without being a timestamp. What survives that can still be
|
|
53
|
+
* outside the range `Date` represents, so the instant is checked before it is
|
|
54
|
+
* rendered. The rendered text then has to satisfy `DATE_TIME` exactly as the
|
|
55
|
+
* string form does — which is what bounds the year, rather than an invented
|
|
56
|
+
* constant: an epoch rendering `'+275760-09-13T00:00:00.000Z'` is rejected here
|
|
57
|
+
* for the same reason that string would be.
|
|
58
|
+
*/
|
|
59
|
+
function fromEpochMillis(value: number, name: string): string {
|
|
60
|
+
if (!Number.isSafeInteger(value) || value <= 0) {
|
|
61
|
+
throw new MalformedPayloadError(name)
|
|
62
|
+
}
|
|
63
|
+
const instant = new Date(value)
|
|
64
|
+
if (Number.isNaN(instant.getTime())) {
|
|
65
|
+
throw new MalformedPayloadError(name)
|
|
66
|
+
}
|
|
67
|
+
const text = instant.toISOString()
|
|
68
|
+
if (!DATE_TIME.test(text)) {
|
|
69
|
+
throw new MalformedPayloadError(name)
|
|
70
|
+
}
|
|
71
|
+
return text
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* A login-flow timestamp the service guarantees, in either form it sends.
|
|
76
|
+
*
|
|
77
|
+
* The contract OpenAPI declares an ISO-8601 string and the running service
|
|
78
|
+
* sends a JSON number of epoch milliseconds, so the SDK accepts both. A number
|
|
79
|
+
* is normalised to the string form at this boundary, so every public timestamp
|
|
80
|
+
* stays one stable type no matter which form arrived. Anything that is neither
|
|
81
|
+
* form still fails closed.
|
|
82
|
+
*/
|
|
83
|
+
export function requiredDateTime(payload: Record<string, unknown>, name: string): string {
|
|
84
|
+
const raw = payload[name]
|
|
85
|
+
if (typeof raw === 'number') {
|
|
86
|
+
return fromEpochMillis(raw, name)
|
|
87
|
+
}
|
|
88
|
+
const value = requiredString(payload, name)
|
|
89
|
+
if (!DATE_TIME.test(value)) {
|
|
90
|
+
throw new MalformedPayloadError(name)
|
|
91
|
+
}
|
|
92
|
+
return value
|
|
93
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
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 JSON number grammar, applied to values that arrive as text.
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* RFC 8259's number grammar.
|
|
23
|
+
*
|
|
24
|
+
* The service sends `Money.amount` as a plain decimal JSON **string**, not a
|
|
25
|
+
* number. So the exact decimal survives
|
|
26
|
+
* `JSON.parse` untouched, and nothing on the way in checks that the text is a
|
|
27
|
+
* number at all — the OpenAPI's `type: number` describes the schema, not the
|
|
28
|
+
* wire.
|
|
29
|
+
*
|
|
30
|
+
* That makes this the **only** check on an amount rather than a second one, which
|
|
31
|
+
* is why it lives on its own rather than beside a decoder.
|
|
32
|
+
*/
|
|
33
|
+
export const JSON_NUMBER = /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?$/
|
|
@@ -0,0 +1,55 @@
|
|
|
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
|
+
import { Money } from '../models/Money'
|
|
20
|
+
import { JSON_NUMBER } from './jsonNumber'
|
|
21
|
+
import { asObject, MalformedPayloadError, requiredString } from './payload'
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Decode the shared `Money` wire shape without coercing its decimal.
|
|
25
|
+
*
|
|
26
|
+
* The service serializes `amount` as a plain decimal JSON string. Accepting a JSON number would lose precision in
|
|
27
|
+
* `JSON.parse` before this decoder could inspect it, so only an RFC 8259
|
|
28
|
+
* number-shaped string is accepted. `Money` owns redaction of the amount.
|
|
29
|
+
*/
|
|
30
|
+
export function toMoney(value: unknown, label: string): Money {
|
|
31
|
+
const payload = asObject(value, label)
|
|
32
|
+
const amount = requiredString(payload, 'amount', `${label}.amount`)
|
|
33
|
+
if (!JSON_NUMBER.test(amount)) {
|
|
34
|
+
throw new MalformedPayloadError(`${label}.amount`)
|
|
35
|
+
}
|
|
36
|
+
return new Money(amount, requiredString(payload, 'currency', `${label}.currency`))
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Decode a guaranteed money field. */
|
|
40
|
+
export function requiredMoney(payload: Record<string, unknown>, name: string): Money {
|
|
41
|
+
const value = payload[name]
|
|
42
|
+
if (value === undefined || value === null) {
|
|
43
|
+
throw new MalformedPayloadError(name)
|
|
44
|
+
}
|
|
45
|
+
return toMoney(value, name)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Decode a money field the service may omit. JSON `null` is absence. */
|
|
49
|
+
export function optionalMoney(payload: Record<string, unknown>, name: string): Money | null {
|
|
50
|
+
const value = payload[name]
|
|
51
|
+
if (value === undefined || value === null) {
|
|
52
|
+
return null
|
|
53
|
+
}
|
|
54
|
+
return toMoney(value, name)
|
|
55
|
+
}
|