@atumlabs/mppx-atum-escrow 0.1.1 → 0.3.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 +50 -0
- package/README.md +212 -47
- package/dist/chunk-4YD6566T.js +371 -0
- package/dist/chunk-Z3AUNEU5.js +2645 -0
- package/dist/{chunk-2MWWLU75.js → chunk-ZFA5SSUP.js} +1691 -1653
- package/dist/client.d.ts +21 -16
- package/dist/client.js +4 -2
- package/dist/index.d.ts +19 -18
- package/dist/index.js +19 -3
- package/dist/internal-9tB7y-A7.d.ts +365 -0
- package/dist/server.d.ts +234 -17
- package/dist/server.js +18 -2
- package/package.json +7 -4
- package/dist/chunk-L62WG2VU.js +0 -131
- package/dist/chunk-W6D2D767.js +0 -1410
- package/dist/internal-CjcEyEsm.d.ts +0 -842
|
@@ -1,487 +1,21 @@
|
|
|
1
1
|
import { createRequire as __atumCreateRequire } from 'module'; const require = __atumCreateRequire(import.meta.url);
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
};
|
|
20
|
-
var __export = (target, all) => {
|
|
21
|
-
for (var name in all)
|
|
22
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
23
|
-
};
|
|
24
|
-
var __copyProps = (to, from, except, desc) => {
|
|
25
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
26
|
-
for (let key of __getOwnPropNames(from))
|
|
27
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
28
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
29
|
-
}
|
|
30
|
-
return to;
|
|
31
|
-
};
|
|
32
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
33
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
34
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
35
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
36
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
37
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
38
|
-
mod
|
|
39
|
-
));
|
|
40
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
41
|
-
|
|
42
|
-
// ../contracts/evm/escrow-encoding/typescript/dist/payment-id.js
|
|
43
|
-
var require_payment_id = __commonJS({
|
|
44
|
-
"../contracts/evm/escrow-encoding/typescript/dist/payment-id.js"(exports) {
|
|
45
|
-
"use strict";
|
|
46
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
47
|
-
exports.computePaymentId = computePaymentId;
|
|
48
|
-
exports.computePaymentIdV2 = computePaymentIdV2;
|
|
49
|
-
var ethers_1 = __require("ethers");
|
|
50
|
-
function computePaymentId(depositor, signature) {
|
|
51
|
-
const abiCoder = ethers_1.ethers.AbiCoder.defaultAbiCoder();
|
|
52
|
-
const encoded = abiCoder.encode(["address", "bytes"], [depositor, signature]);
|
|
53
|
-
return ethers_1.ethers.keccak256(encoded);
|
|
54
|
-
}
|
|
55
|
-
function computePaymentIdV2(depositor, signature, nonce) {
|
|
56
|
-
const abiCoder = ethers_1.ethers.AbiCoder.defaultAbiCoder();
|
|
57
|
-
const encoded = abiCoder.encode(["address", "bytes", "uint256"], [depositor, signature, nonce]);
|
|
58
|
-
return ethers_1.ethers.keccak256(encoded);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
// ../contracts/evm/escrow-encoding/typescript/dist/nonce-generator.js
|
|
64
|
-
var require_nonce_generator = __commonJS({
|
|
65
|
-
"../contracts/evm/escrow-encoding/typescript/dist/nonce-generator.js"(exports) {
|
|
66
|
-
"use strict";
|
|
67
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
68
|
-
exports.generateNonce = generateNonce;
|
|
69
|
-
var ethers_1 = __require("ethers");
|
|
70
|
-
function generateNonce() {
|
|
71
|
-
return ethers_1.ethers.hexlify(ethers_1.ethers.randomBytes(32));
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
// ../contracts/evm/escrow-encoding/typescript/dist/permit-types.js
|
|
77
|
-
var require_permit_types = __commonJS({
|
|
78
|
-
"../contracts/evm/escrow-encoding/typescript/dist/permit-types.js"(exports) {
|
|
79
|
-
"use strict";
|
|
80
|
-
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;
|
|
82
|
-
exports.createPermit2Domain = createPermit2Domain;
|
|
83
|
-
exports.createEscrowDomain = createEscrowDomain;
|
|
84
|
-
exports.PERMIT_WITNESS_TYPES = {
|
|
85
|
-
PermitWitnessTransferFrom: [
|
|
86
|
-
{ name: "permitted", type: "TokenPermissions" },
|
|
87
|
-
{ name: "spender", type: "address" },
|
|
88
|
-
{ name: "nonce", type: "uint256" },
|
|
89
|
-
{ name: "deadline", type: "uint256" },
|
|
90
|
-
{ name: "witness", type: "DepositWitness" }
|
|
91
|
-
],
|
|
92
|
-
TokenPermissions: [
|
|
93
|
-
{ name: "token", type: "address" },
|
|
94
|
-
{ name: "amount", type: "uint256" }
|
|
95
|
-
],
|
|
96
|
-
DepositWitness: [
|
|
97
|
-
{ name: "requestId", type: "bytes32" },
|
|
98
|
-
{ name: "reserver", type: "address" },
|
|
99
|
-
{ name: "releaser", type: "address" }
|
|
100
|
-
]
|
|
101
|
-
};
|
|
102
|
-
exports.PERMIT_WITNESS_TYPES_V2 = {
|
|
103
|
-
PermitWitnessTransferFrom: [
|
|
104
|
-
{ name: "permitted", type: "TokenPermissions" },
|
|
105
|
-
{ name: "spender", type: "address" },
|
|
106
|
-
{ name: "nonce", type: "uint256" },
|
|
107
|
-
{ name: "deadline", type: "uint256" },
|
|
108
|
-
{ name: "witness", type: "DepositWitness" }
|
|
109
|
-
],
|
|
110
|
-
TokenPermissions: [
|
|
111
|
-
{ name: "token", type: "address" },
|
|
112
|
-
{ name: "amount", type: "uint256" }
|
|
113
|
-
],
|
|
114
|
-
DepositWitness: [
|
|
115
|
-
{ name: "reserver", type: "address" },
|
|
116
|
-
{ name: "releaser", type: "address" }
|
|
117
|
-
]
|
|
118
|
-
};
|
|
119
|
-
function createPermit2Domain(chainId, verifyingContract) {
|
|
120
|
-
return {
|
|
121
|
-
name: "Permit2",
|
|
122
|
-
chainId,
|
|
123
|
-
verifyingContract
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
function createEscrowDomain(chainId, verifyingContract) {
|
|
127
|
-
return {
|
|
128
|
-
name: "Escrow",
|
|
129
|
-
version: "3",
|
|
130
|
-
chainId,
|
|
131
|
-
verifyingContract
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
exports.RESERVE_WITNESS_TYPES = {
|
|
135
|
-
ReserveWitness: [
|
|
136
|
-
{ name: "paymentId", type: "bytes32" },
|
|
137
|
-
{ name: "settler", type: "address" }
|
|
138
|
-
]
|
|
139
|
-
};
|
|
140
|
-
exports.RELEASE_WITNESS_TYPES = {
|
|
141
|
-
ReleaseWitness: [
|
|
142
|
-
{ name: "paymentId", type: "bytes32" },
|
|
143
|
-
{ name: "depositor", type: "address" },
|
|
144
|
-
{ name: "token", type: "address" },
|
|
145
|
-
{ name: "amount", type: "uint256" },
|
|
146
|
-
{ name: "feeAmount", type: "uint256" },
|
|
147
|
-
{ name: "reserver", type: "address" },
|
|
148
|
-
{ name: "releaser", type: "address" },
|
|
149
|
-
{ name: "settler", type: "address" }
|
|
150
|
-
]
|
|
151
|
-
};
|
|
152
|
-
exports.REFUND_WITNESS_TYPES = {
|
|
153
|
-
RefundWitness: [
|
|
154
|
-
{ name: "paymentId", type: "bytes32" },
|
|
155
|
-
{ name: "depositor", type: "address" },
|
|
156
|
-
{ name: "token", type: "address" },
|
|
157
|
-
{ name: "amount", type: "uint256" },
|
|
158
|
-
{ name: "feeAmount", type: "uint256" },
|
|
159
|
-
{ name: "reserver", type: "address" },
|
|
160
|
-
{ name: "releaser", type: "address" },
|
|
161
|
-
{ name: "settler", type: "address" }
|
|
162
|
-
]
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
// ../contracts/evm/escrow-encoding/typescript/dist/escrow-abi.js
|
|
168
|
-
var require_escrow_abi = __commonJS({
|
|
169
|
-
"../contracts/evm/escrow-encoding/typescript/dist/escrow-abi.js"(exports) {
|
|
170
|
-
"use strict";
|
|
171
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
172
|
-
exports.ESCROW_V2_ABI_JSON = exports.ESCROW_V3_ABI_JSON = exports.ESCROW_ABI_JSON = exports.ESCROW_ABI = void 0;
|
|
173
|
-
exports.ESCROW_ABI = [
|
|
174
|
-
"function deposit((( address token, uint256 amount) permitted, uint256 nonce, uint256 deadline) permit, address depositor, (bytes32 requestId, address reserver, address releaser) witness, bytes signature) returns (bytes32)",
|
|
175
|
-
"function refund((bytes32 depositId, uint256 deadline) witness, bytes signature)",
|
|
176
|
-
"function getDepositInfo(bytes32 depositId) view returns ((address depositor, address token, uint256 amount, address reserver, address releaser, address settler))",
|
|
177
|
-
"function i_permit2() view returns (address)"
|
|
178
|
-
];
|
|
179
|
-
exports.ESCROW_ABI_JSON = [
|
|
180
|
-
{
|
|
181
|
-
type: "function",
|
|
182
|
-
name: "deposit",
|
|
183
|
-
inputs: [
|
|
184
|
-
{
|
|
185
|
-
name: "permit",
|
|
186
|
-
type: "tuple",
|
|
187
|
-
components: [
|
|
188
|
-
{
|
|
189
|
-
name: "permitted",
|
|
190
|
-
type: "tuple",
|
|
191
|
-
components: [
|
|
192
|
-
{ name: "token", type: "address" },
|
|
193
|
-
{ name: "amount", type: "uint256" }
|
|
194
|
-
]
|
|
195
|
-
},
|
|
196
|
-
{ name: "nonce", type: "uint256" },
|
|
197
|
-
{ name: "deadline", type: "uint256" }
|
|
198
|
-
]
|
|
199
|
-
},
|
|
200
|
-
{ name: "depositor", type: "address" },
|
|
201
|
-
{
|
|
202
|
-
name: "witness",
|
|
203
|
-
type: "tuple",
|
|
204
|
-
components: [
|
|
205
|
-
{ name: "requestId", type: "bytes32" },
|
|
206
|
-
{ name: "reserver", type: "address" },
|
|
207
|
-
{ name: "releaser", type: "address" }
|
|
208
|
-
]
|
|
209
|
-
},
|
|
210
|
-
{ name: "signature", type: "bytes" }
|
|
211
|
-
],
|
|
212
|
-
outputs: [{ name: "depositId", type: "bytes32" }],
|
|
213
|
-
stateMutability: "nonpayable"
|
|
214
|
-
},
|
|
215
|
-
{
|
|
216
|
-
type: "function",
|
|
217
|
-
name: "refund",
|
|
218
|
-
inputs: [
|
|
219
|
-
{
|
|
220
|
-
name: "witness",
|
|
221
|
-
type: "tuple",
|
|
222
|
-
components: [
|
|
223
|
-
{ name: "depositId", type: "bytes32" },
|
|
224
|
-
{ name: "deadline", type: "uint256" }
|
|
225
|
-
]
|
|
226
|
-
},
|
|
227
|
-
{ name: "signature", type: "bytes" }
|
|
228
|
-
],
|
|
229
|
-
outputs: [],
|
|
230
|
-
stateMutability: "nonpayable"
|
|
231
|
-
},
|
|
232
|
-
{
|
|
233
|
-
type: "function",
|
|
234
|
-
name: "getDepositInfo",
|
|
235
|
-
inputs: [{ name: "depositId", type: "bytes32" }],
|
|
236
|
-
outputs: [
|
|
237
|
-
{
|
|
238
|
-
name: "",
|
|
239
|
-
type: "tuple",
|
|
240
|
-
components: [
|
|
241
|
-
{ name: "depositor", type: "address" },
|
|
242
|
-
{ name: "token", type: "address" },
|
|
243
|
-
{ name: "amount", type: "uint256" },
|
|
244
|
-
{ name: "reserver", type: "address" },
|
|
245
|
-
{ name: "releaser", type: "address" },
|
|
246
|
-
{ name: "settler", type: "address" }
|
|
247
|
-
]
|
|
248
|
-
}
|
|
249
|
-
],
|
|
250
|
-
stateMutability: "view"
|
|
251
|
-
},
|
|
252
|
-
{
|
|
253
|
-
type: "function",
|
|
254
|
-
name: "i_permit2",
|
|
255
|
-
inputs: [],
|
|
256
|
-
outputs: [{ name: "", type: "address" }],
|
|
257
|
-
stateMutability: "view"
|
|
258
|
-
}
|
|
259
|
-
];
|
|
260
|
-
exports.ESCROW_V3_ABI_JSON = [
|
|
261
|
-
{
|
|
262
|
-
type: "function",
|
|
263
|
-
name: "deposit",
|
|
264
|
-
inputs: [
|
|
265
|
-
{
|
|
266
|
-
name: "depositInput",
|
|
267
|
-
type: "tuple",
|
|
268
|
-
components: [
|
|
269
|
-
{
|
|
270
|
-
name: "permit",
|
|
271
|
-
type: "tuple",
|
|
272
|
-
components: [
|
|
273
|
-
{
|
|
274
|
-
name: "permitted",
|
|
275
|
-
type: "tuple",
|
|
276
|
-
components: [
|
|
277
|
-
{ name: "token", type: "address" },
|
|
278
|
-
{ name: "amount", type: "uint256" }
|
|
279
|
-
]
|
|
280
|
-
},
|
|
281
|
-
{ name: "nonce", type: "uint256" },
|
|
282
|
-
{ name: "deadline", type: "uint256" }
|
|
283
|
-
]
|
|
284
|
-
},
|
|
285
|
-
{ name: "depositor", type: "address" },
|
|
286
|
-
{
|
|
287
|
-
name: "depositWitness",
|
|
288
|
-
type: "tuple",
|
|
289
|
-
components: [
|
|
290
|
-
{ name: "reserver", type: "address" },
|
|
291
|
-
{ name: "releaser", type: "address" }
|
|
292
|
-
]
|
|
293
|
-
},
|
|
294
|
-
{ name: "depositSignature", type: "bytes" },
|
|
295
|
-
{
|
|
296
|
-
name: "reserveWitness",
|
|
297
|
-
type: "tuple",
|
|
298
|
-
components: [
|
|
299
|
-
{ name: "paymentId", type: "bytes32" },
|
|
300
|
-
{ name: "settler", type: "address" }
|
|
301
|
-
]
|
|
302
|
-
},
|
|
303
|
-
{ name: "reserveSignature", type: "bytes" }
|
|
304
|
-
]
|
|
305
|
-
}
|
|
306
|
-
],
|
|
307
|
-
outputs: [{ name: "paymentId", type: "bytes32" }],
|
|
308
|
-
stateMutability: "nonpayable"
|
|
309
|
-
},
|
|
310
|
-
{
|
|
311
|
-
type: "function",
|
|
312
|
-
name: "refund",
|
|
313
|
-
inputs: [
|
|
314
|
-
{
|
|
315
|
-
name: "refundInput",
|
|
316
|
-
type: "tuple",
|
|
317
|
-
components: [
|
|
318
|
-
{
|
|
319
|
-
name: "refundWitness",
|
|
320
|
-
type: "tuple",
|
|
321
|
-
components: [
|
|
322
|
-
{ name: "paymentId", type: "bytes32" },
|
|
323
|
-
{ name: "depositor", type: "address" },
|
|
324
|
-
{ name: "token", type: "address" },
|
|
325
|
-
{ name: "amount", type: "uint256" },
|
|
326
|
-
{ name: "feeAmount", type: "uint256" },
|
|
327
|
-
{ name: "reserver", type: "address" },
|
|
328
|
-
{ name: "releaser", type: "address" },
|
|
329
|
-
{ name: "settler", type: "address" }
|
|
330
|
-
]
|
|
331
|
-
},
|
|
332
|
-
{ name: "refundSignature", type: "bytes" }
|
|
333
|
-
]
|
|
334
|
-
}
|
|
335
|
-
],
|
|
336
|
-
outputs: [],
|
|
337
|
-
stateMutability: "nonpayable"
|
|
338
|
-
},
|
|
339
|
-
{
|
|
340
|
-
type: "function",
|
|
341
|
-
name: "getDepositHash",
|
|
342
|
-
inputs: [{ name: "paymentId", type: "bytes32" }],
|
|
343
|
-
outputs: [{ name: "", type: "bytes32" }],
|
|
344
|
-
stateMutability: "view"
|
|
345
|
-
},
|
|
346
|
-
{
|
|
347
|
-
type: "function",
|
|
348
|
-
name: "i_permit2",
|
|
349
|
-
inputs: [],
|
|
350
|
-
outputs: [{ name: "", type: "address" }],
|
|
351
|
-
stateMutability: "view"
|
|
352
|
-
}
|
|
353
|
-
];
|
|
354
|
-
exports.ESCROW_V2_ABI_JSON = exports.ESCROW_V3_ABI_JSON;
|
|
355
|
-
}
|
|
356
|
-
});
|
|
357
|
-
|
|
358
|
-
// ../contracts/evm/escrow-encoding/typescript/dist/reserve-encoder.js
|
|
359
|
-
var require_reserve_encoder = __commonJS({
|
|
360
|
-
"../contracts/evm/escrow-encoding/typescript/dist/reserve-encoder.js"(exports) {
|
|
361
|
-
"use strict";
|
|
362
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
363
|
-
exports.computeReserveDigest = computeReserveDigest;
|
|
364
|
-
var ethers_1 = __require("ethers");
|
|
365
|
-
var permit_types_1 = require_permit_types();
|
|
366
|
-
function computeReserveDigest(input) {
|
|
367
|
-
const domain = (0, permit_types_1.createEscrowDomain)(input.chainId, input.escrowContract);
|
|
368
|
-
return ethers_1.TypedDataEncoder.hash(domain, permit_types_1.RESERVE_WITNESS_TYPES, {
|
|
369
|
-
paymentId: input.paymentId,
|
|
370
|
-
settler: input.settler
|
|
371
|
-
});
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
});
|
|
375
|
-
|
|
376
|
-
// ../contracts/evm/escrow-encoding/typescript/dist/deposit-encoder.js
|
|
377
|
-
var require_deposit_encoder = __commonJS({
|
|
378
|
-
"../contracts/evm/escrow-encoding/typescript/dist/deposit-encoder.js"(exports) {
|
|
379
|
-
"use strict";
|
|
380
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
381
|
-
exports.PERMIT2_CONTRACT_ADDRESS = void 0;
|
|
382
|
-
exports.createPermitWitnessTransferFromPrehash = createPermitWitnessTransferFromPrehash2;
|
|
383
|
-
exports.hashPermitWitnessTransferFrom = hashPermitWitnessTransferFrom2;
|
|
384
|
-
var ethers_1 = __require("ethers");
|
|
385
|
-
var permit_types_1 = require_permit_types();
|
|
386
|
-
exports.PERMIT2_CONTRACT_ADDRESS = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
|
|
387
|
-
function createPermitWitnessTransferFromPrehash2(params) {
|
|
388
|
-
return {
|
|
389
|
-
types: permit_types_1.PERMIT_WITNESS_TYPES_V2,
|
|
390
|
-
primaryType: "PermitWitnessTransferFrom",
|
|
391
|
-
domain: {
|
|
392
|
-
name: "Permit2",
|
|
393
|
-
chainId: `0x${params.chainId.toString(16)}`,
|
|
394
|
-
verifyingContract: params.verifyingContract
|
|
395
|
-
},
|
|
396
|
-
message: {
|
|
397
|
-
permitted: {
|
|
398
|
-
token: params.token,
|
|
399
|
-
amount: params.amount
|
|
400
|
-
},
|
|
401
|
-
spender: params.spender,
|
|
402
|
-
nonce: params.nonce.toString(),
|
|
403
|
-
deadline: params.deadline.toString(),
|
|
404
|
-
witness: {
|
|
405
|
-
reserver: params.reserver,
|
|
406
|
-
releaser: params.releaser
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
};
|
|
410
|
-
}
|
|
411
|
-
function hashPermitWitnessTransferFrom2(prehash) {
|
|
412
|
-
return ethers_1.TypedDataEncoder.hash(prehash.domain, prehash.types, prehash.message);
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
});
|
|
416
|
-
|
|
417
|
-
// ../contracts/evm/escrow-encoding/typescript/dist/index.js
|
|
418
|
-
var require_dist = __commonJS({
|
|
419
|
-
"../contracts/evm/escrow-encoding/typescript/dist/index.js"(exports) {
|
|
420
|
-
"use strict";
|
|
421
|
-
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;
|
|
423
|
-
var payment_id_1 = require_payment_id();
|
|
424
|
-
Object.defineProperty(exports, "computePaymentId", { enumerable: true, get: function() {
|
|
425
|
-
return payment_id_1.computePaymentId;
|
|
426
|
-
} });
|
|
427
|
-
Object.defineProperty(exports, "computePaymentIdV2", { enumerable: true, get: function() {
|
|
428
|
-
return payment_id_1.computePaymentIdV2;
|
|
429
|
-
} });
|
|
430
|
-
var nonce_generator_1 = require_nonce_generator();
|
|
431
|
-
Object.defineProperty(exports, "generateNonce", { enumerable: true, get: function() {
|
|
432
|
-
return nonce_generator_1.generateNonce;
|
|
433
|
-
} });
|
|
434
|
-
var permit_types_1 = require_permit_types();
|
|
435
|
-
Object.defineProperty(exports, "PERMIT_WITNESS_TYPES", { enumerable: true, get: function() {
|
|
436
|
-
return permit_types_1.PERMIT_WITNESS_TYPES;
|
|
437
|
-
} });
|
|
438
|
-
Object.defineProperty(exports, "PERMIT_WITNESS_TYPES_V2", { enumerable: true, get: function() {
|
|
439
|
-
return permit_types_1.PERMIT_WITNESS_TYPES_V2;
|
|
440
|
-
} });
|
|
441
|
-
Object.defineProperty(exports, "createPermit2Domain", { enumerable: true, get: function() {
|
|
442
|
-
return permit_types_1.createPermit2Domain;
|
|
443
|
-
} });
|
|
444
|
-
Object.defineProperty(exports, "createEscrowDomain", { enumerable: true, get: function() {
|
|
445
|
-
return permit_types_1.createEscrowDomain;
|
|
446
|
-
} });
|
|
447
|
-
Object.defineProperty(exports, "RESERVE_WITNESS_TYPES", { enumerable: true, get: function() {
|
|
448
|
-
return permit_types_1.RESERVE_WITNESS_TYPES;
|
|
449
|
-
} });
|
|
450
|
-
Object.defineProperty(exports, "RELEASE_WITNESS_TYPES", { enumerable: true, get: function() {
|
|
451
|
-
return permit_types_1.RELEASE_WITNESS_TYPES;
|
|
452
|
-
} });
|
|
453
|
-
Object.defineProperty(exports, "REFUND_WITNESS_TYPES", { enumerable: true, get: function() {
|
|
454
|
-
return permit_types_1.REFUND_WITNESS_TYPES;
|
|
455
|
-
} });
|
|
456
|
-
var escrow_abi_1 = require_escrow_abi();
|
|
457
|
-
Object.defineProperty(exports, "ESCROW_ABI", { enumerable: true, get: function() {
|
|
458
|
-
return escrow_abi_1.ESCROW_ABI;
|
|
459
|
-
} });
|
|
460
|
-
Object.defineProperty(exports, "ESCROW_ABI_JSON", { enumerable: true, get: function() {
|
|
461
|
-
return escrow_abi_1.ESCROW_ABI_JSON;
|
|
462
|
-
} });
|
|
463
|
-
Object.defineProperty(exports, "ESCROW_V2_ABI_JSON", { enumerable: true, get: function() {
|
|
464
|
-
return escrow_abi_1.ESCROW_V2_ABI_JSON;
|
|
465
|
-
} });
|
|
466
|
-
Object.defineProperty(exports, "ESCROW_V3_ABI_JSON", { enumerable: true, get: function() {
|
|
467
|
-
return escrow_abi_1.ESCROW_V3_ABI_JSON;
|
|
468
|
-
} });
|
|
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
|
-
});
|
|
2
|
+
import {
|
|
3
|
+
INTENT_ID_META_KEY,
|
|
4
|
+
__commonJS,
|
|
5
|
+
__esm,
|
|
6
|
+
__export,
|
|
7
|
+
__require,
|
|
8
|
+
__toCommonJS,
|
|
9
|
+
__toESM,
|
|
10
|
+
assetIdentifier,
|
|
11
|
+
atumEscrowChargeMethod,
|
|
12
|
+
chainDefaultsFromExtra,
|
|
13
|
+
chargeRequestId,
|
|
14
|
+
intentIdOf,
|
|
15
|
+
namespaceOf,
|
|
16
|
+
require_dist,
|
|
17
|
+
require_dist2
|
|
18
|
+
} from "./chunk-Z3AUNEU5.js";
|
|
485
19
|
|
|
486
20
|
// ../node_modules/.pnpm/delayed-stream@1.0.0/node_modules/delayed-stream/lib/delayed_stream.js
|
|
487
21
|
var require_delayed_stream = __commonJS({
|
|
@@ -9714,11 +9248,11 @@ var require_sign = __commonJS({
|
|
|
9714
9248
|
"../node_modules/.pnpm/math-intrinsics@1.1.0/node_modules/math-intrinsics/sign.js"(exports, module) {
|
|
9715
9249
|
"use strict";
|
|
9716
9250
|
var $isNaN = require_isNaN();
|
|
9717
|
-
module.exports = function sign(
|
|
9718
|
-
if ($isNaN(
|
|
9719
|
-
return
|
|
9251
|
+
module.exports = function sign(number) {
|
|
9252
|
+
if ($isNaN(number) || number === 0) {
|
|
9253
|
+
return number;
|
|
9720
9254
|
}
|
|
9721
|
-
return
|
|
9255
|
+
return number < 0 ? -1 : 1;
|
|
9722
9256
|
};
|
|
9723
9257
|
}
|
|
9724
9258
|
});
|
|
@@ -10289,17 +9823,17 @@ var require_get_intrinsic = __commonJS({
|
|
|
10289
9823
|
var $exec = bind.call($call, RegExp.prototype.exec);
|
|
10290
9824
|
var rePropName = /[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g;
|
|
10291
9825
|
var reEscapeChar = /\\(\\)?/g;
|
|
10292
|
-
var stringToPath = function stringToPath2(
|
|
10293
|
-
var first = $strSlice(
|
|
10294
|
-
var last = $strSlice(
|
|
9826
|
+
var stringToPath = function stringToPath2(string) {
|
|
9827
|
+
var first = $strSlice(string, 0, 1);
|
|
9828
|
+
var last = $strSlice(string, -1);
|
|
10295
9829
|
if (first === "%" && last !== "%") {
|
|
10296
9830
|
throw new $SyntaxError("invalid intrinsic syntax, expected closing `%`");
|
|
10297
9831
|
} else if (last === "%" && first !== "%") {
|
|
10298
9832
|
throw new $SyntaxError("invalid intrinsic syntax, expected opening `%`");
|
|
10299
9833
|
}
|
|
10300
9834
|
var result = [];
|
|
10301
|
-
$replace(
|
|
10302
|
-
result[result.length] = quote ? $replace(subString, reEscapeChar, "$1") :
|
|
9835
|
+
$replace(string, rePropName, function(match, number, quote, subString) {
|
|
9836
|
+
result[result.length] = quote ? $replace(subString, reEscapeChar, "$1") : number || match;
|
|
10303
9837
|
});
|
|
10304
9838
|
return result;
|
|
10305
9839
|
};
|
|
@@ -10411,22 +9945,22 @@ var require_es_set_tostringtag = __commonJS({
|
|
|
10411
9945
|
var hasOwn = require_hasown();
|
|
10412
9946
|
var $TypeError = require_type();
|
|
10413
9947
|
var toStringTag = hasToStringTag ? Symbol.toStringTag : null;
|
|
10414
|
-
module.exports = function setToStringTag(
|
|
9948
|
+
module.exports = function setToStringTag(object, value) {
|
|
10415
9949
|
var overrideIfSet = arguments.length > 2 && !!arguments[2] && arguments[2].force;
|
|
10416
9950
|
var nonConfigurable = arguments.length > 2 && !!arguments[2] && arguments[2].nonConfigurable;
|
|
10417
9951
|
if (typeof overrideIfSet !== "undefined" && typeof overrideIfSet !== "boolean" || typeof nonConfigurable !== "undefined" && typeof nonConfigurable !== "boolean") {
|
|
10418
9952
|
throw new $TypeError("if provided, the `overrideIfSet` and `nonConfigurable` options must be booleans");
|
|
10419
9953
|
}
|
|
10420
|
-
if (toStringTag && (overrideIfSet || !hasOwn(
|
|
9954
|
+
if (toStringTag && (overrideIfSet || !hasOwn(object, toStringTag))) {
|
|
10421
9955
|
if ($defineProperty) {
|
|
10422
|
-
$defineProperty(
|
|
9956
|
+
$defineProperty(object, toStringTag, {
|
|
10423
9957
|
configurable: !nonConfigurable,
|
|
10424
9958
|
enumerable: false,
|
|
10425
9959
|
value,
|
|
10426
9960
|
writable: false
|
|
10427
9961
|
});
|
|
10428
9962
|
} else {
|
|
10429
|
-
|
|
9963
|
+
object[toStringTag] = value;
|
|
10430
9964
|
}
|
|
10431
9965
|
}
|
|
10432
9966
|
};
|
|
@@ -15655,107 +15189,475 @@ var require_axios = __commonJS({
|
|
|
15655
15189
|
});
|
|
15656
15190
|
|
|
15657
15191
|
// ../payment-gateway-client/dist/index.js
|
|
15658
|
-
var
|
|
15192
|
+
var require_dist3 = __commonJS({
|
|
15659
15193
|
"../payment-gateway-client/dist/index.js"(exports, module) {
|
|
15660
15194
|
"use strict";
|
|
15661
|
-
var
|
|
15662
|
-
var
|
|
15663
|
-
var
|
|
15664
|
-
var
|
|
15665
|
-
var
|
|
15666
|
-
var
|
|
15195
|
+
var __create = Object.create;
|
|
15196
|
+
var __defProp = Object.defineProperty;
|
|
15197
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
15198
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
15199
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
15200
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
15667
15201
|
var __esm2 = (fn, res) => function __init() {
|
|
15668
|
-
return fn && (res = (0, fn[
|
|
15202
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
15669
15203
|
};
|
|
15670
15204
|
var __commonJS2 = (cb, mod) => function __require2() {
|
|
15671
|
-
return mod || (0, cb[
|
|
15205
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
15672
15206
|
};
|
|
15673
15207
|
var __export2 = (target, all) => {
|
|
15674
15208
|
for (var name in all)
|
|
15675
|
-
|
|
15209
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15676
15210
|
};
|
|
15677
|
-
var
|
|
15211
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15678
15212
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
15679
|
-
for (let key of
|
|
15680
|
-
if (!
|
|
15681
|
-
|
|
15213
|
+
for (let key of __getOwnPropNames(from))
|
|
15214
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15215
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15682
15216
|
}
|
|
15683
15217
|
return to;
|
|
15684
15218
|
};
|
|
15685
|
-
var __toESM2 = (mod, isNodeMode, target) => (target = mod != null ?
|
|
15219
|
+
var __toESM2 = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
15686
15220
|
// If the importer is in node compatibility mode or this is not an ESM
|
|
15687
15221
|
// file that has been converted to a CommonJS file using a Babel-
|
|
15688
15222
|
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
15689
15223
|
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
15690
|
-
isNodeMode || !mod || !mod.__esModule ?
|
|
15224
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
15691
15225
|
mod
|
|
15692
15226
|
));
|
|
15693
|
-
var __toCommonJS2 = (mod) =>
|
|
15694
|
-
var
|
|
15695
|
-
"../contracts/
|
|
15227
|
+
var __toCommonJS2 = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15228
|
+
var require_chain_id = __commonJS2({
|
|
15229
|
+
"../contracts/tvm/escrow-encoding/typescript/dist/chain-id.js"(exports2) {
|
|
15696
15230
|
"use strict";
|
|
15697
15231
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
15698
|
-
exports2.
|
|
15699
|
-
|
|
15700
|
-
|
|
15701
|
-
function computePaymentId(depositor, signature) {
|
|
15702
|
-
const abiCoder = ethers_1.ethers.AbiCoder.defaultAbiCoder();
|
|
15703
|
-
const encoded = abiCoder.encode(["address", "bytes"], [depositor, signature]);
|
|
15704
|
-
return ethers_1.ethers.keccak256(encoded);
|
|
15705
|
-
}
|
|
15706
|
-
function computePaymentIdV2(depositor, signature, nonce) {
|
|
15707
|
-
const abiCoder = ethers_1.ethers.AbiCoder.defaultAbiCoder();
|
|
15708
|
-
const encoded = abiCoder.encode(["address", "bytes", "uint256"], [depositor, signature, nonce]);
|
|
15709
|
-
return ethers_1.ethers.keccak256(encoded);
|
|
15232
|
+
exports2.maskChainId = maskChainId2;
|
|
15233
|
+
function maskChainId2(chainId) {
|
|
15234
|
+
return (chainId & 4294967295) >>> 0;
|
|
15710
15235
|
}
|
|
15711
15236
|
}
|
|
15712
15237
|
});
|
|
15713
|
-
var
|
|
15714
|
-
"../contracts/
|
|
15238
|
+
var require_tron_address = __commonJS2({
|
|
15239
|
+
"../contracts/tvm/escrow-encoding/typescript/dist/tron-address.js"(exports2) {
|
|
15715
15240
|
"use strict";
|
|
15241
|
+
var __importDefault = exports2 && exports2.__importDefault || function(mod) {
|
|
15242
|
+
return mod && mod.__esModule ? mod : { "default": mod };
|
|
15243
|
+
};
|
|
15716
15244
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
15717
|
-
exports2.
|
|
15245
|
+
exports2.base58ToHex = base58ToHex2;
|
|
15246
|
+
exports2.normalizeAddress = normalizeAddress2;
|
|
15718
15247
|
var ethers_1 = __require("ethers");
|
|
15719
|
-
|
|
15720
|
-
|
|
15248
|
+
var bs58_1 = __importDefault(__require("bs58"));
|
|
15249
|
+
var TVM_MAINNET_PREFIX = "41";
|
|
15250
|
+
function base58ToHex2(base58Address) {
|
|
15251
|
+
if (!base58Address || !base58Address.startsWith("T")) {
|
|
15252
|
+
throw new Error(`Invalid Tron base58 address: ${base58Address}`);
|
|
15253
|
+
}
|
|
15254
|
+
const decoded = bs58_1.default.decode(base58Address);
|
|
15255
|
+
if (decoded.length !== 25) {
|
|
15256
|
+
throw new Error(`Invalid Tron base58 length (expected 25 bytes): ${base58Address}`);
|
|
15257
|
+
}
|
|
15258
|
+
const payload = decoded.slice(0, 21);
|
|
15259
|
+
const checksum = (0, ethers_1.hexlify)(decoded.slice(21)).slice(2);
|
|
15260
|
+
const computed = (0, ethers_1.sha256)((0, ethers_1.sha256)(payload)).slice(2, 10);
|
|
15261
|
+
if (checksum !== computed) {
|
|
15262
|
+
throw new Error(`Invalid Tron base58 checksum: ${base58Address}`);
|
|
15263
|
+
}
|
|
15264
|
+
return (0, ethers_1.hexlify)(payload).slice(2);
|
|
15265
|
+
}
|
|
15266
|
+
function normalizeAddress2(address) {
|
|
15267
|
+
if (!address) {
|
|
15268
|
+
throw new Error("Empty address");
|
|
15269
|
+
}
|
|
15270
|
+
let hexAddress = address;
|
|
15271
|
+
if (address.startsWith("T")) {
|
|
15272
|
+
hexAddress = base58ToHex2(address);
|
|
15273
|
+
}
|
|
15274
|
+
hexAddress = hexAddress.replace(/^0x/, "");
|
|
15275
|
+
if (hexAddress.startsWith(TVM_MAINNET_PREFIX)) {
|
|
15276
|
+
hexAddress = hexAddress.substring(2);
|
|
15277
|
+
}
|
|
15278
|
+
if (hexAddress.length !== 40) {
|
|
15279
|
+
throw new Error(`Invalid address length: expected 40 chars, got ${hexAddress.length}`);
|
|
15280
|
+
}
|
|
15281
|
+
if (!/^[0-9a-fA-F]{40}$/.test(hexAddress)) {
|
|
15282
|
+
throw new Error("Invalid hex address format");
|
|
15283
|
+
}
|
|
15284
|
+
return "0x" + hexAddress.toLowerCase();
|
|
15721
15285
|
}
|
|
15722
15286
|
}
|
|
15723
15287
|
});
|
|
15724
|
-
var
|
|
15725
|
-
"../contracts/
|
|
15288
|
+
var require_reserve_encoder = __commonJS2({
|
|
15289
|
+
"../contracts/tvm/escrow-encoding/typescript/dist/reserve-encoder.js"(exports2) {
|
|
15726
15290
|
"use strict";
|
|
15727
15291
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
15728
|
-
exports2.
|
|
15729
|
-
|
|
15730
|
-
|
|
15731
|
-
|
|
15732
|
-
|
|
15733
|
-
{ name: "
|
|
15734
|
-
{ name: "
|
|
15735
|
-
{ name: "nonce", type: "uint256" },
|
|
15736
|
-
{ name: "deadline", type: "uint256" },
|
|
15737
|
-
{ name: "witness", type: "DepositWitness" }
|
|
15738
|
-
],
|
|
15739
|
-
TokenPermissions: [
|
|
15740
|
-
{ name: "token", type: "address" },
|
|
15741
|
-
{ name: "amount", type: "uint256" }
|
|
15742
|
-
],
|
|
15743
|
-
DepositWitness: [
|
|
15744
|
-
{ name: "requestId", type: "bytes32" },
|
|
15745
|
-
{ name: "reserver", type: "address" },
|
|
15746
|
-
{ name: "releaser", type: "address" }
|
|
15292
|
+
exports2.computeReserveDigest = computeReserveDigest;
|
|
15293
|
+
var ethers_1 = __require("ethers");
|
|
15294
|
+
var chain_id_1 = require_chain_id();
|
|
15295
|
+
var RESERVE_WITNESS_TYPES = {
|
|
15296
|
+
ReserveWitness: [
|
|
15297
|
+
{ name: "paymentId", type: "bytes32" },
|
|
15298
|
+
{ name: "settler", type: "address" }
|
|
15747
15299
|
]
|
|
15748
15300
|
};
|
|
15749
|
-
|
|
15750
|
-
|
|
15751
|
-
|
|
15752
|
-
|
|
15753
|
-
|
|
15754
|
-
|
|
15755
|
-
|
|
15756
|
-
|
|
15757
|
-
|
|
15758
|
-
|
|
15301
|
+
function computeReserveDigest(input) {
|
|
15302
|
+
const domain = {
|
|
15303
|
+
name: "Escrow",
|
|
15304
|
+
version: "3",
|
|
15305
|
+
chainId: (0, chain_id_1.maskChainId)(input.chainId),
|
|
15306
|
+
verifyingContract: input.escrowContract
|
|
15307
|
+
};
|
|
15308
|
+
return ethers_1.TypedDataEncoder.hash(domain, RESERVE_WITNESS_TYPES, {
|
|
15309
|
+
paymentId: input.paymentId,
|
|
15310
|
+
settler: input.settler
|
|
15311
|
+
});
|
|
15312
|
+
}
|
|
15313
|
+
}
|
|
15314
|
+
});
|
|
15315
|
+
var require_payment_id = __commonJS2({
|
|
15316
|
+
"../contracts/tvm/escrow-encoding/typescript/dist/payment-id.js"(exports2) {
|
|
15317
|
+
"use strict";
|
|
15318
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
15319
|
+
exports2.computePaymentId = computePaymentId;
|
|
15320
|
+
var ethers_1 = __require("ethers");
|
|
15321
|
+
var tron_address_1 = require_tron_address();
|
|
15322
|
+
function computePaymentId(depositor, signature, nonce) {
|
|
15323
|
+
if (!/^[0-9]+$/.test(nonce)) {
|
|
15324
|
+
throw new Error(`invalid nonce (expected base-10 decimal): ${nonce}`);
|
|
15325
|
+
}
|
|
15326
|
+
const encoded = ethers_1.AbiCoder.defaultAbiCoder().encode(["address", "bytes", "uint256"], [(0, tron_address_1.normalizeAddress)(depositor), signature, nonce]);
|
|
15327
|
+
return (0, ethers_1.keccak256)(encoded);
|
|
15328
|
+
}
|
|
15329
|
+
}
|
|
15330
|
+
});
|
|
15331
|
+
var require_deposit_encoder = __commonJS2({
|
|
15332
|
+
"../contracts/tvm/escrow-encoding/typescript/dist/deposit-encoder.js"(exports2) {
|
|
15333
|
+
"use strict";
|
|
15334
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
15335
|
+
exports2.createTvmPermitWitnessTransferFromPrehash = createTvmPermitWitnessTransferFromPrehash2;
|
|
15336
|
+
exports2.hashTvmPermitWitnessTransferFrom = hashTvmPermitWitnessTransferFrom2;
|
|
15337
|
+
var ethers_1 = __require("ethers");
|
|
15338
|
+
var chain_id_1 = require_chain_id();
|
|
15339
|
+
var tron_address_1 = require_tron_address();
|
|
15340
|
+
var PERMIT_WITNESS_TYPES_V2 = {
|
|
15341
|
+
PermitWitnessTransferFrom: [
|
|
15342
|
+
{ name: "permitted", type: "TokenPermissions" },
|
|
15343
|
+
{ name: "spender", type: "address" },
|
|
15344
|
+
{ name: "nonce", type: "uint256" },
|
|
15345
|
+
{ name: "deadline", type: "uint256" },
|
|
15346
|
+
{ name: "witness", type: "DepositWitness" }
|
|
15347
|
+
],
|
|
15348
|
+
TokenPermissions: [
|
|
15349
|
+
{ name: "token", type: "address" },
|
|
15350
|
+
{ name: "amount", type: "uint256" }
|
|
15351
|
+
],
|
|
15352
|
+
DepositWitness: [
|
|
15353
|
+
{ name: "reserver", type: "address" },
|
|
15354
|
+
{ name: "releaser", type: "address" }
|
|
15355
|
+
]
|
|
15356
|
+
};
|
|
15357
|
+
function createTvmPermitWitnessTransferFromPrehash2(params) {
|
|
15358
|
+
const maskedChainId = (0, chain_id_1.maskChainId)(params.chainId);
|
|
15359
|
+
return {
|
|
15360
|
+
types: PERMIT_WITNESS_TYPES_V2,
|
|
15361
|
+
primaryType: "PermitWitnessTransferFrom",
|
|
15362
|
+
domain: {
|
|
15363
|
+
name: "Permit2",
|
|
15364
|
+
chainId: `0x${maskedChainId.toString(16)}`,
|
|
15365
|
+
verifyingContract: (0, tron_address_1.normalizeAddress)(params.permit2Address)
|
|
15366
|
+
},
|
|
15367
|
+
message: {
|
|
15368
|
+
permitted: {
|
|
15369
|
+
token: (0, tron_address_1.normalizeAddress)(params.tokenAddress),
|
|
15370
|
+
amount: params.amount
|
|
15371
|
+
},
|
|
15372
|
+
spender: (0, tron_address_1.normalizeAddress)(params.spenderAddress),
|
|
15373
|
+
nonce: params.nonce.toString(),
|
|
15374
|
+
deadline: params.deadline.toString(),
|
|
15375
|
+
witness: {
|
|
15376
|
+
reserver: (0, tron_address_1.normalizeAddress)(params.reserverAddress),
|
|
15377
|
+
releaser: (0, tron_address_1.normalizeAddress)(params.releaserAddress)
|
|
15378
|
+
}
|
|
15379
|
+
}
|
|
15380
|
+
};
|
|
15381
|
+
}
|
|
15382
|
+
function hashTvmPermitWitnessTransferFrom2(prehash) {
|
|
15383
|
+
return ethers_1.TypedDataEncoder.hash(prehash.domain, prehash.types, prehash.message);
|
|
15384
|
+
}
|
|
15385
|
+
}
|
|
15386
|
+
});
|
|
15387
|
+
var require_dist4 = __commonJS2({
|
|
15388
|
+
"../contracts/tvm/escrow-encoding/typescript/dist/index.js"(exports2) {
|
|
15389
|
+
"use strict";
|
|
15390
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
15391
|
+
exports2.hashTvmPermitWitnessTransferFrom = exports2.createTvmPermitWitnessTransferFromPrehash = exports2.computePaymentId = exports2.computeReserveDigest = exports2.normalizeAddress = exports2.base58ToHex = exports2.maskChainId = void 0;
|
|
15392
|
+
var chain_id_1 = require_chain_id();
|
|
15393
|
+
Object.defineProperty(exports2, "maskChainId", { enumerable: true, get: function() {
|
|
15394
|
+
return chain_id_1.maskChainId;
|
|
15395
|
+
} });
|
|
15396
|
+
var tron_address_1 = require_tron_address();
|
|
15397
|
+
Object.defineProperty(exports2, "base58ToHex", { enumerable: true, get: function() {
|
|
15398
|
+
return tron_address_1.base58ToHex;
|
|
15399
|
+
} });
|
|
15400
|
+
Object.defineProperty(exports2, "normalizeAddress", { enumerable: true, get: function() {
|
|
15401
|
+
return tron_address_1.normalizeAddress;
|
|
15402
|
+
} });
|
|
15403
|
+
var reserve_encoder_1 = require_reserve_encoder();
|
|
15404
|
+
Object.defineProperty(exports2, "computeReserveDigest", { enumerable: true, get: function() {
|
|
15405
|
+
return reserve_encoder_1.computeReserveDigest;
|
|
15406
|
+
} });
|
|
15407
|
+
var payment_id_1 = require_payment_id();
|
|
15408
|
+
Object.defineProperty(exports2, "computePaymentId", { enumerable: true, get: function() {
|
|
15409
|
+
return payment_id_1.computePaymentId;
|
|
15410
|
+
} });
|
|
15411
|
+
var deposit_encoder_1 = require_deposit_encoder();
|
|
15412
|
+
Object.defineProperty(exports2, "createTvmPermitWitnessTransferFromPrehash", { enumerable: true, get: function() {
|
|
15413
|
+
return deposit_encoder_1.createTvmPermitWitnessTransferFromPrehash;
|
|
15414
|
+
} });
|
|
15415
|
+
Object.defineProperty(exports2, "hashTvmPermitWitnessTransferFrom", { enumerable: true, get: function() {
|
|
15416
|
+
return deposit_encoder_1.hashTvmPermitWitnessTransferFrom;
|
|
15417
|
+
} });
|
|
15418
|
+
}
|
|
15419
|
+
});
|
|
15420
|
+
var require_types = __commonJS2({
|
|
15421
|
+
"../schemas/declarations/PaymentRequest/v1/bindings/typescript/sender-auth/dist/types.js"(exports2) {
|
|
15422
|
+
"use strict";
|
|
15423
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
15424
|
+
}
|
|
15425
|
+
});
|
|
15426
|
+
var require_utils = __commonJS2({
|
|
15427
|
+
"../schemas/declarations/PaymentRequest/v1/bindings/typescript/sender-auth/dist/utils.js"(exports2) {
|
|
15428
|
+
"use strict";
|
|
15429
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
15430
|
+
exports2.REQUEST_ID_DOMAIN = exports2.SOLANA_REPLAY_SLOTS = exports2.PERMIT_NONCE_DOMAIN = exports2.REPLAY_HORIZON_SECS = void 0;
|
|
15431
|
+
exports2.resolvePermitDeadline = resolvePermitDeadline;
|
|
15432
|
+
exports2.generatePermitNonce = generatePermitNonce;
|
|
15433
|
+
exports2.resolvePermitNonce = resolvePermitNonce;
|
|
15434
|
+
exports2.canonicalDepositor = canonicalDepositor2;
|
|
15435
|
+
exports2.deterministicPermitNonce = deterministicPermitNonce2;
|
|
15436
|
+
exports2.deterministicSolanaNonce = deterministicSolanaNonce2;
|
|
15437
|
+
exports2.deterministicRequestId = deterministicRequestId;
|
|
15438
|
+
exports2.sameAddress = sameAddress;
|
|
15439
|
+
exports2.assertKeyMatchesSender = assertKeyMatchesSender2;
|
|
15440
|
+
exports2.assertToken = assertToken;
|
|
15441
|
+
exports2.assertAmountMatches = assertAmountMatches;
|
|
15442
|
+
exports2.assertFresh = assertFresh;
|
|
15443
|
+
exports2.assertSpender = assertSpender;
|
|
15444
|
+
exports2.assertWitnessRoles = assertWitnessRoles;
|
|
15445
|
+
exports2.assertRolePairComplete = assertRolePairComplete;
|
|
15446
|
+
exports2.nowSec = nowSec;
|
|
15447
|
+
var ethers_1 = __require("ethers");
|
|
15448
|
+
exports2.REPLAY_HORIZON_SECS = 128;
|
|
15449
|
+
function resolvePermitDeadline(deadline) {
|
|
15450
|
+
return BigInt(deadline);
|
|
15451
|
+
}
|
|
15452
|
+
function generatePermitNonce() {
|
|
15453
|
+
const rand = new Uint32Array(1);
|
|
15454
|
+
globalThis.crypto.getRandomValues(rand);
|
|
15455
|
+
return (BigInt(Date.now()) << 32n) + BigInt(rand[0]);
|
|
15456
|
+
}
|
|
15457
|
+
function resolvePermitNonce(nonce) {
|
|
15458
|
+
return BigInt(nonce);
|
|
15459
|
+
}
|
|
15460
|
+
exports2.PERMIT_NONCE_DOMAIN = "atum-permit:v1:";
|
|
15461
|
+
exports2.SOLANA_REPLAY_SLOTS = 235n;
|
|
15462
|
+
var SOLANA_BUCKET_BITS = 17n;
|
|
15463
|
+
function canonicalDepositor2(depositor) {
|
|
15464
|
+
const lower = depositor.toLowerCase();
|
|
15465
|
+
return lower.startsWith("0x") ? lower : depositor;
|
|
15466
|
+
}
|
|
15467
|
+
function permitNonceSeed(requestId, depositor) {
|
|
15468
|
+
if (!requestId) {
|
|
15469
|
+
throw new Error("sender_auth: request_id is required to derive a deterministic permit nonce");
|
|
15470
|
+
}
|
|
15471
|
+
return BigInt((0, ethers_1.keccak256)((0, ethers_1.toUtf8Bytes)(`${exports2.PERMIT_NONCE_DOMAIN}${requestId}:${canonicalDepositor2(depositor)}`)));
|
|
15472
|
+
}
|
|
15473
|
+
function deterministicPermitNonce2(params) {
|
|
15474
|
+
return permitNonceSeed(params.requestId, params.depositor);
|
|
15475
|
+
}
|
|
15476
|
+
function deterministicSolanaNonce2(params) {
|
|
15477
|
+
const seed = permitNonceSeed(params.requestId, params.depositor);
|
|
15478
|
+
const slot = seed % exports2.SOLANA_REPLAY_SLOTS;
|
|
15479
|
+
const bucket = (seed >> 8n) % (1n << SOLANA_BUCKET_BITS);
|
|
15480
|
+
return bucket << 32n | slot;
|
|
15481
|
+
}
|
|
15482
|
+
exports2.REQUEST_ID_DOMAIN = "atum-request:v1:";
|
|
15483
|
+
function deterministicRequestId(params) {
|
|
15484
|
+
if (!params.anchor) {
|
|
15485
|
+
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)");
|
|
15486
|
+
}
|
|
15487
|
+
if (!params.account) {
|
|
15488
|
+
throw new Error("sender_auth: account is required to derive a deterministic request_id");
|
|
15489
|
+
}
|
|
15490
|
+
if (!/^[A-Za-z0-9_-]*$/.test(params.prefix)) {
|
|
15491
|
+
throw new Error(`sender_auth: request_id prefix must contain only letters, digits, '_' or '-' (got ${JSON.stringify(params.prefix)})`);
|
|
15492
|
+
}
|
|
15493
|
+
const digest = (0, ethers_1.keccak256)((0, ethers_1.toUtf8Bytes)(`${exports2.REQUEST_ID_DOMAIN}${params.anchor}:${canonicalDepositor2(params.account)}`));
|
|
15494
|
+
return `${params.prefix}${digest.slice(2, 26)}`;
|
|
15495
|
+
}
|
|
15496
|
+
function sameAddress(a, b) {
|
|
15497
|
+
if (a.startsWith("0x") && b.startsWith("0x")) {
|
|
15498
|
+
return a.toLowerCase() === b.toLowerCase();
|
|
15499
|
+
}
|
|
15500
|
+
return a === b;
|
|
15501
|
+
}
|
|
15502
|
+
function assertKeyMatchesSender2(matches, sender, derived) {
|
|
15503
|
+
if (!matches) {
|
|
15504
|
+
throw new Error(`sender_auth: private key derives ${derived}, not the expected sender ${sender}`);
|
|
15505
|
+
}
|
|
15506
|
+
}
|
|
15507
|
+
function assertToken(token, sourceAsset, normalize) {
|
|
15508
|
+
if (!sameAddress(token, normalize(sourceAsset))) {
|
|
15509
|
+
throw new Error("sender_auth: permit token does not match the source asset");
|
|
15510
|
+
}
|
|
15511
|
+
}
|
|
15512
|
+
function assertAmountMatches(amount, maxSourceAmount) {
|
|
15513
|
+
if (BigInt(amount) !== BigInt(maxSourceAmount)) {
|
|
15514
|
+
throw new Error("sender_auth: permit amount does not match max_source_amount");
|
|
15515
|
+
}
|
|
15516
|
+
}
|
|
15517
|
+
function assertFresh(deadlineSec, nowSec2) {
|
|
15518
|
+
if (deadlineSec <= nowSec2) {
|
|
15519
|
+
throw new Error("sender_auth: permit deadline is not in the future");
|
|
15520
|
+
}
|
|
15521
|
+
}
|
|
15522
|
+
function assertSpender(spender, escrow, normalize) {
|
|
15523
|
+
if (!sameAddress(spender, normalize(escrow))) {
|
|
15524
|
+
throw new Error("sender_auth: permit spender is not the source escrow");
|
|
15525
|
+
}
|
|
15526
|
+
}
|
|
15527
|
+
function assertWitnessRoles(reserver, releaser, expectedReserver, expectedReleaser, normalize) {
|
|
15528
|
+
if (!sameAddress(reserver, normalize(expectedReserver)) || !sameAddress(releaser, normalize(expectedReleaser))) {
|
|
15529
|
+
throw new Error("sender_auth: deposit witness roles do not match the challenge");
|
|
15530
|
+
}
|
|
15531
|
+
}
|
|
15532
|
+
function assertRolePairComplete(reserver, releaser) {
|
|
15533
|
+
if (reserver === void 0 !== (releaser === void 0)) {
|
|
15534
|
+
throw new Error("sender_auth: reserver and releaser must be supplied together");
|
|
15535
|
+
}
|
|
15536
|
+
}
|
|
15537
|
+
function nowSec() {
|
|
15538
|
+
return Math.floor(Date.now() / 1e3);
|
|
15539
|
+
}
|
|
15540
|
+
}
|
|
15541
|
+
});
|
|
15542
|
+
var require_chain_id2 = __commonJS2({
|
|
15543
|
+
"../schemas/declarations/PaymentRequest/v1/bindings/typescript/sender-auth/dist/chain-id.js"(exports2) {
|
|
15544
|
+
"use strict";
|
|
15545
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
15546
|
+
exports2.TRON_PERMIT2_FALLBACKS = exports2.TRON_CHAIN_IDS = void 0;
|
|
15547
|
+
exports2.namespaceOf = namespaceOf2;
|
|
15548
|
+
exports2.evmChainId = evmChainId;
|
|
15549
|
+
exports2.tronNumericChainId = tronNumericChainId;
|
|
15550
|
+
exports2.resolveTronPermit2 = resolveTronPermit2;
|
|
15551
|
+
exports2.clusterIdFromName = clusterIdFromName;
|
|
15552
|
+
function namespaceOf2(network) {
|
|
15553
|
+
return network.split(":")[0];
|
|
15554
|
+
}
|
|
15555
|
+
function evmChainId(network) {
|
|
15556
|
+
const match = /^eip155:([0-9]+)$/.exec(network);
|
|
15557
|
+
if (!match) {
|
|
15558
|
+
throw new Error(`sender_auth: expected an eip155 network, got ${network}`);
|
|
15559
|
+
}
|
|
15560
|
+
return Number(match[1]);
|
|
15561
|
+
}
|
|
15562
|
+
exports2.TRON_CHAIN_IDS = {
|
|
15563
|
+
mainnet: 728126428,
|
|
15564
|
+
shasta: 2494104990
|
|
15565
|
+
};
|
|
15566
|
+
function tronNumericChainId(network) {
|
|
15567
|
+
const cluster = network.split(":")[1];
|
|
15568
|
+
const id = exports2.TRON_CHAIN_IDS[cluster ?? ""];
|
|
15569
|
+
if (id === void 0) {
|
|
15570
|
+
throw new Error(`sender_auth: unsupported Tron network '${network}'`);
|
|
15571
|
+
}
|
|
15572
|
+
return id;
|
|
15573
|
+
}
|
|
15574
|
+
exports2.TRON_PERMIT2_FALLBACKS = {
|
|
15575
|
+
"tron:mainnet": "TJhMXTHQHeQyMD7TcKQFqAePNgG4b31H9m",
|
|
15576
|
+
"tron:shasta": "TPUqJPASUn1zLvbLBgRZ5pBYrx7WSe5ahp"
|
|
15577
|
+
};
|
|
15578
|
+
function resolveTronPermit2(network) {
|
|
15579
|
+
const resolved = exports2.TRON_PERMIT2_FALLBACKS[network];
|
|
15580
|
+
if (!resolved) {
|
|
15581
|
+
throw new Error(`sender_auth: no Permit2 address known for Tron network '${network}'`);
|
|
15582
|
+
}
|
|
15583
|
+
return resolved;
|
|
15584
|
+
}
|
|
15585
|
+
function clusterIdFromName(name) {
|
|
15586
|
+
const encoded = new TextEncoder().encode(name);
|
|
15587
|
+
if (encoded.length > 32) {
|
|
15588
|
+
throw new Error(`sender_auth: Solana cluster name too long (${encoded.length} > 32 bytes): ${name}`);
|
|
15589
|
+
}
|
|
15590
|
+
const out = new Uint8Array(32);
|
|
15591
|
+
out.set(encoded);
|
|
15592
|
+
return out;
|
|
15593
|
+
}
|
|
15594
|
+
}
|
|
15595
|
+
});
|
|
15596
|
+
var require_payment_id2 = __commonJS2({
|
|
15597
|
+
"../contracts/evm/escrow-encoding/typescript/dist/payment-id.js"(exports2) {
|
|
15598
|
+
"use strict";
|
|
15599
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
15600
|
+
exports2.computePaymentId = computePaymentId;
|
|
15601
|
+
exports2.computePaymentIdV2 = computePaymentIdV2;
|
|
15602
|
+
var ethers_1 = __require("ethers");
|
|
15603
|
+
function computePaymentId(depositor, signature) {
|
|
15604
|
+
const abiCoder = ethers_1.ethers.AbiCoder.defaultAbiCoder();
|
|
15605
|
+
const encoded = abiCoder.encode(["address", "bytes"], [depositor, signature]);
|
|
15606
|
+
return ethers_1.ethers.keccak256(encoded);
|
|
15607
|
+
}
|
|
15608
|
+
function computePaymentIdV2(depositor, signature, nonce) {
|
|
15609
|
+
const abiCoder = ethers_1.ethers.AbiCoder.defaultAbiCoder();
|
|
15610
|
+
const encoded = abiCoder.encode(["address", "bytes", "uint256"], [depositor, signature, nonce]);
|
|
15611
|
+
return ethers_1.ethers.keccak256(encoded);
|
|
15612
|
+
}
|
|
15613
|
+
}
|
|
15614
|
+
});
|
|
15615
|
+
var require_nonce_generator = __commonJS2({
|
|
15616
|
+
"../contracts/evm/escrow-encoding/typescript/dist/nonce-generator.js"(exports2) {
|
|
15617
|
+
"use strict";
|
|
15618
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
15619
|
+
exports2.generateNonce = generateNonce2;
|
|
15620
|
+
var ethers_1 = __require("ethers");
|
|
15621
|
+
function generateNonce2() {
|
|
15622
|
+
return ethers_1.ethers.hexlify(ethers_1.ethers.randomBytes(32));
|
|
15623
|
+
}
|
|
15624
|
+
}
|
|
15625
|
+
});
|
|
15626
|
+
var require_permit_types = __commonJS2({
|
|
15627
|
+
"../contracts/evm/escrow-encoding/typescript/dist/permit-types.js"(exports2) {
|
|
15628
|
+
"use strict";
|
|
15629
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
15630
|
+
exports2.REFUND_WITNESS_TYPES = exports2.RELEASE_WITNESS_TYPES = exports2.RESERVE_WITNESS_TYPES = exports2.PERMIT_WITNESS_TYPES_V2 = exports2.PERMIT_WITNESS_TYPES = void 0;
|
|
15631
|
+
exports2.createPermit2Domain = createPermit2Domain;
|
|
15632
|
+
exports2.createEscrowDomain = createEscrowDomain;
|
|
15633
|
+
exports2.PERMIT_WITNESS_TYPES = {
|
|
15634
|
+
PermitWitnessTransferFrom: [
|
|
15635
|
+
{ name: "permitted", type: "TokenPermissions" },
|
|
15636
|
+
{ name: "spender", type: "address" },
|
|
15637
|
+
{ name: "nonce", type: "uint256" },
|
|
15638
|
+
{ name: "deadline", type: "uint256" },
|
|
15639
|
+
{ name: "witness", type: "DepositWitness" }
|
|
15640
|
+
],
|
|
15641
|
+
TokenPermissions: [
|
|
15642
|
+
{ name: "token", type: "address" },
|
|
15643
|
+
{ name: "amount", type: "uint256" }
|
|
15644
|
+
],
|
|
15645
|
+
DepositWitness: [
|
|
15646
|
+
{ name: "requestId", type: "bytes32" },
|
|
15647
|
+
{ name: "reserver", type: "address" },
|
|
15648
|
+
{ name: "releaser", type: "address" }
|
|
15649
|
+
]
|
|
15650
|
+
};
|
|
15651
|
+
exports2.PERMIT_WITNESS_TYPES_V2 = {
|
|
15652
|
+
PermitWitnessTransferFrom: [
|
|
15653
|
+
{ name: "permitted", type: "TokenPermissions" },
|
|
15654
|
+
{ name: "spender", type: "address" },
|
|
15655
|
+
{ name: "nonce", type: "uint256" },
|
|
15656
|
+
{ name: "deadline", type: "uint256" },
|
|
15657
|
+
{ name: "witness", type: "DepositWitness" }
|
|
15658
|
+
],
|
|
15659
|
+
TokenPermissions: [
|
|
15660
|
+
{ name: "token", type: "address" },
|
|
15759
15661
|
{ name: "amount", type: "uint256" }
|
|
15760
15662
|
],
|
|
15761
15663
|
DepositWitness: [
|
|
@@ -15810,7 +15712,7 @@ var require_dist2 = __commonJS({
|
|
|
15810
15712
|
};
|
|
15811
15713
|
}
|
|
15812
15714
|
});
|
|
15813
|
-
var
|
|
15715
|
+
var require_escrow_abi = __commonJS2({
|
|
15814
15716
|
"../contracts/evm/escrow-encoding/typescript/dist/escrow-abi.js"(exports2) {
|
|
15815
15717
|
"use strict";
|
|
15816
15718
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
@@ -15999,13 +15901,13 @@ var require_dist2 = __commonJS({
|
|
|
15999
15901
|
exports2.ESCROW_V2_ABI_JSON = exports2.ESCROW_V3_ABI_JSON;
|
|
16000
15902
|
}
|
|
16001
15903
|
});
|
|
16002
|
-
var
|
|
15904
|
+
var require_reserve_encoder2 = __commonJS2({
|
|
16003
15905
|
"../contracts/evm/escrow-encoding/typescript/dist/reserve-encoder.js"(exports2) {
|
|
16004
15906
|
"use strict";
|
|
16005
15907
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
16006
15908
|
exports2.computeReserveDigest = computeReserveDigest;
|
|
16007
15909
|
var ethers_1 = __require("ethers");
|
|
16008
|
-
var permit_types_1 =
|
|
15910
|
+
var permit_types_1 = require_permit_types();
|
|
16009
15911
|
function computeReserveDigest(input) {
|
|
16010
15912
|
const domain = (0, permit_types_1.createEscrowDomain)(input.chainId, input.escrowContract);
|
|
16011
15913
|
return ethers_1.TypedDataEncoder.hash(domain, permit_types_1.RESERVE_WITNESS_TYPES, {
|
|
@@ -16015,7 +15917,7 @@ var require_dist2 = __commonJS({
|
|
|
16015
15917
|
}
|
|
16016
15918
|
}
|
|
16017
15919
|
});
|
|
16018
|
-
var
|
|
15920
|
+
var require_deposit_encoder2 = __commonJS2({
|
|
16019
15921
|
"../contracts/evm/escrow-encoding/typescript/dist/deposit-encoder.js"(exports2) {
|
|
16020
15922
|
"use strict";
|
|
16021
15923
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
@@ -16023,7 +15925,7 @@ var require_dist2 = __commonJS({
|
|
|
16023
15925
|
exports2.createPermitWitnessTransferFromPrehash = createPermitWitnessTransferFromPrehash2;
|
|
16024
15926
|
exports2.hashPermitWitnessTransferFrom = hashPermitWitnessTransferFrom2;
|
|
16025
15927
|
var ethers_1 = __require("ethers");
|
|
16026
|
-
var permit_types_1 =
|
|
15928
|
+
var permit_types_1 = require_permit_types();
|
|
16027
15929
|
exports2.PERMIT2_CONTRACT_ADDRESS = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
|
|
16028
15930
|
function createPermitWitnessTransferFromPrehash2(params) {
|
|
16029
15931
|
return {
|
|
@@ -16054,23 +15956,23 @@ var require_dist2 = __commonJS({
|
|
|
16054
15956
|
}
|
|
16055
15957
|
}
|
|
16056
15958
|
});
|
|
16057
|
-
var
|
|
15959
|
+
var require_dist22 = __commonJS2({
|
|
16058
15960
|
"../contracts/evm/escrow-encoding/typescript/dist/index.js"(exports2) {
|
|
16059
15961
|
"use strict";
|
|
16060
15962
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
16061
15963
|
exports2.PERMIT2_CONTRACT_ADDRESS = exports2.hashPermitWitnessTransferFrom = exports2.createPermitWitnessTransferFromPrehash = exports2.computeReserveDigest = exports2.ESCROW_V3_ABI_JSON = exports2.ESCROW_V2_ABI_JSON = exports2.ESCROW_ABI_JSON = exports2.ESCROW_ABI = exports2.REFUND_WITNESS_TYPES = exports2.RELEASE_WITNESS_TYPES = exports2.RESERVE_WITNESS_TYPES = exports2.createEscrowDomain = exports2.createPermit2Domain = exports2.PERMIT_WITNESS_TYPES_V2 = exports2.PERMIT_WITNESS_TYPES = exports2.generateNonce = exports2.computePaymentIdV2 = exports2.computePaymentId = void 0;
|
|
16062
|
-
var payment_id_1 =
|
|
15964
|
+
var payment_id_1 = require_payment_id2();
|
|
16063
15965
|
Object.defineProperty(exports2, "computePaymentId", { enumerable: true, get: function() {
|
|
16064
15966
|
return payment_id_1.computePaymentId;
|
|
16065
15967
|
} });
|
|
16066
15968
|
Object.defineProperty(exports2, "computePaymentIdV2", { enumerable: true, get: function() {
|
|
16067
15969
|
return payment_id_1.computePaymentIdV2;
|
|
16068
15970
|
} });
|
|
16069
|
-
var nonce_generator_1 =
|
|
15971
|
+
var nonce_generator_1 = require_nonce_generator();
|
|
16070
15972
|
Object.defineProperty(exports2, "generateNonce", { enumerable: true, get: function() {
|
|
16071
15973
|
return nonce_generator_1.generateNonce;
|
|
16072
15974
|
} });
|
|
16073
|
-
var permit_types_1 =
|
|
15975
|
+
var permit_types_1 = require_permit_types();
|
|
16074
15976
|
Object.defineProperty(exports2, "PERMIT_WITNESS_TYPES", { enumerable: true, get: function() {
|
|
16075
15977
|
return permit_types_1.PERMIT_WITNESS_TYPES;
|
|
16076
15978
|
} });
|
|
@@ -16092,7 +15994,7 @@ var require_dist2 = __commonJS({
|
|
|
16092
15994
|
Object.defineProperty(exports2, "REFUND_WITNESS_TYPES", { enumerable: true, get: function() {
|
|
16093
15995
|
return permit_types_1.REFUND_WITNESS_TYPES;
|
|
16094
15996
|
} });
|
|
16095
|
-
var escrow_abi_1 =
|
|
15997
|
+
var escrow_abi_1 = require_escrow_abi();
|
|
16096
15998
|
Object.defineProperty(exports2, "ESCROW_ABI", { enumerable: true, get: function() {
|
|
16097
15999
|
return escrow_abi_1.ESCROW_ABI;
|
|
16098
16000
|
} });
|
|
@@ -16105,11 +16007,11 @@ var require_dist2 = __commonJS({
|
|
|
16105
16007
|
Object.defineProperty(exports2, "ESCROW_V3_ABI_JSON", { enumerable: true, get: function() {
|
|
16106
16008
|
return escrow_abi_1.ESCROW_V3_ABI_JSON;
|
|
16107
16009
|
} });
|
|
16108
|
-
var reserve_encoder_1 =
|
|
16010
|
+
var reserve_encoder_1 = require_reserve_encoder2();
|
|
16109
16011
|
Object.defineProperty(exports2, "computeReserveDigest", { enumerable: true, get: function() {
|
|
16110
16012
|
return reserve_encoder_1.computeReserveDigest;
|
|
16111
16013
|
} });
|
|
16112
|
-
var deposit_encoder_1 =
|
|
16014
|
+
var deposit_encoder_1 = require_deposit_encoder2();
|
|
16113
16015
|
Object.defineProperty(exports2, "createPermitWitnessTransferFromPrehash", { enumerable: true, get: function() {
|
|
16114
16016
|
return deposit_encoder_1.createPermitWitnessTransferFromPrehash;
|
|
16115
16017
|
} });
|
|
@@ -16121,199 +16023,270 @@ var require_dist2 = __commonJS({
|
|
|
16121
16023
|
} });
|
|
16122
16024
|
}
|
|
16123
16025
|
});
|
|
16124
|
-
var
|
|
16125
|
-
"../
|
|
16126
|
-
"use strict";
|
|
16127
|
-
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
16128
|
-
exports2.maskChainId = maskChainId2;
|
|
16129
|
-
function maskChainId2(chainId) {
|
|
16130
|
-
return (chainId & 4294967295) >>> 0;
|
|
16131
|
-
}
|
|
16132
|
-
}
|
|
16133
|
-
});
|
|
16134
|
-
var require_tron_address2 = __commonJS2({
|
|
16135
|
-
"../contracts/tvm/escrow-encoding/typescript/dist/tron-address.js"(exports2) {
|
|
16026
|
+
var require_errors = __commonJS2({
|
|
16027
|
+
"../schemas/declarations/PaymentRequest/v1/bindings/typescript/sender-auth/dist/errors.js"(exports2) {
|
|
16136
16028
|
"use strict";
|
|
16137
|
-
var __importDefault = exports2 && exports2.__importDefault || function(mod) {
|
|
16138
|
-
return mod && mod.__esModule ? mod : { "default": mod };
|
|
16139
|
-
};
|
|
16140
16029
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
16141
|
-
exports2.
|
|
16142
|
-
|
|
16143
|
-
|
|
16144
|
-
|
|
16145
|
-
|
|
16146
|
-
function base58ToHex2(base58Address) {
|
|
16147
|
-
if (!base58Address || !base58Address.startsWith("T")) {
|
|
16148
|
-
throw new Error(`Invalid Tron base58 address: ${base58Address}`);
|
|
16149
|
-
}
|
|
16150
|
-
const decoded = bs58_1.default.decode(base58Address);
|
|
16151
|
-
if (decoded.length !== 25) {
|
|
16152
|
-
throw new Error(`Invalid Tron base58 length (expected 25 bytes): ${base58Address}`);
|
|
16153
|
-
}
|
|
16154
|
-
const payload = decoded.slice(0, 21);
|
|
16155
|
-
const checksum = (0, ethers_1.hexlify)(decoded.slice(21)).slice(2);
|
|
16156
|
-
const computed = (0, ethers_1.sha256)((0, ethers_1.sha256)(payload)).slice(2, 10);
|
|
16157
|
-
if (checksum !== computed) {
|
|
16158
|
-
throw new Error(`Invalid Tron base58 checksum: ${base58Address}`);
|
|
16159
|
-
}
|
|
16160
|
-
return (0, ethers_1.hexlify)(payload).slice(2);
|
|
16161
|
-
}
|
|
16162
|
-
function normalizeAddress2(address) {
|
|
16163
|
-
if (!address) {
|
|
16164
|
-
throw new Error("Empty address");
|
|
16165
|
-
}
|
|
16166
|
-
let hexAddress = address;
|
|
16167
|
-
if (address.startsWith("T")) {
|
|
16168
|
-
hexAddress = base58ToHex2(address);
|
|
16169
|
-
}
|
|
16170
|
-
hexAddress = hexAddress.replace(/^0x/, "");
|
|
16171
|
-
if (hexAddress.startsWith(TVM_MAINNET_PREFIX)) {
|
|
16172
|
-
hexAddress = hexAddress.substring(2);
|
|
16173
|
-
}
|
|
16174
|
-
if (hexAddress.length !== 40) {
|
|
16175
|
-
throw new Error(`Invalid address length: expected 40 chars, got ${hexAddress.length}`);
|
|
16030
|
+
exports2.SignerMismatchError = exports2.RecoveryFailedError = exports2.MalformedPrehashError = void 0;
|
|
16031
|
+
var MalformedPrehashError = class extends Error {
|
|
16032
|
+
constructor(message = "sender_auth: malformed message_prehash") {
|
|
16033
|
+
super(message);
|
|
16034
|
+
this.name = "MalformedPrehashError";
|
|
16176
16035
|
}
|
|
16177
|
-
|
|
16178
|
-
|
|
16036
|
+
};
|
|
16037
|
+
exports2.MalformedPrehashError = MalformedPrehashError;
|
|
16038
|
+
var RecoveryFailedError = class extends Error {
|
|
16039
|
+
constructor(message = "sender_auth: could not recover a signer from the signed message") {
|
|
16040
|
+
super(message);
|
|
16041
|
+
this.name = "RecoveryFailedError";
|
|
16179
16042
|
}
|
|
16180
|
-
return "0x" + hexAddress.toLowerCase();
|
|
16181
|
-
}
|
|
16182
|
-
}
|
|
16183
|
-
});
|
|
16184
|
-
var require_reserve_encoder22 = __commonJS2({
|
|
16185
|
-
"../contracts/tvm/escrow-encoding/typescript/dist/reserve-encoder.js"(exports2) {
|
|
16186
|
-
"use strict";
|
|
16187
|
-
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
16188
|
-
exports2.computeReserveDigest = computeReserveDigest;
|
|
16189
|
-
var ethers_1 = __require("ethers");
|
|
16190
|
-
var chain_id_1 = require_chain_id2();
|
|
16191
|
-
var RESERVE_WITNESS_TYPES = {
|
|
16192
|
-
ReserveWitness: [
|
|
16193
|
-
{ name: "paymentId", type: "bytes32" },
|
|
16194
|
-
{ name: "settler", type: "address" }
|
|
16195
|
-
]
|
|
16196
16043
|
};
|
|
16197
|
-
|
|
16198
|
-
|
|
16199
|
-
|
|
16200
|
-
|
|
16201
|
-
|
|
16202
|
-
verifyingContract: input.escrowContract
|
|
16203
|
-
};
|
|
16204
|
-
return ethers_1.TypedDataEncoder.hash(domain, RESERVE_WITNESS_TYPES, {
|
|
16205
|
-
paymentId: input.paymentId,
|
|
16206
|
-
settler: input.settler
|
|
16207
|
-
});
|
|
16208
|
-
}
|
|
16209
|
-
}
|
|
16210
|
-
});
|
|
16211
|
-
var require_payment_id22 = __commonJS2({
|
|
16212
|
-
"../contracts/tvm/escrow-encoding/typescript/dist/payment-id.js"(exports2) {
|
|
16213
|
-
"use strict";
|
|
16214
|
-
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
16215
|
-
exports2.computePaymentId = computePaymentId;
|
|
16216
|
-
var ethers_1 = __require("ethers");
|
|
16217
|
-
var tron_address_1 = require_tron_address2();
|
|
16218
|
-
function computePaymentId(depositor, signature, nonce) {
|
|
16219
|
-
if (!/^[0-9]+$/.test(nonce)) {
|
|
16220
|
-
throw new Error(`invalid nonce (expected base-10 decimal): ${nonce}`);
|
|
16044
|
+
exports2.RecoveryFailedError = RecoveryFailedError;
|
|
16045
|
+
var SignerMismatchError = class extends Error {
|
|
16046
|
+
constructor(message = "sender_auth: recovered signer does not match source.account") {
|
|
16047
|
+
super(message);
|
|
16048
|
+
this.name = "SignerMismatchError";
|
|
16221
16049
|
}
|
|
16222
|
-
|
|
16223
|
-
|
|
16224
|
-
}
|
|
16050
|
+
};
|
|
16051
|
+
exports2.SignerMismatchError = SignerMismatchError;
|
|
16225
16052
|
}
|
|
16226
16053
|
});
|
|
16227
|
-
var
|
|
16228
|
-
"../
|
|
16054
|
+
var require_evm = __commonJS2({
|
|
16055
|
+
"../schemas/declarations/PaymentRequest/v1/bindings/typescript/sender-auth/dist/adapters/evm.js"(exports2) {
|
|
16229
16056
|
"use strict";
|
|
16230
16057
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
16231
|
-
exports2.
|
|
16232
|
-
exports2.hashTvmPermitWitnessTransferFrom = hashTvmPermitWitnessTransferFrom2;
|
|
16058
|
+
exports2.evmAdapter = void 0;
|
|
16233
16059
|
var ethers_1 = __require("ethers");
|
|
16234
|
-
var
|
|
16235
|
-
var
|
|
16236
|
-
var
|
|
16237
|
-
|
|
16238
|
-
|
|
16239
|
-
|
|
16240
|
-
|
|
16241
|
-
|
|
16242
|
-
|
|
16243
|
-
|
|
16244
|
-
|
|
16245
|
-
|
|
16246
|
-
|
|
16247
|
-
|
|
16248
|
-
|
|
16249
|
-
|
|
16250
|
-
|
|
16251
|
-
|
|
16252
|
-
|
|
16253
|
-
|
|
16254
|
-
|
|
16255
|
-
|
|
16256
|
-
|
|
16257
|
-
|
|
16258
|
-
|
|
16259
|
-
|
|
16260
|
-
|
|
16261
|
-
|
|
16262
|
-
}
|
|
16263
|
-
|
|
16264
|
-
|
|
16265
|
-
|
|
16266
|
-
|
|
16267
|
-
},
|
|
16268
|
-
spender: (0, tron_address_1.normalizeAddress)(params.spenderAddress),
|
|
16269
|
-
nonce: params.nonce.toString(),
|
|
16270
|
-
deadline: params.deadline.toString(),
|
|
16271
|
-
witness: {
|
|
16272
|
-
reserver: (0, tron_address_1.normalizeAddress)(params.reserverAddress),
|
|
16273
|
-
releaser: (0, tron_address_1.normalizeAddress)(params.releaserAddress)
|
|
16274
|
-
}
|
|
16060
|
+
var evm_escrow_encoding_1 = require_dist22();
|
|
16061
|
+
var utils_js_1 = require_utils();
|
|
16062
|
+
var errors_js_1 = require_errors();
|
|
16063
|
+
var chain_id_js_1 = require_chain_id2();
|
|
16064
|
+
exports2.evmAdapter = {
|
|
16065
|
+
async buildAuthMessage({ sourceAsset, maxSourceAmount, sourceDefaults, deadline, nonce }) {
|
|
16066
|
+
if (nonce === void 0) {
|
|
16067
|
+
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");
|
|
16068
|
+
}
|
|
16069
|
+
if (deadline === void 0) {
|
|
16070
|
+
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)");
|
|
16071
|
+
}
|
|
16072
|
+
const sourceChainId = sourceAsset.split("/")[0];
|
|
16073
|
+
const chainIdNum = parseInt(sourceChainId.split(":")[1]);
|
|
16074
|
+
const tokenAddress = sourceAsset.split("/")[1].split(":")[1];
|
|
16075
|
+
const permitParams = {
|
|
16076
|
+
chainId: chainIdNum,
|
|
16077
|
+
verifyingContract: evm_escrow_encoding_1.PERMIT2_CONTRACT_ADDRESS,
|
|
16078
|
+
token: tokenAddress,
|
|
16079
|
+
amount: maxSourceAmount,
|
|
16080
|
+
spender: sourceDefaults.escrowContract,
|
|
16081
|
+
nonce: (0, utils_js_1.resolvePermitNonce)(nonce),
|
|
16082
|
+
deadline: (0, utils_js_1.resolvePermitDeadline)(deadline),
|
|
16083
|
+
reserver: sourceDefaults.quoteSelector,
|
|
16084
|
+
releaser: sourceDefaults.fulfillmentVerifierAccount
|
|
16085
|
+
};
|
|
16086
|
+
const messagePrehash = (0, evm_escrow_encoding_1.createPermitWitnessTransferFromPrehash)(permitParams);
|
|
16087
|
+
const messageHash = (0, evm_escrow_encoding_1.hashPermitWitnessTransferFrom)(messagePrehash);
|
|
16088
|
+
return { messageScheme: "EVM_PERMIT2", messageHash, messagePrehash: JSON.stringify(messagePrehash) };
|
|
16089
|
+
},
|
|
16090
|
+
async sign(signedMessage, privateKey) {
|
|
16091
|
+
if (!signedMessage.message_prehash) {
|
|
16092
|
+
throw new Error("EVM adapter sign(): signed_messages[i].message_prehash is required");
|
|
16275
16093
|
}
|
|
16276
|
-
|
|
16277
|
-
|
|
16278
|
-
|
|
16279
|
-
|
|
16280
|
-
|
|
16094
|
+
const prehash = JSON.parse(signedMessage.message_prehash);
|
|
16095
|
+
const prehashDigest = (0, evm_escrow_encoding_1.hashPermitWitnessTransferFrom)(prehash);
|
|
16096
|
+
if (prehashDigest.toLowerCase() !== signedMessage.message.toLowerCase()) {
|
|
16097
|
+
throw new Error(`EVM adapter sign(): message_prehash implies digest ${prehashDigest} but message is ${signedMessage.message}`);
|
|
16098
|
+
}
|
|
16099
|
+
const wallet = new ethers_1.Wallet(privateKey);
|
|
16100
|
+
return wallet.signTypedData(prehash.domain, prehash.types, prehash.message);
|
|
16101
|
+
},
|
|
16102
|
+
recoverSigner(signed, source) {
|
|
16103
|
+
let recovered;
|
|
16104
|
+
try {
|
|
16105
|
+
recovered = (0, ethers_1.recoverAddress)(signed.message, signed.signature);
|
|
16106
|
+
} catch (e) {
|
|
16107
|
+
throw new errors_js_1.RecoveryFailedError(`sender_auth: could not recover a signer: ${e.message}`);
|
|
16108
|
+
}
|
|
16109
|
+
if (!(0, utils_js_1.sameAddress)(recovered, source.account)) {
|
|
16110
|
+
throw new errors_js_1.SignerMismatchError(`sender_auth: recovered ${recovered}, not source.account`);
|
|
16111
|
+
}
|
|
16112
|
+
return source.account;
|
|
16113
|
+
},
|
|
16114
|
+
recoverAndVerify(signed, source, expected) {
|
|
16115
|
+
let canonical;
|
|
16116
|
+
let msg;
|
|
16117
|
+
try {
|
|
16118
|
+
msg = JSON.parse(signed.message_prehash).message;
|
|
16119
|
+
canonical = (0, evm_escrow_encoding_1.createPermitWitnessTransferFromPrehash)({
|
|
16120
|
+
chainId: (0, chain_id_js_1.evmChainId)(source.network),
|
|
16121
|
+
verifyingContract: evm_escrow_encoding_1.PERMIT2_CONTRACT_ADDRESS,
|
|
16122
|
+
token: msg.permitted.token,
|
|
16123
|
+
amount: msg.permitted.amount,
|
|
16124
|
+
spender: msg.spender,
|
|
16125
|
+
nonce: BigInt(msg.nonce),
|
|
16126
|
+
deadline: BigInt(msg.deadline),
|
|
16127
|
+
reserver: msg.witness.reserver,
|
|
16128
|
+
releaser: msg.witness.releaser
|
|
16129
|
+
});
|
|
16130
|
+
} catch {
|
|
16131
|
+
throw new errors_js_1.MalformedPrehashError();
|
|
16132
|
+
}
|
|
16133
|
+
let recovered;
|
|
16134
|
+
try {
|
|
16135
|
+
recovered = (0, ethers_1.verifyTypedData)(canonical.domain, canonical.types, canonical.message, signed.signature);
|
|
16136
|
+
} catch {
|
|
16137
|
+
throw new Error("sender_auth: deposit signature does not recover to source.account");
|
|
16138
|
+
}
|
|
16139
|
+
if (!(0, utils_js_1.sameAddress)(recovered, source.account)) {
|
|
16140
|
+
throw new Error("sender_auth: deposit signature does not recover to source.account");
|
|
16141
|
+
}
|
|
16142
|
+
const deadlineSec = Number(msg.deadline);
|
|
16143
|
+
(0, utils_js_1.assertToken)(msg.permitted.token, source.asset, (a) => a);
|
|
16144
|
+
(0, utils_js_1.assertAmountMatches)(msg.permitted.amount, expected.maxSourceAmount);
|
|
16145
|
+
(0, utils_js_1.assertFresh)(deadlineSec, expected.nowSec ?? (0, utils_js_1.nowSec)());
|
|
16146
|
+
if (expected.escrowContract !== void 0) {
|
|
16147
|
+
(0, utils_js_1.assertSpender)(msg.spender, expected.escrowContract, (a) => a);
|
|
16148
|
+
}
|
|
16149
|
+
(0, utils_js_1.assertRolePairComplete)(expected.reserver, expected.releaser);
|
|
16150
|
+
if (expected.reserver !== void 0 && expected.releaser !== void 0) {
|
|
16151
|
+
(0, utils_js_1.assertWitnessRoles)(msg.witness.reserver, msg.witness.releaser, expected.reserver, expected.releaser, (a) => a);
|
|
16152
|
+
}
|
|
16153
|
+
return {
|
|
16154
|
+
amount: msg.permitted.amount,
|
|
16155
|
+
deadlineSec,
|
|
16156
|
+
permit: {
|
|
16157
|
+
scheme: "EVM_PERMIT2",
|
|
16158
|
+
token: msg.permitted.token,
|
|
16159
|
+
amount: msg.permitted.amount,
|
|
16160
|
+
deadlineSec,
|
|
16161
|
+
reserver: msg.witness.reserver,
|
|
16162
|
+
releaser: msg.witness.releaser,
|
|
16163
|
+
spender: msg.spender
|
|
16164
|
+
}
|
|
16165
|
+
};
|
|
16166
|
+
}
|
|
16167
|
+
};
|
|
16281
16168
|
}
|
|
16282
16169
|
});
|
|
16283
|
-
var
|
|
16284
|
-
"../
|
|
16170
|
+
var require_tron = __commonJS2({
|
|
16171
|
+
"../schemas/declarations/PaymentRequest/v1/bindings/typescript/sender-auth/dist/adapters/tron.js"(exports2) {
|
|
16285
16172
|
"use strict";
|
|
16286
16173
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
16287
|
-
exports2.
|
|
16288
|
-
var
|
|
16289
|
-
|
|
16290
|
-
|
|
16291
|
-
|
|
16292
|
-
var
|
|
16293
|
-
|
|
16294
|
-
|
|
16295
|
-
|
|
16296
|
-
|
|
16297
|
-
|
|
16298
|
-
|
|
16299
|
-
|
|
16300
|
-
|
|
16301
|
-
|
|
16302
|
-
|
|
16303
|
-
|
|
16304
|
-
|
|
16305
|
-
|
|
16306
|
-
|
|
16307
|
-
|
|
16308
|
-
|
|
16309
|
-
|
|
16310
|
-
|
|
16311
|
-
|
|
16312
|
-
|
|
16313
|
-
|
|
16174
|
+
exports2.tronAdapter = void 0;
|
|
16175
|
+
var ethers_1 = __require("ethers");
|
|
16176
|
+
var tvm_escrow_encoding_1 = require_dist4();
|
|
16177
|
+
var utils_js_1 = require_utils();
|
|
16178
|
+
var errors_js_1 = require_errors();
|
|
16179
|
+
var chain_id_js_1 = require_chain_id2();
|
|
16180
|
+
exports2.tronAdapter = {
|
|
16181
|
+
async buildAuthMessage({ sourceAsset, maxSourceAmount, sourceDefaults, deadline, nonce }) {
|
|
16182
|
+
if (nonce === void 0) {
|
|
16183
|
+
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");
|
|
16184
|
+
}
|
|
16185
|
+
if (deadline === void 0) {
|
|
16186
|
+
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)");
|
|
16187
|
+
}
|
|
16188
|
+
const sourceChainId = sourceAsset.split("/")[0];
|
|
16189
|
+
const tokenAddress = sourceAsset.split("/")[1].split(":")[1];
|
|
16190
|
+
const permit2Address = sourceDefaults.permit2Contract ?? (0, chain_id_js_1.resolveTronPermit2)(sourceChainId);
|
|
16191
|
+
const tvmParams = {
|
|
16192
|
+
chainId: (0, chain_id_js_1.tronNumericChainId)(sourceChainId),
|
|
16193
|
+
permit2Address,
|
|
16194
|
+
tokenAddress,
|
|
16195
|
+
amount: maxSourceAmount,
|
|
16196
|
+
spenderAddress: sourceDefaults.escrowContract,
|
|
16197
|
+
nonce: (0, utils_js_1.resolvePermitNonce)(nonce),
|
|
16198
|
+
deadline: (0, utils_js_1.resolvePermitDeadline)(deadline),
|
|
16199
|
+
reserverAddress: sourceDefaults.quoteSelector,
|
|
16200
|
+
releaserAddress: sourceDefaults.fulfillmentVerifierAccount
|
|
16201
|
+
};
|
|
16202
|
+
const messagePrehash = (0, tvm_escrow_encoding_1.createTvmPermitWitnessTransferFromPrehash)(tvmParams);
|
|
16203
|
+
const messageHash = (0, tvm_escrow_encoding_1.hashTvmPermitWitnessTransferFrom)(messagePrehash);
|
|
16204
|
+
return { messageScheme: "EVM_PERMIT2", messageHash, messagePrehash: JSON.stringify(messagePrehash) };
|
|
16205
|
+
},
|
|
16206
|
+
// Signs the TIP-712 typed data, not the bare digest, so a signer can inspect the fields it is
|
|
16207
|
+
// authorizing (Turnkey policies read `eth.eip_712.message[...]`).
|
|
16208
|
+
async sign(signedMessage, privateKey) {
|
|
16209
|
+
if (!signedMessage.message_prehash) {
|
|
16210
|
+
throw new Error("Tron adapter sign(): signed_messages[i].message_prehash is required");
|
|
16211
|
+
}
|
|
16212
|
+
const prehash = JSON.parse(signedMessage.message_prehash);
|
|
16213
|
+
const prehashDigest = (0, tvm_escrow_encoding_1.hashTvmPermitWitnessTransferFrom)(prehash);
|
|
16214
|
+
if (prehashDigest.toLowerCase() !== signedMessage.message.toLowerCase()) {
|
|
16215
|
+
throw new Error(`Tron adapter sign(): message_prehash implies digest ${prehashDigest} but message is ${signedMessage.message}`);
|
|
16216
|
+
}
|
|
16217
|
+
const wallet = new ethers_1.Wallet(privateKey.startsWith("0x") ? privateKey : "0x" + privateKey);
|
|
16218
|
+
return wallet.signTypedData(prehash.domain, prehash.types, prehash.message);
|
|
16219
|
+
},
|
|
16220
|
+
recoverSigner(signed, source) {
|
|
16221
|
+
let recovered;
|
|
16222
|
+
try {
|
|
16223
|
+
recovered = (0, ethers_1.recoverAddress)(signed.message, signed.signature);
|
|
16224
|
+
} catch (e) {
|
|
16225
|
+
throw new errors_js_1.RecoveryFailedError(`sender_auth: could not recover a signer: ${e.message}`);
|
|
16226
|
+
}
|
|
16227
|
+
if (!(0, utils_js_1.sameAddress)(recovered, (0, tvm_escrow_encoding_1.normalizeAddress)(source.account))) {
|
|
16228
|
+
throw new errors_js_1.SignerMismatchError(`sender_auth: recovered ${recovered}, not source.account`);
|
|
16229
|
+
}
|
|
16230
|
+
return source.account;
|
|
16231
|
+
},
|
|
16232
|
+
recoverAndVerify(signed, source, expected) {
|
|
16233
|
+
let msg;
|
|
16234
|
+
let digest;
|
|
16235
|
+
try {
|
|
16236
|
+
msg = JSON.parse(signed.message_prehash).message;
|
|
16237
|
+
const canonical = (0, tvm_escrow_encoding_1.createTvmPermitWitnessTransferFromPrehash)({
|
|
16238
|
+
chainId: (0, chain_id_js_1.tronNumericChainId)(source.network),
|
|
16239
|
+
permit2Address: (0, chain_id_js_1.resolveTronPermit2)(source.network),
|
|
16240
|
+
tokenAddress: msg.permitted.token,
|
|
16241
|
+
amount: msg.permitted.amount,
|
|
16242
|
+
spenderAddress: msg.spender,
|
|
16243
|
+
nonce: BigInt(msg.nonce),
|
|
16244
|
+
deadline: BigInt(msg.deadline),
|
|
16245
|
+
reserverAddress: msg.witness.reserver,
|
|
16246
|
+
releaserAddress: msg.witness.releaser
|
|
16247
|
+
});
|
|
16248
|
+
digest = (0, tvm_escrow_encoding_1.hashTvmPermitWitnessTransferFrom)(canonical);
|
|
16249
|
+
} catch {
|
|
16250
|
+
throw new errors_js_1.MalformedPrehashError();
|
|
16251
|
+
}
|
|
16252
|
+
let recovered;
|
|
16253
|
+
try {
|
|
16254
|
+
recovered = (0, ethers_1.recoverAddress)(digest, signed.signature);
|
|
16255
|
+
} catch {
|
|
16256
|
+
throw new Error("sender_auth: deposit signature does not recover to source.account");
|
|
16257
|
+
}
|
|
16258
|
+
if (!(0, utils_js_1.sameAddress)(recovered, (0, tvm_escrow_encoding_1.normalizeAddress)(source.account))) {
|
|
16259
|
+
throw new Error("sender_auth: deposit signature does not recover to source.account");
|
|
16260
|
+
}
|
|
16261
|
+
const deadlineSec = Number(msg.deadline);
|
|
16262
|
+
(0, utils_js_1.assertToken)(msg.permitted.token, source.asset, tvm_escrow_encoding_1.normalizeAddress);
|
|
16263
|
+
(0, utils_js_1.assertAmountMatches)(msg.permitted.amount, expected.maxSourceAmount);
|
|
16264
|
+
(0, utils_js_1.assertFresh)(deadlineSec, expected.nowSec ?? (0, utils_js_1.nowSec)());
|
|
16265
|
+
if (expected.escrowContract !== void 0) {
|
|
16266
|
+
(0, utils_js_1.assertSpender)(msg.spender, expected.escrowContract, tvm_escrow_encoding_1.normalizeAddress);
|
|
16267
|
+
}
|
|
16268
|
+
(0, utils_js_1.assertRolePairComplete)(expected.reserver, expected.releaser);
|
|
16269
|
+
if (expected.reserver !== void 0 && expected.releaser !== void 0) {
|
|
16270
|
+
(0, utils_js_1.assertWitnessRoles)(msg.witness.reserver, msg.witness.releaser, expected.reserver, expected.releaser, tvm_escrow_encoding_1.normalizeAddress);
|
|
16271
|
+
}
|
|
16272
|
+
return {
|
|
16273
|
+
amount: msg.permitted.amount,
|
|
16274
|
+
deadlineSec,
|
|
16275
|
+
permit: {
|
|
16276
|
+
scheme: "EVM_PERMIT2",
|
|
16277
|
+
token: msg.permitted.token,
|
|
16278
|
+
amount: msg.permitted.amount,
|
|
16279
|
+
deadlineSec,
|
|
16280
|
+
reserver: msg.witness.reserver,
|
|
16281
|
+
releaser: msg.witness.releaser,
|
|
16282
|
+
spender: msg.spender
|
|
16283
|
+
}
|
|
16284
|
+
};
|
|
16285
|
+
}
|
|
16286
|
+
};
|
|
16314
16287
|
}
|
|
16315
16288
|
});
|
|
16316
|
-
var
|
|
16289
|
+
var require_errors2 = __commonJS2({
|
|
16317
16290
|
"../contracts/svm/escrow-encoding/typescript/dist/errors.js"(exports2) {
|
|
16318
16291
|
"use strict";
|
|
16319
16292
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
@@ -16413,8 +16386,8 @@ var require_dist2 = __commonJS({
|
|
|
16413
16386
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
16414
16387
|
exports2.Pubkey = void 0;
|
|
16415
16388
|
var bs58_1 = __importDefault(__require("bs58"));
|
|
16416
|
-
var errors_1 =
|
|
16417
|
-
var
|
|
16389
|
+
var errors_1 = require_errors2();
|
|
16390
|
+
var Pubkey2 = class _Pubkey {
|
|
16418
16391
|
constructor(data) {
|
|
16419
16392
|
if (data.length !== 32) {
|
|
16420
16393
|
throw new errors_1.InvalidPubkeyLengthError();
|
|
@@ -16507,7 +16480,7 @@ var require_dist2 = __commonJS({
|
|
|
16507
16480
|
return this.data.every((b, i) => b === other.data[i]);
|
|
16508
16481
|
}
|
|
16509
16482
|
};
|
|
16510
|
-
exports2.Pubkey =
|
|
16483
|
+
exports2.Pubkey = Pubkey2;
|
|
16511
16484
|
}
|
|
16512
16485
|
});
|
|
16513
16486
|
var require_u64 = __commonJS2({
|
|
@@ -16613,7 +16586,7 @@ var require_dist2 = __commonJS({
|
|
|
16613
16586
|
exports2.crypto = nc && typeof nc === "object" && "webcrypto" in nc ? nc.webcrypto : nc && typeof nc === "object" && "randomBytes" in nc ? nc : void 0;
|
|
16614
16587
|
}
|
|
16615
16588
|
});
|
|
16616
|
-
var
|
|
16589
|
+
var require_utils2 = __commonJS2({
|
|
16617
16590
|
"../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/utils.js"(exports2) {
|
|
16618
16591
|
"use strict";
|
|
16619
16592
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
@@ -16860,7 +16833,7 @@ var require_dist2 = __commonJS({
|
|
|
16860
16833
|
exports2.shake256 = exports2.shake128 = exports2.keccak_512 = exports2.keccak_384 = exports2.keccak_256 = exports2.keccak_224 = exports2.sha3_512 = exports2.sha3_384 = exports2.sha3_256 = exports2.sha3_224 = exports2.Keccak = void 0;
|
|
16861
16834
|
exports2.keccakP = keccakP;
|
|
16862
16835
|
var _u64_ts_1 = require_u64();
|
|
16863
|
-
var utils_ts_1 =
|
|
16836
|
+
var utils_ts_1 = require_utils2();
|
|
16864
16837
|
var _0n = BigInt(0);
|
|
16865
16838
|
var _1n = BigInt(1);
|
|
16866
16839
|
var _2n = BigInt(2);
|
|
@@ -17112,14 +17085,14 @@ var require_dist2 = __commonJS({
|
|
|
17112
17085
|
}
|
|
17113
17086
|
}
|
|
17114
17087
|
});
|
|
17115
|
-
var
|
|
17088
|
+
var require_deposit_encoder3 = __commonJS2({
|
|
17116
17089
|
"../contracts/svm/escrow-encoding/typescript/dist/deposit-encoder.js"(exports2) {
|
|
17117
17090
|
"use strict";
|
|
17118
17091
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
17119
17092
|
exports2.computeDepositHash = computeDepositHash2;
|
|
17120
17093
|
var encoding_utils_1 = require_encoding_utils();
|
|
17121
17094
|
var escrow_domain_1 = require_escrow_domain();
|
|
17122
|
-
var errors_1 =
|
|
17095
|
+
var errors_1 = require_errors2();
|
|
17123
17096
|
function computeDepositHash2(params, domain) {
|
|
17124
17097
|
if (params.paymentId.length !== 32 || (0, encoding_utils_1.isZeroBytes32)(params.paymentId)) {
|
|
17125
17098
|
throw new errors_1.ZeroPaymentIdError();
|
|
@@ -17138,14 +17111,14 @@ var require_dist2 = __commonJS({
|
|
|
17138
17111
|
}
|
|
17139
17112
|
}
|
|
17140
17113
|
});
|
|
17141
|
-
var
|
|
17114
|
+
var require_reserve_encoder3 = __commonJS2({
|
|
17142
17115
|
"../contracts/svm/escrow-encoding/typescript/dist/reserve-encoder.js"(exports2) {
|
|
17143
17116
|
"use strict";
|
|
17144
17117
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
17145
17118
|
exports2.computeReserveHash = computeReserveHash;
|
|
17146
17119
|
var encoding_utils_1 = require_encoding_utils();
|
|
17147
17120
|
var escrow_domain_1 = require_escrow_domain();
|
|
17148
|
-
var errors_1 =
|
|
17121
|
+
var errors_1 = require_errors2();
|
|
17149
17122
|
function computeReserveHash(params, domain) {
|
|
17150
17123
|
if (params.depositHash.length !== 32 || (0, encoding_utils_1.isZeroBytes32)(params.depositHash)) {
|
|
17151
17124
|
throw new errors_1.ZeroDepositHashError();
|
|
@@ -17163,7 +17136,7 @@ var require_dist2 = __commonJS({
|
|
|
17163
17136
|
exports2.computeReleaseHash = computeReleaseHash;
|
|
17164
17137
|
var encoding_utils_1 = require_encoding_utils();
|
|
17165
17138
|
var escrow_domain_1 = require_escrow_domain();
|
|
17166
|
-
var errors_1 =
|
|
17139
|
+
var errors_1 = require_errors2();
|
|
17167
17140
|
function computeReleaseHash(params, domain) {
|
|
17168
17141
|
if (params.depositHash.length !== 32 || (0, encoding_utils_1.isZeroBytes32)(params.depositHash)) {
|
|
17169
17142
|
throw new errors_1.ZeroDepositHashError();
|
|
@@ -17179,7 +17152,7 @@ var require_dist2 = __commonJS({
|
|
|
17179
17152
|
exports2.computeRefundHash = computeRefundHash;
|
|
17180
17153
|
var encoding_utils_1 = require_encoding_utils();
|
|
17181
17154
|
var escrow_domain_1 = require_escrow_domain();
|
|
17182
|
-
var errors_1 =
|
|
17155
|
+
var errors_1 = require_errors2();
|
|
17183
17156
|
function computeRefundHash(params, domain) {
|
|
17184
17157
|
if (params.depositHash.length !== 32 || (0, encoding_utils_1.isZeroBytes32)(params.depositHash)) {
|
|
17185
17158
|
throw new errors_1.ZeroDepositHashError();
|
|
@@ -17188,7 +17161,7 @@ var require_dist2 = __commonJS({
|
|
|
17188
17161
|
}
|
|
17189
17162
|
}
|
|
17190
17163
|
});
|
|
17191
|
-
var
|
|
17164
|
+
var require_nonce_generator2 = __commonJS2({
|
|
17192
17165
|
"../contracts/svm/escrow-encoding/typescript/dist/nonce-generator.js"(exports2) {
|
|
17193
17166
|
"use strict";
|
|
17194
17167
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
@@ -17214,94 +17187,399 @@ var require_dist2 = __commonJS({
|
|
|
17214
17187
|
"../contracts/svm/escrow-encoding/typescript/dist/index.js"(exports2) {
|
|
17215
17188
|
"use strict";
|
|
17216
17189
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
17217
|
-
exports2.MAX_VALID_SLOT = exports2.REPLAY_SLOTS = exports2.generateNonce = exports2.computeRefundHash = exports2.computeReleaseHash = exports2.computeReserveHash = exports2.computeDepositHash = exports2.InvalidHexError = exports2.InvalidBase58Error = exports2.InvalidPubkeyLengthError = exports2.ZeroDepositHashError = exports2.ZeroRecipientError = exports2.ZeroReleaserError = exports2.ZeroReserverError = exports2.ZeroAmountError = exports2.ZeroMintError = exports2.ZeroDepositorError = exports2.ZeroPaymentIdError = exports2.EncodingError = exports2.escrowDomainPrefixBytes = exports2.isZeroBytes32 = exports2.stringToBytes = exports2.keccak256 = exports2.encodeU64LE = exports2.Pubkey = void 0;
|
|
17218
|
-
var pubkey_1 = require_pubkey();
|
|
17219
|
-
Object.defineProperty(exports2, "Pubkey", { enumerable: true, get: function() {
|
|
17220
|
-
return pubkey_1.Pubkey;
|
|
17221
|
-
} });
|
|
17222
|
-
var encoding_utils_1 = require_encoding_utils();
|
|
17223
|
-
Object.defineProperty(exports2, "encodeU64LE", { enumerable: true, get: function() {
|
|
17224
|
-
return encoding_utils_1.encodeU64LE;
|
|
17225
|
-
} });
|
|
17226
|
-
Object.defineProperty(exports2, "keccak256", { enumerable: true, get: function() {
|
|
17227
|
-
return encoding_utils_1.keccak256;
|
|
17228
|
-
} });
|
|
17229
|
-
Object.defineProperty(exports2, "stringToBytes", { enumerable: true, get: function() {
|
|
17230
|
-
return encoding_utils_1.stringToBytes;
|
|
17231
|
-
} });
|
|
17232
|
-
Object.defineProperty(exports2, "isZeroBytes32", { enumerable: true, get: function() {
|
|
17233
|
-
return encoding_utils_1.isZeroBytes32;
|
|
17234
|
-
} });
|
|
17235
|
-
var escrow_domain_1 = require_escrow_domain();
|
|
17236
|
-
Object.defineProperty(exports2, "escrowDomainPrefixBytes", { enumerable: true, get: function() {
|
|
17237
|
-
return escrow_domain_1.escrowDomainPrefixBytes;
|
|
17238
|
-
} });
|
|
17239
|
-
var errors_1 =
|
|
17240
|
-
Object.defineProperty(exports2, "EncodingError", { enumerable: true, get: function() {
|
|
17241
|
-
return errors_1.EncodingError;
|
|
17242
|
-
} });
|
|
17243
|
-
Object.defineProperty(exports2, "ZeroPaymentIdError", { enumerable: true, get: function() {
|
|
17244
|
-
return errors_1.ZeroPaymentIdError;
|
|
17245
|
-
} });
|
|
17246
|
-
Object.defineProperty(exports2, "ZeroDepositorError", { enumerable: true, get: function() {
|
|
17247
|
-
return errors_1.ZeroDepositorError;
|
|
17248
|
-
} });
|
|
17249
|
-
Object.defineProperty(exports2, "ZeroMintError", { enumerable: true, get: function() {
|
|
17250
|
-
return errors_1.ZeroMintError;
|
|
17251
|
-
} });
|
|
17252
|
-
Object.defineProperty(exports2, "ZeroAmountError", { enumerable: true, get: function() {
|
|
17253
|
-
return errors_1.ZeroAmountError;
|
|
17254
|
-
} });
|
|
17255
|
-
Object.defineProperty(exports2, "ZeroReserverError", { enumerable: true, get: function() {
|
|
17256
|
-
return errors_1.ZeroReserverError;
|
|
17257
|
-
} });
|
|
17258
|
-
Object.defineProperty(exports2, "ZeroReleaserError", { enumerable: true, get: function() {
|
|
17259
|
-
return errors_1.ZeroReleaserError;
|
|
17260
|
-
} });
|
|
17261
|
-
Object.defineProperty(exports2, "ZeroRecipientError", { enumerable: true, get: function() {
|
|
17262
|
-
return errors_1.ZeroRecipientError;
|
|
17263
|
-
} });
|
|
17264
|
-
Object.defineProperty(exports2, "ZeroDepositHashError", { enumerable: true, get: function() {
|
|
17265
|
-
return errors_1.ZeroDepositHashError;
|
|
17266
|
-
} });
|
|
17267
|
-
Object.defineProperty(exports2, "InvalidPubkeyLengthError", { enumerable: true, get: function() {
|
|
17268
|
-
return errors_1.InvalidPubkeyLengthError;
|
|
17269
|
-
} });
|
|
17270
|
-
Object.defineProperty(exports2, "InvalidBase58Error", { enumerable: true, get: function() {
|
|
17271
|
-
return errors_1.InvalidBase58Error;
|
|
17272
|
-
} });
|
|
17273
|
-
Object.defineProperty(exports2, "InvalidHexError", { enumerable: true, get: function() {
|
|
17274
|
-
return errors_1.InvalidHexError;
|
|
17275
|
-
} });
|
|
17276
|
-
var deposit_encoder_1 =
|
|
17277
|
-
Object.defineProperty(exports2, "computeDepositHash", { enumerable: true, get: function() {
|
|
17278
|
-
return deposit_encoder_1.computeDepositHash;
|
|
17279
|
-
} });
|
|
17280
|
-
var reserve_encoder_1 =
|
|
17281
|
-
Object.defineProperty(exports2, "computeReserveHash", { enumerable: true, get: function() {
|
|
17282
|
-
return reserve_encoder_1.computeReserveHash;
|
|
17190
|
+
exports2.MAX_VALID_SLOT = exports2.REPLAY_SLOTS = exports2.generateNonce = exports2.computeRefundHash = exports2.computeReleaseHash = exports2.computeReserveHash = exports2.computeDepositHash = exports2.InvalidHexError = exports2.InvalidBase58Error = exports2.InvalidPubkeyLengthError = exports2.ZeroDepositHashError = exports2.ZeroRecipientError = exports2.ZeroReleaserError = exports2.ZeroReserverError = exports2.ZeroAmountError = exports2.ZeroMintError = exports2.ZeroDepositorError = exports2.ZeroPaymentIdError = exports2.EncodingError = exports2.escrowDomainPrefixBytes = exports2.isZeroBytes32 = exports2.stringToBytes = exports2.keccak256 = exports2.encodeU64LE = exports2.Pubkey = void 0;
|
|
17191
|
+
var pubkey_1 = require_pubkey();
|
|
17192
|
+
Object.defineProperty(exports2, "Pubkey", { enumerable: true, get: function() {
|
|
17193
|
+
return pubkey_1.Pubkey;
|
|
17194
|
+
} });
|
|
17195
|
+
var encoding_utils_1 = require_encoding_utils();
|
|
17196
|
+
Object.defineProperty(exports2, "encodeU64LE", { enumerable: true, get: function() {
|
|
17197
|
+
return encoding_utils_1.encodeU64LE;
|
|
17198
|
+
} });
|
|
17199
|
+
Object.defineProperty(exports2, "keccak256", { enumerable: true, get: function() {
|
|
17200
|
+
return encoding_utils_1.keccak256;
|
|
17201
|
+
} });
|
|
17202
|
+
Object.defineProperty(exports2, "stringToBytes", { enumerable: true, get: function() {
|
|
17203
|
+
return encoding_utils_1.stringToBytes;
|
|
17204
|
+
} });
|
|
17205
|
+
Object.defineProperty(exports2, "isZeroBytes32", { enumerable: true, get: function() {
|
|
17206
|
+
return encoding_utils_1.isZeroBytes32;
|
|
17207
|
+
} });
|
|
17208
|
+
var escrow_domain_1 = require_escrow_domain();
|
|
17209
|
+
Object.defineProperty(exports2, "escrowDomainPrefixBytes", { enumerable: true, get: function() {
|
|
17210
|
+
return escrow_domain_1.escrowDomainPrefixBytes;
|
|
17211
|
+
} });
|
|
17212
|
+
var errors_1 = require_errors2();
|
|
17213
|
+
Object.defineProperty(exports2, "EncodingError", { enumerable: true, get: function() {
|
|
17214
|
+
return errors_1.EncodingError;
|
|
17215
|
+
} });
|
|
17216
|
+
Object.defineProperty(exports2, "ZeroPaymentIdError", { enumerable: true, get: function() {
|
|
17217
|
+
return errors_1.ZeroPaymentIdError;
|
|
17218
|
+
} });
|
|
17219
|
+
Object.defineProperty(exports2, "ZeroDepositorError", { enumerable: true, get: function() {
|
|
17220
|
+
return errors_1.ZeroDepositorError;
|
|
17221
|
+
} });
|
|
17222
|
+
Object.defineProperty(exports2, "ZeroMintError", { enumerable: true, get: function() {
|
|
17223
|
+
return errors_1.ZeroMintError;
|
|
17224
|
+
} });
|
|
17225
|
+
Object.defineProperty(exports2, "ZeroAmountError", { enumerable: true, get: function() {
|
|
17226
|
+
return errors_1.ZeroAmountError;
|
|
17227
|
+
} });
|
|
17228
|
+
Object.defineProperty(exports2, "ZeroReserverError", { enumerable: true, get: function() {
|
|
17229
|
+
return errors_1.ZeroReserverError;
|
|
17230
|
+
} });
|
|
17231
|
+
Object.defineProperty(exports2, "ZeroReleaserError", { enumerable: true, get: function() {
|
|
17232
|
+
return errors_1.ZeroReleaserError;
|
|
17233
|
+
} });
|
|
17234
|
+
Object.defineProperty(exports2, "ZeroRecipientError", { enumerable: true, get: function() {
|
|
17235
|
+
return errors_1.ZeroRecipientError;
|
|
17236
|
+
} });
|
|
17237
|
+
Object.defineProperty(exports2, "ZeroDepositHashError", { enumerable: true, get: function() {
|
|
17238
|
+
return errors_1.ZeroDepositHashError;
|
|
17239
|
+
} });
|
|
17240
|
+
Object.defineProperty(exports2, "InvalidPubkeyLengthError", { enumerable: true, get: function() {
|
|
17241
|
+
return errors_1.InvalidPubkeyLengthError;
|
|
17242
|
+
} });
|
|
17243
|
+
Object.defineProperty(exports2, "InvalidBase58Error", { enumerable: true, get: function() {
|
|
17244
|
+
return errors_1.InvalidBase58Error;
|
|
17245
|
+
} });
|
|
17246
|
+
Object.defineProperty(exports2, "InvalidHexError", { enumerable: true, get: function() {
|
|
17247
|
+
return errors_1.InvalidHexError;
|
|
17248
|
+
} });
|
|
17249
|
+
var deposit_encoder_1 = require_deposit_encoder3();
|
|
17250
|
+
Object.defineProperty(exports2, "computeDepositHash", { enumerable: true, get: function() {
|
|
17251
|
+
return deposit_encoder_1.computeDepositHash;
|
|
17252
|
+
} });
|
|
17253
|
+
var reserve_encoder_1 = require_reserve_encoder3();
|
|
17254
|
+
Object.defineProperty(exports2, "computeReserveHash", { enumerable: true, get: function() {
|
|
17255
|
+
return reserve_encoder_1.computeReserveHash;
|
|
17256
|
+
} });
|
|
17257
|
+
var release_encoder_1 = require_release_encoder();
|
|
17258
|
+
Object.defineProperty(exports2, "computeReleaseHash", { enumerable: true, get: function() {
|
|
17259
|
+
return release_encoder_1.computeReleaseHash;
|
|
17260
|
+
} });
|
|
17261
|
+
var refund_encoder_1 = require_refund_encoder();
|
|
17262
|
+
Object.defineProperty(exports2, "computeRefundHash", { enumerable: true, get: function() {
|
|
17263
|
+
return refund_encoder_1.computeRefundHash;
|
|
17264
|
+
} });
|
|
17265
|
+
var nonce_generator_1 = require_nonce_generator2();
|
|
17266
|
+
Object.defineProperty(exports2, "generateNonce", { enumerable: true, get: function() {
|
|
17267
|
+
return nonce_generator_1.generateNonce;
|
|
17268
|
+
} });
|
|
17269
|
+
Object.defineProperty(exports2, "REPLAY_SLOTS", { enumerable: true, get: function() {
|
|
17270
|
+
return nonce_generator_1.REPLAY_SLOTS;
|
|
17271
|
+
} });
|
|
17272
|
+
Object.defineProperty(exports2, "MAX_VALID_SLOT", { enumerable: true, get: function() {
|
|
17273
|
+
return nonce_generator_1.MAX_VALID_SLOT;
|
|
17274
|
+
} });
|
|
17275
|
+
}
|
|
17276
|
+
});
|
|
17277
|
+
var require_solana = __commonJS2({
|
|
17278
|
+
"../schemas/declarations/PaymentRequest/v1/bindings/typescript/sender-auth/dist/adapters/solana.js"(exports2) {
|
|
17279
|
+
"use strict";
|
|
17280
|
+
var __importDefault = exports2 && exports2.__importDefault || function(mod) {
|
|
17281
|
+
return mod && mod.__esModule ? mod : { "default": mod };
|
|
17282
|
+
};
|
|
17283
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
17284
|
+
exports2.solanaAdapter = void 0;
|
|
17285
|
+
var ethers_1 = __require("ethers");
|
|
17286
|
+
var tweetnacl_1 = __importDefault(__require("tweetnacl"));
|
|
17287
|
+
var bs58_1 = __importDefault(__require("bs58"));
|
|
17288
|
+
var solana_escrow_encoding_1 = require_dist32();
|
|
17289
|
+
var utils_js_1 = require_utils();
|
|
17290
|
+
var errors_js_1 = require_errors();
|
|
17291
|
+
var chain_id_js_1 = require_chain_id2();
|
|
17292
|
+
var idAddr = (a) => a;
|
|
17293
|
+
function generateSolanaPaymentIdV3(requestId) {
|
|
17294
|
+
return (0, ethers_1.keccak256)((0, ethers_1.toUtf8Bytes)(requestId));
|
|
17295
|
+
}
|
|
17296
|
+
function hashDeposit(prehash, domain) {
|
|
17297
|
+
return (0, ethers_1.hexlify)((0, solana_escrow_encoding_1.computeDepositHash)({
|
|
17298
|
+
paymentId: (0, ethers_1.getBytes)(prehash.payment_id),
|
|
17299
|
+
depositor: solana_escrow_encoding_1.Pubkey.fromBase58(prehash.depositor),
|
|
17300
|
+
mint: solana_escrow_encoding_1.Pubkey.fromBase58(prehash.mint),
|
|
17301
|
+
amount: BigInt(prehash.amount),
|
|
17302
|
+
reserver: solana_escrow_encoding_1.Pubkey.fromBase58(prehash.reserver),
|
|
17303
|
+
releaser: solana_escrow_encoding_1.Pubkey.fromBase58(prehash.releaser),
|
|
17304
|
+
nonce: BigInt(prehash.nonce),
|
|
17305
|
+
issuedAt: BigInt(prehash.issued_at),
|
|
17306
|
+
deadline: BigInt(prehash.deadline)
|
|
17307
|
+
}, domain));
|
|
17308
|
+
}
|
|
17309
|
+
function domainFrom(defaults) {
|
|
17310
|
+
if (!defaults.escrowContract) {
|
|
17311
|
+
throw new Error("sender_auth: Solana source requires escrowContract (escrow program id) for the deposit-hash domain");
|
|
17312
|
+
}
|
|
17313
|
+
if (!defaults.svmSignatureClusterId || defaults.svmSignatureDomainVersion == null) {
|
|
17314
|
+
throw new Error("sender_auth: Solana source requires svmSignatureClusterId and svmSignatureDomainVersion (V3 escrow domain separation)");
|
|
17315
|
+
}
|
|
17316
|
+
return {
|
|
17317
|
+
clusterId: (0, chain_id_js_1.clusterIdFromName)(defaults.svmSignatureClusterId),
|
|
17318
|
+
signatureDomainVersion: defaults.svmSignatureDomainVersion,
|
|
17319
|
+
programId: solana_escrow_encoding_1.Pubkey.fromBase58(defaults.escrowContract)
|
|
17320
|
+
};
|
|
17321
|
+
}
|
|
17322
|
+
exports2.solanaAdapter = {
|
|
17323
|
+
async buildAuthMessage({ sourceAsset, depositor, maxSourceAmount, requestId, sourceDefaults, nonce, solanaClockReader }) {
|
|
17324
|
+
if (!requestId) {
|
|
17325
|
+
throw new Error("sender_auth: request_id is required");
|
|
17326
|
+
}
|
|
17327
|
+
const sourceChainId = sourceAsset.split("/")[0];
|
|
17328
|
+
const tokenMint = sourceAsset.split("/")[1].split(":")[1];
|
|
17329
|
+
const depositNonce = nonce !== void 0 ? BigInt(nonce) : (0, solana_escrow_encoding_1.generateNonce)();
|
|
17330
|
+
if (nonce !== void 0) {
|
|
17331
|
+
if (depositNonce < 0n || depositNonce >= 1n << 64n) {
|
|
17332
|
+
throw new Error("sender_auth: Solana nonce must fit an unsigned 64-bit integer (0 <= nonce < 2^64)");
|
|
17333
|
+
}
|
|
17334
|
+
if ((depositNonce & 0xffn) >= utils_js_1.SOLANA_REPLAY_SLOTS) {
|
|
17335
|
+
throw new Error(`sender_auth: Solana nonce low byte (replay slot = nonce & 0xFF = ${depositNonce & 0xffn}) must be < ${utils_js_1.SOLANA_REPLAY_SLOTS}; slots ${utils_js_1.SOLANA_REPLAY_SLOTS}-255 are reserved`);
|
|
17336
|
+
}
|
|
17337
|
+
}
|
|
17338
|
+
const issuedAt = solanaClockReader ? await solanaClockReader(sourceChainId) : BigInt(Math.floor(Date.now() / 1e3));
|
|
17339
|
+
const deadline = issuedAt + BigInt(utils_js_1.REPLAY_HORIZON_SECS - 8);
|
|
17340
|
+
const paymentId = generateSolanaPaymentIdV3(requestId);
|
|
17341
|
+
const prehash = {
|
|
17342
|
+
payment_id: paymentId,
|
|
17343
|
+
depositor,
|
|
17344
|
+
mint: tokenMint,
|
|
17345
|
+
amount: BigInt(maxSourceAmount).toString(),
|
|
17346
|
+
reserver: sourceDefaults.quoteSelector,
|
|
17347
|
+
releaser: sourceDefaults.fulfillmentVerifierAccount,
|
|
17348
|
+
nonce: depositNonce.toString(),
|
|
17349
|
+
issued_at: issuedAt.toString(),
|
|
17350
|
+
deadline: deadline.toString()
|
|
17351
|
+
};
|
|
17352
|
+
const depositHash = hashDeposit(prehash, domainFrom(sourceDefaults));
|
|
17353
|
+
return { messageScheme: "SOLANA", messageHash: depositHash, messagePrehash: JSON.stringify(prehash) };
|
|
17354
|
+
},
|
|
17355
|
+
async sign(signedMessage, privateKey) {
|
|
17356
|
+
const messageBytes = (0, ethers_1.getBytes)(signedMessage.message);
|
|
17357
|
+
const secretKey = secretKeyFromPrivate2(privateKey);
|
|
17358
|
+
const sig = tweetnacl_1.default.sign.detached(messageBytes, secretKey);
|
|
17359
|
+
return "0x" + Buffer.from(sig).toString("hex");
|
|
17360
|
+
},
|
|
17361
|
+
deriveDelegateSigner(privateKey) {
|
|
17362
|
+
return bs58_1.default.encode(tweetnacl_1.default.sign.keyPair.fromSecretKey(secretKeyFromPrivate2(privateKey)).publicKey);
|
|
17363
|
+
},
|
|
17364
|
+
recoverSigner(signed, source) {
|
|
17365
|
+
const provided = signed.payload?.delegate_signer;
|
|
17366
|
+
if (provided !== void 0 && provided !== source.account) {
|
|
17367
|
+
throw new errors_js_1.SignerMismatchError(`sender_auth: delegate_signer ${provided} != source.account`);
|
|
17368
|
+
}
|
|
17369
|
+
const signer = provided ?? source.account;
|
|
17370
|
+
let pub;
|
|
17371
|
+
let msg;
|
|
17372
|
+
let sig;
|
|
17373
|
+
try {
|
|
17374
|
+
pub = bs58_1.default.decode(signer);
|
|
17375
|
+
msg = (0, ethers_1.getBytes)(signed.message);
|
|
17376
|
+
sig = (0, ethers_1.getBytes)(signed.signature);
|
|
17377
|
+
} catch {
|
|
17378
|
+
throw new errors_js_1.RecoveryFailedError("sender_auth: malformed Solana pubkey/message/signature encoding");
|
|
17379
|
+
}
|
|
17380
|
+
if (pub.length !== 32 || msg.length !== 32 || sig.length !== 64) {
|
|
17381
|
+
throw new errors_js_1.RecoveryFailedError("sender_auth: Solana pubkey must be 32 bytes, message 32, signature 64");
|
|
17382
|
+
}
|
|
17383
|
+
let ok = false;
|
|
17384
|
+
try {
|
|
17385
|
+
ok = tweetnacl_1.default.sign.detached.verify(msg, sig, pub);
|
|
17386
|
+
} catch {
|
|
17387
|
+
ok = false;
|
|
17388
|
+
}
|
|
17389
|
+
if (!ok) {
|
|
17390
|
+
throw new errors_js_1.SignerMismatchError("sender_auth: ed25519 verification failed");
|
|
17391
|
+
}
|
|
17392
|
+
return source.account;
|
|
17393
|
+
},
|
|
17394
|
+
recoverAndVerify(signed, source, expected) {
|
|
17395
|
+
let prehash;
|
|
17396
|
+
let canonicalHash;
|
|
17397
|
+
try {
|
|
17398
|
+
prehash = JSON.parse(signed.message_prehash);
|
|
17399
|
+
canonicalHash = hashDeposit(prehash, domainFrom(expected));
|
|
17400
|
+
} catch {
|
|
17401
|
+
throw new errors_js_1.MalformedPrehashError();
|
|
17402
|
+
}
|
|
17403
|
+
if (canonicalHash.toLowerCase() !== signed.message.toLowerCase()) {
|
|
17404
|
+
throw new Error("sender_auth: deposit hash does not match the signed message");
|
|
17405
|
+
}
|
|
17406
|
+
const delegateSigner = signed.payload?.delegate_signer;
|
|
17407
|
+
if (!delegateSigner) {
|
|
17408
|
+
throw new Error("sender_auth: Solana credential is missing delegate_signer");
|
|
17409
|
+
}
|
|
17410
|
+
let verified = false;
|
|
17411
|
+
try {
|
|
17412
|
+
verified = tweetnacl_1.default.sign.detached.verify((0, ethers_1.getBytes)(signed.message), (0, ethers_1.getBytes)(signed.signature), bs58_1.default.decode(delegateSigner));
|
|
17413
|
+
} catch {
|
|
17414
|
+
verified = false;
|
|
17415
|
+
}
|
|
17416
|
+
if (!verified || delegateSigner !== source.account || prehash.depositor !== source.account) {
|
|
17417
|
+
throw new Error("sender_auth: deposit signature does not recover to source.account");
|
|
17418
|
+
}
|
|
17419
|
+
const deadlineSec = Number(prehash.deadline);
|
|
17420
|
+
(0, utils_js_1.assertToken)(prehash.mint, source.asset, idAddr);
|
|
17421
|
+
(0, utils_js_1.assertAmountMatches)(prehash.amount, expected.maxSourceAmount);
|
|
17422
|
+
(0, utils_js_1.assertRolePairComplete)(expected.reserver, expected.releaser);
|
|
17423
|
+
if (expected.reserver !== void 0 && expected.releaser !== void 0) {
|
|
17424
|
+
(0, utils_js_1.assertWitnessRoles)(prehash.reserver, prehash.releaser, expected.reserver, expected.releaser, idAddr);
|
|
17425
|
+
}
|
|
17426
|
+
return {
|
|
17427
|
+
amount: prehash.amount,
|
|
17428
|
+
deadlineSec,
|
|
17429
|
+
permit: {
|
|
17430
|
+
scheme: "SOLANA",
|
|
17431
|
+
token: prehash.mint,
|
|
17432
|
+
amount: prehash.amount,
|
|
17433
|
+
deadlineSec,
|
|
17434
|
+
reserver: prehash.reserver,
|
|
17435
|
+
releaser: prehash.releaser,
|
|
17436
|
+
depositor: prehash.depositor
|
|
17437
|
+
}
|
|
17438
|
+
};
|
|
17439
|
+
}
|
|
17440
|
+
};
|
|
17441
|
+
function secretKeyFromPrivate2(privateKey) {
|
|
17442
|
+
if (/^[0-9a-fA-F]{64}$/.test(privateKey)) {
|
|
17443
|
+
const seed = new Uint8Array(32);
|
|
17444
|
+
for (let i = 0; i < 32; i++) {
|
|
17445
|
+
seed[i] = parseInt(privateKey.substring(i * 2, i * 2 + 2), 16);
|
|
17446
|
+
}
|
|
17447
|
+
return tweetnacl_1.default.sign.keyPair.fromSeed(seed).secretKey;
|
|
17448
|
+
}
|
|
17449
|
+
const decoded = bs58_1.default.decode(privateKey);
|
|
17450
|
+
if (decoded.length === 64)
|
|
17451
|
+
return decoded;
|
|
17452
|
+
if (decoded.length === 32)
|
|
17453
|
+
return tweetnacl_1.default.sign.keyPair.fromSeed(decoded).secretKey;
|
|
17454
|
+
throw new Error(`Invalid Solana private key length: expected 32 or 64 bytes, got ${decoded.length}`);
|
|
17455
|
+
}
|
|
17456
|
+
}
|
|
17457
|
+
});
|
|
17458
|
+
var require_adapters = __commonJS2({
|
|
17459
|
+
"../schemas/declarations/PaymentRequest/v1/bindings/typescript/sender-auth/dist/adapters/index.js"(exports2) {
|
|
17460
|
+
"use strict";
|
|
17461
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
17462
|
+
exports2.getChainAdapter = getChainAdapter2;
|
|
17463
|
+
var chain_id_js_1 = require_chain_id2();
|
|
17464
|
+
var evm_js_1 = require_evm();
|
|
17465
|
+
var tron_js_1 = require_tron();
|
|
17466
|
+
var solana_js_1 = require_solana();
|
|
17467
|
+
var adapters2 = {
|
|
17468
|
+
eip155: evm_js_1.evmAdapter,
|
|
17469
|
+
tron: tron_js_1.tronAdapter,
|
|
17470
|
+
solana: solana_js_1.solanaAdapter
|
|
17471
|
+
};
|
|
17472
|
+
function getChainAdapter2(caip2) {
|
|
17473
|
+
const adapter = adapters2[(0, chain_id_js_1.namespaceOf)(caip2)];
|
|
17474
|
+
if (!adapter) {
|
|
17475
|
+
throw new Error(`sender_auth: unsupported source chain '${caip2}'`);
|
|
17476
|
+
}
|
|
17477
|
+
return adapter;
|
|
17478
|
+
}
|
|
17479
|
+
}
|
|
17480
|
+
});
|
|
17481
|
+
var require_verify = __commonJS2({
|
|
17482
|
+
"../schemas/declarations/PaymentRequest/v1/bindings/typescript/sender-auth/dist/verify.js"(exports2) {
|
|
17483
|
+
"use strict";
|
|
17484
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
17485
|
+
exports2.verifyPaymentRequest = verifyPaymentRequest;
|
|
17486
|
+
var index_js_1 = require_adapters();
|
|
17487
|
+
function parseSourceAsset(assetIdentifier2) {
|
|
17488
|
+
const parts = assetIdentifier2.split("/");
|
|
17489
|
+
const nsParts = parts[1]?.split(":");
|
|
17490
|
+
if (parts.length < 2 || !nsParts || nsParts.length < 2 || !nsParts[1]) {
|
|
17491
|
+
throw new Error(`sender_auth: invalid source asset "${assetIdentifier2}"`);
|
|
17492
|
+
}
|
|
17493
|
+
return { network: parts[0], asset: nsParts[1] };
|
|
17494
|
+
}
|
|
17495
|
+
function verifyPaymentRequest(request2, expected = {}) {
|
|
17496
|
+
const senderAuth = request2.sender_auth;
|
|
17497
|
+
if (!senderAuth?.signed_messages?.length) {
|
|
17498
|
+
throw new Error("sender_auth: request has no signed_messages to verify");
|
|
17499
|
+
}
|
|
17500
|
+
if (!request2.source) {
|
|
17501
|
+
throw new Error("sender_auth: request has no source");
|
|
17502
|
+
}
|
|
17503
|
+
const requestSource = parseSourceAsset(request2.source.asset_identifier);
|
|
17504
|
+
const { sourceAsset, network: networkOverride, maxSourceAmount: amountOverride, ...scheme } = expected;
|
|
17505
|
+
const network = networkOverride ?? requestSource.network;
|
|
17506
|
+
const asset = sourceAsset ?? requestSource.asset;
|
|
17507
|
+
const maxSourceAmount = amountOverride ?? request2.max_source_amount ?? "0";
|
|
17508
|
+
const source = { network, asset, account: request2.source.account };
|
|
17509
|
+
const perMessage = { ...scheme, maxSourceAmount };
|
|
17510
|
+
const adapter = (0, index_js_1.getChainAdapter)(network);
|
|
17511
|
+
const results = senderAuth.signed_messages.map((m) => adapter.recoverAndVerify(m, source, perMessage));
|
|
17512
|
+
return { results, recoveredAccount: source.account };
|
|
17513
|
+
}
|
|
17514
|
+
}
|
|
17515
|
+
});
|
|
17516
|
+
var require_signer = __commonJS2({
|
|
17517
|
+
"../schemas/declarations/PaymentRequest/v1/bindings/typescript/sender-auth/dist/signer.js"(exports2) {
|
|
17518
|
+
"use strict";
|
|
17519
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
17520
|
+
exports2.localKeySigner = localKeySigner2;
|
|
17521
|
+
var index_js_1 = require_adapters();
|
|
17522
|
+
function localKeySigner2(network, privateKey) {
|
|
17523
|
+
const adapter = (0, index_js_1.getChainAdapter)(network);
|
|
17524
|
+
return {
|
|
17525
|
+
async sign(signedMessage) {
|
|
17526
|
+
const signature = await adapter.sign(signedMessage, privateKey);
|
|
17527
|
+
const delegateSigner = adapter.deriveDelegateSigner?.(privateKey);
|
|
17528
|
+
return delegateSigner !== void 0 ? { signature, delegateSigner } : { signature };
|
|
17529
|
+
}
|
|
17530
|
+
};
|
|
17531
|
+
}
|
|
17532
|
+
}
|
|
17533
|
+
});
|
|
17534
|
+
var require_dist42 = __commonJS2({
|
|
17535
|
+
"../schemas/declarations/PaymentRequest/v1/bindings/typescript/sender-auth/dist/index.js"(exports2) {
|
|
17536
|
+
"use strict";
|
|
17537
|
+
var __createBinding = exports2 && exports2.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
17538
|
+
if (k2 === void 0) k2 = k;
|
|
17539
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
17540
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17541
|
+
desc = { enumerable: true, get: function() {
|
|
17542
|
+
return m[k];
|
|
17543
|
+
} };
|
|
17544
|
+
}
|
|
17545
|
+
Object.defineProperty(o, k2, desc);
|
|
17546
|
+
}) : (function(o, m, k, k2) {
|
|
17547
|
+
if (k2 === void 0) k2 = k;
|
|
17548
|
+
o[k2] = m[k];
|
|
17549
|
+
}));
|
|
17550
|
+
var __exportStar = exports2 && exports2.__exportStar || function(m, exports3) {
|
|
17551
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports3, p)) __createBinding(exports3, m, p);
|
|
17552
|
+
};
|
|
17553
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
17554
|
+
exports2.localKeySigner = exports2.SignerMismatchError = exports2.RecoveryFailedError = exports2.MalformedPrehashError = exports2.verifyPaymentRequest = exports2.getChainAdapter = void 0;
|
|
17555
|
+
__exportStar(require_types(), exports2);
|
|
17556
|
+
__exportStar(require_utils(), exports2);
|
|
17557
|
+
__exportStar(require_chain_id2(), exports2);
|
|
17558
|
+
var index_js_1 = require_adapters();
|
|
17559
|
+
Object.defineProperty(exports2, "getChainAdapter", { enumerable: true, get: function() {
|
|
17560
|
+
return index_js_1.getChainAdapter;
|
|
17283
17561
|
} });
|
|
17284
|
-
var
|
|
17285
|
-
Object.defineProperty(exports2, "
|
|
17286
|
-
return
|
|
17562
|
+
var verify_js_1 = require_verify();
|
|
17563
|
+
Object.defineProperty(exports2, "verifyPaymentRequest", { enumerable: true, get: function() {
|
|
17564
|
+
return verify_js_1.verifyPaymentRequest;
|
|
17287
17565
|
} });
|
|
17288
|
-
var
|
|
17289
|
-
Object.defineProperty(exports2, "
|
|
17290
|
-
return
|
|
17566
|
+
var errors_js_1 = require_errors();
|
|
17567
|
+
Object.defineProperty(exports2, "MalformedPrehashError", { enumerable: true, get: function() {
|
|
17568
|
+
return errors_js_1.MalformedPrehashError;
|
|
17291
17569
|
} });
|
|
17292
|
-
|
|
17293
|
-
|
|
17294
|
-
return nonce_generator_1.generateNonce;
|
|
17570
|
+
Object.defineProperty(exports2, "RecoveryFailedError", { enumerable: true, get: function() {
|
|
17571
|
+
return errors_js_1.RecoveryFailedError;
|
|
17295
17572
|
} });
|
|
17296
|
-
Object.defineProperty(exports2, "
|
|
17297
|
-
return
|
|
17573
|
+
Object.defineProperty(exports2, "SignerMismatchError", { enumerable: true, get: function() {
|
|
17574
|
+
return errors_js_1.SignerMismatchError;
|
|
17298
17575
|
} });
|
|
17299
|
-
|
|
17300
|
-
|
|
17576
|
+
var signer_js_1 = require_signer();
|
|
17577
|
+
Object.defineProperty(exports2, "localKeySigner", { enumerable: true, get: function() {
|
|
17578
|
+
return signer_js_1.localKeySigner;
|
|
17301
17579
|
} });
|
|
17302
17580
|
}
|
|
17303
17581
|
});
|
|
17304
|
-
var
|
|
17582
|
+
var require_errors3 = __commonJS2({
|
|
17305
17583
|
"../key-management/common/typescript/dist/errors.js"(exports2) {
|
|
17306
17584
|
"use strict";
|
|
17307
17585
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
@@ -17363,7 +17641,7 @@ var require_dist2 = __commonJS({
|
|
|
17363
17641
|
}
|
|
17364
17642
|
}
|
|
17365
17643
|
});
|
|
17366
|
-
var
|
|
17644
|
+
var require_types2 = __commonJS2({
|
|
17367
17645
|
"../key-management/common/typescript/dist/types.js"(exports2) {
|
|
17368
17646
|
"use strict";
|
|
17369
17647
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
@@ -17391,7 +17669,7 @@ var require_dist2 = __commonJS({
|
|
|
17391
17669
|
});
|
|
17392
17670
|
}
|
|
17393
17671
|
});
|
|
17394
|
-
var
|
|
17672
|
+
var require_dist5 = __commonJS2({
|
|
17395
17673
|
"../key-management/common/typescript/dist/index.js"(exports2) {
|
|
17396
17674
|
"use strict";
|
|
17397
17675
|
var __createBinding = exports2 && exports2.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
@@ -17411,8 +17689,8 @@ var require_dist2 = __commonJS({
|
|
|
17411
17689
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports3, p)) __createBinding(exports3, m, p);
|
|
17412
17690
|
};
|
|
17413
17691
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
17414
|
-
__exportStar(
|
|
17415
|
-
__exportStar(
|
|
17692
|
+
__exportStar(require_errors3(), exports2);
|
|
17693
|
+
__exportStar(require_types2(), exports2);
|
|
17416
17694
|
__exportStar(require_policy(), exports2);
|
|
17417
17695
|
}
|
|
17418
17696
|
});
|
|
@@ -17523,7 +17801,7 @@ var require_dist2 = __commonJS({
|
|
|
17523
17801
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
17524
17802
|
exports2.TurnkeyClient = void 0;
|
|
17525
17803
|
var promises_1 = __require("timers/promises");
|
|
17526
|
-
var km_core_1 =
|
|
17804
|
+
var km_core_1 = require_dist5();
|
|
17527
17805
|
var constants_1 = require_constants();
|
|
17528
17806
|
var logger_1 = require_logger();
|
|
17529
17807
|
var meter_1 = require_meter();
|
|
@@ -17538,6 +17816,7 @@ var require_dist2 = __commonJS({
|
|
|
17538
17816
|
retryCounter;
|
|
17539
17817
|
backoffHistogram;
|
|
17540
17818
|
activityPendingCounter;
|
|
17819
|
+
signDurationHistogram;
|
|
17541
17820
|
// The private API scalar is held only long enough to construct the stamper. After
|
|
17542
17821
|
// `getStamper()` runs, this is nulled out so the hex string doesn't survive on the heap
|
|
17543
17822
|
// for the client's lifetime. Web Crypto holds the imported key as an opaque CryptoKey.
|
|
@@ -17566,6 +17845,10 @@ var require_dist2 = __commonJS({
|
|
|
17566
17845
|
this.activityPendingCounter = meter.createCounter("turnkey.activity_pending_total", {
|
|
17567
17846
|
description: "Activities that entered async polling (did not complete synchronously in the submit response), labeled by activity type"
|
|
17568
17847
|
});
|
|
17848
|
+
this.signDurationHistogram = meter.createHistogram("turnkey.sign_duration_ms", {
|
|
17849
|
+
description: "Full Turnkey activity round-trip latency (concurrency-semaphore wait + submit + poll), labeled by activity type and outcome (success|error)",
|
|
17850
|
+
unit: "ms"
|
|
17851
|
+
});
|
|
17569
17852
|
}
|
|
17570
17853
|
emitRetry(reason, path) {
|
|
17571
17854
|
try {
|
|
@@ -17585,6 +17868,12 @@ var require_dist2 = __commonJS({
|
|
|
17585
17868
|
} catch {
|
|
17586
17869
|
}
|
|
17587
17870
|
}
|
|
17871
|
+
emitSignDuration(durationMs, activityType, outcome) {
|
|
17872
|
+
try {
|
|
17873
|
+
this.signDurationHistogram.record(durationMs, { activity_type: activityType, outcome });
|
|
17874
|
+
} catch {
|
|
17875
|
+
}
|
|
17876
|
+
}
|
|
17588
17877
|
// ── public surface ─────────────────────────────────────────────────────────
|
|
17589
17878
|
/** Boot-time reachability + auth probe. Throws TURNKEY_AUTH on bad credentials. */
|
|
17590
17879
|
async whoami() {
|
|
@@ -17634,39 +17923,46 @@ var require_dist2 = __commonJS({
|
|
|
17634
17923
|
}
|
|
17635
17924
|
// ── activity submission ────────────────────────────────────────────────────
|
|
17636
17925
|
async submitActivity(activityType, endpoint, parameters) {
|
|
17637
|
-
const
|
|
17638
|
-
|
|
17639
|
-
|
|
17640
|
-
|
|
17641
|
-
|
|
17642
|
-
|
|
17643
|
-
|
|
17644
|
-
|
|
17645
|
-
|
|
17646
|
-
|
|
17647
|
-
|
|
17648
|
-
|
|
17649
|
-
|
|
17650
|
-
|
|
17651
|
-
|
|
17652
|
-
|
|
17653
|
-
|
|
17654
|
-
throw (0, km_core_1.signerRetryable)(km_core_1.SignerErrorCode.TURNKEY_SIGNER_UNAVAILABLE, `Turnkey ${ctx} activityId=${activity.id} stayed PENDING past ${POLL_TIMEOUT_MS}ms`);
|
|
17926
|
+
const start = Date.now();
|
|
17927
|
+
let outcome = "error";
|
|
17928
|
+
try {
|
|
17929
|
+
const body = {
|
|
17930
|
+
type: activityType,
|
|
17931
|
+
timestampMs: String(Date.now()),
|
|
17932
|
+
organizationId: this.opts.organizationId,
|
|
17933
|
+
parameters
|
|
17934
|
+
};
|
|
17935
|
+
const signWith = typeof parameters.signWith === "string" ? parameters.signWith : void 0;
|
|
17936
|
+
const ctx = `activity=${activityType}${signWith ? ` signWith=${signWith}` : ""}`;
|
|
17937
|
+
const resp = await this.queryPost(`/public/v1/submit/${endpoint}`, body);
|
|
17938
|
+
let activity = resp.activity;
|
|
17939
|
+
const deadline = Date.now() + POLL_TIMEOUT_MS;
|
|
17940
|
+
let pollAttempt = 0;
|
|
17941
|
+
if (activity?.status === "ACTIVITY_STATUS_PENDING") {
|
|
17942
|
+
this.emitActivityPending(activityType);
|
|
17655
17943
|
}
|
|
17656
|
-
|
|
17657
|
-
|
|
17658
|
-
|
|
17659
|
-
|
|
17660
|
-
|
|
17661
|
-
|
|
17662
|
-
|
|
17663
|
-
|
|
17664
|
-
|
|
17665
|
-
|
|
17666
|
-
|
|
17667
|
-
|
|
17944
|
+
while (activity?.status === "ACTIVITY_STATUS_PENDING") {
|
|
17945
|
+
if (Date.now() > deadline) {
|
|
17946
|
+
throw (0, km_core_1.signerRetryable)(km_core_1.SignerErrorCode.TURNKEY_SIGNER_UNAVAILABLE, `Turnkey ${ctx} activityId=${activity.id} stayed PENDING past ${POLL_TIMEOUT_MS}ms`);
|
|
17947
|
+
}
|
|
17948
|
+
const sleepIdx = Math.min(pollAttempt, POLL_BACKOFF_MS.length - 1);
|
|
17949
|
+
await (0, promises_1.setTimeout)(POLL_BACKOFF_MS[sleepIdx]);
|
|
17950
|
+
pollAttempt++;
|
|
17951
|
+
const polled = await this.queryPost("/public/v1/query/get_activity", { organizationId: this.opts.organizationId, activityId: activity.id });
|
|
17952
|
+
activity = polled.activity;
|
|
17953
|
+
}
|
|
17954
|
+
if (activity?.status !== "ACTIVITY_STATUS_COMPLETED") {
|
|
17955
|
+
const failure = activity?.failure ?? {};
|
|
17956
|
+
throw (0, km_core_1.signerTerminal)(km_core_1.SignerErrorCode.TURNKEY_ACTIVITY_FAILED, `Turnkey ${ctx} activityId=${activity?.id ?? "?"} status=${activity?.status ?? "unknown"}; ${JSON.stringify(failure)}`);
|
|
17957
|
+
}
|
|
17958
|
+
if (activity.result == null) {
|
|
17959
|
+
throw (0, km_core_1.signerTerminal)(km_core_1.SignerErrorCode.TURNKEY_BAD_RESPONSE, `Turnkey ${ctx} activityId=${activity.id} COMPLETED but result was missing`);
|
|
17960
|
+
}
|
|
17961
|
+
outcome = "success";
|
|
17962
|
+
return activity.result;
|
|
17963
|
+
} finally {
|
|
17964
|
+
this.emitSignDuration(Date.now() - start, activityType, outcome);
|
|
17668
17965
|
}
|
|
17669
|
-
return activity.result;
|
|
17670
17966
|
}
|
|
17671
17967
|
// ── HTTP layer ────────────────────────────────────────────────────────────
|
|
17672
17968
|
/**
|
|
@@ -17880,7 +18176,7 @@ var require_dist2 = __commonJS({
|
|
|
17880
18176
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
17881
18177
|
exports2.resolveTurnkeyAccountAddress = resolveTurnkeyAccountAddress;
|
|
17882
18178
|
var promises_1 = __require("timers/promises");
|
|
17883
|
-
var km_core_1 =
|
|
18179
|
+
var km_core_1 = require_dist5();
|
|
17884
18180
|
var constants_1 = require_constants();
|
|
17885
18181
|
var DISCOVERY_BACKOFF_MS = constants_1.TURNKEY_RETRY_BACKOFF_MS;
|
|
17886
18182
|
async function resolveTurnkeyAccountAddress(deps, addressFormat) {
|
|
@@ -17934,17 +18230,33 @@ var require_dist2 = __commonJS({
|
|
|
17934
18230
|
"use strict";
|
|
17935
18231
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
17936
18232
|
exports2.signSecp256k1PreimageAndVerify = signSecp256k1PreimageAndVerify;
|
|
18233
|
+
exports2.signSecp256k1TypedDataAndVerify = signSecp256k1TypedDataAndVerify;
|
|
17937
18234
|
exports2.bytesFromHexOrBytes = bytesFromHexOrBytes;
|
|
17938
18235
|
var ethers_1 = __require("ethers");
|
|
17939
|
-
var km_core_1 =
|
|
18236
|
+
var km_core_1 = require_dist5();
|
|
18237
|
+
var EIP712_HASH_FUNCTION = "HASH_FUNCTION_NOT_APPLICABLE";
|
|
17940
18238
|
async function signSecp256k1PreimageAndVerify(client, signWith, preimage, expectedEvmAddrLower) {
|
|
17941
18239
|
const preimageHex = (0, ethers_1.hexlify)(preimage).slice(2);
|
|
17942
|
-
const
|
|
18240
|
+
const parts = await client.signRawPayload({
|
|
17943
18241
|
signWith,
|
|
17944
18242
|
payload: preimageHex,
|
|
17945
18243
|
encoding: "PAYLOAD_ENCODING_HEXADECIMAL",
|
|
17946
18244
|
hashFunction: "HASH_FUNCTION_KECCAK256"
|
|
17947
18245
|
});
|
|
18246
|
+
return recoverAndVerify(parts, (0, ethers_1.keccak256)(preimage), expectedEvmAddrLower);
|
|
18247
|
+
}
|
|
18248
|
+
async function signSecp256k1TypedDataAndVerify(client, signWith, domain, types, message, expectedEvmAddrLower) {
|
|
18249
|
+
const payload = ethers_1.TypedDataEncoder.getPayload(domain, types, message);
|
|
18250
|
+
const parts = await client.signRawPayload({
|
|
18251
|
+
signWith,
|
|
18252
|
+
payload: JSON.stringify(payload),
|
|
18253
|
+
encoding: "PAYLOAD_ENCODING_EIP712",
|
|
18254
|
+
hashFunction: EIP712_HASH_FUNCTION
|
|
18255
|
+
});
|
|
18256
|
+
const digestHex = ethers_1.TypedDataEncoder.hash(domain, types, message);
|
|
18257
|
+
return recoverAndVerify(parts, digestHex, expectedEvmAddrLower);
|
|
18258
|
+
}
|
|
18259
|
+
function recoverAndVerify({ r, s, v }, digestHex, expectedEvmAddrLower) {
|
|
17948
18260
|
let sig;
|
|
17949
18261
|
try {
|
|
17950
18262
|
sig = ethers_1.Signature.from({
|
|
@@ -17955,7 +18267,6 @@ var require_dist2 = __commonJS({
|
|
|
17955
18267
|
} catch (err) {
|
|
17956
18268
|
throw (0, km_core_1.signerTerminal)(km_core_1.SignerErrorCode.TURNKEY_BAD_RESPONSE, `Turnkey returned malformed secp256k1 signature parts r=${r} s=${s} v=${v}`, err instanceof Error ? err : void 0);
|
|
17957
18269
|
}
|
|
17958
|
-
const digestHex = (0, ethers_1.keccak256)(preimage);
|
|
17959
18270
|
const recovered = (0, ethers_1.recoverAddress)(digestHex, sig).toLowerCase();
|
|
17960
18271
|
if (recovered !== expectedEvmAddrLower) {
|
|
17961
18272
|
throw (0, km_core_1.signerTerminal)(km_core_1.SignerErrorCode.TURNKEY_BAD_RESPONSE, `secp256k1 sign-then-recover mismatch: recovered ${recovered}, expected ${expectedEvmAddrLower}`);
|
|
@@ -17967,13 +18278,13 @@ var require_dist2 = __commonJS({
|
|
|
17967
18278
|
}
|
|
17968
18279
|
}
|
|
17969
18280
|
});
|
|
17970
|
-
var
|
|
18281
|
+
var require_evm2 = __commonJS2({
|
|
17971
18282
|
"../key-management/providers/turnkey/typescript/dist/chains/evm.js"(exports2) {
|
|
17972
18283
|
"use strict";
|
|
17973
18284
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
17974
18285
|
exports2.TurnkeyEvmSigner = void 0;
|
|
17975
18286
|
var ethers_1 = __require("ethers");
|
|
17976
|
-
var km_core_1 =
|
|
18287
|
+
var km_core_1 = require_dist5();
|
|
17977
18288
|
var signer_base_1 = require_signer_base();
|
|
17978
18289
|
var secp256k1_helpers_1 = require_secp256k1_helpers();
|
|
17979
18290
|
var ADDRESS_FORMAT = "ADDRESS_FORMAT_ETHEREUM";
|
|
@@ -18017,8 +18328,7 @@ ${msgBytes.length}`);
|
|
|
18017
18328
|
}
|
|
18018
18329
|
async signTypedData(domain, types, message) {
|
|
18019
18330
|
const { signWith, lower } = this.requireAddresses();
|
|
18020
|
-
|
|
18021
|
-
return (0, secp256k1_helpers_1.signSecp256k1PreimageAndVerify)(this.client, signWith, preimage, lower);
|
|
18331
|
+
return (0, secp256k1_helpers_1.signSecp256k1TypedDataAndVerify)(this.client, signWith, domain, types, message, lower);
|
|
18022
18332
|
}
|
|
18023
18333
|
async signTransaction(tx) {
|
|
18024
18334
|
const { signWith, lower } = this.requireAddresses();
|
|
@@ -18088,7 +18398,7 @@ ${msgBytes.length}`);
|
|
|
18088
18398
|
exports2.TurnkeyEvmSigner = TurnkeyEvmSigner2;
|
|
18089
18399
|
}
|
|
18090
18400
|
});
|
|
18091
|
-
var
|
|
18401
|
+
var require_solana2 = __commonJS2({
|
|
18092
18402
|
"../key-management/providers/turnkey/typescript/dist/chains/solana.js"(exports2) {
|
|
18093
18403
|
"use strict";
|
|
18094
18404
|
var __createBinding = exports2 && exports2.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
@@ -18133,9 +18443,10 @@ ${msgBytes.length}`);
|
|
|
18133
18443
|
};
|
|
18134
18444
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
18135
18445
|
exports2.TurnkeySolanaSigner = void 0;
|
|
18446
|
+
exports2.encodePayload = encodePayload;
|
|
18136
18447
|
var web3_js_1 = __require("@solana/web3.js");
|
|
18137
18448
|
var bs58_1 = __importDefault(__require("bs58"));
|
|
18138
|
-
var km_core_1 =
|
|
18449
|
+
var km_core_1 = require_dist5();
|
|
18139
18450
|
var signer_base_1 = require_signer_base();
|
|
18140
18451
|
var ADDRESS_FORMAT = "ADDRESS_FORMAT_SOLANA";
|
|
18141
18452
|
var TurnkeySolanaSigner2 = class {
|
|
@@ -18166,8 +18477,7 @@ ${msgBytes.length}`);
|
|
|
18166
18477
|
}
|
|
18167
18478
|
const { r, s } = await this.client.signRawPayload({
|
|
18168
18479
|
signWith: this.address,
|
|
18169
|
-
|
|
18170
|
-
encoding: "PAYLOAD_ENCODING_HEXADECIMAL",
|
|
18480
|
+
...encodePayload(bytes),
|
|
18171
18481
|
hashFunction: "HASH_FUNCTION_NOT_APPLICABLE"
|
|
18172
18482
|
});
|
|
18173
18483
|
const sig = Buffer.concat([Buffer.from(stripHex(r), "hex"), Buffer.from(stripHex(s), "hex")]);
|
|
@@ -18208,6 +18518,15 @@ ${msgBytes.length}`);
|
|
|
18208
18518
|
}
|
|
18209
18519
|
};
|
|
18210
18520
|
exports2.TurnkeySolanaSigner = TurnkeySolanaSigner2;
|
|
18521
|
+
function encodePayload(bytes) {
|
|
18522
|
+
const buf = Buffer.from(bytes);
|
|
18523
|
+
const text = buf.toString("utf8");
|
|
18524
|
+
const textual = buf.every((b) => b >= 32 && b <= 126 || b === 9 || b === 10 || b === 13);
|
|
18525
|
+
if (textual && Buffer.from(text, "utf8").equals(buf)) {
|
|
18526
|
+
return { payload: text, encoding: "PAYLOAD_ENCODING_TEXT_UTF8" };
|
|
18527
|
+
}
|
|
18528
|
+
return { payload: buf.toString("hex"), encoding: "PAYLOAD_ENCODING_HEXADECIMAL" };
|
|
18529
|
+
}
|
|
18211
18530
|
function stripHex(s) {
|
|
18212
18531
|
return s.startsWith("0x") ? s.slice(2) : s;
|
|
18213
18532
|
}
|
|
@@ -18218,7 +18537,7 @@ ${msgBytes.length}`);
|
|
|
18218
18537
|
}
|
|
18219
18538
|
}
|
|
18220
18539
|
});
|
|
18221
|
-
var
|
|
18540
|
+
var require_tron2 = __commonJS2({
|
|
18222
18541
|
"../key-management/providers/turnkey/typescript/dist/chains/tron.js"(exports2) {
|
|
18223
18542
|
"use strict";
|
|
18224
18543
|
var __importDefault = exports2 && exports2.__importDefault || function(mod) {
|
|
@@ -18230,7 +18549,7 @@ ${msgBytes.length}`);
|
|
|
18230
18549
|
var bs58_1 = __importDefault(__require("bs58"));
|
|
18231
18550
|
var ethers_1 = __require("ethers");
|
|
18232
18551
|
var node_crypto_1 = __require("crypto");
|
|
18233
|
-
var km_core_1 =
|
|
18552
|
+
var km_core_1 = require_dist5();
|
|
18234
18553
|
var signer_base_1 = require_signer_base();
|
|
18235
18554
|
var secp256k1_helpers_1 = require_secp256k1_helpers();
|
|
18236
18555
|
var ADDRESS_FORMAT = "ADDRESS_FORMAT_TRON";
|
|
@@ -18273,8 +18592,7 @@ ${messageBytes.length}`);
|
|
|
18273
18592
|
}
|
|
18274
18593
|
async signTypedData(domain, types, message) {
|
|
18275
18594
|
const { address, evmAddr } = this.requireReady();
|
|
18276
|
-
|
|
18277
|
-
return (0, secp256k1_helpers_1.signSecp256k1PreimageAndVerify)(this.client, address, preimage, evmAddr);
|
|
18595
|
+
return (0, secp256k1_helpers_1.signSecp256k1TypedDataAndVerify)(this.client, address, domain, types, message, evmAddr);
|
|
18278
18596
|
}
|
|
18279
18597
|
async signTransaction(tx) {
|
|
18280
18598
|
const { address, evmAddr } = this.requireReady();
|
|
@@ -18368,9 +18686,20 @@ ${messageBytes.length}`);
|
|
|
18368
18686
|
exports2.listSubOrganizations = listSubOrganizations;
|
|
18369
18687
|
exports2.deleteSubOrganization = deleteSubOrganization;
|
|
18370
18688
|
async function createSubOrganization(client, input) {
|
|
18689
|
+
const rootUsers = input.rootUsers.map((u) => ({
|
|
18690
|
+
userName: u.userName,
|
|
18691
|
+
...u.userEmail ? { userEmail: u.userEmail } : {},
|
|
18692
|
+
apiKeys: (u.apiKeys ?? []).map((k) => ({
|
|
18693
|
+
apiKeyName: k.apiKeyName,
|
|
18694
|
+
publicKey: k.publicKey,
|
|
18695
|
+
curveType: k.curveType ?? "API_KEY_CURVE_P256"
|
|
18696
|
+
})),
|
|
18697
|
+
authenticators: u.authenticators ?? [],
|
|
18698
|
+
oauthProviders: []
|
|
18699
|
+
}));
|
|
18371
18700
|
const params = {
|
|
18372
18701
|
subOrganizationName: input.subOrganizationName,
|
|
18373
|
-
rootUsers
|
|
18702
|
+
rootUsers,
|
|
18374
18703
|
rootQuorumThreshold: input.rootQuorumThreshold,
|
|
18375
18704
|
wallet: input.wallet ? {
|
|
18376
18705
|
walletName: input.wallet.walletName,
|
|
@@ -18391,8 +18720,8 @@ ${messageBytes.length}`);
|
|
|
18391
18720
|
const out = await client.query("/public/v1/query/list_suborgs");
|
|
18392
18721
|
return (out.organizationIds ?? []).map((id) => ({ subOrganizationId: id }));
|
|
18393
18722
|
}
|
|
18394
|
-
async function deleteSubOrganization(client,
|
|
18395
|
-
await client.executeActivity("ACTIVITY_TYPE_DELETE_SUB_ORGANIZATION", "delete_sub_organization", {
|
|
18723
|
+
async function deleteSubOrganization(client, opts = {}) {
|
|
18724
|
+
await client.executeActivity("ACTIVITY_TYPE_DELETE_SUB_ORGANIZATION", "delete_sub_organization", { deleteWithoutExport: opts.deleteWithoutExport ?? false });
|
|
18396
18725
|
}
|
|
18397
18726
|
}
|
|
18398
18727
|
});
|
|
@@ -18634,7 +18963,7 @@ ${messageBytes.length}`);
|
|
|
18634
18963
|
policyName: "allowSignRawPayload",
|
|
18635
18964
|
effect: "EFFECT_ALLOW",
|
|
18636
18965
|
condition: `activity.type in ['ACTIVITY_TYPE_SIGN_RAW_PAYLOAD_V2', 'ACTIVITY_TYPE_SIGN_RAW_PAYLOADS'] && activity.params.hash_function in ['HASH_FUNCTION_KECCAK256', 'HASH_FUNCTION_NOT_APPLICABLE']`,
|
|
18637
|
-
notes: "Allows signRawPayload with the hash functions the
|
|
18966
|
+
notes: "Allows signRawPayload with the hash functions the runtime uses: KECCAK256 (EIP-191/TIP-191/W3C proofs) and NOT_APPLICABLE (Solana ed25519 + EIP-712 typed data)."
|
|
18638
18967
|
};
|
|
18639
18968
|
}
|
|
18640
18969
|
function buildDenyApproveToNonAllowedSpenderEvm(args) {
|
|
@@ -18785,7 +19114,7 @@ ${detail}`);
|
|
|
18785
19114
|
});
|
|
18786
19115
|
for (const chain of chains) {
|
|
18787
19116
|
if (chain.kind === "evm") {
|
|
18788
|
-
const
|
|
19117
|
+
const evmChainId = parseInt(chain.chainId.split(":")[1], 10);
|
|
18789
19118
|
const tokens = extras.allowedTokens[chain.key]?.map((t) => t.toLowerCase()) ?? [];
|
|
18790
19119
|
if (tokens.length === 0) {
|
|
18791
19120
|
throw new Error(`Sender extras: chain "${chain.key}" has no allowedTokens. Add at least one ERC-20 contract address the sender's wallet is permitted to approve, or remove this chain.`);
|
|
@@ -18795,13 +19124,13 @@ ${detail}`);
|
|
|
18795
19124
|
policies.push({
|
|
18796
19125
|
policyName: `allowApproveToPermit2 (${chain.chainId})`,
|
|
18797
19126
|
effect: "EFFECT_ALLOW",
|
|
18798
|
-
condition: `activity.type == 'ACTIVITY_TYPE_SIGN_TRANSACTION_V2' && eth.tx.chain_id == ${
|
|
19127
|
+
condition: `activity.type == 'ACTIVITY_TYPE_SIGN_TRANSACTION_V2' && eth.tx.chain_id == ${evmChainId} && eth.tx.to in [${tokenList}] && eth.tx.data[0..10] == '${APPROVE_SELECTOR}' && eth.tx.data[34..74] == '${permit2Lower}'`,
|
|
18799
19128
|
notes: "Allows ERC-20 approve(Permit2, amount) on allowlisted token contracts. Permit2 is the only legitimate approve spender for the sender flow."
|
|
18800
19129
|
});
|
|
18801
19130
|
policies.push({
|
|
18802
19131
|
policyName: `denyNonZeroValue (${chain.chainId})`,
|
|
18803
19132
|
effect: "EFFECT_DENY",
|
|
18804
|
-
condition: `activity.type == 'ACTIVITY_TYPE_SIGN_TRANSACTION_V2' && eth.tx.chain_id == ${
|
|
19133
|
+
condition: `activity.type == 'ACTIVITY_TYPE_SIGN_TRANSACTION_V2' && eth.tx.chain_id == ${evmChainId} && eth.tx.value > 0`,
|
|
18805
19134
|
notes: "Sender flow never moves native ETH; deny any non-zero value."
|
|
18806
19135
|
});
|
|
18807
19136
|
const caps = extras.evmCaps?.[chain.key];
|
|
@@ -18809,7 +19138,7 @@ ${detail}`);
|
|
|
18809
19138
|
policies.push({
|
|
18810
19139
|
policyName: `maxGasLimit (${chain.chainId})`,
|
|
18811
19140
|
effect: "EFFECT_DENY",
|
|
18812
|
-
condition: `activity.type == 'ACTIVITY_TYPE_SIGN_TRANSACTION_V2' && eth.tx.chain_id == ${
|
|
19141
|
+
condition: `activity.type == 'ACTIVITY_TYPE_SIGN_TRANSACTION_V2' && eth.tx.chain_id == ${evmChainId} && eth.tx.gas > ${caps.maxGasLimit}`,
|
|
18813
19142
|
notes: "Gas DoS defense."
|
|
18814
19143
|
});
|
|
18815
19144
|
}
|
|
@@ -18817,7 +19146,7 @@ ${detail}`);
|
|
|
18817
19146
|
policies.push({
|
|
18818
19147
|
policyName: `maxFeePerGasWei (${chain.chainId})`,
|
|
18819
19148
|
effect: "EFFECT_DENY",
|
|
18820
|
-
condition: `activity.type == 'ACTIVITY_TYPE_SIGN_TRANSACTION_V2' && eth.tx.chain_id == ${
|
|
19149
|
+
condition: `activity.type == 'ACTIVITY_TYPE_SIGN_TRANSACTION_V2' && eth.tx.chain_id == ${evmChainId} && (eth.tx.max_fee_per_gas > ${caps.maxFeePerGasWei} || eth.tx.gas_price > ${caps.maxFeePerGasWei})`,
|
|
18821
19150
|
notes: "Fee DoS defense (covers EIP-1559 and legacy)."
|
|
18822
19151
|
});
|
|
18823
19152
|
}
|
|
@@ -18864,6 +19193,19 @@ ${detail}`);
|
|
|
18864
19193
|
condition: `activity.type == 'ACTIVITY_TYPE_SIGN_TRANSACTION_V2' && solana.tx.instructions.all(i, i.program_key in [${list}])`,
|
|
18865
19194
|
notes: "Sender Solana deposit txs invoke ComputeBudget + Ed25519Program + Atum escrow only."
|
|
18866
19195
|
});
|
|
19196
|
+
const solCap = extras.solanaMaxNativeValue ?? "10000000";
|
|
19197
|
+
policies.push({
|
|
19198
|
+
policyName: `maxNativeValue (${chain.chainId})`,
|
|
19199
|
+
effect: "EFFECT_DENY",
|
|
19200
|
+
condition: `activity.type == 'ACTIVITY_TYPE_SIGN_TRANSACTION_V2' && solana.tx.transfers.any(t, t.amount > ${solCap})`,
|
|
19201
|
+
notes: "Caps native SOL (lamports); default 10,000,000 (0.01 SOL) ATA-rent headroom."
|
|
19202
|
+
});
|
|
19203
|
+
policies.push({
|
|
19204
|
+
policyName: `denySplTransfers (${chain.chainId})`,
|
|
19205
|
+
effect: "EFFECT_DENY",
|
|
19206
|
+
condition: `activity.type == 'ACTIVITY_TYPE_SIGN_TRANSACTION_V2' && solana.tx.spl_transfers.any(t, !(t.to in []))`,
|
|
19207
|
+
notes: "Denies all top-level SPL transfers; the sender moves tokens only via escrow CPI."
|
|
19208
|
+
});
|
|
18867
19209
|
}
|
|
18868
19210
|
}
|
|
18869
19211
|
policies.push({
|
|
@@ -18982,7 +19324,7 @@ ${detail}`);
|
|
|
18982
19324
|
validateAddressMap(obj.allowedTrc20Recipients, "allowedTrc20Recipients", TRON_ADDRESS, source);
|
|
18983
19325
|
}
|
|
18984
19326
|
if (obj.allowedSplRecipients != null) {
|
|
18985
|
-
validateAddressMap(obj.allowedSplRecipients, "allowedSplRecipients", /^[1-9A-HJ-NP-Za-km-z]{32,44}$/, source);
|
|
19327
|
+
validateAddressMap(obj.allowedSplRecipients, "allowedSplRecipients", /^[1-9A-HJ-NP-Za-km-z]{32,44}$/, source, true);
|
|
18986
19328
|
}
|
|
18987
19329
|
if (obj.evmCaps != null) {
|
|
18988
19330
|
validateCapMap(obj.evmCaps, "evmCaps", ["maxGasLimit", "maxFeePerGasWei"], source);
|
|
@@ -19013,12 +19355,12 @@ ${detail}`);
|
|
|
19013
19355
|
}
|
|
19014
19356
|
}
|
|
19015
19357
|
}
|
|
19016
|
-
function validateAddressMap(map, field, pattern, source) {
|
|
19358
|
+
function validateAddressMap(map, field, pattern, source, allowEmpty = false) {
|
|
19017
19359
|
if (typeof map !== "object" || map == null || Array.isArray(map)) {
|
|
19018
19360
|
throw new Error(`${source}: ${field} must be a map keyed by chain name.`);
|
|
19019
19361
|
}
|
|
19020
19362
|
for (const [chainKey, list] of Object.entries(map)) {
|
|
19021
|
-
if (!Array.isArray(list) || list.length === 0) {
|
|
19363
|
+
if (!Array.isArray(list) || !allowEmpty && list.length === 0) {
|
|
19022
19364
|
throw new Error(`${source}: ${field}.${chainKey} must be a non-empty list of addresses.`);
|
|
19023
19365
|
}
|
|
19024
19366
|
for (const addr of list) {
|
|
@@ -19093,6 +19435,10 @@ ${detail}`);
|
|
|
19093
19435
|
const jobs = [];
|
|
19094
19436
|
for (const [chainKey, recipients] of Object.entries(extras.allowedSplRecipients)) {
|
|
19095
19437
|
const chainId = resolveChainId("allowedSplRecipients", chainKey, "solana:");
|
|
19438
|
+
if (recipients.length === 0) {
|
|
19439
|
+
out.push(buildSplRecipientPolicy(chainId, []));
|
|
19440
|
+
continue;
|
|
19441
|
+
}
|
|
19096
19442
|
const mints = ctx.solanaMintsByChainKey[chainKey] ?? [];
|
|
19097
19443
|
if (mints.length === 0) {
|
|
19098
19444
|
throw new Error(`allowedSplRecipients.${chainKey} requires the Solana chain "${chainKey}" to expose at least one asset mint; got 0.`);
|
|
@@ -19160,7 +19506,7 @@ ${detail}`);
|
|
|
19160
19506
|
policyName: `allowedSplRecipients (${chainId})`,
|
|
19161
19507
|
effect: "EFFECT_DENY",
|
|
19162
19508
|
condition: `activity.type == 'ACTIVITY_TYPE_SIGN_TRANSACTION_V2' && solana.tx.spl_transfers.any(t, !(t.to in [${list}]))`,
|
|
19163
|
-
notes: "Denies any top-level SPL transfer to a destination ATA outside the allowlist."
|
|
19509
|
+
notes: allowedAtas.length === 0 ? "Denies ALL top-level SPL transfers (empty allowlist \u2014 no destination is permitted)." : "Denies any top-level SPL transfer to a destination ATA outside the allowlist."
|
|
19164
19510
|
};
|
|
19165
19511
|
}
|
|
19166
19512
|
}
|
|
@@ -19234,7 +19580,7 @@ ${detail}`);
|
|
|
19234
19580
|
} });
|
|
19235
19581
|
}
|
|
19236
19582
|
});
|
|
19237
|
-
var
|
|
19583
|
+
var require_dist6 = __commonJS2({
|
|
19238
19584
|
"../key-management/providers/turnkey/typescript/dist/index.js"(exports2) {
|
|
19239
19585
|
"use strict";
|
|
19240
19586
|
var __createBinding = exports2 && exports2.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
@@ -19254,7 +19600,7 @@ ${detail}`);
|
|
|
19254
19600
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports3, p)) __createBinding(exports3, m, p);
|
|
19255
19601
|
};
|
|
19256
19602
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
19257
|
-
exports2.bytesFromHexOrBytes = exports2.signSecp256k1PreimageAndVerify = exports2.extractTronSignatureFromTransactionProtobuf = exports2.TurnkeyTronSigner = exports2.TurnkeySolanaSigner = exports2.TurnkeyEvmSigner = exports2.noopMeter = exports2.noopLogger = exports2.TURNKEY_RETRY_BACKOFF_MS = exports2.resolveTurnkeyAccountAddress = exports2.p1363ToDer = exports2.createTurnkeyStamper = exports2.createIsolatedTurnkeyClient = exports2.getOrCreateTurnkeyClient = exports2.TurnkeyClient = void 0;
|
|
19603
|
+
exports2.bytesFromHexOrBytes = exports2.signSecp256k1PreimageAndVerify = exports2.extractTronSignatureFromTransactionProtobuf = exports2.TurnkeyTronSigner = exports2.encodePayload = exports2.TurnkeySolanaSigner = exports2.TurnkeyEvmSigner = exports2.noopMeter = exports2.noopLogger = exports2.TURNKEY_RETRY_BACKOFF_MS = exports2.resolveTurnkeyAccountAddress = exports2.p1363ToDer = exports2.createTurnkeyStamper = exports2.createIsolatedTurnkeyClient = exports2.getOrCreateTurnkeyClient = exports2.TurnkeyClient = void 0;
|
|
19258
19604
|
var client_1 = require_client();
|
|
19259
19605
|
Object.defineProperty(exports2, "TurnkeyClient", { enumerable: true, get: function() {
|
|
19260
19606
|
return client_1.TurnkeyClient;
|
|
@@ -19289,15 +19635,18 @@ ${detail}`);
|
|
|
19289
19635
|
Object.defineProperty(exports2, "noopMeter", { enumerable: true, get: function() {
|
|
19290
19636
|
return meter_1.noopMeter;
|
|
19291
19637
|
} });
|
|
19292
|
-
var evm_1 =
|
|
19638
|
+
var evm_1 = require_evm2();
|
|
19293
19639
|
Object.defineProperty(exports2, "TurnkeyEvmSigner", { enumerable: true, get: function() {
|
|
19294
19640
|
return evm_1.TurnkeyEvmSigner;
|
|
19295
19641
|
} });
|
|
19296
|
-
var solana_1 =
|
|
19642
|
+
var solana_1 = require_solana2();
|
|
19297
19643
|
Object.defineProperty(exports2, "TurnkeySolanaSigner", { enumerable: true, get: function() {
|
|
19298
19644
|
return solana_1.TurnkeySolanaSigner;
|
|
19299
19645
|
} });
|
|
19300
|
-
|
|
19646
|
+
Object.defineProperty(exports2, "encodePayload", { enumerable: true, get: function() {
|
|
19647
|
+
return solana_1.encodePayload;
|
|
19648
|
+
} });
|
|
19649
|
+
var tron_1 = require_tron2();
|
|
19301
19650
|
Object.defineProperty(exports2, "TurnkeyTronSigner", { enumerable: true, get: function() {
|
|
19302
19651
|
return tron_1.TurnkeyTronSigner;
|
|
19303
19652
|
} });
|
|
@@ -19356,13 +19705,13 @@ ${detail}`);
|
|
|
19356
19705
|
};
|
|
19357
19706
|
switch (chainPrefix) {
|
|
19358
19707
|
case "eip155": {
|
|
19359
|
-
const { domain, types, message: typedMessage } = parsePrehash(messagePrehash, "EVM");
|
|
19708
|
+
const { domain, types, message: typedMessage } = parsePrehash(messagePrehash, "EVM", message);
|
|
19360
19709
|
const signer = new import_turnkey_signer.TurnkeyEvmSigner(client, deps);
|
|
19361
19710
|
await signer.initialize();
|
|
19362
19711
|
return { signature: await signer.signTypedData(domain, types, typedMessage) };
|
|
19363
19712
|
}
|
|
19364
19713
|
case "tron": {
|
|
19365
|
-
const { domain, types, message: typedMessage } = parsePrehash(messagePrehash, "Tron");
|
|
19714
|
+
const { domain, types, message: typedMessage } = parsePrehash(messagePrehash, "Tron", message);
|
|
19366
19715
|
const signer = new import_turnkey_signer.TurnkeyTronSigner(client, deps);
|
|
19367
19716
|
await signer.initialize();
|
|
19368
19717
|
return { signature: await signer.signTypedData(domain, types, typedMessage) };
|
|
@@ -19390,7 +19739,7 @@ ${detail}`);
|
|
|
19390
19739
|
}
|
|
19391
19740
|
return Uint8Array.from(Buffer.from(hex, "hex"));
|
|
19392
19741
|
}
|
|
19393
|
-
function parsePrehash(messagePrehash, label) {
|
|
19742
|
+
function parsePrehash(messagePrehash, label, advertisedDigest) {
|
|
19394
19743
|
if (!messagePrehash) {
|
|
19395
19744
|
throw new Error(`Turnkey ${label} signing requires signed_messages[0].message_prehash`);
|
|
19396
19745
|
}
|
|
@@ -19404,15 +19753,24 @@ ${detail}`);
|
|
|
19404
19753
|
if (!isObject(parsed) || !isObject(parsed.domain) || !isObject(parsed.types) || !isObject(parsed.message)) {
|
|
19405
19754
|
throw new Error(`Turnkey ${label} signing: message_prehash must be a JSON object with domain, types and message`);
|
|
19406
19755
|
}
|
|
19407
|
-
|
|
19756
|
+
const { EIP712Domain: _derived, ...structTypes } = parsed.types;
|
|
19757
|
+
const prehashDigest = import_ethers5.TypedDataEncoder.hash(parsed.domain, structTypes, parsed.message);
|
|
19758
|
+
if (prehashDigest.toLowerCase() !== advertisedDigest.toLowerCase()) {
|
|
19759
|
+
throw new Error(
|
|
19760
|
+
`Turnkey ${label} signing: message_prehash implies digest ${prehashDigest} but message is ${advertisedDigest}`
|
|
19761
|
+
);
|
|
19762
|
+
}
|
|
19763
|
+
return { domain: parsed.domain, types: structTypes, message: parsed.message };
|
|
19408
19764
|
}
|
|
19409
19765
|
var import_turnkey_signer;
|
|
19766
|
+
var import_ethers5;
|
|
19410
19767
|
var TURNKEY_API_URL;
|
|
19411
19768
|
var DEFAULTS;
|
|
19412
19769
|
var init_turnkey_impl = __esm2({
|
|
19413
19770
|
"src/signers/turnkey-impl.ts"() {
|
|
19414
19771
|
"use strict";
|
|
19415
|
-
import_turnkey_signer = __toESM2(
|
|
19772
|
+
import_turnkey_signer = __toESM2(require_dist6());
|
|
19773
|
+
import_ethers5 = __require("ethers");
|
|
19416
19774
|
TURNKEY_API_URL = "https://api.turnkey.com";
|
|
19417
19775
|
DEFAULTS = {
|
|
19418
19776
|
concurrencyLimit: 10,
|
|
@@ -19467,35 +19825,37 @@ ${detail}`);
|
|
|
19467
19825
|
HealthService: () => HealthService,
|
|
19468
19826
|
Interceptors: () => Interceptors,
|
|
19469
19827
|
MAX_VALID_SLOT: () => import_solana_escrow_encoding.MAX_VALID_SLOT,
|
|
19470
|
-
OpenAPI: () =>
|
|
19828
|
+
OpenAPI: () => OpenAPI2,
|
|
19471
19829
|
PAYMENT_REQUEST_VERSION: () => PAYMENT_REQUEST_VERSION,
|
|
19472
|
-
PERMIT2_CONTRACT_ADDRESS: () =>
|
|
19473
|
-
PaymentGatewayClient: () =>
|
|
19830
|
+
PERMIT2_CONTRACT_ADDRESS: () => import_evm_escrow_encoding2.PERMIT2_CONTRACT_ADDRESS,
|
|
19831
|
+
PaymentGatewayClient: () => PaymentGatewayClient22,
|
|
19474
19832
|
PaymentsService: () => PaymentsService,
|
|
19475
19833
|
QuoteRequestsService: () => QuoteRequestsService,
|
|
19476
19834
|
REPLAY_HORIZON_SECS: () => REPLAY_HORIZON_SECS,
|
|
19477
19835
|
TOTAL_BUCKETS: () => TOTAL_BUCKETS,
|
|
19478
19836
|
TurnkeySenderSigner: () => TurnkeySenderSigner,
|
|
19479
19837
|
base58ToBytes: () => base58ToBytes,
|
|
19480
|
-
base58ToHex: () =>
|
|
19838
|
+
base58ToHex: () => import_tvm_escrow_encoding.base58ToHex,
|
|
19481
19839
|
bytesToHex: () => bytesToHex,
|
|
19482
|
-
createPermitWitnessTransferFromPrehash: () =>
|
|
19483
|
-
createSenderSigner: () =>
|
|
19840
|
+
createPermitWitnessTransferFromPrehash: () => import_evm_escrow_encoding2.createPermitWitnessTransferFromPrehash,
|
|
19841
|
+
createSenderSigner: () => createSenderSigner2,
|
|
19484
19842
|
createSolanaDepositPrehash: () => createSolanaDepositPrehash,
|
|
19485
|
-
createTvmPermitWitnessTransferFromPrehash: () =>
|
|
19843
|
+
createTvmPermitWitnessTransferFromPrehash: () => import_tvm_escrow_encoding.createTvmPermitWitnessTransferFromPrehash,
|
|
19486
19844
|
defaultGateway: () => defaultGateway,
|
|
19487
19845
|
encodeU64LE: () => import_solana_escrow_encoding.encodeU64LE,
|
|
19488
19846
|
generateSolanaNonce: () => generateSolanaNonce,
|
|
19489
19847
|
generateSolanaPaymentId: () => generateSolanaPaymentId,
|
|
19490
|
-
|
|
19848
|
+
getErrorResponse: () => getErrorResponse,
|
|
19849
|
+
hashPermitWitnessTransferFrom: () => import_evm_escrow_encoding2.hashPermitWitnessTransferFrom,
|
|
19491
19850
|
hashRequestId: () => hashRequestId,
|
|
19492
19851
|
hashSolanaDeposit: () => hashSolanaDeposit,
|
|
19493
|
-
hashTvmPermitWitnessTransferFrom: () =>
|
|
19852
|
+
hashTvmPermitWitnessTransferFrom: () => import_tvm_escrow_encoding.hashTvmPermitWitnessTransferFrom,
|
|
19494
19853
|
hexToBytes: () => hexToBytes,
|
|
19495
|
-
|
|
19496
|
-
|
|
19854
|
+
isApiError: () => isApiError,
|
|
19855
|
+
maskChainId: () => import_tvm_escrow_encoding.maskChainId,
|
|
19856
|
+
normalizeAddress: () => import_tvm_escrow_encoding.normalizeAddress,
|
|
19497
19857
|
resolveTurnkeyAddresses: () => resolveTurnkeyAddresses,
|
|
19498
|
-
signPaymentRequest: () =>
|
|
19858
|
+
signPaymentRequest: () => signPaymentRequest2
|
|
19499
19859
|
});
|
|
19500
19860
|
module.exports = __toCommonJS2(index_exports);
|
|
19501
19861
|
var Interceptors = class {
|
|
@@ -19513,7 +19873,7 @@ ${detail}`);
|
|
|
19513
19873
|
}
|
|
19514
19874
|
};
|
|
19515
19875
|
var OpenAPI = {
|
|
19516
|
-
BASE: "https://
|
|
19876
|
+
BASE: "https://payment-gw.production-mainnet.atum.xyz",
|
|
19517
19877
|
CREDENTIALS: "include",
|
|
19518
19878
|
ENCODE_PATH: void 0,
|
|
19519
19879
|
HEADERS: void 0,
|
|
@@ -19686,7 +20046,7 @@ ${detail}`);
|
|
|
19686
20046
|
var getFormData = (options) => {
|
|
19687
20047
|
if (options.formData) {
|
|
19688
20048
|
const formData = new FormData();
|
|
19689
|
-
const
|
|
20049
|
+
const process22 = (key, value) => {
|
|
19690
20050
|
if (isString(value) || isBlob(value)) {
|
|
19691
20051
|
formData.append(key, value);
|
|
19692
20052
|
} else {
|
|
@@ -19695,9 +20055,9 @@ ${detail}`);
|
|
|
19695
20055
|
};
|
|
19696
20056
|
Object.entries(options.formData).filter(([, value]) => value !== void 0 && value !== null).forEach(([key, value]) => {
|
|
19697
20057
|
if (Array.isArray(value)) {
|
|
19698
|
-
value.forEach((v) =>
|
|
20058
|
+
value.forEach((v) => process22(key, v));
|
|
19699
20059
|
} else {
|
|
19700
|
-
|
|
20060
|
+
process22(key, value);
|
|
19701
20061
|
}
|
|
19702
20062
|
});
|
|
19703
20063
|
return formData;
|
|
@@ -19915,8 +20275,26 @@ ${detail}`);
|
|
|
19915
20275
|
* 2. Find optimal settlement routes across chains/assets
|
|
19916
20276
|
* 3. Secure funds in escrow
|
|
19917
20277
|
* 4. Coordinate with settlement agents for execution
|
|
19918
|
-
* 5. Return a real-time result if
|
|
19919
|
-
* otherwise return a payment ID
|
|
20278
|
+
* 5. Return a real-time result if settlement completes inside the synchronous window,
|
|
20279
|
+
* otherwise return a payment ID and status for polling
|
|
20280
|
+
*
|
|
20281
|
+
* **Idempotency.** `request_id` is the idempotency key, scoped to the source account
|
|
20282
|
+
* and originator. Submitting the same `request_id` again returns the ORIGINAL payment
|
|
20283
|
+
* instead of charging a second time, so a client whose request timed out or failed
|
|
20284
|
+
* in transit can safely re-submit.
|
|
20285
|
+
*
|
|
20286
|
+
* Because a re-submission must be admissible on its own, some fields legitimately
|
|
20287
|
+
* differ between attempts and are excluded from the comparison: `quote_deadline` and
|
|
20288
|
+
* `fulfillment_deadline` (both must be in the future, so a later attempt has to move
|
|
20289
|
+
* them), and the `sender_auth` signature they are signed into.
|
|
20290
|
+
*
|
|
20291
|
+
* What must NOT differ is the payment's economics — source account and asset,
|
|
20292
|
+
* destination accounts and assets, `fulfillment_amount`, and `max_source_amount` (the
|
|
20293
|
+
* payer's own risk cap; lowering it on a retry describes a different payment, not the
|
|
20294
|
+
* same one with less headroom). Re-using one `request_id` for a genuinely different
|
|
20295
|
+
* payment is a client bug that would otherwise be silently collapsed onto the first
|
|
20296
|
+
* payment, so it is rejected with `409` and `IDEMPOTENCY_TERMS_MISMATCH`. Use a
|
|
20297
|
+
* distinct `request_id` per payment.
|
|
19920
20298
|
*
|
|
19921
20299
|
* @param data The data for the request.
|
|
19922
20300
|
* @param data.requestBody
|
|
@@ -19933,6 +20311,11 @@ ${detail}`);
|
|
|
19933
20311
|
400: "Invalid request",
|
|
19934
20312
|
401: "Signature or sender authorization could not be verified",
|
|
19935
20313
|
403: "Payment declined during counterparty authorization",
|
|
20314
|
+
409: `The \`request_id\` has already been used for a payment with different economics
|
|
20315
|
+
(\`IDEMPOTENCY_TERMS_MISMATCH\`). Re-submitting one \`request_id\` is how a retry is
|
|
20316
|
+
made safe, so it must identify one payment; use a distinct \`request_id\` per
|
|
20317
|
+
payment.
|
|
20318
|
+
`,
|
|
19936
20319
|
413: "Payment request too large to process",
|
|
19937
20320
|
500: "Internal server error",
|
|
19938
20321
|
503: "A dependency is temporarily unavailable"
|
|
@@ -20217,10 +20600,10 @@ ${detail}`);
|
|
|
20217
20600
|
});
|
|
20218
20601
|
}
|
|
20219
20602
|
};
|
|
20220
|
-
var
|
|
20603
|
+
var PaymentGatewayClient2 = class {
|
|
20221
20604
|
constructor(config, HttpRequest = AxiosHttpRequest) {
|
|
20222
20605
|
this.request = new HttpRequest({
|
|
20223
|
-
BASE: config?.BASE ?? "https://
|
|
20606
|
+
BASE: config?.BASE ?? "https://payment-gw.production-mainnet.atum.xyz",
|
|
20224
20607
|
VERSION: config?.VERSION ?? "1.0.0",
|
|
20225
20608
|
WITH_CREDENTIALS: config?.WITH_CREDENTIALS ?? false,
|
|
20226
20609
|
CREDENTIALS: config?.CREDENTIALS ?? "include",
|
|
@@ -20241,56 +20624,13 @@ ${detail}`);
|
|
|
20241
20624
|
}
|
|
20242
20625
|
};
|
|
20243
20626
|
var import_ethers2 = __require("ethers");
|
|
20244
|
-
var PERMIT_DEADLINE = BigInt(1924991999);
|
|
20245
|
-
function resolvePermitDeadline(deadlineSeconds) {
|
|
20246
|
-
if (deadlineSeconds !== void 0) {
|
|
20247
|
-
return BigInt(Math.floor(Date.now() / 1e3) + deadlineSeconds);
|
|
20248
|
-
}
|
|
20249
|
-
return PERMIT_DEADLINE;
|
|
20250
|
-
}
|
|
20251
|
-
function generatePermitNonce() {
|
|
20252
|
-
const rand = new Uint32Array(1);
|
|
20253
|
-
globalThis.crypto.getRandomValues(rand);
|
|
20254
|
-
return (BigInt(Date.now()) << 32n) + BigInt(rand[0]);
|
|
20255
|
-
}
|
|
20256
|
-
function resolvePermitNonce(nonce) {
|
|
20257
|
-
return nonce !== void 0 ? BigInt(nonce) : generatePermitNonce();
|
|
20258
|
-
}
|
|
20259
20627
|
function assertKeyMatchesSender(matches, sender, derived) {
|
|
20260
20628
|
if (!matches) {
|
|
20261
20629
|
throw new Error(`The private key derives ${derived}, which does not match the sender address ${sender}`);
|
|
20262
20630
|
}
|
|
20263
20631
|
}
|
|
20264
|
-
var import_ethers = __require("ethers");
|
|
20265
|
-
var import_evm_escrow_encoding = __toESM2(require_dist4());
|
|
20266
|
-
function hashRequestId(requestId) {
|
|
20267
|
-
return (0, import_ethers.keccak256)((0, import_ethers.toUtf8Bytes)(requestId));
|
|
20268
|
-
}
|
|
20269
20632
|
var evmAdapter = {
|
|
20270
20633
|
turnkeyAddressFormat: "ADDRESS_FORMAT_ETHEREUM",
|
|
20271
|
-
async buildAuthMessage({ sourceAsset, maxSourceAmount, sourceDefaults, deadlineSeconds, nonce }) {
|
|
20272
|
-
const sourceChainId = sourceAsset.split("/")[0];
|
|
20273
|
-
const chainIdNum = parseInt(sourceChainId.split(":")[1]);
|
|
20274
|
-
const tokenAddress = sourceAsset.split("/")[1].split(":")[1];
|
|
20275
|
-
const permitParams = {
|
|
20276
|
-
chainId: chainIdNum,
|
|
20277
|
-
verifyingContract: import_evm_escrow_encoding.PERMIT2_CONTRACT_ADDRESS,
|
|
20278
|
-
token: tokenAddress,
|
|
20279
|
-
amount: maxSourceAmount,
|
|
20280
|
-
spender: sourceDefaults.escrowContract,
|
|
20281
|
-
nonce: resolvePermitNonce(nonce),
|
|
20282
|
-
deadline: resolvePermitDeadline(deadlineSeconds),
|
|
20283
|
-
reserver: sourceDefaults.quoteSelector,
|
|
20284
|
-
releaser: sourceDefaults.fulfillmentVerifierAccount
|
|
20285
|
-
};
|
|
20286
|
-
const messagePrehash = (0, import_evm_escrow_encoding.createPermitWitnessTransferFromPrehash)(permitParams);
|
|
20287
|
-
const messageHash = (0, import_evm_escrow_encoding.hashPermitWitnessTransferFrom)(messagePrehash);
|
|
20288
|
-
return {
|
|
20289
|
-
messageScheme: "EVM_PERMIT2",
|
|
20290
|
-
messageHash,
|
|
20291
|
-
messagePrehash: JSON.stringify(messagePrehash)
|
|
20292
|
-
};
|
|
20293
|
-
},
|
|
20294
20634
|
formatPrivateKey(key) {
|
|
20295
20635
|
return key.startsWith("0x") ? key : "0x" + key;
|
|
20296
20636
|
},
|
|
@@ -20301,77 +20641,21 @@ ${detail}`);
|
|
|
20301
20641
|
throw new Error("Invalid private key");
|
|
20302
20642
|
}
|
|
20303
20643
|
},
|
|
20304
|
-
/**
|
|
20305
|
-
* Sign the Permit2 PermitWitnessTransferFrom typed data via standard
|
|
20306
|
-
* EIP-712 signing. The prehash is already shaped for direct consumption
|
|
20307
|
-
* by ethers' signTypedData (Permit2 domain has no version/salt; types
|
|
20308
|
-
* omits EIP712Domain since ethers generates that from the domain object).
|
|
20309
|
-
*/
|
|
20310
|
-
async sign(signedMessage, privateKey) {
|
|
20311
|
-
if (!signedMessage.message_prehash) {
|
|
20312
|
-
throw new Error("EVM adapter sign(): signed_messages[i].message_prehash is required");
|
|
20313
|
-
}
|
|
20314
|
-
const prehash = JSON.parse(signedMessage.message_prehash);
|
|
20315
|
-
const wallet = new import_ethers2.ethers.Wallet(privateKey);
|
|
20316
|
-
return wallet.signTypedData(prehash.domain, prehash.types, prehash.message);
|
|
20317
|
-
},
|
|
20318
20644
|
// Called after validatePrivateKey, so ethers.Wallet won't echo a malformed key.
|
|
20319
20645
|
verifyAddressMatchesKey(privateKey, address) {
|
|
20320
20646
|
const derived = new import_ethers2.ethers.Wallet(privateKey).address;
|
|
20321
20647
|
assertKeyMatchesSender(derived.toLowerCase() === address.toLowerCase(), address, derived);
|
|
20322
20648
|
}
|
|
20323
20649
|
};
|
|
20324
|
-
var
|
|
20325
|
-
var
|
|
20326
|
-
var CHAIN_ID_MAP = {
|
|
20327
|
-
"shasta": 2494104990,
|
|
20328
|
-
"mainnet": 728126428
|
|
20329
|
-
};
|
|
20330
|
-
var PERMIT2_FALLBACKS = {
|
|
20331
|
-
"tron:shasta": "TPUqJPASUn1zLvbLBgRZ5pBYrx7WSe5ahp",
|
|
20332
|
-
"tron:mainnet": "TJhMXTHQHeQyMD7TcKQFqAePNgG4b31H9m"
|
|
20333
|
-
};
|
|
20650
|
+
var import_ethers22 = __require("ethers");
|
|
20651
|
+
var import_tvm_escrow_encoding = __toESM2(require_dist4());
|
|
20334
20652
|
var tronAdapter = {
|
|
20335
20653
|
turnkeyAddressFormat: "ADDRESS_FORMAT_TRON",
|
|
20336
|
-
async buildAuthMessage({ sourceAsset, maxSourceAmount, sourceDefaults, deadlineSeconds, nonce }) {
|
|
20337
|
-
const sourceChainId = sourceAsset.split("/")[0];
|
|
20338
|
-
const chainName = sourceChainId.split(":")[1];
|
|
20339
|
-
const chainIdNum = CHAIN_ID_MAP[chainName];
|
|
20340
|
-
if (!chainIdNum) {
|
|
20341
|
-
throw new Error(`Unsupported Tron chain: ${chainName}`);
|
|
20342
|
-
}
|
|
20343
|
-
const tokenAddress = sourceAsset.split("/")[1].split(":")[1];
|
|
20344
|
-
let permit2Address = sourceDefaults.permit2Contract;
|
|
20345
|
-
if (permit2Address === void 0) {
|
|
20346
|
-
permit2Address = PERMIT2_FALLBACKS[sourceChainId];
|
|
20347
|
-
if (!permit2Address) {
|
|
20348
|
-
throw new Error(`don't know Permit2 address for chain ${sourceChainId}`);
|
|
20349
|
-
}
|
|
20350
|
-
}
|
|
20351
|
-
const tvmParams = {
|
|
20352
|
-
chainId: chainIdNum,
|
|
20353
|
-
permit2Address,
|
|
20354
|
-
tokenAddress,
|
|
20355
|
-
amount: maxSourceAmount,
|
|
20356
|
-
spenderAddress: sourceDefaults.escrowContract,
|
|
20357
|
-
nonce: resolvePermitNonce(nonce),
|
|
20358
|
-
deadline: resolvePermitDeadline(deadlineSeconds),
|
|
20359
|
-
reserverAddress: sourceDefaults.quoteSelector,
|
|
20360
|
-
releaserAddress: sourceDefaults.fulfillmentVerifierAccount
|
|
20361
|
-
};
|
|
20362
|
-
const messagePrehash = (0, import_tvm_escrow_encoding2.createTvmPermitWitnessTransferFromPrehash)(tvmParams);
|
|
20363
|
-
const messageHash = (0, import_tvm_escrow_encoding2.hashTvmPermitWitnessTransferFrom)(messagePrehash);
|
|
20364
|
-
return {
|
|
20365
|
-
messageScheme: "EVM_PERMIT2",
|
|
20366
|
-
messageHash,
|
|
20367
|
-
messagePrehash: JSON.stringify(messagePrehash)
|
|
20368
|
-
};
|
|
20369
|
-
},
|
|
20370
20654
|
resolveContractOverrides(sourceDefaults) {
|
|
20371
20655
|
return {
|
|
20372
|
-
quote_selector: (0,
|
|
20656
|
+
quote_selector: (0, import_tvm_escrow_encoding.normalizeAddress)(sourceDefaults.quoteSelector),
|
|
20373
20657
|
fulfillment_verifier: {
|
|
20374
|
-
account: (0,
|
|
20658
|
+
account: (0, import_tvm_escrow_encoding.normalizeAddress)(sourceDefaults.fulfillmentVerifierAccount),
|
|
20375
20659
|
endpoint: sourceDefaults.fulfillmentVerifierEndpoint
|
|
20376
20660
|
}
|
|
20377
20661
|
};
|
|
@@ -20386,129 +20670,64 @@ ${detail}`);
|
|
|
20386
20670
|
throw new Error("Invalid private key");
|
|
20387
20671
|
}
|
|
20388
20672
|
},
|
|
20389
|
-
/**
|
|
20390
|
-
* Tron uses TIP-712 typed-data — same wire format as EIP-712. The prehash
|
|
20391
|
-
* built by createTvmPermitWitnessTransferFromPrehash is now directly
|
|
20392
|
-
* consumable by `wallet.signTypedData(prehash.domain, prehash.types,
|
|
20393
|
-
* prehash.message)`, but this adapter (an internal SDK helper) stays on the
|
|
20394
|
-
* raw-hash sign for parity with the EVM adapter — e2e tests use ethers
|
|
20395
|
-
* directly when they need the typed-data path.
|
|
20396
|
-
*/
|
|
20397
|
-
async sign(signedMessage, privateKey) {
|
|
20398
|
-
const wallet = new import_ethers3.ethers.Wallet(privateKey.startsWith("0x") ? privateKey : "0x" + privateKey);
|
|
20399
|
-
return wallet.signingKey.sign(signedMessage.message).serialized;
|
|
20400
|
-
},
|
|
20401
20673
|
// Tron addresses are the same secp256k1-derived 20 bytes as EVM. Compare the
|
|
20402
20674
|
// derived hex directly against the canonical sender; do NOT run normalizeAddress
|
|
20403
20675
|
// on the derived side — it strips a leading 41, which would corrupt an address
|
|
20404
20676
|
// whose first byte is 0x41.
|
|
20405
20677
|
verifyAddressMatchesKey(privateKey, address) {
|
|
20406
20678
|
const key = privateKey.startsWith("0x") ? privateKey : "0x" + privateKey;
|
|
20407
|
-
const derived = new
|
|
20408
|
-
assertKeyMatchesSender(derived.toLowerCase() === (0,
|
|
20679
|
+
const derived = new import_ethers22.ethers.Wallet(key).address;
|
|
20680
|
+
assertKeyMatchesSender(derived.toLowerCase() === (0, import_tvm_escrow_encoding.normalizeAddress)(address), address, derived);
|
|
20409
20681
|
}
|
|
20410
20682
|
};
|
|
20411
20683
|
var import_tweetnacl = __toESM2(__require("tweetnacl"));
|
|
20412
|
-
var import_bs582 = __toESM2(__require("bs58"));
|
|
20413
|
-
var import_solana_escrow_encoding2 = __toESM2(require_dist32());
|
|
20414
|
-
var import_ethers4 = __require("ethers");
|
|
20415
20684
|
var import_bs58 = __toESM2(__require("bs58"));
|
|
20416
|
-
var
|
|
20417
|
-
|
|
20418
|
-
|
|
20419
|
-
|
|
20420
|
-
|
|
20421
|
-
|
|
20422
|
-
|
|
20423
|
-
|
|
20685
|
+
var solanaAdapter = {
|
|
20686
|
+
turnkeyAddressFormat: "ADDRESS_FORMAT_SOLANA",
|
|
20687
|
+
formatPrivateKey(key) {
|
|
20688
|
+
return key.startsWith("0x") ? key.slice(2) : key;
|
|
20689
|
+
},
|
|
20690
|
+
verifyAddressMatchesKey(privateKey, address) {
|
|
20691
|
+
const derived = deriveSolanaAddress(privateKey);
|
|
20692
|
+
assertKeyMatchesSender(derived === address, address, derived);
|
|
20424
20693
|
}
|
|
20425
|
-
|
|
20426
|
-
|
|
20427
|
-
|
|
20428
|
-
return (0, import_ethers4.hexlify)(bytes);
|
|
20429
|
-
}
|
|
20430
|
-
function hexToBytes(hex) {
|
|
20431
|
-
return (0, import_ethers4.getBytes)(hex.startsWith("0x") ? hex : "0x" + hex);
|
|
20432
|
-
}
|
|
20433
|
-
function generateSolanaPaymentId(requestId, params) {
|
|
20434
|
-
const depositorBytes = base58ToBytes(params.depositor);
|
|
20435
|
-
const reserverBytes = base58ToBytes(params.reserver);
|
|
20436
|
-
const releaserBytes = base58ToBytes(params.releaser);
|
|
20437
|
-
return (0, import_ethers4.keccak256)((0, import_ethers4.concat)([
|
|
20438
|
-
(0, import_ethers4.toUtf8Bytes)(requestId),
|
|
20439
|
-
(0, import_ethers4.toUtf8Bytes)("deposit"),
|
|
20440
|
-
depositorBytes,
|
|
20441
|
-
(0, import_solana_escrow_encoding.encodeU64LE)(params.amount),
|
|
20442
|
-
reserverBytes,
|
|
20443
|
-
releaserBytes,
|
|
20444
|
-
(0, import_solana_escrow_encoding.encodeU64LE)(params.nonce),
|
|
20445
|
-
(0, import_solana_escrow_encoding.encodeU64LE)(params.issuedAt),
|
|
20446
|
-
(0, import_solana_escrow_encoding.encodeU64LE)(params.deadline)
|
|
20447
|
-
]));
|
|
20448
|
-
}
|
|
20449
|
-
function createSolanaDepositPrehash(paymentId, params) {
|
|
20450
|
-
return {
|
|
20451
|
-
payment_id: paymentId,
|
|
20452
|
-
depositor: params.depositor,
|
|
20453
|
-
mint: params.mint,
|
|
20454
|
-
amount: params.amount.toString(),
|
|
20455
|
-
reserver: params.reserver,
|
|
20456
|
-
releaser: params.releaser,
|
|
20457
|
-
nonce: params.nonce.toString(),
|
|
20458
|
-
issued_at: params.issuedAt.toString(),
|
|
20459
|
-
deadline: params.deadline.toString()
|
|
20460
|
-
};
|
|
20461
|
-
}
|
|
20462
|
-
function hashSolanaDeposit(prehash) {
|
|
20463
|
-
const paymentIdBytes = hexToBytes(prehash.payment_id);
|
|
20464
|
-
const depositorBytes = base58ToBytes(prehash.depositor);
|
|
20465
|
-
const mintBytes = base58ToBytes(prehash.mint);
|
|
20466
|
-
const reserverBytes = base58ToBytes(prehash.reserver);
|
|
20467
|
-
const releaserBytes = base58ToBytes(prehash.releaser);
|
|
20468
|
-
return (0, import_ethers4.keccak256)((0, import_ethers4.concat)([
|
|
20469
|
-
(0, import_ethers4.toUtf8Bytes)("deposit"),
|
|
20470
|
-
paymentIdBytes,
|
|
20471
|
-
depositorBytes,
|
|
20472
|
-
mintBytes,
|
|
20473
|
-
(0, import_solana_escrow_encoding.encodeU64LE)(BigInt(prehash.amount)),
|
|
20474
|
-
reserverBytes,
|
|
20475
|
-
releaserBytes,
|
|
20476
|
-
(0, import_solana_escrow_encoding.encodeU64LE)(BigInt(prehash.nonce)),
|
|
20477
|
-
(0, import_solana_escrow_encoding.encodeU64LE)(BigInt(prehash.issued_at)),
|
|
20478
|
-
(0, import_solana_escrow_encoding.encodeU64LE)(BigInt(prehash.deadline))
|
|
20479
|
-
]));
|
|
20480
|
-
}
|
|
20481
|
-
function generateSolanaNonce() {
|
|
20482
|
-
return (0, import_solana_escrow_encoding.generateNonce)();
|
|
20694
|
+
};
|
|
20695
|
+
function deriveSolanaAddress(privateKey) {
|
|
20696
|
+
return import_bs58.default.encode(import_tweetnacl.default.sign.keyPair.fromSecretKey(secretKeyFromPrivate(privateKey)).publicKey);
|
|
20483
20697
|
}
|
|
20484
|
-
function
|
|
20485
|
-
|
|
20486
|
-
|
|
20487
|
-
|
|
20488
|
-
|
|
20489
|
-
|
|
20490
|
-
|
|
20491
|
-
|
|
20698
|
+
function secretKeyFromPrivate(privateKey) {
|
|
20699
|
+
if (/^[0-9a-fA-F]{64}$/.test(privateKey)) {
|
|
20700
|
+
const seed = new Uint8Array(32);
|
|
20701
|
+
for (let i = 0; i < 32; i++) {
|
|
20702
|
+
seed[i] = parseInt(privateKey.substring(i * 2, i * 2 + 2), 16);
|
|
20703
|
+
}
|
|
20704
|
+
return import_tweetnacl.default.sign.keyPair.fromSeed(seed).secretKey;
|
|
20705
|
+
}
|
|
20706
|
+
const decoded = import_bs58.default.decode(privateKey);
|
|
20707
|
+
if (decoded.length === 64) {
|
|
20708
|
+
return decoded;
|
|
20709
|
+
}
|
|
20710
|
+
if (decoded.length === 32) {
|
|
20711
|
+
return import_tweetnacl.default.sign.keyPair.fromSeed(decoded).secretKey;
|
|
20712
|
+
}
|
|
20713
|
+
throw new Error(`Invalid Solana private key length: expected 32 or 64 bytes, got ${decoded.length}`);
|
|
20492
20714
|
}
|
|
20493
|
-
|
|
20494
|
-
|
|
20715
|
+
var adapters = {
|
|
20716
|
+
"eip155": evmAdapter,
|
|
20717
|
+
"tron": tronAdapter,
|
|
20718
|
+
"solana": solanaAdapter
|
|
20719
|
+
};
|
|
20720
|
+
function getChainAdapter(sourceChainId) {
|
|
20721
|
+
const prefix = sourceChainId.split(":")[0];
|
|
20722
|
+
const adapter = adapters[prefix];
|
|
20723
|
+
if (!adapter) throw new Error(`Unsupported source chain: ${sourceChainId}`);
|
|
20724
|
+
return adapter;
|
|
20495
20725
|
}
|
|
20496
|
-
function
|
|
20497
|
-
const
|
|
20498
|
-
|
|
20499
|
-
|
|
20500
|
-
|
|
20501
|
-
mint: import_solana_escrow_encoding.Pubkey.fromBase58(prehash.mint),
|
|
20502
|
-
amount: BigInt(prehash.amount),
|
|
20503
|
-
reserver: import_solana_escrow_encoding.Pubkey.fromBase58(prehash.reserver),
|
|
20504
|
-
releaser: import_solana_escrow_encoding.Pubkey.fromBase58(prehash.releaser),
|
|
20505
|
-
nonce: BigInt(prehash.nonce),
|
|
20506
|
-
issuedAt: BigInt(prehash.issued_at),
|
|
20507
|
-
deadline: BigInt(prehash.deadline)
|
|
20508
|
-
},
|
|
20509
|
-
domain
|
|
20510
|
-
);
|
|
20511
|
-
return bytesToHex(hash);
|
|
20726
|
+
function namespaceForTurnkeyAddressFormat(addressFormat) {
|
|
20727
|
+
for (const [namespace, adapter] of Object.entries(adapters)) {
|
|
20728
|
+
if (adapter.turnkeyAddressFormat === addressFormat) return namespace;
|
|
20729
|
+
}
|
|
20730
|
+
return void 0;
|
|
20512
20731
|
}
|
|
20513
20732
|
var DEFAULT_SOLANA_RPC_URLS = {
|
|
20514
20733
|
"5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp": "https://api.mainnet-beta.solana.com",
|
|
@@ -20575,117 +20794,7 @@ ${detail}`);
|
|
|
20575
20794
|
}
|
|
20576
20795
|
return BigInt(Math.floor(Date.now() / 1e3)) - SOLANA_ISSUED_AT_FALLBACK_SKEW_SECS;
|
|
20577
20796
|
}
|
|
20578
|
-
var
|
|
20579
|
-
turnkeyAddressFormat: "ADDRESS_FORMAT_SOLANA",
|
|
20580
|
-
async buildAuthMessage({ sourceAsset, depositor, maxSourceAmount, requestId, sourceDefaults, solanaRpcUrl, solanaClockReader, solanaLogger }) {
|
|
20581
|
-
const sourceChainId = sourceAsset.split("/")[0];
|
|
20582
|
-
const tokenMint = sourceAsset.split("/")[1].split(":")[1];
|
|
20583
|
-
const nonce = generateSolanaNonce();
|
|
20584
|
-
const issuedAt = await resolveSolanaIssuedAt({
|
|
20585
|
-
sourceChainId,
|
|
20586
|
-
rpcUrlOverride: solanaRpcUrl,
|
|
20587
|
-
reader: solanaClockReader,
|
|
20588
|
-
logger: solanaLogger
|
|
20589
|
-
});
|
|
20590
|
-
const deadline = issuedAt + BigInt(REPLAY_HORIZON_SECS - 8);
|
|
20591
|
-
const solanaParams = {
|
|
20592
|
-
depositor,
|
|
20593
|
-
mint: tokenMint,
|
|
20594
|
-
amount: BigInt(maxSourceAmount),
|
|
20595
|
-
reserver: sourceDefaults.quoteSelector,
|
|
20596
|
-
releaser: sourceDefaults.fulfillmentVerifierAccount,
|
|
20597
|
-
nonce,
|
|
20598
|
-
issuedAt,
|
|
20599
|
-
deadline,
|
|
20600
|
-
requestId
|
|
20601
|
-
};
|
|
20602
|
-
const paymentId = generateSolanaPaymentIdV3(requestId);
|
|
20603
|
-
const prehash = createSolanaDepositPrehash(paymentId, solanaParams);
|
|
20604
|
-
if (!sourceDefaults.svmSignatureClusterId || sourceDefaults.svmSignatureDomainVersion == null) {
|
|
20605
|
-
throw new Error(
|
|
20606
|
-
"Solana source requires svm_signature_cluster_id and svm_signature_domain_version from payment-gw /defaults (V3 escrow domain separation). Is the gateway on V3?"
|
|
20607
|
-
);
|
|
20608
|
-
}
|
|
20609
|
-
const domain = {
|
|
20610
|
-
clusterId: clusterIdFromName2(sourceDefaults.svmSignatureClusterId),
|
|
20611
|
-
signatureDomainVersion: sourceDefaults.svmSignatureDomainVersion,
|
|
20612
|
-
programId: import_solana_escrow_encoding2.Pubkey.fromBase58(sourceDefaults.escrowContract)
|
|
20613
|
-
};
|
|
20614
|
-
const depositHash = hashSolanaDepositV3(prehash, domain);
|
|
20615
|
-
return {
|
|
20616
|
-
messageScheme: "SOLANA",
|
|
20617
|
-
messageHash: depositHash,
|
|
20618
|
-
messagePrehash: JSON.stringify(prehash)
|
|
20619
|
-
};
|
|
20620
|
-
},
|
|
20621
|
-
formatPrivateKey(key) {
|
|
20622
|
-
return key.startsWith("0x") ? key.slice(2) : key;
|
|
20623
|
-
},
|
|
20624
|
-
/**
|
|
20625
|
-
* Solana has no EIP-712-style typed-data standard. The prehash structure
|
|
20626
|
-
* still describes what was hashed (for debugging / wallet UX), but the
|
|
20627
|
-
* canonical signing input is the chain-specific digest already in
|
|
20628
|
-
* signedMessage.message. We sign that with ed25519.
|
|
20629
|
-
*/
|
|
20630
|
-
async sign(signedMessage, privateKey) {
|
|
20631
|
-
const messageBytes = new Uint8Array(Buffer.from(signedMessage.message.replace("0x", ""), "hex"));
|
|
20632
|
-
const secretKey = secretKeyFromPrivate(privateKey);
|
|
20633
|
-
const sig = import_tweetnacl.default.sign.detached(messageBytes, secretKey);
|
|
20634
|
-
return "0x" + Buffer.from(sig).toString("hex");
|
|
20635
|
-
},
|
|
20636
|
-
/**
|
|
20637
|
-
* Solana Ed25519 signatures are not public-key-recoverable (unlike EVM
|
|
20638
|
-
* secp256k1, where ecrecover derives the signer from the signature). The
|
|
20639
|
-
* on-chain Ed25519 verify instruction must therefore be given the signer's
|
|
20640
|
-
* public key explicitly, so we ship it as signed_messages[0].payload.delegate_signer.
|
|
20641
|
-
* In the self-custody CLI flow the signer is the depositor itself, so this
|
|
20642
|
-
* equals source.account.
|
|
20643
|
-
*/
|
|
20644
|
-
deriveDelegateSigner(privateKey) {
|
|
20645
|
-
return deriveSolanaAddress(privateKey);
|
|
20646
|
-
},
|
|
20647
|
-
verifyAddressMatchesKey(privateKey, address) {
|
|
20648
|
-
const derived = deriveSolanaAddress(privateKey);
|
|
20649
|
-
assertKeyMatchesSender(derived === address, address, derived);
|
|
20650
|
-
}
|
|
20651
|
-
};
|
|
20652
|
-
function deriveSolanaAddress(privateKey) {
|
|
20653
|
-
return import_bs582.default.encode(import_tweetnacl.default.sign.keyPair.fromSecretKey(secretKeyFromPrivate(privateKey)).publicKey);
|
|
20654
|
-
}
|
|
20655
|
-
function secretKeyFromPrivate(privateKey) {
|
|
20656
|
-
if (/^[0-9a-fA-F]{64}$/.test(privateKey)) {
|
|
20657
|
-
const seed = new Uint8Array(32);
|
|
20658
|
-
for (let i = 0; i < 32; i++) {
|
|
20659
|
-
seed[i] = parseInt(privateKey.substring(i * 2, i * 2 + 2), 16);
|
|
20660
|
-
}
|
|
20661
|
-
return import_tweetnacl.default.sign.keyPair.fromSeed(seed).secretKey;
|
|
20662
|
-
}
|
|
20663
|
-
const decoded = import_bs582.default.decode(privateKey);
|
|
20664
|
-
if (decoded.length === 64) {
|
|
20665
|
-
return decoded;
|
|
20666
|
-
}
|
|
20667
|
-
if (decoded.length === 32) {
|
|
20668
|
-
return import_tweetnacl.default.sign.keyPair.fromSeed(decoded).secretKey;
|
|
20669
|
-
}
|
|
20670
|
-
throw new Error(`Invalid Solana private key length: expected 32 or 64 bytes, got ${decoded.length}`);
|
|
20671
|
-
}
|
|
20672
|
-
var adapters = {
|
|
20673
|
-
"eip155": evmAdapter,
|
|
20674
|
-
"tron": tronAdapter,
|
|
20675
|
-
"solana": solanaAdapter
|
|
20676
|
-
};
|
|
20677
|
-
function getChainAdapter(sourceChainId) {
|
|
20678
|
-
const prefix = sourceChainId.split(":")[0];
|
|
20679
|
-
const adapter = adapters[prefix];
|
|
20680
|
-
if (!adapter) throw new Error(`Unsupported source chain: ${sourceChainId}`);
|
|
20681
|
-
return adapter;
|
|
20682
|
-
}
|
|
20683
|
-
function namespaceForTurnkeyAddressFormat(addressFormat) {
|
|
20684
|
-
for (const [namespace, adapter] of Object.entries(adapters)) {
|
|
20685
|
-
if (adapter.turnkeyAddressFormat === addressFormat) return namespace;
|
|
20686
|
-
}
|
|
20687
|
-
return void 0;
|
|
20688
|
-
}
|
|
20797
|
+
var import_payment_request_sender_auth2 = __toESM2(require_dist42());
|
|
20689
20798
|
var $AuthorizationResult = {
|
|
20690
20799
|
type: "object",
|
|
20691
20800
|
description: `The result of a counterparty authorization request. Contains either
|
|
@@ -20857,8 +20966,11 @@ Leave empty to use the default verifier.
|
|
|
20857
20966
|
endpoint: {
|
|
20858
20967
|
type: "string",
|
|
20859
20968
|
format: "uri",
|
|
20860
|
-
description:
|
|
20861
|
-
|
|
20969
|
+
description: `Origin of the fulfillment verifier service, with no path \u2014 the caller
|
|
20970
|
+
appends the verifier's own API paths. The gateway's \`/defaults\` response
|
|
20971
|
+
supplies the default fulfillment verifier for each chain.
|
|
20972
|
+
`,
|
|
20973
|
+
example: "https://veri-fill.production-testnet.atum.xyz"
|
|
20862
20974
|
}
|
|
20863
20975
|
}
|
|
20864
20976
|
},
|
|
@@ -21174,11 +21286,18 @@ Required when regulatory compliance or KYC verification is needed for the paymen
|
|
|
21174
21286
|
};
|
|
21175
21287
|
var $PaymentResponse = {
|
|
21176
21288
|
type: "object",
|
|
21177
|
-
description: `Response from submitting a payment request. If
|
|
21178
|
-
the response
|
|
21179
|
-
Otherwise
|
|
21180
|
-
/v1/payments/{paymentId}/status
|
|
21289
|
+
description: `Response from submitting a payment request. If settlement completes inside the
|
|
21290
|
+
gateway's synchronous window, the response includes a fulfillment_confirmation with
|
|
21291
|
+
full settlement details. Otherwise you receive a payment_id plus the payment's
|
|
21292
|
+
current \`status\`, and can poll /v1/payments/{paymentId}/status for updates.
|
|
21293
|
+
|
|
21294
|
+
Read \`status\` before deciding what to do next: a \`pending\` payment is in flight and
|
|
21295
|
+
must NOT be re-submitted under a new request_id (that would be a second payment),
|
|
21296
|
+
whereas a \`failed\` or \`cancelled\` one is terminal \u2014 re-submitting it under the SAME
|
|
21297
|
+
request_id resolves to the same terminal payment, so a genuine re-attempt needs a
|
|
21298
|
+
new request_id.
|
|
21181
21299
|
`,
|
|
21300
|
+
required: ["payment_id", "status", "idempotent_replay"],
|
|
21182
21301
|
properties: {
|
|
21183
21302
|
payment_id: {
|
|
21184
21303
|
type: "string",
|
|
@@ -21186,8 +21305,60 @@ Otherwise, you'll receive a payment_id that you can use to poll the
|
|
|
21186
21305
|
`,
|
|
21187
21306
|
example: "550e8400-e29b-41d4-a716-446655440000"
|
|
21188
21307
|
},
|
|
21308
|
+
status: {
|
|
21309
|
+
type: "string",
|
|
21310
|
+
enum: ["pending", "completed", "failed", "cancelled"],
|
|
21311
|
+
description: `Current status of the payment, with the same meaning as on
|
|
21312
|
+
/v1/payments/{paymentId}/status:
|
|
21313
|
+
- \`pending\`: accepted and being processed
|
|
21314
|
+
- \`completed\`: successfully delivered
|
|
21315
|
+
- \`failed\`: failed (funds returned if escrowed)
|
|
21316
|
+
- \`cancelled\`: cancelled before completion
|
|
21317
|
+
|
|
21318
|
+
Present on every response. \`completed\` is always accompanied by
|
|
21319
|
+
fulfillment_confirmation; \`failed\` is accompanied by \`error\` where a reason has
|
|
21320
|
+
been recorded.
|
|
21321
|
+
`
|
|
21322
|
+
},
|
|
21323
|
+
idempotent_replay: {
|
|
21324
|
+
type: "boolean",
|
|
21325
|
+
description: `Whether this response describes a payment that already existed, rather than one
|
|
21326
|
+
created by this request. \`true\` means the request_id had been used before and you
|
|
21327
|
+
are being handed the ORIGINAL payment \u2014 no second payment was created and nothing
|
|
21328
|
+
additional was charged.
|
|
21329
|
+
|
|
21330
|
+
**Re-attempting a payment.** Re-submit the same request and you get the same payment
|
|
21331
|
+
back. You may re-send the original bytes unchanged: the deadlines will have expired by
|
|
21332
|
+
then \u2014 \`quote_deadline\` bounds the auction and is short, while this endpoint may hold a
|
|
21333
|
+
submission for up to 30 seconds \u2014 and an expired deadline on a re-submission is not an
|
|
21334
|
+
error, because the request is resolved onto the payment that already exists rather than
|
|
21335
|
+
used to create one.
|
|
21336
|
+
|
|
21337
|
+
Re-signing with fresh deadlines is equally fine and returns the same payment. What you
|
|
21338
|
+
must NOT change is the request_id, and what you must not change under it is the
|
|
21339
|
+
payment's economics \u2014 source, destination, fulfillment_amount, max_source_amount \u2014 which
|
|
21340
|
+
are rejected with 409 IDEMPOTENCY_TERMS_MISMATCH. Deadlines and the signature are
|
|
21341
|
+
exempt precisely so that a re-attempt is possible.
|
|
21342
|
+
|
|
21343
|
+
A genuinely new payment needs a NEW request_id. In particular a \`failed\` payment is
|
|
21344
|
+
terminal: re-submitting its request_id keeps returning that dead payment, so recovering
|
|
21345
|
+
means starting a new one under a new key.
|
|
21346
|
+
|
|
21347
|
+
Present on every response, \`false\` for a newly created payment. A response without
|
|
21348
|
+
the field is from a gateway predating it, not a newly created payment.
|
|
21349
|
+
|
|
21350
|
+
This is the field to read when reconciling a suspected double charge: two
|
|
21351
|
+
submissions where the second reports \`true\` are one payment, whereas two both
|
|
21352
|
+
reporting \`false\` are two. It says nothing about how far the payment has got \u2014
|
|
21353
|
+
read \`status\` for that.
|
|
21354
|
+
`,
|
|
21355
|
+
example: false
|
|
21356
|
+
},
|
|
21189
21357
|
fulfillment_confirmation: {
|
|
21190
21358
|
"$ref": "#/components/schemas/FulfillmentConfirmation"
|
|
21359
|
+
},
|
|
21360
|
+
error: {
|
|
21361
|
+
"$ref": "#/components/schemas/PaymentError"
|
|
21191
21362
|
}
|
|
21192
21363
|
}
|
|
21193
21364
|
};
|
|
@@ -21726,8 +21897,11 @@ Leave empty to use the default selector.
|
|
|
21726
21897
|
endpoint: {
|
|
21727
21898
|
type: "string",
|
|
21728
21899
|
format: "uri",
|
|
21729
|
-
description:
|
|
21730
|
-
|
|
21900
|
+
description: `Origin of the fulfillment verifier service, with no path \u2014 the caller
|
|
21901
|
+
appends the verifier's own API paths. The gateway's \`/defaults\` response
|
|
21902
|
+
supplies the default fulfillment verifier for each chain.
|
|
21903
|
+
`,
|
|
21904
|
+
example: "https://veri-fill.production-testnet.atum.xyz"
|
|
21731
21905
|
}
|
|
21732
21906
|
}
|
|
21733
21907
|
},
|
|
@@ -21847,7 +22021,7 @@ bid_award.fulfillment_quote_json.
|
|
|
21847
22021
|
fulfillment_quote: {
|
|
21848
22022
|
type: "object",
|
|
21849
22023
|
description: `The settler-signed FulfillmentQuote (structurally the canonical FulfillmentQuote/v1
|
|
21850
|
-
declaration at https://schemas.atum.
|
|
22024
|
+
declaration at https://schemas.atum.xyz/declarations/FulfillmentQuote/v1), returned
|
|
21851
22025
|
verbatim as an opaque signed document. A client recomputes quote_hash over the returned
|
|
21852
22026
|
bytes and verifies the settler signature, then re-embeds them into
|
|
21853
22027
|
bid_award.fulfillment_quote_json at award. quote_hash is canonicalization-based
|
|
@@ -21873,7 +22047,7 @@ values and WOULD change quote_hash), so the Go binding exposes it as a raw JSON
|
|
|
21873
22047
|
fulfillment_quote: {
|
|
21874
22048
|
type: "object",
|
|
21875
22049
|
description: `The settler-signed FulfillmentQuote (structurally the canonical FulfillmentQuote/v1
|
|
21876
|
-
declaration at https://schemas.atum.
|
|
22050
|
+
declaration at https://schemas.atum.xyz/declarations/FulfillmentQuote/v1), returned
|
|
21877
22051
|
verbatim as an opaque signed document. A client recomputes quote_hash over the returned
|
|
21878
22052
|
bytes and verifies the settler signature, then re-embeds them into
|
|
21879
22053
|
bid_award.fulfillment_quote_json at award. quote_hash is canonicalization-based
|
|
@@ -22186,16 +22360,103 @@ payment-status endpoint.
|
|
|
22186
22360
|
}
|
|
22187
22361
|
}
|
|
22188
22362
|
};
|
|
22363
|
+
function isApiError(err) {
|
|
22364
|
+
return err instanceof ApiError;
|
|
22365
|
+
}
|
|
22366
|
+
function getErrorResponse(err) {
|
|
22367
|
+
if (!(err instanceof ApiError)) {
|
|
22368
|
+
return void 0;
|
|
22369
|
+
}
|
|
22370
|
+
const body = err.body;
|
|
22371
|
+
if (body && typeof body === "object" && typeof body.code === "string" && typeof body.message === "string") {
|
|
22372
|
+
return body;
|
|
22373
|
+
}
|
|
22374
|
+
return void 0;
|
|
22375
|
+
}
|
|
22376
|
+
var import_ethers3 = __require("ethers");
|
|
22377
|
+
var import_evm_escrow_encoding2 = __toESM2(require_dist22());
|
|
22378
|
+
function hashRequestId(requestId) {
|
|
22379
|
+
return (0, import_ethers3.keccak256)((0, import_ethers3.toUtf8Bytes)(requestId));
|
|
22380
|
+
}
|
|
22381
|
+
var import_ethers4 = __require("ethers");
|
|
22382
|
+
var import_bs582 = __toESM2(__require("bs58"));
|
|
22383
|
+
var import_solana_escrow_encoding = __toESM2(require_dist32());
|
|
22384
|
+
var REPLAY_HORIZON_SECS = 128;
|
|
22385
|
+
var TOTAL_BUCKETS = 131072;
|
|
22386
|
+
var DEPOSIT_MESSAGE_SIZE = 199;
|
|
22387
|
+
function base58ToBytes(address) {
|
|
22388
|
+
const bytes = import_bs582.default.decode(address);
|
|
22389
|
+
if (bytes.length !== 32) {
|
|
22390
|
+
throw new Error(`Invalid Solana public key length: expected 32 bytes, got ${bytes.length}`);
|
|
22391
|
+
}
|
|
22392
|
+
return bytes;
|
|
22393
|
+
}
|
|
22394
|
+
function bytesToHex(bytes) {
|
|
22395
|
+
return (0, import_ethers4.hexlify)(bytes);
|
|
22396
|
+
}
|
|
22397
|
+
function hexToBytes(hex) {
|
|
22398
|
+
return (0, import_ethers4.getBytes)(hex.startsWith("0x") ? hex : "0x" + hex);
|
|
22399
|
+
}
|
|
22400
|
+
function generateSolanaPaymentId(requestId, params) {
|
|
22401
|
+
const depositorBytes = base58ToBytes(params.depositor);
|
|
22402
|
+
const reserverBytes = base58ToBytes(params.reserver);
|
|
22403
|
+
const releaserBytes = base58ToBytes(params.releaser);
|
|
22404
|
+
return (0, import_ethers4.keccak256)((0, import_ethers4.concat)([
|
|
22405
|
+
(0, import_ethers4.toUtf8Bytes)(requestId),
|
|
22406
|
+
(0, import_ethers4.toUtf8Bytes)("deposit"),
|
|
22407
|
+
depositorBytes,
|
|
22408
|
+
(0, import_solana_escrow_encoding.encodeU64LE)(params.amount),
|
|
22409
|
+
reserverBytes,
|
|
22410
|
+
releaserBytes,
|
|
22411
|
+
(0, import_solana_escrow_encoding.encodeU64LE)(params.nonce),
|
|
22412
|
+
(0, import_solana_escrow_encoding.encodeU64LE)(params.issuedAt),
|
|
22413
|
+
(0, import_solana_escrow_encoding.encodeU64LE)(params.deadline)
|
|
22414
|
+
]));
|
|
22415
|
+
}
|
|
22416
|
+
function createSolanaDepositPrehash(paymentId, params) {
|
|
22417
|
+
return {
|
|
22418
|
+
payment_id: paymentId,
|
|
22419
|
+
depositor: params.depositor,
|
|
22420
|
+
mint: params.mint,
|
|
22421
|
+
amount: params.amount.toString(),
|
|
22422
|
+
reserver: params.reserver,
|
|
22423
|
+
releaser: params.releaser,
|
|
22424
|
+
nonce: params.nonce.toString(),
|
|
22425
|
+
issued_at: params.issuedAt.toString(),
|
|
22426
|
+
deadline: params.deadline.toString()
|
|
22427
|
+
};
|
|
22428
|
+
}
|
|
22429
|
+
function hashSolanaDeposit(prehash) {
|
|
22430
|
+
const paymentIdBytes = hexToBytes(prehash.payment_id);
|
|
22431
|
+
const depositorBytes = base58ToBytes(prehash.depositor);
|
|
22432
|
+
const mintBytes = base58ToBytes(prehash.mint);
|
|
22433
|
+
const reserverBytes = base58ToBytes(prehash.reserver);
|
|
22434
|
+
const releaserBytes = base58ToBytes(prehash.releaser);
|
|
22435
|
+
return (0, import_ethers4.keccak256)((0, import_ethers4.concat)([
|
|
22436
|
+
(0, import_ethers4.toUtf8Bytes)("deposit"),
|
|
22437
|
+
paymentIdBytes,
|
|
22438
|
+
depositorBytes,
|
|
22439
|
+
mintBytes,
|
|
22440
|
+
(0, import_solana_escrow_encoding.encodeU64LE)(BigInt(prehash.amount)),
|
|
22441
|
+
reserverBytes,
|
|
22442
|
+
releaserBytes,
|
|
22443
|
+
(0, import_solana_escrow_encoding.encodeU64LE)(BigInt(prehash.nonce)),
|
|
22444
|
+
(0, import_solana_escrow_encoding.encodeU64LE)(BigInt(prehash.issued_at)),
|
|
22445
|
+
(0, import_solana_escrow_encoding.encodeU64LE)(BigInt(prehash.deadline))
|
|
22446
|
+
]));
|
|
22447
|
+
}
|
|
22448
|
+
function generateSolanaNonce() {
|
|
22449
|
+
return (0, import_solana_escrow_encoding.generateNonce)();
|
|
22450
|
+
}
|
|
22451
|
+
var import_payment_request_sender_auth3 = __toESM2(require_dist42());
|
|
22189
22452
|
var RawSenderSigner = class {
|
|
22190
|
-
constructor(
|
|
22191
|
-
|
|
22192
|
-
this.privateKey = privateKey;
|
|
22453
|
+
constructor(network, privateKey) {
|
|
22454
|
+
const adapter = getChainAdapter(network);
|
|
22193
22455
|
adapter.validatePrivateKey?.(privateKey);
|
|
22456
|
+
this.inner = (0, import_payment_request_sender_auth3.localKeySigner)(network, adapter.formatPrivateKey(privateKey));
|
|
22194
22457
|
}
|
|
22195
|
-
|
|
22196
|
-
|
|
22197
|
-
const delegateSigner = this.adapter.deriveDelegateSigner?.(this.privateKey);
|
|
22198
|
-
return { signature, ...delegateSigner ? { delegateSigner } : {} };
|
|
22458
|
+
sign(signedMessage) {
|
|
22459
|
+
return this.inner.sign(signedMessage);
|
|
22199
22460
|
}
|
|
22200
22461
|
};
|
|
22201
22462
|
async function loadImpl() {
|
|
@@ -22225,21 +22486,21 @@ payment-status endpoint.
|
|
|
22225
22486
|
);
|
|
22226
22487
|
}
|
|
22227
22488
|
};
|
|
22228
|
-
function
|
|
22489
|
+
function createSenderSigner2(sourceChainId, opts) {
|
|
22229
22490
|
const chainPrefix = sourceChainId.split(":")[0];
|
|
22230
22491
|
if (opts.provider === "turnkey") {
|
|
22231
22492
|
return new TurnkeySenderSigner(chainPrefix, opts);
|
|
22232
22493
|
}
|
|
22233
22494
|
const adapter = getChainAdapter(sourceChainId);
|
|
22234
22495
|
const privateKey = adapter.formatPrivateKey(opts.privateKey);
|
|
22235
|
-
|
|
22496
|
+
adapter.validatePrivateKey?.(opts.privateKey);
|
|
22236
22497
|
if (opts.pinnedAddress) {
|
|
22237
22498
|
if (!adapter.verifyAddressMatchesKey) {
|
|
22238
22499
|
throw new Error(`pinnedAddress was provided but the ${sourceChainId} adapter cannot verify the key derives it`);
|
|
22239
22500
|
}
|
|
22240
22501
|
adapter.verifyAddressMatchesKey(privateKey, opts.pinnedAddress);
|
|
22241
22502
|
}
|
|
22242
|
-
return
|
|
22503
|
+
return new RawSenderSigner(sourceChainId, opts.privateKey);
|
|
22243
22504
|
}
|
|
22244
22505
|
async function resolveTurnkeyAddresses(cfg) {
|
|
22245
22506
|
const impl = await Promise.resolve().then(() => (init_turnkey_impl(), turnkey_impl_exports));
|
|
@@ -22260,7 +22521,7 @@ payment-status endpoint.
|
|
|
22260
22521
|
return addresses;
|
|
22261
22522
|
}
|
|
22262
22523
|
var PAYMENT_REQUEST_VERSION = "1.0";
|
|
22263
|
-
async function
|
|
22524
|
+
async function signPaymentRequest2(request2, signer) {
|
|
22264
22525
|
if (!request2.sender_auth?.signed_messages?.length) {
|
|
22265
22526
|
throw new Error("signPaymentRequest: request.sender_auth.signed_messages must contain at least one message to sign");
|
|
22266
22527
|
}
|
|
@@ -22274,7 +22535,8 @@ payment-status endpoint.
|
|
|
22274
22535
|
}
|
|
22275
22536
|
return request2;
|
|
22276
22537
|
}
|
|
22277
|
-
var defaultGateway = "https://payment-
|
|
22538
|
+
var defaultGateway = "https://payment-gw.production-testnet.atum.xyz";
|
|
22539
|
+
var OpenAPI2 = { ...OpenAPI, BASE: defaultGateway };
|
|
22278
22540
|
var DEFAULT_QUOTE_DEADLINE_SECONDS = 5;
|
|
22279
22541
|
var DEFAULT_FULFILLMENT_DEADLINE_SECONDS = 3600;
|
|
22280
22542
|
var DEFAULT_PAYMENT_QUOTE_DEADLINE_SECONDS = 10;
|
|
@@ -22307,18 +22569,25 @@ payment-status endpoint.
|
|
|
22307
22569
|
}
|
|
22308
22570
|
async function assemblePaymentRequest(params) {
|
|
22309
22571
|
const sourceChainId = params.sourceAsset.split("/")[0];
|
|
22572
|
+
const namespace = sourceChainId.split(":")[0];
|
|
22310
22573
|
const adapter = getChainAdapter(sourceChainId);
|
|
22311
|
-
const
|
|
22574
|
+
const nonce = params.nonce ?? (namespace === "solana" ? (0, import_payment_request_sender_auth2.deterministicSolanaNonce)({ requestId: params.requestId, depositor: params.depositor }) : (0, import_payment_request_sender_auth2.deterministicPermitNonce)({ requestId: params.requestId, depositor: params.depositor }));
|
|
22575
|
+
const auth = await (0, import_payment_request_sender_auth2.getChainAdapter)(sourceChainId).buildAuthMessage({
|
|
22312
22576
|
sourceAsset: params.sourceAsset,
|
|
22313
22577
|
depositor: params.depositor,
|
|
22314
22578
|
// The gateway pins the signed deposit amount to max_source_amount (the cap).
|
|
22315
22579
|
maxSourceAmount: params.maxSourceAmount,
|
|
22316
22580
|
requestId: params.requestId,
|
|
22317
22581
|
sourceDefaults: params.sourceDefaults,
|
|
22318
|
-
|
|
22319
|
-
nonce
|
|
22320
|
-
|
|
22321
|
-
|
|
22582
|
+
deadline: params.deadline,
|
|
22583
|
+
nonce,
|
|
22584
|
+
...namespace === "solana" ? {
|
|
22585
|
+
solanaClockReader: (chainId) => resolveSolanaIssuedAt({
|
|
22586
|
+
sourceChainId: chainId,
|
|
22587
|
+
rpcUrlOverride: params.solanaRpcUrl,
|
|
22588
|
+
reader: params.solanaClockReader
|
|
22589
|
+
})
|
|
22590
|
+
} : {}
|
|
22322
22591
|
});
|
|
22323
22592
|
const contractOverrides = adapter.resolveContractOverrides?.(params.sourceDefaults);
|
|
22324
22593
|
return {
|
|
@@ -22354,10 +22623,12 @@ payment-status endpoint.
|
|
|
22354
22623
|
}
|
|
22355
22624
|
};
|
|
22356
22625
|
}
|
|
22357
|
-
var
|
|
22626
|
+
var PaymentGatewayClient22 = class extends PaymentGatewayClient2 {
|
|
22358
22627
|
constructor(config, HttpRequest = AxiosHttpRequest) {
|
|
22359
|
-
|
|
22360
|
-
|
|
22628
|
+
const envBase = (typeof process !== "undefined" ? process.env.GATEWAY_URL : void 0)?.trim();
|
|
22629
|
+
const base = config?.BASE ?? (envBase || defaultGateway);
|
|
22630
|
+
super({ ...config, BASE: base }, HttpRequest);
|
|
22631
|
+
this.baseUrl = base;
|
|
22361
22632
|
}
|
|
22362
22633
|
/**
|
|
22363
22634
|
* Fetches chain defaults from the payment gateway.
|
|
@@ -22445,14 +22716,35 @@ payment-status endpoint.
|
|
|
22445
22716
|
* @returns A complete PaymentRequest object without the signature
|
|
22446
22717
|
*/
|
|
22447
22718
|
async preparePaymentRequest(params) {
|
|
22448
|
-
const
|
|
22719
|
+
const now = (params.now ?? Date.now)();
|
|
22720
|
+
const { quote_deadline, fulfillment_deadline } = resolveDeadlines({ ...params, now: () => now }, DEFAULT_PAYMENT_QUOTE_DEADLINE_SECONDS);
|
|
22449
22721
|
const sourceChainId = params.sourceAsset.split("/")[0];
|
|
22450
22722
|
const destChainId = params.destinationAsset.split("/")[0];
|
|
22451
22723
|
const [sourceDefaults, fulfillmentProxy] = await Promise.all([
|
|
22452
22724
|
params.resolvedDefaults?.source ?? this.fetchChainDefaults(sourceChainId),
|
|
22453
22725
|
params.resolvedDefaults?.destination?.fulfillmentProxy ?? this.fetchChainDefaults(destChainId).then((d) => d.fulfillmentProxy)
|
|
22454
22726
|
]);
|
|
22455
|
-
|
|
22727
|
+
if (!params.requestId) {
|
|
22728
|
+
throw new Error(
|
|
22729
|
+
"payment-gateway-client: requestId is required \u2014 it is the idempotency key that seeds the deterministic deposit nonce; supply a stable id per logical payment and reuse it on retry"
|
|
22730
|
+
);
|
|
22731
|
+
}
|
|
22732
|
+
const requestId = params.requestId;
|
|
22733
|
+
const sourceNamespace = sourceChainId.split(":")[0];
|
|
22734
|
+
let permitDeadline;
|
|
22735
|
+
if (sourceNamespace !== "solana") {
|
|
22736
|
+
const fulfillmentMs = Date.parse(fulfillment_deadline);
|
|
22737
|
+
if (params.deadlineSeconds !== void 0) {
|
|
22738
|
+
permitDeadline = Math.ceil(now / 1e3) + Math.ceil(params.deadlineSeconds);
|
|
22739
|
+
if (permitDeadline * 1e3 < fulfillmentMs) {
|
|
22740
|
+
throw new Error(
|
|
22741
|
+
`payment-gateway-client: deadlineSeconds (${params.deadlineSeconds}) expires the deposit permit before settlement (fulfillmentDeadlineSeconds). The permit must stay valid until settlement \u2014 pass a deadlineSeconds at least as long as fulfillmentDeadlineSeconds, or omit it to derive it from fulfillment_deadline automatically.`
|
|
22742
|
+
);
|
|
22743
|
+
}
|
|
22744
|
+
} else {
|
|
22745
|
+
permitDeadline = Math.floor(fulfillmentMs / 1e3) + 1;
|
|
22746
|
+
}
|
|
22747
|
+
}
|
|
22456
22748
|
return assemblePaymentRequest({
|
|
22457
22749
|
depositor: params.depositor,
|
|
22458
22750
|
fulfillmentAmount: params.fulfillmentAmount,
|
|
@@ -22466,7 +22758,7 @@ payment-status endpoint.
|
|
|
22466
22758
|
sourceDefaults,
|
|
22467
22759
|
fulfillmentProxy,
|
|
22468
22760
|
nonce: params.nonce,
|
|
22469
|
-
|
|
22761
|
+
deadline: permitDeadline,
|
|
22470
22762
|
solanaRpcUrl: params.solanaRpcUrl,
|
|
22471
22763
|
solanaClockReader: params.solanaClockReader,
|
|
22472
22764
|
settlerRequirements: params.settlerRequirements
|
|
@@ -22553,382 +22845,128 @@ payment-status endpoint.
|
|
|
22553
22845
|
}
|
|
22554
22846
|
});
|
|
22555
22847
|
|
|
22556
|
-
//
|
|
22557
|
-
var
|
|
22558
|
-
|
|
22559
|
-
|
|
22560
|
-
|
|
22561
|
-
|
|
22562
|
-
|
|
22563
|
-
|
|
22564
|
-
|
|
22565
|
-
|
|
22566
|
-
})
|
|
22567
|
-
|
|
22568
|
-
|
|
22569
|
-
|
|
22570
|
-
|
|
22571
|
-
|
|
22572
|
-
|
|
22573
|
-
|
|
22574
|
-
|
|
22575
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22576
|
-
exports.base58ToHex = base58ToHex2;
|
|
22577
|
-
exports.normalizeAddress = normalizeAddress2;
|
|
22578
|
-
var ethers_1 = __require("ethers");
|
|
22579
|
-
var bs58_1 = __importDefault(__require("bs58"));
|
|
22580
|
-
var TVM_MAINNET_PREFIX = "41";
|
|
22581
|
-
function base58ToHex2(base58Address) {
|
|
22582
|
-
if (!base58Address || !base58Address.startsWith("T")) {
|
|
22583
|
-
throw new Error(`Invalid Tron base58 address: ${base58Address}`);
|
|
22584
|
-
}
|
|
22585
|
-
const decoded = bs58_1.default.decode(base58Address);
|
|
22586
|
-
if (decoded.length !== 25) {
|
|
22587
|
-
throw new Error(`Invalid Tron base58 length (expected 25 bytes): ${base58Address}`);
|
|
22588
|
-
}
|
|
22589
|
-
const payload = decoded.slice(0, 21);
|
|
22590
|
-
const checksum = (0, ethers_1.hexlify)(decoded.slice(21)).slice(2);
|
|
22591
|
-
const computed = (0, ethers_1.sha256)((0, ethers_1.sha256)(payload)).slice(2, 10);
|
|
22592
|
-
if (checksum !== computed) {
|
|
22593
|
-
throw new Error(`Invalid Tron base58 checksum: ${base58Address}`);
|
|
22594
|
-
}
|
|
22595
|
-
return (0, ethers_1.hexlify)(payload).slice(2);
|
|
22596
|
-
}
|
|
22597
|
-
function normalizeAddress2(address) {
|
|
22598
|
-
if (!address) {
|
|
22599
|
-
throw new Error("Empty address");
|
|
22600
|
-
}
|
|
22601
|
-
let hexAddress = address;
|
|
22602
|
-
if (address.startsWith("T")) {
|
|
22603
|
-
hexAddress = base58ToHex2(address);
|
|
22604
|
-
}
|
|
22605
|
-
hexAddress = hexAddress.replace(/^0x/, "");
|
|
22606
|
-
if (hexAddress.startsWith(TVM_MAINNET_PREFIX)) {
|
|
22607
|
-
hexAddress = hexAddress.substring(2);
|
|
22608
|
-
}
|
|
22609
|
-
if (hexAddress.length !== 40) {
|
|
22610
|
-
throw new Error(`Invalid address length: expected 40 chars, got ${hexAddress.length}`);
|
|
22848
|
+
// src/client.ts
|
|
22849
|
+
var import_evm_escrow_encoding = __toESM(require_dist(), 1);
|
|
22850
|
+
var import_payment_request_sender_auth = __toESM(require_dist2(), 1);
|
|
22851
|
+
var import_payment_gateway_client = __toESM(require_dist3(), 1);
|
|
22852
|
+
import { Contract, MaxUint256 } from "ethers";
|
|
22853
|
+
import { Credential, Method } from "mppx";
|
|
22854
|
+
function registerClient(config) {
|
|
22855
|
+
const now = config.now ?? (() => Date.now());
|
|
22856
|
+
const gateway = new import_payment_gateway_client.PaymentGatewayClient();
|
|
22857
|
+
return Method.toClient(atumEscrowChargeMethod, {
|
|
22858
|
+
async createCredential({ challenge }) {
|
|
22859
|
+
const { source, extra } = challenge.request;
|
|
22860
|
+
const namespace = namespaceOf(source.network);
|
|
22861
|
+
const account = config.account;
|
|
22862
|
+
const nowMs = now();
|
|
22863
|
+
if (!(extra.quoteDeadlineSeconds > 0 && extra.quoteDeadlineSeconds < extra.fulfillmentDeadlineSeconds)) {
|
|
22864
|
+
throw new Error(
|
|
22865
|
+
`atum-escrow: the challenge's deadline budgets cannot produce a settleable payment. quoteDeadlineSeconds must be above zero and below fulfillmentDeadlineSeconds, because quote collection has to close before settlement is due. Got quoteDeadlineSeconds=${extra.quoteDeadlineSeconds}, fulfillmentDeadlineSeconds=${extra.fulfillmentDeadlineSeconds}. These come from the corridor the resource server offered, so this is a merchant-side configuration problem rather than anything a payer can correct.`
|
|
22866
|
+
);
|
|
22611
22867
|
}
|
|
22612
|
-
|
|
22613
|
-
|
|
22868
|
+
const intentId = intentIdOf(challenge);
|
|
22869
|
+
if (intentId === void 0) {
|
|
22870
|
+
throw new Error(
|
|
22871
|
+
`atum-escrow: the challenge carries no '${INTENT_ID_META_KEY}' metadata, so this payment cannot be made retry-safe and is refused. The merchant must stamp a stable per-purchase identifier into the challenge metadata (see buildChargeChallenge); without it a retry would be charged as a second payment.`
|
|
22872
|
+
);
|
|
22614
22873
|
}
|
|
22615
|
-
|
|
22616
|
-
|
|
22617
|
-
|
|
22618
|
-
|
|
22619
|
-
|
|
22620
|
-
|
|
22621
|
-
|
|
22622
|
-
|
|
22623
|
-
|
|
22624
|
-
|
|
22625
|
-
|
|
22626
|
-
|
|
22627
|
-
|
|
22628
|
-
|
|
22629
|
-
|
|
22630
|
-
|
|
22631
|
-
|
|
22632
|
-
|
|
22633
|
-
|
|
22634
|
-
|
|
22635
|
-
|
|
22636
|
-
|
|
22637
|
-
version: "3",
|
|
22638
|
-
chainId: (0, chain_id_1.maskChainId)(input.chainId),
|
|
22639
|
-
verifyingContract: input.escrowContract
|
|
22640
|
-
};
|
|
22641
|
-
return ethers_1.TypedDataEncoder.hash(domain, RESERVE_WITNESS_TYPES, {
|
|
22642
|
-
paymentId: input.paymentId,
|
|
22643
|
-
settler: input.settler
|
|
22644
|
-
});
|
|
22645
|
-
}
|
|
22646
|
-
}
|
|
22647
|
-
});
|
|
22648
|
-
|
|
22649
|
-
// ../contracts/tvm/escrow-encoding/typescript/dist/payment-id.js
|
|
22650
|
-
var require_payment_id2 = __commonJS({
|
|
22651
|
-
"../contracts/tvm/escrow-encoding/typescript/dist/payment-id.js"(exports) {
|
|
22652
|
-
"use strict";
|
|
22653
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22654
|
-
exports.computePaymentId = computePaymentId;
|
|
22655
|
-
var ethers_1 = __require("ethers");
|
|
22656
|
-
var tron_address_1 = require_tron_address();
|
|
22657
|
-
function computePaymentId(depositor, signature, nonce) {
|
|
22658
|
-
if (!/^[0-9]+$/.test(nonce)) {
|
|
22659
|
-
throw new Error(`invalid nonce (expected base-10 decimal): ${nonce}`);
|
|
22660
|
-
}
|
|
22661
|
-
const encoded = ethers_1.AbiCoder.defaultAbiCoder().encode(["address", "bytes", "uint256"], [(0, tron_address_1.normalizeAddress)(depositor), signature, nonce]);
|
|
22662
|
-
return (0, ethers_1.keccak256)(encoded);
|
|
22663
|
-
}
|
|
22664
|
-
}
|
|
22665
|
-
});
|
|
22666
|
-
|
|
22667
|
-
// ../contracts/tvm/escrow-encoding/typescript/dist/deposit-encoder.js
|
|
22668
|
-
var require_deposit_encoder2 = __commonJS({
|
|
22669
|
-
"../contracts/tvm/escrow-encoding/typescript/dist/deposit-encoder.js"(exports) {
|
|
22670
|
-
"use strict";
|
|
22671
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22672
|
-
exports.createTvmPermitWitnessTransferFromPrehash = createTvmPermitWitnessTransferFromPrehash2;
|
|
22673
|
-
exports.hashTvmPermitWitnessTransferFrom = hashTvmPermitWitnessTransferFrom2;
|
|
22674
|
-
var ethers_1 = __require("ethers");
|
|
22675
|
-
var chain_id_1 = require_chain_id();
|
|
22676
|
-
var tron_address_1 = require_tron_address();
|
|
22677
|
-
var PERMIT_WITNESS_TYPES_V2 = {
|
|
22678
|
-
PermitWitnessTransferFrom: [
|
|
22679
|
-
{ name: "permitted", type: "TokenPermissions" },
|
|
22680
|
-
{ name: "spender", type: "address" },
|
|
22681
|
-
{ name: "nonce", type: "uint256" },
|
|
22682
|
-
{ name: "deadline", type: "uint256" },
|
|
22683
|
-
{ name: "witness", type: "DepositWitness" }
|
|
22684
|
-
],
|
|
22685
|
-
TokenPermissions: [
|
|
22686
|
-
{ name: "token", type: "address" },
|
|
22687
|
-
{ name: "amount", type: "uint256" }
|
|
22688
|
-
],
|
|
22689
|
-
DepositWitness: [
|
|
22690
|
-
{ name: "reserver", type: "address" },
|
|
22691
|
-
{ name: "releaser", type: "address" }
|
|
22692
|
-
]
|
|
22693
|
-
};
|
|
22694
|
-
function createTvmPermitWitnessTransferFromPrehash2(params) {
|
|
22695
|
-
const maskedChainId = (0, chain_id_1.maskChainId)(params.chainId);
|
|
22696
|
-
return {
|
|
22697
|
-
types: PERMIT_WITNESS_TYPES_V2,
|
|
22698
|
-
primaryType: "PermitWitnessTransferFrom",
|
|
22699
|
-
domain: {
|
|
22700
|
-
name: "Permit2",
|
|
22701
|
-
chainId: `0x${maskedChainId.toString(16)}`,
|
|
22702
|
-
verifyingContract: (0, tron_address_1.normalizeAddress)(params.permit2Address)
|
|
22874
|
+
const requestId = chargeRequestId(intentId, account);
|
|
22875
|
+
const sourceDefaults = chainDefaultsFromExtra(extra, source.network);
|
|
22876
|
+
const sourceAssetId = assetIdentifier(source.network, source.asset);
|
|
22877
|
+
const isSolana = namespace === "solana";
|
|
22878
|
+
const solanaIssuedAt = extra.issuedAt;
|
|
22879
|
+
const paymentRequestGw = await gateway.preparePaymentRequest({
|
|
22880
|
+
depositor: account,
|
|
22881
|
+
fulfillmentAmount: extra.fulfillmentAmount,
|
|
22882
|
+
sourceAsset: sourceAssetId,
|
|
22883
|
+
destinationAccount: extra.destination.address,
|
|
22884
|
+
destinationAsset: assetIdentifier(extra.destination.network, extra.destination.asset),
|
|
22885
|
+
// Sign the full advertised cap. The payer MAY sign a lower value, but that only
|
|
22886
|
+
// lowers its own escrow lock and risks the auction not clearing; the full cap is
|
|
22887
|
+
// the safe default and never affects the receive side.
|
|
22888
|
+
maxSourceAmount: source.amount,
|
|
22889
|
+
requestId,
|
|
22890
|
+
quoteDeadlineSeconds: extra.quoteDeadlineSeconds,
|
|
22891
|
+
fulfillmentDeadlineSeconds: extra.fulfillmentDeadlineSeconds,
|
|
22892
|
+
now: () => nowMs,
|
|
22893
|
+
resolvedDefaults: {
|
|
22894
|
+
source: sourceDefaults,
|
|
22895
|
+
destination: { fulfillmentProxy: extra.fulfillmentProxy }
|
|
22703
22896
|
},
|
|
22704
|
-
|
|
22705
|
-
|
|
22706
|
-
|
|
22707
|
-
|
|
22708
|
-
|
|
22709
|
-
|
|
22710
|
-
|
|
22711
|
-
|
|
22712
|
-
|
|
22713
|
-
|
|
22714
|
-
|
|
22715
|
-
|
|
22897
|
+
// EVM/Tron: thread the deterministic nonce, and keep the deposit deadline at least
|
|
22898
|
+
// as late as the fulfillment deadline. The adapter floors the relative deadline, so
|
|
22899
|
+
// +1s guards against truncating below fulfillment_deadline.
|
|
22900
|
+
...isSolana ? {
|
|
22901
|
+
// Solana stamps issued_at and derives its own replay-window deadline. Prefer the
|
|
22902
|
+
// merchant-stamped `extra.issuedAt` (self-contained 402, no client RPC); fall back
|
|
22903
|
+
// to an injected reader, then the client clock, when the 402 doesn't carry it.
|
|
22904
|
+
solanaRpcUrl: "atum-escrow:offline",
|
|
22905
|
+
solanaClockReader: solanaIssuedAt != null ? async () => BigInt(solanaIssuedAt) : config.solanaClockReader ?? (async () => BigInt(Math.floor(nowMs / 1e3)))
|
|
22906
|
+
} : {
|
|
22907
|
+
// No explicit nonce: `preparePaymentRequest` derives it from
|
|
22908
|
+
// (request_id, depositor) via the shared sender_auth SDK — the same
|
|
22909
|
+
// Go-parity-locked derivation every consumer uses. Since request_id is itself
|
|
22910
|
+
// anchored on the intentId above, a rebuild reproduces the same single-use
|
|
22911
|
+
// permit. Overriding it here would fork a second nonce recipe for no gain.
|
|
22912
|
+
//
|
|
22913
|
+
// Keep the deposit deadline at least as late as fulfillment. pgc converts this
|
|
22914
|
+
// relative budget to an absolute permit deadline against the same clock; round
|
|
22915
|
+
// the budget up and add a second so it never truncates below fulfillment_deadline.
|
|
22916
|
+
deadlineSeconds: Math.ceil(extra.fulfillmentDeadlineSeconds) + 1
|
|
22716
22917
|
}
|
|
22717
|
-
};
|
|
22718
|
-
|
|
22719
|
-
|
|
22720
|
-
|
|
22918
|
+
});
|
|
22919
|
+
const signer = buildSenderSigner(source.network, config.signer, account);
|
|
22920
|
+
await (0, import_payment_gateway_client.signPaymentRequest)(paymentRequestGw, signer);
|
|
22921
|
+
const paymentRequest = paymentRequestGw;
|
|
22922
|
+
return Credential.serialize({
|
|
22923
|
+
challenge,
|
|
22924
|
+
payload: { paymentRequest },
|
|
22925
|
+
source: `did:pkh:${source.network}:${(0, import_payment_request_sender_auth.canonicalDepositor)(account)}`
|
|
22926
|
+
});
|
|
22721
22927
|
}
|
|
22722
|
-
}
|
|
22723
|
-
});
|
|
22724
|
-
|
|
22725
|
-
// ../contracts/tvm/escrow-encoding/typescript/dist/index.js
|
|
22726
|
-
var require_dist3 = __commonJS({
|
|
22727
|
-
"../contracts/tvm/escrow-encoding/typescript/dist/index.js"(exports) {
|
|
22728
|
-
"use strict";
|
|
22729
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22730
|
-
exports.hashTvmPermitWitnessTransferFrom = exports.createTvmPermitWitnessTransferFromPrehash = exports.computePaymentId = exports.computeReserveDigest = exports.normalizeAddress = exports.base58ToHex = exports.maskChainId = void 0;
|
|
22731
|
-
var chain_id_1 = require_chain_id();
|
|
22732
|
-
Object.defineProperty(exports, "maskChainId", { enumerable: true, get: function() {
|
|
22733
|
-
return chain_id_1.maskChainId;
|
|
22734
|
-
} });
|
|
22735
|
-
var tron_address_1 = require_tron_address();
|
|
22736
|
-
Object.defineProperty(exports, "base58ToHex", { enumerable: true, get: function() {
|
|
22737
|
-
return tron_address_1.base58ToHex;
|
|
22738
|
-
} });
|
|
22739
|
-
Object.defineProperty(exports, "normalizeAddress", { enumerable: true, get: function() {
|
|
22740
|
-
return tron_address_1.normalizeAddress;
|
|
22741
|
-
} });
|
|
22742
|
-
var reserve_encoder_1 = require_reserve_encoder2();
|
|
22743
|
-
Object.defineProperty(exports, "computeReserveDigest", { enumerable: true, get: function() {
|
|
22744
|
-
return reserve_encoder_1.computeReserveDigest;
|
|
22745
|
-
} });
|
|
22746
|
-
var payment_id_1 = require_payment_id2();
|
|
22747
|
-
Object.defineProperty(exports, "computePaymentId", { enumerable: true, get: function() {
|
|
22748
|
-
return payment_id_1.computePaymentId;
|
|
22749
|
-
} });
|
|
22750
|
-
var deposit_encoder_1 = require_deposit_encoder2();
|
|
22751
|
-
Object.defineProperty(exports, "createTvmPermitWitnessTransferFromPrehash", { enumerable: true, get: function() {
|
|
22752
|
-
return deposit_encoder_1.createTvmPermitWitnessTransferFromPrehash;
|
|
22753
|
-
} });
|
|
22754
|
-
Object.defineProperty(exports, "hashTvmPermitWitnessTransferFrom", { enumerable: true, get: function() {
|
|
22755
|
-
return deposit_encoder_1.hashTvmPermitWitnessTransferFrom;
|
|
22756
|
-
} });
|
|
22757
|
-
}
|
|
22758
|
-
});
|
|
22759
|
-
|
|
22760
|
-
// src/internal.ts
|
|
22761
|
-
var import_tvm_escrow_encoding = __toESM(require_dist3(), 1);
|
|
22762
|
-
import * as z from "zod/mini";
|
|
22763
|
-
import { Method } from "mppx";
|
|
22764
|
-
var METHOD_NAME = "atum-escrow";
|
|
22765
|
-
var INTENT = "charge";
|
|
22766
|
-
var ChargeRequestSchema = z.object({
|
|
22767
|
-
/** The source chain/token/cap the payer funds from (one option per challenge). */
|
|
22768
|
-
source: z.object({
|
|
22769
|
-
/** CAIP-2 source chain id (e.g. `eip155:8453`, `tron:mainnet`, `solana:<genesis>`). */
|
|
22770
|
-
network: z.string(),
|
|
22771
|
-
/** Source token address (EVM hex or base58). */
|
|
22772
|
-
asset: z.string(),
|
|
22773
|
-
/** Source spend cap (fulfillmentAmount + markup), atomic units — the authoritative `max_source_amount`. */
|
|
22774
|
-
amount: z.string()
|
|
22775
|
-
}),
|
|
22776
|
-
/** The destination/corridor block (the reused x402 `extra`). */
|
|
22777
|
-
extra: z.object({
|
|
22778
|
-
/** Where the merchant receives: CAIP-2 chain, token, and receive account. */
|
|
22779
|
-
destination: z.object({
|
|
22780
|
-
network: z.string(),
|
|
22781
|
-
asset: z.string(),
|
|
22782
|
-
account: z.string()
|
|
22783
|
-
}),
|
|
22784
|
-
/** Exact amount the merchant receives, in atomic units of the destination token. */
|
|
22785
|
-
fulfillmentAmount: z.string(),
|
|
22786
|
-
/** Source-chain escrow contract for this option; the payer's funds lock here. */
|
|
22787
|
-
escrow: z.string(),
|
|
22788
|
-
/** Destination-chain fulfillment-proxy contract. */
|
|
22789
|
-
fulfillmentProxy: z.string(),
|
|
22790
|
-
/** Role address that witnesses the escrow deposit on reservation. */
|
|
22791
|
-
reserver: z.string(),
|
|
22792
|
-
/** Role address that witnesses the escrow release on fulfillment. */
|
|
22793
|
-
releaser: z.string(),
|
|
22794
|
-
/** Endpoint used to verify fulfillment on the source chain. */
|
|
22795
|
-
fulfillmentVerifierEndpoint: z.string(),
|
|
22796
|
-
/** Quote-deadline budget in seconds, relative to signing time. */
|
|
22797
|
-
quoteDeadlineSeconds: z.number(),
|
|
22798
|
-
/** Fulfillment-deadline budget in seconds, relative to signing time. */
|
|
22799
|
-
fulfillmentDeadlineSeconds: z.number(),
|
|
22800
|
-
/** Tron-only: the Permit2 contract the deposit is signed against (TIP-712 verifying contract). */
|
|
22801
|
-
permit2: z.optional(z.string()),
|
|
22802
|
-
/** Solana-only: cluster id that domain-separates the deposit authorization. */
|
|
22803
|
-
svmSignatureClusterId: z.optional(z.string()),
|
|
22804
|
-
/** Solana-only: signature domain version that domain-separates the deposit authorization. */
|
|
22805
|
-
svmSignatureDomainVersion: z.optional(z.number())
|
|
22806
|
-
})
|
|
22807
|
-
});
|
|
22808
|
-
var CredentialPayloadSchema = z.object({
|
|
22809
|
-
paymentRequest: z.record(z.string(), z.unknown())
|
|
22810
|
-
});
|
|
22811
|
-
var atumEscrowChargeMethod = Method.from({
|
|
22812
|
-
name: METHOD_NAME,
|
|
22813
|
-
intent: INTENT,
|
|
22814
|
-
schema: {
|
|
22815
|
-
request: ChargeRequestSchema,
|
|
22816
|
-
credential: { payload: CredentialPayloadSchema }
|
|
22817
|
-
}
|
|
22818
|
-
});
|
|
22819
|
-
function namespaceOf(network) {
|
|
22820
|
-
return network.split(":")[0];
|
|
22821
|
-
}
|
|
22822
|
-
function assetTypeFor(network) {
|
|
22823
|
-
switch (namespaceOf(network)) {
|
|
22824
|
-
case "eip155":
|
|
22825
|
-
return "erc20";
|
|
22826
|
-
case "tron":
|
|
22827
|
-
return "trc20";
|
|
22828
|
-
case "solana":
|
|
22829
|
-
return "spl";
|
|
22830
|
-
default:
|
|
22831
|
-
throw new Error(`atum-escrow: unsupported network '${network}'`);
|
|
22832
|
-
}
|
|
22928
|
+
});
|
|
22833
22929
|
}
|
|
22834
|
-
function
|
|
22835
|
-
return
|
|
22930
|
+
function isSenderSigner(signer) {
|
|
22931
|
+
return typeof signer.sign === "function";
|
|
22836
22932
|
}
|
|
22837
|
-
function
|
|
22838
|
-
if (
|
|
22839
|
-
return
|
|
22933
|
+
function buildSenderSigner(network, signer, account) {
|
|
22934
|
+
if (isSenderSigner(signer)) {
|
|
22935
|
+
return signer;
|
|
22840
22936
|
}
|
|
22841
|
-
return
|
|
22842
|
-
|
|
22843
|
-
|
|
22844
|
-
|
|
22845
|
-
escrowContract: extra.escrow,
|
|
22846
|
-
quoteSelector: extra.reserver,
|
|
22847
|
-
fulfillmentVerifierAccount: extra.releaser,
|
|
22848
|
-
fulfillmentVerifierEndpoint: extra.fulfillmentVerifierEndpoint,
|
|
22849
|
-
fulfillmentProxy: extra.fulfillmentProxy,
|
|
22850
|
-
// Pin the Tron Permit2 so the adapter signs against the canonical address (the same one
|
|
22851
|
-
// verify() rebuilds against), never leaving it to the adapter's internal fallback.
|
|
22852
|
-
...namespaceOf(network) === "tron" ? { permit2Contract: resolveTronPermit2(network, extra.permit2) } : {},
|
|
22853
|
-
...extra.svmSignatureClusterId ? { svmSignatureClusterId: extra.svmSignatureClusterId } : {},
|
|
22854
|
-
...extra.svmSignatureDomainVersion != null ? { svmSignatureDomainVersion: extra.svmSignatureDomainVersion } : {}
|
|
22855
|
-
};
|
|
22937
|
+
return (0, import_payment_gateway_client.createSenderSigner)(network, {
|
|
22938
|
+
...signer,
|
|
22939
|
+
pinnedAddress: signer.pinnedAddress ?? account
|
|
22940
|
+
});
|
|
22856
22941
|
}
|
|
22857
|
-
var
|
|
22858
|
-
"
|
|
22859
|
-
"
|
|
22860
|
-
|
|
22861
|
-
function
|
|
22862
|
-
|
|
22863
|
-
|
|
22942
|
+
var ERC20_ALLOWANCE_ABI = [
|
|
22943
|
+
"function allowance(address owner, address spender) view returns (uint256)",
|
|
22944
|
+
"function approve(address spender, uint256 amount) returns (bool)"
|
|
22945
|
+
];
|
|
22946
|
+
async function ensureSourceApproval(params) {
|
|
22947
|
+
if (namespaceOf(params.network) === "solana") {
|
|
22948
|
+
return { alreadySufficient: true };
|
|
22949
|
+
}
|
|
22950
|
+
const spender = params.spender ?? (namespaceOf(params.network) === "eip155" ? import_evm_escrow_encoding.PERMIT2_CONTRACT_ADDRESS : void 0);
|
|
22951
|
+
if (!spender) {
|
|
22864
22952
|
throw new Error(
|
|
22865
|
-
`atum-escrow:
|
|
22953
|
+
`atum-escrow: a spender (Permit2 address) is required to approve on ${params.network}`
|
|
22866
22954
|
);
|
|
22867
22955
|
}
|
|
22868
|
-
|
|
22869
|
-
|
|
22870
|
-
|
|
22871
|
-
if (
|
|
22872
|
-
return
|
|
22873
|
-
}
|
|
22874
|
-
return {
|
|
22875
|
-
quote_selector: (0, import_tvm_escrow_encoding.normalizeAddress)(extra.reserver),
|
|
22876
|
-
fulfillment_verifier: {
|
|
22877
|
-
account: (0, import_tvm_escrow_encoding.normalizeAddress)(extra.releaser),
|
|
22878
|
-
endpoint: extra.fulfillmentVerifierEndpoint
|
|
22879
|
-
}
|
|
22880
|
-
};
|
|
22881
|
-
}
|
|
22882
|
-
function evmChainId(network) {
|
|
22883
|
-
const match = /^eip155:([0-9]+)$/.exec(network);
|
|
22884
|
-
if (!match) {
|
|
22885
|
-
throw new Error(`atum-escrow: expected an eip155 network, got ${network}`);
|
|
22886
|
-
}
|
|
22887
|
-
return Number(match[1]);
|
|
22888
|
-
}
|
|
22889
|
-
var TRON_CHAIN_IDS = {
|
|
22890
|
-
mainnet: 728126428,
|
|
22891
|
-
shasta: 2494104990
|
|
22892
|
-
};
|
|
22893
|
-
function tronNumericChainId(network) {
|
|
22894
|
-
const cluster = network.split(":")[1];
|
|
22895
|
-
const id = TRON_CHAIN_IDS[cluster ?? ""];
|
|
22896
|
-
if (id === void 0) {
|
|
22897
|
-
throw new Error(`atum-escrow: unsupported Tron network '${network}'`);
|
|
22898
|
-
}
|
|
22899
|
-
return id;
|
|
22900
|
-
}
|
|
22901
|
-
function clusterIdFromName(name) {
|
|
22902
|
-
const encoded = new TextEncoder().encode(name);
|
|
22903
|
-
if (encoded.length > 32) {
|
|
22904
|
-
throw new Error(`atum-escrow: Solana cluster name too long (${encoded.length} > 32 bytes): ${name}`);
|
|
22956
|
+
const erc20 = new Contract(params.token, ERC20_ALLOWANCE_ABI, params.signer);
|
|
22957
|
+
const current = await erc20.allowance(params.owner, spender);
|
|
22958
|
+
const sufficient = params.requiredAllowance !== void 0 ? current >= params.requiredAllowance : current >= MaxUint256;
|
|
22959
|
+
if (sufficient) {
|
|
22960
|
+
return { alreadySufficient: true };
|
|
22905
22961
|
}
|
|
22906
|
-
const
|
|
22907
|
-
|
|
22908
|
-
return
|
|
22962
|
+
const tx = await erc20.approve(spender, MaxUint256);
|
|
22963
|
+
await tx.wait?.();
|
|
22964
|
+
return { alreadySufficient: false, txHash: tx.hash };
|
|
22909
22965
|
}
|
|
22910
22966
|
|
|
22911
22967
|
export {
|
|
22912
|
-
|
|
22913
|
-
|
|
22914
|
-
__toESM,
|
|
22915
|
-
require_dist,
|
|
22916
|
-
require_dist2,
|
|
22917
|
-
require_dist3,
|
|
22918
|
-
METHOD_NAME,
|
|
22919
|
-
INTENT,
|
|
22920
|
-
ChargeRequestSchema,
|
|
22921
|
-
CredentialPayloadSchema,
|
|
22922
|
-
atumEscrowChargeMethod,
|
|
22923
|
-
namespaceOf,
|
|
22924
|
-
assetIdentifier,
|
|
22925
|
-
sameAddress,
|
|
22926
|
-
chainDefaultsFromExtra,
|
|
22927
|
-
resolveTronPermit2,
|
|
22928
|
-
contractOverridesFromExtra,
|
|
22929
|
-
evmChainId,
|
|
22930
|
-
tronNumericChainId,
|
|
22931
|
-
clusterIdFromName
|
|
22968
|
+
registerClient,
|
|
22969
|
+
ensureSourceApproval
|
|
22932
22970
|
};
|
|
22933
22971
|
/*! Bundled license information:
|
|
22934
22972
|
|