@gvnrdao/dh-lit-actions 0.0.61 → 0.0.63
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/package.json +3 -3
- package/pkg-dist/pkg-src/constants/chunks/contract-deployments.d.ts.map +1 -0
- package/pkg-dist/pkg-src/constants/chunks/contract-deployments.js.map +1 -0
- package/pkg-dist/pkg-src/constants/chunks/lit-actions-registry.d.ts.map +1 -0
- package/pkg-dist/pkg-src/constants/chunks/lit-actions-registry.js.map +1 -0
- package/pkg-dist/pkg-src/constants/chunks/package-registry.d.ts.map +1 -0
- package/pkg-dist/pkg-src/constants/chunks/package-registry.js.map +1 -0
- package/pkg-dist/pkg-src/constants/index.d.ts.map +1 -0
- package/pkg-dist/pkg-src/constants/index.js.map +1 -0
- package/pkg-dist/pkg-src/executors/chunks/vault-snapshot-executor.d.ts +40 -0
- package/pkg-dist/pkg-src/executors/chunks/vault-snapshot-executor.d.ts.map +1 -0
- package/pkg-dist/pkg-src/executors/chunks/vault-snapshot-executor.js +102 -0
- package/pkg-dist/pkg-src/executors/chunks/vault-snapshot-executor.js.map +1 -0
- package/pkg-dist/pkg-src/executors/index.d.ts +43 -0
- package/pkg-dist/pkg-src/executors/index.d.ts.map +1 -0
- package/pkg-dist/pkg-src/executors/index.js +48 -0
- package/pkg-dist/pkg-src/executors/index.js.map +1 -0
- package/pkg-dist/pkg-src/index.d.ts.map +1 -0
- package/pkg-dist/pkg-src/index.js.map +1 -0
- package/pkg-dist/pkg-src/interfaces/chunks/diamond-hands-lit-actions.i.d.ts.map +1 -0
- package/pkg-dist/pkg-src/interfaces/chunks/diamond-hands-lit-actions.i.js.map +1 -0
- package/pkg-dist/pkg-src/interfaces/chunks/lit-action-config.i.d.ts.map +1 -0
- package/pkg-dist/pkg-src/interfaces/chunks/lit-action-config.i.js.map +1 -0
- package/pkg-dist/pkg-src/interfaces/chunks/lit-action-name.i.d.ts.map +1 -0
- package/pkg-dist/pkg-src/interfaces/chunks/lit-action-name.i.js.map +1 -0
- package/pkg-dist/pkg-src/interfaces/chunks/lit-action-registry.i.d.ts.map +1 -0
- package/pkg-dist/pkg-src/interfaces/chunks/lit-action-registry.i.js.map +1 -0
- package/pkg-dist/pkg-src/interfaces/chunks/pkp-info.i.d.ts.map +1 -0
- package/pkg-dist/pkg-src/interfaces/chunks/pkp-info.i.js.map +1 -0
- package/pkg-dist/pkg-src/interfaces/deployments.d.ts.map +1 -0
- package/pkg-dist/pkg-src/interfaces/deployments.js.map +1 -0
- package/pkg-dist/pkg-src/interfaces/index.d.ts.map +1 -0
- package/pkg-dist/pkg-src/interfaces/index.js.map +1 -0
- package/pkg-dist/pkg-src/utils/chunks/cid-utils.d.ts.map +1 -0
- package/pkg-dist/pkg-src/utils/chunks/cid-utils.js.map +1 -0
- package/pkg-dist/pkg-src/utils/chunks/connection-helpers.d.ts.map +1 -0
- package/pkg-dist/pkg-src/utils/chunks/connection-helpers.js.map +1 -0
- package/pkg-dist/pkg-src/utils/chunks/debug-logger.d.ts.map +1 -0
- package/pkg-dist/pkg-src/utils/chunks/debug-logger.js.map +1 -0
- package/pkg-dist/pkg-src/utils/chunks/error-classification.d.ts.map +1 -0
- package/pkg-dist/pkg-src/utils/chunks/error-classification.js.map +1 -0
- package/pkg-dist/pkg-src/utils/chunks/lit-action-helpers.d.ts.map +1 -0
- package/pkg-dist/pkg-src/utils/chunks/lit-action-helpers.js.map +1 -0
- package/pkg-dist/pkg-src/utils/chunks/pkp-setup.d.ts.map +1 -0
- package/pkg-dist/pkg-src/utils/chunks/pkp-setup.js.map +1 -0
- package/pkg-dist/pkg-src/utils/chunks/session-signature-cache.d.ts.map +1 -0
- package/pkg-dist/pkg-src/utils/chunks/session-signature-cache.js.map +1 -0
- package/pkg-dist/pkg-src/utils/index.d.ts.map +1 -0
- package/pkg-dist/pkg-src/utils/index.js.map +1 -0
- package/pkg-dist/src/constants/chunks/bitcoin-network-config.d.ts +130 -0
- package/pkg-dist/src/constants/chunks/bitcoin-network-config.d.ts.map +1 -0
- package/pkg-dist/src/constants/chunks/bitcoin-network-config.js +244 -0
- package/pkg-dist/src/constants/chunks/bitcoin-network-config.js.map +1 -0
- package/pkg-dist/src/constants/chunks/bitcoin.d.ts +42 -0
- package/pkg-dist/src/constants/chunks/bitcoin.d.ts.map +1 -0
- package/pkg-dist/src/constants/chunks/bitcoin.js +45 -0
- package/pkg-dist/src/constants/chunks/bitcoin.js.map +1 -0
- package/pkg-dist/src/constants/chunks/decimals.d.ts +44 -0
- package/pkg-dist/src/constants/chunks/decimals.d.ts.map +1 -0
- package/pkg-dist/src/constants/chunks/decimals.js +47 -0
- package/pkg-dist/src/constants/chunks/decimals.js.map +1 -0
- package/pkg-dist/src/constants/chunks/liquidation.d.ts +51 -0
- package/pkg-dist/src/constants/chunks/liquidation.d.ts.map +1 -0
- package/pkg-dist/src/constants/chunks/liquidation.js +54 -0
- package/pkg-dist/src/constants/chunks/liquidation.js.map +1 -0
- package/pkg-dist/src/constants/chunks/loan-status.d.ts +57 -0
- package/pkg-dist/src/constants/chunks/loan-status.d.ts.map +1 -0
- package/pkg-dist/src/constants/chunks/loan-status.js +95 -0
- package/pkg-dist/src/constants/chunks/loan-status.js.map +1 -0
- package/pkg-dist/src/constants/chunks/price-oracle.d.ts +46 -0
- package/pkg-dist/src/constants/chunks/price-oracle.d.ts.map +1 -0
- package/pkg-dist/src/constants/chunks/price-oracle.js +49 -0
- package/pkg-dist/src/constants/chunks/price-oracle.js.map +1 -0
- package/pkg-dist/src/constants/chunks/quantum-time.d.ts +63 -0
- package/pkg-dist/src/constants/chunks/quantum-time.d.ts.map +1 -0
- package/pkg-dist/src/constants/chunks/quantum-time.js +66 -0
- package/pkg-dist/src/constants/chunks/quantum-time.js.map +1 -0
- package/pkg-dist/src/constants/index.d.ts +16 -0
- package/pkg-dist/src/constants/index.d.ts.map +1 -0
- package/pkg-dist/src/constants/index.js +57 -0
- package/pkg-dist/src/constants/index.js.map +1 -0
- package/pkg-dist/src/interfaces/chunks/authorization.i.d.ts +19 -0
- package/pkg-dist/src/interfaces/chunks/authorization.i.d.ts.map +1 -0
- package/pkg-dist/src/interfaces/chunks/authorization.i.js +3 -0
- package/pkg-dist/src/interfaces/chunks/authorization.i.js.map +1 -0
- package/pkg-dist/src/interfaces/chunks/bitcoin-data-provider.i.d.ts +60 -0
- package/pkg-dist/src/interfaces/chunks/bitcoin-data-provider.i.d.ts.map +1 -0
- package/pkg-dist/src/interfaces/chunks/bitcoin-data-provider.i.js +3 -0
- package/pkg-dist/src/interfaces/chunks/bitcoin-data-provider.i.js.map +1 -0
- package/pkg-dist/src/interfaces/chunks/circuit-breaker.i.d.ts +18 -0
- package/pkg-dist/src/interfaces/chunks/circuit-breaker.i.d.ts.map +1 -0
- package/pkg-dist/src/interfaces/chunks/circuit-breaker.i.js +8 -0
- package/pkg-dist/src/interfaces/chunks/circuit-breaker.i.js.map +1 -0
- package/pkg-dist/src/interfaces/chunks/mint-authorization.i.d.ts +24 -0
- package/pkg-dist/src/interfaces/chunks/mint-authorization.i.d.ts.map +1 -0
- package/pkg-dist/src/interfaces/chunks/mint-authorization.i.js +5 -0
- package/pkg-dist/src/interfaces/chunks/mint-authorization.i.js.map +1 -0
- package/pkg-dist/src/interfaces/chunks/owner-authorization.d.ts +60 -0
- package/pkg-dist/src/interfaces/chunks/owner-authorization.d.ts.map +1 -0
- package/pkg-dist/src/interfaces/chunks/owner-authorization.js +8 -0
- package/pkg-dist/src/interfaces/chunks/owner-authorization.js.map +1 -0
- package/pkg-dist/src/interfaces/chunks/price-oracle.i.d.ts +26 -0
- package/pkg-dist/src/interfaces/chunks/price-oracle.i.d.ts.map +1 -0
- package/pkg-dist/src/interfaces/chunks/price-oracle.i.js +3 -0
- package/pkg-dist/src/interfaces/chunks/price-oracle.i.js.map +1 -0
- package/pkg-dist/src/interfaces/chunks/vault-balance-module.i.d.ts +23 -0
- package/pkg-dist/src/interfaces/chunks/vault-balance-module.i.d.ts.map +1 -0
- package/pkg-dist/src/interfaces/chunks/vault-balance-module.i.js +3 -0
- package/pkg-dist/src/interfaces/chunks/vault-balance-module.i.js.map +1 -0
- package/pkg-dist/src/interfaces/chunks/vault-balance.i.d.ts +63 -0
- package/pkg-dist/src/interfaces/chunks/vault-balance.i.d.ts.map +1 -0
- package/pkg-dist/src/interfaces/chunks/vault-balance.i.js +3 -0
- package/pkg-dist/src/interfaces/chunks/vault-balance.i.js.map +1 -0
- package/pkg-dist/src/interfaces/chunks/vault-snapshot.i.d.ts +51 -0
- package/pkg-dist/src/interfaces/chunks/vault-snapshot.i.d.ts.map +1 -0
- package/pkg-dist/src/interfaces/chunks/vault-snapshot.i.js +3 -0
- package/pkg-dist/src/interfaces/chunks/vault-snapshot.i.js.map +1 -0
- package/pkg-dist/src/interfaces/index.d.ts +15 -0
- package/pkg-dist/src/interfaces/index.d.ts.map +1 -0
- package/pkg-dist/src/interfaces/index.js +30 -0
- package/pkg-dist/src/interfaces/index.js.map +1 -0
- package/pkg-dist/src/modules/authorization.module.d.ts +160 -0
- package/pkg-dist/src/modules/authorization.module.d.ts.map +1 -0
- package/pkg-dist/src/modules/authorization.module.js +317 -0
- package/pkg-dist/src/modules/authorization.module.js.map +1 -0
- package/pkg-dist/src/modules/bitcoin-data-provider.module.d.ts +91 -0
- package/pkg-dist/src/modules/bitcoin-data-provider.module.d.ts.map +1 -0
- package/pkg-dist/src/modules/bitcoin-data-provider.module.js +261 -0
- package/pkg-dist/src/modules/bitcoin-data-provider.module.js.map +1 -0
- package/pkg-dist/src/modules/business-rules-math.module.d.ts +155 -0
- package/pkg-dist/src/modules/business-rules-math.module.d.ts.map +1 -0
- package/pkg-dist/src/modules/business-rules-math.module.js +309 -0
- package/pkg-dist/src/modules/business-rules-math.module.js.map +1 -0
- package/pkg-dist/src/modules/price-oracle.module.d.ts +29 -0
- package/pkg-dist/src/modules/price-oracle.module.d.ts.map +1 -0
- package/pkg-dist/src/modules/price-oracle.module.js +223 -0
- package/pkg-dist/src/modules/price-oracle.module.js.map +1 -0
- package/pkg-dist/src/modules/protocol-parameters.module.d.ts +58 -0
- package/pkg-dist/src/modules/protocol-parameters.module.d.ts.map +1 -0
- package/pkg-dist/src/modules/protocol-parameters.module.js +125 -0
- package/pkg-dist/src/modules/protocol-parameters.module.js.map +1 -0
- package/pkg-dist/src/modules/quantum-time.module.d.ts +149 -0
- package/pkg-dist/src/modules/quantum-time.module.d.ts.map +1 -0
- package/pkg-dist/src/modules/quantum-time.module.js +240 -0
- package/pkg-dist/src/modules/quantum-time.module.js.map +1 -0
- package/pkg-dist/src/modules/vault-balance.module.d.ts +172 -0
- package/pkg-dist/src/modules/vault-balance.module.d.ts.map +1 -0
- package/pkg-dist/src/modules/vault-balance.module.js +318 -0
- package/pkg-dist/src/modules/vault-balance.module.js.map +1 -0
- package/pkg-dist/src/modules/vault-snapshot.d.ts +168 -0
- package/pkg-dist/src/modules/vault-snapshot.d.ts.map +1 -0
- package/pkg-dist/src/modules/vault-snapshot.js +370 -0
- package/pkg-dist/src/modules/vault-snapshot.js.map +1 -0
- package/pkg-dist/constants/chunks/contract-deployments.d.ts.map +0 -1
- package/pkg-dist/constants/chunks/contract-deployments.js.map +0 -1
- package/pkg-dist/constants/chunks/lit-actions-registry.d.ts.map +0 -1
- package/pkg-dist/constants/chunks/lit-actions-registry.js.map +0 -1
- package/pkg-dist/constants/chunks/package-registry.d.ts.map +0 -1
- package/pkg-dist/constants/chunks/package-registry.js.map +0 -1
- package/pkg-dist/constants/index.d.ts.map +0 -1
- package/pkg-dist/constants/index.js.map +0 -1
- package/pkg-dist/index.d.ts.map +0 -1
- package/pkg-dist/index.js.map +0 -1
- package/pkg-dist/interfaces/chunks/diamond-hands-lit-actions.i.d.ts.map +0 -1
- package/pkg-dist/interfaces/chunks/diamond-hands-lit-actions.i.js.map +0 -1
- package/pkg-dist/interfaces/chunks/lit-action-config.i.d.ts.map +0 -1
- package/pkg-dist/interfaces/chunks/lit-action-config.i.js.map +0 -1
- package/pkg-dist/interfaces/chunks/lit-action-name.i.d.ts.map +0 -1
- package/pkg-dist/interfaces/chunks/lit-action-name.i.js.map +0 -1
- package/pkg-dist/interfaces/chunks/lit-action-registry.i.d.ts.map +0 -1
- package/pkg-dist/interfaces/chunks/lit-action-registry.i.js.map +0 -1
- package/pkg-dist/interfaces/chunks/pkp-info.i.d.ts.map +0 -1
- package/pkg-dist/interfaces/chunks/pkp-info.i.js.map +0 -1
- package/pkg-dist/interfaces/deployments.d.ts.map +0 -1
- package/pkg-dist/interfaces/deployments.js.map +0 -1
- package/pkg-dist/interfaces/index.d.ts.map +0 -1
- package/pkg-dist/interfaces/index.js.map +0 -1
- package/pkg-dist/utils/chunks/cid-utils.d.ts.map +0 -1
- package/pkg-dist/utils/chunks/cid-utils.js.map +0 -1
- package/pkg-dist/utils/chunks/connection-helpers.d.ts.map +0 -1
- package/pkg-dist/utils/chunks/connection-helpers.js.map +0 -1
- package/pkg-dist/utils/chunks/debug-logger.d.ts.map +0 -1
- package/pkg-dist/utils/chunks/debug-logger.js.map +0 -1
- package/pkg-dist/utils/chunks/error-classification.d.ts.map +0 -1
- package/pkg-dist/utils/chunks/error-classification.js.map +0 -1
- package/pkg-dist/utils/chunks/lit-action-helpers.d.ts.map +0 -1
- package/pkg-dist/utils/chunks/lit-action-helpers.js.map +0 -1
- package/pkg-dist/utils/chunks/pkp-setup.d.ts.map +0 -1
- package/pkg-dist/utils/chunks/pkp-setup.js.map +0 -1
- package/pkg-dist/utils/chunks/session-signature-cache.d.ts.map +0 -1
- package/pkg-dist/utils/chunks/session-signature-cache.js.map +0 -1
- package/pkg-dist/utils/index.d.ts.map +0 -1
- package/pkg-dist/utils/index.js.map +0 -1
- /package/pkg-dist/{constants → pkg-src/constants}/chunks/contract-deployments.d.ts +0 -0
- /package/pkg-dist/{constants → pkg-src/constants}/chunks/contract-deployments.js +0 -0
- /package/pkg-dist/{constants → pkg-src/constants}/chunks/lit-actions-registry.d.ts +0 -0
- /package/pkg-dist/{constants → pkg-src/constants}/chunks/lit-actions-registry.js +0 -0
- /package/pkg-dist/{constants → pkg-src/constants}/chunks/package-registry.d.ts +0 -0
- /package/pkg-dist/{constants → pkg-src/constants}/chunks/package-registry.js +0 -0
- /package/pkg-dist/{constants → pkg-src/constants}/index.d.ts +0 -0
- /package/pkg-dist/{constants → pkg-src/constants}/index.js +0 -0
- /package/pkg-dist/{index.d.ts → pkg-src/index.d.ts} +0 -0
- /package/pkg-dist/{index.js → pkg-src/index.js} +0 -0
- /package/pkg-dist/{interfaces → pkg-src/interfaces}/chunks/diamond-hands-lit-actions.i.d.ts +0 -0
- /package/pkg-dist/{interfaces → pkg-src/interfaces}/chunks/diamond-hands-lit-actions.i.js +0 -0
- /package/pkg-dist/{interfaces → pkg-src/interfaces}/chunks/lit-action-config.i.d.ts +0 -0
- /package/pkg-dist/{interfaces → pkg-src/interfaces}/chunks/lit-action-config.i.js +0 -0
- /package/pkg-dist/{interfaces → pkg-src/interfaces}/chunks/lit-action-name.i.d.ts +0 -0
- /package/pkg-dist/{interfaces → pkg-src/interfaces}/chunks/lit-action-name.i.js +0 -0
- /package/pkg-dist/{interfaces → pkg-src/interfaces}/chunks/lit-action-registry.i.d.ts +0 -0
- /package/pkg-dist/{interfaces → pkg-src/interfaces}/chunks/lit-action-registry.i.js +0 -0
- /package/pkg-dist/{interfaces → pkg-src/interfaces}/chunks/pkp-info.i.d.ts +0 -0
- /package/pkg-dist/{interfaces → pkg-src/interfaces}/chunks/pkp-info.i.js +0 -0
- /package/pkg-dist/{interfaces → pkg-src/interfaces}/deployments.d.ts +0 -0
- /package/pkg-dist/{interfaces → pkg-src/interfaces}/deployments.js +0 -0
- /package/pkg-dist/{interfaces → pkg-src/interfaces}/index.d.ts +0 -0
- /package/pkg-dist/{interfaces → pkg-src/interfaces}/index.js +0 -0
- /package/pkg-dist/{utils → pkg-src/utils}/chunks/cid-utils.d.ts +0 -0
- /package/pkg-dist/{utils → pkg-src/utils}/chunks/cid-utils.js +0 -0
- /package/pkg-dist/{utils → pkg-src/utils}/chunks/connection-helpers.d.ts +0 -0
- /package/pkg-dist/{utils → pkg-src/utils}/chunks/connection-helpers.js +0 -0
- /package/pkg-dist/{utils → pkg-src/utils}/chunks/debug-logger.d.ts +0 -0
- /package/pkg-dist/{utils → pkg-src/utils}/chunks/debug-logger.js +0 -0
- /package/pkg-dist/{utils → pkg-src/utils}/chunks/error-classification.d.ts +0 -0
- /package/pkg-dist/{utils → pkg-src/utils}/chunks/error-classification.js +0 -0
- /package/pkg-dist/{utils → pkg-src/utils}/chunks/lit-action-helpers.d.ts +0 -0
- /package/pkg-dist/{utils → pkg-src/utils}/chunks/lit-action-helpers.js +0 -0
- /package/pkg-dist/{utils → pkg-src/utils}/chunks/pkp-setup.d.ts +0 -0
- /package/pkg-dist/{utils → pkg-src/utils}/chunks/pkp-setup.js +0 -0
- /package/pkg-dist/{utils → pkg-src/utils}/chunks/session-signature-cache.d.ts +0 -0
- /package/pkg-dist/{utils → pkg-src/utils}/chunks/session-signature-cache.js +0 -0
- /package/pkg-dist/{utils → pkg-src/utils}/index.d.ts +0 -0
- /package/pkg-dist/{utils → pkg-src/utils}/index.js +0 -0
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthorizationModule = void 0;
|
|
4
|
+
const quantum_time_module_1 = require("./quantum-time.module");
|
|
5
|
+
/**
|
|
6
|
+
* Authorization Module
|
|
7
|
+
*
|
|
8
|
+
* Validates that LIT Action callers are authorized to perform operations.
|
|
9
|
+
*
|
|
10
|
+
* RESTORED PRODUCTION-GRADE DESIGN (from b2794c9):
|
|
11
|
+
* - Quantum timestamp prevents replay across different quantums
|
|
12
|
+
* - Waits for safe quantum moment before validation
|
|
13
|
+
* - Validates timestamp is within current quantum window
|
|
14
|
+
* - Signature proves caller identity
|
|
15
|
+
* - Contract verification proves ownership
|
|
16
|
+
*
|
|
17
|
+
* Authorization Flow:
|
|
18
|
+
* 1. Wait for safe quantum moment (if in dead zone)
|
|
19
|
+
* 2. Verify timestamp is within valid quantum window
|
|
20
|
+
* 3. Build message hash from parameters (positionId, timestamp, chainId, amount, action)
|
|
21
|
+
* 4. Recover signer address from signature (EIP-191 standard)
|
|
22
|
+
* 5. Verify recovered signer === position owner (from contract)
|
|
23
|
+
*
|
|
24
|
+
* Security Properties:
|
|
25
|
+
* - Quantum timing enforces 100-second windows with dead zone protection
|
|
26
|
+
* - Smart contract only accepts one operation per quantum per position
|
|
27
|
+
* - Signature proves caller owns the signing address
|
|
28
|
+
* - Contract verification proves signer is position owner
|
|
29
|
+
* - chainId prevents cross-chain replay attacks
|
|
30
|
+
* - Mode controls whether dev environments (hardhat/regtest) are allowed
|
|
31
|
+
*
|
|
32
|
+
* Example: mintUCD
|
|
33
|
+
* - Message: keccak256(positionId, timestamp, chainId, amount, actionHash)
|
|
34
|
+
* - User signs with wallet (EIP-191)
|
|
35
|
+
* - LIT Action WAITS for safe quantum moment
|
|
36
|
+
* - LIT Action VALIDATES quantum timestamp
|
|
37
|
+
* - LIT Action recovers signer address
|
|
38
|
+
* - LIT Action verifies signer is position owner (via contract)
|
|
39
|
+
*/
|
|
40
|
+
/**
|
|
41
|
+
* Authorization Module
|
|
42
|
+
*
|
|
43
|
+
* Provides methods to verify caller authorization for LIT Actions
|
|
44
|
+
*/
|
|
45
|
+
class AuthorizationModule {
|
|
46
|
+
/**
|
|
47
|
+
* Verify auth structure for amount/position/action operations
|
|
48
|
+
*
|
|
49
|
+
* Validates that all required fields are present and have correct types:
|
|
50
|
+
* - positionId (string, required)
|
|
51
|
+
* - chainId (number, required)
|
|
52
|
+
* - timestamp (number, required)
|
|
53
|
+
* - amount (required, any type that can convert to bigint)
|
|
54
|
+
* - action (string, required)
|
|
55
|
+
* - signature (string, required)
|
|
56
|
+
* - mode ("dev" or "prod", required)
|
|
57
|
+
*
|
|
58
|
+
* @param auth - Authorization object to validate (untyped)
|
|
59
|
+
* @returns Typed OwnerAmountActionAuthorization object after validation
|
|
60
|
+
* @throws Error if any validation fails
|
|
61
|
+
*/
|
|
62
|
+
static verifyAmountPositionActionAuthorizationStructure(auth) {
|
|
63
|
+
if (!auth || typeof auth !== "object") {
|
|
64
|
+
throw new Error('Missing or invalid "auth" parameter - must be an object');
|
|
65
|
+
}
|
|
66
|
+
// Validate all required auth fields
|
|
67
|
+
if (!auth.positionId) {
|
|
68
|
+
throw new Error("auth.positionId is required");
|
|
69
|
+
}
|
|
70
|
+
if (typeof auth.chainId !== "number") {
|
|
71
|
+
throw new Error("auth.chainId must be a number");
|
|
72
|
+
}
|
|
73
|
+
if (typeof auth.timestamp !== "number") {
|
|
74
|
+
throw new Error("auth.timestamp must be a number");
|
|
75
|
+
}
|
|
76
|
+
if (typeof auth.amount === "undefined" || auth.amount === null) {
|
|
77
|
+
throw new Error("auth.amount is required");
|
|
78
|
+
}
|
|
79
|
+
if (!auth.action) {
|
|
80
|
+
throw new Error("auth.action is required");
|
|
81
|
+
}
|
|
82
|
+
if (!auth.signature) {
|
|
83
|
+
throw new Error("auth.signature is required");
|
|
84
|
+
}
|
|
85
|
+
if (!auth.mode) {
|
|
86
|
+
throw new Error("auth.mode is required");
|
|
87
|
+
}
|
|
88
|
+
if (auth.mode !== "dev" && auth.mode !== "prod") {
|
|
89
|
+
throw new Error(`auth.mode must be "dev" or "prod", got: ${auth.mode}`);
|
|
90
|
+
}
|
|
91
|
+
// Return typed object after validation
|
|
92
|
+
return auth;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Recover signer address from signature
|
|
96
|
+
*
|
|
97
|
+
* Uses EIP-191 standard (Ethereum Signed Message)
|
|
98
|
+
*
|
|
99
|
+
* @param messageHash - Keccak256 hash of the message
|
|
100
|
+
* @param signature - Signature to verify
|
|
101
|
+
* @returns Recovered signer address
|
|
102
|
+
*/
|
|
103
|
+
static async recoverSigner(messageHash, signature) {
|
|
104
|
+
try {
|
|
105
|
+
// Convert message hash to bytes for EIP-191 prefixing
|
|
106
|
+
const messageHashBytes = ethers.utils.arrayify(messageHash);
|
|
107
|
+
// Apply EIP-191 prefix: "\x19Ethereum Signed Message:\n" + len(message) + message
|
|
108
|
+
const prefixedHash = ethers.utils.hashMessage(messageHashBytes);
|
|
109
|
+
// Recover address from signature
|
|
110
|
+
const recoveredAddress = ethers.utils.recoverAddress(prefixedHash, signature);
|
|
111
|
+
return recoveredAddress;
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
console.error("[Authorization] Signature recovery failed:", error);
|
|
115
|
+
throw new Error(`Failed to recover signer: ${error instanceof Error ? error.message : String(error)}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Agnostic authorization verification
|
|
120
|
+
*
|
|
121
|
+
* Verifies authorization for any action by:
|
|
122
|
+
* 1. Waiting for safe quantum moment
|
|
123
|
+
* 2. Validating quantum timestamp
|
|
124
|
+
* 3. Building message hash using provided buildMessage function
|
|
125
|
+
* 4. Recovering signer from signature
|
|
126
|
+
* 5. Checking authorization using provided isAuthorized function
|
|
127
|
+
*
|
|
128
|
+
* @param auth - Authorization parameters (timestamp, signature, mode)
|
|
129
|
+
* @param buildMessage - Function to build message hash (caller has context/closure)
|
|
130
|
+
* @param isAuthorized - Function to check if recovered address is authorized (caller has context/closure)
|
|
131
|
+
* @returns True if authorized
|
|
132
|
+
*/
|
|
133
|
+
static async verifyActionAuthorization(auth, buildMessage, isAuthorized) {
|
|
134
|
+
// STEP 1: Wait for safe quantum moment (if needed)
|
|
135
|
+
await (0, quantum_time_module_1.waitForSafeQuantumMoment)();
|
|
136
|
+
// STEP 2: Verify timestamp is within quantum window
|
|
137
|
+
try {
|
|
138
|
+
(0, quantum_time_module_1.validateQuantumTimestamp)(auth.timestamp);
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
console.error("[Authorization] Quantum timestamp validation failed:", error);
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
// Validate mode field
|
|
145
|
+
if (!auth.mode) {
|
|
146
|
+
console.error("[Authorization] Missing mode field");
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
if (auth.mode !== "dev" && auth.mode !== "prod") {
|
|
150
|
+
console.error(`[Authorization] Invalid mode: ${auth.mode}, must be "dev" or "prod"`);
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
// Production mode not yet supported
|
|
154
|
+
if (auth.mode === "prod") {
|
|
155
|
+
console.error('[Authorization] Production mode not yet supported - use mode="dev"');
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
// STEP 3: Build message hash using provided function
|
|
159
|
+
const messageHash = buildMessage();
|
|
160
|
+
console.log("[Authorization] Message hash:", messageHash);
|
|
161
|
+
// STEP 4: Recover signer from signature
|
|
162
|
+
console.log("[Authorization] Recovering signer from signature...");
|
|
163
|
+
console.log(" signature:", auth.signature);
|
|
164
|
+
const recoveredAddress = await this.recoverSigner(messageHash, auth.signature);
|
|
165
|
+
console.log(" recoveredAddress:", recoveredAddress);
|
|
166
|
+
// STEP 5: Check authorization using provided function
|
|
167
|
+
console.log("[Authorization] Checking authorization:");
|
|
168
|
+
console.log(" recoveredAddress:", recoveredAddress);
|
|
169
|
+
console.log(" recoveredAddress (lowercase):", recoveredAddress.toLowerCase());
|
|
170
|
+
const authorized = isAuthorized(recoveredAddress);
|
|
171
|
+
console.log(" match:", authorized ? "✅ YES" : "❌ NO");
|
|
172
|
+
if (!authorized) {
|
|
173
|
+
console.error(`[Authorization] Not authorized:`, `\n Recovered: ${recoveredAddress}`);
|
|
174
|
+
}
|
|
175
|
+
return authorized;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Verify position owner authorization for any amount-based position action
|
|
179
|
+
*
|
|
180
|
+
* AGNOSTIC BASE FUNCTION - verifies authorization without checking action string
|
|
181
|
+
* Specific action verification functions should validate action string before calling this.
|
|
182
|
+
*
|
|
183
|
+
* RESTORED PRODUCTION-GRADE QUANTUM VALIDATION:
|
|
184
|
+
* - STEP 1: Waits for safe quantum moment (avoids dead zone)
|
|
185
|
+
* - STEP 2: Validates timestamp is within current quantum window
|
|
186
|
+
* - STEP 3: Builds message hash from parameters
|
|
187
|
+
* - STEP 4: Recovers signer from signature
|
|
188
|
+
* - STEP 5: Verifies signer matches position owner
|
|
189
|
+
*
|
|
190
|
+
* Message contains: positionId, timestamp, chainId, amount, action
|
|
191
|
+
* NO callerAddress in message (recovered from signature via ecrecover)
|
|
192
|
+
*
|
|
193
|
+
* @param auth - Authorization parameters (positionId, timestamp, chainId, amount, action, signature, mode)
|
|
194
|
+
* @param positionOwner - Position owner address from contract
|
|
195
|
+
* @returns True if authorized
|
|
196
|
+
*/
|
|
197
|
+
static async verifyAmountPositionActionAuthorization(auth, positionOwner) {
|
|
198
|
+
// Build message hash function specific to mint action
|
|
199
|
+
// Caller has closure over auth parameters
|
|
200
|
+
const buildMessage = () => {
|
|
201
|
+
const actionHash = ethers.utils.keccak256(ethers.utils.toUtf8Bytes(auth.action));
|
|
202
|
+
const amountBigInt = typeof auth.amount === "string" ? BigInt(auth.amount) : auth.amount;
|
|
203
|
+
// Debug logging for message hash construction
|
|
204
|
+
console.log("[Authorization] Building message hash:");
|
|
205
|
+
console.log(" positionId:", auth.positionId);
|
|
206
|
+
console.log(" timestamp:", auth.timestamp);
|
|
207
|
+
console.log(" chainId:", auth.chainId);
|
|
208
|
+
console.log(" amount (string):", auth.amount);
|
|
209
|
+
console.log(" amount (BigInt):", amountBigInt.toString());
|
|
210
|
+
console.log(" action:", auth.action);
|
|
211
|
+
console.log(" actionHash:", actionHash);
|
|
212
|
+
const types = [
|
|
213
|
+
"bytes32", // positionId
|
|
214
|
+
"uint256", // timestamp
|
|
215
|
+
"uint256", // chainId
|
|
216
|
+
"uint256", // amount
|
|
217
|
+
"bytes32", // actionHash
|
|
218
|
+
];
|
|
219
|
+
const values = [
|
|
220
|
+
auth.positionId,
|
|
221
|
+
auth.timestamp,
|
|
222
|
+
auth.chainId,
|
|
223
|
+
amountBigInt.toString(),
|
|
224
|
+
actionHash,
|
|
225
|
+
];
|
|
226
|
+
const messageHash = ethers.utils.solidityKeccak256(types, values);
|
|
227
|
+
console.log(" messageHash (solidityKeccak256):", messageHash);
|
|
228
|
+
return messageHash;
|
|
229
|
+
};
|
|
230
|
+
// Authorization check function
|
|
231
|
+
// Caller has closure over positionOwner
|
|
232
|
+
const isAuthorized = (recovered) => {
|
|
233
|
+
return recovered.toLowerCase() === positionOwner.toLowerCase();
|
|
234
|
+
};
|
|
235
|
+
// Use agnostic verification
|
|
236
|
+
return this.verifyActionAuthorization(auth, buildMessage, isAuthorized);
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Verify position owner authorization for mintUCD action
|
|
240
|
+
*
|
|
241
|
+
* Validates action string is "mint-ucd" then delegates to base function.
|
|
242
|
+
*
|
|
243
|
+
* @param auth - Authorization parameters (positionId, timestamp, chainId, amount, action, signature, mode)
|
|
244
|
+
* @param positionOwner - Position owner address from contract
|
|
245
|
+
* @returns True if authorized
|
|
246
|
+
*/
|
|
247
|
+
static async verifyMintAuthorization(auth, positionOwner) {
|
|
248
|
+
// Validate action string matches expected value
|
|
249
|
+
if (auth.action !== "mint-ucd") {
|
|
250
|
+
console.error(`[Authorization] Invalid action for mint: expected "mint-ucd", got "${auth.action}"`);
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
253
|
+
// Delegate to base authorization function
|
|
254
|
+
return this.verifyAmountPositionActionAuthorization(auth, positionOwner);
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Verify position owner authorization for withdrawBTC action
|
|
258
|
+
*
|
|
259
|
+
* Validates action string is "withdraw-btc" and includes destinationAddress in message.
|
|
260
|
+
* Unlike mint/repay, withdrawal requires destination address to prevent unauthorized redirection.
|
|
261
|
+
*
|
|
262
|
+
* Message contains: positionId, timestamp, chainId, amount, destinationAddress, action
|
|
263
|
+
*
|
|
264
|
+
* @param auth - Authorization parameters (positionId, timestamp, chainId, amount, destinationAddress, action, signature, mode)
|
|
265
|
+
* @param positionOwner - Position owner address from contract
|
|
266
|
+
* @returns True if authorized
|
|
267
|
+
*/
|
|
268
|
+
static async verifyWithdrawAuthorization(auth, positionOwner) {
|
|
269
|
+
// Validate action string matches expected value
|
|
270
|
+
if (auth.action !== "withdraw-btc") {
|
|
271
|
+
console.error(`[Authorization] Invalid action for withdrawal: expected "withdraw-btc", got "${auth.action}"`);
|
|
272
|
+
return false;
|
|
273
|
+
}
|
|
274
|
+
// Build message hash function specific to withdraw action (includes destinationAddress)
|
|
275
|
+
const buildMessage = () => {
|
|
276
|
+
const actionHash = ethers.utils.keccak256(ethers.utils.toUtf8Bytes(auth.action));
|
|
277
|
+
const amountBigInt = typeof auth.amount === "string" ? BigInt(auth.amount) : auth.amount;
|
|
278
|
+
// Debug logging for message hash construction
|
|
279
|
+
console.log("[Authorization] Building withdrawal message hash:");
|
|
280
|
+
console.log(" positionId:", auth.positionId);
|
|
281
|
+
console.log(" timestamp:", auth.timestamp);
|
|
282
|
+
console.log(" chainId:", auth.chainId);
|
|
283
|
+
console.log(" amount (string):", auth.amount);
|
|
284
|
+
console.log(" amount (BigInt):", amountBigInt.toString());
|
|
285
|
+
console.log(" destinationAddress:", auth.destinationAddress);
|
|
286
|
+
console.log(" action:", auth.action);
|
|
287
|
+
console.log(" actionHash:", actionHash);
|
|
288
|
+
const types = [
|
|
289
|
+
"bytes32", // positionId
|
|
290
|
+
"uint256", // timestamp
|
|
291
|
+
"uint256", // chainId
|
|
292
|
+
"uint256", // amount (total deduction from vault)
|
|
293
|
+
"string", // destinationAddress (Bitcoin address)
|
|
294
|
+
"bytes32", // actionHash
|
|
295
|
+
];
|
|
296
|
+
const values = [
|
|
297
|
+
auth.positionId,
|
|
298
|
+
auth.timestamp,
|
|
299
|
+
auth.chainId,
|
|
300
|
+
amountBigInt.toString(),
|
|
301
|
+
auth.destinationAddress,
|
|
302
|
+
actionHash,
|
|
303
|
+
];
|
|
304
|
+
const messageHash = ethers.utils.solidityKeccak256(types, values);
|
|
305
|
+
console.log(" messageHash (solidityKeccak256):", messageHash);
|
|
306
|
+
return messageHash;
|
|
307
|
+
};
|
|
308
|
+
// Authorization check function
|
|
309
|
+
const isAuthorized = (recovered) => {
|
|
310
|
+
return recovered.toLowerCase() === positionOwner.toLowerCase();
|
|
311
|
+
};
|
|
312
|
+
// Use agnostic verification
|
|
313
|
+
return this.verifyActionAuthorization(auth, buildMessage, isAuthorized);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
exports.AuthorizationModule = AuthorizationModule;
|
|
317
|
+
//# sourceMappingURL=authorization.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorization.module.js","sourceRoot":"","sources":["../../../src/modules/authorization.module.ts"],"names":[],"mappings":";;;AAAA,+DAG+B;AAO/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH;;;;GAIG;AACH,MAAa,mBAAmB;IAC9B;;;;;;;;;;;;;;;OAeG;IACH,MAAM,CAAC,gDAAgD,CACrD,IAAS;QAET,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;YACtC,MAAM,IAAI,KAAK,CACb,yDAAyD,CAC1D,CAAC;QACJ,CAAC;QAED,oCAAoC;QACpC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;QACjD,CAAC;QAED,IAAI,OAAO,IAAI,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;YACrC,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;QACnD,CAAC;QAED,IAAI,OAAO,IAAI,CAAC,SAAS,KAAK,QAAQ,EAAE,CAAC;YACvC,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;QACrD,CAAC;QAED,IAAI,OAAO,IAAI,CAAC,MA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;QAC5B,OAAO,IAAI,CAAC,yBAAyB,CAAC,IAAI,EAAE,YAAY,EAAE,YAAY,CAAC,CAAC;IAC1E,CAAC;CACF;AA1YD,kDA0YC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bitcoin Data Provider Module
|
|
3
|
+
*
|
|
4
|
+
* Provides Bitcoin network data with support for future consensus mechanisms.
|
|
5
|
+
* Current implementation: Single provider with fallback support
|
|
6
|
+
* Future implementation: 2-of-3 provider consensus
|
|
7
|
+
*
|
|
8
|
+
* This module centralizes all Bitcoin data queries to maintain a consistent
|
|
9
|
+
* interface that won't break when upgrading to multi-provider consensus.
|
|
10
|
+
*/
|
|
11
|
+
import { BitcoinDataProviderConfig, UTXO, UTXOSet } from "../interfaces/chunks/vault-balance.i";
|
|
12
|
+
import { IBitcoinDataProvider } from "../interfaces/chunks/bitcoin-data-provider.i";
|
|
13
|
+
/**
|
|
14
|
+
* Bitcoin Data Provider
|
|
15
|
+
*
|
|
16
|
+
* Fetches UTXO data from Bitcoin network.
|
|
17
|
+
* Interface designed to remain stable when adding multi-provider consensus.
|
|
18
|
+
*/
|
|
19
|
+
export declare class BitcoinDataProvider implements IBitcoinDataProvider {
|
|
20
|
+
private config;
|
|
21
|
+
private timeout;
|
|
22
|
+
constructor(config: BitcoinDataProviderConfig);
|
|
23
|
+
/**
|
|
24
|
+
* Fetch all UTXOs for a Bitcoin address
|
|
25
|
+
*
|
|
26
|
+
* @param address - Bitcoin address (legacy, segwit, or taproot)
|
|
27
|
+
* @returns Array of UTXOs
|
|
28
|
+
*/
|
|
29
|
+
getUTXOs(address: string): Promise<UTXO[]>;
|
|
30
|
+
/**
|
|
31
|
+
* Strip network prefix from Bitcoin address
|
|
32
|
+
*
|
|
33
|
+
* Addresses may be stored with network prefix (e.g., "REGTEST_address")
|
|
34
|
+
* but APIs expect clean addresses without prefix.
|
|
35
|
+
*
|
|
36
|
+
* @param address - Address with optional prefix
|
|
37
|
+
* @returns Clean address without prefix
|
|
38
|
+
*/
|
|
39
|
+
private stripNetworkPrefix;
|
|
40
|
+
/**
|
|
41
|
+
* Fetch UTXOs using Bitcoin RPC (for regtest/testing)
|
|
42
|
+
*/
|
|
43
|
+
private fetchUTXOsFromRPC;
|
|
44
|
+
/**
|
|
45
|
+
* Parse Esplora/Blockstream/Mempool.space UTXO response
|
|
46
|
+
*
|
|
47
|
+
* Expected format: Array of {txid, vout, value, confirmations}
|
|
48
|
+
*
|
|
49
|
+
* @param data Raw response from provider API
|
|
50
|
+
* @returns Array of normalized UTXOs
|
|
51
|
+
*/
|
|
52
|
+
private parseBlockstreamUTXOs;
|
|
53
|
+
/**
|
|
54
|
+
* Internal method to fetch UTXOs from a specific provider
|
|
55
|
+
*
|
|
56
|
+
* Supports standard Esplora API format:
|
|
57
|
+
* - Standard format: {providerUrl}/address/{address}/utxos
|
|
58
|
+
* - providerUrl must include full base path (e.g., "http://localhost:3002/api/esplora")
|
|
59
|
+
*/
|
|
60
|
+
private fetchUTXOsFromProvider;
|
|
61
|
+
/**
|
|
62
|
+
* Get complete UTXO set with balance summary
|
|
63
|
+
*
|
|
64
|
+
* This is the SINGLE method that vault-balance module should call.
|
|
65
|
+
* Returns everything needed to know about Bitcoin network state for an address.
|
|
66
|
+
*
|
|
67
|
+
* @param address - Bitcoin address
|
|
68
|
+
* @param minConfirmations - Minimum confirmations for "confirmed" status (REQUIRED - caller must specify)
|
|
69
|
+
* @returns Complete UTXO set with balance breakdown
|
|
70
|
+
*/
|
|
71
|
+
getUTXOSet(address: string, minConfirmations: number): Promise<UTXOSet>;
|
|
72
|
+
/**
|
|
73
|
+
* Get transaction with confirmation count
|
|
74
|
+
*
|
|
75
|
+
* Checks if transaction exists on Bitcoin network and returns confirmation count.
|
|
76
|
+
* Used to validate authorized spends have been broadcasted.
|
|
77
|
+
*
|
|
78
|
+
* @param txid - Transaction ID to check
|
|
79
|
+
* @returns Transaction with confirmation count, or null if not found
|
|
80
|
+
*/
|
|
81
|
+
getTransaction(txid: string): Promise<{
|
|
82
|
+
txid: string;
|
|
83
|
+
confirmations: number;
|
|
84
|
+
} | null>;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Factory function for creating Bitcoin Data Provider
|
|
88
|
+
* Useful for dependency injection and testing
|
|
89
|
+
*/
|
|
90
|
+
export declare function createBitcoinDataProvider(config: BitcoinDataProviderConfig): BitcoinDataProvider;
|
|
91
|
+
//# sourceMappingURL=bitcoin-data-provider.module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bitcoin-data-provider.module.d.ts","sourceRoot":"","sources":["../../../src/modules/bitcoin-data-provider.module.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EACL,yBAAyB,EACzB,IAAI,EACJ,OAAO,EACR,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,8CAA8C,CAAC;AAEpF;;;;;GAKG;AACH,qBAAa,mBAAoB,YAAW,oBAAoB;IAC9D,OAAO,CAAC,MAAM,CAA4B;IAC1C,OAAO,CAAC,OAAO,CAAS;gBAEZ,MAAM,EAAE,yBAAyB;IAK7C;;;;;OAKG;IACG,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAqDhD;;;;;;;;OAQG;IACH,OAAO,CAAC,kBAAkB;IAK1B;;OAEG;YACW,iBAAiB;IAqB/B;;;;;;;OAOG;IACH,OAAO,CAAC,qBAAqB;IAgB7B;;;;;;OAMG;YACW,sBAAsB;IAkDpC;;;;;;;;;OASG;IACG,UAAU,CACd,OAAO,EAAE,MAAM,EACf,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAAC,OAAO,CAAC;IAkBnB;;;;;;;;OAQG;IACG,cAAc,CAClB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;CA+E3D;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,yBAAyB,GAChC,mBAAmB,CAErB"}
|