@circle-fin/daa-react-native-sdk 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DaaReactNativeSdk.podspec +14 -8
- package/README.md +498 -24
- package/android/build.gradle +12 -7
- package/android/src/main/java/com/circle/daa/reactnative/DaaRegistrationModule.kt +1 -18
- package/android/src/main/java/com/circle/daa/reactnative/DaaSecureKeyExceptions.kt +38 -4
- package/android/src/main/java/com/circle/daa/reactnative/DaaSecureKeyModule.kt +139 -6
- package/android/src/main/java/com/circle/daa/reactnative/InstallationIdentityStore.kt +50 -1
- package/build/DaaClient.d.ts +183 -3
- package/build/DaaClient.js +296 -12
- package/build/api/AccountsClient.d.ts +3 -0
- package/build/api/AccountsClient.js +3 -0
- package/build/api/AuthClient.d.ts +17 -42
- package/build/api/AuthClient.js +26 -62
- package/build/api/ContractExecutionsClient.d.ts +114 -0
- package/build/api/ContractExecutionsClient.js +462 -0
- package/build/api/DaaUserClient.d.ts +74 -11
- package/build/api/DaaUserClient.js +84 -17
- package/build/api/TransactionsClient.d.ts +1 -1
- package/build/api/TransactionsClient.js +1 -0
- package/build/api/TransfersClient.d.ts +3 -0
- package/build/api/TransfersClient.js +3 -0
- package/build/api/WithdrawalsClient.d.ts +3 -0
- package/build/api/WithdrawalsClient.js +3 -0
- package/build/api/deviceApproval.d.ts +48 -0
- package/build/api/deviceApproval.js +247 -0
- package/build/api/deviceStatus.d.ts +61 -0
- package/build/api/deviceStatus.js +216 -0
- package/build/api/loginFailure.d.ts +10 -2
- package/build/api/loginFailure.js +33 -2
- package/build/api/signedResource.d.ts +49 -2
- package/build/api/signedResource.js +135 -36
- package/build/auth/RegistrationFlowKey.js +1 -1
- package/build/auth/daaRegistrationNative.d.ts +0 -22
- package/build/auth/daaRegistrationNative.js +3 -29
- package/build/auth/deviceAuthorization.d.ts +17 -3
- package/build/auth/deviceAuthorization.js +60 -8
- package/build/auth/registrationAuthorization.d.ts +2 -2
- package/build/auth/registrationAuthorization.js +13 -10
- package/build/config.d.ts +27 -0
- package/build/config.js +15 -0
- package/build/crypto/matchingCode.d.ts +47 -0
- package/build/crypto/matchingCode.js +93 -0
- package/build/errors.d.ts +150 -33
- package/build/errors.js +208 -47
- package/build/index.d.ts +11 -3
- package/build/models/ContractExecution.d.ts +197 -0
- package/build/models/ContractExecution.js +130 -0
- package/build/models/CreateContractExecutionRequest.d.ts +81 -0
- package/build/models/CreateContractExecutionRequest.js +19 -0
- package/build/models/DaaUserContext.d.ts +53 -3
- package/build/models/DaaUserContext.js +33 -2
- package/build/models/DeviceStatus.d.ts +69 -0
- package/build/models/DeviceStatus.js +19 -0
- package/build/models/PendingDeviceApproval.d.ts +121 -0
- package/build/models/PendingDeviceApproval.js +208 -0
- package/build/models/PendingDeviceRegistration.d.ts +162 -23
- package/build/models/PendingDeviceRegistration.js +525 -69
- package/build/models/PreparedContractExecution.d.ts +70 -0
- package/build/models/PreparedContractExecution.js +77 -0
- package/build/models/PreparedSocialLogin.d.ts +19 -26
- package/build/models/PreparedSocialLogin.js +32 -15
- package/build/models/Transaction.d.ts +48 -2
- package/build/models/Transaction.js +52 -4
- package/build/models/codeSecrets.d.ts +100 -0
- package/build/models/codeSecrets.js +321 -0
- package/build/securekey/InMemorySecureKey.d.ts +3 -1
- package/build/securekey/InMemorySecureKey.js +47 -6
- package/build/securekey/NativeSecureKey.d.ts +3 -1
- package/build/securekey/NativeSecureKey.js +204 -27
- package/build/securekey/NativeSecureKeyBridge.d.ts +72 -4
- package/build/securekey/SecureKey.d.ts +128 -8
- package/build/securekey/alias.d.ts +9 -0
- package/build/securekey/alias.js +11 -2
- package/build/securekey/ownerAuthKeyResolver.d.ts +26 -9
- package/build/securekey/ownerAuthKeyResolver.js +35 -20
- package/build/securekey/registration.d.ts +19 -0
- package/build/securekey/registration.js +38 -0
- package/build/securekey/resolveNativeBridge.d.ts +3 -0
- package/build/securekey/resolveNativeBridge.js +88 -7
- package/build/transport/headers.d.ts +11 -0
- package/build/transport/headers.js +36 -0
- package/build/wire/contractExecutionPayload.d.ts +24 -0
- package/build/wire/contractExecutionPayload.js +130 -0
- package/build/wire/daaStatusCodes.d.ts +20 -3
- package/build/wire/daaStatusCodes.js +20 -3
- package/build/wire/deviceContextPayload.d.ts +9 -7
- package/build/wire/deviceContextPayload.js +9 -7
- package/build/wire/deviceRegistrationResultPayload.d.ts +55 -10
- package/build/wire/deviceRegistrationResultPayload.js +116 -82
- package/build/wire/deviceStatusPayload.d.ts +20 -0
- package/build/wire/deviceStatusPayload.js +66 -0
- package/build/wire/instant.js +4 -1
- package/build/wire/pendingRegistrationPayload.d.ts +16 -0
- package/build/wire/pendingRegistrationPayload.js +18 -0
- package/build/wire/socialLoginRequestPayload.d.ts +0 -5
- package/build/wire/socialLoginRequestPayload.js +2 -19
- package/build/wire/transactionPayload.d.ts +2 -2
- package/build/wire/transactionPayload.js +27 -4
- package/ios/DaaRegistrationModule.swift +1 -19
- package/ios/DaaSecureKeyExceptions.swift +53 -5
- package/ios/DaaSecureKeyModule.swift +149 -5
- package/ios/InstallationIdentityStore.swift +43 -7
- package/package.json +1 -1
- package/src/DaaClient.ts +353 -15
- package/src/api/AccountsClient.ts +3 -0
- package/src/api/AuthClient.ts +33 -98
- package/src/api/ContractExecutionsClient.ts +527 -0
- package/src/api/DaaUserClient.ts +92 -17
- package/src/api/TransactionsClient.ts +1 -0
- package/src/api/TransfersClient.ts +3 -0
- package/src/api/WithdrawalsClient.ts +3 -0
- package/src/api/deviceApproval.ts +306 -0
- package/src/api/deviceStatus.ts +238 -0
- package/src/api/loginFailure.ts +39 -2
- package/src/api/signedResource.ts +206 -46
- package/src/auth/RegistrationFlowKey.ts +1 -1
- package/src/auth/daaRegistrationNative.ts +4 -49
- package/src/auth/deviceAuthorization.ts +74 -11
- package/src/auth/registrationAuthorization.ts +12 -9
- package/src/config.ts +36 -0
- package/src/crypto/matchingCode.ts +100 -0
- package/src/errors.ts +309 -52
- package/src/index.ts +36 -1
- package/src/models/ContractExecution.ts +250 -0
- package/src/models/CreateContractExecutionRequest.ts +100 -0
- package/src/models/DaaUserContext.ts +59 -3
- package/src/models/DeviceStatus.ts +50 -0
- package/src/models/PendingDeviceApproval.ts +229 -0
- package/src/models/PendingDeviceRegistration.ts +673 -79
- package/src/models/PreparedContractExecution.ts +128 -0
- package/src/models/PreparedSocialLogin.ts +41 -31
- package/src/models/Transaction.ts +77 -2
- package/src/models/codeSecrets.ts +360 -0
- package/src/securekey/InMemorySecureKey.ts +61 -7
- package/src/securekey/NativeSecureKey.ts +234 -25
- package/src/securekey/NativeSecureKeyBridge.ts +84 -4
- package/src/securekey/SecureKey.ts +138 -8
- package/src/securekey/alias.ts +11 -3
- package/src/securekey/ownerAuthKeyResolver.ts +63 -24
- package/src/securekey/registration.ts +40 -0
- package/src/securekey/resolveNativeBridge.ts +167 -9
- package/src/transport/headers.ts +47 -0
- package/src/wire/contractExecutionPayload.ts +152 -0
- package/src/wire/daaStatusCodes.ts +20 -3
- package/src/wire/deviceContextPayload.ts +9 -7
- package/src/wire/deviceRegistrationResultPayload.ts +156 -98
- package/src/wire/deviceStatusPayload.ts +68 -0
- package/src/wire/instant.ts +4 -1
- package/src/wire/pendingRegistrationPayload.ts +44 -1
- package/src/wire/socialLoginRequestPayload.ts +2 -25
- package/src/wire/transactionPayload.ts +40 -4
- package/build/auth/prepareReceipt.d.ts +0 -150
- package/build/auth/prepareReceipt.js +0 -357
- package/build/crypto/es256Jws.d.ts +0 -56
- package/build/crypto/es256Jws.js +0 -196
- package/src/auth/prepareReceipt.ts +0 -522
- package/src/crypto/es256Jws.ts +0 -240
|
@@ -0,0 +1,208 @@
|
|
|
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 _PendingDeviceApproval_thumbprint, _PendingDeviceApproval_codeNonce, _PendingDeviceApproval_codeSecret, _PendingDeviceApproval_authKeyThumbprint, _PendingDeviceApproval_authKey, _PendingDeviceApproval_transport;
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
exports.PendingDeviceApproval = void 0;
|
|
33
|
+
exports.newPendingDeviceApproval = newPendingDeviceApproval;
|
|
34
|
+
const deviceStatus_1 = require("../api/deviceStatus");
|
|
35
|
+
const base64url_1 = require("../crypto/base64url");
|
|
36
|
+
const matchingCode_1 = require("../crypto/matchingCode");
|
|
37
|
+
const serialization_1 = require("../crypto/serialization");
|
|
38
|
+
const errors_1 = require("../errors");
|
|
39
|
+
const headers_1 = require("../transport/headers");
|
|
40
|
+
const uuid_1 = require("../validation/uuid");
|
|
41
|
+
const errorEnvelope_1 = require("../wire/errorEnvelope");
|
|
42
|
+
const codeSecrets_1 = require("./codeSecrets");
|
|
43
|
+
const APPROVAL_TOKEN = Symbol('daa.pendingDeviceApproval');
|
|
44
|
+
/**
|
|
45
|
+
* A new device's registration on an account that already has a device: DAA
|
|
46
|
+
* added this AuthKey as waiting for approval, and an existing device must
|
|
47
|
+
* approve it before it can sign.
|
|
48
|
+
*
|
|
49
|
+
* The app calls {@link sendCodeSecret}, which is what makes DAA tell the
|
|
50
|
+
* partner (`account.device.pending` webhook) to prompt the existing device,
|
|
51
|
+
* and shows {@link getMatchingCode} on this device. The user types the code on
|
|
52
|
+
* the existing device, which approves after checking that the typed code is
|
|
53
|
+
* the one this device's code secret produces. The key can't sign anything
|
|
54
|
+
* until then, and DAA cancels the request at `expiresAt`. Follow the request
|
|
55
|
+
* with `DaaClient.watchDeviceStatus({ authKeyId })`.
|
|
56
|
+
*
|
|
57
|
+
* The code secret is kept with the AuthKey (Keychain on iOS, Keystore-encrypted
|
|
58
|
+
* storage on Android) until DAA says no request is waiting for it, or until
|
|
59
|
+
* {@link sendCodeSecret} sends it. It leaves the device only through
|
|
60
|
+
* {@link sendCodeSecret}, for this request only.
|
|
61
|
+
*
|
|
62
|
+
* If the app discards this object, or restarts, signing in again before
|
|
63
|
+
* `expiresAt` returns the same request and the same code. Once
|
|
64
|
+
* {@link sendCodeSecret} has run, the secret is kept in process memory only:
|
|
65
|
+
* after a restart a sign-in before `expiresAt` still returns the same request,
|
|
66
|
+
* but this device no longer holds the secret its seal commits to. DAA returns
|
|
67
|
+
* that seal, so this SDK can tell: {@link getMatchingCode} and
|
|
68
|
+
* {@link sendCodeSecret} then throw `matching_code_unavailable` and nothing is
|
|
69
|
+
* sent. Have the user wait until `expiresAt` and sign in again.
|
|
70
|
+
*
|
|
71
|
+
* Not constructible by a consumer: exported from `index.ts` as a type only.
|
|
72
|
+
*/
|
|
73
|
+
class PendingDeviceApproval {
|
|
74
|
+
/** @internal Constructed only by `PendingDeviceRegistration.complete`. */
|
|
75
|
+
constructor(token, fields) {
|
|
76
|
+
_PendingDeviceApproval_thumbprint.set(this, void 0);
|
|
77
|
+
_PendingDeviceApproval_codeNonce.set(this, void 0);
|
|
78
|
+
/** `null` when DAA's seal for the request isn't this device's. */
|
|
79
|
+
_PendingDeviceApproval_codeSecret.set(this, void 0);
|
|
80
|
+
_PendingDeviceApproval_authKeyThumbprint.set(this, void 0);
|
|
81
|
+
_PendingDeviceApproval_authKey.set(this, void 0);
|
|
82
|
+
_PendingDeviceApproval_transport.set(this, void 0);
|
|
83
|
+
if (token !== APPROVAL_TOKEN) {
|
|
84
|
+
throw (0, errors_1.contractViolation)('PendingDeviceApproval must be constructed by the DAA SDK');
|
|
85
|
+
}
|
|
86
|
+
if (!(0, uuid_1.isUuid)(fields.requestId) || !(0, uuid_1.isUuid)(fields.authKeyId)) {
|
|
87
|
+
throw (0, errors_1.contractViolation)('PendingDeviceApproval ids must be UUIDs');
|
|
88
|
+
}
|
|
89
|
+
this.requestId = fields.requestId;
|
|
90
|
+
this.authKeyId = fields.authKeyId;
|
|
91
|
+
this.expiresAt = fields.expiresAt;
|
|
92
|
+
__classPrivateFieldSet(this, _PendingDeviceApproval_thumbprint, (0, base64url_1.fromBase64Url)(fields.authKeyThumbprint), "f");
|
|
93
|
+
__classPrivateFieldSet(this, _PendingDeviceApproval_codeNonce, (0, base64url_1.fromBase64Url)(fields.codeNonce), "f");
|
|
94
|
+
// Not copied: `markCodeSecretSent` finds the kept secret by reference.
|
|
95
|
+
// Only `PendingDeviceRegistration` passes it, and nothing writes to it.
|
|
96
|
+
__classPrivateFieldSet(this, _PendingDeviceApproval_codeSecret, fields.codeSecret, "f");
|
|
97
|
+
__classPrivateFieldSet(this, _PendingDeviceApproval_authKeyThumbprint, fields.authKeyThumbprint, "f");
|
|
98
|
+
__classPrivateFieldSet(this, _PendingDeviceApproval_authKey, fields.authKey, "f");
|
|
99
|
+
__classPrivateFieldSet(this, _PendingDeviceApproval_transport, fields.transport, "f");
|
|
100
|
+
// Fails here, at registration, rather than later when the app asks for
|
|
101
|
+
// the code: all three inputs must be 32 bytes.
|
|
102
|
+
if (__classPrivateFieldGet(this, _PendingDeviceApproval_codeSecret, "f") !== null) {
|
|
103
|
+
(0, matchingCode_1.matchingCode)(__classPrivateFieldGet(this, _PendingDeviceApproval_thumbprint, "f"), __classPrivateFieldGet(this, _PendingDeviceApproval_codeNonce, "f"), __classPrivateFieldGet(this, _PendingDeviceApproval_codeSecret, "f"));
|
|
104
|
+
}
|
|
105
|
+
Object.freeze(this);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* The six digits to show on this device, such as `"482913"`. Show them with
|
|
109
|
+
* a space in the middle (`482 913`); the approving device ignores spaces and
|
|
110
|
+
* dashes in what the user types. The same value every time.
|
|
111
|
+
*
|
|
112
|
+
* @throws DaaError with `detail.kind === 'matching_code_unavailable'` when
|
|
113
|
+
* DAA's seal for this request isn't one this device holds the secret for
|
|
114
|
+
* (the app restarted after the secret was sent): no code it shows
|
|
115
|
+
* could match. Tell the user to wait until `expiresAt` and sign in again.
|
|
116
|
+
*/
|
|
117
|
+
getMatchingCode() {
|
|
118
|
+
if (__classPrivateFieldGet(this, _PendingDeviceApproval_codeSecret, "f") === null) {
|
|
119
|
+
throw (0, errors_1.matchingCodeUnavailable)();
|
|
120
|
+
}
|
|
121
|
+
return (0, matchingCode_1.matchingCode)(__classPrivateFieldGet(this, _PendingDeviceApproval_thumbprint, "f"), __classPrivateFieldGet(this, _PendingDeviceApproval_codeNonce, "f"), __classPrivateFieldGet(this, _PendingDeviceApproval_codeSecret, "f"));
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Send this device's code secret to DAA for this request:
|
|
125
|
+
* `POST /v1/accounts/auth/devices/{authKeyId}/codeSecret`. DAA checks it
|
|
126
|
+
* against the seal this device signed into its registration, stores it, and
|
|
127
|
+
* sends the `account.device.pending` webhook so the partner can prompt the
|
|
128
|
+
* existing device. Until it is sent, the existing device can't check the
|
|
129
|
+
* code. Call it once the request is `PENDING_APPROVAL`, before or while
|
|
130
|
+
* showing {@link getMatchingCode}.
|
|
131
|
+
*
|
|
132
|
+
* Safe to call again: DAA accepts the same secret for the same request again
|
|
133
|
+
* (`204`) and re-sends the webhook while the request is waiting. That is the
|
|
134
|
+
* retry for a `500` or a transport failure, which may mean the secret was
|
|
135
|
+
* saved but the webhook was not sent.
|
|
136
|
+
*
|
|
137
|
+
* Once sent, this SDK never seals the secret into another request: the
|
|
138
|
+
* key's next registration seals a new one (a registration that timed out
|
|
139
|
+
* before the send may still reach DAA later with it; see `codeSecrets.ts`). If DAA answers that registration with
|
|
140
|
+
* this same request (it was still waiting), the code still comes from this
|
|
141
|
+
* secret. Waits for any registration of this key in flight: if DAA answers it
|
|
142
|
+
* with a different request, or doesn't answer, this request is no longer the
|
|
143
|
+
* one the secret is sealed into, and nothing is sent.
|
|
144
|
+
*
|
|
145
|
+
* @throws DaaError with `detail.kind === 'transport'` (retryable) when the
|
|
146
|
+
* transport throws; `api` for any status but `204`: retryable for `429`
|
|
147
|
+
* and `5xx` (call again), and not retryable for the `409` with
|
|
148
|
+
* `DEVICE_APPROVAL_INVALID` (`420117`), which DAA returns when this is no
|
|
149
|
+
* longer the key's latest request, the request has ended, or the secret
|
|
150
|
+
* doesn't match the seal; `contract_violation` (not retryable, nothing
|
|
151
|
+
* sent) when this SDK already knows the request is not the one the secret
|
|
152
|
+
* is sealed into: a later sign-in of this key returned another request or
|
|
153
|
+
* got no answer, or DAA said no request is waiting for the key. Sign in
|
|
154
|
+
* again for the current request. `matching_code_unavailable` (nothing
|
|
155
|
+
* sent), as for {@link getMatchingCode}: this device doesn't hold the
|
|
156
|
+
* secret DAA's seal for the request commits to. A secure-key error kind
|
|
157
|
+
* (nothing sent, call again) when deleting the secret from the AuthKey's
|
|
158
|
+
* storage failed, or `transport` (retryable, nothing sent) when that
|
|
159
|
+
* delete didn't finish within 5 seconds: it is deleted before the send so
|
|
160
|
+
* it is never sealed into another request, even after a restart.
|
|
161
|
+
*/
|
|
162
|
+
async sendCodeSecret() {
|
|
163
|
+
if (__classPrivateFieldGet(this, _PendingDeviceApproval_codeSecret, "f") === null) {
|
|
164
|
+
throw (0, errors_1.matchingCodeUnavailable)();
|
|
165
|
+
}
|
|
166
|
+
const codeSecret = __classPrivateFieldGet(this, _PendingDeviceApproval_codeSecret, "f");
|
|
167
|
+
const bodyBytes = (0, serialization_1.serializeBody)({
|
|
168
|
+
requestId: this.requestId,
|
|
169
|
+
codeSecret: (0, base64url_1.toBase64Url)(codeSecret),
|
|
170
|
+
});
|
|
171
|
+
// Decided after any registration of this key in flight has its answer,
|
|
172
|
+
// and recorded before sending: a request whose response is lost may still
|
|
173
|
+
// have reached DAA.
|
|
174
|
+
const maySend = await (0, codeSecrets_1.oneAtATime)(__classPrivateFieldGet(this, _PendingDeviceApproval_authKeyThumbprint, "f"), () => (0, codeSecrets_1.markCodeSecretSent)(__classPrivateFieldGet(this, _PendingDeviceApproval_authKeyThumbprint, "f"), codeSecret, this.requestId, __classPrivateFieldGet(this, _PendingDeviceApproval_authKey, "f")));
|
|
175
|
+
if (!maySend) {
|
|
176
|
+
throw (0, errors_1.contractViolation)('this request is no longer the one this code secret is sealed into; ' +
|
|
177
|
+
'use the PendingDeviceApproval from the latest sign-in');
|
|
178
|
+
}
|
|
179
|
+
let response;
|
|
180
|
+
try {
|
|
181
|
+
response = await __classPrivateFieldGet(this, _PendingDeviceApproval_transport, "f").send({
|
|
182
|
+
method: 'POST',
|
|
183
|
+
path: `${deviceStatus_1.DEVICE_PATH_PREFIX}${this.authKeyId}/codeSecret`,
|
|
184
|
+
query: null,
|
|
185
|
+
headers: { 'Content-Type': 'application/json' },
|
|
186
|
+
bodyBytes,
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
catch (err) {
|
|
190
|
+
// A DaaError the consumer's transport threw keeps its own kind and
|
|
191
|
+
// retryability, as in `asTransportFailure`.
|
|
192
|
+
throw (0, errors_1.isDaaError)(err) ? err : (0, errors_1.transportFailure)(err);
|
|
193
|
+
}
|
|
194
|
+
if (response.status !== 204) {
|
|
195
|
+
throw (0, errors_1.apiFailure)({
|
|
196
|
+
httpStatus: response.status,
|
|
197
|
+
daaStatusCode: (0, errorEnvelope_1.readDaaStatusCode)(response.bodyBytes),
|
|
198
|
+
correlationId: (0, headers_1.headerValueIgnoringCase)(response.headers, 'X-Request-Id'),
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
exports.PendingDeviceApproval = PendingDeviceApproval;
|
|
204
|
+
_PendingDeviceApproval_thumbprint = new WeakMap(), _PendingDeviceApproval_codeNonce = new WeakMap(), _PendingDeviceApproval_codeSecret = new WeakMap(), _PendingDeviceApproval_authKeyThumbprint = new WeakMap(), _PendingDeviceApproval_authKey = new WeakMap(), _PendingDeviceApproval_transport = new WeakMap();
|
|
205
|
+
/** @internal */
|
|
206
|
+
function newPendingDeviceApproval(fields) {
|
|
207
|
+
return new PendingDeviceApproval(APPROVAL_TOKEN, fields);
|
|
208
|
+
}
|
|
@@ -18,13 +18,27 @@
|
|
|
18
18
|
import { type RegistrationFlowKey } from '../auth/RegistrationFlowKey';
|
|
19
19
|
import type { OwnerAuthKey } from '../securekey/SecureKey';
|
|
20
20
|
import type { DaaTransport } from '../transport/DaaTransport';
|
|
21
|
+
import type { DeviceApprovalHint } from '../wire/pendingRegistrationPayload';
|
|
21
22
|
import { type DeviceRegistrationResult } from './DaaUserContext';
|
|
23
|
+
/**
|
|
24
|
+
* Optional device signals for this registration, passed unchanged. DAA uses
|
|
25
|
+
* them to show the device's model and OS in the device list. None of the
|
|
26
|
+
* members is required.
|
|
27
|
+
*/
|
|
28
|
+
export type DeviceRegistrationRiskSignals = Readonly<{
|
|
29
|
+
ipAddress?: string;
|
|
30
|
+
sessionId?: string;
|
|
31
|
+
deviceId?: string;
|
|
32
|
+
}>;
|
|
33
|
+
export type { DeviceApprovalHint };
|
|
22
34
|
/**
|
|
23
35
|
* Pending device registration after Social Session.
|
|
24
36
|
*
|
|
25
|
-
* `complete()` is Device Registration Complete:
|
|
26
|
-
* (`
|
|
27
|
-
* `
|
|
37
|
+
* `complete()` is Device Registration Complete: `POST /v1/accounts/auth/keys`
|
|
38
|
+
* with the body (`type: "deviceKey"`, `idempotencyKey`, `registrationHandle`,
|
|
39
|
+
* `registrationCodeVerifier`, `deviceKeyPublicKey`, and `codeSeal` with
|
|
40
|
+
* `addDeviceApproval` on), plus `riskSignals` when the caller passes them,
|
|
41
|
+
* including the registration code verifier minted before
|
|
28
42
|
* Prepare and redeemed here against the challenge Prepare sent. Two JWSs
|
|
29
43
|
* authorize it — `X-Device-Authorization` (signed by the proposed AuthKey) and
|
|
30
44
|
* `X-Registration-Flow-Authorization` (signed by the per-attempt flow key from
|
|
@@ -33,14 +47,29 @@ import { type DeviceRegistrationResult } from './DaaUserContext';
|
|
|
33
47
|
* handle, profile, AuthKey thumbprint, code verifier). Building and signing
|
|
34
48
|
* those proofs is `authorizeRegistrationComplete`.
|
|
35
49
|
*
|
|
36
|
-
* Every device takes this same path, first or additional
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
50
|
+
* Every device takes this same path, first or additional, with the same body
|
|
51
|
+
* and no mode to select. A first device comes back `ACTIVE`. A new device on an
|
|
52
|
+
* Owner that already has an active device comes back `PENDING_APPROVAL`: DAA
|
|
53
|
+
* adds the key as waiting, and an existing device approves it after the user
|
|
54
|
+
* types the matching code this device shows (see `PendingDeviceApproval`).
|
|
55
|
+
* `codeSeal` is what makes that code possible, so it is sent on every
|
|
56
|
+
* registration: the SDK can't know beforehand which outcome DAA will return.
|
|
57
|
+
*
|
|
58
|
+
* With `addDeviceApproval` on, the SDK asks first. When the Session's
|
|
59
|
+
* `deviceApproval.required` says a new device would wait for approval and this
|
|
60
|
+
* device has no AuthKey Circle registered for the end user,
|
|
61
|
+
* `confirmationRequired` is `true` and this sign-in hasn't created a key. Ask
|
|
62
|
+
* the user whether to add this device (`deviceApproval.hasActiveDevice` says
|
|
63
|
+
* whether one of their devices can approve it), and call
|
|
64
|
+
* `complete({ confirmAddDevice: true })` only if they confirm. That creates
|
|
65
|
+
* the key, or reuses the one this device made for an earlier request, and
|
|
66
|
+
* registers it. DAA's answer still decides the outcome: a request already
|
|
67
|
+
* waiting comes back `PENDING_APPROVAL` again, and `ACTIVE` is possible where
|
|
68
|
+
* DAA doesn't add keys as waiting yet.
|
|
41
69
|
*
|
|
42
|
-
* There is no `abandon()
|
|
43
|
-
*
|
|
70
|
+
* There is no `abandon()` here: call `PreparedSocialLogin.abandon()`, which
|
|
71
|
+
* releases the same flow key. If the caller backs out after Session without
|
|
72
|
+
* calling `complete()` or that `abandon()`, the native flow-key cache is held until the process
|
|
44
73
|
* exits; `complete()` releases it in `finally`. The API has no cancel call for
|
|
45
74
|
* a pending registration.
|
|
46
75
|
*
|
|
@@ -56,35 +85,145 @@ export declare class PendingDeviceRegistration {
|
|
|
56
85
|
* and normalises it here, so a consumer never sees the wire's disagreement.
|
|
57
86
|
*/
|
|
58
87
|
readonly expiresAt: string;
|
|
88
|
+
/**
|
|
89
|
+
* The Session's `deviceApproval`: whether a new device key for this end user
|
|
90
|
+
* would wait for approval, as DAA saw it when it answered. A hint for what to
|
|
91
|
+
* tell the user, not the outcome. `null` when DAA didn't send it.
|
|
92
|
+
*/
|
|
93
|
+
readonly deviceApproval: DeviceApprovalHint | null;
|
|
94
|
+
/**
|
|
95
|
+
* `true` when the user must confirm adding this device before `complete()`
|
|
96
|
+
* creates and registers a key: `addDeviceApproval` is on,
|
|
97
|
+
* `deviceApproval.required` is `true`, and this device has no AuthKey Circle
|
|
98
|
+
* registered for the end user. Call `complete({ confirmAddDevice: true })`
|
|
99
|
+
* only after the user confirms, or without asking when the app knows this
|
|
100
|
+
* device's request is still waiting (`DaaClient.getDeviceStatus` on the
|
|
101
|
+
* `authKeyId` it saved says `pending_approval`): a key waiting for approval
|
|
102
|
+
* isn't registered on the device yet, so it reads as no key here. If the
|
|
103
|
+
* user declines, call `abandon()` on the `PreparedSocialLogin` this came
|
|
104
|
+
* from: nothing was created, but its native flow key is otherwise held until
|
|
105
|
+
* the process exits.
|
|
106
|
+
*/
|
|
107
|
+
readonly confirmationRequired: boolean;
|
|
59
108
|
/** @internal Constructed only by `PreparedSocialLogin.completeSocialSession`. */
|
|
60
109
|
constructor(fields: {
|
|
61
110
|
readonly registrationHandle: string;
|
|
62
111
|
readonly clientEntityId: string;
|
|
63
112
|
readonly expiresAt: string;
|
|
113
|
+
readonly deviceApproval: DeviceApprovalHint | null;
|
|
114
|
+
readonly confirmationRequired: boolean;
|
|
64
115
|
readonly transport: DaaTransport;
|
|
65
116
|
readonly registrationCodeVerifier: string;
|
|
66
117
|
readonly registrationFlowKey: RegistrationFlowKey;
|
|
67
|
-
|
|
118
|
+
/** The AuthKey, or `null` to create it in `complete()` after confirmation. */
|
|
119
|
+
readonly authKey: OwnerAuthKey | null;
|
|
120
|
+
readonly resolveAuthKey: () => Promise<OwnerAuthKey>;
|
|
121
|
+
readonly addDeviceApproval: boolean;
|
|
68
122
|
});
|
|
69
123
|
/**
|
|
70
|
-
* Finish the ceremony: `POST /v1/accounts/auth/
|
|
71
|
-
*
|
|
72
|
-
*
|
|
124
|
+
* Finish the ceremony: `POST /v1/accounts/auth/keys` with both
|
|
125
|
+
* `X-Device-Authorization` and `X-Registration-Flow-Authorization` bound to
|
|
126
|
+
* the exact body bytes. Both proofs name `register_device_key` version 3.
|
|
127
|
+
* DAA reads the body strictly and refuses any member outside the set in the
|
|
128
|
+
* class doc.
|
|
129
|
+
*
|
|
130
|
+
* The body is the same fields for every device — see the class doc.
|
|
131
|
+
* `codeSeal` is sent only with `addDeviceApproval` on (off by default). It
|
|
132
|
+
* commits to the AuthKey's 32-byte code secret. The same secret is sealed
|
|
133
|
+
* again until DAA says no request is waiting for this key, because DAA
|
|
134
|
+
* returns a waiting key's request and keeps its first seal; once
|
|
135
|
+
* `sendCodeSecret()` revealed it, the next registration seals a new one (see
|
|
136
|
+
* `codeSecrets.ts`). On `PENDING_APPROVAL` the returned
|
|
137
|
+
* `PendingDeviceApproval` holds the secret that request's seal commits to.
|
|
138
|
+
* DAA returns that seal, and if this SDK doesn't hold its secret (the app
|
|
139
|
+
* restarted after the secret was sent), the `PendingDeviceApproval`
|
|
140
|
+
* reports the code as unavailable (`matching_code_unavailable`) and sends
|
|
141
|
+
* nothing.
|
|
142
|
+
* DAA must run an enclave that accepts `codeSeal` (0.1.93 or later); older
|
|
143
|
+
* enclaves refuse the body. With the switch off, a `pending_approval` answer
|
|
144
|
+
* (a key already waiting from an earlier registration with it on) throws
|
|
145
|
+
* `contract_violation`: there is no secret to show its code from.
|
|
146
|
+
* The only input is the optional `riskSignals`, device signals for this
|
|
147
|
+
* registration. When given, they go into the body both proofs sign, so nothing
|
|
148
|
+
* between the app and DAA can change them. Without them, registration works
|
|
149
|
+
* the same and the device list shows the device without a model or OS.
|
|
150
|
+
*
|
|
151
|
+
* When `confirmationRequired` is `true`, pass `confirmAddDevice: true` once
|
|
152
|
+
* the user confirmed adding this device: only then is the AuthKey created
|
|
153
|
+
* and the registration sent. Without it, `complete()` throws
|
|
154
|
+
* `contract_violation` and nothing is created or sent. When
|
|
155
|
+
* `confirmationRequired` is `false`, `confirmAddDevice` is ignored.
|
|
73
156
|
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
157
|
+
* The input is checked before anything else: a malformed `riskSignals`, a
|
|
158
|
+
* `confirmAddDevice` that is not a boolean, or a missing confirmation throws
|
|
159
|
+
* `contract_violation` and leaves this registration unused, so the caller can
|
|
160
|
+
* call `complete()` again.
|
|
76
161
|
*
|
|
77
|
-
* The service returns a
|
|
78
|
-
* `
|
|
79
|
-
*
|
|
162
|
+
* The service returns a `KeyCredential` (see
|
|
163
|
+
* `wire/deviceRegistrationResultPayload.ts`): `credentialStatus: "active"`
|
|
164
|
+
* is `ACTIVE`, with `credentialId` as `deviceContext.authKeyId`;
|
|
165
|
+
* `pending_approval` is `PENDING_APPROVAL`; and `pending_activation` is
|
|
166
|
+
* `PENDING_ACTIVATION`. This endpoint never returns
|
|
167
|
+
* `RECOVERY_PENDING`. On `PENDING_APPROVAL`, the
|
|
168
|
+
* AuthKey is not acknowledged: it can't sign until an existing device
|
|
169
|
+
* approves it. On `PENDING_ACTIVATION` (approved, in the account's cool-down
|
|
170
|
+
* until `readyAt`) it is acknowledged but no context is returned: after
|
|
171
|
+
* `readyAt`, `DaaClient.restore` returns it. On `ACTIVE`, acknowledges
|
|
172
|
+
* the AuthKey with the context's `authKeyId` and `ownerBindingId`, so later
|
|
173
|
+
* `resolveOrCreate` returns `existing` and `SecureKeyStore.resolveExisting`
|
|
174
|
+
* can find it.
|
|
80
175
|
*
|
|
81
176
|
* @throws DaaError with `detail.kind === 'login_request_expired'` for `410`;
|
|
82
177
|
* `idempotency_conflict` for a `409` with `IDEMPOTENCY_KEY_REUSED`
|
|
83
178
|
* (`420034`); `contract_violation` for `LOGIN_REQUEST_CONSUMED` (`420039`),
|
|
84
|
-
* for a second call
|
|
85
|
-
*
|
|
179
|
+
* for a second call (except the retry after `registration_not_saved`,
|
|
180
|
+
* below), for unusable key material, for a response the SDK cannot read
|
|
181
|
+
* (including a `credentialStatus` other than `active`, `pending_approval`
|
|
182
|
+
* or `pending_activation`), and for malformed `riskSignals` (nothing is
|
|
183
|
+
* sent and this registration stays unused, so `complete()` can be called
|
|
184
|
+
* again), and for a missing `confirmAddDevice: true` when
|
|
185
|
+
* `confirmationRequired` (likewise nothing is sent and this registration
|
|
186
|
+
* stays unused); and `api` for any other status besides the documented
|
|
86
187
|
* `200`, including the `409` that DAA sends with `AUTH_KEY_BINDING_CONFLICT`
|
|
87
|
-
* (`420038`)
|
|
188
|
+
* (`420038`) or `PASSKEY_OWNER_CREDENTIAL_KIND_MISMATCH` (`420080`);
|
|
189
|
+
* `device_registration_limit`, `device_denied`, `device_approval_conflict`
|
|
190
|
+
* or `device_approval_unavailable` for the four add-a-device refusals (see
|
|
191
|
+
* `deviceRegistrationFailure`); `transport` with `retryable: false` when
|
|
192
|
+
* reading the AuthKey, or the queued prompt and `send()`, takes longer than
|
|
193
|
+
* two minutes (a later read or response is ignored; trying again needs a
|
|
194
|
+
* new login, unless DAA had answered and only saving its answer ran
|
|
195
|
+
* late: `complete()` then retries that save, as after
|
|
196
|
+
* `registration_not_saved`. If that late save finished first, the retry
|
|
197
|
+
* throws `contract_violation` ("already been consumed"): the identifiers
|
|
198
|
+
* are saved, and `DaaClient.restore` finds the key).
|
|
199
|
+
* `user_cancelled` when the user dismisses the authentication
|
|
200
|
+
* prompt: nothing was sent, but this registration is used up, so trying
|
|
201
|
+
* again needs a new login (which reuses the same AuthKey).
|
|
202
|
+
* When `confirmationRequired`, the AuthKey is created here, so a native
|
|
203
|
+
* failure creating it (for example `device_lock_not_set` or
|
|
204
|
+
* `device_not_supported`) is thrown here too; nothing was sent, but this
|
|
205
|
+
* registration is used up, so trying again needs a new login.
|
|
206
|
+
* `registration_not_saved` when DAA answered `ACTIVE` or
|
|
207
|
+
* `PENDING_ACTIVATION` but saving its
|
|
208
|
+
* `authKeyId` and `ownerBindingId` on this device failed (for example a
|
|
209
|
+
* Keychain or Keystore write error). The device is registered with Circle.
|
|
210
|
+
* Call `complete()` again: it sends nothing, retries only the save, and
|
|
211
|
+
* on success returns the same result (its input is ignored).
|
|
212
|
+
* The retry has the same two-minute deadline. If a newer registration of
|
|
213
|
+
* the same key answered in the meantime, the retry throws
|
|
214
|
+
* `contract_violation` and saves nothing: the newer registration's
|
|
215
|
+
* identifiers are the ones to keep.
|
|
216
|
+
* If the key on the device was replaced since (`forgetLocalKey`, then a
|
|
217
|
+
* new sign-in), the retry also throws `contract_violation` and saves
|
|
218
|
+
* nothing. If the save fails with `key_invalidated` or
|
|
219
|
+
* `device_not_initialized` (the key is gone), that kind is thrown as is and
|
|
220
|
+
* nothing is kept to retry: no save can succeed. Other native kinds (for
|
|
221
|
+
* example `device_lock_not_set` or `device_not_supported`, which the user
|
|
222
|
+
* can fix or retry) come as `registration_not_saved`, with the original on
|
|
223
|
+
* `cause`.
|
|
88
224
|
*/
|
|
89
|
-
complete(
|
|
225
|
+
complete(input?: {
|
|
226
|
+
readonly riskSignals?: DeviceRegistrationRiskSignals;
|
|
227
|
+
readonly confirmAddDevice?: boolean;
|
|
228
|
+
}): Promise<DeviceRegistrationResult>;
|
|
90
229
|
}
|