@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/src/errors.ts
CHANGED
|
@@ -23,20 +23,64 @@
|
|
|
23
23
|
// `device_revoked` and `owner_binding_invalid` are reserved: DAA returns no
|
|
24
24
|
// code that produces them, so the SDK never throws them. They stay in the type
|
|
25
25
|
// so that a later DAA code does not change the public type.
|
|
26
|
+
//
|
|
27
|
+
// `clock_skew` is a local classification, not a DAA code. It is not a
|
|
28
|
+
// credential problem and not a reason for an application to fall back to social
|
|
29
|
+
// login or delete its AuthKey: see `clockSkew` below.
|
|
30
|
+
//
|
|
31
|
+
// `user_cancelled` is a local classification, not a DAA code. It is not a
|
|
32
|
+
// credential problem: an application keeps its AuthKey and does not start a
|
|
33
|
+
// login on its own. See `userCancelled` below.
|
|
34
|
+
//
|
|
35
|
+
// The four `device_*` registration kinds are DAA codes that Device Registration
|
|
36
|
+
// Complete returns when a new device joins an account that already has one.
|
|
37
|
+
// Each is a different state with a different next step for the app, so each
|
|
38
|
+
// gets its own kind rather than `api`. See `deviceRegistrationFailure` below.
|
|
39
|
+
//
|
|
40
|
+
// `registration_not_saved` is a local classification, not a DAA code: DAA
|
|
41
|
+
// registered the device, and only saving that on this device failed. See
|
|
42
|
+
// `registrationNotSaved` below.
|
|
43
|
+
//
|
|
44
|
+
// `matching_code_unavailable` is a local classification, not a DAA code: see
|
|
45
|
+
// `matchingCodeUnavailable` below.
|
|
46
|
+
//
|
|
47
|
+
// The four kinds `DaaUserClient.approveDevice` adds are for the device that
|
|
48
|
+
// approves a new one. `matching_code_mismatch` and `device_approval_not_ready`
|
|
49
|
+
// are local classifications; `device_approval_invalid` and
|
|
50
|
+
// `device_approval_busy` are DAA codes. See `deviceApprovalFailure` below.
|
|
51
|
+
//
|
|
52
|
+
// `device_pending` is DAA's `DEVICE_PENDING` on a signed request: the signing
|
|
53
|
+
// key is approved but in its cool-down, or still waiting for approval. See
|
|
54
|
+
// `devicePending` below.
|
|
26
55
|
|
|
27
56
|
export type DaaSdkError =
|
|
28
57
|
| { kind: 'transport'; retryable: boolean; idempotencyKey?: string }
|
|
29
58
|
| { kind: 'api'; httpStatus: number; daaStatusCode?: string | number; retryable: boolean }
|
|
30
59
|
| { kind: 'local_user_authentication_required' }
|
|
60
|
+
| { kind: 'device_lock_not_set' }
|
|
61
|
+
| { kind: 'device_not_supported' }
|
|
62
|
+
| { kind: 'key_invalidated' }
|
|
31
63
|
| { kind: 'login_request_expired' }
|
|
32
64
|
| { kind: 'owner_grant_invalid' }
|
|
33
65
|
| { kind: 'owner_grant_expired' }
|
|
34
|
-
| { kind: 'prepare_receipt_invalid' }
|
|
35
66
|
| { kind: 'owner_binding_invalid' }
|
|
36
67
|
| { kind: 'device_not_initialized' }
|
|
37
68
|
| { kind: 'device_revoked' }
|
|
38
69
|
| { kind: 'idempotency_conflict'; idempotencyKey: string; correlationId?: string }
|
|
39
70
|
| { kind: 'contract_violation'; correlationId?: string }
|
|
71
|
+
| { kind: 'clock_skew'; correlationId?: string }
|
|
72
|
+
| { kind: 'user_cancelled' }
|
|
73
|
+
| { kind: 'device_registration_limit'; retryAfterSeconds?: number; correlationId?: string }
|
|
74
|
+
| { kind: 'device_denied'; correlationId?: string }
|
|
75
|
+
| { kind: 'device_approval_conflict'; correlationId?: string }
|
|
76
|
+
| { kind: 'device_approval_unavailable'; correlationId?: string }
|
|
77
|
+
| { kind: 'registration_not_saved' }
|
|
78
|
+
| { kind: 'matching_code_unavailable' }
|
|
79
|
+
| { kind: 'matching_code_mismatch' }
|
|
80
|
+
| { kind: 'device_approval_not_ready' }
|
|
81
|
+
| { kind: 'device_approval_invalid'; correlationId?: string }
|
|
82
|
+
| { kind: 'device_approval_busy'; correlationId?: string }
|
|
83
|
+
| { kind: 'device_pending'; correlationId?: string }
|
|
40
84
|
|
|
41
85
|
/**
|
|
42
86
|
* An Error carrying a structured `DaaSdkError`. The SDK throws this so callers
|
|
@@ -208,54 +252,6 @@ export function loginRequestExpired(correlationId: string | null): DaaError {
|
|
|
208
252
|
)
|
|
209
253
|
}
|
|
210
254
|
|
|
211
|
-
/**
|
|
212
|
-
* The Prepare receipt could not be verified: it is missing where one is
|
|
213
|
-
* required, malformed, signed by no pinned key, bound to values other than this
|
|
214
|
-
* attempt's, outside its validity window, or the platform verifier is missing
|
|
215
|
-
* or failed.
|
|
216
|
-
*
|
|
217
|
-
* On the login path this is raised only when a trust anchor is pinned for the
|
|
218
|
-
* environment: the SDK then verifies the receipt and fails closed on any
|
|
219
|
-
* mismatch, and nothing from that Prepare response reaches the application.
|
|
220
|
-
* With no anchor pinned, the receipt is ignored. Not retryable in place: the
|
|
221
|
-
* caller's recovery is a new `prepareSocialLogin`, which sends a fresh
|
|
222
|
-
* challenge and flow key. A failure that persists across fresh attempts points
|
|
223
|
-
* at the relay or at trust material that does not match the service's signer,
|
|
224
|
-
* not at the user.
|
|
225
|
-
*
|
|
226
|
-
* The receipt is unverified server-supplied text and never goes into the
|
|
227
|
-
* message; `message` here is one of the SDK's own literals.
|
|
228
|
-
*/
|
|
229
|
-
export function prepareReceiptInvalid(message: string, cause: unknown = undefined): DaaError {
|
|
230
|
-
return new DaaError({ kind: 'prepare_receipt_invalid' }, `DAA: ${message}`, cause)
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* The same error with the response's `X-Request-Id` named in its message.
|
|
235
|
-
*
|
|
236
|
-
* For a check that runs on a decoded response without seeing the response
|
|
237
|
-
* itself — the Prepare receipt's verification has many throw sites and none of
|
|
238
|
-
* them holds the headers — so the caller that does hold the response adds the
|
|
239
|
-
* id once. The detail, the cause, and the stack of the check that threw are
|
|
240
|
-
* unchanged.
|
|
241
|
-
*/
|
|
242
|
-
export function withRequestId(err: DaaError, correlationId: string | null): DaaError {
|
|
243
|
-
if (correlationId === null) {
|
|
244
|
-
return err
|
|
245
|
-
}
|
|
246
|
-
const correlated = new DaaError(
|
|
247
|
-
err.detail,
|
|
248
|
-
`${err.message}${requestIdSuffix(correlationId)}`,
|
|
249
|
-
err.cause,
|
|
250
|
-
)
|
|
251
|
-
if (err.stack !== undefined) {
|
|
252
|
-
// Keep the frame that names which receipt check failed, with the new message.
|
|
253
|
-
// A function replacer, so a `$` in the server's id is not a replace pattern.
|
|
254
|
-
correlated.stack = err.stack.replace(err.message, () => correlated.message)
|
|
255
|
-
}
|
|
256
|
-
return correlated
|
|
257
|
-
}
|
|
258
|
-
|
|
259
255
|
/**
|
|
260
256
|
* An idempotency key was reused with different request bytes: a `409` with
|
|
261
257
|
* `IDEMPOTENCY_KEY_REUSED` (`420034`). Another `409` is not this error.
|
|
@@ -282,6 +278,230 @@ export function idempotencyConflict(
|
|
|
282
278
|
)
|
|
283
279
|
}
|
|
284
280
|
|
|
281
|
+
/**
|
|
282
|
+
* DAA refused a registered-device authorization as invalid
|
|
283
|
+
* (`DEVICE_AUTHORIZATION_INVALID`), and the authorization's own `iat`/`exp`
|
|
284
|
+
* fail DAA's 60-second freshness rule against the response's HTTP `Date`.
|
|
285
|
+
*
|
|
286
|
+
* The device clock was wrong when the authorization was signed, so the
|
|
287
|
+
* recovery is to correct the device time and send a newly signed request — not
|
|
288
|
+
* to treat the AuthKey as rejected. A prepared contract execution cannot be
|
|
289
|
+
* re-signed: `submit` resends the authorization made at `prepare`, so correcting
|
|
290
|
+
* the clock does not help it; prepare a new execution instead, as for an expired
|
|
291
|
+
* authorization (see `ContractExecutionsClient.submit`). `Date` is not signed,
|
|
292
|
+
* so it is used only to choose this classification; its value is not carried on
|
|
293
|
+
* the error.
|
|
294
|
+
*/
|
|
295
|
+
export function clockSkew(correlationId: string | null): DaaError {
|
|
296
|
+
const detail: DaaSdkError =
|
|
297
|
+
correlationId === null ? { kind: 'clock_skew' } : { kind: 'clock_skew', correlationId }
|
|
298
|
+
const suffix = correlationId === null ? '' : ` (requestId=${messageSafe(correlationId)})`
|
|
299
|
+
return new DaaError(
|
|
300
|
+
detail,
|
|
301
|
+
`DAA: the device authorization was rejected and the device clock differs from the service clock${suffix}`,
|
|
302
|
+
)
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* The user dismissed the device's user-authentication prompt (biometrics or
|
|
307
|
+
* device credential) for an AuthKey operation.
|
|
308
|
+
*
|
|
309
|
+
* Deliberate user intent, not a credential problem: the AuthKey is untouched
|
|
310
|
+
* and nothing was sent. The caller keeps the key and lets the user try again
|
|
311
|
+
* when they choose. For a signed request, that means sending it again. For
|
|
312
|
+
* Device Registration Complete the pending registration is used up, so trying
|
|
313
|
+
* again means a new login started by the user. That login reuses the same
|
|
314
|
+
* AuthKey.
|
|
315
|
+
*/
|
|
316
|
+
export function userCancelled(cause: unknown = undefined): DaaError {
|
|
317
|
+
return new DaaError({ kind: 'user_cancelled' }, 'DAA: the user cancelled authentication', cause)
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* DAA refused a signed request because the signing key can't sign yet
|
|
322
|
+
* (`DEVICE_PENDING`, `420118`, `409`): it was approved from another device and
|
|
323
|
+
* is in the account's cool-down until its `readyAt`, or it is still waiting
|
|
324
|
+
* for approval. `restore`, `refreshContext` and every signed write report it.
|
|
325
|
+
* Nothing changed on DAA and the key stays valid: keep it, wait (follow
|
|
326
|
+
* `watchDeviceStatus` until `active`), then call `restore` again. Never
|
|
327
|
+
* `forgetLocalKey` or start a new login for it.
|
|
328
|
+
*/
|
|
329
|
+
export function devicePending(correlationId: string | null = null): DaaError {
|
|
330
|
+
return new DaaError(
|
|
331
|
+
correlationId === null ? { kind: 'device_pending' } : { kind: 'device_pending', correlationId },
|
|
332
|
+
`DAA: this device can't sign yet; wait until it is active${requestIdSuffix(correlationId)}`,
|
|
333
|
+
)
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* This device can't show the matching code for its add-a-device request: DAA
|
|
338
|
+
* returned the request with a `codeSeal` that this device's code secret
|
|
339
|
+
* doesn't open. The request was sealed with a secret this SDK no longer holds
|
|
340
|
+
* (the app restarted while it was waiting, or a registration that timed out
|
|
341
|
+
* reached DAA late). A code shown now could never match, so
|
|
342
|
+
* `PendingDeviceApproval.getMatchingCode()` and `sendCodeSecret()` throw this
|
|
343
|
+
* instead, and nothing is sent. Tell the user to wait until the request's
|
|
344
|
+
* `expiresAt` and sign in again: that opens a new request this device can show
|
|
345
|
+
* the code for.
|
|
346
|
+
*/
|
|
347
|
+
export function matchingCodeUnavailable(): DaaError {
|
|
348
|
+
return new DaaError(
|
|
349
|
+
{ kind: 'matching_code_unavailable' },
|
|
350
|
+
"DAA: this device can't show the matching code for this request; sign in again after it expires",
|
|
351
|
+
)
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Device Registration Complete succeeded, and DAA has this device's AuthKey
|
|
356
|
+
* `ACTIVE` (or `PENDING_ACTIVATION`), but saving the `authKeyId` and
|
|
357
|
+
* `ownerBindingId` it returned on this device failed (for example a Keychain or
|
|
358
|
+
* Keystore write error). Until they are saved, session restore can't find the key, and a new login with it fails with
|
|
359
|
+
* DAA's `AUTH_KEY_BINDING_CONFLICT`. Call `complete()` on the same
|
|
360
|
+
* `PendingDeviceRegistration` again: it sends nothing and retries only the save.
|
|
361
|
+
* The native error is on `cause`, never in the message. A save that fails
|
|
362
|
+
* because the key is gone (`key_invalidated`, `device_not_initialized`) throws
|
|
363
|
+
* that kind instead: retrying could never succeed.
|
|
364
|
+
*/
|
|
365
|
+
export function registrationNotSaved(cause: unknown): DaaError {
|
|
366
|
+
return new DaaError(
|
|
367
|
+
{ kind: 'registration_not_saved' },
|
|
368
|
+
'DAA: the device is registered, but saving its registration on this device failed; call complete() again',
|
|
369
|
+
cause,
|
|
370
|
+
)
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* The add-a-device states Device Registration Complete can refuse with, by the
|
|
375
|
+
* DAA code it sends. What the app does next differs for each:
|
|
376
|
+
*
|
|
377
|
+
* - `device_registration_limit` (`DEVICE_REGISTRATION_LIMIT`, `420109`, `429`):
|
|
378
|
+
* the account had 5 add-a-device requests in the last 10 minutes. Wait
|
|
379
|
+
* `retryAfterSeconds` (from `Retry-After`, when the response has a whole
|
|
380
|
+
* number of seconds there) and sign in again.
|
|
381
|
+
* - `device_denied` (`DEVICE_DENIED`, `420111`, `403`): the user declined this
|
|
382
|
+
* key with Not me on another device, so this key can't ask again.
|
|
383
|
+
* - `device_approval_conflict` (`DEVICE_APPROVAL_CONFLICT`, `420112`, `409`):
|
|
384
|
+
* another new device was already waiting, so DAA cancelled both requests.
|
|
385
|
+
* Both devices must sign in again.
|
|
386
|
+
* - `device_approval_unavailable` (`DEVICE_APPROVAL_UNAVAILABLE`, `420113`,
|
|
387
|
+
* `409`): the account has no active device that could approve this one. If a
|
|
388
|
+
* device is in its cool-down, signing in again after it ends works;
|
|
389
|
+
* otherwise the user must recover the account.
|
|
390
|
+
*
|
|
391
|
+
* In every case this `PendingDeviceRegistration` is used up: trying again
|
|
392
|
+
* needs a new login.
|
|
393
|
+
* `correlationId`, the response's `X-Request-Id`, goes on the detail and in
|
|
394
|
+
* the message, as on `contract_violation`.
|
|
395
|
+
*/
|
|
396
|
+
export function deviceRegistrationFailure(
|
|
397
|
+
kind:
|
|
398
|
+
| 'device_registration_limit'
|
|
399
|
+
| 'device_denied'
|
|
400
|
+
| 'device_approval_conflict'
|
|
401
|
+
| 'device_approval_unavailable',
|
|
402
|
+
correlationId: string | null,
|
|
403
|
+
retryAfterSeconds: number | null = null,
|
|
404
|
+
): DaaError {
|
|
405
|
+
const correlation = correlationId === null ? {} : { correlationId }
|
|
406
|
+
const detail: DaaSdkError =
|
|
407
|
+
kind === 'device_registration_limit'
|
|
408
|
+
? { kind, ...(retryAfterSeconds === null ? {} : { retryAfterSeconds }), ...correlation }
|
|
409
|
+
: { kind, ...correlation }
|
|
410
|
+
return new DaaError(
|
|
411
|
+
detail,
|
|
412
|
+
`DAA: ${DEVICE_REGISTRATION_MESSAGES[kind]}${requestIdSuffix(correlationId)}`,
|
|
413
|
+
)
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
const DEVICE_REGISTRATION_MESSAGES = Object.freeze({
|
|
417
|
+
device_registration_limit: 'too many add-a-device requests on this account recently',
|
|
418
|
+
device_denied: 'this device was declined on this account',
|
|
419
|
+
device_approval_conflict:
|
|
420
|
+
'another device was waiting for approval, so both requests were cancelled',
|
|
421
|
+
device_approval_unavailable: 'this account has no active device that can approve a new device',
|
|
422
|
+
})
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Why `DaaUserClient.approveDevice` refused, and what the app does next:
|
|
426
|
+
*
|
|
427
|
+
* - `matching_code_mismatch` (local): the code the user typed is not the one
|
|
428
|
+
* the new device shows. Nothing was signed or sent, and no biometric prompt
|
|
429
|
+
* was shown. Let the user type it again.
|
|
430
|
+
* - `device_approval_not_ready` (local): the new device has not sent its code
|
|
431
|
+
* secret yet, so the code can't be checked. Nothing was signed or sent.
|
|
432
|
+
* Try again in a few seconds.
|
|
433
|
+
* - `device_approval_invalid` (`DEVICE_APPROVAL_INVALID`, `420117`, `409`, or
|
|
434
|
+
* the request is no longer in the device list): the request is not waiting
|
|
435
|
+
* any more. It expired, was decided on another device, or was cancelled.
|
|
436
|
+
* Don't retry; the new device signs in again if the user still wants it.
|
|
437
|
+
* - `device_approval_busy` (`DEVICE_APPROVAL_BUSY`, `420120`, `409`): the
|
|
438
|
+
* account changed while DAA was approving. Call `approveDevice` again; it
|
|
439
|
+
* signs the same approval body again, so the user sees the biometric prompt again.
|
|
440
|
+
*
|
|
441
|
+
* `correlationId`, the response's `X-Request-Id`, goes on the two DAA kinds'
|
|
442
|
+
* detail and in the message, as on `contract_violation`.
|
|
443
|
+
*/
|
|
444
|
+
export function deviceApprovalFailure(
|
|
445
|
+
kind:
|
|
446
|
+
| 'matching_code_mismatch'
|
|
447
|
+
| 'device_approval_not_ready'
|
|
448
|
+
| 'device_approval_invalid'
|
|
449
|
+
| 'device_approval_busy',
|
|
450
|
+
correlationId: string | null = null,
|
|
451
|
+
cause: unknown = undefined,
|
|
452
|
+
): DaaError {
|
|
453
|
+
const detail: DaaSdkError =
|
|
454
|
+
kind === 'device_approval_invalid' || kind === 'device_approval_busy'
|
|
455
|
+
? { kind, ...(correlationId === null ? {} : { correlationId }) }
|
|
456
|
+
: { kind }
|
|
457
|
+
return new DaaError(
|
|
458
|
+
detail,
|
|
459
|
+
`DAA: ${DEVICE_APPROVAL_MESSAGES[kind]}${requestIdSuffix(correlationId)}`,
|
|
460
|
+
cause,
|
|
461
|
+
)
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
const DEVICE_APPROVAL_MESSAGES = Object.freeze({
|
|
465
|
+
matching_code_mismatch: 'the typed code is not the code the new device shows',
|
|
466
|
+
device_approval_not_ready: 'the new device has not sent its code secret yet',
|
|
467
|
+
device_approval_invalid: 'the device request is no longer waiting for approval',
|
|
468
|
+
device_approval_busy: 'the account changed while approving; approve again',
|
|
469
|
+
})
|
|
470
|
+
|
|
471
|
+
// The codes the native secure-key modules send. iOS async functions reject
|
|
472
|
+
// without a code and Expo prefixes the message ("Calling the '…' function has
|
|
473
|
+
// failed\n→ Caused by: …"), so the iOS module also starts each message with
|
|
474
|
+
// its code in brackets. Same rule as `mapNativeScaError`: a known `code` wins;
|
|
475
|
+
// otherwise the tag at the start of the innermost cause; otherwise none. The
|
|
476
|
+
// message is read only for that tag and never reaches `.message`.
|
|
477
|
+
const NATIVE_SECURE_KEY_CODES: ReadonlySet<string> = new Set([
|
|
478
|
+
'USER_CANCELLED',
|
|
479
|
+
'USER_AUTH_REQUIRED',
|
|
480
|
+
'NOT_INITIALIZED',
|
|
481
|
+
'DEVICE_LOCK_NOT_SET',
|
|
482
|
+
'DEVICE_NOT_SUPPORTED',
|
|
483
|
+
'KEY_INVALIDATED',
|
|
484
|
+
'MATCHING_CODE_MISMATCH',
|
|
485
|
+
])
|
|
486
|
+
const CAUSE_SEPARATOR = '→ Caused by: '
|
|
487
|
+
const CODE_TAG = /^\[([A-Z_]+)\]/
|
|
488
|
+
|
|
489
|
+
function nativeSecureKeyCode(err: unknown): string | undefined {
|
|
490
|
+
const fields = err as { code?: unknown; message?: unknown } | null | undefined
|
|
491
|
+
const code = fields?.code
|
|
492
|
+
if (typeof code === 'string' && NATIVE_SECURE_KEY_CODES.has(code)) {
|
|
493
|
+
return code
|
|
494
|
+
}
|
|
495
|
+
const message = fields?.message
|
|
496
|
+
if (typeof message !== 'string') {
|
|
497
|
+
return undefined
|
|
498
|
+
}
|
|
499
|
+
const at = message.lastIndexOf(CAUSE_SEPARATOR)
|
|
500
|
+
const innermost = at < 0 ? message : message.slice(at + CAUSE_SEPARATOR.length)
|
|
501
|
+
const tag = CODE_TAG.exec(innermost)?.[1]
|
|
502
|
+
return tag !== undefined && NATIVE_SECURE_KEY_CODES.has(tag) ? tag : undefined
|
|
503
|
+
}
|
|
504
|
+
|
|
285
505
|
/**
|
|
286
506
|
* Map an error thrown by the native secure-key module onto `DaaSdkError`. The
|
|
287
507
|
* raw native message is never propagated into `.message` — it can contain
|
|
@@ -289,14 +509,25 @@ export function idempotencyConflict(
|
|
|
289
509
|
* as `.cause` for deliberate inspection.
|
|
290
510
|
*
|
|
291
511
|
* An already-structured `DaaError` passes through unchanged. Otherwise a stable
|
|
292
|
-
*
|
|
293
|
-
* collapses to
|
|
512
|
+
* native code (the error's `code`, or on iOS the `[CODE]` tag on the innermost
|
|
513
|
+
* cause) maps the known custody states; anything else collapses to
|
|
514
|
+
* `contract_violation`.
|
|
294
515
|
*/
|
|
295
516
|
export function mapNativeError(err: unknown): DaaError {
|
|
296
517
|
if (err instanceof DaaError) {
|
|
297
518
|
return err
|
|
298
519
|
}
|
|
299
|
-
const code = (err
|
|
520
|
+
const code = nativeSecureKeyCode(err)
|
|
521
|
+
if (code === 'USER_CANCELLED') {
|
|
522
|
+
// Checked ahead of USER_AUTH_REQUIRED on purpose: a dismissed prompt is the
|
|
523
|
+
// user's choice, not a failed or unavailable authentication.
|
|
524
|
+
return userCancelled(err)
|
|
525
|
+
}
|
|
526
|
+
if (code === 'MATCHING_CODE_MISMATCH') {
|
|
527
|
+
// Native's own typed-code check, before its biometric prompt.
|
|
528
|
+
// `approveDevice` checks first, so this is reached only if the two disagree.
|
|
529
|
+
return deviceApprovalFailure('matching_code_mismatch', null, err)
|
|
530
|
+
}
|
|
300
531
|
if (code === 'USER_AUTH_REQUIRED') {
|
|
301
532
|
return new DaaError(
|
|
302
533
|
{ kind: 'local_user_authentication_required' },
|
|
@@ -311,6 +542,32 @@ export function mapNativeError(err: unknown): DaaError {
|
|
|
311
542
|
err,
|
|
312
543
|
)
|
|
313
544
|
}
|
|
545
|
+
// The next three are device states the user can't fix by trying the prompt
|
|
546
|
+
// again, so each gets its own kind rather than
|
|
547
|
+
// `local_user_authentication_required` ("try again") or `contract_violation`.
|
|
548
|
+
// On Android `device_not_supported` can also be a temporary hardware or
|
|
549
|
+
// keystore failure; docs/native-secure-key.md says how apps should treat it.
|
|
550
|
+
if (code === 'DEVICE_LOCK_NOT_SET') {
|
|
551
|
+
return new DaaError(
|
|
552
|
+
{ kind: 'device_lock_not_set' },
|
|
553
|
+
'DAA: the device has no screen lock or biometric set up',
|
|
554
|
+
err,
|
|
555
|
+
)
|
|
556
|
+
}
|
|
557
|
+
if (code === 'DEVICE_NOT_SUPPORTED') {
|
|
558
|
+
return new DaaError(
|
|
559
|
+
{ kind: 'device_not_supported' },
|
|
560
|
+
'DAA: secure hardware is unavailable for this operation',
|
|
561
|
+
err,
|
|
562
|
+
)
|
|
563
|
+
}
|
|
564
|
+
if (code === 'KEY_INVALIDATED') {
|
|
565
|
+
return new DaaError(
|
|
566
|
+
{ kind: 'key_invalidated' },
|
|
567
|
+
'DAA: the device key was invalidated and cannot be recovered',
|
|
568
|
+
err,
|
|
569
|
+
)
|
|
570
|
+
}
|
|
314
571
|
return new DaaError(
|
|
315
572
|
{ kind: 'contract_violation' },
|
|
316
573
|
'DAA: native secure-key operation failed',
|
package/src/index.ts
CHANGED
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
// elsewhere (see SECURITY.md and the `exports` map in package.json).
|
|
43
43
|
|
|
44
44
|
export { DaaClient } from './DaaClient'
|
|
45
|
+
export type { SessionRestoreResult } from './DaaClient'
|
|
45
46
|
|
|
46
47
|
// Passkey SCA (native ceremony through Circle's hosted page). A runtime value
|
|
47
48
|
// on purpose: it is the only way to reach the DaaSca native module.
|
|
@@ -80,6 +81,7 @@ export type { AccountLimitsClient, AccountLimitsUsageQuery } from './api/Account
|
|
|
80
81
|
export type { DepositAddressListQuery, DepositAddressesClient } from './api/DepositAddressesClient'
|
|
81
82
|
export type { DepositListQuery, DepositsClient } from './api/DepositsClient'
|
|
82
83
|
export type { TransactionListQuery, TransactionsClient } from './api/TransactionsClient'
|
|
84
|
+
export type { ContractExecutionsClient } from './api/ContractExecutionsClient'
|
|
83
85
|
export type { TransferListQuery, TransfersClient } from './api/TransfersClient'
|
|
84
86
|
export type { WithdrawalListQuery, WithdrawalsClient } from './api/WithdrawalsClient'
|
|
85
87
|
export type { FiatAccountsClient } from './api/FiatAccountsClient'
|
|
@@ -91,12 +93,19 @@ export type {
|
|
|
91
93
|
} from './api/WireFiatAccountsClient'
|
|
92
94
|
export type { AchFiatAccountListQuery, AchFiatAccountsClient } from './api/AchFiatAccountsClient'
|
|
93
95
|
export type { DaaUserClient } from './api/DaaUserClient'
|
|
96
|
+
export type { ApproveDeviceArgs } from './api/deviceApproval'
|
|
94
97
|
export type {
|
|
95
98
|
DaaUserContext,
|
|
96
99
|
DeviceContext,
|
|
97
100
|
DeviceRegistrationResult,
|
|
98
101
|
} from './models/DaaUserContext'
|
|
99
|
-
export type {
|
|
102
|
+
export type {
|
|
103
|
+
DeviceApprovalHint,
|
|
104
|
+
DeviceRegistrationRiskSignals,
|
|
105
|
+
PendingDeviceRegistration,
|
|
106
|
+
} from './models/PendingDeviceRegistration'
|
|
107
|
+
export type { DeviceStatus } from './models/DeviceStatus'
|
|
108
|
+
export type { PendingDeviceApproval } from './models/PendingDeviceApproval'
|
|
100
109
|
export type {
|
|
101
110
|
Account,
|
|
102
111
|
AccountPurpose,
|
|
@@ -124,6 +133,26 @@ export type {
|
|
|
124
133
|
CreateTransferRiskSignals,
|
|
125
134
|
CreateTransferSource,
|
|
126
135
|
} from './models/CreateTransferRequest'
|
|
136
|
+
export type {
|
|
137
|
+
ContractExecutionBlockchain,
|
|
138
|
+
CreateContractExecutionAbiRequest,
|
|
139
|
+
CreateContractExecutionRawRequest,
|
|
140
|
+
CreateContractExecutionRequest,
|
|
141
|
+
} from './models/CreateContractExecutionRequest'
|
|
142
|
+
export type {
|
|
143
|
+
PersistedContractExecution,
|
|
144
|
+
PreparedContractExecution,
|
|
145
|
+
PreparedContractExecutionRendering,
|
|
146
|
+
} from './models/PreparedContractExecution'
|
|
147
|
+
export type {
|
|
148
|
+
AbiParameter,
|
|
149
|
+
ContractExecution,
|
|
150
|
+
ContractExecutionErrorCode,
|
|
151
|
+
ContractExecutionInvocation,
|
|
152
|
+
ContractExecutionRendering,
|
|
153
|
+
ContractExecutionSource,
|
|
154
|
+
ContractExecutionStatus,
|
|
155
|
+
} from './models/ContractExecution'
|
|
127
156
|
export type { Address, BusinessPii } from './models/BusinessPii'
|
|
128
157
|
export type { AddressObject, AddressObjectRendering } from './models/AddressObject'
|
|
129
158
|
export type { DepositAddressChain, GenerateAddressRequest } from './models/GenerateAddressRequest'
|
|
@@ -145,6 +174,8 @@ export type {
|
|
|
145
174
|
TransactionAccountLocation,
|
|
146
175
|
TransactionBlockchainLocation,
|
|
147
176
|
TransactionBlockchainLocationRendering,
|
|
177
|
+
TransactionContractExecution,
|
|
178
|
+
TransactionContractExecutionRendering,
|
|
148
179
|
TransactionFiatLocation,
|
|
149
180
|
TransactionLocation,
|
|
150
181
|
TransactionRendering,
|
|
@@ -212,9 +243,13 @@ export type { DaaSdkError } from './errors'
|
|
|
212
243
|
// `err.detail.kind`.
|
|
213
244
|
export { DaaError, isDaaError } from './errors'
|
|
214
245
|
export type {
|
|
246
|
+
AuthKeyRegistration,
|
|
215
247
|
AuthKeyResolution,
|
|
248
|
+
DeviceApprovalCheck,
|
|
249
|
+
DeviceApprovalSigning,
|
|
216
250
|
OwnerAuthKey,
|
|
217
251
|
OwnerKeyIdentity,
|
|
252
|
+
RegisteredOwnerAuthKey,
|
|
218
253
|
SecureKeyStore,
|
|
219
254
|
} from './securekey/SecureKey'
|
|
220
255
|
|