@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.
Files changed (157) hide show
  1. package/DaaReactNativeSdk.podspec +14 -8
  2. package/README.md +498 -24
  3. package/android/build.gradle +12 -7
  4. package/android/src/main/java/com/circle/daa/reactnative/DaaRegistrationModule.kt +1 -18
  5. package/android/src/main/java/com/circle/daa/reactnative/DaaSecureKeyExceptions.kt +38 -4
  6. package/android/src/main/java/com/circle/daa/reactnative/DaaSecureKeyModule.kt +139 -6
  7. package/android/src/main/java/com/circle/daa/reactnative/InstallationIdentityStore.kt +50 -1
  8. package/build/DaaClient.d.ts +183 -3
  9. package/build/DaaClient.js +296 -12
  10. package/build/api/AccountsClient.d.ts +3 -0
  11. package/build/api/AccountsClient.js +3 -0
  12. package/build/api/AuthClient.d.ts +17 -42
  13. package/build/api/AuthClient.js +26 -62
  14. package/build/api/ContractExecutionsClient.d.ts +114 -0
  15. package/build/api/ContractExecutionsClient.js +462 -0
  16. package/build/api/DaaUserClient.d.ts +74 -11
  17. package/build/api/DaaUserClient.js +84 -17
  18. package/build/api/TransactionsClient.d.ts +1 -1
  19. package/build/api/TransactionsClient.js +1 -0
  20. package/build/api/TransfersClient.d.ts +3 -0
  21. package/build/api/TransfersClient.js +3 -0
  22. package/build/api/WithdrawalsClient.d.ts +3 -0
  23. package/build/api/WithdrawalsClient.js +3 -0
  24. package/build/api/deviceApproval.d.ts +48 -0
  25. package/build/api/deviceApproval.js +247 -0
  26. package/build/api/deviceStatus.d.ts +61 -0
  27. package/build/api/deviceStatus.js +216 -0
  28. package/build/api/loginFailure.d.ts +10 -2
  29. package/build/api/loginFailure.js +33 -2
  30. package/build/api/signedResource.d.ts +49 -2
  31. package/build/api/signedResource.js +135 -36
  32. package/build/auth/RegistrationFlowKey.js +1 -1
  33. package/build/auth/daaRegistrationNative.d.ts +0 -22
  34. package/build/auth/daaRegistrationNative.js +3 -29
  35. package/build/auth/deviceAuthorization.d.ts +17 -3
  36. package/build/auth/deviceAuthorization.js +60 -8
  37. package/build/auth/registrationAuthorization.d.ts +2 -2
  38. package/build/auth/registrationAuthorization.js +13 -10
  39. package/build/config.d.ts +27 -0
  40. package/build/config.js +15 -0
  41. package/build/crypto/matchingCode.d.ts +47 -0
  42. package/build/crypto/matchingCode.js +93 -0
  43. package/build/errors.d.ts +150 -33
  44. package/build/errors.js +208 -47
  45. package/build/index.d.ts +11 -3
  46. package/build/models/ContractExecution.d.ts +197 -0
  47. package/build/models/ContractExecution.js +130 -0
  48. package/build/models/CreateContractExecutionRequest.d.ts +81 -0
  49. package/build/models/CreateContractExecutionRequest.js +19 -0
  50. package/build/models/DaaUserContext.d.ts +53 -3
  51. package/build/models/DaaUserContext.js +33 -2
  52. package/build/models/DeviceStatus.d.ts +69 -0
  53. package/build/models/DeviceStatus.js +19 -0
  54. package/build/models/PendingDeviceApproval.d.ts +121 -0
  55. package/build/models/PendingDeviceApproval.js +208 -0
  56. package/build/models/PendingDeviceRegistration.d.ts +162 -23
  57. package/build/models/PendingDeviceRegistration.js +525 -69
  58. package/build/models/PreparedContractExecution.d.ts +70 -0
  59. package/build/models/PreparedContractExecution.js +77 -0
  60. package/build/models/PreparedSocialLogin.d.ts +19 -26
  61. package/build/models/PreparedSocialLogin.js +32 -15
  62. package/build/models/Transaction.d.ts +48 -2
  63. package/build/models/Transaction.js +52 -4
  64. package/build/models/codeSecrets.d.ts +100 -0
  65. package/build/models/codeSecrets.js +321 -0
  66. package/build/securekey/InMemorySecureKey.d.ts +3 -1
  67. package/build/securekey/InMemorySecureKey.js +47 -6
  68. package/build/securekey/NativeSecureKey.d.ts +3 -1
  69. package/build/securekey/NativeSecureKey.js +204 -27
  70. package/build/securekey/NativeSecureKeyBridge.d.ts +72 -4
  71. package/build/securekey/SecureKey.d.ts +128 -8
  72. package/build/securekey/alias.d.ts +9 -0
  73. package/build/securekey/alias.js +11 -2
  74. package/build/securekey/ownerAuthKeyResolver.d.ts +26 -9
  75. package/build/securekey/ownerAuthKeyResolver.js +35 -20
  76. package/build/securekey/registration.d.ts +19 -0
  77. package/build/securekey/registration.js +38 -0
  78. package/build/securekey/resolveNativeBridge.d.ts +3 -0
  79. package/build/securekey/resolveNativeBridge.js +88 -7
  80. package/build/transport/headers.d.ts +11 -0
  81. package/build/transport/headers.js +36 -0
  82. package/build/wire/contractExecutionPayload.d.ts +24 -0
  83. package/build/wire/contractExecutionPayload.js +130 -0
  84. package/build/wire/daaStatusCodes.d.ts +20 -3
  85. package/build/wire/daaStatusCodes.js +20 -3
  86. package/build/wire/deviceContextPayload.d.ts +9 -7
  87. package/build/wire/deviceContextPayload.js +9 -7
  88. package/build/wire/deviceRegistrationResultPayload.d.ts +55 -10
  89. package/build/wire/deviceRegistrationResultPayload.js +116 -82
  90. package/build/wire/deviceStatusPayload.d.ts +20 -0
  91. package/build/wire/deviceStatusPayload.js +66 -0
  92. package/build/wire/instant.js +4 -1
  93. package/build/wire/pendingRegistrationPayload.d.ts +16 -0
  94. package/build/wire/pendingRegistrationPayload.js +18 -0
  95. package/build/wire/socialLoginRequestPayload.d.ts +0 -5
  96. package/build/wire/socialLoginRequestPayload.js +2 -19
  97. package/build/wire/transactionPayload.d.ts +2 -2
  98. package/build/wire/transactionPayload.js +27 -4
  99. package/ios/DaaRegistrationModule.swift +1 -19
  100. package/ios/DaaSecureKeyExceptions.swift +53 -5
  101. package/ios/DaaSecureKeyModule.swift +149 -5
  102. package/ios/InstallationIdentityStore.swift +43 -7
  103. package/package.json +1 -1
  104. package/src/DaaClient.ts +353 -15
  105. package/src/api/AccountsClient.ts +3 -0
  106. package/src/api/AuthClient.ts +33 -98
  107. package/src/api/ContractExecutionsClient.ts +527 -0
  108. package/src/api/DaaUserClient.ts +92 -17
  109. package/src/api/TransactionsClient.ts +1 -0
  110. package/src/api/TransfersClient.ts +3 -0
  111. package/src/api/WithdrawalsClient.ts +3 -0
  112. package/src/api/deviceApproval.ts +306 -0
  113. package/src/api/deviceStatus.ts +238 -0
  114. package/src/api/loginFailure.ts +39 -2
  115. package/src/api/signedResource.ts +206 -46
  116. package/src/auth/RegistrationFlowKey.ts +1 -1
  117. package/src/auth/daaRegistrationNative.ts +4 -49
  118. package/src/auth/deviceAuthorization.ts +74 -11
  119. package/src/auth/registrationAuthorization.ts +12 -9
  120. package/src/config.ts +36 -0
  121. package/src/crypto/matchingCode.ts +100 -0
  122. package/src/errors.ts +309 -52
  123. package/src/index.ts +36 -1
  124. package/src/models/ContractExecution.ts +250 -0
  125. package/src/models/CreateContractExecutionRequest.ts +100 -0
  126. package/src/models/DaaUserContext.ts +59 -3
  127. package/src/models/DeviceStatus.ts +50 -0
  128. package/src/models/PendingDeviceApproval.ts +229 -0
  129. package/src/models/PendingDeviceRegistration.ts +673 -79
  130. package/src/models/PreparedContractExecution.ts +128 -0
  131. package/src/models/PreparedSocialLogin.ts +41 -31
  132. package/src/models/Transaction.ts +77 -2
  133. package/src/models/codeSecrets.ts +360 -0
  134. package/src/securekey/InMemorySecureKey.ts +61 -7
  135. package/src/securekey/NativeSecureKey.ts +234 -25
  136. package/src/securekey/NativeSecureKeyBridge.ts +84 -4
  137. package/src/securekey/SecureKey.ts +138 -8
  138. package/src/securekey/alias.ts +11 -3
  139. package/src/securekey/ownerAuthKeyResolver.ts +63 -24
  140. package/src/securekey/registration.ts +40 -0
  141. package/src/securekey/resolveNativeBridge.ts +167 -9
  142. package/src/transport/headers.ts +47 -0
  143. package/src/wire/contractExecutionPayload.ts +152 -0
  144. package/src/wire/daaStatusCodes.ts +20 -3
  145. package/src/wire/deviceContextPayload.ts +9 -7
  146. package/src/wire/deviceRegistrationResultPayload.ts +156 -98
  147. package/src/wire/deviceStatusPayload.ts +68 -0
  148. package/src/wire/instant.ts +4 -1
  149. package/src/wire/pendingRegistrationPayload.ts +44 -1
  150. package/src/wire/socialLoginRequestPayload.ts +2 -25
  151. package/src/wire/transactionPayload.ts +40 -4
  152. package/build/auth/prepareReceipt.d.ts +0 -150
  153. package/build/auth/prepareReceipt.js +0 -357
  154. package/build/crypto/es256Jws.d.ts +0 -56
  155. package/build/crypto/es256Jws.js +0 -196
  156. package/src/auth/prepareReceipt.ts +0 -522
  157. package/src/crypto/es256Jws.ts +0 -240
package/build/errors.js CHANGED
@@ -24,9 +24,14 @@ exports.malformedResponse = malformedResponse;
24
24
  exports.apiFailure = apiFailure;
25
25
  exports.transportFailure = transportFailure;
26
26
  exports.loginRequestExpired = loginRequestExpired;
27
- exports.prepareReceiptInvalid = prepareReceiptInvalid;
28
- exports.withRequestId = withRequestId;
29
27
  exports.idempotencyConflict = idempotencyConflict;
28
+ exports.clockSkew = clockSkew;
29
+ exports.userCancelled = userCancelled;
30
+ exports.devicePending = devicePending;
31
+ exports.matchingCodeUnavailable = matchingCodeUnavailable;
32
+ exports.registrationNotSaved = registrationNotSaved;
33
+ exports.deviceRegistrationFailure = deviceRegistrationFailure;
34
+ exports.deviceApprovalFailure = deviceApprovalFailure;
30
35
  exports.mapNativeError = mapNativeError;
31
36
  /**
32
37
  * An Error carrying a structured `DaaSdkError`. The SDK throws this so callers
@@ -167,48 +172,6 @@ function transportFailure(cause, idempotencyKey) {
167
172
  function loginRequestExpired(correlationId) {
168
173
  return new DaaError({ kind: 'login_request_expired' }, `DAA: the login request has expired${requestIdSuffix(correlationId)}`);
169
174
  }
170
- /**
171
- * The Prepare receipt could not be verified: it is missing where one is
172
- * required, malformed, signed by no pinned key, bound to values other than this
173
- * attempt's, outside its validity window, or the platform verifier is missing
174
- * or failed.
175
- *
176
- * On the login path this is raised only when a trust anchor is pinned for the
177
- * environment: the SDK then verifies the receipt and fails closed on any
178
- * mismatch, and nothing from that Prepare response reaches the application.
179
- * With no anchor pinned, the receipt is ignored. Not retryable in place: the
180
- * caller's recovery is a new `prepareSocialLogin`, which sends a fresh
181
- * challenge and flow key. A failure that persists across fresh attempts points
182
- * at the relay or at trust material that does not match the service's signer,
183
- * not at the user.
184
- *
185
- * The receipt is unverified server-supplied text and never goes into the
186
- * message; `message` here is one of the SDK's own literals.
187
- */
188
- function prepareReceiptInvalid(message, cause = undefined) {
189
- return new DaaError({ kind: 'prepare_receipt_invalid' }, `DAA: ${message}`, cause);
190
- }
191
- /**
192
- * The same error with the response's `X-Request-Id` named in its message.
193
- *
194
- * For a check that runs on a decoded response without seeing the response
195
- * itself — the Prepare receipt's verification has many throw sites and none of
196
- * them holds the headers — so the caller that does hold the response adds the
197
- * id once. The detail, the cause, and the stack of the check that threw are
198
- * unchanged.
199
- */
200
- function withRequestId(err, correlationId) {
201
- if (correlationId === null) {
202
- return err;
203
- }
204
- const correlated = new DaaError(err.detail, `${err.message}${requestIdSuffix(correlationId)}`, err.cause);
205
- if (err.stack !== undefined) {
206
- // Keep the frame that names which receipt check failed, with the new message.
207
- // A function replacer, so a `$` in the server's id is not a replace pattern.
208
- correlated.stack = err.stack.replace(err.message, () => correlated.message);
209
- }
210
- return correlated;
211
- }
212
175
  /**
213
176
  * An idempotency key was reused with different request bytes: a `409` with
214
177
  * `IDEMPOTENCY_KEY_REUSED` (`420034`). Another `409` is not this error.
@@ -227,6 +190,179 @@ function idempotencyConflict(idempotencyKey, correlationId) {
227
190
  : { kind: 'idempotency_conflict', idempotencyKey, correlationId };
228
191
  return new DaaError(detail, `DAA: idempotency key was reused with a different request${requestIdSuffix(correlationId)}`);
229
192
  }
193
+ /**
194
+ * DAA refused a registered-device authorization as invalid
195
+ * (`DEVICE_AUTHORIZATION_INVALID`), and the authorization's own `iat`/`exp`
196
+ * fail DAA's 60-second freshness rule against the response's HTTP `Date`.
197
+ *
198
+ * The device clock was wrong when the authorization was signed, so the
199
+ * recovery is to correct the device time and send a newly signed request — not
200
+ * to treat the AuthKey as rejected. A prepared contract execution cannot be
201
+ * re-signed: `submit` resends the authorization made at `prepare`, so correcting
202
+ * the clock does not help it; prepare a new execution instead, as for an expired
203
+ * authorization (see `ContractExecutionsClient.submit`). `Date` is not signed,
204
+ * so it is used only to choose this classification; its value is not carried on
205
+ * the error.
206
+ */
207
+ function clockSkew(correlationId) {
208
+ const detail = correlationId === null ? { kind: 'clock_skew' } : { kind: 'clock_skew', correlationId };
209
+ const suffix = correlationId === null ? '' : ` (requestId=${messageSafe(correlationId)})`;
210
+ return new DaaError(detail, `DAA: the device authorization was rejected and the device clock differs from the service clock${suffix}`);
211
+ }
212
+ /**
213
+ * The user dismissed the device's user-authentication prompt (biometrics or
214
+ * device credential) for an AuthKey operation.
215
+ *
216
+ * Deliberate user intent, not a credential problem: the AuthKey is untouched
217
+ * and nothing was sent. The caller keeps the key and lets the user try again
218
+ * when they choose. For a signed request, that means sending it again. For
219
+ * Device Registration Complete the pending registration is used up, so trying
220
+ * again means a new login started by the user. That login reuses the same
221
+ * AuthKey.
222
+ */
223
+ function userCancelled(cause = undefined) {
224
+ return new DaaError({ kind: 'user_cancelled' }, 'DAA: the user cancelled authentication', cause);
225
+ }
226
+ /**
227
+ * DAA refused a signed request because the signing key can't sign yet
228
+ * (`DEVICE_PENDING`, `420118`, `409`): it was approved from another device and
229
+ * is in the account's cool-down until its `readyAt`, or it is still waiting
230
+ * for approval. `restore`, `refreshContext` and every signed write report it.
231
+ * Nothing changed on DAA and the key stays valid: keep it, wait (follow
232
+ * `watchDeviceStatus` until `active`), then call `restore` again. Never
233
+ * `forgetLocalKey` or start a new login for it.
234
+ */
235
+ function devicePending(correlationId = null) {
236
+ return new DaaError(correlationId === null ? { kind: 'device_pending' } : { kind: 'device_pending', correlationId }, `DAA: this device can't sign yet; wait until it is active${requestIdSuffix(correlationId)}`);
237
+ }
238
+ /**
239
+ * This device can't show the matching code for its add-a-device request: DAA
240
+ * returned the request with a `codeSeal` that this device's code secret
241
+ * doesn't open. The request was sealed with a secret this SDK no longer holds
242
+ * (the app restarted while it was waiting, or a registration that timed out
243
+ * reached DAA late). A code shown now could never match, so
244
+ * `PendingDeviceApproval.getMatchingCode()` and `sendCodeSecret()` throw this
245
+ * instead, and nothing is sent. Tell the user to wait until the request's
246
+ * `expiresAt` and sign in again: that opens a new request this device can show
247
+ * the code for.
248
+ */
249
+ function matchingCodeUnavailable() {
250
+ return new DaaError({ kind: 'matching_code_unavailable' }, "DAA: this device can't show the matching code for this request; sign in again after it expires");
251
+ }
252
+ /**
253
+ * Device Registration Complete succeeded, and DAA has this device's AuthKey
254
+ * `ACTIVE` (or `PENDING_ACTIVATION`), but saving the `authKeyId` and
255
+ * `ownerBindingId` it returned on this device failed (for example a Keychain or
256
+ * Keystore write error). Until they are saved, session restore can't find the key, and a new login with it fails with
257
+ * DAA's `AUTH_KEY_BINDING_CONFLICT`. Call `complete()` on the same
258
+ * `PendingDeviceRegistration` again: it sends nothing and retries only the save.
259
+ * The native error is on `cause`, never in the message. A save that fails
260
+ * because the key is gone (`key_invalidated`, `device_not_initialized`) throws
261
+ * that kind instead: retrying could never succeed.
262
+ */
263
+ function registrationNotSaved(cause) {
264
+ return new DaaError({ kind: 'registration_not_saved' }, 'DAA: the device is registered, but saving its registration on this device failed; call complete() again', cause);
265
+ }
266
+ /**
267
+ * The add-a-device states Device Registration Complete can refuse with, by the
268
+ * DAA code it sends. What the app does next differs for each:
269
+ *
270
+ * - `device_registration_limit` (`DEVICE_REGISTRATION_LIMIT`, `420109`, `429`):
271
+ * the account had 5 add-a-device requests in the last 10 minutes. Wait
272
+ * `retryAfterSeconds` (from `Retry-After`, when the response has a whole
273
+ * number of seconds there) and sign in again.
274
+ * - `device_denied` (`DEVICE_DENIED`, `420111`, `403`): the user declined this
275
+ * key with Not me on another device, so this key can't ask again.
276
+ * - `device_approval_conflict` (`DEVICE_APPROVAL_CONFLICT`, `420112`, `409`):
277
+ * another new device was already waiting, so DAA cancelled both requests.
278
+ * Both devices must sign in again.
279
+ * - `device_approval_unavailable` (`DEVICE_APPROVAL_UNAVAILABLE`, `420113`,
280
+ * `409`): the account has no active device that could approve this one. If a
281
+ * device is in its cool-down, signing in again after it ends works;
282
+ * otherwise the user must recover the account.
283
+ *
284
+ * In every case this `PendingDeviceRegistration` is used up: trying again
285
+ * needs a new login.
286
+ * `correlationId`, the response's `X-Request-Id`, goes on the detail and in
287
+ * the message, as on `contract_violation`.
288
+ */
289
+ function deviceRegistrationFailure(kind, correlationId, retryAfterSeconds = null) {
290
+ const correlation = correlationId === null ? {} : { correlationId };
291
+ const detail = kind === 'device_registration_limit'
292
+ ? { kind, ...(retryAfterSeconds === null ? {} : { retryAfterSeconds }), ...correlation }
293
+ : { kind, ...correlation };
294
+ return new DaaError(detail, `DAA: ${DEVICE_REGISTRATION_MESSAGES[kind]}${requestIdSuffix(correlationId)}`);
295
+ }
296
+ const DEVICE_REGISTRATION_MESSAGES = Object.freeze({
297
+ device_registration_limit: 'too many add-a-device requests on this account recently',
298
+ device_denied: 'this device was declined on this account',
299
+ device_approval_conflict: 'another device was waiting for approval, so both requests were cancelled',
300
+ device_approval_unavailable: 'this account has no active device that can approve a new device',
301
+ });
302
+ /**
303
+ * Why `DaaUserClient.approveDevice` refused, and what the app does next:
304
+ *
305
+ * - `matching_code_mismatch` (local): the code the user typed is not the one
306
+ * the new device shows. Nothing was signed or sent, and no biometric prompt
307
+ * was shown. Let the user type it again.
308
+ * - `device_approval_not_ready` (local): the new device has not sent its code
309
+ * secret yet, so the code can't be checked. Nothing was signed or sent.
310
+ * Try again in a few seconds.
311
+ * - `device_approval_invalid` (`DEVICE_APPROVAL_INVALID`, `420117`, `409`, or
312
+ * the request is no longer in the device list): the request is not waiting
313
+ * any more. It expired, was decided on another device, or was cancelled.
314
+ * Don't retry; the new device signs in again if the user still wants it.
315
+ * - `device_approval_busy` (`DEVICE_APPROVAL_BUSY`, `420120`, `409`): the
316
+ * account changed while DAA was approving. Call `approveDevice` again; it
317
+ * signs the same approval body again, so the user sees the biometric prompt again.
318
+ *
319
+ * `correlationId`, the response's `X-Request-Id`, goes on the two DAA kinds'
320
+ * detail and in the message, as on `contract_violation`.
321
+ */
322
+ function deviceApprovalFailure(kind, correlationId = null, cause = undefined) {
323
+ const detail = kind === 'device_approval_invalid' || kind === 'device_approval_busy'
324
+ ? { kind, ...(correlationId === null ? {} : { correlationId }) }
325
+ : { kind };
326
+ return new DaaError(detail, `DAA: ${DEVICE_APPROVAL_MESSAGES[kind]}${requestIdSuffix(correlationId)}`, cause);
327
+ }
328
+ const DEVICE_APPROVAL_MESSAGES = Object.freeze({
329
+ matching_code_mismatch: 'the typed code is not the code the new device shows',
330
+ device_approval_not_ready: 'the new device has not sent its code secret yet',
331
+ device_approval_invalid: 'the device request is no longer waiting for approval',
332
+ device_approval_busy: 'the account changed while approving; approve again',
333
+ });
334
+ // The codes the native secure-key modules send. iOS async functions reject
335
+ // without a code and Expo prefixes the message ("Calling the '…' function has
336
+ // failed\n→ Caused by: …"), so the iOS module also starts each message with
337
+ // its code in brackets. Same rule as `mapNativeScaError`: a known `code` wins;
338
+ // otherwise the tag at the start of the innermost cause; otherwise none. The
339
+ // message is read only for that tag and never reaches `.message`.
340
+ const NATIVE_SECURE_KEY_CODES = new Set([
341
+ 'USER_CANCELLED',
342
+ 'USER_AUTH_REQUIRED',
343
+ 'NOT_INITIALIZED',
344
+ 'DEVICE_LOCK_NOT_SET',
345
+ 'DEVICE_NOT_SUPPORTED',
346
+ 'KEY_INVALIDATED',
347
+ 'MATCHING_CODE_MISMATCH',
348
+ ]);
349
+ const CAUSE_SEPARATOR = '→ Caused by: ';
350
+ const CODE_TAG = /^\[([A-Z_]+)\]/;
351
+ function nativeSecureKeyCode(err) {
352
+ const fields = err;
353
+ const code = fields?.code;
354
+ if (typeof code === 'string' && NATIVE_SECURE_KEY_CODES.has(code)) {
355
+ return code;
356
+ }
357
+ const message = fields?.message;
358
+ if (typeof message !== 'string') {
359
+ return undefined;
360
+ }
361
+ const at = message.lastIndexOf(CAUSE_SEPARATOR);
362
+ const innermost = at < 0 ? message : message.slice(at + CAUSE_SEPARATOR.length);
363
+ const tag = CODE_TAG.exec(innermost)?.[1];
364
+ return tag !== undefined && NATIVE_SECURE_KEY_CODES.has(tag) ? tag : undefined;
365
+ }
230
366
  /**
231
367
  * Map an error thrown by the native secure-key module onto `DaaSdkError`. The
232
368
  * raw native message is never propagated into `.message` — it can contain
@@ -234,19 +370,44 @@ function idempotencyConflict(idempotencyKey, correlationId) {
234
370
  * as `.cause` for deliberate inspection.
235
371
  *
236
372
  * An already-structured `DaaError` passes through unchanged. Otherwise a stable
237
- * `code` on the native error maps the known custody states; anything else
238
- * collapses to `contract_violation`.
373
+ * native code (the error's `code`, or on iOS the `[CODE]` tag on the innermost
374
+ * cause) maps the known custody states; anything else collapses to
375
+ * `contract_violation`.
239
376
  */
240
377
  function mapNativeError(err) {
241
378
  if (err instanceof DaaError) {
242
379
  return err;
243
380
  }
244
- const code = err?.code;
381
+ const code = nativeSecureKeyCode(err);
382
+ if (code === 'USER_CANCELLED') {
383
+ // Checked ahead of USER_AUTH_REQUIRED on purpose: a dismissed prompt is the
384
+ // user's choice, not a failed or unavailable authentication.
385
+ return userCancelled(err);
386
+ }
387
+ if (code === 'MATCHING_CODE_MISMATCH') {
388
+ // Native's own typed-code check, before its biometric prompt.
389
+ // `approveDevice` checks first, so this is reached only if the two disagree.
390
+ return deviceApprovalFailure('matching_code_mismatch', null, err);
391
+ }
245
392
  if (code === 'USER_AUTH_REQUIRED') {
246
393
  return new DaaError({ kind: 'local_user_authentication_required' }, 'DAA: user authentication is required', err);
247
394
  }
248
395
  if (code === 'NOT_INITIALIZED') {
249
396
  return new DaaError({ kind: 'device_not_initialized' }, 'DAA: secure key is not initialized', err);
250
397
  }
398
+ // The next three are device states the user can't fix by trying the prompt
399
+ // again, so each gets its own kind rather than
400
+ // `local_user_authentication_required` ("try again") or `contract_violation`.
401
+ // On Android `device_not_supported` can also be a temporary hardware or
402
+ // keystore failure; docs/native-secure-key.md says how apps should treat it.
403
+ if (code === 'DEVICE_LOCK_NOT_SET') {
404
+ return new DaaError({ kind: 'device_lock_not_set' }, 'DAA: the device has no screen lock or biometric set up', err);
405
+ }
406
+ if (code === 'DEVICE_NOT_SUPPORTED') {
407
+ return new DaaError({ kind: 'device_not_supported' }, 'DAA: secure hardware is unavailable for this operation', err);
408
+ }
409
+ if (code === 'KEY_INVALIDATED') {
410
+ return new DaaError({ kind: 'key_invalidated' }, 'DAA: the device key was invalidated and cannot be recovered', err);
411
+ }
251
412
  return new DaaError({ kind: 'contract_violation' }, 'DAA: native secure-key operation failed', err);
252
413
  }
package/build/index.d.ts CHANGED
@@ -16,6 +16,7 @@
16
16
  * limitations under the License.
17
17
  */
18
18
  export { DaaClient } from './DaaClient';
19
+ export type { SessionRestoreResult } from './DaaClient';
19
20
  export { createScaClient, isScaError, ScaError } from './sca/ScaClient';
20
21
  export type { ScaCapabilities, ScaClient, ScaConfig, ScaEnvironment, ScaErrorCode, } from './sca/ScaClient';
21
22
  export type { AuthClient } from './api/AuthClient';
@@ -24,18 +25,25 @@ export type { AccountLimitsClient, AccountLimitsUsageQuery } from './api/Account
24
25
  export type { DepositAddressListQuery, DepositAddressesClient } from './api/DepositAddressesClient';
25
26
  export type { DepositListQuery, DepositsClient } from './api/DepositsClient';
26
27
  export type { TransactionListQuery, TransactionsClient } from './api/TransactionsClient';
28
+ export type { ContractExecutionsClient } from './api/ContractExecutionsClient';
27
29
  export type { TransferListQuery, TransfersClient } from './api/TransfersClient';
28
30
  export type { WithdrawalListQuery, WithdrawalsClient } from './api/WithdrawalsClient';
29
31
  export type { FiatAccountsClient } from './api/FiatAccountsClient';
30
32
  export type { PublicAccountId, WireFiatAccountListQuery, WireFiatAccountsClient, WireInstructionQuery, } from './api/WireFiatAccountsClient';
31
33
  export type { AchFiatAccountListQuery, AchFiatAccountsClient } from './api/AchFiatAccountsClient';
32
34
  export type { DaaUserClient } from './api/DaaUserClient';
35
+ export type { ApproveDeviceArgs } from './api/deviceApproval';
33
36
  export type { DaaUserContext, DeviceContext, DeviceRegistrationResult, } from './models/DaaUserContext';
34
- export type { PendingDeviceRegistration } from './models/PendingDeviceRegistration';
37
+ export type { DeviceApprovalHint, DeviceRegistrationRiskSignals, PendingDeviceRegistration, } from './models/PendingDeviceRegistration';
38
+ export type { DeviceStatus } from './models/DeviceStatus';
39
+ export type { PendingDeviceApproval } from './models/PendingDeviceApproval';
35
40
  export type { Account, AccountPurpose, AccountRendering, AccountStatus, AccountType, CustodyType, } from './models/Account';
36
41
  export type { CreateAccountRequest } from './models/CreateAccountRequest';
37
42
  export type { AccountLimitsUsage, AccountLimitsUsageItem, AccountLimitsUsageRendering, AccountLimitsUsageResourceType, LimitsUsageAssetType, LimitsUsageComparisonType, LimitsUsageOperation, LimitsUsageUnit, LimitsUsageWindow, } from './models/AccountLimitsUsage';
38
43
  export type { CreateTransferAmount, CreateTransferDestination, CreateTransferRequest, CreateTransferRiskSignals, CreateTransferSource, } from './models/CreateTransferRequest';
44
+ export type { ContractExecutionBlockchain, CreateContractExecutionAbiRequest, CreateContractExecutionRawRequest, CreateContractExecutionRequest, } from './models/CreateContractExecutionRequest';
45
+ export type { PersistedContractExecution, PreparedContractExecution, PreparedContractExecutionRendering, } from './models/PreparedContractExecution';
46
+ export type { AbiParameter, ContractExecution, ContractExecutionErrorCode, ContractExecutionInvocation, ContractExecutionRendering, ContractExecutionSource, ContractExecutionStatus, } from './models/ContractExecution';
39
47
  export type { Address, BusinessPii } from './models/BusinessPii';
40
48
  export type { AddressObject, AddressObjectRendering } from './models/AddressObject';
41
49
  export type { DepositAddressChain, GenerateAddressRequest } from './models/GenerateAddressRequest';
@@ -44,7 +52,7 @@ export type { DepositSummary, DepositSummaryRendering } from './models/DepositSu
44
52
  export type { Money } from './models/Money';
45
53
  export type { Page } from './models/Page';
46
54
  export type { PreparedSocialLogin } from './models/PreparedSocialLogin';
47
- export type { Transaction, TransactionAccountLocation, TransactionBlockchainLocation, TransactionBlockchainLocationRendering, TransactionFiatLocation, TransactionLocation, TransactionRendering, TransactionStatus, TransactionType, } from './models/Transaction';
55
+ export type { Transaction, TransactionAccountLocation, TransactionBlockchainLocation, TransactionBlockchainLocationRendering, TransactionContractExecution, TransactionContractExecutionRendering, TransactionFiatLocation, TransactionLocation, TransactionRendering, TransactionStatus, TransactionType, } from './models/Transaction';
48
56
  export type { Fee, Transfer, TransferDestinationAccountLocation, TransferDestinationAccountLocationRendering, TransferDestinationBlockchainLocation, TransferDestinationBlockchainLocationRendering, TransferDestinationLocation, TransferErrorCode, TransferPolicyEvaluation, TransferRendering, TransferSourceLocation, TransferStatus, } from './models/Transfer';
49
57
  export type { WithdrawalAdjustments, WithdrawalDestination, WithdrawalDestinationType, WithdrawalDetail, WithdrawalDetailRendering, WithdrawalErrorCode, WithdrawalPolicyEvaluation, WithdrawalReturn, WithdrawalRiskEvaluation, WithdrawalStatus, WithdrawalSubAccountSweep, WithdrawalSweepStatus, WithdrawalToAmount, } from './models/Withdrawal';
50
58
  export type { CreateWithdrawalAmount, CreateWithdrawalDestination, CreateWithdrawalRequest, CreateWithdrawalRiskSignals, CreateWithdrawalSource, CreateWithdrawalToAmount, } from './models/CreateWithdrawalRequest';
@@ -56,6 +64,6 @@ export type { DaaEnvironment, DaaSdkConfiguration, DeviceKeyPolicy } from './con
56
64
  export type { DaaHttpRequest, DaaHttpResponse, DaaTransport } from './transport/DaaTransport';
57
65
  export type { DaaSdkError } from './errors';
58
66
  export { DaaError, isDaaError } from './errors';
59
- export type { AuthKeyResolution, OwnerAuthKey, OwnerKeyIdentity, SecureKeyStore, } from './securekey/SecureKey';
67
+ export type { AuthKeyRegistration, AuthKeyResolution, DeviceApprovalCheck, DeviceApprovalSigning, OwnerAuthKey, OwnerKeyIdentity, RegisteredOwnerAuthKey, SecureKeyStore, } from './securekey/SecureKey';
60
68
  export { serializeBody, serializeEmptyBody } from './crypto/serialization';
61
69
  export { toBase64Url, fromBase64Url } from './crypto/base64url';
@@ -0,0 +1,197 @@
1
+ /**
2
+ * Copyright (c) 2026, Circle Internet Group, Inc. All rights reserved.
3
+ *
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+ import type { Money } from './Money';
19
+ /**
20
+ * Where an execution is in its lifecycle.
21
+ *
22
+ * `pending` covers every state before a final provider result, including a
23
+ * submission whose outcome is still being recovered: a timeout is not a
24
+ * failure. Poll {@link ContractExecutionsClient.get} until `complete` or
25
+ * `failed`.
26
+ */
27
+ export type ContractExecutionStatus = {
28
+ readonly kind: 'pending';
29
+ }
30
+ /** Terminal: the provider reported final success. */
31
+ | {
32
+ readonly kind: 'complete';
33
+ }
34
+ /** Terminal: see {@link ContractExecutionErrorCode}. */
35
+ | {
36
+ readonly kind: 'failed';
37
+ } | {
38
+ readonly kind: 'unrecognized';
39
+ readonly rawValue: string | null;
40
+ };
41
+ /**
42
+ * Why an execution failed, present only when the status is `failed`.
43
+ *
44
+ * - `authorization_failed`: DAA rejected the Owner proof before the
45
+ * call was signed. No hash or fee.
46
+ * - `execution_denied`: the Owner proof was valid but execution or fee policy
47
+ * denied the call. No hash or fee.
48
+ * - `insufficient_funds`: the account could not fund the native `amount`.
49
+ * - `insufficient_network_fee`: the provider could not fund the network fee.
50
+ * - `blockchain_error`: the call was included and reverted. The hash and the
51
+ * fee it cost are retained.
52
+ * - `contract_execution_failed`: any other definitive failure.
53
+ *
54
+ * An open set, like every other closed set here: a code this SDK has not
55
+ * shipped for reads as `unrecognized`, not as a failed decode.
56
+ */
57
+ export type ContractExecutionErrorCode = {
58
+ readonly kind: 'authorization_failed';
59
+ } | {
60
+ readonly kind: 'execution_denied';
61
+ } | {
62
+ readonly kind: 'insufficient_funds';
63
+ } | {
64
+ readonly kind: 'insufficient_network_fee';
65
+ } | {
66
+ readonly kind: 'blockchain_error';
67
+ } | {
68
+ readonly kind: 'contract_execution_failed';
69
+ } | {
70
+ readonly kind: 'unrecognized';
71
+ readonly rawValue: string | null;
72
+ };
73
+ /** The executing account. */
74
+ export type ContractExecutionSource = {
75
+ readonly kind: 'account';
76
+ /** Named `accountId` (the wire spells it `id`) so it is not confused with the execution's own `id`. */
77
+ readonly accountId: string;
78
+ } | {
79
+ readonly kind: 'unrecognized';
80
+ readonly rawValue: string | null;
81
+ };
82
+ /**
83
+ * One ABI input value: a string, a boolean, a safe integer, or an array of
84
+ * those.
85
+ *
86
+ * Integers that do not fit in a JavaScript safe integer — most `uint256`
87
+ * values — are decimal **strings**. A JSON number outside
88
+ * `Number.MIN_SAFE_INTEGER..Number.MAX_SAFE_INTEGER` is refused in either
89
+ * direction, because `JSON.parse` and `JSON.stringify` round it before any
90
+ * code here can see it, and the rounded value is not the one the Owner
91
+ * authorized. An integer-looking string stays a string; the SDK never
92
+ * converts between the two.
93
+ */
94
+ export type AbiParameter = string | number | boolean | readonly AbiParameter[];
95
+ /**
96
+ * The accepted invocation, in the mode it was requested in. DAA never converts
97
+ * one mode to the other and never returns encoded call data for an ABI request.
98
+ */
99
+ export type ContractExecutionInvocation = {
100
+ readonly kind: 'raw';
101
+ readonly callData: string;
102
+ } | {
103
+ readonly kind: 'abi';
104
+ readonly abiFunctionSignature: string;
105
+ readonly abiParameters: readonly AbiParameter[];
106
+ };
107
+ /** The redacted shape `JSON.stringify(execution)` produces. */
108
+ export type ContractExecutionRendering = {
109
+ readonly id: string;
110
+ readonly status: ContractExecutionStatus;
111
+ readonly errorCode: ContractExecutionErrorCode | null;
112
+ readonly source: ContractExecutionSource;
113
+ readonly custodyType: string;
114
+ readonly blockchain: string;
115
+ readonly contractAddress: string;
116
+ readonly invocation: {
117
+ readonly kind: 'raw' | 'abi';
118
+ readonly inputs: string;
119
+ };
120
+ readonly amount: {
121
+ readonly amount: string;
122
+ readonly currency: string;
123
+ };
124
+ readonly networkFee: {
125
+ readonly amount: string;
126
+ readonly currency: string;
127
+ } | null;
128
+ readonly transactionHash: string | null;
129
+ readonly createDate: string;
130
+ readonly updateDate: string;
131
+ };
132
+ /**
133
+ * A DAA contract execution.
134
+ *
135
+ * **Guaranteed fields** are `id`, `status`, `source`, `custodyType`,
136
+ * `blockchain`, `contractAddress`, the invocation, `amount`, `createDate`, and
137
+ * `updateDate`. `amount` is the native value attached to the call — zero when
138
+ * the request omitted it — and on a failed execution it describes what was
139
+ * requested, not what moved. `transactionHash` and `networkFee` are present
140
+ * once known, including for a reverted call; `networkFee` is the actual chain
141
+ * cost, not what the customer is billed. `errorCode` is present only when the
142
+ * status is `failed`.
143
+ *
144
+ * `blockchain` and `custodyType` are plain strings on a read, for the reason
145
+ * `Account.blockchain` is: a later service value must not make the execution
146
+ * unreadable. `blockchain` is the service's chain name exactly as sent, which
147
+ * need not be the request's spelling of the same chain (Base is `CBASE` in a
148
+ * request); compare chains through the account, not by string.
149
+ *
150
+ * **No default rendering prints the call.** `contractAddress`, the invocation,
151
+ * `transactionHash`, and both amounts sit behind prototype accessors; `toJSON`
152
+ * and `toString` report only identifiers, states, and the invocation mode.
153
+ *
154
+ * Not constructible by a consumer: exported from `index.ts` as a type only, and
155
+ * the `#` private fields make the type nominal.
156
+ */
157
+ export declare class ContractExecution {
158
+ #private;
159
+ readonly id: string;
160
+ readonly status: ContractExecutionStatus;
161
+ readonly errorCode: ContractExecutionErrorCode | null;
162
+ readonly source: ContractExecutionSource;
163
+ readonly custodyType: string;
164
+ readonly blockchain: string;
165
+ readonly createDate: string;
166
+ readonly updateDate: string;
167
+ /** @internal Constructed only by the SDK's response decoder. */
168
+ constructor(fields: {
169
+ readonly id: string;
170
+ readonly status: ContractExecutionStatus;
171
+ readonly errorCode: ContractExecutionErrorCode | null;
172
+ readonly source: ContractExecutionSource;
173
+ readonly custodyType: string;
174
+ readonly blockchain: string;
175
+ readonly contractAddress: string;
176
+ readonly invocation: ContractExecutionInvocation;
177
+ readonly amount: Money;
178
+ readonly networkFee: Money | null;
179
+ readonly transactionHash: string | null;
180
+ readonly createDate: string;
181
+ readonly updateDate: string;
182
+ });
183
+ /** The target contract address, exactly as the service sent it. */
184
+ get contractAddress(): string;
185
+ /** The accepted invocation. Deeply frozen. */
186
+ get invocation(): ContractExecutionInvocation;
187
+ /** Native value attached to the call; zero when the request omitted it. */
188
+ get amount(): Money;
189
+ /** Actual network cost once known, including for a reverted call; otherwise `null`. */
190
+ get networkFee(): Money | null;
191
+ /** On-chain transaction hash once known, including for a reverted call; otherwise `null`. */
192
+ get transactionHash(): string | null;
193
+ /** Identifiers, states, and the invocation mode render; the call itself does not. */
194
+ toJSON(): ContractExecutionRendering;
195
+ /** Identifiers, states, and the invocation mode print; the call itself does not. */
196
+ toString(): string;
197
+ }