@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
@@ -1,240 +0,0 @@
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
- // Compact ES256 JWS verification against a pinned key set.
20
- //
21
- // This file does the structural work only. The signature itself is checked by
22
- // the native SDKs' `DaaPrepareReceiptSignature` — CryptoKit on iOS,
23
- // `java.security` on Android — through the Expo `DaaRegistration` module;
24
- // there is no curve arithmetic in TypeScript.
25
- // Node/Jest has no native module, so `jest.setup.js` stands in with WebCrypto,
26
- // the same arrangement `crypto/random.ts` uses. A React Native host without the
27
- // module fails closed.
28
- //
29
- // What this file enforces, and why each rule is here:
30
- //
31
- // - `alg` must be exactly `ES256`. It is compared against a fixed allowlist and
32
- // never obeyed, which closes `alg: none` and algorithm confusion by
33
- // construction.
34
- // - `typ` must be the value the caller expects, so a JWS minted for another
35
- // purpose under the same key does not verify as this one.
36
- // - No key is ever taken from the token. `jwk`/`jku`/`x5u`/`x5c` are rejected
37
- // outright, even on a token that would verify. `kid` selects among the keys
38
- // the caller pinned and nothing else: an unknown `kid` is a rejection, not a
39
- // fetch.
40
- // - Any `crit` is rejected: this module understands no extension.
41
- // - The signature must decode to exactly 64 bytes (JOSE `R || S`) before the
42
- // platform is called.
43
- // - The payload is parsed only after the signature verifies, so unverified
44
- // claims never reach a caller.
45
- //
46
- // Rejections are a closed set of this module's own literals, so a caller can
47
- // say why a token was refused without reflecting attacker-supplied text into a
48
- // message a host app is likely to log.
49
-
50
- import {
51
- nativeVerifyPrepareReceiptSignature,
52
- requireDaaRegistrationNative,
53
- } from '../auth/daaRegistrationNative'
54
- import { contractViolation } from '../errors'
55
- import { fromBase64Url } from './base64url'
56
-
57
- /**
58
- * The one algorithm this SDK verifies. Every additional entry is another
59
- * verification path, so the list holds only ES256.
60
- */
61
- export const SUPPORTED_JWS_ALGORITHMS: readonly string[] = Object.freeze(['ES256'])
62
-
63
- /** JOSE `R || S` for P-256: two 32-byte big-endian scalars. */
64
- export const ES256_SIGNATURE_LENGTH = 64
65
-
66
- /** Uncompressed SEC 1 point: `0x04 || X(32) || Y(32)`. */
67
- const X963_LENGTH = 65
68
-
69
- /** Header members that carry or locate a key. Never honoured; always rejected. */
70
- const KEY_SOURCING_HEADERS: readonly string[] = Object.freeze(['jwk', 'jku', 'x5u', 'x5c'])
71
-
72
- /** A verification key the caller pinned, addressed by its `kid`. */
73
- export type PinnedEs256Key = Readonly<{
74
- kid: string
75
- /** Uncompressed P-256 point. The platform validates it is on the curve. */
76
- publicKeyX963: Uint8Array
77
- }>
78
-
79
- export type Es256JwsRejection =
80
- | 'malformed_compact_serialization'
81
- | 'malformed_protected_header'
82
- | 'unsupported_algorithm'
83
- | 'unexpected_type'
84
- | 'header_sources_a_key'
85
- | 'unsupported_critical_header'
86
- | 'missing_key_id'
87
- | 'unknown_key_id'
88
- | 'malformed_signature'
89
- | 'signature_mismatch'
90
- | 'malformed_payload'
91
-
92
- export type Es256JwsResult =
93
- | Readonly<{
94
- verified: true
95
- protectedHeader: Readonly<Record<string, unknown>>
96
- payload: Readonly<Record<string, unknown>>
97
- }>
98
- | Readonly<{ verified: false; reason: Es256JwsRejection }>
99
-
100
- function rejected(reason: Es256JwsRejection): Es256JwsResult {
101
- return { verified: false, reason }
102
- }
103
-
104
- /** Own-property read, so a name on `Object.prototype` never reads as a member. */
105
- export function ownMember(object: Readonly<Record<string, unknown>>, name: string): unknown {
106
- return Object.prototype.hasOwnProperty.call(object, name) ? object[name] : undefined
107
- }
108
-
109
- /** Decode one Base64URL segment as a UTF-8 JSON object, or `null`. */
110
- function decodeJsonObject(segment: string): Record<string, unknown> | null {
111
- let bytes: Uint8Array
112
- try {
113
- bytes = fromBase64Url(segment)
114
- } catch {
115
- return null
116
- }
117
- let parsed: unknown
118
- try {
119
- parsed = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(bytes))
120
- } catch {
121
- return null
122
- }
123
- if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
124
- return null
125
- }
126
- return parsed as Record<string, unknown>
127
- }
128
-
129
- /**
130
- * Index the pinned keys by `kid`.
131
- *
132
- * A malformed key set is a configuration error on this side of the boundary,
133
- * so it throws rather than returning a rejection that would read as a bad token.
134
- */
135
- function indexPinnedKeys(keys: readonly PinnedEs256Key[]): ReadonlyMap<string, Uint8Array> {
136
- if (!Array.isArray(keys) || keys.length === 0) {
137
- throw contractViolation('ES256 verification requires at least one pinned key')
138
- }
139
- const byKid = new Map<string, Uint8Array>()
140
- for (const key of keys) {
141
- if (typeof key.kid !== 'string' || key.kid.length === 0) {
142
- throw contractViolation('every pinned ES256 key must have a non-empty kid')
143
- }
144
- if (byKid.has(key.kid)) {
145
- throw contractViolation('pinned ES256 keys must have distinct kids')
146
- }
147
- if (
148
- !(key.publicKeyX963 instanceof Uint8Array) ||
149
- key.publicKeyX963.length !== X963_LENGTH ||
150
- key.publicKeyX963[0] !== 0x04
151
- ) {
152
- throw contractViolation('every pinned ES256 key must be an uncompressed P-256 point')
153
- }
154
- byKid.set(key.kid, key.publicKeyX963)
155
- }
156
- return byKid
157
- }
158
-
159
- /**
160
- * Verify a compact JWS (`header.payload.signature`) against pinned P-256 keys.
161
- *
162
- * Length bounds are the caller's business: a caller with a contract bound (as
163
- * the Prepare receipt has) applies it first.
164
- *
165
- * @throws DaaError `contract_violation` for a malformed pinned key set, and when
166
- * the platform verifier is unavailable or fails — including a pinned key the
167
- * platform does not accept as a P-256 point. A token that is merely wrong is
168
- * a `{ verified: false }` result, not a throw.
169
- */
170
- export async function verifyCompactEs256(
171
- jws: string,
172
- options: Readonly<{ keys: readonly PinnedEs256Key[]; expectedTyp: string }>,
173
- ): Promise<Es256JwsResult> {
174
- const keysByKid = indexPinnedKeys(options.keys)
175
-
176
- const segments = jws.split('.')
177
- if (segments.length !== 3) {
178
- return rejected('malformed_compact_serialization')
179
- }
180
- const [encodedHeader, encodedPayload, encodedSignature] = segments as [string, string, string]
181
- if (encodedHeader === '' || encodedPayload === '' || encodedSignature === '') {
182
- return rejected('malformed_compact_serialization')
183
- }
184
-
185
- const header = decodeJsonObject(encodedHeader)
186
- if (header === null) {
187
- return rejected('malformed_protected_header')
188
- }
189
- for (const name of KEY_SOURCING_HEADERS) {
190
- if (Object.prototype.hasOwnProperty.call(header, name)) {
191
- return rejected('header_sources_a_key')
192
- }
193
- }
194
- if (Object.prototype.hasOwnProperty.call(header, 'crit')) {
195
- return rejected('unsupported_critical_header')
196
- }
197
- const algorithm = ownMember(header, 'alg')
198
- if (typeof algorithm !== 'string' || !SUPPORTED_JWS_ALGORITHMS.includes(algorithm)) {
199
- return rejected('unsupported_algorithm')
200
- }
201
- if (ownMember(header, 'typ') !== options.expectedTyp) {
202
- return rejected('unexpected_type')
203
- }
204
- const kid = ownMember(header, 'kid')
205
- if (typeof kid !== 'string' || kid.length === 0) {
206
- return rejected('missing_key_id')
207
- }
208
- const publicKeyX963 = keysByKid.get(kid)
209
- if (publicKeyX963 === undefined) {
210
- return rejected('unknown_key_id')
211
- }
212
-
213
- let signature: Uint8Array
214
- try {
215
- signature = fromBase64Url(encodedSignature)
216
- } catch {
217
- return rejected('malformed_signature')
218
- }
219
- if (signature.length !== ES256_SIGNATURE_LENGTH) {
220
- return rejected('malformed_signature')
221
- }
222
-
223
- // RFC 7515 §5.2: the signing input is the ASCII of the two encoded segments
224
- // exactly as received, never re-encoded from the parsed header.
225
- const signingInput = new TextEncoder().encode(`${encodedHeader}.${encodedPayload}`)
226
- const verified = await nativeVerifyPrepareReceiptSignature(requireDaaRegistrationNative(), {
227
- publicKeyX963,
228
- signingInput,
229
- signature,
230
- })
231
- if (!verified) {
232
- return rejected('signature_mismatch')
233
- }
234
-
235
- const payload = decodeJsonObject(encodedPayload)
236
- if (payload === null) {
237
- return rejected('malformed_payload')
238
- }
239
- return { verified: true, protectedHeader: header, payload }
240
- }