@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
|
@@ -0,0 +1,250 @@
|
|
|
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
|
+
import type { Money } from './Money'
|
|
20
|
+
import { REDACTED } from './redaction'
|
|
21
|
+
|
|
22
|
+
// A DAA contract execution, as `POST /v1/accounts/contractExecutions` and
|
|
23
|
+
// `GET /v1/accounts/contractExecutions/{id}` report it.
|
|
24
|
+
//
|
|
25
|
+
// Same posture as `Transfer`: closed-set fields are discriminated unions on
|
|
26
|
+
// `kind`, so a value the service adds later degrades to `unrecognized` instead
|
|
27
|
+
// of failing the whole read. The invocation, target address, and transaction
|
|
28
|
+
// hash are held behind `#` private fields and redacted from every default
|
|
29
|
+
// rendering — the call inputs can carry recipient addresses and amounts.
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Where an execution is in its lifecycle.
|
|
33
|
+
*
|
|
34
|
+
* `pending` covers every state before a final provider result, including a
|
|
35
|
+
* submission whose outcome is still being recovered: a timeout is not a
|
|
36
|
+
* failure. Poll {@link ContractExecutionsClient.get} until `complete` or
|
|
37
|
+
* `failed`.
|
|
38
|
+
*/
|
|
39
|
+
export type ContractExecutionStatus =
|
|
40
|
+
| { readonly kind: 'pending' }
|
|
41
|
+
/** Terminal: the provider reported final success. */
|
|
42
|
+
| { readonly kind: 'complete' }
|
|
43
|
+
/** Terminal: see {@link ContractExecutionErrorCode}. */
|
|
44
|
+
| { readonly kind: 'failed' }
|
|
45
|
+
| { readonly kind: 'unrecognized'; readonly rawValue: string | null }
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Why an execution failed, present only when the status is `failed`.
|
|
49
|
+
*
|
|
50
|
+
* - `authorization_failed`: DAA rejected the Owner proof before the
|
|
51
|
+
* call was signed. No hash or fee.
|
|
52
|
+
* - `execution_denied`: the Owner proof was valid but execution or fee policy
|
|
53
|
+
* denied the call. No hash or fee.
|
|
54
|
+
* - `insufficient_funds`: the account could not fund the native `amount`.
|
|
55
|
+
* - `insufficient_network_fee`: the provider could not fund the network fee.
|
|
56
|
+
* - `blockchain_error`: the call was included and reverted. The hash and the
|
|
57
|
+
* fee it cost are retained.
|
|
58
|
+
* - `contract_execution_failed`: any other definitive failure.
|
|
59
|
+
*
|
|
60
|
+
* An open set, like every other closed set here: a code this SDK has not
|
|
61
|
+
* shipped for reads as `unrecognized`, not as a failed decode.
|
|
62
|
+
*/
|
|
63
|
+
export type ContractExecutionErrorCode =
|
|
64
|
+
| { readonly kind: 'authorization_failed' }
|
|
65
|
+
| { readonly kind: 'execution_denied' }
|
|
66
|
+
| { readonly kind: 'insufficient_funds' }
|
|
67
|
+
| { readonly kind: 'insufficient_network_fee' }
|
|
68
|
+
| { readonly kind: 'blockchain_error' }
|
|
69
|
+
| { readonly kind: 'contract_execution_failed' }
|
|
70
|
+
| { readonly kind: 'unrecognized'; readonly rawValue: string | null }
|
|
71
|
+
|
|
72
|
+
/** The executing account. */
|
|
73
|
+
export type ContractExecutionSource =
|
|
74
|
+
| {
|
|
75
|
+
readonly kind: 'account'
|
|
76
|
+
/** Named `accountId` (the wire spells it `id`) so it is not confused with the execution's own `id`. */
|
|
77
|
+
readonly accountId: string
|
|
78
|
+
}
|
|
79
|
+
| { readonly kind: 'unrecognized'; readonly rawValue: string | null }
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* One ABI input value: a string, a boolean, a safe integer, or an array of
|
|
83
|
+
* those.
|
|
84
|
+
*
|
|
85
|
+
* Integers that do not fit in a JavaScript safe integer — most `uint256`
|
|
86
|
+
* values — are decimal **strings**. A JSON number outside
|
|
87
|
+
* `Number.MIN_SAFE_INTEGER..Number.MAX_SAFE_INTEGER` is refused in either
|
|
88
|
+
* direction, because `JSON.parse` and `JSON.stringify` round it before any
|
|
89
|
+
* code here can see it, and the rounded value is not the one the Owner
|
|
90
|
+
* authorized. An integer-looking string stays a string; the SDK never
|
|
91
|
+
* converts between the two.
|
|
92
|
+
*/
|
|
93
|
+
export type AbiParameter = string | number | boolean | readonly AbiParameter[]
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* The accepted invocation, in the mode it was requested in. DAA never converts
|
|
97
|
+
* one mode to the other and never returns encoded call data for an ABI request.
|
|
98
|
+
*/
|
|
99
|
+
export type ContractExecutionInvocation =
|
|
100
|
+
| { readonly kind: 'raw'; readonly callData: string }
|
|
101
|
+
| {
|
|
102
|
+
readonly kind: 'abi'
|
|
103
|
+
readonly abiFunctionSignature: string
|
|
104
|
+
readonly abiParameters: readonly AbiParameter[]
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** The redacted shape `JSON.stringify(execution)` produces. */
|
|
108
|
+
export type ContractExecutionRendering = {
|
|
109
|
+
readonly id: string
|
|
110
|
+
readonly status: ContractExecutionStatus
|
|
111
|
+
readonly errorCode: ContractExecutionErrorCode | null
|
|
112
|
+
readonly source: ContractExecutionSource
|
|
113
|
+
readonly custodyType: string
|
|
114
|
+
readonly blockchain: string
|
|
115
|
+
readonly contractAddress: string
|
|
116
|
+
readonly invocation: { readonly kind: 'raw' | 'abi'; readonly inputs: string }
|
|
117
|
+
readonly amount: { readonly amount: string; readonly currency: string }
|
|
118
|
+
readonly networkFee: { readonly amount: string; readonly currency: string } | null
|
|
119
|
+
readonly transactionHash: string | null
|
|
120
|
+
readonly createDate: string
|
|
121
|
+
readonly updateDate: string
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* A DAA contract execution.
|
|
126
|
+
*
|
|
127
|
+
* **Guaranteed fields** are `id`, `status`, `source`, `custodyType`,
|
|
128
|
+
* `blockchain`, `contractAddress`, the invocation, `amount`, `createDate`, and
|
|
129
|
+
* `updateDate`. `amount` is the native value attached to the call — zero when
|
|
130
|
+
* the request omitted it — and on a failed execution it describes what was
|
|
131
|
+
* requested, not what moved. `transactionHash` and `networkFee` are present
|
|
132
|
+
* once known, including for a reverted call; `networkFee` is the actual chain
|
|
133
|
+
* cost, not what the customer is billed. `errorCode` is present only when the
|
|
134
|
+
* status is `failed`.
|
|
135
|
+
*
|
|
136
|
+
* `blockchain` and `custodyType` are plain strings on a read, for the reason
|
|
137
|
+
* `Account.blockchain` is: a later service value must not make the execution
|
|
138
|
+
* unreadable. `blockchain` is the service's chain name exactly as sent, which
|
|
139
|
+
* need not be the request's spelling of the same chain (Base is `CBASE` in a
|
|
140
|
+
* request); compare chains through the account, not by string.
|
|
141
|
+
*
|
|
142
|
+
* **No default rendering prints the call.** `contractAddress`, the invocation,
|
|
143
|
+
* `transactionHash`, and both amounts sit behind prototype accessors; `toJSON`
|
|
144
|
+
* and `toString` report only identifiers, states, and the invocation mode.
|
|
145
|
+
*
|
|
146
|
+
* Not constructible by a consumer: exported from `index.ts` as a type only, and
|
|
147
|
+
* the `#` private fields make the type nominal.
|
|
148
|
+
*/
|
|
149
|
+
export class ContractExecution {
|
|
150
|
+
readonly id: string
|
|
151
|
+
readonly status: ContractExecutionStatus
|
|
152
|
+
readonly errorCode: ContractExecutionErrorCode | null
|
|
153
|
+
readonly source: ContractExecutionSource
|
|
154
|
+
readonly custodyType: string
|
|
155
|
+
readonly blockchain: string
|
|
156
|
+
readonly createDate: string
|
|
157
|
+
readonly updateDate: string
|
|
158
|
+
readonly #contractAddress: string
|
|
159
|
+
readonly #invocation: ContractExecutionInvocation
|
|
160
|
+
readonly #amount: Money
|
|
161
|
+
readonly #networkFee: Money | null
|
|
162
|
+
readonly #transactionHash: string | null
|
|
163
|
+
|
|
164
|
+
/** @internal Constructed only by the SDK's response decoder. */
|
|
165
|
+
constructor(fields: {
|
|
166
|
+
readonly id: string
|
|
167
|
+
readonly status: ContractExecutionStatus
|
|
168
|
+
readonly errorCode: ContractExecutionErrorCode | null
|
|
169
|
+
readonly source: ContractExecutionSource
|
|
170
|
+
readonly custodyType: string
|
|
171
|
+
readonly blockchain: string
|
|
172
|
+
readonly contractAddress: string
|
|
173
|
+
readonly invocation: ContractExecutionInvocation
|
|
174
|
+
readonly amount: Money
|
|
175
|
+
readonly networkFee: Money | null
|
|
176
|
+
readonly transactionHash: string | null
|
|
177
|
+
readonly createDate: string
|
|
178
|
+
readonly updateDate: string
|
|
179
|
+
}) {
|
|
180
|
+
this.id = fields.id
|
|
181
|
+
this.status = fields.status
|
|
182
|
+
this.errorCode = fields.errorCode
|
|
183
|
+
this.source = fields.source
|
|
184
|
+
this.custodyType = fields.custodyType
|
|
185
|
+
this.blockchain = fields.blockchain
|
|
186
|
+
this.createDate = fields.createDate
|
|
187
|
+
this.updateDate = fields.updateDate
|
|
188
|
+
this.#contractAddress = fields.contractAddress
|
|
189
|
+
this.#invocation = fields.invocation
|
|
190
|
+
this.#amount = fields.amount
|
|
191
|
+
this.#networkFee = fields.networkFee
|
|
192
|
+
this.#transactionHash = fields.transactionHash
|
|
193
|
+
Object.freeze(this)
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** The target contract address, exactly as the service sent it. */
|
|
197
|
+
get contractAddress(): string {
|
|
198
|
+
return this.#contractAddress
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** The accepted invocation. Deeply frozen. */
|
|
202
|
+
get invocation(): ContractExecutionInvocation {
|
|
203
|
+
return this.#invocation
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** Native value attached to the call; zero when the request omitted it. */
|
|
207
|
+
get amount(): Money {
|
|
208
|
+
return this.#amount
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** Actual network cost once known, including for a reverted call; otherwise `null`. */
|
|
212
|
+
get networkFee(): Money | null {
|
|
213
|
+
return this.#networkFee
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** On-chain transaction hash once known, including for a reverted call; otherwise `null`. */
|
|
217
|
+
get transactionHash(): string | null {
|
|
218
|
+
return this.#transactionHash
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** Identifiers, states, and the invocation mode render; the call itself does not. */
|
|
222
|
+
toJSON(): ContractExecutionRendering {
|
|
223
|
+
return {
|
|
224
|
+
id: this.id,
|
|
225
|
+
status: this.status,
|
|
226
|
+
errorCode: this.errorCode,
|
|
227
|
+
source: this.source,
|
|
228
|
+
custodyType: this.custodyType,
|
|
229
|
+
blockchain: this.blockchain,
|
|
230
|
+
contractAddress: REDACTED,
|
|
231
|
+
invocation: { kind: this.#invocation.kind, inputs: REDACTED },
|
|
232
|
+
amount: this.#amount.toJSON(),
|
|
233
|
+
networkFee: this.#networkFee === null ? null : this.#networkFee.toJSON(),
|
|
234
|
+
transactionHash: this.#transactionHash === null ? null : REDACTED,
|
|
235
|
+
createDate: this.createDate,
|
|
236
|
+
updateDate: this.updateDate,
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** Identifiers, states, and the invocation mode print; the call itself does not. */
|
|
241
|
+
toString(): string {
|
|
242
|
+
return (
|
|
243
|
+
`ContractExecution(id=${this.id}, status=${this.status.kind}, ` +
|
|
244
|
+
`errorCode=${this.errorCode === null ? 'null' : this.errorCode.kind}, ` +
|
|
245
|
+
`blockchain=${this.blockchain}, invocation=${this.#invocation.kind}, ` +
|
|
246
|
+
`amount=${this.#amount.toString()}, createDate=${this.createDate}, ` +
|
|
247
|
+
`updateDate=${this.updateDate})`
|
|
248
|
+
)
|
|
249
|
+
}
|
|
250
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
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
|
+
import type { AbiParameter } from './ContractExecution'
|
|
20
|
+
|
|
21
|
+
// The body of a signed contract execution create.
|
|
22
|
+
//
|
|
23
|
+
// Shaped from the Owner-authorization registry's `contract_execution` entry,
|
|
24
|
+
// for the reason `CreateAccountRequest` sets out: the registry is what DAA
|
|
25
|
+
// validates the signed bytes against, so it decides what may be sent.
|
|
26
|
+
// The registry entry is a `oneOf` of two arms — raw `callData`, or
|
|
27
|
+
// `abiFunctionSignature` plus `abiParameters` — and both arms are
|
|
28
|
+
// `additionalProperties: false`. There is deliberately no fee, gas, or nonce
|
|
29
|
+
// field: DAA selects the execution fee policy itself, and a caller-supplied
|
|
30
|
+
// fee option is rejected rather than dropped.
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The EVM chains the registry's `contract_execution` schema names.
|
|
34
|
+
*
|
|
35
|
+
* A closed set here, unlike `Account.blockchain` on a read, because this is a
|
|
36
|
+
* request: the registry types `blockchain` as this exact enum, so a value
|
|
37
|
+
* outside it cannot be signed into a body DAA accepts. The set is an
|
|
38
|
+
* upper bound; DAA still checks that the chain is enabled for the account and
|
|
39
|
+
* environment, and that it is the account's own chain.
|
|
40
|
+
*/
|
|
41
|
+
export type ContractExecutionBlockchain = 'ETH' | 'ARB' | 'CBASE' | 'OP' | 'UNI' | 'ARC'
|
|
42
|
+
|
|
43
|
+
/** Fields both invocation modes share, in the registry's order. */
|
|
44
|
+
type CreateContractExecutionCommon = Readonly<{
|
|
45
|
+
/**
|
|
46
|
+
* UUID v4 identifying this execution attempt. Persist it with the prepared
|
|
47
|
+
* execution and never reuse it with different body bytes — the authorization
|
|
48
|
+
* JWS carries this same value as its `idempotency_key` claim.
|
|
49
|
+
*/
|
|
50
|
+
idempotencyKey: string
|
|
51
|
+
/** The self-custody DAA account that executes the call. A UUID. */
|
|
52
|
+
accountId: string
|
|
53
|
+
/** Must be the account's own chain. It does not select a network. */
|
|
54
|
+
blockchain: ContractExecutionBlockchain
|
|
55
|
+
/** Target contract: `0x` and 40 hex digits, not the zero address. */
|
|
56
|
+
contractAddress: string
|
|
57
|
+
/**
|
|
58
|
+
* Native value attached to the call, in whole native-asset units (ETH, or
|
|
59
|
+
* native USD on Arc), as a decimal string such as `"0.1"`.
|
|
60
|
+
*
|
|
61
|
+
* Optional. Omitted, it is **not sent**: DAA treats an absent value as zero,
|
|
62
|
+
* and an absent value and an explicit `"0"` are different signed bodies.
|
|
63
|
+
* This is never an ERC-20 quantity (that is an ABI argument) and never the
|
|
64
|
+
* network fee.
|
|
65
|
+
*/
|
|
66
|
+
amount?: string
|
|
67
|
+
}>
|
|
68
|
+
|
|
69
|
+
/** Raw mode: the exact call data to submit. */
|
|
70
|
+
export type CreateContractExecutionRawRequest = CreateContractExecutionCommon &
|
|
71
|
+
Readonly<{
|
|
72
|
+
/** `0x`-prefixed, even-length hex; at least one and at most 16384 bytes. */
|
|
73
|
+
callData: string
|
|
74
|
+
abiFunctionSignature?: never
|
|
75
|
+
abiParameters?: never
|
|
76
|
+
}>
|
|
77
|
+
|
|
78
|
+
/** ABI mode: a canonical function signature and its inputs. */
|
|
79
|
+
export type CreateContractExecutionAbiRequest = CreateContractExecutionCommon &
|
|
80
|
+
Readonly<{
|
|
81
|
+
/**
|
|
82
|
+
* Canonical Solidity signature, such as `approve(address,uint256)`: no
|
|
83
|
+
* whitespace, parameter names, aliases (`uint`, `int`, `byte`), tuples, or
|
|
84
|
+
* fixed-point types. A non-canonical spelling is rejected, never repaired.
|
|
85
|
+
*/
|
|
86
|
+
abiFunctionSignature: string
|
|
87
|
+
/** Inputs in signature order; `[]` for a function with no arguments. */
|
|
88
|
+
abiParameters: readonly AbiParameter[]
|
|
89
|
+
callData?: never
|
|
90
|
+
}>
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Body for creating a contract execution: exactly one invocation mode.
|
|
94
|
+
*
|
|
95
|
+
* Every field is checked before the body is serialized, and the serialized
|
|
96
|
+
* bytes are the ones signed and sent. An unrecognized property — including a
|
|
97
|
+
* fee or gas option — is rejected rather than dropped.
|
|
98
|
+
*/
|
|
99
|
+
export type CreateContractExecutionRequest =
|
|
100
|
+
CreateContractExecutionRawRequest | CreateContractExecutionAbiRequest
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
import { isUuid } from '../validation/uuid'
|
|
20
20
|
import { contractViolation } from '../errors'
|
|
21
21
|
import type { OwnerAuthKey } from '../securekey/SecureKey'
|
|
22
|
+
import type { PendingDeviceApproval } from './PendingDeviceApproval'
|
|
22
23
|
|
|
23
24
|
/** RFC 7638 P-256 JWK thumbprints are 32-byte unpadded Base64URL digests. */
|
|
24
25
|
const JWK_THUMBPRINT = /^[A-Za-z0-9_-]{43}$/
|
|
@@ -26,7 +27,8 @@ const JWK_THUMBPRINT = /^[A-Za-z0-9_-]{43}$/
|
|
|
26
27
|
/**
|
|
27
28
|
* Owner-bound local SDK context: `DaaUserContext`.
|
|
28
29
|
*
|
|
29
|
-
* Produced only by an `ACTIVE` Device Registration Complete
|
|
30
|
+
* Produced only by an `ACTIVE` Device Registration Complete, or by
|
|
31
|
+
* `DaaClient.restore` for a key such a Complete registered. It is not a DAA
|
|
30
32
|
* bearer token or an application session. The `#` private field makes the type
|
|
31
33
|
* nominal: an object literal cannot be typed or passed as one, so `forUser`
|
|
32
34
|
* cannot be opened with a fabricated context. The constructor is also brand-
|
|
@@ -56,8 +58,21 @@ export type DeviceContext = Readonly<{
|
|
|
56
58
|
* call it directly, with no import of this module at all. Requiring this
|
|
57
59
|
* exact `Symbol` as the constructor's first argument closes that path —
|
|
58
60
|
* `ctx.constructor` is reachable, but constructing anything with it throws
|
|
59
|
-
* unless the caller already holds this token
|
|
60
|
-
*
|
|
61
|
+
* unless the caller already holds this token. Three entry points use it:
|
|
62
|
+
*
|
|
63
|
+
* 1. the Device Registration Complete decoder in
|
|
64
|
+
* `../wire/deviceRegistrationResultPayload.ts`;
|
|
65
|
+
* 2. {@link bindAuthKeyToContext} below, which re-mints that same context
|
|
66
|
+
* paired with the AuthKey that authorized Complete;
|
|
67
|
+
* 3. {@link restoreDaaUserContext} below, used only by `DaaClient.restore`.
|
|
68
|
+
*
|
|
69
|
+
* The third is safe for the same reason as the first: it mints only from a
|
|
70
|
+
* `DeviceContext` the service returned to a registered-device authorization
|
|
71
|
+
* signed by the stored AuthKey (`get_device_context`), decoded by the same
|
|
72
|
+
* `toDeviceContext`, whose `authKeyId` `DaaClient.restore` has already checked
|
|
73
|
+
* equals the one stored with that key, and it binds the context to that key's
|
|
74
|
+
* thumbprint exactly as Complete does. The token stays inside this module: the
|
|
75
|
+
* restore path calls the factory rather than holding the token itself.
|
|
61
76
|
*
|
|
62
77
|
* Exported so those wire decoders can import it, but never re-exported from
|
|
63
78
|
* `index.ts` — the package's `exports` map has no entry for this module's
|
|
@@ -144,6 +159,28 @@ export function bindAuthKeyToContext(
|
|
|
144
159
|
)
|
|
145
160
|
}
|
|
146
161
|
|
|
162
|
+
/**
|
|
163
|
+
* Mint the `ACTIVE` context for a restored session.
|
|
164
|
+
*
|
|
165
|
+
* Reached only from `DaaClient.restore`, after the service answered a
|
|
166
|
+
* `get_device_context` request signed by the stored AuthKey and the returned
|
|
167
|
+
* `authKeyId` matched the stored one. Like {@link bindAuthKeyToContext}, the
|
|
168
|
+
* result is paired with that AuthKey's thumbprint, so `forUser` re-checks on
|
|
169
|
+
* every signed operation that it still resolves the same key. All the
|
|
170
|
+
* constructor's own invariants (UUID `clientEntityId`, `active` status, UUID
|
|
171
|
+
* `authKeyId`, well-formed thumbprint) apply unchanged.
|
|
172
|
+
*
|
|
173
|
+
* Kept here, rather than exporting {@link DECODER_TOKEN} to the restore path,
|
|
174
|
+
* so the brand never leaves the modules that decode or bind a context.
|
|
175
|
+
*/
|
|
176
|
+
export function restoreDaaUserContext(
|
|
177
|
+
clientEntityId: string,
|
|
178
|
+
deviceContext: DeviceContext,
|
|
179
|
+
authKeyThumbprint: string,
|
|
180
|
+
): DaaUserContext {
|
|
181
|
+
return new DaaUserContext(DECODER_TOKEN, { clientEntityId, deviceContext }, authKeyThumbprint)
|
|
182
|
+
}
|
|
183
|
+
|
|
147
184
|
/** Fail closed when the local key no longer matches the key paired at Complete. */
|
|
148
185
|
export async function assertAuthKeyMatchesContext(
|
|
149
186
|
context: DaaUserContext,
|
|
@@ -163,8 +200,27 @@ export function isActiveDaaUserContext(value: unknown): value is DaaUserContext
|
|
|
163
200
|
return value instanceof DaaUserContext && value.isActive()
|
|
164
201
|
}
|
|
165
202
|
|
|
203
|
+
/**
|
|
204
|
+
* What Device Registration Complete returns: an ACTIVE context (a first device,
|
|
205
|
+
* or a key the account already holds); for a new device on an account that
|
|
206
|
+
* already has one, `PENDING_APPROVAL` with the matching code to show; for a
|
|
207
|
+
* device already approved from another device but still in the account's
|
|
208
|
+
* cool-down, `PENDING_ACTIVATION` with `readyAt` (no context: it can't sign
|
|
209
|
+
* until then; `DaaClient.restore` returns its context once it can); or the
|
|
210
|
+
* non-authorizing `RECOVERY_PENDING`, which `/v1/accounts/auth/keys` never
|
|
211
|
+
* returns and this SDK never produces. It stays in the type so a consumer's
|
|
212
|
+
* exhaustive `switch` keeps compiling.
|
|
213
|
+
*/
|
|
166
214
|
export type DeviceRegistrationResult =
|
|
167
215
|
| Readonly<{ status: 'ACTIVE'; context: DaaUserContext }>
|
|
216
|
+
| Readonly<{ status: 'PENDING_APPROVAL'; pendingApproval: PendingDeviceApproval }>
|
|
217
|
+
| Readonly<{
|
|
218
|
+
status: 'PENDING_ACTIVATION'
|
|
219
|
+
/** The key's id: follow it with `DaaClient.watchDeviceStatus`. */
|
|
220
|
+
authKeyId: string
|
|
221
|
+
/** When the cool-down ends and the key may sign, as ISO-8601 text. */
|
|
222
|
+
readyAt: string
|
|
223
|
+
}>
|
|
168
224
|
| Readonly<{
|
|
169
225
|
status: 'RECOVERY_PENDING'
|
|
170
226
|
recoveryReference: string
|
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
/**
|
|
20
|
+
* A new device's add-a-device status, as the status route
|
|
21
|
+
* (`GET /v1/accounts/auth/devices/{authKeyId}`) reports it.
|
|
22
|
+
*
|
|
23
|
+
* - `pending_approval`: waiting for an existing device, until `expiresAt`.
|
|
24
|
+
* - `pending_activation`: approved, in the account's cool-down until
|
|
25
|
+
* `readyAt`. The key can't sign yet.
|
|
26
|
+
* - `active`: the key can sign.
|
|
27
|
+
* - `denied`: the user declined it with Not me on another device. The key
|
|
28
|
+
* can't ask again; see `DaaClient.forgetLocalKey`.
|
|
29
|
+
* - `expired`: nobody approved it before `expiresAt`.
|
|
30
|
+
* - `cancelled`: DAA closed the request, for example because another new
|
|
31
|
+
* device was waiting at the same time.
|
|
32
|
+
* - `unrecognized`: a status this SDK version doesn't know, as DAA sent it in
|
|
33
|
+
* `rawValue`. DAA may add statuses before every app updates, so this is not
|
|
34
|
+
* an error; treat it as "can't tell yet" and don't act on the key.
|
|
35
|
+
*
|
|
36
|
+
* These are DAA's own spellings (lowercase), unlike
|
|
37
|
+
* `DeviceRegistrationResult.status` (`'PENDING_APPROVAL'`), which is this
|
|
38
|
+
* SDK's result type for `complete()`.
|
|
39
|
+
*
|
|
40
|
+
* `requestId` is the add-a-device request; a key that never had one (a first
|
|
41
|
+
* device) reads as `active` without it.
|
|
42
|
+
*/
|
|
43
|
+
export type DeviceStatus = Readonly<
|
|
44
|
+
| { status: 'pending_approval'; authKeyId: string; requestId: string; expiresAt: string }
|
|
45
|
+
| { status: 'pending_activation'; authKeyId: string; requestId?: string; readyAt: string }
|
|
46
|
+
| { status: 'active'; authKeyId: string; requestId?: string }
|
|
47
|
+
| { status: 'denied' | 'cancelled'; authKeyId: string; requestId: string }
|
|
48
|
+
| { status: 'expired'; authKeyId: string; requestId: string; expiresAt: string }
|
|
49
|
+
| { status: 'unrecognized'; authKeyId: string; rawValue: string }
|
|
50
|
+
>
|