@cityofzion/bs-ethereum 2.13.5 → 2.14.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.
@@ -1,7 +1,8 @@
1
- import { TBSAccount, TBSToken, TTransferParam, TGetLedgerTransport, ITokenService, TBSNetwork, IBlockchainDataService, IExchangeDataService, INftDataService, IExplorerService, TPingNetworkResponse } from '@cityofzion/blockchain-service';
1
+ import { TBSAccount, TBSToken, TTransferParam, TGetLedgerTransport, ITokenService, TBSNetwork, IBlockchainDataService, IExchangeDataService, INftDataService, IExplorerService, TPingNetworkResponse, IWalletConnectService } from '@cityofzion/blockchain-service';
2
2
  import { ethers } from 'ethers';
3
3
  import { EthersLedgerServiceEthereum } from './services/ledger/EthersLedgerServiceEthereum';
4
4
  import { IBSEthereum, TBSEthereumNetworkId, TSupportedEVM } from './types';
5
+ import { TypedDataSigner } from '@ethersproject/abstract-signer';
5
6
  export declare class BSEthereum<N extends string = string, A extends string = TBSEthereumNetworkId> implements IBSEthereum<N, A> {
6
7
  #private;
7
8
  readonly name: N;
@@ -21,8 +22,9 @@ export declare class BSEthereum<N extends string = string, A extends string = TB
21
22
  nftDataService: INftDataService;
22
23
  explorerService: IExplorerService;
23
24
  tokenService: ITokenService;
25
+ walletConnectService: IWalletConnectService;
24
26
  constructor(name: N, evm?: TSupportedEVM, network?: TBSNetwork<A>, getLedgerTransport?: TGetLedgerTransport<N>);
25
- generateSigner(account: TBSAccount<N>): Promise<ethers.Signer>;
27
+ generateSigner(account: TBSAccount<N>): Promise<ethers.Signer & TypedDataSigner>;
26
28
  setNetwork(network: TBSNetwork<A>): void;
27
29
  pingNetwork(network: TBSNetwork<A>): Promise<TPingNetworkResponse>;
28
30
  validateAddress(address: string): boolean;
@@ -65,6 +65,7 @@ const MoralisEDSEthereum_1 = require("./services/exchange-data/MoralisEDSEthereu
65
65
  const GhostMarketNDSEthereum_1 = require("./services/nft-data/GhostMarketNDSEthereum");
66
66
  const BlockscoutESEthereum_1 = require("./services/explorer/BlockscoutESEthereum");
67
67
  const TokenServiceEthereum_1 = require("./services/token/TokenServiceEthereum");
68
+ const WalletConnectServiceEthereum_1 = require("./services/wallet-connect/WalletConnectServiceEthereum");
68
69
  const axios_1 = __importDefault(require("axios"));
69
70
  class BSEthereum {
70
71
  constructor(name, evm, network, getLedgerTransport) {
@@ -108,6 +109,7 @@ class BSEthereum {
108
109
  this.exchangeDataService = new MoralisEDSEthereum_1.MoralisEDSEthereum(this);
109
110
  this.blockchainDataService = new MoralisBDSEthereum_1.MoralisBDSEthereum(this);
110
111
  this.tokenService = new TokenServiceEthereum_1.TokenServiceEthereum();
112
+ this.walletConnectService = new WalletConnectServiceEthereum_1.WalletConnectServiceEthereum(this);
111
113
  }
112
114
  // This method is done manually because we need to ensure that the request is aborted after timeout
113
115
  pingNetwork(network) {
package/dist/index.d.ts CHANGED
@@ -8,6 +8,7 @@ export * from './services/explorer/BlockscoutESEthereum';
8
8
  export * from './services/ledger/EthersLedgerServiceEthereum';
9
9
  export * from './services/nft-data/GhostMarketNDSEthereum';
10
10
  export * from './services/token/TokenServiceEthereum';
11
+ export * from './services/wallet-connect/WalletConnectServiceEthereum';
11
12
  export * from './assets/abis/ERC20';
12
13
  export * from './assets/abis/ERC721';
13
14
  export * from './types';
package/dist/index.js CHANGED
@@ -24,6 +24,7 @@ __exportStar(require("./services/explorer/BlockscoutESEthereum"), exports);
24
24
  __exportStar(require("./services/ledger/EthersLedgerServiceEthereum"), exports);
25
25
  __exportStar(require("./services/nft-data/GhostMarketNDSEthereum"), exports);
26
26
  __exportStar(require("./services/token/TokenServiceEthereum"), exports);
27
+ __exportStar(require("./services/wallet-connect/WalletConnectServiceEthereum"), exports);
27
28
  __exportStar(require("./assets/abis/ERC20"), exports);
28
29
  __exportStar(require("./assets/abis/ERC721"), exports);
29
30
  __exportStar(require("./types"), exports);
@@ -0,0 +1,29 @@
1
+ import { IWalletConnectService, TBSNetworkId, TWalletConnectServiceRequestMethodParams } from '@cityofzion/blockchain-service';
2
+ import { IBSEthereum } from '../../types';
3
+ export declare class WalletConnectServiceEthereum<N extends string, A extends TBSNetworkId> implements IWalletConnectService {
4
+ #private;
5
+ readonly namespace: string;
6
+ readonly chain: string;
7
+ readonly supportedMethods: string[];
8
+ readonly supportedEvents: string[];
9
+ readonly calculableMethods: string[];
10
+ readonly autoApproveMethods: string[];
11
+ constructor(service: IBSEthereum<N, A>);
12
+ personal_sign(args: TWalletConnectServiceRequestMethodParams<N>): Promise<string>;
13
+ eth_sign(args: TWalletConnectServiceRequestMethodParams<N>): Promise<string>;
14
+ eth_signTransaction(args: TWalletConnectServiceRequestMethodParams<N>): Promise<string>;
15
+ eth_signTypedData(args: TWalletConnectServiceRequestMethodParams<N>): Promise<string>;
16
+ eth_signTypedData_v3(args: TWalletConnectServiceRequestMethodParams<N>): Promise<string>;
17
+ eth_signTypedData_v4(args: TWalletConnectServiceRequestMethodParams<N>): Promise<string>;
18
+ eth_sendTransaction(args: TWalletConnectServiceRequestMethodParams<N>): Promise<string>;
19
+ eth_call(args: TWalletConnectServiceRequestMethodParams<N>): Promise<string>;
20
+ eth_requestAccounts(args: TWalletConnectServiceRequestMethodParams<N>): Promise<string[]>;
21
+ eth_sendRawTransaction(args: TWalletConnectServiceRequestMethodParams<N>): Promise<string>;
22
+ wallet_switchEthereumChain(): Promise<string>;
23
+ eth_addEthereumChain(): Promise<string>;
24
+ eth_switchEthereumChain(): Promise<string>;
25
+ wallet_getPermissions(): Promise<any[]>;
26
+ wallet_requestPermissions(): Promise<any[]>;
27
+ wallet_addEthereumChain(): Promise<string>;
28
+ calculateRequestFee(args: TWalletConnectServiceRequestMethodParams<N>): Promise<string>;
29
+ }
@@ -0,0 +1,220 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
12
+ if (kind === "m") throw new TypeError("Private method is not writable");
13
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
14
+ 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");
15
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
16
+ };
17
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
18
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
19
+ 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");
20
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
21
+ };
22
+ var _WalletConnectServiceEthereum_instances, _WalletConnectServiceEthereum_service, _WalletConnectServiceEthereum_resolveParams, _WalletConnectServiceEthereum_convertHexToUtf8;
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.WalletConnectServiceEthereum = void 0;
25
+ const ethers_1 = require("ethers");
26
+ const BSEthereumConstants_1 = require("../../constants/BSEthereumConstants");
27
+ class WalletConnectServiceEthereum {
28
+ constructor(service) {
29
+ _WalletConnectServiceEthereum_instances.add(this);
30
+ this.namespace = 'eip155';
31
+ this.supportedMethods = [
32
+ 'personal_sign',
33
+ 'eth_sign',
34
+ 'eth_signTransaction',
35
+ 'eth_signTypedData',
36
+ 'eth_signTypedData_v3',
37
+ 'eth_signTypedData_v4',
38
+ 'eth_sendTransaction',
39
+ 'eth_call',
40
+ 'eth_requestAccounts',
41
+ 'eth_sendRawTransaction',
42
+ 'eth_addEthereumChain',
43
+ 'eth_switchEthereumChain',
44
+ 'wallet_switchEthereumChain',
45
+ 'wallet_getPermissions',
46
+ 'wallet_requestPermissions',
47
+ 'wallet_addEthereumChain',
48
+ ];
49
+ this.supportedEvents = ['chainChanged', 'accountsChanged', 'disconnect', 'connect'];
50
+ this.calculableMethods = ['eth_sendTransaction', 'eth_call', 'eth_sendRawTransaction'];
51
+ this.autoApproveMethods = [
52
+ 'eth_requestAccounts',
53
+ 'eth_addEthereumChain',
54
+ 'eth_switchEthereumChain',
55
+ 'wallet_switchEthereumChain',
56
+ 'wallet_getPermissions',
57
+ 'wallet_requestPermissions',
58
+ 'wallet_addEthereumChain',
59
+ ];
60
+ _WalletConnectServiceEthereum_service.set(this, void 0);
61
+ __classPrivateFieldSet(this, _WalletConnectServiceEthereum_service, service, "f");
62
+ this.chain = `${this.namespace}:${__classPrivateFieldGet(this, _WalletConnectServiceEthereum_service, "f").network.id.toString()}`;
63
+ }
64
+ personal_sign(args) {
65
+ return __awaiter(this, void 0, void 0, function* () {
66
+ const wallet = yield __classPrivateFieldGet(this, _WalletConnectServiceEthereum_service, "f").generateSigner(args.account);
67
+ const message = args.params.filter((param) => !ethers_1.ethers.utils.isAddress(param))[0];
68
+ const convertedMessage = __classPrivateFieldGet(this, _WalletConnectServiceEthereum_instances, "m", _WalletConnectServiceEthereum_convertHexToUtf8).call(this, message);
69
+ const signedMessage = yield wallet.signMessage(convertedMessage);
70
+ return signedMessage;
71
+ });
72
+ }
73
+ eth_sign(args) {
74
+ return __awaiter(this, void 0, void 0, function* () {
75
+ return yield this.personal_sign(args);
76
+ });
77
+ }
78
+ eth_signTransaction(args) {
79
+ return __awaiter(this, void 0, void 0, function* () {
80
+ const { param, wallet } = yield __classPrivateFieldGet(this, _WalletConnectServiceEthereum_instances, "m", _WalletConnectServiceEthereum_resolveParams).call(this, args);
81
+ const signature = yield wallet.signTransaction(param);
82
+ return signature;
83
+ });
84
+ }
85
+ eth_signTypedData(args) {
86
+ return __awaiter(this, void 0, void 0, function* () {
87
+ const wallet = yield __classPrivateFieldGet(this, _WalletConnectServiceEthereum_service, "f").generateSigner(args.account);
88
+ const data = args.params.filter((param) => !ethers_1.ethers.utils.isAddress(param))[0];
89
+ const parsedData = typeof data === 'string' ? JSON.parse(data) : data;
90
+ const { domain, types, message } = parsedData;
91
+ // https://github.com/ethers-io/ethers.js/issues/687#issuecomment-714069471
92
+ delete types.EIP712Domain;
93
+ const signedData = yield wallet._signTypedData(domain, types, message);
94
+ return signedData;
95
+ });
96
+ }
97
+ eth_signTypedData_v3(args) {
98
+ return __awaiter(this, void 0, void 0, function* () {
99
+ return yield this.eth_signTypedData(args);
100
+ });
101
+ }
102
+ eth_signTypedData_v4(args) {
103
+ return __awaiter(this, void 0, void 0, function* () {
104
+ return yield this.eth_signTypedData(args);
105
+ });
106
+ }
107
+ eth_sendTransaction(args) {
108
+ return __awaiter(this, void 0, void 0, function* () {
109
+ const { param, provider, wallet } = yield __classPrivateFieldGet(this, _WalletConnectServiceEthereum_instances, "m", _WalletConnectServiceEthereum_resolveParams).call(this, args);
110
+ const connectedWallet = wallet.connect(provider);
111
+ const { hash } = yield connectedWallet.sendTransaction(param);
112
+ return hash;
113
+ });
114
+ }
115
+ eth_call(args) {
116
+ return __awaiter(this, void 0, void 0, function* () {
117
+ const { param, provider, wallet } = yield __classPrivateFieldGet(this, _WalletConnectServiceEthereum_instances, "m", _WalletConnectServiceEthereum_resolveParams).call(this, args);
118
+ const connectedWallet = wallet.connect(provider);
119
+ return yield connectedWallet.call(param);
120
+ });
121
+ }
122
+ eth_requestAccounts(args) {
123
+ return __awaiter(this, void 0, void 0, function* () {
124
+ const wallet = yield __classPrivateFieldGet(this, _WalletConnectServiceEthereum_service, "f").generateSigner(args.account);
125
+ return [yield wallet.getAddress()];
126
+ });
127
+ }
128
+ eth_sendRawTransaction(args) {
129
+ return __awaiter(this, void 0, void 0, function* () {
130
+ const provider = new ethers_1.ethers.providers.JsonRpcProvider(__classPrivateFieldGet(this, _WalletConnectServiceEthereum_service, "f").network.url);
131
+ const { hash } = yield provider.sendTransaction(args.params[0]);
132
+ return hash;
133
+ });
134
+ }
135
+ wallet_switchEthereumChain() {
136
+ return __awaiter(this, void 0, void 0, function* () {
137
+ return 'null';
138
+ });
139
+ }
140
+ eth_addEthereumChain() {
141
+ return __awaiter(this, void 0, void 0, function* () {
142
+ return 'null';
143
+ });
144
+ }
145
+ eth_switchEthereumChain() {
146
+ return __awaiter(this, void 0, void 0, function* () {
147
+ return 'null';
148
+ });
149
+ }
150
+ wallet_getPermissions() {
151
+ return __awaiter(this, void 0, void 0, function* () {
152
+ return [];
153
+ });
154
+ }
155
+ wallet_requestPermissions() {
156
+ return __awaiter(this, void 0, void 0, function* () {
157
+ return [];
158
+ });
159
+ }
160
+ wallet_addEthereumChain() {
161
+ return __awaiter(this, void 0, void 0, function* () {
162
+ return 'null';
163
+ });
164
+ }
165
+ calculateRequestFee(args) {
166
+ return __awaiter(this, void 0, void 0, function* () {
167
+ const { param, wallet, provider } = yield __classPrivateFieldGet(this, _WalletConnectServiceEthereum_instances, "m", _WalletConnectServiceEthereum_resolveParams).call(this, args);
168
+ const connectedWallet = wallet.connect(provider);
169
+ const gasPrice = yield provider.getGasPrice();
170
+ const estimated = yield connectedWallet.estimateGas(param);
171
+ return ethers_1.ethers.utils.formatEther(gasPrice.mul(estimated));
172
+ });
173
+ }
174
+ }
175
+ exports.WalletConnectServiceEthereum = WalletConnectServiceEthereum;
176
+ _WalletConnectServiceEthereum_service = new WeakMap(), _WalletConnectServiceEthereum_instances = new WeakSet(), _WalletConnectServiceEthereum_resolveParams = function _WalletConnectServiceEthereum_resolveParams(args) {
177
+ return __awaiter(this, void 0, void 0, function* () {
178
+ var _a, _b, _c;
179
+ const wallet = yield __classPrivateFieldGet(this, _WalletConnectServiceEthereum_service, "f").generateSigner(args.account);
180
+ const provider = new ethers_1.ethers.providers.JsonRpcProvider(__classPrivateFieldGet(this, _WalletConnectServiceEthereum_service, "f").network.url);
181
+ const param = args.params[0];
182
+ if (typeof param !== 'object') {
183
+ throw new Error('Invalid Params');
184
+ }
185
+ if (param.gas) {
186
+ param.gasLimit = param.gas;
187
+ delete param.gas;
188
+ }
189
+ if (param.type && typeof param.type !== 'number') {
190
+ param.type = parseInt(param.type);
191
+ }
192
+ const gasPrice = yield provider.getGasPrice();
193
+ if (param.type === 2) {
194
+ param.maxPriorityFeePerGas = (_a = param.maxPriorityFeePerGas) !== null && _a !== void 0 ? _a : gasPrice;
195
+ param.maxFeePerGas = (_b = param.maxPriorityFeePerGas) !== null && _b !== void 0 ? _b : gasPrice;
196
+ }
197
+ else {
198
+ param.gasPrice = (_c = param.gasPrice) !== null && _c !== void 0 ? _c : gasPrice;
199
+ }
200
+ if (!param.gasLimit) {
201
+ const connectedWallet = wallet.connect(provider);
202
+ try {
203
+ param.gasLimit = yield connectedWallet.estimateGas(Object.assign(Object.assign({}, param), { gasLimit: BSEthereumConstants_1.BSEthereumConstants.DEFAULT_GAS_LIMIT }));
204
+ }
205
+ catch (_d) {
206
+ param.gasLimit = BSEthereumConstants_1.BSEthereumConstants.DEFAULT_GAS_LIMIT;
207
+ }
208
+ }
209
+ return {
210
+ param,
211
+ provider,
212
+ wallet,
213
+ };
214
+ });
215
+ }, _WalletConnectServiceEthereum_convertHexToUtf8 = function _WalletConnectServiceEthereum_convertHexToUtf8(value) {
216
+ if (ethers_1.ethers.utils.isHexString(value)) {
217
+ return ethers_1.ethers.utils.toUtf8String(value);
218
+ }
219
+ return value;
220
+ };
package/dist/types.d.ts CHANGED
@@ -1,7 +1,10 @@
1
- import { IBlockchainService, IBSWithEncryption, IBSWithExplorer, IBSWithFee, IBSWithLedger, IBSWithNameService, IBSWithNft, TBSNetworkId } from '@cityofzion/blockchain-service';
1
+ import { IBlockchainService, IBSWithEncryption, IBSWithExplorer, IBSWithFee, IBSWithLedger, IBSWithNameService, IBSWithNft, IBSWithWalletConnect, TBSAccount, TBSNetworkId } from '@cityofzion/blockchain-service';
2
+ import { TypedDataSigner } from '@ethersproject/abstract-signer';
3
+ import { ethers } from 'ethers';
2
4
  export type TBSEthereumNetworkId = TBSNetworkId<'1' | '10' | '25' | '56' | '137' | '250' | '1101' | '8453' | '80002' | '42161' | '42220' | '43114' | '59144' | '11155111'>;
3
5
  export type TSupportedEVM = 'ethereum' | 'polygon' | 'base' | 'arbitrum';
4
- export interface IBSEthereum<N extends string = string, A extends string = TBSEthereumNetworkId> extends IBlockchainService<N, A>, IBSWithNft, IBSWithNameService, IBSWithFee<N>, IBSWithLedger<N>, IBSWithExplorer, IBSWithEncryption<N> {
6
+ export interface IBSEthereum<N extends string = string, A extends string = TBSEthereumNetworkId> extends IBlockchainService<N, A>, IBSWithNft, IBSWithNameService, IBSWithFee<N>, IBSWithLedger<N>, IBSWithExplorer, IBSWithEncryption<N>, IBSWithWalletConnect {
7
+ generateSigner(account: TBSAccount<N>): Promise<ethers.Signer & TypedDataSigner>;
5
8
  }
6
9
  export type TMoralisBDSEthereumNativeBalanceApiResponse = {
7
10
  balance: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cityofzion/bs-ethereum",
3
- "version": "2.13.5",
3
+ "version": "2.14.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": "https://github.com/CityOfZion/blockchain-services",
@@ -19,7 +19,7 @@
19
19
  "@ethersproject/abstract-signer": "5.7.0",
20
20
  "@ethersproject/properties": "5.7.0",
21
21
  "@cityofzion/dora-ts": "~0.5.1",
22
- "@cityofzion/blockchain-service": "1.21.3"
22
+ "@cityofzion/blockchain-service": "1.22.0"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@ledgerhq/hw-transport": "~6.31.11",