@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
@@ -0,0 +1,130 @@
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
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
20
+ if (kind === "m") throw new TypeError("Private method is not writable");
21
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
22
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
23
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
24
+ };
25
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
26
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
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
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
29
+ };
30
+ var _ContractExecution_contractAddress, _ContractExecution_invocation, _ContractExecution_amount, _ContractExecution_networkFee, _ContractExecution_transactionHash;
31
+ Object.defineProperty(exports, "__esModule", { value: true });
32
+ exports.ContractExecution = void 0;
33
+ const redaction_1 = require("./redaction");
34
+ /**
35
+ * A DAA contract execution.
36
+ *
37
+ * **Guaranteed fields** are `id`, `status`, `source`, `custodyType`,
38
+ * `blockchain`, `contractAddress`, the invocation, `amount`, `createDate`, and
39
+ * `updateDate`. `amount` is the native value attached to the call — zero when
40
+ * the request omitted it — and on a failed execution it describes what was
41
+ * requested, not what moved. `transactionHash` and `networkFee` are present
42
+ * once known, including for a reverted call; `networkFee` is the actual chain
43
+ * cost, not what the customer is billed. `errorCode` is present only when the
44
+ * status is `failed`.
45
+ *
46
+ * `blockchain` and `custodyType` are plain strings on a read, for the reason
47
+ * `Account.blockchain` is: a later service value must not make the execution
48
+ * unreadable. `blockchain` is the service's chain name exactly as sent, which
49
+ * need not be the request's spelling of the same chain (Base is `CBASE` in a
50
+ * request); compare chains through the account, not by string.
51
+ *
52
+ * **No default rendering prints the call.** `contractAddress`, the invocation,
53
+ * `transactionHash`, and both amounts sit behind prototype accessors; `toJSON`
54
+ * and `toString` report only identifiers, states, and the invocation mode.
55
+ *
56
+ * Not constructible by a consumer: exported from `index.ts` as a type only, and
57
+ * the `#` private fields make the type nominal.
58
+ */
59
+ class ContractExecution {
60
+ /** @internal Constructed only by the SDK's response decoder. */
61
+ constructor(fields) {
62
+ _ContractExecution_contractAddress.set(this, void 0);
63
+ _ContractExecution_invocation.set(this, void 0);
64
+ _ContractExecution_amount.set(this, void 0);
65
+ _ContractExecution_networkFee.set(this, void 0);
66
+ _ContractExecution_transactionHash.set(this, void 0);
67
+ this.id = fields.id;
68
+ this.status = fields.status;
69
+ this.errorCode = fields.errorCode;
70
+ this.source = fields.source;
71
+ this.custodyType = fields.custodyType;
72
+ this.blockchain = fields.blockchain;
73
+ this.createDate = fields.createDate;
74
+ this.updateDate = fields.updateDate;
75
+ __classPrivateFieldSet(this, _ContractExecution_contractAddress, fields.contractAddress, "f");
76
+ __classPrivateFieldSet(this, _ContractExecution_invocation, fields.invocation, "f");
77
+ __classPrivateFieldSet(this, _ContractExecution_amount, fields.amount, "f");
78
+ __classPrivateFieldSet(this, _ContractExecution_networkFee, fields.networkFee, "f");
79
+ __classPrivateFieldSet(this, _ContractExecution_transactionHash, fields.transactionHash, "f");
80
+ Object.freeze(this);
81
+ }
82
+ /** The target contract address, exactly as the service sent it. */
83
+ get contractAddress() {
84
+ return __classPrivateFieldGet(this, _ContractExecution_contractAddress, "f");
85
+ }
86
+ /** The accepted invocation. Deeply frozen. */
87
+ get invocation() {
88
+ return __classPrivateFieldGet(this, _ContractExecution_invocation, "f");
89
+ }
90
+ /** Native value attached to the call; zero when the request omitted it. */
91
+ get amount() {
92
+ return __classPrivateFieldGet(this, _ContractExecution_amount, "f");
93
+ }
94
+ /** Actual network cost once known, including for a reverted call; otherwise `null`. */
95
+ get networkFee() {
96
+ return __classPrivateFieldGet(this, _ContractExecution_networkFee, "f");
97
+ }
98
+ /** On-chain transaction hash once known, including for a reverted call; otherwise `null`. */
99
+ get transactionHash() {
100
+ return __classPrivateFieldGet(this, _ContractExecution_transactionHash, "f");
101
+ }
102
+ /** Identifiers, states, and the invocation mode render; the call itself does not. */
103
+ toJSON() {
104
+ return {
105
+ id: this.id,
106
+ status: this.status,
107
+ errorCode: this.errorCode,
108
+ source: this.source,
109
+ custodyType: this.custodyType,
110
+ blockchain: this.blockchain,
111
+ contractAddress: redaction_1.REDACTED,
112
+ invocation: { kind: __classPrivateFieldGet(this, _ContractExecution_invocation, "f").kind, inputs: redaction_1.REDACTED },
113
+ amount: __classPrivateFieldGet(this, _ContractExecution_amount, "f").toJSON(),
114
+ networkFee: __classPrivateFieldGet(this, _ContractExecution_networkFee, "f") === null ? null : __classPrivateFieldGet(this, _ContractExecution_networkFee, "f").toJSON(),
115
+ transactionHash: __classPrivateFieldGet(this, _ContractExecution_transactionHash, "f") === null ? null : redaction_1.REDACTED,
116
+ createDate: this.createDate,
117
+ updateDate: this.updateDate,
118
+ };
119
+ }
120
+ /** Identifiers, states, and the invocation mode print; the call itself does not. */
121
+ toString() {
122
+ return (`ContractExecution(id=${this.id}, status=${this.status.kind}, ` +
123
+ `errorCode=${this.errorCode === null ? 'null' : this.errorCode.kind}, ` +
124
+ `blockchain=${this.blockchain}, invocation=${__classPrivateFieldGet(this, _ContractExecution_invocation, "f").kind}, ` +
125
+ `amount=${__classPrivateFieldGet(this, _ContractExecution_amount, "f").toString()}, createDate=${this.createDate}, ` +
126
+ `updateDate=${this.updateDate})`);
127
+ }
128
+ }
129
+ exports.ContractExecution = ContractExecution;
130
+ _ContractExecution_contractAddress = new WeakMap(), _ContractExecution_invocation = new WeakMap(), _ContractExecution_amount = new WeakMap(), _ContractExecution_networkFee = new WeakMap(), _ContractExecution_transactionHash = new WeakMap();
@@ -0,0 +1,81 @@
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 { AbiParameter } from './ContractExecution';
19
+ /**
20
+ * The EVM chains the registry's `contract_execution` schema names.
21
+ *
22
+ * A closed set here, unlike `Account.blockchain` on a read, because this is a
23
+ * request: the registry types `blockchain` as this exact enum, so a value
24
+ * outside it cannot be signed into a body DAA accepts. The set is an
25
+ * upper bound; DAA still checks that the chain is enabled for the account and
26
+ * environment, and that it is the account's own chain.
27
+ */
28
+ export type ContractExecutionBlockchain = 'ETH' | 'ARB' | 'CBASE' | 'OP' | 'UNI' | 'ARC';
29
+ /** Fields both invocation modes share, in the registry's order. */
30
+ type CreateContractExecutionCommon = Readonly<{
31
+ /**
32
+ * UUID v4 identifying this execution attempt. Persist it with the prepared
33
+ * execution and never reuse it with different body bytes — the authorization
34
+ * JWS carries this same value as its `idempotency_key` claim.
35
+ */
36
+ idempotencyKey: string;
37
+ /** The self-custody DAA account that executes the call. A UUID. */
38
+ accountId: string;
39
+ /** Must be the account's own chain. It does not select a network. */
40
+ blockchain: ContractExecutionBlockchain;
41
+ /** Target contract: `0x` and 40 hex digits, not the zero address. */
42
+ contractAddress: string;
43
+ /**
44
+ * Native value attached to the call, in whole native-asset units (ETH, or
45
+ * native USD on Arc), as a decimal string such as `"0.1"`.
46
+ *
47
+ * Optional. Omitted, it is **not sent**: DAA treats an absent value as zero,
48
+ * and an absent value and an explicit `"0"` are different signed bodies.
49
+ * This is never an ERC-20 quantity (that is an ABI argument) and never the
50
+ * network fee.
51
+ */
52
+ amount?: string;
53
+ }>;
54
+ /** Raw mode: the exact call data to submit. */
55
+ export type CreateContractExecutionRawRequest = CreateContractExecutionCommon & Readonly<{
56
+ /** `0x`-prefixed, even-length hex; at least one and at most 16384 bytes. */
57
+ callData: string;
58
+ abiFunctionSignature?: never;
59
+ abiParameters?: never;
60
+ }>;
61
+ /** ABI mode: a canonical function signature and its inputs. */
62
+ export type CreateContractExecutionAbiRequest = CreateContractExecutionCommon & Readonly<{
63
+ /**
64
+ * Canonical Solidity signature, such as `approve(address,uint256)`: no
65
+ * whitespace, parameter names, aliases (`uint`, `int`, `byte`), tuples, or
66
+ * fixed-point types. A non-canonical spelling is rejected, never repaired.
67
+ */
68
+ abiFunctionSignature: string;
69
+ /** Inputs in signature order; `[]` for a function with no arguments. */
70
+ abiParameters: readonly AbiParameter[];
71
+ callData?: never;
72
+ }>;
73
+ /**
74
+ * Body for creating a contract execution: exactly one invocation mode.
75
+ *
76
+ * Every field is checked before the body is serialized, and the serialized
77
+ * bytes are the ones signed and sent. An unrecognized property — including a
78
+ * fee or gas option — is rejected rather than dropped.
79
+ */
80
+ export type CreateContractExecutionRequest = CreateContractExecutionRawRequest | CreateContractExecutionAbiRequest;
81
+ export {};
@@ -0,0 +1,19 @@
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 });
@@ -16,10 +16,12 @@
16
16
  * limitations under the License.
17
17
  */
18
18
  import type { OwnerAuthKey } from '../securekey/SecureKey';
19
+ import type { PendingDeviceApproval } from './PendingDeviceApproval';
19
20
  /**
20
21
  * Owner-bound local SDK context: `DaaUserContext`.
21
22
  *
22
- * Produced only by an `ACTIVE` Device Registration Complete. It is not a DAA
23
+ * Produced only by an `ACTIVE` Device Registration Complete, or by
24
+ * `DaaClient.restore` for a key such a Complete registered. It is not a DAA
23
25
  * bearer token or an application session. The `#` private field makes the type
24
26
  * nominal: an object literal cannot be typed or passed as one, so `forUser`
25
27
  * cannot be opened with a fabricated context. The constructor is also brand-
@@ -48,8 +50,21 @@ export type DeviceContext = Readonly<{
48
50
  * call it directly, with no import of this module at all. Requiring this
49
51
  * exact `Symbol` as the constructor's first argument closes that path —
50
52
  * `ctx.constructor` is reachable, but constructing anything with it throws
51
- * unless the caller already holds this token, and the only two places that do
52
- * are the decoder call sites below and in `../wire/deviceRegistrationResultPayload.ts`.
53
+ * unless the caller already holds this token. Three entry points use it:
54
+ *
55
+ * 1. the Device Registration Complete decoder in
56
+ * `../wire/deviceRegistrationResultPayload.ts`;
57
+ * 2. {@link bindAuthKeyToContext} below, which re-mints that same context
58
+ * paired with the AuthKey that authorized Complete;
59
+ * 3. {@link restoreDaaUserContext} below, used only by `DaaClient.restore`.
60
+ *
61
+ * The third is safe for the same reason as the first: it mints only from a
62
+ * `DeviceContext` the service returned to a registered-device authorization
63
+ * signed by the stored AuthKey (`get_device_context`), decoded by the same
64
+ * `toDeviceContext`, whose `authKeyId` `DaaClient.restore` has already checked
65
+ * equals the one stored with that key, and it binds the context to that key's
66
+ * thumbprint exactly as Complete does. The token stays inside this module: the
67
+ * restore path calls the factory rather than holding the token itself.
53
68
  *
54
69
  * Exported so those wire decoders can import it, but never re-exported from
55
70
  * `index.ts` — the package's `exports` map has no entry for this module's
@@ -82,13 +97,48 @@ export declare class DaaUserContext {
82
97
  * branded value because contexts are immutable once exposed to an application.
83
98
  */
84
99
  export declare function bindAuthKeyToContext(context: DaaUserContext, authKeyThumbprint: string): DaaUserContext;
100
+ /**
101
+ * Mint the `ACTIVE` context for a restored session.
102
+ *
103
+ * Reached only from `DaaClient.restore`, after the service answered a
104
+ * `get_device_context` request signed by the stored AuthKey and the returned
105
+ * `authKeyId` matched the stored one. Like {@link bindAuthKeyToContext}, the
106
+ * result is paired with that AuthKey's thumbprint, so `forUser` re-checks on
107
+ * every signed operation that it still resolves the same key. All the
108
+ * constructor's own invariants (UUID `clientEntityId`, `active` status, UUID
109
+ * `authKeyId`, well-formed thumbprint) apply unchanged.
110
+ *
111
+ * Kept here, rather than exporting {@link DECODER_TOKEN} to the restore path,
112
+ * so the brand never leaves the modules that decode or bind a context.
113
+ */
114
+ export declare function restoreDaaUserContext(clientEntityId: string, deviceContext: DeviceContext, authKeyThumbprint: string): DaaUserContext;
85
115
  /** Fail closed when the local key no longer matches the key paired at Complete. */
86
116
  export declare function assertAuthKeyMatchesContext(context: DaaUserContext, authKey: OwnerAuthKey): Promise<void>;
87
117
  /** True only for a context this SDK decoded from an ACTIVE registration. */
88
118
  export declare function isActiveDaaUserContext(value: unknown): value is DaaUserContext;
119
+ /**
120
+ * What Device Registration Complete returns: an ACTIVE context (a first device,
121
+ * or a key the account already holds); for a new device on an account that
122
+ * already has one, `PENDING_APPROVAL` with the matching code to show; for a
123
+ * device already approved from another device but still in the account's
124
+ * cool-down, `PENDING_ACTIVATION` with `readyAt` (no context: it can't sign
125
+ * until then; `DaaClient.restore` returns its context once it can); or the
126
+ * non-authorizing `RECOVERY_PENDING`, which `/v1/accounts/auth/keys` never
127
+ * returns and this SDK never produces. It stays in the type so a consumer's
128
+ * exhaustive `switch` keeps compiling.
129
+ */
89
130
  export type DeviceRegistrationResult = Readonly<{
90
131
  status: 'ACTIVE';
91
132
  context: DaaUserContext;
133
+ }> | Readonly<{
134
+ status: 'PENDING_APPROVAL';
135
+ pendingApproval: PendingDeviceApproval;
136
+ }> | Readonly<{
137
+ status: 'PENDING_ACTIVATION';
138
+ /** The key's id: follow it with `DaaClient.watchDeviceStatus`. */
139
+ authKeyId: string;
140
+ /** When the cool-down ends and the key may sign, as ISO-8601 text. */
141
+ readyAt: string;
92
142
  }> | Readonly<{
93
143
  status: 'RECOVERY_PENDING';
94
144
  recoveryReference: string;
@@ -31,6 +31,7 @@ var _DaaUserContext_active;
31
31
  Object.defineProperty(exports, "__esModule", { value: true });
32
32
  exports.DaaUserContext = exports.DECODER_TOKEN = void 0;
33
33
  exports.bindAuthKeyToContext = bindAuthKeyToContext;
34
+ exports.restoreDaaUserContext = restoreDaaUserContext;
34
35
  exports.assertAuthKeyMatchesContext = assertAuthKeyMatchesContext;
35
36
  exports.isActiveDaaUserContext = isActiveDaaUserContext;
36
37
  const uuid_1 = require("../validation/uuid");
@@ -45,8 +46,21 @@ const JWK_THUMBPRINT = /^[A-Za-z0-9_-]{43}$/;
45
46
  * call it directly, with no import of this module at all. Requiring this
46
47
  * exact `Symbol` as the constructor's first argument closes that path —
47
48
  * `ctx.constructor` is reachable, but constructing anything with it throws
48
- * unless the caller already holds this token, and the only two places that do
49
- * are the decoder call sites below and in `../wire/deviceRegistrationResultPayload.ts`.
49
+ * unless the caller already holds this token. Three entry points use it:
50
+ *
51
+ * 1. the Device Registration Complete decoder in
52
+ * `../wire/deviceRegistrationResultPayload.ts`;
53
+ * 2. {@link bindAuthKeyToContext} below, which re-mints that same context
54
+ * paired with the AuthKey that authorized Complete;
55
+ * 3. {@link restoreDaaUserContext} below, used only by `DaaClient.restore`.
56
+ *
57
+ * The third is safe for the same reason as the first: it mints only from a
58
+ * `DeviceContext` the service returned to a registered-device authorization
59
+ * signed by the stored AuthKey (`get_device_context`), decoded by the same
60
+ * `toDeviceContext`, whose `authKeyId` `DaaClient.restore` has already checked
61
+ * equals the one stored with that key, and it binds the context to that key's
62
+ * thumbprint exactly as Complete does. The token stays inside this module: the
63
+ * restore path calls the factory rather than holding the token itself.
50
64
  *
51
65
  * Exported so those wire decoders can import it, but never re-exported from
52
66
  * `index.ts` — the package's `exports` map has no entry for this module's
@@ -117,6 +131,23 @@ function bindAuthKeyToContext(context, authKeyThumbprint) {
117
131
  }
118
132
  return new DaaUserContext(exports.DECODER_TOKEN, { clientEntityId: context.clientEntityId, deviceContext: context.deviceContext }, authKeyThumbprint);
119
133
  }
134
+ /**
135
+ * Mint the `ACTIVE` context for a restored session.
136
+ *
137
+ * Reached only from `DaaClient.restore`, after the service answered a
138
+ * `get_device_context` request signed by the stored AuthKey and the returned
139
+ * `authKeyId` matched the stored one. Like {@link bindAuthKeyToContext}, the
140
+ * result is paired with that AuthKey's thumbprint, so `forUser` re-checks on
141
+ * every signed operation that it still resolves the same key. All the
142
+ * constructor's own invariants (UUID `clientEntityId`, `active` status, UUID
143
+ * `authKeyId`, well-formed thumbprint) apply unchanged.
144
+ *
145
+ * Kept here, rather than exporting {@link DECODER_TOKEN} to the restore path,
146
+ * so the brand never leaves the modules that decode or bind a context.
147
+ */
148
+ function restoreDaaUserContext(clientEntityId, deviceContext, authKeyThumbprint) {
149
+ return new DaaUserContext(exports.DECODER_TOKEN, { clientEntityId, deviceContext }, authKeyThumbprint);
150
+ }
120
151
  /** Fail closed when the local key no longer matches the key paired at Complete. */
121
152
  async function assertAuthKeyMatchesContext(context, authKey) {
122
153
  const expectedThumbprint = AUTH_KEY_THUMBPRINTS.get(context);
@@ -0,0 +1,69 @@
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
+ /**
19
+ * A new device's add-a-device status, as the status route
20
+ * (`GET /v1/accounts/auth/devices/{authKeyId}`) reports it.
21
+ *
22
+ * - `pending_approval`: waiting for an existing device, until `expiresAt`.
23
+ * - `pending_activation`: approved, in the account's cool-down until
24
+ * `readyAt`. The key can't sign yet.
25
+ * - `active`: the key can sign.
26
+ * - `denied`: the user declined it with Not me on another device. The key
27
+ * can't ask again; see `DaaClient.forgetLocalKey`.
28
+ * - `expired`: nobody approved it before `expiresAt`.
29
+ * - `cancelled`: DAA closed the request, for example because another new
30
+ * device was waiting at the same time.
31
+ * - `unrecognized`: a status this SDK version doesn't know, as DAA sent it in
32
+ * `rawValue`. DAA may add statuses before every app updates, so this is not
33
+ * an error; treat it as "can't tell yet" and don't act on the key.
34
+ *
35
+ * These are DAA's own spellings (lowercase), unlike
36
+ * `DeviceRegistrationResult.status` (`'PENDING_APPROVAL'`), which is this
37
+ * SDK's result type for `complete()`.
38
+ *
39
+ * `requestId` is the add-a-device request; a key that never had one (a first
40
+ * device) reads as `active` without it.
41
+ */
42
+ export type DeviceStatus = Readonly<{
43
+ status: 'pending_approval';
44
+ authKeyId: string;
45
+ requestId: string;
46
+ expiresAt: string;
47
+ } | {
48
+ status: 'pending_activation';
49
+ authKeyId: string;
50
+ requestId?: string;
51
+ readyAt: string;
52
+ } | {
53
+ status: 'active';
54
+ authKeyId: string;
55
+ requestId?: string;
56
+ } | {
57
+ status: 'denied' | 'cancelled';
58
+ authKeyId: string;
59
+ requestId: string;
60
+ } | {
61
+ status: 'expired';
62
+ authKeyId: string;
63
+ requestId: string;
64
+ expiresAt: string;
65
+ } | {
66
+ status: 'unrecognized';
67
+ authKeyId: string;
68
+ rawValue: string;
69
+ }>;
@@ -0,0 +1,19 @@
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 });
@@ -0,0 +1,121 @@
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 { DaaTransport } from '../transport/DaaTransport';
19
+ import type { OwnerAuthKey } from '../securekey/SecureKey';
20
+ /**
21
+ * A new device's registration on an account that already has a device: DAA
22
+ * added this AuthKey as waiting for approval, and an existing device must
23
+ * approve it before it can sign.
24
+ *
25
+ * The app calls {@link sendCodeSecret}, which is what makes DAA tell the
26
+ * partner (`account.device.pending` webhook) to prompt the existing device,
27
+ * and shows {@link getMatchingCode} on this device. The user types the code on
28
+ * the existing device, which approves after checking that the typed code is
29
+ * the one this device's code secret produces. The key can't sign anything
30
+ * until then, and DAA cancels the request at `expiresAt`. Follow the request
31
+ * with `DaaClient.watchDeviceStatus({ authKeyId })`.
32
+ *
33
+ * The code secret is kept with the AuthKey (Keychain on iOS, Keystore-encrypted
34
+ * storage on Android) until DAA says no request is waiting for it, or until
35
+ * {@link sendCodeSecret} sends it. It leaves the device only through
36
+ * {@link sendCodeSecret}, for this request only.
37
+ *
38
+ * If the app discards this object, or restarts, signing in again before
39
+ * `expiresAt` returns the same request and the same code. Once
40
+ * {@link sendCodeSecret} has run, the secret is kept in process memory only:
41
+ * after a restart a sign-in before `expiresAt` still returns the same request,
42
+ * but this device no longer holds the secret its seal commits to. DAA returns
43
+ * that seal, so this SDK can tell: {@link getMatchingCode} and
44
+ * {@link sendCodeSecret} then throw `matching_code_unavailable` and nothing is
45
+ * sent. Have the user wait until `expiresAt` and sign in again.
46
+ *
47
+ * Not constructible by a consumer: exported from `index.ts` as a type only.
48
+ */
49
+ export declare class PendingDeviceApproval {
50
+ #private;
51
+ /** The add-a-device request this device waits on. */
52
+ readonly requestId: string;
53
+ /** This device's new AuthKey id. It can't sign until the request is approved. */
54
+ readonly authKeyId: string;
55
+ /** When DAA cancels the request unless it was approved, as ISO-8601 text. */
56
+ readonly expiresAt: string;
57
+ /** @internal Constructed only by `PendingDeviceRegistration.complete`. */
58
+ constructor(token: symbol, fields: {
59
+ readonly requestId: string;
60
+ readonly authKeyId: string;
61
+ readonly expiresAt: string;
62
+ readonly codeNonce: string;
63
+ readonly authKeyThumbprint: string;
64
+ readonly authKey: OwnerAuthKey;
65
+ readonly codeSecret: Uint8Array | null;
66
+ readonly transport: DaaTransport;
67
+ });
68
+ /**
69
+ * The six digits to show on this device, such as `"482913"`. Show them with
70
+ * a space in the middle (`482 913`); the approving device ignores spaces and
71
+ * dashes in what the user types. The same value every time.
72
+ *
73
+ * @throws DaaError with `detail.kind === 'matching_code_unavailable'` when
74
+ * DAA's seal for this request isn't one this device holds the secret for
75
+ * (the app restarted after the secret was sent): no code it shows
76
+ * could match. Tell the user to wait until `expiresAt` and sign in again.
77
+ */
78
+ getMatchingCode(): string;
79
+ /**
80
+ * Send this device's code secret to DAA for this request:
81
+ * `POST /v1/accounts/auth/devices/{authKeyId}/codeSecret`. DAA checks it
82
+ * against the seal this device signed into its registration, stores it, and
83
+ * sends the `account.device.pending` webhook so the partner can prompt the
84
+ * existing device. Until it is sent, the existing device can't check the
85
+ * code. Call it once the request is `PENDING_APPROVAL`, before or while
86
+ * showing {@link getMatchingCode}.
87
+ *
88
+ * Safe to call again: DAA accepts the same secret for the same request again
89
+ * (`204`) and re-sends the webhook while the request is waiting. That is the
90
+ * retry for a `500` or a transport failure, which may mean the secret was
91
+ * saved but the webhook was not sent.
92
+ *
93
+ * Once sent, this SDK never seals the secret into another request: the
94
+ * key's next registration seals a new one (a registration that timed out
95
+ * before the send may still reach DAA later with it; see `codeSecrets.ts`). If DAA answers that registration with
96
+ * this same request (it was still waiting), the code still comes from this
97
+ * secret. Waits for any registration of this key in flight: if DAA answers it
98
+ * with a different request, or doesn't answer, this request is no longer the
99
+ * one the secret is sealed into, and nothing is sent.
100
+ *
101
+ * @throws DaaError with `detail.kind === 'transport'` (retryable) when the
102
+ * transport throws; `api` for any status but `204`: retryable for `429`
103
+ * and `5xx` (call again), and not retryable for the `409` with
104
+ * `DEVICE_APPROVAL_INVALID` (`420117`), which DAA returns when this is no
105
+ * longer the key's latest request, the request has ended, or the secret
106
+ * doesn't match the seal; `contract_violation` (not retryable, nothing
107
+ * sent) when this SDK already knows the request is not the one the secret
108
+ * is sealed into: a later sign-in of this key returned another request or
109
+ * got no answer, or DAA said no request is waiting for the key. Sign in
110
+ * again for the current request. `matching_code_unavailable` (nothing
111
+ * sent), as for {@link getMatchingCode}: this device doesn't hold the
112
+ * secret DAA's seal for the request commits to. A secure-key error kind
113
+ * (nothing sent, call again) when deleting the secret from the AuthKey's
114
+ * storage failed, or `transport` (retryable, nothing sent) when that
115
+ * delete didn't finish within 5 seconds: it is deleted before the send so
116
+ * it is never sealed into another request, even after a restart.
117
+ */
118
+ sendCodeSecret(): Promise<void>;
119
+ }
120
+ /** @internal */
121
+ export declare function newPendingDeviceApproval(fields: ConstructorParameters<typeof PendingDeviceApproval>[1]): PendingDeviceApproval;