@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,96 @@
|
|
|
1
|
+
// Copyright (c) 2026, Circle Internet Group, Inc. All rights reserved.
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
//
|
|
5
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
// you may not use this file except in compliance with the License.
|
|
7
|
+
// You may obtain a copy of the License at
|
|
8
|
+
//
|
|
9
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
//
|
|
11
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
// See the License for the specific language governing permissions and
|
|
15
|
+
// limitations under the License.
|
|
16
|
+
|
|
17
|
+
import DaaSdk
|
|
18
|
+
import ExpoModulesCore
|
|
19
|
+
|
|
20
|
+
// The codes match the Android bridge exactly, so the TypeScript layer maps one
|
|
21
|
+
// vocabulary. A reason, where there is one, rides in the code as
|
|
22
|
+
// "<CODE>:<Reason>". An async function's rejection reaches JS without the
|
|
23
|
+
// exception's code, and Expo wraps its message ("Calling the 'approve' function
|
|
24
|
+
// has failed → Caused by: …"), so the message also starts with the code in
|
|
25
|
+
// brackets; the TypeScript layer reads it from the innermost cause.
|
|
26
|
+
|
|
27
|
+
private func tagged(_ code: String, _ detail: String) -> String {
|
|
28
|
+
"[\(code)] \(detail)"
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
internal final class ScaCancelledException: Exception {
|
|
32
|
+
override var code: String { "SCA_CANCELLED" }
|
|
33
|
+
override var reason: String { tagged(code, "The ceremony was cancelled") }
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
internal final class ScaFailedException: Exception {
|
|
37
|
+
private let scaCode: String
|
|
38
|
+
private let detail: String
|
|
39
|
+
|
|
40
|
+
init(code: String, detail: String) {
|
|
41
|
+
self.scaCode = code
|
|
42
|
+
self.detail = detail
|
|
43
|
+
super.init()
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
override var code: String { scaCode }
|
|
47
|
+
override var reason: String { tagged(code, detail) }
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
internal final class ScaInvalidConfigurationException: Exception {
|
|
51
|
+
private let detail: String
|
|
52
|
+
|
|
53
|
+
init(_ detail: String) {
|
|
54
|
+
self.detail = detail
|
|
55
|
+
super.init()
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
override var code: String { "SCA_INVALID_CONFIGURATION" }
|
|
59
|
+
override var reason: String { tagged(code, detail) }
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
internal final class ScaCeremonyInProgressException: Exception {
|
|
63
|
+
override var code: String { "SCA_CEREMONY_IN_PROGRESS" }
|
|
64
|
+
override var reason: String { tagged(code, "Another SCA ceremony is still open") }
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
internal func mappedScaException(_ error: Error) -> Exception {
|
|
68
|
+
if let exception = error as? Exception {
|
|
69
|
+
return exception
|
|
70
|
+
}
|
|
71
|
+
guard let scaError = error as? DaaScaError else {
|
|
72
|
+
return ScaFailedException(code: "SCA_PROTOCOL", detail: "Unexpected native error")
|
|
73
|
+
}
|
|
74
|
+
switch scaError {
|
|
75
|
+
case .cancelled:
|
|
76
|
+
return ScaCancelledException()
|
|
77
|
+
case let .expired(message):
|
|
78
|
+
return ScaFailedException(code: "SCA_EXPIRED", detail: message ?? "The ceremony expired")
|
|
79
|
+
case let .unsupported(message):
|
|
80
|
+
return ScaFailedException(code: "SCA_UNSUPPORTED:PasskeyUnavailable", detail: message ?? "Passkeys are unavailable")
|
|
81
|
+
case let .alreadyEnrolled(message):
|
|
82
|
+
return ScaFailedException(code: "SCA_ALREADY_ENROLLED", detail: message ?? "A passkey is already enrolled")
|
|
83
|
+
case .stateMismatch:
|
|
84
|
+
return ScaFailedException(code: "SCA_PROTOCOL:StateMismatch", detail: "The callback did not belong to this ceremony")
|
|
85
|
+
case let .sessionUnavailable(message):
|
|
86
|
+
return ScaFailedException(code: "SCA_UNSUPPORTED:SessionUnavailable", detail: message ?? "No session could be presented")
|
|
87
|
+
case let .protocol(message):
|
|
88
|
+
// The SDK checks the frame token before opening anything; those are caller
|
|
89
|
+
// bugs, reported the same way as Android's argument checks.
|
|
90
|
+
if let message, message.hasPrefix("frameToken") {
|
|
91
|
+
return ScaFailedException(code: "SCA_PROTOCOL:InvalidFrameToken", detail: message)
|
|
92
|
+
}
|
|
93
|
+
return ScaFailedException(code: "SCA_PROTOCOL", detail: message ?? "Protocol error")
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// Copyright (c) 2026, Circle Internet Group, Inc. All rights reserved.
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
//
|
|
5
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
// you may not use this file except in compliance with the License.
|
|
7
|
+
// You may obtain a copy of the License at
|
|
8
|
+
//
|
|
9
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
//
|
|
11
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
// See the License for the specific language governing permissions and
|
|
15
|
+
// limitations under the License.
|
|
16
|
+
|
|
17
|
+
import DaaSdk
|
|
18
|
+
import ExpoModulesCore
|
|
19
|
+
import Foundation
|
|
20
|
+
|
|
21
|
+
// Thin bridge over daa-ios-sdk's `DaaSca`. No ceremony logic lives here: the
|
|
22
|
+
// native SDK opens the hosted page, validates the callback and returns the
|
|
23
|
+
// page's response text, which is passed to JS unchanged (it is the exact
|
|
24
|
+
// X-Sca-Assertion value for approve, and the registration response JSON for
|
|
25
|
+
// enroll). The bridge only translates configuration and errors.
|
|
26
|
+
|
|
27
|
+
internal struct ScaConfigRecord: Record {
|
|
28
|
+
@Field var environment: String = ""
|
|
29
|
+
@Field var redirectUri: String = ""
|
|
30
|
+
@Field var circleOrigin: String?
|
|
31
|
+
@Field var approveTimeoutMs: Double?
|
|
32
|
+
@Field var enrollTimeoutMs: Double?
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public class DaaScaModule: Module {
|
|
36
|
+
private let gate = ScaCeremonyGate()
|
|
37
|
+
|
|
38
|
+
public func definition() -> ModuleDefinition {
|
|
39
|
+
Name("DaaSca")
|
|
40
|
+
|
|
41
|
+
AsyncFunction("capabilities") { (config: ScaConfigRecord) async throws -> [String: Any] in
|
|
42
|
+
let configuration = try scaConfiguration(config)
|
|
43
|
+
return await MainActor.run {
|
|
44
|
+
let capabilities = DaaSca(configuration: configuration).capabilities()
|
|
45
|
+
return [
|
|
46
|
+
"protocolVersion": capabilities.protocolVersion,
|
|
47
|
+
"surface": capabilities.surface == .webAuthenticationSession ? "webAuthenticationSession" : "none",
|
|
48
|
+
"callbackReady": capabilities.callbackSupported,
|
|
49
|
+
"platformPasskeys": capabilities.platformPasskeys,
|
|
50
|
+
"ceremonySupported": capabilities.isCeremonySupported,
|
|
51
|
+
]
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
AsyncFunction("approve") { (config: ScaConfigRecord, frameToken: String) async throws -> String in
|
|
56
|
+
try await self.run(config) { sca in try await sca.approve(frameToken: frameToken) }
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
AsyncFunction("enroll") { (config: ScaConfigRecord, frameToken: String) async throws -> String in
|
|
60
|
+
try await self.run(config) { sca in try await sca.enroll(frameToken: frameToken) }
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// One ceremony at a time across the whole app. The native SDK replaces an open
|
|
65
|
+
// ceremony when a second starts on the same instance; the bridge refuses the
|
|
66
|
+
// second call up front instead, so both platforms behave the same in JS.
|
|
67
|
+
private func run(
|
|
68
|
+
_ config: ScaConfigRecord,
|
|
69
|
+
_ ceremony: @escaping @MainActor (DaaSca) async throws -> String
|
|
70
|
+
) async throws -> String {
|
|
71
|
+
let configuration = try scaConfiguration(config)
|
|
72
|
+
guard gate.enter() else {
|
|
73
|
+
throw ScaCeremonyInProgressException()
|
|
74
|
+
}
|
|
75
|
+
defer { gate.leave() }
|
|
76
|
+
do {
|
|
77
|
+
return try await Task { @MainActor in
|
|
78
|
+
try await ceremony(DaaSca(configuration: configuration))
|
|
79
|
+
}.value
|
|
80
|
+
} catch {
|
|
81
|
+
throw mappedScaException(error)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
private func scaConfiguration(_ config: ScaConfigRecord) throws -> DaaScaConfiguration {
|
|
87
|
+
// Only the public environments; any other Circle host goes through
|
|
88
|
+
// `circleOrigin`, which the native configuration validates.
|
|
89
|
+
let environment: DaaEnvironment
|
|
90
|
+
switch config.environment {
|
|
91
|
+
case "sandbox": environment = .sandbox
|
|
92
|
+
case "production": environment = .production
|
|
93
|
+
default: throw ScaInvalidConfigurationException("environment must be 'sandbox' or 'production'")
|
|
94
|
+
}
|
|
95
|
+
do {
|
|
96
|
+
return try DaaScaConfiguration(
|
|
97
|
+
environment: environment,
|
|
98
|
+
redirectURI: config.redirectUri,
|
|
99
|
+
circleOrigin: config.circleOrigin,
|
|
100
|
+
approveTimeout: (config.approveTimeoutMs.map { $0 / 1000 }) ?? DaaScaConfiguration.defaultApproveTimeout,
|
|
101
|
+
enrollTimeout: (config.enrollTimeoutMs.map { $0 / 1000 }) ?? DaaScaConfiguration.defaultEnrollTimeout
|
|
102
|
+
)
|
|
103
|
+
} catch let error as DaaScaConfigurationError {
|
|
104
|
+
throw ScaInvalidConfigurationException(String(describing: error))
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
private final class ScaCeremonyGate: @unchecked Sendable {
|
|
109
|
+
private let lock = NSLock()
|
|
110
|
+
private var open = false
|
|
111
|
+
|
|
112
|
+
func enter() -> Bool {
|
|
113
|
+
lock.lock()
|
|
114
|
+
defer { lock.unlock() }
|
|
115
|
+
guard !open else { return false }
|
|
116
|
+
open = true
|
|
117
|
+
return true
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
func leave() {
|
|
121
|
+
lock.lock()
|
|
122
|
+
open = false
|
|
123
|
+
lock.unlock()
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// Copyright (c) 2026, Circle Internet Group, Inc. All rights reserved.
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
//
|
|
5
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
// you may not use this file except in compliance with the License.
|
|
7
|
+
// You may obtain a copy of the License at
|
|
8
|
+
//
|
|
9
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
//
|
|
11
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
// See the License for the specific language governing permissions and
|
|
15
|
+
// limitations under the License.
|
|
16
|
+
|
|
17
|
+
import DaaSdk
|
|
18
|
+
import ExpoModulesCore
|
|
19
|
+
|
|
20
|
+
// Stable `code` values for mapNativeError. Reasons are canned — never copy
|
|
21
|
+
// Keychain / Secure Enclave text into the JS message.
|
|
22
|
+
//
|
|
23
|
+
// Every function this module exposes is async, and an async function's
|
|
24
|
+
// rejection reaches JS without the exception's code (Expo wraps it as
|
|
25
|
+
// "Calling the '…' function has failed → Caused by: …"), so each reason also
|
|
26
|
+
// starts with its code in brackets. mapNativeError reads that tag from the
|
|
27
|
+
// innermost cause when no known code survives — the same rule DaaSca uses
|
|
28
|
+
// (see DaaScaExceptions.swift).
|
|
29
|
+
|
|
30
|
+
private func secureKeyReason(_ code: String, _ detail: String) -> String {
|
|
31
|
+
"[\(code)] \(detail)"
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
internal final class UserAuthRequiredException: Exception, @unchecked Sendable {
|
|
35
|
+
override var code: String { "USER_AUTH_REQUIRED" }
|
|
36
|
+
override var reason: String { secureKeyReason(code, "User authentication is required") }
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// The user dismissed the LocalAuthentication prompt. Kept distinct from
|
|
40
|
+
// USER_AUTH_REQUIRED: a cancel is the user's choice, not a credential problem,
|
|
41
|
+
// and the TypeScript side reports it as `user_cancelled`.
|
|
42
|
+
internal final class UserCancelledException: Exception, @unchecked Sendable {
|
|
43
|
+
override var code: String { "USER_CANCELLED" }
|
|
44
|
+
override var reason: String { secureKeyReason(code, "User authentication was cancelled") }
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
internal final class NotInitializedException: Exception, @unchecked Sendable {
|
|
48
|
+
override var code: String { "NOT_INITIALIZED" }
|
|
49
|
+
override var reason: String { secureKeyReason(code, "Secure key is not initialized") }
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// No passcode is set, so no device key can be created. The user fixes it in
|
|
53
|
+
// Settings; retrying does not help.
|
|
54
|
+
internal final class DeviceLockNotSetException: Exception, @unchecked Sendable {
|
|
55
|
+
override var code: String { "DEVICE_LOCK_NOT_SET" }
|
|
56
|
+
override var reason: String { secureKeyReason(code, "The device has no passcode set") }
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// No Secure Enclave on this device (or simulator runtime), so it can never hold
|
|
60
|
+
// a device key.
|
|
61
|
+
internal final class DeviceNotSupportedException: Exception, @unchecked Sendable {
|
|
62
|
+
override var code: String { "DEVICE_NOT_SUPPORTED" }
|
|
63
|
+
override var reason: String { secureKeyReason(code, "The device has no secure hardware for a device key") }
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// The typed matching code is not the code the approval body and code secret
|
|
67
|
+
// produce. Checked before the Face ID / Touch ID prompt; the user can type it
|
|
68
|
+
// again.
|
|
69
|
+
internal final class MatchingCodeMismatchException: Exception, @unchecked Sendable {
|
|
70
|
+
override var code: String { "MATCHING_CODE_MISMATCH" }
|
|
71
|
+
override var reason: String { secureKeyReason(code, "The typed code is not the matching code") }
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
internal final class ContractViolationException: Exception, @unchecked Sendable {
|
|
75
|
+
override var code: String { "CONTRACT_VIOLATION" }
|
|
76
|
+
override var reason: String { secureKeyReason(code, "Native secure-key operation failed") }
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
internal func mappedSecureKeyException(_ error: Error) -> Exception {
|
|
80
|
+
if let exception = error as? Exception {
|
|
81
|
+
return exception
|
|
82
|
+
}
|
|
83
|
+
guard let keyError = error as? DaaSecureKeyError else {
|
|
84
|
+
return ContractViolationException()
|
|
85
|
+
}
|
|
86
|
+
switch keyError {
|
|
87
|
+
case .userCancelled:
|
|
88
|
+
return UserCancelledException()
|
|
89
|
+
case .authenticationFailed, .deviceLocked:
|
|
90
|
+
return UserAuthRequiredException()
|
|
91
|
+
case .devicePasscodeNotSet:
|
|
92
|
+
return DeviceLockNotSetException()
|
|
93
|
+
case .secureEnclaveUnavailable:
|
|
94
|
+
return DeviceNotSupportedException()
|
|
95
|
+
case .keyNotFound, .resolutionRequired:
|
|
96
|
+
return NotInitializedException()
|
|
97
|
+
case .matchingCodeMismatch:
|
|
98
|
+
return MatchingCodeMismatchException()
|
|
99
|
+
case .invalidAppID,
|
|
100
|
+
.invalidKeychainAccessGroup,
|
|
101
|
+
.invalidSigningInput,
|
|
102
|
+
.keyCreationFailed,
|
|
103
|
+
.keyAccessFailed,
|
|
104
|
+
.keychainEntitlementMissing,
|
|
105
|
+
.keyMetadataUnavailable,
|
|
106
|
+
.keyMetadataVersionUnsupported,
|
|
107
|
+
.protectionMismatch,
|
|
108
|
+
.publicKeyUnavailable,
|
|
109
|
+
.operationCancelled,
|
|
110
|
+
.signingAlgorithmUnavailable,
|
|
111
|
+
.signingFailed,
|
|
112
|
+
.authKeyRegistrationRequired,
|
|
113
|
+
// protectionUnavailable is thrown for a DeviceUnlocked-protected key
|
|
114
|
+
// signing a consequential operation — DeviceUnlocked itself is gated
|
|
115
|
+
// behind @_spi, which this bridge never imports, so this is unreachable
|
|
116
|
+
// from RN, same as the other cases in this bucket.
|
|
117
|
+
// authKeyThumbprintMismatch is thrown when a registration device
|
|
118
|
+
// proof's header jwk is not the signing key's own (its RFC 7638
|
|
119
|
+
// thumbprint differs) — an upstream contract violation, not something
|
|
120
|
+
// to retry.
|
|
121
|
+
.protectionUnavailable,
|
|
122
|
+
.authKeyThumbprintMismatch:
|
|
123
|
+
return ContractViolationException()
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
// Copyright (c) 2026, Circle Internet Group, Inc. All rights reserved.
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
//
|
|
5
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
// you may not use this file except in compliance with the License.
|
|
7
|
+
// You may obtain a copy of the License at
|
|
8
|
+
//
|
|
9
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
//
|
|
11
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
// See the License for the specific language governing permissions and
|
|
15
|
+
// limitations under the License.
|
|
16
|
+
|
|
17
|
+
import DaaSdk
|
|
18
|
+
import ExpoModulesCore
|
|
19
|
+
import Foundation
|
|
20
|
+
|
|
21
|
+
public class DaaSecureKeyModule: Module, @unchecked Sendable {
|
|
22
|
+
private let cache = SecureKeyCache()
|
|
23
|
+
|
|
24
|
+
public func definition() -> ModuleDefinition {
|
|
25
|
+
Name("DaaSecureKey")
|
|
26
|
+
let cache = self.cache
|
|
27
|
+
|
|
28
|
+
// Mirrors `DEVICE_KEY_POLICY` in src/config.ts. This is a compiled-in
|
|
29
|
+
// constant, not a live readback of a specific key's real Secure Enclave
|
|
30
|
+
// protection: it is a version-skew guard between this module and the
|
|
31
|
+
// TypeScript it ships with, so a mismatch means the two disagree about
|
|
32
|
+
// the closed set, not that a key was inspected and found wanting. No
|
|
33
|
+
// Keychain/Security API exposes the true `SecAccessControl` of an
|
|
34
|
+
// existing key on iOS, so daa-ios-sdk's public `SecureKey` has no real
|
|
35
|
+
// readback to expose here even in principle.
|
|
36
|
+
Function("declaredKeyPolicy") { () -> [String: Any] in
|
|
37
|
+
[
|
|
38
|
+
"hardwareBacked": true,
|
|
39
|
+
"userVerification": "REQUIRED_FOR_EACH_SIGNATURE",
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
AsyncFunction("resolveOrCreate") { (appId: String, environment: String) async throws -> String in
|
|
44
|
+
do {
|
|
45
|
+
let key = try await cache.secureKey(appId: appId, environment: environment)
|
|
46
|
+
let resolution = try await key.resolveOrCreate()
|
|
47
|
+
switch resolution {
|
|
48
|
+
case .created:
|
|
49
|
+
return "created"
|
|
50
|
+
case .existing:
|
|
51
|
+
return "existing"
|
|
52
|
+
}
|
|
53
|
+
} catch {
|
|
54
|
+
throw mappedSecureKeyException(error)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
AsyncFunction("publicKeySpkiBase64Url") { (appId: String, environment: String) async throws -> String in
|
|
59
|
+
do {
|
|
60
|
+
let key = try await cache.secureKey(appId: appId, environment: environment)
|
|
61
|
+
return try await key.publicKeySPKIBase64URL()
|
|
62
|
+
} catch {
|
|
63
|
+
throw mappedSecureKeyException(error)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Reached from OwnerAuthKey.acknowledgeRegistration(registration) via the
|
|
68
|
+
// TS bridge. This is the only registration-ack entry point; do not add a
|
|
69
|
+
// parallel one. Native always upserts the identifiers into the durable
|
|
70
|
+
// registration record, so a re-registration that assigned new ones
|
|
71
|
+
// replaces the old ones. The deprecated no-identifier variant is not
|
|
72
|
+
// reached: it records nothing resolveExisting could return.
|
|
73
|
+
AsyncFunction("acknowledgeRegistration") { (
|
|
74
|
+
appId: String,
|
|
75
|
+
environment: String,
|
|
76
|
+
authKeyId: String,
|
|
77
|
+
ownerBindingId: String
|
|
78
|
+
) async throws in
|
|
79
|
+
do {
|
|
80
|
+
let key = try await cache.secureKey(appId: appId, environment: environment)
|
|
81
|
+
try await key.acknowledgeRegistration(
|
|
82
|
+
authKeyId: authKeyId,
|
|
83
|
+
ownerBindingId: ownerBindingId
|
|
84
|
+
)
|
|
85
|
+
} catch {
|
|
86
|
+
throw mappedSecureKeyException(error)
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Read-only lookup: never mints a key and never shows a
|
|
91
|
+
// LocalAuthentication prompt. Returns the registration record, or nil
|
|
92
|
+
// (JS null) when there is no key or it has no recorded identifiers.
|
|
93
|
+
AsyncFunction("resolveExisting") { (appId: String, environment: String) async throws -> [String: String]? in
|
|
94
|
+
do {
|
|
95
|
+
// existingSecureKey, not secureKey: this lookup must not mint an
|
|
96
|
+
// installation ID, or replace a malformed one, on its way to "no key".
|
|
97
|
+
guard let key = try await cache.existingSecureKey(appId: appId, environment: environment),
|
|
98
|
+
let registered = try await key.resolveExisting()
|
|
99
|
+
else {
|
|
100
|
+
return nil
|
|
101
|
+
}
|
|
102
|
+
return [
|
|
103
|
+
"authKeyId": registered.authKeyId,
|
|
104
|
+
"ownerBindingId": registered.ownerBindingId,
|
|
105
|
+
]
|
|
106
|
+
} catch {
|
|
107
|
+
throw mappedSecureKeyException(error)
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Explicit, user-initiated local delete of the key and its metadata. Local
|
|
112
|
+
// only: it does not revoke the key with Circle. Idempotent.
|
|
113
|
+
AsyncFunction("forgetLocalKey") { (appId: String, environment: String) async throws in
|
|
114
|
+
do {
|
|
115
|
+
// existingSecureKey, not secureKey: a delete must not mint an
|
|
116
|
+
// installation ID. With none, no key can exist, so there is nothing
|
|
117
|
+
// to delete.
|
|
118
|
+
guard let key = try await cache.existingSecureKey(appId: appId, environment: environment) else {
|
|
119
|
+
return
|
|
120
|
+
}
|
|
121
|
+
try await key.forgetLocalKey()
|
|
122
|
+
} catch {
|
|
123
|
+
throw mappedSecureKeyException(error)
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Typed native signDeviceAuthorization — not a generic sign(bytes). The
|
|
128
|
+
// Base64URL payload is the exact compact-JWS signing input already built in
|
|
129
|
+
// TypeScript; native validates those bytes and signs that same slice.
|
|
130
|
+
// There is no prompt argument: DaaSdk sets all of the Face ID / Touch ID
|
|
131
|
+
// text from the validated operation, and nothing here can change it.
|
|
132
|
+
AsyncFunction("signDeviceAuthorization") { (
|
|
133
|
+
appId: String,
|
|
134
|
+
environment: String,
|
|
135
|
+
signingInputBase64Url: String
|
|
136
|
+
) async throws -> String in
|
|
137
|
+
do {
|
|
138
|
+
let exactBytes = try decodeUnpaddedBase64URL(signingInputBase64Url)
|
|
139
|
+
let signingInput = try DaaDeviceAuthorizationSigningInput(exactBytes: exactBytes)
|
|
140
|
+
let key = try await cache.secureKey(appId: appId, environment: environment)
|
|
141
|
+
let signature = try await key.signDeviceAuthorization(signingInput: signingInput)
|
|
142
|
+
return unpaddedBase64URL(signature)
|
|
143
|
+
} catch {
|
|
144
|
+
throw mappedSecureKeyException(error)
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Typed native device approval — signDeviceAuthorization with the
|
|
149
|
+
// approve_device initializer of DaaDeviceAuthorizationSigningInput, which
|
|
150
|
+
// checks that the approval body is the one the signing input commits to,
|
|
151
|
+
// that the code secret opens its codeSeal, and that enteredCode is the
|
|
152
|
+
// code they produce, all before the Face ID / Touch ID prompt. A wrong
|
|
153
|
+
// code throws matchingCodeMismatch (MATCHING_CODE_MISMATCH). The prompt
|
|
154
|
+
// shows the code; nothing here sets its text.
|
|
155
|
+
AsyncFunction("signDeviceApproval") { (
|
|
156
|
+
appId: String,
|
|
157
|
+
environment: String,
|
|
158
|
+
signingInputBase64Url: String,
|
|
159
|
+
requestBodyBase64Url: String,
|
|
160
|
+
codeSecretBase64Url: String,
|
|
161
|
+
enteredCode: String
|
|
162
|
+
) async throws -> String in
|
|
163
|
+
do {
|
|
164
|
+
let signingInput = try DaaDeviceAuthorizationSigningInput(
|
|
165
|
+
exactBytes: try decodeUnpaddedBase64URL(signingInputBase64Url),
|
|
166
|
+
approvalRequestBody: try decodeUnpaddedBase64URL(requestBodyBase64Url),
|
|
167
|
+
codeSecret: try decodeUnpaddedBase64URL(codeSecretBase64Url),
|
|
168
|
+
enteredCode: enteredCode
|
|
169
|
+
)
|
|
170
|
+
let key = try await cache.secureKey(appId: appId, environment: environment)
|
|
171
|
+
let signature = try await key.signDeviceAuthorization(signingInput: signingInput)
|
|
172
|
+
return unpaddedBase64URL(signature)
|
|
173
|
+
} catch {
|
|
174
|
+
throw mappedSecureKeyException(error)
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// The key's add-a-device code secret, kept in the Keychain across
|
|
179
|
+
// restarts. Never prompts. Only the unsent-secret half of DaaSdk's API is
|
|
180
|
+
// bridged: once the TS side sends a secret it deletes it here, and keeps
|
|
181
|
+
// the sent copy in process memory only.
|
|
182
|
+
AsyncFunction("codeSecret") { (appId: String, environment: String) async throws -> String in
|
|
183
|
+
do {
|
|
184
|
+
let key = try await cache.secureKey(appId: appId, environment: environment)
|
|
185
|
+
return unpaddedBase64URL(try await key.codeSecret())
|
|
186
|
+
} catch {
|
|
187
|
+
throw mappedSecureKeyException(error)
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Deletes the stored code secret only when it equals these bytes.
|
|
192
|
+
AsyncFunction("deleteCodeSecret") { (
|
|
193
|
+
appId: String,
|
|
194
|
+
environment: String,
|
|
195
|
+
secretBase64Url: String
|
|
196
|
+
) async throws in
|
|
197
|
+
do {
|
|
198
|
+
let secret = try decodeUnpaddedBase64URL(secretBase64Url)
|
|
199
|
+
// existingSecureKey, not secureKey: a delete must not mint an
|
|
200
|
+
// installation ID. With none, no key or secret can exist.
|
|
201
|
+
guard let key = try await cache.existingSecureKey(appId: appId, environment: environment) else {
|
|
202
|
+
return
|
|
203
|
+
}
|
|
204
|
+
try await key.deleteCodeSecret(secret)
|
|
205
|
+
} catch {
|
|
206
|
+
throw mappedSecureKeyException(error)
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Typed native signRegistrationDeviceAuthorization — the registration
|
|
211
|
+
// counterpart of signDeviceAuthorization above, NOT the same call. The
|
|
212
|
+
// Base64URL payload is the exact Device Registration Complete device-proof
|
|
213
|
+
// signing input from `auth/registrationAuthorization.ts`; it is validated
|
|
214
|
+
// by DaaRegistrationAuthorizationSigningInput, a different validator from
|
|
215
|
+
// DaaDeviceAuthorizationSigningInput (registration `typ`s, an embedded
|
|
216
|
+
// JWK header, no acknowledged-key gate). Do not route this input through
|
|
217
|
+
// signDeviceAuthorization above, and do not route that input through here.
|
|
218
|
+
// Like signDeviceAuthorization, it takes no prompt: DaaSdk shows its own
|
|
219
|
+
// device-registration prompt text.
|
|
220
|
+
AsyncFunction("signRegistrationDeviceAuthorization") { (
|
|
221
|
+
appId: String,
|
|
222
|
+
environment: String,
|
|
223
|
+
signingInputBase64Url: String
|
|
224
|
+
) async throws -> String in
|
|
225
|
+
do {
|
|
226
|
+
let exactBytes = try decodeUnpaddedBase64URL(signingInputBase64Url)
|
|
227
|
+
let signingInput = try DaaRegistrationAuthorizationSigningInput(exactBytes: exactBytes)
|
|
228
|
+
let key = try await cache.secureKey(appId: appId, environment: environment)
|
|
229
|
+
let signature = try await key.signRegistrationDeviceAuthorization(signingInput: signingInput)
|
|
230
|
+
return unpaddedBase64URL(signature)
|
|
231
|
+
} catch {
|
|
232
|
+
throw mappedSecureKeyException(error)
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
private actor SecureKeyCache {
|
|
239
|
+
private var keys: [String: DaaSecureKey] = [:]
|
|
240
|
+
private var installationID: UUID?
|
|
241
|
+
|
|
242
|
+
func secureKey(appId: String, environment raw: String) throws -> DaaSecureKey {
|
|
243
|
+
guard let key = try resolveKey(appId: appId, environment: raw, mintInstallationID: true) else {
|
|
244
|
+
throw ContractViolationException()
|
|
245
|
+
}
|
|
246
|
+
return key
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// For resolveExisting: like secureKey, but never mints or replaces the
|
|
250
|
+
// installation ID. nil when this install has none yet, so no key can exist.
|
|
251
|
+
func existingSecureKey(appId: String, environment raw: String) throws -> DaaSecureKey? {
|
|
252
|
+
try resolveKey(appId: appId, environment: raw, mintInstallationID: false)
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
private func resolveKey(appId: String, environment raw: String, mintInstallationID: Bool) throws -> DaaSecureKey? {
|
|
256
|
+
guard let environment = DaaEnvironment(rawValue: raw) else {
|
|
257
|
+
throw ContractViolationException()
|
|
258
|
+
}
|
|
259
|
+
let alias = "\(appId).\(environment.rawValue)"
|
|
260
|
+
if let existing = keys[alias] {
|
|
261
|
+
return existing
|
|
262
|
+
}
|
|
263
|
+
let installationID: UUID? = try mintInstallationID ? installationUUID() : existingInstallationUUID()
|
|
264
|
+
guard let installationID else {
|
|
265
|
+
return nil
|
|
266
|
+
}
|
|
267
|
+
let identity = try DaaAuthKeyIdentity(
|
|
268
|
+
appID: appId,
|
|
269
|
+
environment: environment,
|
|
270
|
+
installationID: installationID
|
|
271
|
+
)
|
|
272
|
+
let key = DaaSecureKey(identity: identity)
|
|
273
|
+
keys[alias] = key
|
|
274
|
+
return key
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
private func installationUUID() throws -> UUID {
|
|
278
|
+
if let installationID {
|
|
279
|
+
return installationID
|
|
280
|
+
}
|
|
281
|
+
let id: UUID
|
|
282
|
+
do {
|
|
283
|
+
id = try InstallationIdentityStore.live().loadOrCreate()
|
|
284
|
+
} catch {
|
|
285
|
+
throw ContractViolationException()
|
|
286
|
+
}
|
|
287
|
+
installationID = id
|
|
288
|
+
return id
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
private func existingInstallationUUID() throws -> UUID? {
|
|
292
|
+
if let installationID {
|
|
293
|
+
return installationID
|
|
294
|
+
}
|
|
295
|
+
let id: UUID?
|
|
296
|
+
do {
|
|
297
|
+
id = try InstallationIdentityStore.live().loadExisting()
|
|
298
|
+
} catch {
|
|
299
|
+
throw ContractViolationException()
|
|
300
|
+
}
|
|
301
|
+
if let id {
|
|
302
|
+
installationID = id
|
|
303
|
+
}
|
|
304
|
+
return id
|
|
305
|
+
}
|
|
306
|
+
}
|