@meshconnect/web-link-sdk 3.0.11 → 3.1.0-rc.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.
Files changed (52) hide show
  1. package/Link.js +173 -205
  2. package/package.json +6 -6
  3. package/utils/connectors/evm/chainConfigs.d.ts +2 -0
  4. package/utils/connectors/evm/chainConfigs.js +115 -0
  5. package/utils/connectors/evm/chainSwitching.d.ts +15 -0
  6. package/utils/connectors/evm/chainSwitching.js +242 -0
  7. package/utils/connectors/evm/index.d.ts +8 -0
  8. package/utils/connectors/evm/index.js +8 -0
  9. package/utils/connectors/evm/provider.d.ts +6 -0
  10. package/utils/connectors/evm/provider.js +13 -0
  11. package/utils/connectors/evm/signing.d.ts +1 -0
  12. package/utils/connectors/evm/signing.js +78 -0
  13. package/utils/connectors/evm/transactions.d.ts +9 -0
  14. package/utils/connectors/evm/transactions.js +201 -0
  15. package/utils/connectors/evm/types.d.ts +58 -0
  16. package/utils/connectors/evm/types.js +1 -0
  17. package/utils/connectors/evm/walletConnection.d.ts +20 -0
  18. package/utils/connectors/evm/walletConnection.js +161 -0
  19. package/utils/connectors/evm/walletDiscovery.d.ts +10 -0
  20. package/utils/connectors/evm/walletDiscovery.js +55 -0
  21. package/utils/connectors/solana/connection.d.ts +3 -0
  22. package/utils/connectors/solana/connection.js +94 -0
  23. package/utils/connectors/solana/index.d.ts +5 -0
  24. package/utils/connectors/solana/index.js +5 -0
  25. package/utils/connectors/solana/providerDiscovery.d.ts +3 -0
  26. package/utils/connectors/solana/providerDiscovery.js +75 -0
  27. package/utils/connectors/solana/signing.d.ts +1 -0
  28. package/utils/connectors/solana/signing.js +59 -0
  29. package/utils/connectors/solana/transaction.d.ts +2 -0
  30. package/utils/connectors/solana/transaction.js +158 -0
  31. package/utils/connectors/solana/types.d.ts +68 -0
  32. package/utils/connectors/solana/types.js +8 -0
  33. package/utils/event-types.d.ts +10 -2
  34. package/utils/event-types.js +2 -1
  35. package/utils/sdk-specs.d.ts +1 -0
  36. package/utils/sdk-specs.js +2 -1
  37. package/utils/types.d.ts +38 -29
  38. package/utils/version.d.ts +1 -1
  39. package/utils/version.js +1 -1
  40. package/utils/wallet/EVMWalletStrategy.d.ts +23 -0
  41. package/utils/wallet/EVMWalletStrategy.js +205 -0
  42. package/utils/wallet/SolanaWalletStrategy.d.ts +29 -0
  43. package/utils/wallet/SolanaWalletStrategy.js +194 -0
  44. package/utils/wallet/WalletStrategy.d.ts +45 -0
  45. package/utils/wallet/WalletStrategy.js +25 -0
  46. package/utils/wallet/WalletStrategyFactory.d.ts +15 -0
  47. package/utils/wallet/WalletStrategyFactory.js +31 -0
  48. package/utils/wallet/index.d.ts +4 -0
  49. package/utils/wallet/index.js +4 -0
  50. package/utils/wallet-browser-event-types.d.ts +16 -2
  51. package/utils/wagmiCoreConnectorsUtils.d.ts +0 -11
  52. package/utils/wagmiCoreConnectorsUtils.js +0 -396
@@ -0,0 +1,194 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ if (typeof b !== "function" && b !== null)
10
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
+ extendStatics(d, b);
12
+ function __() { this.constructor = d; }
13
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
+ };
15
+ })();
16
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
17
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18
+ return new (P || (P = Promise))(function (resolve, reject) {
19
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
20
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
21
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
22
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
23
+ });
24
+ };
25
+ var __generator = (this && this.__generator) || function (thisArg, body) {
26
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
27
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
28
+ function verb(n) { return function (v) { return step([n, v]); }; }
29
+ function step(op) {
30
+ if (f) throw new TypeError("Generator is already executing.");
31
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
32
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
33
+ if (y = 0, t) op = [op[0] & 2, t.value];
34
+ switch (op[0]) {
35
+ case 0: case 1: t = op; break;
36
+ case 4: _.label++; return { value: op[1], done: false };
37
+ case 5: _.label++; y = op[1]; op = [0]; continue;
38
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
39
+ default:
40
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
41
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
42
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
43
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
44
+ if (t[2]) _.ops.pop();
45
+ _.trys.pop(); continue;
46
+ }
47
+ op = body.call(thisArg, _);
48
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
49
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
50
+ }
51
+ };
52
+ import { BaseWalletStrategy } from './WalletStrategy';
53
+ import { connectToSolanaWallet, disconnectFromSolanaWallet, signSolanaMessage, sendSOLTransaction, findAvailableSolanaProviders } from '../connectors/solana';
54
+ var SolanaWalletStrategy = /** @class */ (function (_super) {
55
+ __extends(SolanaWalletStrategy, _super);
56
+ function SolanaWalletStrategy() {
57
+ return _super !== null && _super.apply(this, arguments) || this;
58
+ }
59
+ SolanaWalletStrategy.prototype.connect = function (payload) {
60
+ return __awaiter(this, void 0, void 0, function () {
61
+ var result, error_1;
62
+ return __generator(this, function (_a) {
63
+ switch (_a.label) {
64
+ case 0:
65
+ _a.trys.push([0, 2, , 3]);
66
+ return [4 /*yield*/, connectToSolanaWallet(payload.integrationName)];
67
+ case 1:
68
+ result = _a.sent();
69
+ if (result instanceof Error) {
70
+ throw result;
71
+ }
72
+ return [2 /*return*/, {
73
+ accounts: result.accounts,
74
+ chainId: result.chainId,
75
+ isConnected: result.isConnected
76
+ }];
77
+ case 2:
78
+ error_1 = _a.sent();
79
+ throw this.handleError(error_1, 'connect to Solana wallet');
80
+ case 3: return [2 /*return*/];
81
+ }
82
+ });
83
+ });
84
+ };
85
+ SolanaWalletStrategy.prototype.disconnect = function (payload) {
86
+ return __awaiter(this, void 0, void 0, function () {
87
+ var result, error_2;
88
+ return __generator(this, function (_a) {
89
+ switch (_a.label) {
90
+ case 0:
91
+ _a.trys.push([0, 2, , 3]);
92
+ return [4 /*yield*/, disconnectFromSolanaWallet(payload.walletName || 'Unknown Wallet')];
93
+ case 1:
94
+ result = _a.sent();
95
+ if (result instanceof Error) {
96
+ throw result;
97
+ }
98
+ return [3 /*break*/, 3];
99
+ case 2:
100
+ error_2 = _a.sent();
101
+ throw this.handleError(error_2, 'disconnect from Solana wallet');
102
+ case 3: return [2 /*return*/];
103
+ }
104
+ });
105
+ });
106
+ };
107
+ SolanaWalletStrategy.prototype.signMessage = function (payload) {
108
+ return __awaiter(this, void 0, void 0, function () {
109
+ var result, error_3;
110
+ return __generator(this, function (_a) {
111
+ switch (_a.label) {
112
+ case 0:
113
+ _a.trys.push([0, 2, , 3]);
114
+ return [4 /*yield*/, signSolanaMessage(payload.walletName || 'Unknown Wallet', payload.message)];
115
+ case 1:
116
+ result = _a.sent();
117
+ if (result instanceof Error) {
118
+ throw result;
119
+ }
120
+ return [2 /*return*/, result];
121
+ case 2:
122
+ error_3 = _a.sent();
123
+ throw this.handleError(error_3, 'sign Solana message');
124
+ case 3: return [2 /*return*/];
125
+ }
126
+ });
127
+ });
128
+ };
129
+ /**
130
+ * @note Solana doesn't support chain switching as it's a single-chain network
131
+ * This method is implemented to satisfy the interface but will always return mainnet (101)
132
+ */
133
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
134
+ SolanaWalletStrategy.prototype.switchChain = function (_payload) {
135
+ return __awaiter(this, void 0, void 0, function () {
136
+ return __generator(this, function (_a) {
137
+ return [2 /*return*/, {
138
+ chainId: '101',
139
+ accounts: []
140
+ }];
141
+ });
142
+ });
143
+ };
144
+ SolanaWalletStrategy.prototype.sendNativeTransfer = function (payload) {
145
+ return __awaiter(this, void 0, void 0, function () {
146
+ var result, error_4;
147
+ return __generator(this, function (_a) {
148
+ switch (_a.label) {
149
+ case 0:
150
+ _a.trys.push([0, 2, , 3]);
151
+ return [4 /*yield*/, sendSOLTransaction({
152
+ toAddress: payload.toAddress,
153
+ amount: BigInt(payload.amount * Math.pow(10, payload.decimalPlaces)),
154
+ fromAddress: payload.account,
155
+ blockhash: payload.blockhash || '',
156
+ walletName: payload.walletName || ''
157
+ })];
158
+ case 1:
159
+ result = _a.sent();
160
+ if (typeof result === 'string') {
161
+ return [2 /*return*/, result];
162
+ }
163
+ throw result;
164
+ case 2:
165
+ error_4 = _a.sent();
166
+ throw this.handleError(error_4, 'send Solana native transfer');
167
+ case 3: return [2 /*return*/];
168
+ }
169
+ });
170
+ });
171
+ };
172
+ /**
173
+ * @note This feature is not yet implemented for Solana
174
+ * @throws {Error} Always throws with a "not implemented" message
175
+ */
176
+ SolanaWalletStrategy.prototype.sendSmartContractInteraction = function (
177
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
178
+ _payload) {
179
+ return __awaiter(this, void 0, void 0, function () {
180
+ return __generator(this, function (_a) {
181
+ throw new Error('NOT_IMPLEMENTED: Solana smart contract interactions are not yet supported');
182
+ });
183
+ });
184
+ };
185
+ SolanaWalletStrategy.prototype.getProviders = function () {
186
+ var solanaProviderMap = findAvailableSolanaProviders();
187
+ return Object.keys(solanaProviderMap).map(function (id) { return ({
188
+ id: id,
189
+ type: 'solana'
190
+ }); });
191
+ };
192
+ return SolanaWalletStrategy;
193
+ }(BaseWalletStrategy));
194
+ export { SolanaWalletStrategy };
@@ -0,0 +1,45 @@
1
+ import { WalletBrowserPayload, SignRequestPayload, ChainSwitchPayload, TransferPayload, SmartContractPayload, DisconnectPayload } from '../types';
2
+ export interface WalletStrategy {
3
+ connect(payload: WalletBrowserPayload): Promise<{
4
+ accounts: string[];
5
+ chainId: string | number;
6
+ isConnected: boolean;
7
+ }>;
8
+ disconnect(payload: DisconnectPayload): Promise<void>;
9
+ signMessage(payload: SignRequestPayload): Promise<string>;
10
+ switchChain(payload: ChainSwitchPayload): Promise<{
11
+ chainId: number | string;
12
+ accounts: string[];
13
+ }>;
14
+ sendNativeTransfer(payload: TransferPayload): Promise<string>;
15
+ sendSmartContractInteraction(payload: SmartContractPayload): Promise<string>;
16
+ getProviders(): {
17
+ id: string;
18
+ type: string;
19
+ name?: string;
20
+ icon?: string;
21
+ }[];
22
+ }
23
+ export declare abstract class BaseWalletStrategy implements WalletStrategy {
24
+ abstract connect(payload: WalletBrowserPayload): Promise<{
25
+ accounts: string[];
26
+ chainId: string | number;
27
+ isConnected: boolean;
28
+ }>;
29
+ abstract disconnect(payload: DisconnectPayload): Promise<void>;
30
+ abstract signMessage(payload: SignRequestPayload): Promise<string>;
31
+ abstract switchChain(payload: ChainSwitchPayload): Promise<{
32
+ chainId: number | string;
33
+ accounts: string[];
34
+ }>;
35
+ abstract sendNativeTransfer(payload: TransferPayload): Promise<string>;
36
+ abstract sendSmartContractInteraction(payload: SmartContractPayload): Promise<string>;
37
+ abstract getProviders(): {
38
+ id: string;
39
+ type: string;
40
+ name?: string;
41
+ icon?: string;
42
+ }[];
43
+ protected handleError(error: unknown, operation: string): Error;
44
+ protected isUserRejection(error: any): boolean;
45
+ }
@@ -0,0 +1,25 @@
1
+ var BaseWalletStrategy = /** @class */ (function () {
2
+ function BaseWalletStrategy() {
3
+ }
4
+ BaseWalletStrategy.prototype.handleError = function (error, operation) {
5
+ console.error("".concat(operation, " error:"), error);
6
+ if (error instanceof Error) {
7
+ return error;
8
+ }
9
+ return new Error("Failed to ".concat(operation));
10
+ };
11
+ BaseWalletStrategy.prototype.isUserRejection = function (error) {
12
+ var _a;
13
+ if (!error)
14
+ return false;
15
+ var message = ((_a = error.message) === null || _a === void 0 ? void 0 : _a.toLowerCase()) || '';
16
+ //4001 - user reject, -32603 internal error
17
+ var errorCodes = [4001, -32603];
18
+ return (message.includes('user rejected') ||
19
+ message.includes('declined') ||
20
+ message.includes('cancelled') ||
21
+ errorCodes.includes(error.code));
22
+ };
23
+ return BaseWalletStrategy;
24
+ }());
25
+ export { BaseWalletStrategy };
@@ -0,0 +1,15 @@
1
+ import { WalletStrategy } from './WalletStrategy';
2
+ export type NetworkType = 'evm' | 'solana';
3
+ export declare class WalletStrategyFactory {
4
+ private static instance;
5
+ private strategies;
6
+ private constructor();
7
+ static getInstance(): WalletStrategyFactory;
8
+ getStrategy(networkType: NetworkType): WalletStrategy;
9
+ getAllProviders(): {
10
+ id: string;
11
+ type: string;
12
+ name?: string;
13
+ icon?: string;
14
+ }[];
15
+ }
@@ -0,0 +1,31 @@
1
+ import { EVMWalletStrategy } from './EVMWalletStrategy';
2
+ import { SolanaWalletStrategy } from './SolanaWalletStrategy';
3
+ var WalletStrategyFactory = /** @class */ (function () {
4
+ function WalletStrategyFactory() {
5
+ this.strategies = new Map();
6
+ this.strategies.set('evm', new EVMWalletStrategy());
7
+ this.strategies.set('solana', new SolanaWalletStrategy());
8
+ }
9
+ WalletStrategyFactory.getInstance = function () {
10
+ if (!WalletStrategyFactory.instance) {
11
+ WalletStrategyFactory.instance = new WalletStrategyFactory();
12
+ }
13
+ return WalletStrategyFactory.instance;
14
+ };
15
+ WalletStrategyFactory.prototype.getStrategy = function (networkType) {
16
+ var strategy = this.strategies.get(networkType);
17
+ if (!strategy) {
18
+ throw new Error("No strategy found for network type: ".concat(networkType));
19
+ }
20
+ return strategy;
21
+ };
22
+ WalletStrategyFactory.prototype.getAllProviders = function () {
23
+ var allProviders = [];
24
+ this.strategies.forEach(function (strategy) {
25
+ allProviders.push.apply(allProviders, strategy.getProviders());
26
+ });
27
+ return allProviders;
28
+ };
29
+ return WalletStrategyFactory;
30
+ }());
31
+ export { WalletStrategyFactory };
@@ -0,0 +1,4 @@
1
+ export * from './WalletStrategy';
2
+ export * from './EVMWalletStrategy';
3
+ export * from './SolanaWalletStrategy';
4
+ export * from './WalletStrategyFactory';
@@ -0,0 +1,4 @@
1
+ export * from './WalletStrategy';
2
+ export * from './EVMWalletStrategy';
3
+ export * from './SolanaWalletStrategy';
4
+ export * from './WalletStrategyFactory';
@@ -1,5 +1,6 @@
1
1
  export type WalletBrowserEventType = WalletBrowserInjectedWalletSelected | WalletBrowserSignRequest | WalletBrowserChainSwitchRequest | WalletBrowserTransferBalanceRequest | WalletBrowserNativeTransferRequest | WalletBrowserNonNativeTransferRequest | WalletBrowserNativeSmartDeposit | WalletBrowserNonNativeSmartDeposit | WalletBrowserDisconnect;
2
2
  declare const WALLET_BROWSER_EVENT_TYPE_KEYS: readonly ["walletBrowserInjectedWalletSelected", "walletBrowserSignRequest", "walletBrowserChainSwitchRequest", "walletBrowserTransferBalanceRequest", "walletBrowserNativeTransferRequest", "walletBrowserNonNativeTransferRequest", "walletBrowserNativeSmartDeposit", "walletBrowserNonNativeSmartDeposit", "walletBrowserDisconnect"];
3
+ export type NetworkType = 'unknown' | 'evm' | 'solana' | 'bitcoin' | 'cardano' | 'tron' | 'avalancheX' | 'tezos' | 'dogecoin' | 'ripple' | 'stellar' | 'litecoin' | 'sui' | 'aptos' | 'tvm';
3
4
  export type WalletBrowserEventTypeKeys = (typeof WALLET_BROWSER_EVENT_TYPE_KEYS)[number];
4
5
  export declare function isWalletBrowserEventTypeKey(key: string): key is WalletBrowserEventTypeKeys;
5
6
  interface WalletBrowserEventBase {
@@ -9,6 +10,8 @@ export interface WalletBrowserInjectedWalletSelected extends WalletBrowserEventB
9
10
  type: 'walletBrowserInjectedWalletSelected';
10
11
  payload: {
11
12
  integrationName: string;
13
+ networkType?: string;
14
+ targetChainId?: number;
12
15
  };
13
16
  }
14
17
  export interface WalletBrowserSignRequest extends WalletBrowserEventBase {
@@ -16,12 +19,15 @@ export interface WalletBrowserSignRequest extends WalletBrowserEventBase {
16
19
  payload: {
17
20
  address: `0x${string}`;
18
21
  message: string;
22
+ walletName?: string;
23
+ networkType?: NetworkType;
19
24
  };
20
25
  }
21
26
  export interface WalletBrowserChainSwitchRequest extends WalletBrowserEventBase {
22
27
  type: 'walletBrowserChainSwitchRequest';
23
28
  payload: {
24
29
  chainId: number;
30
+ networkType: NetworkType;
25
31
  };
26
32
  }
27
33
  export interface WalletBrowserTransferBalanceRequest extends WalletBrowserEventBase {
@@ -39,14 +45,18 @@ export interface WalletBrowserNativeTransferRequest extends WalletBrowserEventBa
39
45
  decimalPlaces: number;
40
46
  chainId: number;
41
47
  account: string;
48
+ network: string;
49
+ blockhash?: string;
50
+ walletName?: string;
42
51
  };
43
52
  }
44
53
  interface SmartContractPayload {
45
54
  address: string;
46
55
  abi: string;
47
56
  functionName: string;
48
- args: any[];
49
- value?: bigint;
57
+ args: unknown[];
58
+ account: string;
59
+ value?: string;
50
60
  }
51
61
  export interface WalletBrowserNonNativeTransferRequest extends WalletBrowserEventBase {
52
62
  type: 'walletBrowserNonNativeTransferRequest';
@@ -62,5 +72,9 @@ export interface WalletBrowserNonNativeSmartDeposit extends WalletBrowserEventBa
62
72
  }
63
73
  export interface WalletBrowserDisconnect extends WalletBrowserEventBase {
64
74
  type: 'walletBrowserDisconnect';
75
+ payload?: {
76
+ networkType?: NetworkType;
77
+ walletName?: string;
78
+ };
65
79
  }
66
80
  export {};
@@ -1,11 +0,0 @@
1
- import { type GetBalanceReturnType, type ConnectReturnType } from '@wagmi/core';
2
- import { WagmiInjectedConnectorData, Abi } from './types';
3
- import { Hash, Chain } from 'viem';
4
- export declare const getWagmiCoreInjectedData: () => Promise<WagmiInjectedConnectorData[] | Error>;
5
- export declare const connectToSpecificWallet: (walletName: string) => Promise<ConnectReturnType | Error>;
6
- export declare const signedMessage: (address: `0x${string}`, message: string) => Promise<Hash | Error>;
7
- export declare const walletBalance: (account: string, chainId: number) => Promise<GetBalanceReturnType | Error>;
8
- export declare const switchChainFromSDK: (chainId: number) => Promise<Chain | Error>;
9
- export declare const sendTransactionFromSDK: (toAddress: string, amount: number, decimalPlaces: number, chainId: number, account: string) => Promise<Hash | Error>;
10
- export declare const sendNonNativeTransactionFromSDK: (address: string, abi: Abi, functionName: string, args: any[], value?: bigint) => Promise<Hash | Error>;
11
- export declare const disconnectAllAccounts: () => Promise<void | Error>;