@circle-fin/daa-react-native-sdk 0.0.0-stage → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DaaReactNativeSdk.podspec +69 -0
- package/LICENSE +176 -0
- package/README.md +691 -2
- package/android/build.gradle +102 -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 +104 -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 +107 -0
- package/android/src/main/java/com/circle/daa/reactnative/DaaSecureKeyModule.kt +318 -0
- package/android/src/main/java/com/circle/daa/reactnative/InstallationIdentityStore.kt +122 -0
- package/android/src/main/java/com/circle/daa/reactnative/UnpaddedBase64Url.kt +45 -0
- package/build/DaaClient.d.ts +237 -0
- package/build/DaaClient.js +442 -0
- package/build/api/AccountLimitsClient.d.ts +79 -0
- package/build/api/AccountLimitsClient.js +142 -0
- package/build/api/AccountsClient.d.ts +98 -0
- package/build/api/AccountsClient.js +279 -0
- package/build/api/AchFiatAccountsClient.d.ts +92 -0
- package/build/api/AchFiatAccountsClient.js +142 -0
- package/build/api/AuthClient.d.ts +95 -0
- package/build/api/AuthClient.js +221 -0
- package/build/api/ContractExecutionsClient.d.ts +114 -0
- package/build/api/ContractExecutionsClient.js +462 -0
- package/build/api/DaaUserClient.d.ts +187 -0
- package/build/api/DaaUserClient.js +312 -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 +121 -0
- package/build/api/TransfersClient.d.ts +107 -0
- package/build/api/TransfersClient.js +324 -0
- package/build/api/WireFiatAccountsClient.d.ts +99 -0
- package/build/api/WireFiatAccountsClient.js +156 -0
- package/build/api/WithdrawalsClient.d.ts +97 -0
- package/build/api/WithdrawalsClient.js +308 -0
- package/build/api/deviceApproval.d.ts +48 -0
- package/build/api/deviceApproval.js +247 -0
- package/build/api/deviceStatus.d.ts +61 -0
- package/build/api/deviceStatus.js +216 -0
- package/build/api/loginFailure.d.ts +51 -0
- package/build/api/loginFailure.js +95 -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 +124 -0
- package/build/api/signedResource.js +267 -0
- package/build/auth/RegistrationFlowKey.d.ts +93 -0
- package/build/auth/RegistrationFlowKey.js +203 -0
- package/build/auth/daaRegistrationNative.d.ts +58 -0
- package/build/auth/daaRegistrationNative.js +158 -0
- package/build/auth/deviceAuthorization.d.ts +87 -0
- package/build/auth/deviceAuthorization.js +295 -0
- package/build/auth/ownerGrant.d.ts +29 -0
- package/build/auth/ownerGrant.js +90 -0
- package/build/auth/registrationAuthorization.d.ts +48 -0
- package/build/auth/registrationAuthorization.js +246 -0
- package/build/auth/registrationCodeVerifier.d.ts +31 -0
- package/build/auth/registrationCodeVerifier.js +75 -0
- package/build/config.d.ts +106 -0
- package/build/config.js +131 -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/jwkThumbprint.d.ts +32 -0
- package/build/crypto/jwkThumbprint.js +49 -0
- package/build/crypto/matchingCode.d.ts +47 -0
- package/build/crypto/matchingCode.js +93 -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 +307 -0
- package/build/errors.js +413 -0
- package/build/index.d.ts +69 -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/ContractExecution.d.ts +197 -0
- package/build/models/ContractExecution.js +130 -0
- package/build/models/CreateAccountRequest.d.ts +74 -0
- package/build/models/CreateAccountRequest.js +19 -0
- package/build/models/CreateContractExecutionRequest.d.ts +81 -0
- package/build/models/CreateContractExecutionRequest.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 +146 -0
- package/build/models/DaaUserContext.js +164 -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/DeviceStatus.d.ts +69 -0
- package/build/models/DeviceStatus.js +19 -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/PendingDeviceApproval.d.ts +121 -0
- package/build/models/PendingDeviceApproval.js +208 -0
- package/build/models/PendingDeviceRegistration.d.ts +229 -0
- package/build/models/PendingDeviceRegistration.js +636 -0
- package/build/models/PreparedContractExecution.d.ts +70 -0
- package/build/models/PreparedContractExecution.js +77 -0
- package/build/models/PreparedSocialLogin.d.ts +148 -0
- package/build/models/PreparedSocialLogin.js +252 -0
- package/build/models/Transaction.d.ts +233 -0
- package/build/models/Transaction.js +182 -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/codeSecrets.d.ts +100 -0
- package/build/models/codeSecrets.js +321 -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 +25 -0
- package/build/securekey/InMemorySecureKey.js +168 -0
- package/build/securekey/NativeSecureKey.d.ts +26 -0
- package/build/securekey/NativeSecureKey.js +355 -0
- package/build/securekey/NativeSecureKeyBridge.d.ts +151 -0
- package/build/securekey/NativeSecureKeyBridge.js +19 -0
- package/build/securekey/SecureKey.d.ts +257 -0
- package/build/securekey/SecureKey.js +19 -0
- package/build/securekey/alias.d.ts +97 -0
- package/build/securekey/alias.js +184 -0
- package/build/securekey/ownerAuthKeyResolver.d.ts +73 -0
- package/build/securekey/ownerAuthKeyResolver.js +78 -0
- package/build/securekey/registration.d.ts +19 -0
- package/build/securekey/registration.js +38 -0
- package/build/securekey/resolveNativeBridge.d.ts +33 -0
- package/build/securekey/resolveNativeBridge.js +201 -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 +41 -0
- package/build/transport/headers.js +81 -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/contractExecutionPayload.d.ts +24 -0
- package/build/wire/contractExecutionPayload.js +130 -0
- package/build/wire/daaStatusCodes.d.ts +81 -0
- package/build/wire/daaStatusCodes.js +86 -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 +35 -0
- package/build/wire/deviceContextPayload.js +59 -0
- package/build/wire/deviceRegistrationResultPayload.d.ts +77 -0
- package/build/wire/deviceRegistrationResultPayload.js +162 -0
- package/build/wire/deviceStatusPayload.d.ts +20 -0
- package/build/wire/deviceStatusPayload.js +66 -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 +94 -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 +48 -0
- package/build/wire/pendingRegistrationPayload.js +72 -0
- package/build/wire/socialLoginRequestPayload.d.ts +26 -0
- package/build/wire/socialLoginRequestPayload.js +55 -0
- package/build/wire/transactionPayload.d.ts +31 -0
- package/build/wire/transactionPayload.js +149 -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 +125 -0
- package/ios/DaaScaExceptions.swift +96 -0
- package/ios/DaaScaModule.swift +125 -0
- package/ios/DaaSecureKeyExceptions.swift +125 -0
- package/ios/DaaSecureKeyModule.swift +306 -0
- package/ios/InstallationIdentityStore.swift +162 -0
- package/ios/UnpaddedBase64URL.swift +42 -0
- package/package.json +114 -4
- package/src/DaaClient.ts +509 -0
- package/src/api/AccountLimitsClient.ts +146 -0
- package/src/api/AccountsClient.ts +308 -0
- package/src/api/AchFiatAccountsClient.ts +147 -0
- package/src/api/AuthClient.ts +266 -0
- package/src/api/ContractExecutionsClient.ts +527 -0
- package/src/api/DaaUserClient.ts +345 -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 +138 -0
- package/src/api/TransfersClient.ts +364 -0
- package/src/api/WireFiatAccountsClient.ts +172 -0
- package/src/api/WithdrawalsClient.ts +342 -0
- package/src/api/deviceApproval.ts +306 -0
- package/src/api/deviceStatus.ts +238 -0
- package/src/api/loginFailure.ts +112 -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 +427 -0
- package/src/auth/RegistrationFlowKey.ts +274 -0
- package/src/auth/daaRegistrationNative.ts +191 -0
- package/src/auth/deviceAuthorization.ts +365 -0
- package/src/auth/ownerGrant.ts +102 -0
- package/src/auth/registrationAuthorization.ts +309 -0
- package/src/auth/registrationCodeVerifier.ts +76 -0
- package/src/config.ts +192 -0
- package/src/crypto/base64url.ts +88 -0
- package/src/crypto/bytes.ts +30 -0
- package/src/crypto/jwkThumbprint.ts +65 -0
- package/src/crypto/matchingCode.ts +100 -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 +576 -0
- package/src/index.ts +258 -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/ContractExecution.ts +250 -0
- package/src/models/CreateAccountRequest.ts +109 -0
- package/src/models/CreateContractExecutionRequest.ts +100 -0
- package/src/models/CreateTransferRequest.ts +114 -0
- package/src/models/CreateWithdrawalRequest.ts +120 -0
- package/src/models/DaaUserContext.ts +228 -0
- package/src/models/Deposit.ts +307 -0
- package/src/models/DepositSummary.ts +142 -0
- package/src/models/DeviceStatus.ts +50 -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/PendingDeviceApproval.ts +229 -0
- package/src/models/PendingDeviceRegistration.ts +791 -0
- package/src/models/PreparedContractExecution.ts +128 -0
- package/src/models/PreparedSocialLogin.ts +297 -0
- package/src/models/Transaction.ts +322 -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/codeSecrets.ts +360 -0
- package/src/models/redaction.ts +22 -0
- package/src/sca/ScaClient.ts +289 -0
- package/src/securekey/InMemorySecureKey.ts +192 -0
- package/src/securekey/NativeSecureKey.ts +388 -0
- package/src/securekey/NativeSecureKeyBridge.ts +189 -0
- package/src/securekey/SecureKey.ts +279 -0
- package/src/securekey/alias.ts +212 -0
- package/src/securekey/ownerAuthKeyResolver.ts +135 -0
- package/src/securekey/registration.ts +40 -0
- package/src/securekey/resolveNativeBridge.ts +343 -0
- package/src/testing.ts +32 -0
- package/src/transport/DaaTransport.ts +42 -0
- package/src/transport/headers.ts +93 -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/contractExecutionPayload.ts +152 -0
- package/src/wire/daaStatusCodes.ts +86 -0
- package/src/wire/dataEnvelope.ts +80 -0
- package/src/wire/depositPayload.ts +186 -0
- package/src/wire/deviceContextPayload.ts +60 -0
- package/src/wire/deviceRegistrationResultPayload.ts +211 -0
- package/src/wire/deviceStatusPayload.ts +68 -0
- package/src/wire/errorEnvelope.ts +87 -0
- package/src/wire/fiatAccountPayload.ts +112 -0
- package/src/wire/instant.ts +96 -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 +118 -0
- package/src/wire/socialLoginRequestPayload.ts +66 -0
- package/src/wire/transactionPayload.ts +181 -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,462 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2026, Circle Internet Group, Inc. All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
19
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
20
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
21
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
22
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
23
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
24
|
+
};
|
|
25
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
26
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
27
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
28
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
29
|
+
};
|
|
30
|
+
var _ContractExecutionsClient_transport, _ContractExecutionsClient_signing;
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
exports.ContractExecutionsClient = void 0;
|
|
33
|
+
const deviceAuthorization_1 = require("../auth/deviceAuthorization");
|
|
34
|
+
const base64url_1 = require("../crypto/base64url");
|
|
35
|
+
const serialization_1 = require("../crypto/serialization");
|
|
36
|
+
const sha256_1 = require("../crypto/sha256");
|
|
37
|
+
const errors_1 = require("../errors");
|
|
38
|
+
const PreparedContractExecution_1 = require("../models/PreparedContractExecution");
|
|
39
|
+
const requestBody_1 = require("../validation/requestBody");
|
|
40
|
+
const uuid_1 = require("../validation/uuid");
|
|
41
|
+
const contractExecutionPayload_1 = require("../wire/contractExecutionPayload");
|
|
42
|
+
const resourceRequest_1 = require("./resourceRequest");
|
|
43
|
+
const signedResource_1 = require("./signedResource");
|
|
44
|
+
/**
|
|
45
|
+
* `GET /v1/accounts/contractExecutions/{id}` — the public path, as for
|
|
46
|
+
* transfers. The create path is the registry's `canonical_path`, which
|
|
47
|
+
* `postAuthorizedResource` resolves; it is not chosen here.
|
|
48
|
+
*/
|
|
49
|
+
const CONTRACT_EXECUTION_PATH_PREFIX = '/v1/accounts/contractExecutions/';
|
|
50
|
+
/**
|
|
51
|
+
* The properties of each arm of the registry's `contract_execution` `oneOf`,
|
|
52
|
+
* in the order it names them. This is the order the signed bytes use, so it
|
|
53
|
+
* does not vary with how a caller wrote its literal.
|
|
54
|
+
*/
|
|
55
|
+
const COMMON_PROPERTIES = Object.freeze([
|
|
56
|
+
'idempotencyKey',
|
|
57
|
+
'accountId',
|
|
58
|
+
'blockchain',
|
|
59
|
+
'contractAddress',
|
|
60
|
+
'amount',
|
|
61
|
+
]);
|
|
62
|
+
const RAW_PROPERTIES = Object.freeze([...COMMON_PROPERTIES, 'callData']);
|
|
63
|
+
const ABI_PROPERTIES = Object.freeze([
|
|
64
|
+
...COMMON_PROPERTIES,
|
|
65
|
+
'abiFunctionSignature',
|
|
66
|
+
'abiParameters',
|
|
67
|
+
]);
|
|
68
|
+
const BLOCKCHAINS = Object.freeze([
|
|
69
|
+
'ETH',
|
|
70
|
+
'ARB',
|
|
71
|
+
'CBASE',
|
|
72
|
+
'OP',
|
|
73
|
+
'UNI',
|
|
74
|
+
'ARC',
|
|
75
|
+
]);
|
|
76
|
+
const EVM_ADDRESS = /^0x[0-9a-fA-F]{40}$/;
|
|
77
|
+
const ZERO_ADDRESS = /^0x0{40}$/;
|
|
78
|
+
const CALL_DATA = /^0x(?:[0-9a-fA-F]{2})+$/;
|
|
79
|
+
const MAX_CALL_DATA_BYTES = 16384;
|
|
80
|
+
/**
|
|
81
|
+
* Whole native-asset units: no sign, exponent, or leading integer zero; at
|
|
82
|
+
* most 20 integer and 18 fractional digits. DAA enforces the chain's own,
|
|
83
|
+
* possibly smaller, precision at runtime.
|
|
84
|
+
*/
|
|
85
|
+
const NATIVE_AMOUNT = /^(?:0|[1-9][0-9]{0,19})(?:\.[0-9]{1,18})?$/;
|
|
86
|
+
/**
|
|
87
|
+
* The canonical ABI signature grammar DAA enforces: an ASCII identifier, then elementary types — `address`,
|
|
88
|
+
* `bool`, `string`, `bytes`, `bytes1`..`bytes32`, `int8`..`int256` and
|
|
89
|
+
* `uint8`..`uint256` in steps of eight — each with at most seven `[]` or
|
|
90
|
+
* `[N]` dimensions, `N` from 1 to 1024 without leading zeros. No whitespace,
|
|
91
|
+
* names, aliases, tuples, `function`, or fixed-point types.
|
|
92
|
+
*
|
|
93
|
+
* This is syntax only. Which array forms are enabled is a runtime capability
|
|
94
|
+
* that DAA checks and can widen without an SDK release, so the SDK does not
|
|
95
|
+
* pin that list.
|
|
96
|
+
*/
|
|
97
|
+
const ELEMENTARY_TYPE = '(?:address|bool|string|bytes(?:[1-9]|[12][0-9]|3[0-2])?|u?int(?:8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256))';
|
|
98
|
+
const ARRAY_DIMENSIONS = '(?:\\[(?:[1-9][0-9]{0,2}|10[01][0-9]|102[0-4])?\\]){0,7}';
|
|
99
|
+
const ABI_TYPE = ELEMENTARY_TYPE + ARRAY_DIMENSIONS;
|
|
100
|
+
const ABI_SIGNATURE = new RegExp(`^[A-Za-z_$][A-Za-z0-9_$]*\\((?:${ABI_TYPE}(?:,${ABI_TYPE})*)?\\)$`);
|
|
101
|
+
const MAX_SIGNATURE_LENGTH = 1000;
|
|
102
|
+
/** Every property either arm can carry; none may come from the prototype chain. */
|
|
103
|
+
const ALL_PROPERTIES = Object.freeze([...RAW_PROPERTIES, 'abiFunctionSignature', 'abiParameters']);
|
|
104
|
+
/** The outer parameter array is depth one, as DAA counts it. */
|
|
105
|
+
const MAX_PARAMETER_DEPTH = 8;
|
|
106
|
+
/** Every element of every array in the tree counts, arrays included, as DAA counts it. */
|
|
107
|
+
const MAX_PARAMETER_VALUES = 1024;
|
|
108
|
+
/** DAA's limit on the exact request body, checked before anything is signed. */
|
|
109
|
+
const MAX_BODY_BYTES = 65536;
|
|
110
|
+
/**
|
|
111
|
+
* Owner-authorized contract execution from a self-custody account, plus its
|
|
112
|
+
* read.
|
|
113
|
+
*
|
|
114
|
+
* A create is two steps because a retry must be exact. {@link prepare}
|
|
115
|
+
* validates the request, serializes it **once**, and signs one
|
|
116
|
+
* `X-Device-Authorization` over those bytes. {@link submit} sends that pair,
|
|
117
|
+
* unchanged, and is what to call again after a transport failure, a `5xx`, an
|
|
118
|
+
* unreadable response, or an app restart ({@link restore} rebuilds the pair
|
|
119
|
+
* from what `PreparedContractExecution.toPersisted` stored).
|
|
120
|
+
*
|
|
121
|
+
* There is deliberately no one-call `create`. Its prepared value would not
|
|
122
|
+
* outlive a failed call, so the only retry left to the caller would be a new
|
|
123
|
+
* signature over the same body — a different `jti`, which DAA answers with
|
|
124
|
+
* `409` rather than the stored execution.
|
|
125
|
+
*
|
|
126
|
+
* The Owner authorization is the approval for this operation; there is no
|
|
127
|
+
* separate strong-customer-authentication step on this route.
|
|
128
|
+
*
|
|
129
|
+
* Not constructible by a consumer: exported from `index.ts` as a type only, and
|
|
130
|
+
* the `#transport` field makes the type nominal.
|
|
131
|
+
*/
|
|
132
|
+
class ContractExecutionsClient {
|
|
133
|
+
/** @internal Constructed only through the internal user-client factory. */
|
|
134
|
+
constructor(transport, signing) {
|
|
135
|
+
_ContractExecutionsClient_transport.set(this, void 0);
|
|
136
|
+
_ContractExecutionsClient_signing.set(this, void 0);
|
|
137
|
+
__classPrivateFieldSet(this, _ContractExecutionsClient_transport, transport, "f");
|
|
138
|
+
__classPrivateFieldSet(this, _ContractExecutionsClient_signing, signing, "f");
|
|
139
|
+
Object.freeze(this);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Read one contract execution. Poll this until the status is `complete` or
|
|
143
|
+
* `failed`; it is the authoritative outcome.
|
|
144
|
+
*
|
|
145
|
+
* @param contractExecutionId The service-assigned UUID. A value that is not
|
|
146
|
+
* UUID-formatted is rejected locally.
|
|
147
|
+
* @throws DaaError with `detail.kind === 'contract_violation'` for a rejected
|
|
148
|
+
* id or a response the SDK cannot read; `api` for a status other than
|
|
149
|
+
* `200` (an unknown or inaccessible execution is `404`); `transport` if the
|
|
150
|
+
* consumer's transport throws.
|
|
151
|
+
*/
|
|
152
|
+
async get(contractExecutionId) {
|
|
153
|
+
if (!(0, uuid_1.isUuid)(contractExecutionId)) {
|
|
154
|
+
throw (0, errors_1.contractViolation)('contractExecutionId must be a UUID');
|
|
155
|
+
}
|
|
156
|
+
return (0, resourceRequest_1.readResource)({
|
|
157
|
+
transport: __classPrivateFieldGet(this, _ContractExecutionsClient_transport, "f"),
|
|
158
|
+
path: CONTRACT_EXECUTION_PATH_PREFIX + contractExecutionId,
|
|
159
|
+
decode: contractExecutionPayload_1.toContractExecution,
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Validate, serialize once, and Owner-authorize a contract execution, without
|
|
164
|
+
* sending it.
|
|
165
|
+
*
|
|
166
|
+
* Store the result (see `PreparedContractExecution.toPersisted`) before the
|
|
167
|
+
* first {@link submit} if the app must survive a restart mid-request.
|
|
168
|
+
*
|
|
169
|
+
* @throws DaaError with `detail.kind === 'contract_violation'` for a request
|
|
170
|
+
* the registry schema or DAA would reject — including a fee, gas, or other
|
|
171
|
+
* unknown property, and an `abiParameters` count that does not match the
|
|
172
|
+
* signature — and for an AuthKey that is not yet registered. Nothing is
|
|
173
|
+
* signed for a rejected request.
|
|
174
|
+
*/
|
|
175
|
+
async prepare(request) {
|
|
176
|
+
const body = serializedContractExecutionBody(request);
|
|
177
|
+
const bodyBytes = body.bytes;
|
|
178
|
+
const authorization = await (0, signedResource_1.authorizeSignedPost)({
|
|
179
|
+
operation: 'contract_execution',
|
|
180
|
+
authKey: await __classPrivateFieldGet(this, _ContractExecutionsClient_signing, "f").resolveAuthKey(),
|
|
181
|
+
authKeyId: __classPrivateFieldGet(this, _ContractExecutionsClient_signing, "f").authKeyId,
|
|
182
|
+
bodyBytes,
|
|
183
|
+
});
|
|
184
|
+
return new PreparedContractExecution_1.PreparedContractExecution({
|
|
185
|
+
idempotencyKey: body.idempotencyKey,
|
|
186
|
+
bodyBytes,
|
|
187
|
+
authorization,
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Send a prepared execution exactly as it was authorized.
|
|
192
|
+
*
|
|
193
|
+
* Safe to repeat: every call sends identical bytes and the identical
|
|
194
|
+
* authorization. DAA answers `201` for a new execution and `200` with the
|
|
195
|
+
* stored execution for an exact replay — including a replay after the
|
|
196
|
+
* authorization has expired — and both resolve here. A replay of a request
|
|
197
|
+
* DAA never accepted, once its authorization has expired, is refused; the
|
|
198
|
+
* recovery is a new execution with a new idempotency key, not a retry.
|
|
199
|
+
*
|
|
200
|
+
* @throws DaaError with `detail.kind === 'contract_violation'` for a prepared
|
|
201
|
+
* value authorized by a different AuthKey than this user client's, for a
|
|
202
|
+
* rejected, expired, or replayed authorization DAA did not accept, and for
|
|
203
|
+
* a response the SDK cannot read — DAA may have accepted that request, so
|
|
204
|
+
* submit the same value again or poll; never prepare it again under a new
|
|
205
|
+
* key; `clock_skew` when DAA refused the authorization because the device
|
|
206
|
+
* clock was more than 60 seconds off when {@link prepare} signed it — DAA
|
|
207
|
+
* did not accept it, and resubmitting sends the same authorization, so
|
|
208
|
+
* correct the device time and treat it like an expired authorization: a
|
|
209
|
+
* new execution with a new idempotency key; `idempotency_conflict` for a `409` with
|
|
210
|
+
* `IDEMPOTENCY_KEY_REUSED`; `api` for any other status (retryable for `429`
|
|
211
|
+
* and `5xx`: submit the same value again); `transport` if the consumer's
|
|
212
|
+
* transport throws (retryable: submit the same value again).
|
|
213
|
+
*/
|
|
214
|
+
async submit(prepared) {
|
|
215
|
+
const { bodyBytes, authorization } = (0, PreparedContractExecution_1.preparedParts)(prepared);
|
|
216
|
+
if (authorizationKeyId(authorization) !== __classPrivateFieldGet(this, _ContractExecutionsClient_signing, "f").authKeyId) {
|
|
217
|
+
throw (0, errors_1.contractViolation)('the prepared contract execution was authorized by a different AuthKey');
|
|
218
|
+
}
|
|
219
|
+
return (0, signedResource_1.postAuthorizedResource)({
|
|
220
|
+
transport: __classPrivateFieldGet(this, _ContractExecutionsClient_transport, "f"),
|
|
221
|
+
operation: 'contract_execution',
|
|
222
|
+
bodyBytes,
|
|
223
|
+
authorization,
|
|
224
|
+
expectedStatuses: [201, 200],
|
|
225
|
+
decode: contractExecutionPayload_1.toContractExecution,
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Rebuild a prepared execution from `PreparedContractExecution.toPersisted`.
|
|
230
|
+
*
|
|
231
|
+
* The record is checked, not trusted: the body must be one {@link prepare}
|
|
232
|
+
* would have produced, byte for byte, and the authorization must be a
|
|
233
|
+
* compact ES256 `contract_execution` authorization over exactly that body
|
|
234
|
+
* and its idempotency key. This is the integrity of a stored record, not
|
|
235
|
+
* verification: the signature is DAA's to check. Its expiry is deliberately
|
|
236
|
+
* not checked — see {@link submit}.
|
|
237
|
+
*
|
|
238
|
+
* @throws DaaError with `detail.kind === 'contract_violation'` for a record
|
|
239
|
+
* that fails any of those checks.
|
|
240
|
+
*/
|
|
241
|
+
restore(persisted) {
|
|
242
|
+
(0, requestBody_1.requireBodyObject)(persisted, 'persisted contract execution');
|
|
243
|
+
(0, requestBody_1.requireKnownProperties)(persisted, ['version', 'body', 'authorization'], 'persisted contract execution');
|
|
244
|
+
const { version, body, authorization } = persisted;
|
|
245
|
+
if (version !== 1 || typeof body !== 'string' || typeof authorization !== 'string') {
|
|
246
|
+
throw (0, errors_1.contractViolation)('persisted contract execution is not a version 1 record');
|
|
247
|
+
}
|
|
248
|
+
let bodyBytes;
|
|
249
|
+
let parsed;
|
|
250
|
+
try {
|
|
251
|
+
bodyBytes = (0, base64url_1.fromBase64Url)(body);
|
|
252
|
+
parsed = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(bodyBytes));
|
|
253
|
+
}
|
|
254
|
+
catch {
|
|
255
|
+
throw (0, errors_1.contractViolation)('persisted contract execution body is not UTF-8 JSON');
|
|
256
|
+
}
|
|
257
|
+
const projected = serializedContractExecutionBody(parsed);
|
|
258
|
+
if (!sameBytes(projected.bytes, bodyBytes)) {
|
|
259
|
+
throw (0, errors_1.contractViolation)('persisted contract execution body is not one the SDK prepared');
|
|
260
|
+
}
|
|
261
|
+
requireAuthorizationBinding(authorization, bodyBytes, projected.idempotencyKey);
|
|
262
|
+
return new PreparedContractExecution_1.PreparedContractExecution({
|
|
263
|
+
idempotencyKey: projected.idempotencyKey,
|
|
264
|
+
bodyBytes,
|
|
265
|
+
authorization,
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
exports.ContractExecutionsClient = ContractExecutionsClient;
|
|
270
|
+
_ContractExecutionsClient_transport = new WeakMap(), _ContractExecutionsClient_signing = new WeakMap();
|
|
271
|
+
/** Validate, project, and serialize once, within DAA's body limit. */
|
|
272
|
+
function serializedContractExecutionBody(request) {
|
|
273
|
+
const body = createContractExecutionBody(request);
|
|
274
|
+
const bytes = (0, serialization_1.serializeBody)(body.value);
|
|
275
|
+
if (bytes.length > MAX_BODY_BYTES) {
|
|
276
|
+
throw (0, errors_1.contractViolation)('contract execution request body exceeds 65536 bytes');
|
|
277
|
+
}
|
|
278
|
+
return { bytes, idempotencyKey: body.idempotencyKey };
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Project a validated request onto the registry's `contract_execution` shape.
|
|
282
|
+
*
|
|
283
|
+
* Each caller property is read exactly once, into the returned value, so a
|
|
284
|
+
* getter cannot pass validation with one value and serialize another. Returned
|
|
285
|
+
* rather than serialized here so {@link ContractExecutionsClient.prepare} holds
|
|
286
|
+
* the one byte slice it signs.
|
|
287
|
+
*/
|
|
288
|
+
function createContractExecutionBody(request) {
|
|
289
|
+
(0, requestBody_1.requireBodyObject)(request, 'contract execution request');
|
|
290
|
+
const record = request;
|
|
291
|
+
// `Object.keys` (which the unknown-property check reads, as `JSON.stringify`
|
|
292
|
+
// does) cannot see an inherited property, but a plain read can. Refusing one
|
|
293
|
+
// keeps "present" meaning the same thing to every check below.
|
|
294
|
+
for (const name of ALL_PROPERTIES) {
|
|
295
|
+
if (name in record && !Object.prototype.hasOwnProperty.call(record, name)) {
|
|
296
|
+
throw (0, errors_1.contractViolation)(`contract execution request property "${name}" must be its own`);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
const hasCallData = Object.prototype.hasOwnProperty.call(record, 'callData');
|
|
300
|
+
const hasAbi = Object.prototype.hasOwnProperty.call(record, 'abiFunctionSignature') ||
|
|
301
|
+
Object.prototype.hasOwnProperty.call(record, 'abiParameters');
|
|
302
|
+
if (hasCallData === hasAbi) {
|
|
303
|
+
throw (0, errors_1.contractViolation)('contract execution request needs exactly one of callData or abiFunctionSignature with abiParameters');
|
|
304
|
+
}
|
|
305
|
+
(0, requestBody_1.requireKnownProperties)(request, hasCallData ? RAW_PROPERTIES : ABI_PROPERTIES, 'contract execution request');
|
|
306
|
+
const idempotencyKey = record['idempotencyKey'];
|
|
307
|
+
const accountId = record['accountId'];
|
|
308
|
+
const blockchain = record['blockchain'];
|
|
309
|
+
const contractAddress = record['contractAddress'];
|
|
310
|
+
const hasAmount = Object.prototype.hasOwnProperty.call(record, 'amount');
|
|
311
|
+
const amount = record['amount'];
|
|
312
|
+
if (typeof idempotencyKey !== 'string' || !(0, uuid_1.isUuidV4)(idempotencyKey)) {
|
|
313
|
+
throw (0, errors_1.contractViolation)('idempotencyKey must be a UUID v4');
|
|
314
|
+
}
|
|
315
|
+
if (typeof accountId !== 'string' || !(0, uuid_1.isUuid)(accountId)) {
|
|
316
|
+
throw (0, errors_1.contractViolation)('accountId must be a UUID');
|
|
317
|
+
}
|
|
318
|
+
if (typeof blockchain !== 'string' || !BLOCKCHAINS.includes(blockchain)) {
|
|
319
|
+
throw (0, errors_1.contractViolation)(`blockchain must be one of ${BLOCKCHAINS.join(', ')}`);
|
|
320
|
+
}
|
|
321
|
+
if (typeof contractAddress !== 'string' ||
|
|
322
|
+
!EVM_ADDRESS.test(contractAddress) ||
|
|
323
|
+
ZERO_ADDRESS.test(contractAddress)) {
|
|
324
|
+
throw (0, errors_1.contractViolation)('contractAddress must be a non-zero 0x-prefixed 20-byte address');
|
|
325
|
+
}
|
|
326
|
+
// An omitted amount is not sent, and `undefined` is not an omission: it is a
|
|
327
|
+
// present property that `JSON.stringify` would silently drop, so the caller
|
|
328
|
+
// could not tell which body it signed.
|
|
329
|
+
if (hasAmount && (typeof amount !== 'string' || !NATIVE_AMOUNT.test(amount))) {
|
|
330
|
+
throw (0, errors_1.contractViolation)('amount must be a non-negative decimal string, e.g. "0.1"');
|
|
331
|
+
}
|
|
332
|
+
const common = {
|
|
333
|
+
idempotencyKey,
|
|
334
|
+
accountId,
|
|
335
|
+
blockchain,
|
|
336
|
+
contractAddress,
|
|
337
|
+
...(hasAmount ? { amount } : {}),
|
|
338
|
+
};
|
|
339
|
+
if (hasCallData) {
|
|
340
|
+
return { value: { ...common, callData: callDataOf(record['callData']) }, idempotencyKey };
|
|
341
|
+
}
|
|
342
|
+
const abiFunctionSignature = record['abiFunctionSignature'];
|
|
343
|
+
const abiParameters = record['abiParameters'];
|
|
344
|
+
if (typeof abiFunctionSignature !== 'string' ||
|
|
345
|
+
abiFunctionSignature.length > MAX_SIGNATURE_LENGTH ||
|
|
346
|
+
!ABI_SIGNATURE.test(abiFunctionSignature)) {
|
|
347
|
+
throw (0, errors_1.contractViolation)('abiFunctionSignature must be a canonical signature such as approve(address,uint256)');
|
|
348
|
+
}
|
|
349
|
+
if (!Array.isArray(abiParameters)) {
|
|
350
|
+
throw (0, errors_1.contractViolation)('abiParameters must be an array; use [] for no arguments');
|
|
351
|
+
}
|
|
352
|
+
if (abiParameters.length !== argumentCount(abiFunctionSignature)) {
|
|
353
|
+
throw (0, errors_1.contractViolation)('abiParameters must have one value per signature argument');
|
|
354
|
+
}
|
|
355
|
+
return {
|
|
356
|
+
value: {
|
|
357
|
+
...common,
|
|
358
|
+
abiFunctionSignature,
|
|
359
|
+
abiParameters: abiParametersOf(abiParameters, 1, { values: 0 }),
|
|
360
|
+
},
|
|
361
|
+
idempotencyKey,
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Top-level argument count of a signature that already matched
|
|
366
|
+
* {@link ABI_SIGNATURE}. Tuples are outside that grammar, so a comma always
|
|
367
|
+
* separates two top-level types.
|
|
368
|
+
*/
|
|
369
|
+
function argumentCount(signature) {
|
|
370
|
+
const inner = signature.slice(signature.indexOf('(') + 1, -1);
|
|
371
|
+
return inner === '' ? 0 : inner.split(',').length;
|
|
372
|
+
}
|
|
373
|
+
function callDataOf(callData) {
|
|
374
|
+
if (typeof callData !== 'string' || !CALL_DATA.test(callData)) {
|
|
375
|
+
throw (0, errors_1.contractViolation)('callData must be 0x-prefixed, even-length hex of at least one byte');
|
|
376
|
+
}
|
|
377
|
+
if ((callData.length - 2) / 2 > MAX_CALL_DATA_BYTES) {
|
|
378
|
+
throw (0, errors_1.contractViolation)('callData must be at most 16384 bytes');
|
|
379
|
+
}
|
|
380
|
+
return callData;
|
|
381
|
+
}
|
|
382
|
+
/** A validated copy of one array level of the parameter tree. */
|
|
383
|
+
function abiParametersOf(values, depth, total) {
|
|
384
|
+
if (depth > MAX_PARAMETER_DEPTH) {
|
|
385
|
+
throw (0, errors_1.contractViolation)('abiParameters may nest at most eight array levels');
|
|
386
|
+
}
|
|
387
|
+
const copy = [];
|
|
388
|
+
for (const value of values) {
|
|
389
|
+
total.values += 1;
|
|
390
|
+
if (total.values > MAX_PARAMETER_VALUES) {
|
|
391
|
+
throw (0, errors_1.contractViolation)('abiParameters may hold at most 1024 values in total');
|
|
392
|
+
}
|
|
393
|
+
copy.push(abiParameterOf(value, depth, total));
|
|
394
|
+
}
|
|
395
|
+
return copy;
|
|
396
|
+
}
|
|
397
|
+
function abiParameterOf(value, depth, total) {
|
|
398
|
+
if (typeof value === 'string' || typeof value === 'boolean') {
|
|
399
|
+
return value;
|
|
400
|
+
}
|
|
401
|
+
if (typeof value === 'number') {
|
|
402
|
+
// A safe integer is the only number whose `JSON.stringify` spelling is the
|
|
403
|
+
// value the caller wrote. `-0` is safe but spells `0`, which is the same
|
|
404
|
+
// integer, so it is not a change of meaning.
|
|
405
|
+
if (!Number.isSafeInteger(value)) {
|
|
406
|
+
throw (0, errors_1.contractViolation)('abiParameters numbers must be safe integers; pass larger integers as decimal strings');
|
|
407
|
+
}
|
|
408
|
+
return value;
|
|
409
|
+
}
|
|
410
|
+
if (Array.isArray(value)) {
|
|
411
|
+
return abiParametersOf(value, depth + 1, total);
|
|
412
|
+
}
|
|
413
|
+
throw (0, errors_1.contractViolation)('abiParameters values must be strings, booleans, safe integers, or arrays of those');
|
|
414
|
+
}
|
|
415
|
+
/** The `kid` of a compact JWS this SDK produced, or `null` if it cannot be read. */
|
|
416
|
+
function authorizationKeyId(authorization) {
|
|
417
|
+
const header = (0, deviceAuthorization_1.jwsSegmentJson)(authorization, 0);
|
|
418
|
+
return header !== null && typeof header['kid'] === 'string' ? header['kid'] : null;
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* Check that a restored authorization is the `contract_execution` one for
|
|
422
|
+
* these exact bytes. This is integrity of a stored record, not verification:
|
|
423
|
+
* the signature itself is DAA's to check.
|
|
424
|
+
*/
|
|
425
|
+
function requireAuthorizationBinding(authorization, bodyBytes, idempotencyKey) {
|
|
426
|
+
const profile = (0, deviceAuthorization_1.deviceAuthorizationProfile)('contract_execution');
|
|
427
|
+
const header = (0, deviceAuthorization_1.jwsSegmentJson)(authorization, 0);
|
|
428
|
+
const claims = (0, deviceAuthorization_1.jwsSegmentJson)(authorization, 1);
|
|
429
|
+
if (header === null ||
|
|
430
|
+
claims === null ||
|
|
431
|
+
header['alg'] !== 'ES256' ||
|
|
432
|
+
authorizationKeyId(authorization) === null ||
|
|
433
|
+
!isJoseEs256Signature(authorization.split('.')[2] ?? '') ||
|
|
434
|
+
claims['discriminator'] !== profile.discriminator ||
|
|
435
|
+
claims['schema_version'] !== profile.schemaVersion ||
|
|
436
|
+
claims['method'] !== profile.method ||
|
|
437
|
+
claims['canonical_path'] !== profile.canonicalPath ||
|
|
438
|
+
claims['idempotency_key'] !== idempotencyKey ||
|
|
439
|
+
claims['body_sha256'] !== (0, base64url_1.toBase64Url)((0, sha256_1.sha256)(bodyBytes))) {
|
|
440
|
+
throw (0, errors_1.contractViolation)('persisted contract execution authorization does not match its body');
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
/** A base64url segment that decodes to the 64-byte `R || S` ES256 signature. */
|
|
444
|
+
function isJoseEs256Signature(segment) {
|
|
445
|
+
try {
|
|
446
|
+
return (0, base64url_1.fromBase64Url)(segment).length === 64;
|
|
447
|
+
}
|
|
448
|
+
catch {
|
|
449
|
+
return false;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
function sameBytes(a, b) {
|
|
453
|
+
if (a.length !== b.length) {
|
|
454
|
+
return false;
|
|
455
|
+
}
|
|
456
|
+
for (let i = 0; i < a.length; i++) {
|
|
457
|
+
if (a[i] !== b[i]) {
|
|
458
|
+
return false;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
return true;
|
|
462
|
+
}
|
|
@@ -0,0 +1,187 @@
|
|
|
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 { DaaEnvironment } from '../config';
|
|
19
|
+
import { DaaError } from '../errors';
|
|
20
|
+
import type { DeviceContext } from '../models/DaaUserContext';
|
|
21
|
+
import type { DeviceStatus } from '../models/DeviceStatus';
|
|
22
|
+
import type { DaaHttpRequest, DaaTransport } from '../transport/DaaTransport';
|
|
23
|
+
import { AccountLimitsClient } from './AccountLimitsClient';
|
|
24
|
+
import { AccountsClient } from './AccountsClient';
|
|
25
|
+
import { ContractExecutionsClient } from './ContractExecutionsClient';
|
|
26
|
+
import { DepositAddressesClient } from './DepositAddressesClient';
|
|
27
|
+
import { DepositsClient } from './DepositsClient';
|
|
28
|
+
import { type ApproveDeviceArgs } from './deviceApproval';
|
|
29
|
+
import { FiatAccountsClient } from './FiatAccountsClient';
|
|
30
|
+
import { type DaaUserSigning } from './signedResource';
|
|
31
|
+
import { TransactionsClient } from './TransactionsClient';
|
|
32
|
+
import { TransfersClient } from './TransfersClient';
|
|
33
|
+
import { WithdrawalsClient } from './WithdrawalsClient';
|
|
34
|
+
/**
|
|
35
|
+
* The authenticated operations surface, as the SDK contract's `DaaUserClient`.
|
|
36
|
+
*
|
|
37
|
+
* The contract reaches this through the root client's `forUser(context)`, and every
|
|
38
|
+
* operation lives here rather than on the root client — the root client has only
|
|
39
|
+
* `auth` and `forUser`.
|
|
40
|
+
*
|
|
41
|
+
* Every resource client here has at least one operation; the surface never
|
|
42
|
+
* exposes a client with none.
|
|
43
|
+
*
|
|
44
|
+
* Signing material reaches only the clients that have a signed operation.
|
|
45
|
+
* Account limits, deposits, deposit addresses, transactions, and fiat
|
|
46
|
+
* accounts read (and, for deposit addresses, write unsigned) and so are
|
|
47
|
+
* handed none — a client that cannot sign cannot be made to sign by a later
|
|
48
|
+
* edit that forgets which calls are authorized. Fiat-account reads and
|
|
49
|
+
* get-instructions are both unsigned operations; for account limits/usage,
|
|
50
|
+
* see `AccountLimitsClient`'s class note for why it is unsigned.
|
|
51
|
+
*/
|
|
52
|
+
export declare class DaaUserClient {
|
|
53
|
+
#private;
|
|
54
|
+
/** Reads over DAA accounts, and the signed account create. */
|
|
55
|
+
readonly accounts: AccountsClient;
|
|
56
|
+
/** Reads over an account's limits and current usage. */
|
|
57
|
+
readonly accountLimits: AccountLimitsClient;
|
|
58
|
+
/** Reads over DAA deposit addresses. */
|
|
59
|
+
readonly depositAddresses: DepositAddressesClient;
|
|
60
|
+
/** Reads over DAA deposits, and the paged deposit list. */
|
|
61
|
+
readonly deposits: DepositsClient;
|
|
62
|
+
/** Reads over DAA unified account activity. */
|
|
63
|
+
readonly transactions: TransactionsClient;
|
|
64
|
+
/** Reads over DAA transfers, and the signed transfer create. */
|
|
65
|
+
readonly transfers: TransfersClient;
|
|
66
|
+
/** Reads over DAA withdrawals, and the signed withdrawal create. */
|
|
67
|
+
readonly withdrawals: WithdrawalsClient;
|
|
68
|
+
/** Reads over self-custody contract executions, and the signed create. */
|
|
69
|
+
readonly contractExecutions: ContractExecutionsClient;
|
|
70
|
+
/** Reads over wire and ACH fiat accounts, and their receiving instructions. */
|
|
71
|
+
readonly fiatAccounts: FiatAccountsClient;
|
|
72
|
+
/** @internal Constructed only through {@link createDaaUserClient}. */
|
|
73
|
+
constructor(transport: DaaTransport, environment: DaaEnvironment, signing: DaaUserSigning, publicApiOriginOverride?: string);
|
|
74
|
+
/**
|
|
75
|
+
* Signed context refresh (`refreshContext`).
|
|
76
|
+
*
|
|
77
|
+
* `get_device_context` (`GET /v1/accounts/auth/context`) is a registered-device
|
|
78
|
+
* authorization operation, not an ordinary unsigned read: the device
|
|
79
|
+
* authorization payload applies to registered-device authorization for
|
|
80
|
+
* protected writes and signed context refresh, alongside `transfer` and
|
|
81
|
+
* `withdrawal`, and `securekey/SecureKey.ts` names "signed context refresh"
|
|
82
|
+
* alongside "protected writes" as one of the defined DAA operations signing is
|
|
83
|
+
* reachable for. There is no request body: `getSignedResource` signs over the
|
|
84
|
+
* empty byte array per the bodyless-request rule and sends nothing as
|
|
85
|
+
* the request entity.
|
|
86
|
+
*
|
|
87
|
+
* @throws DaaError with `detail.kind === 'contract_violation'` for an AuthKey
|
|
88
|
+
* that is not yet registered, for a rejected or replayed authorization
|
|
89
|
+
* (including a key that is no longer active: DAA has no revoked-credential
|
|
90
|
+
* code, so this never throws `device_revoked`), for a response the SDK
|
|
91
|
+
* cannot read, and once this client is {@link close}d; `clock_skew` when
|
|
92
|
+
* DAA refused the authorization because the device clock was more than 60
|
|
93
|
+
* seconds off: correct the device time, then refresh again;
|
|
94
|
+
* `user_cancelled` when the user dismisses the authentication prompt;
|
|
95
|
+
* `detail.kind === 'api'` for a status other than the documented `200`; and
|
|
96
|
+
* `detail.kind === 'transport'` if the consumer's transport throws, with
|
|
97
|
+
* the thrown value as `err.cause`.
|
|
98
|
+
*/
|
|
99
|
+
refreshContext(): Promise<DeviceContext>;
|
|
100
|
+
/**
|
|
101
|
+
* Approve a new device on this account from this one (add-a-device).
|
|
102
|
+
*
|
|
103
|
+
* The new device shows a six-digit matching code; the user types it here.
|
|
104
|
+
* The SDK reads the request from the device list, checks the typed code
|
|
105
|
+
* against the code the new device's secret produces, and only then signs
|
|
106
|
+
* `approve_device` with this device's key, so a wrong code is refused before
|
|
107
|
+
* any biometric prompt. The prompt shows the code. On success the new device
|
|
108
|
+
* is in its cool-down: the result is normally `pending_activation` with its
|
|
109
|
+
* `readyAt`.
|
|
110
|
+
*
|
|
111
|
+
* `requestId` comes from the partner (the `account.device.pending` webhook
|
|
112
|
+
* pushed to this device) or from the device list's `pendingRequests`.
|
|
113
|
+
*
|
|
114
|
+
* After a `transport` failure, a retryable `api` error, a `401` (once
|
|
115
|
+
* credentials are refreshed) or a `contract_violation`, call it again on this
|
|
116
|
+
* client with the same `requestId`: it signs the same approval body again (the
|
|
117
|
+
* user sees the prompt again), and DAA returns its saved result if the first
|
|
118
|
+
* one went through. Another `4xx` is DAA refusing the approval, and calling
|
|
119
|
+
* again gets the same answer. The body is kept in memory until a valid
|
|
120
|
+
* result, `device_approval_invalid` or `close()`.
|
|
121
|
+
* After `device_approval_busy` the same applies: nothing was saved, so DAA
|
|
122
|
+
* runs the re-signed approval again.
|
|
123
|
+
*
|
|
124
|
+
* Don't call it again for a `requestId` while a call for it is still
|
|
125
|
+
* running: each call reads and signs on its own, so the user sees two
|
|
126
|
+
* prompts.
|
|
127
|
+
*
|
|
128
|
+
* @throws DaaError with `detail.kind`:
|
|
129
|
+
* `matching_code_mismatch` when the typed code is wrong (let the user type
|
|
130
|
+
* it again); `device_approval_not_ready` when the new device has not sent
|
|
131
|
+
* its code secret yet (try again in a few seconds);
|
|
132
|
+
* `device_approval_invalid` when the request is no longer waiting (it
|
|
133
|
+
* expired, or was decided or cancelled); `device_approval_busy` when the
|
|
134
|
+
* account changed meanwhile (call again; the user sees the prompt again);
|
|
135
|
+
* `user_cancelled` when the user dismisses the prompt (the request stays
|
|
136
|
+
* waiting); `clock_skew`, `contract_violation`, `api` and `transport` as
|
|
137
|
+
* for any signed write.
|
|
138
|
+
*/
|
|
139
|
+
approveDevice(args: ApproveDeviceArgs): Promise<DeviceStatus>;
|
|
140
|
+
/**
|
|
141
|
+
* `DaaUserClient.close()` clears active context from memory and cancels
|
|
142
|
+
* unsent work. It preserves an active profile-scoped AuthKey and credential;
|
|
143
|
+
* application logout is not device revocation.
|
|
144
|
+
*
|
|
145
|
+
* This class holds no `DaaUserContext` object and no cancellable in-flight
|
|
146
|
+
* work of its own to release — the context a caller passed to `forUser` is
|
|
147
|
+
* never retained here, only the plain `authKeyId` string and a resolver
|
|
148
|
+
* closure, and every call this SDK makes is a single `transport.send` awaited
|
|
149
|
+
* to completion with no cancellation token in the transport contract to
|
|
150
|
+
* cancel. Concretely, close() revokes this instance's own capability to
|
|
151
|
+
* produce a fresh `X-Device-Authorization` at all, so `refreshContext`,
|
|
152
|
+
* every signed `create` on `accounts` / `transfers` / `withdrawals`, and
|
|
153
|
+
* `contractExecutions.prepare` fail closed with `contract_violation` from
|
|
154
|
+
* this point on instead of silently continuing to sign. The guarded
|
|
155
|
+
* transport also refuses unsigned reads, writes, retained Page navigation
|
|
156
|
+
* closures, and a `contractExecutions.submit` of an execution prepared
|
|
157
|
+
* earlier, so unsent work cannot outlive the user surface that created it.
|
|
158
|
+
* That prepared execution stays valid: a later `forUser` client for the same
|
|
159
|
+
* AuthKey can submit it. The registered AuthKey and Circle's registration
|
|
160
|
+
* acknowledgement are untouched — nothing here calls the native store, so
|
|
161
|
+
* there is nothing here that could revoke either. Idempotent: closing an
|
|
162
|
+
* already-closed client is a no-op.
|
|
163
|
+
*/
|
|
164
|
+
close(): void;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Build the operations surface over a transport.
|
|
168
|
+
*
|
|
169
|
+
* Deliberately **not** exported from `index.ts`, and deliberately not a member of
|
|
170
|
+
* `DaaClient`: a consumer must not reach this without the user context that
|
|
171
|
+
* `forUser` requires, decoded from an `ACTIVE` Device Registration Complete.
|
|
172
|
+
*
|
|
173
|
+
* `publicApiOrigin` is the override `DaaClient` has already validated. Without
|
|
174
|
+
* it, the environment's public API origin is the pagination trust anchor.
|
|
175
|
+
*/
|
|
176
|
+
export declare function createDaaUserClient(transport: DaaTransport, environment: DaaEnvironment, signing: DaaUserSigning, publicApiOrigin?: string): DaaUserClient;
|
|
177
|
+
/**
|
|
178
|
+
* Wrap a throw from the consumer's transport as a `transport` error. An error
|
|
179
|
+
* that is already a `DaaError` passes through unchanged, as in
|
|
180
|
+
* `mapNativeError`.
|
|
181
|
+
*
|
|
182
|
+
* The idempotency key is read from the exact bytes that were handed to the
|
|
183
|
+
* transport, with the same reader the signed `409` mapping uses. A body the
|
|
184
|
+
* reader cannot parse leaves the key off rather than replacing the transport
|
|
185
|
+
* failure with a different error.
|
|
186
|
+
*/
|
|
187
|
+
export declare function asTransportFailure(err: unknown, request: DaaHttpRequest): DaaError;
|