@atumlabs/mppx-atum-escrow 0.1.1 → 0.2.2

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.
@@ -1,1410 +0,0 @@
1
- import { createRequire as __atumCreateRequire } from 'module'; const require = __atumCreateRequire(import.meta.url);
2
- import {
3
- METHOD_NAME,
4
- __commonJS,
5
- __require,
6
- __toESM,
7
- assetIdentifier,
8
- atumEscrowChargeMethod,
9
- clusterIdFromName,
10
- contractOverridesFromExtra,
11
- evmChainId,
12
- namespaceOf,
13
- require_dist,
14
- require_dist2,
15
- require_dist3,
16
- resolveTronPermit2,
17
- sameAddress,
18
- tronNumericChainId
19
- } from "./chunk-2MWWLU75.js";
20
-
21
- // ../contracts/svm/escrow-encoding/typescript/dist/errors.js
22
- var require_errors = __commonJS({
23
- "../contracts/svm/escrow-encoding/typescript/dist/errors.js"(exports) {
24
- "use strict";
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.InvalidHexError = exports.InvalidBase58Error = exports.InvalidPubkeyLengthError = exports.ZeroDepositHashError = exports.ZeroRecipientError = exports.ZeroReleaserError = exports.ZeroReserverError = exports.ZeroAmountError = exports.ZeroMintError = exports.ZeroDepositorError = exports.ZeroPaymentIdError = exports.EncodingError = void 0;
27
- var EncodingError = class extends Error {
28
- constructor(message) {
29
- super(message);
30
- this.name = "EncodingError";
31
- }
32
- };
33
- exports.EncodingError = EncodingError;
34
- var ZeroPaymentIdError = class extends EncodingError {
35
- constructor() {
36
- super("payment ID cannot be zero");
37
- this.name = "ZeroPaymentIdError";
38
- }
39
- };
40
- exports.ZeroPaymentIdError = ZeroPaymentIdError;
41
- var ZeroDepositorError = class extends EncodingError {
42
- constructor() {
43
- super("depositor cannot be zero");
44
- this.name = "ZeroDepositorError";
45
- }
46
- };
47
- exports.ZeroDepositorError = ZeroDepositorError;
48
- var ZeroMintError = class extends EncodingError {
49
- constructor() {
50
- super("mint cannot be zero");
51
- this.name = "ZeroMintError";
52
- }
53
- };
54
- exports.ZeroMintError = ZeroMintError;
55
- var ZeroAmountError = class extends EncodingError {
56
- constructor() {
57
- super("amount cannot be zero");
58
- this.name = "ZeroAmountError";
59
- }
60
- };
61
- exports.ZeroAmountError = ZeroAmountError;
62
- var ZeroReserverError = class extends EncodingError {
63
- constructor() {
64
- super("reserver cannot be zero");
65
- this.name = "ZeroReserverError";
66
- }
67
- };
68
- exports.ZeroReserverError = ZeroReserverError;
69
- var ZeroReleaserError = class extends EncodingError {
70
- constructor() {
71
- super("releaser cannot be zero");
72
- this.name = "ZeroReleaserError";
73
- }
74
- };
75
- exports.ZeroReleaserError = ZeroReleaserError;
76
- var ZeroRecipientError = class extends EncodingError {
77
- constructor() {
78
- super("recipient cannot be zero");
79
- this.name = "ZeroRecipientError";
80
- }
81
- };
82
- exports.ZeroRecipientError = ZeroRecipientError;
83
- var ZeroDepositHashError = class extends EncodingError {
84
- constructor() {
85
- super("deposit hash cannot be zero");
86
- this.name = "ZeroDepositHashError";
87
- }
88
- };
89
- exports.ZeroDepositHashError = ZeroDepositHashError;
90
- var InvalidPubkeyLengthError = class extends EncodingError {
91
- constructor() {
92
- super("invalid pubkey length: expected 32 bytes");
93
- this.name = "InvalidPubkeyLengthError";
94
- }
95
- };
96
- exports.InvalidPubkeyLengthError = InvalidPubkeyLengthError;
97
- var InvalidBase58Error = class extends EncodingError {
98
- constructor() {
99
- super("invalid base58 encoding");
100
- this.name = "InvalidBase58Error";
101
- }
102
- };
103
- exports.InvalidBase58Error = InvalidBase58Error;
104
- var InvalidHexError = class extends EncodingError {
105
- constructor() {
106
- super("invalid hex encoding");
107
- this.name = "InvalidHexError";
108
- }
109
- };
110
- exports.InvalidHexError = InvalidHexError;
111
- }
112
- });
113
-
114
- // ../contracts/svm/escrow-encoding/typescript/dist/pubkey.js
115
- var require_pubkey = __commonJS({
116
- "../contracts/svm/escrow-encoding/typescript/dist/pubkey.js"(exports) {
117
- "use strict";
118
- var __importDefault = exports && exports.__importDefault || function(mod) {
119
- return mod && mod.__esModule ? mod : { "default": mod };
120
- };
121
- Object.defineProperty(exports, "__esModule", { value: true });
122
- exports.Pubkey = void 0;
123
- var bs58_1 = __importDefault(__require("bs58"));
124
- var errors_1 = require_errors();
125
- var Pubkey2 = class _Pubkey {
126
- constructor(data) {
127
- if (data.length !== 32) {
128
- throw new errors_1.InvalidPubkeyLengthError();
129
- }
130
- this.data = data;
131
- }
132
- /**
133
- * Creates a Pubkey from a Base58-encoded string.
134
- * This is the standard format for Solana public keys.
135
- */
136
- static fromBase58(s) {
137
- try {
138
- const decoded = bs58_1.default.decode(s);
139
- if (decoded.length !== 32) {
140
- throw new errors_1.InvalidPubkeyLengthError();
141
- }
142
- return new _Pubkey(decoded);
143
- } catch (e) {
144
- if (e instanceof errors_1.InvalidPubkeyLengthError) {
145
- throw e;
146
- }
147
- throw new errors_1.InvalidBase58Error();
148
- }
149
- }
150
- /**
151
- * Creates a Pubkey from a hex-encoded string.
152
- * Accepts with or without "0x" prefix.
153
- */
154
- static fromHex(s) {
155
- let hex = s;
156
- if (hex.startsWith("0x") || hex.startsWith("0X")) {
157
- hex = hex.slice(2);
158
- }
159
- if (hex.length !== 64) {
160
- throw new errors_1.InvalidPubkeyLengthError();
161
- }
162
- try {
163
- const bytes = new Uint8Array(32);
164
- for (let i = 0; i < 32; i++) {
165
- bytes[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
166
- if (isNaN(bytes[i])) {
167
- throw new errors_1.InvalidHexError();
168
- }
169
- }
170
- return new _Pubkey(bytes);
171
- } catch (e) {
172
- if (e instanceof errors_1.InvalidPubkeyLengthError || e instanceof errors_1.InvalidHexError) {
173
- throw e;
174
- }
175
- throw new errors_1.InvalidHexError();
176
- }
177
- }
178
- /**
179
- * Creates a Pubkey from raw bytes.
180
- */
181
- static fromBytes(bytes) {
182
- if (bytes.length !== 32) {
183
- throw new errors_1.InvalidPubkeyLengthError();
184
- }
185
- return new _Pubkey(new Uint8Array(bytes));
186
- }
187
- /**
188
- * Returns the pubkey as a byte array.
189
- */
190
- toBytes() {
191
- return new Uint8Array(this.data);
192
- }
193
- /**
194
- * Returns the Base58 encoding of the pubkey.
195
- */
196
- toString() {
197
- return bs58_1.default.encode(this.data);
198
- }
199
- /**
200
- * Returns the hex encoding of the pubkey (without 0x prefix).
201
- */
202
- toHex() {
203
- return Array.from(this.data).map((b) => b.toString(16).padStart(2, "0")).join("");
204
- }
205
- /**
206
- * Returns true if the pubkey is all zeros.
207
- */
208
- isZero() {
209
- return this.data.every((b) => b === 0);
210
- }
211
- /**
212
- * Returns true if this pubkey equals another.
213
- */
214
- equals(other) {
215
- return this.data.every((b, i) => b === other.data[i]);
216
- }
217
- };
218
- exports.Pubkey = Pubkey2;
219
- }
220
- });
221
-
222
- // ../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/_u64.js
223
- var require_u64 = __commonJS({
224
- "../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/_u64.js"(exports) {
225
- "use strict";
226
- Object.defineProperty(exports, "__esModule", { value: true });
227
- exports.toBig = exports.shrSL = exports.shrSH = exports.rotrSL = exports.rotrSH = exports.rotrBL = exports.rotrBH = exports.rotr32L = exports.rotr32H = exports.rotlSL = exports.rotlSH = exports.rotlBL = exports.rotlBH = exports.add5L = exports.add5H = exports.add4L = exports.add4H = exports.add3L = exports.add3H = void 0;
228
- exports.add = add;
229
- exports.fromBig = fromBig;
230
- exports.split = split;
231
- var U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
232
- var _32n = /* @__PURE__ */ BigInt(32);
233
- function fromBig(n, le = false) {
234
- if (le)
235
- return { h: Number(n & U32_MASK64), l: Number(n >> _32n & U32_MASK64) };
236
- return { h: Number(n >> _32n & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
237
- }
238
- function split(lst, le = false) {
239
- const len = lst.length;
240
- let Ah = new Uint32Array(len);
241
- let Al = new Uint32Array(len);
242
- for (let i = 0; i < len; i++) {
243
- const { h, l } = fromBig(lst[i], le);
244
- [Ah[i], Al[i]] = [h, l];
245
- }
246
- return [Ah, Al];
247
- }
248
- var toBig = (h, l) => BigInt(h >>> 0) << _32n | BigInt(l >>> 0);
249
- exports.toBig = toBig;
250
- var shrSH = (h, _l, s) => h >>> s;
251
- exports.shrSH = shrSH;
252
- var shrSL = (h, l, s) => h << 32 - s | l >>> s;
253
- exports.shrSL = shrSL;
254
- var rotrSH = (h, l, s) => h >>> s | l << 32 - s;
255
- exports.rotrSH = rotrSH;
256
- var rotrSL = (h, l, s) => h << 32 - s | l >>> s;
257
- exports.rotrSL = rotrSL;
258
- var rotrBH = (h, l, s) => h << 64 - s | l >>> s - 32;
259
- exports.rotrBH = rotrBH;
260
- var rotrBL = (h, l, s) => h >>> s - 32 | l << 64 - s;
261
- exports.rotrBL = rotrBL;
262
- var rotr32H = (_h, l) => l;
263
- exports.rotr32H = rotr32H;
264
- var rotr32L = (h, _l) => h;
265
- exports.rotr32L = rotr32L;
266
- var rotlSH = (h, l, s) => h << s | l >>> 32 - s;
267
- exports.rotlSH = rotlSH;
268
- var rotlSL = (h, l, s) => l << s | h >>> 32 - s;
269
- exports.rotlSL = rotlSL;
270
- var rotlBH = (h, l, s) => l << s - 32 | h >>> 64 - s;
271
- exports.rotlBH = rotlBH;
272
- var rotlBL = (h, l, s) => h << s - 32 | l >>> 64 - s;
273
- exports.rotlBL = rotlBL;
274
- function add(Ah, Al, Bh, Bl) {
275
- const l = (Al >>> 0) + (Bl >>> 0);
276
- return { h: Ah + Bh + (l / 2 ** 32 | 0) | 0, l: l | 0 };
277
- }
278
- var add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
279
- exports.add3L = add3L;
280
- var add3H = (low, Ah, Bh, Ch) => Ah + Bh + Ch + (low / 2 ** 32 | 0) | 0;
281
- exports.add3H = add3H;
282
- var add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
283
- exports.add4L = add4L;
284
- var add4H = (low, Ah, Bh, Ch, Dh) => Ah + Bh + Ch + Dh + (low / 2 ** 32 | 0) | 0;
285
- exports.add4H = add4H;
286
- var add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
287
- exports.add5L = add5L;
288
- var add5H = (low, Ah, Bh, Ch, Dh, Eh) => Ah + Bh + Ch + Dh + Eh + (low / 2 ** 32 | 0) | 0;
289
- exports.add5H = add5H;
290
- var u64 = {
291
- fromBig,
292
- split,
293
- toBig,
294
- shrSH,
295
- shrSL,
296
- rotrSH,
297
- rotrSL,
298
- rotrBH,
299
- rotrBL,
300
- rotr32H,
301
- rotr32L,
302
- rotlSH,
303
- rotlSL,
304
- rotlBH,
305
- rotlBL,
306
- add,
307
- add3L,
308
- add3H,
309
- add4L,
310
- add4H,
311
- add5H,
312
- add5L
313
- };
314
- exports.default = u64;
315
- }
316
- });
317
-
318
- // ../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/cryptoNode.js
319
- var require_cryptoNode = __commonJS({
320
- "../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/cryptoNode.js"(exports) {
321
- "use strict";
322
- Object.defineProperty(exports, "__esModule", { value: true });
323
- exports.crypto = void 0;
324
- var nc = __require("crypto");
325
- exports.crypto = nc && typeof nc === "object" && "webcrypto" in nc ? nc.webcrypto : nc && typeof nc === "object" && "randomBytes" in nc ? nc : void 0;
326
- }
327
- });
328
-
329
- // ../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/utils.js
330
- var require_utils = __commonJS({
331
- "../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/utils.js"(exports) {
332
- "use strict";
333
- Object.defineProperty(exports, "__esModule", { value: true });
334
- exports.wrapXOFConstructorWithOpts = exports.wrapConstructorWithOpts = exports.wrapConstructor = exports.Hash = exports.nextTick = exports.swap32IfBE = exports.byteSwapIfBE = exports.swap8IfBE = exports.isLE = void 0;
335
- exports.isBytes = isBytes;
336
- exports.anumber = anumber;
337
- exports.abytes = abytes;
338
- exports.ahash = ahash;
339
- exports.aexists = aexists;
340
- exports.aoutput = aoutput;
341
- exports.u8 = u8;
342
- exports.u32 = u32;
343
- exports.clean = clean;
344
- exports.createView = createView;
345
- exports.rotr = rotr;
346
- exports.rotl = rotl;
347
- exports.byteSwap = byteSwap;
348
- exports.byteSwap32 = byteSwap32;
349
- exports.bytesToHex = bytesToHex;
350
- exports.hexToBytes = hexToBytes;
351
- exports.asyncLoop = asyncLoop;
352
- exports.utf8ToBytes = utf8ToBytes;
353
- exports.bytesToUtf8 = bytesToUtf8;
354
- exports.toBytes = toBytes;
355
- exports.kdfInputToBytes = kdfInputToBytes;
356
- exports.concatBytes = concatBytes;
357
- exports.checkOpts = checkOpts;
358
- exports.createHasher = createHasher;
359
- exports.createOptHasher = createOptHasher;
360
- exports.createXOFer = createXOFer;
361
- exports.randomBytes = randomBytes;
362
- var crypto_1 = require_cryptoNode();
363
- function isBytes(a) {
364
- return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
365
- }
366
- function anumber(n) {
367
- if (!Number.isSafeInteger(n) || n < 0)
368
- throw new Error("positive integer expected, got " + n);
369
- }
370
- function abytes(b, ...lengths) {
371
- if (!isBytes(b))
372
- throw new Error("Uint8Array expected");
373
- if (lengths.length > 0 && !lengths.includes(b.length))
374
- throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b.length);
375
- }
376
- function ahash(h) {
377
- if (typeof h !== "function" || typeof h.create !== "function")
378
- throw new Error("Hash should be wrapped by utils.createHasher");
379
- anumber(h.outputLen);
380
- anumber(h.blockLen);
381
- }
382
- function aexists(instance, checkFinished = true) {
383
- if (instance.destroyed)
384
- throw new Error("Hash instance has been destroyed");
385
- if (checkFinished && instance.finished)
386
- throw new Error("Hash#digest() has already been called");
387
- }
388
- function aoutput(out, instance) {
389
- abytes(out);
390
- const min = instance.outputLen;
391
- if (out.length < min) {
392
- throw new Error("digestInto() expects output buffer of length at least " + min);
393
- }
394
- }
395
- function u8(arr) {
396
- return new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength);
397
- }
398
- function u32(arr) {
399
- return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
400
- }
401
- function clean(...arrays) {
402
- for (let i = 0; i < arrays.length; i++) {
403
- arrays[i].fill(0);
404
- }
405
- }
406
- function createView(arr) {
407
- return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
408
- }
409
- function rotr(word, shift) {
410
- return word << 32 - shift | word >>> shift;
411
- }
412
- function rotl(word, shift) {
413
- return word << shift | word >>> 32 - shift >>> 0;
414
- }
415
- exports.isLE = (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
416
- function byteSwap(word) {
417
- return word << 24 & 4278190080 | word << 8 & 16711680 | word >>> 8 & 65280 | word >>> 24 & 255;
418
- }
419
- exports.swap8IfBE = exports.isLE ? (n) => n : (n) => byteSwap(n);
420
- exports.byteSwapIfBE = exports.swap8IfBE;
421
- function byteSwap32(arr) {
422
- for (let i = 0; i < arr.length; i++) {
423
- arr[i] = byteSwap(arr[i]);
424
- }
425
- return arr;
426
- }
427
- exports.swap32IfBE = exports.isLE ? (u) => u : byteSwap32;
428
- var hasHexBuiltin = /* @__PURE__ */ (() => (
429
- // @ts-ignore
430
- typeof Uint8Array.from([]).toHex === "function" && typeof Uint8Array.fromHex === "function"
431
- ))();
432
- var hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
433
- function bytesToHex(bytes) {
434
- abytes(bytes);
435
- if (hasHexBuiltin)
436
- return bytes.toHex();
437
- let hex = "";
438
- for (let i = 0; i < bytes.length; i++) {
439
- hex += hexes[bytes[i]];
440
- }
441
- return hex;
442
- }
443
- var asciis = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
444
- function asciiToBase16(ch) {
445
- if (ch >= asciis._0 && ch <= asciis._9)
446
- return ch - asciis._0;
447
- if (ch >= asciis.A && ch <= asciis.F)
448
- return ch - (asciis.A - 10);
449
- if (ch >= asciis.a && ch <= asciis.f)
450
- return ch - (asciis.a - 10);
451
- return;
452
- }
453
- function hexToBytes(hex) {
454
- if (typeof hex !== "string")
455
- throw new Error("hex string expected, got " + typeof hex);
456
- if (hasHexBuiltin)
457
- return Uint8Array.fromHex(hex);
458
- const hl = hex.length;
459
- const al = hl / 2;
460
- if (hl % 2)
461
- throw new Error("hex string expected, got unpadded hex of length " + hl);
462
- const array = new Uint8Array(al);
463
- for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
464
- const n1 = asciiToBase16(hex.charCodeAt(hi));
465
- const n2 = asciiToBase16(hex.charCodeAt(hi + 1));
466
- if (n1 === void 0 || n2 === void 0) {
467
- const char = hex[hi] + hex[hi + 1];
468
- throw new Error('hex string expected, got non-hex character "' + char + '" at index ' + hi);
469
- }
470
- array[ai] = n1 * 16 + n2;
471
- }
472
- return array;
473
- }
474
- var nextTick = async () => {
475
- };
476
- exports.nextTick = nextTick;
477
- async function asyncLoop(iters, tick, cb) {
478
- let ts = Date.now();
479
- for (let i = 0; i < iters; i++) {
480
- cb(i);
481
- const diff = Date.now() - ts;
482
- if (diff >= 0 && diff < tick)
483
- continue;
484
- await (0, exports.nextTick)();
485
- ts += diff;
486
- }
487
- }
488
- function utf8ToBytes(str) {
489
- if (typeof str !== "string")
490
- throw new Error("string expected");
491
- return new Uint8Array(new TextEncoder().encode(str));
492
- }
493
- function bytesToUtf8(bytes) {
494
- return new TextDecoder().decode(bytes);
495
- }
496
- function toBytes(data) {
497
- if (typeof data === "string")
498
- data = utf8ToBytes(data);
499
- abytes(data);
500
- return data;
501
- }
502
- function kdfInputToBytes(data) {
503
- if (typeof data === "string")
504
- data = utf8ToBytes(data);
505
- abytes(data);
506
- return data;
507
- }
508
- function concatBytes(...arrays) {
509
- let sum = 0;
510
- for (let i = 0; i < arrays.length; i++) {
511
- const a = arrays[i];
512
- abytes(a);
513
- sum += a.length;
514
- }
515
- const res = new Uint8Array(sum);
516
- for (let i = 0, pad = 0; i < arrays.length; i++) {
517
- const a = arrays[i];
518
- res.set(a, pad);
519
- pad += a.length;
520
- }
521
- return res;
522
- }
523
- function checkOpts(defaults, opts) {
524
- if (opts !== void 0 && {}.toString.call(opts) !== "[object Object]")
525
- throw new Error("options should be object or undefined");
526
- const merged = Object.assign(defaults, opts);
527
- return merged;
528
- }
529
- var Hash = class {
530
- };
531
- exports.Hash = Hash;
532
- function createHasher(hashCons) {
533
- const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
534
- const tmp = hashCons();
535
- hashC.outputLen = tmp.outputLen;
536
- hashC.blockLen = tmp.blockLen;
537
- hashC.create = () => hashCons();
538
- return hashC;
539
- }
540
- function createOptHasher(hashCons) {
541
- const hashC = (msg, opts) => hashCons(opts).update(toBytes(msg)).digest();
542
- const tmp = hashCons({});
543
- hashC.outputLen = tmp.outputLen;
544
- hashC.blockLen = tmp.blockLen;
545
- hashC.create = (opts) => hashCons(opts);
546
- return hashC;
547
- }
548
- function createXOFer(hashCons) {
549
- const hashC = (msg, opts) => hashCons(opts).update(toBytes(msg)).digest();
550
- const tmp = hashCons({});
551
- hashC.outputLen = tmp.outputLen;
552
- hashC.blockLen = tmp.blockLen;
553
- hashC.create = (opts) => hashCons(opts);
554
- return hashC;
555
- }
556
- exports.wrapConstructor = createHasher;
557
- exports.wrapConstructorWithOpts = createOptHasher;
558
- exports.wrapXOFConstructorWithOpts = createXOFer;
559
- function randomBytes(bytesLength = 32) {
560
- if (crypto_1.crypto && typeof crypto_1.crypto.getRandomValues === "function") {
561
- return crypto_1.crypto.getRandomValues(new Uint8Array(bytesLength));
562
- }
563
- if (crypto_1.crypto && typeof crypto_1.crypto.randomBytes === "function") {
564
- return Uint8Array.from(crypto_1.crypto.randomBytes(bytesLength));
565
- }
566
- throw new Error("crypto.getRandomValues must be defined");
567
- }
568
- }
569
- });
570
-
571
- // ../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/sha3.js
572
- var require_sha3 = __commonJS({
573
- "../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/sha3.js"(exports) {
574
- "use strict";
575
- Object.defineProperty(exports, "__esModule", { value: true });
576
- exports.shake256 = exports.shake128 = exports.keccak_512 = exports.keccak_384 = exports.keccak_256 = exports.keccak_224 = exports.sha3_512 = exports.sha3_384 = exports.sha3_256 = exports.sha3_224 = exports.Keccak = void 0;
577
- exports.keccakP = keccakP;
578
- var _u64_ts_1 = require_u64();
579
- var utils_ts_1 = require_utils();
580
- var _0n = BigInt(0);
581
- var _1n = BigInt(1);
582
- var _2n = BigInt(2);
583
- var _7n = BigInt(7);
584
- var _256n = BigInt(256);
585
- var _0x71n = BigInt(113);
586
- var SHA3_PI = [];
587
- var SHA3_ROTL = [];
588
- var _SHA3_IOTA = [];
589
- for (let round = 0, R = _1n, x = 1, y = 0; round < 24; round++) {
590
- [x, y] = [y, (2 * x + 3 * y) % 5];
591
- SHA3_PI.push(2 * (5 * y + x));
592
- SHA3_ROTL.push((round + 1) * (round + 2) / 2 % 64);
593
- let t = _0n;
594
- for (let j = 0; j < 7; j++) {
595
- R = (R << _1n ^ (R >> _7n) * _0x71n) % _256n;
596
- if (R & _2n)
597
- t ^= _1n << (_1n << /* @__PURE__ */ BigInt(j)) - _1n;
598
- }
599
- _SHA3_IOTA.push(t);
600
- }
601
- var IOTAS = (0, _u64_ts_1.split)(_SHA3_IOTA, true);
602
- var SHA3_IOTA_H = IOTAS[0];
603
- var SHA3_IOTA_L = IOTAS[1];
604
- var rotlH = (h, l, s) => s > 32 ? (0, _u64_ts_1.rotlBH)(h, l, s) : (0, _u64_ts_1.rotlSH)(h, l, s);
605
- var rotlL = (h, l, s) => s > 32 ? (0, _u64_ts_1.rotlBL)(h, l, s) : (0, _u64_ts_1.rotlSL)(h, l, s);
606
- function keccakP(s, rounds = 24) {
607
- const B = new Uint32Array(5 * 2);
608
- for (let round = 24 - rounds; round < 24; round++) {
609
- for (let x = 0; x < 10; x++)
610
- B[x] = s[x] ^ s[x + 10] ^ s[x + 20] ^ s[x + 30] ^ s[x + 40];
611
- for (let x = 0; x < 10; x += 2) {
612
- const idx1 = (x + 8) % 10;
613
- const idx0 = (x + 2) % 10;
614
- const B0 = B[idx0];
615
- const B1 = B[idx0 + 1];
616
- const Th = rotlH(B0, B1, 1) ^ B[idx1];
617
- const Tl = rotlL(B0, B1, 1) ^ B[idx1 + 1];
618
- for (let y = 0; y < 50; y += 10) {
619
- s[x + y] ^= Th;
620
- s[x + y + 1] ^= Tl;
621
- }
622
- }
623
- let curH = s[2];
624
- let curL = s[3];
625
- for (let t = 0; t < 24; t++) {
626
- const shift = SHA3_ROTL[t];
627
- const Th = rotlH(curH, curL, shift);
628
- const Tl = rotlL(curH, curL, shift);
629
- const PI = SHA3_PI[t];
630
- curH = s[PI];
631
- curL = s[PI + 1];
632
- s[PI] = Th;
633
- s[PI + 1] = Tl;
634
- }
635
- for (let y = 0; y < 50; y += 10) {
636
- for (let x = 0; x < 10; x++)
637
- B[x] = s[y + x];
638
- for (let x = 0; x < 10; x++)
639
- s[y + x] ^= ~B[(x + 2) % 10] & B[(x + 4) % 10];
640
- }
641
- s[0] ^= SHA3_IOTA_H[round];
642
- s[1] ^= SHA3_IOTA_L[round];
643
- }
644
- (0, utils_ts_1.clean)(B);
645
- }
646
- var Keccak = class _Keccak extends utils_ts_1.Hash {
647
- // NOTE: we accept arguments in bytes instead of bits here.
648
- constructor(blockLen, suffix, outputLen, enableXOF = false, rounds = 24) {
649
- super();
650
- this.pos = 0;
651
- this.posOut = 0;
652
- this.finished = false;
653
- this.destroyed = false;
654
- this.enableXOF = false;
655
- this.blockLen = blockLen;
656
- this.suffix = suffix;
657
- this.outputLen = outputLen;
658
- this.enableXOF = enableXOF;
659
- this.rounds = rounds;
660
- (0, utils_ts_1.anumber)(outputLen);
661
- if (!(0 < blockLen && blockLen < 200))
662
- throw new Error("only keccak-f1600 function is supported");
663
- this.state = new Uint8Array(200);
664
- this.state32 = (0, utils_ts_1.u32)(this.state);
665
- }
666
- clone() {
667
- return this._cloneInto();
668
- }
669
- keccak() {
670
- (0, utils_ts_1.swap32IfBE)(this.state32);
671
- keccakP(this.state32, this.rounds);
672
- (0, utils_ts_1.swap32IfBE)(this.state32);
673
- this.posOut = 0;
674
- this.pos = 0;
675
- }
676
- update(data) {
677
- (0, utils_ts_1.aexists)(this);
678
- data = (0, utils_ts_1.toBytes)(data);
679
- (0, utils_ts_1.abytes)(data);
680
- const { blockLen, state } = this;
681
- const len = data.length;
682
- for (let pos = 0; pos < len; ) {
683
- const take = Math.min(blockLen - this.pos, len - pos);
684
- for (let i = 0; i < take; i++)
685
- state[this.pos++] ^= data[pos++];
686
- if (this.pos === blockLen)
687
- this.keccak();
688
- }
689
- return this;
690
- }
691
- finish() {
692
- if (this.finished)
693
- return;
694
- this.finished = true;
695
- const { state, suffix, pos, blockLen } = this;
696
- state[pos] ^= suffix;
697
- if ((suffix & 128) !== 0 && pos === blockLen - 1)
698
- this.keccak();
699
- state[blockLen - 1] ^= 128;
700
- this.keccak();
701
- }
702
- writeInto(out) {
703
- (0, utils_ts_1.aexists)(this, false);
704
- (0, utils_ts_1.abytes)(out);
705
- this.finish();
706
- const bufferOut = this.state;
707
- const { blockLen } = this;
708
- for (let pos = 0, len = out.length; pos < len; ) {
709
- if (this.posOut >= blockLen)
710
- this.keccak();
711
- const take = Math.min(blockLen - this.posOut, len - pos);
712
- out.set(bufferOut.subarray(this.posOut, this.posOut + take), pos);
713
- this.posOut += take;
714
- pos += take;
715
- }
716
- return out;
717
- }
718
- xofInto(out) {
719
- if (!this.enableXOF)
720
- throw new Error("XOF is not possible for this instance");
721
- return this.writeInto(out);
722
- }
723
- xof(bytes) {
724
- (0, utils_ts_1.anumber)(bytes);
725
- return this.xofInto(new Uint8Array(bytes));
726
- }
727
- digestInto(out) {
728
- (0, utils_ts_1.aoutput)(out, this);
729
- if (this.finished)
730
- throw new Error("digest() was already called");
731
- this.writeInto(out);
732
- this.destroy();
733
- return out;
734
- }
735
- digest() {
736
- return this.digestInto(new Uint8Array(this.outputLen));
737
- }
738
- destroy() {
739
- this.destroyed = true;
740
- (0, utils_ts_1.clean)(this.state);
741
- }
742
- _cloneInto(to) {
743
- const { blockLen, suffix, outputLen, rounds, enableXOF } = this;
744
- to || (to = new _Keccak(blockLen, suffix, outputLen, enableXOF, rounds));
745
- to.state32.set(this.state32);
746
- to.pos = this.pos;
747
- to.posOut = this.posOut;
748
- to.finished = this.finished;
749
- to.rounds = rounds;
750
- to.suffix = suffix;
751
- to.outputLen = outputLen;
752
- to.enableXOF = enableXOF;
753
- to.destroyed = this.destroyed;
754
- return to;
755
- }
756
- };
757
- exports.Keccak = Keccak;
758
- var gen = (suffix, blockLen, outputLen) => (0, utils_ts_1.createHasher)(() => new Keccak(blockLen, suffix, outputLen));
759
- exports.sha3_224 = (() => gen(6, 144, 224 / 8))();
760
- exports.sha3_256 = (() => gen(6, 136, 256 / 8))();
761
- exports.sha3_384 = (() => gen(6, 104, 384 / 8))();
762
- exports.sha3_512 = (() => gen(6, 72, 512 / 8))();
763
- exports.keccak_224 = (() => gen(1, 144, 224 / 8))();
764
- exports.keccak_256 = (() => gen(1, 136, 256 / 8))();
765
- exports.keccak_384 = (() => gen(1, 104, 384 / 8))();
766
- exports.keccak_512 = (() => gen(1, 72, 512 / 8))();
767
- var genShake = (suffix, blockLen, outputLen) => (0, utils_ts_1.createXOFer)((opts = {}) => new Keccak(blockLen, suffix, opts.dkLen === void 0 ? outputLen : opts.dkLen, true));
768
- exports.shake128 = (() => genShake(31, 168, 128 / 8))();
769
- exports.shake256 = (() => genShake(31, 136, 256 / 8))();
770
- }
771
- });
772
-
773
- // ../contracts/svm/escrow-encoding/typescript/dist/encoding-utils.js
774
- var require_encoding_utils = __commonJS({
775
- "../contracts/svm/escrow-encoding/typescript/dist/encoding-utils.js"(exports) {
776
- "use strict";
777
- Object.defineProperty(exports, "__esModule", { value: true });
778
- exports.encodeU64LE = encodeU64LE;
779
- exports.keccak256 = keccak256;
780
- exports.stringToBytes = stringToBytes;
781
- exports.isZeroBytes32 = isZeroBytes32;
782
- var sha3_1 = require_sha3();
783
- function encodeU64LE(value) {
784
- const buffer = new Uint8Array(8);
785
- let v = value;
786
- for (let i = 0; i < 8; i++) {
787
- buffer[i] = Number(v & 0xffn);
788
- v = v >> 8n;
789
- }
790
- return buffer;
791
- }
792
- function keccak256(...data) {
793
- const totalLength = data.reduce((sum, arr) => sum + arr.length, 0);
794
- const combined = new Uint8Array(totalLength);
795
- let offset = 0;
796
- for (const arr of data) {
797
- combined.set(arr, offset);
798
- offset += arr.length;
799
- }
800
- return (0, sha3_1.keccak_256)(combined);
801
- }
802
- function stringToBytes(s) {
803
- return new TextEncoder().encode(s);
804
- }
805
- function isZeroBytes32(data) {
806
- if (data.length !== 32)
807
- return false;
808
- return data.every((b) => b === 0);
809
- }
810
- }
811
- });
812
-
813
- // ../contracts/svm/escrow-encoding/typescript/dist/escrow-domain.js
814
- var require_escrow_domain = __commonJS({
815
- "../contracts/svm/escrow-encoding/typescript/dist/escrow-domain.js"(exports) {
816
- "use strict";
817
- Object.defineProperty(exports, "__esModule", { value: true });
818
- exports.escrowDomainPrefixBytes = escrowDomainPrefixBytes;
819
- function escrowDomainPrefixBytes(domain) {
820
- if (domain.clusterId.length !== 32) {
821
- throw new Error(`EscrowDomain.clusterId must be 32 bytes, got ${domain.clusterId.length}`);
822
- }
823
- if (!Number.isInteger(domain.signatureDomainVersion) || domain.signatureDomainVersion < 1 || domain.signatureDomainVersion > 255) {
824
- throw new Error(`EscrowDomain.signatureDomainVersion must be an integer in 1..=255, got ${domain.signatureDomainVersion}`);
825
- }
826
- return [
827
- new TextEncoder().encode("escrow"),
828
- new Uint8Array([domain.signatureDomainVersion]),
829
- domain.clusterId,
830
- domain.programId.toBytes()
831
- ];
832
- }
833
- }
834
- });
835
-
836
- // ../contracts/svm/escrow-encoding/typescript/dist/deposit-encoder.js
837
- var require_deposit_encoder = __commonJS({
838
- "../contracts/svm/escrow-encoding/typescript/dist/deposit-encoder.js"(exports) {
839
- "use strict";
840
- Object.defineProperty(exports, "__esModule", { value: true });
841
- exports.computeDepositHash = computeDepositHash2;
842
- var encoding_utils_1 = require_encoding_utils();
843
- var escrow_domain_1 = require_escrow_domain();
844
- var errors_1 = require_errors();
845
- function computeDepositHash2(params, domain) {
846
- if (params.paymentId.length !== 32 || (0, encoding_utils_1.isZeroBytes32)(params.paymentId)) {
847
- throw new errors_1.ZeroPaymentIdError();
848
- }
849
- if (params.depositor.isZero())
850
- throw new errors_1.ZeroDepositorError();
851
- if (params.mint.isZero())
852
- throw new errors_1.ZeroMintError();
853
- if (params.amount === 0n)
854
- throw new errors_1.ZeroAmountError();
855
- if (params.reserver.isZero())
856
- throw new errors_1.ZeroReserverError();
857
- if (params.releaser.isZero())
858
- throw new errors_1.ZeroReleaserError();
859
- return (0, encoding_utils_1.keccak256)(...(0, escrow_domain_1.escrowDomainPrefixBytes)(domain), (0, encoding_utils_1.stringToBytes)("deposit"), params.paymentId, 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));
860
- }
861
- }
862
- });
863
-
864
- // ../contracts/svm/escrow-encoding/typescript/dist/reserve-encoder.js
865
- var require_reserve_encoder = __commonJS({
866
- "../contracts/svm/escrow-encoding/typescript/dist/reserve-encoder.js"(exports) {
867
- "use strict";
868
- Object.defineProperty(exports, "__esModule", { value: true });
869
- exports.computeReserveHash = computeReserveHash;
870
- var encoding_utils_1 = require_encoding_utils();
871
- var escrow_domain_1 = require_escrow_domain();
872
- var errors_1 = require_errors();
873
- function computeReserveHash(params, domain) {
874
- if (params.depositHash.length !== 32 || (0, encoding_utils_1.isZeroBytes32)(params.depositHash)) {
875
- throw new errors_1.ZeroDepositHashError();
876
- }
877
- if (params.recipient.isZero())
878
- throw new errors_1.ZeroRecipientError();
879
- return (0, encoding_utils_1.keccak256)(...(0, escrow_domain_1.escrowDomainPrefixBytes)(domain), (0, encoding_utils_1.stringToBytes)("reserve"), params.recipient.toBytes(), params.depositHash);
880
- }
881
- }
882
- });
883
-
884
- // ../contracts/svm/escrow-encoding/typescript/dist/release-encoder.js
885
- var require_release_encoder = __commonJS({
886
- "../contracts/svm/escrow-encoding/typescript/dist/release-encoder.js"(exports) {
887
- "use strict";
888
- Object.defineProperty(exports, "__esModule", { value: true });
889
- exports.computeReleaseHash = computeReleaseHash;
890
- var encoding_utils_1 = require_encoding_utils();
891
- var escrow_domain_1 = require_escrow_domain();
892
- var errors_1 = require_errors();
893
- function computeReleaseHash(params, domain) {
894
- if (params.depositHash.length !== 32 || (0, encoding_utils_1.isZeroBytes32)(params.depositHash)) {
895
- throw new errors_1.ZeroDepositHashError();
896
- }
897
- return (0, encoding_utils_1.keccak256)(...(0, escrow_domain_1.escrowDomainPrefixBytes)(domain), (0, encoding_utils_1.stringToBytes)("release"), params.depositHash);
898
- }
899
- }
900
- });
901
-
902
- // ../contracts/svm/escrow-encoding/typescript/dist/refund-encoder.js
903
- var require_refund_encoder = __commonJS({
904
- "../contracts/svm/escrow-encoding/typescript/dist/refund-encoder.js"(exports) {
905
- "use strict";
906
- Object.defineProperty(exports, "__esModule", { value: true });
907
- exports.computeRefundHash = computeRefundHash;
908
- var encoding_utils_1 = require_encoding_utils();
909
- var escrow_domain_1 = require_escrow_domain();
910
- var errors_1 = require_errors();
911
- function computeRefundHash(params, domain) {
912
- if (params.depositHash.length !== 32 || (0, encoding_utils_1.isZeroBytes32)(params.depositHash)) {
913
- throw new errors_1.ZeroDepositHashError();
914
- }
915
- return (0, encoding_utils_1.keccak256)(...(0, escrow_domain_1.escrowDomainPrefixBytes)(domain), (0, encoding_utils_1.stringToBytes)("refund"), params.depositHash);
916
- }
917
- }
918
- });
919
-
920
- // ../contracts/svm/escrow-encoding/typescript/dist/nonce-generator.js
921
- var require_nonce_generator = __commonJS({
922
- "../contracts/svm/escrow-encoding/typescript/dist/nonce-generator.js"(exports) {
923
- "use strict";
924
- Object.defineProperty(exports, "__esModule", { value: true });
925
- exports.MAX_VALID_SLOT = exports.REPLAY_SLOTS = void 0;
926
- exports.generateNonce = generateNonce;
927
- var crypto_1 = __require("crypto");
928
- exports.REPLAY_SLOTS = 235;
929
- exports.MAX_VALID_SLOT = exports.REPLAY_SLOTS - 1;
930
- var NONCE_BUCKET_MASK = 131071;
931
- var NONCE_BUCKET_SHIFT = 32n;
932
- function generateNonce() {
933
- const bucketBytes = (0, crypto_1.randomBytes)(4);
934
- const bucketID = bucketBytes.readUInt32LE(0) & NONCE_BUCKET_MASK;
935
- let slot;
936
- do {
937
- slot = (0, crypto_1.randomBytes)(1)[0];
938
- } while (slot >= exports.REPLAY_SLOTS);
939
- return BigInt(bucketID) << NONCE_BUCKET_SHIFT | BigInt(slot);
940
- }
941
- }
942
- });
943
-
944
- // ../contracts/svm/escrow-encoding/typescript/dist/index.js
945
- var require_dist4 = __commonJS({
946
- "../contracts/svm/escrow-encoding/typescript/dist/index.js"(exports) {
947
- "use strict";
948
- Object.defineProperty(exports, "__esModule", { value: true });
949
- 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.ZeroPaymentIdError = exports.EncodingError = exports.escrowDomainPrefixBytes = exports.isZeroBytes32 = exports.stringToBytes = exports.keccak256 = exports.encodeU64LE = exports.Pubkey = void 0;
950
- var pubkey_1 = require_pubkey();
951
- Object.defineProperty(exports, "Pubkey", { enumerable: true, get: function() {
952
- return pubkey_1.Pubkey;
953
- } });
954
- var encoding_utils_1 = require_encoding_utils();
955
- Object.defineProperty(exports, "encodeU64LE", { enumerable: true, get: function() {
956
- return encoding_utils_1.encodeU64LE;
957
- } });
958
- Object.defineProperty(exports, "keccak256", { enumerable: true, get: function() {
959
- return encoding_utils_1.keccak256;
960
- } });
961
- Object.defineProperty(exports, "stringToBytes", { enumerable: true, get: function() {
962
- return encoding_utils_1.stringToBytes;
963
- } });
964
- Object.defineProperty(exports, "isZeroBytes32", { enumerable: true, get: function() {
965
- return encoding_utils_1.isZeroBytes32;
966
- } });
967
- var escrow_domain_1 = require_escrow_domain();
968
- Object.defineProperty(exports, "escrowDomainPrefixBytes", { enumerable: true, get: function() {
969
- return escrow_domain_1.escrowDomainPrefixBytes;
970
- } });
971
- var errors_1 = require_errors();
972
- Object.defineProperty(exports, "EncodingError", { enumerable: true, get: function() {
973
- return errors_1.EncodingError;
974
- } });
975
- Object.defineProperty(exports, "ZeroPaymentIdError", { enumerable: true, get: function() {
976
- return errors_1.ZeroPaymentIdError;
977
- } });
978
- Object.defineProperty(exports, "ZeroDepositorError", { enumerable: true, get: function() {
979
- return errors_1.ZeroDepositorError;
980
- } });
981
- Object.defineProperty(exports, "ZeroMintError", { enumerable: true, get: function() {
982
- return errors_1.ZeroMintError;
983
- } });
984
- Object.defineProperty(exports, "ZeroAmountError", { enumerable: true, get: function() {
985
- return errors_1.ZeroAmountError;
986
- } });
987
- Object.defineProperty(exports, "ZeroReserverError", { enumerable: true, get: function() {
988
- return errors_1.ZeroReserverError;
989
- } });
990
- Object.defineProperty(exports, "ZeroReleaserError", { enumerable: true, get: function() {
991
- return errors_1.ZeroReleaserError;
992
- } });
993
- Object.defineProperty(exports, "ZeroRecipientError", { enumerable: true, get: function() {
994
- return errors_1.ZeroRecipientError;
995
- } });
996
- Object.defineProperty(exports, "ZeroDepositHashError", { enumerable: true, get: function() {
997
- return errors_1.ZeroDepositHashError;
998
- } });
999
- Object.defineProperty(exports, "InvalidPubkeyLengthError", { enumerable: true, get: function() {
1000
- return errors_1.InvalidPubkeyLengthError;
1001
- } });
1002
- Object.defineProperty(exports, "InvalidBase58Error", { enumerable: true, get: function() {
1003
- return errors_1.InvalidBase58Error;
1004
- } });
1005
- Object.defineProperty(exports, "InvalidHexError", { enumerable: true, get: function() {
1006
- return errors_1.InvalidHexError;
1007
- } });
1008
- var deposit_encoder_1 = require_deposit_encoder();
1009
- Object.defineProperty(exports, "computeDepositHash", { enumerable: true, get: function() {
1010
- return deposit_encoder_1.computeDepositHash;
1011
- } });
1012
- var reserve_encoder_1 = require_reserve_encoder();
1013
- Object.defineProperty(exports, "computeReserveHash", { enumerable: true, get: function() {
1014
- return reserve_encoder_1.computeReserveHash;
1015
- } });
1016
- var release_encoder_1 = require_release_encoder();
1017
- Object.defineProperty(exports, "computeReleaseHash", { enumerable: true, get: function() {
1018
- return release_encoder_1.computeReleaseHash;
1019
- } });
1020
- var refund_encoder_1 = require_refund_encoder();
1021
- Object.defineProperty(exports, "computeRefundHash", { enumerable: true, get: function() {
1022
- return refund_encoder_1.computeRefundHash;
1023
- } });
1024
- var nonce_generator_1 = require_nonce_generator();
1025
- Object.defineProperty(exports, "generateNonce", { enumerable: true, get: function() {
1026
- return nonce_generator_1.generateNonce;
1027
- } });
1028
- Object.defineProperty(exports, "REPLAY_SLOTS", { enumerable: true, get: function() {
1029
- return nonce_generator_1.REPLAY_SLOTS;
1030
- } });
1031
- Object.defineProperty(exports, "MAX_VALID_SLOT", { enumerable: true, get: function() {
1032
- return nonce_generator_1.MAX_VALID_SLOT;
1033
- } });
1034
- }
1035
- });
1036
-
1037
- // src/server.ts
1038
- var import_evm_escrow_encoding = __toESM(require_dist(), 1);
1039
- var import_tvm_escrow_encoding = __toESM(require_dist3(), 1);
1040
- var import_solana_escrow_encoding = __toESM(require_dist4(), 1);
1041
- var import_payment_gateway_client = __toESM(require_dist2(), 1);
1042
- import nacl from "tweetnacl";
1043
- import bs58 from "bs58";
1044
- import { verifyTypedData, recoverAddress, getBytes, hexlify } from "ethers";
1045
- import { Method } from "mppx";
1046
- var DEADLINE_SKEW_TOLERANCE_MS = 6e4;
1047
- var SOLANA_MAX_FULFILLMENT_DEADLINE_SECONDS = import_payment_gateway_client.REPLAY_HORIZON_SECS - 10;
1048
- function registerServer(config) {
1049
- const now = config.now ?? (() => Date.now());
1050
- return Method.toServer(atumEscrowChargeMethod, {
1051
- async verify({ credential, request }) {
1052
- const pr = credential.payload.paymentRequest;
1053
- const { source, extra } = request;
1054
- const namespace = namespaceOf(source.network);
1055
- const senderAuth = pr.sender_auth;
1056
- if (!senderAuth || senderAuth.signed_messages.length === 0) {
1057
- throw new Error("atum-escrow: credential is missing sender_auth");
1058
- }
1059
- const signed = senderAuth.signed_messages[0];
1060
- if (!signed.message_prehash) {
1061
- throw new Error("atum-escrow: sender_auth is missing message_prehash");
1062
- }
1063
- if (!pr.source) {
1064
- throw new Error("atum-escrow: credential is missing a source");
1065
- }
1066
- const authTerms = verifySenderAuth(
1067
- namespace,
1068
- signed,
1069
- { network: source.network, asset: source.asset, account: pr.source.account },
1070
- extra
1071
- );
1072
- const cap = BigInt(source.amount);
1073
- const maxSource = BigInt(pr.max_source_amount ?? "0");
1074
- if (maxSource > cap) {
1075
- throw new Error("atum-escrow: max_source_amount exceeds the source cap");
1076
- }
1077
- if (BigInt(authTerms.amount) !== maxSource) {
1078
- throw new Error("atum-escrow: permit amount does not match max_source_amount");
1079
- }
1080
- const dest = pr.destination?.[0];
1081
- if (!dest) {
1082
- throw new Error("atum-escrow: credential is missing a destination");
1083
- }
1084
- if (!sameAddress(dest.account, extra.destination.account)) {
1085
- throw new Error("atum-escrow: destination account does not match the challenge");
1086
- }
1087
- const expectedDestAsset = assetIdentifier(extra.destination.network, extra.destination.asset);
1088
- const destAssetMatches = namespaceOf(extra.destination.network) === "solana" ? dest.asset_identifier === expectedDestAsset : dest.asset_identifier.toLowerCase() === expectedDestAsset.toLowerCase();
1089
- if (!destAssetMatches) {
1090
- throw new Error("atum-escrow: destination asset does not match the challenge");
1091
- }
1092
- if (pr.fulfillment_amount !== extra.fulfillmentAmount) {
1093
- throw new Error("atum-escrow: fulfillment_amount does not match the challenge");
1094
- }
1095
- const overrides = contractOverridesFromExtra(source.network, extra);
1096
- const expectedQuoteSelector = overrides?.quote_selector ?? extra.reserver;
1097
- const expectedVerifier = overrides?.fulfillment_verifier ?? {
1098
- account: extra.releaser,
1099
- endpoint: extra.fulfillmentVerifierEndpoint
1100
- };
1101
- if (!sameAddress(pr.escrow_contract_address ?? "", extra.escrow)) {
1102
- throw new Error("atum-escrow: escrow_contract_address does not match the challenge");
1103
- }
1104
- if (!sameAddress(pr.quote_selector ?? "", expectedQuoteSelector)) {
1105
- throw new Error("atum-escrow: quote_selector does not match the challenge reserver");
1106
- }
1107
- if (!sameAddress(pr.fulfillment_proxy ?? "", extra.fulfillmentProxy)) {
1108
- throw new Error("atum-escrow: fulfillment_proxy does not match the challenge");
1109
- }
1110
- if (!sameAddress(pr.fulfillment_verifier?.account ?? "", expectedVerifier.account)) {
1111
- throw new Error("atum-escrow: fulfillment_verifier.account does not match the challenge releaser");
1112
- }
1113
- if ((pr.fulfillment_verifier?.endpoint ?? "") !== expectedVerifier.endpoint) {
1114
- throw new Error("atum-escrow: fulfillment_verifier.endpoint does not match the challenge");
1115
- }
1116
- const nowMs = now();
1117
- const quote = Date.parse(pr.quote_deadline);
1118
- const fulfillment = Date.parse(pr.fulfillment_deadline);
1119
- if (!(nowMs < quote && quote < fulfillment)) {
1120
- throw new Error(
1121
- "atum-escrow: deadline ordering violated (now < quote_deadline < fulfillment_deadline)"
1122
- );
1123
- }
1124
- if (quote > nowMs + extra.quoteDeadlineSeconds * 1e3 + DEADLINE_SKEW_TOLERANCE_MS) {
1125
- throw new Error("atum-escrow: quote_deadline exceeds the advertised budget");
1126
- }
1127
- if (fulfillment > nowMs + extra.fulfillmentDeadlineSeconds * 1e3 + DEADLINE_SKEW_TOLERANCE_MS) {
1128
- throw new Error("atum-escrow: fulfillment_deadline exceeds the advertised budget");
1129
- }
1130
- if (namespace !== "solana" && authTerms.deadlineSec * 1e3 < fulfillment) {
1131
- throw new Error("atum-escrow: permit deadline expires before fulfillment_deadline");
1132
- }
1133
- const result = await config.submitter.submit(pr);
1134
- const fc = result.fulfillment_confirmation;
1135
- if (!fc) {
1136
- throw new Error(
1137
- "atum-escrow: settlement did not complete within the synchronous window (no FulfillmentConfirmation)"
1138
- );
1139
- }
1140
- return {
1141
- method: METHOD_NAME,
1142
- status: "success",
1143
- timestamp: fc.fulfillment_timestamp ?? new Date(nowMs).toISOString(),
1144
- reference: fc.destination_tx_hash,
1145
- fulfillmentConfirmation: fc
1146
- };
1147
- }
1148
- });
1149
- }
1150
- function verifySenderAuth(namespace, signed, source, extra) {
1151
- switch (namespace) {
1152
- case "eip155":
1153
- return verifyEvmSenderAuth(signed, source, extra);
1154
- case "tron":
1155
- return verifyTronSenderAuth(signed, source, extra);
1156
- case "solana":
1157
- return verifySolanaSenderAuth(signed, source, extra);
1158
- default:
1159
- throw new Error(`atum-escrow: unsupported source chain namespace '${namespace}'`);
1160
- }
1161
- }
1162
- function verifyEvmSenderAuth(signed, source, extra) {
1163
- const msg = JSON.parse(signed.message_prehash).message;
1164
- const canonical = (0, import_evm_escrow_encoding.createPermitWitnessTransferFromPrehash)({
1165
- chainId: evmChainId(source.network),
1166
- verifyingContract: import_evm_escrow_encoding.PERMIT2_CONTRACT_ADDRESS,
1167
- token: msg.permitted.token,
1168
- amount: msg.permitted.amount,
1169
- spender: msg.spender,
1170
- nonce: BigInt(msg.nonce),
1171
- deadline: BigInt(msg.deadline),
1172
- reserver: msg.witness.reserver,
1173
- releaser: msg.witness.releaser
1174
- });
1175
- let recovered;
1176
- try {
1177
- recovered = verifyTypedData(
1178
- canonical.domain,
1179
- canonical.types,
1180
- canonical.message,
1181
- signed.signature
1182
- );
1183
- } catch {
1184
- throw new Error("atum-escrow: deposit signature does not recover to source.account");
1185
- }
1186
- if (!sameAddress(recovered, source.account)) {
1187
- throw new Error("atum-escrow: deposit signature does not recover to source.account");
1188
- }
1189
- checkPermitTerms(msg, source.asset, extra.escrow, extra.reserver, extra.releaser, (a) => a);
1190
- return { amount: msg.permitted.amount, deadlineSec: Number(msg.deadline) };
1191
- }
1192
- function verifyTronSenderAuth(signed, source, extra) {
1193
- const msg = JSON.parse(signed.message_prehash).message;
1194
- const canonical = (0, import_tvm_escrow_encoding.createTvmPermitWitnessTransferFromPrehash)({
1195
- chainId: tronNumericChainId(source.network),
1196
- permit2Address: resolveTronPermit2(source.network, extra.permit2),
1197
- tokenAddress: msg.permitted.token,
1198
- amount: msg.permitted.amount,
1199
- spenderAddress: msg.spender,
1200
- nonce: BigInt(msg.nonce),
1201
- deadline: BigInt(msg.deadline),
1202
- reserverAddress: msg.witness.reserver,
1203
- releaserAddress: msg.witness.releaser
1204
- });
1205
- const digest = (0, import_tvm_escrow_encoding.hashTvmPermitWitnessTransferFrom)(canonical);
1206
- let recovered;
1207
- try {
1208
- recovered = recoverAddress(digest, signed.signature);
1209
- } catch {
1210
- throw new Error("atum-escrow: deposit signature does not recover to source.account");
1211
- }
1212
- if (!sameAddress(recovered, (0, import_tvm_escrow_encoding.normalizeAddress)(source.account))) {
1213
- throw new Error("atum-escrow: deposit signature does not recover to source.account");
1214
- }
1215
- checkPermitTerms(msg, source.asset, extra.escrow, extra.reserver, extra.releaser, import_tvm_escrow_encoding.normalizeAddress);
1216
- return { amount: msg.permitted.amount, deadlineSec: Number(msg.deadline) };
1217
- }
1218
- function checkPermitTerms(msg, sourceAsset, escrow, reserver, releaser, normalize) {
1219
- if (!sameAddress(msg.spender, normalize(escrow))) {
1220
- throw new Error("atum-escrow: permit spender is not the source escrow");
1221
- }
1222
- if (!sameAddress(msg.permitted.token, normalize(sourceAsset))) {
1223
- throw new Error("atum-escrow: permit token does not match the source asset");
1224
- }
1225
- if (!sameAddress(msg.witness.reserver, normalize(reserver)) || !sameAddress(msg.witness.releaser, normalize(releaser))) {
1226
- throw new Error("atum-escrow: deposit witness roles do not match the challenge");
1227
- }
1228
- }
1229
- function verifySolanaSenderAuth(signed, source, extra) {
1230
- if (!extra.svmSignatureClusterId || extra.svmSignatureDomainVersion == null) {
1231
- throw new Error(
1232
- "atum-escrow: Solana source requires svmSignatureClusterId and svmSignatureDomainVersion in the challenge"
1233
- );
1234
- }
1235
- const prehash = JSON.parse(signed.message_prehash);
1236
- const domain = {
1237
- clusterId: clusterIdFromName(extra.svmSignatureClusterId),
1238
- signatureDomainVersion: extra.svmSignatureDomainVersion,
1239
- programId: import_solana_escrow_encoding.Pubkey.fromBase58(extra.escrow)
1240
- };
1241
- const canonicalHash = hexlify(
1242
- (0, import_solana_escrow_encoding.computeDepositHash)(
1243
- {
1244
- paymentId: getBytes(prehash.payment_id),
1245
- depositor: import_solana_escrow_encoding.Pubkey.fromBase58(prehash.depositor),
1246
- mint: import_solana_escrow_encoding.Pubkey.fromBase58(prehash.mint),
1247
- amount: BigInt(prehash.amount),
1248
- reserver: import_solana_escrow_encoding.Pubkey.fromBase58(prehash.reserver),
1249
- releaser: import_solana_escrow_encoding.Pubkey.fromBase58(prehash.releaser),
1250
- nonce: BigInt(prehash.nonce),
1251
- issuedAt: BigInt(prehash.issued_at),
1252
- deadline: BigInt(prehash.deadline)
1253
- },
1254
- domain
1255
- )
1256
- );
1257
- if (canonicalHash.toLowerCase() !== signed.message.toLowerCase()) {
1258
- throw new Error("atum-escrow: deposit hash does not match the signed message");
1259
- }
1260
- const delegateSigner = signed.payload?.delegate_signer;
1261
- if (!delegateSigner) {
1262
- throw new Error("atum-escrow: Solana credential is missing delegate_signer");
1263
- }
1264
- let verified = false;
1265
- try {
1266
- verified = verifyEd25519(
1267
- getBytes(signed.message),
1268
- getBytes(signed.signature),
1269
- base58Decode(delegateSigner)
1270
- );
1271
- } catch {
1272
- verified = false;
1273
- }
1274
- if (!verified || delegateSigner !== source.account || prehash.depositor !== source.account) {
1275
- throw new Error("atum-escrow: deposit signature does not recover to source.account");
1276
- }
1277
- if (!sameAddress(prehash.mint, source.asset)) {
1278
- throw new Error("atum-escrow: permit token does not match the source asset");
1279
- }
1280
- if (!sameAddress(prehash.reserver, extra.reserver) || !sameAddress(prehash.releaser, extra.releaser)) {
1281
- throw new Error("atum-escrow: deposit witness roles do not match the challenge");
1282
- }
1283
- return { amount: prehash.amount, deadlineSec: Number(prehash.deadline) };
1284
- }
1285
- function verifyEd25519(message, signature, publicKey) {
1286
- return nacl.sign.detached.verify(message, signature, publicKey);
1287
- }
1288
- function base58Decode(value) {
1289
- return bs58.decode(value);
1290
- }
1291
- function applyMarkupBps(amount, bps) {
1292
- return (BigInt(amount) * BigInt(1e4 + bps) / 10000n).toString();
1293
- }
1294
- function validateCorridor(corridor) {
1295
- if (!Number.isFinite(corridor.quoteDeadlineSeconds) || corridor.quoteDeadlineSeconds <= 0) {
1296
- throw new Error("atum-escrow: quoteDeadlineSeconds must be a positive number of seconds");
1297
- }
1298
- if (!Number.isFinite(corridor.fulfillmentDeadlineSeconds) || corridor.fulfillmentDeadlineSeconds <= 0) {
1299
- throw new Error("atum-escrow: fulfillmentDeadlineSeconds must be a positive number of seconds");
1300
- }
1301
- if (corridor.quoteDeadlineSeconds >= corridor.fulfillmentDeadlineSeconds) {
1302
- throw new Error(
1303
- "atum-escrow: quoteDeadlineSeconds must be strictly less than fulfillmentDeadlineSeconds"
1304
- );
1305
- }
1306
- if (!Number.isFinite(corridor.markupBps) || corridor.markupBps < 0) {
1307
- throw new Error("atum-escrow: markupBps must be a non-negative number of basis points");
1308
- }
1309
- if (!corridor.sources || corridor.sources.length === 0) {
1310
- throw new Error("atum-escrow: corridor must configure at least one source");
1311
- }
1312
- for (const src of corridor.sources) {
1313
- for (const field of ["network", "escrow", "reserver", "releaser", "fulfillmentVerifierEndpoint"]) {
1314
- if (!src[field]) {
1315
- throw new Error(`atum-escrow: source ${src.network ?? "?"} is missing '${field}'`);
1316
- }
1317
- }
1318
- if (!src.assets || src.assets.length === 0 || src.assets.some((a) => !a)) {
1319
- throw new Error(`atum-escrow: source ${src.network} must list at least one non-empty asset in 'assets'`);
1320
- }
1321
- if (namespaceOf(src.network) === "tron") {
1322
- resolveTronPermit2(src.network, src.permit2);
1323
- }
1324
- if (namespaceOf(src.network) === "solana") {
1325
- if (!src.svmSignatureClusterId || src.svmSignatureDomainVersion == null) {
1326
- throw new Error(
1327
- `atum-escrow: Solana source ${src.network} requires svmSignatureClusterId and svmSignatureDomainVersion`
1328
- );
1329
- }
1330
- if (corridor.fulfillmentDeadlineSeconds > SOLANA_MAX_FULFILLMENT_DEADLINE_SECONDS) {
1331
- throw new Error(
1332
- `atum-escrow: a corridor with a Solana source must set fulfillmentDeadlineSeconds <= ${SOLANA_MAX_FULFILLMENT_DEADLINE_SECONDS} (Solana deposits expire within the escrow replay window); got ${corridor.fulfillmentDeadlineSeconds}`
1333
- );
1334
- }
1335
- }
1336
- }
1337
- }
1338
- function buildChargeRequest(corridor, select, fulfillmentAmount) {
1339
- validateCorridor(corridor);
1340
- const src = corridor.sources.find(
1341
- (s) => s.network === select.network && s.assets.some((a) => sameAddress(a, select.asset))
1342
- );
1343
- if (!src) {
1344
- throw new Error(
1345
- `atum-escrow: no source option configured for ${select.network} / ${select.asset}`
1346
- );
1347
- }
1348
- const selectedAsset = src.assets.find((a) => sameAddress(a, select.asset));
1349
- return {
1350
- source: {
1351
- network: src.network,
1352
- asset: selectedAsset,
1353
- amount: applyMarkupBps(fulfillmentAmount, corridor.markupBps)
1354
- },
1355
- extra: {
1356
- destination: corridor.destination,
1357
- fulfillmentAmount,
1358
- escrow: src.escrow,
1359
- fulfillmentProxy: corridor.fulfillmentProxy,
1360
- reserver: src.reserver,
1361
- releaser: src.releaser,
1362
- fulfillmentVerifierEndpoint: src.fulfillmentVerifierEndpoint,
1363
- quoteDeadlineSeconds: corridor.quoteDeadlineSeconds,
1364
- fulfillmentDeadlineSeconds: corridor.fulfillmentDeadlineSeconds,
1365
- ...src.permit2 ? { permit2: src.permit2 } : {},
1366
- ...src.svmSignatureClusterId ? { svmSignatureClusterId: src.svmSignatureClusterId } : {},
1367
- ...src.svmSignatureDomainVersion != null ? { svmSignatureDomainVersion: src.svmSignatureDomainVersion } : {}
1368
- }
1369
- };
1370
- }
1371
- async function corridorFromDefaults(defaults, params) {
1372
- const [destDefaults, ...sourceDefaults] = await Promise.all([
1373
- defaults.fetchChainDefaults(params.destination.network),
1374
- ...params.sources.map((s) => defaults.fetchChainDefaults(s.network))
1375
- ]);
1376
- const sources = params.sources.map((s, i) => {
1377
- const d = sourceDefaults[i];
1378
- return {
1379
- network: s.network,
1380
- assets: s.assets,
1381
- escrow: d.escrowContract,
1382
- reserver: d.quoteSelector,
1383
- releaser: d.fulfillmentVerifierAccount,
1384
- fulfillmentVerifierEndpoint: d.fulfillmentVerifierEndpoint,
1385
- ...d.permit2Contract ? { permit2: d.permit2Contract } : {},
1386
- ...d.svmSignatureClusterId ? { svmSignatureClusterId: d.svmSignatureClusterId } : {},
1387
- ...d.svmSignatureDomainVersion != null ? { svmSignatureDomainVersion: d.svmSignatureDomainVersion } : {}
1388
- };
1389
- });
1390
- return {
1391
- destination: params.destination,
1392
- fulfillmentProxy: destDefaults.fulfillmentProxy,
1393
- markupBps: params.markupBps,
1394
- quoteDeadlineSeconds: params.quoteDeadlineSeconds,
1395
- fulfillmentDeadlineSeconds: params.fulfillmentDeadlineSeconds,
1396
- sources
1397
- };
1398
- }
1399
-
1400
- export {
1401
- registerServer,
1402
- validateCorridor,
1403
- buildChargeRequest,
1404
- corridorFromDefaults
1405
- };
1406
- /*! Bundled license information:
1407
-
1408
- @noble/hashes/utils.js:
1409
- (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
1410
- */