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