@atumlabs/mppx-atum-escrow 0.2.2 → 0.4.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/CHANGELOG.md +49 -0
- package/README.md +294 -53
- package/THIRD-PARTY-NOTICES.txt +7 -0
- package/dist/{chunk-IPZJXELQ.js → chunk-KRSFEITH.js} +3594 -469
- package/dist/{chunk-4P34CLTO.js → chunk-OEEC5P3E.js} +1323 -252
- package/dist/{chunk-NEM3HEZW.js → chunk-TPLD2L6B.js} +141 -13
- package/dist/client.d.ts +192 -52
- package/dist/client.js +11 -4
- package/dist/index.d.ts +3 -77
- package/dist/index.js +26 -5
- package/dist/{internal-DzEGXm14.d.ts → internal-CJEu9yUF.d.ts} +131 -24
- package/dist/server.d.ts +255 -50
- package/dist/server.js +18 -2
- package/package.json +10 -8
|
@@ -39,6 +39,307 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
39
39
|
));
|
|
40
40
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
41
41
|
|
|
42
|
+
// ../schemas/declarations/PaymentRequest/v1/bindings/typescript/sender-auth/dist/types.js
|
|
43
|
+
var require_types = __commonJS({
|
|
44
|
+
"../schemas/declarations/PaymentRequest/v1/bindings/typescript/sender-auth/dist/types.js"(exports) {
|
|
45
|
+
"use strict";
|
|
46
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// ../schemas/declarations/PaymentRequest/v1/bindings/typescript/sender-auth/dist/destination.js
|
|
51
|
+
var require_destination = __commonJS({
|
|
52
|
+
"../schemas/declarations/PaymentRequest/v1/bindings/typescript/sender-auth/dist/destination.js"(exports) {
|
|
53
|
+
"use strict";
|
|
54
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
55
|
+
exports.DESTINATION_COMMITMENT_WITNESS_VERSION = exports.MAX_DESTINATION_BYTES = void 0;
|
|
56
|
+
exports.usesDestinationCommitment = usesDestinationCommitment;
|
|
57
|
+
exports.deriveDepositRequestHash = deriveDepositRequestHash;
|
|
58
|
+
exports.buildEscrowDestination = buildEscrowDestination;
|
|
59
|
+
var ethers_1 = __require("ethers");
|
|
60
|
+
exports.MAX_DESTINATION_BYTES = 256;
|
|
61
|
+
var NAMESPACE_EIP155 = "eip155";
|
|
62
|
+
exports.DESTINATION_COMMITMENT_WITNESS_VERSION = 4;
|
|
63
|
+
function usesDestinationCommitment(depositWitnessVersion) {
|
|
64
|
+
return depositWitnessVersion === void 0 || depositWitnessVersion >= exports.DESTINATION_COMMITMENT_WITNESS_VERSION;
|
|
65
|
+
}
|
|
66
|
+
function deriveDepositRequestHash(requestId) {
|
|
67
|
+
if (requestId === "") {
|
|
68
|
+
throw new Error('sender_auth: cannot derive deposit_request_hash: request_id is empty, and keccak256("") is a perfectly valid non-zero bytes32, so this would silently commit every empty-id deposit to the same hash instead of failing');
|
|
69
|
+
}
|
|
70
|
+
return (0, ethers_1.keccak256)((0, ethers_1.toUtf8Bytes)(requestId));
|
|
71
|
+
}
|
|
72
|
+
function buildEscrowDestination(assetIdentifier2, account) {
|
|
73
|
+
if (assetIdentifier2 === "") {
|
|
74
|
+
throw new Error("sender_auth: destination asset_identifier is empty");
|
|
75
|
+
}
|
|
76
|
+
if (account === "") {
|
|
77
|
+
throw new Error("sender_auth: destination account is empty");
|
|
78
|
+
}
|
|
79
|
+
if (assetIdentifier2.includes("@") || account.includes("@")) {
|
|
80
|
+
throw new Error(`sender_auth: destination asset_identifier (${JSON.stringify(assetIdentifier2)}) and account (${JSON.stringify(account)}) must not contain '@': it is the separator between them in the committed destination grammar`);
|
|
81
|
+
}
|
|
82
|
+
const namespace = caip2Namespace(assetIdentifier2);
|
|
83
|
+
let asset = assetIdentifier2;
|
|
84
|
+
let acct = account;
|
|
85
|
+
if (namespace === NAMESPACE_EIP155) {
|
|
86
|
+
asset = asset.toLowerCase();
|
|
87
|
+
acct = acct.toLowerCase();
|
|
88
|
+
}
|
|
89
|
+
const destination = `${asset}@${acct}`;
|
|
90
|
+
const byteLength = (0, ethers_1.toUtf8Bytes)(destination).length;
|
|
91
|
+
if (byteLength > exports.MAX_DESTINATION_BYTES) {
|
|
92
|
+
throw new Error(`sender_auth: composed destination is ${byteLength} bytes, over the escrow's MAX_DESTINATION_BYTES of ${exports.MAX_DESTINATION_BYTES}: the contract reverts DestinationTooLong, so this deposit could never be redeemed`);
|
|
93
|
+
}
|
|
94
|
+
return destination;
|
|
95
|
+
}
|
|
96
|
+
function caip2Namespace(assetIdentifier2) {
|
|
97
|
+
const slash = assetIdentifier2.indexOf("/");
|
|
98
|
+
const chainPart = slash === -1 ? "" : assetIdentifier2.slice(0, slash);
|
|
99
|
+
const assetPart = slash === -1 ? "" : assetIdentifier2.slice(slash + 1);
|
|
100
|
+
if (slash === -1 || chainPart === "" || assetPart === "") {
|
|
101
|
+
const looksLegacy = !assetIdentifier2.includes("/") && countChar(assetIdentifier2, ":") === 2;
|
|
102
|
+
const hint = looksLegacy ? " (this looks like the deprecated `<chain>:<ref>:<asset>` form; migrate it to `<chain>:<ref>/<asset-namespace>:<asset-reference>`)" : "";
|
|
103
|
+
throw new Error(`sender_auth: destination asset_identifier ${JSON.stringify(assetIdentifier2)} is not CAIP-19: expected <caip2-chain-id>/<asset-namespace>:<asset-reference>${hint}`);
|
|
104
|
+
}
|
|
105
|
+
const assetColon = assetPart.indexOf(":");
|
|
106
|
+
if (assetColon <= 0 || assetColon === assetPart.length - 1) {
|
|
107
|
+
throw new Error(`sender_auth: destination asset_identifier ${JSON.stringify(assetIdentifier2)} has a malformed asset part ${JSON.stringify(assetPart)}: expected <asset-namespace>:<asset-reference>`);
|
|
108
|
+
}
|
|
109
|
+
const assetNamespace = assetPart.slice(0, assetColon);
|
|
110
|
+
if (assetNamespace !== assetNamespace.toLowerCase()) {
|
|
111
|
+
throw new Error(`sender_auth: destination asset_identifier ${JSON.stringify(assetIdentifier2)} has a non-canonical asset namespace ${JSON.stringify(assetNamespace)}: the ratified grammar requires it lowercase (${JSON.stringify(assetNamespace.toLowerCase())}). It is rejected rather than normalised because the destination commitment is over these exact bytes`);
|
|
112
|
+
}
|
|
113
|
+
const chainColon = chainPart.indexOf(":");
|
|
114
|
+
if (chainColon <= 0 || chainColon === chainPart.length - 1) {
|
|
115
|
+
throw new Error(`sender_auth: destination asset_identifier ${JSON.stringify(assetIdentifier2)} has a malformed chain part ${JSON.stringify(chainPart)}: expected <namespace>:<reference>`);
|
|
116
|
+
}
|
|
117
|
+
const namespace = chainPart.slice(0, chainColon);
|
|
118
|
+
if (namespace !== namespace.toLowerCase()) {
|
|
119
|
+
throw new Error(`sender_auth: destination asset_identifier ${JSON.stringify(assetIdentifier2)} has a non-canonical chain namespace ${JSON.stringify(namespace)}: the ratified grammar requires it lowercase (${JSON.stringify(namespace.toLowerCase())}). It is rejected rather than normalised because the destination commitment is over these exact bytes`);
|
|
120
|
+
}
|
|
121
|
+
return namespace;
|
|
122
|
+
}
|
|
123
|
+
function countChar(s, c) {
|
|
124
|
+
let n = 0;
|
|
125
|
+
for (const ch of s) {
|
|
126
|
+
if (ch === c)
|
|
127
|
+
n++;
|
|
128
|
+
}
|
|
129
|
+
return n;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
// ../schemas/declarations/PaymentRequest/v1/bindings/typescript/sender-auth/dist/utils.js
|
|
135
|
+
var require_utils = __commonJS({
|
|
136
|
+
"../schemas/declarations/PaymentRequest/v1/bindings/typescript/sender-auth/dist/utils.js"(exports) {
|
|
137
|
+
"use strict";
|
|
138
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
139
|
+
exports.REQUEST_ID_DOMAIN = exports.SOLANA_REPLAY_BUCKETS = exports.SOLANA_REPLAY_SLOTS = exports.PERMIT_NONCE_DOMAIN = exports.REPLAY_HORIZON_SECS = void 0;
|
|
140
|
+
exports.resolvePermitDeadline = resolvePermitDeadline;
|
|
141
|
+
exports.generatePermitNonce = generatePermitNonce;
|
|
142
|
+
exports.resolvePermitNonce = resolvePermitNonce;
|
|
143
|
+
exports.canonicalDepositor = canonicalDepositor;
|
|
144
|
+
exports.deterministicPermitNonce = deterministicPermitNonce;
|
|
145
|
+
exports.deterministicSolanaNonce = deterministicSolanaNonce;
|
|
146
|
+
exports.deterministicRequestId = deterministicRequestId2;
|
|
147
|
+
exports.parseSourceAsset = parseSourceAsset;
|
|
148
|
+
exports.sameAddress = sameAddress2;
|
|
149
|
+
exports.assertKeyMatchesSender = assertKeyMatchesSender;
|
|
150
|
+
exports.assertToken = assertToken;
|
|
151
|
+
exports.assertAmountMatches = assertAmountMatches;
|
|
152
|
+
exports.assertFresh = assertFresh;
|
|
153
|
+
exports.assertSpender = assertSpender;
|
|
154
|
+
exports.assertWitnessRoles = assertWitnessRoles;
|
|
155
|
+
exports.assertRolePairComplete = assertRolePairComplete;
|
|
156
|
+
exports.assertDestination = assertDestination;
|
|
157
|
+
exports.assertDepositRequestHash = assertDepositRequestHash;
|
|
158
|
+
exports.nowSec = nowSec;
|
|
159
|
+
var ethers_1 = __require("ethers");
|
|
160
|
+
var destination_js_1 = require_destination();
|
|
161
|
+
exports.REPLAY_HORIZON_SECS = 128;
|
|
162
|
+
function resolvePermitDeadline(deadline) {
|
|
163
|
+
return BigInt(deadline);
|
|
164
|
+
}
|
|
165
|
+
function generatePermitNonce() {
|
|
166
|
+
const rand = new Uint32Array(1);
|
|
167
|
+
globalThis.crypto.getRandomValues(rand);
|
|
168
|
+
return (BigInt(Date.now()) << 32n) + BigInt(rand[0]);
|
|
169
|
+
}
|
|
170
|
+
function resolvePermitNonce(nonce) {
|
|
171
|
+
return BigInt(nonce);
|
|
172
|
+
}
|
|
173
|
+
exports.PERMIT_NONCE_DOMAIN = "atum-permit:v1:";
|
|
174
|
+
exports.SOLANA_REPLAY_SLOTS = 235n;
|
|
175
|
+
exports.SOLANA_REPLAY_BUCKETS = 256n;
|
|
176
|
+
function canonicalDepositor(depositor) {
|
|
177
|
+
const lower = depositor.toLowerCase();
|
|
178
|
+
return lower.startsWith("0x") ? lower : depositor;
|
|
179
|
+
}
|
|
180
|
+
function permitNonceSeed(requestId, depositor) {
|
|
181
|
+
if (!requestId) {
|
|
182
|
+
throw new Error("sender_auth: request_id is required to derive a deterministic permit nonce");
|
|
183
|
+
}
|
|
184
|
+
return BigInt((0, ethers_1.keccak256)((0, ethers_1.toUtf8Bytes)(`${exports.PERMIT_NONCE_DOMAIN}${requestId}:${canonicalDepositor(depositor)}`)));
|
|
185
|
+
}
|
|
186
|
+
function deterministicPermitNonce(params) {
|
|
187
|
+
return permitNonceSeed(params.requestId, params.depositor);
|
|
188
|
+
}
|
|
189
|
+
function deterministicSolanaNonce(params) {
|
|
190
|
+
const seed = permitNonceSeed(params.requestId, params.depositor);
|
|
191
|
+
const slot = seed % exports.SOLANA_REPLAY_SLOTS;
|
|
192
|
+
const bucket = (seed >> 8n) % exports.SOLANA_REPLAY_BUCKETS;
|
|
193
|
+
return bucket << 32n | slot;
|
|
194
|
+
}
|
|
195
|
+
exports.REQUEST_ID_DOMAIN = "atum-request:v1:";
|
|
196
|
+
function deterministicRequestId2(params) {
|
|
197
|
+
if (!params.anchor) {
|
|
198
|
+
throw new Error("sender_auth: a per-intent anchor is required to derive a deterministic request_id (a random one would silently break idempotency and let a retry double-charge)");
|
|
199
|
+
}
|
|
200
|
+
if (!params.account) {
|
|
201
|
+
throw new Error("sender_auth: account is required to derive a deterministic request_id");
|
|
202
|
+
}
|
|
203
|
+
if (!/^[A-Za-z0-9_-]*$/.test(params.prefix)) {
|
|
204
|
+
throw new Error(`sender_auth: request_id prefix must contain only letters, digits, '_' or '-' (got ${JSON.stringify(params.prefix)})`);
|
|
205
|
+
}
|
|
206
|
+
const digest = (0, ethers_1.keccak256)((0, ethers_1.toUtf8Bytes)(`${exports.REQUEST_ID_DOMAIN}${params.anchor}:${canonicalDepositor(params.account)}`));
|
|
207
|
+
return `${params.prefix}${digest.slice(2, 26)}`;
|
|
208
|
+
}
|
|
209
|
+
function parseSourceAsset(assetIdentifier2) {
|
|
210
|
+
const parts = typeof assetIdentifier2 === "string" ? assetIdentifier2.split("/") : [];
|
|
211
|
+
const nsParts = parts[1]?.split(":");
|
|
212
|
+
if (parts.length === 3 && parts[0] && parts[1] && parts[2]) {
|
|
213
|
+
throw new Error(`sender_auth: source asset ${JSON.stringify(assetIdentifier2)} names a token id, which a deposit cannot bind`);
|
|
214
|
+
}
|
|
215
|
+
if (parts.length !== 2 || !parts[0] || !nsParts || nsParts.length !== 2 || !nsParts[0] || !nsParts[1]) {
|
|
216
|
+
throw new Error(`sender_auth: invalid source asset ${JSON.stringify(assetIdentifier2)}`);
|
|
217
|
+
}
|
|
218
|
+
return { network: parts[0], asset: nsParts[1] };
|
|
219
|
+
}
|
|
220
|
+
function sameAddress2(a, b) {
|
|
221
|
+
if (a.startsWith("0x") && b.startsWith("0x")) {
|
|
222
|
+
return a.toLowerCase() === b.toLowerCase();
|
|
223
|
+
}
|
|
224
|
+
return a === b;
|
|
225
|
+
}
|
|
226
|
+
function assertKeyMatchesSender(matches, sender, derived) {
|
|
227
|
+
if (!matches) {
|
|
228
|
+
throw new Error(`sender_auth: private key derives ${derived}, not the expected sender ${sender}`);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
function assertToken(token, sourceAsset, normalize) {
|
|
232
|
+
if (!sameAddress2(token, normalize(sourceAsset))) {
|
|
233
|
+
throw new Error("sender_auth: permit token does not match the source asset");
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
function assertAmountMatches(amount, maxSourceAmount) {
|
|
237
|
+
if (BigInt(amount) !== BigInt(maxSourceAmount)) {
|
|
238
|
+
throw new Error("sender_auth: permit amount does not match max_source_amount");
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
function assertFresh(deadlineSec, nowSec2) {
|
|
242
|
+
if (deadlineSec <= nowSec2) {
|
|
243
|
+
throw new Error("sender_auth: permit deadline is not in the future");
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
function assertSpender(spender, escrow, normalize) {
|
|
247
|
+
if (!sameAddress2(spender, normalize(escrow))) {
|
|
248
|
+
throw new Error("sender_auth: permit spender is not the source escrow");
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
function assertWitnessRoles(reserver, releaser, expectedReserver, expectedReleaser, normalize) {
|
|
252
|
+
if (!sameAddress2(reserver, normalize(expectedReserver)) || !sameAddress2(releaser, normalize(expectedReleaser))) {
|
|
253
|
+
throw new Error("sender_auth: deposit witness roles do not match the challenge");
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
function assertRolePairComplete(reserver, releaser) {
|
|
257
|
+
if (reserver === void 0 !== (releaser === void 0)) {
|
|
258
|
+
throw new Error("sender_auth: reserver and releaser must be supplied together");
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
function assertDestination(signed, expected) {
|
|
262
|
+
if (signed !== expected) {
|
|
263
|
+
throw new Error(`sender_auth: signed deposit destination ${JSON.stringify(signed)} does not match the expected destination ${JSON.stringify(expected)} \u2014 the escrow stores only keccak256(bytes(destination)) and cannot tell a formatting disagreement from a wrong payee, so a deposit signed against this destination could be neither released nor refunded`);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
function assertDepositRequestHash(signedHex, expectedRequestId) {
|
|
267
|
+
const expected = (0, destination_js_1.deriveDepositRequestHash)(expectedRequestId);
|
|
268
|
+
if (signedHex.toLowerCase() !== expected.toLowerCase()) {
|
|
269
|
+
throw new Error(`sender_auth: signed deposit_request_hash ${signedHex} is not keccak256(request_id) for request_id ${JSON.stringify(expectedRequestId)} (expected ${expected}): the deposit authorizes a different payment request`);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
function nowSec() {
|
|
273
|
+
return Math.floor(Date.now() / 1e3);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
// ../schemas/declarations/PaymentRequest/v1/bindings/typescript/sender-auth/dist/chain-id.js
|
|
279
|
+
var require_chain_id = __commonJS({
|
|
280
|
+
"../schemas/declarations/PaymentRequest/v1/bindings/typescript/sender-auth/dist/chain-id.js"(exports) {
|
|
281
|
+
"use strict";
|
|
282
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
283
|
+
exports.TRON_PERMIT2_FALLBACKS = exports.TRON_CHAIN_IDS = exports.MAX_EVM_CHAIN_ID = void 0;
|
|
284
|
+
exports.namespaceOf = namespaceOf2;
|
|
285
|
+
exports.evmChainId = evmChainId;
|
|
286
|
+
exports.tronNumericChainId = tronNumericChainId;
|
|
287
|
+
exports.resolveTronPermit2 = resolveTronPermit22;
|
|
288
|
+
exports.clusterIdFromName = clusterIdFromName;
|
|
289
|
+
function namespaceOf2(network) {
|
|
290
|
+
return network.split(":")[0];
|
|
291
|
+
}
|
|
292
|
+
exports.MAX_EVM_CHAIN_ID = Number.MAX_SAFE_INTEGER;
|
|
293
|
+
function evmChainId(network) {
|
|
294
|
+
const match = /^eip155:([0-9]+)$/.exec(network);
|
|
295
|
+
if (!match) {
|
|
296
|
+
throw new Error(`sender_auth: expected an eip155 network, got ${network}`);
|
|
297
|
+
}
|
|
298
|
+
const chainId = Number(match[1]);
|
|
299
|
+
if (chainId > exports.MAX_EVM_CHAIN_ID) {
|
|
300
|
+
throw new Error(`sender_auth: eip155 chain id ${match[1]} exceeds the EIP-2294 maximum (${exports.MAX_EVM_CHAIN_ID})`);
|
|
301
|
+
}
|
|
302
|
+
return chainId;
|
|
303
|
+
}
|
|
304
|
+
exports.TRON_CHAIN_IDS = {
|
|
305
|
+
mainnet: 728126428,
|
|
306
|
+
shasta: 2494104990
|
|
307
|
+
};
|
|
308
|
+
function tronNumericChainId(network) {
|
|
309
|
+
if (namespaceOf2(network) !== "tron") {
|
|
310
|
+
throw new Error(`sender_auth: expected a tron network, got ${network}`);
|
|
311
|
+
}
|
|
312
|
+
const segments = network.split(":");
|
|
313
|
+
const cluster = segments.length === 2 ? segments[1] : void 0;
|
|
314
|
+
const id = cluster !== void 0 && Object.hasOwn(exports.TRON_CHAIN_IDS, cluster) ? exports.TRON_CHAIN_IDS[cluster] : void 0;
|
|
315
|
+
if (typeof id !== "number") {
|
|
316
|
+
throw new Error(`sender_auth: unsupported Tron network '${network}'`);
|
|
317
|
+
}
|
|
318
|
+
return id;
|
|
319
|
+
}
|
|
320
|
+
exports.TRON_PERMIT2_FALLBACKS = {
|
|
321
|
+
"tron:mainnet": "TJhMXTHQHeQyMD7TcKQFqAePNgG4b31H9m",
|
|
322
|
+
"tron:shasta": "TPUqJPASUn1zLvbLBgRZ5pBYrx7WSe5ahp"
|
|
323
|
+
};
|
|
324
|
+
function resolveTronPermit22(network) {
|
|
325
|
+
const resolved = Object.hasOwn(exports.TRON_PERMIT2_FALLBACKS, network) ? exports.TRON_PERMIT2_FALLBACKS[network] : void 0;
|
|
326
|
+
if (typeof resolved !== "string" || resolved === "") {
|
|
327
|
+
throw new Error(`sender_auth: no Permit2 address known for Tron network '${network}'`);
|
|
328
|
+
}
|
|
329
|
+
return resolved;
|
|
330
|
+
}
|
|
331
|
+
function clusterIdFromName(name) {
|
|
332
|
+
const encoded = new TextEncoder().encode(name);
|
|
333
|
+
if (encoded.length > 32) {
|
|
334
|
+
throw new Error(`sender_auth: Solana cluster name too long (${encoded.length} > 32 bytes): ${name}`);
|
|
335
|
+
}
|
|
336
|
+
const out = new Uint8Array(32);
|
|
337
|
+
out.set(encoded);
|
|
338
|
+
return out;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
|
|
42
343
|
// ../contracts/evm/escrow-encoding/typescript/dist/payment-id.js
|
|
43
344
|
var require_payment_id = __commonJS({
|
|
44
345
|
"../contracts/evm/escrow-encoding/typescript/dist/payment-id.js"(exports) {
|
|
@@ -78,7 +379,7 @@ var require_permit_types = __commonJS({
|
|
|
78
379
|
"../contracts/evm/escrow-encoding/typescript/dist/permit-types.js"(exports) {
|
|
79
380
|
"use strict";
|
|
80
381
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
81
|
-
exports.REFUND_WITNESS_TYPES = exports.RELEASE_WITNESS_TYPES = exports.RESERVE_WITNESS_TYPES = exports.PERMIT_WITNESS_TYPES_V2 = exports.PERMIT_WITNESS_TYPES = void 0;
|
|
382
|
+
exports.REFUND_WITNESS_TYPES_WITH_QUOTE_HASH = exports.RELEASE_WITNESS_TYPES_WITH_QUOTE_HASH = exports.RESERVE_WITNESS_TYPES_WITH_QUOTE_SOURCE = exports.PERMIT_WITNESS_TYPES_WITH_DESTINATION = exports.REFUND_WITNESS_TYPES = exports.RELEASE_WITNESS_TYPES = exports.RESERVE_WITNESS_TYPES = exports.PERMIT_WITNESS_TYPES_V2 = exports.PERMIT_WITNESS_TYPES = void 0;
|
|
82
383
|
exports.createPermit2Domain = createPermit2Domain;
|
|
83
384
|
exports.createEscrowDomain = createEscrowDomain;
|
|
84
385
|
exports.PERMIT_WITNESS_TYPES = {
|
|
@@ -161,6 +462,63 @@ var require_permit_types = __commonJS({
|
|
|
161
462
|
{ name: "settler", type: "address" }
|
|
162
463
|
]
|
|
163
464
|
};
|
|
465
|
+
exports.PERMIT_WITNESS_TYPES_WITH_DESTINATION = {
|
|
466
|
+
PermitWitnessTransferFrom: [
|
|
467
|
+
{ name: "permitted", type: "TokenPermissions" },
|
|
468
|
+
{ name: "spender", type: "address" },
|
|
469
|
+
{ name: "nonce", type: "uint256" },
|
|
470
|
+
{ name: "deadline", type: "uint256" },
|
|
471
|
+
{ name: "witness", type: "DepositWitness" }
|
|
472
|
+
],
|
|
473
|
+
TokenPermissions: [
|
|
474
|
+
{ name: "token", type: "address" },
|
|
475
|
+
{ name: "amount", type: "uint256" }
|
|
476
|
+
],
|
|
477
|
+
DepositWitness: [
|
|
478
|
+
{ name: "depositRequestHash", type: "bytes32" },
|
|
479
|
+
{ name: "destination", type: "string" },
|
|
480
|
+
{ name: "reserver", type: "address" },
|
|
481
|
+
{ name: "releaser", type: "address" }
|
|
482
|
+
]
|
|
483
|
+
};
|
|
484
|
+
exports.RESERVE_WITNESS_TYPES_WITH_QUOTE_SOURCE = {
|
|
485
|
+
ReserveWitness: [
|
|
486
|
+
{ name: "depositId", type: "bytes32" },
|
|
487
|
+
{ name: "quoteHash", type: "bytes32" },
|
|
488
|
+
{ name: "settler", type: "address" },
|
|
489
|
+
{ name: "sourceAmount", type: "uint256" }
|
|
490
|
+
]
|
|
491
|
+
};
|
|
492
|
+
exports.RELEASE_WITNESS_TYPES_WITH_QUOTE_HASH = {
|
|
493
|
+
ReleaseWitness: [
|
|
494
|
+
{ name: "depositId", type: "bytes32" },
|
|
495
|
+
{ name: "quoteHash", type: "bytes32" },
|
|
496
|
+
{ name: "depositRequestHash", type: "bytes32" },
|
|
497
|
+
{ name: "destinationHash", type: "bytes32" },
|
|
498
|
+
{ name: "depositor", type: "address" },
|
|
499
|
+
{ name: "token", type: "address" },
|
|
500
|
+
{ name: "amount", type: "uint256" },
|
|
501
|
+
{ name: "feeAmount", type: "uint256" },
|
|
502
|
+
{ name: "reserver", type: "address" },
|
|
503
|
+
{ name: "releaser", type: "address" },
|
|
504
|
+
{ name: "settler", type: "address" }
|
|
505
|
+
]
|
|
506
|
+
};
|
|
507
|
+
exports.REFUND_WITNESS_TYPES_WITH_QUOTE_HASH = {
|
|
508
|
+
RefundWitness: [
|
|
509
|
+
{ name: "depositId", type: "bytes32" },
|
|
510
|
+
{ name: "quoteHash", type: "bytes32" },
|
|
511
|
+
{ name: "depositRequestHash", type: "bytes32" },
|
|
512
|
+
{ name: "destinationHash", type: "bytes32" },
|
|
513
|
+
{ name: "depositor", type: "address" },
|
|
514
|
+
{ name: "token", type: "address" },
|
|
515
|
+
{ name: "amount", type: "uint256" },
|
|
516
|
+
{ name: "feeAmount", type: "uint256" },
|
|
517
|
+
{ name: "reserver", type: "address" },
|
|
518
|
+
{ name: "releaser", type: "address" },
|
|
519
|
+
{ name: "settler", type: "address" }
|
|
520
|
+
]
|
|
521
|
+
};
|
|
164
522
|
}
|
|
165
523
|
});
|
|
166
524
|
|
|
@@ -287,6 +645,8 @@ var require_escrow_abi = __commonJS({
|
|
|
287
645
|
name: "depositWitness",
|
|
288
646
|
type: "tuple",
|
|
289
647
|
components: [
|
|
648
|
+
{ name: "depositRequestHash", type: "bytes32" },
|
|
649
|
+
{ name: "destination", type: "string" },
|
|
290
650
|
{ name: "reserver", type: "address" },
|
|
291
651
|
{ name: "releaser", type: "address" }
|
|
292
652
|
]
|
|
@@ -296,15 +656,17 @@ var require_escrow_abi = __commonJS({
|
|
|
296
656
|
name: "reserveWitness",
|
|
297
657
|
type: "tuple",
|
|
298
658
|
components: [
|
|
299
|
-
{ name: "
|
|
300
|
-
{ name: "
|
|
659
|
+
{ name: "depositId", type: "bytes32" },
|
|
660
|
+
{ name: "quoteHash", type: "bytes32" },
|
|
661
|
+
{ name: "settler", type: "address" },
|
|
662
|
+
{ name: "sourceAmount", type: "uint256" }
|
|
301
663
|
]
|
|
302
664
|
},
|
|
303
665
|
{ name: "reserveSignature", type: "bytes" }
|
|
304
666
|
]
|
|
305
667
|
}
|
|
306
668
|
],
|
|
307
|
-
outputs: [{ name: "
|
|
669
|
+
outputs: [{ name: "depositId", type: "bytes32" }],
|
|
308
670
|
stateMutability: "nonpayable"
|
|
309
671
|
},
|
|
310
672
|
{
|
|
@@ -319,7 +681,10 @@ var require_escrow_abi = __commonJS({
|
|
|
319
681
|
name: "refundWitness",
|
|
320
682
|
type: "tuple",
|
|
321
683
|
components: [
|
|
322
|
-
{ name: "
|
|
684
|
+
{ name: "depositId", type: "bytes32" },
|
|
685
|
+
{ name: "quoteHash", type: "bytes32" },
|
|
686
|
+
{ name: "depositRequestHash", type: "bytes32" },
|
|
687
|
+
{ name: "destinationHash", type: "bytes32" },
|
|
323
688
|
{ name: "depositor", type: "address" },
|
|
324
689
|
{ name: "token", type: "address" },
|
|
325
690
|
{ name: "amount", type: "uint256" },
|
|
@@ -339,7 +704,7 @@ var require_escrow_abi = __commonJS({
|
|
|
339
704
|
{
|
|
340
705
|
type: "function",
|
|
341
706
|
name: "getDepositHash",
|
|
342
|
-
inputs: [{ name: "
|
|
707
|
+
inputs: [{ name: "depositId", type: "bytes32" }],
|
|
343
708
|
outputs: [{ name: "", type: "bytes32" }],
|
|
344
709
|
stateMutability: "view"
|
|
345
710
|
},
|
|
@@ -355,14 +720,67 @@ var require_escrow_abi = __commonJS({
|
|
|
355
720
|
}
|
|
356
721
|
});
|
|
357
722
|
|
|
723
|
+
// ../contracts/evm/escrow-encoding/typescript/dist/witness-values.js
|
|
724
|
+
var require_witness_values = __commonJS({
|
|
725
|
+
"../contracts/evm/escrow-encoding/typescript/dist/witness-values.js"(exports) {
|
|
726
|
+
"use strict";
|
|
727
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
728
|
+
exports.normalizeBytes32 = normalizeBytes32;
|
|
729
|
+
exports.normalizeAddressField = normalizeAddressField;
|
|
730
|
+
exports.normalizeUint256 = normalizeUint256;
|
|
731
|
+
exports.chainIdToHex = chainIdToHex;
|
|
732
|
+
var ethers_1 = __require("ethers");
|
|
733
|
+
function normalizeBytes32(label, value) {
|
|
734
|
+
let bytes;
|
|
735
|
+
try {
|
|
736
|
+
bytes = (0, ethers_1.getBytes)(value);
|
|
737
|
+
} catch {
|
|
738
|
+
throw new Error(`${label} must be 0x-prefixed hex (32 bytes), got ${JSON.stringify(value)}`);
|
|
739
|
+
}
|
|
740
|
+
if (bytes.length !== 32) {
|
|
741
|
+
throw new Error(`${label} must be exactly 32 bytes, got ${bytes.length}`);
|
|
742
|
+
}
|
|
743
|
+
return (0, ethers_1.hexlify)(bytes);
|
|
744
|
+
}
|
|
745
|
+
function normalizeAddressField(label, value) {
|
|
746
|
+
try {
|
|
747
|
+
return (0, ethers_1.getAddress)(value);
|
|
748
|
+
} catch {
|
|
749
|
+
throw new Error(`${label} must be a 20-byte hex address, got ${JSON.stringify(value)}`);
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
function normalizeUint256(label, value) {
|
|
753
|
+
let n;
|
|
754
|
+
try {
|
|
755
|
+
n = BigInt(value);
|
|
756
|
+
} catch {
|
|
757
|
+
throw new Error(`${label} must be an integer (bigint or decimal string), got ${JSON.stringify(value)}`);
|
|
758
|
+
}
|
|
759
|
+
if (n < 0n) {
|
|
760
|
+
throw new Error(`${label} must be non-negative (uint256), got ${n.toString()}`);
|
|
761
|
+
}
|
|
762
|
+
return n.toString();
|
|
763
|
+
}
|
|
764
|
+
function chainIdToHex(chainId) {
|
|
765
|
+
if (!Number.isSafeInteger(chainId) || chainId < 0) {
|
|
766
|
+
throw new Error(`chainId must be a non-negative safe integer, got ${chainId}`);
|
|
767
|
+
}
|
|
768
|
+
return `0x${chainId.toString(16)}`;
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
});
|
|
772
|
+
|
|
358
773
|
// ../contracts/evm/escrow-encoding/typescript/dist/reserve-encoder.js
|
|
359
774
|
var require_reserve_encoder = __commonJS({
|
|
360
775
|
"../contracts/evm/escrow-encoding/typescript/dist/reserve-encoder.js"(exports) {
|
|
361
776
|
"use strict";
|
|
362
777
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
363
778
|
exports.computeReserveDigest = computeReserveDigest;
|
|
779
|
+
exports.buildReserveTypedDataWithQuoteSource = buildReserveTypedDataWithQuoteSource;
|
|
780
|
+
exports.computeReserveDigestWithQuoteSource = computeReserveDigestWithQuoteSource;
|
|
364
781
|
var ethers_1 = __require("ethers");
|
|
365
782
|
var permit_types_1 = require_permit_types();
|
|
783
|
+
var witness_values_1 = require_witness_values();
|
|
366
784
|
function computeReserveDigest(input) {
|
|
367
785
|
const domain = (0, permit_types_1.createEscrowDomain)(input.chainId, input.escrowContract);
|
|
368
786
|
return ethers_1.TypedDataEncoder.hash(domain, permit_types_1.RESERVE_WITNESS_TYPES, {
|
|
@@ -370,6 +788,114 @@ var require_reserve_encoder = __commonJS({
|
|
|
370
788
|
settler: input.settler
|
|
371
789
|
});
|
|
372
790
|
}
|
|
791
|
+
function buildReserveTypedDataWithQuoteSource(input) {
|
|
792
|
+
return {
|
|
793
|
+
types: permit_types_1.RESERVE_WITNESS_TYPES_WITH_QUOTE_SOURCE,
|
|
794
|
+
primaryType: "ReserveWitness",
|
|
795
|
+
domain: {
|
|
796
|
+
name: "Escrow",
|
|
797
|
+
version: "3",
|
|
798
|
+
chainId: (0, witness_values_1.chainIdToHex)(input.chainId),
|
|
799
|
+
verifyingContract: (0, witness_values_1.normalizeAddressField)("escrowContract", input.escrowContract)
|
|
800
|
+
},
|
|
801
|
+
message: {
|
|
802
|
+
depositId: (0, witness_values_1.normalizeBytes32)("depositId", input.depositId),
|
|
803
|
+
quoteHash: (0, witness_values_1.normalizeBytes32)("quoteHash", input.quoteHash),
|
|
804
|
+
settler: (0, witness_values_1.normalizeAddressField)("settler", input.settler),
|
|
805
|
+
sourceAmount: (0, witness_values_1.normalizeUint256)("sourceAmount", input.sourceAmount)
|
|
806
|
+
}
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
function computeReserveDigestWithQuoteSource(input) {
|
|
810
|
+
const prehash = buildReserveTypedDataWithQuoteSource(input);
|
|
811
|
+
return ethers_1.TypedDataEncoder.hash(prehash.domain, prehash.types, prehash.message);
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
});
|
|
815
|
+
|
|
816
|
+
// ../contracts/evm/escrow-encoding/typescript/dist/release-encoder.js
|
|
817
|
+
var require_release_encoder = __commonJS({
|
|
818
|
+
"../contracts/evm/escrow-encoding/typescript/dist/release-encoder.js"(exports) {
|
|
819
|
+
"use strict";
|
|
820
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
821
|
+
exports.buildReleaseTypedDataWithQuoteHash = buildReleaseTypedDataWithQuoteHash;
|
|
822
|
+
exports.computeReleaseDigestWithQuoteHash = computeReleaseDigestWithQuoteHash;
|
|
823
|
+
var ethers_1 = __require("ethers");
|
|
824
|
+
var permit_types_1 = require_permit_types();
|
|
825
|
+
var witness_values_1 = require_witness_values();
|
|
826
|
+
function buildReleaseTypedDataWithQuoteHash(input) {
|
|
827
|
+
const w = input.witness;
|
|
828
|
+
return {
|
|
829
|
+
types: permit_types_1.RELEASE_WITNESS_TYPES_WITH_QUOTE_HASH,
|
|
830
|
+
primaryType: "ReleaseWitness",
|
|
831
|
+
domain: {
|
|
832
|
+
name: "Escrow",
|
|
833
|
+
version: "3",
|
|
834
|
+
chainId: (0, witness_values_1.chainIdToHex)(input.chainId),
|
|
835
|
+
verifyingContract: (0, witness_values_1.normalizeAddressField)("escrowContract", input.escrowContract)
|
|
836
|
+
},
|
|
837
|
+
message: {
|
|
838
|
+
depositId: (0, witness_values_1.normalizeBytes32)("depositId", w.depositId),
|
|
839
|
+
quoteHash: (0, witness_values_1.normalizeBytes32)("quoteHash", w.quoteHash),
|
|
840
|
+
depositRequestHash: (0, witness_values_1.normalizeBytes32)("depositRequestHash", w.depositRequestHash),
|
|
841
|
+
destinationHash: (0, witness_values_1.normalizeBytes32)("destinationHash", w.destinationHash),
|
|
842
|
+
depositor: (0, witness_values_1.normalizeAddressField)("depositor", w.depositor),
|
|
843
|
+
token: (0, witness_values_1.normalizeAddressField)("token", w.token),
|
|
844
|
+
amount: (0, witness_values_1.normalizeUint256)("amount", w.amount),
|
|
845
|
+
feeAmount: (0, witness_values_1.normalizeUint256)("feeAmount", w.feeAmount),
|
|
846
|
+
reserver: (0, witness_values_1.normalizeAddressField)("reserver", w.reserver),
|
|
847
|
+
releaser: (0, witness_values_1.normalizeAddressField)("releaser", w.releaser),
|
|
848
|
+
settler: (0, witness_values_1.normalizeAddressField)("settler", w.settler)
|
|
849
|
+
}
|
|
850
|
+
};
|
|
851
|
+
}
|
|
852
|
+
function computeReleaseDigestWithQuoteHash(input) {
|
|
853
|
+
const prehash = buildReleaseTypedDataWithQuoteHash(input);
|
|
854
|
+
return ethers_1.TypedDataEncoder.hash(prehash.domain, prehash.types, prehash.message);
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
});
|
|
858
|
+
|
|
859
|
+
// ../contracts/evm/escrow-encoding/typescript/dist/refund-encoder.js
|
|
860
|
+
var require_refund_encoder = __commonJS({
|
|
861
|
+
"../contracts/evm/escrow-encoding/typescript/dist/refund-encoder.js"(exports) {
|
|
862
|
+
"use strict";
|
|
863
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
864
|
+
exports.buildRefundTypedDataWithQuoteHash = buildRefundTypedDataWithQuoteHash;
|
|
865
|
+
exports.computeRefundDigestWithQuoteHash = computeRefundDigestWithQuoteHash;
|
|
866
|
+
var ethers_1 = __require("ethers");
|
|
867
|
+
var permit_types_1 = require_permit_types();
|
|
868
|
+
var witness_values_1 = require_witness_values();
|
|
869
|
+
function buildRefundTypedDataWithQuoteHash(input) {
|
|
870
|
+
const w = input.witness;
|
|
871
|
+
return {
|
|
872
|
+
types: permit_types_1.REFUND_WITNESS_TYPES_WITH_QUOTE_HASH,
|
|
873
|
+
primaryType: "RefundWitness",
|
|
874
|
+
domain: {
|
|
875
|
+
name: "Escrow",
|
|
876
|
+
version: "3",
|
|
877
|
+
chainId: (0, witness_values_1.chainIdToHex)(input.chainId),
|
|
878
|
+
verifyingContract: (0, witness_values_1.normalizeAddressField)("escrowContract", input.escrowContract)
|
|
879
|
+
},
|
|
880
|
+
message: {
|
|
881
|
+
depositId: (0, witness_values_1.normalizeBytes32)("depositId", w.depositId),
|
|
882
|
+
quoteHash: (0, witness_values_1.normalizeBytes32)("quoteHash", w.quoteHash),
|
|
883
|
+
depositRequestHash: (0, witness_values_1.normalizeBytes32)("depositRequestHash", w.depositRequestHash),
|
|
884
|
+
destinationHash: (0, witness_values_1.normalizeBytes32)("destinationHash", w.destinationHash),
|
|
885
|
+
depositor: (0, witness_values_1.normalizeAddressField)("depositor", w.depositor),
|
|
886
|
+
token: (0, witness_values_1.normalizeAddressField)("token", w.token),
|
|
887
|
+
amount: (0, witness_values_1.normalizeUint256)("amount", w.amount),
|
|
888
|
+
feeAmount: (0, witness_values_1.normalizeUint256)("feeAmount", w.feeAmount),
|
|
889
|
+
reserver: (0, witness_values_1.normalizeAddressField)("reserver", w.reserver),
|
|
890
|
+
releaser: (0, witness_values_1.normalizeAddressField)("releaser", w.releaser),
|
|
891
|
+
settler: (0, witness_values_1.normalizeAddressField)("settler", w.settler)
|
|
892
|
+
}
|
|
893
|
+
};
|
|
894
|
+
}
|
|
895
|
+
function computeRefundDigestWithQuoteHash(input) {
|
|
896
|
+
const prehash = buildRefundTypedDataWithQuoteHash(input);
|
|
897
|
+
return ethers_1.TypedDataEncoder.hash(prehash.domain, prehash.types, prehash.message);
|
|
898
|
+
}
|
|
373
899
|
}
|
|
374
900
|
});
|
|
375
901
|
|
|
@@ -378,11 +904,13 @@ var require_deposit_encoder = __commonJS({
|
|
|
378
904
|
"../contracts/evm/escrow-encoding/typescript/dist/deposit-encoder.js"(exports) {
|
|
379
905
|
"use strict";
|
|
380
906
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
381
|
-
exports.PERMIT2_CONTRACT_ADDRESS = void 0;
|
|
907
|
+
exports.MAX_DESTINATION_BYTES = exports.PERMIT2_CONTRACT_ADDRESS = void 0;
|
|
382
908
|
exports.createPermitWitnessTransferFromPrehash = createPermitWitnessTransferFromPrehash;
|
|
383
909
|
exports.hashPermitWitnessTransferFrom = hashPermitWitnessTransferFrom;
|
|
910
|
+
exports.createPermitWitnessTransferFromPrehashWithDestination = createPermitWitnessTransferFromPrehashWithDestination;
|
|
384
911
|
var ethers_1 = __require("ethers");
|
|
385
912
|
var permit_types_1 = require_permit_types();
|
|
913
|
+
var witness_values_1 = require_witness_values();
|
|
386
914
|
exports.PERMIT2_CONTRACT_ADDRESS = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
|
|
387
915
|
function createPermitWitnessTransferFromPrehash(params) {
|
|
388
916
|
return {
|
|
@@ -411,6 +939,43 @@ var require_deposit_encoder = __commonJS({
|
|
|
411
939
|
function hashPermitWitnessTransferFrom(prehash) {
|
|
412
940
|
return ethers_1.TypedDataEncoder.hash(prehash.domain, prehash.types, prehash.message);
|
|
413
941
|
}
|
|
942
|
+
exports.MAX_DESTINATION_BYTES = 256;
|
|
943
|
+
function assertDestinationWithinBounds(destination) {
|
|
944
|
+
if (destination === "") {
|
|
945
|
+
throw new Error('destination is empty: the escrow reverts DestinationCannotBeEmpty, and because keccak256("") is a valid bytes32 this would otherwise sign a commitment to no destination at all');
|
|
946
|
+
}
|
|
947
|
+
const byteLength = (0, ethers_1.toUtf8Bytes)(destination).length;
|
|
948
|
+
if (byteLength > exports.MAX_DESTINATION_BYTES) {
|
|
949
|
+
throw new Error(`destination is ${byteLength} bytes, over the escrow's MAX_DESTINATION_BYTES of ${exports.MAX_DESTINATION_BYTES}: the contract reverts DestinationTooLong, so this digest could never be redeemed`);
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
function createPermitWitnessTransferFromPrehashWithDestination(params) {
|
|
953
|
+
assertDestinationWithinBounds(params.destination);
|
|
954
|
+
return {
|
|
955
|
+
types: permit_types_1.PERMIT_WITNESS_TYPES_WITH_DESTINATION,
|
|
956
|
+
primaryType: "PermitWitnessTransferFrom",
|
|
957
|
+
domain: {
|
|
958
|
+
name: "Permit2",
|
|
959
|
+
chainId: (0, witness_values_1.chainIdToHex)(params.chainId),
|
|
960
|
+
verifyingContract: (0, witness_values_1.normalizeAddressField)("verifyingContract", params.verifyingContract)
|
|
961
|
+
},
|
|
962
|
+
message: {
|
|
963
|
+
permitted: {
|
|
964
|
+
token: (0, witness_values_1.normalizeAddressField)("token", params.token),
|
|
965
|
+
amount: (0, witness_values_1.normalizeUint256)("amount", params.amount)
|
|
966
|
+
},
|
|
967
|
+
spender: (0, witness_values_1.normalizeAddressField)("spender", params.spender),
|
|
968
|
+
nonce: (0, witness_values_1.normalizeUint256)("nonce", params.nonce),
|
|
969
|
+
deadline: (0, witness_values_1.normalizeUint256)("deadline", params.deadline),
|
|
970
|
+
witness: {
|
|
971
|
+
depositRequestHash: (0, witness_values_1.normalizeBytes32)("depositRequestHash", params.depositRequestHash),
|
|
972
|
+
destination: params.destination,
|
|
973
|
+
reserver: (0, witness_values_1.normalizeAddressField)("reserver", params.reserver),
|
|
974
|
+
releaser: (0, witness_values_1.normalizeAddressField)("releaser", params.releaser)
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
};
|
|
978
|
+
}
|
|
414
979
|
}
|
|
415
980
|
});
|
|
416
981
|
|
|
@@ -419,7 +984,7 @@ var require_dist = __commonJS({
|
|
|
419
984
|
"../contracts/evm/escrow-encoding/typescript/dist/index.js"(exports) {
|
|
420
985
|
"use strict";
|
|
421
986
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
422
|
-
exports.PERMIT2_CONTRACT_ADDRESS = exports.hashPermitWitnessTransferFrom = exports.createPermitWitnessTransferFromPrehash = exports.computeReserveDigest = exports.ESCROW_V3_ABI_JSON = exports.ESCROW_V2_ABI_JSON = exports.ESCROW_ABI_JSON = exports.ESCROW_ABI = exports.REFUND_WITNESS_TYPES = exports.RELEASE_WITNESS_TYPES = exports.RESERVE_WITNESS_TYPES = exports.createEscrowDomain = exports.createPermit2Domain = exports.PERMIT_WITNESS_TYPES_V2 = exports.PERMIT_WITNESS_TYPES = exports.generateNonce = exports.computePaymentIdV2 = exports.computePaymentId = void 0;
|
|
987
|
+
exports.MAX_DESTINATION_BYTES = exports.createPermitWitnessTransferFromPrehashWithDestination = exports.PERMIT2_CONTRACT_ADDRESS = exports.hashPermitWitnessTransferFrom = exports.createPermitWitnessTransferFromPrehash = exports.computeRefundDigestWithQuoteHash = exports.buildRefundTypedDataWithQuoteHash = exports.computeReleaseDigestWithQuoteHash = exports.buildReleaseTypedDataWithQuoteHash = exports.computeReserveDigestWithQuoteSource = exports.buildReserveTypedDataWithQuoteSource = exports.computeReserveDigest = exports.ESCROW_V3_ABI_JSON = exports.ESCROW_V2_ABI_JSON = exports.ESCROW_ABI_JSON = exports.ESCROW_ABI = exports.REFUND_WITNESS_TYPES_WITH_QUOTE_HASH = exports.RELEASE_WITNESS_TYPES_WITH_QUOTE_HASH = exports.RESERVE_WITNESS_TYPES_WITH_QUOTE_SOURCE = exports.PERMIT_WITNESS_TYPES_WITH_DESTINATION = exports.REFUND_WITNESS_TYPES = exports.RELEASE_WITNESS_TYPES = exports.RESERVE_WITNESS_TYPES = exports.createEscrowDomain = exports.createPermit2Domain = exports.PERMIT_WITNESS_TYPES_V2 = exports.PERMIT_WITNESS_TYPES = exports.generateNonce = exports.computePaymentIdV2 = exports.computePaymentId = void 0;
|
|
423
988
|
var payment_id_1 = require_payment_id();
|
|
424
989
|
Object.defineProperty(exports, "computePaymentId", { enumerable: true, get: function() {
|
|
425
990
|
return payment_id_1.computePaymentId;
|
|
@@ -453,6 +1018,19 @@ var require_dist = __commonJS({
|
|
|
453
1018
|
Object.defineProperty(exports, "REFUND_WITNESS_TYPES", { enumerable: true, get: function() {
|
|
454
1019
|
return permit_types_1.REFUND_WITNESS_TYPES;
|
|
455
1020
|
} });
|
|
1021
|
+
var permit_types_2 = require_permit_types();
|
|
1022
|
+
Object.defineProperty(exports, "PERMIT_WITNESS_TYPES_WITH_DESTINATION", { enumerable: true, get: function() {
|
|
1023
|
+
return permit_types_2.PERMIT_WITNESS_TYPES_WITH_DESTINATION;
|
|
1024
|
+
} });
|
|
1025
|
+
Object.defineProperty(exports, "RESERVE_WITNESS_TYPES_WITH_QUOTE_SOURCE", { enumerable: true, get: function() {
|
|
1026
|
+
return permit_types_2.RESERVE_WITNESS_TYPES_WITH_QUOTE_SOURCE;
|
|
1027
|
+
} });
|
|
1028
|
+
Object.defineProperty(exports, "RELEASE_WITNESS_TYPES_WITH_QUOTE_HASH", { enumerable: true, get: function() {
|
|
1029
|
+
return permit_types_2.RELEASE_WITNESS_TYPES_WITH_QUOTE_HASH;
|
|
1030
|
+
} });
|
|
1031
|
+
Object.defineProperty(exports, "REFUND_WITNESS_TYPES_WITH_QUOTE_HASH", { enumerable: true, get: function() {
|
|
1032
|
+
return permit_types_2.REFUND_WITNESS_TYPES_WITH_QUOTE_HASH;
|
|
1033
|
+
} });
|
|
456
1034
|
var escrow_abi_1 = require_escrow_abi();
|
|
457
1035
|
Object.defineProperty(exports, "ESCROW_ABI", { enumerable: true, get: function() {
|
|
458
1036
|
return escrow_abi_1.ESCROW_ABI;
|
|
@@ -469,183 +1047,45 @@ var require_dist = __commonJS({
|
|
|
469
1047
|
var reserve_encoder_1 = require_reserve_encoder();
|
|
470
1048
|
Object.defineProperty(exports, "computeReserveDigest", { enumerable: true, get: function() {
|
|
471
1049
|
return reserve_encoder_1.computeReserveDigest;
|
|
472
|
-
} });
|
|
473
|
-
var
|
|
474
|
-
Object.defineProperty(exports, "
|
|
475
|
-
return
|
|
476
|
-
} });
|
|
477
|
-
Object.defineProperty(exports, "
|
|
478
|
-
return
|
|
479
|
-
} });
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
var
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
Object.defineProperty(exports, "
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
exports
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
exports
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
exports
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
exports.assertWitnessRoles = assertWitnessRoles;
|
|
512
|
-
exports.assertRolePairComplete = assertRolePairComplete;
|
|
513
|
-
exports.nowSec = nowSec;
|
|
514
|
-
var ethers_1 = __require("ethers");
|
|
515
|
-
exports.REPLAY_HORIZON_SECS = 128;
|
|
516
|
-
function resolvePermitDeadline(deadline) {
|
|
517
|
-
return BigInt(deadline);
|
|
518
|
-
}
|
|
519
|
-
function generatePermitNonce() {
|
|
520
|
-
const rand = new Uint32Array(1);
|
|
521
|
-
globalThis.crypto.getRandomValues(rand);
|
|
522
|
-
return (BigInt(Date.now()) << 32n) + BigInt(rand[0]);
|
|
523
|
-
}
|
|
524
|
-
function resolvePermitNonce(nonce) {
|
|
525
|
-
return BigInt(nonce);
|
|
526
|
-
}
|
|
527
|
-
exports.PERMIT_NONCE_DOMAIN = "atum-permit:v1:";
|
|
528
|
-
exports.SOLANA_REPLAY_SLOTS = 235n;
|
|
529
|
-
var SOLANA_BUCKET_BITS = 17n;
|
|
530
|
-
function canonicalDepositor(depositor) {
|
|
531
|
-
const lower = depositor.toLowerCase();
|
|
532
|
-
return lower.startsWith("0x") ? lower : depositor;
|
|
533
|
-
}
|
|
534
|
-
function permitNonceSeed(requestId, depositor) {
|
|
535
|
-
if (!requestId) {
|
|
536
|
-
throw new Error("sender_auth: request_id is required to derive a deterministic permit nonce");
|
|
537
|
-
}
|
|
538
|
-
return BigInt((0, ethers_1.keccak256)((0, ethers_1.toUtf8Bytes)(`${exports.PERMIT_NONCE_DOMAIN}${requestId}:${canonicalDepositor(depositor)}`)));
|
|
539
|
-
}
|
|
540
|
-
function deterministicPermitNonce(params) {
|
|
541
|
-
return permitNonceSeed(params.requestId, params.depositor);
|
|
542
|
-
}
|
|
543
|
-
function deterministicSolanaNonce(params) {
|
|
544
|
-
const seed = permitNonceSeed(params.requestId, params.depositor);
|
|
545
|
-
const slot = seed % exports.SOLANA_REPLAY_SLOTS;
|
|
546
|
-
const bucket = (seed >> 8n) % (1n << SOLANA_BUCKET_BITS);
|
|
547
|
-
return bucket << 32n | slot;
|
|
548
|
-
}
|
|
549
|
-
function sameAddress2(a, b) {
|
|
550
|
-
if (a.startsWith("0x") && b.startsWith("0x")) {
|
|
551
|
-
return a.toLowerCase() === b.toLowerCase();
|
|
552
|
-
}
|
|
553
|
-
return a === b;
|
|
554
|
-
}
|
|
555
|
-
function assertKeyMatchesSender(matches, sender, derived) {
|
|
556
|
-
if (!matches) {
|
|
557
|
-
throw new Error(`sender_auth: private key derives ${derived}, not the expected sender ${sender}`);
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
function assertToken(token, sourceAsset, normalize) {
|
|
561
|
-
if (!sameAddress2(token, normalize(sourceAsset))) {
|
|
562
|
-
throw new Error("sender_auth: permit token does not match the source asset");
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
function assertAmountMatches(amount, maxSourceAmount) {
|
|
566
|
-
if (BigInt(amount) !== BigInt(maxSourceAmount)) {
|
|
567
|
-
throw new Error("sender_auth: permit amount does not match max_source_amount");
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
function assertFresh(deadlineSec, nowSec2) {
|
|
571
|
-
if (deadlineSec <= nowSec2) {
|
|
572
|
-
throw new Error("sender_auth: permit deadline is not in the future");
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
function assertSpender(spender, escrow, normalize) {
|
|
576
|
-
if (!sameAddress2(spender, normalize(escrow))) {
|
|
577
|
-
throw new Error("sender_auth: permit spender is not the source escrow");
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
function assertWitnessRoles(reserver, releaser, expectedReserver, expectedReleaser, normalize) {
|
|
581
|
-
if (!sameAddress2(reserver, normalize(expectedReserver)) || !sameAddress2(releaser, normalize(expectedReleaser))) {
|
|
582
|
-
throw new Error("sender_auth: deposit witness roles do not match the challenge");
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
function assertRolePairComplete(reserver, releaser) {
|
|
586
|
-
if (reserver === void 0 !== (releaser === void 0)) {
|
|
587
|
-
throw new Error("sender_auth: reserver and releaser must be supplied together");
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
function nowSec() {
|
|
591
|
-
return Math.floor(Date.now() / 1e3);
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
});
|
|
595
|
-
|
|
596
|
-
// ../schemas/declarations/PaymentRequest/v1/bindings/typescript/sender-auth/dist/chain-id.js
|
|
597
|
-
var require_chain_id = __commonJS({
|
|
598
|
-
"../schemas/declarations/PaymentRequest/v1/bindings/typescript/sender-auth/dist/chain-id.js"(exports) {
|
|
599
|
-
"use strict";
|
|
600
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
601
|
-
exports.TRON_PERMIT2_FALLBACKS = exports.TRON_CHAIN_IDS = void 0;
|
|
602
|
-
exports.namespaceOf = namespaceOf2;
|
|
603
|
-
exports.evmChainId = evmChainId;
|
|
604
|
-
exports.tronNumericChainId = tronNumericChainId;
|
|
605
|
-
exports.resolveTronPermit2 = resolveTronPermit22;
|
|
606
|
-
exports.clusterIdFromName = clusterIdFromName;
|
|
607
|
-
function namespaceOf2(network) {
|
|
608
|
-
return network.split(":")[0];
|
|
609
|
-
}
|
|
610
|
-
function evmChainId(network) {
|
|
611
|
-
const match = /^eip155:([0-9]+)$/.exec(network);
|
|
612
|
-
if (!match) {
|
|
613
|
-
throw new Error(`sender_auth: expected an eip155 network, got ${network}`);
|
|
614
|
-
}
|
|
615
|
-
return Number(match[1]);
|
|
616
|
-
}
|
|
617
|
-
exports.TRON_CHAIN_IDS = {
|
|
618
|
-
mainnet: 728126428,
|
|
619
|
-
shasta: 2494104990
|
|
620
|
-
};
|
|
621
|
-
function tronNumericChainId(network) {
|
|
622
|
-
const cluster = network.split(":")[1];
|
|
623
|
-
const id = exports.TRON_CHAIN_IDS[cluster ?? ""];
|
|
624
|
-
if (id === void 0) {
|
|
625
|
-
throw new Error(`sender_auth: unsupported Tron network '${network}'`);
|
|
626
|
-
}
|
|
627
|
-
return id;
|
|
628
|
-
}
|
|
629
|
-
exports.TRON_PERMIT2_FALLBACKS = {
|
|
630
|
-
"tron:mainnet": "TJhMXTHQHeQyMD7TcKQFqAePNgG4b31H9m",
|
|
631
|
-
"tron:shasta": "TPUqJPASUn1zLvbLBgRZ5pBYrx7WSe5ahp"
|
|
632
|
-
};
|
|
633
|
-
function resolveTronPermit22(network) {
|
|
634
|
-
const resolved = exports.TRON_PERMIT2_FALLBACKS[network];
|
|
635
|
-
if (!resolved) {
|
|
636
|
-
throw new Error(`sender_auth: no Permit2 address known for Tron network '${network}'`);
|
|
637
|
-
}
|
|
638
|
-
return resolved;
|
|
639
|
-
}
|
|
640
|
-
function clusterIdFromName(name) {
|
|
641
|
-
const encoded = new TextEncoder().encode(name);
|
|
642
|
-
if (encoded.length > 32) {
|
|
643
|
-
throw new Error(`sender_auth: Solana cluster name too long (${encoded.length} > 32 bytes): ${name}`);
|
|
644
|
-
}
|
|
645
|
-
const out = new Uint8Array(32);
|
|
646
|
-
out.set(encoded);
|
|
647
|
-
return out;
|
|
648
|
-
}
|
|
1050
|
+
} });
|
|
1051
|
+
var reserve_encoder_2 = require_reserve_encoder();
|
|
1052
|
+
Object.defineProperty(exports, "buildReserveTypedDataWithQuoteSource", { enumerable: true, get: function() {
|
|
1053
|
+
return reserve_encoder_2.buildReserveTypedDataWithQuoteSource;
|
|
1054
|
+
} });
|
|
1055
|
+
Object.defineProperty(exports, "computeReserveDigestWithQuoteSource", { enumerable: true, get: function() {
|
|
1056
|
+
return reserve_encoder_2.computeReserveDigestWithQuoteSource;
|
|
1057
|
+
} });
|
|
1058
|
+
var release_encoder_1 = require_release_encoder();
|
|
1059
|
+
Object.defineProperty(exports, "buildReleaseTypedDataWithQuoteHash", { enumerable: true, get: function() {
|
|
1060
|
+
return release_encoder_1.buildReleaseTypedDataWithQuoteHash;
|
|
1061
|
+
} });
|
|
1062
|
+
Object.defineProperty(exports, "computeReleaseDigestWithQuoteHash", { enumerable: true, get: function() {
|
|
1063
|
+
return release_encoder_1.computeReleaseDigestWithQuoteHash;
|
|
1064
|
+
} });
|
|
1065
|
+
var refund_encoder_1 = require_refund_encoder();
|
|
1066
|
+
Object.defineProperty(exports, "buildRefundTypedDataWithQuoteHash", { enumerable: true, get: function() {
|
|
1067
|
+
return refund_encoder_1.buildRefundTypedDataWithQuoteHash;
|
|
1068
|
+
} });
|
|
1069
|
+
Object.defineProperty(exports, "computeRefundDigestWithQuoteHash", { enumerable: true, get: function() {
|
|
1070
|
+
return refund_encoder_1.computeRefundDigestWithQuoteHash;
|
|
1071
|
+
} });
|
|
1072
|
+
var deposit_encoder_1 = require_deposit_encoder();
|
|
1073
|
+
Object.defineProperty(exports, "createPermitWitnessTransferFromPrehash", { enumerable: true, get: function() {
|
|
1074
|
+
return deposit_encoder_1.createPermitWitnessTransferFromPrehash;
|
|
1075
|
+
} });
|
|
1076
|
+
Object.defineProperty(exports, "hashPermitWitnessTransferFrom", { enumerable: true, get: function() {
|
|
1077
|
+
return deposit_encoder_1.hashPermitWitnessTransferFrom;
|
|
1078
|
+
} });
|
|
1079
|
+
Object.defineProperty(exports, "PERMIT2_CONTRACT_ADDRESS", { enumerable: true, get: function() {
|
|
1080
|
+
return deposit_encoder_1.PERMIT2_CONTRACT_ADDRESS;
|
|
1081
|
+
} });
|
|
1082
|
+
var deposit_encoder_2 = require_deposit_encoder();
|
|
1083
|
+
Object.defineProperty(exports, "createPermitWitnessTransferFromPrehashWithDestination", { enumerable: true, get: function() {
|
|
1084
|
+
return deposit_encoder_2.createPermitWitnessTransferFromPrehashWithDestination;
|
|
1085
|
+
} });
|
|
1086
|
+
Object.defineProperty(exports, "MAX_DESTINATION_BYTES", { enumerable: true, get: function() {
|
|
1087
|
+
return deposit_encoder_2.MAX_DESTINATION_BYTES;
|
|
1088
|
+
} });
|
|
649
1089
|
}
|
|
650
1090
|
});
|
|
651
1091
|
|
|
@@ -688,22 +1128,23 @@ var require_evm = __commonJS({
|
|
|
688
1128
|
var ethers_1 = __require("ethers");
|
|
689
1129
|
var evm_escrow_encoding_1 = require_dist();
|
|
690
1130
|
var utils_js_1 = require_utils();
|
|
1131
|
+
var destination_js_1 = require_destination();
|
|
691
1132
|
var errors_js_1 = require_errors();
|
|
692
1133
|
var chain_id_js_1 = require_chain_id();
|
|
693
1134
|
exports.evmAdapter = {
|
|
694
|
-
async buildAuthMessage({ sourceAsset, maxSourceAmount, sourceDefaults, deadline, nonce }) {
|
|
1135
|
+
async buildAuthMessage({ sourceAsset, maxSourceAmount, requestId, sourceDefaults, destinationAsset, destinationAccount, deadline, nonce }) {
|
|
695
1136
|
if (nonce === void 0) {
|
|
696
|
-
throw new Error("sender_auth: buildAuthMessage requires an explicit nonce \u2014 derive it deterministically from a stable request id (e.g.
|
|
1137
|
+
throw new Error("sender_auth: buildAuthMessage requires an explicit nonce \u2014 derive it deterministically from a stable request id (e.g. an order id) so retries reproduce the same permit; pass generatePermitNonce() only for genuinely one-shot builds");
|
|
697
1138
|
}
|
|
698
1139
|
if (deadline === void 0) {
|
|
699
1140
|
throw new Error("sender_auth: buildAuthMessage requires an explicit permit deadline (absolute Unix seconds) \u2014 the low-level builder does not default it; derive it from the payment's fulfillment/settlement deadline in the calling layer (pgc/mppx)");
|
|
700
1141
|
}
|
|
701
|
-
const sourceChainId =
|
|
702
|
-
const chainIdNum =
|
|
703
|
-
const
|
|
704
|
-
const
|
|
1142
|
+
const { network: sourceChainId, asset: tokenAddress } = (0, utils_js_1.parseSourceAsset)(sourceAsset);
|
|
1143
|
+
const chainIdNum = (0, chain_id_js_1.evmChainId)(sourceChainId);
|
|
1144
|
+
const permit2Contract = sourceDefaults.permit2Contract ?? evm_escrow_encoding_1.PERMIT2_CONTRACT_ADDRESS;
|
|
1145
|
+
const basePermit = {
|
|
705
1146
|
chainId: chainIdNum,
|
|
706
|
-
verifyingContract:
|
|
1147
|
+
verifyingContract: permit2Contract,
|
|
707
1148
|
token: tokenAddress,
|
|
708
1149
|
amount: maxSourceAmount,
|
|
709
1150
|
spender: sourceDefaults.escrowContract,
|
|
@@ -712,7 +1153,21 @@ var require_evm = __commonJS({
|
|
|
712
1153
|
reserver: sourceDefaults.quoteSelector,
|
|
713
1154
|
releaser: sourceDefaults.fulfillmentVerifierAccount
|
|
714
1155
|
};
|
|
715
|
-
|
|
1156
|
+
if ((0, destination_js_1.usesDestinationCommitment)(sourceDefaults.depositWitnessVersion)) {
|
|
1157
|
+
const permitParams = {
|
|
1158
|
+
...basePermit,
|
|
1159
|
+
// The two escrow commitments. Composed here through the shared helpers rather than
|
|
1160
|
+
// accepted pre-built, so this producer and the release signer cannot disagree about
|
|
1161
|
+
// formatting — a disagreement the escrow cannot detect, because it stores only
|
|
1162
|
+
// keccak256(bytes(destination)).
|
|
1163
|
+
depositRequestHash: (0, destination_js_1.deriveDepositRequestHash)(requestId),
|
|
1164
|
+
destination: (0, destination_js_1.buildEscrowDestination)(destinationAsset, destinationAccount)
|
|
1165
|
+
};
|
|
1166
|
+
const messagePrehash2 = (0, evm_escrow_encoding_1.createPermitWitnessTransferFromPrehashWithDestination)(permitParams);
|
|
1167
|
+
const messageHash2 = (0, evm_escrow_encoding_1.hashPermitWitnessTransferFrom)(messagePrehash2);
|
|
1168
|
+
return { messageScheme: "EVM_PERMIT2", messageHash: messageHash2, messagePrehash: JSON.stringify(messagePrehash2) };
|
|
1169
|
+
}
|
|
1170
|
+
const messagePrehash = (0, evm_escrow_encoding_1.createPermitWitnessTransferFromPrehash)(basePermit);
|
|
716
1171
|
const messageHash = (0, evm_escrow_encoding_1.hashPermitWitnessTransferFrom)(messagePrehash);
|
|
717
1172
|
return { messageScheme: "EVM_PERMIT2", messageHash, messagePrehash: JSON.stringify(messagePrehash) };
|
|
718
1173
|
},
|
|
@@ -721,6 +1176,10 @@ var require_evm = __commonJS({
|
|
|
721
1176
|
throw new Error("EVM adapter sign(): signed_messages[i].message_prehash is required");
|
|
722
1177
|
}
|
|
723
1178
|
const prehash = JSON.parse(signedMessage.message_prehash);
|
|
1179
|
+
const prehashDigest = (0, evm_escrow_encoding_1.hashPermitWitnessTransferFrom)(prehash);
|
|
1180
|
+
if (prehashDigest.toLowerCase() !== signedMessage.message.toLowerCase()) {
|
|
1181
|
+
throw new Error(`EVM adapter sign(): message_prehash implies digest ${prehashDigest} but message is ${signedMessage.message}`);
|
|
1182
|
+
}
|
|
724
1183
|
const wallet = new ethers_1.Wallet(privateKey);
|
|
725
1184
|
return wallet.signTypedData(prehash.domain, prehash.types, prehash.message);
|
|
726
1185
|
},
|
|
@@ -741,17 +1200,31 @@ var require_evm = __commonJS({
|
|
|
741
1200
|
let msg;
|
|
742
1201
|
try {
|
|
743
1202
|
msg = JSON.parse(signed.message_prehash).message;
|
|
744
|
-
|
|
1203
|
+
const base = {
|
|
745
1204
|
chainId: (0, chain_id_js_1.evmChainId)(source.network),
|
|
746
|
-
|
|
1205
|
+
// The same Permit2 buildAuthMessage signed against. Taken from the VERIFIER's
|
|
1206
|
+
// expectations, never from msg — the prehash is client-supplied, so reading the domain
|
|
1207
|
+
// out of it would let a caller nominate its own verifying contract and have the
|
|
1208
|
+
// signature check itself. Absent means canonical, matching the build side's default.
|
|
1209
|
+
verifyingContract: expected.permit2Contract ?? evm_escrow_encoding_1.PERMIT2_CONTRACT_ADDRESS,
|
|
747
1210
|
token: msg.permitted.token,
|
|
748
1211
|
amount: msg.permitted.amount,
|
|
749
1212
|
spender: msg.spender,
|
|
750
1213
|
nonce: BigInt(msg.nonce),
|
|
751
1214
|
deadline: BigInt(msg.deadline),
|
|
752
|
-
reserver: msg.witness
|
|
753
|
-
releaser: msg.witness
|
|
754
|
-
}
|
|
1215
|
+
reserver: msg.witness?.reserver,
|
|
1216
|
+
releaser: msg.witness?.releaser
|
|
1217
|
+
};
|
|
1218
|
+
const hasHash = typeof msg.witness?.depositRequestHash === "string";
|
|
1219
|
+
const hasDestination = typeof msg.witness?.destination === "string";
|
|
1220
|
+
if (hasHash !== hasDestination) {
|
|
1221
|
+
throw new Error("half-populated deposit witness");
|
|
1222
|
+
}
|
|
1223
|
+
canonical = hasHash ? (0, evm_escrow_encoding_1.createPermitWitnessTransferFromPrehashWithDestination)({
|
|
1224
|
+
...base,
|
|
1225
|
+
depositRequestHash: msg.witness.depositRequestHash,
|
|
1226
|
+
destination: msg.witness.destination
|
|
1227
|
+
}) : (0, evm_escrow_encoding_1.createPermitWitnessTransferFromPrehash)(base);
|
|
755
1228
|
} catch {
|
|
756
1229
|
throw new errors_js_1.MalformedPrehashError();
|
|
757
1230
|
}
|
|
@@ -775,6 +1248,12 @@ var require_evm = __commonJS({
|
|
|
775
1248
|
if (expected.reserver !== void 0 && expected.releaser !== void 0) {
|
|
776
1249
|
(0, utils_js_1.assertWitnessRoles)(msg.witness.reserver, msg.witness.releaser, expected.reserver, expected.releaser, (a) => a);
|
|
777
1250
|
}
|
|
1251
|
+
if (expected.destination !== void 0) {
|
|
1252
|
+
(0, utils_js_1.assertDestination)(msg.witness.destination, expected.destination);
|
|
1253
|
+
}
|
|
1254
|
+
if (expected.requestId !== void 0) {
|
|
1255
|
+
(0, utils_js_1.assertDepositRequestHash)(msg.witness.depositRequestHash, expected.requestId);
|
|
1256
|
+
}
|
|
778
1257
|
return {
|
|
779
1258
|
amount: msg.permitted.amount,
|
|
780
1259
|
deadlineSec,
|
|
@@ -785,7 +1264,11 @@ var require_evm = __commonJS({
|
|
|
785
1264
|
deadlineSec,
|
|
786
1265
|
reserver: msg.witness.reserver,
|
|
787
1266
|
releaser: msg.witness.releaser,
|
|
788
|
-
spender: msg.spender
|
|
1267
|
+
spender: msg.spender,
|
|
1268
|
+
// Surfaced whether or not the opt-in checks above ran, so a consumer binding these
|
|
1269
|
+
// downstream does not have to re-parse message_prehash and risk drifting from this parse.
|
|
1270
|
+
destination: msg.witness.destination,
|
|
1271
|
+
depositRequestHash: msg.witness.depositRequestHash
|
|
789
1272
|
}
|
|
790
1273
|
};
|
|
791
1274
|
}
|
|
@@ -843,7 +1326,7 @@ var require_tron_address = __commonJS({
|
|
|
843
1326
|
hexAddress = base58ToHex(address);
|
|
844
1327
|
}
|
|
845
1328
|
hexAddress = hexAddress.replace(/^0x/, "");
|
|
846
|
-
if (hexAddress.startsWith(TVM_MAINNET_PREFIX)) {
|
|
1329
|
+
if (hexAddress.length === 42 && hexAddress.startsWith(TVM_MAINNET_PREFIX)) {
|
|
847
1330
|
hexAddress = hexAddress.substring(2);
|
|
848
1331
|
}
|
|
849
1332
|
if (hexAddress.length !== 40) {
|
|
@@ -857,14 +1340,62 @@ var require_tron_address = __commonJS({
|
|
|
857
1340
|
}
|
|
858
1341
|
});
|
|
859
1342
|
|
|
1343
|
+
// ../contracts/tvm/escrow-encoding/typescript/dist/witness-values.js
|
|
1344
|
+
var require_witness_values2 = __commonJS({
|
|
1345
|
+
"../contracts/tvm/escrow-encoding/typescript/dist/witness-values.js"(exports) {
|
|
1346
|
+
"use strict";
|
|
1347
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1348
|
+
exports.normalizeBytes32 = normalizeBytes32;
|
|
1349
|
+
exports.normalizeUint256 = normalizeUint256;
|
|
1350
|
+
exports.maskedChainIdToHex = maskedChainIdToHex;
|
|
1351
|
+
var ethers_1 = __require("ethers");
|
|
1352
|
+
var chain_id_1 = require_chain_id2();
|
|
1353
|
+
function normalizeBytes32(label, value) {
|
|
1354
|
+
let bytes;
|
|
1355
|
+
try {
|
|
1356
|
+
bytes = (0, ethers_1.getBytes)(value);
|
|
1357
|
+
} catch {
|
|
1358
|
+
throw new Error(`${label} must be 0x-prefixed hex (32 bytes), got ${JSON.stringify(value)}`);
|
|
1359
|
+
}
|
|
1360
|
+
if (bytes.length !== 32) {
|
|
1361
|
+
throw new Error(`${label} must be exactly 32 bytes, got ${bytes.length}`);
|
|
1362
|
+
}
|
|
1363
|
+
return (0, ethers_1.hexlify)(bytes);
|
|
1364
|
+
}
|
|
1365
|
+
function normalizeUint256(label, value) {
|
|
1366
|
+
let n;
|
|
1367
|
+
try {
|
|
1368
|
+
n = BigInt(value);
|
|
1369
|
+
} catch {
|
|
1370
|
+
throw new Error(`${label} must be an integer (bigint or decimal string), got ${JSON.stringify(value)}`);
|
|
1371
|
+
}
|
|
1372
|
+
if (n < 0n) {
|
|
1373
|
+
throw new Error(`${label} must be non-negative (uint256), got ${n.toString()}`);
|
|
1374
|
+
}
|
|
1375
|
+
return n.toString();
|
|
1376
|
+
}
|
|
1377
|
+
function maskedChainIdToHex(chainId) {
|
|
1378
|
+
if (!Number.isSafeInteger(chainId) || chainId < 0) {
|
|
1379
|
+
throw new Error(`chainId must be a non-negative safe integer, got ${chainId}`);
|
|
1380
|
+
}
|
|
1381
|
+
return `0x${(0, chain_id_1.maskChainId)(chainId).toString(16)}`;
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
});
|
|
1385
|
+
|
|
860
1386
|
// ../contracts/tvm/escrow-encoding/typescript/dist/reserve-encoder.js
|
|
861
1387
|
var require_reserve_encoder2 = __commonJS({
|
|
862
1388
|
"../contracts/tvm/escrow-encoding/typescript/dist/reserve-encoder.js"(exports) {
|
|
863
1389
|
"use strict";
|
|
864
1390
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1391
|
+
exports.RESERVE_WITNESS_TYPES_WITH_QUOTE_SOURCE = void 0;
|
|
865
1392
|
exports.computeReserveDigest = computeReserveDigest;
|
|
1393
|
+
exports.buildTvmReserveTypedDataWithQuoteSource = buildTvmReserveTypedDataWithQuoteSource;
|
|
1394
|
+
exports.computeTvmReserveDigestWithQuoteSource = computeTvmReserveDigestWithQuoteSource;
|
|
866
1395
|
var ethers_1 = __require("ethers");
|
|
867
1396
|
var chain_id_1 = require_chain_id2();
|
|
1397
|
+
var tron_address_1 = require_tron_address();
|
|
1398
|
+
var witness_values_1 = require_witness_values2();
|
|
868
1399
|
var RESERVE_WITNESS_TYPES = {
|
|
869
1400
|
ReserveWitness: [
|
|
870
1401
|
{ name: "paymentId", type: "bytes32" },
|
|
@@ -883,6 +1414,36 @@ var require_reserve_encoder2 = __commonJS({
|
|
|
883
1414
|
settler: input.settler
|
|
884
1415
|
});
|
|
885
1416
|
}
|
|
1417
|
+
exports.RESERVE_WITNESS_TYPES_WITH_QUOTE_SOURCE = {
|
|
1418
|
+
ReserveWitness: [
|
|
1419
|
+
{ name: "depositId", type: "bytes32" },
|
|
1420
|
+
{ name: "quoteHash", type: "bytes32" },
|
|
1421
|
+
{ name: "settler", type: "address" },
|
|
1422
|
+
{ name: "sourceAmount", type: "uint256" }
|
|
1423
|
+
]
|
|
1424
|
+
};
|
|
1425
|
+
function buildTvmReserveTypedDataWithQuoteSource(input) {
|
|
1426
|
+
return {
|
|
1427
|
+
types: exports.RESERVE_WITNESS_TYPES_WITH_QUOTE_SOURCE,
|
|
1428
|
+
primaryType: "ReserveWitness",
|
|
1429
|
+
domain: {
|
|
1430
|
+
name: "Escrow",
|
|
1431
|
+
version: "3",
|
|
1432
|
+
chainId: (0, witness_values_1.maskedChainIdToHex)(input.chainId),
|
|
1433
|
+
verifyingContract: (0, tron_address_1.normalizeAddress)(input.escrowContract)
|
|
1434
|
+
},
|
|
1435
|
+
message: {
|
|
1436
|
+
depositId: (0, witness_values_1.normalizeBytes32)("depositId", input.depositId),
|
|
1437
|
+
quoteHash: (0, witness_values_1.normalizeBytes32)("quoteHash", input.quoteHash),
|
|
1438
|
+
settler: (0, tron_address_1.normalizeAddress)(input.settler),
|
|
1439
|
+
sourceAmount: (0, witness_values_1.normalizeUint256)("sourceAmount", input.sourceAmount)
|
|
1440
|
+
}
|
|
1441
|
+
};
|
|
1442
|
+
}
|
|
1443
|
+
function computeTvmReserveDigestWithQuoteSource(input) {
|
|
1444
|
+
const prehash = buildTvmReserveTypedDataWithQuoteSource(input);
|
|
1445
|
+
return ethers_1.TypedDataEncoder.hash(prehash.domain, prehash.types, prehash.message);
|
|
1446
|
+
}
|
|
886
1447
|
}
|
|
887
1448
|
});
|
|
888
1449
|
|
|
@@ -909,11 +1470,14 @@ var require_deposit_encoder2 = __commonJS({
|
|
|
909
1470
|
"../contracts/tvm/escrow-encoding/typescript/dist/deposit-encoder.js"(exports) {
|
|
910
1471
|
"use strict";
|
|
911
1472
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1473
|
+
exports.MAX_DESTINATION_BYTES = exports.PERMIT_WITNESS_TYPES_WITH_DESTINATION = void 0;
|
|
912
1474
|
exports.createTvmPermitWitnessTransferFromPrehash = createTvmPermitWitnessTransferFromPrehash;
|
|
913
1475
|
exports.hashTvmPermitWitnessTransferFrom = hashTvmPermitWitnessTransferFrom;
|
|
1476
|
+
exports.createTvmPermitWitnessTransferFromPrehashWithDestination = createTvmPermitWitnessTransferFromPrehashWithDestination;
|
|
914
1477
|
var ethers_1 = __require("ethers");
|
|
915
1478
|
var chain_id_1 = require_chain_id2();
|
|
916
1479
|
var tron_address_1 = require_tron_address();
|
|
1480
|
+
var witness_values_1 = require_witness_values2();
|
|
917
1481
|
var PERMIT_WITNESS_TYPES_V2 = {
|
|
918
1482
|
PermitWitnessTransferFrom: [
|
|
919
1483
|
{ name: "permitted", type: "TokenPermissions" },
|
|
@@ -959,6 +1523,180 @@ var require_deposit_encoder2 = __commonJS({
|
|
|
959
1523
|
function hashTvmPermitWitnessTransferFrom(prehash) {
|
|
960
1524
|
return ethers_1.TypedDataEncoder.hash(prehash.domain, prehash.types, prehash.message);
|
|
961
1525
|
}
|
|
1526
|
+
exports.PERMIT_WITNESS_TYPES_WITH_DESTINATION = {
|
|
1527
|
+
PermitWitnessTransferFrom: [
|
|
1528
|
+
{ name: "permitted", type: "TokenPermissions" },
|
|
1529
|
+
{ name: "spender", type: "address" },
|
|
1530
|
+
{ name: "nonce", type: "uint256" },
|
|
1531
|
+
{ name: "deadline", type: "uint256" },
|
|
1532
|
+
{ name: "witness", type: "DepositWitness" }
|
|
1533
|
+
],
|
|
1534
|
+
TokenPermissions: [
|
|
1535
|
+
{ name: "token", type: "address" },
|
|
1536
|
+
{ name: "amount", type: "uint256" }
|
|
1537
|
+
],
|
|
1538
|
+
DepositWitness: [
|
|
1539
|
+
{ name: "depositRequestHash", type: "bytes32" },
|
|
1540
|
+
{ name: "destination", type: "string" },
|
|
1541
|
+
{ name: "reserver", type: "address" },
|
|
1542
|
+
{ name: "releaser", type: "address" }
|
|
1543
|
+
]
|
|
1544
|
+
};
|
|
1545
|
+
exports.MAX_DESTINATION_BYTES = 256;
|
|
1546
|
+
function assertDestinationWithinBounds(destination) {
|
|
1547
|
+
if (destination === "") {
|
|
1548
|
+
throw new Error('destination is empty: the escrow reverts DestinationCannotBeEmpty, and because keccak256("") is a valid bytes32 this would otherwise sign a commitment to no destination at all');
|
|
1549
|
+
}
|
|
1550
|
+
const byteLength = (0, ethers_1.toUtf8Bytes)(destination).length;
|
|
1551
|
+
if (byteLength > exports.MAX_DESTINATION_BYTES) {
|
|
1552
|
+
throw new Error(`destination is ${byteLength} bytes, over the escrow's MAX_DESTINATION_BYTES of ${exports.MAX_DESTINATION_BYTES}: the contract reverts DestinationTooLong, so this digest could never be redeemed`);
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
1555
|
+
function createTvmPermitWitnessTransferFromPrehashWithDestination(params) {
|
|
1556
|
+
assertDestinationWithinBounds(params.destination);
|
|
1557
|
+
return {
|
|
1558
|
+
types: exports.PERMIT_WITNESS_TYPES_WITH_DESTINATION,
|
|
1559
|
+
primaryType: "PermitWitnessTransferFrom",
|
|
1560
|
+
domain: {
|
|
1561
|
+
name: "Permit2",
|
|
1562
|
+
chainId: (0, witness_values_1.maskedChainIdToHex)(params.chainId),
|
|
1563
|
+
verifyingContract: (0, tron_address_1.normalizeAddress)(params.permit2Address)
|
|
1564
|
+
},
|
|
1565
|
+
message: {
|
|
1566
|
+
permitted: {
|
|
1567
|
+
token: (0, tron_address_1.normalizeAddress)(params.tokenAddress),
|
|
1568
|
+
amount: (0, witness_values_1.normalizeUint256)("amount", params.amount)
|
|
1569
|
+
},
|
|
1570
|
+
spender: (0, tron_address_1.normalizeAddress)(params.spenderAddress),
|
|
1571
|
+
nonce: (0, witness_values_1.normalizeUint256)("nonce", params.nonce),
|
|
1572
|
+
deadline: (0, witness_values_1.normalizeUint256)("deadline", params.deadline),
|
|
1573
|
+
witness: {
|
|
1574
|
+
depositRequestHash: (0, witness_values_1.normalizeBytes32)("depositRequestHash", params.depositRequestHash),
|
|
1575
|
+
destination: params.destination,
|
|
1576
|
+
reserver: (0, tron_address_1.normalizeAddress)(params.reserverAddress),
|
|
1577
|
+
releaser: (0, tron_address_1.normalizeAddress)(params.releaserAddress)
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
};
|
|
1581
|
+
}
|
|
1582
|
+
}
|
|
1583
|
+
});
|
|
1584
|
+
|
|
1585
|
+
// ../contracts/tvm/escrow-encoding/typescript/dist/release-encoder.js
|
|
1586
|
+
var require_release_encoder2 = __commonJS({
|
|
1587
|
+
"../contracts/tvm/escrow-encoding/typescript/dist/release-encoder.js"(exports) {
|
|
1588
|
+
"use strict";
|
|
1589
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1590
|
+
exports.RELEASE_WITNESS_TYPES_WITH_QUOTE_HASH = void 0;
|
|
1591
|
+
exports.buildTvmReleaseTypedDataWithQuoteHash = buildTvmReleaseTypedDataWithQuoteHash;
|
|
1592
|
+
exports.computeTvmReleaseDigestWithQuoteHash = computeTvmReleaseDigestWithQuoteHash;
|
|
1593
|
+
var ethers_1 = __require("ethers");
|
|
1594
|
+
var tron_address_1 = require_tron_address();
|
|
1595
|
+
var witness_values_1 = require_witness_values2();
|
|
1596
|
+
exports.RELEASE_WITNESS_TYPES_WITH_QUOTE_HASH = {
|
|
1597
|
+
ReleaseWitness: [
|
|
1598
|
+
{ name: "depositId", type: "bytes32" },
|
|
1599
|
+
{ name: "quoteHash", type: "bytes32" },
|
|
1600
|
+
{ name: "depositRequestHash", type: "bytes32" },
|
|
1601
|
+
{ name: "destinationHash", type: "bytes32" },
|
|
1602
|
+
{ name: "depositor", type: "address" },
|
|
1603
|
+
{ name: "token", type: "address" },
|
|
1604
|
+
{ name: "amount", type: "uint256" },
|
|
1605
|
+
{ name: "feeAmount", type: "uint256" },
|
|
1606
|
+
{ name: "reserver", type: "address" },
|
|
1607
|
+
{ name: "releaser", type: "address" },
|
|
1608
|
+
{ name: "settler", type: "address" }
|
|
1609
|
+
]
|
|
1610
|
+
};
|
|
1611
|
+
function buildTvmReleaseTypedDataWithQuoteHash(input) {
|
|
1612
|
+
const w = input.witness;
|
|
1613
|
+
return {
|
|
1614
|
+
types: exports.RELEASE_WITNESS_TYPES_WITH_QUOTE_HASH,
|
|
1615
|
+
primaryType: "ReleaseWitness",
|
|
1616
|
+
domain: {
|
|
1617
|
+
name: "Escrow",
|
|
1618
|
+
version: "3",
|
|
1619
|
+
chainId: (0, witness_values_1.maskedChainIdToHex)(input.chainId),
|
|
1620
|
+
verifyingContract: (0, tron_address_1.normalizeAddress)(input.escrowContract)
|
|
1621
|
+
},
|
|
1622
|
+
message: {
|
|
1623
|
+
depositId: (0, witness_values_1.normalizeBytes32)("depositId", w.depositId),
|
|
1624
|
+
quoteHash: (0, witness_values_1.normalizeBytes32)("quoteHash", w.quoteHash),
|
|
1625
|
+
depositRequestHash: (0, witness_values_1.normalizeBytes32)("depositRequestHash", w.depositRequestHash),
|
|
1626
|
+
destinationHash: (0, witness_values_1.normalizeBytes32)("destinationHash", w.destinationHash),
|
|
1627
|
+
depositor: (0, tron_address_1.normalizeAddress)(w.depositor),
|
|
1628
|
+
token: (0, tron_address_1.normalizeAddress)(w.token),
|
|
1629
|
+
amount: (0, witness_values_1.normalizeUint256)("amount", w.amount),
|
|
1630
|
+
feeAmount: (0, witness_values_1.normalizeUint256)("feeAmount", w.feeAmount),
|
|
1631
|
+
reserver: (0, tron_address_1.normalizeAddress)(w.reserver),
|
|
1632
|
+
releaser: (0, tron_address_1.normalizeAddress)(w.releaser),
|
|
1633
|
+
settler: (0, tron_address_1.normalizeAddress)(w.settler)
|
|
1634
|
+
}
|
|
1635
|
+
};
|
|
1636
|
+
}
|
|
1637
|
+
function computeTvmReleaseDigestWithQuoteHash(input) {
|
|
1638
|
+
const prehash = buildTvmReleaseTypedDataWithQuoteHash(input);
|
|
1639
|
+
return ethers_1.TypedDataEncoder.hash(prehash.domain, prehash.types, prehash.message);
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1642
|
+
});
|
|
1643
|
+
|
|
1644
|
+
// ../contracts/tvm/escrow-encoding/typescript/dist/refund-encoder.js
|
|
1645
|
+
var require_refund_encoder2 = __commonJS({
|
|
1646
|
+
"../contracts/tvm/escrow-encoding/typescript/dist/refund-encoder.js"(exports) {
|
|
1647
|
+
"use strict";
|
|
1648
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1649
|
+
exports.REFUND_WITNESS_TYPES_WITH_QUOTE_HASH = void 0;
|
|
1650
|
+
exports.buildTvmRefundTypedDataWithQuoteHash = buildTvmRefundTypedDataWithQuoteHash;
|
|
1651
|
+
exports.computeTvmRefundDigestWithQuoteHash = computeTvmRefundDigestWithQuoteHash;
|
|
1652
|
+
var ethers_1 = __require("ethers");
|
|
1653
|
+
var tron_address_1 = require_tron_address();
|
|
1654
|
+
var witness_values_1 = require_witness_values2();
|
|
1655
|
+
exports.REFUND_WITNESS_TYPES_WITH_QUOTE_HASH = {
|
|
1656
|
+
RefundWitness: [
|
|
1657
|
+
{ name: "depositId", type: "bytes32" },
|
|
1658
|
+
{ name: "quoteHash", type: "bytes32" },
|
|
1659
|
+
{ name: "depositRequestHash", type: "bytes32" },
|
|
1660
|
+
{ name: "destinationHash", type: "bytes32" },
|
|
1661
|
+
{ name: "depositor", type: "address" },
|
|
1662
|
+
{ name: "token", type: "address" },
|
|
1663
|
+
{ name: "amount", type: "uint256" },
|
|
1664
|
+
{ name: "feeAmount", type: "uint256" },
|
|
1665
|
+
{ name: "reserver", type: "address" },
|
|
1666
|
+
{ name: "releaser", type: "address" },
|
|
1667
|
+
{ name: "settler", type: "address" }
|
|
1668
|
+
]
|
|
1669
|
+
};
|
|
1670
|
+
function buildTvmRefundTypedDataWithQuoteHash(input) {
|
|
1671
|
+
const w = input.witness;
|
|
1672
|
+
return {
|
|
1673
|
+
types: exports.REFUND_WITNESS_TYPES_WITH_QUOTE_HASH,
|
|
1674
|
+
primaryType: "RefundWitness",
|
|
1675
|
+
domain: {
|
|
1676
|
+
name: "Escrow",
|
|
1677
|
+
version: "3",
|
|
1678
|
+
chainId: (0, witness_values_1.maskedChainIdToHex)(input.chainId),
|
|
1679
|
+
verifyingContract: (0, tron_address_1.normalizeAddress)(input.escrowContract)
|
|
1680
|
+
},
|
|
1681
|
+
message: {
|
|
1682
|
+
depositId: (0, witness_values_1.normalizeBytes32)("depositId", w.depositId),
|
|
1683
|
+
quoteHash: (0, witness_values_1.normalizeBytes32)("quoteHash", w.quoteHash),
|
|
1684
|
+
depositRequestHash: (0, witness_values_1.normalizeBytes32)("depositRequestHash", w.depositRequestHash),
|
|
1685
|
+
destinationHash: (0, witness_values_1.normalizeBytes32)("destinationHash", w.destinationHash),
|
|
1686
|
+
depositor: (0, tron_address_1.normalizeAddress)(w.depositor),
|
|
1687
|
+
token: (0, tron_address_1.normalizeAddress)(w.token),
|
|
1688
|
+
amount: (0, witness_values_1.normalizeUint256)("amount", w.amount),
|
|
1689
|
+
feeAmount: (0, witness_values_1.normalizeUint256)("feeAmount", w.feeAmount),
|
|
1690
|
+
reserver: (0, tron_address_1.normalizeAddress)(w.reserver),
|
|
1691
|
+
releaser: (0, tron_address_1.normalizeAddress)(w.releaser),
|
|
1692
|
+
settler: (0, tron_address_1.normalizeAddress)(w.settler)
|
|
1693
|
+
}
|
|
1694
|
+
};
|
|
1695
|
+
}
|
|
1696
|
+
function computeTvmRefundDigestWithQuoteHash(input) {
|
|
1697
|
+
const prehash = buildTvmRefundTypedDataWithQuoteHash(input);
|
|
1698
|
+
return ethers_1.TypedDataEncoder.hash(prehash.domain, prehash.types, prehash.message);
|
|
1699
|
+
}
|
|
962
1700
|
}
|
|
963
1701
|
});
|
|
964
1702
|
|
|
@@ -967,7 +1705,7 @@ var require_dist2 = __commonJS({
|
|
|
967
1705
|
"../contracts/tvm/escrow-encoding/typescript/dist/index.js"(exports) {
|
|
968
1706
|
"use strict";
|
|
969
1707
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
970
|
-
exports.hashTvmPermitWitnessTransferFrom = exports.createTvmPermitWitnessTransferFromPrehash = exports.computePaymentId = exports.computeReserveDigest = exports.normalizeAddress = exports.base58ToHex = exports.maskChainId = void 0;
|
|
1708
|
+
exports.MAX_DESTINATION_BYTES = exports.createTvmPermitWitnessTransferFromPrehashWithDestination = exports.PERMIT_WITNESS_TYPES_WITH_DESTINATION = exports.computeTvmRefundDigestWithQuoteHash = exports.buildTvmRefundTypedDataWithQuoteHash = exports.REFUND_WITNESS_TYPES_WITH_QUOTE_HASH = exports.computeTvmReleaseDigestWithQuoteHash = exports.buildTvmReleaseTypedDataWithQuoteHash = exports.RELEASE_WITNESS_TYPES_WITH_QUOTE_HASH = exports.computeTvmReserveDigestWithQuoteSource = exports.buildTvmReserveTypedDataWithQuoteSource = exports.RESERVE_WITNESS_TYPES_WITH_QUOTE_SOURCE = exports.hashTvmPermitWitnessTransferFrom = exports.createTvmPermitWitnessTransferFromPrehash = exports.computePaymentId = exports.computeReserveDigest = exports.normalizeAddress = exports.base58ToHex = exports.maskChainId = void 0;
|
|
971
1709
|
var chain_id_1 = require_chain_id2();
|
|
972
1710
|
Object.defineProperty(exports, "maskChainId", { enumerable: true, get: function() {
|
|
973
1711
|
return chain_id_1.maskChainId;
|
|
@@ -994,6 +1732,46 @@ var require_dist2 = __commonJS({
|
|
|
994
1732
|
Object.defineProperty(exports, "hashTvmPermitWitnessTransferFrom", { enumerable: true, get: function() {
|
|
995
1733
|
return deposit_encoder_1.hashTvmPermitWitnessTransferFrom;
|
|
996
1734
|
} });
|
|
1735
|
+
var reserve_encoder_2 = require_reserve_encoder2();
|
|
1736
|
+
Object.defineProperty(exports, "RESERVE_WITNESS_TYPES_WITH_QUOTE_SOURCE", { enumerable: true, get: function() {
|
|
1737
|
+
return reserve_encoder_2.RESERVE_WITNESS_TYPES_WITH_QUOTE_SOURCE;
|
|
1738
|
+
} });
|
|
1739
|
+
Object.defineProperty(exports, "buildTvmReserveTypedDataWithQuoteSource", { enumerable: true, get: function() {
|
|
1740
|
+
return reserve_encoder_2.buildTvmReserveTypedDataWithQuoteSource;
|
|
1741
|
+
} });
|
|
1742
|
+
Object.defineProperty(exports, "computeTvmReserveDigestWithQuoteSource", { enumerable: true, get: function() {
|
|
1743
|
+
return reserve_encoder_2.computeTvmReserveDigestWithQuoteSource;
|
|
1744
|
+
} });
|
|
1745
|
+
var release_encoder_1 = require_release_encoder2();
|
|
1746
|
+
Object.defineProperty(exports, "RELEASE_WITNESS_TYPES_WITH_QUOTE_HASH", { enumerable: true, get: function() {
|
|
1747
|
+
return release_encoder_1.RELEASE_WITNESS_TYPES_WITH_QUOTE_HASH;
|
|
1748
|
+
} });
|
|
1749
|
+
Object.defineProperty(exports, "buildTvmReleaseTypedDataWithQuoteHash", { enumerable: true, get: function() {
|
|
1750
|
+
return release_encoder_1.buildTvmReleaseTypedDataWithQuoteHash;
|
|
1751
|
+
} });
|
|
1752
|
+
Object.defineProperty(exports, "computeTvmReleaseDigestWithQuoteHash", { enumerable: true, get: function() {
|
|
1753
|
+
return release_encoder_1.computeTvmReleaseDigestWithQuoteHash;
|
|
1754
|
+
} });
|
|
1755
|
+
var refund_encoder_1 = require_refund_encoder2();
|
|
1756
|
+
Object.defineProperty(exports, "REFUND_WITNESS_TYPES_WITH_QUOTE_HASH", { enumerable: true, get: function() {
|
|
1757
|
+
return refund_encoder_1.REFUND_WITNESS_TYPES_WITH_QUOTE_HASH;
|
|
1758
|
+
} });
|
|
1759
|
+
Object.defineProperty(exports, "buildTvmRefundTypedDataWithQuoteHash", { enumerable: true, get: function() {
|
|
1760
|
+
return refund_encoder_1.buildTvmRefundTypedDataWithQuoteHash;
|
|
1761
|
+
} });
|
|
1762
|
+
Object.defineProperty(exports, "computeTvmRefundDigestWithQuoteHash", { enumerable: true, get: function() {
|
|
1763
|
+
return refund_encoder_1.computeTvmRefundDigestWithQuoteHash;
|
|
1764
|
+
} });
|
|
1765
|
+
var deposit_encoder_2 = require_deposit_encoder2();
|
|
1766
|
+
Object.defineProperty(exports, "PERMIT_WITNESS_TYPES_WITH_DESTINATION", { enumerable: true, get: function() {
|
|
1767
|
+
return deposit_encoder_2.PERMIT_WITNESS_TYPES_WITH_DESTINATION;
|
|
1768
|
+
} });
|
|
1769
|
+
Object.defineProperty(exports, "createTvmPermitWitnessTransferFromPrehashWithDestination", { enumerable: true, get: function() {
|
|
1770
|
+
return deposit_encoder_2.createTvmPermitWitnessTransferFromPrehashWithDestination;
|
|
1771
|
+
} });
|
|
1772
|
+
Object.defineProperty(exports, "MAX_DESTINATION_BYTES", { enumerable: true, get: function() {
|
|
1773
|
+
return deposit_encoder_2.MAX_DESTINATION_BYTES;
|
|
1774
|
+
} });
|
|
997
1775
|
}
|
|
998
1776
|
});
|
|
999
1777
|
|
|
@@ -1008,18 +1786,18 @@ var require_tron = __commonJS({
|
|
|
1008
1786
|
var utils_js_1 = require_utils();
|
|
1009
1787
|
var errors_js_1 = require_errors();
|
|
1010
1788
|
var chain_id_js_1 = require_chain_id();
|
|
1789
|
+
var destination_js_1 = require_destination();
|
|
1011
1790
|
exports.tronAdapter = {
|
|
1012
|
-
async buildAuthMessage({ sourceAsset, maxSourceAmount, sourceDefaults, deadline, nonce }) {
|
|
1791
|
+
async buildAuthMessage({ sourceAsset, maxSourceAmount, requestId, sourceDefaults, destinationAsset, destinationAccount, deadline, nonce }) {
|
|
1013
1792
|
if (nonce === void 0) {
|
|
1014
|
-
throw new Error("sender_auth: buildAuthMessage requires an explicit nonce \u2014 derive it deterministically from a stable request id (e.g.
|
|
1793
|
+
throw new Error("sender_auth: buildAuthMessage requires an explicit nonce \u2014 derive it deterministically from a stable request id (e.g. an order id) so retries reproduce the same permit; pass generatePermitNonce() only for genuinely one-shot builds");
|
|
1015
1794
|
}
|
|
1016
1795
|
if (deadline === void 0) {
|
|
1017
1796
|
throw new Error("sender_auth: buildAuthMessage requires an explicit permit deadline (absolute Unix seconds) \u2014 the low-level builder does not default it; derive it from the payment's fulfillment/settlement deadline in the calling layer (pgc/mppx)");
|
|
1018
1797
|
}
|
|
1019
|
-
const sourceChainId =
|
|
1020
|
-
const tokenAddress = sourceAsset.split("/")[1].split(":")[1];
|
|
1798
|
+
const { network: sourceChainId, asset: tokenAddress } = (0, utils_js_1.parseSourceAsset)(sourceAsset);
|
|
1021
1799
|
const permit2Address = sourceDefaults.permit2Contract ?? (0, chain_id_js_1.resolveTronPermit2)(sourceChainId);
|
|
1022
|
-
const
|
|
1800
|
+
const baseParams = {
|
|
1023
1801
|
chainId: (0, chain_id_js_1.tronNumericChainId)(sourceChainId),
|
|
1024
1802
|
permit2Address,
|
|
1025
1803
|
tokenAddress,
|
|
@@ -1030,13 +1808,37 @@ var require_tron = __commonJS({
|
|
|
1030
1808
|
reserverAddress: sourceDefaults.quoteSelector,
|
|
1031
1809
|
releaserAddress: sourceDefaults.fulfillmentVerifierAccount
|
|
1032
1810
|
};
|
|
1033
|
-
|
|
1811
|
+
if ((0, destination_js_1.usesDestinationCommitment)(sourceDefaults.depositWitnessVersion)) {
|
|
1812
|
+
const tvmParams = {
|
|
1813
|
+
...baseParams,
|
|
1814
|
+
// The two commitments, composed through the shared helpers rather than accepted
|
|
1815
|
+
// pre-built, so this producer and the Go release signer cannot disagree about
|
|
1816
|
+
// formatting — a disagreement the escrow cannot detect, because it stores only
|
|
1817
|
+
// keccak256(bytes(destination)).
|
|
1818
|
+
depositRequestHash: (0, destination_js_1.deriveDepositRequestHash)(requestId),
|
|
1819
|
+
destination: (0, destination_js_1.buildEscrowDestination)(destinationAsset, destinationAccount)
|
|
1820
|
+
};
|
|
1821
|
+
const messagePrehash2 = (0, tvm_escrow_encoding_1.createTvmPermitWitnessTransferFromPrehashWithDestination)(tvmParams);
|
|
1822
|
+
const messageHash2 = (0, tvm_escrow_encoding_1.hashTvmPermitWitnessTransferFrom)(messagePrehash2);
|
|
1823
|
+
return { messageScheme: "EVM_PERMIT2", messageHash: messageHash2, messagePrehash: JSON.stringify(messagePrehash2) };
|
|
1824
|
+
}
|
|
1825
|
+
const messagePrehash = (0, tvm_escrow_encoding_1.createTvmPermitWitnessTransferFromPrehash)(baseParams);
|
|
1034
1826
|
const messageHash = (0, tvm_escrow_encoding_1.hashTvmPermitWitnessTransferFrom)(messagePrehash);
|
|
1035
1827
|
return { messageScheme: "EVM_PERMIT2", messageHash, messagePrehash: JSON.stringify(messagePrehash) };
|
|
1036
1828
|
},
|
|
1829
|
+
// Signs the TIP-712 typed data, not the bare digest, so a signer can inspect the fields it is
|
|
1830
|
+
// authorizing (Turnkey policies read `eth.eip_712.message[...]`).
|
|
1037
1831
|
async sign(signedMessage, privateKey) {
|
|
1832
|
+
if (!signedMessage.message_prehash) {
|
|
1833
|
+
throw new Error("Tron adapter sign(): signed_messages[i].message_prehash is required");
|
|
1834
|
+
}
|
|
1835
|
+
const prehash = JSON.parse(signedMessage.message_prehash);
|
|
1836
|
+
const prehashDigest = (0, tvm_escrow_encoding_1.hashTvmPermitWitnessTransferFrom)(prehash);
|
|
1837
|
+
if (prehashDigest.toLowerCase() !== signedMessage.message.toLowerCase()) {
|
|
1838
|
+
throw new Error(`Tron adapter sign(): message_prehash implies digest ${prehashDigest} but message is ${signedMessage.message}`);
|
|
1839
|
+
}
|
|
1038
1840
|
const wallet = new ethers_1.Wallet(privateKey.startsWith("0x") ? privateKey : "0x" + privateKey);
|
|
1039
|
-
return wallet.
|
|
1841
|
+
return wallet.signTypedData(prehash.domain, prehash.types, prehash.message);
|
|
1040
1842
|
},
|
|
1041
1843
|
recoverSigner(signed, source) {
|
|
1042
1844
|
let recovered;
|
|
@@ -1055,17 +1857,31 @@ var require_tron = __commonJS({
|
|
|
1055
1857
|
let digest;
|
|
1056
1858
|
try {
|
|
1057
1859
|
msg = JSON.parse(signed.message_prehash).message;
|
|
1058
|
-
const
|
|
1860
|
+
const base = {
|
|
1059
1861
|
chainId: (0, chain_id_js_1.tronNumericChainId)(source.network),
|
|
1060
|
-
|
|
1862
|
+
// The same Permit2 buildAuthMessage signed against, taken from the VERIFIER's
|
|
1863
|
+
// expectations rather than from msg — the prehash is payer-supplied, so reading the
|
|
1864
|
+
// domain out of it would let a caller nominate its own verifying contract. Absent means
|
|
1865
|
+
// the pinned per-chain address, matching the build side's default.
|
|
1866
|
+
permit2Address: expected.permit2Contract ?? (0, chain_id_js_1.resolveTronPermit2)(source.network),
|
|
1061
1867
|
tokenAddress: msg.permitted.token,
|
|
1062
1868
|
amount: msg.permitted.amount,
|
|
1063
1869
|
spenderAddress: msg.spender,
|
|
1064
1870
|
nonce: BigInt(msg.nonce),
|
|
1065
1871
|
deadline: BigInt(msg.deadline),
|
|
1066
|
-
reserverAddress: msg.witness
|
|
1067
|
-
releaserAddress: msg.witness
|
|
1068
|
-
}
|
|
1872
|
+
reserverAddress: msg.witness?.reserver,
|
|
1873
|
+
releaserAddress: msg.witness?.releaser
|
|
1874
|
+
};
|
|
1875
|
+
const hasHash = typeof msg.witness?.depositRequestHash === "string";
|
|
1876
|
+
const hasDestination = typeof msg.witness?.destination === "string";
|
|
1877
|
+
if (hasHash !== hasDestination) {
|
|
1878
|
+
throw new Error("half-populated witness");
|
|
1879
|
+
}
|
|
1880
|
+
const canonical = hasHash ? (0, tvm_escrow_encoding_1.createTvmPermitWitnessTransferFromPrehashWithDestination)({
|
|
1881
|
+
...base,
|
|
1882
|
+
depositRequestHash: msg.witness.depositRequestHash,
|
|
1883
|
+
destination: msg.witness.destination
|
|
1884
|
+
}) : (0, tvm_escrow_encoding_1.createTvmPermitWitnessTransferFromPrehash)(base);
|
|
1069
1885
|
digest = (0, tvm_escrow_encoding_1.hashTvmPermitWitnessTransferFrom)(canonical);
|
|
1070
1886
|
} catch {
|
|
1071
1887
|
throw new errors_js_1.MalformedPrehashError();
|
|
@@ -1113,7 +1929,7 @@ var require_errors2 = __commonJS({
|
|
|
1113
1929
|
"../contracts/svm/escrow-encoding/typescript/dist/errors.js"(exports) {
|
|
1114
1930
|
"use strict";
|
|
1115
1931
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1116
|
-
exports.InvalidHexError = exports.InvalidBase58Error = exports.InvalidPubkeyLengthError = exports.ZeroDepositHashError = exports.ZeroRecipientError = exports.ZeroReleaserError = exports.ZeroReserverError = exports.ZeroAmountError = exports.ZeroMintError = exports.ZeroDepositorError = exports.
|
|
1932
|
+
exports.DestinationTooLongError = exports.EmptyDestinationError = exports.ZeroSourceAmountError = exports.ZeroQuoteHashError = exports.InvalidHexError = exports.InvalidBase58Error = exports.InvalidPubkeyLengthError = exports.ZeroDepositHashError = exports.ZeroRecipientError = exports.ZeroReleaserError = exports.ZeroReserverError = exports.ZeroAmountError = exports.ZeroMintError = exports.ZeroDepositorError = exports.ZeroDepositRequestHashError = exports.EncodingError = void 0;
|
|
1117
1933
|
var EncodingError = class extends Error {
|
|
1118
1934
|
constructor(message) {
|
|
1119
1935
|
super(message);
|
|
@@ -1121,13 +1937,13 @@ var require_errors2 = __commonJS({
|
|
|
1121
1937
|
}
|
|
1122
1938
|
};
|
|
1123
1939
|
exports.EncodingError = EncodingError;
|
|
1124
|
-
var
|
|
1940
|
+
var ZeroDepositRequestHashError = class extends EncodingError {
|
|
1125
1941
|
constructor() {
|
|
1126
|
-
super("
|
|
1127
|
-
this.name = "
|
|
1942
|
+
super("deposit request hash cannot be zero");
|
|
1943
|
+
this.name = "ZeroDepositRequestHashError";
|
|
1128
1944
|
}
|
|
1129
1945
|
};
|
|
1130
|
-
exports.
|
|
1946
|
+
exports.ZeroDepositRequestHashError = ZeroDepositRequestHashError;
|
|
1131
1947
|
var ZeroDepositorError = class extends EncodingError {
|
|
1132
1948
|
constructor() {
|
|
1133
1949
|
super("depositor cannot be zero");
|
|
@@ -1198,6 +2014,34 @@ var require_errors2 = __commonJS({
|
|
|
1198
2014
|
}
|
|
1199
2015
|
};
|
|
1200
2016
|
exports.InvalidHexError = InvalidHexError;
|
|
2017
|
+
var ZeroQuoteHashError = class extends EncodingError {
|
|
2018
|
+
constructor() {
|
|
2019
|
+
super("quote hash cannot be zero");
|
|
2020
|
+
this.name = "ZeroQuoteHashError";
|
|
2021
|
+
}
|
|
2022
|
+
};
|
|
2023
|
+
exports.ZeroQuoteHashError = ZeroQuoteHashError;
|
|
2024
|
+
var ZeroSourceAmountError = class extends EncodingError {
|
|
2025
|
+
constructor() {
|
|
2026
|
+
super("source amount cannot be zero");
|
|
2027
|
+
this.name = "ZeroSourceAmountError";
|
|
2028
|
+
}
|
|
2029
|
+
};
|
|
2030
|
+
exports.ZeroSourceAmountError = ZeroSourceAmountError;
|
|
2031
|
+
var EmptyDestinationError = class extends EncodingError {
|
|
2032
|
+
constructor() {
|
|
2033
|
+
super("destination cannot be empty");
|
|
2034
|
+
this.name = "EmptyDestinationError";
|
|
2035
|
+
}
|
|
2036
|
+
};
|
|
2037
|
+
exports.EmptyDestinationError = EmptyDestinationError;
|
|
2038
|
+
var DestinationTooLongError = class extends EncodingError {
|
|
2039
|
+
constructor() {
|
|
2040
|
+
super("destination exceeds the maximum length");
|
|
2041
|
+
this.name = "DestinationTooLongError";
|
|
2042
|
+
}
|
|
2043
|
+
};
|
|
2044
|
+
exports.DestinationTooLongError = DestinationTooLongError;
|
|
1201
2045
|
}
|
|
1202
2046
|
});
|
|
1203
2047
|
|
|
@@ -1928,13 +2772,36 @@ var require_deposit_encoder3 = __commonJS({
|
|
|
1928
2772
|
"../contracts/svm/escrow-encoding/typescript/dist/deposit-encoder.js"(exports) {
|
|
1929
2773
|
"use strict";
|
|
1930
2774
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2775
|
+
exports.MAX_DESTINATION_LEN = void 0;
|
|
1931
2776
|
exports.computeDepositHash = computeDepositHash;
|
|
2777
|
+
exports.computeDestinationHash = computeDestinationHash;
|
|
2778
|
+
exports.computeDepositHashV2 = computeDepositHashV2;
|
|
1932
2779
|
var encoding_utils_1 = require_encoding_utils();
|
|
1933
2780
|
var escrow_domain_1 = require_escrow_domain();
|
|
1934
2781
|
var errors_1 = require_errors2();
|
|
1935
2782
|
function computeDepositHash(params, domain) {
|
|
1936
|
-
if (params.
|
|
1937
|
-
throw new errors_1.
|
|
2783
|
+
if (params.depositRequestHash.length !== 32 || (0, encoding_utils_1.isZeroBytes32)(params.depositRequestHash)) {
|
|
2784
|
+
throw new errors_1.ZeroDepositRequestHashError();
|
|
2785
|
+
}
|
|
2786
|
+
if (params.depositor.isZero())
|
|
2787
|
+
throw new errors_1.ZeroDepositorError();
|
|
2788
|
+
if (params.mint.isZero())
|
|
2789
|
+
throw new errors_1.ZeroMintError();
|
|
2790
|
+
if (params.amount === 0n)
|
|
2791
|
+
throw new errors_1.ZeroAmountError();
|
|
2792
|
+
if (params.reserver.isZero())
|
|
2793
|
+
throw new errors_1.ZeroReserverError();
|
|
2794
|
+
if (params.releaser.isZero())
|
|
2795
|
+
throw new errors_1.ZeroReleaserError();
|
|
2796
|
+
return (0, encoding_utils_1.keccak256)(...(0, escrow_domain_1.escrowDomainPrefixBytes)(domain), (0, encoding_utils_1.stringToBytes)("deposit"), params.depositRequestHash, params.depositor.toBytes(), params.mint.toBytes(), (0, encoding_utils_1.encodeU64LE)(params.amount), params.reserver.toBytes(), params.releaser.toBytes(), (0, encoding_utils_1.encodeU64LE)(params.nonce), (0, encoding_utils_1.encodeU64LE)(params.issuedAt), (0, encoding_utils_1.encodeU64LE)(params.deadline));
|
|
2797
|
+
}
|
|
2798
|
+
exports.MAX_DESTINATION_LEN = 256;
|
|
2799
|
+
function computeDestinationHash(destination) {
|
|
2800
|
+
return (0, encoding_utils_1.keccak256)((0, encoding_utils_1.stringToBytes)(destination));
|
|
2801
|
+
}
|
|
2802
|
+
function computeDepositHashV2(params, destination, domain) {
|
|
2803
|
+
if (params.depositRequestHash.length !== 32 || (0, encoding_utils_1.isZeroBytes32)(params.depositRequestHash)) {
|
|
2804
|
+
throw new errors_1.ZeroDepositRequestHashError();
|
|
1938
2805
|
}
|
|
1939
2806
|
if (params.depositor.isZero())
|
|
1940
2807
|
throw new errors_1.ZeroDepositorError();
|
|
@@ -1946,7 +2813,28 @@ var require_deposit_encoder3 = __commonJS({
|
|
|
1946
2813
|
throw new errors_1.ZeroReserverError();
|
|
1947
2814
|
if (params.releaser.isZero())
|
|
1948
2815
|
throw new errors_1.ZeroReleaserError();
|
|
1949
|
-
|
|
2816
|
+
if (destination.length === 0)
|
|
2817
|
+
throw new errors_1.EmptyDestinationError();
|
|
2818
|
+
if ((0, encoding_utils_1.stringToBytes)(destination).length > exports.MAX_DESTINATION_LEN) {
|
|
2819
|
+
throw new errors_1.DestinationTooLongError();
|
|
2820
|
+
}
|
|
2821
|
+
return (0, encoding_utils_1.keccak256)(
|
|
2822
|
+
...(0, escrow_domain_1.escrowDomainPrefixBytes)(domain),
|
|
2823
|
+
(0, encoding_utils_1.stringToBytes)("deposit"),
|
|
2824
|
+
params.depositRequestHash,
|
|
2825
|
+
// Hash first: keccak256 concatenates without length prefixes, so injectivity depends on every
|
|
2826
|
+
// hashed field being fixed-width. Feeding the raw string would make it conditional on the
|
|
2827
|
+
// surrounding widths and diverge from the on-chain program, which hashes it too.
|
|
2828
|
+
computeDestinationHash(destination),
|
|
2829
|
+
params.depositor.toBytes(),
|
|
2830
|
+
params.mint.toBytes(),
|
|
2831
|
+
(0, encoding_utils_1.encodeU64LE)(params.amount),
|
|
2832
|
+
params.reserver.toBytes(),
|
|
2833
|
+
params.releaser.toBytes(),
|
|
2834
|
+
(0, encoding_utils_1.encodeU64LE)(params.nonce),
|
|
2835
|
+
(0, encoding_utils_1.encodeU64LE)(params.issuedAt),
|
|
2836
|
+
(0, encoding_utils_1.encodeU64LE)(params.deadline)
|
|
2837
|
+
);
|
|
1950
2838
|
}
|
|
1951
2839
|
}
|
|
1952
2840
|
});
|
|
@@ -1957,6 +2845,8 @@ var require_reserve_encoder3 = __commonJS({
|
|
|
1957
2845
|
"use strict";
|
|
1958
2846
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1959
2847
|
exports.computeReserveHash = computeReserveHash;
|
|
2848
|
+
exports.computeReserveHashV2 = computeReserveHashV2;
|
|
2849
|
+
exports.computeReserveHashV3 = computeReserveHashV3;
|
|
1960
2850
|
var encoding_utils_1 = require_encoding_utils();
|
|
1961
2851
|
var escrow_domain_1 = require_escrow_domain();
|
|
1962
2852
|
var errors_1 = require_errors2();
|
|
@@ -1968,15 +2858,38 @@ var require_reserve_encoder3 = __commonJS({
|
|
|
1968
2858
|
throw new errors_1.ZeroRecipientError();
|
|
1969
2859
|
return (0, encoding_utils_1.keccak256)(...(0, escrow_domain_1.escrowDomainPrefixBytes)(domain), (0, encoding_utils_1.stringToBytes)("reserve"), params.recipient.toBytes(), params.depositHash);
|
|
1970
2860
|
}
|
|
2861
|
+
function computeReserveHashV2(params, quoteHash, domain) {
|
|
2862
|
+
if (params.depositHash.length !== 32 || (0, encoding_utils_1.isZeroBytes32)(params.depositHash)) {
|
|
2863
|
+
throw new errors_1.ZeroDepositHashError();
|
|
2864
|
+
}
|
|
2865
|
+
if (params.recipient.isZero())
|
|
2866
|
+
throw new errors_1.ZeroRecipientError();
|
|
2867
|
+
if (quoteHash.length !== 32 || (0, encoding_utils_1.isZeroBytes32)(quoteHash))
|
|
2868
|
+
throw new errors_1.ZeroQuoteHashError();
|
|
2869
|
+
return (0, encoding_utils_1.keccak256)(...(0, escrow_domain_1.escrowDomainPrefixBytes)(domain), (0, encoding_utils_1.stringToBytes)("reserve"), params.recipient.toBytes(), params.depositHash, quoteHash);
|
|
2870
|
+
}
|
|
2871
|
+
function computeReserveHashV3(params, quoteHash, sourceAmount, domain) {
|
|
2872
|
+
if (params.depositHash.length !== 32 || (0, encoding_utils_1.isZeroBytes32)(params.depositHash)) {
|
|
2873
|
+
throw new errors_1.ZeroDepositHashError();
|
|
2874
|
+
}
|
|
2875
|
+
if (params.recipient.isZero())
|
|
2876
|
+
throw new errors_1.ZeroRecipientError();
|
|
2877
|
+
if (quoteHash.length !== 32 || (0, encoding_utils_1.isZeroBytes32)(quoteHash))
|
|
2878
|
+
throw new errors_1.ZeroQuoteHashError();
|
|
2879
|
+
if (sourceAmount === 0n)
|
|
2880
|
+
throw new errors_1.ZeroSourceAmountError();
|
|
2881
|
+
return (0, encoding_utils_1.keccak256)(...(0, escrow_domain_1.escrowDomainPrefixBytes)(domain), (0, encoding_utils_1.stringToBytes)("reserve"), params.recipient.toBytes(), params.depositHash, quoteHash, (0, encoding_utils_1.encodeU64LE)(sourceAmount));
|
|
2882
|
+
}
|
|
1971
2883
|
}
|
|
1972
2884
|
});
|
|
1973
2885
|
|
|
1974
2886
|
// ../contracts/svm/escrow-encoding/typescript/dist/release-encoder.js
|
|
1975
|
-
var
|
|
2887
|
+
var require_release_encoder3 = __commonJS({
|
|
1976
2888
|
"../contracts/svm/escrow-encoding/typescript/dist/release-encoder.js"(exports) {
|
|
1977
2889
|
"use strict";
|
|
1978
2890
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1979
2891
|
exports.computeReleaseHash = computeReleaseHash;
|
|
2892
|
+
exports.computeReleaseHashV2 = computeReleaseHashV2;
|
|
1980
2893
|
var encoding_utils_1 = require_encoding_utils();
|
|
1981
2894
|
var escrow_domain_1 = require_escrow_domain();
|
|
1982
2895
|
var errors_1 = require_errors2();
|
|
@@ -1986,15 +2899,22 @@ var require_release_encoder = __commonJS({
|
|
|
1986
2899
|
}
|
|
1987
2900
|
return (0, encoding_utils_1.keccak256)(...(0, escrow_domain_1.escrowDomainPrefixBytes)(domain), (0, encoding_utils_1.stringToBytes)("release"), params.depositHash);
|
|
1988
2901
|
}
|
|
2902
|
+
function computeReleaseHashV2(params, quoteHash, domain) {
|
|
2903
|
+
if (params.depositHash.length !== 32 || (0, encoding_utils_1.isZeroBytes32)(params.depositHash)) {
|
|
2904
|
+
throw new errors_1.ZeroDepositHashError();
|
|
2905
|
+
}
|
|
2906
|
+
return (0, encoding_utils_1.keccak256)(...(0, escrow_domain_1.escrowDomainPrefixBytes)(domain), (0, encoding_utils_1.stringToBytes)("release"), params.depositHash, quoteHash);
|
|
2907
|
+
}
|
|
1989
2908
|
}
|
|
1990
2909
|
});
|
|
1991
2910
|
|
|
1992
2911
|
// ../contracts/svm/escrow-encoding/typescript/dist/refund-encoder.js
|
|
1993
|
-
var
|
|
2912
|
+
var require_refund_encoder3 = __commonJS({
|
|
1994
2913
|
"../contracts/svm/escrow-encoding/typescript/dist/refund-encoder.js"(exports) {
|
|
1995
2914
|
"use strict";
|
|
1996
2915
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1997
2916
|
exports.computeRefundHash = computeRefundHash;
|
|
2917
|
+
exports.computeRefundHashV2 = computeRefundHashV2;
|
|
1998
2918
|
var encoding_utils_1 = require_encoding_utils();
|
|
1999
2919
|
var escrow_domain_1 = require_escrow_domain();
|
|
2000
2920
|
var errors_1 = require_errors2();
|
|
@@ -2004,6 +2924,12 @@ var require_refund_encoder = __commonJS({
|
|
|
2004
2924
|
}
|
|
2005
2925
|
return (0, encoding_utils_1.keccak256)(...(0, escrow_domain_1.escrowDomainPrefixBytes)(domain), (0, encoding_utils_1.stringToBytes)("refund"), params.depositHash);
|
|
2006
2926
|
}
|
|
2927
|
+
function computeRefundHashV2(params, quoteHash, domain) {
|
|
2928
|
+
if (params.depositHash.length !== 32 || (0, encoding_utils_1.isZeroBytes32)(params.depositHash)) {
|
|
2929
|
+
throw new errors_1.ZeroDepositHashError();
|
|
2930
|
+
}
|
|
2931
|
+
return (0, encoding_utils_1.keccak256)(...(0, escrow_domain_1.escrowDomainPrefixBytes)(domain), (0, encoding_utils_1.stringToBytes)("refund"), params.depositHash, quoteHash);
|
|
2932
|
+
}
|
|
2007
2933
|
}
|
|
2008
2934
|
});
|
|
2009
2935
|
|
|
@@ -2012,16 +2938,16 @@ var require_nonce_generator2 = __commonJS({
|
|
|
2012
2938
|
"../contracts/svm/escrow-encoding/typescript/dist/nonce-generator.js"(exports) {
|
|
2013
2939
|
"use strict";
|
|
2014
2940
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2015
|
-
exports.MAX_VALID_SLOT = exports.REPLAY_SLOTS = void 0;
|
|
2941
|
+
exports.REPLAY_BUCKETS = exports.MAX_VALID_SLOT = exports.REPLAY_SLOTS = exports.DEPOSIT_COMPUTE_UNIT_LIMIT = void 0;
|
|
2016
2942
|
exports.generateNonce = generateNonce;
|
|
2017
2943
|
var crypto_1 = __require("crypto");
|
|
2944
|
+
exports.DEPOSIT_COMPUTE_UNIT_LIMIT = 4e5;
|
|
2018
2945
|
exports.REPLAY_SLOTS = 235;
|
|
2019
2946
|
exports.MAX_VALID_SLOT = exports.REPLAY_SLOTS - 1;
|
|
2020
|
-
|
|
2947
|
+
exports.REPLAY_BUCKETS = 256;
|
|
2021
2948
|
var NONCE_BUCKET_SHIFT = 32n;
|
|
2022
2949
|
function generateNonce() {
|
|
2023
|
-
const
|
|
2024
|
-
const bucketID = bucketBytes.readUInt32LE(0) & NONCE_BUCKET_MASK;
|
|
2950
|
+
const bucketID = (0, crypto_1.randomBytes)(4).readUInt32LE(0) % exports.REPLAY_BUCKETS;
|
|
2025
2951
|
let slot;
|
|
2026
2952
|
do {
|
|
2027
2953
|
slot = (0, crypto_1.randomBytes)(1)[0];
|
|
@@ -2036,7 +2962,7 @@ var require_dist3 = __commonJS({
|
|
|
2036
2962
|
"../contracts/svm/escrow-encoding/typescript/dist/index.js"(exports) {
|
|
2037
2963
|
"use strict";
|
|
2038
2964
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2039
|
-
exports.MAX_VALID_SLOT = exports.REPLAY_SLOTS = exports.generateNonce = exports.computeRefundHash = exports.computeReleaseHash = exports.computeReserveHash = exports.computeDepositHash = exports.InvalidHexError = exports.InvalidBase58Error = exports.InvalidPubkeyLengthError = exports.ZeroDepositHashError = exports.ZeroRecipientError = exports.ZeroReleaserError = exports.ZeroReserverError = exports.ZeroAmountError = exports.ZeroMintError = exports.ZeroDepositorError = exports.
|
|
2965
|
+
exports.DEPOSIT_COMPUTE_UNIT_LIMIT = exports.REPLAY_BUCKETS = exports.MAX_VALID_SLOT = exports.REPLAY_SLOTS = exports.generateNonce = exports.computeRefundHashV2 = exports.computeRefundHash = exports.computeReleaseHashV2 = exports.computeReleaseHash = exports.computeReserveHashV3 = exports.computeReserveHashV2 = exports.computeReserveHash = exports.MAX_DESTINATION_LEN = exports.computeDestinationHash = exports.computeDepositHashV2 = exports.computeDepositHash = exports.InvalidHexError = exports.InvalidBase58Error = exports.InvalidPubkeyLengthError = exports.ZeroDepositHashError = exports.ZeroRecipientError = exports.ZeroReleaserError = exports.ZeroReserverError = exports.ZeroAmountError = exports.ZeroMintError = exports.ZeroDepositorError = exports.DestinationTooLongError = exports.EmptyDestinationError = exports.ZeroQuoteHashError = exports.ZeroDepositRequestHashError = exports.EncodingError = exports.escrowDomainPrefixBytes = exports.isZeroBytes32 = exports.stringToBytes = exports.keccak256 = exports.encodeU64LE = exports.Pubkey = void 0;
|
|
2040
2966
|
var pubkey_1 = require_pubkey();
|
|
2041
2967
|
Object.defineProperty(exports, "Pubkey", { enumerable: true, get: function() {
|
|
2042
2968
|
return pubkey_1.Pubkey;
|
|
@@ -2062,8 +2988,17 @@ var require_dist3 = __commonJS({
|
|
|
2062
2988
|
Object.defineProperty(exports, "EncodingError", { enumerable: true, get: function() {
|
|
2063
2989
|
return errors_1.EncodingError;
|
|
2064
2990
|
} });
|
|
2065
|
-
Object.defineProperty(exports, "
|
|
2066
|
-
return errors_1.
|
|
2991
|
+
Object.defineProperty(exports, "ZeroDepositRequestHashError", { enumerable: true, get: function() {
|
|
2992
|
+
return errors_1.ZeroDepositRequestHashError;
|
|
2993
|
+
} });
|
|
2994
|
+
Object.defineProperty(exports, "ZeroQuoteHashError", { enumerable: true, get: function() {
|
|
2995
|
+
return errors_1.ZeroQuoteHashError;
|
|
2996
|
+
} });
|
|
2997
|
+
Object.defineProperty(exports, "EmptyDestinationError", { enumerable: true, get: function() {
|
|
2998
|
+
return errors_1.EmptyDestinationError;
|
|
2999
|
+
} });
|
|
3000
|
+
Object.defineProperty(exports, "DestinationTooLongError", { enumerable: true, get: function() {
|
|
3001
|
+
return errors_1.DestinationTooLongError;
|
|
2067
3002
|
} });
|
|
2068
3003
|
Object.defineProperty(exports, "ZeroDepositorError", { enumerable: true, get: function() {
|
|
2069
3004
|
return errors_1.ZeroDepositorError;
|
|
@@ -2099,18 +3034,39 @@ var require_dist3 = __commonJS({
|
|
|
2099
3034
|
Object.defineProperty(exports, "computeDepositHash", { enumerable: true, get: function() {
|
|
2100
3035
|
return deposit_encoder_1.computeDepositHash;
|
|
2101
3036
|
} });
|
|
3037
|
+
Object.defineProperty(exports, "computeDepositHashV2", { enumerable: true, get: function() {
|
|
3038
|
+
return deposit_encoder_1.computeDepositHashV2;
|
|
3039
|
+
} });
|
|
3040
|
+
Object.defineProperty(exports, "computeDestinationHash", { enumerable: true, get: function() {
|
|
3041
|
+
return deposit_encoder_1.computeDestinationHash;
|
|
3042
|
+
} });
|
|
3043
|
+
Object.defineProperty(exports, "MAX_DESTINATION_LEN", { enumerable: true, get: function() {
|
|
3044
|
+
return deposit_encoder_1.MAX_DESTINATION_LEN;
|
|
3045
|
+
} });
|
|
2102
3046
|
var reserve_encoder_1 = require_reserve_encoder3();
|
|
2103
3047
|
Object.defineProperty(exports, "computeReserveHash", { enumerable: true, get: function() {
|
|
2104
3048
|
return reserve_encoder_1.computeReserveHash;
|
|
2105
3049
|
} });
|
|
2106
|
-
|
|
3050
|
+
Object.defineProperty(exports, "computeReserveHashV2", { enumerable: true, get: function() {
|
|
3051
|
+
return reserve_encoder_1.computeReserveHashV2;
|
|
3052
|
+
} });
|
|
3053
|
+
Object.defineProperty(exports, "computeReserveHashV3", { enumerable: true, get: function() {
|
|
3054
|
+
return reserve_encoder_1.computeReserveHashV3;
|
|
3055
|
+
} });
|
|
3056
|
+
var release_encoder_1 = require_release_encoder3();
|
|
2107
3057
|
Object.defineProperty(exports, "computeReleaseHash", { enumerable: true, get: function() {
|
|
2108
3058
|
return release_encoder_1.computeReleaseHash;
|
|
2109
3059
|
} });
|
|
2110
|
-
|
|
3060
|
+
Object.defineProperty(exports, "computeReleaseHashV2", { enumerable: true, get: function() {
|
|
3061
|
+
return release_encoder_1.computeReleaseHashV2;
|
|
3062
|
+
} });
|
|
3063
|
+
var refund_encoder_1 = require_refund_encoder3();
|
|
2111
3064
|
Object.defineProperty(exports, "computeRefundHash", { enumerable: true, get: function() {
|
|
2112
3065
|
return refund_encoder_1.computeRefundHash;
|
|
2113
3066
|
} });
|
|
3067
|
+
Object.defineProperty(exports, "computeRefundHashV2", { enumerable: true, get: function() {
|
|
3068
|
+
return refund_encoder_1.computeRefundHashV2;
|
|
3069
|
+
} });
|
|
2114
3070
|
var nonce_generator_1 = require_nonce_generator2();
|
|
2115
3071
|
Object.defineProperty(exports, "generateNonce", { enumerable: true, get: function() {
|
|
2116
3072
|
return nonce_generator_1.generateNonce;
|
|
@@ -2121,6 +3077,12 @@ var require_dist3 = __commonJS({
|
|
|
2121
3077
|
Object.defineProperty(exports, "MAX_VALID_SLOT", { enumerable: true, get: function() {
|
|
2122
3078
|
return nonce_generator_1.MAX_VALID_SLOT;
|
|
2123
3079
|
} });
|
|
3080
|
+
Object.defineProperty(exports, "REPLAY_BUCKETS", { enumerable: true, get: function() {
|
|
3081
|
+
return nonce_generator_1.REPLAY_BUCKETS;
|
|
3082
|
+
} });
|
|
3083
|
+
Object.defineProperty(exports, "DEPOSIT_COMPUTE_UNIT_LIMIT", { enumerable: true, get: function() {
|
|
3084
|
+
return nonce_generator_1.DEPOSIT_COMPUTE_UNIT_LIMIT;
|
|
3085
|
+
} });
|
|
2124
3086
|
}
|
|
2125
3087
|
});
|
|
2126
3088
|
|
|
@@ -2137,6 +3099,7 @@ var require_solana = __commonJS({
|
|
|
2137
3099
|
var tweetnacl_1 = __importDefault(__require("tweetnacl"));
|
|
2138
3100
|
var bs58_1 = __importDefault(__require("bs58"));
|
|
2139
3101
|
var solana_escrow_encoding_1 = require_dist3();
|
|
3102
|
+
var destination_js_1 = require_destination();
|
|
2140
3103
|
var utils_js_1 = require_utils();
|
|
2141
3104
|
var errors_js_1 = require_errors();
|
|
2142
3105
|
var chain_id_js_1 = require_chain_id();
|
|
@@ -2146,7 +3109,8 @@ var require_solana = __commonJS({
|
|
|
2146
3109
|
}
|
|
2147
3110
|
function hashDeposit(prehash, domain) {
|
|
2148
3111
|
return (0, ethers_1.hexlify)((0, solana_escrow_encoding_1.computeDepositHash)({
|
|
2149
|
-
|
|
3112
|
+
// The encoder field was renamed for cross-VM parity; the prehash WIRE key stays payment_id.
|
|
3113
|
+
depositRequestHash: (0, ethers_1.getBytes)(prehash.payment_id),
|
|
2150
3114
|
depositor: solana_escrow_encoding_1.Pubkey.fromBase58(prehash.depositor),
|
|
2151
3115
|
mint: solana_escrow_encoding_1.Pubkey.fromBase58(prehash.mint),
|
|
2152
3116
|
amount: BigInt(prehash.amount),
|
|
@@ -2157,6 +3121,26 @@ var require_solana = __commonJS({
|
|
|
2157
3121
|
deadline: BigInt(prehash.deadline)
|
|
2158
3122
|
}, domain));
|
|
2159
3123
|
}
|
|
3124
|
+
var SVM_DESTINATION_COMMITMENT_VERSION = 4;
|
|
3125
|
+
function hashDepositV2(prehash, domain) {
|
|
3126
|
+
return (0, ethers_1.hexlify)((0, solana_escrow_encoding_1.computeDepositHashV2)(
|
|
3127
|
+
{
|
|
3128
|
+
depositRequestHash: (0, ethers_1.getBytes)(prehash.deposit_request_hash),
|
|
3129
|
+
depositor: solana_escrow_encoding_1.Pubkey.fromBase58(prehash.depositor),
|
|
3130
|
+
mint: solana_escrow_encoding_1.Pubkey.fromBase58(prehash.mint),
|
|
3131
|
+
amount: BigInt(prehash.amount),
|
|
3132
|
+
reserver: solana_escrow_encoding_1.Pubkey.fromBase58(prehash.reserver),
|
|
3133
|
+
releaser: solana_escrow_encoding_1.Pubkey.fromBase58(prehash.releaser),
|
|
3134
|
+
nonce: BigInt(prehash.nonce),
|
|
3135
|
+
issuedAt: BigInt(prehash.issued_at),
|
|
3136
|
+
deadline: BigInt(prehash.deadline)
|
|
3137
|
+
},
|
|
3138
|
+
// Plaintext, NOT pre-hashed: the encoder hashes it, and hashing an already-hashed
|
|
3139
|
+
// destination yields a well-formed commitment no on-chain state can satisfy.
|
|
3140
|
+
prehash.destination,
|
|
3141
|
+
domain
|
|
3142
|
+
));
|
|
3143
|
+
}
|
|
2160
3144
|
function domainFrom(defaults) {
|
|
2161
3145
|
if (!defaults.escrowContract) {
|
|
2162
3146
|
throw new Error("sender_auth: Solana source requires escrowContract (escrow program id) for the deposit-hash domain");
|
|
@@ -2171,12 +3155,11 @@ var require_solana = __commonJS({
|
|
|
2171
3155
|
};
|
|
2172
3156
|
}
|
|
2173
3157
|
exports.solanaAdapter = {
|
|
2174
|
-
async buildAuthMessage({ sourceAsset, depositor, maxSourceAmount, requestId, sourceDefaults, nonce, solanaClockReader }) {
|
|
3158
|
+
async buildAuthMessage({ sourceAsset, depositor, maxSourceAmount, requestId, sourceDefaults, destinationAsset, destinationAccount, nonce, solanaClockReader }) {
|
|
2175
3159
|
if (!requestId) {
|
|
2176
3160
|
throw new Error("sender_auth: request_id is required");
|
|
2177
3161
|
}
|
|
2178
|
-
const sourceChainId =
|
|
2179
|
-
const tokenMint = sourceAsset.split("/")[1].split(":")[1];
|
|
3162
|
+
const { network: sourceChainId, asset: tokenMint } = (0, utils_js_1.parseSourceAsset)(sourceAsset);
|
|
2180
3163
|
const depositNonce = nonce !== void 0 ? BigInt(nonce) : (0, solana_escrow_encoding_1.generateNonce)();
|
|
2181
3164
|
if (nonce !== void 0) {
|
|
2182
3165
|
if (depositNonce < 0n || depositNonce >= 1n << 64n) {
|
|
@@ -2189,8 +3172,8 @@ var require_solana = __commonJS({
|
|
|
2189
3172
|
const issuedAt = solanaClockReader ? await solanaClockReader(sourceChainId) : BigInt(Math.floor(Date.now() / 1e3));
|
|
2190
3173
|
const deadline = issuedAt + BigInt(utils_js_1.REPLAY_HORIZON_SECS - 8);
|
|
2191
3174
|
const paymentId = generateSolanaPaymentIdV3(requestId);
|
|
2192
|
-
const
|
|
2193
|
-
|
|
3175
|
+
const domain = domainFrom(sourceDefaults);
|
|
3176
|
+
const common = {
|
|
2194
3177
|
depositor,
|
|
2195
3178
|
mint: tokenMint,
|
|
2196
3179
|
amount: BigInt(maxSourceAmount).toString(),
|
|
@@ -2200,7 +3183,20 @@ var require_solana = __commonJS({
|
|
|
2200
3183
|
issued_at: issuedAt.toString(),
|
|
2201
3184
|
deadline: deadline.toString()
|
|
2202
3185
|
};
|
|
2203
|
-
|
|
3186
|
+
if (domain.signatureDomainVersion >= SVM_DESTINATION_COMMITMENT_VERSION) {
|
|
3187
|
+
const prehashV2 = {
|
|
3188
|
+
deposit_request_hash: paymentId,
|
|
3189
|
+
destination: (0, destination_js_1.buildEscrowDestination)(destinationAsset, destinationAccount),
|
|
3190
|
+
...common
|
|
3191
|
+
};
|
|
3192
|
+
return {
|
|
3193
|
+
messageScheme: "SOLANA",
|
|
3194
|
+
messageHash: hashDepositV2(prehashV2, domain),
|
|
3195
|
+
messagePrehash: JSON.stringify(prehashV2)
|
|
3196
|
+
};
|
|
3197
|
+
}
|
|
3198
|
+
const prehash = { payment_id: paymentId, ...common };
|
|
3199
|
+
const depositHash = hashDeposit(prehash, domain);
|
|
2204
3200
|
return { messageScheme: "SOLANA", messageHash: depositHash, messagePrehash: JSON.stringify(prehash) };
|
|
2205
3201
|
},
|
|
2206
3202
|
async sign(signedMessage, privateKey) {
|
|
@@ -2246,8 +3242,18 @@ var require_solana = __commonJS({
|
|
|
2246
3242
|
let prehash;
|
|
2247
3243
|
let canonicalHash;
|
|
2248
3244
|
try {
|
|
2249
|
-
|
|
2250
|
-
|
|
3245
|
+
const domain = domainFrom(expected);
|
|
3246
|
+
if (domain.signatureDomainVersion >= SVM_DESTINATION_COMMITMENT_VERSION) {
|
|
3247
|
+
const v2 = JSON.parse(signed.message_prehash);
|
|
3248
|
+
if (typeof v2.deposit_request_hash !== "string" || typeof v2.destination !== "string") {
|
|
3249
|
+
throw new Error("pre-widening V1 prehash on a destination-committing domain");
|
|
3250
|
+
}
|
|
3251
|
+
canonicalHash = hashDepositV2(v2, domain);
|
|
3252
|
+
prehash = { payment_id: v2.deposit_request_hash, ...v2 };
|
|
3253
|
+
} else {
|
|
3254
|
+
prehash = JSON.parse(signed.message_prehash);
|
|
3255
|
+
canonicalHash = hashDeposit(prehash, domain);
|
|
3256
|
+
}
|
|
2251
3257
|
} catch {
|
|
2252
3258
|
throw new errors_js_1.MalformedPrehashError();
|
|
2253
3259
|
}
|
|
@@ -2339,14 +3345,7 @@ var require_verify = __commonJS({
|
|
|
2339
3345
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2340
3346
|
exports.verifyPaymentRequest = verifyPaymentRequest;
|
|
2341
3347
|
var index_js_1 = require_adapters();
|
|
2342
|
-
|
|
2343
|
-
const parts = assetIdentifier2.split("/");
|
|
2344
|
-
const nsParts = parts[1]?.split(":");
|
|
2345
|
-
if (parts.length < 2 || !nsParts || nsParts.length < 2 || !nsParts[1]) {
|
|
2346
|
-
throw new Error(`sender_auth: invalid source asset "${assetIdentifier2}"`);
|
|
2347
|
-
}
|
|
2348
|
-
return { network: parts[0], asset: nsParts[1] };
|
|
2349
|
-
}
|
|
3348
|
+
var utils_js_1 = require_utils();
|
|
2350
3349
|
function verifyPaymentRequest(request, expected = {}) {
|
|
2351
3350
|
const senderAuth = request.sender_auth;
|
|
2352
3351
|
if (!senderAuth?.signed_messages?.length) {
|
|
@@ -2355,7 +3354,7 @@ var require_verify = __commonJS({
|
|
|
2355
3354
|
if (!request.source) {
|
|
2356
3355
|
throw new Error("sender_auth: request has no source");
|
|
2357
3356
|
}
|
|
2358
|
-
const requestSource = parseSourceAsset(request.source.asset_identifier);
|
|
3357
|
+
const requestSource = (0, utils_js_1.parseSourceAsset)(request.source.asset_identifier);
|
|
2359
3358
|
const { sourceAsset, network: networkOverride, maxSourceAmount: amountOverride, ...scheme } = expected;
|
|
2360
3359
|
const network = networkOverride ?? requestSource.network;
|
|
2361
3360
|
const asset = sourceAsset ?? requestSource.asset;
|
|
@@ -2410,7 +3409,7 @@ var require_dist4 = __commonJS({
|
|
|
2410
3409
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p)) __createBinding(exports2, m, p);
|
|
2411
3410
|
};
|
|
2412
3411
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2413
|
-
exports.localKeySigner = exports.SignerMismatchError = exports.RecoveryFailedError = exports.MalformedPrehashError = exports.verifyPaymentRequest = exports.getChainAdapter = void 0;
|
|
3412
|
+
exports.localKeySigner = exports.SignerMismatchError = exports.RecoveryFailedError = exports.MalformedPrehashError = exports.verifyPaymentRequest = exports.DESTINATION_COMMITMENT_WITNESS_VERSION = exports.usesDestinationCommitment = exports.MAX_DESTINATION_BYTES = exports.deriveDepositRequestHash = exports.buildEscrowDestination = exports.getChainAdapter = void 0;
|
|
2414
3413
|
__exportStar(require_types(), exports);
|
|
2415
3414
|
__exportStar(require_utils(), exports);
|
|
2416
3415
|
__exportStar(require_chain_id(), exports);
|
|
@@ -2418,6 +3417,22 @@ var require_dist4 = __commonJS({
|
|
|
2418
3417
|
Object.defineProperty(exports, "getChainAdapter", { enumerable: true, get: function() {
|
|
2419
3418
|
return index_js_1.getChainAdapter;
|
|
2420
3419
|
} });
|
|
3420
|
+
var destination_js_1 = require_destination();
|
|
3421
|
+
Object.defineProperty(exports, "buildEscrowDestination", { enumerable: true, get: function() {
|
|
3422
|
+
return destination_js_1.buildEscrowDestination;
|
|
3423
|
+
} });
|
|
3424
|
+
Object.defineProperty(exports, "deriveDepositRequestHash", { enumerable: true, get: function() {
|
|
3425
|
+
return destination_js_1.deriveDepositRequestHash;
|
|
3426
|
+
} });
|
|
3427
|
+
Object.defineProperty(exports, "MAX_DESTINATION_BYTES", { enumerable: true, get: function() {
|
|
3428
|
+
return destination_js_1.MAX_DESTINATION_BYTES;
|
|
3429
|
+
} });
|
|
3430
|
+
Object.defineProperty(exports, "usesDestinationCommitment", { enumerable: true, get: function() {
|
|
3431
|
+
return destination_js_1.usesDestinationCommitment;
|
|
3432
|
+
} });
|
|
3433
|
+
Object.defineProperty(exports, "DESTINATION_COMMITMENT_WITNESS_VERSION", { enumerable: true, get: function() {
|
|
3434
|
+
return destination_js_1.DESTINATION_COMMITMENT_WITNESS_VERSION;
|
|
3435
|
+
} });
|
|
2421
3436
|
var verify_js_1 = require_verify();
|
|
2422
3437
|
Object.defineProperty(exports, "verifyPaymentRequest", { enumerable: true, get: function() {
|
|
2423
3438
|
return verify_js_1.verifyPaymentRequest;
|
|
@@ -2443,9 +3458,34 @@ var require_dist4 = __commonJS({
|
|
|
2443
3458
|
var import_tvm_escrow_encoding = __toESM(require_dist2(), 1);
|
|
2444
3459
|
var import_payment_request_sender_auth = __toESM(require_dist4(), 1);
|
|
2445
3460
|
import * as z from "zod/mini";
|
|
2446
|
-
import { Method } from "mppx";
|
|
3461
|
+
import { Method, PaymentRequest as OpaqueCodec } from "mppx";
|
|
2447
3462
|
var METHOD_NAME = "atum-escrow";
|
|
2448
3463
|
var INTENT = "charge";
|
|
3464
|
+
var INTENT_ID_META_KEY = "atumIntentId";
|
|
3465
|
+
var REQUEST_ID_PREFIX = "req_mpp_";
|
|
3466
|
+
function chargeRequestId(intentId, account) {
|
|
3467
|
+
return (0, import_payment_request_sender_auth.deterministicRequestId)({ anchor: intentId, account, prefix: REQUEST_ID_PREFIX });
|
|
3468
|
+
}
|
|
3469
|
+
function intentIdOf(challenge) {
|
|
3470
|
+
const fromMeta = challenge.meta?.[INTENT_ID_META_KEY];
|
|
3471
|
+
if (typeof fromMeta === "string" && fromMeta !== "") {
|
|
3472
|
+
return fromMeta;
|
|
3473
|
+
}
|
|
3474
|
+
if (challenge.opaque === void 0) {
|
|
3475
|
+
return void 0;
|
|
3476
|
+
}
|
|
3477
|
+
let decoded;
|
|
3478
|
+
try {
|
|
3479
|
+
decoded = OpaqueCodec.deserialize(challenge.opaque);
|
|
3480
|
+
} catch {
|
|
3481
|
+
return void 0;
|
|
3482
|
+
}
|
|
3483
|
+
if (typeof decoded !== "object" || decoded === null) {
|
|
3484
|
+
return void 0;
|
|
3485
|
+
}
|
|
3486
|
+
const value = decoded[INTENT_ID_META_KEY];
|
|
3487
|
+
return typeof value === "string" && value !== "" ? value : void 0;
|
|
3488
|
+
}
|
|
2449
3489
|
var ChargeRequestSchema = z.object({
|
|
2450
3490
|
/** The source chain/token/cap the payer funds from (one option per challenge). */
|
|
2451
3491
|
source: z.object({
|
|
@@ -2526,11 +3566,38 @@ function assetIdentifier(network, asset) {
|
|
|
2526
3566
|
return `${network}/${assetTypeFor(network)}:${asset}`;
|
|
2527
3567
|
}
|
|
2528
3568
|
function sameAddress(a, b) {
|
|
3569
|
+
if (typeof a !== "string" || typeof b !== "string") return false;
|
|
2529
3570
|
if (a.startsWith("0x") && b.startsWith("0x")) {
|
|
2530
3571
|
return a.toLowerCase() === b.toLowerCase();
|
|
2531
3572
|
}
|
|
2532
3573
|
return a === b;
|
|
2533
3574
|
}
|
|
3575
|
+
function sameAssetIdentifier(a, b) {
|
|
3576
|
+
if (a === b) return true;
|
|
3577
|
+
const pa = splitAssetIdentifier(a);
|
|
3578
|
+
const pb = splitAssetIdentifier(b);
|
|
3579
|
+
if (!pa || !pb || pa.namespace !== pb.namespace || pa.assetNamespace !== pb.assetNamespace) {
|
|
3580
|
+
return false;
|
|
3581
|
+
}
|
|
3582
|
+
const referenceMatches = pa.namespace === "solana" ? pa.reference === pb.reference : pa.reference.toLowerCase() === pb.reference.toLowerCase();
|
|
3583
|
+
return referenceMatches && sameAddress(pa.token, pb.token);
|
|
3584
|
+
}
|
|
3585
|
+
function splitAssetIdentifier(identifier) {
|
|
3586
|
+
if (typeof identifier !== "string") return void 0;
|
|
3587
|
+
const slash = identifier.indexOf("/");
|
|
3588
|
+
if (slash < 0) return void 0;
|
|
3589
|
+
const chain = identifier.slice(0, slash);
|
|
3590
|
+
const asset = identifier.slice(slash + 1);
|
|
3591
|
+
const chainColon = chain.indexOf(":");
|
|
3592
|
+
const assetColon = asset.indexOf(":");
|
|
3593
|
+
if (chainColon < 0 || assetColon < 0) return void 0;
|
|
3594
|
+
return {
|
|
3595
|
+
namespace: chain.slice(0, chainColon).toLowerCase(),
|
|
3596
|
+
reference: chain.slice(chainColon + 1),
|
|
3597
|
+
assetNamespace: asset.slice(0, assetColon).toLowerCase(),
|
|
3598
|
+
token: asset.slice(assetColon + 1)
|
|
3599
|
+
};
|
|
3600
|
+
}
|
|
2534
3601
|
function chainDefaultsFromExtra(extra, network) {
|
|
2535
3602
|
return {
|
|
2536
3603
|
escrowContract: extra.escrow,
|
|
@@ -2571,12 +3638,16 @@ export {
|
|
|
2571
3638
|
import_payment_request_sender_auth,
|
|
2572
3639
|
METHOD_NAME,
|
|
2573
3640
|
INTENT,
|
|
3641
|
+
INTENT_ID_META_KEY,
|
|
3642
|
+
chargeRequestId,
|
|
3643
|
+
intentIdOf,
|
|
2574
3644
|
ChargeRequestSchema,
|
|
2575
3645
|
CredentialPayloadSchema,
|
|
2576
3646
|
atumEscrowChargeMethod,
|
|
2577
3647
|
namespaceOf,
|
|
2578
3648
|
assetIdentifier,
|
|
2579
3649
|
sameAddress,
|
|
3650
|
+
sameAssetIdentifier,
|
|
2580
3651
|
chainDefaultsFromExtra,
|
|
2581
3652
|
contractOverridesFromExtra
|
|
2582
3653
|
};
|