@safe-global/api-kit 2.5.9 → 3.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/cjs/index.cjs +993 -0
  2. package/dist/esm/index.mjs +960 -0
  3. package/dist/src/SafeApiKit.d.ts +10 -1
  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 +3 -0
  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 +5 -2
  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 -804
  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,804 +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
- }).then((response) => {
197
- // FIXME remove when the transaction service returns the singleton property instead of masterCopy
198
- if (!response?.singleton) {
199
- const { masterCopy, ...rest } = response;
200
- return { ...rest, singleton: masterCopy };
201
- }
202
- return response;
203
- });
204
- }
205
- /**
206
- * Returns the list of delegates.
207
- *
208
- * @param getSafeDelegateProps - Properties to filter the returned list of delegates
209
- * @returns The list of delegates
210
- * @throws "Checksum address validation failed"
211
- */
212
- async getSafeDelegates({ safeAddress, delegateAddress, delegatorAddress, label, limit, offset }) {
213
- const url = new URL(`${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v2/delegates`);
214
- if (safeAddress) {
215
- const { address: safe } = __classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_getEip3770Address).call(this, safeAddress);
216
- url.searchParams.set('safe', safe);
217
- }
218
- if (delegateAddress) {
219
- const { address: delegate } = __classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_getEip3770Address).call(this, delegateAddress);
220
- url.searchParams.set('delegate', delegate);
221
- }
222
- if (delegatorAddress) {
223
- const { address: delegator } = __classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_getEip3770Address).call(this, delegatorAddress);
224
- url.searchParams.set('delegator', delegator);
225
- }
226
- if (label) {
227
- url.searchParams.set('label', label);
228
- }
229
- if (limit != null) {
230
- url.searchParams.set('limit', limit.toString());
231
- }
232
- if (offset != null) {
233
- url.searchParams.set('offset', offset.toString());
234
- }
235
- return (0, httpRequests_1.sendRequest)({
236
- url: url.toString(),
237
- method: httpRequests_1.HttpMethod.Get
238
- });
239
- }
240
- /**
241
- * Adds a new delegate for a given Safe address.
242
- *
243
- * @param addSafeDelegateProps - The configuration of the new delegate
244
- * @returns
245
- * @throws "Invalid Safe delegate address"
246
- * @throws "Invalid Safe delegator address"
247
- * @throws "Invalid label"
248
- * @throws "Checksum address validation failed"
249
- * @throws "Address <delegate_address> is not checksumed"
250
- * @throws "Safe=<safe_address> does not exist or it's still not indexed"
251
- * @throws "Signing owner is not an owner of the Safe"
252
- */
253
- async addSafeDelegate({ safeAddress, delegateAddress, delegatorAddress, label, signer }) {
254
- if (delegateAddress === '') {
255
- throw new Error('Invalid Safe delegate address');
256
- }
257
- if (delegatorAddress === '') {
258
- throw new Error('Invalid Safe delegator address');
259
- }
260
- if (label === '') {
261
- throw new Error('Invalid label');
262
- }
263
- const { address: delegate } = __classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_getEip3770Address).call(this, delegateAddress);
264
- const { address: delegator } = __classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_getEip3770Address).call(this, delegatorAddress);
265
- const signature = await (0, signDelegate_1.signDelegate)(signer, delegate, __classPrivateFieldGet(this, _SafeApiKit_chainId, "f"));
266
- const body = {
267
- safe: safeAddress ? __classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_getEip3770Address).call(this, safeAddress).address : null,
268
- delegate,
269
- delegator,
270
- label,
271
- signature
272
- };
273
- return (0, httpRequests_1.sendRequest)({
274
- url: `${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v2/delegates/`,
275
- method: httpRequests_1.HttpMethod.Post,
276
- body
277
- });
278
- }
279
- /**
280
- * Removes a delegate for a given Safe address.
281
- *
282
- * @param deleteSafeDelegateProps - The configuration for the delegate that will be removed
283
- * @returns
284
- * @throws "Invalid Safe delegate address"
285
- * @throws "Invalid Safe delegator address"
286
- * @throws "Checksum address validation failed"
287
- * @throws "Signing owner is not an owner of the Safe"
288
- * @throws "Not found"
289
- */
290
- async removeSafeDelegate({ delegateAddress, delegatorAddress, signer }) {
291
- if (delegateAddress === '') {
292
- throw new Error('Invalid Safe delegate address');
293
- }
294
- if (delegatorAddress === '') {
295
- throw new Error('Invalid Safe delegator address');
296
- }
297
- const { address: delegate } = __classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_getEip3770Address).call(this, delegateAddress);
298
- const { address: delegator } = __classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_getEip3770Address).call(this, delegatorAddress);
299
- const signature = await (0, signDelegate_1.signDelegate)(signer, delegate, __classPrivateFieldGet(this, _SafeApiKit_chainId, "f"));
300
- return (0, httpRequests_1.sendRequest)({
301
- url: `${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v2/delegates/${delegate}`,
302
- method: httpRequests_1.HttpMethod.Delete,
303
- body: {
304
- delegator,
305
- signature
306
- }
307
- });
308
- }
309
- /**
310
- * Returns the creation information of a Safe.
311
- *
312
- * @param safeAddress - The Safe address
313
- * @returns The creation information of a Safe
314
- * @throws "Invalid Safe address"
315
- * @throws "Safe creation not found"
316
- * @throws "Checksum address validation failed"
317
- * @throws "Problem connecting to Ethereum network"
318
- */
319
- async getSafeCreationInfo(safeAddress) {
320
- if (safeAddress === '') {
321
- throw new Error('Invalid Safe address');
322
- }
323
- const { address } = __classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_getEip3770Address).call(this, safeAddress);
324
- return (0, httpRequests_1.sendRequest)({
325
- url: `${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v1/safes/${address}/creation/`,
326
- method: httpRequests_1.HttpMethod.Get
327
- }).then((response) => {
328
- // FIXME remove when the transaction service returns the singleton property instead of masterCopy
329
- if (!response?.singleton) {
330
- const { masterCopy, ...rest } = response;
331
- return { ...rest, singleton: masterCopy };
332
- }
333
- return response;
334
- });
335
- }
336
- /**
337
- * Estimates the safeTxGas for a given Safe multi-signature transaction.
338
- *
339
- * @param safeAddress - The Safe address
340
- * @param safeTransaction - The Safe transaction to estimate
341
- * @returns The safeTxGas for the given Safe transaction
342
- * @throws "Invalid Safe address"
343
- * @throws "Data not valid"
344
- * @throws "Safe not found"
345
- * @throws "Tx not valid"
346
- */
347
- async estimateSafeTransaction(safeAddress, safeTransaction) {
348
- if (safeAddress === '') {
349
- throw new Error('Invalid Safe address');
350
- }
351
- const { address } = __classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_getEip3770Address).call(this, safeAddress);
352
- return (0, httpRequests_1.sendRequest)({
353
- url: `${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v1/safes/${address}/multisig-transactions/estimations/`,
354
- method: httpRequests_1.HttpMethod.Post,
355
- body: safeTransaction
356
- });
357
- }
358
- /**
359
- * Creates a new multi-signature transaction with its confirmations and stores it in the Safe Transaction Service.
360
- *
361
- * @param proposeTransactionConfig - The configuration of the proposed transaction
362
- * @returns The hash of the Safe transaction proposed
363
- * @throws "Invalid Safe address"
364
- * @throws "Invalid safeTxHash"
365
- * @throws "Invalid data"
366
- * @throws "Invalid ethereum address/User is not an owner/Invalid signature/Nonce already executed/Sender is not an owner"
367
- */
368
- async proposeTransaction({ safeAddress, safeTransactionData, safeTxHash, senderAddress, senderSignature, origin }) {
369
- if (safeAddress === '') {
370
- throw new Error('Invalid Safe address');
371
- }
372
- const { address: safe } = __classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_getEip3770Address).call(this, safeAddress);
373
- const { address: sender } = __classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_getEip3770Address).call(this, senderAddress);
374
- if (safeTxHash === '') {
375
- throw new Error('Invalid safeTxHash');
376
- }
377
- return (0, httpRequests_1.sendRequest)({
378
- url: `${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v1/safes/${safe}/multisig-transactions/`,
379
- method: httpRequests_1.HttpMethod.Post,
380
- body: {
381
- ...safeTransactionData,
382
- contractTransactionHash: safeTxHash,
383
- sender,
384
- signature: senderSignature,
385
- origin
386
- }
387
- });
388
- }
389
- /**
390
- * Returns the history of incoming transactions of a Safe account.
391
- *
392
- * @param safeAddress - The Safe address
393
- * @returns The history of incoming transactions
394
- * @throws "Invalid Safe address"
395
- * @throws "Checksum address validation failed"
396
- */
397
- async getIncomingTransactions(safeAddress) {
398
- if (safeAddress === '') {
399
- throw new Error('Invalid Safe address');
400
- }
401
- const { address } = __classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_getEip3770Address).call(this, safeAddress);
402
- return (0, httpRequests_1.sendRequest)({
403
- url: `${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v1/safes/${address}/incoming-transfers?executed=true`,
404
- method: httpRequests_1.HttpMethod.Get
405
- });
406
- }
407
- /**
408
- * Returns the history of module transactions of a Safe account.
409
- *
410
- * @param safeAddress - The Safe address
411
- * @returns The history of module transactions
412
- * @throws "Invalid Safe address"
413
- * @throws "Invalid data"
414
- * @throws "Invalid ethereum address"
415
- */
416
- async getModuleTransactions(safeAddress) {
417
- if (safeAddress === '') {
418
- throw new Error('Invalid Safe address');
419
- }
420
- const { address } = __classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_getEip3770Address).call(this, safeAddress);
421
- return (0, httpRequests_1.sendRequest)({
422
- url: `${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v1/safes/${address}/module-transactions/`,
423
- method: httpRequests_1.HttpMethod.Get
424
- });
425
- }
426
- /**
427
- * Returns the history of multi-signature transactions of a Safe account.
428
- *
429
- * @param safeAddress - The Safe address
430
- * @returns The history of multi-signature transactions
431
- * @throws "Invalid Safe address"
432
- * @throws "Checksum address validation failed"
433
- */
434
- async getMultisigTransactions(safeAddress) {
435
- if (safeAddress === '') {
436
- throw new Error('Invalid Safe address');
437
- }
438
- const { address } = __classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_getEip3770Address).call(this, safeAddress);
439
- return (0, httpRequests_1.sendRequest)({
440
- url: `${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v1/safes/${address}/multisig-transactions/`,
441
- method: httpRequests_1.HttpMethod.Get
442
- });
443
- }
444
- async getPendingTransactions(safeAddress, propsOrCurrentNonce = {}) {
445
- if (safeAddress === '') {
446
- throw new Error('Invalid Safe address');
447
- }
448
- // TODO: Remove @deprecated migration code
449
- let currentNonce;
450
- let hasConfirmations;
451
- let ordering;
452
- let limit;
453
- let offset;
454
- if (typeof propsOrCurrentNonce === 'object') {
455
- ;
456
- ({ currentNonce, hasConfirmations, ordering, limit, offset } = propsOrCurrentNonce);
457
- }
458
- else {
459
- console.warn('Deprecated: Use `currentNonce` inside an object instead. See `PendingTransactionsOptions`.');
460
- currentNonce = propsOrCurrentNonce;
461
- }
462
- // END of @deprecated migration code
463
- const { address } = __classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_getEip3770Address).call(this, safeAddress);
464
- const nonce = currentNonce ? currentNonce : (await this.getSafeInfo(address)).nonce;
465
- const url = new URL(`${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v1/safes/${address}/multisig-transactions/?executed=false&nonce__gte=${nonce}`);
466
- if (hasConfirmations) {
467
- url.searchParams.set('has_confirmations', hasConfirmations.toString());
468
- }
469
- if (ordering) {
470
- url.searchParams.set('ordering', ordering);
471
- }
472
- if (limit != null) {
473
- url.searchParams.set('limit', limit.toString());
474
- }
475
- if (offset != null) {
476
- url.searchParams.set('offset', offset.toString());
477
- }
478
- return (0, httpRequests_1.sendRequest)({
479
- url: url.toString(),
480
- method: httpRequests_1.HttpMethod.Get
481
- });
482
- }
483
- /**
484
- * Returns a list of transactions for a Safe. The list has different structures depending on the transaction type
485
- *
486
- * @param safeAddress - The Safe address
487
- * @returns The list of transactions waiting for the confirmation of the Safe owners
488
- * @throws "Invalid Safe address"
489
- * @throws "Checksum address validation failed"
490
- */
491
- async getAllTransactions(safeAddress, options) {
492
- if (safeAddress === '') {
493
- throw new Error('Invalid Safe address');
494
- }
495
- const { address } = __classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_getEip3770Address).call(this, safeAddress);
496
- const url = new URL(`${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v1/safes/${address}/all-transactions/`);
497
- const trusted = options?.trusted?.toString() || 'true';
498
- url.searchParams.set('trusted', trusted);
499
- const queued = options?.queued?.toString() || 'true';
500
- url.searchParams.set('queued', queued);
501
- const executed = options?.executed?.toString() || 'false';
502
- url.searchParams.set('executed', executed);
503
- return (0, httpRequests_1.sendRequest)({
504
- url: url.toString(),
505
- method: httpRequests_1.HttpMethod.Get
506
- });
507
- }
508
- /**
509
- * Returns the right nonce to propose a new transaction after the last pending transaction.
510
- *
511
- * @param safeAddress - The Safe address
512
- * @returns The right nonce to propose a new transaction after the last pending transaction
513
- * @throws "Invalid Safe address"
514
- * @throws "Invalid data"
515
- * @throws "Invalid ethereum address"
516
- */
517
- async getNextNonce(safeAddress) {
518
- if (safeAddress === '') {
519
- throw new Error('Invalid Safe address');
520
- }
521
- const { address } = __classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_getEip3770Address).call(this, safeAddress);
522
- const pendingTransactions = await this.getPendingTransactions(address);
523
- if (pendingTransactions.results.length > 0) {
524
- const maxNonce = pendingTransactions.results.reduce((acc, tx) => {
525
- const curr = BigInt(tx.nonce);
526
- return curr > acc ? curr : acc;
527
- }, 0n);
528
- return (maxNonce + 1n).toString();
529
- }
530
- const safeInfo = await this.getSafeInfo(address);
531
- return safeInfo.nonce;
532
- }
533
- /**
534
- * Returns the list of all the ERC20 tokens handled by the Safe.
535
- *
536
- * @returns The list of all the ERC20 tokens
537
- */
538
- async getTokenList() {
539
- return (0, httpRequests_1.sendRequest)({
540
- url: `${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v1/tokens/`,
541
- method: httpRequests_1.HttpMethod.Get
542
- });
543
- }
544
- /**
545
- * Returns the information of a given ERC20 token.
546
- *
547
- * @param tokenAddress - The token address
548
- * @returns The information of the given ERC20 token
549
- * @throws "Invalid token address"
550
- * @throws "Checksum address validation failed"
551
- */
552
- async getToken(tokenAddress) {
553
- if (tokenAddress === '') {
554
- throw new Error('Invalid token address');
555
- }
556
- const { address } = __classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_getEip3770Address).call(this, tokenAddress);
557
- return (0, httpRequests_1.sendRequest)({
558
- url: `${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v1/tokens/${address}/`,
559
- method: httpRequests_1.HttpMethod.Get
560
- });
561
- }
562
- /**
563
- * Get a message by its safe message hash
564
- * @param messageHash The Safe message hash
565
- * @returns The message
566
- */
567
- async getMessage(messageHash) {
568
- if (!messageHash) {
569
- throw new Error('Invalid messageHash');
570
- }
571
- return (0, httpRequests_1.sendRequest)({
572
- url: `${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v1/messages/${messageHash}/`,
573
- method: httpRequests_1.HttpMethod.Get
574
- });
575
- }
576
- /**
577
- * Get the list of messages associated to a Safe account
578
- * @param safeAddress The safe address
579
- * @param options The options to filter the list of messages
580
- * @returns The paginated list of messages
581
- */
582
- async getMessages(safeAddress, { ordering, limit, offset } = {}) {
583
- if (!__classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_isValidAddress).call(this, safeAddress)) {
584
- throw new Error('Invalid safeAddress');
585
- }
586
- const url = new URL(`${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v1/safes/${safeAddress}/messages/`);
587
- if (ordering) {
588
- url.searchParams.set('ordering', ordering);
589
- }
590
- if (limit != null) {
591
- url.searchParams.set('limit', limit.toString());
592
- }
593
- if (offset != null) {
594
- url.searchParams.set('offset', offset.toString());
595
- }
596
- return (0, httpRequests_1.sendRequest)({
597
- url: url.toString(),
598
- method: httpRequests_1.HttpMethod.Get
599
- });
600
- }
601
- /**
602
- * Creates a new message with an initial signature
603
- * Add more signatures from other owners using addMessageSignature()
604
- * @param safeAddress The safe address
605
- * @param options The raw message to add, signature and safeAppId if any
606
- */
607
- async addMessage(safeAddress, addMessageProps) {
608
- if (!__classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_isValidAddress).call(this, safeAddress)) {
609
- throw new Error('Invalid safeAddress');
610
- }
611
- return (0, httpRequests_1.sendRequest)({
612
- url: `${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v1/safes/${safeAddress}/messages/`,
613
- method: httpRequests_1.HttpMethod.Post,
614
- body: addMessageProps
615
- });
616
- }
617
- /**
618
- * Add a signature to an existing message
619
- * @param messageHash The safe message hash
620
- * @param signature The signature
621
- */
622
- async addMessageSignature(messageHash, signature) {
623
- if (!messageHash || !signature) {
624
- throw new Error('Invalid messageHash or signature');
625
- }
626
- return (0, httpRequests_1.sendRequest)({
627
- url: `${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v1/messages/${messageHash}/signatures/`,
628
- method: httpRequests_1.HttpMethod.Post,
629
- body: {
630
- signature
631
- }
632
- });
633
- }
634
- /**
635
- * Get the SafeOperations that were sent from a particular address.
636
- * @param getSafeOperationsProps - The parameters to filter the list of SafeOperations
637
- * @throws "Safe address must not be empty"
638
- * @throws "Invalid Ethereum address {safeAddress}"
639
- * @returns The SafeOperations sent from the given Safe's address
640
- */
641
- async getSafeOperationsByAddress({ safeAddress, ordering, limit, offset }) {
642
- if (!safeAddress) {
643
- throw new Error('Safe address must not be empty');
644
- }
645
- const { address } = __classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_getEip3770Address).call(this, safeAddress);
646
- const url = new URL(`${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v1/safes/${address}/safe-operations/`);
647
- if (ordering) {
648
- url.searchParams.set('ordering', ordering);
649
- }
650
- if (limit != null) {
651
- url.searchParams.set('limit', limit.toString());
652
- }
653
- if (offset != null) {
654
- url.searchParams.set('offset', offset.toString());
655
- }
656
- return (0, httpRequests_1.sendRequest)({
657
- url: url.toString(),
658
- method: httpRequests_1.HttpMethod.Get
659
- });
660
- }
661
- /**
662
- * Get a SafeOperation by its hash.
663
- * @param safeOperationHash The SafeOperation hash
664
- * @throws "SafeOperation hash must not be empty"
665
- * @throws "Not found."
666
- * @returns The SafeOperation
667
- */
668
- async getSafeOperation(safeOperationHash) {
669
- if (!safeOperationHash) {
670
- throw new Error('SafeOperation hash must not be empty');
671
- }
672
- return (0, httpRequests_1.sendRequest)({
673
- url: `${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v1/safe-operations/${safeOperationHash}/`,
674
- method: httpRequests_1.HttpMethod.Get
675
- });
676
- }
677
- /**
678
- * Create a new 4337 SafeOperation for a Safe.
679
- * @param addSafeOperationProps - The configuration of the SafeOperation
680
- * @throws "Safe address must not be empty"
681
- * @throws "Invalid Safe address {safeAddress}"
682
- * @throws "Module address must not be empty"
683
- * @throws "Invalid module address {moduleAddress}"
684
- * @throws "Signature must not be empty"
685
- */
686
- async addSafeOperation(safeOperation) {
687
- let safeAddress, moduleAddress;
688
- let addSafeOperationProps;
689
- if ((0, types_kit_1.isSafeOperation)(safeOperation)) {
690
- addSafeOperationProps = await (0, safeOperation_1.getAddSafeOperationProps)(safeOperation);
691
- }
692
- else {
693
- addSafeOperationProps = safeOperation;
694
- }
695
- const { entryPoint, moduleAddress: moduleAddressProp, options, safeAddress: safeAddressProp, userOperation } = addSafeOperationProps;
696
- if (!safeAddressProp) {
697
- throw new Error('Safe address must not be empty');
698
- }
699
- try {
700
- safeAddress = __classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_getEip3770Address).call(this, safeAddressProp).address;
701
- }
702
- catch (err) {
703
- throw new Error(`Invalid Safe address ${safeAddressProp}`);
704
- }
705
- if (!moduleAddressProp) {
706
- throw new Error('Module address must not be empty');
707
- }
708
- try {
709
- moduleAddress = __classPrivateFieldGet(this, _SafeApiKit_instances, "m", _SafeApiKit_getEip3770Address).call(this, moduleAddressProp).address;
710
- }
711
- catch (err) {
712
- throw new Error(`Invalid module address ${moduleAddressProp}`);
713
- }
714
- if ((0, utils_1.isEmptyData)(userOperation.signature)) {
715
- throw new Error('Signature must not be empty');
716
- }
717
- // We are receiving the timestamp in seconds (block timestamp), but the API expects it in milliseconds
718
- const getISOString = (date) => !date ? null : new Date(date * 1000).toISOString();
719
- return (0, httpRequests_1.sendRequest)({
720
- url: `${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v1/safes/${safeAddress}/safe-operations/`,
721
- method: httpRequests_1.HttpMethod.Post,
722
- body: {
723
- nonce: userOperation.nonce,
724
- initCode: (0, utils_1.isEmptyData)(userOperation.initCode) ? null : userOperation.initCode,
725
- callData: userOperation.callData,
726
- callGasLimit: userOperation.callGasLimit.toString(),
727
- verificationGasLimit: userOperation.verificationGasLimit.toString(),
728
- preVerificationGas: userOperation.preVerificationGas.toString(),
729
- maxFeePerGas: userOperation.maxFeePerGas.toString(),
730
- maxPriorityFeePerGas: userOperation.maxPriorityFeePerGas.toString(),
731
- paymasterAndData: (0, utils_1.isEmptyData)(userOperation.paymasterAndData)
732
- ? null
733
- : userOperation.paymasterAndData,
734
- entryPoint,
735
- validAfter: getISOString(options?.validAfter),
736
- validUntil: getISOString(options?.validUntil),
737
- signature: userOperation.signature,
738
- moduleAddress
739
- }
740
- });
741
- }
742
- /**
743
- * Returns the list of confirmations for a given a SafeOperation.
744
- *
745
- * @param safeOperationHash - The hash of the SafeOperation to get confirmations for
746
- * @param getSafeOperationConfirmationsOptions - Additional options for fetching the list of confirmations
747
- * @returns The list of confirmations
748
- * @throws "Invalid SafeOperation hash"
749
- * @throws "Invalid data"
750
- */
751
- async getSafeOperationConfirmations(safeOperationHash, { limit, offset } = {}) {
752
- if (!safeOperationHash) {
753
- throw new Error('Invalid SafeOperation hash');
754
- }
755
- const url = new URL(`${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v1/safe-operations/${safeOperationHash}/confirmations/`);
756
- if (limit != null) {
757
- url.searchParams.set('limit', limit.toString());
758
- }
759
- if (offset != null) {
760
- url.searchParams.set('offset', offset.toString());
761
- }
762
- return (0, httpRequests_1.sendRequest)({
763
- url: url.toString(),
764
- method: httpRequests_1.HttpMethod.Get
765
- });
766
- }
767
- /**
768
- * Adds a confirmation for a SafeOperation.
769
- *
770
- * @param safeOperationHash The SafeOperation hash
771
- * @param signature - Signature of the SafeOperation
772
- * @returns
773
- * @throws "Invalid SafeOperation hash"
774
- * @throws "Invalid signature"
775
- * @throws "Malformed data"
776
- * @throws "Error processing data"
777
- */
778
- async confirmSafeOperation(safeOperationHash, signature) {
779
- if (!safeOperationHash) {
780
- throw new Error('Invalid SafeOperation hash');
781
- }
782
- if (!signature) {
783
- throw new Error('Invalid signature');
784
- }
785
- return (0, httpRequests_1.sendRequest)({
786
- url: `${__classPrivateFieldGet(this, _SafeApiKit_txServiceBaseUrl, "f")}/v1/safe-operations/${safeOperationHash}/confirmations/`,
787
- method: httpRequests_1.HttpMethod.Post,
788
- body: { signature }
789
- });
790
- }
791
- }
792
- _SafeApiKit_chainId = new WeakMap(), _SafeApiKit_txServiceBaseUrl = new WeakMap(), _SafeApiKit_instances = new WeakSet(), _SafeApiKit_isValidAddress = function _SafeApiKit_isValidAddress(address) {
793
- try {
794
- (0, protocol_kit_1.validateEthereumAddress)(address);
795
- return true;
796
- }
797
- catch {
798
- return false;
799
- }
800
- }, _SafeApiKit_getEip3770Address = function _SafeApiKit_getEip3770Address(fullAddress) {
801
- return (0, protocol_kit_1.validateEip3770Address)(fullAddress, __classPrivateFieldGet(this, _SafeApiKit_chainId, "f"));
802
- };
803
- exports.default = SafeApiKit;
804
- //# sourceMappingURL=SafeApiKit.js.map