@nucypher/taco 0.1.0-rc.6 → 0.1.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/README.md +63 -1
- package/dist/cjs/conditions/base/contract.d.ts +17 -12
- package/dist/cjs/conditions/base/contract.js +17 -3
- package/dist/cjs/conditions/base/contract.js.map +1 -1
- package/dist/cjs/conditions/base/index.d.ts +3 -21
- package/dist/cjs/conditions/base/index.js +27 -37
- package/dist/cjs/conditions/base/index.js.map +1 -1
- package/dist/cjs/conditions/base/rpc.d.ts +16 -11
- package/dist/cjs/conditions/base/rpc.js +16 -6
- package/dist/cjs/conditions/base/rpc.js.map +1 -1
- package/dist/cjs/conditions/base/time.d.ts +10 -5
- package/dist/cjs/conditions/base/time.js +11 -1
- package/dist/cjs/conditions/base/time.js.map +1 -1
- package/dist/cjs/conditions/compound-condition.d.ts +10 -0
- package/dist/cjs/conditions/compound-condition.js +52 -5
- package/dist/cjs/conditions/compound-condition.js.map +1 -1
- package/dist/cjs/conditions/condition-expr.js +2 -2
- package/dist/cjs/conditions/condition-expr.js.map +1 -1
- package/dist/cjs/conditions/condition-factory.d.ts +4 -0
- package/dist/cjs/conditions/condition-factory.js +26 -0
- package/dist/cjs/conditions/condition-factory.js.map +1 -0
- package/dist/cjs/conditions/condition.d.ts +0 -1
- package/dist/cjs/conditions/condition.js +0 -22
- package/dist/cjs/conditions/condition.js.map +1 -1
- package/dist/cjs/conditions/const.d.ts +3 -0
- package/dist/cjs/conditions/const.js +6 -2
- package/dist/cjs/conditions/const.js.map +1 -1
- package/dist/cjs/conditions/context/context.d.ts +0 -2
- package/dist/cjs/conditions/context/context.js +7 -10
- package/dist/cjs/conditions/context/context.js.map +1 -1
- package/dist/cjs/conditions/index.d.ts +5 -6
- package/dist/cjs/conditions/index.js +7 -14
- package/dist/cjs/conditions/index.js.map +1 -1
- package/dist/cjs/conditions/predefined/erc721.d.ts +2 -2
- package/dist/cjs/conditions/predefined/erc721.js +5 -11
- package/dist/cjs/conditions/predefined/erc721.js.map +1 -1
- package/dist/cjs/conditions/predefined/index.d.ts +1 -1
- package/dist/cjs/conditions/predefined/index.js +25 -4
- package/dist/cjs/conditions/predefined/index.js.map +1 -1
- package/dist/cjs/conditions/{base/shared.d.ts → shared.d.ts} +7 -3
- package/dist/cjs/conditions/shared.js +31 -0
- package/dist/cjs/conditions/shared.js.map +1 -0
- package/dist/cjs/dkg.d.ts +1 -1
- package/dist/cjs/dkg.js +6 -4
- package/dist/cjs/dkg.js.map +1 -1
- package/dist/cjs/taco.d.ts +70 -1
- package/dist/cjs/taco.js +72 -4
- package/dist/cjs/taco.js.map +1 -1
- package/dist/cjs/tdec.d.ts +2 -1
- package/dist/cjs/tdec.js +6 -4
- package/dist/cjs/tdec.js.map +1 -1
- package/dist/es/conditions/base/contract.d.ts +17 -12
- package/dist/es/conditions/base/contract.js +15 -2
- package/dist/es/conditions/base/contract.js.map +1 -1
- package/dist/es/conditions/base/index.d.ts +3 -21
- package/dist/es/conditions/base/index.js +3 -28
- package/dist/es/conditions/base/index.js.map +1 -1
- package/dist/es/conditions/base/rpc.d.ts +16 -11
- package/dist/es/conditions/base/rpc.js +14 -5
- package/dist/es/conditions/base/rpc.js.map +1 -1
- package/dist/es/conditions/base/time.d.ts +10 -5
- package/dist/es/conditions/base/time.js +9 -0
- package/dist/es/conditions/base/time.js.map +1 -1
- package/dist/es/conditions/compound-condition.d.ts +10 -0
- package/dist/es/conditions/compound-condition.js +50 -4
- package/dist/es/conditions/compound-condition.js.map +1 -1
- package/dist/es/conditions/condition-expr.js +2 -2
- package/dist/es/conditions/condition-expr.js.map +1 -1
- package/dist/es/conditions/condition-factory.d.ts +4 -0
- package/dist/es/conditions/condition-factory.js +22 -0
- package/dist/es/conditions/condition-factory.js.map +1 -0
- package/dist/es/conditions/condition.d.ts +0 -1
- package/dist/es/conditions/condition.js +0 -22
- package/dist/es/conditions/condition.js.map +1 -1
- package/dist/es/conditions/const.d.ts +3 -0
- package/dist/es/conditions/const.js +5 -1
- package/dist/es/conditions/const.js.map +1 -1
- package/dist/es/conditions/context/context.d.ts +0 -2
- package/dist/es/conditions/context/context.js +3 -6
- package/dist/es/conditions/context/context.js.map +1 -1
- package/dist/es/conditions/index.d.ts +5 -6
- package/dist/es/conditions/index.js +5 -6
- package/dist/es/conditions/index.js.map +1 -1
- package/dist/es/conditions/predefined/erc721.d.ts +2 -2
- package/dist/es/conditions/predefined/erc721.js +1 -7
- package/dist/es/conditions/predefined/erc721.js.map +1 -1
- package/dist/es/conditions/predefined/index.d.ts +1 -1
- package/dist/es/conditions/predefined/index.js +1 -1
- package/dist/es/conditions/predefined/index.js.map +1 -1
- package/dist/es/conditions/{base/shared.d.ts → shared.d.ts} +7 -3
- package/dist/es/conditions/shared.js +28 -0
- package/dist/es/conditions/shared.js.map +1 -0
- package/dist/es/dkg.d.ts +1 -1
- package/dist/es/dkg.js +6 -4
- package/dist/es/dkg.js.map +1 -1
- package/dist/es/taco.d.ts +70 -1
- package/dist/es/taco.js +71 -3
- package/dist/es/taco.js.map +1 -1
- package/dist/es/tdec.d.ts +2 -1
- package/dist/es/tdec.js +5 -3
- package/dist/es/tdec.js.map +1 -1
- package/dist/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/tsconfig.es.tsbuildinfo +1 -1
- package/package.json +8 -7
- package/dist/cjs/conditions/base/shared.js +0 -17
- package/dist/cjs/conditions/base/shared.js.map +0 -1
- package/dist/es/conditions/base/shared.js +0 -14
- package/dist/es/conditions/base/shared.js.map +0 -1
package/dist/cjs/taco.js
CHANGED
|
@@ -4,9 +4,29 @@ exports.registerEncrypters = exports.isAuthorized = exports.decrypt = exports.en
|
|
|
4
4
|
const nucypher_core_1 = require("@nucypher/nucypher-core");
|
|
5
5
|
const shared_1 = require("@nucypher/shared");
|
|
6
6
|
const utils_1 = require("ethers/lib/utils");
|
|
7
|
-
const
|
|
7
|
+
const condition_expr_1 = require("./conditions/condition-expr");
|
|
8
8
|
const dkg_1 = require("./dkg");
|
|
9
9
|
const tdec_1 = require("./tdec");
|
|
10
|
+
/**
|
|
11
|
+
* Encrypts a message under given conditions using a public key from an active DKG ritual.
|
|
12
|
+
*
|
|
13
|
+
* @export
|
|
14
|
+
* @param {ethers.providers.Provider} provider - Instance of ethers provider which is used to interact with
|
|
15
|
+
* your selected network.
|
|
16
|
+
* @param {Domain} domain - Represents the logical network in which the encryption will be performed.
|
|
17
|
+
* Must match the `ritualId`.
|
|
18
|
+
* @param {Uint8Array | string} message - The message to be encrypted.
|
|
19
|
+
* @param {Condition} condition - Condition under which the message will be encrypted. Those conditions must be
|
|
20
|
+
* satisfied in order to decrypt the message.
|
|
21
|
+
* @param {number} ritualId - The ID of the DKG Ritual to be used for encryption. The message will be encrypted
|
|
22
|
+
* under the public key of this ritual.
|
|
23
|
+
* @param {ethers.Signer} authSigner - The signer that will be used to sign the encrypter authorization.
|
|
24
|
+
*
|
|
25
|
+
* @returns {Promise<ThresholdMessageKit>} Returns Promise that resolves with an instance of ThresholdMessageKit.
|
|
26
|
+
* It represents the encrypted message.
|
|
27
|
+
*
|
|
28
|
+
* @throws {Error} If the active DKG Ritual cannot be retrieved an error is thrown.
|
|
29
|
+
*/
|
|
10
30
|
const encrypt = async (provider, domain, message, condition, ritualId, authSigner) => {
|
|
11
31
|
// TODO(#264): Enable ritual initialization
|
|
12
32
|
// if (ritualId === undefined) {
|
|
@@ -20,15 +40,30 @@ const encrypt = async (provider, domain, message, condition, ritualId, authSigne
|
|
|
20
40
|
// // Given that we just initialized the ritual, this should never happen
|
|
21
41
|
// throw new Error('Ritual ID is undefined');
|
|
22
42
|
// }
|
|
23
|
-
const dkgRitual = await dkg_1.DkgClient.
|
|
43
|
+
const dkgRitual = await dkg_1.DkgClient.getActiveRitual(provider, domain, ritualId);
|
|
24
44
|
return await (0, exports.encryptWithPublicKey)(message, condition, dkgRitual.dkgPublicKey, authSigner);
|
|
25
45
|
};
|
|
26
46
|
exports.encrypt = encrypt;
|
|
47
|
+
/**
|
|
48
|
+
* Encrypts a message with the given DKG public key under a specified condition.
|
|
49
|
+
*
|
|
50
|
+
* @export
|
|
51
|
+
* @param {Uint8Array | string} message - The message to be encrypted.
|
|
52
|
+
* @param {Condition} condition - Condition under which the message will be encrypted. Those conditions must be
|
|
53
|
+
* satisfied in order to decrypt the message.
|
|
54
|
+
* @param {DkgPublicKey} dkgPublicKey - The public key of an active DKG Ritual to be used for encryption
|
|
55
|
+
* @param {ethers.Signer} authSigner - The signer that will be used to sign the encrypter authorization.
|
|
56
|
+
*
|
|
57
|
+
* @returns {Promise<ThresholdMessageKit>} Returns Promise that resolves with an instance of ThresholdMessageKit.
|
|
58
|
+
* It represents the encrypted message.
|
|
59
|
+
*
|
|
60
|
+
* @throws {Error} If the encryption process throws an error, an error is thrown.
|
|
61
|
+
*/
|
|
27
62
|
const encryptWithPublicKey = async (message, condition, dkgPublicKey, authSigner) => {
|
|
28
63
|
if (typeof message === 'string') {
|
|
29
64
|
message = (0, shared_1.toBytes)(message);
|
|
30
65
|
}
|
|
31
|
-
const conditionExpr = new
|
|
66
|
+
const conditionExpr = new condition_expr_1.ConditionExpression(condition);
|
|
32
67
|
const [ciphertext, authenticatedData] = (0, nucypher_core_1.encryptForDkg)(message, dkgPublicKey, conditionExpr.toWASMConditions());
|
|
33
68
|
const headerHash = (0, utils_1.keccak256)(ciphertext.header.toBytes());
|
|
34
69
|
const authorization = await authSigner.signMessage((0, shared_1.fromHexString)(headerHash));
|
|
@@ -36,15 +71,48 @@ const encryptWithPublicKey = async (message, condition, dkgPublicKey, authSigner
|
|
|
36
71
|
return new nucypher_core_1.ThresholdMessageKit(ciphertext, acp);
|
|
37
72
|
};
|
|
38
73
|
exports.encryptWithPublicKey = encryptWithPublicKey;
|
|
74
|
+
/**
|
|
75
|
+
* Decrypts an encrypted message.
|
|
76
|
+
*
|
|
77
|
+
* @export
|
|
78
|
+
* @param {ethers.providers.Provider} provider - Instance of ethers provider which is used to interact with
|
|
79
|
+
* your selected network.
|
|
80
|
+
* @param {Domain} domain - Represents the logical network in which the decryption will be performed.
|
|
81
|
+
* Must match the `ritualId`.
|
|
82
|
+
* @param {ThresholdMessageKit} messageKit - The kit containing the message to be decrypted
|
|
83
|
+
* @param {string} [porterUri] - The URI for the Porter service. If not provided, a value will be obtained
|
|
84
|
+
* from the Domain
|
|
85
|
+
* @param {ethers.Signer} [signer] - An optional signer for the decryption
|
|
86
|
+
* @param {Record<string, CustomContextParam>} [customParameters] - Optional custom parameters that may be required
|
|
87
|
+
* depending on the condition used
|
|
88
|
+
*
|
|
89
|
+
* @returns {Promise<Uint8Array>} Returns Promise that resolves with a decrypted message
|
|
90
|
+
*
|
|
91
|
+
* @throws {Error} If the active DKG Ritual cannot be retrieved or decryption process throws an error,
|
|
92
|
+
* an error is thrown.
|
|
93
|
+
*/
|
|
39
94
|
const decrypt = async (provider, domain, messageKit, porterUri, signer, customParameters) => {
|
|
40
95
|
if (!porterUri) {
|
|
41
96
|
porterUri = (0, shared_1.getPorterUri)(domain);
|
|
42
97
|
}
|
|
43
98
|
const ritualId = await shared_1.DkgCoordinatorAgent.getRitualIdFromPublicKey(provider, domain, messageKit.acp.publicKey);
|
|
44
|
-
const ritual = await dkg_1.DkgClient.
|
|
99
|
+
const ritual = await dkg_1.DkgClient.getActiveRitual(provider, domain, ritualId);
|
|
45
100
|
return (0, tdec_1.retrieveAndDecrypt)(provider, domain, porterUri, messageKit, ritualId, ritual.threshold, signer, customParameters);
|
|
46
101
|
};
|
|
47
102
|
exports.decrypt = decrypt;
|
|
103
|
+
/**
|
|
104
|
+
* Checks if the encryption from the provided messageKit is authorized for the specified ritual.
|
|
105
|
+
*
|
|
106
|
+
* @export
|
|
107
|
+
* @param {ethers.providers.Provider} provider - Instance of ethers provider which is used to interact with
|
|
108
|
+
* your selected network.
|
|
109
|
+
* @param {Domain} domain - The domain which was used to encrypt the network. Must match the `ritualId`.
|
|
110
|
+
* @param {ThresholdMessageKit} messageKit - The encrypted message kit to be checked.
|
|
111
|
+
* @param {number} ritualId - The ID of the DKG Ritual under which the messageKit was supposedly encrypted.
|
|
112
|
+
*
|
|
113
|
+
* @returns {Promise<boolean>} Returns a Promise that resolves with the authorization status.
|
|
114
|
+
* True if authorized, false otherwise
|
|
115
|
+
*/
|
|
48
116
|
const isAuthorized = async (provider, domain, messageKit, ritualId) => shared_1.DkgCoordinatorAgent.isEncryptionAuthorized(provider, domain, ritualId, messageKit);
|
|
49
117
|
exports.isAuthorized = isAuthorized;
|
|
50
118
|
const registerEncrypters = async (provider, signer, domain, ritualId, encrypters) => {
|
package/dist/cjs/taco.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"taco.js","sourceRoot":"","sources":["../../src/taco.ts"],"names":[],"mappings":";;;AAAA,2DAKiC;AACjC,6CAQ0B;AAE1B,4CAA6C;
|
|
1
|
+
{"version":3,"file":"taco.js","sourceRoot":"","sources":["../../src/taco.ts"],"names":[],"mappings":";;;AAAA,2DAKiC;AACjC,6CAQ0B;AAE1B,4CAA6C;AAG7C,gEAAkE;AAElE,+BAAkC;AAClC,iCAA4C;AAE5C;;;;;;;;;;;;;;;;;;;GAmBG;AACI,MAAM,OAAO,GAAG,KAAK,EAC1B,QAAmC,EACnC,MAAc,EACd,OAA4B,EAC5B,SAAoB,EACpB,QAAgB,EAChB,UAAyB,EACK,EAAE;IAChC,2CAA2C;IAC3C,gCAAgC;IAChC,iDAAiD;IACjD,gBAAgB;IAChB,mCAAmC;IACnC,WAAW;IACX,OAAO;IACP,IAAI;IACJ,gCAAgC;IAChC,2EAA2E;IAC3E,+CAA+C;IAC/C,IAAI;IACJ,MAAM,SAAS,GAAG,MAAM,eAAS,CAAC,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;IAE9E,OAAO,MAAM,IAAA,4BAAoB,EAC/B,OAAO,EACP,SAAS,EACT,SAAS,CAAC,YAAY,EACtB,UAAU,CACX,CAAC;AACJ,CAAC,CAAC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IACF,MAAM,MAAM,GAAG,MAAM,eAAS,CAAC,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;IAC3E,OAAO,IAAA,yBAAkB,EACvB,QAAQ,EACR,MAAM,EACN,SAAS,EACT,UAAU,EACV,QAAQ,EACR,MAAM,CAAC,SAAS,EAChB,MAAM,EACN,gBAAgB,CACjB,CAAC;AACJ,CAAC,CAAC;AA5BW,QAAA,OAAO,WA4BlB;AAEF;;;;;;;;;;;;GAYG;AACI,MAAM,YAAY,GAAG,KAAK,EAC/B,QAAmC,EACnC,MAAc,EACd,UAA+B,EAC/B,QAAgB,EAChB,EAAE,CACF,4BAAmB,CAAC,sBAAsB,CACxC,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,UAAU,CACX,CAAC;AAXS,QAAA,YAAY,gBAWrB;AAEG,MAAM,kBAAkB,GAAG,KAAK,EACrC,QAAmC,EACnC,MAAqB,EACrB,MAAc,EACd,QAAgB,EAChB,UAA6B,EACd,EAAE;IACjB,MAAM,6BAAoB,CAAC,kBAAkB,CAC3C,QAAQ,EACR,MAAM,EACN,MAAM,EACN,QAAQ,EACR,UAAU,CACX,CAAC;AACJ,CAAC,CAAC;AAdW,QAAA,kBAAkB,sBAc7B"}
|
package/dist/cjs/tdec.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { DkgPublicKey, ThresholdMessageKit } from '@nucypher/nucypher-core';
|
|
2
2
|
import { Domain } from '@nucypher/shared';
|
|
3
3
|
import { ethers } from 'ethers';
|
|
4
|
-
import { ConditionExpression
|
|
4
|
+
import { ConditionExpression } from './conditions/condition-expr';
|
|
5
|
+
import { CustomContextParam } from './conditions/context';
|
|
5
6
|
export declare const encryptMessage: (plaintext: Uint8Array | string, encryptingKey: DkgPublicKey, conditions: ConditionExpression, authSigner: ethers.Signer) => Promise<ThresholdMessageKit>;
|
|
6
7
|
export declare const retrieveAndDecrypt: (provider: ethers.providers.Provider, domain: Domain, porterUri: string, thresholdMessageKit: ThresholdMessageKit, ritualId: number, threshold: number, signer?: ethers.Signer, customParameters?: Record<string, CustomContextParam>) => Promise<Uint8Array>;
|
package/dist/cjs/tdec.js
CHANGED
|
@@ -4,7 +4,9 @@ exports.retrieveAndDecrypt = exports.encryptMessage = void 0;
|
|
|
4
4
|
const nucypher_core_1 = require("@nucypher/nucypher-core");
|
|
5
5
|
const shared_1 = require("@nucypher/shared");
|
|
6
6
|
const utils_1 = require("ethers/lib/utils");
|
|
7
|
-
const
|
|
7
|
+
const context_1 = require("./conditions/context");
|
|
8
|
+
const ERR_DECRYPTION_FAILED = (errors) => `Threshold of responses not met; TACo decryption failed with errors: ${JSON.stringify(errors)}`;
|
|
9
|
+
const ERR_RITUAL_ID_MISMATCH = (expectedRitualId, ritualIds) => `Ritual id mismatch. Expected ${expectedRitualId}, got ${ritualIds}`;
|
|
8
10
|
const encryptMessage = async (plaintext, encryptingKey, conditions, authSigner) => {
|
|
9
11
|
const [ciphertext, authenticatedData] = (0, nucypher_core_1.encryptForDkg)(plaintext instanceof Uint8Array ? plaintext : (0, shared_1.toBytes)(plaintext), encryptingKey, conditions.toWASMConditions());
|
|
10
12
|
const headerHash = (0, utils_1.keccak256)(ciphertext.header.toBytes());
|
|
@@ -23,12 +25,12 @@ exports.retrieveAndDecrypt = retrieveAndDecrypt;
|
|
|
23
25
|
// Retrieve decryption shares
|
|
24
26
|
const retrieve = async (provider, domain, porterUri, thresholdMessageKit, ritualId, threshold, signer, customParameters) => {
|
|
25
27
|
const dkgParticipants = await shared_1.DkgCoordinatorAgent.getParticipants(provider, domain, ritualId);
|
|
26
|
-
const wasmContext = await
|
|
28
|
+
const wasmContext = await context_1.ConditionContext.fromConditions(provider, thresholdMessageKit.acp.conditions, signer, customParameters).toWASMContext();
|
|
27
29
|
const { sharedSecrets, encryptedRequests } = await makeDecryptionRequests(ritualId, wasmContext, dkgParticipants, thresholdMessageKit);
|
|
28
30
|
const porter = new shared_1.PorterClient(porterUri);
|
|
29
31
|
const { encryptedResponses, errors } = await porter.tacoDecrypt(encryptedRequests, threshold);
|
|
30
32
|
if (Object.keys(encryptedResponses).length < threshold) {
|
|
31
|
-
throw new Error(
|
|
33
|
+
throw new Error(ERR_DECRYPTION_FAILED(errors));
|
|
32
34
|
}
|
|
33
35
|
return makeDecryptionShares(encryptedResponses, sharedSecrets, ritualId);
|
|
34
36
|
};
|
|
@@ -36,7 +38,7 @@ const makeDecryptionShares = (encryptedResponses, sessionSharedSecret, expectedR
|
|
|
36
38
|
const decryptedResponses = Object.entries(encryptedResponses).map(([ursula, response]) => response.decrypt(sessionSharedSecret[ursula]));
|
|
37
39
|
const ritualIds = decryptedResponses.map(({ ritualId }) => ritualId);
|
|
38
40
|
if (ritualIds.some((ritualId) => ritualId !== expectedRitualId)) {
|
|
39
|
-
throw new Error(
|
|
41
|
+
throw new Error(ERR_RITUAL_ID_MISMATCH(expectedRitualId, ritualIds));
|
|
40
42
|
}
|
|
41
43
|
return decryptedResponses.map(({ decryptionShare }) => nucypher_core_1.DecryptionShareSimple.fromBytes(decryptionShare));
|
|
42
44
|
};
|
package/dist/cjs/tdec.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tdec.js","sourceRoot":"","sources":["../../src/tdec.ts"],"names":[],"mappings":";;;AAAA,2DAciC;AACjC,6CAM0B;AAE1B,4CAAuD;
|
|
1
|
+
{"version":3,"file":"tdec.js","sourceRoot":"","sources":["../../src/tdec.ts"],"names":[],"mappings":";;;AAAA,2DAciC;AACjC,6CAM0B;AAE1B,4CAAuD;AAGvD,kDAA4E;AAE5E,MAAM,qBAAqB,GAAG,CAAC,MAAe,EAAE,EAAE,CAChD,uEAAuE,IAAI,CAAC,SAAS,CACnF,MAAM,CACP,EAAE,CAAC;AACN,MAAM,sBAAsB,GAAG,CAC7B,gBAAwB,EACxB,SAAmB,EACnB,EAAE,CAAC,gCAAgC,gBAAgB,SAAS,SAAS,EAAE,CAAC;AAEnE,MAAM,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iB,CAAC,OAAO,CAChD,mBAAmB,EACnB,mBAAmB,CAAC,SAAS,EAAE,CAChC,CAAC;QACF,OAAO,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC;IACtC,CAAC,CAAC,CACH,CAAC;IAEJ,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,CAAC;AAC9C,CAAC,CAAC;AAEF,0DAA0D;AAC1D,MAAM,cAAc,GAAG,GAAG,EAAE,CAAC,mCAAmB,CAAC,MAAM,EAAE,CAAC"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { Condition } from '../condition';
|
|
3
|
+
import { OmitConditionType } from '../shared';
|
|
2
4
|
declare const functionAbiSchema: z.ZodEffects<z.ZodEffects<z.ZodObject<{
|
|
3
5
|
name: z.ZodString;
|
|
4
6
|
type: z.ZodLiteral<"function">;
|
|
@@ -145,15 +147,15 @@ export declare const contractConditionSchema: z.ZodEffects<z.ZodObject<{
|
|
|
145
147
|
returnValueTest: z.ZodObject<{
|
|
146
148
|
index: z.ZodOptional<z.ZodNumber>;
|
|
147
149
|
comparator: z.ZodEnum<["==", ">", "<", ">=", "<=", "!="]>;
|
|
148
|
-
value: z.
|
|
150
|
+
value: z.ZodType<any, z.ZodTypeDef, any>;
|
|
149
151
|
}, "strip", z.ZodTypeAny, {
|
|
150
152
|
comparator: "==" | ">" | "<" | ">=" | "<=" | "!=";
|
|
151
153
|
index?: number | undefined;
|
|
152
|
-
value?:
|
|
154
|
+
value?: any;
|
|
153
155
|
}, {
|
|
154
156
|
comparator: "==" | ">" | "<" | ">=" | "<=" | "!=";
|
|
155
157
|
index?: number | undefined;
|
|
156
|
-
value?:
|
|
158
|
+
value?: any;
|
|
157
159
|
}>;
|
|
158
160
|
conditionType: z.ZodDefault<z.ZodLiteral<"contract">>;
|
|
159
161
|
contractAddress: z.ZodString;
|
|
@@ -298,15 +300,15 @@ export declare const contractConditionSchema: z.ZodEffects<z.ZodObject<{
|
|
|
298
300
|
}[]];
|
|
299
301
|
stateMutability: "view" | "pure";
|
|
300
302
|
}>>;
|
|
301
|
-
parameters: z.ZodArray<z.
|
|
303
|
+
parameters: z.ZodArray<z.ZodType<any, z.ZodTypeDef, any>, "many">;
|
|
302
304
|
}, "strip", z.ZodTypeAny, {
|
|
303
305
|
conditionType: "contract";
|
|
304
306
|
method: string;
|
|
305
|
-
parameters:
|
|
307
|
+
parameters: any[];
|
|
306
308
|
returnValueTest: {
|
|
307
309
|
comparator: "==" | ">" | "<" | ">=" | "<=" | "!=";
|
|
308
310
|
index?: number | undefined;
|
|
309
|
-
value?:
|
|
311
|
+
value?: any;
|
|
310
312
|
};
|
|
311
313
|
contractAddress: string;
|
|
312
314
|
chain?: z.Primitive;
|
|
@@ -332,11 +334,11 @@ export declare const contractConditionSchema: z.ZodEffects<z.ZodObject<{
|
|
|
332
334
|
} | undefined;
|
|
333
335
|
}, {
|
|
334
336
|
method: string;
|
|
335
|
-
parameters:
|
|
337
|
+
parameters: any[];
|
|
336
338
|
returnValueTest: {
|
|
337
339
|
comparator: "==" | ">" | "<" | ">=" | "<=" | "!=";
|
|
338
340
|
index?: number | undefined;
|
|
339
|
-
value?:
|
|
341
|
+
value?: any;
|
|
340
342
|
};
|
|
341
343
|
contractAddress: string;
|
|
342
344
|
chain?: z.Primitive;
|
|
@@ -364,11 +366,11 @@ export declare const contractConditionSchema: z.ZodEffects<z.ZodObject<{
|
|
|
364
366
|
}>, {
|
|
365
367
|
conditionType: "contract";
|
|
366
368
|
method: string;
|
|
367
|
-
parameters:
|
|
369
|
+
parameters: any[];
|
|
368
370
|
returnValueTest: {
|
|
369
371
|
comparator: "==" | ">" | "<" | ">=" | "<=" | "!=";
|
|
370
372
|
index?: number | undefined;
|
|
371
|
-
value?:
|
|
373
|
+
value?: any;
|
|
372
374
|
};
|
|
373
375
|
contractAddress: string;
|
|
374
376
|
chain?: z.Primitive;
|
|
@@ -394,11 +396,11 @@ export declare const contractConditionSchema: z.ZodEffects<z.ZodObject<{
|
|
|
394
396
|
} | undefined;
|
|
395
397
|
}, {
|
|
396
398
|
method: string;
|
|
397
|
-
parameters:
|
|
399
|
+
parameters: any[];
|
|
398
400
|
returnValueTest: {
|
|
399
401
|
comparator: "==" | ">" | "<" | ">=" | "<=" | "!=";
|
|
400
402
|
index?: number | undefined;
|
|
401
|
-
value?:
|
|
403
|
+
value?: any;
|
|
402
404
|
};
|
|
403
405
|
contractAddress: string;
|
|
404
406
|
chain?: z.Primitive;
|
|
@@ -425,4 +427,7 @@ export declare const contractConditionSchema: z.ZodEffects<z.ZodObject<{
|
|
|
425
427
|
} | undefined;
|
|
426
428
|
}>;
|
|
427
429
|
export type ContractConditionProps = z.infer<typeof contractConditionSchema>;
|
|
430
|
+
export declare class ContractCondition extends Condition {
|
|
431
|
+
constructor(value: OmitConditionType<ContractConditionProps>);
|
|
432
|
+
}
|
|
428
433
|
export {};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { ethers } from 'ethers';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
+
import { Condition } from '../condition';
|
|
3
4
|
import { ETH_ADDRESS_REGEXP } from '../const';
|
|
5
|
+
import { paramOrContextParamSchema } from '../shared';
|
|
4
6
|
import { rpcConditionSchema } from './rpc';
|
|
5
7
|
// TODO: Consider replacing with `z.unknown`:
|
|
6
8
|
// Since Solidity types are tied to Solidity version, we may not be able to accurately represent them in Zod.
|
|
@@ -43,6 +45,7 @@ const functionAbiSchema = z
|
|
|
43
45
|
return functionsInAbi.length === 1;
|
|
44
46
|
}, {
|
|
45
47
|
message: '"functionAbi" must contain a single function definition',
|
|
48
|
+
path: ['functionAbi'],
|
|
46
49
|
})
|
|
47
50
|
.refine((functionAbi) => {
|
|
48
51
|
const asInterface = new ethers.utils.Interface(JSON.stringify([functionAbi]));
|
|
@@ -50,6 +53,7 @@ const functionAbiSchema = z
|
|
|
50
53
|
return functionAbi.inputs.length === nrOfInputs;
|
|
51
54
|
}, {
|
|
52
55
|
message: '"parameters" must have the same length as "functionAbi.inputs"',
|
|
56
|
+
path: ['parameters'],
|
|
53
57
|
});
|
|
54
58
|
export const ContractConditionType = 'contract';
|
|
55
59
|
export const contractConditionSchema = rpcConditionSchema
|
|
@@ -57,11 +61,11 @@ export const contractConditionSchema = rpcConditionSchema
|
|
|
57
61
|
conditionType: z
|
|
58
62
|
.literal(ContractConditionType)
|
|
59
63
|
.default(ContractConditionType),
|
|
60
|
-
contractAddress: z.string().regex(ETH_ADDRESS_REGEXP),
|
|
64
|
+
contractAddress: z.string().regex(ETH_ADDRESS_REGEXP).length(42),
|
|
61
65
|
standardContractType: z.enum(['ERC20', 'ERC721']).optional(),
|
|
62
66
|
method: z.string(),
|
|
63
67
|
functionAbi: functionAbiSchema.optional(),
|
|
64
|
-
parameters: z.array(
|
|
68
|
+
parameters: z.array(paramOrContextParamSchema),
|
|
65
69
|
})
|
|
66
70
|
// Adding this custom logic causes the return type to be ZodEffects instead of ZodObject
|
|
67
71
|
// https://github.com/colinhacks/zod/issues/2474
|
|
@@ -69,5 +73,14 @@ export const contractConditionSchema = rpcConditionSchema
|
|
|
69
73
|
// A check to see if either 'standardContractType' or 'functionAbi' is set
|
|
70
74
|
(data) => Boolean(data.standardContractType) !== Boolean(data.functionAbi), {
|
|
71
75
|
message: "At most one of the fields 'standardContractType' and 'functionAbi' must be defined",
|
|
76
|
+
path: ['standardContractType'],
|
|
72
77
|
});
|
|
78
|
+
export class ContractCondition extends Condition {
|
|
79
|
+
constructor(value) {
|
|
80
|
+
super(contractConditionSchema, {
|
|
81
|
+
conditionType: ContractConditionType,
|
|
82
|
+
...value,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
73
86
|
//# sourceMappingURL=contract.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../../../../src/conditions/base/contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,C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7B,aAAa,EAAE,qBAAqB;YACpC,GAAG,KAAK;SACT,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -1,21 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { RpcConditionProps } from './rpc';
|
|
5
|
-
import { TimeConditionProps } from './time';
|
|
6
|
-
export declare class CompoundCondition extends Condition {
|
|
7
|
-
constructor(value: CompoundConditionProps);
|
|
8
|
-
}
|
|
9
|
-
export declare class ContractCondition extends Condition {
|
|
10
|
-
constructor(value: ContractConditionProps);
|
|
11
|
-
}
|
|
12
|
-
export declare class RpcCondition extends Condition {
|
|
13
|
-
constructor(value: RpcConditionProps);
|
|
14
|
-
}
|
|
15
|
-
export declare class TimeCondition extends Condition {
|
|
16
|
-
constructor(value: TimeConditionProps);
|
|
17
|
-
}
|
|
18
|
-
export { ContractConditionType, FunctionAbiProps, type ContractConditionProps, } from './contract';
|
|
19
|
-
export { RpcConditionType, type RpcConditionProps } from './rpc';
|
|
20
|
-
export { ReturnValueTestProps } from './shared';
|
|
21
|
-
export { TimeConditionMethod, TimeConditionType, type TimeConditionProps, } from './time';
|
|
1
|
+
export * as contract from './contract';
|
|
2
|
+
export * as rpc from './rpc';
|
|
3
|
+
export * as time from './time';
|
|
@@ -1,31 +1,6 @@
|
|
|
1
|
-
import { compoundConditionSchema, } from '../compound-condition';
|
|
2
|
-
import { Condition } from '../condition';
|
|
3
|
-
import { contractConditionSchema } from './contract';
|
|
4
|
-
import { rpcConditionSchema } from './rpc';
|
|
5
|
-
import { timeConditionSchema } from './time';
|
|
6
1
|
// Exporting classes here instead of their respective schema files to
|
|
7
2
|
// avoid circular dependency on Condition class.
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
export class ContractCondition extends Condition {
|
|
14
|
-
constructor(value) {
|
|
15
|
-
super(contractConditionSchema, value);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
export class RpcCondition extends Condition {
|
|
19
|
-
constructor(value) {
|
|
20
|
-
super(rpcConditionSchema, value);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
export class TimeCondition extends Condition {
|
|
24
|
-
constructor(value) {
|
|
25
|
-
super(timeConditionSchema, value);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
export { ContractConditionType, } from './contract';
|
|
29
|
-
export { RpcConditionType } from './rpc';
|
|
30
|
-
export { TimeConditionMethod, TimeConditionType, } from './time';
|
|
3
|
+
export * as contract from './contract';
|
|
4
|
+
export * as rpc from './rpc';
|
|
5
|
+
export * as time from './time';
|
|
31
6
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/conditions/base/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/conditions/base/index.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,gDAAgD;AAEhD,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAC7B,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC"}
|
|
@@ -1,42 +1,47 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { Condition } from '../condition';
|
|
3
|
+
import { OmitConditionType } from '../shared';
|
|
2
4
|
export declare const RpcConditionType = "rpc";
|
|
3
5
|
export declare const rpcConditionSchema: z.ZodObject<{
|
|
4
6
|
conditionType: z.ZodDefault<z.ZodLiteral<"rpc">>;
|
|
5
7
|
chain: z.ZodNever | z.ZodLiteral<z.Primitive> | z.ZodUnion<[z.ZodLiteral<z.Primitive>, z.ZodLiteral<z.Primitive>, ...z.ZodLiteral<z.Primitive>[]]>;
|
|
6
|
-
method: z.ZodEnum<["eth_getBalance"
|
|
7
|
-
parameters: z.ZodUnion<[z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodLiteral<":userAddress">]>, "
|
|
8
|
+
method: z.ZodEnum<["eth_getBalance"]>;
|
|
9
|
+
parameters: z.ZodUnion<[z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodLiteral<":userAddress">]>, "atleastone">, z.ZodTuple<[z.ZodUnion<[z.ZodString, z.ZodLiteral<":userAddress">]>, z.ZodType<any, z.ZodTypeDef, any>], null>]>;
|
|
8
10
|
returnValueTest: z.ZodObject<{
|
|
9
11
|
index: z.ZodOptional<z.ZodNumber>;
|
|
10
12
|
comparator: z.ZodEnum<["==", ">", "<", ">=", "<=", "!="]>;
|
|
11
|
-
value: z.
|
|
13
|
+
value: z.ZodType<any, z.ZodTypeDef, any>;
|
|
12
14
|
}, "strip", z.ZodTypeAny, {
|
|
13
15
|
comparator: "==" | ">" | "<" | ">=" | "<=" | "!=";
|
|
14
16
|
index?: number | undefined;
|
|
15
|
-
value?:
|
|
17
|
+
value?: any;
|
|
16
18
|
}, {
|
|
17
19
|
comparator: "==" | ">" | "<" | ">=" | "<=" | "!=";
|
|
18
20
|
index?: number | undefined;
|
|
19
|
-
value?:
|
|
21
|
+
value?: any;
|
|
20
22
|
}>;
|
|
21
23
|
}, "strip", z.ZodTypeAny, {
|
|
22
24
|
conditionType: "rpc";
|
|
23
|
-
method: "eth_getBalance"
|
|
24
|
-
parameters: (string[] | [string,
|
|
25
|
+
method: "eth_getBalance";
|
|
26
|
+
parameters: ([string, ...string[]] | [string, any]) & ([string, ...string[]] | [string, any] | undefined);
|
|
25
27
|
returnValueTest: {
|
|
26
28
|
comparator: "==" | ">" | "<" | ">=" | "<=" | "!=";
|
|
27
29
|
index?: number | undefined;
|
|
28
|
-
value?:
|
|
30
|
+
value?: any;
|
|
29
31
|
};
|
|
30
32
|
chain?: z.Primitive;
|
|
31
33
|
}, {
|
|
32
|
-
method: "eth_getBalance"
|
|
33
|
-
parameters: (string[] | [string,
|
|
34
|
+
method: "eth_getBalance";
|
|
35
|
+
parameters: ([string, ...string[]] | [string, any]) & ([string, ...string[]] | [string, any] | undefined);
|
|
34
36
|
returnValueTest: {
|
|
35
37
|
comparator: "==" | ">" | "<" | ">=" | "<=" | "!=";
|
|
36
38
|
index?: number | undefined;
|
|
37
|
-
value?:
|
|
39
|
+
value?: any;
|
|
38
40
|
};
|
|
39
41
|
conditionType?: "rpc" | undefined;
|
|
40
42
|
chain?: z.Primitive;
|
|
41
43
|
}>;
|
|
42
44
|
export type RpcConditionProps = z.infer<typeof rpcConditionSchema>;
|
|
45
|
+
export declare class RpcCondition extends Condition {
|
|
46
|
+
constructor(value: OmitConditionType<RpcConditionProps>);
|
|
47
|
+
}
|
|
@@ -1,17 +1,26 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { Condition } from '../condition';
|
|
2
3
|
import { SUPPORTED_CHAIN_IDS } from '../const';
|
|
4
|
+
import { EthAddressOrUserAddressSchema, paramOrContextParamSchema, returnValueTestSchema, } from '../shared';
|
|
3
5
|
import createUnionSchema from '../zod';
|
|
4
|
-
import { EthAddressOrUserAddressSchema, returnValueTestSchema } from './shared';
|
|
5
6
|
export const RpcConditionType = 'rpc';
|
|
6
7
|
export const rpcConditionSchema = z.object({
|
|
7
8
|
conditionType: z.literal(RpcConditionType).default(RpcConditionType),
|
|
8
9
|
chain: createUnionSchema(SUPPORTED_CHAIN_IDS),
|
|
9
|
-
method: z.enum(['eth_getBalance'
|
|
10
|
+
method: z.enum(['eth_getBalance']),
|
|
10
11
|
parameters: z.union([
|
|
11
|
-
z.array(EthAddressOrUserAddressSchema).
|
|
12
|
+
z.array(EthAddressOrUserAddressSchema).nonempty(),
|
|
12
13
|
// Using tuple here because ordering matters
|
|
13
|
-
z.tuple([EthAddressOrUserAddressSchema,
|
|
14
|
+
z.tuple([EthAddressOrUserAddressSchema, paramOrContextParamSchema]),
|
|
14
15
|
]),
|
|
15
|
-
returnValueTest: returnValueTestSchema,
|
|
16
|
+
returnValueTest: returnValueTestSchema, // Update to allow multiple return values after expanding supported methods
|
|
16
17
|
});
|
|
18
|
+
export class RpcCondition extends Condition {
|
|
19
|
+
constructor(value) {
|
|
20
|
+
super(rpcConditionSchema, {
|
|
21
|
+
conditionType: RpcConditionType,
|
|
22
|
+
...value,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
17
26
|
//# sourceMappingURL=rpc.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rpc.js","sourceRoot":"","sources":["../../../../src/conditions/base/rpc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"rpc.js","sourceRoot":"","sources":["../../../../src/conditions/base/rpc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,EACL,6BAA6B,EAE7B,yBAAyB,EACzB,qBAAqB,GACtB,MAAM,WAAW,CAAC;AACnB,OAAO,iBAAiB,MAAM,QAAQ,CAAC;AAEvC,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,CAAC;AAEtC,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IACzC,aAAa,EAAE,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC;IACpE,KAAK,EAAE,iBAAiB,CAAC,mBAAmB,CAAC;IAC7C,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,gBAAgB,CAAC,CAAC;IAClC,UAAU,EAAE,CAAC,CAAC,KAAK,CAAC;QAClB,CAAC,CAAC,KAAK,CAAC,6BAA6B,CAAC,CAAC,QAAQ,EAAE;QACjD,4CAA4C;QAC5C,CAAC,CAAC,KAAK,CAAC,CAAC,6BAA6B,EAAE,yBAAyB,CAAC,CAAC;KACpE,CAAC;IACF,eAAe,EAAE,qBAAqB,EAAE,2EAA2E;CACpH,CAAC,CAAC;AAIH,MAAM,OAAO,YAAa,SAAQ,SAAS;IACzC,YAAY,KAA2C;QACrD,KAAK,CAAC,kBAAkB,EAAE;YACxB,aAAa,EAAE,gBAAgB;YAC/B,GAAG,KAAK;SACT,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { Condition } from '../condition';
|
|
3
|
+
import { OmitConditionType } from '../shared';
|
|
2
4
|
export declare const TimeConditionType = "time";
|
|
3
5
|
export declare const TimeConditionMethod = "blocktime";
|
|
4
6
|
export declare const timeConditionSchema: z.ZodObject<{
|
|
@@ -8,15 +10,15 @@ export declare const timeConditionSchema: z.ZodObject<{
|
|
|
8
10
|
returnValueTest: z.ZodObject<{
|
|
9
11
|
index: z.ZodOptional<z.ZodNumber>;
|
|
10
12
|
comparator: z.ZodEnum<["==", ">", "<", ">=", "<=", "!="]>;
|
|
11
|
-
value: z.
|
|
13
|
+
value: z.ZodType<any, z.ZodTypeDef, any>;
|
|
12
14
|
}, "strip", z.ZodTypeAny, {
|
|
13
15
|
comparator: "==" | ">" | "<" | ">=" | "<=" | "!=";
|
|
14
16
|
index?: number | undefined;
|
|
15
|
-
value?:
|
|
17
|
+
value?: any;
|
|
16
18
|
}, {
|
|
17
19
|
comparator: "==" | ">" | "<" | ">=" | "<=" | "!=";
|
|
18
20
|
index?: number | undefined;
|
|
19
|
-
value?:
|
|
21
|
+
value?: any;
|
|
20
22
|
}>;
|
|
21
23
|
}, "strip", z.ZodTypeAny, {
|
|
22
24
|
conditionType: "time";
|
|
@@ -24,17 +26,20 @@ export declare const timeConditionSchema: z.ZodObject<{
|
|
|
24
26
|
returnValueTest: {
|
|
25
27
|
comparator: "==" | ">" | "<" | ">=" | "<=" | "!=";
|
|
26
28
|
index?: number | undefined;
|
|
27
|
-
value?:
|
|
29
|
+
value?: any;
|
|
28
30
|
};
|
|
29
31
|
chain?: z.Primitive;
|
|
30
32
|
}, {
|
|
31
33
|
returnValueTest: {
|
|
32
34
|
comparator: "==" | ">" | "<" | ">=" | "<=" | "!=";
|
|
33
35
|
index?: number | undefined;
|
|
34
|
-
value?:
|
|
36
|
+
value?: any;
|
|
35
37
|
};
|
|
36
38
|
conditionType?: "time" | undefined;
|
|
37
39
|
method?: "blocktime" | undefined;
|
|
38
40
|
chain?: z.Primitive;
|
|
39
41
|
}>;
|
|
40
42
|
export type TimeConditionProps = z.infer<typeof timeConditionSchema>;
|
|
43
|
+
export declare class TimeCondition extends Condition {
|
|
44
|
+
constructor(value: OmitConditionType<TimeConditionProps>);
|
|
45
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { Condition } from '../condition';
|
|
2
3
|
import { rpcConditionSchema } from './rpc';
|
|
3
4
|
// TimeCondition is an RpcCondition with the method set to 'blocktime' and no parameters
|
|
4
5
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
@@ -10,4 +11,12 @@ export const timeConditionSchema = z.object({
|
|
|
10
11
|
conditionType: z.literal(TimeConditionType).default(TimeConditionType),
|
|
11
12
|
method: z.literal(TimeConditionMethod).default(TimeConditionMethod),
|
|
12
13
|
});
|
|
14
|
+
export class TimeCondition extends Condition {
|
|
15
|
+
constructor(value) {
|
|
16
|
+
super(timeConditionSchema, {
|
|
17
|
+
conditionType: TimeConditionType,
|
|
18
|
+
...value,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
13
22
|
//# sourceMappingURL=time.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time.js","sourceRoot":"","sources":["../../../../src/conditions/base/time.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,kBAAkB,EAAE,M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,CAAC;CACpE,CAAC,CAAC;AAIH,MAAM,OAAO,aAAc,SAAQ,SAAS;IAC1C,YAAY,KAA4C;QACtD,KAAK,CAAC,mBAAmB,EAAE;YACzB,aAAa,EAAE,iBAAiB;YAChC,GAAG,KAAK;SACT,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { Condition, ConditionProps } from './condition';
|
|
3
|
+
import { OmitConditionType } from './shared';
|
|
2
4
|
export declare const CompoundConditionType = "compound";
|
|
3
5
|
export declare const compoundConditionSchema: z.ZodSchema;
|
|
4
6
|
export type CompoundConditionProps = z.infer<typeof compoundConditionSchema>;
|
|
7
|
+
export type ConditionOrProps = Condition | ConditionProps;
|
|
8
|
+
export declare class CompoundCondition extends Condition {
|
|
9
|
+
constructor(value: OmitConditionType<CompoundConditionProps>);
|
|
10
|
+
private static withOperator;
|
|
11
|
+
static or(conditions: ConditionOrProps[]): CompoundCondition;
|
|
12
|
+
static and(conditions: ConditionOrProps[]): CompoundCondition;
|
|
13
|
+
static not(condition: ConditionOrProps): CompoundCondition;
|
|
14
|
+
}
|