@tonconnect/sdk 3.4.0-beta.0 → 3.4.0-beta.1
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/README.md +34 -0
- package/dist/tonconnect-sdk.min.js +1 -1
- package/dist/tonconnect-sdk.min.js.map +1 -1
- package/lib/cjs/index.cjs +54 -8
- package/lib/cjs/index.cjs.map +1 -1
- package/lib/esm/index.mjs +54 -9
- package/lib/esm/index.mjs.map +1 -1
- package/lib/types/index.d.ts +35 -4
- package/package.json +2 -2
package/lib/cjs/index.cjs
CHANGED
|
@@ -169,6 +169,14 @@ class WalletMissingRequiredFeaturesError extends TonConnectError {
|
|
|
169
169
|
}
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
+
class WalletWrongNetworkError extends TonConnectError {
|
|
173
|
+
constructor(message, options) {
|
|
174
|
+
super(message, options);
|
|
175
|
+
this.name = 'WalletWrongNetworkError';
|
|
176
|
+
Object.setPrototypeOf(this, WalletWrongNetworkError.prototype);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
172
180
|
function isWalletConnectionSourceJS(value) {
|
|
173
181
|
return 'jsBridgeKey' in value;
|
|
174
182
|
}
|
|
@@ -3786,7 +3794,7 @@ class TonConnectTracker {
|
|
|
3786
3794
|
}
|
|
3787
3795
|
}
|
|
3788
3796
|
|
|
3789
|
-
const tonConnectSdkVersion = "3.4.0-beta.
|
|
3797
|
+
const tonConnectSdkVersion = "3.4.0-beta.1";
|
|
3790
3798
|
|
|
3791
3799
|
const bounceableTag = 0x11;
|
|
3792
3800
|
const noBounceableTag = 0x51;
|
|
@@ -4784,10 +4792,13 @@ class TonConnect {
|
|
|
4784
4792
|
var _a, _b, _c;
|
|
4785
4793
|
// TODO: remove deprecated method
|
|
4786
4794
|
const options = Object.assign({}, additionalOptions);
|
|
4787
|
-
if (typeof requestOrOptions === 'object' &&
|
|
4795
|
+
if (typeof requestOrOptions === 'object' &&
|
|
4796
|
+
requestOrOptions !== null &&
|
|
4797
|
+
'tonProof' in requestOrOptions) {
|
|
4788
4798
|
options.request = requestOrOptions;
|
|
4789
4799
|
}
|
|
4790
4800
|
if (typeof requestOrOptions === 'object' &&
|
|
4801
|
+
requestOrOptions !== null &&
|
|
4791
4802
|
('openingDeadlineMS' in requestOrOptions ||
|
|
4792
4803
|
'signal' in requestOrOptions ||
|
|
4793
4804
|
'request' in requestOrOptions ||
|
|
@@ -4925,7 +4936,7 @@ class TonConnect {
|
|
|
4925
4936
|
}
|
|
4926
4937
|
sendTransaction(transaction, optionsOrOnRequestSent) {
|
|
4927
4938
|
return __awaiter(this, void 0, void 0, function* () {
|
|
4928
|
-
var _a;
|
|
4939
|
+
var _a, _b, _c;
|
|
4929
4940
|
// TODO: remove deprecated method
|
|
4930
4941
|
const options = {};
|
|
4931
4942
|
if (typeof optionsOrOnRequestSent === 'function') {
|
|
@@ -4963,6 +4974,14 @@ class TonConnect {
|
|
|
4963
4974
|
const { validUntil, messages } = transaction, tx = __rest(transaction, ["validUntil", "messages"]);
|
|
4964
4975
|
const from = transaction.from || this.account.address;
|
|
4965
4976
|
const network = transaction.network || this.account.chain;
|
|
4977
|
+
if (((_b = this.wallet) === null || _b === void 0 ? void 0 : _b.account.chain) && network !== this.wallet.account.chain) {
|
|
4978
|
+
throw new WalletWrongNetworkError('Wallet connected to a wrong network', {
|
|
4979
|
+
cause: {
|
|
4980
|
+
expectedChainId: (_c = this.wallet) === null || _c === void 0 ? void 0 : _c.account.chain,
|
|
4981
|
+
actualChainId: network
|
|
4982
|
+
}
|
|
4983
|
+
});
|
|
4984
|
+
}
|
|
4966
4985
|
const response = yield this.provider.sendRequest(sendTransactionParser.convertToRpcRequest(Object.assign(Object.assign({}, tx), { from,
|
|
4967
4986
|
network, valid_until: validUntil, messages: messages.map((_a) => {
|
|
4968
4987
|
var { extraCurrency, payload, stateInit } = _a, msg = __rest(_a, ["extraCurrency", "payload", "stateInit"]);
|
|
@@ -4983,7 +5002,7 @@ class TonConnect {
|
|
|
4983
5002
|
}
|
|
4984
5003
|
signData(data, options) {
|
|
4985
5004
|
return __awaiter(this, void 0, void 0, function* () {
|
|
4986
|
-
var _a;
|
|
5005
|
+
var _a, _b, _c;
|
|
4987
5006
|
const abortController = createAbortController(options === null || options === void 0 ? void 0 : options.signal);
|
|
4988
5007
|
if (abortController.signal.aborted) {
|
|
4989
5008
|
throw new TonConnectError('data sending was aborted');
|
|
@@ -5005,6 +5024,14 @@ class TonConnect {
|
|
|
5005
5024
|
this.tracker.trackDataSentForSignature(this.wallet, data, sessionInfo, traceId);
|
|
5006
5025
|
const from = data.from || this.account.address;
|
|
5007
5026
|
const network = data.network || this.account.chain;
|
|
5027
|
+
if (((_b = this.wallet) === null || _b === void 0 ? void 0 : _b.account.chain) && network !== this.wallet.account.chain) {
|
|
5028
|
+
throw new WalletWrongNetworkError('Wallet connected to a wrong network', {
|
|
5029
|
+
cause: {
|
|
5030
|
+
expectedChainId: (_c = this.wallet) === null || _c === void 0 ? void 0 : _c.account.chain,
|
|
5031
|
+
actualChainId: network
|
|
5032
|
+
}
|
|
5033
|
+
});
|
|
5034
|
+
}
|
|
5008
5035
|
const response = yield this.provider.sendRequest(signDataParser.convertToRpcRequest(Object.assign(Object.assign(Object.assign({}, data), (data.type === 'cell' ? { cell: normalizeBase64(data.cell) } : {})), { from,
|
|
5009
5036
|
network })), { onRequestSent: options === null || options === void 0 ? void 0 : options.onRequestSent, signal: abortController.signal, traceId });
|
|
5010
5037
|
if (signDataParser.isError(response)) {
|
|
@@ -5016,6 +5043,17 @@ class TonConnect {
|
|
|
5016
5043
|
return Object.assign(Object.assign({}, result), { traceId });
|
|
5017
5044
|
});
|
|
5018
5045
|
}
|
|
5046
|
+
/**
|
|
5047
|
+
* Set desired network for the connection. Can only be set before connecting.
|
|
5048
|
+
* If wallet connects with a different chain, the SDK will throw an error and abort connection.
|
|
5049
|
+
* @param network desired network id (e.g., '-239', '-3', or custom). Pass undefined to allow any network.
|
|
5050
|
+
*/
|
|
5051
|
+
setConnectionNetwork(network) {
|
|
5052
|
+
if (this.connected) {
|
|
5053
|
+
throw new TonConnectError('Cannot change network while wallet is connected');
|
|
5054
|
+
}
|
|
5055
|
+
this.desiredChainId = network;
|
|
5056
|
+
}
|
|
5019
5057
|
/**
|
|
5020
5058
|
* Disconnect form thw connected wallet and drop current session.
|
|
5021
5059
|
*/
|
|
@@ -5158,7 +5196,7 @@ class TonConnect {
|
|
|
5158
5196
|
}
|
|
5159
5197
|
}
|
|
5160
5198
|
onWalletConnected(connectEvent, options) {
|
|
5161
|
-
var _a;
|
|
5199
|
+
var _a, _b;
|
|
5162
5200
|
const tonAccountItem = connectEvent.items.find(item => item.name === 'ton_addr');
|
|
5163
5201
|
const tonProofItem = connectEvent.items.find(item => item.name === 'ton_proof');
|
|
5164
5202
|
if (!tonAccountItem) {
|
|
@@ -5180,6 +5218,15 @@ class TonConnect {
|
|
|
5180
5218
|
publicKey: tonAccountItem.publicKey
|
|
5181
5219
|
}
|
|
5182
5220
|
};
|
|
5221
|
+
if (this.desiredChainId && wallet.account.chain !== this.desiredChainId) {
|
|
5222
|
+
const expectedChainId = this.desiredChainId;
|
|
5223
|
+
const actualChainId = wallet.account.chain;
|
|
5224
|
+
(_b = this.provider) === null || _b === void 0 ? void 0 : _b.disconnect();
|
|
5225
|
+
this.onWalletConnectError(new WalletWrongNetworkError('Wallet connected to a wrong network', {
|
|
5226
|
+
cause: { expectedChainId, actualChainId }
|
|
5227
|
+
}));
|
|
5228
|
+
return;
|
|
5229
|
+
}
|
|
5183
5230
|
if (tonProofItem) {
|
|
5184
5231
|
const validationError = validateTonProofItemReply(tonProofItem);
|
|
5185
5232
|
let tonProof = undefined;
|
|
@@ -5260,9 +5307,7 @@ class TonConnect {
|
|
|
5260
5307
|
}
|
|
5261
5308
|
createConnectRequest(request) {
|
|
5262
5309
|
const items = [
|
|
5263
|
-
{
|
|
5264
|
-
name: 'ton_addr'
|
|
5265
|
-
}
|
|
5310
|
+
Object.assign({ name: 'ton_addr' }, (this.desiredChainId ? { network: this.desiredChainId } : {}))
|
|
5266
5311
|
];
|
|
5267
5312
|
if (request === null || request === void 0 ? void 0 : request.tonProof) {
|
|
5268
5313
|
items.push({
|
|
@@ -5328,6 +5373,7 @@ exports.WalletMissingRequiredFeaturesError = WalletMissingRequiredFeaturesError;
|
|
|
5328
5373
|
exports.WalletNotConnectedError = WalletNotConnectedError;
|
|
5329
5374
|
exports.WalletNotInjectedError = WalletNotInjectedError;
|
|
5330
5375
|
exports.WalletNotSupportFeatureError = WalletNotSupportFeatureError;
|
|
5376
|
+
exports.WalletWrongNetworkError = WalletWrongNetworkError;
|
|
5331
5377
|
exports.WalletsListManager = WalletsListManager;
|
|
5332
5378
|
exports.WrongAddressError = WrongAddressError;
|
|
5333
5379
|
exports.checkRequiredWalletFeatures = checkRequiredWalletFeatures;
|