@nucypher/taco 0.1.0-rc.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/LICENSE +675 -0
- package/README.md +3 -0
- package/dist/cjs/conditions/base/contract.d.ts +428 -0
- package/dist/cjs/conditions/base/contract.js +76 -0
- package/dist/cjs/conditions/base/contract.js.map +1 -0
- package/dist/cjs/conditions/base/index.d.ts +21 -0
- package/dist/cjs/conditions/base/index.js +42 -0
- package/dist/cjs/conditions/base/index.js.map +1 -0
- package/dist/cjs/conditions/base/rpc.d.ts +42 -0
- package/dist/cjs/conditions/base/rpc.js +23 -0
- package/dist/cjs/conditions/base/rpc.js.map +1 -0
- package/dist/cjs/conditions/base/shared.d.ts +16 -0
- package/dist/cjs/conditions/base/shared.js +17 -0
- package/dist/cjs/conditions/base/shared.js.map +1 -0
- package/dist/cjs/conditions/base/time.d.ts +40 -0
- package/dist/cjs/conditions/base/time.js +16 -0
- package/dist/cjs/conditions/base/time.js.map +1 -0
- package/dist/cjs/conditions/compound-condition.d.ts +4 -0
- package/dist/cjs/conditions/compound-condition.js +23 -0
- package/dist/cjs/conditions/compound-condition.js.map +1 -0
- package/dist/cjs/conditions/condition-expr.d.ts +23 -0
- package/dist/cjs/conditions/condition-expr.js +62 -0
- package/dist/cjs/conditions/condition-expr.js.map +1 -0
- package/dist/cjs/conditions/condition.d.ts +17 -0
- package/dist/cjs/conditions/condition.js +61 -0
- package/dist/cjs/conditions/condition.js.map +1 -0
- package/dist/cjs/conditions/const.d.ts +4 -0
- package/dist/cjs/conditions/const.js +13 -0
- package/dist/cjs/conditions/const.js.map +1 -0
- package/dist/cjs/conditions/context/context.d.ts +24 -0
- package/dist/cjs/conditions/context/context.js +113 -0
- package/dist/cjs/conditions/context/context.js.map +1 -0
- package/dist/cjs/conditions/context/index.d.ts +1 -0
- package/dist/cjs/conditions/context/index.js +6 -0
- package/dist/cjs/conditions/context/index.js.map +1 -0
- package/dist/cjs/conditions/context/providers.d.ts +16 -0
- package/dist/cjs/conditions/context/providers.js +109 -0
- package/dist/cjs/conditions/context/providers.js.map +1 -0
- package/dist/cjs/conditions/index.d.ts +9 -0
- package/dist/cjs/conditions/index.js +44 -0
- package/dist/cjs/conditions/index.js.map +1 -0
- package/dist/cjs/conditions/predefined/erc721.d.ts +10 -0
- package/dist/cjs/conditions/predefined/erc721.js +39 -0
- package/dist/cjs/conditions/predefined/erc721.js.map +1 -0
- package/dist/cjs/conditions/predefined/index.d.ts +1 -0
- package/dist/cjs/conditions/predefined/index.js +7 -0
- package/dist/cjs/conditions/predefined/index.js.map +1 -0
- package/dist/cjs/conditions/zod.d.ts +3 -0
- package/dist/cjs/conditions/zod.js +19 -0
- package/dist/cjs/conditions/zod.js.map +1 -0
- package/dist/cjs/dkg.d.ts +27 -0
- package/dist/cjs/dkg.js +85 -0
- package/dist/cjs/dkg.js.map +1 -0
- package/dist/cjs/index.d.ts +4 -0
- package/dist/cjs/index.js +39 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/porter.d.ts +4 -0
- package/dist/cjs/porter.js +22 -0
- package/dist/cjs/porter.js.map +1 -0
- package/dist/cjs/taco.d.ts +7 -0
- package/dist/cjs/taco.js +47 -0
- package/dist/cjs/taco.js.map +1 -0
- package/dist/cjs/tdec.d.ts +5 -0
- package/dist/cjs/tdec.js +61 -0
- package/dist/cjs/tdec.js.map +1 -0
- package/dist/cjs/web3.d.ts +33 -0
- package/dist/cjs/web3.js +3 -0
- package/dist/cjs/web3.js.map +1 -0
- package/dist/es/conditions/base/contract.d.ts +428 -0
- package/dist/es/conditions/base/contract.js +73 -0
- package/dist/es/conditions/base/contract.js.map +1 -0
- package/dist/es/conditions/base/index.d.ts +21 -0
- package/dist/es/conditions/base/index.js +31 -0
- package/dist/es/conditions/base/index.js.map +1 -0
- package/dist/es/conditions/base/rpc.d.ts +42 -0
- package/dist/es/conditions/base/rpc.js +17 -0
- package/dist/es/conditions/base/rpc.js.map +1 -0
- package/dist/es/conditions/base/shared.d.ts +16 -0
- package/dist/es/conditions/base/shared.js +14 -0
- package/dist/es/conditions/base/shared.js.map +1 -0
- package/dist/es/conditions/base/time.d.ts +40 -0
- package/dist/es/conditions/base/time.js +13 -0
- package/dist/es/conditions/base/time.js.map +1 -0
- package/dist/es/conditions/compound-condition.d.ts +4 -0
- package/dist/es/conditions/compound-condition.js +20 -0
- package/dist/es/conditions/compound-condition.js.map +1 -0
- package/dist/es/conditions/condition-expr.d.ts +23 -0
- package/dist/es/conditions/condition-expr.js +58 -0
- package/dist/es/conditions/condition-expr.js.map +1 -0
- package/dist/es/conditions/condition.d.ts +17 -0
- package/dist/es/conditions/condition.js +57 -0
- package/dist/es/conditions/condition.js.map +1 -0
- package/dist/es/conditions/const.d.ts +4 -0
- package/dist/es/conditions/const.js +10 -0
- package/dist/es/conditions/const.js.map +1 -0
- package/dist/es/conditions/context/context.d.ts +24 -0
- package/dist/es/conditions/context/context.js +109 -0
- package/dist/es/conditions/context/context.js.map +1 -0
- package/dist/es/conditions/context/index.d.ts +1 -0
- package/dist/es/conditions/context/index.js +2 -0
- package/dist/es/conditions/context/index.js.map +1 -0
- package/dist/es/conditions/context/providers.d.ts +16 -0
- package/dist/es/conditions/context/providers.js +105 -0
- package/dist/es/conditions/context/providers.js.map +1 -0
- package/dist/es/conditions/index.d.ts +9 -0
- package/dist/es/conditions/index.js +10 -0
- package/dist/es/conditions/index.js.map +1 -0
- package/dist/es/conditions/predefined/erc721.d.ts +10 -0
- package/dist/es/conditions/predefined/erc721.js +34 -0
- package/dist/es/conditions/predefined/erc721.js.map +1 -0
- package/dist/es/conditions/predefined/index.d.ts +1 -0
- package/dist/es/conditions/predefined/index.js +2 -0
- package/dist/es/conditions/predefined/index.js.map +1 -0
- package/dist/es/conditions/zod.d.ts +3 -0
- package/dist/es/conditions/zod.js +17 -0
- package/dist/es/conditions/zod.js.map +1 -0
- package/dist/es/dkg.d.ts +27 -0
- package/dist/es/dkg.js +80 -0
- package/dist/es/dkg.js.map +1 -0
- package/dist/es/index.d.ts +4 -0
- package/dist/es/index.js +5 -0
- package/dist/es/index.js.map +1 -0
- package/dist/es/porter.d.ts +4 -0
- package/dist/es/porter.js +14 -0
- package/dist/es/porter.js.map +1 -0
- package/dist/es/taco.d.ts +7 -0
- package/dist/es/taco.js +40 -0
- package/dist/es/taco.js.map +1 -0
- package/dist/es/tdec.d.ts +5 -0
- package/dist/es/tdec.js +56 -0
- package/dist/es/tdec.js.map +1 -0
- package/dist/es/web3.d.ts +33 -0
- package/dist/es/web3.js +2 -0
- package/dist/es/web3.js.map +1 -0
- package/dist/tsconfig.cjs.tsbuildinfo +1 -0
- package/dist/tsconfig.es.tsbuildinfo +1 -0
- package/package.json +58 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../../src/conditions/base/shared.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAExB,oCAAkE;AAErD,QAAA,qBAAqB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC5C,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC5B,UAAU,EAAE,OAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IACtD,KAAK,EAAE,OAAC,CAAC,OAAO,EAAE;CACnB,CAAC,CAAC;AAIH,MAAM,gBAAgB,GAAG,OAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,0BAAkB,CAAC,CAAC;AAC9D,MAAM,iBAAiB,GAAG,OAAC,CAAC,OAAO,CAAC,0BAAkB,CAAC,CAAC;AAC3C,QAAA,6BAA6B,GAAG,OAAC,CAAC,KAAK,CAAC;IACnD,gBAAgB;IAChB,iBAAiB;CAClB,CAAC,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const TimeConditionType = "time";
|
|
3
|
+
export declare const TimeConditionMethod = "blocktime";
|
|
4
|
+
export declare const timeConditionSchema: z.ZodObject<{
|
|
5
|
+
conditionType: z.ZodDefault<z.ZodLiteral<"time">>;
|
|
6
|
+
method: z.ZodDefault<z.ZodLiteral<"blocktime">>;
|
|
7
|
+
chain: z.ZodNever | z.ZodLiteral<z.Primitive> | z.ZodUnion<[z.ZodLiteral<z.Primitive>, z.ZodLiteral<z.Primitive>, ...z.ZodLiteral<z.Primitive>[]]>;
|
|
8
|
+
returnValueTest: z.ZodObject<{
|
|
9
|
+
index: z.ZodOptional<z.ZodNumber>;
|
|
10
|
+
comparator: z.ZodEnum<["==", ">", "<", ">=", "<=", "!="]>;
|
|
11
|
+
value: z.ZodUnknown;
|
|
12
|
+
}, "strip", z.ZodTypeAny, {
|
|
13
|
+
comparator: "==" | ">" | "<" | ">=" | "<=" | "!=";
|
|
14
|
+
index?: number | undefined;
|
|
15
|
+
value?: unknown;
|
|
16
|
+
}, {
|
|
17
|
+
comparator: "==" | ">" | "<" | ">=" | "<=" | "!=";
|
|
18
|
+
index?: number | undefined;
|
|
19
|
+
value?: unknown;
|
|
20
|
+
}>;
|
|
21
|
+
}, "strip", z.ZodTypeAny, {
|
|
22
|
+
conditionType: "time";
|
|
23
|
+
method: "blocktime";
|
|
24
|
+
returnValueTest: {
|
|
25
|
+
comparator: "==" | ">" | "<" | ">=" | "<=" | "!=";
|
|
26
|
+
index?: number | undefined;
|
|
27
|
+
value?: unknown;
|
|
28
|
+
};
|
|
29
|
+
chain?: z.Primitive;
|
|
30
|
+
}, {
|
|
31
|
+
returnValueTest: {
|
|
32
|
+
comparator: "==" | ">" | "<" | ">=" | "<=" | "!=";
|
|
33
|
+
index?: number | undefined;
|
|
34
|
+
value?: unknown;
|
|
35
|
+
};
|
|
36
|
+
conditionType?: "time" | undefined;
|
|
37
|
+
method?: "blocktime" | undefined;
|
|
38
|
+
chain?: z.Primitive;
|
|
39
|
+
}>;
|
|
40
|
+
export type TimeConditionProps = z.infer<typeof timeConditionSchema>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.timeConditionSchema = exports.TimeConditionMethod = exports.TimeConditionType = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const rpc_1 = require("./rpc");
|
|
6
|
+
// TimeCondition is an RpcCondition with the method set to 'blocktime' and no parameters
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
8
|
+
const { parameters: _, ...restShape } = rpc_1.rpcConditionSchema.shape;
|
|
9
|
+
exports.TimeConditionType = 'time';
|
|
10
|
+
exports.TimeConditionMethod = 'blocktime';
|
|
11
|
+
exports.timeConditionSchema = zod_1.z.object({
|
|
12
|
+
...restShape,
|
|
13
|
+
conditionType: zod_1.z.literal(exports.TimeConditionType).default(exports.TimeConditionType),
|
|
14
|
+
method: zod_1.z.literal(exports.TimeConditionMethod).default(exports.TimeConditionMethod),
|
|
15
|
+
});
|
|
16
|
+
//# sourceMappingURL=time.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"time.js","sourceRoot":"","sources":["../../../../src/conditions/base/time.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAExB,+BAA2C;AAE3C,wFAAwF;AACxF,6DAA6D;AAC7D,MAAM,EAAE,UAAU,EAAE,CAAC,EAAE,GAAG,SAAS,EAAE,GAAG,wBAAkB,CAAC,KAAK,CAAC;AAEpD,QAAA,iBAAiB,GAAG,MAAM,CAAC;AAC3B,QAAA,mBAAmB,GAAG,WAAW,CAAC;AAElC,QAAA,mBAAmB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC1C,GAAG,SAAS;IACZ,aAAa,EAAE,OAAC,CAAC,OAAO,CAAC,yBAAiB,CAAC,CAAC,OAAO,CAAC,yBAAiB,CAAC;IACtE,MAAM,EAAE,OAAC,CAAC,OAAO,CAAC,2BAAmB,CAAC,CAAC,OAAO,CAAC,2BAAmB,CAAC;CACpE,CAAC,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.compoundConditionSchema = exports.CompoundConditionType = void 0;
|
|
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");
|
|
8
|
+
exports.CompoundConditionType = 'compound';
|
|
9
|
+
exports.compoundConditionSchema = zod_1.z.object({
|
|
10
|
+
conditionType: zod_1.z
|
|
11
|
+
.literal(exports.CompoundConditionType)
|
|
12
|
+
.default(exports.CompoundConditionType),
|
|
13
|
+
operator: zod_1.z.enum(['and', 'or']),
|
|
14
|
+
operands: zod_1.z
|
|
15
|
+
.array(zod_1.z.lazy(() => zod_1.z.union([
|
|
16
|
+
rpc_1.rpcConditionSchema,
|
|
17
|
+
time_1.timeConditionSchema,
|
|
18
|
+
contract_1.contractConditionSchema,
|
|
19
|
+
exports.compoundConditionSchema,
|
|
20
|
+
])))
|
|
21
|
+
.min(2),
|
|
22
|
+
});
|
|
23
|
+
//# sourceMappingURL=compound-condition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compound-condition.js","sourceRoot":"","sources":["../../../src/conditions/compound-condition.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAExB,8CAA0D;AAC1D,oCAAgD;AAChD,sCAAkD;AAErC,QAAA,qBAAqB,GAAG,UAAU,CAAC;AAEnC,QAAA,uBAAuB,GAAgB,OAAC,CAAC,MAAM,CAAC;IAC3D,aAAa,EAAE,OAAC;SACb,OAAO,CAAC,6BAAqB,CAAC;SAC9B,OAAO,CAAC,6BAAqB,CAAC;IACjC,QAAQ,EAAE,OAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC/B,QAAQ,EAAE,OAAC;SACR,KAAK,CACJ,OAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CACV,OAAC,CAAC,KAAK,CAAC;QACN,wBAAkB;QAClB,0BAAmB;QACnB,kCAAuB;QACvB,+BAAuB;KACxB,CAAC,CACH,CACF;SACA,GAAG,CAAC,CAAC,CAAC;CACV,CAAC,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Conditions as WASMConditions } from '@nucypher/nucypher-core';
|
|
2
|
+
import { ethers } from 'ethers';
|
|
3
|
+
import { Condition } from './condition';
|
|
4
|
+
import { ConditionContext, CustomContextParam } from './context';
|
|
5
|
+
export type ConditionExpressionJSON = {
|
|
6
|
+
version: string;
|
|
7
|
+
condition: Record<string, unknown>;
|
|
8
|
+
};
|
|
9
|
+
export declare class ConditionExpression {
|
|
10
|
+
readonly condition: Condition;
|
|
11
|
+
readonly version: string;
|
|
12
|
+
static version: string;
|
|
13
|
+
constructor(condition: Condition, version?: string);
|
|
14
|
+
toObj(): ConditionExpressionJSON;
|
|
15
|
+
static fromObj(obj: ConditionExpressionJSON): ConditionExpression;
|
|
16
|
+
toJson(): string;
|
|
17
|
+
static fromJSON(json: string): ConditionExpression;
|
|
18
|
+
toWASMConditions(): WASMConditions;
|
|
19
|
+
static fromWASMConditions(conditions: WASMConditions): ConditionExpression;
|
|
20
|
+
buildContext(provider: ethers.providers.Provider, customParameters?: Record<string, CustomContextParam>, signer?: ethers.Signer): ConditionContext;
|
|
21
|
+
contextRequiresSigner(): boolean;
|
|
22
|
+
equals(other: ConditionExpression): boolean;
|
|
23
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConditionExpression = void 0;
|
|
4
|
+
const nucypher_core_1 = require("@nucypher/nucypher-core");
|
|
5
|
+
const shared_1 = require("@nucypher/shared");
|
|
6
|
+
const semver_1 = require("semver");
|
|
7
|
+
const condition_1 = require("./condition");
|
|
8
|
+
const context_1 = require("./context");
|
|
9
|
+
class ConditionExpression {
|
|
10
|
+
condition;
|
|
11
|
+
version;
|
|
12
|
+
static version = '1.0.0';
|
|
13
|
+
constructor(condition, version = ConditionExpression.version) {
|
|
14
|
+
this.condition = condition;
|
|
15
|
+
this.version = version;
|
|
16
|
+
}
|
|
17
|
+
toObj() {
|
|
18
|
+
const condition = this.condition.toObj();
|
|
19
|
+
return {
|
|
20
|
+
version: this.version,
|
|
21
|
+
condition,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
static fromObj(obj) {
|
|
25
|
+
const receivedVersion = new semver_1.SemVer(obj.version);
|
|
26
|
+
const currentVersion = new semver_1.SemVer(ConditionExpression.version);
|
|
27
|
+
if (receivedVersion.major > currentVersion.major) {
|
|
28
|
+
throw new Error(`Version provided, ${obj.version}, is incompatible with current version, ${ConditionExpression.version}`);
|
|
29
|
+
}
|
|
30
|
+
if (!obj.condition) {
|
|
31
|
+
throw new Error(`Invalid condition: unrecognized condition data ${JSON.stringify(obj.condition)}`);
|
|
32
|
+
}
|
|
33
|
+
const condition = condition_1.Condition.fromObj(obj.condition);
|
|
34
|
+
return new ConditionExpression(condition, obj.version);
|
|
35
|
+
}
|
|
36
|
+
toJson() {
|
|
37
|
+
return (0, shared_1.toJSON)(this.toObj());
|
|
38
|
+
}
|
|
39
|
+
static fromJSON(json) {
|
|
40
|
+
return ConditionExpression.fromObj(JSON.parse(json));
|
|
41
|
+
}
|
|
42
|
+
toWASMConditions() {
|
|
43
|
+
return new nucypher_core_1.Conditions((0, shared_1.toJSON)(this.toObj()));
|
|
44
|
+
}
|
|
45
|
+
static fromWASMConditions(conditions) {
|
|
46
|
+
return ConditionExpression.fromJSON(conditions.toString());
|
|
47
|
+
}
|
|
48
|
+
buildContext(provider, customParameters = {}, signer) {
|
|
49
|
+
return new context_1.ConditionContext(provider, [this.condition], customParameters, signer);
|
|
50
|
+
}
|
|
51
|
+
contextRequiresSigner() {
|
|
52
|
+
return this.condition.requiresSigner();
|
|
53
|
+
}
|
|
54
|
+
equals(other) {
|
|
55
|
+
return [
|
|
56
|
+
this.version === other.version,
|
|
57
|
+
this.condition.equals(other.condition),
|
|
58
|
+
].every(Boolean);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.ConditionExpression = ConditionExpression;
|
|
62
|
+
//# sourceMappingURL=condition-expr.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"condition-expr.js","sourceRoot":"","sources":["../../../src/conditions/condition-expr.ts"],"names":[],"mappings":";;;AAAA,2DAAuE;AACvE,6CAA0C;AAE1C,mCAAgC;AAEhC,2CAAwC;AACxC,uCAAiE;AAOjE,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;YAChD,MAAM,IAAI,KAAK,CACb,qBAAqB,GAAG,CAAC,OAAO,2CAA2C,mBAAmB,CAAC,OAAO,EAAE,CACzG,CAAC;SACH;QAED,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE;YAClB,MAAM,IAAI,KAAK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,17 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
type ConditionSchema = z.ZodSchema;
|
|
3
|
+
export type ConditionProps = z.infer<ConditionSchema>;
|
|
4
|
+
export declare class Condition {
|
|
5
|
+
readonly schema: ConditionSchema;
|
|
6
|
+
readonly value: ConditionProps;
|
|
7
|
+
constructor(schema: ConditionSchema, value: ConditionProps);
|
|
8
|
+
static validate(schema: ConditionSchema, value: ConditionProps): {
|
|
9
|
+
data?: ConditionProps;
|
|
10
|
+
error?: z.ZodError;
|
|
11
|
+
};
|
|
12
|
+
requiresSigner(): boolean;
|
|
13
|
+
toObj(): any;
|
|
14
|
+
static fromObj(obj: ConditionProps): Condition;
|
|
15
|
+
equals(other: Condition): boolean;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Condition = void 0;
|
|
4
|
+
const shared_1 = require("@nucypher/shared");
|
|
5
|
+
const base_1 = require("./base");
|
|
6
|
+
const compound_condition_1 = require("./compound-condition");
|
|
7
|
+
const const_1 = require("./const");
|
|
8
|
+
class ConditionFactory {
|
|
9
|
+
static conditionFromProps(obj) {
|
|
10
|
+
switch (obj.conditionType) {
|
|
11
|
+
case base_1.RpcConditionType:
|
|
12
|
+
return new base_1.RpcCondition(obj);
|
|
13
|
+
case base_1.TimeConditionType:
|
|
14
|
+
return new base_1.TimeCondition(obj);
|
|
15
|
+
case base_1.ContractConditionType:
|
|
16
|
+
return new base_1.ContractCondition(obj);
|
|
17
|
+
case compound_condition_1.CompoundConditionType:
|
|
18
|
+
return new base_1.CompoundCondition(obj);
|
|
19
|
+
default:
|
|
20
|
+
throw new Error(`Invalid conditionType: ${obj.conditionType}`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
class Condition {
|
|
25
|
+
schema;
|
|
26
|
+
value;
|
|
27
|
+
constructor(schema, value) {
|
|
28
|
+
this.schema = schema;
|
|
29
|
+
this.value = value;
|
|
30
|
+
const { data, error } = Condition.validate(schema, value);
|
|
31
|
+
if (error) {
|
|
32
|
+
throw new Error(`Invalid condition: ${JSON.stringify(error.issues)}`);
|
|
33
|
+
}
|
|
34
|
+
this.value = data;
|
|
35
|
+
}
|
|
36
|
+
static validate(schema, value) {
|
|
37
|
+
const result = schema.safeParse(value);
|
|
38
|
+
if (result.success) {
|
|
39
|
+
return { data: result.data };
|
|
40
|
+
}
|
|
41
|
+
return { error: result.error };
|
|
42
|
+
}
|
|
43
|
+
requiresSigner() {
|
|
44
|
+
return JSON.stringify(this.value).includes(const_1.USER_ADDRESS_PARAM);
|
|
45
|
+
}
|
|
46
|
+
toObj() {
|
|
47
|
+
const { data, error } = Condition.validate(this.schema, this.value);
|
|
48
|
+
if (error) {
|
|
49
|
+
throw new Error(`Invalid condition: ${JSON.stringify(error.issues)}`);
|
|
50
|
+
}
|
|
51
|
+
return data;
|
|
52
|
+
}
|
|
53
|
+
static fromObj(obj) {
|
|
54
|
+
return ConditionFactory.conditionFromProps(obj);
|
|
55
|
+
}
|
|
56
|
+
equals(other) {
|
|
57
|
+
return (0, shared_1.objectEquals)(this.toObj(), other.toObj());
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.Condition = Condition;
|
|
61
|
+
//# sourceMappingURL=condition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"condition.js","sourceRoot":"","sources":["../../../src/conditions/condition.ts"],"names":[],"mappings":";;;AAAA,6CAAgD;AAGhD,iCAWgB;AAChB,6DAG8B;AAC9B,mCAA6C;AAK7C,MAAM,gBAAgB;IACb,MAAM,CAAC,kBAAkB,CAAC,GAAmB;QAClD,QAAQ,GAAG,CAAC,aAAa,EAAE;YACzB,KAAK,uBAAgB;gBACnB,OAAO,IAAI,mBAAY,CAAC,GAAwB,CAAC,CAAC;YACpD,KAAK,wBAAiB;gBACpB,OAAO,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AAI,CAAC,KAAK,CAAC,CAAC;QACpE,IAAI,KAAK,EAAE;YACT,MAAM,IAAI,KAAK,CAAC,sBAAsB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;SACvE;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,MAAM,CAAC,OAAO,CAAC,GAAmB;QACvC,OAAO,gBAAgB,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC;IAClD,CAAC;IAEM,MAAM,CAAC,KAAgB;QAC5B,OAAO,IAAA,qBAAY,EAAC,IAAI,CAAC,KAAK,EAAE,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;IACnD,CAAC;CACF;AA7CD,8BA6CC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SUPPORTED_CHAIN_IDS = exports.ETH_ADDRESS_REGEXP = exports.USER_ADDRESS_PARAM = void 0;
|
|
4
|
+
const shared_1 = require("@nucypher/shared");
|
|
5
|
+
exports.USER_ADDRESS_PARAM = ':userAddress';
|
|
6
|
+
exports.ETH_ADDRESS_REGEXP = new RegExp('^0x[a-fA-F0-9]{40}$');
|
|
7
|
+
exports.SUPPORTED_CHAIN_IDS = [
|
|
8
|
+
shared_1.ChainId.POLYGON,
|
|
9
|
+
shared_1.ChainId.MUMBAI,
|
|
10
|
+
shared_1.ChainId.GOERLI,
|
|
11
|
+
shared_1.ChainId.MAINNET,
|
|
12
|
+
];
|
|
13
|
+
//# sourceMappingURL=const.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"const.js","sourceRoot":"","sources":["../../../src/conditions/const.ts"],"names":[],"mappings":";;;AAAA,6CAA2C;AAE9B,QAAA,kBAAkB,GAAG,cAAc,CAAC;AAEpC,QAAA,kBAAkB,GAAG,IAAI,MAAM,CAAC,qBAAqB,CAAC,CAAC;AAEvD,QAAA,mBAAmB,GAAG;IACjC,gBAAO,CAAC,OAAO;IACf,gBAAO,CAAC,MAAM;IACd,gBAAO,CAAC,MAAM;IACd,gBAAO,CAAC,OAAO;CAChB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Context, Conditions as WASMConditions } from '@nucypher/nucypher-core';
|
|
2
|
+
import { ethers } from 'ethers';
|
|
3
|
+
import { Condition } from '../condition';
|
|
4
|
+
import { TypedSignature } from './providers';
|
|
5
|
+
export type CustomContextParam = string | number | boolean;
|
|
6
|
+
export type ContextParam = CustomContextParam | TypedSignature;
|
|
7
|
+
export declare const RESERVED_CONTEXT_PARAMS: string[];
|
|
8
|
+
export declare const CONTEXT_PARAM_PREFIX = ":";
|
|
9
|
+
export declare class ConditionContext {
|
|
10
|
+
private readonly provider;
|
|
11
|
+
private readonly conditions;
|
|
12
|
+
readonly customParameters: Record<string, CustomContextParam>;
|
|
13
|
+
private readonly signer?;
|
|
14
|
+
private readonly walletAuthProvider?;
|
|
15
|
+
constructor(provider: ethers.providers.Provider, conditions: ReadonlyArray<Condition>, customParameters?: Record<string, CustomContextParam>, signer?: ethers.Signer | undefined);
|
|
16
|
+
private validate;
|
|
17
|
+
toObj: () => Promise<Record<string, ContextParam>>;
|
|
18
|
+
private fillContextParameters;
|
|
19
|
+
private findRequestedParameters;
|
|
20
|
+
toJson(): Promise<string>;
|
|
21
|
+
withCustomParams(params: Record<string, CustomContextParam>): ConditionContext;
|
|
22
|
+
toWASMContext(): Promise<Context>;
|
|
23
|
+
static fromConditions(provider: ethers.providers.Provider, conditions: WASMConditions, signer?: ethers.Signer): ConditionContext;
|
|
24
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConditionContext = exports.CONTEXT_PARAM_PREFIX = exports.RESERVED_CONTEXT_PARAMS = void 0;
|
|
4
|
+
const nucypher_core_1 = require("@nucypher/nucypher-core");
|
|
5
|
+
const shared_1 = require("@nucypher/shared");
|
|
6
|
+
const condition_expr_1 = require("../condition-expr");
|
|
7
|
+
const const_1 = require("../const");
|
|
8
|
+
const providers_1 = require("./providers");
|
|
9
|
+
exports.RESERVED_CONTEXT_PARAMS = [const_1.USER_ADDRESS_PARAM];
|
|
10
|
+
exports.CONTEXT_PARAM_PREFIX = ':';
|
|
11
|
+
class ConditionContext {
|
|
12
|
+
provider;
|
|
13
|
+
conditions;
|
|
14
|
+
customParameters;
|
|
15
|
+
signer;
|
|
16
|
+
walletAuthProvider;
|
|
17
|
+
constructor(provider, conditions, customParameters = {}, signer) {
|
|
18
|
+
this.provider = provider;
|
|
19
|
+
this.conditions = conditions;
|
|
20
|
+
this.customParameters = customParameters;
|
|
21
|
+
this.signer = signer;
|
|
22
|
+
if (this.signer) {
|
|
23
|
+
this.walletAuthProvider = new providers_1.WalletAuthenticationProvider(this.provider, this.signer);
|
|
24
|
+
}
|
|
25
|
+
this.validate();
|
|
26
|
+
}
|
|
27
|
+
validate() {
|
|
28
|
+
Object.keys(this.customParameters).forEach((key) => {
|
|
29
|
+
if (exports.RESERVED_CONTEXT_PARAMS.includes(key)) {
|
|
30
|
+
throw new Error(`Cannot use reserved parameter name ${key} as custom parameter`);
|
|
31
|
+
}
|
|
32
|
+
if (!key.startsWith(exports.CONTEXT_PARAM_PREFIX)) {
|
|
33
|
+
throw new Error(`Custom parameter ${key} must start with ${exports.CONTEXT_PARAM_PREFIX}`);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
const conditionRequiresSigner = this.conditions.some((c) => c.requiresSigner());
|
|
37
|
+
if (conditionRequiresSigner && !this.signer) {
|
|
38
|
+
throw new Error(`Signer required to satisfy ${const_1.USER_ADDRESS_PARAM} context variable in condition`);
|
|
39
|
+
}
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
toObj = async () => {
|
|
43
|
+
const requestedParameters = this.findRequestedParameters();
|
|
44
|
+
const parameters = await this.fillContextParameters(requestedParameters);
|
|
45
|
+
// Ok, so at this point we should have all the parameters we need
|
|
46
|
+
// If we don't, we have a problem and we should throw
|
|
47
|
+
const missingParameters = Array.from(requestedParameters).filter((key) => !parameters[key]);
|
|
48
|
+
if (missingParameters.length > 0) {
|
|
49
|
+
throw new Error(`Missing custom context parameter(s): ${missingParameters.join(', ')}`);
|
|
50
|
+
}
|
|
51
|
+
return parameters;
|
|
52
|
+
};
|
|
53
|
+
async fillContextParameters(requestedParameters) {
|
|
54
|
+
// Now, we can safely add all the parameters
|
|
55
|
+
const parameters = {};
|
|
56
|
+
// Fill in predefined context parameters
|
|
57
|
+
if (requestedParameters.has(const_1.USER_ADDRESS_PARAM)) {
|
|
58
|
+
if (!this.walletAuthProvider) {
|
|
59
|
+
throw new Error(`Condition contains ${const_1.USER_ADDRESS_PARAM} context variable and requires a signer to populate`);
|
|
60
|
+
}
|
|
61
|
+
parameters[const_1.USER_ADDRESS_PARAM] =
|
|
62
|
+
await this.walletAuthProvider.getOrCreateWalletSignature();
|
|
63
|
+
// Remove from requested parameters
|
|
64
|
+
requestedParameters.delete(const_1.USER_ADDRESS_PARAM);
|
|
65
|
+
}
|
|
66
|
+
// Fill in custom parameters
|
|
67
|
+
for (const key in this.customParameters) {
|
|
68
|
+
parameters[key] = this.customParameters[key];
|
|
69
|
+
}
|
|
70
|
+
return parameters;
|
|
71
|
+
}
|
|
72
|
+
findRequestedParameters() {
|
|
73
|
+
// First, we want to find all the parameters we need to add
|
|
74
|
+
const requestedParameters = new Set();
|
|
75
|
+
// Search conditions for parameters
|
|
76
|
+
const conditions = this.conditions.map((cnd) => cnd.toObj());
|
|
77
|
+
const conditionsToCheck = (0, shared_1.fromJSON)(new nucypher_core_1.Conditions((0, shared_1.toJSON)(conditions)).toString());
|
|
78
|
+
for (const cond of conditionsToCheck) {
|
|
79
|
+
// Check return value test
|
|
80
|
+
const rvt = cond.returnValueTest.value;
|
|
81
|
+
if (typeof rvt === 'string' && rvt.startsWith(exports.CONTEXT_PARAM_PREFIX)) {
|
|
82
|
+
requestedParameters.add(rvt);
|
|
83
|
+
}
|
|
84
|
+
// Check condition parameters
|
|
85
|
+
for (const param of cond.parameters ?? []) {
|
|
86
|
+
if (typeof param === 'string' &&
|
|
87
|
+
param.startsWith(exports.CONTEXT_PARAM_PREFIX)) {
|
|
88
|
+
requestedParameters.add(param);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return requestedParameters;
|
|
93
|
+
}
|
|
94
|
+
async toJson() {
|
|
95
|
+
const parameters = await this.toObj();
|
|
96
|
+
return (0, shared_1.toJSON)(parameters);
|
|
97
|
+
}
|
|
98
|
+
withCustomParams(params) {
|
|
99
|
+
return new ConditionContext(this.provider, this.conditions, params, this.signer);
|
|
100
|
+
}
|
|
101
|
+
async toWASMContext() {
|
|
102
|
+
const asJson = await this.toJson();
|
|
103
|
+
return new nucypher_core_1.Context(asJson);
|
|
104
|
+
}
|
|
105
|
+
static fromConditions(provider, conditions, signer) {
|
|
106
|
+
const innerConditions = [
|
|
107
|
+
condition_expr_1.ConditionExpression.fromWASMConditions(conditions).condition,
|
|
108
|
+
];
|
|
109
|
+
return new ConditionContext(provider, innerConditions, {}, signer);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
exports.ConditionContext = ConditionContext;
|
|
113
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../../../src/conditions/context/context.ts"],"names":[],"mappings":";;;AAAA,2DAAgF;AAChF,6CAAoD;AAIpD,sDAAwD;AACxD,oCAA8C;AAE9C,2CAA2E;AAK9D,QAAA,uBAAuB,GAAG,CAAC,0BAAkB,CAAC,CAAC;AAC/C,QAAA,oBAAoB,GAAG,GAAG,CAAC;AAExC,MAAa,gBAAgB;IAIR;IACA;IACD;IACC;IANF,kBAAkB,CAAgC;IAEnE,YACmB,QAAmC,EACnC,UAAo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M,eAAe,GAAG;YACtB,oCAAmB,CAAC,kBAAkB,CAAC,UAAU,CAAC,CAAC,SAAS;SAC7D,CAAC;QACF,OAAO,IAAI,gBAAgB,CAAC,QAAQ,EAAE,eAAe,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC;IACrE,CAAC;CACF;AAlJD,4CAkJC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ConditionContext, type CustomContextParam } from './context';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConditionContext = void 0;
|
|
4
|
+
var context_1 = require("./context");
|
|
5
|
+
Object.defineProperty(exports, "ConditionContext", { enumerable: true, get: function () { return context_1.ConditionContext; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/conditions/context/index.ts"],"names":[],"mappings":";;;AAAA,qCAAsE;AAA7D,2GAAA,gBAAgB,OAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ethers } from 'ethers';
|
|
2
|
+
import { Eip712TypedData } from '../../web3';
|
|
3
|
+
export interface TypedSignature {
|
|
4
|
+
signature: string;
|
|
5
|
+
typedData: Eip712TypedData;
|
|
6
|
+
address: string;
|
|
7
|
+
}
|
|
8
|
+
export declare class WalletAuthenticationProvider {
|
|
9
|
+
private readonly provider;
|
|
10
|
+
private readonly signer;
|
|
11
|
+
private walletSignature?;
|
|
12
|
+
constructor(provider: ethers.providers.Provider, signer: ethers.Signer);
|
|
13
|
+
getOrCreateWalletSignature(): Promise<TypedSignature>;
|
|
14
|
+
private createWalletSignature;
|
|
15
|
+
private getChainData;
|
|
16
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WalletAuthenticationProvider = void 0;
|
|
4
|
+
const ethers_1 = require("ethers/lib/ethers");
|
|
5
|
+
class WalletAuthenticationProvider {
|
|
6
|
+
provider;
|
|
7
|
+
signer;
|
|
8
|
+
walletSignature;
|
|
9
|
+
constructor(provider, signer) {
|
|
10
|
+
this.provider = provider;
|
|
11
|
+
this.signer = signer;
|
|
12
|
+
}
|
|
13
|
+
async getOrCreateWalletSignature() {
|
|
14
|
+
const address = await this.signer.getAddress();
|
|
15
|
+
const storageKey = `wallet-signature-${address}`;
|
|
16
|
+
// If we have a signature in localStorage, return it
|
|
17
|
+
const isLocalStorage = typeof localStorage !== 'undefined';
|
|
18
|
+
if (isLocalStorage) {
|
|
19
|
+
const maybeSignature = localStorage.getItem(storageKey);
|
|
20
|
+
if (maybeSignature) {
|
|
21
|
+
return JSON.parse(maybeSignature);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
// If not, try returning from memory
|
|
25
|
+
const maybeSignature = this.walletSignature?.[address];
|
|
26
|
+
if (maybeSignature) {
|
|
27
|
+
if (isLocalStorage) {
|
|
28
|
+
localStorage.setItem(storageKey, maybeSignature);
|
|
29
|
+
}
|
|
30
|
+
return JSON.parse(maybeSignature);
|
|
31
|
+
}
|
|
32
|
+
// If at this point we didn't return, we need to create a new signature
|
|
33
|
+
const typedSignature = await this.createWalletSignature();
|
|
34
|
+
// Persist where you can
|
|
35
|
+
if (isLocalStorage) {
|
|
36
|
+
localStorage.setItem(storageKey, JSON.stringify(typedSignature));
|
|
37
|
+
}
|
|
38
|
+
if (!this.walletSignature) {
|
|
39
|
+
this.walletSignature = {};
|
|
40
|
+
}
|
|
41
|
+
this.walletSignature[address] = JSON.stringify(typedSignature);
|
|
42
|
+
return typedSignature;
|
|
43
|
+
}
|
|
44
|
+
async createWalletSignature() {
|
|
45
|
+
// Ensure freshness of the signature
|
|
46
|
+
const { blockNumber, blockHash, chainId } = await this.getChainData();
|
|
47
|
+
const address = await this.signer.getAddress();
|
|
48
|
+
const signatureText = `I'm the owner of address ${address} as of block number ${blockNumber}`;
|
|
49
|
+
const salt = ethers_1.utils.hexlify(ethers_1.utils.randomBytes(32));
|
|
50
|
+
const typedData = {
|
|
51
|
+
types: {
|
|
52
|
+
Wallet: [
|
|
53
|
+
{ name: 'address', type: 'address' },
|
|
54
|
+
{ name: 'signatureText', type: 'string' },
|
|
55
|
+
{ name: 'blockNumber', type: 'uint256' },
|
|
56
|
+
{ name: 'blockHash', type: 'bytes32' },
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
domain: {
|
|
60
|
+
name: 'cbd',
|
|
61
|
+
version: '1',
|
|
62
|
+
chainId,
|
|
63
|
+
salt,
|
|
64
|
+
},
|
|
65
|
+
message: {
|
|
66
|
+
address,
|
|
67
|
+
signatureText,
|
|
68
|
+
blockNumber,
|
|
69
|
+
blockHash,
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
// https://github.com/ethers-io/ethers.js/issues/1431#issuecomment-813950552
|
|
73
|
+
const signature = await this.signer._signTypedData(typedData.domain, typedData.types, typedData.message);
|
|
74
|
+
const formattedTypedData = {
|
|
75
|
+
...typedData,
|
|
76
|
+
primaryType: 'Wallet',
|
|
77
|
+
types: {
|
|
78
|
+
...typedData.types,
|
|
79
|
+
EIP712Domain: [
|
|
80
|
+
{
|
|
81
|
+
name: 'name',
|
|
82
|
+
type: 'string',
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
name: 'version',
|
|
86
|
+
type: 'string',
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
name: 'chainId',
|
|
90
|
+
type: 'uint256',
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
name: 'salt',
|
|
94
|
+
type: 'bytes32',
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
return { signature, typedData: formattedTypedData, address };
|
|
100
|
+
}
|
|
101
|
+
async getChainData() {
|
|
102
|
+
const blockNumber = await this.provider.getBlockNumber();
|
|
103
|
+
const blockHash = (await this.provider.getBlock(blockNumber)).hash;
|
|
104
|
+
const chainId = (await this.provider.getNetwork()).chainId;
|
|
105
|
+
return { blockNumber, blockHash, chainId };
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
exports.WalletAuthenticationProvider = WalletAuthenticationProvider;
|
|
109
|
+
//# sourceMappingURL=providers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"providers.js","sourceRoot":"","sources":["../../../../src/conditions/context/providers.ts"],"names":[],"mappings":";;;AAEA,8CAAyD;AAgBzD,MAAa,4BAA4B;IAIpB;IACA;IAJX,eAAe,CAA0B;IAEjD,YACmB,QAAmC,EACnC,MAAqB;QADrB,aAAQ,GAAR,QAAQ,CAA2B;QACnC,WAAM,GAAN,MAAM,CAAe;IACrC,CAAC;IAEG,KAAK,CAAC,0BAA0B;QACrC,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;QAC/C,MAAM,UAAU,GAAG,oBAAoB,OAAO,EAAE,CAAC;QAEjD,oDAAoD;QACpD,MAAM,cAAc,GAAG,OAAO,YAAY,KAAK,WAAW,CAAC;QAC3D,IAAI,cAAc,EAAE;YAClB,MAAM,cAAc,GAAG,YAAY,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;YACxD,IAAI,cAAc,EAAE;gBAClB,OAAO,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;aACnC;SACF;QAED,oCAAoC;QACpC,MAAM,cAAc,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC,OAAO,CAAC,CAAC;QACvD,IAAI,cAAc,EAAE;YAClB,IAAI,cAAc,EAAE;gBAClB,YAAY,CAAC,OAAO,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;aAClD;YACD,OAAO,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;SACnC;QAED,uEAAuE;QACvE,MAAM,cAAc,GAAG,MAAM,IAAI,CAA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;SACF,CAAC;QACF,4EAA4E;QAC5E,MAAM,SAAS,GAAG,MAChB,IAAI,CAAC,MACN,CAAC,cAAc,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,KAAK,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;QAEvE,MAAM,kBAAkB,GAAuB;YAC7C,GAAG,SAAS;YACZ,WAAW,EAAE,QAAQ;YACrB,KAAK,EAAE;gBACL,GAAG,SAAS,CAAC,KAAK;gBAClB,YAAY,EAAE;oBACZ;wBACE,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,QAAQ;qBACf;oBACD;wBACE,IAAI,EAAE,SAAS;wBACf,IAAI,EAAE,QAAQ;qBACf;oBACD;wBACE,IAAI,EAAE,SAAS;wBACf,IAAI,EAAE,SAAS;qBAChB;oBACD;wBACE,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,SAAS;qBAChB;iBACF;aACF;SACF,CAAC;QACF,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,kBAAkB,EAAE,OAAO,EAAE,CAAC;IAC/D,CAAC;IAEO,KAAK,CAAC,YAAY;QACxB,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,cAAc,EAAE,CAAC;QACzD,MAAM,SAAS,GAAG,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC;QACnE,MAAM,OAAO,GAAG,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC,OAAO,CAAC;QAC3D,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC;IAC7C,CAAC;CACF;AAhHD,oEAgHC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as base from './base';
|
|
2
|
+
import * as predefined from './predefined';
|
|
3
|
+
export * from './base';
|
|
4
|
+
export * from './predefined';
|
|
5
|
+
export { CompoundConditionProps, CompoundConditionType, } from './compound-condition';
|
|
6
|
+
export { Condition, ConditionProps } from './condition';
|
|
7
|
+
export { ConditionExpression, ConditionExpressionJSON } from './condition-expr';
|
|
8
|
+
export { ConditionContext, CustomContextParam } from './context';
|
|
9
|
+
export { base, predefined };
|