@nucypher/taco 0.6.0-alpha.3 → 0.7.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/dist/cjs/conditions/base/address-allowlist.d.ts +10 -0
- package/dist/cjs/conditions/base/address-allowlist.js +19 -0
- package/dist/cjs/conditions/base/address-allowlist.js.map +1 -0
- package/dist/cjs/conditions/base/index.d.ts +2 -0
- package/dist/cjs/conditions/base/index.js +3 -1
- package/dist/cjs/conditions/base/index.js.map +1 -1
- package/dist/cjs/conditions/base/signing.d.ts +10 -0
- package/dist/cjs/conditions/base/signing.js +32 -0
- package/dist/cjs/conditions/base/signing.js.map +1 -0
- package/dist/cjs/conditions/condition-factory.js +8 -0
- package/dist/cjs/conditions/condition-factory.js.map +1 -1
- package/dist/cjs/conditions/context/context.d.ts +4 -0
- package/dist/cjs/conditions/context/context.js +28 -3
- package/dist/cjs/conditions/context/context.js.map +1 -1
- package/dist/cjs/conditions/schemas/address-allowlist.d.ts +16 -0
- package/dist/cjs/conditions/schemas/address-allowlist.js +20 -0
- package/dist/cjs/conditions/schemas/address-allowlist.js.map +1 -0
- package/dist/cjs/conditions/schemas/common.d.ts +1 -0
- package/dist/cjs/conditions/schemas/common.js +16 -3
- package/dist/cjs/conditions/schemas/common.js.map +1 -1
- package/dist/cjs/conditions/schemas/contract.d.ts +21 -18
- package/dist/cjs/conditions/schemas/export-for-zod-doc-gen.d.ts +2 -0
- package/dist/cjs/conditions/schemas/export-for-zod-doc-gen.js +3 -0
- package/dist/cjs/conditions/schemas/export-for-zod-doc-gen.js.map +1 -1
- package/dist/cjs/conditions/schemas/json-api.d.ts +47 -14
- package/dist/cjs/conditions/schemas/json-api.js +16 -2
- package/dist/cjs/conditions/schemas/json-api.js.map +1 -1
- package/dist/cjs/conditions/schemas/json-rpc.d.ts +48 -13
- package/dist/cjs/conditions/schemas/json-rpc.js +16 -2
- package/dist/cjs/conditions/schemas/json-rpc.js.map +1 -1
- package/dist/cjs/conditions/schemas/jwt.d.ts +2 -4
- package/dist/cjs/conditions/schemas/return-value-test.d.ts +28 -12
- package/dist/cjs/conditions/schemas/return-value-test.js +19 -5
- package/dist/cjs/conditions/schemas/return-value-test.js.map +1 -1
- package/dist/cjs/conditions/schemas/rpc.d.ts +18 -12
- package/dist/cjs/conditions/schemas/signing.d.ts +12 -0
- package/dist/cjs/conditions/schemas/signing.js +204 -0
- package/dist/cjs/conditions/schemas/signing.js.map +1 -0
- package/dist/cjs/conditions/schemas/time.d.ts +16 -8
- package/dist/cjs/conditions/schemas/utils.js +6 -1
- package/dist/cjs/conditions/schemas/utils.js.map +1 -1
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/sign.d.ts +24 -0
- package/dist/cjs/sign.js +88 -0
- package/dist/cjs/sign.js.map +1 -0
- package/dist/cjs/types.d.ts +1 -0
- package/dist/es/conditions/base/address-allowlist.d.ts +10 -0
- package/dist/es/conditions/base/address-allowlist.js +15 -0
- package/dist/es/conditions/base/address-allowlist.js.map +1 -0
- package/dist/es/conditions/base/index.d.ts +2 -0
- package/dist/es/conditions/base/index.js +2 -0
- package/dist/es/conditions/base/index.js.map +1 -1
- package/dist/es/conditions/base/signing.d.ts +10 -0
- package/dist/es/conditions/base/signing.js +20 -0
- package/dist/es/conditions/base/signing.js.map +1 -0
- package/dist/es/conditions/condition-factory.js +8 -0
- package/dist/es/conditions/condition-factory.js.map +1 -1
- package/dist/es/conditions/context/context.d.ts +4 -0
- package/dist/es/conditions/context/context.js +27 -2
- package/dist/es/conditions/context/context.js.map +1 -1
- package/dist/es/conditions/schemas/address-allowlist.d.ts +16 -0
- package/dist/es/conditions/schemas/address-allowlist.js +17 -0
- package/dist/es/conditions/schemas/address-allowlist.js.map +1 -0
- package/dist/es/conditions/schemas/common.d.ts +1 -0
- package/dist/es/conditions/schemas/common.js +15 -2
- package/dist/es/conditions/schemas/common.js.map +1 -1
- package/dist/es/conditions/schemas/contract.d.ts +21 -18
- package/dist/es/conditions/schemas/export-for-zod-doc-gen.d.ts +2 -0
- package/dist/es/conditions/schemas/export-for-zod-doc-gen.js +3 -0
- package/dist/es/conditions/schemas/export-for-zod-doc-gen.js.map +1 -1
- package/dist/es/conditions/schemas/json-api.d.ts +47 -14
- package/dist/es/conditions/schemas/json-api.js +17 -3
- package/dist/es/conditions/schemas/json-api.js.map +1 -1
- package/dist/es/conditions/schemas/json-rpc.d.ts +48 -13
- package/dist/es/conditions/schemas/json-rpc.js +17 -3
- package/dist/es/conditions/schemas/json-rpc.js.map +1 -1
- package/dist/es/conditions/schemas/jwt.d.ts +2 -4
- package/dist/es/conditions/schemas/return-value-test.d.ts +28 -12
- package/dist/es/conditions/schemas/return-value-test.js +19 -5
- package/dist/es/conditions/schemas/return-value-test.js.map +1 -1
- package/dist/es/conditions/schemas/rpc.d.ts +18 -12
- package/dist/es/conditions/schemas/signing.d.ts +12 -0
- package/dist/es/conditions/schemas/signing.js +201 -0
- package/dist/es/conditions/schemas/signing.js.map +1 -0
- package/dist/es/conditions/schemas/time.d.ts +16 -8
- package/dist/es/conditions/schemas/utils.js +6 -1
- package/dist/es/conditions/schemas/utils.js.map +1 -1
- package/dist/es/index.d.ts +1 -0
- package/dist/es/index.js +1 -0
- package/dist/es/index.js.map +1 -1
- package/dist/es/sign.d.ts +24 -0
- package/dist/es/sign.js +85 -0
- package/dist/es/sign.js.map +1 -0
- package/dist/es/types.d.ts +1 -0
- package/dist/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/tsconfig.es.tsbuildinfo +1 -1
- package/package.json +5 -4
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { FunctionFragment } from 'ethers/lib/utils';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { baseConditionSchema } from './common';
|
|
4
|
+
import { blockchainReturnValueTestSchema } from './return-value-test';
|
|
5
|
+
export const SIGNING_CONDITION_OBJECT_CONTEXT_VAR = ':signingConditionObject';
|
|
6
|
+
const signingConditionSchema = baseConditionSchema.extend({
|
|
7
|
+
signingObjectContextVar: z
|
|
8
|
+
.literal(SIGNING_CONDITION_OBJECT_CONTEXT_VAR)
|
|
9
|
+
.default(SIGNING_CONDITION_OBJECT_CONTEXT_VAR)
|
|
10
|
+
.describe('The context variable that will be replaced with the signing object at signing'),
|
|
11
|
+
});
|
|
12
|
+
const baseSigningObjectAttributeConditionSchema = signingConditionSchema.extend({
|
|
13
|
+
attributeName: z
|
|
14
|
+
.string()
|
|
15
|
+
.min(1)
|
|
16
|
+
.describe('The name of the attribute to check'),
|
|
17
|
+
});
|
|
18
|
+
export const SigningObjectAttributeConditionType = 'signing-attribute';
|
|
19
|
+
export const signingObjectAttributeConditionSchema = baseSigningObjectAttributeConditionSchema.extend({
|
|
20
|
+
conditionType: z
|
|
21
|
+
.literal(SigningObjectAttributeConditionType)
|
|
22
|
+
.default(SigningObjectAttributeConditionType),
|
|
23
|
+
returnValueTest: blockchainReturnValueTestSchema,
|
|
24
|
+
});
|
|
25
|
+
export const abiParameterValidationSchema = z
|
|
26
|
+
.object({
|
|
27
|
+
parameterIndex: z
|
|
28
|
+
.number()
|
|
29
|
+
.int()
|
|
30
|
+
.nonnegative()
|
|
31
|
+
.describe('Index of parameter to check within abi calldata.'),
|
|
32
|
+
indexWithinTuple: z
|
|
33
|
+
.number()
|
|
34
|
+
.int()
|
|
35
|
+
.nonnegative()
|
|
36
|
+
.optional()
|
|
37
|
+
.describe('Index of value within tuple value at parameter index to check'),
|
|
38
|
+
returnValueTest: blockchainReturnValueTestSchema
|
|
39
|
+
.optional()
|
|
40
|
+
.describe('Comparison check for value within calldata'),
|
|
41
|
+
nestedAbiValidation: z
|
|
42
|
+
.lazy(() => abiCallValidationSchema)
|
|
43
|
+
.optional()
|
|
44
|
+
.describe('Additional checks for nested abi calldata'),
|
|
45
|
+
})
|
|
46
|
+
.refine(
|
|
47
|
+
// An XOR check to see if either 'returnValueTest' or 'nestedAbiValidation' is set
|
|
48
|
+
(parameterValidation) => Boolean(parameterValidation.returnValueTest) !==
|
|
49
|
+
Boolean(parameterValidation.nestedAbiValidation), {
|
|
50
|
+
message: "At most one of the fields 'returnValueTest' and 'nestedAbiValidation' must be defined",
|
|
51
|
+
path: ['returnValueTest'],
|
|
52
|
+
});
|
|
53
|
+
// TODO: is there something already built out there to validate Solidity types?
|
|
54
|
+
function generateSolidityBaseTypeRegExp() {
|
|
55
|
+
// Generate a regex pattern for Solidity base types
|
|
56
|
+
// Generate int/uint sizes (8, 16, ..., 256)
|
|
57
|
+
const intSizes = Array.from({ length: 32 }, (_, i) => (i + 1) * 8); // [8, 16, ..., 256]
|
|
58
|
+
const intSizePattern = intSizes.join('|');
|
|
59
|
+
// Generate bytes sizes (1, 2, ..., 32)
|
|
60
|
+
const bytesSizes = Array.from({ length: 32 }, (_, i) => i + 1); // [1, 2, ..., 32]
|
|
61
|
+
const bytesSizePattern = bytesSizes.join('|');
|
|
62
|
+
// Build the regex string
|
|
63
|
+
const baseTypes = [
|
|
64
|
+
`u?int(${intSizePattern})?`, // uint8, uint16, ..., uint256, int8, int16, ..., int256
|
|
65
|
+
`bytes(${bytesSizePattern})?`, // bytes1, bytes2, ..., bytes32
|
|
66
|
+
'string',
|
|
67
|
+
'address',
|
|
68
|
+
'bool',
|
|
69
|
+
].join('|');
|
|
70
|
+
return new RegExp(`^(${baseTypes})$`);
|
|
71
|
+
}
|
|
72
|
+
// YIKES!
|
|
73
|
+
const solidityBaseTypePattern = generateSolidityBaseTypeRegExp();
|
|
74
|
+
const isValidSolidityType = (param) => {
|
|
75
|
+
// Recursive check for valid Solidity types
|
|
76
|
+
if (!param.baseType || !param.baseType.trim()) {
|
|
77
|
+
return false; // empty type is not valid
|
|
78
|
+
}
|
|
79
|
+
// Check for arrays and tuples
|
|
80
|
+
if (param.baseType === 'tuple') {
|
|
81
|
+
if (!param.components || param.components.length === 0) {
|
|
82
|
+
return false; // tuples must have components defined
|
|
83
|
+
}
|
|
84
|
+
return param.components.every(isValidSolidityType);
|
|
85
|
+
}
|
|
86
|
+
else if (param.baseType === 'array') {
|
|
87
|
+
if (!param.arrayChildren) {
|
|
88
|
+
return false; // arrays must have children type defined
|
|
89
|
+
}
|
|
90
|
+
return isValidSolidityType(param.arrayChildren);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
return solidityBaseTypePattern.test(param.baseType);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
// TODO; find a better way to validate the param type - incomplete best effort for now
|
|
97
|
+
const isValidHumanAbiCallSignature = (signature) => {
|
|
98
|
+
try {
|
|
99
|
+
// TODO: verify this works properly
|
|
100
|
+
const fragment = FunctionFragment.from(signature);
|
|
101
|
+
for (const parameter of fragment.inputs) {
|
|
102
|
+
if (!isValidSolidityType(parameter)) {
|
|
103
|
+
return false; // invalid Solidity type
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// ensure the same sighash format was provided
|
|
107
|
+
return fragment.format() === signature;
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
const humanAbiCallSignatureSchema = z
|
|
114
|
+
.string()
|
|
115
|
+
.refine(isValidHumanAbiCallSignature, {
|
|
116
|
+
message: 'Invalid human readable ABI signature provided',
|
|
117
|
+
})
|
|
118
|
+
.describe('A human readable ABI signature, e.g. "transfer(address,uint256)"');
|
|
119
|
+
/**
|
|
120
|
+
* Validates the allowed ABI calls against the provided signature and validations.
|
|
121
|
+
* This function is used in the superRefine method of the abiCallValidationSchema.
|
|
122
|
+
*
|
|
123
|
+
* @param ctx - The Zod refinement context.
|
|
124
|
+
* @param signature - The ABI signature to validate against.
|
|
125
|
+
* @param validations - The array of validations for the ABI parameters.
|
|
126
|
+
*/
|
|
127
|
+
function validateAllowedAbiCall(ctx, signature, validations) {
|
|
128
|
+
try {
|
|
129
|
+
const fragment = FunctionFragment.from(signature);
|
|
130
|
+
for (const [index, validation] of validations.entries()) {
|
|
131
|
+
if (validation.parameterIndex >= fragment.inputs.length) {
|
|
132
|
+
// invalid parameter index
|
|
133
|
+
ctx.addIssue({
|
|
134
|
+
code: z.ZodIssueCode.custom,
|
|
135
|
+
message: `Parameter index, "${validation.parameterIndex}", is out of range`,
|
|
136
|
+
path: ['allowedAbiCalls', signature, index, 'parameterIndex'],
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
if (validation.indexWithinTuple !== undefined) {
|
|
140
|
+
const paramType = fragment.inputs[validation.parameterIndex];
|
|
141
|
+
if (paramType.baseType !== 'tuple') {
|
|
142
|
+
// type at parameter index is not a tuple
|
|
143
|
+
ctx.addIssue({
|
|
144
|
+
code: z.ZodIssueCode.custom,
|
|
145
|
+
message: `Type at parameter index, "${validation.parameterIndex}", is not a tuple`,
|
|
146
|
+
path: ['allowedAbiCalls', signature, index, 'parameterIndex'],
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
else if (validation.indexWithinTuple >= paramType.components.length) {
|
|
150
|
+
// invalid index within tuple
|
|
151
|
+
ctx.addIssue({
|
|
152
|
+
code: z.ZodIssueCode.custom,
|
|
153
|
+
message: `Index within tuple, "${validation.indexWithinTuple}", is out of range`,
|
|
154
|
+
path: ['allowedAbiCalls', signature, index, 'indexWithinTuple'],
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (validation.nestedAbiValidation) {
|
|
159
|
+
// if there is nested ABI validation, the type must be bytes
|
|
160
|
+
let paramType = fragment.inputs[validation.parameterIndex];
|
|
161
|
+
if (validation.indexWithinTuple !== undefined) {
|
|
162
|
+
// if there is an index within tuple, get the type of the component at that index
|
|
163
|
+
paramType = paramType.components[validation.indexWithinTuple];
|
|
164
|
+
}
|
|
165
|
+
if (paramType.baseType !== 'bytes') {
|
|
166
|
+
ctx.addIssue({
|
|
167
|
+
code: z.ZodIssueCode.custom,
|
|
168
|
+
message: `Invalid type for nested ABI validation, "${paramType.baseType}"; expected bytes`,
|
|
169
|
+
path: ['allowedAbiCalls', signature, index],
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
catch {
|
|
176
|
+
// even though abi signatures are already validated by nested schema - zod uses “greedy” (continuable) validation so all validations are run
|
|
177
|
+
// ignore invalid ABI signature
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
export const abiCallValidationSchema = z
|
|
181
|
+
.object({
|
|
182
|
+
allowedAbiCalls: z.record(humanAbiCallSignatureSchema, z.array(abiParameterValidationSchema)),
|
|
183
|
+
})
|
|
184
|
+
.refine((abiCallValidation) => Object.keys(abiCallValidation.allowedAbiCalls).length > 0, {
|
|
185
|
+
message: 'At least one allowed ABI call must be defined',
|
|
186
|
+
path: ['allowedAbiCalls'],
|
|
187
|
+
})
|
|
188
|
+
.superRefine((data, ctx) => {
|
|
189
|
+
for (const [signature, validations] of Object.entries(data.allowedAbiCalls)) {
|
|
190
|
+
validateAllowedAbiCall(ctx, signature, validations);
|
|
191
|
+
}
|
|
192
|
+
})
|
|
193
|
+
.describe('A map of allowed ABI calls with their respective parameter validations.');
|
|
194
|
+
export const SigningObjectAbiAttributeConditionType = 'signing-abi-attribute';
|
|
195
|
+
export const signingObjectAbiAttributeConditionSchema = baseSigningObjectAttributeConditionSchema.extend({
|
|
196
|
+
conditionType: z
|
|
197
|
+
.literal(SigningObjectAbiAttributeConditionType)
|
|
198
|
+
.default(SigningObjectAbiAttributeConditionType),
|
|
199
|
+
abiValidation: abiCallValidationSchema,
|
|
200
|
+
});
|
|
201
|
+
//# sourceMappingURL=signing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signing.js","sourceRoot":"","sources":["../../../../src/conditions/schemas/signing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAa,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CA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AC,MAAM,CACvB,2BAA2B,EAC3B,CAAC,CAAC,KAAK,CAAC,4BAA4B,CAAC,CACtC;CACF,CAAC;KACD,MAAM,CACL,CAAC,iBAAiB,EAAE,EAAE,CACpB,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,eAAe,CAAC,CAAC,MAAM,GAAG,CAAC,EAC3D;IACE,OAAO,EAAE,+CAA+C;IACxD,IAAI,EAAE,CAAC,iBAAiB,CAAC;CAC1B,CACF;KACA,WAAW,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE;IACzB,KAAK,MAAM,CAAC,SAAS,EAAE,WAAW,CAAC,IAAI,MAAM,CAAC,OAAO,CACnD,IAAI,CAAC,eAAe,CACrB,EAAE,CAAC;QACF,sBAAsB,CAAC,GAAG,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC;IACtD,CAAC;AACH,CAAC,CAAC;KACD,QAAQ,CACP,yEAAyE,CAC1E,CAAC;AAIJ,MAAM,CAAC,MAAM,sCAAsC,GAAG,uBAAuB,CAAC;AAE9E,MAAM,CAAC,MAAM,wCAAwC,GACnD,yCAAyC,CAAC,MAAM,CAAC;IAC/C,aAAa,EAAE,CAAC;SACb,OAAO,CAAC,sCAAsC,CAAC;SAC/C,OAAO,CAAC,sCAAsC,CAAC;IAClD,aAAa,EAAE,uBAAuB;CACvC,CAAC,CAAC"}
|
|
@@ -5,17 +5,25 @@ export declare const timeConditionSchema: z.ZodObject<{
|
|
|
5
5
|
conditionType: z.ZodDefault<z.ZodLiteral<"time">>;
|
|
6
6
|
method: z.ZodDefault<z.ZodLiteral<"blocktime">>;
|
|
7
7
|
chain: z.ZodNumber;
|
|
8
|
-
returnValueTest: z.
|
|
8
|
+
returnValueTest: z.ZodEffects<z.ZodObject<{
|
|
9
9
|
index: z.ZodOptional<z.ZodNumber>;
|
|
10
|
-
comparator: z.ZodEnum<["==", ">", "<", ">=", "<=", "!="]>;
|
|
11
|
-
}
|
|
10
|
+
comparator: z.ZodEnum<["==", ">", "<", ">=", "<=", "!=", "in", "!in"]>;
|
|
11
|
+
} & {
|
|
12
12
|
value: z.ZodType<any, z.ZodTypeDef, any>;
|
|
13
|
-
}
|
|
14
|
-
comparator: "==" | ">" | "<" | ">=" | "<=" | "!=";
|
|
13
|
+
}, "strip", z.ZodTypeAny, {
|
|
14
|
+
comparator: "==" | ">" | "<" | ">=" | "<=" | "!=" | "in" | "!in";
|
|
15
|
+
value?: any;
|
|
16
|
+
index?: number | undefined;
|
|
17
|
+
}, {
|
|
18
|
+
comparator: "==" | ">" | "<" | ">=" | "<=" | "!=" | "in" | "!in";
|
|
19
|
+
value?: any;
|
|
20
|
+
index?: number | undefined;
|
|
21
|
+
}>, {
|
|
22
|
+
comparator: "==" | ">" | "<" | ">=" | "<=" | "!=" | "in" | "!in";
|
|
15
23
|
value?: any;
|
|
16
24
|
index?: number | undefined;
|
|
17
25
|
}, {
|
|
18
|
-
comparator: "==" | ">" | "<" | ">=" | "<=" | "!=";
|
|
26
|
+
comparator: "==" | ">" | "<" | ">=" | "<=" | "!=" | "in" | "!in";
|
|
19
27
|
value?: any;
|
|
20
28
|
index?: number | undefined;
|
|
21
29
|
}>;
|
|
@@ -24,14 +32,14 @@ export declare const timeConditionSchema: z.ZodObject<{
|
|
|
24
32
|
chain: number;
|
|
25
33
|
method: "blocktime";
|
|
26
34
|
returnValueTest: {
|
|
27
|
-
comparator: "==" | ">" | "<" | ">=" | "<=" | "!=";
|
|
35
|
+
comparator: "==" | ">" | "<" | ">=" | "<=" | "!=" | "in" | "!in";
|
|
28
36
|
value?: any;
|
|
29
37
|
index?: number | undefined;
|
|
30
38
|
};
|
|
31
39
|
}, {
|
|
32
40
|
chain: number;
|
|
33
41
|
returnValueTest: {
|
|
34
|
-
comparator: "==" | ">" | "<" | ">=" | "<=" | "!=";
|
|
42
|
+
comparator: "==" | ">" | "<" | ">=" | "<=" | "!=" | "in" | "!in";
|
|
35
43
|
value?: any;
|
|
36
44
|
index?: number | undefined;
|
|
37
45
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { compoundConditionSchema } from '../compound-condition';
|
|
3
|
+
import { addressAllowlistConditionSchema } from './address-allowlist';
|
|
3
4
|
import { contractConditionSchema } from './contract';
|
|
4
5
|
import { ifThenElseConditionSchema } from './if-then-else';
|
|
5
6
|
import { jsonApiConditionSchema } from './json-api';
|
|
@@ -7,15 +8,19 @@ import { jsonRpcConditionSchema } from './json-rpc';
|
|
|
7
8
|
import { jwtConditionSchema } from './jwt';
|
|
8
9
|
import { rpcConditionSchema } from './rpc';
|
|
9
10
|
import { sequentialConditionSchema } from './sequential';
|
|
11
|
+
import { signingObjectAbiAttributeConditionSchema, signingObjectAttributeConditionSchema, } from './signing';
|
|
10
12
|
import { timeConditionSchema } from './time';
|
|
11
13
|
export const anyConditionSchema = z.lazy(() => z.union([
|
|
12
14
|
rpcConditionSchema,
|
|
13
15
|
timeConditionSchema,
|
|
16
|
+
addressAllowlistConditionSchema,
|
|
14
17
|
contractConditionSchema,
|
|
15
|
-
compoundConditionSchema,
|
|
16
18
|
jsonApiConditionSchema,
|
|
17
19
|
jsonRpcConditionSchema,
|
|
18
20
|
jwtConditionSchema,
|
|
21
|
+
signingObjectAttributeConditionSchema,
|
|
22
|
+
signingObjectAbiAttributeConditionSchema,
|
|
23
|
+
compoundConditionSchema,
|
|
19
24
|
sequentialConditionSchema,
|
|
20
25
|
ifThenElseConditionSchema,
|
|
21
26
|
]));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/conditions/schemas/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAEhE,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CA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GAAG,EAAE,CACzD,CAAC,CAAC,KAAK,CAAC;IACN,kBAAkB;IAClB,mBAAmB;IACnB,+BAA+B;IAC/B,uBAAuB;IACvB,sBAAsB;IACtB,sBAAsB;IACtB,kBAAkB;IAClB,qCAAqC;IACrC,wCAAwC;IACxC,uBAAuB;IACvB,yBAAyB;IACzB,yBAAyB;CAC1B,CAAC,CACH,CAAC"}
|
package/dist/es/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { DkgPublicKey, ThresholdMessageKit } from '@nucypher/nucypher-core';
|
|
2
2
|
export { Domain, domains, fromBytes, getPorterUris, initialize, toBytes, toHexString, } from '@nucypher/shared';
|
|
3
3
|
export * as conditions from './conditions';
|
|
4
|
+
export { signUserOp } from './sign';
|
|
4
5
|
export { decrypt, encrypt, encryptWithPublicKey } from './taco';
|
package/dist/es/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { DkgPublicKey, ThresholdMessageKit } from '@nucypher/nucypher-core';
|
|
2
2
|
export { domains, fromBytes, getPorterUris, initialize, toBytes, toHexString, } from '@nucypher/shared';
|
|
3
3
|
export * as conditions from './conditions';
|
|
4
|
+
export { signUserOp } from './sign';
|
|
4
5
|
export { decrypt, encrypt, encryptWithPublicKey } from './taco';
|
|
5
6
|
//# sourceMappingURL=index.js.map
|
package/dist/es/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC5E,OAAO,EAEL,OAAO,EACP,SAAS,EACT,aAAa,EACb,UAAU,EACV,OAAO,EACP,WAAW,GACZ,MAAM,kBAAkB,CAAC;AAE1B,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC;AAE3C,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC5E,OAAO,EAEL,OAAO,EACP,SAAS,EACT,aAAa,EACb,UAAU,EACV,OAAO,EACP,WAAW,GACZ,MAAM,kBAAkB,CAAC;AAE1B,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC;AAE3C,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Domain, TacoSignature, UserOperation } from '@nucypher/shared';
|
|
2
|
+
import { ethers } from 'ethers';
|
|
3
|
+
import { ConditionContext } from './conditions/context';
|
|
4
|
+
export type SignResult = {
|
|
5
|
+
messageHash: string;
|
|
6
|
+
aggregatedSignature: string;
|
|
7
|
+
signingResults: {
|
|
8
|
+
[ursulaAddress: string]: TacoSignature;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Signs a UserOperation.
|
|
13
|
+
* @param provider - The Ethereum provider to use for signing.
|
|
14
|
+
* @param domain - The TACo domain being used.
|
|
15
|
+
* @param cohortId - The cohort ID that identifies the signing cohort.
|
|
16
|
+
* @param chainId - The chain ID for the signing operation.
|
|
17
|
+
* @param userOp - The UserOperation to be signed.
|
|
18
|
+
* @param aaVersion - The AA version of the account abstraction to use for signing.
|
|
19
|
+
* @param context - Optional condition context for the context variable resolution.
|
|
20
|
+
* @param porterUris - Optional URIs for the Porter service. If not provided, will fetch the default URIs from the domain.
|
|
21
|
+
* @returns A promise that resolves to a SignResult containing the message hash, aggregated signature, and signing results from the Porter service.
|
|
22
|
+
* @throws An error if the signing process fails due to insufficient signatures or mismatched hashes.
|
|
23
|
+
*/
|
|
24
|
+
export declare function signUserOp(provider: ethers.providers.Provider, domain: Domain, cohortId: number, chainId: number, userOp: UserOperation, aaVersion: 'mdt' | '0.8.0' | string, context?: ConditionContext, porterUris?: string[]): Promise<SignResult>;
|
package/dist/es/sign.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { convertUserOperationToPython, fromHexString, getPorterUris, PorterClient, SigningCoordinatorAgent, toBase64, toHexString, UserOperationSignatureRequest, } from '@nucypher/shared';
|
|
2
|
+
const ERR_INSUFFICIENT_SIGNATURES = (errors) => `Threshold of signatures not met; TACo signing failed with errors: ${JSON.stringify(errors)}`;
|
|
3
|
+
const ERR_MISMATCHED_HASHES = (hashToSignatures) => `Threshold of signatures not met; multiple mismatched hashes found: ${JSON.stringify(Object.fromEntries(hashToSignatures.entries()))}`;
|
|
4
|
+
function aggregateSignatures(signaturesByAddress, threshold) {
|
|
5
|
+
// Aggregate hex signatures by concatenating them; being careful to remove the '0x' prefix from each signature except the first one.
|
|
6
|
+
const signatures = Object.values(signaturesByAddress)
|
|
7
|
+
.map((sig) => sig.signature)
|
|
8
|
+
.slice(0, threshold);
|
|
9
|
+
if (signatures.length === 1) {
|
|
10
|
+
return signatures[0];
|
|
11
|
+
}
|
|
12
|
+
// Concatenate signatures
|
|
13
|
+
const allBytes = signatures.flatMap((hex) => Array.from(fromHexString(hex)));
|
|
14
|
+
return `0x${toHexString(new Uint8Array(allBytes))}`;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Signs a UserOperation.
|
|
18
|
+
* @param provider - The Ethereum provider to use for signing.
|
|
19
|
+
* @param domain - The TACo domain being used.
|
|
20
|
+
* @param cohortId - The cohort ID that identifies the signing cohort.
|
|
21
|
+
* @param chainId - The chain ID for the signing operation.
|
|
22
|
+
* @param userOp - The UserOperation to be signed.
|
|
23
|
+
* @param aaVersion - The AA version of the account abstraction to use for signing.
|
|
24
|
+
* @param context - Optional condition context for the context variable resolution.
|
|
25
|
+
* @param porterUris - Optional URIs for the Porter service. If not provided, will fetch the default URIs from the domain.
|
|
26
|
+
* @returns A promise that resolves to a SignResult containing the message hash, aggregated signature, and signing results from the Porter service.
|
|
27
|
+
* @throws An error if the signing process fails due to insufficient signatures or mismatched hashes.
|
|
28
|
+
*/
|
|
29
|
+
export async function signUserOp(provider, domain, cohortId, chainId, userOp, aaVersion, context, porterUris) {
|
|
30
|
+
const porterUrisFull = porterUris
|
|
31
|
+
? porterUris
|
|
32
|
+
: await getPorterUris(domain);
|
|
33
|
+
const porter = new PorterClient(porterUrisFull);
|
|
34
|
+
const signers = await SigningCoordinatorAgent.getParticipants(provider, domain, cohortId);
|
|
35
|
+
const threshold = await SigningCoordinatorAgent.getThreshold(provider, domain, cohortId);
|
|
36
|
+
const pythonUserOp = convertUserOperationToPython(userOp);
|
|
37
|
+
const signingRequest = new UserOperationSignatureRequest(pythonUserOp, aaVersion, cohortId, chainId, context || {}, 'userop');
|
|
38
|
+
const signingRequests = Object.fromEntries(signers.map((signer) => [
|
|
39
|
+
signer.provider,
|
|
40
|
+
toBase64(signingRequest.toBytes()),
|
|
41
|
+
]));
|
|
42
|
+
// Build signing request for the user operation
|
|
43
|
+
const porterSignResult = await porter.signUserOp(signingRequests, threshold);
|
|
44
|
+
const hashToSignatures = new Map();
|
|
45
|
+
// Single pass: decode signatures and populate signingResults
|
|
46
|
+
for (const [ursulaAddress, signature] of Object.entries(porterSignResult.signingResults)) {
|
|
47
|
+
// For non-optimistic: track hashes and group signatures for aggregation
|
|
48
|
+
const hash = signature.messageHash;
|
|
49
|
+
if (!hashToSignatures.has(hash)) {
|
|
50
|
+
hashToSignatures.set(hash, {});
|
|
51
|
+
}
|
|
52
|
+
hashToSignatures.get(hash)[ursulaAddress] = signature;
|
|
53
|
+
}
|
|
54
|
+
let messageHash = undefined;
|
|
55
|
+
let signaturesToAggregate = undefined;
|
|
56
|
+
for (const [hash, signatures] of hashToSignatures.entries()) {
|
|
57
|
+
if (Object.keys(signatures).length >= threshold) {
|
|
58
|
+
signaturesToAggregate = signatures;
|
|
59
|
+
messageHash = hash;
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// Insufficient signatures for a message hash to meet the threshold
|
|
64
|
+
if (!messageHash || !signaturesToAggregate) {
|
|
65
|
+
if (hashToSignatures.size > 1 &&
|
|
66
|
+
Object.keys(porterSignResult.errors).length < signers.length - threshold) {
|
|
67
|
+
// Two things are true:
|
|
68
|
+
// 1. we have multiple hashes, which means we have mismatched hashes from different nodes
|
|
69
|
+
// we don't really expect this to happen (other than some malicious nodes)
|
|
70
|
+
// 2. number of errors still could have allowed for a threshold of signatures
|
|
71
|
+
console.error('Porter returned mismatched message hashes:', hashToSignatures);
|
|
72
|
+
throw new Error(ERR_MISMATCHED_HASHES(hashToSignatures));
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
throw new Error(ERR_INSUFFICIENT_SIGNATURES(porterSignResult.errors));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const aggregatedSignature = aggregateSignatures(signaturesToAggregate, threshold);
|
|
79
|
+
return {
|
|
80
|
+
messageHash,
|
|
81
|
+
aggregatedSignature,
|
|
82
|
+
signingResults: porterSignResult.signingResults,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=sign.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sign.js","sourceRoot":"","sources":["../../src/sign.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,EAE5B,aAAa,EACb,aAAa,EACb,YAAY,EACZ,uBAAuB,EAGvB,QAAQ,EACR,WAAW,EAEX,6BAA6B,GAC9B,MAAM,kBAAkB,CAAC;AAK1B,MAAM,2BAA2B,GAAG,CAAC,MAAe,EAAE,EAAE,CACtD,qEAAqE,IAAI,CAAC,SAAS,CACjF,MAAM,CACP,EAAE,CAAC;AACN,MAAM,qBAAqB,GAAG,CAC5B,gBAAyE,EACzE,EAAE,CACF,sEAAsE,IAAI,C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