@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,636 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2026, Circle Internet Group, Inc. All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
19
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
20
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
21
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
22
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
23
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
24
|
+
};
|
|
25
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
26
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
27
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
28
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
29
|
+
};
|
|
30
|
+
var _PendingDeviceRegistration_instances, _PendingDeviceRegistration_transport, _PendingDeviceRegistration_registrationCodeVerifier, _PendingDeviceRegistration_registrationFlowKey, _PendingDeviceRegistration_authKey, _PendingDeviceRegistration_resolveAuthKey, _PendingDeviceRegistration_addDeviceApproval, _PendingDeviceRegistration_consumed, _PendingDeviceRegistration_unsaved, _PendingDeviceRegistration_key, _PendingDeviceRegistration_acknowledge, _PendingDeviceRegistration_forget, _PendingDeviceRegistration_notSaved, _PendingDeviceRegistration_save, _PendingDeviceRegistration_saveAnswer, _PendingDeviceRegistration_finish;
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
exports.PendingDeviceRegistration = void 0;
|
|
33
|
+
const registrationAuthorization_1 = require("../auth/registrationAuthorization");
|
|
34
|
+
const RegistrationFlowKey_1 = require("../auth/RegistrationFlowKey");
|
|
35
|
+
const base64url_1 = require("../crypto/base64url");
|
|
36
|
+
const matchingCode_1 = require("../crypto/matchingCode");
|
|
37
|
+
const random_1 = require("../crypto/random");
|
|
38
|
+
const serialization_1 = require("../crypto/serialization");
|
|
39
|
+
const errors_1 = require("../errors");
|
|
40
|
+
const requestBody_1 = require("../validation/requestBody");
|
|
41
|
+
const loginFailure_1 = require("../api/loginFailure");
|
|
42
|
+
const resourceRequest_1 = require("../api/resourceRequest");
|
|
43
|
+
const deviceRegistrationResultPayload_1 = require("../wire/deviceRegistrationResultPayload");
|
|
44
|
+
const DaaUserContext_1 = require("./DaaUserContext");
|
|
45
|
+
const codeSecrets_1 = require("./codeSecrets");
|
|
46
|
+
const PendingDeviceApproval_1 = require("./PendingDeviceApproval");
|
|
47
|
+
const AUTH_KEY_PUBLIC_KEY = /^[A-Za-z0-9_-]{122}$/;
|
|
48
|
+
/** The `type` that selects device key registration on `/v1/accounts/auth/keys`. */
|
|
49
|
+
const DEVICE_KEY_TYPE = 'deviceKey';
|
|
50
|
+
/**
|
|
51
|
+
* How long one queued `complete()` may run, authentication prompt and
|
|
52
|
+
* transport included, before it fails and the next step for the key starts.
|
|
53
|
+
* Without it, a `send()` that never settles would hold every later sign-in
|
|
54
|
+
* with the key (and every `sendCodeSecret()`) until the process exits. Reading the AuthKey before queuing has
|
|
55
|
+
* its own deadline of the same length.
|
|
56
|
+
*/
|
|
57
|
+
const COMPLETE_DEADLINE_MS = 120000;
|
|
58
|
+
/**
|
|
59
|
+
* Save failures that mean the key is gone from the device: invalidated, or no
|
|
60
|
+
* longer there (`device_not_initialized` is what both native bridges report
|
|
61
|
+
* for a key not found). No retry could succeed, so these pass through as is.
|
|
62
|
+
*/
|
|
63
|
+
const KEY_GONE_KINDS = new Set(['key_invalidated', 'device_not_initialized']);
|
|
64
|
+
/**
|
|
65
|
+
* The newest `ACTIVE` or `PENDING_ACTIVATION` answer per AuthKey thumbprint
|
|
66
|
+
* whose identifiers may not be saved yet. A retried save goes ahead only while
|
|
67
|
+
* its answer is still the newest: once a newer registration of the key
|
|
68
|
+
* answered, that one's
|
|
69
|
+
* identifiers are the ones to keep, and saving the older ones would overwrite
|
|
70
|
+
* them. Kept per process, like the key queue in `codeSecrets.ts`.
|
|
71
|
+
*/
|
|
72
|
+
const newestAnswer = new Map();
|
|
73
|
+
/**
|
|
74
|
+
* Runs `step` and settles within `COMPLETE_DEADLINE_MS`. At the deadline the
|
|
75
|
+
* call fails and the key's queue moves on, but `step` may still be running.
|
|
76
|
+
* It checks `late`: it doesn't send after it, and it ignores a response that
|
|
77
|
+
* comes back after it, so a late answer can't drop the secret. A secret it
|
|
78
|
+
* already sent is held (`holdCodeSecret`): DAA may still add that request as
|
|
79
|
+
* waiting with its seal after a later Complete for the key was refused.
|
|
80
|
+
*/
|
|
81
|
+
async function withDeadline(step) {
|
|
82
|
+
const call = { late: false, sentSecret: null, onLate: null, afterDeadline: null };
|
|
83
|
+
let timer;
|
|
84
|
+
const deadline = new Promise((_, reject) => {
|
|
85
|
+
timer = setTimeout(() => {
|
|
86
|
+
call.late = true;
|
|
87
|
+
if (call.sentSecret !== null) {
|
|
88
|
+
(0, codeSecrets_1.holdCodeSecret)(call.sentSecret);
|
|
89
|
+
}
|
|
90
|
+
call.onLate?.();
|
|
91
|
+
reject(completeTimedOut());
|
|
92
|
+
}, COMPLETE_DEADLINE_MS);
|
|
93
|
+
});
|
|
94
|
+
try {
|
|
95
|
+
return await Promise.race([step(call), deadline]);
|
|
96
|
+
}
|
|
97
|
+
finally {
|
|
98
|
+
clearTimeout(timer);
|
|
99
|
+
// Set only by a step that settled before its deadline: nothing is awaited
|
|
100
|
+
// between setting it and settling, so a timer can't fire in between.
|
|
101
|
+
await call.afterDeadline?.();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function completeTimedOut() {
|
|
105
|
+
return new errors_1.DaaError({ kind: 'transport', retryable: false }, `DAA: Device Registration Complete did not finish within ${COMPLETE_DEADLINE_MS / 1000} seconds`);
|
|
106
|
+
}
|
|
107
|
+
const NO_WAITING_REQUEST_KINDS = new Set([
|
|
108
|
+
'device_registration_limit',
|
|
109
|
+
'device_denied',
|
|
110
|
+
'device_approval_conflict',
|
|
111
|
+
'device_approval_unavailable',
|
|
112
|
+
]);
|
|
113
|
+
const COMPLETE_INPUT_PROPERTIES = Object.freeze(['riskSignals', 'confirmAddDevice']);
|
|
114
|
+
const RISK_SIGNAL_PROPERTIES = Object.freeze(['ipAddress', 'sessionId', 'deviceId']);
|
|
115
|
+
/**
|
|
116
|
+
* Pending device registration after Social Session.
|
|
117
|
+
*
|
|
118
|
+
* `complete()` is Device Registration Complete: `POST /v1/accounts/auth/keys`
|
|
119
|
+
* with the body (`type: "deviceKey"`, `idempotencyKey`, `registrationHandle`,
|
|
120
|
+
* `registrationCodeVerifier`, `deviceKeyPublicKey`, and `codeSeal` with
|
|
121
|
+
* `addDeviceApproval` on), plus `riskSignals` when the caller passes them,
|
|
122
|
+
* including the registration code verifier minted before
|
|
123
|
+
* Prepare and redeemed here against the challenge Prepare sent. Two JWSs
|
|
124
|
+
* authorize it — `X-Device-Authorization` (signed by the proposed AuthKey) and
|
|
125
|
+
* `X-Registration-Flow-Authorization` (signed by the per-attempt flow key from
|
|
126
|
+
* Prepare) — both over the exact body bytes. Both carry the same request claims
|
|
127
|
+
* bar `jti`; only the flow proof also carries the binding claims (registration
|
|
128
|
+
* handle, profile, AuthKey thumbprint, code verifier). Building and signing
|
|
129
|
+
* those proofs is `authorizeRegistrationComplete`.
|
|
130
|
+
*
|
|
131
|
+
* Every device takes this same path, first or additional, with the same body
|
|
132
|
+
* and no mode to select. A first device comes back `ACTIVE`. A new device on an
|
|
133
|
+
* Owner that already has an active device comes back `PENDING_APPROVAL`: DAA
|
|
134
|
+
* adds the key as waiting, and an existing device approves it after the user
|
|
135
|
+
* types the matching code this device shows (see `PendingDeviceApproval`).
|
|
136
|
+
* `codeSeal` is what makes that code possible, so it is sent on every
|
|
137
|
+
* registration: the SDK can't know beforehand which outcome DAA will return.
|
|
138
|
+
*
|
|
139
|
+
* With `addDeviceApproval` on, the SDK asks first. When the Session's
|
|
140
|
+
* `deviceApproval.required` says a new device would wait for approval and this
|
|
141
|
+
* device has no AuthKey Circle registered for the end user,
|
|
142
|
+
* `confirmationRequired` is `true` and this sign-in hasn't created a key. Ask
|
|
143
|
+
* the user whether to add this device (`deviceApproval.hasActiveDevice` says
|
|
144
|
+
* whether one of their devices can approve it), and call
|
|
145
|
+
* `complete({ confirmAddDevice: true })` only if they confirm. That creates
|
|
146
|
+
* the key, or reuses the one this device made for an earlier request, and
|
|
147
|
+
* registers it. DAA's answer still decides the outcome: a request already
|
|
148
|
+
* waiting comes back `PENDING_APPROVAL` again, and `ACTIVE` is possible where
|
|
149
|
+
* DAA doesn't add keys as waiting yet.
|
|
150
|
+
*
|
|
151
|
+
* There is no `abandon()` here: call `PreparedSocialLogin.abandon()`, which
|
|
152
|
+
* releases the same flow key. If the caller backs out after Session without
|
|
153
|
+
* calling `complete()` or that `abandon()`, the native flow-key cache is held until the process
|
|
154
|
+
* exits; `complete()` releases it in `finally`. The API has no cancel call for
|
|
155
|
+
* a pending registration.
|
|
156
|
+
*
|
|
157
|
+
* Not constructible by a consumer: exported from `index.ts` as a type only.
|
|
158
|
+
*/
|
|
159
|
+
class PendingDeviceRegistration {
|
|
160
|
+
/** @internal Constructed only by `PreparedSocialLogin.completeSocialSession`. */
|
|
161
|
+
constructor(fields) {
|
|
162
|
+
_PendingDeviceRegistration_instances.add(this);
|
|
163
|
+
_PendingDeviceRegistration_transport.set(this, void 0);
|
|
164
|
+
_PendingDeviceRegistration_registrationCodeVerifier.set(this, void 0);
|
|
165
|
+
_PendingDeviceRegistration_registrationFlowKey.set(this, void 0);
|
|
166
|
+
/** `null` until `complete()` creates it, when `confirmationRequired`. */
|
|
167
|
+
_PendingDeviceRegistration_authKey.set(this, void 0);
|
|
168
|
+
_PendingDeviceRegistration_resolveAuthKey.set(this, void 0);
|
|
169
|
+
_PendingDeviceRegistration_addDeviceApproval.set(this, void 0);
|
|
170
|
+
_PendingDeviceRegistration_consumed.set(this, false
|
|
171
|
+
// Set when DAA answered ACTIVE but saving its identifiers on this device
|
|
172
|
+
// failed: the next `complete()` retries only that save.
|
|
173
|
+
);
|
|
174
|
+
// Set when DAA answered ACTIVE but saving its identifiers on this device
|
|
175
|
+
// failed: the next `complete()` retries only that save.
|
|
176
|
+
_PendingDeviceRegistration_unsaved.set(this, null
|
|
177
|
+
/** @internal Constructed only by `PreparedSocialLogin.completeSocialSession`. */
|
|
178
|
+
);
|
|
179
|
+
this.registrationHandle = fields.registrationHandle;
|
|
180
|
+
this.clientEntityId = fields.clientEntityId;
|
|
181
|
+
this.expiresAt = fields.expiresAt;
|
|
182
|
+
this.deviceApproval = fields.deviceApproval;
|
|
183
|
+
this.confirmationRequired = fields.confirmationRequired;
|
|
184
|
+
__classPrivateFieldSet(this, _PendingDeviceRegistration_transport, fields.transport, "f");
|
|
185
|
+
__classPrivateFieldSet(this, _PendingDeviceRegistration_registrationCodeVerifier, fields.registrationCodeVerifier, "f");
|
|
186
|
+
__classPrivateFieldSet(this, _PendingDeviceRegistration_registrationFlowKey, fields.registrationFlowKey, "f");
|
|
187
|
+
__classPrivateFieldSet(this, _PendingDeviceRegistration_authKey, fields.authKey, "f");
|
|
188
|
+
__classPrivateFieldSet(this, _PendingDeviceRegistration_resolveAuthKey, fields.resolveAuthKey, "f");
|
|
189
|
+
__classPrivateFieldSet(this, _PendingDeviceRegistration_addDeviceApproval, fields.addDeviceApproval, "f");
|
|
190
|
+
Object.freeze(this);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Finish the ceremony: `POST /v1/accounts/auth/keys` with both
|
|
194
|
+
* `X-Device-Authorization` and `X-Registration-Flow-Authorization` bound to
|
|
195
|
+
* the exact body bytes. Both proofs name `register_device_key` version 3.
|
|
196
|
+
* DAA reads the body strictly and refuses any member outside the set in the
|
|
197
|
+
* class doc.
|
|
198
|
+
*
|
|
199
|
+
* The body is the same fields for every device — see the class doc.
|
|
200
|
+
* `codeSeal` is sent only with `addDeviceApproval` on (off by default). It
|
|
201
|
+
* commits to the AuthKey's 32-byte code secret. The same secret is sealed
|
|
202
|
+
* again until DAA says no request is waiting for this key, because DAA
|
|
203
|
+
* returns a waiting key's request and keeps its first seal; once
|
|
204
|
+
* `sendCodeSecret()` revealed it, the next registration seals a new one (see
|
|
205
|
+
* `codeSecrets.ts`). On `PENDING_APPROVAL` the returned
|
|
206
|
+
* `PendingDeviceApproval` holds the secret that request's seal commits to.
|
|
207
|
+
* DAA returns that seal, and if this SDK doesn't hold its secret (the app
|
|
208
|
+
* restarted after the secret was sent), the `PendingDeviceApproval`
|
|
209
|
+
* reports the code as unavailable (`matching_code_unavailable`) and sends
|
|
210
|
+
* nothing.
|
|
211
|
+
* DAA must run an enclave that accepts `codeSeal` (0.1.93 or later); older
|
|
212
|
+
* enclaves refuse the body. With the switch off, a `pending_approval` answer
|
|
213
|
+
* (a key already waiting from an earlier registration with it on) throws
|
|
214
|
+
* `contract_violation`: there is no secret to show its code from.
|
|
215
|
+
* The only input is the optional `riskSignals`, device signals for this
|
|
216
|
+
* registration. When given, they go into the body both proofs sign, so nothing
|
|
217
|
+
* between the app and DAA can change them. Without them, registration works
|
|
218
|
+
* the same and the device list shows the device without a model or OS.
|
|
219
|
+
*
|
|
220
|
+
* When `confirmationRequired` is `true`, pass `confirmAddDevice: true` once
|
|
221
|
+
* the user confirmed adding this device: only then is the AuthKey created
|
|
222
|
+
* and the registration sent. Without it, `complete()` throws
|
|
223
|
+
* `contract_violation` and nothing is created or sent. When
|
|
224
|
+
* `confirmationRequired` is `false`, `confirmAddDevice` is ignored.
|
|
225
|
+
*
|
|
226
|
+
* The input is checked before anything else: a malformed `riskSignals`, a
|
|
227
|
+
* `confirmAddDevice` that is not a boolean, or a missing confirmation throws
|
|
228
|
+
* `contract_violation` and leaves this registration unused, so the caller can
|
|
229
|
+
* call `complete()` again.
|
|
230
|
+
*
|
|
231
|
+
* The service returns a `KeyCredential` (see
|
|
232
|
+
* `wire/deviceRegistrationResultPayload.ts`): `credentialStatus: "active"`
|
|
233
|
+
* is `ACTIVE`, with `credentialId` as `deviceContext.authKeyId`;
|
|
234
|
+
* `pending_approval` is `PENDING_APPROVAL`; and `pending_activation` is
|
|
235
|
+
* `PENDING_ACTIVATION`. This endpoint never returns
|
|
236
|
+
* `RECOVERY_PENDING`. On `PENDING_APPROVAL`, the
|
|
237
|
+
* AuthKey is not acknowledged: it can't sign until an existing device
|
|
238
|
+
* approves it. On `PENDING_ACTIVATION` (approved, in the account's cool-down
|
|
239
|
+
* until `readyAt`) it is acknowledged but no context is returned: after
|
|
240
|
+
* `readyAt`, `DaaClient.restore` returns it. On `ACTIVE`, acknowledges
|
|
241
|
+
* the AuthKey with the context's `authKeyId` and `ownerBindingId`, so later
|
|
242
|
+
* `resolveOrCreate` returns `existing` and `SecureKeyStore.resolveExisting`
|
|
243
|
+
* can find it.
|
|
244
|
+
*
|
|
245
|
+
* @throws DaaError with `detail.kind === 'login_request_expired'` for `410`;
|
|
246
|
+
* `idempotency_conflict` for a `409` with `IDEMPOTENCY_KEY_REUSED`
|
|
247
|
+
* (`420034`); `contract_violation` for `LOGIN_REQUEST_CONSUMED` (`420039`),
|
|
248
|
+
* for a second call (except the retry after `registration_not_saved`,
|
|
249
|
+
* below), for unusable key material, for a response the SDK cannot read
|
|
250
|
+
* (including a `credentialStatus` other than `active`, `pending_approval`
|
|
251
|
+
* or `pending_activation`), and for malformed `riskSignals` (nothing is
|
|
252
|
+
* sent and this registration stays unused, so `complete()` can be called
|
|
253
|
+
* again), and for a missing `confirmAddDevice: true` when
|
|
254
|
+
* `confirmationRequired` (likewise nothing is sent and this registration
|
|
255
|
+
* stays unused); and `api` for any other status besides the documented
|
|
256
|
+
* `200`, including the `409` that DAA sends with `AUTH_KEY_BINDING_CONFLICT`
|
|
257
|
+
* (`420038`) or `PASSKEY_OWNER_CREDENTIAL_KIND_MISMATCH` (`420080`);
|
|
258
|
+
* `device_registration_limit`, `device_denied`, `device_approval_conflict`
|
|
259
|
+
* or `device_approval_unavailable` for the four add-a-device refusals (see
|
|
260
|
+
* `deviceRegistrationFailure`); `transport` with `retryable: false` when
|
|
261
|
+
* reading the AuthKey, or the queued prompt and `send()`, takes longer than
|
|
262
|
+
* two minutes (a later read or response is ignored; trying again needs a
|
|
263
|
+
* new login, unless DAA had answered and only saving its answer ran
|
|
264
|
+
* late: `complete()` then retries that save, as after
|
|
265
|
+
* `registration_not_saved`. If that late save finished first, the retry
|
|
266
|
+
* throws `contract_violation` ("already been consumed"): the identifiers
|
|
267
|
+
* are saved, and `DaaClient.restore` finds the key).
|
|
268
|
+
* `user_cancelled` when the user dismisses the authentication
|
|
269
|
+
* prompt: nothing was sent, but this registration is used up, so trying
|
|
270
|
+
* again needs a new login (which reuses the same AuthKey).
|
|
271
|
+
* When `confirmationRequired`, the AuthKey is created here, so a native
|
|
272
|
+
* failure creating it (for example `device_lock_not_set` or
|
|
273
|
+
* `device_not_supported`) is thrown here too; nothing was sent, but this
|
|
274
|
+
* registration is used up, so trying again needs a new login.
|
|
275
|
+
* `registration_not_saved` when DAA answered `ACTIVE` or
|
|
276
|
+
* `PENDING_ACTIVATION` but saving its
|
|
277
|
+
* `authKeyId` and `ownerBindingId` on this device failed (for example a
|
|
278
|
+
* Keychain or Keystore write error). The device is registered with Circle.
|
|
279
|
+
* Call `complete()` again: it sends nothing, retries only the save, and
|
|
280
|
+
* on success returns the same result (its input is ignored).
|
|
281
|
+
* The retry has the same two-minute deadline. If a newer registration of
|
|
282
|
+
* the same key answered in the meantime, the retry throws
|
|
283
|
+
* `contract_violation` and saves nothing: the newer registration's
|
|
284
|
+
* identifiers are the ones to keep.
|
|
285
|
+
* If the key on the device was replaced since (`forgetLocalKey`, then a
|
|
286
|
+
* new sign-in), the retry also throws `contract_violation` and saves
|
|
287
|
+
* nothing. If the save fails with `key_invalidated` or
|
|
288
|
+
* `device_not_initialized` (the key is gone), that kind is thrown as is and
|
|
289
|
+
* nothing is kept to retry: no save can succeed. Other native kinds (for
|
|
290
|
+
* example `device_lock_not_set` or `device_not_supported`, which the user
|
|
291
|
+
* can fix or retry) come as `registration_not_saved`, with the original on
|
|
292
|
+
* `cause`.
|
|
293
|
+
*/
|
|
294
|
+
async complete(input) {
|
|
295
|
+
const unsaved = __classPrivateFieldGet(this, _PendingDeviceRegistration_unsaved, "f");
|
|
296
|
+
if (unsaved !== null) {
|
|
297
|
+
__classPrivateFieldSet(this, _PendingDeviceRegistration_unsaved, null, "f");
|
|
298
|
+
return await __classPrivateFieldGet(this, _PendingDeviceRegistration_instances, "m", _PendingDeviceRegistration_save).call(this, unsaved);
|
|
299
|
+
}
|
|
300
|
+
if (__classPrivateFieldGet(this, _PendingDeviceRegistration_consumed, "f")) {
|
|
301
|
+
throw (0, errors_1.contractViolation)('this pending device registration has already been consumed');
|
|
302
|
+
}
|
|
303
|
+
const riskSignals = completeRiskSignals(input);
|
|
304
|
+
const confirmed = completeConfirmation(input);
|
|
305
|
+
if (this.confirmationRequired && !confirmed) {
|
|
306
|
+
throw (0, errors_1.contractViolation)('adding this device needs the user to confirm first; call complete({ confirmAddDevice: true }) after they do');
|
|
307
|
+
}
|
|
308
|
+
__classPrivateFieldSet(this, _PendingDeviceRegistration_consumed, true, "f");
|
|
309
|
+
try {
|
|
310
|
+
// Reading the key (native) has its own deadline: the call isn't queued
|
|
311
|
+
// yet, and a read that finishes late can't go on to queue and send.
|
|
312
|
+
// Creating it, after the user confirmed, is under the same deadline.
|
|
313
|
+
const authKey = __classPrivateFieldGet(this, _PendingDeviceRegistration_authKey, "f") ?? (__classPrivateFieldSet(this, _PendingDeviceRegistration_authKey, await withDeadline(() => __classPrivateFieldGet(this, _PendingDeviceRegistration_resolveAuthKey, "f").call(this)), "f"));
|
|
314
|
+
const { deviceKeyPublicKey, authKeyThumbprint, thumbprintBytes } = await withDeadline(() => readAuthKey(authKey));
|
|
315
|
+
return await (0, codeSecrets_1.oneAtATime)(authKeyThumbprint, () => withDeadline(async (call) => {
|
|
316
|
+
// Without `addDeviceApproval` the body is what it was before add-a-device:
|
|
317
|
+
// no secret and no codeSeal, which an enclave older than 0.1.93 accepts.
|
|
318
|
+
const codeSecret = __classPrivateFieldGet(this, _PendingDeviceRegistration_addDeviceApproval, "f")
|
|
319
|
+
? await (0, codeSecrets_1.codeSecretFor)(authKeyThumbprint, authKey, () => call.late)
|
|
320
|
+
: null;
|
|
321
|
+
if (call.late) {
|
|
322
|
+
throw completeTimedOut();
|
|
323
|
+
}
|
|
324
|
+
const idempotencyKey = (0, random_1.randomUuidV4)();
|
|
325
|
+
const bodyBytes = (0, serialization_1.serializeBody)({
|
|
326
|
+
type: DEVICE_KEY_TYPE,
|
|
327
|
+
idempotencyKey,
|
|
328
|
+
registrationHandle: this.registrationHandle,
|
|
329
|
+
registrationCodeVerifier: __classPrivateFieldGet(this, _PendingDeviceRegistration_registrationCodeVerifier, "f"),
|
|
330
|
+
deviceKeyPublicKey,
|
|
331
|
+
...(codeSecret === null
|
|
332
|
+
? {}
|
|
333
|
+
: { codeSeal: (0, base64url_1.toBase64Url)((0, matchingCode_1.codeSeal)(thumbprintBytes, codeSecret)) }),
|
|
334
|
+
...(riskSignals === undefined ? {} : { riskSignals }),
|
|
335
|
+
});
|
|
336
|
+
const { deviceJws, flowJws } = await (0, registrationAuthorization_1.authorizeRegistrationComplete)({
|
|
337
|
+
bodyBytes,
|
|
338
|
+
registrationHandle: this.registrationHandle,
|
|
339
|
+
registrationCodeVerifier: __classPrivateFieldGet(this, _PendingDeviceRegistration_registrationCodeVerifier, "f"),
|
|
340
|
+
clientEntityId: this.clientEntityId,
|
|
341
|
+
flowKey: __classPrivateFieldGet(this, _PendingDeviceRegistration_registrationFlowKey, "f"),
|
|
342
|
+
authKey,
|
|
343
|
+
});
|
|
344
|
+
if (call.late) {
|
|
345
|
+
throw completeTimedOut();
|
|
346
|
+
}
|
|
347
|
+
call.sentSecret = codeSecret;
|
|
348
|
+
if (codeSecret !== null) {
|
|
349
|
+
(0, codeSecrets_1.sealingCodeSecret)(authKeyThumbprint, codeSecret);
|
|
350
|
+
}
|
|
351
|
+
let response;
|
|
352
|
+
try {
|
|
353
|
+
response = await __classPrivateFieldGet(this, _PendingDeviceRegistration_transport, "f").send({
|
|
354
|
+
method: 'POST',
|
|
355
|
+
path: registrationAuthorization_1.KEY_REGISTRATION_PATH,
|
|
356
|
+
query: null,
|
|
357
|
+
headers: {
|
|
358
|
+
'Content-Type': 'application/json',
|
|
359
|
+
[registrationAuthorization_1.REGISTRATION_DEVICE_AUTHORIZATION_HEADER]: deviceJws,
|
|
360
|
+
[registrationAuthorization_1.REGISTRATION_FLOW_AUTHORIZATION_HEADER]: flowJws,
|
|
361
|
+
},
|
|
362
|
+
bodyBytes,
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
catch (error) {
|
|
366
|
+
// No answer (say, the relay timed out): DAA may still add the
|
|
367
|
+
// request with this secret's seal.
|
|
368
|
+
(0, codeSecrets_1.holdCodeSecret)(codeSecret);
|
|
369
|
+
throw error;
|
|
370
|
+
}
|
|
371
|
+
if (call.late) {
|
|
372
|
+
throw completeTimedOut();
|
|
373
|
+
}
|
|
374
|
+
const failure = (0, loginFailure_1.loginStepFailure)(response, idempotencyKey);
|
|
375
|
+
if (failure !== null && NO_WAITING_REQUEST_KINDS.has(failure.detail.kind)) {
|
|
376
|
+
// Not late: checked just above, with nothing awaited since.
|
|
377
|
+
if ((0, codeSecrets_1.dropCodeSecret)(authKeyThumbprint, codeSecret) && codeSecret !== null) {
|
|
378
|
+
call.afterDeadline = () => (0, codeSecrets_1.deleteStoredCodeSecret)(authKey, codeSecret);
|
|
379
|
+
}
|
|
380
|
+
throw failure;
|
|
381
|
+
}
|
|
382
|
+
if (response.status < 200 || response.status >= 300) {
|
|
383
|
+
// Any other refusal, or a status from something between the app and
|
|
384
|
+
// DAA (a 504 from a relay that timed out), doesn't say whether DAA
|
|
385
|
+
// added the request, so keep the secret as for no answer.
|
|
386
|
+
(0, codeSecrets_1.holdCodeSecret)(codeSecret);
|
|
387
|
+
}
|
|
388
|
+
if (failure !== null) {
|
|
389
|
+
throw failure;
|
|
390
|
+
}
|
|
391
|
+
const result = (0, resourceRequest_1.decodeResourceResponse)({
|
|
392
|
+
response,
|
|
393
|
+
expectedStatus: 200,
|
|
394
|
+
decode: (value) => (0, deviceRegistrationResultPayload_1.toDeviceRegistrationResult)(value, this.clientEntityId),
|
|
395
|
+
});
|
|
396
|
+
const dropped = result.status !== 'PENDING_APPROVAL' && (0, codeSecrets_1.dropCodeSecret)(authKeyThumbprint, codeSecret);
|
|
397
|
+
try {
|
|
398
|
+
return await __classPrivateFieldGet(this, _PendingDeviceRegistration_instances, "m", _PendingDeviceRegistration_finish).call(this, result, authKeyThumbprint, thumbprintBytes, codeSecret, call);
|
|
399
|
+
}
|
|
400
|
+
finally {
|
|
401
|
+
// After the save: nothing may be awaited between DAA's answer and
|
|
402
|
+
// the acknowledgement (see `ACTIVE` in `#finish`). Outside the
|
|
403
|
+
// deadline, so a slow delete can't fail a call whose answer was
|
|
404
|
+
// saved, but before the key's queue moves on, so the next
|
|
405
|
+
// registration can't read this secret back first, unless the
|
|
406
|
+
// delete passes its time limit (`deleteWithinLimit` in
|
|
407
|
+
// `codeSecrets.ts`). Skipped once the deadline passed: the queue
|
|
408
|
+
// already moved on.
|
|
409
|
+
if (dropped && codeSecret !== null && !call.late) {
|
|
410
|
+
call.afterDeadline = () => (0, codeSecrets_1.deleteStoredCodeSecret)(authKey, codeSecret);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}));
|
|
414
|
+
}
|
|
415
|
+
finally {
|
|
416
|
+
await (0, RegistrationFlowKey_1.releaseQuietly)(__classPrivateFieldGet(this, _PendingDeviceRegistration_registrationFlowKey, "f"));
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
exports.PendingDeviceRegistration = PendingDeviceRegistration;
|
|
421
|
+
_PendingDeviceRegistration_transport = new WeakMap(), _PendingDeviceRegistration_registrationCodeVerifier = new WeakMap(), _PendingDeviceRegistration_registrationFlowKey = new WeakMap(), _PendingDeviceRegistration_authKey = new WeakMap(), _PendingDeviceRegistration_resolveAuthKey = new WeakMap(), _PendingDeviceRegistration_addDeviceApproval = new WeakMap(), _PendingDeviceRegistration_consumed = new WeakMap(), _PendingDeviceRegistration_unsaved = new WeakMap(), _PendingDeviceRegistration_instances = new WeakSet(), _PendingDeviceRegistration_key = function _PendingDeviceRegistration_key() {
|
|
422
|
+
if (__classPrivateFieldGet(this, _PendingDeviceRegistration_authKey, "f") === null) {
|
|
423
|
+
throw (0, errors_1.contractViolation)('this pending device registration has no AuthKey yet');
|
|
424
|
+
}
|
|
425
|
+
return __classPrivateFieldGet(this, _PendingDeviceRegistration_authKey, "f");
|
|
426
|
+
}, _PendingDeviceRegistration_acknowledge =
|
|
427
|
+
/**
|
|
428
|
+
* Save the identifiers DAA assigned. If that fails, keep them so the next
|
|
429
|
+
* `complete()` can retry the save without sending Complete again: DAA already
|
|
430
|
+
* answered, and the spent registration handle can't be sent twice. The
|
|
431
|
+
* caller sets `onLate` first, so a save still running at the deadline is
|
|
432
|
+
* kept for retry too.
|
|
433
|
+
*
|
|
434
|
+
* A native save that runs past the deadline can't be cancelled, but it can't
|
|
435
|
+
* overwrite a newer one either: the AuthKey handle queues each save behind
|
|
436
|
+
* the one before it (`#ackTail`), so a newer registration's save lands last.
|
|
437
|
+
*/
|
|
438
|
+
async function _PendingDeviceRegistration_acknowledge(unsaved) {
|
|
439
|
+
try {
|
|
440
|
+
await __classPrivateFieldGet(this, _PendingDeviceRegistration_instances, "m", _PendingDeviceRegistration_key).call(this).acknowledgeRegistration(unsaved.registration);
|
|
441
|
+
}
|
|
442
|
+
catch (error) {
|
|
443
|
+
throw __classPrivateFieldGet(this, _PendingDeviceRegistration_instances, "m", _PendingDeviceRegistration_notSaved).call(this, unsaved, error);
|
|
444
|
+
}
|
|
445
|
+
__classPrivateFieldGet(this, _PendingDeviceRegistration_instances, "m", _PendingDeviceRegistration_forget).call(this, unsaved);
|
|
446
|
+
return unsaved.result;
|
|
447
|
+
}, _PendingDeviceRegistration_forget = function _PendingDeviceRegistration_forget(unsaved) {
|
|
448
|
+
if (__classPrivateFieldGet(this, _PendingDeviceRegistration_unsaved, "f") === unsaved) {
|
|
449
|
+
__classPrivateFieldSet(this, _PendingDeviceRegistration_unsaved, null, "f");
|
|
450
|
+
}
|
|
451
|
+
if (newestAnswer.get(unsaved.authKeyThumbprint) === unsaved) {
|
|
452
|
+
newestAnswer.delete(unsaved.authKeyThumbprint);
|
|
453
|
+
}
|
|
454
|
+
}, _PendingDeviceRegistration_notSaved = function _PendingDeviceRegistration_notSaved(unsaved, error) {
|
|
455
|
+
if (error instanceof errors_1.DaaError && KEY_GONE_KINDS.has(error.detail.kind)) {
|
|
456
|
+
__classPrivateFieldGet(this, _PendingDeviceRegistration_instances, "m", _PendingDeviceRegistration_forget).call(this, unsaved);
|
|
457
|
+
return error;
|
|
458
|
+
}
|
|
459
|
+
__classPrivateFieldSet(this, _PendingDeviceRegistration_unsaved, unsaved, "f");
|
|
460
|
+
return (0, errors_1.registrationNotSaved)(error);
|
|
461
|
+
}, _PendingDeviceRegistration_save =
|
|
462
|
+
/**
|
|
463
|
+
* A retried save: queued behind any registration in flight for the same key,
|
|
464
|
+
* under the same deadline as `complete()`, and refused once a newer
|
|
465
|
+
* registration of the key answered, or once the key on the device
|
|
466
|
+
* is no longer this registration's.
|
|
467
|
+
*/
|
|
468
|
+
async function _PendingDeviceRegistration_save(unsaved) {
|
|
469
|
+
return await (0, codeSecrets_1.oneAtATime)(unsaved.authKeyThumbprint, () => withDeadline(async (call) => {
|
|
470
|
+
if (newestAnswer.get(unsaved.authKeyThumbprint) !== unsaved) {
|
|
471
|
+
throw (0, errors_1.contractViolation)('a newer registration of this AuthKey replaced this one; use its result');
|
|
472
|
+
}
|
|
473
|
+
call.onLate = () => {
|
|
474
|
+
__classPrivateFieldSet(this, _PendingDeviceRegistration_unsaved, unsaved, "f");
|
|
475
|
+
};
|
|
476
|
+
// The native save writes to whatever key the slot holds now. After
|
|
477
|
+
// `forgetLocalKey` and a new sign-in that is a different key, and
|
|
478
|
+
// these identifiers would overwrite its own.
|
|
479
|
+
let current;
|
|
480
|
+
try {
|
|
481
|
+
current = await __classPrivateFieldGet(this, _PendingDeviceRegistration_instances, "m", _PendingDeviceRegistration_key).call(this).thumbprint();
|
|
482
|
+
}
|
|
483
|
+
catch (error) {
|
|
484
|
+
throw __classPrivateFieldGet(this, _PendingDeviceRegistration_instances, "m", _PendingDeviceRegistration_notSaved).call(this, unsaved, error);
|
|
485
|
+
}
|
|
486
|
+
if (call.late) {
|
|
487
|
+
// The key's queue moved on at the deadline, so a newer Complete may
|
|
488
|
+
// have saved since the check above. Save nothing now: `onLate` kept
|
|
489
|
+
// the save, and the next `complete()` checks again.
|
|
490
|
+
throw completeTimedOut();
|
|
491
|
+
}
|
|
492
|
+
if (current !== unsaved.authKeyThumbprint) {
|
|
493
|
+
newestAnswer.delete(unsaved.authKeyThumbprint);
|
|
494
|
+
throw (0, errors_1.contractViolation)("this device's AuthKey was replaced since this registration; sign in again");
|
|
495
|
+
}
|
|
496
|
+
return await __classPrivateFieldGet(this, _PendingDeviceRegistration_instances, "m", _PendingDeviceRegistration_acknowledge).call(this, unsaved);
|
|
497
|
+
}));
|
|
498
|
+
}, _PendingDeviceRegistration_saveAnswer =
|
|
499
|
+
/**
|
|
500
|
+
* Save a final answer's identifiers as the newest answer for its key. If
|
|
501
|
+
* the deadline passes while the save runs, the answer is kept for the next
|
|
502
|
+
* `complete()`.
|
|
503
|
+
*/
|
|
504
|
+
async function _PendingDeviceRegistration_saveAnswer(answer, call) {
|
|
505
|
+
newestAnswer.set(answer.authKeyThumbprint, answer);
|
|
506
|
+
call.onLate = () => {
|
|
507
|
+
__classPrivateFieldSet(this, _PendingDeviceRegistration_unsaved, answer, "f");
|
|
508
|
+
};
|
|
509
|
+
return await __classPrivateFieldGet(this, _PendingDeviceRegistration_instances, "m", _PendingDeviceRegistration_acknowledge).call(this, answer);
|
|
510
|
+
}, _PendingDeviceRegistration_finish = async function _PendingDeviceRegistration_finish(result, authKeyThumbprint, thumbprintBytes, codeSecret, call) {
|
|
511
|
+
switch (result.status) {
|
|
512
|
+
case 'ACTIVE':
|
|
513
|
+
// Keep the server-assigned authKeyId as the JWS kid, but retain the
|
|
514
|
+
// local key's thumbprint alongside it. `DaaClient.forUser` checks this
|
|
515
|
+
// pairing every time it resolves the key for a signed operation.
|
|
516
|
+
//
|
|
517
|
+
// The acknowledgement records the server-assigned identifiers beside
|
|
518
|
+
// the key. That record is what `SecureKeyStore.resolveExisting` reads
|
|
519
|
+
// back without creating a key: `authKeyId` is the `kid` the service
|
|
520
|
+
// looks the key up by. It is an upsert, so a re-registration of the
|
|
521
|
+
// same key that assigned new identifiers replaces the stored ones.
|
|
522
|
+
//
|
|
523
|
+
// No await before the acknowledgement: the queued call's deadline can
|
|
524
|
+
// only pass at an await, and a late call must not overwrite the
|
|
525
|
+
// identifiers a newer Complete for the key stored.
|
|
526
|
+
const boundContext = (0, DaaUserContext_1.bindAuthKeyToContext)(result.context, authKeyThumbprint);
|
|
527
|
+
const answer = Object.freeze({
|
|
528
|
+
result: Object.freeze({ ...result, context: boundContext }),
|
|
529
|
+
authKeyThumbprint,
|
|
530
|
+
registration: {
|
|
531
|
+
authKeyId: result.context.deviceContext.authKeyId,
|
|
532
|
+
ownerBindingId: result.context.deviceContext.ownerBindingId,
|
|
533
|
+
},
|
|
534
|
+
});
|
|
535
|
+
return await __classPrivateFieldGet(this, _PendingDeviceRegistration_instances, "m", _PendingDeviceRegistration_saveAnswer).call(this, answer, call);
|
|
536
|
+
case 'PENDING_ACTIVATION':
|
|
537
|
+
// Approved from another device: the key is the account's, so its
|
|
538
|
+
// identifiers are final and are stored now, letting
|
|
539
|
+
// `DaaClient.restore` return the ACTIVE context once `readyAt` passes
|
|
540
|
+
// (before then DAA answers it with `device_pending`). No context is
|
|
541
|
+
// returned here, so nothing can sign before `readyAt`. A failed save
|
|
542
|
+
// is retried as for `ACTIVE`.
|
|
543
|
+
return await __classPrivateFieldGet(this, _PendingDeviceRegistration_instances, "m", _PendingDeviceRegistration_saveAnswer).call(this, Object.freeze({
|
|
544
|
+
result: Object.freeze({
|
|
545
|
+
status: 'PENDING_ACTIVATION',
|
|
546
|
+
authKeyId: result.authKeyId,
|
|
547
|
+
readyAt: result.readyAt,
|
|
548
|
+
}),
|
|
549
|
+
authKeyThumbprint,
|
|
550
|
+
registration: { authKeyId: result.authKeyId, ownerBindingId: result.ownerBindingId },
|
|
551
|
+
}), call);
|
|
552
|
+
case 'PENDING_APPROVAL':
|
|
553
|
+
if (codeSecret === null) {
|
|
554
|
+
// Only a key already waiting from a registration sent with
|
|
555
|
+
// `addDeviceApproval` on: there is no secret to show its code from.
|
|
556
|
+
throw (0, errors_1.contractViolation)('DAA returned pending_approval for a registration sent without codeSeal; turn on addDeviceApproval');
|
|
557
|
+
}
|
|
558
|
+
return Object.freeze({
|
|
559
|
+
status: 'PENDING_APPROVAL',
|
|
560
|
+
pendingApproval: (0, PendingDeviceApproval_1.newPendingDeviceApproval)({
|
|
561
|
+
requestId: result.requestId,
|
|
562
|
+
authKeyId: result.authKeyId,
|
|
563
|
+
expiresAt: result.expiresAt,
|
|
564
|
+
codeNonce: result.codeNonce,
|
|
565
|
+
authKeyThumbprint,
|
|
566
|
+
authKey: __classPrivateFieldGet(this, _PendingDeviceRegistration_instances, "m", _PendingDeviceRegistration_key).call(this),
|
|
567
|
+
// `null` when DAA's seal for the request isn't this device's:
|
|
568
|
+
// the code is unavailable and nothing is sent for it.
|
|
569
|
+
codeSecret: (0, codeSecrets_1.codeSecretForRequest)(authKeyThumbprint, thumbprintBytes, codeSecret, result.requestId, result.codeSeal),
|
|
570
|
+
transport: __classPrivateFieldGet(this, _PendingDeviceRegistration_transport, "f"),
|
|
571
|
+
}),
|
|
572
|
+
});
|
|
573
|
+
default: {
|
|
574
|
+
const exhaustive = result;
|
|
575
|
+
void exhaustive;
|
|
576
|
+
throw (0, errors_1.contractViolation)('device registration status is not in the closed set');
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
};
|
|
580
|
+
async function readAuthKey(authKey) {
|
|
581
|
+
const deviceKeyPublicKey = await authKey.publicKeySpkiBase64Url();
|
|
582
|
+
if (!AUTH_KEY_PUBLIC_KEY.test(deviceKeyPublicKey)) {
|
|
583
|
+
throw (0, errors_1.contractViolation)('AuthKey public key must be a 122-character unpadded Base64URL P-256 SPKI');
|
|
584
|
+
}
|
|
585
|
+
const authKeyThumbprint = await authKey.thumbprint();
|
|
586
|
+
const thumbprintBytes = (0, matchingCode_1.canonicalBytes32)(authKeyThumbprint);
|
|
587
|
+
if (thumbprintBytes === null) {
|
|
588
|
+
throw (0, errors_1.contractViolation)('AuthKey thumbprint must be a 43-character unpadded Base64URL digest');
|
|
589
|
+
}
|
|
590
|
+
return { deviceKeyPublicKey, authKeyThumbprint, thumbprintBytes };
|
|
591
|
+
}
|
|
592
|
+
/**
|
|
593
|
+
* Check the optional `complete()` input and build the `riskSignals` member.
|
|
594
|
+
*
|
|
595
|
+
* The enclave refuses a registration body whose `riskSignals` has any member
|
|
596
|
+
* besides these three, or a member that is not a string, so an unknown or
|
|
597
|
+
* malformed member is refused here rather than dropped: the caller learns of
|
|
598
|
+
* it before a registration is spent. Building a new object rather than
|
|
599
|
+
* forwarding the caller's also fixes the member order in the signed bytes.
|
|
600
|
+
*/
|
|
601
|
+
function completeRiskSignals(input) {
|
|
602
|
+
if (input === undefined)
|
|
603
|
+
return undefined;
|
|
604
|
+
(0, requestBody_1.requireBodyObject)(input, 'complete input');
|
|
605
|
+
(0, requestBody_1.requireKnownProperties)(input, COMPLETE_INPUT_PROPERTIES, 'complete input');
|
|
606
|
+
const { riskSignals } = input;
|
|
607
|
+
if (riskSignals === undefined)
|
|
608
|
+
return undefined;
|
|
609
|
+
(0, requestBody_1.requireBodyObject)(riskSignals, 'registration risk signals');
|
|
610
|
+
(0, requestBody_1.requireKnownProperties)(riskSignals, RISK_SIGNAL_PROPERTIES, 'registration risk signals');
|
|
611
|
+
const { ipAddress, sessionId, deviceId } = riskSignals;
|
|
612
|
+
requireOptionalRiskSignal(ipAddress, 'ipAddress');
|
|
613
|
+
requireOptionalRiskSignal(sessionId, 'sessionId');
|
|
614
|
+
requireOptionalRiskSignal(deviceId, 'deviceId');
|
|
615
|
+
// None of the members is required, so `{}` is a valid `riskSignals` (the
|
|
616
|
+
// enclave and DAA both accept it) and is sent as the empty object the caller
|
|
617
|
+
// passed, as on transfers and withdrawals.
|
|
618
|
+
return {
|
|
619
|
+
...(ipAddress === undefined ? {} : { ipAddress }),
|
|
620
|
+
...(sessionId === undefined ? {} : { sessionId }),
|
|
621
|
+
...(deviceId === undefined ? {} : { deviceId }),
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
/** `complete()`'s `confirmAddDevice`: whether the user confirmed adding this device. */
|
|
625
|
+
function completeConfirmation(input) {
|
|
626
|
+
const confirmAddDevice = input?.confirmAddDevice;
|
|
627
|
+
if (confirmAddDevice !== undefined && typeof confirmAddDevice !== 'boolean') {
|
|
628
|
+
throw (0, errors_1.contractViolation)('confirmAddDevice must be a boolean');
|
|
629
|
+
}
|
|
630
|
+
return confirmAddDevice === true;
|
|
631
|
+
}
|
|
632
|
+
function requireOptionalRiskSignal(value, name) {
|
|
633
|
+
if (value !== undefined && (typeof value !== 'string' || value.length === 0)) {
|
|
634
|
+
throw (0, errors_1.contractViolation)(`registration risk signal ${name} must be a non-empty string`);
|
|
635
|
+
}
|
|
636
|
+
}
|