@dynamic-labs-sdk/ton 0.0.0 → 0.22.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 +16 -0
- package/dist/TonNetworkProvider.types.d.ts +8 -0
- package/dist/TonNetworkProvider.types.d.ts.map +1 -0
- package/dist/TonWalletAccount.types.d.ts +8 -0
- package/dist/TonWalletAccount.types.d.ts.map +1 -0
- package/dist/TonWalletProvider.types.d.ts +23 -0
- package/dist/TonWalletProvider.types.d.ts.map +1 -0
- package/dist/addTonExtension/addTonExtension.d.ts +13 -0
- package/dist/addTonExtension/addTonExtension.d.ts.map +1 -0
- package/dist/addTonExtension/index.d.ts +2 -0
- package/dist/addTonExtension/index.d.ts.map +1 -0
- package/dist/addWaasTonExtension-B8tYiMfm.esm.js +664 -0
- package/dist/addWaasTonExtension-B8tYiMfm.esm.js.map +1 -0
- package/dist/addWaasTonExtension-Dzrb4rja.cjs.js +717 -0
- package/dist/addWaasTonExtension-Dzrb4rja.cjs.js.map +1 -0
- package/dist/errors/InvalidBocError.d.ts +10 -0
- package/dist/errors/InvalidBocError.d.ts.map +1 -0
- package/dist/errors/InvalidSignatureLengthError.d.ts +10 -0
- package/dist/errors/InvalidSignatureLengthError.d.ts.map +1 -0
- package/dist/errors/NotTonProviderError.d.ts +8 -0
- package/dist/errors/NotTonProviderError.d.ts.map +1 -0
- package/dist/errors/PublicKeyNotFoundError.d.ts +5 -0
- package/dist/errors/PublicKeyNotFoundError.d.ts.map +1 -0
- package/dist/errors/TransactionExecutionFailedError.d.ts +5 -0
- package/dist/errors/TransactionExecutionFailedError.d.ts.map +1 -0
- package/dist/exports/index.d.ts +14 -0
- package/dist/exports/index.d.ts.map +1 -0
- package/dist/exports/waas.d.ts +5 -0
- package/dist/exports/waas.d.ts.map +1 -0
- package/dist/index.cjs.js +100 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.esm.js +92 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/isTonNetworkProvider/index.d.ts +2 -0
- package/dist/isTonNetworkProvider/index.d.ts.map +1 -0
- package/dist/isTonNetworkProvider/isTonNetworkProvider.d.ts +11 -0
- package/dist/isTonNetworkProvider/isTonNetworkProvider.d.ts.map +1 -0
- package/dist/isTonWalletAccount/index.d.ts +2 -0
- package/dist/isTonWalletAccount/index.d.ts.map +1 -0
- package/dist/isTonWalletAccount/isTonWalletAccount.d.ts +11 -0
- package/dist/isTonWalletAccount/isTonWalletAccount.d.ts.map +1 -0
- package/dist/isTonWalletProvider/index.d.ts +2 -0
- package/dist/isTonWalletProvider/index.d.ts.map +1 -0
- package/dist/isTonWalletProvider/isTonWalletProvider.d.ts +11 -0
- package/dist/isTonWalletProvider/isTonWalletProvider.d.ts.map +1 -0
- package/dist/registerTonNetworkProviderBuilder/index.d.ts +2 -0
- package/dist/registerTonNetworkProviderBuilder/index.d.ts.map +1 -0
- package/dist/registerTonNetworkProviderBuilder/registerTonNetworkProviderBuilder.d.ts +4 -0
- package/dist/registerTonNetworkProviderBuilder/registerTonNetworkProviderBuilder.d.ts.map +1 -0
- package/dist/sendJetton/index.d.ts +2 -0
- package/dist/sendJetton/index.d.ts.map +1 -0
- package/dist/sendJetton/sendJetton.d.ts +19 -0
- package/dist/sendJetton/sendJetton.d.ts.map +1 -0
- package/dist/sendTon/index.d.ts +2 -0
- package/dist/sendTon/index.d.ts.map +1 -0
- package/dist/sendTon/sendTon.d.ts +19 -0
- package/dist/sendTon/sendTon.d.ts.map +1 -0
- package/dist/ton.types.d.ts +48 -0
- package/dist/ton.types.d.ts.map +1 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -0
- package/dist/utils/constants.d.ts +6 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/convertTonSendTransactionRequest/convertTonSendTransactionRequest.d.ts +5 -0
- package/dist/utils/convertTonSendTransactionRequest/convertTonSendTransactionRequest.d.ts.map +1 -0
- package/dist/utils/convertTonSendTransactionRequest/createInternalMessage/createInternalMessage.d.ts +28 -0
- package/dist/utils/convertTonSendTransactionRequest/createInternalMessage/createInternalMessage.d.ts.map +1 -0
- package/dist/utils/convertTonSendTransactionRequest/createInternalMessage/index.d.ts +2 -0
- package/dist/utils/convertTonSendTransactionRequest/createInternalMessage/index.d.ts.map +1 -0
- package/dist/utils/convertTonSendTransactionRequest/createSendMsgAction/createSendMsgAction.d.ts +5 -0
- package/dist/utils/convertTonSendTransactionRequest/createSendMsgAction/createSendMsgAction.d.ts.map +1 -0
- package/dist/utils/convertTonSendTransactionRequest/createSendMsgAction/index.d.ts +2 -0
- package/dist/utils/convertTonSendTransactionRequest/createSendMsgAction/index.d.ts.map +1 -0
- package/dist/utils/convertTonSendTransactionRequest/determineBounceFlag/determineBounceFlag.d.ts +3 -0
- package/dist/utils/convertTonSendTransactionRequest/determineBounceFlag/determineBounceFlag.d.ts.map +1 -0
- package/dist/utils/convertTonSendTransactionRequest/determineBounceFlag/index.d.ts +2 -0
- package/dist/utils/convertTonSendTransactionRequest/determineBounceFlag/index.d.ts.map +1 -0
- package/dist/utils/convertTonSendTransactionRequest/index.d.ts +2 -0
- package/dist/utils/convertTonSendTransactionRequest/index.d.ts.map +1 -0
- package/dist/utils/convertTonSendTransactionRequest/parsePayload/index.d.ts +2 -0
- package/dist/utils/convertTonSendTransactionRequest/parsePayload/index.d.ts.map +1 -0
- package/dist/utils/convertTonSendTransactionRequest/parsePayload/parsePayload.d.ts +4 -0
- package/dist/utils/convertTonSendTransactionRequest/parsePayload/parsePayload.d.ts.map +1 -0
- package/dist/utils/convertTonSendTransactionRequest/parseStateInit/index.d.ts +2 -0
- package/dist/utils/convertTonSendTransactionRequest/parseStateInit/index.d.ts.map +1 -0
- package/dist/utils/convertTonSendTransactionRequest/parseStateInit/parseStateInit.d.ts +7 -0
- package/dist/utils/convertTonSendTransactionRequest/parseStateInit/parseStateInit.d.ts.map +1 -0
- package/dist/utils/createTonClient/createTonClient.d.ts +8 -0
- package/dist/utils/createTonClient/createTonClient.d.ts.map +1 -0
- package/dist/utils/createTonClient/index.d.ts +2 -0
- package/dist/utils/createTonClient/index.d.ts.map +1 -0
- package/dist/utils/createTonNetworkProvider/createTonNetworkProvider.d.ts +5 -0
- package/dist/utils/createTonNetworkProvider/createTonNetworkProvider.d.ts.map +1 -0
- package/dist/utils/createTonNetworkProvider/index.d.ts +2 -0
- package/dist/utils/createTonNetworkProvider/index.d.ts.map +1 -0
- package/dist/utils/createTonWalletStateInit/createTonWalletStateInit.d.ts +9 -0
- package/dist/utils/createTonWalletStateInit/createTonWalletStateInit.d.ts.map +1 -0
- package/dist/utils/createTonWalletStateInit/index.d.ts +2 -0
- package/dist/utils/createTonWalletStateInit/index.d.ts.map +1 -0
- package/dist/utils/executeTonTransaction/executeTonTransaction.d.ts +15 -0
- package/dist/utils/executeTonTransaction/executeTonTransaction.d.ts.map +1 -0
- package/dist/utils/executeTonTransaction/index.d.ts +2 -0
- package/dist/utils/executeTonTransaction/index.d.ts.map +1 -0
- package/dist/utils/fetchTonBalance/fetchTonBalance.d.ts +9 -0
- package/dist/utils/fetchTonBalance/fetchTonBalance.d.ts.map +1 -0
- package/dist/utils/fetchTonBalance/index.d.ts +2 -0
- package/dist/utils/fetchTonBalance/index.d.ts.map +1 -0
- package/dist/utils/generateTonConnectProofHash/generateTonConnectProofHash.d.ts +11 -0
- package/dist/utils/generateTonConnectProofHash/generateTonConnectProofHash.d.ts.map +1 -0
- package/dist/utils/generateTonConnectProofHash/generateTonConnectProofMessage/generateTonConnectProofMessage.d.ts +11 -0
- package/dist/utils/generateTonConnectProofHash/generateTonConnectProofMessage/generateTonConnectProofMessage.d.ts.map +1 -0
- package/dist/utils/generateTonConnectProofHash/generateTonConnectProofMessage/index.d.ts +2 -0
- package/dist/utils/generateTonConnectProofHash/generateTonConnectProofMessage/index.d.ts.map +1 -0
- package/dist/utils/generateTonConnectProofHash/index.d.ts +2 -0
- package/dist/utils/generateTonConnectProofHash/index.d.ts.map +1 -0
- package/dist/utils/getJettonWalletAddress/getJettonWalletAddress.d.ts +10 -0
- package/dist/utils/getJettonWalletAddress/getJettonWalletAddress.d.ts.map +1 -0
- package/dist/utils/getJettonWalletAddress/index.d.ts +2 -0
- package/dist/utils/getJettonWalletAddress/index.d.ts.map +1 -0
- package/dist/utils/getTonWalletSeqno/getTonWalletSeqno.d.ts +9 -0
- package/dist/utils/getTonWalletSeqno/getTonWalletSeqno.d.ts.map +1 -0
- package/dist/utils/getTonWalletSeqno/index.d.ts +2 -0
- package/dist/utils/getTonWalletSeqno/index.d.ts.map +1 -0
- package/dist/utils/isTonWalletDeployed/index.d.ts +2 -0
- package/dist/utils/isTonWalletDeployed/index.d.ts.map +1 -0
- package/dist/utils/isTonWalletDeployed/isTonWalletDeployed.d.ts +9 -0
- package/dist/utils/isTonWalletDeployed/isTonWalletDeployed.d.ts.map +1 -0
- package/dist/utils/prepareJettonTransfer/index.d.ts +2 -0
- package/dist/utils/prepareJettonTransfer/index.d.ts.map +1 -0
- package/dist/utils/prepareJettonTransfer/prepareJettonTransfer.d.ts +19 -0
- package/dist/utils/prepareJettonTransfer/prepareJettonTransfer.d.ts.map +1 -0
- package/dist/utils/prepareTonNativeTransfer/index.d.ts +2 -0
- package/dist/utils/prepareTonNativeTransfer/index.d.ts.map +1 -0
- package/dist/utils/prepareTonNativeTransfer/prepareTonNativeTransfer.d.ts +13 -0
- package/dist/utils/prepareTonNativeTransfer/prepareTonNativeTransfer.d.ts.map +1 -0
- package/dist/utils/prepareTonTransaction/index.d.ts +2 -0
- package/dist/utils/prepareTonTransaction/index.d.ts.map +1 -0
- package/dist/utils/prepareTonTransaction/prepareTonTransaction.d.ts +20 -0
- package/dist/utils/prepareTonTransaction/prepareTonTransaction.d.ts.map +1 -0
- package/dist/utils/tonTransferAmount/index.d.ts +2 -0
- package/dist/utils/tonTransferAmount/index.d.ts.map +1 -0
- package/dist/utils/tonTransferAmount/tonTransferAmount.d.ts +7 -0
- package/dist/utils/tonTransferAmount/tonTransferAmount.d.ts.map +1 -0
- package/dist/waas/WaasTonWalletProvider.types.d.ts +4 -0
- package/dist/waas/WaasTonWalletProvider.types.d.ts.map +1 -0
- package/dist/waas/addWaasTonExtension/addWaasTonExtension.d.ts +12 -0
- package/dist/waas/addWaasTonExtension/addWaasTonExtension.d.ts.map +1 -0
- package/dist/waas/addWaasTonExtension/index.d.ts +2 -0
- package/dist/waas/addWaasTonExtension/index.d.ts.map +1 -0
- package/dist/waas/utils/createWalletProviderForWaasTon/createWalletProviderForWaasTon.d.ts +5 -0
- package/dist/waas/utils/createWalletProviderForWaasTon/createWalletProviderForWaasTon.d.ts.map +1 -0
- package/dist/waas/utils/createWalletProviderForWaasTon/index.d.ts +2 -0
- package/dist/waas/utils/createWalletProviderForWaasTon/index.d.ts.map +1 -0
- package/dist/waas/utils/getPublicKeyForWalletAccount/getPublicKeyForWalletAccount.d.ts +7 -0
- package/dist/waas/utils/getPublicKeyForWalletAccount/getPublicKeyForWalletAccount.d.ts.map +1 -0
- package/dist/waas.cjs.js +11 -0
- package/dist/waas.cjs.js.map +1 -0
- package/dist/waas.esm.js +9 -0
- package/dist/waas.esm.js.map +1 -0
- package/package.json +45 -1
|
@@ -0,0 +1,664 @@
|
|
|
1
|
+
import { WalletProviderPriority, assertDefined, consumeMfaTokenIfRequiredForAction, createBaseNetworkProvider, formatWalletProviderGroupKey, formatWalletProviderKey, getActiveNetworkIdFromLastKnownRegistry, getBuffer, getCore, getDefaultClient, getNetworkProviderBuilderRegistry, getNetworkProviderFromNetworkId, getSignedSessionId, getWalletProviderFromWalletAccount, getWalletProviderRegistry, hasExtension, parseAmountToSmallestUnit, registerExtension, switchActiveNetworkInLastKnownRegistry } from "@dynamic-labs-sdk/client/core";
|
|
2
|
+
import { Address, Cell, TonClient, WalletContractV5R1, beginCell, fromNano } from "@ton/ton";
|
|
3
|
+
import { DYNAMIC_WAAS_METADATA, createWaasProvider, getAllUserWaasAddressesForChain } from "@dynamic-labs-sdk/client/waas/core";
|
|
4
|
+
import { MFAAction, WalletProviderEnum } from "@dynamic-labs/sdk-api-core";
|
|
5
|
+
import { CHAIN } from "@tonconnect/sdk";
|
|
6
|
+
import { BaseError } from "@dynamic-labs-sdk/client";
|
|
7
|
+
import { SendMode, external, storeMessage, storeOutList } from "@ton/core";
|
|
8
|
+
import { sha256 } from "@ton/crypto";
|
|
9
|
+
|
|
10
|
+
//#region package.json
|
|
11
|
+
var name = "@dynamic-labs-sdk/ton";
|
|
12
|
+
var version = "0.22.1";
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/utils/createTonClient/createTonClient.ts
|
|
16
|
+
/** @not-instrumented */
|
|
17
|
+
const createTonClient = ({ rpcUrl }) => new TonClient({ endpoint: rpcUrl });
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/utils/fetchTonBalance/fetchTonBalance.ts
|
|
21
|
+
/** @not-instrumented */
|
|
22
|
+
const fetchTonBalance = async ({ address, client }) => {
|
|
23
|
+
try {
|
|
24
|
+
return fromNano(await client.getBalance(Address.parse(address)));
|
|
25
|
+
} catch {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/utils/createTonNetworkProvider/createTonNetworkProvider.ts
|
|
32
|
+
/** @not-instrumented */
|
|
33
|
+
const createTonNetworkProvider = (networkData) => ({
|
|
34
|
+
...createBaseNetworkProvider("TON", networkData),
|
|
35
|
+
getBalance: async ({ address }) => ({ balance: await fetchTonBalance({
|
|
36
|
+
address,
|
|
37
|
+
client: createTonClient({ rpcUrl: networkData.rpcUrls.http[0] })
|
|
38
|
+
}) })
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region src/registerTonNetworkProviderBuilder/registerTonNetworkProviderBuilder.ts
|
|
43
|
+
/** @not-instrumented */
|
|
44
|
+
const registerTonNetworkProviderBuilder = (client) => {
|
|
45
|
+
const networkProviderBuilderRegistry = getNetworkProviderBuilderRegistry(client);
|
|
46
|
+
if (networkProviderBuilderRegistry.get().get("TON")) return;
|
|
47
|
+
networkProviderBuilderRegistry.register({
|
|
48
|
+
builder: createTonNetworkProvider,
|
|
49
|
+
chain: "TON"
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/errors/TransactionExecutionFailedError.ts
|
|
55
|
+
var TransactionExecutionFailedError = class extends BaseError {
|
|
56
|
+
constructor(message) {
|
|
57
|
+
super({
|
|
58
|
+
cause: null,
|
|
59
|
+
code: "transaction_execution_failed_error",
|
|
60
|
+
details: message,
|
|
61
|
+
docsUrl: null,
|
|
62
|
+
name: "TransactionExecutionFailedError",
|
|
63
|
+
shortMessage: "Failed to execute TON transaction"
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region src/utils/constants.ts
|
|
70
|
+
const DEFAULT_TIMEOUT = 60;
|
|
71
|
+
const DEFAULT_JETTON_GAS = BigInt(5e7);
|
|
72
|
+
const NANOTON_PER_TON = BigInt(1e9);
|
|
73
|
+
const TON_PROOF_PREFIX = "ton-proof-item-v2/";
|
|
74
|
+
const TON_CONNECT_PREFIX = "ton-connect";
|
|
75
|
+
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region src/utils/convertTonSendTransactionRequest/createInternalMessage/createInternalMessage.ts
|
|
78
|
+
/** @not-instrumented */
|
|
79
|
+
const createInternalMessage = (destAddr, amount, body, bounce, init) => ({
|
|
80
|
+
body,
|
|
81
|
+
info: {
|
|
82
|
+
bounce,
|
|
83
|
+
bounced: false,
|
|
84
|
+
createdAt: 0,
|
|
85
|
+
createdLt: BigInt(0),
|
|
86
|
+
dest: destAddr,
|
|
87
|
+
forwardFee: BigInt(0),
|
|
88
|
+
ihrDisabled: true,
|
|
89
|
+
ihrFee: BigInt(0),
|
|
90
|
+
src: null,
|
|
91
|
+
type: "internal",
|
|
92
|
+
value: { coins: amount }
|
|
93
|
+
},
|
|
94
|
+
...init && { init }
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
//#endregion
|
|
98
|
+
//#region src/utils/convertTonSendTransactionRequest/createSendMsgAction/createSendMsgAction.ts
|
|
99
|
+
/** @not-instrumented */
|
|
100
|
+
const createSendMsgAction = (internalMessage) => ({
|
|
101
|
+
mode: SendMode.PAY_GAS_SEPARATELY | SendMode.IGNORE_ERRORS,
|
|
102
|
+
outMsg: internalMessage,
|
|
103
|
+
type: "sendMsg"
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
//#endregion
|
|
107
|
+
//#region src/utils/convertTonSendTransactionRequest/determineBounceFlag/determineBounceFlag.ts
|
|
108
|
+
/** @not-instrumented */
|
|
109
|
+
const determineBounceFlag = (address) => !address.startsWith("UQ") && !address.startsWith("0Q");
|
|
110
|
+
|
|
111
|
+
//#endregion
|
|
112
|
+
//#region src/errors/InvalidBocError.ts
|
|
113
|
+
var InvalidBocError = class extends BaseError {
|
|
114
|
+
constructor({ cause, type }) {
|
|
115
|
+
super({
|
|
116
|
+
cause,
|
|
117
|
+
code: "invalid_boc_error",
|
|
118
|
+
docsUrl: null,
|
|
119
|
+
name: "InvalidBocError",
|
|
120
|
+
shortMessage: `Invalid ${type} BOC`
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
//#endregion
|
|
126
|
+
//#region src/utils/convertTonSendTransactionRequest/parsePayload/parsePayload.ts
|
|
127
|
+
/** @not-instrumented */
|
|
128
|
+
const parsePayload = (payload) => {
|
|
129
|
+
if (!payload) return beginCell().endCell();
|
|
130
|
+
try {
|
|
131
|
+
return Cell.fromBase64(payload);
|
|
132
|
+
} catch (e) {
|
|
133
|
+
throw new InvalidBocError({
|
|
134
|
+
cause: e instanceof Error ? e : null,
|
|
135
|
+
type: "payload"
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
//#endregion
|
|
141
|
+
//#region src/utils/convertTonSendTransactionRequest/parseStateInit/parseStateInit.ts
|
|
142
|
+
/** @not-instrumented */
|
|
143
|
+
const parseStateInit = (stateInit) => {
|
|
144
|
+
if (!stateInit) return;
|
|
145
|
+
try {
|
|
146
|
+
const slice = Cell.fromBase64(stateInit).beginParse();
|
|
147
|
+
slice.skip(2);
|
|
148
|
+
return {
|
|
149
|
+
code: slice.loadRef(),
|
|
150
|
+
data: slice.loadRef()
|
|
151
|
+
};
|
|
152
|
+
} catch (e) {
|
|
153
|
+
throw new InvalidBocError({
|
|
154
|
+
cause: e instanceof Error ? e : null,
|
|
155
|
+
type: "stateInit"
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
//#endregion
|
|
161
|
+
//#region src/utils/convertTonSendTransactionRequest/convertTonSendTransactionRequest.ts
|
|
162
|
+
/** @not-instrumented */
|
|
163
|
+
const convertTonSendTransactionRequest = (request) => {
|
|
164
|
+
const actions = [];
|
|
165
|
+
for (const msg of request.messages) {
|
|
166
|
+
const destAddr = Address.parse(msg.address);
|
|
167
|
+
const amount = BigInt(msg.amount);
|
|
168
|
+
const body = parsePayload(msg.payload);
|
|
169
|
+
const init = parseStateInit(msg.stateInit);
|
|
170
|
+
const internalMessage = createInternalMessage(destAddr, amount, body, determineBounceFlag(msg.address), init);
|
|
171
|
+
actions.push(createSendMsgAction(internalMessage));
|
|
172
|
+
}
|
|
173
|
+
return actions;
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
//#endregion
|
|
177
|
+
//#region src/utils/createTonWalletStateInit/createTonWalletStateInit.ts
|
|
178
|
+
/** @not-instrumented */
|
|
179
|
+
const createTonWalletStateInit = ({ publicKey, workchain = 0 }) => {
|
|
180
|
+
return WalletContractV5R1.create({
|
|
181
|
+
publicKey,
|
|
182
|
+
workchain
|
|
183
|
+
}).init;
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
//#endregion
|
|
187
|
+
//#region src/errors/InvalidSignatureLengthError.ts
|
|
188
|
+
var InvalidSignatureLengthError = class extends BaseError {
|
|
189
|
+
constructor({ actual, expected }) {
|
|
190
|
+
super({
|
|
191
|
+
cause: null,
|
|
192
|
+
code: "invalid_signature_length_error",
|
|
193
|
+
docsUrl: null,
|
|
194
|
+
name: "InvalidSignatureLengthError",
|
|
195
|
+
shortMessage: `Invalid signature length: expected ${expected} bytes, got ${actual}`
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
//#endregion
|
|
201
|
+
//#region src/utils/executeTonTransaction/executeTonTransaction.ts
|
|
202
|
+
/** @not-instrumented */
|
|
203
|
+
const executeTonTransaction = async ({ transactionData, signature, client, stateInit }) => {
|
|
204
|
+
const signatureBuffer = getBuffer().from(signature, "base64");
|
|
205
|
+
if (signatureBuffer.length !== 64) throw new InvalidSignatureLengthError({
|
|
206
|
+
actual: signatureBuffer.length,
|
|
207
|
+
expected: 64
|
|
208
|
+
});
|
|
209
|
+
const signingMessageCell = Cell.fromBase64(transactionData.messageBody);
|
|
210
|
+
const externalMsg = external({
|
|
211
|
+
body: beginCell().storeSlice(signingMessageCell.beginParse()).storeBuffer(signatureBuffer).endCell(),
|
|
212
|
+
to: Address.parse(transactionData.address),
|
|
213
|
+
...stateInit ? { init: stateInit } : {}
|
|
214
|
+
});
|
|
215
|
+
const externalMessage = beginCell().store(storeMessage(externalMsg, { forceRef: true })).endCell();
|
|
216
|
+
const boc = externalMessage.toBoc();
|
|
217
|
+
await client.sendFile(boc);
|
|
218
|
+
return { transactionHash: externalMessage.hash().toString("hex") };
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
//#endregion
|
|
222
|
+
//#region src/utils/generateTonConnectProofHash/generateTonConnectProofMessage/generateTonConnectProofMessage.ts
|
|
223
|
+
/** @not-instrumented */
|
|
224
|
+
const generateTonConnectProofMessage = ({ address: addressStr, domain, payload, timestamp }) => {
|
|
225
|
+
const BufferImpl = getBuffer();
|
|
226
|
+
const address = Address.parse(addressStr);
|
|
227
|
+
const domainBytes = BufferImpl.from(domain.value);
|
|
228
|
+
const wc = BufferImpl.alloc(4);
|
|
229
|
+
wc.writeUInt32BE(address.workChain, 0);
|
|
230
|
+
const ts = BufferImpl.alloc(8);
|
|
231
|
+
ts.writeBigUInt64LE(BigInt(timestamp), 0);
|
|
232
|
+
const dl = BufferImpl.alloc(4);
|
|
233
|
+
dl.writeUInt32LE(domain.lengthBytes, 0);
|
|
234
|
+
return BufferImpl.concat([
|
|
235
|
+
BufferImpl.from(TON_PROOF_PREFIX),
|
|
236
|
+
wc,
|
|
237
|
+
address.hash,
|
|
238
|
+
dl,
|
|
239
|
+
domainBytes,
|
|
240
|
+
ts,
|
|
241
|
+
BufferImpl.from(payload)
|
|
242
|
+
]);
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
//#endregion
|
|
246
|
+
//#region src/utils/generateTonConnectProofHash/generateTonConnectProofHash.ts
|
|
247
|
+
/** @not-instrumented */
|
|
248
|
+
const generateTonConnectProofHash = async ({ address, domain, payload, timestamp }) => {
|
|
249
|
+
const BufferImpl = getBuffer();
|
|
250
|
+
const message = generateTonConnectProofMessage({
|
|
251
|
+
address,
|
|
252
|
+
domain,
|
|
253
|
+
payload,
|
|
254
|
+
timestamp
|
|
255
|
+
});
|
|
256
|
+
const messageHash = BufferImpl.from(await sha256(message));
|
|
257
|
+
const fullMsg = BufferImpl.concat([
|
|
258
|
+
BufferImpl.from([255, 255]),
|
|
259
|
+
BufferImpl.from(TON_CONNECT_PREFIX),
|
|
260
|
+
messageHash
|
|
261
|
+
]);
|
|
262
|
+
return BufferImpl.from(await sha256(fullMsg)).toString("hex");
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
//#endregion
|
|
266
|
+
//#region src/utils/getTonWalletSeqno/getTonWalletSeqno.ts
|
|
267
|
+
/** @not-instrumented */
|
|
268
|
+
const getTonWalletSeqno = async ({ walletAddress, client }) => {
|
|
269
|
+
const address = Address.parse(walletAddress);
|
|
270
|
+
return (await client.runMethod(address, "seqno")).stack.readNumber();
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
//#endregion
|
|
274
|
+
//#region src/utils/isTonWalletDeployed/isTonWalletDeployed.ts
|
|
275
|
+
/** @not-instrumented */
|
|
276
|
+
const isTonWalletDeployed = async ({ walletAddress, client }) => {
|
|
277
|
+
const address = Address.parse(walletAddress);
|
|
278
|
+
return (await client.getContractState(address)).state === "active";
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
//#endregion
|
|
282
|
+
//#region src/utils/getJettonWalletAddress/getJettonWalletAddress.ts
|
|
283
|
+
/** @not-instrumented */
|
|
284
|
+
const getJettonWalletAddress = async ({ jettonMasterAddress, ownerAddress, client }) => {
|
|
285
|
+
const masterAddress = Address.parse(jettonMasterAddress);
|
|
286
|
+
const owner = Address.parse(ownerAddress);
|
|
287
|
+
const ownerCell = beginCell().storeAddress(owner).endCell();
|
|
288
|
+
return (await client.runMethod(masterAddress, "get_wallet_address", [{
|
|
289
|
+
cell: ownerCell,
|
|
290
|
+
type: "slice"
|
|
291
|
+
}])).stack.readAddress().toString({
|
|
292
|
+
bounceable: true,
|
|
293
|
+
testOnly: false,
|
|
294
|
+
urlSafe: true
|
|
295
|
+
});
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
//#endregion
|
|
299
|
+
//#region src/utils/prepareJettonTransfer/prepareJettonTransfer.ts
|
|
300
|
+
/** @not-instrumented */
|
|
301
|
+
const prepareJettonTransfer = async ({ walletAddress, jettonMasterAddress, recipientAddress, jettonAmount, forwardTonAmount, client, forwardPayload = "", timeout = DEFAULT_TIMEOUT, gasAmount = DEFAULT_JETTON_GAS, network = CHAIN.MAINNET }) => {
|
|
302
|
+
const validUntil = Math.floor(Date.now() / 1e3) + timeout;
|
|
303
|
+
const jettonWalletAddr = Address.parse(await getJettonWalletAddress({
|
|
304
|
+
client,
|
|
305
|
+
jettonMasterAddress,
|
|
306
|
+
ownerAddress: walletAddress
|
|
307
|
+
}));
|
|
308
|
+
const recipientAddr = Address.parse(recipientAddress);
|
|
309
|
+
const walletAddr = Address.parse(walletAddress);
|
|
310
|
+
const isTestnet = network === CHAIN.TESTNET;
|
|
311
|
+
const forwardPayloadCell = forwardPayload ? beginCell().storeUint(0, 32).storeStringTail(forwardPayload).endCell() : beginCell().endCell();
|
|
312
|
+
const jettonTransferBody = beginCell().storeUint(260734629, 32).storeUint(0, 64).storeCoins(jettonAmount).storeAddress(recipientAddr).storeAddress(walletAddr).storeBit(0).storeCoins(forwardTonAmount).storeBit(0).storeSlice(forwardPayloadCell.beginParse()).endCell();
|
|
313
|
+
const totalAmount = forwardTonAmount + gasAmount;
|
|
314
|
+
const message = {
|
|
315
|
+
address: jettonWalletAddr.toString({
|
|
316
|
+
bounceable: true,
|
|
317
|
+
testOnly: isTestnet,
|
|
318
|
+
urlSafe: true
|
|
319
|
+
}),
|
|
320
|
+
amount: totalAmount.toString(),
|
|
321
|
+
payload: jettonTransferBody.toBoc().toString("base64")
|
|
322
|
+
};
|
|
323
|
+
return {
|
|
324
|
+
from: walletAddr.toString({
|
|
325
|
+
bounceable: false,
|
|
326
|
+
testOnly: isTestnet,
|
|
327
|
+
urlSafe: true
|
|
328
|
+
}),
|
|
329
|
+
messages: [message],
|
|
330
|
+
network,
|
|
331
|
+
validUntil
|
|
332
|
+
};
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
//#endregion
|
|
336
|
+
//#region src/utils/prepareTonTransaction/prepareTonTransaction.ts
|
|
337
|
+
/** @not-instrumented */
|
|
338
|
+
const prepareTonTransaction = ({ actionsArray, walletAddress, seqno, validUntil, timeout, networkGlobalId = CHAIN.MAINNET }) => {
|
|
339
|
+
const walletAddr = Address.parse(walletAddress);
|
|
340
|
+
const actionsCell = beginCell().store(storeOutList(actionsArray)).endCell();
|
|
341
|
+
const actions = beginCell().storeBit(1).storeRef(actionsCell).storeBit(0).endCell();
|
|
342
|
+
const context = beginCell().storeUint(1, 1).storeInt(walletAddr.workChain, 8).storeUint(0, 8).storeUint(0, 15).endCell().beginParse().loadInt(32);
|
|
343
|
+
const walletIdValue = BigInt(networkGlobalId) ^ BigInt(context);
|
|
344
|
+
const signingMessage = beginCell().storeUint(WalletContractV5R1.OpCodes.auth_signed_external, 32).storeInt(walletIdValue, 32);
|
|
345
|
+
if (seqno === 0) for (let i = 0; i < 32; i++) signingMessage.storeBit(1);
|
|
346
|
+
else signingMessage.storeUint(validUntil, 32);
|
|
347
|
+
signingMessage.storeUint(seqno, 32).storeSlice(actions.beginParse());
|
|
348
|
+
const dataToSign = signingMessage.endCell();
|
|
349
|
+
const hashToSign = dataToSign.hash();
|
|
350
|
+
return {
|
|
351
|
+
hashToSign,
|
|
352
|
+
hashToSignHex: hashToSign.toString("hex"),
|
|
353
|
+
transactionData: {
|
|
354
|
+
address: walletAddress,
|
|
355
|
+
messageBody: dataToSign.toBoc().toString("base64"),
|
|
356
|
+
seqno,
|
|
357
|
+
timeout
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
//#endregion
|
|
363
|
+
//#region src/utils/prepareTonNativeTransfer/prepareTonNativeTransfer.ts
|
|
364
|
+
/** @not-instrumented */
|
|
365
|
+
const prepareTonNativeTransfer = ({ walletAddress, recipient, amountInNanoton, timeout = DEFAULT_TIMEOUT, network = CHAIN.MAINNET }) => {
|
|
366
|
+
const validUntil = Math.floor(Date.now() / 1e3) + timeout;
|
|
367
|
+
const recipientAddress = Address.parse(recipient);
|
|
368
|
+
const walletAddr = Address.parse(walletAddress);
|
|
369
|
+
const isTestnet = network === CHAIN.TESTNET;
|
|
370
|
+
const message = {
|
|
371
|
+
address: recipientAddress.toString({
|
|
372
|
+
bounceable: false,
|
|
373
|
+
testOnly: isTestnet,
|
|
374
|
+
urlSafe: true
|
|
375
|
+
}),
|
|
376
|
+
amount: amountInNanoton
|
|
377
|
+
};
|
|
378
|
+
return {
|
|
379
|
+
from: walletAddr.toString({
|
|
380
|
+
bounceable: false,
|
|
381
|
+
testOnly: isTestnet,
|
|
382
|
+
urlSafe: true
|
|
383
|
+
}),
|
|
384
|
+
messages: [message],
|
|
385
|
+
network,
|
|
386
|
+
validUntil
|
|
387
|
+
};
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
//#endregion
|
|
391
|
+
//#region src/errors/NotTonProviderError.ts
|
|
392
|
+
var NotTonProviderError = class extends BaseError {
|
|
393
|
+
providerKey;
|
|
394
|
+
constructor(params) {
|
|
395
|
+
super({
|
|
396
|
+
cause: null,
|
|
397
|
+
code: "not_ton_provider_error",
|
|
398
|
+
docsUrl: null,
|
|
399
|
+
name: "NotTonProviderError",
|
|
400
|
+
shortMessage: "Provider is not a TON wallet provider"
|
|
401
|
+
});
|
|
402
|
+
this.providerKey = params.providerKey;
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
//#endregion
|
|
407
|
+
//#region src/isTonWalletProvider/isTonWalletProvider.ts
|
|
408
|
+
/**
|
|
409
|
+
* Type guard function to check if a wallet provider is a TON wallet provider.
|
|
410
|
+
*
|
|
411
|
+
* @param provider - The wallet provider to check.
|
|
412
|
+
* @returns True if the wallet provider is a TON wallet provider, false otherwise.
|
|
413
|
+
* @not-instrumented
|
|
414
|
+
*/
|
|
415
|
+
const isTonWalletProvider = (provider) => provider.chain === "TON";
|
|
416
|
+
|
|
417
|
+
//#endregion
|
|
418
|
+
//#region src/utils/tonTransferAmount/tonTransferAmount.ts
|
|
419
|
+
const DEFAULT_DECIMALS = 9;
|
|
420
|
+
/** @not-instrumented */
|
|
421
|
+
const tonTransferAmount = async ({ amount, recipient, token, walletAccount }, client) => {
|
|
422
|
+
const provider = getWalletProviderFromWalletAccount({ walletAccount }, client);
|
|
423
|
+
if (!isTonWalletProvider(provider)) throw new NotTonProviderError({ providerKey: provider.key });
|
|
424
|
+
if (token) {
|
|
425
|
+
const rawAmount$1 = parseAmountToSmallestUnit({
|
|
426
|
+
amount,
|
|
427
|
+
decimals: token.decimals ?? DEFAULT_DECIMALS
|
|
428
|
+
});
|
|
429
|
+
return provider.sendJetton({
|
|
430
|
+
transaction: {
|
|
431
|
+
amount: rawAmount$1,
|
|
432
|
+
jettonMasterAddress: token.address,
|
|
433
|
+
recipientAddress: recipient
|
|
434
|
+
},
|
|
435
|
+
walletAccount
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
const rawAmount = parseAmountToSmallestUnit({
|
|
439
|
+
amount,
|
|
440
|
+
decimals: DEFAULT_DECIMALS
|
|
441
|
+
});
|
|
442
|
+
return provider.sendTon({
|
|
443
|
+
transaction: {
|
|
444
|
+
amount: rawAmount,
|
|
445
|
+
recipientAddress: recipient
|
|
446
|
+
},
|
|
447
|
+
walletAccount
|
|
448
|
+
});
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
//#endregion
|
|
452
|
+
//#region src/errors/PublicKeyNotFoundError.ts
|
|
453
|
+
var PublicKeyNotFoundError = class extends BaseError {
|
|
454
|
+
constructor(address) {
|
|
455
|
+
super({
|
|
456
|
+
cause: null,
|
|
457
|
+
code: "public_key_not_found_error",
|
|
458
|
+
docsUrl: null,
|
|
459
|
+
name: "PublicKeyNotFoundError",
|
|
460
|
+
shortMessage: `No public key found for address ${address}`
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
};
|
|
464
|
+
|
|
465
|
+
//#endregion
|
|
466
|
+
//#region src/waas/utils/getPublicKeyForWalletAccount/getPublicKeyForWalletAccount.ts
|
|
467
|
+
/**
|
|
468
|
+
* Gets the public key for a wallet account from the user's verified credentials
|
|
469
|
+
* @not-instrumented
|
|
470
|
+
*/
|
|
471
|
+
const getPublicKeyForWalletAccount = (walletAccount, client) => {
|
|
472
|
+
const user = getCore(client).state.get().user;
|
|
473
|
+
for (const credential of user?.verifiedCredentials ?? []) {
|
|
474
|
+
const additionalAddress = credential.walletAdditionalAddresses?.find((addr) => addr.address === walletAccount.address);
|
|
475
|
+
if (additionalAddress?.publicKey) return additionalAddress.publicKey;
|
|
476
|
+
}
|
|
477
|
+
throw new PublicKeyNotFoundError(walletAccount.address);
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
//#endregion
|
|
481
|
+
//#region src/waas/utils/createWalletProviderForWaasTon/createWalletProviderForWaasTon.ts
|
|
482
|
+
/** @not-instrumented */
|
|
483
|
+
const createWalletProviderForWaasTon = (sdkClient) => {
|
|
484
|
+
const chain = "TON";
|
|
485
|
+
const walletProviderType = WalletProviderEnum.EmbeddedWallet;
|
|
486
|
+
const key = formatWalletProviderKey({
|
|
487
|
+
chain,
|
|
488
|
+
displayName: DYNAMIC_WAAS_METADATA.displayName,
|
|
489
|
+
walletProviderType
|
|
490
|
+
});
|
|
491
|
+
const waasProvider = createWaasProvider({
|
|
492
|
+
chain,
|
|
493
|
+
sdkClient
|
|
494
|
+
});
|
|
495
|
+
const getTonClientForActiveNetwork = async () => {
|
|
496
|
+
const { networkId } = await getActiveNetworkId();
|
|
497
|
+
return createTonClient({ rpcUrl: getNetworkProviderFromNetworkId({
|
|
498
|
+
chain: "TON",
|
|
499
|
+
networkId
|
|
500
|
+
}, sdkClient).rpcUrls.http[0] });
|
|
501
|
+
};
|
|
502
|
+
const getActiveNetworkId = async () => getActiveNetworkIdFromLastKnownRegistry({
|
|
503
|
+
client: sdkClient,
|
|
504
|
+
walletProviderKey: key
|
|
505
|
+
});
|
|
506
|
+
const switchActiveNetwork = async ({ networkId }) => switchActiveNetworkInLastKnownRegistry({
|
|
507
|
+
client: sdkClient,
|
|
508
|
+
networkId,
|
|
509
|
+
walletProviderKey: key
|
|
510
|
+
});
|
|
511
|
+
const getConnectedAddresses = async () => ({ addresses: getAllUserWaasAddressesForChain({ chain }, sdkClient) });
|
|
512
|
+
const signMessage = async ({ message, walletAccount }) => {
|
|
513
|
+
assertDefined(walletAccount, "Wallet account is required");
|
|
514
|
+
return waasProvider.signMessage({
|
|
515
|
+
message,
|
|
516
|
+
walletAccount
|
|
517
|
+
});
|
|
518
|
+
};
|
|
519
|
+
const sendTransaction = async ({ request, walletAccount }) => {
|
|
520
|
+
assertDefined(walletAccount, "Wallet account is required");
|
|
521
|
+
const client = await getTonClientForActiveNetwork();
|
|
522
|
+
const walletAddress = request.from || walletAccount.address;
|
|
523
|
+
const deployed = await isTonWalletDeployed({
|
|
524
|
+
client,
|
|
525
|
+
walletAddress
|
|
526
|
+
});
|
|
527
|
+
const seqno = deployed ? await getTonWalletSeqno({
|
|
528
|
+
client,
|
|
529
|
+
walletAddress
|
|
530
|
+
}) : 0;
|
|
531
|
+
const publicKeyHex = getPublicKeyForWalletAccount(walletAccount, sdkClient);
|
|
532
|
+
const stateInit = deployed ? void 0 : createTonWalletStateInit({
|
|
533
|
+
publicKey: getBuffer().from(publicKeyHex, "hex"),
|
|
534
|
+
workchain: 0
|
|
535
|
+
});
|
|
536
|
+
const actionsArray = convertTonSendTransactionRequest(request);
|
|
537
|
+
const timeoutSeconds = request.validUntil - Math.floor(Date.now() / 1e3);
|
|
538
|
+
if (timeoutSeconds <= 0) throw new TransactionExecutionFailedError("Transaction validUntil is in the past");
|
|
539
|
+
const { hashToSignHex, transactionData } = prepareTonTransaction({
|
|
540
|
+
actionsArray,
|
|
541
|
+
networkGlobalId: request.network || CHAIN.MAINNET,
|
|
542
|
+
seqno,
|
|
543
|
+
timeout: timeoutSeconds,
|
|
544
|
+
validUntil: request.validUntil,
|
|
545
|
+
walletAddress
|
|
546
|
+
});
|
|
547
|
+
const waasClient = await waasProvider.getWaasClient();
|
|
548
|
+
const { signature: signedSessionId } = await getSignedSessionId(sdkClient);
|
|
549
|
+
const mfaToken = await consumeMfaTokenIfRequiredForAction({ mfaAction: MFAAction.WalletWaasSign }, sdkClient);
|
|
550
|
+
return executeTonTransaction({
|
|
551
|
+
client,
|
|
552
|
+
signature: await waasClient.signTransaction({
|
|
553
|
+
authToken: sdkClient.token ?? void 0,
|
|
554
|
+
mfaToken,
|
|
555
|
+
senderAddress: walletAccount.address,
|
|
556
|
+
signedSessionId,
|
|
557
|
+
transaction: hashToSignHex
|
|
558
|
+
}),
|
|
559
|
+
stateInit,
|
|
560
|
+
transactionData
|
|
561
|
+
});
|
|
562
|
+
};
|
|
563
|
+
const sendTon = async ({ transaction, walletAccount }) => {
|
|
564
|
+
assertDefined(walletAccount, "Wallet account is required");
|
|
565
|
+
return sendTransaction({
|
|
566
|
+
request: prepareTonNativeTransfer({
|
|
567
|
+
amountInNanoton: transaction.amount.toString(),
|
|
568
|
+
recipient: transaction.recipientAddress,
|
|
569
|
+
timeout: DEFAULT_TIMEOUT,
|
|
570
|
+
walletAddress: walletAccount.address
|
|
571
|
+
}),
|
|
572
|
+
walletAccount
|
|
573
|
+
});
|
|
574
|
+
};
|
|
575
|
+
const sendJetton = async ({ transaction, walletAccount }) => {
|
|
576
|
+
assertDefined(walletAccount, "Wallet account is required");
|
|
577
|
+
return sendTransaction({
|
|
578
|
+
request: await prepareJettonTransfer({
|
|
579
|
+
client: await getTonClientForActiveNetwork(),
|
|
580
|
+
forwardTonAmount: transaction.forwardTonAmount ?? BigInt(0),
|
|
581
|
+
gasAmount: transaction.gasAmount ?? DEFAULT_JETTON_GAS,
|
|
582
|
+
jettonAmount: transaction.amount,
|
|
583
|
+
jettonMasterAddress: transaction.jettonMasterAddress,
|
|
584
|
+
recipientAddress: transaction.recipientAddress,
|
|
585
|
+
timeout: DEFAULT_TIMEOUT,
|
|
586
|
+
walletAddress: walletAccount.address
|
|
587
|
+
}),
|
|
588
|
+
walletAccount
|
|
589
|
+
});
|
|
590
|
+
};
|
|
591
|
+
const generateTonConnectProof = async ({ payload, walletAccount }) => {
|
|
592
|
+
assertDefined(walletAccount, "Wallet account is required");
|
|
593
|
+
const host = globalThis.location?.host || "";
|
|
594
|
+
const timestamp = Math.floor(Date.now() / 1e3);
|
|
595
|
+
const domain = {
|
|
596
|
+
lengthBytes: new TextEncoder().encode(host).length,
|
|
597
|
+
value: host
|
|
598
|
+
};
|
|
599
|
+
const { signature } = await signMessage({
|
|
600
|
+
message: await generateTonConnectProofHash({
|
|
601
|
+
address: walletAccount.address,
|
|
602
|
+
domain,
|
|
603
|
+
payload,
|
|
604
|
+
timestamp
|
|
605
|
+
}),
|
|
606
|
+
walletAccount
|
|
607
|
+
});
|
|
608
|
+
return {
|
|
609
|
+
address: walletAccount.address,
|
|
610
|
+
domain,
|
|
611
|
+
payload,
|
|
612
|
+
signature,
|
|
613
|
+
timestamp
|
|
614
|
+
};
|
|
615
|
+
};
|
|
616
|
+
return {
|
|
617
|
+
...waasProvider,
|
|
618
|
+
chain,
|
|
619
|
+
generateTonConnectProof,
|
|
620
|
+
getActiveNetworkId,
|
|
621
|
+
getConnectedAddresses,
|
|
622
|
+
groupKey: formatWalletProviderGroupKey(DYNAMIC_WAAS_METADATA.displayName),
|
|
623
|
+
key,
|
|
624
|
+
metadata: {
|
|
625
|
+
displayName: DYNAMIC_WAAS_METADATA.displayName,
|
|
626
|
+
icon: DYNAMIC_WAAS_METADATA.icon
|
|
627
|
+
},
|
|
628
|
+
sendJetton,
|
|
629
|
+
sendTon,
|
|
630
|
+
sendTransaction,
|
|
631
|
+
signMessage,
|
|
632
|
+
switchActiveNetwork,
|
|
633
|
+
transferAmount: (args) => tonTransferAmount(args, sdkClient),
|
|
634
|
+
walletProviderType
|
|
635
|
+
};
|
|
636
|
+
};
|
|
637
|
+
|
|
638
|
+
//#endregion
|
|
639
|
+
//#region src/waas/addWaasTonExtension/addWaasTonExtension.ts
|
|
640
|
+
const WAAS_TON_EXTENSION_KEY = "waasTon";
|
|
641
|
+
/**
|
|
642
|
+
* Adds the Dynamic WaaS (Wallet as a Service) TON extension to the Dynamic client.
|
|
643
|
+
*
|
|
644
|
+
* This extension enables embedded wallet functionality for the TON blockchain,
|
|
645
|
+
* allowing users to have wallets managed by Dynamic's infrastructure.
|
|
646
|
+
*
|
|
647
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
648
|
+
* @not-instrumented
|
|
649
|
+
*/
|
|
650
|
+
const addWaasTonExtension = (client = getDefaultClient()) => {
|
|
651
|
+
if (hasExtension({ extensionKey: WAAS_TON_EXTENSION_KEY }, client)) return;
|
|
652
|
+
registerExtension({ extensionKey: WAAS_TON_EXTENSION_KEY }, client);
|
|
653
|
+
registerTonNetworkProviderBuilder(client);
|
|
654
|
+
const walletProviderRegistry = getWalletProviderRegistry(client);
|
|
655
|
+
const walletProvider = createWalletProviderForWaasTon(client);
|
|
656
|
+
walletProviderRegistry.register({
|
|
657
|
+
priority: WalletProviderPriority.WALLET_SDK,
|
|
658
|
+
walletProvider
|
|
659
|
+
});
|
|
660
|
+
};
|
|
661
|
+
|
|
662
|
+
//#endregion
|
|
663
|
+
export { prepareJettonTransfer as a, name as c, prepareTonNativeTransfer as i, version as l, isTonWalletProvider as n, NANOTON_PER_TON as o, NotTonProviderError as r, TransactionExecutionFailedError as s, addWaasTonExtension as t };
|
|
664
|
+
//# sourceMappingURL=addWaasTonExtension-B8tYiMfm.esm.js.map
|