@shapeshiftoss/hdwallet-walletconnectv2 1.50.7

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.
@@ -0,0 +1,360 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.WalletConnectV2HDWallet = exports.WalletConnectV2WalletInfo = exports.isWalletConnectV2 = void 0;
16
+ const hdwallet_core_1 = require("@shapeshiftoss/hdwallet-core");
17
+ const isObject_1 = __importDefault(require("lodash/isObject"));
18
+ const ethereum_1 = require("./ethereum");
19
+ function isWalletConnectV2(wallet) {
20
+ return isObject_1.default(wallet) && wallet._isWalletConnectV2;
21
+ }
22
+ exports.isWalletConnectV2 = isWalletConnectV2;
23
+ /**
24
+ * WalletConnect Wallet Info
25
+ *
26
+ * Supported JSON-RPC API Methods:
27
+ * - personal_sign
28
+ * - eth_sign
29
+ * - eth_signTypedData
30
+ * - eth_sendTransaction
31
+ * - eth_signTransaction
32
+ * - eth_sendRawTransaction
33
+ * @see https://specs.walletconnect.com/2.0/blockchain-rpc/ethereum-rpc
34
+ */
35
+ class WalletConnectV2WalletInfo {
36
+ constructor() {
37
+ this._supportsETHInfo = true;
38
+ this._supportsBTCInfo = false;
39
+ }
40
+ getVendor() {
41
+ return "WalletConnectV2";
42
+ }
43
+ hasOnDevicePinEntry() {
44
+ return false;
45
+ }
46
+ hasOnDevicePassphrase() {
47
+ return false;
48
+ }
49
+ hasOnDeviceDisplay() {
50
+ return false;
51
+ }
52
+ hasOnDeviceRecovery() {
53
+ return false;
54
+ }
55
+ hasNativeShapeShift() {
56
+ return false;
57
+ }
58
+ supportsBip44Accounts() {
59
+ return false;
60
+ }
61
+ supportsOfflineSigning() {
62
+ return false;
63
+ }
64
+ supportsBroadcast() {
65
+ return true;
66
+ }
67
+ describePath(msg) {
68
+ switch (msg.coin) {
69
+ case "Ethereum":
70
+ return ethereum_1.describeETHPath(msg.path);
71
+ default:
72
+ throw new Error("Unsupported path");
73
+ }
74
+ }
75
+ ethNextAccountPath() {
76
+ return undefined;
77
+ }
78
+ ethSupportsNetwork(chainId) {
79
+ return __awaiter(this, void 0, void 0, function* () {
80
+ return [1, 10, 56, 100, 137, 43114].includes(chainId);
81
+ });
82
+ }
83
+ ethSupportsSecureTransfer() {
84
+ return __awaiter(this, void 0, void 0, function* () {
85
+ return false;
86
+ });
87
+ }
88
+ ethSupportsNativeShapeShift() {
89
+ return false;
90
+ }
91
+ ethSupportsEIP1559() {
92
+ return __awaiter(this, void 0, void 0, function* () {
93
+ return true;
94
+ });
95
+ }
96
+ ethGetAccountPaths(msg) {
97
+ const slip44 = hdwallet_core_1.slip44ByCoin(msg.coin);
98
+ if (slip44 === undefined)
99
+ return [];
100
+ return [
101
+ {
102
+ addressNList: [0x80000000 + 44, 0x80000000 + slip44, 0x80000000 + msg.accountIdx, 0, 0],
103
+ hardenedPath: [0x80000000 + 44, 0x80000000 + slip44, 0x80000000 + msg.accountIdx],
104
+ relPath: [0, 0],
105
+ description: "WalletConnectV2",
106
+ },
107
+ ];
108
+ }
109
+ }
110
+ exports.WalletConnectV2WalletInfo = WalletConnectV2WalletInfo;
111
+ class WalletConnectV2HDWallet {
112
+ constructor(provider) {
113
+ this._supportsETH = true;
114
+ this._supportsETHInfo = true;
115
+ this._supportsBTCInfo = false;
116
+ this._supportsBTC = false;
117
+ this._isWalletConnectV2 = true;
118
+ this._supportsEthSwitchChain = true;
119
+ this._supportsAvalanche = true;
120
+ this._supportsOptimism = true;
121
+ this._supportsBSC = true;
122
+ this._supportsPolygon = true;
123
+ this._supportsGnosis = true;
124
+ this._supportsArbitrum = true;
125
+ this.connected = false;
126
+ this.accounts = [];
127
+ this.provider = provider;
128
+ this.info = new WalletConnectV2WalletInfo();
129
+ }
130
+ getFeatures() {
131
+ return __awaiter(this, void 0, void 0, function* () {
132
+ return {};
133
+ });
134
+ }
135
+ isLocked() {
136
+ return __awaiter(this, void 0, void 0, function* () {
137
+ return false;
138
+ });
139
+ }
140
+ getVendor() {
141
+ return "WalletConnectV2";
142
+ }
143
+ getModel() {
144
+ return __awaiter(this, void 0, void 0, function* () {
145
+ return "WalletConnectV2";
146
+ });
147
+ }
148
+ getLabel() {
149
+ return __awaiter(this, void 0, void 0, function* () {
150
+ return "WalletConnectV2";
151
+ });
152
+ }
153
+ initialize() {
154
+ return __awaiter(this, void 0, void 0, function* () {
155
+ /** Display QR modal to connect */
156
+ yield this.provider.enable();
157
+ });
158
+ }
159
+ hasOnDevicePinEntry() {
160
+ return this.info.hasOnDevicePinEntry();
161
+ }
162
+ hasOnDevicePassphrase() {
163
+ return this.info.hasOnDevicePassphrase();
164
+ }
165
+ hasOnDeviceDisplay() {
166
+ return this.info.hasOnDeviceDisplay();
167
+ }
168
+ hasOnDeviceRecovery() {
169
+ return this.info.hasOnDeviceRecovery();
170
+ }
171
+ hasNativeShapeShift(srcCoin, dstCoin) {
172
+ return this.info.hasNativeShapeShift(srcCoin, dstCoin);
173
+ }
174
+ supportsBip44Accounts() {
175
+ return this.info.supportsBip44Accounts();
176
+ }
177
+ /**
178
+ * Supports Offline Signing
179
+ *
180
+ * Offline signing is supported when `signTransaction` does not broadcast
181
+ * the tx message. WalletConnect's core Connector implementation always
182
+ * makes a request, so offline signing is not supported.
183
+ */
184
+ supportsOfflineSigning() {
185
+ return this.info.supportsOfflineSigning();
186
+ }
187
+ supportsBroadcast() {
188
+ return this.info.supportsBroadcast();
189
+ }
190
+ clearSession() {
191
+ return __awaiter(this, void 0, void 0, function* () {
192
+ yield this.disconnect();
193
+ });
194
+ }
195
+ ping(msg) {
196
+ return __awaiter(this, void 0, void 0, function* () {
197
+ return { msg: msg.msg };
198
+ });
199
+ }
200
+ sendPin() {
201
+ return __awaiter(this, void 0, void 0, function* () {
202
+ return;
203
+ });
204
+ }
205
+ sendPassphrase() {
206
+ return __awaiter(this, void 0, void 0, function* () {
207
+ return;
208
+ });
209
+ }
210
+ sendCharacter() {
211
+ return __awaiter(this, void 0, void 0, function* () {
212
+ return;
213
+ });
214
+ }
215
+ sendWord() {
216
+ return __awaiter(this, void 0, void 0, function* () {
217
+ return;
218
+ });
219
+ }
220
+ cancel() {
221
+ return __awaiter(this, void 0, void 0, function* () {
222
+ return;
223
+ });
224
+ }
225
+ wipe() {
226
+ return __awaiter(this, void 0, void 0, function* () {
227
+ return;
228
+ });
229
+ }
230
+ reset() {
231
+ return __awaiter(this, void 0, void 0, function* () {
232
+ return;
233
+ });
234
+ }
235
+ recover() {
236
+ return __awaiter(this, void 0, void 0, function* () {
237
+ return;
238
+ });
239
+ }
240
+ loadDevice() {
241
+ return __awaiter(this, void 0, void 0, function* () {
242
+ return;
243
+ });
244
+ }
245
+ describePath(msg) {
246
+ return this.info.describePath(msg);
247
+ }
248
+ getPublicKeys() {
249
+ return __awaiter(this, void 0, void 0, function* () {
250
+ // Ethereum public keys are not exposed by the RPC API
251
+ return [];
252
+ });
253
+ }
254
+ isInitialized() {
255
+ return __awaiter(this, void 0, void 0, function* () {
256
+ return true;
257
+ });
258
+ }
259
+ disconnect() {
260
+ return __awaiter(this, void 0, void 0, function* () {
261
+ yield this.provider.disconnect();
262
+ });
263
+ }
264
+ ethSupportsNetwork(chainId = 1) {
265
+ return __awaiter(this, void 0, void 0, function* () {
266
+ return this.info.ethSupportsNetwork(chainId);
267
+ });
268
+ }
269
+ ethSupportsSecureTransfer() {
270
+ return __awaiter(this, void 0, void 0, function* () {
271
+ return this.info.ethSupportsSecureTransfer();
272
+ });
273
+ }
274
+ ethSupportsNativeShapeShift() {
275
+ return this.info.ethSupportsNativeShapeShift();
276
+ }
277
+ ethSupportsEIP1559() {
278
+ return __awaiter(this, void 0, void 0, function* () {
279
+ return this.info.ethSupportsEIP1559();
280
+ });
281
+ }
282
+ ethGetAccountPaths(msg) {
283
+ return this.info.ethGetAccountPaths(msg);
284
+ }
285
+ ethNextAccountPath() {
286
+ return this.info.ethNextAccountPath();
287
+ }
288
+ ethGetAddress() {
289
+ return __awaiter(this, void 0, void 0, function* () {
290
+ if (this.ethAddress) {
291
+ return this.ethAddress;
292
+ }
293
+ const address = yield ethereum_1.ethGetAddress(this.provider);
294
+ if (address) {
295
+ this.ethAddress = address;
296
+ return address;
297
+ }
298
+ else {
299
+ this.ethAddress = undefined;
300
+ return null;
301
+ }
302
+ });
303
+ }
304
+ /**
305
+ * Ethereum Signed Transaction
306
+ *
307
+ * @see https://docs.walletconnect.com/client-api#sign-transaction-eth_signtransaction
308
+ */
309
+ ethSignTx(msg) {
310
+ return __awaiter(this, void 0, void 0, function* () {
311
+ if (!this.ethAddress) {
312
+ throw new Error("No eth address");
313
+ }
314
+ return ethereum_1.ethSignTx(Object.assign(Object.assign({}, msg), { from: this.ethAddress }), this.provider);
315
+ });
316
+ }
317
+ /**
318
+ * Ethereum Send Transaction
319
+ *
320
+ * @see https://docs.walletconnect.com/client-api#send-transaction-eth_sendtransaction
321
+ */
322
+ ethSendTx(msg) {
323
+ return __awaiter(this, void 0, void 0, function* () {
324
+ if (!this.ethAddress) {
325
+ throw new Error("No eth address");
326
+ }
327
+ return ethereum_1.ethSendTx(Object.assign(Object.assign({}, msg), { from: this.ethAddress }), this.provider);
328
+ });
329
+ }
330
+ /**
331
+ * Ethereum Sign Message
332
+ *
333
+ * @see https://docs.walletconnect.com/client-api#sign-message-eth_sign
334
+ */
335
+ ethSignMessage(msg) {
336
+ return __awaiter(this, void 0, void 0, function* () {
337
+ if (!this.ethAddress) {
338
+ throw new Error("No eth address");
339
+ }
340
+ return ethereum_1.ethSignMessage({ data: msg.message, fromAddress: this.ethAddress }, this.provider);
341
+ });
342
+ }
343
+ ethVerifyMessage(msg) {
344
+ return __awaiter(this, void 0, void 0, function* () {
345
+ return ethereum_1.ethVerifyMessage(this.provider, msg);
346
+ });
347
+ }
348
+ getDeviceID() {
349
+ return __awaiter(this, void 0, void 0, function* () {
350
+ return "wc:" + (yield this.ethGetAddress());
351
+ });
352
+ }
353
+ getFirmwareVersion() {
354
+ return __awaiter(this, void 0, void 0, function* () {
355
+ return "WalletConnectV2";
356
+ });
357
+ }
358
+ }
359
+ exports.WalletConnectV2HDWallet = WalletConnectV2HDWallet;
360
+ //# sourceMappingURL=walletconnectV2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"walletconnectV2.js","sourceRoot":"","sources":["../src/walletconnectV2.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAoBA,gEAA4D;AAE5D,+DAAuC;AAEvC,yCAAoH;AAEpH,SAAgB,iBAAiB,CAAC,MAAgB;IAChD,OAAO,kBAAQ,CAAC,MAAM,CAAC,IAAK,MAAc,CAAC,kBAAkB,CAAC;AAChE,CAAC;AAFD,8CAEC;AAED;;;;;;;;;;;GAWG;AACH,MAAa,yBAAyB;IAAtC;QACW,qBAAgB,GAAG,IAAI,CAAC;QACxB,qBAAgB,GAAG,KAAK,CAAC;IA8EpC,CAAC;IA7EQ,SAAS;QACd,OAAO,iBAAiB,CAAC;IAC3B,CAAC;IAEM,mBAAmB;QACxB,OAAO,KAAK,CAAC;IACf,CAAC;IAEM,qBAAqB;QAC1B,OAAO,KAAK,CAAC;IACf,CAAC;IAEM,kBAAkB;QACvB,OAAO,KAAK,CAAC;IACf,CAAC;IAEM,mBAAmB;QACxB,OAAO,KAAK,CAAC;IACf,CAAC;IAEM,mBAAmB;QACxB,OA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AU,EAAE;gBACpB,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC;aACnC;YACD,OAAO,oBAAS,iCAAM,GAAG,KAAE,IAAI,EAAE,IAAI,CAAC,UAAU,KAAI,IAAI,CAAC,QAAQ,CAAC,CAAC;QACrE,CAAC;KAAA;IAED;;;;OAIG;IACU,SAAS,CAAC,GAAc;;YACnC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE;gBACpB,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC;aACnC;YACD,OAAO,oBAAS,iCAAM,GAAG,KAAE,IAAI,EAAE,IAAI,CAAC,UAAU,KAAI,IAAI,CAAC,QAAQ,CAAC,CAAC;QACrE,CAAC;KAAA;IAED;;;;OAIG;IACU,cAAc,CAAC,GAAmB;;YAC7C,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE;gBACpB,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC;aACnC;YACD,OAAO,yBAAc,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,CAAC,UAAU,EAAE,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC5F,CAAC;KAAA;IAEY,gBAAgB,CAAC,GAAqB;;YACjD,OAAO,2BAAgB,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;QAC9C,CAAC;KAAA;IAEY,WAAW;;YACtB,OAAO,KAAK,GAAG,CAAC,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC;QAC9C,CAAC;KAAA;IAEY,kBAAkB;;YAC7B,OAAO,iBAAiB,CAAC;QAC3B,CAAC;KAAA;CACF;AA5OD,0DA4OC"}
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@shapeshiftoss/hdwallet-walletconnectv2",
3
+ "version": "1.50.7",
4
+ "license": "MIT",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "main": "dist/index.js",
9
+ "source": "src/index.ts",
10
+ "types": "dist/index.d.ts",
11
+ "scripts": {
12
+ "build": "tsc --build",
13
+ "clean": "rm -rf dist tsconfig.tsbuildinfo",
14
+ "dev": "yarn tsc --build --watch",
15
+ "prepublishOnly": "yarn clean && yarn build"
16
+ },
17
+ "dependencies": {
18
+ "@shapeshiftoss/hdwallet-core": "1.50.7",
19
+ "@walletconnect/ethereum-provider": "^2.10.1",
20
+ "@walletconnect/modal": "^2.6.2",
21
+ "ethers": "^5.6.5"
22
+ },
23
+ "devDependencies": {
24
+ "typescript": "^4.3.2"
25
+ },
26
+ "gitHead": "3906298615b82287937d10bbff966f136cd13a50"
27
+ }
package/src/adapter.ts ADDED
@@ -0,0 +1,44 @@
1
+ import { Events, Keyring } from "@shapeshiftoss/hdwallet-core";
2
+ import { EthereumProvider } from "@walletconnect/ethereum-provider";
3
+ import { EthereumProviderOptions } from "@walletconnect/ethereum-provider/dist/types/EthereumProvider";
4
+
5
+ import { WalletConnectV2HDWallet } from "./walletconnectV2";
6
+
7
+ export class WalletConnectV2Adapter {
8
+ keyring: Keyring;
9
+ private readonly providerConfig: EthereumProviderOptions;
10
+
11
+ private constructor(keyring: Keyring, config: EthereumProviderOptions) {
12
+ this.keyring = keyring;
13
+ this.providerConfig = config;
14
+ }
15
+
16
+ public static useKeyring(keyring: Keyring, config: EthereumProviderOptions) {
17
+ return new WalletConnectV2Adapter(keyring, config);
18
+ }
19
+
20
+ public async initialize(): Promise<number> {
21
+ return Object.keys(this.keyring.wallets).length;
22
+ }
23
+
24
+ public async pairDevice(): Promise<WalletConnectV2HDWallet> {
25
+ try {
26
+ if (!this.providerConfig) {
27
+ throw new Error("WalletConnectV2 provider configuration not set.");
28
+ }
29
+
30
+ const provider = await EthereumProvider.init(this.providerConfig);
31
+ const wallet = new WalletConnectV2HDWallet(provider);
32
+
33
+ // Enable session (triggers QR Code modal)
34
+ await wallet.initialize();
35
+ const deviceID = await wallet.getDeviceID();
36
+ this.keyring.add(wallet, deviceID);
37
+ this.keyring.emit(["WalletConnectV2", deviceID, Events.CONNECT], deviceID);
38
+ return wallet;
39
+ } catch (error) {
40
+ console.error("Could not pair WalletConnectV2");
41
+ throw error;
42
+ }
43
+ }
44
+ }
@@ -0,0 +1,115 @@
1
+ import type {
2
+ BIP32Path,
3
+ ETHSignedMessage,
4
+ ETHSignedTx,
5
+ ETHSignTx,
6
+ ETHTxHash,
7
+ ETHVerifyMessage,
8
+ PathDescription,
9
+ } from "@shapeshiftoss/hdwallet-core";
10
+ import { addressNListToBIP32, slip44ByCoin } from "@shapeshiftoss/hdwallet-core";
11
+ import EthereumProvider from "@walletconnect/ethereum-provider";
12
+ import type { Bytes } from "ethers";
13
+ import { arrayify, isBytes } from "ethers/lib/utils";
14
+
15
+ const getUnsignedTxFromMessage = (msg: ETHSignTx & { from: string }) => {
16
+ const utxBase = {
17
+ from: msg.from,
18
+ to: msg.to,
19
+ value: msg.value,
20
+ data: msg.data,
21
+ chainId: msg.chainId,
22
+ nonce: msg.nonce,
23
+ gasLimit: msg.gasLimit,
24
+ };
25
+
26
+ return msg.maxFeePerGas
27
+ ? {
28
+ ...utxBase,
29
+ maxFeePerGas: msg.maxFeePerGas,
30
+ maxPriorityFeePerGas: msg.maxPriorityFeePerGas,
31
+ }
32
+ : { ...utxBase, gasPrice: msg.gasPrice };
33
+ };
34
+
35
+ export function describeETHPath(path: BIP32Path): PathDescription {
36
+ const pathStr = addressNListToBIP32(path);
37
+ const unknown: PathDescription = {
38
+ verbose: pathStr,
39
+ coin: "Ethereum",
40
+ isKnown: false,
41
+ };
42
+
43
+ if (path.length !== 5) return unknown;
44
+
45
+ if (path[0] !== 0x80000000 + 44) return unknown;
46
+
47
+ if (path[1] !== 0x80000000 + slip44ByCoin("Ethereum")) return unknown;
48
+
49
+ if ((path[2] & 0x80000000) >>> 0 !== 0x80000000) return unknown;
50
+
51
+ if (path[3] !== 0) return unknown;
52
+
53
+ if (path[4] !== 0) return unknown;
54
+
55
+ const index = path[2] & 0x7fffffff;
56
+ return {
57
+ verbose: `Ethereum Account #${index}`,
58
+ accountIdx: index,
59
+ wholeAccount: true,
60
+ coin: "Ethereum",
61
+ isKnown: true,
62
+ };
63
+ }
64
+
65
+ export async function ethSignTx(
66
+ args: ETHSignTx & { from: string },
67
+ provider: EthereumProvider
68
+ ): Promise<ETHSignedTx | null> {
69
+ const utx = getUnsignedTxFromMessage(args);
70
+ return await provider.request({ method: "eth_signTransaction", params: [utx] });
71
+ }
72
+
73
+ export async function ethSendTx(
74
+ msg: ETHSignTx & { from: string },
75
+ provider: EthereumProvider
76
+ ): Promise<ETHTxHash | null> {
77
+ const utx = getUnsignedTxFromMessage(msg);
78
+ const txHash: string = await provider.request({ method: "eth_sendTransaction", params: [utx] });
79
+ return txHash
80
+ ? {
81
+ hash: txHash,
82
+ }
83
+ : null;
84
+ }
85
+
86
+ export async function ethSignMessage(
87
+ args: { data: string | Bytes; fromAddress: string },
88
+ provider: EthereumProvider
89
+ ): Promise<ETHSignedMessage | null> {
90
+ const buffer = isBytes(args.data) ? Buffer.from(arrayify(args.data)) : Buffer.from(args.data);
91
+
92
+ return await provider.request({
93
+ method: "eth_sign",
94
+ params: [args.fromAddress, buffer],
95
+ });
96
+ }
97
+
98
+ export async function ethGetAddress(provider: EthereumProvider): Promise<string | null> {
99
+ try {
100
+ if (!(provider && provider.connected)) {
101
+ throw new Error("No WalletConnectV2 provider available.");
102
+ }
103
+ const ethAccounts: string[] = await provider.request({
104
+ method: "eth_accounts",
105
+ });
106
+ return ethAccounts[0];
107
+ } catch (error) {
108
+ console.error(error);
109
+ return null;
110
+ }
111
+ }
112
+
113
+ export async function ethVerifyMessage(provider: EthereumProvider, args: ETHVerifyMessage): Promise<boolean> {
114
+ return await provider.request({ method: "ethVerifyMessage", params: [args.message, args.signature] });
115
+ }
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./adapter";
2
+ export * from "./walletconnectV2";