@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
@@ -15,7 +15,7 @@
15
15
  * See the License for the specific language governing permissions and
16
16
  * limitations under the License.
17
17
  */
18
- import type { AppKeyIdentity, OwnerAuthKey, SecureKeyStore } from './SecureKey';
18
+ import type { AppKeyIdentity, OwnerAuthKey, RegisteredOwnerAuthKey, SecureKeyStore } from './SecureKey';
19
19
  /**
20
20
  * Resolves the installation AuthKey for one already-known Owner.
21
21
  *
@@ -24,7 +24,7 @@ import type { AppKeyIdentity, OwnerAuthKey, SecureKeyStore } from './SecureKey';
24
24
  * its choosing, and no store to resolve a different one from. This is the
25
25
  * shape `DaaUserSigning.resolveAuthKey` (`api/signedResource.ts`) needs,
26
26
  * because by the time `forUser` builds one it already knows which Owner it is
27
- * signing for. It is NOT the shape {@link createOwnerAuthKeyResolver} returns
27
+ * signing for. It is NOT the shape {@link AppOwnerKeys.resolveOrCreate} has
28
28
  * — see {@link AppAuthKeyResolver}.
29
29
  */
30
30
  export type OwnerAuthKeyResolver = () => Promise<OwnerAuthKey>;
@@ -43,14 +43,31 @@ export type OwnerAuthKeyResolver = () => Promise<OwnerAuthKey>;
43
43
  */
44
44
  export type AppAuthKeyResolver = (clientEntityId: string) => Promise<OwnerAuthKey>;
45
45
  /**
46
- * Build the resolver for one application identity.
46
+ * Every AuthKey operation `DaaClient` needs for one application identity,
47
+ * over one shared store: login and `forUser` resolve (or create) the key, while
48
+ * session restore reads an already-registered one, and an explicit
49
+ * `forgetLocalKey` deletes it.
50
+ *
51
+ * `#`-private on `DaaClient` for the same reason {@link AppAuthKeyResolver} is:
52
+ * a holder could reach an {@link OwnerAuthKey} and so a generic signing
53
+ * surface.
54
+ */
55
+ export type AppOwnerKeys = Readonly<{
56
+ /** Resolve the Owner's AuthKey, creating it only when absent. */
57
+ resolveOrCreate: AppAuthKeyResolver;
58
+ /** Read-only: the Owner's registered AuthKey and its identifiers, or `null`. */
59
+ resolveExisting: (clientEntityId: string) => Promise<RegisteredOwnerAuthKey | null>;
60
+ /** Delete the Owner's AuthKey on this device. Local only; no revocation. */
61
+ forget: (clientEntityId: string) => Promise<void>;
62
+ }>;
63
+ /**
64
+ * Build {@link AppOwnerKeys} for one application identity.
47
65
  *
48
66
  * @param identity App-level identity (`appId`, `environment`); `null` when
49
67
  * the SDK has no application identity to select a key with, which fails
50
- * closed at the first resolution rather than at construction —
51
- * `AuthClient` is built for Prepare, and Prepare never touches an
52
- * AuthKey.
53
- * @param secureKeys Injected store, which tests substitute. Absent, the native
54
- * store is constructed on first use and reused.
68
+ * closed at the first use rather than at construction.
69
+ * @param secureKeys Injected store, which tests substitute. Absent, the
70
+ * process-wide native store is looked up on first use and reused by all
71
+ * three operations.
55
72
  */
56
- export declare function createOwnerAuthKeyResolver(identity: AppKeyIdentity | null, secureKeys: SecureKeyStore | null): AppAuthKeyResolver;
73
+ export declare function createAppOwnerKeys(identity: AppKeyIdentity | null, secureKeys: SecureKeyStore | null): AppOwnerKeys;
@@ -17,7 +17,7 @@
17
17
  * limitations under the License.
18
18
  */
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.createOwnerAuthKeyResolver = createOwnerAuthKeyResolver;
20
+ exports.createAppOwnerKeys = createAppOwnerKeys;
21
21
  // Resolving the installation AuthKey by alias, in one place.
22
22
  //
23
23
  // Two call sites need the same key: the login ceremony selects it after Social
@@ -29,35 +29,50 @@ exports.createOwnerAuthKeyResolver = createOwnerAuthKeyResolver;
29
29
  // `DeviceContext.authKeyId` supplies the JWS `kid` alongside it.
30
30
  //
31
31
  // The lazy `NativeSecureKeyStore` is why this is a factory rather than a free
32
- // function. Constructing the store requires the Expo `DaaSecureKey` module, and
33
- // `DaaClient` construction deliberately does not; the store is therefore built
34
- // on first resolution and then reused, so login and every later signed write
35
- // share one store — and so share its in-flight `resolveOrCreate` map rather
36
- // than racing two independent handles for the same alias.
32
+ // function. Reaching the store requires the Expo `DaaSecureKey` module, and
33
+ // `DaaClient` construction deliberately does not; the store is therefore looked
34
+ // up on first resolution. It is one store per process, shared by every
35
+ // `DaaClient` (see `resolveNativeSecureKeyStore`), so login, every later signed
36
+ // write, and a forget through any client share one in-flight `resolveOrCreate`
37
+ // map rather than racing independent handles for the same alias.
37
38
  const errors_1 = require("../errors");
38
- const NativeSecureKey_1 = require("./NativeSecureKey");
39
39
  const resolveNativeBridge_1 = require("./resolveNativeBridge");
40
40
  /**
41
- * Build the resolver for one application identity.
41
+ * Build {@link AppOwnerKeys} for one application identity.
42
42
  *
43
43
  * @param identity App-level identity (`appId`, `environment`); `null` when
44
44
  * the SDK has no application identity to select a key with, which fails
45
- * closed at the first resolution rather than at construction —
46
- * `AuthClient` is built for Prepare, and Prepare never touches an
47
- * AuthKey.
48
- * @param secureKeys Injected store, which tests substitute. Absent, the native
49
- * store is constructed on first use and reused.
45
+ * closed at the first use rather than at construction.
46
+ * @param secureKeys Injected store, which tests substitute. Absent, the
47
+ * process-wide native store is looked up on first use and reused by all
48
+ * three operations.
50
49
  */
51
- function createOwnerAuthKeyResolver(identity, secureKeys) {
52
- // The mutable slot the lazily-constructed native store fills. A closure
53
- // variable rather than a field because the clients holding this resolver are
54
- // sealed with `Object.freeze`.
50
+ function createAppOwnerKeys(identity, secureKeys) {
51
+ // The mutable slot the process-wide native store fills on first use. A closure
52
+ // variable rather than a field because the clients holding this are sealed
53
+ // with `Object.freeze`.
55
54
  let nativeStore = null;
56
- return async (clientEntityId) => {
55
+ const store = () => {
57
56
  if (identity === null) {
58
57
  throw (0, errors_1.contractViolation)('AuthKey selection requires the DaaClient application identity');
59
58
  }
60
- const store = secureKeys ?? (nativeStore ?? (nativeStore = new NativeSecureKey_1.NativeSecureKeyStore((0, resolveNativeBridge_1.resolveNativeBridge)())));
61
- return store.resolveOrCreate({ ...identity, clientEntityId });
59
+ return {
60
+ store: secureKeys ?? (nativeStore ?? (nativeStore = (0, resolveNativeBridge_1.resolveNativeSecureKeyStore)())),
61
+ identity,
62
+ };
62
63
  };
64
+ return Object.freeze({
65
+ resolveOrCreate: async (clientEntityId) => {
66
+ const resolved = store();
67
+ return resolved.store.resolveOrCreate({ ...resolved.identity, clientEntityId });
68
+ },
69
+ resolveExisting: async (clientEntityId) => {
70
+ const resolved = store();
71
+ return resolved.store.resolveExisting({ ...resolved.identity, clientEntityId });
72
+ },
73
+ forget: async (clientEntityId) => {
74
+ const resolved = store();
75
+ return resolved.store.forget({ ...resolved.identity, clientEntityId });
76
+ },
77
+ });
63
78
  }
@@ -0,0 +1,19 @@
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 { AuthKeyRegistration } from './SecureKey';
19
+ export declare function assertRegistration(registration: AuthKeyRegistration): AuthKeyRegistration;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) 2026, Circle Internet Group, Inc. All rights reserved.
4
+ *
5
+ * SPDX-License-Identifier: Apache-2.0
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.assertRegistration = assertRegistration;
21
+ const config_1 = require("../config");
22
+ const errors_1 = require("../errors");
23
+ const uuid_1 = require("../validation/uuid");
24
+ // Both identifiers are UUIDs on the wire (the DeviceContext decoder already
25
+ // requires it) and native rejects anything else; checking here fails closed on
26
+ // both platforms the same way, before the bridge is reached. Shared by the
27
+ // native and in-memory stores so both reject a bad argument with the same
28
+ // error, without the in-memory double importing the native store.
29
+ function assertRegistration(registration) {
30
+ if (!(0, config_1.isRecord)(registration) ||
31
+ typeof registration.authKeyId !== 'string' ||
32
+ typeof registration.ownerBindingId !== 'string' ||
33
+ !(0, uuid_1.isUuid)(registration.authKeyId) ||
34
+ !(0, uuid_1.isUuid)(registration.ownerBindingId)) {
35
+ throw (0, errors_1.contractViolation)('AuthKey registration identifiers must be UUIDs');
36
+ }
37
+ return registration;
38
+ }
@@ -16,6 +16,7 @@
16
16
  * limitations under the License.
17
17
  */
18
18
  import type { DeviceKeyPolicy } from '../config';
19
+ import { NativeSecureKeyStore } from './NativeSecureKey';
19
20
  import type { NativeSecureKeyBridge } from './NativeSecureKeyBridge';
20
21
  /**
21
22
  * When the Expo `DaaSecureKey` module is loaded, require that its declared
@@ -28,3 +29,5 @@ import type { NativeSecureKeyBridge } from './NativeSecureKeyBridge';
28
29
  */
29
30
  export declare function assertNativeModuleKeyPolicyIfPresent(configured: DeviceKeyPolicy): void;
30
31
  export declare function resolveNativeBridge(): NativeSecureKeyBridge;
32
+ /** The process-wide {@link NativeSecureKeyStore} over the DaaSecureKey module. */
33
+ export declare function resolveNativeSecureKeyStore(): NativeSecureKeyStore;
@@ -19,10 +19,12 @@
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
20
  exports.assertNativeModuleKeyPolicyIfPresent = assertNativeModuleKeyPolicyIfPresent;
21
21
  exports.resolveNativeBridge = resolveNativeBridge;
22
+ exports.resolveNativeSecureKeyStore = resolveNativeSecureKeyStore;
22
23
  const expo_modules_core_1 = require("expo-modules-core");
23
24
  const config_1 = require("../config");
24
25
  const errors_1 = require("../errors");
25
26
  const alias_1 = require("./alias");
27
+ const NativeSecureKey_1 = require("./NativeSecureKey");
26
28
  /**
27
29
  * When the Expo `DaaSecureKey` module is loaded, require that its declared
28
30
  * policy matches the configured closed set. No-ops when the module is absent
@@ -57,6 +59,25 @@ function assertNativeDeclaredKeyPolicy(native, configured) {
57
59
  // Node / Jest have no native module: fail closed rather than silently no-op.
58
60
  // Tests inject a NativeSecureKeyBridge explicitly.
59
61
  function resolveNativeBridge() {
62
+ return wrapNativeModule(requireNativeModule());
63
+ }
64
+ // One store per native module, so per process in an app. Native keeps one key
65
+ // per alias for the whole process, so every DaaClient must share one handle
66
+ // cache: a forget through one client otherwise leaves another client's cached
67
+ // handle pointing at the deleted key. Keyed by the module object rather than
68
+ // a plain singleton so a test that installs a fresh fake gets a fresh store.
69
+ const nativeStores = new WeakMap();
70
+ /** The process-wide {@link NativeSecureKeyStore} over the DaaSecureKey module. */
71
+ function resolveNativeSecureKeyStore() {
72
+ const native = requireNativeModule();
73
+ let store = nativeStores.get(native);
74
+ if (store === undefined) {
75
+ store = new NativeSecureKey_1.NativeSecureKeyStore(wrapNativeModule(native));
76
+ nativeStores.set(native, store);
77
+ }
78
+ return store;
79
+ }
80
+ function requireNativeModule() {
60
81
  const native = (0, expo_modules_core_1.requireOptionalNativeModule)('DaaSecureKey');
61
82
  if (native === null) {
62
83
  throw (0, errors_1.contractViolation)('native DaaSecureKey module is not available. Provide a NativeSecureKeyBridge ' +
@@ -64,7 +85,7 @@ function resolveNativeBridge() {
64
85
  'module.');
65
86
  }
66
87
  assertNativeDeclaredKeyPolicy(native, config_1.DEVICE_KEY_POLICY);
67
- return wrapNativeModule(native);
88
+ return native;
68
89
  }
69
90
  function wrapNativeModule(native) {
70
91
  return {
@@ -80,13 +101,44 @@ function wrapNativeModule(native) {
80
101
  const identity = (0, alias_1.parseSecureKeyAlias)(alias);
81
102
  return await native.publicKeySpkiBase64Url(identity.appId, identity.environment);
82
103
  },
83
- async acknowledgeRegistration(alias) {
84
- // Calls the acknowledgeRegistration the Expo module already exposes on
85
- // both platforms; no parallel native API is introduced. Native owns
86
- // idempotence and persistence (Data Protection Keychain on iOS,
87
- // app-private storage on Android).
104
+ async acknowledgeRegistration(alias, authKeyId, ownerBindingId) {
105
+ // Native `acknowledgeRegistration(authKeyId, ownerBindingId)`, which
106
+ // always upserts the identifiers into the durable registration record
107
+ // (Data Protection Keychain on iOS, app-private storage on Android). The
108
+ // no-identifier variant is not reached from here: it records no ids, so
109
+ // a key acknowledged only that way has nothing for resolveExisting to read.
110
+ const identity = (0, alias_1.parseSecureKeyAlias)(alias);
111
+ await native.acknowledgeRegistration(identity.appId, identity.environment, authKeyId, ownerBindingId);
112
+ },
113
+ async resolveExisting(alias) {
114
+ // Read-only on purpose: this lookup must never reach
115
+ // resolveOrCreate, which would mint a fresh, unregistered key.
116
+ const resolveExisting = native.resolveExisting;
117
+ if (typeof resolveExisting !== 'function') {
118
+ throw (0, errors_1.contractViolation)('native DaaSecureKey.resolveExisting is required');
119
+ }
120
+ const identity = (0, alias_1.parseSecureKeyAlias)(alias);
121
+ const record = await resolveExisting.call(native, identity.appId, identity.environment);
122
+ // Only an explicit null is "no key": Expo delivers a Swift nil or a
123
+ // Kotlin null return as JS null. `undefined` is not a shape native
124
+ // sends, so it fails closed below instead of becoming "no key".
125
+ if (record === null) {
126
+ return null;
127
+ }
128
+ if (!(0, config_1.isRecord)(record)) {
129
+ throw (0, errors_1.contractViolation)('native resolveExisting returned an unknown shape');
130
+ }
131
+ // Field-level validation happens once, at the store seam
132
+ // (NativeSecureKeyStore), which also covers injected stand-ins.
133
+ return record;
134
+ },
135
+ async forgetLocalKey(alias) {
136
+ const forgetLocalKey = native.forgetLocalKey;
137
+ if (typeof forgetLocalKey !== 'function') {
138
+ throw (0, errors_1.contractViolation)('native DaaSecureKey.forgetLocalKey is required');
139
+ }
88
140
  const identity = (0, alias_1.parseSecureKeyAlias)(alias);
89
- await native.acknowledgeRegistration(identity.appId, identity.environment);
141
+ await forgetLocalKey.call(native, identity.appId, identity.environment);
90
142
  },
91
143
  async sign(alias, messageBase64Url) {
92
144
  // Typed native signDeviceAuthorization — not a generic sign(bytes) Expo
@@ -97,9 +149,38 @@ function wrapNativeModule(native) {
97
149
  if (typeof native.signDeviceAuthorization !== 'function') {
98
150
  throw (0, errors_1.contractViolation)('native DaaSecureKey.signDeviceAuthorization is required');
99
151
  }
152
+ // No prompt text crosses the bridge: the native SDK derives the
153
+ // biometric prompt from the validated operation itself.
100
154
  const identity = (0, alias_1.parseSecureKeyAlias)(alias);
101
155
  return await native.signDeviceAuthorization(identity.appId, identity.environment, messageBase64Url);
102
156
  },
157
+ async signDeviceApproval(alias, messageBase64Url, requestBodyBase64Url, codeSecretBase64Url, enteredCode) {
158
+ // Native `DaaDeviceAuthorizationSigningInput` approval initializer (iOS)
159
+ // or `forDeviceApproval` (Android). Like `sign`, no prompt text crosses
160
+ // the bridge: native shows the matching code it derived itself.
161
+ const signDeviceApproval = native.signDeviceApproval;
162
+ if (typeof signDeviceApproval !== 'function') {
163
+ throw (0, errors_1.contractViolation)('native DaaSecureKey.signDeviceApproval is required');
164
+ }
165
+ const identity = (0, alias_1.parseSecureKeyAlias)(alias);
166
+ return await signDeviceApproval.call(native, identity.appId, identity.environment, messageBase64Url, requestBodyBase64Url, codeSecretBase64Url, enteredCode);
167
+ },
168
+ async codeSecret(alias) {
169
+ const codeSecret = native.codeSecret;
170
+ if (typeof codeSecret !== 'function') {
171
+ throw (0, errors_1.contractViolation)('native DaaSecureKey.codeSecret is required');
172
+ }
173
+ const identity = (0, alias_1.parseSecureKeyAlias)(alias);
174
+ return await codeSecret.call(native, identity.appId, identity.environment);
175
+ },
176
+ async deleteCodeSecret(alias, secretBase64Url) {
177
+ const deleteCodeSecret = native.deleteCodeSecret;
178
+ if (typeof deleteCodeSecret !== 'function') {
179
+ throw (0, errors_1.contractViolation)('native DaaSecureKey.deleteCodeSecret is required');
180
+ }
181
+ const identity = (0, alias_1.parseSecureKeyAlias)(alias);
182
+ await deleteCodeSecret.call(native, identity.appId, identity.environment, secretBase64Url);
183
+ },
103
184
  async signRegistrationDeviceAuthorization(alias, messageBase64Url) {
104
185
  // Typed native signRegistrationDeviceAuthorization — the registration
105
186
  // counterpart of `sign` above, NOT the same native call. `messageBase64Url`
@@ -28,3 +28,14 @@
28
28
  * as an empty string, which a provider could also legitimately send.
29
29
  */
30
30
  export declare function headerValueIgnoringCase(headers: Readonly<Record<string, string>>, name: string): string | null;
31
+ /**
32
+ * Parse an HTTP `Date` header value (RFC 9110 IMF-fixdate, e.g.
33
+ * `Sun, 06 Nov 1994 08:49:37 GMT`) to epoch milliseconds.
34
+ *
35
+ * Parsed by hand rather than with `Date.parse`, whose handling of this format
36
+ * is implementation-defined and differs across JavaScript engines. Returns
37
+ * `null` for an absent header or any value that is not a valid IMF-fixdate
38
+ * (including the obsolete RFC 850 and asctime forms), so a caller treats an
39
+ * unreadable `Date` exactly like a missing one.
40
+ */
41
+ export declare function httpDateMillis(value: string | null): number | null;
@@ -18,6 +18,7 @@
18
18
  */
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
20
  exports.headerValueIgnoringCase = headerValueIgnoringCase;
21
+ exports.httpDateMillis = httpDateMillis;
21
22
  /**
22
23
  * Look a response header up without assuming its casing.
23
24
  *
@@ -43,3 +44,38 @@ function headerValueIgnoringCase(headers, name) {
43
44
  }
44
45
  return null;
45
46
  }
47
+ const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
48
+ const IMF_FIXDATE = /^(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun), (\d{2}) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) (\d{4}) (\d{2}):(\d{2}):(\d{2}) GMT$/;
49
+ /**
50
+ * Parse an HTTP `Date` header value (RFC 9110 IMF-fixdate, e.g.
51
+ * `Sun, 06 Nov 1994 08:49:37 GMT`) to epoch milliseconds.
52
+ *
53
+ * Parsed by hand rather than with `Date.parse`, whose handling of this format
54
+ * is implementation-defined and differs across JavaScript engines. Returns
55
+ * `null` for an absent header or any value that is not a valid IMF-fixdate
56
+ * (including the obsolete RFC 850 and asctime forms), so a caller treats an
57
+ * unreadable `Date` exactly like a missing one.
58
+ */
59
+ function httpDateMillis(value) {
60
+ if (value === null) {
61
+ return null;
62
+ }
63
+ const match = IMF_FIXDATE.exec(value.trim());
64
+ if (match === null) {
65
+ return null;
66
+ }
67
+ const [, day, month, year, hour, minute, second] = match;
68
+ const monthIndex = MONTHS.indexOf(month ?? '');
69
+ const millis = Date.UTC(Number(year), monthIndex, Number(day), Number(hour), Number(minute), Number(second));
70
+ // Reject a calendar-invalid value such as `31 Feb`, which Date.UTC would
71
+ // otherwise silently roll over into the next month.
72
+ const parsed = new Date(millis);
73
+ if (parsed.getUTCDate() !== Number(day) ||
74
+ parsed.getUTCMonth() !== monthIndex ||
75
+ Number(hour) > 23 ||
76
+ Number(minute) > 59 ||
77
+ Number(second) > 60) {
78
+ return null;
79
+ }
80
+ return millis;
81
+ }
@@ -0,0 +1,24 @@
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 { ContractExecution } from '../models/ContractExecution';
19
+ /**
20
+ * Map a decoded `ContractExecution` payload onto the public model.
21
+ *
22
+ * @throws MalformedPayloadError
23
+ */
24
+ export declare function toContractExecution(value: unknown): ContractExecution;
@@ -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
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.toContractExecution = toContractExecution;
21
+ const ContractExecution_1 = require("../models/ContractExecution");
22
+ const moneyPayload_1 = require("./moneyPayload");
23
+ const payload_1 = require("./payload");
24
+ /**
25
+ * Wire payload -> public `ContractExecution` model, and the required/optional
26
+ * line.
27
+ *
28
+ * The service omits null fields, so an absent `transactionHash`, `networkFee`,
29
+ * or `errorCode` is the ordinary "not known yet" / "not failed" case and
30
+ * decodes to `null`. The invocation is required in exactly one mode: a
31
+ * response carrying both or neither is not one the service produces, and is
32
+ * rejected rather than guessed at.
33
+ */
34
+ // `Map` rather than an object literal, for the reason `wire/transferPayload.ts`
35
+ // gives: a wire value spelled like an `Object.prototype` member must not be
36
+ // "recognised".
37
+ const STATUSES = new Map([
38
+ ['pending', Object.freeze({ kind: 'pending' })],
39
+ ['complete', Object.freeze({ kind: 'complete' })],
40
+ ['failed', Object.freeze({ kind: 'failed' })],
41
+ ]);
42
+ const ERROR_CODES = new Map([
43
+ ['authorization_failed', Object.freeze({ kind: 'authorization_failed' })],
44
+ ['execution_denied', Object.freeze({ kind: 'execution_denied' })],
45
+ ['insufficient_funds', Object.freeze({ kind: 'insufficient_funds' })],
46
+ ['insufficient_network_fee', Object.freeze({ kind: 'insufficient_network_fee' })],
47
+ ['blockchain_error', Object.freeze({ kind: 'blockchain_error' })],
48
+ ['contract_execution_failed', Object.freeze({ kind: 'contract_execution_failed' })],
49
+ ]);
50
+ function toStatus(raw) {
51
+ return STATUSES.get(raw) ?? (0, payload_1.unrecognized)(raw);
52
+ }
53
+ /** Present only when the status is `failed`; absent is `null`, not `unrecognized`. */
54
+ function toErrorCode(raw) {
55
+ if (raw === null) {
56
+ return null;
57
+ }
58
+ return ERROR_CODES.get(raw) ?? (0, payload_1.unrecognized)(raw);
59
+ }
60
+ function toSource(value) {
61
+ const payload = (0, payload_1.asObject)(value, 'source');
62
+ const type = (0, payload_1.requiredString)(payload, 'type', 'source.type');
63
+ if (type !== 'account') {
64
+ return (0, payload_1.unrecognized)(type);
65
+ }
66
+ return Object.freeze({
67
+ kind: 'account',
68
+ accountId: (0, payload_1.requiredString)(payload, 'id', 'source.id'),
69
+ });
70
+ }
71
+ /**
72
+ * One ABI input as the service echoes it: the stored request's own values.
73
+ *
74
+ * The service accepted only strings, booleans, safe JSON integers, and nested
75
+ * arrays of those, so anything else — and in particular a JSON number that is
76
+ * not a safe integer, which `JSON.parse` has already rounded — is malformed
77
+ * rather than passed on as a value the Owner never authorized.
78
+ */
79
+ function toAbiParameter(value) {
80
+ if (typeof value === 'string' || typeof value === 'boolean') {
81
+ return value;
82
+ }
83
+ if (typeof value === 'number' && Number.isSafeInteger(value)) {
84
+ return value;
85
+ }
86
+ if (Array.isArray(value)) {
87
+ return Object.freeze(value.map(toAbiParameter));
88
+ }
89
+ throw new payload_1.MalformedPayloadError('abiParameters');
90
+ }
91
+ function toInvocation(payload) {
92
+ const callData = (0, payload_1.optionalString)(payload, 'callData');
93
+ const abiFunctionSignature = (0, payload_1.optionalString)(payload, 'abiFunctionSignature');
94
+ const abiParameters = payload['abiParameters'];
95
+ const hasAbiParameters = abiParameters !== undefined && abiParameters !== null;
96
+ if (callData !== null && abiFunctionSignature === null && !hasAbiParameters) {
97
+ return Object.freeze({ kind: 'raw', callData });
98
+ }
99
+ if (callData === null && abiFunctionSignature !== null && Array.isArray(abiParameters)) {
100
+ return Object.freeze({
101
+ kind: 'abi',
102
+ abiFunctionSignature,
103
+ abiParameters: Object.freeze(abiParameters.map(toAbiParameter)),
104
+ });
105
+ }
106
+ throw new payload_1.MalformedPayloadError('invocation');
107
+ }
108
+ /**
109
+ * Map a decoded `ContractExecution` payload onto the public model.
110
+ *
111
+ * @throws MalformedPayloadError
112
+ */
113
+ function toContractExecution(value) {
114
+ const payload = (0, payload_1.asObject)(value, 'contractExecution');
115
+ return new ContractExecution_1.ContractExecution({
116
+ id: (0, payload_1.requiredString)(payload, 'id'),
117
+ status: toStatus((0, payload_1.requiredString)(payload, 'status')),
118
+ errorCode: toErrorCode((0, payload_1.optionalString)(payload, 'errorCode')),
119
+ source: toSource(payload['source']),
120
+ custodyType: (0, payload_1.requiredString)(payload, 'custodyType'),
121
+ blockchain: (0, payload_1.requiredString)(payload, 'blockchain'),
122
+ contractAddress: (0, payload_1.requiredString)(payload, 'contractAddress'),
123
+ invocation: toInvocation(payload),
124
+ amount: (0, moneyPayload_1.requiredMoney)(payload, 'amount'),
125
+ networkFee: (0, moneyPayload_1.optionalMoney)(payload, 'networkFee'),
126
+ transactionHash: (0, payload_1.optionalString)(payload, 'transactionHash'),
127
+ createDate: (0, payload_1.requiredString)(payload, 'createDate'),
128
+ updateDate: (0, payload_1.requiredString)(payload, 'updateDate'),
129
+ });
130
+ }
@@ -33,9 +33,18 @@
33
33
  *
34
34
  * The signed-request mapping (`api/signedResource.ts`) matches
35
35
  * `DEVICE_AUTHORIZATION_INVALID`, `IDEMPOTENCY_KEY_REUSED`,
36
- * `DEVICE_AUTHORIZATION_REQUEST_MISMATCH` and `DEVICE_AUTHORIZATION_REPLAYED`.
37
- * The login mapping (`api/loginFailure.ts`) matches `IDEMPOTENCY_KEY_REUSED`
38
- * and `LOGIN_REQUEST_CONSUMED`. The unsigned deposit-address create
36
+ * `DEVICE_AUTHORIZATION_REQUEST_MISMATCH`, `DEVICE_AUTHORIZATION_REPLAYED` and
37
+ * `DEVICE_PENDING` (the signing key is still waiting for approval or in its
38
+ * cool-down).
39
+ * The login mapping (`api/loginFailure.ts`) matches `IDEMPOTENCY_KEY_REUSED`,
40
+ * `LOGIN_REQUEST_CONSUMED` and, on Device Registration Complete, the four
41
+ * add-a-device codes (`DEVICE_REGISTRATION_LIMIT`, `DEVICE_DENIED`,
42
+ * `DEVICE_APPROVAL_CONFLICT`, `DEVICE_APPROVAL_UNAVAILABLE`). The device
43
+ * approval (`api/deviceApproval.ts`) matches `DEVICE_APPROVAL_INVALID` and
44
+ * `DEVICE_APPROVAL_BUSY`.
45
+ * `PASSKEY_OWNER_CREDENTIAL_KIND_MISMATCH` is in the table because DAA returns
46
+ * it with `409` from Device Registration Complete when the Owner's credential
47
+ * is a passkey; like `AUTH_KEY_BINDING_CONFLICT` it classifies as `api`. The unsigned deposit-address create
39
48
  * (`api/DepositAddressesClient.ts`) matches `IDEMPOTENCY_KEY_REUSED`.
40
49
  * `AUTH_KEY_BINDING_CONFLICT` is in the table because DAA returns it with `409`
41
50
  * from Device Registration Complete. It classifies as `api`, so no mapping
@@ -50,6 +59,14 @@ export declare const DAA_STATUS_CODES: Readonly<{
50
59
  readonly AUTH_KEY_BINDING_CONFLICT: 420038;
51
60
  readonly LOGIN_REQUEST_CONSUMED: 420039;
52
61
  readonly DEVICE_AUTHORIZATION_REPLAYED: 420043;
62
+ readonly PASSKEY_OWNER_CREDENTIAL_KIND_MISMATCH: 420080;
63
+ readonly DEVICE_REGISTRATION_LIMIT: 420109;
64
+ readonly DEVICE_DENIED: 420111;
65
+ readonly DEVICE_APPROVAL_CONFLICT: 420112;
66
+ readonly DEVICE_APPROVAL_UNAVAILABLE: 420113;
67
+ readonly DEVICE_APPROVAL_INVALID: 420117;
68
+ readonly DEVICE_PENDING: 420118;
69
+ readonly DEVICE_APPROVAL_BUSY: 420120;
53
70
  }>;
54
71
  export type DaaStatusName = keyof typeof DAA_STATUS_CODES;
55
72
  /**
@@ -37,9 +37,18 @@ exports.isDaaStatus = isDaaStatus;
37
37
  *
38
38
  * The signed-request mapping (`api/signedResource.ts`) matches
39
39
  * `DEVICE_AUTHORIZATION_INVALID`, `IDEMPOTENCY_KEY_REUSED`,
40
- * `DEVICE_AUTHORIZATION_REQUEST_MISMATCH` and `DEVICE_AUTHORIZATION_REPLAYED`.
41
- * The login mapping (`api/loginFailure.ts`) matches `IDEMPOTENCY_KEY_REUSED`
42
- * and `LOGIN_REQUEST_CONSUMED`. The unsigned deposit-address create
40
+ * `DEVICE_AUTHORIZATION_REQUEST_MISMATCH`, `DEVICE_AUTHORIZATION_REPLAYED` and
41
+ * `DEVICE_PENDING` (the signing key is still waiting for approval or in its
42
+ * cool-down).
43
+ * The login mapping (`api/loginFailure.ts`) matches `IDEMPOTENCY_KEY_REUSED`,
44
+ * `LOGIN_REQUEST_CONSUMED` and, on Device Registration Complete, the four
45
+ * add-a-device codes (`DEVICE_REGISTRATION_LIMIT`, `DEVICE_DENIED`,
46
+ * `DEVICE_APPROVAL_CONFLICT`, `DEVICE_APPROVAL_UNAVAILABLE`). The device
47
+ * approval (`api/deviceApproval.ts`) matches `DEVICE_APPROVAL_INVALID` and
48
+ * `DEVICE_APPROVAL_BUSY`.
49
+ * `PASSKEY_OWNER_CREDENTIAL_KIND_MISMATCH` is in the table because DAA returns
50
+ * it with `409` from Device Registration Complete when the Owner's credential
51
+ * is a passkey; like `AUTH_KEY_BINDING_CONFLICT` it classifies as `api`. The unsigned deposit-address create
43
52
  * (`api/DepositAddressesClient.ts`) matches `IDEMPOTENCY_KEY_REUSED`.
44
53
  * `AUTH_KEY_BINDING_CONFLICT` is in the table because DAA returns it with `409`
45
54
  * from Device Registration Complete. It classifies as `api`, so no mapping
@@ -54,6 +63,14 @@ exports.DAA_STATUS_CODES = Object.freeze({
54
63
  AUTH_KEY_BINDING_CONFLICT: 420038,
55
64
  LOGIN_REQUEST_CONSUMED: 420039,
56
65
  DEVICE_AUTHORIZATION_REPLAYED: 420043,
66
+ PASSKEY_OWNER_CREDENTIAL_KIND_MISMATCH: 420080,
67
+ DEVICE_REGISTRATION_LIMIT: 420109,
68
+ DEVICE_DENIED: 420111,
69
+ DEVICE_APPROVAL_CONFLICT: 420112,
70
+ DEVICE_APPROVAL_UNAVAILABLE: 420113,
71
+ DEVICE_APPROVAL_INVALID: 420117,
72
+ DEVICE_PENDING: 420118,
73
+ DEVICE_APPROVAL_BUSY: 420120,
57
74
  });
58
75
  /**
59
76
  * Whether a code read by `readDaaStatusCode` is the named DAA status.