@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,47 +1,7 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
1
|
import { Condition } from '../condition';
|
|
2
|
+
import { RpcConditionProps } from '../schemas/rpc';
|
|
3
3
|
import { OmitConditionType } from '../shared';
|
|
4
|
-
export
|
|
5
|
-
export declare const rpcConditionSchema: z.ZodObject<{
|
|
6
|
-
conditionType: z.ZodDefault<z.ZodLiteral<"rpc">>;
|
|
7
|
-
chain: z.ZodNever | z.ZodLiteral<z.Primitive> | z.ZodUnion<[z.ZodLiteral<z.Primitive>, z.ZodLiteral<z.Primitive>, ...z.ZodLiteral<z.Primitive>[]]>;
|
|
8
|
-
method: z.ZodEnum<["eth_getBalance"]>;
|
|
9
|
-
parameters: z.ZodUnion<[z.ZodArray<z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEnum<[":userAddress", ":userAddressExternalEIP4361"]>]>, "atleastone">, z.ZodTuple<[z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEnum<[":userAddress", ":userAddressExternalEIP4361"]>]>, z.ZodType<any, z.ZodTypeDef, any>], null>]>;
|
|
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: "rpc";
|
|
25
|
-
method: "eth_getBalance";
|
|
26
|
-
parameters: [string, ...string[]] | [string, any];
|
|
27
|
-
returnValueTest: {
|
|
28
|
-
comparator: "==" | ">" | "<" | ">=" | "<=" | "!=";
|
|
29
|
-
value?: any;
|
|
30
|
-
index?: number | undefined;
|
|
31
|
-
};
|
|
32
|
-
chain?: z.Primitive;
|
|
33
|
-
}, {
|
|
34
|
-
method: "eth_getBalance";
|
|
35
|
-
parameters: [string, ...string[]] | [string, any];
|
|
36
|
-
returnValueTest: {
|
|
37
|
-
comparator: "==" | ">" | "<" | ">=" | "<=" | "!=";
|
|
38
|
-
value?: any;
|
|
39
|
-
index?: number | undefined;
|
|
40
|
-
};
|
|
41
|
-
conditionType?: "rpc" | undefined;
|
|
42
|
-
chain?: z.Primitive;
|
|
43
|
-
}>;
|
|
44
|
-
export type RpcConditionProps = z.infer<typeof rpcConditionSchema>;
|
|
4
|
+
export { RpcConditionProps, rpcConditionSchema, RpcConditionType, } from '../schemas/rpc';
|
|
45
5
|
export declare class RpcCondition extends Condition {
|
|
46
6
|
constructor(value: OmitConditionType<RpcConditionProps>);
|
|
47
7
|
}
|
|
@@ -1,20 +1,6 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
1
|
import { Condition } from '../condition';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
import createUnionSchema from '../zod';
|
|
6
|
-
export const RpcConditionType = 'rpc';
|
|
7
|
-
export const rpcConditionSchema = z.object({
|
|
8
|
-
conditionType: z.literal(RpcConditionType).default(RpcConditionType),
|
|
9
|
-
chain: createUnionSchema(SUPPORTED_CHAIN_IDS),
|
|
10
|
-
method: z.enum(['eth_getBalance']),
|
|
11
|
-
parameters: z.union([
|
|
12
|
-
z.array(EthAddressOrUserAddressSchema).nonempty(),
|
|
13
|
-
// Using tuple here because ordering matters
|
|
14
|
-
z.tuple([EthAddressOrUserAddressSchema, paramOrContextParamSchema]),
|
|
15
|
-
]),
|
|
16
|
-
returnValueTest: returnValueTestSchema, // Update to allow multiple return values after expanding supported methods
|
|
17
|
-
});
|
|
2
|
+
import { rpcConditionSchema, RpcConditionType, } from '../schemas/rpc';
|
|
3
|
+
export { rpcConditionSchema, RpcConditionType, } from '../schemas/rpc';
|
|
18
4
|
export class RpcCondition extends Condition {
|
|
19
5
|
constructor(value) {
|
|
20
6
|
super(rpcConditionSchema, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rpc.js","sourceRoot":"","sources":["../../../../src/conditions/base/rpc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"rpc.js","sourceRoot":"","sources":["../../../../src/conditions/base/rpc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAEL,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAEL,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,gBAAgB,CAAC;AAExB,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,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,16 +1,6 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
1
|
import { Condition } from '../condition';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
6
|
-
const { parameters: _, ...restShape } = rpcConditionSchema.shape;
|
|
7
|
-
export const TimeConditionType = 'time';
|
|
8
|
-
export const TimeConditionMethod = 'blocktime';
|
|
9
|
-
export const timeConditionSchema = z.object({
|
|
10
|
-
...restShape,
|
|
11
|
-
conditionType: z.literal(TimeConditionType).default(TimeConditionType),
|
|
12
|
-
method: z.literal(TimeConditionMethod).default(TimeConditionMethod),
|
|
13
|
-
});
|
|
2
|
+
import { timeConditionSchema, TimeConditionType, } from '../schemas/time';
|
|
3
|
+
export { TimeConditionMethod, timeConditionSchema, TimeConditionType, } from '../schemas/time';
|
|
14
4
|
export class TimeCondition extends Condition {
|
|
15
5
|
constructor(value) {
|
|
16
6
|
super(timeConditionSchema, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time.js","sourceRoot":"","sources":["../../../../src/conditions/base/time.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"time.js","sourceRoot":"","sources":["../../../../src/conditions/base/time.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAEL,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,mBAAmB,EAEnB,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AAEzB,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,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,39 +1,6 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { contractConditionSchema } from './base/contract';
|
|
3
|
-
import { rpcConditionSchema } from './base/rpc';
|
|
4
|
-
import { timeConditionSchema } from './base/time';
|
|
5
1
|
import { Condition } from './condition';
|
|
6
|
-
|
|
7
|
-
export
|
|
8
|
-
.object({
|
|
9
|
-
conditionType: z
|
|
10
|
-
.literal(CompoundConditionType)
|
|
11
|
-
.default(CompoundConditionType),
|
|
12
|
-
operator: z.enum(['and', 'or', 'not']),
|
|
13
|
-
operands: z
|
|
14
|
-
.array(z.lazy(() => z.union([
|
|
15
|
-
rpcConditionSchema,
|
|
16
|
-
timeConditionSchema,
|
|
17
|
-
contractConditionSchema,
|
|
18
|
-
compoundConditionSchema,
|
|
19
|
-
])))
|
|
20
|
-
.min(1),
|
|
21
|
-
})
|
|
22
|
-
.refine((condition) => {
|
|
23
|
-
// 'and' and 'or' operators must have at least 2 operands
|
|
24
|
-
if (['and', 'or'].includes(condition.operator)) {
|
|
25
|
-
return condition.operands.length >= 2;
|
|
26
|
-
}
|
|
27
|
-
// 'not' operator must have exactly 1 operand
|
|
28
|
-
if (condition.operator === 'not') {
|
|
29
|
-
return condition.operands.length === 1;
|
|
30
|
-
}
|
|
31
|
-
// We test positive cases exhaustively, so we return false here:
|
|
32
|
-
return false;
|
|
33
|
-
}, ({ operands, operator }) => ({
|
|
34
|
-
message: `Invalid number of operands ${operands.length} for operator "${operator}"`,
|
|
35
|
-
path: ['operands'],
|
|
36
|
-
}));
|
|
2
|
+
import { compoundConditionSchema, CompoundConditionType, } from './schemas/compound';
|
|
3
|
+
export { compoundConditionSchema, CompoundConditionType, } from './schemas/compound';
|
|
37
4
|
export class CompoundCondition extends Condition {
|
|
38
5
|
constructor(value) {
|
|
39
6
|
super(compoundConditionSchema, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compound-condition.js","sourceRoot":"","sources":["../../../src/conditions/compound-condition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"compound-condition.js","sourceRoot":"","sources":["../../../src/conditions/compound-condition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAkB,MAAM,aAAa,CAAC;AACxD,OAAO,EAEL,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAEL,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,oBAAoB,CAAC;AAI5B,MAAM,OAAO,iBAAkB,SAAQ,SAAS;IAC9C,YAAY,KAAgD;QAC1D,KAAK,CAAC,uBAAuB,EAAE;YAC7B,aAAa,EAAE,qBAAqB;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,SAAS,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"}
|
|
@@ -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
|
}
|
|
@@ -2,7 +2,6 @@ import { Conditions as CoreConditions } from '@nucypher/nucypher-core';
|
|
|
2
2
|
import { toJSON } from '@nucypher/shared';
|
|
3
3
|
import { SemVer } from 'semver';
|
|
4
4
|
import { ConditionFactory } from './condition-factory';
|
|
5
|
-
import { ConditionContext } from './context';
|
|
6
5
|
const ERR_VERSION = (provided, current) => `Version provided, ${provided}, is incompatible with current version, ${current}`;
|
|
7
6
|
const ERR_CONDITION = (condition) => `Invalid condition: unrecognized condition data ${JSON.stringify(condition)}`;
|
|
8
7
|
export class ConditionExpression {
|
|
@@ -44,9 +43,6 @@ export class ConditionExpression {
|
|
|
44
43
|
static fromCoreConditions(conditions) {
|
|
45
44
|
return ConditionExpression.fromJSON(conditions.toString());
|
|
46
45
|
}
|
|
47
|
-
buildContext(customParameters = {}, authProviders = {}) {
|
|
48
|
-
return new ConditionContext(this.condition, customParameters, authProviders);
|
|
49
|
-
}
|
|
50
46
|
equals(other) {
|
|
51
47
|
return [
|
|
52
48
|
this.version === other.version,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"condition-expr.js","sourceRoot":"","sources":["../../../src/conditions/condition-expr.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,IAAI,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"condition-expr.js","sourceRoot":"","sources":["../../../src/conditions/condition-expr.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,IAAI,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;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,MAAM,OAAO,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,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAChD,MAAM,cAAc,GAAG,IAAI,MAAM,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,gBAAgB,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,MAAM,CAAC,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,cAAc,CAAC,MAAM,CAAC,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"}
|
|
@@ -1,19 +1,30 @@
|
|
|
1
1
|
import { ContractCondition, ContractConditionType, } from './base/contract';
|
|
2
|
+
import { JsonApiCondition, JsonApiConditionType, } from './base/json-api';
|
|
2
3
|
import { RpcCondition, RpcConditionType } from './base/rpc';
|
|
3
4
|
import { TimeCondition, TimeConditionType, } from './base/time';
|
|
4
5
|
import { CompoundCondition, CompoundConditionType, } from './compound-condition';
|
|
6
|
+
import { IfThenElseCondition, IfThenElseConditionType, } from './if-then-else-condition';
|
|
7
|
+
import { SequentialCondition, SequentialConditionType, } from './sequential';
|
|
5
8
|
const ERR_INVALID_CONDITION_TYPE = (type) => `Invalid condition type: ${type}`;
|
|
6
9
|
export class ConditionFactory {
|
|
7
10
|
static conditionFromProps(props) {
|
|
8
11
|
switch (props.conditionType) {
|
|
12
|
+
// Base Conditions
|
|
9
13
|
case RpcConditionType:
|
|
10
14
|
return new RpcCondition(props);
|
|
11
15
|
case TimeConditionType:
|
|
12
16
|
return new TimeCondition(props);
|
|
13
17
|
case ContractConditionType:
|
|
14
18
|
return new ContractCondition(props);
|
|
19
|
+
case JsonApiConditionType:
|
|
20
|
+
return new JsonApiCondition(props);
|
|
21
|
+
// Logical Conditions
|
|
15
22
|
case CompoundConditionType:
|
|
16
23
|
return new CompoundCondition(props);
|
|
24
|
+
case SequentialConditionType:
|
|
25
|
+
return new SequentialCondition(props);
|
|
26
|
+
case IfThenElseConditionType:
|
|
27
|
+
return new IfThenElseCondition(props);
|
|
17
28
|
default:
|
|
18
29
|
throw new Error(ERR_INVALID_CONDITION_TYPE(props.conditionType));
|
|
19
30
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"condition-factory.js","sourceRoot":"","sources":["../../../src/conditions/condition-factory.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EAEjB,qBAAqB,GACtB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,YAAY,EAAqB,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC/E,OAAO,EACL,aAAa,EAEb,iBAAiB,GAClB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,iBAAiB,EAEjB,qBAAqB,GACtB,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"condition-factory.js","sourceRoot":"","sources":["../../../src/conditions/condition-factory.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EAEjB,qBAAqB,GACtB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,gBAAgB,EAEhB,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,YAAY,EAAqB,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC/E,OAAO,EACL,aAAa,EAEb,iBAAiB,GAClB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,iBAAiB,EAEjB,qBAAqB,GACtB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,mBAAmB,EAEnB,uBAAuB,GACxB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,mBAAmB,EAEnB,uBAAuB,GACxB,MAAM,cAAc,CAAC;AAEtB,MAAM,0BAA0B,GAAG,CAAC,IAAY,EAAE,EAAE,CAClD,2BAA2B,IAAI,EAAE,CAAC;AAEpC,MAAM,OAAO,gBAAgB;IACpB,MAAM,CAAC,kBAAkB,CAAC,KAAqB;QACpD,QAAQ,KAAK,CAAC,aAAa,EAAE,CAAC;YAC5B,kBAAkB;YAClB,KAAK,gBAAgB;gBACnB,OAAO,IAAI,YAAY,CAAC,KAA0B,CAAC,CAAC;YACtD,KAAK,iBAAiB;gBACpB,OAAO,IAAI,aAAa,CAAC,KAA2B,CAAC,CAAC;YACxD,KAAK,qBAAqB;gBACxB,OAAO,IAAI,iBAAiB,CAAC,KAA+B,CAAC,CAAC;YAChE,KAAK,oBAAoB;gBACvB,OAAO,IAAI,gBAAgB,CAAC,KAA8B,CAAC,CAAC;YAC9D,qBAAqB;YACrB,KAAK,qBAAqB;gBACxB,OAAO,IAAI,iBAAiB,CAAC,KAA+B,CAAC,CAAC;YAChE,KAAK,uBAAuB;gBAC1B,OAAO,IAAI,mBAAmB,CAAC,KAAiC,CAAC,CAAC;YACpE,KAAK,uBAAuB;gBAC1B,OAAO,IAAI,mBAAmB,CAAC,KAAiC,CAAC,CAAC;YACpE;gBACE,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC;QACrE,CAAC;IACH,CAAC;CACF"}
|
|
@@ -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,5 +1,6 @@
|
|
|
1
1
|
import { objectEquals } from '@nucypher/shared';
|
|
2
2
|
import { USER_ADDRESS_PARAMS } from './const';
|
|
3
|
+
export { baseConditionSchema } from './schemas/common';
|
|
3
4
|
const ERR_INVALID_CONDITION = (error) => `Invalid condition: ${JSON.stringify(error.issues)}`;
|
|
4
5
|
export class Condition {
|
|
5
6
|
schema;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"condition.js","sourceRoot":"","sources":["../../../src/conditions/condition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGhD,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"condition.js","sourceRoot":"","sources":["../../../src/conditions/condition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGhD,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAKvD,MAAM,qBAAqB,GAAG,CAAC,KAAiB,EAAE,EAAE,CAClD,sBAAsB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;AAEvD,MAAM,OAAO,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,mBAAmB,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,YAAY,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;IACnD,CAAC;CACF"}
|
|
@@ -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,8 +1,10 @@
|
|
|
1
1
|
import { ChainId } from '@nucypher/shared';
|
|
2
|
-
import { USER_ADDRESS_PARAM_DEFAULT } from '@nucypher/taco-auth';
|
|
3
|
-
export const USER_ADDRESS_PARAM_EXTERNAL_EIP4361 = ':userAddressExternalEIP4361';
|
|
2
|
+
import { USER_ADDRESS_PARAM_DEFAULT, USER_ADDRESS_PARAM_EXTERNAL_EIP4361, } from '@nucypher/taco-auth';
|
|
4
3
|
// Only allow alphanumeric characters and underscores
|
|
5
|
-
|
|
4
|
+
const contextParamRegexString = ':[a-zA-Z_][a-zA-Z0-9_]*';
|
|
5
|
+
export const CONTEXT_PARAM_REGEXP = new RegExp(contextParamRegexString);
|
|
6
|
+
// Entire string is context param
|
|
7
|
+
export const CONTEXT_PARAM_FULL_MATCH_REGEXP = new RegExp(`^${contextParamRegexString}$`);
|
|
6
8
|
export const CONTEXT_PARAM_PREFIX = ':';
|
|
7
9
|
export const SUPPORTED_CHAIN_IDS = [
|
|
8
10
|
ChainId.POLYGON,
|
|
@@ -15,8 +17,4 @@ export const USER_ADDRESS_PARAMS = [
|
|
|
15
17
|
// Ordering matters, this should always be last
|
|
16
18
|
USER_ADDRESS_PARAM_DEFAULT,
|
|
17
19
|
];
|
|
18
|
-
export const RESERVED_CONTEXT_PARAMS = [
|
|
19
|
-
USER_ADDRESS_PARAM_DEFAULT,
|
|
20
|
-
// USER_ADDRESS_PARAM_EXTERNAL_EIP4361 is not reserved and can be used as a custom context parameter
|
|
21
|
-
];
|
|
22
20
|
//# sourceMappingURL=const.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"const.js","sourceRoot":"","sources":["../../../src/conditions/const.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,
|
|
1
|
+
{"version":3,"file":"const.js","sourceRoot":"","sources":["../../../src/conditions/const.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EACL,0BAA0B,EAC1B,mCAAmC,GACpC,MAAM,qBAAqB,CAAC;AAE7B,qDAAqD;AACrD,MAAM,uBAAuB,GAAG,yBAAyB,CAAC;AAE1D,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,MAAM,CAAC,uBAAuB,CAAC,CAAC;AAExE,iCAAiC;AACjC,MAAM,CAAC,MAAM,+BAA+B,GAAG,IAAI,MAAM,CACvD,IAAI,uBAAuB,GAAG,CAC/B,CAAC;AAEF,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,CAAC;AAExC,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,IAAI;IACZ,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,gBAAgB;CACzB,CAAC;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,mCAAmC;IACnC,+CAA+C;IAC/C,0BAA0B;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,40 +1,35 @@
|
|
|
1
1
|
import { toJSON } from '@nucypher/shared';
|
|
2
|
-
import {
|
|
2
|
+
import { EIP4361AuthProvider, SingleSignOnEIP4361AuthProvider, USER_ADDRESS_PARAM_DEFAULT, USER_ADDRESS_PARAM_EXTERNAL_EIP4361, } from '@nucypher/taco-auth';
|
|
3
3
|
import { CoreConditions, CoreContext } from '../../types';
|
|
4
4
|
import { CompoundConditionType } from '../compound-condition';
|
|
5
5
|
import { ConditionExpression } from '../condition-expr';
|
|
6
|
-
import {
|
|
6
|
+
import { CONTEXT_PARAM_FULL_MATCH_REGEXP, CONTEXT_PARAM_PREFIX, USER_ADDRESS_PARAMS, } from '../const';
|
|
7
7
|
const ERR_RESERVED_PARAM = (key) => `Cannot use reserved parameter name ${key} as custom parameter`;
|
|
8
8
|
const ERR_INVALID_CUSTOM_PARAM = (key) => `Custom parameter ${key} must start with ${CONTEXT_PARAM_PREFIX}`;
|
|
9
9
|
const ERR_AUTH_PROVIDER_REQUIRED = (key) => `No matching authentication provider to satisfy ${key} context variable in condition`;
|
|
10
10
|
const ERR_MISSING_CONTEXT_PARAMS = (params) => `Missing custom context parameter(s): ${params.join(', ')}`;
|
|
11
|
-
const
|
|
12
|
-
const
|
|
11
|
+
const ERR_UNKNOWN_CUSTOM_CONTEXT_PARAM = (param) => `Unknown custom context parameter: ${param}`;
|
|
12
|
+
const ERR_INVALID_AUTH_PROVIDER_TYPE = (param, expected) => `Invalid AuthProvider type for ${param}; expected ${expected}`;
|
|
13
|
+
const ERR_AUTH_PROVIDER_NOT_NEEDED_FOR_CONTEXT_PARAM = (param) => `AuthProvider not necessary for context parameter: ${param}`;
|
|
14
|
+
const EXPECTED_AUTH_PROVIDER_TYPES = {
|
|
15
|
+
[USER_ADDRESS_PARAM_DEFAULT]: EIP4361AuthProvider,
|
|
16
|
+
[USER_ADDRESS_PARAM_EXTERNAL_EIP4361]: SingleSignOnEIP4361AuthProvider,
|
|
17
|
+
};
|
|
18
|
+
export const RESERVED_CONTEXT_PARAMS = [
|
|
19
|
+
USER_ADDRESS_PARAM_EXTERNAL_EIP4361,
|
|
20
|
+
USER_ADDRESS_PARAM_DEFAULT,
|
|
21
|
+
];
|
|
13
22
|
export class ConditionContext {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
constructor(condition
|
|
18
|
-
this.customParameters = customParameters;
|
|
19
|
-
this.authProviders = authProviders;
|
|
23
|
+
requestedContextParameters;
|
|
24
|
+
customContextParameters = {};
|
|
25
|
+
authProviders = {};
|
|
26
|
+
constructor(condition) {
|
|
20
27
|
const condProps = condition.toObj();
|
|
21
|
-
|
|
22
|
-
this.
|
|
23
|
-
this.requestedParameters =
|
|
28
|
+
ConditionContext.validateCoreConditions(condProps);
|
|
29
|
+
this.requestedContextParameters =
|
|
24
30
|
ConditionContext.findContextParameters(condProps);
|
|
25
|
-
this.validateAuthProviders(this.requestedParameters);
|
|
26
31
|
}
|
|
27
|
-
|
|
28
|
-
Object.keys(this.customParameters).forEach((key) => {
|
|
29
|
-
if (RESERVED_CONTEXT_PARAMS.includes(key)) {
|
|
30
|
-
throw new Error(ERR_RESERVED_PARAM(key));
|
|
31
|
-
}
|
|
32
|
-
if (!key.startsWith(CONTEXT_PARAM_PREFIX)) {
|
|
33
|
-
throw new Error(ERR_INVALID_CUSTOM_PARAM(key));
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
validateCoreConditions(condObject) {
|
|
32
|
+
static validateCoreConditions(condObject) {
|
|
38
33
|
// Checking whether the condition is compatible with the current version of the library
|
|
39
34
|
// Intentionally ignoring the return value of the function
|
|
40
35
|
new CoreConditions(toJSON(condObject));
|
|
@@ -42,56 +37,54 @@ export class ConditionContext {
|
|
|
42
37
|
validateNoMissingContextParameters(parameters) {
|
|
43
38
|
// Ok, so at this point we should have all the parameters we need
|
|
44
39
|
// If we don't, we have a problem and we should throw
|
|
45
|
-
const missingParameters = Array.from(this.
|
|
40
|
+
const missingParameters = Array.from(this.requestedContextParameters).filter((key) => parameters[key] === undefined);
|
|
46
41
|
if (missingParameters.length > 0) {
|
|
47
42
|
throw new Error(ERR_MISSING_CONTEXT_PARAMS(missingParameters));
|
|
48
43
|
}
|
|
49
|
-
// We may also have some parameters that are not used
|
|
50
|
-
const unknownParameters = Object.keys(parameters).filter((key) => !this.requestedParameters.has(key) &&
|
|
51
|
-
!RESERVED_CONTEXT_PARAMS.includes(key));
|
|
52
|
-
if (unknownParameters.length > 0) {
|
|
53
|
-
throw new Error(ERR_UNKNOWN_CONTEXT_PARAMS(unknownParameters));
|
|
54
|
-
}
|
|
55
44
|
}
|
|
56
|
-
async fillContextParameters(
|
|
57
|
-
const parameters = await this.fillAuthContextParameters(
|
|
58
|
-
for (const key in this.
|
|
59
|
-
parameters[key] = this.
|
|
45
|
+
async fillContextParameters(requestedContextParameters) {
|
|
46
|
+
const parameters = await this.fillAuthContextParameters(requestedContextParameters);
|
|
47
|
+
for (const key in this.customContextParameters) {
|
|
48
|
+
parameters[key] = this.customContextParameters[key];
|
|
60
49
|
}
|
|
61
50
|
return parameters;
|
|
62
51
|
}
|
|
63
|
-
validateAuthProviders(
|
|
64
|
-
for (const param of
|
|
52
|
+
validateAuthProviders() {
|
|
53
|
+
for (const param of this.requestedContextParameters) {
|
|
65
54
|
// If it's not a user address parameter, we can skip
|
|
66
55
|
if (!USER_ADDRESS_PARAMS.includes(param)) {
|
|
67
56
|
continue;
|
|
68
57
|
}
|
|
69
|
-
//
|
|
70
|
-
|
|
71
|
-
if (!authMethod && !this.customParameters[param]) {
|
|
72
|
-
// If we don't have an auth method, and we don't have a custom parameter, we have a problem
|
|
73
|
-
throw new Error(ERR_NO_AUTH_PROVIDER_FOR_PARAM(param));
|
|
74
|
-
}
|
|
75
|
-
// If we have an auth method, but we don't have an auth provider, we have a problem
|
|
76
|
-
if (authMethod && !this.authProviders[authMethod]) {
|
|
58
|
+
// we don't have a corresponding auth provider, we have a problem
|
|
59
|
+
if (!this.authProviders[param]) {
|
|
77
60
|
throw new Error(ERR_AUTH_PROVIDER_REQUIRED(param));
|
|
78
61
|
}
|
|
79
62
|
}
|
|
80
63
|
}
|
|
81
64
|
async fillAuthContextParameters(requestedParameters) {
|
|
82
65
|
const entries = await Promise.all([...requestedParameters]
|
|
83
|
-
.
|
|
84
|
-
.
|
|
85
|
-
.
|
|
86
|
-
const maybeAuthProvider = this.authProviders[authMethod];
|
|
66
|
+
.filter((param) => USER_ADDRESS_PARAMS.includes(param))
|
|
67
|
+
.map(async (param) => {
|
|
68
|
+
const maybeAuthProvider = this.authProviders[param];
|
|
87
69
|
// TODO: Throw here instead of validating in the constructor?
|
|
88
70
|
// TODO: Hide getOrCreateAuthSignature behind a more generic interface
|
|
89
71
|
return [param, await maybeAuthProvider.getOrCreateAuthSignature()];
|
|
90
72
|
}));
|
|
91
73
|
return Object.fromEntries(entries);
|
|
92
74
|
}
|
|
75
|
+
validateCustomContextParameter(customParam) {
|
|
76
|
+
if (!ConditionContext.isContextParameter(customParam)) {
|
|
77
|
+
throw new Error(ERR_INVALID_CUSTOM_PARAM(customParam));
|
|
78
|
+
}
|
|
79
|
+
if (RESERVED_CONTEXT_PARAMS.includes(customParam)) {
|
|
80
|
+
throw new Error(ERR_RESERVED_PARAM(customParam));
|
|
81
|
+
}
|
|
82
|
+
if (!this.requestedContextParameters.has(customParam)) {
|
|
83
|
+
throw new Error(ERR_UNKNOWN_CUSTOM_CONTEXT_PARAM(customParam));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
93
86
|
static isContextParameter(param) {
|
|
94
|
-
return !!String(param).match(
|
|
87
|
+
return !!String(param).match(CONTEXT_PARAM_FULL_MATCH_REGEXP);
|
|
95
88
|
}
|
|
96
89
|
static findContextParameters(condition) {
|
|
97
90
|
// First, we want to find all the parameters we need to add
|
|
@@ -131,6 +124,21 @@ export class ConditionContext {
|
|
|
131
124
|
}
|
|
132
125
|
return requestedParameters;
|
|
133
126
|
}
|
|
127
|
+
addCustomContextParameterValues(customContextParameters) {
|
|
128
|
+
Object.keys(customContextParameters).forEach((key) => {
|
|
129
|
+
this.validateCustomContextParameter(key);
|
|
130
|
+
this.customContextParameters[key] = customContextParameters[key];
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
addAuthProvider(contextParam, authProvider) {
|
|
134
|
+
if (!(contextParam in EXPECTED_AUTH_PROVIDER_TYPES)) {
|
|
135
|
+
throw new Error(ERR_AUTH_PROVIDER_NOT_NEEDED_FOR_CONTEXT_PARAM(contextParam));
|
|
136
|
+
}
|
|
137
|
+
if (!(authProvider instanceof EXPECTED_AUTH_PROVIDER_TYPES[contextParam])) {
|
|
138
|
+
throw new Error(ERR_INVALID_AUTH_PROVIDER_TYPE(contextParam, typeof authProvider));
|
|
139
|
+
}
|
|
140
|
+
this.authProviders[contextParam] = authProvider;
|
|
141
|
+
}
|
|
134
142
|
async toJson() {
|
|
135
143
|
const parameters = await this.toContextParameters();
|
|
136
144
|
return toJSON(parameters);
|
|
@@ -140,16 +148,14 @@ export class ConditionContext {
|
|
|
140
148
|
return new CoreContext(asJson);
|
|
141
149
|
}
|
|
142
150
|
toContextParameters = async () => {
|
|
143
|
-
|
|
151
|
+
this.validateAuthProviders();
|
|
152
|
+
const parameters = await this.fillContextParameters(this.requestedContextParameters);
|
|
144
153
|
this.validateNoMissingContextParameters(parameters);
|
|
145
154
|
return parameters;
|
|
146
155
|
};
|
|
147
|
-
static
|
|
148
|
-
return new ConditionContext(ConditionExpression.fromCoreConditions(conditions).condition, customParameters, authProviders);
|
|
149
|
-
}
|
|
150
|
-
static requestedContextParameters(messageKit) {
|
|
156
|
+
static fromMessageKit(messageKit) {
|
|
151
157
|
const conditionExpr = ConditionExpression.fromCoreConditions(messageKit.acp.conditions);
|
|
152
|
-
return ConditionContext
|
|
158
|
+
return new ConditionContext(conditionExpr.condition);
|
|
153
159
|
}
|
|
154
160
|
}
|
|
155
161
|
//# sourceMappingURL=context.js.map
|