@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
package/build/DaaClient.js
CHANGED
|
@@ -27,17 +27,21 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
27
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
28
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
29
29
|
};
|
|
30
|
-
var _DaaClient_config, _DaaClient_publicApiOrigin, _DaaClient_auth, _DaaClient_authKeys;
|
|
30
|
+
var _DaaClient_instances, _DaaClient_config, _DaaClient_publicApiOrigin, _DaaClient_auth, _DaaClient_authKeys, _DaaClient_ownerKeys, _DaaClient_restores, _DaaClient_restoreOnce, _DaaClient_confirmRegistration;
|
|
31
31
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
32
|
exports.DaaClient = void 0;
|
|
33
33
|
const AuthClient_1 = require("./api/AuthClient");
|
|
34
|
+
const deviceStatus_1 = require("./api/deviceStatus");
|
|
34
35
|
const DaaUserClient_1 = require("./api/DaaUserClient");
|
|
36
|
+
const signedResource_1 = require("./api/signedResource");
|
|
35
37
|
const config_1 = require("./config");
|
|
36
38
|
const errors_1 = require("./errors");
|
|
37
39
|
const DaaUserContext_1 = require("./models/DaaUserContext");
|
|
38
40
|
const ownerAuthKeyResolver_1 = require("./securekey/ownerAuthKeyResolver");
|
|
39
41
|
const alias_1 = require("./securekey/alias");
|
|
40
42
|
const resolveNativeBridge_1 = require("./securekey/resolveNativeBridge");
|
|
43
|
+
const deviceContextPayload_1 = require("./wire/deviceContextPayload");
|
|
44
|
+
const NO_LOCAL_KEY = Object.freeze({ status: 'no_local_key' });
|
|
41
45
|
/**
|
|
42
46
|
* Root DAA client.
|
|
43
47
|
*
|
|
@@ -48,6 +52,7 @@ const resolveNativeBridge_1 = require("./securekey/resolveNativeBridge");
|
|
|
48
52
|
*/
|
|
49
53
|
class DaaClient {
|
|
50
54
|
constructor(config) {
|
|
55
|
+
_DaaClient_instances.add(this);
|
|
51
56
|
_DaaClient_config.set(this, void 0);
|
|
52
57
|
/** The validated `publicApiOrigin`, or `undefined` for the environment's origin. */
|
|
53
58
|
_DaaClient_publicApiOrigin.set(this, void 0);
|
|
@@ -65,6 +70,17 @@ class DaaClient {
|
|
|
65
70
|
* from nowhere else.
|
|
66
71
|
*/
|
|
67
72
|
_DaaClient_authKeys.set(this, void 0);
|
|
73
|
+
/**
|
|
74
|
+
* The same store as {@link #authKeys}, with the read-only and forget
|
|
75
|
+
* operations session restore needs. `#`-private for the same reason.
|
|
76
|
+
*/
|
|
77
|
+
_DaaClient_ownerKeys.set(this, void 0);
|
|
78
|
+
/**
|
|
79
|
+
* One in-flight restore per `clientEntityId`. Concurrent callers share the
|
|
80
|
+
* promise — one user-authentication prompt, one signed request — and the
|
|
81
|
+
* entry is removed once it settles, so a later call starts afresh.
|
|
82
|
+
*/
|
|
83
|
+
_DaaClient_restores.set(this, new Map());
|
|
68
84
|
if (!config.appId) {
|
|
69
85
|
throw new Error('DAA: appId is required');
|
|
70
86
|
}
|
|
@@ -81,6 +97,7 @@ class DaaClient {
|
|
|
81
97
|
(0, alias_1.assertAppId)(config.appId);
|
|
82
98
|
const publicApiOrigin = (0, config_1.assertPublicApiOrigin)(config.environment, config.publicApiOrigin);
|
|
83
99
|
const keyPolicy = (0, config_1.assertDeviceKeyPolicy)(config.keyPolicy);
|
|
100
|
+
const addDeviceApproval = (0, config_1.assertAddDeviceApproval)(config.addDeviceApproval);
|
|
84
101
|
// When DaaSecureKey is present, fail closed if it declares a weaker policy
|
|
85
102
|
// than the configured closed set. Absent (Node / Jest) is not a pass —
|
|
86
103
|
// resolveNativeBridge() still checks on first AuthKey use.
|
|
@@ -90,16 +107,17 @@ class DaaClient {
|
|
|
90
107
|
// Built eagerly, but it resolves nothing until something asks: the Expo
|
|
91
108
|
// DaaSecureKey module is reached on first resolution, so constructing a
|
|
92
109
|
// DaaClient still does not require it.
|
|
93
|
-
__classPrivateFieldSet(this,
|
|
110
|
+
__classPrivateFieldSet(this, _DaaClient_ownerKeys, (0, ownerAuthKeyResolver_1.createAppOwnerKeys)({ appId: config.appId, environment: config.environment }, null), "f");
|
|
111
|
+
__classPrivateFieldSet(this, _DaaClient_authKeys, __classPrivateFieldGet(this, _DaaClient_ownerKeys, "f").resolveOrCreate, "f");
|
|
94
112
|
// Constructed eagerly. Prepare needs no AuthKey and no DaaSecureKey. The
|
|
95
|
-
// Expo DaaRegistration module (CSPRNG, flow key
|
|
96
|
-
//
|
|
97
|
-
//
|
|
98
|
-
//
|
|
113
|
+
// Expo DaaRegistration module (CSPRNG, flow key) is resolved on first
|
|
114
|
+
// prepare, not here — matching randomBytes / randomUuidV4. A host missing
|
|
115
|
+
// that module fails closed at login. Jest injects a fake. AuthKey selection
|
|
116
|
+
// is lazy on Social Session.
|
|
99
117
|
__classPrivateFieldSet(this, _DaaClient_auth, new AuthClient_1.AuthClient({
|
|
100
118
|
transport: config.transport,
|
|
101
|
-
|
|
102
|
-
|
|
119
|
+
ownerKeys: __classPrivateFieldGet(this, _DaaClient_ownerKeys, "f"),
|
|
120
|
+
addDeviceApproval,
|
|
103
121
|
}), "f");
|
|
104
122
|
}
|
|
105
123
|
get appId() {
|
|
@@ -121,9 +139,12 @@ class DaaClient {
|
|
|
121
139
|
/**
|
|
122
140
|
* The authenticated operations surface for one user.
|
|
123
141
|
*
|
|
124
|
-
* Opens only for an `ACTIVE` `DaaUserContext`
|
|
125
|
-
*
|
|
126
|
-
*
|
|
142
|
+
* Opens only for an `ACTIVE` `DaaUserContext` this SDK minted: one decoded
|
|
143
|
+
* from Device Registration Complete, or one returned by {@link restore} after
|
|
144
|
+
* the service confirmed the stored registration. Both are bound to the local
|
|
145
|
+
* AuthKey's thumbprint, which every signed operation re-checks. A fabricated
|
|
146
|
+
* object, a `RECOVERY_PENDING` result, or a missing context fail closed —
|
|
147
|
+
* they are not an Owner-bound credential.
|
|
127
148
|
*
|
|
128
149
|
* The context is carried into the surface rather than only checked at the
|
|
129
150
|
* door. `deviceContext.authKeyId` is the `kid` every signed write's
|
|
@@ -151,8 +172,271 @@ class DaaClient {
|
|
|
151
172
|
return authKey;
|
|
152
173
|
},
|
|
153
174
|
authKeyId: context.deviceContext.authKeyId,
|
|
175
|
+
clientEntityId,
|
|
154
176
|
}, __classPrivateFieldGet(this, _DaaClient_publicApiOrigin, "f"));
|
|
155
177
|
}
|
|
178
|
+
/**
|
|
179
|
+
* Restore a signed-in user after an app restart with the AuthKey this device
|
|
180
|
+
* already registered, instead of a new social login.
|
|
181
|
+
*
|
|
182
|
+
* `clientEntityId` is the value the app stored, keyed by its own user id,
|
|
183
|
+
* when that user last completed login (`DaaUserContext.clientEntityId`). It
|
|
184
|
+
* only selects which local key to look for; it grants nothing by itself — see
|
|
185
|
+
* the `OwnerKeyIdentity` note in `securekey/SecureKey.ts`.
|
|
186
|
+
*
|
|
187
|
+
* Steps:
|
|
188
|
+
*
|
|
189
|
+
* 1. Look up the registered AuthKey and the `authKeyId` recorded when Circle
|
|
190
|
+
* registered it. This never creates a key and never prompts. None found
|
|
191
|
+
* resolves `{ status: 'no_local_key' }`.
|
|
192
|
+
* 2. Sign `GET /v1/accounts/auth/context` (`get_device_context`) with that
|
|
193
|
+
* key, `kid` = the stored `authKeyId`. This is the one user-authentication
|
|
194
|
+
* prompt (biometrics or device credential).
|
|
195
|
+
* 3. Require the returned `authKeyId` and `ownerBindingId` to equal the
|
|
196
|
+
* stored ones, then return an `ACTIVE` context bound to the key, for
|
|
197
|
+
* {@link forUser}.
|
|
198
|
+
*
|
|
199
|
+
* Call it while the app is in the foreground: iOS cannot show the
|
|
200
|
+
* authentication prompt during a background launch.
|
|
201
|
+
*
|
|
202
|
+
* Concurrent calls for the same `clientEntityId` share one restore.
|
|
203
|
+
*
|
|
204
|
+
* On failure this deletes nothing and starts no login. An application must
|
|
205
|
+
* not do either automatically: keep the key, report the error, and let the
|
|
206
|
+
* user decide (retry, or sign in again). A throw is never "no key" — that is
|
|
207
|
+
* only ever the `no_local_key` result. In particular a native failure while
|
|
208
|
+
* reading the key (for example its local protection metadata is
|
|
209
|
+
* unreadable) throws through the usual native error mapping; it is not
|
|
210
|
+
* turned into `no_local_key`, so it must not start enrollment either.
|
|
211
|
+
*
|
|
212
|
+
* `clientEntityId` must be the lowercase UUID exactly as
|
|
213
|
+
* `DaaUserContext.clientEntityId` returned it. The key slot is derived from
|
|
214
|
+
* those exact characters, so an uppercase copy (for example after a round
|
|
215
|
+
* trip through Swift's `UUID.uuidString`) would find no key; it is rejected
|
|
216
|
+
* instead of being reported as `no_local_key`.
|
|
217
|
+
*
|
|
218
|
+
* @throws DaaError with `detail.kind === 'contract_violation'` for a
|
|
219
|
+
* `clientEntityId` that is not a lowercase UUID, for a returned `authKeyId`
|
|
220
|
+
* or `ownerBindingId` that does not match the stored one, for a key
|
|
221
|
+
* forgotten while the restore was reading it, for a response the SDK
|
|
222
|
+
* cannot read, and when the service rejects the device
|
|
223
|
+
* authorization (the credential is no longer accepted — the same mapping
|
|
224
|
+
* as every signed write; on a revoked or unknown AuthKey the service
|
|
225
|
+
* answers `403` with DAA status `420036`). The application's response is
|
|
226
|
+
* the same for all of them: keep the key and offer sign-in. One exception:
|
|
227
|
+
* on iOS a prompt the system or the app interrupted also arrives as
|
|
228
|
+
* `contract_violation` today, so retry `restore` in the foreground first
|
|
229
|
+
* if the app left it during the prompt (see the README);
|
|
230
|
+
* `user_cancelled` when the user dismisses the authentication prompt:
|
|
231
|
+
* nothing was sent and the key is untouched, so calling `restore` again
|
|
232
|
+
* prompts again; `local_user_authentication_required` when user
|
|
233
|
+
* authentication failed or is unavailable; `clock_skew` when the service
|
|
234
|
+
* rejected the authorization because the device clock is off, the same as
|
|
235
|
+
* `refreshContext`; `api` for any other status besides `200`; `transport` if
|
|
236
|
+
* the consumer's transport throws, with the thrown value as `err.cause`.
|
|
237
|
+
*/
|
|
238
|
+
async restore(args) {
|
|
239
|
+
const clientEntityId = requireClientEntityId(args);
|
|
240
|
+
let inFlight = __classPrivateFieldGet(this, _DaaClient_restores, "f").get(clientEntityId);
|
|
241
|
+
if (inFlight === undefined) {
|
|
242
|
+
inFlight = __classPrivateFieldGet(this, _DaaClient_instances, "m", _DaaClient_restoreOnce).call(this, clientEntityId).finally(() => {
|
|
243
|
+
__classPrivateFieldGet(this, _DaaClient_restores, "f").delete(clientEntityId);
|
|
244
|
+
});
|
|
245
|
+
__classPrivateFieldGet(this, _DaaClient_restores, "f").set(clientEntityId, inFlight);
|
|
246
|
+
}
|
|
247
|
+
return inFlight;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Delete this device's AuthKey for `clientEntityId`, and its local
|
|
251
|
+
* registration record.
|
|
252
|
+
*
|
|
253
|
+
* Call it only on an explicit user action, such as "remove this device",
|
|
254
|
+
* confirming the removal of a key Circle has revoked, or confirming that the
|
|
255
|
+
* user starts over after this new device was declined (status `denied` from
|
|
256
|
+
* {@link getDeviceStatus}, or a registration refused with `device_denied`) —
|
|
257
|
+
* never as an
|
|
258
|
+
* automatic reaction to a failed {@link restore}, a rejected write, or any
|
|
259
|
+
* other status or error. The SDK never deletes the key by itself.
|
|
260
|
+
*
|
|
261
|
+
* It is local only and does NOT revoke the key with Circle, which keeps the
|
|
262
|
+
* registered public key. It cannot be undone: the next login on this device registers a new
|
|
263
|
+
* AuthKey. Succeeds when no key exists.
|
|
264
|
+
*
|
|
265
|
+
* Contexts and `DaaUserClient`s already handed out are not invalidated by
|
|
266
|
+
* this call. Operations that need a new signature fail once the key is gone,
|
|
267
|
+
* but an authorization signed before the delete stays valid, because Circle
|
|
268
|
+
* still accepts the key: a contract execution prepared earlier can still be
|
|
269
|
+
* sent with `contractExecutions.submit`. Close those clients and drop any
|
|
270
|
+
* prepared value you do not intend to send as part of the same action.
|
|
271
|
+
*
|
|
272
|
+
* Do not call it while a login or a {@link restore} for the same
|
|
273
|
+
* `clientEntityId` is still in flight; finish or abandon that first. A
|
|
274
|
+
* restore that is reading the key when the delete starts fails closed with
|
|
275
|
+
* `contract_violation`. A login ceremony that already holds the key is not
|
|
276
|
+
* cancelled: whether its key survives depends on the order the native SDK
|
|
277
|
+
* runs the two calls in, so the outcome is not defined.
|
|
278
|
+
*
|
|
279
|
+
* @throws DaaError with `detail.kind === 'contract_violation'` for a
|
|
280
|
+
* `clientEntityId` that is not a lowercase UUID, and for a native failure
|
|
281
|
+
* that has no more specific mapping. Native failures go through the same
|
|
282
|
+
* mapping as every other AuthKey operation, so the delete can also report
|
|
283
|
+
* `local_user_authentication_required` or `device_not_initialized` if the
|
|
284
|
+
* platform raises one of those.
|
|
285
|
+
*/
|
|
286
|
+
async forgetLocalKey(args) {
|
|
287
|
+
const clientEntityId = requireClientEntityId(args);
|
|
288
|
+
await __classPrivateFieldGet(this, _DaaClient_ownerKeys, "f").forget(clientEntityId);
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* The add-a-device status of this device's new AuthKey:
|
|
292
|
+
* `GET /v1/accounts/auth/devices/{authKeyId}`, with the `authKeyId` DAA
|
|
293
|
+
* returned when it added the key as waiting. One read, for example when the app is reopened
|
|
294
|
+
* while a request was waiting (the app must have saved `authKeyId`); use
|
|
295
|
+
* {@link watchDeviceStatus} to wait for the outcome.
|
|
296
|
+
*
|
|
297
|
+
* `denied` means the user declined this device on another one. The key
|
|
298
|
+
* can't ask again: after the user confirms, the app may delete it with
|
|
299
|
+
* {@link forgetLocalKey} and sign in again with a new key. The SDK never
|
|
300
|
+
* deletes it by itself.
|
|
301
|
+
*
|
|
302
|
+
* `authKeyId` may be in either case.
|
|
303
|
+
*
|
|
304
|
+
* @throws DaaError with `detail.kind === 'contract_violation'` for an
|
|
305
|
+
* `authKeyId` that is not a UUID string and for a response the SDK cannot read;
|
|
306
|
+
* `transport` (retryable) when the transport throws; `api` for any status
|
|
307
|
+
* but `200`, including `404` when DAA doesn't know the key.
|
|
308
|
+
*/
|
|
309
|
+
async getDeviceStatus(args) {
|
|
310
|
+
return await (0, deviceStatus_1.readDeviceStatus)(withTransportFailure(__classPrivateFieldGet(this, _DaaClient_config, "f").transport), requireAuthKeyId(args));
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Wait for the add-a-device outcome: read {@link getDeviceStatus} until it is
|
|
314
|
+
* no longer `pending_approval` or `pending_activation` (so `active`,
|
|
315
|
+
* `denied`, `expired`, `cancelled`, or `unrecognized`), and resolve with it.
|
|
316
|
+
*
|
|
317
|
+
* Reads every 5 s while `pending_approval`, and during the cool-down
|
|
318
|
+
* (`pending_activation`) at `readyAt` or every 30 s, whichever is sooner.
|
|
319
|
+
* DAA reports `expired` once `expiresAt` passes on its clock, so this
|
|
320
|
+
* device's clock never ends the watch. After a retryable failure the wait
|
|
321
|
+
* doubles, up to 30 s, with a random part so that watches that failed
|
|
322
|
+
* together don't retry together. `onStatus` gets the first status and every
|
|
323
|
+
* change; if it throws, the watch rejects with that error. Aborting `signal`
|
|
324
|
+
* stops the watch at once, even during a read, and rejects with the
|
|
325
|
+
* signal's reason; a late response is ignored.
|
|
326
|
+
*
|
|
327
|
+
* Every call runs its own loop. Run one watch per `authKeyId` and abort it
|
|
328
|
+
* when the screen that started it goes away: each extra watch is another
|
|
329
|
+
* read every 5 s against the partner's rate limit for this route.
|
|
330
|
+
*
|
|
331
|
+
* @throws the same errors as {@link getDeviceStatus}, and
|
|
332
|
+
* `contract_violation` for an `onStatus` that is not a function or a
|
|
333
|
+
* `signal` that is not an `AbortSignal`, before anything is sent.
|
|
334
|
+
* Ones marked `retryable` (`transport`, or `api` with `429`/`5xx`) are
|
|
335
|
+
* retried, and the watch rejects with the last one after 10 in a row; any
|
|
336
|
+
* other, such as a transport's own `DaaError` with `retryable: false`,
|
|
337
|
+
* rejects at once.
|
|
338
|
+
*/
|
|
339
|
+
async watchDeviceStatus(args) {
|
|
340
|
+
return await (0, deviceStatus_1.watchDeviceStatus)(withTransportFailure(__classPrivateFieldGet(this, _DaaClient_config, "f").transport), requireWatchArgs(args));
|
|
341
|
+
}
|
|
156
342
|
}
|
|
157
343
|
exports.DaaClient = DaaClient;
|
|
158
|
-
_DaaClient_config = new WeakMap(), _DaaClient_publicApiOrigin = new WeakMap(), _DaaClient_auth = new WeakMap(), _DaaClient_authKeys = new WeakMap()
|
|
344
|
+
_DaaClient_config = new WeakMap(), _DaaClient_publicApiOrigin = new WeakMap(), _DaaClient_auth = new WeakMap(), _DaaClient_authKeys = new WeakMap(), _DaaClient_ownerKeys = new WeakMap(), _DaaClient_restores = new WeakMap(), _DaaClient_instances = new WeakSet(), _DaaClient_restoreOnce = async function _DaaClient_restoreOnce(clientEntityId) {
|
|
345
|
+
const registered = await __classPrivateFieldGet(this, _DaaClient_ownerKeys, "f").resolveExisting(clientEntityId);
|
|
346
|
+
if (registered === null) {
|
|
347
|
+
return NO_LOCAL_KEY;
|
|
348
|
+
}
|
|
349
|
+
// Read before any prompt: the thumbprint comes from the public key.
|
|
350
|
+
const authKeyThumbprint = await registered.authKey.thumbprint();
|
|
351
|
+
const deviceContext = await __classPrivateFieldGet(this, _DaaClient_instances, "m", _DaaClient_confirmRegistration).call(this, registered);
|
|
352
|
+
return Object.freeze({
|
|
353
|
+
status: 'ACTIVE',
|
|
354
|
+
context: (0, DaaUserContext_1.restoreDaaUserContext)(clientEntityId, deviceContext, authKeyThumbprint),
|
|
355
|
+
});
|
|
356
|
+
}, _DaaClient_confirmRegistration =
|
|
357
|
+
/**
|
|
358
|
+
* Ask the service for the device context with a registered-device
|
|
359
|
+
* authorization signed by the stored key, through the same
|
|
360
|
+
* `getSignedResource` path as `DaaUserClient.refreshContext`, and require
|
|
361
|
+
* that it names the same `authKeyId` and `ownerBindingId` that were stored
|
|
362
|
+
* when the key was acknowledged.
|
|
363
|
+
*
|
|
364
|
+
* A different `ownerBindingId` fails closed rather than being adopted: the
|
|
365
|
+
* stored record and the service disagree about which Owner binding this key
|
|
366
|
+
* belongs to, and the SDK has no basis to pick one. Re-registration through
|
|
367
|
+
* login is the path that legitimately records new identifiers.
|
|
368
|
+
*/
|
|
369
|
+
async function _DaaClient_confirmRegistration(registered) {
|
|
370
|
+
const deviceContext = await (0, signedResource_1.getSignedResource)({
|
|
371
|
+
transport: withTransportFailure(__classPrivateFieldGet(this, _DaaClient_config, "f").transport),
|
|
372
|
+
operation: 'get_device_context',
|
|
373
|
+
authKey: registered.authKey,
|
|
374
|
+
authKeyId: registered.authKeyId,
|
|
375
|
+
expectedStatus: 200,
|
|
376
|
+
decode: deviceContextPayload_1.toDeviceContext,
|
|
377
|
+
});
|
|
378
|
+
if (deviceContext.authKeyId !== registered.authKeyId) {
|
|
379
|
+
throw (0, errors_1.contractViolation)('the restored device context names a different AuthKey');
|
|
380
|
+
}
|
|
381
|
+
if (deviceContext.ownerBindingId !== registered.ownerBindingId) {
|
|
382
|
+
throw (0, errors_1.contractViolation)('the restored device context names a different Owner binding');
|
|
383
|
+
}
|
|
384
|
+
return deviceContext;
|
|
385
|
+
};
|
|
386
|
+
function requireClientEntityId(args) {
|
|
387
|
+
const clientEntityId = (0, config_1.isRecord)(args) ? args['clientEntityId'] : undefined;
|
|
388
|
+
if (typeof clientEntityId !== 'string') {
|
|
389
|
+
throw (0, errors_1.contractViolation)('clientEntityId must be a UUID');
|
|
390
|
+
}
|
|
391
|
+
// The same rule enrollment applies when it derives the key alias (lowercase
|
|
392
|
+
// UUID), checked up front so a bad value never reaches the key store.
|
|
393
|
+
(0, alias_1.assertClientEntityId)(clientEntityId);
|
|
394
|
+
return clientEntityId;
|
|
395
|
+
}
|
|
396
|
+
/** The `authKeyId` of a status call; the UUID check itself is `readDeviceStatus`'s. */
|
|
397
|
+
function requireAuthKeyId(args) {
|
|
398
|
+
const authKeyId = (0, config_1.isRecord)(args) ? args['authKeyId'] : undefined;
|
|
399
|
+
if (typeof authKeyId !== 'string') {
|
|
400
|
+
throw (0, errors_1.contractViolation)('authKeyId must be a UUID');
|
|
401
|
+
}
|
|
402
|
+
return authKeyId;
|
|
403
|
+
}
|
|
404
|
+
/** `watchDeviceStatus`'s arguments, checked before the first read. */
|
|
405
|
+
function requireWatchArgs(args) {
|
|
406
|
+
const authKeyId = requireAuthKeyId(args);
|
|
407
|
+
const { onStatus, signal } = args;
|
|
408
|
+
if (onStatus !== undefined && typeof onStatus !== 'function') {
|
|
409
|
+
throw (0, errors_1.contractViolation)('onStatus must be a function');
|
|
410
|
+
}
|
|
411
|
+
// Everything the watch uses, so a partial object fails here, before the
|
|
412
|
+
// first read, not in a cleanup that would leave the watch never settling.
|
|
413
|
+
if (signal !== undefined &&
|
|
414
|
+
!((0, config_1.isRecord)(signal) &&
|
|
415
|
+
typeof signal['aborted'] === 'boolean' &&
|
|
416
|
+
typeof signal['addEventListener'] === 'function' &&
|
|
417
|
+
typeof signal['removeEventListener'] === 'function')) {
|
|
418
|
+
throw (0, errors_1.contractViolation)('signal must be an AbortSignal');
|
|
419
|
+
}
|
|
420
|
+
return {
|
|
421
|
+
authKeyId,
|
|
422
|
+
...(onStatus === undefined ? {} : { onStatus: onStatus }),
|
|
423
|
+
...(signal === undefined ? {} : { signal: signal }),
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* The consumer's transport, with a throw reported as the spec's `transport`
|
|
428
|
+
* error through the same `asTransportFailure` every `DaaUserClient` operation
|
|
429
|
+
* uses.
|
|
430
|
+
*/
|
|
431
|
+
function withTransportFailure(transport) {
|
|
432
|
+
return Object.freeze({
|
|
433
|
+
send: async (request) => {
|
|
434
|
+
try {
|
|
435
|
+
return await transport.send(request);
|
|
436
|
+
}
|
|
437
|
+
catch (err) {
|
|
438
|
+
throw (0, DaaUserClient_1.asTransportFailure)(err, request);
|
|
439
|
+
}
|
|
440
|
+
},
|
|
441
|
+
});
|
|
442
|
+
}
|
|
@@ -86,6 +86,9 @@ export declare class AccountsClient {
|
|
|
86
86
|
* sent — for a rejected or replayed authorization (including a key that is
|
|
87
87
|
* no longer active: DAA has no revoked-credential code, so this never
|
|
88
88
|
* throws `device_revoked`), and for a response the SDK cannot read;
|
|
89
|
+
* `clock_skew` when DAA refused the authorization because the device clock
|
|
90
|
+
* was more than 60 seconds off: correct the device time, then send the same
|
|
91
|
+
* request again;
|
|
89
92
|
* `detail.kind === 'api'` for a status other than the documented `201`; and
|
|
90
93
|
* `detail.kind === 'transport'` if the consumer's transport throws, with the
|
|
91
94
|
* thrown value as `err.cause` and the request's `idempotencyKey` on the
|
|
@@ -161,6 +161,9 @@ class AccountsClient {
|
|
|
161
161
|
* sent — for a rejected or replayed authorization (including a key that is
|
|
162
162
|
* no longer active: DAA has no revoked-credential code, so this never
|
|
163
163
|
* throws `device_revoked`), and for a response the SDK cannot read;
|
|
164
|
+
* `clock_skew` when DAA refused the authorization because the device clock
|
|
165
|
+
* was more than 60 seconds off: correct the device time, then send the same
|
|
166
|
+
* request again;
|
|
164
167
|
* `detail.kind === 'api'` for a status other than the documented `201`; and
|
|
165
168
|
* `detail.kind === 'transport'` if the consumer's transport throws, with the
|
|
166
169
|
* thrown value as `err.cause` and the request's `idempotencyKey` on the
|
|
@@ -15,11 +15,9 @@
|
|
|
15
15
|
* See the License for the specific language governing permissions and
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/
|
|
18
|
-
import { type PrepareReceiptTrustAnchor } from '../auth/prepareReceipt';
|
|
19
18
|
import { type RegistrationFlowKeyProvider } from '../auth/RegistrationFlowKey';
|
|
20
|
-
import type { DaaEnvironment } from '../config';
|
|
21
19
|
import { PreparedSocialLogin } from '../models/PreparedSocialLogin';
|
|
22
|
-
import { type
|
|
20
|
+
import { type AppOwnerKeys } from '../securekey/ownerAuthKeyResolver';
|
|
23
21
|
import type { AppKeyIdentity, SecureKeyStore } from '../securekey/SecureKey';
|
|
24
22
|
import type { DaaTransport } from '../transport/DaaTransport';
|
|
25
23
|
/**
|
|
@@ -32,8 +30,7 @@ import type { DaaTransport } from '../transport/DaaTransport';
|
|
|
32
30
|
*
|
|
33
31
|
* Prepare does not touch an AuthKey. AuthKey selection happens only after
|
|
34
32
|
* the Social Session response, via the injected store (tests) or the native
|
|
35
|
-
* store (production).
|
|
36
|
-
* it returns anything to the application — see `prepareSocialLogin`.
|
|
33
|
+
* store (production).
|
|
37
34
|
*
|
|
38
35
|
* Not constructible by a consumer: exported from `index.ts` as a type only, and
|
|
39
36
|
* the `#transport` field makes the type nominal.
|
|
@@ -64,25 +61,15 @@ export declare class AuthClient {
|
|
|
64
61
|
*/
|
|
65
62
|
identity?: AppKeyIdentity;
|
|
66
63
|
/**
|
|
67
|
-
* The
|
|
68
|
-
* one store and one in-flight `resolveOrCreate` map
|
|
69
|
-
* Unset, this client builds its own from
|
|
70
|
-
* what a test constructing `AuthClient`
|
|
71
|
-
* second holder to share with.
|
|
64
|
+
* The key operations `DaaClient` shares between login, `forUser` and
|
|
65
|
+
* `restore`, so all reach one store and one in-flight `resolveOrCreate` map
|
|
66
|
+
* for this identity. Unset, this client builds its own from
|
|
67
|
+
* `identity`/`secureKeys` — which is what a test constructing `AuthClient`
|
|
68
|
+
* directly wants, since it has no second holder to share with.
|
|
72
69
|
*/
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
|
|
76
|
-
* anchor and is the value the receipt's `environment` claim must name.
|
|
77
|
-
* Falls back to `identity.environment`.
|
|
78
|
-
*/
|
|
79
|
-
environment?: DaaEnvironment;
|
|
80
|
-
/**
|
|
81
|
-
* Test-only override of the pinned receipt trust anchor. Not reachable from
|
|
82
|
-
* `DaaSdkConfiguration`: a consumer cannot choose the key that vouches for
|
|
83
|
-
* its own relay's responses.
|
|
84
|
-
*/
|
|
85
|
-
prepareReceiptTrustAnchor?: PrepareReceiptTrustAnchor | null;
|
|
70
|
+
ownerKeys?: AppOwnerKeys;
|
|
71
|
+
/** `DaaSdkConfiguration.addDeviceApproval`; off when unset. */
|
|
72
|
+
addDeviceApproval?: boolean;
|
|
86
73
|
});
|
|
87
74
|
/**
|
|
88
75
|
* Start one social-login attempt.
|
|
@@ -93,25 +80,13 @@ export declare class AuthClient {
|
|
|
93
80
|
* bytes. Durable persistence across a restart is not implemented — see
|
|
94
81
|
* `models/PreparedSocialLogin.ts`.
|
|
95
82
|
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
* `
|
|
103
|
-
* `auth/prepareReceipt.ts`.
|
|
104
|
-
*
|
|
105
|
-
* @throws DaaError with `detail.kind === 'prepare_receipt_invalid'` when an
|
|
106
|
-
* anchor is pinned and the receipt is missing, malformed, fails its
|
|
107
|
-
* signature or claim checks, has expired, or the platform verifier is
|
|
108
|
-
* missing or fails; `contract_violation` for a rejected provider, unusable
|
|
109
|
-
* local key material, a missing native DaaRegistration module, or a
|
|
110
|
-
* response the SDK cannot read;
|
|
111
|
-
* `login_request_expired` for `410`; `idempotency_conflict` for a `409`
|
|
112
|
-
* with `IDEMPOTENCY_KEY_REUSED` (`420034`); `contract_violation` with the
|
|
113
|
-
* correlation id for `LOGIN_REQUEST_CONSUMED` (`420039`); and `api` for any
|
|
114
|
-
* other status besides the documented `201`, including any other `409`.
|
|
83
|
+
* @throws DaaError with `detail.kind === 'contract_violation'` for a rejected
|
|
84
|
+
* provider, unusable local key material, a missing native DaaRegistration
|
|
85
|
+
* module, a response the SDK cannot read, and (with the correlation id)
|
|
86
|
+
* `LOGIN_REQUEST_CONSUMED` (`420039`); `login_request_expired` for `410`;
|
|
87
|
+
* `idempotency_conflict` for a `409` with `IDEMPOTENCY_KEY_REUSED`
|
|
88
|
+
* (`420034`); and `api` for any other status besides the documented `201`,
|
|
89
|
+
* including any other `409`.
|
|
115
90
|
* Whatever the consumer's transport throws is rethrown unchanged.
|
|
116
91
|
*/
|
|
117
92
|
prepareSocialLogin(input: {
|
package/build/api/AuthClient.js
CHANGED
|
@@ -27,20 +27,16 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
27
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
28
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
29
29
|
};
|
|
30
|
-
var _AuthClient_instances, _AuthClient_transport, _AuthClient_registrationFlowKeys,
|
|
30
|
+
var _AuthClient_instances, _AuthClient_transport, _AuthClient_registrationFlowKeys, _AuthClient_ownerKeys, _AuthClient_addDeviceApproval, _AuthClient_resolveAuthKey, _AuthClient_hasRegisteredAuthKey;
|
|
31
31
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
32
|
exports.AuthClient = void 0;
|
|
33
33
|
const registrationCodeVerifier_1 = require("../auth/registrationCodeVerifier");
|
|
34
|
-
const prepareReceipt_1 = require("../auth/prepareReceipt");
|
|
35
34
|
const RegistrationFlowKey_1 = require("../auth/RegistrationFlowKey");
|
|
36
|
-
const base64url_1 = require("../crypto/base64url");
|
|
37
|
-
const jwkThumbprint_1 = require("../crypto/jwkThumbprint");
|
|
38
35
|
const random_1 = require("../crypto/random");
|
|
39
36
|
const serialization_1 = require("../crypto/serialization");
|
|
40
37
|
const errors_1 = require("../errors");
|
|
41
38
|
const PreparedSocialLogin_1 = require("../models/PreparedSocialLogin");
|
|
42
39
|
const ownerAuthKeyResolver_1 = require("../securekey/ownerAuthKeyResolver");
|
|
43
|
-
const headers_1 = require("../transport/headers");
|
|
44
40
|
const socialLoginRequestPayload_1 = require("../wire/socialLoginRequestPayload");
|
|
45
41
|
const loginFailure_1 = require("./loginFailure");
|
|
46
42
|
const resourceRequest_1 = require("./resourceRequest");
|
|
@@ -78,8 +74,7 @@ const CODE_CHALLENGE = /^[A-Za-z0-9_-]{43}$/;
|
|
|
78
74
|
*
|
|
79
75
|
* Prepare does not touch an AuthKey. AuthKey selection happens only after
|
|
80
76
|
* the Social Session response, via the injected store (tests) or the native
|
|
81
|
-
* store (production).
|
|
82
|
-
* it returns anything to the application — see `prepareSocialLogin`.
|
|
77
|
+
* store (production).
|
|
83
78
|
*
|
|
84
79
|
* Not constructible by a consumer: exported from `index.ts` as a type only, and
|
|
85
80
|
* the `#transport` field makes the type nominal.
|
|
@@ -90,18 +85,12 @@ class AuthClient {
|
|
|
90
85
|
_AuthClient_instances.add(this);
|
|
91
86
|
_AuthClient_transport.set(this, void 0);
|
|
92
87
|
_AuthClient_registrationFlowKeys.set(this, void 0);
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
_AuthClient_prepareReceiptTrustAnchor.set(this, void 0);
|
|
88
|
+
_AuthClient_ownerKeys.set(this, void 0);
|
|
89
|
+
_AuthClient_addDeviceApproval.set(this, void 0);
|
|
96
90
|
__classPrivateFieldSet(this, _AuthClient_transport, args.transport, "f");
|
|
97
91
|
__classPrivateFieldSet(this, _AuthClient_registrationFlowKeys, args.registrationFlowKeys ?? (0, RegistrationFlowKey_1.defaultRegistrationFlowKeyProvider)(), "f");
|
|
98
|
-
__classPrivateFieldSet(this,
|
|
99
|
-
__classPrivateFieldSet(this,
|
|
100
|
-
__classPrivateFieldSet(this, _AuthClient_prepareReceiptTrustAnchor, args.prepareReceiptTrustAnchor !== undefined
|
|
101
|
-
? args.prepareReceiptTrustAnchor
|
|
102
|
-
: __classPrivateFieldGet(this, _AuthClient_environment, "f") === null
|
|
103
|
-
? null
|
|
104
|
-
: (0, prepareReceipt_1.pinnedPrepareReceiptTrustAnchor)(__classPrivateFieldGet(this, _AuthClient_environment, "f")), "f");
|
|
92
|
+
__classPrivateFieldSet(this, _AuthClient_ownerKeys, args.ownerKeys ?? (0, ownerAuthKeyResolver_1.createAppOwnerKeys)(args.identity ?? null, args.secureKeys ?? null), "f");
|
|
93
|
+
__classPrivateFieldSet(this, _AuthClient_addDeviceApproval, args.addDeviceApproval ?? false, "f");
|
|
105
94
|
Object.freeze(this);
|
|
106
95
|
}
|
|
107
96
|
/**
|
|
@@ -113,25 +102,13 @@ class AuthClient {
|
|
|
113
102
|
* bytes. Durable persistence across a restart is not implemented — see
|
|
114
103
|
* `models/PreparedSocialLogin.ts`.
|
|
115
104
|
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
* `
|
|
123
|
-
* `auth/prepareReceipt.ts`.
|
|
124
|
-
*
|
|
125
|
-
* @throws DaaError with `detail.kind === 'prepare_receipt_invalid'` when an
|
|
126
|
-
* anchor is pinned and the receipt is missing, malformed, fails its
|
|
127
|
-
* signature or claim checks, has expired, or the platform verifier is
|
|
128
|
-
* missing or fails; `contract_violation` for a rejected provider, unusable
|
|
129
|
-
* local key material, a missing native DaaRegistration module, or a
|
|
130
|
-
* response the SDK cannot read;
|
|
131
|
-
* `login_request_expired` for `410`; `idempotency_conflict` for a `409`
|
|
132
|
-
* with `IDEMPOTENCY_KEY_REUSED` (`420034`); `contract_violation` with the
|
|
133
|
-
* correlation id for `LOGIN_REQUEST_CONSUMED` (`420039`); and `api` for any
|
|
134
|
-
* other status besides the documented `201`, including any other `409`.
|
|
105
|
+
* @throws DaaError with `detail.kind === 'contract_violation'` for a rejected
|
|
106
|
+
* provider, unusable local key material, a missing native DaaRegistration
|
|
107
|
+
* module, a response the SDK cannot read, and (with the correlation id)
|
|
108
|
+
* `LOGIN_REQUEST_CONSUMED` (`420039`); `login_request_expired` for `410`;
|
|
109
|
+
* `idempotency_conflict` for a `409` with `IDEMPOTENCY_KEY_REUSED`
|
|
110
|
+
* (`420034`); and `api` for any other status besides the documented `201`,
|
|
111
|
+
* including any other `409`.
|
|
135
112
|
* Whatever the consumer's transport throws is rethrown unchanged.
|
|
136
113
|
*/
|
|
137
114
|
async prepareSocialLogin(input) {
|
|
@@ -184,35 +161,18 @@ class AuthClient {
|
|
|
184
161
|
expectedStatus: 201,
|
|
185
162
|
decode: socialLoginRequestPayload_1.toSocialLoginRequest,
|
|
186
163
|
});
|
|
187
|
-
const verifiedReceipt = await (0, prepareReceipt_1.checkPrepareReceipt)(prepared.prepareReceiptJws, __classPrivateFieldGet(this, _AuthClient_prepareReceiptTrustAnchor, "f"), () => ({
|
|
188
|
-
loginRequestId: prepared.loginRequestId,
|
|
189
|
-
nonce: prepared.oidcNonce,
|
|
190
|
-
provider,
|
|
191
|
-
environment: __classPrivateFieldGet(this, _AuthClient_instances, "m", _AuthClient_requireEnvironmentForReceipt).call(this),
|
|
192
|
-
// The SDK's own values, generated before Prepare was sent: the two a
|
|
193
|
-
// relay substituting another attempt cannot make match.
|
|
194
|
-
registrationCodeChallenge,
|
|
195
|
-
registrationFlowKeyThumbprint: (0, jwkThumbprint_1.p256JwkThumbprint)((0, base64url_1.fromBase64Url)(registrationFlowPublicKey)),
|
|
196
|
-
})).catch((err) => {
|
|
197
|
-
// A rejected receipt came from this response, so it names the
|
|
198
|
-
// response's request id. A `contract_violation` from the check is this
|
|
199
|
-
// SDK's own configuration fault and is left as it is.
|
|
200
|
-
throw (0, errors_1.isDaaError)(err) && err.detail.kind === 'prepare_receipt_invalid'
|
|
201
|
-
? (0, errors_1.withRequestId)(err, (0, headers_1.headerValueIgnoringCase)(response.headers, 'X-Request-Id'))
|
|
202
|
-
: err;
|
|
203
|
-
});
|
|
204
164
|
return new PreparedSocialLogin_1.PreparedSocialLogin({
|
|
205
165
|
loginRequestId: prepared.loginRequestId,
|
|
206
166
|
oidcNonce: prepared.oidcNonce,
|
|
207
167
|
oidcState: prepared.oidcState,
|
|
208
|
-
// Only a receipt that verified; an ignored one is not handed on.
|
|
209
|
-
prepareReceiptJws: verifiedReceipt === null ? null : verifiedReceipt.compactJws,
|
|
210
168
|
expiresAt: prepared.expiresAt,
|
|
211
169
|
registrationCodeVerifier,
|
|
212
170
|
registrationFlowKey,
|
|
213
171
|
idempotencyKey,
|
|
214
172
|
transport: __classPrivateFieldGet(this, _AuthClient_transport, "f"),
|
|
215
173
|
resolveAuthKey: (clientEntityId) => __classPrivateFieldGet(this, _AuthClient_instances, "m", _AuthClient_resolveAuthKey).call(this, clientEntityId),
|
|
174
|
+
hasRegisteredAuthKey: (clientEntityId) => __classPrivateFieldGet(this, _AuthClient_instances, "m", _AuthClient_hasRegisteredAuthKey).call(this, clientEntityId),
|
|
175
|
+
addDeviceApproval: __classPrivateFieldGet(this, _AuthClient_addDeviceApproval, "f"),
|
|
216
176
|
});
|
|
217
177
|
}
|
|
218
178
|
catch (error) {
|
|
@@ -225,7 +185,7 @@ class AuthClient {
|
|
|
225
185
|
}
|
|
226
186
|
}
|
|
227
187
|
exports.AuthClient = AuthClient;
|
|
228
|
-
_AuthClient_transport = new WeakMap(), _AuthClient_registrationFlowKeys = new WeakMap(),
|
|
188
|
+
_AuthClient_transport = new WeakMap(), _AuthClient_registrationFlowKeys = new WeakMap(), _AuthClient_ownerKeys = new WeakMap(), _AuthClient_addDeviceApproval = new WeakMap(), _AuthClient_instances = new WeakSet(), _AuthClient_resolveAuthKey =
|
|
229
189
|
/**
|
|
230
190
|
* Select or create the installation AuthKey only after Social Session.
|
|
231
191
|
* Prepare never calls this.
|
|
@@ -245,12 +205,16 @@ _AuthClient_transport = new WeakMap(), _AuthClient_registrationFlowKeys = new We
|
|
|
245
205
|
* `DaaClient` owns, not through this client.
|
|
246
206
|
*/
|
|
247
207
|
async function _AuthClient_resolveAuthKey(clientEntityId) {
|
|
248
|
-
return __classPrivateFieldGet(this,
|
|
249
|
-
},
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
208
|
+
return __classPrivateFieldGet(this, _AuthClient_ownerKeys, "f").resolveOrCreate(clientEntityId);
|
|
209
|
+
}, _AuthClient_hasRegisteredAuthKey =
|
|
210
|
+
/**
|
|
211
|
+
* Whether this device holds an AuthKey Circle registered for
|
|
212
|
+
* `clientEntityId`. Read-only: it never creates a key and never prompts.
|
|
213
|
+
* Answers a boolean, not the key, for the same reason as
|
|
214
|
+
* {@link #resolveAuthKey}.
|
|
215
|
+
*/
|
|
216
|
+
async function _AuthClient_hasRegisteredAuthKey(clientEntityId) {
|
|
217
|
+
return (await __classPrivateFieldGet(this, _AuthClient_ownerKeys, "f").resolveExisting(clientEntityId)) !== null;
|
|
254
218
|
};
|
|
255
219
|
function newIdempotencyKey() {
|
|
256
220
|
return (0, random_1.randomUuidV4)();
|