@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,135 @@
|
|
|
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
|
+
// Resolving the installation AuthKey by alias, in one place.
|
|
20
|
+
//
|
|
21
|
+
// Two call sites need the same key: the login ceremony selects it after Social
|
|
22
|
+
// Session (`AuthClient`), and the authenticated operations surface signs writes
|
|
23
|
+
// with it (`DaaClient.forUser`). The key is not carried on `DaaUserContext` —
|
|
24
|
+
// that context is a decoded server result, not a handle to enclave-held key
|
|
25
|
+
// material — so `forUser` re-resolves by the same `{appId, environment}` alias
|
|
26
|
+
// login used, together with the SAME context's `clientEntityId`.
|
|
27
|
+
// `DeviceContext.authKeyId` supplies the JWS `kid` alongside it.
|
|
28
|
+
//
|
|
29
|
+
// The lazy `NativeSecureKeyStore` is why this is a factory rather than a free
|
|
30
|
+
// function. Reaching the store requires the Expo `DaaSecureKey` module, and
|
|
31
|
+
// `DaaClient` construction deliberately does not; the store is therefore looked
|
|
32
|
+
// up on first resolution. It is one store per process, shared by every
|
|
33
|
+
// `DaaClient` (see `resolveNativeSecureKeyStore`), so login, every later signed
|
|
34
|
+
// write, and a forget through any client share one in-flight `resolveOrCreate`
|
|
35
|
+
// map rather than racing independent handles for the same alias.
|
|
36
|
+
|
|
37
|
+
import { contractViolation } from '../errors'
|
|
38
|
+
import type { NativeSecureKeyStore } from './NativeSecureKey'
|
|
39
|
+
import { resolveNativeSecureKeyStore } from './resolveNativeBridge'
|
|
40
|
+
import type {
|
|
41
|
+
AppKeyIdentity,
|
|
42
|
+
OwnerAuthKey,
|
|
43
|
+
RegisteredOwnerAuthKey,
|
|
44
|
+
SecureKeyStore,
|
|
45
|
+
} from './SecureKey'
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Resolves the installation AuthKey for one already-known Owner.
|
|
49
|
+
*
|
|
50
|
+
* Deliberately a zero-arg function rather than the store itself: a holder can
|
|
51
|
+
* obtain the one key its identity namespaces and nothing else — no alias of
|
|
52
|
+
* its choosing, and no store to resolve a different one from. This is the
|
|
53
|
+
* shape `DaaUserSigning.resolveAuthKey` (`api/signedResource.ts`) needs,
|
|
54
|
+
* because by the time `forUser` builds one it already knows which Owner it is
|
|
55
|
+
* signing for. It is NOT the shape {@link AppOwnerKeys.resolveOrCreate} has
|
|
56
|
+
* — see {@link AppAuthKeyResolver}.
|
|
57
|
+
*/
|
|
58
|
+
export type OwnerAuthKeyResolver = () => Promise<OwnerAuthKey>
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Resolves the installation AuthKey for a given Owner, by `clientEntityId`.
|
|
62
|
+
*
|
|
63
|
+
* `clientEntityId` is a per-call parameter rather than baked into the
|
|
64
|
+
* resolver at construction: it is not known when `DaaClient`
|
|
65
|
+
* builds this resolver (only the Social Session response names an Owner), and
|
|
66
|
+
* one long-lived `DaaClient` may serve more than one Owner over its lifetime
|
|
67
|
+
* — sign-out, then sign back in as someone else. Each call site binds the
|
|
68
|
+
* `clientEntityId` it already has (Social Session's response for login;
|
|
69
|
+
* `DaaUserContext.clientEntityId` for `forUser`) and, for `forUser`, wraps the
|
|
70
|
+
* result down to an {@link OwnerAuthKeyResolver} before handing it to a
|
|
71
|
+
* resource client — a resource client has no Owner concept of its own.
|
|
72
|
+
*/
|
|
73
|
+
export type AppAuthKeyResolver = (clientEntityId: string) => Promise<OwnerAuthKey>
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Every AuthKey operation `DaaClient` needs for one application identity,
|
|
77
|
+
* over one shared store: login and `forUser` resolve (or create) the key, while
|
|
78
|
+
* session restore reads an already-registered one, and an explicit
|
|
79
|
+
* `forgetLocalKey` deletes it.
|
|
80
|
+
*
|
|
81
|
+
* `#`-private on `DaaClient` for the same reason {@link AppAuthKeyResolver} is:
|
|
82
|
+
* a holder could reach an {@link OwnerAuthKey} and so a generic signing
|
|
83
|
+
* surface.
|
|
84
|
+
*/
|
|
85
|
+
export type AppOwnerKeys = Readonly<{
|
|
86
|
+
/** Resolve the Owner's AuthKey, creating it only when absent. */
|
|
87
|
+
resolveOrCreate: AppAuthKeyResolver
|
|
88
|
+
/** Read-only: the Owner's registered AuthKey and its identifiers, or `null`. */
|
|
89
|
+
resolveExisting: (clientEntityId: string) => Promise<RegisteredOwnerAuthKey | null>
|
|
90
|
+
/** Delete the Owner's AuthKey on this device. Local only; no revocation. */
|
|
91
|
+
forget: (clientEntityId: string) => Promise<void>
|
|
92
|
+
}>
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Build {@link AppOwnerKeys} for one application identity.
|
|
96
|
+
*
|
|
97
|
+
* @param identity App-level identity (`appId`, `environment`); `null` when
|
|
98
|
+
* the SDK has no application identity to select a key with, which fails
|
|
99
|
+
* closed at the first use rather than at construction.
|
|
100
|
+
* @param secureKeys Injected store, which tests substitute. Absent, the
|
|
101
|
+
* process-wide native store is looked up on first use and reused by all
|
|
102
|
+
* three operations.
|
|
103
|
+
*/
|
|
104
|
+
export function createAppOwnerKeys(
|
|
105
|
+
identity: AppKeyIdentity | null,
|
|
106
|
+
secureKeys: SecureKeyStore | null,
|
|
107
|
+
): AppOwnerKeys {
|
|
108
|
+
// The mutable slot the process-wide native store fills on first use. A closure
|
|
109
|
+
// variable rather than a field because the clients holding this are sealed
|
|
110
|
+
// with `Object.freeze`.
|
|
111
|
+
let nativeStore: NativeSecureKeyStore | null = null
|
|
112
|
+
const store = (): { store: SecureKeyStore; identity: AppKeyIdentity } => {
|
|
113
|
+
if (identity === null) {
|
|
114
|
+
throw contractViolation('AuthKey selection requires the DaaClient application identity')
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
store: secureKeys ?? (nativeStore ??= resolveNativeSecureKeyStore()),
|
|
118
|
+
identity,
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return Object.freeze({
|
|
122
|
+
resolveOrCreate: async (clientEntityId: string) => {
|
|
123
|
+
const resolved = store()
|
|
124
|
+
return resolved.store.resolveOrCreate({ ...resolved.identity, clientEntityId })
|
|
125
|
+
},
|
|
126
|
+
resolveExisting: async (clientEntityId: string) => {
|
|
127
|
+
const resolved = store()
|
|
128
|
+
return resolved.store.resolveExisting({ ...resolved.identity, clientEntityId })
|
|
129
|
+
},
|
|
130
|
+
forget: async (clientEntityId: string) => {
|
|
131
|
+
const resolved = store()
|
|
132
|
+
return resolved.store.forget({ ...resolved.identity, clientEntityId })
|
|
133
|
+
},
|
|
134
|
+
})
|
|
135
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
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 { isRecord } from '../config'
|
|
20
|
+
import { contractViolation } from '../errors'
|
|
21
|
+
import { isUuid } from '../validation/uuid'
|
|
22
|
+
import type { AuthKeyRegistration } from './SecureKey'
|
|
23
|
+
|
|
24
|
+
// Both identifiers are UUIDs on the wire (the DeviceContext decoder already
|
|
25
|
+
// requires it) and native rejects anything else; checking here fails closed on
|
|
26
|
+
// both platforms the same way, before the bridge is reached. Shared by the
|
|
27
|
+
// native and in-memory stores so both reject a bad argument with the same
|
|
28
|
+
// error, without the in-memory double importing the native store.
|
|
29
|
+
export function assertRegistration(registration: AuthKeyRegistration): AuthKeyRegistration {
|
|
30
|
+
if (
|
|
31
|
+
!isRecord(registration) ||
|
|
32
|
+
typeof registration.authKeyId !== 'string' ||
|
|
33
|
+
typeof registration.ownerBindingId !== 'string' ||
|
|
34
|
+
!isUuid(registration.authKeyId) ||
|
|
35
|
+
!isUuid(registration.ownerBindingId)
|
|
36
|
+
) {
|
|
37
|
+
throw contractViolation('AuthKey registration identifiers must be UUIDs')
|
|
38
|
+
}
|
|
39
|
+
return registration
|
|
40
|
+
}
|
|
@@ -0,0 +1,343 @@
|
|
|
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 { requireOptionalNativeModule } from 'expo-modules-core'
|
|
20
|
+
import { DEVICE_KEY_POLICY, isRecord } from '../config'
|
|
21
|
+
import type { DeviceKeyPolicy } from '../config'
|
|
22
|
+
import { contractViolation } from '../errors'
|
|
23
|
+
import { parseSecureKeyAlias } from './alias'
|
|
24
|
+
import { NativeSecureKeyStore } from './NativeSecureKey'
|
|
25
|
+
import type {
|
|
26
|
+
NativeAuthKeyResolution,
|
|
27
|
+
NativeRegisteredAuthKey,
|
|
28
|
+
NativeSecureKeyBridge,
|
|
29
|
+
} from './NativeSecureKeyBridge'
|
|
30
|
+
|
|
31
|
+
// JS shape of the Expo `DaaSecureKey` native module. Identity is passed as
|
|
32
|
+
// structured `{appId, environment}` fields after TypeScript parses the RN
|
|
33
|
+
// alias; the native module owns the per-install UUID and constructs
|
|
34
|
+
// `DaaAuthKeyIdentity`.
|
|
35
|
+
interface DaaSecureKeyNativeModule {
|
|
36
|
+
/**
|
|
37
|
+
* The DeviceKeyPolicy this native module was built to enforce. This is a
|
|
38
|
+
* version-skew guard, not a live capability readback: it is a compiled-in
|
|
39
|
+
* constant on both sides of the bridge (mirrors `DEVICE_KEY_POLICY`), so a
|
|
40
|
+
* mismatch means the JS and native module versions disagree about the
|
|
41
|
+
* closed set, not that a specific key's real hardware/OS protection was
|
|
42
|
+
* measured and found wanting. Neither native SDK exposes a public API for
|
|
43
|
+
* that.
|
|
44
|
+
*/
|
|
45
|
+
declaredKeyPolicy?: () => unknown
|
|
46
|
+
resolveOrCreate(appId: string, environment: string): Promise<string>
|
|
47
|
+
publicKeySpkiBase64Url(appId: string, environment: string): Promise<string>
|
|
48
|
+
acknowledgeRegistration(
|
|
49
|
+
appId: string,
|
|
50
|
+
environment: string,
|
|
51
|
+
authKeyId: string,
|
|
52
|
+
ownerBindingId: string,
|
|
53
|
+
): Promise<void>
|
|
54
|
+
/**
|
|
55
|
+
* Native `DaaSecureKey.resolveExisting()`: the registration record as
|
|
56
|
+
* `{ authKeyId, ownerBindingId }`, or `null`.
|
|
57
|
+
* Read-only; never mints a key and never prompts. Optional at the type level
|
|
58
|
+
* so a native module built before it existed fails closed in the wrapper
|
|
59
|
+
* below rather than with an untyped `undefined is not a function`.
|
|
60
|
+
*/
|
|
61
|
+
resolveExisting?: (appId: string, environment: string) => Promise<unknown>
|
|
62
|
+
/**
|
|
63
|
+
* Native `DaaSecureKey.forgetLocalKey()`: deletes the key and its local
|
|
64
|
+
* metadata. Local only, idempotent. Optional for the same reason as
|
|
65
|
+
* {@link resolveExisting}.
|
|
66
|
+
*/
|
|
67
|
+
forgetLocalKey?: (appId: string, environment: string) => Promise<void>
|
|
68
|
+
signDeviceAuthorization(
|
|
69
|
+
appId: string,
|
|
70
|
+
environment: string,
|
|
71
|
+
signingInputBase64Url: string,
|
|
72
|
+
): Promise<string>
|
|
73
|
+
/**
|
|
74
|
+
* The registration-profile counterpart of {@link signDeviceAuthorization}.
|
|
75
|
+
* A separate native function with a separate validator
|
|
76
|
+
* (`DaaRegistrationAuthorizationSigningInput`), not an overload — see
|
|
77
|
+
* `NativeSecureKeyBridge.signRegistrationDeviceAuthorization`.
|
|
78
|
+
*/
|
|
79
|
+
signRegistrationDeviceAuthorization(
|
|
80
|
+
appId: string,
|
|
81
|
+
environment: string,
|
|
82
|
+
signingInputBase64Url: string,
|
|
83
|
+
): Promise<string>
|
|
84
|
+
/**
|
|
85
|
+
* The `approve_device` counterpart of {@link signDeviceAuthorization}: native
|
|
86
|
+
* checks the approval body, code secret and typed code against the signing
|
|
87
|
+
* input before any biometric prompt. Optional for the same reason as
|
|
88
|
+
* {@link resolveExisting}.
|
|
89
|
+
*/
|
|
90
|
+
signDeviceApproval?: (
|
|
91
|
+
appId: string,
|
|
92
|
+
environment: string,
|
|
93
|
+
signingInputBase64Url: string,
|
|
94
|
+
requestBodyBase64Url: string,
|
|
95
|
+
codeSecretBase64Url: string,
|
|
96
|
+
enteredCode: string,
|
|
97
|
+
) => Promise<string>
|
|
98
|
+
/**
|
|
99
|
+
* Native `DaaSecureKey.codeSecret()`, as unpadded Base64URL. Optional for
|
|
100
|
+
* the same reason as {@link resolveExisting}.
|
|
101
|
+
*/
|
|
102
|
+
codeSecret?: (appId: string, environment: string) => Promise<string>
|
|
103
|
+
/**
|
|
104
|
+
* Native `DaaSecureKey.deleteCodeSecret(_:)`. Optional for the same reason
|
|
105
|
+
* as {@link resolveExisting}.
|
|
106
|
+
*/
|
|
107
|
+
deleteCodeSecret?: (appId: string, environment: string, secretBase64Url: string) => Promise<void>
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* When the Expo `DaaSecureKey` module is loaded, require that its declared
|
|
112
|
+
* policy matches the configured closed set. No-ops when the module is absent
|
|
113
|
+
* (Node / Jest) so Prepare can still construct a client.
|
|
114
|
+
*
|
|
115
|
+
* This is a version-skew guard between the JS and native module, not a live
|
|
116
|
+
* attestation of a specific key's real protection level — see
|
|
117
|
+
* `declaredKeyPolicy` on `DaaSecureKeyNativeModule` above.
|
|
118
|
+
*/
|
|
119
|
+
export function assertNativeModuleKeyPolicyIfPresent(configured: DeviceKeyPolicy): void {
|
|
120
|
+
const native = requireOptionalNativeModule<DaaSecureKeyNativeModule>('DaaSecureKey')
|
|
121
|
+
if (native === null) {
|
|
122
|
+
return
|
|
123
|
+
}
|
|
124
|
+
assertNativeDeclaredKeyPolicy(native, configured)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function assertNativeDeclaredKeyPolicy(
|
|
128
|
+
native: DaaSecureKeyNativeModule,
|
|
129
|
+
configured: DeviceKeyPolicy,
|
|
130
|
+
): void {
|
|
131
|
+
const query = native.declaredKeyPolicy
|
|
132
|
+
if (typeof query !== 'function') {
|
|
133
|
+
throw contractViolation('native DaaSecureKey module did not declare a DeviceKeyPolicy')
|
|
134
|
+
}
|
|
135
|
+
const declared = query.call(native)
|
|
136
|
+
if (
|
|
137
|
+
!isRecord(declared) ||
|
|
138
|
+
declared['hardwareBacked'] !== configured.hardwareBacked ||
|
|
139
|
+
declared['userVerification'] !== configured.userVerification
|
|
140
|
+
) {
|
|
141
|
+
throw contractViolation(
|
|
142
|
+
'native DaaSecureKey declared keyPolicy does not match the configured DeviceKeyPolicy',
|
|
143
|
+
)
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Production wiring to the platform native module (Swift under ios/, Kotlin
|
|
148
|
+
// under android/), resolved via expo-modules-core.
|
|
149
|
+
//
|
|
150
|
+
// Node / Jest have no native module: fail closed rather than silently no-op.
|
|
151
|
+
// Tests inject a NativeSecureKeyBridge explicitly.
|
|
152
|
+
export function resolveNativeBridge(): NativeSecureKeyBridge {
|
|
153
|
+
return wrapNativeModule(requireNativeModule())
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// One store per native module, so per process in an app. Native keeps one key
|
|
157
|
+
// per alias for the whole process, so every DaaClient must share one handle
|
|
158
|
+
// cache: a forget through one client otherwise leaves another client's cached
|
|
159
|
+
// handle pointing at the deleted key. Keyed by the module object rather than
|
|
160
|
+
// a plain singleton so a test that installs a fresh fake gets a fresh store.
|
|
161
|
+
const nativeStores = new WeakMap<DaaSecureKeyNativeModule, NativeSecureKeyStore>()
|
|
162
|
+
|
|
163
|
+
/** The process-wide {@link NativeSecureKeyStore} over the DaaSecureKey module. */
|
|
164
|
+
export function resolveNativeSecureKeyStore(): NativeSecureKeyStore {
|
|
165
|
+
const native = requireNativeModule()
|
|
166
|
+
let store = nativeStores.get(native)
|
|
167
|
+
if (store === undefined) {
|
|
168
|
+
store = new NativeSecureKeyStore(wrapNativeModule(native))
|
|
169
|
+
nativeStores.set(native, store)
|
|
170
|
+
}
|
|
171
|
+
return store
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function requireNativeModule(): DaaSecureKeyNativeModule {
|
|
175
|
+
const native = requireOptionalNativeModule<DaaSecureKeyNativeModule>('DaaSecureKey')
|
|
176
|
+
if (native === null) {
|
|
177
|
+
throw contractViolation(
|
|
178
|
+
'native DaaSecureKey module is not available. Provide a NativeSecureKeyBridge ' +
|
|
179
|
+
'explicitly, or run inside a React Native app that includes the DaaSecureKey Expo ' +
|
|
180
|
+
'module.',
|
|
181
|
+
)
|
|
182
|
+
}
|
|
183
|
+
assertNativeDeclaredKeyPolicy(native, DEVICE_KEY_POLICY)
|
|
184
|
+
return native
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function wrapNativeModule(native: DaaSecureKeyNativeModule): NativeSecureKeyBridge {
|
|
188
|
+
return {
|
|
189
|
+
async resolveOrCreate(alias: string): Promise<NativeAuthKeyResolution> {
|
|
190
|
+
const identity = parseSecureKeyAlias(alias)
|
|
191
|
+
const resolution = await native.resolveOrCreate(identity.appId, identity.environment)
|
|
192
|
+
if (resolution === 'created' || resolution === 'existing') {
|
|
193
|
+
return resolution
|
|
194
|
+
}
|
|
195
|
+
throw contractViolation('native resolveOrCreate returned an unknown resolution')
|
|
196
|
+
},
|
|
197
|
+
|
|
198
|
+
async publicKeySpkiBase64Url(alias: string): Promise<string> {
|
|
199
|
+
const identity = parseSecureKeyAlias(alias)
|
|
200
|
+
return await native.publicKeySpkiBase64Url(identity.appId, identity.environment)
|
|
201
|
+
},
|
|
202
|
+
|
|
203
|
+
async acknowledgeRegistration(
|
|
204
|
+
alias: string,
|
|
205
|
+
authKeyId: string,
|
|
206
|
+
ownerBindingId: string,
|
|
207
|
+
): Promise<void> {
|
|
208
|
+
// Native `acknowledgeRegistration(authKeyId, ownerBindingId)`, which
|
|
209
|
+
// always upserts the identifiers into the durable registration record
|
|
210
|
+
// (Data Protection Keychain on iOS, app-private storage on Android). The
|
|
211
|
+
// no-identifier variant is not reached from here: it records no ids, so
|
|
212
|
+
// a key acknowledged only that way has nothing for resolveExisting to read.
|
|
213
|
+
const identity = parseSecureKeyAlias(alias)
|
|
214
|
+
await native.acknowledgeRegistration(
|
|
215
|
+
identity.appId,
|
|
216
|
+
identity.environment,
|
|
217
|
+
authKeyId,
|
|
218
|
+
ownerBindingId,
|
|
219
|
+
)
|
|
220
|
+
},
|
|
221
|
+
|
|
222
|
+
async resolveExisting(alias: string): Promise<NativeRegisteredAuthKey | null> {
|
|
223
|
+
// Read-only on purpose: this lookup must never reach
|
|
224
|
+
// resolveOrCreate, which would mint a fresh, unregistered key.
|
|
225
|
+
const resolveExisting = native.resolveExisting
|
|
226
|
+
if (typeof resolveExisting !== 'function') {
|
|
227
|
+
throw contractViolation('native DaaSecureKey.resolveExisting is required')
|
|
228
|
+
}
|
|
229
|
+
const identity = parseSecureKeyAlias(alias)
|
|
230
|
+
const record = await resolveExisting.call(native, identity.appId, identity.environment)
|
|
231
|
+
// Only an explicit null is "no key": Expo delivers a Swift nil or a
|
|
232
|
+
// Kotlin null return as JS null. `undefined` is not a shape native
|
|
233
|
+
// sends, so it fails closed below instead of becoming "no key".
|
|
234
|
+
if (record === null) {
|
|
235
|
+
return null
|
|
236
|
+
}
|
|
237
|
+
if (!isRecord(record)) {
|
|
238
|
+
throw contractViolation('native resolveExisting returned an unknown shape')
|
|
239
|
+
}
|
|
240
|
+
// Field-level validation happens once, at the store seam
|
|
241
|
+
// (NativeSecureKeyStore), which also covers injected stand-ins.
|
|
242
|
+
return record as NativeRegisteredAuthKey
|
|
243
|
+
},
|
|
244
|
+
|
|
245
|
+
async forgetLocalKey(alias: string): Promise<void> {
|
|
246
|
+
const forgetLocalKey = native.forgetLocalKey
|
|
247
|
+
if (typeof forgetLocalKey !== 'function') {
|
|
248
|
+
throw contractViolation('native DaaSecureKey.forgetLocalKey is required')
|
|
249
|
+
}
|
|
250
|
+
const identity = parseSecureKeyAlias(alias)
|
|
251
|
+
await forgetLocalKey.call(native, identity.appId, identity.environment)
|
|
252
|
+
},
|
|
253
|
+
|
|
254
|
+
async sign(alias: string, messageBase64Url: string): Promise<string> {
|
|
255
|
+
// Typed native signDeviceAuthorization — not a generic sign(bytes) Expo
|
|
256
|
+
// method. `messageBase64Url` is the exact compact-JWS signing input
|
|
257
|
+
// `deviceAuthorization.ts` already constructed. Native wraps those bytes
|
|
258
|
+
// in DaaDeviceAuthorizationSigningInput (validates, does not re-encode)
|
|
259
|
+
// and returns 64-byte JOSE R||S as unpadded Base64URL.
|
|
260
|
+
if (typeof native.signDeviceAuthorization !== 'function') {
|
|
261
|
+
throw contractViolation('native DaaSecureKey.signDeviceAuthorization is required')
|
|
262
|
+
}
|
|
263
|
+
// No prompt text crosses the bridge: the native SDK derives the
|
|
264
|
+
// biometric prompt from the validated operation itself.
|
|
265
|
+
const identity = parseSecureKeyAlias(alias)
|
|
266
|
+
return await native.signDeviceAuthorization(
|
|
267
|
+
identity.appId,
|
|
268
|
+
identity.environment,
|
|
269
|
+
messageBase64Url,
|
|
270
|
+
)
|
|
271
|
+
},
|
|
272
|
+
|
|
273
|
+
async signDeviceApproval(
|
|
274
|
+
alias: string,
|
|
275
|
+
messageBase64Url: string,
|
|
276
|
+
requestBodyBase64Url: string,
|
|
277
|
+
codeSecretBase64Url: string,
|
|
278
|
+
enteredCode: string,
|
|
279
|
+
): Promise<string> {
|
|
280
|
+
// Native `DaaDeviceAuthorizationSigningInput` approval initializer (iOS)
|
|
281
|
+
// or `forDeviceApproval` (Android). Like `sign`, no prompt text crosses
|
|
282
|
+
// the bridge: native shows the matching code it derived itself.
|
|
283
|
+
const signDeviceApproval = native.signDeviceApproval
|
|
284
|
+
if (typeof signDeviceApproval !== 'function') {
|
|
285
|
+
throw contractViolation('native DaaSecureKey.signDeviceApproval is required')
|
|
286
|
+
}
|
|
287
|
+
const identity = parseSecureKeyAlias(alias)
|
|
288
|
+
return await signDeviceApproval.call(
|
|
289
|
+
native,
|
|
290
|
+
identity.appId,
|
|
291
|
+
identity.environment,
|
|
292
|
+
messageBase64Url,
|
|
293
|
+
requestBodyBase64Url,
|
|
294
|
+
codeSecretBase64Url,
|
|
295
|
+
enteredCode,
|
|
296
|
+
)
|
|
297
|
+
},
|
|
298
|
+
|
|
299
|
+
async codeSecret(alias: string): Promise<string> {
|
|
300
|
+
const codeSecret = native.codeSecret
|
|
301
|
+
if (typeof codeSecret !== 'function') {
|
|
302
|
+
throw contractViolation('native DaaSecureKey.codeSecret is required')
|
|
303
|
+
}
|
|
304
|
+
const identity = parseSecureKeyAlias(alias)
|
|
305
|
+
return await codeSecret.call(native, identity.appId, identity.environment)
|
|
306
|
+
},
|
|
307
|
+
|
|
308
|
+
async deleteCodeSecret(alias: string, secretBase64Url: string): Promise<void> {
|
|
309
|
+
const deleteCodeSecret = native.deleteCodeSecret
|
|
310
|
+
if (typeof deleteCodeSecret !== 'function') {
|
|
311
|
+
throw contractViolation('native DaaSecureKey.deleteCodeSecret is required')
|
|
312
|
+
}
|
|
313
|
+
const identity = parseSecureKeyAlias(alias)
|
|
314
|
+
await deleteCodeSecret.call(native, identity.appId, identity.environment, secretBase64Url)
|
|
315
|
+
},
|
|
316
|
+
|
|
317
|
+
async signRegistrationDeviceAuthorization(
|
|
318
|
+
alias: string,
|
|
319
|
+
messageBase64Url: string,
|
|
320
|
+
): Promise<string> {
|
|
321
|
+
// Typed native signRegistrationDeviceAuthorization — the registration
|
|
322
|
+
// counterpart of `sign` above, NOT the same native call. `messageBase64Url`
|
|
323
|
+
// is the exact compact-JWS signing input `registrationAuthorization.ts`
|
|
324
|
+
// already constructed. Native wraps those bytes in
|
|
325
|
+
// DaaRegistrationAuthorizationSigningInput (a different validator from
|
|
326
|
+
// DaaDeviceAuthorizationSigningInput: registration `typ`s, an embedded
|
|
327
|
+
// JWK header, and the 14-claim registration payload) and returns the
|
|
328
|
+
// 64-byte JOSE R||S signature as unpadded Base64URL. Unlike `sign`, this
|
|
329
|
+
// does not require a durably acknowledged key.
|
|
330
|
+
if (typeof native.signRegistrationDeviceAuthorization !== 'function') {
|
|
331
|
+
throw contractViolation(
|
|
332
|
+
'native DaaSecureKey.signRegistrationDeviceAuthorization is required',
|
|
333
|
+
)
|
|
334
|
+
}
|
|
335
|
+
const identity = parseSecureKeyAlias(alias)
|
|
336
|
+
return await native.signRegistrationDeviceAuthorization(
|
|
337
|
+
identity.appId,
|
|
338
|
+
identity.environment,
|
|
339
|
+
messageBase64Url,
|
|
340
|
+
)
|
|
341
|
+
},
|
|
342
|
+
}
|
|
343
|
+
}
|
package/src/testing.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
// Test-only entry point: the package's `./testing` subpath.
|
|
20
|
+
//
|
|
21
|
+
// Exposes the DAA Owner-key interfaces and a WebCrypto-backed in-memory store so
|
|
22
|
+
// consumers and golden vectors can exercise signing WITHOUT device hardware.
|
|
23
|
+
//
|
|
24
|
+
// NOT for production: the in-memory store holds a P-256 private key in process
|
|
25
|
+
// memory. It fails closed when constructed in a production build.
|
|
26
|
+
//
|
|
27
|
+
// The Owner-key interfaces (OwnerAuthKey / OwnerKeyIdentity / SecureKeyStore)
|
|
28
|
+
// are exported from the main entry (`.`) since they are the contract a
|
|
29
|
+
// production/native store implements. This subpath adds only the concrete
|
|
30
|
+
// test double.
|
|
31
|
+
|
|
32
|
+
export { InMemorySecureKeyStore } from './securekey/InMemorySecureKey'
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
// Injected transport boundary. The SDK never embeds a DAA service credential; a
|
|
20
|
+
// consumer supplies transport that carries exact request bytes to the DAA public
|
|
21
|
+
// API (directly, or through a consumer backend relay).
|
|
22
|
+
|
|
23
|
+
export type DaaHttpRequest = Readonly<{
|
|
24
|
+
method: string
|
|
25
|
+
/** Signed public API path beginning `/v1` — not a consumer-backend route. */
|
|
26
|
+
path: string
|
|
27
|
+
/** Exact percent-encoded query without the leading `?`, or null. */
|
|
28
|
+
query: string | null
|
|
29
|
+
headers: Readonly<Record<string, string>>
|
|
30
|
+
/** Immutable body bytes. The SDK signs and sends this same slice. */
|
|
31
|
+
bodyBytes: Uint8Array | null
|
|
32
|
+
}>
|
|
33
|
+
|
|
34
|
+
export type DaaHttpResponse = Readonly<{
|
|
35
|
+
status: number
|
|
36
|
+
headers: Readonly<Record<string, string>>
|
|
37
|
+
bodyBytes: Uint8Array | null
|
|
38
|
+
}>
|
|
39
|
+
|
|
40
|
+
export interface DaaTransport {
|
|
41
|
+
send(request: DaaHttpRequest): Promise<DaaHttpResponse>
|
|
42
|
+
}
|
|
@@ -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
|
+
/**
|
|
20
|
+
* Look a response header up without assuming its casing.
|
|
21
|
+
*
|
|
22
|
+
* HTTP field names are case-insensitive and HTTP/2 mandates lowercase on the
|
|
23
|
+
* wire, so a `fetch`-based transport may surface `x-request-id` where another
|
|
24
|
+
* surfaces `X-Request-Id`. `DaaHttpResponse` deliberately does not normalize —
|
|
25
|
+
* the transport is the consumer's — so the typed client, which is the first thing
|
|
26
|
+
* that reads a response header, owns the lookup.
|
|
27
|
+
*
|
|
28
|
+
* Returns `null` for an absent header. Absence is reported as absence rather than
|
|
29
|
+
* as an empty string, which a provider could also legitimately send.
|
|
30
|
+
*/
|
|
31
|
+
export function headerValueIgnoringCase(
|
|
32
|
+
headers: Readonly<Record<string, string>>,
|
|
33
|
+
name: string,
|
|
34
|
+
): string | null {
|
|
35
|
+
const exact = headers[name]
|
|
36
|
+
if (exact !== undefined) {
|
|
37
|
+
return exact
|
|
38
|
+
}
|
|
39
|
+
const wanted = name.toLowerCase()
|
|
40
|
+
for (const key of Object.keys(headers)) {
|
|
41
|
+
if (key.toLowerCase() === wanted) {
|
|
42
|
+
return headers[key] ?? null
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return null
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
|
|
49
|
+
const IMF_FIXDATE =
|
|
50
|
+
/^(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun), (\d{2}) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) (\d{4}) (\d{2}):(\d{2}):(\d{2}) GMT$/
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Parse an HTTP `Date` header value (RFC 9110 IMF-fixdate, e.g.
|
|
54
|
+
* `Sun, 06 Nov 1994 08:49:37 GMT`) to epoch milliseconds.
|
|
55
|
+
*
|
|
56
|
+
* Parsed by hand rather than with `Date.parse`, whose handling of this format
|
|
57
|
+
* is implementation-defined and differs across JavaScript engines. Returns
|
|
58
|
+
* `null` for an absent header or any value that is not a valid IMF-fixdate
|
|
59
|
+
* (including the obsolete RFC 850 and asctime forms), so a caller treats an
|
|
60
|
+
* unreadable `Date` exactly like a missing one.
|
|
61
|
+
*/
|
|
62
|
+
export function httpDateMillis(value: string | null): number | null {
|
|
63
|
+
if (value === null) {
|
|
64
|
+
return null
|
|
65
|
+
}
|
|
66
|
+
const match = IMF_FIXDATE.exec(value.trim())
|
|
67
|
+
if (match === null) {
|
|
68
|
+
return null
|
|
69
|
+
}
|
|
70
|
+
const [, day, month, year, hour, minute, second] = match
|
|
71
|
+
const monthIndex = MONTHS.indexOf(month ?? '')
|
|
72
|
+
const millis = Date.UTC(
|
|
73
|
+
Number(year),
|
|
74
|
+
monthIndex,
|
|
75
|
+
Number(day),
|
|
76
|
+
Number(hour),
|
|
77
|
+
Number(minute),
|
|
78
|
+
Number(second),
|
|
79
|
+
)
|
|
80
|
+
// Reject a calendar-invalid value such as `31 Feb`, which Date.UTC would
|
|
81
|
+
// otherwise silently roll over into the next month.
|
|
82
|
+
const parsed = new Date(millis)
|
|
83
|
+
if (
|
|
84
|
+
parsed.getUTCDate() !== Number(day) ||
|
|
85
|
+
parsed.getUTCMonth() !== monthIndex ||
|
|
86
|
+
Number(hour) > 23 ||
|
|
87
|
+
Number(minute) > 59 ||
|
|
88
|
+
Number(second) > 60
|
|
89
|
+
) {
|
|
90
|
+
return null
|
|
91
|
+
}
|
|
92
|
+
return millis
|
|
93
|
+
}
|