@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,77 @@
|
|
|
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
|
+
internal final class UserAuthRequiredException: Exception, @unchecked Sendable {
|
|
24
|
+
override var code: String { "USER_AUTH_REQUIRED" }
|
|
25
|
+
override var reason: String { "User authentication is required" }
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
internal final class NotInitializedException: Exception, @unchecked Sendable {
|
|
29
|
+
override var code: String { "NOT_INITIALIZED" }
|
|
30
|
+
override var reason: String { "Secure key is not initialized" }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
internal final class ContractViolationException: Exception, @unchecked Sendable {
|
|
34
|
+
override var code: String { "CONTRACT_VIOLATION" }
|
|
35
|
+
override var reason: String { "Native secure-key operation failed" }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
internal func mappedSecureKeyException(_ error: Error) -> Exception {
|
|
39
|
+
if let exception = error as? Exception {
|
|
40
|
+
return exception
|
|
41
|
+
}
|
|
42
|
+
guard let keyError = error as? DaaSecureKeyError else {
|
|
43
|
+
return ContractViolationException()
|
|
44
|
+
}
|
|
45
|
+
switch keyError {
|
|
46
|
+
case .authenticationFailed, .userCancelled, .deviceLocked, .devicePasscodeNotSet:
|
|
47
|
+
return UserAuthRequiredException()
|
|
48
|
+
case .keyNotFound, .resolutionRequired:
|
|
49
|
+
return NotInitializedException()
|
|
50
|
+
case .invalidAppID,
|
|
51
|
+
.invalidKeychainAccessGroup,
|
|
52
|
+
.invalidSigningInput,
|
|
53
|
+
.secureEnclaveUnavailable,
|
|
54
|
+
.keyCreationFailed,
|
|
55
|
+
.keyAccessFailed,
|
|
56
|
+
.keychainEntitlementMissing,
|
|
57
|
+
.keyMetadataUnavailable,
|
|
58
|
+
.keyMetadataVersionUnsupported,
|
|
59
|
+
.protectionMismatch,
|
|
60
|
+
.publicKeyUnavailable,
|
|
61
|
+
.operationCancelled,
|
|
62
|
+
.signingAlgorithmUnavailable,
|
|
63
|
+
.signingFailed,
|
|
64
|
+
.authKeyRegistrationRequired,
|
|
65
|
+
// protectionUnavailable is thrown for a DeviceUnlocked-protected key
|
|
66
|
+
// signing a consequential operation — DeviceUnlocked itself is gated
|
|
67
|
+
// behind @_spi, which this bridge never imports, so this is unreachable
|
|
68
|
+
// from RN, same as the other cases in this bucket.
|
|
69
|
+
// authKeyThumbprintMismatch is thrown when a registration device
|
|
70
|
+
// proof's header jwk is not the signing key's own (its RFC 7638
|
|
71
|
+
// thumbprint differs) — an upstream contract violation, not something
|
|
72
|
+
// to retry.
|
|
73
|
+
.protectionUnavailable,
|
|
74
|
+
.authKeyThumbprintMismatch:
|
|
75
|
+
return ContractViolationException()
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
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() via the TS bridge.
|
|
68
|
+
// This is the only registration-ack entry point; do not add a parallel one.
|
|
69
|
+
AsyncFunction("acknowledgeRegistration") { (appId: String, environment: String) async throws in
|
|
70
|
+
do {
|
|
71
|
+
let key = try await cache.secureKey(appId: appId, environment: environment)
|
|
72
|
+
try await key.acknowledgeRegistration()
|
|
73
|
+
} catch {
|
|
74
|
+
throw mappedSecureKeyException(error)
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Typed native signDeviceAuthorization — not a generic sign(bytes). The
|
|
79
|
+
// Base64URL payload is the exact compact-JWS signing input already built in
|
|
80
|
+
// TypeScript; native validates those bytes and signs that same slice.
|
|
81
|
+
// There is no prompt argument: DaaSdk sets all of the Face ID / Touch ID
|
|
82
|
+
// text from the validated operation, and nothing here can change it.
|
|
83
|
+
AsyncFunction("signDeviceAuthorization") { (
|
|
84
|
+
appId: String,
|
|
85
|
+
environment: String,
|
|
86
|
+
signingInputBase64Url: String
|
|
87
|
+
) async throws -> String in
|
|
88
|
+
do {
|
|
89
|
+
let exactBytes = try decodeUnpaddedBase64URL(signingInputBase64Url)
|
|
90
|
+
let signingInput = try DaaDeviceAuthorizationSigningInput(exactBytes: exactBytes)
|
|
91
|
+
let key = try await cache.secureKey(appId: appId, environment: environment)
|
|
92
|
+
let signature = try await key.signDeviceAuthorization(signingInput: signingInput)
|
|
93
|
+
return unpaddedBase64URL(signature)
|
|
94
|
+
} catch {
|
|
95
|
+
throw mappedSecureKeyException(error)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Typed native signRegistrationDeviceAuthorization — the registration
|
|
100
|
+
// counterpart of signDeviceAuthorization above, NOT the same call. The
|
|
101
|
+
// Base64URL payload is the exact Device Registration Complete device-proof
|
|
102
|
+
// signing input from `auth/registrationAuthorization.ts`; it is validated
|
|
103
|
+
// by DaaRegistrationAuthorizationSigningInput, a different validator from
|
|
104
|
+
// DaaDeviceAuthorizationSigningInput (registration `typ`s, an embedded
|
|
105
|
+
// JWK header, no acknowledged-key gate). Do not route this input through
|
|
106
|
+
// signDeviceAuthorization above, and do not route that input through here.
|
|
107
|
+
// Like signDeviceAuthorization, it takes no prompt: DaaSdk shows its own
|
|
108
|
+
// device-registration prompt text.
|
|
109
|
+
AsyncFunction("signRegistrationDeviceAuthorization") { (
|
|
110
|
+
appId: String,
|
|
111
|
+
environment: String,
|
|
112
|
+
signingInputBase64Url: String
|
|
113
|
+
) async throws -> String in
|
|
114
|
+
do {
|
|
115
|
+
let exactBytes = try decodeUnpaddedBase64URL(signingInputBase64Url)
|
|
116
|
+
let signingInput = try DaaRegistrationAuthorizationSigningInput(exactBytes: exactBytes)
|
|
117
|
+
let key = try await cache.secureKey(appId: appId, environment: environment)
|
|
118
|
+
let signature = try await key.signRegistrationDeviceAuthorization(signingInput: signingInput)
|
|
119
|
+
return unpaddedBase64URL(signature)
|
|
120
|
+
} catch {
|
|
121
|
+
throw mappedSecureKeyException(error)
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
private actor SecureKeyCache {
|
|
128
|
+
private var keys: [String: DaaSecureKey] = [:]
|
|
129
|
+
private var installationID: UUID?
|
|
130
|
+
|
|
131
|
+
func secureKey(appId: String, environment raw: String) throws -> DaaSecureKey {
|
|
132
|
+
guard let environment = DaaEnvironment(rawValue: raw) else {
|
|
133
|
+
throw ContractViolationException()
|
|
134
|
+
}
|
|
135
|
+
let alias = "\(appId).\(environment.rawValue)"
|
|
136
|
+
if let existing = keys[alias] {
|
|
137
|
+
return existing
|
|
138
|
+
}
|
|
139
|
+
let identity = try DaaAuthKeyIdentity(
|
|
140
|
+
appID: appId,
|
|
141
|
+
environment: environment,
|
|
142
|
+
installationID: try installationUUID()
|
|
143
|
+
)
|
|
144
|
+
let key = DaaSecureKey(identity: identity)
|
|
145
|
+
keys[alias] = key
|
|
146
|
+
return key
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
private func installationUUID() throws -> UUID {
|
|
150
|
+
if let installationID {
|
|
151
|
+
return installationID
|
|
152
|
+
}
|
|
153
|
+
let id: UUID
|
|
154
|
+
do {
|
|
155
|
+
id = try InstallationIdentityStore.live().loadOrCreate()
|
|
156
|
+
} catch {
|
|
157
|
+
throw ContractViolationException()
|
|
158
|
+
}
|
|
159
|
+
installationID = id
|
|
160
|
+
return id
|
|
161
|
+
}
|
|
162
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
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 Foundation
|
|
18
|
+
|
|
19
|
+
// Durable per-install UUID for DaaAuthKeyIdentity.installationID.
|
|
20
|
+
// Native docs: the caller persists the UUID; a new install gets a new UUID.
|
|
21
|
+
//
|
|
22
|
+
// Stored as a file in the app container's Application Support directory,
|
|
23
|
+
// excluded from backup. The container survives app updates and is deleted
|
|
24
|
+
// when the app is deleted, so a reinstall mints a new UUID and therefore a
|
|
25
|
+
// new Enclave AuthKey — the same lifetime Android gets from noBackupFilesDir.
|
|
26
|
+
// Excluding it from backup keeps a restore onto another device (or the same
|
|
27
|
+
// device after an erase) from carrying the UUID over. UserDefaults is not
|
|
28
|
+
// used because it is always included in backups. The Keychain is not used
|
|
29
|
+
// because iOS does not reliably purge it when the app is deleted.
|
|
30
|
+
//
|
|
31
|
+
// Keys minted under an earlier installation UUID stay in this app's Keychain
|
|
32
|
+
// access group: they are unreachable from this store, and they are not
|
|
33
|
+
// deleted here or revoked at Circle.
|
|
34
|
+
|
|
35
|
+
enum InstallationIdentityStoreError: Error, Equatable {
|
|
36
|
+
case applicationSupportUnavailable
|
|
37
|
+
case unreadable
|
|
38
|
+
case unwritable
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
struct InstallationIdentityStore {
|
|
42
|
+
static let fileName = "installation-id.v1"
|
|
43
|
+
private static let directoryName = "com.circle.daa.reactnative"
|
|
44
|
+
// Process-wide: concurrent first runs must not each write a different UUID.
|
|
45
|
+
private static let lock = NSLock()
|
|
46
|
+
|
|
47
|
+
let directory: URL
|
|
48
|
+
|
|
49
|
+
static func live() throws -> InstallationIdentityStore {
|
|
50
|
+
guard let applicationSupport = try? FileManager.default.url(
|
|
51
|
+
for: .applicationSupportDirectory,
|
|
52
|
+
in: .userDomainMask,
|
|
53
|
+
appropriateFor: nil,
|
|
54
|
+
create: true
|
|
55
|
+
) else {
|
|
56
|
+
throw InstallationIdentityStoreError.applicationSupportUnavailable
|
|
57
|
+
}
|
|
58
|
+
return InstallationIdentityStore(
|
|
59
|
+
directory: applicationSupport.appendingPathComponent(directoryName, isDirectory: true)
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
func loadOrCreate() throws -> UUID {
|
|
64
|
+
Self.lock.lock()
|
|
65
|
+
defer { Self.lock.unlock() }
|
|
66
|
+
|
|
67
|
+
let file = directory.appendingPathComponent(Self.fileName, isDirectory: false)
|
|
68
|
+
if let existing = try read(file) {
|
|
69
|
+
return existing
|
|
70
|
+
}
|
|
71
|
+
let id = UUID()
|
|
72
|
+
try write(id, to: file)
|
|
73
|
+
return id
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
private func read(_ file: URL) throws -> UUID? {
|
|
77
|
+
guard FileManager.default.fileExists(atPath: file.path) else {
|
|
78
|
+
return nil
|
|
79
|
+
}
|
|
80
|
+
let data: Data
|
|
81
|
+
do {
|
|
82
|
+
data = try Data(contentsOf: file)
|
|
83
|
+
} catch {
|
|
84
|
+
// Present but unreadable (for example before the first unlock after
|
|
85
|
+
// boot): fail and let the next call retry. Never remint over it.
|
|
86
|
+
throw InstallationIdentityStoreError.unreadable
|
|
87
|
+
}
|
|
88
|
+
guard let string = String(data: data, encoding: .utf8),
|
|
89
|
+
let id = UUID(uuidString: string.trimmingCharacters(in: .whitespacesAndNewlines))
|
|
90
|
+
else {
|
|
91
|
+
// Malformed file: delete and remint. The previous Enclave key is not
|
|
92
|
+
// deleted and is not revoked at Circle. This keeps resolveOrCreate
|
|
93
|
+
// usable; it is not equivalent to an uninstall.
|
|
94
|
+
do {
|
|
95
|
+
try FileManager.default.removeItem(at: file)
|
|
96
|
+
} catch {
|
|
97
|
+
throw InstallationIdentityStoreError.unwritable
|
|
98
|
+
}
|
|
99
|
+
return nil
|
|
100
|
+
}
|
|
101
|
+
return id
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
private func write(_ id: UUID, to file: URL) throws {
|
|
105
|
+
do {
|
|
106
|
+
try FileManager.default.createDirectory(at: directory, withIntermediateDirectories: true)
|
|
107
|
+
try Self.excludeFromBackup(directory)
|
|
108
|
+
try Data(id.uuidString.lowercased().utf8).write(
|
|
109
|
+
to: file,
|
|
110
|
+
options: [.atomic, .completeFileProtectionUntilFirstUserAuthentication]
|
|
111
|
+
)
|
|
112
|
+
// The atomic write replaces the file, so mark the file itself as well
|
|
113
|
+
// as its directory.
|
|
114
|
+
try Self.excludeFromBackup(file)
|
|
115
|
+
} catch {
|
|
116
|
+
throw InstallationIdentityStoreError.unwritable
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
private static func excludeFromBackup(_ url: URL) throws {
|
|
121
|
+
var url = url
|
|
122
|
+
var values = URLResourceValues()
|
|
123
|
+
values.isExcludedFromBackup = true
|
|
124
|
+
try url.setResourceValues(values)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
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 Foundation
|
|
18
|
+
|
|
19
|
+
// Shared by DaaSecureKey and DaaRegistration. One canonicalization so a
|
|
20
|
+
// round-trip check on the signing-input decoder cannot drift from encode.
|
|
21
|
+
|
|
22
|
+
func unpaddedBase64URL(_ data: Data) -> String {
|
|
23
|
+
data.base64EncodedString()
|
|
24
|
+
.replacingOccurrences(of: "+", with: "-")
|
|
25
|
+
.replacingOccurrences(of: "/", with: "_")
|
|
26
|
+
.replacingOccurrences(of: "=", with: "")
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
func decodeUnpaddedBase64URL(_ encoded: String) throws -> Data {
|
|
30
|
+
guard encoded.count % 4 != 1 else {
|
|
31
|
+
throw ContractViolationException()
|
|
32
|
+
}
|
|
33
|
+
let padding = String(repeating: "=", count: (4 - encoded.count % 4) % 4)
|
|
34
|
+
let standard = encoded
|
|
35
|
+
.replacingOccurrences(of: "-", with: "+")
|
|
36
|
+
.replacingOccurrences(of: "_", with: "/")
|
|
37
|
+
guard let decoded = Data(base64Encoded: standard + padding),
|
|
38
|
+
unpaddedBase64URL(decoded) == encoded else {
|
|
39
|
+
throw ContractViolationException()
|
|
40
|
+
}
|
|
41
|
+
return decoded
|
|
42
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,116 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@circle-fin/daa-react-native-sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "React Native SDK for Digital Asset Accounts (DAA) — attested authentication and self-custody DAA API access",
|
|
5
|
+
"main": "build/index.js",
|
|
6
|
+
"source": "src/index.ts",
|
|
7
|
+
"types": "build/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./build/index.d.ts",
|
|
11
|
+
"default": "./build/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./testing": {
|
|
14
|
+
"types": "./build/testing.d.ts",
|
|
15
|
+
"default": "./build/testing.js"
|
|
16
|
+
},
|
|
17
|
+
"./package.json": "./package.json"
|
|
18
|
+
},
|
|
19
|
+
"license": "Apache-2.0",
|
|
20
|
+
"homepage": "https://github.com/circlefin/daa-react-native-sdk",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "https://github.com/circlefin/daa-react-native-sdk.git"
|
|
24
|
+
},
|
|
25
|
+
"//private": "The release workflows set private to false when they publish, so a local npm publish cannot run by accident.",
|
|
26
|
+
"private": false,
|
|
27
|
+
"author": "",
|
|
28
|
+
"packageManager": "yarn@1.22.22",
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=22"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsc -p tsconfig.build.json",
|
|
34
|
+
"build:onboarding": "tsc -p packages/onboarding/tsconfig.build.json",
|
|
35
|
+
"prepack": "yarn build",
|
|
36
|
+
"test": "jest",
|
|
37
|
+
"test:ci": "jest --ci --runInBand",
|
|
38
|
+
"check:type": "tsc --noEmit && { [ ! -d packages/onboarding ] || tsc --noEmit -p packages/onboarding; }",
|
|
39
|
+
"lint": "eslint .",
|
|
40
|
+
"format": "prettier --write .",
|
|
41
|
+
"format:check": "prettier --check .",
|
|
42
|
+
"check:license": "bash scripts/check-license-headers.sh",
|
|
43
|
+
"test:ios-native": "bash scripts/test-ios-native.sh"
|
|
44
|
+
},
|
|
45
|
+
"files": [
|
|
46
|
+
"build",
|
|
47
|
+
"src",
|
|
48
|
+
"ios",
|
|
49
|
+
"android",
|
|
50
|
+
"expo-module.config.json",
|
|
51
|
+
"DaaReactNativeSdk.podspec",
|
|
52
|
+
"testing.js",
|
|
53
|
+
"testing.d.ts",
|
|
54
|
+
"README.md",
|
|
55
|
+
"!**/__test__",
|
|
56
|
+
"!**/*.test.ts",
|
|
57
|
+
"!android/build/",
|
|
58
|
+
"!android/.gradle/",
|
|
59
|
+
"!ios/Pods/",
|
|
60
|
+
"!ios/build/",
|
|
61
|
+
"!ios/Tests/"
|
|
62
|
+
],
|
|
63
|
+
"keywords": [
|
|
64
|
+
"react-native",
|
|
65
|
+
"circle",
|
|
66
|
+
"daa",
|
|
67
|
+
"digital-asset-accounts",
|
|
68
|
+
"usdc",
|
|
69
|
+
"self-custody",
|
|
70
|
+
"attested"
|
|
71
|
+
],
|
|
72
|
+
"peerDependencies": {
|
|
73
|
+
"expo": ">=54.0.0",
|
|
74
|
+
"expo-modules-core": ">=3.0.0",
|
|
75
|
+
"react": ">=18.0.0",
|
|
76
|
+
"react-native": ">=0.81.0"
|
|
77
|
+
},
|
|
78
|
+
"peerDependenciesMeta": {
|
|
79
|
+
"expo": {
|
|
80
|
+
"optional": true
|
|
81
|
+
},
|
|
82
|
+
"expo-modules-core": {
|
|
83
|
+
"optional": true
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
"devDependencies": {
|
|
87
|
+
"@cyclonedx/cyclonedx-npm": "6.0.1",
|
|
88
|
+
"@sumsub/react-native-mobilesdk-module": "1.46.1",
|
|
89
|
+
"@react-native/babel-preset": "0.85.3",
|
|
90
|
+
"@react-native/jest-preset": "0.85.3",
|
|
91
|
+
"@testing-library/react-native": "14.0.1",
|
|
92
|
+
"@types/jest": "29.5.14",
|
|
93
|
+
"@types/react": "19.2.3",
|
|
94
|
+
"babel-jest": "29.7.0",
|
|
95
|
+
"eslint": "^9.39.0",
|
|
96
|
+
"eslint-config-prettier": "^10.1.8",
|
|
97
|
+
"eslint-plugin-react-hooks": "^7.1.1",
|
|
98
|
+
"expo-modules-core": "~3.0.29",
|
|
99
|
+
"jest": "^29.7.0",
|
|
100
|
+
"prettier": "^3.6.2",
|
|
101
|
+
"react": "19.2.3",
|
|
102
|
+
"react-native": "0.85.3",
|
|
103
|
+
"react-native-persona": "2.48.0",
|
|
104
|
+
"test-renderer": "^1.0.0",
|
|
105
|
+
"ts-jest": "^29.4.5",
|
|
106
|
+
"typescript": "^5.9.3",
|
|
107
|
+
"typescript-eslint": "^8.38.0"
|
|
108
|
+
},
|
|
109
|
+
"resolutions": {
|
|
110
|
+
"**/@eslint/eslintrc/js-yaml": "^4.3.2",
|
|
111
|
+
"**/@istanbuljs/load-nyc-config/js-yaml": "^3.15.2",
|
|
112
|
+
"typescript-eslint/**/brace-expansion": "5.0.12",
|
|
113
|
+
"@cyclonedx/cyclonedx-npm/**/brace-expansion": "2.1.7",
|
|
114
|
+
"**/minimatch/brace-expansion": "1.1.21"
|
|
115
|
+
}
|
|
116
|
+
}
|