@socket.tech/dl-common 1.0.4-test.4 → 1.0.4-test.5

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.
@@ -1,7 +1,7 @@
1
- import { Provider, TransactionRequest, TransactionResponse } from "@ethersproject/abstract-provider";
2
- import { Deferrable } from "@ethersproject/properties";
1
+ import { type Provider, type TransactionRequest, type TransactionResponse } from "@ethersproject/abstract-provider";
2
+ import { type Deferrable } from "@ethersproject/properties";
3
3
  import { SocketRelaySigner } from "../relaySigner";
4
- import { Contract, Wallet } from "ethers";
4
+ import { Contract, type Wallet } from "ethers";
5
5
  export declare const EIP712_SAFE_TX_TYPE: {
6
6
  SafeTx: {
7
7
  type: string;
@@ -15,17 +15,18 @@ export declare class SocketSigner extends SocketRelaySigner {
15
15
  readonly safeWrapperAddress: string;
16
16
  readonly relayUrl: string;
17
17
  readonly relayerAPIKey: string;
18
- readonly signingWallet: Wallet;
18
+ readonly signingWallet?: Wallet | undefined;
19
19
  readonly useSafe: boolean;
20
20
  readonly useEOA: boolean;
21
21
  readonly sequential: boolean;
22
22
  readonly isCritical: boolean;
23
23
  readonly metadata: object;
24
- readonly safeWrapperContract: Contract;
25
- constructor(provider: Provider, chainId: number, safeAddress: string, safeWrapperAddress: string, relayUrl: string, relayerAPIKey: string, signingWallet: Wallet, useSafe?: boolean, useEOA?: boolean, sequential?: boolean, isCritical?: boolean, metadata?: object);
24
+ readonly safeWrapperContract: Contract | undefined;
25
+ constructor(provider: Provider, chainId: number, safeAddress: string, safeWrapperAddress: string, relayUrl: string, relayerAPIKey: string, signingWallet?: Wallet | undefined, useSafe?: boolean, useEOA?: boolean, sequential?: boolean, isCritical?: boolean, metadata?: object);
26
26
  setSigningWallet(signingWallet: Wallet): SocketRelaySigner;
27
27
  setSafeWrapperAddress(safeWrapperAddress: string): SocketRelaySigner;
28
28
  setSafeAddress(safeAddress: string): SocketRelaySigner;
29
29
  getAddress(): Promise<string>;
30
+ address(): Promise<string>;
30
31
  sendTransaction(transaction: Deferrable<TransactionRequest>): Promise<TransactionResponse>;
31
32
  }
@@ -50,7 +50,8 @@ class SocketSigner extends relaySigner_1.SocketRelaySigner {
50
50
  this.sequential = sequential;
51
51
  this.isCritical = isCritical;
52
52
  this.metadata = metadata;
53
- this.safeWrapperContract = new ethers_1.Contract(this.safeWrapperAddress, MultiSigWrapper_json_1.default, this.provider);
53
+ if (this.safeWrapperAddress.length !== 0)
54
+ this.safeWrapperContract = new ethers_1.Contract(this.safeWrapperAddress, MultiSigWrapper_json_1.default, this.provider);
54
55
  }
55
56
  setSigningWallet(signingWallet) {
56
57
  return new SocketSigner(this.provider, this.chainId, this.safeAddress, this.safeWrapperAddress, this.relayUrl, this.relayerAPIKey, signingWallet, this.useSafe, this.useEOA, this.sequential, this.isCritical, this.metadata);
@@ -62,55 +63,53 @@ class SocketSigner extends relaySigner_1.SocketRelaySigner {
62
63
  return new SocketSigner(this.provider, this.chainId, safeAddress, this.safeWrapperAddress, this.relayUrl, this.relayerAPIKey, this.signingWallet, this.useSafe, this.useEOA, this.sequential, this.isCritical, this.metadata);
63
64
  }
64
65
  async getAddress() {
65
- if (this.useEOA || this.useSafe)
66
+ if (this.signingWallet != null)
66
67
  return await this.signingWallet.getAddress();
67
- return super.getAddress();
68
+ return await super.getAddress();
69
+ }
70
+ async address() {
71
+ return await this.getAddress();
68
72
  }
69
73
  async sendTransaction(transaction) {
70
- try {
71
- if (this.useSafe) {
72
- if (!this.safeWrapperAddress ||
73
- this.safeWrapperAddress === ethers_1.constants.AddressZero)
74
- throw new Error("safeWrapperAddress not provided");
75
- if (!this.safeAddress || this.safeAddress === ethers_1.constants.AddressZero)
76
- throw new Error("safeAddress not provided");
77
- if (!this.signingWallet)
78
- throw new Error("signingWallet not provided");
79
- const nonce = await this.safeWrapperContract.getNonce();
80
- const contractData = {
81
- to: transaction.to,
82
- value: transaction.value || 0,
83
- data: transaction.data || "0x",
84
- operation: 0,
85
- safeTxGas: 0,
86
- baseGas: 0,
87
- gasPrice: 0,
88
- gasToken: ethers_1.constants.AddressZero,
89
- refundReceiver: ethers_1.constants.AddressZero,
74
+ var _a, _b;
75
+ if (this.useSafe) {
76
+ if (this.safeAddress.length === 0 || this.safeAddress === ethers_1.constants.AddressZero)
77
+ throw new Error("safeAddress not provided");
78
+ if (this.safeWrapperContract == null)
79
+ throw new Error("safe wrapper not provided");
80
+ if (this.signingWallet == null)
81
+ throw new Error("signingWallet not provided");
82
+ const nonce = await this.safeWrapperContract.getNonce();
83
+ const contractData = {
84
+ to: transaction.to,
85
+ value: (_a = transaction.value) !== null && _a !== void 0 ? _a : 0,
86
+ data: (_b = transaction.data) !== null && _b !== void 0 ? _b : "0x",
87
+ operation: 0,
88
+ safeTxGas: 0,
89
+ baseGas: 0,
90
+ gasPrice: 0,
91
+ gasToken: ethers_1.constants.AddressZero,
92
+ refundReceiver: ethers_1.constants.AddressZero,
93
+ nonce,
94
+ };
95
+ const signature = await this.signingWallet._signTypedData({ verifyingContract: this.safeAddress, chainId: this.chainId }, exports.EIP712_SAFE_TX_TYPE, contractData);
96
+ // update to & data
97
+ transaction.data =
98
+ this.safeWrapperContract.interface.encodeFunctionData("storeOrRelaySignatures", [
99
+ contractData.to,
90
100
  nonce,
91
- };
92
- const signature = await this.signingWallet._signTypedData({ verifyingContract: this.safeAddress, chainId: this.chainId }, exports.EIP712_SAFE_TX_TYPE, contractData);
93
- // update to & data
94
- transaction.data =
95
- this.safeWrapperContract.interface.encodeFunctionData("storeOrRelaySignatures", [
96
- contractData.to,
97
- nonce,
98
- contractData.value,
99
- contractData.data,
100
- signature,
101
- ]);
102
- transaction.to = this.safeWrapperAddress;
103
- }
104
- if (this.useEOA) {
105
- if (!this.signingWallet)
106
- throw new Error("signingWallet not provided");
107
- return this.signingWallet.sendTransaction(transaction);
108
- }
109
- return super.sendTransaction(transaction);
101
+ contractData.value,
102
+ contractData.data,
103
+ signature,
104
+ ]);
105
+ transaction.to = this.safeWrapperAddress;
110
106
  }
111
- catch (error) {
112
- throw error;
107
+ if (this.useEOA) {
108
+ if (this.signingWallet == null)
109
+ throw new Error("signingWallet not provided");
110
+ return await this.signingWallet.sendTransaction(transaction);
113
111
  }
112
+ return await super.sendTransaction(transaction);
114
113
  }
115
114
  }
116
115
  exports.SocketSigner = SocketSigner;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@socket.tech/dl-common",
3
- "version": "1.0.4-test.4",
3
+ "version": "1.0.4-test.5",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "description": "common utilities for socket data layer.",