@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
|
@@ -16,12 +16,16 @@
|
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/
|
|
18
18
|
import type { DaaEnvironment } from '../config';
|
|
19
|
+
import { DaaError } from '../errors';
|
|
19
20
|
import type { DeviceContext } from '../models/DaaUserContext';
|
|
20
|
-
import type {
|
|
21
|
+
import type { DeviceStatus } from '../models/DeviceStatus';
|
|
22
|
+
import type { DaaHttpRequest, DaaTransport } from '../transport/DaaTransport';
|
|
21
23
|
import { AccountLimitsClient } from './AccountLimitsClient';
|
|
22
24
|
import { AccountsClient } from './AccountsClient';
|
|
25
|
+
import { ContractExecutionsClient } from './ContractExecutionsClient';
|
|
23
26
|
import { DepositAddressesClient } from './DepositAddressesClient';
|
|
24
27
|
import { DepositsClient } from './DepositsClient';
|
|
28
|
+
import { type ApproveDeviceArgs } from './deviceApproval';
|
|
25
29
|
import { FiatAccountsClient } from './FiatAccountsClient';
|
|
26
30
|
import { type DaaUserSigning } from './signedResource';
|
|
27
31
|
import { TransactionsClient } from './TransactionsClient';
|
|
@@ -61,6 +65,8 @@ export declare class DaaUserClient {
|
|
|
61
65
|
readonly transfers: TransfersClient;
|
|
62
66
|
/** Reads over DAA withdrawals, and the signed withdrawal create. */
|
|
63
67
|
readonly withdrawals: WithdrawalsClient;
|
|
68
|
+
/** Reads over self-custody contract executions, and the signed create. */
|
|
69
|
+
readonly contractExecutions: ContractExecutionsClient;
|
|
64
70
|
/** Reads over wire and ACH fiat accounts, and their receiving instructions. */
|
|
65
71
|
readonly fiatAccounts: FiatAccountsClient;
|
|
66
72
|
/** @internal Constructed only through {@link createDaaUserClient}. */
|
|
@@ -82,12 +88,55 @@ export declare class DaaUserClient {
|
|
|
82
88
|
* that is not yet registered, for a rejected or replayed authorization
|
|
83
89
|
* (including a key that is no longer active: DAA has no revoked-credential
|
|
84
90
|
* code, so this never throws `device_revoked`), for a response the SDK
|
|
85
|
-
* cannot read, and once this client is {@link close}d;
|
|
91
|
+
* cannot read, and once this client is {@link close}d; `clock_skew` when
|
|
92
|
+
* DAA refused the authorization because the device clock was more than 60
|
|
93
|
+
* seconds off: correct the device time, then refresh again;
|
|
94
|
+
* `user_cancelled` when the user dismisses the authentication prompt;
|
|
86
95
|
* `detail.kind === 'api'` for a status other than the documented `200`; and
|
|
87
96
|
* `detail.kind === 'transport'` if the consumer's transport throws, with
|
|
88
97
|
* the thrown value as `err.cause`.
|
|
89
98
|
*/
|
|
90
99
|
refreshContext(): Promise<DeviceContext>;
|
|
100
|
+
/**
|
|
101
|
+
* Approve a new device on this account from this one (add-a-device).
|
|
102
|
+
*
|
|
103
|
+
* The new device shows a six-digit matching code; the user types it here.
|
|
104
|
+
* The SDK reads the request from the device list, checks the typed code
|
|
105
|
+
* against the code the new device's secret produces, and only then signs
|
|
106
|
+
* `approve_device` with this device's key, so a wrong code is refused before
|
|
107
|
+
* any biometric prompt. The prompt shows the code. On success the new device
|
|
108
|
+
* is in its cool-down: the result is normally `pending_activation` with its
|
|
109
|
+
* `readyAt`.
|
|
110
|
+
*
|
|
111
|
+
* `requestId` comes from the partner (the `account.device.pending` webhook
|
|
112
|
+
* pushed to this device) or from the device list's `pendingRequests`.
|
|
113
|
+
*
|
|
114
|
+
* After a `transport` failure, a retryable `api` error, a `401` (once
|
|
115
|
+
* credentials are refreshed) or a `contract_violation`, call it again on this
|
|
116
|
+
* client with the same `requestId`: it signs the same approval body again (the
|
|
117
|
+
* user sees the prompt again), and DAA returns its saved result if the first
|
|
118
|
+
* one went through. Another `4xx` is DAA refusing the approval, and calling
|
|
119
|
+
* again gets the same answer. The body is kept in memory until a valid
|
|
120
|
+
* result, `device_approval_invalid` or `close()`.
|
|
121
|
+
* After `device_approval_busy` the same applies: nothing was saved, so DAA
|
|
122
|
+
* runs the re-signed approval again.
|
|
123
|
+
*
|
|
124
|
+
* Don't call it again for a `requestId` while a call for it is still
|
|
125
|
+
* running: each call reads and signs on its own, so the user sees two
|
|
126
|
+
* prompts.
|
|
127
|
+
*
|
|
128
|
+
* @throws DaaError with `detail.kind`:
|
|
129
|
+
* `matching_code_mismatch` when the typed code is wrong (let the user type
|
|
130
|
+
* it again); `device_approval_not_ready` when the new device has not sent
|
|
131
|
+
* its code secret yet (try again in a few seconds);
|
|
132
|
+
* `device_approval_invalid` when the request is no longer waiting (it
|
|
133
|
+
* expired, or was decided or cancelled); `device_approval_busy` when the
|
|
134
|
+
* account changed meanwhile (call again; the user sees the prompt again);
|
|
135
|
+
* `user_cancelled` when the user dismisses the prompt (the request stays
|
|
136
|
+
* waiting); `clock_skew`, `contract_violation`, `api` and `transport` as
|
|
137
|
+
* for any signed write.
|
|
138
|
+
*/
|
|
139
|
+
approveDevice(args: ApproveDeviceArgs): Promise<DeviceStatus>;
|
|
91
140
|
/**
|
|
92
141
|
* `DaaUserClient.close()` clears active context from memory and cancels
|
|
93
142
|
* unsent work. It preserves an active profile-scoped AuthKey and credential;
|
|
@@ -99,15 +148,18 @@ export declare class DaaUserClient {
|
|
|
99
148
|
* closure, and every call this SDK makes is a single `transport.send` awaited
|
|
100
149
|
* to completion with no cancellation token in the transport contract to
|
|
101
150
|
* cancel. Concretely, close() revokes this instance's own capability to
|
|
102
|
-
* produce a fresh `X-Device-Authorization` at all, so `refreshContext
|
|
103
|
-
* every signed `create` on `accounts` / `transfers` / `withdrawals
|
|
104
|
-
* closed with `contract_violation` from
|
|
105
|
-
* continuing to sign. The guarded
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
151
|
+
* produce a fresh `X-Device-Authorization` at all, so `refreshContext`,
|
|
152
|
+
* every signed `create` on `accounts` / `transfers` / `withdrawals`, and
|
|
153
|
+
* `contractExecutions.prepare` fail closed with `contract_violation` from
|
|
154
|
+
* this point on instead of silently continuing to sign. The guarded
|
|
155
|
+
* transport also refuses unsigned reads, writes, retained Page navigation
|
|
156
|
+
* closures, and a `contractExecutions.submit` of an execution prepared
|
|
157
|
+
* earlier, so unsent work cannot outlive the user surface that created it.
|
|
158
|
+
* That prepared execution stays valid: a later `forUser` client for the same
|
|
159
|
+
* AuthKey can submit it. The registered AuthKey and Circle's registration
|
|
160
|
+
* acknowledgement are untouched — nothing here calls the native store, so
|
|
161
|
+
* there is nothing here that could revoke either. Idempotent: closing an
|
|
162
|
+
* already-closed client is a no-op.
|
|
111
163
|
*/
|
|
112
164
|
close(): void;
|
|
113
165
|
}
|
|
@@ -122,3 +174,14 @@ export declare class DaaUserClient {
|
|
|
122
174
|
* it, the environment's public API origin is the pagination trust anchor.
|
|
123
175
|
*/
|
|
124
176
|
export declare function createDaaUserClient(transport: DaaTransport, environment: DaaEnvironment, signing: DaaUserSigning, publicApiOrigin?: string): DaaUserClient;
|
|
177
|
+
/**
|
|
178
|
+
* Wrap a throw from the consumer's transport as a `transport` error. An error
|
|
179
|
+
* that is already a `DaaError` passes through unchanged, as in
|
|
180
|
+
* `mapNativeError`.
|
|
181
|
+
*
|
|
182
|
+
* The idempotency key is read from the exact bytes that were handed to the
|
|
183
|
+
* transport, with the same reader the signed `409` mapping uses. A body the
|
|
184
|
+
* reader cannot parse leaves the key off rather than replacing the transport
|
|
185
|
+
* failure with a different error.
|
|
186
|
+
*/
|
|
187
|
+
export declare function asTransportFailure(err: unknown, request: DaaHttpRequest): DaaError;
|
|
@@ -27,18 +27,21 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
27
27
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
28
28
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
29
29
|
};
|
|
30
|
-
var _DaaUserClient_transport, _DaaUserClient_signing, _DaaUserClient_markClosed;
|
|
30
|
+
var _DaaUserClient_transport, _DaaUserClient_signing, _DaaUserClient_approvals, _DaaUserClient_assertOpen, _DaaUserClient_markClosed;
|
|
31
31
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
32
|
exports.DaaUserClient = void 0;
|
|
33
33
|
exports.createDaaUserClient = createDaaUserClient;
|
|
34
|
+
exports.asTransportFailure = asTransportFailure;
|
|
34
35
|
const config_1 = require("../config");
|
|
35
36
|
const deviceAuthorization_1 = require("../auth/deviceAuthorization");
|
|
36
37
|
const errors_1 = require("../errors");
|
|
37
38
|
const deviceContextPayload_1 = require("../wire/deviceContextPayload");
|
|
38
39
|
const AccountLimitsClient_1 = require("./AccountLimitsClient");
|
|
39
40
|
const AccountsClient_1 = require("./AccountsClient");
|
|
41
|
+
const ContractExecutionsClient_1 = require("./ContractExecutionsClient");
|
|
40
42
|
const DepositAddressesClient_1 = require("./DepositAddressesClient");
|
|
41
43
|
const DepositsClient_1 = require("./DepositsClient");
|
|
44
|
+
const deviceApproval_1 = require("./deviceApproval");
|
|
42
45
|
const FiatAccountsClient_1 = require("./FiatAccountsClient");
|
|
43
46
|
const signedResource_1 = require("./signedResource");
|
|
44
47
|
const TransactionsClient_1 = require("./TransactionsClient");
|
|
@@ -67,14 +70,17 @@ class DaaUserClient {
|
|
|
67
70
|
constructor(transport, environment, signing, publicApiOriginOverride) {
|
|
68
71
|
_DaaUserClient_transport.set(this, void 0);
|
|
69
72
|
_DaaUserClient_signing.set(this, void 0);
|
|
73
|
+
_DaaUserClient_approvals.set(this, new Map());
|
|
74
|
+
_DaaUserClient_assertOpen.set(this, void 0);
|
|
70
75
|
_DaaUserClient_markClosed.set(this, void 0);
|
|
71
76
|
const publicApiOrigin = publicApiOriginOverride ?? (0, config_1.publicApiOriginFor)(environment);
|
|
72
77
|
// `close()` has to reach every signed operation this surface
|
|
73
78
|
// exposes, not just `refreshContext` — an accounts/transfers/withdrawals
|
|
74
|
-
// `create` reached through a "closed"
|
|
75
|
-
// `close()` exists to refuse. Every
|
|
76
|
-
// wrapper rather than the caller's
|
|
77
|
-
// here closes all of them at once
|
|
79
|
+
// `create`, or a contract-execution `prepare`, reached through a "closed"
|
|
80
|
+
// client is exactly the further use `close()` exists to refuse. Every
|
|
81
|
+
// signed client below is handed this one wrapper rather than the caller's
|
|
82
|
+
// `signing` directly, so flipping `closed` here closes all of them at once
|
|
83
|
+
// without editing any resource client.
|
|
78
84
|
let closed = false;
|
|
79
85
|
const assertOpen = () => {
|
|
80
86
|
if (closed) {
|
|
@@ -83,6 +89,7 @@ class DaaUserClient {
|
|
|
83
89
|
};
|
|
84
90
|
const guardedSigning = Object.freeze({
|
|
85
91
|
authKeyId: signing.authKeyId,
|
|
92
|
+
clientEntityId: signing.clientEntityId,
|
|
86
93
|
resolveAuthKey: async () => {
|
|
87
94
|
assertOpen();
|
|
88
95
|
return guardAuthKey(await signing.resolveAuthKey(), assertOpen);
|
|
@@ -116,9 +123,11 @@ class DaaUserClient {
|
|
|
116
123
|
this.transactions = new TransactionsClient_1.TransactionsClient(guardedTransport, publicApiOrigin);
|
|
117
124
|
this.transfers = new TransfersClient_1.TransfersClient(guardedTransport, publicApiOrigin, guardedSigning);
|
|
118
125
|
this.withdrawals = new WithdrawalsClient_1.WithdrawalsClient(guardedTransport, publicApiOrigin, guardedSigning);
|
|
126
|
+
this.contractExecutions = new ContractExecutionsClient_1.ContractExecutionsClient(guardedTransport, guardedSigning);
|
|
119
127
|
this.fiatAccounts = new FiatAccountsClient_1.FiatAccountsClient(guardedTransport);
|
|
120
128
|
__classPrivateFieldSet(this, _DaaUserClient_transport, guardedTransport, "f");
|
|
121
129
|
__classPrivateFieldSet(this, _DaaUserClient_signing, guardedSigning, "f");
|
|
130
|
+
__classPrivateFieldSet(this, _DaaUserClient_assertOpen, assertOpen, "f");
|
|
122
131
|
__classPrivateFieldSet(this, _DaaUserClient_markClosed, () => {
|
|
123
132
|
closed = true;
|
|
124
133
|
}, "f");
|
|
@@ -141,7 +150,10 @@ class DaaUserClient {
|
|
|
141
150
|
* that is not yet registered, for a rejected or replayed authorization
|
|
142
151
|
* (including a key that is no longer active: DAA has no revoked-credential
|
|
143
152
|
* code, so this never throws `device_revoked`), for a response the SDK
|
|
144
|
-
* cannot read, and once this client is {@link close}d;
|
|
153
|
+
* cannot read, and once this client is {@link close}d; `clock_skew` when
|
|
154
|
+
* DAA refused the authorization because the device clock was more than 60
|
|
155
|
+
* seconds off: correct the device time, then refresh again;
|
|
156
|
+
* `user_cancelled` when the user dismisses the authentication prompt;
|
|
145
157
|
* `detail.kind === 'api'` for a status other than the documented `200`; and
|
|
146
158
|
* `detail.kind === 'transport'` if the consumer's transport throws, with
|
|
147
159
|
* the thrown value as `err.cause`.
|
|
@@ -156,6 +168,48 @@ class DaaUserClient {
|
|
|
156
168
|
decode: deviceContextPayload_1.toDeviceContext,
|
|
157
169
|
});
|
|
158
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* Approve a new device on this account from this one (add-a-device).
|
|
173
|
+
*
|
|
174
|
+
* The new device shows a six-digit matching code; the user types it here.
|
|
175
|
+
* The SDK reads the request from the device list, checks the typed code
|
|
176
|
+
* against the code the new device's secret produces, and only then signs
|
|
177
|
+
* `approve_device` with this device's key, so a wrong code is refused before
|
|
178
|
+
* any biometric prompt. The prompt shows the code. On success the new device
|
|
179
|
+
* is in its cool-down: the result is normally `pending_activation` with its
|
|
180
|
+
* `readyAt`.
|
|
181
|
+
*
|
|
182
|
+
* `requestId` comes from the partner (the `account.device.pending` webhook
|
|
183
|
+
* pushed to this device) or from the device list's `pendingRequests`.
|
|
184
|
+
*
|
|
185
|
+
* After a `transport` failure, a retryable `api` error, a `401` (once
|
|
186
|
+
* credentials are refreshed) or a `contract_violation`, call it again on this
|
|
187
|
+
* client with the same `requestId`: it signs the same approval body again (the
|
|
188
|
+
* user sees the prompt again), and DAA returns its saved result if the first
|
|
189
|
+
* one went through. Another `4xx` is DAA refusing the approval, and calling
|
|
190
|
+
* again gets the same answer. The body is kept in memory until a valid
|
|
191
|
+
* result, `device_approval_invalid` or `close()`.
|
|
192
|
+
* After `device_approval_busy` the same applies: nothing was saved, so DAA
|
|
193
|
+
* runs the re-signed approval again.
|
|
194
|
+
*
|
|
195
|
+
* Don't call it again for a `requestId` while a call for it is still
|
|
196
|
+
* running: each call reads and signs on its own, so the user sees two
|
|
197
|
+
* prompts.
|
|
198
|
+
*
|
|
199
|
+
* @throws DaaError with `detail.kind`:
|
|
200
|
+
* `matching_code_mismatch` when the typed code is wrong (let the user type
|
|
201
|
+
* it again); `device_approval_not_ready` when the new device has not sent
|
|
202
|
+
* its code secret yet (try again in a few seconds);
|
|
203
|
+
* `device_approval_invalid` when the request is no longer waiting (it
|
|
204
|
+
* expired, or was decided or cancelled); `device_approval_busy` when the
|
|
205
|
+
* account changed meanwhile (call again; the user sees the prompt again);
|
|
206
|
+
* `user_cancelled` when the user dismisses the prompt (the request stays
|
|
207
|
+
* waiting); `clock_skew`, `contract_violation`, `api` and `transport` as
|
|
208
|
+
* for any signed write.
|
|
209
|
+
*/
|
|
210
|
+
async approveDevice(args) {
|
|
211
|
+
return (0, deviceApproval_1.approveDevice)(__classPrivateFieldGet(this, _DaaUserClient_transport, "f"), __classPrivateFieldGet(this, _DaaUserClient_signing, "f"), __classPrivateFieldGet(this, _DaaUserClient_approvals, "f"), __classPrivateFieldGet(this, _DaaUserClient_assertOpen, "f"), args);
|
|
212
|
+
}
|
|
159
213
|
/**
|
|
160
214
|
* `DaaUserClient.close()` clears active context from memory and cancels
|
|
161
215
|
* unsent work. It preserves an active profile-scoped AuthKey and credential;
|
|
@@ -167,22 +221,26 @@ class DaaUserClient {
|
|
|
167
221
|
* closure, and every call this SDK makes is a single `transport.send` awaited
|
|
168
222
|
* to completion with no cancellation token in the transport contract to
|
|
169
223
|
* cancel. Concretely, close() revokes this instance's own capability to
|
|
170
|
-
* produce a fresh `X-Device-Authorization` at all, so `refreshContext
|
|
171
|
-
* every signed `create` on `accounts` / `transfers` / `withdrawals
|
|
172
|
-
* closed with `contract_violation` from
|
|
173
|
-
* continuing to sign. The guarded
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
*
|
|
224
|
+
* produce a fresh `X-Device-Authorization` at all, so `refreshContext`,
|
|
225
|
+
* every signed `create` on `accounts` / `transfers` / `withdrawals`, and
|
|
226
|
+
* `contractExecutions.prepare` fail closed with `contract_violation` from
|
|
227
|
+
* this point on instead of silently continuing to sign. The guarded
|
|
228
|
+
* transport also refuses unsigned reads, writes, retained Page navigation
|
|
229
|
+
* closures, and a `contractExecutions.submit` of an execution prepared
|
|
230
|
+
* earlier, so unsent work cannot outlive the user surface that created it.
|
|
231
|
+
* That prepared execution stays valid: a later `forUser` client for the same
|
|
232
|
+
* AuthKey can submit it. The registered AuthKey and Circle's registration
|
|
233
|
+
* acknowledgement are untouched — nothing here calls the native store, so
|
|
234
|
+
* there is nothing here that could revoke either. Idempotent: closing an
|
|
235
|
+
* already-closed client is a no-op.
|
|
179
236
|
*/
|
|
180
237
|
close() {
|
|
181
238
|
__classPrivateFieldGet(this, _DaaUserClient_markClosed, "f").call(this);
|
|
239
|
+
__classPrivateFieldGet(this, _DaaUserClient_approvals, "f").clear();
|
|
182
240
|
}
|
|
183
241
|
}
|
|
184
242
|
exports.DaaUserClient = DaaUserClient;
|
|
185
|
-
_DaaUserClient_transport = new WeakMap(), _DaaUserClient_signing = new WeakMap(), _DaaUserClient_markClosed = new WeakMap();
|
|
243
|
+
_DaaUserClient_transport = new WeakMap(), _DaaUserClient_signing = new WeakMap(), _DaaUserClient_approvals = new WeakMap(), _DaaUserClient_assertOpen = new WeakMap(), _DaaUserClient_markClosed = new WeakMap();
|
|
186
244
|
/**
|
|
187
245
|
* Keep an in-flight signed operation tied to this user's lifecycle. The
|
|
188
246
|
* resolver guard prevents new operations after `close()`, while the signing
|
|
@@ -190,11 +248,12 @@ _DaaUserClient_transport = new WeakMap(), _DaaUserClient_signing = new WeakMap()
|
|
|
190
248
|
* otherwise sign with the already-resolved AuthKey.
|
|
191
249
|
*/
|
|
192
250
|
function guardAuthKey(authKey, assertOpen) {
|
|
251
|
+
const signDeviceApproval = authKey.signDeviceApproval?.bind(authKey);
|
|
193
252
|
return Object.freeze({
|
|
194
253
|
publicKeySpkiBase64Url: () => authKey.publicKeySpkiBase64Url(),
|
|
195
254
|
thumbprint: () => authKey.thumbprint(),
|
|
196
255
|
resolution: () => authKey.resolution(),
|
|
197
|
-
acknowledgeRegistration: () => authKey.acknowledgeRegistration(),
|
|
256
|
+
acknowledgeRegistration: (registration) => authKey.acknowledgeRegistration(registration),
|
|
198
257
|
signExactBytes: async (message) => {
|
|
199
258
|
assertOpen();
|
|
200
259
|
return authKey.signExactBytes(message);
|
|
@@ -203,6 +262,14 @@ function guardAuthKey(authKey, assertOpen) {
|
|
|
203
262
|
assertOpen();
|
|
204
263
|
return authKey.signRegistrationDeviceAuthorization(message);
|
|
205
264
|
},
|
|
265
|
+
...(signDeviceApproval === undefined
|
|
266
|
+
? {}
|
|
267
|
+
: {
|
|
268
|
+
signDeviceApproval: async (message, approval) => {
|
|
269
|
+
assertOpen();
|
|
270
|
+
return signDeviceApproval(message, approval);
|
|
271
|
+
},
|
|
272
|
+
}),
|
|
206
273
|
});
|
|
207
274
|
}
|
|
208
275
|
/**
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
import type { Page } from '../models/Page';
|
|
19
19
|
import type { Transaction } from '../models/Transaction';
|
|
20
20
|
import type { DaaTransport } from '../transport/DaaTransport';
|
|
21
|
-
declare const TRANSACTION_TYPES: readonly ["deposit", "withdrawal", "transfer", "fx", "fee", "credit", "other"];
|
|
21
|
+
declare const TRANSACTION_TYPES: readonly ["deposit", "withdrawal", "transfer", "fx", "fee", "credit", "contract_execution", "other"];
|
|
22
22
|
declare const TRANSACTION_STATUSES: readonly ["pending", "complete", "failed", "returned"];
|
|
23
23
|
export type TransactionListQuery = Readonly<{
|
|
24
24
|
/** Select a backing source explicitly; omitted derives from `accountId` or defaults to omnibus. */
|
|
@@ -92,6 +92,9 @@ export declare class TransfersClient {
|
|
|
92
92
|
* sent — for a rejected or replayed authorization (including a key that is
|
|
93
93
|
* no longer active: DAA has no revoked-credential code, so this never
|
|
94
94
|
* throws `device_revoked`), and for a response the SDK cannot read;
|
|
95
|
+
* `clock_skew` when DAA refused the authorization because the device clock
|
|
96
|
+
* was more than 60 seconds off: correct the device time, then send the same
|
|
97
|
+
* request again;
|
|
95
98
|
* `idempotency_conflict`, with the request's key, for a `409` with
|
|
96
99
|
* `IDEMPOTENCY_KEY_REUSED` (`420034`): reconcile the original transfer with
|
|
97
100
|
* the same key; do not mint a new key for it;
|
|
@@ -158,6 +158,9 @@ class TransfersClient {
|
|
|
158
158
|
* sent — for a rejected or replayed authorization (including a key that is
|
|
159
159
|
* no longer active: DAA has no revoked-credential code, so this never
|
|
160
160
|
* throws `device_revoked`), and for a response the SDK cannot read;
|
|
161
|
+
* `clock_skew` when DAA refused the authorization because the device clock
|
|
162
|
+
* was more than 60 seconds off: correct the device time, then send the same
|
|
163
|
+
* request again;
|
|
161
164
|
* `idempotency_conflict`, with the request's key, for a `409` with
|
|
162
165
|
* `IDEMPOTENCY_KEY_REUSED` (`420034`): reconcile the original transfer with
|
|
163
166
|
* the same key; do not mint a new key for it;
|
|
@@ -81,6 +81,9 @@ export declare class WithdrawalsClient {
|
|
|
81
81
|
* sent — for a rejected or replayed authorization (including a key that is
|
|
82
82
|
* no longer active: DAA has no revoked-credential code, so this never
|
|
83
83
|
* throws `device_revoked`), and for a response the SDK cannot read;
|
|
84
|
+
* `clock_skew` when DAA refused the authorization because the device clock
|
|
85
|
+
* was more than 60 seconds off: correct the device time, then send the same
|
|
86
|
+
* request again;
|
|
84
87
|
* `idempotency_conflict`, with the request's key, for a `409` with
|
|
85
88
|
* `IDEMPOTENCY_KEY_REUSED` (`420034`): reconcile the original withdrawal with
|
|
86
89
|
* the same key; do not mint a new key for it;
|
|
@@ -135,6 +135,9 @@ class WithdrawalsClient {
|
|
|
135
135
|
* sent — for a rejected or replayed authorization (including a key that is
|
|
136
136
|
* no longer active: DAA has no revoked-credential code, so this never
|
|
137
137
|
* throws `device_revoked`), and for a response the SDK cannot read;
|
|
138
|
+
* `clock_skew` when DAA refused the authorization because the device clock
|
|
139
|
+
* was more than 60 seconds off: correct the device time, then send the same
|
|
140
|
+
* request again;
|
|
138
141
|
* `idempotency_conflict`, with the request's key, for a `409` with
|
|
139
142
|
* `IDEMPOTENCY_KEY_REUSED` (`420034`): reconcile the original withdrawal with
|
|
140
143
|
* the same key; do not mint a new key for it;
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
import type { DaaTransport } from '../transport/DaaTransport';
|
|
20
|
+
import { type DaaUserSigning } from './signedResource';
|
|
21
|
+
/** The device list: the user's devices and the new devices waiting for approval. */
|
|
22
|
+
export declare const DEVICE_LIST_PATH = "/v1/accounts/auth/devices";
|
|
23
|
+
/**
|
|
24
|
+
* What a retry of one request's approval needs: the exact body (its
|
|
25
|
+
* `idempotencyKey` included), the code secret native checks against it, and
|
|
26
|
+
* the code a typed code must match.
|
|
27
|
+
*/
|
|
28
|
+
type KeptApproval = Readonly<{
|
|
29
|
+
targetAuthKeyId: string;
|
|
30
|
+
codeSecret: Uint8Array;
|
|
31
|
+
code: string;
|
|
32
|
+
bodyBytes: Uint8Array;
|
|
33
|
+
}>;
|
|
34
|
+
/** Approval bodies DAA has not answered yet, by lowercase request id. One per `DaaUserClient`. */
|
|
35
|
+
export type KeptApprovals = Map<string, KeptApproval>;
|
|
36
|
+
export type ApproveDeviceArgs = Readonly<{
|
|
37
|
+
/** The add-a-device request to approve, from the device list or the partner's push. */
|
|
38
|
+
requestId: string;
|
|
39
|
+
/** The six digits the user typed from the new device's screen. Spaces and dashes are ignored. */
|
|
40
|
+
typedCode: string;
|
|
41
|
+
}>;
|
|
42
|
+
/**
|
|
43
|
+
* Approve the waiting device `requestId` with the code the user typed. Resolves
|
|
44
|
+
* with the new device's status, normally `pending_activation` with its
|
|
45
|
+
* `readyAt`.
|
|
46
|
+
*/
|
|
47
|
+
export declare function approveDevice(transport: DaaTransport, signing: DaaUserSigning, kept: KeptApprovals, assertOpen: () => void, args: ApproveDeviceArgs): Promise<DeviceStatus>;
|
|
48
|
+
export {};
|