@nucypher/taco 0.4.0 → 0.6.0-alpha.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 +0 -1
- package/dist/cjs/conditions/base/contract.d.ts +2 -432
- package/dist/cjs/conditions/base/contract.js +7 -80
- package/dist/cjs/conditions/base/contract.js.map +1 -1
- package/dist/cjs/conditions/base/index.d.ts +1 -0
- package/dist/cjs/conditions/base/index.js +2 -1
- package/dist/cjs/conditions/base/index.js.map +1 -1
- package/dist/cjs/conditions/base/json-api.d.ts +7 -0
- package/dist/cjs/conditions/base/json-api.js +19 -0
- package/dist/cjs/conditions/base/json-api.js.map +1 -0
- package/dist/cjs/conditions/base/rpc.d.ts +2 -42
- package/dist/cjs/conditions/base/rpc.js +7 -22
- package/dist/cjs/conditions/base/rpc.js.map +1 -1
- package/dist/cjs/conditions/base/time.d.ts +2 -40
- package/dist/cjs/conditions/base/time.js +8 -15
- package/dist/cjs/conditions/base/time.js.map +1 -1
- package/dist/cjs/conditions/compound-condition.d.ts +2 -4
- package/dist/cjs/conditions/compound-condition.js +7 -38
- package/dist/cjs/conditions/compound-condition.js.map +1 -1
- package/dist/cjs/conditions/condition-expr.d.ts +0 -3
- package/dist/cjs/conditions/condition-expr.js +0 -4
- package/dist/cjs/conditions/condition-expr.js.map +1 -1
- package/dist/cjs/conditions/condition-factory.js +11 -0
- package/dist/cjs/conditions/condition-factory.js.map +1 -1
- package/dist/cjs/conditions/condition.d.ts +1 -1
- package/dist/cjs/conditions/condition.js +3 -1
- package/dist/cjs/conditions/condition.js.map +1 -1
- package/dist/cjs/conditions/const.d.ts +1 -2
- package/dist/cjs/conditions/const.js +6 -8
- package/dist/cjs/conditions/const.js.map +1 -1
- package/dist/cjs/conditions/context/context.d.ts +15 -13
- package/dist/cjs/conditions/context/context.js +62 -56
- package/dist/cjs/conditions/context/context.js.map +1 -1
- package/dist/cjs/conditions/if-then-else-condition.d.ts +7 -0
- package/dist/cjs/conditions/if-then-else-condition.js +18 -0
- package/dist/cjs/conditions/if-then-else-condition.js.map +1 -0
- package/dist/cjs/conditions/index.d.ts +2 -0
- package/dist/cjs/conditions/index.js +3 -1
- package/dist/cjs/conditions/index.js.map +1 -1
- package/dist/cjs/conditions/multi-condition.d.ts +2 -0
- package/dist/cjs/conditions/multi-condition.js +35 -0
- package/dist/cjs/conditions/multi-condition.js.map +1 -0
- package/dist/cjs/conditions/schemas/common.d.ts +12 -0
- package/dist/cjs/conditions/schemas/common.js +36 -0
- package/dist/cjs/conditions/schemas/common.js.map +1 -0
- package/dist/cjs/conditions/schemas/compound.d.ts +4 -0
- package/dist/cjs/conditions/schemas/compound.js +36 -0
- package/dist/cjs/conditions/schemas/compound.js.map +1 -0
- package/dist/cjs/conditions/schemas/context.d.ts +3 -0
- package/dist/cjs/conditions/schemas/context.js +16 -0
- package/dist/cjs/conditions/schemas/context.js.map +1 -0
- package/dist/cjs/conditions/schemas/contract.d.ts +428 -0
- package/dist/cjs/conditions/schemas/contract.js +81 -0
- package/dist/cjs/conditions/schemas/contract.js.map +1 -0
- package/dist/cjs/conditions/schemas/if-then-else.d.ts +4 -0
- package/dist/cjs/conditions/schemas/if-then-else.js +40 -0
- package/dist/cjs/conditions/schemas/if-then-else.js.map +1 -0
- package/dist/cjs/conditions/schemas/json-api.d.ts +46 -0
- package/dist/cjs/conditions/schemas/json-api.js +37 -0
- package/dist/cjs/conditions/schemas/json-api.js.map +1 -0
- package/dist/cjs/conditions/schemas/return-value-test.d.ts +15 -0
- package/dist/cjs/conditions/schemas/return-value-test.js +11 -0
- package/dist/cjs/conditions/schemas/return-value-test.js.map +1 -0
- package/dist/cjs/conditions/schemas/rpc.d.ts +42 -0
- package/dist/cjs/conditions/schemas/rpc.js +58 -0
- package/dist/cjs/conditions/schemas/rpc.js.map +1 -0
- package/dist/cjs/conditions/schemas/sequential.d.ts +6 -0
- package/dist/cjs/conditions/schemas/sequential.js +39 -0
- package/dist/cjs/conditions/schemas/sequential.js.map +1 -0
- package/dist/cjs/conditions/schemas/time.d.ts +40 -0
- package/dist/cjs/conditions/schemas/time.js +16 -0
- package/dist/cjs/conditions/schemas/time.js.map +1 -0
- package/dist/cjs/conditions/schemas/utils.d.ts +2 -0
- package/dist/cjs/conditions/schemas/utils.js +21 -0
- package/dist/cjs/conditions/schemas/utils.js.map +1 -0
- package/dist/cjs/conditions/sequential.d.ts +7 -0
- package/dist/cjs/conditions/sequential.js +18 -0
- package/dist/cjs/conditions/sequential.js.map +1 -0
- package/dist/cjs/conditions/shared.d.ts +2 -19
- package/dist/cjs/conditions/shared.js +6 -32
- package/dist/cjs/conditions/shared.js.map +1 -1
- package/dist/cjs/dkg.d.ts +1 -1
- package/dist/cjs/dkg.js +2 -2
- package/dist/cjs/dkg.js.map +1 -1
- package/dist/cjs/index.d.ts +2 -3
- package/dist/cjs/index.js +2 -8
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/taco.d.ts +5 -23
- package/dist/cjs/taco.js +9 -36
- package/dist/cjs/taco.js.map +1 -1
- package/dist/cjs/tdec.d.ts +3 -4
- package/dist/cjs/tdec.js +11 -8
- package/dist/cjs/tdec.js.map +1 -1
- package/dist/es/conditions/base/contract.d.ts +2 -432
- package/dist/es/conditions/base/contract.js +2 -77
- package/dist/es/conditions/base/contract.js.map +1 -1
- package/dist/es/conditions/base/index.d.ts +1 -0
- package/dist/es/conditions/base/index.js +1 -0
- package/dist/es/conditions/base/index.js.map +1 -1
- package/dist/es/conditions/base/json-api.d.ts +7 -0
- package/dist/es/conditions/base/json-api.js +12 -0
- package/dist/es/conditions/base/json-api.js.map +1 -0
- package/dist/es/conditions/base/rpc.d.ts +2 -42
- package/dist/es/conditions/base/rpc.js +2 -16
- package/dist/es/conditions/base/rpc.js.map +1 -1
- package/dist/es/conditions/base/time.d.ts +2 -40
- package/dist/es/conditions/base/time.js +2 -12
- package/dist/es/conditions/base/time.js.map +1 -1
- package/dist/es/conditions/compound-condition.d.ts +2 -4
- package/dist/es/conditions/compound-condition.js +2 -35
- package/dist/es/conditions/compound-condition.js.map +1 -1
- package/dist/es/conditions/condition-expr.d.ts +0 -3
- package/dist/es/conditions/condition-expr.js +0 -4
- package/dist/es/conditions/condition-expr.js.map +1 -1
- package/dist/es/conditions/condition-factory.js +11 -0
- package/dist/es/conditions/condition-factory.js.map +1 -1
- package/dist/es/conditions/condition.d.ts +1 -1
- package/dist/es/conditions/condition.js +1 -0
- package/dist/es/conditions/condition.js.map +1 -1
- package/dist/es/conditions/const.d.ts +1 -2
- package/dist/es/conditions/const.js +5 -7
- package/dist/es/conditions/const.js.map +1 -1
- package/dist/es/conditions/context/context.d.ts +15 -13
- package/dist/es/conditions/context/context.js +63 -57
- package/dist/es/conditions/context/context.js.map +1 -1
- package/dist/es/conditions/if-then-else-condition.d.ts +7 -0
- package/dist/es/conditions/if-then-else-condition.js +12 -0
- package/dist/es/conditions/if-then-else-condition.js.map +1 -0
- package/dist/es/conditions/index.d.ts +2 -0
- package/dist/es/conditions/index.js +2 -0
- package/dist/es/conditions/index.js.map +1 -1
- package/dist/es/conditions/multi-condition.d.ts +2 -0
- package/dist/es/conditions/multi-condition.js +31 -0
- package/dist/es/conditions/multi-condition.js.map +1 -0
- package/dist/es/conditions/schemas/common.d.ts +12 -0
- package/dist/es/conditions/schemas/common.js +33 -0
- package/dist/es/conditions/schemas/common.js.map +1 -0
- package/dist/es/conditions/schemas/compound.d.ts +4 -0
- package/dist/es/conditions/schemas/compound.js +33 -0
- package/dist/es/conditions/schemas/compound.js.map +1 -0
- package/dist/es/conditions/schemas/context.d.ts +3 -0
- package/dist/es/conditions/schemas/context.js +13 -0
- package/dist/es/conditions/schemas/context.js.map +1 -0
- package/dist/es/conditions/schemas/contract.d.ts +428 -0
- package/dist/es/conditions/schemas/contract.js +78 -0
- package/dist/es/conditions/schemas/contract.js.map +1 -0
- package/dist/es/conditions/schemas/if-then-else.d.ts +4 -0
- package/dist/es/conditions/schemas/if-then-else.js +37 -0
- package/dist/es/conditions/schemas/if-then-else.js.map +1 -0
- package/dist/es/conditions/schemas/json-api.d.ts +46 -0
- package/dist/es/conditions/schemas/json-api.js +34 -0
- package/dist/es/conditions/schemas/json-api.js.map +1 -0
- package/dist/es/conditions/schemas/return-value-test.d.ts +15 -0
- package/dist/es/conditions/schemas/return-value-test.js +8 -0
- package/dist/es/conditions/schemas/return-value-test.js.map +1 -0
- package/dist/es/conditions/schemas/rpc.d.ts +42 -0
- package/dist/es/conditions/schemas/rpc.js +32 -0
- package/dist/es/conditions/schemas/rpc.js.map +1 -0
- package/dist/es/conditions/schemas/sequential.d.ts +6 -0
- package/dist/es/conditions/schemas/sequential.js +36 -0
- package/dist/es/conditions/schemas/sequential.js.map +1 -0
- package/dist/es/conditions/schemas/time.d.ts +40 -0
- package/dist/es/conditions/schemas/time.js +13 -0
- package/dist/es/conditions/schemas/time.js.map +1 -0
- package/dist/es/conditions/schemas/utils.d.ts +2 -0
- package/dist/es/conditions/schemas/utils.js +18 -0
- package/dist/es/conditions/schemas/utils.js.map +1 -0
- package/dist/es/conditions/sequential.d.ts +7 -0
- package/dist/es/conditions/sequential.js +12 -0
- package/dist/es/conditions/sequential.js.map +1 -0
- package/dist/es/conditions/shared.d.ts +2 -19
- package/dist/es/conditions/shared.js +2 -33
- package/dist/es/conditions/shared.js.map +1 -1
- package/dist/es/dkg.d.ts +1 -1
- package/dist/es/dkg.js +2 -2
- package/dist/es/dkg.js.map +1 -1
- package/dist/es/index.d.ts +2 -3
- package/dist/es/index.js +2 -5
- package/dist/es/index.js.map +1 -1
- package/dist/es/taco.d.ts +5 -23
- package/dist/es/taco.js +9 -34
- package/dist/es/taco.js.map +1 -1
- package/dist/es/tdec.d.ts +3 -4
- package/dist/es/tdec.js +12 -9
- 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 +7 -6
|
@@ -1,30 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.RpcCondition = exports.
|
|
7
|
-
const zod_1 = require("zod");
|
|
3
|
+
exports.RpcCondition = exports.RpcConditionType = exports.rpcConditionSchema = void 0;
|
|
8
4
|
const condition_1 = require("../condition");
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
exports.RpcConditionType
|
|
13
|
-
exports.rpcConditionSchema = zod_1.z.object({
|
|
14
|
-
conditionType: zod_1.z.literal(exports.RpcConditionType).default(exports.RpcConditionType),
|
|
15
|
-
chain: (0, zod_2.default)(const_1.SUPPORTED_CHAIN_IDS),
|
|
16
|
-
method: zod_1.z.enum(['eth_getBalance']),
|
|
17
|
-
parameters: zod_1.z.union([
|
|
18
|
-
zod_1.z.array(shared_1.EthAddressOrUserAddressSchema).nonempty(),
|
|
19
|
-
// Using tuple here because ordering matters
|
|
20
|
-
zod_1.z.tuple([shared_1.EthAddressOrUserAddressSchema, shared_1.paramOrContextParamSchema]),
|
|
21
|
-
]),
|
|
22
|
-
returnValueTest: shared_1.returnValueTestSchema, // Update to allow multiple return values after expanding supported methods
|
|
23
|
-
});
|
|
5
|
+
const rpc_1 = require("../schemas/rpc");
|
|
6
|
+
var rpc_2 = require("../schemas/rpc");
|
|
7
|
+
Object.defineProperty(exports, "rpcConditionSchema", { enumerable: true, get: function () { return rpc_2.rpcConditionSchema; } });
|
|
8
|
+
Object.defineProperty(exports, "RpcConditionType", { enumerable: true, get: function () { return rpc_2.RpcConditionType; } });
|
|
24
9
|
class RpcCondition extends condition_1.Condition {
|
|
25
10
|
constructor(value) {
|
|
26
|
-
super(
|
|
27
|
-
conditionType:
|
|
11
|
+
super(rpc_1.rpcConditionSchema, {
|
|
12
|
+
conditionType: rpc_1.RpcConditionType,
|
|
28
13
|
...value,
|
|
29
14
|
});
|
|
30
15
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rpc.js","sourceRoot":"","sources":["../../../../src/conditions/base/rpc.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rpc.js","sourceRoot":"","sources":["../../../../src/conditions/base/rpc.ts"],"names":[],"mappings":";;;AAAA,4CAAyC;AACzC,wCAIwB;AAGxB,sCAIwB;AAFtB,yGAAA,kBAAkB,OAAA;AAClB,uGAAA,gBAAgB,OAAA;AAGlB,MAAa,YAAa,SAAQ,qBAAS;IACzC,YAAY,KAA2C;QACrD,KAAK,CAAC,wBAAkB,EAAE;YACxB,aAAa,EAAE,sBAAgB;YAC/B,GAAG,KAAK;SACT,CAAC,CAAC;IACL,CAAC;CACF;AAPD,oCAOC"}
|
|
@@ -1,45 +1,7 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
1
|
import { Condition } from '../condition';
|
|
2
|
+
import { TimeConditionProps } from '../schemas/time';
|
|
3
3
|
import { OmitConditionType } from '../shared';
|
|
4
|
-
export
|
|
5
|
-
export declare const TimeConditionMethod = "blocktime";
|
|
6
|
-
export declare const timeConditionSchema: z.ZodObject<{
|
|
7
|
-
conditionType: z.ZodDefault<z.ZodLiteral<"time">>;
|
|
8
|
-
method: z.ZodDefault<z.ZodLiteral<"blocktime">>;
|
|
9
|
-
chain: z.ZodNever | z.ZodLiteral<z.Primitive> | z.ZodUnion<[z.ZodLiteral<z.Primitive>, z.ZodLiteral<z.Primitive>, ...z.ZodLiteral<z.Primitive>[]]>;
|
|
10
|
-
returnValueTest: z.ZodObject<{
|
|
11
|
-
index: z.ZodOptional<z.ZodNumber>;
|
|
12
|
-
comparator: z.ZodEnum<["==", ">", "<", ">=", "<=", "!="]>;
|
|
13
|
-
value: z.ZodType<any, z.ZodTypeDef, any>;
|
|
14
|
-
}, "strip", z.ZodTypeAny, {
|
|
15
|
-
comparator: "==" | ">" | "<" | ">=" | "<=" | "!=";
|
|
16
|
-
value?: any;
|
|
17
|
-
index?: number | undefined;
|
|
18
|
-
}, {
|
|
19
|
-
comparator: "==" | ">" | "<" | ">=" | "<=" | "!=";
|
|
20
|
-
value?: any;
|
|
21
|
-
index?: number | undefined;
|
|
22
|
-
}>;
|
|
23
|
-
}, "strip", z.ZodTypeAny, {
|
|
24
|
-
conditionType: "time";
|
|
25
|
-
method: "blocktime";
|
|
26
|
-
returnValueTest: {
|
|
27
|
-
comparator: "==" | ">" | "<" | ">=" | "<=" | "!=";
|
|
28
|
-
value?: any;
|
|
29
|
-
index?: number | undefined;
|
|
30
|
-
};
|
|
31
|
-
chain?: z.Primitive;
|
|
32
|
-
}, {
|
|
33
|
-
returnValueTest: {
|
|
34
|
-
comparator: "==" | ">" | "<" | ">=" | "<=" | "!=";
|
|
35
|
-
value?: any;
|
|
36
|
-
index?: number | undefined;
|
|
37
|
-
};
|
|
38
|
-
conditionType?: "time" | undefined;
|
|
39
|
-
chain?: z.Primitive;
|
|
40
|
-
method?: "blocktime" | undefined;
|
|
41
|
-
}>;
|
|
42
|
-
export type TimeConditionProps = z.infer<typeof timeConditionSchema>;
|
|
4
|
+
export { TimeConditionMethod, TimeConditionProps, timeConditionSchema, TimeConditionType, } from '../schemas/time';
|
|
43
5
|
export declare class TimeCondition extends Condition {
|
|
44
6
|
constructor(value: OmitConditionType<TimeConditionProps>);
|
|
45
7
|
}
|
|
@@ -1,23 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TimeCondition = exports.
|
|
4
|
-
const zod_1 = require("zod");
|
|
3
|
+
exports.TimeCondition = exports.TimeConditionType = exports.timeConditionSchema = exports.TimeConditionMethod = void 0;
|
|
5
4
|
const condition_1 = require("../condition");
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
exports.TimeConditionType
|
|
11
|
-
exports.TimeConditionMethod = 'blocktime';
|
|
12
|
-
exports.timeConditionSchema = zod_1.z.object({
|
|
13
|
-
...restShape,
|
|
14
|
-
conditionType: zod_1.z.literal(exports.TimeConditionType).default(exports.TimeConditionType),
|
|
15
|
-
method: zod_1.z.literal(exports.TimeConditionMethod).default(exports.TimeConditionMethod),
|
|
16
|
-
});
|
|
5
|
+
const time_1 = require("../schemas/time");
|
|
6
|
+
var time_2 = require("../schemas/time");
|
|
7
|
+
Object.defineProperty(exports, "TimeConditionMethod", { enumerable: true, get: function () { return time_2.TimeConditionMethod; } });
|
|
8
|
+
Object.defineProperty(exports, "timeConditionSchema", { enumerable: true, get: function () { return time_2.timeConditionSchema; } });
|
|
9
|
+
Object.defineProperty(exports, "TimeConditionType", { enumerable: true, get: function () { return time_2.TimeConditionType; } });
|
|
17
10
|
class TimeCondition extends condition_1.Condition {
|
|
18
11
|
constructor(value) {
|
|
19
|
-
super(
|
|
20
|
-
conditionType:
|
|
12
|
+
super(time_1.timeConditionSchema, {
|
|
13
|
+
conditionType: time_1.TimeConditionType,
|
|
21
14
|
...value,
|
|
22
15
|
});
|
|
23
16
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time.js","sourceRoot":"","sources":["../../../../src/conditions/base/time.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"time.js","sourceRoot":"","sources":["../../../../src/conditions/base/time.ts"],"names":[],"mappings":";;;AAAA,4CAAyC;AACzC,0CAIyB;AAGzB,wCAKyB;AAJvB,2GAAA,mBAAmB,OAAA;AAEnB,2GAAA,mBAAmB,OAAA;AACnB,yGAAA,iBAAiB,OAAA;AAGnB,MAAa,aAAc,SAAQ,qBAAS;IAC1C,YAAY,KAA4C;QACtD,KAAK,CAAC,0BAAmB,EAAE;YACzB,aAAa,EAAE,wBAAiB;YAChC,GAAG,KAAK;SACT,CAAC,CAAC;IACL,CAAC;CACF;AAPD,sCAOC"}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
1
|
import { Condition, ConditionProps } from './condition';
|
|
2
|
+
import { CompoundConditionProps } from './schemas/compound';
|
|
3
3
|
import { OmitConditionType } from './shared';
|
|
4
|
-
export
|
|
5
|
-
export declare const compoundConditionSchema: z.ZodSchema;
|
|
6
|
-
export type CompoundConditionProps = z.infer<typeof compoundConditionSchema>;
|
|
4
|
+
export { CompoundConditionProps, compoundConditionSchema, CompoundConditionType, } from './schemas/compound';
|
|
7
5
|
export type ConditionOrProps = Condition | ConditionProps;
|
|
8
6
|
export declare class CompoundCondition extends Condition {
|
|
9
7
|
constructor(value: OmitConditionType<CompoundConditionProps>);
|
|
@@ -1,46 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CompoundCondition = exports.
|
|
4
|
-
const zod_1 = require("zod");
|
|
5
|
-
const contract_1 = require("./base/contract");
|
|
6
|
-
const rpc_1 = require("./base/rpc");
|
|
7
|
-
const time_1 = require("./base/time");
|
|
3
|
+
exports.CompoundCondition = exports.CompoundConditionType = exports.compoundConditionSchema = void 0;
|
|
8
4
|
const condition_1 = require("./condition");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
.literal(exports.CompoundConditionType)
|
|
14
|
-
.default(exports.CompoundConditionType),
|
|
15
|
-
operator: zod_1.z.enum(['and', 'or', 'not']),
|
|
16
|
-
operands: zod_1.z
|
|
17
|
-
.array(zod_1.z.lazy(() => zod_1.z.union([
|
|
18
|
-
rpc_1.rpcConditionSchema,
|
|
19
|
-
time_1.timeConditionSchema,
|
|
20
|
-
contract_1.contractConditionSchema,
|
|
21
|
-
exports.compoundConditionSchema,
|
|
22
|
-
])))
|
|
23
|
-
.min(1),
|
|
24
|
-
})
|
|
25
|
-
.refine((condition) => {
|
|
26
|
-
// 'and' and 'or' operators must have at least 2 operands
|
|
27
|
-
if (['and', 'or'].includes(condition.operator)) {
|
|
28
|
-
return condition.operands.length >= 2;
|
|
29
|
-
}
|
|
30
|
-
// 'not' operator must have exactly 1 operand
|
|
31
|
-
if (condition.operator === 'not') {
|
|
32
|
-
return condition.operands.length === 1;
|
|
33
|
-
}
|
|
34
|
-
// We test positive cases exhaustively, so we return false here:
|
|
35
|
-
return false;
|
|
36
|
-
}, ({ operands, operator }) => ({
|
|
37
|
-
message: `Invalid number of operands ${operands.length} for operator "${operator}"`,
|
|
38
|
-
path: ['operands'],
|
|
39
|
-
}));
|
|
5
|
+
const compound_1 = require("./schemas/compound");
|
|
6
|
+
var compound_2 = require("./schemas/compound");
|
|
7
|
+
Object.defineProperty(exports, "compoundConditionSchema", { enumerable: true, get: function () { return compound_2.compoundConditionSchema; } });
|
|
8
|
+
Object.defineProperty(exports, "CompoundConditionType", { enumerable: true, get: function () { return compound_2.CompoundConditionType; } });
|
|
40
9
|
class CompoundCondition extends condition_1.Condition {
|
|
41
10
|
constructor(value) {
|
|
42
|
-
super(
|
|
43
|
-
conditionType:
|
|
11
|
+
super(compound_1.compoundConditionSchema, {
|
|
12
|
+
conditionType: compound_1.CompoundConditionType,
|
|
44
13
|
...value,
|
|
45
14
|
});
|
|
46
15
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compound-condition.js","sourceRoot":"","sources":["../../../src/conditions/compound-condition.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"compound-condition.js","sourceRoot":"","sources":["../../../src/conditions/compound-condition.ts"],"names":[],"mappings":";;;AAAA,2CAAwD;AACxD,iDAI4B;AAG5B,+CAI4B;AAF1B,mHAAA,uBAAuB,OAAA;AACvB,iHAAA,qBAAqB,OAAA;AAKvB,MAAa,iBAAkB,SAAQ,qBAAS;IAC9C,YAAY,KAAgD;QAC1D,KAAK,CAAC,kCAAuB,EAAE;YAC7B,aAAa,EAAE,gCAAqB;YACpC,GAAG,KAAK;SACT,CAAC,CAAC;IACL,CAAC;IAEO,MAAM,CAAC,YAAY,CACzB,QAA4B,EAC5B,QAA8B;QAE9B,MAAM,SAAS,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE;YACzC,IAAI,OAAO,YAAY,qBAAS,EAAE,CAAC;gBACjC,OAAO,OAAO,CAAC,KAAK,EAAE,CAAC;YACzB,CAAC;YACD,OAAO,OAAO,CAAC;QACjB,CAAC,CAAC,CAAC;QACH,OAAO,IAAI,iBAAiB,CAAC;YAC3B,QAAQ;YACR,QAAQ,EAAE,SAAS;SACpB,CAAC,CAAC;IACL,CAAC;IAEM,MAAM,CAAC,EAAE,CAAC,UAA8B;QAC7C,OAAO,iBAAiB,CAAC,YAAY,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IAC1D,CAAC;IAEM,MAAM,CAAC,GAAG,CAAC,UAA8B;QAC9C,OAAO,iBAAiB,CAAC,YAAY,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;IAC3D,CAAC;IAEM,MAAM,CAAC,GAAG,CAAC,SAA2B;QAC3C,OAAO,iBAAiB,CAAC,YAAY,CAAC,CAAC,SAAS,CAAC,EAAE,KAAK,CAAC,CAAC;IAC5D,CAAC;CACF;AAnCD,8CAmCC"}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { Conditions as CoreConditions } from '@nucypher/nucypher-core';
|
|
2
|
-
import { AuthProviders } from '@nucypher/taco-auth';
|
|
3
2
|
import { Condition } from './condition';
|
|
4
|
-
import { ConditionContext, CustomContextParam } from './context';
|
|
5
3
|
export type ConditionExpressionJSON = {
|
|
6
4
|
version: string;
|
|
7
5
|
condition: Record<string, unknown>;
|
|
@@ -17,6 +15,5 @@ export declare class ConditionExpression {
|
|
|
17
15
|
static fromJSON(json: string): ConditionExpression;
|
|
18
16
|
toCoreCondition(): CoreConditions;
|
|
19
17
|
static fromCoreConditions(conditions: CoreConditions): ConditionExpression;
|
|
20
|
-
buildContext(customParameters?: Record<string, CustomContextParam>, authProviders?: AuthProviders): ConditionContext;
|
|
21
18
|
equals(other: ConditionExpression): boolean;
|
|
22
19
|
}
|
|
@@ -5,7 +5,6 @@ const nucypher_core_1 = require("@nucypher/nucypher-core");
|
|
|
5
5
|
const shared_1 = require("@nucypher/shared");
|
|
6
6
|
const semver_1 = require("semver");
|
|
7
7
|
const condition_factory_1 = require("./condition-factory");
|
|
8
|
-
const context_1 = require("./context");
|
|
9
8
|
const ERR_VERSION = (provided, current) => `Version provided, ${provided}, is incompatible with current version, ${current}`;
|
|
10
9
|
const ERR_CONDITION = (condition) => `Invalid condition: unrecognized condition data ${JSON.stringify(condition)}`;
|
|
11
10
|
class ConditionExpression {
|
|
@@ -47,9 +46,6 @@ class ConditionExpression {
|
|
|
47
46
|
static fromCoreConditions(conditions) {
|
|
48
47
|
return ConditionExpression.fromJSON(conditions.toString());
|
|
49
48
|
}
|
|
50
|
-
buildContext(customParameters = {}, authProviders = {}) {
|
|
51
|
-
return new context_1.ConditionContext(this.condition, customParameters, authProviders);
|
|
52
|
-
}
|
|
53
49
|
equals(other) {
|
|
54
50
|
return [
|
|
55
51
|
this.version === other.version,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"condition-expr.js","sourceRoot":"","sources":["../../../src/conditions/condition-expr.ts"],"names":[],"mappings":";;;AAAA,2DAAuE;AACvE,6CAA0C;
|
|
1
|
+
{"version":3,"file":"condition-expr.js","sourceRoot":"","sources":["../../../src/conditions/condition-expr.ts"],"names":[],"mappings":";;;AAAA,2DAAuE;AACvE,6CAA0C;AAC1C,mCAAgC;AAGhC,2DAAuD;AAEvD,MAAM,WAAW,GAAG,CAAC,QAAgB,EAAE,OAAe,EAAE,EAAE,CACxD,qBAAqB,QAAQ,2CAA2C,OAAO,EAAE,CAAC;AACpF,MAAM,aAAa,GAAG,CAAC,SAAkC,EAAE,EAAE,CAC3D,kDAAkD,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,EAAE,CAAC;AAOhF,MAAa,mBAAmB;IAIZ;IACA;IAJX,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC;IAEhC,YACkB,SAAoB,EACpB,UAAkB,mBAAmB,CAAC,OAAO;QAD7C,cAAS,GAAT,SAAS,CAAW;QACpB,YAAO,GAAP,OAAO,CAAsC;IAC5D,CAAC;IAEG,KAAK;QACV,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;QACzC,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,SAAS;SACV,CAAC;IACJ,CAAC;IAEM,MAAM,CAAC,OAAO,CAAC,GAA4B;QAChD,MAAM,eAAe,GAAG,IAAI,eAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAChD,MAAM,cAAc,GAAG,IAAI,eAAM,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC;QAC/D,IAAI,eAAe,CAAC,KAAK,GAAG,cAAc,CAAC,KAAK,EAAE,CAAC;YACjD,MAAM,IAAI,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,OAAO,EAAE,mBAAmB,CAAC,OAAO,CAAC,CAAC,CAAC;QACzE,CAAC;QAED,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC;QAChD,CAAC;QAED,MAAM,SAAS,GAAG,oCAAgB,CAAC,kBAAkB,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACrE,OAAO,IAAI,mBAAmB,CAAC,SAAS,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IACzD,CAAC;IAEM,MAAM;QACX,OAAO,IAAA,eAAM,EAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;IAC9B,CAAC;IAEM,MAAM,CAAC,QAAQ,CAAC,IAAY;QACjC,OAAO,mBAAmB,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;IACvD,CAAC;IAEM,eAAe;QACpB,OAAO,IAAI,0BAAc,CAAC,IAAA,eAAM,EAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IAClD,CAAC;IAEM,MAAM,CAAC,kBAAkB,CAAC,UAA0B;QACzD,OAAO,mBAAmB,CAAC,QAAQ,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC7D,CAAC;IAEM,MAAM,CAAC,KAA0B;QACtC,OAAO;YACL,IAAI,CAAC,OAAO,KAAK,KAAK,CAAC,OAAO;YAC9B,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC;SACvC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACnB,CAAC;;AApDH,kDAqDC"}
|
|
@@ -2,21 +2,32 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ConditionFactory = void 0;
|
|
4
4
|
const contract_1 = require("./base/contract");
|
|
5
|
+
const json_api_1 = require("./base/json-api");
|
|
5
6
|
const rpc_1 = require("./base/rpc");
|
|
6
7
|
const time_1 = require("./base/time");
|
|
7
8
|
const compound_condition_1 = require("./compound-condition");
|
|
9
|
+
const if_then_else_condition_1 = require("./if-then-else-condition");
|
|
10
|
+
const sequential_1 = require("./sequential");
|
|
8
11
|
const ERR_INVALID_CONDITION_TYPE = (type) => `Invalid condition type: ${type}`;
|
|
9
12
|
class ConditionFactory {
|
|
10
13
|
static conditionFromProps(props) {
|
|
11
14
|
switch (props.conditionType) {
|
|
15
|
+
// Base Conditions
|
|
12
16
|
case rpc_1.RpcConditionType:
|
|
13
17
|
return new rpc_1.RpcCondition(props);
|
|
14
18
|
case time_1.TimeConditionType:
|
|
15
19
|
return new time_1.TimeCondition(props);
|
|
16
20
|
case contract_1.ContractConditionType:
|
|
17
21
|
return new contract_1.ContractCondition(props);
|
|
22
|
+
case json_api_1.JsonApiConditionType:
|
|
23
|
+
return new json_api_1.JsonApiCondition(props);
|
|
24
|
+
// Logical Conditions
|
|
18
25
|
case compound_condition_1.CompoundConditionType:
|
|
19
26
|
return new compound_condition_1.CompoundCondition(props);
|
|
27
|
+
case sequential_1.SequentialConditionType:
|
|
28
|
+
return new sequential_1.SequentialCondition(props);
|
|
29
|
+
case if_then_else_condition_1.IfThenElseConditionType:
|
|
30
|
+
return new if_then_else_condition_1.IfThenElseCondition(props);
|
|
20
31
|
default:
|
|
21
32
|
throw new Error(ERR_INVALID_CONDITION_TYPE(props.conditionType));
|
|
22
33
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"condition-factory.js","sourceRoot":"","sources":["../../../src/conditions/condition-factory.ts"],"names":[],"mappings":";;;AAAA,8CAIyB;AACzB,oCAA+E;AAC/E,sCAIqB;AACrB,6DAI8B;
|
|
1
|
+
{"version":3,"file":"condition-factory.js","sourceRoot":"","sources":["../../../src/conditions/condition-factory.ts"],"names":[],"mappings":";;;AAAA,8CAIyB;AACzB,8CAIyB;AACzB,oCAA+E;AAC/E,sCAIqB;AACrB,6DAI8B;AAE9B,qEAIkC;AAClC,6CAIsB;AAEtB,MAAM,0BAA0B,GAAG,CAAC,IAAY,EAAE,EAAE,CAClD,2BAA2B,IAAI,EAAE,CAAC;AAEpC,MAAa,gBAAgB;IACpB,MAAM,CAAC,kBAAkB,CAAC,KAAqB;QACpD,QAAQ,KAAK,CAAC,aAAa,EAAE,CAAC;YAC5B,kBAAkB;YAClB,KAAK,sBAAgB;gBACnB,OAAO,IAAI,kBAAY,CAAC,KAA0B,CAAC,CAAC;YACtD,KAAK,wBAAiB;gBACpB,OAAO,IAAI,oBAAa,CAAC,KAA2B,CAAC,CAAC;YACxD,KAAK,gCAAqB;gBACxB,OAAO,IAAI,4BAAiB,CAAC,KAA+B,CAAC,CAAC;YAChE,KAAK,+BAAoB;gBACvB,OAAO,IAAI,2BAAgB,CAAC,KAA8B,CAAC,CAAC;YAC9D,qBAAqB;YACrB,KAAK,0CAAqB;gBACxB,OAAO,IAAI,sCAAiB,CAAC,KAA+B,CAAC,CAAC;YAChE,KAAK,oCAAuB;gBAC1B,OAAO,IAAI,gCAAmB,CAAC,KAAiC,CAAC,CAAC;YACpE,KAAK,gDAAuB;gBAC1B,OAAO,IAAI,4CAAmB,CAAC,KAAiC,CAAC,CAAC;YACpE;gBACE,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC;QACrE,CAAC;IACH,CAAC;CACF;AAvBD,4CAuBC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
export { baseConditionSchema } from './schemas/common';
|
|
2
3
|
type ConditionSchema = z.ZodSchema;
|
|
3
4
|
export type ConditionProps = z.infer<ConditionSchema>;
|
|
4
5
|
export declare class Condition {
|
|
@@ -14,4 +15,3 @@ export declare class Condition {
|
|
|
14
15
|
toObj(): ConditionProps;
|
|
15
16
|
equals(other: Condition): boolean;
|
|
16
17
|
}
|
|
17
|
-
export {};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Condition = void 0;
|
|
3
|
+
exports.Condition = exports.baseConditionSchema = void 0;
|
|
4
4
|
const shared_1 = require("@nucypher/shared");
|
|
5
5
|
const const_1 = require("./const");
|
|
6
|
+
var common_1 = require("./schemas/common");
|
|
7
|
+
Object.defineProperty(exports, "baseConditionSchema", { enumerable: true, get: function () { return common_1.baseConditionSchema; } });
|
|
6
8
|
const ERR_INVALID_CONDITION = (error) => `Invalid condition: ${JSON.stringify(error.issues)}`;
|
|
7
9
|
class Condition {
|
|
8
10
|
schema;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"condition.js","sourceRoot":"","sources":["../../../src/conditions/condition.ts"],"names":[],"mappings":";;;AAAA,6CAAgD;AAGhD,mCAA8C;
|
|
1
|
+
{"version":3,"file":"condition.js","sourceRoot":"","sources":["../../../src/conditions/condition.ts"],"names":[],"mappings":";;;AAAA,6CAAgD;AAGhD,mCAA8C;AAE9C,2CAAuD;AAA9C,6GAAA,mBAAmB,OAAA;AAK5B,MAAM,qBAAqB,GAAG,CAAC,KAAiB,EAAE,EAAE,CAClD,sBAAsB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;AAEvD,MAAa,SAAS;IAEF;IACA;IAFlB,YACkB,MAAuB,EACvB,KAAqB;QADrB,WAAM,GAAN,MAAM,CAAiB;QACvB,UAAK,GAAL,KAAK,CAAgB;QAErC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAC1D,IAAI,KAAK,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAC,CAAC;QAChD,CAAC;QACD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAEM,MAAM,CAAC,QAAQ,CACpB,MAAuB,EACvB,KAAqB;QAKrB,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QACvC,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YACnB,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;QAC/B,CAAC;QACD,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC;IACjC,CAAC;IAED,8CAA8C;IACvC,2BAA2B;QAChC,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC9C,KAAK,MAAM,KAAK,IAAI,2BAAmB,EAAE,CAAC;YACxC,IAAI,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC/B,OAAO,KAAK,CAAC;YACf,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,sBAAsB;QAC3B,OAAO,OAAO,CAAC,IAAI,CAAC,2BAA2B,EAAE,CAAC,CAAC;IACrD,CAAC;IAEM,KAAK;QACV,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QACpE,IAAI,KAAK,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAC,CAAC;QAChD,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,MAAM,CAAC,KAAgB;QAC5B,OAAO,IAAA,qBAAY,EAAC,IAAI,CAAC,KAAK,EAAE,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;IACnD,CAAC;CACF;AApDD,8BAoDC"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ChainId } from '@nucypher/shared';
|
|
2
|
-
export declare const USER_ADDRESS_PARAM_EXTERNAL_EIP4361 = ":userAddressExternalEIP4361";
|
|
3
2
|
export declare const CONTEXT_PARAM_REGEXP: RegExp;
|
|
3
|
+
export declare const CONTEXT_PARAM_FULL_MATCH_REGEXP: RegExp;
|
|
4
4
|
export declare const CONTEXT_PARAM_PREFIX = ":";
|
|
5
5
|
export declare const SUPPORTED_CHAIN_IDS: ChainId[];
|
|
6
6
|
export declare const USER_ADDRESS_PARAMS: string[];
|
|
7
|
-
export declare const RESERVED_CONTEXT_PARAMS: string[];
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.USER_ADDRESS_PARAMS = exports.SUPPORTED_CHAIN_IDS = exports.CONTEXT_PARAM_PREFIX = exports.CONTEXT_PARAM_FULL_MATCH_REGEXP = exports.CONTEXT_PARAM_REGEXP = void 0;
|
|
4
4
|
const shared_1 = require("@nucypher/shared");
|
|
5
5
|
const taco_auth_1 = require("@nucypher/taco-auth");
|
|
6
|
-
exports.USER_ADDRESS_PARAM_EXTERNAL_EIP4361 = ':userAddressExternalEIP4361';
|
|
7
6
|
// Only allow alphanumeric characters and underscores
|
|
8
|
-
|
|
7
|
+
const contextParamRegexString = ':[a-zA-Z_][a-zA-Z0-9_]*';
|
|
8
|
+
exports.CONTEXT_PARAM_REGEXP = new RegExp(contextParamRegexString);
|
|
9
|
+
// Entire string is context param
|
|
10
|
+
exports.CONTEXT_PARAM_FULL_MATCH_REGEXP = new RegExp(`^${contextParamRegexString}$`);
|
|
9
11
|
exports.CONTEXT_PARAM_PREFIX = ':';
|
|
10
12
|
exports.SUPPORTED_CHAIN_IDS = [
|
|
11
13
|
shared_1.ChainId.POLYGON,
|
|
@@ -14,12 +16,8 @@ exports.SUPPORTED_CHAIN_IDS = [
|
|
|
14
16
|
shared_1.ChainId.ETHEREUM_MAINNET,
|
|
15
17
|
];
|
|
16
18
|
exports.USER_ADDRESS_PARAMS = [
|
|
17
|
-
|
|
19
|
+
taco_auth_1.USER_ADDRESS_PARAM_EXTERNAL_EIP4361,
|
|
18
20
|
// Ordering matters, this should always be last
|
|
19
21
|
taco_auth_1.USER_ADDRESS_PARAM_DEFAULT,
|
|
20
22
|
];
|
|
21
|
-
exports.RESERVED_CONTEXT_PARAMS = [
|
|
22
|
-
taco_auth_1.USER_ADDRESS_PARAM_DEFAULT,
|
|
23
|
-
// USER_ADDRESS_PARAM_EXTERNAL_EIP4361 is not reserved and can be used as a custom context parameter
|
|
24
|
-
];
|
|
25
23
|
//# sourceMappingURL=const.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"const.js","sourceRoot":"","sources":["../../../src/conditions/const.ts"],"names":[],"mappings":";;;AAAA,6CAA2C;AAC3C,
|
|
1
|
+
{"version":3,"file":"const.js","sourceRoot":"","sources":["../../../src/conditions/const.ts"],"names":[],"mappings":";;;AAAA,6CAA2C;AAC3C,mDAG6B;AAE7B,qDAAqD;AACrD,MAAM,uBAAuB,GAAG,yBAAyB,CAAC;AAE7C,QAAA,oBAAoB,GAAG,IAAI,MAAM,CAAC,uBAAuB,CAAC,CAAC;AAExE,iCAAiC;AACpB,QAAA,+BAA+B,GAAG,IAAI,MAAM,CACvD,IAAI,uBAAuB,GAAG,CAC/B,CAAC;AAEW,QAAA,oBAAoB,GAAG,GAAG,CAAC;AAE3B,QAAA,mBAAmB,GAAG;IACjC,gBAAO,CAAC,OAAO;IACf,gBAAO,CAAC,IAAI;IACZ,gBAAO,CAAC,OAAO;IACf,gBAAO,CAAC,gBAAgB;CACzB,CAAC;AAEW,QAAA,mBAAmB,GAAG;IACjC,+CAAmC;IACnC,+CAA+C;IAC/C,sCAA0B;CAC3B,CAAC"}
|
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
import { ThresholdMessageKit } from '@nucypher/nucypher-core';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { Condition
|
|
5
|
-
export type CustomContextParam = string | number | boolean
|
|
2
|
+
import { AuthProvider, AuthSignature } from '@nucypher/taco-auth';
|
|
3
|
+
import { CoreContext } from '../../types';
|
|
4
|
+
import { Condition } from '../condition';
|
|
5
|
+
export type CustomContextParam = string | number | boolean;
|
|
6
6
|
export type ContextParam = CustomContextParam | AuthSignature;
|
|
7
|
+
export declare const RESERVED_CONTEXT_PARAMS: string[];
|
|
7
8
|
export declare class ConditionContext {
|
|
8
|
-
|
|
9
|
-
private
|
|
10
|
-
|
|
11
|
-
constructor(condition: Condition
|
|
12
|
-
private
|
|
13
|
-
private validateCoreConditions;
|
|
9
|
+
requestedContextParameters: Set<string>;
|
|
10
|
+
private customContextParameters;
|
|
11
|
+
private authProviders;
|
|
12
|
+
constructor(condition: Condition);
|
|
13
|
+
private static validateCoreConditions;
|
|
14
14
|
private validateNoMissingContextParameters;
|
|
15
15
|
private fillContextParameters;
|
|
16
16
|
private validateAuthProviders;
|
|
17
17
|
private fillAuthContextParameters;
|
|
18
|
+
private validateCustomContextParameter;
|
|
18
19
|
private static isContextParameter;
|
|
19
|
-
static findContextParameters
|
|
20
|
+
private static findContextParameters;
|
|
21
|
+
addCustomContextParameterValues(customContextParameters: Record<string, CustomContextParam>): void;
|
|
22
|
+
addAuthProvider(contextParam: string, authProvider: AuthProvider): void;
|
|
20
23
|
toJson(): Promise<string>;
|
|
21
24
|
toCoreContext(): Promise<CoreContext>;
|
|
22
25
|
toContextParameters: () => Promise<Record<string, ContextParam>>;
|
|
23
|
-
static
|
|
24
|
-
static requestedContextParameters(messageKit: ThresholdMessageKit): Set<string>;
|
|
26
|
+
static fromMessageKit(messageKit: ThresholdMessageKit): ConditionContext;
|
|
25
27
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ConditionContext = void 0;
|
|
3
|
+
exports.ConditionContext = exports.RESERVED_CONTEXT_PARAMS = void 0;
|
|
4
4
|
const shared_1 = require("@nucypher/shared");
|
|
5
5
|
const taco_auth_1 = require("@nucypher/taco-auth");
|
|
6
6
|
const types_1 = require("../../types");
|
|
@@ -11,33 +11,28 @@ const ERR_RESERVED_PARAM = (key) => `Cannot use reserved parameter name ${key} a
|
|
|
11
11
|
const ERR_INVALID_CUSTOM_PARAM = (key) => `Custom parameter ${key} must start with ${const_1.CONTEXT_PARAM_PREFIX}`;
|
|
12
12
|
const ERR_AUTH_PROVIDER_REQUIRED = (key) => `No matching authentication provider to satisfy ${key} context variable in condition`;
|
|
13
13
|
const ERR_MISSING_CONTEXT_PARAMS = (params) => `Missing custom context parameter(s): ${params.join(', ')}`;
|
|
14
|
-
const
|
|
15
|
-
const
|
|
14
|
+
const ERR_UNKNOWN_CUSTOM_CONTEXT_PARAM = (param) => `Unknown custom context parameter: ${param}`;
|
|
15
|
+
const ERR_INVALID_AUTH_PROVIDER_TYPE = (param, expected) => `Invalid AuthProvider type for ${param}; expected ${expected}`;
|
|
16
|
+
const ERR_AUTH_PROVIDER_NOT_NEEDED_FOR_CONTEXT_PARAM = (param) => `AuthProvider not necessary for context parameter: ${param}`;
|
|
17
|
+
const EXPECTED_AUTH_PROVIDER_TYPES = {
|
|
18
|
+
[taco_auth_1.USER_ADDRESS_PARAM_DEFAULT]: taco_auth_1.EIP4361AuthProvider,
|
|
19
|
+
[taco_auth_1.USER_ADDRESS_PARAM_EXTERNAL_EIP4361]: taco_auth_1.SingleSignOnEIP4361AuthProvider,
|
|
20
|
+
};
|
|
21
|
+
exports.RESERVED_CONTEXT_PARAMS = [
|
|
22
|
+
taco_auth_1.USER_ADDRESS_PARAM_EXTERNAL_EIP4361,
|
|
23
|
+
taco_auth_1.USER_ADDRESS_PARAM_DEFAULT,
|
|
24
|
+
];
|
|
16
25
|
class ConditionContext {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
constructor(condition
|
|
21
|
-
this.customParameters = customParameters;
|
|
22
|
-
this.authProviders = authProviders;
|
|
26
|
+
requestedContextParameters;
|
|
27
|
+
customContextParameters = {};
|
|
28
|
+
authProviders = {};
|
|
29
|
+
constructor(condition) {
|
|
23
30
|
const condProps = condition.toObj();
|
|
24
|
-
|
|
25
|
-
this.
|
|
26
|
-
this.requestedParameters =
|
|
31
|
+
ConditionContext.validateCoreConditions(condProps);
|
|
32
|
+
this.requestedContextParameters =
|
|
27
33
|
ConditionContext.findContextParameters(condProps);
|
|
28
|
-
this.validateAuthProviders(this.requestedParameters);
|
|
29
34
|
}
|
|
30
|
-
|
|
31
|
-
Object.keys(this.customParameters).forEach((key) => {
|
|
32
|
-
if (const_1.RESERVED_CONTEXT_PARAMS.includes(key)) {
|
|
33
|
-
throw new Error(ERR_RESERVED_PARAM(key));
|
|
34
|
-
}
|
|
35
|
-
if (!key.startsWith(const_1.CONTEXT_PARAM_PREFIX)) {
|
|
36
|
-
throw new Error(ERR_INVALID_CUSTOM_PARAM(key));
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
validateCoreConditions(condObject) {
|
|
35
|
+
static validateCoreConditions(condObject) {
|
|
41
36
|
// Checking whether the condition is compatible with the current version of the library
|
|
42
37
|
// Intentionally ignoring the return value of the function
|
|
43
38
|
new types_1.CoreConditions((0, shared_1.toJSON)(condObject));
|
|
@@ -45,56 +40,54 @@ class ConditionContext {
|
|
|
45
40
|
validateNoMissingContextParameters(parameters) {
|
|
46
41
|
// Ok, so at this point we should have all the parameters we need
|
|
47
42
|
// If we don't, we have a problem and we should throw
|
|
48
|
-
const missingParameters = Array.from(this.
|
|
43
|
+
const missingParameters = Array.from(this.requestedContextParameters).filter((key) => parameters[key] === undefined);
|
|
49
44
|
if (missingParameters.length > 0) {
|
|
50
45
|
throw new Error(ERR_MISSING_CONTEXT_PARAMS(missingParameters));
|
|
51
46
|
}
|
|
52
|
-
// We may also have some parameters that are not used
|
|
53
|
-
const unknownParameters = Object.keys(parameters).filter((key) => !this.requestedParameters.has(key) &&
|
|
54
|
-
!const_1.RESERVED_CONTEXT_PARAMS.includes(key));
|
|
55
|
-
if (unknownParameters.length > 0) {
|
|
56
|
-
throw new Error(ERR_UNKNOWN_CONTEXT_PARAMS(unknownParameters));
|
|
57
|
-
}
|
|
58
47
|
}
|
|
59
|
-
async fillContextParameters(
|
|
60
|
-
const parameters = await this.fillAuthContextParameters(
|
|
61
|
-
for (const key in this.
|
|
62
|
-
parameters[key] = this.
|
|
48
|
+
async fillContextParameters(requestedContextParameters) {
|
|
49
|
+
const parameters = await this.fillAuthContextParameters(requestedContextParameters);
|
|
50
|
+
for (const key in this.customContextParameters) {
|
|
51
|
+
parameters[key] = this.customContextParameters[key];
|
|
63
52
|
}
|
|
64
53
|
return parameters;
|
|
65
54
|
}
|
|
66
|
-
validateAuthProviders(
|
|
67
|
-
for (const param of
|
|
55
|
+
validateAuthProviders() {
|
|
56
|
+
for (const param of this.requestedContextParameters) {
|
|
68
57
|
// If it's not a user address parameter, we can skip
|
|
69
58
|
if (!const_1.USER_ADDRESS_PARAMS.includes(param)) {
|
|
70
59
|
continue;
|
|
71
60
|
}
|
|
72
|
-
//
|
|
73
|
-
|
|
74
|
-
if (!authMethod && !this.customParameters[param]) {
|
|
75
|
-
// If we don't have an auth method, and we don't have a custom parameter, we have a problem
|
|
76
|
-
throw new Error(ERR_NO_AUTH_PROVIDER_FOR_PARAM(param));
|
|
77
|
-
}
|
|
78
|
-
// If we have an auth method, but we don't have an auth provider, we have a problem
|
|
79
|
-
if (authMethod && !this.authProviders[authMethod]) {
|
|
61
|
+
// we don't have a corresponding auth provider, we have a problem
|
|
62
|
+
if (!this.authProviders[param]) {
|
|
80
63
|
throw new Error(ERR_AUTH_PROVIDER_REQUIRED(param));
|
|
81
64
|
}
|
|
82
65
|
}
|
|
83
66
|
}
|
|
84
67
|
async fillAuthContextParameters(requestedParameters) {
|
|
85
68
|
const entries = await Promise.all([...requestedParameters]
|
|
86
|
-
.
|
|
87
|
-
.
|
|
88
|
-
.
|
|
89
|
-
const maybeAuthProvider = this.authProviders[authMethod];
|
|
69
|
+
.filter((param) => const_1.USER_ADDRESS_PARAMS.includes(param))
|
|
70
|
+
.map(async (param) => {
|
|
71
|
+
const maybeAuthProvider = this.authProviders[param];
|
|
90
72
|
// TODO: Throw here instead of validating in the constructor?
|
|
91
73
|
// TODO: Hide getOrCreateAuthSignature behind a more generic interface
|
|
92
74
|
return [param, await maybeAuthProvider.getOrCreateAuthSignature()];
|
|
93
75
|
}));
|
|
94
76
|
return Object.fromEntries(entries);
|
|
95
77
|
}
|
|
78
|
+
validateCustomContextParameter(customParam) {
|
|
79
|
+
if (!ConditionContext.isContextParameter(customParam)) {
|
|
80
|
+
throw new Error(ERR_INVALID_CUSTOM_PARAM(customParam));
|
|
81
|
+
}
|
|
82
|
+
if (exports.RESERVED_CONTEXT_PARAMS.includes(customParam)) {
|
|
83
|
+
throw new Error(ERR_RESERVED_PARAM(customParam));
|
|
84
|
+
}
|
|
85
|
+
if (!this.requestedContextParameters.has(customParam)) {
|
|
86
|
+
throw new Error(ERR_UNKNOWN_CUSTOM_CONTEXT_PARAM(customParam));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
96
89
|
static isContextParameter(param) {
|
|
97
|
-
return !!String(param).match(const_1.
|
|
90
|
+
return !!String(param).match(const_1.CONTEXT_PARAM_FULL_MATCH_REGEXP);
|
|
98
91
|
}
|
|
99
92
|
static findContextParameters(condition) {
|
|
100
93
|
// First, we want to find all the parameters we need to add
|
|
@@ -134,6 +127,21 @@ class ConditionContext {
|
|
|
134
127
|
}
|
|
135
128
|
return requestedParameters;
|
|
136
129
|
}
|
|
130
|
+
addCustomContextParameterValues(customContextParameters) {
|
|
131
|
+
Object.keys(customContextParameters).forEach((key) => {
|
|
132
|
+
this.validateCustomContextParameter(key);
|
|
133
|
+
this.customContextParameters[key] = customContextParameters[key];
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
addAuthProvider(contextParam, authProvider) {
|
|
137
|
+
if (!(contextParam in EXPECTED_AUTH_PROVIDER_TYPES)) {
|
|
138
|
+
throw new Error(ERR_AUTH_PROVIDER_NOT_NEEDED_FOR_CONTEXT_PARAM(contextParam));
|
|
139
|
+
}
|
|
140
|
+
if (!(authProvider instanceof EXPECTED_AUTH_PROVIDER_TYPES[contextParam])) {
|
|
141
|
+
throw new Error(ERR_INVALID_AUTH_PROVIDER_TYPE(contextParam, typeof authProvider));
|
|
142
|
+
}
|
|
143
|
+
this.authProviders[contextParam] = authProvider;
|
|
144
|
+
}
|
|
137
145
|
async toJson() {
|
|
138
146
|
const parameters = await this.toContextParameters();
|
|
139
147
|
return (0, shared_1.toJSON)(parameters);
|
|
@@ -143,16 +151,14 @@ class ConditionContext {
|
|
|
143
151
|
return new types_1.CoreContext(asJson);
|
|
144
152
|
}
|
|
145
153
|
toContextParameters = async () => {
|
|
146
|
-
|
|
154
|
+
this.validateAuthProviders();
|
|
155
|
+
const parameters = await this.fillContextParameters(this.requestedContextParameters);
|
|
147
156
|
this.validateNoMissingContextParameters(parameters);
|
|
148
157
|
return parameters;
|
|
149
158
|
};
|
|
150
|
-
static
|
|
151
|
-
return new ConditionContext(condition_expr_1.ConditionExpression.fromCoreConditions(conditions).condition, customParameters, authProviders);
|
|
152
|
-
}
|
|
153
|
-
static requestedContextParameters(messageKit) {
|
|
159
|
+
static fromMessageKit(messageKit) {
|
|
154
160
|
const conditionExpr = condition_expr_1.ConditionExpression.fromCoreConditions(messageKit.acp.conditions);
|
|
155
|
-
return ConditionContext
|
|
161
|
+
return new ConditionContext(conditionExpr.condition);
|
|
156
162
|
}
|
|
157
163
|
}
|
|
158
164
|
exports.ConditionContext = ConditionContext;
|