@meshconnect/web-link-sdk 3.1.5 → 3.1.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.
package/Link.js CHANGED
@@ -158,7 +158,7 @@ function handleLinkEvent(event) {
158
158
  }
159
159
  function handleWalletBrowserEvent(event) {
160
160
  return __awaiter(this, void 0, void 0, function () {
161
- var walletFactory, _a, payload, networkType, strategy, result, error_1, payload, networkType, strategy, result, error_2, payload, networkType, strategy, result, error_3, payload, networkType, strategy, result, error_4, payload, getResponseType, strategy, result, responseType, error_5, errorType, payload, networkType, strategy, error_6;
161
+ var walletFactory, _a, payload, networkType, strategy, result, error_1, payload, networkType, strategy, result, error_2, payload, networkType, strategy, result, error_3, payload, networkType, strategy, result, error_4, payload, getResponseType, networkType, strategy, result, responseType, error_5, errorType, payload, networkType, strategy, error_6;
162
162
  var _b;
163
163
  return __generator(this, function (_c) {
164
164
  switch (_c.label) {
@@ -283,7 +283,8 @@ function handleWalletBrowserEvent(event) {
283
283
  _c.label = 22;
284
284
  case 22:
285
285
  _c.trys.push([22, 24, , 25]);
286
- strategy = walletFactory.getStrategy('evm');
286
+ networkType = (payload.address.startsWith('0x') ? 'evm' : 'solana');
287
+ strategy = walletFactory.getStrategy(networkType);
287
288
  return [4 /*yield*/, strategy.sendSmartContractInteraction(payload)];
288
289
  case 23:
289
290
  result = _c.sent();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meshconnect/web-link-sdk",
3
- "version": "3.1.5",
3
+ "version": "3.1.7",
4
4
  "description": "A client-side JS library for integrating with Mesh Connect",
5
5
  "exports": "./index.js",
6
6
  "license": "MIT",
@@ -23,7 +23,7 @@
23
23
  },
24
24
  "dependencies": {
25
25
  "@meshconnect/node-api": "^2.0.19",
26
- "@solana/web3.js": "^1.91.1",
26
+ "@meshconnect/solana-web3.js": "^1.0.4",
27
27
  "bs58": "^5.0.0",
28
28
  "buffer": "^6.0.3",
29
29
  "ethers": "^6.11.1"
@@ -51,7 +51,7 @@
51
51
  ]
52
52
  },
53
53
  "transformIgnorePatterns": [
54
- "/node_modules/(?!(@solana/web3.js|uuid|jayson|superstruct|@noble|@meshconnect|ethers)/)"
54
+ "/node_modules/(?!(@meshconnect/solana-web3.js|uuid|jayson|superstruct|@noble|@meshconnect|ethers)/)"
55
55
  ],
56
56
  "testEnvironmentOptions": {
57
57
  "url": "http://localhost/"
@@ -60,4 +60,4 @@
60
60
  "module": "./index.js",
61
61
  "main": "./index.js",
62
62
  "types": "./index.d.ts"
63
- }
63
+ }
@@ -1,2 +1,18 @@
1
- import { TransactionConfig } from './types';
1
+ import { PublicKey, VersionedTransaction, TransactionInstruction } from '@meshconnect/solana-web3.js';
2
+ import { TransactionConfig, SolanaProvider } from './types';
3
+ export declare function getAssociatedTokenAddress(mint: PublicKey, owner: PublicKey): Promise<PublicKey>;
4
+ export declare function createSPLTransferInstruction({ fromTokenAccount, toTokenAccount, owner, amount }: {
5
+ fromTokenAccount: PublicKey;
6
+ toTokenAccount: PublicKey;
7
+ owner: PublicKey;
8
+ amount: bigint;
9
+ }): TransactionInstruction;
10
+ export declare function createTransferTransaction(config: {
11
+ fromAddress: string;
12
+ toAddress: string;
13
+ amount: bigint;
14
+ tokenMint?: string;
15
+ blockhash: string;
16
+ }): Promise<VersionedTransaction>;
17
+ export declare function handleManualSignAndSend(transaction: VersionedTransaction, provider: SolanaProvider): Promise<string>;
2
18
  export declare const sendSOLTransaction: (config: TransactionConfig) => Promise<string>;
@@ -34,125 +34,168 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
34
34
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
35
  }
36
36
  };
37
- import { Connection, PublicKey, SystemProgram, Transaction } from '@solana/web3.js';
38
- import bs58 from 'bs58';
37
+ import { PublicKey, SystemProgram, TransactionMessage, VersionedTransaction, TransactionInstruction } from '@meshconnect/solana-web3.js';
39
38
  import { getSolanaProvider } from './providerDiscovery';
40
- var QUICKNODE_RPC = 'https://alien-newest-vineyard.solana-mainnet.quiknode.pro/ebe5e35661d7edb7a5e48ab84bd9d477e472a40b/';
39
+ var TOKEN_PROGRAM_ID = new PublicKey('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA');
40
+ var ASSOCIATED_TOKEN_PROGRAM_ID = new PublicKey('ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL');
41
41
  var isUserRejection = function (error) {
42
- if (!error)
42
+ if (!error || typeof error !== 'object')
43
43
  return false;
44
- var message = ((error === null || error === void 0 ? void 0 : error.message) || '').toLowerCase();
44
+ var err = error;
45
+ var message = (err.message || '').toLowerCase();
45
46
  return (message.includes('user rejected') ||
46
47
  message.includes('declined') ||
47
48
  message.includes('cancelled') ||
48
49
  message.includes('denied') ||
49
- (error === null || error === void 0 ? void 0 : error.code) === 4001);
50
+ err.code === 4001);
50
51
  };
51
- var standardizeSignature = function (rawSignature) {
52
- // First ensure we have a string
53
- var signature = typeof rawSignature === 'string' ? rawSignature : bs58.encode(rawSignature);
54
- // If signature is longer than standard 88 chars, decode and re-encode
55
- if (signature.length > 88) {
56
- try {
57
- var bytes = bs58.decode(signature);
58
- var truncatedBytes = bytes.slice(0, 64);
59
- signature = bs58.encode(truncatedBytes);
60
- }
61
- catch (e) {
62
- console.error('Failed to normalize signature:', e);
63
- }
64
- }
65
- return signature;
66
- };
67
- var createTransferTransaction = function (config) {
68
- var transaction = new Transaction().add(SystemProgram.transfer({
69
- fromPubkey: new PublicKey(config.fromAddress),
70
- toPubkey: new PublicKey(config.toAddress),
71
- lamports: config.amount
72
- }));
73
- transaction.recentBlockhash = config.blockhash;
74
- transaction.feePayer = new PublicKey(config.fromAddress);
75
- return transaction;
76
- };
77
- var handleManualSignAndSend = function (transaction, provider) { return __awaiter(void 0, void 0, void 0, function () {
78
- var signedTx, connection, rawSignature, error_1;
79
- return __generator(this, function (_a) {
80
- switch (_a.label) {
81
- case 0:
82
- _a.trys.push([0, 3, , 4]);
83
- return [4 /*yield*/, provider.signTransaction(transaction)];
84
- case 1:
85
- signedTx = _a.sent();
86
- connection = new Connection(QUICKNODE_RPC);
87
- return [4 /*yield*/, connection.sendRawTransaction(signedTx.serialize(), {
88
- skipPreflight: false,
89
- maxRetries: 3,
90
- preflightCommitment: 'confirmed'
91
- })];
92
- case 2:
93
- rawSignature = _a.sent();
94
- return [2 /*return*/, standardizeSignature(rawSignature)];
95
- case 3:
96
- error_1 = _a.sent();
97
- if (isUserRejection(error_1)) {
98
- throw new Error('Transaction was rejected by user');
99
- }
100
- throw error_1;
101
- case 4: return [2 /*return*/];
102
- }
52
+ export function getAssociatedTokenAddress(mint, owner) {
53
+ return __awaiter(this, void 0, void 0, function () {
54
+ var address;
55
+ return __generator(this, function (_a) {
56
+ switch (_a.label) {
57
+ case 0: return [4 /*yield*/, PublicKey.findProgramAddress([owner.toBuffer(), TOKEN_PROGRAM_ID.toBuffer(), mint.toBuffer()], ASSOCIATED_TOKEN_PROGRAM_ID)];
58
+ case 1:
59
+ address = (_a.sent())[0];
60
+ return [2 /*return*/, address];
61
+ }
62
+ });
103
63
  });
104
- }); };
64
+ }
65
+ export function createSPLTransferInstruction(_a) {
66
+ var fromTokenAccount = _a.fromTokenAccount, toTokenAccount = _a.toTokenAccount, owner = _a.owner, amount = _a.amount;
67
+ var data = Buffer.alloc(9);
68
+ data[0] = 3; // Transfer instruction
69
+ data.writeBigUInt64LE(amount, 1);
70
+ return new TransactionInstruction({
71
+ keys: [
72
+ { pubkey: fromTokenAccount, isSigner: false, isWritable: true },
73
+ { pubkey: toTokenAccount, isSigner: false, isWritable: true },
74
+ { pubkey: owner, isSigner: true, isWritable: false }
75
+ ],
76
+ programId: TOKEN_PROGRAM_ID,
77
+ data: data
78
+ });
79
+ }
80
+ export function createTransferTransaction(config) {
81
+ return __awaiter(this, void 0, void 0, function () {
82
+ var fromPubkey, toPubkey, instruction, tokenMintPubkey, fromTokenAccount, toTokenAccount, messageV0;
83
+ return __generator(this, function (_a) {
84
+ switch (_a.label) {
85
+ case 0:
86
+ fromPubkey = new PublicKey(config.fromAddress);
87
+ toPubkey = new PublicKey(config.toAddress);
88
+ if (!!config.tokenMint) return [3 /*break*/, 1];
89
+ // Native SOL transfer
90
+ instruction = SystemProgram.transfer({
91
+ fromPubkey: fromPubkey,
92
+ toPubkey: toPubkey,
93
+ lamports: Number(config.amount)
94
+ });
95
+ return [3 /*break*/, 4];
96
+ case 1:
97
+ tokenMintPubkey = new PublicKey(config.tokenMint);
98
+ return [4 /*yield*/, getAssociatedTokenAddress(tokenMintPubkey, fromPubkey)];
99
+ case 2:
100
+ fromTokenAccount = _a.sent();
101
+ return [4 /*yield*/, getAssociatedTokenAddress(tokenMintPubkey, toPubkey)];
102
+ case 3:
103
+ toTokenAccount = _a.sent();
104
+ instruction = createSPLTransferInstruction({
105
+ fromTokenAccount: fromTokenAccount,
106
+ toTokenAccount: toTokenAccount,
107
+ owner: fromPubkey,
108
+ amount: BigInt(config.amount)
109
+ });
110
+ _a.label = 4;
111
+ case 4:
112
+ messageV0 = new TransactionMessage({
113
+ payerKey: fromPubkey,
114
+ recentBlockhash: config.blockhash,
115
+ instructions: [instruction]
116
+ }).compileToV0Message();
117
+ return [2 /*return*/, new VersionedTransaction(messageV0)];
118
+ }
119
+ });
120
+ });
121
+ }
122
+ export function handleManualSignAndSend(transaction, provider) {
123
+ return __awaiter(this, void 0, void 0, function () {
124
+ var signature, signedTransaction, signature, error_1;
125
+ var _a;
126
+ return __generator(this, function (_b) {
127
+ switch (_b.label) {
128
+ case 0:
129
+ _b.trys.push([0, 6, , 7]);
130
+ if (!provider.signAndSendTransaction) return [3 /*break*/, 2];
131
+ return [4 /*yield*/, provider.signAndSendTransaction(transaction)];
132
+ case 1:
133
+ signature = (_b.sent()).signature;
134
+ return [2 /*return*/, signature];
135
+ case 2: return [4 /*yield*/, provider.signTransaction(transaction)];
136
+ case 3:
137
+ signedTransaction = _b.sent();
138
+ if (!provider.sendTransaction) {
139
+ throw new Error('Provider does not support sendTransaction');
140
+ }
141
+ return [4 /*yield*/, provider.sendTransaction(signedTransaction)];
142
+ case 4:
143
+ signature = _b.sent();
144
+ return [2 /*return*/, signature];
145
+ case 5: return [3 /*break*/, 7];
146
+ case 6:
147
+ error_1 = _b.sent();
148
+ console.error('Error in handleManualSignAndSend:', error_1);
149
+ if (error_1 instanceof Error && ((_a = error_1.message) === null || _a === void 0 ? void 0 : _a.includes('User rejected'))) {
150
+ throw new Error('Transaction was rejected by user');
151
+ }
152
+ throw error_1;
153
+ case 7: return [2 /*return*/];
154
+ }
155
+ });
156
+ });
157
+ }
105
158
  export var sendSOLTransaction = function (config) { return __awaiter(void 0, void 0, void 0, function () {
106
- var provider, transaction, isManualWallet, error_2, signature, error_3, error_4;
159
+ var provider, transaction, isManualWallet, signature, error_2, error_3;
107
160
  return __generator(this, function (_a) {
108
161
  switch (_a.label) {
109
162
  case 0:
110
- _a.trys.push([0, 9, , 10]);
163
+ _a.trys.push([0, 8, , 9]);
111
164
  provider = getSolanaProvider(config.walletName);
112
- transaction = createTransferTransaction(config);
165
+ return [4 /*yield*/, createTransferTransaction(config)];
166
+ case 1:
167
+ transaction = _a.sent();
113
168
  isManualWallet = provider.isTrust ||
114
169
  provider.isTrustWallet ||
115
170
  config.walletName.toLowerCase().includes('trust');
116
- if (!isManualWallet) return [3 /*break*/, 4];
117
- _a.label = 1;
118
- case 1:
119
- _a.trys.push([1, 3, , 4]);
171
+ if (!isManualWallet) return [3 /*break*/, 3];
120
172
  return [4 /*yield*/, handleManualSignAndSend(transaction, provider)];
121
173
  case 2: return [2 /*return*/, _a.sent()];
122
174
  case 3:
123
- error_2 = _a.sent();
124
- if (isUserRejection(error_2)) {
125
- throw new Error('Transaction was rejected by user');
126
- }
127
- throw error_2;
175
+ if (!provider.signAndSendTransaction) return [3 /*break*/, 7];
176
+ _a.label = 4;
128
177
  case 4:
129
- if (!provider.signAndSendTransaction) return [3 /*break*/, 8];
130
- _a.label = 5;
131
- case 5:
132
- _a.trys.push([5, 7, , 8]);
178
+ _a.trys.push([4, 6, , 7]);
133
179
  return [4 /*yield*/, provider.signAndSendTransaction(transaction)];
134
- case 6:
180
+ case 5:
135
181
  signature = (_a.sent()).signature;
136
182
  return [2 /*return*/, signature];
137
- case 7:
138
- error_3 = _a.sent();
139
- if (isUserRejection(error_3)) {
183
+ case 6:
184
+ error_2 = _a.sent();
185
+ if (isUserRejection(error_2)) {
140
186
  throw new Error('Transaction was rejected by user');
141
187
  }
142
- // For other errors, fall back to manual sign and send
143
188
  return [2 /*return*/, handleManualSignAndSend(transaction, provider)];
144
- case 8:
145
- // If no signAndSendTransaction available, use manual method
146
- return [2 /*return*/, handleManualSignAndSend(transaction, provider)];
147
- case 9:
148
- error_4 = _a.sent();
149
- if (isUserRejection(error_4)) {
189
+ case 7: return [2 /*return*/, handleManualSignAndSend(transaction, provider)];
190
+ case 8:
191
+ error_3 = _a.sent();
192
+ if (isUserRejection(error_3)) {
150
193
  throw new Error('Transaction was rejected by user');
151
194
  }
152
- throw error_4 instanceof Error
153
- ? error_4
195
+ throw error_3 instanceof Error
196
+ ? error_3
154
197
  : new Error("Failed to send SOL transaction with ".concat(config.walletName, " wallet"));
155
- case 10: return [2 /*return*/];
198
+ case 9: return [2 /*return*/];
156
199
  }
157
200
  });
158
201
  }); };
@@ -1,4 +1,4 @@
1
- import { Transaction } from '@solana/web3.js';
1
+ import { Transaction, VersionedTransaction } from '@meshconnect/solana-web3.js';
2
2
  export declare enum SolanaWalletType {
3
3
  PHANTOM = "phantom",
4
4
  SOLFLARE = "solflare",
@@ -31,11 +31,11 @@ export interface SolanaProvider {
31
31
  signMessage(message: Uint8Array): Promise<{
32
32
  signature: Uint8Array;
33
33
  }>;
34
- signTransaction(transaction: Transaction): Promise<Transaction>;
35
- signAndSendTransaction?(transaction: Transaction): Promise<{
34
+ signTransaction(transaction: Transaction | VersionedTransaction): Promise<Transaction | VersionedTransaction>;
35
+ signAndSendTransaction?(transaction: Transaction | VersionedTransaction): Promise<{
36
36
  signature: string;
37
37
  }>;
38
- sendTransaction?(transaction: Transaction): Promise<string>;
38
+ sendTransaction?(transaction: Transaction | VersionedTransaction): Promise<string>;
39
39
  }
40
40
  export interface WindowWithSolanaProviders extends Window {
41
41
  solana?: SolanaProvider & {
@@ -65,4 +65,7 @@ export interface TransactionConfig {
65
65
  fromAddress: string;
66
66
  blockhash: string;
67
67
  walletName: string;
68
+ tokenMint?: string;
69
+ tokenProgram?: string;
70
+ tokenDecimals?: number;
68
71
  }
package/utils/popup.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { Language } from './types';
1
2
  export declare const iframeId = "mesh-link-popup__iframe";
2
3
  export declare function removePopup(): void;
3
- export declare function addPopup(iframeLink: string, language: string | undefined): void;
4
+ export declare function addPopup(iframeLink: string, language: Language | undefined): void;
package/utils/popup.js CHANGED
@@ -19,9 +19,7 @@ export function addPopup(iframeLink, language) {
19
19
  var style = getLinkStyle(iframeLink);
20
20
  styleElement.textContent = getStylesContent(style);
21
21
  window.document.head.appendChild(styleElement);
22
- if (language) {
23
- iframeLink = "".concat(iframeLink).concat(iframeLink.includes('?') ? '&' : '?', "lng=").concat(language);
24
- }
22
+ iframeLink = "".concat(iframeLink).concat(iframeLink.includes('?') ? '&' : '?', "lng=").concat(language || 'en');
25
23
  var popupRootElement = document.createElement('div');
26
24
  popupRootElement.id = popupId;
27
25
  var popupBackdropElement = document.createElement('div');
package/utils/types.d.ts CHANGED
@@ -103,11 +103,14 @@ export interface SmartContractPayload {
103
103
  args: unknown[];
104
104
  account: string;
105
105
  value?: string;
106
+ walletName?: string;
107
+ blockhash?: string;
106
108
  }
107
109
  export interface DisconnectPayload {
108
110
  networkType?: string;
109
111
  walletName?: string;
110
112
  }
113
+ export type Language = 'en' | 'ru';
111
114
  export interface LinkOptions {
112
115
  /**
113
116
  * Client ID that can be obtained at https://dashboard.meshconnect.com/company/keys
@@ -143,9 +146,9 @@ export interface LinkOptions {
143
146
  */
144
147
  transferDestinationTokens?: IntegrationAccessToken[];
145
148
  /**
146
- * Link UI language. Right now only 'en' is supported.
149
+ * Link UI language. Supported: 'en', 'ru'.
147
150
  */
148
- language?: 'en';
151
+ language?: Language;
149
152
  }
150
153
  export interface LinkStyle {
151
154
  ir: number;
@@ -1 +1 @@
1
- export declare const sdkVersion = "3.1.5";
1
+ export declare const sdkVersion = "3.1.6";
package/utils/version.js CHANGED
@@ -1 +1 @@
1
- export var sdkVersion = '3.1.5';
1
+ export var sdkVersion = '3.1.6';
@@ -17,11 +17,7 @@ export declare class SolanaWalletStrategy extends BaseWalletStrategy {
17
17
  accounts: string[];
18
18
  }>;
19
19
  sendNativeTransfer(payload: TransferPayload): Promise<string>;
20
- /**
21
- * @note This feature is not yet implemented for Solana
22
- * @throws {Error} Always throws with a "not implemented" message
23
- */
24
- sendSmartContractInteraction(_payload: SmartContractPayload): Promise<string>;
20
+ sendSmartContractInteraction(payload: SmartContractPayload): Promise<string>;
25
21
  getProviders(): {
26
22
  id: string;
27
23
  type: string;
@@ -50,7 +50,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
50
50
  }
51
51
  };
52
52
  import { BaseWalletStrategy } from './WalletStrategy';
53
- import { connectToSolanaWallet, disconnectFromSolanaWallet, signSolanaMessage, sendSOLTransaction, findAvailableSolanaProviders } from '../connectors/solana';
53
+ import { connectToSolanaWallet, disconnectFromSolanaWallet, signSolanaMessage, sendSOLTransaction, findAvailableSolanaProviders, getSolanaProvider } from '../connectors/solana';
54
54
  var SolanaWalletStrategy = /** @class */ (function (_super) {
55
55
  __extends(SolanaWalletStrategy, _super);
56
56
  function SolanaWalletStrategy() {
@@ -169,16 +169,43 @@ var SolanaWalletStrategy = /** @class */ (function (_super) {
169
169
  });
170
170
  });
171
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) {
172
+ SolanaWalletStrategy.prototype.sendSmartContractInteraction = function (payload) {
179
173
  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');
174
+ var provider, senderAddress, _a, decimals, rawAmount, scaledAmount;
175
+ var _b;
176
+ return __generator(this, function (_c) {
177
+ switch (_c.label) {
178
+ case 0:
179
+ provider = getSolanaProvider(payload.walletName || '');
180
+ _a = payload.account;
181
+ if (_a) return [3 /*break*/, 2];
182
+ return [4 /*yield*/, ((_b = provider.publicKey) === null || _b === void 0 ? void 0 : _b.toString())];
183
+ case 1:
184
+ _a = (_c.sent());
185
+ _c.label = 2;
186
+ case 2:
187
+ senderAddress = _a;
188
+ if (!senderAddress) {
189
+ throw new Error('Sender account address is required');
190
+ }
191
+ decimals = payload.args[2] || 6 // USDC has 6 decimals
192
+ ;
193
+ rawAmount = payload.args[1];
194
+ scaledAmount = rawAmount;
195
+ if (!payload.blockhash) {
196
+ throw new Error('Blockhash is required for Solana transactions');
197
+ }
198
+ return [4 /*yield*/, sendSOLTransaction({
199
+ toAddress: payload.args[0],
200
+ amount: scaledAmount,
201
+ fromAddress: senderAddress,
202
+ blockhash: payload.blockhash,
203
+ walletName: payload.walletName || '',
204
+ tokenMint: payload.address,
205
+ tokenDecimals: decimals
206
+ })];
207
+ case 3: return [2 /*return*/, _c.sent()];
208
+ }
182
209
  });
183
210
  });
184
211
  };