@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
@@ -0,0 +1,961 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ default: () => src_default
34
+ });
35
+ module.exports = __toCommonJS(src_exports);
36
+
37
+ // src/utils/httpRequests.ts
38
+ var import_node_fetch = __toESM(require("node-fetch"));
39
+ async function sendRequest({ url, method, body }) {
40
+ const response = await (0, import_node_fetch.default)(url, {
41
+ method,
42
+ headers: {
43
+ Accept: "application/json",
44
+ "Content-Type": "application/json"
45
+ },
46
+ body: JSON.stringify(body)
47
+ });
48
+ let jsonResponse;
49
+ try {
50
+ jsonResponse = await response.json();
51
+ } catch (error) {
52
+ if (!response.ok) {
53
+ throw new Error(response.statusText);
54
+ }
55
+ }
56
+ if (response.ok) {
57
+ return jsonResponse;
58
+ }
59
+ if (jsonResponse.data) {
60
+ throw new Error(jsonResponse.data);
61
+ }
62
+ if (jsonResponse.detail) {
63
+ throw new Error(jsonResponse.detail);
64
+ }
65
+ if (jsonResponse.message) {
66
+ throw new Error(jsonResponse.message);
67
+ }
68
+ if (jsonResponse.nonFieldErrors) {
69
+ throw new Error(jsonResponse.nonFieldErrors);
70
+ }
71
+ if (jsonResponse.delegate) {
72
+ throw new Error(jsonResponse.delegate);
73
+ }
74
+ if (jsonResponse.safe) {
75
+ throw new Error(jsonResponse.safe);
76
+ }
77
+ if (jsonResponse.delegator) {
78
+ throw new Error(jsonResponse.delegator);
79
+ }
80
+ throw new Error(response.statusText);
81
+ }
82
+
83
+ // src/utils/signDelegate.ts
84
+ async function signDelegate(walletClient, delegateAddress, chainId) {
85
+ const domain = {
86
+ name: "Safe Transaction Service",
87
+ version: "1.0",
88
+ chainId: Number(chainId)
89
+ };
90
+ const types = {
91
+ Delegate: [
92
+ { name: "delegateAddress", type: "address" },
93
+ { name: "totp", type: "uint256" }
94
+ ]
95
+ };
96
+ const totp = Math.floor(Date.now() / 1e3 / 3600);
97
+ return walletClient.signTypedData({
98
+ domain,
99
+ types,
100
+ primaryType: "Delegate",
101
+ message: { delegateAddress, totp }
102
+ });
103
+ }
104
+
105
+ // src/SafeApiKit.ts
106
+ var import_protocol_kit = require("@safe-global/protocol-kit");
107
+ var import_types_kit = require("@safe-global/types-kit");
108
+
109
+ // src/utils/config.ts
110
+ var TRANSACTION_SERVICE_URLS = {
111
+ "1": "https://safe-transaction-mainnet.safe.global/api",
112
+ "10": "https://safe-transaction-optimism.safe.global/api",
113
+ "56": "https://safe-transaction-bsc.safe.global/api",
114
+ "100": "https://safe-transaction-gnosis-chain.safe.global/api",
115
+ "137": "https://safe-transaction-polygon.safe.global/api",
116
+ "196": "https://safe-transaction-xlayer.safe.global/api",
117
+ "324": "https://safe-transaction-zksync.safe.global/api",
118
+ "1101": "https://safe-transaction-zkevm.safe.global/api",
119
+ "5000": "https://safe-transaction-mantle.safe.global/api",
120
+ "8453": "https://safe-transaction-base.safe.global/api",
121
+ "42161": "https://safe-transaction-arbitrum.safe.global/api",
122
+ "42220": "https://safe-transaction-celo.safe.global/api",
123
+ "43114": "https://safe-transaction-avalanche.safe.global/api",
124
+ "59144": "https://safe-transaction-linea.safe.global/api",
125
+ "81457": "https://safe-transaction-blast.safe.global/api",
126
+ "84532": "https://safe-transaction-base-sepolia.safe.global/api",
127
+ "534352": "https://safe-transaction-scroll.safe.global/api",
128
+ "11155111": "https://safe-transaction-sepolia.safe.global/api",
129
+ "1313161554": "https://safe-transaction-aurora.safe.global/api"
130
+ };
131
+
132
+ // src/utils/constants.ts
133
+ var EMPTY_DATA = "0x";
134
+
135
+ // src/utils/index.ts
136
+ var isEmptyData = (input) => !input || input === EMPTY_DATA;
137
+
138
+ // src/utils/safeOperation.ts
139
+ var getAddSafeOperationProps = async (safeOperation) => {
140
+ const userOperation = safeOperation.toUserOperation();
141
+ userOperation.signature = safeOperation.encodedSignatures();
142
+ return {
143
+ entryPoint: safeOperation.data.entryPoint,
144
+ moduleAddress: safeOperation.moduleAddress,
145
+ safeAddress: safeOperation.data.safe,
146
+ userOperation,
147
+ options: {
148
+ validAfter: safeOperation.data.validAfter,
149
+ validUntil: safeOperation.data.validUntil
150
+ }
151
+ };
152
+ };
153
+
154
+ // src/SafeApiKit.ts
155
+ var SafeApiKit = class {
156
+ #chainId;
157
+ #txServiceBaseUrl;
158
+ constructor({ chainId, txServiceUrl }) {
159
+ this.#chainId = chainId;
160
+ if (txServiceUrl) {
161
+ this.#txServiceBaseUrl = txServiceUrl;
162
+ } else {
163
+ const url = TRANSACTION_SERVICE_URLS[chainId.toString()];
164
+ if (!url) {
165
+ throw new TypeError(
166
+ `There is no transaction service available for chainId ${chainId}. Please set the txServiceUrl property to use a custom transaction service.`
167
+ );
168
+ }
169
+ this.#txServiceBaseUrl = url;
170
+ }
171
+ }
172
+ #isValidAddress(address) {
173
+ try {
174
+ (0, import_protocol_kit.validateEthereumAddress)(address);
175
+ return true;
176
+ } catch {
177
+ return false;
178
+ }
179
+ }
180
+ #getEip3770Address(fullAddress) {
181
+ return (0, import_protocol_kit.validateEip3770Address)(fullAddress, this.#chainId);
182
+ }
183
+ /**
184
+ * Returns the information and configuration of the service.
185
+ *
186
+ * @returns The information and configuration of the service
187
+ */
188
+ async getServiceInfo() {
189
+ return sendRequest({
190
+ url: `${this.#txServiceBaseUrl}/v1/about`,
191
+ method: "get" /* Get */
192
+ });
193
+ }
194
+ /**
195
+ * Returns the list of Safe singletons.
196
+ *
197
+ * @returns The list of Safe singletons
198
+ */
199
+ async getServiceSingletonsInfo() {
200
+ return sendRequest({
201
+ url: `${this.#txServiceBaseUrl}/v1/about/singletons`,
202
+ method: "get" /* Get */
203
+ });
204
+ }
205
+ /**
206
+ * Decodes the specified Safe transaction data.
207
+ *
208
+ * @param data - The Safe transaction data. '0x' prefixed hexadecimal string.
209
+ * @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
210
+ * @returns The transaction data decoded
211
+ * @throws "Invalid data"
212
+ * @throws "Not Found"
213
+ * @throws "Ensure this field has at least 1 hexadecimal chars (not counting 0x)."
214
+ */
215
+ async decodeData(data, to) {
216
+ if (data === "") {
217
+ throw new Error("Invalid data");
218
+ }
219
+ const dataDecoderRequest = { data };
220
+ if (to) {
221
+ dataDecoderRequest.to = to;
222
+ }
223
+ return sendRequest({
224
+ url: `${this.#txServiceBaseUrl}/v1/data-decoder/`,
225
+ method: "post" /* Post */,
226
+ body: dataDecoderRequest
227
+ });
228
+ }
229
+ /**
230
+ * Returns the list of Safes where the address provided is an owner.
231
+ *
232
+ * @param ownerAddress - The owner address
233
+ * @returns The list of Safes where the address provided is an owner
234
+ * @throws "Invalid owner address"
235
+ * @throws "Checksum address validation failed"
236
+ */
237
+ async getSafesByOwner(ownerAddress) {
238
+ if (ownerAddress === "") {
239
+ throw new Error("Invalid owner address");
240
+ }
241
+ const { address } = this.#getEip3770Address(ownerAddress);
242
+ return sendRequest({
243
+ url: `${this.#txServiceBaseUrl}/v1/owners/${address}/safes/`,
244
+ method: "get" /* Get */
245
+ });
246
+ }
247
+ /**
248
+ * Returns the list of Safes where the module address provided is enabled.
249
+ *
250
+ * @param moduleAddress - The Safe module address
251
+ * @returns The list of Safe addresses where the module provided is enabled
252
+ * @throws "Invalid module address"
253
+ * @throws "Module address checksum not valid"
254
+ */
255
+ async getSafesByModule(moduleAddress) {
256
+ if (moduleAddress === "") {
257
+ throw new Error("Invalid module address");
258
+ }
259
+ const { address } = this.#getEip3770Address(moduleAddress);
260
+ return sendRequest({
261
+ url: `${this.#txServiceBaseUrl}/v1/modules/${address}/safes/`,
262
+ method: "get" /* Get */
263
+ });
264
+ }
265
+ /**
266
+ * Returns all the information of a Safe transaction.
267
+ *
268
+ * @param safeTxHash - Hash of the Safe transaction
269
+ * @returns The information of a Safe transaction
270
+ * @throws "Invalid safeTxHash"
271
+ * @throws "Not found."
272
+ */
273
+ async getTransaction(safeTxHash) {
274
+ if (safeTxHash === "") {
275
+ throw new Error("Invalid safeTxHash");
276
+ }
277
+ return sendRequest({
278
+ url: `${this.#txServiceBaseUrl}/v1/multisig-transactions/${safeTxHash}/`,
279
+ method: "get" /* Get */
280
+ });
281
+ }
282
+ /**
283
+ * Returns the list of confirmations for a given a Safe transaction.
284
+ *
285
+ * @param safeTxHash - The hash of the Safe transaction
286
+ * @returns The list of confirmations
287
+ * @throws "Invalid safeTxHash"
288
+ */
289
+ async getTransactionConfirmations(safeTxHash) {
290
+ if (safeTxHash === "") {
291
+ throw new Error("Invalid safeTxHash");
292
+ }
293
+ return sendRequest({
294
+ url: `${this.#txServiceBaseUrl}/v1/multisig-transactions/${safeTxHash}/confirmations/`,
295
+ method: "get" /* Get */
296
+ });
297
+ }
298
+ /**
299
+ * Adds a confirmation for a Safe transaction.
300
+ *
301
+ * @param safeTxHash - Hash of the Safe transaction that will be confirmed
302
+ * @param signature - Signature of the transaction
303
+ * @returns
304
+ * @throws "Invalid safeTxHash"
305
+ * @throws "Invalid signature"
306
+ * @throws "Malformed data"
307
+ * @throws "Error processing data"
308
+ */
309
+ async confirmTransaction(safeTxHash, signature) {
310
+ if (safeTxHash === "") {
311
+ throw new Error("Invalid safeTxHash");
312
+ }
313
+ if (signature === "") {
314
+ throw new Error("Invalid signature");
315
+ }
316
+ return sendRequest({
317
+ url: `${this.#txServiceBaseUrl}/v1/multisig-transactions/${safeTxHash}/confirmations/`,
318
+ method: "post" /* Post */,
319
+ body: {
320
+ signature
321
+ }
322
+ });
323
+ }
324
+ /**
325
+ * Returns the information and configuration of the provided Safe address.
326
+ *
327
+ * @param safeAddress - The Safe address
328
+ * @returns The information and configuration of the provided Safe address
329
+ * @throws "Invalid Safe address"
330
+ * @throws "Checksum address validation failed"
331
+ */
332
+ async getSafeInfo(safeAddress) {
333
+ if (safeAddress === "") {
334
+ throw new Error("Invalid Safe address");
335
+ }
336
+ const { address } = this.#getEip3770Address(safeAddress);
337
+ return sendRequest({
338
+ url: `${this.#txServiceBaseUrl}/v1/safes/${address}/`,
339
+ method: "get" /* Get */
340
+ }).then((response) => {
341
+ if (!response?.singleton) {
342
+ const { masterCopy, ...rest } = response;
343
+ return { ...rest, singleton: masterCopy };
344
+ }
345
+ return response;
346
+ });
347
+ }
348
+ /**
349
+ * Returns the list of delegates.
350
+ *
351
+ * @param getSafeDelegateProps - Properties to filter the returned list of delegates
352
+ * @returns The list of delegates
353
+ * @throws "Checksum address validation failed"
354
+ */
355
+ async getSafeDelegates({
356
+ safeAddress,
357
+ delegateAddress,
358
+ delegatorAddress,
359
+ label,
360
+ limit,
361
+ offset
362
+ }) {
363
+ const url = new URL(`${this.#txServiceBaseUrl}/v2/delegates`);
364
+ if (safeAddress) {
365
+ const { address: safe } = this.#getEip3770Address(safeAddress);
366
+ url.searchParams.set("safe", safe);
367
+ }
368
+ if (delegateAddress) {
369
+ const { address: delegate } = this.#getEip3770Address(delegateAddress);
370
+ url.searchParams.set("delegate", delegate);
371
+ }
372
+ if (delegatorAddress) {
373
+ const { address: delegator } = this.#getEip3770Address(delegatorAddress);
374
+ url.searchParams.set("delegator", delegator);
375
+ }
376
+ if (label) {
377
+ url.searchParams.set("label", label);
378
+ }
379
+ if (limit != null) {
380
+ url.searchParams.set("limit", limit.toString());
381
+ }
382
+ if (offset != null) {
383
+ url.searchParams.set("offset", offset.toString());
384
+ }
385
+ return sendRequest({
386
+ url: url.toString(),
387
+ method: "get" /* Get */
388
+ });
389
+ }
390
+ /**
391
+ * Adds a new delegate for a given Safe address.
392
+ *
393
+ * @param addSafeDelegateProps - The configuration of the new delegate
394
+ * @returns
395
+ * @throws "Invalid Safe delegate address"
396
+ * @throws "Invalid Safe delegator address"
397
+ * @throws "Invalid label"
398
+ * @throws "Checksum address validation failed"
399
+ * @throws "Address <delegate_address> is not checksumed"
400
+ * @throws "Safe=<safe_address> does not exist or it's still not indexed"
401
+ * @throws "Signing owner is not an owner of the Safe"
402
+ */
403
+ async addSafeDelegate({
404
+ safeAddress,
405
+ delegateAddress,
406
+ delegatorAddress,
407
+ label,
408
+ signer
409
+ }) {
410
+ if (delegateAddress === "") {
411
+ throw new Error("Invalid Safe delegate address");
412
+ }
413
+ if (delegatorAddress === "") {
414
+ throw new Error("Invalid Safe delegator address");
415
+ }
416
+ if (label === "") {
417
+ throw new Error("Invalid label");
418
+ }
419
+ const { address: delegate } = this.#getEip3770Address(delegateAddress);
420
+ const { address: delegator } = this.#getEip3770Address(delegatorAddress);
421
+ const signature = await signDelegate(signer, delegate, this.#chainId);
422
+ const body = {
423
+ safe: safeAddress ? this.#getEip3770Address(safeAddress).address : null,
424
+ delegate,
425
+ delegator,
426
+ label,
427
+ signature
428
+ };
429
+ return sendRequest({
430
+ url: `${this.#txServiceBaseUrl}/v2/delegates/`,
431
+ method: "post" /* Post */,
432
+ body
433
+ });
434
+ }
435
+ /**
436
+ * Removes a delegate for a given Safe address.
437
+ *
438
+ * @param deleteSafeDelegateProps - The configuration for the delegate that will be removed
439
+ * @returns
440
+ * @throws "Invalid Safe delegate address"
441
+ * @throws "Invalid Safe delegator address"
442
+ * @throws "Checksum address validation failed"
443
+ * @throws "Signing owner is not an owner of the Safe"
444
+ * @throws "Not found"
445
+ */
446
+ async removeSafeDelegate({
447
+ delegateAddress,
448
+ delegatorAddress,
449
+ signer
450
+ }) {
451
+ if (delegateAddress === "") {
452
+ throw new Error("Invalid Safe delegate address");
453
+ }
454
+ if (delegatorAddress === "") {
455
+ throw new Error("Invalid Safe delegator address");
456
+ }
457
+ const { address: delegate } = this.#getEip3770Address(delegateAddress);
458
+ const { address: delegator } = this.#getEip3770Address(delegatorAddress);
459
+ const signature = await signDelegate(signer, delegate, this.#chainId);
460
+ return sendRequest({
461
+ url: `${this.#txServiceBaseUrl}/v2/delegates/${delegate}`,
462
+ method: "delete" /* Delete */,
463
+ body: {
464
+ delegator,
465
+ signature
466
+ }
467
+ });
468
+ }
469
+ /**
470
+ * Returns the creation information of a Safe.
471
+ *
472
+ * @param safeAddress - The Safe address
473
+ * @returns The creation information of a Safe
474
+ * @throws "Invalid Safe address"
475
+ * @throws "Safe creation not found"
476
+ * @throws "Checksum address validation failed"
477
+ * @throws "Problem connecting to Ethereum network"
478
+ */
479
+ async getSafeCreationInfo(safeAddress) {
480
+ if (safeAddress === "") {
481
+ throw new Error("Invalid Safe address");
482
+ }
483
+ const { address } = this.#getEip3770Address(safeAddress);
484
+ return sendRequest({
485
+ url: `${this.#txServiceBaseUrl}/v1/safes/${address}/creation/`,
486
+ method: "get" /* Get */
487
+ });
488
+ }
489
+ /**
490
+ * Estimates the safeTxGas for a given Safe multi-signature transaction.
491
+ *
492
+ * @param safeAddress - The Safe address
493
+ * @param safeTransaction - The Safe transaction to estimate
494
+ * @returns The safeTxGas for the given Safe transaction
495
+ * @throws "Invalid Safe address"
496
+ * @throws "Data not valid"
497
+ * @throws "Safe not found"
498
+ * @throws "Tx not valid"
499
+ */
500
+ async estimateSafeTransaction(safeAddress, safeTransaction) {
501
+ if (safeAddress === "") {
502
+ throw new Error("Invalid Safe address");
503
+ }
504
+ const { address } = this.#getEip3770Address(safeAddress);
505
+ return sendRequest({
506
+ url: `${this.#txServiceBaseUrl}/v1/safes/${address}/multisig-transactions/estimations/`,
507
+ method: "post" /* Post */,
508
+ body: safeTransaction
509
+ });
510
+ }
511
+ /**
512
+ * Creates a new multi-signature transaction with its confirmations and stores it in the Safe Transaction Service.
513
+ *
514
+ * @param proposeTransactionConfig - The configuration of the proposed transaction
515
+ * @returns The hash of the Safe transaction proposed
516
+ * @throws "Invalid Safe address"
517
+ * @throws "Invalid safeTxHash"
518
+ * @throws "Invalid data"
519
+ * @throws "Invalid ethereum address/User is not an owner/Invalid signature/Nonce already executed/Sender is not an owner"
520
+ */
521
+ async proposeTransaction({
522
+ safeAddress,
523
+ safeTransactionData,
524
+ safeTxHash,
525
+ senderAddress,
526
+ senderSignature,
527
+ origin
528
+ }) {
529
+ if (safeAddress === "") {
530
+ throw new Error("Invalid Safe address");
531
+ }
532
+ const { address: safe } = this.#getEip3770Address(safeAddress);
533
+ const { address: sender } = this.#getEip3770Address(senderAddress);
534
+ if (safeTxHash === "") {
535
+ throw new Error("Invalid safeTxHash");
536
+ }
537
+ return sendRequest({
538
+ url: `${this.#txServiceBaseUrl}/v1/safes/${safe}/multisig-transactions/`,
539
+ method: "post" /* Post */,
540
+ body: {
541
+ ...safeTransactionData,
542
+ contractTransactionHash: safeTxHash,
543
+ sender,
544
+ signature: senderSignature,
545
+ origin
546
+ }
547
+ });
548
+ }
549
+ /**
550
+ * Returns the history of incoming transactions of a Safe account.
551
+ *
552
+ * @param safeAddress - The Safe address
553
+ * @returns The history of incoming transactions
554
+ * @throws "Invalid Safe address"
555
+ * @throws "Checksum address validation failed"
556
+ */
557
+ async getIncomingTransactions(safeAddress) {
558
+ if (safeAddress === "") {
559
+ throw new Error("Invalid Safe address");
560
+ }
561
+ const { address } = this.#getEip3770Address(safeAddress);
562
+ return sendRequest({
563
+ url: `${this.#txServiceBaseUrl}/v1/safes/${address}/incoming-transfers?executed=true`,
564
+ method: "get" /* Get */
565
+ });
566
+ }
567
+ /**
568
+ * Returns the history of module transactions of a Safe account.
569
+ *
570
+ * @param safeAddress - The Safe address
571
+ * @returns The history of module transactions
572
+ * @throws "Invalid Safe address"
573
+ * @throws "Invalid data"
574
+ * @throws "Invalid ethereum address"
575
+ */
576
+ async getModuleTransactions(safeAddress) {
577
+ if (safeAddress === "") {
578
+ throw new Error("Invalid Safe address");
579
+ }
580
+ const { address } = this.#getEip3770Address(safeAddress);
581
+ return sendRequest({
582
+ url: `${this.#txServiceBaseUrl}/v1/safes/${address}/module-transactions/`,
583
+ method: "get" /* Get */
584
+ });
585
+ }
586
+ /**
587
+ * Returns the history of multi-signature transactions of a Safe account.
588
+ *
589
+ * @param safeAddress - The Safe address
590
+ * @returns The history of multi-signature transactions
591
+ * @throws "Invalid Safe address"
592
+ * @throws "Checksum address validation failed"
593
+ */
594
+ async getMultisigTransactions(safeAddress) {
595
+ if (safeAddress === "") {
596
+ throw new Error("Invalid Safe address");
597
+ }
598
+ const { address } = this.#getEip3770Address(safeAddress);
599
+ return sendRequest({
600
+ url: `${this.#txServiceBaseUrl}/v1/safes/${address}/multisig-transactions/`,
601
+ method: "get" /* Get */
602
+ });
603
+ }
604
+ async getPendingTransactions(safeAddress, propsOrCurrentNonce = {}) {
605
+ if (safeAddress === "") {
606
+ throw new Error("Invalid Safe address");
607
+ }
608
+ let currentNonce;
609
+ let hasConfirmations;
610
+ let ordering;
611
+ let limit;
612
+ let offset;
613
+ if (typeof propsOrCurrentNonce === "object") {
614
+ ;
615
+ ({ currentNonce, hasConfirmations, ordering, limit, offset } = propsOrCurrentNonce);
616
+ } else {
617
+ console.warn(
618
+ "Deprecated: Use `currentNonce` inside an object instead. See `PendingTransactionsOptions`."
619
+ );
620
+ currentNonce = propsOrCurrentNonce;
621
+ }
622
+ const { address } = this.#getEip3770Address(safeAddress);
623
+ const nonce = currentNonce ? currentNonce : (await this.getSafeInfo(address)).nonce;
624
+ const url = new URL(
625
+ `${this.#txServiceBaseUrl}/v1/safes/${address}/multisig-transactions/?executed=false&nonce__gte=${nonce}`
626
+ );
627
+ if (hasConfirmations) {
628
+ url.searchParams.set("has_confirmations", hasConfirmations.toString());
629
+ }
630
+ if (ordering) {
631
+ url.searchParams.set("ordering", ordering);
632
+ }
633
+ if (limit != null) {
634
+ url.searchParams.set("limit", limit.toString());
635
+ }
636
+ if (offset != null) {
637
+ url.searchParams.set("offset", offset.toString());
638
+ }
639
+ return sendRequest({
640
+ url: url.toString(),
641
+ method: "get" /* Get */
642
+ });
643
+ }
644
+ /**
645
+ * Returns a list of transactions for a Safe. The list has different structures depending on the transaction type
646
+ *
647
+ * @param safeAddress - The Safe address
648
+ * @returns The list of transactions waiting for the confirmation of the Safe owners
649
+ * @throws "Invalid Safe address"
650
+ * @throws "Checksum address validation failed"
651
+ */
652
+ async getAllTransactions(safeAddress, options) {
653
+ if (safeAddress === "") {
654
+ throw new Error("Invalid Safe address");
655
+ }
656
+ const { address } = this.#getEip3770Address(safeAddress);
657
+ const url = new URL(`${this.#txServiceBaseUrl}/v1/safes/${address}/all-transactions/`);
658
+ const trusted = options?.trusted?.toString() || "true";
659
+ url.searchParams.set("trusted", trusted);
660
+ const queued = options?.queued?.toString() || "true";
661
+ url.searchParams.set("queued", queued);
662
+ const executed = options?.executed?.toString() || "false";
663
+ url.searchParams.set("executed", executed);
664
+ return sendRequest({
665
+ url: url.toString(),
666
+ method: "get" /* Get */
667
+ });
668
+ }
669
+ /**
670
+ * Returns the right nonce to propose a new transaction after the last pending transaction.
671
+ *
672
+ * @param safeAddress - The Safe address
673
+ * @returns The right nonce to propose a new transaction after the last pending transaction
674
+ * @throws "Invalid Safe address"
675
+ * @throws "Invalid data"
676
+ * @throws "Invalid ethereum address"
677
+ */
678
+ async getNextNonce(safeAddress) {
679
+ if (safeAddress === "") {
680
+ throw new Error("Invalid Safe address");
681
+ }
682
+ const { address } = this.#getEip3770Address(safeAddress);
683
+ const pendingTransactions = await this.getPendingTransactions(address);
684
+ if (pendingTransactions.results.length > 0) {
685
+ const nonces = pendingTransactions.results.map((tx) => tx.nonce);
686
+ const lastNonce = Math.max(...nonces);
687
+ return lastNonce + 1;
688
+ }
689
+ const safeInfo = await this.getSafeInfo(address);
690
+ return safeInfo.nonce;
691
+ }
692
+ /**
693
+ * Returns the list of all the ERC20 tokens handled by the Safe.
694
+ *
695
+ * @returns The list of all the ERC20 tokens
696
+ */
697
+ async getTokenList() {
698
+ return sendRequest({
699
+ url: `${this.#txServiceBaseUrl}/v1/tokens/`,
700
+ method: "get" /* Get */
701
+ });
702
+ }
703
+ /**
704
+ * Returns the information of a given ERC20 token.
705
+ *
706
+ * @param tokenAddress - The token address
707
+ * @returns The information of the given ERC20 token
708
+ * @throws "Invalid token address"
709
+ * @throws "Checksum address validation failed"
710
+ */
711
+ async getToken(tokenAddress) {
712
+ if (tokenAddress === "") {
713
+ throw new Error("Invalid token address");
714
+ }
715
+ const { address } = this.#getEip3770Address(tokenAddress);
716
+ return sendRequest({
717
+ url: `${this.#txServiceBaseUrl}/v1/tokens/${address}/`,
718
+ method: "get" /* Get */
719
+ });
720
+ }
721
+ /**
722
+ * Get a message by its safe message hash
723
+ * @param messageHash The Safe message hash
724
+ * @returns The message
725
+ */
726
+ async getMessage(messageHash) {
727
+ if (!messageHash) {
728
+ throw new Error("Invalid messageHash");
729
+ }
730
+ return sendRequest({
731
+ url: `${this.#txServiceBaseUrl}/v1/messages/${messageHash}/`,
732
+ method: "get" /* Get */
733
+ });
734
+ }
735
+ /**
736
+ * Get the list of messages associated to a Safe account
737
+ * @param safeAddress The safe address
738
+ * @param options The options to filter the list of messages
739
+ * @returns The paginated list of messages
740
+ */
741
+ async getMessages(safeAddress, { ordering, limit, offset } = {}) {
742
+ if (!this.#isValidAddress(safeAddress)) {
743
+ throw new Error("Invalid safeAddress");
744
+ }
745
+ const url = new URL(`${this.#txServiceBaseUrl}/v1/safes/${safeAddress}/messages/`);
746
+ if (ordering) {
747
+ url.searchParams.set("ordering", ordering);
748
+ }
749
+ if (limit != null) {
750
+ url.searchParams.set("limit", limit.toString());
751
+ }
752
+ if (offset != null) {
753
+ url.searchParams.set("offset", offset.toString());
754
+ }
755
+ return sendRequest({
756
+ url: url.toString(),
757
+ method: "get" /* Get */
758
+ });
759
+ }
760
+ /**
761
+ * Creates a new message with an initial signature
762
+ * Add more signatures from other owners using addMessageSignature()
763
+ * @param safeAddress The safe address
764
+ * @param options The raw message to add, signature and safeAppId if any
765
+ */
766
+ async addMessage(safeAddress, addMessageProps) {
767
+ if (!this.#isValidAddress(safeAddress)) {
768
+ throw new Error("Invalid safeAddress");
769
+ }
770
+ return sendRequest({
771
+ url: `${this.#txServiceBaseUrl}/v1/safes/${safeAddress}/messages/`,
772
+ method: "post" /* Post */,
773
+ body: addMessageProps
774
+ });
775
+ }
776
+ /**
777
+ * Add a signature to an existing message
778
+ * @param messageHash The safe message hash
779
+ * @param signature The signature
780
+ */
781
+ async addMessageSignature(messageHash, signature) {
782
+ if (!messageHash || !signature) {
783
+ throw new Error("Invalid messageHash or signature");
784
+ }
785
+ return sendRequest({
786
+ url: `${this.#txServiceBaseUrl}/v1/messages/${messageHash}/signatures/`,
787
+ method: "post" /* Post */,
788
+ body: {
789
+ signature
790
+ }
791
+ });
792
+ }
793
+ /**
794
+ * Get the SafeOperations that were sent from a particular address.
795
+ * @param getSafeOperationsProps - The parameters to filter the list of SafeOperations
796
+ * @throws "Safe address must not be empty"
797
+ * @throws "Invalid Ethereum address {safeAddress}"
798
+ * @returns The SafeOperations sent from the given Safe's address
799
+ */
800
+ async getSafeOperationsByAddress({
801
+ safeAddress,
802
+ ordering,
803
+ limit,
804
+ offset
805
+ }) {
806
+ if (!safeAddress) {
807
+ throw new Error("Safe address must not be empty");
808
+ }
809
+ const { address } = this.#getEip3770Address(safeAddress);
810
+ const url = new URL(`${this.#txServiceBaseUrl}/v1/safes/${address}/safe-operations/`);
811
+ if (ordering) {
812
+ url.searchParams.set("ordering", ordering);
813
+ }
814
+ if (limit != null) {
815
+ url.searchParams.set("limit", limit.toString());
816
+ }
817
+ if (offset != null) {
818
+ url.searchParams.set("offset", offset.toString());
819
+ }
820
+ return sendRequest({
821
+ url: url.toString(),
822
+ method: "get" /* Get */
823
+ });
824
+ }
825
+ /**
826
+ * Get a SafeOperation by its hash.
827
+ * @param safeOperationHash The SafeOperation hash
828
+ * @throws "SafeOperation hash must not be empty"
829
+ * @throws "Not found."
830
+ * @returns The SafeOperation
831
+ */
832
+ async getSafeOperation(safeOperationHash) {
833
+ if (!safeOperationHash) {
834
+ throw new Error("SafeOperation hash must not be empty");
835
+ }
836
+ return sendRequest({
837
+ url: `${this.#txServiceBaseUrl}/v1/safe-operations/${safeOperationHash}/`,
838
+ method: "get" /* Get */
839
+ });
840
+ }
841
+ /**
842
+ * Create a new 4337 SafeOperation for a Safe.
843
+ * @param addSafeOperationProps - The configuration of the SafeOperation
844
+ * @throws "Safe address must not be empty"
845
+ * @throws "Invalid Safe address {safeAddress}"
846
+ * @throws "Module address must not be empty"
847
+ * @throws "Invalid module address {moduleAddress}"
848
+ * @throws "Signature must not be empty"
849
+ */
850
+ async addSafeOperation(safeOperation) {
851
+ let safeAddress, moduleAddress;
852
+ let addSafeOperationProps;
853
+ if ((0, import_types_kit.isSafeOperation)(safeOperation)) {
854
+ addSafeOperationProps = await getAddSafeOperationProps(safeOperation);
855
+ } else {
856
+ addSafeOperationProps = safeOperation;
857
+ }
858
+ const {
859
+ entryPoint,
860
+ moduleAddress: moduleAddressProp,
861
+ options,
862
+ safeAddress: safeAddressProp,
863
+ userOperation
864
+ } = addSafeOperationProps;
865
+ if (!safeAddressProp) {
866
+ throw new Error("Safe address must not be empty");
867
+ }
868
+ try {
869
+ safeAddress = this.#getEip3770Address(safeAddressProp).address;
870
+ } catch (err) {
871
+ throw new Error(`Invalid Safe address ${safeAddressProp}`);
872
+ }
873
+ if (!moduleAddressProp) {
874
+ throw new Error("Module address must not be empty");
875
+ }
876
+ try {
877
+ moduleAddress = this.#getEip3770Address(moduleAddressProp).address;
878
+ } catch (err) {
879
+ throw new Error(`Invalid module address ${moduleAddressProp}`);
880
+ }
881
+ if (isEmptyData(userOperation.signature)) {
882
+ throw new Error("Signature must not be empty");
883
+ }
884
+ const getISOString = (date) => !date ? null : new Date(date * 1e3).toISOString();
885
+ return sendRequest({
886
+ url: `${this.#txServiceBaseUrl}/v1/safes/${safeAddress}/safe-operations/`,
887
+ method: "post" /* Post */,
888
+ body: {
889
+ nonce: Number(userOperation.nonce),
890
+ initCode: isEmptyData(userOperation.initCode) ? null : userOperation.initCode,
891
+ callData: userOperation.callData,
892
+ callGasLimit: userOperation.callGasLimit.toString(),
893
+ verificationGasLimit: userOperation.verificationGasLimit.toString(),
894
+ preVerificationGas: userOperation.preVerificationGas.toString(),
895
+ maxFeePerGas: userOperation.maxFeePerGas.toString(),
896
+ maxPriorityFeePerGas: userOperation.maxPriorityFeePerGas.toString(),
897
+ paymasterAndData: isEmptyData(userOperation.paymasterAndData) ? null : userOperation.paymasterAndData,
898
+ entryPoint,
899
+ validAfter: getISOString(options?.validAfter),
900
+ validUntil: getISOString(options?.validUntil),
901
+ signature: userOperation.signature,
902
+ moduleAddress
903
+ }
904
+ });
905
+ }
906
+ /**
907
+ * Returns the list of confirmations for a given a SafeOperation.
908
+ *
909
+ * @param safeOperationHash - The hash of the SafeOperation to get confirmations for
910
+ * @param getSafeOperationConfirmationsOptions - Additional options for fetching the list of confirmations
911
+ * @returns The list of confirmations
912
+ * @throws "Invalid SafeOperation hash"
913
+ * @throws "Invalid data"
914
+ */
915
+ async getSafeOperationConfirmations(safeOperationHash, { limit, offset } = {}) {
916
+ if (!safeOperationHash) {
917
+ throw new Error("Invalid SafeOperation hash");
918
+ }
919
+ const url = new URL(
920
+ `${this.#txServiceBaseUrl}/v1/safe-operations/${safeOperationHash}/confirmations/`
921
+ );
922
+ if (limit != null) {
923
+ url.searchParams.set("limit", limit.toString());
924
+ }
925
+ if (offset != null) {
926
+ url.searchParams.set("offset", offset.toString());
927
+ }
928
+ return sendRequest({
929
+ url: url.toString(),
930
+ method: "get" /* Get */
931
+ });
932
+ }
933
+ /**
934
+ * Adds a confirmation for a SafeOperation.
935
+ *
936
+ * @param safeOperationHash The SafeOperation hash
937
+ * @param signature - Signature of the SafeOperation
938
+ * @returns
939
+ * @throws "Invalid SafeOperation hash"
940
+ * @throws "Invalid signature"
941
+ * @throws "Malformed data"
942
+ * @throws "Error processing data"
943
+ */
944
+ async confirmSafeOperation(safeOperationHash, signature) {
945
+ if (!safeOperationHash) {
946
+ throw new Error("Invalid SafeOperation hash");
947
+ }
948
+ if (!signature) {
949
+ throw new Error("Invalid signature");
950
+ }
951
+ return sendRequest({
952
+ url: `${this.#txServiceBaseUrl}/v1/safe-operations/${safeOperationHash}/confirmations/`,
953
+ method: "post" /* Post */,
954
+ body: { signature }
955
+ });
956
+ }
957
+ };
958
+ var SafeApiKit_default = SafeApiKit;
959
+
960
+ // src/index.ts
961
+ var src_default = SafeApiKit_default;