@safe-global/api-kit 2.5.6 → 2.5.8-alpha.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.
Files changed (40) hide show
  1. package/dist/cjs/index.cjs +961 -0
  2. package/dist/esm/index.mjs +930 -0
  3. package/dist/src/SafeApiKit.d.ts +1 -0
  4. package/dist/src/SafeApiKit.d.ts.map +1 -0
  5. package/dist/src/index.d.ts +1 -0
  6. package/dist/src/index.d.ts.map +1 -0
  7. package/dist/src/types/safeTransactionServiceTypes.d.ts +20 -25
  8. package/dist/src/types/safeTransactionServiceTypes.d.ts.map +1 -0
  9. package/dist/src/utils/config.d.ts +1 -0
  10. package/dist/src/utils/config.d.ts.map +1 -0
  11. package/dist/src/utils/constants.d.ts +1 -0
  12. package/dist/src/utils/constants.d.ts.map +1 -0
  13. package/dist/src/utils/httpRequests.d.ts +1 -0
  14. package/dist/src/utils/httpRequests.d.ts.map +1 -0
  15. package/dist/src/utils/index.d.ts +1 -0
  16. package/dist/src/utils/index.d.ts.map +1 -0
  17. package/dist/src/utils/safeOperation.d.ts +1 -0
  18. package/dist/src/utils/safeOperation.d.ts.map +1 -0
  19. package/dist/src/utils/signDelegate.d.ts +1 -0
  20. package/dist/src/utils/signDelegate.d.ts.map +1 -0
  21. package/package.json +17 -8
  22. package/dist/src/SafeApiKit.js +0 -788
  23. package/dist/src/SafeApiKit.js.map +0 -1
  24. package/dist/src/index.js +0 -23
  25. package/dist/src/index.js.map +0 -1
  26. package/dist/src/types/safeTransactionServiceTypes.js +0 -3
  27. package/dist/src/types/safeTransactionServiceTypes.js.map +0 -1
  28. package/dist/src/utils/config.js +0 -25
  29. package/dist/src/utils/config.js.map +0 -1
  30. package/dist/src/utils/constants.js +0 -5
  31. package/dist/src/utils/constants.js.map +0 -1
  32. package/dist/src/utils/httpRequests.js +0 -59
  33. package/dist/src/utils/httpRequests.js.map +0 -1
  34. package/dist/src/utils/index.js +0 -7
  35. package/dist/src/utils/index.js.map +0 -1
  36. package/dist/src/utils/safeOperation.js +0 -19
  37. package/dist/src/utils/safeOperation.js.map +0 -1
  38. package/dist/src/utils/signDelegate.js +0 -25
  39. package/dist/src/utils/signDelegate.js.map +0 -1
  40. package/dist/tsconfig.build.tsbuildinfo +0 -1
@@ -1,788 +0,0 @@
1
- "use strict";
2
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
- if (kind === "m") throw new TypeError("Private method is not writable");
4
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
- };
8
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
- };
13
- var _SafeApiKit_instances, _SafeApiKit_chainId, _SafeApiKit_txServiceBaseUrl, _SafeApiKit_isValidAddress, _SafeApiKit_getEip3770Address;
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const httpRequests_1 = require("./utils/httpRequests");
16
- const signDelegate_1 = require("./utils/signDelegate");
17
- const protocol_kit_1 = require("@safe-global/protocol-kit");
18
- const types_kit_1 = require("@safe-global/types-kit");
19
- const config_1 = require("./utils/config");
20
- const utils_1 = require("./utils");
21
- const safeOperation_1 = require("./utils/safeOperation");
22
- class SafeApiKit {
23
- constructor({ chainId, txServiceUrl }) {
24
- _SafeApiKit_instances.add(this);
25
- _SafeApiKit_chainId.set(this, void 0);
26
- _SafeApiKit_txServiceBaseUrl.set(this, void 0);
27
- __classPrivateFieldSet(this, _SafeApiKit_chainId, chainId, "f");
28
- if (txServiceUrl) {
29
- __classPrivateFieldSet(this, _SafeApiKit_txServiceBaseUrl, txServiceUrl, "f");
30
- }
31
- else {
32
- const url = config_1.TRANSACTION_SERVICE_URLS[chainId.toString()];
33
- if (!url) {
34
- throw new TypeError(`There is no transaction service available for chainId ${chainId}. Please set the txServiceUrl property to use a custom transaction service.`);
35
- }
36
- __classPrivateFieldSet(this, _SafeApiKit_txServiceBaseUrl, url, "f");
37
- }
38
- }
39
- /**
40
- * Returns the information and configuration of the service.
41
- *
42
- * @returns The information and configuration of the service
43
- */
44
- async getServiceInfo() {
45
- return (0, httpRequests_1.sendRequest)({
46
- url: `${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v1/about`,
47
- method: httpRequests_1.HttpMethod.Get
48
- });
49
- }
50
- /**
51
- * Returns the list of Safe singletons.
52
- *
53
- * @returns The list of Safe singletons
54
- */
55
- async getServiceSingletonsInfo() {
56
- return (0, httpRequests_1.sendRequest)({
57
- url: `${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v1/about/singletons`,
58
- method: httpRequests_1.HttpMethod.Get
59
- });
60
- }
61
- /**
62
- * Decodes the specified Safe transaction data.
63
- *
64
- * @param data - The Safe transaction data. '0x' prefixed hexadecimal string.
65
- * @param to - The address of the receiving contract. If provided, the decoded data will be more accurate, as in case of an ABI collision the Safe Transaction Service would know which ABI to use
66
- * @returns The transaction data decoded
67
- * @throws "Invalid data"
68
- * @throws "Not Found"
69
- * @throws "Ensure this field has at least 1 hexadecimal chars (not counting 0x)."
70
- */
71
- async decodeData(data, to) {
72
- if (data === '') {
73
- throw new Error('Invalid data');
74
- }
75
- const dataDecoderRequest = { data };
76
- if (to) {
77
- dataDecoderRequest.to = to;
78
- }
79
- return (0, httpRequests_1.sendRequest)({
80
- url: `${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v1/data-decoder/`,
81
- method: httpRequests_1.HttpMethod.Post,
82
- body: dataDecoderRequest
83
- });
84
- }
85
- /**
86
- * Returns the list of Safes where the address provided is an owner.
87
- *
88
- * @param ownerAddress - The owner address
89
- * @returns The list of Safes where the address provided is an owner
90
- * @throws "Invalid owner address"
91
- * @throws "Checksum address validation failed"
92
- */
93
- async getSafesByOwner(ownerAddress) {
94
- if (ownerAddress === '') {
95
- throw new Error('Invalid owner address');
96
- }
97
- const { address } = __classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_getEip3770Address).call(this, ownerAddress);
98
- return (0, httpRequests_1.sendRequest)({
99
- url: `${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v1/owners/${address}/safes/`,
100
- method: httpRequests_1.HttpMethod.Get
101
- });
102
- }
103
- /**
104
- * Returns the list of Safes where the module address provided is enabled.
105
- *
106
- * @param moduleAddress - The Safe module address
107
- * @returns The list of Safe addresses where the module provided is enabled
108
- * @throws "Invalid module address"
109
- * @throws "Module address checksum not valid"
110
- */
111
- async getSafesByModule(moduleAddress) {
112
- if (moduleAddress === '') {
113
- throw new Error('Invalid module address');
114
- }
115
- const { address } = __classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_getEip3770Address).call(this, moduleAddress);
116
- return (0, httpRequests_1.sendRequest)({
117
- url: `${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v1/modules/${address}/safes/`,
118
- method: httpRequests_1.HttpMethod.Get
119
- });
120
- }
121
- /**
122
- * Returns all the information of a Safe transaction.
123
- *
124
- * @param safeTxHash - Hash of the Safe transaction
125
- * @returns The information of a Safe transaction
126
- * @throws "Invalid safeTxHash"
127
- * @throws "Not found."
128
- */
129
- async getTransaction(safeTxHash) {
130
- if (safeTxHash === '') {
131
- throw new Error('Invalid safeTxHash');
132
- }
133
- return (0, httpRequests_1.sendRequest)({
134
- url: `${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v1/multisig-transactions/${safeTxHash}/`,
135
- method: httpRequests_1.HttpMethod.Get
136
- });
137
- }
138
- /**
139
- * Returns the list of confirmations for a given a Safe transaction.
140
- *
141
- * @param safeTxHash - The hash of the Safe transaction
142
- * @returns The list of confirmations
143
- * @throws "Invalid safeTxHash"
144
- */
145
- async getTransactionConfirmations(safeTxHash) {
146
- if (safeTxHash === '') {
147
- throw new Error('Invalid safeTxHash');
148
- }
149
- return (0, httpRequests_1.sendRequest)({
150
- url: `${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v1/multisig-transactions/${safeTxHash}/confirmations/`,
151
- method: httpRequests_1.HttpMethod.Get
152
- });
153
- }
154
- /**
155
- * Adds a confirmation for a Safe transaction.
156
- *
157
- * @param safeTxHash - Hash of the Safe transaction that will be confirmed
158
- * @param signature - Signature of the transaction
159
- * @returns
160
- * @throws "Invalid safeTxHash"
161
- * @throws "Invalid signature"
162
- * @throws "Malformed data"
163
- * @throws "Error processing data"
164
- */
165
- async confirmTransaction(safeTxHash, signature) {
166
- if (safeTxHash === '') {
167
- throw new Error('Invalid safeTxHash');
168
- }
169
- if (signature === '') {
170
- throw new Error('Invalid signature');
171
- }
172
- return (0, httpRequests_1.sendRequest)({
173
- url: `${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v1/multisig-transactions/${safeTxHash}/confirmations/`,
174
- method: httpRequests_1.HttpMethod.Post,
175
- body: {
176
- signature
177
- }
178
- });
179
- }
180
- /**
181
- * Returns the information and configuration of the provided Safe address.
182
- *
183
- * @param safeAddress - The Safe address
184
- * @returns The information and configuration of the provided Safe address
185
- * @throws "Invalid Safe address"
186
- * @throws "Checksum address validation failed"
187
- */
188
- async getSafeInfo(safeAddress) {
189
- if (safeAddress === '') {
190
- throw new Error('Invalid Safe address');
191
- }
192
- const { address } = __classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_getEip3770Address).call(this, safeAddress);
193
- return (0, httpRequests_1.sendRequest)({
194
- url: `${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v1/safes/${address}/`,
195
- method: httpRequests_1.HttpMethod.Get
196
- });
197
- }
198
- /**
199
- * Returns the list of delegates.
200
- *
201
- * @param getSafeDelegateProps - Properties to filter the returned list of delegates
202
- * @returns The list of delegates
203
- * @throws "Checksum address validation failed"
204
- */
205
- async getSafeDelegates({ safeAddress, delegateAddress, delegatorAddress, label, limit, offset }) {
206
- const url = new URL(`${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v2/delegates`);
207
- if (safeAddress) {
208
- const { address: safe } = __classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_getEip3770Address).call(this, safeAddress);
209
- url.searchParams.set('safe', safe);
210
- }
211
- if (delegateAddress) {
212
- const { address: delegate } = __classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_getEip3770Address).call(this, delegateAddress);
213
- url.searchParams.set('delegate', delegate);
214
- }
215
- if (delegatorAddress) {
216
- const { address: delegator } = __classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_getEip3770Address).call(this, delegatorAddress);
217
- url.searchParams.set('delegator', delegator);
218
- }
219
- if (label) {
220
- url.searchParams.set('label', label);
221
- }
222
- if (limit != null) {
223
- url.searchParams.set('limit', limit.toString());
224
- }
225
- if (offset != null) {
226
- url.searchParams.set('offset', offset.toString());
227
- }
228
- return (0, httpRequests_1.sendRequest)({
229
- url: url.toString(),
230
- method: httpRequests_1.HttpMethod.Get
231
- });
232
- }
233
- /**
234
- * Adds a new delegate for a given Safe address.
235
- *
236
- * @param addSafeDelegateProps - The configuration of the new delegate
237
- * @returns
238
- * @throws "Invalid Safe delegate address"
239
- * @throws "Invalid Safe delegator address"
240
- * @throws "Invalid label"
241
- * @throws "Checksum address validation failed"
242
- * @throws "Address <delegate_address> is not checksumed"
243
- * @throws "Safe=<safe_address> does not exist or it's still not indexed"
244
- * @throws "Signing owner is not an owner of the Safe"
245
- */
246
- async addSafeDelegate({ safeAddress, delegateAddress, delegatorAddress, label, signer }) {
247
- if (delegateAddress === '') {
248
- throw new Error('Invalid Safe delegate address');
249
- }
250
- if (delegatorAddress === '') {
251
- throw new Error('Invalid Safe delegator address');
252
- }
253
- if (label === '') {
254
- throw new Error('Invalid label');
255
- }
256
- const { address: delegate } = __classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_getEip3770Address).call(this, delegateAddress);
257
- const { address: delegator } = __classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_getEip3770Address).call(this, delegatorAddress);
258
- const signature = await (0, signDelegate_1.signDelegate)(signer, delegate, __classPrivateFieldGet(this, _SafeApiKit_chainId, "f"));
259
- const body = {
260
- safe: safeAddress ? __classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_getEip3770Address).call(this, safeAddress).address : null,
261
- delegate,
262
- delegator,
263
- label,
264
- signature
265
- };
266
- return (0, httpRequests_1.sendRequest)({
267
- url: `${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v2/delegates/`,
268
- method: httpRequests_1.HttpMethod.Post,
269
- body
270
- });
271
- }
272
- /**
273
- * Removes a delegate for a given Safe address.
274
- *
275
- * @param deleteSafeDelegateProps - The configuration for the delegate that will be removed
276
- * @returns
277
- * @throws "Invalid Safe delegate address"
278
- * @throws "Invalid Safe delegator address"
279
- * @throws "Checksum address validation failed"
280
- * @throws "Signing owner is not an owner of the Safe"
281
- * @throws "Not found"
282
- */
283
- async removeSafeDelegate({ delegateAddress, delegatorAddress, signer }) {
284
- if (delegateAddress === '') {
285
- throw new Error('Invalid Safe delegate address');
286
- }
287
- if (delegatorAddress === '') {
288
- throw new Error('Invalid Safe delegator address');
289
- }
290
- const { address: delegate } = __classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_getEip3770Address).call(this, delegateAddress);
291
- const { address: delegator } = __classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_getEip3770Address).call(this, delegatorAddress);
292
- const signature = await (0, signDelegate_1.signDelegate)(signer, delegate, __classPrivateFieldGet(this, _SafeApiKit_chainId, "f"));
293
- return (0, httpRequests_1.sendRequest)({
294
- url: `${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v2/delegates/${delegate}`,
295
- method: httpRequests_1.HttpMethod.Delete,
296
- body: {
297
- delegator,
298
- signature
299
- }
300
- });
301
- }
302
- /**
303
- * Returns the creation information of a Safe.
304
- *
305
- * @param safeAddress - The Safe address
306
- * @returns The creation information of a Safe
307
- * @throws "Invalid Safe address"
308
- * @throws "Safe creation not found"
309
- * @throws "Checksum address validation failed"
310
- * @throws "Problem connecting to Ethereum network"
311
- */
312
- async getSafeCreationInfo(safeAddress) {
313
- if (safeAddress === '') {
314
- throw new Error('Invalid Safe address');
315
- }
316
- const { address } = __classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_getEip3770Address).call(this, safeAddress);
317
- return (0, httpRequests_1.sendRequest)({
318
- url: `${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v1/safes/${address}/creation/`,
319
- method: httpRequests_1.HttpMethod.Get
320
- });
321
- }
322
- /**
323
- * Estimates the safeTxGas for a given Safe multi-signature transaction.
324
- *
325
- * @param safeAddress - The Safe address
326
- * @param safeTransaction - The Safe transaction to estimate
327
- * @returns The safeTxGas for the given Safe transaction
328
- * @throws "Invalid Safe address"
329
- * @throws "Data not valid"
330
- * @throws "Safe not found"
331
- * @throws "Tx not valid"
332
- */
333
- async estimateSafeTransaction(safeAddress, safeTransaction) {
334
- if (safeAddress === '') {
335
- throw new Error('Invalid Safe address');
336
- }
337
- const { address } = __classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_getEip3770Address).call(this, safeAddress);
338
- return (0, httpRequests_1.sendRequest)({
339
- url: `${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v1/safes/${address}/multisig-transactions/estimations/`,
340
- method: httpRequests_1.HttpMethod.Post,
341
- body: safeTransaction
342
- });
343
- }
344
- /**
345
- * Creates a new multi-signature transaction with its confirmations and stores it in the Safe Transaction Service.
346
- *
347
- * @param proposeTransactionConfig - The configuration of the proposed transaction
348
- * @returns The hash of the Safe transaction proposed
349
- * @throws "Invalid Safe address"
350
- * @throws "Invalid safeTxHash"
351
- * @throws "Invalid data"
352
- * @throws "Invalid ethereum address/User is not an owner/Invalid signature/Nonce already executed/Sender is not an owner"
353
- */
354
- async proposeTransaction({ safeAddress, safeTransactionData, safeTxHash, senderAddress, senderSignature, origin }) {
355
- if (safeAddress === '') {
356
- throw new Error('Invalid Safe address');
357
- }
358
- const { address: safe } = __classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_getEip3770Address).call(this, safeAddress);
359
- const { address: sender } = __classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_getEip3770Address).call(this, senderAddress);
360
- if (safeTxHash === '') {
361
- throw new Error('Invalid safeTxHash');
362
- }
363
- return (0, httpRequests_1.sendRequest)({
364
- url: `${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v1/safes/${safe}/multisig-transactions/`,
365
- method: httpRequests_1.HttpMethod.Post,
366
- body: {
367
- ...safeTransactionData,
368
- contractTransactionHash: safeTxHash,
369
- sender,
370
- signature: senderSignature,
371
- origin
372
- }
373
- });
374
- }
375
- /**
376
- * Returns the history of incoming transactions of a Safe account.
377
- *
378
- * @param safeAddress - The Safe address
379
- * @returns The history of incoming transactions
380
- * @throws "Invalid Safe address"
381
- * @throws "Checksum address validation failed"
382
- */
383
- async getIncomingTransactions(safeAddress) {
384
- if (safeAddress === '') {
385
- throw new Error('Invalid Safe address');
386
- }
387
- const { address } = __classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_getEip3770Address).call(this, safeAddress);
388
- return (0, httpRequests_1.sendRequest)({
389
- url: `${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v1/safes/${address}/incoming-transfers?executed=true`,
390
- method: httpRequests_1.HttpMethod.Get
391
- });
392
- }
393
- /**
394
- * Returns the history of module transactions of a Safe account.
395
- *
396
- * @param safeAddress - The Safe address
397
- * @returns The history of module transactions
398
- * @throws "Invalid Safe address"
399
- * @throws "Invalid data"
400
- * @throws "Invalid ethereum address"
401
- */
402
- async getModuleTransactions(safeAddress) {
403
- if (safeAddress === '') {
404
- throw new Error('Invalid Safe address');
405
- }
406
- const { address } = __classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_getEip3770Address).call(this, safeAddress);
407
- return (0, httpRequests_1.sendRequest)({
408
- url: `${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v1/safes/${address}/module-transactions/`,
409
- method: httpRequests_1.HttpMethod.Get
410
- });
411
- }
412
- /**
413
- * Returns the history of multi-signature transactions of a Safe account.
414
- *
415
- * @param safeAddress - The Safe address
416
- * @returns The history of multi-signature transactions
417
- * @throws "Invalid Safe address"
418
- * @throws "Checksum address validation failed"
419
- */
420
- async getMultisigTransactions(safeAddress) {
421
- if (safeAddress === '') {
422
- throw new Error('Invalid Safe address');
423
- }
424
- const { address } = __classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_getEip3770Address).call(this, safeAddress);
425
- return (0, httpRequests_1.sendRequest)({
426
- url: `${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v1/safes/${address}/multisig-transactions/`,
427
- method: httpRequests_1.HttpMethod.Get
428
- });
429
- }
430
- async getPendingTransactions(safeAddress, propsOrCurrentNonce = {}) {
431
- if (safeAddress === '') {
432
- throw new Error('Invalid Safe address');
433
- }
434
- // TODO: Remove @deprecated migration code
435
- let currentNonce;
436
- let hasConfirmations;
437
- let ordering;
438
- let limit;
439
- let offset;
440
- if (typeof propsOrCurrentNonce === 'object') {
441
- ;
442
- ({ currentNonce, hasConfirmations, ordering, limit, offset } = propsOrCurrentNonce);
443
- }
444
- else {
445
- console.warn('Deprecated: Use `currentNonce` inside an object instead. See `PendingTransactionsOptions`.');
446
- currentNonce = propsOrCurrentNonce;
447
- }
448
- // END of @deprecated migration code
449
- const { address } = __classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_getEip3770Address).call(this, safeAddress);
450
- const nonce = currentNonce ? currentNonce : (await this.getSafeInfo(address)).nonce;
451
- const url = new URL(`${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v1/safes/${address}/multisig-transactions/?executed=false&nonce__gte=${nonce}`);
452
- if (hasConfirmations) {
453
- url.searchParams.set('has_confirmations', hasConfirmations.toString());
454
- }
455
- if (ordering) {
456
- url.searchParams.set('ordering', ordering);
457
- }
458
- if (limit != null) {
459
- url.searchParams.set('limit', limit.toString());
460
- }
461
- if (offset != null) {
462
- url.searchParams.set('offset', offset.toString());
463
- }
464
- return (0, httpRequests_1.sendRequest)({
465
- url: url.toString(),
466
- method: httpRequests_1.HttpMethod.Get
467
- });
468
- }
469
- /**
470
- * Returns a list of transactions for a Safe. The list has different structures depending on the transaction type
471
- *
472
- * @param safeAddress - The Safe address
473
- * @returns The list of transactions waiting for the confirmation of the Safe owners
474
- * @throws "Invalid Safe address"
475
- * @throws "Checksum address validation failed"
476
- */
477
- async getAllTransactions(safeAddress, options) {
478
- if (safeAddress === '') {
479
- throw new Error('Invalid Safe address');
480
- }
481
- const { address } = __classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_getEip3770Address).call(this, safeAddress);
482
- const url = new URL(`${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v1/safes/${address}/all-transactions/`);
483
- const trusted = options?.trusted?.toString() || 'true';
484
- url.searchParams.set('trusted', trusted);
485
- const queued = options?.queued?.toString() || 'true';
486
- url.searchParams.set('queued', queued);
487
- const executed = options?.executed?.toString() || 'false';
488
- url.searchParams.set('executed', executed);
489
- return (0, httpRequests_1.sendRequest)({
490
- url: url.toString(),
491
- method: httpRequests_1.HttpMethod.Get
492
- });
493
- }
494
- /**
495
- * Returns the right nonce to propose a new transaction after the last pending transaction.
496
- *
497
- * @param safeAddress - The Safe address
498
- * @returns The right nonce to propose a new transaction after the last pending transaction
499
- * @throws "Invalid Safe address"
500
- * @throws "Invalid data"
501
- * @throws "Invalid ethereum address"
502
- */
503
- async getNextNonce(safeAddress) {
504
- if (safeAddress === '') {
505
- throw new Error('Invalid Safe address');
506
- }
507
- const { address } = __classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_getEip3770Address).call(this, safeAddress);
508
- const pendingTransactions = await this.getPendingTransactions(address);
509
- if (pendingTransactions.results.length > 0) {
510
- const nonces = pendingTransactions.results.map((tx) => tx.nonce);
511
- const lastNonce = Math.max(...nonces);
512
- return lastNonce + 1;
513
- }
514
- const safeInfo = await this.getSafeInfo(address);
515
- return safeInfo.nonce;
516
- }
517
- /**
518
- * Returns the list of all the ERC20 tokens handled by the Safe.
519
- *
520
- * @returns The list of all the ERC20 tokens
521
- */
522
- async getTokenList() {
523
- return (0, httpRequests_1.sendRequest)({
524
- url: `${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v1/tokens/`,
525
- method: httpRequests_1.HttpMethod.Get
526
- });
527
- }
528
- /**
529
- * Returns the information of a given ERC20 token.
530
- *
531
- * @param tokenAddress - The token address
532
- * @returns The information of the given ERC20 token
533
- * @throws "Invalid token address"
534
- * @throws "Checksum address validation failed"
535
- */
536
- async getToken(tokenAddress) {
537
- if (tokenAddress === '') {
538
- throw new Error('Invalid token address');
539
- }
540
- const { address } = __classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_getEip3770Address).call(this, tokenAddress);
541
- return (0, httpRequests_1.sendRequest)({
542
- url: `${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v1/tokens/${address}/`,
543
- method: httpRequests_1.HttpMethod.Get
544
- });
545
- }
546
- /**
547
- * Get a message by its safe message hash
548
- * @param messageHash The Safe message hash
549
- * @returns The message
550
- */
551
- async getMessage(messageHash) {
552
- if (!messageHash) {
553
- throw new Error('Invalid messageHash');
554
- }
555
- return (0, httpRequests_1.sendRequest)({
556
- url: `${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v1/messages/${messageHash}/`,
557
- method: httpRequests_1.HttpMethod.Get
558
- });
559
- }
560
- /**
561
- * Get the list of messages associated to a Safe account
562
- * @param safeAddress The safe address
563
- * @param options The options to filter the list of messages
564
- * @returns The paginated list of messages
565
- */
566
- async getMessages(safeAddress, { ordering, limit, offset } = {}) {
567
- if (!__classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_isValidAddress).call(this, safeAddress)) {
568
- throw new Error('Invalid safeAddress');
569
- }
570
- const url = new URL(`${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v1/safes/${safeAddress}/messages/`);
571
- if (ordering) {
572
- url.searchParams.set('ordering', ordering);
573
- }
574
- if (limit != null) {
575
- url.searchParams.set('limit', limit.toString());
576
- }
577
- if (offset != null) {
578
- url.searchParams.set('offset', offset.toString());
579
- }
580
- return (0, httpRequests_1.sendRequest)({
581
- url: url.toString(),
582
- method: httpRequests_1.HttpMethod.Get
583
- });
584
- }
585
- /**
586
- * Creates a new message with an initial signature
587
- * Add more signatures from other owners using addMessageSignature()
588
- * @param safeAddress The safe address
589
- * @param options The raw message to add, signature and safeAppId if any
590
- */
591
- async addMessage(safeAddress, addMessageProps) {
592
- if (!__classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_isValidAddress).call(this, safeAddress)) {
593
- throw new Error('Invalid safeAddress');
594
- }
595
- return (0, httpRequests_1.sendRequest)({
596
- url: `${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v1/safes/${safeAddress}/messages/`,
597
- method: httpRequests_1.HttpMethod.Post,
598
- body: addMessageProps
599
- });
600
- }
601
- /**
602
- * Add a signature to an existing message
603
- * @param messageHash The safe message hash
604
- * @param signature The signature
605
- */
606
- async addMessageSignature(messageHash, signature) {
607
- if (!messageHash || !signature) {
608
- throw new Error('Invalid messageHash or signature');
609
- }
610
- return (0, httpRequests_1.sendRequest)({
611
- url: `${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v1/messages/${messageHash}/signatures/`,
612
- method: httpRequests_1.HttpMethod.Post,
613
- body: {
614
- signature
615
- }
616
- });
617
- }
618
- /**
619
- * Get the SafeOperations that were sent from a particular address.
620
- * @param getSafeOperationsProps - The parameters to filter the list of SafeOperations
621
- * @throws "Safe address must not be empty"
622
- * @throws "Invalid Ethereum address {safeAddress}"
623
- * @returns The SafeOperations sent from the given Safe's address
624
- */
625
- async getSafeOperationsByAddress({ safeAddress, ordering, limit, offset }) {
626
- if (!safeAddress) {
627
- throw new Error('Safe address must not be empty');
628
- }
629
- const { address } = __classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_getEip3770Address).call(this, safeAddress);
630
- const url = new URL(`${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v1/safes/${address}/safe-operations/`);
631
- if (ordering) {
632
- url.searchParams.set('ordering', ordering);
633
- }
634
- if (limit != null) {
635
- url.searchParams.set('limit', limit.toString());
636
- }
637
- if (offset != null) {
638
- url.searchParams.set('offset', offset.toString());
639
- }
640
- return (0, httpRequests_1.sendRequest)({
641
- url: url.toString(),
642
- method: httpRequests_1.HttpMethod.Get
643
- });
644
- }
645
- /**
646
- * Get a SafeOperation by its hash.
647
- * @param safeOperationHash The SafeOperation hash
648
- * @throws "SafeOperation hash must not be empty"
649
- * @throws "Not found."
650
- * @returns The SafeOperation
651
- */
652
- async getSafeOperation(safeOperationHash) {
653
- if (!safeOperationHash) {
654
- throw new Error('SafeOperation hash must not be empty');
655
- }
656
- return (0, httpRequests_1.sendRequest)({
657
- url: `${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v1/safe-operations/${safeOperationHash}/`,
658
- method: httpRequests_1.HttpMethod.Get
659
- });
660
- }
661
- /**
662
- * Create a new 4337 SafeOperation for a Safe.
663
- * @param addSafeOperationProps - The configuration of the SafeOperation
664
- * @throws "Safe address must not be empty"
665
- * @throws "Invalid Safe address {safeAddress}"
666
- * @throws "Module address must not be empty"
667
- * @throws "Invalid module address {moduleAddress}"
668
- * @throws "Signature must not be empty"
669
- */
670
- async addSafeOperation(safeOperation) {
671
- let safeAddress, moduleAddress;
672
- let addSafeOperationProps;
673
- if ((0, types_kit_1.isSafeOperation)(safeOperation)) {
674
- addSafeOperationProps = await (0, safeOperation_1.getAddSafeOperationProps)(safeOperation);
675
- }
676
- else {
677
- addSafeOperationProps = safeOperation;
678
- }
679
- const { entryPoint, moduleAddress: moduleAddressProp, options, safeAddress: safeAddressProp, userOperation } = addSafeOperationProps;
680
- if (!safeAddressProp) {
681
- throw new Error('Safe address must not be empty');
682
- }
683
- try {
684
- safeAddress = __classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_getEip3770Address).call(this, safeAddressProp).address;
685
- }
686
- catch (err) {
687
- throw new Error(`Invalid Safe address ${safeAddressProp}`);
688
- }
689
- if (!moduleAddressProp) {
690
- throw new Error('Module address must not be empty');
691
- }
692
- try {
693
- moduleAddress = __classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_getEip3770Address).call(this, moduleAddressProp).address;
694
- }
695
- catch (err) {
696
- throw new Error(`Invalid module address ${moduleAddressProp}`);
697
- }
698
- if ((0, utils_1.isEmptyData)(userOperation.signature)) {
699
- throw new Error('Signature must not be empty');
700
- }
701
- // We are receiving the timestamp in seconds (block timestamp), but the API expects it in milliseconds
702
- const getISOString = (date) => !date ? null : new Date(date * 1000).toISOString();
703
- return (0, httpRequests_1.sendRequest)({
704
- url: `${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v1/safes/${safeAddress}/safe-operations/`,
705
- method: httpRequests_1.HttpMethod.Post,
706
- body: {
707
- nonce: Number(userOperation.nonce),
708
- initCode: (0, utils_1.isEmptyData)(userOperation.initCode) ? null : userOperation.initCode,
709
- callData: userOperation.callData,
710
- callGasLimit: userOperation.callGasLimit.toString(),
711
- verificationGasLimit: userOperation.verificationGasLimit.toString(),
712
- preVerificationGas: userOperation.preVerificationGas.toString(),
713
- maxFeePerGas: userOperation.maxFeePerGas.toString(),
714
- maxPriorityFeePerGas: userOperation.maxPriorityFeePerGas.toString(),
715
- paymasterAndData: (0, utils_1.isEmptyData)(userOperation.paymasterAndData)
716
- ? null
717
- : userOperation.paymasterAndData,
718
- entryPoint,
719
- validAfter: getISOString(options?.validAfter),
720
- validUntil: getISOString(options?.validUntil),
721
- signature: userOperation.signature,
722
- moduleAddress
723
- }
724
- });
725
- }
726
- /**
727
- * Returns the list of confirmations for a given a SafeOperation.
728
- *
729
- * @param safeOperationHash - The hash of the SafeOperation to get confirmations for
730
- * @param getSafeOperationConfirmationsOptions - Additional options for fetching the list of confirmations
731
- * @returns The list of confirmations
732
- * @throws "Invalid SafeOperation hash"
733
- * @throws "Invalid data"
734
- */
735
- async getSafeOperationConfirmations(safeOperationHash, { limit, offset } = {}) {
736
- if (!safeOperationHash) {
737
- throw new Error('Invalid SafeOperation hash');
738
- }
739
- const url = new URL(`${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v1/safe-operations/${safeOperationHash}/confirmations/`);
740
- if (limit != null) {
741
- url.searchParams.set('limit', limit.toString());
742
- }
743
- if (offset != null) {
744
- url.searchParams.set('offset', offset.toString());
745
- }
746
- return (0, httpRequests_1.sendRequest)({
747
- url: url.toString(),
748
- method: httpRequests_1.HttpMethod.Get
749
- });
750
- }
751
- /**
752
- * Adds a confirmation for a SafeOperation.
753
- *
754
- * @param safeOperationHash The SafeOperation hash
755
- * @param signature - Signature of the SafeOperation
756
- * @returns
757
- * @throws "Invalid SafeOperation hash"
758
- * @throws "Invalid signature"
759
- * @throws "Malformed data"
760
- * @throws "Error processing data"
761
- */
762
- async confirmSafeOperation(safeOperationHash, signature) {
763
- if (!safeOperationHash) {
764
- throw new Error('Invalid SafeOperation hash');
765
- }
766
- if (!signature) {
767
- throw new Error('Invalid signature');
768
- }
769
- return (0, httpRequests_1.sendRequest)({
770
- url: `${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v1/safe-operations/${safeOperationHash}/confirmations/`,
771
- method: httpRequests_1.HttpMethod.Post,
772
- body: { signature }
773
- });
774
- }
775
- }
776
- _SafeApiKit_chainId = new WeakMap(), _SafeApiKit_txServiceBaseUrl = new WeakMap(), _SafeApiKit_instances = new WeakSet(), _SafeApiKit_isValidAddress = function _SafeApiKit_isValidAddress(address) {
777
- try {
778
- (0, protocol_kit_1.validateEthereumAddress)(address);
779
- return true;
780
- }
781
- catch {
782
- return false;
783
- }
784
- }, _SafeApiKit_getEip3770Address = function _SafeApiKit_getEip3770Address(fullAddress) {
785
- return (0, protocol_kit_1.validateEip3770Address)(fullAddress, __classPrivateFieldGet(this, _SafeApiKit_chainId, "f"));
786
- };
787
- exports.default = SafeApiKit;
788
- //# sourceMappingURL=SafeApiKit.js.map