@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
@@ -17,14 +17,16 @@
17
17
  */
18
18
  import type { DeviceContext } from '../models/DaaUserContext';
19
19
  /**
20
- * Decode the wire `DeviceContext`: the shape Device Registration
21
- * Complete's `context` carries and `get_device_context`
22
- * (`GET /v1/accounts/auth/context`, `DaaUserClient.refreshContext`) returns.
20
+ * Decode the wire `DeviceContext`: the shape `get_device_context`
21
+ * (`GET /v1/accounts/auth/context`, `DaaUserClient.refreshContext`) returns,
22
+ * and the shape Device Registration Complete's `KeyCredential` is renamed to
23
+ * (`wire/deviceRegistrationResultPayload.ts`).
23
24
  *
24
- * One decoder for both, rather than two copies: they are the same
25
- * `DeviceContext` response type, so a divergence between "the shape Complete
26
- * returns" and "the shape refresh returns" would be a service defect, not
27
- * something two independent decoders should each get to interpret.
25
+ * One decoder for both, rather than two copies: DAA builds the
26
+ * `KeyCredential` from the same `DeviceContext`, so a divergence between "the
27
+ * shape Complete returns" and "the shape refresh returns" would be a service
28
+ * defect, not something two independent decoders should each get to
29
+ * interpret.
28
30
  *
29
31
  * `DeviceContext.resolvedAt` is one of the timestamps the service sends in its
30
32
  * default number form, the same as `PreparedSocialLogin.expiresAt`, so the
@@ -29,14 +29,16 @@ function requiredUuidField(payload, name) {
29
29
  return value;
30
30
  }
31
31
  /**
32
- * Decode the wire `DeviceContext`: the shape Device Registration
33
- * Complete's `context` carries and `get_device_context`
34
- * (`GET /v1/accounts/auth/context`, `DaaUserClient.refreshContext`) returns.
32
+ * Decode the wire `DeviceContext`: the shape `get_device_context`
33
+ * (`GET /v1/accounts/auth/context`, `DaaUserClient.refreshContext`) returns,
34
+ * and the shape Device Registration Complete's `KeyCredential` is renamed to
35
+ * (`wire/deviceRegistrationResultPayload.ts`).
35
36
  *
36
- * One decoder for both, rather than two copies: they are the same
37
- * `DeviceContext` response type, so a divergence between "the shape Complete
38
- * returns" and "the shape refresh returns" would be a service defect, not
39
- * something two independent decoders should each get to interpret.
37
+ * One decoder for both, rather than two copies: DAA builds the
38
+ * `KeyCredential` from the same `DeviceContext`, so a divergence between "the
39
+ * shape Complete returns" and "the shape refresh returns" would be a service
40
+ * defect, not something two independent decoders should each get to
41
+ * interpret.
40
42
  *
41
43
  * `DeviceContext.resolvedAt` is one of the timestamps the service sends in its
42
44
  * default number form, the same as `PreparedSocialLogin.expiresAt`, so the
@@ -17,16 +17,61 @@
17
17
  */
18
18
  import { type DeviceRegistrationResult } from '../models/DaaUserContext';
19
19
  /**
20
- * Map Complete's `data` payload.
20
+ * A `pending_approval` registration as DAA sends it. `PendingDeviceRegistration`
21
+ * adds the local code secret and AuthKey thumbprint to make the public
22
+ * `PendingDeviceApproval`.
23
+ */
24
+ export type PendingApprovalPayload = Readonly<{
25
+ status: 'PENDING_APPROVAL';
26
+ requestId: string;
27
+ authKeyId: string;
28
+ expiresAt: string;
29
+ codeNonce: string;
30
+ /** The request's stored seal, or `null` from a DAA that doesn't send it. */
31
+ codeSeal: string | null;
32
+ }>;
33
+ /**
34
+ * A `pending_activation` registration as DAA sends it: a device approved from
35
+ * another device, signing in again during the account's cool-down.
36
+ * `PendingDeviceRegistration` acknowledges the key with `ownerBindingId`,
37
+ * which the public result leaves out.
38
+ */
39
+ export type PendingActivationPayload = Readonly<{
40
+ status: 'PENDING_ACTIVATION';
41
+ authKeyId: string;
42
+ ownerBindingId: string;
43
+ readyAt: string;
44
+ }>;
45
+ /**
46
+ * Complete's decoded payload, before the pending variants get their local state.
47
+ * `/v1/accounts/auth/keys` never returns `RECOVERY_PENDING`, so this decoder
48
+ * never produces it, although the public `DeviceRegistrationResult` keeps it.
49
+ */
50
+ export type DecodedDeviceRegistration = Extract<DeviceRegistrationResult, {
51
+ status: 'ACTIVE';
52
+ }> | PendingApprovalPayload | PendingActivationPayload;
53
+ /**
54
+ * Map Complete's `data` payload: the `KeyCredential` that
55
+ * `POST /v1/accounts/auth/keys` returns for `"type": "deviceKey"`.
56
+ *
57
+ * DAA builds a `KeyCredential` from the same `DeviceContext` that
58
+ * `get_device_context` returns, with names that fit both key types. For a
59
+ * device key, `credentialStatus` is the `deviceCredentialStatus` and
60
+ * `credentialId` is the `authKeyId` (the `kid` that later
61
+ * `X-Device-Authorization` requests sign with). Every other member keeps its
62
+ * name. So the payload is checked for `type: "deviceKey"`, those two members
63
+ * are renamed, and the result is decoded as a `DeviceContext`:
64
+ *
65
+ * - `active` is `ACTIVE` (`toDeviceContext`), a first device or a key the
66
+ * account already holds;
67
+ * - `pending_approval` is a new device on an account that already has one (see
68
+ * `toPendingApproval`);
69
+ * - `pending_activation` is an approved device signing in again during its
70
+ * cool-down (see `toPendingActivation`);
71
+ * - any other status, or a missing one, fails closed, as does a malformed
72
+ * UUID or timestamp.
21
73
  *
22
- * The service returns a flat `DeviceContext`. The wrapped `{ status, context }`
23
- * shape and `RECOVERY_PENDING` are also decoded when present. An absent
24
- * `status` is read as that flat shape only on a positive signal: it still needs
25
- * `deviceCredentialStatus === 'active'` (enforced by `toDeviceContext`), and
26
- * it must carry neither `recoveryReference` nor `expiresAt` — the fields that
27
- * belong to the `RECOVERY_PENDING` shape. A payload carrying either alongside
28
- * an absent `status` is ambiguous and is rejected rather than resolved toward
29
- * the more privileged `ACTIVE` outcome. Extra members are otherwise ignored.
74
+ * Any other `type` is refused. Extra members are otherwise ignored.
30
75
  * `clientEntityId` comes from Social Session, not this payload.
31
76
  */
32
- export declare function toDeviceRegistrationResult(value: unknown, sessionClientEntityId: string): DeviceRegistrationResult;
77
+ export declare function toDeviceRegistrationResult(value: unknown, sessionClientEntityId: string): DecodedDeviceRegistration;
@@ -19,110 +19,144 @@
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
20
  exports.toDeviceRegistrationResult = toDeviceRegistrationResult;
21
21
  const DaaUserContext_1 = require("../models/DaaUserContext");
22
+ const matchingCode_1 = require("../crypto/matchingCode");
23
+ const uuid_1 = require("../validation/uuid");
22
24
  const deviceContextPayload_1 = require("./deviceContextPayload");
23
25
  const instant_1 = require("./instant");
24
26
  const payload_1 = require("./payload");
25
- const RECOVERY_REF_MIN = 16;
26
- const RECOVERY_REF_MAX = 512;
27
- function toActiveContext(payload, sessionClientEntityId) {
28
- return new DaaUserContext_1.DaaUserContext(DaaUserContext_1.DECODER_TOKEN, {
29
- clientEntityId: sessionClientEntityId,
30
- deviceContext: (0, deviceContextPayload_1.toDeviceContext)(payload),
31
- });
32
- }
27
+ /** The only `type` a device key registration may echo. */
28
+ const DEVICE_KEY_TYPE = 'deviceKey';
33
29
  /**
34
- * The DeviceContext-shaped object Complete returns: a flat payload, or
35
- * nested `context.deviceContext` / `context` when `status: "ACTIVE"`.
30
+ * The `KeyCredential` members that `DeviceContext` names differently, by their
31
+ * `DeviceContext` name. A decoder error names the `KeyCredential` member.
36
32
  */
37
- function deviceContextPayloadFromComplete(payload) {
38
- if ((0, payload_1.optionalString)(payload, 'status') !== 'ACTIVE') {
39
- return payload;
40
- }
41
- const contextPayload = (0, payload_1.optionalObject)(payload, 'context');
42
- if (contextPayload === null) {
43
- throw new payload_1.MalformedPayloadError('context');
44
- }
45
- return (0, payload_1.optionalObject)(contextPayload, 'deviceContext') ?? contextPayload;
46
- }
33
+ const KEY_CREDENTIAL_NAMES = Object.freeze({
34
+ deviceCredentialStatus: 'credentialStatus',
35
+ authKeyId: 'credentialId',
36
+ });
47
37
  /**
48
- * Map Complete's `data` payload.
38
+ * Map Complete's `data` payload: the `KeyCredential` that
39
+ * `POST /v1/accounts/auth/keys` returns for `"type": "deviceKey"`.
40
+ *
41
+ * DAA builds a `KeyCredential` from the same `DeviceContext` that
42
+ * `get_device_context` returns, with names that fit both key types. For a
43
+ * device key, `credentialStatus` is the `deviceCredentialStatus` and
44
+ * `credentialId` is the `authKeyId` (the `kid` that later
45
+ * `X-Device-Authorization` requests sign with). Every other member keeps its
46
+ * name. So the payload is checked for `type: "deviceKey"`, those two members
47
+ * are renamed, and the result is decoded as a `DeviceContext`:
49
48
  *
50
- * The service returns a flat `DeviceContext`. The wrapped `{ status, context }`
51
- * shape and `RECOVERY_PENDING` are also decoded when present. An absent
52
- * `status` is read as that flat shape only on a positive signal: it still needs
53
- * `deviceCredentialStatus === 'active'` (enforced by `toDeviceContext`), and
54
- * it must carry neither `recoveryReference` nor `expiresAt` — the fields that
55
- * belong to the `RECOVERY_PENDING` shape. A payload carrying either alongside
56
- * an absent `status` is ambiguous and is rejected rather than resolved toward
57
- * the more privileged `ACTIVE` outcome. Extra members are otherwise ignored.
49
+ * - `active` is `ACTIVE` (`toDeviceContext`), a first device or a key the
50
+ * account already holds;
51
+ * - `pending_approval` is a new device on an account that already has one (see
52
+ * `toPendingApproval`);
53
+ * - `pending_activation` is an approved device signing in again during its
54
+ * cool-down (see `toPendingActivation`);
55
+ * - any other status, or a missing one, fails closed, as does a malformed
56
+ * UUID or timestamp.
57
+ *
58
+ * Any other `type` is refused. Extra members are otherwise ignored.
58
59
  * `clientEntityId` comes from Social Session, not this payload.
59
60
  */
60
61
  function toDeviceRegistrationResult(value, sessionClientEntityId) {
61
- const payload = (0, payload_1.asObject)(value, 'payload');
62
- const status = (0, payload_1.optionalString)(payload, 'status');
63
- if (status === 'RECOVERY_PENDING') {
64
- if ((0, payload_1.optionalObject)(payload, 'context') !== null) {
65
- throw new payload_1.MalformedPayloadError('context');
62
+ const payload = deviceContextFromKeyCredential((0, payload_1.asObject)(value, 'payload'));
63
+ try {
64
+ const credentialStatus = (0, payload_1.optionalString)(payload, 'deviceCredentialStatus');
65
+ if (credentialStatus === 'pending_approval') {
66
+ return toPendingApproval(payload);
66
67
  }
67
- const recoveryReference = (0, payload_1.requiredString)(payload, 'recoveryReference');
68
- if (recoveryReference.length < RECOVERY_REF_MIN ||
69
- recoveryReference.length > RECOVERY_REF_MAX) {
70
- throw new payload_1.MalformedPayloadError('recoveryReference');
68
+ if (credentialStatus === 'pending_activation') {
69
+ return toPendingActivation(payload);
71
70
  }
72
- const result = Object.freeze({
73
- status: 'RECOVERY_PENDING',
74
- recoveryReference,
75
- // `expiresAt` accepts both timestamp forms, like the other login-flow
76
- // timestamps on this response.
77
- expiresAt: (0, instant_1.requiredDateTime)(payload, 'expiresAt'),
78
- });
79
- return result;
80
- }
81
- if (status === 'ACTIVE') {
82
- const contextPayload = (0, payload_1.optionalObject)(payload, 'context');
83
- if (contextPayload === null) {
84
- throw new payload_1.MalformedPayloadError('context');
85
- }
86
- const nestedClient = (0, payload_1.optionalString)(contextPayload, 'clientEntityId');
87
- if (nestedClient !== null && nestedClient !== sessionClientEntityId) {
88
- throw new payload_1.MalformedPayloadError('clientEntityId');
89
- }
90
- const devicePayload = deviceContextPayloadFromComplete(payload);
91
71
  const result = Object.freeze({
92
72
  status: 'ACTIVE',
93
73
  context: new DaaUserContext_1.DaaUserContext(DaaUserContext_1.DECODER_TOKEN, {
94
74
  clientEntityId: sessionClientEntityId,
95
- deviceContext: (0, deviceContextPayload_1.toDeviceContext)(devicePayload),
75
+ deviceContext: (0, deviceContextPayload_1.toDeviceContext)(payload),
96
76
  }),
97
77
  });
98
78
  return result;
99
79
  }
100
- if (status !== null) {
101
- throw new payload_1.MalformedPayloadError('status');
80
+ catch (error) {
81
+ if (error instanceof payload_1.MalformedPayloadError) {
82
+ throw new payload_1.MalformedPayloadError(KEY_CREDENTIAL_NAMES[error.fieldName] ?? error.fieldName);
83
+ }
84
+ throw error;
102
85
  }
103
- // Flat shape: only decodable on a positive ACTIVE signal, never on
104
- // the mere absence of `status`. `toActiveContext` still requires
105
- // `deviceCredentialStatus === 'active'`; this additionally refuses a
106
- // payload that also carries a `RECOVERY_PENDING` field, rather than
107
- // silently preferring the more privileged outcome. The error names
108
- // whichever `RECOVERY_PENDING` field is actually present — `status` itself
109
- // is absent here, not malformed.
110
- const conflictingRecoveryField = hasPresentField(payload, 'recoveryReference')
111
- ? 'recoveryReference'
112
- : hasPresentField(payload, 'expiresAt')
113
- ? 'expiresAt'
114
- : null;
115
- if (conflictingRecoveryField !== null) {
116
- throw new payload_1.MalformedPayloadError(conflictingRecoveryField);
86
+ }
87
+ /**
88
+ * The `KeyCredential` as a flat `DeviceContext`: `credentialStatus` becomes
89
+ * `deviceCredentialStatus` and `credentialId` becomes `authKeyId`; every other
90
+ * member is kept as it is.
91
+ */
92
+ function deviceContextFromKeyCredential(payload) {
93
+ if ((0, payload_1.requiredString)(payload, 'type') !== DEVICE_KEY_TYPE) {
94
+ throw new payload_1.MalformedPayloadError('type');
95
+ }
96
+ const deviceContext = { ...payload };
97
+ delete deviceContext.type;
98
+ delete deviceContext.credentialStatus;
99
+ delete deviceContext.credentialId;
100
+ deviceContext.deviceCredentialStatus = payload.credentialStatus;
101
+ deviceContext.authKeyId = payload.credentialId;
102
+ return deviceContext;
103
+ }
104
+ /**
105
+ * The `DeviceContext` DAA returns for a new device on an account that
106
+ * already has one: `deviceCredentialStatus: "pending_approval"` with the
107
+ * request's `requestId`, `expiresAt` and the enclave's `codeNonce` (32 bytes,
108
+ * canonical unpadded Base64URL, so `PendingDeviceApproval` can decode it).
109
+ * `codeSeal`, when present, is the seal the request was created with (32
110
+ * bytes, the same encoding): for a key that was already waiting it is the one
111
+ * from its first registration, not this body's. A DAA that doesn't send it
112
+ * yet decodes as `null`. `ownerBindingId` and `resolvedAt` are not read:
113
+ * nothing here signs until the request is approved.
114
+ */
115
+ function toPendingApproval(payload) {
116
+ const codeNonce = (0, payload_1.requiredString)(payload, 'codeNonce');
117
+ if ((0, matchingCode_1.canonicalBytes32)(codeNonce) === null) {
118
+ throw new payload_1.MalformedPayloadError('codeNonce');
119
+ }
120
+ const codeSeal = (0, payload_1.optionalString)(payload, 'codeSeal');
121
+ if (codeSeal !== null && (0, matchingCode_1.canonicalBytes32)(codeSeal) === null) {
122
+ throw new payload_1.MalformedPayloadError('codeSeal');
117
123
  }
118
- const result = Object.freeze({
119
- status: 'ACTIVE',
120
- context: toActiveContext(payload, sessionClientEntityId),
124
+ return Object.freeze({
125
+ status: 'PENDING_APPROVAL',
126
+ requestId: requiredUuid(payload, 'requestId'),
127
+ authKeyId: requiredUuid(payload, 'authKeyId'),
128
+ expiresAt: (0, instant_1.requiredDateTime)(payload, 'expiresAt'),
129
+ codeNonce,
130
+ codeSeal,
121
131
  });
122
- return result;
123
132
  }
124
- /** JSON `null` is treated as absence, matching `optionalString`/`optionalObject`. */
125
- function hasPresentField(payload, name) {
126
- const value = payload[name];
127
- return value !== undefined && value !== null;
133
+ /**
134
+ * The `DeviceContext` DAA returns for a device an existing device already
135
+ * approved, signing in again before the account's cool-down ends:
136
+ * `deviceCredentialStatus: "pending_activation"` with `readyAt`, when the key
137
+ * may sign. The key is the account's, so `ownerBindingId` and `authKeyId` are
138
+ * final. The `pending_approval` fields (`requestId`, `expiresAt`, `codeNonce`,
139
+ * `codeSeal`) make the payload ambiguous, so a payload carrying any of them is
140
+ * refused. `resolvedAt` is not read.
141
+ */
142
+ function toPendingActivation(payload) {
143
+ for (const name of ['requestId', 'expiresAt', 'codeNonce', 'codeSeal']) {
144
+ const value = payload[name];
145
+ if (value !== undefined && value !== null) {
146
+ throw new payload_1.MalformedPayloadError(name);
147
+ }
148
+ }
149
+ return Object.freeze({
150
+ status: 'PENDING_ACTIVATION',
151
+ authKeyId: requiredUuid(payload, 'authKeyId'),
152
+ ownerBindingId: requiredUuid(payload, 'ownerBindingId'),
153
+ readyAt: (0, instant_1.requiredDateTime)(payload, 'readyAt'),
154
+ });
155
+ }
156
+ function requiredUuid(payload, name) {
157
+ const value = (0, payload_1.requiredString)(payload, name);
158
+ if (!(0, uuid_1.isUuid)(value)) {
159
+ throw new payload_1.MalformedPayloadError(name);
160
+ }
161
+ return value;
128
162
  }
@@ -0,0 +1,20 @@
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 { DeviceStatus } from '../models/DeviceStatus';
19
+ /** Decode the status route's `data`. An unknown `status` is kept as `unrecognized`. */
20
+ export declare function toDeviceStatus(value: unknown): DeviceStatus;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) 2026, Circle Internet Group, Inc. All rights reserved.
4
+ *
5
+ * SPDX-License-Identifier: Apache-2.0
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.toDeviceStatus = toDeviceStatus;
21
+ const uuid_1 = require("../validation/uuid");
22
+ const instant_1 = require("./instant");
23
+ const payload_1 = require("./payload");
24
+ /** Decode the status route's `data`. An unknown `status` is kept as `unrecognized`. */
25
+ function toDeviceStatus(value) {
26
+ const payload = (0, payload_1.asObject)(value, 'payload');
27
+ const authKeyId = requiredUuid(payload, 'authKeyId');
28
+ const status = (0, payload_1.requiredString)(payload, 'status');
29
+ switch (status) {
30
+ case 'pending_approval':
31
+ case 'expired':
32
+ return Object.freeze({
33
+ status,
34
+ authKeyId,
35
+ requestId: requiredUuid(payload, 'requestId'),
36
+ expiresAt: (0, instant_1.requiredDateTime)(payload, 'expiresAt'),
37
+ });
38
+ case 'denied':
39
+ case 'cancelled':
40
+ return Object.freeze({ status, authKeyId, requestId: requiredUuid(payload, 'requestId') });
41
+ case 'pending_activation':
42
+ return Object.freeze({
43
+ status,
44
+ authKeyId,
45
+ ...optionalRequestId(payload),
46
+ readyAt: (0, instant_1.requiredDateTime)(payload, 'readyAt'),
47
+ });
48
+ case 'active':
49
+ return Object.freeze({ status, authKeyId, ...optionalRequestId(payload) });
50
+ default:
51
+ // Preserved, not refused: DAA may add a status before this SDK knows it.
52
+ return Object.freeze({ status: 'unrecognized', authKeyId, rawValue: status });
53
+ }
54
+ }
55
+ function optionalRequestId(payload) {
56
+ return (0, payload_1.optionalString)(payload, 'requestId') === null
57
+ ? {}
58
+ : { requestId: requiredUuid(payload, 'requestId') };
59
+ }
60
+ function requiredUuid(payload, name) {
61
+ const value = (0, payload_1.requiredString)(payload, name);
62
+ if (!(0, uuid_1.isUuid)(value)) {
63
+ throw new payload_1.MalformedPayloadError(name);
64
+ }
65
+ return value;
66
+ }
@@ -36,7 +36,10 @@ const payload_1 = require("./payload");
36
36
  //
37
37
  // The three fields are `PreparedSocialLogin.expiresAt`,
38
38
  // `SocialSession.expiresAt` and `DeviceContext.resolvedAt`. They are the same
39
- // kind of field, serialised the same way, so all three accept both forms.
39
+ // kind of field, serialised the same way, so all three accept both forms. The
40
+ // device context's other timestamps (`expiresAt` on `pending_approval`,
41
+ // `readyAt` on `pending_activation`) come in the same response and accept both
42
+ // forms too.
40
43
  /**
41
44
  * The ISO-8601 form the contract declares for an `Instant`, with a `T`
42
45
  * separator. The service does not always send this form — see `requiredDateTime`
@@ -27,6 +27,22 @@ export type PendingRegistrationPayload = Readonly<{
27
27
  * the response does not carry it.
28
28
  */
29
29
  ownerGrant: string | null;
30
+ /** `SocialSession.deviceApproval`, or null when the service doesn't send it. */
31
+ deviceApproval: DeviceApprovalHint | null;
32
+ }>;
33
+ /**
34
+ * DAA's answer, when the Session was answered, to whether a new device key for
35
+ * this end user would wait for approval from an existing device. A hint for
36
+ * asking the user first, not the outcome: the registration response decides.
37
+ *
38
+ * - `required`: device approval is on and the end user already has an account,
39
+ * so a new device key would wait for approval.
40
+ * - `hasActiveDevice`: the account had a device that can approve. Always
41
+ * `false` when `required` is `false`.
42
+ */
43
+ export type DeviceApprovalHint = Readonly<{
44
+ required: boolean;
45
+ hasActiveDevice: boolean;
30
46
  }>;
31
47
  /** Map the `SocialSession` body onto the fields the SDK keeps. */
32
48
  export declare function toPendingRegistration(value: unknown): PendingRegistrationPayload;
@@ -24,6 +24,23 @@ const payload_1 = require("./payload");
24
24
  /** The service caps `SocialSession.registrationHandle` at 200 characters. */
25
25
  const HANDLE_MIN = 1;
26
26
  const HANDLE_MAX = 200;
27
+ function requiredBoolean(payload, name, label) {
28
+ const value = payload[name];
29
+ if (typeof value !== 'boolean') {
30
+ throw new payload_1.MalformedPayloadError(label);
31
+ }
32
+ return value;
33
+ }
34
+ function optionalDeviceApproval(payload) {
35
+ const value = (0, payload_1.optionalObject)(payload, 'deviceApproval');
36
+ if (value === null) {
37
+ return null;
38
+ }
39
+ return Object.freeze({
40
+ required: requiredBoolean(value, 'required', 'deviceApproval.required'),
41
+ hasActiveDevice: requiredBoolean(value, 'hasActiveDevice', 'deviceApproval.hasActiveDevice'),
42
+ });
43
+ }
27
44
  function requiredBounded(payload, name, min, max) {
28
45
  const value = (0, payload_1.requiredString)(payload, name);
29
46
  if (value.length < min || value.length > max) {
@@ -50,5 +67,6 @@ function toPendingRegistration(value) {
50
67
  // is accepted here.
51
68
  expiresAt: (0, instant_1.requiredDateTime)(payload, 'expiresAt'),
52
69
  ownerGrant,
70
+ deviceApproval: optionalDeviceApproval(payload),
53
71
  };
54
72
  }
@@ -21,11 +21,6 @@ export type SocialLoginRequestPayload = Readonly<{
21
21
  oidcState: string;
22
22
  /** ISO-8601, normalised when the service sends epoch milliseconds instead. */
23
23
  expiresAt: string;
24
- /**
25
- * The raw `prepareReceiptJws` member, unvalidated: `null` when absent. Only
26
- * `checkPrepareReceipt` reads it.
27
- */
28
- prepareReceiptJws: unknown;
29
24
  }>;
30
25
  /** Map a Prepare success payload onto the fields the SDK keeps. */
31
26
  export declare function toSocialLoginRequest(value: unknown): SocialLoginRequestPayload;
@@ -23,17 +23,8 @@ const instant_1 = require("./instant");
23
23
  const payload_1 = require("./payload");
24
24
  // Decoder for Prepare's `201` `data` payload.
25
25
  //
26
- // The `PreparedSocialLogin` body is loginRequestId, oidcNonce, oidcState,
27
- // expiresAt, and `prepareReceiptJws` when the service signs a receipt. Extra
28
- // response members are ignored.
29
- //
30
- // The receipt is carried through raw and not examined here: not its presence,
31
- // its type, or its shape. What to do with it is decided per environment by
32
- // `auth/prepareReceipt.ts`'s `checkPrepareReceipt`, which `prepareSocialLogin`
33
- // calls right after this decoder. With no trust anchor pinned the receipt is
34
- // ignored, so a receipt the SDK cannot use must not fail the response here;
35
- // with an anchor pinned, a missing or malformed receipt is
36
- // `prepare_receipt_invalid` there rather than a malformed response here.
26
+ // The `PreparedSocialLogin` body is loginRequestId, oidcNonce, oidcState, and
27
+ // expiresAt. Extra response members are ignored.
37
28
  const OIDC_VALUE_MIN = 32;
38
29
  const OIDC_VALUE_MAX = 256;
39
30
  function requiredUuid(payload, name) {
@@ -50,13 +41,6 @@ function requiredOidcValue(payload, name) {
50
41
  }
51
42
  return value;
52
43
  }
53
- /** The raw receipt member: `null` when absent or JSON `null`, else whatever was sent. */
54
- function rawPrepareReceipt(payload) {
55
- const value = Object.prototype.hasOwnProperty.call(payload, 'prepareReceiptJws')
56
- ? payload['prepareReceiptJws']
57
- : undefined;
58
- return value === undefined ? null : value;
59
- }
60
44
  /** Map a Prepare success payload onto the fields the SDK keeps. */
61
45
  function toSocialLoginRequest(value) {
62
46
  const payload = (0, payload_1.asObject)(value, 'payload');
@@ -67,6 +51,5 @@ function toSocialLoginRequest(value) {
67
51
  // The service sends this as epoch milliseconds; the decoder also accepts
68
52
  // ISO-8601. See `instant.ts`.
69
53
  expiresAt: (0, instant_1.requiredDateTime)(payload, 'expiresAt'),
70
- prepareReceiptJws: rawPrepareReceipt(payload),
71
54
  };
72
55
  }
@@ -22,8 +22,8 @@ import { Transaction } from '../models/Transaction';
22
22
  * Unknown additional fields are ignored and an unfamiliar present closed-set
23
23
  * or location value degrades to `unrecognized`; a missing guaranteed field
24
24
  * throws. Guaranteed fields are `id`, `type`, `status`, `amount`, `createDate`,
25
- * and `updateDate` — see `models/Transaction.ts`. `source` and `destination`
26
- * decode to `null` when absent.
25
+ * and `updateDate` — see `models/Transaction.ts`. `source`, `destination`, and
26
+ * `contractExecution` decode to `null` when absent.
27
27
  *
28
28
  * @throws MalformedPayloadError
29
29
  */
@@ -26,8 +26,8 @@ const payload_1 = require("./payload");
26
26
  * Wire payload -> public `Transaction` model, and the required/optional line.
27
27
  *
28
28
  * Generic object and string readers come from `wire/payload`; shared money
29
- * decoding comes from `wire/moneyPayload`. Transaction-specific enum and
30
- * location decoding remains here.
29
+ * decoding comes from `wire/moneyPayload`. Transaction-specific enum,
30
+ * location, and contract-execution summary decoding remains here.
31
31
  */
32
32
  const TRANSACTION_TYPES = new Map([
33
33
  ['deposit', Object.freeze({ kind: 'deposit' })],
@@ -36,6 +36,7 @@ const TRANSACTION_TYPES = new Map([
36
36
  ['fx', Object.freeze({ kind: 'fx' })],
37
37
  ['fee', Object.freeze({ kind: 'fee' })],
38
38
  ['credit', Object.freeze({ kind: 'credit' })],
39
+ ['contract_execution', Object.freeze({ kind: 'contract_execution' })],
39
40
  ['other', Object.freeze({ kind: 'other' })],
40
41
  ]);
41
42
  const TRANSACTION_STATUSES = new Map([
@@ -94,14 +95,35 @@ function toOptionalTransactionLocation(value, field) {
94
95
  }
95
96
  return toTransactionLocation(value, field);
96
97
  }
98
+ /**
99
+ * Decode the optional `contractExecution` summary (OpenAPI
100
+ * `ContractExecutionActivityDetails`). Absent or JSON `null` is `null`.
101
+ *
102
+ * Once present, `id`, `blockchain`, and `contractAddress` are required and
103
+ * `functionSelector` is optional. `blockchain` is read as a string rather than
104
+ * checked against the service's current chain list, so a chain added later
105
+ * does not fail the row. The selector pattern is not re-checked either.
106
+ */
107
+ function toOptionalContractExecution(payload) {
108
+ const summary = (0, payload_1.optionalObject)(payload, 'contractExecution');
109
+ if (summary === null) {
110
+ return null;
111
+ }
112
+ return new Transaction_1.TransactionContractExecution({
113
+ id: (0, payload_1.requiredString)(summary, 'id', 'contractExecution.id'),
114
+ blockchain: (0, payload_1.requiredString)(summary, 'blockchain', 'contractExecution.blockchain'),
115
+ contractAddress: (0, payload_1.requiredString)(summary, 'contractAddress', 'contractExecution.contractAddress'),
116
+ functionSelector: (0, payload_1.optionalString)(summary, 'functionSelector', 'contractExecution.functionSelector'),
117
+ });
118
+ }
97
119
  /**
98
120
  * Map a decoded `Transaction` payload onto the public model.
99
121
  *
100
122
  * Unknown additional fields are ignored and an unfamiliar present closed-set
101
123
  * or location value degrades to `unrecognized`; a missing guaranteed field
102
124
  * throws. Guaranteed fields are `id`, `type`, `status`, `amount`, `createDate`,
103
- * and `updateDate` — see `models/Transaction.ts`. `source` and `destination`
104
- * decode to `null` when absent.
125
+ * and `updateDate` — see `models/Transaction.ts`. `source`, `destination`, and
126
+ * `contractExecution` decode to `null` when absent.
105
127
  *
106
128
  * @throws MalformedPayloadError
107
129
  */
@@ -114,6 +136,7 @@ function toTransaction(value) {
114
136
  amount: (0, moneyPayload_1.requiredMoney)(payload, 'amount'),
115
137
  source: toOptionalTransactionLocation(payload['source'], 'source'),
116
138
  destination: toOptionalTransactionLocation(payload['destination'], 'destination'),
139
+ contractExecution: toOptionalContractExecution(payload),
117
140
  createDate: (0, payload_1.requiredString)(payload, 'createDate'),
118
141
  updateDate: (0, payload_1.requiredString)(payload, 'updateDate'),
119
142
  });