@circle-fin/daa-react-native-sdk 0.0.0-stage → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DaaReactNativeSdk.podspec +63 -0
- package/LICENSE +176 -0
- package/README.md +217 -2
- package/android/build.gradle +97 -0
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/java/com/circle/daa/reactnative/DaaRegistrationExceptions.kt +47 -0
- package/android/src/main/java/com/circle/daa/reactnative/DaaRegistrationModule.kt +121 -0
- package/android/src/main/java/com/circle/daa/reactnative/DaaScaExceptions.kt +60 -0
- package/android/src/main/java/com/circle/daa/reactnative/DaaScaModule.kt +179 -0
- package/android/src/main/java/com/circle/daa/reactnative/DaaSecureKeyExceptions.kt +73 -0
- package/android/src/main/java/com/circle/daa/reactnative/DaaSecureKeyModule.kt +185 -0
- package/android/src/main/java/com/circle/daa/reactnative/InstallationIdentityStore.kt +73 -0
- package/android/src/main/java/com/circle/daa/reactnative/UnpaddedBase64Url.kt +45 -0
- package/build/DaaClient.d.ts +57 -0
- package/build/DaaClient.js +158 -0
- package/build/api/AccountLimitsClient.d.ts +79 -0
- package/build/api/AccountLimitsClient.js +142 -0
- package/build/api/AccountsClient.d.ts +95 -0
- package/build/api/AccountsClient.js +276 -0
- package/build/api/AchFiatAccountsClient.d.ts +92 -0
- package/build/api/AchFiatAccountsClient.js +142 -0
- package/build/api/AuthClient.d.ts +120 -0
- package/build/api/AuthClient.js +257 -0
- package/build/api/DaaUserClient.d.ts +124 -0
- package/build/api/DaaUserClient.js +245 -0
- package/build/api/DepositAddressesClient.d.ts +112 -0
- package/build/api/DepositAddressesClient.js +222 -0
- package/build/api/DepositsClient.d.ts +106 -0
- package/build/api/DepositsClient.js +183 -0
- package/build/api/FiatAccountsClient.d.ts +43 -0
- package/build/api/FiatAccountsClient.js +46 -0
- package/build/api/TransactionsClient.d.ts +64 -0
- package/build/api/TransactionsClient.js +120 -0
- package/build/api/TransfersClient.d.ts +104 -0
- package/build/api/TransfersClient.js +321 -0
- package/build/api/WireFiatAccountsClient.d.ts +99 -0
- package/build/api/WireFiatAccountsClient.js +156 -0
- package/build/api/WithdrawalsClient.d.ts +94 -0
- package/build/api/WithdrawalsClient.js +305 -0
- package/build/api/loginFailure.d.ts +43 -0
- package/build/api/loginFailure.js +64 -0
- package/build/api/pagination.d.ts +29 -0
- package/build/api/pagination.js +50 -0
- package/build/api/queryParameters.d.ts +23 -0
- package/build/api/queryParameters.js +77 -0
- package/build/api/resourceRequest.d.ts +60 -0
- package/build/api/resourceRequest.js +79 -0
- package/build/api/signedResource.d.ts +77 -0
- package/build/api/signedResource.js +168 -0
- package/build/auth/RegistrationFlowKey.d.ts +93 -0
- package/build/auth/RegistrationFlowKey.js +203 -0
- package/build/auth/daaRegistrationNative.d.ts +80 -0
- package/build/auth/daaRegistrationNative.js +184 -0
- package/build/auth/deviceAuthorization.d.ts +73 -0
- package/build/auth/deviceAuthorization.js +243 -0
- package/build/auth/ownerGrant.d.ts +29 -0
- package/build/auth/ownerGrant.js +90 -0
- package/build/auth/prepareReceipt.d.ts +150 -0
- package/build/auth/prepareReceipt.js +357 -0
- package/build/auth/registrationAuthorization.d.ts +48 -0
- package/build/auth/registrationAuthorization.js +243 -0
- package/build/auth/registrationCodeVerifier.d.ts +31 -0
- package/build/auth/registrationCodeVerifier.js +75 -0
- package/build/config.d.ts +79 -0
- package/build/config.js +116 -0
- package/build/crypto/base64url.d.ts +26 -0
- package/build/crypto/base64url.js +87 -0
- package/build/crypto/bytes.d.ts +27 -0
- package/build/crypto/bytes.js +32 -0
- package/build/crypto/es256Jws.d.ts +56 -0
- package/build/crypto/es256Jws.js +196 -0
- package/build/crypto/jwkThumbprint.d.ts +32 -0
- package/build/crypto/jwkThumbprint.js +49 -0
- package/build/crypto/random.d.ts +35 -0
- package/build/crypto/random.js +106 -0
- package/build/crypto/serialization.d.ts +26 -0
- package/build/crypto/serialization.js +43 -0
- package/build/crypto/sha256.d.ts +18 -0
- package/build/crypto/sha256.js +100 -0
- package/build/errors.d.ts +190 -0
- package/build/errors.js +252 -0
- package/build/index.d.ts +61 -0
- package/build/index.js +67 -0
- package/build/models/Account.d.ts +201 -0
- package/build/models/Account.js +147 -0
- package/build/models/AccountLimitsUsage.d.ts +169 -0
- package/build/models/AccountLimitsUsage.js +86 -0
- package/build/models/Ach.d.ts +135 -0
- package/build/models/Ach.js +184 -0
- package/build/models/AddressObject.d.ts +128 -0
- package/build/models/AddressObject.js +141 -0
- package/build/models/BusinessPii.d.ts +84 -0
- package/build/models/BusinessPii.js +142 -0
- package/build/models/CreateAccountRequest.d.ts +74 -0
- package/build/models/CreateAccountRequest.js +19 -0
- package/build/models/CreateTransferRequest.d.ts +91 -0
- package/build/models/CreateTransferRequest.js +19 -0
- package/build/models/CreateWithdrawalRequest.d.ts +99 -0
- package/build/models/CreateWithdrawalRequest.js +19 -0
- package/build/models/DaaUserContext.d.ts +96 -0
- package/build/models/DaaUserContext.js +133 -0
- package/build/models/Deposit.d.ts +241 -0
- package/build/models/Deposit.js +149 -0
- package/build/models/DepositSummary.d.ts +91 -0
- package/build/models/DepositSummary.js +114 -0
- package/build/models/FiatAccount.d.ts +99 -0
- package/build/models/FiatAccount.js +151 -0
- package/build/models/GenerateAddressRequest.d.ts +67 -0
- package/build/models/GenerateAddressRequest.js +68 -0
- package/build/models/Money.d.ts +76 -0
- package/build/models/Money.js +99 -0
- package/build/models/Page.d.ts +33 -0
- package/build/models/Page.js +57 -0
- package/build/models/PendingDeviceRegistration.d.ts +90 -0
- package/build/models/PendingDeviceRegistration.js +180 -0
- package/build/models/PreparedSocialLogin.d.ts +155 -0
- package/build/models/PreparedSocialLogin.js +235 -0
- package/build/models/Transaction.d.ts +187 -0
- package/build/models/Transaction.js +134 -0
- package/build/models/Transfer.d.ts +335 -0
- package/build/models/Transfer.js +240 -0
- package/build/models/Wire.d.ts +213 -0
- package/build/models/Wire.js +264 -0
- package/build/models/Withdrawal.d.ts +201 -0
- package/build/models/Withdrawal.js +156 -0
- package/build/models/redaction.d.ts +18 -0
- package/build/models/redaction.js +23 -0
- package/build/sca/ScaClient.d.ts +105 -0
- package/build/sca/ScaClient.js +193 -0
- package/build/securekey/InMemorySecureKey.d.ts +23 -0
- package/build/securekey/InMemorySecureKey.js +127 -0
- package/build/securekey/NativeSecureKey.d.ts +24 -0
- package/build/securekey/NativeSecureKey.js +178 -0
- package/build/securekey/NativeSecureKeyBridge.d.ts +83 -0
- package/build/securekey/NativeSecureKeyBridge.js +19 -0
- package/build/securekey/SecureKey.d.ts +137 -0
- package/build/securekey/SecureKey.js +19 -0
- package/build/securekey/alias.d.ts +88 -0
- package/build/securekey/alias.js +175 -0
- package/build/securekey/ownerAuthKeyResolver.d.ts +56 -0
- package/build/securekey/ownerAuthKeyResolver.js +63 -0
- package/build/securekey/resolveNativeBridge.d.ts +30 -0
- package/build/securekey/resolveNativeBridge.js +120 -0
- package/build/testing.d.ts +18 -0
- package/build/testing.js +34 -0
- package/build/transport/DaaTransport.d.ts +35 -0
- package/build/transport/DaaTransport.js +19 -0
- package/build/transport/headers.d.ts +30 -0
- package/build/transport/headers.js +45 -0
- package/build/validation/requestBody.d.ts +27 -0
- package/build/validation/requestBody.js +56 -0
- package/build/validation/uuid.d.ts +25 -0
- package/build/validation/uuid.js +33 -0
- package/build/wire/accountLimitsUsagePayload.d.ts +30 -0
- package/build/wire/accountLimitsUsagePayload.js +130 -0
- package/build/wire/accountPayload.d.ts +36 -0
- package/build/wire/accountPayload.js +100 -0
- package/build/wire/achPayload.d.ts +24 -0
- package/build/wire/achPayload.js +82 -0
- package/build/wire/addressObjectPayload.d.ts +44 -0
- package/build/wire/addressObjectPayload.js +64 -0
- package/build/wire/daaStatusCodes.d.ts +64 -0
- package/build/wire/daaStatusCodes.js +69 -0
- package/build/wire/dataEnvelope.d.ts +40 -0
- package/build/wire/dataEnvelope.js +79 -0
- package/build/wire/depositPayload.d.ts +42 -0
- package/build/wire/depositPayload.js +159 -0
- package/build/wire/deviceContextPayload.d.ts +33 -0
- package/build/wire/deviceContextPayload.js +57 -0
- package/build/wire/deviceRegistrationResultPayload.d.ts +32 -0
- package/build/wire/deviceRegistrationResultPayload.js +128 -0
- package/build/wire/errorEnvelope.d.ts +43 -0
- package/build/wire/errorEnvelope.js +85 -0
- package/build/wire/fiatAccountPayload.d.ts +37 -0
- package/build/wire/fiatAccountPayload.js +93 -0
- package/build/wire/instant.d.ts +27 -0
- package/build/wire/instant.js +91 -0
- package/build/wire/jsonNumber.d.ts +30 -0
- package/build/wire/jsonNumber.js +34 -0
- package/build/wire/moneyPayload.d.ts +30 -0
- package/build/wire/moneyPayload.js +56 -0
- package/build/wire/paginationLinks.d.ts +28 -0
- package/build/wire/paginationLinks.js +167 -0
- package/build/wire/payload.d.ts +60 -0
- package/build/wire/payload.js +121 -0
- package/build/wire/pendingRegistrationPayload.d.ts +32 -0
- package/build/wire/pendingRegistrationPayload.js +54 -0
- package/build/wire/socialLoginRequestPayload.d.ts +31 -0
- package/build/wire/socialLoginRequestPayload.js +72 -0
- package/build/wire/transactionPayload.d.ts +31 -0
- package/build/wire/transactionPayload.js +126 -0
- package/build/wire/transferPayload.d.ts +43 -0
- package/build/wire/transferPayload.js +218 -0
- package/build/wire/wireEnums.d.ts +22 -0
- package/build/wire/wireEnums.js +69 -0
- package/build/wire/wirePayload.d.ts +29 -0
- package/build/wire/wirePayload.js +138 -0
- package/build/wire/withdrawalPayload.d.ts +27 -0
- package/build/wire/withdrawalPayload.js +179 -0
- package/expo-module.config.json +14 -0
- package/ios/DaaRegistrationExceptions.swift +58 -0
- package/ios/DaaRegistrationModule.swift +143 -0
- package/ios/DaaScaExceptions.swift +96 -0
- package/ios/DaaScaModule.swift +125 -0
- package/ios/DaaSecureKeyExceptions.swift +77 -0
- package/ios/DaaSecureKeyModule.swift +162 -0
- package/ios/InstallationIdentityStore.swift +126 -0
- package/ios/UnpaddedBase64URL.swift +42 -0
- package/package.json +114 -4
- package/src/DaaClient.ts +171 -0
- package/src/api/AccountLimitsClient.ts +146 -0
- package/src/api/AccountsClient.ts +305 -0
- package/src/api/AchFiatAccountsClient.ts +147 -0
- package/src/api/AuthClient.ts +331 -0
- package/src/api/DaaUserClient.ts +270 -0
- package/src/api/DepositAddressesClient.ts +239 -0
- package/src/api/DepositsClient.ts +208 -0
- package/src/api/FiatAccountsClient.ts +50 -0
- package/src/api/TransactionsClient.ts +137 -0
- package/src/api/TransfersClient.ts +361 -0
- package/src/api/WireFiatAccountsClient.ts +172 -0
- package/src/api/WithdrawalsClient.ts +339 -0
- package/src/api/loginFailure.ts +75 -0
- package/src/api/pagination.ts +63 -0
- package/src/api/queryParameters.ts +82 -0
- package/src/api/resourceRequest.ts +135 -0
- package/src/api/signedResource.ts +267 -0
- package/src/auth/RegistrationFlowKey.ts +274 -0
- package/src/auth/daaRegistrationNative.ts +236 -0
- package/src/auth/deviceAuthorization.ts +302 -0
- package/src/auth/ownerGrant.ts +102 -0
- package/src/auth/prepareReceipt.ts +522 -0
- package/src/auth/registrationAuthorization.ts +306 -0
- package/src/auth/registrationCodeVerifier.ts +76 -0
- package/src/config.ts +156 -0
- package/src/crypto/base64url.ts +88 -0
- package/src/crypto/bytes.ts +30 -0
- package/src/crypto/es256Jws.ts +240 -0
- package/src/crypto/jwkThumbprint.ts +65 -0
- package/src/crypto/random.ts +113 -0
- package/src/crypto/serialization.ts +42 -0
- package/src/crypto/sha256.ts +105 -0
- package/src/errors.ts +319 -0
- package/src/index.ts +223 -0
- package/src/models/Account.ts +264 -0
- package/src/models/AccountLimitsUsage.ts +192 -0
- package/src/models/Ach.ts +269 -0
- package/src/models/AddressObject.ts +169 -0
- package/src/models/BusinessPii.ts +154 -0
- package/src/models/CreateAccountRequest.ts +109 -0
- package/src/models/CreateTransferRequest.ts +114 -0
- package/src/models/CreateWithdrawalRequest.ts +120 -0
- package/src/models/DaaUserContext.ts +172 -0
- package/src/models/Deposit.ts +307 -0
- package/src/models/DepositSummary.ts +142 -0
- package/src/models/FiatAccount.ts +195 -0
- package/src/models/GenerateAddressRequest.ts +101 -0
- package/src/models/Money.ts +91 -0
- package/src/models/Page.ts +48 -0
- package/src/models/PendingDeviceRegistration.ts +197 -0
- package/src/models/PreparedSocialLogin.ts +287 -0
- package/src/models/Transaction.ts +247 -0
- package/src/models/Transfer.ts +459 -0
- package/src/models/Wire.ts +405 -0
- package/src/models/Withdrawal.ts +283 -0
- package/src/models/redaction.ts +22 -0
- package/src/sca/ScaClient.ts +289 -0
- package/src/securekey/InMemorySecureKey.ts +138 -0
- package/src/securekey/NativeSecureKey.ts +179 -0
- package/src/securekey/NativeSecureKeyBridge.ts +109 -0
- package/src/securekey/SecureKey.ts +149 -0
- package/src/securekey/alias.ts +204 -0
- package/src/securekey/ownerAuthKeyResolver.ts +96 -0
- package/src/securekey/resolveNativeBridge.ts +185 -0
- package/src/testing.ts +32 -0
- package/src/transport/DaaTransport.ts +42 -0
- package/src/transport/headers.ts +46 -0
- package/src/validation/requestBody.ts +60 -0
- package/src/validation/uuid.ts +31 -0
- package/src/wire/accountLimitsUsagePayload.ts +182 -0
- package/src/wire/accountPayload.ts +108 -0
- package/src/wire/achPayload.ts +98 -0
- package/src/wire/addressObjectPayload.ts +64 -0
- package/src/wire/daaStatusCodes.ts +69 -0
- package/src/wire/dataEnvelope.ts +80 -0
- package/src/wire/depositPayload.ts +186 -0
- package/src/wire/deviceContextPayload.ts +58 -0
- package/src/wire/deviceRegistrationResultPayload.ts +153 -0
- package/src/wire/errorEnvelope.ts +87 -0
- package/src/wire/fiatAccountPayload.ts +112 -0
- package/src/wire/instant.ts +93 -0
- package/src/wire/jsonNumber.ts +33 -0
- package/src/wire/moneyPayload.ts +55 -0
- package/src/wire/paginationLinks.ts +204 -0
- package/src/wire/payload.ts +146 -0
- package/src/wire/pendingRegistrationPayload.ts +75 -0
- package/src/wire/socialLoginRequestPayload.ts +89 -0
- package/src/wire/transactionPayload.ts +145 -0
- package/src/wire/transferPayload.ts +249 -0
- package/src/wire/wireEnums.ts +74 -0
- package/src/wire/wirePayload.ts +160 -0
- package/src/wire/withdrawalPayload.ts +219 -0
- package/testing.d.ts +19 -0
- package/testing.js +25 -0
|
@@ -0,0 +1,168 @@
|
|
|
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
|
+
// Signed public POST/GET: either serialize-once body bytes, or no body at all,
|
|
23
|
+
// plus a fresh `X-Device-Authorization` compact JWS.
|
|
24
|
+
//
|
|
25
|
+
// Signed v1 operations carry `query = null`. Failures are classified on the
|
|
26
|
+
// numeric DAA status code only, through `wire/daaStatusCodes.ts`.
|
|
27
|
+
// An invalid, missing, replayed, or mismatched authorization becomes
|
|
28
|
+
// `contract_violation`. A `409` whose body carries `IDEMPOTENCY_KEY_REUSED`
|
|
29
|
+
// (`420034`) becomes `idempotency_conflict`, with the key recovered from the
|
|
30
|
+
// same request bytes that were signed and sent, not the (unsigned) response
|
|
31
|
+
// body; the caller reconciles the original operation rather than replacing the
|
|
32
|
+
// key.
|
|
33
|
+
//
|
|
34
|
+
// DAA has no code for an expired device authorization, a missing one, or a
|
|
35
|
+
// revoked credential: it reports them as `DEVICE_AUTHORIZATION_INVALID` or,
|
|
36
|
+
// on context refresh, `DEVICE_AUTHORIZATION_REQUEST_MISMATCH`, and the SDK
|
|
37
|
+
// classifies the code it receives. So a signed call is sent once, with no
|
|
38
|
+
// fresh-JWS retry, and no DAA response produces `device_revoked`. A
|
|
39
|
+
// non-numeric string `code` is `api`, even when it is the name of one of these
|
|
40
|
+
// conditions or of a row this mapping classifies.
|
|
41
|
+
//
|
|
42
|
+
// `AccountsClient.create` (`create_account`),
|
|
43
|
+
// `TransfersClient.create` (`transfer`), and `WithdrawalsClient.create`
|
|
44
|
+
// (`withdrawal`) call `postSignedResource`. `DaaUserClient.refreshContext`
|
|
45
|
+
// (`get_device_context`) calls `getSignedResource` — the device-authorization
|
|
46
|
+
// contract treats "signed context refresh" alongside protected writes, and
|
|
47
|
+
// `securekey/SecureKey.ts` lists it alongside them as one of the defined DAA
|
|
48
|
+
// operations signing is reachable for.
|
|
49
|
+
const deviceAuthorization_1 = require("../auth/deviceAuthorization");
|
|
50
|
+
const errors_1 = require("../errors");
|
|
51
|
+
const headers_1 = require("../transport/headers");
|
|
52
|
+
const daaStatusCodes_1 = require("../wire/daaStatusCodes");
|
|
53
|
+
const errorEnvelope_1 = require("../wire/errorEnvelope");
|
|
54
|
+
const resourceRequest_1 = require("./resourceRequest");
|
|
55
|
+
/** Execute a public POST with a fresh registered-device authorization header. */
|
|
56
|
+
async function postSignedResource({ transport, operation, authKey, authKeyId, bodyBytes, expectedStatus, decode, }) {
|
|
57
|
+
const profile = (0, deviceAuthorization_1.deviceAuthorizationProfile)(operation);
|
|
58
|
+
if (profile.method !== 'POST') {
|
|
59
|
+
throw (0, errors_1.contractViolation)('postSignedResource only sends POST registry operations');
|
|
60
|
+
}
|
|
61
|
+
const response = await sendSignedPost({
|
|
62
|
+
transport,
|
|
63
|
+
operation,
|
|
64
|
+
path: profile.canonicalPath,
|
|
65
|
+
authKey,
|
|
66
|
+
authKeyId,
|
|
67
|
+
bodyBytes,
|
|
68
|
+
});
|
|
69
|
+
if (response.status !== expectedStatus) {
|
|
70
|
+
throw mapSignedRequestFailure(response, bodyBytes);
|
|
71
|
+
}
|
|
72
|
+
return (0, resourceRequest_1.decodeResourceResponse)({ response, expectedStatus, decode });
|
|
73
|
+
}
|
|
74
|
+
/** No body to serialize for a bodyless signed read; the signature hashes the empty byte array. */
|
|
75
|
+
const EMPTY_BODY = new Uint8Array(0);
|
|
76
|
+
/**
|
|
77
|
+
* Execute a public GET with a fresh registered-device authorization header.
|
|
78
|
+
*
|
|
79
|
+
* The only registry operation this reaches is `get_device_context`
|
|
80
|
+
* (`DaaUserClient.refreshContext`). There is no request body to serialize or
|
|
81
|
+
* sign over: `authorizeExactRequest` hashes the empty byte array per the
|
|
82
|
+
* bodyless-request rule, and nothing is sent as a request entity — the same
|
|
83
|
+
* bodyless shape `resourceRequest.ts`'s unsigned `readResource` sends.
|
|
84
|
+
*/
|
|
85
|
+
async function getSignedResource({ transport, operation, authKey, authKeyId, expectedStatus, decode, }) {
|
|
86
|
+
const profile = (0, deviceAuthorization_1.deviceAuthorizationProfile)(operation);
|
|
87
|
+
if (profile.method !== 'GET') {
|
|
88
|
+
throw (0, errors_1.contractViolation)('getSignedResource only sends GET registry operations');
|
|
89
|
+
}
|
|
90
|
+
const response = await sendSignedGet({
|
|
91
|
+
transport,
|
|
92
|
+
operation,
|
|
93
|
+
path: profile.canonicalPath,
|
|
94
|
+
authKey,
|
|
95
|
+
authKeyId,
|
|
96
|
+
});
|
|
97
|
+
if (response.status !== expectedStatus) {
|
|
98
|
+
throw mapSignedRequestFailure(response, EMPTY_BODY);
|
|
99
|
+
}
|
|
100
|
+
return (0, resourceRequest_1.decodeResourceResponse)({ response, expectedStatus, decode });
|
|
101
|
+
}
|
|
102
|
+
async function sendSignedGet(args) {
|
|
103
|
+
const compactJws = await (0, deviceAuthorization_1.authorizeExactRequest)({
|
|
104
|
+
authKey: args.authKey,
|
|
105
|
+
authKeyId: args.authKeyId,
|
|
106
|
+
operation: args.operation,
|
|
107
|
+
bodyBytes: EMPTY_BODY,
|
|
108
|
+
});
|
|
109
|
+
return args.transport.send({
|
|
110
|
+
method: 'GET',
|
|
111
|
+
path: args.path,
|
|
112
|
+
query: null,
|
|
113
|
+
headers: {
|
|
114
|
+
[deviceAuthorization_1.DEVICE_AUTHORIZATION_HEADER]: compactJws,
|
|
115
|
+
},
|
|
116
|
+
bodyBytes: null,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
async function sendSignedPost(args) {
|
|
120
|
+
const compactJws = await (0, deviceAuthorization_1.authorizeExactRequest)({
|
|
121
|
+
authKey: args.authKey,
|
|
122
|
+
authKeyId: args.authKeyId,
|
|
123
|
+
operation: args.operation,
|
|
124
|
+
bodyBytes: args.bodyBytes,
|
|
125
|
+
});
|
|
126
|
+
return args.transport.send({
|
|
127
|
+
method: 'POST',
|
|
128
|
+
path: args.path,
|
|
129
|
+
query: null,
|
|
130
|
+
headers: {
|
|
131
|
+
'Content-Type': 'application/json',
|
|
132
|
+
[deviceAuthorization_1.DEVICE_AUTHORIZATION_HEADER]: compactJws,
|
|
133
|
+
},
|
|
134
|
+
bodyBytes: args.bodyBytes,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
function mapSignedRequestFailure(response, bodyBytes) {
|
|
138
|
+
const correlationId = (0, headers_1.headerValueIgnoringCase)(response.headers, 'X-Request-Id');
|
|
139
|
+
const daaStatusCode = (0, errorEnvelope_1.readDaaStatusCode)(response.bodyBytes);
|
|
140
|
+
const fallback = () => (0, errors_1.apiFailure)({
|
|
141
|
+
httpStatus: response.status,
|
|
142
|
+
daaStatusCode,
|
|
143
|
+
correlationId,
|
|
144
|
+
});
|
|
145
|
+
if ((0, daaStatusCodes_1.isDaaStatus)(daaStatusCode, 'IDEMPOTENCY_KEY_REUSED')) {
|
|
146
|
+
// Gated on both the status code and the HTTP status, so a body that
|
|
147
|
+
// carries this code on some other status falls through to the generic
|
|
148
|
+
// `api` failure below rather than being trusted. The contract puts this
|
|
149
|
+
// code at `409`, which is where DAA's transfer and withdrawal
|
|
150
|
+
// create routes send it. Non-custodial account create never sends it (a
|
|
151
|
+
// reused key returns the original account). Recovered from the signed
|
|
152
|
+
// request's own bytes, not the response — `idempotencyKeyFromExactBody`
|
|
153
|
+
// returns `undefined` for a bodyless request (`getSignedResource`), so this
|
|
154
|
+
// never fires for `get_device_context`.
|
|
155
|
+
const idempotencyKey = response.status === 409 ? (0, deviceAuthorization_1.idempotencyKeyFromExactBody)(bodyBytes) : undefined;
|
|
156
|
+
return idempotencyKey !== undefined
|
|
157
|
+
? (0, errors_1.idempotencyConflict)(idempotencyKey, correlationId)
|
|
158
|
+
: fallback();
|
|
159
|
+
}
|
|
160
|
+
if ((0, daaStatusCodes_1.isDaaStatus)(daaStatusCode, 'DEVICE_AUTHORIZATION_REPLAYED') ||
|
|
161
|
+
(0, daaStatusCodes_1.isDaaStatus)(daaStatusCode, 'DEVICE_AUTHORIZATION_REQUEST_MISMATCH')) {
|
|
162
|
+
return (0, errors_1.contractViolation)('the device authorization was replayed or did not match the request', correlationId);
|
|
163
|
+
}
|
|
164
|
+
if ((0, daaStatusCodes_1.isDaaStatus)(daaStatusCode, 'DEVICE_AUTHORIZATION_INVALID')) {
|
|
165
|
+
return (0, errors_1.contractViolation)('the device authorization was rejected', correlationId);
|
|
166
|
+
}
|
|
167
|
+
return fallback();
|
|
168
|
+
}
|
|
@@ -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 (`authKeyPublicKey`) | **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,80 @@
|
|
|
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
|
+
* Native ES256 verification of a Prepare receipt signature, delegated to the
|
|
34
|
+
* native SDKs' `DaaPrepareReceiptSignature` (CryptoKit on iOS,
|
|
35
|
+
* `java.security` on Android). All three arguments are unpadded
|
|
36
|
+
* Base64URL — the uncompressed P-256 point of a pinned key, the exact JWS
|
|
37
|
+
* signing input, and the 64-byte JOSE `R || S` signature. Resolves `true`
|
|
38
|
+
* only for a valid signature; rejects when the key is not a P-256 point.
|
|
39
|
+
*/
|
|
40
|
+
verifyPrepareReceiptSignature(publicKeyX963Base64Url: string, signingInputBase64Url: string, signatureBase64Url: string): Promise<boolean>;
|
|
41
|
+
}
|
|
42
|
+
export declare function optionalDaaRegistrationNative(): DaaRegistrationNativeModule | null;
|
|
43
|
+
export declare function requireDaaRegistrationNative(): DaaRegistrationNativeModule;
|
|
44
|
+
/** Verifier bytes from native `DaaSecureRandom`, decoded at the seam. */
|
|
45
|
+
export declare function nativeRandomBytes(native: DaaRegistrationNativeModule, count: number): Uint8Array;
|
|
46
|
+
export declare function nativeRandomUuidV4(native: DaaRegistrationNativeModule): string;
|
|
47
|
+
export declare function nativeGenerateRegistrationFlowKey(native: DaaRegistrationNativeModule): string;
|
|
48
|
+
export declare function nativeRegistrationFlowPublicKeySpkiBase64Url(native: DaaRegistrationNativeModule, id: string): string;
|
|
49
|
+
/**
|
|
50
|
+
* Sign the exact Device Registration Complete flow-JWS signing input with the
|
|
51
|
+
* cached native flow key. Returns unpadded Base64URL of the 64-byte JOSE
|
|
52
|
+
* `R || S` signature. Not a generic sign: `id` names a cached
|
|
53
|
+
* `DaaRegistrationFlowKey`, and native validates the bytes as a registration
|
|
54
|
+
* authorization signing input before it ever touches the private key.
|
|
55
|
+
*/
|
|
56
|
+
export declare function nativeSignRegistrationAuthorization(native: DaaRegistrationNativeModule, id: string, signingInputBase64Url: string): Uint8Array;
|
|
57
|
+
/**
|
|
58
|
+
* Verify one ES256 signature with platform crypto.
|
|
59
|
+
*
|
|
60
|
+
* Only a literal `true` from native counts as verified. Anything else — `false`,
|
|
61
|
+
* a non-boolean, a rejection, a missing function on an older host build — is
|
|
62
|
+
* not a pass: a rejection or a missing function is a `contract_violation`, and
|
|
63
|
+
* any other value is `false`.
|
|
64
|
+
*/
|
|
65
|
+
export declare function nativeVerifyPrepareReceiptSignature(native: DaaRegistrationNativeModule, args: Readonly<{
|
|
66
|
+
publicKeyX963: Uint8Array;
|
|
67
|
+
signingInput: Uint8Array;
|
|
68
|
+
signature: Uint8Array;
|
|
69
|
+
}>): Promise<boolean>;
|
|
70
|
+
/**
|
|
71
|
+
* Drop a cached native flow key.
|
|
72
|
+
*
|
|
73
|
+
* Cleanup, so it is forgiving: an older host app whose module predates this
|
|
74
|
+
* function, or an id the native side no longer holds, is not an error. The
|
|
75
|
+
* alternative would make a `finally` block throw over tidying up and mask the
|
|
76
|
+
* failure that sent it there. What it must not do is fail silently in a way
|
|
77
|
+
* that leaves key material resident — hence the explicit function check rather
|
|
78
|
+
* than an optional-call shrug.
|
|
79
|
+
*/
|
|
80
|
+
export declare function nativeReleaseRegistrationFlowKey(native: DaaRegistrationNativeModule, id: string): void;
|