@dynamic-labs/waas-evm 4.9.2-preview.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.
- package/CHANGELOG.md +5099 -0
- package/LICENSE +21 -0
- package/README.md +7 -0
- package/_virtual/_tslib.cjs +36 -0
- package/_virtual/_tslib.js +32 -0
- package/package.cjs +8 -0
- package/package.js +4 -0
- package/package.json +31 -0
- package/src/DynamicWaasEVMConnector.cjs +285 -0
- package/src/DynamicWaasEVMConnector.d.ts +61 -0
- package/src/DynamicWaasEVMConnector.js +281 -0
- package/src/DynamicWaasEVMConnectors.cjs +10 -0
- package/src/DynamicWaasEVMConnectors.d.ts +2 -0
- package/src/DynamicWaasEVMConnectors.js +6 -0
- package/src/index.cjs +14 -0
- package/src/index.d.ts +2 -0
- package/src/index.js +7 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Dynamic Labs, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
/******************************************************************************
|
|
7
|
+
Copyright (c) Microsoft Corporation.
|
|
8
|
+
|
|
9
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
10
|
+
purpose with or without fee is hereby granted.
|
|
11
|
+
|
|
12
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
13
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
14
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
15
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
16
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
17
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
18
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
19
|
+
***************************************************************************** */
|
|
20
|
+
|
|
21
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
22
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
32
|
+
var e = new Error(message);
|
|
33
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
exports.__awaiter = __awaiter;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
/******************************************************************************
|
|
3
|
+
Copyright (c) Microsoft Corporation.
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted.
|
|
7
|
+
|
|
8
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
9
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
10
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
11
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
12
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
13
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
14
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
15
|
+
***************************************************************************** */
|
|
16
|
+
|
|
17
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
28
|
+
var e = new Error(message);
|
|
29
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export { __awaiter };
|
package/package.cjs
ADDED
package/package.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dynamic-labs/waas-evm",
|
|
3
|
+
"version": "4.9.2-preview.0",
|
|
4
|
+
"description": "A React SDK for implementing wallet web3 authentication and authorization to your website.",
|
|
5
|
+
"author": "Dynamic Labs, Inc.",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"main": "./src/index.cjs",
|
|
8
|
+
"module": "./src/index.js",
|
|
9
|
+
"types": "./src/index.d.ts",
|
|
10
|
+
"type": "module",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./src/index.d.ts",
|
|
14
|
+
"import": "./src/index.js",
|
|
15
|
+
"require": "./src/index.cjs"
|
|
16
|
+
},
|
|
17
|
+
"./package.json": "./package.json"
|
|
18
|
+
},
|
|
19
|
+
"homepage": "https://www.dynamic.xyz/",
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@dynamic-labs-wallet/evm": "0.0.33",
|
|
22
|
+
"viem": "2.21.55",
|
|
23
|
+
"@dynamic-labs/assert-package-version": "4.9.2-preview.0",
|
|
24
|
+
"@dynamic-labs/ethereum-core": "4.9.2-preview.0",
|
|
25
|
+
"@dynamic-labs/logger": "4.9.2-preview.0",
|
|
26
|
+
"@dynamic-labs/types": "4.9.2-preview.0",
|
|
27
|
+
"@dynamic-labs/utils": "4.9.2-preview.0",
|
|
28
|
+
"@dynamic-labs/wallet-connector-core": "4.9.2-preview.0"
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {}
|
|
31
|
+
}
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../_virtual/_tslib.cjs');
|
|
7
|
+
var viem = require('viem');
|
|
8
|
+
var accounts = require('viem/accounts');
|
|
9
|
+
var evm = require('@dynamic-labs-wallet/evm');
|
|
10
|
+
var logger$1 = require('@dynamic-labs/logger');
|
|
11
|
+
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
12
|
+
var ethereumCore = require('@dynamic-labs/ethereum-core');
|
|
13
|
+
var utils = require('@dynamic-labs/utils');
|
|
14
|
+
|
|
15
|
+
const logger = new logger$1.Logger('DynamicWaasConnector');
|
|
16
|
+
class DynamicWaasEVMConnector extends ethereumCore.EthereumWalletConnector {
|
|
17
|
+
constructor(props) {
|
|
18
|
+
super(props);
|
|
19
|
+
this.name = 'Dynamic Waas';
|
|
20
|
+
this.overrideKey = 'dynamicwaas';
|
|
21
|
+
this.isEmbeddedWallet = true;
|
|
22
|
+
}
|
|
23
|
+
setGetAuthTokenFunction(getAuthToken) {
|
|
24
|
+
this.getAuthToken = getAuthToken;
|
|
25
|
+
}
|
|
26
|
+
setEnvironmentId(environmentId) {
|
|
27
|
+
this.environmentId = environmentId;
|
|
28
|
+
}
|
|
29
|
+
setBaseApiUrl(baseApiUrl) {
|
|
30
|
+
this.baseApiUrl = baseApiUrl;
|
|
31
|
+
}
|
|
32
|
+
setlastUsedChainId(chainId) {
|
|
33
|
+
if (chainId === undefined) {
|
|
34
|
+
localStorage.removeItem(DynamicWaasEVMConnector.lastUsedChainIdStorageKey);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
localStorage.setItem(DynamicWaasEVMConnector.lastUsedChainIdStorageKey, chainId.toString());
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
getlastUsedChainId() {
|
|
41
|
+
const lastUsedChainIdLS = localStorage.getItem(DynamicWaasEVMConnector.lastUsedChainIdStorageKey);
|
|
42
|
+
if (!lastUsedChainIdLS)
|
|
43
|
+
return undefined;
|
|
44
|
+
try {
|
|
45
|
+
const chainId = parseInt(lastUsedChainIdLS);
|
|
46
|
+
if (isNaN(chainId)) {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
const isChainCurrentlyEnabled = this.evmNetworks.some((network) => network.chainId === chainId);
|
|
50
|
+
if (!isChainCurrentlyEnabled) {
|
|
51
|
+
const lastUsedChainId = this.evmNetworks[0].chainId;
|
|
52
|
+
this.setlastUsedChainId(lastUsedChainId);
|
|
53
|
+
return lastUsedChainId;
|
|
54
|
+
}
|
|
55
|
+
return chainId;
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
logger.error(err);
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
currentChainId() {
|
|
63
|
+
var _a, _b, _c;
|
|
64
|
+
return (_a = this.getlastUsedChainId()) !== null && _a !== void 0 ? _a : (_c = (_b = this.evmNetworks) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.chainId;
|
|
65
|
+
}
|
|
66
|
+
getNetwork() {
|
|
67
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
return this.currentChainId();
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
getEvmNetworkByChainId(chainId) {
|
|
72
|
+
return this.evmNetworks.find((network) => network.chainId === chainId);
|
|
73
|
+
}
|
|
74
|
+
currentEvmNetwork() {
|
|
75
|
+
const chainId = this.currentChainId();
|
|
76
|
+
if (!chainId) {
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
return this.getEvmNetworkByChainId(chainId);
|
|
80
|
+
}
|
|
81
|
+
switchNetwork(_a) {
|
|
82
|
+
return _tslib.__awaiter(this, arguments, void 0, function* ({ networkChainId, }) {
|
|
83
|
+
if (!networkChainId) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
let networkChainIdInt = networkChainId;
|
|
87
|
+
if (typeof networkChainId === 'string') {
|
|
88
|
+
networkChainIdInt = parseInt(networkChainId);
|
|
89
|
+
}
|
|
90
|
+
this.setlastUsedChainId(networkChainIdInt);
|
|
91
|
+
this.emit('chainChange', {
|
|
92
|
+
chain: networkChainIdInt.toString(),
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
getRpcUrl() {
|
|
97
|
+
var _a;
|
|
98
|
+
const evmNetwork = this.currentEvmNetwork();
|
|
99
|
+
if (!evmNetwork) {
|
|
100
|
+
throw new Error('EVM network not found');
|
|
101
|
+
}
|
|
102
|
+
return ((_a = evmNetwork === null || evmNetwork === void 0 ? void 0 : evmNetwork.privateCustomerRpcUrls) === null || _a === void 0 ? void 0 : _a[0]) || (evmNetwork === null || evmNetwork === void 0 ? void 0 : evmNetwork.rpcUrls[0]);
|
|
103
|
+
}
|
|
104
|
+
setActiveAccountAddress(accountAddress) {
|
|
105
|
+
this.activeAccountAddress = accountAddress;
|
|
106
|
+
}
|
|
107
|
+
createDynamicWaasClient() {
|
|
108
|
+
var _a;
|
|
109
|
+
const authToken = (_a = this.getAuthToken) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
110
|
+
if (!authToken) {
|
|
111
|
+
throw new Error('Auth token is required');
|
|
112
|
+
}
|
|
113
|
+
if (!this.environmentId) {
|
|
114
|
+
throw new Error('Environment ID is required');
|
|
115
|
+
}
|
|
116
|
+
return new evm.DynamicEvmWalletClient({
|
|
117
|
+
authToken,
|
|
118
|
+
baseApiUrl: this.baseApiUrl,
|
|
119
|
+
baseMPCRelayApiUrl: 'relay.dynamic-preprod.xyz',
|
|
120
|
+
environmentId: this.environmentId,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
getWaasWalletClient() {
|
|
124
|
+
if (!this.dynamicWaasClient) {
|
|
125
|
+
this.dynamicWaasClient = this.createDynamicWaasClient();
|
|
126
|
+
}
|
|
127
|
+
return this.dynamicWaasClient;
|
|
128
|
+
}
|
|
129
|
+
validateActiveWallet(expectedAddress) {
|
|
130
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
131
|
+
const walletClient = this.getWaasWalletClient();
|
|
132
|
+
const targetWallet = yield walletClient.getWallet({
|
|
133
|
+
accountAddress: expectedAddress,
|
|
134
|
+
});
|
|
135
|
+
if (!targetWallet) {
|
|
136
|
+
throw new utils.DynamicError('Account not found');
|
|
137
|
+
}
|
|
138
|
+
const isWalletActive = walletConnectorCore.isSameAddress(targetWallet.accountAddress, this.activeAccountAddress || '', this.connectedChain);
|
|
139
|
+
if (!isWalletActive) {
|
|
140
|
+
this.activeAccountAddress = targetWallet.accountAddress;
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
getViemAccount({ accountAddress }) {
|
|
145
|
+
const client = this.getWaasWalletClient();
|
|
146
|
+
const customViemAccount = accounts.toAccount({
|
|
147
|
+
address: accountAddress,
|
|
148
|
+
signMessage: ({ message }) => client.signMessage({ accountAddress, message: message }),
|
|
149
|
+
signTransaction: (transaction) => client
|
|
150
|
+
.signTransaction({
|
|
151
|
+
senderAddress: accountAddress,
|
|
152
|
+
transaction,
|
|
153
|
+
})
|
|
154
|
+
.then((tx) => tx),
|
|
155
|
+
signTypedData: (typedData) => client.signMessage({
|
|
156
|
+
accountAddress,
|
|
157
|
+
message: typedData,
|
|
158
|
+
}),
|
|
159
|
+
});
|
|
160
|
+
return customViemAccount;
|
|
161
|
+
}
|
|
162
|
+
getWalletClient(chainId) {
|
|
163
|
+
const targetAccountAddress = this.activeAccountAddress;
|
|
164
|
+
if (!targetAccountAddress) {
|
|
165
|
+
return this.getPublicClient();
|
|
166
|
+
}
|
|
167
|
+
const rpcUrl = this.getRpcUrl();
|
|
168
|
+
const viemAccount = this.getViemAccount({
|
|
169
|
+
accountAddress: targetAccountAddress,
|
|
170
|
+
});
|
|
171
|
+
const evmNetwork = chainId
|
|
172
|
+
? this.getEvmNetworkByChainId(parseInt(chainId))
|
|
173
|
+
: this.currentEvmNetwork();
|
|
174
|
+
if (!evmNetwork) {
|
|
175
|
+
throw new Error('EVM network not found');
|
|
176
|
+
}
|
|
177
|
+
const walletClient = viem.createWalletClient({
|
|
178
|
+
account: viemAccount,
|
|
179
|
+
chain: ethereumCore.getOrMapViemChain(evmNetwork),
|
|
180
|
+
transport: viem.http(rpcUrl),
|
|
181
|
+
});
|
|
182
|
+
return walletClient;
|
|
183
|
+
}
|
|
184
|
+
createWalletAccount() {
|
|
185
|
+
return _tslib.__awaiter(this, arguments, void 0, function* ({ thresholdSignatureScheme = 'TWO_OF_TWO', } = {}) {
|
|
186
|
+
const walletClient = this.getWaasWalletClient();
|
|
187
|
+
const createdWallet = yield walletClient.createWalletAccount({
|
|
188
|
+
thresholdSignatureScheme: thresholdSignatureScheme,
|
|
189
|
+
});
|
|
190
|
+
return createdWallet;
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
signMessage(message) {
|
|
194
|
+
var _a;
|
|
195
|
+
return (_a = this.getWalletClient()) === null || _a === void 0 ? void 0 : _a.signMessage({ message });
|
|
196
|
+
}
|
|
197
|
+
getSigner() {
|
|
198
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
199
|
+
return this.getWalletClient();
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
getWalletClientByAddress({ accountAddress, }) {
|
|
203
|
+
this.setActiveAccountAddress(accountAddress);
|
|
204
|
+
return this.getWalletClient();
|
|
205
|
+
}
|
|
206
|
+
exportPrivateKey() {
|
|
207
|
+
return _tslib.__awaiter(this, arguments, void 0, function* ({ accountAddress, } = {}) {
|
|
208
|
+
const walletClient = this.getWaasWalletClient();
|
|
209
|
+
const targetAccountAddress = accountAddress || this.activeAccountAddress;
|
|
210
|
+
if (!targetAccountAddress) {
|
|
211
|
+
throw new Error('Account address is required');
|
|
212
|
+
}
|
|
213
|
+
const privateKey = yield walletClient.exportPrivateKey({
|
|
214
|
+
accountAddress: targetAccountAddress,
|
|
215
|
+
});
|
|
216
|
+
if (!(privateKey === null || privateKey === void 0 ? void 0 : privateKey.derivedPrivateKey)) {
|
|
217
|
+
throw new Error('Error exporting private key');
|
|
218
|
+
}
|
|
219
|
+
return privateKey.derivedPrivateKey;
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
importPrivateKey(_a) {
|
|
223
|
+
return _tslib.__awaiter(this, arguments, void 0, function* ({ privateKey, chainName, thresholdSignatureScheme = 'TWO_OF_TWO', }) {
|
|
224
|
+
const walletClient = this.getWaasWalletClient();
|
|
225
|
+
yield walletClient.importPrivateKey({
|
|
226
|
+
chainName,
|
|
227
|
+
privateKey,
|
|
228
|
+
thresholdSignatureScheme: thresholdSignatureScheme,
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
exportClientKeyshares(_a) {
|
|
233
|
+
return _tslib.__awaiter(this, arguments, void 0, function* ({ accountAddress, }) {
|
|
234
|
+
if (!accountAddress) {
|
|
235
|
+
throw new Error('Account address is required');
|
|
236
|
+
}
|
|
237
|
+
this.setActiveAccountAddress(accountAddress);
|
|
238
|
+
const walletClient = this.getWaasWalletClient();
|
|
239
|
+
yield walletClient.exportClientKeyshares({
|
|
240
|
+
accountAddress,
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
createUiTransaction(from) {
|
|
245
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
246
|
+
yield this.validateActiveWallet(from);
|
|
247
|
+
const walletClient = this.getWalletClient();
|
|
248
|
+
const publicClient = yield this.getPublicClient();
|
|
249
|
+
if (!publicClient || !walletClient) {
|
|
250
|
+
throw new utils.DynamicError('No public client available');
|
|
251
|
+
}
|
|
252
|
+
return new ethereumCore.ViemUiTransaction({
|
|
253
|
+
account: from,
|
|
254
|
+
onSubmit: (transaction) => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
255
|
+
// Non native token
|
|
256
|
+
if (transaction.nonNativeAddress) {
|
|
257
|
+
return walletClient.writeContract({
|
|
258
|
+
abi: viem.erc20Abi,
|
|
259
|
+
account: walletClient.account,
|
|
260
|
+
address: transaction.nonNativeAddress,
|
|
261
|
+
args: [transaction.to, transaction.nonNativeValue],
|
|
262
|
+
functionName: 'transfer',
|
|
263
|
+
maxFeePerGas: transaction.maxFeePerGas,
|
|
264
|
+
maxPriorityFeePerGas: transaction.maxPriorityFeePerGas,
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
// Native token
|
|
268
|
+
return walletClient.sendTransaction({
|
|
269
|
+
account: walletClient.account,
|
|
270
|
+
data: '0x',
|
|
271
|
+
maxFeePerGas: transaction.maxFeePerGas,
|
|
272
|
+
maxPriorityFeePerGas: transaction.maxPriorityFeePerGas,
|
|
273
|
+
to: transaction.to,
|
|
274
|
+
value: transaction.value,
|
|
275
|
+
});
|
|
276
|
+
}),
|
|
277
|
+
publicClient,
|
|
278
|
+
transaction: {},
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
DynamicWaasEVMConnector.lastUsedChainIdStorageKey = 'dynamic-waas-evm-last-used-chain-id';
|
|
284
|
+
|
|
285
|
+
exports.DynamicWaasEVMConnector = DynamicWaasEVMConnector;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Account, Hex, Transport, WalletClient, Chain as ViemChain } from 'viem';
|
|
2
|
+
import { LocalAccount } from 'viem/accounts';
|
|
3
|
+
import { DynamicEvmWalletClient } from '@dynamic-labs-wallet/evm';
|
|
4
|
+
import { EthereumWalletConnector, SwitchNetworkOps, EthereumWalletConnectorOpts } from '@dynamic-labs/ethereum-core';
|
|
5
|
+
import { IUITransaction } from '@dynamic-labs/types';
|
|
6
|
+
export declare class DynamicWaasEVMConnector extends EthereumWalletConnector {
|
|
7
|
+
static lastUsedChainIdStorageKey: string;
|
|
8
|
+
name: string;
|
|
9
|
+
overrideKey: string;
|
|
10
|
+
isEmbeddedWallet: boolean;
|
|
11
|
+
private environmentId?;
|
|
12
|
+
private getAuthToken?;
|
|
13
|
+
private dynamicWaasClient;
|
|
14
|
+
private activeAccountAddress;
|
|
15
|
+
private baseApiUrl?;
|
|
16
|
+
constructor(props: EthereumWalletConnectorOpts);
|
|
17
|
+
setGetAuthTokenFunction(getAuthToken: () => string): void;
|
|
18
|
+
setEnvironmentId(environmentId: string): void;
|
|
19
|
+
setBaseApiUrl(baseApiUrl: string): void;
|
|
20
|
+
setlastUsedChainId(chainId: number | undefined): void;
|
|
21
|
+
private getlastUsedChainId;
|
|
22
|
+
private currentChainId;
|
|
23
|
+
getNetwork(): Promise<number | undefined>;
|
|
24
|
+
private getEvmNetworkByChainId;
|
|
25
|
+
private currentEvmNetwork;
|
|
26
|
+
switchNetwork({ networkChainId, }: SwitchNetworkOps): Promise<void>;
|
|
27
|
+
private getRpcUrl;
|
|
28
|
+
private setActiveAccountAddress;
|
|
29
|
+
createDynamicWaasClient(): DynamicEvmWalletClient;
|
|
30
|
+
getWaasWalletClient(): DynamicEvmWalletClient;
|
|
31
|
+
validateActiveWallet(expectedAddress: string): Promise<void>;
|
|
32
|
+
getViemAccount({ accountAddress }: {
|
|
33
|
+
accountAddress: string;
|
|
34
|
+
}): LocalAccount;
|
|
35
|
+
getWalletClient(chainId?: string): WalletClient<Transport, ViemChain, Account> | undefined;
|
|
36
|
+
createWalletAccount({ thresholdSignatureScheme, }?: {
|
|
37
|
+
thresholdSignatureScheme?: string;
|
|
38
|
+
}): Promise<{
|
|
39
|
+
accountAddress: string;
|
|
40
|
+
publicKeyHex: string;
|
|
41
|
+
rawPublicKey: any;
|
|
42
|
+
clientKeyShares: any[];
|
|
43
|
+
}>;
|
|
44
|
+
signMessage(message: string): Promise<Hex>;
|
|
45
|
+
getSigner(): Promise<any>;
|
|
46
|
+
getWalletClientByAddress({ accountAddress, }: {
|
|
47
|
+
accountAddress: string;
|
|
48
|
+
}): WalletClient<Transport, ViemChain, Account> | undefined;
|
|
49
|
+
exportPrivateKey({ accountAddress, }?: {
|
|
50
|
+
accountAddress?: string;
|
|
51
|
+
}): Promise<string>;
|
|
52
|
+
importPrivateKey({ privateKey, chainName, thresholdSignatureScheme, }: {
|
|
53
|
+
privateKey: string;
|
|
54
|
+
chainName: string;
|
|
55
|
+
thresholdSignatureScheme?: string;
|
|
56
|
+
}): Promise<void>;
|
|
57
|
+
exportClientKeyshares({ accountAddress, }: {
|
|
58
|
+
accountAddress: string;
|
|
59
|
+
}): Promise<void>;
|
|
60
|
+
createUiTransaction(from: string): Promise<IUITransaction>;
|
|
61
|
+
}
|