@circle-fin/daa-react-native-sdk 0.0.0-stage → 0.4.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 +63 -0
- package/LICENSE +176 -0
- package/README.md +217 -2
- package/android/build.gradle +97 -0
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/java/com/circle/daa/reactnative/DaaRegistrationExceptions.kt +47 -0
- package/android/src/main/java/com/circle/daa/reactnative/DaaRegistrationModule.kt +121 -0
- package/android/src/main/java/com/circle/daa/reactnative/DaaScaExceptions.kt +60 -0
- package/android/src/main/java/com/circle/daa/reactnative/DaaScaModule.kt +179 -0
- package/android/src/main/java/com/circle/daa/reactnative/DaaSecureKeyExceptions.kt +73 -0
- package/android/src/main/java/com/circle/daa/reactnative/DaaSecureKeyModule.kt +185 -0
- package/android/src/main/java/com/circle/daa/reactnative/InstallationIdentityStore.kt +73 -0
- package/android/src/main/java/com/circle/daa/reactnative/UnpaddedBase64Url.kt +45 -0
- package/build/DaaClient.d.ts +57 -0
- package/build/DaaClient.js +158 -0
- package/build/api/AccountLimitsClient.d.ts +79 -0
- package/build/api/AccountLimitsClient.js +142 -0
- package/build/api/AccountsClient.d.ts +95 -0
- package/build/api/AccountsClient.js +276 -0
- package/build/api/AchFiatAccountsClient.d.ts +92 -0
- package/build/api/AchFiatAccountsClient.js +142 -0
- package/build/api/AuthClient.d.ts +120 -0
- package/build/api/AuthClient.js +257 -0
- package/build/api/DaaUserClient.d.ts +124 -0
- package/build/api/DaaUserClient.js +245 -0
- package/build/api/DepositAddressesClient.d.ts +112 -0
- package/build/api/DepositAddressesClient.js +222 -0
- package/build/api/DepositsClient.d.ts +106 -0
- package/build/api/DepositsClient.js +183 -0
- package/build/api/FiatAccountsClient.d.ts +43 -0
- package/build/api/FiatAccountsClient.js +46 -0
- package/build/api/TransactionsClient.d.ts +64 -0
- package/build/api/TransactionsClient.js +120 -0
- package/build/api/TransfersClient.d.ts +104 -0
- package/build/api/TransfersClient.js +321 -0
- package/build/api/WireFiatAccountsClient.d.ts +99 -0
- package/build/api/WireFiatAccountsClient.js +156 -0
- package/build/api/WithdrawalsClient.d.ts +94 -0
- package/build/api/WithdrawalsClient.js +305 -0
- package/build/api/loginFailure.d.ts +43 -0
- package/build/api/loginFailure.js +64 -0
- package/build/api/pagination.d.ts +29 -0
- package/build/api/pagination.js +50 -0
- package/build/api/queryParameters.d.ts +23 -0
- package/build/api/queryParameters.js +77 -0
- package/build/api/resourceRequest.d.ts +60 -0
- package/build/api/resourceRequest.js +79 -0
- package/build/api/signedResource.d.ts +77 -0
- package/build/api/signedResource.js +168 -0
- package/build/auth/RegistrationFlowKey.d.ts +93 -0
- package/build/auth/RegistrationFlowKey.js +203 -0
- package/build/auth/daaRegistrationNative.d.ts +80 -0
- package/build/auth/daaRegistrationNative.js +184 -0
- package/build/auth/deviceAuthorization.d.ts +73 -0
- package/build/auth/deviceAuthorization.js +243 -0
- package/build/auth/ownerGrant.d.ts +29 -0
- package/build/auth/ownerGrant.js +90 -0
- package/build/auth/prepareReceipt.d.ts +150 -0
- package/build/auth/prepareReceipt.js +357 -0
- package/build/auth/registrationAuthorization.d.ts +48 -0
- package/build/auth/registrationAuthorization.js +243 -0
- package/build/auth/registrationCodeVerifier.d.ts +31 -0
- package/build/auth/registrationCodeVerifier.js +75 -0
- package/build/config.d.ts +79 -0
- package/build/config.js +116 -0
- package/build/crypto/base64url.d.ts +26 -0
- package/build/crypto/base64url.js +87 -0
- package/build/crypto/bytes.d.ts +27 -0
- package/build/crypto/bytes.js +32 -0
- package/build/crypto/es256Jws.d.ts +56 -0
- package/build/crypto/es256Jws.js +196 -0
- package/build/crypto/jwkThumbprint.d.ts +32 -0
- package/build/crypto/jwkThumbprint.js +49 -0
- package/build/crypto/random.d.ts +35 -0
- package/build/crypto/random.js +106 -0
- package/build/crypto/serialization.d.ts +26 -0
- package/build/crypto/serialization.js +43 -0
- package/build/crypto/sha256.d.ts +18 -0
- package/build/crypto/sha256.js +100 -0
- package/build/errors.d.ts +190 -0
- package/build/errors.js +252 -0
- package/build/index.d.ts +61 -0
- package/build/index.js +67 -0
- package/build/models/Account.d.ts +201 -0
- package/build/models/Account.js +147 -0
- package/build/models/AccountLimitsUsage.d.ts +169 -0
- package/build/models/AccountLimitsUsage.js +86 -0
- package/build/models/Ach.d.ts +135 -0
- package/build/models/Ach.js +184 -0
- package/build/models/AddressObject.d.ts +128 -0
- package/build/models/AddressObject.js +141 -0
- package/build/models/BusinessPii.d.ts +84 -0
- package/build/models/BusinessPii.js +142 -0
- package/build/models/CreateAccountRequest.d.ts +74 -0
- package/build/models/CreateAccountRequest.js +19 -0
- package/build/models/CreateTransferRequest.d.ts +91 -0
- package/build/models/CreateTransferRequest.js +19 -0
- package/build/models/CreateWithdrawalRequest.d.ts +99 -0
- package/build/models/CreateWithdrawalRequest.js +19 -0
- package/build/models/DaaUserContext.d.ts +96 -0
- package/build/models/DaaUserContext.js +133 -0
- package/build/models/Deposit.d.ts +241 -0
- package/build/models/Deposit.js +149 -0
- package/build/models/DepositSummary.d.ts +91 -0
- package/build/models/DepositSummary.js +114 -0
- package/build/models/FiatAccount.d.ts +99 -0
- package/build/models/FiatAccount.js +151 -0
- package/build/models/GenerateAddressRequest.d.ts +67 -0
- package/build/models/GenerateAddressRequest.js +68 -0
- package/build/models/Money.d.ts +76 -0
- package/build/models/Money.js +99 -0
- package/build/models/Page.d.ts +33 -0
- package/build/models/Page.js +57 -0
- package/build/models/PendingDeviceRegistration.d.ts +90 -0
- package/build/models/PendingDeviceRegistration.js +180 -0
- package/build/models/PreparedSocialLogin.d.ts +155 -0
- package/build/models/PreparedSocialLogin.js +235 -0
- package/build/models/Transaction.d.ts +187 -0
- package/build/models/Transaction.js +134 -0
- package/build/models/Transfer.d.ts +335 -0
- package/build/models/Transfer.js +240 -0
- package/build/models/Wire.d.ts +213 -0
- package/build/models/Wire.js +264 -0
- package/build/models/Withdrawal.d.ts +201 -0
- package/build/models/Withdrawal.js +156 -0
- package/build/models/redaction.d.ts +18 -0
- package/build/models/redaction.js +23 -0
- package/build/sca/ScaClient.d.ts +105 -0
- package/build/sca/ScaClient.js +193 -0
- package/build/securekey/InMemorySecureKey.d.ts +23 -0
- package/build/securekey/InMemorySecureKey.js +127 -0
- package/build/securekey/NativeSecureKey.d.ts +24 -0
- package/build/securekey/NativeSecureKey.js +178 -0
- package/build/securekey/NativeSecureKeyBridge.d.ts +83 -0
- package/build/securekey/NativeSecureKeyBridge.js +19 -0
- package/build/securekey/SecureKey.d.ts +137 -0
- package/build/securekey/SecureKey.js +19 -0
- package/build/securekey/alias.d.ts +88 -0
- package/build/securekey/alias.js +175 -0
- package/build/securekey/ownerAuthKeyResolver.d.ts +56 -0
- package/build/securekey/ownerAuthKeyResolver.js +63 -0
- package/build/securekey/resolveNativeBridge.d.ts +30 -0
- package/build/securekey/resolveNativeBridge.js +120 -0
- package/build/testing.d.ts +18 -0
- package/build/testing.js +34 -0
- package/build/transport/DaaTransport.d.ts +35 -0
- package/build/transport/DaaTransport.js +19 -0
- package/build/transport/headers.d.ts +30 -0
- package/build/transport/headers.js +45 -0
- package/build/validation/requestBody.d.ts +27 -0
- package/build/validation/requestBody.js +56 -0
- package/build/validation/uuid.d.ts +25 -0
- package/build/validation/uuid.js +33 -0
- package/build/wire/accountLimitsUsagePayload.d.ts +30 -0
- package/build/wire/accountLimitsUsagePayload.js +130 -0
- package/build/wire/accountPayload.d.ts +36 -0
- package/build/wire/accountPayload.js +100 -0
- package/build/wire/achPayload.d.ts +24 -0
- package/build/wire/achPayload.js +82 -0
- package/build/wire/addressObjectPayload.d.ts +44 -0
- package/build/wire/addressObjectPayload.js +64 -0
- package/build/wire/daaStatusCodes.d.ts +64 -0
- package/build/wire/daaStatusCodes.js +69 -0
- package/build/wire/dataEnvelope.d.ts +40 -0
- package/build/wire/dataEnvelope.js +79 -0
- package/build/wire/depositPayload.d.ts +42 -0
- package/build/wire/depositPayload.js +159 -0
- package/build/wire/deviceContextPayload.d.ts +33 -0
- package/build/wire/deviceContextPayload.js +57 -0
- package/build/wire/deviceRegistrationResultPayload.d.ts +32 -0
- package/build/wire/deviceRegistrationResultPayload.js +128 -0
- package/build/wire/errorEnvelope.d.ts +43 -0
- package/build/wire/errorEnvelope.js +85 -0
- package/build/wire/fiatAccountPayload.d.ts +37 -0
- package/build/wire/fiatAccountPayload.js +93 -0
- package/build/wire/instant.d.ts +27 -0
- package/build/wire/instant.js +91 -0
- package/build/wire/jsonNumber.d.ts +30 -0
- package/build/wire/jsonNumber.js +34 -0
- package/build/wire/moneyPayload.d.ts +30 -0
- package/build/wire/moneyPayload.js +56 -0
- package/build/wire/paginationLinks.d.ts +28 -0
- package/build/wire/paginationLinks.js +167 -0
- package/build/wire/payload.d.ts +60 -0
- package/build/wire/payload.js +121 -0
- package/build/wire/pendingRegistrationPayload.d.ts +32 -0
- package/build/wire/pendingRegistrationPayload.js +54 -0
- package/build/wire/socialLoginRequestPayload.d.ts +31 -0
- package/build/wire/socialLoginRequestPayload.js +72 -0
- package/build/wire/transactionPayload.d.ts +31 -0
- package/build/wire/transactionPayload.js +126 -0
- package/build/wire/transferPayload.d.ts +43 -0
- package/build/wire/transferPayload.js +218 -0
- package/build/wire/wireEnums.d.ts +22 -0
- package/build/wire/wireEnums.js +69 -0
- package/build/wire/wirePayload.d.ts +29 -0
- package/build/wire/wirePayload.js +138 -0
- package/build/wire/withdrawalPayload.d.ts +27 -0
- package/build/wire/withdrawalPayload.js +179 -0
- package/expo-module.config.json +14 -0
- package/ios/DaaRegistrationExceptions.swift +58 -0
- package/ios/DaaRegistrationModule.swift +143 -0
- package/ios/DaaScaExceptions.swift +96 -0
- package/ios/DaaScaModule.swift +125 -0
- package/ios/DaaSecureKeyExceptions.swift +77 -0
- package/ios/DaaSecureKeyModule.swift +162 -0
- package/ios/InstallationIdentityStore.swift +126 -0
- package/ios/UnpaddedBase64URL.swift +42 -0
- package/package.json +114 -4
- package/src/DaaClient.ts +171 -0
- package/src/api/AccountLimitsClient.ts +146 -0
- package/src/api/AccountsClient.ts +305 -0
- package/src/api/AchFiatAccountsClient.ts +147 -0
- package/src/api/AuthClient.ts +331 -0
- package/src/api/DaaUserClient.ts +270 -0
- package/src/api/DepositAddressesClient.ts +239 -0
- package/src/api/DepositsClient.ts +208 -0
- package/src/api/FiatAccountsClient.ts +50 -0
- package/src/api/TransactionsClient.ts +137 -0
- package/src/api/TransfersClient.ts +361 -0
- package/src/api/WireFiatAccountsClient.ts +172 -0
- package/src/api/WithdrawalsClient.ts +339 -0
- package/src/api/loginFailure.ts +75 -0
- package/src/api/pagination.ts +63 -0
- package/src/api/queryParameters.ts +82 -0
- package/src/api/resourceRequest.ts +135 -0
- package/src/api/signedResource.ts +267 -0
- package/src/auth/RegistrationFlowKey.ts +274 -0
- package/src/auth/daaRegistrationNative.ts +236 -0
- package/src/auth/deviceAuthorization.ts +302 -0
- package/src/auth/ownerGrant.ts +102 -0
- package/src/auth/prepareReceipt.ts +522 -0
- package/src/auth/registrationAuthorization.ts +306 -0
- package/src/auth/registrationCodeVerifier.ts +76 -0
- package/src/config.ts +156 -0
- package/src/crypto/base64url.ts +88 -0
- package/src/crypto/bytes.ts +30 -0
- package/src/crypto/es256Jws.ts +240 -0
- package/src/crypto/jwkThumbprint.ts +65 -0
- package/src/crypto/random.ts +113 -0
- package/src/crypto/serialization.ts +42 -0
- package/src/crypto/sha256.ts +105 -0
- package/src/errors.ts +319 -0
- package/src/index.ts +223 -0
- package/src/models/Account.ts +264 -0
- package/src/models/AccountLimitsUsage.ts +192 -0
- package/src/models/Ach.ts +269 -0
- package/src/models/AddressObject.ts +169 -0
- package/src/models/BusinessPii.ts +154 -0
- package/src/models/CreateAccountRequest.ts +109 -0
- package/src/models/CreateTransferRequest.ts +114 -0
- package/src/models/CreateWithdrawalRequest.ts +120 -0
- package/src/models/DaaUserContext.ts +172 -0
- package/src/models/Deposit.ts +307 -0
- package/src/models/DepositSummary.ts +142 -0
- package/src/models/FiatAccount.ts +195 -0
- package/src/models/GenerateAddressRequest.ts +101 -0
- package/src/models/Money.ts +91 -0
- package/src/models/Page.ts +48 -0
- package/src/models/PendingDeviceRegistration.ts +197 -0
- package/src/models/PreparedSocialLogin.ts +287 -0
- package/src/models/Transaction.ts +247 -0
- package/src/models/Transfer.ts +459 -0
- package/src/models/Wire.ts +405 -0
- package/src/models/Withdrawal.ts +283 -0
- package/src/models/redaction.ts +22 -0
- package/src/sca/ScaClient.ts +289 -0
- package/src/securekey/InMemorySecureKey.ts +138 -0
- package/src/securekey/NativeSecureKey.ts +179 -0
- package/src/securekey/NativeSecureKeyBridge.ts +109 -0
- package/src/securekey/SecureKey.ts +149 -0
- package/src/securekey/alias.ts +204 -0
- package/src/securekey/ownerAuthKeyResolver.ts +96 -0
- package/src/securekey/resolveNativeBridge.ts +185 -0
- package/src/testing.ts +32 -0
- package/src/transport/DaaTransport.ts +42 -0
- package/src/transport/headers.ts +46 -0
- package/src/validation/requestBody.ts +60 -0
- package/src/validation/uuid.ts +31 -0
- package/src/wire/accountLimitsUsagePayload.ts +182 -0
- package/src/wire/accountPayload.ts +108 -0
- package/src/wire/achPayload.ts +98 -0
- package/src/wire/addressObjectPayload.ts +64 -0
- package/src/wire/daaStatusCodes.ts +69 -0
- package/src/wire/dataEnvelope.ts +80 -0
- package/src/wire/depositPayload.ts +186 -0
- package/src/wire/deviceContextPayload.ts +58 -0
- package/src/wire/deviceRegistrationResultPayload.ts +153 -0
- package/src/wire/errorEnvelope.ts +87 -0
- package/src/wire/fiatAccountPayload.ts +112 -0
- package/src/wire/instant.ts +93 -0
- package/src/wire/jsonNumber.ts +33 -0
- package/src/wire/moneyPayload.ts +55 -0
- package/src/wire/paginationLinks.ts +204 -0
- package/src/wire/payload.ts +146 -0
- package/src/wire/pendingRegistrationPayload.ts +75 -0
- package/src/wire/socialLoginRequestPayload.ts +89 -0
- package/src/wire/transactionPayload.ts +145 -0
- package/src/wire/transferPayload.ts +249 -0
- package/src/wire/wireEnums.ts +74 -0
- package/src/wire/wirePayload.ts +160 -0
- package/src/wire/withdrawalPayload.ts +219 -0
- package/testing.d.ts +19 -0
- package/testing.js +25 -0
|
@@ -0,0 +1,100 @@
|
|
|
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.sha256 = sha256;
|
|
21
|
+
// Minimal SHA-256 (FIPS 180-4), dependency-free, so JWK thumbprints can be
|
|
22
|
+
// derived in TypeScript on React Native (Hermes has no WebCrypto by default).
|
|
23
|
+
// Standard algorithm; verified against known test vectors in the unit tests.
|
|
24
|
+
const K = new Uint32Array([
|
|
25
|
+
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
|
26
|
+
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
|
27
|
+
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
|
28
|
+
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
|
29
|
+
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
|
30
|
+
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
|
31
|
+
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
|
32
|
+
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
|
|
33
|
+
]);
|
|
34
|
+
function rotr(x, n) {
|
|
35
|
+
return (x >>> n) | (x << (32 - n));
|
|
36
|
+
}
|
|
37
|
+
function sha256(input) {
|
|
38
|
+
const h = new Uint32Array([
|
|
39
|
+
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19,
|
|
40
|
+
]);
|
|
41
|
+
const l = input.length;
|
|
42
|
+
const bitLen = l * 8;
|
|
43
|
+
// Pad to a multiple of 64 bytes: 0x80, zeros, then the 64-bit big-endian length.
|
|
44
|
+
const total = (((l + 8) >> 6) + 1) << 6;
|
|
45
|
+
const m = new Uint8Array(total);
|
|
46
|
+
m.set(input);
|
|
47
|
+
m[l] = 0x80;
|
|
48
|
+
const dv = new DataView(m.buffer);
|
|
49
|
+
dv.setUint32(total - 4, bitLen >>> 0, false);
|
|
50
|
+
dv.setUint32(total - 8, Math.floor(bitLen / 0x100000000), false);
|
|
51
|
+
const w = new Uint32Array(64);
|
|
52
|
+
for (let off = 0; off < total; off += 64) {
|
|
53
|
+
for (let i = 0; i < 16; i++)
|
|
54
|
+
w[i] = dv.getUint32(off + i * 4, false);
|
|
55
|
+
for (let i = 16; i < 64; i++) {
|
|
56
|
+
const a15 = w[i - 15];
|
|
57
|
+
const a2 = w[i - 2];
|
|
58
|
+
const s0 = rotr(a15, 7) ^ rotr(a15, 18) ^ (a15 >>> 3);
|
|
59
|
+
const s1 = rotr(a2, 17) ^ rotr(a2, 19) ^ (a2 >>> 10);
|
|
60
|
+
w[i] = (w[i - 16] + s0 + w[i - 7] + s1) >>> 0;
|
|
61
|
+
}
|
|
62
|
+
let a = h[0];
|
|
63
|
+
let b = h[1];
|
|
64
|
+
let c = h[2];
|
|
65
|
+
let d = h[3];
|
|
66
|
+
let e = h[4];
|
|
67
|
+
let f = h[5];
|
|
68
|
+
let g = h[6];
|
|
69
|
+
let hh = h[7];
|
|
70
|
+
for (let i = 0; i < 64; i++) {
|
|
71
|
+
const S1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
|
|
72
|
+
const ch = (e & f) ^ (~e & g);
|
|
73
|
+
const t1 = (hh + S1 + ch + K[i] + w[i]) >>> 0;
|
|
74
|
+
const S0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);
|
|
75
|
+
const maj = (a & b) ^ (a & c) ^ (b & c);
|
|
76
|
+
const t2 = (S0 + maj) >>> 0;
|
|
77
|
+
hh = g;
|
|
78
|
+
g = f;
|
|
79
|
+
f = e;
|
|
80
|
+
e = (d + t1) >>> 0;
|
|
81
|
+
d = c;
|
|
82
|
+
c = b;
|
|
83
|
+
b = a;
|
|
84
|
+
a = (t1 + t2) >>> 0;
|
|
85
|
+
}
|
|
86
|
+
h[0] = (h[0] + a) >>> 0;
|
|
87
|
+
h[1] = (h[1] + b) >>> 0;
|
|
88
|
+
h[2] = (h[2] + c) >>> 0;
|
|
89
|
+
h[3] = (h[3] + d) >>> 0;
|
|
90
|
+
h[4] = (h[4] + e) >>> 0;
|
|
91
|
+
h[5] = (h[5] + f) >>> 0;
|
|
92
|
+
h[6] = (h[6] + g) >>> 0;
|
|
93
|
+
h[7] = (h[7] + hh) >>> 0;
|
|
94
|
+
}
|
|
95
|
+
const out = new Uint8Array(32);
|
|
96
|
+
const odv = new DataView(out.buffer);
|
|
97
|
+
for (let i = 0; i < 8; i++)
|
|
98
|
+
odv.setUint32(i * 4, h[i], false);
|
|
99
|
+
return out;
|
|
100
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
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
|
+
export type DaaSdkError = {
|
|
19
|
+
kind: 'transport';
|
|
20
|
+
retryable: boolean;
|
|
21
|
+
idempotencyKey?: string;
|
|
22
|
+
} | {
|
|
23
|
+
kind: 'api';
|
|
24
|
+
httpStatus: number;
|
|
25
|
+
daaStatusCode?: string | number;
|
|
26
|
+
retryable: boolean;
|
|
27
|
+
} | {
|
|
28
|
+
kind: 'local_user_authentication_required';
|
|
29
|
+
} | {
|
|
30
|
+
kind: 'login_request_expired';
|
|
31
|
+
} | {
|
|
32
|
+
kind: 'owner_grant_invalid';
|
|
33
|
+
} | {
|
|
34
|
+
kind: 'owner_grant_expired';
|
|
35
|
+
} | {
|
|
36
|
+
kind: 'prepare_receipt_invalid';
|
|
37
|
+
} | {
|
|
38
|
+
kind: 'owner_binding_invalid';
|
|
39
|
+
} | {
|
|
40
|
+
kind: 'device_not_initialized';
|
|
41
|
+
} | {
|
|
42
|
+
kind: 'device_revoked';
|
|
43
|
+
} | {
|
|
44
|
+
kind: 'idempotency_conflict';
|
|
45
|
+
idempotencyKey: string;
|
|
46
|
+
correlationId?: string;
|
|
47
|
+
} | {
|
|
48
|
+
kind: 'contract_violation';
|
|
49
|
+
correlationId?: string;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* An Error carrying a structured `DaaSdkError`. The SDK throws this so callers
|
|
53
|
+
* get the stable model (`err.detail.kind`) instead of raw platform text.
|
|
54
|
+
*/
|
|
55
|
+
export declare class DaaError extends Error {
|
|
56
|
+
readonly detail: DaaSdkError;
|
|
57
|
+
readonly cause: unknown;
|
|
58
|
+
constructor(detail: DaaSdkError, message: string, cause?: unknown);
|
|
59
|
+
}
|
|
60
|
+
/** Narrow an unknown caught value to `DaaError` (so callers can read `.detail`). */
|
|
61
|
+
export declare function isDaaError(err: unknown): err is DaaError;
|
|
62
|
+
/** A local boundary/contract check failed (no request was sent). */
|
|
63
|
+
export declare function contractViolation(message: string, correlationId?: string | null): DaaError;
|
|
64
|
+
/**
|
|
65
|
+
* A successful response could not be read as the contract's shape.
|
|
66
|
+
*
|
|
67
|
+
* The same `contract_violation` kind as a local check: the model describes a
|
|
68
|
+
* broken contract, not which side broke it, and a caller's recovery is the same
|
|
69
|
+
* either way — the call cannot be made to succeed by retrying it. What
|
|
70
|
+
* distinguishes this one is `correlationId`, the provider's `X-Request-Id`, which
|
|
71
|
+
* is what makes it diagnosable server-side.
|
|
72
|
+
*
|
|
73
|
+
* Nothing derived from the response *body* is carried. The body is the thing the
|
|
74
|
+
* SDK could not vouch for; a misrouted or intercepted response must not be able
|
|
75
|
+
* to put its own text into a consumer's logs. Not even the name of the field that
|
|
76
|
+
* was missing goes in.
|
|
77
|
+
*/
|
|
78
|
+
export declare function malformedResponse(correlationId: string | null): DaaError;
|
|
79
|
+
/**
|
|
80
|
+
* A DAA API call returned an unexpected status.
|
|
81
|
+
*
|
|
82
|
+
* `retryable` is decided by the HTTP status alone. A caller may safely retry
|
|
83
|
+
* `429` and `5xx` responses; write retries must reuse the original body and
|
|
84
|
+
* idempotency key. Other `4xx` responses will not become successes on a second
|
|
85
|
+
* attempt. The DAA status code is carried for logging and support but is
|
|
86
|
+
* deliberately **not** consulted — an unknown DAA code stays observable and is
|
|
87
|
+
* never guessed retryable.
|
|
88
|
+
*
|
|
89
|
+
* `correlationId` goes in the message and **not** on the detail, because the
|
|
90
|
+
* `api` variant does not model one — the error model puts the field on
|
|
91
|
+
* `contract_violation` only, and the SDK does not widen the `api` type to carry
|
|
92
|
+
* it. Sanitising costs nothing here: a correlation id is printable, so the
|
|
93
|
+
* message copy is the exact header. Only a header already carrying control
|
|
94
|
+
* characters differs, and that value is not one to hand back untouched.
|
|
95
|
+
*/
|
|
96
|
+
export declare function apiFailure(args: {
|
|
97
|
+
httpStatus: number;
|
|
98
|
+
daaStatusCode: string | number | null;
|
|
99
|
+
correlationId: string | null;
|
|
100
|
+
}): DaaError;
|
|
101
|
+
/**
|
|
102
|
+
* The consumer's transport threw instead of returning a response.
|
|
103
|
+
*
|
|
104
|
+
* The error model calls this `transport`. A throw from `DaaTransport.send` does
|
|
105
|
+
* not say whether the request reached DAA. Cancellation after transport
|
|
106
|
+
* submission remains an ambiguous result and follows the retry rules; a throw
|
|
107
|
+
* from the transport leaves the same unknown outcome. The retry rule is to
|
|
108
|
+
* retry with the same body bytes and the same idempotency key. That is why
|
|
109
|
+
* `retryable` is `true`, and why the idempotency key of the request handed to
|
|
110
|
+
* the transport, when its body has one, goes on the detail: it is the key the
|
|
111
|
+
* retry must reuse.
|
|
112
|
+
*
|
|
113
|
+
* The thrown value is the consumer's own error. It is kept as `cause`, not
|
|
114
|
+
* copied into `message`: the SDK cannot vouch for its text, and `message` is
|
|
115
|
+
* what crash reporters log by default.
|
|
116
|
+
*
|
|
117
|
+
* Every `DaaUserClient` operation reports a transport throw this way. The three
|
|
118
|
+
* login calls (Prepare, Social Session, and Device Registration Complete) do
|
|
119
|
+
* not: they rethrow the consumer's error unchanged, because the SDK mints their
|
|
120
|
+
* idempotency keys itself and does not let a caller resend the same bytes, so
|
|
121
|
+
* `retryable: true` would not be true for them.
|
|
122
|
+
*/
|
|
123
|
+
export declare function transportFailure(cause: unknown, idempotencyKey?: string): DaaError;
|
|
124
|
+
/**
|
|
125
|
+
* The pending login request expired (`410`).
|
|
126
|
+
*
|
|
127
|
+
* The contract's rule for the Prepare and Social Session calls: "An exact retry
|
|
128
|
+
* after expiry returns `410`; the SDK starts a new logical attempt with a fresh,
|
|
129
|
+
* permanently unused key." So the caller's recovery is a new `prepareSocialLogin`,
|
|
130
|
+
* not a retry, and the expired key is never reused.
|
|
131
|
+
*
|
|
132
|
+
* `correlationId`, the response's `X-Request-Id`, goes in the message only, as
|
|
133
|
+
* on `api`. The error model puts a correlation id on `contract_violation`;
|
|
134
|
+
* `idempotency_conflict` also carries it, as an optional field (see
|
|
135
|
+
* {@link idempotencyConflict}), and this variant does not.
|
|
136
|
+
*/
|
|
137
|
+
export declare function loginRequestExpired(correlationId: string | null): DaaError;
|
|
138
|
+
/**
|
|
139
|
+
* The Prepare receipt could not be verified: it is missing where one is
|
|
140
|
+
* required, malformed, signed by no pinned key, bound to values other than this
|
|
141
|
+
* attempt's, outside its validity window, or the platform verifier is missing
|
|
142
|
+
* or failed.
|
|
143
|
+
*
|
|
144
|
+
* On the login path this is raised only when a trust anchor is pinned for the
|
|
145
|
+
* environment: the SDK then verifies the receipt and fails closed on any
|
|
146
|
+
* mismatch, and nothing from that Prepare response reaches the application.
|
|
147
|
+
* With no anchor pinned, the receipt is ignored. Not retryable in place: the
|
|
148
|
+
* caller's recovery is a new `prepareSocialLogin`, which sends a fresh
|
|
149
|
+
* challenge and flow key. A failure that persists across fresh attempts points
|
|
150
|
+
* at the relay or at trust material that does not match the service's signer,
|
|
151
|
+
* not at the user.
|
|
152
|
+
*
|
|
153
|
+
* The receipt is unverified server-supplied text and never goes into the
|
|
154
|
+
* message; `message` here is one of the SDK's own literals.
|
|
155
|
+
*/
|
|
156
|
+
export declare function prepareReceiptInvalid(message: string, cause?: unknown): DaaError;
|
|
157
|
+
/**
|
|
158
|
+
* The same error with the response's `X-Request-Id` named in its message.
|
|
159
|
+
*
|
|
160
|
+
* For a check that runs on a decoded response without seeing the response
|
|
161
|
+
* itself — the Prepare receipt's verification has many throw sites and none of
|
|
162
|
+
* them holds the headers — so the caller that does hold the response adds the
|
|
163
|
+
* id once. The detail, the cause, and the stack of the check that threw are
|
|
164
|
+
* unchanged.
|
|
165
|
+
*/
|
|
166
|
+
export declare function withRequestId(err: DaaError, correlationId: string | null): DaaError;
|
|
167
|
+
/**
|
|
168
|
+
* An idempotency key was reused with different request bytes: a `409` with
|
|
169
|
+
* `IDEMPOTENCY_KEY_REUSED` (`420034`). Another `409` is not this error.
|
|
170
|
+
*
|
|
171
|
+
* The key goes on the detail so a caller can correlate the conflict; it stays
|
|
172
|
+
* out of `message` because that string is what crash reporters log by default.
|
|
173
|
+
* The response's `X-Request-Id` is the server's id, not the caller's, so it goes
|
|
174
|
+
* in both, in the shape `contract_violation` uses: a host that reports
|
|
175
|
+
* `err.detail` rather than the message can still trace the conflict
|
|
176
|
+
* server-side. The error model puts a correlation id on `contract_violation`;
|
|
177
|
+
* `idempotency_conflict` also carries it, as an optional field.
|
|
178
|
+
*/
|
|
179
|
+
export declare function idempotencyConflict(idempotencyKey: string, correlationId: string | null): DaaError;
|
|
180
|
+
/**
|
|
181
|
+
* Map an error thrown by the native secure-key module onto `DaaSdkError`. The
|
|
182
|
+
* raw native message is never propagated into `.message` — it can contain
|
|
183
|
+
* keystore/enclave internals that must not reach host-app logs — but is retained
|
|
184
|
+
* as `.cause` for deliberate inspection.
|
|
185
|
+
*
|
|
186
|
+
* An already-structured `DaaError` passes through unchanged. Otherwise a stable
|
|
187
|
+
* `code` on the native error maps the known custody states; anything else
|
|
188
|
+
* collapses to `contract_violation`.
|
|
189
|
+
*/
|
|
190
|
+
export declare function mapNativeError(err: unknown): DaaError;
|
package/build/errors.js
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
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.DaaError = void 0;
|
|
21
|
+
exports.isDaaError = isDaaError;
|
|
22
|
+
exports.contractViolation = contractViolation;
|
|
23
|
+
exports.malformedResponse = malformedResponse;
|
|
24
|
+
exports.apiFailure = apiFailure;
|
|
25
|
+
exports.transportFailure = transportFailure;
|
|
26
|
+
exports.loginRequestExpired = loginRequestExpired;
|
|
27
|
+
exports.prepareReceiptInvalid = prepareReceiptInvalid;
|
|
28
|
+
exports.withRequestId = withRequestId;
|
|
29
|
+
exports.idempotencyConflict = idempotencyConflict;
|
|
30
|
+
exports.mapNativeError = mapNativeError;
|
|
31
|
+
/**
|
|
32
|
+
* An Error carrying a structured `DaaSdkError`. The SDK throws this so callers
|
|
33
|
+
* get the stable model (`err.detail.kind`) instead of raw platform text.
|
|
34
|
+
*/
|
|
35
|
+
class DaaError extends Error {
|
|
36
|
+
constructor(detail, message, cause = undefined) {
|
|
37
|
+
super(message);
|
|
38
|
+
this.name = 'DaaError';
|
|
39
|
+
this.detail = detail;
|
|
40
|
+
this.cause = cause;
|
|
41
|
+
// Keep `cause` non-enumerable so JSON.stringify and crash reporters that
|
|
42
|
+
// walk own enumerable properties do not export the raw native error (its
|
|
43
|
+
// code / userInfo / native stack). It stays readable via `err.cause`.
|
|
44
|
+
Object.defineProperty(this, 'cause', { enumerable: false });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.DaaError = DaaError;
|
|
48
|
+
/** Narrow an unknown caught value to `DaaError` (so callers can read `.detail`). */
|
|
49
|
+
function isDaaError(err) {
|
|
50
|
+
return err instanceof DaaError;
|
|
51
|
+
}
|
|
52
|
+
/** A local boundary/contract check failed (no request was sent). */
|
|
53
|
+
function contractViolation(message, correlationId) {
|
|
54
|
+
if (correlationId === undefined || correlationId === null) {
|
|
55
|
+
return new DaaError({ kind: 'contract_violation' }, `DAA: ${message}`);
|
|
56
|
+
}
|
|
57
|
+
return new DaaError({ kind: 'contract_violation', correlationId }, `DAA: ${message}${requestIdSuffix(correlationId)}`);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* A correlation id is a server-supplied header value, and it reaches
|
|
61
|
+
* `DaaError.message` — which a consuming app is likely to log verbatim. A header
|
|
62
|
+
* carrying CR, LF, or other control characters could therefore forge log lines,
|
|
63
|
+
* so only printable ASCII is interpolated.
|
|
64
|
+
*
|
|
65
|
+
* This does not cost the value: a correlation id is printable, so the message
|
|
66
|
+
* carries the exact header. Only one already carrying control characters comes
|
|
67
|
+
* through altered, and the missing characters are the ones that made it unsafe.
|
|
68
|
+
* Where the error model carries the field — `contract_violation` — the detail
|
|
69
|
+
* still holds it exactly, for a caller reading it deliberately rather than
|
|
70
|
+
* logging it.
|
|
71
|
+
*/
|
|
72
|
+
function messageSafe(correlationId) {
|
|
73
|
+
return correlationId.replace(/[^\x20-\x7e]/g, '');
|
|
74
|
+
}
|
|
75
|
+
/** The ` (requestId=…)` message suffix, or nothing when there is no correlation id. */
|
|
76
|
+
function requestIdSuffix(correlationId) {
|
|
77
|
+
return correlationId === null ? '' : ` (requestId=${messageSafe(correlationId)})`;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* A successful response could not be read as the contract's shape.
|
|
81
|
+
*
|
|
82
|
+
* The same `contract_violation` kind as a local check: the model describes a
|
|
83
|
+
* broken contract, not which side broke it, and a caller's recovery is the same
|
|
84
|
+
* either way — the call cannot be made to succeed by retrying it. What
|
|
85
|
+
* distinguishes this one is `correlationId`, the provider's `X-Request-Id`, which
|
|
86
|
+
* is what makes it diagnosable server-side.
|
|
87
|
+
*
|
|
88
|
+
* Nothing derived from the response *body* is carried. The body is the thing the
|
|
89
|
+
* SDK could not vouch for; a misrouted or intercepted response must not be able
|
|
90
|
+
* to put its own text into a consumer's logs. Not even the name of the field that
|
|
91
|
+
* was missing goes in.
|
|
92
|
+
*/
|
|
93
|
+
function malformedResponse(correlationId) {
|
|
94
|
+
const detail = correlationId === null
|
|
95
|
+
? { kind: 'contract_violation' }
|
|
96
|
+
: { kind: 'contract_violation', correlationId };
|
|
97
|
+
return new DaaError(detail, `DAA: the response did not match the DAA API contract${requestIdSuffix(correlationId)}`);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* A DAA API call returned an unexpected status.
|
|
101
|
+
*
|
|
102
|
+
* `retryable` is decided by the HTTP status alone. A caller may safely retry
|
|
103
|
+
* `429` and `5xx` responses; write retries must reuse the original body and
|
|
104
|
+
* idempotency key. Other `4xx` responses will not become successes on a second
|
|
105
|
+
* attempt. The DAA status code is carried for logging and support but is
|
|
106
|
+
* deliberately **not** consulted — an unknown DAA code stays observable and is
|
|
107
|
+
* never guessed retryable.
|
|
108
|
+
*
|
|
109
|
+
* `correlationId` goes in the message and **not** on the detail, because the
|
|
110
|
+
* `api` variant does not model one — the error model puts the field on
|
|
111
|
+
* `contract_violation` only, and the SDK does not widen the `api` type to carry
|
|
112
|
+
* it. Sanitising costs nothing here: a correlation id is printable, so the
|
|
113
|
+
* message copy is the exact header. Only a header already carrying control
|
|
114
|
+
* characters differs, and that value is not one to hand back untouched.
|
|
115
|
+
*/
|
|
116
|
+
function apiFailure(args) {
|
|
117
|
+
const retryable = args.httpStatus === 429 || args.httpStatus >= 500;
|
|
118
|
+
const detail = {
|
|
119
|
+
kind: 'api',
|
|
120
|
+
httpStatus: args.httpStatus,
|
|
121
|
+
retryable,
|
|
122
|
+
...(args.daaStatusCode === null ? {} : { daaStatusCode: args.daaStatusCode }),
|
|
123
|
+
};
|
|
124
|
+
return new DaaError(detail, `DAA: API call failed (status=${args.httpStatus})${requestIdSuffix(args.correlationId)}`);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* The consumer's transport threw instead of returning a response.
|
|
128
|
+
*
|
|
129
|
+
* The error model calls this `transport`. A throw from `DaaTransport.send` does
|
|
130
|
+
* not say whether the request reached DAA. Cancellation after transport
|
|
131
|
+
* submission remains an ambiguous result and follows the retry rules; a throw
|
|
132
|
+
* from the transport leaves the same unknown outcome. The retry rule is to
|
|
133
|
+
* retry with the same body bytes and the same idempotency key. That is why
|
|
134
|
+
* `retryable` is `true`, and why the idempotency key of the request handed to
|
|
135
|
+
* the transport, when its body has one, goes on the detail: it is the key the
|
|
136
|
+
* retry must reuse.
|
|
137
|
+
*
|
|
138
|
+
* The thrown value is the consumer's own error. It is kept as `cause`, not
|
|
139
|
+
* copied into `message`: the SDK cannot vouch for its text, and `message` is
|
|
140
|
+
* what crash reporters log by default.
|
|
141
|
+
*
|
|
142
|
+
* Every `DaaUserClient` operation reports a transport throw this way. The three
|
|
143
|
+
* login calls (Prepare, Social Session, and Device Registration Complete) do
|
|
144
|
+
* not: they rethrow the consumer's error unchanged, because the SDK mints their
|
|
145
|
+
* idempotency keys itself and does not let a caller resend the same bytes, so
|
|
146
|
+
* `retryable: true` would not be true for them.
|
|
147
|
+
*/
|
|
148
|
+
function transportFailure(cause, idempotencyKey) {
|
|
149
|
+
const detail = idempotencyKey === undefined
|
|
150
|
+
? { kind: 'transport', retryable: true }
|
|
151
|
+
: { kind: 'transport', retryable: true, idempotencyKey };
|
|
152
|
+
return new DaaError(detail, 'DAA: the transport failed before a response was received', cause);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* The pending login request expired (`410`).
|
|
156
|
+
*
|
|
157
|
+
* The contract's rule for the Prepare and Social Session calls: "An exact retry
|
|
158
|
+
* after expiry returns `410`; the SDK starts a new logical attempt with a fresh,
|
|
159
|
+
* permanently unused key." So the caller's recovery is a new `prepareSocialLogin`,
|
|
160
|
+
* not a retry, and the expired key is never reused.
|
|
161
|
+
*
|
|
162
|
+
* `correlationId`, the response's `X-Request-Id`, goes in the message only, as
|
|
163
|
+
* on `api`. The error model puts a correlation id on `contract_violation`;
|
|
164
|
+
* `idempotency_conflict` also carries it, as an optional field (see
|
|
165
|
+
* {@link idempotencyConflict}), and this variant does not.
|
|
166
|
+
*/
|
|
167
|
+
function loginRequestExpired(correlationId) {
|
|
168
|
+
return new DaaError({ kind: 'login_request_expired' }, `DAA: the login request has expired${requestIdSuffix(correlationId)}`);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* The Prepare receipt could not be verified: it is missing where one is
|
|
172
|
+
* required, malformed, signed by no pinned key, bound to values other than this
|
|
173
|
+
* attempt's, outside its validity window, or the platform verifier is missing
|
|
174
|
+
* or failed.
|
|
175
|
+
*
|
|
176
|
+
* On the login path this is raised only when a trust anchor is pinned for the
|
|
177
|
+
* environment: the SDK then verifies the receipt and fails closed on any
|
|
178
|
+
* mismatch, and nothing from that Prepare response reaches the application.
|
|
179
|
+
* With no anchor pinned, the receipt is ignored. Not retryable in place: the
|
|
180
|
+
* caller's recovery is a new `prepareSocialLogin`, which sends a fresh
|
|
181
|
+
* challenge and flow key. A failure that persists across fresh attempts points
|
|
182
|
+
* at the relay or at trust material that does not match the service's signer,
|
|
183
|
+
* not at the user.
|
|
184
|
+
*
|
|
185
|
+
* The receipt is unverified server-supplied text and never goes into the
|
|
186
|
+
* message; `message` here is one of the SDK's own literals.
|
|
187
|
+
*/
|
|
188
|
+
function prepareReceiptInvalid(message, cause = undefined) {
|
|
189
|
+
return new DaaError({ kind: 'prepare_receipt_invalid' }, `DAA: ${message}`, cause);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* The same error with the response's `X-Request-Id` named in its message.
|
|
193
|
+
*
|
|
194
|
+
* For a check that runs on a decoded response without seeing the response
|
|
195
|
+
* itself — the Prepare receipt's verification has many throw sites and none of
|
|
196
|
+
* them holds the headers — so the caller that does hold the response adds the
|
|
197
|
+
* id once. The detail, the cause, and the stack of the check that threw are
|
|
198
|
+
* unchanged.
|
|
199
|
+
*/
|
|
200
|
+
function withRequestId(err, correlationId) {
|
|
201
|
+
if (correlationId === null) {
|
|
202
|
+
return err;
|
|
203
|
+
}
|
|
204
|
+
const correlated = new DaaError(err.detail, `${err.message}${requestIdSuffix(correlationId)}`, err.cause);
|
|
205
|
+
if (err.stack !== undefined) {
|
|
206
|
+
// Keep the frame that names which receipt check failed, with the new message.
|
|
207
|
+
// A function replacer, so a `$` in the server's id is not a replace pattern.
|
|
208
|
+
correlated.stack = err.stack.replace(err.message, () => correlated.message);
|
|
209
|
+
}
|
|
210
|
+
return correlated;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* An idempotency key was reused with different request bytes: a `409` with
|
|
214
|
+
* `IDEMPOTENCY_KEY_REUSED` (`420034`). Another `409` is not this error.
|
|
215
|
+
*
|
|
216
|
+
* The key goes on the detail so a caller can correlate the conflict; it stays
|
|
217
|
+
* out of `message` because that string is what crash reporters log by default.
|
|
218
|
+
* The response's `X-Request-Id` is the server's id, not the caller's, so it goes
|
|
219
|
+
* in both, in the shape `contract_violation` uses: a host that reports
|
|
220
|
+
* `err.detail` rather than the message can still trace the conflict
|
|
221
|
+
* server-side. The error model puts a correlation id on `contract_violation`;
|
|
222
|
+
* `idempotency_conflict` also carries it, as an optional field.
|
|
223
|
+
*/
|
|
224
|
+
function idempotencyConflict(idempotencyKey, correlationId) {
|
|
225
|
+
const detail = correlationId === null
|
|
226
|
+
? { kind: 'idempotency_conflict', idempotencyKey }
|
|
227
|
+
: { kind: 'idempotency_conflict', idempotencyKey, correlationId };
|
|
228
|
+
return new DaaError(detail, `DAA: idempotency key was reused with a different request${requestIdSuffix(correlationId)}`);
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Map an error thrown by the native secure-key module onto `DaaSdkError`. The
|
|
232
|
+
* raw native message is never propagated into `.message` — it can contain
|
|
233
|
+
* keystore/enclave internals that must not reach host-app logs — but is retained
|
|
234
|
+
* as `.cause` for deliberate inspection.
|
|
235
|
+
*
|
|
236
|
+
* An already-structured `DaaError` passes through unchanged. Otherwise a stable
|
|
237
|
+
* `code` on the native error maps the known custody states; anything else
|
|
238
|
+
* collapses to `contract_violation`.
|
|
239
|
+
*/
|
|
240
|
+
function mapNativeError(err) {
|
|
241
|
+
if (err instanceof DaaError) {
|
|
242
|
+
return err;
|
|
243
|
+
}
|
|
244
|
+
const code = err?.code;
|
|
245
|
+
if (code === 'USER_AUTH_REQUIRED') {
|
|
246
|
+
return new DaaError({ kind: 'local_user_authentication_required' }, 'DAA: user authentication is required', err);
|
|
247
|
+
}
|
|
248
|
+
if (code === 'NOT_INITIALIZED') {
|
|
249
|
+
return new DaaError({ kind: 'device_not_initialized' }, 'DAA: secure key is not initialized', err);
|
|
250
|
+
}
|
|
251
|
+
return new DaaError({ kind: 'contract_violation' }, 'DAA: native secure-key operation failed', err);
|
|
252
|
+
}
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
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
|
+
export { DaaClient } from './DaaClient';
|
|
19
|
+
export { createScaClient, isScaError, ScaError } from './sca/ScaClient';
|
|
20
|
+
export type { ScaCapabilities, ScaClient, ScaConfig, ScaEnvironment, ScaErrorCode, } from './sca/ScaClient';
|
|
21
|
+
export type { AuthClient } from './api/AuthClient';
|
|
22
|
+
export type { AccountListQuery, AccountsClient } from './api/AccountsClient';
|
|
23
|
+
export type { AccountLimitsClient, AccountLimitsUsageQuery } from './api/AccountLimitsClient';
|
|
24
|
+
export type { DepositAddressListQuery, DepositAddressesClient } from './api/DepositAddressesClient';
|
|
25
|
+
export type { DepositListQuery, DepositsClient } from './api/DepositsClient';
|
|
26
|
+
export type { TransactionListQuery, TransactionsClient } from './api/TransactionsClient';
|
|
27
|
+
export type { TransferListQuery, TransfersClient } from './api/TransfersClient';
|
|
28
|
+
export type { WithdrawalListQuery, WithdrawalsClient } from './api/WithdrawalsClient';
|
|
29
|
+
export type { FiatAccountsClient } from './api/FiatAccountsClient';
|
|
30
|
+
export type { PublicAccountId, WireFiatAccountListQuery, WireFiatAccountsClient, WireInstructionQuery, } from './api/WireFiatAccountsClient';
|
|
31
|
+
export type { AchFiatAccountListQuery, AchFiatAccountsClient } from './api/AchFiatAccountsClient';
|
|
32
|
+
export type { DaaUserClient } from './api/DaaUserClient';
|
|
33
|
+
export type { DaaUserContext, DeviceContext, DeviceRegistrationResult, } from './models/DaaUserContext';
|
|
34
|
+
export type { PendingDeviceRegistration } from './models/PendingDeviceRegistration';
|
|
35
|
+
export type { Account, AccountPurpose, AccountRendering, AccountStatus, AccountType, CustodyType, } from './models/Account';
|
|
36
|
+
export type { CreateAccountRequest } from './models/CreateAccountRequest';
|
|
37
|
+
export type { AccountLimitsUsage, AccountLimitsUsageItem, AccountLimitsUsageRendering, AccountLimitsUsageResourceType, LimitsUsageAssetType, LimitsUsageComparisonType, LimitsUsageOperation, LimitsUsageUnit, LimitsUsageWindow, } from './models/AccountLimitsUsage';
|
|
38
|
+
export type { CreateTransferAmount, CreateTransferDestination, CreateTransferRequest, CreateTransferRiskSignals, CreateTransferSource, } from './models/CreateTransferRequest';
|
|
39
|
+
export type { Address, BusinessPii } from './models/BusinessPii';
|
|
40
|
+
export type { AddressObject, AddressObjectRendering } from './models/AddressObject';
|
|
41
|
+
export type { DepositAddressChain, GenerateAddressRequest } from './models/GenerateAddressRequest';
|
|
42
|
+
export type { Deposit, DepositAccountLocation, DepositRendering, DepositRiskEvaluation, DepositSourceLocation, DepositStatus, DepositType, } from './models/Deposit';
|
|
43
|
+
export type { DepositSummary, DepositSummaryRendering } from './models/DepositSummary';
|
|
44
|
+
export type { Money } from './models/Money';
|
|
45
|
+
export type { Page } from './models/Page';
|
|
46
|
+
export type { PreparedSocialLogin } from './models/PreparedSocialLogin';
|
|
47
|
+
export type { Transaction, TransactionAccountLocation, TransactionBlockchainLocation, TransactionBlockchainLocationRendering, TransactionFiatLocation, TransactionLocation, TransactionRendering, TransactionStatus, TransactionType, } from './models/Transaction';
|
|
48
|
+
export type { Fee, Transfer, TransferDestinationAccountLocation, TransferDestinationAccountLocationRendering, TransferDestinationBlockchainLocation, TransferDestinationBlockchainLocationRendering, TransferDestinationLocation, TransferErrorCode, TransferPolicyEvaluation, TransferRendering, TransferSourceLocation, TransferStatus, } from './models/Transfer';
|
|
49
|
+
export type { WithdrawalAdjustments, WithdrawalDestination, WithdrawalDestinationType, WithdrawalDetail, WithdrawalDetailRendering, WithdrawalErrorCode, WithdrawalPolicyEvaluation, WithdrawalReturn, WithdrawalRiskEvaluation, WithdrawalStatus, WithdrawalSubAccountSweep, WithdrawalSweepStatus, WithdrawalToAmount, } from './models/Withdrawal';
|
|
50
|
+
export type { CreateWithdrawalAmount, CreateWithdrawalDestination, CreateWithdrawalRequest, CreateWithdrawalRiskSignals, CreateWithdrawalSource, CreateWithdrawalToAmount, } from './models/CreateWithdrawalRequest';
|
|
51
|
+
export type { BankAddress, BillingDetails, FiatAccountStatus } from './models/FiatAccount';
|
|
52
|
+
export type { TransferTypeInfo, Wire, WireInstruction, WireInstructionBeneficiary, WireInstructionBeneficiaryBank, WireSummary, } from './models/Wire';
|
|
53
|
+
export type { ACH, ACHInstruction, ACHInstructionBeneficiary, ACHInstructionBeneficiaryBank, } from './models/Ach';
|
|
54
|
+
export { DAA_ENVIRONMENTS, DEVICE_KEY_POLICY } from './config';
|
|
55
|
+
export type { DaaEnvironment, DaaSdkConfiguration, DeviceKeyPolicy } from './config';
|
|
56
|
+
export type { DaaHttpRequest, DaaHttpResponse, DaaTransport } from './transport/DaaTransport';
|
|
57
|
+
export type { DaaSdkError } from './errors';
|
|
58
|
+
export { DaaError, isDaaError } from './errors';
|
|
59
|
+
export type { AuthKeyResolution, OwnerAuthKey, OwnerKeyIdentity, SecureKeyStore, } from './securekey/SecureKey';
|
|
60
|
+
export { serializeBody, serializeEmptyBody } from './crypto/serialization';
|
|
61
|
+
export { toBase64Url, fromBase64Url } from './crypto/base64url';
|