@agoric/orchestration 0.1.1-dev-d57b08e.0.d57b08e → 0.1.1-dev-2ae3f1f.0.2ae3f1f
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/package.json +16 -16
- package/src/stubs/{viem-abi.d.ts → viem-typedData.ts} +9 -4
- package/src/utils/abitype.d.ts +6 -0
- package/src/utils/abitype.d.ts.map +1 -0
- package/src/utils/abitype.ts +13 -0
- package/src/utils/permit2/signatureTransfer.d.ts +208 -0
- package/src/utils/permit2/signatureTransfer.d.ts.map +1 -0
- package/src/utils/permit2/signatureTransfer.ts +240 -0
- package/src/utils/permit2/signatureTransferHelpers.d.ts +21 -0
- package/src/utils/permit2/signatureTransferHelpers.d.ts.map +1 -0
- package/src/utils/permit2/signatureTransferHelpers.ts +139 -0
- package/src/utils/permit2.d.ts +11 -0
- package/src/utils/permit2.d.ts.map +1 -0
- package/src/utils/permit2.ts +11 -0
- package/src/utils/viem-utils/hashTypedData.d.ts +17 -0
- package/src/utils/viem-utils/hashTypedData.d.ts.map +1 -0
- package/src/utils/viem-utils/hashTypedData.ts +57 -0
- package/src/utils/viem-utils/types.d.ts +6 -0
- package/src/utils/viem-utils/types.d.ts.map +1 -0
- package/src/utils/viem-utils/types.ts +18 -0
- package/src/utils/viem.d.ts +11 -0
- package/src/utils/viem.d.ts.map +1 -0
- package/src/utils/viem.ts +11 -0
- package/src/vendor/viem/{_esm-YOAV66U4.js → _esm-OKAICHVC.js} +2 -2
- package/src/vendor/viem/{ccip-AAQDZF3N.js → ccip-34BSSMV5.js} +1 -2
- package/src/vendor/viem/{chunk-4EF4K2MH.js → chunk-GCI53Z2G.js} +35 -1
- package/src/vendor/viem/chunk-OFIEVWYB.js +326 -0
- package/src/vendor/viem/viem-abi.js +2 -2
- package/src/vendor/viem/viem-typedData.d.ts +19 -0
- package/src/vendor/viem/viem-typedData.js +56 -0
- package/tsup.config.ts +13 -2
- package/src/stubs/viem-abi.d.ts.map +0 -1
- package/src/vendor/viem/chunk-XN4LUOIH.js +0 -253
- package/src/vendor/viem/secp256k1-WHBDSQB2.js +0 -1914
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BaseError,
|
|
3
|
+
BytesSizeMismatchError,
|
|
4
|
+
InvalidAddressError,
|
|
5
|
+
bytesRegex,
|
|
6
|
+
checksumAddress,
|
|
7
|
+
concat,
|
|
8
|
+
encodeAbiParameters,
|
|
9
|
+
getAddress,
|
|
10
|
+
hexToBigInt,
|
|
11
|
+
hexToNumber,
|
|
12
|
+
integerRegex,
|
|
13
|
+
isAddress,
|
|
14
|
+
isAddressEqual,
|
|
15
|
+
isHex,
|
|
16
|
+
keccak256,
|
|
17
|
+
numberToHex,
|
|
18
|
+
size,
|
|
19
|
+
stringify,
|
|
20
|
+
toHex
|
|
21
|
+
} from "./chunk-GCI53Z2G.js";
|
|
22
|
+
|
|
23
|
+
// ../../node_modules/viem/_esm/errors/typedData.js
|
|
24
|
+
var InvalidDomainError = class extends BaseError {
|
|
25
|
+
constructor({ domain }) {
|
|
26
|
+
super(`Invalid domain "${stringify(domain)}".`, {
|
|
27
|
+
metaMessages: ["Must be a valid EIP-712 domain."]
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
var InvalidPrimaryTypeError = class extends BaseError {
|
|
32
|
+
constructor({ primaryType, types }) {
|
|
33
|
+
super(`Invalid primary type \`${primaryType}\` must be one of \`${JSON.stringify(Object.keys(types))}\`.`, {
|
|
34
|
+
docsPath: "/api/glossary/Errors#typeddatainvalidprimarytypeerror",
|
|
35
|
+
metaMessages: ["Check that the primary type is a key in `types`."]
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
var InvalidStructTypeError = class extends BaseError {
|
|
40
|
+
constructor({ type }) {
|
|
41
|
+
super(`Struct type "${type}" is invalid.`, {
|
|
42
|
+
metaMessages: ["Struct type must not be a Solidity type."],
|
|
43
|
+
name: "InvalidStructTypeError"
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// ../../node_modules/viem/_esm/utils/typedData.js
|
|
49
|
+
function serializeTypedData(parameters) {
|
|
50
|
+
const { domain: domain_, message: message_, primaryType, types } = parameters;
|
|
51
|
+
const normalizeData = (struct, data_) => {
|
|
52
|
+
const data = { ...data_ };
|
|
53
|
+
for (const param of struct) {
|
|
54
|
+
const { name, type } = param;
|
|
55
|
+
if (type === "address")
|
|
56
|
+
data[name] = data[name].toLowerCase();
|
|
57
|
+
}
|
|
58
|
+
return data;
|
|
59
|
+
};
|
|
60
|
+
const domain = (() => {
|
|
61
|
+
if (!types.EIP712Domain)
|
|
62
|
+
return {};
|
|
63
|
+
if (!domain_)
|
|
64
|
+
return {};
|
|
65
|
+
return normalizeData(types.EIP712Domain, domain_);
|
|
66
|
+
})();
|
|
67
|
+
const message = (() => {
|
|
68
|
+
if (primaryType === "EIP712Domain")
|
|
69
|
+
return void 0;
|
|
70
|
+
return normalizeData(types[primaryType], message_);
|
|
71
|
+
})();
|
|
72
|
+
return stringify({ domain, message, primaryType, types });
|
|
73
|
+
}
|
|
74
|
+
function validateTypedData(parameters) {
|
|
75
|
+
const { domain, message, primaryType, types } = parameters;
|
|
76
|
+
const validateData = (struct, data) => {
|
|
77
|
+
for (const param of struct) {
|
|
78
|
+
const { name, type } = param;
|
|
79
|
+
const value = data[name];
|
|
80
|
+
const integerMatch = type.match(integerRegex);
|
|
81
|
+
if (integerMatch && (typeof value === "number" || typeof value === "bigint")) {
|
|
82
|
+
const [_type, base, size_] = integerMatch;
|
|
83
|
+
numberToHex(value, {
|
|
84
|
+
signed: base === "int",
|
|
85
|
+
size: Number.parseInt(size_) / 8
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
if (type === "address" && typeof value === "string" && !isAddress(value))
|
|
89
|
+
throw new InvalidAddressError({ address: value });
|
|
90
|
+
const bytesMatch = type.match(bytesRegex);
|
|
91
|
+
if (bytesMatch) {
|
|
92
|
+
const [_type, size_] = bytesMatch;
|
|
93
|
+
if (size_ && size(value) !== Number.parseInt(size_))
|
|
94
|
+
throw new BytesSizeMismatchError({
|
|
95
|
+
expectedSize: Number.parseInt(size_),
|
|
96
|
+
givenSize: size(value)
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
const struct2 = types[type];
|
|
100
|
+
if (struct2) {
|
|
101
|
+
validateReference(type);
|
|
102
|
+
validateData(struct2, value);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
if (types.EIP712Domain && domain) {
|
|
107
|
+
if (typeof domain !== "object")
|
|
108
|
+
throw new InvalidDomainError({ domain });
|
|
109
|
+
validateData(types.EIP712Domain, domain);
|
|
110
|
+
}
|
|
111
|
+
if (primaryType !== "EIP712Domain") {
|
|
112
|
+
if (types[primaryType])
|
|
113
|
+
validateData(types[primaryType], message);
|
|
114
|
+
else
|
|
115
|
+
throw new InvalidPrimaryTypeError({ primaryType, types });
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function getTypesForEIP712Domain({ domain }) {
|
|
119
|
+
return [
|
|
120
|
+
typeof domain?.name === "string" && { name: "name", type: "string" },
|
|
121
|
+
domain?.version && { name: "version", type: "string" },
|
|
122
|
+
(typeof domain?.chainId === "number" || typeof domain?.chainId === "bigint") && {
|
|
123
|
+
name: "chainId",
|
|
124
|
+
type: "uint256"
|
|
125
|
+
},
|
|
126
|
+
domain?.verifyingContract && {
|
|
127
|
+
name: "verifyingContract",
|
|
128
|
+
type: "address"
|
|
129
|
+
},
|
|
130
|
+
domain?.salt && { name: "salt", type: "bytes32" }
|
|
131
|
+
].filter(Boolean);
|
|
132
|
+
}
|
|
133
|
+
function validateReference(type) {
|
|
134
|
+
if (type === "address" || type === "bool" || type === "string" || type.startsWith("bytes") || type.startsWith("uint") || type.startsWith("int"))
|
|
135
|
+
throw new InvalidStructTypeError({ type });
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// ../../node_modules/viem/_esm/utils/signature/hashTypedData.js
|
|
139
|
+
function hashTypedData(parameters) {
|
|
140
|
+
const { domain = {}, message, primaryType } = parameters;
|
|
141
|
+
const types = {
|
|
142
|
+
EIP712Domain: getTypesForEIP712Domain({ domain }),
|
|
143
|
+
...parameters.types
|
|
144
|
+
};
|
|
145
|
+
validateTypedData({
|
|
146
|
+
domain,
|
|
147
|
+
message,
|
|
148
|
+
primaryType,
|
|
149
|
+
types
|
|
150
|
+
});
|
|
151
|
+
const parts = ["0x1901"];
|
|
152
|
+
if (domain)
|
|
153
|
+
parts.push(hashDomain({
|
|
154
|
+
domain,
|
|
155
|
+
types
|
|
156
|
+
}));
|
|
157
|
+
if (primaryType !== "EIP712Domain")
|
|
158
|
+
parts.push(hashStruct({
|
|
159
|
+
data: message,
|
|
160
|
+
primaryType,
|
|
161
|
+
types
|
|
162
|
+
}));
|
|
163
|
+
return keccak256(concat(parts));
|
|
164
|
+
}
|
|
165
|
+
function hashDomain({ domain, types }) {
|
|
166
|
+
return hashStruct({
|
|
167
|
+
data: domain,
|
|
168
|
+
primaryType: "EIP712Domain",
|
|
169
|
+
types
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
function hashStruct({ data, primaryType, types }) {
|
|
173
|
+
const encoded = encodeData({
|
|
174
|
+
data,
|
|
175
|
+
primaryType,
|
|
176
|
+
types
|
|
177
|
+
});
|
|
178
|
+
return keccak256(encoded);
|
|
179
|
+
}
|
|
180
|
+
function encodeData({ data, primaryType, types }) {
|
|
181
|
+
const encodedTypes = [{ type: "bytes32" }];
|
|
182
|
+
const encodedValues = [hashType({ primaryType, types })];
|
|
183
|
+
for (const field of types[primaryType]) {
|
|
184
|
+
const [type, value] = encodeField({
|
|
185
|
+
types,
|
|
186
|
+
name: field.name,
|
|
187
|
+
type: field.type,
|
|
188
|
+
value: data[field.name]
|
|
189
|
+
});
|
|
190
|
+
encodedTypes.push(type);
|
|
191
|
+
encodedValues.push(value);
|
|
192
|
+
}
|
|
193
|
+
return encodeAbiParameters(encodedTypes, encodedValues);
|
|
194
|
+
}
|
|
195
|
+
function hashType({ primaryType, types }) {
|
|
196
|
+
const encodedHashType = toHex(encodeType({ primaryType, types }));
|
|
197
|
+
return keccak256(encodedHashType);
|
|
198
|
+
}
|
|
199
|
+
function encodeType({ primaryType, types }) {
|
|
200
|
+
let result = "";
|
|
201
|
+
const unsortedDeps = findTypeDependencies({ primaryType, types });
|
|
202
|
+
unsortedDeps.delete(primaryType);
|
|
203
|
+
const deps = [primaryType, ...Array.from(unsortedDeps).sort()];
|
|
204
|
+
for (const type of deps) {
|
|
205
|
+
result += `${type}(${types[type].map(({ name, type: t }) => `${t} ${name}`).join(",")})`;
|
|
206
|
+
}
|
|
207
|
+
return result;
|
|
208
|
+
}
|
|
209
|
+
function findTypeDependencies({ primaryType: primaryType_, types }, results = /* @__PURE__ */ new Set()) {
|
|
210
|
+
const match = primaryType_.match(/^\w*/u);
|
|
211
|
+
const primaryType = match?.[0];
|
|
212
|
+
if (results.has(primaryType) || types[primaryType] === void 0) {
|
|
213
|
+
return results;
|
|
214
|
+
}
|
|
215
|
+
results.add(primaryType);
|
|
216
|
+
for (const field of types[primaryType]) {
|
|
217
|
+
findTypeDependencies({ primaryType: field.type, types }, results);
|
|
218
|
+
}
|
|
219
|
+
return results;
|
|
220
|
+
}
|
|
221
|
+
function encodeField({ types, name, type, value }) {
|
|
222
|
+
if (types[type] !== void 0) {
|
|
223
|
+
return [
|
|
224
|
+
{ type: "bytes32" },
|
|
225
|
+
keccak256(encodeData({ data: value, primaryType: type, types }))
|
|
226
|
+
];
|
|
227
|
+
}
|
|
228
|
+
if (type === "bytes") {
|
|
229
|
+
const prepend = value.length % 2 ? "0" : "";
|
|
230
|
+
value = `0x${prepend + value.slice(2)}`;
|
|
231
|
+
return [{ type: "bytes32" }, keccak256(value)];
|
|
232
|
+
}
|
|
233
|
+
if (type === "string")
|
|
234
|
+
return [{ type: "bytes32" }, keccak256(toHex(value))];
|
|
235
|
+
if (type.lastIndexOf("]") === type.length - 1) {
|
|
236
|
+
const parsedType = type.slice(0, type.lastIndexOf("["));
|
|
237
|
+
const typeValuePairs = value.map((item) => encodeField({
|
|
238
|
+
name,
|
|
239
|
+
type: parsedType,
|
|
240
|
+
types,
|
|
241
|
+
value: item
|
|
242
|
+
}));
|
|
243
|
+
return [
|
|
244
|
+
{ type: "bytes32" },
|
|
245
|
+
keccak256(encodeAbiParameters(typeValuePairs.map(([t]) => t), typeValuePairs.map(([, v]) => v)))
|
|
246
|
+
];
|
|
247
|
+
}
|
|
248
|
+
return [{ type }, value];
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// ../../node_modules/viem/_esm/accounts/utils/publicKeyToAddress.js
|
|
252
|
+
function publicKeyToAddress(publicKey) {
|
|
253
|
+
const address = keccak256(`0x${publicKey.substring(4)}`).substring(26);
|
|
254
|
+
return checksumAddress(`0x${address}`);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// ../../node_modules/viem/_esm/utils/signature/recoverPublicKey.js
|
|
258
|
+
async function recoverPublicKey({ hash, signature }) {
|
|
259
|
+
const hashHex = isHex(hash) ? hash : toHex(hash);
|
|
260
|
+
const { secp256k1 } = await import("@noble/curves/secp256k1");
|
|
261
|
+
const signature_ = (() => {
|
|
262
|
+
if (typeof signature === "object" && "r" in signature && "s" in signature) {
|
|
263
|
+
const { r, s, v, yParity } = signature;
|
|
264
|
+
const yParityOrV2 = Number(yParity ?? v);
|
|
265
|
+
const recoveryBit2 = toRecoveryBit(yParityOrV2);
|
|
266
|
+
return new secp256k1.Signature(hexToBigInt(r), hexToBigInt(s)).addRecoveryBit(recoveryBit2);
|
|
267
|
+
}
|
|
268
|
+
const signatureHex = isHex(signature) ? signature : toHex(signature);
|
|
269
|
+
if (size(signatureHex) !== 65)
|
|
270
|
+
throw new Error("invalid signature length");
|
|
271
|
+
const yParityOrV = hexToNumber(`0x${signatureHex.slice(130)}`);
|
|
272
|
+
const recoveryBit = toRecoveryBit(yParityOrV);
|
|
273
|
+
return secp256k1.Signature.fromCompact(signatureHex.substring(2, 130)).addRecoveryBit(recoveryBit);
|
|
274
|
+
})();
|
|
275
|
+
const publicKey = signature_.recoverPublicKey(hashHex.substring(2)).toHex(false);
|
|
276
|
+
return `0x${publicKey}`;
|
|
277
|
+
}
|
|
278
|
+
function toRecoveryBit(yParityOrV) {
|
|
279
|
+
if (yParityOrV === 0 || yParityOrV === 1)
|
|
280
|
+
return yParityOrV;
|
|
281
|
+
if (yParityOrV === 27)
|
|
282
|
+
return 0;
|
|
283
|
+
if (yParityOrV === 28)
|
|
284
|
+
return 1;
|
|
285
|
+
throw new Error("Invalid yParityOrV value");
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// ../../node_modules/viem/_esm/utils/signature/recoverAddress.js
|
|
289
|
+
async function recoverAddress({ hash, signature }) {
|
|
290
|
+
return publicKeyToAddress(await recoverPublicKey({ hash, signature }));
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// ../../node_modules/viem/_esm/utils/signature/recoverTypedDataAddress.js
|
|
294
|
+
async function recoverTypedDataAddress(parameters) {
|
|
295
|
+
const { domain, message, primaryType, signature, types } = parameters;
|
|
296
|
+
return recoverAddress({
|
|
297
|
+
hash: hashTypedData({
|
|
298
|
+
domain,
|
|
299
|
+
message,
|
|
300
|
+
primaryType,
|
|
301
|
+
types
|
|
302
|
+
}),
|
|
303
|
+
signature
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// ../../node_modules/viem/_esm/utils/signature/verifyTypedData.js
|
|
308
|
+
async function verifyTypedData(parameters) {
|
|
309
|
+
const { address, domain, message, primaryType, signature, types } = parameters;
|
|
310
|
+
return isAddressEqual(getAddress(address), await recoverTypedDataAddress({
|
|
311
|
+
domain,
|
|
312
|
+
message,
|
|
313
|
+
primaryType,
|
|
314
|
+
signature,
|
|
315
|
+
types
|
|
316
|
+
}));
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
export {
|
|
320
|
+
hashTypedData,
|
|
321
|
+
hashStruct,
|
|
322
|
+
serializeTypedData,
|
|
323
|
+
validateTypedData,
|
|
324
|
+
recoverTypedDataAddress,
|
|
325
|
+
verifyTypedData
|
|
326
|
+
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import "./chunk-OFIEVWYB.js";
|
|
1
2
|
import {
|
|
2
3
|
decodeAbiParameters,
|
|
3
4
|
encodeAbiParameters,
|
|
4
5
|
encodeFunctionData
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import "./chunk-XN4LUOIH.js";
|
|
6
|
+
} from "./chunk-GCI53Z2G.js";
|
|
7
7
|
import "./chunk-4VNS5WPM.js";
|
|
8
8
|
export {
|
|
9
9
|
decodeAbiParameters,
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export { hashStruct, hashTypedData, recoverTypedDataAddress, serializeTypedData, validateTypedData, verifyTypedData } from 'viem/utils';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file viem internal typedData utils exported for direct usage
|
|
5
|
+
*
|
|
6
|
+
* @license MIT
|
|
7
|
+
* Copyright (c) 2023-present weth, LLC
|
|
8
|
+
* Copied from https://github.com/wevm/viem/blob/ea0b9d4c391567dd811acbfd889121bb9cb1c26c/src/utils/signature/hashTypedData.ts
|
|
9
|
+
*/
|
|
10
|
+
type MessageTypeProperty = {
|
|
11
|
+
name: string;
|
|
12
|
+
type: string;
|
|
13
|
+
};
|
|
14
|
+
declare function encodeType({ primaryType, types, }: {
|
|
15
|
+
primaryType: string;
|
|
16
|
+
types: Record<string, readonly MessageTypeProperty[]>;
|
|
17
|
+
}): string;
|
|
18
|
+
|
|
19
|
+
export { encodeType };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {
|
|
2
|
+
hashStruct,
|
|
3
|
+
hashTypedData,
|
|
4
|
+
recoverTypedDataAddress,
|
|
5
|
+
serializeTypedData,
|
|
6
|
+
validateTypedData,
|
|
7
|
+
verifyTypedData
|
|
8
|
+
} from "./chunk-OFIEVWYB.js";
|
|
9
|
+
import "./chunk-GCI53Z2G.js";
|
|
10
|
+
import "./chunk-4VNS5WPM.js";
|
|
11
|
+
|
|
12
|
+
// src/utils/viem-utils/hashTypedData.ts
|
|
13
|
+
function encodeType({
|
|
14
|
+
primaryType,
|
|
15
|
+
types
|
|
16
|
+
}) {
|
|
17
|
+
let result = "";
|
|
18
|
+
const unsortedDeps = findTypeDependencies({ primaryType, types });
|
|
19
|
+
unsortedDeps.delete(primaryType);
|
|
20
|
+
const deps = [primaryType, ...Array.from(unsortedDeps).sort()];
|
|
21
|
+
for (const type of deps) {
|
|
22
|
+
result += `${type}(${types[type].map(({ name, type: t }) => `${t} ${name}`).join(",")})`;
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
function findTypeDependencies({
|
|
27
|
+
primaryType: primaryType_,
|
|
28
|
+
types
|
|
29
|
+
}, results = /* @__PURE__ */ new Set()) {
|
|
30
|
+
const match = primaryType_.match(/^\w*/u);
|
|
31
|
+
const primaryType = match?.[0];
|
|
32
|
+
if (results.has(primaryType) || types[primaryType] === void 0) {
|
|
33
|
+
return results;
|
|
34
|
+
}
|
|
35
|
+
results.add(primaryType);
|
|
36
|
+
for (const field of types[primaryType]) {
|
|
37
|
+
findTypeDependencies({ primaryType: field.type, types }, results);
|
|
38
|
+
}
|
|
39
|
+
return results;
|
|
40
|
+
}
|
|
41
|
+
export {
|
|
42
|
+
encodeType,
|
|
43
|
+
hashStruct,
|
|
44
|
+
hashTypedData,
|
|
45
|
+
recoverTypedDataAddress,
|
|
46
|
+
serializeTypedData,
|
|
47
|
+
validateTypedData,
|
|
48
|
+
verifyTypedData
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* @file viem internal typedData utils exported for direct usage
|
|
52
|
+
*
|
|
53
|
+
* @license MIT
|
|
54
|
+
* Copyright (c) 2023-present weth, LLC
|
|
55
|
+
* Copied from https://github.com/wevm/viem/blob/ea0b9d4c391567dd811acbfd889121bb9cb1c26c/src/utils/signature/hashTypedData.ts
|
|
56
|
+
*/
|
package/tsup.config.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { defineConfig } from 'tsup';
|
|
6
6
|
|
|
7
7
|
export default defineConfig({
|
|
8
|
-
entry: ['src/stubs/viem-abi.ts'],
|
|
8
|
+
entry: ['src/stubs/viem-abi.ts', 'src/stubs/viem-typedData.ts'],
|
|
9
9
|
format: ['esm'],
|
|
10
10
|
outDir: 'src/vendor/viem',
|
|
11
11
|
target: 'es2020',
|
|
@@ -13,5 +13,16 @@ export default defineConfig({
|
|
|
13
13
|
dts: true,
|
|
14
14
|
bundle: true,
|
|
15
15
|
platform: 'neutral',
|
|
16
|
-
external: [
|
|
16
|
+
external: [
|
|
17
|
+
'stream',
|
|
18
|
+
'crypto',
|
|
19
|
+
'http',
|
|
20
|
+
'https',
|
|
21
|
+
'zlib',
|
|
22
|
+
'net',
|
|
23
|
+
'tls',
|
|
24
|
+
'url',
|
|
25
|
+
'@noble/hashes',
|
|
26
|
+
'@noble/curves',
|
|
27
|
+
],
|
|
17
28
|
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"viem-abi.d.ts","sourceRoot":"","sources":["viem-abi.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
// ../../node_modules/@noble/curves/esm/abstract/utils.js
|
|
2
|
-
var _0n = /* @__PURE__ */ BigInt(0);
|
|
3
|
-
var _1n = /* @__PURE__ */ BigInt(1);
|
|
4
|
-
function isBytes(a) {
|
|
5
|
-
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
6
|
-
}
|
|
7
|
-
function abytes(item) {
|
|
8
|
-
if (!isBytes(item))
|
|
9
|
-
throw new Error("Uint8Array expected");
|
|
10
|
-
}
|
|
11
|
-
function abool(title, value) {
|
|
12
|
-
if (typeof value !== "boolean")
|
|
13
|
-
throw new Error(title + " boolean expected, got " + value);
|
|
14
|
-
}
|
|
15
|
-
function numberToHexUnpadded(num) {
|
|
16
|
-
const hex = num.toString(16);
|
|
17
|
-
return hex.length & 1 ? "0" + hex : hex;
|
|
18
|
-
}
|
|
19
|
-
function hexToNumber(hex) {
|
|
20
|
-
if (typeof hex !== "string")
|
|
21
|
-
throw new Error("hex string expected, got " + typeof hex);
|
|
22
|
-
return hex === "" ? _0n : BigInt("0x" + hex);
|
|
23
|
-
}
|
|
24
|
-
var hasHexBuiltin = (
|
|
25
|
-
// @ts-ignore
|
|
26
|
-
typeof Uint8Array.from([]).toHex === "function" && typeof Uint8Array.fromHex === "function"
|
|
27
|
-
);
|
|
28
|
-
var hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
|
|
29
|
-
function bytesToHex(bytes) {
|
|
30
|
-
abytes(bytes);
|
|
31
|
-
if (hasHexBuiltin)
|
|
32
|
-
return bytes.toHex();
|
|
33
|
-
let hex = "";
|
|
34
|
-
for (let i = 0; i < bytes.length; i++) {
|
|
35
|
-
hex += hexes[bytes[i]];
|
|
36
|
-
}
|
|
37
|
-
return hex;
|
|
38
|
-
}
|
|
39
|
-
var asciis = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
|
|
40
|
-
function asciiToBase16(ch) {
|
|
41
|
-
if (ch >= asciis._0 && ch <= asciis._9)
|
|
42
|
-
return ch - asciis._0;
|
|
43
|
-
if (ch >= asciis.A && ch <= asciis.F)
|
|
44
|
-
return ch - (asciis.A - 10);
|
|
45
|
-
if (ch >= asciis.a && ch <= asciis.f)
|
|
46
|
-
return ch - (asciis.a - 10);
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
function hexToBytes(hex) {
|
|
50
|
-
if (typeof hex !== "string")
|
|
51
|
-
throw new Error("hex string expected, got " + typeof hex);
|
|
52
|
-
if (hasHexBuiltin)
|
|
53
|
-
return Uint8Array.fromHex(hex);
|
|
54
|
-
const hl = hex.length;
|
|
55
|
-
const al = hl / 2;
|
|
56
|
-
if (hl % 2)
|
|
57
|
-
throw new Error("hex string expected, got unpadded hex of length " + hl);
|
|
58
|
-
const array = new Uint8Array(al);
|
|
59
|
-
for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
|
|
60
|
-
const n1 = asciiToBase16(hex.charCodeAt(hi));
|
|
61
|
-
const n2 = asciiToBase16(hex.charCodeAt(hi + 1));
|
|
62
|
-
if (n1 === void 0 || n2 === void 0) {
|
|
63
|
-
const char = hex[hi] + hex[hi + 1];
|
|
64
|
-
throw new Error('hex string expected, got non-hex character "' + char + '" at index ' + hi);
|
|
65
|
-
}
|
|
66
|
-
array[ai] = n1 * 16 + n2;
|
|
67
|
-
}
|
|
68
|
-
return array;
|
|
69
|
-
}
|
|
70
|
-
function bytesToNumberBE(bytes) {
|
|
71
|
-
return hexToNumber(bytesToHex(bytes));
|
|
72
|
-
}
|
|
73
|
-
function bytesToNumberLE(bytes) {
|
|
74
|
-
abytes(bytes);
|
|
75
|
-
return hexToNumber(bytesToHex(Uint8Array.from(bytes).reverse()));
|
|
76
|
-
}
|
|
77
|
-
function numberToBytesBE(n, len) {
|
|
78
|
-
return hexToBytes(n.toString(16).padStart(len * 2, "0"));
|
|
79
|
-
}
|
|
80
|
-
function numberToBytesLE(n, len) {
|
|
81
|
-
return numberToBytesBE(n, len).reverse();
|
|
82
|
-
}
|
|
83
|
-
function ensureBytes(title, hex, expectedLength) {
|
|
84
|
-
let res;
|
|
85
|
-
if (typeof hex === "string") {
|
|
86
|
-
try {
|
|
87
|
-
res = hexToBytes(hex);
|
|
88
|
-
} catch (e) {
|
|
89
|
-
throw new Error(title + " must be hex string or Uint8Array, cause: " + e);
|
|
90
|
-
}
|
|
91
|
-
} else if (isBytes(hex)) {
|
|
92
|
-
res = Uint8Array.from(hex);
|
|
93
|
-
} else {
|
|
94
|
-
throw new Error(title + " must be hex string or Uint8Array");
|
|
95
|
-
}
|
|
96
|
-
const len = res.length;
|
|
97
|
-
if (typeof expectedLength === "number" && len !== expectedLength)
|
|
98
|
-
throw new Error(title + " of length " + expectedLength + " expected, got " + len);
|
|
99
|
-
return res;
|
|
100
|
-
}
|
|
101
|
-
function concatBytes(...arrays) {
|
|
102
|
-
let sum = 0;
|
|
103
|
-
for (let i = 0; i < arrays.length; i++) {
|
|
104
|
-
const a = arrays[i];
|
|
105
|
-
abytes(a);
|
|
106
|
-
sum += a.length;
|
|
107
|
-
}
|
|
108
|
-
const res = new Uint8Array(sum);
|
|
109
|
-
for (let i = 0, pad = 0; i < arrays.length; i++) {
|
|
110
|
-
const a = arrays[i];
|
|
111
|
-
res.set(a, pad);
|
|
112
|
-
pad += a.length;
|
|
113
|
-
}
|
|
114
|
-
return res;
|
|
115
|
-
}
|
|
116
|
-
function utf8ToBytes(str) {
|
|
117
|
-
if (typeof str !== "string")
|
|
118
|
-
throw new Error("string expected");
|
|
119
|
-
return new Uint8Array(new TextEncoder().encode(str));
|
|
120
|
-
}
|
|
121
|
-
var isPosBig = (n) => typeof n === "bigint" && _0n <= n;
|
|
122
|
-
function inRange(n, min, max) {
|
|
123
|
-
return isPosBig(n) && isPosBig(min) && isPosBig(max) && min <= n && n < max;
|
|
124
|
-
}
|
|
125
|
-
function aInRange(title, n, min, max) {
|
|
126
|
-
if (!inRange(n, min, max))
|
|
127
|
-
throw new Error("expected valid " + title + ": " + min + " <= n < " + max + ", got " + n);
|
|
128
|
-
}
|
|
129
|
-
function bitLen(n) {
|
|
130
|
-
let len;
|
|
131
|
-
for (len = 0; n > _0n; n >>= _1n, len += 1)
|
|
132
|
-
;
|
|
133
|
-
return len;
|
|
134
|
-
}
|
|
135
|
-
var bitMask = (n) => (_1n << BigInt(n)) - _1n;
|
|
136
|
-
var u8n = (len) => new Uint8Array(len);
|
|
137
|
-
var u8fr = (arr) => Uint8Array.from(arr);
|
|
138
|
-
function createHmacDrbg(hashLen, qByteLen, hmacFn) {
|
|
139
|
-
if (typeof hashLen !== "number" || hashLen < 2)
|
|
140
|
-
throw new Error("hashLen must be a number");
|
|
141
|
-
if (typeof qByteLen !== "number" || qByteLen < 2)
|
|
142
|
-
throw new Error("qByteLen must be a number");
|
|
143
|
-
if (typeof hmacFn !== "function")
|
|
144
|
-
throw new Error("hmacFn must be a function");
|
|
145
|
-
let v = u8n(hashLen);
|
|
146
|
-
let k = u8n(hashLen);
|
|
147
|
-
let i = 0;
|
|
148
|
-
const reset = () => {
|
|
149
|
-
v.fill(1);
|
|
150
|
-
k.fill(0);
|
|
151
|
-
i = 0;
|
|
152
|
-
};
|
|
153
|
-
const h = (...b) => hmacFn(k, v, ...b);
|
|
154
|
-
const reseed = (seed = u8n(0)) => {
|
|
155
|
-
k = h(u8fr([0]), seed);
|
|
156
|
-
v = h();
|
|
157
|
-
if (seed.length === 0)
|
|
158
|
-
return;
|
|
159
|
-
k = h(u8fr([1]), seed);
|
|
160
|
-
v = h();
|
|
161
|
-
};
|
|
162
|
-
const gen = () => {
|
|
163
|
-
if (i++ >= 1e3)
|
|
164
|
-
throw new Error("drbg: tried 1000 values");
|
|
165
|
-
let len = 0;
|
|
166
|
-
const out = [];
|
|
167
|
-
while (len < qByteLen) {
|
|
168
|
-
v = h();
|
|
169
|
-
const sl = v.slice();
|
|
170
|
-
out.push(sl);
|
|
171
|
-
len += v.length;
|
|
172
|
-
}
|
|
173
|
-
return concatBytes(...out);
|
|
174
|
-
};
|
|
175
|
-
const genUntil = (seed, pred) => {
|
|
176
|
-
reset();
|
|
177
|
-
reseed(seed);
|
|
178
|
-
let res = void 0;
|
|
179
|
-
while (!(res = pred(gen())))
|
|
180
|
-
reseed();
|
|
181
|
-
reset();
|
|
182
|
-
return res;
|
|
183
|
-
};
|
|
184
|
-
return genUntil;
|
|
185
|
-
}
|
|
186
|
-
var validatorFns = {
|
|
187
|
-
bigint: (val) => typeof val === "bigint",
|
|
188
|
-
function: (val) => typeof val === "function",
|
|
189
|
-
boolean: (val) => typeof val === "boolean",
|
|
190
|
-
string: (val) => typeof val === "string",
|
|
191
|
-
stringOrUint8Array: (val) => typeof val === "string" || isBytes(val),
|
|
192
|
-
isSafeInteger: (val) => Number.isSafeInteger(val),
|
|
193
|
-
array: (val) => Array.isArray(val),
|
|
194
|
-
field: (val, object) => object.Fp.isValid(val),
|
|
195
|
-
hash: (val) => typeof val === "function" && Number.isSafeInteger(val.outputLen)
|
|
196
|
-
};
|
|
197
|
-
function validateObject(object, validators, optValidators = {}) {
|
|
198
|
-
const checkField = (fieldName, type, isOptional) => {
|
|
199
|
-
const checkVal = validatorFns[type];
|
|
200
|
-
if (typeof checkVal !== "function")
|
|
201
|
-
throw new Error("invalid validator function");
|
|
202
|
-
const val = object[fieldName];
|
|
203
|
-
if (isOptional && val === void 0)
|
|
204
|
-
return;
|
|
205
|
-
if (!checkVal(val, object)) {
|
|
206
|
-
throw new Error("param " + String(fieldName) + " is invalid. Expected " + type + ", got " + val);
|
|
207
|
-
}
|
|
208
|
-
};
|
|
209
|
-
for (const [fieldName, type] of Object.entries(validators))
|
|
210
|
-
checkField(fieldName, type, false);
|
|
211
|
-
for (const [fieldName, type] of Object.entries(optValidators))
|
|
212
|
-
checkField(fieldName, type, true);
|
|
213
|
-
return object;
|
|
214
|
-
}
|
|
215
|
-
function memoized(fn) {
|
|
216
|
-
const map = /* @__PURE__ */ new WeakMap();
|
|
217
|
-
return (arg, ...args) => {
|
|
218
|
-
const val = map.get(arg);
|
|
219
|
-
if (val !== void 0)
|
|
220
|
-
return val;
|
|
221
|
-
const computed = fn(arg, ...args);
|
|
222
|
-
map.set(arg, computed);
|
|
223
|
-
return computed;
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
export {
|
|
228
|
-
isBytes,
|
|
229
|
-
abytes,
|
|
230
|
-
abool,
|
|
231
|
-
numberToHexUnpadded,
|
|
232
|
-
bytesToHex,
|
|
233
|
-
hexToBytes,
|
|
234
|
-
bytesToNumberBE,
|
|
235
|
-
bytesToNumberLE,
|
|
236
|
-
numberToBytesBE,
|
|
237
|
-
numberToBytesLE,
|
|
238
|
-
ensureBytes,
|
|
239
|
-
concatBytes,
|
|
240
|
-
utf8ToBytes,
|
|
241
|
-
inRange,
|
|
242
|
-
aInRange,
|
|
243
|
-
bitLen,
|
|
244
|
-
bitMask,
|
|
245
|
-
createHmacDrbg,
|
|
246
|
-
validateObject,
|
|
247
|
-
memoized
|
|
248
|
-
};
|
|
249
|
-
/*! Bundled license information:
|
|
250
|
-
|
|
251
|
-
@noble/curves/esm/abstract/utils.js:
|
|
252
|
-
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
253
|
-
*/
|