eth-twc-sdk-js 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -0
- package/dist/abi.cjs +286 -0
- package/dist/abi.d.cts +419 -0
- package/dist/abi.d.ts +419 -0
- package/dist/abi.js +259 -0
- package/dist/config.cjs +41 -0
- package/dist/config.d.cts +14 -0
- package/dist/config.d.ts +14 -0
- package/dist/config.js +11 -0
- package/dist/selfTransfer/batch/index.cjs +373 -0
- package/dist/selfTransfer/batch/index.d.cts +24 -0
- package/dist/selfTransfer/batch/index.d.ts +24 -0
- package/dist/selfTransfer/batch/index.js +345 -0
- package/dist/selfTransfer/single/index.cjs +360 -0
- package/dist/selfTransfer/single/index.d.cts +20 -0
- package/dist/selfTransfer/single/index.d.ts +20 -0
- package/dist/selfTransfer/single/index.js +332 -0
- package/dist/selfTransfer/unified/index.cjs +372 -0
- package/dist/selfTransfer/unified/index.d.cts +24 -0
- package/dist/selfTransfer/unified/index.d.ts +24 -0
- package/dist/selfTransfer/unified/index.js +344 -0
- package/dist/signatureTransfer/batch/index.cjs +545 -0
- package/dist/signatureTransfer/batch/index.d.cts +100 -0
- package/dist/signatureTransfer/batch/index.d.ts +100 -0
- package/dist/signatureTransfer/batch/index.js +514 -0
- package/dist/signatureTransfer/cancelAuthorization/index.cjs +491 -0
- package/dist/signatureTransfer/cancelAuthorization/index.d.cts +49 -0
- package/dist/signatureTransfer/cancelAuthorization/index.d.ts +49 -0
- package/dist/signatureTransfer/cancelAuthorization/index.js +460 -0
- package/dist/signatureTransfer/single/index.cjs +528 -0
- package/dist/signatureTransfer/single/index.d.cts +84 -0
- package/dist/signatureTransfer/single/index.d.ts +84 -0
- package/dist/signatureTransfer/single/index.js +497 -0
- package/dist/signatureTransfer/unified/index.cjs +541 -0
- package/dist/signatureTransfer/unified/index.d.cts +95 -0
- package/dist/signatureTransfer/unified/index.d.ts +95 -0
- package/dist/signatureTransfer/unified/index.js +510 -0
- package/dist/types/transferDetail.cjs +62 -0
- package/dist/types/transferDetail.d.cts +15 -0
- package/dist/types/transferDetail.d.ts +15 -0
- package/dist/types/transferDetail.js +36 -0
- package/dist/types/utils.cjs +52 -0
- package/dist/types/utils.d.cts +12 -0
- package/dist/types/utils.d.ts +12 -0
- package/dist/types/utils.js +23 -0
- package/dist/utils.cjs +123 -0
- package/dist/utils.d.cts +21 -0
- package/dist/utils.d.ts +21 -0
- package/dist/utils.js +90 -0
- package/dist/verify.cjs +366 -0
- package/dist/verify.d.cts +433 -0
- package/dist/verify.d.ts +433 -0
- package/dist/verify.js +339 -0
- package/package.json +100 -0
|
@@ -0,0 +1,541 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// signatureTransfer/unified/index.ts
|
|
21
|
+
var unified_exports = {};
|
|
22
|
+
__export(unified_exports, {
|
|
23
|
+
argsSchema: () => argsSchema,
|
|
24
|
+
eip712Types: () => eip712Types,
|
|
25
|
+
sendTx: () => sendTx,
|
|
26
|
+
sign: () => sign,
|
|
27
|
+
signedDataSchema: () => signedDataSchema
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(unified_exports);
|
|
30
|
+
|
|
31
|
+
// twcConstants.ts
|
|
32
|
+
var EIP712_DOMAIN_NAME = "TransferWithCommitment";
|
|
33
|
+
var EIP712_DOMAIN_VERSION = "1";
|
|
34
|
+
var transferWithCommitmentAddress = "0x5C260DD537A9c23Bbd42493e59F3CeA7da2DbC71";
|
|
35
|
+
|
|
36
|
+
// utils.ts
|
|
37
|
+
var chainIdToBig = (id) => typeof id === "bigint" ? id : BigInt(id);
|
|
38
|
+
var assertPublicWalletSameChain = (publicClient, wallet) => {
|
|
39
|
+
const publicId = publicClient.chain?.id;
|
|
40
|
+
const walletId = wallet.chain?.id;
|
|
41
|
+
if (publicId === void 0 || walletId === void 0) {
|
|
42
|
+
throw new Error(
|
|
43
|
+
"Chain is not set on public client and/or wallet client"
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
if (publicId !== walletId) {
|
|
47
|
+
throw new Error(
|
|
48
|
+
`PublicClient and WalletClient chain mismatch: ${publicId} vs ${walletId}`
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
async function assertTransferContractDeployed(publicClient, contractAddress = transferWithCommitmentAddress) {
|
|
53
|
+
const code = await publicClient.getCode({ address: contractAddress });
|
|
54
|
+
if (code === void 0 || code === "0x") {
|
|
55
|
+
throw new Error(
|
|
56
|
+
`TransferWithCommitment is not deployed at ${contractAddress} on this chain (no contract code). Deploy with CREATE2 (see contracts/TWC_CREATE2.md) or switch network.`
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function assertEip712DomainFromContractMatchesExpected(publicClient, eip712) {
|
|
61
|
+
const chainId = publicClient.chain?.id;
|
|
62
|
+
if (chainId === void 0) {
|
|
63
|
+
throw new Error("Chain is not set on public client");
|
|
64
|
+
}
|
|
65
|
+
const d = eip712.domain;
|
|
66
|
+
if (d.name !== EIP712_DOMAIN_NAME) {
|
|
67
|
+
throw new Error(
|
|
68
|
+
`Unexpected EIP-712 domain name: expected "${EIP712_DOMAIN_NAME}", got "${String(d.name)}"`
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
if (d.version !== EIP712_DOMAIN_VERSION) {
|
|
72
|
+
throw new Error(
|
|
73
|
+
`Unexpected EIP-712 domain version: expected "${EIP712_DOMAIN_VERSION}", got "${String(d.version)}"`
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
const vc = d.verifyingContract;
|
|
77
|
+
if (vc === void 0 || vc.toLowerCase() !== transferWithCommitmentAddress.toLowerCase()) {
|
|
78
|
+
throw new Error(
|
|
79
|
+
`Unexpected EIP-712 verifyingContract: expected ${transferWithCommitmentAddress}, got ${String(vc)}`
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
if (d.chainId !== void 0 && chainIdToBig(d.chainId) !== BigInt(chainId)) {
|
|
83
|
+
throw new Error(
|
|
84
|
+
`EIP-712 domain.chainId (${d.chainId}) does not match public client chain id (${chainId})`
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
var assertSignerMatchesEip712Role = (signer, messageAddress, role) => {
|
|
89
|
+
if (signer.toLowerCase() !== messageAddress.toLowerCase()) {
|
|
90
|
+
throw new Error(
|
|
91
|
+
`Signer account (${signer}) does not match EIP-712 message ${role} (${messageAddress})`
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
var assertSignedDomainMatchesClientAndConfig = (publicClient, domain, configuredContract) => {
|
|
96
|
+
const publicId = publicClient.chain?.id;
|
|
97
|
+
if (publicId === void 0) {
|
|
98
|
+
throw new Error("Chain is not set on public client");
|
|
99
|
+
}
|
|
100
|
+
if (chainIdToBig(domain.chainId) !== BigInt(publicId)) {
|
|
101
|
+
throw new Error(
|
|
102
|
+
`Signed data domain.chainId (${domain.chainId}) does not match client chain id (${publicId})`
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
if (domain.verifyingContract.toLowerCase() !== configuredContract.toLowerCase()) {
|
|
106
|
+
throw new Error(
|
|
107
|
+
`Signed data domain.verifyingContract (${domain.verifyingContract}) does not match transferWithCommitmentAddress (${configuredContract})`
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
// signatureTransfer/shared/domain.ts
|
|
113
|
+
var ZERO_SALT = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
114
|
+
function domainForTypedDataSign(raw) {
|
|
115
|
+
if (raw.salt !== void 0 && typeof raw.salt === "string" && raw.salt.toLowerCase() === ZERO_SALT) {
|
|
116
|
+
const { salt: _s, ...rest } = raw;
|
|
117
|
+
return rest;
|
|
118
|
+
}
|
|
119
|
+
return raw;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// signatureTransfer/unified/eip712Types.ts
|
|
123
|
+
var eip712Types = {
|
|
124
|
+
UniCommitTransfers: [
|
|
125
|
+
{ name: "from", type: "address" },
|
|
126
|
+
{ name: "executor", type: "address" },
|
|
127
|
+
{ name: "details", type: "TransferDetail[]" },
|
|
128
|
+
{ name: "validAfter", type: "uint256" },
|
|
129
|
+
{ name: "validBefore", type: "uint256" },
|
|
130
|
+
{ name: "commitment", type: "bytes32" }
|
|
131
|
+
],
|
|
132
|
+
TransferDetail: [
|
|
133
|
+
{ name: "to", type: "address" },
|
|
134
|
+
{ name: "token", type: "address" },
|
|
135
|
+
{ name: "value", type: "uint256" }
|
|
136
|
+
]
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
// signatureTransfer/unified/types.ts
|
|
140
|
+
var import_arktype4 = require("arktype");
|
|
141
|
+
|
|
142
|
+
// types/utils.ts
|
|
143
|
+
var import_arktype = require("arktype");
|
|
144
|
+
var UINT256_MAX = (1n << 256n) - 1n;
|
|
145
|
+
var uint256 = (0, import_arktype.type)("bigint").filter(
|
|
146
|
+
(v, ctx) => v <= UINT256_MAX && v >= 0n ? true : ctx.reject(`must be: 0n <= value <= ${UINT256_MAX}`)
|
|
147
|
+
);
|
|
148
|
+
var reBytes32 = /^0x[0-9a-fA-F]{64}$/;
|
|
149
|
+
var reBytes = /^0x[0-9a-fA-F]+$/;
|
|
150
|
+
var reAddress = /^0x[0-9a-fA-F]{40}$/;
|
|
151
|
+
var bytes32 = (0, import_arktype.type)("string").narrow(
|
|
152
|
+
(s) => reBytes32.test(s)
|
|
153
|
+
);
|
|
154
|
+
var bytes = (0, import_arktype.type)("string").narrow((s) => reBytes.test(s));
|
|
155
|
+
var address = (0, import_arktype.type)("string").narrow(
|
|
156
|
+
(s) => reAddress.test(s)
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
// signatureTransfer/shared/signedDomain.ts
|
|
160
|
+
var import_arktype2 = require("arktype");
|
|
161
|
+
var chainIdAsDomain = (0, import_arktype2.type)("number").or(uint256);
|
|
162
|
+
var signedDomainSchema = (0, import_arktype2.type)({
|
|
163
|
+
name: (0, import_arktype2.type)("string"),
|
|
164
|
+
version: (0, import_arktype2.type)("string"),
|
|
165
|
+
chainId: chainIdAsDomain,
|
|
166
|
+
verifyingContract: address,
|
|
167
|
+
salt: bytes32.optional()
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
// types/transferDetail.ts
|
|
171
|
+
var import_arktype3 = require("arktype");
|
|
172
|
+
var transferDetail = (0, import_arktype3.type)({
|
|
173
|
+
to: address,
|
|
174
|
+
token: address,
|
|
175
|
+
value: uint256
|
|
176
|
+
});
|
|
177
|
+
var committedTransferDetail = (0, import_arktype3.type)({
|
|
178
|
+
to: address,
|
|
179
|
+
token: address,
|
|
180
|
+
value: uint256,
|
|
181
|
+
commitment: bytes32
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
// signatureTransfer/unified/types.ts
|
|
185
|
+
var argsSchema = (0, import_arktype4.type)({
|
|
186
|
+
from: address,
|
|
187
|
+
executor: address,
|
|
188
|
+
details: transferDetail.array(),
|
|
189
|
+
validAfter: uint256.default(0n),
|
|
190
|
+
validBefore: uint256.default(UINT256_MAX),
|
|
191
|
+
commitment: bytes32
|
|
192
|
+
}).narrow((v) => v.details.length > 0 && v.validAfter <= v.validBefore);
|
|
193
|
+
var signedUnifiedSchema = (0, import_arktype4.type)({
|
|
194
|
+
domain: signedDomainSchema,
|
|
195
|
+
from: address,
|
|
196
|
+
details: transferDetail.array(),
|
|
197
|
+
validAfter: uint256,
|
|
198
|
+
validBefore: uint256,
|
|
199
|
+
commitment: bytes32,
|
|
200
|
+
signature: bytes
|
|
201
|
+
}).narrow(
|
|
202
|
+
(v) => v.validAfter <= v.validBefore && v.details.length > 0
|
|
203
|
+
);
|
|
204
|
+
var signedDataSchema = signedUnifiedSchema;
|
|
205
|
+
|
|
206
|
+
// signatureTransfer/unified/sign.ts
|
|
207
|
+
var sign = async (publicClient, wallet, account, args) => {
|
|
208
|
+
assertPublicWalletSameChain(publicClient, wallet);
|
|
209
|
+
const a = argsSchema.assert(args);
|
|
210
|
+
assertSignerMatchesEip712Role(account, a.from, "from");
|
|
211
|
+
await assertTransferContractDeployed(publicClient);
|
|
212
|
+
const rawEip712 = await publicClient.getEip712Domain({
|
|
213
|
+
address: transferWithCommitmentAddress
|
|
214
|
+
});
|
|
215
|
+
assertEip712DomainFromContractMatchesExpected(publicClient, rawEip712);
|
|
216
|
+
const domain = domainForTypedDataSign(rawEip712.domain);
|
|
217
|
+
const signature = await wallet.signTypedData({
|
|
218
|
+
account,
|
|
219
|
+
domain,
|
|
220
|
+
types: eip712Types,
|
|
221
|
+
primaryType: "UniCommitTransfers",
|
|
222
|
+
message: {
|
|
223
|
+
from: a.from,
|
|
224
|
+
executor: a.executor,
|
|
225
|
+
details: a.details,
|
|
226
|
+
validAfter: a.validAfter,
|
|
227
|
+
validBefore: a.validBefore,
|
|
228
|
+
commitment: a.commitment
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
return {
|
|
232
|
+
domain,
|
|
233
|
+
from: a.from,
|
|
234
|
+
details: a.details,
|
|
235
|
+
commitment: a.commitment,
|
|
236
|
+
validAfter: a.validAfter,
|
|
237
|
+
validBefore: a.validBefore,
|
|
238
|
+
signature
|
|
239
|
+
};
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
// ../contracts/abi/generated.ts
|
|
243
|
+
var transferWithCommitmentAbi = [
|
|
244
|
+
{
|
|
245
|
+
type: "constructor",
|
|
246
|
+
inputs: [
|
|
247
|
+
{ name: "name", internalType: "string", type: "string" },
|
|
248
|
+
{ name: "version", internalType: "string", type: "string" }
|
|
249
|
+
],
|
|
250
|
+
stateMutability: "nonpayable"
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
type: "function",
|
|
254
|
+
inputs: [],
|
|
255
|
+
name: "BATCH_TRANSFER_WITH_COMMIT_TYPEHASH",
|
|
256
|
+
outputs: [{ name: "", internalType: "bytes32", type: "bytes32" }],
|
|
257
|
+
stateMutability: "view"
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
type: "function",
|
|
261
|
+
inputs: [],
|
|
262
|
+
name: "CANCEL_AUTHORIZATION_TYPEHASH",
|
|
263
|
+
outputs: [{ name: "", internalType: "bytes32", type: "bytes32" }],
|
|
264
|
+
stateMutability: "view"
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
type: "function",
|
|
268
|
+
inputs: [],
|
|
269
|
+
name: "TRANSFER_WITH_COMMIT_TYPEHASH",
|
|
270
|
+
outputs: [{ name: "", internalType: "bytes32", type: "bytes32" }],
|
|
271
|
+
stateMutability: "view"
|
|
272
|
+
},
|
|
273
|
+
{
|
|
274
|
+
type: "function",
|
|
275
|
+
inputs: [],
|
|
276
|
+
name: "UNI_COMMIT_TRANSFER_TYPEHASH",
|
|
277
|
+
outputs: [{ name: "", internalType: "bytes32", type: "bytes32" }],
|
|
278
|
+
stateMutability: "view"
|
|
279
|
+
},
|
|
280
|
+
{
|
|
281
|
+
type: "function",
|
|
282
|
+
inputs: [
|
|
283
|
+
{ name: "authorizer", internalType: "address", type: "address" },
|
|
284
|
+
{ name: "commitment", internalType: "bytes32", type: "bytes32" },
|
|
285
|
+
{ name: "signature", internalType: "bytes", type: "bytes" }
|
|
286
|
+
],
|
|
287
|
+
name: "cancelAuthorization",
|
|
288
|
+
outputs: [],
|
|
289
|
+
stateMutability: "nonpayable"
|
|
290
|
+
},
|
|
291
|
+
{
|
|
292
|
+
type: "function",
|
|
293
|
+
inputs: [
|
|
294
|
+
{ name: "payer", internalType: "address", type: "address" },
|
|
295
|
+
{ name: "commitment", internalType: "bytes32", type: "bytes32" }
|
|
296
|
+
],
|
|
297
|
+
name: "commitmentState",
|
|
298
|
+
outputs: [{ name: "", internalType: "bool", type: "bool" }],
|
|
299
|
+
stateMutability: "view"
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
type: "function",
|
|
303
|
+
inputs: [],
|
|
304
|
+
name: "eip712Domain",
|
|
305
|
+
outputs: [
|
|
306
|
+
{ name: "fields", internalType: "bytes1", type: "bytes1" },
|
|
307
|
+
{ name: "name", internalType: "string", type: "string" },
|
|
308
|
+
{ name: "version", internalType: "string", type: "string" },
|
|
309
|
+
{ name: "chainId", internalType: "uint256", type: "uint256" },
|
|
310
|
+
{ name: "verifyingContract", internalType: "address", type: "address" },
|
|
311
|
+
{ name: "salt", internalType: "bytes32", type: "bytes32" },
|
|
312
|
+
{ name: "extensions", internalType: "uint256[]", type: "uint256[]" }
|
|
313
|
+
],
|
|
314
|
+
stateMutability: "view"
|
|
315
|
+
},
|
|
316
|
+
{
|
|
317
|
+
type: "function",
|
|
318
|
+
inputs: [
|
|
319
|
+
{ name: "token", internalType: "address", type: "address" },
|
|
320
|
+
{ name: "to", internalType: "address", type: "address" },
|
|
321
|
+
{ name: "value", internalType: "uint256", type: "uint256" },
|
|
322
|
+
{ name: "commitment", internalType: "bytes32", type: "bytes32" }
|
|
323
|
+
],
|
|
324
|
+
name: "transfer",
|
|
325
|
+
outputs: [],
|
|
326
|
+
stateMutability: "nonpayable"
|
|
327
|
+
},
|
|
328
|
+
{
|
|
329
|
+
type: "function",
|
|
330
|
+
inputs: [
|
|
331
|
+
{
|
|
332
|
+
name: "details",
|
|
333
|
+
internalType: "struct TransferDetail[]",
|
|
334
|
+
type: "tuple[]",
|
|
335
|
+
components: [
|
|
336
|
+
{ name: "to", internalType: "address", type: "address" },
|
|
337
|
+
{ name: "token", internalType: "address", type: "address" },
|
|
338
|
+
{ name: "value", internalType: "uint256", type: "uint256" }
|
|
339
|
+
]
|
|
340
|
+
},
|
|
341
|
+
{ name: "commitment", internalType: "bytes32", type: "bytes32" }
|
|
342
|
+
],
|
|
343
|
+
name: "transfer",
|
|
344
|
+
outputs: [],
|
|
345
|
+
stateMutability: "nonpayable"
|
|
346
|
+
},
|
|
347
|
+
{
|
|
348
|
+
type: "function",
|
|
349
|
+
inputs: [
|
|
350
|
+
{
|
|
351
|
+
name: "details",
|
|
352
|
+
internalType: "struct CommittedTransferDetail[]",
|
|
353
|
+
type: "tuple[]",
|
|
354
|
+
components: [
|
|
355
|
+
{ name: "to", internalType: "address", type: "address" },
|
|
356
|
+
{ name: "token", internalType: "address", type: "address" },
|
|
357
|
+
{ name: "value", internalType: "uint256", type: "uint256" },
|
|
358
|
+
{ name: "commitment", internalType: "bytes32", type: "bytes32" }
|
|
359
|
+
]
|
|
360
|
+
}
|
|
361
|
+
],
|
|
362
|
+
name: "transfer",
|
|
363
|
+
outputs: [],
|
|
364
|
+
stateMutability: "nonpayable"
|
|
365
|
+
},
|
|
366
|
+
{
|
|
367
|
+
type: "function",
|
|
368
|
+
inputs: [
|
|
369
|
+
{ name: "from", internalType: "address", type: "address" },
|
|
370
|
+
{
|
|
371
|
+
name: "details",
|
|
372
|
+
internalType: "struct TransferDetail[]",
|
|
373
|
+
type: "tuple[]",
|
|
374
|
+
components: [
|
|
375
|
+
{ name: "to", internalType: "address", type: "address" },
|
|
376
|
+
{ name: "token", internalType: "address", type: "address" },
|
|
377
|
+
{ name: "value", internalType: "uint256", type: "uint256" }
|
|
378
|
+
]
|
|
379
|
+
},
|
|
380
|
+
{ name: "validAfter", internalType: "uint256", type: "uint256" },
|
|
381
|
+
{ name: "validBefore", internalType: "uint256", type: "uint256" },
|
|
382
|
+
{ name: "commitment", internalType: "bytes32", type: "bytes32" },
|
|
383
|
+
{ name: "signature", internalType: "bytes", type: "bytes" }
|
|
384
|
+
],
|
|
385
|
+
name: "transferWithAuthorization",
|
|
386
|
+
outputs: [],
|
|
387
|
+
stateMutability: "nonpayable"
|
|
388
|
+
},
|
|
389
|
+
{
|
|
390
|
+
type: "function",
|
|
391
|
+
inputs: [
|
|
392
|
+
{ name: "from", internalType: "address", type: "address" },
|
|
393
|
+
{
|
|
394
|
+
name: "details",
|
|
395
|
+
internalType: "struct CommittedTransferDetail[]",
|
|
396
|
+
type: "tuple[]",
|
|
397
|
+
components: [
|
|
398
|
+
{ name: "to", internalType: "address", type: "address" },
|
|
399
|
+
{ name: "token", internalType: "address", type: "address" },
|
|
400
|
+
{ name: "value", internalType: "uint256", type: "uint256" },
|
|
401
|
+
{ name: "commitment", internalType: "bytes32", type: "bytes32" }
|
|
402
|
+
]
|
|
403
|
+
},
|
|
404
|
+
{ name: "validAfter", internalType: "uint256", type: "uint256" },
|
|
405
|
+
{ name: "validBefore", internalType: "uint256", type: "uint256" },
|
|
406
|
+
{ name: "batchCommitment", internalType: "bytes32", type: "bytes32" },
|
|
407
|
+
{ name: "signature", internalType: "bytes", type: "bytes" }
|
|
408
|
+
],
|
|
409
|
+
name: "transferWithAuthorization",
|
|
410
|
+
outputs: [],
|
|
411
|
+
stateMutability: "nonpayable"
|
|
412
|
+
},
|
|
413
|
+
{
|
|
414
|
+
type: "function",
|
|
415
|
+
inputs: [
|
|
416
|
+
{ name: "from", internalType: "address", type: "address" },
|
|
417
|
+
{ name: "to", internalType: "address", type: "address" },
|
|
418
|
+
{ name: "token", internalType: "address", type: "address" },
|
|
419
|
+
{ name: "value", internalType: "uint256", type: "uint256" },
|
|
420
|
+
{ name: "validAfter", internalType: "uint256", type: "uint256" },
|
|
421
|
+
{ name: "validBefore", internalType: "uint256", type: "uint256" },
|
|
422
|
+
{ name: "commitment", internalType: "bytes32", type: "bytes32" },
|
|
423
|
+
{ name: "signature", internalType: "bytes", type: "bytes" }
|
|
424
|
+
],
|
|
425
|
+
name: "transferWithAuthorization",
|
|
426
|
+
outputs: [],
|
|
427
|
+
stateMutability: "nonpayable"
|
|
428
|
+
},
|
|
429
|
+
{
|
|
430
|
+
type: "event",
|
|
431
|
+
anonymous: false,
|
|
432
|
+
inputs: [
|
|
433
|
+
{
|
|
434
|
+
name: "payer",
|
|
435
|
+
internalType: "address",
|
|
436
|
+
type: "address",
|
|
437
|
+
indexed: true
|
|
438
|
+
},
|
|
439
|
+
{
|
|
440
|
+
name: "commitment",
|
|
441
|
+
internalType: "bytes32",
|
|
442
|
+
type: "bytes32",
|
|
443
|
+
indexed: true
|
|
444
|
+
}
|
|
445
|
+
],
|
|
446
|
+
name: "CommitmentUsed"
|
|
447
|
+
},
|
|
448
|
+
{ type: "event", anonymous: false, inputs: [], name: "EIP712DomainChanged" },
|
|
449
|
+
{
|
|
450
|
+
type: "event",
|
|
451
|
+
anonymous: false,
|
|
452
|
+
inputs: [
|
|
453
|
+
{ name: "from", internalType: "address", type: "address", indexed: true },
|
|
454
|
+
{ name: "to", internalType: "address", type: "address", indexed: true },
|
|
455
|
+
{
|
|
456
|
+
name: "token",
|
|
457
|
+
internalType: "address",
|
|
458
|
+
type: "address",
|
|
459
|
+
indexed: true
|
|
460
|
+
},
|
|
461
|
+
{
|
|
462
|
+
name: "value",
|
|
463
|
+
internalType: "uint256",
|
|
464
|
+
type: "uint256",
|
|
465
|
+
indexed: false
|
|
466
|
+
},
|
|
467
|
+
{
|
|
468
|
+
name: "commitment",
|
|
469
|
+
internalType: "bytes32",
|
|
470
|
+
type: "bytes32",
|
|
471
|
+
indexed: false
|
|
472
|
+
}
|
|
473
|
+
],
|
|
474
|
+
name: "TransferWithCommitmentSent"
|
|
475
|
+
},
|
|
476
|
+
{
|
|
477
|
+
type: "error",
|
|
478
|
+
inputs: [
|
|
479
|
+
{ name: "token", internalType: "address", type: "address" },
|
|
480
|
+
{ name: "from", internalType: "address", type: "address" },
|
|
481
|
+
{ name: "value", internalType: "uint256", type: "uint256" }
|
|
482
|
+
],
|
|
483
|
+
name: "AllowanceNotEnough"
|
|
484
|
+
},
|
|
485
|
+
{ type: "error", inputs: [], name: "InvalidShortString" },
|
|
486
|
+
{ type: "error", inputs: [], name: "ReentrancyGuardReentrantCall" },
|
|
487
|
+
{
|
|
488
|
+
type: "error",
|
|
489
|
+
inputs: [{ name: "token", internalType: "address", type: "address" }],
|
|
490
|
+
name: "SafeERC20FailedOperation"
|
|
491
|
+
},
|
|
492
|
+
{
|
|
493
|
+
type: "error",
|
|
494
|
+
inputs: [{ name: "str", internalType: "string", type: "string" }],
|
|
495
|
+
name: "StringTooLong"
|
|
496
|
+
}
|
|
497
|
+
];
|
|
498
|
+
|
|
499
|
+
// signatureTransfer/shared/context.ts
|
|
500
|
+
async function assertSignatureTransferContext(publicClient, wallet, signedData) {
|
|
501
|
+
assertPublicWalletSameChain(publicClient, wallet);
|
|
502
|
+
await assertTransferContractDeployed(publicClient, transferWithCommitmentAddress);
|
|
503
|
+
assertSignedDomainMatchesClientAndConfig(
|
|
504
|
+
publicClient,
|
|
505
|
+
signedData.domain,
|
|
506
|
+
transferWithCommitmentAddress
|
|
507
|
+
);
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
// signatureTransfer/unified/sendTx.ts
|
|
511
|
+
var sendTx = async (publicClient, wallet, account, signedData) => {
|
|
512
|
+
await assertSignatureTransferContext(publicClient, wallet, signedData);
|
|
513
|
+
const { request } = await publicClient.simulateContract({
|
|
514
|
+
address: transferWithCommitmentAddress,
|
|
515
|
+
abi: transferWithCommitmentAbi,
|
|
516
|
+
functionName: "transferWithAuthorization",
|
|
517
|
+
args: [
|
|
518
|
+
signedData.from,
|
|
519
|
+
signedData.details.map((detail) => ({
|
|
520
|
+
to: detail.to,
|
|
521
|
+
token: detail.token,
|
|
522
|
+
value: detail.value
|
|
523
|
+
})),
|
|
524
|
+
signedData.validAfter,
|
|
525
|
+
signedData.validBefore,
|
|
526
|
+
signedData.commitment,
|
|
527
|
+
signedData.signature
|
|
528
|
+
],
|
|
529
|
+
account
|
|
530
|
+
});
|
|
531
|
+
const hash = await wallet.writeContract(request);
|
|
532
|
+
return hash;
|
|
533
|
+
};
|
|
534
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
535
|
+
0 && (module.exports = {
|
|
536
|
+
argsSchema,
|
|
537
|
+
eip712Types,
|
|
538
|
+
sendTx,
|
|
539
|
+
sign,
|
|
540
|
+
signedDataSchema
|
|
541
|
+
});
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { PublicClient, WalletClient, Hex } from 'viem';
|
|
2
|
+
import * as arktype_internal_variants_object_ts from 'arktype/internal/variants/object.ts';
|
|
3
|
+
import * as arktype_internal_attributes_ts from 'arktype/internal/attributes.ts';
|
|
4
|
+
|
|
5
|
+
declare const argsSchema: arktype_internal_variants_object_ts.ObjectType<{
|
|
6
|
+
from: `0x${string}`;
|
|
7
|
+
executor: `0x${string}`;
|
|
8
|
+
details: {
|
|
9
|
+
to: `0x${string}`;
|
|
10
|
+
token: `0x${string}`;
|
|
11
|
+
value: bigint;
|
|
12
|
+
}[];
|
|
13
|
+
validAfter: arktype_internal_attributes_ts.Default<bigint, 0n>;
|
|
14
|
+
validBefore: arktype_internal_attributes_ts.Default<bigint, bigint>;
|
|
15
|
+
commitment: `0x${string}`;
|
|
16
|
+
}, {}>;
|
|
17
|
+
declare const signedUnifiedSchema: arktype_internal_variants_object_ts.ObjectType<{
|
|
18
|
+
domain: {
|
|
19
|
+
name: string;
|
|
20
|
+
version: string;
|
|
21
|
+
chainId: number | bigint;
|
|
22
|
+
verifyingContract: `0x${string}`;
|
|
23
|
+
salt?: `0x${string}` | undefined;
|
|
24
|
+
};
|
|
25
|
+
from: `0x${string}`;
|
|
26
|
+
details: {
|
|
27
|
+
to: `0x${string}`;
|
|
28
|
+
token: `0x${string}`;
|
|
29
|
+
value: bigint;
|
|
30
|
+
}[];
|
|
31
|
+
validAfter: bigint;
|
|
32
|
+
validBefore: bigint;
|
|
33
|
+
commitment: `0x${string}`;
|
|
34
|
+
signature: `0x${string}`;
|
|
35
|
+
}, {}>;
|
|
36
|
+
declare const signedDataSchema: arktype_internal_variants_object_ts.ObjectType<{
|
|
37
|
+
domain: {
|
|
38
|
+
name: string;
|
|
39
|
+
version: string;
|
|
40
|
+
chainId: number | bigint;
|
|
41
|
+
verifyingContract: `0x${string}`;
|
|
42
|
+
salt?: `0x${string}` | undefined;
|
|
43
|
+
};
|
|
44
|
+
from: `0x${string}`;
|
|
45
|
+
details: {
|
|
46
|
+
to: `0x${string}`;
|
|
47
|
+
token: `0x${string}`;
|
|
48
|
+
value: bigint;
|
|
49
|
+
}[];
|
|
50
|
+
validAfter: bigint;
|
|
51
|
+
validBefore: bigint;
|
|
52
|
+
commitment: `0x${string}`;
|
|
53
|
+
signature: `0x${string}`;
|
|
54
|
+
}, {}>;
|
|
55
|
+
type SignatureTransferUnifiedArgs = typeof argsSchema.inferIn;
|
|
56
|
+
type SignedUnifiedTransfer = typeof signedUnifiedSchema.infer;
|
|
57
|
+
|
|
58
|
+
/** EIP-712 型名 UniCommitTransfers(単一コミット共有の転送セット)を署名する */
|
|
59
|
+
declare const sign: (publicClient: PublicClient, wallet: WalletClient, account: Hex, args: SignatureTransferUnifiedArgs) => Promise<SignedUnifiedTransfer>;
|
|
60
|
+
|
|
61
|
+
declare const sendTx: (publicClient: PublicClient, wallet: WalletClient, account: Hex, signedData: SignedUnifiedTransfer) => Promise<`0x${string}`>;
|
|
62
|
+
|
|
63
|
+
declare const eip712Types: {
|
|
64
|
+
readonly UniCommitTransfers: readonly [{
|
|
65
|
+
readonly name: "from";
|
|
66
|
+
readonly type: "address";
|
|
67
|
+
}, {
|
|
68
|
+
readonly name: "executor";
|
|
69
|
+
readonly type: "address";
|
|
70
|
+
}, {
|
|
71
|
+
readonly name: "details";
|
|
72
|
+
readonly type: "TransferDetail[]";
|
|
73
|
+
}, {
|
|
74
|
+
readonly name: "validAfter";
|
|
75
|
+
readonly type: "uint256";
|
|
76
|
+
}, {
|
|
77
|
+
readonly name: "validBefore";
|
|
78
|
+
readonly type: "uint256";
|
|
79
|
+
}, {
|
|
80
|
+
readonly name: "commitment";
|
|
81
|
+
readonly type: "bytes32";
|
|
82
|
+
}];
|
|
83
|
+
readonly TransferDetail: readonly [{
|
|
84
|
+
readonly name: "to";
|
|
85
|
+
readonly type: "address";
|
|
86
|
+
}, {
|
|
87
|
+
readonly name: "token";
|
|
88
|
+
readonly type: "address";
|
|
89
|
+
}, {
|
|
90
|
+
readonly name: "value";
|
|
91
|
+
readonly type: "uint256";
|
|
92
|
+
}];
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export { type SignatureTransferUnifiedArgs, type SignedUnifiedTransfer, argsSchema, eip712Types, sendTx, sign, signedDataSchema };
|