@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,267 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.postSignedResource = postSignedResource;
|
|
21
|
+
exports.getSignedResource = getSignedResource;
|
|
22
|
+
exports.authorizeSignedPost = authorizeSignedPost;
|
|
23
|
+
exports.postAuthorizedResource = postAuthorizedResource;
|
|
24
|
+
// Signed public POST/GET: either serialize-once body bytes, or no body at all,
|
|
25
|
+
// plus a fresh `X-Device-Authorization` compact JWS.
|
|
26
|
+
//
|
|
27
|
+
// Signed v1 operations carry `query = null`. Failures are classified on the
|
|
28
|
+
// numeric DAA status code only, through `wire/daaStatusCodes.ts`.
|
|
29
|
+
// An invalid, missing, replayed, or mismatched authorization becomes
|
|
30
|
+
// `contract_violation` — the credential rejection a caller must handle on every
|
|
31
|
+
// signed request. The one exception is a `DEVICE_AUTHORIZATION_INVALID` whose
|
|
32
|
+
// own `iat`/`exp` fail DAA's 60-second freshness rule against the response's
|
|
33
|
+
// HTTP `Date`: that is `clock_skew` (see `isClockSkewed`). A `409` whose
|
|
34
|
+
// body carries `IDEMPOTENCY_KEY_REUSED` (`420034`) becomes
|
|
35
|
+
// `idempotency_conflict`, with the key recovered from the same request bytes
|
|
36
|
+
// that were signed and sent, not the (unsigned) response body; the caller
|
|
37
|
+
// reconciles the original operation rather than replacing the key.
|
|
38
|
+
//
|
|
39
|
+
// DAA has no code for an expired device authorization, a missing one, or a
|
|
40
|
+
// revoked credential: it reports them as `DEVICE_AUTHORIZATION_INVALID` or,
|
|
41
|
+
// on context refresh, `DEVICE_AUTHORIZATION_REQUEST_MISMATCH`, and the SDK
|
|
42
|
+
// classifies the code it receives. So a signed call is sent once, with no
|
|
43
|
+
// fresh-JWS retry, and no DAA response produces `device_revoked`. A
|
|
44
|
+
// non-numeric string `code` is `api`, even when it is the name of one of these
|
|
45
|
+
// conditions or of a row this mapping classifies.
|
|
46
|
+
//
|
|
47
|
+
// `AccountsClient.create` (`create_account`),
|
|
48
|
+
// `TransfersClient.create` (`transfer`), and `WithdrawalsClient.create`
|
|
49
|
+
// (`withdrawal`) call `postSignedResource`. `ContractExecutionsClient`
|
|
50
|
+
// (`contract_execution`) splits the same POST in two —
|
|
51
|
+
// `authorizeSignedPost` once, then `postAuthorizedResource` for the first send
|
|
52
|
+
// and every retry — because DAA requires a replay to carry the originally
|
|
53
|
+
// accepted authorization, not a fresh one; see
|
|
54
|
+
// `models/PreparedContractExecution.ts`. `DaaUserClient.refreshContext`
|
|
55
|
+
// (`get_device_context`) calls `getSignedResource` — the device-authorization
|
|
56
|
+
// contract treats "signed context refresh" alongside protected writes, and
|
|
57
|
+
// `securekey/SecureKey.ts` lists it alongside them as one of the defined DAA
|
|
58
|
+
// operations signing is reachable for.
|
|
59
|
+
const deviceAuthorization_1 = require("../auth/deviceAuthorization");
|
|
60
|
+
const errors_1 = require("../errors");
|
|
61
|
+
const headers_1 = require("../transport/headers");
|
|
62
|
+
const daaStatusCodes_1 = require("../wire/daaStatusCodes");
|
|
63
|
+
const errorEnvelope_1 = require("../wire/errorEnvelope");
|
|
64
|
+
const resourceRequest_1 = require("./resourceRequest");
|
|
65
|
+
/** Execute a public POST with a fresh registered-device authorization header. */
|
|
66
|
+
async function postSignedResource({ transport, operation, authKey, authKeyId, bodyBytes, expectedStatus, decode, }) {
|
|
67
|
+
const profile = (0, deviceAuthorization_1.deviceAuthorizationProfile)(operation);
|
|
68
|
+
if (profile.method !== 'POST') {
|
|
69
|
+
throw (0, errors_1.contractViolation)('postSignedResource only sends POST registry operations');
|
|
70
|
+
}
|
|
71
|
+
return postAuthorizedResource({
|
|
72
|
+
transport,
|
|
73
|
+
operation,
|
|
74
|
+
bodyBytes,
|
|
75
|
+
authorization: await authorizeSignedPost({ operation, authKey, authKeyId, bodyBytes }),
|
|
76
|
+
expectedStatuses: [expectedStatus],
|
|
77
|
+
decode,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/** No body to serialize for a bodyless signed read; the signature hashes the empty byte array. */
|
|
81
|
+
const EMPTY_BODY = new Uint8Array(0);
|
|
82
|
+
/**
|
|
83
|
+
* Execute a public GET with a fresh registered-device authorization header.
|
|
84
|
+
*
|
|
85
|
+
* The only registry operation this reaches is `get_device_context`
|
|
86
|
+
* (`DaaUserClient.refreshContext`). There is no request body to serialize or
|
|
87
|
+
* sign over: `authorizeExactRequest` hashes the empty byte array per the
|
|
88
|
+
* bodyless-request rule, and nothing is sent as a request entity — the same
|
|
89
|
+
* bodyless shape `resourceRequest.ts`'s unsigned `readResource` sends.
|
|
90
|
+
*/
|
|
91
|
+
async function getSignedResource({ transport, operation, authKey, authKeyId, expectedStatus, decode, }) {
|
|
92
|
+
const profile = (0, deviceAuthorization_1.deviceAuthorizationProfile)(operation);
|
|
93
|
+
if (profile.method !== 'GET') {
|
|
94
|
+
throw (0, errors_1.contractViolation)('getSignedResource only sends GET registry operations');
|
|
95
|
+
}
|
|
96
|
+
const authorization = await (0, deviceAuthorization_1.authorizeExactRequest)({
|
|
97
|
+
authKey,
|
|
98
|
+
authKeyId,
|
|
99
|
+
operation,
|
|
100
|
+
bodyBytes: EMPTY_BODY,
|
|
101
|
+
});
|
|
102
|
+
const response = await sendSignedGet({
|
|
103
|
+
transport,
|
|
104
|
+
path: profile.canonicalPath,
|
|
105
|
+
authorization,
|
|
106
|
+
});
|
|
107
|
+
if (response.status !== expectedStatus) {
|
|
108
|
+
throw mapSignedRequestFailure(response, EMPTY_BODY, authorization);
|
|
109
|
+
}
|
|
110
|
+
return (0, resourceRequest_1.decodeResourceResponse)({ response, expectedStatus, decode });
|
|
111
|
+
}
|
|
112
|
+
function sendSignedGet(args) {
|
|
113
|
+
return args.transport.send({
|
|
114
|
+
method: 'GET',
|
|
115
|
+
path: args.path,
|
|
116
|
+
query: null,
|
|
117
|
+
headers: {
|
|
118
|
+
[deviceAuthorization_1.DEVICE_AUTHORIZATION_HEADER]: args.authorization,
|
|
119
|
+
},
|
|
120
|
+
bodyBytes: null,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
function sendAuthorizedPost(args) {
|
|
124
|
+
return args.transport.send({
|
|
125
|
+
method: 'POST',
|
|
126
|
+
path: args.path,
|
|
127
|
+
query: null,
|
|
128
|
+
headers: {
|
|
129
|
+
'Content-Type': 'application/json',
|
|
130
|
+
[deviceAuthorization_1.DEVICE_AUTHORIZATION_HEADER]: args.authorization,
|
|
131
|
+
},
|
|
132
|
+
bodyBytes: args.bodyBytes,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Sign a POST registry operation's authorization over exact bytes, without
|
|
137
|
+
* sending anything. The signing half of {@link postSignedResource}.
|
|
138
|
+
*/
|
|
139
|
+
async function authorizeSignedPost({ operation, authKey, authKeyId, bodyBytes, approval, }) {
|
|
140
|
+
if ((0, deviceAuthorization_1.deviceAuthorizationProfile)(operation).method !== 'POST') {
|
|
141
|
+
throw (0, errors_1.contractViolation)('authorizeSignedPost only signs POST registry operations');
|
|
142
|
+
}
|
|
143
|
+
return (0, deviceAuthorization_1.authorizeExactRequest)({
|
|
144
|
+
authKey,
|
|
145
|
+
authKeyId,
|
|
146
|
+
operation,
|
|
147
|
+
bodyBytes,
|
|
148
|
+
...(approval === undefined ? {} : { approval }),
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Send a POST with an authorization signed earlier, unchanged — the sending
|
|
153
|
+
* half of {@link postSignedResource}, and the one to call again on a retry.
|
|
154
|
+
*
|
|
155
|
+
* Nothing here signs, and nothing reads the authorization's `exp`: an exact
|
|
156
|
+
* replay of a request DAA already accepted is answered from its stored result
|
|
157
|
+
* whether or not the JWS has expired, and DAA, not the SDK, decides that.
|
|
158
|
+
* Failures map exactly as {@link postSignedResource}'s do.
|
|
159
|
+
*/
|
|
160
|
+
async function postAuthorizedResource({ transport, operation, bodyBytes, authorization, expectedStatuses, decode, failure, }) {
|
|
161
|
+
const profile = (0, deviceAuthorization_1.deviceAuthorizationProfile)(operation);
|
|
162
|
+
if (profile.method !== 'POST') {
|
|
163
|
+
throw (0, errors_1.contractViolation)('postAuthorizedResource only sends POST registry operations');
|
|
164
|
+
}
|
|
165
|
+
const response = await sendAuthorizedPost({
|
|
166
|
+
transport,
|
|
167
|
+
path: profile.canonicalPath,
|
|
168
|
+
bodyBytes,
|
|
169
|
+
authorization,
|
|
170
|
+
});
|
|
171
|
+
if (!expectedStatuses.includes(response.status)) {
|
|
172
|
+
throw failure?.(response) ?? mapSignedRequestFailure(response, bodyBytes, authorization);
|
|
173
|
+
}
|
|
174
|
+
return (0, resourceRequest_1.decodeResourceResponse)({ response, expectedStatus: response.status, decode });
|
|
175
|
+
}
|
|
176
|
+
function mapSignedRequestFailure(response, bodyBytes, authorization) {
|
|
177
|
+
const correlationId = (0, headers_1.headerValueIgnoringCase)(response.headers, 'X-Request-Id');
|
|
178
|
+
const daaStatusCode = (0, errorEnvelope_1.readDaaStatusCode)(response.bodyBytes);
|
|
179
|
+
const fallback = () => (0, errors_1.apiFailure)({
|
|
180
|
+
httpStatus: response.status,
|
|
181
|
+
daaStatusCode,
|
|
182
|
+
correlationId,
|
|
183
|
+
});
|
|
184
|
+
if ((0, daaStatusCodes_1.isDaaStatus)(daaStatusCode, 'IDEMPOTENCY_KEY_REUSED')) {
|
|
185
|
+
// Gated on both the status code and the HTTP status, so a body that
|
|
186
|
+
// carries this code on some other status falls through to the generic
|
|
187
|
+
// `api` failure below rather than being trusted. The contract puts this
|
|
188
|
+
// code at `409`, which is where DAA's transfer and withdrawal
|
|
189
|
+
// create routes send it. Non-custodial account create never sends it (a
|
|
190
|
+
// reused key returns the original account). Recovered from the signed
|
|
191
|
+
// request's own bytes, not the response — `idempotencyKeyFromExactBody`
|
|
192
|
+
// returns `undefined` for a bodyless request (`getSignedResource`), so this
|
|
193
|
+
// never fires for `get_device_context`.
|
|
194
|
+
const idempotencyKey = response.status === 409 ? (0, deviceAuthorization_1.idempotencyKeyFromExactBody)(bodyBytes) : undefined;
|
|
195
|
+
return idempotencyKey !== undefined
|
|
196
|
+
? (0, errors_1.idempotencyConflict)(idempotencyKey, correlationId)
|
|
197
|
+
: fallback();
|
|
198
|
+
}
|
|
199
|
+
if ((0, daaStatusCodes_1.isDaaStatus)(daaStatusCode, 'DEVICE_AUTHORIZATION_REPLAYED') ||
|
|
200
|
+
(0, daaStatusCodes_1.isDaaStatus)(daaStatusCode, 'DEVICE_AUTHORIZATION_REQUEST_MISMATCH')) {
|
|
201
|
+
return (0, errors_1.contractViolation)('the device authorization was replayed or did not match the request', correlationId);
|
|
202
|
+
}
|
|
203
|
+
if ((0, daaStatusCodes_1.isDaaStatus)(daaStatusCode, 'DEVICE_PENDING')) {
|
|
204
|
+
// The key can't sign yet: approved and in its cool-down, or still
|
|
205
|
+
// waiting for approval. Not a credential problem, so not
|
|
206
|
+
// `contract_violation`. Gated on `409`, where every DAA route sends it,
|
|
207
|
+
// like `IDEMPOTENCY_KEY_REUSED` above.
|
|
208
|
+
return response.status === 409 ? (0, errors_1.devicePending)(correlationId) : fallback();
|
|
209
|
+
}
|
|
210
|
+
if ((0, daaStatusCodes_1.isDaaStatus)(daaStatusCode, 'DEVICE_AUTHORIZATION_INVALID')) {
|
|
211
|
+
// DAA's freshness check reports this code (as a `400`), so only this code
|
|
212
|
+
// is refined; a replayed or mismatched authorization is never a clock
|
|
213
|
+
// problem, and a `401` from something other than DAA carries no DAA code.
|
|
214
|
+
return isClockSkewed(response, authorization)
|
|
215
|
+
? (0, errors_1.clockSkew)(correlationId)
|
|
216
|
+
: (0, errors_1.contractViolation)('the device authorization was rejected', correlationId);
|
|
217
|
+
}
|
|
218
|
+
return fallback();
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* DAA's freshness rule for a device authorization
|
|
222
|
+
* (`OwnerAuthorizationPrevalidator.validateFreshness`): it is refused when
|
|
223
|
+
* `iat > now + 60` or `exp < now - 60`, in whole epoch seconds.
|
|
224
|
+
*/
|
|
225
|
+
const FRESHNESS_SKEW_SECONDS = 60;
|
|
226
|
+
/**
|
|
227
|
+
* Slack for the time between DAA reading its clock and stamping the response
|
|
228
|
+
* `Date`. Only the `exp` side needs it: `Date` is never earlier than the check,
|
|
229
|
+
* so `iat > Date + 60` already proves `iat > now + 60`.
|
|
230
|
+
*/
|
|
231
|
+
const RESPONSE_DATE_SLACK_SECONDS = 5;
|
|
232
|
+
/**
|
|
233
|
+
* Whether DAA refused this authorization because the device clock is wrong,
|
|
234
|
+
* judged from the authorization's own `iat`/`exp` against the response's HTTP
|
|
235
|
+
* `Date`, with DAA's own rule.
|
|
236
|
+
*
|
|
237
|
+
* - `iat` more than 60 s after `Date`: the device clock was ahead when it
|
|
238
|
+
* signed. Compared with the signed `iat`, not `Date.now()`, so neither the
|
|
239
|
+
* whole-second `Date` nor response transit time can push a clock that is
|
|
240
|
+
* within tolerance over the line.
|
|
241
|
+
* - `exp` more than 60 s before `Date`: the authorization had expired, and the
|
|
242
|
+
* device clock now reads more than `exp - iat + 60` seconds (360 s) behind
|
|
243
|
+
* the service — far enough that an authorization signed now would be
|
|
244
|
+
* refused too. A device less far behind passes DAA's rule, so an expiry
|
|
245
|
+
* there is the authorization's age, not the clock: that matters for
|
|
246
|
+
* `contractExecutions.submit`, whose authorization was signed at `prepare`
|
|
247
|
+
* and may simply have aged out, whatever the clock did since.
|
|
248
|
+
*
|
|
249
|
+
* `Date` is unsigned and the transport is the consumer's, so this only chooses
|
|
250
|
+
* between two classifications of a response that has already failed. A
|
|
251
|
+
* missing or unreadable `Date` or claim is not skew.
|
|
252
|
+
*/
|
|
253
|
+
function isClockSkewed(response, authorization) {
|
|
254
|
+
const serverMillis = (0, headers_1.httpDateMillis)((0, headers_1.headerValueIgnoringCase)(response.headers, 'Date'));
|
|
255
|
+
const claims = (0, deviceAuthorization_1.jwsSegmentJson)(authorization, 1);
|
|
256
|
+
const iat = claims?.['iat'];
|
|
257
|
+
const exp = claims?.['exp'];
|
|
258
|
+
if (serverMillis === null || typeof iat !== 'number' || typeof exp !== 'number') {
|
|
259
|
+
return false;
|
|
260
|
+
}
|
|
261
|
+
const serverSeconds = serverMillis / 1000;
|
|
262
|
+
if (iat > serverSeconds + FRESHNESS_SKEW_SECONDS) {
|
|
263
|
+
return true;
|
|
264
|
+
}
|
|
265
|
+
return (exp < serverSeconds - FRESHNESS_SKEW_SECONDS - RESPONSE_DATE_SLACK_SECONDS &&
|
|
266
|
+
serverMillis - Date.now() > (exp - iat + FRESHNESS_SKEW_SECONDS) * 1000);
|
|
267
|
+
}
|
|
@@ -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
|
+
import { type DaaRegistrationNativeModule } from './daaRegistrationNative';
|
|
19
|
+
/**
|
|
20
|
+
* One attempt's registration-flow key. Not an AuthKey; see the file header.
|
|
21
|
+
*
|
|
22
|
+
* The interface carries the public-key export for Prepare, the Complete-only
|
|
23
|
+
* signing helper, and an explicit release: the native implementations hold the
|
|
24
|
+
* private key in a process-lifetime cache, so something has to say when it is
|
|
25
|
+
* no longer needed.
|
|
26
|
+
*/
|
|
27
|
+
export interface RegistrationFlowKey {
|
|
28
|
+
/**
|
|
29
|
+
* Unpadded Base64URL DER SubjectPublicKeyInfo of the public key, the exact
|
|
30
|
+
* form `PrepareSocialLoginRequest.registrationFlowPublicKey` wants.
|
|
31
|
+
*/
|
|
32
|
+
publicKeySpkiBase64Url(): Promise<string>;
|
|
33
|
+
/**
|
|
34
|
+
* ES256 signature (JOSE `R || S`, 64 bytes) over the exact Device Registration
|
|
35
|
+
* Complete flow-JWS signing input. Not a public generic sign API.
|
|
36
|
+
*/
|
|
37
|
+
signExactBytes(message: Uint8Array): Promise<Uint8Array>;
|
|
38
|
+
/**
|
|
39
|
+
* Discard the key, so a native implementation stops holding its private half.
|
|
40
|
+
*
|
|
41
|
+
* Safe to call more than once and safe to call on a key that was never used.
|
|
42
|
+
* The key is dead afterwards: `publicKeySpkiBase64Url()` on a released native
|
|
43
|
+
* key fails closed rather than returning a stale value.
|
|
44
|
+
*
|
|
45
|
+
* Device Registration Complete is the owner of this call: it signs, then
|
|
46
|
+
* releases. `PreparedSocialLogin.abandon()` is the other caller when the user
|
|
47
|
+
* backs out of provider login. `PendingDeviceRegistration` has no
|
|
48
|
+
* `abandon()`: after Session, the key is held until Complete or until the
|
|
49
|
+
* process exits.
|
|
50
|
+
*/
|
|
51
|
+
release(): Promise<void>;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Source of per-attempt registration-flow keys.
|
|
55
|
+
*
|
|
56
|
+
* A seam so `AuthClient` can switch providers without changing callers.
|
|
57
|
+
* Production generation is `DaaRegistrationFlowKey` in `daa-ios-sdk` /
|
|
58
|
+
* `daa-android-sdk` — not `DaaSecureKey`, which is the Owner AuthKey. The Expo
|
|
59
|
+
* `DaaRegistration` module bridges that type and keeps the private key in
|
|
60
|
+
* native memory. WebCrypto is an explicit test stand-in
|
|
61
|
+
* (`webCryptoRegistrationFlowKeyProvider`), never a fallback. A host missing
|
|
62
|
+
* the Expo module fails closed. The seam is not exported from `index.ts`: a
|
|
63
|
+
* consumer cannot substitute the key that proves its own registration handoff.
|
|
64
|
+
*/
|
|
65
|
+
export interface RegistrationFlowKeyProvider {
|
|
66
|
+
generate(): Promise<RegistrationFlowKey>;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Production React Native provider: native `DaaRegistrationFlowKey` via the
|
|
70
|
+
* Expo `DaaRegistration` module. The private key never crosses the bridge.
|
|
71
|
+
*/
|
|
72
|
+
export declare function nativeRegistrationFlowKeyProvider(native: DaaRegistrationNativeModule): RegistrationFlowKeyProvider;
|
|
73
|
+
/**
|
|
74
|
+
* Node/Jest stand-in: a non-extractable WebCrypto P-256 keypair per attempt.
|
|
75
|
+
*
|
|
76
|
+
* `extractable: false` is set even though the key never leaves the process. It
|
|
77
|
+
* costs nothing, and it means a future bug that hands the handle somewhere else
|
|
78
|
+
* still cannot export the private key.
|
|
79
|
+
*
|
|
80
|
+
* **Not the production RN path.** Production `defaultRegistrationFlowKeyProvider`
|
|
81
|
+
* never calls this. Absent `crypto.subtle`, `generate()` fails closed with
|
|
82
|
+
* `contract_violation` rather than weaker key generation.
|
|
83
|
+
*/
|
|
84
|
+
export declare function webCryptoRegistrationFlowKeyProvider(): RegistrationFlowKeyProvider;
|
|
85
|
+
/**
|
|
86
|
+
* Native `DaaRegistrationFlowKey` via the Expo module. A missing module is a
|
|
87
|
+
* `contract_violation` — WebCrypto is never a fallback. The native module is
|
|
88
|
+
* resolved on `generate()`, not when this provider is constructed, so building
|
|
89
|
+
* a `DaaClient` does not require the Expo module to be linked.
|
|
90
|
+
*/
|
|
91
|
+
export declare function defaultRegistrationFlowKeyProvider(): RegistrationFlowKeyProvider;
|
|
92
|
+
/** Drop the key without replacing the failure that triggered cleanup. */
|
|
93
|
+
export declare function releaseQuietly(key: RegistrationFlowKey): Promise<void>;
|
|
@@ -0,0 +1,203 @@
|
|
|
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 _WebCryptoRegistrationFlowKey_keyPair, _NativeRegistrationFlowKey_native, _NativeRegistrationFlowKey_id;
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
exports.nativeRegistrationFlowKeyProvider = nativeRegistrationFlowKeyProvider;
|
|
33
|
+
exports.webCryptoRegistrationFlowKeyProvider = webCryptoRegistrationFlowKeyProvider;
|
|
34
|
+
exports.defaultRegistrationFlowKeyProvider = defaultRegistrationFlowKeyProvider;
|
|
35
|
+
exports.releaseQuietly = releaseQuietly;
|
|
36
|
+
// The ephemeral registration-flow key.
|
|
37
|
+
//
|
|
38
|
+
// ============================================================================
|
|
39
|
+
// THIS IS NOT AN AuthKey. Do not treat it as one, and do not route it through
|
|
40
|
+
// `SecureKeyStore`.
|
|
41
|
+
// ============================================================================
|
|
42
|
+
//
|
|
43
|
+
// The login contract uses two different P-256 keys, and confusing
|
|
44
|
+
// them is the failure this file's naming exists to prevent:
|
|
45
|
+
//
|
|
46
|
+
// | | AuthKey (`OwnerAuthKey`, `securekey/`) | registration-flow key (this file) |
|
|
47
|
+
// | --- | --- | --- |
|
|
48
|
+
// | Lifetime | durable, survives the app | **one login attempt** |
|
|
49
|
+
// | Scope | `{environment, customer application, Owner (clientEntityId), installation}` | nothing; it is anonymous |
|
|
50
|
+
// | Storage | Secure Enclave / Android Keystore, via `SecureKeyStore` | process memory only |
|
|
51
|
+
// | Exported at | Device Registration Complete (`deviceKeyPublicKey`) | **Prepare** (`registrationFlowPublicKey`) |
|
|
52
|
+
// | Selected | only *after* the Social Session response | before Prepare |
|
|
53
|
+
// | Authorizes | DAA operations, via `X-Device-Authorization` | nothing |
|
|
54
|
+
//
|
|
55
|
+
// The contract says the same thing in one line on
|
|
56
|
+
// `PrepareSocialLoginRequest.registrationFlowPublicKey`: "Unpadded Base64URL DER
|
|
57
|
+
// SubjectPublicKeyInfo for an ephemeral P-256 flow key; **it is not an AuthKey**".
|
|
58
|
+
//
|
|
59
|
+
// Its whole job is to prove, at Device Registration Complete, that the caller
|
|
60
|
+
// completing the registration is the caller that prepared it — the flow-key JWS
|
|
61
|
+
// is one of the two fresh proofs over the exact Complete request bytes. Because
|
|
62
|
+
// it is per-attempt and anonymous, it deliberately does NOT go into the
|
|
63
|
+
// enclave: a key in the Secure Enclave is a key that outlives the attempt and
|
|
64
|
+
// acquires a namespace, which is exactly what this one must not have.
|
|
65
|
+
//
|
|
66
|
+
// Signing is a **typed Complete-only helper**, not a public `sign(bytes)`. The
|
|
67
|
+
// member is `signExactBytes` of the JWS signing input for
|
|
68
|
+
// `X-Registration-Flow-Authorization`. It is not exported from `index.ts`.
|
|
69
|
+
// Both the native Expo bridge (`DaaRegistrationFlowKey.signRegistrationAuthorization`
|
|
70
|
+
// on iOS and Android) and the WebCrypto test stand-in sign for real, so Device
|
|
71
|
+
// Registration Complete can finish on a physical device.
|
|
72
|
+
const base64url_1 = require("../crypto/base64url");
|
|
73
|
+
const bytes_1 = require("../crypto/bytes");
|
|
74
|
+
const errors_1 = require("../errors");
|
|
75
|
+
const daaRegistrationNative_1 = require("./daaRegistrationNative");
|
|
76
|
+
/** Byte length of a P-256 SubjectPublicKeyInfo. */
|
|
77
|
+
const P256_SPKI_BYTE_LENGTH = 91;
|
|
78
|
+
class WebCryptoRegistrationFlowKey {
|
|
79
|
+
constructor(keyPair) {
|
|
80
|
+
_WebCryptoRegistrationFlowKey_keyPair.set(this, void 0);
|
|
81
|
+
__classPrivateFieldSet(this, _WebCryptoRegistrationFlowKey_keyPair, keyPair, "f");
|
|
82
|
+
Object.freeze(this);
|
|
83
|
+
}
|
|
84
|
+
// Nothing to free: the CryptoKey is ordinary garbage once the handle is
|
|
85
|
+
// dropped, and WebCrypto exposes no destroy. Present so the two providers
|
|
86
|
+
// satisfy one interface.
|
|
87
|
+
async release() { }
|
|
88
|
+
async publicKeySpkiBase64Url() {
|
|
89
|
+
const spki = await subtle().exportKey('spki', __classPrivateFieldGet(this, _WebCryptoRegistrationFlowKey_keyPair, "f").publicKey);
|
|
90
|
+
const bytes = new Uint8Array(spki);
|
|
91
|
+
if (bytes.length !== P256_SPKI_BYTE_LENGTH) {
|
|
92
|
+
throw (0, errors_1.contractViolation)('registration-flow key did not export a 91-byte P-256 SubjectPublicKeyInfo');
|
|
93
|
+
}
|
|
94
|
+
return (0, base64url_1.toBase64Url)(bytes);
|
|
95
|
+
}
|
|
96
|
+
async signExactBytes(message) {
|
|
97
|
+
const signature = await subtle().sign({ name: 'ECDSA', hash: 'SHA-256' }, __classPrivateFieldGet(this, _WebCryptoRegistrationFlowKey_keyPair, "f").privateKey, (0, bytes_1.toArrayBuffer)(message));
|
|
98
|
+
return new Uint8Array(signature);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
_WebCryptoRegistrationFlowKey_keyPair = new WeakMap();
|
|
102
|
+
class NativeRegistrationFlowKey {
|
|
103
|
+
constructor(native, id) {
|
|
104
|
+
_NativeRegistrationFlowKey_native.set(this, void 0);
|
|
105
|
+
_NativeRegistrationFlowKey_id.set(this, void 0);
|
|
106
|
+
__classPrivateFieldSet(this, _NativeRegistrationFlowKey_native, native, "f");
|
|
107
|
+
__classPrivateFieldSet(this, _NativeRegistrationFlowKey_id, id, "f");
|
|
108
|
+
Object.freeze(this);
|
|
109
|
+
}
|
|
110
|
+
async publicKeySpkiBase64Url() {
|
|
111
|
+
const spki = (0, daaRegistrationNative_1.nativeRegistrationFlowPublicKeySpkiBase64Url)(__classPrivateFieldGet(this, _NativeRegistrationFlowKey_native, "f"), __classPrivateFieldGet(this, _NativeRegistrationFlowKey_id, "f"));
|
|
112
|
+
const bytes = decodeSpki(spki);
|
|
113
|
+
return (0, base64url_1.toBase64Url)(bytes);
|
|
114
|
+
}
|
|
115
|
+
async release() {
|
|
116
|
+
(0, daaRegistrationNative_1.nativeReleaseRegistrationFlowKey)(__classPrivateFieldGet(this, _NativeRegistrationFlowKey_native, "f"), __classPrivateFieldGet(this, _NativeRegistrationFlowKey_id, "f"));
|
|
117
|
+
}
|
|
118
|
+
async signExactBytes(message) {
|
|
119
|
+
// The Expo module holds the private key; only the exact bytes and the
|
|
120
|
+
// resulting signature cross the bridge as Base64URL strings.
|
|
121
|
+
const signingInputBase64Url = (0, base64url_1.toBase64Url)(message);
|
|
122
|
+
return (0, daaRegistrationNative_1.nativeSignRegistrationAuthorization)(__classPrivateFieldGet(this, _NativeRegistrationFlowKey_native, "f"), __classPrivateFieldGet(this, _NativeRegistrationFlowKey_id, "f"), signingInputBase64Url);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
_NativeRegistrationFlowKey_native = new WeakMap(), _NativeRegistrationFlowKey_id = new WeakMap();
|
|
126
|
+
/**
|
|
127
|
+
* Production React Native provider: native `DaaRegistrationFlowKey` via the
|
|
128
|
+
* Expo `DaaRegistration` module. The private key never crosses the bridge.
|
|
129
|
+
*/
|
|
130
|
+
function nativeRegistrationFlowKeyProvider(native) {
|
|
131
|
+
return {
|
|
132
|
+
async generate() {
|
|
133
|
+
const id = (0, daaRegistrationNative_1.nativeGenerateRegistrationFlowKey)(native);
|
|
134
|
+
return new NativeRegistrationFlowKey(native, id);
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Node/Jest stand-in: a non-extractable WebCrypto P-256 keypair per attempt.
|
|
140
|
+
*
|
|
141
|
+
* `extractable: false` is set even though the key never leaves the process. It
|
|
142
|
+
* costs nothing, and it means a future bug that hands the handle somewhere else
|
|
143
|
+
* still cannot export the private key.
|
|
144
|
+
*
|
|
145
|
+
* **Not the production RN path.** Production `defaultRegistrationFlowKeyProvider`
|
|
146
|
+
* never calls this. Absent `crypto.subtle`, `generate()` fails closed with
|
|
147
|
+
* `contract_violation` rather than weaker key generation.
|
|
148
|
+
*/
|
|
149
|
+
function webCryptoRegistrationFlowKeyProvider() {
|
|
150
|
+
return {
|
|
151
|
+
async generate() {
|
|
152
|
+
const keyPair = (await subtle().generateKey({ name: 'ECDSA', namedCurve: 'P-256' }, false, [
|
|
153
|
+
'sign',
|
|
154
|
+
'verify',
|
|
155
|
+
]));
|
|
156
|
+
return new WebCryptoRegistrationFlowKey(keyPair);
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Native `DaaRegistrationFlowKey` via the Expo module. A missing module is a
|
|
162
|
+
* `contract_violation` — WebCrypto is never a fallback. The native module is
|
|
163
|
+
* resolved on `generate()`, not when this provider is constructed, so building
|
|
164
|
+
* a `DaaClient` does not require the Expo module to be linked.
|
|
165
|
+
*/
|
|
166
|
+
function defaultRegistrationFlowKeyProvider() {
|
|
167
|
+
return {
|
|
168
|
+
async generate() {
|
|
169
|
+
return nativeRegistrationFlowKeyProvider((0, daaRegistrationNative_1.requireDaaRegistrationNative)()).generate();
|
|
170
|
+
},
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
/** Drop the key without replacing the failure that triggered cleanup. */
|
|
174
|
+
async function releaseQuietly(key) {
|
|
175
|
+
try {
|
|
176
|
+
await key.release();
|
|
177
|
+
}
|
|
178
|
+
catch {
|
|
179
|
+
// Intentionally empty: a throwing release must not mask the originating error.
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
function decodeSpki(spki) {
|
|
183
|
+
let bytes;
|
|
184
|
+
try {
|
|
185
|
+
bytes = (0, base64url_1.fromBase64Url)(spki);
|
|
186
|
+
}
|
|
187
|
+
catch {
|
|
188
|
+
throw (0, errors_1.contractViolation)('registration-flow key did not export valid Base64URL SubjectPublicKeyInfo');
|
|
189
|
+
}
|
|
190
|
+
if (bytes.length !== P256_SPKI_BYTE_LENGTH) {
|
|
191
|
+
throw (0, errors_1.contractViolation)('registration-flow key did not export a 91-byte P-256 SubjectPublicKeyInfo');
|
|
192
|
+
}
|
|
193
|
+
return bytes;
|
|
194
|
+
}
|
|
195
|
+
function subtle() {
|
|
196
|
+
const host = globalThis.crypto;
|
|
197
|
+
if (host === undefined || host.subtle === undefined) {
|
|
198
|
+
throw (0, errors_1.contractViolation)('crypto.subtle is required to generate the ephemeral registration-flow key; ' +
|
|
199
|
+
'install a WebCrypto polyfill in the host app or supply a native ' +
|
|
200
|
+
'DaaRegistrationFlowKey provider');
|
|
201
|
+
}
|
|
202
|
+
return host.subtle;
|
|
203
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
export declare const DAA_REGISTRATION_MODULE = "DaaRegistration";
|
|
19
|
+
export interface DaaRegistrationNativeModule {
|
|
20
|
+
randomBytes(count: number): string;
|
|
21
|
+
randomUuidV4(): string;
|
|
22
|
+
generateRegistrationFlowKey(): string;
|
|
23
|
+
registrationFlowPublicKeySpkiBase64Url(id: string): string;
|
|
24
|
+
releaseRegistrationFlowKey(id: string): void;
|
|
25
|
+
/**
|
|
26
|
+
* Typed Complete-only sign — not a generic `sign(bytes)`. `signingInputBase64Url`
|
|
27
|
+
* is the exact Device Registration Complete flow-JWS signing input; the native
|
|
28
|
+
* module validates those bytes and signs that same slice with the cached flow
|
|
29
|
+
* key, returning unpadded Base64URL of the 64-byte JOSE `R || S` signature.
|
|
30
|
+
*/
|
|
31
|
+
signRegistrationAuthorization(id: string, signingInputBase64Url: string): string;
|
|
32
|
+
}
|
|
33
|
+
export declare function optionalDaaRegistrationNative(): DaaRegistrationNativeModule | null;
|
|
34
|
+
export declare function requireDaaRegistrationNative(): DaaRegistrationNativeModule;
|
|
35
|
+
/** Verifier bytes from native `DaaSecureRandom`, decoded at the seam. */
|
|
36
|
+
export declare function nativeRandomBytes(native: DaaRegistrationNativeModule, count: number): Uint8Array;
|
|
37
|
+
export declare function nativeRandomUuidV4(native: DaaRegistrationNativeModule): string;
|
|
38
|
+
export declare function nativeGenerateRegistrationFlowKey(native: DaaRegistrationNativeModule): string;
|
|
39
|
+
export declare function nativeRegistrationFlowPublicKeySpkiBase64Url(native: DaaRegistrationNativeModule, id: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* Sign the exact Device Registration Complete flow-JWS signing input with the
|
|
42
|
+
* cached native flow key. Returns unpadded Base64URL of the 64-byte JOSE
|
|
43
|
+
* `R || S` signature. Not a generic sign: `id` names a cached
|
|
44
|
+
* `DaaRegistrationFlowKey`, and native validates the bytes as a registration
|
|
45
|
+
* authorization signing input before it ever touches the private key.
|
|
46
|
+
*/
|
|
47
|
+
export declare function nativeSignRegistrationAuthorization(native: DaaRegistrationNativeModule, id: string, signingInputBase64Url: string): Uint8Array;
|
|
48
|
+
/**
|
|
49
|
+
* Drop a cached native flow key.
|
|
50
|
+
*
|
|
51
|
+
* Cleanup, so it is forgiving: an older host app whose module predates this
|
|
52
|
+
* function, or an id the native side no longer holds, is not an error. The
|
|
53
|
+
* alternative would make a `finally` block throw over tidying up and mask the
|
|
54
|
+
* failure that sent it there. What it must not do is fail silently in a way
|
|
55
|
+
* that leaves key material resident — hence the explicit function check rather
|
|
56
|
+
* than an optional-call shrug.
|
|
57
|
+
*/
|
|
58
|
+
export declare function nativeReleaseRegistrationFlowKey(native: DaaRegistrationNativeModule, id: string): void;
|