@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,150 @@
|
|
|
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 { DaaEnvironment } from '../config';
|
|
19
|
+
import type { P256PublicJwk } from '../crypto/jwkThumbprint';
|
|
20
|
+
/** Contract bounds on `SocialLoginRequest.prepareReceiptJws`. */
|
|
21
|
+
export declare const PREPARE_RECEIPT_MIN_LENGTH = 64;
|
|
22
|
+
export declare const PREPARE_RECEIPT_MAX_LENGTH = 8192;
|
|
23
|
+
/** The JWS `typ` DAA signs the receipt with. */
|
|
24
|
+
export declare const PREPARE_RECEIPT_TYP = "daa-prepare-receipt+jws";
|
|
25
|
+
/** Widest clock skew an anchor may allow, so a configuration typo cannot disable expiry. */
|
|
26
|
+
export declare const PREPARE_RECEIPT_MAX_CLOCK_SKEW_SECONDS = 300;
|
|
27
|
+
/** One pinned receipt-signing key, addressed by the `kid` DAA puts in the header. */
|
|
28
|
+
export type PrepareReceiptVerificationKey = Readonly<{
|
|
29
|
+
kid: string;
|
|
30
|
+
jwk: P256PublicJwk;
|
|
31
|
+
}>;
|
|
32
|
+
/**
|
|
33
|
+
* Everything a trust anchor pins, in one value.
|
|
34
|
+
*
|
|
35
|
+
* `verificationKeys` is pinned by the build and never derived from a receipt.
|
|
36
|
+
* More than one entry allows a rotation overlap; the receipt's `kid` selects
|
|
37
|
+
* among them and nothing else.
|
|
38
|
+
*/
|
|
39
|
+
export type PrepareReceiptTrustAnchor = Readonly<{
|
|
40
|
+
/** Exact expected `iss`. */
|
|
41
|
+
issuer: string;
|
|
42
|
+
/** Exact expected `aud`, or one member of an `aud` array. */
|
|
43
|
+
audience: string;
|
|
44
|
+
verificationKeys: readonly PrepareReceiptVerificationKey[];
|
|
45
|
+
/** Allowance on `exp` / `iat` / `nbf`, in seconds. */
|
|
46
|
+
maxClockSkewSeconds: number;
|
|
47
|
+
}>;
|
|
48
|
+
/**
|
|
49
|
+
* The build-time pinned anchor for an environment. **`null` for every
|
|
50
|
+
* environment in this release.**
|
|
51
|
+
*
|
|
52
|
+
* A function rather than a `const`, so that its declared return type does not
|
|
53
|
+
* narrow the rest of this module to unreachable code.
|
|
54
|
+
*/
|
|
55
|
+
export declare function pinnedPrepareReceiptTrustAnchor(environment: DaaEnvironment): PrepareReceiptTrustAnchor | null;
|
|
56
|
+
/**
|
|
57
|
+
* The values this attempt's receipt must name. The first two come from the
|
|
58
|
+
* Prepare response; the rest are the SDK's own.
|
|
59
|
+
*/
|
|
60
|
+
export type PrepareReceiptExpectation = Readonly<{
|
|
61
|
+
loginRequestId: string;
|
|
62
|
+
/** The Prepare response's `oidcNonce`; the receipt's `nonce` claim. */
|
|
63
|
+
nonce: string;
|
|
64
|
+
provider: string;
|
|
65
|
+
environment: DaaEnvironment;
|
|
66
|
+
registrationCodeChallenge: string;
|
|
67
|
+
registrationFlowKeyThumbprint: string;
|
|
68
|
+
}>;
|
|
69
|
+
/**
|
|
70
|
+
* Test-only clock, following `auth/deviceAuthorization.ts`: production code
|
|
71
|
+
* always uses the system clock, and no production caller passes one.
|
|
72
|
+
*/
|
|
73
|
+
export type PrepareReceiptClock = Readonly<{
|
|
74
|
+
nowEpochSeconds: () => number;
|
|
75
|
+
}>;
|
|
76
|
+
/** What a verified receipt attested. Only ever returned after every check passed. */
|
|
77
|
+
export type VerifiedPrepareReceipt = Readonly<{
|
|
78
|
+
/** The receipt exactly as received. */
|
|
79
|
+
compactJws: string;
|
|
80
|
+
loginRequestId: string;
|
|
81
|
+
nonce: string;
|
|
82
|
+
expiresAtEpochSeconds: number;
|
|
83
|
+
/** Signed but not compared on the login path; see {@link requirePrepareReceiptTenantScope}. */
|
|
84
|
+
tenantScope: Readonly<{
|
|
85
|
+
customerAppId: unknown;
|
|
86
|
+
parentEntityIdDigest: unknown;
|
|
87
|
+
}>;
|
|
88
|
+
}>;
|
|
89
|
+
/**
|
|
90
|
+
* Whether a value is shaped like the compact JWS the contract describes and sits
|
|
91
|
+
* within its declared length bounds. Structural only: shape is not trust.
|
|
92
|
+
*/
|
|
93
|
+
export declare function isPrepareReceiptShape(value: string): boolean;
|
|
94
|
+
/**
|
|
95
|
+
* What login does with the receipt, given the anchor for this environment.
|
|
96
|
+
*
|
|
97
|
+
* | Anchor | Receipt | Result |
|
|
98
|
+
* | ------ | ------- | ----------------------------------------------------------- |
|
|
99
|
+
* | unset | absent | `null`: nothing to verify, login proceeds |
|
|
100
|
+
* | unset | present | `null`: the receipt is ignored, login proceeds as if absent |
|
|
101
|
+
* | set | absent | `prepare_receipt_invalid`: the receipt is required |
|
|
102
|
+
* | set | present | {@link verifyPrepareReceipt}; any failure throws |
|
|
103
|
+
*
|
|
104
|
+
* `prepareReceiptJws` is the raw response member: `undefined` or `null` is
|
|
105
|
+
* absent, and anything else is present, whatever its type. In the first two
|
|
106
|
+
* rows it is not read at all, and `expected` is a thunk so they compute
|
|
107
|
+
* nothing: with no anchor, the login path does no receipt work.
|
|
108
|
+
*
|
|
109
|
+
* In the second row, an SDK without the anchor ignores the receipt: it could
|
|
110
|
+
* not verify it, so ignoring gives up no protection. An ignored receipt is
|
|
111
|
+
* never passed on as if it were checked: this returns `null` for it exactly as
|
|
112
|
+
* for no receipt, so the login path hands the application no receipt at all.
|
|
113
|
+
*/
|
|
114
|
+
export declare function checkPrepareReceipt(prepareReceiptJws: unknown, anchor: PrepareReceiptTrustAnchor | null, expected: () => PrepareReceiptExpectation, clock?: PrepareReceiptClock): Promise<VerifiedPrepareReceipt | null>;
|
|
115
|
+
/**
|
|
116
|
+
* Verify the receipt against a trust anchor and this attempt's expectation.
|
|
117
|
+
*
|
|
118
|
+
* Order: the anchor and the expectation first, because a fault in either is a
|
|
119
|
+
* configuration error; then the receipt's shape; then its header and signature;
|
|
120
|
+
* and only then the claims, because a claim from an unverified token is not
|
|
121
|
+
* evidence of anything.
|
|
122
|
+
*
|
|
123
|
+
* A fault in the anchor, the expectation, or the clock is `contract_violation`;
|
|
124
|
+
* every rejection of the receipt itself, including a platform verifier that is
|
|
125
|
+
* missing or fails, is `prepare_receipt_invalid`.
|
|
126
|
+
*
|
|
127
|
+
* The receipt is never interpolated into an error: it is unverified
|
|
128
|
+
* server-supplied text, and a consumer is likely to log the message verbatim.
|
|
129
|
+
*/
|
|
130
|
+
export declare function verifyPrepareReceipt(prepareReceiptJws: unknown, anchor: PrepareReceiptTrustAnchor, expected: PrepareReceiptExpectation, clock?: PrepareReceiptClock): Promise<VerifiedPrepareReceipt>;
|
|
131
|
+
/**
|
|
132
|
+
* Domain separator for `parentEntityIdDigest`, byte-for-byte the one DAA
|
|
133
|
+
* signs with. The trailing NUL is part of it.
|
|
134
|
+
*/
|
|
135
|
+
export declare const PARENT_ENTITY_ID_DIGEST_DOMAIN = "daa-prepare-receipt-parent-entity-digest-v1\0";
|
|
136
|
+
/**
|
|
137
|
+
* `base64url_nopad(SHA-256(utf8(domain) || utf8(parentEntityId)))`, where the
|
|
138
|
+
* id is the canonical lower-case hyphenated UUID — DAA's pinned formula.
|
|
139
|
+
*/
|
|
140
|
+
export declare function parentEntityIdDigest(parentEntityId: string): string;
|
|
141
|
+
/**
|
|
142
|
+
* Tenant-scope comparison for a verified receipt. **Not called on the login
|
|
143
|
+
* path:** the SDK has no defined way to derive the expected parent entity from
|
|
144
|
+
* its configuration. A caller that has the expected values calls this after
|
|
145
|
+
* {@link verifyPrepareReceipt}.
|
|
146
|
+
*/
|
|
147
|
+
export declare function requirePrepareReceiptTenantScope(receipt: VerifiedPrepareReceipt, expected: Readonly<{
|
|
148
|
+
customerAppId: string;
|
|
149
|
+
parentEntityId: string;
|
|
150
|
+
}>): void;
|
|
@@ -0,0 +1,357 @@
|
|
|
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.PARENT_ENTITY_ID_DIGEST_DOMAIN = exports.PREPARE_RECEIPT_MAX_CLOCK_SKEW_SECONDS = exports.PREPARE_RECEIPT_TYP = exports.PREPARE_RECEIPT_MAX_LENGTH = exports.PREPARE_RECEIPT_MIN_LENGTH = void 0;
|
|
21
|
+
exports.pinnedPrepareReceiptTrustAnchor = pinnedPrepareReceiptTrustAnchor;
|
|
22
|
+
exports.isPrepareReceiptShape = isPrepareReceiptShape;
|
|
23
|
+
exports.checkPrepareReceipt = checkPrepareReceipt;
|
|
24
|
+
exports.verifyPrepareReceipt = verifyPrepareReceipt;
|
|
25
|
+
exports.parentEntityIdDigest = parentEntityIdDigest;
|
|
26
|
+
exports.requirePrepareReceiptTenantScope = requirePrepareReceiptTenantScope;
|
|
27
|
+
const base64url_1 = require("../crypto/base64url");
|
|
28
|
+
const es256Jws_1 = require("../crypto/es256Jws");
|
|
29
|
+
const sha256_1 = require("../crypto/sha256");
|
|
30
|
+
const errors_1 = require("../errors");
|
|
31
|
+
const uuid_1 = require("../validation/uuid");
|
|
32
|
+
/** Contract bounds on `SocialLoginRequest.prepareReceiptJws`. */
|
|
33
|
+
exports.PREPARE_RECEIPT_MIN_LENGTH = 64;
|
|
34
|
+
exports.PREPARE_RECEIPT_MAX_LENGTH = 8192;
|
|
35
|
+
/** The JWS `typ` DAA signs the receipt with. */
|
|
36
|
+
exports.PREPARE_RECEIPT_TYP = 'daa-prepare-receipt+jws';
|
|
37
|
+
/** Widest clock skew an anchor may allow, so a configuration typo cannot disable expiry. */
|
|
38
|
+
exports.PREPARE_RECEIPT_MAX_CLOCK_SKEW_SECONDS = 300;
|
|
39
|
+
/** Compact JWS serialization: three Base64URL segments separated by dots. */
|
|
40
|
+
const COMPACT_JWS = /^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/;
|
|
41
|
+
/**
|
|
42
|
+
* The build-time pinned anchor for an environment. **`null` for every
|
|
43
|
+
* environment in this release.**
|
|
44
|
+
*
|
|
45
|
+
* A function rather than a `const`, so that its declared return type does not
|
|
46
|
+
* narrow the rest of this module to unreachable code.
|
|
47
|
+
*/
|
|
48
|
+
function pinnedPrepareReceiptTrustAnchor(environment) {
|
|
49
|
+
void environment;
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
const SYSTEM_CLOCK = {
|
|
53
|
+
nowEpochSeconds: () => Math.floor(Date.now() / 1000),
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Whether a value is shaped like the compact JWS the contract describes and sits
|
|
57
|
+
* within its declared length bounds. Structural only: shape is not trust.
|
|
58
|
+
*/
|
|
59
|
+
function isPrepareReceiptShape(value) {
|
|
60
|
+
return (value.length >= exports.PREPARE_RECEIPT_MIN_LENGTH &&
|
|
61
|
+
value.length <= exports.PREPARE_RECEIPT_MAX_LENGTH &&
|
|
62
|
+
COMPACT_JWS.test(value));
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* What login does with the receipt, given the anchor for this environment.
|
|
66
|
+
*
|
|
67
|
+
* | Anchor | Receipt | Result |
|
|
68
|
+
* | ------ | ------- | ----------------------------------------------------------- |
|
|
69
|
+
* | unset | absent | `null`: nothing to verify, login proceeds |
|
|
70
|
+
* | unset | present | `null`: the receipt is ignored, login proceeds as if absent |
|
|
71
|
+
* | set | absent | `prepare_receipt_invalid`: the receipt is required |
|
|
72
|
+
* | set | present | {@link verifyPrepareReceipt}; any failure throws |
|
|
73
|
+
*
|
|
74
|
+
* `prepareReceiptJws` is the raw response member: `undefined` or `null` is
|
|
75
|
+
* absent, and anything else is present, whatever its type. In the first two
|
|
76
|
+
* rows it is not read at all, and `expected` is a thunk so they compute
|
|
77
|
+
* nothing: with no anchor, the login path does no receipt work.
|
|
78
|
+
*
|
|
79
|
+
* In the second row, an SDK without the anchor ignores the receipt: it could
|
|
80
|
+
* not verify it, so ignoring gives up no protection. An ignored receipt is
|
|
81
|
+
* never passed on as if it were checked: this returns `null` for it exactly as
|
|
82
|
+
* for no receipt, so the login path hands the application no receipt at all.
|
|
83
|
+
*/
|
|
84
|
+
async function checkPrepareReceipt(prepareReceiptJws, anchor, expected, clock = SYSTEM_CLOCK) {
|
|
85
|
+
if (anchor === null) {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
if (prepareReceiptJws === undefined || prepareReceiptJws === null) {
|
|
89
|
+
throw (0, errors_1.prepareReceiptInvalid)('the Prepare response carries no receipt, and this environment requires one');
|
|
90
|
+
}
|
|
91
|
+
return verifyPrepareReceipt(prepareReceiptJws, anchor, expected(), clock);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Verify the receipt against a trust anchor and this attempt's expectation.
|
|
95
|
+
*
|
|
96
|
+
* Order: the anchor and the expectation first, because a fault in either is a
|
|
97
|
+
* configuration error; then the receipt's shape; then its header and signature;
|
|
98
|
+
* and only then the claims, because a claim from an unverified token is not
|
|
99
|
+
* evidence of anything.
|
|
100
|
+
*
|
|
101
|
+
* A fault in the anchor, the expectation, or the clock is `contract_violation`;
|
|
102
|
+
* every rejection of the receipt itself, including a platform verifier that is
|
|
103
|
+
* missing or fails, is `prepare_receipt_invalid`.
|
|
104
|
+
*
|
|
105
|
+
* The receipt is never interpolated into an error: it is unverified
|
|
106
|
+
* server-supplied text, and a consumer is likely to log the message verbatim.
|
|
107
|
+
*/
|
|
108
|
+
async function verifyPrepareReceipt(prepareReceiptJws, anchor, expected, clock = SYSTEM_CLOCK) {
|
|
109
|
+
const keys = pinnedKeys(anchor);
|
|
110
|
+
requireExpectation(expected);
|
|
111
|
+
const now = clock.nowEpochSeconds();
|
|
112
|
+
if (!Number.isInteger(now) || now <= 0) {
|
|
113
|
+
throw (0, errors_1.contractViolation)('the Prepare receipt clock must yield a positive Unix timestamp');
|
|
114
|
+
}
|
|
115
|
+
if (typeof prepareReceiptJws !== 'string' || !isPrepareReceiptShape(prepareReceiptJws)) {
|
|
116
|
+
throw (0, errors_1.prepareReceiptInvalid)('the Prepare receipt is not a compact JWS within the contract length bounds');
|
|
117
|
+
}
|
|
118
|
+
const result = await platformVerify(prepareReceiptJws, keys);
|
|
119
|
+
if (!result.verified) {
|
|
120
|
+
throw (0, errors_1.prepareReceiptInvalid)(`the Prepare receipt did not verify (${result.reason})`);
|
|
121
|
+
}
|
|
122
|
+
const claims = result.payload;
|
|
123
|
+
requireClaimEquals(claims, 'iss', anchor.issuer);
|
|
124
|
+
requireAudience(claims, anchor.audience);
|
|
125
|
+
requireNonEmptyClaim(claims, 'jti');
|
|
126
|
+
requireClaimEquals(claims, 'environment', expected.environment);
|
|
127
|
+
requireClaimEquals(claims, 'provider', expected.provider);
|
|
128
|
+
requireClaimEquals(claims, 'loginRequestId', expected.loginRequestId);
|
|
129
|
+
requireClaimEquals(claims, 'nonce', expected.nonce);
|
|
130
|
+
requireClaimEquals(claims, 'registrationCodeChallenge', expected.registrationCodeChallenge);
|
|
131
|
+
requireClaimEquals(claims, 'registrationFlowKeyThumbprint', expected.registrationFlowKeyThumbprint);
|
|
132
|
+
const expiresAtEpochSeconds = requireTimeClaims(claims, now, anchor.maxClockSkewSeconds);
|
|
133
|
+
return {
|
|
134
|
+
compactJws: prepareReceiptJws,
|
|
135
|
+
loginRequestId: expected.loginRequestId,
|
|
136
|
+
nonce: expected.nonce,
|
|
137
|
+
expiresAtEpochSeconds,
|
|
138
|
+
tenantScope: {
|
|
139
|
+
customerAppId: (0, es256Jws_1.ownMember)(claims, 'customerAppId'),
|
|
140
|
+
parentEntityIdDigest: (0, es256Jws_1.ownMember)(claims, 'parentEntityIdDigest'),
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* The signature check, with a platform verifier that is missing or fails
|
|
146
|
+
* reported as the receipt failing to verify.
|
|
147
|
+
*
|
|
148
|
+
* `pinnedKeys` has already validated everything {@link verifyCompactEs256}
|
|
149
|
+
* would reject as a configuration error, so the only `DaaError` left to come
|
|
150
|
+
* out of it is the platform's: no `DaaRegistration` module, one without the
|
|
151
|
+
* verify function, or a native rejection. A native rejection also covers a
|
|
152
|
+
* pinned point the platform does not accept as on the curve — the one anchor
|
|
153
|
+
* fault only the platform can see, and indistinguishable here from the rest.
|
|
154
|
+
* The SDK's own message and the original error (as `cause`) are kept.
|
|
155
|
+
*/
|
|
156
|
+
async function platformVerify(jws, keys) {
|
|
157
|
+
try {
|
|
158
|
+
return await (0, es256Jws_1.verifyCompactEs256)(jws, { keys, expectedTyp: exports.PREPARE_RECEIPT_TYP });
|
|
159
|
+
}
|
|
160
|
+
catch (err) {
|
|
161
|
+
if ((0, errors_1.isDaaError)(err) && err.detail.kind === 'contract_violation') {
|
|
162
|
+
throw new errors_1.DaaError({ kind: 'prepare_receipt_invalid' }, err.message, err);
|
|
163
|
+
}
|
|
164
|
+
throw err;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Domain separator for `parentEntityIdDigest`, byte-for-byte the one DAA
|
|
169
|
+
* signs with. The trailing NUL is part of it.
|
|
170
|
+
*/
|
|
171
|
+
exports.PARENT_ENTITY_ID_DIGEST_DOMAIN = 'daa-prepare-receipt-parent-entity-digest-v1\0';
|
|
172
|
+
/**
|
|
173
|
+
* `base64url_nopad(SHA-256(utf8(domain) || utf8(parentEntityId)))`, where the
|
|
174
|
+
* id is the canonical lower-case hyphenated UUID — DAA's pinned formula.
|
|
175
|
+
*/
|
|
176
|
+
function parentEntityIdDigest(parentEntityId) {
|
|
177
|
+
if (typeof parentEntityId !== 'string' ||
|
|
178
|
+
!(0, uuid_1.isUuid)(parentEntityId) ||
|
|
179
|
+
parentEntityId !== parentEntityId.toLowerCase()) {
|
|
180
|
+
throw (0, errors_1.contractViolation)('parentEntityId must be a canonical lower-case UUID');
|
|
181
|
+
}
|
|
182
|
+
const encoder = new TextEncoder();
|
|
183
|
+
const domain = encoder.encode(exports.PARENT_ENTITY_ID_DIGEST_DOMAIN);
|
|
184
|
+
const id = encoder.encode(parentEntityId);
|
|
185
|
+
const input = new Uint8Array(domain.length + id.length);
|
|
186
|
+
input.set(domain);
|
|
187
|
+
input.set(id, domain.length);
|
|
188
|
+
return (0, base64url_1.toBase64Url)((0, sha256_1.sha256)(input));
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Tenant-scope comparison for a verified receipt. **Not called on the login
|
|
192
|
+
* path:** the SDK has no defined way to derive the expected parent entity from
|
|
193
|
+
* its configuration. A caller that has the expected values calls this after
|
|
194
|
+
* {@link verifyPrepareReceipt}.
|
|
195
|
+
*/
|
|
196
|
+
function requirePrepareReceiptTenantScope(receipt, expected) {
|
|
197
|
+
const { customerAppId, parentEntityIdDigest: digest } = receipt.tenantScope;
|
|
198
|
+
if (typeof customerAppId !== 'string' || customerAppId !== expected.customerAppId) {
|
|
199
|
+
throw (0, errors_1.prepareReceiptInvalid)('the Prepare receipt does not bind the expected customerAppId');
|
|
200
|
+
}
|
|
201
|
+
if (typeof digest !== 'string' || digest !== parentEntityIdDigest(expected.parentEntityId)) {
|
|
202
|
+
throw (0, errors_1.prepareReceiptInvalid)('the Prepare receipt does not bind the expected parentEntityIdDigest');
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Validate the anchor and convert its keys to the points the platform verifies
|
|
207
|
+
* against. A malformed anchor is a configuration error, not a rejected receipt.
|
|
208
|
+
* Whether each point is on the curve is the platform's check.
|
|
209
|
+
*/
|
|
210
|
+
function pinnedKeys(anchor) {
|
|
211
|
+
if (typeof anchor !== 'object' || anchor === null) {
|
|
212
|
+
throw (0, errors_1.contractViolation)('the Prepare receipt trust anchor must be an object');
|
|
213
|
+
}
|
|
214
|
+
if (typeof anchor.issuer !== 'string' || anchor.issuer.length === 0) {
|
|
215
|
+
throw (0, errors_1.contractViolation)('the Prepare receipt trust anchor must name an issuer');
|
|
216
|
+
}
|
|
217
|
+
if (typeof anchor.audience !== 'string' || anchor.audience.length === 0) {
|
|
218
|
+
throw (0, errors_1.contractViolation)('the Prepare receipt trust anchor must name an audience');
|
|
219
|
+
}
|
|
220
|
+
if (!Number.isInteger(anchor.maxClockSkewSeconds) ||
|
|
221
|
+
anchor.maxClockSkewSeconds < 0 ||
|
|
222
|
+
anchor.maxClockSkewSeconds > exports.PREPARE_RECEIPT_MAX_CLOCK_SKEW_SECONDS) {
|
|
223
|
+
throw (0, errors_1.contractViolation)('the Prepare receipt trust anchor clock skew must be between 0 and ' +
|
|
224
|
+
`${exports.PREPARE_RECEIPT_MAX_CLOCK_SKEW_SECONDS} seconds`);
|
|
225
|
+
}
|
|
226
|
+
if (!Array.isArray(anchor.verificationKeys) || anchor.verificationKeys.length === 0) {
|
|
227
|
+
throw (0, errors_1.contractViolation)('the Prepare receipt trust anchor must pin at least one P-256 key');
|
|
228
|
+
}
|
|
229
|
+
const kids = new Set();
|
|
230
|
+
for (const key of anchor.verificationKeys) {
|
|
231
|
+
if (typeof key !== 'object' || key === null) {
|
|
232
|
+
throw (0, errors_1.contractViolation)('every Prepare receipt verification key must be an object');
|
|
233
|
+
}
|
|
234
|
+
if (typeof key.kid !== 'string' || key.kid.length === 0) {
|
|
235
|
+
throw (0, errors_1.contractViolation)('every Prepare receipt verification key must have a non-empty kid');
|
|
236
|
+
}
|
|
237
|
+
if (kids.has(key.kid)) {
|
|
238
|
+
throw (0, errors_1.contractViolation)('Prepare receipt verification keys must have distinct kids');
|
|
239
|
+
}
|
|
240
|
+
kids.add(key.kid);
|
|
241
|
+
}
|
|
242
|
+
return anchor.verificationKeys.map((key) => ({
|
|
243
|
+
kid: key.kid,
|
|
244
|
+
publicKeyX963: x963FromJwk(key.jwk),
|
|
245
|
+
}));
|
|
246
|
+
}
|
|
247
|
+
function x963FromJwk(jwk) {
|
|
248
|
+
if (typeof jwk !== 'object' || jwk === null || jwk.kty !== 'EC' || jwk.crv !== 'P-256') {
|
|
249
|
+
throw (0, errors_1.contractViolation)('a Prepare receipt verification key must be an EC P-256 JWK');
|
|
250
|
+
}
|
|
251
|
+
let x;
|
|
252
|
+
let y;
|
|
253
|
+
try {
|
|
254
|
+
x = (0, base64url_1.fromBase64Url)(jwk.x);
|
|
255
|
+
y = (0, base64url_1.fromBase64Url)(jwk.y);
|
|
256
|
+
}
|
|
257
|
+
catch {
|
|
258
|
+
throw (0, errors_1.contractViolation)('a Prepare receipt verification key has a non-Base64URL coordinate');
|
|
259
|
+
}
|
|
260
|
+
if (x.length !== 32 || y.length !== 32) {
|
|
261
|
+
throw (0, errors_1.contractViolation)('a Prepare receipt verification key must have 32-byte x and y coordinates');
|
|
262
|
+
}
|
|
263
|
+
const point = new Uint8Array(65);
|
|
264
|
+
point[0] = 0x04;
|
|
265
|
+
point.set(x, 1);
|
|
266
|
+
point.set(y, 33);
|
|
267
|
+
return point;
|
|
268
|
+
}
|
|
269
|
+
function requireExpectation(expected) {
|
|
270
|
+
if (typeof expected !== 'object' || expected === null) {
|
|
271
|
+
throw (0, errors_1.contractViolation)('verifying a Prepare receipt requires the expected values for this attempt');
|
|
272
|
+
}
|
|
273
|
+
for (const name of [
|
|
274
|
+
'loginRequestId',
|
|
275
|
+
'nonce',
|
|
276
|
+
'provider',
|
|
277
|
+
'environment',
|
|
278
|
+
'registrationCodeChallenge',
|
|
279
|
+
'registrationFlowKeyThumbprint',
|
|
280
|
+
]) {
|
|
281
|
+
const value = expected[name];
|
|
282
|
+
if (typeof value !== 'string' || value.length === 0) {
|
|
283
|
+
throw (0, errors_1.contractViolation)(`verifying a Prepare receipt requires the expected ${name}`);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Exact string equality on one claim. Not constant-time, and does not need to
|
|
289
|
+
* be: every value compared is one the SDK sent, generated, or relayed to the
|
|
290
|
+
* application; none is a secret. The claim name goes in the message — it is
|
|
291
|
+
* one of this module's literals — and the value never does.
|
|
292
|
+
*/
|
|
293
|
+
function requireClaimEquals(claims, name, expected) {
|
|
294
|
+
const actual = (0, es256Jws_1.ownMember)(claims, name);
|
|
295
|
+
if (typeof actual !== 'string' || actual !== expected) {
|
|
296
|
+
throw (0, errors_1.prepareReceiptInvalid)(`the Prepare receipt does not bind the expected ${name}`);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
function requireNonEmptyClaim(claims, name) {
|
|
300
|
+
const actual = (0, es256Jws_1.ownMember)(claims, name);
|
|
301
|
+
if (typeof actual !== 'string' || actual.length === 0) {
|
|
302
|
+
throw (0, errors_1.prepareReceiptInvalid)(`the Prepare receipt does not carry a ${name}`);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
/** RFC 7519 §4.1.3: `aud` is a string or an array of strings that must contain ours. */
|
|
306
|
+
function requireAudience(claims, audience) {
|
|
307
|
+
const actual = (0, es256Jws_1.ownMember)(claims, 'aud');
|
|
308
|
+
if (typeof actual === 'string' && actual === audience) {
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
if (Array.isArray(actual) && actual.some((value) => value === audience)) {
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
throw (0, errors_1.prepareReceiptInvalid)('the Prepare receipt does not bind the expected aud');
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* `exp` and `iat` are required (DAA always sets both); `nbf` is checked when
|
|
318
|
+
* present. All are RFC 7519 NumericDates in seconds — deliberately not the
|
|
319
|
+
* epoch-millis tolerance `wire/instant.ts` carries for the Prepare body, since
|
|
320
|
+
* DAA's signer emits seconds. A millisecond value fails the upper bound below
|
|
321
|
+
* instead of passing as an expiry thousands of years out.
|
|
322
|
+
*/
|
|
323
|
+
function requireTimeClaims(claims, nowEpochSeconds, maxClockSkewSeconds) {
|
|
324
|
+
const exp = requireNumericDate(claims, 'exp');
|
|
325
|
+
const iat = requireNumericDate(claims, 'iat');
|
|
326
|
+
if (exp + maxClockSkewSeconds < nowEpochSeconds) {
|
|
327
|
+
throw (0, errors_1.prepareReceiptInvalid)('the Prepare receipt has expired');
|
|
328
|
+
}
|
|
329
|
+
if (iat - maxClockSkewSeconds > nowEpochSeconds) {
|
|
330
|
+
throw (0, errors_1.prepareReceiptInvalid)('the Prepare receipt is not valid yet (iat is in the future)');
|
|
331
|
+
}
|
|
332
|
+
if (iat > exp) {
|
|
333
|
+
throw (0, errors_1.prepareReceiptInvalid)('the Prepare receipt expires before it was issued');
|
|
334
|
+
}
|
|
335
|
+
if ((0, es256Jws_1.ownMember)(claims, 'nbf') !== undefined) {
|
|
336
|
+
const nbf = requireNumericDate(claims, 'nbf');
|
|
337
|
+
if (nbf - maxClockSkewSeconds > nowEpochSeconds) {
|
|
338
|
+
throw (0, errors_1.prepareReceiptInvalid)('the Prepare receipt is not valid yet (nbf is in the future)');
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
return exp;
|
|
342
|
+
}
|
|
343
|
+
/** Past year 9999 is not a clock; it is a unit mistake or a receipt that never expires. */
|
|
344
|
+
const MAX_NUMERIC_DATE = 253402300799;
|
|
345
|
+
function requireNumericDate(claims, name) {
|
|
346
|
+
const value = (0, es256Jws_1.ownMember)(claims, name);
|
|
347
|
+
if (value === undefined) {
|
|
348
|
+
throw (0, errors_1.prepareReceiptInvalid)(`the Prepare receipt does not carry an ${name}`);
|
|
349
|
+
}
|
|
350
|
+
if (typeof value !== 'number' ||
|
|
351
|
+
!Number.isInteger(value) ||
|
|
352
|
+
value <= 0 ||
|
|
353
|
+
value > MAX_NUMERIC_DATE) {
|
|
354
|
+
throw (0, errors_1.prepareReceiptInvalid)(`the Prepare receipt carries a malformed ${name}`);
|
|
355
|
+
}
|
|
356
|
+
return value;
|
|
357
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
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 { RegistrationFlowKey } from './RegistrationFlowKey';
|
|
19
|
+
import type { OwnerAuthKey } from '../securekey/SecureKey';
|
|
20
|
+
export declare const REGISTRATION_FLOW_AUTHORIZATION_HEADER = "X-Registration-Flow-Authorization";
|
|
21
|
+
export declare const REGISTRATION_DEVICE_AUTHORIZATION_HEADER = "X-Device-Authorization";
|
|
22
|
+
/** Public path of `completeDeviceRegistration` (OpenAPI + signed `canonical_path`). */
|
|
23
|
+
export declare const DEVICE_REGISTRATION_COMPLETE_PATH = "/v1/accounts/auth/deviceKeyRegistration";
|
|
24
|
+
export type RegistrationAuthorizationClock = Readonly<{
|
|
25
|
+
nowEpochSeconds: () => number;
|
|
26
|
+
jti: () => string;
|
|
27
|
+
}>;
|
|
28
|
+
export type RegistrationCompleteProofs = Readonly<{
|
|
29
|
+
flowJws: string;
|
|
30
|
+
deviceJws: string;
|
|
31
|
+
}>;
|
|
32
|
+
export type RegistrationCompleteAuthorizationRequest = Readonly<{
|
|
33
|
+
bodyBytes: Uint8Array;
|
|
34
|
+
registrationHandle: string;
|
|
35
|
+
registrationCodeVerifier: string;
|
|
36
|
+
/** The bound Owner's durable identifier; signed as `profile_id`. */
|
|
37
|
+
clientEntityId: string;
|
|
38
|
+
flowKey: RegistrationFlowKey;
|
|
39
|
+
authKey: OwnerAuthKey;
|
|
40
|
+
}>;
|
|
41
|
+
/**
|
|
42
|
+
* Build the two registration JWSs over the exact Complete body bytes.
|
|
43
|
+
*
|
|
44
|
+
* Serializes header and payload with `JSON.stringify` (DAA verifies the
|
|
45
|
+
* transmitted signing input and parsed claim semantics, not a reconstructed
|
|
46
|
+
* encoding). Each signature is 64-byte JOSE `R || S`.
|
|
47
|
+
*/
|
|
48
|
+
export declare function authorizeRegistrationComplete(request: RegistrationCompleteAuthorizationRequest, clock?: RegistrationAuthorizationClock): Promise<RegistrationCompleteProofs>;
|