@atumlabs/mppx-atum-escrow 0.3.0 → 0.4.1
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 +42 -0
- package/LICENSE +201 -165
- package/NOTICE +2 -0
- package/README.md +88 -11
- package/THIRD-PARTY-NOTICES.txt +23 -29
- package/dist/{chunk-4YD6566T.js → chunk-EWIOTGMO.js} +18 -8
- package/dist/{chunk-ZFA5SSUP.js → chunk-IGTT7XSG.js} +7329 -2023
- package/dist/{chunk-Z3AUNEU5.js → chunk-LAWFMGYD.js} +1333 -271
- package/dist/client.d.ts +181 -42
- package/dist/client.js +11 -8
- package/dist/index.d.ts +4 -77
- package/dist/index.js +12 -9
- package/dist/{internal-9tB7y-A7.d.ts → internal-BZBJJfaL.d.ts} +105 -42
- package/dist/server.d.ts +47 -43
- package/dist/server.js +4 -6
- package/package.json +14 -11
|
@@ -11,11 +11,20 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
11
11
|
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
12
12
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
13
13
|
});
|
|
14
|
-
var __esm = (fn, res) => function __init() {
|
|
15
|
-
|
|
14
|
+
var __esm = (fn, res, err) => function __init() {
|
|
15
|
+
if (err) throw err[0];
|
|
16
|
+
try {
|
|
17
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
18
|
+
} catch (e) {
|
|
19
|
+
throw err = [e], e;
|
|
20
|
+
}
|
|
16
21
|
};
|
|
17
22
|
var __commonJS = (cb, mod) => function __require2() {
|
|
18
|
-
|
|
23
|
+
try {
|
|
24
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
25
|
+
} catch (e) {
|
|
26
|
+
throw mod = 0, e;
|
|
27
|
+
}
|
|
19
28
|
};
|
|
20
29
|
var __export = (target, all) => {
|
|
21
30
|
for (var name in all)
|
|
@@ -39,6 +48,307 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
39
48
|
));
|
|
40
49
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
41
50
|
|
|
51
|
+
// ../schemas/declarations/PaymentRequest/v1/bindings/typescript/sender-auth/dist/types.js
|
|
52
|
+
var require_types = __commonJS({
|
|
53
|
+
"../schemas/declarations/PaymentRequest/v1/bindings/typescript/sender-auth/dist/types.js"(exports) {
|
|
54
|
+
"use strict";
|
|
55
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// ../schemas/declarations/PaymentRequest/v1/bindings/typescript/sender-auth/dist/destination.js
|
|
60
|
+
var require_destination = __commonJS({
|
|
61
|
+
"../schemas/declarations/PaymentRequest/v1/bindings/typescript/sender-auth/dist/destination.js"(exports) {
|
|
62
|
+
"use strict";
|
|
63
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
64
|
+
exports.DESTINATION_COMMITMENT_WITNESS_VERSION = exports.MAX_DESTINATION_BYTES = void 0;
|
|
65
|
+
exports.usesDestinationCommitment = usesDestinationCommitment;
|
|
66
|
+
exports.deriveDepositRequestHash = deriveDepositRequestHash;
|
|
67
|
+
exports.buildEscrowDestination = buildEscrowDestination;
|
|
68
|
+
var ethers_1 = __require("ethers");
|
|
69
|
+
exports.MAX_DESTINATION_BYTES = 256;
|
|
70
|
+
var NAMESPACE_EIP155 = "eip155";
|
|
71
|
+
exports.DESTINATION_COMMITMENT_WITNESS_VERSION = 4;
|
|
72
|
+
function usesDestinationCommitment(depositWitnessVersion) {
|
|
73
|
+
return depositWitnessVersion === void 0 || depositWitnessVersion >= exports.DESTINATION_COMMITMENT_WITNESS_VERSION;
|
|
74
|
+
}
|
|
75
|
+
function deriveDepositRequestHash(requestId) {
|
|
76
|
+
if (requestId === "") {
|
|
77
|
+
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');
|
|
78
|
+
}
|
|
79
|
+
return (0, ethers_1.keccak256)((0, ethers_1.toUtf8Bytes)(requestId));
|
|
80
|
+
}
|
|
81
|
+
function buildEscrowDestination(assetIdentifier2, account) {
|
|
82
|
+
if (assetIdentifier2 === "") {
|
|
83
|
+
throw new Error("sender_auth: destination asset_identifier is empty");
|
|
84
|
+
}
|
|
85
|
+
if (account === "") {
|
|
86
|
+
throw new Error("sender_auth: destination account is empty");
|
|
87
|
+
}
|
|
88
|
+
if (assetIdentifier2.includes("@") || account.includes("@")) {
|
|
89
|
+
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`);
|
|
90
|
+
}
|
|
91
|
+
const namespace = caip2Namespace(assetIdentifier2);
|
|
92
|
+
let asset = assetIdentifier2;
|
|
93
|
+
let acct = account;
|
|
94
|
+
if (namespace === NAMESPACE_EIP155) {
|
|
95
|
+
asset = asset.toLowerCase();
|
|
96
|
+
acct = acct.toLowerCase();
|
|
97
|
+
}
|
|
98
|
+
const destination = `${asset}@${acct}`;
|
|
99
|
+
const byteLength = (0, ethers_1.toUtf8Bytes)(destination).length;
|
|
100
|
+
if (byteLength > exports.MAX_DESTINATION_BYTES) {
|
|
101
|
+
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`);
|
|
102
|
+
}
|
|
103
|
+
return destination;
|
|
104
|
+
}
|
|
105
|
+
function caip2Namespace(assetIdentifier2) {
|
|
106
|
+
const slash = assetIdentifier2.indexOf("/");
|
|
107
|
+
const chainPart = slash === -1 ? "" : assetIdentifier2.slice(0, slash);
|
|
108
|
+
const assetPart = slash === -1 ? "" : assetIdentifier2.slice(slash + 1);
|
|
109
|
+
if (slash === -1 || chainPart === "" || assetPart === "") {
|
|
110
|
+
const looksLegacy = !assetIdentifier2.includes("/") && countChar(assetIdentifier2, ":") === 2;
|
|
111
|
+
const hint = looksLegacy ? " (this looks like the deprecated `<chain>:<ref>:<asset>` form; migrate it to `<chain>:<ref>/<asset-namespace>:<asset-reference>`)" : "";
|
|
112
|
+
throw new Error(`sender_auth: destination asset_identifier ${JSON.stringify(assetIdentifier2)} is not CAIP-19: expected <caip2-chain-id>/<asset-namespace>:<asset-reference>${hint}`);
|
|
113
|
+
}
|
|
114
|
+
const assetColon = assetPart.indexOf(":");
|
|
115
|
+
if (assetColon <= 0 || assetColon === assetPart.length - 1) {
|
|
116
|
+
throw new Error(`sender_auth: destination asset_identifier ${JSON.stringify(assetIdentifier2)} has a malformed asset part ${JSON.stringify(assetPart)}: expected <asset-namespace>:<asset-reference>`);
|
|
117
|
+
}
|
|
118
|
+
const assetNamespace = assetPart.slice(0, assetColon);
|
|
119
|
+
if (assetNamespace !== assetNamespace.toLowerCase()) {
|
|
120
|
+
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`);
|
|
121
|
+
}
|
|
122
|
+
const chainColon = chainPart.indexOf(":");
|
|
123
|
+
if (chainColon <= 0 || chainColon === chainPart.length - 1) {
|
|
124
|
+
throw new Error(`sender_auth: destination asset_identifier ${JSON.stringify(assetIdentifier2)} has a malformed chain part ${JSON.stringify(chainPart)}: expected <namespace>:<reference>`);
|
|
125
|
+
}
|
|
126
|
+
const namespace = chainPart.slice(0, chainColon);
|
|
127
|
+
if (namespace !== namespace.toLowerCase()) {
|
|
128
|
+
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`);
|
|
129
|
+
}
|
|
130
|
+
return namespace;
|
|
131
|
+
}
|
|
132
|
+
function countChar(s, c) {
|
|
133
|
+
let n = 0;
|
|
134
|
+
for (const ch of s) {
|
|
135
|
+
if (ch === c)
|
|
136
|
+
n++;
|
|
137
|
+
}
|
|
138
|
+
return n;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
// ../schemas/declarations/PaymentRequest/v1/bindings/typescript/sender-auth/dist/utils.js
|
|
144
|
+
var require_utils = __commonJS({
|
|
145
|
+
"../schemas/declarations/PaymentRequest/v1/bindings/typescript/sender-auth/dist/utils.js"(exports) {
|
|
146
|
+
"use strict";
|
|
147
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
148
|
+
exports.REQUEST_ID_DOMAIN = exports.SOLANA_REPLAY_BUCKETS = exports.SOLANA_REPLAY_SLOTS = exports.PERMIT_NONCE_DOMAIN = exports.REPLAY_HORIZON_SECS = void 0;
|
|
149
|
+
exports.resolvePermitDeadline = resolvePermitDeadline;
|
|
150
|
+
exports.generatePermitNonce = generatePermitNonce;
|
|
151
|
+
exports.resolvePermitNonce = resolvePermitNonce;
|
|
152
|
+
exports.canonicalDepositor = canonicalDepositor;
|
|
153
|
+
exports.deterministicPermitNonce = deterministicPermitNonce;
|
|
154
|
+
exports.deterministicSolanaNonce = deterministicSolanaNonce;
|
|
155
|
+
exports.deterministicRequestId = deterministicRequestId2;
|
|
156
|
+
exports.parseSourceAsset = parseSourceAsset;
|
|
157
|
+
exports.sameAddress = sameAddress2;
|
|
158
|
+
exports.assertKeyMatchesSender = assertKeyMatchesSender;
|
|
159
|
+
exports.assertToken = assertToken;
|
|
160
|
+
exports.assertAmountMatches = assertAmountMatches;
|
|
161
|
+
exports.assertFresh = assertFresh;
|
|
162
|
+
exports.assertSpender = assertSpender;
|
|
163
|
+
exports.assertWitnessRoles = assertWitnessRoles;
|
|
164
|
+
exports.assertRolePairComplete = assertRolePairComplete;
|
|
165
|
+
exports.assertDestination = assertDestination;
|
|
166
|
+
exports.assertDepositRequestHash = assertDepositRequestHash;
|
|
167
|
+
exports.nowSec = nowSec;
|
|
168
|
+
var ethers_1 = __require("ethers");
|
|
169
|
+
var destination_js_1 = require_destination();
|
|
170
|
+
exports.REPLAY_HORIZON_SECS = 128;
|
|
171
|
+
function resolvePermitDeadline(deadline) {
|
|
172
|
+
return BigInt(deadline);
|
|
173
|
+
}
|
|
174
|
+
function generatePermitNonce() {
|
|
175
|
+
const rand = new Uint32Array(1);
|
|
176
|
+
globalThis.crypto.getRandomValues(rand);
|
|
177
|
+
return (BigInt(Date.now()) << 32n) + BigInt(rand[0]);
|
|
178
|
+
}
|
|
179
|
+
function resolvePermitNonce(nonce) {
|
|
180
|
+
return BigInt(nonce);
|
|
181
|
+
}
|
|
182
|
+
exports.PERMIT_NONCE_DOMAIN = "atum-permit:v1:";
|
|
183
|
+
exports.SOLANA_REPLAY_SLOTS = 235n;
|
|
184
|
+
exports.SOLANA_REPLAY_BUCKETS = 256n;
|
|
185
|
+
function canonicalDepositor(depositor) {
|
|
186
|
+
const lower = depositor.toLowerCase();
|
|
187
|
+
return lower.startsWith("0x") ? lower : depositor;
|
|
188
|
+
}
|
|
189
|
+
function permitNonceSeed(requestId, depositor) {
|
|
190
|
+
if (!requestId) {
|
|
191
|
+
throw new Error("sender_auth: request_id is required to derive a deterministic permit nonce");
|
|
192
|
+
}
|
|
193
|
+
return BigInt((0, ethers_1.keccak256)((0, ethers_1.toUtf8Bytes)(`${exports.PERMIT_NONCE_DOMAIN}${requestId}:${canonicalDepositor(depositor)}`)));
|
|
194
|
+
}
|
|
195
|
+
function deterministicPermitNonce(params) {
|
|
196
|
+
return permitNonceSeed(params.requestId, params.depositor);
|
|
197
|
+
}
|
|
198
|
+
function deterministicSolanaNonce(params) {
|
|
199
|
+
const seed = permitNonceSeed(params.requestId, params.depositor);
|
|
200
|
+
const slot = seed % exports.SOLANA_REPLAY_SLOTS;
|
|
201
|
+
const bucket = (seed >> 8n) % exports.SOLANA_REPLAY_BUCKETS;
|
|
202
|
+
return bucket << 32n | slot;
|
|
203
|
+
}
|
|
204
|
+
exports.REQUEST_ID_DOMAIN = "atum-request:v1:";
|
|
205
|
+
function deterministicRequestId2(params) {
|
|
206
|
+
if (!params.anchor) {
|
|
207
|
+
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)");
|
|
208
|
+
}
|
|
209
|
+
if (!params.account) {
|
|
210
|
+
throw new Error("sender_auth: account is required to derive a deterministic request_id");
|
|
211
|
+
}
|
|
212
|
+
if (!/^[A-Za-z0-9_-]*$/.test(params.prefix)) {
|
|
213
|
+
throw new Error(`sender_auth: request_id prefix must contain only letters, digits, '_' or '-' (got ${JSON.stringify(params.prefix)})`);
|
|
214
|
+
}
|
|
215
|
+
const digest = (0, ethers_1.keccak256)((0, ethers_1.toUtf8Bytes)(`${exports.REQUEST_ID_DOMAIN}${params.anchor}:${canonicalDepositor(params.account)}`));
|
|
216
|
+
return `${params.prefix}${digest.slice(2, 26)}`;
|
|
217
|
+
}
|
|
218
|
+
function parseSourceAsset(assetIdentifier2) {
|
|
219
|
+
const parts = typeof assetIdentifier2 === "string" ? assetIdentifier2.split("/") : [];
|
|
220
|
+
const nsParts = parts[1]?.split(":");
|
|
221
|
+
if (parts.length === 3 && parts[0] && parts[1] && parts[2]) {
|
|
222
|
+
throw new Error(`sender_auth: source asset ${JSON.stringify(assetIdentifier2)} names a token id, which a deposit cannot bind`);
|
|
223
|
+
}
|
|
224
|
+
if (parts.length !== 2 || !parts[0] || !nsParts || nsParts.length !== 2 || !nsParts[0] || !nsParts[1]) {
|
|
225
|
+
throw new Error(`sender_auth: invalid source asset ${JSON.stringify(assetIdentifier2)}`);
|
|
226
|
+
}
|
|
227
|
+
return { network: parts[0], asset: nsParts[1] };
|
|
228
|
+
}
|
|
229
|
+
function sameAddress2(a, b) {
|
|
230
|
+
if (a.startsWith("0x") && b.startsWith("0x")) {
|
|
231
|
+
return a.toLowerCase() === b.toLowerCase();
|
|
232
|
+
}
|
|
233
|
+
return a === b;
|
|
234
|
+
}
|
|
235
|
+
function assertKeyMatchesSender(matches, sender, derived) {
|
|
236
|
+
if (!matches) {
|
|
237
|
+
throw new Error(`sender_auth: private key derives ${derived}, not the expected sender ${sender}`);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
function assertToken(token, sourceAsset, normalize) {
|
|
241
|
+
if (!sameAddress2(token, normalize(sourceAsset))) {
|
|
242
|
+
throw new Error("sender_auth: permit token does not match the source asset");
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
function assertAmountMatches(amount, maxSourceAmount) {
|
|
246
|
+
if (BigInt(amount) !== BigInt(maxSourceAmount)) {
|
|
247
|
+
throw new Error("sender_auth: permit amount does not match max_source_amount");
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
function assertFresh(deadlineSec, nowSec2) {
|
|
251
|
+
if (deadlineSec <= nowSec2) {
|
|
252
|
+
throw new Error("sender_auth: permit deadline is not in the future");
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
function assertSpender(spender, escrow, normalize) {
|
|
256
|
+
if (!sameAddress2(spender, normalize(escrow))) {
|
|
257
|
+
throw new Error("sender_auth: permit spender is not the source escrow");
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
function assertWitnessRoles(reserver, releaser, expectedReserver, expectedReleaser, normalize) {
|
|
261
|
+
if (!sameAddress2(reserver, normalize(expectedReserver)) || !sameAddress2(releaser, normalize(expectedReleaser))) {
|
|
262
|
+
throw new Error("sender_auth: deposit witness roles do not match the challenge");
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
function assertRolePairComplete(reserver, releaser) {
|
|
266
|
+
if (reserver === void 0 !== (releaser === void 0)) {
|
|
267
|
+
throw new Error("sender_auth: reserver and releaser must be supplied together");
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
function assertDestination(signed, expected) {
|
|
271
|
+
if (signed !== expected) {
|
|
272
|
+
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`);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
function assertDepositRequestHash(signedHex, expectedRequestId) {
|
|
276
|
+
const expected = (0, destination_js_1.deriveDepositRequestHash)(expectedRequestId);
|
|
277
|
+
if (signedHex.toLowerCase() !== expected.toLowerCase()) {
|
|
278
|
+
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`);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
function nowSec() {
|
|
282
|
+
return Math.floor(Date.now() / 1e3);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
// ../schemas/declarations/PaymentRequest/v1/bindings/typescript/sender-auth/dist/chain-id.js
|
|
288
|
+
var require_chain_id = __commonJS({
|
|
289
|
+
"../schemas/declarations/PaymentRequest/v1/bindings/typescript/sender-auth/dist/chain-id.js"(exports) {
|
|
290
|
+
"use strict";
|
|
291
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
292
|
+
exports.TRON_PERMIT2_FALLBACKS = exports.TRON_CHAIN_IDS = exports.MAX_EVM_CHAIN_ID = void 0;
|
|
293
|
+
exports.namespaceOf = namespaceOf2;
|
|
294
|
+
exports.evmChainId = evmChainId;
|
|
295
|
+
exports.tronNumericChainId = tronNumericChainId;
|
|
296
|
+
exports.resolveTronPermit2 = resolveTronPermit22;
|
|
297
|
+
exports.clusterIdFromName = clusterIdFromName;
|
|
298
|
+
function namespaceOf2(network) {
|
|
299
|
+
return network.split(":")[0];
|
|
300
|
+
}
|
|
301
|
+
exports.MAX_EVM_CHAIN_ID = Number.MAX_SAFE_INTEGER;
|
|
302
|
+
function evmChainId(network) {
|
|
303
|
+
const match = /^eip155:([0-9]+)$/.exec(network);
|
|
304
|
+
if (!match) {
|
|
305
|
+
throw new Error(`sender_auth: expected an eip155 network, got ${network}`);
|
|
306
|
+
}
|
|
307
|
+
const chainId = Number(match[1]);
|
|
308
|
+
if (chainId > exports.MAX_EVM_CHAIN_ID) {
|
|
309
|
+
throw new Error(`sender_auth: eip155 chain id ${match[1]} exceeds the EIP-2294 maximum (${exports.MAX_EVM_CHAIN_ID})`);
|
|
310
|
+
}
|
|
311
|
+
return chainId;
|
|
312
|
+
}
|
|
313
|
+
exports.TRON_CHAIN_IDS = {
|
|
314
|
+
mainnet: 728126428,
|
|
315
|
+
shasta: 2494104990
|
|
316
|
+
};
|
|
317
|
+
function tronNumericChainId(network) {
|
|
318
|
+
if (namespaceOf2(network) !== "tron") {
|
|
319
|
+
throw new Error(`sender_auth: expected a tron network, got ${network}`);
|
|
320
|
+
}
|
|
321
|
+
const segments = network.split(":");
|
|
322
|
+
const cluster = segments.length === 2 ? segments[1] : void 0;
|
|
323
|
+
const id = cluster !== void 0 && Object.hasOwn(exports.TRON_CHAIN_IDS, cluster) ? exports.TRON_CHAIN_IDS[cluster] : void 0;
|
|
324
|
+
if (typeof id !== "number") {
|
|
325
|
+
throw new Error(`sender_auth: unsupported Tron network '${network}'`);
|
|
326
|
+
}
|
|
327
|
+
return id;
|
|
328
|
+
}
|
|
329
|
+
exports.TRON_PERMIT2_FALLBACKS = {
|
|
330
|
+
"tron:mainnet": "TJhMXTHQHeQyMD7TcKQFqAePNgG4b31H9m",
|
|
331
|
+
"tron:shasta": "TPUqJPASUn1zLvbLBgRZ5pBYrx7WSe5ahp"
|
|
332
|
+
};
|
|
333
|
+
function resolveTronPermit22(network) {
|
|
334
|
+
const resolved = Object.hasOwn(exports.TRON_PERMIT2_FALLBACKS, network) ? exports.TRON_PERMIT2_FALLBACKS[network] : void 0;
|
|
335
|
+
if (typeof resolved !== "string" || resolved === "") {
|
|
336
|
+
throw new Error(`sender_auth: no Permit2 address known for Tron network '${network}'`);
|
|
337
|
+
}
|
|
338
|
+
return resolved;
|
|
339
|
+
}
|
|
340
|
+
function clusterIdFromName(name) {
|
|
341
|
+
const encoded = new TextEncoder().encode(name);
|
|
342
|
+
if (encoded.length > 32) {
|
|
343
|
+
throw new Error(`sender_auth: Solana cluster name too long (${encoded.length} > 32 bytes): ${name}`);
|
|
344
|
+
}
|
|
345
|
+
const out = new Uint8Array(32);
|
|
346
|
+
out.set(encoded);
|
|
347
|
+
return out;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
|
|
42
352
|
// ../contracts/evm/escrow-encoding/typescript/dist/payment-id.js
|
|
43
353
|
var require_payment_id = __commonJS({
|
|
44
354
|
"../contracts/evm/escrow-encoding/typescript/dist/payment-id.js"(exports) {
|
|
@@ -78,7 +388,7 @@ var require_permit_types = __commonJS({
|
|
|
78
388
|
"../contracts/evm/escrow-encoding/typescript/dist/permit-types.js"(exports) {
|
|
79
389
|
"use strict";
|
|
80
390
|
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;
|
|
391
|
+
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
392
|
exports.createPermit2Domain = createPermit2Domain;
|
|
83
393
|
exports.createEscrowDomain = createEscrowDomain;
|
|
84
394
|
exports.PERMIT_WITNESS_TYPES = {
|
|
@@ -161,6 +471,63 @@ var require_permit_types = __commonJS({
|
|
|
161
471
|
{ name: "settler", type: "address" }
|
|
162
472
|
]
|
|
163
473
|
};
|
|
474
|
+
exports.PERMIT_WITNESS_TYPES_WITH_DESTINATION = {
|
|
475
|
+
PermitWitnessTransferFrom: [
|
|
476
|
+
{ name: "permitted", type: "TokenPermissions" },
|
|
477
|
+
{ name: "spender", type: "address" },
|
|
478
|
+
{ name: "nonce", type: "uint256" },
|
|
479
|
+
{ name: "deadline", type: "uint256" },
|
|
480
|
+
{ name: "witness", type: "DepositWitness" }
|
|
481
|
+
],
|
|
482
|
+
TokenPermissions: [
|
|
483
|
+
{ name: "token", type: "address" },
|
|
484
|
+
{ name: "amount", type: "uint256" }
|
|
485
|
+
],
|
|
486
|
+
DepositWitness: [
|
|
487
|
+
{ name: "depositRequestHash", type: "bytes32" },
|
|
488
|
+
{ name: "destination", type: "string" },
|
|
489
|
+
{ name: "reserver", type: "address" },
|
|
490
|
+
{ name: "releaser", type: "address" }
|
|
491
|
+
]
|
|
492
|
+
};
|
|
493
|
+
exports.RESERVE_WITNESS_TYPES_WITH_QUOTE_SOURCE = {
|
|
494
|
+
ReserveWitness: [
|
|
495
|
+
{ name: "depositId", type: "bytes32" },
|
|
496
|
+
{ name: "quoteHash", type: "bytes32" },
|
|
497
|
+
{ name: "settler", type: "address" },
|
|
498
|
+
{ name: "sourceAmount", type: "uint256" }
|
|
499
|
+
]
|
|
500
|
+
};
|
|
501
|
+
exports.RELEASE_WITNESS_TYPES_WITH_QUOTE_HASH = {
|
|
502
|
+
ReleaseWitness: [
|
|
503
|
+
{ name: "depositId", type: "bytes32" },
|
|
504
|
+
{ name: "quoteHash", type: "bytes32" },
|
|
505
|
+
{ name: "depositRequestHash", type: "bytes32" },
|
|
506
|
+
{ name: "destinationHash", type: "bytes32" },
|
|
507
|
+
{ name: "depositor", type: "address" },
|
|
508
|
+
{ name: "token", type: "address" },
|
|
509
|
+
{ name: "amount", type: "uint256" },
|
|
510
|
+
{ name: "feeAmount", type: "uint256" },
|
|
511
|
+
{ name: "reserver", type: "address" },
|
|
512
|
+
{ name: "releaser", type: "address" },
|
|
513
|
+
{ name: "settler", type: "address" }
|
|
514
|
+
]
|
|
515
|
+
};
|
|
516
|
+
exports.REFUND_WITNESS_TYPES_WITH_QUOTE_HASH = {
|
|
517
|
+
RefundWitness: [
|
|
518
|
+
{ name: "depositId", type: "bytes32" },
|
|
519
|
+
{ name: "quoteHash", type: "bytes32" },
|
|
520
|
+
{ name: "depositRequestHash", type: "bytes32" },
|
|
521
|
+
{ name: "destinationHash", type: "bytes32" },
|
|
522
|
+
{ name: "depositor", type: "address" },
|
|
523
|
+
{ name: "token", type: "address" },
|
|
524
|
+
{ name: "amount", type: "uint256" },
|
|
525
|
+
{ name: "feeAmount", type: "uint256" },
|
|
526
|
+
{ name: "reserver", type: "address" },
|
|
527
|
+
{ name: "releaser", type: "address" },
|
|
528
|
+
{ name: "settler", type: "address" }
|
|
529
|
+
]
|
|
530
|
+
};
|
|
164
531
|
}
|
|
165
532
|
});
|
|
166
533
|
|
|
@@ -287,6 +654,8 @@ var require_escrow_abi = __commonJS({
|
|
|
287
654
|
name: "depositWitness",
|
|
288
655
|
type: "tuple",
|
|
289
656
|
components: [
|
|
657
|
+
{ name: "depositRequestHash", type: "bytes32" },
|
|
658
|
+
{ name: "destination", type: "string" },
|
|
290
659
|
{ name: "reserver", type: "address" },
|
|
291
660
|
{ name: "releaser", type: "address" }
|
|
292
661
|
]
|
|
@@ -296,15 +665,17 @@ var require_escrow_abi = __commonJS({
|
|
|
296
665
|
name: "reserveWitness",
|
|
297
666
|
type: "tuple",
|
|
298
667
|
components: [
|
|
299
|
-
{ name: "
|
|
300
|
-
{ name: "
|
|
668
|
+
{ name: "depositId", type: "bytes32" },
|
|
669
|
+
{ name: "quoteHash", type: "bytes32" },
|
|
670
|
+
{ name: "settler", type: "address" },
|
|
671
|
+
{ name: "sourceAmount", type: "uint256" }
|
|
301
672
|
]
|
|
302
673
|
},
|
|
303
674
|
{ name: "reserveSignature", type: "bytes" }
|
|
304
675
|
]
|
|
305
676
|
}
|
|
306
677
|
],
|
|
307
|
-
outputs: [{ name: "
|
|
678
|
+
outputs: [{ name: "depositId", type: "bytes32" }],
|
|
308
679
|
stateMutability: "nonpayable"
|
|
309
680
|
},
|
|
310
681
|
{
|
|
@@ -319,7 +690,10 @@ var require_escrow_abi = __commonJS({
|
|
|
319
690
|
name: "refundWitness",
|
|
320
691
|
type: "tuple",
|
|
321
692
|
components: [
|
|
322
|
-
{ name: "
|
|
693
|
+
{ name: "depositId", type: "bytes32" },
|
|
694
|
+
{ name: "quoteHash", type: "bytes32" },
|
|
695
|
+
{ name: "depositRequestHash", type: "bytes32" },
|
|
696
|
+
{ name: "destinationHash", type: "bytes32" },
|
|
323
697
|
{ name: "depositor", type: "address" },
|
|
324
698
|
{ name: "token", type: "address" },
|
|
325
699
|
{ name: "amount", type: "uint256" },
|
|
@@ -339,7 +713,7 @@ var require_escrow_abi = __commonJS({
|
|
|
339
713
|
{
|
|
340
714
|
type: "function",
|
|
341
715
|
name: "getDepositHash",
|
|
342
|
-
inputs: [{ name: "
|
|
716
|
+
inputs: [{ name: "depositId", type: "bytes32" }],
|
|
343
717
|
outputs: [{ name: "", type: "bytes32" }],
|
|
344
718
|
stateMutability: "view"
|
|
345
719
|
},
|
|
@@ -355,14 +729,67 @@ var require_escrow_abi = __commonJS({
|
|
|
355
729
|
}
|
|
356
730
|
});
|
|
357
731
|
|
|
358
|
-
// ../contracts/evm/escrow-encoding/typescript/dist/
|
|
359
|
-
var
|
|
732
|
+
// ../contracts/evm/escrow-encoding/typescript/dist/witness-values.js
|
|
733
|
+
var require_witness_values = __commonJS({
|
|
734
|
+
"../contracts/evm/escrow-encoding/typescript/dist/witness-values.js"(exports) {
|
|
735
|
+
"use strict";
|
|
736
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
737
|
+
exports.normalizeBytes32 = normalizeBytes32;
|
|
738
|
+
exports.normalizeAddressField = normalizeAddressField;
|
|
739
|
+
exports.normalizeUint256 = normalizeUint256;
|
|
740
|
+
exports.chainIdToHex = chainIdToHex;
|
|
741
|
+
var ethers_1 = __require("ethers");
|
|
742
|
+
function normalizeBytes32(label, value) {
|
|
743
|
+
let bytes;
|
|
744
|
+
try {
|
|
745
|
+
bytes = (0, ethers_1.getBytes)(value);
|
|
746
|
+
} catch {
|
|
747
|
+
throw new Error(`${label} must be 0x-prefixed hex (32 bytes), got ${JSON.stringify(value)}`);
|
|
748
|
+
}
|
|
749
|
+
if (bytes.length !== 32) {
|
|
750
|
+
throw new Error(`${label} must be exactly 32 bytes, got ${bytes.length}`);
|
|
751
|
+
}
|
|
752
|
+
return (0, ethers_1.hexlify)(bytes);
|
|
753
|
+
}
|
|
754
|
+
function normalizeAddressField(label, value) {
|
|
755
|
+
try {
|
|
756
|
+
return (0, ethers_1.getAddress)(value);
|
|
757
|
+
} catch {
|
|
758
|
+
throw new Error(`${label} must be a 20-byte hex address, got ${JSON.stringify(value)}`);
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
function normalizeUint256(label, value) {
|
|
762
|
+
let n;
|
|
763
|
+
try {
|
|
764
|
+
n = BigInt(value);
|
|
765
|
+
} catch {
|
|
766
|
+
throw new Error(`${label} must be an integer (bigint or decimal string), got ${JSON.stringify(value)}`);
|
|
767
|
+
}
|
|
768
|
+
if (n < 0n) {
|
|
769
|
+
throw new Error(`${label} must be non-negative (uint256), got ${n.toString()}`);
|
|
770
|
+
}
|
|
771
|
+
return n.toString();
|
|
772
|
+
}
|
|
773
|
+
function chainIdToHex(chainId) {
|
|
774
|
+
if (!Number.isSafeInteger(chainId) || chainId < 0) {
|
|
775
|
+
throw new Error(`chainId must be a non-negative safe integer, got ${chainId}`);
|
|
776
|
+
}
|
|
777
|
+
return `0x${chainId.toString(16)}`;
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
});
|
|
781
|
+
|
|
782
|
+
// ../contracts/evm/escrow-encoding/typescript/dist/reserve-encoder.js
|
|
783
|
+
var require_reserve_encoder = __commonJS({
|
|
360
784
|
"../contracts/evm/escrow-encoding/typescript/dist/reserve-encoder.js"(exports) {
|
|
361
785
|
"use strict";
|
|
362
786
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
363
787
|
exports.computeReserveDigest = computeReserveDigest;
|
|
788
|
+
exports.buildReserveTypedDataWithQuoteSource = buildReserveTypedDataWithQuoteSource;
|
|
789
|
+
exports.computeReserveDigestWithQuoteSource = computeReserveDigestWithQuoteSource;
|
|
364
790
|
var ethers_1 = __require("ethers");
|
|
365
791
|
var permit_types_1 = require_permit_types();
|
|
792
|
+
var witness_values_1 = require_witness_values();
|
|
366
793
|
function computeReserveDigest(input) {
|
|
367
794
|
const domain = (0, permit_types_1.createEscrowDomain)(input.chainId, input.escrowContract);
|
|
368
795
|
return ethers_1.TypedDataEncoder.hash(domain, permit_types_1.RESERVE_WITNESS_TYPES, {
|
|
@@ -370,6 +797,114 @@ var require_reserve_encoder = __commonJS({
|
|
|
370
797
|
settler: input.settler
|
|
371
798
|
});
|
|
372
799
|
}
|
|
800
|
+
function buildReserveTypedDataWithQuoteSource(input) {
|
|
801
|
+
return {
|
|
802
|
+
types: permit_types_1.RESERVE_WITNESS_TYPES_WITH_QUOTE_SOURCE,
|
|
803
|
+
primaryType: "ReserveWitness",
|
|
804
|
+
domain: {
|
|
805
|
+
name: "Escrow",
|
|
806
|
+
version: "3",
|
|
807
|
+
chainId: (0, witness_values_1.chainIdToHex)(input.chainId),
|
|
808
|
+
verifyingContract: (0, witness_values_1.normalizeAddressField)("escrowContract", input.escrowContract)
|
|
809
|
+
},
|
|
810
|
+
message: {
|
|
811
|
+
depositId: (0, witness_values_1.normalizeBytes32)("depositId", input.depositId),
|
|
812
|
+
quoteHash: (0, witness_values_1.normalizeBytes32)("quoteHash", input.quoteHash),
|
|
813
|
+
settler: (0, witness_values_1.normalizeAddressField)("settler", input.settler),
|
|
814
|
+
sourceAmount: (0, witness_values_1.normalizeUint256)("sourceAmount", input.sourceAmount)
|
|
815
|
+
}
|
|
816
|
+
};
|
|
817
|
+
}
|
|
818
|
+
function computeReserveDigestWithQuoteSource(input) {
|
|
819
|
+
const prehash = buildReserveTypedDataWithQuoteSource(input);
|
|
820
|
+
return ethers_1.TypedDataEncoder.hash(prehash.domain, prehash.types, prehash.message);
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
});
|
|
824
|
+
|
|
825
|
+
// ../contracts/evm/escrow-encoding/typescript/dist/release-encoder.js
|
|
826
|
+
var require_release_encoder = __commonJS({
|
|
827
|
+
"../contracts/evm/escrow-encoding/typescript/dist/release-encoder.js"(exports) {
|
|
828
|
+
"use strict";
|
|
829
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
830
|
+
exports.buildReleaseTypedDataWithQuoteHash = buildReleaseTypedDataWithQuoteHash;
|
|
831
|
+
exports.computeReleaseDigestWithQuoteHash = computeReleaseDigestWithQuoteHash;
|
|
832
|
+
var ethers_1 = __require("ethers");
|
|
833
|
+
var permit_types_1 = require_permit_types();
|
|
834
|
+
var witness_values_1 = require_witness_values();
|
|
835
|
+
function buildReleaseTypedDataWithQuoteHash(input) {
|
|
836
|
+
const w = input.witness;
|
|
837
|
+
return {
|
|
838
|
+
types: permit_types_1.RELEASE_WITNESS_TYPES_WITH_QUOTE_HASH,
|
|
839
|
+
primaryType: "ReleaseWitness",
|
|
840
|
+
domain: {
|
|
841
|
+
name: "Escrow",
|
|
842
|
+
version: "3",
|
|
843
|
+
chainId: (0, witness_values_1.chainIdToHex)(input.chainId),
|
|
844
|
+
verifyingContract: (0, witness_values_1.normalizeAddressField)("escrowContract", input.escrowContract)
|
|
845
|
+
},
|
|
846
|
+
message: {
|
|
847
|
+
depositId: (0, witness_values_1.normalizeBytes32)("depositId", w.depositId),
|
|
848
|
+
quoteHash: (0, witness_values_1.normalizeBytes32)("quoteHash", w.quoteHash),
|
|
849
|
+
depositRequestHash: (0, witness_values_1.normalizeBytes32)("depositRequestHash", w.depositRequestHash),
|
|
850
|
+
destinationHash: (0, witness_values_1.normalizeBytes32)("destinationHash", w.destinationHash),
|
|
851
|
+
depositor: (0, witness_values_1.normalizeAddressField)("depositor", w.depositor),
|
|
852
|
+
token: (0, witness_values_1.normalizeAddressField)("token", w.token),
|
|
853
|
+
amount: (0, witness_values_1.normalizeUint256)("amount", w.amount),
|
|
854
|
+
feeAmount: (0, witness_values_1.normalizeUint256)("feeAmount", w.feeAmount),
|
|
855
|
+
reserver: (0, witness_values_1.normalizeAddressField)("reserver", w.reserver),
|
|
856
|
+
releaser: (0, witness_values_1.normalizeAddressField)("releaser", w.releaser),
|
|
857
|
+
settler: (0, witness_values_1.normalizeAddressField)("settler", w.settler)
|
|
858
|
+
}
|
|
859
|
+
};
|
|
860
|
+
}
|
|
861
|
+
function computeReleaseDigestWithQuoteHash(input) {
|
|
862
|
+
const prehash = buildReleaseTypedDataWithQuoteHash(input);
|
|
863
|
+
return ethers_1.TypedDataEncoder.hash(prehash.domain, prehash.types, prehash.message);
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
});
|
|
867
|
+
|
|
868
|
+
// ../contracts/evm/escrow-encoding/typescript/dist/refund-encoder.js
|
|
869
|
+
var require_refund_encoder = __commonJS({
|
|
870
|
+
"../contracts/evm/escrow-encoding/typescript/dist/refund-encoder.js"(exports) {
|
|
871
|
+
"use strict";
|
|
872
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
873
|
+
exports.buildRefundTypedDataWithQuoteHash = buildRefundTypedDataWithQuoteHash;
|
|
874
|
+
exports.computeRefundDigestWithQuoteHash = computeRefundDigestWithQuoteHash;
|
|
875
|
+
var ethers_1 = __require("ethers");
|
|
876
|
+
var permit_types_1 = require_permit_types();
|
|
877
|
+
var witness_values_1 = require_witness_values();
|
|
878
|
+
function buildRefundTypedDataWithQuoteHash(input) {
|
|
879
|
+
const w = input.witness;
|
|
880
|
+
return {
|
|
881
|
+
types: permit_types_1.REFUND_WITNESS_TYPES_WITH_QUOTE_HASH,
|
|
882
|
+
primaryType: "RefundWitness",
|
|
883
|
+
domain: {
|
|
884
|
+
name: "Escrow",
|
|
885
|
+
version: "3",
|
|
886
|
+
chainId: (0, witness_values_1.chainIdToHex)(input.chainId),
|
|
887
|
+
verifyingContract: (0, witness_values_1.normalizeAddressField)("escrowContract", input.escrowContract)
|
|
888
|
+
},
|
|
889
|
+
message: {
|
|
890
|
+
depositId: (0, witness_values_1.normalizeBytes32)("depositId", w.depositId),
|
|
891
|
+
quoteHash: (0, witness_values_1.normalizeBytes32)("quoteHash", w.quoteHash),
|
|
892
|
+
depositRequestHash: (0, witness_values_1.normalizeBytes32)("depositRequestHash", w.depositRequestHash),
|
|
893
|
+
destinationHash: (0, witness_values_1.normalizeBytes32)("destinationHash", w.destinationHash),
|
|
894
|
+
depositor: (0, witness_values_1.normalizeAddressField)("depositor", w.depositor),
|
|
895
|
+
token: (0, witness_values_1.normalizeAddressField)("token", w.token),
|
|
896
|
+
amount: (0, witness_values_1.normalizeUint256)("amount", w.amount),
|
|
897
|
+
feeAmount: (0, witness_values_1.normalizeUint256)("feeAmount", w.feeAmount),
|
|
898
|
+
reserver: (0, witness_values_1.normalizeAddressField)("reserver", w.reserver),
|
|
899
|
+
releaser: (0, witness_values_1.normalizeAddressField)("releaser", w.releaser),
|
|
900
|
+
settler: (0, witness_values_1.normalizeAddressField)("settler", w.settler)
|
|
901
|
+
}
|
|
902
|
+
};
|
|
903
|
+
}
|
|
904
|
+
function computeRefundDigestWithQuoteHash(input) {
|
|
905
|
+
const prehash = buildRefundTypedDataWithQuoteHash(input);
|
|
906
|
+
return ethers_1.TypedDataEncoder.hash(prehash.domain, prehash.types, prehash.message);
|
|
907
|
+
}
|
|
373
908
|
}
|
|
374
909
|
});
|
|
375
910
|
|
|
@@ -378,11 +913,13 @@ var require_deposit_encoder = __commonJS({
|
|
|
378
913
|
"../contracts/evm/escrow-encoding/typescript/dist/deposit-encoder.js"(exports) {
|
|
379
914
|
"use strict";
|
|
380
915
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
381
|
-
exports.PERMIT2_CONTRACT_ADDRESS = void 0;
|
|
916
|
+
exports.MAX_DESTINATION_BYTES = exports.PERMIT2_CONTRACT_ADDRESS = void 0;
|
|
382
917
|
exports.createPermitWitnessTransferFromPrehash = createPermitWitnessTransferFromPrehash;
|
|
383
918
|
exports.hashPermitWitnessTransferFrom = hashPermitWitnessTransferFrom;
|
|
919
|
+
exports.createPermitWitnessTransferFromPrehashWithDestination = createPermitWitnessTransferFromPrehashWithDestination;
|
|
384
920
|
var ethers_1 = __require("ethers");
|
|
385
921
|
var permit_types_1 = require_permit_types();
|
|
922
|
+
var witness_values_1 = require_witness_values();
|
|
386
923
|
exports.PERMIT2_CONTRACT_ADDRESS = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
|
|
387
924
|
function createPermitWitnessTransferFromPrehash(params) {
|
|
388
925
|
return {
|
|
@@ -411,6 +948,43 @@ var require_deposit_encoder = __commonJS({
|
|
|
411
948
|
function hashPermitWitnessTransferFrom(prehash) {
|
|
412
949
|
return ethers_1.TypedDataEncoder.hash(prehash.domain, prehash.types, prehash.message);
|
|
413
950
|
}
|
|
951
|
+
exports.MAX_DESTINATION_BYTES = 256;
|
|
952
|
+
function assertDestinationWithinBounds(destination) {
|
|
953
|
+
if (destination === "") {
|
|
954
|
+
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');
|
|
955
|
+
}
|
|
956
|
+
const byteLength = (0, ethers_1.toUtf8Bytes)(destination).length;
|
|
957
|
+
if (byteLength > exports.MAX_DESTINATION_BYTES) {
|
|
958
|
+
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`);
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
function createPermitWitnessTransferFromPrehashWithDestination(params) {
|
|
962
|
+
assertDestinationWithinBounds(params.destination);
|
|
963
|
+
return {
|
|
964
|
+
types: permit_types_1.PERMIT_WITNESS_TYPES_WITH_DESTINATION,
|
|
965
|
+
primaryType: "PermitWitnessTransferFrom",
|
|
966
|
+
domain: {
|
|
967
|
+
name: "Permit2",
|
|
968
|
+
chainId: (0, witness_values_1.chainIdToHex)(params.chainId),
|
|
969
|
+
verifyingContract: (0, witness_values_1.normalizeAddressField)("verifyingContract", params.verifyingContract)
|
|
970
|
+
},
|
|
971
|
+
message: {
|
|
972
|
+
permitted: {
|
|
973
|
+
token: (0, witness_values_1.normalizeAddressField)("token", params.token),
|
|
974
|
+
amount: (0, witness_values_1.normalizeUint256)("amount", params.amount)
|
|
975
|
+
},
|
|
976
|
+
spender: (0, witness_values_1.normalizeAddressField)("spender", params.spender),
|
|
977
|
+
nonce: (0, witness_values_1.normalizeUint256)("nonce", params.nonce),
|
|
978
|
+
deadline: (0, witness_values_1.normalizeUint256)("deadline", params.deadline),
|
|
979
|
+
witness: {
|
|
980
|
+
depositRequestHash: (0, witness_values_1.normalizeBytes32)("depositRequestHash", params.depositRequestHash),
|
|
981
|
+
destination: params.destination,
|
|
982
|
+
reserver: (0, witness_values_1.normalizeAddressField)("reserver", params.reserver),
|
|
983
|
+
releaser: (0, witness_values_1.normalizeAddressField)("releaser", params.releaser)
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
};
|
|
987
|
+
}
|
|
414
988
|
}
|
|
415
989
|
});
|
|
416
990
|
|
|
@@ -419,7 +993,7 @@ var require_dist = __commonJS({
|
|
|
419
993
|
"../contracts/evm/escrow-encoding/typescript/dist/index.js"(exports) {
|
|
420
994
|
"use strict";
|
|
421
995
|
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;
|
|
996
|
+
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
997
|
var payment_id_1 = require_payment_id();
|
|
424
998
|
Object.defineProperty(exports, "computePaymentId", { enumerable: true, get: function() {
|
|
425
999
|
return payment_id_1.computePaymentId;
|
|
@@ -453,6 +1027,19 @@ var require_dist = __commonJS({
|
|
|
453
1027
|
Object.defineProperty(exports, "REFUND_WITNESS_TYPES", { enumerable: true, get: function() {
|
|
454
1028
|
return permit_types_1.REFUND_WITNESS_TYPES;
|
|
455
1029
|
} });
|
|
1030
|
+
var permit_types_2 = require_permit_types();
|
|
1031
|
+
Object.defineProperty(exports, "PERMIT_WITNESS_TYPES_WITH_DESTINATION", { enumerable: true, get: function() {
|
|
1032
|
+
return permit_types_2.PERMIT_WITNESS_TYPES_WITH_DESTINATION;
|
|
1033
|
+
} });
|
|
1034
|
+
Object.defineProperty(exports, "RESERVE_WITNESS_TYPES_WITH_QUOTE_SOURCE", { enumerable: true, get: function() {
|
|
1035
|
+
return permit_types_2.RESERVE_WITNESS_TYPES_WITH_QUOTE_SOURCE;
|
|
1036
|
+
} });
|
|
1037
|
+
Object.defineProperty(exports, "RELEASE_WITNESS_TYPES_WITH_QUOTE_HASH", { enumerable: true, get: function() {
|
|
1038
|
+
return permit_types_2.RELEASE_WITNESS_TYPES_WITH_QUOTE_HASH;
|
|
1039
|
+
} });
|
|
1040
|
+
Object.defineProperty(exports, "REFUND_WITNESS_TYPES_WITH_QUOTE_HASH", { enumerable: true, get: function() {
|
|
1041
|
+
return permit_types_2.REFUND_WITNESS_TYPES_WITH_QUOTE_HASH;
|
|
1042
|
+
} });
|
|
456
1043
|
var escrow_abi_1 = require_escrow_abi();
|
|
457
1044
|
Object.defineProperty(exports, "ESCROW_ABI", { enumerable: true, get: function() {
|
|
458
1045
|
return escrow_abi_1.ESCROW_ABI;
|
|
@@ -469,199 +1056,45 @@ var require_dist = __commonJS({
|
|
|
469
1056
|
var reserve_encoder_1 = require_reserve_encoder();
|
|
470
1057
|
Object.defineProperty(exports, "computeReserveDigest", { enumerable: true, get: function() {
|
|
471
1058
|
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.assertFresh = assertFresh;
|
|
512
|
-
exports.assertSpender = assertSpender;
|
|
513
|
-
exports.assertWitnessRoles = assertWitnessRoles;
|
|
514
|
-
exports.assertRolePairComplete = assertRolePairComplete;
|
|
515
|
-
exports.nowSec = nowSec;
|
|
516
|
-
var ethers_1 = __require("ethers");
|
|
517
|
-
exports.REPLAY_HORIZON_SECS = 128;
|
|
518
|
-
function resolvePermitDeadline(deadline) {
|
|
519
|
-
return BigInt(deadline);
|
|
520
|
-
}
|
|
521
|
-
function generatePermitNonce() {
|
|
522
|
-
const rand = new Uint32Array(1);
|
|
523
|
-
globalThis.crypto.getRandomValues(rand);
|
|
524
|
-
return (BigInt(Date.now()) << 32n) + BigInt(rand[0]);
|
|
525
|
-
}
|
|
526
|
-
function resolvePermitNonce(nonce) {
|
|
527
|
-
return BigInt(nonce);
|
|
528
|
-
}
|
|
529
|
-
exports.PERMIT_NONCE_DOMAIN = "atum-permit:v1:";
|
|
530
|
-
exports.SOLANA_REPLAY_SLOTS = 235n;
|
|
531
|
-
var SOLANA_BUCKET_BITS = 17n;
|
|
532
|
-
function canonicalDepositor(depositor) {
|
|
533
|
-
const lower = depositor.toLowerCase();
|
|
534
|
-
return lower.startsWith("0x") ? lower : depositor;
|
|
535
|
-
}
|
|
536
|
-
function permitNonceSeed(requestId, depositor) {
|
|
537
|
-
if (!requestId) {
|
|
538
|
-
throw new Error("sender_auth: request_id is required to derive a deterministic permit nonce");
|
|
539
|
-
}
|
|
540
|
-
return BigInt((0, ethers_1.keccak256)((0, ethers_1.toUtf8Bytes)(`${exports.PERMIT_NONCE_DOMAIN}${requestId}:${canonicalDepositor(depositor)}`)));
|
|
541
|
-
}
|
|
542
|
-
function deterministicPermitNonce(params) {
|
|
543
|
-
return permitNonceSeed(params.requestId, params.depositor);
|
|
544
|
-
}
|
|
545
|
-
function deterministicSolanaNonce(params) {
|
|
546
|
-
const seed = permitNonceSeed(params.requestId, params.depositor);
|
|
547
|
-
const slot = seed % exports.SOLANA_REPLAY_SLOTS;
|
|
548
|
-
const bucket = (seed >> 8n) % (1n << SOLANA_BUCKET_BITS);
|
|
549
|
-
return bucket << 32n | slot;
|
|
550
|
-
}
|
|
551
|
-
exports.REQUEST_ID_DOMAIN = "atum-request:v1:";
|
|
552
|
-
function deterministicRequestId2(params) {
|
|
553
|
-
if (!params.anchor) {
|
|
554
|
-
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)");
|
|
555
|
-
}
|
|
556
|
-
if (!params.account) {
|
|
557
|
-
throw new Error("sender_auth: account is required to derive a deterministic request_id");
|
|
558
|
-
}
|
|
559
|
-
if (!/^[A-Za-z0-9_-]*$/.test(params.prefix)) {
|
|
560
|
-
throw new Error(`sender_auth: request_id prefix must contain only letters, digits, '_' or '-' (got ${JSON.stringify(params.prefix)})`);
|
|
561
|
-
}
|
|
562
|
-
const digest = (0, ethers_1.keccak256)((0, ethers_1.toUtf8Bytes)(`${exports.REQUEST_ID_DOMAIN}${params.anchor}:${canonicalDepositor(params.account)}`));
|
|
563
|
-
return `${params.prefix}${digest.slice(2, 26)}`;
|
|
564
|
-
}
|
|
565
|
-
function sameAddress2(a, b) {
|
|
566
|
-
if (a.startsWith("0x") && b.startsWith("0x")) {
|
|
567
|
-
return a.toLowerCase() === b.toLowerCase();
|
|
568
|
-
}
|
|
569
|
-
return a === b;
|
|
570
|
-
}
|
|
571
|
-
function assertKeyMatchesSender(matches, sender, derived) {
|
|
572
|
-
if (!matches) {
|
|
573
|
-
throw new Error(`sender_auth: private key derives ${derived}, not the expected sender ${sender}`);
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
function assertToken(token, sourceAsset, normalize) {
|
|
577
|
-
if (!sameAddress2(token, normalize(sourceAsset))) {
|
|
578
|
-
throw new Error("sender_auth: permit token does not match the source asset");
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
function assertAmountMatches(amount, maxSourceAmount) {
|
|
582
|
-
if (BigInt(amount) !== BigInt(maxSourceAmount)) {
|
|
583
|
-
throw new Error("sender_auth: permit amount does not match max_source_amount");
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
function assertFresh(deadlineSec, nowSec2) {
|
|
587
|
-
if (deadlineSec <= nowSec2) {
|
|
588
|
-
throw new Error("sender_auth: permit deadline is not in the future");
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
function assertSpender(spender, escrow, normalize) {
|
|
592
|
-
if (!sameAddress2(spender, normalize(escrow))) {
|
|
593
|
-
throw new Error("sender_auth: permit spender is not the source escrow");
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
|
-
function assertWitnessRoles(reserver, releaser, expectedReserver, expectedReleaser, normalize) {
|
|
597
|
-
if (!sameAddress2(reserver, normalize(expectedReserver)) || !sameAddress2(releaser, normalize(expectedReleaser))) {
|
|
598
|
-
throw new Error("sender_auth: deposit witness roles do not match the challenge");
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
function assertRolePairComplete(reserver, releaser) {
|
|
602
|
-
if (reserver === void 0 !== (releaser === void 0)) {
|
|
603
|
-
throw new Error("sender_auth: reserver and releaser must be supplied together");
|
|
604
|
-
}
|
|
605
|
-
}
|
|
606
|
-
function nowSec() {
|
|
607
|
-
return Math.floor(Date.now() / 1e3);
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
});
|
|
611
|
-
|
|
612
|
-
// ../schemas/declarations/PaymentRequest/v1/bindings/typescript/sender-auth/dist/chain-id.js
|
|
613
|
-
var require_chain_id = __commonJS({
|
|
614
|
-
"../schemas/declarations/PaymentRequest/v1/bindings/typescript/sender-auth/dist/chain-id.js"(exports) {
|
|
615
|
-
"use strict";
|
|
616
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
617
|
-
exports.TRON_PERMIT2_FALLBACKS = exports.TRON_CHAIN_IDS = void 0;
|
|
618
|
-
exports.namespaceOf = namespaceOf2;
|
|
619
|
-
exports.evmChainId = evmChainId;
|
|
620
|
-
exports.tronNumericChainId = tronNumericChainId;
|
|
621
|
-
exports.resolveTronPermit2 = resolveTronPermit22;
|
|
622
|
-
exports.clusterIdFromName = clusterIdFromName;
|
|
623
|
-
function namespaceOf2(network) {
|
|
624
|
-
return network.split(":")[0];
|
|
625
|
-
}
|
|
626
|
-
function evmChainId(network) {
|
|
627
|
-
const match = /^eip155:([0-9]+)$/.exec(network);
|
|
628
|
-
if (!match) {
|
|
629
|
-
throw new Error(`sender_auth: expected an eip155 network, got ${network}`);
|
|
630
|
-
}
|
|
631
|
-
return Number(match[1]);
|
|
632
|
-
}
|
|
633
|
-
exports.TRON_CHAIN_IDS = {
|
|
634
|
-
mainnet: 728126428,
|
|
635
|
-
shasta: 2494104990
|
|
636
|
-
};
|
|
637
|
-
function tronNumericChainId(network) {
|
|
638
|
-
const cluster = network.split(":")[1];
|
|
639
|
-
const id = exports.TRON_CHAIN_IDS[cluster ?? ""];
|
|
640
|
-
if (id === void 0) {
|
|
641
|
-
throw new Error(`sender_auth: unsupported Tron network '${network}'`);
|
|
642
|
-
}
|
|
643
|
-
return id;
|
|
644
|
-
}
|
|
645
|
-
exports.TRON_PERMIT2_FALLBACKS = {
|
|
646
|
-
"tron:mainnet": "TJhMXTHQHeQyMD7TcKQFqAePNgG4b31H9m",
|
|
647
|
-
"tron:shasta": "TPUqJPASUn1zLvbLBgRZ5pBYrx7WSe5ahp"
|
|
648
|
-
};
|
|
649
|
-
function resolveTronPermit22(network) {
|
|
650
|
-
const resolved = exports.TRON_PERMIT2_FALLBACKS[network];
|
|
651
|
-
if (!resolved) {
|
|
652
|
-
throw new Error(`sender_auth: no Permit2 address known for Tron network '${network}'`);
|
|
653
|
-
}
|
|
654
|
-
return resolved;
|
|
655
|
-
}
|
|
656
|
-
function clusterIdFromName(name) {
|
|
657
|
-
const encoded = new TextEncoder().encode(name);
|
|
658
|
-
if (encoded.length > 32) {
|
|
659
|
-
throw new Error(`sender_auth: Solana cluster name too long (${encoded.length} > 32 bytes): ${name}`);
|
|
660
|
-
}
|
|
661
|
-
const out = new Uint8Array(32);
|
|
662
|
-
out.set(encoded);
|
|
663
|
-
return out;
|
|
664
|
-
}
|
|
1059
|
+
} });
|
|
1060
|
+
var reserve_encoder_2 = require_reserve_encoder();
|
|
1061
|
+
Object.defineProperty(exports, "buildReserveTypedDataWithQuoteSource", { enumerable: true, get: function() {
|
|
1062
|
+
return reserve_encoder_2.buildReserveTypedDataWithQuoteSource;
|
|
1063
|
+
} });
|
|
1064
|
+
Object.defineProperty(exports, "computeReserveDigestWithQuoteSource", { enumerable: true, get: function() {
|
|
1065
|
+
return reserve_encoder_2.computeReserveDigestWithQuoteSource;
|
|
1066
|
+
} });
|
|
1067
|
+
var release_encoder_1 = require_release_encoder();
|
|
1068
|
+
Object.defineProperty(exports, "buildReleaseTypedDataWithQuoteHash", { enumerable: true, get: function() {
|
|
1069
|
+
return release_encoder_1.buildReleaseTypedDataWithQuoteHash;
|
|
1070
|
+
} });
|
|
1071
|
+
Object.defineProperty(exports, "computeReleaseDigestWithQuoteHash", { enumerable: true, get: function() {
|
|
1072
|
+
return release_encoder_1.computeReleaseDigestWithQuoteHash;
|
|
1073
|
+
} });
|
|
1074
|
+
var refund_encoder_1 = require_refund_encoder();
|
|
1075
|
+
Object.defineProperty(exports, "buildRefundTypedDataWithQuoteHash", { enumerable: true, get: function() {
|
|
1076
|
+
return refund_encoder_1.buildRefundTypedDataWithQuoteHash;
|
|
1077
|
+
} });
|
|
1078
|
+
Object.defineProperty(exports, "computeRefundDigestWithQuoteHash", { enumerable: true, get: function() {
|
|
1079
|
+
return refund_encoder_1.computeRefundDigestWithQuoteHash;
|
|
1080
|
+
} });
|
|
1081
|
+
var deposit_encoder_1 = require_deposit_encoder();
|
|
1082
|
+
Object.defineProperty(exports, "createPermitWitnessTransferFromPrehash", { enumerable: true, get: function() {
|
|
1083
|
+
return deposit_encoder_1.createPermitWitnessTransferFromPrehash;
|
|
1084
|
+
} });
|
|
1085
|
+
Object.defineProperty(exports, "hashPermitWitnessTransferFrom", { enumerable: true, get: function() {
|
|
1086
|
+
return deposit_encoder_1.hashPermitWitnessTransferFrom;
|
|
1087
|
+
} });
|
|
1088
|
+
Object.defineProperty(exports, "PERMIT2_CONTRACT_ADDRESS", { enumerable: true, get: function() {
|
|
1089
|
+
return deposit_encoder_1.PERMIT2_CONTRACT_ADDRESS;
|
|
1090
|
+
} });
|
|
1091
|
+
var deposit_encoder_2 = require_deposit_encoder();
|
|
1092
|
+
Object.defineProperty(exports, "createPermitWitnessTransferFromPrehashWithDestination", { enumerable: true, get: function() {
|
|
1093
|
+
return deposit_encoder_2.createPermitWitnessTransferFromPrehashWithDestination;
|
|
1094
|
+
} });
|
|
1095
|
+
Object.defineProperty(exports, "MAX_DESTINATION_BYTES", { enumerable: true, get: function() {
|
|
1096
|
+
return deposit_encoder_2.MAX_DESTINATION_BYTES;
|
|
1097
|
+
} });
|
|
665
1098
|
}
|
|
666
1099
|
});
|
|
667
1100
|
|
|
@@ -704,22 +1137,23 @@ var require_evm = __commonJS({
|
|
|
704
1137
|
var ethers_1 = __require("ethers");
|
|
705
1138
|
var evm_escrow_encoding_1 = require_dist();
|
|
706
1139
|
var utils_js_1 = require_utils();
|
|
1140
|
+
var destination_js_1 = require_destination();
|
|
707
1141
|
var errors_js_1 = require_errors();
|
|
708
1142
|
var chain_id_js_1 = require_chain_id();
|
|
709
1143
|
exports.evmAdapter = {
|
|
710
|
-
async buildAuthMessage({ sourceAsset, maxSourceAmount, sourceDefaults, deadline, nonce }) {
|
|
1144
|
+
async buildAuthMessage({ sourceAsset, maxSourceAmount, requestId, sourceDefaults, destinationAsset, destinationAccount, deadline, nonce }) {
|
|
711
1145
|
if (nonce === void 0) {
|
|
712
1146
|
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");
|
|
713
1147
|
}
|
|
714
1148
|
if (deadline === void 0) {
|
|
715
1149
|
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)");
|
|
716
1150
|
}
|
|
717
|
-
const sourceChainId =
|
|
718
|
-
const chainIdNum =
|
|
719
|
-
const
|
|
720
|
-
const
|
|
1151
|
+
const { network: sourceChainId, asset: tokenAddress } = (0, utils_js_1.parseSourceAsset)(sourceAsset);
|
|
1152
|
+
const chainIdNum = (0, chain_id_js_1.evmChainId)(sourceChainId);
|
|
1153
|
+
const permit2Contract = sourceDefaults.permit2Contract ?? evm_escrow_encoding_1.PERMIT2_CONTRACT_ADDRESS;
|
|
1154
|
+
const basePermit = {
|
|
721
1155
|
chainId: chainIdNum,
|
|
722
|
-
verifyingContract:
|
|
1156
|
+
verifyingContract: permit2Contract,
|
|
723
1157
|
token: tokenAddress,
|
|
724
1158
|
amount: maxSourceAmount,
|
|
725
1159
|
spender: sourceDefaults.escrowContract,
|
|
@@ -728,7 +1162,21 @@ var require_evm = __commonJS({
|
|
|
728
1162
|
reserver: sourceDefaults.quoteSelector,
|
|
729
1163
|
releaser: sourceDefaults.fulfillmentVerifierAccount
|
|
730
1164
|
};
|
|
731
|
-
|
|
1165
|
+
if ((0, destination_js_1.usesDestinationCommitment)(sourceDefaults.depositWitnessVersion)) {
|
|
1166
|
+
const permitParams = {
|
|
1167
|
+
...basePermit,
|
|
1168
|
+
// The two escrow commitments. Composed here through the shared helpers rather than
|
|
1169
|
+
// accepted pre-built, so this producer and the release signer cannot disagree about
|
|
1170
|
+
// formatting — a disagreement the escrow cannot detect, because it stores only
|
|
1171
|
+
// keccak256(bytes(destination)).
|
|
1172
|
+
depositRequestHash: (0, destination_js_1.deriveDepositRequestHash)(requestId),
|
|
1173
|
+
destination: (0, destination_js_1.buildEscrowDestination)(destinationAsset, destinationAccount)
|
|
1174
|
+
};
|
|
1175
|
+
const messagePrehash2 = (0, evm_escrow_encoding_1.createPermitWitnessTransferFromPrehashWithDestination)(permitParams);
|
|
1176
|
+
const messageHash2 = (0, evm_escrow_encoding_1.hashPermitWitnessTransferFrom)(messagePrehash2);
|
|
1177
|
+
return { messageScheme: "EVM_PERMIT2", messageHash: messageHash2, messagePrehash: JSON.stringify(messagePrehash2) };
|
|
1178
|
+
}
|
|
1179
|
+
const messagePrehash = (0, evm_escrow_encoding_1.createPermitWitnessTransferFromPrehash)(basePermit);
|
|
732
1180
|
const messageHash = (0, evm_escrow_encoding_1.hashPermitWitnessTransferFrom)(messagePrehash);
|
|
733
1181
|
return { messageScheme: "EVM_PERMIT2", messageHash, messagePrehash: JSON.stringify(messagePrehash) };
|
|
734
1182
|
},
|
|
@@ -761,17 +1209,31 @@ var require_evm = __commonJS({
|
|
|
761
1209
|
let msg;
|
|
762
1210
|
try {
|
|
763
1211
|
msg = JSON.parse(signed.message_prehash).message;
|
|
764
|
-
|
|
1212
|
+
const base = {
|
|
765
1213
|
chainId: (0, chain_id_js_1.evmChainId)(source.network),
|
|
766
|
-
|
|
1214
|
+
// The same Permit2 buildAuthMessage signed against. Taken from the VERIFIER's
|
|
1215
|
+
// expectations, never from msg — the prehash is client-supplied, so reading the domain
|
|
1216
|
+
// out of it would let a caller nominate its own verifying contract and have the
|
|
1217
|
+
// signature check itself. Absent means canonical, matching the build side's default.
|
|
1218
|
+
verifyingContract: expected.permit2Contract ?? evm_escrow_encoding_1.PERMIT2_CONTRACT_ADDRESS,
|
|
767
1219
|
token: msg.permitted.token,
|
|
768
1220
|
amount: msg.permitted.amount,
|
|
769
1221
|
spender: msg.spender,
|
|
770
1222
|
nonce: BigInt(msg.nonce),
|
|
771
1223
|
deadline: BigInt(msg.deadline),
|
|
772
|
-
reserver: msg.witness
|
|
773
|
-
releaser: msg.witness
|
|
774
|
-
}
|
|
1224
|
+
reserver: msg.witness?.reserver,
|
|
1225
|
+
releaser: msg.witness?.releaser
|
|
1226
|
+
};
|
|
1227
|
+
const hasHash = typeof msg.witness?.depositRequestHash === "string";
|
|
1228
|
+
const hasDestination = typeof msg.witness?.destination === "string";
|
|
1229
|
+
if (hasHash !== hasDestination) {
|
|
1230
|
+
throw new Error("half-populated deposit witness");
|
|
1231
|
+
}
|
|
1232
|
+
canonical = hasHash ? (0, evm_escrow_encoding_1.createPermitWitnessTransferFromPrehashWithDestination)({
|
|
1233
|
+
...base,
|
|
1234
|
+
depositRequestHash: msg.witness.depositRequestHash,
|
|
1235
|
+
destination: msg.witness.destination
|
|
1236
|
+
}) : (0, evm_escrow_encoding_1.createPermitWitnessTransferFromPrehash)(base);
|
|
775
1237
|
} catch {
|
|
776
1238
|
throw new errors_js_1.MalformedPrehashError();
|
|
777
1239
|
}
|
|
@@ -795,6 +1257,12 @@ var require_evm = __commonJS({
|
|
|
795
1257
|
if (expected.reserver !== void 0 && expected.releaser !== void 0) {
|
|
796
1258
|
(0, utils_js_1.assertWitnessRoles)(msg.witness.reserver, msg.witness.releaser, expected.reserver, expected.releaser, (a) => a);
|
|
797
1259
|
}
|
|
1260
|
+
if (expected.destination !== void 0) {
|
|
1261
|
+
(0, utils_js_1.assertDestination)(msg.witness.destination, expected.destination);
|
|
1262
|
+
}
|
|
1263
|
+
if (expected.requestId !== void 0) {
|
|
1264
|
+
(0, utils_js_1.assertDepositRequestHash)(msg.witness.depositRequestHash, expected.requestId);
|
|
1265
|
+
}
|
|
798
1266
|
return {
|
|
799
1267
|
amount: msg.permitted.amount,
|
|
800
1268
|
deadlineSec,
|
|
@@ -805,7 +1273,11 @@ var require_evm = __commonJS({
|
|
|
805
1273
|
deadlineSec,
|
|
806
1274
|
reserver: msg.witness.reserver,
|
|
807
1275
|
releaser: msg.witness.releaser,
|
|
808
|
-
spender: msg.spender
|
|
1276
|
+
spender: msg.spender,
|
|
1277
|
+
// Surfaced whether or not the opt-in checks above ran, so a consumer binding these
|
|
1278
|
+
// downstream does not have to re-parse message_prehash and risk drifting from this parse.
|
|
1279
|
+
destination: msg.witness.destination,
|
|
1280
|
+
depositRequestHash: msg.witness.depositRequestHash
|
|
809
1281
|
}
|
|
810
1282
|
};
|
|
811
1283
|
}
|
|
@@ -863,7 +1335,7 @@ var require_tron_address = __commonJS({
|
|
|
863
1335
|
hexAddress = base58ToHex(address);
|
|
864
1336
|
}
|
|
865
1337
|
hexAddress = hexAddress.replace(/^0x/, "");
|
|
866
|
-
if (hexAddress.startsWith(TVM_MAINNET_PREFIX)) {
|
|
1338
|
+
if (hexAddress.length === 42 && hexAddress.startsWith(TVM_MAINNET_PREFIX)) {
|
|
867
1339
|
hexAddress = hexAddress.substring(2);
|
|
868
1340
|
}
|
|
869
1341
|
if (hexAddress.length !== 40) {
|
|
@@ -877,14 +1349,62 @@ var require_tron_address = __commonJS({
|
|
|
877
1349
|
}
|
|
878
1350
|
});
|
|
879
1351
|
|
|
1352
|
+
// ../contracts/tvm/escrow-encoding/typescript/dist/witness-values.js
|
|
1353
|
+
var require_witness_values2 = __commonJS({
|
|
1354
|
+
"../contracts/tvm/escrow-encoding/typescript/dist/witness-values.js"(exports) {
|
|
1355
|
+
"use strict";
|
|
1356
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1357
|
+
exports.normalizeBytes32 = normalizeBytes32;
|
|
1358
|
+
exports.normalizeUint256 = normalizeUint256;
|
|
1359
|
+
exports.maskedChainIdToHex = maskedChainIdToHex;
|
|
1360
|
+
var ethers_1 = __require("ethers");
|
|
1361
|
+
var chain_id_1 = require_chain_id2();
|
|
1362
|
+
function normalizeBytes32(label, value) {
|
|
1363
|
+
let bytes;
|
|
1364
|
+
try {
|
|
1365
|
+
bytes = (0, ethers_1.getBytes)(value);
|
|
1366
|
+
} catch {
|
|
1367
|
+
throw new Error(`${label} must be 0x-prefixed hex (32 bytes), got ${JSON.stringify(value)}`);
|
|
1368
|
+
}
|
|
1369
|
+
if (bytes.length !== 32) {
|
|
1370
|
+
throw new Error(`${label} must be exactly 32 bytes, got ${bytes.length}`);
|
|
1371
|
+
}
|
|
1372
|
+
return (0, ethers_1.hexlify)(bytes);
|
|
1373
|
+
}
|
|
1374
|
+
function normalizeUint256(label, value) {
|
|
1375
|
+
let n;
|
|
1376
|
+
try {
|
|
1377
|
+
n = BigInt(value);
|
|
1378
|
+
} catch {
|
|
1379
|
+
throw new Error(`${label} must be an integer (bigint or decimal string), got ${JSON.stringify(value)}`);
|
|
1380
|
+
}
|
|
1381
|
+
if (n < 0n) {
|
|
1382
|
+
throw new Error(`${label} must be non-negative (uint256), got ${n.toString()}`);
|
|
1383
|
+
}
|
|
1384
|
+
return n.toString();
|
|
1385
|
+
}
|
|
1386
|
+
function maskedChainIdToHex(chainId) {
|
|
1387
|
+
if (!Number.isSafeInteger(chainId) || chainId < 0) {
|
|
1388
|
+
throw new Error(`chainId must be a non-negative safe integer, got ${chainId}`);
|
|
1389
|
+
}
|
|
1390
|
+
return `0x${(0, chain_id_1.maskChainId)(chainId).toString(16)}`;
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
});
|
|
1394
|
+
|
|
880
1395
|
// ../contracts/tvm/escrow-encoding/typescript/dist/reserve-encoder.js
|
|
881
1396
|
var require_reserve_encoder2 = __commonJS({
|
|
882
1397
|
"../contracts/tvm/escrow-encoding/typescript/dist/reserve-encoder.js"(exports) {
|
|
883
1398
|
"use strict";
|
|
884
1399
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1400
|
+
exports.RESERVE_WITNESS_TYPES_WITH_QUOTE_SOURCE = void 0;
|
|
885
1401
|
exports.computeReserveDigest = computeReserveDigest;
|
|
1402
|
+
exports.buildTvmReserveTypedDataWithQuoteSource = buildTvmReserveTypedDataWithQuoteSource;
|
|
1403
|
+
exports.computeTvmReserveDigestWithQuoteSource = computeTvmReserveDigestWithQuoteSource;
|
|
886
1404
|
var ethers_1 = __require("ethers");
|
|
887
1405
|
var chain_id_1 = require_chain_id2();
|
|
1406
|
+
var tron_address_1 = require_tron_address();
|
|
1407
|
+
var witness_values_1 = require_witness_values2();
|
|
888
1408
|
var RESERVE_WITNESS_TYPES = {
|
|
889
1409
|
ReserveWitness: [
|
|
890
1410
|
{ name: "paymentId", type: "bytes32" },
|
|
@@ -903,6 +1423,36 @@ var require_reserve_encoder2 = __commonJS({
|
|
|
903
1423
|
settler: input.settler
|
|
904
1424
|
});
|
|
905
1425
|
}
|
|
1426
|
+
exports.RESERVE_WITNESS_TYPES_WITH_QUOTE_SOURCE = {
|
|
1427
|
+
ReserveWitness: [
|
|
1428
|
+
{ name: "depositId", type: "bytes32" },
|
|
1429
|
+
{ name: "quoteHash", type: "bytes32" },
|
|
1430
|
+
{ name: "settler", type: "address" },
|
|
1431
|
+
{ name: "sourceAmount", type: "uint256" }
|
|
1432
|
+
]
|
|
1433
|
+
};
|
|
1434
|
+
function buildTvmReserveTypedDataWithQuoteSource(input) {
|
|
1435
|
+
return {
|
|
1436
|
+
types: exports.RESERVE_WITNESS_TYPES_WITH_QUOTE_SOURCE,
|
|
1437
|
+
primaryType: "ReserveWitness",
|
|
1438
|
+
domain: {
|
|
1439
|
+
name: "Escrow",
|
|
1440
|
+
version: "3",
|
|
1441
|
+
chainId: (0, witness_values_1.maskedChainIdToHex)(input.chainId),
|
|
1442
|
+
verifyingContract: (0, tron_address_1.normalizeAddress)(input.escrowContract)
|
|
1443
|
+
},
|
|
1444
|
+
message: {
|
|
1445
|
+
depositId: (0, witness_values_1.normalizeBytes32)("depositId", input.depositId),
|
|
1446
|
+
quoteHash: (0, witness_values_1.normalizeBytes32)("quoteHash", input.quoteHash),
|
|
1447
|
+
settler: (0, tron_address_1.normalizeAddress)(input.settler),
|
|
1448
|
+
sourceAmount: (0, witness_values_1.normalizeUint256)("sourceAmount", input.sourceAmount)
|
|
1449
|
+
}
|
|
1450
|
+
};
|
|
1451
|
+
}
|
|
1452
|
+
function computeTvmReserveDigestWithQuoteSource(input) {
|
|
1453
|
+
const prehash = buildTvmReserveTypedDataWithQuoteSource(input);
|
|
1454
|
+
return ethers_1.TypedDataEncoder.hash(prehash.domain, prehash.types, prehash.message);
|
|
1455
|
+
}
|
|
906
1456
|
}
|
|
907
1457
|
});
|
|
908
1458
|
|
|
@@ -929,11 +1479,14 @@ var require_deposit_encoder2 = __commonJS({
|
|
|
929
1479
|
"../contracts/tvm/escrow-encoding/typescript/dist/deposit-encoder.js"(exports) {
|
|
930
1480
|
"use strict";
|
|
931
1481
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1482
|
+
exports.MAX_DESTINATION_BYTES = exports.PERMIT_WITNESS_TYPES_WITH_DESTINATION = void 0;
|
|
932
1483
|
exports.createTvmPermitWitnessTransferFromPrehash = createTvmPermitWitnessTransferFromPrehash;
|
|
933
1484
|
exports.hashTvmPermitWitnessTransferFrom = hashTvmPermitWitnessTransferFrom;
|
|
1485
|
+
exports.createTvmPermitWitnessTransferFromPrehashWithDestination = createTvmPermitWitnessTransferFromPrehashWithDestination;
|
|
934
1486
|
var ethers_1 = __require("ethers");
|
|
935
1487
|
var chain_id_1 = require_chain_id2();
|
|
936
1488
|
var tron_address_1 = require_tron_address();
|
|
1489
|
+
var witness_values_1 = require_witness_values2();
|
|
937
1490
|
var PERMIT_WITNESS_TYPES_V2 = {
|
|
938
1491
|
PermitWitnessTransferFrom: [
|
|
939
1492
|
{ name: "permitted", type: "TokenPermissions" },
|
|
@@ -979,6 +1532,180 @@ var require_deposit_encoder2 = __commonJS({
|
|
|
979
1532
|
function hashTvmPermitWitnessTransferFrom(prehash) {
|
|
980
1533
|
return ethers_1.TypedDataEncoder.hash(prehash.domain, prehash.types, prehash.message);
|
|
981
1534
|
}
|
|
1535
|
+
exports.PERMIT_WITNESS_TYPES_WITH_DESTINATION = {
|
|
1536
|
+
PermitWitnessTransferFrom: [
|
|
1537
|
+
{ name: "permitted", type: "TokenPermissions" },
|
|
1538
|
+
{ name: "spender", type: "address" },
|
|
1539
|
+
{ name: "nonce", type: "uint256" },
|
|
1540
|
+
{ name: "deadline", type: "uint256" },
|
|
1541
|
+
{ name: "witness", type: "DepositWitness" }
|
|
1542
|
+
],
|
|
1543
|
+
TokenPermissions: [
|
|
1544
|
+
{ name: "token", type: "address" },
|
|
1545
|
+
{ name: "amount", type: "uint256" }
|
|
1546
|
+
],
|
|
1547
|
+
DepositWitness: [
|
|
1548
|
+
{ name: "depositRequestHash", type: "bytes32" },
|
|
1549
|
+
{ name: "destination", type: "string" },
|
|
1550
|
+
{ name: "reserver", type: "address" },
|
|
1551
|
+
{ name: "releaser", type: "address" }
|
|
1552
|
+
]
|
|
1553
|
+
};
|
|
1554
|
+
exports.MAX_DESTINATION_BYTES = 256;
|
|
1555
|
+
function assertDestinationWithinBounds(destination) {
|
|
1556
|
+
if (destination === "") {
|
|
1557
|
+
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');
|
|
1558
|
+
}
|
|
1559
|
+
const byteLength = (0, ethers_1.toUtf8Bytes)(destination).length;
|
|
1560
|
+
if (byteLength > exports.MAX_DESTINATION_BYTES) {
|
|
1561
|
+
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`);
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1564
|
+
function createTvmPermitWitnessTransferFromPrehashWithDestination(params) {
|
|
1565
|
+
assertDestinationWithinBounds(params.destination);
|
|
1566
|
+
return {
|
|
1567
|
+
types: exports.PERMIT_WITNESS_TYPES_WITH_DESTINATION,
|
|
1568
|
+
primaryType: "PermitWitnessTransferFrom",
|
|
1569
|
+
domain: {
|
|
1570
|
+
name: "Permit2",
|
|
1571
|
+
chainId: (0, witness_values_1.maskedChainIdToHex)(params.chainId),
|
|
1572
|
+
verifyingContract: (0, tron_address_1.normalizeAddress)(params.permit2Address)
|
|
1573
|
+
},
|
|
1574
|
+
message: {
|
|
1575
|
+
permitted: {
|
|
1576
|
+
token: (0, tron_address_1.normalizeAddress)(params.tokenAddress),
|
|
1577
|
+
amount: (0, witness_values_1.normalizeUint256)("amount", params.amount)
|
|
1578
|
+
},
|
|
1579
|
+
spender: (0, tron_address_1.normalizeAddress)(params.spenderAddress),
|
|
1580
|
+
nonce: (0, witness_values_1.normalizeUint256)("nonce", params.nonce),
|
|
1581
|
+
deadline: (0, witness_values_1.normalizeUint256)("deadline", params.deadline),
|
|
1582
|
+
witness: {
|
|
1583
|
+
depositRequestHash: (0, witness_values_1.normalizeBytes32)("depositRequestHash", params.depositRequestHash),
|
|
1584
|
+
destination: params.destination,
|
|
1585
|
+
reserver: (0, tron_address_1.normalizeAddress)(params.reserverAddress),
|
|
1586
|
+
releaser: (0, tron_address_1.normalizeAddress)(params.releaserAddress)
|
|
1587
|
+
}
|
|
1588
|
+
}
|
|
1589
|
+
};
|
|
1590
|
+
}
|
|
1591
|
+
}
|
|
1592
|
+
});
|
|
1593
|
+
|
|
1594
|
+
// ../contracts/tvm/escrow-encoding/typescript/dist/release-encoder.js
|
|
1595
|
+
var require_release_encoder2 = __commonJS({
|
|
1596
|
+
"../contracts/tvm/escrow-encoding/typescript/dist/release-encoder.js"(exports) {
|
|
1597
|
+
"use strict";
|
|
1598
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1599
|
+
exports.RELEASE_WITNESS_TYPES_WITH_QUOTE_HASH = void 0;
|
|
1600
|
+
exports.buildTvmReleaseTypedDataWithQuoteHash = buildTvmReleaseTypedDataWithQuoteHash;
|
|
1601
|
+
exports.computeTvmReleaseDigestWithQuoteHash = computeTvmReleaseDigestWithQuoteHash;
|
|
1602
|
+
var ethers_1 = __require("ethers");
|
|
1603
|
+
var tron_address_1 = require_tron_address();
|
|
1604
|
+
var witness_values_1 = require_witness_values2();
|
|
1605
|
+
exports.RELEASE_WITNESS_TYPES_WITH_QUOTE_HASH = {
|
|
1606
|
+
ReleaseWitness: [
|
|
1607
|
+
{ name: "depositId", type: "bytes32" },
|
|
1608
|
+
{ name: "quoteHash", type: "bytes32" },
|
|
1609
|
+
{ name: "depositRequestHash", type: "bytes32" },
|
|
1610
|
+
{ name: "destinationHash", type: "bytes32" },
|
|
1611
|
+
{ name: "depositor", type: "address" },
|
|
1612
|
+
{ name: "token", type: "address" },
|
|
1613
|
+
{ name: "amount", type: "uint256" },
|
|
1614
|
+
{ name: "feeAmount", type: "uint256" },
|
|
1615
|
+
{ name: "reserver", type: "address" },
|
|
1616
|
+
{ name: "releaser", type: "address" },
|
|
1617
|
+
{ name: "settler", type: "address" }
|
|
1618
|
+
]
|
|
1619
|
+
};
|
|
1620
|
+
function buildTvmReleaseTypedDataWithQuoteHash(input) {
|
|
1621
|
+
const w = input.witness;
|
|
1622
|
+
return {
|
|
1623
|
+
types: exports.RELEASE_WITNESS_TYPES_WITH_QUOTE_HASH,
|
|
1624
|
+
primaryType: "ReleaseWitness",
|
|
1625
|
+
domain: {
|
|
1626
|
+
name: "Escrow",
|
|
1627
|
+
version: "3",
|
|
1628
|
+
chainId: (0, witness_values_1.maskedChainIdToHex)(input.chainId),
|
|
1629
|
+
verifyingContract: (0, tron_address_1.normalizeAddress)(input.escrowContract)
|
|
1630
|
+
},
|
|
1631
|
+
message: {
|
|
1632
|
+
depositId: (0, witness_values_1.normalizeBytes32)("depositId", w.depositId),
|
|
1633
|
+
quoteHash: (0, witness_values_1.normalizeBytes32)("quoteHash", w.quoteHash),
|
|
1634
|
+
depositRequestHash: (0, witness_values_1.normalizeBytes32)("depositRequestHash", w.depositRequestHash),
|
|
1635
|
+
destinationHash: (0, witness_values_1.normalizeBytes32)("destinationHash", w.destinationHash),
|
|
1636
|
+
depositor: (0, tron_address_1.normalizeAddress)(w.depositor),
|
|
1637
|
+
token: (0, tron_address_1.normalizeAddress)(w.token),
|
|
1638
|
+
amount: (0, witness_values_1.normalizeUint256)("amount", w.amount),
|
|
1639
|
+
feeAmount: (0, witness_values_1.normalizeUint256)("feeAmount", w.feeAmount),
|
|
1640
|
+
reserver: (0, tron_address_1.normalizeAddress)(w.reserver),
|
|
1641
|
+
releaser: (0, tron_address_1.normalizeAddress)(w.releaser),
|
|
1642
|
+
settler: (0, tron_address_1.normalizeAddress)(w.settler)
|
|
1643
|
+
}
|
|
1644
|
+
};
|
|
1645
|
+
}
|
|
1646
|
+
function computeTvmReleaseDigestWithQuoteHash(input) {
|
|
1647
|
+
const prehash = buildTvmReleaseTypedDataWithQuoteHash(input);
|
|
1648
|
+
return ethers_1.TypedDataEncoder.hash(prehash.domain, prehash.types, prehash.message);
|
|
1649
|
+
}
|
|
1650
|
+
}
|
|
1651
|
+
});
|
|
1652
|
+
|
|
1653
|
+
// ../contracts/tvm/escrow-encoding/typescript/dist/refund-encoder.js
|
|
1654
|
+
var require_refund_encoder2 = __commonJS({
|
|
1655
|
+
"../contracts/tvm/escrow-encoding/typescript/dist/refund-encoder.js"(exports) {
|
|
1656
|
+
"use strict";
|
|
1657
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1658
|
+
exports.REFUND_WITNESS_TYPES_WITH_QUOTE_HASH = void 0;
|
|
1659
|
+
exports.buildTvmRefundTypedDataWithQuoteHash = buildTvmRefundTypedDataWithQuoteHash;
|
|
1660
|
+
exports.computeTvmRefundDigestWithQuoteHash = computeTvmRefundDigestWithQuoteHash;
|
|
1661
|
+
var ethers_1 = __require("ethers");
|
|
1662
|
+
var tron_address_1 = require_tron_address();
|
|
1663
|
+
var witness_values_1 = require_witness_values2();
|
|
1664
|
+
exports.REFUND_WITNESS_TYPES_WITH_QUOTE_HASH = {
|
|
1665
|
+
RefundWitness: [
|
|
1666
|
+
{ name: "depositId", type: "bytes32" },
|
|
1667
|
+
{ name: "quoteHash", type: "bytes32" },
|
|
1668
|
+
{ name: "depositRequestHash", type: "bytes32" },
|
|
1669
|
+
{ name: "destinationHash", type: "bytes32" },
|
|
1670
|
+
{ name: "depositor", type: "address" },
|
|
1671
|
+
{ name: "token", type: "address" },
|
|
1672
|
+
{ name: "amount", type: "uint256" },
|
|
1673
|
+
{ name: "feeAmount", type: "uint256" },
|
|
1674
|
+
{ name: "reserver", type: "address" },
|
|
1675
|
+
{ name: "releaser", type: "address" },
|
|
1676
|
+
{ name: "settler", type: "address" }
|
|
1677
|
+
]
|
|
1678
|
+
};
|
|
1679
|
+
function buildTvmRefundTypedDataWithQuoteHash(input) {
|
|
1680
|
+
const w = input.witness;
|
|
1681
|
+
return {
|
|
1682
|
+
types: exports.REFUND_WITNESS_TYPES_WITH_QUOTE_HASH,
|
|
1683
|
+
primaryType: "RefundWitness",
|
|
1684
|
+
domain: {
|
|
1685
|
+
name: "Escrow",
|
|
1686
|
+
version: "3",
|
|
1687
|
+
chainId: (0, witness_values_1.maskedChainIdToHex)(input.chainId),
|
|
1688
|
+
verifyingContract: (0, tron_address_1.normalizeAddress)(input.escrowContract)
|
|
1689
|
+
},
|
|
1690
|
+
message: {
|
|
1691
|
+
depositId: (0, witness_values_1.normalizeBytes32)("depositId", w.depositId),
|
|
1692
|
+
quoteHash: (0, witness_values_1.normalizeBytes32)("quoteHash", w.quoteHash),
|
|
1693
|
+
depositRequestHash: (0, witness_values_1.normalizeBytes32)("depositRequestHash", w.depositRequestHash),
|
|
1694
|
+
destinationHash: (0, witness_values_1.normalizeBytes32)("destinationHash", w.destinationHash),
|
|
1695
|
+
depositor: (0, tron_address_1.normalizeAddress)(w.depositor),
|
|
1696
|
+
token: (0, tron_address_1.normalizeAddress)(w.token),
|
|
1697
|
+
amount: (0, witness_values_1.normalizeUint256)("amount", w.amount),
|
|
1698
|
+
feeAmount: (0, witness_values_1.normalizeUint256)("feeAmount", w.feeAmount),
|
|
1699
|
+
reserver: (0, tron_address_1.normalizeAddress)(w.reserver),
|
|
1700
|
+
releaser: (0, tron_address_1.normalizeAddress)(w.releaser),
|
|
1701
|
+
settler: (0, tron_address_1.normalizeAddress)(w.settler)
|
|
1702
|
+
}
|
|
1703
|
+
};
|
|
1704
|
+
}
|
|
1705
|
+
function computeTvmRefundDigestWithQuoteHash(input) {
|
|
1706
|
+
const prehash = buildTvmRefundTypedDataWithQuoteHash(input);
|
|
1707
|
+
return ethers_1.TypedDataEncoder.hash(prehash.domain, prehash.types, prehash.message);
|
|
1708
|
+
}
|
|
982
1709
|
}
|
|
983
1710
|
});
|
|
984
1711
|
|
|
@@ -987,7 +1714,7 @@ var require_dist2 = __commonJS({
|
|
|
987
1714
|
"../contracts/tvm/escrow-encoding/typescript/dist/index.js"(exports) {
|
|
988
1715
|
"use strict";
|
|
989
1716
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
990
|
-
exports.hashTvmPermitWitnessTransferFrom = exports.createTvmPermitWitnessTransferFromPrehash = exports.computePaymentId = exports.computeReserveDigest = exports.normalizeAddress = exports.base58ToHex = exports.maskChainId = void 0;
|
|
1717
|
+
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;
|
|
991
1718
|
var chain_id_1 = require_chain_id2();
|
|
992
1719
|
Object.defineProperty(exports, "maskChainId", { enumerable: true, get: function() {
|
|
993
1720
|
return chain_id_1.maskChainId;
|
|
@@ -1014,6 +1741,46 @@ var require_dist2 = __commonJS({
|
|
|
1014
1741
|
Object.defineProperty(exports, "hashTvmPermitWitnessTransferFrom", { enumerable: true, get: function() {
|
|
1015
1742
|
return deposit_encoder_1.hashTvmPermitWitnessTransferFrom;
|
|
1016
1743
|
} });
|
|
1744
|
+
var reserve_encoder_2 = require_reserve_encoder2();
|
|
1745
|
+
Object.defineProperty(exports, "RESERVE_WITNESS_TYPES_WITH_QUOTE_SOURCE", { enumerable: true, get: function() {
|
|
1746
|
+
return reserve_encoder_2.RESERVE_WITNESS_TYPES_WITH_QUOTE_SOURCE;
|
|
1747
|
+
} });
|
|
1748
|
+
Object.defineProperty(exports, "buildTvmReserveTypedDataWithQuoteSource", { enumerable: true, get: function() {
|
|
1749
|
+
return reserve_encoder_2.buildTvmReserveTypedDataWithQuoteSource;
|
|
1750
|
+
} });
|
|
1751
|
+
Object.defineProperty(exports, "computeTvmReserveDigestWithQuoteSource", { enumerable: true, get: function() {
|
|
1752
|
+
return reserve_encoder_2.computeTvmReserveDigestWithQuoteSource;
|
|
1753
|
+
} });
|
|
1754
|
+
var release_encoder_1 = require_release_encoder2();
|
|
1755
|
+
Object.defineProperty(exports, "RELEASE_WITNESS_TYPES_WITH_QUOTE_HASH", { enumerable: true, get: function() {
|
|
1756
|
+
return release_encoder_1.RELEASE_WITNESS_TYPES_WITH_QUOTE_HASH;
|
|
1757
|
+
} });
|
|
1758
|
+
Object.defineProperty(exports, "buildTvmReleaseTypedDataWithQuoteHash", { enumerable: true, get: function() {
|
|
1759
|
+
return release_encoder_1.buildTvmReleaseTypedDataWithQuoteHash;
|
|
1760
|
+
} });
|
|
1761
|
+
Object.defineProperty(exports, "computeTvmReleaseDigestWithQuoteHash", { enumerable: true, get: function() {
|
|
1762
|
+
return release_encoder_1.computeTvmReleaseDigestWithQuoteHash;
|
|
1763
|
+
} });
|
|
1764
|
+
var refund_encoder_1 = require_refund_encoder2();
|
|
1765
|
+
Object.defineProperty(exports, "REFUND_WITNESS_TYPES_WITH_QUOTE_HASH", { enumerable: true, get: function() {
|
|
1766
|
+
return refund_encoder_1.REFUND_WITNESS_TYPES_WITH_QUOTE_HASH;
|
|
1767
|
+
} });
|
|
1768
|
+
Object.defineProperty(exports, "buildTvmRefundTypedDataWithQuoteHash", { enumerable: true, get: function() {
|
|
1769
|
+
return refund_encoder_1.buildTvmRefundTypedDataWithQuoteHash;
|
|
1770
|
+
} });
|
|
1771
|
+
Object.defineProperty(exports, "computeTvmRefundDigestWithQuoteHash", { enumerable: true, get: function() {
|
|
1772
|
+
return refund_encoder_1.computeTvmRefundDigestWithQuoteHash;
|
|
1773
|
+
} });
|
|
1774
|
+
var deposit_encoder_2 = require_deposit_encoder2();
|
|
1775
|
+
Object.defineProperty(exports, "PERMIT_WITNESS_TYPES_WITH_DESTINATION", { enumerable: true, get: function() {
|
|
1776
|
+
return deposit_encoder_2.PERMIT_WITNESS_TYPES_WITH_DESTINATION;
|
|
1777
|
+
} });
|
|
1778
|
+
Object.defineProperty(exports, "createTvmPermitWitnessTransferFromPrehashWithDestination", { enumerable: true, get: function() {
|
|
1779
|
+
return deposit_encoder_2.createTvmPermitWitnessTransferFromPrehashWithDestination;
|
|
1780
|
+
} });
|
|
1781
|
+
Object.defineProperty(exports, "MAX_DESTINATION_BYTES", { enumerable: true, get: function() {
|
|
1782
|
+
return deposit_encoder_2.MAX_DESTINATION_BYTES;
|
|
1783
|
+
} });
|
|
1017
1784
|
}
|
|
1018
1785
|
});
|
|
1019
1786
|
|
|
@@ -1028,18 +1795,18 @@ var require_tron = __commonJS({
|
|
|
1028
1795
|
var utils_js_1 = require_utils();
|
|
1029
1796
|
var errors_js_1 = require_errors();
|
|
1030
1797
|
var chain_id_js_1 = require_chain_id();
|
|
1798
|
+
var destination_js_1 = require_destination();
|
|
1031
1799
|
exports.tronAdapter = {
|
|
1032
|
-
async buildAuthMessage({ sourceAsset, maxSourceAmount, sourceDefaults, deadline, nonce }) {
|
|
1800
|
+
async buildAuthMessage({ sourceAsset, maxSourceAmount, requestId, sourceDefaults, destinationAsset, destinationAccount, deadline, nonce }) {
|
|
1033
1801
|
if (nonce === void 0) {
|
|
1034
1802
|
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");
|
|
1035
1803
|
}
|
|
1036
1804
|
if (deadline === void 0) {
|
|
1037
1805
|
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)");
|
|
1038
1806
|
}
|
|
1039
|
-
const sourceChainId =
|
|
1040
|
-
const tokenAddress = sourceAsset.split("/")[1].split(":")[1];
|
|
1807
|
+
const { network: sourceChainId, asset: tokenAddress } = (0, utils_js_1.parseSourceAsset)(sourceAsset);
|
|
1041
1808
|
const permit2Address = sourceDefaults.permit2Contract ?? (0, chain_id_js_1.resolveTronPermit2)(sourceChainId);
|
|
1042
|
-
const
|
|
1809
|
+
const baseParams = {
|
|
1043
1810
|
chainId: (0, chain_id_js_1.tronNumericChainId)(sourceChainId),
|
|
1044
1811
|
permit2Address,
|
|
1045
1812
|
tokenAddress,
|
|
@@ -1050,7 +1817,21 @@ var require_tron = __commonJS({
|
|
|
1050
1817
|
reserverAddress: sourceDefaults.quoteSelector,
|
|
1051
1818
|
releaserAddress: sourceDefaults.fulfillmentVerifierAccount
|
|
1052
1819
|
};
|
|
1053
|
-
|
|
1820
|
+
if ((0, destination_js_1.usesDestinationCommitment)(sourceDefaults.depositWitnessVersion)) {
|
|
1821
|
+
const tvmParams = {
|
|
1822
|
+
...baseParams,
|
|
1823
|
+
// The two commitments, composed through the shared helpers rather than accepted
|
|
1824
|
+
// pre-built, so this producer and the Go release signer cannot disagree about
|
|
1825
|
+
// formatting — a disagreement the escrow cannot detect, because it stores only
|
|
1826
|
+
// keccak256(bytes(destination)).
|
|
1827
|
+
depositRequestHash: (0, destination_js_1.deriveDepositRequestHash)(requestId),
|
|
1828
|
+
destination: (0, destination_js_1.buildEscrowDestination)(destinationAsset, destinationAccount)
|
|
1829
|
+
};
|
|
1830
|
+
const messagePrehash2 = (0, tvm_escrow_encoding_1.createTvmPermitWitnessTransferFromPrehashWithDestination)(tvmParams);
|
|
1831
|
+
const messageHash2 = (0, tvm_escrow_encoding_1.hashTvmPermitWitnessTransferFrom)(messagePrehash2);
|
|
1832
|
+
return { messageScheme: "EVM_PERMIT2", messageHash: messageHash2, messagePrehash: JSON.stringify(messagePrehash2) };
|
|
1833
|
+
}
|
|
1834
|
+
const messagePrehash = (0, tvm_escrow_encoding_1.createTvmPermitWitnessTransferFromPrehash)(baseParams);
|
|
1054
1835
|
const messageHash = (0, tvm_escrow_encoding_1.hashTvmPermitWitnessTransferFrom)(messagePrehash);
|
|
1055
1836
|
return { messageScheme: "EVM_PERMIT2", messageHash, messagePrehash: JSON.stringify(messagePrehash) };
|
|
1056
1837
|
},
|
|
@@ -1085,17 +1866,31 @@ var require_tron = __commonJS({
|
|
|
1085
1866
|
let digest;
|
|
1086
1867
|
try {
|
|
1087
1868
|
msg = JSON.parse(signed.message_prehash).message;
|
|
1088
|
-
const
|
|
1869
|
+
const base = {
|
|
1089
1870
|
chainId: (0, chain_id_js_1.tronNumericChainId)(source.network),
|
|
1090
|
-
|
|
1871
|
+
// The same Permit2 buildAuthMessage signed against, taken from the VERIFIER's
|
|
1872
|
+
// expectations rather than from msg — the prehash is payer-supplied, so reading the
|
|
1873
|
+
// domain out of it would let a caller nominate its own verifying contract. Absent means
|
|
1874
|
+
// the pinned per-chain address, matching the build side's default.
|
|
1875
|
+
permit2Address: expected.permit2Contract ?? (0, chain_id_js_1.resolveTronPermit2)(source.network),
|
|
1091
1876
|
tokenAddress: msg.permitted.token,
|
|
1092
1877
|
amount: msg.permitted.amount,
|
|
1093
1878
|
spenderAddress: msg.spender,
|
|
1094
1879
|
nonce: BigInt(msg.nonce),
|
|
1095
1880
|
deadline: BigInt(msg.deadline),
|
|
1096
|
-
reserverAddress: msg.witness
|
|
1097
|
-
releaserAddress: msg.witness
|
|
1098
|
-
}
|
|
1881
|
+
reserverAddress: msg.witness?.reserver,
|
|
1882
|
+
releaserAddress: msg.witness?.releaser
|
|
1883
|
+
};
|
|
1884
|
+
const hasHash = typeof msg.witness?.depositRequestHash === "string";
|
|
1885
|
+
const hasDestination = typeof msg.witness?.destination === "string";
|
|
1886
|
+
if (hasHash !== hasDestination) {
|
|
1887
|
+
throw new Error("half-populated witness");
|
|
1888
|
+
}
|
|
1889
|
+
const canonical = hasHash ? (0, tvm_escrow_encoding_1.createTvmPermitWitnessTransferFromPrehashWithDestination)({
|
|
1890
|
+
...base,
|
|
1891
|
+
depositRequestHash: msg.witness.depositRequestHash,
|
|
1892
|
+
destination: msg.witness.destination
|
|
1893
|
+
}) : (0, tvm_escrow_encoding_1.createTvmPermitWitnessTransferFromPrehash)(base);
|
|
1099
1894
|
digest = (0, tvm_escrow_encoding_1.hashTvmPermitWitnessTransferFrom)(canonical);
|
|
1100
1895
|
} catch {
|
|
1101
1896
|
throw new errors_js_1.MalformedPrehashError();
|
|
@@ -1143,7 +1938,7 @@ var require_errors2 = __commonJS({
|
|
|
1143
1938
|
"../contracts/svm/escrow-encoding/typescript/dist/errors.js"(exports) {
|
|
1144
1939
|
"use strict";
|
|
1145
1940
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1146
|
-
exports.InvalidHexError = exports.InvalidBase58Error = exports.InvalidPubkeyLengthError = exports.ZeroDepositHashError = exports.ZeroRecipientError = exports.ZeroReleaserError = exports.ZeroReserverError = exports.ZeroAmountError = exports.ZeroMintError = exports.ZeroDepositorError = exports.
|
|
1941
|
+
exports.InvalidEscrowDomainError = 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;
|
|
1147
1942
|
var EncodingError = class extends Error {
|
|
1148
1943
|
constructor(message) {
|
|
1149
1944
|
super(message);
|
|
@@ -1151,13 +1946,13 @@ var require_errors2 = __commonJS({
|
|
|
1151
1946
|
}
|
|
1152
1947
|
};
|
|
1153
1948
|
exports.EncodingError = EncodingError;
|
|
1154
|
-
var
|
|
1949
|
+
var ZeroDepositRequestHashError = class extends EncodingError {
|
|
1155
1950
|
constructor() {
|
|
1156
|
-
super("
|
|
1157
|
-
this.name = "
|
|
1951
|
+
super("deposit request hash cannot be zero");
|
|
1952
|
+
this.name = "ZeroDepositRequestHashError";
|
|
1158
1953
|
}
|
|
1159
1954
|
};
|
|
1160
|
-
exports.
|
|
1955
|
+
exports.ZeroDepositRequestHashError = ZeroDepositRequestHashError;
|
|
1161
1956
|
var ZeroDepositorError = class extends EncodingError {
|
|
1162
1957
|
constructor() {
|
|
1163
1958
|
super("depositor cannot be zero");
|
|
@@ -1228,6 +2023,41 @@ var require_errors2 = __commonJS({
|
|
|
1228
2023
|
}
|
|
1229
2024
|
};
|
|
1230
2025
|
exports.InvalidHexError = InvalidHexError;
|
|
2026
|
+
var ZeroQuoteHashError = class extends EncodingError {
|
|
2027
|
+
constructor() {
|
|
2028
|
+
super("quote hash cannot be zero");
|
|
2029
|
+
this.name = "ZeroQuoteHashError";
|
|
2030
|
+
}
|
|
2031
|
+
};
|
|
2032
|
+
exports.ZeroQuoteHashError = ZeroQuoteHashError;
|
|
2033
|
+
var ZeroSourceAmountError = class extends EncodingError {
|
|
2034
|
+
constructor() {
|
|
2035
|
+
super("source amount cannot be zero");
|
|
2036
|
+
this.name = "ZeroSourceAmountError";
|
|
2037
|
+
}
|
|
2038
|
+
};
|
|
2039
|
+
exports.ZeroSourceAmountError = ZeroSourceAmountError;
|
|
2040
|
+
var EmptyDestinationError = class extends EncodingError {
|
|
2041
|
+
constructor() {
|
|
2042
|
+
super("destination cannot be empty");
|
|
2043
|
+
this.name = "EmptyDestinationError";
|
|
2044
|
+
}
|
|
2045
|
+
};
|
|
2046
|
+
exports.EmptyDestinationError = EmptyDestinationError;
|
|
2047
|
+
var DestinationTooLongError = class extends EncodingError {
|
|
2048
|
+
constructor() {
|
|
2049
|
+
super("destination exceeds the maximum length");
|
|
2050
|
+
this.name = "DestinationTooLongError";
|
|
2051
|
+
}
|
|
2052
|
+
};
|
|
2053
|
+
exports.DestinationTooLongError = DestinationTooLongError;
|
|
2054
|
+
var InvalidEscrowDomainError = class extends EncodingError {
|
|
2055
|
+
constructor(message) {
|
|
2056
|
+
super(message);
|
|
2057
|
+
this.name = "InvalidEscrowDomainError";
|
|
2058
|
+
}
|
|
2059
|
+
};
|
|
2060
|
+
exports.InvalidEscrowDomainError = InvalidEscrowDomainError;
|
|
1231
2061
|
}
|
|
1232
2062
|
});
|
|
1233
2063
|
|
|
@@ -1936,12 +2766,17 @@ var require_escrow_domain = __commonJS({
|
|
|
1936
2766
|
"use strict";
|
|
1937
2767
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1938
2768
|
exports.escrowDomainPrefixBytes = escrowDomainPrefixBytes;
|
|
2769
|
+
exports.newEscrowDomain = newEscrowDomain;
|
|
2770
|
+
var errors_1 = require_errors2();
|
|
1939
2771
|
function escrowDomainPrefixBytes(domain) {
|
|
1940
2772
|
if (domain.clusterId.length !== 32) {
|
|
1941
|
-
throw new
|
|
2773
|
+
throw new errors_1.InvalidEscrowDomainError(`EscrowDomain.clusterId must be 32 bytes, got ${domain.clusterId.length}`);
|
|
2774
|
+
}
|
|
2775
|
+
if (domain.programId.isZero()) {
|
|
2776
|
+
throw new errors_1.InvalidEscrowDomainError("EscrowDomain.programId cannot be zero");
|
|
1942
2777
|
}
|
|
1943
2778
|
if (!Number.isInteger(domain.signatureDomainVersion) || domain.signatureDomainVersion < 1 || domain.signatureDomainVersion > 255) {
|
|
1944
|
-
throw new
|
|
2779
|
+
throw new errors_1.InvalidEscrowDomainError(`EscrowDomain.signatureDomainVersion must be an integer in 1..=255, got ${domain.signatureDomainVersion}`);
|
|
1945
2780
|
}
|
|
1946
2781
|
return [
|
|
1947
2782
|
new TextEncoder().encode("escrow"),
|
|
@@ -1950,6 +2785,25 @@ var require_escrow_domain = __commonJS({
|
|
|
1950
2785
|
domain.programId.toBytes()
|
|
1951
2786
|
];
|
|
1952
2787
|
}
|
|
2788
|
+
function newEscrowDomain(clusterName, signatureDomainVersion, programId) {
|
|
2789
|
+
const trimmed = clusterName.trim();
|
|
2790
|
+
if (trimmed.length === 0) {
|
|
2791
|
+
throw new errors_1.InvalidEscrowDomainError("EscrowDomain cluster name cannot be empty");
|
|
2792
|
+
}
|
|
2793
|
+
const encoded = new TextEncoder().encode(trimmed);
|
|
2794
|
+
if (encoded.length > 32) {
|
|
2795
|
+
throw new errors_1.InvalidEscrowDomainError(`EscrowDomain cluster name "${trimmed}" exceeds 32 bytes`);
|
|
2796
|
+
}
|
|
2797
|
+
if (!Number.isInteger(signatureDomainVersion) || signatureDomainVersion < 1 || signatureDomainVersion > 255) {
|
|
2798
|
+
throw new errors_1.InvalidEscrowDomainError(`EscrowDomain.signatureDomainVersion must be an integer in 1..=255, got ${signatureDomainVersion}`);
|
|
2799
|
+
}
|
|
2800
|
+
if (programId.isZero()) {
|
|
2801
|
+
throw new errors_1.InvalidEscrowDomainError("EscrowDomain.programId cannot be zero");
|
|
2802
|
+
}
|
|
2803
|
+
const clusterId = new Uint8Array(32);
|
|
2804
|
+
clusterId.set(encoded);
|
|
2805
|
+
return { clusterId, signatureDomainVersion, programId };
|
|
2806
|
+
}
|
|
1953
2807
|
}
|
|
1954
2808
|
});
|
|
1955
2809
|
|
|
@@ -1958,13 +2812,36 @@ var require_deposit_encoder3 = __commonJS({
|
|
|
1958
2812
|
"../contracts/svm/escrow-encoding/typescript/dist/deposit-encoder.js"(exports) {
|
|
1959
2813
|
"use strict";
|
|
1960
2814
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2815
|
+
exports.MAX_DESTINATION_LEN = void 0;
|
|
1961
2816
|
exports.computeDepositHash = computeDepositHash;
|
|
2817
|
+
exports.computeDestinationHash = computeDestinationHash;
|
|
2818
|
+
exports.computeDepositHashV2 = computeDepositHashV2;
|
|
1962
2819
|
var encoding_utils_1 = require_encoding_utils();
|
|
1963
2820
|
var escrow_domain_1 = require_escrow_domain();
|
|
1964
2821
|
var errors_1 = require_errors2();
|
|
1965
2822
|
function computeDepositHash(params, domain) {
|
|
1966
|
-
if (params.
|
|
1967
|
-
throw new errors_1.
|
|
2823
|
+
if (params.depositRequestHash.length !== 32 || (0, encoding_utils_1.isZeroBytes32)(params.depositRequestHash)) {
|
|
2824
|
+
throw new errors_1.ZeroDepositRequestHashError();
|
|
2825
|
+
}
|
|
2826
|
+
if (params.depositor.isZero())
|
|
2827
|
+
throw new errors_1.ZeroDepositorError();
|
|
2828
|
+
if (params.mint.isZero())
|
|
2829
|
+
throw new errors_1.ZeroMintError();
|
|
2830
|
+
if (params.amount === 0n)
|
|
2831
|
+
throw new errors_1.ZeroAmountError();
|
|
2832
|
+
if (params.reserver.isZero())
|
|
2833
|
+
throw new errors_1.ZeroReserverError();
|
|
2834
|
+
if (params.releaser.isZero())
|
|
2835
|
+
throw new errors_1.ZeroReleaserError();
|
|
2836
|
+
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));
|
|
2837
|
+
}
|
|
2838
|
+
exports.MAX_DESTINATION_LEN = 256;
|
|
2839
|
+
function computeDestinationHash(destination) {
|
|
2840
|
+
return (0, encoding_utils_1.keccak256)((0, encoding_utils_1.stringToBytes)(destination));
|
|
2841
|
+
}
|
|
2842
|
+
function computeDepositHashV2(params, destination, domain) {
|
|
2843
|
+
if (params.depositRequestHash.length !== 32 || (0, encoding_utils_1.isZeroBytes32)(params.depositRequestHash)) {
|
|
2844
|
+
throw new errors_1.ZeroDepositRequestHashError();
|
|
1968
2845
|
}
|
|
1969
2846
|
if (params.depositor.isZero())
|
|
1970
2847
|
throw new errors_1.ZeroDepositorError();
|
|
@@ -1976,7 +2853,28 @@ var require_deposit_encoder3 = __commonJS({
|
|
|
1976
2853
|
throw new errors_1.ZeroReserverError();
|
|
1977
2854
|
if (params.releaser.isZero())
|
|
1978
2855
|
throw new errors_1.ZeroReleaserError();
|
|
1979
|
-
|
|
2856
|
+
if (destination.length === 0)
|
|
2857
|
+
throw new errors_1.EmptyDestinationError();
|
|
2858
|
+
if ((0, encoding_utils_1.stringToBytes)(destination).length > exports.MAX_DESTINATION_LEN) {
|
|
2859
|
+
throw new errors_1.DestinationTooLongError();
|
|
2860
|
+
}
|
|
2861
|
+
return (0, encoding_utils_1.keccak256)(
|
|
2862
|
+
...(0, escrow_domain_1.escrowDomainPrefixBytes)(domain),
|
|
2863
|
+
(0, encoding_utils_1.stringToBytes)("deposit"),
|
|
2864
|
+
params.depositRequestHash,
|
|
2865
|
+
// Hash first: keccak256 concatenates without length prefixes, so injectivity depends on every
|
|
2866
|
+
// hashed field being fixed-width. Feeding the raw string would make it conditional on the
|
|
2867
|
+
// surrounding widths and diverge from the on-chain program, which hashes it too.
|
|
2868
|
+
computeDestinationHash(destination),
|
|
2869
|
+
params.depositor.toBytes(),
|
|
2870
|
+
params.mint.toBytes(),
|
|
2871
|
+
(0, encoding_utils_1.encodeU64LE)(params.amount),
|
|
2872
|
+
params.reserver.toBytes(),
|
|
2873
|
+
params.releaser.toBytes(),
|
|
2874
|
+
(0, encoding_utils_1.encodeU64LE)(params.nonce),
|
|
2875
|
+
(0, encoding_utils_1.encodeU64LE)(params.issuedAt),
|
|
2876
|
+
(0, encoding_utils_1.encodeU64LE)(params.deadline)
|
|
2877
|
+
);
|
|
1980
2878
|
}
|
|
1981
2879
|
}
|
|
1982
2880
|
});
|
|
@@ -1987,6 +2885,8 @@ var require_reserve_encoder3 = __commonJS({
|
|
|
1987
2885
|
"use strict";
|
|
1988
2886
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1989
2887
|
exports.computeReserveHash = computeReserveHash;
|
|
2888
|
+
exports.computeReserveHashV2 = computeReserveHashV2;
|
|
2889
|
+
exports.computeReserveHashV3 = computeReserveHashV3;
|
|
1990
2890
|
var encoding_utils_1 = require_encoding_utils();
|
|
1991
2891
|
var escrow_domain_1 = require_escrow_domain();
|
|
1992
2892
|
var errors_1 = require_errors2();
|
|
@@ -1998,15 +2898,38 @@ var require_reserve_encoder3 = __commonJS({
|
|
|
1998
2898
|
throw new errors_1.ZeroRecipientError();
|
|
1999
2899
|
return (0, encoding_utils_1.keccak256)(...(0, escrow_domain_1.escrowDomainPrefixBytes)(domain), (0, encoding_utils_1.stringToBytes)("reserve"), params.recipient.toBytes(), params.depositHash);
|
|
2000
2900
|
}
|
|
2901
|
+
function computeReserveHashV2(params, quoteHash, domain) {
|
|
2902
|
+
if (params.depositHash.length !== 32 || (0, encoding_utils_1.isZeroBytes32)(params.depositHash)) {
|
|
2903
|
+
throw new errors_1.ZeroDepositHashError();
|
|
2904
|
+
}
|
|
2905
|
+
if (params.recipient.isZero())
|
|
2906
|
+
throw new errors_1.ZeroRecipientError();
|
|
2907
|
+
if (quoteHash.length !== 32 || (0, encoding_utils_1.isZeroBytes32)(quoteHash))
|
|
2908
|
+
throw new errors_1.ZeroQuoteHashError();
|
|
2909
|
+
return (0, encoding_utils_1.keccak256)(...(0, escrow_domain_1.escrowDomainPrefixBytes)(domain), (0, encoding_utils_1.stringToBytes)("reserve"), params.recipient.toBytes(), params.depositHash, quoteHash);
|
|
2910
|
+
}
|
|
2911
|
+
function computeReserveHashV3(params, quoteHash, sourceAmount, domain) {
|
|
2912
|
+
if (params.depositHash.length !== 32 || (0, encoding_utils_1.isZeroBytes32)(params.depositHash)) {
|
|
2913
|
+
throw new errors_1.ZeroDepositHashError();
|
|
2914
|
+
}
|
|
2915
|
+
if (params.recipient.isZero())
|
|
2916
|
+
throw new errors_1.ZeroRecipientError();
|
|
2917
|
+
if (quoteHash.length !== 32 || (0, encoding_utils_1.isZeroBytes32)(quoteHash))
|
|
2918
|
+
throw new errors_1.ZeroQuoteHashError();
|
|
2919
|
+
if (sourceAmount === 0n)
|
|
2920
|
+
throw new errors_1.ZeroSourceAmountError();
|
|
2921
|
+
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));
|
|
2922
|
+
}
|
|
2001
2923
|
}
|
|
2002
2924
|
});
|
|
2003
2925
|
|
|
2004
2926
|
// ../contracts/svm/escrow-encoding/typescript/dist/release-encoder.js
|
|
2005
|
-
var
|
|
2927
|
+
var require_release_encoder3 = __commonJS({
|
|
2006
2928
|
"../contracts/svm/escrow-encoding/typescript/dist/release-encoder.js"(exports) {
|
|
2007
2929
|
"use strict";
|
|
2008
2930
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2009
2931
|
exports.computeReleaseHash = computeReleaseHash;
|
|
2932
|
+
exports.computeReleaseHashV2 = computeReleaseHashV2;
|
|
2010
2933
|
var encoding_utils_1 = require_encoding_utils();
|
|
2011
2934
|
var escrow_domain_1 = require_escrow_domain();
|
|
2012
2935
|
var errors_1 = require_errors2();
|
|
@@ -2016,15 +2939,22 @@ var require_release_encoder = __commonJS({
|
|
|
2016
2939
|
}
|
|
2017
2940
|
return (0, encoding_utils_1.keccak256)(...(0, escrow_domain_1.escrowDomainPrefixBytes)(domain), (0, encoding_utils_1.stringToBytes)("release"), params.depositHash);
|
|
2018
2941
|
}
|
|
2942
|
+
function computeReleaseHashV2(params, quoteHash, domain) {
|
|
2943
|
+
if (params.depositHash.length !== 32 || (0, encoding_utils_1.isZeroBytes32)(params.depositHash)) {
|
|
2944
|
+
throw new errors_1.ZeroDepositHashError();
|
|
2945
|
+
}
|
|
2946
|
+
return (0, encoding_utils_1.keccak256)(...(0, escrow_domain_1.escrowDomainPrefixBytes)(domain), (0, encoding_utils_1.stringToBytes)("release"), params.depositHash, quoteHash);
|
|
2947
|
+
}
|
|
2019
2948
|
}
|
|
2020
2949
|
});
|
|
2021
2950
|
|
|
2022
2951
|
// ../contracts/svm/escrow-encoding/typescript/dist/refund-encoder.js
|
|
2023
|
-
var
|
|
2952
|
+
var require_refund_encoder3 = __commonJS({
|
|
2024
2953
|
"../contracts/svm/escrow-encoding/typescript/dist/refund-encoder.js"(exports) {
|
|
2025
2954
|
"use strict";
|
|
2026
2955
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2027
2956
|
exports.computeRefundHash = computeRefundHash;
|
|
2957
|
+
exports.computeRefundHashV2 = computeRefundHashV2;
|
|
2028
2958
|
var encoding_utils_1 = require_encoding_utils();
|
|
2029
2959
|
var escrow_domain_1 = require_escrow_domain();
|
|
2030
2960
|
var errors_1 = require_errors2();
|
|
@@ -2034,6 +2964,12 @@ var require_refund_encoder = __commonJS({
|
|
|
2034
2964
|
}
|
|
2035
2965
|
return (0, encoding_utils_1.keccak256)(...(0, escrow_domain_1.escrowDomainPrefixBytes)(domain), (0, encoding_utils_1.stringToBytes)("refund"), params.depositHash);
|
|
2036
2966
|
}
|
|
2967
|
+
function computeRefundHashV2(params, quoteHash, domain) {
|
|
2968
|
+
if (params.depositHash.length !== 32 || (0, encoding_utils_1.isZeroBytes32)(params.depositHash)) {
|
|
2969
|
+
throw new errors_1.ZeroDepositHashError();
|
|
2970
|
+
}
|
|
2971
|
+
return (0, encoding_utils_1.keccak256)(...(0, escrow_domain_1.escrowDomainPrefixBytes)(domain), (0, encoding_utils_1.stringToBytes)("refund"), params.depositHash, quoteHash);
|
|
2972
|
+
}
|
|
2037
2973
|
}
|
|
2038
2974
|
});
|
|
2039
2975
|
|
|
@@ -2042,16 +2978,16 @@ var require_nonce_generator2 = __commonJS({
|
|
|
2042
2978
|
"../contracts/svm/escrow-encoding/typescript/dist/nonce-generator.js"(exports) {
|
|
2043
2979
|
"use strict";
|
|
2044
2980
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2045
|
-
exports.MAX_VALID_SLOT = exports.REPLAY_SLOTS = void 0;
|
|
2981
|
+
exports.REPLAY_BUCKETS = exports.MAX_VALID_SLOT = exports.REPLAY_SLOTS = exports.DEPOSIT_COMPUTE_UNIT_LIMIT = void 0;
|
|
2046
2982
|
exports.generateNonce = generateNonce;
|
|
2047
2983
|
var crypto_1 = __require("crypto");
|
|
2984
|
+
exports.DEPOSIT_COMPUTE_UNIT_LIMIT = 4e5;
|
|
2048
2985
|
exports.REPLAY_SLOTS = 235;
|
|
2049
2986
|
exports.MAX_VALID_SLOT = exports.REPLAY_SLOTS - 1;
|
|
2050
|
-
|
|
2987
|
+
exports.REPLAY_BUCKETS = 256;
|
|
2051
2988
|
var NONCE_BUCKET_SHIFT = 32n;
|
|
2052
2989
|
function generateNonce() {
|
|
2053
|
-
const
|
|
2054
|
-
const bucketID = bucketBytes.readUInt32LE(0) & NONCE_BUCKET_MASK;
|
|
2990
|
+
const bucketID = (0, crypto_1.randomBytes)(4).readUInt32LE(0) % exports.REPLAY_BUCKETS;
|
|
2055
2991
|
let slot;
|
|
2056
2992
|
do {
|
|
2057
2993
|
slot = (0, crypto_1.randomBytes)(1)[0];
|
|
@@ -2066,7 +3002,7 @@ var require_dist3 = __commonJS({
|
|
|
2066
3002
|
"../contracts/svm/escrow-encoding/typescript/dist/index.js"(exports) {
|
|
2067
3003
|
"use strict";
|
|
2068
3004
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2069
|
-
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.
|
|
3005
|
+
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.InvalidEscrowDomainError = exports.ZeroSourceAmountError = 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.newEscrowDomain = exports.escrowDomainPrefixBytes = exports.isZeroBytes32 = exports.stringToBytes = exports.keccak256 = exports.encodeU64LE = exports.Pubkey = void 0;
|
|
2070
3006
|
var pubkey_1 = require_pubkey();
|
|
2071
3007
|
Object.defineProperty(exports, "Pubkey", { enumerable: true, get: function() {
|
|
2072
3008
|
return pubkey_1.Pubkey;
|
|
@@ -2088,12 +3024,24 @@ var require_dist3 = __commonJS({
|
|
|
2088
3024
|
Object.defineProperty(exports, "escrowDomainPrefixBytes", { enumerable: true, get: function() {
|
|
2089
3025
|
return escrow_domain_1.escrowDomainPrefixBytes;
|
|
2090
3026
|
} });
|
|
3027
|
+
Object.defineProperty(exports, "newEscrowDomain", { enumerable: true, get: function() {
|
|
3028
|
+
return escrow_domain_1.newEscrowDomain;
|
|
3029
|
+
} });
|
|
2091
3030
|
var errors_1 = require_errors2();
|
|
2092
3031
|
Object.defineProperty(exports, "EncodingError", { enumerable: true, get: function() {
|
|
2093
3032
|
return errors_1.EncodingError;
|
|
2094
3033
|
} });
|
|
2095
|
-
Object.defineProperty(exports, "
|
|
2096
|
-
return errors_1.
|
|
3034
|
+
Object.defineProperty(exports, "ZeroDepositRequestHashError", { enumerable: true, get: function() {
|
|
3035
|
+
return errors_1.ZeroDepositRequestHashError;
|
|
3036
|
+
} });
|
|
3037
|
+
Object.defineProperty(exports, "ZeroQuoteHashError", { enumerable: true, get: function() {
|
|
3038
|
+
return errors_1.ZeroQuoteHashError;
|
|
3039
|
+
} });
|
|
3040
|
+
Object.defineProperty(exports, "EmptyDestinationError", { enumerable: true, get: function() {
|
|
3041
|
+
return errors_1.EmptyDestinationError;
|
|
3042
|
+
} });
|
|
3043
|
+
Object.defineProperty(exports, "DestinationTooLongError", { enumerable: true, get: function() {
|
|
3044
|
+
return errors_1.DestinationTooLongError;
|
|
2097
3045
|
} });
|
|
2098
3046
|
Object.defineProperty(exports, "ZeroDepositorError", { enumerable: true, get: function() {
|
|
2099
3047
|
return errors_1.ZeroDepositorError;
|
|
@@ -2116,6 +3064,12 @@ var require_dist3 = __commonJS({
|
|
|
2116
3064
|
Object.defineProperty(exports, "ZeroDepositHashError", { enumerable: true, get: function() {
|
|
2117
3065
|
return errors_1.ZeroDepositHashError;
|
|
2118
3066
|
} });
|
|
3067
|
+
Object.defineProperty(exports, "ZeroSourceAmountError", { enumerable: true, get: function() {
|
|
3068
|
+
return errors_1.ZeroSourceAmountError;
|
|
3069
|
+
} });
|
|
3070
|
+
Object.defineProperty(exports, "InvalidEscrowDomainError", { enumerable: true, get: function() {
|
|
3071
|
+
return errors_1.InvalidEscrowDomainError;
|
|
3072
|
+
} });
|
|
2119
3073
|
Object.defineProperty(exports, "InvalidPubkeyLengthError", { enumerable: true, get: function() {
|
|
2120
3074
|
return errors_1.InvalidPubkeyLengthError;
|
|
2121
3075
|
} });
|
|
@@ -2129,18 +3083,39 @@ var require_dist3 = __commonJS({
|
|
|
2129
3083
|
Object.defineProperty(exports, "computeDepositHash", { enumerable: true, get: function() {
|
|
2130
3084
|
return deposit_encoder_1.computeDepositHash;
|
|
2131
3085
|
} });
|
|
3086
|
+
Object.defineProperty(exports, "computeDepositHashV2", { enumerable: true, get: function() {
|
|
3087
|
+
return deposit_encoder_1.computeDepositHashV2;
|
|
3088
|
+
} });
|
|
3089
|
+
Object.defineProperty(exports, "computeDestinationHash", { enumerable: true, get: function() {
|
|
3090
|
+
return deposit_encoder_1.computeDestinationHash;
|
|
3091
|
+
} });
|
|
3092
|
+
Object.defineProperty(exports, "MAX_DESTINATION_LEN", { enumerable: true, get: function() {
|
|
3093
|
+
return deposit_encoder_1.MAX_DESTINATION_LEN;
|
|
3094
|
+
} });
|
|
2132
3095
|
var reserve_encoder_1 = require_reserve_encoder3();
|
|
2133
3096
|
Object.defineProperty(exports, "computeReserveHash", { enumerable: true, get: function() {
|
|
2134
3097
|
return reserve_encoder_1.computeReserveHash;
|
|
2135
3098
|
} });
|
|
2136
|
-
|
|
3099
|
+
Object.defineProperty(exports, "computeReserveHashV2", { enumerable: true, get: function() {
|
|
3100
|
+
return reserve_encoder_1.computeReserveHashV2;
|
|
3101
|
+
} });
|
|
3102
|
+
Object.defineProperty(exports, "computeReserveHashV3", { enumerable: true, get: function() {
|
|
3103
|
+
return reserve_encoder_1.computeReserveHashV3;
|
|
3104
|
+
} });
|
|
3105
|
+
var release_encoder_1 = require_release_encoder3();
|
|
2137
3106
|
Object.defineProperty(exports, "computeReleaseHash", { enumerable: true, get: function() {
|
|
2138
3107
|
return release_encoder_1.computeReleaseHash;
|
|
2139
3108
|
} });
|
|
2140
|
-
|
|
3109
|
+
Object.defineProperty(exports, "computeReleaseHashV2", { enumerable: true, get: function() {
|
|
3110
|
+
return release_encoder_1.computeReleaseHashV2;
|
|
3111
|
+
} });
|
|
3112
|
+
var refund_encoder_1 = require_refund_encoder3();
|
|
2141
3113
|
Object.defineProperty(exports, "computeRefundHash", { enumerable: true, get: function() {
|
|
2142
3114
|
return refund_encoder_1.computeRefundHash;
|
|
2143
3115
|
} });
|
|
3116
|
+
Object.defineProperty(exports, "computeRefundHashV2", { enumerable: true, get: function() {
|
|
3117
|
+
return refund_encoder_1.computeRefundHashV2;
|
|
3118
|
+
} });
|
|
2144
3119
|
var nonce_generator_1 = require_nonce_generator2();
|
|
2145
3120
|
Object.defineProperty(exports, "generateNonce", { enumerable: true, get: function() {
|
|
2146
3121
|
return nonce_generator_1.generateNonce;
|
|
@@ -2151,6 +3126,12 @@ var require_dist3 = __commonJS({
|
|
|
2151
3126
|
Object.defineProperty(exports, "MAX_VALID_SLOT", { enumerable: true, get: function() {
|
|
2152
3127
|
return nonce_generator_1.MAX_VALID_SLOT;
|
|
2153
3128
|
} });
|
|
3129
|
+
Object.defineProperty(exports, "REPLAY_BUCKETS", { enumerable: true, get: function() {
|
|
3130
|
+
return nonce_generator_1.REPLAY_BUCKETS;
|
|
3131
|
+
} });
|
|
3132
|
+
Object.defineProperty(exports, "DEPOSIT_COMPUTE_UNIT_LIMIT", { enumerable: true, get: function() {
|
|
3133
|
+
return nonce_generator_1.DEPOSIT_COMPUTE_UNIT_LIMIT;
|
|
3134
|
+
} });
|
|
2154
3135
|
}
|
|
2155
3136
|
});
|
|
2156
3137
|
|
|
@@ -2167,6 +3148,7 @@ var require_solana = __commonJS({
|
|
|
2167
3148
|
var tweetnacl_1 = __importDefault(__require("tweetnacl"));
|
|
2168
3149
|
var bs58_1 = __importDefault(__require("bs58"));
|
|
2169
3150
|
var solana_escrow_encoding_1 = require_dist3();
|
|
3151
|
+
var destination_js_1 = require_destination();
|
|
2170
3152
|
var utils_js_1 = require_utils();
|
|
2171
3153
|
var errors_js_1 = require_errors();
|
|
2172
3154
|
var chain_id_js_1 = require_chain_id();
|
|
@@ -2176,7 +3158,8 @@ var require_solana = __commonJS({
|
|
|
2176
3158
|
}
|
|
2177
3159
|
function hashDeposit(prehash, domain) {
|
|
2178
3160
|
return (0, ethers_1.hexlify)((0, solana_escrow_encoding_1.computeDepositHash)({
|
|
2179
|
-
|
|
3161
|
+
// The encoder field was renamed for cross-VM parity; the prehash WIRE key stays payment_id.
|
|
3162
|
+
depositRequestHash: (0, ethers_1.getBytes)(prehash.payment_id),
|
|
2180
3163
|
depositor: solana_escrow_encoding_1.Pubkey.fromBase58(prehash.depositor),
|
|
2181
3164
|
mint: solana_escrow_encoding_1.Pubkey.fromBase58(prehash.mint),
|
|
2182
3165
|
amount: BigInt(prehash.amount),
|
|
@@ -2187,6 +3170,26 @@ var require_solana = __commonJS({
|
|
|
2187
3170
|
deadline: BigInt(prehash.deadline)
|
|
2188
3171
|
}, domain));
|
|
2189
3172
|
}
|
|
3173
|
+
var SVM_DESTINATION_COMMITMENT_VERSION = 4;
|
|
3174
|
+
function hashDepositV2(prehash, domain) {
|
|
3175
|
+
return (0, ethers_1.hexlify)((0, solana_escrow_encoding_1.computeDepositHashV2)(
|
|
3176
|
+
{
|
|
3177
|
+
depositRequestHash: (0, ethers_1.getBytes)(prehash.deposit_request_hash),
|
|
3178
|
+
depositor: solana_escrow_encoding_1.Pubkey.fromBase58(prehash.depositor),
|
|
3179
|
+
mint: solana_escrow_encoding_1.Pubkey.fromBase58(prehash.mint),
|
|
3180
|
+
amount: BigInt(prehash.amount),
|
|
3181
|
+
reserver: solana_escrow_encoding_1.Pubkey.fromBase58(prehash.reserver),
|
|
3182
|
+
releaser: solana_escrow_encoding_1.Pubkey.fromBase58(prehash.releaser),
|
|
3183
|
+
nonce: BigInt(prehash.nonce),
|
|
3184
|
+
issuedAt: BigInt(prehash.issued_at),
|
|
3185
|
+
deadline: BigInt(prehash.deadline)
|
|
3186
|
+
},
|
|
3187
|
+
// Plaintext, NOT pre-hashed: the encoder hashes it, and hashing an already-hashed
|
|
3188
|
+
// destination yields a well-formed commitment no on-chain state can satisfy.
|
|
3189
|
+
prehash.destination,
|
|
3190
|
+
domain
|
|
3191
|
+
));
|
|
3192
|
+
}
|
|
2190
3193
|
function domainFrom(defaults) {
|
|
2191
3194
|
if (!defaults.escrowContract) {
|
|
2192
3195
|
throw new Error("sender_auth: Solana source requires escrowContract (escrow program id) for the deposit-hash domain");
|
|
@@ -2201,12 +3204,11 @@ var require_solana = __commonJS({
|
|
|
2201
3204
|
};
|
|
2202
3205
|
}
|
|
2203
3206
|
exports.solanaAdapter = {
|
|
2204
|
-
async buildAuthMessage({ sourceAsset, depositor, maxSourceAmount, requestId, sourceDefaults, nonce, solanaClockReader }) {
|
|
3207
|
+
async buildAuthMessage({ sourceAsset, depositor, maxSourceAmount, requestId, sourceDefaults, destinationAsset, destinationAccount, nonce, solanaClockReader }) {
|
|
2205
3208
|
if (!requestId) {
|
|
2206
3209
|
throw new Error("sender_auth: request_id is required");
|
|
2207
3210
|
}
|
|
2208
|
-
const sourceChainId =
|
|
2209
|
-
const tokenMint = sourceAsset.split("/")[1].split(":")[1];
|
|
3211
|
+
const { network: sourceChainId, asset: tokenMint } = (0, utils_js_1.parseSourceAsset)(sourceAsset);
|
|
2210
3212
|
const depositNonce = nonce !== void 0 ? BigInt(nonce) : (0, solana_escrow_encoding_1.generateNonce)();
|
|
2211
3213
|
if (nonce !== void 0) {
|
|
2212
3214
|
if (depositNonce < 0n || depositNonce >= 1n << 64n) {
|
|
@@ -2219,8 +3221,8 @@ var require_solana = __commonJS({
|
|
|
2219
3221
|
const issuedAt = solanaClockReader ? await solanaClockReader(sourceChainId) : BigInt(Math.floor(Date.now() / 1e3));
|
|
2220
3222
|
const deadline = issuedAt + BigInt(utils_js_1.REPLAY_HORIZON_SECS - 8);
|
|
2221
3223
|
const paymentId = generateSolanaPaymentIdV3(requestId);
|
|
2222
|
-
const
|
|
2223
|
-
|
|
3224
|
+
const domain = domainFrom(sourceDefaults);
|
|
3225
|
+
const common = {
|
|
2224
3226
|
depositor,
|
|
2225
3227
|
mint: tokenMint,
|
|
2226
3228
|
amount: BigInt(maxSourceAmount).toString(),
|
|
@@ -2230,7 +3232,20 @@ var require_solana = __commonJS({
|
|
|
2230
3232
|
issued_at: issuedAt.toString(),
|
|
2231
3233
|
deadline: deadline.toString()
|
|
2232
3234
|
};
|
|
2233
|
-
|
|
3235
|
+
if (domain.signatureDomainVersion >= SVM_DESTINATION_COMMITMENT_VERSION) {
|
|
3236
|
+
const prehashV2 = {
|
|
3237
|
+
deposit_request_hash: paymentId,
|
|
3238
|
+
destination: (0, destination_js_1.buildEscrowDestination)(destinationAsset, destinationAccount),
|
|
3239
|
+
...common
|
|
3240
|
+
};
|
|
3241
|
+
return {
|
|
3242
|
+
messageScheme: "SOLANA",
|
|
3243
|
+
messageHash: hashDepositV2(prehashV2, domain),
|
|
3244
|
+
messagePrehash: JSON.stringify(prehashV2)
|
|
3245
|
+
};
|
|
3246
|
+
}
|
|
3247
|
+
const prehash = { payment_id: paymentId, ...common };
|
|
3248
|
+
const depositHash = hashDeposit(prehash, domain);
|
|
2234
3249
|
return { messageScheme: "SOLANA", messageHash: depositHash, messagePrehash: JSON.stringify(prehash) };
|
|
2235
3250
|
},
|
|
2236
3251
|
async sign(signedMessage, privateKey) {
|
|
@@ -2276,8 +3291,18 @@ var require_solana = __commonJS({
|
|
|
2276
3291
|
let prehash;
|
|
2277
3292
|
let canonicalHash;
|
|
2278
3293
|
try {
|
|
2279
|
-
|
|
2280
|
-
|
|
3294
|
+
const domain = domainFrom(expected);
|
|
3295
|
+
if (domain.signatureDomainVersion >= SVM_DESTINATION_COMMITMENT_VERSION) {
|
|
3296
|
+
const v2 = JSON.parse(signed.message_prehash);
|
|
3297
|
+
if (typeof v2.deposit_request_hash !== "string" || typeof v2.destination !== "string") {
|
|
3298
|
+
throw new Error("pre-widening V1 prehash on a destination-committing domain");
|
|
3299
|
+
}
|
|
3300
|
+
canonicalHash = hashDepositV2(v2, domain);
|
|
3301
|
+
prehash = { payment_id: v2.deposit_request_hash, ...v2 };
|
|
3302
|
+
} else {
|
|
3303
|
+
prehash = JSON.parse(signed.message_prehash);
|
|
3304
|
+
canonicalHash = hashDeposit(prehash, domain);
|
|
3305
|
+
}
|
|
2281
3306
|
} catch {
|
|
2282
3307
|
throw new errors_js_1.MalformedPrehashError();
|
|
2283
3308
|
}
|
|
@@ -2369,14 +3394,7 @@ var require_verify = __commonJS({
|
|
|
2369
3394
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2370
3395
|
exports.verifyPaymentRequest = verifyPaymentRequest;
|
|
2371
3396
|
var index_js_1 = require_adapters();
|
|
2372
|
-
|
|
2373
|
-
const parts = assetIdentifier2.split("/");
|
|
2374
|
-
const nsParts = parts[1]?.split(":");
|
|
2375
|
-
if (parts.length < 2 || !nsParts || nsParts.length < 2 || !nsParts[1]) {
|
|
2376
|
-
throw new Error(`sender_auth: invalid source asset "${assetIdentifier2}"`);
|
|
2377
|
-
}
|
|
2378
|
-
return { network: parts[0], asset: nsParts[1] };
|
|
2379
|
-
}
|
|
3397
|
+
var utils_js_1 = require_utils();
|
|
2380
3398
|
function verifyPaymentRequest(request, expected = {}) {
|
|
2381
3399
|
const senderAuth = request.sender_auth;
|
|
2382
3400
|
if (!senderAuth?.signed_messages?.length) {
|
|
@@ -2385,7 +3403,7 @@ var require_verify = __commonJS({
|
|
|
2385
3403
|
if (!request.source) {
|
|
2386
3404
|
throw new Error("sender_auth: request has no source");
|
|
2387
3405
|
}
|
|
2388
|
-
const requestSource = parseSourceAsset(request.source.asset_identifier);
|
|
3406
|
+
const requestSource = (0, utils_js_1.parseSourceAsset)(request.source.asset_identifier);
|
|
2389
3407
|
const { sourceAsset, network: networkOverride, maxSourceAmount: amountOverride, ...scheme } = expected;
|
|
2390
3408
|
const network = networkOverride ?? requestSource.network;
|
|
2391
3409
|
const asset = sourceAsset ?? requestSource.asset;
|
|
@@ -2440,7 +3458,7 @@ var require_dist4 = __commonJS({
|
|
|
2440
3458
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p)) __createBinding(exports2, m, p);
|
|
2441
3459
|
};
|
|
2442
3460
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2443
|
-
exports.localKeySigner = exports.SignerMismatchError = exports.RecoveryFailedError = exports.MalformedPrehashError = exports.verifyPaymentRequest = exports.getChainAdapter = void 0;
|
|
3461
|
+
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;
|
|
2444
3462
|
__exportStar(require_types(), exports);
|
|
2445
3463
|
__exportStar(require_utils(), exports);
|
|
2446
3464
|
__exportStar(require_chain_id(), exports);
|
|
@@ -2448,6 +3466,22 @@ var require_dist4 = __commonJS({
|
|
|
2448
3466
|
Object.defineProperty(exports, "getChainAdapter", { enumerable: true, get: function() {
|
|
2449
3467
|
return index_js_1.getChainAdapter;
|
|
2450
3468
|
} });
|
|
3469
|
+
var destination_js_1 = require_destination();
|
|
3470
|
+
Object.defineProperty(exports, "buildEscrowDestination", { enumerable: true, get: function() {
|
|
3471
|
+
return destination_js_1.buildEscrowDestination;
|
|
3472
|
+
} });
|
|
3473
|
+
Object.defineProperty(exports, "deriveDepositRequestHash", { enumerable: true, get: function() {
|
|
3474
|
+
return destination_js_1.deriveDepositRequestHash;
|
|
3475
|
+
} });
|
|
3476
|
+
Object.defineProperty(exports, "MAX_DESTINATION_BYTES", { enumerable: true, get: function() {
|
|
3477
|
+
return destination_js_1.MAX_DESTINATION_BYTES;
|
|
3478
|
+
} });
|
|
3479
|
+
Object.defineProperty(exports, "usesDestinationCommitment", { enumerable: true, get: function() {
|
|
3480
|
+
return destination_js_1.usesDestinationCommitment;
|
|
3481
|
+
} });
|
|
3482
|
+
Object.defineProperty(exports, "DESTINATION_COMMITMENT_WITNESS_VERSION", { enumerable: true, get: function() {
|
|
3483
|
+
return destination_js_1.DESTINATION_COMMITMENT_WITNESS_VERSION;
|
|
3484
|
+
} });
|
|
2451
3485
|
var verify_js_1 = require_verify();
|
|
2452
3486
|
Object.defineProperty(exports, "verifyPaymentRequest", { enumerable: true, get: function() {
|
|
2453
3487
|
return verify_js_1.verifyPaymentRequest;
|
|
@@ -2581,11 +3615,38 @@ function assetIdentifier(network, asset) {
|
|
|
2581
3615
|
return `${network}/${assetTypeFor(network)}:${asset}`;
|
|
2582
3616
|
}
|
|
2583
3617
|
function sameAddress(a, b) {
|
|
3618
|
+
if (typeof a !== "string" || typeof b !== "string") return false;
|
|
2584
3619
|
if (a.startsWith("0x") && b.startsWith("0x")) {
|
|
2585
3620
|
return a.toLowerCase() === b.toLowerCase();
|
|
2586
3621
|
}
|
|
2587
3622
|
return a === b;
|
|
2588
3623
|
}
|
|
3624
|
+
function sameAssetIdentifier(a, b) {
|
|
3625
|
+
if (a === b) return true;
|
|
3626
|
+
const pa = splitAssetIdentifier(a);
|
|
3627
|
+
const pb = splitAssetIdentifier(b);
|
|
3628
|
+
if (!pa || !pb || pa.namespace !== pb.namespace || pa.assetNamespace !== pb.assetNamespace) {
|
|
3629
|
+
return false;
|
|
3630
|
+
}
|
|
3631
|
+
const referenceMatches = pa.namespace === "solana" ? pa.reference === pb.reference : pa.reference.toLowerCase() === pb.reference.toLowerCase();
|
|
3632
|
+
return referenceMatches && sameAddress(pa.token, pb.token);
|
|
3633
|
+
}
|
|
3634
|
+
function splitAssetIdentifier(identifier) {
|
|
3635
|
+
if (typeof identifier !== "string") return void 0;
|
|
3636
|
+
const slash = identifier.indexOf("/");
|
|
3637
|
+
if (slash < 0) return void 0;
|
|
3638
|
+
const chain = identifier.slice(0, slash);
|
|
3639
|
+
const asset = identifier.slice(slash + 1);
|
|
3640
|
+
const chainColon = chain.indexOf(":");
|
|
3641
|
+
const assetColon = asset.indexOf(":");
|
|
3642
|
+
if (chainColon < 0 || assetColon < 0) return void 0;
|
|
3643
|
+
return {
|
|
3644
|
+
namespace: chain.slice(0, chainColon).toLowerCase(),
|
|
3645
|
+
reference: chain.slice(chainColon + 1),
|
|
3646
|
+
assetNamespace: asset.slice(0, assetColon).toLowerCase(),
|
|
3647
|
+
token: asset.slice(assetColon + 1)
|
|
3648
|
+
};
|
|
3649
|
+
}
|
|
2589
3650
|
function chainDefaultsFromExtra(extra, network) {
|
|
2590
3651
|
return {
|
|
2591
3652
|
escrowContract: extra.escrow,
|
|
@@ -2635,6 +3696,7 @@ export {
|
|
|
2635
3696
|
namespaceOf,
|
|
2636
3697
|
assetIdentifier,
|
|
2637
3698
|
sameAddress,
|
|
3699
|
+
sameAssetIdentifier,
|
|
2638
3700
|
chainDefaultsFromExtra,
|
|
2639
3701
|
contractOverridesFromExtra
|
|
2640
3702
|
};
|