@safe-global/sdk-starter-kit 1.1.3-alpha.0 → 1.1.4

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 (60) hide show
  1. package/dist/src/BaseClient.d.ts +0 -1
  2. package/dist/src/BaseClient.js +123 -0
  3. package/dist/src/BaseClient.js.map +1 -0
  4. package/dist/src/SafeClient.d.ts +0 -1
  5. package/dist/src/SafeClient.js +215 -0
  6. package/dist/src/SafeClient.js.map +1 -0
  7. package/dist/src/constants.d.ts +0 -1
  8. package/dist/src/constants.js +37 -0
  9. package/dist/src/constants.js.map +1 -0
  10. package/dist/src/extensions/index.d.ts +0 -1
  11. package/dist/src/extensions/index.js +20 -0
  12. package/dist/src/extensions/index.js.map +1 -0
  13. package/dist/src/extensions/messages/SafeMessageClient.d.ts +0 -1
  14. package/dist/src/extensions/messages/SafeMessageClient.js +161 -0
  15. package/dist/src/extensions/messages/SafeMessageClient.js.map +1 -0
  16. package/dist/src/extensions/messages/offChainMessages.d.ts +0 -1
  17. package/dist/src/extensions/messages/offChainMessages.js +52 -0
  18. package/dist/src/extensions/messages/offChainMessages.js.map +1 -0
  19. package/dist/src/extensions/messages/onChainMessages.d.ts +0 -1
  20. package/dist/src/extensions/messages/onChainMessages.js +48 -0
  21. package/dist/src/extensions/messages/onChainMessages.js.map +1 -0
  22. package/dist/src/extensions/safe-operations/SafeOperationClient.d.ts +0 -1
  23. package/dist/src/extensions/safe-operations/SafeOperationClient.js +127 -0
  24. package/dist/src/extensions/safe-operations/SafeOperationClient.js.map +1 -0
  25. package/dist/src/extensions/safe-operations/safeOperations.d.ts +0 -1
  26. package/dist/src/extensions/safe-operations/safeOperations.js +85 -0
  27. package/dist/src/extensions/safe-operations/safeOperations.js.map +1 -0
  28. package/dist/src/index.d.ts +0 -1
  29. package/dist/src/index.js +112 -0
  30. package/dist/src/index.js.map +1 -0
  31. package/dist/src/types.d.ts +0 -1
  32. package/dist/src/types.js +3 -0
  33. package/dist/src/types.js.map +1 -0
  34. package/dist/src/utils/index.d.ts +6 -7
  35. package/dist/src/utils/index.js +57 -0
  36. package/dist/src/utils/index.js.map +1 -0
  37. package/dist/src/utils/proposeTransaction.d.ts +0 -1
  38. package/dist/src/utils/proposeTransaction.js +29 -0
  39. package/dist/src/utils/proposeTransaction.js.map +1 -0
  40. package/dist/src/utils/sendTransaction.d.ts +0 -1
  41. package/dist/src/utils/sendTransaction.js +28 -0
  42. package/dist/src/utils/sendTransaction.js.map +1 -0
  43. package/dist/tsconfig.build.tsbuildinfo +1 -0
  44. package/package.json +8 -17
  45. package/dist/cjs/index.cjs +0 -906
  46. package/dist/esm/index.mjs +0 -875
  47. package/dist/src/BaseClient.d.ts.map +0 -1
  48. package/dist/src/SafeClient.d.ts.map +0 -1
  49. package/dist/src/constants.d.ts.map +0 -1
  50. package/dist/src/extensions/index.d.ts.map +0 -1
  51. package/dist/src/extensions/messages/SafeMessageClient.d.ts.map +0 -1
  52. package/dist/src/extensions/messages/offChainMessages.d.ts.map +0 -1
  53. package/dist/src/extensions/messages/onChainMessages.d.ts.map +0 -1
  54. package/dist/src/extensions/safe-operations/SafeOperationClient.d.ts.map +0 -1
  55. package/dist/src/extensions/safe-operations/safeOperations.d.ts.map +0 -1
  56. package/dist/src/index.d.ts.map +0 -1
  57. package/dist/src/types.d.ts.map +0 -1
  58. package/dist/src/utils/index.d.ts.map +0 -1
  59. package/dist/src/utils/proposeTransaction.d.ts.map +0 -1
  60. package/dist/src/utils/sendTransaction.d.ts.map +0 -1
@@ -80,4 +80,3 @@ export declare class BaseClient {
80
80
  */
81
81
  createChangeThresholdTransaction(changeThresholdParams: ChangeThresholdTxParams): Promise<TransactionBase>;
82
82
  }
83
- //# sourceMappingURL=BaseClient.d.ts.map
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
+ 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");
5
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
+ };
7
+ var _BaseClient_instances, _BaseClient_buildTransaction;
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.BaseClient = void 0;
10
+ class BaseClient {
11
+ constructor(protocolKit, apiKit) {
12
+ _BaseClient_instances.add(this);
13
+ this.protocolKit = protocolKit;
14
+ this.apiKit = apiKit;
15
+ }
16
+ /**
17
+ * Returns the Safe address.
18
+ *
19
+ * @returns {string} The Safe address
20
+ */
21
+ async getAddress() {
22
+ return this.protocolKit.getAddress();
23
+ }
24
+ /**
25
+ * Checks if the current Safe is deployed.
26
+ *
27
+ * @returns {boolean} if the Safe contract is deployed
28
+ */
29
+ async isDeployed() {
30
+ return this.protocolKit.isSafeDeployed();
31
+ }
32
+ /**
33
+ * Checks if a specific address is an owner of the current Safe.
34
+ *
35
+ * @param {string} ownerAddress - The account address
36
+ * @returns {boolean} TRUE if the account is an owner
37
+ */
38
+ async isOwner(ownerAddress) {
39
+ return this.protocolKit.isOwner(ownerAddress);
40
+ }
41
+ /**
42
+ * Returns the list of Safe owner accounts.
43
+ *
44
+ * @returns The list of owners
45
+ */
46
+ async getOwners() {
47
+ return this.protocolKit.getOwners();
48
+ }
49
+ /**
50
+ * Returns the Safe threshold.
51
+ *
52
+ * @returns {number} The Safe threshold
53
+ */
54
+ async getThreshold() {
55
+ return this.protocolKit.getThreshold();
56
+ }
57
+ /**
58
+ * Returns the Safe nonce.
59
+ *
60
+ * @returns {number} The Safe nonce
61
+ */
62
+ async getNonce() {
63
+ return this.protocolKit.getNonce();
64
+ }
65
+ /**
66
+ * Returns a list of owners who have approved a specific Safe transaction.
67
+ *
68
+ * @param {string} txHash - The Safe transaction hash
69
+ * @returns {string[]} The list of owners
70
+ */
71
+ async getOwnersWhoApprovedTransaction(txHash) {
72
+ return this.protocolKit.getOwnersWhoApprovedTx(txHash);
73
+ }
74
+ /**
75
+ * Encodes the data for adding a new owner to the Safe.
76
+ *
77
+ * @param {AddOwnerTxParams | AddPasskeyOwnerTxParams} addOwnerParams - The parameters for adding a new owner
78
+ * @returns {TransactionBase} The encoded data
79
+ */
80
+ async createAddOwnerTransaction(addOwnerParams) {
81
+ const addOwnerTransaction = await this.protocolKit.createAddOwnerTx(addOwnerParams);
82
+ return __classPrivateFieldGet(this, _BaseClient_instances, "m", _BaseClient_buildTransaction).call(this, addOwnerTransaction);
83
+ }
84
+ /**
85
+ * Encodes the data for removing an owner from the Safe.
86
+ *
87
+ * @param {RemoveOwnerTxParams | RemovePasskeyOwnerTxParams} removeOwnerParams - The parameters for removing an owner
88
+ * @returns {TransactionBase} The encoded data
89
+ */
90
+ async createRemoveOwnerTransaction(removeOwnerParams) {
91
+ const removeOwnerTransaction = await this.protocolKit.createRemoveOwnerTx(removeOwnerParams);
92
+ return __classPrivateFieldGet(this, _BaseClient_instances, "m", _BaseClient_buildTransaction).call(this, removeOwnerTransaction);
93
+ }
94
+ /**
95
+ * Encodes the data for swapping an owner in the Safe.
96
+ *
97
+ * @param {SwapOwnerTxParams} swapParams - The parameters for swapping an owner
98
+ * @returns {TransactionBase} The encoded data
99
+ */
100
+ async createSwapOwnerTransaction(swapParams) {
101
+ const swapOwnerTransaction = await this.protocolKit.createSwapOwnerTx(swapParams);
102
+ return __classPrivateFieldGet(this, _BaseClient_instances, "m", _BaseClient_buildTransaction).call(this, swapOwnerTransaction);
103
+ }
104
+ /**
105
+ * Encodes the data for changing the Safe threshold.
106
+ *
107
+ * @param {ChangeThresholdTxParams} changeThresholdParams - The parameters for changing the Safe threshold
108
+ * @returns {TransactionBase} The encoded data
109
+ */
110
+ async createChangeThresholdTransaction(changeThresholdParams) {
111
+ const changeThresholdTransaction = await this.protocolKit.createChangeThresholdTx(changeThresholdParams.threshold);
112
+ return __classPrivateFieldGet(this, _BaseClient_instances, "m", _BaseClient_buildTransaction).call(this, changeThresholdTransaction);
113
+ }
114
+ }
115
+ exports.BaseClient = BaseClient;
116
+ _BaseClient_instances = new WeakSet(), _BaseClient_buildTransaction = async function _BaseClient_buildTransaction(safeTransaction) {
117
+ return {
118
+ to: safeTransaction.data.to,
119
+ value: safeTransaction.data.value,
120
+ data: safeTransaction.data.data
121
+ };
122
+ };
123
+ //# sourceMappingURL=BaseClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaseClient.js","sourceRoot":"","sources":["../../src/BaseClient.ts"],"names":[],"mappings":";;;;;;;;;AAYA,MAAa,UAAU;IAIrB,YAAY,WAAiB,EAAE,MAAkB;;QAC/C,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,UAAU;QACd,OAAO,IAAI,CAAC,WAAW,CAAC,UAAU,EAAE,CAAA;IACtC,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,UAAU;QACd,OAAO,IAAI,CAAC,WAAW,CAAC,cAAc,EAAE,CAAA;IAC1C,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,OAAO,CAAC,YAAoB;QAChC,OAAO,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,YAAY,CAAC,CAAA;IAC/C,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,SAAS;QACb,OAAO,IAAI,CAAC,WAAW,CAAC,SAAS,EAAE,CAAA;IACrC,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,YAAY;QAChB,OAAO,IAAI,CAAC,WAAW,CAAC,YAAY,EAAE,CAAA;IACxC,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,QAAQ;QACZ,OAAO,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAA;IACpC,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,+BAA+B,CAAC,MAAc;QAClD,OAAO,IAAI,C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CAAC"}
@@ -60,4 +60,3 @@ export declare class SafeClient extends BaseClient {
60
60
  extend<T>(extendFunc: (client: this) => Promise<T>): Promise<this & T>;
61
61
  extend<T>(extendFunc: (client: this) => T): this & T;
62
62
  }
63
- //# sourceMappingURL=SafeClient.d.ts.map
@@ -0,0 +1,215 @@
1
+ "use strict";
2
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
+ 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");
5
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
+ };
7
+ var _SafeClient_instances, _SafeClient_deployAndExecuteTransaction, _SafeClient_deployAndProposeTransaction, _SafeClient_executeTransaction, _SafeClient_proposeTransaction, _SafeClient_reconnectSafe;
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.SafeClient = void 0;
10
+ const utils_1 = require("./utils");
11
+ const constants_1 = require("./constants");
12
+ const BaseClient_1 = require("./BaseClient");
13
+ /**
14
+ * @class
15
+ * This class provides the core functionality to create, sign and execute transactions.
16
+ * It also provides the ability to be extended with features through the extend function.
17
+ *
18
+ * @example
19
+ * const safeClient = await createSafeClient({ ... })
20
+ *
21
+ * const { transactions } = await safeClient.send(...)
22
+ * await safeClient.confirm(transactions?.safeTxHash)
23
+ */
24
+ class SafeClient extends BaseClient_1.BaseClient {
25
+ constructor(protocolKit, apiKit) {
26
+ super(protocolKit, apiKit);
27
+ _SafeClient_instances.add(this);
28
+ }
29
+ /**
30
+ * Sends transactions through the Safe protocol.
31
+ * You can send an array to transactions { to, value, data} that we will convert to a transaction batch
32
+ *
33
+ * @param {SendTransactionProps} props The SendTransactionProps object.
34
+ * @param {TransactionBase[]} props.transactions An array of transactions to be sent.
35
+ * @param {string} props.transactions[].to The recipient address of the transaction.
36
+ * @param {string} props.transactions[].value The value of the transaction.
37
+ * @param {string} props.transactions[].data The data of the transaction.
38
+ * @param {string} props.from The sender address of the transaction.
39
+ * @param {number | string} props.gasLimit The gas limit of the transaction.
40
+ * @param {number | string} props.gasPrice The gas price of the transaction.
41
+ * @param {number | string} props.maxFeePerGas The max fee per gas of the transaction.
42
+ * @param {number | string} props.maxPriorityFeePerGas The max priority fee per gas of the transaction.
43
+ * @param {number} props.nonce The nonce of the transaction.
44
+ * @returns {Promise<SafeClientResult>} A promise that resolves to the result of the transaction.
45
+ */
46
+ async send({ transactions, ...transactionOptions }) {
47
+ const isSafeDeployed = await this.protocolKit.isSafeDeployed();
48
+ const isMultisigSafe = (await this.protocolKit.getThreshold()) > 1;
49
+ const safeTransaction = await this.protocolKit.createTransaction({ transactions });
50
+ if (isSafeDeployed) {
51
+ if (isMultisigSafe) {
52
+ // If the threshold is greater than 1, we need to propose the transaction first
53
+ return __classPrivateFieldGet(this, _SafeClient_instances, "m", _SafeClient_proposeTransaction).call(this, { safeTransaction });
54
+ }
55
+ else {
56
+ // If the threshold is 1, we can execute the transaction
57
+ return __classPrivateFieldGet(this, _SafeClient_instances, "m", _SafeClient_executeTransaction).call(this, { safeTransaction, ...transactionOptions });
58
+ }
59
+ }
60
+ else {
61
+ if (isMultisigSafe) {
62
+ // If the threshold is greater than 1, we need to deploy the Safe account first and
63
+ // afterwards propose the transaction
64
+ // The transaction should be confirmed with other owners until the threshold is reached
65
+ return __classPrivateFieldGet(this, _SafeClient_instances, "m", _SafeClient_deployAndProposeTransaction).call(this, { safeTransaction, ...transactionOptions });
66
+ }
67
+ else {
68
+ // If the threshold is 1, we can deploy the Safe account and execute the transaction in one step
69
+ return __classPrivateFieldGet(this, _SafeClient_instances, "m", _SafeClient_deployAndExecuteTransaction).call(this, { safeTransaction, ...transactionOptions });
70
+ }
71
+ }
72
+ }
73
+ /**
74
+ * Confirms a transaction by its safe transaction hash.
75
+ *
76
+ * @param {ConfirmTransactionProps} props The ConfirmTransactionProps object.
77
+ * @param {string} props.safeTxHash The hash of the safe transaction to confirm.
78
+ * @returns {Promise<SafeClientResult>} A promise that resolves to the result of the confirmed transaction.
79
+ * @throws {Error} If the transaction confirmation fails.
80
+ */
81
+ async confirm({ safeTxHash }) {
82
+ let transactionResponse = await this.apiKit.getTransaction(safeTxHash);
83
+ const safeAddress = await this.protocolKit.getAddress();
84
+ const signedTransaction = await this.protocolKit.signTransaction(transactionResponse);
85
+ await this.apiKit.confirmTransaction(safeTxHash, signedTransaction.encodedSignatures());
86
+ transactionResponse = await this.apiKit.getTransaction(safeTxHash);
87
+ if (transactionResponse.confirmations &&
88
+ transactionResponse.confirmationsRequired === transactionResponse.confirmations.length) {
89
+ const executedTransactionResponse = await this.protocolKit.executeTransaction(transactionResponse);
90
+ await (0, utils_1.waitSafeTxReceipt)(executedTransactionResponse);
91
+ return (0, utils_1.createSafeClientResult)({
92
+ status: constants_1.SafeClientTxStatus.EXECUTED,
93
+ safeAddress,
94
+ txHash: executedTransactionResponse.hash,
95
+ safeTxHash
96
+ });
97
+ }
98
+ return (0, utils_1.createSafeClientResult)({
99
+ status: constants_1.SafeClientTxStatus.PENDING_SIGNATURES,
100
+ safeAddress,
101
+ safeTxHash
102
+ });
103
+ }
104
+ /**
105
+ * Retrieves the pending transactions for the current safe address.
106
+ *
107
+ * @async
108
+ * @returns {Promise<SafeMultisigTransactionListResponse>} A promise that resolves to an array of pending transactions.
109
+ * @throws {Error} If there is an issue retrieving the safe address or pending transactions.
110
+ */
111
+ async getPendingTransactions() {
112
+ const safeAddress = await this.protocolKit.getAddress();
113
+ return this.apiKit.getPendingTransactions(safeAddress);
114
+ }
115
+ extend(extendFunc) {
116
+ const result = extendFunc(this);
117
+ if (result instanceof Promise) {
118
+ return result.then((extensions) => Object.assign(this, extensions));
119
+ }
120
+ else {
121
+ return Object.assign(this, result);
122
+ }
123
+ }
124
+ }
125
+ exports.SafeClient = SafeClient;
126
+ _SafeClient_instances = new WeakSet(), _SafeClient_deployAndExecuteTransaction =
127
+ /**
128
+ * Deploys and executes a transaction in one step.
129
+ *
130
+ * @param {SafeTransaction} safeTransaction The safe transaction to be executed
131
+ * @param {TransactionOptions} options Optional transaction options
132
+ * @returns A promise that resolves to the result of the transaction
133
+ */
134
+ async function _SafeClient_deployAndExecuteTransaction({ safeTransaction, ...transactionOptions }) {
135
+ safeTransaction = await this.protocolKit.signTransaction(safeTransaction);
136
+ const transactionBatchWithDeployment = await this.protocolKit.wrapSafeTransactionIntoDeploymentBatch(safeTransaction, transactionOptions);
137
+ const hash = await (0, utils_1.sendTransaction)({
138
+ transaction: transactionBatchWithDeployment,
139
+ protocolKit: this.protocolKit
140
+ });
141
+ await __classPrivateFieldGet(this, _SafeClient_instances, "m", _SafeClient_reconnectSafe).call(this);
142
+ return (0, utils_1.createSafeClientResult)({
143
+ safeAddress: await this.protocolKit.getAddress(),
144
+ status: constants_1.SafeClientTxStatus.DEPLOYED_AND_EXECUTED,
145
+ deploymentTxHash: hash,
146
+ txHash: hash
147
+ });
148
+ }, _SafeClient_deployAndProposeTransaction =
149
+ /**
150
+ * Deploys and proposes a transaction in one step.
151
+ *
152
+ * @param {SafeTransaction} safeTransaction The safe transaction to be proposed
153
+ * @param {TransactionOptions} transactionOptions Optional transaction options
154
+ * @returns A promise that resolves to the result of the transaction
155
+ */
156
+ async function _SafeClient_deployAndProposeTransaction({ safeTransaction, ...transactionOptions }) {
157
+ const safeDeploymentTransaction = await this.protocolKit.createSafeDeploymentTransaction();
158
+ const hash = await (0, utils_1.sendTransaction)({
159
+ transaction: { ...safeDeploymentTransaction, ...transactionOptions },
160
+ protocolKit: this.protocolKit
161
+ });
162
+ await __classPrivateFieldGet(this, _SafeClient_instances, "m", _SafeClient_reconnectSafe).call(this);
163
+ safeTransaction = await this.protocolKit.signTransaction(safeTransaction);
164
+ const safeTxHash = await (0, utils_1.proposeTransaction)({
165
+ safeTransaction,
166
+ protocolKit: this.protocolKit,
167
+ apiKit: this.apiKit
168
+ });
169
+ return (0, utils_1.createSafeClientResult)({
170
+ safeAddress: await this.protocolKit.getAddress(),
171
+ status: constants_1.SafeClientTxStatus.DEPLOYED_AND_PENDING_SIGNATURES,
172
+ deploymentTxHash: hash,
173
+ safeTxHash
174
+ });
175
+ }, _SafeClient_executeTransaction =
176
+ /**
177
+ * Executes a transaction.
178
+ *
179
+ * @param {SafeTransaction} safeTransaction The safe transaction to be executed
180
+ * @param {TransactionOptions} transactionOptions Optional transaction options
181
+ * @returns A promise that resolves to the result of the transaction
182
+ */
183
+ async function _SafeClient_executeTransaction({ safeTransaction, ...transactionOptions }) {
184
+ safeTransaction = await this.protocolKit.signTransaction(safeTransaction);
185
+ const { hash } = await this.protocolKit.executeTransaction(safeTransaction, transactionOptions);
186
+ return (0, utils_1.createSafeClientResult)({
187
+ safeAddress: await this.protocolKit.getAddress(),
188
+ status: constants_1.SafeClientTxStatus.EXECUTED,
189
+ txHash: hash
190
+ });
191
+ }, _SafeClient_proposeTransaction =
192
+ /**
193
+ * Proposes a transaction to the Safe.
194
+ * @param { SafeTransaction } safeTransaction The safe transaction to propose
195
+ * @returns The SafeClientResult
196
+ */
197
+ async function _SafeClient_proposeTransaction({ safeTransaction }) {
198
+ const safeTxHash = await (0, utils_1.proposeTransaction)({
199
+ safeTransaction,
200
+ protocolKit: this.protocolKit,
201
+ apiKit: this.apiKit
202
+ });
203
+ return (0, utils_1.createSafeClientResult)({
204
+ safeAddress: await this.protocolKit.getAddress(),
205
+ status: constants_1.SafeClientTxStatus.PENDING_SIGNATURES,
206
+ safeTxHash
207
+ });
208
+ }, _SafeClient_reconnectSafe = async function _SafeClient_reconnectSafe() {
209
+ this.protocolKit = await this.protocolKit.connect({
210
+ provider: this.protocolKit.getSafeProvider().provider,
211
+ signer: this.protocolKit.getSafeProvider().signer,
212
+ safeAddress: await this.protocolKit.getAddress()
213
+ });
214
+ };
215
+ //# sourceMappingURL=SafeClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SafeClient.js","sourceRoot":"","sources":["../../src/S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,MAAM,UAAU,GAAG,MAAM,IAAA,0BAAkB,EAAC;QAC1C,eAAe;QACf,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,MAAM,EAAE,IAAI,CAAC,MAAM;KACpB,CAAC,CAAA;IAEF,OAAO,IAAA,8BAAsB,EAAC;QAC5B,WAAW,EAAE,MAAM,IAAI,CAAC,WAAW,CAAC,UAAU,EAAE;QAChD,MAAM,EAAE,8BAAkB,CAAC,kBAAkB;QAC7C,UAAU;KACX,CAAC,CAAA;AACJ,CAAC,8BAED,KAAK;IACH,IAAI,CAAC,WAAW,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC;QAChD,QAAQ,EAAE,IAAI,CAAC,WAAW,CAAC,eAAe,EAAE,CAAC,QAAQ;QACrD,MAAM,EAAE,IAAI,CAAC,WAAW,CAAC,eAAe,EAAE,CAAC,MAAM;QACjD,WAAW,EAAE,MAAM,IAAI,CAAC,WAAW,CAAC,UAAU,EAAE;KACjD,CAAC,CAAA;AACJ,CAAC"}
@@ -24,4 +24,3 @@ export declare const MESSAGES: {
24
24
  SAFE_OPERATION_EXECUTED: string;
25
25
  SAFE_OPERATION_PENDING_SIGNATURES: string;
26
26
  };
27
- //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MESSAGES = exports.SafeClientTxStatus = exports.DEFAULT_DEPLOYMENT_TYPE = void 0;
4
+ exports.DEFAULT_DEPLOYMENT_TYPE = 'canonical';
5
+ var SafeClientTxStatus;
6
+ (function (SafeClientTxStatus) {
7
+ SafeClientTxStatus["DEPLOYED_AND_EXECUTED"] = "DEPLOYED_AND_EXECUTED";
8
+ SafeClientTxStatus["DEPLOYED_AND_PENDING_SIGNATURES"] = "DEPLOYED_AND_PENDING_SIGNATURES";
9
+ SafeClientTxStatus["EXECUTED"] = "EXECUTED";
10
+ SafeClientTxStatus["PENDING_SIGNATURES"] = "PENDING_SIGNATURES";
11
+ SafeClientTxStatus["MESSAGE_PENDING_SIGNATURES"] = "MESSAGE_PENDING_SIGNATURES";
12
+ SafeClientTxStatus["MESSAGE_CONFIRMED"] = "MESSAGE_CONFIRMED";
13
+ SafeClientTxStatus["DEPLOYED_AND_MESSAGE_PENDING_SIGNATURES"] = "DEPLOYED_AND_MESSAGE_PENDING_SIGNATURES";
14
+ SafeClientTxStatus["DEPLOYED_AND_MESSAGE_CONFIRMED"] = "DEPLOYED_AND_MESSAGE_CONFIRMED";
15
+ SafeClientTxStatus["SAFE_OPERATION_EXECUTED"] = "SAFE_OPERATION_EXECUTED";
16
+ SafeClientTxStatus["SAFE_OPERATION_PENDING_SIGNATURES"] = "SAFE_OPERATION_PENDING_SIGNATURES";
17
+ })(SafeClientTxStatus || (exports.SafeClientTxStatus = SafeClientTxStatus = {}));
18
+ const TRANSACTION_EXECUTED = 'The transaction has been executed, check the ethereumTxHash in the transactions property to view it on the corresponding blockchain explorer';
19
+ const TRANSACTION_SAVED = 'The transaction was not executed on-chain yet. There are pending signatures and you need to confirm it with other Safe owners first. Use the confirm(safeTxHash) method with other signer connected to the client';
20
+ const OFFCHAIN_MESSAGE_SAVED = 'The message was stored using the Safe Transaction Service, you need to confirm it with other Safe owners in order to make it valid. Use the confirmMessage(messageHash) method with other signer connected to the client';
21
+ const OFFCHAIN_MESSAGE_CONFIRMED = 'The message was stored using Safe services and now is confirmed and valid';
22
+ const SAFE_OPERATION_SAVED = 'The UserOperation was stored using the Safe Transaction Service as an SafeOperation, you need to confirm it with other Safe owners in order to make it valid. Use the confirmSafeOperation(safeOperationHash) method with other signer connected to the client';
23
+ const SAFE_OPERATION_SENT_TO_BUNDLER = 'The SafeOperation was sent to the bundler for being processed. Check the userOperationHash in the safeOperations property to see the SafeOperation in the corresponding explorer';
24
+ const SAFE_DEPLOYED = 'A new Safe account was deployed, check the ethereumTxHash in the safeAccountDeployment property to view it on the corresponding blockchain explorer';
25
+ exports.MESSAGES = {
26
+ [SafeClientTxStatus.DEPLOYED_AND_EXECUTED]: `${SAFE_DEPLOYED}. ${TRANSACTION_EXECUTED}`,
27
+ [SafeClientTxStatus.DEPLOYED_AND_PENDING_SIGNATURES]: `${SAFE_DEPLOYED}. ${TRANSACTION_SAVED}`,
28
+ [SafeClientTxStatus.EXECUTED]: TRANSACTION_EXECUTED,
29
+ [SafeClientTxStatus.PENDING_SIGNATURES]: TRANSACTION_SAVED,
30
+ [SafeClientTxStatus.MESSAGE_PENDING_SIGNATURES]: OFFCHAIN_MESSAGE_SAVED,
31
+ [SafeClientTxStatus.MESSAGE_CONFIRMED]: OFFCHAIN_MESSAGE_CONFIRMED,
32
+ [SafeClientTxStatus.DEPLOYED_AND_MESSAGE_PENDING_SIGNATURES]: `${SAFE_DEPLOYED}. ${OFFCHAIN_MESSAGE_SAVED}`,
33
+ [SafeClientTxStatus.DEPLOYED_AND_MESSAGE_CONFIRMED]: `${SAFE_DEPLOYED}. ${OFFCHAIN_MESSAGE_CONFIRMED}`,
34
+ [SafeClientTxStatus.SAFE_OPERATION_EXECUTED]: SAFE_OPERATION_SENT_TO_BUNDLER,
35
+ [SafeClientTxStatus.SAFE_OPERATION_PENDING_SIGNATURES]: SAFE_OPERATION_SAVED
36
+ };
37
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAEa,QAAA,uBAAuB,GAAmB,WAAW,CAAA;AAElE,IAAY,kBAWX;AAXD,WAAY,kBAAkB;IAC5B,qEAA+C,CAAA;IAC/C,yFAAmE,CAAA;IACnE,2CAAqB,CAAA;IACrB,+DAAyC,CAAA;IACzC,+EAAyD,CAAA;IACzD,6DAAuC,CAAA;IACvC,yGAAmF,CAAA;IACnF,uFAAiE,CAAA;IACjE,yEAAmD,CAAA;IACnD,6FAAuE,CAAA;AACzE,CAAC,EAXW,kBAAkB,kCAAlB,kBAAkB,QAW7B;AAED,MAAM,oBAAoB,GACxB,8IAA8I,CAAA;AAChJ,MAAM,iBAAiB,GACrB,mNAAmN,CAAA;AACrN,MAAM,sBAAsB,GAC1B,0NAA0N,CAAA;AAC5N,MAAM,0BAA0B,GAC9B,2EAA2E,CAAA;AAC7E,MAAM,oBAAoB,GACxB,gQAAgQ,CAAA;AAClQ,MAAM,8BAA8B,GAClC,kLAAkL,CAAA;AACpL,MAAM,aAAa,GACjB,qJAAqJ,CAAA;AAE1I,QAAA,QAAQ,GAAG;IACtB,CAAC,kBAAkB,CAAC,qBAAqB,CAAC,EAAE,GAAG,aAAa,KAAK,oBAAoB,EAAE;IACvF,CAAC,kBAAkB,CAAC,+BAA+B,CAAC,EAAE,GAAG,aAAa,KAAK,iBAAiB,EAAE;IAC9F,CAAC,kBAAkB,CAAC,QAAQ,CAAC,EAAE,oBAAoB;IACnD,CAAC,kBAAkB,CAAC,kBAAkB,CAAC,EAAE,iBAAiB;IAC1D,CAAC,kBAAkB,CAAC,0BAA0B,CAAC,EAAE,sBAAsB;IACvE,CAAC,kBAAkB,CAAC,iBAAiB,CAAC,EAAE,0BAA0B;IAClE,CAAC,kBAAkB,CAAC,uCAAuC,CAAC,EAAE,GAAG,aAAa,KAAK,sBAAsB,EAAE;IAC3G,CAAC,kBAAkB,CAAC,8BAA8B,CAAC,EAAE,GAAG,aAAa,KAAK,0BAA0B,EAAE;IACtG,CAAC,kBAAkB,CAAC,uBAAuB,CAAC,EAAE,8BAA8B;IAC5E,CAAC,kBAAkB,CAAC,iCAAiC,CAAC,EAAE,oBAAoB;CAC7E,CAAA"}
@@ -1,4 +1,3 @@
1
1
  export * from './messages/onChainMessages';
2
2
  export * from './messages/offChainMessages';
3
3
  export * from './safe-operations/safeOperations';
4
- //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./messages/onChainMessages"), exports);
18
+ __exportStar(require("./messages/offChainMessages"), exports);
19
+ __exportStar(require("./safe-operations/safeOperations"), exports);
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/extensions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6DAA0C;AAC1C,8DAA2C;AAC3C,mEAAgD"}
@@ -39,4 +39,3 @@ export declare class SafeMessageClient {
39
39
  */
40
40
  getPendingMessages(options?: ListOptions): Promise<SafeMessageListResponse>;
41
41
  }
42
- //# sourceMappingURL=SafeMessageClient.d.ts.map
@@ -0,0 +1,161 @@
1
+ "use strict";
2
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
+ 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");
5
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
+ };
7
+ var _SafeMessageClient_instances, _SafeMessageClient_deployAndAddMessage, _SafeMessageClient_addMessage, _SafeMessageClient_updateProtocolKitWithDeployedSafe;
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.SafeMessageClient = void 0;
10
+ const protocol_kit_1 = require("@safe-global/protocol-kit");
11
+ const utils_1 = require("../../utils");
12
+ const constants_1 = require("../../constants");
13
+ /**
14
+ * @class
15
+ * This class provides the functionality to create and confirm off-chain messages
16
+ */
17
+ class SafeMessageClient {
18
+ /**
19
+ * @constructor
20
+ * @param {Safe} protocolKit A Safe instance
21
+ * @param {SafeApiKit} apiKit A SafeApiKit instance
22
+ */
23
+ constructor(protocolKit, apiKit) {
24
+ _SafeMessageClient_instances.add(this);
25
+ this.protocolKit = protocolKit;
26
+ this.apiKit = apiKit;
27
+ }
28
+ /**
29
+ * Send off-chain messages using the Transaction service
30
+ *
31
+ * @param {SendOffChainMessageProps} props The message properties
32
+ * @param {string | EIP712TypedData} props.message The message to be sent. Can be a raw string or an EIP712TypedData object
33
+ * @returns {Promise<SafeClientResult>} A SafeClientResult. You can get the messageHash to confirmMessage() afterwards from the messages property
34
+ */
35
+ async sendMessage({ message }) {
36
+ const isSafeDeployed = await this.protocolKit.isSafeDeployed();
37
+ const safeMessage = this.protocolKit.createMessage(message);
38
+ if (isSafeDeployed) {
39
+ return __classPrivateFieldGet(this, _SafeMessageClient_instances, "m", _SafeMessageClient_addMessage).call(this, { safeMessage });
40
+ }
41
+ else {
42
+ return __classPrivateFieldGet(this, _SafeMessageClient_instances, "m", _SafeMessageClient_deployAndAddMessage).call(this, { safeMessage });
43
+ }
44
+ }
45
+ /**
46
+ * Confirms an off-chain message using the Transaction service
47
+ *
48
+ * @param {ConfirmOffChainMessageProps} props The confirmation properties
49
+ * @param {string} props.messageHash The messageHash. Returned from the sendMessage() method inside the SafeClientResult messages property
50
+ * @returns {Promise<SafeClientResult>} A SafeClientResult with the result of the confirmation
51
+ */
52
+ async confirmMessage({ messageHash }) {
53
+ let messageResponse = await this.apiKit.getMessage(messageHash);
54
+ const safeAddress = await this.protocolKit.getAddress();
55
+ const threshold = await this.protocolKit.getThreshold();
56
+ let safeMessage = this.protocolKit.createMessage(messageResponse.message);
57
+ safeMessage = await this.protocolKit.signMessage(safeMessage);
58
+ await this.apiKit.addMessageSignature(messageHash, safeMessage.encodedSignatures());
59
+ messageResponse = await this.apiKit.getMessage(messageHash);
60
+ return (0, utils_1.createSafeClientResult)({
61
+ status: messageResponse.confirmations.length === threshold
62
+ ? constants_1.SafeClientTxStatus.MESSAGE_CONFIRMED
63
+ : constants_1.SafeClientTxStatus.MESSAGE_PENDING_SIGNATURES,
64
+ safeAddress,
65
+ messageHash
66
+ });
67
+ }
68
+ /**
69
+ * Get the list of pending off-chain messages. This messages can be confirmed using the confirmMessage() method
70
+ *
71
+ * @param {ListOptions} options The pagination options
72
+ * @returns {Promise<SafeMessageListResponse>} A list of pending messages
73
+ */
74
+ async getPendingMessages(options) {
75
+ const safeAddress = await this.protocolKit.getAddress();
76
+ return this.apiKit.getMessages(safeAddress, options);
77
+ }
78
+ }
79
+ exports.SafeMessageClient = SafeMessageClient;
80
+ _SafeMessageClient_instances = new WeakSet(), _SafeMessageClient_deployAndAddMessage =
81
+ /**
82
+ * Deploys a new Safe account based on the provided config and adds a message using the Transaction service
83
+ * - If the Safe threshold > 1, we need to deploy the Safe account first and afterwards add the message
84
+ * The message should be confirmed with other owners using the confirmMessage() method until the threshold is reached in order to be valid
85
+ * - If the threshold = 1, we can deploy the Safe account and add the message in one step. The message will be valid immediately
86
+ *
87
+ * @param {SafeTransaction} safeMessage The safe message
88
+ * @returns {Promise<SafeClientResult>} The SafeClientResult
89
+ */
90
+ async function _SafeMessageClient_deployAndAddMessage({ safeMessage }) {
91
+ let deploymentTxHash;
92
+ const threshold = await this.protocolKit.getThreshold();
93
+ const safeDeploymentTransaction = await this.protocolKit.createSafeDeploymentTransaction();
94
+ try {
95
+ deploymentTxHash = await (0, utils_1.sendTransaction)({
96
+ transaction: safeDeploymentTransaction,
97
+ protocolKit: this.protocolKit
98
+ });
99
+ await __classPrivateFieldGet(this, _SafeMessageClient_instances, "m", _SafeMessageClient_updateProtocolKitWithDeployedSafe).call(this);
100
+ }
101
+ catch (error) {
102
+ throw new Error('Could not deploy the Safe account');
103
+ }
104
+ try {
105
+ const { messages } = await __classPrivateFieldGet(this, _SafeMessageClient_instances, "m", _SafeMessageClient_addMessage).call(this, { safeMessage });
106
+ const messageResponse = await this.apiKit.getMessage(messages?.messageHash || '0x');
107
+ return (0, utils_1.createSafeClientResult)({
108
+ safeAddress: await this.protocolKit.getAddress(),
109
+ status: messageResponse.confirmations.length === threshold
110
+ ? constants_1.SafeClientTxStatus.DEPLOYED_AND_MESSAGE_CONFIRMED
111
+ : constants_1.SafeClientTxStatus.DEPLOYED_AND_MESSAGE_PENDING_SIGNATURES,
112
+ deploymentTxHash,
113
+ messageHash: messages?.messageHash
114
+ });
115
+ }
116
+ catch (error) {
117
+ throw new Error('Could not add a new off-chain message to the Safe account');
118
+ }
119
+ }, _SafeMessageClient_addMessage =
120
+ /**
121
+ * Add a new off-chain message using the Transaction service
122
+ * - If the threshold > 1, remember to confirmMessage() after sendMessage()
123
+ * - If the threshold = 1, then the message is confirmed and valid immediately
124
+ *
125
+ * @param {SafeMessage} safeMessage The message
126
+ * @returns {Promise<SafeClientResult>} The SafeClientResult
127
+ */
128
+ async function _SafeMessageClient_addMessage({ safeMessage }) {
129
+ const safeAddress = await this.protocolKit.getAddress();
130
+ const threshold = await this.protocolKit.getThreshold();
131
+ const signedMessage = await this.protocolKit.signMessage(safeMessage);
132
+ const messageHash = await this.protocolKit.getSafeMessageHash((0, protocol_kit_1.hashSafeMessage)(safeMessage.data));
133
+ try {
134
+ await this.apiKit.addMessage(safeAddress, {
135
+ message: safeMessage.data,
136
+ signature: signedMessage.encodedSignatures()
137
+ });
138
+ }
139
+ catch (error) {
140
+ throw new Error('Could not add a new off-chain message to the Safe account');
141
+ }
142
+ const message = await this.apiKit.getMessage(messageHash);
143
+ return (0, utils_1.createSafeClientResult)({
144
+ safeAddress: await this.protocolKit.getAddress(),
145
+ status: message.confirmations.length === threshold
146
+ ? constants_1.SafeClientTxStatus.MESSAGE_CONFIRMED
147
+ : constants_1.SafeClientTxStatus.MESSAGE_PENDING_SIGNATURES,
148
+ messageHash
149
+ });
150
+ }, _SafeMessageClient_updateProtocolKitWithDeployedSafe =
151
+ /**
152
+ * This method updates the Safe instance with the deployed Safe account
153
+ */
154
+ async function _SafeMessageClient_updateProtocolKitWithDeployedSafe() {
155
+ this.protocolKit = await this.protocolKit.connect({
156
+ provider: this.protocolKit.getSafeProvider().provider,
157
+ signer: this.protocolKit.getSafeProvider().signer,
158
+ safeAddress: await this.protocolKit.getAddress()
159
+ });
160
+ };
161
+ //# sourceMappingURL=SafeMessageClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SafeMessageClient.js","sourceRoot":"","sources":["../../../../src/extensions/messages/SafeMessageClient.ts"],"names":[],"mappings":";;;;;;;;;AAAA,4DAAiE;AAOjE,8DAA4F;AAC5F,sEAA2E;AAO3E;;;GAGG;AACH,MAAa,iBAAiB;IAI5B;;;;OAIG;IACH,YAAY,WAAiB,EAAE,MAAkB;;QAC/C,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,WAAW,CAAC,EAAE,OAAO,EAA4B;QACrD,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,cAAc,EAAE,CAAA;QAC9D,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,OAAO,CAAC,CAAA;QAE3D,IAAI,cAAc,EAAE,CAAC;YACnB,OAAO,uBAAA,IAAI,mEAAY,MAAhB,IAAI,EAAa,EAAE,WAAW,EAAE,CAAC,CAAA;QAC1C,CAAC;aAAM,CAAC;YACN,OAAO,uBAAA,IAAI,4EAAqB,MAAzB,IAAI,EAAsB,EAAE,WAAW,EAAE,CAAC,CAAA;QACnD,CAAC;IACH,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,cAAc,CAAC,EAAE,WAAW,EAA+B;QAC/D,IAAI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OffChainMessages(options?: ListOptions): Promise<SafeMessageListResponse>;
38
38
  };
39
- //# sourceMappingURL=offChainMessages.d.ts.map